Fossil SCM

merge trunk

jan.nijtmans 2013-11-12 15:27 jan-httpsproxytunnel merge
Commit 1bd561c3ba5457b13e6a4d4dcc873297943ec31f
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,4 +1,5 @@
11
compat/openssl*
22
compat/tcl*
33
fossil
44
fossil.exe
5
+win/fossil.exe
56
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,4 +1,5 @@
1 compat/openssl*
2 compat/tcl*
3 fossil
4 fossil.exe
 
5
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,4 +1,5 @@
1 compat/openssl*
2 compat/tcl*
3 fossil
4 fossil.exe
5 win/fossil.exe
6
--- .fossil-settings/keep-glob
+++ .fossil-settings/keep-glob
@@ -1,4 +1,5 @@
11
compat/openssl*
22
compat/tcl*
33
fossil
44
fossil.exe
5
+win/fossil.exe
56
--- .fossil-settings/keep-glob
+++ .fossil-settings/keep-glob
@@ -1,4 +1,5 @@
1 compat/openssl*
2 compat/tcl*
3 fossil
4 fossil.exe
 
5
--- .fossil-settings/keep-glob
+++ .fossil-settings/keep-glob
@@ -1,4 +1,5 @@
1 compat/openssl*
2 compat/tcl*
3 fossil
4 fossil.exe
5 win/fossil.exe
6
-6
--- src/add.c
+++ src/add.c
@@ -258,13 +258,10 @@
258258
}
259259
if( zIgnoreFlag==0 ){
260260
zIgnoreFlag = db_get("ignore-glob", 0);
261261
}
262262
vid = db_lget_int("checkout",0);
263
- if( vid==0 ){
264
- fossil_fatal("no checkout to add to");
265
- }
266263
db_begin_transaction();
267264
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
268265
filename_collation());
269266
pClean = glob_create(zCleanFlag);
270267
pIgnore = glob_create(zIgnoreFlag);
@@ -500,13 +497,10 @@
500497
}
501498
if( zIgnoreFlag==0 ){
502499
zIgnoreFlag = db_get("ignore-glob", 0);
503500
}
504501
vid = db_lget_int("checkout",0);
505
- if( vid==0 ){
506
- fossil_fatal("no checkout to add to");
507
- }
508502
db_begin_transaction();
509503
510504
/* step 1:
511505
** Populate the temp table "sfile" with the names of all unmanaged
512506
** files currently in the check-out, except for files that match the
513507
--- src/add.c
+++ src/add.c
@@ -258,13 +258,10 @@
258 }
259 if( zIgnoreFlag==0 ){
260 zIgnoreFlag = db_get("ignore-glob", 0);
261 }
262 vid = db_lget_int("checkout",0);
263 if( vid==0 ){
264 fossil_fatal("no checkout to add to");
265 }
266 db_begin_transaction();
267 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
268 filename_collation());
269 pClean = glob_create(zCleanFlag);
270 pIgnore = glob_create(zIgnoreFlag);
@@ -500,13 +497,10 @@
500 }
501 if( zIgnoreFlag==0 ){
502 zIgnoreFlag = db_get("ignore-glob", 0);
503 }
504 vid = db_lget_int("checkout",0);
505 if( vid==0 ){
506 fossil_fatal("no checkout to add to");
507 }
508 db_begin_transaction();
509
510 /* step 1:
511 ** Populate the temp table "sfile" with the names of all unmanaged
512 ** files currently in the check-out, except for files that match the
513
--- src/add.c
+++ src/add.c
@@ -258,13 +258,10 @@
258 }
259 if( zIgnoreFlag==0 ){
260 zIgnoreFlag = db_get("ignore-glob", 0);
261 }
262 vid = db_lget_int("checkout",0);
 
 
 
263 db_begin_transaction();
264 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
265 filename_collation());
266 pClean = glob_create(zCleanFlag);
267 pIgnore = glob_create(zIgnoreFlag);
@@ -500,13 +497,10 @@
497 }
498 if( zIgnoreFlag==0 ){
499 zIgnoreFlag = db_get("ignore-glob", 0);
500 }
501 vid = db_lget_int("checkout",0);
 
 
 
502 db_begin_transaction();
503
504 /* step 1:
505 ** Populate the temp table "sfile" with the names of all unmanaged
506 ** files currently in the check-out, except for files that match the
507
+16 -9
--- src/checkin.c
+++ src/checkin.c
@@ -977,11 +977,11 @@
977977
int vid, /* BLOB.id for the parent check-in */
978978
CheckinInfo *p, /* Information about the check-in */
979979
int *pnFBcard /* OUT: Number of generated B- and F-cards */
980980
){
981981
char *zDate; /* Date of the check-in */
982
- char *zParentUuid; /* UUID of parent check-in */
982
+ char *zParentUuid = 0; /* UUID of parent check-in */
983983
Blob filename; /* A single filename */
984984
int nBasename; /* Size of base filename */
985985
Stmt q; /* Various queries */
986986
Blob mcksum; /* Manifest checksum */
987987
ManifestFile *pFile; /* File from the baseline */
@@ -990,16 +990,18 @@
990990
const char *zColor; /* Modified value of p->zColor */
991991
992992
assert( pBaseline==0 || pBaseline->zBaseline==0 );
993993
assert( pBaseline==0 || zBaselineUuid!=0 );
994994
blob_zero(pOut);
995
- zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d AND "
996
- "EXISTS(SELECT 1 FROM event WHERE event.type='ci' and event.objid=%d)",
997
- vid, vid);
998
- if( !zParentUuid ){
999
- fossil_fatal("Could not find a valid check-in for RID %d. "
1000
- "Possible checkout/repo mismatch.", vid);
995
+ if( vid ){
996
+ zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d AND "
997
+ "EXISTS(SELECT 1 FROM event WHERE event.type='ci' and event.objid=%d)",
998
+ vid, vid);
999
+ if( !zParentUuid ){
1000
+ fossil_fatal("Could not find a valid check-in for RID %d. "
1001
+ "Possible checkout/repo mismatch.", vid);
1002
+ }
10011003
}
10021004
if( pBaseline ){
10031005
blob_appendf(pOut, "B %s\n", zBaselineUuid);
10041006
manifest_file_rewind(pBaseline);
10051007
pFile = manifest_file_next(pBaseline, 0);
@@ -1091,11 +1093,11 @@
10911093
nFBcard++;
10921094
}
10931095
if( p->zMimetype && p->zMimetype[0] ){
10941096
blob_appendf(pOut, "N %F\n", p->zMimetype);
10951097
}
1096
- if( zParentUuid ){
1098
+ if( vid ){
10971099
blob_appendf(pOut, "P %s", zParentUuid);
10981100
if( p->verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
10991101
free(zParentUuid);
11001102
db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0 OR id<-2");
11011103
while( db_step(&q)==SQLITE_ROW ){
@@ -1610,12 +1612,17 @@
16101612
}
16111613
16121614
/*
16131615
** Do not allow a commit that will cause a fork unless the --allow-fork
16141616
** or --force flags is used, or unless this is a private check-in.
1617
+ ** The initial commit MUST have tags "trunk" and "sym-trunk".
16151618
*/
1616
- if( sCiInfo.zBranch==0 && allowFork==0 && forceFlag==0
1619
+ if( !vid ){
1620
+ if( sCiInfo.zBranch==0 ){
1621
+ sCiInfo.zBranch = db_get("main-branch", "trunk");
1622
+ }
1623
+ }else if( sCiInfo.zBranch==0 && allowFork==0 && forceFlag==0
16171624
&& g.markPrivate==0 && !is_a_leaf(vid)
16181625
){
16191626
fossil_fatal("would fork. \"update\" first or use --allow-fork.");
16201627
}
16211628
16221629
--- src/checkin.c
+++ src/checkin.c
@@ -977,11 +977,11 @@
977 int vid, /* BLOB.id for the parent check-in */
978 CheckinInfo *p, /* Information about the check-in */
979 int *pnFBcard /* OUT: Number of generated B- and F-cards */
980 ){
981 char *zDate; /* Date of the check-in */
982 char *zParentUuid; /* UUID of parent check-in */
983 Blob filename; /* A single filename */
984 int nBasename; /* Size of base filename */
985 Stmt q; /* Various queries */
986 Blob mcksum; /* Manifest checksum */
987 ManifestFile *pFile; /* File from the baseline */
@@ -990,16 +990,18 @@
990 const char *zColor; /* Modified value of p->zColor */
991
992 assert( pBaseline==0 || pBaseline->zBaseline==0 );
993 assert( pBaseline==0 || zBaselineUuid!=0 );
994 blob_zero(pOut);
995 zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d AND "
996 "EXISTS(SELECT 1 FROM event WHERE event.type='ci' and event.objid=%d)",
997 vid, vid);
998 if( !zParentUuid ){
999 fossil_fatal("Could not find a valid check-in for RID %d. "
1000 "Possible checkout/repo mismatch.", vid);
 
 
1001 }
1002 if( pBaseline ){
1003 blob_appendf(pOut, "B %s\n", zBaselineUuid);
1004 manifest_file_rewind(pBaseline);
1005 pFile = manifest_file_next(pBaseline, 0);
@@ -1091,11 +1093,11 @@
1091 nFBcard++;
1092 }
1093 if( p->zMimetype && p->zMimetype[0] ){
1094 blob_appendf(pOut, "N %F\n", p->zMimetype);
1095 }
1096 if( zParentUuid ){
1097 blob_appendf(pOut, "P %s", zParentUuid);
1098 if( p->verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
1099 free(zParentUuid);
1100 db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0 OR id<-2");
1101 while( db_step(&q)==SQLITE_ROW ){
@@ -1610,12 +1612,17 @@
1610 }
1611
1612 /*
1613 ** Do not allow a commit that will cause a fork unless the --allow-fork
1614 ** or --force flags is used, or unless this is a private check-in.
 
1615 */
1616 if( sCiInfo.zBranch==0 && allowFork==0 && forceFlag==0
 
 
 
 
1617 && g.markPrivate==0 && !is_a_leaf(vid)
1618 ){
1619 fossil_fatal("would fork. \"update\" first or use --allow-fork.");
1620 }
1621
1622
--- src/checkin.c
+++ src/checkin.c
@@ -977,11 +977,11 @@
977 int vid, /* BLOB.id for the parent check-in */
978 CheckinInfo *p, /* Information about the check-in */
979 int *pnFBcard /* OUT: Number of generated B- and F-cards */
980 ){
981 char *zDate; /* Date of the check-in */
982 char *zParentUuid = 0; /* UUID of parent check-in */
983 Blob filename; /* A single filename */
984 int nBasename; /* Size of base filename */
985 Stmt q; /* Various queries */
986 Blob mcksum; /* Manifest checksum */
987 ManifestFile *pFile; /* File from the baseline */
@@ -990,16 +990,18 @@
990 const char *zColor; /* Modified value of p->zColor */
991
992 assert( pBaseline==0 || pBaseline->zBaseline==0 );
993 assert( pBaseline==0 || zBaselineUuid!=0 );
994 blob_zero(pOut);
995 if( vid ){
996 zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d AND "
997 "EXISTS(SELECT 1 FROM event WHERE event.type='ci' and event.objid=%d)",
998 vid, vid);
999 if( !zParentUuid ){
1000 fossil_fatal("Could not find a valid check-in for RID %d. "
1001 "Possible checkout/repo mismatch.", vid);
1002 }
1003 }
1004 if( pBaseline ){
1005 blob_appendf(pOut, "B %s\n", zBaselineUuid);
1006 manifest_file_rewind(pBaseline);
1007 pFile = manifest_file_next(pBaseline, 0);
@@ -1091,11 +1093,11 @@
1093 nFBcard++;
1094 }
1095 if( p->zMimetype && p->zMimetype[0] ){
1096 blob_appendf(pOut, "N %F\n", p->zMimetype);
1097 }
1098 if( vid ){
1099 blob_appendf(pOut, "P %s", zParentUuid);
1100 if( p->verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
1101 free(zParentUuid);
1102 db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0 OR id<-2");
1103 while( db_step(&q)==SQLITE_ROW ){
@@ -1610,12 +1612,17 @@
1612 }
1613
1614 /*
1615 ** Do not allow a commit that will cause a fork unless the --allow-fork
1616 ** or --force flags is used, or unless this is a private check-in.
1617 ** The initial commit MUST have tags "trunk" and "sym-trunk".
1618 */
1619 if( !vid ){
1620 if( sCiInfo.zBranch==0 ){
1621 sCiInfo.zBranch = db_get("main-branch", "trunk");
1622 }
1623 }else if( sCiInfo.zBranch==0 && allowFork==0 && forceFlag==0
1624 && g.markPrivate==0 && !is_a_leaf(vid)
1625 ){
1626 fossil_fatal("would fork. \"update\" first or use --allow-fork.");
1627 }
1628
1629
+1 -1
--- src/checkout.c
+++ src/checkout.c
@@ -220,11 +220,11 @@
220220
zVers = db_text(0, "SELECT uuid FROM event, blob"
221221
" WHERE event.objid=blob.rid AND event.type='ci'"
222222
" ORDER BY event.mtime DESC");
223223
}
224224
if( zVers==0 ){
225
- fossil_fatal("cannot locate \"latest\" checkout");
225
+ return;
226226
}
227227
}else{
228228
zVers = g.argv[2];
229229
}
230230
vid = load_vfile(zVers);
231231
--- src/checkout.c
+++ src/checkout.c
@@ -220,11 +220,11 @@
220 zVers = db_text(0, "SELECT uuid FROM event, blob"
221 " WHERE event.objid=blob.rid AND event.type='ci'"
222 " ORDER BY event.mtime DESC");
223 }
224 if( zVers==0 ){
225 fossil_fatal("cannot locate \"latest\" checkout");
226 }
227 }else{
228 zVers = g.argv[2];
229 }
230 vid = load_vfile(zVers);
231
--- src/checkout.c
+++ src/checkout.c
@@ -220,11 +220,11 @@
220 zVers = db_text(0, "SELECT uuid FROM event, blob"
221 " WHERE event.objid=blob.rid AND event.type='ci'"
222 " ORDER BY event.mtime DESC");
223 }
224 if( zVers==0 ){
225 return;
226 }
227 }else{
228 zVers = g.argv[2];
229 }
230 vid = load_vfile(zVers);
231
+5 -1
--- src/clone.c
+++ src/clone.c
@@ -105,10 +105,11 @@
105105
** admin user. This can be overridden using the -A|--admin-user
106106
** parameter.
107107
**
108108
** Options:
109109
** --admin-user|-A USERNAME Make USERNAME the administrator
110
+** --once Don't save url.
110111
** --private Also clone private branches
111112
** --ssl-identity=filename Use the SSL identity if requested by the server
112113
** --ssh-command|-c 'command' Use this SSH command
113114
**
114115
** See also: init
@@ -116,12 +117,14 @@
116117
void clone_cmd(void){
117118
char *zPassword;
118119
const char *zDefaultUser; /* Optional name of the default user */
119120
int nErr = 0;
120121
int bPrivate = 0; /* Also clone private branches */
122
+ int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
121123
122124
if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
125
+ if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
123126
clone_ssh_find_options();
124127
url_proxy_options();
125128
if( g.argc < 4 ){
126129
usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
127130
}
@@ -130,11 +133,11 @@
130133
fossil_fatal("file already exists: %s", g.argv[3]);
131134
}
132135
133136
zDefaultUser = find_option("admin-user","A",1);
134137
135
- url_parse(g.argv[2], URL_PROMPT_PW|URL_ASK_REMEMBER_PW);
138
+ url_parse(g.argv[2], urlFlags);
136139
if( zDefaultUser==0 && g.urlUser!=0 ) zDefaultUser = g.urlUser;
137140
if( g.urlIsFile ){
138141
file_copy(g.urlName, g.argv[3]);
139142
db_close(1);
140143
db_open_repository(g.argv[3]);
@@ -156,10 +159,11 @@
156159
db_record_repository_filename(g.argv[3]);
157160
db_initial_setup(0, 0, zDefaultUser, 0);
158161
user_select();
159162
db_set("content-schema", CONTENT_SCHEMA, 0);
160163
db_set("aux-schema", AUX_SCHEMA, 0);
164
+ db_set("rebuilt", get_version(), 0);
161165
url_remember();
162166
if( g.zSSLIdentity!=0 ){
163167
/* If the --ssl-identity option was specified, store it as a setting */
164168
Blob fn;
165169
blob_zero(&fn);
166170
--- src/clone.c
+++ src/clone.c
@@ -105,10 +105,11 @@
105 ** admin user. This can be overridden using the -A|--admin-user
106 ** parameter.
107 **
108 ** Options:
109 ** --admin-user|-A USERNAME Make USERNAME the administrator
 
110 ** --private Also clone private branches
111 ** --ssl-identity=filename Use the SSL identity if requested by the server
112 ** --ssh-command|-c 'command' Use this SSH command
113 **
114 ** See also: init
@@ -116,12 +117,14 @@
116 void clone_cmd(void){
117 char *zPassword;
118 const char *zDefaultUser; /* Optional name of the default user */
119 int nErr = 0;
120 int bPrivate = 0; /* Also clone private branches */
 
121
122 if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
 
123 clone_ssh_find_options();
124 url_proxy_options();
125 if( g.argc < 4 ){
126 usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
127 }
@@ -130,11 +133,11 @@
130 fossil_fatal("file already exists: %s", g.argv[3]);
131 }
132
133 zDefaultUser = find_option("admin-user","A",1);
134
135 url_parse(g.argv[2], URL_PROMPT_PW|URL_ASK_REMEMBER_PW);
136 if( zDefaultUser==0 && g.urlUser!=0 ) zDefaultUser = g.urlUser;
137 if( g.urlIsFile ){
138 file_copy(g.urlName, g.argv[3]);
139 db_close(1);
140 db_open_repository(g.argv[3]);
@@ -156,10 +159,11 @@
156 db_record_repository_filename(g.argv[3]);
157 db_initial_setup(0, 0, zDefaultUser, 0);
158 user_select();
159 db_set("content-schema", CONTENT_SCHEMA, 0);
160 db_set("aux-schema", AUX_SCHEMA, 0);
 
161 url_remember();
162 if( g.zSSLIdentity!=0 ){
163 /* If the --ssl-identity option was specified, store it as a setting */
164 Blob fn;
165 blob_zero(&fn);
166
--- src/clone.c
+++ src/clone.c
@@ -105,10 +105,11 @@
105 ** admin user. This can be overridden using the -A|--admin-user
106 ** parameter.
107 **
108 ** Options:
109 ** --admin-user|-A USERNAME Make USERNAME the administrator
110 ** --once Don't save url.
111 ** --private Also clone private branches
112 ** --ssl-identity=filename Use the SSL identity if requested by the server
113 ** --ssh-command|-c 'command' Use this SSH command
114 **
115 ** See also: init
@@ -116,12 +117,14 @@
117 void clone_cmd(void){
118 char *zPassword;
119 const char *zDefaultUser; /* Optional name of the default user */
120 int nErr = 0;
121 int bPrivate = 0; /* Also clone private branches */
122 int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
123
124 if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
125 if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
126 clone_ssh_find_options();
127 url_proxy_options();
128 if( g.argc < 4 ){
129 usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
130 }
@@ -130,11 +133,11 @@
133 fossil_fatal("file already exists: %s", g.argv[3]);
134 }
135
136 zDefaultUser = find_option("admin-user","A",1);
137
138 url_parse(g.argv[2], urlFlags);
139 if( zDefaultUser==0 && g.urlUser!=0 ) zDefaultUser = g.urlUser;
140 if( g.urlIsFile ){
141 file_copy(g.urlName, g.argv[3]);
142 db_close(1);
143 db_open_repository(g.argv[3]);
@@ -156,10 +159,11 @@
159 db_record_repository_filename(g.argv[3]);
160 db_initial_setup(0, 0, zDefaultUser, 0);
161 user_select();
162 db_set("content-schema", CONTENT_SCHEMA, 0);
163 db_set("aux-schema", AUX_SCHEMA, 0);
164 db_set("rebuilt", get_version(), 0);
165 url_remember();
166 if( g.zSSLIdentity!=0 ){
167 /* If the --ssl-identity option was specified, store it as a setting */
168 Blob fn;
169 blob_zero(&fn);
170
+12 -7
--- src/comformat.c
+++ src/comformat.c
@@ -26,28 +26,36 @@
2626
** Given a comment string zText, format that string for printing
2727
** on a TTY. Assume that the output cursors is indent spaces from
2828
** the left margin and that a single line can contain no more than
2929
** lineLength characters. Indent all subsequent lines by indent.
3030
**
31
-** lineLength must be less than 400.
32
-**
3331
** Return the number of newlines that are output.
3432
*/
3533
int comment_print(const char *zText, int indent, int lineLength){
3634
int tlen = lineLength - indent;
3735
int si, sk, i, k;
3836
int doIndent = 0;
39
- char zBuf[400];
37
+ char *zBuf;
38
+ char zBuffer[400];
4039
int lineCnt = 0;
4140
41
+ if( tlen<=0 ){
42
+ tlen = strlen(zText);
43
+ }
44
+ if( tlen >= (sizeof(zBuffer)) ){
45
+ zBuf = fossil_malloc(tlen+1);
46
+ }else{
47
+ zBuf = zBuffer;
48
+ }
4249
for(;;){
4350
while( fossil_isspace(zText[0]) ){ zText++; }
4451
if( zText[0]==0 ){
4552
if( doIndent==0 ){
4653
fossil_print("\n");
4754
lineCnt = 1;
4855
}
56
+ if( zBuf!=zBuffer) fossil_free(zBuf);
4957
return lineCnt;
5058
}
5159
for(sk=si=i=k=0; zText[i] && k<tlen; i++){
5260
char c = zText[i];
5361
if( fossil_isspace(c) ){
@@ -69,19 +77,16 @@
6977
fossil_print("%*s", indent, "");
7078
}
7179
doIndent = 1;
7280
if( sk>0 && zText[i] ){
7381
zText += si;
74
- zBuf[sk++] = '\n';
7582
zBuf[sk] = 0;
76
- fossil_print("%s", zBuf);
7783
}else{
7884
zText += i;
79
- zBuf[k++] = '\n';
8085
zBuf[k] = 0;
81
- fossil_print("%s", zBuf);
8286
}
87
+ fossil_print("%s\n", zBuf);
8388
lineCnt++;
8489
}
8590
}
8691
8792
/*
8893
--- src/comformat.c
+++ src/comformat.c
@@ -26,28 +26,36 @@
26 ** Given a comment string zText, format that string for printing
27 ** on a TTY. Assume that the output cursors is indent spaces from
28 ** the left margin and that a single line can contain no more than
29 ** lineLength characters. Indent all subsequent lines by indent.
30 **
31 ** lineLength must be less than 400.
32 **
33 ** Return the number of newlines that are output.
34 */
35 int comment_print(const char *zText, int indent, int lineLength){
36 int tlen = lineLength - indent;
37 int si, sk, i, k;
38 int doIndent = 0;
39 char zBuf[400];
 
40 int lineCnt = 0;
41
 
 
 
 
 
 
 
 
42 for(;;){
43 while( fossil_isspace(zText[0]) ){ zText++; }
44 if( zText[0]==0 ){
45 if( doIndent==0 ){
46 fossil_print("\n");
47 lineCnt = 1;
48 }
 
49 return lineCnt;
50 }
51 for(sk=si=i=k=0; zText[i] && k<tlen; i++){
52 char c = zText[i];
53 if( fossil_isspace(c) ){
@@ -69,19 +77,16 @@
69 fossil_print("%*s", indent, "");
70 }
71 doIndent = 1;
72 if( sk>0 && zText[i] ){
73 zText += si;
74 zBuf[sk++] = '\n';
75 zBuf[sk] = 0;
76 fossil_print("%s", zBuf);
77 }else{
78 zText += i;
79 zBuf[k++] = '\n';
80 zBuf[k] = 0;
81 fossil_print("%s", zBuf);
82 }
 
83 lineCnt++;
84 }
85 }
86
87 /*
88
--- src/comformat.c
+++ src/comformat.c
@@ -26,28 +26,36 @@
26 ** Given a comment string zText, format that string for printing
27 ** on a TTY. Assume that the output cursors is indent spaces from
28 ** the left margin and that a single line can contain no more than
29 ** lineLength characters. Indent all subsequent lines by indent.
30 **
 
 
31 ** Return the number of newlines that are output.
32 */
33 int comment_print(const char *zText, int indent, int lineLength){
34 int tlen = lineLength - indent;
35 int si, sk, i, k;
36 int doIndent = 0;
37 char *zBuf;
38 char zBuffer[400];
39 int lineCnt = 0;
40
41 if( tlen<=0 ){
42 tlen = strlen(zText);
43 }
44 if( tlen >= (sizeof(zBuffer)) ){
45 zBuf = fossil_malloc(tlen+1);
46 }else{
47 zBuf = zBuffer;
48 }
49 for(;;){
50 while( fossil_isspace(zText[0]) ){ zText++; }
51 if( zText[0]==0 ){
52 if( doIndent==0 ){
53 fossil_print("\n");
54 lineCnt = 1;
55 }
56 if( zBuf!=zBuffer) fossil_free(zBuf);
57 return lineCnt;
58 }
59 for(sk=si=i=k=0; zText[i] && k<tlen; i++){
60 char c = zText[i];
61 if( fossil_isspace(c) ){
@@ -69,19 +77,16 @@
77 fossil_print("%*s", indent, "");
78 }
79 doIndent = 1;
80 if( sk>0 && zText[i] ){
81 zText += si;
 
82 zBuf[sk] = 0;
 
83 }else{
84 zText += i;
 
85 zBuf[k] = 0;
 
86 }
87 fossil_print("%s\n", zBuf);
88 lineCnt++;
89 }
90 }
91
92 /*
93
+2 -2
--- src/config.h
+++ src/config.h
@@ -25,12 +25,12 @@
2525
#ifndef _FILE_OFFSET_BITS
2626
# define _FILE_OFFSET_BITS 64
2727
#endif
2828
#define _LARGEFILE_SOURCE 1
2929
30
-/* Make sure that in Win32 builds, _USE_32BIT_TIME_T is always defined. */
31
-#if defined(_WIN32) && !defined(_WIN64) && !defined(_USE_32BIT_TIME_T)
30
+/* Make sure that in Win32 MinGW builds, _USE_32BIT_TIME_T is always defined. */
31
+#if defined(_WIN32) && !defined(_WIN64) && !defined(_MSC_VER) && !defined(_USE_32BIT_TIME_T)
3232
# define _USE_32BIT_TIME_T
3333
#endif
3434
3535
#ifdef HAVE_AUTOCONFIG_H
3636
#include "autoconfig.h"
3737
--- src/config.h
+++ src/config.h
@@ -25,12 +25,12 @@
25 #ifndef _FILE_OFFSET_BITS
26 # define _FILE_OFFSET_BITS 64
27 #endif
28 #define _LARGEFILE_SOURCE 1
29
30 /* Make sure that in Win32 builds, _USE_32BIT_TIME_T is always defined. */
31 #if defined(_WIN32) && !defined(_WIN64) && !defined(_USE_32BIT_TIME_T)
32 # define _USE_32BIT_TIME_T
33 #endif
34
35 #ifdef HAVE_AUTOCONFIG_H
36 #include "autoconfig.h"
37
--- src/config.h
+++ src/config.h
@@ -25,12 +25,12 @@
25 #ifndef _FILE_OFFSET_BITS
26 # define _FILE_OFFSET_BITS 64
27 #endif
28 #define _LARGEFILE_SOURCE 1
29
30 /* Make sure that in Win32 MinGW builds, _USE_32BIT_TIME_T is always defined. */
31 #if defined(_WIN32) && !defined(_WIN64) && !defined(_MSC_VER) && !defined(_USE_32BIT_TIME_T)
32 # define _USE_32BIT_TIME_T
33 #endif
34
35 #ifdef HAVE_AUTOCONFIG_H
36 #include "autoconfig.h"
37
+84
--- src/db.c
+++ src/db.c
@@ -1340,10 +1340,11 @@
13401340
Blob hash;
13411341
Blob manifest;
13421342
13431343
db_set("content-schema", CONTENT_SCHEMA, 0);
13441344
db_set("aux-schema", AUX_SCHEMA, 0);
1345
+ db_set("rebuilt", get_version(), 0);
13451346
if( makeServerCodes ){
13461347
db_multi_exec(
13471348
"INSERT INTO config(name,value,mtime)"
13481349
" VALUES('server-code', lower(hex(randomblob(20))),now());"
13491350
"INSERT INTO config(name,value,mtime)"
@@ -1798,10 +1799,27 @@
17981799
}
17991800
if( z==0 ){
18001801
z = zDefault;
18011802
}
18021803
return z;
1804
+}
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
+ }
1820
+ return z;
18031821
}
18041822
void db_set(const char *zName, const char *zValue, int globalFlag){
18051823
db_begin_transaction();
18061824
if( globalFlag ){
18071825
db_swap_connections();
@@ -2442,5 +2460,71 @@
24422460
rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]);
24432461
fossil_print("Time differences: %s\n", db_timespan_name(rDiff));
24442462
sqlite3_close(g.db);
24452463
g.db = 0;
24462464
}
2465
+
2466
+/*
2467
+** COMMAND: test-without-rowid
2468
+** %fossil test-without-rowid FILENAME...
2469
+**
2470
+** Change the Fossil repository FILENAME to make use of the WITHOUT ROWID
2471
+** optimization. FILENAME can also be the ~/.fossil file or a local
2472
+** .fslckout or _FOSSIL_ file.
2473
+**
2474
+** The purpose of this command is for testing the WITHOUT ROWID capabilities
2475
+** of SQLite. There is no big advantage to using WITHOUT ROWID in Fossil.
2476
+**
2477
+** Options:
2478
+** --dryrun | -n No changes. Just print what would happen.
2479
+*/
2480
+void test_without_rowid(void){
2481
+ int i, j;
2482
+ Stmt q;
2483
+ Blob allSql;
2484
+ int dryRun = find_option("dry-run", "n", 0)!=0;
2485
+ for(i=2; i<g.argc; i++){
2486
+ db_open_or_attach(g.argv[i], "main", 0);
2487
+ blob_init(&allSql, "BEGIN;\n", -1);
2488
+ db_prepare(&q,
2489
+ "SELECT name, sql FROM main.sqlite_master "
2490
+ " WHERE type='table' AND sql NOT LIKE '%%WITHOUT ROWID%%'"
2491
+ " AND name IN ('global_config','shun','concealed','config',"
2492
+ " 'plink','tagxref','backlink','vcache');"
2493
+ );
2494
+ while( db_step(&q)==SQLITE_ROW ){
2495
+ const char *zTName = db_column_text(&q, 0);
2496
+ const char *zOrigSql = db_column_text(&q, 1);
2497
+ Blob newSql;
2498
+ blob_init(&newSql, 0, 0);
2499
+ for(j=0; zOrigSql[j]; j++){
2500
+ if( fossil_strnicmp(zOrigSql+j,"unique",6)==0 ){
2501
+ blob_append(&newSql, zOrigSql, j);
2502
+ blob_append(&newSql, "PRIMARY KEY", -1);
2503
+ zOrigSql += j+6;
2504
+ j = -1;
2505
+ }
2506
+ }
2507
+ blob_append(&newSql, zOrigSql, -1);
2508
+ blob_appendf(&allSql,
2509
+ "ALTER TABLE %s RENAME TO x_%s;\n"
2510
+ "%s WITHOUT ROWID;\n"
2511
+ "INSERT INTO %s SELECT * FROM x_%s;\n"
2512
+ "DROP TABLE x_%s;\n",
2513
+ zTName, zTName, blob_str(&newSql), zTName, zTName, zTName
2514
+ );
2515
+ fossil_print("Converting table %s of %s to WITHOUT ROWID.\n", zTName, g.argv[i]);
2516
+ blob_reset(&newSql);
2517
+ }
2518
+ blob_appendf(&allSql, "COMMIT;\n");
2519
+ db_finalize(&q);
2520
+ if( dryRun ){
2521
+ fossil_print("SQL that would have been evaluated:\n");
2522
+ fossil_print("-------------------------------------------------------------\n");
2523
+ fossil_print("%s", blob_str(&allSql));
2524
+ }else{
2525
+ db_multi_exec("%s", blob_str(&allSql));
2526
+ }
2527
+ blob_reset(&allSql);
2528
+ db_close(1);
2529
+ }
2530
+}
24472531
--- src/db.c
+++ src/db.c
@@ -1340,10 +1340,11 @@
1340 Blob hash;
1341 Blob manifest;
1342
1343 db_set("content-schema", CONTENT_SCHEMA, 0);
1344 db_set("aux-schema", AUX_SCHEMA, 0);
 
1345 if( makeServerCodes ){
1346 db_multi_exec(
1347 "INSERT INTO config(name,value,mtime)"
1348 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1349 "INSERT INTO config(name,value,mtime)"
@@ -1798,10 +1799,27 @@
1798 }
1799 if( z==0 ){
1800 z = zDefault;
1801 }
1802 return z;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1803 }
1804 void db_set(const char *zName, const char *zValue, int globalFlag){
1805 db_begin_transaction();
1806 if( globalFlag ){
1807 db_swap_connections();
@@ -2442,5 +2460,71 @@
2442 rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]);
2443 fossil_print("Time differences: %s\n", db_timespan_name(rDiff));
2444 sqlite3_close(g.db);
2445 g.db = 0;
2446 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2447
--- src/db.c
+++ src/db.c
@@ -1340,10 +1340,11 @@
1340 Blob hash;
1341 Blob manifest;
1342
1343 db_set("content-schema", CONTENT_SCHEMA, 0);
1344 db_set("aux-schema", AUX_SCHEMA, 0);
1345 db_set("rebuilt", get_version(), 0);
1346 if( makeServerCodes ){
1347 db_multi_exec(
1348 "INSERT INTO config(name,value,mtime)"
1349 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1350 "INSERT INTO config(name,value,mtime)"
@@ -1798,10 +1799,27 @@
1799 }
1800 if( z==0 ){
1801 z = zDefault;
1802 }
1803 return z;
1804 }
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 }
1820 return z;
1821 }
1822 void db_set(const char *zName, const char *zValue, int globalFlag){
1823 db_begin_transaction();
1824 if( globalFlag ){
1825 db_swap_connections();
@@ -2442,5 +2460,71 @@
2460 rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]);
2461 fossil_print("Time differences: %s\n", db_timespan_name(rDiff));
2462 sqlite3_close(g.db);
2463 g.db = 0;
2464 }
2465
2466 /*
2467 ** COMMAND: test-without-rowid
2468 ** %fossil test-without-rowid FILENAME...
2469 **
2470 ** Change the Fossil repository FILENAME to make use of the WITHOUT ROWID
2471 ** optimization. FILENAME can also be the ~/.fossil file or a local
2472 ** .fslckout or _FOSSIL_ file.
2473 **
2474 ** The purpose of this command is for testing the WITHOUT ROWID capabilities
2475 ** of SQLite. There is no big advantage to using WITHOUT ROWID in Fossil.
2476 **
2477 ** Options:
2478 ** --dryrun | -n No changes. Just print what would happen.
2479 */
2480 void test_without_rowid(void){
2481 int i, j;
2482 Stmt q;
2483 Blob allSql;
2484 int dryRun = find_option("dry-run", "n", 0)!=0;
2485 for(i=2; i<g.argc; i++){
2486 db_open_or_attach(g.argv[i], "main", 0);
2487 blob_init(&allSql, "BEGIN;\n", -1);
2488 db_prepare(&q,
2489 "SELECT name, sql FROM main.sqlite_master "
2490 " WHERE type='table' AND sql NOT LIKE '%%WITHOUT ROWID%%'"
2491 " AND name IN ('global_config','shun','concealed','config',"
2492 " 'plink','tagxref','backlink','vcache');"
2493 );
2494 while( db_step(&q)==SQLITE_ROW ){
2495 const char *zTName = db_column_text(&q, 0);
2496 const char *zOrigSql = db_column_text(&q, 1);
2497 Blob newSql;
2498 blob_init(&newSql, 0, 0);
2499 for(j=0; zOrigSql[j]; j++){
2500 if( fossil_strnicmp(zOrigSql+j,"unique",6)==0 ){
2501 blob_append(&newSql, zOrigSql, j);
2502 blob_append(&newSql, "PRIMARY KEY", -1);
2503 zOrigSql += j+6;
2504 j = -1;
2505 }
2506 }
2507 blob_append(&newSql, zOrigSql, -1);
2508 blob_appendf(&allSql,
2509 "ALTER TABLE %s RENAME TO x_%s;\n"
2510 "%s WITHOUT ROWID;\n"
2511 "INSERT INTO %s SELECT * FROM x_%s;\n"
2512 "DROP TABLE x_%s;\n",
2513 zTName, zTName, blob_str(&newSql), zTName, zTName, zTName
2514 );
2515 fossil_print("Converting table %s of %s to WITHOUT ROWID.\n", zTName, g.argv[i]);
2516 blob_reset(&newSql);
2517 }
2518 blob_appendf(&allSql, "COMMIT;\n");
2519 db_finalize(&q);
2520 if( dryRun ){
2521 fossil_print("SQL that would have been evaluated:\n");
2522 fossil_print("-------------------------------------------------------------\n");
2523 fossil_print("%s", blob_str(&allSql));
2524 }else{
2525 db_multi_exec("%s", blob_str(&allSql));
2526 }
2527 blob_reset(&allSql);
2528 db_close(1);
2529 }
2530 }
2531
--- src/descendants.c
+++ src/descendants.c
@@ -329,11 +329,11 @@
329329
"%s"
330330
" AND event.objid IN (SELECT rid FROM leaves)"
331331
" ORDER BY event.mtime DESC",
332332
timeline_query_for_tty()
333333
);
334
- print_timeline(&q, 20, 0);
334
+ print_timeline(&q, -20, 79, 0);
335335
db_finalize(&q);
336336
}
337337
338338
/*
339339
** COMMAND: leaves*
340340
--- src/descendants.c
+++ src/descendants.c
@@ -329,11 +329,11 @@
329 "%s"
330 " AND event.objid IN (SELECT rid FROM leaves)"
331 " ORDER BY event.mtime DESC",
332 timeline_query_for_tty()
333 );
334 print_timeline(&q, 20, 0);
335 db_finalize(&q);
336 }
337
338 /*
339 ** COMMAND: leaves*
340
--- src/descendants.c
+++ src/descendants.c
@@ -329,11 +329,11 @@
329 "%s"
330 " AND event.objid IN (SELECT rid FROM leaves)"
331 " ORDER BY event.mtime DESC",
332 timeline_query_for_tty()
333 );
334 print_timeline(&q, -20, 79, 0);
335 db_finalize(&q);
336 }
337
338 /*
339 ** COMMAND: leaves*
340
+12 -4
--- src/finfo.c
+++ src/finfo.c
@@ -43,16 +43,18 @@
4343
** Options:
4444
** -b|--brief display a brief (one line / revision) summary
4545
** --case-sensitive B Enable or disable case-sensitive filenames. B is a
4646
** boolean: "yes", "no", "true", "false", etc.
4747
** -l|--log select log mode (the default)
48
-** -n|--limit N display the first N changes
48
+** -n|--limit N display the first N changes. N=0 means no limit.
4949
** --offset P skip P changes
5050
** -p|--print select print mode
5151
** -r|--revision R print the given revision (or ckout, if none is given)
5252
** to stdout (only in print mode)
5353
** -s|--status select status mode (print a status indicator for FILE)
54
+** -W|--width <num> With of lines (default 79). Must be >22 or 0
55
+** (= no limit, resulting in a single line per entry).
5456
**
5557
** See also: artifact, cat, descendants, info, leaves
5658
*/
5759
void finfo_cmd(void){
5860
capture_case_sensitive_option();
@@ -134,21 +136,27 @@
134136
Stmt q;
135137
Blob fname;
136138
int rid;
137139
const char *zFilename;
138140
const char *zLimit;
141
+ const char *zWidth;
139142
const char *zOffset;
140
- int iLimit, iOffset, iBrief;
143
+ int iLimit, iOffset, iBrief, iWidth;
141144
142145
if( find_option("log","l",0) ){
143146
/* this is the default, no-op */
144147
}
145148
zLimit = find_option("limit","n",1);
149
+ zWidth = find_option("width","W",1);
146150
iLimit = zLimit ? atoi(zLimit) : -1;
151
+ iWidth = zWidth ? atoi(zWidth) : 79;
147152
zOffset = find_option("offset",0,1);
148153
iOffset = zOffset ? atoi(zOffset) : 0;
149154
iBrief = (find_option("brief","b",0) == 0);
155
+ if( (iWidth!=0) && (iWidth<=22) ){
156
+ fossil_fatal("--width|-W value must be >22 or 0");
157
+ }
150158
if( g.argc!=3 ){
151159
usage("?-l|--log? ?-b|--brief? FILENAME");
152160
}
153161
file_tree_name(g.argv[2], &fname, 1);
154162
rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
@@ -188,20 +196,20 @@
188196
if( iBrief ){
189197
fossil_print("%s ", zDate);
190198
zOut = sqlite3_mprintf(
191199
"[%.10s] %s (user: %s, artifact: [%.10s], branch: %s)",
192200
zCiUuid, zCom, zUser, zFileUuid, zBr);
193
- comment_print(zOut, 11, 79);
201
+ comment_print(zOut, 11, iWidth);
194202
sqlite3_free(zOut);
195203
}else{
196204
blob_reset(&line);
197205
blob_appendf(&line, "%.10s ", zCiUuid);
198206
blob_appendf(&line, "%.10s ", zDate);
199207
blob_appendf(&line, "%8.8s ", zUser);
200208
blob_appendf(&line, "%8.8s ", zBr);
201209
blob_appendf(&line,"%-39.39s", zCom );
202
- comment_print(blob_str(&line), 0, 79);
210
+ comment_print(blob_str(&line), 0, iWidth);
203211
}
204212
}
205213
db_finalize(&q);
206214
blob_reset(&fname);
207215
}
208216
--- src/finfo.c
+++ src/finfo.c
@@ -43,16 +43,18 @@
43 ** Options:
44 ** -b|--brief display a brief (one line / revision) summary
45 ** --case-sensitive B Enable or disable case-sensitive filenames. B is a
46 ** boolean: "yes", "no", "true", "false", etc.
47 ** -l|--log select log mode (the default)
48 ** -n|--limit N display the first N changes
49 ** --offset P skip P changes
50 ** -p|--print select print mode
51 ** -r|--revision R print the given revision (or ckout, if none is given)
52 ** to stdout (only in print mode)
53 ** -s|--status select status mode (print a status indicator for FILE)
 
 
54 **
55 ** See also: artifact, cat, descendants, info, leaves
56 */
57 void finfo_cmd(void){
58 capture_case_sensitive_option();
@@ -134,21 +136,27 @@
134 Stmt q;
135 Blob fname;
136 int rid;
137 const char *zFilename;
138 const char *zLimit;
 
139 const char *zOffset;
140 int iLimit, iOffset, iBrief;
141
142 if( find_option("log","l",0) ){
143 /* this is the default, no-op */
144 }
145 zLimit = find_option("limit","n",1);
 
146 iLimit = zLimit ? atoi(zLimit) : -1;
 
147 zOffset = find_option("offset",0,1);
148 iOffset = zOffset ? atoi(zOffset) : 0;
149 iBrief = (find_option("brief","b",0) == 0);
 
 
 
150 if( g.argc!=3 ){
151 usage("?-l|--log? ?-b|--brief? FILENAME");
152 }
153 file_tree_name(g.argv[2], &fname, 1);
154 rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
@@ -188,20 +196,20 @@
188 if( iBrief ){
189 fossil_print("%s ", zDate);
190 zOut = sqlite3_mprintf(
191 "[%.10s] %s (user: %s, artifact: [%.10s], branch: %s)",
192 zCiUuid, zCom, zUser, zFileUuid, zBr);
193 comment_print(zOut, 11, 79);
194 sqlite3_free(zOut);
195 }else{
196 blob_reset(&line);
197 blob_appendf(&line, "%.10s ", zCiUuid);
198 blob_appendf(&line, "%.10s ", zDate);
199 blob_appendf(&line, "%8.8s ", zUser);
200 blob_appendf(&line, "%8.8s ", zBr);
201 blob_appendf(&line,"%-39.39s", zCom );
202 comment_print(blob_str(&line), 0, 79);
203 }
204 }
205 db_finalize(&q);
206 blob_reset(&fname);
207 }
208
--- src/finfo.c
+++ src/finfo.c
@@ -43,16 +43,18 @@
43 ** Options:
44 ** -b|--brief display a brief (one line / revision) summary
45 ** --case-sensitive B Enable or disable case-sensitive filenames. B is a
46 ** boolean: "yes", "no", "true", "false", etc.
47 ** -l|--log select log mode (the default)
48 ** -n|--limit N display the first N changes. N=0 means no limit.
49 ** --offset P skip P changes
50 ** -p|--print select print mode
51 ** -r|--revision R print the given revision (or ckout, if none is given)
52 ** to stdout (only in print mode)
53 ** -s|--status select status mode (print a status indicator for FILE)
54 ** -W|--width <num> With of lines (default 79). Must be >22 or 0
55 ** (= no limit, resulting in a single line per entry).
56 **
57 ** See also: artifact, cat, descendants, info, leaves
58 */
59 void finfo_cmd(void){
60 capture_case_sensitive_option();
@@ -134,21 +136,27 @@
136 Stmt q;
137 Blob fname;
138 int rid;
139 const char *zFilename;
140 const char *zLimit;
141 const char *zWidth;
142 const char *zOffset;
143 int iLimit, iOffset, iBrief, iWidth;
144
145 if( find_option("log","l",0) ){
146 /* this is the default, no-op */
147 }
148 zLimit = find_option("limit","n",1);
149 zWidth = find_option("width","W",1);
150 iLimit = zLimit ? atoi(zLimit) : -1;
151 iWidth = zWidth ? atoi(zWidth) : 79;
152 zOffset = find_option("offset",0,1);
153 iOffset = zOffset ? atoi(zOffset) : 0;
154 iBrief = (find_option("brief","b",0) == 0);
155 if( (iWidth!=0) && (iWidth<=22) ){
156 fossil_fatal("--width|-W value must be >22 or 0");
157 }
158 if( g.argc!=3 ){
159 usage("?-l|--log? ?-b|--brief? FILENAME");
160 }
161 file_tree_name(g.argv[2], &fname, 1);
162 rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
@@ -188,20 +196,20 @@
196 if( iBrief ){
197 fossil_print("%s ", zDate);
198 zOut = sqlite3_mprintf(
199 "[%.10s] %s (user: %s, artifact: [%.10s], branch: %s)",
200 zCiUuid, zCom, zUser, zFileUuid, zBr);
201 comment_print(zOut, 11, iWidth);
202 sqlite3_free(zOut);
203 }else{
204 blob_reset(&line);
205 blob_appendf(&line, "%.10s ", zCiUuid);
206 blob_appendf(&line, "%.10s ", zDate);
207 blob_appendf(&line, "%8.8s ", zUser);
208 blob_appendf(&line, "%8.8s ", zBr);
209 blob_appendf(&line,"%-39.39s", zCom );
210 comment_print(blob_str(&line), 0, iWidth);
211 }
212 }
213 db_finalize(&q);
214 blob_reset(&fname);
215 }
216
+1 -1
--- src/json.c
+++ src/json.c
@@ -987,11 +987,11 @@
987987
if(!jfile || !*jfile){
988988
break;
989989
}
990990
inFile = (0==strcmp("-",jfile))
991991
? stdin
992
- : fopen(jfile,"rb");
992
+ : fossil_fopen(jfile,"rb");
993993
if(!inFile){
994994
g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
995995
fossil_fatal("Could not open JSON file [%s].",jfile)
996996
/* Does not return. */
997997
;
998998
--- src/json.c
+++ src/json.c
@@ -987,11 +987,11 @@
987 if(!jfile || !*jfile){
988 break;
989 }
990 inFile = (0==strcmp("-",jfile))
991 ? stdin
992 : fopen(jfile,"rb");
993 if(!inFile){
994 g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
995 fossil_fatal("Could not open JSON file [%s].",jfile)
996 /* Does not return. */
997 ;
998
--- src/json.c
+++ src/json.c
@@ -987,11 +987,11 @@
987 if(!jfile || !*jfile){
988 break;
989 }
990 inFile = (0==strcmp("-",jfile))
991 ? stdin
992 : fossil_fopen(jfile,"rb");
993 if(!inFile){
994 g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
995 fossil_fatal("Could not open JSON file [%s].",jfile)
996 /* Does not return. */
997 ;
998
+7 -1
--- src/login.c
+++ src/login.c
@@ -778,10 +778,11 @@
778778
const char *zCookie; /* Text of the login cookie */
779779
const char *zIpAddr; /* Raw IP address of the requestor */
780780
char *zRemoteAddr; /* Abbreviated IP address of the requestor */
781781
const char *zCap = 0; /* Capability string */
782782
const char *zPublicPages = 0; /* GLOB patterns of public pages */
783
+ const char *zLogin = 0; /* Login user for credentials */
783784
784785
/* Only run this check once. */
785786
if( g.userUid!=0 ) return;
786787
787788
sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
@@ -799,11 +800,16 @@
799800
g.fSshClient & CGI_SSH_CLIENT )
800801
&& g.useLocalauth
801802
&& db_get_int("localauth",0)==0
802803
&& P("HTTPS")==0
803804
){
804
- uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
805
+ if( g.localOpen ) zLogin = db_lget("default-user",0);
806
+ if( zLogin!=0 ){
807
+ uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zLogin);
808
+ }else{
809
+ uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
810
+ }
805811
g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid);
806812
zCap = "sx";
807813
g.noPswd = 1;
808814
g.isHuman = 1;
809815
sqlite3_snprintf(sizeof(g.zCsrfToken), g.zCsrfToken, "localhost");
810816
--- src/login.c
+++ src/login.c
@@ -778,10 +778,11 @@
778 const char *zCookie; /* Text of the login cookie */
779 const char *zIpAddr; /* Raw IP address of the requestor */
780 char *zRemoteAddr; /* Abbreviated IP address of the requestor */
781 const char *zCap = 0; /* Capability string */
782 const char *zPublicPages = 0; /* GLOB patterns of public pages */
 
783
784 /* Only run this check once. */
785 if( g.userUid!=0 ) return;
786
787 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
@@ -799,11 +800,16 @@
799 g.fSshClient & CGI_SSH_CLIENT )
800 && g.useLocalauth
801 && db_get_int("localauth",0)==0
802 && P("HTTPS")==0
803 ){
804 uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
 
 
 
 
 
805 g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid);
806 zCap = "sx";
807 g.noPswd = 1;
808 g.isHuman = 1;
809 sqlite3_snprintf(sizeof(g.zCsrfToken), g.zCsrfToken, "localhost");
810
--- src/login.c
+++ src/login.c
@@ -778,10 +778,11 @@
778 const char *zCookie; /* Text of the login cookie */
779 const char *zIpAddr; /* Raw IP address of the requestor */
780 char *zRemoteAddr; /* Abbreviated IP address of the requestor */
781 const char *zCap = 0; /* Capability string */
782 const char *zPublicPages = 0; /* GLOB patterns of public pages */
783 const char *zLogin = 0; /* Login user for credentials */
784
785 /* Only run this check once. */
786 if( g.userUid!=0 ) return;
787
788 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
@@ -799,11 +800,16 @@
800 g.fSshClient & CGI_SSH_CLIENT )
801 && g.useLocalauth
802 && db_get_int("localauth",0)==0
803 && P("HTTPS")==0
804 ){
805 if( g.localOpen ) zLogin = db_lget("default-user",0);
806 if( zLogin!=0 ){
807 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zLogin);
808 }else{
809 uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
810 }
811 g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid);
812 zCap = "sx";
813 g.noPswd = 1;
814 g.isHuman = 1;
815 sqlite3_snprintf(sizeof(g.zCsrfToken), g.zCsrfToken, "localhost");
816
+9 -2
--- src/main.c
+++ src/main.c
@@ -807,10 +807,18 @@
807807
multi_column_list(aCmd, nCmd);
808808
}
809809
810810
811811
812
+/*
813
+** This function returns a human readable version string.
814
+*/
815
+const char *get_version(){
816
+ static const char version[] = RELEASE_VERSION " " MANIFEST_VERSION " "
817
+ MANIFEST_DATE " UTC";
818
+ return version;
819
+}
812820
813821
/*
814822
** COMMAND: version
815823
**
816824
** Usage: %fossil version ?-verbose|-v?
@@ -819,12 +827,11 @@
819827
** If the verbose option is specified, additional details will
820828
** be output about what optional features this binary was compiled
821829
** with
822830
*/
823831
void version_cmd(void){
824
- fossil_print("This is fossil version " RELEASE_VERSION " "
825
- MANIFEST_VERSION " " MANIFEST_DATE " UTC\n");
832
+ fossil_print("This is fossil version %s\n", get_version());
826833
if(!find_option("verbose","v",0)){
827834
return;
828835
}else{
829836
#if defined(FOSSIL_ENABLE_TCL)
830837
int rc;
831838
--- src/main.c
+++ src/main.c
@@ -807,10 +807,18 @@
807 multi_column_list(aCmd, nCmd);
808 }
809
810
811
 
 
 
 
 
 
 
 
812
813 /*
814 ** COMMAND: version
815 **
816 ** Usage: %fossil version ?-verbose|-v?
@@ -819,12 +827,11 @@
819 ** If the verbose option is specified, additional details will
820 ** be output about what optional features this binary was compiled
821 ** with
822 */
823 void version_cmd(void){
824 fossil_print("This is fossil version " RELEASE_VERSION " "
825 MANIFEST_VERSION " " MANIFEST_DATE " UTC\n");
826 if(!find_option("verbose","v",0)){
827 return;
828 }else{
829 #if defined(FOSSIL_ENABLE_TCL)
830 int rc;
831
--- src/main.c
+++ src/main.c
@@ -807,10 +807,18 @@
807 multi_column_list(aCmd, nCmd);
808 }
809
810
811
812 /*
813 ** This function returns a human readable version string.
814 */
815 const char *get_version(){
816 static const char version[] = RELEASE_VERSION " " MANIFEST_VERSION " "
817 MANIFEST_DATE " UTC";
818 return version;
819 }
820
821 /*
822 ** COMMAND: version
823 **
824 ** Usage: %fossil version ?-verbose|-v?
@@ -819,12 +827,11 @@
827 ** If the verbose option is specified, additional details will
828 ** be output about what optional features this binary was compiled
829 ** with
830 */
831 void version_cmd(void){
832 fossil_print("This is fossil version %s\n", get_version());
 
833 if(!find_option("verbose","v",0)){
834 return;
835 }else{
836 #if defined(FOSSIL_ENABLE_TCL)
837 int rc;
838
+9 -2
--- src/main.c
+++ src/main.c
@@ -807,10 +807,18 @@
807807
multi_column_list(aCmd, nCmd);
808808
}
809809
810810
811811
812
+/*
813
+** This function returns a human readable version string.
814
+*/
815
+const char *get_version(){
816
+ static const char version[] = RELEASE_VERSION " " MANIFEST_VERSION " "
817
+ MANIFEST_DATE " UTC";
818
+ return version;
819
+}
812820
813821
/*
814822
** COMMAND: version
815823
**
816824
** Usage: %fossil version ?-verbose|-v?
@@ -819,12 +827,11 @@
819827
** If the verbose option is specified, additional details will
820828
** be output about what optional features this binary was compiled
821829
** with
822830
*/
823831
void version_cmd(void){
824
- fossil_print("This is fossil version " RELEASE_VERSION " "
825
- MANIFEST_VERSION " " MANIFEST_DATE " UTC\n");
832
+ fossil_print("This is fossil version %s\n", get_version());
826833
if(!find_option("verbose","v",0)){
827834
return;
828835
}else{
829836
#if defined(FOSSIL_ENABLE_TCL)
830837
int rc;
831838
--- src/main.c
+++ src/main.c
@@ -807,10 +807,18 @@
807 multi_column_list(aCmd, nCmd);
808 }
809
810
811
 
 
 
 
 
 
 
 
812
813 /*
814 ** COMMAND: version
815 **
816 ** Usage: %fossil version ?-verbose|-v?
@@ -819,12 +827,11 @@
819 ** If the verbose option is specified, additional details will
820 ** be output about what optional features this binary was compiled
821 ** with
822 */
823 void version_cmd(void){
824 fossil_print("This is fossil version " RELEASE_VERSION " "
825 MANIFEST_VERSION " " MANIFEST_DATE " UTC\n");
826 if(!find_option("verbose","v",0)){
827 return;
828 }else{
829 #if defined(FOSSIL_ENABLE_TCL)
830 int rc;
831
--- src/main.c
+++ src/main.c
@@ -807,10 +807,18 @@
807 multi_column_list(aCmd, nCmd);
808 }
809
810
811
812 /*
813 ** This function returns a human readable version string.
814 */
815 const char *get_version(){
816 static const char version[] = RELEASE_VERSION " " MANIFEST_VERSION " "
817 MANIFEST_DATE " UTC";
818 return version;
819 }
820
821 /*
822 ** COMMAND: version
823 **
824 ** Usage: %fossil version ?-verbose|-v?
@@ -819,12 +827,11 @@
827 ** If the verbose option is specified, additional details will
828 ** be output about what optional features this binary was compiled
829 ** with
830 */
831 void version_cmd(void){
832 fossil_print("This is fossil version %s\n", get_version());
 
833 if(!find_option("verbose","v",0)){
834 return;
835 }else{
836 #if defined(FOSSIL_ENABLE_TCL)
837 int rc;
838
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -781,10 +781,13 @@
781781
writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
782782
writeln "\$(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\n"
783783
784784
writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
785785
set opt {-Dmain=sqlite3_shell}
786
+append opt " -Dsqlite3_strglob=strglob"
787
+append opt " -Dgetenv=fossil_getenv"
788
+append opt " -Dfopen=fossil_fopen"
786789
append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
787790
writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
788791
789792
writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
790793
writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
@@ -888,11 +891,11 @@
888891
889892
version$E: $B\src\mkversion.c
890893
$(BCC) -o$@ $**
891894
892895
$(OBJDIR)\shell$O : $(SRCDIR)\shell.c
893
- $(TCC) -o$@ -c -Dmain=sqlite3_shell $(SQLITE_OPTIONS) $**
896
+ $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
894897
895898
$(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
896899
$(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
897900
898901
$(OBJDIR)\th$O : $(SRCDIR)\th.c
@@ -1091,11 +1094,11 @@
10911094
10921095
mkversion$E: $B\src\mkversion.c
10931096
$(BCC) $**
10941097
10951098
$(OX)\shell$O : $(SRCDIR)\shell.c
1096
- $(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
1099
+ $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
10971100
10981101
$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
10991102
$(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
11001103
11011104
$(OX)\th$O : $(SRCDIR)\th.c
@@ -1277,11 +1280,11 @@
12771280
12781281
# define the sqlite shell files, which need special flags on compile
12791282
SQLITESHELLSRC=shell.c
12801283
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
12811284
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1282
-SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob
1285
+SQLITESHELLDEFINES=-Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
12831286
12841287
# define the th scripting files, which need special flags on compile
12851288
THSRC=th.c th_lang.c
12861289
ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
12871290
THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
12881291
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -781,10 +781,13 @@
781 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
782 writeln "\$(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\n"
783
784 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
785 set opt {-Dmain=sqlite3_shell}
 
 
 
786 append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
787 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
788
789 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
790 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
@@ -888,11 +891,11 @@
888
889 version$E: $B\src\mkversion.c
890 $(BCC) -o$@ $**
891
892 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
893 $(TCC) -o$@ -c -Dmain=sqlite3_shell $(SQLITE_OPTIONS) $**
894
895 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
896 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
897
898 $(OBJDIR)\th$O : $(SRCDIR)\th.c
@@ -1091,11 +1094,11 @@
1091
1092 mkversion$E: $B\src\mkversion.c
1093 $(BCC) $**
1094
1095 $(OX)\shell$O : $(SRCDIR)\shell.c
1096 $(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
1097
1098 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
1099 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
1100
1101 $(OX)\th$O : $(SRCDIR)\th.c
@@ -1277,11 +1280,11 @@
1277
1278 # define the sqlite shell files, which need special flags on compile
1279 SQLITESHELLSRC=shell.c
1280 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
1281 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1282 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob
1283
1284 # define the th scripting files, which need special flags on compile
1285 THSRC=th.c th_lang.c
1286 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
1287 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
1288
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -781,10 +781,13 @@
781 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
782 writeln "\$(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\n"
783
784 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
785 set opt {-Dmain=sqlite3_shell}
786 append opt " -Dsqlite3_strglob=strglob"
787 append opt " -Dgetenv=fossil_getenv"
788 append opt " -Dfopen=fossil_fopen"
789 append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
790 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
791
792 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
793 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
@@ -888,11 +891,11 @@
891
892 version$E: $B\src\mkversion.c
893 $(BCC) -o$@ $**
894
895 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
896 $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
897
898 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
899 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
900
901 $(OBJDIR)\th$O : $(SRCDIR)\th.c
@@ -1091,11 +1094,11 @@
1094
1095 mkversion$E: $B\src\mkversion.c
1096 $(BCC) $**
1097
1098 $(OX)\shell$O : $(SRCDIR)\shell.c
1099 $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
1100
1101 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
1102 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
1103
1104 $(OX)\th$O : $(SRCDIR)\th.c
@@ -1277,11 +1280,11 @@
1280
1281 # define the sqlite shell files, which need special flags on compile
1282 SQLITESHELLSRC=shell.c
1283 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
1284 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1285 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
1286
1287 # define the th scripting files, which need special flags on compile
1288 THSRC=th.c th_lang.c
1289 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
1290 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
1291
+2 -2
--- src/manifest.c
+++ src/manifest.c
@@ -1899,11 +1899,11 @@
18991899
|| !validate16(p->zAttachTarget, UUID_SIZE)
19001900
){
19011901
char *zComment;
19021902
if( p->zAttachSrc && p->zAttachSrc[0] ){
19031903
zComment = mprintf(
1904
- "Add attachment [%R/artifact/%S|%h] to wiki page [%h]",
1904
+ "Add attachment [/artifact/%S|%h] to wiki page [%h]",
19051905
p->zAttachSrc, p->zAttachName, p->zAttachTarget);
19061906
}else{
19071907
zComment = mprintf("Delete attachment \"%h\" from wiki page [%h]",
19081908
p->zAttachName, p->zAttachTarget);
19091909
}
@@ -1915,11 +1915,11 @@
19151915
free(zComment);
19161916
}else{
19171917
char *zComment;
19181918
if( p->zAttachSrc && p->zAttachSrc[0] ){
19191919
zComment = mprintf(
1920
- "Add attachment [%R/artifact/%S|%h] to ticket [%S]",
1920
+ "Add attachment [/artifact/%S|%h] to ticket [%S]",
19211921
p->zAttachSrc, p->zAttachName, p->zAttachTarget);
19221922
}else{
19231923
zComment = mprintf("Delete attachment \"%h\" from ticket [%.10s]",
19241924
p->zAttachName, p->zAttachTarget);
19251925
}
19261926
--- src/manifest.c
+++ src/manifest.c
@@ -1899,11 +1899,11 @@
1899 || !validate16(p->zAttachTarget, UUID_SIZE)
1900 ){
1901 char *zComment;
1902 if( p->zAttachSrc && p->zAttachSrc[0] ){
1903 zComment = mprintf(
1904 "Add attachment [%R/artifact/%S|%h] to wiki page [%h]",
1905 p->zAttachSrc, p->zAttachName, p->zAttachTarget);
1906 }else{
1907 zComment = mprintf("Delete attachment \"%h\" from wiki page [%h]",
1908 p->zAttachName, p->zAttachTarget);
1909 }
@@ -1915,11 +1915,11 @@
1915 free(zComment);
1916 }else{
1917 char *zComment;
1918 if( p->zAttachSrc && p->zAttachSrc[0] ){
1919 zComment = mprintf(
1920 "Add attachment [%R/artifact/%S|%h] to ticket [%S]",
1921 p->zAttachSrc, p->zAttachName, p->zAttachTarget);
1922 }else{
1923 zComment = mprintf("Delete attachment \"%h\" from ticket [%.10s]",
1924 p->zAttachName, p->zAttachTarget);
1925 }
1926
--- src/manifest.c
+++ src/manifest.c
@@ -1899,11 +1899,11 @@
1899 || !validate16(p->zAttachTarget, UUID_SIZE)
1900 ){
1901 char *zComment;
1902 if( p->zAttachSrc && p->zAttachSrc[0] ){
1903 zComment = mprintf(
1904 "Add attachment [/artifact/%S|%h] to wiki page [%h]",
1905 p->zAttachSrc, p->zAttachName, p->zAttachTarget);
1906 }else{
1907 zComment = mprintf("Delete attachment \"%h\" from wiki page [%h]",
1908 p->zAttachName, p->zAttachTarget);
1909 }
@@ -1915,11 +1915,11 @@
1915 free(zComment);
1916 }else{
1917 char *zComment;
1918 if( p->zAttachSrc && p->zAttachSrc[0] ){
1919 zComment = mprintf(
1920 "Add attachment [/artifact/%S|%h] to ticket [%S]",
1921 p->zAttachSrc, p->zAttachName, p->zAttachTarget);
1922 }else{
1923 zComment = mprintf("Delete attachment \"%h\" from ticket [%.10s]",
1924 p->zAttachName, p->zAttachTarget);
1925 }
1926
+6 -2
--- src/printf.c
+++ src/printf.c
@@ -922,11 +922,11 @@
922922
va_list ap;
923923
static const char *azEnv[] = { "HTTP_HOST", "HTTP_USER_AGENT",
924924
"PATH_INFO", "QUERY_STRING", "REMOTE_ADDR", "REQUEST_METHOD",
925925
"REQUEST_URI", "SCRIPT_NAME" };
926926
if( g.zErrlog==0 ) return;
927
- out = fopen(g.zErrlog, "a");
927
+ out = fossil_fopen(g.zErrlog, "a");
928928
if( out==0 ) return;
929929
now = time(0);
930930
pNow = gmtime(&now);
931931
fprintf(out, "------------- %04d-%02d-%02d %02d:%02d:%02d UTC ------------\n",
932932
pNow->tm_year+1900, pNow->tm_mon+1, pNow->tm_mday+1,
@@ -934,11 +934,15 @@
934934
va_start(ap, zFormat);
935935
vfprintf(out, zFormat, ap);
936936
fprintf(out, "\n");
937937
va_end(ap);
938938
for(i=0; i<sizeof(azEnv)/sizeof(azEnv[0]); i++){
939
- if( (z = getenv(azEnv[i]))!=0 || (z = P(azEnv[i]))!=0 ){
939
+ char *p;
940
+ if( (p = fossil_getenv(azEnv[i]))!=0 ){
941
+ fprintf(out, "%s=%s\n", azEnv[i], p);
942
+ fossil_filename_free(p);
943
+ }else if( (z = P(azEnv[i]))!=0 ){
940944
fprintf(out, "%s=%s\n", azEnv[i], z);
941945
}
942946
}
943947
fclose(out);
944948
}
945949
--- src/printf.c
+++ src/printf.c
@@ -922,11 +922,11 @@
922 va_list ap;
923 static const char *azEnv[] = { "HTTP_HOST", "HTTP_USER_AGENT",
924 "PATH_INFO", "QUERY_STRING", "REMOTE_ADDR", "REQUEST_METHOD",
925 "REQUEST_URI", "SCRIPT_NAME" };
926 if( g.zErrlog==0 ) return;
927 out = fopen(g.zErrlog, "a");
928 if( out==0 ) return;
929 now = time(0);
930 pNow = gmtime(&now);
931 fprintf(out, "------------- %04d-%02d-%02d %02d:%02d:%02d UTC ------------\n",
932 pNow->tm_year+1900, pNow->tm_mon+1, pNow->tm_mday+1,
@@ -934,11 +934,15 @@
934 va_start(ap, zFormat);
935 vfprintf(out, zFormat, ap);
936 fprintf(out, "\n");
937 va_end(ap);
938 for(i=0; i<sizeof(azEnv)/sizeof(azEnv[0]); i++){
939 if( (z = getenv(azEnv[i]))!=0 || (z = P(azEnv[i]))!=0 ){
 
 
 
 
940 fprintf(out, "%s=%s\n", azEnv[i], z);
941 }
942 }
943 fclose(out);
944 }
945
--- src/printf.c
+++ src/printf.c
@@ -922,11 +922,11 @@
922 va_list ap;
923 static const char *azEnv[] = { "HTTP_HOST", "HTTP_USER_AGENT",
924 "PATH_INFO", "QUERY_STRING", "REMOTE_ADDR", "REQUEST_METHOD",
925 "REQUEST_URI", "SCRIPT_NAME" };
926 if( g.zErrlog==0 ) return;
927 out = fossil_fopen(g.zErrlog, "a");
928 if( out==0 ) return;
929 now = time(0);
930 pNow = gmtime(&now);
931 fprintf(out, "------------- %04d-%02d-%02d %02d:%02d:%02d UTC ------------\n",
932 pNow->tm_year+1900, pNow->tm_mon+1, pNow->tm_mday+1,
@@ -934,11 +934,15 @@
934 va_start(ap, zFormat);
935 vfprintf(out, zFormat, ap);
936 fprintf(out, "\n");
937 va_end(ap);
938 for(i=0; i<sizeof(azEnv)/sizeof(azEnv[0]); i++){
939 char *p;
940 if( (p = fossil_getenv(azEnv[i]))!=0 ){
941 fprintf(out, "%s=%s\n", azEnv[i], p);
942 fossil_filename_free(p);
943 }else if( (z = P(azEnv[i]))!=0 ){
944 fprintf(out, "%s=%s\n", azEnv[i], z);
945 }
946 }
947 fclose(out);
948 }
949
+6 -3
--- src/rebuild.c
+++ src/rebuild.c
@@ -349,10 +349,11 @@
349349
" WHERE type='table'"
350350
" AND name NOT IN ('blob','delta','rcvfrom','user',"
351351
"'config','shun','private','reportfmt',"
352352
"'concealed','accesslog','modreq')"
353353
" AND name NOT GLOB 'sqlite_*'"
354
+ " AND name NOT GLOB 'fx_*'"
354355
);
355356
if( zTable==0 ) break;
356357
db_multi_exec("DROP TABLE %Q", zTable);
357358
free(zTable);
358359
}
@@ -580,12 +581,13 @@
580581
ttyOutput = 1;
581582
errCnt = rebuild_db(randomizeFlag, 1, doClustering);
582583
reconstruct_private_table();
583584
db_multi_exec(
584585
"REPLACE INTO config(name,value,mtime) VALUES('content-schema','%s',now());"
585
- "REPLACE INTO config(name,value,mtime) VALUES('aux-schema','%s',now());",
586
- CONTENT_SCHEMA, AUX_SCHEMA
586
+ "REPLACE INTO config(name,value,mtime) VALUES('aux-schema','%s',now());"
587
+ "REPLACE INTO config(name,value,mtime) VALUES('rebuilt','%s',now());",
588
+ CONTENT_SCHEMA, AUX_SCHEMA, get_version()
587589
);
588590
if( errCnt && !forceFlag ){
589591
fossil_print(
590592
"%d errors. Rolling back changes. Use --force to force a commit.\n",
591593
errCnt
@@ -606,11 +608,12 @@
606608
db_multi_exec("PRAGMA page_size=%d", newPagesize);
607609
runVacuum = 1;
608610
}
609611
if( runDeanalyze ){
610612
db_multi_exec("DROP TABLE IF EXISTS sqlite_stat1;"
611
- "DROP TABLE IF EXISTS sqlite_stat3;");
613
+ "DROP TABLE IF EXISTS sqlite_stat3;"
614
+ "DROP TABLE IF EXISTS sqlite_stat4;");
612615
}
613616
if( runAnalyze ){
614617
fossil_print("Analyzing the database... "); fflush(stdout);
615618
db_multi_exec("ANALYZE;");
616619
fossil_print("done\n");
617620
--- src/rebuild.c
+++ src/rebuild.c
@@ -349,10 +349,11 @@
349 " WHERE type='table'"
350 " AND name NOT IN ('blob','delta','rcvfrom','user',"
351 "'config','shun','private','reportfmt',"
352 "'concealed','accesslog','modreq')"
353 " AND name NOT GLOB 'sqlite_*'"
 
354 );
355 if( zTable==0 ) break;
356 db_multi_exec("DROP TABLE %Q", zTable);
357 free(zTable);
358 }
@@ -580,12 +581,13 @@
580 ttyOutput = 1;
581 errCnt = rebuild_db(randomizeFlag, 1, doClustering);
582 reconstruct_private_table();
583 db_multi_exec(
584 "REPLACE INTO config(name,value,mtime) VALUES('content-schema','%s',now());"
585 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema','%s',now());",
586 CONTENT_SCHEMA, AUX_SCHEMA
 
587 );
588 if( errCnt && !forceFlag ){
589 fossil_print(
590 "%d errors. Rolling back changes. Use --force to force a commit.\n",
591 errCnt
@@ -606,11 +608,12 @@
606 db_multi_exec("PRAGMA page_size=%d", newPagesize);
607 runVacuum = 1;
608 }
609 if( runDeanalyze ){
610 db_multi_exec("DROP TABLE IF EXISTS sqlite_stat1;"
611 "DROP TABLE IF EXISTS sqlite_stat3;");
 
612 }
613 if( runAnalyze ){
614 fossil_print("Analyzing the database... "); fflush(stdout);
615 db_multi_exec("ANALYZE;");
616 fossil_print("done\n");
617
--- src/rebuild.c
+++ src/rebuild.c
@@ -349,10 +349,11 @@
349 " WHERE type='table'"
350 " AND name NOT IN ('blob','delta','rcvfrom','user',"
351 "'config','shun','private','reportfmt',"
352 "'concealed','accesslog','modreq')"
353 " AND name NOT GLOB 'sqlite_*'"
354 " AND name NOT GLOB 'fx_*'"
355 );
356 if( zTable==0 ) break;
357 db_multi_exec("DROP TABLE %Q", zTable);
358 free(zTable);
359 }
@@ -580,12 +581,13 @@
581 ttyOutput = 1;
582 errCnt = rebuild_db(randomizeFlag, 1, doClustering);
583 reconstruct_private_table();
584 db_multi_exec(
585 "REPLACE INTO config(name,value,mtime) VALUES('content-schema','%s',now());"
586 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema','%s',now());"
587 "REPLACE INTO config(name,value,mtime) VALUES('rebuilt','%s',now());",
588 CONTENT_SCHEMA, AUX_SCHEMA, get_version()
589 );
590 if( errCnt && !forceFlag ){
591 fossil_print(
592 "%d errors. Rolling back changes. Use --force to force a commit.\n",
593 errCnt
@@ -606,11 +608,12 @@
608 db_multi_exec("PRAGMA page_size=%d", newPagesize);
609 runVacuum = 1;
610 }
611 if( runDeanalyze ){
612 db_multi_exec("DROP TABLE IF EXISTS sqlite_stat1;"
613 "DROP TABLE IF EXISTS sqlite_stat3;"
614 "DROP TABLE IF EXISTS sqlite_stat4;");
615 }
616 if( runAnalyze ){
617 fossil_print("Analyzing the database... "); fflush(stdout);
618 db_multi_exec("ANALYZE;");
619 fossil_print("done\n");
620
--- src/report.c
+++ src/report.c
@@ -183,10 +183,13 @@
183183
"event",
184184
"tag",
185185
"tagxref",
186186
};
187187
int i;
188
+ if( fossil_strncmp(zArg1, "fx_", 3)==0 ){
189
+ break;
190
+ }
188191
for(i=0; i<sizeof(azAllowed)/sizeof(azAllowed[0]); i++){
189192
if( fossil_stricmp(zArg1, azAllowed[i])==0 ) break;
190193
}
191194
if( i>=sizeof(azAllowed)/sizeof(azAllowed[0]) ){
192195
*(char**)pError = mprintf("access to table \"%s\" is restricted",zArg1);
193196
--- src/report.c
+++ src/report.c
@@ -183,10 +183,13 @@
183 "event",
184 "tag",
185 "tagxref",
186 };
187 int i;
 
 
 
188 for(i=0; i<sizeof(azAllowed)/sizeof(azAllowed[0]); i++){
189 if( fossil_stricmp(zArg1, azAllowed[i])==0 ) break;
190 }
191 if( i>=sizeof(azAllowed)/sizeof(azAllowed[0]) ){
192 *(char**)pError = mprintf("access to table \"%s\" is restricted",zArg1);
193
--- src/report.c
+++ src/report.c
@@ -183,10 +183,13 @@
183 "event",
184 "tag",
185 "tagxref",
186 };
187 int i;
188 if( fossil_strncmp(zArg1, "fx_", 3)==0 ){
189 break;
190 }
191 for(i=0; i<sizeof(azAllowed)/sizeof(azAllowed[0]); i++){
192 if( fossil_stricmp(zArg1, azAllowed[i])==0 ) break;
193 }
194 if( i>=sizeof(azAllowed)/sizeof(azAllowed[0]) ){
195 *(char**)pError = mprintf("access to table \"%s\" is restricted",zArg1);
196
+3 -6
--- src/search.c
+++ src/search.c
@@ -189,12 +189,12 @@
189189
int iBest;
190190
char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
191191
off the end of the
192192
results. */
193193
char const * zLimit = find_option("limit","n",1);
194
- int const nLimit = zLimit ? atoi(zLimit) : -1; /* Max number of entries
195
- to list */
194
+ int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching
195
+ lines/entries to list */
196196
197197
db_must_be_within_tree();
198198
if( g.argc<2 ) return;
199199
blob_init(&pattern, g.argv[2], -1);
200200
for(i=3; i<g.argc; i++){
@@ -220,13 +220,10 @@
220220
"WHERE 1 ", -1);
221221
if(!fAll){
222222
blob_appendf(&sql,"AND x>%d ", iBest/3);
223223
}
224224
blob_append(&sql, "ORDER BY x DESC, date DESC ", -1);
225
- if(nLimit>0){
226
- blob_appendf(&sql, "LIMIT %d", nLimit);
227
- }
228225
db_prepare(&q, blob_str(&sql));
229226
blob_reset(&sql);
230
- print_timeline(&q, 1000, 0);
227
+ print_timeline(&q, nLimit, 79, 0);
231228
db_finalize(&q);
232229
}
233230
--- src/search.c
+++ src/search.c
@@ -189,12 +189,12 @@
189 int iBest;
190 char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
191 off the end of the
192 results. */
193 char const * zLimit = find_option("limit","n",1);
194 int const nLimit = zLimit ? atoi(zLimit) : -1; /* Max number of entries
195 to list */
196
197 db_must_be_within_tree();
198 if( g.argc<2 ) return;
199 blob_init(&pattern, g.argv[2], -1);
200 for(i=3; i<g.argc; i++){
@@ -220,13 +220,10 @@
220 "WHERE 1 ", -1);
221 if(!fAll){
222 blob_appendf(&sql,"AND x>%d ", iBest/3);
223 }
224 blob_append(&sql, "ORDER BY x DESC, date DESC ", -1);
225 if(nLimit>0){
226 blob_appendf(&sql, "LIMIT %d", nLimit);
227 }
228 db_prepare(&q, blob_str(&sql));
229 blob_reset(&sql);
230 print_timeline(&q, 1000, 0);
231 db_finalize(&q);
232 }
233
--- src/search.c
+++ src/search.c
@@ -189,12 +189,12 @@
189 int iBest;
190 char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
191 off the end of the
192 results. */
193 char const * zLimit = find_option("limit","n",1);
194 int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching
195 lines/entries to list */
196
197 db_must_be_within_tree();
198 if( g.argc<2 ) return;
199 blob_init(&pattern, g.argv[2], -1);
200 for(i=3; i<g.argc; i++){
@@ -220,13 +220,10 @@
220 "WHERE 1 ", -1);
221 if(!fAll){
222 blob_appendf(&sql,"AND x>%d ", iBest/3);
223 }
224 blob_append(&sql, "ORDER BY x DESC, date DESC ", -1);
 
 
 
225 db_prepare(&q, blob_str(&sql));
226 blob_reset(&sql);
227 print_timeline(&q, nLimit, 79, 0);
228 db_finalize(&q);
229 }
230
+71 -23
--- src/shell.c
+++ src/shell.c
@@ -84,32 +84,50 @@
8484
* overridden with the -batch command line option.
8585
*/
8686
#define isatty(x) 1
8787
#endif
8888
89
-/* True if the timer is enabled */
90
-static int enableTimer = 0;
91
-
9289
/* ctype macros that work with signed characters */
9390
#define IsSpace(X) isspace((unsigned char)X)
9491
#define IsDigit(X) isdigit((unsigned char)X)
9592
#define ToLower(X) (char)tolower((unsigned char)X)
9693
94
+
95
+/* True if the timer is enabled */
96
+static int enableTimer = 0;
97
+
98
+/* Return the current wall-clock time */
99
+static sqlite3_int64 timeOfDay(void){
100
+ static sqlite3_vfs *clockVfs = 0;
101
+ sqlite3_int64 t;
102
+ if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
103
+ if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
104
+ clockVfs->xCurrentTimeInt64(clockVfs, &t);
105
+ }else{
106
+ double r;
107
+ clockVfs->xCurrentTime(clockVfs, &r);
108
+ t = (sqlite3_int64)(r*86400000.0);
109
+ }
110
+ return t;
111
+}
112
+
97113
#if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
98114
&& !defined(__minux)
99115
#include <sys/time.h>
100116
#include <sys/resource.h>
101117
102118
/* Saved resource information for the beginning of an operation */
103
-static struct rusage sBegin;
119
+static struct rusage sBegin; /* CPU time at start */
120
+static sqlite3_int64 iBegin; /* Wall-clock time at start */
104121
105122
/*
106123
** Begin timing an operation
107124
*/
108125
static void beginTimer(void){
109126
if( enableTimer ){
110127
getrusage(RUSAGE_SELF, &sBegin);
128
+ iBegin = timeOfDay();
111129
}
112130
}
113131
114132
/* Return the difference of two time_structs in seconds */
115133
static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
@@ -121,12 +139,14 @@
121139
** Print the timing results.
122140
*/
123141
static void endTimer(void){
124142
if( enableTimer ){
125143
struct rusage sEnd;
144
+ sqlite3_int64 iEnd = timeOfDay();
126145
getrusage(RUSAGE_SELF, &sEnd);
127
- printf("CPU Time: user %f sys %f\n",
146
+ printf("Run Time: real %.3f user %f sys %f\n",
147
+ (iEnd - iBegin)*0.001,
128148
timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
129149
timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
130150
}
131151
}
132152
@@ -140,10 +160,11 @@
140160
141161
/* Saved resource information for the beginning of an operation */
142162
static HANDLE hProcess;
143163
static FILETIME ftKernelBegin;
144164
static FILETIME ftUserBegin;
165
+static sqlite3_int64 ftWallBegin;
145166
typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
146167
static GETPROCTIMES getProcessTimesAddr = NULL;
147168
148169
/*
149170
** Check to see if we have timer support. Return 1 if necessary
@@ -177,10 +198,11 @@
177198
*/
178199
static void beginTimer(void){
179200
if( enableTimer && getProcessTimesAddr ){
180201
FILETIME ftCreation, ftExit;
181202
getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
203
+ ftWallBegin = timeOfDay();
182204
}
183205
}
184206
185207
/* Return the difference of two FILETIME structs in seconds */
186208
static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
@@ -193,12 +215,14 @@
193215
** Print the timing results.
194216
*/
195217
static void endTimer(void){
196218
if( enableTimer && getProcessTimesAddr){
197219
FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
220
+ sqlite3_int64 ftWallEnd = timeOfDay();
198221
getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
199
- printf("CPU Time: user %f sys %f\n",
222
+ printf("Run Time: real %.3f user %f sys %f\n",
223
+ (ftWallEnd - ftWallBegin)*0.001,
200224
timeDiff(&ftUserBegin, &ftUserEnd),
201225
timeDiff(&ftKernelBegin, &ftKernelEnd));
202226
}
203227
}
204228
@@ -434,10 +458,11 @@
434458
struct previous_mode_data explainPrev;
435459
/* Holds the mode information just before
436460
** .explain ON */
437461
char outfile[FILENAME_MAX]; /* Filename for *out */
438462
const char *zDbFilename; /* name of the database file */
463
+ char *zFreeOnClose; /* Filename to free when closing */
439464
const char *zVfs; /* Name of VFS to use */
440465
sqlite3_stmt *pStmt; /* Current statement if any. */
441466
FILE *pLog; /* Write log output here */
442467
};
443468
@@ -1435,10 +1460,11 @@
14351460
" line One value per line\n"
14361461
" list Values delimited by .separator string\n"
14371462
" tabs Tab-separated values\n"
14381463
" tcl TCL list elements\n"
14391464
".nullvalue STRING Use STRING in place of NULL values\n"
1465
+ ".open ?FILENAME? Close existing database and reopen FILENAME\n"
14401466
".output FILENAME Send output to FILENAME\n"
14411467
".output stdout Send output to the screen\n"
14421468
".print STRING... Print literal STRING\n"
14431469
".prompt MAIN CONTINUE Replace the standard prompts\n"
14441470
".quit Exit this program\n"
@@ -1468,11 +1494,11 @@
14681494
14691495
/*
14701496
** Make sure the database is open. If it is not, then open it. If
14711497
** the database fails to open, print an error message and exit.
14721498
*/
1473
-static void open_db(struct callback_data *p){
1499
+static void open_db(struct callback_data *p, int keepAlive){
14741500
if( p->db==0 ){
14751501
sqlite3_initialize();
14761502
sqlite3_open(p->zDbFilename, &p->db);
14771503
db = p->db;
14781504
if( db && sqlite3_errcode(db)==SQLITE_OK ){
@@ -1480,10 +1506,11 @@
14801506
shellstaticFunc, 0, 0);
14811507
}
14821508
if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
14831509
fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
14841510
p->zDbFilename, sqlite3_errmsg(db));
1511
+ if( keepAlive ) return;
14851512
exit(1);
14861513
}
14871514
#ifndef SQLITE_OMIT_LOAD_EXTENSION
14881515
sqlite3_enable_load_extension(p->db, 1);
14891516
#endif
@@ -1832,11 +1859,11 @@
18321859
if( rc!=SQLITE_OK ){
18331860
fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
18341861
sqlite3_close(pDest);
18351862
return 1;
18361863
}
1837
- open_db(p);
1864
+ open_db(p, 0);
18381865
pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
18391866
if( pBackup==0 ){
18401867
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
18411868
sqlite3_close(pDest);
18421869
return 1;
@@ -1864,11 +1891,11 @@
18641891
}else
18651892
18661893
if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
18671894
struct callback_data data;
18681895
char *zErrMsg = 0;
1869
- open_db(p);
1896
+ open_db(p, 0);
18701897
memcpy(&data, p, sizeof(data));
18711898
data.showHeader = 1;
18721899
data.mode = MODE_Column;
18731900
data.colWidth[0] = 3;
18741901
data.colWidth[1] = 15;
@@ -1881,11 +1908,11 @@
18811908
rc = 1;
18821909
}
18831910
}else
18841911
18851912
if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
1886
- open_db(p);
1913
+ open_db(p, 0);
18871914
/* When playing back a "dump", the content might appear in an order
18881915
** which causes immediate foreign key constraints to be violated.
18891916
** So disable foreign-key constraint enforcement to prevent problems. */
18901917
fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
18911918
fprintf(p->out, "BEGIN TRANSACTION;\n");
@@ -2000,11 +2027,11 @@
20002027
CSVReader sCsv; /* Reader context */
20012028
int (*xCloser)(FILE*); /* Procedure to close th3 connection */
20022029
20032030
seenInterrupt = 0;
20042031
memset(&sCsv, 0, sizeof(sCsv));
2005
- open_db(p);
2032
+ open_db(p, 0);
20062033
nSep = strlen30(p->separator);
20072034
if( nSep==0 ){
20082035
fprintf(stderr, "Error: non-null separator required for import\n");
20092036
return 1;
20102037
}
@@ -2138,11 +2165,11 @@
21382165
}else
21392166
21402167
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
21412168
struct callback_data data;
21422169
char *zErrMsg = 0;
2143
- open_db(p);
2170
+ open_db(p, 0);
21442171
memcpy(&data, p, sizeof(data));
21452172
data.showHeader = 0;
21462173
data.mode = MODE_List;
21472174
if( nArg==1 ){
21482175
rc = sqlite3_exec(p->db,
@@ -2204,11 +2231,11 @@
22042231
if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){
22052232
const char *zFile, *zProc;
22062233
char *zErrMsg = 0;
22072234
zFile = azArg[1];
22082235
zProc = nArg>=3 ? azArg[2] : 0;
2209
- open_db(p);
2236
+ open_db(p, 0);
22102237
rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
22112238
if( rc!=SQLITE_OK ){
22122239
fprintf(stderr, "Error: %s\n", zErrMsg);
22132240
sqlite3_free(zErrMsg);
22142241
rc = 1;
@@ -2269,10 +2296,30 @@
22692296
22702297
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
22712298
sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
22722299
"%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
22732300
}else
2301
+
2302
+ if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
2303
+ sqlite3 *savedDb = p->db;
2304
+ const char *zSavedFilename = p->zDbFilename;
2305
+ char *zNewFilename = 0;
2306
+ p->db = 0;
2307
+ if( nArg>=2 ){
2308
+ p->zDbFilename = zNewFilename = sqlite3_mprintf("%s", azArg[1]);
2309
+ }
2310
+ open_db(p, 1);
2311
+ if( p->db!=0 ){
2312
+ sqlite3_close(savedDb);
2313
+ sqlite3_free(p->zFreeOnClose);
2314
+ p->zFreeOnClose = zNewFilename;
2315
+ }else{
2316
+ sqlite3_free(zNewFilename);
2317
+ p->db = savedDb;
2318
+ p->zDbFilename = zSavedFilename;
2319
+ }
2320
+ }else
22742321
22752322
if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
22762323
if( p->outfile[0]=='|' ){
22772324
pclose(p->out);
22782325
}else{
@@ -2353,11 +2400,11 @@
23532400
if( rc!=SQLITE_OK ){
23542401
fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
23552402
sqlite3_close(pSrc);
23562403
return 1;
23572404
}
2358
- open_db(p);
2405
+ open_db(p, 0);
23592406
pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
23602407
if( pBackup==0 ){
23612408
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
23622409
sqlite3_close(pSrc);
23632410
return 1;
@@ -2383,11 +2430,11 @@
23832430
}else
23842431
23852432
if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
23862433
struct callback_data data;
23872434
char *zErrMsg = 0;
2388
- open_db(p);
2435
+ open_db(p, 0);
23892436
memcpy(&data, p, sizeof(data));
23902437
data.showHeader = 0;
23912438
data.mode = MODE_Semi;
23922439
if( nArg>1 ){
23932440
int i;
@@ -2514,11 +2561,11 @@
25142561
sqlite3_stmt *pStmt;
25152562
char **azResult;
25162563
int nRow, nAlloc;
25172564
char *zSql = 0;
25182565
int ii;
2519
- open_db(p);
2566
+ open_db(p, 0);
25202567
rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
25212568
if( rc ) return rc;
25222569
zSql = sqlite3_mprintf(
25232570
"SELECT name FROM sqlite_master"
25242571
" WHERE type IN ('table','view')"
@@ -2614,11 +2661,11 @@
26142661
{ "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
26152662
};
26162663
int testctrl = -1;
26172664
int rc = 0;
26182665
int i, n;
2619
- open_db(p);
2666
+ open_db(p, 0);
26202667
26212668
/* convert testctrl text option to value. allow any unique prefix
26222669
** of the option name, or a numerical value. */
26232670
n = strlen30(azArg[1]);
26242671
for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
@@ -2713,11 +2760,11 @@
27132760
}
27142761
}
27152762
}else
27162763
27172764
if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
2718
- open_db(p);
2765
+ open_db(p, 0);
27192766
sqlite3_busy_timeout(p->db, (int)integerValue(azArg[1]));
27202767
}else
27212768
27222769
if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
27232770
&& nArg==2
@@ -2724,11 +2771,11 @@
27242771
){
27252772
enableTimer = booleanValue(azArg[1]);
27262773
}else
27272774
27282775
if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
2729
- open_db(p);
2776
+ open_db(p, 0);
27302777
output_file_close(p->traceOut);
27312778
p->traceOut = output_file_open(azArg[1]);
27322779
#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
27332780
if( p->traceOut==0 ){
27342781
sqlite3_trace(p->db, 0, 0);
@@ -2916,11 +2963,11 @@
29162963
nSql += nLine;
29172964
}
29182965
if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
29192966
&& sqlite3_complete(zSql) ){
29202967
p->cnt = 0;
2921
- open_db(p);
2968
+ open_db(p, 0);
29222969
BEGIN_TIMER;
29232970
rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
29242971
END_TIMER;
29252972
if( rc || zErrMsg ){
29262973
char zPrefix[100];
@@ -3249,11 +3296,11 @@
32493296
** file does not exist, delay opening it. This prevents empty database
32503297
** files from being created if a user mistypes the database name argument
32513298
** to the sqlite command-line tool.
32523299
*/
32533300
if( access(data.zDbFilename, 0)==0 ){
3254
- open_db(&data);
3301
+ open_db(&data, 0);
32553302
}
32563303
32573304
/* Process the initialization file if there is one. If no -init option
32583305
** is given on the command line, look for a file named ~/.sqliterc and
32593306
** try to process it.
@@ -3329,11 +3376,11 @@
33293376
z = cmdline_option_value(argc,argv,++i);
33303377
if( z[0]=='.' ){
33313378
rc = do_meta_command(z, &data);
33323379
if( rc && bail_on_error ) return rc==2 ? 0 : rc;
33333380
}else{
3334
- open_db(&data);
3381
+ open_db(&data, 0);
33353382
rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
33363383
if( zErrMsg!=0 ){
33373384
fprintf(stderr,"Error: %s\n", zErrMsg);
33383385
if( bail_on_error ) return rc!=0 ? rc : 1;
33393386
}else if( rc!=0 ){
@@ -3353,11 +3400,11 @@
33533400
*/
33543401
if( zFirstCmd[0]=='.' ){
33553402
rc = do_meta_command(zFirstCmd, &data);
33563403
if( rc==2 ) rc = 0;
33573404
}else{
3358
- open_db(&data);
3405
+ open_db(&data, 0);
33593406
rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
33603407
if( zErrMsg!=0 ){
33613408
fprintf(stderr,"Error: %s\n", zErrMsg);
33623409
return rc!=0 ? rc : 1;
33633410
}else if( rc!=0 ){
@@ -3400,7 +3447,8 @@
34003447
}
34013448
set_table_name(&data, 0);
34023449
if( data.db ){
34033450
sqlite3_close(data.db);
34043451
}
3452
+ sqlite3_free(data.zFreeOnClose);
34053453
return rc;
34063454
}
34073455
--- src/shell.c
+++ src/shell.c
@@ -84,32 +84,50 @@
84 * overridden with the -batch command line option.
85 */
86 #define isatty(x) 1
87 #endif
88
89 /* True if the timer is enabled */
90 static int enableTimer = 0;
91
92 /* ctype macros that work with signed characters */
93 #define IsSpace(X) isspace((unsigned char)X)
94 #define IsDigit(X) isdigit((unsigned char)X)
95 #define ToLower(X) (char)tolower((unsigned char)X)
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97 #if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
98 && !defined(__minux)
99 #include <sys/time.h>
100 #include <sys/resource.h>
101
102 /* Saved resource information for the beginning of an operation */
103 static struct rusage sBegin;
 
104
105 /*
106 ** Begin timing an operation
107 */
108 static void beginTimer(void){
109 if( enableTimer ){
110 getrusage(RUSAGE_SELF, &sBegin);
 
111 }
112 }
113
114 /* Return the difference of two time_structs in seconds */
115 static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
@@ -121,12 +139,14 @@
121 ** Print the timing results.
122 */
123 static void endTimer(void){
124 if( enableTimer ){
125 struct rusage sEnd;
 
126 getrusage(RUSAGE_SELF, &sEnd);
127 printf("CPU Time: user %f sys %f\n",
 
128 timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
129 timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
130 }
131 }
132
@@ -140,10 +160,11 @@
140
141 /* Saved resource information for the beginning of an operation */
142 static HANDLE hProcess;
143 static FILETIME ftKernelBegin;
144 static FILETIME ftUserBegin;
 
145 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
146 static GETPROCTIMES getProcessTimesAddr = NULL;
147
148 /*
149 ** Check to see if we have timer support. Return 1 if necessary
@@ -177,10 +198,11 @@
177 */
178 static void beginTimer(void){
179 if( enableTimer && getProcessTimesAddr ){
180 FILETIME ftCreation, ftExit;
181 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
 
182 }
183 }
184
185 /* Return the difference of two FILETIME structs in seconds */
186 static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
@@ -193,12 +215,14 @@
193 ** Print the timing results.
194 */
195 static void endTimer(void){
196 if( enableTimer && getProcessTimesAddr){
197 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
 
198 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
199 printf("CPU Time: user %f sys %f\n",
 
200 timeDiff(&ftUserBegin, &ftUserEnd),
201 timeDiff(&ftKernelBegin, &ftKernelEnd));
202 }
203 }
204
@@ -434,10 +458,11 @@
434 struct previous_mode_data explainPrev;
435 /* Holds the mode information just before
436 ** .explain ON */
437 char outfile[FILENAME_MAX]; /* Filename for *out */
438 const char *zDbFilename; /* name of the database file */
 
439 const char *zVfs; /* Name of VFS to use */
440 sqlite3_stmt *pStmt; /* Current statement if any. */
441 FILE *pLog; /* Write log output here */
442 };
443
@@ -1435,10 +1460,11 @@
1435 " line One value per line\n"
1436 " list Values delimited by .separator string\n"
1437 " tabs Tab-separated values\n"
1438 " tcl TCL list elements\n"
1439 ".nullvalue STRING Use STRING in place of NULL values\n"
 
1440 ".output FILENAME Send output to FILENAME\n"
1441 ".output stdout Send output to the screen\n"
1442 ".print STRING... Print literal STRING\n"
1443 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1444 ".quit Exit this program\n"
@@ -1468,11 +1494,11 @@
1468
1469 /*
1470 ** Make sure the database is open. If it is not, then open it. If
1471 ** the database fails to open, print an error message and exit.
1472 */
1473 static void open_db(struct callback_data *p){
1474 if( p->db==0 ){
1475 sqlite3_initialize();
1476 sqlite3_open(p->zDbFilename, &p->db);
1477 db = p->db;
1478 if( db && sqlite3_errcode(db)==SQLITE_OK ){
@@ -1480,10 +1506,11 @@
1480 shellstaticFunc, 0, 0);
1481 }
1482 if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
1483 fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
1484 p->zDbFilename, sqlite3_errmsg(db));
 
1485 exit(1);
1486 }
1487 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1488 sqlite3_enable_load_extension(p->db, 1);
1489 #endif
@@ -1832,11 +1859,11 @@
1832 if( rc!=SQLITE_OK ){
1833 fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
1834 sqlite3_close(pDest);
1835 return 1;
1836 }
1837 open_db(p);
1838 pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
1839 if( pBackup==0 ){
1840 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
1841 sqlite3_close(pDest);
1842 return 1;
@@ -1864,11 +1891,11 @@
1864 }else
1865
1866 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
1867 struct callback_data data;
1868 char *zErrMsg = 0;
1869 open_db(p);
1870 memcpy(&data, p, sizeof(data));
1871 data.showHeader = 1;
1872 data.mode = MODE_Column;
1873 data.colWidth[0] = 3;
1874 data.colWidth[1] = 15;
@@ -1881,11 +1908,11 @@
1881 rc = 1;
1882 }
1883 }else
1884
1885 if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
1886 open_db(p);
1887 /* When playing back a "dump", the content might appear in an order
1888 ** which causes immediate foreign key constraints to be violated.
1889 ** So disable foreign-key constraint enforcement to prevent problems. */
1890 fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
1891 fprintf(p->out, "BEGIN TRANSACTION;\n");
@@ -2000,11 +2027,11 @@
2000 CSVReader sCsv; /* Reader context */
2001 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2002
2003 seenInterrupt = 0;
2004 memset(&sCsv, 0, sizeof(sCsv));
2005 open_db(p);
2006 nSep = strlen30(p->separator);
2007 if( nSep==0 ){
2008 fprintf(stderr, "Error: non-null separator required for import\n");
2009 return 1;
2010 }
@@ -2138,11 +2165,11 @@
2138 }else
2139
2140 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2141 struct callback_data data;
2142 char *zErrMsg = 0;
2143 open_db(p);
2144 memcpy(&data, p, sizeof(data));
2145 data.showHeader = 0;
2146 data.mode = MODE_List;
2147 if( nArg==1 ){
2148 rc = sqlite3_exec(p->db,
@@ -2204,11 +2231,11 @@
2204 if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){
2205 const char *zFile, *zProc;
2206 char *zErrMsg = 0;
2207 zFile = azArg[1];
2208 zProc = nArg>=3 ? azArg[2] : 0;
2209 open_db(p);
2210 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
2211 if( rc!=SQLITE_OK ){
2212 fprintf(stderr, "Error: %s\n", zErrMsg);
2213 sqlite3_free(zErrMsg);
2214 rc = 1;
@@ -2269,10 +2296,30 @@
2269
2270 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
2271 sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2272 "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2273 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2274
2275 if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
2276 if( p->outfile[0]=='|' ){
2277 pclose(p->out);
2278 }else{
@@ -2353,11 +2400,11 @@
2353 if( rc!=SQLITE_OK ){
2354 fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
2355 sqlite3_close(pSrc);
2356 return 1;
2357 }
2358 open_db(p);
2359 pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
2360 if( pBackup==0 ){
2361 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
2362 sqlite3_close(pSrc);
2363 return 1;
@@ -2383,11 +2430,11 @@
2383 }else
2384
2385 if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
2386 struct callback_data data;
2387 char *zErrMsg = 0;
2388 open_db(p);
2389 memcpy(&data, p, sizeof(data));
2390 data.showHeader = 0;
2391 data.mode = MODE_Semi;
2392 if( nArg>1 ){
2393 int i;
@@ -2514,11 +2561,11 @@
2514 sqlite3_stmt *pStmt;
2515 char **azResult;
2516 int nRow, nAlloc;
2517 char *zSql = 0;
2518 int ii;
2519 open_db(p);
2520 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
2521 if( rc ) return rc;
2522 zSql = sqlite3_mprintf(
2523 "SELECT name FROM sqlite_master"
2524 " WHERE type IN ('table','view')"
@@ -2614,11 +2661,11 @@
2614 { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
2615 };
2616 int testctrl = -1;
2617 int rc = 0;
2618 int i, n;
2619 open_db(p);
2620
2621 /* convert testctrl text option to value. allow any unique prefix
2622 ** of the option name, or a numerical value. */
2623 n = strlen30(azArg[1]);
2624 for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
@@ -2713,11 +2760,11 @@
2713 }
2714 }
2715 }else
2716
2717 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
2718 open_db(p);
2719 sqlite3_busy_timeout(p->db, (int)integerValue(azArg[1]));
2720 }else
2721
2722 if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
2723 && nArg==2
@@ -2724,11 +2771,11 @@
2724 ){
2725 enableTimer = booleanValue(azArg[1]);
2726 }else
2727
2728 if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
2729 open_db(p);
2730 output_file_close(p->traceOut);
2731 p->traceOut = output_file_open(azArg[1]);
2732 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
2733 if( p->traceOut==0 ){
2734 sqlite3_trace(p->db, 0, 0);
@@ -2916,11 +2963,11 @@
2916 nSql += nLine;
2917 }
2918 if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
2919 && sqlite3_complete(zSql) ){
2920 p->cnt = 0;
2921 open_db(p);
2922 BEGIN_TIMER;
2923 rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
2924 END_TIMER;
2925 if( rc || zErrMsg ){
2926 char zPrefix[100];
@@ -3249,11 +3296,11 @@
3249 ** file does not exist, delay opening it. This prevents empty database
3250 ** files from being created if a user mistypes the database name argument
3251 ** to the sqlite command-line tool.
3252 */
3253 if( access(data.zDbFilename, 0)==0 ){
3254 open_db(&data);
3255 }
3256
3257 /* Process the initialization file if there is one. If no -init option
3258 ** is given on the command line, look for a file named ~/.sqliterc and
3259 ** try to process it.
@@ -3329,11 +3376,11 @@
3329 z = cmdline_option_value(argc,argv,++i);
3330 if( z[0]=='.' ){
3331 rc = do_meta_command(z, &data);
3332 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
3333 }else{
3334 open_db(&data);
3335 rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
3336 if( zErrMsg!=0 ){
3337 fprintf(stderr,"Error: %s\n", zErrMsg);
3338 if( bail_on_error ) return rc!=0 ? rc : 1;
3339 }else if( rc!=0 ){
@@ -3353,11 +3400,11 @@
3353 */
3354 if( zFirstCmd[0]=='.' ){
3355 rc = do_meta_command(zFirstCmd, &data);
3356 if( rc==2 ) rc = 0;
3357 }else{
3358 open_db(&data);
3359 rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
3360 if( zErrMsg!=0 ){
3361 fprintf(stderr,"Error: %s\n", zErrMsg);
3362 return rc!=0 ? rc : 1;
3363 }else if( rc!=0 ){
@@ -3400,7 +3447,8 @@
3400 }
3401 set_table_name(&data, 0);
3402 if( data.db ){
3403 sqlite3_close(data.db);
3404 }
 
3405 return rc;
3406 }
3407
--- src/shell.c
+++ src/shell.c
@@ -84,32 +84,50 @@
84 * overridden with the -batch command line option.
85 */
86 #define isatty(x) 1
87 #endif
88
 
 
 
89 /* ctype macros that work with signed characters */
90 #define IsSpace(X) isspace((unsigned char)X)
91 #define IsDigit(X) isdigit((unsigned char)X)
92 #define ToLower(X) (char)tolower((unsigned char)X)
93
94
95 /* True if the timer is enabled */
96 static int enableTimer = 0;
97
98 /* Return the current wall-clock time */
99 static sqlite3_int64 timeOfDay(void){
100 static sqlite3_vfs *clockVfs = 0;
101 sqlite3_int64 t;
102 if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
103 if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
104 clockVfs->xCurrentTimeInt64(clockVfs, &t);
105 }else{
106 double r;
107 clockVfs->xCurrentTime(clockVfs, &r);
108 t = (sqlite3_int64)(r*86400000.0);
109 }
110 return t;
111 }
112
113 #if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
114 && !defined(__minux)
115 #include <sys/time.h>
116 #include <sys/resource.h>
117
118 /* Saved resource information for the beginning of an operation */
119 static struct rusage sBegin; /* CPU time at start */
120 static sqlite3_int64 iBegin; /* Wall-clock time at start */
121
122 /*
123 ** Begin timing an operation
124 */
125 static void beginTimer(void){
126 if( enableTimer ){
127 getrusage(RUSAGE_SELF, &sBegin);
128 iBegin = timeOfDay();
129 }
130 }
131
132 /* Return the difference of two time_structs in seconds */
133 static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
@@ -121,12 +139,14 @@
139 ** Print the timing results.
140 */
141 static void endTimer(void){
142 if( enableTimer ){
143 struct rusage sEnd;
144 sqlite3_int64 iEnd = timeOfDay();
145 getrusage(RUSAGE_SELF, &sEnd);
146 printf("Run Time: real %.3f user %f sys %f\n",
147 (iEnd - iBegin)*0.001,
148 timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
149 timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
150 }
151 }
152
@@ -140,10 +160,11 @@
160
161 /* Saved resource information for the beginning of an operation */
162 static HANDLE hProcess;
163 static FILETIME ftKernelBegin;
164 static FILETIME ftUserBegin;
165 static sqlite3_int64 ftWallBegin;
166 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
167 static GETPROCTIMES getProcessTimesAddr = NULL;
168
169 /*
170 ** Check to see if we have timer support. Return 1 if necessary
@@ -177,10 +198,11 @@
198 */
199 static void beginTimer(void){
200 if( enableTimer && getProcessTimesAddr ){
201 FILETIME ftCreation, ftExit;
202 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
203 ftWallBegin = timeOfDay();
204 }
205 }
206
207 /* Return the difference of two FILETIME structs in seconds */
208 static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
@@ -193,12 +215,14 @@
215 ** Print the timing results.
216 */
217 static void endTimer(void){
218 if( enableTimer && getProcessTimesAddr){
219 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
220 sqlite3_int64 ftWallEnd = timeOfDay();
221 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
222 printf("Run Time: real %.3f user %f sys %f\n",
223 (ftWallEnd - ftWallBegin)*0.001,
224 timeDiff(&ftUserBegin, &ftUserEnd),
225 timeDiff(&ftKernelBegin, &ftKernelEnd));
226 }
227 }
228
@@ -434,10 +458,11 @@
458 struct previous_mode_data explainPrev;
459 /* Holds the mode information just before
460 ** .explain ON */
461 char outfile[FILENAME_MAX]; /* Filename for *out */
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
@@ -1435,10 +1460,11 @@
1460 " line One value per line\n"
1461 " list Values delimited by .separator string\n"
1462 " tabs Tab-separated values\n"
1463 " tcl TCL list elements\n"
1464 ".nullvalue STRING Use STRING in place of NULL values\n"
1465 ".open ?FILENAME? Close existing database and reopen FILENAME\n"
1466 ".output FILENAME Send output to FILENAME\n"
1467 ".output stdout Send output to the screen\n"
1468 ".print STRING... Print literal STRING\n"
1469 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1470 ".quit Exit this program\n"
@@ -1468,11 +1494,11 @@
1494
1495 /*
1496 ** Make sure the database is open. If it is not, then open it. If
1497 ** the database fails to open, print an error message and exit.
1498 */
1499 static void open_db(struct callback_data *p, int keepAlive){
1500 if( p->db==0 ){
1501 sqlite3_initialize();
1502 sqlite3_open(p->zDbFilename, &p->db);
1503 db = p->db;
1504 if( db && sqlite3_errcode(db)==SQLITE_OK ){
@@ -1480,10 +1506,11 @@
1506 shellstaticFunc, 0, 0);
1507 }
1508 if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
1509 fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
1510 p->zDbFilename, sqlite3_errmsg(db));
1511 if( keepAlive ) return;
1512 exit(1);
1513 }
1514 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1515 sqlite3_enable_load_extension(p->db, 1);
1516 #endif
@@ -1832,11 +1859,11 @@
1859 if( rc!=SQLITE_OK ){
1860 fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
1861 sqlite3_close(pDest);
1862 return 1;
1863 }
1864 open_db(p, 0);
1865 pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
1866 if( pBackup==0 ){
1867 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
1868 sqlite3_close(pDest);
1869 return 1;
@@ -1864,11 +1891,11 @@
1891 }else
1892
1893 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
1894 struct callback_data data;
1895 char *zErrMsg = 0;
1896 open_db(p, 0);
1897 memcpy(&data, p, sizeof(data));
1898 data.showHeader = 1;
1899 data.mode = MODE_Column;
1900 data.colWidth[0] = 3;
1901 data.colWidth[1] = 15;
@@ -1881,11 +1908,11 @@
1908 rc = 1;
1909 }
1910 }else
1911
1912 if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
1913 open_db(p, 0);
1914 /* When playing back a "dump", the content might appear in an order
1915 ** which causes immediate foreign key constraints to be violated.
1916 ** So disable foreign-key constraint enforcement to prevent problems. */
1917 fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
1918 fprintf(p->out, "BEGIN TRANSACTION;\n");
@@ -2000,11 +2027,11 @@
2027 CSVReader sCsv; /* Reader context */
2028 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2029
2030 seenInterrupt = 0;
2031 memset(&sCsv, 0, sizeof(sCsv));
2032 open_db(p, 0);
2033 nSep = strlen30(p->separator);
2034 if( nSep==0 ){
2035 fprintf(stderr, "Error: non-null separator required for import\n");
2036 return 1;
2037 }
@@ -2138,11 +2165,11 @@
2165 }else
2166
2167 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2168 struct callback_data data;
2169 char *zErrMsg = 0;
2170 open_db(p, 0);
2171 memcpy(&data, p, sizeof(data));
2172 data.showHeader = 0;
2173 data.mode = MODE_List;
2174 if( nArg==1 ){
2175 rc = sqlite3_exec(p->db,
@@ -2204,11 +2231,11 @@
2231 if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){
2232 const char *zFile, *zProc;
2233 char *zErrMsg = 0;
2234 zFile = azArg[1];
2235 zProc = nArg>=3 ? azArg[2] : 0;
2236 open_db(p, 0);
2237 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
2238 if( rc!=SQLITE_OK ){
2239 fprintf(stderr, "Error: %s\n", zErrMsg);
2240 sqlite3_free(zErrMsg);
2241 rc = 1;
@@ -2269,10 +2296,30 @@
2296
2297 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
2298 sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2299 "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2300 }else
2301
2302 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
2303 sqlite3 *savedDb = p->db;
2304 const char *zSavedFilename = p->zDbFilename;
2305 char *zNewFilename = 0;
2306 p->db = 0;
2307 if( nArg>=2 ){
2308 p->zDbFilename = zNewFilename = sqlite3_mprintf("%s", azArg[1]);
2309 }
2310 open_db(p, 1);
2311 if( p->db!=0 ){
2312 sqlite3_close(savedDb);
2313 sqlite3_free(p->zFreeOnClose);
2314 p->zFreeOnClose = zNewFilename;
2315 }else{
2316 sqlite3_free(zNewFilename);
2317 p->db = savedDb;
2318 p->zDbFilename = zSavedFilename;
2319 }
2320 }else
2321
2322 if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
2323 if( p->outfile[0]=='|' ){
2324 pclose(p->out);
2325 }else{
@@ -2353,11 +2400,11 @@
2400 if( rc!=SQLITE_OK ){
2401 fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
2402 sqlite3_close(pSrc);
2403 return 1;
2404 }
2405 open_db(p, 0);
2406 pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
2407 if( pBackup==0 ){
2408 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
2409 sqlite3_close(pSrc);
2410 return 1;
@@ -2383,11 +2430,11 @@
2430 }else
2431
2432 if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
2433 struct callback_data data;
2434 char *zErrMsg = 0;
2435 open_db(p, 0);
2436 memcpy(&data, p, sizeof(data));
2437 data.showHeader = 0;
2438 data.mode = MODE_Semi;
2439 if( nArg>1 ){
2440 int i;
@@ -2514,11 +2561,11 @@
2561 sqlite3_stmt *pStmt;
2562 char **azResult;
2563 int nRow, nAlloc;
2564 char *zSql = 0;
2565 int ii;
2566 open_db(p, 0);
2567 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
2568 if( rc ) return rc;
2569 zSql = sqlite3_mprintf(
2570 "SELECT name FROM sqlite_master"
2571 " WHERE type IN ('table','view')"
@@ -2614,11 +2661,11 @@
2661 { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
2662 };
2663 int testctrl = -1;
2664 int rc = 0;
2665 int i, n;
2666 open_db(p, 0);
2667
2668 /* convert testctrl text option to value. allow any unique prefix
2669 ** of the option name, or a numerical value. */
2670 n = strlen30(azArg[1]);
2671 for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
@@ -2713,11 +2760,11 @@
2760 }
2761 }
2762 }else
2763
2764 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
2765 open_db(p, 0);
2766 sqlite3_busy_timeout(p->db, (int)integerValue(azArg[1]));
2767 }else
2768
2769 if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
2770 && nArg==2
@@ -2724,11 +2771,11 @@
2771 ){
2772 enableTimer = booleanValue(azArg[1]);
2773 }else
2774
2775 if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
2776 open_db(p, 0);
2777 output_file_close(p->traceOut);
2778 p->traceOut = output_file_open(azArg[1]);
2779 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
2780 if( p->traceOut==0 ){
2781 sqlite3_trace(p->db, 0, 0);
@@ -2916,11 +2963,11 @@
2963 nSql += nLine;
2964 }
2965 if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
2966 && sqlite3_complete(zSql) ){
2967 p->cnt = 0;
2968 open_db(p, 0);
2969 BEGIN_TIMER;
2970 rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
2971 END_TIMER;
2972 if( rc || zErrMsg ){
2973 char zPrefix[100];
@@ -3249,11 +3296,11 @@
3296 ** file does not exist, delay opening it. This prevents empty database
3297 ** files from being created if a user mistypes the database name argument
3298 ** to the sqlite command-line tool.
3299 */
3300 if( access(data.zDbFilename, 0)==0 ){
3301 open_db(&data, 0);
3302 }
3303
3304 /* Process the initialization file if there is one. If no -init option
3305 ** is given on the command line, look for a file named ~/.sqliterc and
3306 ** try to process it.
@@ -3329,11 +3376,11 @@
3376 z = cmdline_option_value(argc,argv,++i);
3377 if( z[0]=='.' ){
3378 rc = do_meta_command(z, &data);
3379 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
3380 }else{
3381 open_db(&data, 0);
3382 rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
3383 if( zErrMsg!=0 ){
3384 fprintf(stderr,"Error: %s\n", zErrMsg);
3385 if( bail_on_error ) return rc!=0 ? rc : 1;
3386 }else if( rc!=0 ){
@@ -3353,11 +3400,11 @@
3400 */
3401 if( zFirstCmd[0]=='.' ){
3402 rc = do_meta_command(zFirstCmd, &data);
3403 if( rc==2 ) rc = 0;
3404 }else{
3405 open_db(&data, 0);
3406 rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
3407 if( zErrMsg!=0 ){
3408 fprintf(stderr,"Error: %s\n", zErrMsg);
3409 return rc!=0 ? rc : 1;
3410 }else if( rc!=0 ){
@@ -3400,7 +3447,8 @@
3447 }
3448 set_table_name(&data, 0);
3449 if( data.db ){
3450 sqlite3_close(data.db);
3451 }
3452 sqlite3_free(data.zFreeOnClose);
3453 return rc;
3454 }
3455
+6341 -4927
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.8.1. By combining all the individual C code files into this
3
+** version 3.8.2. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -133,13 +133,13 @@
133133
**
134134
** See also: [sqlite3_libversion()],
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138
-#define SQLITE_VERSION "3.8.1"
139
-#define SQLITE_VERSION_NUMBER 3008001
140
-#define SQLITE_SOURCE_ID "2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a"
138
+#define SQLITE_VERSION "3.8.2"
139
+#define SQLITE_VERSION_NUMBER 3008002
140
+#define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -527,10 +527,11 @@
527527
#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
528528
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
529529
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
530530
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
531531
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
532
+#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
532533
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
533534
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
534535
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
535536
536537
/*
@@ -938,10 +939,18 @@
938939
** pointer is overwritten with the old value. The limit is not changed if
939940
** the value originally pointed to is negative, and so the current limit
940941
** can be queried by passing in a pointer to a negative number. This
941942
** file-control is used internally to implement [PRAGMA mmap_size].
942943
**
944
+** <li>[[SQLITE_FCNTL_TRACE]]
945
+** The [SQLITE_FCNTL_TRACE] file control provides advisory information
946
+** to the VFS about what the higher layers of the SQLite stack are doing.
947
+** This file control is used by some VFS activity tracing [shims].
948
+** The argument is a zero-terminated string. Higher layers in the
949
+** SQLite stack may generate instances of this file control if
950
+** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
951
+**
943952
** </ul>
944953
*/
945954
#define SQLITE_FCNTL_LOCKSTATE 1
946955
#define SQLITE_GET_LOCKPROXYFILE 2
947956
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -957,10 +966,11 @@
957966
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
958967
#define SQLITE_FCNTL_PRAGMA 14
959968
#define SQLITE_FCNTL_BUSYHANDLER 15
960969
#define SQLITE_FCNTL_TEMPFILENAME 16
961970
#define SQLITE_FCNTL_MMAP_SIZE 18
971
+#define SQLITE_FCNTL_TRACE 19
962972
963973
/*
964974
** CAPI3REF: Mutex Handle
965975
**
966976
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1803,23 +1813,25 @@
18031813
SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
18041814
18051815
/*
18061816
** CAPI3REF: Last Insert Rowid
18071817
**
1808
-** ^Each entry in an SQLite table has a unique 64-bit signed
1818
+** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1819
+** has a unique 64-bit signed
18091820
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
18101821
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
18111822
** names are not also used by explicitly declared columns. ^If
18121823
** the table has a column of type [INTEGER PRIMARY KEY] then that column
18131824
** is another alias for the rowid.
18141825
**
1815
-** ^This routine returns the [rowid] of the most recent
1816
-** successful [INSERT] into the database from the [database connection]
1817
-** in the first argument. ^As of SQLite version 3.7.7, this routines
1818
-** records the last insert rowid of both ordinary tables and [virtual tables].
1819
-** ^If no successful [INSERT]s
1820
-** have ever occurred on that database connection, zero is returned.
1826
+** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
1827
+** most recent successful [INSERT] into a rowid table or [virtual table]
1828
+** on database connection D.
1829
+** ^Inserts into [WITHOUT ROWID] tables are not recorded.
1830
+** ^If no successful [INSERT]s into rowid tables
1831
+** have ever occurred on the database connection D,
1832
+** then sqlite3_last_insert_rowid(D) returns zero.
18211833
**
18221834
** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
18231835
** method, then this routine will return the [rowid] of the inserted
18241836
** row as long as the trigger or virtual table method is running.
18251837
** But once the trigger or virtual table method ends, the value returned
@@ -4832,16 +4844,17 @@
48324844
/*
48334845
** CAPI3REF: Data Change Notification Callbacks
48344846
**
48354847
** ^The sqlite3_update_hook() interface registers a callback function
48364848
** with the [database connection] identified by the first argument
4837
-** to be invoked whenever a row is updated, inserted or deleted.
4849
+** to be invoked whenever a row is updated, inserted or deleted in
4850
+** a rowid table.
48384851
** ^Any callback set by a previous call to this function
48394852
** for the same database connection is overridden.
48404853
**
48414854
** ^The second argument is a pointer to the function to invoke when a
4842
-** row is updated, inserted or deleted.
4855
+** row is updated, inserted or deleted in a rowid table.
48434856
** ^The first argument to the callback is a copy of the third argument
48444857
** to sqlite3_update_hook().
48454858
** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
48464859
** or [SQLITE_UPDATE], depending on the operation that caused the callback
48474860
** to be invoked.
@@ -4850,10 +4863,11 @@
48504863
** ^The final callback parameter is the [rowid] of the row.
48514864
** ^In the case of an update, this is the [rowid] after the update takes place.
48524865
**
48534866
** ^(The update hook is not invoked when internal system tables are
48544867
** modified (i.e. sqlite_master and sqlite_sequence).)^
4868
+** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
48554869
**
48564870
** ^In the current implementation, the update hook
48574871
** is not invoked when duplication rows are deleted because of an
48584872
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
48594873
** invoked when rows are deleted using the [truncate optimization].
@@ -5539,10 +5553,13 @@
55395553
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
55405554
** the opened blob. ^The size of a blob may not be changed by this
55415555
** interface. Use the [UPDATE] SQL command to change the size of a
55425556
** blob.
55435557
**
5558
+** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5559
+** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5560
+**
55445561
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
55455562
** and the built-in [zeroblob] SQL function can be used, if desired,
55465563
** to create an empty, zero-filled blob in which to read or write using
55475564
** this interface.
55485565
**
@@ -7756,10 +7773,17 @@
77567773
#endif
77577774
#if defined(NDEBUG) && defined(SQLITE_DEBUG)
77587775
# undef NDEBUG
77597776
#endif
77607777
7778
+/*
7779
+** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on.
7780
+*/
7781
+#if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG)
7782
+# define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
7783
+#endif
7784
+
77617785
/*
77627786
** The testcase() macro is used to aid in coverage testing. When
77637787
** doing coverage testing, the condition inside the argument to
77647788
** testcase() must be evaluated both true and false in order to
77657789
** get full branch coverage. The testcase() macro is inserted
@@ -7972,143 +7996,144 @@
79727996
#define TK_EXISTS 20
79737997
#define TK_TEMP 21
79747998
#define TK_LP 22
79757999
#define TK_RP 23
79768000
#define TK_AS 24
7977
-#define TK_COMMA 25
7978
-#define TK_ID 26
7979
-#define TK_INDEXED 27
7980
-#define TK_ABORT 28
7981
-#define TK_ACTION 29
7982
-#define TK_AFTER 30
7983
-#define TK_ANALYZE 31
7984
-#define TK_ASC 32
7985
-#define TK_ATTACH 33
7986
-#define TK_BEFORE 34
7987
-#define TK_BY 35
7988
-#define TK_CASCADE 36
7989
-#define TK_CAST 37
7990
-#define TK_COLUMNKW 38
7991
-#define TK_CONFLICT 39
7992
-#define TK_DATABASE 40
7993
-#define TK_DESC 41
7994
-#define TK_DETACH 42
7995
-#define TK_EACH 43
7996
-#define TK_FAIL 44
7997
-#define TK_FOR 45
7998
-#define TK_IGNORE 46
7999
-#define TK_INITIALLY 47
8000
-#define TK_INSTEAD 48
8001
-#define TK_LIKE_KW 49
8002
-#define TK_MATCH 50
8003
-#define TK_NO 51
8004
-#define TK_KEY 52
8005
-#define TK_OF 53
8006
-#define TK_OFFSET 54
8007
-#define TK_PRAGMA 55
8008
-#define TK_RAISE 56
8009
-#define TK_REPLACE 57
8010
-#define TK_RESTRICT 58
8011
-#define TK_ROW 59
8012
-#define TK_TRIGGER 60
8013
-#define TK_VACUUM 61
8014
-#define TK_VIEW 62
8015
-#define TK_VIRTUAL 63
8016
-#define TK_REINDEX 64
8017
-#define TK_RENAME 65
8018
-#define TK_CTIME_KW 66
8019
-#define TK_ANY 67
8020
-#define TK_OR 68
8021
-#define TK_AND 69
8022
-#define TK_IS 70
8023
-#define TK_BETWEEN 71
8024
-#define TK_IN 72
8025
-#define TK_ISNULL 73
8026
-#define TK_NOTNULL 74
8027
-#define TK_NE 75
8028
-#define TK_EQ 76
8029
-#define TK_GT 77
8030
-#define TK_LE 78
8031
-#define TK_LT 79
8032
-#define TK_GE 80
8033
-#define TK_ESCAPE 81
8034
-#define TK_BITAND 82
8035
-#define TK_BITOR 83
8036
-#define TK_LSHIFT 84
8037
-#define TK_RSHIFT 85
8038
-#define TK_PLUS 86
8039
-#define TK_MINUS 87
8040
-#define TK_STAR 88
8041
-#define TK_SLASH 89
8042
-#define TK_REM 90
8043
-#define TK_CONCAT 91
8044
-#define TK_COLLATE 92
8045
-#define TK_BITNOT 93
8046
-#define TK_STRING 94
8047
-#define TK_JOIN_KW 95
8048
-#define TK_CONSTRAINT 96
8049
-#define TK_DEFAULT 97
8050
-#define TK_NULL 98
8051
-#define TK_PRIMARY 99
8052
-#define TK_UNIQUE 100
8053
-#define TK_CHECK 101
8054
-#define TK_REFERENCES 102
8055
-#define TK_AUTOINCR 103
8056
-#define TK_ON 104
8057
-#define TK_INSERT 105
8058
-#define TK_DELETE 106
8059
-#define TK_UPDATE 107
8060
-#define TK_SET 108
8061
-#define TK_DEFERRABLE 109
8062
-#define TK_FOREIGN 110
8063
-#define TK_DROP 111
8064
-#define TK_UNION 112
8065
-#define TK_ALL 113
8066
-#define TK_EXCEPT 114
8067
-#define TK_INTERSECT 115
8068
-#define TK_SELECT 116
8069
-#define TK_DISTINCT 117
8070
-#define TK_DOT 118
8071
-#define TK_FROM 119
8072
-#define TK_JOIN 120
8073
-#define TK_USING 121
8074
-#define TK_ORDER 122
8075
-#define TK_GROUP 123
8076
-#define TK_HAVING 124
8077
-#define TK_LIMIT 125
8078
-#define TK_WHERE 126
8079
-#define TK_INTO 127
8080
-#define TK_VALUES 128
8081
-#define TK_INTEGER 129
8082
-#define TK_FLOAT 130
8083
-#define TK_BLOB 131
8084
-#define TK_REGISTER 132
8085
-#define TK_VARIABLE 133
8086
-#define TK_CASE 134
8087
-#define TK_WHEN 135
8088
-#define TK_THEN 136
8089
-#define TK_ELSE 137
8090
-#define TK_INDEX 138
8091
-#define TK_ALTER 139
8092
-#define TK_ADD 140
8093
-#define TK_TO_TEXT 141
8094
-#define TK_TO_BLOB 142
8095
-#define TK_TO_NUMERIC 143
8096
-#define TK_TO_INT 144
8097
-#define TK_TO_REAL 145
8098
-#define TK_ISNOT 146
8099
-#define TK_END_OF_FILE 147
8100
-#define TK_ILLEGAL 148
8101
-#define TK_SPACE 149
8102
-#define TK_UNCLOSED_STRING 150
8103
-#define TK_FUNCTION 151
8104
-#define TK_COLUMN 152
8105
-#define TK_AGG_FUNCTION 153
8106
-#define TK_AGG_COLUMN 154
8107
-#define TK_CONST_FUNC 155
8108
-#define TK_UMINUS 156
8109
-#define TK_UPLUS 157
8001
+#define TK_WITHOUT 25
8002
+#define TK_COMMA 26
8003
+#define TK_ID 27
8004
+#define TK_INDEXED 28
8005
+#define TK_ABORT 29
8006
+#define TK_ACTION 30
8007
+#define TK_AFTER 31
8008
+#define TK_ANALYZE 32
8009
+#define TK_ASC 33
8010
+#define TK_ATTACH 34
8011
+#define TK_BEFORE 35
8012
+#define TK_BY 36
8013
+#define TK_CASCADE 37
8014
+#define TK_CAST 38
8015
+#define TK_COLUMNKW 39
8016
+#define TK_CONFLICT 40
8017
+#define TK_DATABASE 41
8018
+#define TK_DESC 42
8019
+#define TK_DETACH 43
8020
+#define TK_EACH 44
8021
+#define TK_FAIL 45
8022
+#define TK_FOR 46
8023
+#define TK_IGNORE 47
8024
+#define TK_INITIALLY 48
8025
+#define TK_INSTEAD 49
8026
+#define TK_LIKE_KW 50
8027
+#define TK_MATCH 51
8028
+#define TK_NO 52
8029
+#define TK_KEY 53
8030
+#define TK_OF 54
8031
+#define TK_OFFSET 55
8032
+#define TK_PRAGMA 56
8033
+#define TK_RAISE 57
8034
+#define TK_REPLACE 58
8035
+#define TK_RESTRICT 59
8036
+#define TK_ROW 60
8037
+#define TK_TRIGGER 61
8038
+#define TK_VACUUM 62
8039
+#define TK_VIEW 63
8040
+#define TK_VIRTUAL 64
8041
+#define TK_REINDEX 65
8042
+#define TK_RENAME 66
8043
+#define TK_CTIME_KW 67
8044
+#define TK_ANY 68
8045
+#define TK_OR 69
8046
+#define TK_AND 70
8047
+#define TK_IS 71
8048
+#define TK_BETWEEN 72
8049
+#define TK_IN 73
8050
+#define TK_ISNULL 74
8051
+#define TK_NOTNULL 75
8052
+#define TK_NE 76
8053
+#define TK_EQ 77
8054
+#define TK_GT 78
8055
+#define TK_LE 79
8056
+#define TK_LT 80
8057
+#define TK_GE 81
8058
+#define TK_ESCAPE 82
8059
+#define TK_BITAND 83
8060
+#define TK_BITOR 84
8061
+#define TK_LSHIFT 85
8062
+#define TK_RSHIFT 86
8063
+#define TK_PLUS 87
8064
+#define TK_MINUS 88
8065
+#define TK_STAR 89
8066
+#define TK_SLASH 90
8067
+#define TK_REM 91
8068
+#define TK_CONCAT 92
8069
+#define TK_COLLATE 93
8070
+#define TK_BITNOT 94
8071
+#define TK_STRING 95
8072
+#define TK_JOIN_KW 96
8073
+#define TK_CONSTRAINT 97
8074
+#define TK_DEFAULT 98
8075
+#define TK_NULL 99
8076
+#define TK_PRIMARY 100
8077
+#define TK_UNIQUE 101
8078
+#define TK_CHECK 102
8079
+#define TK_REFERENCES 103
8080
+#define TK_AUTOINCR 104
8081
+#define TK_ON 105
8082
+#define TK_INSERT 106
8083
+#define TK_DELETE 107
8084
+#define TK_UPDATE 108
8085
+#define TK_SET 109
8086
+#define TK_DEFERRABLE 110
8087
+#define TK_FOREIGN 111
8088
+#define TK_DROP 112
8089
+#define TK_UNION 113
8090
+#define TK_ALL 114
8091
+#define TK_EXCEPT 115
8092
+#define TK_INTERSECT 116
8093
+#define TK_SELECT 117
8094
+#define TK_DISTINCT 118
8095
+#define TK_DOT 119
8096
+#define TK_FROM 120
8097
+#define TK_JOIN 121
8098
+#define TK_USING 122
8099
+#define TK_ORDER 123
8100
+#define TK_GROUP 124
8101
+#define TK_HAVING 125
8102
+#define TK_LIMIT 126
8103
+#define TK_WHERE 127
8104
+#define TK_INTO 128
8105
+#define TK_VALUES 129
8106
+#define TK_INTEGER 130
8107
+#define TK_FLOAT 131
8108
+#define TK_BLOB 132
8109
+#define TK_REGISTER 133
8110
+#define TK_VARIABLE 134
8111
+#define TK_CASE 135
8112
+#define TK_WHEN 136
8113
+#define TK_THEN 137
8114
+#define TK_ELSE 138
8115
+#define TK_INDEX 139
8116
+#define TK_ALTER 140
8117
+#define TK_ADD 141
8118
+#define TK_TO_TEXT 142
8119
+#define TK_TO_BLOB 143
8120
+#define TK_TO_NUMERIC 144
8121
+#define TK_TO_INT 145
8122
+#define TK_TO_REAL 146
8123
+#define TK_ISNOT 147
8124
+#define TK_END_OF_FILE 148
8125
+#define TK_ILLEGAL 149
8126
+#define TK_SPACE 150
8127
+#define TK_UNCLOSED_STRING 151
8128
+#define TK_FUNCTION 152
8129
+#define TK_COLUMN 153
8130
+#define TK_AGG_FUNCTION 154
8131
+#define TK_AGG_COLUMN 155
8132
+#define TK_CONST_FUNC 156
8133
+#define TK_UMINUS 157
8134
+#define TK_UPLUS 158
81108135
81118136
/************** End of parse.h ***********************************************/
81128137
/************** Continuing where we left off in sqliteInt.h ******************/
81138138
#include <stdio.h>
81148139
#include <stdlib.h>
@@ -8881,11 +8906,11 @@
88818906
KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
88828907
int *ai; /* Used when p4type is P4_INTARRAY */
88838908
SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
88848909
int (*xAdvance)(BtCursor *, int *);
88858910
} p4;
8886
-#ifdef SQLITE_DEBUG
8911
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
88878912
char *zComment; /* Comment to improve readability */
88888913
#endif
88898914
#ifdef VDBE_PROFILE
88908915
int cnt; /* Number of times this instruction was executed */
88918916
u64 cycles; /* Total time spent executing this instruction */
@@ -8937,19 +8962,15 @@
89378962
#define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
89388963
#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
89398964
#define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */
89408965
#define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
89418966
8942
-/* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure
8943
-** is made. That copy is freed when the Vdbe is finalized. But if the
8944
-** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used. It still
8945
-** gets freed when the Vdbe is finalized so it still should be obtained
8946
-** from a single sqliteMalloc(). But no copy is made and the calling
8947
-** function should *not* try to free the KeyInfo.
8948
-*/
8949
-#define P4_KEYINFO_HANDOFF (-16)
8950
-#define P4_KEYINFO_STATIC (-17)
8967
+/* Error message codes for OP_Halt */
8968
+#define P5_ConstraintNotNull 1
8969
+#define P5_ConstraintUnique 2
8970
+#define P5_ConstraintCheck 3
8971
+#define P5_ConstraintFK 4
89518972
89528973
/*
89538974
** The Vdbe.aColName array contains 5n Mem structures, where n is the
89548975
** number of columns of data returned by the statement.
89558976
*/
@@ -8982,160 +9003,160 @@
89829003
*/
89839004
/************** Include opcodes.h in the middle of vdbe.h ********************/
89849005
/************** Begin file opcodes.h *****************************************/
89859006
/* Automatically generated. Do not edit */
89869007
/* See the mkopcodeh.awk script for details */
8987
-#define OP_Function 1
8988
-#define OP_Savepoint 2
8989
-#define OP_AutoCommit 3
8990
-#define OP_Transaction 4
8991
-#define OP_SorterNext 5
8992
-#define OP_Prev 6
8993
-#define OP_Next 7
8994
-#define OP_AggStep 8
8995
-#define OP_Checkpoint 9
8996
-#define OP_JournalMode 10
8997
-#define OP_Vacuum 11
8998
-#define OP_VFilter 12
8999
-#define OP_VUpdate 13
9000
-#define OP_Goto 14
9001
-#define OP_Gosub 15
9002
-#define OP_Return 16
9003
-#define OP_Yield 17
9004
-#define OP_HaltIfNull 18
9005
-#define OP_Not 19 /* same as TK_NOT */
9006
-#define OP_Halt 20
9007
-#define OP_Integer 21
9008
-#define OP_Int64 22
9009
-#define OP_String 23
9010
-#define OP_Null 24
9011
-#define OP_Blob 25
9012
-#define OP_Variable 26
9013
-#define OP_Move 27
9014
-#define OP_Copy 28
9015
-#define OP_SCopy 29
9016
-#define OP_ResultRow 30
9017
-#define OP_CollSeq 31
9018
-#define OP_AddImm 32
9019
-#define OP_MustBeInt 33
9020
-#define OP_RealAffinity 34
9021
-#define OP_Permutation 35
9022
-#define OP_Compare 36
9023
-#define OP_Jump 37
9024
-#define OP_Once 38
9025
-#define OP_If 39
9026
-#define OP_IfNot 40
9027
-#define OP_Column 41
9028
-#define OP_Affinity 42
9029
-#define OP_MakeRecord 43
9030
-#define OP_Count 44
9031
-#define OP_ReadCookie 45
9032
-#define OP_SetCookie 46
9033
-#define OP_VerifyCookie 47
9034
-#define OP_OpenRead 48
9035
-#define OP_OpenWrite 49
9036
-#define OP_OpenAutoindex 50
9037
-#define OP_OpenEphemeral 51
9038
-#define OP_SorterOpen 52
9039
-#define OP_OpenPseudo 53
9040
-#define OP_Close 54
9041
-#define OP_SeekLt 55
9042
-#define OP_SeekLe 56
9043
-#define OP_SeekGe 57
9044
-#define OP_SeekGt 58
9045
-#define OP_Seek 59
9046
-#define OP_NotFound 60
9047
-#define OP_Found 61
9048
-#define OP_IsUnique 62
9049
-#define OP_NotExists 63
9050
-#define OP_Sequence 64
9051
-#define OP_NewRowid 65
9052
-#define OP_Insert 66
9053
-#define OP_InsertInt 67
9054
-#define OP_Or 68 /* same as TK_OR */
9055
-#define OP_And 69 /* same as TK_AND */
9056
-#define OP_Delete 70
9057
-#define OP_ResetCount 71
9058
-#define OP_SorterCompare 72
9059
-#define OP_IsNull 73 /* same as TK_ISNULL */
9060
-#define OP_NotNull 74 /* same as TK_NOTNULL */
9061
-#define OP_Ne 75 /* same as TK_NE */
9062
-#define OP_Eq 76 /* same as TK_EQ */
9063
-#define OP_Gt 77 /* same as TK_GT */
9064
-#define OP_Le 78 /* same as TK_LE */
9065
-#define OP_Lt 79 /* same as TK_LT */
9066
-#define OP_Ge 80 /* same as TK_GE */
9067
-#define OP_SorterData 81
9068
-#define OP_BitAnd 82 /* same as TK_BITAND */
9069
-#define OP_BitOr 83 /* same as TK_BITOR */
9070
-#define OP_ShiftLeft 84 /* same as TK_LSHIFT */
9071
-#define OP_ShiftRight 85 /* same as TK_RSHIFT */
9072
-#define OP_Add 86 /* same as TK_PLUS */
9073
-#define OP_Subtract 87 /* same as TK_MINUS */
9074
-#define OP_Multiply 88 /* same as TK_STAR */
9075
-#define OP_Divide 89 /* same as TK_SLASH */
9076
-#define OP_Remainder 90 /* same as TK_REM */
9077
-#define OP_Concat 91 /* same as TK_CONCAT */
9078
-#define OP_RowKey 92
9079
-#define OP_BitNot 93 /* same as TK_BITNOT */
9080
-#define OP_String8 94 /* same as TK_STRING */
9081
-#define OP_RowData 95
9082
-#define OP_Rowid 96
9083
-#define OP_NullRow 97
9084
-#define OP_Last 98
9085
-#define OP_SorterSort 99
9086
-#define OP_Sort 100
9087
-#define OP_Rewind 101
9088
-#define OP_SorterInsert 102
9089
-#define OP_IdxInsert 103
9090
-#define OP_IdxDelete 104
9091
-#define OP_IdxRowid 105
9092
-#define OP_IdxLT 106
9093
-#define OP_IdxGE 107
9094
-#define OP_Destroy 108
9095
-#define OP_Clear 109
9096
-#define OP_CreateIndex 110
9097
-#define OP_CreateTable 111
9098
-#define OP_ParseSchema 112
9099
-#define OP_LoadAnalysis 113
9100
-#define OP_DropTable 114
9101
-#define OP_DropIndex 115
9102
-#define OP_DropTrigger 116
9103
-#define OP_IntegrityCk 117
9104
-#define OP_RowSetAdd 118
9105
-#define OP_RowSetRead 119
9106
-#define OP_RowSetTest 120
9107
-#define OP_Program 121
9108
-#define OP_Param 122
9109
-#define OP_FkCounter 123
9110
-#define OP_FkIfZero 124
9111
-#define OP_MemMax 125
9112
-#define OP_IfPos 126
9113
-#define OP_IfNeg 127
9114
-#define OP_IfZero 128
9115
-#define OP_AggFinal 129
9116
-#define OP_Real 130 /* same as TK_FLOAT */
9117
-#define OP_IncrVacuum 131
9118
-#define OP_Expire 132
9119
-#define OP_TableLock 133
9120
-#define OP_VBegin 134
9121
-#define OP_VCreate 135
9122
-#define OP_VDestroy 136
9123
-#define OP_VOpen 137
9124
-#define OP_VColumn 138
9125
-#define OP_VNext 139
9126
-#define OP_VRename 140
9127
-#define OP_ToText 141 /* same as TK_TO_TEXT */
9128
-#define OP_ToBlob 142 /* same as TK_TO_BLOB */
9129
-#define OP_ToNumeric 143 /* same as TK_TO_NUMERIC*/
9130
-#define OP_ToInt 144 /* same as TK_TO_INT */
9131
-#define OP_ToReal 145 /* same as TK_TO_REAL */
9132
-#define OP_Pagecount 146
9133
-#define OP_MaxPgcnt 147
9134
-#define OP_Trace 148
9135
-#define OP_Noop 149
9136
-#define OP_Explain 150
9008
+#define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
9009
+#define OP_Savepoint 2
9010
+#define OP_AutoCommit 3
9011
+#define OP_Transaction 4
9012
+#define OP_SorterNext 5
9013
+#define OP_Prev 6
9014
+#define OP_Next 7
9015
+#define OP_AggStep 8 /* synopsis: accum=r[P3] step(r[P2@P5]) */
9016
+#define OP_Checkpoint 9
9017
+#define OP_JournalMode 10
9018
+#define OP_Vacuum 11
9019
+#define OP_VFilter 12 /* synopsis: iPlan=r[P3] zPlan='P4' */
9020
+#define OP_VUpdate 13 /* synopsis: data=r[P3@P2] */
9021
+#define OP_Goto 14
9022
+#define OP_Gosub 15
9023
+#define OP_Return 16
9024
+#define OP_Yield 17
9025
+#define OP_HaltIfNull 18 /* synopsis: if r[P3] null then halt */
9026
+#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9027
+#define OP_Halt 20
9028
+#define OP_Integer 21 /* synopsis: r[P2]=P1 */
9029
+#define OP_Int64 22 /* synopsis: r[P2]=P4 */
9030
+#define OP_String 23 /* synopsis: r[P2]='P4' (len=P1) */
9031
+#define OP_Null 24 /* synopsis: r[P2..P3]=NULL */
9032
+#define OP_Blob 25 /* synopsis: r[P2]=P4 (len=P1) */
9033
+#define OP_Variable 26 /* synopsis: r[P2]=parameter(P1,P4) */
9034
+#define OP_Move 27 /* synopsis: r[P2@P3]=r[P1@P3] */
9035
+#define OP_Copy 28 /* synopsis: r[P2@P3]=r[P1@P3] */
9036
+#define OP_SCopy 29 /* synopsis: r[P2]=r[P1] */
9037
+#define OP_ResultRow 30 /* synopsis: output=r[P1@P2] */
9038
+#define OP_CollSeq 31
9039
+#define OP_AddImm 32 /* synopsis: r[P1]=r[P1]+P2 */
9040
+#define OP_MustBeInt 33
9041
+#define OP_RealAffinity 34
9042
+#define OP_Permutation 35
9043
+#define OP_Compare 36
9044
+#define OP_Jump 37
9045
+#define OP_Once 38
9046
+#define OP_If 39
9047
+#define OP_IfNot 40
9048
+#define OP_Column 41 /* synopsis: r[P3]=PX */
9049
+#define OP_Affinity 42 /* synopsis: affinity(r[P1@P2]) */
9050
+#define OP_MakeRecord 43 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9051
+#define OP_Count 44 /* synopsis: r[P2]=count() */
9052
+#define OP_ReadCookie 45
9053
+#define OP_SetCookie 46
9054
+#define OP_VerifyCookie 47
9055
+#define OP_OpenRead 48 /* synopsis: root=P2 iDb=P3 */
9056
+#define OP_OpenWrite 49 /* synopsis: root=P2 iDb=P3 */
9057
+#define OP_OpenAutoindex 50 /* synopsis: nColumn=P2 */
9058
+#define OP_OpenEphemeral 51 /* synopsis: nColumn=P2 */
9059
+#define OP_SorterOpen 52
9060
+#define OP_OpenPseudo 53 /* synopsis: content in r[P2@P3] */
9061
+#define OP_Close 54
9062
+#define OP_SeekLt 55 /* synopsis: key=r[P3@P4] */
9063
+#define OP_SeekLe 56 /* synopsis: key=r[P3@P4] */
9064
+#define OP_SeekGe 57 /* synopsis: key=r[P3@P4] */
9065
+#define OP_SeekGt 58 /* synopsis: key=r[P3@P4] */
9066
+#define OP_Seek 59 /* synopsis: intkey=r[P2] */
9067
+#define OP_NoConflict 60 /* synopsis: key=r[P3@P4] */
9068
+#define OP_NotFound 61 /* synopsis: key=r[P3@P4] */
9069
+#define OP_Found 62 /* synopsis: key=r[P3@P4] */
9070
+#define OP_NotExists 63 /* synopsis: intkey=r[P3] */
9071
+#define OP_Sequence 64 /* synopsis: r[P2]=rowid */
9072
+#define OP_NewRowid 65 /* synopsis: r[P2]=rowid */
9073
+#define OP_Insert 66 /* synopsis: intkey=r[P3] data=r[P2] */
9074
+#define OP_InsertInt 67 /* synopsis: intkey=P3 data=r[P2] */
9075
+#define OP_Delete 68
9076
+#define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9077
+#define OP_And 70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9078
+#define OP_ResetCount 71
9079
+#define OP_SorterCompare 72 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9080
+#define OP_SorterData 73 /* synopsis: r[P2]=data */
9081
+#define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9082
+#define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9083
+#define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9084
+#define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9085
+#define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9086
+#define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9087
+#define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P3 */
9088
+#define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9089
+#define OP_RowKey 82 /* synopsis: r[P2]=key */
9090
+#define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9091
+#define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9092
+#define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9093
+#define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9094
+#define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
9095
+#define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9096
+#define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9097
+#define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P1]/r[P2] */
9098
+#define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P1]%r[P2] */
9099
+#define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9100
+#define OP_RowData 93 /* synopsis: r[P2]=data */
9101
+#define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9102
+#define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
9103
+#define OP_Rowid 96 /* synopsis: r[P2]=rowid */
9104
+#define OP_NullRow 97
9105
+#define OP_Last 98
9106
+#define OP_SorterSort 99
9107
+#define OP_Sort 100
9108
+#define OP_Rewind 101
9109
+#define OP_SorterInsert 102
9110
+#define OP_IdxInsert 103 /* synopsis: key=r[P2] */
9111
+#define OP_IdxDelete 104 /* synopsis: key=r[P2@P3] */
9112
+#define OP_IdxRowid 105 /* synopsis: r[P2]=rowid */
9113
+#define OP_IdxLT 106 /* synopsis: key=r[P3@P4] */
9114
+#define OP_IdxGE 107 /* synopsis: key=r[P3@P4] */
9115
+#define OP_Destroy 108
9116
+#define OP_Clear 109
9117
+#define OP_CreateIndex 110 /* synopsis: r[P2]=root iDb=P1 */
9118
+#define OP_CreateTable 111 /* synopsis: r[P2]=root iDb=P1 */
9119
+#define OP_ParseSchema 112
9120
+#define OP_LoadAnalysis 113
9121
+#define OP_DropTable 114
9122
+#define OP_DropIndex 115
9123
+#define OP_DropTrigger 116
9124
+#define OP_IntegrityCk 117
9125
+#define OP_RowSetAdd 118 /* synopsis: rowset(P1)=r[P2] */
9126
+#define OP_RowSetRead 119 /* synopsis: r[P3]=rowset(P1) */
9127
+#define OP_RowSetTest 120 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9128
+#define OP_Program 121
9129
+#define OP_Param 122
9130
+#define OP_FkCounter 123 /* synopsis: fkctr[P1]+=P2 */
9131
+#define OP_FkIfZero 124 /* synopsis: if fkctr[P1]==0 goto P2 */
9132
+#define OP_MemMax 125 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9133
+#define OP_IfPos 126 /* synopsis: if r[P1]>0 goto P2 */
9134
+#define OP_IfNeg 127 /* synopsis: if r[P1]<0 goto P2 */
9135
+#define OP_IfZero 128 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9136
+#define OP_AggFinal 129 /* synopsis: accum=r[P1] N=P2 */
9137
+#define OP_IncrVacuum 130
9138
+#define OP_Real 131 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9139
+#define OP_Expire 132
9140
+#define OP_TableLock 133 /* synopsis: iDb=P1 root=P2 write=P3 */
9141
+#define OP_VBegin 134
9142
+#define OP_VCreate 135
9143
+#define OP_VDestroy 136
9144
+#define OP_VOpen 137
9145
+#define OP_VColumn 138 /* synopsis: r[P3]=vcolumn(P2) */
9146
+#define OP_VNext 139
9147
+#define OP_VRename 140
9148
+#define OP_Pagecount 141
9149
+#define OP_ToText 142 /* same as TK_TO_TEXT */
9150
+#define OP_ToBlob 143 /* same as TK_TO_BLOB */
9151
+#define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
9152
+#define OP_ToInt 145 /* same as TK_TO_INT */
9153
+#define OP_ToReal 146 /* same as TK_TO_REAL */
9154
+#define OP_MaxPgcnt 147
9155
+#define OP_Trace 148
9156
+#define OP_Noop 149
9157
+#define OP_Explain 150
91379158
91389159
91399160
/* Properties such as "out2" or "jump" that are specified in
91409161
** comments following the "case" for each opcode in the vdbe.c
91419162
** are encoded into bitvectors as follows:
@@ -9149,26 +9170,26 @@
91499170
#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
91509171
#define OPFLG_INITIALIZER {\
91519172
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
91529173
/* 8 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01,\
91539174
/* 16 */ 0x04, 0x04, 0x10, 0x24, 0x00, 0x02, 0x02, 0x02,\
9154
-/* 24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x00, 0x00,\
9175
+/* 24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00,\
91559176
/* 32 */ 0x04, 0x05, 0x04, 0x00, 0x00, 0x01, 0x01, 0x05,\
91569177
/* 40 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00,\
91579178
/* 48 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,\
91589179
/* 56 */ 0x11, 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11,\
9159
-/* 64 */ 0x02, 0x02, 0x00, 0x00, 0x4c, 0x4c, 0x00, 0x00,\
9160
-/* 72 */ 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
9161
-/* 80 */ 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9162
-/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02, 0x00,\
9180
+/* 64 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c, 0x4c, 0x00,\
9181
+/* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
9182
+/* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9183
+/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
91639184
/* 96 */ 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08,\
91649185
/* 104 */ 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02, 0x02,\
91659186
/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
91669187
/* 120 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05, 0x05,\
9167
-/* 128 */ 0x05, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,\
9168
-/* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x04, 0x04,\
9169
-/* 144 */ 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00,}
9188
+/* 128 */ 0x05, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,\
9189
+/* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x04, 0x04,\
9190
+/* 144 */ 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,}
91709191
91719192
/************** End of opcodes.h *********************************************/
91729193
/************** Continuing where we left off in vdbe.h ***********************/
91739194
91749195
/*
@@ -9189,10 +9210,11 @@
91899210
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
91909211
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
91919212
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
91929213
SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
91939214
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
9215
+SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
91949216
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
91959217
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
91969218
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
91979219
SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
91989220
SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
@@ -9227,19 +9249,31 @@
92279249
92289250
#ifndef SQLITE_OMIT_TRIGGER
92299251
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
92309252
#endif
92319253
9232
-
9233
-#ifndef NDEBUG
9254
+/* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
9255
+** each VDBE opcode.
9256
+**
9257
+** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
9258
+** comments in VDBE programs that show key decision points in the code
9259
+** generator.
9260
+*/
9261
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
92349262
SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
92359263
# define VdbeComment(X) sqlite3VdbeComment X
92369264
SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
92379265
# define VdbeNoopComment(X) sqlite3VdbeNoopComment X
9266
+# ifdef SQLITE_ENABLE_MODULE_COMMENTS
9267
+# define VdbeModuleComment(X) sqlite3VdbeNoopComment X
9268
+# else
9269
+# define VdbeModuleComment(X)
9270
+# endif
92389271
#else
92399272
# define VdbeComment(X)
92409273
# define VdbeNoopComment(X)
9274
+# define VdbeModuleComment(X)
92419275
#endif
92429276
92439277
#endif
92449278
92459279
/************** End of vdbe.h ************************************************/
@@ -10631,10 +10665,11 @@
1063110665
#define TF_Readonly 0x01 /* Read-only system table */
1063210666
#define TF_Ephemeral 0x02 /* An ephemeral table */
1063310667
#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
1063410668
#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
1063510669
#define TF_Virtual 0x10 /* Is a virtual table */
10670
+#define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
1063610671
1063710672
1063810673
/*
1063910674
** Test to see whether or not a table is a virtual table. This is
1064010675
** done as a macro so that it will be optimized out when virtual
@@ -10646,10 +10681,13 @@
1064610681
#else
1064710682
# define IsVirtual(X) 0
1064810683
# define IsHiddenColumn(X) 0
1064910684
#endif
1065010685
10686
+/* Does the table have a rowid */
10687
+#define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
10688
+
1065110689
/*
1065210690
** Each foreign key constraint is an instance of the following structure.
1065310691
**
1065410692
** A foreign key is associated with two tables. The "from" table is
1065510693
** the table that contains the REFERENCES clause that creates the foreign
@@ -10660,30 +10698,39 @@
1066010698
** a INTEGER PRIMARY KEY,
1066110699
** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
1066210700
** );
1066310701
**
1066410702
** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
10703
+** Equivalent names:
10704
+**
10705
+** from-table == child-table
10706
+** to-table == parent-table
1066510707
**
1066610708
** Each REFERENCES clause generates an instance of the following structure
1066710709
** which is attached to the from-table. The to-table need not exist when
1066810710
** the from-table is created. The existence of the to-table is not checked.
10711
+**
10712
+** The list of all parents for child Table X is held at X.pFKey.
10713
+**
10714
+** A list of all children for a table named Z (which might not even exist)
10715
+** is held in Schema.fkeyHash with a hash key of Z.
1066910716
*/
1067010717
struct FKey {
1067110718
Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */
10672
- FKey *pNextFrom; /* Next foreign key in pFrom */
10719
+ FKey *pNextFrom; /* Next FKey with the same in pFrom. Next parent of pFrom */
1067310720
char *zTo; /* Name of table that the key points to (aka: Parent) */
10674
- FKey *pNextTo; /* Next foreign key on table named zTo */
10675
- FKey *pPrevTo; /* Previous foreign key on table named zTo */
10721
+ FKey *pNextTo; /* Next with the same zTo. Next child of zTo. */
10722
+ FKey *pPrevTo; /* Previous with the same zTo */
1067610723
int nCol; /* Number of columns in this key */
1067710724
/* EV: R-30323-21917 */
10678
- u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
10679
- u8 aAction[2]; /* ON DELETE and ON UPDATE actions, respectively */
10680
- Trigger *apTrigger[2]; /* Triggers for aAction[] actions */
10681
- struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
10682
- int iFrom; /* Index of column in pFrom */
10683
- char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */
10684
- } aCol[1]; /* One entry for each of nCol column s */
10725
+ u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
10726
+ u8 aAction[2]; /* ON DELETE and ON UPDATE actions, respectively */
10727
+ Trigger *apTrigger[2];/* Triggers for aAction[] actions */
10728
+ struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
10729
+ int iFrom; /* Index of column in pFrom */
10730
+ char *zCol; /* Name of column in zTo. If NULL use PRIMARY KEY */
10731
+ } aCol[1]; /* One entry for each of nCol columns */
1068510732
};
1068610733
1068710734
/*
1068810735
** SQLite supports many different ways to resolve a constraint
1068910736
** error. ROLLBACK processing means that a constraint violation
@@ -10732,13 +10779,15 @@
1073210779
** Note that aSortOrder[] and aColl[] have nField+1 slots. There
1073310780
** are nField slots for the columns of an index then one extra slot
1073410781
** for the rowid at the end.
1073510782
*/
1073610783
struct KeyInfo {
10737
- sqlite3 *db; /* The database connection */
10784
+ u32 nRef; /* Number of references to this KeyInfo object */
1073810785
u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
10739
- u16 nField; /* Maximum index for aColl[] and aSortOrder[] */
10786
+ u16 nField; /* Number of key columns in the index */
10787
+ u16 nXField; /* Number of columns beyond the key columns */
10788
+ sqlite3 *db; /* The database connection */
1074010789
u8 *aSortOrder; /* Sort order for each column. */
1074110790
CollSeq *aColl[1]; /* Collating sequence for each term of the key */
1074210791
};
1074310792
1074410793
/*
@@ -10757,20 +10806,18 @@
1075710806
*/
1075810807
struct UnpackedRecord {
1075910808
KeyInfo *pKeyInfo; /* Collation and sort-order information */
1076010809
u16 nField; /* Number of entries in apMem[] */
1076110810
u8 flags; /* Boolean settings. UNPACKED_... below */
10762
- i64 rowid; /* Used by UNPACKED_PREFIX_SEARCH */
1076310811
Mem *aMem; /* Values */
1076410812
};
1076510813
1076610814
/*
1076710815
** Allowed values of UnpackedRecord.flags
1076810816
*/
1076910817
#define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
1077010818
#define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
10771
-#define UNPACKED_PREFIX_SEARCH 0x04 /* Ignore final (rowid) field */
1077210819
1077310820
/*
1077410821
** Each SQL index is represented in memory by an
1077510822
** instance of the following structure.
1077610823
**
@@ -10796,26 +10843,30 @@
1079610843
** algorithm to employ whenever an attempt is made to insert a non-unique
1079710844
** element.
1079810845
*/
1079910846
struct Index {
1080010847
char *zName; /* Name of this index */
10801
- int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10848
+ i16 *aiColumn; /* Which columns are used by this index. 1st is 0 */
1080210849
tRowcnt *aiRowEst; /* From ANALYZE: Est. rows selected by each column */
1080310850
Table *pTable; /* The SQL table being indexed */
1080410851
char *zColAff; /* String defining the affinity of each column */
1080510852
Index *pNext; /* The next index associated with the same table */
1080610853
Schema *pSchema; /* Schema containing this index */
1080710854
u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
1080810855
char **azColl; /* Array of collation sequence names for index */
1080910856
Expr *pPartIdxWhere; /* WHERE clause for partial indices */
10857
+ KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */
1081010858
int tnum; /* DB Page containing root of this index */
1081110859
LogEst szIdxRow; /* Estimated average row size in bytes */
10812
- u16 nColumn; /* Number of columns in table used by this index */
10860
+ u16 nKeyCol; /* Number of columns forming the key */
10861
+ u16 nColumn; /* Number of columns stored in the index */
1081310862
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
1081410863
unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
1081510864
unsigned bUnordered:1; /* Use this index for == or IN queries only */
1081610865
unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
10866
+ unsigned isResized:1; /* True if resizeIndexObject() has been called */
10867
+ unsigned isCovering:1; /* True if this is a covering index */
1081710868
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
1081810869
int nSample; /* Number of elements in aSample[] */
1081910870
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
1082010871
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1082110872
IndexSample *aSample; /* Samples of the left-most key */
@@ -11490,10 +11541,12 @@
1149011541
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
1149111542
1149211543
/* Information used while coding trigger programs. */
1149311544
Parse *pToplevel; /* Parse structure for main program (or NULL) */
1149411545
Table *pTriggerTab; /* Table triggers are being coded for */
11546
+ int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */
11547
+ int addrSkipPK; /* Address of instruction to skip PRIMARY KEY index */
1149511548
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
1149611549
u32 oldmask; /* Mask of old.* columns referenced */
1149711550
u32 newmask; /* Mask of new.* columns referenced */
1149811551
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
1149911552
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
@@ -11502,10 +11555,11 @@
1150211555
/* Above is constant between recursions. Below is reset before and after
1150311556
** each recursion */
1150411557
1150511558
int nVar; /* Number of '?' variables seen in the SQL so far */
1150611559
int nzVar; /* Number of available slots in azVar[] */
11560
+ u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
1150711561
u8 explain; /* True if the EXPLAIN flag is found on the query */
1150811562
#ifndef SQLITE_OMIT_VIRTUALTABLE
1150911563
u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
1151011564
int nVtabLock; /* Number of virtual tables to lock */
1151111565
#endif
@@ -11515,11 +11569,10 @@
1151511569
int iSelectId; /* ID of current select for EXPLAIN output */
1151611570
int iNextSelectId; /* Next available select ID for EXPLAIN output */
1151711571
#endif
1151811572
char **azVar; /* Pointers to names of parameters */
1151911573
Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
11520
- int *aAlias; /* Register used to hold aliased result */
1152111574
const char *zTail; /* All SQL text past the last semicolon parsed */
1152211575
Table *pNewTable; /* A table being constructed by CREATE TABLE */
1152311576
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
1152411577
const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
1152511578
Token sNameToken; /* Token with unqualified schema object name */
@@ -11984,19 +12037,21 @@
1198412037
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
1198512038
SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
1198612039
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
1198712040
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
1198812041
SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
12042
+SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
12043
+SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
1198912044
SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
1199012045
SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*);
1199112046
SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
1199212047
SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
1199312048
SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
1199412049
SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
1199512050
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
1199612051
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
11997
-SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
12052
+SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
1199812053
SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
1199912054
sqlite3_vfs**,char**,char **);
1200012055
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
1200112056
SQLITE_PRIVATE int sqlite3CodeOnce(Parse *);
1200212057
@@ -12045,10 +12100,11 @@
1204512100
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
1204612101
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
1204712102
SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
1204812103
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
1204912104
SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
12105
+SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
1205012106
SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
1205112107
Expr*, int, int);
1205212108
SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
1205312109
SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
1205412110
SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
@@ -12067,11 +12123,11 @@
1206712123
SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo*);
1206812124
SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
1206912125
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
1207012126
SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
1207112127
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
12072
-SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*);
12128
+SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
1207312129
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
1207412130
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
1207512131
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1207612132
SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
1207712133
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
@@ -12121,21 +12177,23 @@
1212112177
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1212212178
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
1212312179
SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
1212412180
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
1212512181
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12126
-SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
12127
-SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*);
12182
+SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
12183
+SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
1212812184
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
12129
-SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
12130
- int*,int,int,int,int,int*);
12131
-SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
12132
-SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
12185
+SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
12186
+ u8,u8,int,int*);
12187
+SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12188
+SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, int*, int*);
1213312189
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
1213412190
SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
1213512191
SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
12136
-SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, int);
12192
+SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
12193
+SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
12194
+SQLITE_PRIVATE void sqlite3RowidConstraint(Parse*, int, Table*);
1213712195
SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
1213812196
SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
1213912197
SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
1214012198
SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
1214112199
SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int);
@@ -12349,12 +12407,17 @@
1234912407
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
1235012408
SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
1235112409
SQLITE_PRIVATE void sqlite3SchemaClear(void *);
1235212410
SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
1235312411
SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
12354
-SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int);
12355
-SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
12412
+SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
12413
+SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
12414
+SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
12415
+SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
12416
+#ifdef SQLITE_DEBUG
12417
+SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*);
12418
+#endif
1235612419
SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
1235712420
void (*)(sqlite3_context*,int,sqlite3_value **),
1235812421
void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
1235912422
FuncDestructor *pDestructor
1236012423
);
@@ -13350,12 +13413,11 @@
1335013413
i64 seqCount; /* Sequence counter */
1335113414
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1335213415
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
1335313416
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
1335413417
13355
- /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
13356
- ** OP_IsUnique opcode on this cursor. */
13418
+ /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */
1335713419
int seekResult;
1335813420
1335913421
/* Cached information about the header for the data record that the
1336013422
** cursor is currently pointing to. Only valid if cacheStatus matches
1336113423
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -13716,11 +13778,11 @@
1371613778
SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
1371713779
SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
1371813780
SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
1371913781
SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, const VdbeCursor *, int *);
1372013782
SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, const VdbeCursor *, Mem *);
13721
-SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int *);
13783
+SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
1372213784
1372313785
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
1372413786
SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
1372513787
SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
1372613788
#else
@@ -22794,163 +22856,168 @@
2279422856
2279522857
/************** End of hash.c ************************************************/
2279622858
/************** Begin file opcodes.c *****************************************/
2279722859
/* Automatically generated. Do not edit */
2279822860
/* See the mkopcodec.awk script for details. */
22799
-#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
22861
+#if !defined(SQLITE_OMIT_EXPLAIN) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
22862
+#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) || defined(SQLITE_DEBUG)
22863
+# define OpHelp(X) "\0" X
22864
+#else
22865
+# define OpHelp(X)
22866
+#endif
2280022867
SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
2280122868
static const char *const azName[] = { "?",
22802
- /* 1 */ "Function",
22803
- /* 2 */ "Savepoint",
22804
- /* 3 */ "AutoCommit",
22805
- /* 4 */ "Transaction",
22806
- /* 5 */ "SorterNext",
22807
- /* 6 */ "Prev",
22808
- /* 7 */ "Next",
22809
- /* 8 */ "AggStep",
22810
- /* 9 */ "Checkpoint",
22811
- /* 10 */ "JournalMode",
22812
- /* 11 */ "Vacuum",
22813
- /* 12 */ "VFilter",
22814
- /* 13 */ "VUpdate",
22815
- /* 14 */ "Goto",
22816
- /* 15 */ "Gosub",
22817
- /* 16 */ "Return",
22818
- /* 17 */ "Yield",
22819
- /* 18 */ "HaltIfNull",
22820
- /* 19 */ "Not",
22821
- /* 20 */ "Halt",
22822
- /* 21 */ "Integer",
22823
- /* 22 */ "Int64",
22824
- /* 23 */ "String",
22825
- /* 24 */ "Null",
22826
- /* 25 */ "Blob",
22827
- /* 26 */ "Variable",
22828
- /* 27 */ "Move",
22829
- /* 28 */ "Copy",
22830
- /* 29 */ "SCopy",
22831
- /* 30 */ "ResultRow",
22832
- /* 31 */ "CollSeq",
22833
- /* 32 */ "AddImm",
22834
- /* 33 */ "MustBeInt",
22835
- /* 34 */ "RealAffinity",
22836
- /* 35 */ "Permutation",
22837
- /* 36 */ "Compare",
22838
- /* 37 */ "Jump",
22839
- /* 38 */ "Once",
22840
- /* 39 */ "If",
22841
- /* 40 */ "IfNot",
22842
- /* 41 */ "Column",
22843
- /* 42 */ "Affinity",
22844
- /* 43 */ "MakeRecord",
22845
- /* 44 */ "Count",
22846
- /* 45 */ "ReadCookie",
22847
- /* 46 */ "SetCookie",
22848
- /* 47 */ "VerifyCookie",
22849
- /* 48 */ "OpenRead",
22850
- /* 49 */ "OpenWrite",
22851
- /* 50 */ "OpenAutoindex",
22852
- /* 51 */ "OpenEphemeral",
22853
- /* 52 */ "SorterOpen",
22854
- /* 53 */ "OpenPseudo",
22855
- /* 54 */ "Close",
22856
- /* 55 */ "SeekLt",
22857
- /* 56 */ "SeekLe",
22858
- /* 57 */ "SeekGe",
22859
- /* 58 */ "SeekGt",
22860
- /* 59 */ "Seek",
22861
- /* 60 */ "NotFound",
22862
- /* 61 */ "Found",
22863
- /* 62 */ "IsUnique",
22864
- /* 63 */ "NotExists",
22865
- /* 64 */ "Sequence",
22866
- /* 65 */ "NewRowid",
22867
- /* 66 */ "Insert",
22868
- /* 67 */ "InsertInt",
22869
- /* 68 */ "Or",
22870
- /* 69 */ "And",
22871
- /* 70 */ "Delete",
22872
- /* 71 */ "ResetCount",
22873
- /* 72 */ "SorterCompare",
22874
- /* 73 */ "IsNull",
22875
- /* 74 */ "NotNull",
22876
- /* 75 */ "Ne",
22877
- /* 76 */ "Eq",
22878
- /* 77 */ "Gt",
22879
- /* 78 */ "Le",
22880
- /* 79 */ "Lt",
22881
- /* 80 */ "Ge",
22882
- /* 81 */ "SorterData",
22883
- /* 82 */ "BitAnd",
22884
- /* 83 */ "BitOr",
22885
- /* 84 */ "ShiftLeft",
22886
- /* 85 */ "ShiftRight",
22887
- /* 86 */ "Add",
22888
- /* 87 */ "Subtract",
22889
- /* 88 */ "Multiply",
22890
- /* 89 */ "Divide",
22891
- /* 90 */ "Remainder",
22892
- /* 91 */ "Concat",
22893
- /* 92 */ "RowKey",
22894
- /* 93 */ "BitNot",
22895
- /* 94 */ "String8",
22896
- /* 95 */ "RowData",
22897
- /* 96 */ "Rowid",
22898
- /* 97 */ "NullRow",
22899
- /* 98 */ "Last",
22900
- /* 99 */ "SorterSort",
22901
- /* 100 */ "Sort",
22902
- /* 101 */ "Rewind",
22903
- /* 102 */ "SorterInsert",
22904
- /* 103 */ "IdxInsert",
22905
- /* 104 */ "IdxDelete",
22906
- /* 105 */ "IdxRowid",
22907
- /* 106 */ "IdxLT",
22908
- /* 107 */ "IdxGE",
22909
- /* 108 */ "Destroy",
22910
- /* 109 */ "Clear",
22911
- /* 110 */ "CreateIndex",
22912
- /* 111 */ "CreateTable",
22913
- /* 112 */ "ParseSchema",
22914
- /* 113 */ "LoadAnalysis",
22915
- /* 114 */ "DropTable",
22916
- /* 115 */ "DropIndex",
22917
- /* 116 */ "DropTrigger",
22918
- /* 117 */ "IntegrityCk",
22919
- /* 118 */ "RowSetAdd",
22920
- /* 119 */ "RowSetRead",
22921
- /* 120 */ "RowSetTest",
22922
- /* 121 */ "Program",
22923
- /* 122 */ "Param",
22924
- /* 123 */ "FkCounter",
22925
- /* 124 */ "FkIfZero",
22926
- /* 125 */ "MemMax",
22927
- /* 126 */ "IfPos",
22928
- /* 127 */ "IfNeg",
22929
- /* 128 */ "IfZero",
22930
- /* 129 */ "AggFinal",
22931
- /* 130 */ "Real",
22932
- /* 131 */ "IncrVacuum",
22933
- /* 132 */ "Expire",
22934
- /* 133 */ "TableLock",
22935
- /* 134 */ "VBegin",
22936
- /* 135 */ "VCreate",
22937
- /* 136 */ "VDestroy",
22938
- /* 137 */ "VOpen",
22939
- /* 138 */ "VColumn",
22940
- /* 139 */ "VNext",
22941
- /* 140 */ "VRename",
22942
- /* 141 */ "ToText",
22943
- /* 142 */ "ToBlob",
22944
- /* 143 */ "ToNumeric",
22945
- /* 144 */ "ToInt",
22946
- /* 145 */ "ToReal",
22947
- /* 146 */ "Pagecount",
22948
- /* 147 */ "MaxPgcnt",
22949
- /* 148 */ "Trace",
22950
- /* 149 */ "Noop",
22951
- /* 150 */ "Explain",
22869
+ /* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
22870
+ /* 2 */ "Savepoint" OpHelp(""),
22871
+ /* 3 */ "AutoCommit" OpHelp(""),
22872
+ /* 4 */ "Transaction" OpHelp(""),
22873
+ /* 5 */ "SorterNext" OpHelp(""),
22874
+ /* 6 */ "Prev" OpHelp(""),
22875
+ /* 7 */ "Next" OpHelp(""),
22876
+ /* 8 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
22877
+ /* 9 */ "Checkpoint" OpHelp(""),
22878
+ /* 10 */ "JournalMode" OpHelp(""),
22879
+ /* 11 */ "Vacuum" OpHelp(""),
22880
+ /* 12 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"),
22881
+ /* 13 */ "VUpdate" OpHelp("data=r[P3@P2]"),
22882
+ /* 14 */ "Goto" OpHelp(""),
22883
+ /* 15 */ "Gosub" OpHelp(""),
22884
+ /* 16 */ "Return" OpHelp(""),
22885
+ /* 17 */ "Yield" OpHelp(""),
22886
+ /* 18 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
22887
+ /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
22888
+ /* 20 */ "Halt" OpHelp(""),
22889
+ /* 21 */ "Integer" OpHelp("r[P2]=P1"),
22890
+ /* 22 */ "Int64" OpHelp("r[P2]=P4"),
22891
+ /* 23 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
22892
+ /* 24 */ "Null" OpHelp("r[P2..P3]=NULL"),
22893
+ /* 25 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
22894
+ /* 26 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
22895
+ /* 27 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
22896
+ /* 28 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
22897
+ /* 29 */ "SCopy" OpHelp("r[P2]=r[P1]"),
22898
+ /* 30 */ "ResultRow" OpHelp("output=r[P1@P2]"),
22899
+ /* 31 */ "CollSeq" OpHelp(""),
22900
+ /* 32 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
22901
+ /* 33 */ "MustBeInt" OpHelp(""),
22902
+ /* 34 */ "RealAffinity" OpHelp(""),
22903
+ /* 35 */ "Permutation" OpHelp(""),
22904
+ /* 36 */ "Compare" OpHelp(""),
22905
+ /* 37 */ "Jump" OpHelp(""),
22906
+ /* 38 */ "Once" OpHelp(""),
22907
+ /* 39 */ "If" OpHelp(""),
22908
+ /* 40 */ "IfNot" OpHelp(""),
22909
+ /* 41 */ "Column" OpHelp("r[P3]=PX"),
22910
+ /* 42 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
22911
+ /* 43 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
22912
+ /* 44 */ "Count" OpHelp("r[P2]=count()"),
22913
+ /* 45 */ "ReadCookie" OpHelp(""),
22914
+ /* 46 */ "SetCookie" OpHelp(""),
22915
+ /* 47 */ "VerifyCookie" OpHelp(""),
22916
+ /* 48 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
22917
+ /* 49 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
22918
+ /* 50 */ "OpenAutoindex" OpHelp("nColumn=P2"),
22919
+ /* 51 */ "OpenEphemeral" OpHelp("nColumn=P2"),
22920
+ /* 52 */ "SorterOpen" OpHelp(""),
22921
+ /* 53 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
22922
+ /* 54 */ "Close" OpHelp(""),
22923
+ /* 55 */ "SeekLt" OpHelp("key=r[P3@P4]"),
22924
+ /* 56 */ "SeekLe" OpHelp("key=r[P3@P4]"),
22925
+ /* 57 */ "SeekGe" OpHelp("key=r[P3@P4]"),
22926
+ /* 58 */ "SeekGt" OpHelp("key=r[P3@P4]"),
22927
+ /* 59 */ "Seek" OpHelp("intkey=r[P2]"),
22928
+ /* 60 */ "NoConflict" OpHelp("key=r[P3@P4]"),
22929
+ /* 61 */ "NotFound" OpHelp("key=r[P3@P4]"),
22930
+ /* 62 */ "Found" OpHelp("key=r[P3@P4]"),
22931
+ /* 63 */ "NotExists" OpHelp("intkey=r[P3]"),
22932
+ /* 64 */ "Sequence" OpHelp("r[P2]=rowid"),
22933
+ /* 65 */ "NewRowid" OpHelp("r[P2]=rowid"),
22934
+ /* 66 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
22935
+ /* 67 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
22936
+ /* 68 */ "Delete" OpHelp(""),
22937
+ /* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
22938
+ /* 70 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
22939
+ /* 71 */ "ResetCount" OpHelp(""),
22940
+ /* 72 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
22941
+ /* 73 */ "SorterData" OpHelp("r[P2]=data"),
22942
+ /* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
22943
+ /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
22944
+ /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
22945
+ /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
22946
+ /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
22947
+ /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22948
+ /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P3"),
22949
+ /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
22950
+ /* 82 */ "RowKey" OpHelp("r[P2]=key"),
22951
+ /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
22952
+ /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
22953
+ /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
22954
+ /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
22955
+ /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
22956
+ /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
22957
+ /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22958
+ /* 90 */ "Divide" OpHelp("r[P3]=r[P1]/r[P2]"),
22959
+ /* 91 */ "Remainder" OpHelp("r[P3]=r[P1]%r[P2]"),
22960
+ /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22961
+ /* 93 */ "RowData" OpHelp("r[P2]=data"),
22962
+ /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
22963
+ /* 95 */ "String8" OpHelp("r[P2]='P4'"),
22964
+ /* 96 */ "Rowid" OpHelp("r[P2]=rowid"),
22965
+ /* 97 */ "NullRow" OpHelp(""),
22966
+ /* 98 */ "Last" OpHelp(""),
22967
+ /* 99 */ "SorterSort" OpHelp(""),
22968
+ /* 100 */ "Sort" OpHelp(""),
22969
+ /* 101 */ "Rewind" OpHelp(""),
22970
+ /* 102 */ "SorterInsert" OpHelp(""),
22971
+ /* 103 */ "IdxInsert" OpHelp("key=r[P2]"),
22972
+ /* 104 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
22973
+ /* 105 */ "IdxRowid" OpHelp("r[P2]=rowid"),
22974
+ /* 106 */ "IdxLT" OpHelp("key=r[P3@P4]"),
22975
+ /* 107 */ "IdxGE" OpHelp("key=r[P3@P4]"),
22976
+ /* 108 */ "Destroy" OpHelp(""),
22977
+ /* 109 */ "Clear" OpHelp(""),
22978
+ /* 110 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
22979
+ /* 111 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
22980
+ /* 112 */ "ParseSchema" OpHelp(""),
22981
+ /* 113 */ "LoadAnalysis" OpHelp(""),
22982
+ /* 114 */ "DropTable" OpHelp(""),
22983
+ /* 115 */ "DropIndex" OpHelp(""),
22984
+ /* 116 */ "DropTrigger" OpHelp(""),
22985
+ /* 117 */ "IntegrityCk" OpHelp(""),
22986
+ /* 118 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
22987
+ /* 119 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
22988
+ /* 120 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
22989
+ /* 121 */ "Program" OpHelp(""),
22990
+ /* 122 */ "Param" OpHelp(""),
22991
+ /* 123 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
22992
+ /* 124 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
22993
+ /* 125 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
22994
+ /* 126 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
22995
+ /* 127 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
22996
+ /* 128 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
22997
+ /* 129 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
22998
+ /* 130 */ "IncrVacuum" OpHelp(""),
22999
+ /* 131 */ "Real" OpHelp("r[P2]=P4"),
23000
+ /* 132 */ "Expire" OpHelp(""),
23001
+ /* 133 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23002
+ /* 134 */ "VBegin" OpHelp(""),
23003
+ /* 135 */ "VCreate" OpHelp(""),
23004
+ /* 136 */ "VDestroy" OpHelp(""),
23005
+ /* 137 */ "VOpen" OpHelp(""),
23006
+ /* 138 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23007
+ /* 139 */ "VNext" OpHelp(""),
23008
+ /* 140 */ "VRename" OpHelp(""),
23009
+ /* 141 */ "Pagecount" OpHelp(""),
23010
+ /* 142 */ "ToText" OpHelp(""),
23011
+ /* 143 */ "ToBlob" OpHelp(""),
23012
+ /* 144 */ "ToNumeric" OpHelp(""),
23013
+ /* 145 */ "ToInt" OpHelp(""),
23014
+ /* 146 */ "ToReal" OpHelp(""),
23015
+ /* 147 */ "MaxPgcnt" OpHelp(""),
23016
+ /* 148 */ "Trace" OpHelp(""),
23017
+ /* 149 */ "Noop" OpHelp(""),
23018
+ /* 150 */ "Explain" OpHelp(""),
2295223019
};
2295323020
return azName[i];
2295423021
}
2295523022
#endif
2295623023
@@ -25053,11 +25120,13 @@
2505325120
**
2505425121
** If the locking level of the file descriptor is already at or below
2505525122
** the requested locking level, this routine is a no-op.
2505625123
*/
2505725124
static int unixUnlock(sqlite3_file *id, int eFileLock){
25125
+#if SQLITE_MAX_MMAP_SIZE>0
2505825126
assert( eFileLock==SHARED_LOCK || ((unixFile *)id)->nFetchOut==0 );
25127
+#endif
2505925128
return posixUnlock(id, eFileLock, 0);
2506025129
}
2506125130
2506225131
#if SQLITE_MAX_MMAP_SIZE>0
2506325132
static int unixMapfile(unixFile *pFd, i64 nByte);
@@ -30878,38 +30947,52 @@
3087830947
#if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
3087930948
# error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
3088030949
must be defined."
3088130950
#endif
3088230951
30952
+/*
30953
+** This constant should already be defined (in the "WinDef.h" SDK file).
30954
+*/
30955
+#ifndef MAX_PATH
30956
+# define MAX_PATH (260)
30957
+#endif
30958
+
3088330959
/*
3088430960
** Maximum pathname length (in chars) for Win32. This should normally be
3088530961
** MAX_PATH.
3088630962
*/
3088730963
#ifndef SQLITE_WIN32_MAX_PATH_CHARS
3088830964
# define SQLITE_WIN32_MAX_PATH_CHARS (MAX_PATH)
3088930965
#endif
3089030966
30967
+/*
30968
+** This constant should already be defined (in the "WinNT.h" SDK file).
30969
+*/
30970
+#ifndef UNICODE_STRING_MAX_CHARS
30971
+# define UNICODE_STRING_MAX_CHARS (32767)
30972
+#endif
30973
+
3089130974
/*
3089230975
** Maximum pathname length (in chars) for WinNT. This should normally be
30893
-** 32767.
30976
+** UNICODE_STRING_MAX_CHARS.
3089430977
*/
3089530978
#ifndef SQLITE_WINNT_MAX_PATH_CHARS
30896
-# define SQLITE_WINNT_MAX_PATH_CHARS (32767)
30979
+# define SQLITE_WINNT_MAX_PATH_CHARS (UNICODE_STRING_MAX_CHARS)
3089730980
#endif
3089830981
3089930982
/*
3090030983
** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in
30901
-** characters, so we allocate 3 bytes per character assuming worst-case of
30984
+** characters, so we allocate 4 bytes per character assuming worst-case of
3090230985
** 4-bytes-per-character for UTF8.
3090330986
*/
3090430987
#ifndef SQLITE_WIN32_MAX_PATH_BYTES
3090530988
# define SQLITE_WIN32_MAX_PATH_BYTES (SQLITE_WIN32_MAX_PATH_CHARS*4)
3090630989
#endif
3090730990
3090830991
/*
3090930992
** Maximum pathname length (in bytes) for WinNT. This should normally be
30910
-** 32767 * sizeof(WCHAR).
30993
+** UNICODE_STRING_MAX_CHARS * sizeof(WCHAR).
3091130994
*/
3091230995
#ifndef SQLITE_WINNT_MAX_PATH_BYTES
3091330996
# define SQLITE_WINNT_MAX_PATH_BYTES \
3091430997
(sizeof(WCHAR) * SQLITE_WINNT_MAX_PATH_CHARS)
3091530998
#endif
@@ -30936,18 +31019,14 @@
3093631019
#ifndef UNUSED_VARIABLE_VALUE
3093731020
# define UNUSED_VARIABLE_VALUE(x) (void)(x)
3093831021
#endif
3093931022
3094031023
/*
30941
-** Returns the string that should be used as the directory separator.
31024
+** Returns the character that should be used as the directory separator.
3094231025
*/
30943
-#ifndef winGetDirDep
30944
-# ifdef __CYGWIN__
30945
-# define winGetDirDep() "/"
30946
-# else
30947
-# define winGetDirDep() "\\"
30948
-# endif
31026
+#ifndef winGetDirSep
31027
+# define winGetDirSep() '\\'
3094931028
#endif
3095031029
3095131030
/*
3095231031
** Do we need to manually define the Win32 file mapping APIs for use with WAL
3095331032
** mode (e.g. these APIs are available in the Windows CE SDK; however, they
@@ -31135,34 +31214,45 @@
3113531214
** sqlite3_mem_methods implementation.
3113631215
*/
3113731216
typedef struct winMemData winMemData;
3113831217
struct winMemData {
3113931218
#ifndef NDEBUG
31140
- u32 magic; /* Magic number to detect structure corruption. */
31219
+ u32 magic1; /* Magic number to detect structure corruption. */
3114131220
#endif
3114231221
HANDLE hHeap; /* The handle to our heap. */
3114331222
BOOL bOwned; /* Do we own the heap (i.e. destroy it on shutdown)? */
31223
+#ifndef NDEBUG
31224
+ u32 magic2; /* Magic number to detect structure corruption. */
31225
+#endif
3114431226
};
3114531227
3114631228
#ifndef NDEBUG
31147
-#define WINMEM_MAGIC 0x42b2830b
31229
+#define WINMEM_MAGIC1 0x42b2830b
31230
+#define WINMEM_MAGIC2 0xbd4d7cf4
3114831231
#endif
3114931232
3115031233
static struct winMemData win_mem_data = {
3115131234
#ifndef NDEBUG
31152
- WINMEM_MAGIC,
31235
+ WINMEM_MAGIC1,
3115331236
#endif
3115431237
NULL, FALSE
31238
+#ifndef NDEBUG
31239
+ ,WINMEM_MAGIC2
31240
+#endif
3115531241
};
3115631242
3115731243
#ifndef NDEBUG
31158
-#define winMemAssertMagic() assert( win_mem_data.magic==WINMEM_MAGIC )
31244
+#define winMemAssertMagic1() assert( win_mem_data.magic1==WINMEM_MAGIC1 )
31245
+#define winMemAssertMagic2() assert( win_mem_data.magic2==WINMEM_MAGIC2 )
31246
+#define winMemAssertMagic() winMemAssertMagic1(); winMemAssertMagic2();
3115931247
#else
3116031248
#define winMemAssertMagic()
3116131249
#endif
3116231250
31163
-#define winMemGetHeap() win_mem_data.hHeap
31251
+#define winMemGetDataPtr() &win_mem_data
31252
+#define winMemGetHeap() win_mem_data.hHeap
31253
+#define winMemGetOwned() win_mem_data.bOwned
3116431254
3116531255
static void *winMemMalloc(int nBytes);
3116631256
static void winMemFree(void *pPrior);
3116731257
static void *winMemRealloc(void *pPrior, int nBytes);
3116831258
static int winMemSize(void *p);
@@ -31555,44 +31645,52 @@
3155531645
#endif
3155631646
3155731647
#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
3155831648
LPCVOID))aSyscall[42].pCurrent)
3155931649
31650
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31651
+ { "HeapCompact", (SYSCALL)HeapCompact, 0 },
31652
+#else
31653
+ { "HeapCompact", (SYSCALL)0, 0 },
31654
+#endif
31655
+
31656
+#define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[43].pCurrent)
31657
+
3156031658
#if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
3156131659
{ "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
3156231660
#else
3156331661
{ "LoadLibraryA", (SYSCALL)0, 0 },
3156431662
#endif
3156531663
31566
-#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[43].pCurrent)
31664
+#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
3156731665
3156831666
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
3156931667
!defined(SQLITE_OMIT_LOAD_EXTENSION)
3157031668
{ "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
3157131669
#else
3157231670
{ "LoadLibraryW", (SYSCALL)0, 0 },
3157331671
#endif
3157431672
31575
-#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[44].pCurrent)
31673
+#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[45].pCurrent)
3157631674
3157731675
#if !SQLITE_OS_WINRT
3157831676
{ "LocalFree", (SYSCALL)LocalFree, 0 },
3157931677
#else
3158031678
{ "LocalFree", (SYSCALL)0, 0 },
3158131679
#endif
3158231680
31583
-#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[45].pCurrent)
31681
+#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[46].pCurrent)
3158431682
3158531683
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3158631684
{ "LockFile", (SYSCALL)LockFile, 0 },
3158731685
#else
3158831686
{ "LockFile", (SYSCALL)0, 0 },
3158931687
#endif
3159031688
3159131689
#ifndef osLockFile
3159231690
#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31593
- DWORD))aSyscall[46].pCurrent)
31691
+ DWORD))aSyscall[47].pCurrent)
3159431692
#endif
3159531693
3159631694
#if !SQLITE_OS_WINCE
3159731695
{ "LockFileEx", (SYSCALL)LockFileEx, 0 },
3159831696
#else
@@ -31599,218 +31697,218 @@
3159931697
{ "LockFileEx", (SYSCALL)0, 0 },
3160031698
#endif
3160131699
3160231700
#ifndef osLockFileEx
3160331701
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
31604
- LPOVERLAPPED))aSyscall[47].pCurrent)
31702
+ LPOVERLAPPED))aSyscall[48].pCurrent)
3160531703
#endif
3160631704
3160731705
#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
3160831706
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
3160931707
#else
3161031708
{ "MapViewOfFile", (SYSCALL)0, 0 },
3161131709
#endif
3161231710
3161331711
#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31614
- SIZE_T))aSyscall[48].pCurrent)
31712
+ SIZE_T))aSyscall[49].pCurrent)
3161531713
3161631714
{ "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
3161731715
3161831716
#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
31619
- int))aSyscall[49].pCurrent)
31717
+ int))aSyscall[50].pCurrent)
3162031718
3162131719
{ "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
3162231720
3162331721
#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
31624
- LARGE_INTEGER*))aSyscall[50].pCurrent)
31722
+ LARGE_INTEGER*))aSyscall[51].pCurrent)
3162531723
3162631724
{ "ReadFile", (SYSCALL)ReadFile, 0 },
3162731725
3162831726
#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
31629
- LPOVERLAPPED))aSyscall[51].pCurrent)
31727
+ LPOVERLAPPED))aSyscall[52].pCurrent)
3163031728
3163131729
{ "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
3163231730
31633
-#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent)
31731
+#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[53].pCurrent)
3163431732
3163531733
#if !SQLITE_OS_WINRT
3163631734
{ "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
3163731735
#else
3163831736
{ "SetFilePointer", (SYSCALL)0, 0 },
3163931737
#endif
3164031738
3164131739
#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
31642
- DWORD))aSyscall[53].pCurrent)
31740
+ DWORD))aSyscall[54].pCurrent)
3164331741
3164431742
#if !SQLITE_OS_WINRT
3164531743
{ "Sleep", (SYSCALL)Sleep, 0 },
3164631744
#else
3164731745
{ "Sleep", (SYSCALL)0, 0 },
3164831746
#endif
3164931747
31650
-#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[54].pCurrent)
31748
+#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent)
3165131749
3165231750
{ "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
3165331751
3165431752
#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
31655
- LPFILETIME))aSyscall[55].pCurrent)
31753
+ LPFILETIME))aSyscall[56].pCurrent)
3165631754
3165731755
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3165831756
{ "UnlockFile", (SYSCALL)UnlockFile, 0 },
3165931757
#else
3166031758
{ "UnlockFile", (SYSCALL)0, 0 },
3166131759
#endif
3166231760
3166331761
#ifndef osUnlockFile
3166431762
#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31665
- DWORD))aSyscall[56].pCurrent)
31763
+ DWORD))aSyscall[57].pCurrent)
3166631764
#endif
3166731765
3166831766
#if !SQLITE_OS_WINCE
3166931767
{ "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
3167031768
#else
3167131769
{ "UnlockFileEx", (SYSCALL)0, 0 },
3167231770
#endif
3167331771
3167431772
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31675
- LPOVERLAPPED))aSyscall[57].pCurrent)
31773
+ LPOVERLAPPED))aSyscall[58].pCurrent)
3167631774
3167731775
#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
3167831776
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
3167931777
#else
3168031778
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
3168131779
#endif
3168231780
31683
-#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[58].pCurrent)
31781
+#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[59].pCurrent)
3168431782
3168531783
{ "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
3168631784
3168731785
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
31688
- LPCSTR,LPBOOL))aSyscall[59].pCurrent)
31786
+ LPCSTR,LPBOOL))aSyscall[60].pCurrent)
3168931787
3169031788
{ "WriteFile", (SYSCALL)WriteFile, 0 },
3169131789
3169231790
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
31693
- LPOVERLAPPED))aSyscall[60].pCurrent)
31791
+ LPOVERLAPPED))aSyscall[61].pCurrent)
3169431792
3169531793
#if SQLITE_OS_WINRT
3169631794
{ "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
3169731795
#else
3169831796
{ "CreateEventExW", (SYSCALL)0, 0 },
3169931797
#endif
3170031798
3170131799
#define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
31702
- DWORD,DWORD))aSyscall[61].pCurrent)
31800
+ DWORD,DWORD))aSyscall[62].pCurrent)
3170331801
3170431802
#if !SQLITE_OS_WINRT
3170531803
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
3170631804
#else
3170731805
{ "WaitForSingleObject", (SYSCALL)0, 0 },
3170831806
#endif
3170931807
3171031808
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
31711
- DWORD))aSyscall[62].pCurrent)
31809
+ DWORD))aSyscall[63].pCurrent)
3171231810
3171331811
#if SQLITE_OS_WINRT
3171431812
{ "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
3171531813
#else
3171631814
{ "WaitForSingleObjectEx", (SYSCALL)0, 0 },
3171731815
#endif
3171831816
3171931817
#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
31720
- BOOL))aSyscall[63].pCurrent)
31818
+ BOOL))aSyscall[64].pCurrent)
3172131819
3172231820
#if SQLITE_OS_WINRT
3172331821
{ "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
3172431822
#else
3172531823
{ "SetFilePointerEx", (SYSCALL)0, 0 },
3172631824
#endif
3172731825
3172831826
#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
31729
- PLARGE_INTEGER,DWORD))aSyscall[64].pCurrent)
31827
+ PLARGE_INTEGER,DWORD))aSyscall[65].pCurrent)
3173031828
3173131829
#if SQLITE_OS_WINRT
3173231830
{ "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
3173331831
#else
3173431832
{ "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
3173531833
#endif
3173631834
3173731835
#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
31738
- FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[65].pCurrent)
31836
+ FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
3173931837
3174031838
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3174131839
{ "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
3174231840
#else
3174331841
{ "MapViewOfFileFromApp", (SYSCALL)0, 0 },
3174431842
#endif
3174531843
3174631844
#define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
31747
- SIZE_T))aSyscall[66].pCurrent)
31845
+ SIZE_T))aSyscall[67].pCurrent)
3174831846
3174931847
#if SQLITE_OS_WINRT
3175031848
{ "CreateFile2", (SYSCALL)CreateFile2, 0 },
3175131849
#else
3175231850
{ "CreateFile2", (SYSCALL)0, 0 },
3175331851
#endif
3175431852
3175531853
#define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
31756
- LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[67].pCurrent)
31854
+ LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[68].pCurrent)
3175731855
3175831856
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_LOAD_EXTENSION)
3175931857
{ "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
3176031858
#else
3176131859
{ "LoadPackagedLibrary", (SYSCALL)0, 0 },
3176231860
#endif
3176331861
3176431862
#define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
31765
- DWORD))aSyscall[68].pCurrent)
31863
+ DWORD))aSyscall[69].pCurrent)
3176631864
3176731865
#if SQLITE_OS_WINRT
3176831866
{ "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
3176931867
#else
3177031868
{ "GetTickCount64", (SYSCALL)0, 0 },
3177131869
#endif
3177231870
31773
-#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[69].pCurrent)
31871
+#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[70].pCurrent)
3177431872
3177531873
#if SQLITE_OS_WINRT
3177631874
{ "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
3177731875
#else
3177831876
{ "GetNativeSystemInfo", (SYSCALL)0, 0 },
3177931877
#endif
3178031878
3178131879
#define osGetNativeSystemInfo ((VOID(WINAPI*)( \
31782
- LPSYSTEM_INFO))aSyscall[70].pCurrent)
31880
+ LPSYSTEM_INFO))aSyscall[71].pCurrent)
3178331881
3178431882
#if defined(SQLITE_WIN32_HAS_ANSI)
3178531883
{ "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
3178631884
#else
3178731885
{ "OutputDebugStringA", (SYSCALL)0, 0 },
3178831886
#endif
3178931887
31790
-#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[71].pCurrent)
31888
+#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[72].pCurrent)
3179131889
3179231890
#if defined(SQLITE_WIN32_HAS_WIDE)
3179331891
{ "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
3179431892
#else
3179531893
{ "OutputDebugStringW", (SYSCALL)0, 0 },
3179631894
#endif
3179731895
31798
-#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[72].pCurrent)
31896
+#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[73].pCurrent)
3179931897
3180031898
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
3180131899
31802
-#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[73].pCurrent)
31900
+#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
3180331901
3180431902
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3180531903
{ "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
3180631904
#else
3180731905
{ "CreateFileMappingFromApp", (SYSCALL)0, 0 },
3180831906
#endif
3180931907
3181031908
#define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
31811
- LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[74].pCurrent)
31909
+ LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent)
3181231910
3181331911
}; /* End of the overrideable system calls */
3181431912
3181531913
/*
3181631914
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -31893,10 +31991,98 @@
3189331991
if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
3189431992
}
3189531993
return 0;
3189631994
}
3189731995
31996
+#ifdef SQLITE_WIN32_MALLOC
31997
+/*
31998
+** If a Win32 native heap has been configured, this function will attempt to
31999
+** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one
32000
+** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The
32001
+** "pnLargest" argument, if non-zero, will be used to return the size of the
32002
+** largest committed free block in the heap, in bytes.
32003
+*/
32004
+SQLITE_API int sqlite3_win32_compact_heap(LPUINT pnLargest){
32005
+ int rc = SQLITE_OK;
32006
+ UINT nLargest = 0;
32007
+ HANDLE hHeap;
32008
+
32009
+ winMemAssertMagic();
32010
+ hHeap = winMemGetHeap();
32011
+ assert( hHeap!=0 );
32012
+ assert( hHeap!=INVALID_HANDLE_VALUE );
32013
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32014
+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32015
+#endif
32016
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
32017
+ if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){
32018
+ DWORD lastErrno = osGetLastError();
32019
+ if( lastErrno==NO_ERROR ){
32020
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p",
32021
+ (void*)hHeap);
32022
+ rc = SQLITE_NOMEM;
32023
+ }else{
32024
+ sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p",
32025
+ osGetLastError(), (void*)hHeap);
32026
+ rc = SQLITE_ERROR;
32027
+ }
32028
+ }
32029
+#else
32030
+ sqlite3_log(SQLITE_NOTFOUND, "failed to HeapCompact, heap=%p",
32031
+ (void*)hHeap);
32032
+ rc = SQLITE_NOTFOUND;
32033
+#endif
32034
+ if( pnLargest ) *pnLargest = nLargest;
32035
+ return rc;
32036
+}
32037
+
32038
+/*
32039
+** If a Win32 native heap has been configured, this function will attempt to
32040
+** destroy and recreate it. If the Win32 native heap is not isolated and/or
32041
+** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
32042
+** be returned and no changes will be made to the Win32 native heap.
32043
+*/
32044
+SQLITE_API int sqlite3_win32_reset_heap(){
32045
+ int rc;
32046
+ MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
32047
+ MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
32048
+ MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
32049
+ MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
32050
+ sqlite3_mutex_enter(pMaster);
32051
+ sqlite3_mutex_enter(pMem);
32052
+ winMemAssertMagic();
32053
+ if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
32054
+ /*
32055
+ ** At this point, there should be no outstanding memory allocations on
32056
+ ** the heap. Also, since both the master and memsys locks are currently
32057
+ ** being held by us, no other function (i.e. from another thread) should
32058
+ ** be able to even access the heap. Attempt to destroy and recreate our
32059
+ ** isolated Win32 native heap now.
32060
+ */
32061
+ assert( winMemGetHeap()!=NULL );
32062
+ assert( winMemGetOwned() );
32063
+ assert( sqlite3_memory_used()==0 );
32064
+ winMemShutdown(winMemGetDataPtr());
32065
+ assert( winMemGetHeap()==NULL );
32066
+ assert( !winMemGetOwned() );
32067
+ assert( sqlite3_memory_used()==0 );
32068
+ rc = winMemInit(winMemGetDataPtr());
32069
+ assert( rc!=SQLITE_OK || winMemGetHeap()!=NULL );
32070
+ assert( rc!=SQLITE_OK || winMemGetOwned() );
32071
+ assert( rc!=SQLITE_OK || sqlite3_memory_used()==0 );
32072
+ }else{
32073
+ /*
32074
+ ** The Win32 native heap cannot be modified because it may be in use.
32075
+ */
32076
+ rc = SQLITE_BUSY;
32077
+ }
32078
+ sqlite3_mutex_leave(pMem);
32079
+ sqlite3_mutex_leave(pMaster);
32080
+ return rc;
32081
+}
32082
+#endif /* SQLITE_WIN32_MALLOC */
32083
+
3189832084
/*
3189932085
** This function outputs the specified (ANSI) string to the Win32 debugger
3190032086
** (if available).
3190132087
*/
3190232088
@@ -32001,11 +32187,11 @@
3200132187
winMemAssertMagic();
3200232188
hHeap = winMemGetHeap();
3200332189
assert( hHeap!=0 );
3200432190
assert( hHeap!=INVALID_HANDLE_VALUE );
3200532191
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32006
- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32192
+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3200732193
#endif
3200832194
assert( nBytes>=0 );
3200932195
p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
3201032196
if( !p ){
3201132197
sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%lu), heap=%p",
@@ -32023,11 +32209,11 @@
3202332209
winMemAssertMagic();
3202432210
hHeap = winMemGetHeap();
3202532211
assert( hHeap!=0 );
3202632212
assert( hHeap!=INVALID_HANDLE_VALUE );
3202732213
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32028
- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32214
+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
3202932215
#endif
3203032216
if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
3203132217
if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
3203232218
sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%lu), heap=%p",
3203332219
pPrior, osGetLastError(), (void*)hHeap);
@@ -32044,11 +32230,11 @@
3204432230
winMemAssertMagic();
3204532231
hHeap = winMemGetHeap();
3204632232
assert( hHeap!=0 );
3204732233
assert( hHeap!=INVALID_HANDLE_VALUE );
3204832234
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32049
- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32235
+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
3205032236
#endif
3205132237
assert( nBytes>=0 );
3205232238
if( !pPrior ){
3205332239
p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
3205432240
}else{
@@ -32072,11 +32258,11 @@
3207232258
winMemAssertMagic();
3207332259
hHeap = winMemGetHeap();
3207432260
assert( hHeap!=0 );
3207532261
assert( hHeap!=INVALID_HANDLE_VALUE );
3207632262
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32077
- assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32263
+ assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, p) );
3207832264
#endif
3207932265
if( !p ) return 0;
3208032266
n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
3208132267
if( n==(SIZE_T)-1 ){
3208232268
sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%lu), heap=%p",
@@ -32098,11 +32284,12 @@
3209832284
*/
3209932285
static int winMemInit(void *pAppData){
3210032286
winMemData *pWinMemData = (winMemData *)pAppData;
3210132287
3210232288
if( !pWinMemData ) return SQLITE_ERROR;
32103
- assert( pWinMemData->magic==WINMEM_MAGIC );
32289
+ assert( pWinMemData->magic1==WINMEM_MAGIC1 );
32290
+ assert( pWinMemData->magic2==WINMEM_MAGIC2 );
3210432291
3210532292
#if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
3210632293
if( !pWinMemData->hHeap ){
3210732294
pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
3210832295
SQLITE_WIN32_HEAP_INIT_SIZE,
@@ -32140,10 +32327,13 @@
3214032327
*/
3214132328
static void winMemShutdown(void *pAppData){
3214232329
winMemData *pWinMemData = (winMemData *)pAppData;
3214332330
3214432331
if( !pWinMemData ) return;
32332
+ assert( pWinMemData->magic1==WINMEM_MAGIC1 );
32333
+ assert( pWinMemData->magic2==WINMEM_MAGIC2 );
32334
+
3214532335
if( pWinMemData->hHeap ){
3214632336
assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
3214732337
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3214832338
assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3214932339
#endif
@@ -34809,16 +34999,25 @@
3480934999
return zConverted;
3481035000
}
3481135001
3481235002
/*
3481335003
** This function returns non-zero if the specified UTF-8 string buffer
34814
-** ends with a directory separator character.
35004
+** ends with a directory separator character or one was successfully
35005
+** added to it.
3481535006
*/
34816
-static int winEndsInDirSep(char *zBuf){
35007
+static int winMakeEndInDirSep(int nBuf, char *zBuf){
3481735008
if( zBuf ){
3481835009
int nLen = sqlite3Strlen30(zBuf);
34819
- return nLen>0 && winIsDirSep(zBuf[nLen-1]);
35010
+ if( nLen>0 ){
35011
+ if( winIsDirSep(zBuf[nLen-1]) ){
35012
+ return 1;
35013
+ }else if( nLen+1<nBuf ){
35014
+ zBuf[nLen] = winGetDirSep();
35015
+ zBuf[nLen+1] = '\0';
35016
+ return 1;
35017
+ }
35018
+ }
3482035019
}
3482135020
return 0;
3482235021
}
3482335022
3482435023
/*
@@ -34829,11 +35028,12 @@
3482935028
static char zChars[] =
3483035029
"abcdefghijklmnopqrstuvwxyz"
3483135030
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3483235031
"0123456789";
3483335032
size_t i, j;
34834
- int nBuf, nLen;
35033
+ int nPre = sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX);
35034
+ int nMax, nBuf, nDir, nLen;
3483535035
char *zBuf;
3483635036
3483735037
/* It's odd to simulate an io-error here, but really this is just
3483835038
** using the io-error infrastructure to test that SQLite handles this
3483935039
** function failing.
@@ -34841,26 +35041,36 @@
3484135041
SimulateIOError( return SQLITE_IOERR );
3484235042
3484335043
/* Allocate a temporary buffer to store the fully qualified file
3484435044
** name for the temporary file. If this fails, we cannot continue.
3484535045
*/
34846
- nBuf = pVfs->mxPathname;
34847
- zBuf = sqlite3MallocZero( nBuf+2 );
35046
+ nMax = pVfs->mxPathname; nBuf = nMax + 2;
35047
+ zBuf = sqlite3MallocZero( nBuf );
3484835048
if( !zBuf ){
3484935049
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
3485035050
return SQLITE_IOERR_NOMEM;
3485135051
}
3485235052
3485335053
/* Figure out the effective temporary directory. First, check if one
3485435054
** has been explicitly set by the application; otherwise, use the one
3485535055
** configured by the operating system.
3485635056
*/
34857
- assert( nBuf>30 );
35057
+ nDir = nMax - (nPre + 15);
35058
+ assert( nDir>0 );
3485835059
if( sqlite3_temp_directory ){
34859
- sqlite3_snprintf(nBuf-30, zBuf, "%s%s", sqlite3_temp_directory,
34860
- winEndsInDirSep(sqlite3_temp_directory) ? "" :
34861
- winGetDirDep());
35060
+ int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
35061
+ if( nDirLen>0 ){
35062
+ if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
35063
+ nDirLen++;
35064
+ }
35065
+ if( nDirLen>nDir ){
35066
+ sqlite3_free(zBuf);
35067
+ OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
35068
+ return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
35069
+ }
35070
+ sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
35071
+ }
3486235072
}
3486335073
#if defined(__CYGWIN__)
3486435074
else{
3486535075
static const char *azDirs[] = {
3486635076
0, /* getenv("SQLITE_TMPDIR") */
@@ -34885,41 +35095,41 @@
3488535095
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
3488635096
void *zConverted;
3488735097
if( zDir==0 ) continue;
3488835098
/* If the path starts with a drive letter followed by the colon
3488935099
** character, assume it is already a native Win32 path; otherwise,
34890
- ** it must be converted to a native Win32 path prior via the Cygwin
34891
- ** API prior to using it.
35100
+ ** it must be converted to a native Win32 path via the Cygwin API
35101
+ ** prior to using it.
3489235102
*/
3489335103
if( winIsDriveLetterAndColon(zDir) ){
3489435104
zConverted = winConvertFromUtf8Filename(zDir);
3489535105
if( !zConverted ){
3489635106
sqlite3_free(zBuf);
3489735107
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
3489835108
return SQLITE_IOERR_NOMEM;
3489935109
}
3490035110
if( winIsDir(zConverted) ){
34901
- sqlite3_snprintf(nBuf-30, zBuf, "%s", zDir);
35111
+ sqlite3_snprintf(nMax, zBuf, "%s", zDir);
3490235112
sqlite3_free(zConverted);
3490335113
break;
3490435114
}
3490535115
sqlite3_free(zConverted);
3490635116
}else{
34907
- zConverted = sqlite3MallocZero( nBuf+1 );
35117
+ zConverted = sqlite3MallocZero( nMax+1 );
3490835118
if( !zConverted ){
3490935119
sqlite3_free(zBuf);
3491035120
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
3491135121
return SQLITE_IOERR_NOMEM;
3491235122
}
3491335123
if( cygwin_conv_path(
3491435124
osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
34915
- zConverted, nBuf+1)<0 ){
35125
+ zConverted, nMax+1)<0 ){
3491635126
sqlite3_free(zConverted);
3491735127
sqlite3_free(zBuf);
3491835128
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
3491935129
return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
34920
- "winGetTempname1", zDir);
35130
+ "winGetTempname2", zDir);
3492135131
}
3492235132
if( winIsDir(zConverted) ){
3492335133
/* At this point, we know the candidate directory exists and should
3492435134
** be used. However, we may need to convert the string containing
3492535135
** its name into UTF-8 (i.e. if it is UTF-16 right now).
@@ -34930,16 +35140,16 @@
3493035140
sqlite3_free(zConverted);
3493135141
sqlite3_free(zBuf);
3493235142
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
3493335143
return SQLITE_IOERR_NOMEM;
3493435144
}
34935
- sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8);
35145
+ sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
3493635146
sqlite3_free(zUtf8);
3493735147
sqlite3_free(zConverted);
3493835148
break;
3493935149
}else{
34940
- sqlite3_snprintf(nBuf-30, zBuf, "%s", zConverted);
35150
+ sqlite3_snprintf(nMax, zBuf, "%s", zConverted);
3494135151
sqlite3_free(zConverted);
3494235152
break;
3494335153
}
3494435154
}
3494535155
sqlite3_free(zConverted);
@@ -34947,26 +35157,26 @@
3494735157
}
3494835158
}
3494935159
#elif !SQLITE_OS_WINRT && !defined(__CYGWIN__)
3495035160
else if( osIsNT() ){
3495135161
char *zMulti;
34952
- LPWSTR zWidePath = sqlite3MallocZero( nBuf*sizeof(WCHAR) );
35162
+ LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
3495335163
if( !zWidePath ){
3495435164
sqlite3_free(zBuf);
3495535165
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
3495635166
return SQLITE_IOERR_NOMEM;
3495735167
}
34958
- if( osGetTempPathW(nBuf, zWidePath)==0 ){
35168
+ if( osGetTempPathW(nMax, zWidePath)==0 ){
3495935169
sqlite3_free(zWidePath);
3496035170
sqlite3_free(zBuf);
3496135171
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
3496235172
return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
34963
- "winGetTempname1", 0);
35173
+ "winGetTempname2", 0);
3496435174
}
3496535175
zMulti = winUnicodeToUtf8(zWidePath);
3496635176
if( zMulti ){
34967
- sqlite3_snprintf(nBuf-30, zBuf, "%s", zMulti);
35177
+ sqlite3_snprintf(nMax, zBuf, "%s", zMulti);
3496835178
sqlite3_free(zMulti);
3496935179
sqlite3_free(zWidePath);
3497035180
}else{
3497135181
sqlite3_free(zWidePath);
3497235182
sqlite3_free(zBuf);
@@ -34975,25 +35185,25 @@
3497535185
}
3497635186
}
3497735187
#ifdef SQLITE_WIN32_HAS_ANSI
3497835188
else{
3497935189
char *zUtf8;
34980
- char *zMbcsPath = sqlite3MallocZero( nBuf );
35190
+ char *zMbcsPath = sqlite3MallocZero( nMax );
3498135191
if( !zMbcsPath ){
3498235192
sqlite3_free(zBuf);
3498335193
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
3498435194
return SQLITE_IOERR_NOMEM;
3498535195
}
34986
- if( osGetTempPathA(nBuf, zMbcsPath)==0 ){
35196
+ if( osGetTempPathA(nMax, zMbcsPath)==0 ){
3498735197
sqlite3_free(zBuf);
3498835198
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
3498935199
return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
34990
- "winGetTempname2", 0);
35200
+ "winGetTempname3", 0);
3499135201
}
3499235202
zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
3499335203
if( zUtf8 ){
34994
- sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8);
35204
+ sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
3499535205
sqlite3_free(zUtf8);
3499635206
}else{
3499735207
sqlite3_free(zBuf);
3499835208
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
3499935209
return SQLITE_IOERR_NOMEM;
@@ -35000,22 +35210,40 @@
3500035210
}
3500135211
}
3500235212
#endif /* SQLITE_WIN32_HAS_ANSI */
3500335213
#endif /* !SQLITE_OS_WINRT */
3500435214
35005
- /* Check that the output buffer is large enough for the temporary file
35006
- ** name. If it is not, return SQLITE_ERROR.
35215
+ /*
35216
+ ** Check to make sure the temporary directory ends with an appropriate
35217
+ ** separator. If it does not and there is not enough space left to add
35218
+ ** one, fail.
35219
+ */
35220
+ if( !winMakeEndInDirSep(nDir+1, zBuf) ){
35221
+ sqlite3_free(zBuf);
35222
+ OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
35223
+ return winLogError(SQLITE_ERROR, 0, "winGetTempname4", 0);
35224
+ }
35225
+
35226
+ /*
35227
+ ** Check that the output buffer is large enough for the temporary file
35228
+ ** name in the following format:
35229
+ **
35230
+ ** "<temporary_directory>/etilqs_XXXXXXXXXXXXXXX\0\0"
35231
+ **
35232
+ ** If not, return SQLITE_ERROR. The number 17 is used here in order to
35233
+ ** account for the space used by the 15 character random suffix and the
35234
+ ** two trailing NUL characters. The final directory separator character
35235
+ ** has already added if it was not already present.
3500735236
*/
3500835237
nLen = sqlite3Strlen30(zBuf);
35009
-
35010
- if( (nLen + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
35238
+ if( (nLen + nPre + 17) > nBuf ){
3501135239
sqlite3_free(zBuf);
3501235240
OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
35013
- return winLogError(SQLITE_ERROR, 0, "winGetTempname3", 0);
35241
+ return winLogError(SQLITE_ERROR, 0, "winGetTempname5", 0);
3501435242
}
3501535243
35016
- sqlite3_snprintf(nBuf-18-nLen, zBuf+nLen, SQLITE_TEMP_FILE_PREFIX);
35244
+ sqlite3_snprintf(nBuf-16-nLen, zBuf+nLen, SQLITE_TEMP_FILE_PREFIX);
3501735245
3501835246
j = sqlite3Strlen30(zBuf);
3501935247
sqlite3_randomness(15, &zBuf[j]);
3502035248
for(i=0; i<15; i++, j++){
3502135249
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
@@ -35066,11 +35294,11 @@
3506635294
sqlite3_file *id, /* Write the SQLite file handle here */
3506735295
int flags, /* Open mode flags */
3506835296
int *pOutFlags /* Status return flags */
3506935297
){
3507035298
HANDLE h;
35071
- DWORD lastErrno;
35299
+ DWORD lastErrno = 0;
3507235300
DWORD dwDesiredAccess;
3507335301
DWORD dwShareMode;
3507435302
DWORD dwCreationDisposition;
3507535303
DWORD dwFlagsAndAttributes = 0;
3507635304
#if SQLITE_OS_WINCE
@@ -35357,11 +35585,11 @@
3535735585
int syncDir /* Not used on win32 */
3535835586
){
3535935587
int cnt = 0;
3536035588
int rc;
3536135589
DWORD attr;
35362
- DWORD lastErrno;
35590
+ DWORD lastErrno = 0;
3536335591
void *zConverted;
3536435592
UNUSED_PARAMETER(pVfs);
3536535593
UNUSED_PARAMETER(syncDir);
3536635594
3536735595
SimulateIOError(return SQLITE_IOERR_DELETE);
@@ -35465,11 +35693,11 @@
3546535693
int flags, /* Type of test to make on this file */
3546635694
int *pResOut /* OUT: Result */
3546735695
){
3546835696
DWORD attr;
3546935697
int rc = 0;
35470
- DWORD lastErrno;
35698
+ DWORD lastErrno = 0;
3547135699
void *zConverted;
3547235700
UNUSED_PARAMETER(pVfs);
3547335701
3547435702
SimulateIOError( return SQLITE_IOERR_ACCESS; );
3547535703
OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
@@ -35611,12 +35839,12 @@
3561135839
pVfs->mxPathname+1)<0 ){
3561235840
sqlite3_free(zOut);
3561335841
return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
3561435842
"winFullPathname1", zRelative);
3561535843
}
35616
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s",
35617
- sqlite3_data_directory, winGetDirDep(), zOut);
35844
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35845
+ sqlite3_data_directory, winGetDirSep(), zOut);
3561835846
sqlite3_free(zOut);
3561935847
}else{
3562035848
if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){
3562135849
return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
3562235850
"winFullPathname2", zRelative);
@@ -35634,12 +35862,12 @@
3563435862
** NOTE: We are dealing with a relative path name and the data
3563535863
** directory has been set. Therefore, use it as the basis
3563635864
** for converting the relative path name to an absolute
3563735865
** one by prepending the data directory and a backslash.
3563835866
*/
35639
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s",
35640
- sqlite3_data_directory, winGetDirDep(), zRelative);
35867
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35868
+ sqlite3_data_directory, winGetDirSep(), zRelative);
3564135869
}else{
3564235870
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
3564335871
}
3564435872
return SQLITE_OK;
3564535873
#endif
@@ -35667,12 +35895,12 @@
3566735895
** NOTE: We are dealing with a relative path name and the data
3566835896
** directory has been set. Therefore, use it as the basis
3566935897
** for converting the relative path name to an absolute
3567035898
** one by prepending the data directory and a backslash.
3567135899
*/
35672
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s",
35673
- sqlite3_data_directory, winGetDirDep(), zRelative);
35900
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35901
+ sqlite3_data_directory, winGetDirSep(), zRelative);
3567435902
return SQLITE_OK;
3567535903
}
3567635904
zConverted = winConvertFromUtf8Filename(zRelative);
3567735905
if( zConverted==0 ){
3567835906
return SQLITE_IOERR_NOMEM;
@@ -36006,11 +36234,11 @@
3600636234
};
3600736235
#endif
3600836236
3600936237
/* Double-check that the aSyscall[] array has been constructed
3601036238
** correctly. See ticket [bb3a86e890c8e96ab] */
36011
- assert( ArraySize(aSyscall)==75 );
36239
+ assert( ArraySize(aSyscall)==76 );
3601236240
3601336241
/* get memory map allocation granularity */
3601436242
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
3601536243
#if SQLITE_OS_WINRT
3601636244
osGetNativeSystemInfo(&winSysInfo);
@@ -50676,11 +50904,11 @@
5067650904
int bias, /* Bias search to the high end */
5067750905
int *pRes /* Write search results here */
5067850906
){
5067950907
int rc; /* Status code */
5068050908
UnpackedRecord *pIdxKey; /* Unpacked index key */
50681
- char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
50909
+ char aSpace[200]; /* Temp space for pIdxKey - to avoid a malloc */
5068250910
char *pFree = 0;
5068350911
5068450912
if( pKey ){
5068550913
assert( nKey==(i64)(int)nKey );
5068650914
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
@@ -60294,19 +60522,19 @@
6029460522
6029560523
if( pRec==0 ){
6029660524
Index *pIdx = p->pIdx; /* Index being probed */
6029760525
int nByte; /* Bytes of space to allocate */
6029860526
int i; /* Counter variable */
60299
- int nCol = pIdx->nColumn+1; /* Number of index columns including rowid */
60527
+ int nCol = pIdx->nColumn; /* Number of index columns including rowid */
6030060528
6030160529
nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord);
6030260530
pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
6030360531
if( pRec ){
60304
- pRec->pKeyInfo = sqlite3IndexKeyinfo(p->pParse, pIdx);
60532
+ pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
6030560533
if( pRec->pKeyInfo ){
60306
- assert( pRec->pKeyInfo->nField+1==nCol );
60307
- pRec->pKeyInfo->enc = ENC(db);
60534
+ assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60535
+ assert( pRec->pKeyInfo->enc==ENC(db) );
6030860536
pRec->flags = UNPACKED_PREFIX_MATCH;
6030960537
pRec->aMem = (Mem *)&pRec[1];
6031060538
for(i=0; i<nCol; i++){
6031160539
pRec->aMem[i].flags = MEM_Null;
6031260540
pRec->aMem[i].type = SQLITE_NULL;
@@ -60625,17 +60853,17 @@
6062560853
** the object.
6062660854
*/
6062760855
SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){
6062860856
if( pRec ){
6062960857
int i;
60630
- int nCol = pRec->pKeyInfo->nField+1;
60858
+ int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
6063160859
Mem *aMem = pRec->aMem;
6063260860
sqlite3 *db = aMem[0].db;
6063360861
for(i=0; i<nCol; i++){
6063460862
sqlite3DbFree(db, aMem[i].zMalloc);
6063560863
}
60636
- sqlite3DbFree(db, pRec->pKeyInfo);
60864
+ sqlite3KeyInfoUnref(pRec->pKeyInfo);
6063760865
sqlite3DbFree(db, pRec);
6063860866
}
6063960867
}
6064060868
#endif /* ifdef SQLITE_ENABLE_STAT4 */
6064160869
@@ -60784,10 +61012,21 @@
6078461012
p->aOp = pNew;
6078561013
}
6078661014
return (pNew ? SQLITE_OK : SQLITE_NOMEM);
6078761015
}
6078861016
61017
+#ifdef SQLITE_DEBUG
61018
+/* This routine is just a convenient place to set a breakpoint that will
61019
+** fire after each opcode is inserted and displayed using
61020
+** "PRAGMA vdbe_addoptrace=on".
61021
+*/
61022
+static void test_addop_breakpoint(void){
61023
+ static int n = 0;
61024
+ n++;
61025
+}
61026
+#endif
61027
+
6078961028
/*
6079061029
** Add a new instruction to the list of instructions current in the
6079161030
** VDBE. Return the address of the new instruction.
6079261031
**
6079361032
** Parameters:
@@ -60821,14 +61060,17 @@
6082161060
pOp->p1 = p1;
6082261061
pOp->p2 = p2;
6082361062
pOp->p3 = p3;
6082461063
pOp->p4.p = 0;
6082561064
pOp->p4type = P4_NOTUSED;
60826
-#ifdef SQLITE_DEBUG
61065
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6082761066
pOp->zComment = 0;
61067
+#endif
61068
+#ifdef SQLITE_DEBUG
6082861069
if( p->db->flags & SQLITE_VdbeAddopTrace ){
6082961070
sqlite3VdbePrintOp(0, i, &p->aOp[i]);
61071
+ test_addop_breakpoint();
6083061072
}
6083161073
#endif
6083261074
#ifdef VDBE_PROFILE
6083361075
pOp->cycles = 0;
6083461076
pOp->cnt = 0;
@@ -61200,21 +61442,24 @@
6120061442
for(i=0; i<nOp; i++, pIn++){
6120161443
int p2 = pIn->p2;
6120261444
VdbeOp *pOut = &p->aOp[i+addr];
6120361445
pOut->opcode = pIn->opcode;
6120461446
pOut->p1 = pIn->p1;
61205
- if( p2<0 && (sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP)!=0 ){
61447
+ if( p2<0 ){
61448
+ assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
6120661449
pOut->p2 = addr + ADDR(p2);
6120761450
}else{
6120861451
pOut->p2 = p2;
6120961452
}
6121061453
pOut->p3 = pIn->p3;
6121161454
pOut->p4type = P4_NOTUSED;
6121261455
pOut->p4.p = 0;
6121361456
pOut->p5 = 0;
61214
-#ifdef SQLITE_DEBUG
61457
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6121561458
pOut->zComment = 0;
61459
+#endif
61460
+#ifdef SQLITE_DEBUG
6121661461
if( p->db->flags & SQLITE_VdbeAddopTrace ){
6121761462
sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
6121861463
}
6121961464
#endif
6122061465
}
@@ -61298,15 +61543,17 @@
6129861543
assert( db );
6129961544
switch( p4type ){
6130061545
case P4_REAL:
6130161546
case P4_INT64:
6130261547
case P4_DYNAMIC:
61303
- case P4_KEYINFO:
61304
- case P4_INTARRAY:
61305
- case P4_KEYINFO_HANDOFF: {
61548
+ case P4_INTARRAY: {
6130661549
sqlite3DbFree(db, p4);
6130761550
break;
61551
+ }
61552
+ case P4_KEYINFO: {
61553
+ if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
61554
+ break;
6130861555
}
6130961556
case P4_MPRINTF: {
6131061557
if( db->pnBytesFreed==0 ) sqlite3_free(p4);
6131161558
break;
6131261559
}
@@ -61340,11 +61587,11 @@
6134061587
static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
6134161588
if( aOp ){
6134261589
Op *pOp;
6134361590
for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
6134461591
freeP4(db, pOp->p4type, pOp->p4.p);
61345
-#ifdef SQLITE_DEBUG
61592
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6134661593
sqlite3DbFree(db, pOp->zComment);
6134761594
#endif
6134861595
}
6134961596
}
6135061597
sqlite3DbFree(db, aOp);
@@ -61368,10 +61615,11 @@
6136861615
VdbeOp *pOp = &p->aOp[addr];
6136961616
sqlite3 *db = p->db;
6137061617
freeP4(db, pOp->p4type, pOp->p4.p);
6137161618
memset(pOp, 0, sizeof(pOp[0]));
6137261619
pOp->opcode = OP_Noop;
61620
+ if( addr==p->nOp-1 ) p->nOp--;
6137361621
}
6137461622
}
6137561623
6137661624
/*
6137761625
** Change the value of the P4 operand for a specific instruction.
@@ -61381,18 +61629,10 @@
6138161629
**
6138261630
** If n>=0 then the P4 operand is dynamic, meaning that a copy of
6138361631
** the string is made into memory obtained from sqlite3_malloc().
6138461632
** A value of n==0 means copy bytes of zP4 up to and including the
6138561633
** first null byte. If n>0 then copy n+1 bytes of zP4.
61386
-**
61387
-** If n==P4_KEYINFO it means that zP4 is a pointer to a KeyInfo structure.
61388
-** A copy is made of the KeyInfo structure into memory obtained from
61389
-** sqlite3_malloc, to be freed when the Vdbe is finalized.
61390
-** n==P4_KEYINFO_HANDOFF indicates that zP4 points to a KeyInfo structure
61391
-** stored in memory that the caller has obtained from sqlite3_malloc. The
61392
-** caller should not free the allocation, it will be freed when the Vdbe is
61393
-** finalized.
6139461634
**
6139561635
** Other values of n (P4_STATIC, P4_COLLSEQ etc.) indicate that zP4 points
6139661636
** to a string or structure that is guaranteed to exist for the lifetime of
6139761637
** the Vdbe. In these cases we can just copy the pointer.
6139861638
**
@@ -61403,11 +61643,11 @@
6140361643
sqlite3 *db;
6140461644
assert( p!=0 );
6140561645
db = p->db;
6140661646
assert( p->magic==VDBE_MAGIC_INIT );
6140761647
if( p->aOp==0 || db->mallocFailed ){
61408
- if ( n!=P4_KEYINFO && n!=P4_VTAB ) {
61648
+ if( n!=P4_VTAB ){
6140961649
freeP4(db, n, (void*)*(char**)&zP4);
6141061650
}
6141161651
return;
6141261652
}
6141361653
assert( p->nOp>0 );
@@ -61426,23 +61666,10 @@
6142661666
pOp->p4type = P4_INT32;
6142761667
}else if( zP4==0 ){
6142861668
pOp->p4.p = 0;
6142961669
pOp->p4type = P4_NOTUSED;
6143061670
}else if( n==P4_KEYINFO ){
61431
- KeyInfo *pOrig, *pNew;
61432
-
61433
- pOrig = (KeyInfo*)zP4;
61434
- pOp->p4.pKeyInfo = pNew = sqlite3KeyInfoAlloc(db, pOrig->nField);
61435
- if( pNew ){
61436
- memcpy(pNew->aColl, pOrig->aColl, pOrig->nField*sizeof(pNew->aColl[0]));
61437
- memcpy(pNew->aSortOrder, pOrig->aSortOrder, pOrig->nField);
61438
- pOp->p4type = P4_KEYINFO;
61439
- }else{
61440
- p->db->mallocFailed = 1;
61441
- pOp->p4type = P4_NOTUSED;
61442
- }
61443
- }else if( n==P4_KEYINFO_HANDOFF ){
6144461671
pOp->p4.p = (void*)zP4;
6144561672
pOp->p4type = P4_KEYINFO;
6144661673
}else if( n==P4_VTAB ){
6144761674
pOp->p4.p = (void*)zP4;
6144861675
pOp->p4type = P4_VTAB;
@@ -61456,11 +61683,23 @@
6145661683
pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
6145761684
pOp->p4type = P4_DYNAMIC;
6145861685
}
6145961686
}
6146061687
61461
-#ifndef NDEBUG
61688
+/*
61689
+** Set the P4 on the most recently added opcode to the KeyInfo for the
61690
+** index given.
61691
+*/
61692
+SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
61693
+ Vdbe *v = pParse->pVdbe;
61694
+ assert( v!=0 );
61695
+ assert( pIdx!=0 );
61696
+ sqlite3VdbeChangeP4(v, -1, (char*)sqlite3KeyInfoOfIndex(pParse, pIdx),
61697
+ P4_KEYINFO);
61698
+}
61699
+
61700
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6146261701
/*
6146361702
** Change the comment on the most recently coded instruction. Or
6146461703
** insert a No-op and add the comment to that new instruction. This
6146561704
** makes the code easier to read during debugging. None of this happens
6146661705
** in a production build.
@@ -61530,10 +61769,85 @@
6153061769
return (VdbeOp*)&dummy;
6153161770
}else{
6153261771
return &p->aOp[addr];
6153361772
}
6153461773
}
61774
+
61775
+#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
61776
+/*
61777
+** Return an integer value for one of the parameters to the opcode pOp
61778
+** determined by character c.
61779
+*/
61780
+static int translateP(char c, const Op *pOp){
61781
+ if( c=='1' ) return pOp->p1;
61782
+ if( c=='2' ) return pOp->p2;
61783
+ if( c=='3' ) return pOp->p3;
61784
+ if( c=='4' ) return pOp->p4.i;
61785
+ return pOp->p5;
61786
+}
61787
+
61788
+/*
61789
+** Compute a string for the "comment" field of a VDBE opcode listing
61790
+*/
61791
+static int displayComment(
61792
+ const Op *pOp, /* The opcode to be commented */
61793
+ const char *zP4, /* Previously obtained value for P4 */
61794
+ char *zTemp, /* Write result here */
61795
+ int nTemp /* Space available in zTemp[] */
61796
+){
61797
+ const char *zOpName;
61798
+ const char *zSynopsis;
61799
+ int nOpName;
61800
+ int ii, jj;
61801
+ zOpName = sqlite3OpcodeName(pOp->opcode);
61802
+ nOpName = sqlite3Strlen30(zOpName);
61803
+ if( zOpName[nOpName+1] ){
61804
+ int seenCom = 0;
61805
+ char c;
61806
+ zSynopsis = zOpName += nOpName + 1;
61807
+ for(ii=jj=0; jj<nTemp-1 && (c = zSynopsis[ii])!=0; ii++){
61808
+ if( c=='P' ){
61809
+ c = zSynopsis[++ii];
61810
+ if( c=='4' ){
61811
+ sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zP4);
61812
+ }else if( c=='X' ){
61813
+ sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", pOp->zComment);
61814
+ seenCom = 1;
61815
+ }else{
61816
+ int v1 = translateP(c, pOp);
61817
+ int v2;
61818
+ sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
61819
+ if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
61820
+ ii += 3;
61821
+ jj += sqlite3Strlen30(zTemp+jj);
61822
+ v2 = translateP(zSynopsis[ii], pOp);
61823
+ if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
61824
+ }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
61825
+ ii += 4;
61826
+ }
61827
+ }
61828
+ jj += sqlite3Strlen30(zTemp+jj);
61829
+ }else{
61830
+ zTemp[jj++] = c;
61831
+ }
61832
+ }
61833
+ if( !seenCom && jj<nTemp-5 && pOp->zComment ){
61834
+ sqlite3_snprintf(nTemp-jj, zTemp+jj, "; %s", pOp->zComment);
61835
+ jj += sqlite3Strlen30(zTemp+jj);
61836
+ }
61837
+ if( jj<nTemp ) zTemp[jj] = 0;
61838
+ }else if( pOp->zComment ){
61839
+ sqlite3_snprintf(nTemp, zTemp, "%s", pOp->zComment);
61840
+ jj = sqlite3Strlen30(zTemp);
61841
+ }else{
61842
+ zTemp[0] = 0;
61843
+ jj = 0;
61844
+ }
61845
+ return jj;
61846
+}
61847
+#endif /* SQLITE_DEBUG */
61848
+
6153561849
6153661850
#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \
6153761851
|| defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
6153861852
/*
6153961853
** Compute a string that describes the P4 parameter for an opcode.
@@ -61541,21 +61855,24 @@
6154161855
*/
6154261856
static char *displayP4(Op *pOp, char *zTemp, int nTemp){
6154361857
char *zP4 = zTemp;
6154461858
assert( nTemp>=20 );
6154561859
switch( pOp->p4type ){
61546
- case P4_KEYINFO_STATIC:
6154761860
case P4_KEYINFO: {
6154861861
int i, j;
6154961862
KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
6155061863
assert( pKeyInfo->aSortOrder!=0 );
61551
- sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
61864
+ sqlite3_snprintf(nTemp, zTemp, "k(%d", pKeyInfo->nField);
6155261865
i = sqlite3Strlen30(zTemp);
6155361866
for(j=0; j<pKeyInfo->nField; j++){
6155461867
CollSeq *pColl = pKeyInfo->aColl[j];
6155561868
const char *zColl = pColl ? pColl->zName : "nil";
6155661869
int n = sqlite3Strlen30(zColl);
61870
+ if( n==6 && memcmp(zColl,"BINARY",6)==0 ){
61871
+ zColl = "B";
61872
+ n = 1;
61873
+ }
6155761874
if( i+n>nTemp-6 ){
6155861875
memcpy(&zTemp[i],",...",4);
6155961876
break;
6156061877
}
6156161878
zTemp[i++] = ',';
@@ -61724,20 +62041,22 @@
6172462041
** Print a single opcode. This routine is used for debugging only.
6172562042
*/
6172662043
SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
6172762044
char *zP4;
6172862045
char zPtr[50];
61729
- static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-4s %.2X %s\n";
62046
+ char zCom[100];
62047
+ static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-13s %.2X %s\n";
6173062048
if( pOut==0 ) pOut = stdout;
6173162049
zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
62050
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62051
+ displayComment(pOp, zP4, zCom, sizeof(zCom));
62052
+#else
62053
+ zCom[0] = 0
62054
+#endif
6173262055
fprintf(pOut, zFormat1, pc,
6173362056
sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
61734
-#ifdef SQLITE_DEBUG
61735
- pOp->zComment ? pOp->zComment : ""
61736
-#else
61737
- ""
61738
-#endif
62057
+ zCom
6173962058
);
6174062059
fflush(pOut);
6174162060
}
6174262061
#endif
6174362062
@@ -61879,11 +62198,11 @@
6187962198
}else if( db->u1.isInterrupted ){
6188062199
p->rc = SQLITE_INTERRUPT;
6188162200
rc = SQLITE_ERROR;
6188262201
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
6188362202
}else{
61884
- char *z;
62203
+ char *zP4;
6188562204
Op *pOp;
6188662205
if( i<p->nOp ){
6188762206
/* The output line number is small enough that we are still in the
6188862207
** main program. */
6188962208
pOp = &p->aOp[i];
@@ -61902,11 +62221,11 @@
6190262221
pMem->type = SQLITE_INTEGER;
6190362222
pMem->u.i = i; /* Program counter */
6190462223
pMem++;
6190562224
6190662225
pMem->flags = MEM_Static|MEM_Str|MEM_Term;
61907
- pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
62226
+ pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
6190862227
assert( pMem->z!=0 );
6190962228
pMem->n = sqlite3Strlen30(pMem->z);
6191062229
pMem->type = SQLITE_TEXT;
6191162230
pMem->enc = SQLITE_UTF8;
6191262231
pMem++;
@@ -61949,13 +62268,13 @@
6194962268
if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
6195062269
assert( p->db->mallocFailed );
6195162270
return SQLITE_ERROR;
6195262271
}
6195362272
pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
61954
- z = displayP4(pOp, pMem->z, 32);
61955
- if( z!=pMem->z ){
61956
- sqlite3VdbeMemSetStr(pMem, z, -1, SQLITE_UTF8, 0);
62273
+ zP4 = displayP4(pOp, pMem->z, 32);
62274
+ if( zP4!=pMem->z ){
62275
+ sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
6195762276
}else{
6195862277
assert( pMem->z!=0 );
6195962278
pMem->n = sqlite3Strlen30(pMem->z);
6196062279
pMem->enc = SQLITE_UTF8;
6196162280
}
@@ -61972,23 +62291,23 @@
6197262291
sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
6197362292
pMem->type = SQLITE_TEXT;
6197462293
pMem->enc = SQLITE_UTF8;
6197562294
pMem++;
6197662295
61977
-#ifdef SQLITE_DEBUG
61978
- if( pOp->zComment ){
61979
- pMem->flags = MEM_Str|MEM_Term;
61980
- pMem->z = pOp->zComment;
61981
- pMem->n = sqlite3Strlen30(pMem->z);
61982
- pMem->enc = SQLITE_UTF8;
61983
- pMem->type = SQLITE_TEXT;
61984
- }else
62296
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62297
+ if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
62298
+ assert( p->db->mallocFailed );
62299
+ return SQLITE_ERROR;
62300
+ }
62301
+ pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62302
+ pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62303
+ pMem->type = SQLITE_TEXT;
62304
+ pMem->enc = SQLITE_UTF8;
62305
+#else
62306
+ pMem->flags = MEM_Null; /* Comment */
62307
+ pMem->type = SQLITE_NULL;
6198562308
#endif
61986
- {
61987
- pMem->flags = MEM_Null; /* Comment */
61988
- pMem->type = SQLITE_NULL;
61989
- }
6199062309
}
6199162310
6199262311
p->nResColumn = 8 - 4*(p->explain-1);
6199362312
p->pResultSet = &p->aMem[1];
6199462313
p->rc = SQLITE_OK;
@@ -62775,11 +63094,11 @@
6277563094
if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
6277663095
|| (!deferred && p->nFkConstraint>0)
6277763096
){
6277863097
p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
6277963098
p->errorAction = OE_Abort;
62780
- sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
63099
+ sqlite3SetString(&p->zErrMsg, db, "FOREIGN KEY constraint failed");
6278163100
return SQLITE_ERROR;
6278263101
}
6278363102
return SQLITE_OK;
6278463103
}
6278563104
#endif
@@ -63706,11 +64025,11 @@
6370664025
*/
6370764026
/* mem1.u.i = 0; // not needed, here to silence compiler warning */
6370864027
6370964028
idx1 = getVarint32(aKey1, szHdr1);
6371064029
d1 = szHdr1;
63711
- assert( pKeyInfo->nField+1>=pPKey2->nField );
64030
+ assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField );
6371264031
assert( pKeyInfo->aSortOrder!=0 );
6371364032
while( idx1<szHdr1 && i<pPKey2->nField ){
6371464033
u32 serial_type1;
6371564034
6371664035
/* Read the serial types for the next element in each key. */
@@ -63735,28 +64054,13 @@
6373564054
/* Do the comparison
6373664055
*/
6373764056
rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
6373864057
if( rc!=0 ){
6373964058
assert( mem1.zMalloc==0 ); /* See comment below */
63740
-
63741
- /* Invert the result if we are using DESC sort order. */
6374264059
if( pKeyInfo->aSortOrder[i] ){
63743
- rc = -rc;
63744
- }
63745
-
63746
- /* If the PREFIX_SEARCH flag is set and all fields except the final
63747
- ** rowid field were equal, then clear the PREFIX_SEARCH flag and set
63748
- ** pPKey2->rowid to the value of the rowid field in (pKey1, nKey1).
63749
- ** This is used by the OP_IsUnique opcode.
63750
- */
63751
- if( (pPKey2->flags & UNPACKED_PREFIX_SEARCH) && i==(pPKey2->nField-1) ){
63752
- assert( idx1==szHdr1 && rc );
63753
- assert( mem1.flags & MEM_Int );
63754
- pPKey2->flags &= ~UNPACKED_PREFIX_SEARCH;
63755
- pPKey2->rowid = mem1.u.i;
63756
- }
63757
-
64060
+ rc = -rc; /* Invert the result for DESC sort order. */
64061
+ }
6375864062
return rc;
6375964063
}
6376064064
i++;
6376164065
}
6376264066
@@ -66271,77 +66575,81 @@
6627166575
*/
6627266576
union vdbeExecUnion {
6627366577
struct OP_Yield_stack_vars {
6627466578
int pcDest;
6627566579
} aa;
66580
+ struct OP_Halt_stack_vars {
66581
+ const char *zType;
66582
+ const char *zLogFmt;
66583
+ } ab;
6627666584
struct OP_Null_stack_vars {
6627766585
int cnt;
6627866586
u16 nullFlag;
66279
- } ab;
66587
+ } ac;
6628066588
struct OP_Variable_stack_vars {
6628166589
Mem *pVar; /* Value being transferred */
66282
- } ac;
66590
+ } ad;
6628366591
struct OP_Move_stack_vars {
6628466592
char *zMalloc; /* Holding variable for allocated memory */
6628566593
int n; /* Number of registers left to copy */
6628666594
int p1; /* Register to copy from */
6628766595
int p2; /* Register to copy to */
66288
- } ad;
66596
+ } ae;
6628966597
struct OP_Copy_stack_vars {
6629066598
int n;
66291
- } ae;
66599
+ } af;
6629266600
struct OP_ResultRow_stack_vars {
6629366601
Mem *pMem;
6629466602
int i;
66295
- } af;
66603
+ } ag;
6629666604
struct OP_Concat_stack_vars {
6629766605
i64 nByte;
66298
- } ag;
66606
+ } ah;
6629966607
struct OP_Remainder_stack_vars {
6630066608
char bIntint; /* Started out as two integer operands */
6630166609
int flags; /* Combined MEM_* flags from both inputs */
6630266610
i64 iA; /* Integer value of left operand */
6630366611
i64 iB; /* Integer value of right operand */
6630466612
double rA; /* Real value of left operand */
6630566613
double rB; /* Real value of right operand */
66306
- } ah;
66614
+ } ai;
6630766615
struct OP_Function_stack_vars {
6630866616
int i;
6630966617
Mem *pArg;
6631066618
sqlite3_context ctx;
6631166619
sqlite3_value **apVal;
6631266620
int n;
66313
- } ai;
66621
+ } aj;
6631466622
struct OP_ShiftRight_stack_vars {
6631566623
i64 iA;
6631666624
u64 uA;
6631766625
i64 iB;
6631866626
u8 op;
66319
- } aj;
66627
+ } ak;
6632066628
struct OP_Ge_stack_vars {
6632166629
int res; /* Result of the comparison of pIn1 against pIn3 */
6632266630
char affinity; /* Affinity to use for comparison */
6632366631
u16 flags1; /* Copy of initial value of pIn1->flags */
6632466632
u16 flags3; /* Copy of initial value of pIn3->flags */
66325
- } ak;
66633
+ } al;
6632666634
struct OP_Compare_stack_vars {
6632766635
int n;
6632866636
int i;
6632966637
int p1;
6633066638
int p2;
6633166639
const KeyInfo *pKeyInfo;
6633266640
int idx;
6633366641
CollSeq *pColl; /* Collating sequence to use on this term */
6633466642
int bRev; /* True for DESCENDING sort order */
66335
- } al;
66643
+ } am;
6633666644
struct OP_Or_stack_vars {
6633766645
int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
6633866646
int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66339
- } am;
66647
+ } an;
6634066648
struct OP_IfNot_stack_vars {
6634166649
int c;
66342
- } an;
66650
+ } ao;
6634366651
struct OP_Column_stack_vars {
6634466652
u32 payloadSize; /* Number of bytes in the record */
6634566653
i64 payloadSize64; /* Number of bytes in the record */
6634666654
int p1; /* P1 value of the opcode */
6634766655
int p2; /* column number to retrieve */
@@ -66362,15 +66670,15 @@
6636266670
u32 szField; /* Number of bytes in the content of a field */
6636366671
int szHdr; /* Size of the header size field at start of record */
6636466672
int avail; /* Number of bytes of available data */
6636566673
u32 t; /* A type code from the record header */
6636666674
Mem *pReg; /* PseudoTable input register */
66367
- } ao;
66675
+ } ap;
6636866676
struct OP_Affinity_stack_vars {
6636966677
const char *zAffinity; /* The affinity to be applied */
6637066678
char cAff; /* A single character of affinity */
66371
- } ap;
66679
+ } aq;
6637266680
struct OP_MakeRecord_stack_vars {
6637366681
u8 *zNewRecord; /* A buffer to hold the data for the new record */
6637466682
Mem *pRec; /* The new record */
6637566683
u64 nData; /* Number of bytes of data space */
6637666684
int nHdr; /* Number of bytes of header space */
@@ -66383,93 +66691,86 @@
6638366691
int nField; /* Number of fields in the record */
6638466692
char *zAffinity; /* The affinity string for the record */
6638566693
int file_format; /* File format to use for encoding */
6638666694
int i; /* Space used in zNewRecord[] */
6638766695
int len; /* Length of a field */
66388
- } aq;
66696
+ } ar;
6638966697
struct OP_Count_stack_vars {
6639066698
i64 nEntry;
6639166699
BtCursor *pCrsr;
66392
- } ar;
66700
+ } as;
6639366701
struct OP_Savepoint_stack_vars {
6639466702
int p1; /* Value of P1 operand */
6639566703
char *zName; /* Name of savepoint */
6639666704
int nName;
6639766705
Savepoint *pNew;
6639866706
Savepoint *pSavepoint;
6639966707
Savepoint *pTmp;
6640066708
int iSavepoint;
6640166709
int ii;
66402
- } as;
66710
+ } at;
6640366711
struct OP_AutoCommit_stack_vars {
6640466712
int desiredAutoCommit;
6640566713
int iRollback;
6640666714
int turnOnAC;
66407
- } at;
66715
+ } au;
6640866716
struct OP_Transaction_stack_vars {
6640966717
Btree *pBt;
66410
- } au;
66718
+ } av;
6641166719
struct OP_ReadCookie_stack_vars {
6641266720
int iMeta;
6641366721
int iDb;
6641466722
int iCookie;
66415
- } av;
66723
+ } aw;
6641666724
struct OP_SetCookie_stack_vars {
6641766725
Db *pDb;
66418
- } aw;
66726
+ } ax;
6641966727
struct OP_VerifyCookie_stack_vars {
6642066728
int iMeta;
6642166729
int iGen;
6642266730
Btree *pBt;
66423
- } ax;
66731
+ } ay;
6642466732
struct OP_OpenWrite_stack_vars {
6642566733
int nField;
6642666734
KeyInfo *pKeyInfo;
6642766735
int p2;
6642866736
int iDb;
6642966737
int wrFlag;
6643066738
Btree *pX;
6643166739
VdbeCursor *pCur;
6643266740
Db *pDb;
66433
- } ay;
66741
+ } az;
6643466742
struct OP_OpenEphemeral_stack_vars {
6643566743
VdbeCursor *pCx;
66436
- } az;
66744
+ KeyInfo *pKeyInfo;
66745
+ } ba;
6643766746
struct OP_SorterOpen_stack_vars {
6643866747
VdbeCursor *pCx;
66439
- } ba;
66748
+ } bb;
6644066749
struct OP_OpenPseudo_stack_vars {
6644166750
VdbeCursor *pCx;
66442
- } bb;
66751
+ } bc;
6644366752
struct OP_SeekGt_stack_vars {
6644466753
int res;
6644566754
int oc;
6644666755
VdbeCursor *pC;
6644766756
UnpackedRecord r;
6644866757
int nField;
6644966758
i64 iKey; /* The rowid we are to seek to */
66450
- } bc;
66759
+ } bd;
6645166760
struct OP_Seek_stack_vars {
6645266761
VdbeCursor *pC;
66453
- } bd;
66762
+ } be;
6645466763
struct OP_Found_stack_vars {
6645566764
int alreadyExists;
66765
+ int ii;
6645666766
VdbeCursor *pC;
6645766767
int res;
6645866768
char *pFree;
6645966769
UnpackedRecord *pIdxKey;
6646066770
UnpackedRecord r;
66461
- char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*3 + 7];
66462
- } be;
66463
- struct OP_IsUnique_stack_vars {
66464
- u16 ii;
66465
- VdbeCursor *pCx;
66466
- BtCursor *pCrsr;
66467
- u16 nField;
66468
- Mem *aMx;
66469
- UnpackedRecord r; /* B-Tree index search key */
66470
- i64 R; /* Rowid stored in register P3 */
66771
+ char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
6647166772
} bf;
6647266773
struct OP_NotExists_stack_vars {
6647366774
VdbeCursor *pC;
6647466775
BtCursor *pCrsr;
6647566776
int res;
@@ -66499,10 +66800,11 @@
6649966800
VdbeCursor *pC;
6650066801
} bj;
6650166802
struct OP_SorterCompare_stack_vars {
6650266803
VdbeCursor *pC;
6650366804
int res;
66805
+ int nIgnore;
6650466806
} bk;
6650566807
struct OP_SorterData_stack_vars {
6650666808
VdbeCursor *pC;
6650766809
} bl;
6650866810
struct OP_RowData_stack_vars {
@@ -66939,23 +67241,25 @@
6693967241
REGISTER_TRACE(pOp->p1, pIn1);
6694067242
pc = u.aa.pcDest;
6694167243
break;
6694267244
}
6694367245
66944
-/* Opcode: HaltIfNull P1 P2 P3 P4 *
67246
+/* Opcode: HaltIfNull P1 P2 P3 P4 P5
67247
+** Synopsis: if r[P3] null then halt
6694567248
**
6694667249
** Check the value in register P3. If it is NULL then Halt using
6694767250
** parameter P1, P2, and P4 as if this were a Halt instruction. If the
6694867251
** value in register P3 is not NULL, then this routine is a no-op.
67252
+** The P5 parameter should be 1.
6694967253
*/
6695067254
case OP_HaltIfNull: { /* in3 */
6695167255
pIn3 = &aMem[pOp->p3];
6695267256
if( (pIn3->flags & MEM_Null)==0 ) break;
6695367257
/* Fall through into OP_Halt */
6695467258
}
6695567259
66956
-/* Opcode: Halt P1 P2 * P4 *
67260
+/* Opcode: Halt P1 P2 * P4 P5
6695767261
**
6695867262
** Exit immediately. All open cursors, etc are closed
6695967263
** automatically.
6696067264
**
6696167265
** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
@@ -66965,26 +67269,42 @@
6696567269
** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
6696667270
** then back out all changes that have occurred during this execution of the
6696767271
** VDBE, but do not rollback the transaction.
6696867272
**
6696967273
** If P4 is not null then it is an error message string.
67274
+**
67275
+** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
67276
+**
67277
+** 0: (no change)
67278
+** 1: NOT NULL contraint failed: P4
67279
+** 2: UNIQUE constraint failed: P4
67280
+** 3: CHECK constraint failed: P4
67281
+** 4: FOREIGN KEY constraint failed: P4
67282
+**
67283
+** If P5 is not zero and P4 is NULL, then everything after the ":" is
67284
+** omitted.
6697067285
**
6697167286
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
6697267287
** every program. So a jump past the last instruction of the program
6697367288
** is the same as executing Halt.
6697467289
*/
6697567290
case OP_Halt: {
67291
+#if 0 /* local variables moved into u.ab */
67292
+ const char *zType;
67293
+ const char *zLogFmt;
67294
+#endif /* local variables moved into u.ab */
67295
+
6697667296
if( pOp->p1==SQLITE_OK && p->pFrame ){
6697767297
/* Halt the sub-program. Return control to the parent frame. */
6697867298
VdbeFrame *pFrame = p->pFrame;
6697967299
p->pFrame = pFrame->pParent;
6698067300
p->nFrame--;
6698167301
sqlite3VdbeSetChanges(db, p->nChange);
6698267302
pc = sqlite3VdbeFrameRestore(pFrame);
6698367303
lastRowid = db->lastRowid;
6698467304
if( pOp->p2==OE_Ignore ){
66985
- /* Instruction pc is the OP_Program that invoked the sub-program
67305
+ /* Instruction pc is the OP_Program that invoked the sub-program
6698667306
** currently being halted. If the p2 instruction of this OP_Halt
6698767307
** instruction is set to OE_Ignore, then the sub-program is throwing
6698867308
** an IGNORE exception. In this case jump to the address specified
6698967309
** as the p2 of the calling OP_Program. */
6699067310
pc = p->aOp[pc].p2-1;
@@ -66991,22 +67311,37 @@
6699167311
}
6699267312
aOp = p->aOp;
6699367313
aMem = p->aMem;
6699467314
break;
6699567315
}
66996
-
6699767316
p->rc = pOp->p1;
6699867317
p->errorAction = (u8)pOp->p2;
6699967318
p->pc = pc;
67000
- if( pOp->p4.z ){
67001
- assert( p->rc!=SQLITE_OK );
67002
- sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67003
- testcase( sqlite3GlobalConfig.xLog!=0 );
67004
- sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pc, p->zSql, pOp->p4.z);
67005
- }else if( p->rc ){
67006
- testcase( sqlite3GlobalConfig.xLog!=0 );
67007
- sqlite3_log(pOp->p1, "constraint failed at %d in [%s]", pc, p->zSql);
67319
+ if( p->rc ){
67320
+ if( pOp->p5 ){
67321
+ static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
67322
+ "FOREIGN KEY" };
67323
+ assert( pOp->p5>=1 && pOp->p5<=4 );
67324
+ testcase( pOp->p5==1 );
67325
+ testcase( pOp->p5==2 );
67326
+ testcase( pOp->p5==3 );
67327
+ testcase( pOp->p5==4 );
67328
+ u.ab.zType = azType[pOp->p5-1];
67329
+ }else{
67330
+ u.ab.zType = 0;
67331
+ }
67332
+ assert( u.ab.zType!=0 || pOp->p4.z!=0 );
67333
+ u.ab.zLogFmt = "abort at %d in [%s]: %s";
67334
+ if( u.ab.zType && pOp->p4.z ){
67335
+ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67336
+ u.ab.zType, pOp->p4.z);
67337
+ }else if( pOp->p4.z ){
67338
+ sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67339
+ }else{
67340
+ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
67341
+ }
67342
+ sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
6700867343
}
6700967344
rc = sqlite3VdbeHalt(p);
6701067345
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
6701167346
if( rc==SQLITE_BUSY ){
6701267347
p->rc = rc = SQLITE_BUSY;
@@ -67017,19 +67352,21 @@
6701767352
}
6701867353
goto vdbe_return;
6701967354
}
6702067355
6702167356
/* Opcode: Integer P1 P2 * * *
67357
+** Synopsis: r[P2]=P1
6702267358
**
6702367359
** The 32-bit integer value P1 is written into register P2.
6702467360
*/
6702567361
case OP_Integer: { /* out2-prerelease */
6702667362
pOut->u.i = pOp->p1;
6702767363
break;
6702867364
}
6702967365
6703067366
/* Opcode: Int64 * P2 * P4 *
67367
+** Synopsis: r[P2]=P4
6703167368
**
6703267369
** P4 is a pointer to a 64-bit integer value.
6703367370
** Write that value into register P2.
6703467371
*/
6703567372
case OP_Int64: { /* out2-prerelease */
@@ -67038,10 +67375,11 @@
6703867375
break;
6703967376
}
6704067377
6704167378
#ifndef SQLITE_OMIT_FLOATING_POINT
6704267379
/* Opcode: Real * P2 * P4 *
67380
+** Synopsis: r[P2]=P4
6704367381
**
6704467382
** P4 is a pointer to a 64-bit floating point value.
6704567383
** Write that value into register P2.
6704667384
*/
6704767385
case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
@@ -67051,10 +67389,11 @@
6705167389
break;
6705267390
}
6705367391
#endif
6705467392
6705567393
/* Opcode: String8 * P2 * P4 *
67394
+** Synopsis: r[P2]='P4'
6705667395
**
6705767396
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
6705867397
** into an OP_String before it is executed for the first time.
6705967398
*/
6706067399
case OP_String8: { /* same as TK_STRING, out2-prerelease */
@@ -67085,10 +67424,11 @@
6708567424
}
6708667425
/* Fall through to the next case, OP_String */
6708767426
}
6708867427
6708967428
/* Opcode: String P1 P2 * P4 *
67429
+** Synopsis: r[P2]='P4' (len=P1)
6709067430
**
6709167431
** The string value P4 of length P1 (bytes) is stored in register P2.
6709267432
*/
6709367433
case OP_String: { /* out2-prerelease */
6709467434
assert( pOp->p4.z!=0 );
@@ -67099,10 +67439,11 @@
6709967439
UPDATE_MAX_BLOBSIZE(pOut);
6710067440
break;
6710167441
}
6710267442
6710367443
/* Opcode: Null P1 P2 P3 * *
67444
+** Synopsis: r[P2..P3]=NULL
6710467445
**
6710567446
** Write a NULL into registers P2. If P3 greater than P2, then also write
6710667447
** NULL into register P3 and every register in between P2 and P3. If P3
6710767448
** is less than P2 (typically P3 is zero) then only register P2 is
6710867449
** set to NULL.
@@ -67110,29 +67451,30 @@
6711067451
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
6711167452
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
6711267453
** OP_Ne or OP_Eq.
6711367454
*/
6711467455
case OP_Null: { /* out2-prerelease */
67115
-#if 0 /* local variables moved into u.ab */
67456
+#if 0 /* local variables moved into u.ac */
6711667457
int cnt;
6711767458
u16 nullFlag;
67118
-#endif /* local variables moved into u.ab */
67119
- u.ab.cnt = pOp->p3-pOp->p2;
67459
+#endif /* local variables moved into u.ac */
67460
+ u.ac.cnt = pOp->p3-pOp->p2;
6712067461
assert( pOp->p3<=(p->nMem-p->nCursor) );
67121
- pOut->flags = u.ab.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67122
- while( u.ab.cnt>0 ){
67462
+ pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67463
+ while( u.ac.cnt>0 ){
6712367464
pOut++;
6712467465
memAboutToChange(p, pOut);
6712567466
VdbeMemRelease(pOut);
67126
- pOut->flags = u.ab.nullFlag;
67127
- u.ab.cnt--;
67467
+ pOut->flags = u.ac.nullFlag;
67468
+ u.ac.cnt--;
6712867469
}
6712967470
break;
6713067471
}
6713167472
6713267473
6713367474
/* Opcode: Blob P1 P2 * P4
67475
+** Synopsis: r[P2]=P4 (len=P1)
6713467476
**
6713567477
** P4 points to a blob of data P1 bytes long. Store this
6713667478
** blob in register P2.
6713767479
*/
6713867480
case OP_Blob: { /* out2-prerelease */
@@ -67142,107 +67484,111 @@
6714267484
UPDATE_MAX_BLOBSIZE(pOut);
6714367485
break;
6714467486
}
6714567487
6714667488
/* Opcode: Variable P1 P2 * P4 *
67489
+** Synopsis: r[P2]=parameter(P1,P4)
6714767490
**
6714867491
** Transfer the values of bound parameter P1 into register P2
6714967492
**
6715067493
** If the parameter is named, then its name appears in P4 and P3==1.
6715167494
** The P4 value is used by sqlite3_bind_parameter_name().
6715267495
*/
6715367496
case OP_Variable: { /* out2-prerelease */
67154
-#if 0 /* local variables moved into u.ac */
67497
+#if 0 /* local variables moved into u.ad */
6715567498
Mem *pVar; /* Value being transferred */
67156
-#endif /* local variables moved into u.ac */
67499
+#endif /* local variables moved into u.ad */
6715767500
6715867501
assert( pOp->p1>0 && pOp->p1<=p->nVar );
6715967502
assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67160
- u.ac.pVar = &p->aVar[pOp->p1 - 1];
67161
- if( sqlite3VdbeMemTooBig(u.ac.pVar) ){
67503
+ u.ad.pVar = &p->aVar[pOp->p1 - 1];
67504
+ if( sqlite3VdbeMemTooBig(u.ad.pVar) ){
6716267505
goto too_big;
6716367506
}
67164
- sqlite3VdbeMemShallowCopy(pOut, u.ac.pVar, MEM_Static);
67507
+ sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
6716567508
UPDATE_MAX_BLOBSIZE(pOut);
6716667509
break;
6716767510
}
6716867511
6716967512
/* Opcode: Move P1 P2 P3 * *
67513
+** Synopsis: r[P2@P3]=r[P1@P3]
6717067514
**
6717167515
** Move the values in register P1..P1+P3 over into
6717267516
** registers P2..P2+P3. Registers P1..P1+P3 are
6717367517
** left holding a NULL. It is an error for register ranges
6717467518
** P1..P1+P3 and P2..P2+P3 to overlap.
6717567519
*/
6717667520
case OP_Move: {
67177
-#if 0 /* local variables moved into u.ad */
67521
+#if 0 /* local variables moved into u.ae */
6717867522
char *zMalloc; /* Holding variable for allocated memory */
6717967523
int n; /* Number of registers left to copy */
6718067524
int p1; /* Register to copy from */
6718167525
int p2; /* Register to copy to */
67182
-#endif /* local variables moved into u.ad */
67183
-
67184
- u.ad.n = pOp->p3 + 1;
67185
- u.ad.p1 = pOp->p1;
67186
- u.ad.p2 = pOp->p2;
67187
- assert( u.ad.n>0 && u.ad.p1>0 && u.ad.p2>0 );
67188
- assert( u.ad.p1+u.ad.n<=u.ad.p2 || u.ad.p2+u.ad.n<=u.ad.p1 );
67189
-
67190
- pIn1 = &aMem[u.ad.p1];
67191
- pOut = &aMem[u.ad.p2];
67192
- while( u.ad.n-- ){
67526
+#endif /* local variables moved into u.ae */
67527
+
67528
+ u.ae.n = pOp->p3 + 1;
67529
+ u.ae.p1 = pOp->p1;
67530
+ u.ae.p2 = pOp->p2;
67531
+ assert( u.ae.n>0 && u.ae.p1>0 && u.ae.p2>0 );
67532
+ assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67533
+
67534
+ pIn1 = &aMem[u.ae.p1];
67535
+ pOut = &aMem[u.ae.p2];
67536
+ while( u.ae.n-- ){
6719367537
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6719467538
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6719567539
assert( memIsValid(pIn1) );
6719667540
memAboutToChange(p, pOut);
67197
- u.ad.zMalloc = pOut->zMalloc;
67541
+ u.ae.zMalloc = pOut->zMalloc;
6719867542
pOut->zMalloc = 0;
6719967543
sqlite3VdbeMemMove(pOut, pIn1);
6720067544
#ifdef SQLITE_DEBUG
67201
- if( pOut->pScopyFrom>=&aMem[u.ad.p1] && pOut->pScopyFrom<&aMem[u.ad.p1+pOp->p3] ){
67202
- pOut->pScopyFrom += u.ad.p1 - pOp->p2;
67545
+ if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){
67546
+ pOut->pScopyFrom += u.ae.p1 - pOp->p2;
6720367547
}
6720467548
#endif
67205
- pIn1->zMalloc = u.ad.zMalloc;
67206
- REGISTER_TRACE(u.ad.p2++, pOut);
67549
+ pIn1->zMalloc = u.ae.zMalloc;
67550
+ REGISTER_TRACE(u.ae.p2++, pOut);
6720767551
pIn1++;
6720867552
pOut++;
6720967553
}
6721067554
break;
6721167555
}
6721267556
6721367557
/* Opcode: Copy P1 P2 P3 * *
67558
+** Synopsis: r[P2@P3]=r[P1@P3]
6721467559
**
6721567560
** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
6721667561
**
6721767562
** This instruction makes a deep copy of the value. A duplicate
6721867563
** is made of any string or blob constant. See also OP_SCopy.
6721967564
*/
6722067565
case OP_Copy: {
67221
-#if 0 /* local variables moved into u.ae */
67566
+#if 0 /* local variables moved into u.af */
6722267567
int n;
67223
-#endif /* local variables moved into u.ae */
67568
+#endif /* local variables moved into u.af */
6722467569
67225
- u.ae.n = pOp->p3;
67570
+ u.af.n = pOp->p3;
6722667571
pIn1 = &aMem[pOp->p1];
6722767572
pOut = &aMem[pOp->p2];
6722867573
assert( pOut!=pIn1 );
6722967574
while( 1 ){
6723067575
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
6723167576
Deephemeralize(pOut);
6723267577
#ifdef SQLITE_DEBUG
6723367578
pOut->pScopyFrom = 0;
6723467579
#endif
67235
- REGISTER_TRACE(pOp->p2+pOp->p3-u.ae.n, pOut);
67236
- if( (u.ae.n--)==0 ) break;
67580
+ REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut);
67581
+ if( (u.af.n--)==0 ) break;
6723767582
pOut++;
6723867583
pIn1++;
6723967584
}
6724067585
break;
6724167586
}
6724267587
6724367588
/* Opcode: SCopy P1 P2 * * *
67589
+** Synopsis: r[P2]=r[P1]
6724467590
**
6724567591
** Make a shallow copy of register P1 into register P2.
6724667592
**
6724767593
** This instruction makes a shallow copy of the value. If the value
6724867594
** is a string or blob, then the copy is only a pointer to the
@@ -67250,35 +67596,35 @@
6725067596
** Worse, if the original is deallocated, the copy becomes invalid.
6725167597
** Thus the program must guarantee that the original will not change
6725267598
** during the lifetime of the copy. Use OP_Copy to make a complete
6725367599
** copy.
6725467600
*/
67255
-case OP_SCopy: { /* in1, out2 */
67601
+case OP_SCopy: { /* out2 */
6725667602
pIn1 = &aMem[pOp->p1];
6725767603
pOut = &aMem[pOp->p2];
6725867604
assert( pOut!=pIn1 );
6725967605
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
6726067606
#ifdef SQLITE_DEBUG
6726167607
if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1;
6726267608
#endif
67263
- REGISTER_TRACE(pOp->p2, pOut);
6726467609
break;
6726567610
}
6726667611
6726767612
/* Opcode: ResultRow P1 P2 * * *
67613
+** Synopsis: output=r[P1@P2]
6726867614
**
6726967615
** The registers P1 through P1+P2-1 contain a single row of
6727067616
** results. This opcode causes the sqlite3_step() call to terminate
6727167617
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
6727267618
** structure to provide access to the top P1 values as the result
6727367619
** row.
6727467620
*/
6727567621
case OP_ResultRow: {
67276
-#if 0 /* local variables moved into u.af */
67622
+#if 0 /* local variables moved into u.ag */
6727767623
Mem *pMem;
6727867624
int i;
67279
-#endif /* local variables moved into u.af */
67625
+#endif /* local variables moved into u.ag */
6728067626
assert( p->nResColumn==pOp->p2 );
6728167627
assert( pOp->p1>0 );
6728267628
assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
6728367629
6728467630
/* If this statement has violated immediate foreign key constraints, do
@@ -67316,19 +67662,19 @@
6731667662
6731767663
/* Make sure the results of the current row are \000 terminated
6731867664
** and have an assigned type. The results are de-ephemeralized as
6731967665
** a side effect.
6732067666
*/
67321
- u.af.pMem = p->pResultSet = &aMem[pOp->p1];
67322
- for(u.af.i=0; u.af.i<pOp->p2; u.af.i++){
67323
- assert( memIsValid(&u.af.pMem[u.af.i]) );
67324
- Deephemeralize(&u.af.pMem[u.af.i]);
67325
- assert( (u.af.pMem[u.af.i].flags & MEM_Ephem)==0
67326
- || (u.af.pMem[u.af.i].flags & (MEM_Str|MEM_Blob))==0 );
67327
- sqlite3VdbeMemNulTerminate(&u.af.pMem[u.af.i]);
67328
- sqlite3VdbeMemStoreType(&u.af.pMem[u.af.i]);
67329
- REGISTER_TRACE(pOp->p1+u.af.i, &u.af.pMem[u.af.i]);
67667
+ u.ag.pMem = p->pResultSet = &aMem[pOp->p1];
67668
+ for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){
67669
+ assert( memIsValid(&u.ag.pMem[u.ag.i]) );
67670
+ Deephemeralize(&u.ag.pMem[u.ag.i]);
67671
+ assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0
67672
+ || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 );
67673
+ sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]);
67674
+ sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]);
67675
+ REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]);
6733067676
}
6733167677
if( db->mallocFailed ) goto no_mem;
6733267678
6733367679
/* Return SQLITE_ROW
6733467680
*/
@@ -67336,10 +67682,11 @@
6733667682
rc = SQLITE_ROW;
6733767683
goto vdbe_return;
6733867684
}
6733967685
6734067686
/* Opcode: Concat P1 P2 P3 * *
67687
+** Synopsis: r[P3]=r[P2]+r[P1]
6734167688
**
6734267689
** Add the text in register P1 onto the end of the text in
6734367690
** register P2 and store the result in register P3.
6734467691
** If either the P1 or P2 text are NULL then store NULL in P3.
6734567692
**
@@ -67348,13 +67695,13 @@
6734867695
** It is illegal for P1 and P3 to be the same register. Sometimes,
6734967696
** if P3 is the same register as P2, the implementation is able
6735067697
** to avoid a memcpy().
6735167698
*/
6735267699
case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67353
-#if 0 /* local variables moved into u.ag */
67700
+#if 0 /* local variables moved into u.ah */
6735467701
i64 nByte;
67355
-#endif /* local variables moved into u.ag */
67702
+#endif /* local variables moved into u.ah */
6735667703
6735767704
pIn1 = &aMem[pOp->p1];
6735867705
pIn2 = &aMem[pOp->p2];
6735967706
pOut = &aMem[pOp->p3];
6736067707
assert( pIn1!=pOut );
@@ -67363,58 +67710,63 @@
6736367710
break;
6736467711
}
6736567712
if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
6736667713
Stringify(pIn1, encoding);
6736767714
Stringify(pIn2, encoding);
67368
- u.ag.nByte = pIn1->n + pIn2->n;
67369
- if( u.ag.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67715
+ u.ah.nByte = pIn1->n + pIn2->n;
67716
+ if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6737067717
goto too_big;
6737167718
}
6737267719
MemSetTypeFlag(pOut, MEM_Str);
67373
- if( sqlite3VdbeMemGrow(pOut, (int)u.ag.nByte+2, pOut==pIn2) ){
67720
+ if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
6737467721
goto no_mem;
6737567722
}
6737667723
if( pOut!=pIn2 ){
6737767724
memcpy(pOut->z, pIn2->z, pIn2->n);
6737867725
}
6737967726
memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67380
- pOut->z[u.ag.nByte] = 0;
67381
- pOut->z[u.ag.nByte+1] = 0;
67727
+ pOut->z[u.ah.nByte]=0;
67728
+ pOut->z[u.ah.nByte+1] = 0;
6738267729
pOut->flags |= MEM_Term;
67383
- pOut->n = (int)u.ag.nByte;
67730
+ pOut->n = (int)u.ah.nByte;
6738467731
pOut->enc = encoding;
6738567732
UPDATE_MAX_BLOBSIZE(pOut);
6738667733
break;
6738767734
}
6738867735
6738967736
/* Opcode: Add P1 P2 P3 * *
67737
+** Synopsis: r[P3]=r[P1]+r[P2]
6739067738
**
6739167739
** Add the value in register P1 to the value in register P2
6739267740
** and store the result in register P3.
6739367741
** If either input is NULL, the result is NULL.
6739467742
*/
6739567743
/* Opcode: Multiply P1 P2 P3 * *
67744
+** Synopsis: r[P3]=r[P1]*r[P2]
6739667745
**
6739767746
**
6739867747
** Multiply the value in register P1 by the value in register P2
6739967748
** and store the result in register P3.
6740067749
** If either input is NULL, the result is NULL.
6740167750
*/
6740267751
/* Opcode: Subtract P1 P2 P3 * *
67752
+** Synopsis: r[P3]=r[P2]-r[P1]
6740367753
**
6740467754
** Subtract the value in register P1 from the value in register P2
6740567755
** and store the result in register P3.
6740667756
** If either input is NULL, the result is NULL.
6740767757
*/
6740867758
/* Opcode: Divide P1 P2 P3 * *
67759
+** Synopsis: r[P3]=r[P1]/r[P2]
6740967760
**
6741067761
** Divide the value in register P1 by the value in register P2
6741167762
** and store the result in register P3 (P3=P2/P1). If the value in
6741267763
** register P1 is zero, then the result is NULL. If either input is
6741367764
** NULL, the result is NULL.
6741467765
*/
6741567766
/* Opcode: Remainder P1 P2 P3 * *
67767
+** Synopsis: r[P3]=r[P1]%r[P2]
6741667768
**
6741767769
** Compute the remainder after integer division of the value in
6741867770
** register P1 by the value in register P2 and store the result in P3.
6741967771
** If the value in register P2 is zero the result is NULL.
6742067772
** If either operand is NULL, the result is NULL.
@@ -67422,83 +67774,83 @@
6742267774
case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
6742367775
case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
6742467776
case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
6742567777
case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
6742667778
case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67427
-#if 0 /* local variables moved into u.ah */
67779
+#if 0 /* local variables moved into u.ai */
6742867780
char bIntint; /* Started out as two integer operands */
6742967781
int flags; /* Combined MEM_* flags from both inputs */
6743067782
i64 iA; /* Integer value of left operand */
6743167783
i64 iB; /* Integer value of right operand */
6743267784
double rA; /* Real value of left operand */
6743367785
double rB; /* Real value of right operand */
67434
-#endif /* local variables moved into u.ah */
67786
+#endif /* local variables moved into u.ai */
6743567787
6743667788
pIn1 = &aMem[pOp->p1];
6743767789
applyNumericAffinity(pIn1);
6743867790
pIn2 = &aMem[pOp->p2];
6743967791
applyNumericAffinity(pIn2);
6744067792
pOut = &aMem[pOp->p3];
67441
- u.ah.flags = pIn1->flags | pIn2->flags;
67442
- if( (u.ah.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67793
+ u.ai.flags = pIn1->flags | pIn2->flags;
67794
+ if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
6744367795
if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67444
- u.ah.iA = pIn1->u.i;
67445
- u.ah.iB = pIn2->u.i;
67446
- u.ah.bIntint = 1;
67796
+ u.ai.iA = pIn1->u.i;
67797
+ u.ai.iB = pIn2->u.i;
67798
+ u.ai.bIntint = 1;
6744767799
switch( pOp->opcode ){
67448
- case OP_Add: if( sqlite3AddInt64(&u.ah.iB,u.ah.iA) ) goto fp_math; break;
67449
- case OP_Subtract: if( sqlite3SubInt64(&u.ah.iB,u.ah.iA) ) goto fp_math; break;
67450
- case OP_Multiply: if( sqlite3MulInt64(&u.ah.iB,u.ah.iA) ) goto fp_math; break;
67800
+ case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67801
+ case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67802
+ case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
6745167803
case OP_Divide: {
67452
- if( u.ah.iA==0 ) goto arithmetic_result_is_null;
67453
- if( u.ah.iA==-1 && u.ah.iB==SMALLEST_INT64 ) goto fp_math;
67454
- u.ah.iB /= u.ah.iA;
67804
+ if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67805
+ if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math;
67806
+ u.ai.iB /= u.ai.iA;
6745567807
break;
6745667808
}
6745767809
default: {
67458
- if( u.ah.iA==0 ) goto arithmetic_result_is_null;
67459
- if( u.ah.iA==-1 ) u.ah.iA = 1;
67460
- u.ah.iB %= u.ah.iA;
67810
+ if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67811
+ if( u.ai.iA==-1 ) u.ai.iA = 1;
67812
+ u.ai.iB %= u.ai.iA;
6746167813
break;
6746267814
}
6746367815
}
67464
- pOut->u.i = u.ah.iB;
67816
+ pOut->u.i = u.ai.iB;
6746567817
MemSetTypeFlag(pOut, MEM_Int);
6746667818
}else{
67467
- u.ah.bIntint = 0;
67819
+ u.ai.bIntint = 0;
6746867820
fp_math:
67469
- u.ah.rA = sqlite3VdbeRealValue(pIn1);
67470
- u.ah.rB = sqlite3VdbeRealValue(pIn2);
67821
+ u.ai.rA = sqlite3VdbeRealValue(pIn1);
67822
+ u.ai.rB = sqlite3VdbeRealValue(pIn2);
6747167823
switch( pOp->opcode ){
67472
- case OP_Add: u.ah.rB += u.ah.rA; break;
67473
- case OP_Subtract: u.ah.rB -= u.ah.rA; break;
67474
- case OP_Multiply: u.ah.rB *= u.ah.rA; break;
67824
+ case OP_Add: u.ai.rB += u.ai.rA; break;
67825
+ case OP_Subtract: u.ai.rB -= u.ai.rA; break;
67826
+ case OP_Multiply: u.ai.rB *= u.ai.rA; break;
6747567827
case OP_Divide: {
6747667828
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67477
- if( u.ah.rA==(double)0 ) goto arithmetic_result_is_null;
67478
- u.ah.rB /= u.ah.rA;
67829
+ if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null;
67830
+ u.ai.rB /= u.ai.rA;
6747967831
break;
6748067832
}
6748167833
default: {
67482
- u.ah.iA = (i64)u.ah.rA;
67483
- u.ah.iB = (i64)u.ah.rB;
67484
- if( u.ah.iA==0 ) goto arithmetic_result_is_null;
67485
- if( u.ah.iA==-1 ) u.ah.iA = 1;
67486
- u.ah.rB = (double)(u.ah.iB % u.ah.iA);
67834
+ u.ai.iA = (i64)u.ai.rA;
67835
+ u.ai.iB = (i64)u.ai.rB;
67836
+ if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67837
+ if( u.ai.iA==-1 ) u.ai.iA = 1;
67838
+ u.ai.rB = (double)(u.ai.iB % u.ai.iA);
6748767839
break;
6748867840
}
6748967841
}
6749067842
#ifdef SQLITE_OMIT_FLOATING_POINT
67491
- pOut->u.i = u.ah.rB;
67843
+ pOut->u.i = u.ai.rB;
6749267844
MemSetTypeFlag(pOut, MEM_Int);
6749367845
#else
67494
- if( sqlite3IsNaN(u.ah.rB) ){
67846
+ if( sqlite3IsNaN(u.ai.rB) ){
6749567847
goto arithmetic_result_is_null;
6749667848
}
67497
- pOut->r = u.ah.rB;
67849
+ pOut->r = u.ai.rB;
6749867850
MemSetTypeFlag(pOut, MEM_Real);
67499
- if( (u.ah.flags & MEM_Real)==0 && !u.ah.bIntint ){
67851
+ if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
6750067852
sqlite3VdbeIntegerAffinity(pOut);
6750167853
}
6750267854
#endif
6750367855
}
6750467856
break;
@@ -67530,10 +67882,11 @@
6753067882
}
6753167883
break;
6753267884
}
6753367885
6753467886
/* Opcode: Function P1 P2 P3 P4 P5
67887
+** Synopsis: r[P3]=func(r[P2@P5])
6753567888
**
6753667889
** Invoke a user function (P4 is a pointer to a Function structure that
6753767890
** defines the function) with P5 arguments taken from register P2 and
6753867891
** successors. The result of the function is stored in register P3.
6753967892
** Register P3 must not be one of the function inputs.
@@ -67546,85 +67899,85 @@
6754667899
** invocation of this opcode.
6754767900
**
6754867901
** See also: AggStep and AggFinal
6754967902
*/
6755067903
case OP_Function: {
67551
-#if 0 /* local variables moved into u.ai */
67904
+#if 0 /* local variables moved into u.aj */
6755267905
int i;
6755367906
Mem *pArg;
6755467907
sqlite3_context ctx;
6755567908
sqlite3_value **apVal;
6755667909
int n;
67557
-#endif /* local variables moved into u.ai */
67910
+#endif /* local variables moved into u.aj */
6755867911
67559
- u.ai.n = pOp->p5;
67560
- u.ai.apVal = p->apArg;
67561
- assert( u.ai.apVal || u.ai.n==0 );
67912
+ u.aj.n = pOp->p5;
67913
+ u.aj.apVal = p->apArg;
67914
+ assert( u.aj.apVal || u.aj.n==0 );
6756267915
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
6756367916
pOut = &aMem[pOp->p3];
6756467917
memAboutToChange(p, pOut);
6756567918
67566
- assert( u.ai.n==0 || (pOp->p2>0 && pOp->p2+u.ai.n<=(p->nMem-p->nCursor)+1) );
67567
- assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ai.n );
67568
- u.ai.pArg = &aMem[pOp->p2];
67569
- for(u.ai.i=0; u.ai.i<u.ai.n; u.ai.i++, u.ai.pArg++){
67570
- assert( memIsValid(u.ai.pArg) );
67571
- u.ai.apVal[u.ai.i] = u.ai.pArg;
67572
- Deephemeralize(u.ai.pArg);
67573
- sqlite3VdbeMemStoreType(u.ai.pArg);
67574
- REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
67919
+ assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) );
67920
+ assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n );
67921
+ u.aj.pArg = &aMem[pOp->p2];
67922
+ for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){
67923
+ assert( memIsValid(u.aj.pArg) );
67924
+ u.aj.apVal[u.aj.i] = u.aj.pArg;
67925
+ Deephemeralize(u.aj.pArg);
67926
+ sqlite3VdbeMemStoreType(u.aj.pArg);
67927
+ REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
6757567928
}
6757667929
6757767930
assert( pOp->p4type==P4_FUNCDEF );
67578
- u.ai.ctx.pFunc = pOp->p4.pFunc;
67579
- u.ai.ctx.s.flags = MEM_Null;
67580
- u.ai.ctx.s.db = db;
67581
- u.ai.ctx.s.xDel = 0;
67582
- u.ai.ctx.s.zMalloc = 0;
67583
- u.ai.ctx.iOp = pc;
67584
- u.ai.ctx.pVdbe = p;
67931
+ u.aj.ctx.pFunc = pOp->p4.pFunc;
67932
+ u.aj.ctx.s.flags = MEM_Null;
67933
+ u.aj.ctx.s.db = db;
67934
+ u.aj.ctx.s.xDel = 0;
67935
+ u.aj.ctx.s.zMalloc = 0;
67936
+ u.aj.ctx.iOp = pc;
67937
+ u.aj.ctx.pVdbe = p;
6758567938
6758667939
/* The output cell may already have a buffer allocated. Move
67587
- ** the pointer to u.ai.ctx.s so in case the user-function can use
67940
+ ** the pointer to u.aj.ctx.s so in case the user-function can use
6758867941
** the already allocated buffer instead of allocating a new one.
6758967942
*/
67590
- sqlite3VdbeMemMove(&u.ai.ctx.s, pOut);
67591
- MemSetTypeFlag(&u.ai.ctx.s, MEM_Null);
67943
+ sqlite3VdbeMemMove(&u.aj.ctx.s, pOut);
67944
+ MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
6759267945
67593
- u.ai.ctx.fErrorOrAux = 0;
67594
- if( u.ai.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67946
+ u.aj.ctx.fErrorOrAux = 0;
67947
+ if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
6759567948
assert( pOp>aOp );
6759667949
assert( pOp[-1].p4type==P4_COLLSEQ );
6759767950
assert( pOp[-1].opcode==OP_CollSeq );
67598
- u.ai.ctx.pColl = pOp[-1].p4.pColl;
67951
+ u.aj.ctx.pColl = pOp[-1].p4.pColl;
6759967952
}
6760067953
db->lastRowid = lastRowid;
67601
- (*u.ai.ctx.pFunc->xFunc)(&u.ai.ctx, u.ai.n, u.ai.apVal); /* IMP: R-24505-23230 */
67954
+ (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */
6760267955
lastRowid = db->lastRowid;
6760367956
6760467957
if( db->mallocFailed ){
6760567958
/* Even though a malloc() has failed, the implementation of the
6760667959
** user function may have called an sqlite3_result_XXX() function
6760767960
** to return a value. The following call releases any resources
6760867961
** associated with such a value.
6760967962
*/
67610
- sqlite3VdbeMemRelease(&u.ai.ctx.s);
67963
+ sqlite3VdbeMemRelease(&u.aj.ctx.s);
6761167964
goto no_mem;
6761267965
}
6761367966
6761467967
/* If the function returned an error, throw an exception */
67615
- if( u.ai.ctx.fErrorOrAux ){
67616
- if( u.ai.ctx.isError ){
67617
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ai.ctx.s));
67618
- rc = u.ai.ctx.isError;
67968
+ if( u.aj.ctx.fErrorOrAux ){
67969
+ if( u.aj.ctx.isError ){
67970
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s));
67971
+ rc = u.aj.ctx.isError;
6761967972
}
6762067973
sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
6762167974
}
6762267975
6762367976
/* Copy the result of the function into register P3 */
67624
- sqlite3VdbeChangeEncoding(&u.ai.ctx.s, encoding);
67625
- sqlite3VdbeMemMove(pOut, &u.ai.ctx.s);
67977
+ sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
67978
+ sqlite3VdbeMemMove(pOut, &u.aj.ctx.s);
6762667979
if( sqlite3VdbeMemTooBig(pOut) ){
6762767980
goto too_big;
6762867981
}
6762967982
6763067983
#if 0
@@ -67639,29 +67992,33 @@
6763967992
UPDATE_MAX_BLOBSIZE(pOut);
6764067993
break;
6764167994
}
6764267995
6764367996
/* Opcode: BitAnd P1 P2 P3 * *
67997
+** Synopsis: r[P3]=r[P1]&r[P2]
6764467998
**
6764567999
** Take the bit-wise AND of the values in register P1 and P2 and
6764668000
** store the result in register P3.
6764768001
** If either input is NULL, the result is NULL.
6764868002
*/
6764968003
/* Opcode: BitOr P1 P2 P3 * *
68004
+** Synopsis: r[P3]=r[P1]|r[P2]
6765068005
**
6765168006
** Take the bit-wise OR of the values in register P1 and P2 and
6765268007
** store the result in register P3.
6765368008
** If either input is NULL, the result is NULL.
6765468009
*/
6765568010
/* Opcode: ShiftLeft P1 P2 P3 * *
68011
+** Synopsis: r[P3]=r[P2]<<r[P1]
6765668012
**
6765768013
** Shift the integer value in register P2 to the left by the
6765868014
** number of bits specified by the integer in register P1.
6765968015
** Store the result in register P3.
6766068016
** If either input is NULL, the result is NULL.
6766168017
*/
6766268018
/* Opcode: ShiftRight P1 P2 P3 * *
68019
+** Synopsis: r[P3]=r[P2]>>r[P1]
6766368020
**
6766468021
** Shift the integer value in register P2 to the right by the
6766568022
** number of bits specified by the integer in register P1.
6766668023
** Store the result in register P3.
6766768024
** If either input is NULL, the result is NULL.
@@ -67668,61 +68025,62 @@
6766868025
*/
6766968026
case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
6767068027
case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
6767168028
case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
6767268029
case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
67673
-#if 0 /* local variables moved into u.aj */
68030
+#if 0 /* local variables moved into u.ak */
6767468031
i64 iA;
6767568032
u64 uA;
6767668033
i64 iB;
6767768034
u8 op;
67678
-#endif /* local variables moved into u.aj */
68035
+#endif /* local variables moved into u.ak */
6767968036
6768068037
pIn1 = &aMem[pOp->p1];
6768168038
pIn2 = &aMem[pOp->p2];
6768268039
pOut = &aMem[pOp->p3];
6768368040
if( (pIn1->flags | pIn2->flags) & MEM_Null ){
6768468041
sqlite3VdbeMemSetNull(pOut);
6768568042
break;
6768668043
}
67687
- u.aj.iA = sqlite3VdbeIntValue(pIn2);
67688
- u.aj.iB = sqlite3VdbeIntValue(pIn1);
67689
- u.aj.op = pOp->opcode;
67690
- if( u.aj.op==OP_BitAnd ){
67691
- u.aj.iA &= u.aj.iB;
67692
- }else if( u.aj.op==OP_BitOr ){
67693
- u.aj.iA |= u.aj.iB;
67694
- }else if( u.aj.iB!=0 ){
67695
- assert( u.aj.op==OP_ShiftRight || u.aj.op==OP_ShiftLeft );
68044
+ u.ak.iA = sqlite3VdbeIntValue(pIn2);
68045
+ u.ak.iB = sqlite3VdbeIntValue(pIn1);
68046
+ u.ak.op = pOp->opcode;
68047
+ if( u.ak.op==OP_BitAnd ){
68048
+ u.ak.iA &= u.ak.iB;
68049
+ }else if( u.ak.op==OP_BitOr ){
68050
+ u.ak.iA |= u.ak.iB;
68051
+ }else if( u.ak.iB!=0 ){
68052
+ assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft );
6769668053
6769768054
/* If shifting by a negative amount, shift in the other direction */
67698
- if( u.aj.iB<0 ){
68055
+ if( u.ak.iB<0 ){
6769968056
assert( OP_ShiftRight==OP_ShiftLeft+1 );
67700
- u.aj.op = 2*OP_ShiftLeft + 1 - u.aj.op;
67701
- u.aj.iB = u.aj.iB>(-64) ? -u.aj.iB : 64;
68057
+ u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op;
68058
+ u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64;
6770268059
}
6770368060
67704
- if( u.aj.iB>=64 ){
67705
- u.aj.iA = (u.aj.iA>=0 || u.aj.op==OP_ShiftLeft) ? 0 : -1;
67706
- }else{
67707
- memcpy(&u.aj.uA, &u.aj.iA, sizeof(u.aj.uA));
67708
- if( u.aj.op==OP_ShiftLeft ){
67709
- u.aj.uA <<= u.aj.iB;
67710
- }else{
67711
- u.aj.uA >>= u.aj.iB;
68061
+ if( u.ak.iB>=64 ){
68062
+ u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1;
68063
+ }else{
68064
+ memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA));
68065
+ if( u.ak.op==OP_ShiftLeft ){
68066
+ u.ak.uA <<= u.ak.iB;
68067
+ }else{
68068
+ u.ak.uA >>= u.ak.iB;
6771268069
/* Sign-extend on a right shift of a negative number */
67713
- if( u.aj.iA<0 ) u.aj.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.aj.iB);
68070
+ if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB);
6771468071
}
67715
- memcpy(&u.aj.iA, &u.aj.uA, sizeof(u.aj.iA));
68072
+ memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
6771668073
}
6771768074
}
67718
- pOut->u.i = u.aj.iA;
68075
+ pOut->u.i = u.ak.iA;
6771968076
MemSetTypeFlag(pOut, MEM_Int);
6772068077
break;
6772168078
}
6772268079
6772368080
/* Opcode: AddImm P1 P2 * * *
68081
+** Synopsis: r[P1]=r[P1]+P2
6772468082
**
6772568083
** Add the constant P2 to the value in register P1.
6772668084
** The result is always an integer.
6772768085
**
6772868086
** To force any register to be an integer, just add 0.
@@ -67877,10 +68235,11 @@
6787768235
break;
6787868236
}
6787968237
#endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
6788068238
6788168239
/* Opcode: Lt P1 P2 P3 P4 P5
68240
+** Synopsis: if r[P1]<r[P3] goto P3
6788268241
**
6788368242
** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
6788468243
** jump to address P2.
6788568244
**
6788668245
** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -67911,10 +68270,11 @@
6791168270
** If the SQLITE_NULLEQ bit is set in P5, then NULL values are considered
6791268271
** equal to one another, provided that they do not have their MEM_Cleared
6791368272
** bit set.
6791468273
*/
6791568274
/* Opcode: Ne P1 P2 P3 P4 P5
68275
+** Synopsis: if r[P1]!=r[P3] goto P2
6791668276
**
6791768277
** This works just like the Lt opcode except that the jump is taken if
6791868278
** the operands in registers P1 and P3 are not equal. See the Lt opcode for
6791968279
** additional information.
6792068280
**
@@ -67923,10 +68283,11 @@
6792368283
** of comparison is false. If either operand is NULL then the result is true.
6792468284
** If neither operand is NULL the result is the same as it would be if
6792568285
** the SQLITE_NULLEQ flag were omitted from P5.
6792668286
*/
6792768287
/* Opcode: Eq P1 P2 P3 P4 P5
68288
+** Synopsis: if r[P1]==r[P3] goto P2
6792868289
**
6792968290
** This works just like the Lt opcode except that the jump is taken if
6793068291
** the operands in registers P1 and P3 are equal.
6793168292
** See the Lt opcode for additional information.
6793268293
**
@@ -67935,22 +68296,25 @@
6793568296
** of comparison is true. If either operand is NULL then the result is false.
6793668297
** If neither operand is NULL the result is the same as it would be if
6793768298
** the SQLITE_NULLEQ flag were omitted from P5.
6793868299
*/
6793968300
/* Opcode: Le P1 P2 P3 P4 P5
68301
+** Synopsis: if r[P1]<=r[P3] goto P2
6794068302
**
6794168303
** This works just like the Lt opcode except that the jump is taken if
6794268304
** the content of register P3 is less than or equal to the content of
6794368305
** register P1. See the Lt opcode for additional information.
6794468306
*/
6794568307
/* Opcode: Gt P1 P2 P3 P4 P5
68308
+** Synopsis: if r[P1]>r[P3] goto P2
6794668309
**
6794768310
** This works just like the Lt opcode except that the jump is taken if
6794868311
** the content of register P3 is greater than the content of
6794968312
** register P1. See the Lt opcode for additional information.
6795068313
*/
6795168314
/* Opcode: Ge P1 P2 P3 P4 P5
68315
+** Synopsis: if r[P1]>=r[P3] goto P2
6795268316
**
6795368317
** This works just like the Lt opcode except that the jump is taken if
6795468318
** the content of register P3 is greater than or equal to the content of
6795568319
** register P1. See the Lt opcode for additional information.
6795668320
*/
@@ -67958,37 +68322,37 @@
6795868322
case OP_Ne: /* same as TK_NE, jump, in1, in3 */
6795968323
case OP_Lt: /* same as TK_LT, jump, in1, in3 */
6796068324
case OP_Le: /* same as TK_LE, jump, in1, in3 */
6796168325
case OP_Gt: /* same as TK_GT, jump, in1, in3 */
6796268326
case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
67963
-#if 0 /* local variables moved into u.ak */
68327
+#if 0 /* local variables moved into u.al */
6796468328
int res; /* Result of the comparison of pIn1 against pIn3 */
6796568329
char affinity; /* Affinity to use for comparison */
6796668330
u16 flags1; /* Copy of initial value of pIn1->flags */
6796768331
u16 flags3; /* Copy of initial value of pIn3->flags */
67968
-#endif /* local variables moved into u.ak */
68332
+#endif /* local variables moved into u.al */
6796968333
6797068334
pIn1 = &aMem[pOp->p1];
6797168335
pIn3 = &aMem[pOp->p3];
67972
- u.ak.flags1 = pIn1->flags;
67973
- u.ak.flags3 = pIn3->flags;
67974
- if( (u.ak.flags1 | u.ak.flags3)&MEM_Null ){
68336
+ u.al.flags1 = pIn1->flags;
68337
+ u.al.flags3 = pIn3->flags;
68338
+ if( (u.al.flags1 | u.al.flags3)&MEM_Null ){
6797568339
/* One or both operands are NULL */
6797668340
if( pOp->p5 & SQLITE_NULLEQ ){
6797768341
/* If SQLITE_NULLEQ is set (which will only happen if the operator is
6797868342
** OP_Eq or OP_Ne) then take the jump or not depending on whether
6797968343
** or not both operands are null.
6798068344
*/
6798168345
assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
67982
- assert( (u.ak.flags1 & MEM_Cleared)==0 );
67983
- if( (u.ak.flags1&MEM_Null)!=0
67984
- && (u.ak.flags3&MEM_Null)!=0
67985
- && (u.ak.flags3&MEM_Cleared)==0
68346
+ assert( (u.al.flags1 & MEM_Cleared)==0 );
68347
+ if( (u.al.flags1&MEM_Null)!=0
68348
+ && (u.al.flags3&MEM_Null)!=0
68349
+ && (u.al.flags3&MEM_Cleared)==0
6798668350
){
67987
- u.ak.res = 0; /* Results are equal */
68351
+ u.al.res = 0; /* Results are equal */
6798868352
}else{
67989
- u.ak.res = 1; /* Results are not equal */
68353
+ u.al.res = 1; /* Results are not equal */
6799068354
}
6799168355
}else{
6799268356
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
6799368357
** then the result is always NULL.
6799468358
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68002,44 +68366,44 @@
6800268366
}
6800368367
break;
6800468368
}
6800568369
}else{
6800668370
/* Neither operand is NULL. Do a comparison. */
68007
- u.ak.affinity = pOp->p5 & SQLITE_AFF_MASK;
68008
- if( u.ak.affinity ){
68009
- applyAffinity(pIn1, u.ak.affinity, encoding);
68010
- applyAffinity(pIn3, u.ak.affinity, encoding);
68371
+ u.al.affinity = pOp->p5 & SQLITE_AFF_MASK;
68372
+ if( u.al.affinity ){
68373
+ applyAffinity(pIn1, u.al.affinity, encoding);
68374
+ applyAffinity(pIn3, u.al.affinity, encoding);
6801168375
if( db->mallocFailed ) goto no_mem;
6801268376
}
6801368377
6801468378
assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
6801568379
ExpandBlob(pIn1);
6801668380
ExpandBlob(pIn3);
68017
- u.ak.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68381
+ u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
6801868382
}
6801968383
switch( pOp->opcode ){
68020
- case OP_Eq: u.ak.res = u.ak.res==0; break;
68021
- case OP_Ne: u.ak.res = u.ak.res!=0; break;
68022
- case OP_Lt: u.ak.res = u.ak.res<0; break;
68023
- case OP_Le: u.ak.res = u.ak.res<=0; break;
68024
- case OP_Gt: u.ak.res = u.ak.res>0; break;
68025
- default: u.ak.res = u.ak.res>=0; break;
68384
+ case OP_Eq: u.al.res = u.al.res==0; break;
68385
+ case OP_Ne: u.al.res = u.al.res!=0; break;
68386
+ case OP_Lt: u.al.res = u.al.res<0; break;
68387
+ case OP_Le: u.al.res = u.al.res<=0; break;
68388
+ case OP_Gt: u.al.res = u.al.res>0; break;
68389
+ default: u.al.res = u.al.res>=0; break;
6802668390
}
6802768391
6802868392
if( pOp->p5 & SQLITE_STOREP2 ){
6802968393
pOut = &aMem[pOp->p2];
6803068394
memAboutToChange(p, pOut);
6803168395
MemSetTypeFlag(pOut, MEM_Int);
68032
- pOut->u.i = u.ak.res;
68396
+ pOut->u.i = u.al.res;
6803368397
REGISTER_TRACE(pOp->p2, pOut);
68034
- }else if( u.ak.res ){
68398
+ }else if( u.al.res ){
6803568399
pc = pOp->p2-1;
6803668400
}
6803768401
6803868402
/* Undo any changes made by applyAffinity() to the input registers. */
68039
- pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.ak.flags1&MEM_TypeMask);
68040
- pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.ak.flags3&MEM_TypeMask);
68403
+ pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask);
68404
+ pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask);
6804168405
break;
6804268406
}
6804368407
6804468408
/* Opcode: Permutation * * * P4 *
6804568409
**
@@ -68075,51 +68439,51 @@
6807568439
** The comparison is a sort comparison, so NULLs compare equal,
6807668440
** NULLs are less than numbers, numbers are less than strings,
6807768441
** and strings are less than blobs.
6807868442
*/
6807968443
case OP_Compare: {
68080
-#if 0 /* local variables moved into u.al */
68444
+#if 0 /* local variables moved into u.am */
6808168445
int n;
6808268446
int i;
6808368447
int p1;
6808468448
int p2;
6808568449
const KeyInfo *pKeyInfo;
6808668450
int idx;
6808768451
CollSeq *pColl; /* Collating sequence to use on this term */
6808868452
int bRev; /* True for DESCENDING sort order */
68089
-#endif /* local variables moved into u.al */
68453
+#endif /* local variables moved into u.am */
6809068454
6809168455
if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68092
- u.al.n = pOp->p3;
68093
- u.al.pKeyInfo = pOp->p4.pKeyInfo;
68094
- assert( u.al.n>0 );
68095
- assert( u.al.pKeyInfo!=0 );
68096
- u.al.p1 = pOp->p1;
68097
- u.al.p2 = pOp->p2;
68456
+ u.am.n = pOp->p3;
68457
+ u.am.pKeyInfo = pOp->p4.pKeyInfo;
68458
+ assert( u.am.n>0 );
68459
+ assert( u.am.pKeyInfo!=0 );
68460
+ u.am.p1 = pOp->p1;
68461
+ u.am.p2 = pOp->p2;
6809868462
#if SQLITE_DEBUG
6809968463
if( aPermute ){
6810068464
int k, mx = 0;
68101
- for(k=0; k<u.al.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68102
- assert( u.al.p1>0 && u.al.p1+mx<=(p->nMem-p->nCursor)+1 );
68103
- assert( u.al.p2>0 && u.al.p2+mx<=(p->nMem-p->nCursor)+1 );
68465
+ for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68466
+ assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 );
68467
+ assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 );
6810468468
}else{
68105
- assert( u.al.p1>0 && u.al.p1+u.al.n<=(p->nMem-p->nCursor)+1 );
68106
- assert( u.al.p2>0 && u.al.p2+u.al.n<=(p->nMem-p->nCursor)+1 );
68469
+ assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 );
68470
+ assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 );
6810768471
}
6810868472
#endif /* SQLITE_DEBUG */
68109
- for(u.al.i=0; u.al.i<u.al.n; u.al.i++){
68110
- u.al.idx = aPermute ? aPermute[u.al.i] : u.al.i;
68111
- assert( memIsValid(&aMem[u.al.p1+u.al.idx]) );
68112
- assert( memIsValid(&aMem[u.al.p2+u.al.idx]) );
68113
- REGISTER_TRACE(u.al.p1+u.al.idx, &aMem[u.al.p1+u.al.idx]);
68114
- REGISTER_TRACE(u.al.p2+u.al.idx, &aMem[u.al.p2+u.al.idx]);
68115
- assert( u.al.i<u.al.pKeyInfo->nField );
68116
- u.al.pColl = u.al.pKeyInfo->aColl[u.al.i];
68117
- u.al.bRev = u.al.pKeyInfo->aSortOrder[u.al.i];
68118
- iCompare = sqlite3MemCompare(&aMem[u.al.p1+u.al.idx], &aMem[u.al.p2+u.al.idx], u.al.pColl);
68473
+ for(u.am.i=0; u.am.i<u.am.n; u.am.i++){
68474
+ u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i;
68475
+ assert( memIsValid(&aMem[u.am.p1+u.am.idx]) );
68476
+ assert( memIsValid(&aMem[u.am.p2+u.am.idx]) );
68477
+ REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]);
68478
+ REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]);
68479
+ assert( u.am.i<u.am.pKeyInfo->nField );
68480
+ u.am.pColl = u.am.pKeyInfo->aColl[u.am.i];
68481
+ u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i];
68482
+ iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl);
6811968483
if( iCompare ){
68120
- if( u.al.bRev ) iCompare = -iCompare;
68484
+ if( u.am.bRev ) iCompare = -iCompare;
6812168485
break;
6812268486
}
6812368487
}
6812468488
aPermute = 0;
6812568489
break;
@@ -68141,19 +68505,21 @@
6814168505
}
6814268506
break;
6814368507
}
6814468508
6814568509
/* Opcode: And P1 P2 P3 * *
68510
+** Synopsis: r[P3]=(r[P1] && r[P2])
6814668511
**
6814768512
** Take the logical AND of the values in registers P1 and P2 and
6814868513
** write the result into register P3.
6814968514
**
6815068515
** If either P1 or P2 is 0 (false) then the result is 0 even if
6815168516
** the other input is NULL. A NULL and true or two NULLs give
6815268517
** a NULL output.
6815368518
*/
6815468519
/* Opcode: Or P1 P2 P3 * *
68520
+** Synopsis: r[P3]=(r[P1] || r[P2])
6815568521
**
6815668522
** Take the logical OR of the values in register P1 and P2 and
6815768523
** store the answer in register P3.
6815868524
**
6815968525
** If either P1 or P2 is nonzero (true) then the result is 1 (true)
@@ -68160,45 +68526,46 @@
6816068526
** even if the other input is NULL. A NULL and false or two NULLs
6816168527
** give a NULL output.
6816268528
*/
6816368529
case OP_And: /* same as TK_AND, in1, in2, out3 */
6816468530
case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68165
-#if 0 /* local variables moved into u.am */
68531
+#if 0 /* local variables moved into u.an */
6816668532
int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
6816768533
int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68168
-#endif /* local variables moved into u.am */
68534
+#endif /* local variables moved into u.an */
6816968535
6817068536
pIn1 = &aMem[pOp->p1];
6817168537
if( pIn1->flags & MEM_Null ){
68172
- u.am.v1 = 2;
68538
+ u.an.v1 = 2;
6817368539
}else{
68174
- u.am.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68540
+ u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
6817568541
}
6817668542
pIn2 = &aMem[pOp->p2];
6817768543
if( pIn2->flags & MEM_Null ){
68178
- u.am.v2 = 2;
68544
+ u.an.v2 = 2;
6817968545
}else{
68180
- u.am.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68546
+ u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
6818168547
}
6818268548
if( pOp->opcode==OP_And ){
6818368549
static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68184
- u.am.v1 = and_logic[u.am.v1*3+u.am.v2];
68550
+ u.an.v1 = and_logic[u.an.v1*3+u.an.v2];
6818568551
}else{
6818668552
static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68187
- u.am.v1 = or_logic[u.am.v1*3+u.am.v2];
68553
+ u.an.v1 = or_logic[u.an.v1*3+u.an.v2];
6818868554
}
6818968555
pOut = &aMem[pOp->p3];
68190
- if( u.am.v1==2 ){
68556
+ if( u.an.v1==2 ){
6819168557
MemSetTypeFlag(pOut, MEM_Null);
6819268558
}else{
68193
- pOut->u.i = u.am.v1;
68559
+ pOut->u.i = u.an.v1;
6819468560
MemSetTypeFlag(pOut, MEM_Int);
6819568561
}
6819668562
break;
6819768563
}
6819868564
6819968565
/* Opcode: Not P1 P2 * * *
68566
+** Synopsis: r[P2]= !r[P1]
6820068567
**
6820168568
** Interpret the value in register P1 as a boolean value. Store the
6820268569
** boolean complement in register P2. If the value in register P1 is
6820368570
** NULL, then a NULL is stored in P2.
6820468571
*/
@@ -68212,10 +68579,11 @@
6821268579
}
6821368580
break;
6821468581
}
6821568582
6821668583
/* Opcode: BitNot P1 P2 * * *
68584
+** Synopsis: r[P1]= ~r[P1]
6821768585
**
6821868586
** Interpret the content of register P1 as an integer. Store the
6821968587
** ones-complement of the P1 value into register P2. If P1 holds
6822068588
** a NULL then store a NULL in P2.
6822168589
*/
@@ -68257,31 +68625,32 @@
6825768625
** is considered false if it has a numeric value of zero. If the value
6825868626
** in P1 is NULL then take the jump if P3 is zero.
6825968627
*/
6826068628
case OP_If: /* jump, in1 */
6826168629
case OP_IfNot: { /* jump, in1 */
68262
-#if 0 /* local variables moved into u.an */
68630
+#if 0 /* local variables moved into u.ao */
6826368631
int c;
68264
-#endif /* local variables moved into u.an */
68632
+#endif /* local variables moved into u.ao */
6826568633
pIn1 = &aMem[pOp->p1];
6826668634
if( pIn1->flags & MEM_Null ){
68267
- u.an.c = pOp->p3;
68635
+ u.ao.c = pOp->p3;
6826868636
}else{
6826968637
#ifdef SQLITE_OMIT_FLOATING_POINT
68270
- u.an.c = sqlite3VdbeIntValue(pIn1)!=0;
68638
+ u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
6827168639
#else
68272
- u.an.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68640
+ u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
6827368641
#endif
68274
- if( pOp->opcode==OP_IfNot ) u.an.c = !u.an.c;
68642
+ if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
6827568643
}
68276
- if( u.an.c ){
68644
+ if( u.ao.c ){
6827768645
pc = pOp->p2-1;
6827868646
}
6827968647
break;
6828068648
}
6828168649
6828268650
/* Opcode: IsNull P1 P2 * * *
68651
+** Synopsis: if r[P1]==NULL goto P2
6828368652
**
6828468653
** Jump to P2 if the value in register P1 is NULL.
6828568654
*/
6828668655
case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
6828768656
pIn1 = &aMem[pOp->p1];
@@ -68290,10 +68659,11 @@
6829068659
}
6829168660
break;
6829268661
}
6829368662
6829468663
/* Opcode: NotNull P1 P2 * * *
68664
+** Synopsis: if r[P1]!=NULL goto P2
6829568665
**
6829668666
** Jump to P2 if the value in register P1 is not NULL.
6829768667
*/
6829868668
case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
6829968669
pIn1 = &aMem[pOp->p1];
@@ -68302,10 +68672,11 @@
6830268672
}
6830368673
break;
6830468674
}
6830568675
6830668676
/* Opcode: Column P1 P2 P3 P4 P5
68677
+** Synopsis: r[P3]=PX
6830768678
**
6830868679
** Interpret the data that cursor P1 points to as a structure built using
6830968680
** the MakeRecord instruction. (See the MakeRecord opcode for additional
6831068681
** information about the format of the data.) Extract the P2-th column
6831168682
** from this record. If there are less that (P2+1)
@@ -68326,11 +68697,11 @@
6832668697
** the result is guaranteed to only be used as the argument of a length()
6832768698
** or typeof() function, respectively. The loading of large blobs can be
6832868699
** skipped for length() and all content loading can be skipped for typeof().
6832968700
*/
6833068701
case OP_Column: {
68331
-#if 0 /* local variables moved into u.ao */
68702
+#if 0 /* local variables moved into u.ap */
6833268703
u32 payloadSize; /* Number of bytes in the record */
6833368704
i64 payloadSize64; /* Number of bytes in the record */
6833468705
int p1; /* P1 value of the opcode */
6833568706
int p2; /* column number to retrieve */
6833668707
VdbeCursor *pC; /* The VDBE cursor */
@@ -68350,135 +68721,133 @@
6835068721
u32 szField; /* Number of bytes in the content of a field */
6835168722
int szHdr; /* Size of the header size field at start of record */
6835268723
int avail; /* Number of bytes of available data */
6835368724
u32 t; /* A type code from the record header */
6835468725
Mem *pReg; /* PseudoTable input register */
68355
-#endif /* local variables moved into u.ao */
68726
+#endif /* local variables moved into u.ap */
6835668727
6835768728
68358
- u.ao.p1 = pOp->p1;
68359
- u.ao.p2 = pOp->p2;
68360
- u.ao.pC = 0;
68361
- memset(&u.ao.sMem, 0, sizeof(u.ao.sMem));
68362
- assert( u.ao.p1<p->nCursor );
68729
+ u.ap.p1 = pOp->p1;
68730
+ u.ap.p2 = pOp->p2;
68731
+ u.ap.pC = 0;
68732
+ memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
68733
+ assert( u.ap.p1<p->nCursor );
6836368734
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68364
- u.ao.pDest = &aMem[pOp->p3];
68365
- memAboutToChange(p, u.ao.pDest);
68366
- u.ao.zRec = 0;
68735
+ u.ap.pDest = &aMem[pOp->p3];
68736
+ memAboutToChange(p, u.ap.pDest);
68737
+ u.ap.zRec = 0;
6836768738
68368
- /* This block sets the variable u.ao.payloadSize to be the total number of
68739
+ /* This block sets the variable u.ap.payloadSize to be the total number of
6836968740
** bytes in the record.
6837068741
**
68371
- ** u.ao.zRec is set to be the complete text of the record if it is available.
68742
+ ** u.ap.zRec is set to be the complete text of the record if it is available.
6837268743
** The complete record text is always available for pseudo-tables
6837368744
** If the record is stored in a cursor, the complete record text
68374
- ** might be available in the u.ao.pC->aRow cache. Or it might not be.
68375
- ** If the data is unavailable, u.ao.zRec is set to NULL.
68745
+ ** might be available in the u.ap.pC->aRow cache. Or it might not be.
68746
+ ** If the data is unavailable, u.ap.zRec is set to NULL.
6837668747
**
6837768748
** We also compute the number of columns in the record. For cursors,
6837868749
** the number of columns is stored in the VdbeCursor.nField element.
6837968750
*/
68380
- u.ao.pC = p->apCsr[u.ao.p1];
68381
- assert( u.ao.pC!=0 );
68751
+ u.ap.pC = p->apCsr[u.ap.p1];
68752
+ assert( u.ap.pC!=0 );
6838268753
#ifndef SQLITE_OMIT_VIRTUALTABLE
68383
- assert( u.ao.pC->pVtabCursor==0 );
68754
+ assert( u.ap.pC->pVtabCursor==0 );
6838468755
#endif
68385
- u.ao.pCrsr = u.ao.pC->pCursor;
68386
- if( u.ao.pCrsr!=0 ){
68756
+ u.ap.pCrsr = u.ap.pC->pCursor;
68757
+ if( u.ap.pCrsr!=0 ){
6838768758
/* The record is stored in a B-Tree */
68388
- rc = sqlite3VdbeCursorMoveto(u.ao.pC);
68759
+ rc = sqlite3VdbeCursorMoveto(u.ap.pC);
6838968760
if( rc ) goto abort_due_to_error;
68390
- if( u.ao.pC->nullRow ){
68391
- u.ao.payloadSize = 0;
68392
- }else if( u.ao.pC->cacheStatus==p->cacheCtr ){
68393
- u.ao.payloadSize = u.ao.pC->payloadSize;
68394
- u.ao.zRec = (char*)u.ao.pC->aRow;
68395
- }else if( u.ao.pC->isIndex ){
68396
- assert( sqlite3BtreeCursorIsValid(u.ao.pCrsr) );
68397
- VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ao.pCrsr, &u.ao.payloadSize64);
68761
+ if( u.ap.pC->nullRow ){
68762
+ u.ap.payloadSize = 0;
68763
+ }else if( u.ap.pC->cacheStatus==p->cacheCtr ){
68764
+ u.ap.payloadSize = u.ap.pC->payloadSize;
68765
+ u.ap.zRec = (char*)u.ap.pC->aRow;
68766
+ }else if( u.ap.pC->isIndex ){
68767
+ assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68768
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
6839868769
assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
6839968770
/* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68400
- ** payload size, so it is impossible for u.ao.payloadSize64 to be
68771
+ ** payload size, so it is impossible for u.ap.payloadSize64 to be
6840168772
** larger than 32 bits. */
68402
- assert( (u.ao.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ao.payloadSize64 );
68403
- u.ao.payloadSize = (u32)u.ao.payloadSize64;
68773
+ assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
68774
+ u.ap.payloadSize = (u32)u.ap.payloadSize64;
6840468775
}else{
68405
- assert( sqlite3BtreeCursorIsValid(u.ao.pCrsr) );
68406
- VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ao.pCrsr, &u.ao.payloadSize);
68776
+ assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68777
+ VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.payloadSize);
6840768778
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
6840868779
}
68409
- }else if( ALWAYS(u.ao.pC->pseudoTableReg>0) ){
68410
- u.ao.pReg = &aMem[u.ao.pC->pseudoTableReg];
68411
- if( u.ao.pC->multiPseudo ){
68412
- sqlite3VdbeMemShallowCopy(u.ao.pDest, u.ao.pReg+u.ao.p2, MEM_Ephem);
68413
- Deephemeralize(u.ao.pDest);
68780
+ }else{
68781
+ assert( u.ap.pC->pseudoTableReg>0 );
68782
+ u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
68783
+ if( u.ap.pC->multiPseudo ){
68784
+ sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
68785
+ Deephemeralize(u.ap.pDest);
6841468786
goto op_column_out;
6841568787
}
68416
- assert( u.ao.pReg->flags & MEM_Blob );
68417
- assert( memIsValid(u.ao.pReg) );
68418
- u.ao.payloadSize = u.ao.pReg->n;
68419
- u.ao.zRec = u.ao.pReg->z;
68420
- u.ao.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
68421
- assert( u.ao.payloadSize==0 || u.ao.zRec!=0 );
68422
- }else{
68423
- /* Consider the row to be NULL */
68424
- u.ao.payloadSize = 0;
68788
+ assert( u.ap.pReg->flags & MEM_Blob );
68789
+ assert( memIsValid(u.ap.pReg) );
68790
+ u.ap.payloadSize = u.ap.pReg->n;
68791
+ u.ap.zRec = u.ap.pReg->z;
68792
+ u.ap.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
68793
+ assert( u.ap.payloadSize==0 || u.ap.zRec!=0 );
6842568794
}
6842668795
68427
- /* If u.ao.payloadSize is 0, then just store a NULL. This can happen because of
68796
+ /* If u.ap.payloadSize is 0, then just store a NULL. This can happen because of
6842868797
** nullRow or because of a corrupt database. */
68429
- if( u.ao.payloadSize==0 ){
68430
- MemSetTypeFlag(u.ao.pDest, MEM_Null);
68798
+ if( u.ap.payloadSize==0 ){
68799
+ MemSetTypeFlag(u.ap.pDest, MEM_Null);
6843168800
goto op_column_out;
6843268801
}
6843368802
assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
68434
- if( u.ao.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68803
+ if( u.ap.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
6843568804
goto too_big;
6843668805
}
6843768806
68438
- u.ao.nField = u.ao.pC->nField;
68439
- assert( u.ao.p2<u.ao.nField );
68807
+ u.ap.nField = u.ap.pC->nField;
68808
+ assert( u.ap.p2<u.ap.nField );
6844068809
6844168810
/* Read and parse the table header. Store the results of the parse
6844268811
** into the record header cache fields of the cursor.
6844368812
*/
68444
- u.ao.aType = u.ao.pC->aType;
68445
- if( u.ao.pC->cacheStatus==p->cacheCtr ){
68446
- u.ao.aOffset = u.ao.pC->aOffset;
68813
+ u.ap.aType = u.ap.pC->aType;
68814
+ if( u.ap.pC->cacheStatus==p->cacheCtr ){
68815
+ u.ap.aOffset = u.ap.pC->aOffset;
6844768816
}else{
68448
- assert(u.ao.aType);
68449
- u.ao.avail = 0;
68450
- u.ao.pC->aOffset = u.ao.aOffset = &u.ao.aType[u.ao.nField];
68451
- u.ao.pC->payloadSize = u.ao.payloadSize;
68452
- u.ao.pC->cacheStatus = p->cacheCtr;
68817
+ assert(u.ap.aType);
68818
+ u.ap.avail = 0;
68819
+ u.ap.pC->aOffset = u.ap.aOffset = &u.ap.aType[u.ap.nField];
68820
+ u.ap.pC->payloadSize = u.ap.payloadSize;
68821
+ u.ap.pC->cacheStatus = p->cacheCtr;
6845368822
6845468823
/* Figure out how many bytes are in the header */
68455
- if( u.ao.zRec ){
68456
- u.ao.zData = u.ao.zRec;
68824
+ if( u.ap.zRec ){
68825
+ u.ap.zData = u.ap.zRec;
6845768826
}else{
68458
- if( u.ao.pC->isIndex ){
68459
- u.ao.zData = (char*)sqlite3BtreeKeyFetch(u.ao.pCrsr, &u.ao.avail);
68827
+ if( u.ap.pC->isIndex ){
68828
+ u.ap.zData = (char*)sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
6846068829
}else{
68461
- u.ao.zData = (char*)sqlite3BtreeDataFetch(u.ao.pCrsr, &u.ao.avail);
68830
+ u.ap.zData = (char*)sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
6846268831
}
6846368832
/* If KeyFetch()/DataFetch() managed to get the entire payload,
68464
- ** save the payload in the u.ao.pC->aRow cache. That will save us from
68833
+ ** save the payload in the u.ap.pC->aRow cache. That will save us from
6846568834
** having to make additional calls to fetch the content portion of
6846668835
** the record.
6846768836
*/
68468
- assert( u.ao.avail>=0 );
68469
- if( u.ao.payloadSize <= (u32)u.ao.avail ){
68470
- u.ao.zRec = u.ao.zData;
68471
- u.ao.pC->aRow = (u8*)u.ao.zData;
68837
+ assert( u.ap.avail>=0 );
68838
+ if( u.ap.payloadSize <= (u32)u.ap.avail ){
68839
+ u.ap.zRec = u.ap.zData;
68840
+ u.ap.pC->aRow = (u8*)u.ap.zData;
6847268841
}else{
68473
- u.ao.pC->aRow = 0;
68842
+ u.ap.pC->aRow = 0;
6847468843
}
6847568844
}
6847668845
/* The following assert is true in all cases except when
6847768846
** the database file has been corrupted externally.
68478
- ** assert( u.ao.zRec!=0 || u.ao.avail>=u.ao.payloadSize || u.ao.avail>=9 ); */
68479
- u.ao.szHdr = getVarint32((u8*)u.ao.zData, u.ao.offset);
68847
+ ** assert( u.ap.zRec!=0 || u.ap.avail>=u.ap.payloadSize || u.ap.avail>=9 ); */
68848
+ u.ap.szHdr = getVarint32((u8*)u.ap.zData, u.ap.offset);
6848068849
6848168850
/* Make sure a corrupt database has not given us an oversize header.
6848268851
** Do this now to avoid an oversize memory allocation.
6848368852
**
6848468853
** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68485,193 +68854,195 @@
6848568854
** types use so much data space that there can only be 4096 and 32 of
6848668855
** them, respectively. So the maximum header length results from a
6848768856
** 3-byte type for each of the maximum of 32768 columns plus three
6848868857
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
6848968858
*/
68490
- if( u.ao.offset > 98307 ){
68859
+ if( u.ap.offset > 98307 ){
6849168860
rc = SQLITE_CORRUPT_BKPT;
6849268861
goto op_column_out;
6849368862
}
6849468863
68495
- /* Compute in u.ao.len the number of bytes of data we need to read in order
68496
- ** to get u.ao.nField type values. u.ao.offset is an upper bound on this. But
68497
- ** u.ao.nField might be significantly less than the true number of columns
68498
- ** in the table, and in that case, 5*u.ao.nField+3 might be smaller than u.ao.offset.
68499
- ** We want to minimize u.ao.len in order to limit the size of the memory
68500
- ** allocation, especially if a corrupt database file has caused u.ao.offset
68864
+ /* Compute in u.ap.len the number of bytes of data we need to read in order
68865
+ ** to get u.ap.nField type values. u.ap.offset is an upper bound on this. But
68866
+ ** u.ap.nField might be significantly less than the true number of columns
68867
+ ** in the table, and in that case, 5*u.ap.nField+3 might be smaller than u.ap.offset.
68868
+ ** We want to minimize u.ap.len in order to limit the size of the memory
68869
+ ** allocation, especially if a corrupt database file has caused u.ap.offset
6850168870
** to be oversized. Offset is limited to 98307 above. But 98307 might
6850268871
** still exceed Robson memory allocation limits on some configurations.
68503
- ** On systems that cannot tolerate large memory allocations, u.ao.nField*5+3
68504
- ** will likely be much smaller since u.ao.nField will likely be less than
68872
+ ** On systems that cannot tolerate large memory allocations, u.ap.nField*5+3
68873
+ ** will likely be much smaller since u.ap.nField will likely be less than
6850568874
** 20 or so. This insures that Robson memory allocation limits are
6850668875
** not exceeded even for corrupt database files.
6850768876
*/
68508
- u.ao.len = u.ao.nField*5 + 3;
68509
- if( u.ao.len > (int)u.ao.offset ) u.ao.len = (int)u.ao.offset;
68877
+ u.ap.len = u.ap.nField*5 + 3;
68878
+ if( u.ap.len > (int)u.ap.offset ) u.ap.len = (int)u.ap.offset;
6851068879
6851168880
/* The KeyFetch() or DataFetch() above are fast and will get the entire
6851268881
** record header in most cases. But they will fail to get the complete
6851368882
** record header if the record header does not fit on a single page
6851468883
** in the B-Tree. When that happens, use sqlite3VdbeMemFromBtree() to
6851568884
** acquire the complete header text.
6851668885
*/
68517
- if( !u.ao.zRec && u.ao.avail<u.ao.len ){
68518
- u.ao.sMem.flags = 0;
68519
- u.ao.sMem.db = 0;
68520
- rc = sqlite3VdbeMemFromBtree(u.ao.pCrsr, 0, u.ao.len, u.ao.pC->isIndex, &u.ao.sMem);
68886
+ if( !u.ap.zRec && u.ap.avail<u.ap.len ){
68887
+ u.ap.sMem.flags = 0;
68888
+ u.ap.sMem.db = 0;
68889
+ rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.len, u.ap.pC->isIndex, &u.ap.sMem);
6852168890
if( rc!=SQLITE_OK ){
6852268891
goto op_column_out;
6852368892
}
68524
- u.ao.zData = u.ao.sMem.z;
68525
- }
68526
- u.ao.zEndHdr = (u8 *)&u.ao.zData[u.ao.len];
68527
- u.ao.zIdx = (u8 *)&u.ao.zData[u.ao.szHdr];
68528
-
68529
- /* Scan the header and use it to fill in the u.ao.aType[] and u.ao.aOffset[]
68530
- ** arrays. u.ao.aType[u.ao.i] will contain the type integer for the u.ao.i-th
68531
- ** column and u.ao.aOffset[u.ao.i] will contain the u.ao.offset from the beginning
68532
- ** of the record to the start of the data for the u.ao.i-th column
68533
- */
68534
- for(u.ao.i=0; u.ao.i<u.ao.nField; u.ao.i++){
68535
- if( u.ao.zIdx<u.ao.zEndHdr ){
68536
- u.ao.aOffset[u.ao.i] = u.ao.offset;
68537
- if( u.ao.zIdx[0]<0x80 ){
68538
- u.ao.t = u.ao.zIdx[0];
68539
- u.ao.zIdx++;
68893
+ u.ap.zData = u.ap.sMem.z;
68894
+ }
68895
+ u.ap.zEndHdr = (u8 *)&u.ap.zData[u.ap.len];
68896
+ u.ap.zIdx = (u8 *)&u.ap.zData[u.ap.szHdr];
68897
+
68898
+ /* Scan the header and use it to fill in the u.ap.aType[] and u.ap.aOffset[]
68899
+ ** arrays. u.ap.aType[u.ap.i] will contain the type integer for the u.ap.i-th
68900
+ ** column and u.ap.aOffset[u.ap.i] will contain the u.ap.offset from the beginning
68901
+ ** of the record to the start of the data for the u.ap.i-th column
68902
+ */
68903
+ for(u.ap.i=0; u.ap.i<u.ap.nField; u.ap.i++){
68904
+ if( u.ap.zIdx<u.ap.zEndHdr ){
68905
+ u.ap.aOffset[u.ap.i] = u.ap.offset;
68906
+ if( u.ap.zIdx[0]<0x80 ){
68907
+ u.ap.t = u.ap.zIdx[0];
68908
+ u.ap.zIdx++;
6854068909
}else{
68541
- u.ao.zIdx += sqlite3GetVarint32(u.ao.zIdx, &u.ao.t);
68910
+ u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t);
6854268911
}
68543
- u.ao.aType[u.ao.i] = u.ao.t;
68544
- u.ao.szField = sqlite3VdbeSerialTypeLen(u.ao.t);
68545
- u.ao.offset += u.ao.szField;
68546
- if( u.ao.offset<u.ao.szField ){ /* True if u.ao.offset overflows */
68547
- u.ao.zIdx = &u.ao.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68912
+ u.ap.aType[u.ap.i] = u.ap.t;
68913
+ u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68914
+ u.ap.offset += u.ap.szField;
68915
+ if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */
68916
+ u.ap.zIdx = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
6854868917
break;
6854968918
}
6855068919
}else{
68551
- /* If u.ao.i is less that u.ao.nField, then there are fewer fields in this
68920
+ /* If u.ap.i is less that u.ap.nField, then there are fewer fields in this
6855268921
** record than SetNumColumns indicated there are columns in the
68553
- ** table. Set the u.ao.offset for any extra columns not present in
68922
+ ** table. Set the u.ap.offset for any extra columns not present in
6855468923
** the record to 0. This tells code below to store the default value
6855568924
** for the column instead of deserializing a value from the record.
6855668925
*/
68557
- u.ao.aOffset[u.ao.i] = 0;
68926
+ u.ap.aOffset[u.ap.i] = 0;
6855868927
}
6855968928
}
68560
- sqlite3VdbeMemRelease(&u.ao.sMem);
68561
- u.ao.sMem.flags = MEM_Null;
68929
+ sqlite3VdbeMemRelease(&u.ap.sMem);
68930
+ u.ap.sMem.flags = MEM_Null;
6856268931
6856368932
/* If we have read more header data than was contained in the header,
6856468933
** or if the end of the last field appears to be past the end of the
6856568934
** record, or if the end of the last field appears to be before the end
6856668935
** of the record (when all fields present), then we must be dealing
6856768936
** with a corrupt database.
6856868937
*/
68569
- if( (u.ao.zIdx > u.ao.zEndHdr) || (u.ao.offset > u.ao.payloadSize)
68570
- || (u.ao.zIdx==u.ao.zEndHdr && u.ao.offset!=u.ao.payloadSize) ){
68938
+ if( (u.ap.zIdx > u.ap.zEndHdr) || (u.ap.offset > u.ap.payloadSize)
68939
+ || (u.ap.zIdx==u.ap.zEndHdr && u.ap.offset!=u.ap.payloadSize) ){
6857168940
rc = SQLITE_CORRUPT_BKPT;
6857268941
goto op_column_out;
6857368942
}
6857468943
}
6857568944
68576
- /* Get the column information. If u.ao.aOffset[u.ao.p2] is non-zero, then
68577
- ** deserialize the value from the record. If u.ao.aOffset[u.ao.p2] is zero,
68945
+ /* Get the column information. If u.ap.aOffset[u.ap.p2] is non-zero, then
68946
+ ** deserialize the value from the record. If u.ap.aOffset[u.ap.p2] is zero,
6857868947
** then there are not enough fields in the record to satisfy the
6857968948
** request. In this case, set the value NULL or to P4 if P4 is
6858068949
** a pointer to a Mem object.
6858168950
*/
68582
- if( u.ao.aOffset[u.ao.p2] ){
68951
+ if( u.ap.aOffset[u.ap.p2] ){
6858368952
assert( rc==SQLITE_OK );
68584
- if( u.ao.zRec ){
68953
+ if( u.ap.zRec ){
6858568954
/* This is the common case where the whole row fits on a single page */
68586
- VdbeMemRelease(u.ao.pDest);
68587
- sqlite3VdbeSerialGet((u8 *)&u.ao.zRec[u.ao.aOffset[u.ao.p2]], u.ao.aType[u.ao.p2], u.ao.pDest);
68955
+ VdbeMemRelease(u.ap.pDest);
68956
+ sqlite3VdbeSerialGet((u8 *)&u.ap.zRec[u.ap.aOffset[u.ap.p2]], u.ap.aType[u.ap.p2], u.ap.pDest);
6858868957
}else{
6858968958
/* This branch happens only when the row overflows onto multiple pages */
68590
- u.ao.t = u.ao.aType[u.ao.p2];
68959
+ u.ap.t = u.ap.aType[u.ap.p2];
6859168960
if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68592
- && ((u.ao.t>=12 && (u.ao.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)
68961
+ && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)
6859368962
){
6859468963
/* Content is irrelevant for the typeof() function and for
6859568964
** the length(X) function if X is a blob. So we might as well use
6859668965
** bogus content rather than reading content from disk. NULL works
68597
- ** for text and blob and whatever is in the u.ao.payloadSize64 variable
68966
+ ** for text and blob and whatever is in the u.ap.payloadSize64 variable
6859868967
** will work for everything else. */
68599
- u.ao.zData = u.ao.t<12 ? (char*)&u.ao.payloadSize64 : 0;
68968
+ u.ap.zData = u.ap.t<12 ? (char*)&u.ap.payloadSize64 : 0;
6860068969
}else{
68601
- u.ao.len = sqlite3VdbeSerialTypeLen(u.ao.t);
68602
- sqlite3VdbeMemMove(&u.ao.sMem, u.ao.pDest);
68603
- rc = sqlite3VdbeMemFromBtree(u.ao.pCrsr, u.ao.aOffset[u.ao.p2], u.ao.len, u.ao.pC->isIndex,
68604
- &u.ao.sMem);
68970
+ u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t);
68971
+ sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
68972
+ rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, u.ap.pC->isIndex,
68973
+ &u.ap.sMem);
6860568974
if( rc!=SQLITE_OK ){
6860668975
goto op_column_out;
6860768976
}
68608
- u.ao.zData = u.ao.sMem.z;
68977
+ u.ap.zData = u.ap.sMem.z;
6860968978
}
68610
- sqlite3VdbeSerialGet((u8*)u.ao.zData, u.ao.t, u.ao.pDest);
68979
+ sqlite3VdbeSerialGet((u8*)u.ap.zData, u.ap.t, u.ap.pDest);
6861168980
}
68612
- u.ao.pDest->enc = encoding;
68981
+ u.ap.pDest->enc = encoding;
6861368982
}else{
6861468983
if( pOp->p4type==P4_MEM ){
68615
- sqlite3VdbeMemShallowCopy(u.ao.pDest, pOp->p4.pMem, MEM_Static);
68984
+ sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
6861668985
}else{
68617
- MemSetTypeFlag(u.ao.pDest, MEM_Null);
68986
+ MemSetTypeFlag(u.ap.pDest, MEM_Null);
6861868987
}
6861968988
}
6862068989
6862168990
/* If we dynamically allocated space to hold the data (in the
6862268991
** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68623
- ** dynamically allocated space over to the u.ao.pDest structure.
68992
+ ** dynamically allocated space over to the u.ap.pDest structure.
6862468993
** This prevents a memory copy.
6862568994
*/
68626
- if( u.ao.sMem.zMalloc ){
68627
- assert( u.ao.sMem.z==u.ao.sMem.zMalloc );
68628
- assert( !(u.ao.pDest->flags & MEM_Dyn) );
68629
- assert( !(u.ao.pDest->flags & (MEM_Blob|MEM_Str)) || u.ao.pDest->z==u.ao.sMem.z );
68630
- u.ao.pDest->flags &= ~(MEM_Ephem|MEM_Static);
68631
- u.ao.pDest->flags |= MEM_Term;
68632
- u.ao.pDest->z = u.ao.sMem.z;
68633
- u.ao.pDest->zMalloc = u.ao.sMem.zMalloc;
68995
+ if( u.ap.sMem.zMalloc ){
68996
+ assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
68997
+ assert( !(u.ap.pDest->flags & MEM_Dyn) );
68998
+ assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
68999
+ u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
69000
+ u.ap.pDest->flags |= MEM_Term;
69001
+ u.ap.pDest->z = u.ap.sMem.z;
69002
+ u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
6863469003
}
6863569004
68636
- rc = sqlite3VdbeMemMakeWriteable(u.ao.pDest);
69005
+ rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
6863769006
6863869007
op_column_out:
68639
- UPDATE_MAX_BLOBSIZE(u.ao.pDest);
68640
- REGISTER_TRACE(pOp->p3, u.ao.pDest);
69008
+ UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69009
+ REGISTER_TRACE(pOp->p3, u.ap.pDest);
6864169010
break;
6864269011
}
6864369012
6864469013
/* Opcode: Affinity P1 P2 * P4 *
69014
+** Synopsis: affinity(r[P1@P2])
6864569015
**
6864669016
** Apply affinities to a range of P2 registers starting with P1.
6864769017
**
6864869018
** P4 is a string that is P2 characters long. The nth character of the
6864969019
** string indicates the column affinity that should be used for the nth
6865069020
** memory cell in the range.
6865169021
*/
6865269022
case OP_Affinity: {
68653
-#if 0 /* local variables moved into u.ap */
69023
+#if 0 /* local variables moved into u.aq */
6865469024
const char *zAffinity; /* The affinity to be applied */
6865569025
char cAff; /* A single character of affinity */
68656
-#endif /* local variables moved into u.ap */
69026
+#endif /* local variables moved into u.aq */
6865769027
68658
- u.ap.zAffinity = pOp->p4.z;
68659
- assert( u.ap.zAffinity!=0 );
68660
- assert( u.ap.zAffinity[pOp->p2]==0 );
69028
+ u.aq.zAffinity = pOp->p4.z;
69029
+ assert( u.aq.zAffinity!=0 );
69030
+ assert( u.aq.zAffinity[pOp->p2]==0 );
6866169031
pIn1 = &aMem[pOp->p1];
68662
- while( (u.ap.cAff = *(u.ap.zAffinity++))!=0 ){
69032
+ while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
6866369033
assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
6866469034
assert( memIsValid(pIn1) );
6866569035
ExpandBlob(pIn1);
68666
- applyAffinity(pIn1, u.ap.cAff, encoding);
69036
+ applyAffinity(pIn1, u.aq.cAff, encoding);
6866769037
pIn1++;
6866869038
}
6866969039
break;
6867069040
}
6867169041
6867269042
/* Opcode: MakeRecord P1 P2 P3 P4 *
69043
+** Synopsis: r[P3]=mkrec(r[P1@P2])
6867369044
**
6867469045
** Convert P2 registers beginning with P1 into the [record format]
6867569046
** use as a data record in a database table or as a key
6867669047
** in an index. The OP_Column opcode can decode the record later.
6867769048
**
@@ -68683,11 +69054,11 @@
6868369054
** macros defined in sqliteInt.h.
6868469055
**
6868569056
** If P4 is NULL then all index fields have the affinity NONE.
6868669057
*/
6868769058
case OP_MakeRecord: {
68688
-#if 0 /* local variables moved into u.aq */
69059
+#if 0 /* local variables moved into u.ar */
6868969060
u8 *zNewRecord; /* A buffer to hold the data for the new record */
6869069061
Mem *pRec; /* The new record */
6869169062
u64 nData; /* Number of bytes of data space */
6869269063
int nHdr; /* Number of bytes of header space */
6869369064
i64 nByte; /* Data space required for this record */
@@ -68699,11 +69070,11 @@
6869969070
int nField; /* Number of fields in the record */
6870069071
char *zAffinity; /* The affinity string for the record */
6870169072
int file_format; /* File format to use for encoding */
6870269073
int i; /* Space used in zNewRecord[] */
6870369074
int len; /* Length of a field */
68704
-#endif /* local variables moved into u.aq */
69075
+#endif /* local variables moved into u.ar */
6870569076
6870669077
/* Assuming the record contains N fields, the record format looks
6870769078
** like this:
6870869079
**
6870969080
** ------------------------------------------------------------------------
@@ -68716,114 +69087,112 @@
6871669087
** Each type field is a varint representing the serial type of the
6871769088
** corresponding data element (see sqlite3VdbeSerialType()). The
6871869089
** hdr-size field is also a varint which is the offset from the beginning
6871969090
** of the record to data0.
6872069091
*/
68721
- u.aq.nData = 0; /* Number of bytes of data space */
68722
- u.aq.nHdr = 0; /* Number of bytes of header space */
68723
- u.aq.nZero = 0; /* Number of zero bytes at the end of the record */
68724
- u.aq.nField = pOp->p1;
68725
- u.aq.zAffinity = pOp->p4.z;
68726
- assert( u.aq.nField>0 && pOp->p2>0 && pOp->p2+u.aq.nField<=(p->nMem-p->nCursor)+1 );
68727
- u.aq.pData0 = &aMem[u.aq.nField];
68728
- u.aq.nField = pOp->p2;
68729
- u.aq.pLast = &u.aq.pData0[u.aq.nField-1];
68730
- u.aq.file_format = p->minWriteFileFormat;
69092
+ u.ar.nData = 0; /* Number of bytes of data space */
69093
+ u.ar.nHdr = 0; /* Number of bytes of header space */
69094
+ u.ar.nZero = 0; /* Number of zero bytes at the end of the record */
69095
+ u.ar.nField = pOp->p1;
69096
+ u.ar.zAffinity = pOp->p4.z;
69097
+ assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 );
69098
+ u.ar.pData0 = &aMem[u.ar.nField];
69099
+ u.ar.nField = pOp->p2;
69100
+ u.ar.pLast = &u.ar.pData0[u.ar.nField-1];
69101
+ u.ar.file_format = p->minWriteFileFormat;
6873169102
6873269103
/* Identify the output register */
6873369104
assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
6873469105
pOut = &aMem[pOp->p3];
6873569106
memAboutToChange(p, pOut);
6873669107
6873769108
/* Loop through the elements that will make up the record to figure
6873869109
** out how much space is required for the new record.
6873969110
*/
68740
- for(u.aq.pRec=u.aq.pData0; u.aq.pRec<=u.aq.pLast; u.aq.pRec++){
68741
- assert( memIsValid(u.aq.pRec) );
68742
- if( u.aq.zAffinity ){
68743
- applyAffinity(u.aq.pRec, u.aq.zAffinity[u.aq.pRec-u.aq.pData0], encoding);
68744
- }
68745
- if( u.aq.pRec->flags&MEM_Zero && u.aq.pRec->n>0 ){
68746
- sqlite3VdbeMemExpandBlob(u.aq.pRec);
68747
- }
68748
- u.aq.serial_type = sqlite3VdbeSerialType(u.aq.pRec, u.aq.file_format);
68749
- u.aq.len = sqlite3VdbeSerialTypeLen(u.aq.serial_type);
68750
- u.aq.nData += u.aq.len;
68751
- u.aq.nHdr += sqlite3VarintLen(u.aq.serial_type);
68752
- if( u.aq.pRec->flags & MEM_Zero ){
69111
+ for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69112
+ assert( memIsValid(u.ar.pRec) );
69113
+ if( u.ar.zAffinity ){
69114
+ applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding);
69115
+ }
69116
+ if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){
69117
+ sqlite3VdbeMemExpandBlob(u.ar.pRec);
69118
+ }
69119
+ u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69120
+ u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type);
69121
+ u.ar.nData += u.ar.len;
69122
+ u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type);
69123
+ if( u.ar.pRec->flags & MEM_Zero ){
6875369124
/* Only pure zero-filled BLOBs can be input to this Opcode.
6875469125
** We do not allow blobs with a prefix and a zero-filled tail. */
68755
- u.aq.nZero += u.aq.pRec->u.nZero;
68756
- }else if( u.aq.len ){
68757
- u.aq.nZero = 0;
69126
+ u.ar.nZero += u.ar.pRec->u.nZero;
69127
+ }else if( u.ar.len ){
69128
+ u.ar.nZero = 0;
6875869129
}
6875969130
}
6876069131
6876169132
/* Add the initial header varint and total the size */
68762
- u.aq.nHdr += u.aq.nVarint = sqlite3VarintLen(u.aq.nHdr);
68763
- if( u.aq.nVarint<sqlite3VarintLen(u.aq.nHdr) ){
68764
- u.aq.nHdr++;
69133
+ u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr);
69134
+ if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){
69135
+ u.ar.nHdr++;
6876569136
}
68766
- u.aq.nByte = u.aq.nHdr+u.aq.nData-u.aq.nZero;
68767
- if( u.aq.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69137
+ u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero;
69138
+ if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6876869139
goto too_big;
6876969140
}
6877069141
6877169142
/* Make sure the output register has a buffer large enough to store
6877269143
** the new record. The output register (pOp->p3) is not allowed to
6877369144
** be one of the input registers (because the following call to
6877469145
** sqlite3VdbeMemGrow() could clobber the value before it is used).
6877569146
*/
68776
- if( sqlite3VdbeMemGrow(pOut, (int)u.aq.nByte, 0) ){
69147
+ if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
6877769148
goto no_mem;
6877869149
}
68779
- u.aq.zNewRecord = (u8 *)pOut->z;
69150
+ u.ar.zNewRecord = (u8 *)pOut->z;
6878069151
6878169152
/* Write the record */
68782
- u.aq.i = putVarint32(u.aq.zNewRecord, u.aq.nHdr);
68783
- for(u.aq.pRec=u.aq.pData0; u.aq.pRec<=u.aq.pLast; u.aq.pRec++){
68784
- u.aq.serial_type = sqlite3VdbeSerialType(u.aq.pRec, u.aq.file_format);
68785
- u.aq.i += putVarint32(&u.aq.zNewRecord[u.aq.i], u.aq.serial_type); /* serial type */
68786
- }
68787
- for(u.aq.pRec=u.aq.pData0; u.aq.pRec<=u.aq.pLast; u.aq.pRec++){ /* serial data */
68788
- u.aq.i += sqlite3VdbeSerialPut(&u.aq.zNewRecord[u.aq.i], (int)(u.aq.nByte-u.aq.i), u.aq.pRec,u.aq.file_format);
68789
- }
68790
- assert( u.aq.i==u.aq.nByte );
69153
+ u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr);
69154
+ for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69155
+ u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69156
+ u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */
69157
+ }
69158
+ for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */
69159
+ u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format);
69160
+ }
69161
+ assert( u.ar.i==u.ar.nByte );
6879169162
6879269163
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68793
- pOut->n = (int)u.aq.nByte;
69164
+ pOut->n = (int)u.ar.nByte;
6879469165
pOut->flags = MEM_Blob | MEM_Dyn;
6879569166
pOut->xDel = 0;
68796
- if( u.aq.nZero ){
68797
- pOut->u.nZero = u.aq.nZero;
69167
+ if( u.ar.nZero ){
69168
+ pOut->u.nZero = u.ar.nZero;
6879869169
pOut->flags |= MEM_Zero;
6879969170
}
6880069171
pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
6880169172
REGISTER_TRACE(pOp->p3, pOut);
6880269173
UPDATE_MAX_BLOBSIZE(pOut);
6880369174
break;
6880469175
}
6880569176
6880669177
/* Opcode: Count P1 P2 * * *
69178
+** Synopsis: r[P2]=count()
6880769179
**
6880869180
** Store the number of entries (an integer value) in the table or index
6880969181
** opened by cursor P1 in register P2
6881069182
*/
6881169183
#ifndef SQLITE_OMIT_BTREECOUNT
6881269184
case OP_Count: { /* out2-prerelease */
68813
-#if 0 /* local variables moved into u.ar */
69185
+#if 0 /* local variables moved into u.as */
6881469186
i64 nEntry;
6881569187
BtCursor *pCrsr;
68816
-#endif /* local variables moved into u.ar */
68817
-
68818
- u.ar.pCrsr = p->apCsr[pOp->p1]->pCursor;
68819
- if( ALWAYS(u.ar.pCrsr) ){
68820
- rc = sqlite3BtreeCount(u.ar.pCrsr, &u.ar.nEntry);
68821
- }else{
68822
- u.ar.nEntry = 0;
68823
- }
68824
- pOut->u.i = u.ar.nEntry;
69188
+#endif /* local variables moved into u.as */
69189
+
69190
+ u.as.pCrsr = p->apCsr[pOp->p1]->pCursor;
69191
+ assert( u.as.pCrsr );
69192
+ rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry);
69193
+ pOut->u.i = u.as.nEntry;
6882569194
break;
6882669195
}
6882769196
#endif
6882869197
6882969198
/* Opcode: Savepoint P1 * * P4 *
@@ -68831,43 +69200,43 @@
6883169200
** Open, release or rollback the savepoint named by parameter P4, depending
6883269201
** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
6883369202
** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
6883469203
*/
6883569204
case OP_Savepoint: {
68836
-#if 0 /* local variables moved into u.as */
69205
+#if 0 /* local variables moved into u.at */
6883769206
int p1; /* Value of P1 operand */
6883869207
char *zName; /* Name of savepoint */
6883969208
int nName;
6884069209
Savepoint *pNew;
6884169210
Savepoint *pSavepoint;
6884269211
Savepoint *pTmp;
6884369212
int iSavepoint;
6884469213
int ii;
68845
-#endif /* local variables moved into u.as */
69214
+#endif /* local variables moved into u.at */
6884669215
68847
- u.as.p1 = pOp->p1;
68848
- u.as.zName = pOp->p4.z;
69216
+ u.at.p1 = pOp->p1;
69217
+ u.at.zName = pOp->p4.z;
6884969218
68850
- /* Assert that the u.as.p1 parameter is valid. Also that if there is no open
69219
+ /* Assert that the u.at.p1 parameter is valid. Also that if there is no open
6885169220
** transaction, then there cannot be any savepoints.
6885269221
*/
6885369222
assert( db->pSavepoint==0 || db->autoCommit==0 );
68854
- assert( u.as.p1==SAVEPOINT_BEGIN||u.as.p1==SAVEPOINT_RELEASE||u.as.p1==SAVEPOINT_ROLLBACK );
69223
+ assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK );
6885569224
assert( db->pSavepoint || db->isTransactionSavepoint==0 );
6885669225
assert( checkSavepointCount(db) );
6885769226
assert( p->bIsReader );
6885869227
68859
- if( u.as.p1==SAVEPOINT_BEGIN ){
69228
+ if( u.at.p1==SAVEPOINT_BEGIN ){
6886069229
if( db->nVdbeWrite>0 ){
6886169230
/* A new savepoint cannot be created if there are active write
6886269231
** statements (i.e. open read/write incremental blob handles).
6886369232
*/
6886469233
sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
6886569234
"SQL statements in progress");
6886669235
rc = SQLITE_BUSY;
6886769236
}else{
68868
- u.as.nName = sqlite3Strlen30(u.as.zName);
69237
+ u.at.nName = sqlite3Strlen30(u.at.zName);
6886969238
6887069239
#ifndef SQLITE_OMIT_VIRTUALTABLE
6887169240
/* This call is Ok even if this savepoint is actually a transaction
6887269241
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
6887369242
** If this is a transaction savepoint being opened, it is guaranteed
@@ -68877,14 +69246,14 @@
6887769246
db->nStatement+db->nSavepoint);
6887869247
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6887969248
#endif
6888069249
6888169250
/* Create a new savepoint structure. */
68882
- u.as.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.as.nName+1);
68883
- if( u.as.pNew ){
68884
- u.as.pNew->zName = (char *)&u.as.pNew[1];
68885
- memcpy(u.as.pNew->zName, u.as.zName, u.as.nName+1);
69251
+ u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1);
69252
+ if( u.at.pNew ){
69253
+ u.at.pNew->zName = (char *)&u.at.pNew[1];
69254
+ memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1);
6888669255
6888769256
/* If there is no open transaction, then mark this as a special
6888869257
** "transaction savepoint". */
6888969258
if( db->autoCommit ){
6889069259
db->autoCommit = 0;
@@ -68892,32 +69261,32 @@
6889269261
}else{
6889369262
db->nSavepoint++;
6889469263
}
6889569264
6889669265
/* Link the new savepoint into the database handle's list. */
68897
- u.as.pNew->pNext = db->pSavepoint;
68898
- db->pSavepoint = u.as.pNew;
68899
- u.as.pNew->nDeferredCons = db->nDeferredCons;
68900
- u.as.pNew->nDeferredImmCons = db->nDeferredImmCons;
69266
+ u.at.pNew->pNext = db->pSavepoint;
69267
+ db->pSavepoint = u.at.pNew;
69268
+ u.at.pNew->nDeferredCons = db->nDeferredCons;
69269
+ u.at.pNew->nDeferredImmCons = db->nDeferredImmCons;
6890169270
}
6890269271
}
6890369272
}else{
68904
- u.as.iSavepoint = 0;
69273
+ u.at.iSavepoint = 0;
6890569274
6890669275
/* Find the named savepoint. If there is no such savepoint, then an
6890769276
** an error is returned to the user. */
6890869277
for(
68909
- u.as.pSavepoint = db->pSavepoint;
68910
- u.as.pSavepoint && sqlite3StrICmp(u.as.pSavepoint->zName, u.as.zName);
68911
- u.as.pSavepoint = u.as.pSavepoint->pNext
69278
+ u.at.pSavepoint = db->pSavepoint;
69279
+ u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName);
69280
+ u.at.pSavepoint = u.at.pSavepoint->pNext
6891269281
){
68913
- u.as.iSavepoint++;
69282
+ u.at.iSavepoint++;
6891469283
}
68915
- if( !u.as.pSavepoint ){
68916
- sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.as.zName);
69284
+ if( !u.at.pSavepoint ){
69285
+ sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName);
6891769286
rc = SQLITE_ERROR;
68918
- }else if( db->nVdbeWrite>0 && u.as.p1==SAVEPOINT_RELEASE ){
69287
+ }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){
6891969288
/* It is not possible to release (commit) a savepoint if there are
6892069289
** active write statements.
6892169290
*/
6892269291
sqlite3SetString(&p->zErrMsg, db,
6892369292
"cannot release savepoint - SQL statements in progress"
@@ -68927,12 +69296,12 @@
6892769296
6892869297
/* Determine whether or not this is a transaction savepoint. If so,
6892969298
** and this is a RELEASE command, then the current transaction
6893069299
** is committed.
6893169300
*/
68932
- int isTransaction = u.as.pSavepoint->pNext==0 && db->isTransactionSavepoint;
68933
- if( isTransaction && u.as.p1==SAVEPOINT_RELEASE ){
69301
+ int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint;
69302
+ if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){
6893469303
if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6893569304
goto vdbe_return;
6893669305
}
6893769306
db->autoCommit = 1;
6893869307
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -68942,56 +69311,56 @@
6894269311
goto vdbe_return;
6894369312
}
6894469313
db->isTransactionSavepoint = 0;
6894569314
rc = p->rc;
6894669315
}else{
68947
- u.as.iSavepoint = db->nSavepoint - u.as.iSavepoint - 1;
68948
- if( u.as.p1==SAVEPOINT_ROLLBACK ){
68949
- for(u.as.ii=0; u.as.ii<db->nDb; u.as.ii++){
68950
- sqlite3BtreeTripAllCursors(db->aDb[u.as.ii].pBt, SQLITE_ABORT);
69316
+ u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1;
69317
+ if( u.at.p1==SAVEPOINT_ROLLBACK ){
69318
+ for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69319
+ sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT);
6895169320
}
6895269321
}
68953
- for(u.as.ii=0; u.as.ii<db->nDb; u.as.ii++){
68954
- rc = sqlite3BtreeSavepoint(db->aDb[u.as.ii].pBt, u.as.p1, u.as.iSavepoint);
69322
+ for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69323
+ rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint);
6895569324
if( rc!=SQLITE_OK ){
6895669325
goto abort_due_to_error;
6895769326
}
6895869327
}
68959
- if( u.as.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
69328
+ if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
6896069329
sqlite3ExpirePreparedStatements(db);
6896169330
sqlite3ResetAllSchemasOfConnection(db);
6896269331
db->flags = (db->flags | SQLITE_InternChanges);
6896369332
}
6896469333
}
6896569334
6896669335
/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
6896769336
** savepoints nested inside of the savepoint being operated on. */
68968
- while( db->pSavepoint!=u.as.pSavepoint ){
68969
- u.as.pTmp = db->pSavepoint;
68970
- db->pSavepoint = u.as.pTmp->pNext;
68971
- sqlite3DbFree(db, u.as.pTmp);
69337
+ while( db->pSavepoint!=u.at.pSavepoint ){
69338
+ u.at.pTmp = db->pSavepoint;
69339
+ db->pSavepoint = u.at.pTmp->pNext;
69340
+ sqlite3DbFree(db, u.at.pTmp);
6897269341
db->nSavepoint--;
6897369342
}
6897469343
6897569344
/* If it is a RELEASE, then destroy the savepoint being operated on
6897669345
** too. If it is a ROLLBACK TO, then set the number of deferred
6897769346
** constraint violations present in the database to the value stored
6897869347
** when the savepoint was created. */
68979
- if( u.as.p1==SAVEPOINT_RELEASE ){
68980
- assert( u.as.pSavepoint==db->pSavepoint );
68981
- db->pSavepoint = u.as.pSavepoint->pNext;
68982
- sqlite3DbFree(db, u.as.pSavepoint);
69348
+ if( u.at.p1==SAVEPOINT_RELEASE ){
69349
+ assert( u.at.pSavepoint==db->pSavepoint );
69350
+ db->pSavepoint = u.at.pSavepoint->pNext;
69351
+ sqlite3DbFree(db, u.at.pSavepoint);
6898369352
if( !isTransaction ){
6898469353
db->nSavepoint--;
6898569354
}
6898669355
}else{
68987
- db->nDeferredCons = u.as.pSavepoint->nDeferredCons;
68988
- db->nDeferredImmCons = u.as.pSavepoint->nDeferredImmCons;
69356
+ db->nDeferredCons = u.at.pSavepoint->nDeferredCons;
69357
+ db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons;
6898969358
}
6899069359
6899169360
if( !isTransaction ){
68992
- rc = sqlite3VtabSavepoint(db, u.as.p1, u.as.iSavepoint);
69361
+ rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
6899369362
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6899469363
}
6899569364
}
6899669365
}
6899769366
@@ -69006,54 +69375,54 @@
6900669375
** there are active writing VMs or active VMs that use shared cache.
6900769376
**
6900869377
** This instruction causes the VM to halt.
6900969378
*/
6901069379
case OP_AutoCommit: {
69011
-#if 0 /* local variables moved into u.at */
69380
+#if 0 /* local variables moved into u.au */
6901269381
int desiredAutoCommit;
6901369382
int iRollback;
6901469383
int turnOnAC;
69015
-#endif /* local variables moved into u.at */
69384
+#endif /* local variables moved into u.au */
6901669385
69017
- u.at.desiredAutoCommit = pOp->p1;
69018
- u.at.iRollback = pOp->p2;
69019
- u.at.turnOnAC = u.at.desiredAutoCommit && !db->autoCommit;
69020
- assert( u.at.desiredAutoCommit==1 || u.at.desiredAutoCommit==0 );
69021
- assert( u.at.desiredAutoCommit==1 || u.at.iRollback==0 );
69386
+ u.au.desiredAutoCommit = pOp->p1;
69387
+ u.au.iRollback = pOp->p2;
69388
+ u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit;
69389
+ assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 );
69390
+ assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 );
6902269391
assert( db->nVdbeActive>0 ); /* At least this one VM is active */
6902369392
assert( p->bIsReader );
6902469393
6902569394
#if 0
69026
- if( u.at.turnOnAC && u.at.iRollback && db->nVdbeActive>1 ){
69395
+ if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
6902769396
/* If this instruction implements a ROLLBACK and other VMs are
6902869397
** still running, and a transaction is active, return an error indicating
6902969398
** that the other VMs must complete first.
6903069399
*/
6903169400
sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
6903269401
"SQL statements in progress");
6903369402
rc = SQLITE_BUSY;
6903469403
}else
6903569404
#endif
69036
- if( u.at.turnOnAC && !u.at.iRollback && db->nVdbeWrite>0 ){
69405
+ if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
6903769406
/* If this instruction implements a COMMIT and other VMs are writing
6903869407
** return an error indicating that the other VMs must complete first.
6903969408
*/
6904069409
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
6904169410
"SQL statements in progress");
6904269411
rc = SQLITE_BUSY;
69043
- }else if( u.at.desiredAutoCommit!=db->autoCommit ){
69044
- if( u.at.iRollback ){
69045
- assert( u.at.desiredAutoCommit==1 );
69412
+ }else if( u.au.desiredAutoCommit!=db->autoCommit ){
69413
+ if( u.au.iRollback ){
69414
+ assert( u.au.desiredAutoCommit==1 );
6904669415
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6904769416
db->autoCommit = 1;
6904869417
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6904969418
goto vdbe_return;
6905069419
}else{
69051
- db->autoCommit = (u8)u.at.desiredAutoCommit;
69420
+ db->autoCommit = (u8)u.au.desiredAutoCommit;
6905269421
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
6905369422
p->pc = pc;
69054
- db->autoCommit = (u8)(1-u.at.desiredAutoCommit);
69423
+ db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
6905569424
p->rc = rc = SQLITE_BUSY;
6905669425
goto vdbe_return;
6905769426
}
6905869427
}
6905969428
assert( db->nStatement==0 );
@@ -69064,12 +69433,12 @@
6906469433
rc = SQLITE_ERROR;
6906569434
}
6906669435
goto vdbe_return;
6906769436
}else{
6906869437
sqlite3SetString(&p->zErrMsg, db,
69069
- (!u.at.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69070
- (u.at.iRollback)?"cannot rollback - no transaction is active":
69438
+ (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69439
+ (u.au.iRollback)?"cannot rollback - no transaction is active":
6907169440
"cannot commit - no transaction is active"));
6907269441
6907369442
rc = SQLITE_ERROR;
6907469443
}
6907569444
break;
@@ -69105,26 +69474,26 @@
6910569474
** will automatically commit when the VDBE halts.
6910669475
**
6910769476
** If P2 is zero, then a read-lock is obtained on the database file.
6910869477
*/
6910969478
case OP_Transaction: {
69110
-#if 0 /* local variables moved into u.au */
69479
+#if 0 /* local variables moved into u.av */
6911169480
Btree *pBt;
69112
-#endif /* local variables moved into u.au */
69481
+#endif /* local variables moved into u.av */
6911369482
6911469483
assert( p->bIsReader );
6911569484
assert( p->readOnly==0 || pOp->p2==0 );
6911669485
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6911769486
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6911869487
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
6911969488
rc = SQLITE_READONLY;
6912069489
goto abort_due_to_error;
6912169490
}
69122
- u.au.pBt = db->aDb[pOp->p1].pBt;
69491
+ u.av.pBt = db->aDb[pOp->p1].pBt;
6912369492
69124
- if( u.au.pBt ){
69125
- rc = sqlite3BtreeBeginTrans(u.au.pBt, pOp->p2);
69493
+ if( u.av.pBt ){
69494
+ rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
6912669495
if( rc==SQLITE_BUSY ){
6912769496
p->pc = pc;
6912869497
p->rc = rc = SQLITE_BUSY;
6912969498
goto vdbe_return;
6913069499
}
@@ -69133,20 +69502,20 @@
6913369502
}
6913469503
6913569504
if( pOp->p2 && p->usesStmtJournal
6913669505
&& (db->autoCommit==0 || db->nVdbeRead>1)
6913769506
){
69138
- assert( sqlite3BtreeIsInTrans(u.au.pBt) );
69507
+ assert( sqlite3BtreeIsInTrans(u.av.pBt) );
6913969508
if( p->iStatement==0 ){
6914069509
assert( db->nStatement>=0 && db->nSavepoint>=0 );
6914169510
db->nStatement++;
6914269511
p->iStatement = db->nSavepoint + db->nStatement;
6914369512
}
6914469513
6914569514
rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
6914669515
if( rc==SQLITE_OK ){
69147
- rc = sqlite3BtreeBeginStmt(u.au.pBt, p->iStatement);
69516
+ rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
6914869517
}
6914969518
6915069519
/* Store the current value of the database handles deferred constraint
6915169520
** counter. If the statement transaction needs to be rolled back,
6915269521
** the value of this counter needs to be restored too. */
@@ -69168,26 +69537,26 @@
6916869537
** There must be a read-lock on the database (either a transaction
6916969538
** must be started or there must be an open cursor) before
6917069539
** executing this instruction.
6917169540
*/
6917269541
case OP_ReadCookie: { /* out2-prerelease */
69173
-#if 0 /* local variables moved into u.av */
69542
+#if 0 /* local variables moved into u.aw */
6917469543
int iMeta;
6917569544
int iDb;
6917669545
int iCookie;
69177
-#endif /* local variables moved into u.av */
69546
+#endif /* local variables moved into u.aw */
6917869547
6917969548
assert( p->bIsReader );
69180
- u.av.iDb = pOp->p1;
69181
- u.av.iCookie = pOp->p3;
69549
+ u.aw.iDb = pOp->p1;
69550
+ u.aw.iCookie = pOp->p3;
6918269551
assert( pOp->p3<SQLITE_N_BTREE_META );
69183
- assert( u.av.iDb>=0 && u.av.iDb<db->nDb );
69184
- assert( db->aDb[u.av.iDb].pBt!=0 );
69185
- assert( (p->btreeMask & (((yDbMask)1)<<u.av.iDb))!=0 );
69552
+ assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
69553
+ assert( db->aDb[u.aw.iDb].pBt!=0 );
69554
+ assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 );
6918669555
69187
- sqlite3BtreeGetMeta(db->aDb[u.av.iDb].pBt, u.av.iCookie, (u32 *)&u.av.iMeta);
69188
- pOut->u.i = u.av.iMeta;
69556
+ sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta);
69557
+ pOut->u.i = u.aw.iMeta;
6918969558
break;
6919069559
}
6919169560
6919269561
/* Opcode: SetCookie P1 P2 P3 * *
6919369562
**
@@ -69198,31 +69567,31 @@
6919869567
** database file used to store temporary tables.
6919969568
**
6920069569
** A transaction must be started before executing this opcode.
6920169570
*/
6920269571
case OP_SetCookie: { /* in3 */
69203
-#if 0 /* local variables moved into u.aw */
69572
+#if 0 /* local variables moved into u.ax */
6920469573
Db *pDb;
69205
-#endif /* local variables moved into u.aw */
69574
+#endif /* local variables moved into u.ax */
6920669575
assert( pOp->p2<SQLITE_N_BTREE_META );
6920769576
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6920869577
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6920969578
assert( p->readOnly==0 );
69210
- u.aw.pDb = &db->aDb[pOp->p1];
69211
- assert( u.aw.pDb->pBt!=0 );
69579
+ u.ax.pDb = &db->aDb[pOp->p1];
69580
+ assert( u.ax.pDb->pBt!=0 );
6921269581
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6921369582
pIn3 = &aMem[pOp->p3];
6921469583
sqlite3VdbeMemIntegerify(pIn3);
6921569584
/* See note about index shifting on OP_ReadCookie */
69216
- rc = sqlite3BtreeUpdateMeta(u.aw.pDb->pBt, pOp->p2, (int)pIn3->u.i);
69585
+ rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i);
6921769586
if( pOp->p2==BTREE_SCHEMA_VERSION ){
6921869587
/* When the schema cookie changes, record the new cookie internally */
69219
- u.aw.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69588
+ u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
6922069589
db->flags |= SQLITE_InternChanges;
6922169590
}else if( pOp->p2==BTREE_FILE_FORMAT ){
6922269591
/* Record changes in the file format */
69223
- u.aw.pDb->pSchema->file_format = (u8)pIn3->u.i;
69592
+ u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i;
6922469593
}
6922569594
if( pOp->p1==1 ){
6922669595
/* Invalidate all prepared statements whenever the TEMP database
6922769596
** schema is changed. Ticket #1644 */
6922869597
sqlite3ExpirePreparedStatements(db);
@@ -69248,28 +69617,28 @@
6924869617
** Either a transaction needs to have been started or an OP_Open needs
6924969618
** to be executed (to establish a read lock) before this opcode is
6925069619
** invoked.
6925169620
*/
6925269621
case OP_VerifyCookie: {
69253
-#if 0 /* local variables moved into u.ax */
69622
+#if 0 /* local variables moved into u.ay */
6925469623
int iMeta;
6925569624
int iGen;
6925669625
Btree *pBt;
69257
-#endif /* local variables moved into u.ax */
69626
+#endif /* local variables moved into u.ay */
6925869627
6925969628
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6926069629
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6926169630
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6926269631
assert( p->bIsReader );
69263
- u.ax.pBt = db->aDb[pOp->p1].pBt;
69264
- if( u.ax.pBt ){
69265
- sqlite3BtreeGetMeta(u.ax.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ax.iMeta);
69266
- u.ax.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69632
+ u.ay.pBt = db->aDb[pOp->p1].pBt;
69633
+ if( u.ay.pBt ){
69634
+ sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta);
69635
+ u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
6926769636
}else{
69268
- u.ax.iGen = u.ax.iMeta = 0;
69637
+ u.ay.iGen = u.ay.iMeta = 0;
6926969638
}
69270
- if( u.ax.iMeta!=pOp->p2 || u.ax.iGen!=pOp->p3 ){
69639
+ if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
6927169640
sqlite3DbFree(db, p->zErrMsg);
6927269641
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
6927369642
/* If the schema-cookie from the database file matches the cookie
6927469643
** stored with the in-memory representation of the schema, do
6927569644
** not reload the schema from the database file.
@@ -69281,11 +69650,11 @@
6928169650
** discard the database schema, as the user code implementing the
6928269651
** v-table would have to be ready for the sqlite3_vtab structure itself
6928369652
** to be invalidated whenever sqlite3_step() is called from within
6928469653
** a v-table method.
6928569654
*/
69286
- if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ax.iMeta ){
69655
+ if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
6928769656
sqlite3ResetOneSchema(db, pOp->p1);
6928869657
}
6928969658
6929069659
p->expired = 1;
6929169660
rc = SQLITE_SCHEMA;
@@ -69292,10 +69661,11 @@
6929269661
}
6929369662
break;
6929469663
}
6929569664
6929669665
/* Opcode: OpenRead P1 P2 P3 P4 P5
69666
+** Synopsis: root=P2 iDb=P3
6929769667
**
6929869668
** Open a read-only cursor for the database table whose root page is
6929969669
** P2 in a database file. The database file is determined by P3.
6930069670
** P3==0 means the main database, P3==1 means the database used for
6930169671
** temporary tables, and P3>1 means used the corresponding attached
@@ -69322,10 +69692,11 @@
6932269692
** value, it is set to the number of columns in the table.
6932369693
**
6932469694
** See also OpenWrite.
6932569695
*/
6932669696
/* Opcode: OpenWrite P1 P2 P3 P4 P5
69697
+** Synopsis: root=P2 iDb=P3
6932769698
**
6932869699
** Open a read/write cursor named P1 on the table or index whose root
6932969700
** page is P2. Or if P5!=0 use the content of register P2 to find the
6933069701
** root page.
6933169702
**
@@ -69342,20 +69713,20 @@
6934269713
**
6934369714
** See also OpenRead.
6934469715
*/
6934569716
case OP_OpenRead:
6934669717
case OP_OpenWrite: {
69347
-#if 0 /* local variables moved into u.ay */
69718
+#if 0 /* local variables moved into u.az */
6934869719
int nField;
6934969720
KeyInfo *pKeyInfo;
6935069721
int p2;
6935169722
int iDb;
6935269723
int wrFlag;
6935369724
Btree *pX;
6935469725
VdbeCursor *pCur;
6935569726
Db *pDb;
69356
-#endif /* local variables moved into u.ay */
69727
+#endif /* local variables moved into u.az */
6935769728
6935869729
assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
6935969730
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
6936069731
assert( p->bIsReader );
6936169732
assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69363,76 +69734,78 @@
6936369734
if( p->expired ){
6936469735
rc = SQLITE_ABORT;
6936569736
break;
6936669737
}
6936769738
69368
- u.ay.nField = 0;
69369
- u.ay.pKeyInfo = 0;
69370
- u.ay.p2 = pOp->p2;
69371
- u.ay.iDb = pOp->p3;
69372
- assert( u.ay.iDb>=0 && u.ay.iDb<db->nDb );
69373
- assert( (p->btreeMask & (((yDbMask)1)<<u.ay.iDb))!=0 );
69374
- u.ay.pDb = &db->aDb[u.ay.iDb];
69375
- u.ay.pX = u.ay.pDb->pBt;
69376
- assert( u.ay.pX!=0 );
69739
+ u.az.nField = 0;
69740
+ u.az.pKeyInfo = 0;
69741
+ u.az.p2 = pOp->p2;
69742
+ u.az.iDb = pOp->p3;
69743
+ assert( u.az.iDb>=0 && u.az.iDb<db->nDb );
69744
+ assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 );
69745
+ u.az.pDb = &db->aDb[u.az.iDb];
69746
+ u.az.pX = u.az.pDb->pBt;
69747
+ assert( u.az.pX!=0 );
6937769748
if( pOp->opcode==OP_OpenWrite ){
69378
- u.ay.wrFlag = 1;
69379
- assert( sqlite3SchemaMutexHeld(db, u.ay.iDb, 0) );
69380
- if( u.ay.pDb->pSchema->file_format < p->minWriteFileFormat ){
69381
- p->minWriteFileFormat = u.ay.pDb->pSchema->file_format;
69749
+ u.az.wrFlag = 1;
69750
+ assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) );
69751
+ if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){
69752
+ p->minWriteFileFormat = u.az.pDb->pSchema->file_format;
6938269753
}
6938369754
}else{
69384
- u.ay.wrFlag = 0;
69755
+ u.az.wrFlag = 0;
6938569756
}
6938669757
if( pOp->p5 & OPFLAG_P2ISREG ){
69387
- assert( u.ay.p2>0 );
69388
- assert( u.ay.p2<=(p->nMem-p->nCursor) );
69389
- pIn2 = &aMem[u.ay.p2];
69758
+ assert( u.az.p2>0 );
69759
+ assert( u.az.p2<=(p->nMem-p->nCursor) );
69760
+ pIn2 = &aMem[u.az.p2];
6939069761
assert( memIsValid(pIn2) );
6939169762
assert( (pIn2->flags & MEM_Int)!=0 );
6939269763
sqlite3VdbeMemIntegerify(pIn2);
69393
- u.ay.p2 = (int)pIn2->u.i;
69394
- /* The u.ay.p2 value always comes from a prior OP_CreateTable opcode and
69395
- ** that opcode will always set the u.ay.p2 value to 2 or more or else fail.
69764
+ u.az.p2 = (int)pIn2->u.i;
69765
+ /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and
69766
+ ** that opcode will always set the u.az.p2 value to 2 or more or else fail.
6939669767
** If there were a failure, the prepared statement would have halted
6939769768
** before reaching this instruction. */
69398
- if( NEVER(u.ay.p2<2) ) {
69769
+ if( NEVER(u.az.p2<2) ) {
6939969770
rc = SQLITE_CORRUPT_BKPT;
6940069771
goto abort_due_to_error;
6940169772
}
6940269773
}
6940369774
if( pOp->p4type==P4_KEYINFO ){
69404
- u.ay.pKeyInfo = pOp->p4.pKeyInfo;
69405
- u.ay.pKeyInfo->enc = ENC(p->db);
69406
- u.ay.nField = u.ay.pKeyInfo->nField+1;
69775
+ u.az.pKeyInfo = pOp->p4.pKeyInfo;
69776
+ assert( u.az.pKeyInfo->enc==ENC(db) );
69777
+ assert( u.az.pKeyInfo->db==db );
69778
+ u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
6940769779
}else if( pOp->p4type==P4_INT32 ){
69408
- u.ay.nField = pOp->p4.i;
69780
+ u.az.nField = pOp->p4.i;
6940969781
}
6941069782
assert( pOp->p1>=0 );
69411
- u.ay.pCur = allocateCursor(p, pOp->p1, u.ay.nField, u.ay.iDb, 1);
69412
- if( u.ay.pCur==0 ) goto no_mem;
69413
- u.ay.pCur->nullRow = 1;
69414
- u.ay.pCur->isOrdered = 1;
69415
- rc = sqlite3BtreeCursor(u.ay.pX, u.ay.p2, u.ay.wrFlag, u.ay.pKeyInfo, u.ay.pCur->pCursor);
69416
- u.ay.pCur->pKeyInfo = u.ay.pKeyInfo;
69783
+ u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69784
+ if( u.az.pCur==0 ) goto no_mem;
69785
+ u.az.pCur->nullRow = 1;
69786
+ u.az.pCur->isOrdered = 1;
69787
+ rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
69788
+ u.az.pCur->pKeyInfo = u.az.pKeyInfo;
6941769789
assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69418
- sqlite3BtreeCursorHints(u.ay.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69790
+ sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
6941969791
6942069792
/* Since it performs no memory allocation or IO, the only value that
6942169793
** sqlite3BtreeCursor() may return is SQLITE_OK. */
6942269794
assert( rc==SQLITE_OK );
6942369795
6942469796
/* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
6942569797
** SQLite used to check if the root-page flags were sane at this point
6942669798
** and report database corruption if they were not, but this check has
6942769799
** since moved into the btree layer. */
69428
- u.ay.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69429
- u.ay.pCur->isIndex = !u.ay.pCur->isTable;
69800
+ u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69801
+ u.az.pCur->isIndex = !u.az.pCur->isTable;
6943069802
break;
6943169803
}
6943269804
6943369805
/* Opcode: OpenEphemeral P1 P2 * P4 P5
69806
+** Synopsis: nColumn=P2
6943469807
**
6943569808
** Open a new cursor P1 to a transient table.
6943669809
** The cursor is always opened read/write even if
6943769810
** the main database is read-only. The ephemeral
6943869811
** table is deleted automatically when the cursor is closed.
@@ -69440,98 +69813,96 @@
6944069813
** P2 is the number of columns in the ephemeral table.
6944169814
** The cursor points to a BTree table if P4==0 and to a BTree index
6944269815
** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
6944369816
** that defines the format of keys in the index.
6944469817
**
69445
-** This opcode was once called OpenTemp. But that created
69446
-** confusion because the term "temp table", might refer either
69447
-** to a TEMP table at the SQL level, or to a table opened by
69448
-** this opcode. Then this opcode was call OpenVirtual. But
69449
-** that created confusion with the whole virtual-table idea.
69450
-**
6945169818
** The P5 parameter can be a mask of the BTREE_* flags defined
6945269819
** in btree.h. These flags control aspects of the operation of
6945369820
** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
6945469821
** added automatically.
6945569822
*/
6945669823
/* Opcode: OpenAutoindex P1 P2 * P4 *
69824
+** Synopsis: nColumn=P2
6945769825
**
6945869826
** This opcode works the same as OP_OpenEphemeral. It has a
6945969827
** different name to distinguish its use. Tables created using
6946069828
** by this opcode will be used for automatically created transient
6946169829
** indices in joins.
6946269830
*/
6946369831
case OP_OpenAutoindex:
6946469832
case OP_OpenEphemeral: {
69465
-#if 0 /* local variables moved into u.az */
69833
+#if 0 /* local variables moved into u.ba */
6946669834
VdbeCursor *pCx;
69467
-#endif /* local variables moved into u.az */
69835
+ KeyInfo *pKeyInfo;
69836
+#endif /* local variables moved into u.ba */
69837
+
6946869838
static const int vfsFlags =
6946969839
SQLITE_OPEN_READWRITE |
6947069840
SQLITE_OPEN_CREATE |
6947169841
SQLITE_OPEN_EXCLUSIVE |
6947269842
SQLITE_OPEN_DELETEONCLOSE |
6947369843
SQLITE_OPEN_TRANSIENT_DB;
69474
-
6947569844
assert( pOp->p1>=0 );
69476
- u.az.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69477
- if( u.az.pCx==0 ) goto no_mem;
69478
- u.az.pCx->nullRow = 1;
69479
- rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.az.pCx->pBt,
69845
+ u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69846
+ if( u.ba.pCx==0 ) goto no_mem;
69847
+ u.ba.pCx->nullRow = 1;
69848
+ rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
6948069849
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
6948169850
if( rc==SQLITE_OK ){
69482
- rc = sqlite3BtreeBeginTrans(u.az.pCx->pBt, 1);
69851
+ rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
6948369852
}
6948469853
if( rc==SQLITE_OK ){
6948569854
/* If a transient index is required, create it by calling
6948669855
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
6948769856
** opening it. If a transient table is required, just use the
6948869857
** automatically created table with root-page 1 (an BLOB_INTKEY table).
6948969858
*/
69490
- if( pOp->p4.pKeyInfo ){
69859
+ if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
6949169860
int pgno;
6949269861
assert( pOp->p4type==P4_KEYINFO );
69493
- rc = sqlite3BtreeCreateTable(u.az.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69862
+ rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
6949469863
if( rc==SQLITE_OK ){
6949569864
assert( pgno==MASTER_ROOT+1 );
69496
- rc = sqlite3BtreeCursor(u.az.pCx->pBt, pgno, 1,
69497
- (KeyInfo*)pOp->p4.z, u.az.pCx->pCursor);
69498
- u.az.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69499
- u.az.pCx->pKeyInfo->enc = ENC(p->db);
69500
- }
69501
- u.az.pCx->isTable = 0;
69502
- }else{
69503
- rc = sqlite3BtreeCursor(u.az.pCx->pBt, MASTER_ROOT, 1, 0, u.az.pCx->pCursor);
69504
- u.az.pCx->isTable = 1;
69865
+ assert( u.ba.pKeyInfo->db==db );
69866
+ assert( u.ba.pKeyInfo->enc==ENC(db) );
69867
+ u.ba.pCx->pKeyInfo = u.ba.pKeyInfo;
69868
+ rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor);
69869
+ }
69870
+ u.ba.pCx->isTable = 0;
69871
+ }else{
69872
+ rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69873
+ u.ba.pCx->isTable = 1;
6950569874
}
6950669875
}
69507
- u.az.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69508
- u.az.pCx->isIndex = !u.az.pCx->isTable;
69876
+ u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69877
+ u.ba.pCx->isIndex = !u.ba.pCx->isTable;
6950969878
break;
6951069879
}
6951169880
69512
-/* Opcode: SorterOpen P1 P2 * P4 *
69881
+/* Opcode: SorterOpen P1 * * P4 *
6951369882
**
6951469883
** This opcode works like OP_OpenEphemeral except that it opens
6951569884
** a transient index that is specifically designed to sort large
6951669885
** tables using an external merge-sort algorithm.
6951769886
*/
6951869887
case OP_SorterOpen: {
69519
-#if 0 /* local variables moved into u.ba */
69888
+#if 0 /* local variables moved into u.bb */
6952069889
VdbeCursor *pCx;
69521
-#endif /* local variables moved into u.ba */
69522
-
69523
- u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69524
- if( u.ba.pCx==0 ) goto no_mem;
69525
- u.ba.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69526
- u.ba.pCx->pKeyInfo->enc = ENC(p->db);
69527
- u.ba.pCx->isSorter = 1;
69528
- rc = sqlite3VdbeSorterInit(db, u.ba.pCx);
69890
+#endif /* local variables moved into u.bb */
69891
+
69892
+ u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69893
+ if( u.bb.pCx==0 ) goto no_mem;
69894
+ u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69895
+ assert( u.bb.pCx->pKeyInfo->db==db );
69896
+ assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69897
+ u.bb.pCx->isSorter = 1;
69898
+ rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
6952969899
break;
6953069900
}
6953169901
6953269902
/* Opcode: OpenPseudo P1 P2 P3 * P5
69903
+** Synopsis: content in r[P2@P3]
6953369904
**
6953469905
** Open a new cursor that points to a fake table that contains a single
6953569906
** row of data. The content of that one row in the content of memory
6953669907
** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
6953769908
** MEM_Blob content contained in register P2. When P5==1, then the
@@ -69544,22 +69915,22 @@
6954469915
**
6954569916
** P3 is the number of fields in the records that will be stored by
6954669917
** the pseudo-table.
6954769918
*/
6954869919
case OP_OpenPseudo: {
69549
-#if 0 /* local variables moved into u.bb */
69920
+#if 0 /* local variables moved into u.bc */
6955069921
VdbeCursor *pCx;
69551
-#endif /* local variables moved into u.bb */
69922
+#endif /* local variables moved into u.bc */
6955269923
6955369924
assert( pOp->p1>=0 );
69554
- u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69555
- if( u.bb.pCx==0 ) goto no_mem;
69556
- u.bb.pCx->nullRow = 1;
69557
- u.bb.pCx->pseudoTableReg = pOp->p2;
69558
- u.bb.pCx->isTable = 1;
69559
- u.bb.pCx->isIndex = 0;
69560
- u.bb.pCx->multiPseudo = pOp->p5;
69925
+ u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69926
+ if( u.bc.pCx==0 ) goto no_mem;
69927
+ u.bc.pCx->nullRow = 1;
69928
+ u.bc.pCx->pseudoTableReg = pOp->p2;
69929
+ u.bc.pCx->isTable = 1;
69930
+ u.bc.pCx->isIndex = 0;
69931
+ u.bc.pCx->multiPseudo = pOp->p5;
6956169932
break;
6956269933
}
6956369934
6956469935
/* Opcode: Close P1 * * * *
6956569936
**
@@ -69572,10 +69943,11 @@
6957269943
p->apCsr[pOp->p1] = 0;
6957369944
break;
6957469945
}
6957569946
6957669947
/* Opcode: SeekGe P1 P2 P3 P4 *
69948
+** Synopsis: key=r[P3@P4]
6957769949
**
6957869950
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
6957969951
** use the value in register P3 as the key. If cursor P1 refers
6958069952
** to an SQL index, then P3 is the first in an array of P4 registers
6958169953
** that are used as an unpacked index key.
@@ -69585,10 +69957,11 @@
6958569957
** greater than or equal to the key and P2 is not zero, then jump to P2.
6958669958
**
6958769959
** See also: Found, NotFound, Distinct, SeekLt, SeekGt, SeekLe
6958869960
*/
6958969961
/* Opcode: SeekGt P1 P2 P3 P4 *
69962
+** Synopsis: key=r[P3@P4]
6959069963
**
6959169964
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
6959269965
** use the value in register P3 as a key. If cursor P1 refers
6959369966
** to an SQL index, then P3 is the first in an array of P4 registers
6959469967
** that are used as an unpacked index key.
@@ -69598,10 +69971,11 @@
6959869971
** the key and P2 is not zero, then jump to P2.
6959969972
**
6960069973
** See also: Found, NotFound, Distinct, SeekLt, SeekGe, SeekLe
6960169974
*/
6960269975
/* Opcode: SeekLt P1 P2 P3 P4 *
69976
+** Synopsis: key=r[P3@P4]
6960369977
**
6960469978
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
6960569979
** use the value in register P3 as a key. If cursor P1 refers
6960669980
** to an SQL index, then P3 is the first in an array of P4 registers
6960769981
** that are used as an unpacked index key.
@@ -69611,10 +69985,11 @@
6961169985
** the key and P2 is not zero, then jump to P2.
6961269986
**
6961369987
** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLe
6961469988
*/
6961569989
/* Opcode: SeekLe P1 P2 P3 P4 *
69990
+** Synopsis: key=r[P3@P4]
6961669991
**
6961769992
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
6961869993
** use the value in register P3 as a key. If cursor P1 refers
6961969994
** to an SQL index, then P3 is the first in an array of P4 registers
6962069995
** that are used as an unpacked index key.
@@ -69627,200 +70002,197 @@
6962770002
*/
6962870003
case OP_SeekLt: /* jump, in3 */
6962970004
case OP_SeekLe: /* jump, in3 */
6963070005
case OP_SeekGe: /* jump, in3 */
6963170006
case OP_SeekGt: { /* jump, in3 */
69632
-#if 0 /* local variables moved into u.bc */
70007
+#if 0 /* local variables moved into u.bd */
6963370008
int res;
6963470009
int oc;
6963570010
VdbeCursor *pC;
6963670011
UnpackedRecord r;
6963770012
int nField;
6963870013
i64 iKey; /* The rowid we are to seek to */
69639
-#endif /* local variables moved into u.bc */
70014
+#endif /* local variables moved into u.bd */
6964070015
6964170016
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6964270017
assert( pOp->p2!=0 );
69643
- u.bc.pC = p->apCsr[pOp->p1];
69644
- assert( u.bc.pC!=0 );
69645
- assert( u.bc.pC->pseudoTableReg==0 );
70018
+ u.bd.pC = p->apCsr[pOp->p1];
70019
+ assert( u.bd.pC!=0 );
70020
+ assert( u.bd.pC->pseudoTableReg==0 );
6964670021
assert( OP_SeekLe == OP_SeekLt+1 );
6964770022
assert( OP_SeekGe == OP_SeekLt+2 );
6964870023
assert( OP_SeekGt == OP_SeekLt+3 );
69649
- assert( u.bc.pC->isOrdered );
69650
- if( ALWAYS(u.bc.pC->pCursor!=0) ){
69651
- u.bc.oc = pOp->opcode;
69652
- u.bc.pC->nullRow = 0;
69653
- if( u.bc.pC->isTable ){
69654
- /* The input value in P3 might be of any type: integer, real, string,
69655
- ** blob, or NULL. But it needs to be an integer before we can do
69656
- ** the seek, so covert it. */
69657
- pIn3 = &aMem[pOp->p3];
69658
- applyNumericAffinity(pIn3);
69659
- u.bc.iKey = sqlite3VdbeIntValue(pIn3);
69660
- u.bc.pC->rowidIsValid = 0;
69661
-
69662
- /* If the P3 value could not be converted into an integer without
69663
- ** loss of information, then special processing is required... */
69664
- if( (pIn3->flags & MEM_Int)==0 ){
69665
- if( (pIn3->flags & MEM_Real)==0 ){
69666
- /* If the P3 value cannot be converted into any kind of a number,
69667
- ** then the seek is not possible, so jump to P2 */
69668
- pc = pOp->p2 - 1;
69669
- break;
69670
- }
69671
- /* If we reach this point, then the P3 value must be a floating
69672
- ** point number. */
69673
- assert( (pIn3->flags & MEM_Real)!=0 );
69674
-
69675
- if( u.bc.iKey==SMALLEST_INT64 && (pIn3->r<(double)u.bc.iKey || pIn3->r>0) ){
69676
- /* The P3 value is too large in magnitude to be expressed as an
69677
- ** integer. */
69678
- u.bc.res = 1;
69679
- if( pIn3->r<0 ){
69680
- if( u.bc.oc>=OP_SeekGe ){ assert( u.bc.oc==OP_SeekGe || u.bc.oc==OP_SeekGt );
69681
- rc = sqlite3BtreeFirst(u.bc.pC->pCursor, &u.bc.res);
69682
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
69683
- }
69684
- }else{
69685
- if( u.bc.oc<=OP_SeekLe ){ assert( u.bc.oc==OP_SeekLt || u.bc.oc==OP_SeekLe );
69686
- rc = sqlite3BtreeLast(u.bc.pC->pCursor, &u.bc.res);
69687
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
69688
- }
69689
- }
69690
- if( u.bc.res ){
69691
- pc = pOp->p2 - 1;
69692
- }
69693
- break;
69694
- }else if( u.bc.oc==OP_SeekLt || u.bc.oc==OP_SeekGe ){
69695
- /* Use the ceiling() function to convert real->int */
69696
- if( pIn3->r > (double)u.bc.iKey ) u.bc.iKey++;
69697
- }else{
69698
- /* Use the floor() function to convert real->int */
69699
- assert( u.bc.oc==OP_SeekLe || u.bc.oc==OP_SeekGt );
69700
- if( pIn3->r < (double)u.bc.iKey ) u.bc.iKey--;
69701
- }
69702
- }
69703
- rc = sqlite3BtreeMovetoUnpacked(u.bc.pC->pCursor, 0, (u64)u.bc.iKey, 0, &u.bc.res);
69704
- if( rc!=SQLITE_OK ){
69705
- goto abort_due_to_error;
69706
- }
69707
- if( u.bc.res==0 ){
69708
- u.bc.pC->rowidIsValid = 1;
69709
- u.bc.pC->lastRowid = u.bc.iKey;
69710
- }
69711
- }else{
69712
- u.bc.nField = pOp->p4.i;
69713
- assert( pOp->p4type==P4_INT32 );
69714
- assert( u.bc.nField>0 );
69715
- u.bc.r.pKeyInfo = u.bc.pC->pKeyInfo;
69716
- u.bc.r.nField = (u16)u.bc.nField;
69717
-
69718
- /* The next line of code computes as follows, only faster:
69719
- ** if( u.bc.oc==OP_SeekGt || u.bc.oc==OP_SeekLe ){
69720
- ** u.bc.r.flags = UNPACKED_INCRKEY;
69721
- ** }else{
69722
- ** u.bc.r.flags = 0;
69723
- ** }
69724
- */
69725
- u.bc.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bc.oc - OP_SeekLt)));
69726
- assert( u.bc.oc!=OP_SeekGt || u.bc.r.flags==UNPACKED_INCRKEY );
69727
- assert( u.bc.oc!=OP_SeekLe || u.bc.r.flags==UNPACKED_INCRKEY );
69728
- assert( u.bc.oc!=OP_SeekGe || u.bc.r.flags==0 );
69729
- assert( u.bc.oc!=OP_SeekLt || u.bc.r.flags==0 );
69730
-
69731
- u.bc.r.aMem = &aMem[pOp->p3];
69732
-#ifdef SQLITE_DEBUG
69733
- { int i; for(i=0; i<u.bc.r.nField; i++) assert( memIsValid(&u.bc.r.aMem[i]) ); }
69734
-#endif
69735
- ExpandBlob(u.bc.r.aMem);
69736
- rc = sqlite3BtreeMovetoUnpacked(u.bc.pC->pCursor, &u.bc.r, 0, 0, &u.bc.res);
69737
- if( rc!=SQLITE_OK ){
69738
- goto abort_due_to_error;
69739
- }
69740
- u.bc.pC->rowidIsValid = 0;
69741
- }
69742
- u.bc.pC->deferredMoveto = 0;
69743
- u.bc.pC->cacheStatus = CACHE_STALE;
69744
-#ifdef SQLITE_TEST
69745
- sqlite3_search_count++;
69746
-#endif
69747
- if( u.bc.oc>=OP_SeekGe ){ assert( u.bc.oc==OP_SeekGe || u.bc.oc==OP_SeekGt );
69748
- if( u.bc.res<0 || (u.bc.res==0 && u.bc.oc==OP_SeekGt) ){
69749
- rc = sqlite3BtreeNext(u.bc.pC->pCursor, &u.bc.res);
69750
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
69751
- u.bc.pC->rowidIsValid = 0;
69752
- }else{
69753
- u.bc.res = 0;
69754
- }
69755
- }else{
69756
- assert( u.bc.oc==OP_SeekLt || u.bc.oc==OP_SeekLe );
69757
- if( u.bc.res>0 || (u.bc.res==0 && u.bc.oc==OP_SeekLt) ){
69758
- rc = sqlite3BtreePrevious(u.bc.pC->pCursor, &u.bc.res);
69759
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
69760
- u.bc.pC->rowidIsValid = 0;
69761
- }else{
69762
- /* u.bc.res might be negative because the table is empty. Check to
69763
- ** see if this is the case.
69764
- */
69765
- u.bc.res = sqlite3BtreeEof(u.bc.pC->pCursor);
69766
- }
69767
- }
69768
- assert( pOp->p2>0 );
69769
- if( u.bc.res ){
69770
- pc = pOp->p2 - 1;
69771
- }
69772
- }else{
69773
- /* This happens when attempting to open the sqlite3_master table
69774
- ** for read access returns SQLITE_EMPTY. In this case always
69775
- ** take the jump (since there are no records in the table).
69776
- */
70024
+ assert( u.bd.pC->isOrdered );
70025
+ assert( u.bd.pC->pCursor!=0 );
70026
+ u.bd.oc = pOp->opcode;
70027
+ u.bd.pC->nullRow = 0;
70028
+ if( u.bd.pC->isTable ){
70029
+ /* The input value in P3 might be of any type: integer, real, string,
70030
+ ** blob, or NULL. But it needs to be an integer before we can do
70031
+ ** the seek, so covert it. */
70032
+ pIn3 = &aMem[pOp->p3];
70033
+ applyNumericAffinity(pIn3);
70034
+ u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70035
+ u.bd.pC->rowidIsValid = 0;
70036
+
70037
+ /* If the P3 value could not be converted into an integer without
70038
+ ** loss of information, then special processing is required... */
70039
+ if( (pIn3->flags & MEM_Int)==0 ){
70040
+ if( (pIn3->flags & MEM_Real)==0 ){
70041
+ /* If the P3 value cannot be converted into any kind of a number,
70042
+ ** then the seek is not possible, so jump to P2 */
70043
+ pc = pOp->p2 - 1;
70044
+ break;
70045
+ }
70046
+ /* If we reach this point, then the P3 value must be a floating
70047
+ ** point number. */
70048
+ assert( (pIn3->flags & MEM_Real)!=0 );
70049
+
70050
+ if( u.bd.iKey==SMALLEST_INT64 && (pIn3->r<(double)u.bd.iKey || pIn3->r>0) ){
70051
+ /* The P3 value is too large in magnitude to be expressed as an
70052
+ ** integer. */
70053
+ u.bd.res = 1;
70054
+ if( pIn3->r<0 ){
70055
+ if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70056
+ rc = sqlite3BtreeFirst(u.bd.pC->pCursor, &u.bd.res);
70057
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
70058
+ }
70059
+ }else{
70060
+ if( u.bd.oc<=OP_SeekLe ){ assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70061
+ rc = sqlite3BtreeLast(u.bd.pC->pCursor, &u.bd.res);
70062
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
70063
+ }
70064
+ }
70065
+ if( u.bd.res ){
70066
+ pc = pOp->p2 - 1;
70067
+ }
70068
+ break;
70069
+ }else if( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekGe ){
70070
+ /* Use the ceiling() function to convert real->int */
70071
+ if( pIn3->r > (double)u.bd.iKey ) u.bd.iKey++;
70072
+ }else{
70073
+ /* Use the floor() function to convert real->int */
70074
+ assert( u.bd.oc==OP_SeekLe || u.bd.oc==OP_SeekGt );
70075
+ if( pIn3->r < (double)u.bd.iKey ) u.bd.iKey--;
70076
+ }
70077
+ }
70078
+ rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res);
70079
+ if( rc!=SQLITE_OK ){
70080
+ goto abort_due_to_error;
70081
+ }
70082
+ if( u.bd.res==0 ){
70083
+ u.bd.pC->rowidIsValid = 1;
70084
+ u.bd.pC->lastRowid = u.bd.iKey;
70085
+ }
70086
+ }else{
70087
+ u.bd.nField = pOp->p4.i;
70088
+ assert( pOp->p4type==P4_INT32 );
70089
+ assert( u.bd.nField>0 );
70090
+ u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo;
70091
+ u.bd.r.nField = (u16)u.bd.nField;
70092
+
70093
+ /* The next line of code computes as follows, only faster:
70094
+ ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){
70095
+ ** u.bd.r.flags = UNPACKED_INCRKEY;
70096
+ ** }else{
70097
+ ** u.bd.r.flags = 0;
70098
+ ** }
70099
+ */
70100
+ u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt)));
70101
+ assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY );
70102
+ assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY );
70103
+ assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 );
70104
+ assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 );
70105
+
70106
+ u.bd.r.aMem = &aMem[pOp->p3];
70107
+#ifdef SQLITE_DEBUG
70108
+ { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); }
70109
+#endif
70110
+ ExpandBlob(u.bd.r.aMem);
70111
+ rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res);
70112
+ if( rc!=SQLITE_OK ){
70113
+ goto abort_due_to_error;
70114
+ }
70115
+ u.bd.pC->rowidIsValid = 0;
70116
+ }
70117
+ u.bd.pC->deferredMoveto = 0;
70118
+ u.bd.pC->cacheStatus = CACHE_STALE;
70119
+#ifdef SQLITE_TEST
70120
+ sqlite3_search_count++;
70121
+#endif
70122
+ if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70123
+ if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){
70124
+ rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res);
70125
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
70126
+ u.bd.pC->rowidIsValid = 0;
70127
+ }else{
70128
+ u.bd.res = 0;
70129
+ }
70130
+ }else{
70131
+ assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70132
+ if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){
70133
+ rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res);
70134
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
70135
+ u.bd.pC->rowidIsValid = 0;
70136
+ }else{
70137
+ /* u.bd.res might be negative because the table is empty. Check to
70138
+ ** see if this is the case.
70139
+ */
70140
+ u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor);
70141
+ }
70142
+ }
70143
+ assert( pOp->p2>0 );
70144
+ if( u.bd.res ){
6977770145
pc = pOp->p2 - 1;
6977870146
}
6977970147
break;
6978070148
}
6978170149
6978270150
/* Opcode: Seek P1 P2 * * *
70151
+** Synopsis: intkey=r[P2]
6978370152
**
6978470153
** P1 is an open table cursor and P2 is a rowid integer. Arrange
6978570154
** for P1 to move so that it points to the rowid given by P2.
6978670155
**
6978770156
** This is actually a deferred seek. Nothing actually happens until
6978870157
** the cursor is used to read a record. That way, if no reads
6978970158
** occur, no unnecessary I/O happens.
6979070159
*/
6979170160
case OP_Seek: { /* in2 */
69792
-#if 0 /* local variables moved into u.bd */
70161
+#if 0 /* local variables moved into u.be */
6979370162
VdbeCursor *pC;
69794
-#endif /* local variables moved into u.bd */
70163
+#endif /* local variables moved into u.be */
6979570164
6979670165
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69797
- u.bd.pC = p->apCsr[pOp->p1];
69798
- assert( u.bd.pC!=0 );
69799
- if( ALWAYS(u.bd.pC->pCursor!=0) ){
69800
- assert( u.bd.pC->isTable );
69801
- u.bd.pC->nullRow = 0;
69802
- pIn2 = &aMem[pOp->p2];
69803
- u.bd.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
69804
- u.bd.pC->rowidIsValid = 0;
69805
- u.bd.pC->deferredMoveto = 1;
69806
- }
70166
+ u.be.pC = p->apCsr[pOp->p1];
70167
+ assert( u.be.pC!=0 );
70168
+ assert( u.be.pC->pCursor!=0 );
70169
+ assert( u.be.pC->isTable );
70170
+ u.be.pC->nullRow = 0;
70171
+ pIn2 = &aMem[pOp->p2];
70172
+ u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
70173
+ u.be.pC->rowidIsValid = 0;
70174
+ u.be.pC->deferredMoveto = 1;
6980770175
break;
6980870176
}
6980970177
6981070178
6981170179
/* Opcode: Found P1 P2 P3 P4 *
70180
+** Synopsis: key=r[P3@P4]
6981270181
**
6981370182
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
6981470183
** P4>0 then register P3 is the first of P4 registers that form an unpacked
6981570184
** record.
6981670185
**
6981770186
** Cursor P1 is on an index btree. If the record identified by P3 and P4
6981870187
** is a prefix of any entry in P1 then a jump is made to P2 and
6981970188
** P1 is left pointing at the matching entry.
70189
+**
70190
+** See also: NotFound, NoConflict, NotExists. SeekGe
6982070191
*/
6982170192
/* Opcode: NotFound P1 P2 P3 P4 *
70193
+** Synopsis: key=r[P3@P4]
6982270194
**
6982370195
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
6982470196
** P4>0 then register P3 is the first of P4 registers that form an unpacked
6982570197
** record.
6982670198
**
@@ -69828,177 +70200,126 @@
6982870200
** is not the prefix of any entry in P1 then a jump is made to P2. If P1
6982970201
** does contain an entry whose prefix matches the P3/P4 record then control
6983070202
** falls through to the next instruction and P1 is left pointing at the
6983170203
** matching entry.
6983270204
**
69833
-** See also: Found, NotExists, IsUnique
70205
+** See also: Found, NotExists, NoConflict
6983470206
*/
70207
+/* Opcode: NoConflict P1 P2 P3 P4 *
70208
+** Synopsis: key=r[P3@P4]
70209
+**
70210
+** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
70211
+** P4>0 then register P3 is the first of P4 registers that form an unpacked
70212
+** record.
70213
+**
70214
+** Cursor P1 is on an index btree. If the record identified by P3 and P4
70215
+** contains any NULL value, jump immediately to P2. If all terms of the
70216
+** record are not-NULL then a check is done to determine if any row in the
70217
+** P1 index btree has a matching key prefix. If there are no matches, jump
70218
+** immediately to P2. If there is a match, fall through and leave the P1
70219
+** cursor pointing to the matching row.
70220
+**
70221
+** This opcode is similar to OP_NotFound with the exceptions that the
70222
+** branch is always taken if any part of the search key input is NULL.
70223
+**
70224
+** See also: NotFound, Found, NotExists
70225
+*/
70226
+case OP_NoConflict: /* jump, in3 */
6983570227
case OP_NotFound: /* jump, in3 */
6983670228
case OP_Found: { /* jump, in3 */
69837
-#if 0 /* local variables moved into u.be */
70229
+#if 0 /* local variables moved into u.bf */
6983870230
int alreadyExists;
70231
+ int ii;
6983970232
VdbeCursor *pC;
6984070233
int res;
6984170234
char *pFree;
6984270235
UnpackedRecord *pIdxKey;
6984370236
UnpackedRecord r;
69844
- char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*3 + 7];
69845
-#endif /* local variables moved into u.be */
69846
-
69847
-#ifdef SQLITE_TEST
69848
- sqlite3_found_count++;
69849
-#endif
69850
-
69851
- u.be.alreadyExists = 0;
69852
- assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69853
- assert( pOp->p4type==P4_INT32 );
69854
- u.be.pC = p->apCsr[pOp->p1];
69855
- assert( u.be.pC!=0 );
69856
- pIn3 = &aMem[pOp->p3];
69857
- if( ALWAYS(u.be.pC->pCursor!=0) ){
69858
-
69859
- assert( u.be.pC->isTable==0 );
69860
- if( pOp->p4.i>0 ){
69861
- u.be.r.pKeyInfo = u.be.pC->pKeyInfo;
69862
- u.be.r.nField = (u16)pOp->p4.i;
69863
- u.be.r.aMem = pIn3;
69864
-#ifdef SQLITE_DEBUG
69865
- { int i; for(i=0; i<u.be.r.nField; i++) assert( memIsValid(&u.be.r.aMem[i]) ); }
69866
-#endif
69867
- u.be.r.flags = UNPACKED_PREFIX_MATCH;
69868
- u.be.pIdxKey = &u.be.r;
69869
- }else{
69870
- u.be.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
69871
- u.be.pC->pKeyInfo, u.be.aTempRec, sizeof(u.be.aTempRec), &u.be.pFree
69872
- );
69873
- if( u.be.pIdxKey==0 ) goto no_mem;
69874
- assert( pIn3->flags & MEM_Blob );
69875
- assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
69876
- sqlite3VdbeRecordUnpack(u.be.pC->pKeyInfo, pIn3->n, pIn3->z, u.be.pIdxKey);
69877
- u.be.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
69878
- }
69879
- rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, u.be.pIdxKey, 0, 0, &u.be.res);
69880
- if( pOp->p4.i==0 ){
69881
- sqlite3DbFree(db, u.be.pFree);
69882
- }
69883
- if( rc!=SQLITE_OK ){
69884
- break;
69885
- }
69886
- u.be.alreadyExists = (u.be.res==0);
69887
- u.be.pC->deferredMoveto = 0;
69888
- u.be.pC->cacheStatus = CACHE_STALE;
69889
- }
69890
- if( pOp->opcode==OP_Found ){
69891
- if( u.be.alreadyExists ) pc = pOp->p2 - 1;
69892
- }else{
69893
- if( !u.be.alreadyExists ) pc = pOp->p2 - 1;
69894
- }
69895
- break;
69896
-}
69897
-
69898
-/* Opcode: IsUnique P1 P2 P3 P4 *
69899
-**
69900
-** Cursor P1 is open on an index b-tree - that is to say, a btree which
69901
-** no data and where the key are records generated by OP_MakeRecord with
69902
-** the list field being the integer ROWID of the entry that the index
69903
-** entry refers to.
69904
-**
69905
-** The P3 register contains an integer record number. Call this record
69906
-** number R. Register P4 is the first in a set of N contiguous registers
69907
-** that make up an unpacked index key that can be used with cursor P1.
69908
-** The value of N can be inferred from the cursor. N includes the rowid
69909
-** value appended to the end of the index record. This rowid value may
69910
-** or may not be the same as R.
69911
-**
69912
-** If any of the N registers beginning with register P4 contains a NULL
69913
-** value, jump immediately to P2.
69914
-**
69915
-** Otherwise, this instruction checks if cursor P1 contains an entry
69916
-** where the first (N-1) fields match but the rowid value at the end
69917
-** of the index entry is not R. If there is no such entry, control jumps
69918
-** to instruction P2. Otherwise, the rowid of the conflicting index
69919
-** entry is copied to register P3 and control falls through to the next
69920
-** instruction.
69921
-**
69922
-** See also: NotFound, NotExists, Found
69923
-*/
69924
-case OP_IsUnique: { /* jump, in3 */
69925
-#if 0 /* local variables moved into u.bf */
69926
- u16 ii;
69927
- VdbeCursor *pCx;
69928
- BtCursor *pCrsr;
69929
- u16 nField;
69930
- Mem *aMx;
69931
- UnpackedRecord r; /* B-Tree index search key */
69932
- i64 R; /* Rowid stored in register P3 */
69933
-#endif /* local variables moved into u.bf */
69934
-
69935
- pIn3 = &aMem[pOp->p3];
69936
- u.bf.aMx = &aMem[pOp->p4.i];
69937
- /* Assert that the values of parameters P1 and P4 are in range. */
69938
- assert( pOp->p4type==P4_INT32 );
69939
- assert( pOp->p4.i>0 && pOp->p4.i<=(p->nMem-p->nCursor) );
69940
- assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69941
-
69942
- /* Find the index cursor. */
69943
- u.bf.pCx = p->apCsr[pOp->p1];
69944
- assert( u.bf.pCx->deferredMoveto==0 );
69945
- u.bf.pCx->seekResult = 0;
69946
- u.bf.pCx->cacheStatus = CACHE_STALE;
69947
- u.bf.pCrsr = u.bf.pCx->pCursor;
69948
-
69949
- /* If any of the values are NULL, take the jump. */
69950
- u.bf.nField = u.bf.pCx->pKeyInfo->nField;
69951
- for(u.bf.ii=0; u.bf.ii<u.bf.nField; u.bf.ii++){
69952
- if( u.bf.aMx[u.bf.ii].flags & MEM_Null ){
69953
- pc = pOp->p2 - 1;
69954
- u.bf.pCrsr = 0;
69955
- break;
69956
- }
69957
- }
69958
- assert( (u.bf.aMx[u.bf.nField].flags & MEM_Null)==0 );
69959
-
69960
- if( u.bf.pCrsr!=0 ){
69961
- /* Populate the index search key. */
69962
- u.bf.r.pKeyInfo = u.bf.pCx->pKeyInfo;
69963
- u.bf.r.nField = u.bf.nField + 1;
69964
- u.bf.r.flags = UNPACKED_PREFIX_SEARCH;
69965
- u.bf.r.aMem = u.bf.aMx;
69966
-#ifdef SQLITE_DEBUG
69967
- { int i; for(i=0; i<u.bf.r.nField; i++) assert( memIsValid(&u.bf.r.aMem[i]) ); }
69968
-#endif
69969
-
69970
- /* Extract the value of u.bf.R from register P3. */
69971
- sqlite3VdbeMemIntegerify(pIn3);
69972
- u.bf.R = pIn3->u.i;
69973
-
69974
- /* Search the B-Tree index. If no conflicting record is found, jump
69975
- ** to P2. Otherwise, copy the rowid of the conflicting record to
69976
- ** register P3 and fall through to the next instruction. */
69977
- rc = sqlite3BtreeMovetoUnpacked(u.bf.pCrsr, &u.bf.r, 0, 0, &u.bf.pCx->seekResult);
69978
- if( (u.bf.r.flags & UNPACKED_PREFIX_SEARCH) || u.bf.r.rowid==u.bf.R ){
69979
- pc = pOp->p2 - 1;
69980
- }else{
69981
- pIn3->u.i = u.bf.r.rowid;
69982
- }
70237
+ char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70238
+#endif /* local variables moved into u.bf */
70239
+
70240
+#ifdef SQLITE_TEST
70241
+ if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
70242
+#endif
70243
+
70244
+ u.bf.alreadyExists = 0;
70245
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70246
+ assert( pOp->p4type==P4_INT32 );
70247
+ u.bf.pC = p->apCsr[pOp->p1];
70248
+ assert( u.bf.pC!=0 );
70249
+ pIn3 = &aMem[pOp->p3];
70250
+ assert( u.bf.pC->pCursor!=0 );
70251
+ assert( u.bf.pC->isTable==0 );
70252
+ if( pOp->p4.i>0 ){
70253
+ u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo;
70254
+ u.bf.r.nField = (u16)pOp->p4.i;
70255
+ u.bf.r.aMem = pIn3;
70256
+#ifdef SQLITE_DEBUG
70257
+ {
70258
+ int i;
70259
+ for(i=0; i<u.bf.r.nField; i++){
70260
+ assert( memIsValid(&u.bf.r.aMem[i]) );
70261
+ if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]);
70262
+ }
70263
+ }
70264
+#endif
70265
+ u.bf.r.flags = UNPACKED_PREFIX_MATCH;
70266
+ u.bf.pIdxKey = &u.bf.r;
70267
+ }else{
70268
+ u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70269
+ u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree
70270
+ );
70271
+ if( u.bf.pIdxKey==0 ) goto no_mem;
70272
+ assert( pIn3->flags & MEM_Blob );
70273
+ assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70274
+ sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey);
70275
+ u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70276
+ }
70277
+ if( pOp->opcode==OP_NoConflict ){
70278
+ /* For the OP_NoConflict opcode, take the jump if any of the
70279
+ ** input fields are NULL, since any key with a NULL will not
70280
+ ** conflict */
70281
+ for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){
70282
+ if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){
70283
+ pc = pOp->p2 - 1;
70284
+ break;
70285
+ }
70286
+ }
70287
+ }
70288
+ rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
70289
+ if( pOp->p4.i==0 ){
70290
+ sqlite3DbFree(db, u.bf.pFree);
70291
+ }
70292
+ if( rc!=SQLITE_OK ){
70293
+ break;
70294
+ }
70295
+ u.bf.pC->seekResult = u.bf.res;
70296
+ u.bf.alreadyExists = (u.bf.res==0);
70297
+ u.bf.pC->nullRow = 1-u.bf.alreadyExists;
70298
+ u.bf.pC->deferredMoveto = 0;
70299
+ u.bf.pC->cacheStatus = CACHE_STALE;
70300
+ if( pOp->opcode==OP_Found ){
70301
+ if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
70302
+ }else{
70303
+ if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
6998370304
}
6998470305
break;
6998570306
}
6998670307
6998770308
/* Opcode: NotExists P1 P2 P3 * *
69988
-**
69989
-** Use the content of register P3 as an integer key. If a record
69990
-** with that key does not exist in table of P1, then jump to P2.
69991
-** If the record does exist, then fall through. The cursor is left
69992
-** pointing to the record if it exists.
69993
-**
69994
-** The difference between this operation and NotFound is that this
69995
-** operation assumes the key is an integer and that P1 is a table whereas
69996
-** NotFound assumes key is a blob constructed from MakeRecord and
69997
-** P1 is an index.
69998
-**
69999
-** See also: Found, NotFound, IsUnique
70309
+** Synopsis: intkey=r[P3]
70310
+**
70311
+** P1 is the index of a cursor open on an SQL table btree (with integer
70312
+** keys). P3 is an integer rowid. If P1 does not contain a record with
70313
+** rowid P3 then jump immediately to P2. If P1 does contain a record
70314
+** with rowid P3 then leave the cursor pointing at that record and fall
70315
+** through to the next instruction.
70316
+**
70317
+** The OP_NotFound opcode performs the same operation on index btrees
70318
+** (with arbitrary multi-value keys).
70319
+**
70320
+** See also: Found, NotFound, NoConflict
7000070321
*/
7000170322
case OP_NotExists: { /* jump, in3 */
7000270323
#if 0 /* local variables moved into u.bg */
7000370324
VdbeCursor *pC;
7000470325
BtCursor *pCrsr;
@@ -70012,36 +70333,29 @@
7001270333
u.bg.pC = p->apCsr[pOp->p1];
7001370334
assert( u.bg.pC!=0 );
7001470335
assert( u.bg.pC->isTable );
7001570336
assert( u.bg.pC->pseudoTableReg==0 );
7001670337
u.bg.pCrsr = u.bg.pC->pCursor;
70017
- if( ALWAYS(u.bg.pCrsr!=0) ){
70018
- u.bg.res = 0;
70019
- u.bg.iKey = pIn3->u.i;
70020
- rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70021
- u.bg.pC->lastRowid = pIn3->u.i;
70022
- u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70023
- u.bg.pC->nullRow = 0;
70024
- u.bg.pC->cacheStatus = CACHE_STALE;
70025
- u.bg.pC->deferredMoveto = 0;
70026
- if( u.bg.res!=0 ){
70027
- pc = pOp->p2 - 1;
70028
- assert( u.bg.pC->rowidIsValid==0 );
70029
- }
70030
- u.bg.pC->seekResult = u.bg.res;
70031
- }else{
70032
- /* This happens when an attempt to open a read cursor on the
70033
- ** sqlite_master table returns SQLITE_EMPTY.
70034
- */
70035
- pc = pOp->p2 - 1;
70036
- assert( u.bg.pC->rowidIsValid==0 );
70037
- u.bg.pC->seekResult = 0;
70038
- }
70338
+ assert( u.bg.pCrsr!=0 );
70339
+ u.bg.res = 0;
70340
+ u.bg.iKey = pIn3->u.i;
70341
+ rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70342
+ u.bg.pC->lastRowid = pIn3->u.i;
70343
+ u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70344
+ u.bg.pC->nullRow = 0;
70345
+ u.bg.pC->cacheStatus = CACHE_STALE;
70346
+ u.bg.pC->deferredMoveto = 0;
70347
+ if( u.bg.res!=0 ){
70348
+ pc = pOp->p2 - 1;
70349
+ assert( u.bg.pC->rowidIsValid==0 );
70350
+ }
70351
+ u.bg.pC->seekResult = u.bg.res;
7003970352
break;
7004070353
}
7004170354
7004270355
/* Opcode: Sequence P1 P2 * * *
70356
+** Synopsis: r[P2]=rowid
7004370357
**
7004470358
** Find the next available sequence number for cursor P1.
7004570359
** Write the sequence number into register P2.
7004670360
** The sequence number on the cursor is incremented after this
7004770361
** instruction.
@@ -70053,10 +70367,11 @@
7005370367
break;
7005470368
}
7005570369
7005670370
7005770371
/* Opcode: NewRowid P1 P2 P3 * *
70372
+** Synopsis: r[P2]=rowid
7005870373
**
7005970374
** Get a new integer record number (a.k.a "rowid") used as the key to a table.
7006070375
** The record number is not previously used as a key in the database
7006170376
** table that cursor P1 points to. The new record number is written
7006270377
** written to register P2.
@@ -70204,10 +70519,11 @@
7020470519
pOut->u.i = u.bh.v;
7020570520
break;
7020670521
}
7020770522
7020870523
/* Opcode: Insert P1 P2 P3 P4 P5
70524
+** Synopsis: intkey=r[P3] data=r[P2]
7020970525
**
7021070526
** Write an entry into the table of cursor P1. A new entry is
7021170527
** created if it doesn't already exist or the data for an existing
7021270528
** entry is overwritten. The data is the value MEM_Blob stored in register
7021370529
** number P2. The key is stored in register P3. The key must
@@ -70243,10 +70559,11 @@
7024370559
**
7024470560
** This instruction only works on tables. The equivalent instruction
7024570561
** for indices is OP_IdxInsert.
7024670562
*/
7024770563
/* Opcode: InsertInt P1 P2 P3 P4 P5
70564
+** Synopsis: intkey=P3 data=r[P2]
7024870565
**
7024970566
** This works exactly like OP_Insert except that the key is the
7025070567
** integer value P3, not the value of the integer stored in register P3.
7025170568
*/
7025270569
case OP_Insert:
@@ -70396,34 +70713,46 @@
7039670713
sqlite3VdbeSetChanges(db, p->nChange);
7039770714
p->nChange = 0;
7039870715
break;
7039970716
}
7040070717
70401
-/* Opcode: SorterCompare P1 P2 P3
70718
+/* Opcode: SorterCompare P1 P2 P3 P4
70719
+** Synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2
7040270720
**
70403
-** P1 is a sorter cursor. This instruction compares the record blob in
70404
-** register P3 with the entry that the sorter cursor currently points to.
70405
-** If, excluding the rowid fields at the end, the two records are a match,
70406
-** fall through to the next instruction. Otherwise, jump to instruction P2.
70721
+** P1 is a sorter cursor. This instruction compares a prefix of the
70722
+** the record blob in register P3 against a prefix of the entry that
70723
+** the sorter cursor currently points to. The final P4 fields of both
70724
+** the P3 and sorter record are ignored.
70725
+**
70726
+** If either P3 or the sorter contains a NULL in one of their significant
70727
+** fields (not counting the P4 fields at the end which are ignored) then
70728
+** the comparison is assumed to be equal.
70729
+**
70730
+** Fall through to next instruction if the two records compare equal to
70731
+** each other. Jump to P2 if they are different.
7040770732
*/
7040870733
case OP_SorterCompare: {
7040970734
#if 0 /* local variables moved into u.bk */
7041070735
VdbeCursor *pC;
7041170736
int res;
70737
+ int nIgnore;
7041270738
#endif /* local variables moved into u.bk */
7041370739
7041470740
u.bk.pC = p->apCsr[pOp->p1];
7041570741
assert( isSorter(u.bk.pC) );
70742
+ assert( pOp->p4type==P4_INT32 );
7041670743
pIn3 = &aMem[pOp->p3];
70417
- rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, &u.bk.res);
70744
+ u.bk.nIgnore = pOp->p4.i;
70745
+ rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res);
7041870746
if( u.bk.res ){
7041970747
pc = pOp->p2-1;
7042070748
}
7042170749
break;
7042270750
};
7042370751
7042470752
/* Opcode: SorterData P1 P2 * * *
70753
+** Synopsis: r[P2]=data
7042570754
**
7042670755
** Write into register P2 the current sorter data for sorter cursor P1.
7042770756
*/
7042870757
case OP_SorterData: {
7042970758
#if 0 /* local variables moved into u.bl */
@@ -70436,10 +70765,11 @@
7043670765
rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
7043770766
break;
7043870767
}
7043970768
7044070769
/* Opcode: RowData P1 P2 * * *
70770
+** Synopsis: r[P2]=data
7044170771
**
7044270772
** Write into register P2 the complete row data for cursor P1.
7044370773
** There is no interpretation of the data.
7044470774
** It is just copied onto the P2 register exactly as
7044570775
** it is found in the database file.
@@ -70446,10 +70776,11 @@
7044670776
**
7044770777
** If the P1 cursor must be pointing to a valid row (not a NULL row)
7044870778
** of a real table, not a pseudo-table.
7044970779
*/
7045070780
/* Opcode: RowKey P1 P2 * * *
70781
+** Synopsis: r[P2]=key
7045170782
**
7045270783
** Write into register P2 the complete row key for cursor P1.
7045370784
** There is no interpretation of the data.
7045470785
** The key is copied onto the P3 register exactly as
7045570786
** it is found in the database file.
@@ -70516,14 +70847,16 @@
7051670847
}else{
7051770848
rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
7051870849
}
7051970850
pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
7052070851
UPDATE_MAX_BLOBSIZE(pOut);
70852
+ REGISTER_TRACE(pOp->p2, pOut);
7052170853
break;
7052270854
}
7052370855
7052470856
/* Opcode: Rowid P1 P2 * * *
70857
+** Synopsis: r[P2]=rowid
7052570858
**
7052670859
** Store in register P2 an integer which is the key of the table entry that
7052770860
** P1 is currently point to.
7052870861
**
7052970862
** P1 can be either an ordinary table or a virtual table. There used to
@@ -70611,13 +70944,12 @@
7061170944
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7061270945
u.bp.pC = p->apCsr[pOp->p1];
7061370946
assert( u.bp.pC!=0 );
7061470947
u.bp.pCrsr = u.bp.pC->pCursor;
7061570948
u.bp.res = 0;
70616
- if( ALWAYS(u.bp.pCrsr!=0) ){
70617
- rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
70618
- }
70949
+ assert( u.bp.pCrsr!=0 );
70950
+ rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
7061970951
u.bp.pC->nullRow = (u8)u.bp.res;
7062070952
u.bp.pC->deferredMoveto = 0;
7062170953
u.bp.pC->rowidIsValid = 0;
7062270954
u.bp.pC->cacheStatus = CACHE_STALE;
7062370955
if( pOp->p2>0 && u.bp.res ){
@@ -70685,11 +71017,11 @@
7068571017
pc = pOp->p2 - 1;
7068671018
}
7068771019
break;
7068871020
}
7068971021
70690
-/* Opcode: Next P1 P2 * P4 P5
71022
+/* Opcode: Next P1 P2 * * P5
7069171023
**
7069271024
** Advance cursor P1 so that it points to the next key/data pair in its
7069371025
** table or index. If there are no more key/value pairs then fall through
7069471026
** to the following instruction. But if the cursor advance was successful,
7069571027
** jump immediately to P2.
@@ -70757,10 +71089,11 @@
7075771089
u.br.pC->rowidIsValid = 0;
7075871090
goto check_for_interrupt;
7075971091
}
7076071092
7076171093
/* Opcode: IdxInsert P1 P2 P3 * P5
71094
+** Synopsis: key=r[P2]
7076271095
**
7076371096
** Register P2 holds an SQL index key made using the
7076471097
** MakeRecord instructions. This opcode writes that key
7076571098
** into the index P1. Data for the entry is nil.
7076671099
**
@@ -70784,31 +71117,32 @@
7078471117
assert( u.bs.pC!=0 );
7078571118
assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) );
7078671119
pIn2 = &aMem[pOp->p2];
7078771120
assert( pIn2->flags & MEM_Blob );
7078871121
u.bs.pCrsr = u.bs.pC->pCursor;
70789
- if( ALWAYS(u.bs.pCrsr!=0) ){
70790
- assert( u.bs.pC->isTable==0 );
70791
- rc = ExpandBlob(pIn2);
70792
- if( rc==SQLITE_OK ){
70793
- if( isSorter(u.bs.pC) ){
70794
- rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
70795
- }else{
70796
- u.bs.nKey = pIn2->n;
70797
- u.bs.zKey = pIn2->z;
70798
- rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
70799
- ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
70800
- );
70801
- assert( u.bs.pC->deferredMoveto==0 );
70802
- u.bs.pC->cacheStatus = CACHE_STALE;
70803
- }
71122
+ if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71123
+ assert( u.bs.pCrsr!=0 );
71124
+ assert( u.bs.pC->isTable==0 );
71125
+ rc = ExpandBlob(pIn2);
71126
+ if( rc==SQLITE_OK ){
71127
+ if( isSorter(u.bs.pC) ){
71128
+ rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
71129
+ }else{
71130
+ u.bs.nKey = pIn2->n;
71131
+ u.bs.zKey = pIn2->z;
71132
+ rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
71133
+ ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
71134
+ );
71135
+ assert( u.bs.pC->deferredMoveto==0 );
71136
+ u.bs.pC->cacheStatus = CACHE_STALE;
7080471137
}
7080571138
}
7080671139
break;
7080771140
}
7080871141
7080971142
/* Opcode: IdxDelete P1 P2 P3 * *
71143
+** Synopsis: key=r[P2@P3]
7081071144
**
7081171145
** The content of P3 registers starting at register P2 form
7081271146
** an unpacked index key. This opcode removes that entry from the
7081371147
** index opened by cursor P1.
7081471148
*/
@@ -70824,29 +71158,30 @@
7082471158
assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
7082571159
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7082671160
u.bt.pC = p->apCsr[pOp->p1];
7082771161
assert( u.bt.pC!=0 );
7082871162
u.bt.pCrsr = u.bt.pC->pCursor;
70829
- if( ALWAYS(u.bt.pCrsr!=0) ){
70830
- u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
70831
- u.bt.r.nField = (u16)pOp->p3;
70832
- u.bt.r.flags = 0;
70833
- u.bt.r.aMem = &aMem[pOp->p2];
71163
+ assert( u.bt.pCrsr!=0 );
71164
+ assert( pOp->p5==0 );
71165
+ u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
71166
+ u.bt.r.nField = (u16)pOp->p3;
71167
+ u.bt.r.flags = UNPACKED_PREFIX_MATCH;
71168
+ u.bt.r.aMem = &aMem[pOp->p2];
7083471169
#ifdef SQLITE_DEBUG
70835
- { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
71170
+ { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
7083671171
#endif
70837
- rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
70838
- if( rc==SQLITE_OK && u.bt.res==0 ){
70839
- rc = sqlite3BtreeDelete(u.bt.pCrsr);
70840
- }
70841
- assert( u.bt.pC->deferredMoveto==0 );
70842
- u.bt.pC->cacheStatus = CACHE_STALE;
71172
+ rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
71173
+ if( rc==SQLITE_OK && u.bt.res==0 ){
71174
+ rc = sqlite3BtreeDelete(u.bt.pCrsr);
7084371175
}
71176
+ assert( u.bt.pC->deferredMoveto==0 );
71177
+ u.bt.pC->cacheStatus = CACHE_STALE;
7084471178
break;
7084571179
}
7084671180
7084771181
/* Opcode: IdxRowid P1 P2 * * *
71182
+** Synopsis: r[P2]=rowid
7084871183
**
7084971184
** Write into register P2 an integer which is the last entry in the record at
7085071185
** the end of the index key pointed to by cursor P1. This integer should be
7085171186
** the rowid of the table entry to which this index entry points.
7085271187
**
@@ -70861,29 +71196,29 @@
7086171196
7086271197
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7086371198
u.bu.pC = p->apCsr[pOp->p1];
7086471199
assert( u.bu.pC!=0 );
7086571200
u.bu.pCrsr = u.bu.pC->pCursor;
71201
+ assert( u.bu.pCrsr!=0 );
7086671202
pOut->flags = MEM_Null;
70867
- if( ALWAYS(u.bu.pCrsr!=0) ){
70868
- rc = sqlite3VdbeCursorMoveto(u.bu.pC);
70869
- if( NEVER(rc) ) goto abort_due_to_error;
70870
- assert( u.bu.pC->deferredMoveto==0 );
70871
- assert( u.bu.pC->isTable==0 );
70872
- if( !u.bu.pC->nullRow ){
70873
- rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
70874
- if( rc!=SQLITE_OK ){
70875
- goto abort_due_to_error;
70876
- }
70877
- pOut->u.i = u.bu.rowid;
70878
- pOut->flags = MEM_Int;
70879
- }
71203
+ rc = sqlite3VdbeCursorMoveto(u.bu.pC);
71204
+ if( NEVER(rc) ) goto abort_due_to_error;
71205
+ assert( u.bu.pC->deferredMoveto==0 );
71206
+ assert( u.bu.pC->isTable==0 );
71207
+ if( !u.bu.pC->nullRow ){
71208
+ rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
71209
+ if( rc!=SQLITE_OK ){
71210
+ goto abort_due_to_error;
71211
+ }
71212
+ pOut->u.i = u.bu.rowid;
71213
+ pOut->flags = MEM_Int;
7088071214
}
7088171215
break;
7088271216
}
7088371217
7088471218
/* Opcode: IdxGE P1 P2 P3 P4 P5
71219
+** Synopsis: key=r[P3@P4]
7088571220
**
7088671221
** The P4 register values beginning with P3 form an unpacked index
7088771222
** key that omits the ROWID. Compare this key value against the index
7088871223
** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
7088971224
**
@@ -70894,10 +71229,11 @@
7089471229
** prior to the comparison. This make the opcode work like IdxGT except
7089571230
** that if the key from register P3 is a prefix of the key in the cursor,
7089671231
** the result is false whereas it would be true with IdxGT.
7089771232
*/
7089871233
/* Opcode: IdxLT P1 P2 P3 P4 P5
71234
+** Synopsis: key=r[P3@P4]
7089971235
**
7090071236
** The P4 register values beginning with P3 form an unpacked index
7090171237
** key that omits the ROWID. Compare this key value against the index
7090271238
** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
7090371239
**
@@ -70917,35 +71253,34 @@
7091771253
7091871254
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7091971255
u.bv.pC = p->apCsr[pOp->p1];
7092071256
assert( u.bv.pC!=0 );
7092171257
assert( u.bv.pC->isOrdered );
70922
- if( ALWAYS(u.bv.pC->pCursor!=0) ){
70923
- assert( u.bv.pC->deferredMoveto==0 );
70924
- assert( pOp->p5==0 || pOp->p5==1 );
70925
- assert( pOp->p4type==P4_INT32 );
70926
- u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
70927
- u.bv.r.nField = (u16)pOp->p4.i;
70928
- if( pOp->p5 ){
70929
- u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
70930
- }else{
70931
- u.bv.r.flags = UNPACKED_PREFIX_MATCH;
70932
- }
70933
- u.bv.r.aMem = &aMem[pOp->p3];
71258
+ assert( u.bv.pC->pCursor!=0);
71259
+ assert( u.bv.pC->deferredMoveto==0 );
71260
+ assert( pOp->p5==0 || pOp->p5==1 );
71261
+ assert( pOp->p4type==P4_INT32 );
71262
+ u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
71263
+ u.bv.r.nField = (u16)pOp->p4.i;
71264
+ if( pOp->p5 ){
71265
+ u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71266
+ }else{
71267
+ u.bv.r.flags = UNPACKED_PREFIX_MATCH;
71268
+ }
71269
+ u.bv.r.aMem = &aMem[pOp->p3];
7093471270
#ifdef SQLITE_DEBUG
70935
- { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
71271
+ { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
7093671272
#endif
70937
- rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
70938
- if( pOp->opcode==OP_IdxLT ){
70939
- u.bv.res = -u.bv.res;
70940
- }else{
70941
- assert( pOp->opcode==OP_IdxGE );
70942
- u.bv.res++;
70943
- }
70944
- if( u.bv.res>0 ){
70945
- pc = pOp->p2 - 1 ;
70946
- }
71273
+ rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
71274
+ if( pOp->opcode==OP_IdxLT ){
71275
+ u.bv.res = -u.bv.res;
71276
+ }else{
71277
+ assert( pOp->opcode==OP_IdxGE );
71278
+ u.bv.res++;
71279
+ }
71280
+ if( u.bv.res>0 ){
71281
+ pc = pOp->p2 - 1 ;
7094771282
}
7094871283
break;
7094971284
}
7095071285
7095171286
/* Opcode: Destroy P1 P2 P3 * *
@@ -71052,10 +71387,11 @@
7105271387
}
7105371388
break;
7105471389
}
7105571390
7105671391
/* Opcode: CreateTable P1 P2 * * *
71392
+** Synopsis: r[P2]=root iDb=P1
7105771393
**
7105871394
** Allocate a new table in the main database file if P1==0 or in the
7105971395
** auxiliary database file if P1==1 or in an attached database if
7106071396
** P1>1. Write the root page number of the new table into
7106171397
** register P2
@@ -71065,10 +71401,11 @@
7106571401
** has an arbitrary key but no data.
7106671402
**
7106771403
** See also: CreateIndex
7106871404
*/
7106971405
/* Opcode: CreateIndex P1 P2 * * *
71406
+** Synopsis: r[P2]=root iDb=P1
7107071407
**
7107171408
** Allocate a new index in the main database file if P1==0 or in the
7107271409
** auxiliary database file if P1==1 or in an attached database if
7107371410
** P1>1. Write the root page number of the new table into
7107471411
** register P2.
@@ -71272,10 +71609,11 @@
7127271609
break;
7127371610
}
7127471611
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
7127571612
7127671613
/* Opcode: RowSetAdd P1 P2 * * *
71614
+** Synopsis: rowset(P1)=r[P2]
7127771615
**
7127871616
** Insert the integer value held by register P2 into a boolean index
7127971617
** held in register P1.
7128071618
**
7128171619
** An assertion fails if P2 is not an integer.
@@ -71291,10 +71629,11 @@
7129171629
sqlite3RowSetInsert(pIn1->u.pRowSet, pIn2->u.i);
7129271630
break;
7129371631
}
7129471632
7129571633
/* Opcode: RowSetRead P1 P2 P3 * *
71634
+** Synopsis: r[P3]=rowset(P1)
7129671635
**
7129771636
** Extract the smallest value from boolean index P1 and put that value into
7129871637
** register P3. Or, if boolean index P1 is initially empty, leave P3
7129971638
** unchanged and jump to instruction P2.
7130071639
*/
@@ -71316,10 +71655,11 @@
7131671655
}
7131771656
goto check_for_interrupt;
7131871657
}
7131971658
7132071659
/* Opcode: RowSetTest P1 P2 P3 P4
71660
+** Synopsis: if r[P3] in rowset(P1) goto P2
7132171661
**
7132271662
** Register P3 is assumed to hold a 64-bit integer value. If register P1
7132371663
** contains a RowSet object and that RowSet object contains
7132471664
** the value held in P3, jump to register P2. Otherwise, insert the
7132571665
** integer in P3 into the RowSet and continue on to the
@@ -71525,10 +71865,11 @@
7152571865
7152671866
#endif /* #ifndef SQLITE_OMIT_TRIGGER */
7152771867
7152871868
#ifndef SQLITE_OMIT_FOREIGN_KEY
7152971869
/* Opcode: FkCounter P1 P2 * * *
71870
+** Synopsis: fkctr[P1]+=P2
7153071871
**
7153171872
** Increment a "constraint counter" by P2 (P2 may be negative or positive).
7153271873
** If P1 is non-zero, the database constraint counter is incremented
7153371874
** (deferred foreign key constraints). Otherwise, if P1 is zero, the
7153471875
** statement counter is incremented (immediate foreign key constraints).
@@ -71543,10 +71884,11 @@
7154371884
}
7154471885
break;
7154571886
}
7154671887
7154771888
/* Opcode: FkIfZero P1 P2 * * *
71889
+** Synopsis: if fkctr[P1]==0 goto P2
7154871890
**
7154971891
** This opcode tests if a foreign key constraint-counter is currently zero.
7155071892
** If so, jump to instruction P2. Otherwise, fall through to the next
7155171893
** instruction.
7155271894
**
@@ -71565,10 +71907,11 @@
7156571907
}
7156671908
#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
7156771909
7156871910
#ifndef SQLITE_OMIT_AUTOINCREMENT
7156971911
/* Opcode: MemMax P1 P2 * * *
71912
+** Synopsis: r[P1]=max(r[P1],r[P2])
7157071913
**
7157171914
** P1 is a register in the root frame of this VM (the root frame is
7157271915
** different from the current frame if this instruction is being executed
7157371916
** within a sub-program). Set the value of register P1 to the maximum of
7157471917
** its current value and the value in register P2.
@@ -71597,10 +71940,11 @@
7159771940
break;
7159871941
}
7159971942
#endif /* SQLITE_OMIT_AUTOINCREMENT */
7160071943
7160171944
/* Opcode: IfPos P1 P2 * * *
71945
+** Synopsis: if r[P1]>0 goto P2
7160271946
**
7160371947
** If the value of register P1 is 1 or greater, jump to P2.
7160471948
**
7160571949
** It is illegal to use this instruction on a register that does
7160671950
** not contain an integer. An assertion fault will result if you try.
@@ -71613,10 +71957,11 @@
7161371957
}
7161471958
break;
7161571959
}
7161671960
7161771961
/* Opcode: IfNeg P1 P2 * * *
71962
+** Synopsis: if r[P1]<0 goto P2
7161871963
**
7161971964
** If the value of register P1 is less than zero, jump to P2.
7162071965
**
7162171966
** It is illegal to use this instruction on a register that does
7162271967
** not contain an integer. An assertion fault will result if you try.
@@ -71629,10 +71974,11 @@
7162971974
}
7163071975
break;
7163171976
}
7163271977
7163371978
/* Opcode: IfZero P1 P2 P3 * *
71979
+** Synopsis: r[P1]+=P3, if r[P1]==0 goto P2
7163471980
**
7163571981
** The register P1 must contain an integer. Add literal P3 to the
7163671982
** value in register P1. If the result is exactly 0, jump to P2.
7163771983
**
7163871984
** It is illegal to use this instruction on a register that does
@@ -71647,10 +71993,11 @@
7164771993
}
7164871994
break;
7164971995
}
7165071996
7165171997
/* Opcode: AggStep * P2 P3 P4 P5
71998
+** Synopsis: accum=r[P3] step(r[P2@P5])
7165271999
**
7165372000
** Execute the step function for an aggregate. The
7165472001
** function has P5 arguments. P4 is a pointer to the FuncDef
7165572002
** structure that specifies the function. Use register
7165672003
** P3 as the accumulator.
@@ -71712,10 +72059,11 @@
7171272059
7171372060
break;
7171472061
}
7171572062
7171672063
/* Opcode: AggFinal P1 P2 * P4 *
72064
+** Synopsis: accum=r[P1] N=P2
7171772065
**
7171872066
** Execute the finalizer function for an aggregate. P1 is
7171972067
** the memory location that is the accumulator for the aggregate.
7172072068
**
7172172069
** P2 is the number of arguments that the step function takes and
@@ -71947,10 +72295,11 @@
7194772295
break;
7194872296
}
7194972297
7195072298
#ifndef SQLITE_OMIT_SHARED_CACHE
7195172299
/* Opcode: TableLock P1 P2 P3 P4 *
72300
+** Synopsis: iDb=P1 root=P2 write=P3
7195272301
**
7195372302
** Obtain a lock on a particular table. This instruction is only used when
7195472303
** the shared-cache feature is enabled.
7195572304
**
7195672305
** P1 is the index of the database in sqlite3.aDb[] of the database
@@ -72067,10 +72416,11 @@
7206772416
}
7206872417
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7206972418
7207072419
#ifndef SQLITE_OMIT_VIRTUALTABLE
7207172420
/* Opcode: VFilter P1 P2 P3 P4 *
72421
+** Synopsis: iPlan=r[P3] zPlan='P4'
7207272422
**
7207372423
** P1 is a cursor opened using VOpen. P2 is an address to jump to if
7207472424
** the filtered result set is empty.
7207572425
**
7207672426
** P4 is either NULL or a string that was generated by the xBestIndex
@@ -72143,10 +72493,11 @@
7214372493
}
7214472494
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7214572495
7214672496
#ifndef SQLITE_OMIT_VIRTUALTABLE
7214772497
/* Opcode: VColumn P1 P2 P3 * *
72498
+** Synopsis: r[P3]=vcolumn(P2)
7214872499
**
7214972500
** Store the value of the P2-th column of
7215072501
** the row of the virtual-table that the
7215172502
** P1 cursor is pointing to into register P3.
7215272503
*/
@@ -72282,10 +72633,11 @@
7228272633
}
7228372634
#endif
7228472635
7228572636
#ifndef SQLITE_OMIT_VIRTUALTABLE
7228672637
/* Opcode: VUpdate P1 P2 P3 P4 *
72638
+** Synopsis: data=r[P3@P2]
7228772639
**
7228872640
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7228972641
** This opcode invokes the corresponding xUpdate method. P2 values
7229072642
** are contiguous memory cells starting at P3 to pass to the xUpdate
7229172643
** invocation. The value in register (P3+P2-1) corresponds to the
@@ -72413,10 +72765,20 @@
7241372765
){
7241472766
u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
7241572767
db->xTrace(db->pTraceArg, u.cs.z);
7241672768
sqlite3DbFree(db, u.cs.z);
7241772769
}
72770
+#ifdef SQLITE_USE_FCNTL_TRACE
72771
+ u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72772
+ if( u.cs.zTrace ){
72773
+ int i;
72774
+ for(i=0; i<db->nDb; i++){
72775
+ if( ((1<<i) & p->btreeMask)==0 ) continue;
72776
+ sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace);
72777
+ }
72778
+ }
72779
+#endif /* SQLITE_USE_FCNTL_TRACE */
7241872780
#ifdef SQLITE_DEBUG
7241972781
if( (db->flags & SQLITE_SqlTrace)!=0
7242072782
&& (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7242172783
){
7242272784
sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
@@ -72727,10 +73089,14 @@
7272773089
pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
7272873090
if( pTab && IsVirtual(pTab) ){
7272973091
pTab = 0;
7273073092
sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
7273173093
}
73094
+ if( pTab && !HasRowid(pTab) ){
73095
+ pTab = 0;
73096
+ sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
73097
+ }
7273273098
#ifndef SQLITE_OMIT_VIEW
7273373099
if( pTab && pTab->pSelect ){
7273473100
pTab = 0;
7273573101
sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
7273673102
}
@@ -72784,11 +73150,11 @@
7278473150
}
7278573151
}
7278673152
#endif
7278773153
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
7278873154
int j;
72789
- for(j=0; j<pIdx->nColumn; j++){
73155
+ for(j=0; j<pIdx->nKeyCol; j++){
7279073156
if( pIdx->aiColumn[j]==iCol ){
7279173157
zFault = "indexed";
7279273158
}
7279373159
}
7279473160
}
@@ -73405,11 +73771,11 @@
7340573771
** If pKey2 is passed a NULL pointer, then it is assumed that the pCsr->aSpace
7340673772
** has been allocated and contains an unpacked record that is used as key2.
7340773773
*/
7340873774
static void vdbeSorterCompare(
7340973775
const VdbeCursor *pCsr, /* Cursor object (for pKeyInfo) */
73410
- int bOmitRowid, /* Ignore rowid field at end of keys */
73776
+ int nIgnore, /* Ignore the last nIgnore fields */
7341173777
const void *pKey1, int nKey1, /* Left side of comparison */
7341273778
const void *pKey2, int nKey2, /* Right side of comparison */
7341373779
int *pRes /* OUT: Result of comparison */
7341473780
){
7341573781
KeyInfo *pKeyInfo = pCsr->pKeyInfo;
@@ -73419,12 +73785,12 @@
7341973785
7342073786
if( pKey2 ){
7342173787
sqlite3VdbeRecordUnpack(pKeyInfo, nKey2, pKey2, r2);
7342273788
}
7342373789
73424
- if( bOmitRowid ){
73425
- r2->nField = pKeyInfo->nField;
73790
+ if( nIgnore ){
73791
+ r2->nField = pKeyInfo->nField - nIgnore;
7342673792
assert( r2->nField>0 );
7342773793
for(i=0; i<r2->nField; i++){
7342873794
if( r2->aMem[i].flags & MEM_Null ){
7342973795
*pRes = -1;
7343073796
return;
@@ -74046,17 +74412,18 @@
7404674412
** key.
7404774413
*/
7404874414
SQLITE_PRIVATE int sqlite3VdbeSorterCompare(
7404974415
const VdbeCursor *pCsr, /* Sorter cursor */
7405074416
Mem *pVal, /* Value to compare to current sorter key */
74417
+ int nIgnore, /* Ignore this many fields at the end */
7405174418
int *pRes /* OUT: Result of comparison */
7405274419
){
7405374420
VdbeSorter *pSorter = pCsr->pSorter;
7405474421
void *pKey; int nKey; /* Sorter key to compare pVal with */
7405574422
7405674423
pKey = vdbeSorterRowkey(pSorter, &nKey);
74057
- vdbeSorterCompare(pCsr, 1, pVal->z, pVal->n, pKey, nKey, pRes);
74424
+ vdbeSorterCompare(pCsr, nIgnore, pVal->z, pVal->n, pKey, nKey, pRes);
7405874425
return SQLITE_OK;
7405974426
}
7406074427
7406174428
/************** End of vdbesort.c ********************************************/
7406274429
/************** Begin file journal.c *****************************************/
@@ -74955,11 +75322,13 @@
7495575322
sqlite3 *db = pParse->db; /* The database connection */
7495675323
struct SrcList_item *pItem; /* Use for looping over pSrcList items */
7495775324
struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
7495875325
NameContext *pTopNC = pNC; /* First namecontext in the list */
7495975326
Schema *pSchema = 0; /* Schema of the expression */
74960
- int isTrigger = 0;
75327
+ int isTrigger = 0; /* True if resolved to a trigger column */
75328
+ Table *pTab = 0; /* Table hold the row */
75329
+ Column *pCol; /* A column of pTab */
7496175330
7496275331
assert( pNC ); /* the name context cannot be NULL. */
7496375332
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
7496475333
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
7496575334
@@ -74996,13 +75365,10 @@
7499675365
ExprList *pEList;
7499775366
SrcList *pSrcList = pNC->pSrcList;
7499875367
7499975368
if( pSrcList ){
7500075369
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
75001
- Table *pTab;
75002
- Column *pCol;
75003
-
7500475370
pTab = pItem->pTab;
7500575371
assert( pTab!=0 && pTab->zName!=0 );
7500675372
assert( pTab->nCol>0 );
7500775373
if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
7500875374
int hit = 0;
@@ -75058,13 +75424,12 @@
7505875424
7505975425
#ifndef SQLITE_OMIT_TRIGGER
7506075426
/* If we have not already resolved the name, then maybe
7506175427
** it is a new.* or old.* trigger argument reference
7506275428
*/
75063
- if( zDb==0 && zTab!=0 && cnt==0 && pParse->pTriggerTab!=0 ){
75429
+ if( zDb==0 && zTab!=0 && cntTab==0 && pParse->pTriggerTab!=0 ){
7506475430
int op = pParse->eTriggerOp;
75065
- Table *pTab = 0;
7506675431
assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
7506775432
if( op!=TK_DELETE && sqlite3StrICmp("new",zTab) == 0 ){
7506875433
pExpr->iTable = 1;
7506975434
pTab = pParse->pTriggerTab;
7507075435
}else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
@@ -75074,20 +75439,19 @@
7507475439
7507575440
if( pTab ){
7507675441
int iCol;
7507775442
pSchema = pTab->pSchema;
7507875443
cntTab++;
75079
- for(iCol=0; iCol<pTab->nCol; iCol++){
75080
- Column *pCol = &pTab->aCol[iCol];
75444
+ for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
7508175445
if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
7508275446
if( iCol==pTab->iPKey ){
7508375447
iCol = -1;
7508475448
}
7508575449
break;
7508675450
}
7508775451
}
75088
- if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) ){
75452
+ if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
7508975453
iCol = -1; /* IMP: R-44911-55124 */
7509075454
}
7509175455
if( iCol<pTab->nCol ){
7509275456
cnt++;
7509375457
if( iCol<0 ){
@@ -75110,11 +75474,12 @@
7511075474
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
7511175475
7511275476
/*
7511375477
** Perhaps the name is a reference to the ROWID
7511475478
*/
75115
- if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) ){
75479
+ assert( pTab!=0 || cntTab==0 );
75480
+ if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
7511675481
cnt = 1;
7511775482
pExpr->iColumn = -1; /* IMP: R-44911-55124 */
7511875483
pExpr->affinity = SQLITE_AFF_INTEGER;
7511975484
}
7512075485
@@ -77714,20 +78079,20 @@
7771478079
p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
7771578080
if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
7771678081
sqlite3 *db = pParse->db; /* Database connection */
7771778082
Table *pTab; /* Table <table>. */
7771878083
Expr *pExpr; /* Expression <column> */
77719
- int iCol; /* Index of column <column> */
77720
- int iDb; /* Database idx for pTab */
78084
+ i16 iCol; /* Index of column <column> */
78085
+ i16 iDb; /* Database idx for pTab */
7772178086
7772278087
assert( p ); /* Because of isCandidateForInOpt(p) */
7772378088
assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
7772478089
assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
7772578090
assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
7772678091
pTab = p->pSrc->a[0].pTab;
7772778092
pExpr = p->pEList->a[0].pExpr;
77728
- iCol = pExpr->iColumn;
78093
+ iCol = (i16)pExpr->iColumn;
7772978094
7773078095
/* Code an OP_VerifyCookie and OP_TableLock for <table>. */
7773178096
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7773278097
sqlite3CodeVerifySchema(pParse, iDb);
7773378098
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
@@ -77761,20 +78126,15 @@
7776178126
int affinity_ok = sqlite3IndexAffinityOk(pX, pTab->aCol[iCol].affinity);
7776278127
7776378128
for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
7776478129
if( (pIdx->aiColumn[0]==iCol)
7776578130
&& sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
77766
- && (!mustBeUnique || (pIdx->nColumn==1 && pIdx->onError!=OE_None))
78131
+ && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
7776778132
){
77768
- int iAddr;
77769
- char *pKey;
77770
-
77771
- pKey = (char *)sqlite3IndexKeyinfo(pParse, pIdx);
77772
- iAddr = sqlite3CodeOnce(pParse);
77773
-
77774
- sqlite3VdbeAddOp4(v, OP_OpenRead, iTab, pIdx->tnum, iDb,
77775
- pKey,P4_KEYINFO_HANDOFF);
78133
+ int iAddr = sqlite3CodeOnce(pParse);
78134
+ sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
78135
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
7777678136
VdbeComment((v, "%s", pIdx->zName));
7777778137
assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
7777878138
eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
7777978139
7778078140
sqlite3VdbeJumpHere(v, iAddr);
@@ -77910,11 +78270,11 @@
7791078270
** is used.
7791178271
*/
7791278272
pExpr->iTable = pParse->nTab++;
7791378273
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
7791478274
if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
77915
- pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1);
78275
+ pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
7791678276
7791778277
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
7791878278
/* Case 1: expr IN (SELECT ...)
7791978279
**
7792078280
** Generate code to write the results of the select into the temporary
@@ -77928,17 +78288,18 @@
7792878288
dest.affSdst = (u8)affinity;
7792978289
assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
7793078290
pExpr->x.pSelect->iLimit = 0;
7793178291
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
7793278292
if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
77933
- sqlite3DbFree(pParse->db, pKeyInfo);
78293
+ sqlite3KeyInfoUnref(pKeyInfo);
7793478294
return 0;
7793578295
}
7793678296
pEList = pExpr->x.pSelect->pEList;
7793778297
assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
7793878298
assert( pEList!=0 );
7793978299
assert( pEList->nExpr>0 );
78300
+ assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
7794078301
pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
7794178302
pEList->a[0].pExpr);
7794278303
}else if( ALWAYS(pExpr->x.pList!=0) ){
7794378304
/* Case 2: expr IN (exprlist)
7794478305
**
@@ -77954,10 +78315,11 @@
7795478315
7795578316
if( !affinity ){
7795678317
affinity = SQLITE_AFF_NONE;
7795778318
}
7795878319
if( pKeyInfo ){
78320
+ assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
7795978321
pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
7796078322
}
7796178323
7796278324
/* Loop through each expression in <exprlist>. */
7796378325
r1 = sqlite3GetTempReg(pParse);
@@ -77995,11 +78357,11 @@
7799578357
}
7799678358
sqlite3ReleaseTempReg(pParse, r1);
7799778359
sqlite3ReleaseTempReg(pParse, r2);
7799878360
}
7799978361
if( pKeyInfo ){
78000
- sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO_HANDOFF);
78362
+ sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
7800178363
}
7800278364
break;
7800378365
}
7800478366
7800578367
case TK_EXISTS:
@@ -78396,19 +78758,23 @@
7839678758
** Generate code to extract the value of the iCol-th column of a table.
7839778759
*/
7839878760
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
7839978761
Vdbe *v, /* The VDBE under construction */
7840078762
Table *pTab, /* The table containing the value */
78401
- int iTabCur, /* The cursor for this table */
78763
+ int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
7840278764
int iCol, /* Index of the column to extract */
78403
- int regOut /* Extract the valud into this register */
78765
+ int regOut /* Extract the value into this register */
7840478766
){
7840578767
if( iCol<0 || iCol==pTab->iPKey ){
7840678768
sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
7840778769
}else{
7840878770
int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
78409
- sqlite3VdbeAddOp3(v, op, iTabCur, iCol, regOut);
78771
+ int x = iCol;
78772
+ if( !HasRowid(pTab) ){
78773
+ x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol);
78774
+ }
78775
+ sqlite3VdbeAddOp3(v, op, iTabCur, x, regOut);
7841078776
}
7841178777
if( iCol>=0 ){
7841278778
sqlite3ColumnDefault(v, pTab, iCol, regOut);
7841378779
}
7841478780
}
@@ -79150,11 +79516,11 @@
7915079516
if( pExpr->affinity==OE_Ignore ){
7915179517
sqlite3VdbeAddOp4(
7915279518
v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
7915379519
}else{
7915479520
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
79155
- pExpr->affinity, pExpr->u.zToken, 0);
79521
+ pExpr->affinity, pExpr->u.zToken, 0, 0);
7915679522
}
7915779523
7915879524
break;
7915979525
}
7916079526
#endif
@@ -81526,12 +81892,11 @@
8152681892
}
8152781893
8152881894
/* Open the sqlite_stat[134] tables for writing. */
8152981895
for(i=0; aTable[i].zCols; i++){
8153081896
assert( i<ArraySize(aTable) );
81531
- sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb);
81532
- sqlite3VdbeChangeP4(v, -1, (char *)3, P4_INT32);
81897
+ sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb, 3);
8153381898
sqlite3VdbeChangeP5(v, aCreateTbl[i]);
8153481899
}
8153581900
}
8153681901
8153781902
/*
@@ -81551,11 +81916,15 @@
8155181916
struct Stat4Sample {
8155281917
tRowcnt *anEq; /* sqlite_stat4.nEq */
8155381918
tRowcnt *anDLt; /* sqlite_stat4.nDLt */
8155481919
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
8155581920
tRowcnt *anLt; /* sqlite_stat4.nLt */
81556
- i64 iRowid; /* Rowid in main table of the key */
81921
+ union {
81922
+ i64 iRowid; /* Rowid in main table of the key */
81923
+ u8 *aRowid; /* Key for WITHOUT ROWID tables */
81924
+ } u;
81925
+ u32 nRowid; /* Sizeof aRowid[] */
8155781926
u8 isPSample; /* True if a periodic sample */
8155881927
int iCol; /* If !isPSample, the reason for inclusion */
8155981928
u32 iHash; /* Tiebreaker hash */
8156081929
#endif
8156181930
};
@@ -81564,16 +81933,90 @@
8156481933
tRowcnt nPSample; /* How often to do a periodic sample */
8156581934
int nCol; /* Number of columns in index + rowid */
8156681935
int mxSample; /* Maximum number of samples to accumulate */
8156781936
Stat4Sample current; /* Current row as a Stat4Sample */
8156881937
u32 iPrn; /* Pseudo-random number used for sampling */
81569
- Stat4Sample *aBest; /* Array of (nCol-1) best samples */
81938
+ Stat4Sample *aBest; /* Array of nCol best samples */
8157081939
int iMin; /* Index in a[] of entry with minimum score */
8157181940
int nSample; /* Current number of samples */
8157281941
int iGet; /* Index of current sample accessed by stat_get() */
8157381942
Stat4Sample *a; /* Array of mxSample Stat4Sample objects */
81943
+ sqlite3 *db; /* Database connection, for malloc() */
8157481944
};
81945
+
81946
+/* Reclaim memory used by a Stat4Sample
81947
+*/
81948
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81949
+static void sampleClear(sqlite3 *db, Stat4Sample *p){
81950
+ assert( db!=0 );
81951
+ if( p->nRowid ){
81952
+ sqlite3DbFree(db, p->u.aRowid);
81953
+ p->nRowid = 0;
81954
+ }
81955
+}
81956
+#endif
81957
+
81958
+/* Initialize the BLOB value of a ROWID
81959
+*/
81960
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81961
+static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){
81962
+ assert( db!=0 );
81963
+ if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
81964
+ p->u.aRowid = sqlite3DbMallocRaw(db, n);
81965
+ if( p->u.aRowid ){
81966
+ p->nRowid = n;
81967
+ memcpy(p->u.aRowid, pData, n);
81968
+ }else{
81969
+ p->nRowid = 0;
81970
+ }
81971
+}
81972
+#endif
81973
+
81974
+/* Initialize the INTEGER value of a ROWID.
81975
+*/
81976
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81977
+static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){
81978
+ assert( db!=0 );
81979
+ if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
81980
+ p->nRowid = 0;
81981
+ p->u.iRowid = iRowid;
81982
+}
81983
+#endif
81984
+
81985
+
81986
+/*
81987
+** Copy the contents of object (*pFrom) into (*pTo).
81988
+*/
81989
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81990
+static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){
81991
+ pTo->isPSample = pFrom->isPSample;
81992
+ pTo->iCol = pFrom->iCol;
81993
+ pTo->iHash = pFrom->iHash;
81994
+ memcpy(pTo->anEq, pFrom->anEq, sizeof(tRowcnt)*p->nCol);
81995
+ memcpy(pTo->anLt, pFrom->anLt, sizeof(tRowcnt)*p->nCol);
81996
+ memcpy(pTo->anDLt, pFrom->anDLt, sizeof(tRowcnt)*p->nCol);
81997
+ if( pFrom->nRowid ){
81998
+ sampleSetRowid(p->db, pTo, pFrom->nRowid, pFrom->u.aRowid);
81999
+ }else{
82000
+ sampleSetRowidInt64(p->db, pTo, pFrom->u.iRowid);
82001
+ }
82002
+}
82003
+#endif
82004
+
82005
+/*
82006
+** Reclaim all memory of a Stat4Accum structure.
82007
+*/
82008
+static void stat4Destructor(void *pOld){
82009
+ Stat4Accum *p = (Stat4Accum*)pOld;
82010
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
82011
+ int i;
82012
+ for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
82013
+ for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
82014
+ sampleClear(p->db, &p->current);
82015
+#endif
82016
+ sqlite3DbFree(p->db, p);
82017
+}
8157582018
8157682019
/*
8157782020
** Implementation of the stat_init(N,C) SQL function. The two parameters
8157882021
** are the number of rows in the table or index (C) and the number of columns
8157982022
** in the index (N). The second argument (C) is only used for STAT3 and STAT4.
@@ -81589,10 +82032,11 @@
8158982032
){
8159082033
Stat4Accum *p;
8159182034
int nCol; /* Number of columns in index being sampled */
8159282035
int nColUp; /* nCol rounded up for alignment */
8159382036
int n; /* Bytes of space to allocate */
82037
+ sqlite3 *db; /* Database connection */
8159482038
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
8159582039
int mxSample = SQLITE_STAT4_SAMPLES;
8159682040
#endif
8159782041
8159882042
/* Decode the three function arguments */
@@ -81605,20 +82049,22 @@
8160582049
n = sizeof(*p)
8160682050
+ sizeof(tRowcnt)*nColUp /* Stat4Accum.anEq */
8160782051
+ sizeof(tRowcnt)*nColUp /* Stat4Accum.anDLt */
8160882052
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
8160982053
+ sizeof(tRowcnt)*nColUp /* Stat4Accum.anLt */
81610
- + sizeof(Stat4Sample)*(nCol+mxSample) /* Stat4Accum.aBest[], a[] */
82054
+ + sizeof(Stat4Sample)*(nCol+mxSample) /* Stat4Accum.aBest[], a[] */
8161182055
+ sizeof(tRowcnt)*3*nColUp*(nCol+mxSample)
8161282056
#endif
8161382057
;
81614
- p = sqlite3MallocZero(n);
82058
+ db = sqlite3_context_db_handle(context);
82059
+ p = sqlite3DbMallocZero(db, n);
8161582060
if( p==0 ){
8161682061
sqlite3_result_error_nomem(context);
8161782062
return;
8161882063
}
8161982064
82065
+ p->db = db;
8162082066
p->nRow = 0;
8162182067
p->nCol = nCol;
8162282068
p->current.anDLt = (tRowcnt*)&p[1];
8162382069
p->current.anEq = &p->current.anDLt[nColUp];
8162482070
@@ -81649,11 +82095,11 @@
8164982095
}
8165082096
}
8165182097
#endif
8165282098
8165382099
/* Return a pointer to the allocated object to the caller */
81654
- sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
82100
+ sqlite3_result_blob(context, p, sizeof(p), stat4Destructor);
8165582101
}
8165682102
static const FuncDef statInitFuncdef = {
8165782103
1+IsStat34, /* nArg */
8165882104
SQLITE_UTF8, /* funcFlags */
8165982105
0, /* pUserData */
@@ -81723,29 +82169,16 @@
8172382169
#else
8172482170
return (nEqNew==nEqOld && pNew->iHash>pOld->iHash);
8172582171
#endif
8172682172
}
8172782173
81728
-/*
81729
-** Copy the contents of object (*pFrom) into (*pTo).
81730
-*/
81731
-static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){
81732
- pTo->iRowid = pFrom->iRowid;
81733
- pTo->isPSample = pFrom->isPSample;
81734
- pTo->iCol = pFrom->iCol;
81735
- pTo->iHash = pFrom->iHash;
81736
- memcpy(pTo->anEq, pFrom->anEq, sizeof(tRowcnt)*p->nCol);
81737
- memcpy(pTo->anLt, pFrom->anLt, sizeof(tRowcnt)*p->nCol);
81738
- memcpy(pTo->anDLt, pFrom->anDLt, sizeof(tRowcnt)*p->nCol);
81739
-}
81740
-
8174182174
/*
8174282175
** Copy the contents of sample *pNew into the p->a[] array. If necessary,
8174382176
** remove the least desirable sample from p->a[] to make room.
8174482177
*/
8174582178
static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
81746
- Stat4Sample *pSample;
82179
+ Stat4Sample *pSample = 0;
8174782180
int i;
8174882181
8174982182
assert( IsStat4 || nEqZero==0 );
8175082183
8175182184
#ifdef SQLITE_ENABLE_STAT4
@@ -81781,12 +82214,14 @@
8178182214
if( p->nSample>=p->mxSample ){
8178282215
Stat4Sample *pMin = &p->a[p->iMin];
8178382216
tRowcnt *anEq = pMin->anEq;
8178482217
tRowcnt *anLt = pMin->anLt;
8178582218
tRowcnt *anDLt = pMin->anDLt;
82219
+ sampleClear(p->db, pMin);
8178682220
memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-p->iMin-1));
8178782221
pSample = &p->a[p->nSample-1];
82222
+ pSample->nRowid = 0;
8178882223
pSample->anEq = anEq;
8178982224
pSample->anDLt = anDLt;
8179082225
pSample->anLt = anLt;
8179182226
p->nSample = p->mxSample-1;
8179282227
}
@@ -81879,20 +82314,21 @@
8187982314
UNUSED_PARAMETER( iChng );
8188082315
#endif
8188182316
}
8188282317
8188382318
/*
81884
-** Implementation of the stat_push SQL function: stat_push(P,R,C)
82319
+** Implementation of the stat_push SQL function: stat_push(P,C,R)
8188582320
** Arguments:
8188682321
**
8188782322
** P Pointer to the Stat4Accum object created by stat_init()
8188882323
** C Index of left-most column to differ from previous row
81889
-** R Rowid for the current row
82324
+** R Rowid for the current row. Might be a key record for
82325
+** WITHOUT ROWID tables.
8189082326
**
8189182327
** The SQL function always returns NULL.
8189282328
**
81893
-** The R parameter is only used for STAT3 and STAT4.
82329
+** The R parameter is only used for STAT3 and STAT4
8189482330
*/
8189582331
static void statPush(
8189682332
sqlite3_context *context,
8189782333
int argc,
8189882334
sqlite3_value **argv
@@ -81928,11 +82364,16 @@
8192882364
p->current.anEq[i] = 1;
8192982365
}
8193082366
}
8193182367
p->nRow++;
8193282368
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81933
- p->current.iRowid = sqlite3_value_int64(argv[2]);
82369
+ if( sqlite3_value_type(argv[2])==SQLITE_INTEGER ){
82370
+ sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2]));
82371
+ }else{
82372
+ sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
82373
+ sqlite3_value_blob(argv[2]));
82374
+ }
8193482375
p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345;
8193582376
#endif
8193682377
8193782378
#ifdef SQLITE_ENABLE_STAT4
8193882379
{
@@ -82052,11 +82493,17 @@
8205282493
if( p->iGet<0 ){
8205382494
samplePushPrevious(p, 0);
8205482495
p->iGet = 0;
8205582496
}
8205682497
if( p->iGet<p->nSample ){
82057
- sqlite3_result_int64(context, p->a[p->iGet].iRowid);
82498
+ Stat4Sample *pS = p->a + p->iGet;
82499
+ if( pS->nRowid==0 ){
82500
+ sqlite3_result_int64(context, pS->u.iRowid);
82501
+ }else{
82502
+ sqlite3_result_blob(context, pS->u.aRowid, pS->nRowid,
82503
+ SQLITE_TRANSIENT);
82504
+ }
8205882505
}
8205982506
}else{
8206082507
tRowcnt *aCnt = 0;
8206182508
8206282509
assert( p->iGet<p->nSample );
@@ -82189,26 +82636,30 @@
8218982636
sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
8219082637
sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
8219182638
8219282639
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
8219382640
int nCol; /* Number of columns indexed by pIdx */
82194
- KeyInfo *pKey; /* KeyInfo structure for pIdx */
8219582641
int *aGotoChng; /* Array of jump instruction addresses */
8219682642
int addrRewind; /* Address of "OP_Rewind iIdxCur" */
8219782643
int addrGotoChng0; /* Address of "Goto addr_chng_0" */
8219882644
int addrNextRow; /* Address of "next_row:" */
82645
+ const char *zIdxName; /* Name of the index */
8219982646
8220082647
if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
8220182648
if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
8220282649
VdbeNoopComment((v, "Begin analysis of %s", pIdx->zName));
82203
- nCol = pIdx->nColumn;
82650
+ nCol = pIdx->nKeyCol;
8220482651
aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
8220582652
if( aGotoChng==0 ) continue;
82206
- pKey = sqlite3IndexKeyinfo(pParse, pIdx);
8220782653
8220882654
/* Populate the register containing the index name. */
82209
- sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
82655
+ if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
82656
+ zIdxName = pTab->zName;
82657
+ }else{
82658
+ zIdxName = pIdx->zName;
82659
+ }
82660
+ sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
8221082661
8221182662
/*
8221282663
** Pseudo-code for loop that calls stat_push():
8221382664
**
8221482665
** Rewind csr
@@ -82247,11 +82698,11 @@
8224782698
pParse->nMem = MAX(pParse->nMem, regPrev+nCol);
8224882699
8224982700
/* Open a read-only cursor on the index being analyzed. */
8225082701
assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
8225182702
sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
82252
- sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
82703
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
8225382704
VdbeComment((v, "%s", pIdx->zName));
8225482705
8225582706
/* Invoke the stat_init() function. The arguments are:
8225682707
**
8225782708
** (1) the number of columns in the index including the rowid,
@@ -82321,12 +82772,25 @@
8232182772
** Next csr
8232282773
** if !eof(csr) goto next_row;
8232382774
*/
8232482775
sqlite3VdbeJumpHere(v, aGotoChng[nCol]);
8232582776
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
82326
- sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
8232782777
assert( regRowid==(regStat4+2) );
82778
+ if( HasRowid(pTab) ){
82779
+ sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
82780
+ }else{
82781
+ Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
82782
+ int j, k, regKey;
82783
+ regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
82784
+ for(j=0; j<pPk->nKeyCol; j++){
82785
+ k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
82786
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
82787
+ VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
82788
+ }
82789
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
82790
+ sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
82791
+ }
8232882792
#endif
8232982793
assert( regChng==(regStat4+1) );
8233082794
sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
8233182795
sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
8233282796
sqlite3VdbeChangeP5(v, 2+IsStat34);
@@ -82348,26 +82812,27 @@
8234882812
int regSample = regStat1+3;
8234982813
int regCol = regStat1+4;
8235082814
int regSampleRowid = regCol + nCol;
8235182815
int addrNext;
8235282816
int addrIsNull;
82817
+ u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
8235382818
8235482819
pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
8235582820
8235682821
addrNext = sqlite3VdbeCurrentAddr(v);
8235782822
callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
8235882823
addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
8235982824
callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
8236082825
callStatGet(v, regStat4, STAT_GET_NLT, regLt);
8236182826
callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
82362
- sqlite3VdbeAddOp3(v, OP_NotExists, iTabCur, addrNext, regSampleRowid);
82827
+ sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
8236382828
#ifdef SQLITE_ENABLE_STAT3
8236482829
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
8236582830
pIdx->aiColumn[0], regSample);
8236682831
#else
8236782832
for(i=0; i<nCol; i++){
82368
- int iCol = pIdx->aiColumn[i];
82833
+ i16 iCol = pIdx->aiColumn[i];
8236982834
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
8237082835
}
8237182836
sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
8237282837
#endif
8237382838
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0);
@@ -82619,11 +83084,11 @@
8261983084
pIndex = 0;
8262083085
}
8262183086
z = argv[2];
8262283087
8262383088
if( pIndex ){
82624
- decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst, pIndex);
83089
+ decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
8262583090
if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0];
8262683091
}else{
8262783092
Index fakeIdx;
8262883093
fakeIdx.szIdxRow = pTable->szTabRow;
8262983094
decodeIntArray((char*)z, 1, &pTable->nRowEst, &fakeIdx);
@@ -82665,11 +83130,11 @@
8266583130
static void initAvgEq(Index *pIdx){
8266683131
if( pIdx ){
8266783132
IndexSample *aSample = pIdx->aSample;
8266883133
IndexSample *pFinal = &aSample[pIdx->nSample-1];
8266983134
int iCol;
82670
- for(iCol=0; iCol<pIdx->nColumn; iCol++){
83135
+ for(iCol=0; iCol<pIdx->nKeyCol; iCol++){
8267183136
int i; /* Used to iterate through samples */
8267283137
tRowcnt sumEq = 0; /* Sum of the nEq values */
8267383138
tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
8267483139
tRowcnt avgEq = 0;
8267583140
tRowcnt nDLt = pFinal->anDLt[iCol];
@@ -82692,10 +83157,27 @@
8269283157
pIdx->aAvgEq[iCol] = avgEq;
8269383158
if( pIdx->nSampleCol==1 ) break;
8269483159
}
8269583160
}
8269683161
}
83162
+
83163
+/*
83164
+** Look up an index by name. Or, if the name of a WITHOUT ROWID table
83165
+** is supplied instead, find the PRIMARY KEY index for that table.
83166
+*/
83167
+static Index *findIndexOrPrimaryKey(
83168
+ sqlite3 *db,
83169
+ const char *zName,
83170
+ const char *zDb
83171
+){
83172
+ Index *pIdx = sqlite3FindIndex(db, zName, zDb);
83173
+ if( pIdx==0 ){
83174
+ Table *pTab = sqlite3FindTable(db, zName, zDb);
83175
+ if( pTab && !HasRowid(pTab) ) pIdx = sqlite3PrimaryKeyIndex(pTab);
83176
+ }
83177
+ return pIdx;
83178
+}
8269783179
8269883180
/*
8269983181
** Load the content from either the sqlite_stat4 or sqlite_stat3 table
8270083182
** into the relevant Index.aSample[] arrays.
8270183183
**
@@ -82742,18 +83224,18 @@
8274283224
tRowcnt *pSpace;
8274383225
8274483226
zIndex = (char *)sqlite3_column_text(pStmt, 0);
8274583227
if( zIndex==0 ) continue;
8274683228
nSample = sqlite3_column_int(pStmt, 1);
82747
- pIdx = sqlite3FindIndex(db, zIndex, zDb);
83229
+ pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
8274883230
assert( pIdx==0 || bStat3 || pIdx->nSample==0 );
8274983231
/* Index.nSample is non-zero at this point if data has already been
8275083232
** loaded from the stat4 table. In this case ignore stat3 data. */
8275183233
if( pIdx==0 || pIdx->nSample ) continue;
8275283234
if( bStat3==0 ){
82753
- nIdxCol = pIdx->nColumn+1;
82754
- nAvgCol = pIdx->nColumn;
83235
+ nIdxCol = pIdx->nKeyCol+1;
83236
+ nAvgCol = pIdx->nKeyCol;
8275583237
}
8275683238
pIdx->nSampleCol = nIdxCol;
8275783239
nByte = sizeof(IndexSample) * nSample;
8275883240
nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
8275983241
nByte += nAvgCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
@@ -82788,11 +83270,11 @@
8278883270
Index *pIdx; /* Pointer to the index object */
8278983271
int nCol = 1; /* Number of columns in index */
8279083272
8279183273
zIndex = (char *)sqlite3_column_text(pStmt, 0);
8279283274
if( zIndex==0 ) continue;
82793
- pIdx = sqlite3FindIndex(db, zIndex, zDb);
83275
+ pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
8279483276
if( pIdx==0 ) continue;
8279583277
/* This next condition is true if data has already been loaded from
8279683278
** the sqlite_stat4 table. In this case ignore stat3 data. */
8279783279
nCol = pIdx->nSampleCol;
8279883280
if( bStat3 && nCol>1 ) continue;
@@ -84144,12 +84626,14 @@
8414484626
*/
8414584627
static void freeIndex(sqlite3 *db, Index *p){
8414684628
#ifndef SQLITE_OMIT_ANALYZE
8414784629
sqlite3DeleteIndexSamples(db, p);
8414884630
#endif
84631
+ if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
8414984632
sqlite3ExprDelete(db, p->pPartIdxWhere);
8415084633
sqlite3DbFree(db, p->zColAff);
84634
+ if( p->isResized ) sqlite3DbFree(db, p->azColl);
8415184635
sqlite3DbFree(db, p);
8415284636
}
8415384637
8415484638
/*
8415584639
** For the index called zIdxName which is found in the database iDb,
@@ -84403,12 +84887,11 @@
8440384887
** writing. The table is opened using cursor 0.
8440484888
*/
8440584889
SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
8440684890
Vdbe *v = sqlite3GetVdbe(p);
8440784891
sqlite3TableLock(p, iDb, MASTER_ROOT, 1, SCHEMA_TABLE(iDb));
84408
- sqlite3VdbeAddOp3(v, OP_OpenWrite, 0, MASTER_ROOT, iDb);
84409
- sqlite3VdbeChangeP4(v, -1, (char *)5, P4_INT32); /* 5 column table */
84892
+ sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5);
8441084893
if( p->nTab==0 ){
8441184894
p->nTab = 1;
8441284895
}
8441384896
}
8441484897
@@ -84508,10 +84991,31 @@
8450884991
sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s", zName);
8450984992
return SQLITE_ERROR;
8451084993
}
8451184994
return SQLITE_OK;
8451284995
}
84996
+
84997
+/*
84998
+** Return the PRIMARY KEY index of a table
84999
+*/
85000
+SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
85001
+ Index *p;
85002
+ for(p=pTab->pIndex; p && p->autoIndex!=2; p=p->pNext){}
85003
+ return p;
85004
+}
85005
+
85006
+/*
85007
+** Return the column of index pIdx that corresponds to table
85008
+** column iCol. Return -1 if not found.
85009
+*/
85010
+SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index *pIdx, i16 iCol){
85011
+ int i;
85012
+ for(i=0; i<pIdx->nColumn; i++){
85013
+ if( iCol==pIdx->aiColumn[i] ) return i;
85014
+ }
85015
+ return -1;
85016
+}
8451385017
8451485018
/*
8451585019
** Begin constructing a new table representation in memory. This is
8451685020
** the first of several action routines that get called in response
8451785021
** to a CREATE TABLE statement. In particular, this routine is called
@@ -84708,11 +85212,11 @@
8470885212
if( isView || isVirtual ){
8470985213
sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
8471085214
}else
8471185215
#endif
8471285216
{
84713
- sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
85217
+ pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
8471485218
}
8471585219
sqlite3OpenMasterTable(pParse, iDb);
8471685220
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
8471785221
sqlite3VdbeAddOp2(v, OP_Null, 0, reg3);
8471885222
sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
@@ -84976,10 +85480,11 @@
8497685480
int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */
8497785481
){
8497885482
Table *pTab = pParse->pNewTable;
8497985483
char *zType = 0;
8498085484
int iCol = -1, i;
85485
+ int nTerm;
8498185486
if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
8498285487
if( pTab->tabFlags & TF_HasPrimaryKey ){
8498385488
sqlite3ErrorMsg(pParse,
8498485489
"table \"%s\" has more than one primary key", pTab->zName);
8498585490
goto primary_key_exit;
@@ -84986,43 +85491,47 @@
8498685491
}
8498785492
pTab->tabFlags |= TF_HasPrimaryKey;
8498885493
if( pList==0 ){
8498985494
iCol = pTab->nCol - 1;
8499085495
pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
85496
+ zType = pTab->aCol[iCol].zType;
85497
+ nTerm = 1;
8499185498
}else{
84992
- for(i=0; i<pList->nExpr; i++){
85499
+ nTerm = pList->nExpr;
85500
+ for(i=0; i<nTerm; i++){
8499385501
for(iCol=0; iCol<pTab->nCol; iCol++){
8499485502
if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
85503
+ pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
85504
+ zType = pTab->aCol[iCol].zType;
8499585505
break;
8499685506
}
8499785507
}
84998
- if( iCol<pTab->nCol ){
84999
- pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
85000
- }
85001
- }
85002
- if( pList->nExpr>1 ) iCol = -1;
85003
- }
85004
- if( iCol>=0 && iCol<pTab->nCol ){
85005
- zType = pTab->aCol[iCol].zType;
85006
- }
85007
- if( zType && sqlite3StrICmp(zType, "INTEGER")==0
85008
- && sortOrder==SQLITE_SO_ASC ){
85508
+ }
85509
+ }
85510
+ if( nTerm==1
85511
+ && zType && sqlite3StrICmp(zType, "INTEGER")==0
85512
+ && sortOrder==SQLITE_SO_ASC
85513
+ ){
8500985514
pTab->iPKey = iCol;
8501085515
pTab->keyConf = (u8)onError;
8501185516
assert( autoInc==0 || autoInc==1 );
8501285517
pTab->tabFlags |= autoInc*TF_Autoincrement;
85518
+ if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
8501385519
}else if( autoInc ){
8501485520
#ifndef SQLITE_OMIT_AUTOINCREMENT
8501585521
sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
8501685522
"INTEGER PRIMARY KEY");
8501785523
#endif
8501885524
}else{
85525
+ Vdbe *v = pParse->pVdbe;
8501985526
Index *p;
85527
+ if( v ) pParse->addrSkipPK = sqlite3VdbeAddOp0(v, OP_Noop);
8502085528
p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
8502185529
0, sortOrder, 0);
8502285530
if( p ){
8502385531
p->autoIndex = 2;
85532
+ if( v ) sqlite3VdbeJumpHere(v, pParse->addrSkipPK);
8502485533
}
8502585534
pList = 0;
8502685535
}
8502785536
8502885537
primary_key_exit:
@@ -85075,11 +85584,11 @@
8507585584
/* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
8507685585
** then an index may have been created on this column before the
8507785586
** collation type was added. Correct this if it is the case.
8507885587
*/
8507985588
for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
85080
- assert( pIdx->nColumn==1 );
85589
+ assert( pIdx->nKeyCol==1 );
8508185590
if( pIdx->aiColumn[0]==i ){
8508285591
pIdx->azColl[0] = p->aCol[i].zColl;
8508385592
}
8508485593
}
8508585594
}else{
@@ -85266,10 +85775,35 @@
8526685775
assert( k<=n );
8526785776
}
8526885777
sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd);
8526985778
return zStmt;
8527085779
}
85780
+
85781
+/*
85782
+** Resize an Index object to hold N columns total. Return SQLITE_OK
85783
+** on success and SQLITE_NOMEM on an OOM error.
85784
+*/
85785
+static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){
85786
+ char *zExtra;
85787
+ int nByte;
85788
+ if( pIdx->nColumn>=N ) return SQLITE_OK;
85789
+ assert( pIdx->isResized==0 );
85790
+ nByte = (sizeof(char*) + sizeof(i16) + 1)*N;
85791
+ zExtra = sqlite3DbMallocZero(db, nByte);
85792
+ if( zExtra==0 ) return SQLITE_NOMEM;
85793
+ memcpy(zExtra, pIdx->azColl, sizeof(char*)*pIdx->nColumn);
85794
+ pIdx->azColl = (char**)zExtra;
85795
+ zExtra += sizeof(char*)*N;
85796
+ memcpy(zExtra, pIdx->aiColumn, sizeof(i16)*pIdx->nColumn);
85797
+ pIdx->aiColumn = (i16*)zExtra;
85798
+ zExtra += sizeof(i16)*N;
85799
+ memcpy(zExtra, pIdx->aSortOrder, pIdx->nColumn);
85800
+ pIdx->aSortOrder = (u8*)zExtra;
85801
+ pIdx->nColumn = N;
85802
+ pIdx->isResized = 1;
85803
+ return SQLITE_OK;
85804
+}
8527185805
8527285806
/*
8527385807
** Estimate the total row width for a table.
8527485808
*/
8527585809
static void estimateTableWidth(Table *pTab){
@@ -85285,19 +85819,151 @@
8528585819
8528685820
/*
8528785821
** Estimate the average size of a row for an index.
8528885822
*/
8528985823
static void estimateIndexWidth(Index *pIdx){
85290
- unsigned wIndex = 1;
85824
+ unsigned wIndex = 0;
8529185825
int i;
8529285826
const Column *aCol = pIdx->pTable->aCol;
8529385827
for(i=0; i<pIdx->nColumn; i++){
85294
- assert( pIdx->aiColumn[i]>=0 && pIdx->aiColumn[i]<pIdx->pTable->nCol );
85295
- wIndex += aCol[pIdx->aiColumn[i]].szEst;
85828
+ i16 x = pIdx->aiColumn[i];
85829
+ assert( x<pIdx->pTable->nCol );
85830
+ wIndex += x<0 ? 1 : aCol[pIdx->aiColumn[i]].szEst;
8529685831
}
8529785832
pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
8529885833
}
85834
+
85835
+/* Return true if value x is found any of the first nCol entries of aiCol[]
85836
+*/
85837
+static int hasColumn(const i16 *aiCol, int nCol, int x){
85838
+ while( nCol-- > 0 ) if( x==*(aiCol++) ) return 1;
85839
+ return 0;
85840
+}
85841
+
85842
+/*
85843
+** This routine runs at the end of parsing a CREATE TABLE statement that
85844
+** has a WITHOUT ROWID clause. The job of this routine is to convert both
85845
+** internal schema data structures and the generated VDBE code so that they
85846
+** are appropriate for a WITHOUT ROWID table instead of a rowid table.
85847
+** Changes include:
85848
+**
85849
+** (1) Convert the OP_CreateTable into an OP_CreateIndex. There is
85850
+** no rowid btree for a WITHOUT ROWID. Instead, the canonical
85851
+** data storage is a covering index btree.
85852
+** (2) Bypass the creation of the sqlite_master table entry
85853
+** for the PRIMARY KEY as the the primary key index is now
85854
+** identified by the sqlite_master table entry of the table itself.
85855
+** (3) Set the Index.tnum of the PRIMARY KEY Index object in the
85856
+** schema to the rootpage from the main table.
85857
+** (4) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
85858
+** (5) Add all table columns to the PRIMARY KEY Index object
85859
+** so that the PRIMARY KEY is a covering index. The surplus
85860
+** columns are part of KeyInfo.nXField and are not used for
85861
+** sorting or lookup or uniqueness checks.
85862
+** (6) Replace the rowid tail on all automatically generated UNIQUE
85863
+** indices with the PRIMARY KEY columns.
85864
+*/
85865
+static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
85866
+ Index *pIdx;
85867
+ Index *pPk;
85868
+ int nPk;
85869
+ int i, j;
85870
+ sqlite3 *db = pParse->db;
85871
+ Vdbe *v = pParse->pVdbe;
85872
+
85873
+ /* Convert the OP_CreateTable opcode that would normally create the
85874
+ ** root-page for the table into a OP_CreateIndex opcode. The index
85875
+ ** created will become the PRIMARY KEY index.
85876
+ */
85877
+ if( pParse->addrCrTab ){
85878
+ assert( v );
85879
+ sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
85880
+ }
85881
+
85882
+ /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
85883
+ ** table entry.
85884
+ */
85885
+ if( pParse->addrSkipPK ){
85886
+ assert( v );
85887
+ sqlite3VdbeGetOp(v, pParse->addrSkipPK)->opcode = OP_Goto;
85888
+ }
85889
+
85890
+ /* Locate the PRIMARY KEY index. Or, if this table was originally
85891
+ ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
85892
+ */
85893
+ if( pTab->iPKey>=0 ){
85894
+ ExprList *pList;
85895
+ pList = sqlite3ExprListAppend(pParse, 0, 0);
85896
+ if( pList==0 ) return;
85897
+ pList->a[0].zName = sqlite3DbStrDup(pParse->db,
85898
+ pTab->aCol[pTab->iPKey].zName);
85899
+ pList->a[0].sortOrder = pParse->iPkSortOrder;
85900
+ assert( pParse->pNewTable==pTab );
85901
+ pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
85902
+ if( pPk==0 ) return;
85903
+ pPk->autoIndex = 2;
85904
+ pTab->iPKey = -1;
85905
+ }else{
85906
+ pPk = sqlite3PrimaryKeyIndex(pTab);
85907
+ }
85908
+ pPk->isCovering = 1;
85909
+ assert( pPk!=0 );
85910
+ nPk = pPk->nKeyCol;
85911
+
85912
+ /* Make sure every column of the PRIMARY KEY is NOT NULL */
85913
+ for(i=0; i<nPk; i++){
85914
+ pTab->aCol[pPk->aiColumn[i]].notNull = 1;
85915
+ }
85916
+ pPk->uniqNotNull = 1;
85917
+
85918
+ /* The root page of the PRIMARY KEY is the table root page */
85919
+ pPk->tnum = pTab->tnum;
85920
+
85921
+ /* Update the in-memory representation of all UNIQUE indices by converting
85922
+ ** the final rowid column into one or more columns of the PRIMARY KEY.
85923
+ */
85924
+ for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
85925
+ int n;
85926
+ if( pIdx->autoIndex==2 ) continue;
85927
+ for(i=n=0; i<nPk; i++){
85928
+ if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
85929
+ }
85930
+ if( n==0 ){
85931
+ /* This index is a superset of the primary key */
85932
+ pIdx->nColumn = pIdx->nKeyCol;
85933
+ continue;
85934
+ }
85935
+ if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
85936
+ for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
85937
+ if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ){
85938
+ pIdx->aiColumn[j] = pPk->aiColumn[i];
85939
+ pIdx->azColl[j] = pPk->azColl[i];
85940
+ j++;
85941
+ }
85942
+ }
85943
+ assert( pIdx->nColumn>=pIdx->nKeyCol+n );
85944
+ assert( pIdx->nColumn>=j );
85945
+ }
85946
+
85947
+ /* Add all table columns to the PRIMARY KEY index
85948
+ */
85949
+ if( nPk<pTab->nCol ){
85950
+ if( resizeIndexObject(db, pPk, pTab->nCol) ) return;
85951
+ for(i=0, j=nPk; i<pTab->nCol; i++){
85952
+ if( !hasColumn(pPk->aiColumn, j, i) ){
85953
+ assert( j<pPk->nColumn );
85954
+ pPk->aiColumn[j] = i;
85955
+ pPk->azColl[j] = "BINARY";
85956
+ j++;
85957
+ }
85958
+ }
85959
+ assert( pPk->nColumn==j );
85960
+ assert( pTab->nCol==j );
85961
+ }else{
85962
+ pPk->nColumn = pTab->nCol;
85963
+ }
85964
+}
8529985965
8530085966
/*
8530185967
** This routine is called to report the final ")" that terminates
8530285968
** a CREATE TABLE statement.
8530385969
**
@@ -85318,11 +85984,12 @@
8531885984
** the new table will match the result set of the SELECT.
8531985985
*/
8532085986
SQLITE_PRIVATE void sqlite3EndTable(
8532185987
Parse *pParse, /* Parse context */
8532285988
Token *pCons, /* The ',' token after the last column defn. */
85323
- Token *pEnd, /* The final ')' token in the CREATE TABLE */
85989
+ Token *pEnd, /* The ')' before options in the CREATE TABLE */
85990
+ u8 tabOpts, /* Extra table options. Usually 0. */
8532485991
Select *pSelect /* Select from a "CREATE ... AS SELECT" */
8532585992
){
8532685993
Table *p; /* The new table */
8532785994
sqlite3 *db = pParse->db; /* The database connection */
8532885995
int iDb; /* Database in which the table lives */
@@ -85333,10 +86000,35 @@
8533386000
}
8533486001
p = pParse->pNewTable;
8533586002
if( p==0 ) return;
8533686003
8533786004
assert( !db->init.busy || !pSelect );
86005
+
86006
+ /* If the db->init.busy is 1 it means we are reading the SQL off the
86007
+ ** "sqlite_master" or "sqlite_temp_master" table on the disk.
86008
+ ** So do not write to the disk again. Extract the root page number
86009
+ ** for the table from the db->init.newTnum field. (The page number
86010
+ ** should have been put there by the sqliteOpenCb routine.)
86011
+ */
86012
+ if( db->init.busy ){
86013
+ p->tnum = db->init.newTnum;
86014
+ }
86015
+
86016
+ /* Special processing for WITHOUT ROWID Tables */
86017
+ if( tabOpts & TF_WithoutRowid ){
86018
+ if( (p->tabFlags & TF_Autoincrement) ){
86019
+ sqlite3ErrorMsg(pParse,
86020
+ "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
86021
+ return;
86022
+ }
86023
+ if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
86024
+ sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
86025
+ }else{
86026
+ p->tabFlags |= TF_WithoutRowid;
86027
+ convertToWithoutRowidTable(pParse, p);
86028
+ }
86029
+ }
8533886030
8533986031
iDb = sqlite3SchemaToIndex(db, p->pSchema);
8534086032
8534186033
#ifndef SQLITE_OMIT_CHECK
8534286034
/* Resolve names in all CHECK constraint expressions.
@@ -85350,20 +86042,10 @@
8535086042
estimateTableWidth(p);
8535186043
for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
8535286044
estimateIndexWidth(pIdx);
8535386045
}
8535486046
85355
- /* If the db->init.busy is 1 it means we are reading the SQL off the
85356
- ** "sqlite_master" or "sqlite_temp_master" table on the disk.
85357
- ** So do not write to the disk again. Extract the root page number
85358
- ** for the table from the db->init.newTnum field. (The page number
85359
- ** should have been put there by the sqliteOpenCb routine.)
85360
- */
85361
- if( db->init.busy ){
85362
- p->tnum = db->init.newTnum;
85363
- }
85364
-
8536586047
/* If not initializing, then create a record for the new table
8536686048
** in the SQLITE_MASTER table of the database.
8536786049
**
8536886050
** If this is a TEMPORARY table, write the entry into the auxiliary
8536986051
** file instead of into the main database file.
@@ -85433,11 +86115,13 @@
8543386115
8543486116
/* Compute the complete text of the CREATE statement */
8543586117
if( pSelect ){
8543686118
zStmt = createTableStmt(db, p);
8543786119
}else{
85438
- n = (int)(pEnd->z - pParse->sNameToken.z) + 1;
86120
+ Token *pEnd2 = tabOpts ? &pParse->sLastToken : pEnd;
86121
+ n = (int)(pEnd2->z - pParse->sNameToken.z);
86122
+ if( pEnd2->z[0]!=';' ) n += pEnd2->n;
8543986123
zStmt = sqlite3MPrintf(db,
8544086124
"CREATE %s %.*s", zType2, n, pParse->sNameToken.z
8544186125
);
8544286126
}
8544386127
@@ -85476,11 +86160,11 @@
8547686160
}
8547786161
#endif
8547886162
8547986163
/* Reparse everything to update our internal data structures */
8548086164
sqlite3VdbeAddParseSchemaOp(v, iDb,
85481
- sqlite3MPrintf(db, "tbl_name='%q'", p->zName));
86165
+ sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
8548286166
}
8548386167
8548486168
8548586169
/* Add the table to the in-memory representation of the database.
8548686170
*/
@@ -85581,11 +86265,11 @@
8558186265
while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
8558286266
sEnd.z = &z[n-1];
8558386267
sEnd.n = 1;
8558486268
8558586269
/* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
85586
- sqlite3EndTable(pParse, 0, &sEnd, 0);
86270
+ sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
8558786271
return;
8558886272
}
8558986273
#endif /* SQLITE_OMIT_VIEW */
8559086274
8559186275
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -86036,12 +86720,12 @@
8603686720
/*
8603786721
** This routine is called to create a new foreign key on the table
8603886722
** currently under construction. pFromCol determines which columns
8603986723
** in the current table point to the foreign key. If pFromCol==0 then
8604086724
** connect the key to the last column inserted. pTo is the name of
86041
-** the table referred to. pToCol is a list of tables in the other
86042
-** pTo table that the foreign key points to. flags contains all
86725
+** the table referred to (a.k.a the "parent" table). pToCol is a list
86726
+** of tables in the parent pTo table. flags contains all
8604386727
** information about the conflict resolution algorithms specified
8604486728
** in the ON DELETE, ON UPDATE and ON INSERT clauses.
8604586729
**
8604686730
** An FKey structure is created and added to the table currently
8604786731
** under construction in the pParse->pNewTable field.
@@ -86220,41 +86904,43 @@
8622086904
if( v==0 ) return;
8622186905
if( memRootPage>=0 ){
8622286906
tnum = memRootPage;
8622386907
}else{
8622486908
tnum = pIndex->tnum;
86225
- sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
8622686909
}
86227
- pKey = sqlite3IndexKeyinfo(pParse, pIndex);
86228
- sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86229
- (char *)pKey, P4_KEYINFO_HANDOFF);
86230
- sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86910
+ pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
8623186911
8623286912
/* Open the sorter cursor if we are to use one. */
8623386913
iSorter = pParse->nTab++;
86234
- sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
86914
+ sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)
86915
+ sqlite3KeyInfoRef(pKey), P4_KEYINFO);
8623586916
8623686917
/* Open the table. Loop through all rows of the table, inserting index
8623786918
** records into the sorter. */
8623886919
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
8623986920
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
8624086921
regRecord = sqlite3GetTempReg(pParse);
8624186922
86242
- sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1, &iPartIdxLabel);
86923
+ sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 0, &iPartIdxLabel);
8624386924
sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
8624486925
sqlite3VdbeResolveLabel(v, iPartIdxLabel);
8624586926
sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
8624686927
sqlite3VdbeJumpHere(v, addr1);
86928
+ if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
86929
+ sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86930
+ (char *)pKey, P4_KEYINFO);
86931
+ sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86932
+
8624786933
addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
86248
- if( pIndex->onError!=OE_None ){
86934
+ assert( pKey!=0 || db->mallocFailed || pParse->nErr );
86935
+ if( pIndex->onError!=OE_None && pKey!=0 ){
8624986936
int j2 = sqlite3VdbeCurrentAddr(v) + 3;
8625086937
sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
8625186938
addr2 = sqlite3VdbeCurrentAddr(v);
86252
- sqlite3VdbeAddOp3(v, OP_SorterCompare, iSorter, j2, regRecord);
86253
- sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
86254
- OE_Abort, "indexed columns are not unique", P4_STATIC
86255
- );
86939
+ sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86940
+ pKey->nField - pIndex->nKeyCol);
86941
+ sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
8625686942
}else{
8625786943
addr2 = sqlite3VdbeCurrentAddr(v);
8625886944
}
8625986945
sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
8626086946
sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
@@ -86265,10 +86951,45 @@
8626586951
8626686952
sqlite3VdbeAddOp1(v, OP_Close, iTab);
8626786953
sqlite3VdbeAddOp1(v, OP_Close, iIdx);
8626886954
sqlite3VdbeAddOp1(v, OP_Close, iSorter);
8626986955
}
86956
+
86957
+/*
86958
+** Allocate heap space to hold an Index object with nCol columns.
86959
+**
86960
+** Increase the allocation size to provide an extra nExtra bytes
86961
+** of 8-byte aligned space after the Index object and return a
86962
+** pointer to this extra space in *ppExtra.
86963
+*/
86964
+SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(
86965
+ sqlite3 *db, /* Database connection */
86966
+ i16 nCol, /* Total number of columns in the index */
86967
+ int nExtra, /* Number of bytes of extra space to alloc */
86968
+ char **ppExtra /* Pointer to the "extra" space */
86969
+){
86970
+ Index *p; /* Allocated index object */
86971
+ int nByte; /* Bytes of space for Index object + arrays */
86972
+
86973
+ nByte = ROUND8(sizeof(Index)) + /* Index structure */
86974
+ ROUND8(sizeof(char*)*nCol) + /* Index.azColl */
86975
+ ROUND8(sizeof(tRowcnt)*(nCol+1) + /* Index.aiRowEst */
86976
+ sizeof(i16)*nCol + /* Index.aiColumn */
86977
+ sizeof(u8)*nCol); /* Index.aSortOrder */
86978
+ p = sqlite3DbMallocZero(db, nByte + nExtra);
86979
+ if( p ){
86980
+ char *pExtra = ((char*)p)+ROUND8(sizeof(Index));
86981
+ p->azColl = (char**)pExtra; pExtra += ROUND8(sizeof(char*)*nCol);
86982
+ p->aiRowEst = (tRowcnt*)pExtra; pExtra += sizeof(tRowcnt)*(nCol+1);
86983
+ p->aiColumn = (i16*)pExtra; pExtra += sizeof(i16)*nCol;
86984
+ p->aSortOrder = (u8*)pExtra;
86985
+ p->nColumn = nCol;
86986
+ p->nKeyCol = nCol - 1;
86987
+ *ppExtra = ((char*)p) + nByte;
86988
+ }
86989
+ return p;
86990
+}
8627086991
8627186992
/*
8627286993
** Create a new index for an SQL table. pName1.pName2 is the name of the index
8627386994
** and pTblList is the name of the table that is to be indexed. Both will
8627486995
** be NULL for a primary key or an index that is created to satisfy a
@@ -86300,22 +87021,22 @@
8630087021
Table *pTab = 0; /* Table to be indexed */
8630187022
Index *pIndex = 0; /* The index to be created */
8630287023
char *zName = 0; /* Name of the index */
8630387024
int nName; /* Number of characters in zName */
8630487025
int i, j;
86305
- Token nullId; /* Fake token for an empty ID list */
8630687026
DbFixer sFix; /* For assigning database names to pTable */
8630787027
int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
8630887028
sqlite3 *db = pParse->db;
8630987029
Db *pDb; /* The specific table containing the indexed database */
8631087030
int iDb; /* Index of the database that is being written */
8631187031
Token *pName = 0; /* Unqualified name of the index to create */
8631287032
struct ExprList_item *pListItem; /* For looping over pList */
8631387033
const Column *pTabCol; /* A column in the table */
86314
- int nCol; /* Number of columns */
8631587034
int nExtra = 0; /* Space allocated for zExtra[] */
87035
+ int nExtraCol; /* Number of extra columns needed */
8631687036
char *zExtra; /* Extra space after the Index object */
87037
+ Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
8631787038
8631887039
assert( pParse->nErr==0 ); /* Never called with prior errors */
8631987040
if( db->mallocFailed || IN_DECLARE_VTAB ){
8632087041
goto exit_create_index;
8632187042
}
@@ -86363,10 +87084,11 @@
8636387084
sqlite3ErrorMsg(pParse,
8636487085
"cannot create a TEMP index on non-TEMP table \"%s\"",
8636587086
pTab->zName);
8636687087
goto exit_create_index;
8636787088
}
87089
+ if( !HasRowid(pTab) ) pPk = sqlite3PrimaryKeyIndex(pTab);
8636887090
}else{
8636987091
assert( pName==0 );
8637087092
assert( pStart==0 );
8637187093
pTab = pParse->pNewTable;
8637287094
if( !pTab ) goto exit_create_index;
@@ -86458,15 +87180,14 @@
8645887180
/* If pList==0, it means this routine was called to make a primary
8645987181
** key out of the last column added to the table under construction.
8646087182
** So create a fake list to simulate this.
8646187183
*/
8646287184
if( pList==0 ){
86463
- nullId.z = pTab->aCol[pTab->nCol-1].zName;
86464
- nullId.n = sqlite3Strlen30((char*)nullId.z);
8646587185
pList = sqlite3ExprListAppend(pParse, 0, 0);
8646687186
if( pList==0 ) goto exit_create_index;
86467
- sqlite3ExprListSetName(pParse, pList, &nullId, 0);
87187
+ pList->a[0].zName = sqlite3DbStrDup(pParse->db,
87188
+ pTab->aCol[pTab->nCol-1].zName);
8646887189
pList->a[0].sortOrder = (u8)sortOrder;
8646987190
}
8647087191
8647187192
/* Figure out how many bytes of space are required to store explicitly
8647287193
** specified collation sequence names.
@@ -86481,40 +87202,27 @@
8648187202
8648287203
/*
8648387204
** Allocate the index structure.
8648487205
*/
8648587206
nName = sqlite3Strlen30(zName);
86486
- nCol = pList->nExpr;
86487
- pIndex = sqlite3DbMallocZero(db,
86488
- ROUND8(sizeof(Index)) + /* Index structure */
86489
- ROUND8(sizeof(tRowcnt)*(nCol+1)) + /* Index.aiRowEst */
86490
- sizeof(char *)*nCol + /* Index.azColl */
86491
- sizeof(int)*nCol + /* Index.aiColumn */
86492
- sizeof(u8)*nCol + /* Index.aSortOrder */
86493
- nName + 1 + /* Index.zName */
86494
- nExtra /* Collation sequence names */
86495
- );
87207
+ nExtraCol = pPk ? pPk->nKeyCol : 1;
87208
+ pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
87209
+ nName + nExtra + 1, &zExtra);
8649687210
if( db->mallocFailed ){
8649787211
goto exit_create_index;
8649887212
}
86499
- zExtra = (char*)pIndex;
86500
- pIndex->aiRowEst = (tRowcnt*)&zExtra[ROUND8(sizeof(Index))];
86501
- pIndex->azColl = (char**)
86502
- ((char*)pIndex->aiRowEst + ROUND8(sizeof(tRowcnt)*nCol+1));
8650387213
assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowEst) );
8650487214
assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
86505
- pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
86506
- pIndex->aSortOrder = (u8 *)(&pIndex->aiColumn[nCol]);
86507
- pIndex->zName = (char *)(&pIndex->aSortOrder[nCol]);
86508
- zExtra = (char *)(&pIndex->zName[nName+1]);
87215
+ pIndex->zName = zExtra;
87216
+ zExtra += nName + 1;
8650987217
memcpy(pIndex->zName, zName, nName+1);
8651087218
pIndex->pTable = pTab;
86511
- pIndex->nColumn = pList->nExpr;
8651287219
pIndex->onError = (u8)onError;
86513
- pIndex->uniqNotNull = onError==OE_Abort;
87220
+ pIndex->uniqNotNull = onError!=OE_None;
8651487221
pIndex->autoIndex = (u8)(pName==0);
8651587222
pIndex->pSchema = db->aDb[iDb].pSchema;
87223
+ pIndex->nKeyCol = pList->nExpr;
8651687224
if( pPIWhere ){
8651787225
sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
8651887226
pIndex->pPartIdxWhere = pPIWhere;
8651987227
pPIWhere = 0;
8652087228
}
@@ -86550,11 +87258,12 @@
8655087258
sqlite3ErrorMsg(pParse, "table %s has no column named %s",
8655187259
pTab->zName, zColName);
8655287260
pParse->checkSchema = 1;
8655387261
goto exit_create_index;
8655487262
}
86555
- pIndex->aiColumn[i] = j;
87263
+ assert( pTab->nCol<=0x7fff && j<=0x7fff );
87264
+ pIndex->aiColumn[i] = (i16)j;
8655687265
if( pListItem->pExpr ){
8655787266
int nColl;
8655887267
assert( pListItem->pExpr->op==TK_COLLATE );
8655987268
zColl = pListItem->pExpr->u.zToken;
8656087269
nColl = sqlite3Strlen30(zColl) + 1;
@@ -86573,10 +87282,27 @@
8657387282
pIndex->azColl[i] = zColl;
8657487283
requestedSortOrder = pListItem->sortOrder & sortOrderMask;
8657587284
pIndex->aSortOrder[i] = (u8)requestedSortOrder;
8657687285
if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
8657787286
}
87287
+ if( pPk ){
87288
+ for(j=0; j<pPk->nKeyCol; j++){
87289
+ int x = pPk->aiColumn[j];
87290
+ if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
87291
+ pIndex->nColumn--;
87292
+ }else{
87293
+ pIndex->aiColumn[i] = x;
87294
+ pIndex->azColl[i] = pPk->azColl[j];
87295
+ pIndex->aSortOrder[i] = pPk->aSortOrder[j];
87296
+ i++;
87297
+ }
87298
+ }
87299
+ assert( i==pIndex->nColumn );
87300
+ }else{
87301
+ pIndex->aiColumn[i] = -1;
87302
+ pIndex->azColl[i] = "BINARY";
87303
+ }
8657887304
sqlite3DefaultRowEst(pIndex);
8657987305
if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
8658087306
8658187307
if( pTab==pParse->pNewTable ){
8658287308
/* This routine has been called to create an automatic index as a
@@ -86605,20 +87331,20 @@
8660587331
int k;
8660687332
assert( pIdx->onError!=OE_None );
8660787333
assert( pIdx->autoIndex );
8660887334
assert( pIndex->onError!=OE_None );
8660987335
86610
- if( pIdx->nColumn!=pIndex->nColumn ) continue;
86611
- for(k=0; k<pIdx->nColumn; k++){
87336
+ if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
87337
+ for(k=0; k<pIdx->nKeyCol; k++){
8661287338
const char *z1;
8661387339
const char *z2;
8661487340
if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
8661587341
z1 = pIdx->azColl[k];
8661687342
z2 = pIndex->azColl[k];
8661787343
if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
8661887344
}
86619
- if( k==pIdx->nColumn ){
87345
+ if( k==pIdx->nKeyCol ){
8662087346
if( pIdx->onError!=pIndex->onError ){
8662187347
/* This constraint creates the same index as a previous
8662287348
** constraint specified somewhere in the CREATE TABLE statement.
8662387349
** However the ON CONFLICT clauses are different. If both this
8662487350
** constraint and the previous equivalent constraint have explicit
@@ -86656,26 +87382,24 @@
8665687382
if( pTblName!=0 ){
8665787383
pIndex->tnum = db->init.newTnum;
8665887384
}
8665987385
}
8666087386
86661
- /* If the db->init.busy is 0 then create the index on disk. This
86662
- ** involves writing the index into the master table and filling in the
86663
- ** index with the current table contents.
86664
- **
86665
- ** The db->init.busy is 0 when the user first enters a CREATE INDEX
86666
- ** command. db->init.busy is 1 when a database is opened and
86667
- ** CREATE INDEX statements are read out of the master table. In
86668
- ** the latter case the index already exists on disk, which is why
86669
- ** we don't want to recreate it.
86670
- **
86671
- ** If pTblName==0 it means this index is generated as a primary key
86672
- ** or UNIQUE constraint of a CREATE TABLE statement. Since the table
87387
+ /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
87388
+ ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
87389
+ ** emit code to allocate the index rootpage on disk and make an entry for
87390
+ ** the index in the sqlite_master table and populate the index with
87391
+ ** content. But, do not do this if we are simply reading the sqlite_master
87392
+ ** table to parse the schema, or if this index is the PRIMARY KEY index
87393
+ ** of a WITHOUT ROWID table.
87394
+ **
87395
+ ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
87396
+ ** or UNIQUE index in a CREATE TABLE statement. Since the table
8667387397
** has just been created, it contains no data and the index initialization
8667487398
** step can be skipped.
8667587399
*/
86676
- else if( pParse->nErr==0 ){
87400
+ else if( pParse->nErr==0 && (HasRowid(pTab) || pTblName!=0) ){
8667787401
Vdbe *v;
8667887402
char *zStmt;
8667987403
int iMem = ++pParse->nMem;
8668087404
8668187405
v = sqlite3GetVdbe(pParse);
@@ -86783,16 +87507,16 @@
8678387507
tRowcnt n;
8678487508
assert( a!=0 );
8678587509
a[0] = pIdx->pTable->nRowEst;
8678687510
if( a[0]<10 ) a[0] = 10;
8678787511
n = 10;
86788
- for(i=1; i<=pIdx->nColumn; i++){
87512
+ for(i=1; i<=pIdx->nKeyCol; i++){
8678987513
a[i] = n;
8679087514
if( n>5 ) n--;
8679187515
}
8679287516
if( pIdx->onError!=OE_None ){
86793
- a[pIdx->nColumn] = 1;
87517
+ a[pIdx->nKeyCol] = 1;
8679487518
}
8679587519
}
8679687520
8679787521
/*
8679887522
** This routine will drop an existing named index. This routine
@@ -87476,18 +88200,71 @@
8747688200
SQLITE_PRIVATE void sqlite3HaltConstraint(
8747788201
Parse *pParse, /* Parsing context */
8747888202
int errCode, /* extended error code */
8747988203
int onError, /* Constraint type */
8748088204
char *p4, /* Error message */
87481
- int p4type /* P4_STATIC or P4_TRANSIENT */
88205
+ i8 p4type, /* P4_STATIC or P4_TRANSIENT */
88206
+ u8 p5Errmsg /* P5_ErrMsg type */
8748288207
){
8748388208
Vdbe *v = sqlite3GetVdbe(pParse);
8748488209
assert( (errCode&0xff)==SQLITE_CONSTRAINT );
8748588210
if( onError==OE_Abort ){
8748688211
sqlite3MayAbort(pParse);
8748788212
}
8748888213
sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
88214
+ if( p5Errmsg ) sqlite3VdbeChangeP5(v, p5Errmsg);
88215
+}
88216
+
88217
+/*
88218
+** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation.
88219
+*/
88220
+SQLITE_PRIVATE void sqlite3UniqueConstraint(
88221
+ Parse *pParse, /* Parsing context */
88222
+ int onError, /* Constraint type */
88223
+ Index *pIdx /* The index that triggers the constraint */
88224
+){
88225
+ char *zErr;
88226
+ int j;
88227
+ StrAccum errMsg;
88228
+ Table *pTab = pIdx->pTable;
88229
+
88230
+ sqlite3StrAccumInit(&errMsg, 0, 0, 200);
88231
+ errMsg.db = pParse->db;
88232
+ for(j=0; j<pIdx->nKeyCol; j++){
88233
+ char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
88234
+ if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
88235
+ sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
88236
+ sqlite3StrAccumAppend(&errMsg, ".", 1);
88237
+ sqlite3StrAccumAppend(&errMsg, zCol, -1);
88238
+ }
88239
+ zErr = sqlite3StrAccumFinish(&errMsg);
88240
+ sqlite3HaltConstraint(pParse,
88241
+ (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
88242
+ onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
88243
+}
88244
+
88245
+
88246
+/*
88247
+** Code an OP_Halt due to non-unique rowid.
88248
+*/
88249
+SQLITE_PRIVATE void sqlite3RowidConstraint(
88250
+ Parse *pParse, /* Parsing context */
88251
+ int onError, /* Conflict resolution algorithm */
88252
+ Table *pTab /* The table with the non-unique rowid */
88253
+){
88254
+ char *zMsg;
88255
+ int rc;
88256
+ if( pTab->iPKey>=0 ){
88257
+ zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
88258
+ pTab->aCol[pTab->iPKey].zName);
88259
+ rc = SQLITE_CONSTRAINT_PRIMARYKEY;
88260
+ }else{
88261
+ zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
88262
+ rc = SQLITE_CONSTRAINT_ROWID;
88263
+ }
88264
+ sqlite3HaltConstraint(pParse, rc, onError, zMsg, P4_DYNAMIC,
88265
+ P5_ConstraintUnique);
8748988266
}
8749088267
8749188268
/*
8749288269
** Check to see if pIndex uses the collating sequence pColl. Return
8749388270
** true if it does and false if it does not.
@@ -87496,12 +88273,12 @@
8749688273
static int collationMatch(const char *zColl, Index *pIndex){
8749788274
int i;
8749888275
assert( zColl!=0 );
8749988276
for(i=0; i<pIndex->nColumn; i++){
8750088277
const char *z = pIndex->azColl[i];
87501
- assert( z!=0 );
87502
- if( 0==sqlite3StrICmp(z, zColl) ){
88278
+ assert( z!=0 || pIndex->aiColumn[i]<0 );
88279
+ if( pIndex->aiColumn[i]>=0 && 0==sqlite3StrICmp(z, zColl) ){
8750388280
return 1;
8750488281
}
8750588282
}
8750688283
return 0;
8750788284
}
@@ -87616,39 +88393,53 @@
8761688393
sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
8761788394
}
8761888395
#endif
8761988396
8762088397
/*
87621
-** Return a dynamicly allocated KeyInfo structure that can be used
87622
-** with OP_OpenRead or OP_OpenWrite to access database index pIdx.
87623
-**
87624
-** If successful, a pointer to the new structure is returned. In this case
87625
-** the caller is responsible for calling sqlite3DbFree(db, ) on the returned
87626
-** pointer. If an error occurs (out of memory or missing collation
87627
-** sequence), NULL is returned and the state of pParse updated to reflect
87628
-** the error.
87629
-*/
87630
-SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){
87631
- int i;
87632
- int nCol = pIdx->nColumn;
87633
- KeyInfo *pKey;
87634
-
87635
- pKey = sqlite3KeyInfoAlloc(pParse->db, nCol);
87636
- if( pKey ){
87637
- for(i=0; i<nCol; i++){
87638
- char *zColl = pIdx->azColl[i];
87639
- assert( zColl );
87640
- pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
87641
- pKey->aSortOrder[i] = pIdx->aSortOrder[i];
87642
- }
87643
- }
87644
-
87645
- if( pParse->nErr ){
87646
- sqlite3DbFree(pParse->db, pKey);
87647
- pKey = 0;
87648
- }
87649
- return pKey;
88398
+** Return a KeyInfo structure that is appropriate for the given Index.
88399
+**
88400
+** The KeyInfo structure for an index is cached in the Index object.
88401
+** So there might be multiple references to the returned pointer. The
88402
+** caller should not try to modify the KeyInfo object.
88403
+**
88404
+** The caller should invoke sqlite3KeyInfoUnref() on the returned object
88405
+** when it has finished using it.
88406
+*/
88407
+SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
88408
+ if( pParse->nErr ) return 0;
88409
+#ifndef SQLITE_OMIT_SHARED_CACHE
88410
+ if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){
88411
+ sqlite3KeyInfoUnref(pIdx->pKeyInfo);
88412
+ pIdx->pKeyInfo = 0;
88413
+ }
88414
+#endif
88415
+ if( pIdx->pKeyInfo==0 ){
88416
+ int i;
88417
+ int nCol = pIdx->nColumn;
88418
+ int nKey = pIdx->nKeyCol;
88419
+ KeyInfo *pKey;
88420
+ if( pIdx->uniqNotNull ){
88421
+ pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
88422
+ }else{
88423
+ pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
88424
+ }
88425
+ if( pKey ){
88426
+ assert( sqlite3KeyInfoIsWriteable(pKey) );
88427
+ for(i=0; i<nCol; i++){
88428
+ char *zColl = pIdx->azColl[i];
88429
+ if( NEVER(zColl==0) ) zColl = "BINARY";
88430
+ pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
88431
+ pKey->aSortOrder[i] = pIdx->aSortOrder[i];
88432
+ }
88433
+ if( pParse->nErr ){
88434
+ sqlite3KeyInfoUnref(pKey);
88435
+ }else{
88436
+ pIdx->pKeyInfo = pKey;
88437
+ }
88438
+ }
88439
+ }
88440
+ return sqlite3KeyInfoRef(pIdx->pKeyInfo);
8765088441
}
8765188442
8765288443
/************** End of build.c ***********************************************/
8765388444
/************** Begin file callback.c ****************************************/
8765488445
/*
@@ -88264,11 +89055,11 @@
8826489055
SrcList *pSrc, /* the FROM clause -- which tables to scan */
8826589056
Expr *pWhere, /* The WHERE clause. May be null */
8826689057
ExprList *pOrderBy, /* The ORDER BY clause. May be null */
8826789058
Expr *pLimit, /* The LIMIT clause. May be null */
8826889059
Expr *pOffset, /* The OFFSET clause. May be null */
88269
- char *zStmtType /* Either DELETE or UPDATE. For error messages. */
89060
+ char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
8827089061
){
8827189062
Expr *pWhereRowid = NULL; /* WHERE rowid .. */
8827289063
Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
8827389064
Expr *pSelectRowid = NULL; /* SELECT rowid ... */
8827489065
ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */
@@ -88339,11 +89130,12 @@
8833989130
sqlite3ExprListDelete(pParse->db, pOrderBy);
8834089131
sqlite3ExprDelete(pParse->db, pLimit);
8834189132
sqlite3ExprDelete(pParse->db, pOffset);
8834289133
return 0;
8834389134
}
88344
-#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
89135
+#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */
89136
+ /* && !defined(SQLITE_OMIT_SUBQUERY) */
8834589137
8834689138
/*
8834789139
** Generate code for a DELETE FROM statement.
8834889140
**
8834989141
** DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
@@ -88360,11 +89152,13 @@
8836089152
const char *zDb; /* Name of database holding pTab */
8836189153
int end, addr = 0; /* A couple addresses of generated code */
8836289154
int i; /* Loop counter */
8836389155
WhereInfo *pWInfo; /* Information about the WHERE clause */
8836489156
Index *pIdx; /* For looping over indices of the table */
88365
- int iCur; /* VDBE Cursor number for pTab */
89157
+ int iTabCur; /* Cursor number for the table */
89158
+ int iDataCur; /* VDBE cursor for the canonical data source */
89159
+ int iIdxCur; /* Cursor number of the first index */
8836689160
sqlite3 *db; /* Main database structure */
8836789161
AuthContext sContext; /* Authorization context */
8836889162
NameContext sNC; /* Name context to resolve expressions in */
8836989163
int iDb; /* Database number */
8837089164
int memCnt = -1; /* Memory cell used for change counting */
@@ -88425,11 +89219,11 @@
8842589219
assert(!isView || pTrigger);
8842689220
8842789221
/* Assign cursor number to the table and all its indices.
8842889222
*/
8842989223
assert( pTabList->nSrc==1 );
88430
- iCur = pTabList->a[0].iCursor = pParse->nTab++;
89224
+ iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
8843189225
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
8843289226
pParse->nTab++;
8843389227
}
8843489228
8843589229
/* Start the view context
@@ -88450,11 +89244,12 @@
8845089244
/* If we are trying to delete from a view, realize that view into
8845189245
** a ephemeral table.
8845289246
*/
8845389247
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
8845489248
if( isView ){
88455
- sqlite3MaterializeView(pParse, pTab, pWhere, iCur);
89249
+ sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur);
89250
+ iDataCur = iIdxCur = iTabCur;
8845689251
}
8845789252
#endif
8845889253
8845989254
/* Resolve the column names in the WHERE clause.
8846089255
*/
@@ -88481,22 +89276,78 @@
8848189276
if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab)
8848289277
&& 0==sqlite3FkRequired(pParse, pTab, 0, 0)
8848389278
){
8848489279
assert( !isView );
8848589280
sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
88486
- sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
88487
- pTab->zName, P4_STATIC);
89281
+ if( HasRowid(pTab) ){
89282
+ sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
89283
+ pTab->zName, P4_STATIC);
89284
+ }
8848889285
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
8848989286
assert( pIdx->pSchema==pTab->pSchema );
8849089287
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
8849189288
}
8849289289
}else
8849389290
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
88494
- /* The usual case: There is a WHERE clause so we have to scan through
88495
- ** the table and pick which records to delete.
88496
- */
88497
- {
89291
+ if( !HasRowid(pTab) ){
89292
+ /* There is a WHERE clause on a WITHOUT ROWID table.
89293
+ */
89294
+ Index *pPk; /* The PRIMARY KEY index on the table */
89295
+ int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
89296
+ int iEph; /* Ephemeral table holding all primary key values */
89297
+ int iKey; /* Key value inserting into iEph */
89298
+ i16 nPk; /* Number of components of the PRIMARY KEY */
89299
+
89300
+ pPk = sqlite3PrimaryKeyIndex(pTab);
89301
+ assert( pPk!=0 );
89302
+ nPk = pPk->nKeyCol;
89303
+ iPk = pParse->nMem+1;
89304
+ pParse->nMem += nPk;
89305
+ iKey = ++pParse->nMem;
89306
+ iEph = pParse->nTab++;
89307
+
89308
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
89309
+ sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89310
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 0, 0);
89311
+ if( pWInfo==0 ) goto delete_from_cleanup;
89312
+ for(i=0; i<nPk; i++){
89313
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, pPk->aiColumn[i],iPk+i);
89314
+ }
89315
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89316
+ sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89317
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, iKey);
89318
+ if( db->flags & SQLITE_CountRows ){
89319
+ sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89320
+ }
89321
+ sqlite3WhereEnd(pWInfo);
89322
+
89323
+ /* Open cursors for all indices of the table.
89324
+ */
89325
+ sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite,
89326
+ iTabCur, &iDataCur, &iIdxCur);
89327
+
89328
+ /* Loop over the primary keys to be deleted. */
89329
+ addr = sqlite3VdbeAddOp1(v, OP_Rewind, iEph);
89330
+ sqlite3VdbeAddOp2(v, OP_RowKey, iEph, iPk);
89331
+
89332
+ /* Delete the row */
89333
+ sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89334
+ iPk, 0, 1, OE_Default, 0);
89335
+
89336
+ /* End of the delete loop */
89337
+ sqlite3VdbeAddOp2(v, OP_Next, iEph, addr+1);
89338
+ sqlite3VdbeJumpHere(v, addr);
89339
+
89340
+ /* Close the cursors open on the table and its indexes. */
89341
+ assert( iDataCur>=iIdxCur );
89342
+ for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89343
+ sqlite3VdbeAddOp1(v, OP_Close, iIdxCur+i);
89344
+ }
89345
+ }else{
89346
+ /* There is a WHERE clause on a rowid table. Run a loop that extracts
89347
+ ** all rowids to be deleted into a RowSet.
89348
+ */
8849889349
int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
8849989350
int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
8850089351
int regRowid; /* Actual register containing rowids */
8850189352
8850289353
/* Collect rowids of every row to be deleted.
@@ -88504,11 +89355,11 @@
8850489355
sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
8850589356
pWInfo = sqlite3WhereBegin(
8850689357
pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
8850789358
);
8850889359
if( pWInfo==0 ) goto delete_from_cleanup;
88509
- regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0);
89360
+ regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iRowid, 0);
8851089361
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
8851189362
if( db->flags & SQLITE_CountRows ){
8851289363
sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
8851389364
}
8851489365
sqlite3WhereEnd(pWInfo);
@@ -88521,11 +89372,14 @@
8852189372
/* Unless this is a view, open cursors for the table we are
8852289373
** deleting from and all its indices. If this is a view, then the
8852389374
** only effect this statement has is to fire the INSTEAD OF
8852489375
** triggers. */
8852589376
if( !isView ){
88526
- sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite);
89377
+ sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur,
89378
+ &iDataCur, &iIdxCur);
89379
+ assert( iDataCur==iTabCur );
89380
+ assert( iIdxCur==iDataCur+1 );
8852789381
}
8852889382
8852989383
addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);
8853089384
8853189385
/* Delete the row */
@@ -88538,23 +89392,24 @@
8853889392
sqlite3MayAbort(pParse);
8853989393
}else
8854089394
#endif
8854189395
{
8854289396
int count = (pParse->nested==0); /* True to count changes */
88543
- sqlite3GenerateRowDelete(pParse, pTab, iCur, iRowid, count, pTrigger, OE_Default);
89397
+ sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89398
+ iRowid, 1, count, OE_Default, 0);
8854489399
}
8854589400
8854689401
/* End of the delete loop */
8854789402
sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
8854889403
sqlite3VdbeResolveLabel(v, end);
8854989404
8855089405
/* Close the cursors open on the table and its indexes. */
8855189406
if( !isView && !IsVirtual(pTab) ){
88552
- for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
88553
- sqlite3VdbeAddOp2(v, OP_Close, iCur + i, pIdx->tnum);
89407
+ sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
89408
+ for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89409
+ sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
8855489410
}
88555
- sqlite3VdbeAddOp1(v, OP_Close, iCur);
8855689411
}
8855789412
}
8855889413
8855989414
/* Update the sqlite_sequence table by storing the content of the
8856089415
** maximum rowid counter values recorded while inserting into
@@ -88590,48 +89445,56 @@
8859089445
#undef pTrigger
8859189446
#endif
8859289447
8859389448
/*
8859489449
** This routine generates VDBE code that causes a single row of a
88595
-** single table to be deleted.
89450
+** single table to be deleted. Both the original table entry and
89451
+** all indices are removed.
8859689452
**
88597
-** The VDBE must be in a particular state when this routine is called.
88598
-** These are the requirements:
89453
+** Preconditions:
8859989454
**
88600
-** 1. A read/write cursor pointing to pTab, the table containing the row
88601
-** to be deleted, must be opened as cursor number $iCur.
89455
+** 1. iDataCur is an open cursor on the btree that is the canonical data
89456
+** store for the table. (This will be either the table itself,
89457
+** in the case of a rowid table, or the PRIMARY KEY index in the case
89458
+** of a WITHOUT ROWID table.)
8860289459
**
8860389460
** 2. Read/write cursors for all indices of pTab must be open as
88604
-** cursor number base+i for the i-th index.
89461
+** cursor number iIdxCur+i for the i-th index.
8860589462
**
88606
-** 3. The record number of the row to be deleted must be stored in
88607
-** memory cell iRowid.
88608
-**
88609
-** This routine generates code to remove both the table record and all
88610
-** index entries that point to that record.
89463
+** 3. The primary key for the row to be deleted must be stored in a
89464
+** sequence of nPk memory cells starting at iPk. If nPk==0 that means
89465
+** that a search record formed from OP_MakeRecord is contained in the
89466
+** single memory location iPk.
8861189467
*/
8861289468
SQLITE_PRIVATE void sqlite3GenerateRowDelete(
8861389469
Parse *pParse, /* Parsing context */
8861489470
Table *pTab, /* Table containing the row to be deleted */
88615
- int iCur, /* Cursor number for the table */
88616
- int iRowid, /* Memory cell that contains the rowid to delete */
88617
- int count, /* If non-zero, increment the row change counter */
8861889471
Trigger *pTrigger, /* List of triggers to (potentially) fire */
88619
- int onconf /* Default ON CONFLICT policy for triggers */
89472
+ int iDataCur, /* Cursor from which column data is extracted */
89473
+ int iIdxCur, /* First index cursor */
89474
+ int iPk, /* First memory cell containing the PRIMARY KEY */
89475
+ i16 nPk, /* Number of PRIMARY KEY memory cells */
89476
+ u8 count, /* If non-zero, increment the row change counter */
89477
+ u8 onconf, /* Default ON CONFLICT policy for triggers */
89478
+ u8 bNoSeek /* iDataCur is already pointing to the row to delete */
8862089479
){
8862189480
Vdbe *v = pParse->pVdbe; /* Vdbe */
8862289481
int iOld = 0; /* First register in OLD.* array */
8862389482
int iLabel; /* Label resolved to end of generated code */
89483
+ u8 opSeek; /* Seek opcode */
8862489484
8862589485
/* Vdbe is guaranteed to have been allocated by this stage. */
8862689486
assert( v );
89487
+ VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
89488
+ iDataCur, iIdxCur, iPk, (int)nPk));
8862789489
8862889490
/* Seek cursor iCur to the row to delete. If this row no longer exists
8862989491
** (this can happen if a trigger program has already deleted it), do
8863089492
** not attempt to delete it or fire any DELETE triggers. */
8863189493
iLabel = sqlite3VdbeMakeLabel(v);
88632
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
89494
+ opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89495
+ if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
8863389496
8863489497
/* If there are any triggers to fire, allocate a range of registers to
8863589498
** use for the old.* references in the triggers. */
8863689499
if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
8863789500
u32 mask; /* Mask of OLD.* columns in use */
@@ -88646,14 +89509,14 @@
8864689509
iOld = pParse->nMem+1;
8864789510
pParse->nMem += (1 + pTab->nCol);
8864889511
8864989512
/* Populate the OLD.* pseudo-table register array. These values will be
8865089513
** used by any BEFORE and AFTER triggers that exist. */
88651
- sqlite3VdbeAddOp2(v, OP_Copy, iRowid, iOld);
89514
+ sqlite3VdbeAddOp2(v, OP_Copy, iPk, iOld);
8865289515
for(iCol=0; iCol<pTab->nCol; iCol++){
8865389516
if( mask==0xffffffff || mask&(1<<iCol) ){
88654
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol, iOld+iCol+1);
89517
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
8865589518
}
8865689519
}
8865789520
8865889521
/* Invoke BEFORE DELETE trigger programs. */
8865989522
sqlite3CodeRowTrigger(pParse, pTrigger,
@@ -88662,11 +89525,11 @@
8866289525
8866389526
/* Seek the cursor to the row to be deleted again. It may be that
8866489527
** the BEFORE triggers coded above have already removed the row
8866589528
** being deleted. Do not attempt to delete the row a second time, and
8866689529
** do not fire AFTER triggers. */
88667
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
89530
+ sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
8866889531
8866989532
/* Do FK processing. This call checks that any FK constraints that
8867089533
** refer to this table (i.e. constraints attached to other tables)
8867189534
** are not violated by deleting this row. */
8867289535
sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -88674,12 +89537,12 @@
8867489537
8867589538
/* Delete the index and table entries. Skip this step if pTab is really
8867689539
** a view (in which case the only effect of the DELETE statement is to
8867789540
** fire the INSTEAD OF triggers). */
8867889541
if( pTab->pSelect==0 ){
88679
- sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
88680
- sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
89542
+ sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
89543
+ sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
8868189544
if( count ){
8868289545
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
8868389546
}
8868489547
}
8868589548
@@ -88695,53 +89558,65 @@
8869589558
8869689559
/* Jump here if the row had already been deleted before any BEFORE
8869789560
** trigger programs were invoked. Or if a trigger program throws a
8869889561
** RAISE(IGNORE) exception. */
8869989562
sqlite3VdbeResolveLabel(v, iLabel);
89563
+ VdbeModuleComment((v, "END: GenRowDel()"));
8870089564
}
8870189565
8870289566
/*
8870389567
** This routine generates VDBE code that causes the deletion of all
88704
-** index entries associated with a single row of a single table.
89568
+** index entries associated with a single row of a single table, pTab
8870589569
**
88706
-** The VDBE must be in a particular state when this routine is called.
88707
-** These are the requirements:
89570
+** Preconditions:
8870889571
**
88709
-** 1. A read/write cursor pointing to pTab, the table containing the row
88710
-** to be deleted, must be opened as cursor number "iCur".
89572
+** 1. A read/write cursor "iDataCur" must be open on the canonical storage
89573
+** btree for the table pTab. (This will be either the table itself
89574
+** for rowid tables or to the primary key index for WITHOUT ROWID
89575
+** tables.)
8871189576
**
8871289577
** 2. Read/write cursors for all indices of pTab must be open as
88713
-** cursor number iCur+i for the i-th index.
89578
+** cursor number iIdxCur+i for the i-th index. (The pTab->pIndex
89579
+** index is the 0-th index.)
8871489580
**
88715
-** 3. The "iCur" cursor must be pointing to the row that is to be
88716
-** deleted.
89581
+** 3. The "iDataCur" cursor must be already be positioned on the row
89582
+** that is to be deleted.
8871789583
*/
8871889584
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(
8871989585
Parse *pParse, /* Parsing and code generating context */
8872089586
Table *pTab, /* Table containing the row to be deleted */
88721
- int iCur, /* Cursor number for the table */
89587
+ int iDataCur, /* Cursor of table holding data. */
89588
+ int iIdxCur, /* First index cursor */
8872289589
int *aRegIdx /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */
8872389590
){
88724
- int i;
88725
- Index *pIdx;
88726
- int r1;
88727
- int iPartIdxLabel;
88728
- Vdbe *v = pParse->pVdbe;
88729
-
88730
- for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
88731
- if( aRegIdx!=0 && aRegIdx[i-1]==0 ) continue;
88732
- r1 = sqlite3GenerateIndexKey(pParse, pIdx, iCur, 0, 0, &iPartIdxLabel);
88733
- sqlite3VdbeAddOp3(v, OP_IdxDelete, iCur+i, r1, pIdx->nColumn+1);
89591
+ int i; /* Index loop counter */
89592
+ int r1; /* Register holding an index key */
89593
+ int iPartIdxLabel; /* Jump destination for skipping partial index entries */
89594
+ Index *pIdx; /* Current index */
89595
+ Vdbe *v; /* The prepared statement under construction */
89596
+ Index *pPk; /* PRIMARY KEY index, or NULL for rowid tables */
89597
+
89598
+ v = pParse->pVdbe;
89599
+ pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
89600
+ for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89601
+ assert( iIdxCur+i!=iDataCur || pPk==pIdx );
89602
+ if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
89603
+ if( pIdx==pPk ) continue;
89604
+ VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));
89605
+ r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, &iPartIdxLabel);
89606
+ sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1,
89607
+ pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn);
8873489608
sqlite3VdbeResolveLabel(v, iPartIdxLabel);
8873589609
}
8873689610
}
8873789611
8873889612
/*
88739
-** Generate code that will assemble an index key and put it in register
89613
+** Generate code that will assemble an index key and stores it in register
8874089614
** regOut. The key with be for index pIdx which is an index on pTab.
8874189615
** iCur is the index of a cursor open on the pTab table and pointing to
88742
-** the entry that needs indexing.
89616
+** the entry that needs indexing. If pTab is a WITHOUT ROWID table, then
89617
+** iCur must be the cursor of the PRIMARY KEY index.
8874389618
**
8874489619
** Return a register number which is the first in a block of
8874589620
** registers that holds the elements of the index key. The
8874689621
** block of registers has already been deallocated by the time
8874789622
** this routine returns.
@@ -88754,56 +89629,58 @@
8875489629
** sqlite3VdbeResolveLabel().
8875589630
*/
8875689631
SQLITE_PRIVATE int sqlite3GenerateIndexKey(
8875789632
Parse *pParse, /* Parsing context */
8875889633
Index *pIdx, /* The index for which to generate a key */
88759
- int iCur, /* Cursor number for the pIdx->pTable table */
88760
- int regOut, /* Write the new index key to this register */
88761
- int doMakeRec, /* Run the OP_MakeRecord instruction if true */
89634
+ int iDataCur, /* Cursor number from which to take column data */
89635
+ int regOut, /* Put the new key into this register if not 0 */
89636
+ int prefixOnly, /* Compute only a unique prefix of the key */
8876289637
int *piPartIdxLabel /* OUT: Jump to this label to skip partial index */
8876389638
){
8876489639
Vdbe *v = pParse->pVdbe;
8876589640
int j;
8876689641
Table *pTab = pIdx->pTable;
8876789642
int regBase;
8876889643
int nCol;
89644
+ Index *pPk;
8876989645
8877089646
if( piPartIdxLabel ){
8877189647
if( pIdx->pPartIdxWhere ){
8877289648
*piPartIdxLabel = sqlite3VdbeMakeLabel(v);
88773
- pParse->iPartIdxTab = iCur;
89649
+ pParse->iPartIdxTab = iDataCur;
8877489650
sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
8877589651
SQLITE_JUMPIFNULL);
8877689652
}else{
8877789653
*piPartIdxLabel = 0;
8877889654
}
8877989655
}
88780
- nCol = pIdx->nColumn;
88781
- regBase = sqlite3GetTempRange(pParse, nCol+1);
88782
- sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regBase+nCol);
89656
+ nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
89657
+ regBase = sqlite3GetTempRange(pParse, nCol);
89658
+ pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
8878389659
for(j=0; j<nCol; j++){
88784
- int idx = pIdx->aiColumn[j];
88785
- if( idx==pTab->iPKey ){
88786
- sqlite3VdbeAddOp2(v, OP_SCopy, regBase+nCol, regBase+j);
89660
+ i16 idx = pIdx->aiColumn[j];
89661
+ if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx);
89662
+ if( idx<0 || idx==pTab->iPKey ){
89663
+ sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j);
8878789664
}else{
88788
- sqlite3VdbeAddOp3(v, OP_Column, iCur, idx, regBase+j);
88789
- sqlite3ColumnDefault(v, pTab, idx, -1);
89665
+ sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j);
89666
+ sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1);
8879089667
}
8879189668
}
88792
- if( doMakeRec ){
89669
+ if( regOut ){
8879389670
const char *zAff;
8879489671
if( pTab->pSelect
8879589672
|| OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
8879689673
){
8879789674
zAff = 0;
8879889675
}else{
8879989676
zAff = sqlite3IndexAffinityStr(v, pIdx);
8880089677
}
88801
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);
89678
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
8880289679
sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
8880389680
}
88804
- sqlite3ReleaseTempRange(pParse, regBase, nCol+1);
89681
+ sqlite3ReleaseTempRange(pParse, regBase, nCol);
8880589682
return regBase;
8880689683
}
8880789684
8880889685
/************** End of delete.c **********************************************/
8880989686
/************** Begin file func.c ********************************************/
@@ -88943,12 +89820,12 @@
8894389820
switch( sqlite3_value_type(argv[0]) ){
8894489821
case SQLITE_INTEGER: {
8894589822
i64 iVal = sqlite3_value_int64(argv[0]);
8894689823
if( iVal<0 ){
8894789824
if( (iVal<<1)==0 ){
88948
- /* IMP: R-35460-15084 If X is the integer -9223372036854775807 then
88949
- ** abs(X) throws an integer overflow error since there is no
89825
+ /* IMP: R-31676-45509 If X is the integer -9223372036854775808
89826
+ ** then abs(X) throws an integer overflow error since there is no
8895089827
** equivalent positive 64-bit two complement value. */
8895189828
sqlite3_result_error(context, "integer overflow", -1);
8895289829
return;
8895389830
}
8895489831
iVal = -iVal;
@@ -90755,11 +91632,11 @@
9075591632
if( !aiCol ) return 1;
9075691633
*paiCol = aiCol;
9075791634
}
9075891635
9075991636
for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
90760
- if( pIdx->nColumn==nCol && pIdx->onError!=OE_None ){
91637
+ if( pIdx->nKeyCol==nCol && pIdx->onError!=OE_None ){
9076191638
/* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
9076291639
** of columns. If each indexed column corresponds to a foreign key
9076391640
** column of pFKey, then this index is a winner. */
9076491641
9076591642
if( zKey==0 ){
@@ -90778,11 +91655,11 @@
9077891655
** map to an explicit list of columns in table pParent. Check if this
9077991656
** index matches those columns. Also, check that the index uses
9078091657
** the default collation sequences for each column. */
9078191658
int i, j;
9078291659
for(i=0; i<nCol; i++){
90783
- int iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
91660
+ i16 iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
9078491661
char *zDfltColl; /* Def. collation for column */
9078591662
char *zIdxCol; /* Name of indexed column */
9078691663
9078791664
/* If the index uses a collation sequence that is different from
9078891665
** the default collation sequence for the column, this index is
@@ -90909,14 +91786,13 @@
9090991786
sqlite3ReleaseTempReg(pParse, regTemp);
9091091787
}else{
9091191788
int nCol = pFKey->nCol;
9091291789
int regTemp = sqlite3GetTempRange(pParse, nCol);
9091391790
int regRec = sqlite3GetTempReg(pParse);
90914
- KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
9091591791
9091691792
sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
90917
- sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
91793
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
9091891794
for(i=0; i<nCol; i++){
9091991795
sqlite3VdbeAddOp2(v, OP_Copy, aiCol[i]+1+regData, regTemp+i);
9092091796
}
9092191797
9092291798
/* If the parent table is the same as the child table, and we are about
@@ -90962,12 +91838,11 @@
9096291838
** one row into the table, raise a constraint immediately instead of
9096391839
** incrementing a counter. This is necessary as the VM code is being
9096491840
** generated for will not open a statement transaction. */
9096591841
assert( nIncr==1 );
9096691842
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
90967
- OE_Abort, "foreign key constraint failed", P4_STATIC
90968
- );
91843
+ OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
9096991844
}else{
9097091845
if( nIncr>0 && pFKey->isDeferred==0 ){
9097191846
sqlite3ParseToplevel(pParse)->mayAbort = 1;
9097291847
}
9097391848
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
@@ -90975,10 +91850,66 @@
9097591850
9097691851
sqlite3VdbeResolveLabel(v, iOk);
9097791852
sqlite3VdbeAddOp1(v, OP_Close, iCur);
9097891853
}
9097991854
91855
+
91856
+/*
91857
+** Return an Expr object that refers to a memory register corresponding
91858
+** to column iCol of table pTab.
91859
+**
91860
+** regBase is the first of an array of register that contains the data
91861
+** for pTab. regBase itself holds the rowid. regBase+1 holds the first
91862
+** column. regBase+2 holds the second column, and so forth.
91863
+*/
91864
+static Expr *exprTableRegister(
91865
+ Parse *pParse, /* Parsing and code generating context */
91866
+ Table *pTab, /* The table whose content is at r[regBase]... */
91867
+ int regBase, /* Contents of table pTab */
91868
+ i16 iCol /* Which column of pTab is desired */
91869
+){
91870
+ Expr *pExpr;
91871
+ Column *pCol;
91872
+ const char *zColl;
91873
+ sqlite3 *db = pParse->db;
91874
+
91875
+ pExpr = sqlite3Expr(db, TK_REGISTER, 0);
91876
+ if( pExpr ){
91877
+ if( iCol>=0 && iCol!=pTab->iPKey ){
91878
+ pCol = &pTab->aCol[iCol];
91879
+ pExpr->iTable = regBase + iCol + 1;
91880
+ pExpr->affinity = pCol->affinity;
91881
+ zColl = pCol->zColl;
91882
+ if( zColl==0 ) zColl = db->pDfltColl->zName;
91883
+ pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl);
91884
+ }else{
91885
+ pExpr->iTable = regBase;
91886
+ pExpr->affinity = SQLITE_AFF_INTEGER;
91887
+ }
91888
+ }
91889
+ return pExpr;
91890
+}
91891
+
91892
+/*
91893
+** Return an Expr object that refers to column iCol of table pTab which
91894
+** has cursor iCur.
91895
+*/
91896
+static Expr *exprTableColumn(
91897
+ sqlite3 *db, /* The database connection */
91898
+ Table *pTab, /* The table whose column is desired */
91899
+ int iCursor, /* The open cursor on the table */
91900
+ i16 iCol /* The column that is wanted */
91901
+){
91902
+ Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
91903
+ if( pExpr ){
91904
+ pExpr->pTab = pTab;
91905
+ pExpr->iTable = iCursor;
91906
+ pExpr->iColumn = iCol;
91907
+ }
91908
+ return pExpr;
91909
+}
91910
+
9098091911
/*
9098191912
** This function is called to generate code executed when a row is deleted
9098291913
** from the parent table of foreign key constraint pFKey and, if pFKey is
9098391914
** deferred, when a row is inserted into the same table. When generating
9098491915
** code for an SQL UPDATE operation, this function may be called twice -
@@ -90990,31 +91921,31 @@
9099091921
**
9099191922
** Operation | FK type | Action taken
9099291923
** --------------------------------------------------------------------------
9099391924
** DELETE immediate Increment the "immediate constraint counter".
9099491925
** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
90995
-** throw a "foreign key constraint failed" exception.
91926
+** throw a "FOREIGN KEY constraint failed" exception.
9099691927
**
9099791928
** INSERT immediate Decrement the "immediate constraint counter".
9099891929
**
9099991930
** DELETE deferred Increment the "deferred constraint counter".
9100091931
** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
91001
-** throw a "foreign key constraint failed" exception.
91932
+** throw a "FOREIGN KEY constraint failed" exception.
9100291933
**
9100391934
** INSERT deferred Decrement the "deferred constraint counter".
9100491935
**
9100591936
** These operations are identified in the comment at the top of this file
9100691937
** (fkey.c) as "I.2" and "D.2".
9100791938
*/
9100891939
static void fkScanChildren(
9100991940
Parse *pParse, /* Parse context */
91010
- SrcList *pSrc, /* SrcList containing the table to scan */
91011
- Table *pTab,
91012
- Index *pIdx, /* Foreign key index */
91013
- FKey *pFKey, /* Foreign key relationship */
91941
+ SrcList *pSrc, /* The child table to be scanned */
91942
+ Table *pTab, /* The parent table */
91943
+ Index *pIdx, /* Index on parent covering the foreign key */
91944
+ FKey *pFKey, /* The foreign key linking pSrc to pTab */
9101491945
int *aiCol, /* Map from pIdx cols to child table cols */
91015
- int regData, /* Referenced table data starts here */
91946
+ int regData, /* Parent row data starts here */
9101691947
int nIncr /* Amount to increment deferred counter by */
9101791948
){
9101891949
sqlite3 *db = pParse->db; /* Database handle */
9101991950
int i; /* Iterator variable */
9102091951
Expr *pWhere = 0; /* WHERE clause to scan with */
@@ -91021,11 +91952,13 @@
9102191952
NameContext sNameContext; /* Context used to resolve WHERE clause */
9102291953
WhereInfo *pWInfo; /* Context used by sqlite3WhereXXX() */
9102391954
int iFkIfZero = 0; /* Address of OP_FkIfZero */
9102491955
Vdbe *v = sqlite3GetVdbe(pParse);
9102591956
91026
- assert( !pIdx || pIdx->pTable==pTab );
91957
+ assert( pIdx==0 || pIdx->pTable==pTab );
91958
+ assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
91959
+ assert( pIdx!=0 || pFKey->nCol==1 );
9102791960
9102891961
if( nIncr<0 ){
9102991962
iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
9103091963
}
9103191964
@@ -91039,59 +91972,55 @@
9103991972
*/
9104091973
for(i=0; i<pFKey->nCol; i++){
9104191974
Expr *pLeft; /* Value from parent table row */
9104291975
Expr *pRight; /* Column ref to child table */
9104391976
Expr *pEq; /* Expression (pLeft = pRight) */
91044
- int iCol; /* Index of column in child table */
91977
+ i16 iCol; /* Index of column in child table */
9104591978
const char *zCol; /* Name of column in child table */
9104691979
91047
- pLeft = sqlite3Expr(db, TK_REGISTER, 0);
91048
- if( pLeft ){
91049
- /* Set the collation sequence and affinity of the LHS of each TK_EQ
91050
- ** expression to the parent key column defaults. */
91051
- if( pIdx ){
91052
- Column *pCol;
91053
- const char *zColl;
91054
- iCol = pIdx->aiColumn[i];
91055
- pCol = &pTab->aCol[iCol];
91056
- if( pTab->iPKey==iCol ) iCol = -1;
91057
- pLeft->iTable = regData+iCol+1;
91058
- pLeft->affinity = pCol->affinity;
91059
- zColl = pCol->zColl;
91060
- if( zColl==0 ) zColl = db->pDfltColl->zName;
91061
- pLeft = sqlite3ExprAddCollateString(pParse, pLeft, zColl);
91062
- }else{
91063
- pLeft->iTable = regData;
91064
- pLeft->affinity = SQLITE_AFF_INTEGER;
91065
- }
91066
- }
91980
+ iCol = pIdx ? pIdx->aiColumn[i] : -1;
91981
+ pLeft = exprTableRegister(pParse, pTab, regData, iCol);
9106791982
iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
9106891983
assert( iCol>=0 );
9106991984
zCol = pFKey->pFrom->aCol[iCol].zName;
9107091985
pRight = sqlite3Expr(db, TK_ID, zCol);
9107191986
pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
9107291987
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
9107391988
}
9107491989
91075
- /* If the child table is the same as the parent table, and this scan
91076
- ** is taking place as part of a DELETE operation (operation D.2), omit the
91077
- ** row being deleted from the scan by adding ($rowid != rowid) to the WHERE
91078
- ** clause, where $rowid is the rowid of the row being deleted. */
91990
+ /* If the child table is the same as the parent table, then add terms
91991
+ ** to the WHERE clause that prevent this entry from being scanned.
91992
+ ** The added WHERE clause terms are like this:
91993
+ **
91994
+ ** $current_rowid!=rowid
91995
+ ** NOT( $current_a==a AND $current_b==b AND ... )
91996
+ **
91997
+ ** The first form is used for rowid tables. The second form is used
91998
+ ** for WITHOUT ROWID tables. In the second form, the primary key is
91999
+ ** (a,b,...)
92000
+ */
9107992001
if( pTab==pFKey->pFrom && nIncr>0 ){
91080
- Expr *pEq; /* Expression (pLeft = pRight) */
92002
+ Expr *pNe; /* Expression (pLeft != pRight) */
9108192003
Expr *pLeft; /* Value from parent table row */
9108292004
Expr *pRight; /* Column ref to child table */
91083
- pLeft = sqlite3Expr(db, TK_REGISTER, 0);
91084
- pRight = sqlite3Expr(db, TK_COLUMN, 0);
91085
- if( pLeft && pRight ){
91086
- pLeft->iTable = regData;
91087
- pLeft->affinity = SQLITE_AFF_INTEGER;
91088
- pRight->iTable = pSrc->a[0].iCursor;
91089
- pRight->iColumn = -1;
91090
- }
91091
- pEq = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
91092
- pWhere = sqlite3ExprAnd(db, pWhere, pEq);
92005
+ if( HasRowid(pTab) ){
92006
+ pLeft = exprTableRegister(pParse, pTab, regData, -1);
92007
+ pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
92008
+ pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
92009
+ }else{
92010
+ Expr *pEq, *pAll = 0;
92011
+ Index *pPk = sqlite3PrimaryKeyIndex(pTab);
92012
+ for(i=0; i<pPk->nKeyCol; i++){
92013
+ i16 iCol = pIdx->aiColumn[i];
92014
+ pLeft = exprTableRegister(pParse, pTab, regData, iCol);
92015
+ pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
92016
+ pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
92017
+ pAll = sqlite3ExprAnd(db, pAll, pEq);
92018
+ }
92019
+ pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0, 0);
92020
+ }
92021
+ pWhere = sqlite3ExprAnd(db, pWhere, pNe);
9109392022
}
9109492023
9109592024
/* Resolve the references in the WHERE clause. */
9109692025
memset(&sNameContext, 0, sizeof(NameContext));
9109792026
sNameContext.pSrcList = pSrc;
@@ -91117,12 +92046,12 @@
9111792046
sqlite3VdbeJumpHere(v, iFkIfZero);
9111892047
}
9111992048
}
9112092049
9112192050
/*
91122
-** This function returns a pointer to the head of a linked list of FK
91123
-** constraints for which table pTab is the parent table. For example,
92051
+** This function returns a linked list of FKey objects (connected by
92052
+** FKey.pNextTo) holding all children of table pTab. For example,
9112492053
** given the following schema:
9112592054
**
9112692055
** CREATE TABLE t1(a PRIMARY KEY);
9112792056
** CREATE TABLE t2(b REFERENCES t1(a);
9112892057
**
@@ -91209,12 +92138,11 @@
9120992138
** constraints are violated.
9121092139
*/
9121192140
if( (db->flags & SQLITE_DeferFKs)==0 ){
9121292141
sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
9121392142
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
91214
- OE_Abort, "foreign key constraint failed", P4_STATIC
91215
- );
92143
+ OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
9121692144
}
9121792145
9121892146
if( iSkip ){
9121992147
sqlite3VdbeResolveLabel(v, iSkip);
9122092148
}
@@ -91420,11 +92348,12 @@
9142092348
}
9142192349
9142292350
sqlite3DbFree(db, aiFree);
9142392351
}
9142492352
91425
- /* Loop through all the foreign key constraints that refer to this table */
92353
+ /* Loop through all the foreign key constraints that refer to this table.
92354
+ ** (the "child" constraints) */
9142692355
for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
9142792356
Index *pIdx = 0; /* Foreign key index for pFKey */
9142892357
SrcList *pSrc;
9142992358
int *aiCol = 0;
9143092359
@@ -91445,13 +92374,12 @@
9144592374
if( !isIgnoreErrors || db->mallocFailed ) return;
9144692375
continue;
9144792376
}
9144892377
assert( aiCol || pFKey->nCol==1 );
9144992378
91450
- /* Create a SrcList structure containing a single table (the table
91451
- ** the foreign key that refers to this table is attached to). This
91452
- ** is required for the sqlite3WhereXXX() interface. */
92379
+ /* Create a SrcList structure containing the child table. We need the
92380
+ ** child table as a SrcList for sqlite3WhereBegin() */
9145392381
pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
9145492382
if( pSrc ){
9145592383
struct SrcList_item *pItem = pSrc->a;
9145692384
pItem->pTab = pFKey->pFrom;
9145792385
pItem->zName = pFKey->pFrom->zName;
@@ -91496,11 +92424,11 @@
9149692424
}
9149792425
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
9149892426
Index *pIdx = 0;
9149992427
sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
9150092428
if( pIdx ){
91501
- for(i=0; i<pIdx->nColumn; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]);
92429
+ for(i=0; i<pIdx->nKeyCol; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]);
9150292430
}
9150392431
}
9150492432
}
9150592433
return mask;
9150692434
}
@@ -91688,11 +92616,11 @@
9168892616
Token tFrom;
9168992617
Expr *pRaise;
9169092618
9169192619
tFrom.z = zFrom;
9169292620
tFrom.n = nFrom;
91693
- pRaise = sqlite3Expr(db, TK_RAISE, "foreign key constraint failed");
92621
+ pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
9169492622
if( pRaise ){
9169592623
pRaise->affinity = OE_Abort;
9169692624
}
9169792625
pSelect = sqlite3SelectNew(pParse,
9169892626
sqlite3ExprListAppend(pParse, 0, pRaise),
@@ -91852,27 +92780,42 @@
9185292780
** This file contains C code routines that are called by the parser
9185392781
** to handle INSERT statements in SQLite.
9185492782
*/
9185592783
9185692784
/*
91857
-** Generate code that will open a table for reading.
92785
+** Generate code that will
92786
+**
92787
+** (1) acquire a lock for table pTab then
92788
+** (2) open pTab as cursor iCur.
92789
+**
92790
+** If pTab is a WITHOUT ROWID table, then it is the PRIMARY KEY index
92791
+** for that table that is actually opened.
9185892792
*/
9185992793
SQLITE_PRIVATE void sqlite3OpenTable(
91860
- Parse *p, /* Generate code into this VDBE */
92794
+ Parse *pParse, /* Generate code into this VDBE */
9186192795
int iCur, /* The cursor number of the table */
9186292796
int iDb, /* The database index in sqlite3.aDb[] */
9186392797
Table *pTab, /* The table to be opened */
9186492798
int opcode /* OP_OpenRead or OP_OpenWrite */
9186592799
){
9186692800
Vdbe *v;
9186792801
assert( !IsVirtual(pTab) );
91868
- v = sqlite3GetVdbe(p);
92802
+ v = sqlite3GetVdbe(pParse);
9186992803
assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
91870
- sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName);
91871
- sqlite3VdbeAddOp3(v, opcode, iCur, pTab->tnum, iDb);
91872
- sqlite3VdbeChangeP4(v, -1, SQLITE_INT_TO_PTR(pTab->nCol), P4_INT32);
91873
- VdbeComment((v, "%s", pTab->zName));
92804
+ sqlite3TableLock(pParse, iDb, pTab->tnum,
92805
+ (opcode==OP_OpenWrite)?1:0, pTab->zName);
92806
+ if( HasRowid(pTab) ){
92807
+ sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nCol);
92808
+ VdbeComment((v, "%s", pTab->zName));
92809
+ }else{
92810
+ Index *pPk = sqlite3PrimaryKeyIndex(pTab);
92811
+ assert( pPk!=0 );
92812
+ assert( pPk->tnum=pTab->tnum );
92813
+ sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
92814
+ sqlite3VdbeSetP4KeyInfo(pParse, pPk);
92815
+ VdbeComment((v, "%s", pTab->zName));
92816
+ }
9187492817
}
9187592818
9187692819
/*
9187792820
** Return a pointer to the column affinity string associated with index
9187892821
** pIdx. A column affinity string has one character for each column in
@@ -91904,19 +92847,19 @@
9190492847
** up.
9190592848
*/
9190692849
int n;
9190792850
Table *pTab = pIdx->pTable;
9190892851
sqlite3 *db = sqlite3VdbeDb(v);
91909
- pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+2);
92852
+ pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
9191092853
if( !pIdx->zColAff ){
9191192854
db->mallocFailed = 1;
9191292855
return 0;
9191392856
}
9191492857
for(n=0; n<pIdx->nColumn; n++){
91915
- pIdx->zColAff[n] = pTab->aCol[pIdx->aiColumn[n]].affinity;
92858
+ i16 x = pIdx->aiColumn[n];
92859
+ pIdx->zColAff[n] = x<0 ? SQLITE_AFF_INTEGER : pTab->aCol[x].affinity;
9191692860
}
91917
- pIdx->zColAff[n++] = SQLITE_AFF_INTEGER;
9191892861
pIdx->zColAff[n] = 0;
9191992862
}
9192092863
9192192864
return pIdx->zColAff;
9192292865
}
@@ -92258,11 +93201,11 @@
9225893201
int onError, /* How to handle constraint errors */
9225993202
int iDbDest /* The database of pDest */
9226093203
);
9226193204
9226293205
/*
92263
-** This routine is call to handle SQL of the following forms:
93206
+** This routine is called to handle SQL of the following forms:
9226493207
**
9226593208
** insert into TABLE (IDLIST) values(EXPRLIST)
9226693209
** insert into TABLE (IDLIST) select
9226793210
**
9226893211
** The IDLIST following the table name is always optional. If omitted,
@@ -92273,16 +93216,16 @@
9227393216
** statement above, and pSelect is NULL. For the second form, pList is
9227493217
** NULL and pSelect is a pointer to the select statement used to generate
9227593218
** data for the insert.
9227693219
**
9227793220
** The code generated follows one of four templates. For a simple
92278
-** select with data coming from a VALUES clause, the code executes
93221
+** insert with data coming from a VALUES clause, the code executes
9227993222
** once straight down through. Pseudo-code follows (we call this
9228093223
** the "1st template"):
9228193224
**
9228293225
** open write cursor to <table> and its indices
92283
-** puts VALUES clause expressions onto the stack
93226
+** put VALUES clause expressions into registers
9228493227
** write the resulting record into <table>
9228593228
** cleanup
9228693229
**
9228793230
** The three remaining templates assume the statement is of the form
9228893231
**
@@ -92376,12 +93319,13 @@
9237693319
int i, j, idx; /* Loop counters */
9237793320
Vdbe *v; /* Generate code into this virtual machine */
9237893321
Index *pIdx; /* For looping over indices of the table */
9237993322
int nColumn; /* Number of columns in the data */
9238093323
int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
92381
- int baseCur = 0; /* VDBE Cursor number for pTab */
92382
- int keyColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
93324
+ int iDataCur = 0; /* VDBE cursor that is the main data repository */
93325
+ int iIdxCur = 0; /* First index cursor */
93326
+ int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
9238393327
int endOfLoop; /* Label for the end of the insertion loop */
9238493328
int useTempTable = 0; /* Store SELECT results in intermediate table */
9238593329
int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
9238693330
int addrInsTop = 0; /* Jump to label "D" */
9238793331
int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
@@ -92388,10 +93332,11 @@
9238893332
int addrSelect = 0; /* Address of coroutine that implements the SELECT */
9238993333
SelectDest dest; /* Destination for SELECT on rhs of INSERT */
9239093334
int iDb; /* Index of database holding TABLE */
9239193335
Db *pDb; /* The database containing table being inserted into */
9239293336
int appendFlag = 0; /* True if the insert is likely to be an append */
93337
+ int withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
9239393338
9239493339
/* Register allocations */
9239593340
int regFromSelect = 0;/* Base register for data coming from SELECT */
9239693341
int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
9239793342
int regRowCount = 0; /* Memory cell used for the row counter */
@@ -92427,10 +93372,11 @@
9242793372
pDb = &db->aDb[iDb];
9242893373
zDb = pDb->zName;
9242993374
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
9243093375
goto insert_cleanup;
9243193376
}
93377
+ withoutRowid = !HasRowid(pTab);
9243293378
9243393379
/* Figure out if we have any triggers and if the table being
9243493380
** inserted into is a view
9243593381
*/
9243693382
#ifndef SQLITE_OMIT_TRIGGER
@@ -92446,20 +93392,17 @@
9244693392
# define isView 0
9244793393
#endif
9244893394
assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
9244993395
9245093396
/* If pTab is really a view, make sure it has been initialized.
92451
- ** ViewGetColumnNames() is a no-op if pTab is not a view (or virtual
92452
- ** module table).
93397
+ ** ViewGetColumnNames() is a no-op if pTab is not a view.
9245393398
*/
9245493399
if( sqlite3ViewGetColumnNames(pParse, pTab) ){
9245593400
goto insert_cleanup;
9245693401
}
9245793402
92458
- /* Ensure that:
92459
- * (a) the table is not read-only,
92460
- * (b) that if it is a view then ON INSERT triggers exist
93403
+ /* Cannot insert into a read-only table.
9246193404
*/
9246293405
if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
9246393406
goto insert_cleanup;
9246493407
}
9246593408
@@ -92496,12 +93439,11 @@
9249693439
** is coming from a SELECT statement, then generate a co-routine that
9249793440
** produces a single row of the SELECT on each invocation. The
9249893441
** co-routine is the common header to the 3rd and 4th templates.
9249993442
*/
9250093443
if( pSelect ){
92501
- /* Data is coming from a SELECT. Generate a co-routine to run that
92502
- ** SELECT. */
93444
+ /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
9250393445
int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
9250493446
if( rc ) goto insert_cleanup;
9250593447
9250693448
regEof = dest.iSDParm + 1;
9250793449
regFromSelect = dest.iSdst;
@@ -92509,11 +93451,11 @@
9250993451
nColumn = pSelect->pEList->nExpr;
9251093452
assert( dest.nSdst==nColumn );
9251193453
9251293454
/* Set useTempTable to TRUE if the result of the SELECT statement
9251393455
** should be written into a temporary table (template 4). Set to
92514
- ** FALSE if each* row of the SELECT can be written directly into
93456
+ ** FALSE if each output row of the SELECT can be written directly into
9251593457
** the destination table (template 3).
9251693458
**
9251793459
** A temp table must be used if the table being updated is also one
9251893460
** of the tables being read by the SELECT statement. Also use a
9251993461
** temp table in the case of row triggers.
@@ -92592,15 +93534,15 @@
9259293534
/* If the INSERT statement included an IDLIST term, then make sure
9259393535
** all elements of the IDLIST really are columns of the table and
9259493536
** remember the column indices.
9259593537
**
9259693538
** If the table has an INTEGER PRIMARY KEY column and that column
92597
- ** is named in the IDLIST, then record in the keyColumn variable
92598
- ** the index into IDLIST of the primary key column. keyColumn is
93539
+ ** is named in the IDLIST, then record in the ipkColumn variable
93540
+ ** the index into IDLIST of the primary key column. ipkColumn is
9259993541
** the index of the primary key as it appears in IDLIST, not as
92600
- ** is appears in the original table. (The index of the primary
92601
- ** key in the original table is pTab->iPKey.)
93542
+ ** is appears in the original table. (The index of the INTEGER
93543
+ ** PRIMARY KEY in the original table is pTab->iPKey.)
9260293544
*/
9260393545
if( pColumn ){
9260493546
for(i=0; i<pColumn->nId; i++){
9260593547
pColumn->a[i].idx = -1;
9260693548
}
@@ -92607,18 +93549,18 @@
9260793549
for(i=0; i<pColumn->nId; i++){
9260893550
for(j=0; j<pTab->nCol; j++){
9260993551
if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
9261093552
pColumn->a[i].idx = j;
9261193553
if( j==pTab->iPKey ){
92612
- keyColumn = i;
93554
+ ipkColumn = i; assert( !withoutRowid );
9261393555
}
9261493556
break;
9261593557
}
9261693558
}
9261793559
if( j>=pTab->nCol ){
92618
- if( sqlite3IsRowid(pColumn->a[i].zName) ){
92619
- keyColumn = i;
93560
+ if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93561
+ ipkColumn = i;
9262093562
}else{
9262193563
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
9262293564
pTabList, 0, pColumn->a[i].zName);
9262393565
pParse->checkSchema = 1;
9262493566
goto insert_cleanup;
@@ -92626,15 +93568,15 @@
9262693568
}
9262793569
}
9262893570
}
9262993571
9263093572
/* If there is no IDLIST term but the table has an integer primary
92631
- ** key, the set the keyColumn variable to the primary key column index
92632
- ** in the original table definition.
93573
+ ** key, the set the ipkColumn variable to the integer primary key
93574
+ ** column index in the original table definition.
9263393575
*/
9263493576
if( pColumn==0 && nColumn>0 ){
92635
- keyColumn = pTab->iPKey;
93577
+ ipkColumn = pTab->iPKey;
9263693578
}
9263793579
9263893580
/* Initialize the count of rows to be inserted
9263993581
*/
9264093582
if( db->flags & SQLITE_CountRows ){
@@ -92643,13 +93585,12 @@
9264393585
}
9264493586
9264593587
/* If this is not a view, open the table and and all indices */
9264693588
if( !isView ){
9264793589
int nIdx;
92648
-
92649
- baseCur = pParse->nTab;
92650
- nIdx = sqlite3OpenTableAndIndices(pParse, pTab, baseCur, OP_OpenWrite);
93590
+ nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1,
93591
+ &iDataCur, &iIdxCur);
9265193592
aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
9265293593
if( aRegIdx==0 ){
9265393594
goto insert_cleanup;
9265493595
}
9265593596
for(i=0; i<nIdx; i++){
@@ -92705,19 +93646,20 @@
9270593646
** PRIMARY KEY into which a NULL is being inserted, that NULL will be
9270693647
** translated into a unique ID for the row. But on a BEFORE trigger,
9270793648
** we do not know what the unique ID will be (because the insert has
9270893649
** not happened yet) so we substitute a rowid of -1
9270993650
*/
92710
- if( keyColumn<0 ){
93651
+ if( ipkColumn<0 ){
9271193652
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
9271293653
}else{
9271393654
int j1;
93655
+ assert( !withoutRowid );
9271493656
if( useTempTable ){
92715
- sqlite3VdbeAddOp3(v, OP_Column, srcTab, keyColumn, regCols);
93657
+ sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
9271693658
}else{
9271793659
assert( pSelect==0 ); /* Otherwise useTempTable is true */
92718
- sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr, regCols);
93660
+ sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
9271993661
}
9272093662
j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
9272193663
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
9272293664
sqlite3VdbeJumpHere(v, j1);
9272393665
sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
@@ -92763,33 +93705,31 @@
9276393705
pTab, regCols-pTab->nCol-1, onError, endOfLoop);
9276493706
9276593707
sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
9276693708
}
9276793709
92768
- /* Push the record number for the new entry onto the stack. The
92769
- ** record number is a randomly generate integer created by NewRowid
92770
- ** except when the table has an INTEGER PRIMARY KEY column, in which
92771
- ** case the record number is the same as that column.
93710
+ /* Compute the content of the next row to insert into a range of
93711
+ ** registers beginning at regIns.
9277293712
*/
9277393713
if( !isView ){
9277493714
if( IsVirtual(pTab) ){
9277593715
/* The row that the VUpdate opcode will delete: none */
9277693716
sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
9277793717
}
92778
- if( keyColumn>=0 ){
93718
+ if( ipkColumn>=0 ){
9277993719
if( useTempTable ){
92780
- sqlite3VdbeAddOp3(v, OP_Column, srcTab, keyColumn, regRowid);
93720
+ sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
9278193721
}else if( pSelect ){
92782
- sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+keyColumn, regRowid);
93722
+ sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid);
9278393723
}else{
9278493724
VdbeOp *pOp;
92785
- sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr, regRowid);
93725
+ sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
9278693726
pOp = sqlite3VdbeGetOp(v, -1);
9278793727
if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
9278893728
appendFlag = 1;
9278993729
pOp->opcode = OP_NewRowid;
92790
- pOp->p1 = baseCur;
93730
+ pOp->p1 = iDataCur;
9279193731
pOp->p2 = regRowid;
9279293732
pOp->p3 = regAutoinc;
9279393733
}
9279493734
}
9279593735
/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
@@ -92797,36 +93737,36 @@
9279793737
*/
9279893738
if( !appendFlag ){
9279993739
int j1;
9280093740
if( !IsVirtual(pTab) ){
9280193741
j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
92802
- sqlite3VdbeAddOp3(v, OP_NewRowid, baseCur, regRowid, regAutoinc);
93742
+ sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
9280393743
sqlite3VdbeJumpHere(v, j1);
9280493744
}else{
9280593745
j1 = sqlite3VdbeCurrentAddr(v);
9280693746
sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
9280793747
}
9280893748
sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
9280993749
}
92810
- }else if( IsVirtual(pTab) ){
93750
+ }else if( IsVirtual(pTab) || withoutRowid ){
9281193751
sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
9281293752
}else{
92813
- sqlite3VdbeAddOp3(v, OP_NewRowid, baseCur, regRowid, regAutoinc);
93753
+ sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
9281493754
appendFlag = 1;
9281593755
}
9281693756
autoIncStep(pParse, regAutoinc, regRowid);
9281793757
92818
- /* Push onto the stack, data for all columns of the new entry, beginning
93758
+ /* Compute data for all columns of the new entry, beginning
9281993759
** with the first column.
9282093760
*/
9282193761
nHidden = 0;
9282293762
for(i=0; i<pTab->nCol; i++){
9282393763
int iRegStore = regRowid+1+i;
9282493764
if( i==pTab->iPKey ){
9282593765
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
92826
- ** Whenever this column is read, the record number will be substituted
92827
- ** in its place. So will fill this column with a NULL to avoid
93766
+ ** Whenever this column is read, the rowid will be substituted
93767
+ ** in its place. Hence, fill this column with a NULL to avoid
9282893768
** taking up data space with information that will never be used. */
9282993769
sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
9283093770
continue;
9283193771
}
9283293772
if( pColumn==0 ){
@@ -92865,17 +93805,16 @@
9286593805
sqlite3MayAbort(pParse);
9286693806
}else
9286793807
#endif
9286893808
{
9286993809
int isReplace; /* Set to true if constraints may cause a replace */
92870
- sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
92871
- keyColumn>=0, 0, onError, endOfLoop, &isReplace
93810
+ sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
93811
+ regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace
9287293812
);
9287393813
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
92874
- sqlite3CompleteInsertion(
92875
- pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
92876
- );
93814
+ sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
93815
+ regIns, aRegIdx, 0, appendFlag, isReplace==0);
9287793816
}
9287893817
}
9287993818
9288093819
/* Update the count of rows that are inserted
9288193820
*/
@@ -92902,13 +93841,13 @@
9290293841
sqlite3VdbeJumpHere(v, addrInsTop);
9290393842
}
9290493843
9290593844
if( !IsVirtual(pTab) && !isView ){
9290693845
/* Close all tables opened */
92907
- sqlite3VdbeAddOp1(v, OP_Close, baseCur);
92908
- for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
92909
- sqlite3VdbeAddOp1(v, OP_Close, idx+baseCur);
93846
+ if( iDataCur<iIdxCur ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
93847
+ for(idx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
93848
+ sqlite3VdbeAddOp1(v, OP_Close, idx+iIdxCur);
9291093849
}
9291193850
}
9291293851
9291393852
insert_end:
9291493853
/* Update the sqlite_sequence table by storing the content of the
@@ -92949,65 +93888,78 @@
9294993888
#endif
9295093889
#ifdef tmask
9295193890
#undef tmask
9295293891
#endif
9295393892
92954
-
9295593893
/*
92956
-** Generate code to do constraint checks prior to an INSERT or an UPDATE.
92957
-**
92958
-** The input is a range of consecutive registers as follows:
92959
-**
92960
-** 1. The rowid of the row after the update.
92961
-**
92962
-** 2. The data in the first column of the entry after the update.
92963
-**
92964
-** i. Data from middle columns...
92965
-**
92966
-** N. The data in the last column of the entry after the update.
92967
-**
92968
-** The regRowid parameter is the index of the register containing (1).
92969
-**
92970
-** If isUpdate is true and rowidChng is non-zero, then rowidChng contains
92971
-** the address of a register containing the rowid before the update takes
92972
-** place. isUpdate is true for UPDATEs and false for INSERTs. If isUpdate
92973
-** is false, indicating an INSERT statement, then a non-zero rowidChng
92974
-** indicates that the rowid was explicitly specified as part of the
92975
-** INSERT statement. If rowidChng is false, it means that the rowid is
92976
-** computed automatically in an insert or that the rowid value is not
92977
-** modified by an update.
92978
-**
92979
-** The code generated by this routine store new index entries into
93894
+** Generate code to do constraint checks prior to an INSERT or an UPDATE
93895
+** on table pTab.
93896
+**
93897
+** The regNewData parameter is the first register in a range that contains
93898
+** the data to be inserted or the data after the update. There will be
93899
+** pTab->nCol+1 registers in this range. The first register (the one
93900
+** that regNewData points to) will contain the new rowid, or NULL in the
93901
+** case of a WITHOUT ROWID table. The second register in the range will
93902
+** contain the content of the first table column. The third register will
93903
+** contain the content of the second table column. And so forth.
93904
+**
93905
+** The regOldData parameter is similar to regNewData except that it contains
93906
+** the data prior to an UPDATE rather than afterwards. regOldData is zero
93907
+** for an INSERT. This routine can distinguish between UPDATE and INSERT by
93908
+** checking regOldData for zero.
93909
+**
93910
+** For an UPDATE, the pkChng boolean is true if the true primary key (the
93911
+** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
93912
+** might be modified by the UPDATE. If pkChng is false, then the key of
93913
+** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
93914
+**
93915
+** For an INSERT, the pkChng boolean indicates whether or not the rowid
93916
+** was explicitly specified as part of the INSERT statement. If pkChng
93917
+** is zero, it means that the either rowid is computed automatically or
93918
+** that the table is a WITHOUT ROWID table and has no rowid. On an INSERT,
93919
+** pkChng will only be true if the INSERT statement provides an integer
93920
+** value for either the rowid column or its INTEGER PRIMARY KEY alias.
93921
+**
93922
+** The code generated by this routine will store new index entries into
9298093923
** registers identified by aRegIdx[]. No index entry is created for
9298193924
** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
9298293925
** the same as the order of indices on the linked list of indices
92983
-** attached to the table.
93926
+** at pTab->pIndex.
93927
+**
93928
+** The caller must have already opened writeable cursors on the main
93929
+** table and all applicable indices (that is to say, all indices for which
93930
+** aRegIdx[] is not zero). iDataCur is the cursor for the main table when
93931
+** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
93932
+** index when operating on a WITHOUT ROWID table. iIdxCur is the cursor
93933
+** for the first index in the pTab->pIndex list. Cursors for other indices
93934
+** are at iIdxCur+N for the N-th element of the pTab->pIndex list.
9298493935
**
9298593936
** This routine also generates code to check constraints. NOT NULL,
9298693937
** CHECK, and UNIQUE constraints are all checked. If a constraint fails,
9298793938
** then the appropriate action is performed. There are five possible
9298893939
** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
9298993940
**
9299093941
** Constraint type Action What Happens
9299193942
** --------------- ---------- ----------------------------------------
9299293943
** any ROLLBACK The current transaction is rolled back and
92993
-** sqlite3_exec() returns immediately with a
93944
+** sqlite3_step() returns immediately with a
9299493945
** return code of SQLITE_CONSTRAINT.
9299593946
**
9299693947
** any ABORT Back out changes from the current command
9299793948
** only (do not do a complete rollback) then
92998
-** cause sqlite3_exec() to return immediately
93949
+** cause sqlite3_step() to return immediately
9299993950
** with SQLITE_CONSTRAINT.
9300093951
**
93001
-** any FAIL Sqlite3_exec() returns immediately with a
93952
+** any FAIL Sqlite3_step() returns immediately with a
9300293953
** return code of SQLITE_CONSTRAINT. The
9300393954
** transaction is not rolled back and any
93004
-** prior changes are retained.
93955
+** changes to prior rows are retained.
9300593956
**
93006
-** any IGNORE The record number and data is popped from
93007
-** the stack and there is an immediate jump
93008
-** to label ignoreDest.
93957
+** any IGNORE The attempt in insert or update the current
93958
+** row is skipped, without throwing an error.
93959
+** Processing continues with the next row.
93960
+** (There is an immediate jump to ignoreDest.)
9300993961
**
9301093962
** NOT NULL REPLACE The NULL value is replace by the default
9301193963
** value for that column. If the default value
9301293964
** is NULL, the action is the same as ABORT.
9301393965
**
@@ -93018,48 +93970,61 @@
9301893970
**
9301993971
** Which action to take is determined by the overrideError parameter.
9302093972
** Or if overrideError==OE_Default, then the pParse->onError parameter
9302193973
** is used. Or if pParse->onError==OE_Default then the onError value
9302293974
** for the constraint is used.
93023
-**
93024
-** The calling routine must open a read/write cursor for pTab with
93025
-** cursor number "baseCur". All indices of pTab must also have open
93026
-** read/write cursors with cursor number baseCur+i for the i-th cursor.
93027
-** Except, if there is no possibility of a REPLACE action then
93028
-** cursors do not need to be open for indices where aRegIdx[i]==0.
9302993975
*/
9303093976
SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(
93031
- Parse *pParse, /* The parser context */
93032
- Table *pTab, /* the table into which we are inserting */
93033
- int baseCur, /* Index of a read/write cursor pointing at pTab */
93034
- int regRowid, /* Index of the range of input registers */
93035
- int *aRegIdx, /* Register used by each index. 0 for unused indices */
93036
- int rowidChng, /* True if the rowid might collide with existing entry */
93037
- int isUpdate, /* True for UPDATE, False for INSERT */
93038
- int overrideError, /* Override onError to this if not OE_Default */
93039
- int ignoreDest, /* Jump to this label on an OE_Ignore resolution */
93040
- int *pbMayReplace /* OUT: Set to true if constraint may cause a replace */
93977
+ Parse *pParse, /* The parser context */
93978
+ Table *pTab, /* The table being inserted or updated */
93979
+ int *aRegIdx, /* Use register aRegIdx[i] for index i. 0 for unused */
93980
+ int iDataCur, /* Canonical data cursor (main table or PK index) */
93981
+ int iIdxCur, /* First index cursor */
93982
+ int regNewData, /* First register in a range holding values to insert */
93983
+ int regOldData, /* Previous content. 0 for INSERTs */
93984
+ u8 pkChng, /* Non-zero if the rowid or PRIMARY KEY changed */
93985
+ u8 overrideError, /* Override onError to this if not OE_Default */
93986
+ int ignoreDest, /* Jump to this label on an OE_Ignore resolution */
93987
+ int *pbMayReplace /* OUT: Set to true if constraint may cause a replace */
9304193988
){
93042
- int i; /* loop counter */
93043
- Vdbe *v; /* VDBE under constrution */
93044
- int nCol; /* Number of columns */
93045
- int onError; /* Conflict resolution strategy */
93046
- int j1; /* Addresss of jump instruction */
93047
- int j2 = 0, j3; /* Addresses of jump instructions */
93048
- int regData; /* Register containing first data column */
93049
- int iCur; /* Table cursor number */
93989
+ Vdbe *v; /* VDBE under constrution */
9305093990
Index *pIdx; /* Pointer to one of the indices */
93991
+ Index *pPk = 0; /* The PRIMARY KEY index */
9305193992
sqlite3 *db; /* Database connection */
93993
+ int i; /* loop counter */
93994
+ int ix; /* Index loop counter */
93995
+ int nCol; /* Number of columns */
93996
+ int onError; /* Conflict resolution strategy */
93997
+ int j1; /* Addresss of jump instruction */
9305293998
int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
93053
- int regOldRowid = (rowidChng && isUpdate) ? rowidChng : regRowid;
93999
+ int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
94000
+ int ipkTop = 0; /* Top of the rowid change constraint check */
94001
+ int ipkBottom = 0; /* Bottom of the rowid change constraint check */
94002
+ u8 isUpdate; /* True if this is an UPDATE operation */
9305494003
94004
+ isUpdate = regOldData!=0;
9305594005
db = pParse->db;
9305694006
v = sqlite3GetVdbe(pParse);
9305794007
assert( v!=0 );
9305894008
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
9305994009
nCol = pTab->nCol;
93060
- regData = regRowid + 1;
94010
+
94011
+ /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
94012
+ ** normal rowid tables. nPkField is the number of key fields in the
94013
+ ** pPk index or 1 for a rowid table. In other words, nPkField is the
94014
+ ** number of fields in the true primary key of the table. */
94015
+ if( HasRowid(pTab) ){
94016
+ pPk = 0;
94017
+ nPkField = 1;
94018
+ }else{
94019
+ pPk = sqlite3PrimaryKeyIndex(pTab);
94020
+ nPkField = pPk->nKeyCol;
94021
+ }
94022
+
94023
+ /* Record that this module has started */
94024
+ VdbeModuleComment((v, "BEGIN: GenCnstCks(%d,%d,%d,%d,%d)",
94025
+ iDataCur, iIdxCur, regNewData, regOldData, pkChng));
9306194026
9306294027
/* Test all NOT NULL constraints.
9306394028
*/
9306494029
for(i=0; i<nCol; i++){
9306594030
if( i==pTab->iPKey ){
@@ -93078,28 +94043,28 @@
9307894043
assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
9307994044
|| onError==OE_Ignore || onError==OE_Replace );
9308094045
switch( onError ){
9308194046
case OE_Abort:
9308294047
sqlite3MayAbort(pParse);
94048
+ /* Fall through */
9308394049
case OE_Rollback:
9308494050
case OE_Fail: {
93085
- char *zMsg;
93086
- sqlite3VdbeAddOp3(v, OP_HaltIfNull,
93087
- SQLITE_CONSTRAINT_NOTNULL, onError, regData+i);
93088
- zMsg = sqlite3MPrintf(db, "%s.%s may not be NULL",
93089
- pTab->zName, pTab->aCol[i].zName);
93090
- sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC);
94051
+ char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
94052
+ pTab->aCol[i].zName);
94053
+ sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
94054
+ regNewData+1+i, zMsg, P4_DYNAMIC);
94055
+ sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
9309194056
break;
9309294057
}
9309394058
case OE_Ignore: {
93094
- sqlite3VdbeAddOp2(v, OP_IsNull, regData+i, ignoreDest);
94059
+ sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
9309594060
break;
9309694061
}
9309794062
default: {
9309894063
assert( onError==OE_Replace );
93099
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regData+i);
93100
- sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regData+i);
94064
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
94065
+ sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
9310194066
sqlite3VdbeJumpHere(v, j1);
9310294067
break;
9310394068
}
9310494069
}
9310594070
}
@@ -93107,59 +94072,79 @@
9310794072
/* Test all CHECK constraints
9310894073
*/
9310994074
#ifndef SQLITE_OMIT_CHECK
9311094075
if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
9311194076
ExprList *pCheck = pTab->pCheck;
93112
- pParse->ckBase = regData;
94077
+ pParse->ckBase = regNewData+1;
9311394078
onError = overrideError!=OE_Default ? overrideError : OE_Abort;
9311494079
for(i=0; i<pCheck->nExpr; i++){
9311594080
int allOk = sqlite3VdbeMakeLabel(v);
9311694081
sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
9311794082
if( onError==OE_Ignore ){
9311894083
sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
9311994084
}else{
93120
- char *zConsName = pCheck->a[i].zName;
94085
+ char *zName = pCheck->a[i].zName;
94086
+ if( zName==0 ) zName = pTab->zName;
9312194087
if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
93122
- if( zConsName ){
93123
- zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName);
93124
- }else{
93125
- zConsName = 0;
93126
- }
9312794088
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
93128
- onError, zConsName, P4_DYNAMIC);
94089
+ onError, zName, P4_TRANSIENT,
94090
+ P5_ConstraintCheck);
9312994091
}
9313094092
sqlite3VdbeResolveLabel(v, allOk);
9313194093
}
9313294094
}
9313394095
#endif /* !defined(SQLITE_OMIT_CHECK) */
9313494096
93135
- /* If we have an INTEGER PRIMARY KEY, make sure the primary key
93136
- ** of the new record does not previously exist. Except, if this
93137
- ** is an UPDATE and the primary key is not changing, that is OK.
94097
+ /* If rowid is changing, make sure the new rowid does not previously
94098
+ ** exist in the table.
9313894099
*/
93139
- if( rowidChng ){
94100
+ if( pkChng && pPk==0 ){
94101
+ int addrRowidOk = sqlite3VdbeMakeLabel(v);
94102
+
94103
+ /* Figure out what action to take in case of a rowid collision */
9314094104
onError = pTab->keyConf;
9314194105
if( overrideError!=OE_Default ){
9314294106
onError = overrideError;
9314394107
}else if( onError==OE_Default ){
9314494108
onError = OE_Abort;
9314594109
}
93146
-
94110
+
9314794111
if( isUpdate ){
93148
- j2 = sqlite3VdbeAddOp3(v, OP_Eq, regRowid, 0, rowidChng);
94112
+ /* pkChng!=0 does not mean that the rowid has change, only that
94113
+ ** it might have changed. Skip the conflict logic below if the rowid
94114
+ ** is unchanged. */
94115
+ sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
9314994116
}
93150
- j3 = sqlite3VdbeAddOp3(v, OP_NotExists, baseCur, 0, regRowid);
94117
+
94118
+ /* If the response to a rowid conflict is REPLACE but the response
94119
+ ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
94120
+ ** to defer the running of the rowid conflict checking until after
94121
+ ** the UNIQUE constraints have run.
94122
+ */
94123
+ if( onError==OE_Replace && overrideError!=OE_Replace ){
94124
+ for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
94125
+ if( pIdx->onError==OE_Ignore || pIdx->onError==OE_Fail ){
94126
+ ipkTop = sqlite3VdbeAddOp0(v, OP_Goto);
94127
+ break;
94128
+ }
94129
+ }
94130
+ }
94131
+
94132
+ /* Check to see if the new rowid already exists in the table. Skip
94133
+ ** the following conflict logic if it does not. */
94134
+ sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
94135
+
94136
+ /* Generate code that deals with a rowid collision */
9315194137
switch( onError ){
9315294138
default: {
9315394139
onError = OE_Abort;
9315494140
/* Fall thru into the next case */
9315594141
}
9315694142
case OE_Rollback:
9315794143
case OE_Abort:
9315894144
case OE_Fail: {
93159
- sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY,
93160
- onError, "PRIMARY KEY must be unique", P4_STATIC);
94145
+ sqlite3RowidConstraint(pParse, onError, pTab);
9316194146
break;
9316294147
}
9316394148
case OE_Replace: {
9316494149
/* If there are DELETE triggers on this table and the
9316594150
** recursive-triggers flag is set, call GenerateRowDelete() to
@@ -93187,123 +94172,162 @@
9318794172
if( db->flags&SQLITE_RecTriggers ){
9318894173
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
9318994174
}
9319094175
if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){
9319194176
sqlite3MultiWrite(pParse);
93192
- sqlite3GenerateRowDelete(
93193
- pParse, pTab, baseCur, regRowid, 0, pTrigger, OE_Replace
93194
- );
94177
+ sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
94178
+ regNewData, 1, 0, OE_Replace, 1);
9319594179
}else if( pTab->pIndex ){
9319694180
sqlite3MultiWrite(pParse);
93197
- sqlite3GenerateRowIndexDelete(pParse, pTab, baseCur, 0);
94181
+ sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
9319894182
}
9319994183
seenReplace = 1;
9320094184
break;
9320194185
}
9320294186
case OE_Ignore: {
93203
- assert( seenReplace==0 );
94187
+ /*assert( seenReplace==0 );*/
9320494188
sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
9320594189
break;
9320694190
}
9320794191
}
93208
- sqlite3VdbeJumpHere(v, j3);
93209
- if( isUpdate ){
93210
- sqlite3VdbeJumpHere(v, j2);
94192
+ sqlite3VdbeResolveLabel(v, addrRowidOk);
94193
+ if( ipkTop ){
94194
+ ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
94195
+ sqlite3VdbeJumpHere(v, ipkTop);
9321194196
}
9321294197
}
9321394198
9321494199
/* Test all UNIQUE constraints by creating entries for each UNIQUE
9321594200
** index and making sure that duplicate entries do not already exist.
93216
- ** Add the new records to the indices as we go.
94201
+ ** Compute the revised record entries for indices as we go.
94202
+ **
94203
+ ** This loop also handles the case of the PRIMARY KEY index for a
94204
+ ** WITHOUT ROWID table.
9321794205
*/
93218
- for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
93219
- int regIdx;
93220
- int regR;
93221
- int addrSkipRow = 0;
94206
+ for(ix=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, ix++){
94207
+ int regIdx; /* Range of registers hold conent for pIdx */
94208
+ int regR; /* Range of registers holding conflicting PK */
94209
+ int iThisCur; /* Cursor for this UNIQUE index */
94210
+ int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
9322294211
93223
- if( aRegIdx[iCur]==0 ) continue; /* Skip unused indices */
94212
+ if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
94213
+ iThisCur = iIdxCur+ix;
94214
+ addrUniqueOk = sqlite3VdbeMakeLabel(v);
9322494215
94216
+ /* Skip partial indices for which the WHERE clause is not true */
9322594217
if( pIdx->pPartIdxWhere ){
93226
- sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[iCur]);
93227
- addrSkipRow = sqlite3VdbeMakeLabel(v);
93228
- pParse->ckBase = regData;
93229
- sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, addrSkipRow,
94218
+ sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
94219
+ pParse->ckBase = regNewData+1;
94220
+ sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
9323094221
SQLITE_JUMPIFNULL);
9323194222
pParse->ckBase = 0;
9323294223
}
9323394224
93234
- /* Create a key for accessing the index entry */
93235
- regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn+1);
94225
+ /* Create a record for this index entry as it should appear after
94226
+ ** the insert or update. Store that record in the aRegIdx[ix] register
94227
+ */
94228
+ regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
9323694229
for(i=0; i<pIdx->nColumn; i++){
93237
- int idx = pIdx->aiColumn[i];
93238
- if( idx==pTab->iPKey ){
93239
- sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
94230
+ int iField = pIdx->aiColumn[i];
94231
+ int x;
94232
+ if( iField<0 || iField==pTab->iPKey ){
94233
+ x = regNewData;
9324094234
}else{
93241
- sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i);
94235
+ x = iField + regNewData + 1;
9324294236
}
94237
+ sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94238
+ VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
9324394239
}
93244
- sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
93245
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
94240
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
9324694241
sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
93247
- sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
94242
+ VdbeComment((v, "for %s", pIdx->zName));
94243
+ sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
9324894244
93249
- /* Find out what action to take in case there is an indexing conflict */
94245
+ /* In an UPDATE operation, if this index is the PRIMARY KEY index
94246
+ ** of a WITHOUT ROWID table and there has been no change the
94247
+ ** primary key, then no collision is possible. The collision detection
94248
+ ** logic below can all be skipped. */
94249
+ if( isUpdate && pPk==pIdx && pkChng==0 ){
94250
+ sqlite3VdbeResolveLabel(v, addrUniqueOk);
94251
+ continue;
94252
+ }
94253
+
94254
+ /* Find out what action to take in case there is a uniqueness conflict */
9325094255
onError = pIdx->onError;
9325194256
if( onError==OE_None ){
93252
- sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
93253
- sqlite3VdbeResolveLabel(v, addrSkipRow);
94257
+ sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
94258
+ sqlite3VdbeResolveLabel(v, addrUniqueOk);
9325494259
continue; /* pIdx is not a UNIQUE index */
9325594260
}
9325694261
if( overrideError!=OE_Default ){
9325794262
onError = overrideError;
9325894263
}else if( onError==OE_Default ){
9325994264
onError = OE_Abort;
9326094265
}
93261
- if( seenReplace ){
93262
- if( onError==OE_Ignore ) onError = OE_Replace;
93263
- else if( onError==OE_Fail ) onError = OE_Abort;
93264
- }
9326594266
9326694267
/* Check to see if the new index entry will be unique */
93267
- regR = sqlite3GetTempReg(pParse);
93268
- sqlite3VdbeAddOp2(v, OP_SCopy, regOldRowid, regR);
93269
- j3 = sqlite3VdbeAddOp4(v, OP_IsUnique, baseCur+iCur+1, 0,
93270
- regR, SQLITE_INT_TO_PTR(regIdx),
93271
- P4_INT32);
93272
- sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
94268
+ sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94269
+ regIdx, pIdx->nKeyCol);
94270
+
94271
+ /* Generate code to handle collisions */
94272
+ regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94273
+ if( HasRowid(pTab) ){
94274
+ sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94275
+ /* Conflict only if the rowid of the existing index entry
94276
+ ** is different from old-rowid */
94277
+ if( isUpdate ){
94278
+ sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94279
+ }
94280
+ }else{
94281
+ int x;
94282
+ /* Extract the PRIMARY KEY from the end of the index entry and
94283
+ ** store it in registers regR..regR+nPk-1 */
94284
+ if( (isUpdate || onError==OE_Replace) && pIdx!=pPk ){
94285
+ for(i=0; i<pPk->nKeyCol; i++){
94286
+ x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
94287
+ sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
94288
+ VdbeComment((v, "%s.%s", pTab->zName,
94289
+ pTab->aCol[pPk->aiColumn[i]].zName));
94290
+ }
94291
+ }
94292
+ if( isUpdate ){
94293
+ /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
94294
+ ** table, only conflict if the new PRIMARY KEY values are actually
94295
+ ** different from the old.
94296
+ **
94297
+ ** For a UNIQUE index, only conflict if the PRIMARY KEY values
94298
+ ** of the matched index row are different from the original PRIMARY
94299
+ ** KEY values of this row before the update. */
94300
+ int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
94301
+ int op = OP_Ne;
94302
+ int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
94303
+
94304
+ for(i=0; i<pPk->nKeyCol; i++){
94305
+ char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
94306
+ x = pPk->aiColumn[i];
94307
+ if( i==(pPk->nKeyCol-1) ){
94308
+ addrJump = addrUniqueOk;
94309
+ op = OP_Eq;
94310
+ }
94311
+ sqlite3VdbeAddOp4(v, op,
94312
+ regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94313
+ );
94314
+ }
94315
+ }
94316
+ }
9327394317
9327494318
/* Generate code that executes if the new index entry is not unique */
9327594319
assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
9327694320
|| onError==OE_Ignore || onError==OE_Replace );
9327794321
switch( onError ){
9327894322
case OE_Rollback:
9327994323
case OE_Abort:
9328094324
case OE_Fail: {
93281
- int j;
93282
- StrAccum errMsg;
93283
- const char *zSep;
93284
- char *zErr;
93285
-
93286
- sqlite3StrAccumInit(&errMsg, 0, 0, 200);
93287
- errMsg.db = db;
93288
- zSep = pIdx->nColumn>1 ? "columns " : "column ";
93289
- for(j=0; j<pIdx->nColumn; j++){
93290
- char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
93291
- sqlite3StrAccumAppend(&errMsg, zSep, -1);
93292
- zSep = ", ";
93293
- sqlite3StrAccumAppend(&errMsg, zCol, -1);
93294
- }
93295
- sqlite3StrAccumAppend(&errMsg,
93296
- pIdx->nColumn>1 ? " are not unique" : " is not unique", -1);
93297
- zErr = sqlite3StrAccumFinish(&errMsg);
93298
- sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
93299
- onError, zErr, 0);
93300
- sqlite3DbFree(errMsg.db, zErr);
94325
+ sqlite3UniqueConstraint(pParse, onError, pIdx);
9330194326
break;
9330294327
}
9330394328
case OE_Ignore: {
93304
- assert( seenReplace==0 );
9330594329
sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
9330694330
break;
9330794331
}
9330894332
default: {
9330994333
Trigger *pTrigger = 0;
@@ -93310,67 +94334,75 @@
9331094334
assert( onError==OE_Replace );
9331194335
sqlite3MultiWrite(pParse);
9331294336
if( db->flags&SQLITE_RecTriggers ){
9331394337
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
9331494338
}
93315
- sqlite3GenerateRowDelete(
93316
- pParse, pTab, baseCur, regR, 0, pTrigger, OE_Replace
93317
- );
94339
+ sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
94340
+ regR, nPkField, 0, OE_Replace, pIdx==pPk);
9331894341
seenReplace = 1;
9331994342
break;
9332094343
}
9332194344
}
93322
- sqlite3VdbeJumpHere(v, j3);
93323
- sqlite3VdbeResolveLabel(v, addrSkipRow);
93324
- sqlite3ReleaseTempReg(pParse, regR);
94345
+ sqlite3VdbeResolveLabel(v, addrUniqueOk);
94346
+ sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
94347
+ if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
94348
+ }
94349
+ if( ipkTop ){
94350
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, ipkTop+1);
94351
+ sqlite3VdbeJumpHere(v, ipkBottom);
9332594352
}
9332694353
93327
- if( pbMayReplace ){
93328
- *pbMayReplace = seenReplace;
93329
- }
94354
+ *pbMayReplace = seenReplace;
94355
+ VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
9333094356
}
9333194357
9333294358
/*
9333394359
** This routine generates code to finish the INSERT or UPDATE operation
9333494360
** that was started by a prior call to sqlite3GenerateConstraintChecks.
93335
-** A consecutive range of registers starting at regRowid contains the
94361
+** A consecutive range of registers starting at regNewData contains the
9333694362
** rowid and the content to be inserted.
9333794363
**
9333894364
** The arguments to this routine should be the same as the first six
9333994365
** arguments to sqlite3GenerateConstraintChecks.
9334094366
*/
9334194367
SQLITE_PRIVATE void sqlite3CompleteInsertion(
9334294368
Parse *pParse, /* The parser context */
9334394369
Table *pTab, /* the table into which we are inserting */
93344
- int baseCur, /* Index of a read/write cursor pointing at pTab */
93345
- int regRowid, /* Range of content */
94370
+ int iDataCur, /* Cursor of the canonical data source */
94371
+ int iIdxCur, /* First index cursor */
94372
+ int regNewData, /* Range of content */
9334694373
int *aRegIdx, /* Register used by each index. 0 for unused indices */
9334794374
int isUpdate, /* True for UPDATE, False for INSERT */
9334894375
int appendBias, /* True if this is likely to be an append */
9334994376
int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */
9335094377
){
93351
- int i;
93352
- Vdbe *v;
93353
- Index *pIdx;
93354
- u8 pik_flags;
93355
- int regData;
93356
- int regRec;
94378
+ Vdbe *v; /* Prepared statements under construction */
94379
+ Index *pIdx; /* An index being inserted or updated */
94380
+ u8 pik_flags; /* flag values passed to the btree insert */
94381
+ int regData; /* Content registers (after the rowid) */
94382
+ int regRec; /* Register holding assemblied record for the table */
94383
+ int i; /* Loop counter */
9335794384
9335894385
v = sqlite3GetVdbe(pParse);
9335994386
assert( v!=0 );
9336094387
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
9336194388
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
9336294389
if( aRegIdx[i]==0 ) continue;
9336394390
if( pIdx->pPartIdxWhere ){
9336494391
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
9336594392
}
93366
- sqlite3VdbeAddOp2(v, OP_IdxInsert, baseCur+i+1, aRegIdx[i]);
93367
- if( useSeekResult ){
93368
- sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
94393
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
94394
+ pik_flags = 0;
94395
+ if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
94396
+ if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
94397
+ assert( pParse->nested==0 );
94398
+ pik_flags |= OPFLAG_NCHANGE;
9336994399
}
94400
+ if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags);
9337094401
}
93371
- regData = regRowid + 1;
94402
+ if( !HasRowid(pTab) ) return;
94403
+ regData = regNewData + 1;
9337294404
regRec = sqlite3GetTempReg(pParse);
9337394405
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
9337494406
sqlite3TableAffinityStr(v, pTab);
9337594407
sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
9337694408
if( pParse->nested ){
@@ -93383,51 +94415,75 @@
9338394415
pik_flags |= OPFLAG_APPEND;
9338494416
}
9338594417
if( useSeekResult ){
9338694418
pik_flags |= OPFLAG_USESEEKRESULT;
9338794419
}
93388
- sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid);
94420
+ sqlite3VdbeAddOp3(v, OP_Insert, iDataCur, regRec, regNewData);
9338994421
if( !pParse->nested ){
9339094422
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
9339194423
}
9339294424
sqlite3VdbeChangeP5(v, pik_flags);
9339394425
}
9339494426
9339594427
/*
93396
-** Generate code that will open cursors for a table and for all
93397
-** indices of that table. The "baseCur" parameter is the cursor number used
93398
-** for the table. Indices are opened on subsequent cursors.
94428
+** Allocate cursors for the pTab table and all its indices and generate
94429
+** code to open and initialized those cursors.
9339994430
**
93400
-** Return the number of indices on the table.
94431
+** The cursor for the object that contains the complete data (normally
94432
+** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
94433
+** ROWID table) is returned in *piDataCur. The first index cursor is
94434
+** returned in *piIdxCur. The number of indices is returned.
94435
+**
94436
+** Use iBase as the first cursor (either the *piDataCur for rowid tables
94437
+** or the first index for WITHOUT ROWID tables) if it is non-negative.
94438
+** If iBase is negative, then allocate the next available cursor.
94439
+**
94440
+** For a rowid table, *piDataCur will be exactly one less than *piIdxCur.
94441
+** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
94442
+** of *piIdxCurs, depending on where the PRIMARY KEY index appears on the
94443
+** pTab->pIndex list.
9340194444
*/
9340294445
SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
9340394446
Parse *pParse, /* Parsing context */
9340494447
Table *pTab, /* Table to be opened */
93405
- int baseCur, /* Cursor number assigned to the table */
93406
- int op /* OP_OpenRead or OP_OpenWrite */
94448
+ int op, /* OP_OpenRead or OP_OpenWrite */
94449
+ int iBase, /* Use this for the table cursor, if there is one */
94450
+ int *piDataCur, /* Write the database source cursor number here */
94451
+ int *piIdxCur /* Write the first index cursor number here */
9340794452
){
9340894453
int i;
9340994454
int iDb;
9341094455
Index *pIdx;
9341194456
Vdbe *v;
9341294457
93413
- if( IsVirtual(pTab) ) return 0;
94458
+ assert( op==OP_OpenRead || op==OP_OpenWrite );
94459
+ if( IsVirtual(pTab) ){
94460
+ *piDataCur = 0;
94461
+ *piIdxCur = 1;
94462
+ return 0;
94463
+ }
9341494464
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
9341594465
v = sqlite3GetVdbe(pParse);
9341694466
assert( v!=0 );
93417
- sqlite3OpenTable(pParse, baseCur, iDb, pTab, op);
93418
- for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
93419
- KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
94467
+ if( iBase<0 ) iBase = pParse->nTab;
94468
+ if( HasRowid(pTab) ){
94469
+ *piDataCur = iBase++;
94470
+ sqlite3OpenTable(pParse, *piDataCur, iDb, pTab, op);
94471
+ }else{
94472
+ sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
94473
+ }
94474
+ *piIdxCur = iBase;
94475
+ for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94476
+ int iIdxCur = iBase++;
9342094477
assert( pIdx->pSchema==pTab->pSchema );
93421
- sqlite3VdbeAddOp4(v, op, i+baseCur, pIdx->tnum, iDb,
93422
- (char*)pKey, P4_KEYINFO_HANDOFF);
94478
+ if( pIdx->autoIndex==2 && !HasRowid(pTab) ) *piDataCur = iIdxCur;
94479
+ sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94480
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
9342394481
VdbeComment((v, "%s", pIdx->zName));
9342494482
}
93425
- if( pParse->nTab<baseCur+i ){
93426
- pParse->nTab = baseCur+i;
93427
- }
93428
- return i-1;
94483
+ if( iBase>pParse->nTab ) pParse->nTab = iBase;
94484
+ return i;
9342994485
}
9343094486
9343194487
9343294488
#ifdef SQLITE_TEST
9343394489
/*
@@ -93468,17 +94524,17 @@
9346894524
*/
9346994525
static int xferCompatibleIndex(Index *pDest, Index *pSrc){
9347094526
int i;
9347194527
assert( pDest && pSrc );
9347294528
assert( pDest->pTable!=pSrc->pTable );
93473
- if( pDest->nColumn!=pSrc->nColumn ){
94529
+ if( pDest->nKeyCol!=pSrc->nKeyCol ){
9347494530
return 0; /* Different number of columns */
9347594531
}
9347694532
if( pDest->onError!=pSrc->onError ){
9347794533
return 0; /* Different conflict resolution strategies */
9347894534
}
93479
- for(i=0; i<pSrc->nColumn; i++){
94535
+ for(i=0; i<pSrc->nKeyCol; i++){
9348094536
if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
9348194537
return 0; /* Different columns indexed */
9348294538
}
9348394539
if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
9348494540
return 0; /* Different sort orders */
@@ -93533,14 +94589,13 @@
9353394589
struct SrcList_item *pItem; /* An element of pSelect->pSrc */
9353494590
int i; /* Loop counter */
9353594591
int iDbSrc; /* The database of pSrc */
9353694592
int iSrc, iDest; /* Cursors from source and destination */
9353794593
int addr1, addr2; /* Loop addresses */
93538
- int emptyDestTest; /* Address of test for empty pDest */
93539
- int emptySrcTest; /* Address of test for empty pSrc */
94594
+ int emptyDestTest = 0; /* Address of test for empty pDest */
94595
+ int emptySrcTest = 0; /* Address of test for empty pSrc */
9354094596
Vdbe *v; /* The VDBE we are building */
93541
- KeyInfo *pKey; /* Key information for an index */
9354294597
int regAutoinc; /* Memory register used by AUTOINC */
9354394598
int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
9354494599
int regData, regRowid; /* Registers holding data and rowid */
9354594600
9354694601
if( pSelect==0 ){
@@ -93606,10 +94661,13 @@
9360694661
return 0; /* FROM clause does not contain a real table */
9360794662
}
9360894663
if( pSrc==pDest ){
9360994664
return 0; /* tab1 and tab2 may not be the same table */
9361094665
}
94666
+ if( HasRowid(pDest)!=HasRowid(pSrc) ){
94667
+ return 0; /* source and destination must both be WITHOUT ROWID or not */
94668
+ }
9361194669
#ifndef SQLITE_OMIT_VIRTUALTABLE
9361294670
if( pSrc->tabFlags & TF_Virtual ){
9361394671
return 0; /* tab2 must not be a virtual table */
9361494672
}
9361594673
#endif
@@ -93676,11 +94734,14 @@
9367694734
v = sqlite3GetVdbe(pParse);
9367794735
sqlite3CodeVerifySchema(pParse, iDbSrc);
9367894736
iSrc = pParse->nTab++;
9367994737
iDest = pParse->nTab++;
9368094738
regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
94739
+ regData = sqlite3GetTempReg(pParse);
94740
+ regRowid = sqlite3GetTempReg(pParse);
9368194741
sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
94742
+ assert( HasRowid(pDest) || destHasUniqueIdx );
9368294743
if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
9368394744
|| destHasUniqueIdx /* (2) */
9368494745
|| (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
9368594746
){
9368694747
/* In some circumstances, we are able to run the xfer optimization
@@ -93698,62 +94759,60 @@
9369894759
** (3) onError is something other than OE_Abort and OE_Rollback.
9369994760
*/
9370094761
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
9370194762
emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
9370294763
sqlite3VdbeJumpHere(v, addr1);
93703
- }else{
93704
- emptyDestTest = 0;
93705
- }
93706
- sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
93707
- emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
93708
- regData = sqlite3GetTempReg(pParse);
93709
- regRowid = sqlite3GetTempReg(pParse);
93710
- if( pDest->iPKey>=0 ){
93711
- addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
93712
- addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
93713
- sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY,
93714
- onError, "PRIMARY KEY must be unique", P4_STATIC);
93715
- sqlite3VdbeJumpHere(v, addr2);
93716
- autoIncStep(pParse, regAutoinc, regRowid);
93717
- }else if( pDest->pIndex==0 ){
93718
- addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
93719
- }else{
93720
- addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
93721
- assert( (pDest->tabFlags & TF_Autoincrement)==0 );
93722
- }
93723
- sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
93724
- sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
93725
- sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
93726
- sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
93727
- sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
94764
+ }
94765
+ if( HasRowid(pSrc) ){
94766
+ sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94767
+ emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94768
+ if( pDest->iPKey>=0 ){
94769
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94770
+ addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
94771
+ sqlite3RowidConstraint(pParse, onError, pDest);
94772
+ sqlite3VdbeJumpHere(v, addr2);
94773
+ autoIncStep(pParse, regAutoinc, regRowid);
94774
+ }else if( pDest->pIndex==0 ){
94775
+ addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
94776
+ }else{
94777
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94778
+ assert( (pDest->tabFlags & TF_Autoincrement)==0 );
94779
+ }
94780
+ sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
94781
+ sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
94782
+ sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
94783
+ sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94784
+ sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
94785
+ sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94786
+ sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94787
+ }else{
94788
+ sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
94789
+ sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
94790
+ }
9372894791
for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
9372994792
for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
9373094793
if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
9373194794
}
9373294795
assert( pSrcIdx );
93733
- sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
93734
- sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
93735
- pKey = sqlite3IndexKeyinfo(pParse, pSrcIdx);
93736
- sqlite3VdbeAddOp4(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc,
93737
- (char*)pKey, P4_KEYINFO_HANDOFF);
94796
+ sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
94797
+ sqlite3VdbeSetP4KeyInfo(pParse, pSrcIdx);
9373894798
VdbeComment((v, "%s", pSrcIdx->zName));
93739
- pKey = sqlite3IndexKeyinfo(pParse, pDestIdx);
93740
- sqlite3VdbeAddOp4(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest,
93741
- (char*)pKey, P4_KEYINFO_HANDOFF);
94799
+ sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
94800
+ sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
9374294801
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
9374394802
VdbeComment((v, "%s", pDestIdx->zName));
9374494803
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
9374594804
sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
9374694805
sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
9374794806
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
9374894807
sqlite3VdbeJumpHere(v, addr1);
94808
+ sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94809
+ sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
9374994810
}
9375094811
sqlite3VdbeJumpHere(v, emptySrcTest);
9375194812
sqlite3ReleaseTempReg(pParse, regRowid);
9375294813
sqlite3ReleaseTempReg(pParse, regData);
93753
- sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
93754
- sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
9375594814
if( emptyDestTest ){
9375694815
sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
9375794816
sqlite3VdbeJumpHere(v, emptyDestTest);
9375894817
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
9375994818
return 0;
@@ -95251,15 +96310,17 @@
9525196310
{ /* zName: */ "auto_vacuum",
9525296311
/* ePragTyp: */ PragTyp_AUTO_VACUUM,
9525396312
/* ePragFlag: */ PragFlag_NeedSchema,
9525496313
/* iArg: */ 0 },
9525596314
#endif
96315
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9525696316
#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
9525796317
{ /* zName: */ "automatic_index",
9525896318
/* ePragTyp: */ PragTyp_FLAG,
9525996319
/* ePragFlag: */ 0,
9526096320
/* iArg: */ SQLITE_AutoIndex },
96321
+#endif
9526196322
#endif
9526296323
{ /* zName: */ "busy_timeout",
9526396324
/* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
9526496325
/* ePragFlag: */ 0,
9526596326
/* iArg: */ 0 },
@@ -95267,22 +96328,26 @@
9526796328
{ /* zName: */ "cache_size",
9526896329
/* ePragTyp: */ PragTyp_CACHE_SIZE,
9526996330
/* ePragFlag: */ PragFlag_NeedSchema,
9527096331
/* iArg: */ 0 },
9527196332
#endif
96333
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9527296334
{ /* zName: */ "cache_spill",
9527396335
/* ePragTyp: */ PragTyp_FLAG,
9527496336
/* ePragFlag: */ 0,
9527596337
/* iArg: */ SQLITE_CacheSpill },
96338
+#endif
9527696339
{ /* zName: */ "case_sensitive_like",
9527796340
/* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
9527896341
/* ePragFlag: */ 0,
9527996342
/* iArg: */ 0 },
96343
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9528096344
{ /* zName: */ "checkpoint_fullfsync",
9528196345
/* ePragTyp: */ PragTyp_FLAG,
9528296346
/* ePragFlag: */ 0,
9528396347
/* iArg: */ SQLITE_CkptFullFSync },
96348
+#endif
9528496349
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
9528596350
{ /* zName: */ "collation_list",
9528696351
/* ePragTyp: */ PragTyp_COLLATION_LIST,
9528796352
/* ePragFlag: */ 0,
9528896353
/* iArg: */ 0 },
@@ -95291,14 +96356,16 @@
9529196356
{ /* zName: */ "compile_options",
9529296357
/* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
9529396358
/* ePragFlag: */ 0,
9529496359
/* iArg: */ 0 },
9529596360
#endif
96361
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9529696362
{ /* zName: */ "count_changes",
9529796363
/* ePragTyp: */ PragTyp_FLAG,
9529896364
/* ePragFlag: */ 0,
9529996365
/* iArg: */ SQLITE_CountRows },
96366
+#endif
9530096367
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
9530196368
{ /* zName: */ "data_store_directory",
9530296369
/* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
9530396370
/* ePragFlag: */ 0,
9530496371
/* iArg: */ 0 },
@@ -95313,20 +96380,24 @@
9531396380
{ /* zName: */ "default_cache_size",
9531496381
/* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
9531596382
/* ePragFlag: */ PragFlag_NeedSchema,
9531696383
/* iArg: */ 0 },
9531796384
#endif
96385
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9531896386
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
9531996387
{ /* zName: */ "defer_foreign_keys",
9532096388
/* ePragTyp: */ PragTyp_FLAG,
9532196389
/* ePragFlag: */ 0,
9532296390
/* iArg: */ SQLITE_DeferFKs },
9532396391
#endif
96392
+#endif
96393
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9532496394
{ /* zName: */ "empty_result_callbacks",
9532596395
/* ePragTyp: */ PragTyp_FLAG,
9532696396
/* ePragFlag: */ 0,
9532796397
/* iArg: */ SQLITE_NullCallback },
96398
+#endif
9532896399
#if !defined(SQLITE_OMIT_UTF16)
9532996400
{ /* zName: */ "encoding",
9533096401
/* ePragTyp: */ PragTyp_ENCODING,
9533196402
/* ePragFlag: */ 0,
9533296403
/* iArg: */ 0 },
@@ -95341,30 +96412,34 @@
9534196412
{ /* zName: */ "foreign_key_list",
9534296413
/* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
9534396414
/* ePragFlag: */ PragFlag_NeedSchema,
9534496415
/* iArg: */ 0 },
9534596416
#endif
96417
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9534696418
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
9534796419
{ /* zName: */ "foreign_keys",
9534896420
/* ePragTyp: */ PragTyp_FLAG,
9534996421
/* ePragFlag: */ 0,
9535096422
/* iArg: */ SQLITE_ForeignKeys },
96423
+#endif
9535196424
#endif
9535296425
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
9535396426
{ /* zName: */ "freelist_count",
9535496427
/* ePragTyp: */ PragTyp_HEADER_VALUE,
9535596428
/* ePragFlag: */ 0,
9535696429
/* iArg: */ 0 },
9535796430
#endif
96431
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9535896432
{ /* zName: */ "full_column_names",
9535996433
/* ePragTyp: */ PragTyp_FLAG,
9536096434
/* ePragFlag: */ 0,
9536196435
/* iArg: */ SQLITE_FullColNames },
9536296436
{ /* zName: */ "fullfsync",
9536396437
/* ePragTyp: */ PragTyp_FLAG,
9536496438
/* ePragFlag: */ 0,
9536596439
/* iArg: */ SQLITE_FullFSync },
96440
+#endif
9536696441
#if defined(SQLITE_HAS_CODEC)
9536796442
{ /* zName: */ "hexkey",
9536896443
/* ePragTyp: */ PragTyp_HEXKEY,
9536996444
/* ePragFlag: */ 0,
9537096445
/* iArg: */ 0 },
@@ -95371,15 +96446,17 @@
9537196446
{ /* zName: */ "hexrekey",
9537296447
/* ePragTyp: */ PragTyp_HEXKEY,
9537396448
/* ePragFlag: */ 0,
9537496449
/* iArg: */ 0 },
9537596450
#endif
96451
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9537696452
#if !defined(SQLITE_OMIT_CHECK)
9537796453
{ /* zName: */ "ignore_check_constraints",
9537896454
/* ePragTyp: */ PragTyp_FLAG,
9537996455
/* ePragFlag: */ 0,
9538096456
/* iArg: */ SQLITE_IgnoreChecks },
96457
+#endif
9538196458
#endif
9538296459
#if !defined(SQLITE_OMIT_AUTOVACUUM)
9538396460
{ /* zName: */ "incremental_vacuum",
9538496461
/* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
9538596462
/* ePragFlag: */ PragFlag_NeedSchema,
@@ -95415,14 +96492,16 @@
9541596492
{ /* zName: */ "key",
9541696493
/* ePragTyp: */ PragTyp_KEY,
9541796494
/* ePragFlag: */ 0,
9541896495
/* iArg: */ 0 },
9541996496
#endif
96497
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9542096498
{ /* zName: */ "legacy_file_format",
9542196499
/* ePragTyp: */ PragTyp_FLAG,
9542296500
/* ePragFlag: */ 0,
9542396501
/* iArg: */ SQLITE_LegacyFileFmt },
96502
+#endif
9542496503
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
9542596504
{ /* zName: */ "lock_proxy_file",
9542696505
/* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
9542796506
/* ePragFlag: */ 0,
9542896507
/* iArg: */ 0 },
@@ -95459,38 +96538,44 @@
9545996538
{ /* zName: */ "parser_trace",
9546096539
/* ePragTyp: */ PragTyp_PARSER_TRACE,
9546196540
/* ePragFlag: */ 0,
9546296541
/* iArg: */ 0 },
9546396542
#endif
96543
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9546496544
{ /* zName: */ "query_only",
9546596545
/* ePragTyp: */ PragTyp_FLAG,
9546696546
/* ePragFlag: */ 0,
9546796547
/* iArg: */ SQLITE_QueryOnly },
96548
+#endif
9546896549
#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
9546996550
{ /* zName: */ "quick_check",
9547096551
/* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
9547196552
/* ePragFlag: */ PragFlag_NeedSchema,
9547296553
/* iArg: */ 0 },
9547396554
#endif
96555
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9547496556
{ /* zName: */ "read_uncommitted",
9547596557
/* ePragTyp: */ PragTyp_FLAG,
9547696558
/* ePragFlag: */ 0,
9547796559
/* iArg: */ SQLITE_ReadUncommitted },
9547896560
{ /* zName: */ "recursive_triggers",
9547996561
/* ePragTyp: */ PragTyp_FLAG,
9548096562
/* ePragFlag: */ 0,
9548196563
/* iArg: */ SQLITE_RecTriggers },
96564
+#endif
9548296565
#if defined(SQLITE_HAS_CODEC)
9548396566
{ /* zName: */ "rekey",
9548496567
/* ePragTyp: */ PragTyp_REKEY,
9548596568
/* ePragFlag: */ 0,
9548696569
/* iArg: */ 0 },
9548796570
#endif
96571
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9548896572
{ /* zName: */ "reverse_unordered_selects",
9548996573
/* ePragTyp: */ PragTyp_FLAG,
9549096574
/* ePragFlag: */ 0,
9549196575
/* iArg: */ SQLITE_ReverseOrder },
96576
+#endif
9549296577
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
9549396578
{ /* zName: */ "schema_version",
9549496579
/* ePragTyp: */ PragTyp_HEADER_VALUE,
9549596580
/* ePragFlag: */ 0,
9549696581
/* iArg: */ 0 },
@@ -95499,27 +96584,31 @@
9549996584
{ /* zName: */ "secure_delete",
9550096585
/* ePragTyp: */ PragTyp_SECURE_DELETE,
9550196586
/* ePragFlag: */ 0,
9550296587
/* iArg: */ 0 },
9550396588
#endif
96589
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9550496590
{ /* zName: */ "short_column_names",
9550596591
/* ePragTyp: */ PragTyp_FLAG,
9550696592
/* ePragFlag: */ 0,
9550796593
/* iArg: */ SQLITE_ShortColNames },
96594
+#endif
9550896595
{ /* zName: */ "shrink_memory",
9550996596
/* ePragTyp: */ PragTyp_SHRINK_MEMORY,
9551096597
/* ePragFlag: */ 0,
9551196598
/* iArg: */ 0 },
9551296599
{ /* zName: */ "soft_heap_limit",
9551396600
/* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
9551496601
/* ePragFlag: */ 0,
9551596602
/* iArg: */ 0 },
96603
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9551696604
#if defined(SQLITE_DEBUG)
9551796605
{ /* zName: */ "sql_trace",
9551896606
/* ePragTyp: */ PragTyp_FLAG,
9551996607
/* ePragFlag: */ 0,
9552096608
/* iArg: */ SQLITE_SqlTrace },
96609
+#endif
9552196610
#endif
9552296611
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
9552396612
{ /* zName: */ "stats",
9552496613
/* ePragTyp: */ PragTyp_STATS,
9552596614
/* ePragFlag: */ PragFlag_NeedSchema,
@@ -95551,10 +96640,11 @@
9555196640
{ /* zName: */ "user_version",
9555296641
/* ePragTyp: */ PragTyp_HEADER_VALUE,
9555396642
/* ePragFlag: */ 0,
9555496643
/* iArg: */ 0 },
9555596644
#endif
96645
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9555696646
#if defined(SQLITE_DEBUG)
9555796647
{ /* zName: */ "vdbe_addoptrace",
9555896648
/* ePragTyp: */ PragTyp_FLAG,
9555996649
/* ePragFlag: */ 0,
9556096650
/* iArg: */ SQLITE_VdbeAddopTrace },
@@ -95568,10 +96658,11 @@
9556896658
/* iArg: */ SQLITE_VdbeListing },
9556996659
{ /* zName: */ "vdbe_trace",
9557096660
/* ePragTyp: */ PragTyp_FLAG,
9557196661
/* ePragFlag: */ 0,
9557296662
/* iArg: */ SQLITE_VdbeTrace },
96663
+#endif
9557396664
#endif
9557496665
#if !defined(SQLITE_OMIT_WAL)
9557596666
{ /* zName: */ "wal_autocheckpoint",
9557696667
/* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
9557796668
/* ePragFlag: */ 0,
@@ -95579,14 +96670,16 @@
9557996670
{ /* zName: */ "wal_checkpoint",
9558096671
/* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
9558196672
/* ePragFlag: */ PragFlag_NeedSchema,
9558296673
/* iArg: */ 0 },
9558396674
#endif
96675
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
9558496676
{ /* zName: */ "writable_schema",
9558596677
/* ePragTyp: */ PragTyp_FLAG,
9558696678
/* ePragFlag: */ 0,
9558796679
/* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
96680
+#endif
9558896681
};
9558996682
/* Number of pragmas: 56 on by default, 68 total. */
9559096683
/* End of the automatically generated pragma table.
9559196684
***************************************************************************/
9559296685
@@ -96548,12 +97641,11 @@
9654897641
pTab = sqlite3FindTable(db, zRight, zDb);
9654997642
if( pTab ){
9655097643
int i, k;
9655197644
int nHidden = 0;
9655297645
Column *pCol;
96553
- Index *pPk;
96554
- for(pPk=pTab->pIndex; pPk && pPk->autoIndex!=2; pPk=pPk->pNext){}
97646
+ Index *pPk = sqlite3PrimaryKeyIndex(pTab);
9655597647
sqlite3VdbeSetNumCols(v, 6);
9655697648
pParse->nMem = 6;
9655797649
sqlite3CodeVerifySchema(pParse, iDb);
9655897650
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
9655997651
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
@@ -96632,12 +97724,12 @@
9663297724
pParse->nMem = 3;
9663397725
sqlite3CodeVerifySchema(pParse, iDb);
9663497726
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
9663597727
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
9663697728
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
96637
- for(i=0; i<pIdx->nColumn; i++){
96638
- int cnum = pIdx->aiColumn[i];
97729
+ for(i=0; i<pIdx->nKeyCol; i++){
97730
+ i16 cnum = pIdx->aiColumn[i];
9663997731
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
9664097732
sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
9664197733
assert( pTab->nCol>cnum );
9664297734
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
9664397735
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
@@ -96804,13 +97896,12 @@
9680497896
x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
9680597897
if( x==0 ){
9680697898
if( pIdx==0 ){
9680797899
sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead);
9680897900
}else{
96809
- KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
9681097901
sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb);
96811
- sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
97902
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
9681297903
}
9681397904
}else{
9681497905
k = 0;
9681597906
break;
9681697907
}
@@ -96970,20 +98061,24 @@
9697098061
assert( sqlite3SchemaMutexHeld(db, i, 0) );
9697198062
pTbls = &db->aDb[i].pSchema->tblHash;
9697298063
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
9697398064
Table *pTab = sqliteHashData(x);
9697498065
Index *pIdx;
96975
- sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
96976
- cnt++;
98066
+ if( HasRowid(pTab) ){
98067
+ sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
98068
+ VdbeComment((v, "%s", pTab->zName));
98069
+ cnt++;
98070
+ }
9697798071
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
9697898072
sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt);
98073
+ VdbeComment((v, "%s", pIdx->zName));
9697998074
cnt++;
9698098075
}
9698198076
}
9698298077
9698398078
/* Make sure sufficient number of registers have been allocated */
96984
- pParse->nMem = MAX( pParse->nMem, cnt+7 );
98079
+ pParse->nMem = MAX( pParse->nMem, cnt+8 );
9698598080
9698698081
/* Do the b-tree integrity checks */
9698798082
sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
9698898083
sqlite3VdbeChangeP5(v, (u8)i);
9698998084
addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
@@ -96997,62 +98092,64 @@
9699798092
9699898093
/* Make sure all the indices are constructed correctly.
9699998094
*/
9700098095
for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
9700198096
Table *pTab = sqliteHashData(x);
97002
- Index *pIdx;
98097
+ Index *pIdx, *pPk;
9700398098
int loopTop;
98099
+ int iDataCur, iIdxCur;
9700498100
9700598101
if( pTab->pIndex==0 ) continue;
98102
+ pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
9700698103
addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
9700798104
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9700898105
sqlite3VdbeJumpHere(v, addr);
9700998106
sqlite3ExprCacheClear(pParse);
97010
- sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
97011
- for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
97012
- sqlite3VdbeAddOp2(v, OP_Integer, 0, 7+j); /* index entries counter */
97013
- }
97014
- pParse->nMem = MAX(pParse->nMem, 7+j);
97015
- loopTop = sqlite3VdbeAddOp2(v, OP_Rewind, 1, 0) + 1;
97016
- for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
97017
- int jmp2, jmp3;
98107
+ sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98108
+ 1, &iDataCur, &iIdxCur);
98109
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98110
+ for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98111
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98112
+ }
98113
+ pParse->nMem = MAX(pParse->nMem, 8+j);
98114
+ sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0);
98115
+ loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
98116
+ for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98117
+ int jmp2, jmp3, jmp4;
9701898118
int r1;
97019
- static const VdbeOpList idxErr[] = {
97020
- { OP_AddImm, 1, -1, 0},
97021
- { OP_String8, 0, 3, 0}, /* 1 */
97022
- { OP_Rowid, 1, 4, 0},
97023
- { OP_String8, 0, 5, 0}, /* 3 */
97024
- { OP_String8, 0, 6, 0}, /* 4 */
97025
- { OP_Concat, 4, 3, 3},
97026
- { OP_Concat, 5, 3, 3},
97027
- { OP_Concat, 6, 3, 3},
97028
- { OP_ResultRow, 3, 1, 0},
97029
- { OP_IfPos, 1, 0, 0}, /* 9 */
97030
- { OP_Halt, 0, 0, 0},
97031
- };
97032
- r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0, &jmp3);
97033
- sqlite3VdbeAddOp2(v, OP_AddImm, 7+j, 1); /* increment entry count */
97034
- jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1);
97035
- addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
97036
- sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
97037
- sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
97038
- sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_TRANSIENT);
97039
- sqlite3VdbeJumpHere(v, addr+9);
98119
+ if( pPk==pIdx ) continue;
98120
+ r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3);
98121
+ sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
98122
+ jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98123
+ pIdx->nColumn);
98124
+ sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
98125
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
98126
+ sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
98127
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
98128
+ P4_STATIC);
98129
+ sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98130
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
98131
+ sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98132
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98133
+ jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
98134
+ sqlite3VdbeAddOp0(v, OP_Halt);
98135
+ sqlite3VdbeJumpHere(v, jmp4);
9704098136
sqlite3VdbeJumpHere(v, jmp2);
9704198137
sqlite3VdbeResolveLabel(v, jmp3);
9704298138
}
97043
- sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop);
98139
+ sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop);
9704498140
sqlite3VdbeJumpHere(v, loopTop-1);
9704598141
#ifndef SQLITE_OMIT_BTREECOUNT
9704698142
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
9704798143
"wrong # of entries in index ", P4_STATIC);
9704898144
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98145
+ if( pPk==pIdx ) continue;
9704998146
addr = sqlite3VdbeCurrentAddr(v);
9705098147
sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
9705198148
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
97052
- sqlite3VdbeAddOp2(v, OP_Count, j+2, 3);
97053
- sqlite3VdbeAddOp3(v, OP_Eq, 7+j, addr+8, 3);
98149
+ sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98150
+ sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3);
9705498151
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
9705598152
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
9705698153
sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
9705798154
sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
9705898155
}
@@ -99096,28 +100193,61 @@
99096100193
sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
99097100194
}
99098100195
}
99099100196
99100100197
/*
99101
-** Allocate a KeyInfo object sufficient for an index of N columns.
99102
-**
99103
-** Actually, always allocate one extra column for the rowid at the end
99104
-** of the index. So the KeyInfo returned will have space sufficient for
99105
-** N+1 columns.
100198
+** Allocate a KeyInfo object sufficient for an index of N key columns and
100199
+** X extra columns.
99106100200
*/
99107
-SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N){
99108
- KeyInfo *p = sqlite3DbMallocZero(db,
99109
- sizeof(KeyInfo) + (N+1)*(sizeof(CollSeq*)+1));
100201
+SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
100202
+ KeyInfo *p = sqlite3DbMallocZero(0,
100203
+ sizeof(KeyInfo) + (N+X)*(sizeof(CollSeq*)+1));
99110100204
if( p ){
99111
- p->aSortOrder = (u8*)&p->aColl[N+1];
100205
+ p->aSortOrder = (u8*)&p->aColl[N+X];
99112100206
p->nField = (u16)N;
100207
+ p->nXField = (u16)X;
99113100208
p->enc = ENC(db);
99114100209
p->db = db;
100210
+ p->nRef = 1;
100211
+ }else{
100212
+ db->mallocFailed = 1;
100213
+ }
100214
+ return p;
100215
+}
100216
+
100217
+/*
100218
+** Deallocate a KeyInfo object
100219
+*/
100220
+SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
100221
+ if( p ){
100222
+ assert( p->nRef>0 );
100223
+ p->nRef--;
100224
+ if( p->nRef==0 ) sqlite3DbFree(0, p);
100225
+ }
100226
+}
100227
+
100228
+/*
100229
+** Make a new pointer to a KeyInfo object
100230
+*/
100231
+SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo *p){
100232
+ if( p ){
100233
+ assert( p->nRef>0 );
100234
+ p->nRef++;
99115100235
}
99116100236
return p;
99117100237
}
99118100238
100239
+#ifdef SQLITE_DEBUG
100240
+/*
100241
+** Return TRUE if a KeyInfo object can be change. The KeyInfo object
100242
+** can only be changed if this is just a single reference to the object.
100243
+**
100244
+** This routine is used only inside of assert() statements.
100245
+*/
100246
+SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo *p){ return p->nRef==1; }
100247
+#endif /* SQLITE_DEBUG */
100248
+
99119100249
/*
99120100250
** Given an expression list, generate a KeyInfo structure that records
99121100251
** the collating sequence for each expression in that expression list.
99122100252
**
99123100253
** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
@@ -99126,23 +100256,23 @@
99126100256
** then the KeyInfo structure is appropriate for initializing a virtual
99127100257
** index to implement a DISTINCT test.
99128100258
**
99129100259
** Space to hold the KeyInfo structure is obtain from malloc. The calling
99130100260
** function is responsible for seeing that this structure is eventually
99131
-** freed. Add the KeyInfo structure to the P4 field of an opcode using
99132
-** P4_KEYINFO_HANDOFF is the usual way of dealing with this.
100261
+** freed.
99133100262
*/
99134100263
static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
99135100264
int nExpr;
99136100265
KeyInfo *pInfo;
99137100266
struct ExprList_item *pItem;
99138100267
sqlite3 *db = pParse->db;
99139100268
int i;
99140100269
99141100270
nExpr = pList->nExpr;
99142
- pInfo = sqlite3KeyInfoAlloc(db, nExpr);
100271
+ pInfo = sqlite3KeyInfoAlloc(db, nExpr, 1);
99143100272
if( pInfo ){
100273
+ assert( sqlite3KeyInfoIsWriteable(pInfo) );
99144100274
for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
99145100275
CollSeq *pColl;
99146100276
pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
99147100277
if( !pColl ) pColl = db->pDfltColl;
99148100278
pInfo->aColl[i] = pColl;
@@ -100281,11 +101411,11 @@
100281101411
CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
100282101412
int nCol; /* Number of columns in result set */
100283101413
100284101414
assert( p->pRightmost==p );
100285101415
nCol = p->pEList->nExpr;
100286
- pKeyInfo = sqlite3KeyInfoAlloc(db, nCol);
101416
+ pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
100287101417
if( !pKeyInfo ){
100288101418
rc = SQLITE_NOMEM;
100289101419
goto multi_select_end;
100290101420
}
100291101421
for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
@@ -100303,15 +101433,16 @@
100303101433
** always safely abort as soon as the first unused slot is found */
100304101434
assert( pLoop->addrOpenEphm[1]<0 );
100305101435
break;
100306101436
}
100307101437
sqlite3VdbeChangeP2(v, addr, nCol);
100308
- sqlite3VdbeChangeP4(v, addr, (char*)pKeyInfo, P4_KEYINFO);
101438
+ sqlite3VdbeChangeP4(v, addr, (char*)sqlite3KeyInfoRef(pKeyInfo),
101439
+ P4_KEYINFO);
100309101440
pLoop->addrOpenEphm[i] = -1;
100310101441
}
100311101442
}
100312
- sqlite3DbFree(db, pKeyInfo);
101443
+ sqlite3KeyInfoUnref(pKeyInfo);
100313101444
}
100314101445
100315101446
multi_select_end:
100316101447
pDest->iSdst = dest.iSdst;
100317101448
pDest->nSdst = dest.nSdst;
@@ -100346,11 +101477,10 @@
100346101477
SelectDest *pIn, /* Coroutine supplying data */
100347101478
SelectDest *pDest, /* Where to send the data */
100348101479
int regReturn, /* The return address register */
100349101480
int regPrev, /* Previous result register. No uniqueness if 0 */
100350101481
KeyInfo *pKeyInfo, /* For comparing with previous entry */
100351
- int p4type, /* The p4 type for pKeyInfo */
100352101482
int iBreak /* Jump here if we hit the LIMIT */
100353101483
){
100354101484
Vdbe *v = pParse->pVdbe;
100355101485
int iContinue;
100356101486
int addr;
@@ -100362,11 +101492,11 @@
100362101492
*/
100363101493
if( regPrev ){
100364101494
int j1, j2;
100365101495
j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
100366101496
j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
100367
- (char*)pKeyInfo, p4type);
101497
+ (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
100368101498
sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
100369101499
sqlite3VdbeJumpHere(v, j1);
100370101500
sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
100371101501
sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
100372101502
}
@@ -100660,11 +101790,11 @@
100660101790
struct ExprList_item *pItem;
100661101791
for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
100662101792
assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
100663101793
aPermute[i] = pItem->iOrderByCol - 1;
100664101794
}
100665
- pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy);
101795
+ pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
100666101796
if( pKeyMerge ){
100667101797
for(i=0; i<nOrderBy; i++){
100668101798
CollSeq *pColl;
100669101799
Expr *pTerm = pOrderBy->a[i].pExpr;
100670101800
if( pTerm->flags & EP_Collate ){
@@ -100673,10 +101803,11 @@
100673101803
pColl = multiSelectCollSeq(pParse, p, aPermute[i]);
100674101804
if( pColl==0 ) pColl = db->pDfltColl;
100675101805
pOrderBy->a[i].pExpr =
100676101806
sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
100677101807
}
101808
+ assert( sqlite3KeyInfoIsWriteable(pKeyMerge) );
100678101809
pKeyMerge->aColl[i] = pColl;
100679101810
pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder;
100680101811
}
100681101812
}
100682101813
}else{
@@ -100698,12 +101829,13 @@
100698101829
int nExpr = p->pEList->nExpr;
100699101830
assert( nOrderBy>=nExpr || db->mallocFailed );
100700101831
regPrev = pParse->nMem+1;
100701101832
pParse->nMem += nExpr+1;
100702101833
sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
100703
- pKeyDup = sqlite3KeyInfoAlloc(db, nExpr);
101834
+ pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
100704101835
if( pKeyDup ){
101836
+ assert( sqlite3KeyInfoIsWriteable(pKeyDup) );
100705101837
for(i=0; i<nExpr; i++){
100706101838
pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
100707101839
pKeyDup->aSortOrder[i] = 0;
100708101840
}
100709101841
}
@@ -100781,21 +101913,22 @@
100781101913
** select as the next output row of the compound select.
100782101914
*/
100783101915
VdbeNoopComment((v, "Output routine for A"));
100784101916
addrOutA = generateOutputSubroutine(pParse,
100785101917
p, &destA, pDest, regOutA,
100786
- regPrev, pKeyDup, P4_KEYINFO_HANDOFF, labelEnd);
101918
+ regPrev, pKeyDup, labelEnd);
100787101919
100788101920
/* Generate a subroutine that outputs the current row of the B
100789101921
** select as the next output row of the compound select.
100790101922
*/
100791101923
if( op==TK_ALL || op==TK_UNION ){
100792101924
VdbeNoopComment((v, "Output routine for B"));
100793101925
addrOutB = generateOutputSubroutine(pParse,
100794101926
p, &destB, pDest, regOutB,
100795
- regPrev, pKeyDup, P4_KEYINFO_STATIC, labelEnd);
101927
+ regPrev, pKeyDup, labelEnd);
100796101928
}
101929
+ sqlite3KeyInfoUnref(pKeyDup);
100797101930
100798101931
/* Generate a subroutine to run when the results from select A
100799101932
** are exhausted and only data in select B remains.
100800101933
*/
100801101934
VdbeNoopComment((v, "eof-A subroutine"));
@@ -100870,11 +102003,11 @@
100870102003
/* Implement the main merge loop
100871102004
*/
100872102005
sqlite3VdbeResolveLabel(v, labelCmpr);
100873102006
sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
100874102007
sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
100875
- (char*)pKeyMerge, P4_KEYINFO_HANDOFF);
102008
+ (char*)pKeyMerge, P4_KEYINFO);
100876102009
sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
100877102010
sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
100878102011
100879102012
/* Jump to the this point in order to terminate the query.
100880102013
*/
@@ -102096,11 +103229,11 @@
102096103229
"argument");
102097103230
pFunc->iDistinct = -1;
102098103231
}else{
102099103232
KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->x.pList);
102100103233
sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
102101
- (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
103234
+ (char*)pKeyInfo, P4_KEYINFO);
102102103235
}
102103103236
}
102104103237
}
102105103238
}
102106103239
@@ -102551,11 +103684,11 @@
102551103684
pKeyInfo = keyInfoFromExprList(pParse, pOrderBy);
102552103685
pOrderBy->iECursor = pParse->nTab++;
102553103686
p->addrOpenEphm[2] = addrSortIndex =
102554103687
sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
102555103688
pOrderBy->iECursor, pOrderBy->nExpr+2, 0,
102556
- (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
103689
+ (char*)pKeyInfo, P4_KEYINFO);
102557103690
}else{
102558103691
addrSortIndex = -1;
102559103692
}
102560103693
102561103694
/* If the output is destined for a temporary table, open that table.
@@ -102579,11 +103712,11 @@
102579103712
if( p->selFlags & SF_Distinct ){
102580103713
sDistinct.tabTnct = pParse->nTab++;
102581103714
sDistinct.addrTnct = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
102582103715
sDistinct.tabTnct, 0, 0,
102583103716
(char*)keyInfoFromExprList(pParse, p->pEList),
102584
- P4_KEYINFO_HANDOFF);
103717
+ P4_KEYINFO);
102585103718
sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
102586103719
sDistinct.eTnctType = WHERE_DISTINCT_UNORDERED;
102587103720
}else{
102588103721
sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
102589103722
}
@@ -102703,11 +103836,11 @@
102703103836
*/
102704103837
sAggInfo.sortingIdx = pParse->nTab++;
102705103838
pKeyInfo = keyInfoFromExprList(pParse, pGroupBy);
102706103839
addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
102707103840
sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
102708
- 0, (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
103841
+ 0, (char*)pKeyInfo, P4_KEYINFO);
102709103842
102710103843
/* Initialize memory locations used by GROUP BY aggregate processing
102711103844
*/
102712103845
iUseFlag = ++pParse->nMem;
102713103846
iAbortFlag = ++pParse->nMem;
@@ -102817,11 +103950,11 @@
102817103950
sAggInfo.directMode = 1;
102818103951
sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
102819103952
}
102820103953
}
102821103954
sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
102822
- (char*)pKeyInfo, P4_KEYINFO);
103955
+ (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
102823103956
j1 = sqlite3VdbeCurrentAddr(v);
102824103957
sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
102825103958
102826103959
/* Generate code that runs whenever the GROUP BY changes.
102827103960
** Changes in the GROUP BY are detected by the previous code
@@ -102943,17 +104076,17 @@
102943104076
pBest = pIdx;
102944104077
}
102945104078
}
102946104079
if( pBest ){
102947104080
iRoot = pBest->tnum;
102948
- pKeyInfo = sqlite3IndexKeyinfo(pParse, pBest);
104081
+ pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest);
102949104082
}
102950104083
102951104084
/* Open a read-only cursor, execute the OP_Count, close the cursor. */
102952
- sqlite3VdbeAddOp3(v, OP_OpenRead, iCsr, iRoot, iDb);
104085
+ sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, iRoot, iDb, 1);
102953104086
if( pKeyInfo ){
102954
- sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO_HANDOFF);
104087
+ sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
102955104088
}
102956104089
sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
102957104090
sqlite3VdbeAddOp1(v, OP_Close, iCsr);
102958104091
explainSimpleCount(pParse, pTab, pBest);
102959104092
}else
@@ -104155,11 +105288,11 @@
104155105288
}
104156105289
104157105290
return 0;
104158105291
}
104159105292
104160
-#ifdef SQLITE_DEBUG
105293
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
104161105294
/*
104162105295
** This function is used to add VdbeComment() annotations to a VDBE
104163105296
** program. It is not used in production code, only for debugging.
104164105297
*/
104165105298
static const char *onErrorText(int onError){
@@ -104603,44 +105736,54 @@
104603105736
Expr *pWhere, /* The WHERE clause. May be null */
104604105737
int onError /* How to handle constraint errors */
104605105738
){
104606105739
int i, j; /* Loop counters */
104607105740
Table *pTab; /* The table to be updated */
104608
- int addr = 0; /* VDBE instruction address of the start of the loop */
105741
+ int addrTop = 0; /* VDBE instruction address of the start of the loop */
104609105742
WhereInfo *pWInfo; /* Information about the WHERE clause */
104610105743
Vdbe *v; /* The virtual database engine */
104611105744
Index *pIdx; /* For looping over indices */
105745
+ Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
104612105746
int nIdx; /* Number of indices that need updating */
104613
- int iCur; /* VDBE Cursor number of pTab */
105747
+ int iDataCur; /* Cursor for the canonical data btree */
105748
+ int iIdxCur; /* Cursor for the first index */
104614105749
sqlite3 *db; /* The database structure */
104615105750
int *aRegIdx = 0; /* One register assigned to each index to be updated */
104616105751
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
104617105752
** an expression for the i-th column of the table.
104618105753
** aXRef[i]==-1 if the i-th column is not changed. */
104619
- int chngRowid; /* True if the record number is being changed */
105754
+ u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105755
+ u8 chngRowid; /* Rowid changed in a normal table */
105756
+ u8 chngKey; /* Either chngPk or chngRowid */
104620105757
Expr *pRowidExpr = 0; /* Expression defining the new record number */
104621105758
int openAll = 0; /* True if all indices need to be opened */
104622105759
AuthContext sContext; /* The authorization context */
104623105760
NameContext sNC; /* The name-context to resolve expressions in */
104624105761
int iDb; /* Database containing the table being updated */
104625105762
int okOnePass; /* True for one-pass algorithm without the FIFO */
104626105763
int hasFK; /* True if foreign key processing is required */
105764
+ int labelBreak; /* Jump here to break out of UPDATE loop */
105765
+ int labelContinue; /* Jump here to continue next step of UPDATE loop */
104627105766
104628105767
#ifndef SQLITE_OMIT_TRIGGER
104629105768
int isView; /* True when updating a view (INSTEAD OF trigger) */
104630105769
Trigger *pTrigger; /* List of triggers on pTab, if required */
104631105770
int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
104632105771
#endif
104633105772
int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */
105773
+ int iEph = 0; /* Ephemeral table holding all primary key values */
105774
+ int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
105775
+ int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
104634105776
104635105777
/* Register Allocations */
104636105778
int regRowCount = 0; /* A count of rows changed */
104637105779
int regOldRowid; /* The old rowid */
104638105780
int regNewRowid; /* The new rowid */
104639105781
int regNew; /* Content of the NEW.* table in triggers */
104640105782
int regOld = 0; /* Content of OLD.* table in triggers */
104641105783
int regRowSet = 0; /* Rowset of rows to be updated */
105784
+ int regKey = 0; /* composite PRIMARY KEY value */
104642105785
104643105786
memset(&sContext, 0, sizeof(sContext));
104644105787
db = pParse->db;
104645105788
if( pParse->nErr || db->mallocFailed ){
104646105789
goto update_cleanup;
@@ -104683,12 +105826,18 @@
104683105826
/* Allocate a cursors for the main database table and for all indices.
104684105827
** The index cursors might not be used, but if they are used they
104685105828
** need to occur right after the database cursor. So go ahead and
104686105829
** allocate enough space, just in case.
104687105830
*/
104688
- pTabList->a[0].iCursor = iCur = pParse->nTab++;
104689
- for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
105831
+ pTabList->a[0].iCursor = iDataCur = pParse->nTab++;
105832
+ iIdxCur = iDataCur+1;
105833
+ pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105834
+ for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105835
+ if( pIdx->autoIndex==2 && pPk!=0 ){
105836
+ iDataCur = pParse->nTab;
105837
+ pTabList->a[0].iCursor = iDataCur;
105838
+ }
104690105839
pParse->nTab++;
104691105840
}
104692105841
104693105842
/* Initialize the name-context */
104694105843
memset(&sNC, 0, sizeof(sNC));
@@ -104699,27 +105848,29 @@
104699105848
** of the UPDATE statement. Also find the column index
104700105849
** for each column to be updated in the pChanges array. For each
104701105850
** column to be updated, make sure we have authorization to change
104702105851
** that column.
104703105852
*/
104704
- chngRowid = 0;
105853
+ chngRowid = chngPk = 0;
104705105854
for(i=0; i<pChanges->nExpr; i++){
104706105855
if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
104707105856
goto update_cleanup;
104708105857
}
104709105858
for(j=0; j<pTab->nCol; j++){
104710105859
if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
104711105860
if( j==pTab->iPKey ){
104712105861
chngRowid = 1;
104713105862
pRowidExpr = pChanges->a[i].pExpr;
105863
+ }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
105864
+ chngPk = 1;
104714105865
}
104715105866
aXRef[j] = i;
104716105867
break;
104717105868
}
104718105869
}
104719105870
if( j>=pTab->nCol ){
104720
- if( sqlite3IsRowid(pChanges->a[i].zName) ){
105871
+ if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zName) ){
104721105872
j = -1;
104722105873
chngRowid = 1;
104723105874
pRowidExpr = pChanges->a[i].pExpr;
104724105875
}else{
104725105876
sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
@@ -104739,30 +105890,33 @@
104739105890
aXRef[j] = -1;
104740105891
}
104741105892
}
104742105893
#endif
104743105894
}
105895
+ assert( (chngRowid & chngPk)==0 );
105896
+ assert( chngRowid==0 || chngRowid==1 );
105897
+ assert( chngPk==0 || chngPk==1 );
105898
+ chngKey = chngRowid + chngPk;
104744105899
104745
- hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngRowid);
105900
+ hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
104746105901
104747105902
/* Allocate memory for the array aRegIdx[]. There is one entry in the
104748105903
** array for each index associated with table being updated. Fill in
104749105904
** the value with a register number for indices that are to be used
104750105905
** and with zero for unused indices.
104751105906
*/
104752
- for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
104753105907
if( nIdx>0 ){
104754105908
aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
104755105909
if( aRegIdx==0 ) goto update_cleanup;
104756105910
}
104757105911
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
104758105912
int reg;
104759
- if( hasFK || chngRowid || pIdx->pPartIdxWhere ){
105913
+ if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
104760105914
reg = ++pParse->nMem;
104761105915
}else{
104762105916
reg = 0;
104763
- for(i=0; i<pIdx->nColumn; i++){
105917
+ for(i=0; i<pIdx->nKeyCol; i++){
104764105918
if( aXRef[pIdx->aiColumn[i]]>=0 ){
104765105919
reg = ++pParse->nMem;
104766105920
break;
104767105921
}
104768105922
}
@@ -104788,15 +105942,15 @@
104788105942
#endif
104789105943
104790105944
/* Allocate required registers. */
104791105945
regRowSet = ++pParse->nMem;
104792105946
regOldRowid = regNewRowid = ++pParse->nMem;
104793
- if( pTrigger || hasFK ){
105947
+ if( chngPk || pTrigger || hasFK ){
104794105948
regOld = pParse->nMem + 1;
104795105949
pParse->nMem += pTab->nCol;
104796105950
}
104797
- if( chngRowid || pTrigger || hasFK ){
105951
+ if( chngKey || pTrigger || hasFK ){
104798105952
regNewRowid = ++pParse->nMem;
104799105953
}
104800105954
regNew = pParse->nMem + 1;
104801105955
pParse->nMem += pTab->nCol;
104802105956
@@ -104808,11 +105962,11 @@
104808105962
/* If we are trying to update a view, realize that view into
104809105963
** a ephemeral table.
104810105964
*/
104811105965
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
104812105966
if( isView ){
104813
- sqlite3MaterializeView(pParse, pTab, pWhere, iCur);
105967
+ sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur);
104814105968
}
104815105969
#endif
104816105970
104817105971
/* Resolve the column names in all the expressions in the
104818105972
** WHERE clause.
@@ -104821,43 +105975,81 @@
104821105975
goto update_cleanup;
104822105976
}
104823105977
104824105978
/* Begin the database scan
104825105979
*/
104826
- sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
104827
- pWInfo = sqlite3WhereBegin(
104828
- pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, 0
104829
- );
104830
- if( pWInfo==0 ) goto update_cleanup;
104831
- okOnePass = sqlite3WhereOkOnePass(pWInfo);
104832
-
104833
- /* Remember the rowid of every item to be updated.
104834
- */
104835
- sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regOldRowid);
104836
- if( !okOnePass ){
104837
- sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
104838
- }
104839
-
104840
- /* End the database scan loop.
104841
- */
104842
- sqlite3WhereEnd(pWInfo);
105980
+ if( HasRowid(pTab) ){
105981
+ sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
105982
+ pWInfo = sqlite3WhereBegin(
105983
+ pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, iIdxCur
105984
+ );
105985
+ if( pWInfo==0 ) goto update_cleanup;
105986
+ okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
105987
+
105988
+ /* Remember the rowid of every item to be updated.
105989
+ */
105990
+ sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
105991
+ if( !okOnePass ){
105992
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
105993
+ }
105994
+
105995
+ /* End the database scan loop.
105996
+ */
105997
+ sqlite3WhereEnd(pWInfo);
105998
+ }else{
105999
+ int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
106000
+ i16 nPk; /* Number of components of the PRIMARY KEY */
106001
+ int addrOpen; /* Address of the OpenEphemeral instruction */
106002
+
106003
+ assert( pPk!=0 );
106004
+ nPk = pPk->nKeyCol;
106005
+ iPk = pParse->nMem+1;
106006
+ pParse->nMem += nPk;
106007
+ regKey = ++pParse->nMem;
106008
+ iEph = pParse->nTab++;
106009
+ sqlite3VdbeAddOp2(v, OP_Null, 0, iPk);
106010
+ addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
106011
+ sqlite3VdbeSetP4KeyInfo(pParse, pPk);
106012
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
106013
+ WHERE_ONEPASS_DESIRED, iIdxCur);
106014
+ if( pWInfo==0 ) goto update_cleanup;
106015
+ okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
106016
+ for(i=0; i<nPk; i++){
106017
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
106018
+ iPk+i);
106019
+ }
106020
+ if( okOnePass ){
106021
+ sqlite3VdbeChangeToNoop(v, addrOpen);
106022
+ nKey = nPk;
106023
+ regKey = iPk;
106024
+ }else{
106025
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106026
+ sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
106027
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106028
+ }
106029
+ sqlite3WhereEnd(pWInfo);
106030
+ }
104843106031
104844106032
/* Initialize the count of updated rows
104845106033
*/
104846106034
if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
104847106035
regRowCount = ++pParse->nMem;
104848106036
sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
104849106037
}
104850106038
106039
+ labelBreak = sqlite3VdbeMakeLabel(v);
104851106040
if( !isView ){
104852106041
/*
104853106042
** Open every index that needs updating. Note that if any
104854106043
** index could potentially invoke a REPLACE conflict resolution
104855106044
** action, then we need to open all indices because we might need
104856106045
** to be deleting some records.
104857106046
*/
104858
- if( !okOnePass ) sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
106047
+ if( !okOnePass && HasRowid(pTab) ){
106048
+ sqlite3OpenTable(pParse, iDataCur, iDb, pTab, OP_OpenWrite);
106049
+ }
106050
+ sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
104859106051
if( onError==OE_Replace ){
104860106052
openAll = 1;
104861106053
}else{
104862106054
openAll = 0;
104863106055
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
@@ -104866,59 +106058,71 @@
104866106058
break;
104867106059
}
104868106060
}
104869106061
}
104870106062
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106063
+ int iThisCur = iIdxCur+i;
104871106064
assert( aRegIdx );
104872
- if( openAll || aRegIdx[i]>0 ){
104873
- KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
104874
- sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,
104875
- (char*)pKey, P4_KEYINFO_HANDOFF);
104876
- assert( pParse->nTab>iCur+i+1 );
106065
+ if( (openAll || aRegIdx[i]>0)
106066
+ && iThisCur!=aiCurOnePass[1]
106067
+ ){
106068
+ assert( iThisCur!=aiCurOnePass[0] );
106069
+ sqlite3VdbeAddOp3(v, OP_OpenWrite, iThisCur, pIdx->tnum, iDb);
106070
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
106071
+ assert( pParse->nTab>iThisCur );
106072
+ VdbeComment((v, "%s", pIdx->zName));
106073
+ if( okOnePass && pPk && iThisCur==iDataCur ){
106074
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak,
106075
+ regKey, nKey);
106076
+ }
104877106077
}
104878106078
}
104879106079
}
104880106080
104881106081
/* Top of the update loop */
104882106082
if( okOnePass ){
104883
- int a1 = sqlite3VdbeAddOp1(v, OP_NotNull, regOldRowid);
104884
- addr = sqlite3VdbeAddOp0(v, OP_Goto);
104885
- sqlite3VdbeJumpHere(v, a1);
106083
+ labelContinue = labelBreak;
106084
+ sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106085
+ }else if( pPk ){
106086
+ labelContinue = sqlite3VdbeMakeLabel(v);
106087
+ sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
106088
+ addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106089
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
104886106090
}else{
104887
- addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, 0, regOldRowid);
106091
+ labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106092
+ regOldRowid);
106093
+ sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
104888106094
}
104889106095
104890
- /* Make cursor iCur point to the record that is being updated. If
104891
- ** this record does not exist for some reason (deleted by a trigger,
104892
- ** for example, then jump to the next iteration of the RowSet loop. */
104893
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);
104894
-
104895106096
/* If the record number will change, set register regNewRowid to
104896106097
** contain the new value. If the record number is not being modified,
104897106098
** then regNewRowid is the same register as regOldRowid, which is
104898106099
** already populated. */
104899
- assert( chngRowid || pTrigger || hasFK || regOldRowid==regNewRowid );
106100
+ assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
104900106101
if( chngRowid ){
104901106102
sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
104902106103
sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
104903106104
}
104904106105
104905
- /* If there are triggers on this table, populate an array of registers
104906
- ** with the required old.* column data. */
104907
- if( hasFK || pTrigger ){
106106
+ /* Compute the old pre-UPDATE content of the row being changed, if that
106107
+ ** information is needed */
106108
+ if( chngPk || hasFK || pTrigger ){
104908106109
u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
104909106110
oldmask |= sqlite3TriggerColmask(pParse,
104910106111
pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
104911106112
);
104912106113
for(i=0; i<pTab->nCol; i++){
104913
- if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){
104914
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
106114
+ if( oldmask==0xffffffff
106115
+ || (i<32 && (oldmask & (1<<i)))
106116
+ || (pTab->aCol[i].colFlags & COLFLAG_PRIMKEY)!=0
106117
+ ){
106118
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regOld+i);
104915106119
}else{
104916106120
sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
104917106121
}
104918106122
}
104919
- if( chngRowid==0 ){
106123
+ if( chngRowid==0 && pPk==0 ){
104920106124
sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);
104921106125
}
104922106126
}
104923106127
104924106128
/* Populate the array of registers beginning at regNew with the new
@@ -104951,12 +106155,11 @@
104951106155
** if there are one or more BEFORE triggers that use this value via
104952106156
** a new.* reference in a trigger program.
104953106157
*/
104954106158
testcase( i==31 );
104955106159
testcase( i==32 );
104956
- sqlite3VdbeAddOp3(v, OP_Column, iCur, i, regNew+i);
104957
- sqlite3ColumnDefault(v, pTab, i, regNew+i);
106160
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
104958106161
}
104959106162
}
104960106163
}
104961106164
104962106165
/* Fire any BEFORE UPDATE triggers. This happens before constraints are
@@ -104964,67 +106167,85 @@
104964106167
*/
104965106168
if( tmask&TRIGGER_BEFORE ){
104966106169
sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
104967106170
sqlite3TableAffinityStr(v, pTab);
104968106171
sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
104969
- TRIGGER_BEFORE, pTab, regOldRowid, onError, addr);
106172
+ TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
104970106173
104971106174
/* The row-trigger may have deleted the row being updated. In this
104972106175
** case, jump to the next row. No updates or AFTER triggers are
104973106176
** required. This behavior - what happens when the row being updated
104974106177
** is deleted or renamed by a BEFORE trigger - is left undefined in the
104975106178
** documentation.
104976106179
*/
104977
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);
106180
+ if( pPk ){
106181
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
106182
+ }else{
106183
+ sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106184
+ }
104978106185
104979106186
/* If it did not delete it, the row-trigger may still have modified
104980106187
** some of the columns of the row being updated. Load the values for
104981106188
** all columns not modified by the update statement into their
104982106189
** registers in case this has happened.
104983106190
*/
104984106191
for(i=0; i<pTab->nCol; i++){
104985106192
if( aXRef[i]<0 && i!=pTab->iPKey ){
104986
- sqlite3VdbeAddOp3(v, OP_Column, iCur, i, regNew+i);
104987
- sqlite3ColumnDefault(v, pTab, i, regNew+i);
106193
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
104988106194
}
104989106195
}
104990106196
}
104991106197
104992106198
if( !isView ){
104993
- int j1; /* Address of jump instruction */
106199
+ int j1 = 0; /* Address of jump instruction */
106200
+ int bReplace = 0; /* True if REPLACE conflict resolution might happen */
104994106201
104995106202
/* Do constraint checks. */
104996
- sqlite3GenerateConstraintChecks(pParse, pTab, iCur, regNewRowid,
104997
- aRegIdx, (chngRowid?regOldRowid:0), 1, onError, addr, 0);
106203
+ assert( regOldRowid>0 );
106204
+ sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
106205
+ regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace);
104998106206
104999106207
/* Do FK constraint checks. */
105000106208
if( hasFK ){
105001
- sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngRowid);
106209
+ sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
105002106210
}
105003106211
105004106212
/* Delete the index entries associated with the current record. */
105005
- j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regOldRowid);
105006
- sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
106213
+ if( bReplace || chngKey ){
106214
+ if( pPk ){
106215
+ j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106216
+ }else{
106217
+ j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106218
+ }
106219
+ }
106220
+ sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
105007106221
105008106222
/* If changing the record number, delete the old record. */
105009
- if( hasFK || chngRowid ){
105010
- sqlite3VdbeAddOp2(v, OP_Delete, iCur, 0);
106223
+ if( hasFK || chngKey || pPk!=0 ){
106224
+ sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
105011106225
}
105012
- sqlite3VdbeJumpHere(v, j1);
106226
+ if( bReplace || chngKey ){
106227
+ if( sqlite3VdbeCurrentAddr(v)==j1+1 ){
106228
+ sqlite3VdbeChangeToNoop(v, j1);
106229
+ }else{
106230
+ sqlite3VdbeJumpHere(v, j1);
106231
+ }
106232
+ }
105013106233
105014106234
if( hasFK ){
105015
- sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngRowid);
106235
+ sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
105016106236
}
105017106237
105018106238
/* Insert the new index entries and the new record. */
105019
- sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
106239
+ sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
106240
+ regNewRowid, aRegIdx, 1, 0, 0);
105020106241
105021106242
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
105022106243
** handle rows (possibly in other tables) that refer via a foreign key
105023106244
** to the row just updated. */
105024106245
if( hasFK ){
105025
- sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngRowid);
106246
+ sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngKey);
105026106247
}
105027106248
}
105028106249
105029106250
/* Increment the row counter
105030106251
*/
@@ -105031,26 +106252,33 @@
105031106252
if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
105032106253
sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1);
105033106254
}
105034106255
105035106256
sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
105036
- TRIGGER_AFTER, pTab, regOldRowid, onError, addr);
106257
+ TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue);
105037106258
105038106259
/* Repeat the above with the next record to be updated, until
105039106260
** all record selected by the WHERE clause have been updated.
105040106261
*/
105041
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
105042
- sqlite3VdbeJumpHere(v, addr);
106262
+ if( okOnePass ){
106263
+ /* Nothing to do at end-of-loop for a single-pass */
106264
+ }else if( pPk ){
106265
+ sqlite3VdbeResolveLabel(v, labelContinue);
106266
+ sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop);
106267
+ }else{
106268
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106269
+ }
106270
+ sqlite3VdbeResolveLabel(v, labelBreak);
105043106271
105044106272
/* Close all tables */
105045106273
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
105046106274
assert( aRegIdx );
105047106275
if( openAll || aRegIdx[i]>0 ){
105048
- sqlite3VdbeAddOp2(v, OP_Close, iCur+i+1, 0);
106276
+ sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
105049106277
}
105050106278
}
105051
- sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
106279
+ if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
105052106280
105053106281
/* Update the sqlite_sequence table by storing the content of the
105054106282
** maximum rowid counter values recorded while inserting into
105055106283
** autoincrement tables.
105056106284
*/
@@ -105418,11 +106646,11 @@
105418106646
** in the temporary database.
105419106647
*/
105420106648
rc = execExecSql(db, pzErrMsg,
105421106649
"SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
105422106650
" FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
105423
- " AND rootpage>0"
106651
+ " AND coalesce(rootpage,1)>0"
105424106652
);
105425106653
if( rc!=SQLITE_OK ) goto end_of_vacuum;
105426106654
rc = execExecSql(db, pzErrMsg,
105427106655
"SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
105428106656
" FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
@@ -105439,11 +106667,11 @@
105439106667
rc = execExecSql(db, pzErrMsg,
105440106668
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
105441106669
"|| ' SELECT * FROM main.' || quote(name) || ';'"
105442106670
"FROM main.sqlite_master "
105443106671
"WHERE type = 'table' AND name!='sqlite_sequence' "
105444
- " AND rootpage>0"
106672
+ " AND coalesce(rootpage,1)>0"
105445106673
);
105446106674
if( rc!=SQLITE_OK ) goto end_of_vacuum;
105447106675
105448106676
/* Copy over the sequence table
105449106677
*/
@@ -107062,10 +108290,11 @@
107062108290
u8 nLevel; /* Number of nested loop */
107063108291
int iTop; /* The very beginning of the WHERE loop */
107064108292
int iContinue; /* Jump here to continue with next record */
107065108293
int iBreak; /* Jump here to break out of the loop */
107066108294
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
108295
+ int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
107067108296
WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
107068108297
WhereClause sWC; /* Decomposition of the WHERE clause */
107069108298
WhereLevel a[1]; /* Information about each nest loop in WHERE */
107070108299
};
107071108300
@@ -107154,12 +108383,23 @@
107154108383
107155108384
/*
107156108385
** Return TRUE if an UPDATE or DELETE statement can operate directly on
107157108386
** the rowids returned by a WHERE clause. Return FALSE if doing an
107158108387
** UPDATE or DELETE might change subsequent WHERE clause results.
108388
+**
108389
+** If the ONEPASS optimization is used (if this routine returns true)
108390
+** then also write the indices of open cursors used by ONEPASS
108391
+** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data
108392
+** table and iaCur[1] gets the cursor used by an auxiliary index.
108393
+** Either value may be -1, indicating that cursor is not used.
108394
+** Any cursors returned will have been opened for writing.
108395
+**
108396
+** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
108397
+** unable to use the ONEPASS optimization.
107159108398
*/
107160
-SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo){
108399
+SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo, int *aiCur){
108400
+ memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);
107161108401
return pWInfo->okOnePass;
107162108402
}
107163108403
107164108404
/*
107165108405
** Move the content of pSrc into pDest
@@ -107531,11 +108771,14 @@
107531108771
while( pScan->iEquiv<=pScan->nEquiv ){
107532108772
iCur = pScan->aEquiv[pScan->iEquiv-2];
107533108773
iColumn = pScan->aEquiv[pScan->iEquiv-1];
107534108774
while( (pWC = pScan->pWC)!=0 ){
107535108775
for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
107536
- if( pTerm->leftCursor==iCur && pTerm->u.leftColumn==iColumn ){
108776
+ if( pTerm->leftCursor==iCur
108777
+ && pTerm->u.leftColumn==iColumn
108778
+ && (pScan->iEquiv<=2 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
108779
+ ){
107537108780
if( (pTerm->eOperator & WO_EQUIV)!=0
107538108781
&& pScan->nEquiv<ArraySize(pScan->aEquiv)
107539108782
){
107540108783
int j;
107541108784
pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
@@ -107621,11 +108864,11 @@
107621108864
pScan->pOrigWC = pWC;
107622108865
pScan->pWC = pWC;
107623108866
if( pIdx && iColumn>=0 ){
107624108867
pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
107625108868
for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
107626
- if( NEVER(j>=pIdx->nColumn) ) return 0;
108869
+ if( NEVER(j>=pIdx->nKeyCol) ) return 0;
107627108870
}
107628108871
pScan->zCollName = pIdx->azColl[j];
107629108872
}else{
107630108873
pScan->idxaff = 0;
107631108874
pScan->zCollName = 0;
@@ -108551,20 +109794,20 @@
108551109794
** 3. All of those index columns for which the WHERE clause does not
108552109795
** contain a "col=X" term are subject to a NOT NULL constraint.
108553109796
*/
108554109797
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
108555109798
if( pIdx->onError==OE_None ) continue;
108556
- for(i=0; i<pIdx->nColumn; i++){
108557
- int iCol = pIdx->aiColumn[i];
109799
+ for(i=0; i<pIdx->nKeyCol; i++){
109800
+ i16 iCol = pIdx->aiColumn[i];
108558109801
if( 0==findTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
108559109802
int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i);
108560
- if( iIdxCol<0 || pTab->aCol[pIdx->aiColumn[i]].notNull==0 ){
109803
+ if( iIdxCol<0 || pTab->aCol[iCol].notNull==0 ){
108561109804
break;
108562109805
}
108563109806
}
108564109807
}
108565
- if( i==pIdx->nColumn ){
109808
+ if( i==pIdx->nKeyCol ){
108566109809
/* This index implies that the DISTINCT qualifier is redundant. */
108567109810
return 1;
108568109811
}
108569109812
}
108570109813
@@ -108658,26 +109901,25 @@
108658109901
WhereClause *pWC, /* The WHERE clause */
108659109902
struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
108660109903
Bitmask notReady, /* Mask of cursors that are not available */
108661109904
WhereLevel *pLevel /* Write new index here */
108662109905
){
108663
- int nColumn; /* Number of columns in the constructed index */
109906
+ int nKeyCol; /* Number of columns in the constructed index */
108664109907
WhereTerm *pTerm; /* A single term of the WHERE clause */
108665109908
WhereTerm *pWCEnd; /* End of pWC->a[] */
108666
- int nByte; /* Byte of memory needed for pIdx */
108667109909
Index *pIdx; /* Object describing the transient index */
108668109910
Vdbe *v; /* Prepared statement under construction */
108669109911
int addrInit; /* Address of the initialization bypass jump */
108670109912
Table *pTable; /* The table being indexed */
108671
- KeyInfo *pKeyinfo; /* Key information for the index */
108672109913
int addrTop; /* Top of the index fill loop */
108673109914
int regRecord; /* Register holding an index record */
108674109915
int n; /* Column counter */
108675109916
int i; /* Loop counter */
108676109917
int mxBitCol; /* Maximum column in pSrc->colUsed */
108677109918
CollSeq *pColl; /* Collating sequence to on a column */
108678109919
WhereLoop *pLoop; /* The Loop object */
109920
+ char *zNotUsed; /* Extra space on the end of pIdx */
108679109921
Bitmask idxCols; /* Bitmap of columns used for indexing */
108680109922
Bitmask extraCols; /* Bitmap of additional columns */
108681109923
u8 sentWarning = 0; /* True if a warnning has been issued */
108682109924
108683109925
/* Generate code to skip over the creation and initialization of the
@@ -108686,11 +109928,11 @@
108686109928
assert( v!=0 );
108687109929
addrInit = sqlite3CodeOnce(pParse);
108688109930
108689109931
/* Count the number of columns that will be added to the index
108690109932
** and used to match WHERE clause constraints */
108691
- nColumn = 0;
109933
+ nKeyCol = 0;
108692109934
pTable = pSrc->pTab;
108693109935
pWCEnd = &pWC->a[pWC->nTerm];
108694109936
pLoop = pLevel->pWLoop;
108695109937
idxCols = 0;
108696109938
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
@@ -108704,18 +109946,18 @@
108704109946
"automatic index on %s(%s)", pTable->zName,
108705109947
pTable->aCol[iCol].zName);
108706109948
sentWarning = 1;
108707109949
}
108708109950
if( (idxCols & cMask)==0 ){
108709
- if( whereLoopResize(pParse->db, pLoop, nColumn+1) ) return;
108710
- pLoop->aLTerm[nColumn++] = pTerm;
109951
+ if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
109952
+ pLoop->aLTerm[nKeyCol++] = pTerm;
108711109953
idxCols |= cMask;
108712109954
}
108713109955
}
108714109956
}
108715
- assert( nColumn>0 );
108716
- pLoop->u.btree.nEq = pLoop->nLTerm = nColumn;
109957
+ assert( nKeyCol>0 );
109958
+ pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;
108717109959
pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
108718109960
| WHERE_AUTO_INDEX;
108719109961
108720109962
/* Count the number of additional columns needed to create a
108721109963
** covering index. A "covering index" is an index that contains all
@@ -108728,30 +109970,22 @@
108728109970
extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
108729109971
mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
108730109972
testcase( pTable->nCol==BMS-1 );
108731109973
testcase( pTable->nCol==BMS-2 );
108732109974
for(i=0; i<mxBitCol; i++){
108733
- if( extraCols & MASKBIT(i) ) nColumn++;
109975
+ if( extraCols & MASKBIT(i) ) nKeyCol++;
108734109976
}
108735109977
if( pSrc->colUsed & MASKBIT(BMS-1) ){
108736
- nColumn += pTable->nCol - BMS + 1;
109978
+ nKeyCol += pTable->nCol - BMS + 1;
108737109979
}
108738109980
pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;
108739109981
108740109982
/* Construct the Index object to describe this index */
108741
- nByte = sizeof(Index);
108742
- nByte += nColumn*sizeof(int); /* Index.aiColumn */
108743
- nByte += nColumn*sizeof(char*); /* Index.azColl */
108744
- nByte += nColumn; /* Index.aSortOrder */
108745
- pIdx = sqlite3DbMallocZero(pParse->db, nByte);
109983
+ pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
108746109984
if( pIdx==0 ) return;
108747109985
pLoop->u.btree.pIndex = pIdx;
108748
- pIdx->azColl = (char**)&pIdx[1];
108749
- pIdx->aiColumn = (int*)&pIdx->azColl[nColumn];
108750
- pIdx->aSortOrder = (u8*)&pIdx->aiColumn[nColumn];
108751109986
pIdx->zName = "auto-index";
108752
- pIdx->nColumn = nColumn;
108753109987
pIdx->pTable = pTable;
108754109988
n = 0;
108755109989
idxCols = 0;
108756109990
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
108757109991
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -108785,24 +110019,25 @@
108785110019
pIdx->aiColumn[n] = i;
108786110020
pIdx->azColl[n] = "BINARY";
108787110021
n++;
108788110022
}
108789110023
}
108790
- assert( n==nColumn );
110024
+ assert( n==nKeyCol );
110025
+ pIdx->aiColumn[n] = -1;
110026
+ pIdx->azColl[n] = "BINARY";
108791110027
108792110028
/* Create the automatic index */
108793
- pKeyinfo = sqlite3IndexKeyinfo(pParse, pIdx);
108794110029
assert( pLevel->iIdxCur>=0 );
108795110030
pLevel->iIdxCur = pParse->nTab++;
108796
- sqlite3VdbeAddOp4(v, OP_OpenAutoindex, pLevel->iIdxCur, nColumn+1, 0,
108797
- (char*)pKeyinfo, P4_KEYINFO_HANDOFF);
110031
+ sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110032
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
108798110033
VdbeComment((v, "for %s", pTable->zName));
108799110034
108800110035
/* Fill the automatic index with content */
108801110036
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
108802110037
regRecord = sqlite3GetTempReg(pParse);
108803
- sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 1, 0);
110038
+ sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0);
108804110039
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
108805110040
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
108806110041
sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
108807110042
sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
108808110043
sqlite3VdbeJumpHere(v, addrTop);
@@ -109045,11 +110280,11 @@
109045110280
iUpper = aSample[0].anLt[iCol];
109046110281
}else{
109047110282
iUpper = i>=pIdx->nSample ? pIdx->aiRowEst[0] : aSample[i].anLt[iCol];
109048110283
iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol];
109049110284
}
109050
- aStat[1] = (pIdx->nColumn>iCol ? pIdx->aAvgEq[iCol] : 1);
110285
+ aStat[1] = (pIdx->nKeyCol>iCol ? pIdx->aAvgEq[iCol] : 1);
109051110286
if( iLower>=iUpper ){
109052110287
iGap = 0;
109053110288
}else{
109054110289
iGap = iUpper - iLower;
109055110290
}
@@ -109145,11 +110380,11 @@
109145110380
** of iUpper are requested of whereKeyStats() and the smaller used.
109146110381
*/
109147110382
tRowcnt iLower;
109148110383
tRowcnt iUpper;
109149110384
109150
- if( nEq==p->nColumn ){
110385
+ if( nEq==p->nKeyCol ){
109151110386
aff = SQLITE_AFF_INTEGER;
109152110387
}else{
109153110388
aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
109154110389
}
109155110390
/* Determine iLower and iUpper using ($P) only. */
@@ -109203,11 +110438,11 @@
109203110438
}
109204110439
if( nNew<nOut ){
109205110440
nOut = nNew;
109206110441
}
109207110442
pLoop->nOut = (LogEst)nOut;
109208
- WHERETRACE(0x100, ("range scan regions: %u..%u est=%d\n",
110443
+ WHERETRACE(0x10, ("range scan regions: %u..%u est=%d\n",
109209110444
(u32)iLower, (u32)iUpper, nOut));
109210110445
return SQLITE_OK;
109211110446
}
109212110447
}
109213110448
#else
@@ -109263,11 +110498,11 @@
109263110498
int rc; /* Subfunction return code */
109264110499
tRowcnt a[2]; /* Statistics */
109265110500
int bOk;
109266110501
109267110502
assert( nEq>=1 );
109268
- assert( nEq<=(p->nColumn+1) );
110503
+ assert( nEq<=(p->nKeyCol+1) );
109269110504
assert( p->aSample!=0 );
109270110505
assert( p->nSample>0 );
109271110506
assert( pBuilder->nRecValid<nEq );
109272110507
109273110508
/* If values are not available for all fields of the index to the left
@@ -109276,11 +110511,11 @@
109276110511
return SQLITE_NOTFOUND;
109277110512
}
109278110513
109279110514
/* This is an optimization only. The call to sqlite3Stat4ProbeSetValue()
109280110515
** below would return the same value. */
109281
- if( nEq>p->nColumn ){
110516
+ if( nEq>p->nKeyCol ){
109282110517
*pnRow = 1;
109283110518
return SQLITE_OK;
109284110519
}
109285110520
109286110521
aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity;
@@ -109289,11 +110524,11 @@
109289110524
if( rc!=SQLITE_OK ) return rc;
109290110525
if( bOk==0 ) return SQLITE_NOTFOUND;
109291110526
pBuilder->nRecValid = nEq;
109292110527
109293110528
whereKeyStats(pParse, p, pRec, 0, a);
109294
- WHERETRACE(0x100,("equality scan regions: %d\n", (int)a[1]));
110529
+ WHERETRACE(0x10,("equality scan regions: %d\n", (int)a[1]));
109295110530
*pnRow = a[1];
109296110531
109297110532
return rc;
109298110533
}
109299110534
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -109337,11 +110572,11 @@
109337110572
}
109338110573
109339110574
if( rc==SQLITE_OK ){
109340110575
if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
109341110576
*pnRow = nRowEst;
109342
- WHERETRACE(0x100,("IN row estimate: est=%g\n", nRowEst));
110577
+ WHERETRACE(0x10,("IN row estimate: est=%g\n", nRowEst));
109343110578
}
109344110579
assert( pBuilder->nRecValid==nRecValid );
109345110580
return rc;
109346110581
}
109347110582
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -109663,31 +110898,31 @@
109663110898
static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
109664110899
Index *pIndex = pLoop->u.btree.pIndex;
109665110900
int nEq = pLoop->u.btree.nEq;
109666110901
int i, j;
109667110902
Column *aCol = pTab->aCol;
109668
- int *aiColumn = pIndex->aiColumn;
110903
+ i16 *aiColumn = pIndex->aiColumn;
109669110904
StrAccum txt;
109670110905
109671110906
if( nEq==0 && (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ){
109672110907
return 0;
109673110908
}
109674110909
sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
109675110910
txt.db = db;
109676110911
sqlite3StrAccumAppend(&txt, " (", 2);
109677110912
for(i=0; i<nEq; i++){
109678
- char *z = (i==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[i]].zName;
110913
+ char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
109679110914
explainAppendTerm(&txt, i, z, "=");
109680110915
}
109681110916
109682110917
j = i;
109683110918
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
109684
- char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
110919
+ char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
109685110920
explainAppendTerm(&txt, i++, z, ">");
109686110921
}
109687110922
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
109688
- char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
110923
+ char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
109689110924
explainAppendTerm(&txt, i, z, "<");
109690110925
}
109691110926
sqlite3StrAccumAppend(&txt, ")", 1);
109692110927
return sqlite3StrAccumFinish(&txt);
109693110928
}
@@ -109810,11 +111045,11 @@
109810111045
iCur = pTabItem->iCursor;
109811111046
pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109812111047
bRev = (pWInfo->revMask>>iLevel)&1;
109813111048
omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
109814111049
&& (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
109815
- VdbeNoopComment((v, "Begin Join Loop %d", iLevel));
111050
+ VdbeNoopComment((v, "Begin WHERE-Loop %d: %s", iLevel,pTabItem->pTab->zName));
109816111051
109817111052
/* Create labels for the "break" and "continue" instructions
109818111053
** for the current loop. Jump to addrBrk to break out of a loop.
109819111054
** Jump to cont to go immediately to the next iteration of the
109820111055
** loop.
@@ -110067,11 +111302,11 @@
110067111302
** the first one after the nEq equality constraints in the index,
110068111303
** this requires some special handling.
110069111304
*/
110070111305
if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
110071111306
&& (pWInfo->bOBSat!=0)
110072
- && (pIdx->nColumn>nEq)
111307
+ && (pIdx->nKeyCol>nEq)
110073111308
){
110074111309
/* assert( pOrderBy->nExpr==1 ); */
110075111310
/* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
110076111311
isMinQuery = 1;
110077111312
nExtraReg = 1;
@@ -110100,12 +111335,12 @@
110100111335
110101111336
/* If we are doing a reverse order scan on an ascending index, or
110102111337
** a forward order scan on a descending index, interchange the
110103111338
** start and end terms (pRangeStart and pRangeEnd).
110104111339
*/
110105
- if( (nEq<pIdx->nColumn && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
110106
- || (bRev && pIdx->nColumn==nEq)
111340
+ if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111341
+ || (bRev && pIdx->nKeyCol==nEq)
110107111342
){
110108111343
SWAP(WhereTerm *, pRangeEnd, pRangeStart);
110109111344
}
110110111345
110111111346
testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
@@ -110210,15 +111445,26 @@
110210111445
sqlite3ReleaseTempReg(pParse, r1);
110211111446
110212111447
/* Seek the table cursor, if required */
110213111448
disableTerm(pLevel, pRangeStart);
110214111449
disableTerm(pLevel, pRangeEnd);
110215
- if( !omitTable ){
111450
+ if( omitTable ){
111451
+ /* pIdx is a covering index. No need to access the main table. */
111452
+ }else if( HasRowid(pIdx->pTable) ){
110216111453
iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
110217111454
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
110218111455
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
110219111456
sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
111457
+ }else{
111458
+ Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
111459
+ iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
111460
+ for(j=0; j<pPk->nKeyCol; j++){
111461
+ k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
111462
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
111463
+ }
111464
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
111465
+ iRowidReg, pPk->nKeyCol);
110220111466
}
110221111467
110222111468
/* Record the instruction used to terminate the loop. Disable
110223111469
** WHERE clause terms made redundant by the index range scan.
110224111470
*/
@@ -110541,27 +111787,43 @@
110541111787
}
110542111788
sqlite3ReleaseTempReg(pParse, iReleaseReg);
110543111789
110544111790
return pLevel->notReady;
110545111791
}
111792
+
111793
+#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
111794
+/*
111795
+** Generate "Explanation" text for a WhereTerm.
111796
+*/
111797
+static void whereExplainTerm(Vdbe *v, WhereTerm *pTerm){
111798
+ char zType[4];
111799
+ memcpy(zType, "...", 4);
111800
+ if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
111801
+ if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
111802
+ if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
111803
+ sqlite3ExplainPrintf(v, "%s ", zType);
111804
+ sqlite3ExplainExpr(v, pTerm->pExpr);
111805
+}
111806
+#endif /* WHERETRACE_ENABLED && SQLITE_ENABLE_TREE_EXPLAIN */
111807
+
110546111808
110547111809
#ifdef WHERETRACE_ENABLED
110548111810
/*
110549111811
** Print a WhereLoop object for debugging purposes
110550111812
*/
110551
-static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
110552
- int nb = 1+(pTabList->nSrc+7)/8;
110553
- struct SrcList_item *pItem = pTabList->a + p->iTab;
111813
+static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
111814
+ WhereInfo *pWInfo = pWC->pWInfo;
111815
+ int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
111816
+ struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
110554111817
Table *pTab = pItem->pTab;
110555111818
sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
110556111819
p->iTab, nb, p->maskSelf, nb, p->prereq);
110557111820
sqlite3DebugPrintf(" %12s",
110558111821
pItem->zAlias ? pItem->zAlias : pTab->zName);
110559111822
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
110560
- if( p->u.btree.pIndex ){
110561
- const char *zName = p->u.btree.pIndex->zName;
110562
- if( zName==0 ) zName = "ipk";
111823
+ const char *zName;
111824
+ if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
110563111825
if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
110564111826
int i = sqlite3Strlen30(zName) - 1;
110565111827
while( zName[i]!='_' ) i--;
110566111828
zName += i;
110567111829
}
@@ -110580,10 +111842,30 @@
110580111842
sqlite3DebugPrintf(" %-19s", z);
110581111843
sqlite3_free(z);
110582111844
}
110583111845
sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
110584111846
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
111847
+#ifdef SQLITE_ENABLE_TREE_EXPLAIN
111848
+ /* If the 0x100 bit of wheretracing is set, then show all of the constraint
111849
+ ** expressions in the WhereLoop.aLTerm[] array.
111850
+ */
111851
+ if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ /* WHERETRACE 0x100 */
111852
+ int i;
111853
+ Vdbe *v = pWInfo->pParse->pVdbe;
111854
+ sqlite3ExplainBegin(v);
111855
+ for(i=0; i<p->nLTerm; i++){
111856
+ WhereTerm *pTerm = p->aLTerm[i];
111857
+ sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111858
+ sqlite3ExplainPush(v);
111859
+ whereExplainTerm(v, pTerm);
111860
+ sqlite3ExplainPop(v);
111861
+ sqlite3ExplainNL(v);
111862
+ }
111863
+ sqlite3ExplainFinish(v);
111864
+ sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
111865
+ }
111866
+#endif
110585111867
}
110586111868
#endif
110587111869
110588111870
/*
110589111871
** Convert bulk memory into a valid WhereLoop that can be passed
@@ -110605,10 +111887,11 @@
110605111887
sqlite3_free(p->u.vtab.idxStr);
110606111888
p->u.vtab.needFree = 0;
110607111889
p->u.vtab.idxStr = 0;
110608111890
}else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
110609111891
sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
111892
+ sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo);
110610111893
sqlite3DbFree(db, p->u.btree.pIndex);
110611111894
p->u.btree.pIndex = 0;
110612111895
}
110613111896
}
110614111897
}
@@ -110719,14 +112002,14 @@
110719112002
u16 n = pBuilder->pOrSet->n;
110720112003
int x =
110721112004
#endif
110722112005
whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
110723112006
pTemplate->nOut);
110724
-#if WHERETRACE_ENABLED
112007
+#if WHERETRACE_ENABLED /* 0x8 */
110725112008
if( sqlite3WhereTrace & 0x8 ){
110726112009
sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
110727
- whereLoopPrint(pTemplate, pWInfo->pTabList);
112010
+ whereLoopPrint(pTemplate, pBuilder->pWC);
110728112011
}
110729112012
#endif
110730112013
return SQLITE_OK;
110731112014
}
110732112015
@@ -110792,18 +112075,18 @@
110792112075
110793112076
/* If we reach this point it means that either p[] should be overwritten
110794112077
** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
110795112078
** WhereLoop and insert it.
110796112079
*/
110797
-#if WHERETRACE_ENABLED
112080
+#if WHERETRACE_ENABLED /* 0x8 */
110798112081
if( sqlite3WhereTrace & 0x8 ){
110799112082
if( p!=0 ){
110800112083
sqlite3DebugPrintf("ins-del: ");
110801
- whereLoopPrint(p, pWInfo->pTabList);
112084
+ whereLoopPrint(p, pBuilder->pWC);
110802112085
}
110803112086
sqlite3DebugPrintf("ins-new: ");
110804
- whereLoopPrint(pTemplate, pWInfo->pTabList);
112087
+ whereLoopPrint(pTemplate, pBuilder->pWC);
110805112088
}
110806112089
#endif
110807112090
if( p==0 ){
110808112091
p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
110809112092
if( p==0 ) return SQLITE_NOMEM;
@@ -110820,14 +112103,14 @@
110820112103
}
110821112104
return SQLITE_OK;
110822112105
110823112106
/* Jump here if the insert is a no-op */
110824112107
whereLoopInsert_noop:
110825
-#if WHERETRACE_ENABLED
112108
+#if WHERETRACE_ENABLED /* 0x8 */
110826112109
if( sqlite3WhereTrace & 0x8 ){
110827112110
sqlite3DebugPrintf("ins-noop: ");
110828
- whereLoopPrint(pTemplate, pWInfo->pTabList);
112111
+ whereLoopPrint(pTemplate, pBuilder->pWC);
110829112112
}
110830112113
#endif
110831112114
return SQLITE_OK;
110832112115
}
110833112116
@@ -110904,12 +112187,12 @@
110904112187
}else{
110905112188
opMask = WO_EQ|WO_IN|WO_ISNULL|WO_GT|WO_GE|WO_LT|WO_LE;
110906112189
}
110907112190
if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
110908112191
110909
- assert( pNew->u.btree.nEq<=pProbe->nColumn );
110910
- if( pNew->u.btree.nEq < pProbe->nColumn ){
112192
+ assert( pNew->u.btree.nEq<=pProbe->nKeyCol );
112193
+ if( pNew->u.btree.nEq < pProbe->nKeyCol ){
110911112194
iCol = pProbe->aiColumn[pNew->u.btree.nEq];
110912112195
nRowEst = sqlite3LogEst(pProbe->aiRowEst[pNew->u.btree.nEq+1]);
110913112196
if( nRowEst==0 && pProbe->onError==OE_None ) nRowEst = 1;
110914112197
}else{
110915112198
iCol = -1;
@@ -110962,11 +112245,11 @@
110962112245
assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
110963112246
|| nInMul==0 );
110964112247
pNew->wsFlags |= WHERE_COLUMN_EQ;
110965112248
if( iCol<0
110966112249
|| (pProbe->onError!=OE_None && nInMul==0
110967
- && pNew->u.btree.nEq==pProbe->nColumn-1)
112250
+ && pNew->u.btree.nEq==pProbe->nKeyCol-1)
110968112251
){
110969112252
assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
110970112253
pNew->wsFlags |= WHERE_ONEROW;
110971112254
}
110972112255
pNew->u.btree.nEq++;
@@ -111028,11 +112311,11 @@
111028112311
/* Step cost for each output row */
111029112312
pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut);
111030112313
whereLoopOutputAdjust(pBuilder->pWC, pNew);
111031112314
rc = whereLoopInsert(pBuilder, pNew);
111032112315
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
111033
- && pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0))
112316
+ && pNew->u.btree.nEq<(pProbe->nKeyCol + (pProbe->zName!=0))
111034112317
){
111035112318
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
111036112319
}
111037112320
pNew->nOut = saved_nOut;
111038112321
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -111067,11 +112350,11 @@
111067112350
if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
111068112351
for(ii=0; ii<pOB->nExpr; ii++){
111069112352
Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr);
111070112353
if( pExpr->op!=TK_COLUMN ) return 0;
111071112354
if( pExpr->iTable==iCursor ){
111072
- for(jj=0; jj<pIndex->nColumn; jj++){
112355
+ for(jj=0; jj<pIndex->nKeyCol; jj++){
111073112356
if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
111074112357
}
111075112358
}
111076112359
}
111077112360
return 0;
@@ -111084,14 +112367,15 @@
111084112367
static Bitmask columnsInIndex(Index *pIdx){
111085112368
Bitmask m = 0;
111086112369
int j;
111087112370
for(j=pIdx->nColumn-1; j>=0; j--){
111088112371
int x = pIdx->aiColumn[j];
111089
- assert( x>=0 );
111090
- testcase( x==BMS-1 );
111091
- testcase( x==BMS-2 );
111092
- if( x<BMS-1 ) m |= MASKBIT(x);
112372
+ if( x>=0 ){
112373
+ testcase( x==BMS-1 );
112374
+ testcase( x==BMS-2 );
112375
+ if( x<BMS-1 ) m |= MASKBIT(x);
112376
+ }
111093112377
}
111094112378
return m;
111095112379
}
111096112380
111097112381
/* Check to see if a partial index with pPartIndexWhere can be used
@@ -111117,11 +112401,11 @@
111117112401
){
111118112402
WhereInfo *pWInfo; /* WHERE analysis context */
111119112403
Index *pProbe; /* An index we are evaluating */
111120112404
Index sPk; /* A fake index object for the primary key */
111121112405
tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
111122
- int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
112406
+ i16 aiColumnPk = -1; /* The aColumn[] value for the sPk index */
111123112407
SrcList *pTabList; /* The FROM clause */
111124112408
struct SrcList_item *pSrc; /* The FROM clause btree term to add */
111125112409
WhereLoop *pNew; /* Template WhereLoop object */
111126112410
int rc = SQLITE_OK; /* Return code */
111127112411
int iSortIdx = 1; /* Index number */
@@ -111140,18 +112424,20 @@
111140112424
assert( !IsVirtual(pSrc->pTab) );
111141112425
111142112426
if( pSrc->pIndex ){
111143112427
/* An INDEXED BY clause specifies a particular index to use */
111144112428
pProbe = pSrc->pIndex;
112429
+ }else if( !HasRowid(pTab) ){
112430
+ pProbe = pTab->pIndex;
111145112431
}else{
111146112432
/* There is no INDEXED BY clause. Create a fake Index object in local
111147112433
** variable sPk to represent the rowid primary key index. Make this
111148112434
** fake index the first in a chain of Index objects with all of the real
111149112435
** indices to follow */
111150112436
Index *pFirst; /* First of real indices on the table */
111151112437
memset(&sPk, 0, sizeof(Index));
111152
- sPk.nColumn = 1;
112438
+ sPk.nKeyCol = 1;
111153112439
sPk.aiColumn = &aiColumnPk;
111154112440
sPk.aiRowEst = aiRowEstPk;
111155112441
sPk.onError = OE_Replace;
111156112442
sPk.pTable = pTab;
111157112443
aiRowEstPk[0] = pTab->nRowEst;
@@ -111172,10 +112458,11 @@
111172112458
if( !pBuilder->pOrSet
111173112459
&& (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
111174112460
&& pSrc->pIndex==0
111175112461
&& !pSrc->viaCoroutine
111176112462
&& !pSrc->notIndexed
112463
+ && HasRowid(pTab)
111177112464
&& !pSrc->isCorrelated
111178112465
){
111179112466
/* Generate auto-index WhereLoops */
111180112467
WhereTerm *pTerm;
111181112468
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
@@ -111234,18 +112521,25 @@
111234112521
whereLoopOutputAdjust(pWC, pNew);
111235112522
rc = whereLoopInsert(pBuilder, pNew);
111236112523
pNew->nOut = rSize;
111237112524
if( rc ) break;
111238112525
}else{
111239
- Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe);
111240
- pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
112526
+ Bitmask m;
112527
+ if( pProbe->isCovering ){
112528
+ pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
112529
+ m = 0;
112530
+ }else{
112531
+ m = pSrc->colUsed & ~columnsInIndex(pProbe);
112532
+ pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
112533
+ }
111241112534
111242112535
/* Full scan via index */
111243112536
if( b
112537
+ || !HasRowid(pTab)
111244112538
|| ( m==0
111245112539
&& pProbe->bUnordered==0
111246
- && pProbe->szIdxRow<pTab->szTabRow
112540
+ && (pProbe->szIdxRow<pTab->szTabRow)
111247112541
&& (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
111248112542
&& sqlite3GlobalConfig.bUseCis
111249112543
&& OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan)
111250112544
)
111251112545
){
@@ -111257,11 +112551,10 @@
111257112551
** is smaller for smaller indices, thus favoring them.
111258112552
*/
111259112553
pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 1 +
111260112554
(15*pProbe->szIdxRow)/pTab->szTabRow;
111261112555
}else{
111262
- assert( b!=0 );
111263112556
/* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N)
111264112557
** which we will simplify to just N*log2(N) */
111265112558
pNew->rRun = rSize + rLogSize;
111266112559
}
111267112560
whereLoopOutputAdjust(pWC, pNew);
@@ -111473,10 +112766,11 @@
111473112766
if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
111474112767
pWCEnd = pWC->a + pWC->nTerm;
111475112768
pNew = pBuilder->pNew;
111476112769
memset(&sSum, 0, sizeof(sSum));
111477112770
pItem = pWInfo->pTabList->a + pNew->iTab;
112771
+ if( !HasRowid(pItem->pTab) ) return SQLITE_OK;
111478112772
iCur = pItem->iCursor;
111479112773
111480112774
for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
111481112775
if( (pTerm->eOperator & WO_OR)!=0
111482112776
&& (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
@@ -111622,11 +112916,12 @@
111622112916
u8 rev; /* Composite sort order */
111623112917
u8 revIdx; /* Index sort order */
111624112918
u8 isOrderDistinct; /* All prior WhereLoops are order-distinct */
111625112919
u8 distinctColumns; /* True if the loop has UNIQUE NOT NULL columns */
111626112920
u8 isMatch; /* iColumn matches a term of the ORDER BY clause */
111627
- u16 nColumn; /* Number of columns in pIndex */
112921
+ u16 nKeyCol; /* Number of key columns in pIndex */
112922
+ u16 nColumn; /* Total number of ordered columns in the index */
111628112923
u16 nOrderBy; /* Number terms in the ORDER BY clause */
111629112924
int iLoop; /* Index of WhereLoop in pPath being processed */
111630112925
int i, j; /* Loop counters */
111631112926
int iCur; /* Cursor number for current WhereLoop */
111632112927
int iColumn; /* A column number within table iCur */
@@ -111714,24 +113009,28 @@
111714113009
}
111715113010
111716113011
if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
111717113012
if( pLoop->wsFlags & WHERE_IPK ){
111718113013
pIndex = 0;
111719
- nColumn = 0;
113014
+ nKeyCol = 0;
113015
+ nColumn = 1;
111720113016
}else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
111721113017
return 0;
111722113018
}else{
113019
+ nKeyCol = pIndex->nKeyCol;
111723113020
nColumn = pIndex->nColumn;
113021
+ assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
113022
+ assert( pIndex->aiColumn[nColumn-1]==(-1) || !HasRowid(pIndex->pTable));
111724113023
isOrderDistinct = pIndex->onError!=OE_None;
111725113024
}
111726113025
111727113026
/* Loop through all columns of the index and deal with the ones
111728113027
** that are not constrained by == or IN.
111729113028
*/
111730113029
rev = revSet = 0;
111731113030
distinctColumns = 0;
111732
- for(j=0; j<=nColumn; j++){
113031
+ for(j=0; j<nColumn; j++){
111733113032
u8 bOnce; /* True to run the ORDER BY search loop */
111734113033
111735113034
/* Skip over == and IS NULL terms */
111736113035
if( j<pLoop->u.btree.nEq
111737113036
&& ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
@@ -111744,24 +113043,21 @@
111744113043
}
111745113044
111746113045
/* Get the column number in the table (iColumn) and sort order
111747113046
** (revIdx) for the j-th column of the index.
111748113047
*/
111749
- if( j<nColumn ){
111750
- /* Normal index columns */
113048
+ if( pIndex ){
111751113049
iColumn = pIndex->aiColumn[j];
111752113050
revIdx = pIndex->aSortOrder[j];
111753113051
if( iColumn==pIndex->pTable->iPKey ) iColumn = -1;
111754113052
}else{
111755
- /* The ROWID column at the end */
111756
- assert( j==nColumn );
111757113053
iColumn = -1;
111758113054
revIdx = 0;
111759113055
}
111760113056
111761113057
/* An unconstrained column that might be NULL means that this
111762
- ** WhereLoop is not well-ordered
113058
+ ** WhereLoop is not well-ordered
111763113059
*/
111764113060
if( isOrderDistinct
111765113061
&& iColumn>=0
111766113062
&& j>=pLoop->u.btree.nEq
111767113063
&& pIndex->pTable->aCol[iColumn].notNull==0
@@ -111808,11 +113104,11 @@
111808113104
revSet = 1;
111809113105
}
111810113106
}
111811113107
}else{
111812113108
/* No match found */
111813
- if( j==0 || j<nColumn ){
113109
+ if( j==0 || j<nKeyCol ){
111814113110
testcase( isOrderDistinct!=0 );
111815113111
isOrderDistinct = 0;
111816113112
}
111817113113
break;
111818113114
}
@@ -111981,11 +113277,11 @@
111981113277
break;
111982113278
}
111983113279
}
111984113280
if( jj>=nTo ){
111985113281
if( nTo>=mxChoice && rCost>=mxCost ){
111986
-#ifdef WHERETRACE_ENABLED
113282
+#ifdef WHERETRACE_ENABLED /* 0x4 */
111987113283
if( sqlite3WhereTrace&0x4 ){
111988113284
sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
111989113285
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111990113286
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111991113287
}
@@ -111999,20 +113295,20 @@
111999113295
}else{
112000113296
/* New path replaces the prior worst to keep count below mxChoice */
112001113297
jj = mxI;
112002113298
}
112003113299
pTo = &aTo[jj];
112004
-#ifdef WHERETRACE_ENABLED
113300
+#ifdef WHERETRACE_ENABLED /* 0x4 */
112005113301
if( sqlite3WhereTrace&0x4 ){
112006113302
sqlite3DebugPrintf("New %s cost=%-3d,%3d order=%c\n",
112007113303
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
112008113304
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
112009113305
}
112010113306
#endif
112011113307
}else{
112012113308
if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
112013
-#ifdef WHERETRACE_ENABLED
113309
+#ifdef WHERETRACE_ENABLED /* 0x4 */
112014113310
if( sqlite3WhereTrace&0x4 ){
112015113311
sqlite3DebugPrintf(
112016113312
"Skip %s cost=%-3d,%3d order=%c",
112017113313
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
112018113314
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -112024,11 +113320,11 @@
112024113320
testcase( pTo->rCost==rCost );
112025113321
continue;
112026113322
}
112027113323
testcase( pTo->rCost==rCost+1 );
112028113324
/* A new and better score for a previously created equivalent path */
112029
-#ifdef WHERETRACE_ENABLED
113325
+#ifdef WHERETRACE_ENABLED /* 0x4 */
112030113326
if( sqlite3WhereTrace&0x4 ){
112031113327
sqlite3DebugPrintf(
112032113328
"Update %s cost=%-3d,%3d order=%c",
112033113329
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
112034113330
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -112060,11 +113356,11 @@
112060113356
}
112061113357
}
112062113358
}
112063113359
}
112064113360
112065
-#ifdef WHERETRACE_ENABLED
113361
+#ifdef WHERETRACE_ENABLED /* >=2 */
112066113362
if( sqlite3WhereTrace>=2 ){
112067113363
sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
112068113364
for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
112069113365
sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
112070113366
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
@@ -112174,20 +113470,20 @@
112174113470
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
112175113471
assert( pLoop->aLTermSpace==pLoop->aLTerm );
112176113472
assert( ArraySize(pLoop->aLTermSpace)==4 );
112177113473
if( pIdx->onError==OE_None
112178113474
|| pIdx->pPartIdxWhere!=0
112179
- || pIdx->nColumn>ArraySize(pLoop->aLTermSpace)
113475
+ || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
112180113476
) continue;
112181
- for(j=0; j<pIdx->nColumn; j++){
113477
+ for(j=0; j<pIdx->nKeyCol; j++){
112182113478
pTerm = findTerm(pWC, iCur, pIdx->aiColumn[j], 0, WO_EQ, pIdx);
112183113479
if( pTerm==0 ) break;
112184113480
pLoop->aLTerm[j] = pTerm;
112185113481
}
112186
- if( j!=pIdx->nColumn ) continue;
113482
+ if( j!=pIdx->nKeyCol ) continue;
112187113483
pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW|WHERE_INDEXED;
112188
- if( (pItem->colUsed & ~columnsInIndex(pIdx))==0 ){
113484
+ if( pIdx->isCovering || (pItem->colUsed & ~columnsInIndex(pIdx))==0 ){
112189113485
pLoop->wsFlags |= WHERE_IDX_ONLY;
112190113486
}
112191113487
pLoop->nLTerm = j;
112192113488
pLoop->u.btree.nEq = j;
112193113489
pLoop->u.btree.pIndex = pIdx;
@@ -112291,10 +113587,18 @@
112291113587
**
112292113588
** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
112293113589
** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
112294113590
** if there is one. If there is no ORDER BY clause or if this routine
112295113591
** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
113592
+**
113593
+** The iIdxCur parameter is the cursor number of an index. If
113594
+** WHERE_ONETABLE_ONLY is set, iIdxCur is the cursor number of an index
113595
+** to use for OR clause processing. The WHERE clause should use this
113596
+** specific cursor. If WHERE_ONEPASS_DESIRED is set, then iIdxCur is
113597
+** the first cursor in an array of cursors for all indices. iIdxCur should
113598
+** be used to compute the appropriate cursor depending on which index is
113599
+** used.
112296113600
*/
112297113601
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
112298113602
Parse *pParse, /* The parser context */
112299113603
SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
112300113604
Expr *pWhere, /* The WHERE clause */
@@ -112356,10 +113660,11 @@
112356113660
if( db->mallocFailed ){
112357113661
sqlite3DbFree(db, pWInfo);
112358113662
pWInfo = 0;
112359113663
goto whereBeginError;
112360113664
}
113665
+ pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
112361113666
pWInfo->nLevel = nTabList;
112362113667
pWInfo->pParse = pParse;
112363113668
pWInfo->pTabList = pTabList;
112364113669
pWInfo->pOrderBy = pOrderBy;
112365113670
pWInfo->pResultSet = pResultSet;
@@ -112469,24 +113774,41 @@
112469113774
}
112470113775
}
112471113776
112472113777
/* Construct the WhereLoop objects */
112473113778
WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
113779
+ /* Display all terms of the WHERE clause */
113780
+#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
113781
+ if( sqlite3WhereTrace & 0x100 ){
113782
+ int i;
113783
+ Vdbe *v = pParse->pVdbe;
113784
+ sqlite3ExplainBegin(v);
113785
+ for(i=0; i<sWLB.pWC->nTerm; i++){
113786
+ sqlite3ExplainPrintf(v, "#%-2d ", i);
113787
+ sqlite3ExplainPush(v);
113788
+ whereExplainTerm(v, &sWLB.pWC->a[i]);
113789
+ sqlite3ExplainPop(v);
113790
+ sqlite3ExplainNL(v);
113791
+ }
113792
+ sqlite3ExplainFinish(v);
113793
+ sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
113794
+ }
113795
+#endif
112474113796
if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
112475113797
rc = whereLoopAddAll(&sWLB);
112476113798
if( rc ) goto whereBeginError;
112477113799
112478113800
/* Display all of the WhereLoop objects if wheretrace is enabled */
112479
-#ifdef WHERETRACE_ENABLED
113801
+#ifdef WHERETRACE_ENABLED /* !=0 */
112480113802
if( sqlite3WhereTrace ){
112481113803
WhereLoop *p;
112482113804
int i;
112483113805
static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
112484113806
"ABCDEFGHIJKLMNOPQRSTUVWYXZ";
112485113807
for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
112486113808
p->cId = zLabel[i%sizeof(zLabel)];
112487
- whereLoopPrint(p, pTabList);
113809
+ whereLoopPrint(p, sWLB.pWC);
112488113810
}
112489113811
}
112490113812
#endif
112491113813
112492113814
wherePathSolver(pWInfo, 0);
@@ -112500,11 +113822,11 @@
112500113822
pWInfo->revMask = (Bitmask)(-1);
112501113823
}
112502113824
if( pParse->nErr || NEVER(db->mallocFailed) ){
112503113825
goto whereBeginError;
112504113826
}
112505
-#ifdef WHERETRACE_ENABLED
113827
+#ifdef WHERETRACE_ENABLED /* !=0 */
112506113828
if( sqlite3WhereTrace ){
112507113829
int ii;
112508113830
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
112509113831
if( pWInfo->bOBSat ){
112510113832
sqlite3DebugPrintf(" ORDERBY=0x%llx", pWInfo->revMask);
@@ -112523,11 +113845,11 @@
112523113845
break;
112524113846
}
112525113847
}
112526113848
sqlite3DebugPrintf("\n");
112527113849
for(ii=0; ii<pWInfo->nLevel; ii++){
112528
- whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
113850
+ whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
112529113851
}
112530113852
}
112531113853
#endif
112532113854
/* Attempt to omit tables from the join that do not effect the result */
112533113855
if( pWInfo->nLevel>=2
@@ -112570,11 +113892,13 @@
112570113892
*/
112571113893
assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
112572113894
if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
112573113895
&& (pWInfo->a[0].pWLoop->wsFlags & WHERE_ONEROW)!=0 ){
112574113896
pWInfo->okOnePass = 1;
112575
- pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY;
113897
+ if( HasRowid(pTabList->a[0].pTab) ){
113898
+ pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY;
113899
+ }
112576113900
}
112577113901
112578113902
/* Open all tables in the pTabList and any indices selected for
112579113903
** searching those tables.
112580113904
*/
@@ -112600,15 +113924,20 @@
112600113924
/* noop */
112601113925
}else
112602113926
#endif
112603113927
if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
112604113928
&& (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){
112605
- int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
113929
+ int op = OP_OpenRead;
113930
+ if( pWInfo->okOnePass ){
113931
+ op = OP_OpenWrite;
113932
+ pWInfo->aiCurOnePass[0] = pTabItem->iCursor;
113933
+ };
112606113934
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
113935
+ assert( pTabItem->iCursor==pLevel->iTabCur );
112607113936
testcase( !pWInfo->okOnePass && pTab->nCol==BMS-1 );
112608113937
testcase( !pWInfo->okOnePass && pTab->nCol==BMS );
112609
- if( !pWInfo->okOnePass && pTab->nCol<BMS ){
113938
+ if( !pWInfo->okOnePass && pTab->nCol<BMS && HasRowid(pTab) ){
112610113939
Bitmask b = pTabItem->colUsed;
112611113940
int n = 0;
112612113941
for(; b; b=b>>1, n++){}
112613113942
sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1,
112614113943
SQLITE_INT_TO_PTR(n), P4_INT32);
@@ -112617,17 +113946,34 @@
112617113946
}else{
112618113947
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
112619113948
}
112620113949
if( pLoop->wsFlags & WHERE_INDEXED ){
112621113950
Index *pIx = pLoop->u.btree.pIndex;
112622
- KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
112623
- /* FIXME: As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */
112624
- int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++;
113951
+ int iIndexCur;
113952
+ int op = OP_OpenRead;
113953
+ /* iIdxCur is always set if to a positive value if ONEPASS is possible */
113954
+ assert( iIdxCur!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
113955
+ if( pWInfo->okOnePass ){
113956
+ Index *pJ = pTabItem->pTab->pIndex;
113957
+ iIndexCur = iIdxCur;
113958
+ assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
113959
+ while( ALWAYS(pJ) && pJ!=pIx ){
113960
+ iIndexCur++;
113961
+ pJ = pJ->pNext;
113962
+ }
113963
+ op = OP_OpenWrite;
113964
+ pWInfo->aiCurOnePass[1] = iIndexCur;
113965
+ }else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){
113966
+ iIndexCur = iIdxCur;
113967
+ }else{
113968
+ iIndexCur = pParse->nTab++;
113969
+ }
113970
+ pLevel->iIdxCur = iIndexCur;
112625113971
assert( pIx->pSchema==pTab->pSchema );
112626113972
assert( iIndexCur>=0 );
112627
- sqlite3VdbeAddOp4(v, OP_OpenRead, iIndexCur, pIx->tnum, iDb,
112628
- (char*)pKey, P4_KEYINFO_HANDOFF);
113973
+ sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
113974
+ sqlite3VdbeSetP4KeyInfo(pParse, pIx);
112629113975
VdbeComment((v, "%s", pIx->zName));
112630113976
}
112631113977
sqlite3CodeVerifySchema(pParse, iDb);
112632113978
notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
112633113979
}
@@ -112718,35 +114064,44 @@
112718114064
}else{
112719114065
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
112720114066
}
112721114067
sqlite3VdbeJumpHere(v, addr);
112722114068
}
114069
+ VdbeNoopComment((v, "End WHERE-Loop %d: %s", i,
114070
+ pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
112723114071
}
112724114072
112725114073
/* The "break" point is here, just past the end of the outer loop.
112726114074
** Set it.
112727114075
*/
112728114076
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
112729114077
112730
- /* Close all of the cursors that were opened by sqlite3WhereBegin.
112731
- */
112732114078
assert( pWInfo->nLevel<=pTabList->nSrc );
112733114079
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
112734114080
Index *pIdx = 0;
112735114081
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
112736114082
Table *pTab = pTabItem->pTab;
112737114083
assert( pTab!=0 );
112738114084
pLoop = pLevel->pWLoop;
114085
+
114086
+ /* Close all of the cursors that were opened by sqlite3WhereBegin.
114087
+ ** Except, do not close cursors that will be reused by the OR optimization
114088
+ ** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114089
+ ** created for the ONEPASS optimization.
114090
+ */
112739114091
if( (pTab->tabFlags & TF_Ephemeral)==0
112740114092
&& pTab->pSelect==0
112741114093
&& (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
112742114094
){
112743114095
int ws = pLoop->wsFlags;
112744114096
if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
112745114097
sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
112746114098
}
112747
- if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 ){
114099
+ if( (ws & WHERE_INDEXED)!=0
114100
+ && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0
114101
+ && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
114102
+ ){
112748114103
sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
112749114104
}
112750114105
}
112751114106
112752114107
/* If this scan uses an index, make VDBE code substitutions to read data
@@ -112764,27 +114119,31 @@
112764114119
pIdx = pLoop->u.btree.pIndex;
112765114120
}else if( pLoop->wsFlags & WHERE_MULTI_OR ){
112766114121
pIdx = pLevel->u.pCovidx;
112767114122
}
112768114123
if( pIdx && !db->mallocFailed ){
112769
- int k, j, last;
114124
+ int k, last;
112770114125
VdbeOp *pOp;
112771114126
112772114127
last = sqlite3VdbeCurrentAddr(v);
112773114128
k = pLevel->addrBody;
112774114129
pOp = sqlite3VdbeGetOp(v, k);
112775114130
for(; k<last; k++, pOp++){
112776114131
if( pOp->p1!=pLevel->iTabCur ) continue;
112777114132
if( pOp->opcode==OP_Column ){
112778
- for(j=0; j<pIdx->nColumn; j++){
112779
- if( pOp->p2==pIdx->aiColumn[j] ){
112780
- pOp->p2 = j;
112781
- pOp->p1 = pLevel->iIdxCur;
112782
- break;
112783
- }
112784
- }
112785
- assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || j<pIdx->nColumn );
114133
+ int x = pOp->p2;
114134
+ assert( pIdx->pTable==pTab );
114135
+ if( !HasRowid(pTab) ){
114136
+ Index *pPk = sqlite3PrimaryKeyIndex(pTab);
114137
+ x = pPk->aiColumn[x];
114138
+ }
114139
+ x = sqlite3ColumnOfIndex(pIdx, x);
114140
+ if( x>=0 ){
114141
+ pOp->p2 = x;
114142
+ pOp->p1 = pLevel->iIdxCur;
114143
+ }
114144
+ assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 );
112786114145
}else if( pOp->opcode==OP_Rowid ){
112787114146
pOp->p1 = pLevel->iIdxCur;
112788114147
pOp->opcode = OP_IdxRowid;
112789114148
}
112790114149
}
@@ -112988,42 +114347,42 @@
112988114347
** YYNRULE the number of rules in the grammar
112989114348
** YYERRORSYMBOL is the code number of the error symbol. If not
112990114349
** defined, then do no error processing.
112991114350
*/
112992114351
#define YYCODETYPE unsigned char
112993
-#define YYNOCODE 251
114352
+#define YYNOCODE 253
112994114353
#define YYACTIONTYPE unsigned short int
112995
-#define YYWILDCARD 67
114354
+#define YYWILDCARD 68
112996114355
#define sqlite3ParserTOKENTYPE Token
112997114356
typedef union {
112998114357
int yyinit;
112999114358
sqlite3ParserTOKENTYPE yy0;
113000
- struct LimitVal yy64;
113001
- Expr* yy122;
113002
- Select* yy159;
113003
- IdList* yy180;
113004
- struct {int value; int mask;} yy207;
113005
- u8 yy258;
113006
- u16 yy305;
113007
- struct LikeOp yy318;
113008
- TriggerStep* yy327;
113009
- ExprSpan yy342;
113010
- SrcList* yy347;
113011
- int yy392;
113012
- struct TrigEvent yy410;
113013
- ExprList* yy442;
113014
- struct ValueList yy487;
114359
+ int yy4;
114360
+ struct TrigEvent yy90;
114361
+ ExprSpan yy118;
114362
+ u16 yy177;
114363
+ TriggerStep* yy203;
114364
+ u8 yy210;
114365
+ struct {int value; int mask;} yy215;
114366
+ SrcList* yy259;
114367
+ struct ValueList yy260;
114368
+ struct LimitVal yy292;
114369
+ Expr* yy314;
114370
+ ExprList* yy322;
114371
+ struct LikeOp yy342;
114372
+ IdList* yy384;
114373
+ Select* yy387;
113015114374
} YYMINORTYPE;
113016114375
#ifndef YYSTACKDEPTH
113017114376
#define YYSTACKDEPTH 100
113018114377
#endif
113019114378
#define sqlite3ParserARG_SDECL Parse *pParse;
113020114379
#define sqlite3ParserARG_PDECL ,Parse *pParse
113021114380
#define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
113022114381
#define sqlite3ParserARG_STORE yypParser->pParse = pParse
113023
-#define YYNSTATE 628
113024
-#define YYNRULE 327
114382
+#define YYNSTATE 631
114383
+#define YYNRULE 329
113025114384
#define YYFALLBACK 1
113026114385
#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
113027114386
#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
113028114387
#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
113029114388
@@ -113089,478 +114448,484 @@
113089114448
** shifting terminals.
113090114449
** yy_reduce_ofst[] For each state, the offset into yy_action for
113091114450
** shifting non-terminals after a reduce.
113092114451
** yy_default[] Default action for each state.
113093114452
*/
113094
-#define YY_ACTTAB_COUNT (1564)
114453
+#define YY_ACTTAB_COUNT (1582)
113095114454
static const YYACTIONTYPE yy_action[] = {
113096
- /* 0 */ 310, 956, 184, 418, 2, 171, 625, 595, 56, 56,
113097
- /* 10 */ 56, 56, 49, 54, 54, 54, 54, 53, 53, 52,
113098
- /* 20 */ 52, 52, 51, 233, 621, 620, 299, 621, 620, 234,
113099
- /* 30 */ 588, 582, 56, 56, 56, 56, 19, 54, 54, 54,
113100
- /* 40 */ 54, 53, 53, 52, 52, 52, 51, 233, 606, 57,
113101
- /* 50 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113102
- /* 60 */ 56, 56, 542, 54, 54, 54, 54, 53, 53, 52,
113103
- /* 70 */ 52, 52, 51, 233, 310, 595, 326, 196, 195, 194,
113104
- /* 80 */ 33, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113105
- /* 90 */ 51, 233, 618, 617, 165, 618, 617, 381, 378, 377,
113106
- /* 100 */ 408, 533, 577, 577, 588, 582, 304, 423, 376, 59,
113107
- /* 110 */ 53, 53, 52, 52, 52, 51, 233, 50, 47, 146,
113108
- /* 120 */ 575, 546, 65, 57, 58, 48, 580, 579, 581, 581,
113109
- /* 130 */ 55, 55, 56, 56, 56, 56, 213, 54, 54, 54,
113110
- /* 140 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 223,
113111
- /* 150 */ 540, 421, 170, 176, 138, 281, 384, 276, 383, 168,
113112
- /* 160 */ 490, 552, 410, 669, 621, 620, 272, 439, 410, 439,
113113
- /* 170 */ 551, 605, 67, 483, 508, 619, 600, 413, 588, 582,
113114
- /* 180 */ 601, 484, 619, 413, 619, 599, 91, 440, 441, 440,
113115
- /* 190 */ 336, 599, 73, 670, 222, 267, 481, 57, 58, 48,
113116
- /* 200 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56,
113117
- /* 210 */ 671, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113118
- /* 220 */ 51, 233, 310, 280, 232, 231, 1, 132, 200, 386,
113119
- /* 230 */ 621, 620, 618, 617, 279, 436, 290, 564, 175, 263,
113120
- /* 240 */ 410, 265, 438, 498, 437, 166, 442, 569, 337, 569,
113121
- /* 250 */ 201, 538, 588, 582, 600, 413, 165, 595, 601, 381,
113122
- /* 260 */ 378, 377, 598, 599, 92, 524, 619, 570, 570, 593,
113123
- /* 270 */ 376, 57, 58, 48, 580, 579, 581, 581, 55, 55,
113124
- /* 280 */ 56, 56, 56, 56, 598, 54, 54, 54, 54, 53,
113125
- /* 290 */ 53, 52, 52, 52, 51, 233, 310, 464, 618, 617,
113126
- /* 300 */ 591, 591, 591, 174, 273, 397, 410, 273, 410, 549,
113127
- /* 310 */ 398, 621, 620, 68, 327, 621, 620, 621, 620, 619,
113128
- /* 320 */ 547, 413, 619, 413, 472, 595, 588, 582, 473, 599,
113129
- /* 330 */ 92, 599, 92, 52, 52, 52, 51, 233, 514, 513,
113130
- /* 340 */ 206, 323, 364, 465, 221, 57, 58, 48, 580, 579,
113131
- /* 350 */ 581, 581, 55, 55, 56, 56, 56, 56, 530, 54,
113132
- /* 360 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233,
113133
- /* 370 */ 310, 397, 410, 397, 598, 373, 387, 531, 348, 618,
113134
- /* 380 */ 617, 576, 202, 618, 617, 618, 617, 413, 621, 620,
113135
- /* 390 */ 145, 255, 347, 254, 578, 599, 74, 352, 45, 490,
113136
- /* 400 */ 588, 582, 235, 189, 465, 545, 167, 297, 187, 470,
113137
- /* 410 */ 480, 67, 62, 39, 619, 547, 598, 346, 574, 57,
113138
- /* 420 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113139
- /* 430 */ 56, 56, 6, 54, 54, 54, 54, 53, 53, 52,
113140
- /* 440 */ 52, 52, 51, 233, 310, 563, 559, 408, 529, 577,
113141
- /* 450 */ 577, 345, 255, 347, 254, 182, 618, 617, 504, 505,
113142
- /* 460 */ 315, 410, 558, 235, 166, 272, 410, 353, 565, 181,
113143
- /* 470 */ 408, 547, 577, 577, 588, 582, 413, 538, 557, 562,
113144
- /* 480 */ 518, 413, 619, 249, 599, 16, 7, 36, 468, 599,
113145
- /* 490 */ 92, 517, 619, 57, 58, 48, 580, 579, 581, 581,
113146
- /* 500 */ 55, 55, 56, 56, 56, 56, 542, 54, 54, 54,
113147
- /* 510 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 328,
113148
- /* 520 */ 573, 572, 526, 559, 561, 395, 872, 246, 410, 248,
113149
- /* 530 */ 171, 393, 595, 219, 408, 410, 577, 577, 503, 558,
113150
- /* 540 */ 365, 145, 511, 413, 408, 229, 577, 577, 588, 582,
113151
- /* 550 */ 413, 599, 92, 382, 270, 557, 166, 401, 599, 69,
113152
- /* 560 */ 502, 420, 946, 199, 946, 198, 547, 57, 58, 48,
113153
- /* 570 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56,
113154
- /* 580 */ 569, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113155
- /* 590 */ 51, 233, 310, 318, 420, 945, 509, 945, 309, 598,
113156
- /* 600 */ 595, 566, 491, 212, 173, 247, 424, 616, 615, 614,
113157
- /* 610 */ 324, 197, 143, 406, 573, 572, 490, 66, 50, 47,
113158
- /* 620 */ 146, 595, 588, 582, 232, 231, 560, 428, 67, 556,
113159
- /* 630 */ 15, 619, 186, 544, 304, 422, 35, 206, 433, 424,
113160
- /* 640 */ 553, 57, 58, 48, 580, 579, 581, 581, 55, 55,
113161
- /* 650 */ 56, 56, 56, 56, 205, 54, 54, 54, 54, 53,
113162
- /* 660 */ 53, 52, 52, 52, 51, 233, 310, 570, 570, 261,
113163
- /* 670 */ 269, 598, 12, 374, 569, 166, 410, 314, 410, 421,
113164
- /* 680 */ 410, 474, 474, 366, 619, 50, 47, 146, 598, 595,
113165
- /* 690 */ 256, 413, 166, 413, 352, 413, 588, 582, 32, 599,
113166
- /* 700 */ 94, 599, 97, 599, 95, 628, 626, 330, 142, 50,
113167
- /* 710 */ 47, 146, 334, 350, 359, 57, 58, 48, 580, 579,
113168
- /* 720 */ 581, 581, 55, 55, 56, 56, 56, 56, 410, 54,
113169
- /* 730 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233,
113170
- /* 740 */ 310, 410, 389, 413, 410, 22, 566, 405, 212, 363,
113171
- /* 750 */ 390, 599, 104, 360, 410, 156, 413, 410, 604, 413,
113172
- /* 760 */ 538, 332, 570, 570, 599, 103, 494, 599, 105, 413,
113173
- /* 770 */ 588, 582, 413, 261, 550, 619, 11, 599, 106, 522,
113174
- /* 780 */ 599, 133, 169, 458, 457, 170, 35, 602, 619, 57,
113175
- /* 790 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113176
- /* 800 */ 56, 56, 410, 54, 54, 54, 54, 53, 53, 52,
113177
- /* 810 */ 52, 52, 51, 233, 310, 410, 260, 413, 410, 50,
113178
- /* 820 */ 47, 146, 358, 319, 356, 599, 134, 528, 353, 338,
113179
- /* 830 */ 413, 410, 357, 413, 358, 410, 358, 619, 599, 98,
113180
- /* 840 */ 129, 599, 102, 619, 588, 582, 413, 21, 235, 619,
113181
- /* 850 */ 413, 619, 211, 143, 599, 101, 30, 167, 599, 93,
113182
- /* 860 */ 351, 536, 203, 57, 58, 48, 580, 579, 581, 581,
113183
- /* 870 */ 55, 55, 56, 56, 56, 56, 410, 54, 54, 54,
113184
- /* 880 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 410,
113185
- /* 890 */ 527, 413, 410, 426, 215, 306, 598, 552, 141, 599,
113186
- /* 900 */ 100, 40, 410, 38, 413, 410, 551, 413, 410, 228,
113187
- /* 910 */ 220, 315, 599, 77, 501, 599, 96, 413, 588, 582,
113188
- /* 920 */ 413, 339, 253, 413, 218, 599, 137, 380, 599, 136,
113189
- /* 930 */ 28, 599, 135, 271, 716, 210, 482, 57, 58, 48,
113190
- /* 940 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56,
113191
- /* 950 */ 410, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113192
- /* 960 */ 51, 233, 310, 410, 273, 413, 410, 316, 147, 598,
113193
- /* 970 */ 273, 627, 2, 599, 76, 209, 410, 127, 413, 619,
113194
- /* 980 */ 126, 413, 410, 622, 235, 619, 599, 90, 375, 599,
113195
- /* 990 */ 89, 413, 588, 582, 27, 261, 351, 413, 619, 599,
113196
- /* 1000 */ 75, 322, 542, 542, 125, 599, 88, 321, 279, 598,
113197
- /* 1010 */ 619, 57, 46, 48, 580, 579, 581, 581, 55, 55,
113198
- /* 1020 */ 56, 56, 56, 56, 410, 54, 54, 54, 54, 53,
113199
- /* 1030 */ 53, 52, 52, 52, 51, 233, 310, 410, 451, 413,
113200
- /* 1040 */ 164, 285, 283, 273, 610, 425, 305, 599, 87, 371,
113201
- /* 1050 */ 410, 478, 413, 410, 609, 410, 608, 603, 619, 619,
113202
- /* 1060 */ 599, 99, 587, 586, 122, 413, 588, 582, 413, 619,
113203
- /* 1070 */ 413, 619, 619, 599, 86, 367, 599, 17, 599, 85,
113204
- /* 1080 */ 320, 185, 520, 519, 584, 583, 58, 48, 580, 579,
113205
- /* 1090 */ 581, 581, 55, 55, 56, 56, 56, 56, 410, 54,
113206
- /* 1100 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233,
113207
- /* 1110 */ 310, 585, 410, 413, 410, 261, 261, 261, 409, 592,
113208
- /* 1120 */ 475, 599, 84, 170, 410, 467, 519, 413, 121, 413,
113209
- /* 1130 */ 619, 619, 619, 619, 619, 599, 83, 599, 72, 413,
113210
- /* 1140 */ 588, 582, 51, 233, 626, 330, 471, 599, 71, 258,
113211
- /* 1150 */ 159, 120, 14, 463, 157, 158, 117, 261, 449, 448,
113212
- /* 1160 */ 447, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113213
- /* 1170 */ 56, 56, 619, 54, 54, 54, 54, 53, 53, 52,
113214
- /* 1180 */ 52, 52, 51, 233, 44, 404, 261, 3, 410, 460,
113215
- /* 1190 */ 261, 414, 620, 118, 399, 10, 25, 24, 555, 349,
113216
- /* 1200 */ 217, 619, 407, 413, 410, 619, 4, 44, 404, 619,
113217
- /* 1210 */ 3, 599, 82, 619, 414, 620, 456, 543, 115, 413,
113218
- /* 1220 */ 539, 402, 537, 275, 507, 407, 251, 599, 81, 216,
113219
- /* 1230 */ 274, 564, 619, 243, 454, 619, 154, 619, 619, 619,
113220
- /* 1240 */ 450, 417, 624, 110, 402, 619, 410, 236, 64, 123,
113221
- /* 1250 */ 488, 41, 42, 532, 564, 204, 410, 268, 43, 412,
113222
- /* 1260 */ 411, 413, 266, 593, 108, 619, 107, 435, 333, 599,
113223
- /* 1270 */ 80, 413, 619, 264, 41, 42, 444, 619, 410, 599,
113224
- /* 1280 */ 70, 43, 412, 411, 434, 262, 593, 149, 619, 598,
113225
- /* 1290 */ 257, 237, 188, 413, 591, 591, 591, 590, 589, 13,
113226
- /* 1300 */ 619, 599, 18, 329, 235, 619, 44, 404, 361, 3,
113227
- /* 1310 */ 419, 462, 340, 414, 620, 227, 124, 591, 591, 591,
113228
- /* 1320 */ 590, 589, 13, 619, 407, 410, 619, 410, 139, 34,
113229
- /* 1330 */ 404, 388, 3, 148, 623, 313, 414, 620, 312, 331,
113230
- /* 1340 */ 413, 461, 413, 402, 180, 354, 413, 407, 599, 79,
113231
- /* 1350 */ 599, 78, 250, 564, 599, 9, 619, 613, 612, 611,
113232
- /* 1360 */ 619, 8, 453, 443, 242, 416, 402, 619, 239, 235,
113233
- /* 1370 */ 179, 238, 429, 41, 42, 289, 564, 619, 619, 619,
113234
- /* 1380 */ 43, 412, 411, 619, 144, 593, 619, 619, 177, 61,
113235
- /* 1390 */ 619, 597, 392, 621, 620, 288, 41, 42, 415, 619,
113236
- /* 1400 */ 294, 30, 394, 43, 412, 411, 293, 619, 593, 31,
113237
- /* 1410 */ 619, 396, 292, 60, 230, 37, 591, 591, 591, 590,
113238
- /* 1420 */ 589, 13, 214, 554, 183, 291, 172, 302, 301, 300,
113239
- /* 1430 */ 178, 298, 596, 564, 452, 29, 286, 391, 541, 591,
113240
- /* 1440 */ 591, 591, 590, 589, 13, 284, 521, 535, 150, 534,
113241
- /* 1450 */ 241, 282, 385, 192, 191, 325, 516, 515, 277, 240,
113242
- /* 1460 */ 511, 524, 308, 512, 128, 593, 510, 225, 226, 487,
113243
- /* 1470 */ 486, 224, 152, 492, 465, 307, 485, 163, 153, 372,
113244
- /* 1480 */ 479, 151, 162, 259, 370, 161, 368, 208, 476, 477,
113245
- /* 1490 */ 26, 160, 469, 466, 362, 140, 591, 591, 591, 116,
113246
- /* 1500 */ 119, 455, 344, 155, 114, 343, 113, 112, 446, 111,
113247
- /* 1510 */ 131, 109, 432, 317, 130, 431, 23, 20, 430, 427,
113248
- /* 1520 */ 190, 63, 255, 342, 244, 607, 295, 287, 311, 594,
113249
- /* 1530 */ 278, 508, 496, 235, 493, 571, 497, 568, 495, 403,
113250
- /* 1540 */ 459, 379, 355, 245, 193, 303, 567, 296, 341, 5,
113251
- /* 1550 */ 445, 548, 506, 207, 525, 500, 335, 489, 252, 369,
113252
- /* 1560 */ 400, 499, 523, 233,
114455
+ /* 0 */ 312, 961, 185, 420, 2, 171, 516, 515, 597, 56,
114456
+ /* 10 */ 56, 56, 56, 49, 54, 54, 54, 54, 53, 53,
114457
+ /* 20 */ 52, 52, 52, 51, 234, 197, 196, 195, 624, 623,
114458
+ /* 30 */ 301, 590, 584, 56, 56, 56, 56, 156, 54, 54,
114459
+ /* 40 */ 54, 54, 53, 53, 52, 52, 52, 51, 234, 628,
114460
+ /* 50 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114461
+ /* 60 */ 56, 56, 56, 466, 54, 54, 54, 54, 53, 53,
114462
+ /* 70 */ 52, 52, 52, 51, 234, 312, 597, 52, 52, 52,
114463
+ /* 80 */ 51, 234, 33, 54, 54, 54, 54, 53, 53, 52,
114464
+ /* 90 */ 52, 52, 51, 234, 624, 623, 621, 620, 165, 624,
114465
+ /* 100 */ 623, 383, 380, 379, 214, 328, 590, 584, 624, 623,
114466
+ /* 110 */ 467, 59, 378, 619, 618, 617, 53, 53, 52, 52,
114467
+ /* 120 */ 52, 51, 234, 506, 507, 57, 58, 48, 582, 581,
114468
+ /* 130 */ 583, 583, 55, 55, 56, 56, 56, 56, 30, 54,
114469
+ /* 140 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114470
+ /* 150 */ 312, 50, 47, 146, 233, 232, 207, 474, 256, 349,
114471
+ /* 160 */ 255, 475, 621, 620, 554, 438, 298, 621, 620, 236,
114472
+ /* 170 */ 674, 435, 440, 553, 439, 366, 621, 620, 540, 224,
114473
+ /* 180 */ 551, 590, 584, 176, 138, 282, 386, 277, 385, 168,
114474
+ /* 190 */ 600, 422, 951, 548, 622, 951, 273, 572, 572, 566,
114475
+ /* 200 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114476
+ /* 210 */ 56, 56, 56, 354, 54, 54, 54, 54, 53, 53,
114477
+ /* 220 */ 52, 52, 52, 51, 234, 312, 561, 526, 62, 675,
114478
+ /* 230 */ 132, 595, 410, 348, 579, 579, 492, 426, 577, 419,
114479
+ /* 240 */ 627, 65, 329, 560, 441, 237, 676, 123, 607, 67,
114480
+ /* 250 */ 542, 532, 622, 170, 205, 500, 590, 584, 166, 559,
114481
+ /* 260 */ 622, 403, 593, 593, 593, 442, 443, 271, 422, 950,
114482
+ /* 270 */ 166, 223, 950, 483, 190, 57, 58, 48, 582, 581,
114483
+ /* 280 */ 583, 583, 55, 55, 56, 56, 56, 56, 600, 54,
114484
+ /* 290 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114485
+ /* 300 */ 312, 441, 412, 376, 175, 165, 166, 391, 383, 380,
114486
+ /* 310 */ 379, 342, 412, 203, 426, 66, 392, 622, 415, 378,
114487
+ /* 320 */ 597, 166, 442, 338, 444, 571, 601, 74, 415, 624,
114488
+ /* 330 */ 623, 590, 584, 624, 623, 174, 601, 92, 333, 171,
114489
+ /* 340 */ 1, 410, 597, 579, 579, 624, 623, 600, 306, 425,
114490
+ /* 350 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114491
+ /* 360 */ 56, 56, 56, 580, 54, 54, 54, 54, 53, 53,
114492
+ /* 370 */ 52, 52, 52, 51, 234, 312, 472, 262, 399, 68,
114493
+ /* 380 */ 412, 339, 571, 389, 624, 623, 578, 602, 597, 589,
114494
+ /* 390 */ 588, 603, 412, 622, 423, 533, 415, 621, 620, 513,
114495
+ /* 400 */ 257, 621, 620, 166, 601, 91, 590, 584, 415, 45,
114496
+ /* 410 */ 597, 586, 585, 621, 620, 250, 601, 92, 39, 347,
114497
+ /* 420 */ 576, 336, 597, 547, 567, 57, 58, 48, 582, 581,
114498
+ /* 430 */ 583, 583, 55, 55, 56, 56, 56, 56, 587, 54,
114499
+ /* 440 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114500
+ /* 450 */ 312, 561, 621, 620, 531, 291, 470, 188, 399, 375,
114501
+ /* 460 */ 247, 492, 249, 350, 412, 476, 476, 368, 560, 299,
114502
+ /* 470 */ 334, 412, 281, 482, 67, 565, 410, 622, 579, 579,
114503
+ /* 480 */ 415, 590, 584, 280, 559, 467, 520, 415, 601, 92,
114504
+ /* 490 */ 597, 167, 544, 36, 877, 601, 16, 519, 564, 6,
114505
+ /* 500 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114506
+ /* 510 */ 56, 56, 56, 200, 54, 54, 54, 54, 53, 53,
114507
+ /* 520 */ 52, 52, 52, 51, 234, 312, 183, 412, 236, 528,
114508
+ /* 530 */ 395, 535, 358, 256, 349, 255, 397, 412, 248, 182,
114509
+ /* 540 */ 353, 359, 549, 415, 236, 317, 563, 50, 47, 146,
114510
+ /* 550 */ 273, 601, 73, 415, 7, 311, 590, 584, 568, 493,
114511
+ /* 560 */ 213, 601, 92, 233, 232, 410, 173, 579, 579, 330,
114512
+ /* 570 */ 575, 574, 631, 629, 332, 57, 58, 48, 582, 581,
114513
+ /* 580 */ 583, 583, 55, 55, 56, 56, 56, 56, 199, 54,
114514
+ /* 590 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114515
+ /* 600 */ 312, 492, 340, 320, 511, 505, 572, 572, 460, 562,
114516
+ /* 610 */ 549, 170, 145, 430, 67, 558, 410, 622, 579, 579,
114517
+ /* 620 */ 384, 236, 600, 412, 408, 575, 574, 504, 572, 572,
114518
+ /* 630 */ 571, 590, 584, 353, 198, 143, 268, 549, 316, 415,
114519
+ /* 640 */ 306, 424, 207, 50, 47, 146, 167, 601, 69, 546,
114520
+ /* 650 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114521
+ /* 660 */ 56, 56, 56, 555, 54, 54, 54, 54, 53, 53,
114522
+ /* 670 */ 52, 52, 52, 51, 234, 312, 600, 326, 412, 270,
114523
+ /* 680 */ 145, 264, 274, 266, 459, 571, 423, 35, 412, 568,
114524
+ /* 690 */ 407, 213, 428, 388, 415, 308, 212, 143, 622, 354,
114525
+ /* 700 */ 317, 12, 601, 94, 415, 549, 590, 584, 50, 47,
114526
+ /* 710 */ 146, 365, 601, 97, 552, 362, 318, 147, 602, 361,
114527
+ /* 720 */ 325, 15, 603, 187, 206, 57, 58, 48, 582, 581,
114528
+ /* 730 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114529
+ /* 740 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114530
+ /* 750 */ 312, 412, 35, 412, 415, 22, 630, 2, 600, 50,
114531
+ /* 760 */ 47, 146, 601, 95, 412, 485, 510, 415, 412, 415,
114532
+ /* 770 */ 412, 11, 235, 486, 412, 601, 104, 601, 103, 19,
114533
+ /* 780 */ 415, 590, 584, 352, 415, 40, 415, 38, 601, 105,
114534
+ /* 790 */ 415, 32, 601, 106, 601, 133, 544, 169, 601, 134,
114535
+ /* 800 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114536
+ /* 810 */ 56, 56, 56, 412, 54, 54, 54, 54, 53, 53,
114537
+ /* 820 */ 52, 52, 52, 51, 234, 312, 412, 274, 412, 415,
114538
+ /* 830 */ 412, 274, 274, 274, 201, 230, 721, 601, 98, 484,
114539
+ /* 840 */ 427, 307, 415, 622, 415, 540, 415, 622, 622, 622,
114540
+ /* 850 */ 601, 102, 601, 101, 601, 93, 590, 584, 262, 21,
114541
+ /* 860 */ 129, 622, 522, 521, 554, 222, 469, 521, 600, 324,
114542
+ /* 870 */ 323, 322, 211, 553, 622, 57, 58, 48, 582, 581,
114543
+ /* 880 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114544
+ /* 890 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114545
+ /* 900 */ 312, 412, 261, 412, 415, 412, 600, 210, 625, 367,
114546
+ /* 910 */ 51, 234, 601, 100, 538, 606, 142, 415, 355, 415,
114547
+ /* 920 */ 412, 415, 412, 496, 622, 601, 77, 601, 96, 601,
114548
+ /* 930 */ 137, 590, 584, 530, 622, 529, 415, 141, 415, 28,
114549
+ /* 940 */ 524, 600, 229, 544, 601, 136, 601, 135, 604, 204,
114550
+ /* 950 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114551
+ /* 960 */ 56, 56, 56, 412, 54, 54, 54, 54, 53, 53,
114552
+ /* 970 */ 52, 52, 52, 51, 234, 312, 412, 360, 412, 415,
114553
+ /* 980 */ 412, 360, 286, 600, 503, 220, 127, 601, 76, 629,
114554
+ /* 990 */ 332, 382, 415, 622, 415, 540, 415, 622, 412, 613,
114555
+ /* 1000 */ 601, 90, 601, 89, 601, 75, 590, 584, 341, 272,
114556
+ /* 1010 */ 377, 622, 126, 27, 415, 622, 164, 544, 125, 280,
114557
+ /* 1020 */ 373, 122, 601, 88, 480, 57, 46, 48, 582, 581,
114558
+ /* 1030 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114559
+ /* 1040 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114560
+ /* 1050 */ 312, 412, 360, 412, 415, 412, 284, 186, 369, 321,
114561
+ /* 1060 */ 477, 170, 601, 87, 121, 473, 221, 415, 622, 415,
114562
+ /* 1070 */ 254, 415, 412, 355, 412, 601, 99, 601, 86, 601,
114563
+ /* 1080 */ 17, 590, 584, 259, 612, 120, 159, 158, 415, 622,
114564
+ /* 1090 */ 415, 14, 465, 157, 462, 25, 601, 85, 601, 84,
114565
+ /* 1100 */ 622, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114566
+ /* 1110 */ 56, 56, 56, 412, 54, 54, 54, 54, 53, 53,
114567
+ /* 1120 */ 52, 52, 52, 51, 234, 312, 412, 262, 412, 415,
114568
+ /* 1130 */ 412, 262, 118, 611, 117, 24, 10, 601, 83, 351,
114569
+ /* 1140 */ 216, 219, 415, 622, 415, 608, 415, 622, 412, 622,
114570
+ /* 1150 */ 601, 72, 601, 71, 601, 82, 590, 584, 262, 4,
114571
+ /* 1160 */ 605, 622, 458, 115, 415, 456, 252, 154, 452, 110,
114572
+ /* 1170 */ 108, 453, 601, 81, 622, 451, 622, 48, 582, 581,
114573
+ /* 1180 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114574
+ /* 1190 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114575
+ /* 1200 */ 44, 406, 450, 3, 415, 412, 262, 107, 416, 623,
114576
+ /* 1210 */ 446, 437, 601, 80, 436, 335, 238, 189, 411, 409,
114577
+ /* 1220 */ 594, 415, 622, 44, 406, 401, 3, 412, 557, 601,
114578
+ /* 1230 */ 70, 416, 623, 412, 622, 149, 622, 421, 404, 64,
114579
+ /* 1240 */ 412, 622, 409, 415, 622, 331, 139, 148, 566, 415,
114580
+ /* 1250 */ 449, 601, 18, 228, 124, 626, 415, 601, 79, 315,
114581
+ /* 1260 */ 181, 404, 412, 545, 601, 78, 262, 541, 41, 42,
114582
+ /* 1270 */ 534, 566, 390, 202, 262, 43, 414, 413, 415, 622,
114583
+ /* 1280 */ 595, 314, 622, 622, 180, 539, 601, 92, 415, 276,
114584
+ /* 1290 */ 622, 41, 42, 509, 616, 615, 601, 9, 43, 414,
114585
+ /* 1300 */ 413, 622, 418, 595, 262, 622, 275, 600, 614, 622,
114586
+ /* 1310 */ 218, 593, 593, 593, 592, 591, 13, 178, 217, 417,
114587
+ /* 1320 */ 622, 236, 622, 44, 406, 490, 3, 269, 399, 267,
114588
+ /* 1330 */ 609, 416, 623, 400, 593, 593, 593, 592, 591, 13,
114589
+ /* 1340 */ 265, 622, 409, 622, 263, 622, 34, 406, 244, 3,
114590
+ /* 1350 */ 258, 363, 464, 463, 416, 623, 622, 356, 251, 8,
114591
+ /* 1360 */ 622, 404, 177, 599, 455, 409, 622, 622, 622, 622,
114592
+ /* 1370 */ 445, 566, 243, 622, 622, 236, 295, 240, 31, 239,
114593
+ /* 1380 */ 622, 431, 30, 396, 404, 290, 622, 294, 622, 293,
114594
+ /* 1390 */ 144, 41, 42, 622, 566, 622, 394, 622, 43, 414,
114595
+ /* 1400 */ 413, 622, 289, 595, 398, 60, 622, 292, 37, 231,
114596
+ /* 1410 */ 598, 172, 622, 29, 41, 42, 393, 523, 622, 556,
114597
+ /* 1420 */ 184, 43, 414, 413, 287, 387, 595, 543, 285, 518,
114598
+ /* 1430 */ 537, 536, 517, 327, 593, 593, 593, 592, 591, 13,
114599
+ /* 1440 */ 215, 283, 278, 514, 513, 304, 303, 302, 179, 300,
114600
+ /* 1450 */ 512, 310, 454, 128, 227, 226, 309, 593, 593, 593,
114601
+ /* 1460 */ 592, 591, 13, 494, 489, 225, 488, 150, 487, 242,
114602
+ /* 1470 */ 163, 61, 374, 481, 162, 161, 624, 623, 241, 372,
114603
+ /* 1480 */ 209, 479, 370, 260, 26, 160, 478, 364, 468, 471,
114604
+ /* 1490 */ 140, 152, 119, 467, 131, 116, 155, 153, 345, 457,
114605
+ /* 1500 */ 151, 346, 130, 114, 113, 112, 111, 448, 319, 23,
114606
+ /* 1510 */ 109, 434, 20, 433, 432, 429, 566, 610, 573, 596,
114607
+ /* 1520 */ 63, 405, 191, 279, 510, 296, 498, 288, 570, 495,
114608
+ /* 1530 */ 499, 497, 461, 194, 5, 305, 193, 192, 381, 569,
114609
+ /* 1540 */ 357, 256, 344, 245, 526, 246, 253, 313, 595, 343,
114610
+ /* 1550 */ 447, 297, 236, 402, 550, 491, 508, 502, 501, 527,
114611
+ /* 1560 */ 234, 208, 525, 962, 962, 962, 371, 962, 962, 962,
114612
+ /* 1570 */ 962, 962, 962, 962, 962, 337, 962, 962, 962, 593,
114613
+ /* 1580 */ 593, 593,
113253114614
};
113254114615
static const YYCODETYPE yy_lookahead[] = {
113255
- /* 0 */ 19, 142, 143, 144, 145, 24, 1, 26, 77, 78,
114616
+ /* 0 */ 19, 143, 144, 145, 146, 24, 7, 8, 27, 78,
113256114617
/* 10 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
113257
- /* 20 */ 89, 90, 91, 92, 26, 27, 15, 26, 27, 197,
113258
- /* 30 */ 49, 50, 77, 78, 79, 80, 204, 82, 83, 84,
113259
- /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 23, 68,
114618
+ /* 20 */ 89, 90, 91, 92, 93, 106, 107, 108, 27, 28,
114619
+ /* 30 */ 15, 50, 51, 78, 79, 80, 81, 26, 83, 84,
114620
+ /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 1,
113260114621
/* 50 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113261
- /* 60 */ 79, 80, 166, 82, 83, 84, 85, 86, 87, 88,
113262
- /* 70 */ 89, 90, 91, 92, 19, 94, 19, 105, 106, 107,
113263
- /* 80 */ 25, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113264
- /* 90 */ 91, 92, 94, 95, 96, 94, 95, 99, 100, 101,
113265
- /* 100 */ 112, 205, 114, 115, 49, 50, 22, 23, 110, 54,
113266
- /* 110 */ 86, 87, 88, 89, 90, 91, 92, 221, 222, 223,
113267
- /* 120 */ 23, 120, 25, 68, 69, 70, 71, 72, 73, 74,
113268
- /* 130 */ 75, 76, 77, 78, 79, 80, 22, 82, 83, 84,
113269
- /* 140 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 92,
113270
- /* 150 */ 23, 67, 25, 96, 97, 98, 99, 100, 101, 102,
113271
- /* 160 */ 150, 32, 150, 118, 26, 27, 109, 150, 150, 150,
113272
- /* 170 */ 41, 161, 162, 180, 181, 165, 113, 165, 49, 50,
113273
- /* 180 */ 117, 188, 165, 165, 165, 173, 174, 170, 171, 170,
113274
- /* 190 */ 171, 173, 174, 118, 184, 16, 186, 68, 69, 70,
113275
- /* 200 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
113276
- /* 210 */ 118, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113277
- /* 220 */ 91, 92, 19, 98, 86, 87, 22, 24, 160, 88,
113278
- /* 230 */ 26, 27, 94, 95, 109, 97, 224, 66, 118, 60,
113279
- /* 240 */ 150, 62, 104, 23, 106, 25, 229, 230, 229, 230,
113280
- /* 250 */ 160, 150, 49, 50, 113, 165, 96, 26, 117, 99,
113281
- /* 260 */ 100, 101, 194, 173, 174, 94, 165, 129, 130, 98,
113282
- /* 270 */ 110, 68, 69, 70, 71, 72, 73, 74, 75, 76,
113283
- /* 280 */ 77, 78, 79, 80, 194, 82, 83, 84, 85, 86,
113284
- /* 290 */ 87, 88, 89, 90, 91, 92, 19, 11, 94, 95,
113285
- /* 300 */ 129, 130, 131, 118, 150, 215, 150, 150, 150, 25,
113286
- /* 310 */ 220, 26, 27, 22, 213, 26, 27, 26, 27, 165,
113287
- /* 320 */ 25, 165, 165, 165, 30, 94, 49, 50, 34, 173,
113288
- /* 330 */ 174, 173, 174, 88, 89, 90, 91, 92, 7, 8,
113289
- /* 340 */ 160, 187, 48, 57, 187, 68, 69, 70, 71, 72,
113290
- /* 350 */ 73, 74, 75, 76, 77, 78, 79, 80, 23, 82,
113291
- /* 360 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
113292
- /* 370 */ 19, 215, 150, 215, 194, 19, 220, 88, 220, 94,
113293
- /* 380 */ 95, 23, 160, 94, 95, 94, 95, 165, 26, 27,
113294
- /* 390 */ 95, 105, 106, 107, 113, 173, 174, 217, 22, 150,
113295
- /* 400 */ 49, 50, 116, 119, 57, 120, 50, 158, 22, 21,
113296
- /* 410 */ 161, 162, 232, 136, 165, 120, 194, 237, 23, 68,
113297
- /* 420 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113298
- /* 430 */ 79, 80, 22, 82, 83, 84, 85, 86, 87, 88,
113299
- /* 440 */ 89, 90, 91, 92, 19, 23, 12, 112, 23, 114,
113300
- /* 450 */ 115, 63, 105, 106, 107, 23, 94, 95, 97, 98,
113301
- /* 460 */ 104, 150, 28, 116, 25, 109, 150, 150, 23, 23,
113302
- /* 470 */ 112, 25, 114, 115, 49, 50, 165, 150, 44, 11,
113303
- /* 480 */ 46, 165, 165, 16, 173, 174, 76, 136, 100, 173,
113304
- /* 490 */ 174, 57, 165, 68, 69, 70, 71, 72, 73, 74,
113305
- /* 500 */ 75, 76, 77, 78, 79, 80, 166, 82, 83, 84,
113306
- /* 510 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 169,
113307
- /* 520 */ 170, 171, 23, 12, 23, 214, 138, 60, 150, 62,
113308
- /* 530 */ 24, 215, 26, 216, 112, 150, 114, 115, 36, 28,
113309
- /* 540 */ 213, 95, 103, 165, 112, 205, 114, 115, 49, 50,
113310
- /* 550 */ 165, 173, 174, 51, 23, 44, 25, 46, 173, 174,
113311
- /* 560 */ 58, 22, 23, 22, 25, 160, 120, 68, 69, 70,
113312
- /* 570 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
113313
- /* 580 */ 230, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113314
- /* 590 */ 91, 92, 19, 215, 22, 23, 23, 25, 163, 194,
113315
- /* 600 */ 94, 166, 167, 168, 25, 138, 67, 7, 8, 9,
113316
- /* 610 */ 108, 206, 207, 169, 170, 171, 150, 22, 221, 222,
113317
- /* 620 */ 223, 26, 49, 50, 86, 87, 23, 161, 162, 23,
113318
- /* 630 */ 22, 165, 24, 120, 22, 23, 25, 160, 241, 67,
113319
- /* 640 */ 176, 68, 69, 70, 71, 72, 73, 74, 75, 76,
113320
- /* 650 */ 77, 78, 79, 80, 160, 82, 83, 84, 85, 86,
113321
- /* 660 */ 87, 88, 89, 90, 91, 92, 19, 129, 130, 150,
113322
- /* 670 */ 23, 194, 35, 23, 230, 25, 150, 155, 150, 67,
113323
- /* 680 */ 150, 105, 106, 107, 165, 221, 222, 223, 194, 94,
113324
- /* 690 */ 23, 165, 25, 165, 217, 165, 49, 50, 25, 173,
113325
- /* 700 */ 174, 173, 174, 173, 174, 0, 1, 2, 118, 221,
113326
- /* 710 */ 222, 223, 193, 219, 237, 68, 69, 70, 71, 72,
113327
- /* 720 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82,
113328
- /* 730 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
113329
- /* 740 */ 19, 150, 19, 165, 150, 24, 166, 167, 168, 227,
113330
- /* 750 */ 27, 173, 174, 231, 150, 25, 165, 150, 172, 165,
113331
- /* 760 */ 150, 242, 129, 130, 173, 174, 180, 173, 174, 165,
113332
- /* 770 */ 49, 50, 165, 150, 176, 165, 35, 173, 174, 165,
113333
- /* 780 */ 173, 174, 35, 23, 23, 25, 25, 173, 165, 68,
113334
- /* 790 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113335
- /* 800 */ 79, 80, 150, 82, 83, 84, 85, 86, 87, 88,
113336
- /* 810 */ 89, 90, 91, 92, 19, 150, 193, 165, 150, 221,
113337
- /* 820 */ 222, 223, 150, 213, 19, 173, 174, 23, 150, 97,
113338
- /* 830 */ 165, 150, 27, 165, 150, 150, 150, 165, 173, 174,
113339
- /* 840 */ 22, 173, 174, 165, 49, 50, 165, 52, 116, 165,
113340
- /* 850 */ 165, 165, 206, 207, 173, 174, 126, 50, 173, 174,
113341
- /* 860 */ 128, 27, 160, 68, 69, 70, 71, 72, 73, 74,
113342
- /* 870 */ 75, 76, 77, 78, 79, 80, 150, 82, 83, 84,
113343
- /* 880 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 150,
113344
- /* 890 */ 23, 165, 150, 23, 216, 25, 194, 32, 39, 173,
113345
- /* 900 */ 174, 135, 150, 137, 165, 150, 41, 165, 150, 52,
113346
- /* 910 */ 238, 104, 173, 174, 29, 173, 174, 165, 49, 50,
113347
- /* 920 */ 165, 219, 238, 165, 238, 173, 174, 52, 173, 174,
113348
- /* 930 */ 22, 173, 174, 23, 23, 160, 25, 68, 69, 70,
113349
- /* 940 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
113350
- /* 950 */ 150, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113351
- /* 960 */ 91, 92, 19, 150, 150, 165, 150, 245, 246, 194,
113352
- /* 970 */ 150, 144, 145, 173, 174, 160, 150, 22, 165, 165,
113353
- /* 980 */ 22, 165, 150, 150, 116, 165, 173, 174, 52, 173,
113354
- /* 990 */ 174, 165, 49, 50, 22, 150, 128, 165, 165, 173,
113355
- /* 1000 */ 174, 187, 166, 166, 22, 173, 174, 187, 109, 194,
113356
- /* 1010 */ 165, 68, 69, 70, 71, 72, 73, 74, 75, 76,
113357
- /* 1020 */ 77, 78, 79, 80, 150, 82, 83, 84, 85, 86,
113358
- /* 1030 */ 87, 88, 89, 90, 91, 92, 19, 150, 193, 165,
113359
- /* 1040 */ 102, 205, 205, 150, 150, 247, 248, 173, 174, 19,
113360
- /* 1050 */ 150, 20, 165, 150, 150, 150, 150, 150, 165, 165,
113361
- /* 1060 */ 173, 174, 49, 50, 104, 165, 49, 50, 165, 165,
113362
- /* 1070 */ 165, 165, 165, 173, 174, 43, 173, 174, 173, 174,
113363
- /* 1080 */ 187, 24, 190, 191, 71, 72, 69, 70, 71, 72,
113364
- /* 1090 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82,
113365
- /* 1100 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
113366
- /* 1110 */ 19, 98, 150, 165, 150, 150, 150, 150, 150, 150,
113367
- /* 1120 */ 59, 173, 174, 25, 150, 190, 191, 165, 53, 165,
113368
- /* 1130 */ 165, 165, 165, 165, 165, 173, 174, 173, 174, 165,
113369
- /* 1140 */ 49, 50, 91, 92, 1, 2, 53, 173, 174, 138,
113370
- /* 1150 */ 104, 22, 5, 1, 35, 118, 127, 150, 193, 193,
113371
- /* 1160 */ 193, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113372
- /* 1170 */ 79, 80, 165, 82, 83, 84, 85, 86, 87, 88,
113373
- /* 1180 */ 89, 90, 91, 92, 19, 20, 150, 22, 150, 27,
113374
- /* 1190 */ 150, 26, 27, 108, 150, 22, 76, 76, 150, 25,
113375
- /* 1200 */ 193, 165, 37, 165, 150, 165, 22, 19, 20, 165,
113376
- /* 1210 */ 22, 173, 174, 165, 26, 27, 23, 150, 119, 165,
113377
- /* 1220 */ 150, 56, 150, 150, 150, 37, 16, 173, 174, 193,
113378
- /* 1230 */ 150, 66, 165, 193, 1, 165, 121, 165, 165, 165,
113379
- /* 1240 */ 20, 146, 147, 119, 56, 165, 150, 152, 16, 154,
113380
- /* 1250 */ 150, 86, 87, 88, 66, 160, 150, 150, 93, 94,
113381
- /* 1260 */ 95, 165, 150, 98, 108, 165, 127, 23, 65, 173,
113382
- /* 1270 */ 174, 165, 165, 150, 86, 87, 128, 165, 150, 173,
113383
- /* 1280 */ 174, 93, 94, 95, 23, 150, 98, 15, 165, 194,
113384
- /* 1290 */ 150, 140, 22, 165, 129, 130, 131, 132, 133, 134,
113385
- /* 1300 */ 165, 173, 174, 3, 116, 165, 19, 20, 150, 22,
113386
- /* 1310 */ 4, 150, 217, 26, 27, 179, 179, 129, 130, 131,
113387
- /* 1320 */ 132, 133, 134, 165, 37, 150, 165, 150, 164, 19,
113388
- /* 1330 */ 20, 150, 22, 246, 149, 249, 26, 27, 249, 244,
113389
- /* 1340 */ 165, 150, 165, 56, 6, 150, 165, 37, 173, 174,
113390
- /* 1350 */ 173, 174, 150, 66, 173, 174, 165, 149, 149, 13,
113391
- /* 1360 */ 165, 25, 150, 150, 150, 149, 56, 165, 150, 116,
113392
- /* 1370 */ 151, 150, 150, 86, 87, 150, 66, 165, 165, 165,
113393
- /* 1380 */ 93, 94, 95, 165, 150, 98, 165, 165, 151, 22,
113394
- /* 1390 */ 165, 194, 150, 26, 27, 150, 86, 87, 159, 165,
113395
- /* 1400 */ 199, 126, 123, 93, 94, 95, 200, 165, 98, 124,
113396
- /* 1410 */ 165, 122, 201, 125, 225, 135, 129, 130, 131, 132,
113397
- /* 1420 */ 133, 134, 5, 157, 157, 202, 118, 10, 11, 12,
113398
- /* 1430 */ 13, 14, 203, 66, 17, 104, 210, 121, 211, 129,
113399
- /* 1440 */ 130, 131, 132, 133, 134, 210, 175, 211, 31, 211,
113400
- /* 1450 */ 33, 210, 104, 86, 87, 47, 175, 183, 175, 42,
113401
- /* 1460 */ 103, 94, 178, 177, 22, 98, 175, 92, 228, 175,
113402
- /* 1470 */ 175, 228, 55, 183, 57, 178, 175, 156, 61, 18,
113403
- /* 1480 */ 157, 64, 156, 235, 157, 156, 45, 157, 236, 157,
113404
- /* 1490 */ 135, 156, 199, 189, 157, 68, 129, 130, 131, 22,
113405
- /* 1500 */ 189, 199, 157, 156, 192, 18, 192, 192, 199, 192,
113406
- /* 1510 */ 218, 189, 40, 157, 218, 157, 240, 240, 157, 38,
113407
- /* 1520 */ 196, 243, 105, 106, 107, 153, 198, 209, 111, 166,
113408
- /* 1530 */ 176, 181, 166, 116, 166, 230, 176, 230, 176, 226,
113409
- /* 1540 */ 199, 177, 239, 209, 185, 148, 166, 195, 209, 196,
113410
- /* 1550 */ 199, 208, 182, 233, 173, 182, 139, 186, 239, 234,
113411
- /* 1560 */ 191, 182, 173, 92,
113412
-};
113413
-#define YY_SHIFT_USE_DFLT (-70)
113414
-#define YY_SHIFT_COUNT (417)
113415
-#define YY_SHIFT_MIN (-69)
113416
-#define YY_SHIFT_MAX (1487)
114622
+ /* 60 */ 79, 80, 81, 11, 83, 84, 85, 86, 87, 88,
114623
+ /* 70 */ 89, 90, 91, 92, 93, 19, 95, 89, 90, 91,
114624
+ /* 80 */ 92, 93, 26, 83, 84, 85, 86, 87, 88, 89,
114625
+ /* 90 */ 90, 91, 92, 93, 27, 28, 95, 96, 97, 27,
114626
+ /* 100 */ 28, 100, 101, 102, 22, 19, 50, 51, 27, 28,
114627
+ /* 110 */ 58, 55, 111, 7, 8, 9, 87, 88, 89, 90,
114628
+ /* 120 */ 91, 92, 93, 98, 99, 69, 70, 71, 72, 73,
114629
+ /* 130 */ 74, 75, 76, 77, 78, 79, 80, 81, 127, 83,
114630
+ /* 140 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114631
+ /* 150 */ 19, 223, 224, 225, 87, 88, 162, 31, 106, 107,
114632
+ /* 160 */ 108, 35, 95, 96, 33, 98, 23, 95, 96, 117,
114633
+ /* 170 */ 119, 243, 105, 42, 107, 49, 95, 96, 151, 93,
114634
+ /* 180 */ 26, 50, 51, 97, 98, 99, 100, 101, 102, 103,
114635
+ /* 190 */ 196, 22, 23, 121, 167, 26, 110, 130, 131, 67,
114636
+ /* 200 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114637
+ /* 210 */ 79, 80, 81, 219, 83, 84, 85, 86, 87, 88,
114638
+ /* 220 */ 89, 90, 91, 92, 93, 19, 12, 95, 234, 119,
114639
+ /* 230 */ 24, 99, 113, 239, 115, 116, 151, 68, 23, 147,
114640
+ /* 240 */ 148, 26, 215, 29, 151, 153, 119, 155, 163, 164,
114641
+ /* 250 */ 23, 23, 167, 26, 162, 23, 50, 51, 26, 45,
114642
+ /* 260 */ 167, 47, 130, 131, 132, 172, 173, 23, 22, 23,
114643
+ /* 270 */ 26, 186, 26, 188, 120, 69, 70, 71, 72, 73,
114644
+ /* 280 */ 74, 75, 76, 77, 78, 79, 80, 81, 196, 83,
114645
+ /* 290 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114646
+ /* 300 */ 19, 151, 151, 23, 119, 97, 26, 19, 100, 101,
114647
+ /* 310 */ 102, 219, 151, 162, 68, 22, 28, 167, 167, 111,
114648
+ /* 320 */ 27, 26, 172, 173, 231, 232, 175, 176, 167, 27,
114649
+ /* 330 */ 28, 50, 51, 27, 28, 119, 175, 176, 246, 24,
114650
+ /* 340 */ 22, 113, 27, 115, 116, 27, 28, 196, 22, 23,
114651
+ /* 350 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114652
+ /* 360 */ 79, 80, 81, 114, 83, 84, 85, 86, 87, 88,
114653
+ /* 370 */ 89, 90, 91, 92, 93, 19, 21, 151, 217, 22,
114654
+ /* 380 */ 151, 231, 232, 222, 27, 28, 23, 114, 95, 50,
114655
+ /* 390 */ 51, 118, 151, 167, 68, 89, 167, 95, 96, 104,
114656
+ /* 400 */ 23, 95, 96, 26, 175, 176, 50, 51, 167, 22,
114657
+ /* 410 */ 95, 72, 73, 95, 96, 16, 175, 176, 137, 64,
114658
+ /* 420 */ 23, 195, 27, 121, 23, 69, 70, 71, 72, 73,
114659
+ /* 430 */ 74, 75, 76, 77, 78, 79, 80, 81, 99, 83,
114660
+ /* 440 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114661
+ /* 450 */ 19, 12, 95, 96, 23, 226, 101, 22, 217, 19,
114662
+ /* 460 */ 61, 151, 63, 222, 151, 106, 107, 108, 29, 159,
114663
+ /* 470 */ 244, 151, 99, 163, 164, 23, 113, 167, 115, 116,
114664
+ /* 480 */ 167, 50, 51, 110, 45, 58, 47, 167, 175, 176,
114665
+ /* 490 */ 95, 51, 168, 137, 139, 175, 176, 58, 11, 22,
114666
+ /* 500 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114667
+ /* 510 */ 79, 80, 81, 22, 83, 84, 85, 86, 87, 88,
114668
+ /* 520 */ 89, 90, 91, 92, 93, 19, 23, 151, 117, 23,
114669
+ /* 530 */ 217, 207, 19, 106, 107, 108, 216, 151, 139, 23,
114670
+ /* 540 */ 129, 28, 26, 167, 117, 105, 23, 223, 224, 225,
114671
+ /* 550 */ 110, 175, 176, 167, 77, 165, 50, 51, 168, 169,
114672
+ /* 560 */ 170, 175, 176, 87, 88, 113, 26, 115, 116, 171,
114673
+ /* 570 */ 172, 173, 0, 1, 2, 69, 70, 71, 72, 73,
114674
+ /* 580 */ 74, 75, 76, 77, 78, 79, 80, 81, 162, 83,
114675
+ /* 590 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114676
+ /* 600 */ 19, 151, 98, 217, 23, 37, 130, 131, 23, 23,
114677
+ /* 610 */ 26, 26, 96, 163, 164, 23, 113, 167, 115, 116,
114678
+ /* 620 */ 52, 117, 196, 151, 171, 172, 173, 59, 130, 131,
114679
+ /* 630 */ 232, 50, 51, 129, 208, 209, 16, 121, 156, 167,
114680
+ /* 640 */ 22, 23, 162, 223, 224, 225, 51, 175, 176, 121,
114681
+ /* 650 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114682
+ /* 660 */ 79, 80, 81, 178, 83, 84, 85, 86, 87, 88,
114683
+ /* 670 */ 89, 90, 91, 92, 93, 19, 196, 109, 151, 23,
114684
+ /* 680 */ 96, 61, 151, 63, 23, 232, 68, 26, 151, 168,
114685
+ /* 690 */ 169, 170, 23, 89, 167, 26, 208, 209, 167, 219,
114686
+ /* 700 */ 105, 36, 175, 176, 167, 121, 50, 51, 223, 224,
114687
+ /* 710 */ 225, 229, 175, 176, 178, 233, 247, 248, 114, 239,
114688
+ /* 720 */ 189, 22, 118, 24, 162, 69, 70, 71, 72, 73,
114689
+ /* 730 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114690
+ /* 740 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114691
+ /* 750 */ 19, 151, 26, 151, 167, 24, 145, 146, 196, 223,
114692
+ /* 760 */ 224, 225, 175, 176, 151, 182, 183, 167, 151, 167,
114693
+ /* 770 */ 151, 36, 199, 190, 151, 175, 176, 175, 176, 206,
114694
+ /* 780 */ 167, 50, 51, 221, 167, 136, 167, 138, 175, 176,
114695
+ /* 790 */ 167, 26, 175, 176, 175, 176, 168, 36, 175, 176,
114696
+ /* 800 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114697
+ /* 810 */ 79, 80, 81, 151, 83, 84, 85, 86, 87, 88,
114698
+ /* 820 */ 89, 90, 91, 92, 93, 19, 151, 151, 151, 167,
114699
+ /* 830 */ 151, 151, 151, 151, 162, 207, 23, 175, 176, 26,
114700
+ /* 840 */ 249, 250, 167, 167, 167, 151, 167, 167, 167, 167,
114701
+ /* 850 */ 175, 176, 175, 176, 175, 176, 50, 51, 151, 53,
114702
+ /* 860 */ 22, 167, 192, 193, 33, 189, 192, 193, 196, 189,
114703
+ /* 870 */ 189, 189, 162, 42, 167, 69, 70, 71, 72, 73,
114704
+ /* 880 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114705
+ /* 890 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114706
+ /* 900 */ 19, 151, 195, 151, 167, 151, 196, 162, 151, 215,
114707
+ /* 910 */ 92, 93, 175, 176, 28, 174, 119, 167, 151, 167,
114708
+ /* 920 */ 151, 167, 151, 182, 167, 175, 176, 175, 176, 175,
114709
+ /* 930 */ 176, 50, 51, 23, 167, 23, 167, 40, 167, 22,
114710
+ /* 940 */ 167, 196, 53, 168, 175, 176, 175, 176, 175, 162,
114711
+ /* 950 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114712
+ /* 960 */ 79, 80, 81, 151, 83, 84, 85, 86, 87, 88,
114713
+ /* 970 */ 89, 90, 91, 92, 93, 19, 151, 151, 151, 167,
114714
+ /* 980 */ 151, 151, 207, 196, 30, 218, 22, 175, 176, 1,
114715
+ /* 990 */ 2, 53, 167, 167, 167, 151, 167, 167, 151, 151,
114716
+ /* 1000 */ 175, 176, 175, 176, 175, 176, 50, 51, 221, 23,
114717
+ /* 1010 */ 53, 167, 22, 22, 167, 167, 103, 168, 22, 110,
114718
+ /* 1020 */ 19, 105, 175, 176, 20, 69, 70, 71, 72, 73,
114719
+ /* 1030 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114720
+ /* 1040 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114721
+ /* 1050 */ 19, 151, 151, 151, 167, 151, 207, 24, 44, 215,
114722
+ /* 1060 */ 60, 26, 175, 176, 54, 54, 240, 167, 167, 167,
114723
+ /* 1070 */ 240, 167, 151, 151, 151, 175, 176, 175, 176, 175,
114724
+ /* 1080 */ 176, 50, 51, 139, 151, 22, 105, 119, 167, 167,
114725
+ /* 1090 */ 167, 5, 1, 36, 28, 77, 175, 176, 175, 176,
114726
+ /* 1100 */ 167, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114727
+ /* 1110 */ 79, 80, 81, 151, 83, 84, 85, 86, 87, 88,
114728
+ /* 1120 */ 89, 90, 91, 92, 93, 19, 151, 151, 151, 167,
114729
+ /* 1130 */ 151, 151, 109, 151, 128, 77, 22, 175, 176, 26,
114730
+ /* 1140 */ 218, 240, 167, 167, 167, 151, 167, 167, 151, 167,
114731
+ /* 1150 */ 175, 176, 175, 176, 175, 176, 50, 51, 151, 22,
114732
+ /* 1160 */ 151, 167, 23, 120, 167, 1, 16, 122, 20, 120,
114733
+ /* 1170 */ 109, 195, 175, 176, 167, 195, 167, 71, 72, 73,
114734
+ /* 1180 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114735
+ /* 1190 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114736
+ /* 1200 */ 19, 20, 195, 22, 167, 151, 151, 128, 27, 28,
114737
+ /* 1210 */ 129, 23, 175, 176, 23, 66, 141, 22, 151, 38,
114738
+ /* 1220 */ 151, 167, 167, 19, 20, 151, 22, 151, 151, 175,
114739
+ /* 1230 */ 176, 27, 28, 151, 167, 15, 167, 4, 57, 16,
114740
+ /* 1240 */ 151, 167, 38, 167, 167, 3, 166, 248, 67, 167,
114741
+ /* 1250 */ 195, 175, 176, 181, 181, 150, 167, 175, 176, 251,
114742
+ /* 1260 */ 6, 57, 151, 151, 175, 176, 151, 151, 87, 88,
114743
+ /* 1270 */ 89, 67, 151, 162, 151, 94, 95, 96, 167, 167,
114744
+ /* 1280 */ 99, 251, 167, 167, 152, 151, 175, 176, 167, 151,
114745
+ /* 1290 */ 167, 87, 88, 151, 150, 150, 175, 176, 94, 95,
114746
+ /* 1300 */ 96, 167, 150, 99, 151, 167, 151, 196, 13, 167,
114747
+ /* 1310 */ 195, 130, 131, 132, 133, 134, 135, 152, 195, 160,
114748
+ /* 1320 */ 167, 117, 167, 19, 20, 151, 22, 151, 217, 151,
114749
+ /* 1330 */ 161, 27, 28, 222, 130, 131, 132, 133, 134, 135,
114750
+ /* 1340 */ 151, 167, 38, 167, 151, 167, 19, 20, 195, 22,
114751
+ /* 1350 */ 151, 151, 151, 151, 27, 28, 167, 151, 151, 26,
114752
+ /* 1360 */ 167, 57, 25, 196, 151, 38, 167, 167, 167, 167,
114753
+ /* 1370 */ 151, 67, 151, 167, 167, 117, 201, 151, 125, 151,
114754
+ /* 1380 */ 167, 151, 127, 124, 57, 151, 167, 202, 167, 203,
114755
+ /* 1390 */ 151, 87, 88, 167, 67, 167, 151, 167, 94, 95,
114756
+ /* 1400 */ 96, 167, 151, 99, 123, 126, 167, 204, 136, 227,
114757
+ /* 1410 */ 205, 119, 167, 105, 87, 88, 122, 177, 167, 158,
114758
+ /* 1420 */ 158, 94, 95, 96, 212, 105, 99, 213, 212, 177,
114759
+ /* 1430 */ 213, 213, 185, 48, 130, 131, 132, 133, 134, 135,
114760
+ /* 1440 */ 5, 212, 177, 179, 104, 10, 11, 12, 13, 14,
114761
+ /* 1450 */ 177, 180, 17, 22, 230, 93, 180, 130, 131, 132,
114762
+ /* 1460 */ 133, 134, 135, 185, 177, 230, 177, 32, 177, 34,
114763
+ /* 1470 */ 157, 22, 18, 158, 157, 157, 27, 28, 43, 158,
114764
+ /* 1480 */ 158, 158, 46, 237, 136, 157, 238, 158, 191, 201,
114765
+ /* 1490 */ 69, 56, 191, 58, 220, 22, 157, 62, 18, 201,
114766
+ /* 1500 */ 65, 158, 220, 194, 194, 194, 194, 201, 158, 242,
114767
+ /* 1510 */ 191, 41, 242, 158, 158, 39, 67, 154, 232, 168,
114768
+ /* 1520 */ 245, 228, 198, 178, 183, 200, 168, 211, 232, 168,
114769
+ /* 1530 */ 178, 178, 201, 187, 198, 149, 87, 88, 179, 168,
114770
+ /* 1540 */ 241, 106, 107, 108, 95, 211, 241, 112, 99, 211,
114771
+ /* 1550 */ 201, 197, 117, 193, 210, 188, 184, 184, 184, 175,
114772
+ /* 1560 */ 93, 235, 175, 252, 252, 252, 236, 252, 252, 252,
114773
+ /* 1570 */ 252, 252, 252, 252, 252, 140, 252, 252, 252, 130,
114774
+ /* 1580 */ 131, 132,
114775
+};
114776
+#define YY_SHIFT_USE_DFLT (-82)
114777
+#define YY_SHIFT_COUNT (419)
114778
+#define YY_SHIFT_MIN (-81)
114779
+#define YY_SHIFT_MAX (1480)
113417114780
static const short yy_shift_ofst[] = {
113418
- /* 0 */ 1143, 1188, 1417, 1188, 1287, 1287, 138, 138, -2, -19,
113419
- /* 10 */ 1287, 1287, 1287, 1287, 347, 362, 129, 129, 795, 1165,
113420
- /* 20 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
113421
- /* 30 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
113422
- /* 40 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1310, 1287,
113423
- /* 50 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
113424
- /* 60 */ 1287, 1287, 286, 362, 362, 538, 538, 231, 1253, 55,
113425
- /* 70 */ 721, 647, 573, 499, 425, 351, 277, 203, 869, 869,
113426
- /* 80 */ 869, 869, 869, 869, 869, 869, 869, 869, 869, 869,
113427
- /* 90 */ 869, 869, 869, 943, 869, 1017, 1091, 1091, -69, -45,
113428
- /* 100 */ -45, -45, -45, -45, -1, 24, 245, 362, 362, 362,
113429
- /* 110 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113430
- /* 120 */ 362, 362, 362, 388, 356, 362, 362, 362, 362, 362,
113431
- /* 130 */ 732, 868, 231, 1051, 1471, -70, -70, -70, 1367, 57,
113432
- /* 140 */ 434, 434, 289, 291, 285, 1, 204, 572, 539, 362,
113433
- /* 150 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113434
- /* 160 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113435
- /* 170 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113436
- /* 180 */ 362, 506, 506, 506, 705, 1253, 1253, 1253, -70, -70,
113437
- /* 190 */ -70, 171, 171, 160, 502, 502, 502, 446, 432, 511,
113438
- /* 200 */ 422, 358, 335, -12, -12, -12, -12, 576, 294, -12,
113439
- /* 210 */ -12, 295, 595, 141, 600, 730, 723, 723, 805, 730,
113440
- /* 220 */ 805, 439, 911, 231, 865, 231, 865, 807, 865, 723,
113441
- /* 230 */ 766, 633, 633, 231, 284, 63, 608, 1481, 1308, 1308,
113442
- /* 240 */ 1472, 1472, 1308, 1477, 1427, 1275, 1487, 1487, 1487, 1487,
113443
- /* 250 */ 1308, 1461, 1275, 1477, 1427, 1427, 1275, 1308, 1461, 1355,
113444
- /* 260 */ 1441, 1308, 1308, 1461, 1308, 1461, 1308, 1461, 1442, 1348,
113445
- /* 270 */ 1348, 1348, 1408, 1375, 1375, 1442, 1348, 1357, 1348, 1408,
113446
- /* 280 */ 1348, 1348, 1316, 1331, 1316, 1331, 1316, 1331, 1308, 1308,
113447
- /* 290 */ 1280, 1288, 1289, 1285, 1279, 1275, 1253, 1336, 1346, 1346,
113448
- /* 300 */ 1338, 1338, 1338, 1338, -70, -70, -70, -70, -70, -70,
113449
- /* 310 */ 1013, 467, 612, 84, 179, -28, 870, 410, 761, 760,
113450
- /* 320 */ 667, 650, 531, 220, 361, 331, 125, 127, 97, 1306,
113451
- /* 330 */ 1300, 1270, 1151, 1272, 1203, 1232, 1261, 1244, 1148, 1174,
113452
- /* 340 */ 1139, 1156, 1124, 1220, 1115, 1210, 1233, 1099, 1193, 1184,
113453
- /* 350 */ 1174, 1173, 1029, 1121, 1120, 1085, 1162, 1119, 1037, 1152,
113454
- /* 360 */ 1147, 1129, 1046, 1011, 1093, 1098, 1075, 1061, 1032, 960,
113455
- /* 370 */ 1057, 1031, 1030, 899, 938, 982, 936, 972, 958, 910,
113456
- /* 380 */ 955, 875, 885, 908, 857, 859, 867, 804, 590, 834,
113457
- /* 390 */ 747, 818, 513, 611, 741, 673, 637, 611, 606, 603,
113458
- /* 400 */ 579, 501, 541, 468, 386, 445, 395, 376, 281, 185,
113459
- /* 410 */ 120, 92, 75, 45, 114, 25, 11, 5,
114781
+ /* 0 */ 988, 1204, 1435, 1204, 1304, 1304, 67, 67, 1, -19,
114782
+ /* 10 */ 1304, 1304, 1304, 1304, 427, 81, 131, 131, 806, 1181,
114783
+ /* 20 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304,
114784
+ /* 30 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304,
114785
+ /* 40 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1327, 1304,
114786
+ /* 50 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304,
114787
+ /* 60 */ 1304, 1304, 52, 81, 81, 476, 476, 395, 1258, 56,
114788
+ /* 70 */ 731, 656, 581, 506, 431, 356, 281, 206, 881, 881,
114789
+ /* 80 */ 881, 881, 881, 881, 881, 881, 881, 881, 881, 881,
114790
+ /* 90 */ 881, 881, 881, 956, 881, 1031, 1106, 1106, -69, -45,
114791
+ /* 100 */ -45, -45, -45, -45, 0, 29, -12, 81, 81, 81,
114792
+ /* 110 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114793
+ /* 120 */ 81, 81, 81, 355, 440, 81, 81, 81, 81, 81,
114794
+ /* 130 */ 504, 411, 395, 818, 1467, -82, -82, -82, 1449, 86,
114795
+ /* 140 */ 439, 439, 306, 357, 302, 72, 318, 246, 169, 81,
114796
+ /* 150 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114797
+ /* 160 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114798
+ /* 170 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114799
+ /* 180 */ 81, 81, 315, 315, 315, 572, 1258, 1258, 1258, -82,
114800
+ /* 190 */ -82, -82, 132, 132, 208, 568, 568, 568, 516, 503,
114801
+ /* 200 */ 214, 452, 363, 228, 119, 119, 119, 119, 359, 126,
114802
+ /* 210 */ 119, 119, 584, 293, 604, 106, 11, 288, 288, 513,
114803
+ /* 220 */ 11, 513, 295, 813, 395, 831, 395, 831, 595, 831,
114804
+ /* 230 */ 288, 649, 498, 498, 395, 154, 273, 699, 1476, 1292,
114805
+ /* 240 */ 1292, 1470, 1470, 1292, 1473, 1421, 1255, 1480, 1480, 1480,
114806
+ /* 250 */ 1480, 1292, 1454, 1255, 1473, 1421, 1421, 1255, 1292, 1454,
114807
+ /* 260 */ 1348, 1436, 1292, 1292, 1454, 1292, 1454, 1292, 1454, 1431,
114808
+ /* 270 */ 1320, 1320, 1320, 1385, 1362, 1362, 1431, 1320, 1340, 1320,
114809
+ /* 280 */ 1385, 1320, 1320, 1294, 1308, 1294, 1308, 1294, 1308, 1292,
114810
+ /* 290 */ 1292, 1272, 1279, 1281, 1253, 1259, 1255, 1258, 1337, 1333,
114811
+ /* 300 */ 1295, 1295, 1254, 1254, 1254, 1254, -82, -82, -82, -82,
114812
+ /* 310 */ -82, -82, 339, 399, 618, 326, 620, -81, 669, 477,
114813
+ /* 320 */ 661, 585, 377, 280, 244, 232, 25, -1, 373, 227,
114814
+ /* 330 */ 215, 1233, 1242, 1195, 1075, 1220, 1149, 1223, 1191, 1188,
114815
+ /* 340 */ 1081, 1113, 1079, 1061, 1049, 1148, 1045, 1150, 1164, 1043,
114816
+ /* 350 */ 1139, 1137, 1113, 1114, 1006, 1058, 1018, 1023, 1066, 1057,
114817
+ /* 360 */ 968, 1091, 1086, 1063, 981, 944, 1011, 1035, 1010, 1000,
114818
+ /* 370 */ 1014, 916, 1033, 1004, 1001, 909, 913, 996, 957, 991,
114819
+ /* 380 */ 990, 986, 964, 938, 954, 917, 889, 897, 912, 910,
114820
+ /* 390 */ 797, 886, 761, 838, 528, 726, 735, 765, 665, 726,
114821
+ /* 400 */ 592, 586, 540, 523, 491, 487, 435, 401, 397, 387,
114822
+ /* 410 */ 249, 216, 185, 127, 110, 51, 82, 143, 15, 48,
113460114823
};
113461
-#define YY_REDUCE_USE_DFLT (-169)
113462
-#define YY_REDUCE_COUNT (309)
113463
-#define YY_REDUCE_MIN (-168)
113464
-#define YY_REDUCE_MAX (1397)
114824
+#define YY_REDUCE_USE_DFLT (-143)
114825
+#define YY_REDUCE_COUNT (311)
114826
+#define YY_REDUCE_MIN (-142)
114827
+#define YY_REDUCE_MAX (1387)
113465114828
static const short yy_reduce_ofst[] = {
113466
- /* 0 */ -141, 90, 1095, 222, 158, 156, 19, 17, 10, -104,
113467
- /* 10 */ 378, 316, 311, 12, 180, 249, 598, 464, 397, 1181,
113468
- /* 20 */ 1177, 1175, 1128, 1106, 1096, 1054, 1038, 974, 964, 962,
113469
- /* 30 */ 948, 905, 903, 900, 887, 874, 832, 826, 816, 813,
113470
- /* 40 */ 800, 758, 755, 752, 742, 739, 726, 685, 681, 668,
113471
- /* 50 */ 665, 652, 607, 604, 594, 591, 578, 530, 528, 526,
113472
- /* 60 */ 385, 18, 477, 466, 519, 444, 350, 435, 405, 488,
113473
- /* 70 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488,
113474
- /* 80 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488,
113475
- /* 90 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488,
113476
- /* 100 */ 488, 488, 488, 488, 488, 488, 488, 1040, 678, 1036,
113477
- /* 110 */ 1007, 967, 966, 965, 845, 686, 610, 684, 317, 672,
113478
- /* 120 */ 893, 327, 623, 522, -7, 820, 814, 157, 154, 101,
113479
- /* 130 */ 702, 494, 580, 488, 488, 488, 488, 488, 614, 586,
113480
- /* 140 */ 935, 892, 968, 1245, 1242, 1234, 1225, 798, 798, 1222,
113481
- /* 150 */ 1221, 1218, 1214, 1213, 1212, 1202, 1195, 1191, 1161, 1158,
113482
- /* 160 */ 1140, 1135, 1123, 1112, 1107, 1100, 1080, 1074, 1073, 1072,
113483
- /* 170 */ 1070, 1067, 1048, 1044, 969, 968, 907, 906, 904, 894,
113484
- /* 180 */ 833, 837, 836, 340, 827, 815, 775, 68, 722, 646,
113485
- /* 190 */ -168, 1389, 1381, 1371, 1379, 1373, 1370, 1343, 1352, 1369,
113486
- /* 200 */ 1352, 1352, 1352, 1352, 1352, 1352, 1352, 1325, 1320, 1352,
113487
- /* 210 */ 1352, 1343, 1380, 1353, 1397, 1351, 1339, 1334, 1319, 1341,
113488
- /* 220 */ 1303, 1364, 1359, 1368, 1362, 1366, 1360, 1350, 1354, 1318,
113489
- /* 230 */ 1313, 1307, 1305, 1363, 1328, 1324, 1372, 1278, 1361, 1358,
113490
- /* 240 */ 1277, 1276, 1356, 1296, 1322, 1309, 1317, 1315, 1314, 1312,
113491
- /* 250 */ 1345, 1347, 1302, 1292, 1311, 1304, 1293, 1337, 1335, 1252,
113492
- /* 260 */ 1248, 1332, 1330, 1329, 1327, 1326, 1323, 1321, 1297, 1301,
113493
- /* 270 */ 1295, 1294, 1290, 1243, 1240, 1284, 1291, 1286, 1283, 1274,
113494
- /* 280 */ 1281, 1271, 1238, 1241, 1236, 1235, 1227, 1226, 1267, 1266,
113495
- /* 290 */ 1189, 1229, 1223, 1211, 1206, 1201, 1197, 1239, 1237, 1219,
113496
- /* 300 */ 1216, 1209, 1208, 1185, 1089, 1086, 1087, 1137, 1136, 1164,
114829
+ /* 0 */ -142, 1111, 92, 151, 241, 161, 150, 93, 85, 324,
114830
+ /* 10 */ 386, 313, 320, 229, -6, 310, 536, 485, -72, 1121,
114831
+ /* 20 */ 1089, 1082, 1076, 1054, 1037, 997, 979, 977, 975, 962,
114832
+ /* 30 */ 923, 921, 904, 902, 900, 887, 847, 829, 827, 825,
114833
+ /* 40 */ 812, 771, 769, 754, 752, 750, 737, 679, 677, 675,
114834
+ /* 50 */ 662, 623, 619, 617, 613, 602, 600, 587, 537, 527,
114835
+ /* 60 */ 472, 376, 480, 450, 226, 453, 398, 390, 426, 420,
114836
+ /* 70 */ 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
114837
+ /* 80 */ 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
114838
+ /* 90 */ 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
114839
+ /* 100 */ 420, 420, 420, 420, 420, 420, 420, 1153, 922, 1123,
114840
+ /* 110 */ 1115, 1055, 1007, 980, 976, 901, 844, 830, 767, 826,
114841
+ /* 120 */ 682, 694, 707, 482, 583, 681, 680, 676, 531, 27,
114842
+ /* 130 */ 787, 562, 521, 420, 420, 420, 420, 420, 773, 741,
114843
+ /* 140 */ 674, 670, 1067, 1251, 1245, 1239, 1234, 591, 591, 1230,
114844
+ /* 150 */ 1228, 1226, 1221, 1219, 1213, 1207, 1206, 1202, 1201, 1200,
114845
+ /* 160 */ 1199, 1193, 1189, 1178, 1176, 1174, 1155, 1142, 1138, 1134,
114846
+ /* 170 */ 1116, 1112, 1077, 1074, 1069, 1067, 1009, 994, 982, 933,
114847
+ /* 180 */ 848, 757, 849, 775, 628, 611, 745, 710, 672, 469,
114848
+ /* 190 */ 488, 573, 1387, 1384, 1367, 1374, 1373, 1372, 1344, 1354,
114849
+ /* 200 */ 1360, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1330, 1326,
114850
+ /* 210 */ 1354, 1354, 1344, 1371, 1336, 1386, 1349, 1338, 1334, 1305,
114851
+ /* 220 */ 1331, 1299, 1359, 1346, 1361, 1353, 1358, 1352, 1341, 1345,
114852
+ /* 230 */ 1316, 1293, 1296, 1286, 1351, 1325, 1324, 1363, 1275, 1356,
114853
+ /* 240 */ 1355, 1270, 1267, 1350, 1282, 1319, 1306, 1312, 1311, 1310,
114854
+ /* 250 */ 1309, 1343, 1339, 1298, 1274, 1301, 1297, 1288, 1329, 1328,
114855
+ /* 260 */ 1248, 1246, 1323, 1322, 1318, 1321, 1317, 1315, 1313, 1276,
114856
+ /* 270 */ 1291, 1289, 1287, 1278, 1235, 1224, 1271, 1273, 1264, 1265,
114857
+ /* 280 */ 1247, 1252, 1240, 1218, 1229, 1217, 1216, 1214, 1212, 1262,
114858
+ /* 290 */ 1261, 1182, 1205, 1203, 1186, 1185, 1175, 1167, 1169, 1159,
114859
+ /* 300 */ 1165, 1132, 1152, 1145, 1144, 1105, 1030, 1008, 999, 1073,
114860
+ /* 310 */ 1072, 1080,
113497114861
};
113498114862
static const YYACTIONTYPE yy_default[] = {
113499
- /* 0 */ 633, 867, 955, 955, 867, 867, 955, 955, 955, 757,
113500
- /* 10 */ 955, 955, 955, 865, 955, 955, 785, 785, 929, 955,
113501
- /* 20 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113502
- /* 30 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113503
- /* 40 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113504
- /* 50 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113505
- /* 60 */ 955, 955, 955, 955, 955, 955, 955, 672, 761, 791,
113506
- /* 70 */ 955, 955, 955, 955, 955, 955, 955, 955, 928, 930,
113507
- /* 80 */ 799, 798, 908, 772, 796, 789, 793, 868, 861, 862,
113508
- /* 90 */ 860, 864, 869, 955, 792, 828, 845, 827, 839, 844,
113509
- /* 100 */ 851, 843, 840, 830, 829, 831, 832, 955, 955, 955,
113510
- /* 110 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113511
- /* 120 */ 955, 955, 955, 659, 726, 955, 955, 955, 955, 955,
113512
- /* 130 */ 955, 955, 955, 833, 834, 848, 847, 846, 955, 664,
113513
- /* 140 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113514
- /* 150 */ 935, 933, 955, 880, 955, 955, 955, 955, 955, 955,
113515
- /* 160 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113516
- /* 170 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113517
- /* 180 */ 639, 757, 757, 757, 633, 955, 955, 955, 947, 761,
113518
- /* 190 */ 751, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113519
- /* 200 */ 955, 955, 955, 801, 740, 918, 920, 955, 901, 738,
113520
- /* 210 */ 661, 759, 674, 749, 641, 795, 774, 774, 913, 795,
113521
- /* 220 */ 913, 697, 720, 955, 785, 955, 785, 694, 785, 774,
113522
- /* 230 */ 863, 955, 955, 955, 758, 749, 955, 940, 765, 765,
113523
- /* 240 */ 932, 932, 765, 807, 730, 795, 737, 737, 737, 737,
113524
- /* 250 */ 765, 656, 795, 807, 730, 730, 795, 765, 656, 907,
113525
- /* 260 */ 905, 765, 765, 656, 765, 656, 765, 656, 873, 728,
113526
- /* 270 */ 728, 728, 712, 877, 877, 873, 728, 697, 728, 712,
113527
- /* 280 */ 728, 728, 778, 773, 778, 773, 778, 773, 765, 765,
113528
- /* 290 */ 955, 790, 779, 788, 786, 795, 955, 715, 649, 649,
113529
- /* 300 */ 638, 638, 638, 638, 952, 952, 947, 699, 699, 682,
113530
- /* 310 */ 955, 955, 955, 955, 955, 955, 955, 882, 955, 955,
113531
- /* 320 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113532
- /* 330 */ 634, 942, 955, 955, 939, 955, 955, 955, 955, 800,
113533
- /* 340 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113534
- /* 350 */ 917, 955, 955, 955, 955, 955, 955, 955, 911, 955,
113535
- /* 360 */ 955, 955, 955, 955, 955, 904, 903, 955, 955, 955,
113536
- /* 370 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113537
- /* 380 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113538
- /* 390 */ 955, 955, 955, 787, 955, 780, 955, 866, 955, 955,
113539
- /* 400 */ 955, 955, 955, 955, 955, 955, 955, 955, 743, 816,
113540
- /* 410 */ 955, 815, 819, 814, 666, 955, 647, 955, 630, 635,
113541
- /* 420 */ 951, 954, 953, 950, 949, 948, 943, 941, 938, 937,
113542
- /* 430 */ 936, 934, 931, 927, 886, 884, 891, 890, 889, 888,
113543
- /* 440 */ 887, 885, 883, 881, 802, 797, 794, 926, 879, 739,
113544
- /* 450 */ 736, 735, 655, 944, 910, 919, 806, 805, 808, 916,
113545
- /* 460 */ 915, 914, 912, 909, 896, 804, 803, 731, 871, 870,
113546
- /* 470 */ 658, 900, 899, 898, 902, 906, 897, 767, 657, 654,
113547
- /* 480 */ 663, 718, 719, 727, 725, 724, 723, 722, 721, 717,
113548
- /* 490 */ 665, 673, 711, 696, 695, 876, 878, 875, 874, 704,
113549
- /* 500 */ 703, 709, 708, 707, 706, 705, 702, 701, 700, 693,
113550
- /* 510 */ 692, 698, 691, 714, 713, 710, 690, 734, 733, 732,
113551
- /* 520 */ 729, 689, 688, 687, 819, 686, 685, 825, 824, 812,
113552
- /* 530 */ 855, 754, 753, 752, 764, 763, 776, 775, 810, 809,
113553
- /* 540 */ 777, 762, 756, 755, 771, 770, 769, 768, 760, 750,
113554
- /* 550 */ 782, 784, 783, 781, 857, 766, 854, 925, 924, 923,
113555
- /* 560 */ 922, 921, 859, 858, 826, 823, 677, 678, 894, 893,
113556
- /* 570 */ 895, 892, 680, 679, 676, 675, 856, 745, 744, 852,
113557
- /* 580 */ 849, 841, 837, 853, 850, 842, 838, 836, 835, 821,
113558
- /* 590 */ 820, 818, 817, 813, 822, 668, 746, 742, 741, 811,
113559
- /* 600 */ 748, 747, 684, 683, 681, 662, 660, 653, 651, 650,
113560
- /* 610 */ 652, 648, 646, 645, 644, 643, 642, 671, 670, 669,
113561
- /* 620 */ 667, 666, 640, 637, 636, 632, 631, 629,
114863
+ /* 0 */ 636, 872, 960, 960, 872, 872, 960, 960, 960, 762,
114864
+ /* 10 */ 960, 960, 960, 870, 960, 960, 790, 790, 934, 960,
114865
+ /* 20 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114866
+ /* 30 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114867
+ /* 40 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114868
+ /* 50 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114869
+ /* 60 */ 960, 960, 960, 960, 960, 960, 960, 677, 766, 796,
114870
+ /* 70 */ 960, 960, 960, 960, 960, 960, 960, 960, 933, 935,
114871
+ /* 80 */ 804, 803, 913, 777, 801, 794, 798, 873, 866, 867,
114872
+ /* 90 */ 865, 869, 874, 960, 797, 833, 850, 832, 844, 849,
114873
+ /* 100 */ 856, 848, 845, 835, 834, 836, 837, 960, 960, 960,
114874
+ /* 110 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114875
+ /* 120 */ 960, 960, 960, 662, 731, 960, 960, 960, 960, 960,
114876
+ /* 130 */ 960, 960, 960, 838, 839, 853, 852, 851, 960, 669,
114877
+ /* 140 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114878
+ /* 150 */ 940, 938, 960, 885, 960, 960, 960, 960, 960, 960,
114879
+ /* 160 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114880
+ /* 170 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114881
+ /* 180 */ 960, 642, 762, 762, 762, 636, 960, 960, 960, 952,
114882
+ /* 190 */ 766, 756, 960, 960, 960, 960, 960, 960, 960, 960,
114883
+ /* 200 */ 960, 960, 960, 960, 806, 745, 923, 925, 960, 906,
114884
+ /* 210 */ 743, 664, 764, 679, 754, 644, 800, 779, 779, 918,
114885
+ /* 220 */ 800, 918, 702, 725, 960, 790, 960, 790, 699, 790,
114886
+ /* 230 */ 779, 868, 960, 960, 960, 763, 754, 960, 945, 770,
114887
+ /* 240 */ 770, 937, 937, 770, 812, 735, 800, 742, 742, 742,
114888
+ /* 250 */ 742, 770, 659, 800, 812, 735, 735, 800, 770, 659,
114889
+ /* 260 */ 912, 910, 770, 770, 659, 770, 659, 770, 659, 878,
114890
+ /* 270 */ 733, 733, 733, 717, 882, 882, 878, 733, 702, 733,
114891
+ /* 280 */ 717, 733, 733, 783, 778, 783, 778, 783, 778, 770,
114892
+ /* 290 */ 770, 960, 795, 784, 793, 791, 800, 960, 665, 720,
114893
+ /* 300 */ 652, 652, 641, 641, 641, 641, 957, 957, 952, 704,
114894
+ /* 310 */ 704, 687, 960, 960, 960, 960, 960, 960, 960, 887,
114895
+ /* 320 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114896
+ /* 330 */ 960, 960, 637, 947, 960, 960, 944, 960, 960, 960,
114897
+ /* 340 */ 960, 805, 960, 960, 960, 960, 960, 960, 960, 960,
114898
+ /* 350 */ 960, 960, 922, 960, 960, 960, 960, 960, 960, 960,
114899
+ /* 360 */ 916, 960, 960, 960, 960, 960, 960, 909, 908, 960,
114900
+ /* 370 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114901
+ /* 380 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114902
+ /* 390 */ 960, 960, 960, 960, 960, 792, 960, 785, 960, 871,
114903
+ /* 400 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114904
+ /* 410 */ 748, 821, 960, 820, 824, 819, 671, 960, 650, 960,
114905
+ /* 420 */ 633, 638, 956, 959, 958, 955, 954, 953, 948, 946,
114906
+ /* 430 */ 943, 942, 941, 939, 936, 932, 891, 889, 896, 895,
114907
+ /* 440 */ 894, 893, 892, 890, 888, 886, 807, 802, 799, 931,
114908
+ /* 450 */ 884, 744, 741, 740, 658, 949, 915, 924, 811, 810,
114909
+ /* 460 */ 813, 921, 920, 919, 917, 914, 901, 809, 808, 736,
114910
+ /* 470 */ 876, 875, 661, 905, 904, 903, 907, 911, 902, 772,
114911
+ /* 480 */ 660, 657, 668, 723, 724, 732, 730, 729, 728, 727,
114912
+ /* 490 */ 726, 722, 670, 678, 716, 701, 700, 881, 883, 880,
114913
+ /* 500 */ 879, 709, 708, 714, 713, 712, 711, 710, 707, 706,
114914
+ /* 510 */ 705, 698, 697, 703, 696, 719, 718, 715, 695, 739,
114915
+ /* 520 */ 738, 737, 734, 694, 693, 692, 824, 691, 690, 830,
114916
+ /* 530 */ 829, 817, 860, 759, 758, 757, 769, 768, 781, 780,
114917
+ /* 540 */ 815, 814, 782, 767, 761, 760, 776, 775, 774, 773,
114918
+ /* 550 */ 765, 755, 787, 789, 788, 786, 862, 771, 859, 930,
114919
+ /* 560 */ 929, 928, 927, 926, 864, 863, 831, 828, 682, 683,
114920
+ /* 570 */ 899, 898, 900, 897, 685, 684, 681, 680, 861, 750,
114921
+ /* 580 */ 749, 857, 854, 846, 842, 858, 855, 847, 843, 841,
114922
+ /* 590 */ 840, 826, 825, 823, 822, 818, 827, 673, 751, 747,
114923
+ /* 600 */ 746, 816, 753, 752, 689, 688, 686, 667, 666, 663,
114924
+ /* 610 */ 656, 654, 653, 655, 651, 649, 648, 647, 646, 645,
114925
+ /* 620 */ 676, 675, 674, 672, 671, 643, 640, 639, 635, 634,
114926
+ /* 630 */ 632,
113562114927
};
113563114928
113564114929
/* The next table maps tokens into fallback tokens. If a construct
113565114930
** like the following:
113566114931
**
@@ -113573,75 +114938,76 @@
113573114938
*/
113574114939
#ifdef YYFALLBACK
113575114940
static const YYCODETYPE yyFallback[] = {
113576114941
0, /* $ => nothing */
113577114942
0, /* SEMI => nothing */
113578
- 26, /* EXPLAIN => ID */
113579
- 26, /* QUERY => ID */
113580
- 26, /* PLAN => ID */
113581
- 26, /* BEGIN => ID */
114943
+ 27, /* EXPLAIN => ID */
114944
+ 27, /* QUERY => ID */
114945
+ 27, /* PLAN => ID */
114946
+ 27, /* BEGIN => ID */
113582114947
0, /* TRANSACTION => nothing */
113583
- 26, /* DEFERRED => ID */
113584
- 26, /* IMMEDIATE => ID */
113585
- 26, /* EXCLUSIVE => ID */
114948
+ 27, /* DEFERRED => ID */
114949
+ 27, /* IMMEDIATE => ID */
114950
+ 27, /* EXCLUSIVE => ID */
113586114951
0, /* COMMIT => nothing */
113587
- 26, /* END => ID */
113588
- 26, /* ROLLBACK => ID */
113589
- 26, /* SAVEPOINT => ID */
113590
- 26, /* RELEASE => ID */
114952
+ 27, /* END => ID */
114953
+ 27, /* ROLLBACK => ID */
114954
+ 27, /* SAVEPOINT => ID */
114955
+ 27, /* RELEASE => ID */
113591114956
0, /* TO => nothing */
113592114957
0, /* TABLE => nothing */
113593114958
0, /* CREATE => nothing */
113594
- 26, /* IF => ID */
114959
+ 27, /* IF => ID */
113595114960
0, /* NOT => nothing */
113596114961
0, /* EXISTS => nothing */
113597
- 26, /* TEMP => ID */
114962
+ 27, /* TEMP => ID */
113598114963
0, /* LP => nothing */
113599114964
0, /* RP => nothing */
113600114965
0, /* AS => nothing */
114966
+ 27, /* WITHOUT => ID */
113601114967
0, /* COMMA => nothing */
113602114968
0, /* ID => nothing */
113603114969
0, /* INDEXED => nothing */
113604
- 26, /* ABORT => ID */
113605
- 26, /* ACTION => ID */
113606
- 26, /* AFTER => ID */
113607
- 26, /* ANALYZE => ID */
113608
- 26, /* ASC => ID */
113609
- 26, /* ATTACH => ID */
113610
- 26, /* BEFORE => ID */
113611
- 26, /* BY => ID */
113612
- 26, /* CASCADE => ID */
113613
- 26, /* CAST => ID */
113614
- 26, /* COLUMNKW => ID */
113615
- 26, /* CONFLICT => ID */
113616
- 26, /* DATABASE => ID */
113617
- 26, /* DESC => ID */
113618
- 26, /* DETACH => ID */
113619
- 26, /* EACH => ID */
113620
- 26, /* FAIL => ID */
113621
- 26, /* FOR => ID */
113622
- 26, /* IGNORE => ID */
113623
- 26, /* INITIALLY => ID */
113624
- 26, /* INSTEAD => ID */
113625
- 26, /* LIKE_KW => ID */
113626
- 26, /* MATCH => ID */
113627
- 26, /* NO => ID */
113628
- 26, /* KEY => ID */
113629
- 26, /* OF => ID */
113630
- 26, /* OFFSET => ID */
113631
- 26, /* PRAGMA => ID */
113632
- 26, /* RAISE => ID */
113633
- 26, /* REPLACE => ID */
113634
- 26, /* RESTRICT => ID */
113635
- 26, /* ROW => ID */
113636
- 26, /* TRIGGER => ID */
113637
- 26, /* VACUUM => ID */
113638
- 26, /* VIEW => ID */
113639
- 26, /* VIRTUAL => ID */
113640
- 26, /* REINDEX => ID */
113641
- 26, /* RENAME => ID */
113642
- 26, /* CTIME_KW => ID */
114970
+ 27, /* ABORT => ID */
114971
+ 27, /* ACTION => ID */
114972
+ 27, /* AFTER => ID */
114973
+ 27, /* ANALYZE => ID */
114974
+ 27, /* ASC => ID */
114975
+ 27, /* ATTACH => ID */
114976
+ 27, /* BEFORE => ID */
114977
+ 27, /* BY => ID */
114978
+ 27, /* CASCADE => ID */
114979
+ 27, /* CAST => ID */
114980
+ 27, /* COLUMNKW => ID */
114981
+ 27, /* CONFLICT => ID */
114982
+ 27, /* DATABASE => ID */
114983
+ 27, /* DESC => ID */
114984
+ 27, /* DETACH => ID */
114985
+ 27, /* EACH => ID */
114986
+ 27, /* FAIL => ID */
114987
+ 27, /* FOR => ID */
114988
+ 27, /* IGNORE => ID */
114989
+ 27, /* INITIALLY => ID */
114990
+ 27, /* INSTEAD => ID */
114991
+ 27, /* LIKE_KW => ID */
114992
+ 27, /* MATCH => ID */
114993
+ 27, /* NO => ID */
114994
+ 27, /* KEY => ID */
114995
+ 27, /* OF => ID */
114996
+ 27, /* OFFSET => ID */
114997
+ 27, /* PRAGMA => ID */
114998
+ 27, /* RAISE => ID */
114999
+ 27, /* REPLACE => ID */
115000
+ 27, /* RESTRICT => ID */
115001
+ 27, /* ROW => ID */
115002
+ 27, /* TRIGGER => ID */
115003
+ 27, /* VACUUM => ID */
115004
+ 27, /* VIEW => ID */
115005
+ 27, /* VIRTUAL => ID */
115006
+ 27, /* REINDEX => ID */
115007
+ 27, /* RENAME => ID */
115008
+ 27, /* CTIME_KW => ID */
113643115009
};
113644115010
#endif /* YYFALLBACK */
113645115011
113646115012
/* The following structure represents a single element of the
113647115013
** parser's stack. Information stored includes:
@@ -113722,67 +115088,67 @@
113722115088
"PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
113723115089
"IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
113724115090
"ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
113725115091
"TABLE", "CREATE", "IF", "NOT",
113726115092
"EXISTS", "TEMP", "LP", "RP",
113727
- "AS", "COMMA", "ID", "INDEXED",
113728
- "ABORT", "ACTION", "AFTER", "ANALYZE",
113729
- "ASC", "ATTACH", "BEFORE", "BY",
113730
- "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
113731
- "DATABASE", "DESC", "DETACH", "EACH",
113732
- "FAIL", "FOR", "IGNORE", "INITIALLY",
113733
- "INSTEAD", "LIKE_KW", "MATCH", "NO",
113734
- "KEY", "OF", "OFFSET", "PRAGMA",
113735
- "RAISE", "REPLACE", "RESTRICT", "ROW",
113736
- "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
113737
- "REINDEX", "RENAME", "CTIME_KW", "ANY",
113738
- "OR", "AND", "IS", "BETWEEN",
113739
- "IN", "ISNULL", "NOTNULL", "NE",
113740
- "EQ", "GT", "LE", "LT",
113741
- "GE", "ESCAPE", "BITAND", "BITOR",
113742
- "LSHIFT", "RSHIFT", "PLUS", "MINUS",
113743
- "STAR", "SLASH", "REM", "CONCAT",
113744
- "COLLATE", "BITNOT", "STRING", "JOIN_KW",
113745
- "CONSTRAINT", "DEFAULT", "NULL", "PRIMARY",
113746
- "UNIQUE", "CHECK", "REFERENCES", "AUTOINCR",
113747
- "ON", "INSERT", "DELETE", "UPDATE",
113748
- "SET", "DEFERRABLE", "FOREIGN", "DROP",
113749
- "UNION", "ALL", "EXCEPT", "INTERSECT",
113750
- "SELECT", "DISTINCT", "DOT", "FROM",
113751
- "JOIN", "USING", "ORDER", "GROUP",
113752
- "HAVING", "LIMIT", "WHERE", "INTO",
113753
- "VALUES", "INTEGER", "FLOAT", "BLOB",
113754
- "REGISTER", "VARIABLE", "CASE", "WHEN",
113755
- "THEN", "ELSE", "INDEX", "ALTER",
113756
- "ADD", "error", "input", "cmdlist",
113757
- "ecmd", "explain", "cmdx", "cmd",
113758
- "transtype", "trans_opt", "nm", "savepoint_opt",
113759
- "create_table", "create_table_args", "createkw", "temp",
113760
- "ifnotexists", "dbnm", "columnlist", "conslist_opt",
113761
- "select", "column", "columnid", "type",
113762
- "carglist", "id", "ids", "typetoken",
113763
- "typename", "signed", "plus_num", "minus_num",
113764
- "ccons", "term", "expr", "onconf",
113765
- "sortorder", "autoinc", "idxlist_opt", "refargs",
113766
- "defer_subclause", "refarg", "refact", "init_deferred_pred_opt",
113767
- "conslist", "tconscomma", "tcons", "idxlist",
113768
- "defer_subclause_opt", "orconf", "resolvetype", "raisetype",
113769
- "ifexists", "fullname", "oneselect", "multiselect_op",
113770
- "distinct", "selcollist", "from", "where_opt",
113771
- "groupby_opt", "having_opt", "orderby_opt", "limit_opt",
113772
- "sclp", "as", "seltablist", "stl_prefix",
113773
- "joinop", "indexed_opt", "on_opt", "using_opt",
113774
- "joinop2", "inscollist", "sortlist", "nexprlist",
113775
- "setlist", "insert_cmd", "inscollist_opt", "valuelist",
113776
- "exprlist", "likeop", "between_op", "in_op",
113777
- "case_operand", "case_exprlist", "case_else", "uniqueflag",
113778
- "collate", "nmnum", "number", "trigger_decl",
113779
- "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause",
113780
- "when_clause", "trigger_cmd", "trnm", "tridxby",
113781
- "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt",
113782
- "create_vtab", "vtabarglist", "vtabarg", "vtabargtoken",
113783
- "lp", "anylist",
115093
+ "AS", "WITHOUT", "COMMA", "ID",
115094
+ "INDEXED", "ABORT", "ACTION", "AFTER",
115095
+ "ANALYZE", "ASC", "ATTACH", "BEFORE",
115096
+ "BY", "CASCADE", "CAST", "COLUMNKW",
115097
+ "CONFLICT", "DATABASE", "DESC", "DETACH",
115098
+ "EACH", "FAIL", "FOR", "IGNORE",
115099
+ "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
115100
+ "NO", "KEY", "OF", "OFFSET",
115101
+ "PRAGMA", "RAISE", "REPLACE", "RESTRICT",
115102
+ "ROW", "TRIGGER", "VACUUM", "VIEW",
115103
+ "VIRTUAL", "REINDEX", "RENAME", "CTIME_KW",
115104
+ "ANY", "OR", "AND", "IS",
115105
+ "BETWEEN", "IN", "ISNULL", "NOTNULL",
115106
+ "NE", "EQ", "GT", "LE",
115107
+ "LT", "GE", "ESCAPE", "BITAND",
115108
+ "BITOR", "LSHIFT", "RSHIFT", "PLUS",
115109
+ "MINUS", "STAR", "SLASH", "REM",
115110
+ "CONCAT", "COLLATE", "BITNOT", "STRING",
115111
+ "JOIN_KW", "CONSTRAINT", "DEFAULT", "NULL",
115112
+ "PRIMARY", "UNIQUE", "CHECK", "REFERENCES",
115113
+ "AUTOINCR", "ON", "INSERT", "DELETE",
115114
+ "UPDATE", "SET", "DEFERRABLE", "FOREIGN",
115115
+ "DROP", "UNION", "ALL", "EXCEPT",
115116
+ "INTERSECT", "SELECT", "DISTINCT", "DOT",
115117
+ "FROM", "JOIN", "USING", "ORDER",
115118
+ "GROUP", "HAVING", "LIMIT", "WHERE",
115119
+ "INTO", "VALUES", "INTEGER", "FLOAT",
115120
+ "BLOB", "REGISTER", "VARIABLE", "CASE",
115121
+ "WHEN", "THEN", "ELSE", "INDEX",
115122
+ "ALTER", "ADD", "error", "input",
115123
+ "cmdlist", "ecmd", "explain", "cmdx",
115124
+ "cmd", "transtype", "trans_opt", "nm",
115125
+ "savepoint_opt", "create_table", "create_table_args", "createkw",
115126
+ "temp", "ifnotexists", "dbnm", "columnlist",
115127
+ "conslist_opt", "table_options", "select", "column",
115128
+ "columnid", "type", "carglist", "id",
115129
+ "ids", "typetoken", "typename", "signed",
115130
+ "plus_num", "minus_num", "ccons", "term",
115131
+ "expr", "onconf", "sortorder", "autoinc",
115132
+ "idxlist_opt", "refargs", "defer_subclause", "refarg",
115133
+ "refact", "init_deferred_pred_opt", "conslist", "tconscomma",
115134
+ "tcons", "idxlist", "defer_subclause_opt", "orconf",
115135
+ "resolvetype", "raisetype", "ifexists", "fullname",
115136
+ "oneselect", "multiselect_op", "distinct", "selcollist",
115137
+ "from", "where_opt", "groupby_opt", "having_opt",
115138
+ "orderby_opt", "limit_opt", "sclp", "as",
115139
+ "seltablist", "stl_prefix", "joinop", "indexed_opt",
115140
+ "on_opt", "using_opt", "joinop2", "idlist",
115141
+ "sortlist", "nexprlist", "setlist", "insert_cmd",
115142
+ "inscollist_opt", "valuelist", "exprlist", "likeop",
115143
+ "between_op", "in_op", "case_operand", "case_exprlist",
115144
+ "case_else", "uniqueflag", "collate", "nmnum",
115145
+ "number", "trigger_decl", "trigger_cmd_list", "trigger_time",
115146
+ "trigger_event", "foreach_clause", "when_clause", "trigger_cmd",
115147
+ "trnm", "tridxby", "database_kw_opt", "key_opt",
115148
+ "add_column_fullname", "kwcolumn_opt", "create_vtab", "vtabarglist",
115149
+ "vtabarg", "vtabargtoken", "lp", "anylist",
113784115150
};
113785115151
#endif /* NDEBUG */
113786115152
113787115153
#ifndef NDEBUG
113788115154
/* For tracing reduce actions, the names of all rules are required.
@@ -113818,305 +115184,307 @@
113818115184
/* 27 */ "createkw ::= CREATE",
113819115185
/* 28 */ "ifnotexists ::=",
113820115186
/* 29 */ "ifnotexists ::= IF NOT EXISTS",
113821115187
/* 30 */ "temp ::= TEMP",
113822115188
/* 31 */ "temp ::=",
113823
- /* 32 */ "create_table_args ::= LP columnlist conslist_opt RP",
115189
+ /* 32 */ "create_table_args ::= LP columnlist conslist_opt RP table_options",
113824115190
/* 33 */ "create_table_args ::= AS select",
113825
- /* 34 */ "columnlist ::= columnlist COMMA column",
113826
- /* 35 */ "columnlist ::= column",
113827
- /* 36 */ "column ::= columnid type carglist",
113828
- /* 37 */ "columnid ::= nm",
113829
- /* 38 */ "id ::= ID",
113830
- /* 39 */ "id ::= INDEXED",
113831
- /* 40 */ "ids ::= ID|STRING",
113832
- /* 41 */ "nm ::= id",
113833
- /* 42 */ "nm ::= STRING",
113834
- /* 43 */ "nm ::= JOIN_KW",
113835
- /* 44 */ "type ::=",
113836
- /* 45 */ "type ::= typetoken",
113837
- /* 46 */ "typetoken ::= typename",
113838
- /* 47 */ "typetoken ::= typename LP signed RP",
113839
- /* 48 */ "typetoken ::= typename LP signed COMMA signed RP",
113840
- /* 49 */ "typename ::= ids",
113841
- /* 50 */ "typename ::= typename ids",
113842
- /* 51 */ "signed ::= plus_num",
113843
- /* 52 */ "signed ::= minus_num",
113844
- /* 53 */ "carglist ::= carglist ccons",
113845
- /* 54 */ "carglist ::=",
113846
- /* 55 */ "ccons ::= CONSTRAINT nm",
113847
- /* 56 */ "ccons ::= DEFAULT term",
113848
- /* 57 */ "ccons ::= DEFAULT LP expr RP",
113849
- /* 58 */ "ccons ::= DEFAULT PLUS term",
113850
- /* 59 */ "ccons ::= DEFAULT MINUS term",
113851
- /* 60 */ "ccons ::= DEFAULT id",
113852
- /* 61 */ "ccons ::= NULL onconf",
113853
- /* 62 */ "ccons ::= NOT NULL onconf",
113854
- /* 63 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
113855
- /* 64 */ "ccons ::= UNIQUE onconf",
113856
- /* 65 */ "ccons ::= CHECK LP expr RP",
113857
- /* 66 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
113858
- /* 67 */ "ccons ::= defer_subclause",
113859
- /* 68 */ "ccons ::= COLLATE ids",
113860
- /* 69 */ "autoinc ::=",
113861
- /* 70 */ "autoinc ::= AUTOINCR",
113862
- /* 71 */ "refargs ::=",
113863
- /* 72 */ "refargs ::= refargs refarg",
113864
- /* 73 */ "refarg ::= MATCH nm",
113865
- /* 74 */ "refarg ::= ON INSERT refact",
113866
- /* 75 */ "refarg ::= ON DELETE refact",
113867
- /* 76 */ "refarg ::= ON UPDATE refact",
113868
- /* 77 */ "refact ::= SET NULL",
113869
- /* 78 */ "refact ::= SET DEFAULT",
113870
- /* 79 */ "refact ::= CASCADE",
113871
- /* 80 */ "refact ::= RESTRICT",
113872
- /* 81 */ "refact ::= NO ACTION",
113873
- /* 82 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
113874
- /* 83 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
113875
- /* 84 */ "init_deferred_pred_opt ::=",
113876
- /* 85 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
113877
- /* 86 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
113878
- /* 87 */ "conslist_opt ::=",
113879
- /* 88 */ "conslist_opt ::= COMMA conslist",
113880
- /* 89 */ "conslist ::= conslist tconscomma tcons",
113881
- /* 90 */ "conslist ::= tcons",
113882
- /* 91 */ "tconscomma ::= COMMA",
113883
- /* 92 */ "tconscomma ::=",
113884
- /* 93 */ "tcons ::= CONSTRAINT nm",
113885
- /* 94 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
113886
- /* 95 */ "tcons ::= UNIQUE LP idxlist RP onconf",
113887
- /* 96 */ "tcons ::= CHECK LP expr RP onconf",
113888
- /* 97 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
113889
- /* 98 */ "defer_subclause_opt ::=",
113890
- /* 99 */ "defer_subclause_opt ::= defer_subclause",
113891
- /* 100 */ "onconf ::=",
113892
- /* 101 */ "onconf ::= ON CONFLICT resolvetype",
113893
- /* 102 */ "orconf ::=",
113894
- /* 103 */ "orconf ::= OR resolvetype",
113895
- /* 104 */ "resolvetype ::= raisetype",
113896
- /* 105 */ "resolvetype ::= IGNORE",
113897
- /* 106 */ "resolvetype ::= REPLACE",
113898
- /* 107 */ "cmd ::= DROP TABLE ifexists fullname",
113899
- /* 108 */ "ifexists ::= IF EXISTS",
113900
- /* 109 */ "ifexists ::=",
113901
- /* 110 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select",
113902
- /* 111 */ "cmd ::= DROP VIEW ifexists fullname",
113903
- /* 112 */ "cmd ::= select",
113904
- /* 113 */ "select ::= oneselect",
113905
- /* 114 */ "select ::= select multiselect_op oneselect",
113906
- /* 115 */ "multiselect_op ::= UNION",
113907
- /* 116 */ "multiselect_op ::= UNION ALL",
113908
- /* 117 */ "multiselect_op ::= EXCEPT|INTERSECT",
113909
- /* 118 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
113910
- /* 119 */ "distinct ::= DISTINCT",
113911
- /* 120 */ "distinct ::= ALL",
113912
- /* 121 */ "distinct ::=",
113913
- /* 122 */ "sclp ::= selcollist COMMA",
113914
- /* 123 */ "sclp ::=",
113915
- /* 124 */ "selcollist ::= sclp expr as",
113916
- /* 125 */ "selcollist ::= sclp STAR",
113917
- /* 126 */ "selcollist ::= sclp nm DOT STAR",
113918
- /* 127 */ "as ::= AS nm",
113919
- /* 128 */ "as ::= ids",
113920
- /* 129 */ "as ::=",
113921
- /* 130 */ "from ::=",
113922
- /* 131 */ "from ::= FROM seltablist",
113923
- /* 132 */ "stl_prefix ::= seltablist joinop",
113924
- /* 133 */ "stl_prefix ::=",
113925
- /* 134 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
113926
- /* 135 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
113927
- /* 136 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
113928
- /* 137 */ "dbnm ::=",
113929
- /* 138 */ "dbnm ::= DOT nm",
113930
- /* 139 */ "fullname ::= nm dbnm",
113931
- /* 140 */ "joinop ::= COMMA|JOIN",
113932
- /* 141 */ "joinop ::= JOIN_KW JOIN",
113933
- /* 142 */ "joinop ::= JOIN_KW nm JOIN",
113934
- /* 143 */ "joinop ::= JOIN_KW nm nm JOIN",
113935
- /* 144 */ "on_opt ::= ON expr",
113936
- /* 145 */ "on_opt ::=",
113937
- /* 146 */ "indexed_opt ::=",
113938
- /* 147 */ "indexed_opt ::= INDEXED BY nm",
113939
- /* 148 */ "indexed_opt ::= NOT INDEXED",
113940
- /* 149 */ "using_opt ::= USING LP inscollist RP",
113941
- /* 150 */ "using_opt ::=",
113942
- /* 151 */ "orderby_opt ::=",
113943
- /* 152 */ "orderby_opt ::= ORDER BY sortlist",
113944
- /* 153 */ "sortlist ::= sortlist COMMA expr sortorder",
113945
- /* 154 */ "sortlist ::= expr sortorder",
113946
- /* 155 */ "sortorder ::= ASC",
113947
- /* 156 */ "sortorder ::= DESC",
113948
- /* 157 */ "sortorder ::=",
113949
- /* 158 */ "groupby_opt ::=",
113950
- /* 159 */ "groupby_opt ::= GROUP BY nexprlist",
113951
- /* 160 */ "having_opt ::=",
113952
- /* 161 */ "having_opt ::= HAVING expr",
113953
- /* 162 */ "limit_opt ::=",
113954
- /* 163 */ "limit_opt ::= LIMIT expr",
113955
- /* 164 */ "limit_opt ::= LIMIT expr OFFSET expr",
113956
- /* 165 */ "limit_opt ::= LIMIT expr COMMA expr",
113957
- /* 166 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
113958
- /* 167 */ "where_opt ::=",
113959
- /* 168 */ "where_opt ::= WHERE expr",
113960
- /* 169 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
113961
- /* 170 */ "setlist ::= setlist COMMA nm EQ expr",
113962
- /* 171 */ "setlist ::= nm EQ expr",
113963
- /* 172 */ "cmd ::= insert_cmd INTO fullname inscollist_opt valuelist",
113964
- /* 173 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
113965
- /* 174 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
113966
- /* 175 */ "insert_cmd ::= INSERT orconf",
113967
- /* 176 */ "insert_cmd ::= REPLACE",
113968
- /* 177 */ "valuelist ::= VALUES LP nexprlist RP",
113969
- /* 178 */ "valuelist ::= valuelist COMMA LP exprlist RP",
113970
- /* 179 */ "inscollist_opt ::=",
113971
- /* 180 */ "inscollist_opt ::= LP inscollist RP",
113972
- /* 181 */ "inscollist ::= inscollist COMMA nm",
113973
- /* 182 */ "inscollist ::= nm",
113974
- /* 183 */ "expr ::= term",
113975
- /* 184 */ "expr ::= LP expr RP",
113976
- /* 185 */ "term ::= NULL",
113977
- /* 186 */ "expr ::= id",
113978
- /* 187 */ "expr ::= JOIN_KW",
113979
- /* 188 */ "expr ::= nm DOT nm",
113980
- /* 189 */ "expr ::= nm DOT nm DOT nm",
113981
- /* 190 */ "term ::= INTEGER|FLOAT|BLOB",
113982
- /* 191 */ "term ::= STRING",
113983
- /* 192 */ "expr ::= REGISTER",
113984
- /* 193 */ "expr ::= VARIABLE",
113985
- /* 194 */ "expr ::= expr COLLATE ids",
113986
- /* 195 */ "expr ::= CAST LP expr AS typetoken RP",
113987
- /* 196 */ "expr ::= ID LP distinct exprlist RP",
113988
- /* 197 */ "expr ::= ID LP STAR RP",
113989
- /* 198 */ "term ::= CTIME_KW",
113990
- /* 199 */ "expr ::= expr AND expr",
113991
- /* 200 */ "expr ::= expr OR expr",
113992
- /* 201 */ "expr ::= expr LT|GT|GE|LE expr",
113993
- /* 202 */ "expr ::= expr EQ|NE expr",
113994
- /* 203 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
113995
- /* 204 */ "expr ::= expr PLUS|MINUS expr",
113996
- /* 205 */ "expr ::= expr STAR|SLASH|REM expr",
113997
- /* 206 */ "expr ::= expr CONCAT expr",
113998
- /* 207 */ "likeop ::= LIKE_KW",
113999
- /* 208 */ "likeop ::= NOT LIKE_KW",
114000
- /* 209 */ "likeop ::= MATCH",
114001
- /* 210 */ "likeop ::= NOT MATCH",
114002
- /* 211 */ "expr ::= expr likeop expr",
114003
- /* 212 */ "expr ::= expr likeop expr ESCAPE expr",
114004
- /* 213 */ "expr ::= expr ISNULL|NOTNULL",
114005
- /* 214 */ "expr ::= expr NOT NULL",
114006
- /* 215 */ "expr ::= expr IS expr",
114007
- /* 216 */ "expr ::= expr IS NOT expr",
114008
- /* 217 */ "expr ::= NOT expr",
114009
- /* 218 */ "expr ::= BITNOT expr",
114010
- /* 219 */ "expr ::= MINUS expr",
114011
- /* 220 */ "expr ::= PLUS expr",
114012
- /* 221 */ "between_op ::= BETWEEN",
114013
- /* 222 */ "between_op ::= NOT BETWEEN",
114014
- /* 223 */ "expr ::= expr between_op expr AND expr",
114015
- /* 224 */ "in_op ::= IN",
114016
- /* 225 */ "in_op ::= NOT IN",
114017
- /* 226 */ "expr ::= expr in_op LP exprlist RP",
114018
- /* 227 */ "expr ::= LP select RP",
114019
- /* 228 */ "expr ::= expr in_op LP select RP",
114020
- /* 229 */ "expr ::= expr in_op nm dbnm",
114021
- /* 230 */ "expr ::= EXISTS LP select RP",
114022
- /* 231 */ "expr ::= CASE case_operand case_exprlist case_else END",
114023
- /* 232 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
114024
- /* 233 */ "case_exprlist ::= WHEN expr THEN expr",
114025
- /* 234 */ "case_else ::= ELSE expr",
114026
- /* 235 */ "case_else ::=",
114027
- /* 236 */ "case_operand ::= expr",
114028
- /* 237 */ "case_operand ::=",
114029
- /* 238 */ "exprlist ::= nexprlist",
114030
- /* 239 */ "exprlist ::=",
114031
- /* 240 */ "nexprlist ::= nexprlist COMMA expr",
114032
- /* 241 */ "nexprlist ::= expr",
114033
- /* 242 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt",
114034
- /* 243 */ "uniqueflag ::= UNIQUE",
114035
- /* 244 */ "uniqueflag ::=",
114036
- /* 245 */ "idxlist_opt ::=",
114037
- /* 246 */ "idxlist_opt ::= LP idxlist RP",
114038
- /* 247 */ "idxlist ::= idxlist COMMA nm collate sortorder",
114039
- /* 248 */ "idxlist ::= nm collate sortorder",
114040
- /* 249 */ "collate ::=",
114041
- /* 250 */ "collate ::= COLLATE ids",
114042
- /* 251 */ "cmd ::= DROP INDEX ifexists fullname",
114043
- /* 252 */ "cmd ::= VACUUM",
114044
- /* 253 */ "cmd ::= VACUUM nm",
114045
- /* 254 */ "cmd ::= PRAGMA nm dbnm",
114046
- /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
114047
- /* 256 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
114048
- /* 257 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
114049
- /* 258 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
114050
- /* 259 */ "nmnum ::= plus_num",
114051
- /* 260 */ "nmnum ::= nm",
114052
- /* 261 */ "nmnum ::= ON",
114053
- /* 262 */ "nmnum ::= DELETE",
114054
- /* 263 */ "nmnum ::= DEFAULT",
114055
- /* 264 */ "plus_num ::= PLUS number",
114056
- /* 265 */ "plus_num ::= number",
114057
- /* 266 */ "minus_num ::= MINUS number",
114058
- /* 267 */ "number ::= INTEGER|FLOAT",
114059
- /* 268 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
114060
- /* 269 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
114061
- /* 270 */ "trigger_time ::= BEFORE",
114062
- /* 271 */ "trigger_time ::= AFTER",
114063
- /* 272 */ "trigger_time ::= INSTEAD OF",
114064
- /* 273 */ "trigger_time ::=",
114065
- /* 274 */ "trigger_event ::= DELETE|INSERT",
114066
- /* 275 */ "trigger_event ::= UPDATE",
114067
- /* 276 */ "trigger_event ::= UPDATE OF inscollist",
114068
- /* 277 */ "foreach_clause ::=",
114069
- /* 278 */ "foreach_clause ::= FOR EACH ROW",
114070
- /* 279 */ "when_clause ::=",
114071
- /* 280 */ "when_clause ::= WHEN expr",
114072
- /* 281 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
114073
- /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI",
114074
- /* 283 */ "trnm ::= nm",
114075
- /* 284 */ "trnm ::= nm DOT nm",
114076
- /* 285 */ "tridxby ::=",
114077
- /* 286 */ "tridxby ::= INDEXED BY nm",
114078
- /* 287 */ "tridxby ::= NOT INDEXED",
114079
- /* 288 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
114080
- /* 289 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist",
114081
- /* 290 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
114082
- /* 291 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
114083
- /* 292 */ "trigger_cmd ::= select",
114084
- /* 293 */ "expr ::= RAISE LP IGNORE RP",
114085
- /* 294 */ "expr ::= RAISE LP raisetype COMMA nm RP",
114086
- /* 295 */ "raisetype ::= ROLLBACK",
114087
- /* 296 */ "raisetype ::= ABORT",
114088
- /* 297 */ "raisetype ::= FAIL",
114089
- /* 298 */ "cmd ::= DROP TRIGGER ifexists fullname",
114090
- /* 299 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
114091
- /* 300 */ "cmd ::= DETACH database_kw_opt expr",
114092
- /* 301 */ "key_opt ::=",
114093
- /* 302 */ "key_opt ::= KEY expr",
114094
- /* 303 */ "database_kw_opt ::= DATABASE",
114095
- /* 304 */ "database_kw_opt ::=",
114096
- /* 305 */ "cmd ::= REINDEX",
114097
- /* 306 */ "cmd ::= REINDEX nm dbnm",
114098
- /* 307 */ "cmd ::= ANALYZE",
114099
- /* 308 */ "cmd ::= ANALYZE nm dbnm",
114100
- /* 309 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
114101
- /* 310 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
114102
- /* 311 */ "add_column_fullname ::= fullname",
114103
- /* 312 */ "kwcolumn_opt ::=",
114104
- /* 313 */ "kwcolumn_opt ::= COLUMNKW",
114105
- /* 314 */ "cmd ::= create_vtab",
114106
- /* 315 */ "cmd ::= create_vtab LP vtabarglist RP",
114107
- /* 316 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
114108
- /* 317 */ "vtabarglist ::= vtabarg",
114109
- /* 318 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
114110
- /* 319 */ "vtabarg ::=",
114111
- /* 320 */ "vtabarg ::= vtabarg vtabargtoken",
114112
- /* 321 */ "vtabargtoken ::= ANY",
114113
- /* 322 */ "vtabargtoken ::= lp anylist RP",
114114
- /* 323 */ "lp ::= LP",
114115
- /* 324 */ "anylist ::=",
114116
- /* 325 */ "anylist ::= anylist LP anylist RP",
114117
- /* 326 */ "anylist ::= anylist ANY",
115191
+ /* 34 */ "table_options ::=",
115192
+ /* 35 */ "table_options ::= WITHOUT nm",
115193
+ /* 36 */ "columnlist ::= columnlist COMMA column",
115194
+ /* 37 */ "columnlist ::= column",
115195
+ /* 38 */ "column ::= columnid type carglist",
115196
+ /* 39 */ "columnid ::= nm",
115197
+ /* 40 */ "id ::= ID",
115198
+ /* 41 */ "id ::= INDEXED",
115199
+ /* 42 */ "ids ::= ID|STRING",
115200
+ /* 43 */ "nm ::= id",
115201
+ /* 44 */ "nm ::= STRING",
115202
+ /* 45 */ "nm ::= JOIN_KW",
115203
+ /* 46 */ "type ::=",
115204
+ /* 47 */ "type ::= typetoken",
115205
+ /* 48 */ "typetoken ::= typename",
115206
+ /* 49 */ "typetoken ::= typename LP signed RP",
115207
+ /* 50 */ "typetoken ::= typename LP signed COMMA signed RP",
115208
+ /* 51 */ "typename ::= ids",
115209
+ /* 52 */ "typename ::= typename ids",
115210
+ /* 53 */ "signed ::= plus_num",
115211
+ /* 54 */ "signed ::= minus_num",
115212
+ /* 55 */ "carglist ::= carglist ccons",
115213
+ /* 56 */ "carglist ::=",
115214
+ /* 57 */ "ccons ::= CONSTRAINT nm",
115215
+ /* 58 */ "ccons ::= DEFAULT term",
115216
+ /* 59 */ "ccons ::= DEFAULT LP expr RP",
115217
+ /* 60 */ "ccons ::= DEFAULT PLUS term",
115218
+ /* 61 */ "ccons ::= DEFAULT MINUS term",
115219
+ /* 62 */ "ccons ::= DEFAULT id",
115220
+ /* 63 */ "ccons ::= NULL onconf",
115221
+ /* 64 */ "ccons ::= NOT NULL onconf",
115222
+ /* 65 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
115223
+ /* 66 */ "ccons ::= UNIQUE onconf",
115224
+ /* 67 */ "ccons ::= CHECK LP expr RP",
115225
+ /* 68 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
115226
+ /* 69 */ "ccons ::= defer_subclause",
115227
+ /* 70 */ "ccons ::= COLLATE ids",
115228
+ /* 71 */ "autoinc ::=",
115229
+ /* 72 */ "autoinc ::= AUTOINCR",
115230
+ /* 73 */ "refargs ::=",
115231
+ /* 74 */ "refargs ::= refargs refarg",
115232
+ /* 75 */ "refarg ::= MATCH nm",
115233
+ /* 76 */ "refarg ::= ON INSERT refact",
115234
+ /* 77 */ "refarg ::= ON DELETE refact",
115235
+ /* 78 */ "refarg ::= ON UPDATE refact",
115236
+ /* 79 */ "refact ::= SET NULL",
115237
+ /* 80 */ "refact ::= SET DEFAULT",
115238
+ /* 81 */ "refact ::= CASCADE",
115239
+ /* 82 */ "refact ::= RESTRICT",
115240
+ /* 83 */ "refact ::= NO ACTION",
115241
+ /* 84 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
115242
+ /* 85 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
115243
+ /* 86 */ "init_deferred_pred_opt ::=",
115244
+ /* 87 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
115245
+ /* 88 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
115246
+ /* 89 */ "conslist_opt ::=",
115247
+ /* 90 */ "conslist_opt ::= COMMA conslist",
115248
+ /* 91 */ "conslist ::= conslist tconscomma tcons",
115249
+ /* 92 */ "conslist ::= tcons",
115250
+ /* 93 */ "tconscomma ::= COMMA",
115251
+ /* 94 */ "tconscomma ::=",
115252
+ /* 95 */ "tcons ::= CONSTRAINT nm",
115253
+ /* 96 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
115254
+ /* 97 */ "tcons ::= UNIQUE LP idxlist RP onconf",
115255
+ /* 98 */ "tcons ::= CHECK LP expr RP onconf",
115256
+ /* 99 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
115257
+ /* 100 */ "defer_subclause_opt ::=",
115258
+ /* 101 */ "defer_subclause_opt ::= defer_subclause",
115259
+ /* 102 */ "onconf ::=",
115260
+ /* 103 */ "onconf ::= ON CONFLICT resolvetype",
115261
+ /* 104 */ "orconf ::=",
115262
+ /* 105 */ "orconf ::= OR resolvetype",
115263
+ /* 106 */ "resolvetype ::= raisetype",
115264
+ /* 107 */ "resolvetype ::= IGNORE",
115265
+ /* 108 */ "resolvetype ::= REPLACE",
115266
+ /* 109 */ "cmd ::= DROP TABLE ifexists fullname",
115267
+ /* 110 */ "ifexists ::= IF EXISTS",
115268
+ /* 111 */ "ifexists ::=",
115269
+ /* 112 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select",
115270
+ /* 113 */ "cmd ::= DROP VIEW ifexists fullname",
115271
+ /* 114 */ "cmd ::= select",
115272
+ /* 115 */ "select ::= oneselect",
115273
+ /* 116 */ "select ::= select multiselect_op oneselect",
115274
+ /* 117 */ "multiselect_op ::= UNION",
115275
+ /* 118 */ "multiselect_op ::= UNION ALL",
115276
+ /* 119 */ "multiselect_op ::= EXCEPT|INTERSECT",
115277
+ /* 120 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
115278
+ /* 121 */ "distinct ::= DISTINCT",
115279
+ /* 122 */ "distinct ::= ALL",
115280
+ /* 123 */ "distinct ::=",
115281
+ /* 124 */ "sclp ::= selcollist COMMA",
115282
+ /* 125 */ "sclp ::=",
115283
+ /* 126 */ "selcollist ::= sclp expr as",
115284
+ /* 127 */ "selcollist ::= sclp STAR",
115285
+ /* 128 */ "selcollist ::= sclp nm DOT STAR",
115286
+ /* 129 */ "as ::= AS nm",
115287
+ /* 130 */ "as ::= ids",
115288
+ /* 131 */ "as ::=",
115289
+ /* 132 */ "from ::=",
115290
+ /* 133 */ "from ::= FROM seltablist",
115291
+ /* 134 */ "stl_prefix ::= seltablist joinop",
115292
+ /* 135 */ "stl_prefix ::=",
115293
+ /* 136 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
115294
+ /* 137 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
115295
+ /* 138 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
115296
+ /* 139 */ "dbnm ::=",
115297
+ /* 140 */ "dbnm ::= DOT nm",
115298
+ /* 141 */ "fullname ::= nm dbnm",
115299
+ /* 142 */ "joinop ::= COMMA|JOIN",
115300
+ /* 143 */ "joinop ::= JOIN_KW JOIN",
115301
+ /* 144 */ "joinop ::= JOIN_KW nm JOIN",
115302
+ /* 145 */ "joinop ::= JOIN_KW nm nm JOIN",
115303
+ /* 146 */ "on_opt ::= ON expr",
115304
+ /* 147 */ "on_opt ::=",
115305
+ /* 148 */ "indexed_opt ::=",
115306
+ /* 149 */ "indexed_opt ::= INDEXED BY nm",
115307
+ /* 150 */ "indexed_opt ::= NOT INDEXED",
115308
+ /* 151 */ "using_opt ::= USING LP idlist RP",
115309
+ /* 152 */ "using_opt ::=",
115310
+ /* 153 */ "orderby_opt ::=",
115311
+ /* 154 */ "orderby_opt ::= ORDER BY sortlist",
115312
+ /* 155 */ "sortlist ::= sortlist COMMA expr sortorder",
115313
+ /* 156 */ "sortlist ::= expr sortorder",
115314
+ /* 157 */ "sortorder ::= ASC",
115315
+ /* 158 */ "sortorder ::= DESC",
115316
+ /* 159 */ "sortorder ::=",
115317
+ /* 160 */ "groupby_opt ::=",
115318
+ /* 161 */ "groupby_opt ::= GROUP BY nexprlist",
115319
+ /* 162 */ "having_opt ::=",
115320
+ /* 163 */ "having_opt ::= HAVING expr",
115321
+ /* 164 */ "limit_opt ::=",
115322
+ /* 165 */ "limit_opt ::= LIMIT expr",
115323
+ /* 166 */ "limit_opt ::= LIMIT expr OFFSET expr",
115324
+ /* 167 */ "limit_opt ::= LIMIT expr COMMA expr",
115325
+ /* 168 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
115326
+ /* 169 */ "where_opt ::=",
115327
+ /* 170 */ "where_opt ::= WHERE expr",
115328
+ /* 171 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
115329
+ /* 172 */ "setlist ::= setlist COMMA nm EQ expr",
115330
+ /* 173 */ "setlist ::= nm EQ expr",
115331
+ /* 174 */ "cmd ::= insert_cmd INTO fullname inscollist_opt valuelist",
115332
+ /* 175 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
115333
+ /* 176 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
115334
+ /* 177 */ "insert_cmd ::= INSERT orconf",
115335
+ /* 178 */ "insert_cmd ::= REPLACE",
115336
+ /* 179 */ "valuelist ::= VALUES LP nexprlist RP",
115337
+ /* 180 */ "valuelist ::= valuelist COMMA LP exprlist RP",
115338
+ /* 181 */ "inscollist_opt ::=",
115339
+ /* 182 */ "inscollist_opt ::= LP idlist RP",
115340
+ /* 183 */ "idlist ::= idlist COMMA nm",
115341
+ /* 184 */ "idlist ::= nm",
115342
+ /* 185 */ "expr ::= term",
115343
+ /* 186 */ "expr ::= LP expr RP",
115344
+ /* 187 */ "term ::= NULL",
115345
+ /* 188 */ "expr ::= id",
115346
+ /* 189 */ "expr ::= JOIN_KW",
115347
+ /* 190 */ "expr ::= nm DOT nm",
115348
+ /* 191 */ "expr ::= nm DOT nm DOT nm",
115349
+ /* 192 */ "term ::= INTEGER|FLOAT|BLOB",
115350
+ /* 193 */ "term ::= STRING",
115351
+ /* 194 */ "expr ::= REGISTER",
115352
+ /* 195 */ "expr ::= VARIABLE",
115353
+ /* 196 */ "expr ::= expr COLLATE ids",
115354
+ /* 197 */ "expr ::= CAST LP expr AS typetoken RP",
115355
+ /* 198 */ "expr ::= ID LP distinct exprlist RP",
115356
+ /* 199 */ "expr ::= ID LP STAR RP",
115357
+ /* 200 */ "term ::= CTIME_KW",
115358
+ /* 201 */ "expr ::= expr AND expr",
115359
+ /* 202 */ "expr ::= expr OR expr",
115360
+ /* 203 */ "expr ::= expr LT|GT|GE|LE expr",
115361
+ /* 204 */ "expr ::= expr EQ|NE expr",
115362
+ /* 205 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
115363
+ /* 206 */ "expr ::= expr PLUS|MINUS expr",
115364
+ /* 207 */ "expr ::= expr STAR|SLASH|REM expr",
115365
+ /* 208 */ "expr ::= expr CONCAT expr",
115366
+ /* 209 */ "likeop ::= LIKE_KW",
115367
+ /* 210 */ "likeop ::= NOT LIKE_KW",
115368
+ /* 211 */ "likeop ::= MATCH",
115369
+ /* 212 */ "likeop ::= NOT MATCH",
115370
+ /* 213 */ "expr ::= expr likeop expr",
115371
+ /* 214 */ "expr ::= expr likeop expr ESCAPE expr",
115372
+ /* 215 */ "expr ::= expr ISNULL|NOTNULL",
115373
+ /* 216 */ "expr ::= expr NOT NULL",
115374
+ /* 217 */ "expr ::= expr IS expr",
115375
+ /* 218 */ "expr ::= expr IS NOT expr",
115376
+ /* 219 */ "expr ::= NOT expr",
115377
+ /* 220 */ "expr ::= BITNOT expr",
115378
+ /* 221 */ "expr ::= MINUS expr",
115379
+ /* 222 */ "expr ::= PLUS expr",
115380
+ /* 223 */ "between_op ::= BETWEEN",
115381
+ /* 224 */ "between_op ::= NOT BETWEEN",
115382
+ /* 225 */ "expr ::= expr between_op expr AND expr",
115383
+ /* 226 */ "in_op ::= IN",
115384
+ /* 227 */ "in_op ::= NOT IN",
115385
+ /* 228 */ "expr ::= expr in_op LP exprlist RP",
115386
+ /* 229 */ "expr ::= LP select RP",
115387
+ /* 230 */ "expr ::= expr in_op LP select RP",
115388
+ /* 231 */ "expr ::= expr in_op nm dbnm",
115389
+ /* 232 */ "expr ::= EXISTS LP select RP",
115390
+ /* 233 */ "expr ::= CASE case_operand case_exprlist case_else END",
115391
+ /* 234 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
115392
+ /* 235 */ "case_exprlist ::= WHEN expr THEN expr",
115393
+ /* 236 */ "case_else ::= ELSE expr",
115394
+ /* 237 */ "case_else ::=",
115395
+ /* 238 */ "case_operand ::= expr",
115396
+ /* 239 */ "case_operand ::=",
115397
+ /* 240 */ "exprlist ::= nexprlist",
115398
+ /* 241 */ "exprlist ::=",
115399
+ /* 242 */ "nexprlist ::= nexprlist COMMA expr",
115400
+ /* 243 */ "nexprlist ::= expr",
115401
+ /* 244 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt",
115402
+ /* 245 */ "uniqueflag ::= UNIQUE",
115403
+ /* 246 */ "uniqueflag ::=",
115404
+ /* 247 */ "idxlist_opt ::=",
115405
+ /* 248 */ "idxlist_opt ::= LP idxlist RP",
115406
+ /* 249 */ "idxlist ::= idxlist COMMA nm collate sortorder",
115407
+ /* 250 */ "idxlist ::= nm collate sortorder",
115408
+ /* 251 */ "collate ::=",
115409
+ /* 252 */ "collate ::= COLLATE ids",
115410
+ /* 253 */ "cmd ::= DROP INDEX ifexists fullname",
115411
+ /* 254 */ "cmd ::= VACUUM",
115412
+ /* 255 */ "cmd ::= VACUUM nm",
115413
+ /* 256 */ "cmd ::= PRAGMA nm dbnm",
115414
+ /* 257 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
115415
+ /* 258 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
115416
+ /* 259 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
115417
+ /* 260 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
115418
+ /* 261 */ "nmnum ::= plus_num",
115419
+ /* 262 */ "nmnum ::= nm",
115420
+ /* 263 */ "nmnum ::= ON",
115421
+ /* 264 */ "nmnum ::= DELETE",
115422
+ /* 265 */ "nmnum ::= DEFAULT",
115423
+ /* 266 */ "plus_num ::= PLUS number",
115424
+ /* 267 */ "plus_num ::= number",
115425
+ /* 268 */ "minus_num ::= MINUS number",
115426
+ /* 269 */ "number ::= INTEGER|FLOAT",
115427
+ /* 270 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
115428
+ /* 271 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
115429
+ /* 272 */ "trigger_time ::= BEFORE",
115430
+ /* 273 */ "trigger_time ::= AFTER",
115431
+ /* 274 */ "trigger_time ::= INSTEAD OF",
115432
+ /* 275 */ "trigger_time ::=",
115433
+ /* 276 */ "trigger_event ::= DELETE|INSERT",
115434
+ /* 277 */ "trigger_event ::= UPDATE",
115435
+ /* 278 */ "trigger_event ::= UPDATE OF idlist",
115436
+ /* 279 */ "foreach_clause ::=",
115437
+ /* 280 */ "foreach_clause ::= FOR EACH ROW",
115438
+ /* 281 */ "when_clause ::=",
115439
+ /* 282 */ "when_clause ::= WHEN expr",
115440
+ /* 283 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
115441
+ /* 284 */ "trigger_cmd_list ::= trigger_cmd SEMI",
115442
+ /* 285 */ "trnm ::= nm",
115443
+ /* 286 */ "trnm ::= nm DOT nm",
115444
+ /* 287 */ "tridxby ::=",
115445
+ /* 288 */ "tridxby ::= INDEXED BY nm",
115446
+ /* 289 */ "tridxby ::= NOT INDEXED",
115447
+ /* 290 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
115448
+ /* 291 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist",
115449
+ /* 292 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
115450
+ /* 293 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
115451
+ /* 294 */ "trigger_cmd ::= select",
115452
+ /* 295 */ "expr ::= RAISE LP IGNORE RP",
115453
+ /* 296 */ "expr ::= RAISE LP raisetype COMMA nm RP",
115454
+ /* 297 */ "raisetype ::= ROLLBACK",
115455
+ /* 298 */ "raisetype ::= ABORT",
115456
+ /* 299 */ "raisetype ::= FAIL",
115457
+ /* 300 */ "cmd ::= DROP TRIGGER ifexists fullname",
115458
+ /* 301 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
115459
+ /* 302 */ "cmd ::= DETACH database_kw_opt expr",
115460
+ /* 303 */ "key_opt ::=",
115461
+ /* 304 */ "key_opt ::= KEY expr",
115462
+ /* 305 */ "database_kw_opt ::= DATABASE",
115463
+ /* 306 */ "database_kw_opt ::=",
115464
+ /* 307 */ "cmd ::= REINDEX",
115465
+ /* 308 */ "cmd ::= REINDEX nm dbnm",
115466
+ /* 309 */ "cmd ::= ANALYZE",
115467
+ /* 310 */ "cmd ::= ANALYZE nm dbnm",
115468
+ /* 311 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
115469
+ /* 312 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
115470
+ /* 313 */ "add_column_fullname ::= fullname",
115471
+ /* 314 */ "kwcolumn_opt ::=",
115472
+ /* 315 */ "kwcolumn_opt ::= COLUMNKW",
115473
+ /* 316 */ "cmd ::= create_vtab",
115474
+ /* 317 */ "cmd ::= create_vtab LP vtabarglist RP",
115475
+ /* 318 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
115476
+ /* 319 */ "vtabarglist ::= vtabarg",
115477
+ /* 320 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
115478
+ /* 321 */ "vtabarg ::=",
115479
+ /* 322 */ "vtabarg ::= vtabarg vtabargtoken",
115480
+ /* 323 */ "vtabargtoken ::= ANY",
115481
+ /* 324 */ "vtabargtoken ::= lp anylist RP",
115482
+ /* 325 */ "lp ::= LP",
115483
+ /* 326 */ "anylist ::=",
115484
+ /* 327 */ "anylist ::= anylist LP anylist RP",
115485
+ /* 328 */ "anylist ::= anylist ANY",
114118115486
};
114119115487
#endif /* NDEBUG */
114120115488
114121115489
114122115490
#if YYSTACKDEPTH<=0
@@ -114191,80 +115559,80 @@
114191115559
**
114192115560
** Note: during a reduce, the only symbols destroyed are those
114193115561
** which appear on the RHS of the rule, but which are not used
114194115562
** inside the C code.
114195115563
*/
114196
- case 160: /* select */
114197
- case 194: /* oneselect */
114198
-{
114199
-sqlite3SelectDelete(pParse->db, (yypminor->yy159));
114200
-}
114201
- break;
114202
- case 173: /* term */
114203
- case 174: /* expr */
114204
-{
114205
-sqlite3ExprDelete(pParse->db, (yypminor->yy342).pExpr);
114206
-}
114207
- break;
114208
- case 178: /* idxlist_opt */
114209
- case 187: /* idxlist */
114210
- case 197: /* selcollist */
114211
- case 200: /* groupby_opt */
114212
- case 202: /* orderby_opt */
114213
- case 204: /* sclp */
114214
- case 214: /* sortlist */
114215
- case 215: /* nexprlist */
114216
- case 216: /* setlist */
114217
- case 220: /* exprlist */
114218
- case 225: /* case_exprlist */
114219
-{
114220
-sqlite3ExprListDelete(pParse->db, (yypminor->yy442));
114221
-}
114222
- break;
114223
- case 193: /* fullname */
114224
- case 198: /* from */
114225
- case 206: /* seltablist */
114226
- case 207: /* stl_prefix */
114227
-{
114228
-sqlite3SrcListDelete(pParse->db, (yypminor->yy347));
114229
-}
114230
- break;
114231
- case 199: /* where_opt */
114232
- case 201: /* having_opt */
114233
- case 210: /* on_opt */
114234
- case 224: /* case_operand */
114235
- case 226: /* case_else */
114236
- case 236: /* when_clause */
114237
- case 241: /* key_opt */
114238
-{
114239
-sqlite3ExprDelete(pParse->db, (yypminor->yy122));
114240
-}
114241
- break;
114242
- case 211: /* using_opt */
114243
- case 213: /* inscollist */
114244
- case 218: /* inscollist_opt */
114245
-{
114246
-sqlite3IdListDelete(pParse->db, (yypminor->yy180));
114247
-}
114248
- break;
114249
- case 219: /* valuelist */
114250
-{
114251
-
114252
- sqlite3ExprListDelete(pParse->db, (yypminor->yy487).pList);
114253
- sqlite3SelectDelete(pParse->db, (yypminor->yy487).pSelect);
114254
-
114255
-}
114256
- break;
114257
- case 232: /* trigger_cmd_list */
114258
- case 237: /* trigger_cmd */
114259
-{
114260
-sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy327));
114261
-}
114262
- break;
114263
- case 234: /* trigger_event */
114264
-{
114265
-sqlite3IdListDelete(pParse->db, (yypminor->yy410).b);
115564
+ case 162: /* select */
115565
+ case 196: /* oneselect */
115566
+{
115567
+sqlite3SelectDelete(pParse->db, (yypminor->yy387));
115568
+}
115569
+ break;
115570
+ case 175: /* term */
115571
+ case 176: /* expr */
115572
+{
115573
+sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
115574
+}
115575
+ break;
115576
+ case 180: /* idxlist_opt */
115577
+ case 189: /* idxlist */
115578
+ case 199: /* selcollist */
115579
+ case 202: /* groupby_opt */
115580
+ case 204: /* orderby_opt */
115581
+ case 206: /* sclp */
115582
+ case 216: /* sortlist */
115583
+ case 217: /* nexprlist */
115584
+ case 218: /* setlist */
115585
+ case 222: /* exprlist */
115586
+ case 227: /* case_exprlist */
115587
+{
115588
+sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
115589
+}
115590
+ break;
115591
+ case 195: /* fullname */
115592
+ case 200: /* from */
115593
+ case 208: /* seltablist */
115594
+ case 209: /* stl_prefix */
115595
+{
115596
+sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
115597
+}
115598
+ break;
115599
+ case 201: /* where_opt */
115600
+ case 203: /* having_opt */
115601
+ case 212: /* on_opt */
115602
+ case 226: /* case_operand */
115603
+ case 228: /* case_else */
115604
+ case 238: /* when_clause */
115605
+ case 243: /* key_opt */
115606
+{
115607
+sqlite3ExprDelete(pParse->db, (yypminor->yy314));
115608
+}
115609
+ break;
115610
+ case 213: /* using_opt */
115611
+ case 215: /* idlist */
115612
+ case 220: /* inscollist_opt */
115613
+{
115614
+sqlite3IdListDelete(pParse->db, (yypminor->yy384));
115615
+}
115616
+ break;
115617
+ case 221: /* valuelist */
115618
+{
115619
+
115620
+ sqlite3ExprListDelete(pParse->db, (yypminor->yy260).pList);
115621
+ sqlite3SelectDelete(pParse->db, (yypminor->yy260).pSelect);
115622
+
115623
+}
115624
+ break;
115625
+ case 234: /* trigger_cmd_list */
115626
+ case 239: /* trigger_cmd */
115627
+{
115628
+sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
115629
+}
115630
+ break;
115631
+ case 236: /* trigger_event */
115632
+{
115633
+sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
114266115634
}
114267115635
break;
114268115636
default: break; /* If no destructor action specified: do nothing */
114269115637
}
114270115638
}
@@ -114505,337 +115873,339 @@
114505115873
*/
114506115874
static const struct {
114507115875
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
114508115876
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
114509115877
} yyRuleInfo[] = {
114510
- { 142, 1 },
114511
- { 143, 2 },
114512
- { 143, 1 },
114513
- { 144, 1 },
114514
- { 144, 3 },
114515
- { 145, 0 },
114516
- { 145, 1 },
114517
- { 145, 3 },
114518
- { 146, 1 },
114519
- { 147, 3 },
114520
- { 149, 0 },
114521
- { 149, 1 },
114522
- { 149, 2 },
114523
- { 148, 0 },
114524
- { 148, 1 },
114525
- { 148, 1 },
114526
- { 148, 1 },
114527
- { 147, 2 },
114528
- { 147, 2 },
114529
- { 147, 2 },
114530
- { 151, 1 },
114531
- { 151, 0 },
114532
- { 147, 2 },
114533
- { 147, 3 },
114534
- { 147, 5 },
114535
- { 147, 2 },
114536
- { 152, 6 },
114537
- { 154, 1 },
114538
- { 156, 0 },
114539
- { 156, 3 },
114540
- { 155, 1 },
114541
- { 155, 0 },
114542
- { 153, 4 },
114543
- { 153, 2 },
114544
- { 158, 3 },
114545
- { 158, 1 },
114546
- { 161, 3 },
114547
- { 162, 1 },
114548
- { 165, 1 },
114549
- { 165, 1 },
114550
- { 166, 1 },
114551
- { 150, 1 },
114552
- { 150, 1 },
114553
- { 150, 1 },
114554
- { 163, 0 },
114555
- { 163, 1 },
114556
- { 167, 1 },
114557
- { 167, 4 },
114558
- { 167, 6 },
114559
- { 168, 1 },
114560
- { 168, 2 },
114561
- { 169, 1 },
114562
- { 169, 1 },
114563
- { 164, 2 },
114564
- { 164, 0 },
114565
- { 172, 2 },
114566
- { 172, 2 },
114567
- { 172, 4 },
114568
- { 172, 3 },
114569
- { 172, 3 },
114570
- { 172, 2 },
114571
- { 172, 2 },
114572
- { 172, 3 },
114573
- { 172, 5 },
114574
- { 172, 2 },
114575
- { 172, 4 },
114576
- { 172, 4 },
114577
- { 172, 1 },
114578
- { 172, 2 },
114579
- { 177, 0 },
114580
- { 177, 1 },
114581
- { 179, 0 },
114582
- { 179, 2 },
114583
- { 181, 2 },
114584
- { 181, 3 },
114585
- { 181, 3 },
114586
- { 181, 3 },
114587
- { 182, 2 },
114588
- { 182, 2 },
114589
- { 182, 1 },
114590
- { 182, 1 },
114591
- { 182, 2 },
114592
- { 180, 3 },
114593
- { 180, 2 },
114594
- { 183, 0 },
114595
- { 183, 2 },
114596
- { 183, 2 },
114597
- { 159, 0 },
114598
- { 159, 2 },
114599
- { 184, 3 },
114600
- { 184, 1 },
114601
- { 185, 1 },
114602
- { 185, 0 },
114603
- { 186, 2 },
114604
- { 186, 7 },
114605
- { 186, 5 },
114606
- { 186, 5 },
114607
- { 186, 10 },
114608
- { 188, 0 },
114609
- { 188, 1 },
114610
- { 175, 0 },
114611
- { 175, 3 },
114612
- { 189, 0 },
114613
- { 189, 2 },
114614
- { 190, 1 },
114615
- { 190, 1 },
114616
- { 190, 1 },
114617
- { 147, 4 },
114618
- { 192, 2 },
114619
- { 192, 0 },
114620
- { 147, 8 },
114621
- { 147, 4 },
114622
- { 147, 1 },
114623
- { 160, 1 },
114624
- { 160, 3 },
114625
- { 195, 1 },
114626
- { 195, 2 },
114627
- { 195, 1 },
114628
- { 194, 9 },
114629
- { 196, 1 },
114630
- { 196, 1 },
114631
- { 196, 0 },
114632
- { 204, 2 },
114633
- { 204, 0 },
114634
- { 197, 3 },
114635
- { 197, 2 },
114636
- { 197, 4 },
114637
- { 205, 2 },
114638
- { 205, 1 },
114639
- { 205, 0 },
114640
- { 198, 0 },
114641
- { 198, 2 },
114642
- { 207, 2 },
114643
- { 207, 0 },
114644
- { 206, 7 },
114645
- { 206, 7 },
114646
- { 206, 7 },
114647
- { 157, 0 },
114648
- { 157, 2 },
114649
- { 193, 2 },
114650
- { 208, 1 },
114651
- { 208, 2 },
114652
- { 208, 3 },
114653
- { 208, 4 },
114654
- { 210, 2 },
114655
- { 210, 0 },
114656
- { 209, 0 },
114657
- { 209, 3 },
114658
- { 209, 2 },
114659
- { 211, 4 },
114660
- { 211, 0 },
114661
- { 202, 0 },
114662
- { 202, 3 },
114663
- { 214, 4 },
114664
- { 214, 2 },
114665
- { 176, 1 },
114666
- { 176, 1 },
114667
- { 176, 0 },
114668
- { 200, 0 },
114669
- { 200, 3 },
114670
- { 201, 0 },
114671
- { 201, 2 },
114672
- { 203, 0 },
114673
- { 203, 2 },
114674
- { 203, 4 },
114675
- { 203, 4 },
114676
- { 147, 5 },
114677
- { 199, 0 },
114678
- { 199, 2 },
114679
- { 147, 7 },
114680
- { 216, 5 },
114681
- { 216, 3 },
114682
- { 147, 5 },
114683
- { 147, 5 },
114684
- { 147, 6 },
114685
- { 217, 2 },
114686
- { 217, 1 },
114687
- { 219, 4 },
114688
- { 219, 5 },
114689
- { 218, 0 },
114690
- { 218, 3 },
114691
- { 213, 3 },
114692
- { 213, 1 },
114693
- { 174, 1 },
114694
- { 174, 3 },
114695
- { 173, 1 },
114696
- { 174, 1 },
114697
- { 174, 1 },
114698
- { 174, 3 },
114699
- { 174, 5 },
114700
- { 173, 1 },
114701
- { 173, 1 },
114702
- { 174, 1 },
114703
- { 174, 1 },
114704
- { 174, 3 },
114705
- { 174, 6 },
114706
- { 174, 5 },
114707
- { 174, 4 },
114708
- { 173, 1 },
114709
- { 174, 3 },
114710
- { 174, 3 },
114711
- { 174, 3 },
114712
- { 174, 3 },
114713
- { 174, 3 },
114714
- { 174, 3 },
114715
- { 174, 3 },
114716
- { 174, 3 },
114717
- { 221, 1 },
114718
- { 221, 2 },
114719
- { 221, 1 },
114720
- { 221, 2 },
114721
- { 174, 3 },
114722
- { 174, 5 },
114723
- { 174, 2 },
114724
- { 174, 3 },
114725
- { 174, 3 },
114726
- { 174, 4 },
114727
- { 174, 2 },
114728
- { 174, 2 },
114729
- { 174, 2 },
114730
- { 174, 2 },
114731
- { 222, 1 },
114732
- { 222, 2 },
114733
- { 174, 5 },
114734
- { 223, 1 },
114735
- { 223, 2 },
114736
- { 174, 5 },
114737
- { 174, 3 },
114738
- { 174, 5 },
114739
- { 174, 4 },
114740
- { 174, 4 },
114741
- { 174, 5 },
114742
- { 225, 5 },
114743
- { 225, 4 },
114744
- { 226, 2 },
114745
- { 226, 0 },
114746
- { 224, 1 },
114747
- { 224, 0 },
114748
- { 220, 1 },
114749
- { 220, 0 },
114750
- { 215, 3 },
114751
- { 215, 1 },
114752
- { 147, 12 },
114753
- { 227, 1 },
114754
- { 227, 0 },
114755
- { 178, 0 },
114756
- { 178, 3 },
114757
- { 187, 5 },
114758
- { 187, 3 },
114759
- { 228, 0 },
114760
- { 228, 2 },
114761
- { 147, 4 },
114762
- { 147, 1 },
114763
- { 147, 2 },
114764
- { 147, 3 },
114765
- { 147, 5 },
114766
- { 147, 6 },
114767
- { 147, 5 },
114768
- { 147, 6 },
114769
- { 229, 1 },
114770
- { 229, 1 },
114771
- { 229, 1 },
114772
- { 229, 1 },
114773
- { 229, 1 },
114774
- { 170, 2 },
114775
- { 170, 1 },
114776
- { 171, 2 },
114777
- { 230, 1 },
114778
- { 147, 5 },
114779
- { 231, 11 },
114780
- { 233, 1 },
114781
- { 233, 1 },
114782
- { 233, 2 },
114783
- { 233, 0 },
114784
- { 234, 1 },
114785
- { 234, 1 },
114786
- { 234, 3 },
114787
- { 235, 0 },
114788
- { 235, 3 },
114789
- { 236, 0 },
114790
- { 236, 2 },
114791
- { 232, 3 },
114792
- { 232, 2 },
114793
- { 238, 1 },
114794
- { 238, 3 },
114795
- { 239, 0 },
114796
- { 239, 3 },
114797
- { 239, 2 },
114798
- { 237, 7 },
114799
- { 237, 5 },
114800
- { 237, 5 },
114801
- { 237, 5 },
114802
- { 237, 1 },
114803
- { 174, 4 },
114804
- { 174, 6 },
114805
- { 191, 1 },
114806
- { 191, 1 },
114807
- { 191, 1 },
114808
- { 147, 4 },
114809
- { 147, 6 },
114810
- { 147, 3 },
114811
- { 241, 0 },
114812
- { 241, 2 },
114813
- { 240, 1 },
114814
- { 240, 0 },
114815
- { 147, 1 },
114816
- { 147, 3 },
114817
- { 147, 1 },
114818
- { 147, 3 },
114819
- { 147, 6 },
114820
- { 147, 6 },
114821
- { 242, 1 },
114822
- { 243, 0 },
114823
- { 243, 1 },
114824
- { 147, 1 },
114825
- { 147, 4 },
114826
- { 244, 8 },
114827
- { 245, 1 },
114828
- { 245, 3 },
114829
- { 246, 0 },
114830
- { 246, 2 },
114831
- { 247, 1 },
114832
- { 247, 3 },
114833
- { 248, 1 },
114834
- { 249, 0 },
114835
- { 249, 4 },
114836
- { 249, 2 },
115878
+ { 143, 1 },
115879
+ { 144, 2 },
115880
+ { 144, 1 },
115881
+ { 145, 1 },
115882
+ { 145, 3 },
115883
+ { 146, 0 },
115884
+ { 146, 1 },
115885
+ { 146, 3 },
115886
+ { 147, 1 },
115887
+ { 148, 3 },
115888
+ { 150, 0 },
115889
+ { 150, 1 },
115890
+ { 150, 2 },
115891
+ { 149, 0 },
115892
+ { 149, 1 },
115893
+ { 149, 1 },
115894
+ { 149, 1 },
115895
+ { 148, 2 },
115896
+ { 148, 2 },
115897
+ { 148, 2 },
115898
+ { 152, 1 },
115899
+ { 152, 0 },
115900
+ { 148, 2 },
115901
+ { 148, 3 },
115902
+ { 148, 5 },
115903
+ { 148, 2 },
115904
+ { 153, 6 },
115905
+ { 155, 1 },
115906
+ { 157, 0 },
115907
+ { 157, 3 },
115908
+ { 156, 1 },
115909
+ { 156, 0 },
115910
+ { 154, 5 },
115911
+ { 154, 2 },
115912
+ { 161, 0 },
115913
+ { 161, 2 },
115914
+ { 159, 3 },
115915
+ { 159, 1 },
115916
+ { 163, 3 },
115917
+ { 164, 1 },
115918
+ { 167, 1 },
115919
+ { 167, 1 },
115920
+ { 168, 1 },
115921
+ { 151, 1 },
115922
+ { 151, 1 },
115923
+ { 151, 1 },
115924
+ { 165, 0 },
115925
+ { 165, 1 },
115926
+ { 169, 1 },
115927
+ { 169, 4 },
115928
+ { 169, 6 },
115929
+ { 170, 1 },
115930
+ { 170, 2 },
115931
+ { 171, 1 },
115932
+ { 171, 1 },
115933
+ { 166, 2 },
115934
+ { 166, 0 },
115935
+ { 174, 2 },
115936
+ { 174, 2 },
115937
+ { 174, 4 },
115938
+ { 174, 3 },
115939
+ { 174, 3 },
115940
+ { 174, 2 },
115941
+ { 174, 2 },
115942
+ { 174, 3 },
115943
+ { 174, 5 },
115944
+ { 174, 2 },
115945
+ { 174, 4 },
115946
+ { 174, 4 },
115947
+ { 174, 1 },
115948
+ { 174, 2 },
115949
+ { 179, 0 },
115950
+ { 179, 1 },
115951
+ { 181, 0 },
115952
+ { 181, 2 },
115953
+ { 183, 2 },
115954
+ { 183, 3 },
115955
+ { 183, 3 },
115956
+ { 183, 3 },
115957
+ { 184, 2 },
115958
+ { 184, 2 },
115959
+ { 184, 1 },
115960
+ { 184, 1 },
115961
+ { 184, 2 },
115962
+ { 182, 3 },
115963
+ { 182, 2 },
115964
+ { 185, 0 },
115965
+ { 185, 2 },
115966
+ { 185, 2 },
115967
+ { 160, 0 },
115968
+ { 160, 2 },
115969
+ { 186, 3 },
115970
+ { 186, 1 },
115971
+ { 187, 1 },
115972
+ { 187, 0 },
115973
+ { 188, 2 },
115974
+ { 188, 7 },
115975
+ { 188, 5 },
115976
+ { 188, 5 },
115977
+ { 188, 10 },
115978
+ { 190, 0 },
115979
+ { 190, 1 },
115980
+ { 177, 0 },
115981
+ { 177, 3 },
115982
+ { 191, 0 },
115983
+ { 191, 2 },
115984
+ { 192, 1 },
115985
+ { 192, 1 },
115986
+ { 192, 1 },
115987
+ { 148, 4 },
115988
+ { 194, 2 },
115989
+ { 194, 0 },
115990
+ { 148, 8 },
115991
+ { 148, 4 },
115992
+ { 148, 1 },
115993
+ { 162, 1 },
115994
+ { 162, 3 },
115995
+ { 197, 1 },
115996
+ { 197, 2 },
115997
+ { 197, 1 },
115998
+ { 196, 9 },
115999
+ { 198, 1 },
116000
+ { 198, 1 },
116001
+ { 198, 0 },
116002
+ { 206, 2 },
116003
+ { 206, 0 },
116004
+ { 199, 3 },
116005
+ { 199, 2 },
116006
+ { 199, 4 },
116007
+ { 207, 2 },
116008
+ { 207, 1 },
116009
+ { 207, 0 },
116010
+ { 200, 0 },
116011
+ { 200, 2 },
116012
+ { 209, 2 },
116013
+ { 209, 0 },
116014
+ { 208, 7 },
116015
+ { 208, 7 },
116016
+ { 208, 7 },
116017
+ { 158, 0 },
116018
+ { 158, 2 },
116019
+ { 195, 2 },
116020
+ { 210, 1 },
116021
+ { 210, 2 },
116022
+ { 210, 3 },
116023
+ { 210, 4 },
116024
+ { 212, 2 },
116025
+ { 212, 0 },
116026
+ { 211, 0 },
116027
+ { 211, 3 },
116028
+ { 211, 2 },
116029
+ { 213, 4 },
116030
+ { 213, 0 },
116031
+ { 204, 0 },
116032
+ { 204, 3 },
116033
+ { 216, 4 },
116034
+ { 216, 2 },
116035
+ { 178, 1 },
116036
+ { 178, 1 },
116037
+ { 178, 0 },
116038
+ { 202, 0 },
116039
+ { 202, 3 },
116040
+ { 203, 0 },
116041
+ { 203, 2 },
116042
+ { 205, 0 },
116043
+ { 205, 2 },
116044
+ { 205, 4 },
116045
+ { 205, 4 },
116046
+ { 148, 5 },
116047
+ { 201, 0 },
116048
+ { 201, 2 },
116049
+ { 148, 7 },
116050
+ { 218, 5 },
116051
+ { 218, 3 },
116052
+ { 148, 5 },
116053
+ { 148, 5 },
116054
+ { 148, 6 },
116055
+ { 219, 2 },
116056
+ { 219, 1 },
116057
+ { 221, 4 },
116058
+ { 221, 5 },
116059
+ { 220, 0 },
116060
+ { 220, 3 },
116061
+ { 215, 3 },
116062
+ { 215, 1 },
116063
+ { 176, 1 },
116064
+ { 176, 3 },
116065
+ { 175, 1 },
116066
+ { 176, 1 },
116067
+ { 176, 1 },
116068
+ { 176, 3 },
116069
+ { 176, 5 },
116070
+ { 175, 1 },
116071
+ { 175, 1 },
116072
+ { 176, 1 },
116073
+ { 176, 1 },
116074
+ { 176, 3 },
116075
+ { 176, 6 },
116076
+ { 176, 5 },
116077
+ { 176, 4 },
116078
+ { 175, 1 },
116079
+ { 176, 3 },
116080
+ { 176, 3 },
116081
+ { 176, 3 },
116082
+ { 176, 3 },
116083
+ { 176, 3 },
116084
+ { 176, 3 },
116085
+ { 176, 3 },
116086
+ { 176, 3 },
116087
+ { 223, 1 },
116088
+ { 223, 2 },
116089
+ { 223, 1 },
116090
+ { 223, 2 },
116091
+ { 176, 3 },
116092
+ { 176, 5 },
116093
+ { 176, 2 },
116094
+ { 176, 3 },
116095
+ { 176, 3 },
116096
+ { 176, 4 },
116097
+ { 176, 2 },
116098
+ { 176, 2 },
116099
+ { 176, 2 },
116100
+ { 176, 2 },
116101
+ { 224, 1 },
116102
+ { 224, 2 },
116103
+ { 176, 5 },
116104
+ { 225, 1 },
116105
+ { 225, 2 },
116106
+ { 176, 5 },
116107
+ { 176, 3 },
116108
+ { 176, 5 },
116109
+ { 176, 4 },
116110
+ { 176, 4 },
116111
+ { 176, 5 },
116112
+ { 227, 5 },
116113
+ { 227, 4 },
116114
+ { 228, 2 },
116115
+ { 228, 0 },
116116
+ { 226, 1 },
116117
+ { 226, 0 },
116118
+ { 222, 1 },
116119
+ { 222, 0 },
116120
+ { 217, 3 },
116121
+ { 217, 1 },
116122
+ { 148, 12 },
116123
+ { 229, 1 },
116124
+ { 229, 0 },
116125
+ { 180, 0 },
116126
+ { 180, 3 },
116127
+ { 189, 5 },
116128
+ { 189, 3 },
116129
+ { 230, 0 },
116130
+ { 230, 2 },
116131
+ { 148, 4 },
116132
+ { 148, 1 },
116133
+ { 148, 2 },
116134
+ { 148, 3 },
116135
+ { 148, 5 },
116136
+ { 148, 6 },
116137
+ { 148, 5 },
116138
+ { 148, 6 },
116139
+ { 231, 1 },
116140
+ { 231, 1 },
116141
+ { 231, 1 },
116142
+ { 231, 1 },
116143
+ { 231, 1 },
116144
+ { 172, 2 },
116145
+ { 172, 1 },
116146
+ { 173, 2 },
116147
+ { 232, 1 },
116148
+ { 148, 5 },
116149
+ { 233, 11 },
116150
+ { 235, 1 },
116151
+ { 235, 1 },
116152
+ { 235, 2 },
116153
+ { 235, 0 },
116154
+ { 236, 1 },
116155
+ { 236, 1 },
116156
+ { 236, 3 },
116157
+ { 237, 0 },
116158
+ { 237, 3 },
116159
+ { 238, 0 },
116160
+ { 238, 2 },
116161
+ { 234, 3 },
116162
+ { 234, 2 },
116163
+ { 240, 1 },
116164
+ { 240, 3 },
116165
+ { 241, 0 },
116166
+ { 241, 3 },
116167
+ { 241, 2 },
116168
+ { 239, 7 },
116169
+ { 239, 5 },
116170
+ { 239, 5 },
116171
+ { 239, 5 },
116172
+ { 239, 1 },
116173
+ { 176, 4 },
116174
+ { 176, 6 },
116175
+ { 193, 1 },
116176
+ { 193, 1 },
116177
+ { 193, 1 },
116178
+ { 148, 4 },
116179
+ { 148, 6 },
116180
+ { 148, 3 },
116181
+ { 243, 0 },
116182
+ { 243, 2 },
116183
+ { 242, 1 },
116184
+ { 242, 0 },
116185
+ { 148, 1 },
116186
+ { 148, 3 },
116187
+ { 148, 1 },
116188
+ { 148, 3 },
116189
+ { 148, 6 },
116190
+ { 148, 6 },
116191
+ { 244, 1 },
116192
+ { 245, 0 },
116193
+ { 245, 1 },
116194
+ { 148, 1 },
116195
+ { 148, 4 },
116196
+ { 246, 8 },
116197
+ { 247, 1 },
116198
+ { 247, 3 },
116199
+ { 248, 0 },
116200
+ { 248, 2 },
116201
+ { 249, 1 },
116202
+ { 249, 3 },
116203
+ { 250, 1 },
116204
+ { 251, 0 },
116205
+ { 251, 4 },
116206
+ { 251, 2 },
114837116207
};
114838116208
114839116209
static void yy_accept(yyParser*); /* Forward Declaration */
114840116210
114841116211
/*
@@ -114899,21 +116269,21 @@
114899116269
break;
114900116270
case 8: /* cmdx ::= cmd */
114901116271
{ sqlite3FinishCoding(pParse); }
114902116272
break;
114903116273
case 9: /* cmd ::= BEGIN transtype trans_opt */
114904
-{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy392);}
116274
+{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
114905116275
break;
114906116276
case 13: /* transtype ::= */
114907
-{yygotominor.yy392 = TK_DEFERRED;}
116277
+{yygotominor.yy4 = TK_DEFERRED;}
114908116278
break;
114909116279
case 14: /* transtype ::= DEFERRED */
114910116280
case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15);
114911116281
case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16);
114912
- case 115: /* multiselect_op ::= UNION */ yytestcase(yyruleno==115);
114913
- case 117: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==117);
114914
-{yygotominor.yy392 = yymsp[0].major;}
116282
+ case 117: /* multiselect_op ::= UNION */ yytestcase(yyruleno==117);
116283
+ case 119: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==119);
116284
+{yygotominor.yy4 = yymsp[0].major;}
114915116285
break;
114916116286
case 17: /* cmd ::= COMMIT trans_opt */
114917116287
case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18);
114918116288
{sqlite3CommitTransaction(pParse);}
114919116289
break;
@@ -114935,11 +116305,11 @@
114935116305
sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
114936116306
}
114937116307
break;
114938116308
case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
114939116309
{
114940
- sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy392,0,0,yymsp[-2].minor.yy392);
116310
+ sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
114941116311
}
114942116312
break;
114943116313
case 27: /* createkw ::= CREATE */
114944116314
{
114945116315
pParse->db->lookaside.bEnabled = 0;
@@ -114946,1051 +116316,1064 @@
114946116316
yygotominor.yy0 = yymsp[0].minor.yy0;
114947116317
}
114948116318
break;
114949116319
case 28: /* ifnotexists ::= */
114950116320
case 31: /* temp ::= */ yytestcase(yyruleno==31);
114951
- case 69: /* autoinc ::= */ yytestcase(yyruleno==69);
114952
- case 82: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==82);
114953
- case 84: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==84);
114954
- case 86: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==86);
114955
- case 98: /* defer_subclause_opt ::= */ yytestcase(yyruleno==98);
114956
- case 109: /* ifexists ::= */ yytestcase(yyruleno==109);
114957
- case 221: /* between_op ::= BETWEEN */ yytestcase(yyruleno==221);
114958
- case 224: /* in_op ::= IN */ yytestcase(yyruleno==224);
114959
-{yygotominor.yy392 = 0;}
116321
+ case 71: /* autoinc ::= */ yytestcase(yyruleno==71);
116322
+ case 84: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==84);
116323
+ case 86: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==86);
116324
+ case 88: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==88);
116325
+ case 100: /* defer_subclause_opt ::= */ yytestcase(yyruleno==100);
116326
+ case 111: /* ifexists ::= */ yytestcase(yyruleno==111);
116327
+ case 223: /* between_op ::= BETWEEN */ yytestcase(yyruleno==223);
116328
+ case 226: /* in_op ::= IN */ yytestcase(yyruleno==226);
116329
+{yygotominor.yy4 = 0;}
114960116330
break;
114961116331
case 29: /* ifnotexists ::= IF NOT EXISTS */
114962116332
case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
114963
- case 70: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==70);
114964
- case 85: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==85);
114965
- case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108);
114966
- case 222: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==222);
114967
- case 225: /* in_op ::= NOT IN */ yytestcase(yyruleno==225);
114968
-{yygotominor.yy392 = 1;}
116333
+ case 72: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==72);
116334
+ case 87: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==87);
116335
+ case 110: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==110);
116336
+ case 224: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==224);
116337
+ case 227: /* in_op ::= NOT IN */ yytestcase(yyruleno==227);
116338
+{yygotominor.yy4 = 1;}
114969116339
break;
114970
- case 32: /* create_table_args ::= LP columnlist conslist_opt RP */
116340
+ case 32: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
114971116341
{
114972
- sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
116342
+ sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy210,0);
114973116343
}
114974116344
break;
114975116345
case 33: /* create_table_args ::= AS select */
114976116346
{
114977
- sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy159);
114978
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
116347
+ sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy387);
116348
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
114979116349
}
114980116350
break;
114981
- case 36: /* column ::= columnid type carglist */
116351
+ case 34: /* table_options ::= */
116352
+{yygotominor.yy210 = 0;}
116353
+ break;
116354
+ case 35: /* table_options ::= WITHOUT nm */
116355
+{
116356
+ if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
116357
+ yygotominor.yy210 = TF_WithoutRowid;
116358
+ }else{
116359
+ yygotominor.yy210 = 0;
116360
+ sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
116361
+ }
116362
+}
116363
+ break;
116364
+ case 38: /* column ::= columnid type carglist */
114982116365
{
114983116366
yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
114984116367
yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
114985116368
}
114986116369
break;
114987
- case 37: /* columnid ::= nm */
116370
+ case 39: /* columnid ::= nm */
114988116371
{
114989116372
sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
114990116373
yygotominor.yy0 = yymsp[0].minor.yy0;
114991116374
pParse->constraintName.n = 0;
114992116375
}
114993116376
break;
114994
- case 38: /* id ::= ID */
114995
- case 39: /* id ::= INDEXED */ yytestcase(yyruleno==39);
114996
- case 40: /* ids ::= ID|STRING */ yytestcase(yyruleno==40);
114997
- case 41: /* nm ::= id */ yytestcase(yyruleno==41);
114998
- case 42: /* nm ::= STRING */ yytestcase(yyruleno==42);
114999
- case 43: /* nm ::= JOIN_KW */ yytestcase(yyruleno==43);
115000
- case 46: /* typetoken ::= typename */ yytestcase(yyruleno==46);
115001
- case 49: /* typename ::= ids */ yytestcase(yyruleno==49);
115002
- case 127: /* as ::= AS nm */ yytestcase(yyruleno==127);
115003
- case 128: /* as ::= ids */ yytestcase(yyruleno==128);
115004
- case 138: /* dbnm ::= DOT nm */ yytestcase(yyruleno==138);
115005
- case 147: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==147);
115006
- case 250: /* collate ::= COLLATE ids */ yytestcase(yyruleno==250);
115007
- case 259: /* nmnum ::= plus_num */ yytestcase(yyruleno==259);
115008
- case 260: /* nmnum ::= nm */ yytestcase(yyruleno==260);
115009
- case 261: /* nmnum ::= ON */ yytestcase(yyruleno==261);
115010
- case 262: /* nmnum ::= DELETE */ yytestcase(yyruleno==262);
115011
- case 263: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==263);
115012
- case 264: /* plus_num ::= PLUS number */ yytestcase(yyruleno==264);
115013
- case 265: /* plus_num ::= number */ yytestcase(yyruleno==265);
115014
- case 266: /* minus_num ::= MINUS number */ yytestcase(yyruleno==266);
115015
- case 267: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==267);
115016
- case 283: /* trnm ::= nm */ yytestcase(yyruleno==283);
116377
+ case 40: /* id ::= ID */
116378
+ case 41: /* id ::= INDEXED */ yytestcase(yyruleno==41);
116379
+ case 42: /* ids ::= ID|STRING */ yytestcase(yyruleno==42);
116380
+ case 43: /* nm ::= id */ yytestcase(yyruleno==43);
116381
+ case 44: /* nm ::= STRING */ yytestcase(yyruleno==44);
116382
+ case 45: /* nm ::= JOIN_KW */ yytestcase(yyruleno==45);
116383
+ case 48: /* typetoken ::= typename */ yytestcase(yyruleno==48);
116384
+ case 51: /* typename ::= ids */ yytestcase(yyruleno==51);
116385
+ case 129: /* as ::= AS nm */ yytestcase(yyruleno==129);
116386
+ case 130: /* as ::= ids */ yytestcase(yyruleno==130);
116387
+ case 140: /* dbnm ::= DOT nm */ yytestcase(yyruleno==140);
116388
+ case 149: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==149);
116389
+ case 252: /* collate ::= COLLATE ids */ yytestcase(yyruleno==252);
116390
+ case 261: /* nmnum ::= plus_num */ yytestcase(yyruleno==261);
116391
+ case 262: /* nmnum ::= nm */ yytestcase(yyruleno==262);
116392
+ case 263: /* nmnum ::= ON */ yytestcase(yyruleno==263);
116393
+ case 264: /* nmnum ::= DELETE */ yytestcase(yyruleno==264);
116394
+ case 265: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==265);
116395
+ case 266: /* plus_num ::= PLUS number */ yytestcase(yyruleno==266);
116396
+ case 267: /* plus_num ::= number */ yytestcase(yyruleno==267);
116397
+ case 268: /* minus_num ::= MINUS number */ yytestcase(yyruleno==268);
116398
+ case 269: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==269);
116399
+ case 285: /* trnm ::= nm */ yytestcase(yyruleno==285);
115017116400
{yygotominor.yy0 = yymsp[0].minor.yy0;}
115018116401
break;
115019
- case 45: /* type ::= typetoken */
116402
+ case 47: /* type ::= typetoken */
115020116403
{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
115021116404
break;
115022
- case 47: /* typetoken ::= typename LP signed RP */
116405
+ case 49: /* typetoken ::= typename LP signed RP */
115023116406
{
115024116407
yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
115025116408
yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
115026116409
}
115027116410
break;
115028
- case 48: /* typetoken ::= typename LP signed COMMA signed RP */
116411
+ case 50: /* typetoken ::= typename LP signed COMMA signed RP */
115029116412
{
115030116413
yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
115031116414
yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
115032116415
}
115033116416
break;
115034
- case 50: /* typename ::= typename ids */
116417
+ case 52: /* typename ::= typename ids */
115035116418
{yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
115036116419
break;
115037
- case 55: /* ccons ::= CONSTRAINT nm */
115038
- case 93: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==93);
116420
+ case 57: /* ccons ::= CONSTRAINT nm */
116421
+ case 95: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==95);
115039116422
{pParse->constraintName = yymsp[0].minor.yy0;}
115040116423
break;
115041
- case 56: /* ccons ::= DEFAULT term */
115042
- case 58: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==58);
115043
-{sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy342);}
115044
- break;
115045
- case 57: /* ccons ::= DEFAULT LP expr RP */
115046
-{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy342);}
115047
- break;
115048
- case 59: /* ccons ::= DEFAULT MINUS term */
116424
+ case 58: /* ccons ::= DEFAULT term */
116425
+ case 60: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==60);
116426
+{sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy118);}
116427
+ break;
116428
+ case 59: /* ccons ::= DEFAULT LP expr RP */
116429
+{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy118);}
116430
+ break;
116431
+ case 61: /* ccons ::= DEFAULT MINUS term */
115049116432
{
115050116433
ExprSpan v;
115051
- v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy342.pExpr, 0, 0);
116434
+ v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy118.pExpr, 0, 0);
115052116435
v.zStart = yymsp[-1].minor.yy0.z;
115053
- v.zEnd = yymsp[0].minor.yy342.zEnd;
116436
+ v.zEnd = yymsp[0].minor.yy118.zEnd;
115054116437
sqlite3AddDefaultValue(pParse,&v);
115055116438
}
115056116439
break;
115057
- case 60: /* ccons ::= DEFAULT id */
116440
+ case 62: /* ccons ::= DEFAULT id */
115058116441
{
115059116442
ExprSpan v;
115060116443
spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0);
115061116444
sqlite3AddDefaultValue(pParse,&v);
115062116445
}
115063116446
break;
115064
- case 62: /* ccons ::= NOT NULL onconf */
115065
-{sqlite3AddNotNull(pParse, yymsp[0].minor.yy392);}
115066
- break;
115067
- case 63: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
115068
-{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy392,yymsp[0].minor.yy392,yymsp[-2].minor.yy392);}
115069
- break;
115070
- case 64: /* ccons ::= UNIQUE onconf */
115071
-{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy392,0,0,0,0);}
115072
- break;
115073
- case 65: /* ccons ::= CHECK LP expr RP */
115074
-{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy342.pExpr);}
115075
- break;
115076
- case 66: /* ccons ::= REFERENCES nm idxlist_opt refargs */
115077
-{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy442,yymsp[0].minor.yy392);}
115078
- break;
115079
- case 67: /* ccons ::= defer_subclause */
115080
-{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy392);}
115081
- break;
115082
- case 68: /* ccons ::= COLLATE ids */
116447
+ case 64: /* ccons ::= NOT NULL onconf */
116448
+{sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
116449
+ break;
116450
+ case 65: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
116451
+{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
116452
+ break;
116453
+ case 66: /* ccons ::= UNIQUE onconf */
116454
+{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0);}
116455
+ break;
116456
+ case 67: /* ccons ::= CHECK LP expr RP */
116457
+{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy118.pExpr);}
116458
+ break;
116459
+ case 68: /* ccons ::= REFERENCES nm idxlist_opt refargs */
116460
+{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
116461
+ break;
116462
+ case 69: /* ccons ::= defer_subclause */
116463
+{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
116464
+ break;
116465
+ case 70: /* ccons ::= COLLATE ids */
115083116466
{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
115084116467
break;
115085
- case 71: /* refargs ::= */
115086
-{ yygotominor.yy392 = OE_None*0x0101; /* EV: R-19803-45884 */}
115087
- break;
115088
- case 72: /* refargs ::= refargs refarg */
115089
-{ yygotominor.yy392 = (yymsp[-1].minor.yy392 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; }
115090
- break;
115091
- case 73: /* refarg ::= MATCH nm */
115092
- case 74: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==74);
115093
-{ yygotominor.yy207.value = 0; yygotominor.yy207.mask = 0x000000; }
115094
- break;
115095
- case 75: /* refarg ::= ON DELETE refact */
115096
-{ yygotominor.yy207.value = yymsp[0].minor.yy392; yygotominor.yy207.mask = 0x0000ff; }
115097
- break;
115098
- case 76: /* refarg ::= ON UPDATE refact */
115099
-{ yygotominor.yy207.value = yymsp[0].minor.yy392<<8; yygotominor.yy207.mask = 0x00ff00; }
115100
- break;
115101
- case 77: /* refact ::= SET NULL */
115102
-{ yygotominor.yy392 = OE_SetNull; /* EV: R-33326-45252 */}
115103
- break;
115104
- case 78: /* refact ::= SET DEFAULT */
115105
-{ yygotominor.yy392 = OE_SetDflt; /* EV: R-33326-45252 */}
115106
- break;
115107
- case 79: /* refact ::= CASCADE */
115108
-{ yygotominor.yy392 = OE_Cascade; /* EV: R-33326-45252 */}
115109
- break;
115110
- case 80: /* refact ::= RESTRICT */
115111
-{ yygotominor.yy392 = OE_Restrict; /* EV: R-33326-45252 */}
115112
- break;
115113
- case 81: /* refact ::= NO ACTION */
115114
-{ yygotominor.yy392 = OE_None; /* EV: R-33326-45252 */}
115115
- break;
115116
- case 83: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
115117
- case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99);
115118
- case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101);
115119
- case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104);
115120
-{yygotominor.yy392 = yymsp[0].minor.yy392;}
115121
- break;
115122
- case 87: /* conslist_opt ::= */
116468
+ case 73: /* refargs ::= */
116469
+{ yygotominor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
116470
+ break;
116471
+ case 74: /* refargs ::= refargs refarg */
116472
+{ yygotominor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
116473
+ break;
116474
+ case 75: /* refarg ::= MATCH nm */
116475
+ case 76: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==76);
116476
+{ yygotominor.yy215.value = 0; yygotominor.yy215.mask = 0x000000; }
116477
+ break;
116478
+ case 77: /* refarg ::= ON DELETE refact */
116479
+{ yygotominor.yy215.value = yymsp[0].minor.yy4; yygotominor.yy215.mask = 0x0000ff; }
116480
+ break;
116481
+ case 78: /* refarg ::= ON UPDATE refact */
116482
+{ yygotominor.yy215.value = yymsp[0].minor.yy4<<8; yygotominor.yy215.mask = 0x00ff00; }
116483
+ break;
116484
+ case 79: /* refact ::= SET NULL */
116485
+{ yygotominor.yy4 = OE_SetNull; /* EV: R-33326-45252 */}
116486
+ break;
116487
+ case 80: /* refact ::= SET DEFAULT */
116488
+{ yygotominor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */}
116489
+ break;
116490
+ case 81: /* refact ::= CASCADE */
116491
+{ yygotominor.yy4 = OE_Cascade; /* EV: R-33326-45252 */}
116492
+ break;
116493
+ case 82: /* refact ::= RESTRICT */
116494
+{ yygotominor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
116495
+ break;
116496
+ case 83: /* refact ::= NO ACTION */
116497
+{ yygotominor.yy4 = OE_None; /* EV: R-33326-45252 */}
116498
+ break;
116499
+ case 85: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
116500
+ case 101: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==101);
116501
+ case 103: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==103);
116502
+ case 106: /* resolvetype ::= raisetype */ yytestcase(yyruleno==106);
116503
+{yygotominor.yy4 = yymsp[0].minor.yy4;}
116504
+ break;
116505
+ case 89: /* conslist_opt ::= */
115123116506
{yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
115124116507
break;
115125
- case 88: /* conslist_opt ::= COMMA conslist */
116508
+ case 90: /* conslist_opt ::= COMMA conslist */
115126116509
{yygotominor.yy0 = yymsp[-1].minor.yy0;}
115127116510
break;
115128
- case 91: /* tconscomma ::= COMMA */
116511
+ case 93: /* tconscomma ::= COMMA */
115129116512
{pParse->constraintName.n = 0;}
115130116513
break;
115131
- case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
115132
-{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy442,yymsp[0].minor.yy392,yymsp[-2].minor.yy392,0);}
115133
- break;
115134
- case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */
115135
-{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy442,yymsp[0].minor.yy392,0,0,0,0);}
115136
- break;
115137
- case 96: /* tcons ::= CHECK LP expr RP onconf */
115138
-{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy342.pExpr);}
115139
- break;
115140
- case 97: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
115141
-{
115142
- sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy442, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy442, yymsp[-1].minor.yy392);
115143
- sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy392);
115144
-}
115145
- break;
115146
- case 100: /* onconf ::= */
115147
-{yygotominor.yy392 = OE_Default;}
115148
- break;
115149
- case 102: /* orconf ::= */
115150
-{yygotominor.yy258 = OE_Default;}
115151
- break;
115152
- case 103: /* orconf ::= OR resolvetype */
115153
-{yygotominor.yy258 = (u8)yymsp[0].minor.yy392;}
115154
- break;
115155
- case 105: /* resolvetype ::= IGNORE */
115156
-{yygotominor.yy392 = OE_Ignore;}
115157
- break;
115158
- case 106: /* resolvetype ::= REPLACE */
115159
-{yygotominor.yy392 = OE_Replace;}
115160
- break;
115161
- case 107: /* cmd ::= DROP TABLE ifexists fullname */
115162
-{
115163
- sqlite3DropTable(pParse, yymsp[0].minor.yy347, 0, yymsp[-1].minor.yy392);
115164
-}
115165
- break;
115166
- case 110: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
115167
-{
115168
- sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy159, yymsp[-6].minor.yy392, yymsp[-4].minor.yy392);
115169
-}
115170
- break;
115171
- case 111: /* cmd ::= DROP VIEW ifexists fullname */
115172
-{
115173
- sqlite3DropTable(pParse, yymsp[0].minor.yy347, 1, yymsp[-1].minor.yy392);
115174
-}
115175
- break;
115176
- case 112: /* cmd ::= select */
116514
+ case 96: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
116515
+{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
116516
+ break;
116517
+ case 97: /* tcons ::= UNIQUE LP idxlist RP onconf */
116518
+{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0);}
116519
+ break;
116520
+ case 98: /* tcons ::= CHECK LP expr RP onconf */
116521
+{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy118.pExpr);}
116522
+ break;
116523
+ case 99: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
116524
+{
116525
+ sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
116526
+ sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
116527
+}
116528
+ break;
116529
+ case 102: /* onconf ::= */
116530
+{yygotominor.yy4 = OE_Default;}
116531
+ break;
116532
+ case 104: /* orconf ::= */
116533
+{yygotominor.yy210 = OE_Default;}
116534
+ break;
116535
+ case 105: /* orconf ::= OR resolvetype */
116536
+{yygotominor.yy210 = (u8)yymsp[0].minor.yy4;}
116537
+ break;
116538
+ case 107: /* resolvetype ::= IGNORE */
116539
+{yygotominor.yy4 = OE_Ignore;}
116540
+ break;
116541
+ case 108: /* resolvetype ::= REPLACE */
116542
+{yygotominor.yy4 = OE_Replace;}
116543
+ break;
116544
+ case 109: /* cmd ::= DROP TABLE ifexists fullname */
116545
+{
116546
+ sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
116547
+}
116548
+ break;
116549
+ case 112: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
116550
+{
116551
+ sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy387, yymsp[-6].minor.yy4, yymsp[-4].minor.yy4);
116552
+}
116553
+ break;
116554
+ case 113: /* cmd ::= DROP VIEW ifexists fullname */
116555
+{
116556
+ sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
116557
+}
116558
+ break;
116559
+ case 114: /* cmd ::= select */
115177116560
{
115178116561
SelectDest dest = {SRT_Output, 0, 0, 0, 0};
115179
- sqlite3Select(pParse, yymsp[0].minor.yy159, &dest);
116562
+ sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
115180116563
sqlite3ExplainBegin(pParse->pVdbe);
115181
- sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy159);
116564
+ sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy387);
115182116565
sqlite3ExplainFinish(pParse->pVdbe);
115183
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
115184
-}
115185
- break;
115186
- case 113: /* select ::= oneselect */
115187
-{yygotominor.yy159 = yymsp[0].minor.yy159;}
115188
- break;
115189
- case 114: /* select ::= select multiselect_op oneselect */
115190
-{
115191
- if( yymsp[0].minor.yy159 ){
115192
- yymsp[0].minor.yy159->op = (u8)yymsp[-1].minor.yy392;
115193
- yymsp[0].minor.yy159->pPrior = yymsp[-2].minor.yy159;
115194
- if( yymsp[-1].minor.yy392!=TK_ALL ) pParse->hasCompound = 1;
115195
- }else{
115196
- sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159);
115197
- }
115198
- yygotominor.yy159 = yymsp[0].minor.yy159;
115199
-}
115200
- break;
115201
- case 116: /* multiselect_op ::= UNION ALL */
115202
-{yygotominor.yy392 = TK_ALL;}
115203
- break;
115204
- case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
115205
-{
115206
- yygotominor.yy159 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy442,yymsp[-5].minor.yy347,yymsp[-4].minor.yy122,yymsp[-3].minor.yy442,yymsp[-2].minor.yy122,yymsp[-1].minor.yy442,yymsp[-7].minor.yy305,yymsp[0].minor.yy64.pLimit,yymsp[0].minor.yy64.pOffset);
115207
-}
115208
- break;
115209
- case 119: /* distinct ::= DISTINCT */
115210
-{yygotominor.yy305 = SF_Distinct;}
115211
- break;
115212
- case 120: /* distinct ::= ALL */
115213
- case 121: /* distinct ::= */ yytestcase(yyruleno==121);
115214
-{yygotominor.yy305 = 0;}
115215
- break;
115216
- case 122: /* sclp ::= selcollist COMMA */
115217
- case 246: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==246);
115218
-{yygotominor.yy442 = yymsp[-1].minor.yy442;}
115219
- break;
115220
- case 123: /* sclp ::= */
115221
- case 151: /* orderby_opt ::= */ yytestcase(yyruleno==151);
115222
- case 158: /* groupby_opt ::= */ yytestcase(yyruleno==158);
115223
- case 239: /* exprlist ::= */ yytestcase(yyruleno==239);
115224
- case 245: /* idxlist_opt ::= */ yytestcase(yyruleno==245);
115225
-{yygotominor.yy442 = 0;}
115226
- break;
115227
- case 124: /* selcollist ::= sclp expr as */
115228
-{
115229
- yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy442, yymsp[-1].minor.yy342.pExpr);
115230
- if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[0].minor.yy0, 1);
115231
- sqlite3ExprListSetSpan(pParse,yygotominor.yy442,&yymsp[-1].minor.yy342);
115232
-}
115233
- break;
115234
- case 125: /* selcollist ::= sclp STAR */
116566
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
116567
+}
116568
+ break;
116569
+ case 115: /* select ::= oneselect */
116570
+{yygotominor.yy387 = yymsp[0].minor.yy387;}
116571
+ break;
116572
+ case 116: /* select ::= select multiselect_op oneselect */
116573
+{
116574
+ if( yymsp[0].minor.yy387 ){
116575
+ yymsp[0].minor.yy387->op = (u8)yymsp[-1].minor.yy4;
116576
+ yymsp[0].minor.yy387->pPrior = yymsp[-2].minor.yy387;
116577
+ if( yymsp[-1].minor.yy4!=TK_ALL ) pParse->hasCompound = 1;
116578
+ }else{
116579
+ sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
116580
+ }
116581
+ yygotominor.yy387 = yymsp[0].minor.yy387;
116582
+}
116583
+ break;
116584
+ case 118: /* multiselect_op ::= UNION ALL */
116585
+{yygotominor.yy4 = TK_ALL;}
116586
+ break;
116587
+ case 120: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
116588
+{
116589
+ yygotominor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy177,yymsp[0].minor.yy292.pLimit,yymsp[0].minor.yy292.pOffset);
116590
+}
116591
+ break;
116592
+ case 121: /* distinct ::= DISTINCT */
116593
+{yygotominor.yy177 = SF_Distinct;}
116594
+ break;
116595
+ case 122: /* distinct ::= ALL */
116596
+ case 123: /* distinct ::= */ yytestcase(yyruleno==123);
116597
+{yygotominor.yy177 = 0;}
116598
+ break;
116599
+ case 124: /* sclp ::= selcollist COMMA */
116600
+ case 248: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==248);
116601
+{yygotominor.yy322 = yymsp[-1].minor.yy322;}
116602
+ break;
116603
+ case 125: /* sclp ::= */
116604
+ case 153: /* orderby_opt ::= */ yytestcase(yyruleno==153);
116605
+ case 160: /* groupby_opt ::= */ yytestcase(yyruleno==160);
116606
+ case 241: /* exprlist ::= */ yytestcase(yyruleno==241);
116607
+ case 247: /* idxlist_opt ::= */ yytestcase(yyruleno==247);
116608
+{yygotominor.yy322 = 0;}
116609
+ break;
116610
+ case 126: /* selcollist ::= sclp expr as */
116611
+{
116612
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, yymsp[-1].minor.yy118.pExpr);
116613
+ if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[0].minor.yy0, 1);
116614
+ sqlite3ExprListSetSpan(pParse,yygotominor.yy322,&yymsp[-1].minor.yy118);
116615
+}
116616
+ break;
116617
+ case 127: /* selcollist ::= sclp STAR */
115235116618
{
115236116619
Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
115237
- yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy442, p);
116620
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy322, p);
115238116621
}
115239116622
break;
115240
- case 126: /* selcollist ::= sclp nm DOT STAR */
116623
+ case 128: /* selcollist ::= sclp nm DOT STAR */
115241116624
{
115242116625
Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
115243116626
Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
115244116627
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
115245
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442, pDot);
116628
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, pDot);
115246116629
}
115247116630
break;
115248
- case 129: /* as ::= */
116631
+ case 131: /* as ::= */
115249116632
{yygotominor.yy0.n = 0;}
115250116633
break;
115251
- case 130: /* from ::= */
115252
-{yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));}
115253
- break;
115254
- case 131: /* from ::= FROM seltablist */
115255
-{
115256
- yygotominor.yy347 = yymsp[0].minor.yy347;
115257
- sqlite3SrcListShiftJoinType(yygotominor.yy347);
115258
-}
115259
- break;
115260
- case 132: /* stl_prefix ::= seltablist joinop */
115261
-{
115262
- yygotominor.yy347 = yymsp[-1].minor.yy347;
115263
- if( ALWAYS(yygotominor.yy347 && yygotominor.yy347->nSrc>0) ) yygotominor.yy347->a[yygotominor.yy347->nSrc-1].jointype = (u8)yymsp[0].minor.yy392;
115264
-}
115265
- break;
115266
- case 133: /* stl_prefix ::= */
115267
-{yygotominor.yy347 = 0;}
115268
- break;
115269
- case 134: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
115270
-{
115271
- yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
115272
- sqlite3SrcListIndexedBy(pParse, yygotominor.yy347, &yymsp[-2].minor.yy0);
115273
-}
115274
- break;
115275
- case 135: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
115276
-{
115277
- yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy159,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
115278
- }
115279
- break;
115280
- case 136: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
115281
-{
115282
- if( yymsp[-6].minor.yy347==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy122==0 && yymsp[0].minor.yy180==0 ){
115283
- yygotominor.yy347 = yymsp[-4].minor.yy347;
115284
- }else if( yymsp[-4].minor.yy347->nSrc==1 ){
115285
- yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
115286
- if( yygotominor.yy347 ){
115287
- struct SrcList_item *pNew = &yygotominor.yy347->a[yygotominor.yy347->nSrc-1];
115288
- struct SrcList_item *pOld = yymsp[-4].minor.yy347->a;
116634
+ case 132: /* from ::= */
116635
+{yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
116636
+ break;
116637
+ case 133: /* from ::= FROM seltablist */
116638
+{
116639
+ yygotominor.yy259 = yymsp[0].minor.yy259;
116640
+ sqlite3SrcListShiftJoinType(yygotominor.yy259);
116641
+}
116642
+ break;
116643
+ case 134: /* stl_prefix ::= seltablist joinop */
116644
+{
116645
+ yygotominor.yy259 = yymsp[-1].minor.yy259;
116646
+ if( ALWAYS(yygotominor.yy259 && yygotominor.yy259->nSrc>0) ) yygotominor.yy259->a[yygotominor.yy259->nSrc-1].jointype = (u8)yymsp[0].minor.yy4;
116647
+}
116648
+ break;
116649
+ case 135: /* stl_prefix ::= */
116650
+{yygotominor.yy259 = 0;}
116651
+ break;
116652
+ case 136: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
116653
+{
116654
+ yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
116655
+ sqlite3SrcListIndexedBy(pParse, yygotominor.yy259, &yymsp[-2].minor.yy0);
116656
+}
116657
+ break;
116658
+ case 137: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
116659
+{
116660
+ yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
116661
+ }
116662
+ break;
116663
+ case 138: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
116664
+{
116665
+ if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
116666
+ yygotominor.yy259 = yymsp[-4].minor.yy259;
116667
+ }else if( yymsp[-4].minor.yy259->nSrc==1 ){
116668
+ yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
116669
+ if( yygotominor.yy259 ){
116670
+ struct SrcList_item *pNew = &yygotominor.yy259->a[yygotominor.yy259->nSrc-1];
116671
+ struct SrcList_item *pOld = yymsp[-4].minor.yy259->a;
115289116672
pNew->zName = pOld->zName;
115290116673
pNew->zDatabase = pOld->zDatabase;
115291116674
pNew->pSelect = pOld->pSelect;
115292116675
pOld->zName = pOld->zDatabase = 0;
115293116676
pOld->pSelect = 0;
115294116677
}
115295
- sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy347);
116678
+ sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy259);
115296116679
}else{
115297116680
Select *pSubquery;
115298
- sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
115299
- pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy347,0,0,0,0,SF_NestedFrom,0,0);
115300
- yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
116681
+ sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
116682
+ pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,SF_NestedFrom,0,0);
116683
+ yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
115301116684
}
115302116685
}
115303116686
break;
115304
- case 137: /* dbnm ::= */
115305
- case 146: /* indexed_opt ::= */ yytestcase(yyruleno==146);
116687
+ case 139: /* dbnm ::= */
116688
+ case 148: /* indexed_opt ::= */ yytestcase(yyruleno==148);
115306116689
{yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
115307116690
break;
115308
- case 139: /* fullname ::= nm dbnm */
115309
-{yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
115310
- break;
115311
- case 140: /* joinop ::= COMMA|JOIN */
115312
-{ yygotominor.yy392 = JT_INNER; }
115313
- break;
115314
- case 141: /* joinop ::= JOIN_KW JOIN */
115315
-{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
115316
- break;
115317
- case 142: /* joinop ::= JOIN_KW nm JOIN */
115318
-{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
115319
- break;
115320
- case 143: /* joinop ::= JOIN_KW nm nm JOIN */
115321
-{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
115322
- break;
115323
- case 144: /* on_opt ::= ON expr */
115324
- case 161: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==161);
115325
- case 168: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==168);
115326
- case 234: /* case_else ::= ELSE expr */ yytestcase(yyruleno==234);
115327
- case 236: /* case_operand ::= expr */ yytestcase(yyruleno==236);
115328
-{yygotominor.yy122 = yymsp[0].minor.yy342.pExpr;}
115329
- break;
115330
- case 145: /* on_opt ::= */
115331
- case 160: /* having_opt ::= */ yytestcase(yyruleno==160);
115332
- case 167: /* where_opt ::= */ yytestcase(yyruleno==167);
115333
- case 235: /* case_else ::= */ yytestcase(yyruleno==235);
115334
- case 237: /* case_operand ::= */ yytestcase(yyruleno==237);
115335
-{yygotominor.yy122 = 0;}
115336
- break;
115337
- case 148: /* indexed_opt ::= NOT INDEXED */
116691
+ case 141: /* fullname ::= nm dbnm */
116692
+{yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
116693
+ break;
116694
+ case 142: /* joinop ::= COMMA|JOIN */
116695
+{ yygotominor.yy4 = JT_INNER; }
116696
+ break;
116697
+ case 143: /* joinop ::= JOIN_KW JOIN */
116698
+{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
116699
+ break;
116700
+ case 144: /* joinop ::= JOIN_KW nm JOIN */
116701
+{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
116702
+ break;
116703
+ case 145: /* joinop ::= JOIN_KW nm nm JOIN */
116704
+{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
116705
+ break;
116706
+ case 146: /* on_opt ::= ON expr */
116707
+ case 163: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==163);
116708
+ case 170: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==170);
116709
+ case 236: /* case_else ::= ELSE expr */ yytestcase(yyruleno==236);
116710
+ case 238: /* case_operand ::= expr */ yytestcase(yyruleno==238);
116711
+{yygotominor.yy314 = yymsp[0].minor.yy118.pExpr;}
116712
+ break;
116713
+ case 147: /* on_opt ::= */
116714
+ case 162: /* having_opt ::= */ yytestcase(yyruleno==162);
116715
+ case 169: /* where_opt ::= */ yytestcase(yyruleno==169);
116716
+ case 237: /* case_else ::= */ yytestcase(yyruleno==237);
116717
+ case 239: /* case_operand ::= */ yytestcase(yyruleno==239);
116718
+{yygotominor.yy314 = 0;}
116719
+ break;
116720
+ case 150: /* indexed_opt ::= NOT INDEXED */
115338116721
{yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
115339116722
break;
115340
- case 149: /* using_opt ::= USING LP inscollist RP */
115341
- case 180: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==180);
115342
-{yygotominor.yy180 = yymsp[-1].minor.yy180;}
115343
- break;
115344
- case 150: /* using_opt ::= */
115345
- case 179: /* inscollist_opt ::= */ yytestcase(yyruleno==179);
115346
-{yygotominor.yy180 = 0;}
115347
- break;
115348
- case 152: /* orderby_opt ::= ORDER BY sortlist */
115349
- case 159: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==159);
115350
- case 238: /* exprlist ::= nexprlist */ yytestcase(yyruleno==238);
115351
-{yygotominor.yy442 = yymsp[0].minor.yy442;}
115352
- break;
115353
- case 153: /* sortlist ::= sortlist COMMA expr sortorder */
115354
-{
115355
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442,yymsp[-1].minor.yy342.pExpr);
115356
- if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
115357
-}
115358
- break;
115359
- case 154: /* sortlist ::= expr sortorder */
115360
-{
115361
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy342.pExpr);
115362
- if( yygotominor.yy442 && ALWAYS(yygotominor.yy442->a) ) yygotominor.yy442->a[0].sortOrder = (u8)yymsp[0].minor.yy392;
115363
-}
115364
- break;
115365
- case 155: /* sortorder ::= ASC */
115366
- case 157: /* sortorder ::= */ yytestcase(yyruleno==157);
115367
-{yygotominor.yy392 = SQLITE_SO_ASC;}
115368
- break;
115369
- case 156: /* sortorder ::= DESC */
115370
-{yygotominor.yy392 = SQLITE_SO_DESC;}
115371
- break;
115372
- case 162: /* limit_opt ::= */
115373
-{yygotominor.yy64.pLimit = 0; yygotominor.yy64.pOffset = 0;}
115374
- break;
115375
- case 163: /* limit_opt ::= LIMIT expr */
115376
-{yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr; yygotominor.yy64.pOffset = 0;}
115377
- break;
115378
- case 164: /* limit_opt ::= LIMIT expr OFFSET expr */
115379
-{yygotominor.yy64.pLimit = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pOffset = yymsp[0].minor.yy342.pExpr;}
115380
- break;
115381
- case 165: /* limit_opt ::= LIMIT expr COMMA expr */
115382
-{yygotominor.yy64.pOffset = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr;}
115383
- break;
115384
- case 166: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
115385
-{
115386
- sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy347, &yymsp[-1].minor.yy0);
115387
- sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy347,yymsp[0].minor.yy122);
115388
-}
115389
- break;
115390
- case 169: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
115391
-{
115392
- sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy347, &yymsp[-3].minor.yy0);
115393
- sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy442,"set list");
115394
- sqlite3Update(pParse,yymsp[-4].minor.yy347,yymsp[-1].minor.yy442,yymsp[0].minor.yy122,yymsp[-5].minor.yy258);
115395
-}
115396
- break;
115397
- case 170: /* setlist ::= setlist COMMA nm EQ expr */
115398
-{
115399
- yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy442, yymsp[0].minor.yy342.pExpr);
115400
- sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
115401
-}
115402
- break;
115403
- case 171: /* setlist ::= nm EQ expr */
115404
-{
115405
- yygotominor.yy442 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy342.pExpr);
115406
- sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
115407
-}
115408
- break;
115409
- case 172: /* cmd ::= insert_cmd INTO fullname inscollist_opt valuelist */
115410
-{sqlite3Insert(pParse, yymsp[-2].minor.yy347, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);}
115411
- break;
115412
- case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
115413
-{sqlite3Insert(pParse, yymsp[-2].minor.yy347, 0, yymsp[0].minor.yy159, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);}
115414
- break;
115415
- case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
115416
-{sqlite3Insert(pParse, yymsp[-3].minor.yy347, 0, 0, yymsp[-2].minor.yy180, yymsp[-5].minor.yy258);}
115417
- break;
115418
- case 175: /* insert_cmd ::= INSERT orconf */
115419
-{yygotominor.yy258 = yymsp[0].minor.yy258;}
115420
- break;
115421
- case 176: /* insert_cmd ::= REPLACE */
115422
-{yygotominor.yy258 = OE_Replace;}
115423
- break;
115424
- case 177: /* valuelist ::= VALUES LP nexprlist RP */
115425
-{
115426
- yygotominor.yy487.pList = yymsp[-1].minor.yy442;
115427
- yygotominor.yy487.pSelect = 0;
115428
-}
115429
- break;
115430
- case 178: /* valuelist ::= valuelist COMMA LP exprlist RP */
115431
-{
115432
- Select *pRight = sqlite3SelectNew(pParse, yymsp[-1].minor.yy442, 0, 0, 0, 0, 0, 0, 0, 0);
115433
- if( yymsp[-4].minor.yy487.pList ){
115434
- yymsp[-4].minor.yy487.pSelect = sqlite3SelectNew(pParse, yymsp[-4].minor.yy487.pList, 0, 0, 0, 0, 0, 0, 0, 0);
115435
- yymsp[-4].minor.yy487.pList = 0;
115436
- }
115437
- yygotominor.yy487.pList = 0;
115438
- if( yymsp[-4].minor.yy487.pSelect==0 || pRight==0 ){
116723
+ case 151: /* using_opt ::= USING LP idlist RP */
116724
+ case 182: /* inscollist_opt ::= LP idlist RP */ yytestcase(yyruleno==182);
116725
+{yygotominor.yy384 = yymsp[-1].minor.yy384;}
116726
+ break;
116727
+ case 152: /* using_opt ::= */
116728
+ case 181: /* inscollist_opt ::= */ yytestcase(yyruleno==181);
116729
+{yygotominor.yy384 = 0;}
116730
+ break;
116731
+ case 154: /* orderby_opt ::= ORDER BY sortlist */
116732
+ case 161: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==161);
116733
+ case 240: /* exprlist ::= nexprlist */ yytestcase(yyruleno==240);
116734
+{yygotominor.yy322 = yymsp[0].minor.yy322;}
116735
+ break;
116736
+ case 155: /* sortlist ::= sortlist COMMA expr sortorder */
116737
+{
116738
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy118.pExpr);
116739
+ if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
116740
+}
116741
+ break;
116742
+ case 156: /* sortlist ::= expr sortorder */
116743
+{
116744
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy118.pExpr);
116745
+ if( yygotominor.yy322 && ALWAYS(yygotominor.yy322->a) ) yygotominor.yy322->a[0].sortOrder = (u8)yymsp[0].minor.yy4;
116746
+}
116747
+ break;
116748
+ case 157: /* sortorder ::= ASC */
116749
+ case 159: /* sortorder ::= */ yytestcase(yyruleno==159);
116750
+{yygotominor.yy4 = SQLITE_SO_ASC;}
116751
+ break;
116752
+ case 158: /* sortorder ::= DESC */
116753
+{yygotominor.yy4 = SQLITE_SO_DESC;}
116754
+ break;
116755
+ case 164: /* limit_opt ::= */
116756
+{yygotominor.yy292.pLimit = 0; yygotominor.yy292.pOffset = 0;}
116757
+ break;
116758
+ case 165: /* limit_opt ::= LIMIT expr */
116759
+{yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr; yygotominor.yy292.pOffset = 0;}
116760
+ break;
116761
+ case 166: /* limit_opt ::= LIMIT expr OFFSET expr */
116762
+{yygotominor.yy292.pLimit = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pOffset = yymsp[0].minor.yy118.pExpr;}
116763
+ break;
116764
+ case 167: /* limit_opt ::= LIMIT expr COMMA expr */
116765
+{yygotominor.yy292.pOffset = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr;}
116766
+ break;
116767
+ case 168: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
116768
+{
116769
+ sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
116770
+ sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314);
116771
+}
116772
+ break;
116773
+ case 171: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
116774
+{
116775
+ sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
116776
+ sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list");
116777
+ sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy210);
116778
+}
116779
+ break;
116780
+ case 172: /* setlist ::= setlist COMMA nm EQ expr */
116781
+{
116782
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy118.pExpr);
116783
+ sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
116784
+}
116785
+ break;
116786
+ case 173: /* setlist ::= nm EQ expr */
116787
+{
116788
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy118.pExpr);
116789
+ sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
116790
+}
116791
+ break;
116792
+ case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt valuelist */
116793
+{sqlite3Insert(pParse, yymsp[-2].minor.yy259, yymsp[0].minor.yy260.pList, yymsp[0].minor.yy260.pSelect, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
116794
+ break;
116795
+ case 175: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
116796
+{sqlite3Insert(pParse, yymsp[-2].minor.yy259, 0, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
116797
+ break;
116798
+ case 176: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
116799
+{sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy210);}
116800
+ break;
116801
+ case 177: /* insert_cmd ::= INSERT orconf */
116802
+{yygotominor.yy210 = yymsp[0].minor.yy210;}
116803
+ break;
116804
+ case 178: /* insert_cmd ::= REPLACE */
116805
+{yygotominor.yy210 = OE_Replace;}
116806
+ break;
116807
+ case 179: /* valuelist ::= VALUES LP nexprlist RP */
116808
+{
116809
+ yygotominor.yy260.pList = yymsp[-1].minor.yy322;
116810
+ yygotominor.yy260.pSelect = 0;
116811
+}
116812
+ break;
116813
+ case 180: /* valuelist ::= valuelist COMMA LP exprlist RP */
116814
+{
116815
+ Select *pRight = sqlite3SelectNew(pParse, yymsp[-1].minor.yy322, 0, 0, 0, 0, 0, 0, 0, 0);
116816
+ if( yymsp[-4].minor.yy260.pList ){
116817
+ yymsp[-4].minor.yy260.pSelect = sqlite3SelectNew(pParse, yymsp[-4].minor.yy260.pList, 0, 0, 0, 0, 0, 0, 0, 0);
116818
+ yymsp[-4].minor.yy260.pList = 0;
116819
+ }
116820
+ yygotominor.yy260.pList = 0;
116821
+ if( yymsp[-4].minor.yy260.pSelect==0 || pRight==0 ){
115439116822
sqlite3SelectDelete(pParse->db, pRight);
115440
- sqlite3SelectDelete(pParse->db, yymsp[-4].minor.yy487.pSelect);
115441
- yygotominor.yy487.pSelect = 0;
116823
+ sqlite3SelectDelete(pParse->db, yymsp[-4].minor.yy260.pSelect);
116824
+ yygotominor.yy260.pSelect = 0;
115442116825
}else{
115443116826
pRight->op = TK_ALL;
115444
- pRight->pPrior = yymsp[-4].minor.yy487.pSelect;
116827
+ pRight->pPrior = yymsp[-4].minor.yy260.pSelect;
115445116828
pRight->selFlags |= SF_Values;
115446116829
pRight->pPrior->selFlags |= SF_Values;
115447
- yygotominor.yy487.pSelect = pRight;
115448
- }
115449
-}
115450
- break;
115451
- case 181: /* inscollist ::= inscollist COMMA nm */
115452
-{yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);}
115453
- break;
115454
- case 182: /* inscollist ::= nm */
115455
-{yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
115456
- break;
115457
- case 183: /* expr ::= term */
115458
-{yygotominor.yy342 = yymsp[0].minor.yy342;}
115459
- break;
115460
- case 184: /* expr ::= LP expr RP */
115461
-{yygotominor.yy342.pExpr = yymsp[-1].minor.yy342.pExpr; spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
115462
- break;
115463
- case 185: /* term ::= NULL */
115464
- case 190: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==190);
115465
- case 191: /* term ::= STRING */ yytestcase(yyruleno==191);
115466
-{spanExpr(&yygotominor.yy342, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
115467
- break;
115468
- case 186: /* expr ::= id */
115469
- case 187: /* expr ::= JOIN_KW */ yytestcase(yyruleno==187);
115470
-{spanExpr(&yygotominor.yy342, pParse, TK_ID, &yymsp[0].minor.yy0);}
115471
- break;
115472
- case 188: /* expr ::= nm DOT nm */
116830
+ yygotominor.yy260.pSelect = pRight;
116831
+ }
116832
+}
116833
+ break;
116834
+ case 183: /* idlist ::= idlist COMMA nm */
116835
+{yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
116836
+ break;
116837
+ case 184: /* idlist ::= nm */
116838
+{yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
116839
+ break;
116840
+ case 185: /* expr ::= term */
116841
+{yygotominor.yy118 = yymsp[0].minor.yy118;}
116842
+ break;
116843
+ case 186: /* expr ::= LP expr RP */
116844
+{yygotominor.yy118.pExpr = yymsp[-1].minor.yy118.pExpr; spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
116845
+ break;
116846
+ case 187: /* term ::= NULL */
116847
+ case 192: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==192);
116848
+ case 193: /* term ::= STRING */ yytestcase(yyruleno==193);
116849
+{spanExpr(&yygotominor.yy118, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
116850
+ break;
116851
+ case 188: /* expr ::= id */
116852
+ case 189: /* expr ::= JOIN_KW */ yytestcase(yyruleno==189);
116853
+{spanExpr(&yygotominor.yy118, pParse, TK_ID, &yymsp[0].minor.yy0);}
116854
+ break;
116855
+ case 190: /* expr ::= nm DOT nm */
115473116856
{
115474116857
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
115475116858
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
115476
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
115477
- spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
116859
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
116860
+ spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
115478116861
}
115479116862
break;
115480
- case 189: /* expr ::= nm DOT nm DOT nm */
116863
+ case 191: /* expr ::= nm DOT nm DOT nm */
115481116864
{
115482116865
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
115483116866
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
115484116867
Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
115485116868
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
115486
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
115487
- spanSet(&yygotominor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
116869
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
116870
+ spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
115488116871
}
115489116872
break;
115490
- case 192: /* expr ::= REGISTER */
116873
+ case 194: /* expr ::= REGISTER */
115491116874
{
115492116875
/* When doing a nested parse, one can include terms in an expression
115493116876
** that look like this: #1 #2 ... These terms refer to registers
115494116877
** in the virtual machine. #N is the N-th register. */
115495116878
if( pParse->nested==0 ){
115496116879
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &yymsp[0].minor.yy0);
115497
- yygotominor.yy342.pExpr = 0;
115498
- }else{
115499
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
115500
- if( yygotominor.yy342.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy342.pExpr->iTable);
115501
- }
115502
- spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
115503
-}
115504
- break;
115505
- case 193: /* expr ::= VARIABLE */
115506
-{
115507
- spanExpr(&yygotominor.yy342, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
115508
- sqlite3ExprAssignVarNumber(pParse, yygotominor.yy342.pExpr);
115509
- spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
115510
-}
115511
- break;
115512
- case 194: /* expr ::= expr COLLATE ids */
115513
-{
115514
- yygotominor.yy342.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0);
115515
- yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart;
115516
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115517
-}
115518
- break;
115519
- case 195: /* expr ::= CAST LP expr AS typetoken RP */
115520
-{
115521
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy342.pExpr, 0, &yymsp[-1].minor.yy0);
115522
- spanSet(&yygotominor.yy342,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
115523
-}
115524
- break;
115525
- case 196: /* expr ::= ID LP distinct exprlist RP */
115526
-{
115527
- if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
116880
+ yygotominor.yy118.pExpr = 0;
116881
+ }else{
116882
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
116883
+ if( yygotominor.yy118.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy118.pExpr->iTable);
116884
+ }
116885
+ spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116886
+}
116887
+ break;
116888
+ case 195: /* expr ::= VARIABLE */
116889
+{
116890
+ spanExpr(&yygotominor.yy118, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
116891
+ sqlite3ExprAssignVarNumber(pParse, yygotominor.yy118.pExpr);
116892
+ spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116893
+}
116894
+ break;
116895
+ case 196: /* expr ::= expr COLLATE ids */
116896
+{
116897
+ yygotominor.yy118.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
116898
+ yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
116899
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
116900
+}
116901
+ break;
116902
+ case 197: /* expr ::= CAST LP expr AS typetoken RP */
116903
+{
116904
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy118.pExpr, 0, &yymsp[-1].minor.yy0);
116905
+ spanSet(&yygotominor.yy118,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
116906
+}
116907
+ break;
116908
+ case 198: /* expr ::= ID LP distinct exprlist RP */
116909
+{
116910
+ if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
115528116911
sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
115529116912
}
115530
- yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy442, &yymsp[-4].minor.yy0);
115531
- spanSet(&yygotominor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
115532
- if( yymsp[-2].minor.yy305 && yygotominor.yy342.pExpr ){
115533
- yygotominor.yy342.pExpr->flags |= EP_Distinct;
115534
- }
115535
-}
115536
- break;
115537
- case 197: /* expr ::= ID LP STAR RP */
115538
-{
115539
- yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
115540
- spanSet(&yygotominor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
115541
-}
115542
- break;
115543
- case 198: /* term ::= CTIME_KW */
116913
+ yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
116914
+ spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
116915
+ if( yymsp[-2].minor.yy177 && yygotominor.yy118.pExpr ){
116916
+ yygotominor.yy118.pExpr->flags |= EP_Distinct;
116917
+ }
116918
+}
116919
+ break;
116920
+ case 199: /* expr ::= ID LP STAR RP */
116921
+{
116922
+ yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
116923
+ spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
116924
+}
116925
+ break;
116926
+ case 200: /* term ::= CTIME_KW */
115544116927
{
115545116928
/* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
115546116929
** treated as functions that return constants */
115547
- yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
115548
- if( yygotominor.yy342.pExpr ){
115549
- yygotominor.yy342.pExpr->op = TK_CONST_FUNC;
115550
- }
115551
- spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
115552
-}
115553
- break;
115554
- case 199: /* expr ::= expr AND expr */
115555
- case 200: /* expr ::= expr OR expr */ yytestcase(yyruleno==200);
115556
- case 201: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==201);
115557
- case 202: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==202);
115558
- case 203: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==203);
115559
- case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204);
115560
- case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205);
115561
- case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206);
115562
-{spanBinaryExpr(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);}
115563
- break;
115564
- case 207: /* likeop ::= LIKE_KW */
115565
- case 209: /* likeop ::= MATCH */ yytestcase(yyruleno==209);
115566
-{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 0;}
115567
- break;
115568
- case 208: /* likeop ::= NOT LIKE_KW */
115569
- case 210: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==210);
115570
-{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 1;}
115571
- break;
115572
- case 211: /* expr ::= expr likeop expr */
115573
-{
115574
- ExprList *pList;
115575
- pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy342.pExpr);
115576
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy342.pExpr);
115577
- yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy318.eOperator);
115578
- if( yymsp[-1].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115579
- yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart;
115580
- yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
115581
- if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc;
115582
-}
115583
- break;
115584
- case 212: /* expr ::= expr likeop expr ESCAPE expr */
115585
-{
115586
- ExprList *pList;
115587
- pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
115588
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy342.pExpr);
115589
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr);
115590
- yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy318.eOperator);
115591
- if( yymsp[-3].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115592
- yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115593
- yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
115594
- if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc;
115595
-}
115596
- break;
115597
- case 213: /* expr ::= expr ISNULL|NOTNULL */
115598
-{spanUnaryPostfix(&yygotominor.yy342,pParse,yymsp[0].major,&yymsp[-1].minor.yy342,&yymsp[0].minor.yy0);}
115599
- break;
115600
- case 214: /* expr ::= expr NOT NULL */
115601
-{spanUnaryPostfix(&yygotominor.yy342,pParse,TK_NOTNULL,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy0);}
115602
- break;
115603
- case 215: /* expr ::= expr IS expr */
115604
-{
115605
- spanBinaryExpr(&yygotominor.yy342,pParse,TK_IS,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);
115606
- binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_ISNULL);
115607
-}
115608
- break;
115609
- case 216: /* expr ::= expr IS NOT expr */
115610
-{
115611
- spanBinaryExpr(&yygotominor.yy342,pParse,TK_ISNOT,&yymsp[-3].minor.yy342,&yymsp[0].minor.yy342);
115612
- binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_NOTNULL);
115613
-}
115614
- break;
115615
- case 217: /* expr ::= NOT expr */
115616
- case 218: /* expr ::= BITNOT expr */ yytestcase(yyruleno==218);
115617
-{spanUnaryPrefix(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
115618
- break;
115619
- case 219: /* expr ::= MINUS expr */
115620
-{spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UMINUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
115621
- break;
115622
- case 220: /* expr ::= PLUS expr */
115623
-{spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UPLUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
115624
- break;
115625
- case 223: /* expr ::= expr between_op expr AND expr */
115626
-{
115627
- ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
115628
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr);
115629
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy342.pExpr, 0, 0);
115630
- if( yygotominor.yy342.pExpr ){
115631
- yygotominor.yy342.pExpr->x.pList = pList;
116930
+ yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
116931
+ if( yygotominor.yy118.pExpr ){
116932
+ yygotominor.yy118.pExpr->op = TK_CONST_FUNC;
116933
+ }
116934
+ spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116935
+}
116936
+ break;
116937
+ case 201: /* expr ::= expr AND expr */
116938
+ case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
116939
+ case 203: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==203);
116940
+ case 204: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==204);
116941
+ case 205: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==205);
116942
+ case 206: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==206);
116943
+ case 207: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==207);
116944
+ case 208: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==208);
116945
+{spanBinaryExpr(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);}
116946
+ break;
116947
+ case 209: /* likeop ::= LIKE_KW */
116948
+ case 211: /* likeop ::= MATCH */ yytestcase(yyruleno==211);
116949
+{yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.bNot = 0;}
116950
+ break;
116951
+ case 210: /* likeop ::= NOT LIKE_KW */
116952
+ case 212: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==212);
116953
+{yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.bNot = 1;}
116954
+ break;
116955
+ case 213: /* expr ::= expr likeop expr */
116956
+{
116957
+ ExprList *pList;
116958
+ pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy118.pExpr);
116959
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy118.pExpr);
116960
+ yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy342.eOperator);
116961
+ if( yymsp[-1].minor.yy342.bNot ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
116962
+ yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
116963
+ yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
116964
+ if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
116965
+}
116966
+ break;
116967
+ case 214: /* expr ::= expr likeop expr ESCAPE expr */
116968
+{
116969
+ ExprList *pList;
116970
+ pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
116971
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy118.pExpr);
116972
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
116973
+ yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy342.eOperator);
116974
+ if( yymsp[-3].minor.yy342.bNot ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
116975
+ yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
116976
+ yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
116977
+ if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
116978
+}
116979
+ break;
116980
+ case 215: /* expr ::= expr ISNULL|NOTNULL */
116981
+{spanUnaryPostfix(&yygotominor.yy118,pParse,yymsp[0].major,&yymsp[-1].minor.yy118,&yymsp[0].minor.yy0);}
116982
+ break;
116983
+ case 216: /* expr ::= expr NOT NULL */
116984
+{spanUnaryPostfix(&yygotominor.yy118,pParse,TK_NOTNULL,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy0);}
116985
+ break;
116986
+ case 217: /* expr ::= expr IS expr */
116987
+{
116988
+ spanBinaryExpr(&yygotominor.yy118,pParse,TK_IS,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);
116989
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_ISNULL);
116990
+}
116991
+ break;
116992
+ case 218: /* expr ::= expr IS NOT expr */
116993
+{
116994
+ spanBinaryExpr(&yygotominor.yy118,pParse,TK_ISNOT,&yymsp[-3].minor.yy118,&yymsp[0].minor.yy118);
116995
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_NOTNULL);
116996
+}
116997
+ break;
116998
+ case 219: /* expr ::= NOT expr */
116999
+ case 220: /* expr ::= BITNOT expr */ yytestcase(yyruleno==220);
117000
+{spanUnaryPrefix(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
117001
+ break;
117002
+ case 221: /* expr ::= MINUS expr */
117003
+{spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UMINUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
117004
+ break;
117005
+ case 222: /* expr ::= PLUS expr */
117006
+{spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UPLUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
117007
+ break;
117008
+ case 225: /* expr ::= expr between_op expr AND expr */
117009
+{
117010
+ ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
117011
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
117012
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy118.pExpr, 0, 0);
117013
+ if( yygotominor.yy118.pExpr ){
117014
+ yygotominor.yy118.pExpr->x.pList = pList;
115632117015
}else{
115633117016
sqlite3ExprListDelete(pParse->db, pList);
115634117017
}
115635
- if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115636
- yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115637
- yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
115638
-}
115639
- break;
115640
- case 226: /* expr ::= expr in_op LP exprlist RP */
115641
-{
115642
- if( yymsp[-1].minor.yy442==0 ){
117018
+ if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117019
+ yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
117020
+ yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
117021
+}
117022
+ break;
117023
+ case 228: /* expr ::= expr in_op LP exprlist RP */
117024
+{
117025
+ if( yymsp[-1].minor.yy322==0 ){
115643117026
/* Expressions of the form
115644117027
**
115645117028
** expr1 IN ()
115646117029
** expr1 NOT IN ()
115647117030
**
115648117031
** simplify to constants 0 (false) and 1 (true), respectively,
115649117032
** regardless of the value of expr1.
115650117033
*/
115651
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy392]);
115652
- sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy342.pExpr);
115653
- }else{
115654
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
115655
- if( yygotominor.yy342.pExpr ){
115656
- yygotominor.yy342.pExpr->x.pList = yymsp[-1].minor.yy442;
115657
- sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115658
- }else{
115659
- sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy442);
115660
- }
115661
- if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115662
- }
115663
- yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115664
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115665
- }
115666
- break;
115667
- case 227: /* expr ::= LP select RP */
115668
-{
115669
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
115670
- if( yygotominor.yy342.pExpr ){
115671
- yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
115672
- ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
115673
- sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115674
- }else{
115675
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
115676
- }
115677
- yygotominor.yy342.zStart = yymsp[-2].minor.yy0.z;
115678
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115679
- }
115680
- break;
115681
- case 228: /* expr ::= expr in_op LP select RP */
115682
-{
115683
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
115684
- if( yygotominor.yy342.pExpr ){
115685
- yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
115686
- ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
115687
- sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115688
- }else{
115689
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
115690
- }
115691
- if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115692
- yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115693
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115694
- }
115695
- break;
115696
- case 229: /* expr ::= expr in_op nm dbnm */
117034
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy4]);
117035
+ sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy118.pExpr);
117036
+ }else{
117037
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
117038
+ if( yygotominor.yy118.pExpr ){
117039
+ yygotominor.yy118.pExpr->x.pList = yymsp[-1].minor.yy322;
117040
+ sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117041
+ }else{
117042
+ sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
117043
+ }
117044
+ if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117045
+ }
117046
+ yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
117047
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117048
+ }
117049
+ break;
117050
+ case 229: /* expr ::= LP select RP */
117051
+{
117052
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
117053
+ if( yygotominor.yy118.pExpr ){
117054
+ yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
117055
+ ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
117056
+ sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117057
+ }else{
117058
+ sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
117059
+ }
117060
+ yygotominor.yy118.zStart = yymsp[-2].minor.yy0.z;
117061
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117062
+ }
117063
+ break;
117064
+ case 230: /* expr ::= expr in_op LP select RP */
117065
+{
117066
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
117067
+ if( yygotominor.yy118.pExpr ){
117068
+ yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
117069
+ ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
117070
+ sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117071
+ }else{
117072
+ sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
117073
+ }
117074
+ if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117075
+ yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
117076
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117077
+ }
117078
+ break;
117079
+ case 231: /* expr ::= expr in_op nm dbnm */
115697117080
{
115698117081
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
115699
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
115700
- if( yygotominor.yy342.pExpr ){
115701
- yygotominor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
115702
- ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
115703
- sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
117082
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy118.pExpr, 0, 0);
117083
+ if( yygotominor.yy118.pExpr ){
117084
+ yygotominor.yy118.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
117085
+ ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
117086
+ sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
115704117087
}else{
115705117088
sqlite3SrcListDelete(pParse->db, pSrc);
115706117089
}
115707
- if( yymsp[-2].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115708
- yygotominor.yy342.zStart = yymsp[-3].minor.yy342.zStart;
115709
- yygotominor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
115710
- }
115711
- break;
115712
- case 230: /* expr ::= EXISTS LP select RP */
115713
-{
115714
- Expr *p = yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
117090
+ if( yymsp[-2].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117091
+ yygotominor.yy118.zStart = yymsp[-3].minor.yy118.zStart;
117092
+ yygotominor.yy118.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
117093
+ }
117094
+ break;
117095
+ case 232: /* expr ::= EXISTS LP select RP */
117096
+{
117097
+ Expr *p = yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
115715117098
if( p ){
115716
- p->x.pSelect = yymsp[-1].minor.yy159;
117099
+ p->x.pSelect = yymsp[-1].minor.yy387;
115717117100
ExprSetProperty(p, EP_xIsSelect);
115718117101
sqlite3ExprSetHeight(pParse, p);
115719117102
}else{
115720
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
115721
- }
115722
- yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z;
115723
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115724
- }
115725
- break;
115726
- case 231: /* expr ::= CASE case_operand case_exprlist case_else END */
115727
-{
115728
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, 0, 0);
115729
- if( yygotominor.yy342.pExpr ){
115730
- yygotominor.yy342.pExpr->x.pList = yymsp[-1].minor.yy122 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[-1].minor.yy122) : yymsp[-2].minor.yy442;
115731
- sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115732
- }else{
115733
- sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
115734
- sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy122);
115735
- }
115736
- yygotominor.yy342.zStart = yymsp[-4].minor.yy0.z;
115737
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115738
-}
115739
- break;
115740
- case 232: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
115741
-{
115742
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, yymsp[-2].minor.yy342.pExpr);
115743
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr);
115744
-}
115745
- break;
115746
- case 233: /* case_exprlist ::= WHEN expr THEN expr */
115747
-{
115748
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
115749
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr);
115750
-}
115751
- break;
115752
- case 240: /* nexprlist ::= nexprlist COMMA expr */
115753
-{yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[0].minor.yy342.pExpr);}
115754
- break;
115755
- case 241: /* nexprlist ::= expr */
115756
-{yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy342.pExpr);}
115757
- break;
115758
- case 242: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt */
117103
+ sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
117104
+ }
117105
+ yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
117106
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117107
+ }
117108
+ break;
117109
+ case 233: /* expr ::= CASE case_operand case_exprlist case_else END */
117110
+{
117111
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, 0, 0);
117112
+ if( yygotominor.yy118.pExpr ){
117113
+ yygotominor.yy118.pExpr->x.pList = yymsp[-1].minor.yy314 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy314) : yymsp[-2].minor.yy322;
117114
+ sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117115
+ }else{
117116
+ sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
117117
+ sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy314);
117118
+ }
117119
+ yygotominor.yy118.zStart = yymsp[-4].minor.yy0.z;
117120
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117121
+}
117122
+ break;
117123
+ case 234: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
117124
+{
117125
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy118.pExpr);
117126
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
117127
+}
117128
+ break;
117129
+ case 235: /* case_exprlist ::= WHEN expr THEN expr */
117130
+{
117131
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
117132
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
117133
+}
117134
+ break;
117135
+ case 242: /* nexprlist ::= nexprlist COMMA expr */
117136
+{yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy118.pExpr);}
117137
+ break;
117138
+ case 243: /* nexprlist ::= expr */
117139
+{yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy118.pExpr);}
117140
+ break;
117141
+ case 244: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt */
115759117142
{
115760117143
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
115761
- sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy442, yymsp[-10].minor.yy392,
115762
- &yymsp[-11].minor.yy0, yymsp[0].minor.yy122, SQLITE_SO_ASC, yymsp[-8].minor.yy392);
115763
-}
115764
- break;
115765
- case 243: /* uniqueflag ::= UNIQUE */
115766
- case 296: /* raisetype ::= ABORT */ yytestcase(yyruleno==296);
115767
-{yygotominor.yy392 = OE_Abort;}
115768
- break;
115769
- case 244: /* uniqueflag ::= */
115770
-{yygotominor.yy392 = OE_None;}
115771
- break;
115772
- case 247: /* idxlist ::= idxlist COMMA nm collate sortorder */
115773
-{
115774
- Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
115775
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p);
115776
- sqlite3ExprListSetName(pParse,yygotominor.yy442,&yymsp[-2].minor.yy0,1);
115777
- sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
115778
- if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
115779
-}
115780
- break;
115781
- case 248: /* idxlist ::= nm collate sortorder */
115782
-{
115783
- Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
115784
- yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p);
115785
- sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
115786
- sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
115787
- if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
115788
-}
115789
- break;
115790
- case 249: /* collate ::= */
117144
+ sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy4,
117145
+ &yymsp[-11].minor.yy0, yymsp[0].minor.yy314, SQLITE_SO_ASC, yymsp[-8].minor.yy4);
117146
+}
117147
+ break;
117148
+ case 245: /* uniqueflag ::= UNIQUE */
117149
+ case 298: /* raisetype ::= ABORT */ yytestcase(yyruleno==298);
117150
+{yygotominor.yy4 = OE_Abort;}
117151
+ break;
117152
+ case 246: /* uniqueflag ::= */
117153
+{yygotominor.yy4 = OE_None;}
117154
+ break;
117155
+ case 249: /* idxlist ::= idxlist COMMA nm collate sortorder */
117156
+{
117157
+ Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
117158
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
117159
+ sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
117160
+ sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
117161
+ if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
117162
+}
117163
+ break;
117164
+ case 250: /* idxlist ::= nm collate sortorder */
117165
+{
117166
+ Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
117167
+ yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
117168
+ sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
117169
+ sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
117170
+ if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
117171
+}
117172
+ break;
117173
+ case 251: /* collate ::= */
115791117174
{yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
115792117175
break;
115793
- case 251: /* cmd ::= DROP INDEX ifexists fullname */
115794
-{sqlite3DropIndex(pParse, yymsp[0].minor.yy347, yymsp[-1].minor.yy392);}
117176
+ case 253: /* cmd ::= DROP INDEX ifexists fullname */
117177
+{sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
115795117178
break;
115796
- case 252: /* cmd ::= VACUUM */
115797
- case 253: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==253);
117179
+ case 254: /* cmd ::= VACUUM */
117180
+ case 255: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==255);
115798117181
{sqlite3Vacuum(pParse);}
115799117182
break;
115800
- case 254: /* cmd ::= PRAGMA nm dbnm */
117183
+ case 256: /* cmd ::= PRAGMA nm dbnm */
115801117184
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
115802117185
break;
115803
- case 255: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
117186
+ case 257: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
115804117187
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
115805117188
break;
115806
- case 256: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
117189
+ case 258: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
115807117190
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
115808117191
break;
115809
- case 257: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
117192
+ case 259: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
115810117193
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
115811117194
break;
115812
- case 258: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
117195
+ case 260: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
115813117196
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
115814117197
break;
115815
- case 268: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
117198
+ case 270: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
115816117199
{
115817117200
Token all;
115818117201
all.z = yymsp[-3].minor.yy0.z;
115819117202
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
115820
- sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy327, &all);
117203
+ sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
115821117204
}
115822117205
break;
115823
- case 269: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
117206
+ case 271: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
115824117207
{
115825
- sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy392, yymsp[-4].minor.yy410.a, yymsp[-4].minor.yy410.b, yymsp[-2].minor.yy347, yymsp[0].minor.yy122, yymsp[-10].minor.yy392, yymsp[-8].minor.yy392);
117208
+ sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
115826117209
yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
115827117210
}
115828117211
break;
115829
- case 270: /* trigger_time ::= BEFORE */
115830
- case 273: /* trigger_time ::= */ yytestcase(yyruleno==273);
115831
-{ yygotominor.yy392 = TK_BEFORE; }
115832
- break;
115833
- case 271: /* trigger_time ::= AFTER */
115834
-{ yygotominor.yy392 = TK_AFTER; }
115835
- break;
115836
- case 272: /* trigger_time ::= INSTEAD OF */
115837
-{ yygotominor.yy392 = TK_INSTEAD;}
115838
- break;
115839
- case 274: /* trigger_event ::= DELETE|INSERT */
115840
- case 275: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==275);
115841
-{yygotominor.yy410.a = yymsp[0].major; yygotominor.yy410.b = 0;}
115842
- break;
115843
- case 276: /* trigger_event ::= UPDATE OF inscollist */
115844
-{yygotominor.yy410.a = TK_UPDATE; yygotominor.yy410.b = yymsp[0].minor.yy180;}
115845
- break;
115846
- case 279: /* when_clause ::= */
115847
- case 301: /* key_opt ::= */ yytestcase(yyruleno==301);
115848
-{ yygotominor.yy122 = 0; }
115849
- break;
115850
- case 280: /* when_clause ::= WHEN expr */
115851
- case 302: /* key_opt ::= KEY expr */ yytestcase(yyruleno==302);
115852
-{ yygotominor.yy122 = yymsp[0].minor.yy342.pExpr; }
115853
- break;
115854
- case 281: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
115855
-{
115856
- assert( yymsp[-2].minor.yy327!=0 );
115857
- yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327;
115858
- yymsp[-2].minor.yy327->pLast = yymsp[-1].minor.yy327;
115859
- yygotominor.yy327 = yymsp[-2].minor.yy327;
115860
-}
115861
- break;
115862
- case 282: /* trigger_cmd_list ::= trigger_cmd SEMI */
115863
-{
115864
- assert( yymsp[-1].minor.yy327!=0 );
115865
- yymsp[-1].minor.yy327->pLast = yymsp[-1].minor.yy327;
115866
- yygotominor.yy327 = yymsp[-1].minor.yy327;
115867
-}
115868
- break;
115869
- case 284: /* trnm ::= nm DOT nm */
117212
+ case 272: /* trigger_time ::= BEFORE */
117213
+ case 275: /* trigger_time ::= */ yytestcase(yyruleno==275);
117214
+{ yygotominor.yy4 = TK_BEFORE; }
117215
+ break;
117216
+ case 273: /* trigger_time ::= AFTER */
117217
+{ yygotominor.yy4 = TK_AFTER; }
117218
+ break;
117219
+ case 274: /* trigger_time ::= INSTEAD OF */
117220
+{ yygotominor.yy4 = TK_INSTEAD;}
117221
+ break;
117222
+ case 276: /* trigger_event ::= DELETE|INSERT */
117223
+ case 277: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==277);
117224
+{yygotominor.yy90.a = yymsp[0].major; yygotominor.yy90.b = 0;}
117225
+ break;
117226
+ case 278: /* trigger_event ::= UPDATE OF idlist */
117227
+{yygotominor.yy90.a = TK_UPDATE; yygotominor.yy90.b = yymsp[0].minor.yy384;}
117228
+ break;
117229
+ case 281: /* when_clause ::= */
117230
+ case 303: /* key_opt ::= */ yytestcase(yyruleno==303);
117231
+{ yygotominor.yy314 = 0; }
117232
+ break;
117233
+ case 282: /* when_clause ::= WHEN expr */
117234
+ case 304: /* key_opt ::= KEY expr */ yytestcase(yyruleno==304);
117235
+{ yygotominor.yy314 = yymsp[0].minor.yy118.pExpr; }
117236
+ break;
117237
+ case 283: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
117238
+{
117239
+ assert( yymsp[-2].minor.yy203!=0 );
117240
+ yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
117241
+ yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
117242
+ yygotominor.yy203 = yymsp[-2].minor.yy203;
117243
+}
117244
+ break;
117245
+ case 284: /* trigger_cmd_list ::= trigger_cmd SEMI */
117246
+{
117247
+ assert( yymsp[-1].minor.yy203!=0 );
117248
+ yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
117249
+ yygotominor.yy203 = yymsp[-1].minor.yy203;
117250
+}
117251
+ break;
117252
+ case 286: /* trnm ::= nm DOT nm */
115870117253
{
115871117254
yygotominor.yy0 = yymsp[0].minor.yy0;
115872117255
sqlite3ErrorMsg(pParse,
115873117256
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
115874117257
"statements within triggers");
115875117258
}
115876117259
break;
115877
- case 286: /* tridxby ::= INDEXED BY nm */
117260
+ case 288: /* tridxby ::= INDEXED BY nm */
115878117261
{
115879117262
sqlite3ErrorMsg(pParse,
115880117263
"the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
115881117264
"within triggers");
115882117265
}
115883117266
break;
115884
- case 287: /* tridxby ::= NOT INDEXED */
117267
+ case 289: /* tridxby ::= NOT INDEXED */
115885117268
{
115886117269
sqlite3ErrorMsg(pParse,
115887117270
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
115888117271
"within triggers");
115889117272
}
115890117273
break;
115891
- case 288: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
115892
-{ yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-5].minor.yy258); }
115893
- break;
115894
- case 289: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist */
115895
-{yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-4].minor.yy258);}
115896
- break;
115897
- case 290: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
115898
-{yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy258);}
115899
- break;
115900
- case 291: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
115901
-{yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy122);}
115902
- break;
115903
- case 292: /* trigger_cmd ::= select */
115904
-{yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); }
115905
- break;
115906
- case 293: /* expr ::= RAISE LP IGNORE RP */
115907
-{
115908
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
115909
- if( yygotominor.yy342.pExpr ){
115910
- yygotominor.yy342.pExpr->affinity = OE_Ignore;
115911
- }
115912
- yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z;
115913
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115914
-}
115915
- break;
115916
- case 294: /* expr ::= RAISE LP raisetype COMMA nm RP */
115917
-{
115918
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
115919
- if( yygotominor.yy342.pExpr ) {
115920
- yygotominor.yy342.pExpr->affinity = (char)yymsp[-3].minor.yy392;
115921
- }
115922
- yygotominor.yy342.zStart = yymsp[-5].minor.yy0.z;
115923
- yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115924
-}
115925
- break;
115926
- case 295: /* raisetype ::= ROLLBACK */
115927
-{yygotominor.yy392 = OE_Rollback;}
115928
- break;
115929
- case 297: /* raisetype ::= FAIL */
115930
-{yygotominor.yy392 = OE_Fail;}
115931
- break;
115932
- case 298: /* cmd ::= DROP TRIGGER ifexists fullname */
115933
-{
115934
- sqlite3DropTrigger(pParse,yymsp[0].minor.yy347,yymsp[-1].minor.yy392);
115935
-}
115936
- break;
115937
- case 299: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
115938
-{
115939
- sqlite3Attach(pParse, yymsp[-3].minor.yy342.pExpr, yymsp[-1].minor.yy342.pExpr, yymsp[0].minor.yy122);
115940
-}
115941
- break;
115942
- case 300: /* cmd ::= DETACH database_kw_opt expr */
115943
-{
115944
- sqlite3Detach(pParse, yymsp[0].minor.yy342.pExpr);
115945
-}
115946
- break;
115947
- case 305: /* cmd ::= REINDEX */
117274
+ case 290: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
117275
+{ yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
117276
+ break;
117277
+ case 291: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist */
117278
+{yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, yymsp[0].minor.yy260.pList, yymsp[0].minor.yy260.pSelect, yymsp[-4].minor.yy210);}
117279
+ break;
117280
+ case 292: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
117281
+{yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
117282
+ break;
117283
+ case 293: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
117284
+{yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
117285
+ break;
117286
+ case 294: /* trigger_cmd ::= select */
117287
+{yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
117288
+ break;
117289
+ case 295: /* expr ::= RAISE LP IGNORE RP */
117290
+{
117291
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
117292
+ if( yygotominor.yy118.pExpr ){
117293
+ yygotominor.yy118.pExpr->affinity = OE_Ignore;
117294
+ }
117295
+ yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
117296
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117297
+}
117298
+ break;
117299
+ case 296: /* expr ::= RAISE LP raisetype COMMA nm RP */
117300
+{
117301
+ yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
117302
+ if( yygotominor.yy118.pExpr ) {
117303
+ yygotominor.yy118.pExpr->affinity = (char)yymsp[-3].minor.yy4;
117304
+ }
117305
+ yygotominor.yy118.zStart = yymsp[-5].minor.yy0.z;
117306
+ yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117307
+}
117308
+ break;
117309
+ case 297: /* raisetype ::= ROLLBACK */
117310
+{yygotominor.yy4 = OE_Rollback;}
117311
+ break;
117312
+ case 299: /* raisetype ::= FAIL */
117313
+{yygotominor.yy4 = OE_Fail;}
117314
+ break;
117315
+ case 300: /* cmd ::= DROP TRIGGER ifexists fullname */
117316
+{
117317
+ sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
117318
+}
117319
+ break;
117320
+ case 301: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
117321
+{
117322
+ sqlite3Attach(pParse, yymsp[-3].minor.yy118.pExpr, yymsp[-1].minor.yy118.pExpr, yymsp[0].minor.yy314);
117323
+}
117324
+ break;
117325
+ case 302: /* cmd ::= DETACH database_kw_opt expr */
117326
+{
117327
+ sqlite3Detach(pParse, yymsp[0].minor.yy118.pExpr);
117328
+}
117329
+ break;
117330
+ case 307: /* cmd ::= REINDEX */
115948117331
{sqlite3Reindex(pParse, 0, 0);}
115949117332
break;
115950
- case 306: /* cmd ::= REINDEX nm dbnm */
117333
+ case 308: /* cmd ::= REINDEX nm dbnm */
115951117334
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
115952117335
break;
115953
- case 307: /* cmd ::= ANALYZE */
117336
+ case 309: /* cmd ::= ANALYZE */
115954117337
{sqlite3Analyze(pParse, 0, 0);}
115955117338
break;
115956
- case 308: /* cmd ::= ANALYZE nm dbnm */
117339
+ case 310: /* cmd ::= ANALYZE nm dbnm */
115957117340
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
115958117341
break;
115959
- case 309: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
117342
+ case 311: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
115960117343
{
115961
- sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy347,&yymsp[0].minor.yy0);
117344
+ sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
115962117345
}
115963117346
break;
115964
- case 310: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
117347
+ case 312: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
115965117348
{
115966117349
sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
115967117350
}
115968117351
break;
115969
- case 311: /* add_column_fullname ::= fullname */
117352
+ case 313: /* add_column_fullname ::= fullname */
115970117353
{
115971117354
pParse->db->lookaside.bEnabled = 0;
115972
- sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy347);
117355
+ sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
115973117356
}
115974117357
break;
115975
- case 314: /* cmd ::= create_vtab */
117358
+ case 316: /* cmd ::= create_vtab */
115976117359
{sqlite3VtabFinishParse(pParse,0);}
115977117360
break;
115978
- case 315: /* cmd ::= create_vtab LP vtabarglist RP */
117361
+ case 317: /* cmd ::= create_vtab LP vtabarglist RP */
115979117362
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
115980117363
break;
115981
- case 316: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
117364
+ case 318: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
115982117365
{
115983
- sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy392);
117366
+ sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy4);
115984117367
}
115985117368
break;
115986
- case 319: /* vtabarg ::= */
117369
+ case 321: /* vtabarg ::= */
115987117370
{sqlite3VtabArgInit(pParse);}
115988117371
break;
115989
- case 321: /* vtabargtoken ::= ANY */
115990
- case 322: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==322);
115991
- case 323: /* lp ::= LP */ yytestcase(yyruleno==323);
117372
+ case 323: /* vtabargtoken ::= ANY */
117373
+ case 324: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==324);
117374
+ case 325: /* lp ::= LP */ yytestcase(yyruleno==325);
115992117375
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
115993117376
break;
115994117377
default:
115995117378
/* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
115996117379
/* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
@@ -116001,34 +117384,34 @@
116001117384
/* (11) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==11);
116002117385
/* (12) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==12);
116003117386
/* (20) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==20);
116004117387
/* (21) savepoint_opt ::= */ yytestcase(yyruleno==21);
116005117388
/* (25) cmd ::= create_table create_table_args */ yytestcase(yyruleno==25);
116006
- /* (34) columnlist ::= columnlist COMMA column */ yytestcase(yyruleno==34);
116007
- /* (35) columnlist ::= column */ yytestcase(yyruleno==35);
116008
- /* (44) type ::= */ yytestcase(yyruleno==44);
116009
- /* (51) signed ::= plus_num */ yytestcase(yyruleno==51);
116010
- /* (52) signed ::= minus_num */ yytestcase(yyruleno==52);
116011
- /* (53) carglist ::= carglist ccons */ yytestcase(yyruleno==53);
116012
- /* (54) carglist ::= */ yytestcase(yyruleno==54);
116013
- /* (61) ccons ::= NULL onconf */ yytestcase(yyruleno==61);
116014
- /* (89) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==89);
116015
- /* (90) conslist ::= tcons */ yytestcase(yyruleno==90);
116016
- /* (92) tconscomma ::= */ yytestcase(yyruleno==92);
116017
- /* (277) foreach_clause ::= */ yytestcase(yyruleno==277);
116018
- /* (278) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==278);
116019
- /* (285) tridxby ::= */ yytestcase(yyruleno==285);
116020
- /* (303) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==303);
116021
- /* (304) database_kw_opt ::= */ yytestcase(yyruleno==304);
116022
- /* (312) kwcolumn_opt ::= */ yytestcase(yyruleno==312);
116023
- /* (313) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==313);
116024
- /* (317) vtabarglist ::= vtabarg */ yytestcase(yyruleno==317);
116025
- /* (318) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==318);
116026
- /* (320) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==320);
116027
- /* (324) anylist ::= */ yytestcase(yyruleno==324);
116028
- /* (325) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==325);
116029
- /* (326) anylist ::= anylist ANY */ yytestcase(yyruleno==326);
117389
+ /* (36) columnlist ::= columnlist COMMA column */ yytestcase(yyruleno==36);
117390
+ /* (37) columnlist ::= column */ yytestcase(yyruleno==37);
117391
+ /* (46) type ::= */ yytestcase(yyruleno==46);
117392
+ /* (53) signed ::= plus_num */ yytestcase(yyruleno==53);
117393
+ /* (54) signed ::= minus_num */ yytestcase(yyruleno==54);
117394
+ /* (55) carglist ::= carglist ccons */ yytestcase(yyruleno==55);
117395
+ /* (56) carglist ::= */ yytestcase(yyruleno==56);
117396
+ /* (63) ccons ::= NULL onconf */ yytestcase(yyruleno==63);
117397
+ /* (91) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==91);
117398
+ /* (92) conslist ::= tcons */ yytestcase(yyruleno==92);
117399
+ /* (94) tconscomma ::= */ yytestcase(yyruleno==94);
117400
+ /* (279) foreach_clause ::= */ yytestcase(yyruleno==279);
117401
+ /* (280) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==280);
117402
+ /* (287) tridxby ::= */ yytestcase(yyruleno==287);
117403
+ /* (305) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==305);
117404
+ /* (306) database_kw_opt ::= */ yytestcase(yyruleno==306);
117405
+ /* (314) kwcolumn_opt ::= */ yytestcase(yyruleno==314);
117406
+ /* (315) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==315);
117407
+ /* (319) vtabarglist ::= vtabarg */ yytestcase(yyruleno==319);
117408
+ /* (320) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==320);
117409
+ /* (322) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==322);
117410
+ /* (326) anylist ::= */ yytestcase(yyruleno==326);
117411
+ /* (327) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==327);
117412
+ /* (328) anylist ::= anylist ANY */ yytestcase(yyruleno==328);
116030117413
break;
116031117414
};
116032117415
assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
116033117416
yygoto = yyRuleInfo[yyruleno].lhs;
116034117417
yysize = yyRuleInfo[yyruleno].nrhs;
@@ -116363,24 +117746,24 @@
116363117746
** might be implemented more directly using a hand-written hash table.
116364117747
** But by using this automatically generated code, the size of the code
116365117748
** is substantially reduced. This is important for embedded applications
116366117749
** on platforms with limited memory.
116367117750
*/
116368
-/* Hash score: 175 */
117751
+/* Hash score: 177 */
116369117752
static int keywordCode(const char *z, int n){
116370
- /* zText[] encodes 811 bytes of keywords in 541 bytes */
117753
+ /* zText[] encodes 819 bytes of keywords in 545 bytes */
116371117754
/* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
116372117755
/* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
116373117756
/* XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY */
116374
- /* UNIQUERYATTACHAVINGROUPDATEBEGINNERELEASEBETWEENOTNULLIKE */
116375
- /* CASCADELETECASECOLLATECREATECURRENT_DATEDETACHIMMEDIATEJOIN */
116376
- /* SERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHENWHERENAME */
116377
- /* AFTEREPLACEANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSS */
116378
- /* CURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAILFROMFULLGLOBYIF */
116379
- /* ISNULLORDERESTRICTOUTERIGHTROLLBACKROWUNIONUSINGVACUUMVIEW */
117757
+ /* UNIQUERYWITHOUTERELEASEATTACHAVINGROUPDATEBEGINNERENAMEBETWEEN */
117758
+ /* OTNULLIKECASCADELETECASECOLLATECREATECURRENT_DATEDETACH */
117759
+ /* IMMEDIATEJOINSERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHEN */
117760
+ /* WHEREPLACEAFTERESTRICTANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMIT */
117761
+ /* CONFLICTCROSSCURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAIL */
117762
+ /* FROMFULLGLOBYIFISNULLORDERIGHTROLLBACKROWUNIONUSINGVACUUMVIEW */
116380117763
/* INITIALLY */
116381
- static const char zText[540] = {
117764
+ static const char zText[544] = {
116382117765
'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
116383117766
'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
116384117767
'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
116385117768
'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
116386117769
'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
@@ -116387,105 +117770,106 @@
116387117770
'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
116388117771
'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
116389117772
'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
116390117773
'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
116391117774
'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
116392
- 'U','E','R','Y','A','T','T','A','C','H','A','V','I','N','G','R','O','U',
116393
- 'P','D','A','T','E','B','E','G','I','N','N','E','R','E','L','E','A','S',
116394
- 'E','B','E','T','W','E','E','N','O','T','N','U','L','L','I','K','E','C',
116395
- 'A','S','C','A','D','E','L','E','T','E','C','A','S','E','C','O','L','L',
116396
- 'A','T','E','C','R','E','A','T','E','C','U','R','R','E','N','T','_','D',
116397
- 'A','T','E','D','E','T','A','C','H','I','M','M','E','D','I','A','T','E',
116398
- 'J','O','I','N','S','E','R','T','M','A','T','C','H','P','L','A','N','A',
116399
- 'L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U',
116400
- 'E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','W',
116401
- 'H','E','R','E','N','A','M','E','A','F','T','E','R','E','P','L','A','C',
116402
- 'E','A','N','D','E','F','A','U','L','T','A','U','T','O','I','N','C','R',
116403
- 'E','M','E','N','T','C','A','S','T','C','O','L','U','M','N','C','O','M',
116404
- 'M','I','T','C','O','N','F','L','I','C','T','C','R','O','S','S','C','U',
116405
- 'R','R','E','N','T','_','T','I','M','E','S','T','A','M','P','R','I','M',
116406
- 'A','R','Y','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T',
116407
- 'D','R','O','P','F','A','I','L','F','R','O','M','F','U','L','L','G','L',
116408
- 'O','B','Y','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S',
116409
- 'T','R','I','C','T','O','U','T','E','R','I','G','H','T','R','O','L','L',
116410
- 'B','A','C','K','R','O','W','U','N','I','O','N','U','S','I','N','G','V',
116411
- 'A','C','U','U','M','V','I','E','W','I','N','I','T','I','A','L','L','Y',
117775
+ 'U','E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S',
117776
+ 'E','A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A',
117777
+ 'T','E','B','E','G','I','N','N','E','R','E','N','A','M','E','B','E','T',
117778
+ 'W','E','E','N','O','T','N','U','L','L','I','K','E','C','A','S','C','A',
117779
+ 'D','E','L','E','T','E','C','A','S','E','C','O','L','L','A','T','E','C',
117780
+ 'R','E','A','T','E','C','U','R','R','E','N','T','_','D','A','T','E','D',
117781
+ 'E','T','A','C','H','I','M','M','E','D','I','A','T','E','J','O','I','N',
117782
+ 'S','E','R','T','M','A','T','C','H','P','L','A','N','A','L','Y','Z','E',
117783
+ 'P','R','A','G','M','A','B','O','R','T','V','A','L','U','E','S','V','I',
117784
+ 'R','T','U','A','L','I','M','I','T','W','H','E','N','W','H','E','R','E',
117785
+ 'P','L','A','C','E','A','F','T','E','R','E','S','T','R','I','C','T','A',
117786
+ 'N','D','E','F','A','U','L','T','A','U','T','O','I','N','C','R','E','M',
117787
+ 'E','N','T','C','A','S','T','C','O','L','U','M','N','C','O','M','M','I',
117788
+ 'T','C','O','N','F','L','I','C','T','C','R','O','S','S','C','U','R','R',
117789
+ 'E','N','T','_','T','I','M','E','S','T','A','M','P','R','I','M','A','R',
117790
+ 'Y','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T','D','R',
117791
+ 'O','P','F','A','I','L','F','R','O','M','F','U','L','L','G','L','O','B',
117792
+ 'Y','I','F','I','S','N','U','L','L','O','R','D','E','R','I','G','H','T',
117793
+ 'R','O','L','L','B','A','C','K','R','O','W','U','N','I','O','N','U','S',
117794
+ 'I','N','G','V','A','C','U','U','M','V','I','E','W','I','N','I','T','I',
117795
+ 'A','L','L','Y',
116412117796
};
116413117797
static const unsigned char aHash[127] = {
116414
- 72, 101, 114, 70, 0, 45, 0, 0, 78, 0, 73, 0, 0,
116415
- 42, 12, 74, 15, 0, 113, 81, 50, 108, 0, 19, 0, 0,
116416
- 118, 0, 116, 111, 0, 22, 89, 0, 9, 0, 0, 66, 67,
116417
- 0, 65, 6, 0, 48, 86, 98, 0, 115, 97, 0, 0, 44,
116418
- 0, 99, 24, 0, 17, 0, 119, 49, 23, 0, 5, 106, 25,
116419
- 92, 0, 0, 121, 102, 56, 120, 53, 28, 51, 0, 87, 0,
116420
- 96, 26, 0, 95, 0, 0, 0, 91, 88, 93, 84, 105, 14,
116421
- 39, 104, 0, 77, 0, 18, 85, 107, 32, 0, 117, 76, 109,
116422
- 58, 46, 80, 0, 0, 90, 40, 0, 112, 0, 36, 0, 0,
116423
- 29, 0, 82, 59, 60, 0, 20, 57, 0, 52,
117798
+ 75, 104, 115, 73, 0, 45, 0, 0, 81, 0, 76, 0, 0,
117799
+ 42, 12, 77, 15, 0, 114, 84, 53, 111, 0, 19, 0, 0,
117800
+ 119, 0, 117, 88, 0, 22, 92, 0, 9, 0, 0, 69, 70,
117801
+ 0, 68, 6, 0, 48, 89, 101, 0, 116, 100, 0, 0, 44,
117802
+ 0, 102, 24, 0, 17, 0, 120, 52, 23, 0, 5, 109, 25,
117803
+ 95, 0, 0, 122, 105, 59, 121, 56, 28, 54, 0, 90, 0,
117804
+ 99, 26, 0, 98, 0, 0, 0, 94, 91, 96, 87, 108, 14,
117805
+ 39, 107, 0, 80, 0, 18, 86, 110, 32, 0, 118, 79, 112,
117806
+ 61, 46, 83, 0, 0, 93, 40, 0, 113, 0, 36, 0, 0,
117807
+ 29, 0, 85, 62, 63, 0, 20, 60, 0, 55,
116424117808
};
116425
- static const unsigned char aNext[121] = {
117809
+ static const unsigned char aNext[122] = {
116426117810
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
116427117811
0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
116428117812
0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116429
- 0, 0, 0, 0, 33, 0, 21, 0, 0, 0, 43, 3, 47,
116430
- 0, 0, 0, 0, 30, 0, 54, 0, 38, 0, 0, 0, 1,
116431
- 62, 0, 0, 63, 0, 41, 0, 0, 0, 0, 0, 0, 0,
116432
- 61, 0, 0, 0, 0, 31, 55, 16, 34, 10, 0, 0, 0,
116433
- 0, 0, 0, 0, 11, 68, 75, 0, 8, 0, 100, 94, 0,
116434
- 103, 0, 83, 0, 71, 0, 0, 110, 27, 37, 69, 79, 0,
116435
- 35, 64, 0, 0,
117813
+ 0, 0, 0, 0, 33, 0, 21, 0, 0, 0, 0, 0, 0,
117814
+ 43, 3, 47, 0, 0, 0, 0, 30, 0, 57, 0, 38, 0,
117815
+ 0, 0, 1, 65, 0, 0, 66, 0, 41, 0, 0, 0, 0,
117816
+ 0, 0, 49, 64, 0, 0, 0, 51, 31, 0, 16, 34, 10,
117817
+ 0, 0, 0, 0, 0, 0, 0, 11, 71, 78, 0, 8, 0,
117818
+ 103, 97, 0, 106, 0, 58, 0, 74, 50, 27, 37, 72, 82,
117819
+ 0, 35, 67, 0, 0,
116436117820
};
116437
- static const unsigned char aLen[121] = {
117821
+ static const unsigned char aLen[122] = {
116438117822
7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
116439117823
7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
116440117824
11, 6, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10,
116441
- 4, 6, 2, 3, 9, 4, 2, 6, 5, 6, 6, 5, 6,
116442
- 5, 5, 7, 7, 7, 3, 2, 4, 4, 7, 3, 6, 4,
116443
- 7, 6, 12, 6, 9, 4, 6, 5, 4, 7, 6, 5, 6,
116444
- 7, 5, 4, 5, 6, 5, 7, 3, 7, 13, 2, 2, 4,
116445
- 6, 6, 8, 5, 17, 12, 7, 8, 8, 2, 4, 4, 4,
116446
- 4, 4, 2, 2, 6, 5, 8, 5, 5, 8, 3, 5, 5,
116447
- 6, 4, 9, 3,
117825
+ 4, 6, 2, 3, 9, 4, 2, 6, 5, 7, 5, 7, 6,
117826
+ 6, 5, 6, 5, 5, 6, 7, 7, 3, 2, 4, 4, 7,
117827
+ 3, 6, 4, 7, 6, 12, 6, 9, 4, 6, 5, 4, 7,
117828
+ 6, 5, 6, 7, 5, 4, 5, 7, 5, 8, 3, 7, 13,
117829
+ 2, 2, 4, 6, 6, 8, 5, 17, 12, 7, 8, 8, 2,
117830
+ 4, 4, 4, 4, 4, 2, 2, 6, 5, 5, 8, 3, 5,
117831
+ 5, 6, 4, 9, 3,
116448117832
};
116449
- static const unsigned short int aOffset[121] = {
117833
+ static const unsigned short int aOffset[122] = {
116450117834
0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
116451117835
36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
116452117836
86, 91, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152,
116453
- 159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 189, 194, 197,
116454
- 203, 206, 210, 217, 223, 223, 223, 226, 229, 233, 234, 238, 244,
116455
- 248, 255, 261, 273, 279, 288, 290, 296, 301, 303, 310, 315, 320,
116456
- 326, 332, 337, 341, 344, 350, 354, 361, 363, 370, 372, 374, 383,
116457
- 387, 393, 399, 407, 412, 412, 428, 435, 442, 443, 450, 454, 458,
116458
- 462, 466, 469, 471, 473, 479, 483, 491, 495, 500, 508, 511, 516,
116459
- 521, 527, 531, 536,
117837
+ 159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 188, 192, 199,
117838
+ 204, 209, 212, 218, 221, 225, 231, 237, 237, 237, 240, 243, 247,
117839
+ 248, 252, 258, 262, 269, 275, 287, 293, 302, 304, 310, 315, 317,
117840
+ 324, 329, 334, 340, 346, 351, 355, 358, 365, 369, 377, 379, 386,
117841
+ 388, 390, 399, 403, 409, 415, 423, 428, 428, 444, 451, 458, 459,
117842
+ 466, 470, 474, 478, 482, 485, 487, 489, 495, 499, 504, 512, 515,
117843
+ 520, 525, 531, 535, 540,
116460117844
};
116461
- static const unsigned char aCode[121] = {
117845
+ static const unsigned char aCode[122] = {
116462117846
TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
116463117847
TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
116464117848
TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
116465117849
TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
116466117850
TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
116467117851
TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
116468117852
TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT,
116469117853
TK_INTERSECT, TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO,
116470117854
TK_OFFSET, TK_OF, TK_SET, TK_TEMP, TK_TEMP,
116471
- TK_OR, TK_UNIQUE, TK_QUERY, TK_ATTACH, TK_HAVING,
116472
- TK_GROUP, TK_UPDATE, TK_BEGIN, TK_JOIN_KW, TK_RELEASE,
116473
- TK_BETWEEN, TK_NOTNULL, TK_NOT, TK_NO, TK_NULL,
116474
- TK_LIKE_KW, TK_CASCADE, TK_ASC, TK_DELETE, TK_CASE,
116475
- TK_COLLATE, TK_CREATE, TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE,
116476
- TK_JOIN, TK_INSERT, TK_MATCH, TK_PLAN, TK_ANALYZE,
116477
- TK_PRAGMA, TK_ABORT, TK_VALUES, TK_VIRTUAL, TK_LIMIT,
116478
- TK_WHEN, TK_WHERE, TK_RENAME, TK_AFTER, TK_REPLACE,
116479
- TK_AND, TK_DEFAULT, TK_AUTOINCR, TK_TO, TK_IN,
116480
- TK_CAST, TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, TK_JOIN_KW,
116481
- TK_CTIME_KW, TK_CTIME_KW, TK_PRIMARY, TK_DEFERRED, TK_DISTINCT,
116482
- TK_IS, TK_DROP, TK_FAIL, TK_FROM, TK_JOIN_KW,
116483
- TK_LIKE_KW, TK_BY, TK_IF, TK_ISNULL, TK_ORDER,
116484
- TK_RESTRICT, TK_JOIN_KW, TK_JOIN_KW, TK_ROLLBACK, TK_ROW,
116485
- TK_UNION, TK_USING, TK_VACUUM, TK_VIEW, TK_INITIALLY,
116486
- TK_ALL,
117855
+ TK_OR, TK_UNIQUE, TK_QUERY, TK_WITHOUT, TK_JOIN_KW,
117856
+ TK_RELEASE, TK_ATTACH, TK_HAVING, TK_GROUP, TK_UPDATE,
117857
+ TK_BEGIN, TK_JOIN_KW, TK_RENAME, TK_BETWEEN, TK_NOTNULL,
117858
+ TK_NOT, TK_NO, TK_NULL, TK_LIKE_KW, TK_CASCADE,
117859
+ TK_ASC, TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE,
117860
+ TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT,
117861
+ TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT,
117862
+ TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_WHERE,
117863
+ TK_REPLACE, TK_AFTER, TK_RESTRICT, TK_AND, TK_DEFAULT,
117864
+ TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW,
117865
+ TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW,
117866
+ TK_PRIMARY, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP,
117867
+ TK_FAIL, TK_FROM, TK_JOIN_KW, TK_LIKE_KW, TK_BY,
117868
+ TK_IF, TK_ISNULL, TK_ORDER, TK_JOIN_KW, TK_ROLLBACK,
117869
+ TK_ROW, TK_UNION, TK_USING, TK_VACUUM, TK_VIEW,
117870
+ TK_INITIALLY, TK_ALL,
116487117871
};
116488117872
int h, i;
116489117873
if( n<2 ) return TK_ID;
116490117874
h = ((charMap(z[0])*4) ^
116491117875
(charMap(z[n-1])*3) ^
@@ -116538,92 +117922,93 @@
116538117922
testcase( i==43 ); /* TEMPORARY */
116539117923
testcase( i==44 ); /* TEMP */
116540117924
testcase( i==45 ); /* OR */
116541117925
testcase( i==46 ); /* UNIQUE */
116542117926
testcase( i==47 ); /* QUERY */
116543
- testcase( i==48 ); /* ATTACH */
116544
- testcase( i==49 ); /* HAVING */
116545
- testcase( i==50 ); /* GROUP */
116546
- testcase( i==51 ); /* UPDATE */
116547
- testcase( i==52 ); /* BEGIN */
116548
- testcase( i==53 ); /* INNER */
116549
- testcase( i==54 ); /* RELEASE */
116550
- testcase( i==55 ); /* BETWEEN */
116551
- testcase( i==56 ); /* NOTNULL */
116552
- testcase( i==57 ); /* NOT */
116553
- testcase( i==58 ); /* NO */
116554
- testcase( i==59 ); /* NULL */
116555
- testcase( i==60 ); /* LIKE */
116556
- testcase( i==61 ); /* CASCADE */
116557
- testcase( i==62 ); /* ASC */
116558
- testcase( i==63 ); /* DELETE */
116559
- testcase( i==64 ); /* CASE */
116560
- testcase( i==65 ); /* COLLATE */
116561
- testcase( i==66 ); /* CREATE */
116562
- testcase( i==67 ); /* CURRENT_DATE */
116563
- testcase( i==68 ); /* DETACH */
116564
- testcase( i==69 ); /* IMMEDIATE */
116565
- testcase( i==70 ); /* JOIN */
116566
- testcase( i==71 ); /* INSERT */
116567
- testcase( i==72 ); /* MATCH */
116568
- testcase( i==73 ); /* PLAN */
116569
- testcase( i==74 ); /* ANALYZE */
116570
- testcase( i==75 ); /* PRAGMA */
116571
- testcase( i==76 ); /* ABORT */
116572
- testcase( i==77 ); /* VALUES */
116573
- testcase( i==78 ); /* VIRTUAL */
116574
- testcase( i==79 ); /* LIMIT */
116575
- testcase( i==80 ); /* WHEN */
116576
- testcase( i==81 ); /* WHERE */
116577
- testcase( i==82 ); /* RENAME */
116578
- testcase( i==83 ); /* AFTER */
116579
- testcase( i==84 ); /* REPLACE */
116580
- testcase( i==85 ); /* AND */
116581
- testcase( i==86 ); /* DEFAULT */
116582
- testcase( i==87 ); /* AUTOINCREMENT */
116583
- testcase( i==88 ); /* TO */
116584
- testcase( i==89 ); /* IN */
116585
- testcase( i==90 ); /* CAST */
116586
- testcase( i==91 ); /* COLUMN */
116587
- testcase( i==92 ); /* COMMIT */
116588
- testcase( i==93 ); /* CONFLICT */
116589
- testcase( i==94 ); /* CROSS */
116590
- testcase( i==95 ); /* CURRENT_TIMESTAMP */
116591
- testcase( i==96 ); /* CURRENT_TIME */
116592
- testcase( i==97 ); /* PRIMARY */
116593
- testcase( i==98 ); /* DEFERRED */
116594
- testcase( i==99 ); /* DISTINCT */
116595
- testcase( i==100 ); /* IS */
116596
- testcase( i==101 ); /* DROP */
116597
- testcase( i==102 ); /* FAIL */
116598
- testcase( i==103 ); /* FROM */
116599
- testcase( i==104 ); /* FULL */
116600
- testcase( i==105 ); /* GLOB */
116601
- testcase( i==106 ); /* BY */
116602
- testcase( i==107 ); /* IF */
116603
- testcase( i==108 ); /* ISNULL */
116604
- testcase( i==109 ); /* ORDER */
116605
- testcase( i==110 ); /* RESTRICT */
116606
- testcase( i==111 ); /* OUTER */
116607
- testcase( i==112 ); /* RIGHT */
116608
- testcase( i==113 ); /* ROLLBACK */
116609
- testcase( i==114 ); /* ROW */
116610
- testcase( i==115 ); /* UNION */
116611
- testcase( i==116 ); /* USING */
116612
- testcase( i==117 ); /* VACUUM */
116613
- testcase( i==118 ); /* VIEW */
116614
- testcase( i==119 ); /* INITIALLY */
116615
- testcase( i==120 ); /* ALL */
117927
+ testcase( i==48 ); /* WITHOUT */
117928
+ testcase( i==49 ); /* OUTER */
117929
+ testcase( i==50 ); /* RELEASE */
117930
+ testcase( i==51 ); /* ATTACH */
117931
+ testcase( i==52 ); /* HAVING */
117932
+ testcase( i==53 ); /* GROUP */
117933
+ testcase( i==54 ); /* UPDATE */
117934
+ testcase( i==55 ); /* BEGIN */
117935
+ testcase( i==56 ); /* INNER */
117936
+ testcase( i==57 ); /* RENAME */
117937
+ testcase( i==58 ); /* BETWEEN */
117938
+ testcase( i==59 ); /* NOTNULL */
117939
+ testcase( i==60 ); /* NOT */
117940
+ testcase( i==61 ); /* NO */
117941
+ testcase( i==62 ); /* NULL */
117942
+ testcase( i==63 ); /* LIKE */
117943
+ testcase( i==64 ); /* CASCADE */
117944
+ testcase( i==65 ); /* ASC */
117945
+ testcase( i==66 ); /* DELETE */
117946
+ testcase( i==67 ); /* CASE */
117947
+ testcase( i==68 ); /* COLLATE */
117948
+ testcase( i==69 ); /* CREATE */
117949
+ testcase( i==70 ); /* CURRENT_DATE */
117950
+ testcase( i==71 ); /* DETACH */
117951
+ testcase( i==72 ); /* IMMEDIATE */
117952
+ testcase( i==73 ); /* JOIN */
117953
+ testcase( i==74 ); /* INSERT */
117954
+ testcase( i==75 ); /* MATCH */
117955
+ testcase( i==76 ); /* PLAN */
117956
+ testcase( i==77 ); /* ANALYZE */
117957
+ testcase( i==78 ); /* PRAGMA */
117958
+ testcase( i==79 ); /* ABORT */
117959
+ testcase( i==80 ); /* VALUES */
117960
+ testcase( i==81 ); /* VIRTUAL */
117961
+ testcase( i==82 ); /* LIMIT */
117962
+ testcase( i==83 ); /* WHEN */
117963
+ testcase( i==84 ); /* WHERE */
117964
+ testcase( i==85 ); /* REPLACE */
117965
+ testcase( i==86 ); /* AFTER */
117966
+ testcase( i==87 ); /* RESTRICT */
117967
+ testcase( i==88 ); /* AND */
117968
+ testcase( i==89 ); /* DEFAULT */
117969
+ testcase( i==90 ); /* AUTOINCREMENT */
117970
+ testcase( i==91 ); /* TO */
117971
+ testcase( i==92 ); /* IN */
117972
+ testcase( i==93 ); /* CAST */
117973
+ testcase( i==94 ); /* COLUMN */
117974
+ testcase( i==95 ); /* COMMIT */
117975
+ testcase( i==96 ); /* CONFLICT */
117976
+ testcase( i==97 ); /* CROSS */
117977
+ testcase( i==98 ); /* CURRENT_TIMESTAMP */
117978
+ testcase( i==99 ); /* CURRENT_TIME */
117979
+ testcase( i==100 ); /* PRIMARY */
117980
+ testcase( i==101 ); /* DEFERRED */
117981
+ testcase( i==102 ); /* DISTINCT */
117982
+ testcase( i==103 ); /* IS */
117983
+ testcase( i==104 ); /* DROP */
117984
+ testcase( i==105 ); /* FAIL */
117985
+ testcase( i==106 ); /* FROM */
117986
+ testcase( i==107 ); /* FULL */
117987
+ testcase( i==108 ); /* GLOB */
117988
+ testcase( i==109 ); /* BY */
117989
+ testcase( i==110 ); /* IF */
117990
+ testcase( i==111 ); /* ISNULL */
117991
+ testcase( i==112 ); /* ORDER */
117992
+ testcase( i==113 ); /* RIGHT */
117993
+ testcase( i==114 ); /* ROLLBACK */
117994
+ testcase( i==115 ); /* ROW */
117995
+ testcase( i==116 ); /* UNION */
117996
+ testcase( i==117 ); /* USING */
117997
+ testcase( i==118 ); /* VACUUM */
117998
+ testcase( i==119 ); /* VIEW */
117999
+ testcase( i==120 ); /* INITIALLY */
118000
+ testcase( i==121 ); /* ALL */
116616118001
return aCode[i];
116617118002
}
116618118003
}
116619118004
return TK_ID;
116620118005
}
116621118006
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
116622118007
return keywordCode((char*)z, n);
116623118008
}
116624
-#define SQLITE_N_KEYWORD 121
118009
+#define SQLITE_N_KEYWORD 122
116625118010
116626118011
/************** End of keywordhash.h *****************************************/
116627118012
/************** Continuing where we left off in tokenize.c *******************/
116628118013
116629118014
@@ -117066,11 +118451,10 @@
117066118451
}
117067118452
117068118453
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
117069118454
for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
117070118455
sqlite3DbFree(db, pParse->azVar);
117071
- sqlite3DbFree(db, pParse->aAlias);
117072118456
while( pParse->pAinc ){
117073118457
AutoincInfo *p = pParse->pAinc;
117074118458
pParse->pAinc = p->pNext;
117075118459
sqlite3DbFree(db, p);
117076118460
}
@@ -118594,10 +119978,11 @@
118594119978
case SQLITE_CONSTRAINT_COMMITHOOK:
118595119979
zName = "SQLITE_CONSTRAINT_COMMITHOOK"; break;
118596119980
case SQLITE_CONSTRAINT_VTAB: zName = "SQLITE_CONSTRAINT_VTAB"; break;
118597119981
case SQLITE_CONSTRAINT_FUNCTION:
118598119982
zName = "SQLITE_CONSTRAINT_FUNCTION"; break;
119983
+ case SQLITE_CONSTRAINT_ROWID: zName = "SQLITE_CONSTRAINT_ROWID"; break;
118599119984
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
118600119985
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
118601119986
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
118602119987
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
118603119988
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
@@ -119408,10 +120793,36 @@
119408120793
** function.
119409120794
*/
119410120795
SQLITE_API const char *sqlite3_errstr(int rc){
119411120796
return sqlite3ErrStr(rc);
119412120797
}
120798
+
120799
+/*
120800
+** Invalidate all cached KeyInfo objects for database connection "db"
120801
+*/
120802
+static void invalidateCachedKeyInfo(sqlite3 *db){
120803
+ Db *pDb; /* A single database */
120804
+ int iDb; /* The database index number */
120805
+ HashElem *k; /* For looping over tables in pDb */
120806
+ Table *pTab; /* A table in the database */
120807
+ Index *pIdx; /* Each index */
120808
+
120809
+ for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
120810
+ if( pDb->pBt==0 ) continue;
120811
+ sqlite3BtreeEnter(pDb->pBt);
120812
+ for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
120813
+ pTab = (Table*)sqliteHashData(k);
120814
+ for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120815
+ if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){
120816
+ sqlite3KeyInfoUnref(pIdx->pKeyInfo);
120817
+ pIdx->pKeyInfo = 0;
120818
+ }
120819
+ }
120820
+ }
120821
+ sqlite3BtreeLeave(pDb->pBt);
120822
+ }
120823
+}
119413120824
119414120825
/*
119415120826
** Create a new collating function for database "db". The name is zName
119416120827
** and the encoding is enc.
119417120828
*/
@@ -119453,10 +120864,11 @@
119453120864
sqlite3Error(db, SQLITE_BUSY,
119454120865
"unable to delete/modify collation sequence due to active statements");
119455120866
return SQLITE_BUSY;
119456120867
}
119457120868
sqlite3ExpirePreparedStatements(db);
120869
+ invalidateCachedKeyInfo(db);
119458120870
119459120871
/* If collation sequence pColl was created directly by a call to
119460120872
** sqlite3_create_collation, and not generated by synthCollSeq(),
119461120873
** then any copies made by synthCollSeq() need to be invalidated.
119462120874
** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128435,10 +129847,15 @@
128435129847
}
128436129848
*ppCsr = pCsr;
128437129849
return rc;
128438129850
}
128439129851
129852
+/*
129853
+** Function getNextNode(), which is called by fts3ExprParse(), may itself
129854
+** call fts3ExprParse(). So this forward declaration is required.
129855
+*/
129856
+static int fts3ExprParse(ParseContext *, const char *, int, Fts3Expr **, int *);
128440129857
128441129858
/*
128442129859
** Extract the next token from buffer z (length n) using the tokenizer
128443129860
** and other information (column names etc.) in pParse. Create an Fts3Expr
128444129861
** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
@@ -128469,11 +129886,35 @@
128469129886
const char *zToken;
128470129887
int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
128471129888
int nByte; /* total space to allocate */
128472129889
128473129890
rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
128474
- if( rc==SQLITE_OK ){
129891
+
129892
+ if( (rc==SQLITE_OK || rc==SQLITE_DONE) && sqlite3_fts3_enable_parentheses ){
129893
+ int i;
129894
+ if( rc==SQLITE_DONE ) iStart = n;
129895
+ for(i=0; i<iStart; i++){
129896
+ if( z[i]=='(' ){
129897
+ pParse->nNest++;
129898
+ rc = fts3ExprParse(pParse, &z[i+1], n-i-1, &pRet, &nConsumed);
129899
+ if( rc==SQLITE_OK && !pRet ){
129900
+ rc = SQLITE_DONE;
129901
+ }
129902
+ nConsumed = (int)(i + 1 + nConsumed);
129903
+ break;
129904
+ }
129905
+
129906
+ if( z[i]==')' ){
129907
+ rc = SQLITE_DONE;
129908
+ pParse->nNest--;
129909
+ nConsumed = i+1;
129910
+ break;
129911
+ }
129912
+ }
129913
+ }
129914
+
129915
+ if( nConsumed==0 && rc==SQLITE_OK ){
128475129916
nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
128476129917
pRet = (Fts3Expr *)fts3MallocZero(nByte);
128477129918
if( !pRet ){
128478129919
rc = SQLITE_NOMEM;
128479129920
}else{
@@ -128649,16 +130090,10 @@
128649130090
sqlite3_free(p);
128650130091
*ppExpr = 0;
128651130092
return SQLITE_NOMEM;
128652130093
}
128653130094
128654
-/*
128655
-** Function getNextNode(), which is called by fts3ExprParse(), may itself
128656
-** call fts3ExprParse(). So this forward declaration is required.
128657
-*/
128658
-static int fts3ExprParse(ParseContext *, const char *, int, Fts3Expr **, int *);
128659
-
128660130095
/*
128661130096
** The output variable *ppExpr is populated with an allocated Fts3Expr
128662130097
** structure, or set to 0 if the end of the input buffer is reached.
128663130098
**
128664130099
** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM
@@ -128751,31 +130186,10 @@
128751130186
** user has supplied a token such as "ORacle". Continue.
128752130187
*/
128753130188
}
128754130189
}
128755130190
128756
- /* Check for an open bracket. */
128757
- if( sqlite3_fts3_enable_parentheses ){
128758
- if( *zInput=='(' ){
128759
- int nConsumed;
128760
- pParse->nNest++;
128761
- rc = fts3ExprParse(pParse, &zInput[1], nInput-1, ppExpr, &nConsumed);
128762
- if( rc==SQLITE_OK && !*ppExpr ){
128763
- rc = SQLITE_DONE;
128764
- }
128765
- *pnConsumed = (int)((zInput - z) + 1 + nConsumed);
128766
- return rc;
128767
- }
128768
-
128769
- /* Check for a close bracket. */
128770
- if( *zInput==')' ){
128771
- pParse->nNest--;
128772
- *pnConsumed = (int)((zInput - z) + 1);
128773
- return SQLITE_DONE;
128774
- }
128775
- }
128776
-
128777130191
/* See if we are dealing with a quoted phrase. If this is the case, then
128778130192
** search for the closing quote and pass the whole string to getNextString()
128779130193
** for processing. This is easy to do, as fts3 has no syntax for escaping
128780130194
** a quote character embedded in a string.
128781130195
*/
128782130196
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.1"
139 #define SQLITE_VERSION_NUMBER 3008001
140 #define SQLITE_SOURCE_ID "2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -527,10 +527,11 @@
527 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
528 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
529 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
530 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
531 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
 
532 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
533 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
534 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
535
536 /*
@@ -938,10 +939,18 @@
938 ** pointer is overwritten with the old value. The limit is not changed if
939 ** the value originally pointed to is negative, and so the current limit
940 ** can be queried by passing in a pointer to a negative number. This
941 ** file-control is used internally to implement [PRAGMA mmap_size].
942 **
 
 
 
 
 
 
 
 
943 ** </ul>
944 */
945 #define SQLITE_FCNTL_LOCKSTATE 1
946 #define SQLITE_GET_LOCKPROXYFILE 2
947 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -957,10 +966,11 @@
957 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
958 #define SQLITE_FCNTL_PRAGMA 14
959 #define SQLITE_FCNTL_BUSYHANDLER 15
960 #define SQLITE_FCNTL_TEMPFILENAME 16
961 #define SQLITE_FCNTL_MMAP_SIZE 18
 
962
963 /*
964 ** CAPI3REF: Mutex Handle
965 **
966 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1803,23 +1813,25 @@
1803 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
1804
1805 /*
1806 ** CAPI3REF: Last Insert Rowid
1807 **
1808 ** ^Each entry in an SQLite table has a unique 64-bit signed
 
1809 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1810 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1811 ** names are not also used by explicitly declared columns. ^If
1812 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1813 ** is another alias for the rowid.
1814 **
1815 ** ^This routine returns the [rowid] of the most recent
1816 ** successful [INSERT] into the database from the [database connection]
1817 ** in the first argument. ^As of SQLite version 3.7.7, this routines
1818 ** records the last insert rowid of both ordinary tables and [virtual tables].
1819 ** ^If no successful [INSERT]s
1820 ** have ever occurred on that database connection, zero is returned.
 
1821 **
1822 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1823 ** method, then this routine will return the [rowid] of the inserted
1824 ** row as long as the trigger or virtual table method is running.
1825 ** But once the trigger or virtual table method ends, the value returned
@@ -4832,16 +4844,17 @@
4832 /*
4833 ** CAPI3REF: Data Change Notification Callbacks
4834 **
4835 ** ^The sqlite3_update_hook() interface registers a callback function
4836 ** with the [database connection] identified by the first argument
4837 ** to be invoked whenever a row is updated, inserted or deleted.
 
4838 ** ^Any callback set by a previous call to this function
4839 ** for the same database connection is overridden.
4840 **
4841 ** ^The second argument is a pointer to the function to invoke when a
4842 ** row is updated, inserted or deleted.
4843 ** ^The first argument to the callback is a copy of the third argument
4844 ** to sqlite3_update_hook().
4845 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
4846 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
4847 ** to be invoked.
@@ -4850,10 +4863,11 @@
4850 ** ^The final callback parameter is the [rowid] of the row.
4851 ** ^In the case of an update, this is the [rowid] after the update takes place.
4852 **
4853 ** ^(The update hook is not invoked when internal system tables are
4854 ** modified (i.e. sqlite_master and sqlite_sequence).)^
 
4855 **
4856 ** ^In the current implementation, the update hook
4857 ** is not invoked when duplication rows are deleted because of an
4858 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
4859 ** invoked when rows are deleted using the [truncate optimization].
@@ -5539,10 +5553,13 @@
5539 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5540 ** the opened blob. ^The size of a blob may not be changed by this
5541 ** interface. Use the [UPDATE] SQL command to change the size of a
5542 ** blob.
5543 **
 
 
 
5544 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5545 ** and the built-in [zeroblob] SQL function can be used, if desired,
5546 ** to create an empty, zero-filled blob in which to read or write using
5547 ** this interface.
5548 **
@@ -7756,10 +7773,17 @@
7756 #endif
7757 #if defined(NDEBUG) && defined(SQLITE_DEBUG)
7758 # undef NDEBUG
7759 #endif
7760
 
 
 
 
 
 
 
7761 /*
7762 ** The testcase() macro is used to aid in coverage testing. When
7763 ** doing coverage testing, the condition inside the argument to
7764 ** testcase() must be evaluated both true and false in order to
7765 ** get full branch coverage. The testcase() macro is inserted
@@ -7972,143 +7996,144 @@
7972 #define TK_EXISTS 20
7973 #define TK_TEMP 21
7974 #define TK_LP 22
7975 #define TK_RP 23
7976 #define TK_AS 24
7977 #define TK_COMMA 25
7978 #define TK_ID 26
7979 #define TK_INDEXED 27
7980 #define TK_ABORT 28
7981 #define TK_ACTION 29
7982 #define TK_AFTER 30
7983 #define TK_ANALYZE 31
7984 #define TK_ASC 32
7985 #define TK_ATTACH 33
7986 #define TK_BEFORE 34
7987 #define TK_BY 35
7988 #define TK_CASCADE 36
7989 #define TK_CAST 37
7990 #define TK_COLUMNKW 38
7991 #define TK_CONFLICT 39
7992 #define TK_DATABASE 40
7993 #define TK_DESC 41
7994 #define TK_DETACH 42
7995 #define TK_EACH 43
7996 #define TK_FAIL 44
7997 #define TK_FOR 45
7998 #define TK_IGNORE 46
7999 #define TK_INITIALLY 47
8000 #define TK_INSTEAD 48
8001 #define TK_LIKE_KW 49
8002 #define TK_MATCH 50
8003 #define TK_NO 51
8004 #define TK_KEY 52
8005 #define TK_OF 53
8006 #define TK_OFFSET 54
8007 #define TK_PRAGMA 55
8008 #define TK_RAISE 56
8009 #define TK_REPLACE 57
8010 #define TK_RESTRICT 58
8011 #define TK_ROW 59
8012 #define TK_TRIGGER 60
8013 #define TK_VACUUM 61
8014 #define TK_VIEW 62
8015 #define TK_VIRTUAL 63
8016 #define TK_REINDEX 64
8017 #define TK_RENAME 65
8018 #define TK_CTIME_KW 66
8019 #define TK_ANY 67
8020 #define TK_OR 68
8021 #define TK_AND 69
8022 #define TK_IS 70
8023 #define TK_BETWEEN 71
8024 #define TK_IN 72
8025 #define TK_ISNULL 73
8026 #define TK_NOTNULL 74
8027 #define TK_NE 75
8028 #define TK_EQ 76
8029 #define TK_GT 77
8030 #define TK_LE 78
8031 #define TK_LT 79
8032 #define TK_GE 80
8033 #define TK_ESCAPE 81
8034 #define TK_BITAND 82
8035 #define TK_BITOR 83
8036 #define TK_LSHIFT 84
8037 #define TK_RSHIFT 85
8038 #define TK_PLUS 86
8039 #define TK_MINUS 87
8040 #define TK_STAR 88
8041 #define TK_SLASH 89
8042 #define TK_REM 90
8043 #define TK_CONCAT 91
8044 #define TK_COLLATE 92
8045 #define TK_BITNOT 93
8046 #define TK_STRING 94
8047 #define TK_JOIN_KW 95
8048 #define TK_CONSTRAINT 96
8049 #define TK_DEFAULT 97
8050 #define TK_NULL 98
8051 #define TK_PRIMARY 99
8052 #define TK_UNIQUE 100
8053 #define TK_CHECK 101
8054 #define TK_REFERENCES 102
8055 #define TK_AUTOINCR 103
8056 #define TK_ON 104
8057 #define TK_INSERT 105
8058 #define TK_DELETE 106
8059 #define TK_UPDATE 107
8060 #define TK_SET 108
8061 #define TK_DEFERRABLE 109
8062 #define TK_FOREIGN 110
8063 #define TK_DROP 111
8064 #define TK_UNION 112
8065 #define TK_ALL 113
8066 #define TK_EXCEPT 114
8067 #define TK_INTERSECT 115
8068 #define TK_SELECT 116
8069 #define TK_DISTINCT 117
8070 #define TK_DOT 118
8071 #define TK_FROM 119
8072 #define TK_JOIN 120
8073 #define TK_USING 121
8074 #define TK_ORDER 122
8075 #define TK_GROUP 123
8076 #define TK_HAVING 124
8077 #define TK_LIMIT 125
8078 #define TK_WHERE 126
8079 #define TK_INTO 127
8080 #define TK_VALUES 128
8081 #define TK_INTEGER 129
8082 #define TK_FLOAT 130
8083 #define TK_BLOB 131
8084 #define TK_REGISTER 132
8085 #define TK_VARIABLE 133
8086 #define TK_CASE 134
8087 #define TK_WHEN 135
8088 #define TK_THEN 136
8089 #define TK_ELSE 137
8090 #define TK_INDEX 138
8091 #define TK_ALTER 139
8092 #define TK_ADD 140
8093 #define TK_TO_TEXT 141
8094 #define TK_TO_BLOB 142
8095 #define TK_TO_NUMERIC 143
8096 #define TK_TO_INT 144
8097 #define TK_TO_REAL 145
8098 #define TK_ISNOT 146
8099 #define TK_END_OF_FILE 147
8100 #define TK_ILLEGAL 148
8101 #define TK_SPACE 149
8102 #define TK_UNCLOSED_STRING 150
8103 #define TK_FUNCTION 151
8104 #define TK_COLUMN 152
8105 #define TK_AGG_FUNCTION 153
8106 #define TK_AGG_COLUMN 154
8107 #define TK_CONST_FUNC 155
8108 #define TK_UMINUS 156
8109 #define TK_UPLUS 157
 
8110
8111 /************** End of parse.h ***********************************************/
8112 /************** Continuing where we left off in sqliteInt.h ******************/
8113 #include <stdio.h>
8114 #include <stdlib.h>
@@ -8881,11 +8906,11 @@
8881 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
8882 int *ai; /* Used when p4type is P4_INTARRAY */
8883 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
8884 int (*xAdvance)(BtCursor *, int *);
8885 } p4;
8886 #ifdef SQLITE_DEBUG
8887 char *zComment; /* Comment to improve readability */
8888 #endif
8889 #ifdef VDBE_PROFILE
8890 int cnt; /* Number of times this instruction was executed */
8891 u64 cycles; /* Total time spent executing this instruction */
@@ -8937,19 +8962,15 @@
8937 #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
8938 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
8939 #define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */
8940 #define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
8941
8942 /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure
8943 ** is made. That copy is freed when the Vdbe is finalized. But if the
8944 ** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used. It still
8945 ** gets freed when the Vdbe is finalized so it still should be obtained
8946 ** from a single sqliteMalloc(). But no copy is made and the calling
8947 ** function should *not* try to free the KeyInfo.
8948 */
8949 #define P4_KEYINFO_HANDOFF (-16)
8950 #define P4_KEYINFO_STATIC (-17)
8951
8952 /*
8953 ** The Vdbe.aColName array contains 5n Mem structures, where n is the
8954 ** number of columns of data returned by the statement.
8955 */
@@ -8982,160 +9003,160 @@
8982 */
8983 /************** Include opcodes.h in the middle of vdbe.h ********************/
8984 /************** Begin file opcodes.h *****************************************/
8985 /* Automatically generated. Do not edit */
8986 /* See the mkopcodeh.awk script for details */
8987 #define OP_Function 1
8988 #define OP_Savepoint 2
8989 #define OP_AutoCommit 3
8990 #define OP_Transaction 4
8991 #define OP_SorterNext 5
8992 #define OP_Prev 6
8993 #define OP_Next 7
8994 #define OP_AggStep 8
8995 #define OP_Checkpoint 9
8996 #define OP_JournalMode 10
8997 #define OP_Vacuum 11
8998 #define OP_VFilter 12
8999 #define OP_VUpdate 13
9000 #define OP_Goto 14
9001 #define OP_Gosub 15
9002 #define OP_Return 16
9003 #define OP_Yield 17
9004 #define OP_HaltIfNull 18
9005 #define OP_Not 19 /* same as TK_NOT */
9006 #define OP_Halt 20
9007 #define OP_Integer 21
9008 #define OP_Int64 22
9009 #define OP_String 23
9010 #define OP_Null 24
9011 #define OP_Blob 25
9012 #define OP_Variable 26
9013 #define OP_Move 27
9014 #define OP_Copy 28
9015 #define OP_SCopy 29
9016 #define OP_ResultRow 30
9017 #define OP_CollSeq 31
9018 #define OP_AddImm 32
9019 #define OP_MustBeInt 33
9020 #define OP_RealAffinity 34
9021 #define OP_Permutation 35
9022 #define OP_Compare 36
9023 #define OP_Jump 37
9024 #define OP_Once 38
9025 #define OP_If 39
9026 #define OP_IfNot 40
9027 #define OP_Column 41
9028 #define OP_Affinity 42
9029 #define OP_MakeRecord 43
9030 #define OP_Count 44
9031 #define OP_ReadCookie 45
9032 #define OP_SetCookie 46
9033 #define OP_VerifyCookie 47
9034 #define OP_OpenRead 48
9035 #define OP_OpenWrite 49
9036 #define OP_OpenAutoindex 50
9037 #define OP_OpenEphemeral 51
9038 #define OP_SorterOpen 52
9039 #define OP_OpenPseudo 53
9040 #define OP_Close 54
9041 #define OP_SeekLt 55
9042 #define OP_SeekLe 56
9043 #define OP_SeekGe 57
9044 #define OP_SeekGt 58
9045 #define OP_Seek 59
9046 #define OP_NotFound 60
9047 #define OP_Found 61
9048 #define OP_IsUnique 62
9049 #define OP_NotExists 63
9050 #define OP_Sequence 64
9051 #define OP_NewRowid 65
9052 #define OP_Insert 66
9053 #define OP_InsertInt 67
9054 #define OP_Or 68 /* same as TK_OR */
9055 #define OP_And 69 /* same as TK_AND */
9056 #define OP_Delete 70
9057 #define OP_ResetCount 71
9058 #define OP_SorterCompare 72
9059 #define OP_IsNull 73 /* same as TK_ISNULL */
9060 #define OP_NotNull 74 /* same as TK_NOTNULL */
9061 #define OP_Ne 75 /* same as TK_NE */
9062 #define OP_Eq 76 /* same as TK_EQ */
9063 #define OP_Gt 77 /* same as TK_GT */
9064 #define OP_Le 78 /* same as TK_LE */
9065 #define OP_Lt 79 /* same as TK_LT */
9066 #define OP_Ge 80 /* same as TK_GE */
9067 #define OP_SorterData 81
9068 #define OP_BitAnd 82 /* same as TK_BITAND */
9069 #define OP_BitOr 83 /* same as TK_BITOR */
9070 #define OP_ShiftLeft 84 /* same as TK_LSHIFT */
9071 #define OP_ShiftRight 85 /* same as TK_RSHIFT */
9072 #define OP_Add 86 /* same as TK_PLUS */
9073 #define OP_Subtract 87 /* same as TK_MINUS */
9074 #define OP_Multiply 88 /* same as TK_STAR */
9075 #define OP_Divide 89 /* same as TK_SLASH */
9076 #define OP_Remainder 90 /* same as TK_REM */
9077 #define OP_Concat 91 /* same as TK_CONCAT */
9078 #define OP_RowKey 92
9079 #define OP_BitNot 93 /* same as TK_BITNOT */
9080 #define OP_String8 94 /* same as TK_STRING */
9081 #define OP_RowData 95
9082 #define OP_Rowid 96
9083 #define OP_NullRow 97
9084 #define OP_Last 98
9085 #define OP_SorterSort 99
9086 #define OP_Sort 100
9087 #define OP_Rewind 101
9088 #define OP_SorterInsert 102
9089 #define OP_IdxInsert 103
9090 #define OP_IdxDelete 104
9091 #define OP_IdxRowid 105
9092 #define OP_IdxLT 106
9093 #define OP_IdxGE 107
9094 #define OP_Destroy 108
9095 #define OP_Clear 109
9096 #define OP_CreateIndex 110
9097 #define OP_CreateTable 111
9098 #define OP_ParseSchema 112
9099 #define OP_LoadAnalysis 113
9100 #define OP_DropTable 114
9101 #define OP_DropIndex 115
9102 #define OP_DropTrigger 116
9103 #define OP_IntegrityCk 117
9104 #define OP_RowSetAdd 118
9105 #define OP_RowSetRead 119
9106 #define OP_RowSetTest 120
9107 #define OP_Program 121
9108 #define OP_Param 122
9109 #define OP_FkCounter 123
9110 #define OP_FkIfZero 124
9111 #define OP_MemMax 125
9112 #define OP_IfPos 126
9113 #define OP_IfNeg 127
9114 #define OP_IfZero 128
9115 #define OP_AggFinal 129
9116 #define OP_Real 130 /* same as TK_FLOAT */
9117 #define OP_IncrVacuum 131
9118 #define OP_Expire 132
9119 #define OP_TableLock 133
9120 #define OP_VBegin 134
9121 #define OP_VCreate 135
9122 #define OP_VDestroy 136
9123 #define OP_VOpen 137
9124 #define OP_VColumn 138
9125 #define OP_VNext 139
9126 #define OP_VRename 140
9127 #define OP_ToText 141 /* same as TK_TO_TEXT */
9128 #define OP_ToBlob 142 /* same as TK_TO_BLOB */
9129 #define OP_ToNumeric 143 /* same as TK_TO_NUMERIC*/
9130 #define OP_ToInt 144 /* same as TK_TO_INT */
9131 #define OP_ToReal 145 /* same as TK_TO_REAL */
9132 #define OP_Pagecount 146
9133 #define OP_MaxPgcnt 147
9134 #define OP_Trace 148
9135 #define OP_Noop 149
9136 #define OP_Explain 150
9137
9138
9139 /* Properties such as "out2" or "jump" that are specified in
9140 ** comments following the "case" for each opcode in the vdbe.c
9141 ** are encoded into bitvectors as follows:
@@ -9149,26 +9170,26 @@
9149 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9150 #define OPFLG_INITIALIZER {\
9151 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9152 /* 8 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01,\
9153 /* 16 */ 0x04, 0x04, 0x10, 0x24, 0x00, 0x02, 0x02, 0x02,\
9154 /* 24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x00, 0x00,\
9155 /* 32 */ 0x04, 0x05, 0x04, 0x00, 0x00, 0x01, 0x01, 0x05,\
9156 /* 40 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00,\
9157 /* 48 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,\
9158 /* 56 */ 0x11, 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11,\
9159 /* 64 */ 0x02, 0x02, 0x00, 0x00, 0x4c, 0x4c, 0x00, 0x00,\
9160 /* 72 */ 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
9161 /* 80 */ 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9162 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02, 0x00,\
9163 /* 96 */ 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08,\
9164 /* 104 */ 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02, 0x02,\
9165 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
9166 /* 120 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05, 0x05,\
9167 /* 128 */ 0x05, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,\
9168 /* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x04, 0x04,\
9169 /* 144 */ 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00,}
9170
9171 /************** End of opcodes.h *********************************************/
9172 /************** Continuing where we left off in vdbe.h ***********************/
9173
9174 /*
@@ -9189,10 +9210,11 @@
9189 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9190 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
9191 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
9192 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
9193 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
 
9194 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
9195 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
9196 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
9197 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
9198 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
@@ -9227,19 +9249,31 @@
9227
9228 #ifndef SQLITE_OMIT_TRIGGER
9229 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9230 #endif
9231
9232
9233 #ifndef NDEBUG
 
 
 
 
 
 
9234 SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
9235 # define VdbeComment(X) sqlite3VdbeComment X
9236 SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
9237 # define VdbeNoopComment(X) sqlite3VdbeNoopComment X
 
 
 
 
 
9238 #else
9239 # define VdbeComment(X)
9240 # define VdbeNoopComment(X)
 
9241 #endif
9242
9243 #endif
9244
9245 /************** End of vdbe.h ************************************************/
@@ -10631,10 +10665,11 @@
10631 #define TF_Readonly 0x01 /* Read-only system table */
10632 #define TF_Ephemeral 0x02 /* An ephemeral table */
10633 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
10634 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
10635 #define TF_Virtual 0x10 /* Is a virtual table */
 
10636
10637
10638 /*
10639 ** Test to see whether or not a table is a virtual table. This is
10640 ** done as a macro so that it will be optimized out when virtual
@@ -10646,10 +10681,13 @@
10646 #else
10647 # define IsVirtual(X) 0
10648 # define IsHiddenColumn(X) 0
10649 #endif
10650
 
 
 
10651 /*
10652 ** Each foreign key constraint is an instance of the following structure.
10653 **
10654 ** A foreign key is associated with two tables. The "from" table is
10655 ** the table that contains the REFERENCES clause that creates the foreign
@@ -10660,30 +10698,39 @@
10660 ** a INTEGER PRIMARY KEY,
10661 ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
10662 ** );
10663 **
10664 ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
 
 
 
 
10665 **
10666 ** Each REFERENCES clause generates an instance of the following structure
10667 ** which is attached to the from-table. The to-table need not exist when
10668 ** the from-table is created. The existence of the to-table is not checked.
 
 
 
 
 
10669 */
10670 struct FKey {
10671 Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */
10672 FKey *pNextFrom; /* Next foreign key in pFrom */
10673 char *zTo; /* Name of table that the key points to (aka: Parent) */
10674 FKey *pNextTo; /* Next foreign key on table named zTo */
10675 FKey *pPrevTo; /* Previous foreign key on table named zTo */
10676 int nCol; /* Number of columns in this key */
10677 /* EV: R-30323-21917 */
10678 u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
10679 u8 aAction[2]; /* ON DELETE and ON UPDATE actions, respectively */
10680 Trigger *apTrigger[2]; /* Triggers for aAction[] actions */
10681 struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
10682 int iFrom; /* Index of column in pFrom */
10683 char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */
10684 } aCol[1]; /* One entry for each of nCol column s */
10685 };
10686
10687 /*
10688 ** SQLite supports many different ways to resolve a constraint
10689 ** error. ROLLBACK processing means that a constraint violation
@@ -10732,13 +10779,15 @@
10732 ** Note that aSortOrder[] and aColl[] have nField+1 slots. There
10733 ** are nField slots for the columns of an index then one extra slot
10734 ** for the rowid at the end.
10735 */
10736 struct KeyInfo {
10737 sqlite3 *db; /* The database connection */
10738 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
10739 u16 nField; /* Maximum index for aColl[] and aSortOrder[] */
 
 
10740 u8 *aSortOrder; /* Sort order for each column. */
10741 CollSeq *aColl[1]; /* Collating sequence for each term of the key */
10742 };
10743
10744 /*
@@ -10757,20 +10806,18 @@
10757 */
10758 struct UnpackedRecord {
10759 KeyInfo *pKeyInfo; /* Collation and sort-order information */
10760 u16 nField; /* Number of entries in apMem[] */
10761 u8 flags; /* Boolean settings. UNPACKED_... below */
10762 i64 rowid; /* Used by UNPACKED_PREFIX_SEARCH */
10763 Mem *aMem; /* Values */
10764 };
10765
10766 /*
10767 ** Allowed values of UnpackedRecord.flags
10768 */
10769 #define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
10770 #define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
10771 #define UNPACKED_PREFIX_SEARCH 0x04 /* Ignore final (rowid) field */
10772
10773 /*
10774 ** Each SQL index is represented in memory by an
10775 ** instance of the following structure.
10776 **
@@ -10796,26 +10843,30 @@
10796 ** algorithm to employ whenever an attempt is made to insert a non-unique
10797 ** element.
10798 */
10799 struct Index {
10800 char *zName; /* Name of this index */
10801 int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10802 tRowcnt *aiRowEst; /* From ANALYZE: Est. rows selected by each column */
10803 Table *pTable; /* The SQL table being indexed */
10804 char *zColAff; /* String defining the affinity of each column */
10805 Index *pNext; /* The next index associated with the same table */
10806 Schema *pSchema; /* Schema containing this index */
10807 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
10808 char **azColl; /* Array of collation sequence names for index */
10809 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
 
10810 int tnum; /* DB Page containing root of this index */
10811 LogEst szIdxRow; /* Estimated average row size in bytes */
10812 u16 nColumn; /* Number of columns in table used by this index */
 
10813 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10814 unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
10815 unsigned bUnordered:1; /* Use this index for == or IN queries only */
10816 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
 
 
10817 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
10818 int nSample; /* Number of elements in aSample[] */
10819 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
10820 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
10821 IndexSample *aSample; /* Samples of the left-most key */
@@ -11490,10 +11541,12 @@
11490 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
11491
11492 /* Information used while coding trigger programs. */
11493 Parse *pToplevel; /* Parse structure for main program (or NULL) */
11494 Table *pTriggerTab; /* Table triggers are being coded for */
 
 
11495 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
11496 u32 oldmask; /* Mask of old.* columns referenced */
11497 u32 newmask; /* Mask of new.* columns referenced */
11498 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
11499 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
@@ -11502,10 +11555,11 @@
11502 /* Above is constant between recursions. Below is reset before and after
11503 ** each recursion */
11504
11505 int nVar; /* Number of '?' variables seen in the SQL so far */
11506 int nzVar; /* Number of available slots in azVar[] */
 
11507 u8 explain; /* True if the EXPLAIN flag is found on the query */
11508 #ifndef SQLITE_OMIT_VIRTUALTABLE
11509 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
11510 int nVtabLock; /* Number of virtual tables to lock */
11511 #endif
@@ -11515,11 +11569,10 @@
11515 int iSelectId; /* ID of current select for EXPLAIN output */
11516 int iNextSelectId; /* Next available select ID for EXPLAIN output */
11517 #endif
11518 char **azVar; /* Pointers to names of parameters */
11519 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
11520 int *aAlias; /* Register used to hold aliased result */
11521 const char *zTail; /* All SQL text past the last semicolon parsed */
11522 Table *pNewTable; /* A table being constructed by CREATE TABLE */
11523 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
11524 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
11525 Token sNameToken; /* Token with unqualified schema object name */
@@ -11984,19 +12037,21 @@
11984 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
11985 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
11986 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
11987 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
11988 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
 
 
11989 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
11990 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*);
11991 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
11992 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
11993 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
11994 SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
11995 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
11996 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
11997 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
11998 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
11999 sqlite3_vfs**,char**,char **);
12000 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
12001 SQLITE_PRIVATE int sqlite3CodeOnce(Parse *);
12002
@@ -12045,10 +12100,11 @@
12045 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
12046 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
12047 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
12048 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
12049 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
 
12050 SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
12051 Expr*, int, int);
12052 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
12053 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
12054 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
@@ -12067,11 +12123,11 @@
12067 SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo*);
12068 SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
12069 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
12070 SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
12071 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
12072 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*);
12073 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
12074 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
12075 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
12076 SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
12077 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
@@ -12121,21 +12177,23 @@
12121 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12122 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12123 SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
12124 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12125 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12126 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
12127 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*);
12128 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
12129 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
12130 int*,int,int,int,int,int*);
12131 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
12132 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
12133 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
12134 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
12135 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
12136 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, int);
 
 
12137 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
12138 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
12139 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
12140 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
12141 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int);
@@ -12349,12 +12407,17 @@
12349 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
12350 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
12351 SQLITE_PRIVATE void sqlite3SchemaClear(void *);
12352 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
12353 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
12354 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int);
12355 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
 
 
 
 
 
12356 SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
12357 void (*)(sqlite3_context*,int,sqlite3_value **),
12358 void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
12359 FuncDestructor *pDestructor
12360 );
@@ -13350,12 +13413,11 @@
13350 i64 seqCount; /* Sequence counter */
13351 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13352 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
13353 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
13354
13355 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
13356 ** OP_IsUnique opcode on this cursor. */
13357 int seekResult;
13358
13359 /* Cached information about the header for the data record that the
13360 ** cursor is currently pointing to. Only valid if cacheStatus matches
13361 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -13716,11 +13778,11 @@
13716 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
13717 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
13718 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
13719 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, const VdbeCursor *, int *);
13720 SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, const VdbeCursor *, Mem *);
13721 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int *);
13722
13723 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
13724 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
13725 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
13726 #else
@@ -22794,163 +22856,168 @@
22794
22795 /************** End of hash.c ************************************************/
22796 /************** Begin file opcodes.c *****************************************/
22797 /* Automatically generated. Do not edit */
22798 /* See the mkopcodec.awk script for details. */
22799 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
 
 
 
 
 
22800 SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
22801 static const char *const azName[] = { "?",
22802 /* 1 */ "Function",
22803 /* 2 */ "Savepoint",
22804 /* 3 */ "AutoCommit",
22805 /* 4 */ "Transaction",
22806 /* 5 */ "SorterNext",
22807 /* 6 */ "Prev",
22808 /* 7 */ "Next",
22809 /* 8 */ "AggStep",
22810 /* 9 */ "Checkpoint",
22811 /* 10 */ "JournalMode",
22812 /* 11 */ "Vacuum",
22813 /* 12 */ "VFilter",
22814 /* 13 */ "VUpdate",
22815 /* 14 */ "Goto",
22816 /* 15 */ "Gosub",
22817 /* 16 */ "Return",
22818 /* 17 */ "Yield",
22819 /* 18 */ "HaltIfNull",
22820 /* 19 */ "Not",
22821 /* 20 */ "Halt",
22822 /* 21 */ "Integer",
22823 /* 22 */ "Int64",
22824 /* 23 */ "String",
22825 /* 24 */ "Null",
22826 /* 25 */ "Blob",
22827 /* 26 */ "Variable",
22828 /* 27 */ "Move",
22829 /* 28 */ "Copy",
22830 /* 29 */ "SCopy",
22831 /* 30 */ "ResultRow",
22832 /* 31 */ "CollSeq",
22833 /* 32 */ "AddImm",
22834 /* 33 */ "MustBeInt",
22835 /* 34 */ "RealAffinity",
22836 /* 35 */ "Permutation",
22837 /* 36 */ "Compare",
22838 /* 37 */ "Jump",
22839 /* 38 */ "Once",
22840 /* 39 */ "If",
22841 /* 40 */ "IfNot",
22842 /* 41 */ "Column",
22843 /* 42 */ "Affinity",
22844 /* 43 */ "MakeRecord",
22845 /* 44 */ "Count",
22846 /* 45 */ "ReadCookie",
22847 /* 46 */ "SetCookie",
22848 /* 47 */ "VerifyCookie",
22849 /* 48 */ "OpenRead",
22850 /* 49 */ "OpenWrite",
22851 /* 50 */ "OpenAutoindex",
22852 /* 51 */ "OpenEphemeral",
22853 /* 52 */ "SorterOpen",
22854 /* 53 */ "OpenPseudo",
22855 /* 54 */ "Close",
22856 /* 55 */ "SeekLt",
22857 /* 56 */ "SeekLe",
22858 /* 57 */ "SeekGe",
22859 /* 58 */ "SeekGt",
22860 /* 59 */ "Seek",
22861 /* 60 */ "NotFound",
22862 /* 61 */ "Found",
22863 /* 62 */ "IsUnique",
22864 /* 63 */ "NotExists",
22865 /* 64 */ "Sequence",
22866 /* 65 */ "NewRowid",
22867 /* 66 */ "Insert",
22868 /* 67 */ "InsertInt",
22869 /* 68 */ "Or",
22870 /* 69 */ "And",
22871 /* 70 */ "Delete",
22872 /* 71 */ "ResetCount",
22873 /* 72 */ "SorterCompare",
22874 /* 73 */ "IsNull",
22875 /* 74 */ "NotNull",
22876 /* 75 */ "Ne",
22877 /* 76 */ "Eq",
22878 /* 77 */ "Gt",
22879 /* 78 */ "Le",
22880 /* 79 */ "Lt",
22881 /* 80 */ "Ge",
22882 /* 81 */ "SorterData",
22883 /* 82 */ "BitAnd",
22884 /* 83 */ "BitOr",
22885 /* 84 */ "ShiftLeft",
22886 /* 85 */ "ShiftRight",
22887 /* 86 */ "Add",
22888 /* 87 */ "Subtract",
22889 /* 88 */ "Multiply",
22890 /* 89 */ "Divide",
22891 /* 90 */ "Remainder",
22892 /* 91 */ "Concat",
22893 /* 92 */ "RowKey",
22894 /* 93 */ "BitNot",
22895 /* 94 */ "String8",
22896 /* 95 */ "RowData",
22897 /* 96 */ "Rowid",
22898 /* 97 */ "NullRow",
22899 /* 98 */ "Last",
22900 /* 99 */ "SorterSort",
22901 /* 100 */ "Sort",
22902 /* 101 */ "Rewind",
22903 /* 102 */ "SorterInsert",
22904 /* 103 */ "IdxInsert",
22905 /* 104 */ "IdxDelete",
22906 /* 105 */ "IdxRowid",
22907 /* 106 */ "IdxLT",
22908 /* 107 */ "IdxGE",
22909 /* 108 */ "Destroy",
22910 /* 109 */ "Clear",
22911 /* 110 */ "CreateIndex",
22912 /* 111 */ "CreateTable",
22913 /* 112 */ "ParseSchema",
22914 /* 113 */ "LoadAnalysis",
22915 /* 114 */ "DropTable",
22916 /* 115 */ "DropIndex",
22917 /* 116 */ "DropTrigger",
22918 /* 117 */ "IntegrityCk",
22919 /* 118 */ "RowSetAdd",
22920 /* 119 */ "RowSetRead",
22921 /* 120 */ "RowSetTest",
22922 /* 121 */ "Program",
22923 /* 122 */ "Param",
22924 /* 123 */ "FkCounter",
22925 /* 124 */ "FkIfZero",
22926 /* 125 */ "MemMax",
22927 /* 126 */ "IfPos",
22928 /* 127 */ "IfNeg",
22929 /* 128 */ "IfZero",
22930 /* 129 */ "AggFinal",
22931 /* 130 */ "Real",
22932 /* 131 */ "IncrVacuum",
22933 /* 132 */ "Expire",
22934 /* 133 */ "TableLock",
22935 /* 134 */ "VBegin",
22936 /* 135 */ "VCreate",
22937 /* 136 */ "VDestroy",
22938 /* 137 */ "VOpen",
22939 /* 138 */ "VColumn",
22940 /* 139 */ "VNext",
22941 /* 140 */ "VRename",
22942 /* 141 */ "ToText",
22943 /* 142 */ "ToBlob",
22944 /* 143 */ "ToNumeric",
22945 /* 144 */ "ToInt",
22946 /* 145 */ "ToReal",
22947 /* 146 */ "Pagecount",
22948 /* 147 */ "MaxPgcnt",
22949 /* 148 */ "Trace",
22950 /* 149 */ "Noop",
22951 /* 150 */ "Explain",
22952 };
22953 return azName[i];
22954 }
22955 #endif
22956
@@ -25053,11 +25120,13 @@
25053 **
25054 ** If the locking level of the file descriptor is already at or below
25055 ** the requested locking level, this routine is a no-op.
25056 */
25057 static int unixUnlock(sqlite3_file *id, int eFileLock){
 
25058 assert( eFileLock==SHARED_LOCK || ((unixFile *)id)->nFetchOut==0 );
 
25059 return posixUnlock(id, eFileLock, 0);
25060 }
25061
25062 #if SQLITE_MAX_MMAP_SIZE>0
25063 static int unixMapfile(unixFile *pFd, i64 nByte);
@@ -30878,38 +30947,52 @@
30878 #if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
30879 # error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
30880 must be defined."
30881 #endif
30882
 
 
 
 
 
 
 
30883 /*
30884 ** Maximum pathname length (in chars) for Win32. This should normally be
30885 ** MAX_PATH.
30886 */
30887 #ifndef SQLITE_WIN32_MAX_PATH_CHARS
30888 # define SQLITE_WIN32_MAX_PATH_CHARS (MAX_PATH)
30889 #endif
30890
 
 
 
 
 
 
 
30891 /*
30892 ** Maximum pathname length (in chars) for WinNT. This should normally be
30893 ** 32767.
30894 */
30895 #ifndef SQLITE_WINNT_MAX_PATH_CHARS
30896 # define SQLITE_WINNT_MAX_PATH_CHARS (32767)
30897 #endif
30898
30899 /*
30900 ** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in
30901 ** characters, so we allocate 3 bytes per character assuming worst-case of
30902 ** 4-bytes-per-character for UTF8.
30903 */
30904 #ifndef SQLITE_WIN32_MAX_PATH_BYTES
30905 # define SQLITE_WIN32_MAX_PATH_BYTES (SQLITE_WIN32_MAX_PATH_CHARS*4)
30906 #endif
30907
30908 /*
30909 ** Maximum pathname length (in bytes) for WinNT. This should normally be
30910 ** 32767 * sizeof(WCHAR).
30911 */
30912 #ifndef SQLITE_WINNT_MAX_PATH_BYTES
30913 # define SQLITE_WINNT_MAX_PATH_BYTES \
30914 (sizeof(WCHAR) * SQLITE_WINNT_MAX_PATH_CHARS)
30915 #endif
@@ -30936,18 +31019,14 @@
30936 #ifndef UNUSED_VARIABLE_VALUE
30937 # define UNUSED_VARIABLE_VALUE(x) (void)(x)
30938 #endif
30939
30940 /*
30941 ** Returns the string that should be used as the directory separator.
30942 */
30943 #ifndef winGetDirDep
30944 # ifdef __CYGWIN__
30945 # define winGetDirDep() "/"
30946 # else
30947 # define winGetDirDep() "\\"
30948 # endif
30949 #endif
30950
30951 /*
30952 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
30953 ** mode (e.g. these APIs are available in the Windows CE SDK; however, they
@@ -31135,34 +31214,45 @@
31135 ** sqlite3_mem_methods implementation.
31136 */
31137 typedef struct winMemData winMemData;
31138 struct winMemData {
31139 #ifndef NDEBUG
31140 u32 magic; /* Magic number to detect structure corruption. */
31141 #endif
31142 HANDLE hHeap; /* The handle to our heap. */
31143 BOOL bOwned; /* Do we own the heap (i.e. destroy it on shutdown)? */
 
 
 
31144 };
31145
31146 #ifndef NDEBUG
31147 #define WINMEM_MAGIC 0x42b2830b
 
31148 #endif
31149
31150 static struct winMemData win_mem_data = {
31151 #ifndef NDEBUG
31152 WINMEM_MAGIC,
31153 #endif
31154 NULL, FALSE
 
 
 
31155 };
31156
31157 #ifndef NDEBUG
31158 #define winMemAssertMagic() assert( win_mem_data.magic==WINMEM_MAGIC )
 
 
31159 #else
31160 #define winMemAssertMagic()
31161 #endif
31162
31163 #define winMemGetHeap() win_mem_data.hHeap
 
 
31164
31165 static void *winMemMalloc(int nBytes);
31166 static void winMemFree(void *pPrior);
31167 static void *winMemRealloc(void *pPrior, int nBytes);
31168 static int winMemSize(void *p);
@@ -31555,44 +31645,52 @@
31555 #endif
31556
31557 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
31558 LPCVOID))aSyscall[42].pCurrent)
31559
 
 
 
 
 
 
 
 
31560 #if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31561 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
31562 #else
31563 { "LoadLibraryA", (SYSCALL)0, 0 },
31564 #endif
31565
31566 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[43].pCurrent)
31567
31568 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
31569 !defined(SQLITE_OMIT_LOAD_EXTENSION)
31570 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
31571 #else
31572 { "LoadLibraryW", (SYSCALL)0, 0 },
31573 #endif
31574
31575 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[44].pCurrent)
31576
31577 #if !SQLITE_OS_WINRT
31578 { "LocalFree", (SYSCALL)LocalFree, 0 },
31579 #else
31580 { "LocalFree", (SYSCALL)0, 0 },
31581 #endif
31582
31583 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[45].pCurrent)
31584
31585 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31586 { "LockFile", (SYSCALL)LockFile, 0 },
31587 #else
31588 { "LockFile", (SYSCALL)0, 0 },
31589 #endif
31590
31591 #ifndef osLockFile
31592 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31593 DWORD))aSyscall[46].pCurrent)
31594 #endif
31595
31596 #if !SQLITE_OS_WINCE
31597 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
31598 #else
@@ -31599,218 +31697,218 @@
31599 { "LockFileEx", (SYSCALL)0, 0 },
31600 #endif
31601
31602 #ifndef osLockFileEx
31603 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
31604 LPOVERLAPPED))aSyscall[47].pCurrent)
31605 #endif
31606
31607 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
31608 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
31609 #else
31610 { "MapViewOfFile", (SYSCALL)0, 0 },
31611 #endif
31612
31613 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31614 SIZE_T))aSyscall[48].pCurrent)
31615
31616 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
31617
31618 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
31619 int))aSyscall[49].pCurrent)
31620
31621 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
31622
31623 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
31624 LARGE_INTEGER*))aSyscall[50].pCurrent)
31625
31626 { "ReadFile", (SYSCALL)ReadFile, 0 },
31627
31628 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
31629 LPOVERLAPPED))aSyscall[51].pCurrent)
31630
31631 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
31632
31633 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent)
31634
31635 #if !SQLITE_OS_WINRT
31636 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
31637 #else
31638 { "SetFilePointer", (SYSCALL)0, 0 },
31639 #endif
31640
31641 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
31642 DWORD))aSyscall[53].pCurrent)
31643
31644 #if !SQLITE_OS_WINRT
31645 { "Sleep", (SYSCALL)Sleep, 0 },
31646 #else
31647 { "Sleep", (SYSCALL)0, 0 },
31648 #endif
31649
31650 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[54].pCurrent)
31651
31652 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
31653
31654 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
31655 LPFILETIME))aSyscall[55].pCurrent)
31656
31657 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31658 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
31659 #else
31660 { "UnlockFile", (SYSCALL)0, 0 },
31661 #endif
31662
31663 #ifndef osUnlockFile
31664 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31665 DWORD))aSyscall[56].pCurrent)
31666 #endif
31667
31668 #if !SQLITE_OS_WINCE
31669 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
31670 #else
31671 { "UnlockFileEx", (SYSCALL)0, 0 },
31672 #endif
31673
31674 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31675 LPOVERLAPPED))aSyscall[57].pCurrent)
31676
31677 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
31678 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
31679 #else
31680 { "UnmapViewOfFile", (SYSCALL)0, 0 },
31681 #endif
31682
31683 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[58].pCurrent)
31684
31685 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
31686
31687 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
31688 LPCSTR,LPBOOL))aSyscall[59].pCurrent)
31689
31690 { "WriteFile", (SYSCALL)WriteFile, 0 },
31691
31692 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
31693 LPOVERLAPPED))aSyscall[60].pCurrent)
31694
31695 #if SQLITE_OS_WINRT
31696 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
31697 #else
31698 { "CreateEventExW", (SYSCALL)0, 0 },
31699 #endif
31700
31701 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
31702 DWORD,DWORD))aSyscall[61].pCurrent)
31703
31704 #if !SQLITE_OS_WINRT
31705 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
31706 #else
31707 { "WaitForSingleObject", (SYSCALL)0, 0 },
31708 #endif
31709
31710 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
31711 DWORD))aSyscall[62].pCurrent)
31712
31713 #if SQLITE_OS_WINRT
31714 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
31715 #else
31716 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
31717 #endif
31718
31719 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
31720 BOOL))aSyscall[63].pCurrent)
31721
31722 #if SQLITE_OS_WINRT
31723 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
31724 #else
31725 { "SetFilePointerEx", (SYSCALL)0, 0 },
31726 #endif
31727
31728 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
31729 PLARGE_INTEGER,DWORD))aSyscall[64].pCurrent)
31730
31731 #if SQLITE_OS_WINRT
31732 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
31733 #else
31734 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
31735 #endif
31736
31737 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
31738 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[65].pCurrent)
31739
31740 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31741 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
31742 #else
31743 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
31744 #endif
31745
31746 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
31747 SIZE_T))aSyscall[66].pCurrent)
31748
31749 #if SQLITE_OS_WINRT
31750 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
31751 #else
31752 { "CreateFile2", (SYSCALL)0, 0 },
31753 #endif
31754
31755 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
31756 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[67].pCurrent)
31757
31758 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31759 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
31760 #else
31761 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
31762 #endif
31763
31764 #define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
31765 DWORD))aSyscall[68].pCurrent)
31766
31767 #if SQLITE_OS_WINRT
31768 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
31769 #else
31770 { "GetTickCount64", (SYSCALL)0, 0 },
31771 #endif
31772
31773 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[69].pCurrent)
31774
31775 #if SQLITE_OS_WINRT
31776 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
31777 #else
31778 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
31779 #endif
31780
31781 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
31782 LPSYSTEM_INFO))aSyscall[70].pCurrent)
31783
31784 #if defined(SQLITE_WIN32_HAS_ANSI)
31785 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
31786 #else
31787 { "OutputDebugStringA", (SYSCALL)0, 0 },
31788 #endif
31789
31790 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[71].pCurrent)
31791
31792 #if defined(SQLITE_WIN32_HAS_WIDE)
31793 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
31794 #else
31795 { "OutputDebugStringW", (SYSCALL)0, 0 },
31796 #endif
31797
31798 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[72].pCurrent)
31799
31800 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
31801
31802 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[73].pCurrent)
31803
31804 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31805 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
31806 #else
31807 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
31808 #endif
31809
31810 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
31811 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[74].pCurrent)
31812
31813 }; /* End of the overrideable system calls */
31814
31815 /*
31816 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -31893,10 +31991,98 @@
31893 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
31894 }
31895 return 0;
31896 }
31897
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31898 /*
31899 ** This function outputs the specified (ANSI) string to the Win32 debugger
31900 ** (if available).
31901 */
31902
@@ -32001,11 +32187,11 @@
32001 winMemAssertMagic();
32002 hHeap = winMemGetHeap();
32003 assert( hHeap!=0 );
32004 assert( hHeap!=INVALID_HANDLE_VALUE );
32005 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32006 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32007 #endif
32008 assert( nBytes>=0 );
32009 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
32010 if( !p ){
32011 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%lu), heap=%p",
@@ -32023,11 +32209,11 @@
32023 winMemAssertMagic();
32024 hHeap = winMemGetHeap();
32025 assert( hHeap!=0 );
32026 assert( hHeap!=INVALID_HANDLE_VALUE );
32027 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32028 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32029 #endif
32030 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
32031 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
32032 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%lu), heap=%p",
32033 pPrior, osGetLastError(), (void*)hHeap);
@@ -32044,11 +32230,11 @@
32044 winMemAssertMagic();
32045 hHeap = winMemGetHeap();
32046 assert( hHeap!=0 );
32047 assert( hHeap!=INVALID_HANDLE_VALUE );
32048 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32049 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32050 #endif
32051 assert( nBytes>=0 );
32052 if( !pPrior ){
32053 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
32054 }else{
@@ -32072,11 +32258,11 @@
32072 winMemAssertMagic();
32073 hHeap = winMemGetHeap();
32074 assert( hHeap!=0 );
32075 assert( hHeap!=INVALID_HANDLE_VALUE );
32076 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32077 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32078 #endif
32079 if( !p ) return 0;
32080 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
32081 if( n==(SIZE_T)-1 ){
32082 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%lu), heap=%p",
@@ -32098,11 +32284,12 @@
32098 */
32099 static int winMemInit(void *pAppData){
32100 winMemData *pWinMemData = (winMemData *)pAppData;
32101
32102 if( !pWinMemData ) return SQLITE_ERROR;
32103 assert( pWinMemData->magic==WINMEM_MAGIC );
 
32104
32105 #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
32106 if( !pWinMemData->hHeap ){
32107 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
32108 SQLITE_WIN32_HEAP_INIT_SIZE,
@@ -32140,10 +32327,13 @@
32140 */
32141 static void winMemShutdown(void *pAppData){
32142 winMemData *pWinMemData = (winMemData *)pAppData;
32143
32144 if( !pWinMemData ) return;
 
 
 
32145 if( pWinMemData->hHeap ){
32146 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
32147 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32148 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32149 #endif
@@ -34809,16 +34999,25 @@
34809 return zConverted;
34810 }
34811
34812 /*
34813 ** This function returns non-zero if the specified UTF-8 string buffer
34814 ** ends with a directory separator character.
 
34815 */
34816 static int winEndsInDirSep(char *zBuf){
34817 if( zBuf ){
34818 int nLen = sqlite3Strlen30(zBuf);
34819 return nLen>0 && winIsDirSep(zBuf[nLen-1]);
 
 
 
 
 
 
 
 
34820 }
34821 return 0;
34822 }
34823
34824 /*
@@ -34829,11 +35028,12 @@
34829 static char zChars[] =
34830 "abcdefghijklmnopqrstuvwxyz"
34831 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34832 "0123456789";
34833 size_t i, j;
34834 int nBuf, nLen;
 
34835 char *zBuf;
34836
34837 /* It's odd to simulate an io-error here, but really this is just
34838 ** using the io-error infrastructure to test that SQLite handles this
34839 ** function failing.
@@ -34841,26 +35041,36 @@
34841 SimulateIOError( return SQLITE_IOERR );
34842
34843 /* Allocate a temporary buffer to store the fully qualified file
34844 ** name for the temporary file. If this fails, we cannot continue.
34845 */
34846 nBuf = pVfs->mxPathname;
34847 zBuf = sqlite3MallocZero( nBuf+2 );
34848 if( !zBuf ){
34849 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34850 return SQLITE_IOERR_NOMEM;
34851 }
34852
34853 /* Figure out the effective temporary directory. First, check if one
34854 ** has been explicitly set by the application; otherwise, use the one
34855 ** configured by the operating system.
34856 */
34857 assert( nBuf>30 );
 
34858 if( sqlite3_temp_directory ){
34859 sqlite3_snprintf(nBuf-30, zBuf, "%s%s", sqlite3_temp_directory,
34860 winEndsInDirSep(sqlite3_temp_directory) ? "" :
34861 winGetDirDep());
 
 
 
 
 
 
 
 
 
34862 }
34863 #if defined(__CYGWIN__)
34864 else{
34865 static const char *azDirs[] = {
34866 0, /* getenv("SQLITE_TMPDIR") */
@@ -34885,41 +35095,41 @@
34885 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34886 void *zConverted;
34887 if( zDir==0 ) continue;
34888 /* If the path starts with a drive letter followed by the colon
34889 ** character, assume it is already a native Win32 path; otherwise,
34890 ** it must be converted to a native Win32 path prior via the Cygwin
34891 ** API prior to using it.
34892 */
34893 if( winIsDriveLetterAndColon(zDir) ){
34894 zConverted = winConvertFromUtf8Filename(zDir);
34895 if( !zConverted ){
34896 sqlite3_free(zBuf);
34897 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34898 return SQLITE_IOERR_NOMEM;
34899 }
34900 if( winIsDir(zConverted) ){
34901 sqlite3_snprintf(nBuf-30, zBuf, "%s", zDir);
34902 sqlite3_free(zConverted);
34903 break;
34904 }
34905 sqlite3_free(zConverted);
34906 }else{
34907 zConverted = sqlite3MallocZero( nBuf+1 );
34908 if( !zConverted ){
34909 sqlite3_free(zBuf);
34910 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34911 return SQLITE_IOERR_NOMEM;
34912 }
34913 if( cygwin_conv_path(
34914 osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
34915 zConverted, nBuf+1)<0 ){
34916 sqlite3_free(zConverted);
34917 sqlite3_free(zBuf);
34918 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
34919 return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
34920 "winGetTempname1", zDir);
34921 }
34922 if( winIsDir(zConverted) ){
34923 /* At this point, we know the candidate directory exists and should
34924 ** be used. However, we may need to convert the string containing
34925 ** its name into UTF-8 (i.e. if it is UTF-16 right now).
@@ -34930,16 +35140,16 @@
34930 sqlite3_free(zConverted);
34931 sqlite3_free(zBuf);
34932 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34933 return SQLITE_IOERR_NOMEM;
34934 }
34935 sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8);
34936 sqlite3_free(zUtf8);
34937 sqlite3_free(zConverted);
34938 break;
34939 }else{
34940 sqlite3_snprintf(nBuf-30, zBuf, "%s", zConverted);
34941 sqlite3_free(zConverted);
34942 break;
34943 }
34944 }
34945 sqlite3_free(zConverted);
@@ -34947,26 +35157,26 @@
34947 }
34948 }
34949 #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__)
34950 else if( osIsNT() ){
34951 char *zMulti;
34952 LPWSTR zWidePath = sqlite3MallocZero( nBuf*sizeof(WCHAR) );
34953 if( !zWidePath ){
34954 sqlite3_free(zBuf);
34955 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34956 return SQLITE_IOERR_NOMEM;
34957 }
34958 if( osGetTempPathW(nBuf, zWidePath)==0 ){
34959 sqlite3_free(zWidePath);
34960 sqlite3_free(zBuf);
34961 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
34962 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
34963 "winGetTempname1", 0);
34964 }
34965 zMulti = winUnicodeToUtf8(zWidePath);
34966 if( zMulti ){
34967 sqlite3_snprintf(nBuf-30, zBuf, "%s", zMulti);
34968 sqlite3_free(zMulti);
34969 sqlite3_free(zWidePath);
34970 }else{
34971 sqlite3_free(zWidePath);
34972 sqlite3_free(zBuf);
@@ -34975,25 +35185,25 @@
34975 }
34976 }
34977 #ifdef SQLITE_WIN32_HAS_ANSI
34978 else{
34979 char *zUtf8;
34980 char *zMbcsPath = sqlite3MallocZero( nBuf );
34981 if( !zMbcsPath ){
34982 sqlite3_free(zBuf);
34983 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34984 return SQLITE_IOERR_NOMEM;
34985 }
34986 if( osGetTempPathA(nBuf, zMbcsPath)==0 ){
34987 sqlite3_free(zBuf);
34988 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
34989 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
34990 "winGetTempname2", 0);
34991 }
34992 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
34993 if( zUtf8 ){
34994 sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8);
34995 sqlite3_free(zUtf8);
34996 }else{
34997 sqlite3_free(zBuf);
34998 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34999 return SQLITE_IOERR_NOMEM;
@@ -35000,22 +35210,40 @@
35000 }
35001 }
35002 #endif /* SQLITE_WIN32_HAS_ANSI */
35003 #endif /* !SQLITE_OS_WINRT */
35004
35005 /* Check that the output buffer is large enough for the temporary file
35006 ** name. If it is not, return SQLITE_ERROR.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35007 */
35008 nLen = sqlite3Strlen30(zBuf);
35009
35010 if( (nLen + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
35011 sqlite3_free(zBuf);
35012 OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
35013 return winLogError(SQLITE_ERROR, 0, "winGetTempname3", 0);
35014 }
35015
35016 sqlite3_snprintf(nBuf-18-nLen, zBuf+nLen, SQLITE_TEMP_FILE_PREFIX);
35017
35018 j = sqlite3Strlen30(zBuf);
35019 sqlite3_randomness(15, &zBuf[j]);
35020 for(i=0; i<15; i++, j++){
35021 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
@@ -35066,11 +35294,11 @@
35066 sqlite3_file *id, /* Write the SQLite file handle here */
35067 int flags, /* Open mode flags */
35068 int *pOutFlags /* Status return flags */
35069 ){
35070 HANDLE h;
35071 DWORD lastErrno;
35072 DWORD dwDesiredAccess;
35073 DWORD dwShareMode;
35074 DWORD dwCreationDisposition;
35075 DWORD dwFlagsAndAttributes = 0;
35076 #if SQLITE_OS_WINCE
@@ -35357,11 +35585,11 @@
35357 int syncDir /* Not used on win32 */
35358 ){
35359 int cnt = 0;
35360 int rc;
35361 DWORD attr;
35362 DWORD lastErrno;
35363 void *zConverted;
35364 UNUSED_PARAMETER(pVfs);
35365 UNUSED_PARAMETER(syncDir);
35366
35367 SimulateIOError(return SQLITE_IOERR_DELETE);
@@ -35465,11 +35693,11 @@
35465 int flags, /* Type of test to make on this file */
35466 int *pResOut /* OUT: Result */
35467 ){
35468 DWORD attr;
35469 int rc = 0;
35470 DWORD lastErrno;
35471 void *zConverted;
35472 UNUSED_PARAMETER(pVfs);
35473
35474 SimulateIOError( return SQLITE_IOERR_ACCESS; );
35475 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
@@ -35611,12 +35839,12 @@
35611 pVfs->mxPathname+1)<0 ){
35612 sqlite3_free(zOut);
35613 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
35614 "winFullPathname1", zRelative);
35615 }
35616 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s",
35617 sqlite3_data_directory, winGetDirDep(), zOut);
35618 sqlite3_free(zOut);
35619 }else{
35620 if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){
35621 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
35622 "winFullPathname2", zRelative);
@@ -35634,12 +35862,12 @@
35634 ** NOTE: We are dealing with a relative path name and the data
35635 ** directory has been set. Therefore, use it as the basis
35636 ** for converting the relative path name to an absolute
35637 ** one by prepending the data directory and a backslash.
35638 */
35639 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s",
35640 sqlite3_data_directory, winGetDirDep(), zRelative);
35641 }else{
35642 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
35643 }
35644 return SQLITE_OK;
35645 #endif
@@ -35667,12 +35895,12 @@
35667 ** NOTE: We are dealing with a relative path name and the data
35668 ** directory has been set. Therefore, use it as the basis
35669 ** for converting the relative path name to an absolute
35670 ** one by prepending the data directory and a backslash.
35671 */
35672 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s",
35673 sqlite3_data_directory, winGetDirDep(), zRelative);
35674 return SQLITE_OK;
35675 }
35676 zConverted = winConvertFromUtf8Filename(zRelative);
35677 if( zConverted==0 ){
35678 return SQLITE_IOERR_NOMEM;
@@ -36006,11 +36234,11 @@
36006 };
36007 #endif
36008
36009 /* Double-check that the aSyscall[] array has been constructed
36010 ** correctly. See ticket [bb3a86e890c8e96ab] */
36011 assert( ArraySize(aSyscall)==75 );
36012
36013 /* get memory map allocation granularity */
36014 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
36015 #if SQLITE_OS_WINRT
36016 osGetNativeSystemInfo(&winSysInfo);
@@ -50676,11 +50904,11 @@
50676 int bias, /* Bias search to the high end */
50677 int *pRes /* Write search results here */
50678 ){
50679 int rc; /* Status code */
50680 UnpackedRecord *pIdxKey; /* Unpacked index key */
50681 char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
50682 char *pFree = 0;
50683
50684 if( pKey ){
50685 assert( nKey==(i64)(int)nKey );
50686 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
@@ -60294,19 +60522,19 @@
60294
60295 if( pRec==0 ){
60296 Index *pIdx = p->pIdx; /* Index being probed */
60297 int nByte; /* Bytes of space to allocate */
60298 int i; /* Counter variable */
60299 int nCol = pIdx->nColumn+1; /* Number of index columns including rowid */
60300
60301 nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord);
60302 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
60303 if( pRec ){
60304 pRec->pKeyInfo = sqlite3IndexKeyinfo(p->pParse, pIdx);
60305 if( pRec->pKeyInfo ){
60306 assert( pRec->pKeyInfo->nField+1==nCol );
60307 pRec->pKeyInfo->enc = ENC(db);
60308 pRec->flags = UNPACKED_PREFIX_MATCH;
60309 pRec->aMem = (Mem *)&pRec[1];
60310 for(i=0; i<nCol; i++){
60311 pRec->aMem[i].flags = MEM_Null;
60312 pRec->aMem[i].type = SQLITE_NULL;
@@ -60625,17 +60853,17 @@
60625 ** the object.
60626 */
60627 SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){
60628 if( pRec ){
60629 int i;
60630 int nCol = pRec->pKeyInfo->nField+1;
60631 Mem *aMem = pRec->aMem;
60632 sqlite3 *db = aMem[0].db;
60633 for(i=0; i<nCol; i++){
60634 sqlite3DbFree(db, aMem[i].zMalloc);
60635 }
60636 sqlite3DbFree(db, pRec->pKeyInfo);
60637 sqlite3DbFree(db, pRec);
60638 }
60639 }
60640 #endif /* ifdef SQLITE_ENABLE_STAT4 */
60641
@@ -60784,10 +61012,21 @@
60784 p->aOp = pNew;
60785 }
60786 return (pNew ? SQLITE_OK : SQLITE_NOMEM);
60787 }
60788
 
 
 
 
 
 
 
 
 
 
 
60789 /*
60790 ** Add a new instruction to the list of instructions current in the
60791 ** VDBE. Return the address of the new instruction.
60792 **
60793 ** Parameters:
@@ -60821,14 +61060,17 @@
60821 pOp->p1 = p1;
60822 pOp->p2 = p2;
60823 pOp->p3 = p3;
60824 pOp->p4.p = 0;
60825 pOp->p4type = P4_NOTUSED;
60826 #ifdef SQLITE_DEBUG
60827 pOp->zComment = 0;
 
 
60828 if( p->db->flags & SQLITE_VdbeAddopTrace ){
60829 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
 
60830 }
60831 #endif
60832 #ifdef VDBE_PROFILE
60833 pOp->cycles = 0;
60834 pOp->cnt = 0;
@@ -61200,21 +61442,24 @@
61200 for(i=0; i<nOp; i++, pIn++){
61201 int p2 = pIn->p2;
61202 VdbeOp *pOut = &p->aOp[i+addr];
61203 pOut->opcode = pIn->opcode;
61204 pOut->p1 = pIn->p1;
61205 if( p2<0 && (sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP)!=0 ){
 
61206 pOut->p2 = addr + ADDR(p2);
61207 }else{
61208 pOut->p2 = p2;
61209 }
61210 pOut->p3 = pIn->p3;
61211 pOut->p4type = P4_NOTUSED;
61212 pOut->p4.p = 0;
61213 pOut->p5 = 0;
61214 #ifdef SQLITE_DEBUG
61215 pOut->zComment = 0;
 
 
61216 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61217 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
61218 }
61219 #endif
61220 }
@@ -61298,15 +61543,17 @@
61298 assert( db );
61299 switch( p4type ){
61300 case P4_REAL:
61301 case P4_INT64:
61302 case P4_DYNAMIC:
61303 case P4_KEYINFO:
61304 case P4_INTARRAY:
61305 case P4_KEYINFO_HANDOFF: {
61306 sqlite3DbFree(db, p4);
61307 break;
 
 
 
 
61308 }
61309 case P4_MPRINTF: {
61310 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
61311 break;
61312 }
@@ -61340,11 +61587,11 @@
61340 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
61341 if( aOp ){
61342 Op *pOp;
61343 for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
61344 freeP4(db, pOp->p4type, pOp->p4.p);
61345 #ifdef SQLITE_DEBUG
61346 sqlite3DbFree(db, pOp->zComment);
61347 #endif
61348 }
61349 }
61350 sqlite3DbFree(db, aOp);
@@ -61368,10 +61615,11 @@
61368 VdbeOp *pOp = &p->aOp[addr];
61369 sqlite3 *db = p->db;
61370 freeP4(db, pOp->p4type, pOp->p4.p);
61371 memset(pOp, 0, sizeof(pOp[0]));
61372 pOp->opcode = OP_Noop;
 
61373 }
61374 }
61375
61376 /*
61377 ** Change the value of the P4 operand for a specific instruction.
@@ -61381,18 +61629,10 @@
61381 **
61382 ** If n>=0 then the P4 operand is dynamic, meaning that a copy of
61383 ** the string is made into memory obtained from sqlite3_malloc().
61384 ** A value of n==0 means copy bytes of zP4 up to and including the
61385 ** first null byte. If n>0 then copy n+1 bytes of zP4.
61386 **
61387 ** If n==P4_KEYINFO it means that zP4 is a pointer to a KeyInfo structure.
61388 ** A copy is made of the KeyInfo structure into memory obtained from
61389 ** sqlite3_malloc, to be freed when the Vdbe is finalized.
61390 ** n==P4_KEYINFO_HANDOFF indicates that zP4 points to a KeyInfo structure
61391 ** stored in memory that the caller has obtained from sqlite3_malloc. The
61392 ** caller should not free the allocation, it will be freed when the Vdbe is
61393 ** finalized.
61394 **
61395 ** Other values of n (P4_STATIC, P4_COLLSEQ etc.) indicate that zP4 points
61396 ** to a string or structure that is guaranteed to exist for the lifetime of
61397 ** the Vdbe. In these cases we can just copy the pointer.
61398 **
@@ -61403,11 +61643,11 @@
61403 sqlite3 *db;
61404 assert( p!=0 );
61405 db = p->db;
61406 assert( p->magic==VDBE_MAGIC_INIT );
61407 if( p->aOp==0 || db->mallocFailed ){
61408 if ( n!=P4_KEYINFO && n!=P4_VTAB ) {
61409 freeP4(db, n, (void*)*(char**)&zP4);
61410 }
61411 return;
61412 }
61413 assert( p->nOp>0 );
@@ -61426,23 +61666,10 @@
61426 pOp->p4type = P4_INT32;
61427 }else if( zP4==0 ){
61428 pOp->p4.p = 0;
61429 pOp->p4type = P4_NOTUSED;
61430 }else if( n==P4_KEYINFO ){
61431 KeyInfo *pOrig, *pNew;
61432
61433 pOrig = (KeyInfo*)zP4;
61434 pOp->p4.pKeyInfo = pNew = sqlite3KeyInfoAlloc(db, pOrig->nField);
61435 if( pNew ){
61436 memcpy(pNew->aColl, pOrig->aColl, pOrig->nField*sizeof(pNew->aColl[0]));
61437 memcpy(pNew->aSortOrder, pOrig->aSortOrder, pOrig->nField);
61438 pOp->p4type = P4_KEYINFO;
61439 }else{
61440 p->db->mallocFailed = 1;
61441 pOp->p4type = P4_NOTUSED;
61442 }
61443 }else if( n==P4_KEYINFO_HANDOFF ){
61444 pOp->p4.p = (void*)zP4;
61445 pOp->p4type = P4_KEYINFO;
61446 }else if( n==P4_VTAB ){
61447 pOp->p4.p = (void*)zP4;
61448 pOp->p4type = P4_VTAB;
@@ -61456,11 +61683,23 @@
61456 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
61457 pOp->p4type = P4_DYNAMIC;
61458 }
61459 }
61460
61461 #ifndef NDEBUG
 
 
 
 
 
 
 
 
 
 
 
 
61462 /*
61463 ** Change the comment on the most recently coded instruction. Or
61464 ** insert a No-op and add the comment to that new instruction. This
61465 ** makes the code easier to read during debugging. None of this happens
61466 ** in a production build.
@@ -61530,10 +61769,85 @@
61530 return (VdbeOp*)&dummy;
61531 }else{
61532 return &p->aOp[addr];
61533 }
61534 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61535
61536 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \
61537 || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
61538 /*
61539 ** Compute a string that describes the P4 parameter for an opcode.
@@ -61541,21 +61855,24 @@
61541 */
61542 static char *displayP4(Op *pOp, char *zTemp, int nTemp){
61543 char *zP4 = zTemp;
61544 assert( nTemp>=20 );
61545 switch( pOp->p4type ){
61546 case P4_KEYINFO_STATIC:
61547 case P4_KEYINFO: {
61548 int i, j;
61549 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
61550 assert( pKeyInfo->aSortOrder!=0 );
61551 sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
61552 i = sqlite3Strlen30(zTemp);
61553 for(j=0; j<pKeyInfo->nField; j++){
61554 CollSeq *pColl = pKeyInfo->aColl[j];
61555 const char *zColl = pColl ? pColl->zName : "nil";
61556 int n = sqlite3Strlen30(zColl);
 
 
 
 
61557 if( i+n>nTemp-6 ){
61558 memcpy(&zTemp[i],",...",4);
61559 break;
61560 }
61561 zTemp[i++] = ',';
@@ -61724,20 +62041,22 @@
61724 ** Print a single opcode. This routine is used for debugging only.
61725 */
61726 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
61727 char *zP4;
61728 char zPtr[50];
61729 static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-4s %.2X %s\n";
 
61730 if( pOut==0 ) pOut = stdout;
61731 zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
 
 
 
 
 
61732 fprintf(pOut, zFormat1, pc,
61733 sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
61734 #ifdef SQLITE_DEBUG
61735 pOp->zComment ? pOp->zComment : ""
61736 #else
61737 ""
61738 #endif
61739 );
61740 fflush(pOut);
61741 }
61742 #endif
61743
@@ -61879,11 +62198,11 @@
61879 }else if( db->u1.isInterrupted ){
61880 p->rc = SQLITE_INTERRUPT;
61881 rc = SQLITE_ERROR;
61882 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
61883 }else{
61884 char *z;
61885 Op *pOp;
61886 if( i<p->nOp ){
61887 /* The output line number is small enough that we are still in the
61888 ** main program. */
61889 pOp = &p->aOp[i];
@@ -61902,11 +62221,11 @@
61902 pMem->type = SQLITE_INTEGER;
61903 pMem->u.i = i; /* Program counter */
61904 pMem++;
61905
61906 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
61907 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
61908 assert( pMem->z!=0 );
61909 pMem->n = sqlite3Strlen30(pMem->z);
61910 pMem->type = SQLITE_TEXT;
61911 pMem->enc = SQLITE_UTF8;
61912 pMem++;
@@ -61949,13 +62268,13 @@
61949 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
61950 assert( p->db->mallocFailed );
61951 return SQLITE_ERROR;
61952 }
61953 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
61954 z = displayP4(pOp, pMem->z, 32);
61955 if( z!=pMem->z ){
61956 sqlite3VdbeMemSetStr(pMem, z, -1, SQLITE_UTF8, 0);
61957 }else{
61958 assert( pMem->z!=0 );
61959 pMem->n = sqlite3Strlen30(pMem->z);
61960 pMem->enc = SQLITE_UTF8;
61961 }
@@ -61972,23 +62291,23 @@
61972 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
61973 pMem->type = SQLITE_TEXT;
61974 pMem->enc = SQLITE_UTF8;
61975 pMem++;
61976
61977 #ifdef SQLITE_DEBUG
61978 if( pOp->zComment ){
61979 pMem->flags = MEM_Str|MEM_Term;
61980 pMem->z = pOp->zComment;
61981 pMem->n = sqlite3Strlen30(pMem->z);
61982 pMem->enc = SQLITE_UTF8;
61983 pMem->type = SQLITE_TEXT;
61984 }else
 
 
 
 
61985 #endif
61986 {
61987 pMem->flags = MEM_Null; /* Comment */
61988 pMem->type = SQLITE_NULL;
61989 }
61990 }
61991
61992 p->nResColumn = 8 - 4*(p->explain-1);
61993 p->pResultSet = &p->aMem[1];
61994 p->rc = SQLITE_OK;
@@ -62775,11 +63094,11 @@
62775 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
62776 || (!deferred && p->nFkConstraint>0)
62777 ){
62778 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
62779 p->errorAction = OE_Abort;
62780 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
62781 return SQLITE_ERROR;
62782 }
62783 return SQLITE_OK;
62784 }
62785 #endif
@@ -63706,11 +64025,11 @@
63706 */
63707 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
63708
63709 idx1 = getVarint32(aKey1, szHdr1);
63710 d1 = szHdr1;
63711 assert( pKeyInfo->nField+1>=pPKey2->nField );
63712 assert( pKeyInfo->aSortOrder!=0 );
63713 while( idx1<szHdr1 && i<pPKey2->nField ){
63714 u32 serial_type1;
63715
63716 /* Read the serial types for the next element in each key. */
@@ -63735,28 +64054,13 @@
63735 /* Do the comparison
63736 */
63737 rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
63738 if( rc!=0 ){
63739 assert( mem1.zMalloc==0 ); /* See comment below */
63740
63741 /* Invert the result if we are using DESC sort order. */
63742 if( pKeyInfo->aSortOrder[i] ){
63743 rc = -rc;
63744 }
63745
63746 /* If the PREFIX_SEARCH flag is set and all fields except the final
63747 ** rowid field were equal, then clear the PREFIX_SEARCH flag and set
63748 ** pPKey2->rowid to the value of the rowid field in (pKey1, nKey1).
63749 ** This is used by the OP_IsUnique opcode.
63750 */
63751 if( (pPKey2->flags & UNPACKED_PREFIX_SEARCH) && i==(pPKey2->nField-1) ){
63752 assert( idx1==szHdr1 && rc );
63753 assert( mem1.flags & MEM_Int );
63754 pPKey2->flags &= ~UNPACKED_PREFIX_SEARCH;
63755 pPKey2->rowid = mem1.u.i;
63756 }
63757
63758 return rc;
63759 }
63760 i++;
63761 }
63762
@@ -66271,77 +66575,81 @@
66271 */
66272 union vdbeExecUnion {
66273 struct OP_Yield_stack_vars {
66274 int pcDest;
66275 } aa;
 
 
 
 
66276 struct OP_Null_stack_vars {
66277 int cnt;
66278 u16 nullFlag;
66279 } ab;
66280 struct OP_Variable_stack_vars {
66281 Mem *pVar; /* Value being transferred */
66282 } ac;
66283 struct OP_Move_stack_vars {
66284 char *zMalloc; /* Holding variable for allocated memory */
66285 int n; /* Number of registers left to copy */
66286 int p1; /* Register to copy from */
66287 int p2; /* Register to copy to */
66288 } ad;
66289 struct OP_Copy_stack_vars {
66290 int n;
66291 } ae;
66292 struct OP_ResultRow_stack_vars {
66293 Mem *pMem;
66294 int i;
66295 } af;
66296 struct OP_Concat_stack_vars {
66297 i64 nByte;
66298 } ag;
66299 struct OP_Remainder_stack_vars {
66300 char bIntint; /* Started out as two integer operands */
66301 int flags; /* Combined MEM_* flags from both inputs */
66302 i64 iA; /* Integer value of left operand */
66303 i64 iB; /* Integer value of right operand */
66304 double rA; /* Real value of left operand */
66305 double rB; /* Real value of right operand */
66306 } ah;
66307 struct OP_Function_stack_vars {
66308 int i;
66309 Mem *pArg;
66310 sqlite3_context ctx;
66311 sqlite3_value **apVal;
66312 int n;
66313 } ai;
66314 struct OP_ShiftRight_stack_vars {
66315 i64 iA;
66316 u64 uA;
66317 i64 iB;
66318 u8 op;
66319 } aj;
66320 struct OP_Ge_stack_vars {
66321 int res; /* Result of the comparison of pIn1 against pIn3 */
66322 char affinity; /* Affinity to use for comparison */
66323 u16 flags1; /* Copy of initial value of pIn1->flags */
66324 u16 flags3; /* Copy of initial value of pIn3->flags */
66325 } ak;
66326 struct OP_Compare_stack_vars {
66327 int n;
66328 int i;
66329 int p1;
66330 int p2;
66331 const KeyInfo *pKeyInfo;
66332 int idx;
66333 CollSeq *pColl; /* Collating sequence to use on this term */
66334 int bRev; /* True for DESCENDING sort order */
66335 } al;
66336 struct OP_Or_stack_vars {
66337 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66338 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66339 } am;
66340 struct OP_IfNot_stack_vars {
66341 int c;
66342 } an;
66343 struct OP_Column_stack_vars {
66344 u32 payloadSize; /* Number of bytes in the record */
66345 i64 payloadSize64; /* Number of bytes in the record */
66346 int p1; /* P1 value of the opcode */
66347 int p2; /* column number to retrieve */
@@ -66362,15 +66670,15 @@
66362 u32 szField; /* Number of bytes in the content of a field */
66363 int szHdr; /* Size of the header size field at start of record */
66364 int avail; /* Number of bytes of available data */
66365 u32 t; /* A type code from the record header */
66366 Mem *pReg; /* PseudoTable input register */
66367 } ao;
66368 struct OP_Affinity_stack_vars {
66369 const char *zAffinity; /* The affinity to be applied */
66370 char cAff; /* A single character of affinity */
66371 } ap;
66372 struct OP_MakeRecord_stack_vars {
66373 u8 *zNewRecord; /* A buffer to hold the data for the new record */
66374 Mem *pRec; /* The new record */
66375 u64 nData; /* Number of bytes of data space */
66376 int nHdr; /* Number of bytes of header space */
@@ -66383,93 +66691,86 @@
66383 int nField; /* Number of fields in the record */
66384 char *zAffinity; /* The affinity string for the record */
66385 int file_format; /* File format to use for encoding */
66386 int i; /* Space used in zNewRecord[] */
66387 int len; /* Length of a field */
66388 } aq;
66389 struct OP_Count_stack_vars {
66390 i64 nEntry;
66391 BtCursor *pCrsr;
66392 } ar;
66393 struct OP_Savepoint_stack_vars {
66394 int p1; /* Value of P1 operand */
66395 char *zName; /* Name of savepoint */
66396 int nName;
66397 Savepoint *pNew;
66398 Savepoint *pSavepoint;
66399 Savepoint *pTmp;
66400 int iSavepoint;
66401 int ii;
66402 } as;
66403 struct OP_AutoCommit_stack_vars {
66404 int desiredAutoCommit;
66405 int iRollback;
66406 int turnOnAC;
66407 } at;
66408 struct OP_Transaction_stack_vars {
66409 Btree *pBt;
66410 } au;
66411 struct OP_ReadCookie_stack_vars {
66412 int iMeta;
66413 int iDb;
66414 int iCookie;
66415 } av;
66416 struct OP_SetCookie_stack_vars {
66417 Db *pDb;
66418 } aw;
66419 struct OP_VerifyCookie_stack_vars {
66420 int iMeta;
66421 int iGen;
66422 Btree *pBt;
66423 } ax;
66424 struct OP_OpenWrite_stack_vars {
66425 int nField;
66426 KeyInfo *pKeyInfo;
66427 int p2;
66428 int iDb;
66429 int wrFlag;
66430 Btree *pX;
66431 VdbeCursor *pCur;
66432 Db *pDb;
66433 } ay;
66434 struct OP_OpenEphemeral_stack_vars {
66435 VdbeCursor *pCx;
66436 } az;
 
66437 struct OP_SorterOpen_stack_vars {
66438 VdbeCursor *pCx;
66439 } ba;
66440 struct OP_OpenPseudo_stack_vars {
66441 VdbeCursor *pCx;
66442 } bb;
66443 struct OP_SeekGt_stack_vars {
66444 int res;
66445 int oc;
66446 VdbeCursor *pC;
66447 UnpackedRecord r;
66448 int nField;
66449 i64 iKey; /* The rowid we are to seek to */
66450 } bc;
66451 struct OP_Seek_stack_vars {
66452 VdbeCursor *pC;
66453 } bd;
66454 struct OP_Found_stack_vars {
66455 int alreadyExists;
 
66456 VdbeCursor *pC;
66457 int res;
66458 char *pFree;
66459 UnpackedRecord *pIdxKey;
66460 UnpackedRecord r;
66461 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*3 + 7];
66462 } be;
66463 struct OP_IsUnique_stack_vars {
66464 u16 ii;
66465 VdbeCursor *pCx;
66466 BtCursor *pCrsr;
66467 u16 nField;
66468 Mem *aMx;
66469 UnpackedRecord r; /* B-Tree index search key */
66470 i64 R; /* Rowid stored in register P3 */
66471 } bf;
66472 struct OP_NotExists_stack_vars {
66473 VdbeCursor *pC;
66474 BtCursor *pCrsr;
66475 int res;
@@ -66499,10 +66800,11 @@
66499 VdbeCursor *pC;
66500 } bj;
66501 struct OP_SorterCompare_stack_vars {
66502 VdbeCursor *pC;
66503 int res;
 
66504 } bk;
66505 struct OP_SorterData_stack_vars {
66506 VdbeCursor *pC;
66507 } bl;
66508 struct OP_RowData_stack_vars {
@@ -66939,23 +67241,25 @@
66939 REGISTER_TRACE(pOp->p1, pIn1);
66940 pc = u.aa.pcDest;
66941 break;
66942 }
66943
66944 /* Opcode: HaltIfNull P1 P2 P3 P4 *
 
66945 **
66946 ** Check the value in register P3. If it is NULL then Halt using
66947 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the
66948 ** value in register P3 is not NULL, then this routine is a no-op.
 
66949 */
66950 case OP_HaltIfNull: { /* in3 */
66951 pIn3 = &aMem[pOp->p3];
66952 if( (pIn3->flags & MEM_Null)==0 ) break;
66953 /* Fall through into OP_Halt */
66954 }
66955
66956 /* Opcode: Halt P1 P2 * P4 *
66957 **
66958 ** Exit immediately. All open cursors, etc are closed
66959 ** automatically.
66960 **
66961 ** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
@@ -66965,26 +67269,42 @@
66965 ** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
66966 ** then back out all changes that have occurred during this execution of the
66967 ** VDBE, but do not rollback the transaction.
66968 **
66969 ** If P4 is not null then it is an error message string.
 
 
 
 
 
 
 
 
 
 
 
66970 **
66971 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
66972 ** every program. So a jump past the last instruction of the program
66973 ** is the same as executing Halt.
66974 */
66975 case OP_Halt: {
 
 
 
 
 
66976 if( pOp->p1==SQLITE_OK && p->pFrame ){
66977 /* Halt the sub-program. Return control to the parent frame. */
66978 VdbeFrame *pFrame = p->pFrame;
66979 p->pFrame = pFrame->pParent;
66980 p->nFrame--;
66981 sqlite3VdbeSetChanges(db, p->nChange);
66982 pc = sqlite3VdbeFrameRestore(pFrame);
66983 lastRowid = db->lastRowid;
66984 if( pOp->p2==OE_Ignore ){
66985 /* Instruction pc is the OP_Program that invoked the sub-program
66986 ** currently being halted. If the p2 instruction of this OP_Halt
66987 ** instruction is set to OE_Ignore, then the sub-program is throwing
66988 ** an IGNORE exception. In this case jump to the address specified
66989 ** as the p2 of the calling OP_Program. */
66990 pc = p->aOp[pc].p2-1;
@@ -66991,22 +67311,37 @@
66991 }
66992 aOp = p->aOp;
66993 aMem = p->aMem;
66994 break;
66995 }
66996
66997 p->rc = pOp->p1;
66998 p->errorAction = (u8)pOp->p2;
66999 p->pc = pc;
67000 if( pOp->p4.z ){
67001 assert( p->rc!=SQLITE_OK );
67002 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67003 testcase( sqlite3GlobalConfig.xLog!=0 );
67004 sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pc, p->zSql, pOp->p4.z);
67005 }else if( p->rc ){
67006 testcase( sqlite3GlobalConfig.xLog!=0 );
67007 sqlite3_log(pOp->p1, "constraint failed at %d in [%s]", pc, p->zSql);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67008 }
67009 rc = sqlite3VdbeHalt(p);
67010 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67011 if( rc==SQLITE_BUSY ){
67012 p->rc = rc = SQLITE_BUSY;
@@ -67017,19 +67352,21 @@
67017 }
67018 goto vdbe_return;
67019 }
67020
67021 /* Opcode: Integer P1 P2 * * *
 
67022 **
67023 ** The 32-bit integer value P1 is written into register P2.
67024 */
67025 case OP_Integer: { /* out2-prerelease */
67026 pOut->u.i = pOp->p1;
67027 break;
67028 }
67029
67030 /* Opcode: Int64 * P2 * P4 *
 
67031 **
67032 ** P4 is a pointer to a 64-bit integer value.
67033 ** Write that value into register P2.
67034 */
67035 case OP_Int64: { /* out2-prerelease */
@@ -67038,10 +67375,11 @@
67038 break;
67039 }
67040
67041 #ifndef SQLITE_OMIT_FLOATING_POINT
67042 /* Opcode: Real * P2 * P4 *
 
67043 **
67044 ** P4 is a pointer to a 64-bit floating point value.
67045 ** Write that value into register P2.
67046 */
67047 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
@@ -67051,10 +67389,11 @@
67051 break;
67052 }
67053 #endif
67054
67055 /* Opcode: String8 * P2 * P4 *
 
67056 **
67057 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67058 ** into an OP_String before it is executed for the first time.
67059 */
67060 case OP_String8: { /* same as TK_STRING, out2-prerelease */
@@ -67085,10 +67424,11 @@
67085 }
67086 /* Fall through to the next case, OP_String */
67087 }
67088
67089 /* Opcode: String P1 P2 * P4 *
 
67090 **
67091 ** The string value P4 of length P1 (bytes) is stored in register P2.
67092 */
67093 case OP_String: { /* out2-prerelease */
67094 assert( pOp->p4.z!=0 );
@@ -67099,10 +67439,11 @@
67099 UPDATE_MAX_BLOBSIZE(pOut);
67100 break;
67101 }
67102
67103 /* Opcode: Null P1 P2 P3 * *
 
67104 **
67105 ** Write a NULL into registers P2. If P3 greater than P2, then also write
67106 ** NULL into register P3 and every register in between P2 and P3. If P3
67107 ** is less than P2 (typically P3 is zero) then only register P2 is
67108 ** set to NULL.
@@ -67110,29 +67451,30 @@
67110 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67111 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67112 ** OP_Ne or OP_Eq.
67113 */
67114 case OP_Null: { /* out2-prerelease */
67115 #if 0 /* local variables moved into u.ab */
67116 int cnt;
67117 u16 nullFlag;
67118 #endif /* local variables moved into u.ab */
67119 u.ab.cnt = pOp->p3-pOp->p2;
67120 assert( pOp->p3<=(p->nMem-p->nCursor) );
67121 pOut->flags = u.ab.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67122 while( u.ab.cnt>0 ){
67123 pOut++;
67124 memAboutToChange(p, pOut);
67125 VdbeMemRelease(pOut);
67126 pOut->flags = u.ab.nullFlag;
67127 u.ab.cnt--;
67128 }
67129 break;
67130 }
67131
67132
67133 /* Opcode: Blob P1 P2 * P4
 
67134 **
67135 ** P4 points to a blob of data P1 bytes long. Store this
67136 ** blob in register P2.
67137 */
67138 case OP_Blob: { /* out2-prerelease */
@@ -67142,107 +67484,111 @@
67142 UPDATE_MAX_BLOBSIZE(pOut);
67143 break;
67144 }
67145
67146 /* Opcode: Variable P1 P2 * P4 *
 
67147 **
67148 ** Transfer the values of bound parameter P1 into register P2
67149 **
67150 ** If the parameter is named, then its name appears in P4 and P3==1.
67151 ** The P4 value is used by sqlite3_bind_parameter_name().
67152 */
67153 case OP_Variable: { /* out2-prerelease */
67154 #if 0 /* local variables moved into u.ac */
67155 Mem *pVar; /* Value being transferred */
67156 #endif /* local variables moved into u.ac */
67157
67158 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67159 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67160 u.ac.pVar = &p->aVar[pOp->p1 - 1];
67161 if( sqlite3VdbeMemTooBig(u.ac.pVar) ){
67162 goto too_big;
67163 }
67164 sqlite3VdbeMemShallowCopy(pOut, u.ac.pVar, MEM_Static);
67165 UPDATE_MAX_BLOBSIZE(pOut);
67166 break;
67167 }
67168
67169 /* Opcode: Move P1 P2 P3 * *
 
67170 **
67171 ** Move the values in register P1..P1+P3 over into
67172 ** registers P2..P2+P3. Registers P1..P1+P3 are
67173 ** left holding a NULL. It is an error for register ranges
67174 ** P1..P1+P3 and P2..P2+P3 to overlap.
67175 */
67176 case OP_Move: {
67177 #if 0 /* local variables moved into u.ad */
67178 char *zMalloc; /* Holding variable for allocated memory */
67179 int n; /* Number of registers left to copy */
67180 int p1; /* Register to copy from */
67181 int p2; /* Register to copy to */
67182 #endif /* local variables moved into u.ad */
67183
67184 u.ad.n = pOp->p3 + 1;
67185 u.ad.p1 = pOp->p1;
67186 u.ad.p2 = pOp->p2;
67187 assert( u.ad.n>0 && u.ad.p1>0 && u.ad.p2>0 );
67188 assert( u.ad.p1+u.ad.n<=u.ad.p2 || u.ad.p2+u.ad.n<=u.ad.p1 );
67189
67190 pIn1 = &aMem[u.ad.p1];
67191 pOut = &aMem[u.ad.p2];
67192 while( u.ad.n-- ){
67193 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67194 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67195 assert( memIsValid(pIn1) );
67196 memAboutToChange(p, pOut);
67197 u.ad.zMalloc = pOut->zMalloc;
67198 pOut->zMalloc = 0;
67199 sqlite3VdbeMemMove(pOut, pIn1);
67200 #ifdef SQLITE_DEBUG
67201 if( pOut->pScopyFrom>=&aMem[u.ad.p1] && pOut->pScopyFrom<&aMem[u.ad.p1+pOp->p3] ){
67202 pOut->pScopyFrom += u.ad.p1 - pOp->p2;
67203 }
67204 #endif
67205 pIn1->zMalloc = u.ad.zMalloc;
67206 REGISTER_TRACE(u.ad.p2++, pOut);
67207 pIn1++;
67208 pOut++;
67209 }
67210 break;
67211 }
67212
67213 /* Opcode: Copy P1 P2 P3 * *
 
67214 **
67215 ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
67216 **
67217 ** This instruction makes a deep copy of the value. A duplicate
67218 ** is made of any string or blob constant. See also OP_SCopy.
67219 */
67220 case OP_Copy: {
67221 #if 0 /* local variables moved into u.ae */
67222 int n;
67223 #endif /* local variables moved into u.ae */
67224
67225 u.ae.n = pOp->p3;
67226 pIn1 = &aMem[pOp->p1];
67227 pOut = &aMem[pOp->p2];
67228 assert( pOut!=pIn1 );
67229 while( 1 ){
67230 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67231 Deephemeralize(pOut);
67232 #ifdef SQLITE_DEBUG
67233 pOut->pScopyFrom = 0;
67234 #endif
67235 REGISTER_TRACE(pOp->p2+pOp->p3-u.ae.n, pOut);
67236 if( (u.ae.n--)==0 ) break;
67237 pOut++;
67238 pIn1++;
67239 }
67240 break;
67241 }
67242
67243 /* Opcode: SCopy P1 P2 * * *
 
67244 **
67245 ** Make a shallow copy of register P1 into register P2.
67246 **
67247 ** This instruction makes a shallow copy of the value. If the value
67248 ** is a string or blob, then the copy is only a pointer to the
@@ -67250,35 +67596,35 @@
67250 ** Worse, if the original is deallocated, the copy becomes invalid.
67251 ** Thus the program must guarantee that the original will not change
67252 ** during the lifetime of the copy. Use OP_Copy to make a complete
67253 ** copy.
67254 */
67255 case OP_SCopy: { /* in1, out2 */
67256 pIn1 = &aMem[pOp->p1];
67257 pOut = &aMem[pOp->p2];
67258 assert( pOut!=pIn1 );
67259 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67260 #ifdef SQLITE_DEBUG
67261 if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1;
67262 #endif
67263 REGISTER_TRACE(pOp->p2, pOut);
67264 break;
67265 }
67266
67267 /* Opcode: ResultRow P1 P2 * * *
 
67268 **
67269 ** The registers P1 through P1+P2-1 contain a single row of
67270 ** results. This opcode causes the sqlite3_step() call to terminate
67271 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67272 ** structure to provide access to the top P1 values as the result
67273 ** row.
67274 */
67275 case OP_ResultRow: {
67276 #if 0 /* local variables moved into u.af */
67277 Mem *pMem;
67278 int i;
67279 #endif /* local variables moved into u.af */
67280 assert( p->nResColumn==pOp->p2 );
67281 assert( pOp->p1>0 );
67282 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67283
67284 /* If this statement has violated immediate foreign key constraints, do
@@ -67316,19 +67662,19 @@
67316
67317 /* Make sure the results of the current row are \000 terminated
67318 ** and have an assigned type. The results are de-ephemeralized as
67319 ** a side effect.
67320 */
67321 u.af.pMem = p->pResultSet = &aMem[pOp->p1];
67322 for(u.af.i=0; u.af.i<pOp->p2; u.af.i++){
67323 assert( memIsValid(&u.af.pMem[u.af.i]) );
67324 Deephemeralize(&u.af.pMem[u.af.i]);
67325 assert( (u.af.pMem[u.af.i].flags & MEM_Ephem)==0
67326 || (u.af.pMem[u.af.i].flags & (MEM_Str|MEM_Blob))==0 );
67327 sqlite3VdbeMemNulTerminate(&u.af.pMem[u.af.i]);
67328 sqlite3VdbeMemStoreType(&u.af.pMem[u.af.i]);
67329 REGISTER_TRACE(pOp->p1+u.af.i, &u.af.pMem[u.af.i]);
67330 }
67331 if( db->mallocFailed ) goto no_mem;
67332
67333 /* Return SQLITE_ROW
67334 */
@@ -67336,10 +67682,11 @@
67336 rc = SQLITE_ROW;
67337 goto vdbe_return;
67338 }
67339
67340 /* Opcode: Concat P1 P2 P3 * *
 
67341 **
67342 ** Add the text in register P1 onto the end of the text in
67343 ** register P2 and store the result in register P3.
67344 ** If either the P1 or P2 text are NULL then store NULL in P3.
67345 **
@@ -67348,13 +67695,13 @@
67348 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67349 ** if P3 is the same register as P2, the implementation is able
67350 ** to avoid a memcpy().
67351 */
67352 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67353 #if 0 /* local variables moved into u.ag */
67354 i64 nByte;
67355 #endif /* local variables moved into u.ag */
67356
67357 pIn1 = &aMem[pOp->p1];
67358 pIn2 = &aMem[pOp->p2];
67359 pOut = &aMem[pOp->p3];
67360 assert( pIn1!=pOut );
@@ -67363,58 +67710,63 @@
67363 break;
67364 }
67365 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67366 Stringify(pIn1, encoding);
67367 Stringify(pIn2, encoding);
67368 u.ag.nByte = pIn1->n + pIn2->n;
67369 if( u.ag.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67370 goto too_big;
67371 }
67372 MemSetTypeFlag(pOut, MEM_Str);
67373 if( sqlite3VdbeMemGrow(pOut, (int)u.ag.nByte+2, pOut==pIn2) ){
67374 goto no_mem;
67375 }
67376 if( pOut!=pIn2 ){
67377 memcpy(pOut->z, pIn2->z, pIn2->n);
67378 }
67379 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67380 pOut->z[u.ag.nByte] = 0;
67381 pOut->z[u.ag.nByte+1] = 0;
67382 pOut->flags |= MEM_Term;
67383 pOut->n = (int)u.ag.nByte;
67384 pOut->enc = encoding;
67385 UPDATE_MAX_BLOBSIZE(pOut);
67386 break;
67387 }
67388
67389 /* Opcode: Add P1 P2 P3 * *
 
67390 **
67391 ** Add the value in register P1 to the value in register P2
67392 ** and store the result in register P3.
67393 ** If either input is NULL, the result is NULL.
67394 */
67395 /* Opcode: Multiply P1 P2 P3 * *
 
67396 **
67397 **
67398 ** Multiply the value in register P1 by the value in register P2
67399 ** and store the result in register P3.
67400 ** If either input is NULL, the result is NULL.
67401 */
67402 /* Opcode: Subtract P1 P2 P3 * *
 
67403 **
67404 ** Subtract the value in register P1 from the value in register P2
67405 ** and store the result in register P3.
67406 ** If either input is NULL, the result is NULL.
67407 */
67408 /* Opcode: Divide P1 P2 P3 * *
 
67409 **
67410 ** Divide the value in register P1 by the value in register P2
67411 ** and store the result in register P3 (P3=P2/P1). If the value in
67412 ** register P1 is zero, then the result is NULL. If either input is
67413 ** NULL, the result is NULL.
67414 */
67415 /* Opcode: Remainder P1 P2 P3 * *
 
67416 **
67417 ** Compute the remainder after integer division of the value in
67418 ** register P1 by the value in register P2 and store the result in P3.
67419 ** If the value in register P2 is zero the result is NULL.
67420 ** If either operand is NULL, the result is NULL.
@@ -67422,83 +67774,83 @@
67422 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67423 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67424 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67425 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67426 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67427 #if 0 /* local variables moved into u.ah */
67428 char bIntint; /* Started out as two integer operands */
67429 int flags; /* Combined MEM_* flags from both inputs */
67430 i64 iA; /* Integer value of left operand */
67431 i64 iB; /* Integer value of right operand */
67432 double rA; /* Real value of left operand */
67433 double rB; /* Real value of right operand */
67434 #endif /* local variables moved into u.ah */
67435
67436 pIn1 = &aMem[pOp->p1];
67437 applyNumericAffinity(pIn1);
67438 pIn2 = &aMem[pOp->p2];
67439 applyNumericAffinity(pIn2);
67440 pOut = &aMem[pOp->p3];
67441 u.ah.flags = pIn1->flags | pIn2->flags;
67442 if( (u.ah.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67443 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67444 u.ah.iA = pIn1->u.i;
67445 u.ah.iB = pIn2->u.i;
67446 u.ah.bIntint = 1;
67447 switch( pOp->opcode ){
67448 case OP_Add: if( sqlite3AddInt64(&u.ah.iB,u.ah.iA) ) goto fp_math; break;
67449 case OP_Subtract: if( sqlite3SubInt64(&u.ah.iB,u.ah.iA) ) goto fp_math; break;
67450 case OP_Multiply: if( sqlite3MulInt64(&u.ah.iB,u.ah.iA) ) goto fp_math; break;
67451 case OP_Divide: {
67452 if( u.ah.iA==0 ) goto arithmetic_result_is_null;
67453 if( u.ah.iA==-1 && u.ah.iB==SMALLEST_INT64 ) goto fp_math;
67454 u.ah.iB /= u.ah.iA;
67455 break;
67456 }
67457 default: {
67458 if( u.ah.iA==0 ) goto arithmetic_result_is_null;
67459 if( u.ah.iA==-1 ) u.ah.iA = 1;
67460 u.ah.iB %= u.ah.iA;
67461 break;
67462 }
67463 }
67464 pOut->u.i = u.ah.iB;
67465 MemSetTypeFlag(pOut, MEM_Int);
67466 }else{
67467 u.ah.bIntint = 0;
67468 fp_math:
67469 u.ah.rA = sqlite3VdbeRealValue(pIn1);
67470 u.ah.rB = sqlite3VdbeRealValue(pIn2);
67471 switch( pOp->opcode ){
67472 case OP_Add: u.ah.rB += u.ah.rA; break;
67473 case OP_Subtract: u.ah.rB -= u.ah.rA; break;
67474 case OP_Multiply: u.ah.rB *= u.ah.rA; break;
67475 case OP_Divide: {
67476 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67477 if( u.ah.rA==(double)0 ) goto arithmetic_result_is_null;
67478 u.ah.rB /= u.ah.rA;
67479 break;
67480 }
67481 default: {
67482 u.ah.iA = (i64)u.ah.rA;
67483 u.ah.iB = (i64)u.ah.rB;
67484 if( u.ah.iA==0 ) goto arithmetic_result_is_null;
67485 if( u.ah.iA==-1 ) u.ah.iA = 1;
67486 u.ah.rB = (double)(u.ah.iB % u.ah.iA);
67487 break;
67488 }
67489 }
67490 #ifdef SQLITE_OMIT_FLOATING_POINT
67491 pOut->u.i = u.ah.rB;
67492 MemSetTypeFlag(pOut, MEM_Int);
67493 #else
67494 if( sqlite3IsNaN(u.ah.rB) ){
67495 goto arithmetic_result_is_null;
67496 }
67497 pOut->r = u.ah.rB;
67498 MemSetTypeFlag(pOut, MEM_Real);
67499 if( (u.ah.flags & MEM_Real)==0 && !u.ah.bIntint ){
67500 sqlite3VdbeIntegerAffinity(pOut);
67501 }
67502 #endif
67503 }
67504 break;
@@ -67530,10 +67882,11 @@
67530 }
67531 break;
67532 }
67533
67534 /* Opcode: Function P1 P2 P3 P4 P5
 
67535 **
67536 ** Invoke a user function (P4 is a pointer to a Function structure that
67537 ** defines the function) with P5 arguments taken from register P2 and
67538 ** successors. The result of the function is stored in register P3.
67539 ** Register P3 must not be one of the function inputs.
@@ -67546,85 +67899,85 @@
67546 ** invocation of this opcode.
67547 **
67548 ** See also: AggStep and AggFinal
67549 */
67550 case OP_Function: {
67551 #if 0 /* local variables moved into u.ai */
67552 int i;
67553 Mem *pArg;
67554 sqlite3_context ctx;
67555 sqlite3_value **apVal;
67556 int n;
67557 #endif /* local variables moved into u.ai */
67558
67559 u.ai.n = pOp->p5;
67560 u.ai.apVal = p->apArg;
67561 assert( u.ai.apVal || u.ai.n==0 );
67562 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
67563 pOut = &aMem[pOp->p3];
67564 memAboutToChange(p, pOut);
67565
67566 assert( u.ai.n==0 || (pOp->p2>0 && pOp->p2+u.ai.n<=(p->nMem-p->nCursor)+1) );
67567 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ai.n );
67568 u.ai.pArg = &aMem[pOp->p2];
67569 for(u.ai.i=0; u.ai.i<u.ai.n; u.ai.i++, u.ai.pArg++){
67570 assert( memIsValid(u.ai.pArg) );
67571 u.ai.apVal[u.ai.i] = u.ai.pArg;
67572 Deephemeralize(u.ai.pArg);
67573 sqlite3VdbeMemStoreType(u.ai.pArg);
67574 REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
67575 }
67576
67577 assert( pOp->p4type==P4_FUNCDEF );
67578 u.ai.ctx.pFunc = pOp->p4.pFunc;
67579 u.ai.ctx.s.flags = MEM_Null;
67580 u.ai.ctx.s.db = db;
67581 u.ai.ctx.s.xDel = 0;
67582 u.ai.ctx.s.zMalloc = 0;
67583 u.ai.ctx.iOp = pc;
67584 u.ai.ctx.pVdbe = p;
67585
67586 /* The output cell may already have a buffer allocated. Move
67587 ** the pointer to u.ai.ctx.s so in case the user-function can use
67588 ** the already allocated buffer instead of allocating a new one.
67589 */
67590 sqlite3VdbeMemMove(&u.ai.ctx.s, pOut);
67591 MemSetTypeFlag(&u.ai.ctx.s, MEM_Null);
67592
67593 u.ai.ctx.fErrorOrAux = 0;
67594 if( u.ai.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67595 assert( pOp>aOp );
67596 assert( pOp[-1].p4type==P4_COLLSEQ );
67597 assert( pOp[-1].opcode==OP_CollSeq );
67598 u.ai.ctx.pColl = pOp[-1].p4.pColl;
67599 }
67600 db->lastRowid = lastRowid;
67601 (*u.ai.ctx.pFunc->xFunc)(&u.ai.ctx, u.ai.n, u.ai.apVal); /* IMP: R-24505-23230 */
67602 lastRowid = db->lastRowid;
67603
67604 if( db->mallocFailed ){
67605 /* Even though a malloc() has failed, the implementation of the
67606 ** user function may have called an sqlite3_result_XXX() function
67607 ** to return a value. The following call releases any resources
67608 ** associated with such a value.
67609 */
67610 sqlite3VdbeMemRelease(&u.ai.ctx.s);
67611 goto no_mem;
67612 }
67613
67614 /* If the function returned an error, throw an exception */
67615 if( u.ai.ctx.fErrorOrAux ){
67616 if( u.ai.ctx.isError ){
67617 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ai.ctx.s));
67618 rc = u.ai.ctx.isError;
67619 }
67620 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
67621 }
67622
67623 /* Copy the result of the function into register P3 */
67624 sqlite3VdbeChangeEncoding(&u.ai.ctx.s, encoding);
67625 sqlite3VdbeMemMove(pOut, &u.ai.ctx.s);
67626 if( sqlite3VdbeMemTooBig(pOut) ){
67627 goto too_big;
67628 }
67629
67630 #if 0
@@ -67639,29 +67992,33 @@
67639 UPDATE_MAX_BLOBSIZE(pOut);
67640 break;
67641 }
67642
67643 /* Opcode: BitAnd P1 P2 P3 * *
 
67644 **
67645 ** Take the bit-wise AND of the values in register P1 and P2 and
67646 ** store the result in register P3.
67647 ** If either input is NULL, the result is NULL.
67648 */
67649 /* Opcode: BitOr P1 P2 P3 * *
 
67650 **
67651 ** Take the bit-wise OR of the values in register P1 and P2 and
67652 ** store the result in register P3.
67653 ** If either input is NULL, the result is NULL.
67654 */
67655 /* Opcode: ShiftLeft P1 P2 P3 * *
 
67656 **
67657 ** Shift the integer value in register P2 to the left by the
67658 ** number of bits specified by the integer in register P1.
67659 ** Store the result in register P3.
67660 ** If either input is NULL, the result is NULL.
67661 */
67662 /* Opcode: ShiftRight P1 P2 P3 * *
 
67663 **
67664 ** Shift the integer value in register P2 to the right by the
67665 ** number of bits specified by the integer in register P1.
67666 ** Store the result in register P3.
67667 ** If either input is NULL, the result is NULL.
@@ -67668,61 +68025,62 @@
67668 */
67669 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
67670 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
67671 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
67672 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
67673 #if 0 /* local variables moved into u.aj */
67674 i64 iA;
67675 u64 uA;
67676 i64 iB;
67677 u8 op;
67678 #endif /* local variables moved into u.aj */
67679
67680 pIn1 = &aMem[pOp->p1];
67681 pIn2 = &aMem[pOp->p2];
67682 pOut = &aMem[pOp->p3];
67683 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
67684 sqlite3VdbeMemSetNull(pOut);
67685 break;
67686 }
67687 u.aj.iA = sqlite3VdbeIntValue(pIn2);
67688 u.aj.iB = sqlite3VdbeIntValue(pIn1);
67689 u.aj.op = pOp->opcode;
67690 if( u.aj.op==OP_BitAnd ){
67691 u.aj.iA &= u.aj.iB;
67692 }else if( u.aj.op==OP_BitOr ){
67693 u.aj.iA |= u.aj.iB;
67694 }else if( u.aj.iB!=0 ){
67695 assert( u.aj.op==OP_ShiftRight || u.aj.op==OP_ShiftLeft );
67696
67697 /* If shifting by a negative amount, shift in the other direction */
67698 if( u.aj.iB<0 ){
67699 assert( OP_ShiftRight==OP_ShiftLeft+1 );
67700 u.aj.op = 2*OP_ShiftLeft + 1 - u.aj.op;
67701 u.aj.iB = u.aj.iB>(-64) ? -u.aj.iB : 64;
67702 }
67703
67704 if( u.aj.iB>=64 ){
67705 u.aj.iA = (u.aj.iA>=0 || u.aj.op==OP_ShiftLeft) ? 0 : -1;
67706 }else{
67707 memcpy(&u.aj.uA, &u.aj.iA, sizeof(u.aj.uA));
67708 if( u.aj.op==OP_ShiftLeft ){
67709 u.aj.uA <<= u.aj.iB;
67710 }else{
67711 u.aj.uA >>= u.aj.iB;
67712 /* Sign-extend on a right shift of a negative number */
67713 if( u.aj.iA<0 ) u.aj.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.aj.iB);
67714 }
67715 memcpy(&u.aj.iA, &u.aj.uA, sizeof(u.aj.iA));
67716 }
67717 }
67718 pOut->u.i = u.aj.iA;
67719 MemSetTypeFlag(pOut, MEM_Int);
67720 break;
67721 }
67722
67723 /* Opcode: AddImm P1 P2 * * *
 
67724 **
67725 ** Add the constant P2 to the value in register P1.
67726 ** The result is always an integer.
67727 **
67728 ** To force any register to be an integer, just add 0.
@@ -67877,10 +68235,11 @@
67877 break;
67878 }
67879 #endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
67880
67881 /* Opcode: Lt P1 P2 P3 P4 P5
 
67882 **
67883 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
67884 ** jump to address P2.
67885 **
67886 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -67911,10 +68270,11 @@
67911 ** If the SQLITE_NULLEQ bit is set in P5, then NULL values are considered
67912 ** equal to one another, provided that they do not have their MEM_Cleared
67913 ** bit set.
67914 */
67915 /* Opcode: Ne P1 P2 P3 P4 P5
 
67916 **
67917 ** This works just like the Lt opcode except that the jump is taken if
67918 ** the operands in registers P1 and P3 are not equal. See the Lt opcode for
67919 ** additional information.
67920 **
@@ -67923,10 +68283,11 @@
67923 ** of comparison is false. If either operand is NULL then the result is true.
67924 ** If neither operand is NULL the result is the same as it would be if
67925 ** the SQLITE_NULLEQ flag were omitted from P5.
67926 */
67927 /* Opcode: Eq P1 P2 P3 P4 P5
 
67928 **
67929 ** This works just like the Lt opcode except that the jump is taken if
67930 ** the operands in registers P1 and P3 are equal.
67931 ** See the Lt opcode for additional information.
67932 **
@@ -67935,22 +68296,25 @@
67935 ** of comparison is true. If either operand is NULL then the result is false.
67936 ** If neither operand is NULL the result is the same as it would be if
67937 ** the SQLITE_NULLEQ flag were omitted from P5.
67938 */
67939 /* Opcode: Le P1 P2 P3 P4 P5
 
67940 **
67941 ** This works just like the Lt opcode except that the jump is taken if
67942 ** the content of register P3 is less than or equal to the content of
67943 ** register P1. See the Lt opcode for additional information.
67944 */
67945 /* Opcode: Gt P1 P2 P3 P4 P5
 
67946 **
67947 ** This works just like the Lt opcode except that the jump is taken if
67948 ** the content of register P3 is greater than the content of
67949 ** register P1. See the Lt opcode for additional information.
67950 */
67951 /* Opcode: Ge P1 P2 P3 P4 P5
 
67952 **
67953 ** This works just like the Lt opcode except that the jump is taken if
67954 ** the content of register P3 is greater than or equal to the content of
67955 ** register P1. See the Lt opcode for additional information.
67956 */
@@ -67958,37 +68322,37 @@
67958 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
67959 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
67960 case OP_Le: /* same as TK_LE, jump, in1, in3 */
67961 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
67962 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
67963 #if 0 /* local variables moved into u.ak */
67964 int res; /* Result of the comparison of pIn1 against pIn3 */
67965 char affinity; /* Affinity to use for comparison */
67966 u16 flags1; /* Copy of initial value of pIn1->flags */
67967 u16 flags3; /* Copy of initial value of pIn3->flags */
67968 #endif /* local variables moved into u.ak */
67969
67970 pIn1 = &aMem[pOp->p1];
67971 pIn3 = &aMem[pOp->p3];
67972 u.ak.flags1 = pIn1->flags;
67973 u.ak.flags3 = pIn3->flags;
67974 if( (u.ak.flags1 | u.ak.flags3)&MEM_Null ){
67975 /* One or both operands are NULL */
67976 if( pOp->p5 & SQLITE_NULLEQ ){
67977 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
67978 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
67979 ** or not both operands are null.
67980 */
67981 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
67982 assert( (u.ak.flags1 & MEM_Cleared)==0 );
67983 if( (u.ak.flags1&MEM_Null)!=0
67984 && (u.ak.flags3&MEM_Null)!=0
67985 && (u.ak.flags3&MEM_Cleared)==0
67986 ){
67987 u.ak.res = 0; /* Results are equal */
67988 }else{
67989 u.ak.res = 1; /* Results are not equal */
67990 }
67991 }else{
67992 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
67993 ** then the result is always NULL.
67994 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68002,44 +68366,44 @@
68002 }
68003 break;
68004 }
68005 }else{
68006 /* Neither operand is NULL. Do a comparison. */
68007 u.ak.affinity = pOp->p5 & SQLITE_AFF_MASK;
68008 if( u.ak.affinity ){
68009 applyAffinity(pIn1, u.ak.affinity, encoding);
68010 applyAffinity(pIn3, u.ak.affinity, encoding);
68011 if( db->mallocFailed ) goto no_mem;
68012 }
68013
68014 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68015 ExpandBlob(pIn1);
68016 ExpandBlob(pIn3);
68017 u.ak.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68018 }
68019 switch( pOp->opcode ){
68020 case OP_Eq: u.ak.res = u.ak.res==0; break;
68021 case OP_Ne: u.ak.res = u.ak.res!=0; break;
68022 case OP_Lt: u.ak.res = u.ak.res<0; break;
68023 case OP_Le: u.ak.res = u.ak.res<=0; break;
68024 case OP_Gt: u.ak.res = u.ak.res>0; break;
68025 default: u.ak.res = u.ak.res>=0; break;
68026 }
68027
68028 if( pOp->p5 & SQLITE_STOREP2 ){
68029 pOut = &aMem[pOp->p2];
68030 memAboutToChange(p, pOut);
68031 MemSetTypeFlag(pOut, MEM_Int);
68032 pOut->u.i = u.ak.res;
68033 REGISTER_TRACE(pOp->p2, pOut);
68034 }else if( u.ak.res ){
68035 pc = pOp->p2-1;
68036 }
68037
68038 /* Undo any changes made by applyAffinity() to the input registers. */
68039 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.ak.flags1&MEM_TypeMask);
68040 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.ak.flags3&MEM_TypeMask);
68041 break;
68042 }
68043
68044 /* Opcode: Permutation * * * P4 *
68045 **
@@ -68075,51 +68439,51 @@
68075 ** The comparison is a sort comparison, so NULLs compare equal,
68076 ** NULLs are less than numbers, numbers are less than strings,
68077 ** and strings are less than blobs.
68078 */
68079 case OP_Compare: {
68080 #if 0 /* local variables moved into u.al */
68081 int n;
68082 int i;
68083 int p1;
68084 int p2;
68085 const KeyInfo *pKeyInfo;
68086 int idx;
68087 CollSeq *pColl; /* Collating sequence to use on this term */
68088 int bRev; /* True for DESCENDING sort order */
68089 #endif /* local variables moved into u.al */
68090
68091 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68092 u.al.n = pOp->p3;
68093 u.al.pKeyInfo = pOp->p4.pKeyInfo;
68094 assert( u.al.n>0 );
68095 assert( u.al.pKeyInfo!=0 );
68096 u.al.p1 = pOp->p1;
68097 u.al.p2 = pOp->p2;
68098 #if SQLITE_DEBUG
68099 if( aPermute ){
68100 int k, mx = 0;
68101 for(k=0; k<u.al.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68102 assert( u.al.p1>0 && u.al.p1+mx<=(p->nMem-p->nCursor)+1 );
68103 assert( u.al.p2>0 && u.al.p2+mx<=(p->nMem-p->nCursor)+1 );
68104 }else{
68105 assert( u.al.p1>0 && u.al.p1+u.al.n<=(p->nMem-p->nCursor)+1 );
68106 assert( u.al.p2>0 && u.al.p2+u.al.n<=(p->nMem-p->nCursor)+1 );
68107 }
68108 #endif /* SQLITE_DEBUG */
68109 for(u.al.i=0; u.al.i<u.al.n; u.al.i++){
68110 u.al.idx = aPermute ? aPermute[u.al.i] : u.al.i;
68111 assert( memIsValid(&aMem[u.al.p1+u.al.idx]) );
68112 assert( memIsValid(&aMem[u.al.p2+u.al.idx]) );
68113 REGISTER_TRACE(u.al.p1+u.al.idx, &aMem[u.al.p1+u.al.idx]);
68114 REGISTER_TRACE(u.al.p2+u.al.idx, &aMem[u.al.p2+u.al.idx]);
68115 assert( u.al.i<u.al.pKeyInfo->nField );
68116 u.al.pColl = u.al.pKeyInfo->aColl[u.al.i];
68117 u.al.bRev = u.al.pKeyInfo->aSortOrder[u.al.i];
68118 iCompare = sqlite3MemCompare(&aMem[u.al.p1+u.al.idx], &aMem[u.al.p2+u.al.idx], u.al.pColl);
68119 if( iCompare ){
68120 if( u.al.bRev ) iCompare = -iCompare;
68121 break;
68122 }
68123 }
68124 aPermute = 0;
68125 break;
@@ -68141,19 +68505,21 @@
68141 }
68142 break;
68143 }
68144
68145 /* Opcode: And P1 P2 P3 * *
 
68146 **
68147 ** Take the logical AND of the values in registers P1 and P2 and
68148 ** write the result into register P3.
68149 **
68150 ** If either P1 or P2 is 0 (false) then the result is 0 even if
68151 ** the other input is NULL. A NULL and true or two NULLs give
68152 ** a NULL output.
68153 */
68154 /* Opcode: Or P1 P2 P3 * *
 
68155 **
68156 ** Take the logical OR of the values in register P1 and P2 and
68157 ** store the answer in register P3.
68158 **
68159 ** If either P1 or P2 is nonzero (true) then the result is 1 (true)
@@ -68160,45 +68526,46 @@
68160 ** even if the other input is NULL. A NULL and false or two NULLs
68161 ** give a NULL output.
68162 */
68163 case OP_And: /* same as TK_AND, in1, in2, out3 */
68164 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68165 #if 0 /* local variables moved into u.am */
68166 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68167 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68168 #endif /* local variables moved into u.am */
68169
68170 pIn1 = &aMem[pOp->p1];
68171 if( pIn1->flags & MEM_Null ){
68172 u.am.v1 = 2;
68173 }else{
68174 u.am.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68175 }
68176 pIn2 = &aMem[pOp->p2];
68177 if( pIn2->flags & MEM_Null ){
68178 u.am.v2 = 2;
68179 }else{
68180 u.am.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68181 }
68182 if( pOp->opcode==OP_And ){
68183 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68184 u.am.v1 = and_logic[u.am.v1*3+u.am.v2];
68185 }else{
68186 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68187 u.am.v1 = or_logic[u.am.v1*3+u.am.v2];
68188 }
68189 pOut = &aMem[pOp->p3];
68190 if( u.am.v1==2 ){
68191 MemSetTypeFlag(pOut, MEM_Null);
68192 }else{
68193 pOut->u.i = u.am.v1;
68194 MemSetTypeFlag(pOut, MEM_Int);
68195 }
68196 break;
68197 }
68198
68199 /* Opcode: Not P1 P2 * * *
 
68200 **
68201 ** Interpret the value in register P1 as a boolean value. Store the
68202 ** boolean complement in register P2. If the value in register P1 is
68203 ** NULL, then a NULL is stored in P2.
68204 */
@@ -68212,10 +68579,11 @@
68212 }
68213 break;
68214 }
68215
68216 /* Opcode: BitNot P1 P2 * * *
 
68217 **
68218 ** Interpret the content of register P1 as an integer. Store the
68219 ** ones-complement of the P1 value into register P2. If P1 holds
68220 ** a NULL then store a NULL in P2.
68221 */
@@ -68257,31 +68625,32 @@
68257 ** is considered false if it has a numeric value of zero. If the value
68258 ** in P1 is NULL then take the jump if P3 is zero.
68259 */
68260 case OP_If: /* jump, in1 */
68261 case OP_IfNot: { /* jump, in1 */
68262 #if 0 /* local variables moved into u.an */
68263 int c;
68264 #endif /* local variables moved into u.an */
68265 pIn1 = &aMem[pOp->p1];
68266 if( pIn1->flags & MEM_Null ){
68267 u.an.c = pOp->p3;
68268 }else{
68269 #ifdef SQLITE_OMIT_FLOATING_POINT
68270 u.an.c = sqlite3VdbeIntValue(pIn1)!=0;
68271 #else
68272 u.an.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68273 #endif
68274 if( pOp->opcode==OP_IfNot ) u.an.c = !u.an.c;
68275 }
68276 if( u.an.c ){
68277 pc = pOp->p2-1;
68278 }
68279 break;
68280 }
68281
68282 /* Opcode: IsNull P1 P2 * * *
 
68283 **
68284 ** Jump to P2 if the value in register P1 is NULL.
68285 */
68286 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
68287 pIn1 = &aMem[pOp->p1];
@@ -68290,10 +68659,11 @@
68290 }
68291 break;
68292 }
68293
68294 /* Opcode: NotNull P1 P2 * * *
 
68295 **
68296 ** Jump to P2 if the value in register P1 is not NULL.
68297 */
68298 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
68299 pIn1 = &aMem[pOp->p1];
@@ -68302,10 +68672,11 @@
68302 }
68303 break;
68304 }
68305
68306 /* Opcode: Column P1 P2 P3 P4 P5
 
68307 **
68308 ** Interpret the data that cursor P1 points to as a structure built using
68309 ** the MakeRecord instruction. (See the MakeRecord opcode for additional
68310 ** information about the format of the data.) Extract the P2-th column
68311 ** from this record. If there are less that (P2+1)
@@ -68326,11 +68697,11 @@
68326 ** the result is guaranteed to only be used as the argument of a length()
68327 ** or typeof() function, respectively. The loading of large blobs can be
68328 ** skipped for length() and all content loading can be skipped for typeof().
68329 */
68330 case OP_Column: {
68331 #if 0 /* local variables moved into u.ao */
68332 u32 payloadSize; /* Number of bytes in the record */
68333 i64 payloadSize64; /* Number of bytes in the record */
68334 int p1; /* P1 value of the opcode */
68335 int p2; /* column number to retrieve */
68336 VdbeCursor *pC; /* The VDBE cursor */
@@ -68350,135 +68721,133 @@
68350 u32 szField; /* Number of bytes in the content of a field */
68351 int szHdr; /* Size of the header size field at start of record */
68352 int avail; /* Number of bytes of available data */
68353 u32 t; /* A type code from the record header */
68354 Mem *pReg; /* PseudoTable input register */
68355 #endif /* local variables moved into u.ao */
68356
68357
68358 u.ao.p1 = pOp->p1;
68359 u.ao.p2 = pOp->p2;
68360 u.ao.pC = 0;
68361 memset(&u.ao.sMem, 0, sizeof(u.ao.sMem));
68362 assert( u.ao.p1<p->nCursor );
68363 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68364 u.ao.pDest = &aMem[pOp->p3];
68365 memAboutToChange(p, u.ao.pDest);
68366 u.ao.zRec = 0;
68367
68368 /* This block sets the variable u.ao.payloadSize to be the total number of
68369 ** bytes in the record.
68370 **
68371 ** u.ao.zRec is set to be the complete text of the record if it is available.
68372 ** The complete record text is always available for pseudo-tables
68373 ** If the record is stored in a cursor, the complete record text
68374 ** might be available in the u.ao.pC->aRow cache. Or it might not be.
68375 ** If the data is unavailable, u.ao.zRec is set to NULL.
68376 **
68377 ** We also compute the number of columns in the record. For cursors,
68378 ** the number of columns is stored in the VdbeCursor.nField element.
68379 */
68380 u.ao.pC = p->apCsr[u.ao.p1];
68381 assert( u.ao.pC!=0 );
68382 #ifndef SQLITE_OMIT_VIRTUALTABLE
68383 assert( u.ao.pC->pVtabCursor==0 );
68384 #endif
68385 u.ao.pCrsr = u.ao.pC->pCursor;
68386 if( u.ao.pCrsr!=0 ){
68387 /* The record is stored in a B-Tree */
68388 rc = sqlite3VdbeCursorMoveto(u.ao.pC);
68389 if( rc ) goto abort_due_to_error;
68390 if( u.ao.pC->nullRow ){
68391 u.ao.payloadSize = 0;
68392 }else if( u.ao.pC->cacheStatus==p->cacheCtr ){
68393 u.ao.payloadSize = u.ao.pC->payloadSize;
68394 u.ao.zRec = (char*)u.ao.pC->aRow;
68395 }else if( u.ao.pC->isIndex ){
68396 assert( sqlite3BtreeCursorIsValid(u.ao.pCrsr) );
68397 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ao.pCrsr, &u.ao.payloadSize64);
68398 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68399 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68400 ** payload size, so it is impossible for u.ao.payloadSize64 to be
68401 ** larger than 32 bits. */
68402 assert( (u.ao.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ao.payloadSize64 );
68403 u.ao.payloadSize = (u32)u.ao.payloadSize64;
68404 }else{
68405 assert( sqlite3BtreeCursorIsValid(u.ao.pCrsr) );
68406 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ao.pCrsr, &u.ao.payloadSize);
68407 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68408 }
68409 }else if( ALWAYS(u.ao.pC->pseudoTableReg>0) ){
68410 u.ao.pReg = &aMem[u.ao.pC->pseudoTableReg];
68411 if( u.ao.pC->multiPseudo ){
68412 sqlite3VdbeMemShallowCopy(u.ao.pDest, u.ao.pReg+u.ao.p2, MEM_Ephem);
68413 Deephemeralize(u.ao.pDest);
 
68414 goto op_column_out;
68415 }
68416 assert( u.ao.pReg->flags & MEM_Blob );
68417 assert( memIsValid(u.ao.pReg) );
68418 u.ao.payloadSize = u.ao.pReg->n;
68419 u.ao.zRec = u.ao.pReg->z;
68420 u.ao.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
68421 assert( u.ao.payloadSize==0 || u.ao.zRec!=0 );
68422 }else{
68423 /* Consider the row to be NULL */
68424 u.ao.payloadSize = 0;
68425 }
68426
68427 /* If u.ao.payloadSize is 0, then just store a NULL. This can happen because of
68428 ** nullRow or because of a corrupt database. */
68429 if( u.ao.payloadSize==0 ){
68430 MemSetTypeFlag(u.ao.pDest, MEM_Null);
68431 goto op_column_out;
68432 }
68433 assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
68434 if( u.ao.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68435 goto too_big;
68436 }
68437
68438 u.ao.nField = u.ao.pC->nField;
68439 assert( u.ao.p2<u.ao.nField );
68440
68441 /* Read and parse the table header. Store the results of the parse
68442 ** into the record header cache fields of the cursor.
68443 */
68444 u.ao.aType = u.ao.pC->aType;
68445 if( u.ao.pC->cacheStatus==p->cacheCtr ){
68446 u.ao.aOffset = u.ao.pC->aOffset;
68447 }else{
68448 assert(u.ao.aType);
68449 u.ao.avail = 0;
68450 u.ao.pC->aOffset = u.ao.aOffset = &u.ao.aType[u.ao.nField];
68451 u.ao.pC->payloadSize = u.ao.payloadSize;
68452 u.ao.pC->cacheStatus = p->cacheCtr;
68453
68454 /* Figure out how many bytes are in the header */
68455 if( u.ao.zRec ){
68456 u.ao.zData = u.ao.zRec;
68457 }else{
68458 if( u.ao.pC->isIndex ){
68459 u.ao.zData = (char*)sqlite3BtreeKeyFetch(u.ao.pCrsr, &u.ao.avail);
68460 }else{
68461 u.ao.zData = (char*)sqlite3BtreeDataFetch(u.ao.pCrsr, &u.ao.avail);
68462 }
68463 /* If KeyFetch()/DataFetch() managed to get the entire payload,
68464 ** save the payload in the u.ao.pC->aRow cache. That will save us from
68465 ** having to make additional calls to fetch the content portion of
68466 ** the record.
68467 */
68468 assert( u.ao.avail>=0 );
68469 if( u.ao.payloadSize <= (u32)u.ao.avail ){
68470 u.ao.zRec = u.ao.zData;
68471 u.ao.pC->aRow = (u8*)u.ao.zData;
68472 }else{
68473 u.ao.pC->aRow = 0;
68474 }
68475 }
68476 /* The following assert is true in all cases except when
68477 ** the database file has been corrupted externally.
68478 ** assert( u.ao.zRec!=0 || u.ao.avail>=u.ao.payloadSize || u.ao.avail>=9 ); */
68479 u.ao.szHdr = getVarint32((u8*)u.ao.zData, u.ao.offset);
68480
68481 /* Make sure a corrupt database has not given us an oversize header.
68482 ** Do this now to avoid an oversize memory allocation.
68483 **
68484 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68485,193 +68854,195 @@
68485 ** types use so much data space that there can only be 4096 and 32 of
68486 ** them, respectively. So the maximum header length results from a
68487 ** 3-byte type for each of the maximum of 32768 columns plus three
68488 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68489 */
68490 if( u.ao.offset > 98307 ){
68491 rc = SQLITE_CORRUPT_BKPT;
68492 goto op_column_out;
68493 }
68494
68495 /* Compute in u.ao.len the number of bytes of data we need to read in order
68496 ** to get u.ao.nField type values. u.ao.offset is an upper bound on this. But
68497 ** u.ao.nField might be significantly less than the true number of columns
68498 ** in the table, and in that case, 5*u.ao.nField+3 might be smaller than u.ao.offset.
68499 ** We want to minimize u.ao.len in order to limit the size of the memory
68500 ** allocation, especially if a corrupt database file has caused u.ao.offset
68501 ** to be oversized. Offset is limited to 98307 above. But 98307 might
68502 ** still exceed Robson memory allocation limits on some configurations.
68503 ** On systems that cannot tolerate large memory allocations, u.ao.nField*5+3
68504 ** will likely be much smaller since u.ao.nField will likely be less than
68505 ** 20 or so. This insures that Robson memory allocation limits are
68506 ** not exceeded even for corrupt database files.
68507 */
68508 u.ao.len = u.ao.nField*5 + 3;
68509 if( u.ao.len > (int)u.ao.offset ) u.ao.len = (int)u.ao.offset;
68510
68511 /* The KeyFetch() or DataFetch() above are fast and will get the entire
68512 ** record header in most cases. But they will fail to get the complete
68513 ** record header if the record header does not fit on a single page
68514 ** in the B-Tree. When that happens, use sqlite3VdbeMemFromBtree() to
68515 ** acquire the complete header text.
68516 */
68517 if( !u.ao.zRec && u.ao.avail<u.ao.len ){
68518 u.ao.sMem.flags = 0;
68519 u.ao.sMem.db = 0;
68520 rc = sqlite3VdbeMemFromBtree(u.ao.pCrsr, 0, u.ao.len, u.ao.pC->isIndex, &u.ao.sMem);
68521 if( rc!=SQLITE_OK ){
68522 goto op_column_out;
68523 }
68524 u.ao.zData = u.ao.sMem.z;
68525 }
68526 u.ao.zEndHdr = (u8 *)&u.ao.zData[u.ao.len];
68527 u.ao.zIdx = (u8 *)&u.ao.zData[u.ao.szHdr];
68528
68529 /* Scan the header and use it to fill in the u.ao.aType[] and u.ao.aOffset[]
68530 ** arrays. u.ao.aType[u.ao.i] will contain the type integer for the u.ao.i-th
68531 ** column and u.ao.aOffset[u.ao.i] will contain the u.ao.offset from the beginning
68532 ** of the record to the start of the data for the u.ao.i-th column
68533 */
68534 for(u.ao.i=0; u.ao.i<u.ao.nField; u.ao.i++){
68535 if( u.ao.zIdx<u.ao.zEndHdr ){
68536 u.ao.aOffset[u.ao.i] = u.ao.offset;
68537 if( u.ao.zIdx[0]<0x80 ){
68538 u.ao.t = u.ao.zIdx[0];
68539 u.ao.zIdx++;
68540 }else{
68541 u.ao.zIdx += sqlite3GetVarint32(u.ao.zIdx, &u.ao.t);
68542 }
68543 u.ao.aType[u.ao.i] = u.ao.t;
68544 u.ao.szField = sqlite3VdbeSerialTypeLen(u.ao.t);
68545 u.ao.offset += u.ao.szField;
68546 if( u.ao.offset<u.ao.szField ){ /* True if u.ao.offset overflows */
68547 u.ao.zIdx = &u.ao.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68548 break;
68549 }
68550 }else{
68551 /* If u.ao.i is less that u.ao.nField, then there are fewer fields in this
68552 ** record than SetNumColumns indicated there are columns in the
68553 ** table. Set the u.ao.offset for any extra columns not present in
68554 ** the record to 0. This tells code below to store the default value
68555 ** for the column instead of deserializing a value from the record.
68556 */
68557 u.ao.aOffset[u.ao.i] = 0;
68558 }
68559 }
68560 sqlite3VdbeMemRelease(&u.ao.sMem);
68561 u.ao.sMem.flags = MEM_Null;
68562
68563 /* If we have read more header data than was contained in the header,
68564 ** or if the end of the last field appears to be past the end of the
68565 ** record, or if the end of the last field appears to be before the end
68566 ** of the record (when all fields present), then we must be dealing
68567 ** with a corrupt database.
68568 */
68569 if( (u.ao.zIdx > u.ao.zEndHdr) || (u.ao.offset > u.ao.payloadSize)
68570 || (u.ao.zIdx==u.ao.zEndHdr && u.ao.offset!=u.ao.payloadSize) ){
68571 rc = SQLITE_CORRUPT_BKPT;
68572 goto op_column_out;
68573 }
68574 }
68575
68576 /* Get the column information. If u.ao.aOffset[u.ao.p2] is non-zero, then
68577 ** deserialize the value from the record. If u.ao.aOffset[u.ao.p2] is zero,
68578 ** then there are not enough fields in the record to satisfy the
68579 ** request. In this case, set the value NULL or to P4 if P4 is
68580 ** a pointer to a Mem object.
68581 */
68582 if( u.ao.aOffset[u.ao.p2] ){
68583 assert( rc==SQLITE_OK );
68584 if( u.ao.zRec ){
68585 /* This is the common case where the whole row fits on a single page */
68586 VdbeMemRelease(u.ao.pDest);
68587 sqlite3VdbeSerialGet((u8 *)&u.ao.zRec[u.ao.aOffset[u.ao.p2]], u.ao.aType[u.ao.p2], u.ao.pDest);
68588 }else{
68589 /* This branch happens only when the row overflows onto multiple pages */
68590 u.ao.t = u.ao.aType[u.ao.p2];
68591 if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68592 && ((u.ao.t>=12 && (u.ao.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)
68593 ){
68594 /* Content is irrelevant for the typeof() function and for
68595 ** the length(X) function if X is a blob. So we might as well use
68596 ** bogus content rather than reading content from disk. NULL works
68597 ** for text and blob and whatever is in the u.ao.payloadSize64 variable
68598 ** will work for everything else. */
68599 u.ao.zData = u.ao.t<12 ? (char*)&u.ao.payloadSize64 : 0;
68600 }else{
68601 u.ao.len = sqlite3VdbeSerialTypeLen(u.ao.t);
68602 sqlite3VdbeMemMove(&u.ao.sMem, u.ao.pDest);
68603 rc = sqlite3VdbeMemFromBtree(u.ao.pCrsr, u.ao.aOffset[u.ao.p2], u.ao.len, u.ao.pC->isIndex,
68604 &u.ao.sMem);
68605 if( rc!=SQLITE_OK ){
68606 goto op_column_out;
68607 }
68608 u.ao.zData = u.ao.sMem.z;
68609 }
68610 sqlite3VdbeSerialGet((u8*)u.ao.zData, u.ao.t, u.ao.pDest);
68611 }
68612 u.ao.pDest->enc = encoding;
68613 }else{
68614 if( pOp->p4type==P4_MEM ){
68615 sqlite3VdbeMemShallowCopy(u.ao.pDest, pOp->p4.pMem, MEM_Static);
68616 }else{
68617 MemSetTypeFlag(u.ao.pDest, MEM_Null);
68618 }
68619 }
68620
68621 /* If we dynamically allocated space to hold the data (in the
68622 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68623 ** dynamically allocated space over to the u.ao.pDest structure.
68624 ** This prevents a memory copy.
68625 */
68626 if( u.ao.sMem.zMalloc ){
68627 assert( u.ao.sMem.z==u.ao.sMem.zMalloc );
68628 assert( !(u.ao.pDest->flags & MEM_Dyn) );
68629 assert( !(u.ao.pDest->flags & (MEM_Blob|MEM_Str)) || u.ao.pDest->z==u.ao.sMem.z );
68630 u.ao.pDest->flags &= ~(MEM_Ephem|MEM_Static);
68631 u.ao.pDest->flags |= MEM_Term;
68632 u.ao.pDest->z = u.ao.sMem.z;
68633 u.ao.pDest->zMalloc = u.ao.sMem.zMalloc;
68634 }
68635
68636 rc = sqlite3VdbeMemMakeWriteable(u.ao.pDest);
68637
68638 op_column_out:
68639 UPDATE_MAX_BLOBSIZE(u.ao.pDest);
68640 REGISTER_TRACE(pOp->p3, u.ao.pDest);
68641 break;
68642 }
68643
68644 /* Opcode: Affinity P1 P2 * P4 *
 
68645 **
68646 ** Apply affinities to a range of P2 registers starting with P1.
68647 **
68648 ** P4 is a string that is P2 characters long. The nth character of the
68649 ** string indicates the column affinity that should be used for the nth
68650 ** memory cell in the range.
68651 */
68652 case OP_Affinity: {
68653 #if 0 /* local variables moved into u.ap */
68654 const char *zAffinity; /* The affinity to be applied */
68655 char cAff; /* A single character of affinity */
68656 #endif /* local variables moved into u.ap */
68657
68658 u.ap.zAffinity = pOp->p4.z;
68659 assert( u.ap.zAffinity!=0 );
68660 assert( u.ap.zAffinity[pOp->p2]==0 );
68661 pIn1 = &aMem[pOp->p1];
68662 while( (u.ap.cAff = *(u.ap.zAffinity++))!=0 ){
68663 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
68664 assert( memIsValid(pIn1) );
68665 ExpandBlob(pIn1);
68666 applyAffinity(pIn1, u.ap.cAff, encoding);
68667 pIn1++;
68668 }
68669 break;
68670 }
68671
68672 /* Opcode: MakeRecord P1 P2 P3 P4 *
 
68673 **
68674 ** Convert P2 registers beginning with P1 into the [record format]
68675 ** use as a data record in a database table or as a key
68676 ** in an index. The OP_Column opcode can decode the record later.
68677 **
@@ -68683,11 +69054,11 @@
68683 ** macros defined in sqliteInt.h.
68684 **
68685 ** If P4 is NULL then all index fields have the affinity NONE.
68686 */
68687 case OP_MakeRecord: {
68688 #if 0 /* local variables moved into u.aq */
68689 u8 *zNewRecord; /* A buffer to hold the data for the new record */
68690 Mem *pRec; /* The new record */
68691 u64 nData; /* Number of bytes of data space */
68692 int nHdr; /* Number of bytes of header space */
68693 i64 nByte; /* Data space required for this record */
@@ -68699,11 +69070,11 @@
68699 int nField; /* Number of fields in the record */
68700 char *zAffinity; /* The affinity string for the record */
68701 int file_format; /* File format to use for encoding */
68702 int i; /* Space used in zNewRecord[] */
68703 int len; /* Length of a field */
68704 #endif /* local variables moved into u.aq */
68705
68706 /* Assuming the record contains N fields, the record format looks
68707 ** like this:
68708 **
68709 ** ------------------------------------------------------------------------
@@ -68716,114 +69087,112 @@
68716 ** Each type field is a varint representing the serial type of the
68717 ** corresponding data element (see sqlite3VdbeSerialType()). The
68718 ** hdr-size field is also a varint which is the offset from the beginning
68719 ** of the record to data0.
68720 */
68721 u.aq.nData = 0; /* Number of bytes of data space */
68722 u.aq.nHdr = 0; /* Number of bytes of header space */
68723 u.aq.nZero = 0; /* Number of zero bytes at the end of the record */
68724 u.aq.nField = pOp->p1;
68725 u.aq.zAffinity = pOp->p4.z;
68726 assert( u.aq.nField>0 && pOp->p2>0 && pOp->p2+u.aq.nField<=(p->nMem-p->nCursor)+1 );
68727 u.aq.pData0 = &aMem[u.aq.nField];
68728 u.aq.nField = pOp->p2;
68729 u.aq.pLast = &u.aq.pData0[u.aq.nField-1];
68730 u.aq.file_format = p->minWriteFileFormat;
68731
68732 /* Identify the output register */
68733 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
68734 pOut = &aMem[pOp->p3];
68735 memAboutToChange(p, pOut);
68736
68737 /* Loop through the elements that will make up the record to figure
68738 ** out how much space is required for the new record.
68739 */
68740 for(u.aq.pRec=u.aq.pData0; u.aq.pRec<=u.aq.pLast; u.aq.pRec++){
68741 assert( memIsValid(u.aq.pRec) );
68742 if( u.aq.zAffinity ){
68743 applyAffinity(u.aq.pRec, u.aq.zAffinity[u.aq.pRec-u.aq.pData0], encoding);
68744 }
68745 if( u.aq.pRec->flags&MEM_Zero && u.aq.pRec->n>0 ){
68746 sqlite3VdbeMemExpandBlob(u.aq.pRec);
68747 }
68748 u.aq.serial_type = sqlite3VdbeSerialType(u.aq.pRec, u.aq.file_format);
68749 u.aq.len = sqlite3VdbeSerialTypeLen(u.aq.serial_type);
68750 u.aq.nData += u.aq.len;
68751 u.aq.nHdr += sqlite3VarintLen(u.aq.serial_type);
68752 if( u.aq.pRec->flags & MEM_Zero ){
68753 /* Only pure zero-filled BLOBs can be input to this Opcode.
68754 ** We do not allow blobs with a prefix and a zero-filled tail. */
68755 u.aq.nZero += u.aq.pRec->u.nZero;
68756 }else if( u.aq.len ){
68757 u.aq.nZero = 0;
68758 }
68759 }
68760
68761 /* Add the initial header varint and total the size */
68762 u.aq.nHdr += u.aq.nVarint = sqlite3VarintLen(u.aq.nHdr);
68763 if( u.aq.nVarint<sqlite3VarintLen(u.aq.nHdr) ){
68764 u.aq.nHdr++;
68765 }
68766 u.aq.nByte = u.aq.nHdr+u.aq.nData-u.aq.nZero;
68767 if( u.aq.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
68768 goto too_big;
68769 }
68770
68771 /* Make sure the output register has a buffer large enough to store
68772 ** the new record. The output register (pOp->p3) is not allowed to
68773 ** be one of the input registers (because the following call to
68774 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
68775 */
68776 if( sqlite3VdbeMemGrow(pOut, (int)u.aq.nByte, 0) ){
68777 goto no_mem;
68778 }
68779 u.aq.zNewRecord = (u8 *)pOut->z;
68780
68781 /* Write the record */
68782 u.aq.i = putVarint32(u.aq.zNewRecord, u.aq.nHdr);
68783 for(u.aq.pRec=u.aq.pData0; u.aq.pRec<=u.aq.pLast; u.aq.pRec++){
68784 u.aq.serial_type = sqlite3VdbeSerialType(u.aq.pRec, u.aq.file_format);
68785 u.aq.i += putVarint32(&u.aq.zNewRecord[u.aq.i], u.aq.serial_type); /* serial type */
68786 }
68787 for(u.aq.pRec=u.aq.pData0; u.aq.pRec<=u.aq.pLast; u.aq.pRec++){ /* serial data */
68788 u.aq.i += sqlite3VdbeSerialPut(&u.aq.zNewRecord[u.aq.i], (int)(u.aq.nByte-u.aq.i), u.aq.pRec,u.aq.file_format);
68789 }
68790 assert( u.aq.i==u.aq.nByte );
68791
68792 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68793 pOut->n = (int)u.aq.nByte;
68794 pOut->flags = MEM_Blob | MEM_Dyn;
68795 pOut->xDel = 0;
68796 if( u.aq.nZero ){
68797 pOut->u.nZero = u.aq.nZero;
68798 pOut->flags |= MEM_Zero;
68799 }
68800 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
68801 REGISTER_TRACE(pOp->p3, pOut);
68802 UPDATE_MAX_BLOBSIZE(pOut);
68803 break;
68804 }
68805
68806 /* Opcode: Count P1 P2 * * *
 
68807 **
68808 ** Store the number of entries (an integer value) in the table or index
68809 ** opened by cursor P1 in register P2
68810 */
68811 #ifndef SQLITE_OMIT_BTREECOUNT
68812 case OP_Count: { /* out2-prerelease */
68813 #if 0 /* local variables moved into u.ar */
68814 i64 nEntry;
68815 BtCursor *pCrsr;
68816 #endif /* local variables moved into u.ar */
68817
68818 u.ar.pCrsr = p->apCsr[pOp->p1]->pCursor;
68819 if( ALWAYS(u.ar.pCrsr) ){
68820 rc = sqlite3BtreeCount(u.ar.pCrsr, &u.ar.nEntry);
68821 }else{
68822 u.ar.nEntry = 0;
68823 }
68824 pOut->u.i = u.ar.nEntry;
68825 break;
68826 }
68827 #endif
68828
68829 /* Opcode: Savepoint P1 * * P4 *
@@ -68831,43 +69200,43 @@
68831 ** Open, release or rollback the savepoint named by parameter P4, depending
68832 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
68833 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
68834 */
68835 case OP_Savepoint: {
68836 #if 0 /* local variables moved into u.as */
68837 int p1; /* Value of P1 operand */
68838 char *zName; /* Name of savepoint */
68839 int nName;
68840 Savepoint *pNew;
68841 Savepoint *pSavepoint;
68842 Savepoint *pTmp;
68843 int iSavepoint;
68844 int ii;
68845 #endif /* local variables moved into u.as */
68846
68847 u.as.p1 = pOp->p1;
68848 u.as.zName = pOp->p4.z;
68849
68850 /* Assert that the u.as.p1 parameter is valid. Also that if there is no open
68851 ** transaction, then there cannot be any savepoints.
68852 */
68853 assert( db->pSavepoint==0 || db->autoCommit==0 );
68854 assert( u.as.p1==SAVEPOINT_BEGIN||u.as.p1==SAVEPOINT_RELEASE||u.as.p1==SAVEPOINT_ROLLBACK );
68855 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
68856 assert( checkSavepointCount(db) );
68857 assert( p->bIsReader );
68858
68859 if( u.as.p1==SAVEPOINT_BEGIN ){
68860 if( db->nVdbeWrite>0 ){
68861 /* A new savepoint cannot be created if there are active write
68862 ** statements (i.e. open read/write incremental blob handles).
68863 */
68864 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
68865 "SQL statements in progress");
68866 rc = SQLITE_BUSY;
68867 }else{
68868 u.as.nName = sqlite3Strlen30(u.as.zName);
68869
68870 #ifndef SQLITE_OMIT_VIRTUALTABLE
68871 /* This call is Ok even if this savepoint is actually a transaction
68872 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
68873 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -68877,14 +69246,14 @@
68877 db->nStatement+db->nSavepoint);
68878 if( rc!=SQLITE_OK ) goto abort_due_to_error;
68879 #endif
68880
68881 /* Create a new savepoint structure. */
68882 u.as.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.as.nName+1);
68883 if( u.as.pNew ){
68884 u.as.pNew->zName = (char *)&u.as.pNew[1];
68885 memcpy(u.as.pNew->zName, u.as.zName, u.as.nName+1);
68886
68887 /* If there is no open transaction, then mark this as a special
68888 ** "transaction savepoint". */
68889 if( db->autoCommit ){
68890 db->autoCommit = 0;
@@ -68892,32 +69261,32 @@
68892 }else{
68893 db->nSavepoint++;
68894 }
68895
68896 /* Link the new savepoint into the database handle's list. */
68897 u.as.pNew->pNext = db->pSavepoint;
68898 db->pSavepoint = u.as.pNew;
68899 u.as.pNew->nDeferredCons = db->nDeferredCons;
68900 u.as.pNew->nDeferredImmCons = db->nDeferredImmCons;
68901 }
68902 }
68903 }else{
68904 u.as.iSavepoint = 0;
68905
68906 /* Find the named savepoint. If there is no such savepoint, then an
68907 ** an error is returned to the user. */
68908 for(
68909 u.as.pSavepoint = db->pSavepoint;
68910 u.as.pSavepoint && sqlite3StrICmp(u.as.pSavepoint->zName, u.as.zName);
68911 u.as.pSavepoint = u.as.pSavepoint->pNext
68912 ){
68913 u.as.iSavepoint++;
68914 }
68915 if( !u.as.pSavepoint ){
68916 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.as.zName);
68917 rc = SQLITE_ERROR;
68918 }else if( db->nVdbeWrite>0 && u.as.p1==SAVEPOINT_RELEASE ){
68919 /* It is not possible to release (commit) a savepoint if there are
68920 ** active write statements.
68921 */
68922 sqlite3SetString(&p->zErrMsg, db,
68923 "cannot release savepoint - SQL statements in progress"
@@ -68927,12 +69296,12 @@
68927
68928 /* Determine whether or not this is a transaction savepoint. If so,
68929 ** and this is a RELEASE command, then the current transaction
68930 ** is committed.
68931 */
68932 int isTransaction = u.as.pSavepoint->pNext==0 && db->isTransactionSavepoint;
68933 if( isTransaction && u.as.p1==SAVEPOINT_RELEASE ){
68934 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
68935 goto vdbe_return;
68936 }
68937 db->autoCommit = 1;
68938 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -68942,56 +69311,56 @@
68942 goto vdbe_return;
68943 }
68944 db->isTransactionSavepoint = 0;
68945 rc = p->rc;
68946 }else{
68947 u.as.iSavepoint = db->nSavepoint - u.as.iSavepoint - 1;
68948 if( u.as.p1==SAVEPOINT_ROLLBACK ){
68949 for(u.as.ii=0; u.as.ii<db->nDb; u.as.ii++){
68950 sqlite3BtreeTripAllCursors(db->aDb[u.as.ii].pBt, SQLITE_ABORT);
68951 }
68952 }
68953 for(u.as.ii=0; u.as.ii<db->nDb; u.as.ii++){
68954 rc = sqlite3BtreeSavepoint(db->aDb[u.as.ii].pBt, u.as.p1, u.as.iSavepoint);
68955 if( rc!=SQLITE_OK ){
68956 goto abort_due_to_error;
68957 }
68958 }
68959 if( u.as.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
68960 sqlite3ExpirePreparedStatements(db);
68961 sqlite3ResetAllSchemasOfConnection(db);
68962 db->flags = (db->flags | SQLITE_InternChanges);
68963 }
68964 }
68965
68966 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
68967 ** savepoints nested inside of the savepoint being operated on. */
68968 while( db->pSavepoint!=u.as.pSavepoint ){
68969 u.as.pTmp = db->pSavepoint;
68970 db->pSavepoint = u.as.pTmp->pNext;
68971 sqlite3DbFree(db, u.as.pTmp);
68972 db->nSavepoint--;
68973 }
68974
68975 /* If it is a RELEASE, then destroy the savepoint being operated on
68976 ** too. If it is a ROLLBACK TO, then set the number of deferred
68977 ** constraint violations present in the database to the value stored
68978 ** when the savepoint was created. */
68979 if( u.as.p1==SAVEPOINT_RELEASE ){
68980 assert( u.as.pSavepoint==db->pSavepoint );
68981 db->pSavepoint = u.as.pSavepoint->pNext;
68982 sqlite3DbFree(db, u.as.pSavepoint);
68983 if( !isTransaction ){
68984 db->nSavepoint--;
68985 }
68986 }else{
68987 db->nDeferredCons = u.as.pSavepoint->nDeferredCons;
68988 db->nDeferredImmCons = u.as.pSavepoint->nDeferredImmCons;
68989 }
68990
68991 if( !isTransaction ){
68992 rc = sqlite3VtabSavepoint(db, u.as.p1, u.as.iSavepoint);
68993 if( rc!=SQLITE_OK ) goto abort_due_to_error;
68994 }
68995 }
68996 }
68997
@@ -69006,54 +69375,54 @@
69006 ** there are active writing VMs or active VMs that use shared cache.
69007 **
69008 ** This instruction causes the VM to halt.
69009 */
69010 case OP_AutoCommit: {
69011 #if 0 /* local variables moved into u.at */
69012 int desiredAutoCommit;
69013 int iRollback;
69014 int turnOnAC;
69015 #endif /* local variables moved into u.at */
69016
69017 u.at.desiredAutoCommit = pOp->p1;
69018 u.at.iRollback = pOp->p2;
69019 u.at.turnOnAC = u.at.desiredAutoCommit && !db->autoCommit;
69020 assert( u.at.desiredAutoCommit==1 || u.at.desiredAutoCommit==0 );
69021 assert( u.at.desiredAutoCommit==1 || u.at.iRollback==0 );
69022 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
69023 assert( p->bIsReader );
69024
69025 #if 0
69026 if( u.at.turnOnAC && u.at.iRollback && db->nVdbeActive>1 ){
69027 /* If this instruction implements a ROLLBACK and other VMs are
69028 ** still running, and a transaction is active, return an error indicating
69029 ** that the other VMs must complete first.
69030 */
69031 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69032 "SQL statements in progress");
69033 rc = SQLITE_BUSY;
69034 }else
69035 #endif
69036 if( u.at.turnOnAC && !u.at.iRollback && db->nVdbeWrite>0 ){
69037 /* If this instruction implements a COMMIT and other VMs are writing
69038 ** return an error indicating that the other VMs must complete first.
69039 */
69040 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69041 "SQL statements in progress");
69042 rc = SQLITE_BUSY;
69043 }else if( u.at.desiredAutoCommit!=db->autoCommit ){
69044 if( u.at.iRollback ){
69045 assert( u.at.desiredAutoCommit==1 );
69046 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69047 db->autoCommit = 1;
69048 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69049 goto vdbe_return;
69050 }else{
69051 db->autoCommit = (u8)u.at.desiredAutoCommit;
69052 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69053 p->pc = pc;
69054 db->autoCommit = (u8)(1-u.at.desiredAutoCommit);
69055 p->rc = rc = SQLITE_BUSY;
69056 goto vdbe_return;
69057 }
69058 }
69059 assert( db->nStatement==0 );
@@ -69064,12 +69433,12 @@
69064 rc = SQLITE_ERROR;
69065 }
69066 goto vdbe_return;
69067 }else{
69068 sqlite3SetString(&p->zErrMsg, db,
69069 (!u.at.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69070 (u.at.iRollback)?"cannot rollback - no transaction is active":
69071 "cannot commit - no transaction is active"));
69072
69073 rc = SQLITE_ERROR;
69074 }
69075 break;
@@ -69105,26 +69474,26 @@
69105 ** will automatically commit when the VDBE halts.
69106 **
69107 ** If P2 is zero, then a read-lock is obtained on the database file.
69108 */
69109 case OP_Transaction: {
69110 #if 0 /* local variables moved into u.au */
69111 Btree *pBt;
69112 #endif /* local variables moved into u.au */
69113
69114 assert( p->bIsReader );
69115 assert( p->readOnly==0 || pOp->p2==0 );
69116 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69117 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69118 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69119 rc = SQLITE_READONLY;
69120 goto abort_due_to_error;
69121 }
69122 u.au.pBt = db->aDb[pOp->p1].pBt;
69123
69124 if( u.au.pBt ){
69125 rc = sqlite3BtreeBeginTrans(u.au.pBt, pOp->p2);
69126 if( rc==SQLITE_BUSY ){
69127 p->pc = pc;
69128 p->rc = rc = SQLITE_BUSY;
69129 goto vdbe_return;
69130 }
@@ -69133,20 +69502,20 @@
69133 }
69134
69135 if( pOp->p2 && p->usesStmtJournal
69136 && (db->autoCommit==0 || db->nVdbeRead>1)
69137 ){
69138 assert( sqlite3BtreeIsInTrans(u.au.pBt) );
69139 if( p->iStatement==0 ){
69140 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69141 db->nStatement++;
69142 p->iStatement = db->nSavepoint + db->nStatement;
69143 }
69144
69145 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69146 if( rc==SQLITE_OK ){
69147 rc = sqlite3BtreeBeginStmt(u.au.pBt, p->iStatement);
69148 }
69149
69150 /* Store the current value of the database handles deferred constraint
69151 ** counter. If the statement transaction needs to be rolled back,
69152 ** the value of this counter needs to be restored too. */
@@ -69168,26 +69537,26 @@
69168 ** There must be a read-lock on the database (either a transaction
69169 ** must be started or there must be an open cursor) before
69170 ** executing this instruction.
69171 */
69172 case OP_ReadCookie: { /* out2-prerelease */
69173 #if 0 /* local variables moved into u.av */
69174 int iMeta;
69175 int iDb;
69176 int iCookie;
69177 #endif /* local variables moved into u.av */
69178
69179 assert( p->bIsReader );
69180 u.av.iDb = pOp->p1;
69181 u.av.iCookie = pOp->p3;
69182 assert( pOp->p3<SQLITE_N_BTREE_META );
69183 assert( u.av.iDb>=0 && u.av.iDb<db->nDb );
69184 assert( db->aDb[u.av.iDb].pBt!=0 );
69185 assert( (p->btreeMask & (((yDbMask)1)<<u.av.iDb))!=0 );
69186
69187 sqlite3BtreeGetMeta(db->aDb[u.av.iDb].pBt, u.av.iCookie, (u32 *)&u.av.iMeta);
69188 pOut->u.i = u.av.iMeta;
69189 break;
69190 }
69191
69192 /* Opcode: SetCookie P1 P2 P3 * *
69193 **
@@ -69198,31 +69567,31 @@
69198 ** database file used to store temporary tables.
69199 **
69200 ** A transaction must be started before executing this opcode.
69201 */
69202 case OP_SetCookie: { /* in3 */
69203 #if 0 /* local variables moved into u.aw */
69204 Db *pDb;
69205 #endif /* local variables moved into u.aw */
69206 assert( pOp->p2<SQLITE_N_BTREE_META );
69207 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69208 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69209 assert( p->readOnly==0 );
69210 u.aw.pDb = &db->aDb[pOp->p1];
69211 assert( u.aw.pDb->pBt!=0 );
69212 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69213 pIn3 = &aMem[pOp->p3];
69214 sqlite3VdbeMemIntegerify(pIn3);
69215 /* See note about index shifting on OP_ReadCookie */
69216 rc = sqlite3BtreeUpdateMeta(u.aw.pDb->pBt, pOp->p2, (int)pIn3->u.i);
69217 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69218 /* When the schema cookie changes, record the new cookie internally */
69219 u.aw.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69220 db->flags |= SQLITE_InternChanges;
69221 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69222 /* Record changes in the file format */
69223 u.aw.pDb->pSchema->file_format = (u8)pIn3->u.i;
69224 }
69225 if( pOp->p1==1 ){
69226 /* Invalidate all prepared statements whenever the TEMP database
69227 ** schema is changed. Ticket #1644 */
69228 sqlite3ExpirePreparedStatements(db);
@@ -69248,28 +69617,28 @@
69248 ** Either a transaction needs to have been started or an OP_Open needs
69249 ** to be executed (to establish a read lock) before this opcode is
69250 ** invoked.
69251 */
69252 case OP_VerifyCookie: {
69253 #if 0 /* local variables moved into u.ax */
69254 int iMeta;
69255 int iGen;
69256 Btree *pBt;
69257 #endif /* local variables moved into u.ax */
69258
69259 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69260 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69261 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69262 assert( p->bIsReader );
69263 u.ax.pBt = db->aDb[pOp->p1].pBt;
69264 if( u.ax.pBt ){
69265 sqlite3BtreeGetMeta(u.ax.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ax.iMeta);
69266 u.ax.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69267 }else{
69268 u.ax.iGen = u.ax.iMeta = 0;
69269 }
69270 if( u.ax.iMeta!=pOp->p2 || u.ax.iGen!=pOp->p3 ){
69271 sqlite3DbFree(db, p->zErrMsg);
69272 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69273 /* If the schema-cookie from the database file matches the cookie
69274 ** stored with the in-memory representation of the schema, do
69275 ** not reload the schema from the database file.
@@ -69281,11 +69650,11 @@
69281 ** discard the database schema, as the user code implementing the
69282 ** v-table would have to be ready for the sqlite3_vtab structure itself
69283 ** to be invalidated whenever sqlite3_step() is called from within
69284 ** a v-table method.
69285 */
69286 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ax.iMeta ){
69287 sqlite3ResetOneSchema(db, pOp->p1);
69288 }
69289
69290 p->expired = 1;
69291 rc = SQLITE_SCHEMA;
@@ -69292,10 +69661,11 @@
69292 }
69293 break;
69294 }
69295
69296 /* Opcode: OpenRead P1 P2 P3 P4 P5
 
69297 **
69298 ** Open a read-only cursor for the database table whose root page is
69299 ** P2 in a database file. The database file is determined by P3.
69300 ** P3==0 means the main database, P3==1 means the database used for
69301 ** temporary tables, and P3>1 means used the corresponding attached
@@ -69322,10 +69692,11 @@
69322 ** value, it is set to the number of columns in the table.
69323 **
69324 ** See also OpenWrite.
69325 */
69326 /* Opcode: OpenWrite P1 P2 P3 P4 P5
 
69327 **
69328 ** Open a read/write cursor named P1 on the table or index whose root
69329 ** page is P2. Or if P5!=0 use the content of register P2 to find the
69330 ** root page.
69331 **
@@ -69342,20 +69713,20 @@
69342 **
69343 ** See also OpenRead.
69344 */
69345 case OP_OpenRead:
69346 case OP_OpenWrite: {
69347 #if 0 /* local variables moved into u.ay */
69348 int nField;
69349 KeyInfo *pKeyInfo;
69350 int p2;
69351 int iDb;
69352 int wrFlag;
69353 Btree *pX;
69354 VdbeCursor *pCur;
69355 Db *pDb;
69356 #endif /* local variables moved into u.ay */
69357
69358 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69359 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69360 assert( p->bIsReader );
69361 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69363,76 +69734,78 @@
69363 if( p->expired ){
69364 rc = SQLITE_ABORT;
69365 break;
69366 }
69367
69368 u.ay.nField = 0;
69369 u.ay.pKeyInfo = 0;
69370 u.ay.p2 = pOp->p2;
69371 u.ay.iDb = pOp->p3;
69372 assert( u.ay.iDb>=0 && u.ay.iDb<db->nDb );
69373 assert( (p->btreeMask & (((yDbMask)1)<<u.ay.iDb))!=0 );
69374 u.ay.pDb = &db->aDb[u.ay.iDb];
69375 u.ay.pX = u.ay.pDb->pBt;
69376 assert( u.ay.pX!=0 );
69377 if( pOp->opcode==OP_OpenWrite ){
69378 u.ay.wrFlag = 1;
69379 assert( sqlite3SchemaMutexHeld(db, u.ay.iDb, 0) );
69380 if( u.ay.pDb->pSchema->file_format < p->minWriteFileFormat ){
69381 p->minWriteFileFormat = u.ay.pDb->pSchema->file_format;
69382 }
69383 }else{
69384 u.ay.wrFlag = 0;
69385 }
69386 if( pOp->p5 & OPFLAG_P2ISREG ){
69387 assert( u.ay.p2>0 );
69388 assert( u.ay.p2<=(p->nMem-p->nCursor) );
69389 pIn2 = &aMem[u.ay.p2];
69390 assert( memIsValid(pIn2) );
69391 assert( (pIn2->flags & MEM_Int)!=0 );
69392 sqlite3VdbeMemIntegerify(pIn2);
69393 u.ay.p2 = (int)pIn2->u.i;
69394 /* The u.ay.p2 value always comes from a prior OP_CreateTable opcode and
69395 ** that opcode will always set the u.ay.p2 value to 2 or more or else fail.
69396 ** If there were a failure, the prepared statement would have halted
69397 ** before reaching this instruction. */
69398 if( NEVER(u.ay.p2<2) ) {
69399 rc = SQLITE_CORRUPT_BKPT;
69400 goto abort_due_to_error;
69401 }
69402 }
69403 if( pOp->p4type==P4_KEYINFO ){
69404 u.ay.pKeyInfo = pOp->p4.pKeyInfo;
69405 u.ay.pKeyInfo->enc = ENC(p->db);
69406 u.ay.nField = u.ay.pKeyInfo->nField+1;
 
69407 }else if( pOp->p4type==P4_INT32 ){
69408 u.ay.nField = pOp->p4.i;
69409 }
69410 assert( pOp->p1>=0 );
69411 u.ay.pCur = allocateCursor(p, pOp->p1, u.ay.nField, u.ay.iDb, 1);
69412 if( u.ay.pCur==0 ) goto no_mem;
69413 u.ay.pCur->nullRow = 1;
69414 u.ay.pCur->isOrdered = 1;
69415 rc = sqlite3BtreeCursor(u.ay.pX, u.ay.p2, u.ay.wrFlag, u.ay.pKeyInfo, u.ay.pCur->pCursor);
69416 u.ay.pCur->pKeyInfo = u.ay.pKeyInfo;
69417 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69418 sqlite3BtreeCursorHints(u.ay.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69419
69420 /* Since it performs no memory allocation or IO, the only value that
69421 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69422 assert( rc==SQLITE_OK );
69423
69424 /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
69425 ** SQLite used to check if the root-page flags were sane at this point
69426 ** and report database corruption if they were not, but this check has
69427 ** since moved into the btree layer. */
69428 u.ay.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69429 u.ay.pCur->isIndex = !u.ay.pCur->isTable;
69430 break;
69431 }
69432
69433 /* Opcode: OpenEphemeral P1 P2 * P4 P5
 
69434 **
69435 ** Open a new cursor P1 to a transient table.
69436 ** The cursor is always opened read/write even if
69437 ** the main database is read-only. The ephemeral
69438 ** table is deleted automatically when the cursor is closed.
@@ -69440,98 +69813,96 @@
69440 ** P2 is the number of columns in the ephemeral table.
69441 ** The cursor points to a BTree table if P4==0 and to a BTree index
69442 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
69443 ** that defines the format of keys in the index.
69444 **
69445 ** This opcode was once called OpenTemp. But that created
69446 ** confusion because the term "temp table", might refer either
69447 ** to a TEMP table at the SQL level, or to a table opened by
69448 ** this opcode. Then this opcode was call OpenVirtual. But
69449 ** that created confusion with the whole virtual-table idea.
69450 **
69451 ** The P5 parameter can be a mask of the BTREE_* flags defined
69452 ** in btree.h. These flags control aspects of the operation of
69453 ** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
69454 ** added automatically.
69455 */
69456 /* Opcode: OpenAutoindex P1 P2 * P4 *
 
69457 **
69458 ** This opcode works the same as OP_OpenEphemeral. It has a
69459 ** different name to distinguish its use. Tables created using
69460 ** by this opcode will be used for automatically created transient
69461 ** indices in joins.
69462 */
69463 case OP_OpenAutoindex:
69464 case OP_OpenEphemeral: {
69465 #if 0 /* local variables moved into u.az */
69466 VdbeCursor *pCx;
69467 #endif /* local variables moved into u.az */
 
 
69468 static const int vfsFlags =
69469 SQLITE_OPEN_READWRITE |
69470 SQLITE_OPEN_CREATE |
69471 SQLITE_OPEN_EXCLUSIVE |
69472 SQLITE_OPEN_DELETEONCLOSE |
69473 SQLITE_OPEN_TRANSIENT_DB;
69474
69475 assert( pOp->p1>=0 );
69476 u.az.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69477 if( u.az.pCx==0 ) goto no_mem;
69478 u.az.pCx->nullRow = 1;
69479 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.az.pCx->pBt,
69480 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69481 if( rc==SQLITE_OK ){
69482 rc = sqlite3BtreeBeginTrans(u.az.pCx->pBt, 1);
69483 }
69484 if( rc==SQLITE_OK ){
69485 /* If a transient index is required, create it by calling
69486 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69487 ** opening it. If a transient table is required, just use the
69488 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69489 */
69490 if( pOp->p4.pKeyInfo ){
69491 int pgno;
69492 assert( pOp->p4type==P4_KEYINFO );
69493 rc = sqlite3BtreeCreateTable(u.az.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69494 if( rc==SQLITE_OK ){
69495 assert( pgno==MASTER_ROOT+1 );
69496 rc = sqlite3BtreeCursor(u.az.pCx->pBt, pgno, 1,
69497 (KeyInfo*)pOp->p4.z, u.az.pCx->pCursor);
69498 u.az.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69499 u.az.pCx->pKeyInfo->enc = ENC(p->db);
69500 }
69501 u.az.pCx->isTable = 0;
69502 }else{
69503 rc = sqlite3BtreeCursor(u.az.pCx->pBt, MASTER_ROOT, 1, 0, u.az.pCx->pCursor);
69504 u.az.pCx->isTable = 1;
69505 }
69506 }
69507 u.az.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69508 u.az.pCx->isIndex = !u.az.pCx->isTable;
69509 break;
69510 }
69511
69512 /* Opcode: SorterOpen P1 P2 * P4 *
69513 **
69514 ** This opcode works like OP_OpenEphemeral except that it opens
69515 ** a transient index that is specifically designed to sort large
69516 ** tables using an external merge-sort algorithm.
69517 */
69518 case OP_SorterOpen: {
69519 #if 0 /* local variables moved into u.ba */
69520 VdbeCursor *pCx;
69521 #endif /* local variables moved into u.ba */
69522
69523 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69524 if( u.ba.pCx==0 ) goto no_mem;
69525 u.ba.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69526 u.ba.pCx->pKeyInfo->enc = ENC(p->db);
69527 u.ba.pCx->isSorter = 1;
69528 rc = sqlite3VdbeSorterInit(db, u.ba.pCx);
 
69529 break;
69530 }
69531
69532 /* Opcode: OpenPseudo P1 P2 P3 * P5
 
69533 **
69534 ** Open a new cursor that points to a fake table that contains a single
69535 ** row of data. The content of that one row in the content of memory
69536 ** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
69537 ** MEM_Blob content contained in register P2. When P5==1, then the
@@ -69544,22 +69915,22 @@
69544 **
69545 ** P3 is the number of fields in the records that will be stored by
69546 ** the pseudo-table.
69547 */
69548 case OP_OpenPseudo: {
69549 #if 0 /* local variables moved into u.bb */
69550 VdbeCursor *pCx;
69551 #endif /* local variables moved into u.bb */
69552
69553 assert( pOp->p1>=0 );
69554 u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69555 if( u.bb.pCx==0 ) goto no_mem;
69556 u.bb.pCx->nullRow = 1;
69557 u.bb.pCx->pseudoTableReg = pOp->p2;
69558 u.bb.pCx->isTable = 1;
69559 u.bb.pCx->isIndex = 0;
69560 u.bb.pCx->multiPseudo = pOp->p5;
69561 break;
69562 }
69563
69564 /* Opcode: Close P1 * * * *
69565 **
@@ -69572,10 +69943,11 @@
69572 p->apCsr[pOp->p1] = 0;
69573 break;
69574 }
69575
69576 /* Opcode: SeekGe P1 P2 P3 P4 *
 
69577 **
69578 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69579 ** use the value in register P3 as the key. If cursor P1 refers
69580 ** to an SQL index, then P3 is the first in an array of P4 registers
69581 ** that are used as an unpacked index key.
@@ -69585,10 +69957,11 @@
69585 ** greater than or equal to the key and P2 is not zero, then jump to P2.
69586 **
69587 ** See also: Found, NotFound, Distinct, SeekLt, SeekGt, SeekLe
69588 */
69589 /* Opcode: SeekGt P1 P2 P3 P4 *
 
69590 **
69591 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69592 ** use the value in register P3 as a key. If cursor P1 refers
69593 ** to an SQL index, then P3 is the first in an array of P4 registers
69594 ** that are used as an unpacked index key.
@@ -69598,10 +69971,11 @@
69598 ** the key and P2 is not zero, then jump to P2.
69599 **
69600 ** See also: Found, NotFound, Distinct, SeekLt, SeekGe, SeekLe
69601 */
69602 /* Opcode: SeekLt P1 P2 P3 P4 *
 
69603 **
69604 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69605 ** use the value in register P3 as a key. If cursor P1 refers
69606 ** to an SQL index, then P3 is the first in an array of P4 registers
69607 ** that are used as an unpacked index key.
@@ -69611,10 +69985,11 @@
69611 ** the key and P2 is not zero, then jump to P2.
69612 **
69613 ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLe
69614 */
69615 /* Opcode: SeekLe P1 P2 P3 P4 *
 
69616 **
69617 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69618 ** use the value in register P3 as a key. If cursor P1 refers
69619 ** to an SQL index, then P3 is the first in an array of P4 registers
69620 ** that are used as an unpacked index key.
@@ -69627,200 +70002,197 @@
69627 */
69628 case OP_SeekLt: /* jump, in3 */
69629 case OP_SeekLe: /* jump, in3 */
69630 case OP_SeekGe: /* jump, in3 */
69631 case OP_SeekGt: { /* jump, in3 */
69632 #if 0 /* local variables moved into u.bc */
69633 int res;
69634 int oc;
69635 VdbeCursor *pC;
69636 UnpackedRecord r;
69637 int nField;
69638 i64 iKey; /* The rowid we are to seek to */
69639 #endif /* local variables moved into u.bc */
69640
69641 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69642 assert( pOp->p2!=0 );
69643 u.bc.pC = p->apCsr[pOp->p1];
69644 assert( u.bc.pC!=0 );
69645 assert( u.bc.pC->pseudoTableReg==0 );
69646 assert( OP_SeekLe == OP_SeekLt+1 );
69647 assert( OP_SeekGe == OP_SeekLt+2 );
69648 assert( OP_SeekGt == OP_SeekLt+3 );
69649 assert( u.bc.pC->isOrdered );
69650 if( ALWAYS(u.bc.pC->pCursor!=0) ){
69651 u.bc.oc = pOp->opcode;
69652 u.bc.pC->nullRow = 0;
69653 if( u.bc.pC->isTable ){
69654 /* The input value in P3 might be of any type: integer, real, string,
69655 ** blob, or NULL. But it needs to be an integer before we can do
69656 ** the seek, so covert it. */
69657 pIn3 = &aMem[pOp->p3];
69658 applyNumericAffinity(pIn3);
69659 u.bc.iKey = sqlite3VdbeIntValue(pIn3);
69660 u.bc.pC->rowidIsValid = 0;
69661
69662 /* If the P3 value could not be converted into an integer without
69663 ** loss of information, then special processing is required... */
69664 if( (pIn3->flags & MEM_Int)==0 ){
69665 if( (pIn3->flags & MEM_Real)==0 ){
69666 /* If the P3 value cannot be converted into any kind of a number,
69667 ** then the seek is not possible, so jump to P2 */
69668 pc = pOp->p2 - 1;
69669 break;
69670 }
69671 /* If we reach this point, then the P3 value must be a floating
69672 ** point number. */
69673 assert( (pIn3->flags & MEM_Real)!=0 );
69674
69675 if( u.bc.iKey==SMALLEST_INT64 && (pIn3->r<(double)u.bc.iKey || pIn3->r>0) ){
69676 /* The P3 value is too large in magnitude to be expressed as an
69677 ** integer. */
69678 u.bc.res = 1;
69679 if( pIn3->r<0 ){
69680 if( u.bc.oc>=OP_SeekGe ){ assert( u.bc.oc==OP_SeekGe || u.bc.oc==OP_SeekGt );
69681 rc = sqlite3BtreeFirst(u.bc.pC->pCursor, &u.bc.res);
69682 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69683 }
69684 }else{
69685 if( u.bc.oc<=OP_SeekLe ){ assert( u.bc.oc==OP_SeekLt || u.bc.oc==OP_SeekLe );
69686 rc = sqlite3BtreeLast(u.bc.pC->pCursor, &u.bc.res);
69687 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69688 }
69689 }
69690 if( u.bc.res ){
69691 pc = pOp->p2 - 1;
69692 }
69693 break;
69694 }else if( u.bc.oc==OP_SeekLt || u.bc.oc==OP_SeekGe ){
69695 /* Use the ceiling() function to convert real->int */
69696 if( pIn3->r > (double)u.bc.iKey ) u.bc.iKey++;
69697 }else{
69698 /* Use the floor() function to convert real->int */
69699 assert( u.bc.oc==OP_SeekLe || u.bc.oc==OP_SeekGt );
69700 if( pIn3->r < (double)u.bc.iKey ) u.bc.iKey--;
69701 }
69702 }
69703 rc = sqlite3BtreeMovetoUnpacked(u.bc.pC->pCursor, 0, (u64)u.bc.iKey, 0, &u.bc.res);
69704 if( rc!=SQLITE_OK ){
69705 goto abort_due_to_error;
69706 }
69707 if( u.bc.res==0 ){
69708 u.bc.pC->rowidIsValid = 1;
69709 u.bc.pC->lastRowid = u.bc.iKey;
69710 }
69711 }else{
69712 u.bc.nField = pOp->p4.i;
69713 assert( pOp->p4type==P4_INT32 );
69714 assert( u.bc.nField>0 );
69715 u.bc.r.pKeyInfo = u.bc.pC->pKeyInfo;
69716 u.bc.r.nField = (u16)u.bc.nField;
69717
69718 /* The next line of code computes as follows, only faster:
69719 ** if( u.bc.oc==OP_SeekGt || u.bc.oc==OP_SeekLe ){
69720 ** u.bc.r.flags = UNPACKED_INCRKEY;
69721 ** }else{
69722 ** u.bc.r.flags = 0;
69723 ** }
69724 */
69725 u.bc.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bc.oc - OP_SeekLt)));
69726 assert( u.bc.oc!=OP_SeekGt || u.bc.r.flags==UNPACKED_INCRKEY );
69727 assert( u.bc.oc!=OP_SeekLe || u.bc.r.flags==UNPACKED_INCRKEY );
69728 assert( u.bc.oc!=OP_SeekGe || u.bc.r.flags==0 );
69729 assert( u.bc.oc!=OP_SeekLt || u.bc.r.flags==0 );
69730
69731 u.bc.r.aMem = &aMem[pOp->p3];
69732 #ifdef SQLITE_DEBUG
69733 { int i; for(i=0; i<u.bc.r.nField; i++) assert( memIsValid(&u.bc.r.aMem[i]) ); }
69734 #endif
69735 ExpandBlob(u.bc.r.aMem);
69736 rc = sqlite3BtreeMovetoUnpacked(u.bc.pC->pCursor, &u.bc.r, 0, 0, &u.bc.res);
69737 if( rc!=SQLITE_OK ){
69738 goto abort_due_to_error;
69739 }
69740 u.bc.pC->rowidIsValid = 0;
69741 }
69742 u.bc.pC->deferredMoveto = 0;
69743 u.bc.pC->cacheStatus = CACHE_STALE;
69744 #ifdef SQLITE_TEST
69745 sqlite3_search_count++;
69746 #endif
69747 if( u.bc.oc>=OP_SeekGe ){ assert( u.bc.oc==OP_SeekGe || u.bc.oc==OP_SeekGt );
69748 if( u.bc.res<0 || (u.bc.res==0 && u.bc.oc==OP_SeekGt) ){
69749 rc = sqlite3BtreeNext(u.bc.pC->pCursor, &u.bc.res);
69750 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69751 u.bc.pC->rowidIsValid = 0;
69752 }else{
69753 u.bc.res = 0;
69754 }
69755 }else{
69756 assert( u.bc.oc==OP_SeekLt || u.bc.oc==OP_SeekLe );
69757 if( u.bc.res>0 || (u.bc.res==0 && u.bc.oc==OP_SeekLt) ){
69758 rc = sqlite3BtreePrevious(u.bc.pC->pCursor, &u.bc.res);
69759 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69760 u.bc.pC->rowidIsValid = 0;
69761 }else{
69762 /* u.bc.res might be negative because the table is empty. Check to
69763 ** see if this is the case.
69764 */
69765 u.bc.res = sqlite3BtreeEof(u.bc.pC->pCursor);
69766 }
69767 }
69768 assert( pOp->p2>0 );
69769 if( u.bc.res ){
69770 pc = pOp->p2 - 1;
69771 }
69772 }else{
69773 /* This happens when attempting to open the sqlite3_master table
69774 ** for read access returns SQLITE_EMPTY. In this case always
69775 ** take the jump (since there are no records in the table).
69776 */
69777 pc = pOp->p2 - 1;
69778 }
69779 break;
69780 }
69781
69782 /* Opcode: Seek P1 P2 * * *
 
69783 **
69784 ** P1 is an open table cursor and P2 is a rowid integer. Arrange
69785 ** for P1 to move so that it points to the rowid given by P2.
69786 **
69787 ** This is actually a deferred seek. Nothing actually happens until
69788 ** the cursor is used to read a record. That way, if no reads
69789 ** occur, no unnecessary I/O happens.
69790 */
69791 case OP_Seek: { /* in2 */
69792 #if 0 /* local variables moved into u.bd */
69793 VdbeCursor *pC;
69794 #endif /* local variables moved into u.bd */
69795
69796 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69797 u.bd.pC = p->apCsr[pOp->p1];
69798 assert( u.bd.pC!=0 );
69799 if( ALWAYS(u.bd.pC->pCursor!=0) ){
69800 assert( u.bd.pC->isTable );
69801 u.bd.pC->nullRow = 0;
69802 pIn2 = &aMem[pOp->p2];
69803 u.bd.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
69804 u.bd.pC->rowidIsValid = 0;
69805 u.bd.pC->deferredMoveto = 1;
69806 }
69807 break;
69808 }
69809
69810
69811 /* Opcode: Found P1 P2 P3 P4 *
 
69812 **
69813 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
69814 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
69815 ** record.
69816 **
69817 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
69818 ** is a prefix of any entry in P1 then a jump is made to P2 and
69819 ** P1 is left pointing at the matching entry.
 
 
69820 */
69821 /* Opcode: NotFound P1 P2 P3 P4 *
 
69822 **
69823 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
69824 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
69825 ** record.
69826 **
@@ -69828,177 +70200,126 @@
69828 ** is not the prefix of any entry in P1 then a jump is made to P2. If P1
69829 ** does contain an entry whose prefix matches the P3/P4 record then control
69830 ** falls through to the next instruction and P1 is left pointing at the
69831 ** matching entry.
69832 **
69833 ** See also: Found, NotExists, IsUnique
69834 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69835 case OP_NotFound: /* jump, in3 */
69836 case OP_Found: { /* jump, in3 */
69837 #if 0 /* local variables moved into u.be */
69838 int alreadyExists;
 
69839 VdbeCursor *pC;
69840 int res;
69841 char *pFree;
69842 UnpackedRecord *pIdxKey;
69843 UnpackedRecord r;
69844 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*3 + 7];
69845 #endif /* local variables moved into u.be */
69846
69847 #ifdef SQLITE_TEST
69848 sqlite3_found_count++;
69849 #endif
69850
69851 u.be.alreadyExists = 0;
69852 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69853 assert( pOp->p4type==P4_INT32 );
69854 u.be.pC = p->apCsr[pOp->p1];
69855 assert( u.be.pC!=0 );
69856 pIn3 = &aMem[pOp->p3];
69857 if( ALWAYS(u.be.pC->pCursor!=0) ){
69858
69859 assert( u.be.pC->isTable==0 );
69860 if( pOp->p4.i>0 ){
69861 u.be.r.pKeyInfo = u.be.pC->pKeyInfo;
69862 u.be.r.nField = (u16)pOp->p4.i;
69863 u.be.r.aMem = pIn3;
69864 #ifdef SQLITE_DEBUG
69865 { int i; for(i=0; i<u.be.r.nField; i++) assert( memIsValid(&u.be.r.aMem[i]) ); }
69866 #endif
69867 u.be.r.flags = UNPACKED_PREFIX_MATCH;
69868 u.be.pIdxKey = &u.be.r;
69869 }else{
69870 u.be.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
69871 u.be.pC->pKeyInfo, u.be.aTempRec, sizeof(u.be.aTempRec), &u.be.pFree
69872 );
69873 if( u.be.pIdxKey==0 ) goto no_mem;
69874 assert( pIn3->flags & MEM_Blob );
69875 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
69876 sqlite3VdbeRecordUnpack(u.be.pC->pKeyInfo, pIn3->n, pIn3->z, u.be.pIdxKey);
69877 u.be.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
69878 }
69879 rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, u.be.pIdxKey, 0, 0, &u.be.res);
69880 if( pOp->p4.i==0 ){
69881 sqlite3DbFree(db, u.be.pFree);
69882 }
69883 if( rc!=SQLITE_OK ){
69884 break;
69885 }
69886 u.be.alreadyExists = (u.be.res==0);
69887 u.be.pC->deferredMoveto = 0;
69888 u.be.pC->cacheStatus = CACHE_STALE;
69889 }
69890 if( pOp->opcode==OP_Found ){
69891 if( u.be.alreadyExists ) pc = pOp->p2 - 1;
69892 }else{
69893 if( !u.be.alreadyExists ) pc = pOp->p2 - 1;
69894 }
69895 break;
69896 }
69897
69898 /* Opcode: IsUnique P1 P2 P3 P4 *
69899 **
69900 ** Cursor P1 is open on an index b-tree - that is to say, a btree which
69901 ** no data and where the key are records generated by OP_MakeRecord with
69902 ** the list field being the integer ROWID of the entry that the index
69903 ** entry refers to.
69904 **
69905 ** The P3 register contains an integer record number. Call this record
69906 ** number R. Register P4 is the first in a set of N contiguous registers
69907 ** that make up an unpacked index key that can be used with cursor P1.
69908 ** The value of N can be inferred from the cursor. N includes the rowid
69909 ** value appended to the end of the index record. This rowid value may
69910 ** or may not be the same as R.
69911 **
69912 ** If any of the N registers beginning with register P4 contains a NULL
69913 ** value, jump immediately to P2.
69914 **
69915 ** Otherwise, this instruction checks if cursor P1 contains an entry
69916 ** where the first (N-1) fields match but the rowid value at the end
69917 ** of the index entry is not R. If there is no such entry, control jumps
69918 ** to instruction P2. Otherwise, the rowid of the conflicting index
69919 ** entry is copied to register P3 and control falls through to the next
69920 ** instruction.
69921 **
69922 ** See also: NotFound, NotExists, Found
69923 */
69924 case OP_IsUnique: { /* jump, in3 */
69925 #if 0 /* local variables moved into u.bf */
69926 u16 ii;
69927 VdbeCursor *pCx;
69928 BtCursor *pCrsr;
69929 u16 nField;
69930 Mem *aMx;
69931 UnpackedRecord r; /* B-Tree index search key */
69932 i64 R; /* Rowid stored in register P3 */
69933 #endif /* local variables moved into u.bf */
69934
69935 pIn3 = &aMem[pOp->p3];
69936 u.bf.aMx = &aMem[pOp->p4.i];
69937 /* Assert that the values of parameters P1 and P4 are in range. */
69938 assert( pOp->p4type==P4_INT32 );
69939 assert( pOp->p4.i>0 && pOp->p4.i<=(p->nMem-p->nCursor) );
69940 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69941
69942 /* Find the index cursor. */
69943 u.bf.pCx = p->apCsr[pOp->p1];
69944 assert( u.bf.pCx->deferredMoveto==0 );
69945 u.bf.pCx->seekResult = 0;
69946 u.bf.pCx->cacheStatus = CACHE_STALE;
69947 u.bf.pCrsr = u.bf.pCx->pCursor;
69948
69949 /* If any of the values are NULL, take the jump. */
69950 u.bf.nField = u.bf.pCx->pKeyInfo->nField;
69951 for(u.bf.ii=0; u.bf.ii<u.bf.nField; u.bf.ii++){
69952 if( u.bf.aMx[u.bf.ii].flags & MEM_Null ){
69953 pc = pOp->p2 - 1;
69954 u.bf.pCrsr = 0;
69955 break;
69956 }
69957 }
69958 assert( (u.bf.aMx[u.bf.nField].flags & MEM_Null)==0 );
69959
69960 if( u.bf.pCrsr!=0 ){
69961 /* Populate the index search key. */
69962 u.bf.r.pKeyInfo = u.bf.pCx->pKeyInfo;
69963 u.bf.r.nField = u.bf.nField + 1;
69964 u.bf.r.flags = UNPACKED_PREFIX_SEARCH;
69965 u.bf.r.aMem = u.bf.aMx;
69966 #ifdef SQLITE_DEBUG
69967 { int i; for(i=0; i<u.bf.r.nField; i++) assert( memIsValid(&u.bf.r.aMem[i]) ); }
69968 #endif
69969
69970 /* Extract the value of u.bf.R from register P3. */
69971 sqlite3VdbeMemIntegerify(pIn3);
69972 u.bf.R = pIn3->u.i;
69973
69974 /* Search the B-Tree index. If no conflicting record is found, jump
69975 ** to P2. Otherwise, copy the rowid of the conflicting record to
69976 ** register P3 and fall through to the next instruction. */
69977 rc = sqlite3BtreeMovetoUnpacked(u.bf.pCrsr, &u.bf.r, 0, 0, &u.bf.pCx->seekResult);
69978 if( (u.bf.r.flags & UNPACKED_PREFIX_SEARCH) || u.bf.r.rowid==u.bf.R ){
69979 pc = pOp->p2 - 1;
69980 }else{
69981 pIn3->u.i = u.bf.r.rowid;
69982 }
69983 }
69984 break;
69985 }
69986
69987 /* Opcode: NotExists P1 P2 P3 * *
69988 **
69989 ** Use the content of register P3 as an integer key. If a record
69990 ** with that key does not exist in table of P1, then jump to P2.
69991 ** If the record does exist, then fall through. The cursor is left
69992 ** pointing to the record if it exists.
69993 **
69994 ** The difference between this operation and NotFound is that this
69995 ** operation assumes the key is an integer and that P1 is a table whereas
69996 ** NotFound assumes key is a blob constructed from MakeRecord and
69997 ** P1 is an index.
69998 **
69999 ** See also: Found, NotFound, IsUnique
70000 */
70001 case OP_NotExists: { /* jump, in3 */
70002 #if 0 /* local variables moved into u.bg */
70003 VdbeCursor *pC;
70004 BtCursor *pCrsr;
@@ -70012,36 +70333,29 @@
70012 u.bg.pC = p->apCsr[pOp->p1];
70013 assert( u.bg.pC!=0 );
70014 assert( u.bg.pC->isTable );
70015 assert( u.bg.pC->pseudoTableReg==0 );
70016 u.bg.pCrsr = u.bg.pC->pCursor;
70017 if( ALWAYS(u.bg.pCrsr!=0) ){
70018 u.bg.res = 0;
70019 u.bg.iKey = pIn3->u.i;
70020 rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70021 u.bg.pC->lastRowid = pIn3->u.i;
70022 u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70023 u.bg.pC->nullRow = 0;
70024 u.bg.pC->cacheStatus = CACHE_STALE;
70025 u.bg.pC->deferredMoveto = 0;
70026 if( u.bg.res!=0 ){
70027 pc = pOp->p2 - 1;
70028 assert( u.bg.pC->rowidIsValid==0 );
70029 }
70030 u.bg.pC->seekResult = u.bg.res;
70031 }else{
70032 /* This happens when an attempt to open a read cursor on the
70033 ** sqlite_master table returns SQLITE_EMPTY.
70034 */
70035 pc = pOp->p2 - 1;
70036 assert( u.bg.pC->rowidIsValid==0 );
70037 u.bg.pC->seekResult = 0;
70038 }
70039 break;
70040 }
70041
70042 /* Opcode: Sequence P1 P2 * * *
 
70043 **
70044 ** Find the next available sequence number for cursor P1.
70045 ** Write the sequence number into register P2.
70046 ** The sequence number on the cursor is incremented after this
70047 ** instruction.
@@ -70053,10 +70367,11 @@
70053 break;
70054 }
70055
70056
70057 /* Opcode: NewRowid P1 P2 P3 * *
 
70058 **
70059 ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
70060 ** The record number is not previously used as a key in the database
70061 ** table that cursor P1 points to. The new record number is written
70062 ** written to register P2.
@@ -70204,10 +70519,11 @@
70204 pOut->u.i = u.bh.v;
70205 break;
70206 }
70207
70208 /* Opcode: Insert P1 P2 P3 P4 P5
 
70209 **
70210 ** Write an entry into the table of cursor P1. A new entry is
70211 ** created if it doesn't already exist or the data for an existing
70212 ** entry is overwritten. The data is the value MEM_Blob stored in register
70213 ** number P2. The key is stored in register P3. The key must
@@ -70243,10 +70559,11 @@
70243 **
70244 ** This instruction only works on tables. The equivalent instruction
70245 ** for indices is OP_IdxInsert.
70246 */
70247 /* Opcode: InsertInt P1 P2 P3 P4 P5
 
70248 **
70249 ** This works exactly like OP_Insert except that the key is the
70250 ** integer value P3, not the value of the integer stored in register P3.
70251 */
70252 case OP_Insert:
@@ -70396,34 +70713,46 @@
70396 sqlite3VdbeSetChanges(db, p->nChange);
70397 p->nChange = 0;
70398 break;
70399 }
70400
70401 /* Opcode: SorterCompare P1 P2 P3
 
70402 **
70403 ** P1 is a sorter cursor. This instruction compares the record blob in
70404 ** register P3 with the entry that the sorter cursor currently points to.
70405 ** If, excluding the rowid fields at the end, the two records are a match,
70406 ** fall through to the next instruction. Otherwise, jump to instruction P2.
 
 
 
 
 
 
 
70407 */
70408 case OP_SorterCompare: {
70409 #if 0 /* local variables moved into u.bk */
70410 VdbeCursor *pC;
70411 int res;
 
70412 #endif /* local variables moved into u.bk */
70413
70414 u.bk.pC = p->apCsr[pOp->p1];
70415 assert( isSorter(u.bk.pC) );
 
70416 pIn3 = &aMem[pOp->p3];
70417 rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, &u.bk.res);
 
70418 if( u.bk.res ){
70419 pc = pOp->p2-1;
70420 }
70421 break;
70422 };
70423
70424 /* Opcode: SorterData P1 P2 * * *
 
70425 **
70426 ** Write into register P2 the current sorter data for sorter cursor P1.
70427 */
70428 case OP_SorterData: {
70429 #if 0 /* local variables moved into u.bl */
@@ -70436,10 +70765,11 @@
70436 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
70437 break;
70438 }
70439
70440 /* Opcode: RowData P1 P2 * * *
 
70441 **
70442 ** Write into register P2 the complete row data for cursor P1.
70443 ** There is no interpretation of the data.
70444 ** It is just copied onto the P2 register exactly as
70445 ** it is found in the database file.
@@ -70446,10 +70776,11 @@
70446 **
70447 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70448 ** of a real table, not a pseudo-table.
70449 */
70450 /* Opcode: RowKey P1 P2 * * *
 
70451 **
70452 ** Write into register P2 the complete row key for cursor P1.
70453 ** There is no interpretation of the data.
70454 ** The key is copied onto the P3 register exactly as
70455 ** it is found in the database file.
@@ -70516,14 +70847,16 @@
70516 }else{
70517 rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70518 }
70519 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70520 UPDATE_MAX_BLOBSIZE(pOut);
 
70521 break;
70522 }
70523
70524 /* Opcode: Rowid P1 P2 * * *
 
70525 **
70526 ** Store in register P2 an integer which is the key of the table entry that
70527 ** P1 is currently point to.
70528 **
70529 ** P1 can be either an ordinary table or a virtual table. There used to
@@ -70611,13 +70944,12 @@
70611 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70612 u.bp.pC = p->apCsr[pOp->p1];
70613 assert( u.bp.pC!=0 );
70614 u.bp.pCrsr = u.bp.pC->pCursor;
70615 u.bp.res = 0;
70616 if( ALWAYS(u.bp.pCrsr!=0) ){
70617 rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
70618 }
70619 u.bp.pC->nullRow = (u8)u.bp.res;
70620 u.bp.pC->deferredMoveto = 0;
70621 u.bp.pC->rowidIsValid = 0;
70622 u.bp.pC->cacheStatus = CACHE_STALE;
70623 if( pOp->p2>0 && u.bp.res ){
@@ -70685,11 +71017,11 @@
70685 pc = pOp->p2 - 1;
70686 }
70687 break;
70688 }
70689
70690 /* Opcode: Next P1 P2 * P4 P5
70691 **
70692 ** Advance cursor P1 so that it points to the next key/data pair in its
70693 ** table or index. If there are no more key/value pairs then fall through
70694 ** to the following instruction. But if the cursor advance was successful,
70695 ** jump immediately to P2.
@@ -70757,10 +71089,11 @@
70757 u.br.pC->rowidIsValid = 0;
70758 goto check_for_interrupt;
70759 }
70760
70761 /* Opcode: IdxInsert P1 P2 P3 * P5
 
70762 **
70763 ** Register P2 holds an SQL index key made using the
70764 ** MakeRecord instructions. This opcode writes that key
70765 ** into the index P1. Data for the entry is nil.
70766 **
@@ -70784,31 +71117,32 @@
70784 assert( u.bs.pC!=0 );
70785 assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) );
70786 pIn2 = &aMem[pOp->p2];
70787 assert( pIn2->flags & MEM_Blob );
70788 u.bs.pCrsr = u.bs.pC->pCursor;
70789 if( ALWAYS(u.bs.pCrsr!=0) ){
70790 assert( u.bs.pC->isTable==0 );
70791 rc = ExpandBlob(pIn2);
70792 if( rc==SQLITE_OK ){
70793 if( isSorter(u.bs.pC) ){
70794 rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
70795 }else{
70796 u.bs.nKey = pIn2->n;
70797 u.bs.zKey = pIn2->z;
70798 rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
70799 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
70800 );
70801 assert( u.bs.pC->deferredMoveto==0 );
70802 u.bs.pC->cacheStatus = CACHE_STALE;
70803 }
70804 }
70805 }
70806 break;
70807 }
70808
70809 /* Opcode: IdxDelete P1 P2 P3 * *
 
70810 **
70811 ** The content of P3 registers starting at register P2 form
70812 ** an unpacked index key. This opcode removes that entry from the
70813 ** index opened by cursor P1.
70814 */
@@ -70824,29 +71158,30 @@
70824 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
70825 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70826 u.bt.pC = p->apCsr[pOp->p1];
70827 assert( u.bt.pC!=0 );
70828 u.bt.pCrsr = u.bt.pC->pCursor;
70829 if( ALWAYS(u.bt.pCrsr!=0) ){
70830 u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
70831 u.bt.r.nField = (u16)pOp->p3;
70832 u.bt.r.flags = 0;
70833 u.bt.r.aMem = &aMem[pOp->p2];
 
70834 #ifdef SQLITE_DEBUG
70835 { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
70836 #endif
70837 rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
70838 if( rc==SQLITE_OK && u.bt.res==0 ){
70839 rc = sqlite3BtreeDelete(u.bt.pCrsr);
70840 }
70841 assert( u.bt.pC->deferredMoveto==0 );
70842 u.bt.pC->cacheStatus = CACHE_STALE;
70843 }
 
 
70844 break;
70845 }
70846
70847 /* Opcode: IdxRowid P1 P2 * * *
 
70848 **
70849 ** Write into register P2 an integer which is the last entry in the record at
70850 ** the end of the index key pointed to by cursor P1. This integer should be
70851 ** the rowid of the table entry to which this index entry points.
70852 **
@@ -70861,29 +71196,29 @@
70861
70862 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70863 u.bu.pC = p->apCsr[pOp->p1];
70864 assert( u.bu.pC!=0 );
70865 u.bu.pCrsr = u.bu.pC->pCursor;
 
70866 pOut->flags = MEM_Null;
70867 if( ALWAYS(u.bu.pCrsr!=0) ){
70868 rc = sqlite3VdbeCursorMoveto(u.bu.pC);
70869 if( NEVER(rc) ) goto abort_due_to_error;
70870 assert( u.bu.pC->deferredMoveto==0 );
70871 assert( u.bu.pC->isTable==0 );
70872 if( !u.bu.pC->nullRow ){
70873 rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
70874 if( rc!=SQLITE_OK ){
70875 goto abort_due_to_error;
70876 }
70877 pOut->u.i = u.bu.rowid;
70878 pOut->flags = MEM_Int;
70879 }
70880 }
70881 break;
70882 }
70883
70884 /* Opcode: IdxGE P1 P2 P3 P4 P5
 
70885 **
70886 ** The P4 register values beginning with P3 form an unpacked index
70887 ** key that omits the ROWID. Compare this key value against the index
70888 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
70889 **
@@ -70894,10 +71229,11 @@
70894 ** prior to the comparison. This make the opcode work like IdxGT except
70895 ** that if the key from register P3 is a prefix of the key in the cursor,
70896 ** the result is false whereas it would be true with IdxGT.
70897 */
70898 /* Opcode: IdxLT P1 P2 P3 P4 P5
 
70899 **
70900 ** The P4 register values beginning with P3 form an unpacked index
70901 ** key that omits the ROWID. Compare this key value against the index
70902 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
70903 **
@@ -70917,35 +71253,34 @@
70917
70918 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70919 u.bv.pC = p->apCsr[pOp->p1];
70920 assert( u.bv.pC!=0 );
70921 assert( u.bv.pC->isOrdered );
70922 if( ALWAYS(u.bv.pC->pCursor!=0) ){
70923 assert( u.bv.pC->deferredMoveto==0 );
70924 assert( pOp->p5==0 || pOp->p5==1 );
70925 assert( pOp->p4type==P4_INT32 );
70926 u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
70927 u.bv.r.nField = (u16)pOp->p4.i;
70928 if( pOp->p5 ){
70929 u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
70930 }else{
70931 u.bv.r.flags = UNPACKED_PREFIX_MATCH;
70932 }
70933 u.bv.r.aMem = &aMem[pOp->p3];
70934 #ifdef SQLITE_DEBUG
70935 { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
70936 #endif
70937 rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
70938 if( pOp->opcode==OP_IdxLT ){
70939 u.bv.res = -u.bv.res;
70940 }else{
70941 assert( pOp->opcode==OP_IdxGE );
70942 u.bv.res++;
70943 }
70944 if( u.bv.res>0 ){
70945 pc = pOp->p2 - 1 ;
70946 }
70947 }
70948 break;
70949 }
70950
70951 /* Opcode: Destroy P1 P2 P3 * *
@@ -71052,10 +71387,11 @@
71052 }
71053 break;
71054 }
71055
71056 /* Opcode: CreateTable P1 P2 * * *
 
71057 **
71058 ** Allocate a new table in the main database file if P1==0 or in the
71059 ** auxiliary database file if P1==1 or in an attached database if
71060 ** P1>1. Write the root page number of the new table into
71061 ** register P2
@@ -71065,10 +71401,11 @@
71065 ** has an arbitrary key but no data.
71066 **
71067 ** See also: CreateIndex
71068 */
71069 /* Opcode: CreateIndex P1 P2 * * *
 
71070 **
71071 ** Allocate a new index in the main database file if P1==0 or in the
71072 ** auxiliary database file if P1==1 or in an attached database if
71073 ** P1>1. Write the root page number of the new table into
71074 ** register P2.
@@ -71272,10 +71609,11 @@
71272 break;
71273 }
71274 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
71275
71276 /* Opcode: RowSetAdd P1 P2 * * *
 
71277 **
71278 ** Insert the integer value held by register P2 into a boolean index
71279 ** held in register P1.
71280 **
71281 ** An assertion fails if P2 is not an integer.
@@ -71291,10 +71629,11 @@
71291 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn2->u.i);
71292 break;
71293 }
71294
71295 /* Opcode: RowSetRead P1 P2 P3 * *
 
71296 **
71297 ** Extract the smallest value from boolean index P1 and put that value into
71298 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71299 ** unchanged and jump to instruction P2.
71300 */
@@ -71316,10 +71655,11 @@
71316 }
71317 goto check_for_interrupt;
71318 }
71319
71320 /* Opcode: RowSetTest P1 P2 P3 P4
 
71321 **
71322 ** Register P3 is assumed to hold a 64-bit integer value. If register P1
71323 ** contains a RowSet object and that RowSet object contains
71324 ** the value held in P3, jump to register P2. Otherwise, insert the
71325 ** integer in P3 into the RowSet and continue on to the
@@ -71525,10 +71865,11 @@
71525
71526 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71527
71528 #ifndef SQLITE_OMIT_FOREIGN_KEY
71529 /* Opcode: FkCounter P1 P2 * * *
 
71530 **
71531 ** Increment a "constraint counter" by P2 (P2 may be negative or positive).
71532 ** If P1 is non-zero, the database constraint counter is incremented
71533 ** (deferred foreign key constraints). Otherwise, if P1 is zero, the
71534 ** statement counter is incremented (immediate foreign key constraints).
@@ -71543,10 +71884,11 @@
71543 }
71544 break;
71545 }
71546
71547 /* Opcode: FkIfZero P1 P2 * * *
 
71548 **
71549 ** This opcode tests if a foreign key constraint-counter is currently zero.
71550 ** If so, jump to instruction P2. Otherwise, fall through to the next
71551 ** instruction.
71552 **
@@ -71565,10 +71907,11 @@
71565 }
71566 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
71567
71568 #ifndef SQLITE_OMIT_AUTOINCREMENT
71569 /* Opcode: MemMax P1 P2 * * *
 
71570 **
71571 ** P1 is a register in the root frame of this VM (the root frame is
71572 ** different from the current frame if this instruction is being executed
71573 ** within a sub-program). Set the value of register P1 to the maximum of
71574 ** its current value and the value in register P2.
@@ -71597,10 +71940,11 @@
71597 break;
71598 }
71599 #endif /* SQLITE_OMIT_AUTOINCREMENT */
71600
71601 /* Opcode: IfPos P1 P2 * * *
 
71602 **
71603 ** If the value of register P1 is 1 or greater, jump to P2.
71604 **
71605 ** It is illegal to use this instruction on a register that does
71606 ** not contain an integer. An assertion fault will result if you try.
@@ -71613,10 +71957,11 @@
71613 }
71614 break;
71615 }
71616
71617 /* Opcode: IfNeg P1 P2 * * *
 
71618 **
71619 ** If the value of register P1 is less than zero, jump to P2.
71620 **
71621 ** It is illegal to use this instruction on a register that does
71622 ** not contain an integer. An assertion fault will result if you try.
@@ -71629,10 +71974,11 @@
71629 }
71630 break;
71631 }
71632
71633 /* Opcode: IfZero P1 P2 P3 * *
 
71634 **
71635 ** The register P1 must contain an integer. Add literal P3 to the
71636 ** value in register P1. If the result is exactly 0, jump to P2.
71637 **
71638 ** It is illegal to use this instruction on a register that does
@@ -71647,10 +71993,11 @@
71647 }
71648 break;
71649 }
71650
71651 /* Opcode: AggStep * P2 P3 P4 P5
 
71652 **
71653 ** Execute the step function for an aggregate. The
71654 ** function has P5 arguments. P4 is a pointer to the FuncDef
71655 ** structure that specifies the function. Use register
71656 ** P3 as the accumulator.
@@ -71712,10 +72059,11 @@
71712
71713 break;
71714 }
71715
71716 /* Opcode: AggFinal P1 P2 * P4 *
 
71717 **
71718 ** Execute the finalizer function for an aggregate. P1 is
71719 ** the memory location that is the accumulator for the aggregate.
71720 **
71721 ** P2 is the number of arguments that the step function takes and
@@ -71947,10 +72295,11 @@
71947 break;
71948 }
71949
71950 #ifndef SQLITE_OMIT_SHARED_CACHE
71951 /* Opcode: TableLock P1 P2 P3 P4 *
 
71952 **
71953 ** Obtain a lock on a particular table. This instruction is only used when
71954 ** the shared-cache feature is enabled.
71955 **
71956 ** P1 is the index of the database in sqlite3.aDb[] of the database
@@ -72067,10 +72416,11 @@
72067 }
72068 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72069
72070 #ifndef SQLITE_OMIT_VIRTUALTABLE
72071 /* Opcode: VFilter P1 P2 P3 P4 *
 
72072 **
72073 ** P1 is a cursor opened using VOpen. P2 is an address to jump to if
72074 ** the filtered result set is empty.
72075 **
72076 ** P4 is either NULL or a string that was generated by the xBestIndex
@@ -72143,10 +72493,11 @@
72143 }
72144 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72145
72146 #ifndef SQLITE_OMIT_VIRTUALTABLE
72147 /* Opcode: VColumn P1 P2 P3 * *
 
72148 **
72149 ** Store the value of the P2-th column of
72150 ** the row of the virtual-table that the
72151 ** P1 cursor is pointing to into register P3.
72152 */
@@ -72282,10 +72633,11 @@
72282 }
72283 #endif
72284
72285 #ifndef SQLITE_OMIT_VIRTUALTABLE
72286 /* Opcode: VUpdate P1 P2 P3 P4 *
 
72287 **
72288 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72289 ** This opcode invokes the corresponding xUpdate method. P2 values
72290 ** are contiguous memory cells starting at P3 to pass to the xUpdate
72291 ** invocation. The value in register (P3+P2-1) corresponds to the
@@ -72413,10 +72765,20 @@
72413 ){
72414 u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
72415 db->xTrace(db->pTraceArg, u.cs.z);
72416 sqlite3DbFree(db, u.cs.z);
72417 }
 
 
 
 
 
 
 
 
 
 
72418 #ifdef SQLITE_DEBUG
72419 if( (db->flags & SQLITE_SqlTrace)!=0
72420 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72421 ){
72422 sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
@@ -72727,10 +73089,14 @@
72727 pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
72728 if( pTab && IsVirtual(pTab) ){
72729 pTab = 0;
72730 sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
72731 }
 
 
 
 
72732 #ifndef SQLITE_OMIT_VIEW
72733 if( pTab && pTab->pSelect ){
72734 pTab = 0;
72735 sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
72736 }
@@ -72784,11 +73150,11 @@
72784 }
72785 }
72786 #endif
72787 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
72788 int j;
72789 for(j=0; j<pIdx->nColumn; j++){
72790 if( pIdx->aiColumn[j]==iCol ){
72791 zFault = "indexed";
72792 }
72793 }
72794 }
@@ -73405,11 +73771,11 @@
73405 ** If pKey2 is passed a NULL pointer, then it is assumed that the pCsr->aSpace
73406 ** has been allocated and contains an unpacked record that is used as key2.
73407 */
73408 static void vdbeSorterCompare(
73409 const VdbeCursor *pCsr, /* Cursor object (for pKeyInfo) */
73410 int bOmitRowid, /* Ignore rowid field at end of keys */
73411 const void *pKey1, int nKey1, /* Left side of comparison */
73412 const void *pKey2, int nKey2, /* Right side of comparison */
73413 int *pRes /* OUT: Result of comparison */
73414 ){
73415 KeyInfo *pKeyInfo = pCsr->pKeyInfo;
@@ -73419,12 +73785,12 @@
73419
73420 if( pKey2 ){
73421 sqlite3VdbeRecordUnpack(pKeyInfo, nKey2, pKey2, r2);
73422 }
73423
73424 if( bOmitRowid ){
73425 r2->nField = pKeyInfo->nField;
73426 assert( r2->nField>0 );
73427 for(i=0; i<r2->nField; i++){
73428 if( r2->aMem[i].flags & MEM_Null ){
73429 *pRes = -1;
73430 return;
@@ -74046,17 +74412,18 @@
74046 ** key.
74047 */
74048 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(
74049 const VdbeCursor *pCsr, /* Sorter cursor */
74050 Mem *pVal, /* Value to compare to current sorter key */
 
74051 int *pRes /* OUT: Result of comparison */
74052 ){
74053 VdbeSorter *pSorter = pCsr->pSorter;
74054 void *pKey; int nKey; /* Sorter key to compare pVal with */
74055
74056 pKey = vdbeSorterRowkey(pSorter, &nKey);
74057 vdbeSorterCompare(pCsr, 1, pVal->z, pVal->n, pKey, nKey, pRes);
74058 return SQLITE_OK;
74059 }
74060
74061 /************** End of vdbesort.c ********************************************/
74062 /************** Begin file journal.c *****************************************/
@@ -74955,11 +75322,13 @@
74955 sqlite3 *db = pParse->db; /* The database connection */
74956 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
74957 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
74958 NameContext *pTopNC = pNC; /* First namecontext in the list */
74959 Schema *pSchema = 0; /* Schema of the expression */
74960 int isTrigger = 0;
 
 
74961
74962 assert( pNC ); /* the name context cannot be NULL. */
74963 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
74964 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
74965
@@ -74996,13 +75365,10 @@
74996 ExprList *pEList;
74997 SrcList *pSrcList = pNC->pSrcList;
74998
74999 if( pSrcList ){
75000 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
75001 Table *pTab;
75002 Column *pCol;
75003
75004 pTab = pItem->pTab;
75005 assert( pTab!=0 && pTab->zName!=0 );
75006 assert( pTab->nCol>0 );
75007 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
75008 int hit = 0;
@@ -75058,13 +75424,12 @@
75058
75059 #ifndef SQLITE_OMIT_TRIGGER
75060 /* If we have not already resolved the name, then maybe
75061 ** it is a new.* or old.* trigger argument reference
75062 */
75063 if( zDb==0 && zTab!=0 && cnt==0 && pParse->pTriggerTab!=0 ){
75064 int op = pParse->eTriggerOp;
75065 Table *pTab = 0;
75066 assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
75067 if( op!=TK_DELETE && sqlite3StrICmp("new",zTab) == 0 ){
75068 pExpr->iTable = 1;
75069 pTab = pParse->pTriggerTab;
75070 }else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
@@ -75074,20 +75439,19 @@
75074
75075 if( pTab ){
75076 int iCol;
75077 pSchema = pTab->pSchema;
75078 cntTab++;
75079 for(iCol=0; iCol<pTab->nCol; iCol++){
75080 Column *pCol = &pTab->aCol[iCol];
75081 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
75082 if( iCol==pTab->iPKey ){
75083 iCol = -1;
75084 }
75085 break;
75086 }
75087 }
75088 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) ){
75089 iCol = -1; /* IMP: R-44911-55124 */
75090 }
75091 if( iCol<pTab->nCol ){
75092 cnt++;
75093 if( iCol<0 ){
@@ -75110,11 +75474,12 @@
75110 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75111
75112 /*
75113 ** Perhaps the name is a reference to the ROWID
75114 */
75115 if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) ){
 
75116 cnt = 1;
75117 pExpr->iColumn = -1; /* IMP: R-44911-55124 */
75118 pExpr->affinity = SQLITE_AFF_INTEGER;
75119 }
75120
@@ -77714,20 +78079,20 @@
77714 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
77715 if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
77716 sqlite3 *db = pParse->db; /* Database connection */
77717 Table *pTab; /* Table <table>. */
77718 Expr *pExpr; /* Expression <column> */
77719 int iCol; /* Index of column <column> */
77720 int iDb; /* Database idx for pTab */
77721
77722 assert( p ); /* Because of isCandidateForInOpt(p) */
77723 assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
77724 assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
77725 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
77726 pTab = p->pSrc->a[0].pTab;
77727 pExpr = p->pEList->a[0].pExpr;
77728 iCol = pExpr->iColumn;
77729
77730 /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
77731 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
77732 sqlite3CodeVerifySchema(pParse, iDb);
77733 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
@@ -77761,20 +78126,15 @@
77761 int affinity_ok = sqlite3IndexAffinityOk(pX, pTab->aCol[iCol].affinity);
77762
77763 for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
77764 if( (pIdx->aiColumn[0]==iCol)
77765 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
77766 && (!mustBeUnique || (pIdx->nColumn==1 && pIdx->onError!=OE_None))
77767 ){
77768 int iAddr;
77769 char *pKey;
77770
77771 pKey = (char *)sqlite3IndexKeyinfo(pParse, pIdx);
77772 iAddr = sqlite3CodeOnce(pParse);
77773
77774 sqlite3VdbeAddOp4(v, OP_OpenRead, iTab, pIdx->tnum, iDb,
77775 pKey,P4_KEYINFO_HANDOFF);
77776 VdbeComment((v, "%s", pIdx->zName));
77777 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
77778 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
77779
77780 sqlite3VdbeJumpHere(v, iAddr);
@@ -77910,11 +78270,11 @@
77910 ** is used.
77911 */
77912 pExpr->iTable = pParse->nTab++;
77913 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
77914 if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
77915 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1);
77916
77917 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
77918 /* Case 1: expr IN (SELECT ...)
77919 **
77920 ** Generate code to write the results of the select into the temporary
@@ -77928,17 +78288,18 @@
77928 dest.affSdst = (u8)affinity;
77929 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
77930 pExpr->x.pSelect->iLimit = 0;
77931 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
77932 if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
77933 sqlite3DbFree(pParse->db, pKeyInfo);
77934 return 0;
77935 }
77936 pEList = pExpr->x.pSelect->pEList;
77937 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
77938 assert( pEList!=0 );
77939 assert( pEList->nExpr>0 );
 
77940 pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
77941 pEList->a[0].pExpr);
77942 }else if( ALWAYS(pExpr->x.pList!=0) ){
77943 /* Case 2: expr IN (exprlist)
77944 **
@@ -77954,10 +78315,11 @@
77954
77955 if( !affinity ){
77956 affinity = SQLITE_AFF_NONE;
77957 }
77958 if( pKeyInfo ){
 
77959 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
77960 }
77961
77962 /* Loop through each expression in <exprlist>. */
77963 r1 = sqlite3GetTempReg(pParse);
@@ -77995,11 +78357,11 @@
77995 }
77996 sqlite3ReleaseTempReg(pParse, r1);
77997 sqlite3ReleaseTempReg(pParse, r2);
77998 }
77999 if( pKeyInfo ){
78000 sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO_HANDOFF);
78001 }
78002 break;
78003 }
78004
78005 case TK_EXISTS:
@@ -78396,19 +78758,23 @@
78396 ** Generate code to extract the value of the iCol-th column of a table.
78397 */
78398 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
78399 Vdbe *v, /* The VDBE under construction */
78400 Table *pTab, /* The table containing the value */
78401 int iTabCur, /* The cursor for this table */
78402 int iCol, /* Index of the column to extract */
78403 int regOut /* Extract the valud into this register */
78404 ){
78405 if( iCol<0 || iCol==pTab->iPKey ){
78406 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
78407 }else{
78408 int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
78409 sqlite3VdbeAddOp3(v, op, iTabCur, iCol, regOut);
 
 
 
 
78410 }
78411 if( iCol>=0 ){
78412 sqlite3ColumnDefault(v, pTab, iCol, regOut);
78413 }
78414 }
@@ -79150,11 +79516,11 @@
79150 if( pExpr->affinity==OE_Ignore ){
79151 sqlite3VdbeAddOp4(
79152 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
79153 }else{
79154 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
79155 pExpr->affinity, pExpr->u.zToken, 0);
79156 }
79157
79158 break;
79159 }
79160 #endif
@@ -81526,12 +81892,11 @@
81526 }
81527
81528 /* Open the sqlite_stat[134] tables for writing. */
81529 for(i=0; aTable[i].zCols; i++){
81530 assert( i<ArraySize(aTable) );
81531 sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb);
81532 sqlite3VdbeChangeP4(v, -1, (char *)3, P4_INT32);
81533 sqlite3VdbeChangeP5(v, aCreateTbl[i]);
81534 }
81535 }
81536
81537 /*
@@ -81551,11 +81916,15 @@
81551 struct Stat4Sample {
81552 tRowcnt *anEq; /* sqlite_stat4.nEq */
81553 tRowcnt *anDLt; /* sqlite_stat4.nDLt */
81554 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81555 tRowcnt *anLt; /* sqlite_stat4.nLt */
81556 i64 iRowid; /* Rowid in main table of the key */
 
 
 
 
81557 u8 isPSample; /* True if a periodic sample */
81558 int iCol; /* If !isPSample, the reason for inclusion */
81559 u32 iHash; /* Tiebreaker hash */
81560 #endif
81561 };
@@ -81564,16 +81933,90 @@
81564 tRowcnt nPSample; /* How often to do a periodic sample */
81565 int nCol; /* Number of columns in index + rowid */
81566 int mxSample; /* Maximum number of samples to accumulate */
81567 Stat4Sample current; /* Current row as a Stat4Sample */
81568 u32 iPrn; /* Pseudo-random number used for sampling */
81569 Stat4Sample *aBest; /* Array of (nCol-1) best samples */
81570 int iMin; /* Index in a[] of entry with minimum score */
81571 int nSample; /* Current number of samples */
81572 int iGet; /* Index of current sample accessed by stat_get() */
81573 Stat4Sample *a; /* Array of mxSample Stat4Sample objects */
 
81574 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81575
81576 /*
81577 ** Implementation of the stat_init(N,C) SQL function. The two parameters
81578 ** are the number of rows in the table or index (C) and the number of columns
81579 ** in the index (N). The second argument (C) is only used for STAT3 and STAT4.
@@ -81589,10 +82032,11 @@
81589 ){
81590 Stat4Accum *p;
81591 int nCol; /* Number of columns in index being sampled */
81592 int nColUp; /* nCol rounded up for alignment */
81593 int n; /* Bytes of space to allocate */
 
81594 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81595 int mxSample = SQLITE_STAT4_SAMPLES;
81596 #endif
81597
81598 /* Decode the three function arguments */
@@ -81605,20 +82049,22 @@
81605 n = sizeof(*p)
81606 + sizeof(tRowcnt)*nColUp /* Stat4Accum.anEq */
81607 + sizeof(tRowcnt)*nColUp /* Stat4Accum.anDLt */
81608 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81609 + sizeof(tRowcnt)*nColUp /* Stat4Accum.anLt */
81610 + sizeof(Stat4Sample)*(nCol+mxSample) /* Stat4Accum.aBest[], a[] */
81611 + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample)
81612 #endif
81613 ;
81614 p = sqlite3MallocZero(n);
 
81615 if( p==0 ){
81616 sqlite3_result_error_nomem(context);
81617 return;
81618 }
81619
 
81620 p->nRow = 0;
81621 p->nCol = nCol;
81622 p->current.anDLt = (tRowcnt*)&p[1];
81623 p->current.anEq = &p->current.anDLt[nColUp];
81624
@@ -81649,11 +82095,11 @@
81649 }
81650 }
81651 #endif
81652
81653 /* Return a pointer to the allocated object to the caller */
81654 sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
81655 }
81656 static const FuncDef statInitFuncdef = {
81657 1+IsStat34, /* nArg */
81658 SQLITE_UTF8, /* funcFlags */
81659 0, /* pUserData */
@@ -81723,29 +82169,16 @@
81723 #else
81724 return (nEqNew==nEqOld && pNew->iHash>pOld->iHash);
81725 #endif
81726 }
81727
81728 /*
81729 ** Copy the contents of object (*pFrom) into (*pTo).
81730 */
81731 static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){
81732 pTo->iRowid = pFrom->iRowid;
81733 pTo->isPSample = pFrom->isPSample;
81734 pTo->iCol = pFrom->iCol;
81735 pTo->iHash = pFrom->iHash;
81736 memcpy(pTo->anEq, pFrom->anEq, sizeof(tRowcnt)*p->nCol);
81737 memcpy(pTo->anLt, pFrom->anLt, sizeof(tRowcnt)*p->nCol);
81738 memcpy(pTo->anDLt, pFrom->anDLt, sizeof(tRowcnt)*p->nCol);
81739 }
81740
81741 /*
81742 ** Copy the contents of sample *pNew into the p->a[] array. If necessary,
81743 ** remove the least desirable sample from p->a[] to make room.
81744 */
81745 static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
81746 Stat4Sample *pSample;
81747 int i;
81748
81749 assert( IsStat4 || nEqZero==0 );
81750
81751 #ifdef SQLITE_ENABLE_STAT4
@@ -81781,12 +82214,14 @@
81781 if( p->nSample>=p->mxSample ){
81782 Stat4Sample *pMin = &p->a[p->iMin];
81783 tRowcnt *anEq = pMin->anEq;
81784 tRowcnt *anLt = pMin->anLt;
81785 tRowcnt *anDLt = pMin->anDLt;
 
81786 memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-p->iMin-1));
81787 pSample = &p->a[p->nSample-1];
 
81788 pSample->anEq = anEq;
81789 pSample->anDLt = anDLt;
81790 pSample->anLt = anLt;
81791 p->nSample = p->mxSample-1;
81792 }
@@ -81879,20 +82314,21 @@
81879 UNUSED_PARAMETER( iChng );
81880 #endif
81881 }
81882
81883 /*
81884 ** Implementation of the stat_push SQL function: stat_push(P,R,C)
81885 ** Arguments:
81886 **
81887 ** P Pointer to the Stat4Accum object created by stat_init()
81888 ** C Index of left-most column to differ from previous row
81889 ** R Rowid for the current row
 
81890 **
81891 ** The SQL function always returns NULL.
81892 **
81893 ** The R parameter is only used for STAT3 and STAT4.
81894 */
81895 static void statPush(
81896 sqlite3_context *context,
81897 int argc,
81898 sqlite3_value **argv
@@ -81928,11 +82364,16 @@
81928 p->current.anEq[i] = 1;
81929 }
81930 }
81931 p->nRow++;
81932 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81933 p->current.iRowid = sqlite3_value_int64(argv[2]);
 
 
 
 
 
81934 p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345;
81935 #endif
81936
81937 #ifdef SQLITE_ENABLE_STAT4
81938 {
@@ -82052,11 +82493,17 @@
82052 if( p->iGet<0 ){
82053 samplePushPrevious(p, 0);
82054 p->iGet = 0;
82055 }
82056 if( p->iGet<p->nSample ){
82057 sqlite3_result_int64(context, p->a[p->iGet].iRowid);
 
 
 
 
 
 
82058 }
82059 }else{
82060 tRowcnt *aCnt = 0;
82061
82062 assert( p->iGet<p->nSample );
@@ -82189,26 +82636,30 @@
82189 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
82190 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
82191
82192 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
82193 int nCol; /* Number of columns indexed by pIdx */
82194 KeyInfo *pKey; /* KeyInfo structure for pIdx */
82195 int *aGotoChng; /* Array of jump instruction addresses */
82196 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
82197 int addrGotoChng0; /* Address of "Goto addr_chng_0" */
82198 int addrNextRow; /* Address of "next_row:" */
 
82199
82200 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
82201 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
82202 VdbeNoopComment((v, "Begin analysis of %s", pIdx->zName));
82203 nCol = pIdx->nColumn;
82204 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
82205 if( aGotoChng==0 ) continue;
82206 pKey = sqlite3IndexKeyinfo(pParse, pIdx);
82207
82208 /* Populate the register containing the index name. */
82209 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
 
 
 
 
 
82210
82211 /*
82212 ** Pseudo-code for loop that calls stat_push():
82213 **
82214 ** Rewind csr
@@ -82247,11 +82698,11 @@
82247 pParse->nMem = MAX(pParse->nMem, regPrev+nCol);
82248
82249 /* Open a read-only cursor on the index being analyzed. */
82250 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
82251 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
82252 sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
82253 VdbeComment((v, "%s", pIdx->zName));
82254
82255 /* Invoke the stat_init() function. The arguments are:
82256 **
82257 ** (1) the number of columns in the index including the rowid,
@@ -82321,12 +82772,25 @@
82321 ** Next csr
82322 ** if !eof(csr) goto next_row;
82323 */
82324 sqlite3VdbeJumpHere(v, aGotoChng[nCol]);
82325 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
82326 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
82327 assert( regRowid==(regStat4+2) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82328 #endif
82329 assert( regChng==(regStat4+1) );
82330 sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
82331 sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
82332 sqlite3VdbeChangeP5(v, 2+IsStat34);
@@ -82348,26 +82812,27 @@
82348 int regSample = regStat1+3;
82349 int regCol = regStat1+4;
82350 int regSampleRowid = regCol + nCol;
82351 int addrNext;
82352 int addrIsNull;
 
82353
82354 pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
82355
82356 addrNext = sqlite3VdbeCurrentAddr(v);
82357 callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
82358 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
82359 callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
82360 callStatGet(v, regStat4, STAT_GET_NLT, regLt);
82361 callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
82362 sqlite3VdbeAddOp3(v, OP_NotExists, iTabCur, addrNext, regSampleRowid);
82363 #ifdef SQLITE_ENABLE_STAT3
82364 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
82365 pIdx->aiColumn[0], regSample);
82366 #else
82367 for(i=0; i<nCol; i++){
82368 int iCol = pIdx->aiColumn[i];
82369 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
82370 }
82371 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
82372 #endif
82373 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0);
@@ -82619,11 +83084,11 @@
82619 pIndex = 0;
82620 }
82621 z = argv[2];
82622
82623 if( pIndex ){
82624 decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst, pIndex);
82625 if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0];
82626 }else{
82627 Index fakeIdx;
82628 fakeIdx.szIdxRow = pTable->szTabRow;
82629 decodeIntArray((char*)z, 1, &pTable->nRowEst, &fakeIdx);
@@ -82665,11 +83130,11 @@
82665 static void initAvgEq(Index *pIdx){
82666 if( pIdx ){
82667 IndexSample *aSample = pIdx->aSample;
82668 IndexSample *pFinal = &aSample[pIdx->nSample-1];
82669 int iCol;
82670 for(iCol=0; iCol<pIdx->nColumn; iCol++){
82671 int i; /* Used to iterate through samples */
82672 tRowcnt sumEq = 0; /* Sum of the nEq values */
82673 tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
82674 tRowcnt avgEq = 0;
82675 tRowcnt nDLt = pFinal->anDLt[iCol];
@@ -82692,10 +83157,27 @@
82692 pIdx->aAvgEq[iCol] = avgEq;
82693 if( pIdx->nSampleCol==1 ) break;
82694 }
82695 }
82696 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82697
82698 /*
82699 ** Load the content from either the sqlite_stat4 or sqlite_stat3 table
82700 ** into the relevant Index.aSample[] arrays.
82701 **
@@ -82742,18 +83224,18 @@
82742 tRowcnt *pSpace;
82743
82744 zIndex = (char *)sqlite3_column_text(pStmt, 0);
82745 if( zIndex==0 ) continue;
82746 nSample = sqlite3_column_int(pStmt, 1);
82747 pIdx = sqlite3FindIndex(db, zIndex, zDb);
82748 assert( pIdx==0 || bStat3 || pIdx->nSample==0 );
82749 /* Index.nSample is non-zero at this point if data has already been
82750 ** loaded from the stat4 table. In this case ignore stat3 data. */
82751 if( pIdx==0 || pIdx->nSample ) continue;
82752 if( bStat3==0 ){
82753 nIdxCol = pIdx->nColumn+1;
82754 nAvgCol = pIdx->nColumn;
82755 }
82756 pIdx->nSampleCol = nIdxCol;
82757 nByte = sizeof(IndexSample) * nSample;
82758 nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
82759 nByte += nAvgCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
@@ -82788,11 +83270,11 @@
82788 Index *pIdx; /* Pointer to the index object */
82789 int nCol = 1; /* Number of columns in index */
82790
82791 zIndex = (char *)sqlite3_column_text(pStmt, 0);
82792 if( zIndex==0 ) continue;
82793 pIdx = sqlite3FindIndex(db, zIndex, zDb);
82794 if( pIdx==0 ) continue;
82795 /* This next condition is true if data has already been loaded from
82796 ** the sqlite_stat4 table. In this case ignore stat3 data. */
82797 nCol = pIdx->nSampleCol;
82798 if( bStat3 && nCol>1 ) continue;
@@ -84144,12 +84626,14 @@
84144 */
84145 static void freeIndex(sqlite3 *db, Index *p){
84146 #ifndef SQLITE_OMIT_ANALYZE
84147 sqlite3DeleteIndexSamples(db, p);
84148 #endif
 
84149 sqlite3ExprDelete(db, p->pPartIdxWhere);
84150 sqlite3DbFree(db, p->zColAff);
 
84151 sqlite3DbFree(db, p);
84152 }
84153
84154 /*
84155 ** For the index called zIdxName which is found in the database iDb,
@@ -84403,12 +84887,11 @@
84403 ** writing. The table is opened using cursor 0.
84404 */
84405 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
84406 Vdbe *v = sqlite3GetVdbe(p);
84407 sqlite3TableLock(p, iDb, MASTER_ROOT, 1, SCHEMA_TABLE(iDb));
84408 sqlite3VdbeAddOp3(v, OP_OpenWrite, 0, MASTER_ROOT, iDb);
84409 sqlite3VdbeChangeP4(v, -1, (char *)5, P4_INT32); /* 5 column table */
84410 if( p->nTab==0 ){
84411 p->nTab = 1;
84412 }
84413 }
84414
@@ -84508,10 +84991,31 @@
84508 sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s", zName);
84509 return SQLITE_ERROR;
84510 }
84511 return SQLITE_OK;
84512 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84513
84514 /*
84515 ** Begin constructing a new table representation in memory. This is
84516 ** the first of several action routines that get called in response
84517 ** to a CREATE TABLE statement. In particular, this routine is called
@@ -84708,11 +85212,11 @@
84708 if( isView || isVirtual ){
84709 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
84710 }else
84711 #endif
84712 {
84713 sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
84714 }
84715 sqlite3OpenMasterTable(pParse, iDb);
84716 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
84717 sqlite3VdbeAddOp2(v, OP_Null, 0, reg3);
84718 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
@@ -84976,10 +85480,11 @@
84976 int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */
84977 ){
84978 Table *pTab = pParse->pNewTable;
84979 char *zType = 0;
84980 int iCol = -1, i;
 
84981 if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
84982 if( pTab->tabFlags & TF_HasPrimaryKey ){
84983 sqlite3ErrorMsg(pParse,
84984 "table \"%s\" has more than one primary key", pTab->zName);
84985 goto primary_key_exit;
@@ -84986,43 +85491,47 @@
84986 }
84987 pTab->tabFlags |= TF_HasPrimaryKey;
84988 if( pList==0 ){
84989 iCol = pTab->nCol - 1;
84990 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
 
 
84991 }else{
84992 for(i=0; i<pList->nExpr; i++){
 
84993 for(iCol=0; iCol<pTab->nCol; iCol++){
84994 if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
 
 
84995 break;
84996 }
84997 }
84998 if( iCol<pTab->nCol ){
84999 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
85000 }
85001 }
85002 if( pList->nExpr>1 ) iCol = -1;
85003 }
85004 if( iCol>=0 && iCol<pTab->nCol ){
85005 zType = pTab->aCol[iCol].zType;
85006 }
85007 if( zType && sqlite3StrICmp(zType, "INTEGER")==0
85008 && sortOrder==SQLITE_SO_ASC ){
85009 pTab->iPKey = iCol;
85010 pTab->keyConf = (u8)onError;
85011 assert( autoInc==0 || autoInc==1 );
85012 pTab->tabFlags |= autoInc*TF_Autoincrement;
 
85013 }else if( autoInc ){
85014 #ifndef SQLITE_OMIT_AUTOINCREMENT
85015 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
85016 "INTEGER PRIMARY KEY");
85017 #endif
85018 }else{
 
85019 Index *p;
 
85020 p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
85021 0, sortOrder, 0);
85022 if( p ){
85023 p->autoIndex = 2;
 
85024 }
85025 pList = 0;
85026 }
85027
85028 primary_key_exit:
@@ -85075,11 +85584,11 @@
85075 /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
85076 ** then an index may have been created on this column before the
85077 ** collation type was added. Correct this if it is the case.
85078 */
85079 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
85080 assert( pIdx->nColumn==1 );
85081 if( pIdx->aiColumn[0]==i ){
85082 pIdx->azColl[0] = p->aCol[i].zColl;
85083 }
85084 }
85085 }else{
@@ -85266,10 +85775,35 @@
85266 assert( k<=n );
85267 }
85268 sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd);
85269 return zStmt;
85270 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85271
85272 /*
85273 ** Estimate the total row width for a table.
85274 */
85275 static void estimateTableWidth(Table *pTab){
@@ -85285,19 +85819,151 @@
85285
85286 /*
85287 ** Estimate the average size of a row for an index.
85288 */
85289 static void estimateIndexWidth(Index *pIdx){
85290 unsigned wIndex = 1;
85291 int i;
85292 const Column *aCol = pIdx->pTable->aCol;
85293 for(i=0; i<pIdx->nColumn; i++){
85294 assert( pIdx->aiColumn[i]>=0 && pIdx->aiColumn[i]<pIdx->pTable->nCol );
85295 wIndex += aCol[pIdx->aiColumn[i]].szEst;
 
85296 }
85297 pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
85298 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85299
85300 /*
85301 ** This routine is called to report the final ")" that terminates
85302 ** a CREATE TABLE statement.
85303 **
@@ -85318,11 +85984,12 @@
85318 ** the new table will match the result set of the SELECT.
85319 */
85320 SQLITE_PRIVATE void sqlite3EndTable(
85321 Parse *pParse, /* Parse context */
85322 Token *pCons, /* The ',' token after the last column defn. */
85323 Token *pEnd, /* The final ')' token in the CREATE TABLE */
 
85324 Select *pSelect /* Select from a "CREATE ... AS SELECT" */
85325 ){
85326 Table *p; /* The new table */
85327 sqlite3 *db = pParse->db; /* The database connection */
85328 int iDb; /* Database in which the table lives */
@@ -85333,10 +86000,35 @@
85333 }
85334 p = pParse->pNewTable;
85335 if( p==0 ) return;
85336
85337 assert( !db->init.busy || !pSelect );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85338
85339 iDb = sqlite3SchemaToIndex(db, p->pSchema);
85340
85341 #ifndef SQLITE_OMIT_CHECK
85342 /* Resolve names in all CHECK constraint expressions.
@@ -85350,20 +86042,10 @@
85350 estimateTableWidth(p);
85351 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
85352 estimateIndexWidth(pIdx);
85353 }
85354
85355 /* If the db->init.busy is 1 it means we are reading the SQL off the
85356 ** "sqlite_master" or "sqlite_temp_master" table on the disk.
85357 ** So do not write to the disk again. Extract the root page number
85358 ** for the table from the db->init.newTnum field. (The page number
85359 ** should have been put there by the sqliteOpenCb routine.)
85360 */
85361 if( db->init.busy ){
85362 p->tnum = db->init.newTnum;
85363 }
85364
85365 /* If not initializing, then create a record for the new table
85366 ** in the SQLITE_MASTER table of the database.
85367 **
85368 ** If this is a TEMPORARY table, write the entry into the auxiliary
85369 ** file instead of into the main database file.
@@ -85433,11 +86115,13 @@
85433
85434 /* Compute the complete text of the CREATE statement */
85435 if( pSelect ){
85436 zStmt = createTableStmt(db, p);
85437 }else{
85438 n = (int)(pEnd->z - pParse->sNameToken.z) + 1;
 
 
85439 zStmt = sqlite3MPrintf(db,
85440 "CREATE %s %.*s", zType2, n, pParse->sNameToken.z
85441 );
85442 }
85443
@@ -85476,11 +86160,11 @@
85476 }
85477 #endif
85478
85479 /* Reparse everything to update our internal data structures */
85480 sqlite3VdbeAddParseSchemaOp(v, iDb,
85481 sqlite3MPrintf(db, "tbl_name='%q'", p->zName));
85482 }
85483
85484
85485 /* Add the table to the in-memory representation of the database.
85486 */
@@ -85581,11 +86265,11 @@
85581 while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
85582 sEnd.z = &z[n-1];
85583 sEnd.n = 1;
85584
85585 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
85586 sqlite3EndTable(pParse, 0, &sEnd, 0);
85587 return;
85588 }
85589 #endif /* SQLITE_OMIT_VIEW */
85590
85591 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -86036,12 +86720,12 @@
86036 /*
86037 ** This routine is called to create a new foreign key on the table
86038 ** currently under construction. pFromCol determines which columns
86039 ** in the current table point to the foreign key. If pFromCol==0 then
86040 ** connect the key to the last column inserted. pTo is the name of
86041 ** the table referred to. pToCol is a list of tables in the other
86042 ** pTo table that the foreign key points to. flags contains all
86043 ** information about the conflict resolution algorithms specified
86044 ** in the ON DELETE, ON UPDATE and ON INSERT clauses.
86045 **
86046 ** An FKey structure is created and added to the table currently
86047 ** under construction in the pParse->pNewTable field.
@@ -86220,41 +86904,43 @@
86220 if( v==0 ) return;
86221 if( memRootPage>=0 ){
86222 tnum = memRootPage;
86223 }else{
86224 tnum = pIndex->tnum;
86225 sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
86226 }
86227 pKey = sqlite3IndexKeyinfo(pParse, pIndex);
86228 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86229 (char *)pKey, P4_KEYINFO_HANDOFF);
86230 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86231
86232 /* Open the sorter cursor if we are to use one. */
86233 iSorter = pParse->nTab++;
86234 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
 
86235
86236 /* Open the table. Loop through all rows of the table, inserting index
86237 ** records into the sorter. */
86238 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86239 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
86240 regRecord = sqlite3GetTempReg(pParse);
86241
86242 sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1, &iPartIdxLabel);
86243 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
86244 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86245 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
86246 sqlite3VdbeJumpHere(v, addr1);
 
 
 
 
 
86247 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
86248 if( pIndex->onError!=OE_None ){
 
86249 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
86250 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
86251 addr2 = sqlite3VdbeCurrentAddr(v);
86252 sqlite3VdbeAddOp3(v, OP_SorterCompare, iSorter, j2, regRecord);
86253 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
86254 OE_Abort, "indexed columns are not unique", P4_STATIC
86255 );
86256 }else{
86257 addr2 = sqlite3VdbeCurrentAddr(v);
86258 }
86259 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
86260 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
@@ -86265,10 +86951,45 @@
86265
86266 sqlite3VdbeAddOp1(v, OP_Close, iTab);
86267 sqlite3VdbeAddOp1(v, OP_Close, iIdx);
86268 sqlite3VdbeAddOp1(v, OP_Close, iSorter);
86269 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86270
86271 /*
86272 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
86273 ** and pTblList is the name of the table that is to be indexed. Both will
86274 ** be NULL for a primary key or an index that is created to satisfy a
@@ -86300,22 +87021,22 @@
86300 Table *pTab = 0; /* Table to be indexed */
86301 Index *pIndex = 0; /* The index to be created */
86302 char *zName = 0; /* Name of the index */
86303 int nName; /* Number of characters in zName */
86304 int i, j;
86305 Token nullId; /* Fake token for an empty ID list */
86306 DbFixer sFix; /* For assigning database names to pTable */
86307 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
86308 sqlite3 *db = pParse->db;
86309 Db *pDb; /* The specific table containing the indexed database */
86310 int iDb; /* Index of the database that is being written */
86311 Token *pName = 0; /* Unqualified name of the index to create */
86312 struct ExprList_item *pListItem; /* For looping over pList */
86313 const Column *pTabCol; /* A column in the table */
86314 int nCol; /* Number of columns */
86315 int nExtra = 0; /* Space allocated for zExtra[] */
 
86316 char *zExtra; /* Extra space after the Index object */
 
86317
86318 assert( pParse->nErr==0 ); /* Never called with prior errors */
86319 if( db->mallocFailed || IN_DECLARE_VTAB ){
86320 goto exit_create_index;
86321 }
@@ -86363,10 +87084,11 @@
86363 sqlite3ErrorMsg(pParse,
86364 "cannot create a TEMP index on non-TEMP table \"%s\"",
86365 pTab->zName);
86366 goto exit_create_index;
86367 }
 
86368 }else{
86369 assert( pName==0 );
86370 assert( pStart==0 );
86371 pTab = pParse->pNewTable;
86372 if( !pTab ) goto exit_create_index;
@@ -86458,15 +87180,14 @@
86458 /* If pList==0, it means this routine was called to make a primary
86459 ** key out of the last column added to the table under construction.
86460 ** So create a fake list to simulate this.
86461 */
86462 if( pList==0 ){
86463 nullId.z = pTab->aCol[pTab->nCol-1].zName;
86464 nullId.n = sqlite3Strlen30((char*)nullId.z);
86465 pList = sqlite3ExprListAppend(pParse, 0, 0);
86466 if( pList==0 ) goto exit_create_index;
86467 sqlite3ExprListSetName(pParse, pList, &nullId, 0);
 
86468 pList->a[0].sortOrder = (u8)sortOrder;
86469 }
86470
86471 /* Figure out how many bytes of space are required to store explicitly
86472 ** specified collation sequence names.
@@ -86481,40 +87202,27 @@
86481
86482 /*
86483 ** Allocate the index structure.
86484 */
86485 nName = sqlite3Strlen30(zName);
86486 nCol = pList->nExpr;
86487 pIndex = sqlite3DbMallocZero(db,
86488 ROUND8(sizeof(Index)) + /* Index structure */
86489 ROUND8(sizeof(tRowcnt)*(nCol+1)) + /* Index.aiRowEst */
86490 sizeof(char *)*nCol + /* Index.azColl */
86491 sizeof(int)*nCol + /* Index.aiColumn */
86492 sizeof(u8)*nCol + /* Index.aSortOrder */
86493 nName + 1 + /* Index.zName */
86494 nExtra /* Collation sequence names */
86495 );
86496 if( db->mallocFailed ){
86497 goto exit_create_index;
86498 }
86499 zExtra = (char*)pIndex;
86500 pIndex->aiRowEst = (tRowcnt*)&zExtra[ROUND8(sizeof(Index))];
86501 pIndex->azColl = (char**)
86502 ((char*)pIndex->aiRowEst + ROUND8(sizeof(tRowcnt)*nCol+1));
86503 assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowEst) );
86504 assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
86505 pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
86506 pIndex->aSortOrder = (u8 *)(&pIndex->aiColumn[nCol]);
86507 pIndex->zName = (char *)(&pIndex->aSortOrder[nCol]);
86508 zExtra = (char *)(&pIndex->zName[nName+1]);
86509 memcpy(pIndex->zName, zName, nName+1);
86510 pIndex->pTable = pTab;
86511 pIndex->nColumn = pList->nExpr;
86512 pIndex->onError = (u8)onError;
86513 pIndex->uniqNotNull = onError==OE_Abort;
86514 pIndex->autoIndex = (u8)(pName==0);
86515 pIndex->pSchema = db->aDb[iDb].pSchema;
 
86516 if( pPIWhere ){
86517 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
86518 pIndex->pPartIdxWhere = pPIWhere;
86519 pPIWhere = 0;
86520 }
@@ -86550,11 +87258,12 @@
86550 sqlite3ErrorMsg(pParse, "table %s has no column named %s",
86551 pTab->zName, zColName);
86552 pParse->checkSchema = 1;
86553 goto exit_create_index;
86554 }
86555 pIndex->aiColumn[i] = j;
 
86556 if( pListItem->pExpr ){
86557 int nColl;
86558 assert( pListItem->pExpr->op==TK_COLLATE );
86559 zColl = pListItem->pExpr->u.zToken;
86560 nColl = sqlite3Strlen30(zColl) + 1;
@@ -86573,10 +87282,27 @@
86573 pIndex->azColl[i] = zColl;
86574 requestedSortOrder = pListItem->sortOrder & sortOrderMask;
86575 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
86576 if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
86577 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86578 sqlite3DefaultRowEst(pIndex);
86579 if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
86580
86581 if( pTab==pParse->pNewTable ){
86582 /* This routine has been called to create an automatic index as a
@@ -86605,20 +87331,20 @@
86605 int k;
86606 assert( pIdx->onError!=OE_None );
86607 assert( pIdx->autoIndex );
86608 assert( pIndex->onError!=OE_None );
86609
86610 if( pIdx->nColumn!=pIndex->nColumn ) continue;
86611 for(k=0; k<pIdx->nColumn; k++){
86612 const char *z1;
86613 const char *z2;
86614 if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
86615 z1 = pIdx->azColl[k];
86616 z2 = pIndex->azColl[k];
86617 if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
86618 }
86619 if( k==pIdx->nColumn ){
86620 if( pIdx->onError!=pIndex->onError ){
86621 /* This constraint creates the same index as a previous
86622 ** constraint specified somewhere in the CREATE TABLE statement.
86623 ** However the ON CONFLICT clauses are different. If both this
86624 ** constraint and the previous equivalent constraint have explicit
@@ -86656,26 +87382,24 @@
86656 if( pTblName!=0 ){
86657 pIndex->tnum = db->init.newTnum;
86658 }
86659 }
86660
86661 /* If the db->init.busy is 0 then create the index on disk. This
86662 ** involves writing the index into the master table and filling in the
86663 ** index with the current table contents.
86664 **
86665 ** The db->init.busy is 0 when the user first enters a CREATE INDEX
86666 ** command. db->init.busy is 1 when a database is opened and
86667 ** CREATE INDEX statements are read out of the master table. In
86668 ** the latter case the index already exists on disk, which is why
86669 ** we don't want to recreate it.
86670 **
86671 ** If pTblName==0 it means this index is generated as a primary key
86672 ** or UNIQUE constraint of a CREATE TABLE statement. Since the table
86673 ** has just been created, it contains no data and the index initialization
86674 ** step can be skipped.
86675 */
86676 else if( pParse->nErr==0 ){
86677 Vdbe *v;
86678 char *zStmt;
86679 int iMem = ++pParse->nMem;
86680
86681 v = sqlite3GetVdbe(pParse);
@@ -86783,16 +87507,16 @@
86783 tRowcnt n;
86784 assert( a!=0 );
86785 a[0] = pIdx->pTable->nRowEst;
86786 if( a[0]<10 ) a[0] = 10;
86787 n = 10;
86788 for(i=1; i<=pIdx->nColumn; i++){
86789 a[i] = n;
86790 if( n>5 ) n--;
86791 }
86792 if( pIdx->onError!=OE_None ){
86793 a[pIdx->nColumn] = 1;
86794 }
86795 }
86796
86797 /*
86798 ** This routine will drop an existing named index. This routine
@@ -87476,18 +88200,71 @@
87476 SQLITE_PRIVATE void sqlite3HaltConstraint(
87477 Parse *pParse, /* Parsing context */
87478 int errCode, /* extended error code */
87479 int onError, /* Constraint type */
87480 char *p4, /* Error message */
87481 int p4type /* P4_STATIC or P4_TRANSIENT */
 
87482 ){
87483 Vdbe *v = sqlite3GetVdbe(pParse);
87484 assert( (errCode&0xff)==SQLITE_CONSTRAINT );
87485 if( onError==OE_Abort ){
87486 sqlite3MayAbort(pParse);
87487 }
87488 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87489 }
87490
87491 /*
87492 ** Check to see if pIndex uses the collating sequence pColl. Return
87493 ** true if it does and false if it does not.
@@ -87496,12 +88273,12 @@
87496 static int collationMatch(const char *zColl, Index *pIndex){
87497 int i;
87498 assert( zColl!=0 );
87499 for(i=0; i<pIndex->nColumn; i++){
87500 const char *z = pIndex->azColl[i];
87501 assert( z!=0 );
87502 if( 0==sqlite3StrICmp(z, zColl) ){
87503 return 1;
87504 }
87505 }
87506 return 0;
87507 }
@@ -87616,39 +88393,53 @@
87616 sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
87617 }
87618 #endif
87619
87620 /*
87621 ** Return a dynamicly allocated KeyInfo structure that can be used
87622 ** with OP_OpenRead or OP_OpenWrite to access database index pIdx.
87623 **
87624 ** If successful, a pointer to the new structure is returned. In this case
87625 ** the caller is responsible for calling sqlite3DbFree(db, ) on the returned
87626 ** pointer. If an error occurs (out of memory or missing collation
87627 ** sequence), NULL is returned and the state of pParse updated to reflect
87628 ** the error.
87629 */
87630 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){
87631 int i;
87632 int nCol = pIdx->nColumn;
87633 KeyInfo *pKey;
87634
87635 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol);
87636 if( pKey ){
87637 for(i=0; i<nCol; i++){
87638 char *zColl = pIdx->azColl[i];
87639 assert( zColl );
87640 pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
87641 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
87642 }
87643 }
87644
87645 if( pParse->nErr ){
87646 sqlite3DbFree(pParse->db, pKey);
87647 pKey = 0;
87648 }
87649 return pKey;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87650 }
87651
87652 /************** End of build.c ***********************************************/
87653 /************** Begin file callback.c ****************************************/
87654 /*
@@ -88264,11 +89055,11 @@
88264 SrcList *pSrc, /* the FROM clause -- which tables to scan */
88265 Expr *pWhere, /* The WHERE clause. May be null */
88266 ExprList *pOrderBy, /* The ORDER BY clause. May be null */
88267 Expr *pLimit, /* The LIMIT clause. May be null */
88268 Expr *pOffset, /* The OFFSET clause. May be null */
88269 char *zStmtType /* Either DELETE or UPDATE. For error messages. */
88270 ){
88271 Expr *pWhereRowid = NULL; /* WHERE rowid .. */
88272 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
88273 Expr *pSelectRowid = NULL; /* SELECT rowid ... */
88274 ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */
@@ -88339,11 +89130,12 @@
88339 sqlite3ExprListDelete(pParse->db, pOrderBy);
88340 sqlite3ExprDelete(pParse->db, pLimit);
88341 sqlite3ExprDelete(pParse->db, pOffset);
88342 return 0;
88343 }
88344 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
 
88345
88346 /*
88347 ** Generate code for a DELETE FROM statement.
88348 **
88349 ** DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
@@ -88360,11 +89152,13 @@
88360 const char *zDb; /* Name of database holding pTab */
88361 int end, addr = 0; /* A couple addresses of generated code */
88362 int i; /* Loop counter */
88363 WhereInfo *pWInfo; /* Information about the WHERE clause */
88364 Index *pIdx; /* For looping over indices of the table */
88365 int iCur; /* VDBE Cursor number for pTab */
 
 
88366 sqlite3 *db; /* Main database structure */
88367 AuthContext sContext; /* Authorization context */
88368 NameContext sNC; /* Name context to resolve expressions in */
88369 int iDb; /* Database number */
88370 int memCnt = -1; /* Memory cell used for change counting */
@@ -88425,11 +89219,11 @@
88425 assert(!isView || pTrigger);
88426
88427 /* Assign cursor number to the table and all its indices.
88428 */
88429 assert( pTabList->nSrc==1 );
88430 iCur = pTabList->a[0].iCursor = pParse->nTab++;
88431 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
88432 pParse->nTab++;
88433 }
88434
88435 /* Start the view context
@@ -88450,11 +89244,12 @@
88450 /* If we are trying to delete from a view, realize that view into
88451 ** a ephemeral table.
88452 */
88453 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
88454 if( isView ){
88455 sqlite3MaterializeView(pParse, pTab, pWhere, iCur);
 
88456 }
88457 #endif
88458
88459 /* Resolve the column names in the WHERE clause.
88460 */
@@ -88481,22 +89276,78 @@
88481 if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab)
88482 && 0==sqlite3FkRequired(pParse, pTab, 0, 0)
88483 ){
88484 assert( !isView );
88485 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
88486 sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
88487 pTab->zName, P4_STATIC);
 
 
88488 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
88489 assert( pIdx->pSchema==pTab->pSchema );
88490 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
88491 }
88492 }else
88493 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
88494 /* The usual case: There is a WHERE clause so we have to scan through
88495 ** the table and pick which records to delete.
88496 */
88497 {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88498 int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
88499 int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
88500 int regRowid; /* Actual register containing rowids */
88501
88502 /* Collect rowids of every row to be deleted.
@@ -88504,11 +89355,11 @@
88504 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
88505 pWInfo = sqlite3WhereBegin(
88506 pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
88507 );
88508 if( pWInfo==0 ) goto delete_from_cleanup;
88509 regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0);
88510 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
88511 if( db->flags & SQLITE_CountRows ){
88512 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
88513 }
88514 sqlite3WhereEnd(pWInfo);
@@ -88521,11 +89372,14 @@
88521 /* Unless this is a view, open cursors for the table we are
88522 ** deleting from and all its indices. If this is a view, then the
88523 ** only effect this statement has is to fire the INSTEAD OF
88524 ** triggers. */
88525 if( !isView ){
88526 sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite);
 
 
 
88527 }
88528
88529 addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);
88530
88531 /* Delete the row */
@@ -88538,23 +89392,24 @@
88538 sqlite3MayAbort(pParse);
88539 }else
88540 #endif
88541 {
88542 int count = (pParse->nested==0); /* True to count changes */
88543 sqlite3GenerateRowDelete(pParse, pTab, iCur, iRowid, count, pTrigger, OE_Default);
 
88544 }
88545
88546 /* End of the delete loop */
88547 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
88548 sqlite3VdbeResolveLabel(v, end);
88549
88550 /* Close the cursors open on the table and its indexes. */
88551 if( !isView && !IsVirtual(pTab) ){
88552 for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
88553 sqlite3VdbeAddOp2(v, OP_Close, iCur + i, pIdx->tnum);
 
88554 }
88555 sqlite3VdbeAddOp1(v, OP_Close, iCur);
88556 }
88557 }
88558
88559 /* Update the sqlite_sequence table by storing the content of the
88560 ** maximum rowid counter values recorded while inserting into
@@ -88590,48 +89445,56 @@
88590 #undef pTrigger
88591 #endif
88592
88593 /*
88594 ** This routine generates VDBE code that causes a single row of a
88595 ** single table to be deleted.
 
88596 **
88597 ** The VDBE must be in a particular state when this routine is called.
88598 ** These are the requirements:
88599 **
88600 ** 1. A read/write cursor pointing to pTab, the table containing the row
88601 ** to be deleted, must be opened as cursor number $iCur.
 
 
88602 **
88603 ** 2. Read/write cursors for all indices of pTab must be open as
88604 ** cursor number base+i for the i-th index.
88605 **
88606 ** 3. The record number of the row to be deleted must be stored in
88607 ** memory cell iRowid.
88608 **
88609 ** This routine generates code to remove both the table record and all
88610 ** index entries that point to that record.
88611 */
88612 SQLITE_PRIVATE void sqlite3GenerateRowDelete(
88613 Parse *pParse, /* Parsing context */
88614 Table *pTab, /* Table containing the row to be deleted */
88615 int iCur, /* Cursor number for the table */
88616 int iRowid, /* Memory cell that contains the rowid to delete */
88617 int count, /* If non-zero, increment the row change counter */
88618 Trigger *pTrigger, /* List of triggers to (potentially) fire */
88619 int onconf /* Default ON CONFLICT policy for triggers */
 
 
 
 
 
 
88620 ){
88621 Vdbe *v = pParse->pVdbe; /* Vdbe */
88622 int iOld = 0; /* First register in OLD.* array */
88623 int iLabel; /* Label resolved to end of generated code */
 
88624
88625 /* Vdbe is guaranteed to have been allocated by this stage. */
88626 assert( v );
 
 
88627
88628 /* Seek cursor iCur to the row to delete. If this row no longer exists
88629 ** (this can happen if a trigger program has already deleted it), do
88630 ** not attempt to delete it or fire any DELETE triggers. */
88631 iLabel = sqlite3VdbeMakeLabel(v);
88632 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
 
88633
88634 /* If there are any triggers to fire, allocate a range of registers to
88635 ** use for the old.* references in the triggers. */
88636 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
88637 u32 mask; /* Mask of OLD.* columns in use */
@@ -88646,14 +89509,14 @@
88646 iOld = pParse->nMem+1;
88647 pParse->nMem += (1 + pTab->nCol);
88648
88649 /* Populate the OLD.* pseudo-table register array. These values will be
88650 ** used by any BEFORE and AFTER triggers that exist. */
88651 sqlite3VdbeAddOp2(v, OP_Copy, iRowid, iOld);
88652 for(iCol=0; iCol<pTab->nCol; iCol++){
88653 if( mask==0xffffffff || mask&(1<<iCol) ){
88654 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol, iOld+iCol+1);
88655 }
88656 }
88657
88658 /* Invoke BEFORE DELETE trigger programs. */
88659 sqlite3CodeRowTrigger(pParse, pTrigger,
@@ -88662,11 +89525,11 @@
88662
88663 /* Seek the cursor to the row to be deleted again. It may be that
88664 ** the BEFORE triggers coded above have already removed the row
88665 ** being deleted. Do not attempt to delete the row a second time, and
88666 ** do not fire AFTER triggers. */
88667 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
88668
88669 /* Do FK processing. This call checks that any FK constraints that
88670 ** refer to this table (i.e. constraints attached to other tables)
88671 ** are not violated by deleting this row. */
88672 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -88674,12 +89537,12 @@
88674
88675 /* Delete the index and table entries. Skip this step if pTab is really
88676 ** a view (in which case the only effect of the DELETE statement is to
88677 ** fire the INSTEAD OF triggers). */
88678 if( pTab->pSelect==0 ){
88679 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
88680 sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
88681 if( count ){
88682 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
88683 }
88684 }
88685
@@ -88695,53 +89558,65 @@
88695
88696 /* Jump here if the row had already been deleted before any BEFORE
88697 ** trigger programs were invoked. Or if a trigger program throws a
88698 ** RAISE(IGNORE) exception. */
88699 sqlite3VdbeResolveLabel(v, iLabel);
 
88700 }
88701
88702 /*
88703 ** This routine generates VDBE code that causes the deletion of all
88704 ** index entries associated with a single row of a single table.
88705 **
88706 ** The VDBE must be in a particular state when this routine is called.
88707 ** These are the requirements:
88708 **
88709 ** 1. A read/write cursor pointing to pTab, the table containing the row
88710 ** to be deleted, must be opened as cursor number "iCur".
 
 
88711 **
88712 ** 2. Read/write cursors for all indices of pTab must be open as
88713 ** cursor number iCur+i for the i-th index.
 
88714 **
88715 ** 3. The "iCur" cursor must be pointing to the row that is to be
88716 ** deleted.
88717 */
88718 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(
88719 Parse *pParse, /* Parsing and code generating context */
88720 Table *pTab, /* Table containing the row to be deleted */
88721 int iCur, /* Cursor number for the table */
 
88722 int *aRegIdx /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */
88723 ){
88724 int i;
88725 Index *pIdx;
88726 int r1;
88727 int iPartIdxLabel;
88728 Vdbe *v = pParse->pVdbe;
88729
88730 for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
88731 if( aRegIdx!=0 && aRegIdx[i-1]==0 ) continue;
88732 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iCur, 0, 0, &iPartIdxLabel);
88733 sqlite3VdbeAddOp3(v, OP_IdxDelete, iCur+i, r1, pIdx->nColumn+1);
 
 
 
 
 
 
 
88734 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
88735 }
88736 }
88737
88738 /*
88739 ** Generate code that will assemble an index key and put it in register
88740 ** regOut. The key with be for index pIdx which is an index on pTab.
88741 ** iCur is the index of a cursor open on the pTab table and pointing to
88742 ** the entry that needs indexing.
 
88743 **
88744 ** Return a register number which is the first in a block of
88745 ** registers that holds the elements of the index key. The
88746 ** block of registers has already been deallocated by the time
88747 ** this routine returns.
@@ -88754,56 +89629,58 @@
88754 ** sqlite3VdbeResolveLabel().
88755 */
88756 SQLITE_PRIVATE int sqlite3GenerateIndexKey(
88757 Parse *pParse, /* Parsing context */
88758 Index *pIdx, /* The index for which to generate a key */
88759 int iCur, /* Cursor number for the pIdx->pTable table */
88760 int regOut, /* Write the new index key to this register */
88761 int doMakeRec, /* Run the OP_MakeRecord instruction if true */
88762 int *piPartIdxLabel /* OUT: Jump to this label to skip partial index */
88763 ){
88764 Vdbe *v = pParse->pVdbe;
88765 int j;
88766 Table *pTab = pIdx->pTable;
88767 int regBase;
88768 int nCol;
 
88769
88770 if( piPartIdxLabel ){
88771 if( pIdx->pPartIdxWhere ){
88772 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
88773 pParse->iPartIdxTab = iCur;
88774 sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
88775 SQLITE_JUMPIFNULL);
88776 }else{
88777 *piPartIdxLabel = 0;
88778 }
88779 }
88780 nCol = pIdx->nColumn;
88781 regBase = sqlite3GetTempRange(pParse, nCol+1);
88782 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regBase+nCol);
88783 for(j=0; j<nCol; j++){
88784 int idx = pIdx->aiColumn[j];
88785 if( idx==pTab->iPKey ){
88786 sqlite3VdbeAddOp2(v, OP_SCopy, regBase+nCol, regBase+j);
 
88787 }else{
88788 sqlite3VdbeAddOp3(v, OP_Column, iCur, idx, regBase+j);
88789 sqlite3ColumnDefault(v, pTab, idx, -1);
88790 }
88791 }
88792 if( doMakeRec ){
88793 const char *zAff;
88794 if( pTab->pSelect
88795 || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
88796 ){
88797 zAff = 0;
88798 }else{
88799 zAff = sqlite3IndexAffinityStr(v, pIdx);
88800 }
88801 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);
88802 sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
88803 }
88804 sqlite3ReleaseTempRange(pParse, regBase, nCol+1);
88805 return regBase;
88806 }
88807
88808 /************** End of delete.c **********************************************/
88809 /************** Begin file func.c ********************************************/
@@ -88943,12 +89820,12 @@
88943 switch( sqlite3_value_type(argv[0]) ){
88944 case SQLITE_INTEGER: {
88945 i64 iVal = sqlite3_value_int64(argv[0]);
88946 if( iVal<0 ){
88947 if( (iVal<<1)==0 ){
88948 /* IMP: R-35460-15084 If X is the integer -9223372036854775807 then
88949 ** abs(X) throws an integer overflow error since there is no
88950 ** equivalent positive 64-bit two complement value. */
88951 sqlite3_result_error(context, "integer overflow", -1);
88952 return;
88953 }
88954 iVal = -iVal;
@@ -90755,11 +91632,11 @@
90755 if( !aiCol ) return 1;
90756 *paiCol = aiCol;
90757 }
90758
90759 for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
90760 if( pIdx->nColumn==nCol && pIdx->onError!=OE_None ){
90761 /* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
90762 ** of columns. If each indexed column corresponds to a foreign key
90763 ** column of pFKey, then this index is a winner. */
90764
90765 if( zKey==0 ){
@@ -90778,11 +91655,11 @@
90778 ** map to an explicit list of columns in table pParent. Check if this
90779 ** index matches those columns. Also, check that the index uses
90780 ** the default collation sequences for each column. */
90781 int i, j;
90782 for(i=0; i<nCol; i++){
90783 int iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
90784 char *zDfltColl; /* Def. collation for column */
90785 char *zIdxCol; /* Name of indexed column */
90786
90787 /* If the index uses a collation sequence that is different from
90788 ** the default collation sequence for the column, this index is
@@ -90909,14 +91786,13 @@
90909 sqlite3ReleaseTempReg(pParse, regTemp);
90910 }else{
90911 int nCol = pFKey->nCol;
90912 int regTemp = sqlite3GetTempRange(pParse, nCol);
90913 int regRec = sqlite3GetTempReg(pParse);
90914 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
90915
90916 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
90917 sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
90918 for(i=0; i<nCol; i++){
90919 sqlite3VdbeAddOp2(v, OP_Copy, aiCol[i]+1+regData, regTemp+i);
90920 }
90921
90922 /* If the parent table is the same as the child table, and we are about
@@ -90962,12 +91838,11 @@
90962 ** one row into the table, raise a constraint immediately instead of
90963 ** incrementing a counter. This is necessary as the VM code is being
90964 ** generated for will not open a statement transaction. */
90965 assert( nIncr==1 );
90966 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
90967 OE_Abort, "foreign key constraint failed", P4_STATIC
90968 );
90969 }else{
90970 if( nIncr>0 && pFKey->isDeferred==0 ){
90971 sqlite3ParseToplevel(pParse)->mayAbort = 1;
90972 }
90973 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
@@ -90975,10 +91850,66 @@
90975
90976 sqlite3VdbeResolveLabel(v, iOk);
90977 sqlite3VdbeAddOp1(v, OP_Close, iCur);
90978 }
90979
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90980 /*
90981 ** This function is called to generate code executed when a row is deleted
90982 ** from the parent table of foreign key constraint pFKey and, if pFKey is
90983 ** deferred, when a row is inserted into the same table. When generating
90984 ** code for an SQL UPDATE operation, this function may be called twice -
@@ -90990,31 +91921,31 @@
90990 **
90991 ** Operation | FK type | Action taken
90992 ** --------------------------------------------------------------------------
90993 ** DELETE immediate Increment the "immediate constraint counter".
90994 ** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
90995 ** throw a "foreign key constraint failed" exception.
90996 **
90997 ** INSERT immediate Decrement the "immediate constraint counter".
90998 **
90999 ** DELETE deferred Increment the "deferred constraint counter".
91000 ** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
91001 ** throw a "foreign key constraint failed" exception.
91002 **
91003 ** INSERT deferred Decrement the "deferred constraint counter".
91004 **
91005 ** These operations are identified in the comment at the top of this file
91006 ** (fkey.c) as "I.2" and "D.2".
91007 */
91008 static void fkScanChildren(
91009 Parse *pParse, /* Parse context */
91010 SrcList *pSrc, /* SrcList containing the table to scan */
91011 Table *pTab,
91012 Index *pIdx, /* Foreign key index */
91013 FKey *pFKey, /* Foreign key relationship */
91014 int *aiCol, /* Map from pIdx cols to child table cols */
91015 int regData, /* Referenced table data starts here */
91016 int nIncr /* Amount to increment deferred counter by */
91017 ){
91018 sqlite3 *db = pParse->db; /* Database handle */
91019 int i; /* Iterator variable */
91020 Expr *pWhere = 0; /* WHERE clause to scan with */
@@ -91021,11 +91952,13 @@
91021 NameContext sNameContext; /* Context used to resolve WHERE clause */
91022 WhereInfo *pWInfo; /* Context used by sqlite3WhereXXX() */
91023 int iFkIfZero = 0; /* Address of OP_FkIfZero */
91024 Vdbe *v = sqlite3GetVdbe(pParse);
91025
91026 assert( !pIdx || pIdx->pTable==pTab );
 
 
91027
91028 if( nIncr<0 ){
91029 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
91030 }
91031
@@ -91039,59 +91972,55 @@
91039 */
91040 for(i=0; i<pFKey->nCol; i++){
91041 Expr *pLeft; /* Value from parent table row */
91042 Expr *pRight; /* Column ref to child table */
91043 Expr *pEq; /* Expression (pLeft = pRight) */
91044 int iCol; /* Index of column in child table */
91045 const char *zCol; /* Name of column in child table */
91046
91047 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
91048 if( pLeft ){
91049 /* Set the collation sequence and affinity of the LHS of each TK_EQ
91050 ** expression to the parent key column defaults. */
91051 if( pIdx ){
91052 Column *pCol;
91053 const char *zColl;
91054 iCol = pIdx->aiColumn[i];
91055 pCol = &pTab->aCol[iCol];
91056 if( pTab->iPKey==iCol ) iCol = -1;
91057 pLeft->iTable = regData+iCol+1;
91058 pLeft->affinity = pCol->affinity;
91059 zColl = pCol->zColl;
91060 if( zColl==0 ) zColl = db->pDfltColl->zName;
91061 pLeft = sqlite3ExprAddCollateString(pParse, pLeft, zColl);
91062 }else{
91063 pLeft->iTable = regData;
91064 pLeft->affinity = SQLITE_AFF_INTEGER;
91065 }
91066 }
91067 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
91068 assert( iCol>=0 );
91069 zCol = pFKey->pFrom->aCol[iCol].zName;
91070 pRight = sqlite3Expr(db, TK_ID, zCol);
91071 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
91072 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
91073 }
91074
91075 /* If the child table is the same as the parent table, and this scan
91076 ** is taking place as part of a DELETE operation (operation D.2), omit the
91077 ** row being deleted from the scan by adding ($rowid != rowid) to the WHERE
91078 ** clause, where $rowid is the rowid of the row being deleted. */
 
 
 
 
 
 
 
91079 if( pTab==pFKey->pFrom && nIncr>0 ){
91080 Expr *pEq; /* Expression (pLeft = pRight) */
91081 Expr *pLeft; /* Value from parent table row */
91082 Expr *pRight; /* Column ref to child table */
91083 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
91084 pRight = sqlite3Expr(db, TK_COLUMN, 0);
91085 if( pLeft && pRight ){
91086 pLeft->iTable = regData;
91087 pLeft->affinity = SQLITE_AFF_INTEGER;
91088 pRight->iTable = pSrc->a[0].iCursor;
91089 pRight->iColumn = -1;
91090 }
91091 pEq = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
91092 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
 
 
 
 
 
 
 
91093 }
91094
91095 /* Resolve the references in the WHERE clause. */
91096 memset(&sNameContext, 0, sizeof(NameContext));
91097 sNameContext.pSrcList = pSrc;
@@ -91117,12 +92046,12 @@
91117 sqlite3VdbeJumpHere(v, iFkIfZero);
91118 }
91119 }
91120
91121 /*
91122 ** This function returns a pointer to the head of a linked list of FK
91123 ** constraints for which table pTab is the parent table. For example,
91124 ** given the following schema:
91125 **
91126 ** CREATE TABLE t1(a PRIMARY KEY);
91127 ** CREATE TABLE t2(b REFERENCES t1(a);
91128 **
@@ -91209,12 +92138,11 @@
91209 ** constraints are violated.
91210 */
91211 if( (db->flags & SQLITE_DeferFKs)==0 ){
91212 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
91213 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
91214 OE_Abort, "foreign key constraint failed", P4_STATIC
91215 );
91216 }
91217
91218 if( iSkip ){
91219 sqlite3VdbeResolveLabel(v, iSkip);
91220 }
@@ -91420,11 +92348,12 @@
91420 }
91421
91422 sqlite3DbFree(db, aiFree);
91423 }
91424
91425 /* Loop through all the foreign key constraints that refer to this table */
 
91426 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
91427 Index *pIdx = 0; /* Foreign key index for pFKey */
91428 SrcList *pSrc;
91429 int *aiCol = 0;
91430
@@ -91445,13 +92374,12 @@
91445 if( !isIgnoreErrors || db->mallocFailed ) return;
91446 continue;
91447 }
91448 assert( aiCol || pFKey->nCol==1 );
91449
91450 /* Create a SrcList structure containing a single table (the table
91451 ** the foreign key that refers to this table is attached to). This
91452 ** is required for the sqlite3WhereXXX() interface. */
91453 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
91454 if( pSrc ){
91455 struct SrcList_item *pItem = pSrc->a;
91456 pItem->pTab = pFKey->pFrom;
91457 pItem->zName = pFKey->pFrom->zName;
@@ -91496,11 +92424,11 @@
91496 }
91497 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
91498 Index *pIdx = 0;
91499 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
91500 if( pIdx ){
91501 for(i=0; i<pIdx->nColumn; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]);
91502 }
91503 }
91504 }
91505 return mask;
91506 }
@@ -91688,11 +92616,11 @@
91688 Token tFrom;
91689 Expr *pRaise;
91690
91691 tFrom.z = zFrom;
91692 tFrom.n = nFrom;
91693 pRaise = sqlite3Expr(db, TK_RAISE, "foreign key constraint failed");
91694 if( pRaise ){
91695 pRaise->affinity = OE_Abort;
91696 }
91697 pSelect = sqlite3SelectNew(pParse,
91698 sqlite3ExprListAppend(pParse, 0, pRaise),
@@ -91852,27 +92780,42 @@
91852 ** This file contains C code routines that are called by the parser
91853 ** to handle INSERT statements in SQLite.
91854 */
91855
91856 /*
91857 ** Generate code that will open a table for reading.
 
 
 
 
 
 
91858 */
91859 SQLITE_PRIVATE void sqlite3OpenTable(
91860 Parse *p, /* Generate code into this VDBE */
91861 int iCur, /* The cursor number of the table */
91862 int iDb, /* The database index in sqlite3.aDb[] */
91863 Table *pTab, /* The table to be opened */
91864 int opcode /* OP_OpenRead or OP_OpenWrite */
91865 ){
91866 Vdbe *v;
91867 assert( !IsVirtual(pTab) );
91868 v = sqlite3GetVdbe(p);
91869 assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
91870 sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName);
91871 sqlite3VdbeAddOp3(v, opcode, iCur, pTab->tnum, iDb);
91872 sqlite3VdbeChangeP4(v, -1, SQLITE_INT_TO_PTR(pTab->nCol), P4_INT32);
91873 VdbeComment((v, "%s", pTab->zName));
 
 
 
 
 
 
 
 
 
91874 }
91875
91876 /*
91877 ** Return a pointer to the column affinity string associated with index
91878 ** pIdx. A column affinity string has one character for each column in
@@ -91904,19 +92847,19 @@
91904 ** up.
91905 */
91906 int n;
91907 Table *pTab = pIdx->pTable;
91908 sqlite3 *db = sqlite3VdbeDb(v);
91909 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+2);
91910 if( !pIdx->zColAff ){
91911 db->mallocFailed = 1;
91912 return 0;
91913 }
91914 for(n=0; n<pIdx->nColumn; n++){
91915 pIdx->zColAff[n] = pTab->aCol[pIdx->aiColumn[n]].affinity;
 
91916 }
91917 pIdx->zColAff[n++] = SQLITE_AFF_INTEGER;
91918 pIdx->zColAff[n] = 0;
91919 }
91920
91921 return pIdx->zColAff;
91922 }
@@ -92258,11 +93201,11 @@
92258 int onError, /* How to handle constraint errors */
92259 int iDbDest /* The database of pDest */
92260 );
92261
92262 /*
92263 ** This routine is call to handle SQL of the following forms:
92264 **
92265 ** insert into TABLE (IDLIST) values(EXPRLIST)
92266 ** insert into TABLE (IDLIST) select
92267 **
92268 ** The IDLIST following the table name is always optional. If omitted,
@@ -92273,16 +93216,16 @@
92273 ** statement above, and pSelect is NULL. For the second form, pList is
92274 ** NULL and pSelect is a pointer to the select statement used to generate
92275 ** data for the insert.
92276 **
92277 ** The code generated follows one of four templates. For a simple
92278 ** select with data coming from a VALUES clause, the code executes
92279 ** once straight down through. Pseudo-code follows (we call this
92280 ** the "1st template"):
92281 **
92282 ** open write cursor to <table> and its indices
92283 ** puts VALUES clause expressions onto the stack
92284 ** write the resulting record into <table>
92285 ** cleanup
92286 **
92287 ** The three remaining templates assume the statement is of the form
92288 **
@@ -92376,12 +93319,13 @@
92376 int i, j, idx; /* Loop counters */
92377 Vdbe *v; /* Generate code into this virtual machine */
92378 Index *pIdx; /* For looping over indices of the table */
92379 int nColumn; /* Number of columns in the data */
92380 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
92381 int baseCur = 0; /* VDBE Cursor number for pTab */
92382 int keyColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
 
92383 int endOfLoop; /* Label for the end of the insertion loop */
92384 int useTempTable = 0; /* Store SELECT results in intermediate table */
92385 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
92386 int addrInsTop = 0; /* Jump to label "D" */
92387 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
@@ -92388,10 +93332,11 @@
92388 int addrSelect = 0; /* Address of coroutine that implements the SELECT */
92389 SelectDest dest; /* Destination for SELECT on rhs of INSERT */
92390 int iDb; /* Index of database holding TABLE */
92391 Db *pDb; /* The database containing table being inserted into */
92392 int appendFlag = 0; /* True if the insert is likely to be an append */
 
92393
92394 /* Register allocations */
92395 int regFromSelect = 0;/* Base register for data coming from SELECT */
92396 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
92397 int regRowCount = 0; /* Memory cell used for the row counter */
@@ -92427,10 +93372,11 @@
92427 pDb = &db->aDb[iDb];
92428 zDb = pDb->zName;
92429 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
92430 goto insert_cleanup;
92431 }
 
92432
92433 /* Figure out if we have any triggers and if the table being
92434 ** inserted into is a view
92435 */
92436 #ifndef SQLITE_OMIT_TRIGGER
@@ -92446,20 +93392,17 @@
92446 # define isView 0
92447 #endif
92448 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
92449
92450 /* If pTab is really a view, make sure it has been initialized.
92451 ** ViewGetColumnNames() is a no-op if pTab is not a view (or virtual
92452 ** module table).
92453 */
92454 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
92455 goto insert_cleanup;
92456 }
92457
92458 /* Ensure that:
92459 * (a) the table is not read-only,
92460 * (b) that if it is a view then ON INSERT triggers exist
92461 */
92462 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
92463 goto insert_cleanup;
92464 }
92465
@@ -92496,12 +93439,11 @@
92496 ** is coming from a SELECT statement, then generate a co-routine that
92497 ** produces a single row of the SELECT on each invocation. The
92498 ** co-routine is the common header to the 3rd and 4th templates.
92499 */
92500 if( pSelect ){
92501 /* Data is coming from a SELECT. Generate a co-routine to run that
92502 ** SELECT. */
92503 int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
92504 if( rc ) goto insert_cleanup;
92505
92506 regEof = dest.iSDParm + 1;
92507 regFromSelect = dest.iSdst;
@@ -92509,11 +93451,11 @@
92509 nColumn = pSelect->pEList->nExpr;
92510 assert( dest.nSdst==nColumn );
92511
92512 /* Set useTempTable to TRUE if the result of the SELECT statement
92513 ** should be written into a temporary table (template 4). Set to
92514 ** FALSE if each* row of the SELECT can be written directly into
92515 ** the destination table (template 3).
92516 **
92517 ** A temp table must be used if the table being updated is also one
92518 ** of the tables being read by the SELECT statement. Also use a
92519 ** temp table in the case of row triggers.
@@ -92592,15 +93534,15 @@
92592 /* If the INSERT statement included an IDLIST term, then make sure
92593 ** all elements of the IDLIST really are columns of the table and
92594 ** remember the column indices.
92595 **
92596 ** If the table has an INTEGER PRIMARY KEY column and that column
92597 ** is named in the IDLIST, then record in the keyColumn variable
92598 ** the index into IDLIST of the primary key column. keyColumn is
92599 ** the index of the primary key as it appears in IDLIST, not as
92600 ** is appears in the original table. (The index of the primary
92601 ** key in the original table is pTab->iPKey.)
92602 */
92603 if( pColumn ){
92604 for(i=0; i<pColumn->nId; i++){
92605 pColumn->a[i].idx = -1;
92606 }
@@ -92607,18 +93549,18 @@
92607 for(i=0; i<pColumn->nId; i++){
92608 for(j=0; j<pTab->nCol; j++){
92609 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
92610 pColumn->a[i].idx = j;
92611 if( j==pTab->iPKey ){
92612 keyColumn = i;
92613 }
92614 break;
92615 }
92616 }
92617 if( j>=pTab->nCol ){
92618 if( sqlite3IsRowid(pColumn->a[i].zName) ){
92619 keyColumn = i;
92620 }else{
92621 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
92622 pTabList, 0, pColumn->a[i].zName);
92623 pParse->checkSchema = 1;
92624 goto insert_cleanup;
@@ -92626,15 +93568,15 @@
92626 }
92627 }
92628 }
92629
92630 /* If there is no IDLIST term but the table has an integer primary
92631 ** key, the set the keyColumn variable to the primary key column index
92632 ** in the original table definition.
92633 */
92634 if( pColumn==0 && nColumn>0 ){
92635 keyColumn = pTab->iPKey;
92636 }
92637
92638 /* Initialize the count of rows to be inserted
92639 */
92640 if( db->flags & SQLITE_CountRows ){
@@ -92643,13 +93585,12 @@
92643 }
92644
92645 /* If this is not a view, open the table and and all indices */
92646 if( !isView ){
92647 int nIdx;
92648
92649 baseCur = pParse->nTab;
92650 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, baseCur, OP_OpenWrite);
92651 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
92652 if( aRegIdx==0 ){
92653 goto insert_cleanup;
92654 }
92655 for(i=0; i<nIdx; i++){
@@ -92705,19 +93646,20 @@
92705 ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
92706 ** translated into a unique ID for the row. But on a BEFORE trigger,
92707 ** we do not know what the unique ID will be (because the insert has
92708 ** not happened yet) so we substitute a rowid of -1
92709 */
92710 if( keyColumn<0 ){
92711 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
92712 }else{
92713 int j1;
 
92714 if( useTempTable ){
92715 sqlite3VdbeAddOp3(v, OP_Column, srcTab, keyColumn, regCols);
92716 }else{
92717 assert( pSelect==0 ); /* Otherwise useTempTable is true */
92718 sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr, regCols);
92719 }
92720 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
92721 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
92722 sqlite3VdbeJumpHere(v, j1);
92723 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
@@ -92763,33 +93705,31 @@
92763 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
92764
92765 sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
92766 }
92767
92768 /* Push the record number for the new entry onto the stack. The
92769 ** record number is a randomly generate integer created by NewRowid
92770 ** except when the table has an INTEGER PRIMARY KEY column, in which
92771 ** case the record number is the same as that column.
92772 */
92773 if( !isView ){
92774 if( IsVirtual(pTab) ){
92775 /* The row that the VUpdate opcode will delete: none */
92776 sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
92777 }
92778 if( keyColumn>=0 ){
92779 if( useTempTable ){
92780 sqlite3VdbeAddOp3(v, OP_Column, srcTab, keyColumn, regRowid);
92781 }else if( pSelect ){
92782 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+keyColumn, regRowid);
92783 }else{
92784 VdbeOp *pOp;
92785 sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr, regRowid);
92786 pOp = sqlite3VdbeGetOp(v, -1);
92787 if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
92788 appendFlag = 1;
92789 pOp->opcode = OP_NewRowid;
92790 pOp->p1 = baseCur;
92791 pOp->p2 = regRowid;
92792 pOp->p3 = regAutoinc;
92793 }
92794 }
92795 /* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
@@ -92797,36 +93737,36 @@
92797 */
92798 if( !appendFlag ){
92799 int j1;
92800 if( !IsVirtual(pTab) ){
92801 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
92802 sqlite3VdbeAddOp3(v, OP_NewRowid, baseCur, regRowid, regAutoinc);
92803 sqlite3VdbeJumpHere(v, j1);
92804 }else{
92805 j1 = sqlite3VdbeCurrentAddr(v);
92806 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
92807 }
92808 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
92809 }
92810 }else if( IsVirtual(pTab) ){
92811 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
92812 }else{
92813 sqlite3VdbeAddOp3(v, OP_NewRowid, baseCur, regRowid, regAutoinc);
92814 appendFlag = 1;
92815 }
92816 autoIncStep(pParse, regAutoinc, regRowid);
92817
92818 /* Push onto the stack, data for all columns of the new entry, beginning
92819 ** with the first column.
92820 */
92821 nHidden = 0;
92822 for(i=0; i<pTab->nCol; i++){
92823 int iRegStore = regRowid+1+i;
92824 if( i==pTab->iPKey ){
92825 /* The value of the INTEGER PRIMARY KEY column is always a NULL.
92826 ** Whenever this column is read, the record number will be substituted
92827 ** in its place. So will fill this column with a NULL to avoid
92828 ** taking up data space with information that will never be used. */
92829 sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
92830 continue;
92831 }
92832 if( pColumn==0 ){
@@ -92865,17 +93805,16 @@
92865 sqlite3MayAbort(pParse);
92866 }else
92867 #endif
92868 {
92869 int isReplace; /* Set to true if constraints may cause a replace */
92870 sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
92871 keyColumn>=0, 0, onError, endOfLoop, &isReplace
92872 );
92873 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
92874 sqlite3CompleteInsertion(
92875 pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
92876 );
92877 }
92878 }
92879
92880 /* Update the count of rows that are inserted
92881 */
@@ -92902,13 +93841,13 @@
92902 sqlite3VdbeJumpHere(v, addrInsTop);
92903 }
92904
92905 if( !IsVirtual(pTab) && !isView ){
92906 /* Close all tables opened */
92907 sqlite3VdbeAddOp1(v, OP_Close, baseCur);
92908 for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
92909 sqlite3VdbeAddOp1(v, OP_Close, idx+baseCur);
92910 }
92911 }
92912
92913 insert_end:
92914 /* Update the sqlite_sequence table by storing the content of the
@@ -92949,65 +93888,78 @@
92949 #endif
92950 #ifdef tmask
92951 #undef tmask
92952 #endif
92953
92954
92955 /*
92956 ** Generate code to do constraint checks prior to an INSERT or an UPDATE.
92957 **
92958 ** The input is a range of consecutive registers as follows:
92959 **
92960 ** 1. The rowid of the row after the update.
92961 **
92962 ** 2. The data in the first column of the entry after the update.
92963 **
92964 ** i. Data from middle columns...
92965 **
92966 ** N. The data in the last column of the entry after the update.
92967 **
92968 ** The regRowid parameter is the index of the register containing (1).
92969 **
92970 ** If isUpdate is true and rowidChng is non-zero, then rowidChng contains
92971 ** the address of a register containing the rowid before the update takes
92972 ** place. isUpdate is true for UPDATEs and false for INSERTs. If isUpdate
92973 ** is false, indicating an INSERT statement, then a non-zero rowidChng
92974 ** indicates that the rowid was explicitly specified as part of the
92975 ** INSERT statement. If rowidChng is false, it means that the rowid is
92976 ** computed automatically in an insert or that the rowid value is not
92977 ** modified by an update.
92978 **
92979 ** The code generated by this routine store new index entries into
 
 
 
 
 
92980 ** registers identified by aRegIdx[]. No index entry is created for
92981 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
92982 ** the same as the order of indices on the linked list of indices
92983 ** attached to the table.
 
 
 
 
 
 
 
 
92984 **
92985 ** This routine also generates code to check constraints. NOT NULL,
92986 ** CHECK, and UNIQUE constraints are all checked. If a constraint fails,
92987 ** then the appropriate action is performed. There are five possible
92988 ** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
92989 **
92990 ** Constraint type Action What Happens
92991 ** --------------- ---------- ----------------------------------------
92992 ** any ROLLBACK The current transaction is rolled back and
92993 ** sqlite3_exec() returns immediately with a
92994 ** return code of SQLITE_CONSTRAINT.
92995 **
92996 ** any ABORT Back out changes from the current command
92997 ** only (do not do a complete rollback) then
92998 ** cause sqlite3_exec() to return immediately
92999 ** with SQLITE_CONSTRAINT.
93000 **
93001 ** any FAIL Sqlite3_exec() returns immediately with a
93002 ** return code of SQLITE_CONSTRAINT. The
93003 ** transaction is not rolled back and any
93004 ** prior changes are retained.
93005 **
93006 ** any IGNORE The record number and data is popped from
93007 ** the stack and there is an immediate jump
93008 ** to label ignoreDest.
 
93009 **
93010 ** NOT NULL REPLACE The NULL value is replace by the default
93011 ** value for that column. If the default value
93012 ** is NULL, the action is the same as ABORT.
93013 **
@@ -93018,48 +93970,61 @@
93018 **
93019 ** Which action to take is determined by the overrideError parameter.
93020 ** Or if overrideError==OE_Default, then the pParse->onError parameter
93021 ** is used. Or if pParse->onError==OE_Default then the onError value
93022 ** for the constraint is used.
93023 **
93024 ** The calling routine must open a read/write cursor for pTab with
93025 ** cursor number "baseCur". All indices of pTab must also have open
93026 ** read/write cursors with cursor number baseCur+i for the i-th cursor.
93027 ** Except, if there is no possibility of a REPLACE action then
93028 ** cursors do not need to be open for indices where aRegIdx[i]==0.
93029 */
93030 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(
93031 Parse *pParse, /* The parser context */
93032 Table *pTab, /* the table into which we are inserting */
93033 int baseCur, /* Index of a read/write cursor pointing at pTab */
93034 int regRowid, /* Index of the range of input registers */
93035 int *aRegIdx, /* Register used by each index. 0 for unused indices */
93036 int rowidChng, /* True if the rowid might collide with existing entry */
93037 int isUpdate, /* True for UPDATE, False for INSERT */
93038 int overrideError, /* Override onError to this if not OE_Default */
93039 int ignoreDest, /* Jump to this label on an OE_Ignore resolution */
93040 int *pbMayReplace /* OUT: Set to true if constraint may cause a replace */
 
93041 ){
93042 int i; /* loop counter */
93043 Vdbe *v; /* VDBE under constrution */
93044 int nCol; /* Number of columns */
93045 int onError; /* Conflict resolution strategy */
93046 int j1; /* Addresss of jump instruction */
93047 int j2 = 0, j3; /* Addresses of jump instructions */
93048 int regData; /* Register containing first data column */
93049 int iCur; /* Table cursor number */
93050 Index *pIdx; /* Pointer to one of the indices */
 
93051 sqlite3 *db; /* Database connection */
 
 
 
 
 
93052 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
93053 int regOldRowid = (rowidChng && isUpdate) ? rowidChng : regRowid;
 
 
 
93054
 
93055 db = pParse->db;
93056 v = sqlite3GetVdbe(pParse);
93057 assert( v!=0 );
93058 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
93059 nCol = pTab->nCol;
93060 regData = regRowid + 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93061
93062 /* Test all NOT NULL constraints.
93063 */
93064 for(i=0; i<nCol; i++){
93065 if( i==pTab->iPKey ){
@@ -93078,28 +94043,28 @@
93078 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
93079 || onError==OE_Ignore || onError==OE_Replace );
93080 switch( onError ){
93081 case OE_Abort:
93082 sqlite3MayAbort(pParse);
 
93083 case OE_Rollback:
93084 case OE_Fail: {
93085 char *zMsg;
93086 sqlite3VdbeAddOp3(v, OP_HaltIfNull,
93087 SQLITE_CONSTRAINT_NOTNULL, onError, regData+i);
93088 zMsg = sqlite3MPrintf(db, "%s.%s may not be NULL",
93089 pTab->zName, pTab->aCol[i].zName);
93090 sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC);
93091 break;
93092 }
93093 case OE_Ignore: {
93094 sqlite3VdbeAddOp2(v, OP_IsNull, regData+i, ignoreDest);
93095 break;
93096 }
93097 default: {
93098 assert( onError==OE_Replace );
93099 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regData+i);
93100 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regData+i);
93101 sqlite3VdbeJumpHere(v, j1);
93102 break;
93103 }
93104 }
93105 }
@@ -93107,59 +94072,79 @@
93107 /* Test all CHECK constraints
93108 */
93109 #ifndef SQLITE_OMIT_CHECK
93110 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
93111 ExprList *pCheck = pTab->pCheck;
93112 pParse->ckBase = regData;
93113 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
93114 for(i=0; i<pCheck->nExpr; i++){
93115 int allOk = sqlite3VdbeMakeLabel(v);
93116 sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
93117 if( onError==OE_Ignore ){
93118 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
93119 }else{
93120 char *zConsName = pCheck->a[i].zName;
 
93121 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
93122 if( zConsName ){
93123 zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName);
93124 }else{
93125 zConsName = 0;
93126 }
93127 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
93128 onError, zConsName, P4_DYNAMIC);
 
93129 }
93130 sqlite3VdbeResolveLabel(v, allOk);
93131 }
93132 }
93133 #endif /* !defined(SQLITE_OMIT_CHECK) */
93134
93135 /* If we have an INTEGER PRIMARY KEY, make sure the primary key
93136 ** of the new record does not previously exist. Except, if this
93137 ** is an UPDATE and the primary key is not changing, that is OK.
93138 */
93139 if( rowidChng ){
 
 
 
93140 onError = pTab->keyConf;
93141 if( overrideError!=OE_Default ){
93142 onError = overrideError;
93143 }else if( onError==OE_Default ){
93144 onError = OE_Abort;
93145 }
93146
93147 if( isUpdate ){
93148 j2 = sqlite3VdbeAddOp3(v, OP_Eq, regRowid, 0, rowidChng);
 
 
 
93149 }
93150 j3 = sqlite3VdbeAddOp3(v, OP_NotExists, baseCur, 0, regRowid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93151 switch( onError ){
93152 default: {
93153 onError = OE_Abort;
93154 /* Fall thru into the next case */
93155 }
93156 case OE_Rollback:
93157 case OE_Abort:
93158 case OE_Fail: {
93159 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY,
93160 onError, "PRIMARY KEY must be unique", P4_STATIC);
93161 break;
93162 }
93163 case OE_Replace: {
93164 /* If there are DELETE triggers on this table and the
93165 ** recursive-triggers flag is set, call GenerateRowDelete() to
@@ -93187,123 +94172,162 @@
93187 if( db->flags&SQLITE_RecTriggers ){
93188 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
93189 }
93190 if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){
93191 sqlite3MultiWrite(pParse);
93192 sqlite3GenerateRowDelete(
93193 pParse, pTab, baseCur, regRowid, 0, pTrigger, OE_Replace
93194 );
93195 }else if( pTab->pIndex ){
93196 sqlite3MultiWrite(pParse);
93197 sqlite3GenerateRowIndexDelete(pParse, pTab, baseCur, 0);
93198 }
93199 seenReplace = 1;
93200 break;
93201 }
93202 case OE_Ignore: {
93203 assert( seenReplace==0 );
93204 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
93205 break;
93206 }
93207 }
93208 sqlite3VdbeJumpHere(v, j3);
93209 if( isUpdate ){
93210 sqlite3VdbeJumpHere(v, j2);
 
93211 }
93212 }
93213
93214 /* Test all UNIQUE constraints by creating entries for each UNIQUE
93215 ** index and making sure that duplicate entries do not already exist.
93216 ** Add the new records to the indices as we go.
 
 
 
93217 */
93218 for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
93219 int regIdx;
93220 int regR;
93221 int addrSkipRow = 0;
 
93222
93223 if( aRegIdx[iCur]==0 ) continue; /* Skip unused indices */
 
 
93224
 
93225 if( pIdx->pPartIdxWhere ){
93226 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[iCur]);
93227 addrSkipRow = sqlite3VdbeMakeLabel(v);
93228 pParse->ckBase = regData;
93229 sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, addrSkipRow,
93230 SQLITE_JUMPIFNULL);
93231 pParse->ckBase = 0;
93232 }
93233
93234 /* Create a key for accessing the index entry */
93235 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn+1);
 
 
93236 for(i=0; i<pIdx->nColumn; i++){
93237 int idx = pIdx->aiColumn[i];
93238 if( idx==pTab->iPKey ){
93239 sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
 
93240 }else{
93241 sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i);
93242 }
 
 
93243 }
93244 sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
93245 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
93246 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
93247 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
 
93248
93249 /* Find out what action to take in case there is an indexing conflict */
 
 
 
 
 
 
 
 
 
93250 onError = pIdx->onError;
93251 if( onError==OE_None ){
93252 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
93253 sqlite3VdbeResolveLabel(v, addrSkipRow);
93254 continue; /* pIdx is not a UNIQUE index */
93255 }
93256 if( overrideError!=OE_Default ){
93257 onError = overrideError;
93258 }else if( onError==OE_Default ){
93259 onError = OE_Abort;
93260 }
93261 if( seenReplace ){
93262 if( onError==OE_Ignore ) onError = OE_Replace;
93263 else if( onError==OE_Fail ) onError = OE_Abort;
93264 }
93265
93266 /* Check to see if the new index entry will be unique */
93267 regR = sqlite3GetTempReg(pParse);
93268 sqlite3VdbeAddOp2(v, OP_SCopy, regOldRowid, regR);
93269 j3 = sqlite3VdbeAddOp4(v, OP_IsUnique, baseCur+iCur+1, 0,
93270 regR, SQLITE_INT_TO_PTR(regIdx),
93271 P4_INT32);
93272 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93273
93274 /* Generate code that executes if the new index entry is not unique */
93275 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
93276 || onError==OE_Ignore || onError==OE_Replace );
93277 switch( onError ){
93278 case OE_Rollback:
93279 case OE_Abort:
93280 case OE_Fail: {
93281 int j;
93282 StrAccum errMsg;
93283 const char *zSep;
93284 char *zErr;
93285
93286 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
93287 errMsg.db = db;
93288 zSep = pIdx->nColumn>1 ? "columns " : "column ";
93289 for(j=0; j<pIdx->nColumn; j++){
93290 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
93291 sqlite3StrAccumAppend(&errMsg, zSep, -1);
93292 zSep = ", ";
93293 sqlite3StrAccumAppend(&errMsg, zCol, -1);
93294 }
93295 sqlite3StrAccumAppend(&errMsg,
93296 pIdx->nColumn>1 ? " are not unique" : " is not unique", -1);
93297 zErr = sqlite3StrAccumFinish(&errMsg);
93298 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
93299 onError, zErr, 0);
93300 sqlite3DbFree(errMsg.db, zErr);
93301 break;
93302 }
93303 case OE_Ignore: {
93304 assert( seenReplace==0 );
93305 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
93306 break;
93307 }
93308 default: {
93309 Trigger *pTrigger = 0;
@@ -93310,67 +94334,75 @@
93310 assert( onError==OE_Replace );
93311 sqlite3MultiWrite(pParse);
93312 if( db->flags&SQLITE_RecTriggers ){
93313 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
93314 }
93315 sqlite3GenerateRowDelete(
93316 pParse, pTab, baseCur, regR, 0, pTrigger, OE_Replace
93317 );
93318 seenReplace = 1;
93319 break;
93320 }
93321 }
93322 sqlite3VdbeJumpHere(v, j3);
93323 sqlite3VdbeResolveLabel(v, addrSkipRow);
93324 sqlite3ReleaseTempReg(pParse, regR);
 
 
 
 
93325 }
93326
93327 if( pbMayReplace ){
93328 *pbMayReplace = seenReplace;
93329 }
93330 }
93331
93332 /*
93333 ** This routine generates code to finish the INSERT or UPDATE operation
93334 ** that was started by a prior call to sqlite3GenerateConstraintChecks.
93335 ** A consecutive range of registers starting at regRowid contains the
93336 ** rowid and the content to be inserted.
93337 **
93338 ** The arguments to this routine should be the same as the first six
93339 ** arguments to sqlite3GenerateConstraintChecks.
93340 */
93341 SQLITE_PRIVATE void sqlite3CompleteInsertion(
93342 Parse *pParse, /* The parser context */
93343 Table *pTab, /* the table into which we are inserting */
93344 int baseCur, /* Index of a read/write cursor pointing at pTab */
93345 int regRowid, /* Range of content */
 
93346 int *aRegIdx, /* Register used by each index. 0 for unused indices */
93347 int isUpdate, /* True for UPDATE, False for INSERT */
93348 int appendBias, /* True if this is likely to be an append */
93349 int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */
93350 ){
93351 int i;
93352 Vdbe *v;
93353 Index *pIdx;
93354 u8 pik_flags;
93355 int regData;
93356 int regRec;
93357
93358 v = sqlite3GetVdbe(pParse);
93359 assert( v!=0 );
93360 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
93361 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
93362 if( aRegIdx[i]==0 ) continue;
93363 if( pIdx->pPartIdxWhere ){
93364 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
93365 }
93366 sqlite3VdbeAddOp2(v, OP_IdxInsert, baseCur+i+1, aRegIdx[i]);
93367 if( useSeekResult ){
93368 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
 
 
 
93369 }
 
93370 }
93371 regData = regRowid + 1;
 
93372 regRec = sqlite3GetTempReg(pParse);
93373 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
93374 sqlite3TableAffinityStr(v, pTab);
93375 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
93376 if( pParse->nested ){
@@ -93383,51 +94415,75 @@
93383 pik_flags |= OPFLAG_APPEND;
93384 }
93385 if( useSeekResult ){
93386 pik_flags |= OPFLAG_USESEEKRESULT;
93387 }
93388 sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid);
93389 if( !pParse->nested ){
93390 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
93391 }
93392 sqlite3VdbeChangeP5(v, pik_flags);
93393 }
93394
93395 /*
93396 ** Generate code that will open cursors for a table and for all
93397 ** indices of that table. The "baseCur" parameter is the cursor number used
93398 ** for the table. Indices are opened on subsequent cursors.
93399 **
93400 ** Return the number of indices on the table.
 
 
 
 
 
 
 
 
 
 
 
 
93401 */
93402 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
93403 Parse *pParse, /* Parsing context */
93404 Table *pTab, /* Table to be opened */
93405 int baseCur, /* Cursor number assigned to the table */
93406 int op /* OP_OpenRead or OP_OpenWrite */
 
 
93407 ){
93408 int i;
93409 int iDb;
93410 Index *pIdx;
93411 Vdbe *v;
93412
93413 if( IsVirtual(pTab) ) return 0;
 
 
 
 
 
93414 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
93415 v = sqlite3GetVdbe(pParse);
93416 assert( v!=0 );
93417 sqlite3OpenTable(pParse, baseCur, iDb, pTab, op);
93418 for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
93419 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
 
 
 
 
 
 
 
93420 assert( pIdx->pSchema==pTab->pSchema );
93421 sqlite3VdbeAddOp4(v, op, i+baseCur, pIdx->tnum, iDb,
93422 (char*)pKey, P4_KEYINFO_HANDOFF);
 
93423 VdbeComment((v, "%s", pIdx->zName));
93424 }
93425 if( pParse->nTab<baseCur+i ){
93426 pParse->nTab = baseCur+i;
93427 }
93428 return i-1;
93429 }
93430
93431
93432 #ifdef SQLITE_TEST
93433 /*
@@ -93468,17 +94524,17 @@
93468 */
93469 static int xferCompatibleIndex(Index *pDest, Index *pSrc){
93470 int i;
93471 assert( pDest && pSrc );
93472 assert( pDest->pTable!=pSrc->pTable );
93473 if( pDest->nColumn!=pSrc->nColumn ){
93474 return 0; /* Different number of columns */
93475 }
93476 if( pDest->onError!=pSrc->onError ){
93477 return 0; /* Different conflict resolution strategies */
93478 }
93479 for(i=0; i<pSrc->nColumn; i++){
93480 if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
93481 return 0; /* Different columns indexed */
93482 }
93483 if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
93484 return 0; /* Different sort orders */
@@ -93533,14 +94589,13 @@
93533 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
93534 int i; /* Loop counter */
93535 int iDbSrc; /* The database of pSrc */
93536 int iSrc, iDest; /* Cursors from source and destination */
93537 int addr1, addr2; /* Loop addresses */
93538 int emptyDestTest; /* Address of test for empty pDest */
93539 int emptySrcTest; /* Address of test for empty pSrc */
93540 Vdbe *v; /* The VDBE we are building */
93541 KeyInfo *pKey; /* Key information for an index */
93542 int regAutoinc; /* Memory register used by AUTOINC */
93543 int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
93544 int regData, regRowid; /* Registers holding data and rowid */
93545
93546 if( pSelect==0 ){
@@ -93606,10 +94661,13 @@
93606 return 0; /* FROM clause does not contain a real table */
93607 }
93608 if( pSrc==pDest ){
93609 return 0; /* tab1 and tab2 may not be the same table */
93610 }
 
 
 
93611 #ifndef SQLITE_OMIT_VIRTUALTABLE
93612 if( pSrc->tabFlags & TF_Virtual ){
93613 return 0; /* tab2 must not be a virtual table */
93614 }
93615 #endif
@@ -93676,11 +94734,14 @@
93676 v = sqlite3GetVdbe(pParse);
93677 sqlite3CodeVerifySchema(pParse, iDbSrc);
93678 iSrc = pParse->nTab++;
93679 iDest = pParse->nTab++;
93680 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
 
 
93681 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
 
93682 if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
93683 || destHasUniqueIdx /* (2) */
93684 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
93685 ){
93686 /* In some circumstances, we are able to run the xfer optimization
@@ -93698,62 +94759,60 @@
93698 ** (3) onError is something other than OE_Abort and OE_Rollback.
93699 */
93700 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
93701 emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
93702 sqlite3VdbeJumpHere(v, addr1);
93703 }else{
93704 emptyDestTest = 0;
93705 }
93706 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
93707 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
93708 regData = sqlite3GetTempReg(pParse);
93709 regRowid = sqlite3GetTempReg(pParse);
93710 if( pDest->iPKey>=0 ){
93711 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
93712 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
93713 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY,
93714 onError, "PRIMARY KEY must be unique", P4_STATIC);
93715 sqlite3VdbeJumpHere(v, addr2);
93716 autoIncStep(pParse, regAutoinc, regRowid);
93717 }else if( pDest->pIndex==0 ){
93718 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
93719 }else{
93720 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
93721 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
93722 }
93723 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
93724 sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
93725 sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
93726 sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
93727 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
 
 
93728 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
93729 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
93730 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
93731 }
93732 assert( pSrcIdx );
93733 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
93734 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
93735 pKey = sqlite3IndexKeyinfo(pParse, pSrcIdx);
93736 sqlite3VdbeAddOp4(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc,
93737 (char*)pKey, P4_KEYINFO_HANDOFF);
93738 VdbeComment((v, "%s", pSrcIdx->zName));
93739 pKey = sqlite3IndexKeyinfo(pParse, pDestIdx);
93740 sqlite3VdbeAddOp4(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest,
93741 (char*)pKey, P4_KEYINFO_HANDOFF);
93742 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
93743 VdbeComment((v, "%s", pDestIdx->zName));
93744 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
93745 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
93746 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
93747 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
93748 sqlite3VdbeJumpHere(v, addr1);
 
 
93749 }
93750 sqlite3VdbeJumpHere(v, emptySrcTest);
93751 sqlite3ReleaseTempReg(pParse, regRowid);
93752 sqlite3ReleaseTempReg(pParse, regData);
93753 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
93754 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
93755 if( emptyDestTest ){
93756 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
93757 sqlite3VdbeJumpHere(v, emptyDestTest);
93758 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
93759 return 0;
@@ -95251,15 +96310,17 @@
95251 { /* zName: */ "auto_vacuum",
95252 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
95253 /* ePragFlag: */ PragFlag_NeedSchema,
95254 /* iArg: */ 0 },
95255 #endif
 
95256 #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
95257 { /* zName: */ "automatic_index",
95258 /* ePragTyp: */ PragTyp_FLAG,
95259 /* ePragFlag: */ 0,
95260 /* iArg: */ SQLITE_AutoIndex },
 
95261 #endif
95262 { /* zName: */ "busy_timeout",
95263 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
95264 /* ePragFlag: */ 0,
95265 /* iArg: */ 0 },
@@ -95267,22 +96328,26 @@
95267 { /* zName: */ "cache_size",
95268 /* ePragTyp: */ PragTyp_CACHE_SIZE,
95269 /* ePragFlag: */ PragFlag_NeedSchema,
95270 /* iArg: */ 0 },
95271 #endif
 
95272 { /* zName: */ "cache_spill",
95273 /* ePragTyp: */ PragTyp_FLAG,
95274 /* ePragFlag: */ 0,
95275 /* iArg: */ SQLITE_CacheSpill },
 
95276 { /* zName: */ "case_sensitive_like",
95277 /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
95278 /* ePragFlag: */ 0,
95279 /* iArg: */ 0 },
 
95280 { /* zName: */ "checkpoint_fullfsync",
95281 /* ePragTyp: */ PragTyp_FLAG,
95282 /* ePragFlag: */ 0,
95283 /* iArg: */ SQLITE_CkptFullFSync },
 
95284 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95285 { /* zName: */ "collation_list",
95286 /* ePragTyp: */ PragTyp_COLLATION_LIST,
95287 /* ePragFlag: */ 0,
95288 /* iArg: */ 0 },
@@ -95291,14 +96356,16 @@
95291 { /* zName: */ "compile_options",
95292 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
95293 /* ePragFlag: */ 0,
95294 /* iArg: */ 0 },
95295 #endif
 
95296 { /* zName: */ "count_changes",
95297 /* ePragTyp: */ PragTyp_FLAG,
95298 /* ePragFlag: */ 0,
95299 /* iArg: */ SQLITE_CountRows },
 
95300 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
95301 { /* zName: */ "data_store_directory",
95302 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
95303 /* ePragFlag: */ 0,
95304 /* iArg: */ 0 },
@@ -95313,20 +96380,24 @@
95313 { /* zName: */ "default_cache_size",
95314 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
95315 /* ePragFlag: */ PragFlag_NeedSchema,
95316 /* iArg: */ 0 },
95317 #endif
 
95318 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95319 { /* zName: */ "defer_foreign_keys",
95320 /* ePragTyp: */ PragTyp_FLAG,
95321 /* ePragFlag: */ 0,
95322 /* iArg: */ SQLITE_DeferFKs },
95323 #endif
 
 
95324 { /* zName: */ "empty_result_callbacks",
95325 /* ePragTyp: */ PragTyp_FLAG,
95326 /* ePragFlag: */ 0,
95327 /* iArg: */ SQLITE_NullCallback },
 
95328 #if !defined(SQLITE_OMIT_UTF16)
95329 { /* zName: */ "encoding",
95330 /* ePragTyp: */ PragTyp_ENCODING,
95331 /* ePragFlag: */ 0,
95332 /* iArg: */ 0 },
@@ -95341,30 +96412,34 @@
95341 { /* zName: */ "foreign_key_list",
95342 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
95343 /* ePragFlag: */ PragFlag_NeedSchema,
95344 /* iArg: */ 0 },
95345 #endif
 
95346 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95347 { /* zName: */ "foreign_keys",
95348 /* ePragTyp: */ PragTyp_FLAG,
95349 /* ePragFlag: */ 0,
95350 /* iArg: */ SQLITE_ForeignKeys },
 
95351 #endif
95352 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95353 { /* zName: */ "freelist_count",
95354 /* ePragTyp: */ PragTyp_HEADER_VALUE,
95355 /* ePragFlag: */ 0,
95356 /* iArg: */ 0 },
95357 #endif
 
95358 { /* zName: */ "full_column_names",
95359 /* ePragTyp: */ PragTyp_FLAG,
95360 /* ePragFlag: */ 0,
95361 /* iArg: */ SQLITE_FullColNames },
95362 { /* zName: */ "fullfsync",
95363 /* ePragTyp: */ PragTyp_FLAG,
95364 /* ePragFlag: */ 0,
95365 /* iArg: */ SQLITE_FullFSync },
 
95366 #if defined(SQLITE_HAS_CODEC)
95367 { /* zName: */ "hexkey",
95368 /* ePragTyp: */ PragTyp_HEXKEY,
95369 /* ePragFlag: */ 0,
95370 /* iArg: */ 0 },
@@ -95371,15 +96446,17 @@
95371 { /* zName: */ "hexrekey",
95372 /* ePragTyp: */ PragTyp_HEXKEY,
95373 /* ePragFlag: */ 0,
95374 /* iArg: */ 0 },
95375 #endif
 
95376 #if !defined(SQLITE_OMIT_CHECK)
95377 { /* zName: */ "ignore_check_constraints",
95378 /* ePragTyp: */ PragTyp_FLAG,
95379 /* ePragFlag: */ 0,
95380 /* iArg: */ SQLITE_IgnoreChecks },
 
95381 #endif
95382 #if !defined(SQLITE_OMIT_AUTOVACUUM)
95383 { /* zName: */ "incremental_vacuum",
95384 /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
95385 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -95415,14 +96492,16 @@
95415 { /* zName: */ "key",
95416 /* ePragTyp: */ PragTyp_KEY,
95417 /* ePragFlag: */ 0,
95418 /* iArg: */ 0 },
95419 #endif
 
95420 { /* zName: */ "legacy_file_format",
95421 /* ePragTyp: */ PragTyp_FLAG,
95422 /* ePragFlag: */ 0,
95423 /* iArg: */ SQLITE_LegacyFileFmt },
 
95424 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
95425 { /* zName: */ "lock_proxy_file",
95426 /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
95427 /* ePragFlag: */ 0,
95428 /* iArg: */ 0 },
@@ -95459,38 +96538,44 @@
95459 { /* zName: */ "parser_trace",
95460 /* ePragTyp: */ PragTyp_PARSER_TRACE,
95461 /* ePragFlag: */ 0,
95462 /* iArg: */ 0 },
95463 #endif
 
95464 { /* zName: */ "query_only",
95465 /* ePragTyp: */ PragTyp_FLAG,
95466 /* ePragFlag: */ 0,
95467 /* iArg: */ SQLITE_QueryOnly },
 
95468 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
95469 { /* zName: */ "quick_check",
95470 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
95471 /* ePragFlag: */ PragFlag_NeedSchema,
95472 /* iArg: */ 0 },
95473 #endif
 
95474 { /* zName: */ "read_uncommitted",
95475 /* ePragTyp: */ PragTyp_FLAG,
95476 /* ePragFlag: */ 0,
95477 /* iArg: */ SQLITE_ReadUncommitted },
95478 { /* zName: */ "recursive_triggers",
95479 /* ePragTyp: */ PragTyp_FLAG,
95480 /* ePragFlag: */ 0,
95481 /* iArg: */ SQLITE_RecTriggers },
 
95482 #if defined(SQLITE_HAS_CODEC)
95483 { /* zName: */ "rekey",
95484 /* ePragTyp: */ PragTyp_REKEY,
95485 /* ePragFlag: */ 0,
95486 /* iArg: */ 0 },
95487 #endif
 
95488 { /* zName: */ "reverse_unordered_selects",
95489 /* ePragTyp: */ PragTyp_FLAG,
95490 /* ePragFlag: */ 0,
95491 /* iArg: */ SQLITE_ReverseOrder },
 
95492 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95493 { /* zName: */ "schema_version",
95494 /* ePragTyp: */ PragTyp_HEADER_VALUE,
95495 /* ePragFlag: */ 0,
95496 /* iArg: */ 0 },
@@ -95499,27 +96584,31 @@
95499 { /* zName: */ "secure_delete",
95500 /* ePragTyp: */ PragTyp_SECURE_DELETE,
95501 /* ePragFlag: */ 0,
95502 /* iArg: */ 0 },
95503 #endif
 
95504 { /* zName: */ "short_column_names",
95505 /* ePragTyp: */ PragTyp_FLAG,
95506 /* ePragFlag: */ 0,
95507 /* iArg: */ SQLITE_ShortColNames },
 
95508 { /* zName: */ "shrink_memory",
95509 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
95510 /* ePragFlag: */ 0,
95511 /* iArg: */ 0 },
95512 { /* zName: */ "soft_heap_limit",
95513 /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
95514 /* ePragFlag: */ 0,
95515 /* iArg: */ 0 },
 
95516 #if defined(SQLITE_DEBUG)
95517 { /* zName: */ "sql_trace",
95518 /* ePragTyp: */ PragTyp_FLAG,
95519 /* ePragFlag: */ 0,
95520 /* iArg: */ SQLITE_SqlTrace },
 
95521 #endif
95522 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95523 { /* zName: */ "stats",
95524 /* ePragTyp: */ PragTyp_STATS,
95525 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -95551,10 +96640,11 @@
95551 { /* zName: */ "user_version",
95552 /* ePragTyp: */ PragTyp_HEADER_VALUE,
95553 /* ePragFlag: */ 0,
95554 /* iArg: */ 0 },
95555 #endif
 
95556 #if defined(SQLITE_DEBUG)
95557 { /* zName: */ "vdbe_addoptrace",
95558 /* ePragTyp: */ PragTyp_FLAG,
95559 /* ePragFlag: */ 0,
95560 /* iArg: */ SQLITE_VdbeAddopTrace },
@@ -95568,10 +96658,11 @@
95568 /* iArg: */ SQLITE_VdbeListing },
95569 { /* zName: */ "vdbe_trace",
95570 /* ePragTyp: */ PragTyp_FLAG,
95571 /* ePragFlag: */ 0,
95572 /* iArg: */ SQLITE_VdbeTrace },
 
95573 #endif
95574 #if !defined(SQLITE_OMIT_WAL)
95575 { /* zName: */ "wal_autocheckpoint",
95576 /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
95577 /* ePragFlag: */ 0,
@@ -95579,14 +96670,16 @@
95579 { /* zName: */ "wal_checkpoint",
95580 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
95581 /* ePragFlag: */ PragFlag_NeedSchema,
95582 /* iArg: */ 0 },
95583 #endif
 
95584 { /* zName: */ "writable_schema",
95585 /* ePragTyp: */ PragTyp_FLAG,
95586 /* ePragFlag: */ 0,
95587 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
 
95588 };
95589 /* Number of pragmas: 56 on by default, 68 total. */
95590 /* End of the automatically generated pragma table.
95591 ***************************************************************************/
95592
@@ -96548,12 +97641,11 @@
96548 pTab = sqlite3FindTable(db, zRight, zDb);
96549 if( pTab ){
96550 int i, k;
96551 int nHidden = 0;
96552 Column *pCol;
96553 Index *pPk;
96554 for(pPk=pTab->pIndex; pPk && pPk->autoIndex!=2; pPk=pPk->pNext){}
96555 sqlite3VdbeSetNumCols(v, 6);
96556 pParse->nMem = 6;
96557 sqlite3CodeVerifySchema(pParse, iDb);
96558 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
96559 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
@@ -96632,12 +97724,12 @@
96632 pParse->nMem = 3;
96633 sqlite3CodeVerifySchema(pParse, iDb);
96634 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
96635 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
96636 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
96637 for(i=0; i<pIdx->nColumn; i++){
96638 int cnum = pIdx->aiColumn[i];
96639 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
96640 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
96641 assert( pTab->nCol>cnum );
96642 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
96643 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
@@ -96804,13 +97896,12 @@
96804 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
96805 if( x==0 ){
96806 if( pIdx==0 ){
96807 sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead);
96808 }else{
96809 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
96810 sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb);
96811 sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
96812 }
96813 }else{
96814 k = 0;
96815 break;
96816 }
@@ -96970,20 +98061,24 @@
96970 assert( sqlite3SchemaMutexHeld(db, i, 0) );
96971 pTbls = &db->aDb[i].pSchema->tblHash;
96972 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
96973 Table *pTab = sqliteHashData(x);
96974 Index *pIdx;
96975 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
96976 cnt++;
 
 
 
96977 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
96978 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt);
 
96979 cnt++;
96980 }
96981 }
96982
96983 /* Make sure sufficient number of registers have been allocated */
96984 pParse->nMem = MAX( pParse->nMem, cnt+7 );
96985
96986 /* Do the b-tree integrity checks */
96987 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
96988 sqlite3VdbeChangeP5(v, (u8)i);
96989 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
@@ -96997,62 +98092,64 @@
96997
96998 /* Make sure all the indices are constructed correctly.
96999 */
97000 for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
97001 Table *pTab = sqliteHashData(x);
97002 Index *pIdx;
97003 int loopTop;
 
97004
97005 if( pTab->pIndex==0 ) continue;
 
97006 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
97007 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
97008 sqlite3VdbeJumpHere(v, addr);
97009 sqlite3ExprCacheClear(pParse);
97010 sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
97011 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
97012 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7+j); /* index entries counter */
97013 }
97014 pParse->nMem = MAX(pParse->nMem, 7+j);
97015 loopTop = sqlite3VdbeAddOp2(v, OP_Rewind, 1, 0) + 1;
97016 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
97017 int jmp2, jmp3;
 
 
 
97018 int r1;
97019 static const VdbeOpList idxErr[] = {
97020 { OP_AddImm, 1, -1, 0},
97021 { OP_String8, 0, 3, 0}, /* 1 */
97022 { OP_Rowid, 1, 4, 0},
97023 { OP_String8, 0, 5, 0}, /* 3 */
97024 { OP_String8, 0, 6, 0}, /* 4 */
97025 { OP_Concat, 4, 3, 3},
97026 { OP_Concat, 5, 3, 3},
97027 { OP_Concat, 6, 3, 3},
97028 { OP_ResultRow, 3, 1, 0},
97029 { OP_IfPos, 1, 0, 0}, /* 9 */
97030 { OP_Halt, 0, 0, 0},
97031 };
97032 r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0, &jmp3);
97033 sqlite3VdbeAddOp2(v, OP_AddImm, 7+j, 1); /* increment entry count */
97034 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1);
97035 addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
97036 sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
97037 sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
97038 sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_TRANSIENT);
97039 sqlite3VdbeJumpHere(v, addr+9);
97040 sqlite3VdbeJumpHere(v, jmp2);
97041 sqlite3VdbeResolveLabel(v, jmp3);
97042 }
97043 sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop);
97044 sqlite3VdbeJumpHere(v, loopTop-1);
97045 #ifndef SQLITE_OMIT_BTREECOUNT
97046 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
97047 "wrong # of entries in index ", P4_STATIC);
97048 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
 
97049 addr = sqlite3VdbeCurrentAddr(v);
97050 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
97051 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
97052 sqlite3VdbeAddOp2(v, OP_Count, j+2, 3);
97053 sqlite3VdbeAddOp3(v, OP_Eq, 7+j, addr+8, 3);
97054 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
97055 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
97056 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
97057 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
97058 }
@@ -99096,28 +100193,61 @@
99096 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
99097 }
99098 }
99099
99100 /*
99101 ** Allocate a KeyInfo object sufficient for an index of N columns.
99102 **
99103 ** Actually, always allocate one extra column for the rowid at the end
99104 ** of the index. So the KeyInfo returned will have space sufficient for
99105 ** N+1 columns.
99106 */
99107 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N){
99108 KeyInfo *p = sqlite3DbMallocZero(db,
99109 sizeof(KeyInfo) + (N+1)*(sizeof(CollSeq*)+1));
99110 if( p ){
99111 p->aSortOrder = (u8*)&p->aColl[N+1];
99112 p->nField = (u16)N;
 
99113 p->enc = ENC(db);
99114 p->db = db;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99115 }
99116 return p;
99117 }
99118
 
 
 
 
 
 
 
 
 
 
99119 /*
99120 ** Given an expression list, generate a KeyInfo structure that records
99121 ** the collating sequence for each expression in that expression list.
99122 **
99123 ** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
@@ -99126,23 +100256,23 @@
99126 ** then the KeyInfo structure is appropriate for initializing a virtual
99127 ** index to implement a DISTINCT test.
99128 **
99129 ** Space to hold the KeyInfo structure is obtain from malloc. The calling
99130 ** function is responsible for seeing that this structure is eventually
99131 ** freed. Add the KeyInfo structure to the P4 field of an opcode using
99132 ** P4_KEYINFO_HANDOFF is the usual way of dealing with this.
99133 */
99134 static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
99135 int nExpr;
99136 KeyInfo *pInfo;
99137 struct ExprList_item *pItem;
99138 sqlite3 *db = pParse->db;
99139 int i;
99140
99141 nExpr = pList->nExpr;
99142 pInfo = sqlite3KeyInfoAlloc(db, nExpr);
99143 if( pInfo ){
 
99144 for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
99145 CollSeq *pColl;
99146 pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
99147 if( !pColl ) pColl = db->pDfltColl;
99148 pInfo->aColl[i] = pColl;
@@ -100281,11 +101411,11 @@
100281 CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
100282 int nCol; /* Number of columns in result set */
100283
100284 assert( p->pRightmost==p );
100285 nCol = p->pEList->nExpr;
100286 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol);
100287 if( !pKeyInfo ){
100288 rc = SQLITE_NOMEM;
100289 goto multi_select_end;
100290 }
100291 for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
@@ -100303,15 +101433,16 @@
100303 ** always safely abort as soon as the first unused slot is found */
100304 assert( pLoop->addrOpenEphm[1]<0 );
100305 break;
100306 }
100307 sqlite3VdbeChangeP2(v, addr, nCol);
100308 sqlite3VdbeChangeP4(v, addr, (char*)pKeyInfo, P4_KEYINFO);
 
100309 pLoop->addrOpenEphm[i] = -1;
100310 }
100311 }
100312 sqlite3DbFree(db, pKeyInfo);
100313 }
100314
100315 multi_select_end:
100316 pDest->iSdst = dest.iSdst;
100317 pDest->nSdst = dest.nSdst;
@@ -100346,11 +101477,10 @@
100346 SelectDest *pIn, /* Coroutine supplying data */
100347 SelectDest *pDest, /* Where to send the data */
100348 int regReturn, /* The return address register */
100349 int regPrev, /* Previous result register. No uniqueness if 0 */
100350 KeyInfo *pKeyInfo, /* For comparing with previous entry */
100351 int p4type, /* The p4 type for pKeyInfo */
100352 int iBreak /* Jump here if we hit the LIMIT */
100353 ){
100354 Vdbe *v = pParse->pVdbe;
100355 int iContinue;
100356 int addr;
@@ -100362,11 +101492,11 @@
100362 */
100363 if( regPrev ){
100364 int j1, j2;
100365 j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
100366 j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
100367 (char*)pKeyInfo, p4type);
100368 sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
100369 sqlite3VdbeJumpHere(v, j1);
100370 sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
100371 sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
100372 }
@@ -100660,11 +101790,11 @@
100660 struct ExprList_item *pItem;
100661 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
100662 assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
100663 aPermute[i] = pItem->iOrderByCol - 1;
100664 }
100665 pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy);
100666 if( pKeyMerge ){
100667 for(i=0; i<nOrderBy; i++){
100668 CollSeq *pColl;
100669 Expr *pTerm = pOrderBy->a[i].pExpr;
100670 if( pTerm->flags & EP_Collate ){
@@ -100673,10 +101803,11 @@
100673 pColl = multiSelectCollSeq(pParse, p, aPermute[i]);
100674 if( pColl==0 ) pColl = db->pDfltColl;
100675 pOrderBy->a[i].pExpr =
100676 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
100677 }
 
100678 pKeyMerge->aColl[i] = pColl;
100679 pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder;
100680 }
100681 }
100682 }else{
@@ -100698,12 +101829,13 @@
100698 int nExpr = p->pEList->nExpr;
100699 assert( nOrderBy>=nExpr || db->mallocFailed );
100700 regPrev = pParse->nMem+1;
100701 pParse->nMem += nExpr+1;
100702 sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
100703 pKeyDup = sqlite3KeyInfoAlloc(db, nExpr);
100704 if( pKeyDup ){
 
100705 for(i=0; i<nExpr; i++){
100706 pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
100707 pKeyDup->aSortOrder[i] = 0;
100708 }
100709 }
@@ -100781,21 +101913,22 @@
100781 ** select as the next output row of the compound select.
100782 */
100783 VdbeNoopComment((v, "Output routine for A"));
100784 addrOutA = generateOutputSubroutine(pParse,
100785 p, &destA, pDest, regOutA,
100786 regPrev, pKeyDup, P4_KEYINFO_HANDOFF, labelEnd);
100787
100788 /* Generate a subroutine that outputs the current row of the B
100789 ** select as the next output row of the compound select.
100790 */
100791 if( op==TK_ALL || op==TK_UNION ){
100792 VdbeNoopComment((v, "Output routine for B"));
100793 addrOutB = generateOutputSubroutine(pParse,
100794 p, &destB, pDest, regOutB,
100795 regPrev, pKeyDup, P4_KEYINFO_STATIC, labelEnd);
100796 }
 
100797
100798 /* Generate a subroutine to run when the results from select A
100799 ** are exhausted and only data in select B remains.
100800 */
100801 VdbeNoopComment((v, "eof-A subroutine"));
@@ -100870,11 +102003,11 @@
100870 /* Implement the main merge loop
100871 */
100872 sqlite3VdbeResolveLabel(v, labelCmpr);
100873 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
100874 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
100875 (char*)pKeyMerge, P4_KEYINFO_HANDOFF);
100876 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
100877 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
100878
100879 /* Jump to the this point in order to terminate the query.
100880 */
@@ -102096,11 +103229,11 @@
102096 "argument");
102097 pFunc->iDistinct = -1;
102098 }else{
102099 KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->x.pList);
102100 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
102101 (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
102102 }
102103 }
102104 }
102105 }
102106
@@ -102551,11 +103684,11 @@
102551 pKeyInfo = keyInfoFromExprList(pParse, pOrderBy);
102552 pOrderBy->iECursor = pParse->nTab++;
102553 p->addrOpenEphm[2] = addrSortIndex =
102554 sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
102555 pOrderBy->iECursor, pOrderBy->nExpr+2, 0,
102556 (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
102557 }else{
102558 addrSortIndex = -1;
102559 }
102560
102561 /* If the output is destined for a temporary table, open that table.
@@ -102579,11 +103712,11 @@
102579 if( p->selFlags & SF_Distinct ){
102580 sDistinct.tabTnct = pParse->nTab++;
102581 sDistinct.addrTnct = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
102582 sDistinct.tabTnct, 0, 0,
102583 (char*)keyInfoFromExprList(pParse, p->pEList),
102584 P4_KEYINFO_HANDOFF);
102585 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
102586 sDistinct.eTnctType = WHERE_DISTINCT_UNORDERED;
102587 }else{
102588 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
102589 }
@@ -102703,11 +103836,11 @@
102703 */
102704 sAggInfo.sortingIdx = pParse->nTab++;
102705 pKeyInfo = keyInfoFromExprList(pParse, pGroupBy);
102706 addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
102707 sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
102708 0, (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
102709
102710 /* Initialize memory locations used by GROUP BY aggregate processing
102711 */
102712 iUseFlag = ++pParse->nMem;
102713 iAbortFlag = ++pParse->nMem;
@@ -102817,11 +103950,11 @@
102817 sAggInfo.directMode = 1;
102818 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
102819 }
102820 }
102821 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
102822 (char*)pKeyInfo, P4_KEYINFO);
102823 j1 = sqlite3VdbeCurrentAddr(v);
102824 sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
102825
102826 /* Generate code that runs whenever the GROUP BY changes.
102827 ** Changes in the GROUP BY are detected by the previous code
@@ -102943,17 +104076,17 @@
102943 pBest = pIdx;
102944 }
102945 }
102946 if( pBest ){
102947 iRoot = pBest->tnum;
102948 pKeyInfo = sqlite3IndexKeyinfo(pParse, pBest);
102949 }
102950
102951 /* Open a read-only cursor, execute the OP_Count, close the cursor. */
102952 sqlite3VdbeAddOp3(v, OP_OpenRead, iCsr, iRoot, iDb);
102953 if( pKeyInfo ){
102954 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO_HANDOFF);
102955 }
102956 sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
102957 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
102958 explainSimpleCount(pParse, pTab, pBest);
102959 }else
@@ -104155,11 +105288,11 @@
104155 }
104156
104157 return 0;
104158 }
104159
104160 #ifdef SQLITE_DEBUG
104161 /*
104162 ** This function is used to add VdbeComment() annotations to a VDBE
104163 ** program. It is not used in production code, only for debugging.
104164 */
104165 static const char *onErrorText(int onError){
@@ -104603,44 +105736,54 @@
104603 Expr *pWhere, /* The WHERE clause. May be null */
104604 int onError /* How to handle constraint errors */
104605 ){
104606 int i, j; /* Loop counters */
104607 Table *pTab; /* The table to be updated */
104608 int addr = 0; /* VDBE instruction address of the start of the loop */
104609 WhereInfo *pWInfo; /* Information about the WHERE clause */
104610 Vdbe *v; /* The virtual database engine */
104611 Index *pIdx; /* For looping over indices */
 
104612 int nIdx; /* Number of indices that need updating */
104613 int iCur; /* VDBE Cursor number of pTab */
 
104614 sqlite3 *db; /* The database structure */
104615 int *aRegIdx = 0; /* One register assigned to each index to be updated */
104616 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
104617 ** an expression for the i-th column of the table.
104618 ** aXRef[i]==-1 if the i-th column is not changed. */
104619 int chngRowid; /* True if the record number is being changed */
 
 
104620 Expr *pRowidExpr = 0; /* Expression defining the new record number */
104621 int openAll = 0; /* True if all indices need to be opened */
104622 AuthContext sContext; /* The authorization context */
104623 NameContext sNC; /* The name-context to resolve expressions in */
104624 int iDb; /* Database containing the table being updated */
104625 int okOnePass; /* True for one-pass algorithm without the FIFO */
104626 int hasFK; /* True if foreign key processing is required */
 
 
104627
104628 #ifndef SQLITE_OMIT_TRIGGER
104629 int isView; /* True when updating a view (INSTEAD OF trigger) */
104630 Trigger *pTrigger; /* List of triggers on pTab, if required */
104631 int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
104632 #endif
104633 int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */
 
 
 
104634
104635 /* Register Allocations */
104636 int regRowCount = 0; /* A count of rows changed */
104637 int regOldRowid; /* The old rowid */
104638 int regNewRowid; /* The new rowid */
104639 int regNew; /* Content of the NEW.* table in triggers */
104640 int regOld = 0; /* Content of OLD.* table in triggers */
104641 int regRowSet = 0; /* Rowset of rows to be updated */
 
104642
104643 memset(&sContext, 0, sizeof(sContext));
104644 db = pParse->db;
104645 if( pParse->nErr || db->mallocFailed ){
104646 goto update_cleanup;
@@ -104683,12 +105826,18 @@
104683 /* Allocate a cursors for the main database table and for all indices.
104684 ** The index cursors might not be used, but if they are used they
104685 ** need to occur right after the database cursor. So go ahead and
104686 ** allocate enough space, just in case.
104687 */
104688 pTabList->a[0].iCursor = iCur = pParse->nTab++;
104689 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
 
 
 
 
 
 
104690 pParse->nTab++;
104691 }
104692
104693 /* Initialize the name-context */
104694 memset(&sNC, 0, sizeof(sNC));
@@ -104699,27 +105848,29 @@
104699 ** of the UPDATE statement. Also find the column index
104700 ** for each column to be updated in the pChanges array. For each
104701 ** column to be updated, make sure we have authorization to change
104702 ** that column.
104703 */
104704 chngRowid = 0;
104705 for(i=0; i<pChanges->nExpr; i++){
104706 if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
104707 goto update_cleanup;
104708 }
104709 for(j=0; j<pTab->nCol; j++){
104710 if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
104711 if( j==pTab->iPKey ){
104712 chngRowid = 1;
104713 pRowidExpr = pChanges->a[i].pExpr;
 
 
104714 }
104715 aXRef[j] = i;
104716 break;
104717 }
104718 }
104719 if( j>=pTab->nCol ){
104720 if( sqlite3IsRowid(pChanges->a[i].zName) ){
104721 j = -1;
104722 chngRowid = 1;
104723 pRowidExpr = pChanges->a[i].pExpr;
104724 }else{
104725 sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
@@ -104739,30 +105890,33 @@
104739 aXRef[j] = -1;
104740 }
104741 }
104742 #endif
104743 }
 
 
 
 
104744
104745 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngRowid);
104746
104747 /* Allocate memory for the array aRegIdx[]. There is one entry in the
104748 ** array for each index associated with table being updated. Fill in
104749 ** the value with a register number for indices that are to be used
104750 ** and with zero for unused indices.
104751 */
104752 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
104753 if( nIdx>0 ){
104754 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
104755 if( aRegIdx==0 ) goto update_cleanup;
104756 }
104757 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
104758 int reg;
104759 if( hasFK || chngRowid || pIdx->pPartIdxWhere ){
104760 reg = ++pParse->nMem;
104761 }else{
104762 reg = 0;
104763 for(i=0; i<pIdx->nColumn; i++){
104764 if( aXRef[pIdx->aiColumn[i]]>=0 ){
104765 reg = ++pParse->nMem;
104766 break;
104767 }
104768 }
@@ -104788,15 +105942,15 @@
104788 #endif
104789
104790 /* Allocate required registers. */
104791 regRowSet = ++pParse->nMem;
104792 regOldRowid = regNewRowid = ++pParse->nMem;
104793 if( pTrigger || hasFK ){
104794 regOld = pParse->nMem + 1;
104795 pParse->nMem += pTab->nCol;
104796 }
104797 if( chngRowid || pTrigger || hasFK ){
104798 regNewRowid = ++pParse->nMem;
104799 }
104800 regNew = pParse->nMem + 1;
104801 pParse->nMem += pTab->nCol;
104802
@@ -104808,11 +105962,11 @@
104808 /* If we are trying to update a view, realize that view into
104809 ** a ephemeral table.
104810 */
104811 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
104812 if( isView ){
104813 sqlite3MaterializeView(pParse, pTab, pWhere, iCur);
104814 }
104815 #endif
104816
104817 /* Resolve the column names in all the expressions in the
104818 ** WHERE clause.
@@ -104821,43 +105975,81 @@
104821 goto update_cleanup;
104822 }
104823
104824 /* Begin the database scan
104825 */
104826 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
104827 pWInfo = sqlite3WhereBegin(
104828 pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, 0
104829 );
104830 if( pWInfo==0 ) goto update_cleanup;
104831 okOnePass = sqlite3WhereOkOnePass(pWInfo);
104832
104833 /* Remember the rowid of every item to be updated.
104834 */
104835 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regOldRowid);
104836 if( !okOnePass ){
104837 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
104838 }
104839
104840 /* End the database scan loop.
104841 */
104842 sqlite3WhereEnd(pWInfo);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104843
104844 /* Initialize the count of updated rows
104845 */
104846 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
104847 regRowCount = ++pParse->nMem;
104848 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
104849 }
104850
 
104851 if( !isView ){
104852 /*
104853 ** Open every index that needs updating. Note that if any
104854 ** index could potentially invoke a REPLACE conflict resolution
104855 ** action, then we need to open all indices because we might need
104856 ** to be deleting some records.
104857 */
104858 if( !okOnePass ) sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
 
 
 
104859 if( onError==OE_Replace ){
104860 openAll = 1;
104861 }else{
104862 openAll = 0;
104863 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
@@ -104866,59 +106058,71 @@
104866 break;
104867 }
104868 }
104869 }
104870 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
 
104871 assert( aRegIdx );
104872 if( openAll || aRegIdx[i]>0 ){
104873 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
104874 sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,
104875 (char*)pKey, P4_KEYINFO_HANDOFF);
104876 assert( pParse->nTab>iCur+i+1 );
 
 
 
 
 
 
 
104877 }
104878 }
104879 }
104880
104881 /* Top of the update loop */
104882 if( okOnePass ){
104883 int a1 = sqlite3VdbeAddOp1(v, OP_NotNull, regOldRowid);
104884 addr = sqlite3VdbeAddOp0(v, OP_Goto);
104885 sqlite3VdbeJumpHere(v, a1);
 
 
 
 
104886 }else{
104887 addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, 0, regOldRowid);
 
 
104888 }
104889
104890 /* Make cursor iCur point to the record that is being updated. If
104891 ** this record does not exist for some reason (deleted by a trigger,
104892 ** for example, then jump to the next iteration of the RowSet loop. */
104893 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);
104894
104895 /* If the record number will change, set register regNewRowid to
104896 ** contain the new value. If the record number is not being modified,
104897 ** then regNewRowid is the same register as regOldRowid, which is
104898 ** already populated. */
104899 assert( chngRowid || pTrigger || hasFK || regOldRowid==regNewRowid );
104900 if( chngRowid ){
104901 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
104902 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
104903 }
104904
104905 /* If there are triggers on this table, populate an array of registers
104906 ** with the required old.* column data. */
104907 if( hasFK || pTrigger ){
104908 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
104909 oldmask |= sqlite3TriggerColmask(pParse,
104910 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
104911 );
104912 for(i=0; i<pTab->nCol; i++){
104913 if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){
104914 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
 
 
 
104915 }else{
104916 sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
104917 }
104918 }
104919 if( chngRowid==0 ){
104920 sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);
104921 }
104922 }
104923
104924 /* Populate the array of registers beginning at regNew with the new
@@ -104951,12 +106155,11 @@
104951 ** if there are one or more BEFORE triggers that use this value via
104952 ** a new.* reference in a trigger program.
104953 */
104954 testcase( i==31 );
104955 testcase( i==32 );
104956 sqlite3VdbeAddOp3(v, OP_Column, iCur, i, regNew+i);
104957 sqlite3ColumnDefault(v, pTab, i, regNew+i);
104958 }
104959 }
104960 }
104961
104962 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
@@ -104964,67 +106167,85 @@
104964 */
104965 if( tmask&TRIGGER_BEFORE ){
104966 sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
104967 sqlite3TableAffinityStr(v, pTab);
104968 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
104969 TRIGGER_BEFORE, pTab, regOldRowid, onError, addr);
104970
104971 /* The row-trigger may have deleted the row being updated. In this
104972 ** case, jump to the next row. No updates or AFTER triggers are
104973 ** required. This behavior - what happens when the row being updated
104974 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
104975 ** documentation.
104976 */
104977 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);
 
 
 
 
104978
104979 /* If it did not delete it, the row-trigger may still have modified
104980 ** some of the columns of the row being updated. Load the values for
104981 ** all columns not modified by the update statement into their
104982 ** registers in case this has happened.
104983 */
104984 for(i=0; i<pTab->nCol; i++){
104985 if( aXRef[i]<0 && i!=pTab->iPKey ){
104986 sqlite3VdbeAddOp3(v, OP_Column, iCur, i, regNew+i);
104987 sqlite3ColumnDefault(v, pTab, i, regNew+i);
104988 }
104989 }
104990 }
104991
104992 if( !isView ){
104993 int j1; /* Address of jump instruction */
 
104994
104995 /* Do constraint checks. */
104996 sqlite3GenerateConstraintChecks(pParse, pTab, iCur, regNewRowid,
104997 aRegIdx, (chngRowid?regOldRowid:0), 1, onError, addr, 0);
 
104998
104999 /* Do FK constraint checks. */
105000 if( hasFK ){
105001 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngRowid);
105002 }
105003
105004 /* Delete the index entries associated with the current record. */
105005 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regOldRowid);
105006 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
 
 
 
 
 
 
105007
105008 /* If changing the record number, delete the old record. */
105009 if( hasFK || chngRowid ){
105010 sqlite3VdbeAddOp2(v, OP_Delete, iCur, 0);
105011 }
105012 sqlite3VdbeJumpHere(v, j1);
 
 
 
 
 
 
105013
105014 if( hasFK ){
105015 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngRowid);
105016 }
105017
105018 /* Insert the new index entries and the new record. */
105019 sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
 
105020
105021 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
105022 ** handle rows (possibly in other tables) that refer via a foreign key
105023 ** to the row just updated. */
105024 if( hasFK ){
105025 sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngRowid);
105026 }
105027 }
105028
105029 /* Increment the row counter
105030 */
@@ -105031,26 +106252,33 @@
105031 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
105032 sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1);
105033 }
105034
105035 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
105036 TRIGGER_AFTER, pTab, regOldRowid, onError, addr);
105037
105038 /* Repeat the above with the next record to be updated, until
105039 ** all record selected by the WHERE clause have been updated.
105040 */
105041 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
105042 sqlite3VdbeJumpHere(v, addr);
 
 
 
 
 
 
 
105043
105044 /* Close all tables */
105045 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
105046 assert( aRegIdx );
105047 if( openAll || aRegIdx[i]>0 ){
105048 sqlite3VdbeAddOp2(v, OP_Close, iCur+i+1, 0);
105049 }
105050 }
105051 sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
105052
105053 /* Update the sqlite_sequence table by storing the content of the
105054 ** maximum rowid counter values recorded while inserting into
105055 ** autoincrement tables.
105056 */
@@ -105418,11 +106646,11 @@
105418 ** in the temporary database.
105419 */
105420 rc = execExecSql(db, pzErrMsg,
105421 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
105422 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
105423 " AND rootpage>0"
105424 );
105425 if( rc!=SQLITE_OK ) goto end_of_vacuum;
105426 rc = execExecSql(db, pzErrMsg,
105427 "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
105428 " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
@@ -105439,11 +106667,11 @@
105439 rc = execExecSql(db, pzErrMsg,
105440 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
105441 "|| ' SELECT * FROM main.' || quote(name) || ';'"
105442 "FROM main.sqlite_master "
105443 "WHERE type = 'table' AND name!='sqlite_sequence' "
105444 " AND rootpage>0"
105445 );
105446 if( rc!=SQLITE_OK ) goto end_of_vacuum;
105447
105448 /* Copy over the sequence table
105449 */
@@ -107062,10 +108290,11 @@
107062 u8 nLevel; /* Number of nested loop */
107063 int iTop; /* The very beginning of the WHERE loop */
107064 int iContinue; /* Jump here to continue with next record */
107065 int iBreak; /* Jump here to break out of the loop */
107066 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
 
107067 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
107068 WhereClause sWC; /* Decomposition of the WHERE clause */
107069 WhereLevel a[1]; /* Information about each nest loop in WHERE */
107070 };
107071
@@ -107154,12 +108383,23 @@
107154
107155 /*
107156 ** Return TRUE if an UPDATE or DELETE statement can operate directly on
107157 ** the rowids returned by a WHERE clause. Return FALSE if doing an
107158 ** UPDATE or DELETE might change subsequent WHERE clause results.
 
 
 
 
 
 
 
 
 
 
107159 */
107160 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo){
 
107161 return pWInfo->okOnePass;
107162 }
107163
107164 /*
107165 ** Move the content of pSrc into pDest
@@ -107531,11 +108771,14 @@
107531 while( pScan->iEquiv<=pScan->nEquiv ){
107532 iCur = pScan->aEquiv[pScan->iEquiv-2];
107533 iColumn = pScan->aEquiv[pScan->iEquiv-1];
107534 while( (pWC = pScan->pWC)!=0 ){
107535 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
107536 if( pTerm->leftCursor==iCur && pTerm->u.leftColumn==iColumn ){
 
 
 
107537 if( (pTerm->eOperator & WO_EQUIV)!=0
107538 && pScan->nEquiv<ArraySize(pScan->aEquiv)
107539 ){
107540 int j;
107541 pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
@@ -107621,11 +108864,11 @@
107621 pScan->pOrigWC = pWC;
107622 pScan->pWC = pWC;
107623 if( pIdx && iColumn>=0 ){
107624 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
107625 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
107626 if( NEVER(j>=pIdx->nColumn) ) return 0;
107627 }
107628 pScan->zCollName = pIdx->azColl[j];
107629 }else{
107630 pScan->idxaff = 0;
107631 pScan->zCollName = 0;
@@ -108551,20 +109794,20 @@
108551 ** 3. All of those index columns for which the WHERE clause does not
108552 ** contain a "col=X" term are subject to a NOT NULL constraint.
108553 */
108554 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
108555 if( pIdx->onError==OE_None ) continue;
108556 for(i=0; i<pIdx->nColumn; i++){
108557 int iCol = pIdx->aiColumn[i];
108558 if( 0==findTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
108559 int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i);
108560 if( iIdxCol<0 || pTab->aCol[pIdx->aiColumn[i]].notNull==0 ){
108561 break;
108562 }
108563 }
108564 }
108565 if( i==pIdx->nColumn ){
108566 /* This index implies that the DISTINCT qualifier is redundant. */
108567 return 1;
108568 }
108569 }
108570
@@ -108658,26 +109901,25 @@
108658 WhereClause *pWC, /* The WHERE clause */
108659 struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
108660 Bitmask notReady, /* Mask of cursors that are not available */
108661 WhereLevel *pLevel /* Write new index here */
108662 ){
108663 int nColumn; /* Number of columns in the constructed index */
108664 WhereTerm *pTerm; /* A single term of the WHERE clause */
108665 WhereTerm *pWCEnd; /* End of pWC->a[] */
108666 int nByte; /* Byte of memory needed for pIdx */
108667 Index *pIdx; /* Object describing the transient index */
108668 Vdbe *v; /* Prepared statement under construction */
108669 int addrInit; /* Address of the initialization bypass jump */
108670 Table *pTable; /* The table being indexed */
108671 KeyInfo *pKeyinfo; /* Key information for the index */
108672 int addrTop; /* Top of the index fill loop */
108673 int regRecord; /* Register holding an index record */
108674 int n; /* Column counter */
108675 int i; /* Loop counter */
108676 int mxBitCol; /* Maximum column in pSrc->colUsed */
108677 CollSeq *pColl; /* Collating sequence to on a column */
108678 WhereLoop *pLoop; /* The Loop object */
 
108679 Bitmask idxCols; /* Bitmap of columns used for indexing */
108680 Bitmask extraCols; /* Bitmap of additional columns */
108681 u8 sentWarning = 0; /* True if a warnning has been issued */
108682
108683 /* Generate code to skip over the creation and initialization of the
@@ -108686,11 +109928,11 @@
108686 assert( v!=0 );
108687 addrInit = sqlite3CodeOnce(pParse);
108688
108689 /* Count the number of columns that will be added to the index
108690 ** and used to match WHERE clause constraints */
108691 nColumn = 0;
108692 pTable = pSrc->pTab;
108693 pWCEnd = &pWC->a[pWC->nTerm];
108694 pLoop = pLevel->pWLoop;
108695 idxCols = 0;
108696 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
@@ -108704,18 +109946,18 @@
108704 "automatic index on %s(%s)", pTable->zName,
108705 pTable->aCol[iCol].zName);
108706 sentWarning = 1;
108707 }
108708 if( (idxCols & cMask)==0 ){
108709 if( whereLoopResize(pParse->db, pLoop, nColumn+1) ) return;
108710 pLoop->aLTerm[nColumn++] = pTerm;
108711 idxCols |= cMask;
108712 }
108713 }
108714 }
108715 assert( nColumn>0 );
108716 pLoop->u.btree.nEq = pLoop->nLTerm = nColumn;
108717 pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
108718 | WHERE_AUTO_INDEX;
108719
108720 /* Count the number of additional columns needed to create a
108721 ** covering index. A "covering index" is an index that contains all
@@ -108728,30 +109970,22 @@
108728 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
108729 mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
108730 testcase( pTable->nCol==BMS-1 );
108731 testcase( pTable->nCol==BMS-2 );
108732 for(i=0; i<mxBitCol; i++){
108733 if( extraCols & MASKBIT(i) ) nColumn++;
108734 }
108735 if( pSrc->colUsed & MASKBIT(BMS-1) ){
108736 nColumn += pTable->nCol - BMS + 1;
108737 }
108738 pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;
108739
108740 /* Construct the Index object to describe this index */
108741 nByte = sizeof(Index);
108742 nByte += nColumn*sizeof(int); /* Index.aiColumn */
108743 nByte += nColumn*sizeof(char*); /* Index.azColl */
108744 nByte += nColumn; /* Index.aSortOrder */
108745 pIdx = sqlite3DbMallocZero(pParse->db, nByte);
108746 if( pIdx==0 ) return;
108747 pLoop->u.btree.pIndex = pIdx;
108748 pIdx->azColl = (char**)&pIdx[1];
108749 pIdx->aiColumn = (int*)&pIdx->azColl[nColumn];
108750 pIdx->aSortOrder = (u8*)&pIdx->aiColumn[nColumn];
108751 pIdx->zName = "auto-index";
108752 pIdx->nColumn = nColumn;
108753 pIdx->pTable = pTable;
108754 n = 0;
108755 idxCols = 0;
108756 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
108757 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -108785,24 +110019,25 @@
108785 pIdx->aiColumn[n] = i;
108786 pIdx->azColl[n] = "BINARY";
108787 n++;
108788 }
108789 }
108790 assert( n==nColumn );
 
 
108791
108792 /* Create the automatic index */
108793 pKeyinfo = sqlite3IndexKeyinfo(pParse, pIdx);
108794 assert( pLevel->iIdxCur>=0 );
108795 pLevel->iIdxCur = pParse->nTab++;
108796 sqlite3VdbeAddOp4(v, OP_OpenAutoindex, pLevel->iIdxCur, nColumn+1, 0,
108797 (char*)pKeyinfo, P4_KEYINFO_HANDOFF);
108798 VdbeComment((v, "for %s", pTable->zName));
108799
108800 /* Fill the automatic index with content */
108801 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
108802 regRecord = sqlite3GetTempReg(pParse);
108803 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 1, 0);
108804 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
108805 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
108806 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
108807 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
108808 sqlite3VdbeJumpHere(v, addrTop);
@@ -109045,11 +110280,11 @@
109045 iUpper = aSample[0].anLt[iCol];
109046 }else{
109047 iUpper = i>=pIdx->nSample ? pIdx->aiRowEst[0] : aSample[i].anLt[iCol];
109048 iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol];
109049 }
109050 aStat[1] = (pIdx->nColumn>iCol ? pIdx->aAvgEq[iCol] : 1);
109051 if( iLower>=iUpper ){
109052 iGap = 0;
109053 }else{
109054 iGap = iUpper - iLower;
109055 }
@@ -109145,11 +110380,11 @@
109145 ** of iUpper are requested of whereKeyStats() and the smaller used.
109146 */
109147 tRowcnt iLower;
109148 tRowcnt iUpper;
109149
109150 if( nEq==p->nColumn ){
109151 aff = SQLITE_AFF_INTEGER;
109152 }else{
109153 aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
109154 }
109155 /* Determine iLower and iUpper using ($P) only. */
@@ -109203,11 +110438,11 @@
109203 }
109204 if( nNew<nOut ){
109205 nOut = nNew;
109206 }
109207 pLoop->nOut = (LogEst)nOut;
109208 WHERETRACE(0x100, ("range scan regions: %u..%u est=%d\n",
109209 (u32)iLower, (u32)iUpper, nOut));
109210 return SQLITE_OK;
109211 }
109212 }
109213 #else
@@ -109263,11 +110498,11 @@
109263 int rc; /* Subfunction return code */
109264 tRowcnt a[2]; /* Statistics */
109265 int bOk;
109266
109267 assert( nEq>=1 );
109268 assert( nEq<=(p->nColumn+1) );
109269 assert( p->aSample!=0 );
109270 assert( p->nSample>0 );
109271 assert( pBuilder->nRecValid<nEq );
109272
109273 /* If values are not available for all fields of the index to the left
@@ -109276,11 +110511,11 @@
109276 return SQLITE_NOTFOUND;
109277 }
109278
109279 /* This is an optimization only. The call to sqlite3Stat4ProbeSetValue()
109280 ** below would return the same value. */
109281 if( nEq>p->nColumn ){
109282 *pnRow = 1;
109283 return SQLITE_OK;
109284 }
109285
109286 aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity;
@@ -109289,11 +110524,11 @@
109289 if( rc!=SQLITE_OK ) return rc;
109290 if( bOk==0 ) return SQLITE_NOTFOUND;
109291 pBuilder->nRecValid = nEq;
109292
109293 whereKeyStats(pParse, p, pRec, 0, a);
109294 WHERETRACE(0x100,("equality scan regions: %d\n", (int)a[1]));
109295 *pnRow = a[1];
109296
109297 return rc;
109298 }
109299 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -109337,11 +110572,11 @@
109337 }
109338
109339 if( rc==SQLITE_OK ){
109340 if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
109341 *pnRow = nRowEst;
109342 WHERETRACE(0x100,("IN row estimate: est=%g\n", nRowEst));
109343 }
109344 assert( pBuilder->nRecValid==nRecValid );
109345 return rc;
109346 }
109347 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -109663,31 +110898,31 @@
109663 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
109664 Index *pIndex = pLoop->u.btree.pIndex;
109665 int nEq = pLoop->u.btree.nEq;
109666 int i, j;
109667 Column *aCol = pTab->aCol;
109668 int *aiColumn = pIndex->aiColumn;
109669 StrAccum txt;
109670
109671 if( nEq==0 && (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ){
109672 return 0;
109673 }
109674 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
109675 txt.db = db;
109676 sqlite3StrAccumAppend(&txt, " (", 2);
109677 for(i=0; i<nEq; i++){
109678 char *z = (i==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[i]].zName;
109679 explainAppendTerm(&txt, i, z, "=");
109680 }
109681
109682 j = i;
109683 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
109684 char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
109685 explainAppendTerm(&txt, i++, z, ">");
109686 }
109687 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
109688 char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
109689 explainAppendTerm(&txt, i, z, "<");
109690 }
109691 sqlite3StrAccumAppend(&txt, ")", 1);
109692 return sqlite3StrAccumFinish(&txt);
109693 }
@@ -109810,11 +111045,11 @@
109810 iCur = pTabItem->iCursor;
109811 pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109812 bRev = (pWInfo->revMask>>iLevel)&1;
109813 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
109814 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
109815 VdbeNoopComment((v, "Begin Join Loop %d", iLevel));
109816
109817 /* Create labels for the "break" and "continue" instructions
109818 ** for the current loop. Jump to addrBrk to break out of a loop.
109819 ** Jump to cont to go immediately to the next iteration of the
109820 ** loop.
@@ -110067,11 +111302,11 @@
110067 ** the first one after the nEq equality constraints in the index,
110068 ** this requires some special handling.
110069 */
110070 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
110071 && (pWInfo->bOBSat!=0)
110072 && (pIdx->nColumn>nEq)
110073 ){
110074 /* assert( pOrderBy->nExpr==1 ); */
110075 /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
110076 isMinQuery = 1;
110077 nExtraReg = 1;
@@ -110100,12 +111335,12 @@
110100
110101 /* If we are doing a reverse order scan on an ascending index, or
110102 ** a forward order scan on a descending index, interchange the
110103 ** start and end terms (pRangeStart and pRangeEnd).
110104 */
110105 if( (nEq<pIdx->nColumn && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
110106 || (bRev && pIdx->nColumn==nEq)
110107 ){
110108 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
110109 }
110110
110111 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
@@ -110210,15 +111445,26 @@
110210 sqlite3ReleaseTempReg(pParse, r1);
110211
110212 /* Seek the table cursor, if required */
110213 disableTerm(pLevel, pRangeStart);
110214 disableTerm(pLevel, pRangeEnd);
110215 if( !omitTable ){
 
 
110216 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
110217 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
110218 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
110219 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
 
 
 
 
 
 
 
 
 
110220 }
110221
110222 /* Record the instruction used to terminate the loop. Disable
110223 ** WHERE clause terms made redundant by the index range scan.
110224 */
@@ -110541,27 +111787,43 @@
110541 }
110542 sqlite3ReleaseTempReg(pParse, iReleaseReg);
110543
110544 return pLevel->notReady;
110545 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110546
110547 #ifdef WHERETRACE_ENABLED
110548 /*
110549 ** Print a WhereLoop object for debugging purposes
110550 */
110551 static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
110552 int nb = 1+(pTabList->nSrc+7)/8;
110553 struct SrcList_item *pItem = pTabList->a + p->iTab;
 
110554 Table *pTab = pItem->pTab;
110555 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
110556 p->iTab, nb, p->maskSelf, nb, p->prereq);
110557 sqlite3DebugPrintf(" %12s",
110558 pItem->zAlias ? pItem->zAlias : pTab->zName);
110559 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
110560 if( p->u.btree.pIndex ){
110561 const char *zName = p->u.btree.pIndex->zName;
110562 if( zName==0 ) zName = "ipk";
110563 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
110564 int i = sqlite3Strlen30(zName) - 1;
110565 while( zName[i]!='_' ) i--;
110566 zName += i;
110567 }
@@ -110580,10 +111842,30 @@
110580 sqlite3DebugPrintf(" %-19s", z);
110581 sqlite3_free(z);
110582 }
110583 sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
110584 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110585 }
110586 #endif
110587
110588 /*
110589 ** Convert bulk memory into a valid WhereLoop that can be passed
@@ -110605,10 +111887,11 @@
110605 sqlite3_free(p->u.vtab.idxStr);
110606 p->u.vtab.needFree = 0;
110607 p->u.vtab.idxStr = 0;
110608 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
110609 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
 
110610 sqlite3DbFree(db, p->u.btree.pIndex);
110611 p->u.btree.pIndex = 0;
110612 }
110613 }
110614 }
@@ -110719,14 +112002,14 @@
110719 u16 n = pBuilder->pOrSet->n;
110720 int x =
110721 #endif
110722 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
110723 pTemplate->nOut);
110724 #if WHERETRACE_ENABLED
110725 if( sqlite3WhereTrace & 0x8 ){
110726 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
110727 whereLoopPrint(pTemplate, pWInfo->pTabList);
110728 }
110729 #endif
110730 return SQLITE_OK;
110731 }
110732
@@ -110792,18 +112075,18 @@
110792
110793 /* If we reach this point it means that either p[] should be overwritten
110794 ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
110795 ** WhereLoop and insert it.
110796 */
110797 #if WHERETRACE_ENABLED
110798 if( sqlite3WhereTrace & 0x8 ){
110799 if( p!=0 ){
110800 sqlite3DebugPrintf("ins-del: ");
110801 whereLoopPrint(p, pWInfo->pTabList);
110802 }
110803 sqlite3DebugPrintf("ins-new: ");
110804 whereLoopPrint(pTemplate, pWInfo->pTabList);
110805 }
110806 #endif
110807 if( p==0 ){
110808 p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
110809 if( p==0 ) return SQLITE_NOMEM;
@@ -110820,14 +112103,14 @@
110820 }
110821 return SQLITE_OK;
110822
110823 /* Jump here if the insert is a no-op */
110824 whereLoopInsert_noop:
110825 #if WHERETRACE_ENABLED
110826 if( sqlite3WhereTrace & 0x8 ){
110827 sqlite3DebugPrintf("ins-noop: ");
110828 whereLoopPrint(pTemplate, pWInfo->pTabList);
110829 }
110830 #endif
110831 return SQLITE_OK;
110832 }
110833
@@ -110904,12 +112187,12 @@
110904 }else{
110905 opMask = WO_EQ|WO_IN|WO_ISNULL|WO_GT|WO_GE|WO_LT|WO_LE;
110906 }
110907 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
110908
110909 assert( pNew->u.btree.nEq<=pProbe->nColumn );
110910 if( pNew->u.btree.nEq < pProbe->nColumn ){
110911 iCol = pProbe->aiColumn[pNew->u.btree.nEq];
110912 nRowEst = sqlite3LogEst(pProbe->aiRowEst[pNew->u.btree.nEq+1]);
110913 if( nRowEst==0 && pProbe->onError==OE_None ) nRowEst = 1;
110914 }else{
110915 iCol = -1;
@@ -110962,11 +112245,11 @@
110962 assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
110963 || nInMul==0 );
110964 pNew->wsFlags |= WHERE_COLUMN_EQ;
110965 if( iCol<0
110966 || (pProbe->onError!=OE_None && nInMul==0
110967 && pNew->u.btree.nEq==pProbe->nColumn-1)
110968 ){
110969 assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
110970 pNew->wsFlags |= WHERE_ONEROW;
110971 }
110972 pNew->u.btree.nEq++;
@@ -111028,11 +112311,11 @@
111028 /* Step cost for each output row */
111029 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut);
111030 whereLoopOutputAdjust(pBuilder->pWC, pNew);
111031 rc = whereLoopInsert(pBuilder, pNew);
111032 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
111033 && pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0))
111034 ){
111035 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
111036 }
111037 pNew->nOut = saved_nOut;
111038 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -111067,11 +112350,11 @@
111067 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
111068 for(ii=0; ii<pOB->nExpr; ii++){
111069 Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr);
111070 if( pExpr->op!=TK_COLUMN ) return 0;
111071 if( pExpr->iTable==iCursor ){
111072 for(jj=0; jj<pIndex->nColumn; jj++){
111073 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
111074 }
111075 }
111076 }
111077 return 0;
@@ -111084,14 +112367,15 @@
111084 static Bitmask columnsInIndex(Index *pIdx){
111085 Bitmask m = 0;
111086 int j;
111087 for(j=pIdx->nColumn-1; j>=0; j--){
111088 int x = pIdx->aiColumn[j];
111089 assert( x>=0 );
111090 testcase( x==BMS-1 );
111091 testcase( x==BMS-2 );
111092 if( x<BMS-1 ) m |= MASKBIT(x);
 
111093 }
111094 return m;
111095 }
111096
111097 /* Check to see if a partial index with pPartIndexWhere can be used
@@ -111117,11 +112401,11 @@
111117 ){
111118 WhereInfo *pWInfo; /* WHERE analysis context */
111119 Index *pProbe; /* An index we are evaluating */
111120 Index sPk; /* A fake index object for the primary key */
111121 tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
111122 int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
111123 SrcList *pTabList; /* The FROM clause */
111124 struct SrcList_item *pSrc; /* The FROM clause btree term to add */
111125 WhereLoop *pNew; /* Template WhereLoop object */
111126 int rc = SQLITE_OK; /* Return code */
111127 int iSortIdx = 1; /* Index number */
@@ -111140,18 +112424,20 @@
111140 assert( !IsVirtual(pSrc->pTab) );
111141
111142 if( pSrc->pIndex ){
111143 /* An INDEXED BY clause specifies a particular index to use */
111144 pProbe = pSrc->pIndex;
 
 
111145 }else{
111146 /* There is no INDEXED BY clause. Create a fake Index object in local
111147 ** variable sPk to represent the rowid primary key index. Make this
111148 ** fake index the first in a chain of Index objects with all of the real
111149 ** indices to follow */
111150 Index *pFirst; /* First of real indices on the table */
111151 memset(&sPk, 0, sizeof(Index));
111152 sPk.nColumn = 1;
111153 sPk.aiColumn = &aiColumnPk;
111154 sPk.aiRowEst = aiRowEstPk;
111155 sPk.onError = OE_Replace;
111156 sPk.pTable = pTab;
111157 aiRowEstPk[0] = pTab->nRowEst;
@@ -111172,10 +112458,11 @@
111172 if( !pBuilder->pOrSet
111173 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
111174 && pSrc->pIndex==0
111175 && !pSrc->viaCoroutine
111176 && !pSrc->notIndexed
 
111177 && !pSrc->isCorrelated
111178 ){
111179 /* Generate auto-index WhereLoops */
111180 WhereTerm *pTerm;
111181 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
@@ -111234,18 +112521,25 @@
111234 whereLoopOutputAdjust(pWC, pNew);
111235 rc = whereLoopInsert(pBuilder, pNew);
111236 pNew->nOut = rSize;
111237 if( rc ) break;
111238 }else{
111239 Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe);
111240 pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
 
 
 
 
 
 
111241
111242 /* Full scan via index */
111243 if( b
 
111244 || ( m==0
111245 && pProbe->bUnordered==0
111246 && pProbe->szIdxRow<pTab->szTabRow
111247 && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
111248 && sqlite3GlobalConfig.bUseCis
111249 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan)
111250 )
111251 ){
@@ -111257,11 +112551,10 @@
111257 ** is smaller for smaller indices, thus favoring them.
111258 */
111259 pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 1 +
111260 (15*pProbe->szIdxRow)/pTab->szTabRow;
111261 }else{
111262 assert( b!=0 );
111263 /* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N)
111264 ** which we will simplify to just N*log2(N) */
111265 pNew->rRun = rSize + rLogSize;
111266 }
111267 whereLoopOutputAdjust(pWC, pNew);
@@ -111473,10 +112766,11 @@
111473 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
111474 pWCEnd = pWC->a + pWC->nTerm;
111475 pNew = pBuilder->pNew;
111476 memset(&sSum, 0, sizeof(sSum));
111477 pItem = pWInfo->pTabList->a + pNew->iTab;
 
111478 iCur = pItem->iCursor;
111479
111480 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
111481 if( (pTerm->eOperator & WO_OR)!=0
111482 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
@@ -111622,11 +112916,12 @@
111622 u8 rev; /* Composite sort order */
111623 u8 revIdx; /* Index sort order */
111624 u8 isOrderDistinct; /* All prior WhereLoops are order-distinct */
111625 u8 distinctColumns; /* True if the loop has UNIQUE NOT NULL columns */
111626 u8 isMatch; /* iColumn matches a term of the ORDER BY clause */
111627 u16 nColumn; /* Number of columns in pIndex */
 
111628 u16 nOrderBy; /* Number terms in the ORDER BY clause */
111629 int iLoop; /* Index of WhereLoop in pPath being processed */
111630 int i, j; /* Loop counters */
111631 int iCur; /* Cursor number for current WhereLoop */
111632 int iColumn; /* A column number within table iCur */
@@ -111714,24 +113009,28 @@
111714 }
111715
111716 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
111717 if( pLoop->wsFlags & WHERE_IPK ){
111718 pIndex = 0;
111719 nColumn = 0;
 
111720 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
111721 return 0;
111722 }else{
 
111723 nColumn = pIndex->nColumn;
 
 
111724 isOrderDistinct = pIndex->onError!=OE_None;
111725 }
111726
111727 /* Loop through all columns of the index and deal with the ones
111728 ** that are not constrained by == or IN.
111729 */
111730 rev = revSet = 0;
111731 distinctColumns = 0;
111732 for(j=0; j<=nColumn; j++){
111733 u8 bOnce; /* True to run the ORDER BY search loop */
111734
111735 /* Skip over == and IS NULL terms */
111736 if( j<pLoop->u.btree.nEq
111737 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
@@ -111744,24 +113043,21 @@
111744 }
111745
111746 /* Get the column number in the table (iColumn) and sort order
111747 ** (revIdx) for the j-th column of the index.
111748 */
111749 if( j<nColumn ){
111750 /* Normal index columns */
111751 iColumn = pIndex->aiColumn[j];
111752 revIdx = pIndex->aSortOrder[j];
111753 if( iColumn==pIndex->pTable->iPKey ) iColumn = -1;
111754 }else{
111755 /* The ROWID column at the end */
111756 assert( j==nColumn );
111757 iColumn = -1;
111758 revIdx = 0;
111759 }
111760
111761 /* An unconstrained column that might be NULL means that this
111762 ** WhereLoop is not well-ordered
111763 */
111764 if( isOrderDistinct
111765 && iColumn>=0
111766 && j>=pLoop->u.btree.nEq
111767 && pIndex->pTable->aCol[iColumn].notNull==0
@@ -111808,11 +113104,11 @@
111808 revSet = 1;
111809 }
111810 }
111811 }else{
111812 /* No match found */
111813 if( j==0 || j<nColumn ){
111814 testcase( isOrderDistinct!=0 );
111815 isOrderDistinct = 0;
111816 }
111817 break;
111818 }
@@ -111981,11 +113277,11 @@
111981 break;
111982 }
111983 }
111984 if( jj>=nTo ){
111985 if( nTo>=mxChoice && rCost>=mxCost ){
111986 #ifdef WHERETRACE_ENABLED
111987 if( sqlite3WhereTrace&0x4 ){
111988 sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
111989 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111990 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111991 }
@@ -111999,20 +113295,20 @@
111999 }else{
112000 /* New path replaces the prior worst to keep count below mxChoice */
112001 jj = mxI;
112002 }
112003 pTo = &aTo[jj];
112004 #ifdef WHERETRACE_ENABLED
112005 if( sqlite3WhereTrace&0x4 ){
112006 sqlite3DebugPrintf("New %s cost=%-3d,%3d order=%c\n",
112007 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
112008 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
112009 }
112010 #endif
112011 }else{
112012 if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
112013 #ifdef WHERETRACE_ENABLED
112014 if( sqlite3WhereTrace&0x4 ){
112015 sqlite3DebugPrintf(
112016 "Skip %s cost=%-3d,%3d order=%c",
112017 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
112018 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -112024,11 +113320,11 @@
112024 testcase( pTo->rCost==rCost );
112025 continue;
112026 }
112027 testcase( pTo->rCost==rCost+1 );
112028 /* A new and better score for a previously created equivalent path */
112029 #ifdef WHERETRACE_ENABLED
112030 if( sqlite3WhereTrace&0x4 ){
112031 sqlite3DebugPrintf(
112032 "Update %s cost=%-3d,%3d order=%c",
112033 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
112034 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -112060,11 +113356,11 @@
112060 }
112061 }
112062 }
112063 }
112064
112065 #ifdef WHERETRACE_ENABLED
112066 if( sqlite3WhereTrace>=2 ){
112067 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
112068 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
112069 sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
112070 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
@@ -112174,20 +113470,20 @@
112174 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
112175 assert( pLoop->aLTermSpace==pLoop->aLTerm );
112176 assert( ArraySize(pLoop->aLTermSpace)==4 );
112177 if( pIdx->onError==OE_None
112178 || pIdx->pPartIdxWhere!=0
112179 || pIdx->nColumn>ArraySize(pLoop->aLTermSpace)
112180 ) continue;
112181 for(j=0; j<pIdx->nColumn; j++){
112182 pTerm = findTerm(pWC, iCur, pIdx->aiColumn[j], 0, WO_EQ, pIdx);
112183 if( pTerm==0 ) break;
112184 pLoop->aLTerm[j] = pTerm;
112185 }
112186 if( j!=pIdx->nColumn ) continue;
112187 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW|WHERE_INDEXED;
112188 if( (pItem->colUsed & ~columnsInIndex(pIdx))==0 ){
112189 pLoop->wsFlags |= WHERE_IDX_ONLY;
112190 }
112191 pLoop->nLTerm = j;
112192 pLoop->u.btree.nEq = j;
112193 pLoop->u.btree.pIndex = pIdx;
@@ -112291,10 +113587,18 @@
112291 **
112292 ** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
112293 ** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
112294 ** if there is one. If there is no ORDER BY clause or if this routine
112295 ** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
 
 
 
 
 
 
 
 
112296 */
112297 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
112298 Parse *pParse, /* The parser context */
112299 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
112300 Expr *pWhere, /* The WHERE clause */
@@ -112356,10 +113660,11 @@
112356 if( db->mallocFailed ){
112357 sqlite3DbFree(db, pWInfo);
112358 pWInfo = 0;
112359 goto whereBeginError;
112360 }
 
112361 pWInfo->nLevel = nTabList;
112362 pWInfo->pParse = pParse;
112363 pWInfo->pTabList = pTabList;
112364 pWInfo->pOrderBy = pOrderBy;
112365 pWInfo->pResultSet = pResultSet;
@@ -112469,24 +113774,41 @@
112469 }
112470 }
112471
112472 /* Construct the WhereLoop objects */
112473 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112474 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
112475 rc = whereLoopAddAll(&sWLB);
112476 if( rc ) goto whereBeginError;
112477
112478 /* Display all of the WhereLoop objects if wheretrace is enabled */
112479 #ifdef WHERETRACE_ENABLED
112480 if( sqlite3WhereTrace ){
112481 WhereLoop *p;
112482 int i;
112483 static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
112484 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
112485 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
112486 p->cId = zLabel[i%sizeof(zLabel)];
112487 whereLoopPrint(p, pTabList);
112488 }
112489 }
112490 #endif
112491
112492 wherePathSolver(pWInfo, 0);
@@ -112500,11 +113822,11 @@
112500 pWInfo->revMask = (Bitmask)(-1);
112501 }
112502 if( pParse->nErr || NEVER(db->mallocFailed) ){
112503 goto whereBeginError;
112504 }
112505 #ifdef WHERETRACE_ENABLED
112506 if( sqlite3WhereTrace ){
112507 int ii;
112508 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
112509 if( pWInfo->bOBSat ){
112510 sqlite3DebugPrintf(" ORDERBY=0x%llx", pWInfo->revMask);
@@ -112523,11 +113845,11 @@
112523 break;
112524 }
112525 }
112526 sqlite3DebugPrintf("\n");
112527 for(ii=0; ii<pWInfo->nLevel; ii++){
112528 whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
112529 }
112530 }
112531 #endif
112532 /* Attempt to omit tables from the join that do not effect the result */
112533 if( pWInfo->nLevel>=2
@@ -112570,11 +113892,13 @@
112570 */
112571 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
112572 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
112573 && (pWInfo->a[0].pWLoop->wsFlags & WHERE_ONEROW)!=0 ){
112574 pWInfo->okOnePass = 1;
112575 pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY;
 
 
112576 }
112577
112578 /* Open all tables in the pTabList and any indices selected for
112579 ** searching those tables.
112580 */
@@ -112600,15 +113924,20 @@
112600 /* noop */
112601 }else
112602 #endif
112603 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
112604 && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){
112605 int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
 
 
 
 
112606 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
 
112607 testcase( !pWInfo->okOnePass && pTab->nCol==BMS-1 );
112608 testcase( !pWInfo->okOnePass && pTab->nCol==BMS );
112609 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
112610 Bitmask b = pTabItem->colUsed;
112611 int n = 0;
112612 for(; b; b=b>>1, n++){}
112613 sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1,
112614 SQLITE_INT_TO_PTR(n), P4_INT32);
@@ -112617,17 +113946,34 @@
112617 }else{
112618 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
112619 }
112620 if( pLoop->wsFlags & WHERE_INDEXED ){
112621 Index *pIx = pLoop->u.btree.pIndex;
112622 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
112623 /* FIXME: As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */
112624 int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112625 assert( pIx->pSchema==pTab->pSchema );
112626 assert( iIndexCur>=0 );
112627 sqlite3VdbeAddOp4(v, OP_OpenRead, iIndexCur, pIx->tnum, iDb,
112628 (char*)pKey, P4_KEYINFO_HANDOFF);
112629 VdbeComment((v, "%s", pIx->zName));
112630 }
112631 sqlite3CodeVerifySchema(pParse, iDb);
112632 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
112633 }
@@ -112718,35 +114064,44 @@
112718 }else{
112719 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
112720 }
112721 sqlite3VdbeJumpHere(v, addr);
112722 }
 
 
112723 }
112724
112725 /* The "break" point is here, just past the end of the outer loop.
112726 ** Set it.
112727 */
112728 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
112729
112730 /* Close all of the cursors that were opened by sqlite3WhereBegin.
112731 */
112732 assert( pWInfo->nLevel<=pTabList->nSrc );
112733 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
112734 Index *pIdx = 0;
112735 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
112736 Table *pTab = pTabItem->pTab;
112737 assert( pTab!=0 );
112738 pLoop = pLevel->pWLoop;
 
 
 
 
 
 
112739 if( (pTab->tabFlags & TF_Ephemeral)==0
112740 && pTab->pSelect==0
112741 && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
112742 ){
112743 int ws = pLoop->wsFlags;
112744 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
112745 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
112746 }
112747 if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 ){
 
 
 
112748 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
112749 }
112750 }
112751
112752 /* If this scan uses an index, make VDBE code substitutions to read data
@@ -112764,27 +114119,31 @@
112764 pIdx = pLoop->u.btree.pIndex;
112765 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
112766 pIdx = pLevel->u.pCovidx;
112767 }
112768 if( pIdx && !db->mallocFailed ){
112769 int k, j, last;
112770 VdbeOp *pOp;
112771
112772 last = sqlite3VdbeCurrentAddr(v);
112773 k = pLevel->addrBody;
112774 pOp = sqlite3VdbeGetOp(v, k);
112775 for(; k<last; k++, pOp++){
112776 if( pOp->p1!=pLevel->iTabCur ) continue;
112777 if( pOp->opcode==OP_Column ){
112778 for(j=0; j<pIdx->nColumn; j++){
112779 if( pOp->p2==pIdx->aiColumn[j] ){
112780 pOp->p2 = j;
112781 pOp->p1 = pLevel->iIdxCur;
112782 break;
112783 }
112784 }
112785 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || j<pIdx->nColumn );
 
 
 
 
112786 }else if( pOp->opcode==OP_Rowid ){
112787 pOp->p1 = pLevel->iIdxCur;
112788 pOp->opcode = OP_IdxRowid;
112789 }
112790 }
@@ -112988,42 +114347,42 @@
112988 ** YYNRULE the number of rules in the grammar
112989 ** YYERRORSYMBOL is the code number of the error symbol. If not
112990 ** defined, then do no error processing.
112991 */
112992 #define YYCODETYPE unsigned char
112993 #define YYNOCODE 251
112994 #define YYACTIONTYPE unsigned short int
112995 #define YYWILDCARD 67
112996 #define sqlite3ParserTOKENTYPE Token
112997 typedef union {
112998 int yyinit;
112999 sqlite3ParserTOKENTYPE yy0;
113000 struct LimitVal yy64;
113001 Expr* yy122;
113002 Select* yy159;
113003 IdList* yy180;
113004 struct {int value; int mask;} yy207;
113005 u8 yy258;
113006 u16 yy305;
113007 struct LikeOp yy318;
113008 TriggerStep* yy327;
113009 ExprSpan yy342;
113010 SrcList* yy347;
113011 int yy392;
113012 struct TrigEvent yy410;
113013 ExprList* yy442;
113014 struct ValueList yy487;
113015 } YYMINORTYPE;
113016 #ifndef YYSTACKDEPTH
113017 #define YYSTACKDEPTH 100
113018 #endif
113019 #define sqlite3ParserARG_SDECL Parse *pParse;
113020 #define sqlite3ParserARG_PDECL ,Parse *pParse
113021 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
113022 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
113023 #define YYNSTATE 628
113024 #define YYNRULE 327
113025 #define YYFALLBACK 1
113026 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
113027 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
113028 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
113029
@@ -113089,478 +114448,484 @@
113089 ** shifting terminals.
113090 ** yy_reduce_ofst[] For each state, the offset into yy_action for
113091 ** shifting non-terminals after a reduce.
113092 ** yy_default[] Default action for each state.
113093 */
113094 #define YY_ACTTAB_COUNT (1564)
113095 static const YYACTIONTYPE yy_action[] = {
113096 /* 0 */ 310, 956, 184, 418, 2, 171, 625, 595, 56, 56,
113097 /* 10 */ 56, 56, 49, 54, 54, 54, 54, 53, 53, 52,
113098 /* 20 */ 52, 52, 51, 233, 621, 620, 299, 621, 620, 234,
113099 /* 30 */ 588, 582, 56, 56, 56, 56, 19, 54, 54, 54,
113100 /* 40 */ 54, 53, 53, 52, 52, 52, 51, 233, 606, 57,
113101 /* 50 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113102 /* 60 */ 56, 56, 542, 54, 54, 54, 54, 53, 53, 52,
113103 /* 70 */ 52, 52, 51, 233, 310, 595, 326, 196, 195, 194,
113104 /* 80 */ 33, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113105 /* 90 */ 51, 233, 618, 617, 165, 618, 617, 381, 378, 377,
113106 /* 100 */ 408, 533, 577, 577, 588, 582, 304, 423, 376, 59,
113107 /* 110 */ 53, 53, 52, 52, 52, 51, 233, 50, 47, 146,
113108 /* 120 */ 575, 546, 65, 57, 58, 48, 580, 579, 581, 581,
113109 /* 130 */ 55, 55, 56, 56, 56, 56, 213, 54, 54, 54,
113110 /* 140 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 223,
113111 /* 150 */ 540, 421, 170, 176, 138, 281, 384, 276, 383, 168,
113112 /* 160 */ 490, 552, 410, 669, 621, 620, 272, 439, 410, 439,
113113 /* 170 */ 551, 605, 67, 483, 508, 619, 600, 413, 588, 582,
113114 /* 180 */ 601, 484, 619, 413, 619, 599, 91, 440, 441, 440,
113115 /* 190 */ 336, 599, 73, 670, 222, 267, 481, 57, 58, 48,
113116 /* 200 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56,
113117 /* 210 */ 671, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113118 /* 220 */ 51, 233, 310, 280, 232, 231, 1, 132, 200, 386,
113119 /* 230 */ 621, 620, 618, 617, 279, 436, 290, 564, 175, 263,
113120 /* 240 */ 410, 265, 438, 498, 437, 166, 442, 569, 337, 569,
113121 /* 250 */ 201, 538, 588, 582, 600, 413, 165, 595, 601, 381,
113122 /* 260 */ 378, 377, 598, 599, 92, 524, 619, 570, 570, 593,
113123 /* 270 */ 376, 57, 58, 48, 580, 579, 581, 581, 55, 55,
113124 /* 280 */ 56, 56, 56, 56, 598, 54, 54, 54, 54, 53,
113125 /* 290 */ 53, 52, 52, 52, 51, 233, 310, 464, 618, 617,
113126 /* 300 */ 591, 591, 591, 174, 273, 397, 410, 273, 410, 549,
113127 /* 310 */ 398, 621, 620, 68, 327, 621, 620, 621, 620, 619,
113128 /* 320 */ 547, 413, 619, 413, 472, 595, 588, 582, 473, 599,
113129 /* 330 */ 92, 599, 92, 52, 52, 52, 51, 233, 514, 513,
113130 /* 340 */ 206, 323, 364, 465, 221, 57, 58, 48, 580, 579,
113131 /* 350 */ 581, 581, 55, 55, 56, 56, 56, 56, 530, 54,
113132 /* 360 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233,
113133 /* 370 */ 310, 397, 410, 397, 598, 373, 387, 531, 348, 618,
113134 /* 380 */ 617, 576, 202, 618, 617, 618, 617, 413, 621, 620,
113135 /* 390 */ 145, 255, 347, 254, 578, 599, 74, 352, 45, 490,
113136 /* 400 */ 588, 582, 235, 189, 465, 545, 167, 297, 187, 470,
113137 /* 410 */ 480, 67, 62, 39, 619, 547, 598, 346, 574, 57,
113138 /* 420 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113139 /* 430 */ 56, 56, 6, 54, 54, 54, 54, 53, 53, 52,
113140 /* 440 */ 52, 52, 51, 233, 310, 563, 559, 408, 529, 577,
113141 /* 450 */ 577, 345, 255, 347, 254, 182, 618, 617, 504, 505,
113142 /* 460 */ 315, 410, 558, 235, 166, 272, 410, 353, 565, 181,
113143 /* 470 */ 408, 547, 577, 577, 588, 582, 413, 538, 557, 562,
113144 /* 480 */ 518, 413, 619, 249, 599, 16, 7, 36, 468, 599,
113145 /* 490 */ 92, 517, 619, 57, 58, 48, 580, 579, 581, 581,
113146 /* 500 */ 55, 55, 56, 56, 56, 56, 542, 54, 54, 54,
113147 /* 510 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 328,
113148 /* 520 */ 573, 572, 526, 559, 561, 395, 872, 246, 410, 248,
113149 /* 530 */ 171, 393, 595, 219, 408, 410, 577, 577, 503, 558,
113150 /* 540 */ 365, 145, 511, 413, 408, 229, 577, 577, 588, 582,
113151 /* 550 */ 413, 599, 92, 382, 270, 557, 166, 401, 599, 69,
113152 /* 560 */ 502, 420, 946, 199, 946, 198, 547, 57, 58, 48,
113153 /* 570 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56,
113154 /* 580 */ 569, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113155 /* 590 */ 51, 233, 310, 318, 420, 945, 509, 945, 309, 598,
113156 /* 600 */ 595, 566, 491, 212, 173, 247, 424, 616, 615, 614,
113157 /* 610 */ 324, 197, 143, 406, 573, 572, 490, 66, 50, 47,
113158 /* 620 */ 146, 595, 588, 582, 232, 231, 560, 428, 67, 556,
113159 /* 630 */ 15, 619, 186, 544, 304, 422, 35, 206, 433, 424,
113160 /* 640 */ 553, 57, 58, 48, 580, 579, 581, 581, 55, 55,
113161 /* 650 */ 56, 56, 56, 56, 205, 54, 54, 54, 54, 53,
113162 /* 660 */ 53, 52, 52, 52, 51, 233, 310, 570, 570, 261,
113163 /* 670 */ 269, 598, 12, 374, 569, 166, 410, 314, 410, 421,
113164 /* 680 */ 410, 474, 474, 366, 619, 50, 47, 146, 598, 595,
113165 /* 690 */ 256, 413, 166, 413, 352, 413, 588, 582, 32, 599,
113166 /* 700 */ 94, 599, 97, 599, 95, 628, 626, 330, 142, 50,
113167 /* 710 */ 47, 146, 334, 350, 359, 57, 58, 48, 580, 579,
113168 /* 720 */ 581, 581, 55, 55, 56, 56, 56, 56, 410, 54,
113169 /* 730 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233,
113170 /* 740 */ 310, 410, 389, 413, 410, 22, 566, 405, 212, 363,
113171 /* 750 */ 390, 599, 104, 360, 410, 156, 413, 410, 604, 413,
113172 /* 760 */ 538, 332, 570, 570, 599, 103, 494, 599, 105, 413,
113173 /* 770 */ 588, 582, 413, 261, 550, 619, 11, 599, 106, 522,
113174 /* 780 */ 599, 133, 169, 458, 457, 170, 35, 602, 619, 57,
113175 /* 790 */ 58, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113176 /* 800 */ 56, 56, 410, 54, 54, 54, 54, 53, 53, 52,
113177 /* 810 */ 52, 52, 51, 233, 310, 410, 260, 413, 410, 50,
113178 /* 820 */ 47, 146, 358, 319, 356, 599, 134, 528, 353, 338,
113179 /* 830 */ 413, 410, 357, 413, 358, 410, 358, 619, 599, 98,
113180 /* 840 */ 129, 599, 102, 619, 588, 582, 413, 21, 235, 619,
113181 /* 850 */ 413, 619, 211, 143, 599, 101, 30, 167, 599, 93,
113182 /* 860 */ 351, 536, 203, 57, 58, 48, 580, 579, 581, 581,
113183 /* 870 */ 55, 55, 56, 56, 56, 56, 410, 54, 54, 54,
113184 /* 880 */ 54, 53, 53, 52, 52, 52, 51, 233, 310, 410,
113185 /* 890 */ 527, 413, 410, 426, 215, 306, 598, 552, 141, 599,
113186 /* 900 */ 100, 40, 410, 38, 413, 410, 551, 413, 410, 228,
113187 /* 910 */ 220, 315, 599, 77, 501, 599, 96, 413, 588, 582,
113188 /* 920 */ 413, 339, 253, 413, 218, 599, 137, 380, 599, 136,
113189 /* 930 */ 28, 599, 135, 271, 716, 210, 482, 57, 58, 48,
113190 /* 940 */ 580, 579, 581, 581, 55, 55, 56, 56, 56, 56,
113191 /* 950 */ 410, 54, 54, 54, 54, 53, 53, 52, 52, 52,
113192 /* 960 */ 51, 233, 310, 410, 273, 413, 410, 316, 147, 598,
113193 /* 970 */ 273, 627, 2, 599, 76, 209, 410, 127, 413, 619,
113194 /* 980 */ 126, 413, 410, 622, 235, 619, 599, 90, 375, 599,
113195 /* 990 */ 89, 413, 588, 582, 27, 261, 351, 413, 619, 599,
113196 /* 1000 */ 75, 322, 542, 542, 125, 599, 88, 321, 279, 598,
113197 /* 1010 */ 619, 57, 46, 48, 580, 579, 581, 581, 55, 55,
113198 /* 1020 */ 56, 56, 56, 56, 410, 54, 54, 54, 54, 53,
113199 /* 1030 */ 53, 52, 52, 52, 51, 233, 310, 410, 451, 413,
113200 /* 1040 */ 164, 285, 283, 273, 610, 425, 305, 599, 87, 371,
113201 /* 1050 */ 410, 478, 413, 410, 609, 410, 608, 603, 619, 619,
113202 /* 1060 */ 599, 99, 587, 586, 122, 413, 588, 582, 413, 619,
113203 /* 1070 */ 413, 619, 619, 599, 86, 367, 599, 17, 599, 85,
113204 /* 1080 */ 320, 185, 520, 519, 584, 583, 58, 48, 580, 579,
113205 /* 1090 */ 581, 581, 55, 55, 56, 56, 56, 56, 410, 54,
113206 /* 1100 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 233,
113207 /* 1110 */ 310, 585, 410, 413, 410, 261, 261, 261, 409, 592,
113208 /* 1120 */ 475, 599, 84, 170, 410, 467, 519, 413, 121, 413,
113209 /* 1130 */ 619, 619, 619, 619, 619, 599, 83, 599, 72, 413,
113210 /* 1140 */ 588, 582, 51, 233, 626, 330, 471, 599, 71, 258,
113211 /* 1150 */ 159, 120, 14, 463, 157, 158, 117, 261, 449, 448,
113212 /* 1160 */ 447, 48, 580, 579, 581, 581, 55, 55, 56, 56,
113213 /* 1170 */ 56, 56, 619, 54, 54, 54, 54, 53, 53, 52,
113214 /* 1180 */ 52, 52, 51, 233, 44, 404, 261, 3, 410, 460,
113215 /* 1190 */ 261, 414, 620, 118, 399, 10, 25, 24, 555, 349,
113216 /* 1200 */ 217, 619, 407, 413, 410, 619, 4, 44, 404, 619,
113217 /* 1210 */ 3, 599, 82, 619, 414, 620, 456, 543, 115, 413,
113218 /* 1220 */ 539, 402, 537, 275, 507, 407, 251, 599, 81, 216,
113219 /* 1230 */ 274, 564, 619, 243, 454, 619, 154, 619, 619, 619,
113220 /* 1240 */ 450, 417, 624, 110, 402, 619, 410, 236, 64, 123,
113221 /* 1250 */ 488, 41, 42, 532, 564, 204, 410, 268, 43, 412,
113222 /* 1260 */ 411, 413, 266, 593, 108, 619, 107, 435, 333, 599,
113223 /* 1270 */ 80, 413, 619, 264, 41, 42, 444, 619, 410, 599,
113224 /* 1280 */ 70, 43, 412, 411, 434, 262, 593, 149, 619, 598,
113225 /* 1290 */ 257, 237, 188, 413, 591, 591, 591, 590, 589, 13,
113226 /* 1300 */ 619, 599, 18, 329, 235, 619, 44, 404, 361, 3,
113227 /* 1310 */ 419, 462, 340, 414, 620, 227, 124, 591, 591, 591,
113228 /* 1320 */ 590, 589, 13, 619, 407, 410, 619, 410, 139, 34,
113229 /* 1330 */ 404, 388, 3, 148, 623, 313, 414, 620, 312, 331,
113230 /* 1340 */ 413, 461, 413, 402, 180, 354, 413, 407, 599, 79,
113231 /* 1350 */ 599, 78, 250, 564, 599, 9, 619, 613, 612, 611,
113232 /* 1360 */ 619, 8, 453, 443, 242, 416, 402, 619, 239, 235,
113233 /* 1370 */ 179, 238, 429, 41, 42, 289, 564, 619, 619, 619,
113234 /* 1380 */ 43, 412, 411, 619, 144, 593, 619, 619, 177, 61,
113235 /* 1390 */ 619, 597, 392, 621, 620, 288, 41, 42, 415, 619,
113236 /* 1400 */ 294, 30, 394, 43, 412, 411, 293, 619, 593, 31,
113237 /* 1410 */ 619, 396, 292, 60, 230, 37, 591, 591, 591, 590,
113238 /* 1420 */ 589, 13, 214, 554, 183, 291, 172, 302, 301, 300,
113239 /* 1430 */ 178, 298, 596, 564, 452, 29, 286, 391, 541, 591,
113240 /* 1440 */ 591, 591, 590, 589, 13, 284, 521, 535, 150, 534,
113241 /* 1450 */ 241, 282, 385, 192, 191, 325, 516, 515, 277, 240,
113242 /* 1460 */ 511, 524, 308, 512, 128, 593, 510, 225, 226, 487,
113243 /* 1470 */ 486, 224, 152, 492, 465, 307, 485, 163, 153, 372,
113244 /* 1480 */ 479, 151, 162, 259, 370, 161, 368, 208, 476, 477,
113245 /* 1490 */ 26, 160, 469, 466, 362, 140, 591, 591, 591, 116,
113246 /* 1500 */ 119, 455, 344, 155, 114, 343, 113, 112, 446, 111,
113247 /* 1510 */ 131, 109, 432, 317, 130, 431, 23, 20, 430, 427,
113248 /* 1520 */ 190, 63, 255, 342, 244, 607, 295, 287, 311, 594,
113249 /* 1530 */ 278, 508, 496, 235, 493, 571, 497, 568, 495, 403,
113250 /* 1540 */ 459, 379, 355, 245, 193, 303, 567, 296, 341, 5,
113251 /* 1550 */ 445, 548, 506, 207, 525, 500, 335, 489, 252, 369,
113252 /* 1560 */ 400, 499, 523, 233,
 
 
113253 };
113254 static const YYCODETYPE yy_lookahead[] = {
113255 /* 0 */ 19, 142, 143, 144, 145, 24, 1, 26, 77, 78,
113256 /* 10 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
113257 /* 20 */ 89, 90, 91, 92, 26, 27, 15, 26, 27, 197,
113258 /* 30 */ 49, 50, 77, 78, 79, 80, 204, 82, 83, 84,
113259 /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 23, 68,
113260 /* 50 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113261 /* 60 */ 79, 80, 166, 82, 83, 84, 85, 86, 87, 88,
113262 /* 70 */ 89, 90, 91, 92, 19, 94, 19, 105, 106, 107,
113263 /* 80 */ 25, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113264 /* 90 */ 91, 92, 94, 95, 96, 94, 95, 99, 100, 101,
113265 /* 100 */ 112, 205, 114, 115, 49, 50, 22, 23, 110, 54,
113266 /* 110 */ 86, 87, 88, 89, 90, 91, 92, 221, 222, 223,
113267 /* 120 */ 23, 120, 25, 68, 69, 70, 71, 72, 73, 74,
113268 /* 130 */ 75, 76, 77, 78, 79, 80, 22, 82, 83, 84,
113269 /* 140 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 92,
113270 /* 150 */ 23, 67, 25, 96, 97, 98, 99, 100, 101, 102,
113271 /* 160 */ 150, 32, 150, 118, 26, 27, 109, 150, 150, 150,
113272 /* 170 */ 41, 161, 162, 180, 181, 165, 113, 165, 49, 50,
113273 /* 180 */ 117, 188, 165, 165, 165, 173, 174, 170, 171, 170,
113274 /* 190 */ 171, 173, 174, 118, 184, 16, 186, 68, 69, 70,
113275 /* 200 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
113276 /* 210 */ 118, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113277 /* 220 */ 91, 92, 19, 98, 86, 87, 22, 24, 160, 88,
113278 /* 230 */ 26, 27, 94, 95, 109, 97, 224, 66, 118, 60,
113279 /* 240 */ 150, 62, 104, 23, 106, 25, 229, 230, 229, 230,
113280 /* 250 */ 160, 150, 49, 50, 113, 165, 96, 26, 117, 99,
113281 /* 260 */ 100, 101, 194, 173, 174, 94, 165, 129, 130, 98,
113282 /* 270 */ 110, 68, 69, 70, 71, 72, 73, 74, 75, 76,
113283 /* 280 */ 77, 78, 79, 80, 194, 82, 83, 84, 85, 86,
113284 /* 290 */ 87, 88, 89, 90, 91, 92, 19, 11, 94, 95,
113285 /* 300 */ 129, 130, 131, 118, 150, 215, 150, 150, 150, 25,
113286 /* 310 */ 220, 26, 27, 22, 213, 26, 27, 26, 27, 165,
113287 /* 320 */ 25, 165, 165, 165, 30, 94, 49, 50, 34, 173,
113288 /* 330 */ 174, 173, 174, 88, 89, 90, 91, 92, 7, 8,
113289 /* 340 */ 160, 187, 48, 57, 187, 68, 69, 70, 71, 72,
113290 /* 350 */ 73, 74, 75, 76, 77, 78, 79, 80, 23, 82,
113291 /* 360 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
113292 /* 370 */ 19, 215, 150, 215, 194, 19, 220, 88, 220, 94,
113293 /* 380 */ 95, 23, 160, 94, 95, 94, 95, 165, 26, 27,
113294 /* 390 */ 95, 105, 106, 107, 113, 173, 174, 217, 22, 150,
113295 /* 400 */ 49, 50, 116, 119, 57, 120, 50, 158, 22, 21,
113296 /* 410 */ 161, 162, 232, 136, 165, 120, 194, 237, 23, 68,
113297 /* 420 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113298 /* 430 */ 79, 80, 22, 82, 83, 84, 85, 86, 87, 88,
113299 /* 440 */ 89, 90, 91, 92, 19, 23, 12, 112, 23, 114,
113300 /* 450 */ 115, 63, 105, 106, 107, 23, 94, 95, 97, 98,
113301 /* 460 */ 104, 150, 28, 116, 25, 109, 150, 150, 23, 23,
113302 /* 470 */ 112, 25, 114, 115, 49, 50, 165, 150, 44, 11,
113303 /* 480 */ 46, 165, 165, 16, 173, 174, 76, 136, 100, 173,
113304 /* 490 */ 174, 57, 165, 68, 69, 70, 71, 72, 73, 74,
113305 /* 500 */ 75, 76, 77, 78, 79, 80, 166, 82, 83, 84,
113306 /* 510 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 169,
113307 /* 520 */ 170, 171, 23, 12, 23, 214, 138, 60, 150, 62,
113308 /* 530 */ 24, 215, 26, 216, 112, 150, 114, 115, 36, 28,
113309 /* 540 */ 213, 95, 103, 165, 112, 205, 114, 115, 49, 50,
113310 /* 550 */ 165, 173, 174, 51, 23, 44, 25, 46, 173, 174,
113311 /* 560 */ 58, 22, 23, 22, 25, 160, 120, 68, 69, 70,
113312 /* 570 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
113313 /* 580 */ 230, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113314 /* 590 */ 91, 92, 19, 215, 22, 23, 23, 25, 163, 194,
113315 /* 600 */ 94, 166, 167, 168, 25, 138, 67, 7, 8, 9,
113316 /* 610 */ 108, 206, 207, 169, 170, 171, 150, 22, 221, 222,
113317 /* 620 */ 223, 26, 49, 50, 86, 87, 23, 161, 162, 23,
113318 /* 630 */ 22, 165, 24, 120, 22, 23, 25, 160, 241, 67,
113319 /* 640 */ 176, 68, 69, 70, 71, 72, 73, 74, 75, 76,
113320 /* 650 */ 77, 78, 79, 80, 160, 82, 83, 84, 85, 86,
113321 /* 660 */ 87, 88, 89, 90, 91, 92, 19, 129, 130, 150,
113322 /* 670 */ 23, 194, 35, 23, 230, 25, 150, 155, 150, 67,
113323 /* 680 */ 150, 105, 106, 107, 165, 221, 222, 223, 194, 94,
113324 /* 690 */ 23, 165, 25, 165, 217, 165, 49, 50, 25, 173,
113325 /* 700 */ 174, 173, 174, 173, 174, 0, 1, 2, 118, 221,
113326 /* 710 */ 222, 223, 193, 219, 237, 68, 69, 70, 71, 72,
113327 /* 720 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82,
113328 /* 730 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
113329 /* 740 */ 19, 150, 19, 165, 150, 24, 166, 167, 168, 227,
113330 /* 750 */ 27, 173, 174, 231, 150, 25, 165, 150, 172, 165,
113331 /* 760 */ 150, 242, 129, 130, 173, 174, 180, 173, 174, 165,
113332 /* 770 */ 49, 50, 165, 150, 176, 165, 35, 173, 174, 165,
113333 /* 780 */ 173, 174, 35, 23, 23, 25, 25, 173, 165, 68,
113334 /* 790 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113335 /* 800 */ 79, 80, 150, 82, 83, 84, 85, 86, 87, 88,
113336 /* 810 */ 89, 90, 91, 92, 19, 150, 193, 165, 150, 221,
113337 /* 820 */ 222, 223, 150, 213, 19, 173, 174, 23, 150, 97,
113338 /* 830 */ 165, 150, 27, 165, 150, 150, 150, 165, 173, 174,
113339 /* 840 */ 22, 173, 174, 165, 49, 50, 165, 52, 116, 165,
113340 /* 850 */ 165, 165, 206, 207, 173, 174, 126, 50, 173, 174,
113341 /* 860 */ 128, 27, 160, 68, 69, 70, 71, 72, 73, 74,
113342 /* 870 */ 75, 76, 77, 78, 79, 80, 150, 82, 83, 84,
113343 /* 880 */ 85, 86, 87, 88, 89, 90, 91, 92, 19, 150,
113344 /* 890 */ 23, 165, 150, 23, 216, 25, 194, 32, 39, 173,
113345 /* 900 */ 174, 135, 150, 137, 165, 150, 41, 165, 150, 52,
113346 /* 910 */ 238, 104, 173, 174, 29, 173, 174, 165, 49, 50,
113347 /* 920 */ 165, 219, 238, 165, 238, 173, 174, 52, 173, 174,
113348 /* 930 */ 22, 173, 174, 23, 23, 160, 25, 68, 69, 70,
113349 /* 940 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
113350 /* 950 */ 150, 82, 83, 84, 85, 86, 87, 88, 89, 90,
113351 /* 960 */ 91, 92, 19, 150, 150, 165, 150, 245, 246, 194,
113352 /* 970 */ 150, 144, 145, 173, 174, 160, 150, 22, 165, 165,
113353 /* 980 */ 22, 165, 150, 150, 116, 165, 173, 174, 52, 173,
113354 /* 990 */ 174, 165, 49, 50, 22, 150, 128, 165, 165, 173,
113355 /* 1000 */ 174, 187, 166, 166, 22, 173, 174, 187, 109, 194,
113356 /* 1010 */ 165, 68, 69, 70, 71, 72, 73, 74, 75, 76,
113357 /* 1020 */ 77, 78, 79, 80, 150, 82, 83, 84, 85, 86,
113358 /* 1030 */ 87, 88, 89, 90, 91, 92, 19, 150, 193, 165,
113359 /* 1040 */ 102, 205, 205, 150, 150, 247, 248, 173, 174, 19,
113360 /* 1050 */ 150, 20, 165, 150, 150, 150, 150, 150, 165, 165,
113361 /* 1060 */ 173, 174, 49, 50, 104, 165, 49, 50, 165, 165,
113362 /* 1070 */ 165, 165, 165, 173, 174, 43, 173, 174, 173, 174,
113363 /* 1080 */ 187, 24, 190, 191, 71, 72, 69, 70, 71, 72,
113364 /* 1090 */ 73, 74, 75, 76, 77, 78, 79, 80, 150, 82,
113365 /* 1100 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
113366 /* 1110 */ 19, 98, 150, 165, 150, 150, 150, 150, 150, 150,
113367 /* 1120 */ 59, 173, 174, 25, 150, 190, 191, 165, 53, 165,
113368 /* 1130 */ 165, 165, 165, 165, 165, 173, 174, 173, 174, 165,
113369 /* 1140 */ 49, 50, 91, 92, 1, 2, 53, 173, 174, 138,
113370 /* 1150 */ 104, 22, 5, 1, 35, 118, 127, 150, 193, 193,
113371 /* 1160 */ 193, 70, 71, 72, 73, 74, 75, 76, 77, 78,
113372 /* 1170 */ 79, 80, 165, 82, 83, 84, 85, 86, 87, 88,
113373 /* 1180 */ 89, 90, 91, 92, 19, 20, 150, 22, 150, 27,
113374 /* 1190 */ 150, 26, 27, 108, 150, 22, 76, 76, 150, 25,
113375 /* 1200 */ 193, 165, 37, 165, 150, 165, 22, 19, 20, 165,
113376 /* 1210 */ 22, 173, 174, 165, 26, 27, 23, 150, 119, 165,
113377 /* 1220 */ 150, 56, 150, 150, 150, 37, 16, 173, 174, 193,
113378 /* 1230 */ 150, 66, 165, 193, 1, 165, 121, 165, 165, 165,
113379 /* 1240 */ 20, 146, 147, 119, 56, 165, 150, 152, 16, 154,
113380 /* 1250 */ 150, 86, 87, 88, 66, 160, 150, 150, 93, 94,
113381 /* 1260 */ 95, 165, 150, 98, 108, 165, 127, 23, 65, 173,
113382 /* 1270 */ 174, 165, 165, 150, 86, 87, 128, 165, 150, 173,
113383 /* 1280 */ 174, 93, 94, 95, 23, 150, 98, 15, 165, 194,
113384 /* 1290 */ 150, 140, 22, 165, 129, 130, 131, 132, 133, 134,
113385 /* 1300 */ 165, 173, 174, 3, 116, 165, 19, 20, 150, 22,
113386 /* 1310 */ 4, 150, 217, 26, 27, 179, 179, 129, 130, 131,
113387 /* 1320 */ 132, 133, 134, 165, 37, 150, 165, 150, 164, 19,
113388 /* 1330 */ 20, 150, 22, 246, 149, 249, 26, 27, 249, 244,
113389 /* 1340 */ 165, 150, 165, 56, 6, 150, 165, 37, 173, 174,
113390 /* 1350 */ 173, 174, 150, 66, 173, 174, 165, 149, 149, 13,
113391 /* 1360 */ 165, 25, 150, 150, 150, 149, 56, 165, 150, 116,
113392 /* 1370 */ 151, 150, 150, 86, 87, 150, 66, 165, 165, 165,
113393 /* 1380 */ 93, 94, 95, 165, 150, 98, 165, 165, 151, 22,
113394 /* 1390 */ 165, 194, 150, 26, 27, 150, 86, 87, 159, 165,
113395 /* 1400 */ 199, 126, 123, 93, 94, 95, 200, 165, 98, 124,
113396 /* 1410 */ 165, 122, 201, 125, 225, 135, 129, 130, 131, 132,
113397 /* 1420 */ 133, 134, 5, 157, 157, 202, 118, 10, 11, 12,
113398 /* 1430 */ 13, 14, 203, 66, 17, 104, 210, 121, 211, 129,
113399 /* 1440 */ 130, 131, 132, 133, 134, 210, 175, 211, 31, 211,
113400 /* 1450 */ 33, 210, 104, 86, 87, 47, 175, 183, 175, 42,
113401 /* 1460 */ 103, 94, 178, 177, 22, 98, 175, 92, 228, 175,
113402 /* 1470 */ 175, 228, 55, 183, 57, 178, 175, 156, 61, 18,
113403 /* 1480 */ 157, 64, 156, 235, 157, 156, 45, 157, 236, 157,
113404 /* 1490 */ 135, 156, 199, 189, 157, 68, 129, 130, 131, 22,
113405 /* 1500 */ 189, 199, 157, 156, 192, 18, 192, 192, 199, 192,
113406 /* 1510 */ 218, 189, 40, 157, 218, 157, 240, 240, 157, 38,
113407 /* 1520 */ 196, 243, 105, 106, 107, 153, 198, 209, 111, 166,
113408 /* 1530 */ 176, 181, 166, 116, 166, 230, 176, 230, 176, 226,
113409 /* 1540 */ 199, 177, 239, 209, 185, 148, 166, 195, 209, 196,
113410 /* 1550 */ 199, 208, 182, 233, 173, 182, 139, 186, 239, 234,
113411 /* 1560 */ 191, 182, 173, 92,
113412 };
113413 #define YY_SHIFT_USE_DFLT (-70)
113414 #define YY_SHIFT_COUNT (417)
113415 #define YY_SHIFT_MIN (-69)
113416 #define YY_SHIFT_MAX (1487)
 
 
113417 static const short yy_shift_ofst[] = {
113418 /* 0 */ 1143, 1188, 1417, 1188, 1287, 1287, 138, 138, -2, -19,
113419 /* 10 */ 1287, 1287, 1287, 1287, 347, 362, 129, 129, 795, 1165,
113420 /* 20 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
113421 /* 30 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
113422 /* 40 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1310, 1287,
113423 /* 50 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287,
113424 /* 60 */ 1287, 1287, 286, 362, 362, 538, 538, 231, 1253, 55,
113425 /* 70 */ 721, 647, 573, 499, 425, 351, 277, 203, 869, 869,
113426 /* 80 */ 869, 869, 869, 869, 869, 869, 869, 869, 869, 869,
113427 /* 90 */ 869, 869, 869, 943, 869, 1017, 1091, 1091, -69, -45,
113428 /* 100 */ -45, -45, -45, -45, -1, 24, 245, 362, 362, 362,
113429 /* 110 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113430 /* 120 */ 362, 362, 362, 388, 356, 362, 362, 362, 362, 362,
113431 /* 130 */ 732, 868, 231, 1051, 1471, -70, -70, -70, 1367, 57,
113432 /* 140 */ 434, 434, 289, 291, 285, 1, 204, 572, 539, 362,
113433 /* 150 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113434 /* 160 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113435 /* 170 */ 362, 362, 362, 362, 362, 362, 362, 362, 362, 362,
113436 /* 180 */ 362, 506, 506, 506, 705, 1253, 1253, 1253, -70, -70,
113437 /* 190 */ -70, 171, 171, 160, 502, 502, 502, 446, 432, 511,
113438 /* 200 */ 422, 358, 335, -12, -12, -12, -12, 576, 294, -12,
113439 /* 210 */ -12, 295, 595, 141, 600, 730, 723, 723, 805, 730,
113440 /* 220 */ 805, 439, 911, 231, 865, 231, 865, 807, 865, 723,
113441 /* 230 */ 766, 633, 633, 231, 284, 63, 608, 1481, 1308, 1308,
113442 /* 240 */ 1472, 1472, 1308, 1477, 1427, 1275, 1487, 1487, 1487, 1487,
113443 /* 250 */ 1308, 1461, 1275, 1477, 1427, 1427, 1275, 1308, 1461, 1355,
113444 /* 260 */ 1441, 1308, 1308, 1461, 1308, 1461, 1308, 1461, 1442, 1348,
113445 /* 270 */ 1348, 1348, 1408, 1375, 1375, 1442, 1348, 1357, 1348, 1408,
113446 /* 280 */ 1348, 1348, 1316, 1331, 1316, 1331, 1316, 1331, 1308, 1308,
113447 /* 290 */ 1280, 1288, 1289, 1285, 1279, 1275, 1253, 1336, 1346, 1346,
113448 /* 300 */ 1338, 1338, 1338, 1338, -70, -70, -70, -70, -70, -70,
113449 /* 310 */ 1013, 467, 612, 84, 179, -28, 870, 410, 761, 760,
113450 /* 320 */ 667, 650, 531, 220, 361, 331, 125, 127, 97, 1306,
113451 /* 330 */ 1300, 1270, 1151, 1272, 1203, 1232, 1261, 1244, 1148, 1174,
113452 /* 340 */ 1139, 1156, 1124, 1220, 1115, 1210, 1233, 1099, 1193, 1184,
113453 /* 350 */ 1174, 1173, 1029, 1121, 1120, 1085, 1162, 1119, 1037, 1152,
113454 /* 360 */ 1147, 1129, 1046, 1011, 1093, 1098, 1075, 1061, 1032, 960,
113455 /* 370 */ 1057, 1031, 1030, 899, 938, 982, 936, 972, 958, 910,
113456 /* 380 */ 955, 875, 885, 908, 857, 859, 867, 804, 590, 834,
113457 /* 390 */ 747, 818, 513, 611, 741, 673, 637, 611, 606, 603,
113458 /* 400 */ 579, 501, 541, 468, 386, 445, 395, 376, 281, 185,
113459 /* 410 */ 120, 92, 75, 45, 114, 25, 11, 5,
113460 };
113461 #define YY_REDUCE_USE_DFLT (-169)
113462 #define YY_REDUCE_COUNT (309)
113463 #define YY_REDUCE_MIN (-168)
113464 #define YY_REDUCE_MAX (1397)
113465 static const short yy_reduce_ofst[] = {
113466 /* 0 */ -141, 90, 1095, 222, 158, 156, 19, 17, 10, -104,
113467 /* 10 */ 378, 316, 311, 12, 180, 249, 598, 464, 397, 1181,
113468 /* 20 */ 1177, 1175, 1128, 1106, 1096, 1054, 1038, 974, 964, 962,
113469 /* 30 */ 948, 905, 903, 900, 887, 874, 832, 826, 816, 813,
113470 /* 40 */ 800, 758, 755, 752, 742, 739, 726, 685, 681, 668,
113471 /* 50 */ 665, 652, 607, 604, 594, 591, 578, 530, 528, 526,
113472 /* 60 */ 385, 18, 477, 466, 519, 444, 350, 435, 405, 488,
113473 /* 70 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488,
113474 /* 80 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488,
113475 /* 90 */ 488, 488, 488, 488, 488, 488, 488, 488, 488, 488,
113476 /* 100 */ 488, 488, 488, 488, 488, 488, 488, 1040, 678, 1036,
113477 /* 110 */ 1007, 967, 966, 965, 845, 686, 610, 684, 317, 672,
113478 /* 120 */ 893, 327, 623, 522, -7, 820, 814, 157, 154, 101,
113479 /* 130 */ 702, 494, 580, 488, 488, 488, 488, 488, 614, 586,
113480 /* 140 */ 935, 892, 968, 1245, 1242, 1234, 1225, 798, 798, 1222,
113481 /* 150 */ 1221, 1218, 1214, 1213, 1212, 1202, 1195, 1191, 1161, 1158,
113482 /* 160 */ 1140, 1135, 1123, 1112, 1107, 1100, 1080, 1074, 1073, 1072,
113483 /* 170 */ 1070, 1067, 1048, 1044, 969, 968, 907, 906, 904, 894,
113484 /* 180 */ 833, 837, 836, 340, 827, 815, 775, 68, 722, 646,
113485 /* 190 */ -168, 1389, 1381, 1371, 1379, 1373, 1370, 1343, 1352, 1369,
113486 /* 200 */ 1352, 1352, 1352, 1352, 1352, 1352, 1352, 1325, 1320, 1352,
113487 /* 210 */ 1352, 1343, 1380, 1353, 1397, 1351, 1339, 1334, 1319, 1341,
113488 /* 220 */ 1303, 1364, 1359, 1368, 1362, 1366, 1360, 1350, 1354, 1318,
113489 /* 230 */ 1313, 1307, 1305, 1363, 1328, 1324, 1372, 1278, 1361, 1358,
113490 /* 240 */ 1277, 1276, 1356, 1296, 1322, 1309, 1317, 1315, 1314, 1312,
113491 /* 250 */ 1345, 1347, 1302, 1292, 1311, 1304, 1293, 1337, 1335, 1252,
113492 /* 260 */ 1248, 1332, 1330, 1329, 1327, 1326, 1323, 1321, 1297, 1301,
113493 /* 270 */ 1295, 1294, 1290, 1243, 1240, 1284, 1291, 1286, 1283, 1274,
113494 /* 280 */ 1281, 1271, 1238, 1241, 1236, 1235, 1227, 1226, 1267, 1266,
113495 /* 290 */ 1189, 1229, 1223, 1211, 1206, 1201, 1197, 1239, 1237, 1219,
113496 /* 300 */ 1216, 1209, 1208, 1185, 1089, 1086, 1087, 1137, 1136, 1164,
 
113497 };
113498 static const YYACTIONTYPE yy_default[] = {
113499 /* 0 */ 633, 867, 955, 955, 867, 867, 955, 955, 955, 757,
113500 /* 10 */ 955, 955, 955, 865, 955, 955, 785, 785, 929, 955,
113501 /* 20 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113502 /* 30 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113503 /* 40 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113504 /* 50 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113505 /* 60 */ 955, 955, 955, 955, 955, 955, 955, 672, 761, 791,
113506 /* 70 */ 955, 955, 955, 955, 955, 955, 955, 955, 928, 930,
113507 /* 80 */ 799, 798, 908, 772, 796, 789, 793, 868, 861, 862,
113508 /* 90 */ 860, 864, 869, 955, 792, 828, 845, 827, 839, 844,
113509 /* 100 */ 851, 843, 840, 830, 829, 831, 832, 955, 955, 955,
113510 /* 110 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113511 /* 120 */ 955, 955, 955, 659, 726, 955, 955, 955, 955, 955,
113512 /* 130 */ 955, 955, 955, 833, 834, 848, 847, 846, 955, 664,
113513 /* 140 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113514 /* 150 */ 935, 933, 955, 880, 955, 955, 955, 955, 955, 955,
113515 /* 160 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113516 /* 170 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113517 /* 180 */ 639, 757, 757, 757, 633, 955, 955, 955, 947, 761,
113518 /* 190 */ 751, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113519 /* 200 */ 955, 955, 955, 801, 740, 918, 920, 955, 901, 738,
113520 /* 210 */ 661, 759, 674, 749, 641, 795, 774, 774, 913, 795,
113521 /* 220 */ 913, 697, 720, 955, 785, 955, 785, 694, 785, 774,
113522 /* 230 */ 863, 955, 955, 955, 758, 749, 955, 940, 765, 765,
113523 /* 240 */ 932, 932, 765, 807, 730, 795, 737, 737, 737, 737,
113524 /* 250 */ 765, 656, 795, 807, 730, 730, 795, 765, 656, 907,
113525 /* 260 */ 905, 765, 765, 656, 765, 656, 765, 656, 873, 728,
113526 /* 270 */ 728, 728, 712, 877, 877, 873, 728, 697, 728, 712,
113527 /* 280 */ 728, 728, 778, 773, 778, 773, 778, 773, 765, 765,
113528 /* 290 */ 955, 790, 779, 788, 786, 795, 955, 715, 649, 649,
113529 /* 300 */ 638, 638, 638, 638, 952, 952, 947, 699, 699, 682,
113530 /* 310 */ 955, 955, 955, 955, 955, 955, 955, 882, 955, 955,
113531 /* 320 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113532 /* 330 */ 634, 942, 955, 955, 939, 955, 955, 955, 955, 800,
113533 /* 340 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113534 /* 350 */ 917, 955, 955, 955, 955, 955, 955, 955, 911, 955,
113535 /* 360 */ 955, 955, 955, 955, 955, 904, 903, 955, 955, 955,
113536 /* 370 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113537 /* 380 */ 955, 955, 955, 955, 955, 955, 955, 955, 955, 955,
113538 /* 390 */ 955, 955, 955, 787, 955, 780, 955, 866, 955, 955,
113539 /* 400 */ 955, 955, 955, 955, 955, 955, 955, 955, 743, 816,
113540 /* 410 */ 955, 815, 819, 814, 666, 955, 647, 955, 630, 635,
113541 /* 420 */ 951, 954, 953, 950, 949, 948, 943, 941, 938, 937,
113542 /* 430 */ 936, 934, 931, 927, 886, 884, 891, 890, 889, 888,
113543 /* 440 */ 887, 885, 883, 881, 802, 797, 794, 926, 879, 739,
113544 /* 450 */ 736, 735, 655, 944, 910, 919, 806, 805, 808, 916,
113545 /* 460 */ 915, 914, 912, 909, 896, 804, 803, 731, 871, 870,
113546 /* 470 */ 658, 900, 899, 898, 902, 906, 897, 767, 657, 654,
113547 /* 480 */ 663, 718, 719, 727, 725, 724, 723, 722, 721, 717,
113548 /* 490 */ 665, 673, 711, 696, 695, 876, 878, 875, 874, 704,
113549 /* 500 */ 703, 709, 708, 707, 706, 705, 702, 701, 700, 693,
113550 /* 510 */ 692, 698, 691, 714, 713, 710, 690, 734, 733, 732,
113551 /* 520 */ 729, 689, 688, 687, 819, 686, 685, 825, 824, 812,
113552 /* 530 */ 855, 754, 753, 752, 764, 763, 776, 775, 810, 809,
113553 /* 540 */ 777, 762, 756, 755, 771, 770, 769, 768, 760, 750,
113554 /* 550 */ 782, 784, 783, 781, 857, 766, 854, 925, 924, 923,
113555 /* 560 */ 922, 921, 859, 858, 826, 823, 677, 678, 894, 893,
113556 /* 570 */ 895, 892, 680, 679, 676, 675, 856, 745, 744, 852,
113557 /* 580 */ 849, 841, 837, 853, 850, 842, 838, 836, 835, 821,
113558 /* 590 */ 820, 818, 817, 813, 822, 668, 746, 742, 741, 811,
113559 /* 600 */ 748, 747, 684, 683, 681, 662, 660, 653, 651, 650,
113560 /* 610 */ 652, 648, 646, 645, 644, 643, 642, 671, 670, 669,
113561 /* 620 */ 667, 666, 640, 637, 636, 632, 631, 629,
 
113562 };
113563
113564 /* The next table maps tokens into fallback tokens. If a construct
113565 ** like the following:
113566 **
@@ -113573,75 +114938,76 @@
113573 */
113574 #ifdef YYFALLBACK
113575 static const YYCODETYPE yyFallback[] = {
113576 0, /* $ => nothing */
113577 0, /* SEMI => nothing */
113578 26, /* EXPLAIN => ID */
113579 26, /* QUERY => ID */
113580 26, /* PLAN => ID */
113581 26, /* BEGIN => ID */
113582 0, /* TRANSACTION => nothing */
113583 26, /* DEFERRED => ID */
113584 26, /* IMMEDIATE => ID */
113585 26, /* EXCLUSIVE => ID */
113586 0, /* COMMIT => nothing */
113587 26, /* END => ID */
113588 26, /* ROLLBACK => ID */
113589 26, /* SAVEPOINT => ID */
113590 26, /* RELEASE => ID */
113591 0, /* TO => nothing */
113592 0, /* TABLE => nothing */
113593 0, /* CREATE => nothing */
113594 26, /* IF => ID */
113595 0, /* NOT => nothing */
113596 0, /* EXISTS => nothing */
113597 26, /* TEMP => ID */
113598 0, /* LP => nothing */
113599 0, /* RP => nothing */
113600 0, /* AS => nothing */
 
113601 0, /* COMMA => nothing */
113602 0, /* ID => nothing */
113603 0, /* INDEXED => nothing */
113604 26, /* ABORT => ID */
113605 26, /* ACTION => ID */
113606 26, /* AFTER => ID */
113607 26, /* ANALYZE => ID */
113608 26, /* ASC => ID */
113609 26, /* ATTACH => ID */
113610 26, /* BEFORE => ID */
113611 26, /* BY => ID */
113612 26, /* CASCADE => ID */
113613 26, /* CAST => ID */
113614 26, /* COLUMNKW => ID */
113615 26, /* CONFLICT => ID */
113616 26, /* DATABASE => ID */
113617 26, /* DESC => ID */
113618 26, /* DETACH => ID */
113619 26, /* EACH => ID */
113620 26, /* FAIL => ID */
113621 26, /* FOR => ID */
113622 26, /* IGNORE => ID */
113623 26, /* INITIALLY => ID */
113624 26, /* INSTEAD => ID */
113625 26, /* LIKE_KW => ID */
113626 26, /* MATCH => ID */
113627 26, /* NO => ID */
113628 26, /* KEY => ID */
113629 26, /* OF => ID */
113630 26, /* OFFSET => ID */
113631 26, /* PRAGMA => ID */
113632 26, /* RAISE => ID */
113633 26, /* REPLACE => ID */
113634 26, /* RESTRICT => ID */
113635 26, /* ROW => ID */
113636 26, /* TRIGGER => ID */
113637 26, /* VACUUM => ID */
113638 26, /* VIEW => ID */
113639 26, /* VIRTUAL => ID */
113640 26, /* REINDEX => ID */
113641 26, /* RENAME => ID */
113642 26, /* CTIME_KW => ID */
113643 };
113644 #endif /* YYFALLBACK */
113645
113646 /* The following structure represents a single element of the
113647 ** parser's stack. Information stored includes:
@@ -113722,67 +115088,67 @@
113722 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
113723 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
113724 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
113725 "TABLE", "CREATE", "IF", "NOT",
113726 "EXISTS", "TEMP", "LP", "RP",
113727 "AS", "COMMA", "ID", "INDEXED",
113728 "ABORT", "ACTION", "AFTER", "ANALYZE",
113729 "ASC", "ATTACH", "BEFORE", "BY",
113730 "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
113731 "DATABASE", "DESC", "DETACH", "EACH",
113732 "FAIL", "FOR", "IGNORE", "INITIALLY",
113733 "INSTEAD", "LIKE_KW", "MATCH", "NO",
113734 "KEY", "OF", "OFFSET", "PRAGMA",
113735 "RAISE", "REPLACE", "RESTRICT", "ROW",
113736 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
113737 "REINDEX", "RENAME", "CTIME_KW", "ANY",
113738 "OR", "AND", "IS", "BETWEEN",
113739 "IN", "ISNULL", "NOTNULL", "NE",
113740 "EQ", "GT", "LE", "LT",
113741 "GE", "ESCAPE", "BITAND", "BITOR",
113742 "LSHIFT", "RSHIFT", "PLUS", "MINUS",
113743 "STAR", "SLASH", "REM", "CONCAT",
113744 "COLLATE", "BITNOT", "STRING", "JOIN_KW",
113745 "CONSTRAINT", "DEFAULT", "NULL", "PRIMARY",
113746 "UNIQUE", "CHECK", "REFERENCES", "AUTOINCR",
113747 "ON", "INSERT", "DELETE", "UPDATE",
113748 "SET", "DEFERRABLE", "FOREIGN", "DROP",
113749 "UNION", "ALL", "EXCEPT", "INTERSECT",
113750 "SELECT", "DISTINCT", "DOT", "FROM",
113751 "JOIN", "USING", "ORDER", "GROUP",
113752 "HAVING", "LIMIT", "WHERE", "INTO",
113753 "VALUES", "INTEGER", "FLOAT", "BLOB",
113754 "REGISTER", "VARIABLE", "CASE", "WHEN",
113755 "THEN", "ELSE", "INDEX", "ALTER",
113756 "ADD", "error", "input", "cmdlist",
113757 "ecmd", "explain", "cmdx", "cmd",
113758 "transtype", "trans_opt", "nm", "savepoint_opt",
113759 "create_table", "create_table_args", "createkw", "temp",
113760 "ifnotexists", "dbnm", "columnlist", "conslist_opt",
113761 "select", "column", "columnid", "type",
113762 "carglist", "id", "ids", "typetoken",
113763 "typename", "signed", "plus_num", "minus_num",
113764 "ccons", "term", "expr", "onconf",
113765 "sortorder", "autoinc", "idxlist_opt", "refargs",
113766 "defer_subclause", "refarg", "refact", "init_deferred_pred_opt",
113767 "conslist", "tconscomma", "tcons", "idxlist",
113768 "defer_subclause_opt", "orconf", "resolvetype", "raisetype",
113769 "ifexists", "fullname", "oneselect", "multiselect_op",
113770 "distinct", "selcollist", "from", "where_opt",
113771 "groupby_opt", "having_opt", "orderby_opt", "limit_opt",
113772 "sclp", "as", "seltablist", "stl_prefix",
113773 "joinop", "indexed_opt", "on_opt", "using_opt",
113774 "joinop2", "inscollist", "sortlist", "nexprlist",
113775 "setlist", "insert_cmd", "inscollist_opt", "valuelist",
113776 "exprlist", "likeop", "between_op", "in_op",
113777 "case_operand", "case_exprlist", "case_else", "uniqueflag",
113778 "collate", "nmnum", "number", "trigger_decl",
113779 "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause",
113780 "when_clause", "trigger_cmd", "trnm", "tridxby",
113781 "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt",
113782 "create_vtab", "vtabarglist", "vtabarg", "vtabargtoken",
113783 "lp", "anylist",
113784 };
113785 #endif /* NDEBUG */
113786
113787 #ifndef NDEBUG
113788 /* For tracing reduce actions, the names of all rules are required.
@@ -113818,305 +115184,307 @@
113818 /* 27 */ "createkw ::= CREATE",
113819 /* 28 */ "ifnotexists ::=",
113820 /* 29 */ "ifnotexists ::= IF NOT EXISTS",
113821 /* 30 */ "temp ::= TEMP",
113822 /* 31 */ "temp ::=",
113823 /* 32 */ "create_table_args ::= LP columnlist conslist_opt RP",
113824 /* 33 */ "create_table_args ::= AS select",
113825 /* 34 */ "columnlist ::= columnlist COMMA column",
113826 /* 35 */ "columnlist ::= column",
113827 /* 36 */ "column ::= columnid type carglist",
113828 /* 37 */ "columnid ::= nm",
113829 /* 38 */ "id ::= ID",
113830 /* 39 */ "id ::= INDEXED",
113831 /* 40 */ "ids ::= ID|STRING",
113832 /* 41 */ "nm ::= id",
113833 /* 42 */ "nm ::= STRING",
113834 /* 43 */ "nm ::= JOIN_KW",
113835 /* 44 */ "type ::=",
113836 /* 45 */ "type ::= typetoken",
113837 /* 46 */ "typetoken ::= typename",
113838 /* 47 */ "typetoken ::= typename LP signed RP",
113839 /* 48 */ "typetoken ::= typename LP signed COMMA signed RP",
113840 /* 49 */ "typename ::= ids",
113841 /* 50 */ "typename ::= typename ids",
113842 /* 51 */ "signed ::= plus_num",
113843 /* 52 */ "signed ::= minus_num",
113844 /* 53 */ "carglist ::= carglist ccons",
113845 /* 54 */ "carglist ::=",
113846 /* 55 */ "ccons ::= CONSTRAINT nm",
113847 /* 56 */ "ccons ::= DEFAULT term",
113848 /* 57 */ "ccons ::= DEFAULT LP expr RP",
113849 /* 58 */ "ccons ::= DEFAULT PLUS term",
113850 /* 59 */ "ccons ::= DEFAULT MINUS term",
113851 /* 60 */ "ccons ::= DEFAULT id",
113852 /* 61 */ "ccons ::= NULL onconf",
113853 /* 62 */ "ccons ::= NOT NULL onconf",
113854 /* 63 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
113855 /* 64 */ "ccons ::= UNIQUE onconf",
113856 /* 65 */ "ccons ::= CHECK LP expr RP",
113857 /* 66 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
113858 /* 67 */ "ccons ::= defer_subclause",
113859 /* 68 */ "ccons ::= COLLATE ids",
113860 /* 69 */ "autoinc ::=",
113861 /* 70 */ "autoinc ::= AUTOINCR",
113862 /* 71 */ "refargs ::=",
113863 /* 72 */ "refargs ::= refargs refarg",
113864 /* 73 */ "refarg ::= MATCH nm",
113865 /* 74 */ "refarg ::= ON INSERT refact",
113866 /* 75 */ "refarg ::= ON DELETE refact",
113867 /* 76 */ "refarg ::= ON UPDATE refact",
113868 /* 77 */ "refact ::= SET NULL",
113869 /* 78 */ "refact ::= SET DEFAULT",
113870 /* 79 */ "refact ::= CASCADE",
113871 /* 80 */ "refact ::= RESTRICT",
113872 /* 81 */ "refact ::= NO ACTION",
113873 /* 82 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
113874 /* 83 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
113875 /* 84 */ "init_deferred_pred_opt ::=",
113876 /* 85 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
113877 /* 86 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
113878 /* 87 */ "conslist_opt ::=",
113879 /* 88 */ "conslist_opt ::= COMMA conslist",
113880 /* 89 */ "conslist ::= conslist tconscomma tcons",
113881 /* 90 */ "conslist ::= tcons",
113882 /* 91 */ "tconscomma ::= COMMA",
113883 /* 92 */ "tconscomma ::=",
113884 /* 93 */ "tcons ::= CONSTRAINT nm",
113885 /* 94 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
113886 /* 95 */ "tcons ::= UNIQUE LP idxlist RP onconf",
113887 /* 96 */ "tcons ::= CHECK LP expr RP onconf",
113888 /* 97 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
113889 /* 98 */ "defer_subclause_opt ::=",
113890 /* 99 */ "defer_subclause_opt ::= defer_subclause",
113891 /* 100 */ "onconf ::=",
113892 /* 101 */ "onconf ::= ON CONFLICT resolvetype",
113893 /* 102 */ "orconf ::=",
113894 /* 103 */ "orconf ::= OR resolvetype",
113895 /* 104 */ "resolvetype ::= raisetype",
113896 /* 105 */ "resolvetype ::= IGNORE",
113897 /* 106 */ "resolvetype ::= REPLACE",
113898 /* 107 */ "cmd ::= DROP TABLE ifexists fullname",
113899 /* 108 */ "ifexists ::= IF EXISTS",
113900 /* 109 */ "ifexists ::=",
113901 /* 110 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select",
113902 /* 111 */ "cmd ::= DROP VIEW ifexists fullname",
113903 /* 112 */ "cmd ::= select",
113904 /* 113 */ "select ::= oneselect",
113905 /* 114 */ "select ::= select multiselect_op oneselect",
113906 /* 115 */ "multiselect_op ::= UNION",
113907 /* 116 */ "multiselect_op ::= UNION ALL",
113908 /* 117 */ "multiselect_op ::= EXCEPT|INTERSECT",
113909 /* 118 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
113910 /* 119 */ "distinct ::= DISTINCT",
113911 /* 120 */ "distinct ::= ALL",
113912 /* 121 */ "distinct ::=",
113913 /* 122 */ "sclp ::= selcollist COMMA",
113914 /* 123 */ "sclp ::=",
113915 /* 124 */ "selcollist ::= sclp expr as",
113916 /* 125 */ "selcollist ::= sclp STAR",
113917 /* 126 */ "selcollist ::= sclp nm DOT STAR",
113918 /* 127 */ "as ::= AS nm",
113919 /* 128 */ "as ::= ids",
113920 /* 129 */ "as ::=",
113921 /* 130 */ "from ::=",
113922 /* 131 */ "from ::= FROM seltablist",
113923 /* 132 */ "stl_prefix ::= seltablist joinop",
113924 /* 133 */ "stl_prefix ::=",
113925 /* 134 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
113926 /* 135 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
113927 /* 136 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
113928 /* 137 */ "dbnm ::=",
113929 /* 138 */ "dbnm ::= DOT nm",
113930 /* 139 */ "fullname ::= nm dbnm",
113931 /* 140 */ "joinop ::= COMMA|JOIN",
113932 /* 141 */ "joinop ::= JOIN_KW JOIN",
113933 /* 142 */ "joinop ::= JOIN_KW nm JOIN",
113934 /* 143 */ "joinop ::= JOIN_KW nm nm JOIN",
113935 /* 144 */ "on_opt ::= ON expr",
113936 /* 145 */ "on_opt ::=",
113937 /* 146 */ "indexed_opt ::=",
113938 /* 147 */ "indexed_opt ::= INDEXED BY nm",
113939 /* 148 */ "indexed_opt ::= NOT INDEXED",
113940 /* 149 */ "using_opt ::= USING LP inscollist RP",
113941 /* 150 */ "using_opt ::=",
113942 /* 151 */ "orderby_opt ::=",
113943 /* 152 */ "orderby_opt ::= ORDER BY sortlist",
113944 /* 153 */ "sortlist ::= sortlist COMMA expr sortorder",
113945 /* 154 */ "sortlist ::= expr sortorder",
113946 /* 155 */ "sortorder ::= ASC",
113947 /* 156 */ "sortorder ::= DESC",
113948 /* 157 */ "sortorder ::=",
113949 /* 158 */ "groupby_opt ::=",
113950 /* 159 */ "groupby_opt ::= GROUP BY nexprlist",
113951 /* 160 */ "having_opt ::=",
113952 /* 161 */ "having_opt ::= HAVING expr",
113953 /* 162 */ "limit_opt ::=",
113954 /* 163 */ "limit_opt ::= LIMIT expr",
113955 /* 164 */ "limit_opt ::= LIMIT expr OFFSET expr",
113956 /* 165 */ "limit_opt ::= LIMIT expr COMMA expr",
113957 /* 166 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
113958 /* 167 */ "where_opt ::=",
113959 /* 168 */ "where_opt ::= WHERE expr",
113960 /* 169 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
113961 /* 170 */ "setlist ::= setlist COMMA nm EQ expr",
113962 /* 171 */ "setlist ::= nm EQ expr",
113963 /* 172 */ "cmd ::= insert_cmd INTO fullname inscollist_opt valuelist",
113964 /* 173 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
113965 /* 174 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
113966 /* 175 */ "insert_cmd ::= INSERT orconf",
113967 /* 176 */ "insert_cmd ::= REPLACE",
113968 /* 177 */ "valuelist ::= VALUES LP nexprlist RP",
113969 /* 178 */ "valuelist ::= valuelist COMMA LP exprlist RP",
113970 /* 179 */ "inscollist_opt ::=",
113971 /* 180 */ "inscollist_opt ::= LP inscollist RP",
113972 /* 181 */ "inscollist ::= inscollist COMMA nm",
113973 /* 182 */ "inscollist ::= nm",
113974 /* 183 */ "expr ::= term",
113975 /* 184 */ "expr ::= LP expr RP",
113976 /* 185 */ "term ::= NULL",
113977 /* 186 */ "expr ::= id",
113978 /* 187 */ "expr ::= JOIN_KW",
113979 /* 188 */ "expr ::= nm DOT nm",
113980 /* 189 */ "expr ::= nm DOT nm DOT nm",
113981 /* 190 */ "term ::= INTEGER|FLOAT|BLOB",
113982 /* 191 */ "term ::= STRING",
113983 /* 192 */ "expr ::= REGISTER",
113984 /* 193 */ "expr ::= VARIABLE",
113985 /* 194 */ "expr ::= expr COLLATE ids",
113986 /* 195 */ "expr ::= CAST LP expr AS typetoken RP",
113987 /* 196 */ "expr ::= ID LP distinct exprlist RP",
113988 /* 197 */ "expr ::= ID LP STAR RP",
113989 /* 198 */ "term ::= CTIME_KW",
113990 /* 199 */ "expr ::= expr AND expr",
113991 /* 200 */ "expr ::= expr OR expr",
113992 /* 201 */ "expr ::= expr LT|GT|GE|LE expr",
113993 /* 202 */ "expr ::= expr EQ|NE expr",
113994 /* 203 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
113995 /* 204 */ "expr ::= expr PLUS|MINUS expr",
113996 /* 205 */ "expr ::= expr STAR|SLASH|REM expr",
113997 /* 206 */ "expr ::= expr CONCAT expr",
113998 /* 207 */ "likeop ::= LIKE_KW",
113999 /* 208 */ "likeop ::= NOT LIKE_KW",
114000 /* 209 */ "likeop ::= MATCH",
114001 /* 210 */ "likeop ::= NOT MATCH",
114002 /* 211 */ "expr ::= expr likeop expr",
114003 /* 212 */ "expr ::= expr likeop expr ESCAPE expr",
114004 /* 213 */ "expr ::= expr ISNULL|NOTNULL",
114005 /* 214 */ "expr ::= expr NOT NULL",
114006 /* 215 */ "expr ::= expr IS expr",
114007 /* 216 */ "expr ::= expr IS NOT expr",
114008 /* 217 */ "expr ::= NOT expr",
114009 /* 218 */ "expr ::= BITNOT expr",
114010 /* 219 */ "expr ::= MINUS expr",
114011 /* 220 */ "expr ::= PLUS expr",
114012 /* 221 */ "between_op ::= BETWEEN",
114013 /* 222 */ "between_op ::= NOT BETWEEN",
114014 /* 223 */ "expr ::= expr between_op expr AND expr",
114015 /* 224 */ "in_op ::= IN",
114016 /* 225 */ "in_op ::= NOT IN",
114017 /* 226 */ "expr ::= expr in_op LP exprlist RP",
114018 /* 227 */ "expr ::= LP select RP",
114019 /* 228 */ "expr ::= expr in_op LP select RP",
114020 /* 229 */ "expr ::= expr in_op nm dbnm",
114021 /* 230 */ "expr ::= EXISTS LP select RP",
114022 /* 231 */ "expr ::= CASE case_operand case_exprlist case_else END",
114023 /* 232 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
114024 /* 233 */ "case_exprlist ::= WHEN expr THEN expr",
114025 /* 234 */ "case_else ::= ELSE expr",
114026 /* 235 */ "case_else ::=",
114027 /* 236 */ "case_operand ::= expr",
114028 /* 237 */ "case_operand ::=",
114029 /* 238 */ "exprlist ::= nexprlist",
114030 /* 239 */ "exprlist ::=",
114031 /* 240 */ "nexprlist ::= nexprlist COMMA expr",
114032 /* 241 */ "nexprlist ::= expr",
114033 /* 242 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt",
114034 /* 243 */ "uniqueflag ::= UNIQUE",
114035 /* 244 */ "uniqueflag ::=",
114036 /* 245 */ "idxlist_opt ::=",
114037 /* 246 */ "idxlist_opt ::= LP idxlist RP",
114038 /* 247 */ "idxlist ::= idxlist COMMA nm collate sortorder",
114039 /* 248 */ "idxlist ::= nm collate sortorder",
114040 /* 249 */ "collate ::=",
114041 /* 250 */ "collate ::= COLLATE ids",
114042 /* 251 */ "cmd ::= DROP INDEX ifexists fullname",
114043 /* 252 */ "cmd ::= VACUUM",
114044 /* 253 */ "cmd ::= VACUUM nm",
114045 /* 254 */ "cmd ::= PRAGMA nm dbnm",
114046 /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
114047 /* 256 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
114048 /* 257 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
114049 /* 258 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
114050 /* 259 */ "nmnum ::= plus_num",
114051 /* 260 */ "nmnum ::= nm",
114052 /* 261 */ "nmnum ::= ON",
114053 /* 262 */ "nmnum ::= DELETE",
114054 /* 263 */ "nmnum ::= DEFAULT",
114055 /* 264 */ "plus_num ::= PLUS number",
114056 /* 265 */ "plus_num ::= number",
114057 /* 266 */ "minus_num ::= MINUS number",
114058 /* 267 */ "number ::= INTEGER|FLOAT",
114059 /* 268 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
114060 /* 269 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
114061 /* 270 */ "trigger_time ::= BEFORE",
114062 /* 271 */ "trigger_time ::= AFTER",
114063 /* 272 */ "trigger_time ::= INSTEAD OF",
114064 /* 273 */ "trigger_time ::=",
114065 /* 274 */ "trigger_event ::= DELETE|INSERT",
114066 /* 275 */ "trigger_event ::= UPDATE",
114067 /* 276 */ "trigger_event ::= UPDATE OF inscollist",
114068 /* 277 */ "foreach_clause ::=",
114069 /* 278 */ "foreach_clause ::= FOR EACH ROW",
114070 /* 279 */ "when_clause ::=",
114071 /* 280 */ "when_clause ::= WHEN expr",
114072 /* 281 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
114073 /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI",
114074 /* 283 */ "trnm ::= nm",
114075 /* 284 */ "trnm ::= nm DOT nm",
114076 /* 285 */ "tridxby ::=",
114077 /* 286 */ "tridxby ::= INDEXED BY nm",
114078 /* 287 */ "tridxby ::= NOT INDEXED",
114079 /* 288 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
114080 /* 289 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist",
114081 /* 290 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
114082 /* 291 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
114083 /* 292 */ "trigger_cmd ::= select",
114084 /* 293 */ "expr ::= RAISE LP IGNORE RP",
114085 /* 294 */ "expr ::= RAISE LP raisetype COMMA nm RP",
114086 /* 295 */ "raisetype ::= ROLLBACK",
114087 /* 296 */ "raisetype ::= ABORT",
114088 /* 297 */ "raisetype ::= FAIL",
114089 /* 298 */ "cmd ::= DROP TRIGGER ifexists fullname",
114090 /* 299 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
114091 /* 300 */ "cmd ::= DETACH database_kw_opt expr",
114092 /* 301 */ "key_opt ::=",
114093 /* 302 */ "key_opt ::= KEY expr",
114094 /* 303 */ "database_kw_opt ::= DATABASE",
114095 /* 304 */ "database_kw_opt ::=",
114096 /* 305 */ "cmd ::= REINDEX",
114097 /* 306 */ "cmd ::= REINDEX nm dbnm",
114098 /* 307 */ "cmd ::= ANALYZE",
114099 /* 308 */ "cmd ::= ANALYZE nm dbnm",
114100 /* 309 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
114101 /* 310 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
114102 /* 311 */ "add_column_fullname ::= fullname",
114103 /* 312 */ "kwcolumn_opt ::=",
114104 /* 313 */ "kwcolumn_opt ::= COLUMNKW",
114105 /* 314 */ "cmd ::= create_vtab",
114106 /* 315 */ "cmd ::= create_vtab LP vtabarglist RP",
114107 /* 316 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
114108 /* 317 */ "vtabarglist ::= vtabarg",
114109 /* 318 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
114110 /* 319 */ "vtabarg ::=",
114111 /* 320 */ "vtabarg ::= vtabarg vtabargtoken",
114112 /* 321 */ "vtabargtoken ::= ANY",
114113 /* 322 */ "vtabargtoken ::= lp anylist RP",
114114 /* 323 */ "lp ::= LP",
114115 /* 324 */ "anylist ::=",
114116 /* 325 */ "anylist ::= anylist LP anylist RP",
114117 /* 326 */ "anylist ::= anylist ANY",
 
 
114118 };
114119 #endif /* NDEBUG */
114120
114121
114122 #if YYSTACKDEPTH<=0
@@ -114191,80 +115559,80 @@
114191 **
114192 ** Note: during a reduce, the only symbols destroyed are those
114193 ** which appear on the RHS of the rule, but which are not used
114194 ** inside the C code.
114195 */
114196 case 160: /* select */
114197 case 194: /* oneselect */
114198 {
114199 sqlite3SelectDelete(pParse->db, (yypminor->yy159));
114200 }
114201 break;
114202 case 173: /* term */
114203 case 174: /* expr */
114204 {
114205 sqlite3ExprDelete(pParse->db, (yypminor->yy342).pExpr);
114206 }
114207 break;
114208 case 178: /* idxlist_opt */
114209 case 187: /* idxlist */
114210 case 197: /* selcollist */
114211 case 200: /* groupby_opt */
114212 case 202: /* orderby_opt */
114213 case 204: /* sclp */
114214 case 214: /* sortlist */
114215 case 215: /* nexprlist */
114216 case 216: /* setlist */
114217 case 220: /* exprlist */
114218 case 225: /* case_exprlist */
114219 {
114220 sqlite3ExprListDelete(pParse->db, (yypminor->yy442));
114221 }
114222 break;
114223 case 193: /* fullname */
114224 case 198: /* from */
114225 case 206: /* seltablist */
114226 case 207: /* stl_prefix */
114227 {
114228 sqlite3SrcListDelete(pParse->db, (yypminor->yy347));
114229 }
114230 break;
114231 case 199: /* where_opt */
114232 case 201: /* having_opt */
114233 case 210: /* on_opt */
114234 case 224: /* case_operand */
114235 case 226: /* case_else */
114236 case 236: /* when_clause */
114237 case 241: /* key_opt */
114238 {
114239 sqlite3ExprDelete(pParse->db, (yypminor->yy122));
114240 }
114241 break;
114242 case 211: /* using_opt */
114243 case 213: /* inscollist */
114244 case 218: /* inscollist_opt */
114245 {
114246 sqlite3IdListDelete(pParse->db, (yypminor->yy180));
114247 }
114248 break;
114249 case 219: /* valuelist */
114250 {
114251
114252 sqlite3ExprListDelete(pParse->db, (yypminor->yy487).pList);
114253 sqlite3SelectDelete(pParse->db, (yypminor->yy487).pSelect);
114254
114255 }
114256 break;
114257 case 232: /* trigger_cmd_list */
114258 case 237: /* trigger_cmd */
114259 {
114260 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy327));
114261 }
114262 break;
114263 case 234: /* trigger_event */
114264 {
114265 sqlite3IdListDelete(pParse->db, (yypminor->yy410).b);
114266 }
114267 break;
114268 default: break; /* If no destructor action specified: do nothing */
114269 }
114270 }
@@ -114505,337 +115873,339 @@
114505 */
114506 static const struct {
114507 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
114508 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
114509 } yyRuleInfo[] = {
114510 { 142, 1 },
114511 { 143, 2 },
114512 { 143, 1 },
114513 { 144, 1 },
114514 { 144, 3 },
114515 { 145, 0 },
114516 { 145, 1 },
114517 { 145, 3 },
114518 { 146, 1 },
114519 { 147, 3 },
114520 { 149, 0 },
114521 { 149, 1 },
114522 { 149, 2 },
114523 { 148, 0 },
114524 { 148, 1 },
114525 { 148, 1 },
114526 { 148, 1 },
114527 { 147, 2 },
114528 { 147, 2 },
114529 { 147, 2 },
114530 { 151, 1 },
114531 { 151, 0 },
114532 { 147, 2 },
114533 { 147, 3 },
114534 { 147, 5 },
114535 { 147, 2 },
114536 { 152, 6 },
114537 { 154, 1 },
114538 { 156, 0 },
114539 { 156, 3 },
114540 { 155, 1 },
114541 { 155, 0 },
114542 { 153, 4 },
114543 { 153, 2 },
114544 { 158, 3 },
114545 { 158, 1 },
114546 { 161, 3 },
114547 { 162, 1 },
114548 { 165, 1 },
114549 { 165, 1 },
114550 { 166, 1 },
114551 { 150, 1 },
114552 { 150, 1 },
114553 { 150, 1 },
114554 { 163, 0 },
114555 { 163, 1 },
114556 { 167, 1 },
114557 { 167, 4 },
114558 { 167, 6 },
114559 { 168, 1 },
114560 { 168, 2 },
114561 { 169, 1 },
114562 { 169, 1 },
114563 { 164, 2 },
114564 { 164, 0 },
114565 { 172, 2 },
114566 { 172, 2 },
114567 { 172, 4 },
114568 { 172, 3 },
114569 { 172, 3 },
114570 { 172, 2 },
114571 { 172, 2 },
114572 { 172, 3 },
114573 { 172, 5 },
114574 { 172, 2 },
114575 { 172, 4 },
114576 { 172, 4 },
114577 { 172, 1 },
114578 { 172, 2 },
114579 { 177, 0 },
114580 { 177, 1 },
114581 { 179, 0 },
114582 { 179, 2 },
114583 { 181, 2 },
114584 { 181, 3 },
114585 { 181, 3 },
114586 { 181, 3 },
114587 { 182, 2 },
114588 { 182, 2 },
114589 { 182, 1 },
114590 { 182, 1 },
114591 { 182, 2 },
114592 { 180, 3 },
114593 { 180, 2 },
114594 { 183, 0 },
114595 { 183, 2 },
114596 { 183, 2 },
114597 { 159, 0 },
114598 { 159, 2 },
114599 { 184, 3 },
114600 { 184, 1 },
114601 { 185, 1 },
114602 { 185, 0 },
114603 { 186, 2 },
114604 { 186, 7 },
114605 { 186, 5 },
114606 { 186, 5 },
114607 { 186, 10 },
114608 { 188, 0 },
114609 { 188, 1 },
114610 { 175, 0 },
114611 { 175, 3 },
114612 { 189, 0 },
114613 { 189, 2 },
114614 { 190, 1 },
114615 { 190, 1 },
114616 { 190, 1 },
114617 { 147, 4 },
114618 { 192, 2 },
114619 { 192, 0 },
114620 { 147, 8 },
114621 { 147, 4 },
114622 { 147, 1 },
114623 { 160, 1 },
114624 { 160, 3 },
114625 { 195, 1 },
114626 { 195, 2 },
114627 { 195, 1 },
114628 { 194, 9 },
114629 { 196, 1 },
114630 { 196, 1 },
114631 { 196, 0 },
114632 { 204, 2 },
114633 { 204, 0 },
114634 { 197, 3 },
114635 { 197, 2 },
114636 { 197, 4 },
114637 { 205, 2 },
114638 { 205, 1 },
114639 { 205, 0 },
114640 { 198, 0 },
114641 { 198, 2 },
114642 { 207, 2 },
114643 { 207, 0 },
114644 { 206, 7 },
114645 { 206, 7 },
114646 { 206, 7 },
114647 { 157, 0 },
114648 { 157, 2 },
114649 { 193, 2 },
114650 { 208, 1 },
114651 { 208, 2 },
114652 { 208, 3 },
114653 { 208, 4 },
114654 { 210, 2 },
114655 { 210, 0 },
114656 { 209, 0 },
114657 { 209, 3 },
114658 { 209, 2 },
114659 { 211, 4 },
114660 { 211, 0 },
114661 { 202, 0 },
114662 { 202, 3 },
114663 { 214, 4 },
114664 { 214, 2 },
114665 { 176, 1 },
114666 { 176, 1 },
114667 { 176, 0 },
114668 { 200, 0 },
114669 { 200, 3 },
114670 { 201, 0 },
114671 { 201, 2 },
114672 { 203, 0 },
114673 { 203, 2 },
114674 { 203, 4 },
114675 { 203, 4 },
114676 { 147, 5 },
114677 { 199, 0 },
114678 { 199, 2 },
114679 { 147, 7 },
114680 { 216, 5 },
114681 { 216, 3 },
114682 { 147, 5 },
114683 { 147, 5 },
114684 { 147, 6 },
114685 { 217, 2 },
114686 { 217, 1 },
114687 { 219, 4 },
114688 { 219, 5 },
114689 { 218, 0 },
114690 { 218, 3 },
114691 { 213, 3 },
114692 { 213, 1 },
114693 { 174, 1 },
114694 { 174, 3 },
114695 { 173, 1 },
114696 { 174, 1 },
114697 { 174, 1 },
114698 { 174, 3 },
114699 { 174, 5 },
114700 { 173, 1 },
114701 { 173, 1 },
114702 { 174, 1 },
114703 { 174, 1 },
114704 { 174, 3 },
114705 { 174, 6 },
114706 { 174, 5 },
114707 { 174, 4 },
114708 { 173, 1 },
114709 { 174, 3 },
114710 { 174, 3 },
114711 { 174, 3 },
114712 { 174, 3 },
114713 { 174, 3 },
114714 { 174, 3 },
114715 { 174, 3 },
114716 { 174, 3 },
114717 { 221, 1 },
114718 { 221, 2 },
114719 { 221, 1 },
114720 { 221, 2 },
114721 { 174, 3 },
114722 { 174, 5 },
114723 { 174, 2 },
114724 { 174, 3 },
114725 { 174, 3 },
114726 { 174, 4 },
114727 { 174, 2 },
114728 { 174, 2 },
114729 { 174, 2 },
114730 { 174, 2 },
114731 { 222, 1 },
114732 { 222, 2 },
114733 { 174, 5 },
114734 { 223, 1 },
114735 { 223, 2 },
114736 { 174, 5 },
114737 { 174, 3 },
114738 { 174, 5 },
114739 { 174, 4 },
114740 { 174, 4 },
114741 { 174, 5 },
114742 { 225, 5 },
114743 { 225, 4 },
114744 { 226, 2 },
114745 { 226, 0 },
114746 { 224, 1 },
114747 { 224, 0 },
114748 { 220, 1 },
114749 { 220, 0 },
114750 { 215, 3 },
114751 { 215, 1 },
114752 { 147, 12 },
114753 { 227, 1 },
114754 { 227, 0 },
114755 { 178, 0 },
114756 { 178, 3 },
114757 { 187, 5 },
114758 { 187, 3 },
114759 { 228, 0 },
114760 { 228, 2 },
114761 { 147, 4 },
114762 { 147, 1 },
114763 { 147, 2 },
114764 { 147, 3 },
114765 { 147, 5 },
114766 { 147, 6 },
114767 { 147, 5 },
114768 { 147, 6 },
114769 { 229, 1 },
114770 { 229, 1 },
114771 { 229, 1 },
114772 { 229, 1 },
114773 { 229, 1 },
114774 { 170, 2 },
114775 { 170, 1 },
114776 { 171, 2 },
114777 { 230, 1 },
114778 { 147, 5 },
114779 { 231, 11 },
114780 { 233, 1 },
114781 { 233, 1 },
114782 { 233, 2 },
114783 { 233, 0 },
114784 { 234, 1 },
114785 { 234, 1 },
114786 { 234, 3 },
114787 { 235, 0 },
114788 { 235, 3 },
114789 { 236, 0 },
114790 { 236, 2 },
114791 { 232, 3 },
114792 { 232, 2 },
114793 { 238, 1 },
114794 { 238, 3 },
114795 { 239, 0 },
114796 { 239, 3 },
114797 { 239, 2 },
114798 { 237, 7 },
114799 { 237, 5 },
114800 { 237, 5 },
114801 { 237, 5 },
114802 { 237, 1 },
114803 { 174, 4 },
114804 { 174, 6 },
114805 { 191, 1 },
114806 { 191, 1 },
114807 { 191, 1 },
114808 { 147, 4 },
114809 { 147, 6 },
114810 { 147, 3 },
114811 { 241, 0 },
114812 { 241, 2 },
114813 { 240, 1 },
114814 { 240, 0 },
114815 { 147, 1 },
114816 { 147, 3 },
114817 { 147, 1 },
114818 { 147, 3 },
114819 { 147, 6 },
114820 { 147, 6 },
114821 { 242, 1 },
114822 { 243, 0 },
114823 { 243, 1 },
114824 { 147, 1 },
114825 { 147, 4 },
114826 { 244, 8 },
114827 { 245, 1 },
114828 { 245, 3 },
114829 { 246, 0 },
114830 { 246, 2 },
114831 { 247, 1 },
114832 { 247, 3 },
114833 { 248, 1 },
114834 { 249, 0 },
114835 { 249, 4 },
114836 { 249, 2 },
 
 
114837 };
114838
114839 static void yy_accept(yyParser*); /* Forward Declaration */
114840
114841 /*
@@ -114899,21 +116269,21 @@
114899 break;
114900 case 8: /* cmdx ::= cmd */
114901 { sqlite3FinishCoding(pParse); }
114902 break;
114903 case 9: /* cmd ::= BEGIN transtype trans_opt */
114904 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy392);}
114905 break;
114906 case 13: /* transtype ::= */
114907 {yygotominor.yy392 = TK_DEFERRED;}
114908 break;
114909 case 14: /* transtype ::= DEFERRED */
114910 case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15);
114911 case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16);
114912 case 115: /* multiselect_op ::= UNION */ yytestcase(yyruleno==115);
114913 case 117: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==117);
114914 {yygotominor.yy392 = yymsp[0].major;}
114915 break;
114916 case 17: /* cmd ::= COMMIT trans_opt */
114917 case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18);
114918 {sqlite3CommitTransaction(pParse);}
114919 break;
@@ -114935,11 +116305,11 @@
114935 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
114936 }
114937 break;
114938 case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
114939 {
114940 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy392,0,0,yymsp[-2].minor.yy392);
114941 }
114942 break;
114943 case 27: /* createkw ::= CREATE */
114944 {
114945 pParse->db->lookaside.bEnabled = 0;
@@ -114946,1051 +116316,1064 @@
114946 yygotominor.yy0 = yymsp[0].minor.yy0;
114947 }
114948 break;
114949 case 28: /* ifnotexists ::= */
114950 case 31: /* temp ::= */ yytestcase(yyruleno==31);
114951 case 69: /* autoinc ::= */ yytestcase(yyruleno==69);
114952 case 82: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==82);
114953 case 84: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==84);
114954 case 86: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==86);
114955 case 98: /* defer_subclause_opt ::= */ yytestcase(yyruleno==98);
114956 case 109: /* ifexists ::= */ yytestcase(yyruleno==109);
114957 case 221: /* between_op ::= BETWEEN */ yytestcase(yyruleno==221);
114958 case 224: /* in_op ::= IN */ yytestcase(yyruleno==224);
114959 {yygotominor.yy392 = 0;}
114960 break;
114961 case 29: /* ifnotexists ::= IF NOT EXISTS */
114962 case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
114963 case 70: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==70);
114964 case 85: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==85);
114965 case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108);
114966 case 222: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==222);
114967 case 225: /* in_op ::= NOT IN */ yytestcase(yyruleno==225);
114968 {yygotominor.yy392 = 1;}
114969 break;
114970 case 32: /* create_table_args ::= LP columnlist conslist_opt RP */
114971 {
114972 sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
114973 }
114974 break;
114975 case 33: /* create_table_args ::= AS select */
114976 {
114977 sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy159);
114978 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
114979 }
114980 break;
114981 case 36: /* column ::= columnid type carglist */
 
 
 
 
 
 
 
 
 
 
 
 
 
114982 {
114983 yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
114984 yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
114985 }
114986 break;
114987 case 37: /* columnid ::= nm */
114988 {
114989 sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
114990 yygotominor.yy0 = yymsp[0].minor.yy0;
114991 pParse->constraintName.n = 0;
114992 }
114993 break;
114994 case 38: /* id ::= ID */
114995 case 39: /* id ::= INDEXED */ yytestcase(yyruleno==39);
114996 case 40: /* ids ::= ID|STRING */ yytestcase(yyruleno==40);
114997 case 41: /* nm ::= id */ yytestcase(yyruleno==41);
114998 case 42: /* nm ::= STRING */ yytestcase(yyruleno==42);
114999 case 43: /* nm ::= JOIN_KW */ yytestcase(yyruleno==43);
115000 case 46: /* typetoken ::= typename */ yytestcase(yyruleno==46);
115001 case 49: /* typename ::= ids */ yytestcase(yyruleno==49);
115002 case 127: /* as ::= AS nm */ yytestcase(yyruleno==127);
115003 case 128: /* as ::= ids */ yytestcase(yyruleno==128);
115004 case 138: /* dbnm ::= DOT nm */ yytestcase(yyruleno==138);
115005 case 147: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==147);
115006 case 250: /* collate ::= COLLATE ids */ yytestcase(yyruleno==250);
115007 case 259: /* nmnum ::= plus_num */ yytestcase(yyruleno==259);
115008 case 260: /* nmnum ::= nm */ yytestcase(yyruleno==260);
115009 case 261: /* nmnum ::= ON */ yytestcase(yyruleno==261);
115010 case 262: /* nmnum ::= DELETE */ yytestcase(yyruleno==262);
115011 case 263: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==263);
115012 case 264: /* plus_num ::= PLUS number */ yytestcase(yyruleno==264);
115013 case 265: /* plus_num ::= number */ yytestcase(yyruleno==265);
115014 case 266: /* minus_num ::= MINUS number */ yytestcase(yyruleno==266);
115015 case 267: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==267);
115016 case 283: /* trnm ::= nm */ yytestcase(yyruleno==283);
115017 {yygotominor.yy0 = yymsp[0].minor.yy0;}
115018 break;
115019 case 45: /* type ::= typetoken */
115020 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
115021 break;
115022 case 47: /* typetoken ::= typename LP signed RP */
115023 {
115024 yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
115025 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
115026 }
115027 break;
115028 case 48: /* typetoken ::= typename LP signed COMMA signed RP */
115029 {
115030 yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
115031 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
115032 }
115033 break;
115034 case 50: /* typename ::= typename ids */
115035 {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
115036 break;
115037 case 55: /* ccons ::= CONSTRAINT nm */
115038 case 93: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==93);
115039 {pParse->constraintName = yymsp[0].minor.yy0;}
115040 break;
115041 case 56: /* ccons ::= DEFAULT term */
115042 case 58: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==58);
115043 {sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy342);}
115044 break;
115045 case 57: /* ccons ::= DEFAULT LP expr RP */
115046 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy342);}
115047 break;
115048 case 59: /* ccons ::= DEFAULT MINUS term */
115049 {
115050 ExprSpan v;
115051 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy342.pExpr, 0, 0);
115052 v.zStart = yymsp[-1].minor.yy0.z;
115053 v.zEnd = yymsp[0].minor.yy342.zEnd;
115054 sqlite3AddDefaultValue(pParse,&v);
115055 }
115056 break;
115057 case 60: /* ccons ::= DEFAULT id */
115058 {
115059 ExprSpan v;
115060 spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0);
115061 sqlite3AddDefaultValue(pParse,&v);
115062 }
115063 break;
115064 case 62: /* ccons ::= NOT NULL onconf */
115065 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy392);}
115066 break;
115067 case 63: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
115068 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy392,yymsp[0].minor.yy392,yymsp[-2].minor.yy392);}
115069 break;
115070 case 64: /* ccons ::= UNIQUE onconf */
115071 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy392,0,0,0,0);}
115072 break;
115073 case 65: /* ccons ::= CHECK LP expr RP */
115074 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy342.pExpr);}
115075 break;
115076 case 66: /* ccons ::= REFERENCES nm idxlist_opt refargs */
115077 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy442,yymsp[0].minor.yy392);}
115078 break;
115079 case 67: /* ccons ::= defer_subclause */
115080 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy392);}
115081 break;
115082 case 68: /* ccons ::= COLLATE ids */
115083 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
115084 break;
115085 case 71: /* refargs ::= */
115086 { yygotominor.yy392 = OE_None*0x0101; /* EV: R-19803-45884 */}
115087 break;
115088 case 72: /* refargs ::= refargs refarg */
115089 { yygotominor.yy392 = (yymsp[-1].minor.yy392 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; }
115090 break;
115091 case 73: /* refarg ::= MATCH nm */
115092 case 74: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==74);
115093 { yygotominor.yy207.value = 0; yygotominor.yy207.mask = 0x000000; }
115094 break;
115095 case 75: /* refarg ::= ON DELETE refact */
115096 { yygotominor.yy207.value = yymsp[0].minor.yy392; yygotominor.yy207.mask = 0x0000ff; }
115097 break;
115098 case 76: /* refarg ::= ON UPDATE refact */
115099 { yygotominor.yy207.value = yymsp[0].minor.yy392<<8; yygotominor.yy207.mask = 0x00ff00; }
115100 break;
115101 case 77: /* refact ::= SET NULL */
115102 { yygotominor.yy392 = OE_SetNull; /* EV: R-33326-45252 */}
115103 break;
115104 case 78: /* refact ::= SET DEFAULT */
115105 { yygotominor.yy392 = OE_SetDflt; /* EV: R-33326-45252 */}
115106 break;
115107 case 79: /* refact ::= CASCADE */
115108 { yygotominor.yy392 = OE_Cascade; /* EV: R-33326-45252 */}
115109 break;
115110 case 80: /* refact ::= RESTRICT */
115111 { yygotominor.yy392 = OE_Restrict; /* EV: R-33326-45252 */}
115112 break;
115113 case 81: /* refact ::= NO ACTION */
115114 { yygotominor.yy392 = OE_None; /* EV: R-33326-45252 */}
115115 break;
115116 case 83: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
115117 case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99);
115118 case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101);
115119 case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104);
115120 {yygotominor.yy392 = yymsp[0].minor.yy392;}
115121 break;
115122 case 87: /* conslist_opt ::= */
115123 {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
115124 break;
115125 case 88: /* conslist_opt ::= COMMA conslist */
115126 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
115127 break;
115128 case 91: /* tconscomma ::= COMMA */
115129 {pParse->constraintName.n = 0;}
115130 break;
115131 case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
115132 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy442,yymsp[0].minor.yy392,yymsp[-2].minor.yy392,0);}
115133 break;
115134 case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */
115135 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy442,yymsp[0].minor.yy392,0,0,0,0);}
115136 break;
115137 case 96: /* tcons ::= CHECK LP expr RP onconf */
115138 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy342.pExpr);}
115139 break;
115140 case 97: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
115141 {
115142 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy442, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy442, yymsp[-1].minor.yy392);
115143 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy392);
115144 }
115145 break;
115146 case 100: /* onconf ::= */
115147 {yygotominor.yy392 = OE_Default;}
115148 break;
115149 case 102: /* orconf ::= */
115150 {yygotominor.yy258 = OE_Default;}
115151 break;
115152 case 103: /* orconf ::= OR resolvetype */
115153 {yygotominor.yy258 = (u8)yymsp[0].minor.yy392;}
115154 break;
115155 case 105: /* resolvetype ::= IGNORE */
115156 {yygotominor.yy392 = OE_Ignore;}
115157 break;
115158 case 106: /* resolvetype ::= REPLACE */
115159 {yygotominor.yy392 = OE_Replace;}
115160 break;
115161 case 107: /* cmd ::= DROP TABLE ifexists fullname */
115162 {
115163 sqlite3DropTable(pParse, yymsp[0].minor.yy347, 0, yymsp[-1].minor.yy392);
115164 }
115165 break;
115166 case 110: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
115167 {
115168 sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy159, yymsp[-6].minor.yy392, yymsp[-4].minor.yy392);
115169 }
115170 break;
115171 case 111: /* cmd ::= DROP VIEW ifexists fullname */
115172 {
115173 sqlite3DropTable(pParse, yymsp[0].minor.yy347, 1, yymsp[-1].minor.yy392);
115174 }
115175 break;
115176 case 112: /* cmd ::= select */
115177 {
115178 SelectDest dest = {SRT_Output, 0, 0, 0, 0};
115179 sqlite3Select(pParse, yymsp[0].minor.yy159, &dest);
115180 sqlite3ExplainBegin(pParse->pVdbe);
115181 sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy159);
115182 sqlite3ExplainFinish(pParse->pVdbe);
115183 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
115184 }
115185 break;
115186 case 113: /* select ::= oneselect */
115187 {yygotominor.yy159 = yymsp[0].minor.yy159;}
115188 break;
115189 case 114: /* select ::= select multiselect_op oneselect */
115190 {
115191 if( yymsp[0].minor.yy159 ){
115192 yymsp[0].minor.yy159->op = (u8)yymsp[-1].minor.yy392;
115193 yymsp[0].minor.yy159->pPrior = yymsp[-2].minor.yy159;
115194 if( yymsp[-1].minor.yy392!=TK_ALL ) pParse->hasCompound = 1;
115195 }else{
115196 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159);
115197 }
115198 yygotominor.yy159 = yymsp[0].minor.yy159;
115199 }
115200 break;
115201 case 116: /* multiselect_op ::= UNION ALL */
115202 {yygotominor.yy392 = TK_ALL;}
115203 break;
115204 case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
115205 {
115206 yygotominor.yy159 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy442,yymsp[-5].minor.yy347,yymsp[-4].minor.yy122,yymsp[-3].minor.yy442,yymsp[-2].minor.yy122,yymsp[-1].minor.yy442,yymsp[-7].minor.yy305,yymsp[0].minor.yy64.pLimit,yymsp[0].minor.yy64.pOffset);
115207 }
115208 break;
115209 case 119: /* distinct ::= DISTINCT */
115210 {yygotominor.yy305 = SF_Distinct;}
115211 break;
115212 case 120: /* distinct ::= ALL */
115213 case 121: /* distinct ::= */ yytestcase(yyruleno==121);
115214 {yygotominor.yy305 = 0;}
115215 break;
115216 case 122: /* sclp ::= selcollist COMMA */
115217 case 246: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==246);
115218 {yygotominor.yy442 = yymsp[-1].minor.yy442;}
115219 break;
115220 case 123: /* sclp ::= */
115221 case 151: /* orderby_opt ::= */ yytestcase(yyruleno==151);
115222 case 158: /* groupby_opt ::= */ yytestcase(yyruleno==158);
115223 case 239: /* exprlist ::= */ yytestcase(yyruleno==239);
115224 case 245: /* idxlist_opt ::= */ yytestcase(yyruleno==245);
115225 {yygotominor.yy442 = 0;}
115226 break;
115227 case 124: /* selcollist ::= sclp expr as */
115228 {
115229 yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy442, yymsp[-1].minor.yy342.pExpr);
115230 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[0].minor.yy0, 1);
115231 sqlite3ExprListSetSpan(pParse,yygotominor.yy442,&yymsp[-1].minor.yy342);
115232 }
115233 break;
115234 case 125: /* selcollist ::= sclp STAR */
115235 {
115236 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
115237 yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy442, p);
115238 }
115239 break;
115240 case 126: /* selcollist ::= sclp nm DOT STAR */
115241 {
115242 Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
115243 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
115244 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
115245 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442, pDot);
115246 }
115247 break;
115248 case 129: /* as ::= */
115249 {yygotominor.yy0.n = 0;}
115250 break;
115251 case 130: /* from ::= */
115252 {yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));}
115253 break;
115254 case 131: /* from ::= FROM seltablist */
115255 {
115256 yygotominor.yy347 = yymsp[0].minor.yy347;
115257 sqlite3SrcListShiftJoinType(yygotominor.yy347);
115258 }
115259 break;
115260 case 132: /* stl_prefix ::= seltablist joinop */
115261 {
115262 yygotominor.yy347 = yymsp[-1].minor.yy347;
115263 if( ALWAYS(yygotominor.yy347 && yygotominor.yy347->nSrc>0) ) yygotominor.yy347->a[yygotominor.yy347->nSrc-1].jointype = (u8)yymsp[0].minor.yy392;
115264 }
115265 break;
115266 case 133: /* stl_prefix ::= */
115267 {yygotominor.yy347 = 0;}
115268 break;
115269 case 134: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
115270 {
115271 yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
115272 sqlite3SrcListIndexedBy(pParse, yygotominor.yy347, &yymsp[-2].minor.yy0);
115273 }
115274 break;
115275 case 135: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
115276 {
115277 yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy159,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
115278 }
115279 break;
115280 case 136: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
115281 {
115282 if( yymsp[-6].minor.yy347==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy122==0 && yymsp[0].minor.yy180==0 ){
115283 yygotominor.yy347 = yymsp[-4].minor.yy347;
115284 }else if( yymsp[-4].minor.yy347->nSrc==1 ){
115285 yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
115286 if( yygotominor.yy347 ){
115287 struct SrcList_item *pNew = &yygotominor.yy347->a[yygotominor.yy347->nSrc-1];
115288 struct SrcList_item *pOld = yymsp[-4].minor.yy347->a;
115289 pNew->zName = pOld->zName;
115290 pNew->zDatabase = pOld->zDatabase;
115291 pNew->pSelect = pOld->pSelect;
115292 pOld->zName = pOld->zDatabase = 0;
115293 pOld->pSelect = 0;
115294 }
115295 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy347);
115296 }else{
115297 Select *pSubquery;
115298 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
115299 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy347,0,0,0,0,SF_NestedFrom,0,0);
115300 yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
115301 }
115302 }
115303 break;
115304 case 137: /* dbnm ::= */
115305 case 146: /* indexed_opt ::= */ yytestcase(yyruleno==146);
115306 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
115307 break;
115308 case 139: /* fullname ::= nm dbnm */
115309 {yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
115310 break;
115311 case 140: /* joinop ::= COMMA|JOIN */
115312 { yygotominor.yy392 = JT_INNER; }
115313 break;
115314 case 141: /* joinop ::= JOIN_KW JOIN */
115315 { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
115316 break;
115317 case 142: /* joinop ::= JOIN_KW nm JOIN */
115318 { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
115319 break;
115320 case 143: /* joinop ::= JOIN_KW nm nm JOIN */
115321 { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
115322 break;
115323 case 144: /* on_opt ::= ON expr */
115324 case 161: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==161);
115325 case 168: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==168);
115326 case 234: /* case_else ::= ELSE expr */ yytestcase(yyruleno==234);
115327 case 236: /* case_operand ::= expr */ yytestcase(yyruleno==236);
115328 {yygotominor.yy122 = yymsp[0].minor.yy342.pExpr;}
115329 break;
115330 case 145: /* on_opt ::= */
115331 case 160: /* having_opt ::= */ yytestcase(yyruleno==160);
115332 case 167: /* where_opt ::= */ yytestcase(yyruleno==167);
115333 case 235: /* case_else ::= */ yytestcase(yyruleno==235);
115334 case 237: /* case_operand ::= */ yytestcase(yyruleno==237);
115335 {yygotominor.yy122 = 0;}
115336 break;
115337 case 148: /* indexed_opt ::= NOT INDEXED */
115338 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
115339 break;
115340 case 149: /* using_opt ::= USING LP inscollist RP */
115341 case 180: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==180);
115342 {yygotominor.yy180 = yymsp[-1].minor.yy180;}
115343 break;
115344 case 150: /* using_opt ::= */
115345 case 179: /* inscollist_opt ::= */ yytestcase(yyruleno==179);
115346 {yygotominor.yy180 = 0;}
115347 break;
115348 case 152: /* orderby_opt ::= ORDER BY sortlist */
115349 case 159: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==159);
115350 case 238: /* exprlist ::= nexprlist */ yytestcase(yyruleno==238);
115351 {yygotominor.yy442 = yymsp[0].minor.yy442;}
115352 break;
115353 case 153: /* sortlist ::= sortlist COMMA expr sortorder */
115354 {
115355 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442,yymsp[-1].minor.yy342.pExpr);
115356 if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
115357 }
115358 break;
115359 case 154: /* sortlist ::= expr sortorder */
115360 {
115361 yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy342.pExpr);
115362 if( yygotominor.yy442 && ALWAYS(yygotominor.yy442->a) ) yygotominor.yy442->a[0].sortOrder = (u8)yymsp[0].minor.yy392;
115363 }
115364 break;
115365 case 155: /* sortorder ::= ASC */
115366 case 157: /* sortorder ::= */ yytestcase(yyruleno==157);
115367 {yygotominor.yy392 = SQLITE_SO_ASC;}
115368 break;
115369 case 156: /* sortorder ::= DESC */
115370 {yygotominor.yy392 = SQLITE_SO_DESC;}
115371 break;
115372 case 162: /* limit_opt ::= */
115373 {yygotominor.yy64.pLimit = 0; yygotominor.yy64.pOffset = 0;}
115374 break;
115375 case 163: /* limit_opt ::= LIMIT expr */
115376 {yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr; yygotominor.yy64.pOffset = 0;}
115377 break;
115378 case 164: /* limit_opt ::= LIMIT expr OFFSET expr */
115379 {yygotominor.yy64.pLimit = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pOffset = yymsp[0].minor.yy342.pExpr;}
115380 break;
115381 case 165: /* limit_opt ::= LIMIT expr COMMA expr */
115382 {yygotominor.yy64.pOffset = yymsp[-2].minor.yy342.pExpr; yygotominor.yy64.pLimit = yymsp[0].minor.yy342.pExpr;}
115383 break;
115384 case 166: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
115385 {
115386 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy347, &yymsp[-1].minor.yy0);
115387 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy347,yymsp[0].minor.yy122);
115388 }
115389 break;
115390 case 169: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
115391 {
115392 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy347, &yymsp[-3].minor.yy0);
115393 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy442,"set list");
115394 sqlite3Update(pParse,yymsp[-4].minor.yy347,yymsp[-1].minor.yy442,yymsp[0].minor.yy122,yymsp[-5].minor.yy258);
115395 }
115396 break;
115397 case 170: /* setlist ::= setlist COMMA nm EQ expr */
115398 {
115399 yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy442, yymsp[0].minor.yy342.pExpr);
115400 sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
115401 }
115402 break;
115403 case 171: /* setlist ::= nm EQ expr */
115404 {
115405 yygotominor.yy442 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy342.pExpr);
115406 sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
115407 }
115408 break;
115409 case 172: /* cmd ::= insert_cmd INTO fullname inscollist_opt valuelist */
115410 {sqlite3Insert(pParse, yymsp[-2].minor.yy347, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);}
115411 break;
115412 case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
115413 {sqlite3Insert(pParse, yymsp[-2].minor.yy347, 0, yymsp[0].minor.yy159, yymsp[-1].minor.yy180, yymsp[-4].minor.yy258);}
115414 break;
115415 case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
115416 {sqlite3Insert(pParse, yymsp[-3].minor.yy347, 0, 0, yymsp[-2].minor.yy180, yymsp[-5].minor.yy258);}
115417 break;
115418 case 175: /* insert_cmd ::= INSERT orconf */
115419 {yygotominor.yy258 = yymsp[0].minor.yy258;}
115420 break;
115421 case 176: /* insert_cmd ::= REPLACE */
115422 {yygotominor.yy258 = OE_Replace;}
115423 break;
115424 case 177: /* valuelist ::= VALUES LP nexprlist RP */
115425 {
115426 yygotominor.yy487.pList = yymsp[-1].minor.yy442;
115427 yygotominor.yy487.pSelect = 0;
115428 }
115429 break;
115430 case 178: /* valuelist ::= valuelist COMMA LP exprlist RP */
115431 {
115432 Select *pRight = sqlite3SelectNew(pParse, yymsp[-1].minor.yy442, 0, 0, 0, 0, 0, 0, 0, 0);
115433 if( yymsp[-4].minor.yy487.pList ){
115434 yymsp[-4].minor.yy487.pSelect = sqlite3SelectNew(pParse, yymsp[-4].minor.yy487.pList, 0, 0, 0, 0, 0, 0, 0, 0);
115435 yymsp[-4].minor.yy487.pList = 0;
115436 }
115437 yygotominor.yy487.pList = 0;
115438 if( yymsp[-4].minor.yy487.pSelect==0 || pRight==0 ){
115439 sqlite3SelectDelete(pParse->db, pRight);
115440 sqlite3SelectDelete(pParse->db, yymsp[-4].minor.yy487.pSelect);
115441 yygotominor.yy487.pSelect = 0;
115442 }else{
115443 pRight->op = TK_ALL;
115444 pRight->pPrior = yymsp[-4].minor.yy487.pSelect;
115445 pRight->selFlags |= SF_Values;
115446 pRight->pPrior->selFlags |= SF_Values;
115447 yygotominor.yy487.pSelect = pRight;
115448 }
115449 }
115450 break;
115451 case 181: /* inscollist ::= inscollist COMMA nm */
115452 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);}
115453 break;
115454 case 182: /* inscollist ::= nm */
115455 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
115456 break;
115457 case 183: /* expr ::= term */
115458 {yygotominor.yy342 = yymsp[0].minor.yy342;}
115459 break;
115460 case 184: /* expr ::= LP expr RP */
115461 {yygotominor.yy342.pExpr = yymsp[-1].minor.yy342.pExpr; spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
115462 break;
115463 case 185: /* term ::= NULL */
115464 case 190: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==190);
115465 case 191: /* term ::= STRING */ yytestcase(yyruleno==191);
115466 {spanExpr(&yygotominor.yy342, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
115467 break;
115468 case 186: /* expr ::= id */
115469 case 187: /* expr ::= JOIN_KW */ yytestcase(yyruleno==187);
115470 {spanExpr(&yygotominor.yy342, pParse, TK_ID, &yymsp[0].minor.yy0);}
115471 break;
115472 case 188: /* expr ::= nm DOT nm */
115473 {
115474 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
115475 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
115476 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
115477 spanSet(&yygotominor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
115478 }
115479 break;
115480 case 189: /* expr ::= nm DOT nm DOT nm */
115481 {
115482 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
115483 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
115484 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
115485 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
115486 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
115487 spanSet(&yygotominor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
115488 }
115489 break;
115490 case 192: /* expr ::= REGISTER */
115491 {
115492 /* When doing a nested parse, one can include terms in an expression
115493 ** that look like this: #1 #2 ... These terms refer to registers
115494 ** in the virtual machine. #N is the N-th register. */
115495 if( pParse->nested==0 ){
115496 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &yymsp[0].minor.yy0);
115497 yygotominor.yy342.pExpr = 0;
115498 }else{
115499 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
115500 if( yygotominor.yy342.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy342.pExpr->iTable);
115501 }
115502 spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
115503 }
115504 break;
115505 case 193: /* expr ::= VARIABLE */
115506 {
115507 spanExpr(&yygotominor.yy342, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
115508 sqlite3ExprAssignVarNumber(pParse, yygotominor.yy342.pExpr);
115509 spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
115510 }
115511 break;
115512 case 194: /* expr ::= expr COLLATE ids */
115513 {
115514 yygotominor.yy342.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0);
115515 yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart;
115516 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115517 }
115518 break;
115519 case 195: /* expr ::= CAST LP expr AS typetoken RP */
115520 {
115521 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy342.pExpr, 0, &yymsp[-1].minor.yy0);
115522 spanSet(&yygotominor.yy342,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
115523 }
115524 break;
115525 case 196: /* expr ::= ID LP distinct exprlist RP */
115526 {
115527 if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
115528 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
115529 }
115530 yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy442, &yymsp[-4].minor.yy0);
115531 spanSet(&yygotominor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
115532 if( yymsp[-2].minor.yy305 && yygotominor.yy342.pExpr ){
115533 yygotominor.yy342.pExpr->flags |= EP_Distinct;
115534 }
115535 }
115536 break;
115537 case 197: /* expr ::= ID LP STAR RP */
115538 {
115539 yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
115540 spanSet(&yygotominor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
115541 }
115542 break;
115543 case 198: /* term ::= CTIME_KW */
115544 {
115545 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
115546 ** treated as functions that return constants */
115547 yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
115548 if( yygotominor.yy342.pExpr ){
115549 yygotominor.yy342.pExpr->op = TK_CONST_FUNC;
115550 }
115551 spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
115552 }
115553 break;
115554 case 199: /* expr ::= expr AND expr */
115555 case 200: /* expr ::= expr OR expr */ yytestcase(yyruleno==200);
115556 case 201: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==201);
115557 case 202: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==202);
115558 case 203: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==203);
115559 case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204);
115560 case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205);
115561 case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206);
115562 {spanBinaryExpr(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);}
115563 break;
115564 case 207: /* likeop ::= LIKE_KW */
115565 case 209: /* likeop ::= MATCH */ yytestcase(yyruleno==209);
115566 {yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 0;}
115567 break;
115568 case 208: /* likeop ::= NOT LIKE_KW */
115569 case 210: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==210);
115570 {yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.bNot = 1;}
115571 break;
115572 case 211: /* expr ::= expr likeop expr */
115573 {
115574 ExprList *pList;
115575 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy342.pExpr);
115576 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy342.pExpr);
115577 yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy318.eOperator);
115578 if( yymsp[-1].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115579 yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart;
115580 yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
115581 if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc;
115582 }
115583 break;
115584 case 212: /* expr ::= expr likeop expr ESCAPE expr */
115585 {
115586 ExprList *pList;
115587 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
115588 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy342.pExpr);
115589 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr);
115590 yygotominor.yy342.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy318.eOperator);
115591 if( yymsp[-3].minor.yy318.bNot ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115592 yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115593 yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
115594 if( yygotominor.yy342.pExpr ) yygotominor.yy342.pExpr->flags |= EP_InfixFunc;
115595 }
115596 break;
115597 case 213: /* expr ::= expr ISNULL|NOTNULL */
115598 {spanUnaryPostfix(&yygotominor.yy342,pParse,yymsp[0].major,&yymsp[-1].minor.yy342,&yymsp[0].minor.yy0);}
115599 break;
115600 case 214: /* expr ::= expr NOT NULL */
115601 {spanUnaryPostfix(&yygotominor.yy342,pParse,TK_NOTNULL,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy0);}
115602 break;
115603 case 215: /* expr ::= expr IS expr */
115604 {
115605 spanBinaryExpr(&yygotominor.yy342,pParse,TK_IS,&yymsp[-2].minor.yy342,&yymsp[0].minor.yy342);
115606 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_ISNULL);
115607 }
115608 break;
115609 case 216: /* expr ::= expr IS NOT expr */
115610 {
115611 spanBinaryExpr(&yygotominor.yy342,pParse,TK_ISNOT,&yymsp[-3].minor.yy342,&yymsp[0].minor.yy342);
115612 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy342.pExpr, yygotominor.yy342.pExpr, TK_NOTNULL);
115613 }
115614 break;
115615 case 217: /* expr ::= NOT expr */
115616 case 218: /* expr ::= BITNOT expr */ yytestcase(yyruleno==218);
115617 {spanUnaryPrefix(&yygotominor.yy342,pParse,yymsp[-1].major,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
115618 break;
115619 case 219: /* expr ::= MINUS expr */
115620 {spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UMINUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
115621 break;
115622 case 220: /* expr ::= PLUS expr */
115623 {spanUnaryPrefix(&yygotominor.yy342,pParse,TK_UPLUS,&yymsp[0].minor.yy342,&yymsp[-1].minor.yy0);}
115624 break;
115625 case 223: /* expr ::= expr between_op expr AND expr */
115626 {
115627 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
115628 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy342.pExpr);
115629 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy342.pExpr, 0, 0);
115630 if( yygotominor.yy342.pExpr ){
115631 yygotominor.yy342.pExpr->x.pList = pList;
115632 }else{
115633 sqlite3ExprListDelete(pParse->db, pList);
115634 }
115635 if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115636 yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115637 yygotominor.yy342.zEnd = yymsp[0].minor.yy342.zEnd;
115638 }
115639 break;
115640 case 226: /* expr ::= expr in_op LP exprlist RP */
115641 {
115642 if( yymsp[-1].minor.yy442==0 ){
115643 /* Expressions of the form
115644 **
115645 ** expr1 IN ()
115646 ** expr1 NOT IN ()
115647 **
115648 ** simplify to constants 0 (false) and 1 (true), respectively,
115649 ** regardless of the value of expr1.
115650 */
115651 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy392]);
115652 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy342.pExpr);
115653 }else{
115654 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
115655 if( yygotominor.yy342.pExpr ){
115656 yygotominor.yy342.pExpr->x.pList = yymsp[-1].minor.yy442;
115657 sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115658 }else{
115659 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy442);
115660 }
115661 if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115662 }
115663 yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115664 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115665 }
115666 break;
115667 case 227: /* expr ::= LP select RP */
115668 {
115669 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
115670 if( yygotominor.yy342.pExpr ){
115671 yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
115672 ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
115673 sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115674 }else{
115675 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
115676 }
115677 yygotominor.yy342.zStart = yymsp[-2].minor.yy0.z;
115678 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115679 }
115680 break;
115681 case 228: /* expr ::= expr in_op LP select RP */
115682 {
115683 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
115684 if( yygotominor.yy342.pExpr ){
115685 yygotominor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
115686 ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
115687 sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115688 }else{
115689 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
115690 }
115691 if( yymsp[-3].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115692 yygotominor.yy342.zStart = yymsp[-4].minor.yy342.zStart;
115693 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115694 }
115695 break;
115696 case 229: /* expr ::= expr in_op nm dbnm */
115697 {
115698 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
115699 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
115700 if( yygotominor.yy342.pExpr ){
115701 yygotominor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
115702 ExprSetProperty(yygotominor.yy342.pExpr, EP_xIsSelect);
115703 sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115704 }else{
115705 sqlite3SrcListDelete(pParse->db, pSrc);
115706 }
115707 if( yymsp[-2].minor.yy392 ) yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy342.pExpr, 0, 0);
115708 yygotominor.yy342.zStart = yymsp[-3].minor.yy342.zStart;
115709 yygotominor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
115710 }
115711 break;
115712 case 230: /* expr ::= EXISTS LP select RP */
115713 {
115714 Expr *p = yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
115715 if( p ){
115716 p->x.pSelect = yymsp[-1].minor.yy159;
115717 ExprSetProperty(p, EP_xIsSelect);
115718 sqlite3ExprSetHeight(pParse, p);
115719 }else{
115720 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
115721 }
115722 yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z;
115723 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115724 }
115725 break;
115726 case 231: /* expr ::= CASE case_operand case_exprlist case_else END */
115727 {
115728 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, 0, 0);
115729 if( yygotominor.yy342.pExpr ){
115730 yygotominor.yy342.pExpr->x.pList = yymsp[-1].minor.yy122 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[-1].minor.yy122) : yymsp[-2].minor.yy442;
115731 sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115732 }else{
115733 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
115734 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy122);
115735 }
115736 yygotominor.yy342.zStart = yymsp[-4].minor.yy0.z;
115737 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115738 }
115739 break;
115740 case 232: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
115741 {
115742 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, yymsp[-2].minor.yy342.pExpr);
115743 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr);
115744 }
115745 break;
115746 case 233: /* case_exprlist ::= WHEN expr THEN expr */
115747 {
115748 yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy342.pExpr);
115749 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy342.pExpr);
115750 }
115751 break;
115752 case 240: /* nexprlist ::= nexprlist COMMA expr */
115753 {yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[0].minor.yy342.pExpr);}
115754 break;
115755 case 241: /* nexprlist ::= expr */
115756 {yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy342.pExpr);}
115757 break;
115758 case 242: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt */
115759 {
115760 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
115761 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy442, yymsp[-10].minor.yy392,
115762 &yymsp[-11].minor.yy0, yymsp[0].minor.yy122, SQLITE_SO_ASC, yymsp[-8].minor.yy392);
115763 }
115764 break;
115765 case 243: /* uniqueflag ::= UNIQUE */
115766 case 296: /* raisetype ::= ABORT */ yytestcase(yyruleno==296);
115767 {yygotominor.yy392 = OE_Abort;}
115768 break;
115769 case 244: /* uniqueflag ::= */
115770 {yygotominor.yy392 = OE_None;}
115771 break;
115772 case 247: /* idxlist ::= idxlist COMMA nm collate sortorder */
115773 {
115774 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
115775 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p);
115776 sqlite3ExprListSetName(pParse,yygotominor.yy442,&yymsp[-2].minor.yy0,1);
115777 sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
115778 if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
115779 }
115780 break;
115781 case 248: /* idxlist ::= nm collate sortorder */
115782 {
115783 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
115784 yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p);
115785 sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1);
115786 sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
115787 if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
115788 }
115789 break;
115790 case 249: /* collate ::= */
115791 {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
115792 break;
115793 case 251: /* cmd ::= DROP INDEX ifexists fullname */
115794 {sqlite3DropIndex(pParse, yymsp[0].minor.yy347, yymsp[-1].minor.yy392);}
115795 break;
115796 case 252: /* cmd ::= VACUUM */
115797 case 253: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==253);
115798 {sqlite3Vacuum(pParse);}
115799 break;
115800 case 254: /* cmd ::= PRAGMA nm dbnm */
115801 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
115802 break;
115803 case 255: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
115804 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
115805 break;
115806 case 256: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
115807 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
115808 break;
115809 case 257: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
115810 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
115811 break;
115812 case 258: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
115813 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
115814 break;
115815 case 268: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
115816 {
115817 Token all;
115818 all.z = yymsp[-3].minor.yy0.z;
115819 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
115820 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy327, &all);
115821 }
115822 break;
115823 case 269: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
115824 {
115825 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy392, yymsp[-4].minor.yy410.a, yymsp[-4].minor.yy410.b, yymsp[-2].minor.yy347, yymsp[0].minor.yy122, yymsp[-10].minor.yy392, yymsp[-8].minor.yy392);
115826 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
115827 }
115828 break;
115829 case 270: /* trigger_time ::= BEFORE */
115830 case 273: /* trigger_time ::= */ yytestcase(yyruleno==273);
115831 { yygotominor.yy392 = TK_BEFORE; }
115832 break;
115833 case 271: /* trigger_time ::= AFTER */
115834 { yygotominor.yy392 = TK_AFTER; }
115835 break;
115836 case 272: /* trigger_time ::= INSTEAD OF */
115837 { yygotominor.yy392 = TK_INSTEAD;}
115838 break;
115839 case 274: /* trigger_event ::= DELETE|INSERT */
115840 case 275: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==275);
115841 {yygotominor.yy410.a = yymsp[0].major; yygotominor.yy410.b = 0;}
115842 break;
115843 case 276: /* trigger_event ::= UPDATE OF inscollist */
115844 {yygotominor.yy410.a = TK_UPDATE; yygotominor.yy410.b = yymsp[0].minor.yy180;}
115845 break;
115846 case 279: /* when_clause ::= */
115847 case 301: /* key_opt ::= */ yytestcase(yyruleno==301);
115848 { yygotominor.yy122 = 0; }
115849 break;
115850 case 280: /* when_clause ::= WHEN expr */
115851 case 302: /* key_opt ::= KEY expr */ yytestcase(yyruleno==302);
115852 { yygotominor.yy122 = yymsp[0].minor.yy342.pExpr; }
115853 break;
115854 case 281: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
115855 {
115856 assert( yymsp[-2].minor.yy327!=0 );
115857 yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327;
115858 yymsp[-2].minor.yy327->pLast = yymsp[-1].minor.yy327;
115859 yygotominor.yy327 = yymsp[-2].minor.yy327;
115860 }
115861 break;
115862 case 282: /* trigger_cmd_list ::= trigger_cmd SEMI */
115863 {
115864 assert( yymsp[-1].minor.yy327!=0 );
115865 yymsp[-1].minor.yy327->pLast = yymsp[-1].minor.yy327;
115866 yygotominor.yy327 = yymsp[-1].minor.yy327;
115867 }
115868 break;
115869 case 284: /* trnm ::= nm DOT nm */
115870 {
115871 yygotominor.yy0 = yymsp[0].minor.yy0;
115872 sqlite3ErrorMsg(pParse,
115873 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
115874 "statements within triggers");
115875 }
115876 break;
115877 case 286: /* tridxby ::= INDEXED BY nm */
115878 {
115879 sqlite3ErrorMsg(pParse,
115880 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
115881 "within triggers");
115882 }
115883 break;
115884 case 287: /* tridxby ::= NOT INDEXED */
115885 {
115886 sqlite3ErrorMsg(pParse,
115887 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
115888 "within triggers");
115889 }
115890 break;
115891 case 288: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
115892 { yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-5].minor.yy258); }
115893 break;
115894 case 289: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist */
115895 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-4].minor.yy258);}
115896 break;
115897 case 290: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
115898 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy258);}
115899 break;
115900 case 291: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
115901 {yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy122);}
115902 break;
115903 case 292: /* trigger_cmd ::= select */
115904 {yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); }
115905 break;
115906 case 293: /* expr ::= RAISE LP IGNORE RP */
115907 {
115908 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
115909 if( yygotominor.yy342.pExpr ){
115910 yygotominor.yy342.pExpr->affinity = OE_Ignore;
115911 }
115912 yygotominor.yy342.zStart = yymsp[-3].minor.yy0.z;
115913 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115914 }
115915 break;
115916 case 294: /* expr ::= RAISE LP raisetype COMMA nm RP */
115917 {
115918 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
115919 if( yygotominor.yy342.pExpr ) {
115920 yygotominor.yy342.pExpr->affinity = (char)yymsp[-3].minor.yy392;
115921 }
115922 yygotominor.yy342.zStart = yymsp[-5].minor.yy0.z;
115923 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115924 }
115925 break;
115926 case 295: /* raisetype ::= ROLLBACK */
115927 {yygotominor.yy392 = OE_Rollback;}
115928 break;
115929 case 297: /* raisetype ::= FAIL */
115930 {yygotominor.yy392 = OE_Fail;}
115931 break;
115932 case 298: /* cmd ::= DROP TRIGGER ifexists fullname */
115933 {
115934 sqlite3DropTrigger(pParse,yymsp[0].minor.yy347,yymsp[-1].minor.yy392);
115935 }
115936 break;
115937 case 299: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
115938 {
115939 sqlite3Attach(pParse, yymsp[-3].minor.yy342.pExpr, yymsp[-1].minor.yy342.pExpr, yymsp[0].minor.yy122);
115940 }
115941 break;
115942 case 300: /* cmd ::= DETACH database_kw_opt expr */
115943 {
115944 sqlite3Detach(pParse, yymsp[0].minor.yy342.pExpr);
115945 }
115946 break;
115947 case 305: /* cmd ::= REINDEX */
115948 {sqlite3Reindex(pParse, 0, 0);}
115949 break;
115950 case 306: /* cmd ::= REINDEX nm dbnm */
115951 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
115952 break;
115953 case 307: /* cmd ::= ANALYZE */
115954 {sqlite3Analyze(pParse, 0, 0);}
115955 break;
115956 case 308: /* cmd ::= ANALYZE nm dbnm */
115957 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
115958 break;
115959 case 309: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
115960 {
115961 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy347,&yymsp[0].minor.yy0);
115962 }
115963 break;
115964 case 310: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
115965 {
115966 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
115967 }
115968 break;
115969 case 311: /* add_column_fullname ::= fullname */
115970 {
115971 pParse->db->lookaside.bEnabled = 0;
115972 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy347);
115973 }
115974 break;
115975 case 314: /* cmd ::= create_vtab */
115976 {sqlite3VtabFinishParse(pParse,0);}
115977 break;
115978 case 315: /* cmd ::= create_vtab LP vtabarglist RP */
115979 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
115980 break;
115981 case 316: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
115982 {
115983 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy392);
115984 }
115985 break;
115986 case 319: /* vtabarg ::= */
115987 {sqlite3VtabArgInit(pParse);}
115988 break;
115989 case 321: /* vtabargtoken ::= ANY */
115990 case 322: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==322);
115991 case 323: /* lp ::= LP */ yytestcase(yyruleno==323);
115992 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
115993 break;
115994 default:
115995 /* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
115996 /* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
@@ -116001,34 +117384,34 @@
116001 /* (11) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==11);
116002 /* (12) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==12);
116003 /* (20) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==20);
116004 /* (21) savepoint_opt ::= */ yytestcase(yyruleno==21);
116005 /* (25) cmd ::= create_table create_table_args */ yytestcase(yyruleno==25);
116006 /* (34) columnlist ::= columnlist COMMA column */ yytestcase(yyruleno==34);
116007 /* (35) columnlist ::= column */ yytestcase(yyruleno==35);
116008 /* (44) type ::= */ yytestcase(yyruleno==44);
116009 /* (51) signed ::= plus_num */ yytestcase(yyruleno==51);
116010 /* (52) signed ::= minus_num */ yytestcase(yyruleno==52);
116011 /* (53) carglist ::= carglist ccons */ yytestcase(yyruleno==53);
116012 /* (54) carglist ::= */ yytestcase(yyruleno==54);
116013 /* (61) ccons ::= NULL onconf */ yytestcase(yyruleno==61);
116014 /* (89) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==89);
116015 /* (90) conslist ::= tcons */ yytestcase(yyruleno==90);
116016 /* (92) tconscomma ::= */ yytestcase(yyruleno==92);
116017 /* (277) foreach_clause ::= */ yytestcase(yyruleno==277);
116018 /* (278) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==278);
116019 /* (285) tridxby ::= */ yytestcase(yyruleno==285);
116020 /* (303) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==303);
116021 /* (304) database_kw_opt ::= */ yytestcase(yyruleno==304);
116022 /* (312) kwcolumn_opt ::= */ yytestcase(yyruleno==312);
116023 /* (313) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==313);
116024 /* (317) vtabarglist ::= vtabarg */ yytestcase(yyruleno==317);
116025 /* (318) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==318);
116026 /* (320) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==320);
116027 /* (324) anylist ::= */ yytestcase(yyruleno==324);
116028 /* (325) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==325);
116029 /* (326) anylist ::= anylist ANY */ yytestcase(yyruleno==326);
116030 break;
116031 };
116032 assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
116033 yygoto = yyRuleInfo[yyruleno].lhs;
116034 yysize = yyRuleInfo[yyruleno].nrhs;
@@ -116363,24 +117746,24 @@
116363 ** might be implemented more directly using a hand-written hash table.
116364 ** But by using this automatically generated code, the size of the code
116365 ** is substantially reduced. This is important for embedded applications
116366 ** on platforms with limited memory.
116367 */
116368 /* Hash score: 175 */
116369 static int keywordCode(const char *z, int n){
116370 /* zText[] encodes 811 bytes of keywords in 541 bytes */
116371 /* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
116372 /* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
116373 /* XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY */
116374 /* UNIQUERYATTACHAVINGROUPDATEBEGINNERELEASEBETWEENOTNULLIKE */
116375 /* CASCADELETECASECOLLATECREATECURRENT_DATEDETACHIMMEDIATEJOIN */
116376 /* SERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHENWHERENAME */
116377 /* AFTEREPLACEANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSS */
116378 /* CURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAILFROMFULLGLOBYIF */
116379 /* ISNULLORDERESTRICTOUTERIGHTROLLBACKROWUNIONUSINGVACUUMVIEW */
116380 /* INITIALLY */
116381 static const char zText[540] = {
116382 'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
116383 'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
116384 'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
116385 'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
116386 'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
@@ -116387,105 +117770,106 @@
116387 'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
116388 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
116389 'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
116390 'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
116391 'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
116392 'U','E','R','Y','A','T','T','A','C','H','A','V','I','N','G','R','O','U',
116393 'P','D','A','T','E','B','E','G','I','N','N','E','R','E','L','E','A','S',
116394 'E','B','E','T','W','E','E','N','O','T','N','U','L','L','I','K','E','C',
116395 'A','S','C','A','D','E','L','E','T','E','C','A','S','E','C','O','L','L',
116396 'A','T','E','C','R','E','A','T','E','C','U','R','R','E','N','T','_','D',
116397 'A','T','E','D','E','T','A','C','H','I','M','M','E','D','I','A','T','E',
116398 'J','O','I','N','S','E','R','T','M','A','T','C','H','P','L','A','N','A',
116399 'L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U',
116400 'E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','W',
116401 'H','E','R','E','N','A','M','E','A','F','T','E','R','E','P','L','A','C',
116402 'E','A','N','D','E','F','A','U','L','T','A','U','T','O','I','N','C','R',
116403 'E','M','E','N','T','C','A','S','T','C','O','L','U','M','N','C','O','M',
116404 'M','I','T','C','O','N','F','L','I','C','T','C','R','O','S','S','C','U',
116405 'R','R','E','N','T','_','T','I','M','E','S','T','A','M','P','R','I','M',
116406 'A','R','Y','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T',
116407 'D','R','O','P','F','A','I','L','F','R','O','M','F','U','L','L','G','L',
116408 'O','B','Y','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S',
116409 'T','R','I','C','T','O','U','T','E','R','I','G','H','T','R','O','L','L',
116410 'B','A','C','K','R','O','W','U','N','I','O','N','U','S','I','N','G','V',
116411 'A','C','U','U','M','V','I','E','W','I','N','I','T','I','A','L','L','Y',
 
116412 };
116413 static const unsigned char aHash[127] = {
116414 72, 101, 114, 70, 0, 45, 0, 0, 78, 0, 73, 0, 0,
116415 42, 12, 74, 15, 0, 113, 81, 50, 108, 0, 19, 0, 0,
116416 118, 0, 116, 111, 0, 22, 89, 0, 9, 0, 0, 66, 67,
116417 0, 65, 6, 0, 48, 86, 98, 0, 115, 97, 0, 0, 44,
116418 0, 99, 24, 0, 17, 0, 119, 49, 23, 0, 5, 106, 25,
116419 92, 0, 0, 121, 102, 56, 120, 53, 28, 51, 0, 87, 0,
116420 96, 26, 0, 95, 0, 0, 0, 91, 88, 93, 84, 105, 14,
116421 39, 104, 0, 77, 0, 18, 85, 107, 32, 0, 117, 76, 109,
116422 58, 46, 80, 0, 0, 90, 40, 0, 112, 0, 36, 0, 0,
116423 29, 0, 82, 59, 60, 0, 20, 57, 0, 52,
116424 };
116425 static const unsigned char aNext[121] = {
116426 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
116427 0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
116428 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116429 0, 0, 0, 0, 33, 0, 21, 0, 0, 0, 43, 3, 47,
116430 0, 0, 0, 0, 30, 0, 54, 0, 38, 0, 0, 0, 1,
116431 62, 0, 0, 63, 0, 41, 0, 0, 0, 0, 0, 0, 0,
116432 61, 0, 0, 0, 0, 31, 55, 16, 34, 10, 0, 0, 0,
116433 0, 0, 0, 0, 11, 68, 75, 0, 8, 0, 100, 94, 0,
116434 103, 0, 83, 0, 71, 0, 0, 110, 27, 37, 69, 79, 0,
116435 35, 64, 0, 0,
116436 };
116437 static const unsigned char aLen[121] = {
116438 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
116439 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
116440 11, 6, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10,
116441 4, 6, 2, 3, 9, 4, 2, 6, 5, 6, 6, 5, 6,
116442 5, 5, 7, 7, 7, 3, 2, 4, 4, 7, 3, 6, 4,
116443 7, 6, 12, 6, 9, 4, 6, 5, 4, 7, 6, 5, 6,
116444 7, 5, 4, 5, 6, 5, 7, 3, 7, 13, 2, 2, 4,
116445 6, 6, 8, 5, 17, 12, 7, 8, 8, 2, 4, 4, 4,
116446 4, 4, 2, 2, 6, 5, 8, 5, 5, 8, 3, 5, 5,
116447 6, 4, 9, 3,
116448 };
116449 static const unsigned short int aOffset[121] = {
116450 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
116451 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
116452 86, 91, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152,
116453 159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 189, 194, 197,
116454 203, 206, 210, 217, 223, 223, 223, 226, 229, 233, 234, 238, 244,
116455 248, 255, 261, 273, 279, 288, 290, 296, 301, 303, 310, 315, 320,
116456 326, 332, 337, 341, 344, 350, 354, 361, 363, 370, 372, 374, 383,
116457 387, 393, 399, 407, 412, 412, 428, 435, 442, 443, 450, 454, 458,
116458 462, 466, 469, 471, 473, 479, 483, 491, 495, 500, 508, 511, 516,
116459 521, 527, 531, 536,
116460 };
116461 static const unsigned char aCode[121] = {
116462 TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
116463 TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
116464 TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
116465 TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
116466 TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
116467 TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
116468 TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT,
116469 TK_INTERSECT, TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO,
116470 TK_OFFSET, TK_OF, TK_SET, TK_TEMP, TK_TEMP,
116471 TK_OR, TK_UNIQUE, TK_QUERY, TK_ATTACH, TK_HAVING,
116472 TK_GROUP, TK_UPDATE, TK_BEGIN, TK_JOIN_KW, TK_RELEASE,
116473 TK_BETWEEN, TK_NOTNULL, TK_NOT, TK_NO, TK_NULL,
116474 TK_LIKE_KW, TK_CASCADE, TK_ASC, TK_DELETE, TK_CASE,
116475 TK_COLLATE, TK_CREATE, TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE,
116476 TK_JOIN, TK_INSERT, TK_MATCH, TK_PLAN, TK_ANALYZE,
116477 TK_PRAGMA, TK_ABORT, TK_VALUES, TK_VIRTUAL, TK_LIMIT,
116478 TK_WHEN, TK_WHERE, TK_RENAME, TK_AFTER, TK_REPLACE,
116479 TK_AND, TK_DEFAULT, TK_AUTOINCR, TK_TO, TK_IN,
116480 TK_CAST, TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, TK_JOIN_KW,
116481 TK_CTIME_KW, TK_CTIME_KW, TK_PRIMARY, TK_DEFERRED, TK_DISTINCT,
116482 TK_IS, TK_DROP, TK_FAIL, TK_FROM, TK_JOIN_KW,
116483 TK_LIKE_KW, TK_BY, TK_IF, TK_ISNULL, TK_ORDER,
116484 TK_RESTRICT, TK_JOIN_KW, TK_JOIN_KW, TK_ROLLBACK, TK_ROW,
116485 TK_UNION, TK_USING, TK_VACUUM, TK_VIEW, TK_INITIALLY,
116486 TK_ALL,
116487 };
116488 int h, i;
116489 if( n<2 ) return TK_ID;
116490 h = ((charMap(z[0])*4) ^
116491 (charMap(z[n-1])*3) ^
@@ -116538,92 +117922,93 @@
116538 testcase( i==43 ); /* TEMPORARY */
116539 testcase( i==44 ); /* TEMP */
116540 testcase( i==45 ); /* OR */
116541 testcase( i==46 ); /* UNIQUE */
116542 testcase( i==47 ); /* QUERY */
116543 testcase( i==48 ); /* ATTACH */
116544 testcase( i==49 ); /* HAVING */
116545 testcase( i==50 ); /* GROUP */
116546 testcase( i==51 ); /* UPDATE */
116547 testcase( i==52 ); /* BEGIN */
116548 testcase( i==53 ); /* INNER */
116549 testcase( i==54 ); /* RELEASE */
116550 testcase( i==55 ); /* BETWEEN */
116551 testcase( i==56 ); /* NOTNULL */
116552 testcase( i==57 ); /* NOT */
116553 testcase( i==58 ); /* NO */
116554 testcase( i==59 ); /* NULL */
116555 testcase( i==60 ); /* LIKE */
116556 testcase( i==61 ); /* CASCADE */
116557 testcase( i==62 ); /* ASC */
116558 testcase( i==63 ); /* DELETE */
116559 testcase( i==64 ); /* CASE */
116560 testcase( i==65 ); /* COLLATE */
116561 testcase( i==66 ); /* CREATE */
116562 testcase( i==67 ); /* CURRENT_DATE */
116563 testcase( i==68 ); /* DETACH */
116564 testcase( i==69 ); /* IMMEDIATE */
116565 testcase( i==70 ); /* JOIN */
116566 testcase( i==71 ); /* INSERT */
116567 testcase( i==72 ); /* MATCH */
116568 testcase( i==73 ); /* PLAN */
116569 testcase( i==74 ); /* ANALYZE */
116570 testcase( i==75 ); /* PRAGMA */
116571 testcase( i==76 ); /* ABORT */
116572 testcase( i==77 ); /* VALUES */
116573 testcase( i==78 ); /* VIRTUAL */
116574 testcase( i==79 ); /* LIMIT */
116575 testcase( i==80 ); /* WHEN */
116576 testcase( i==81 ); /* WHERE */
116577 testcase( i==82 ); /* RENAME */
116578 testcase( i==83 ); /* AFTER */
116579 testcase( i==84 ); /* REPLACE */
116580 testcase( i==85 ); /* AND */
116581 testcase( i==86 ); /* DEFAULT */
116582 testcase( i==87 ); /* AUTOINCREMENT */
116583 testcase( i==88 ); /* TO */
116584 testcase( i==89 ); /* IN */
116585 testcase( i==90 ); /* CAST */
116586 testcase( i==91 ); /* COLUMN */
116587 testcase( i==92 ); /* COMMIT */
116588 testcase( i==93 ); /* CONFLICT */
116589 testcase( i==94 ); /* CROSS */
116590 testcase( i==95 ); /* CURRENT_TIMESTAMP */
116591 testcase( i==96 ); /* CURRENT_TIME */
116592 testcase( i==97 ); /* PRIMARY */
116593 testcase( i==98 ); /* DEFERRED */
116594 testcase( i==99 ); /* DISTINCT */
116595 testcase( i==100 ); /* IS */
116596 testcase( i==101 ); /* DROP */
116597 testcase( i==102 ); /* FAIL */
116598 testcase( i==103 ); /* FROM */
116599 testcase( i==104 ); /* FULL */
116600 testcase( i==105 ); /* GLOB */
116601 testcase( i==106 ); /* BY */
116602 testcase( i==107 ); /* IF */
116603 testcase( i==108 ); /* ISNULL */
116604 testcase( i==109 ); /* ORDER */
116605 testcase( i==110 ); /* RESTRICT */
116606 testcase( i==111 ); /* OUTER */
116607 testcase( i==112 ); /* RIGHT */
116608 testcase( i==113 ); /* ROLLBACK */
116609 testcase( i==114 ); /* ROW */
116610 testcase( i==115 ); /* UNION */
116611 testcase( i==116 ); /* USING */
116612 testcase( i==117 ); /* VACUUM */
116613 testcase( i==118 ); /* VIEW */
116614 testcase( i==119 ); /* INITIALLY */
116615 testcase( i==120 ); /* ALL */
 
116616 return aCode[i];
116617 }
116618 }
116619 return TK_ID;
116620 }
116621 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
116622 return keywordCode((char*)z, n);
116623 }
116624 #define SQLITE_N_KEYWORD 121
116625
116626 /************** End of keywordhash.h *****************************************/
116627 /************** Continuing where we left off in tokenize.c *******************/
116628
116629
@@ -117066,11 +118451,10 @@
117066 }
117067
117068 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
117069 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
117070 sqlite3DbFree(db, pParse->azVar);
117071 sqlite3DbFree(db, pParse->aAlias);
117072 while( pParse->pAinc ){
117073 AutoincInfo *p = pParse->pAinc;
117074 pParse->pAinc = p->pNext;
117075 sqlite3DbFree(db, p);
117076 }
@@ -118594,10 +119978,11 @@
118594 case SQLITE_CONSTRAINT_COMMITHOOK:
118595 zName = "SQLITE_CONSTRAINT_COMMITHOOK"; break;
118596 case SQLITE_CONSTRAINT_VTAB: zName = "SQLITE_CONSTRAINT_VTAB"; break;
118597 case SQLITE_CONSTRAINT_FUNCTION:
118598 zName = "SQLITE_CONSTRAINT_FUNCTION"; break;
 
118599 case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
118600 case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
118601 case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
118602 case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
118603 case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
@@ -119408,10 +120793,36 @@
119408 ** function.
119409 */
119410 SQLITE_API const char *sqlite3_errstr(int rc){
119411 return sqlite3ErrStr(rc);
119412 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119413
119414 /*
119415 ** Create a new collating function for database "db". The name is zName
119416 ** and the encoding is enc.
119417 */
@@ -119453,10 +120864,11 @@
119453 sqlite3Error(db, SQLITE_BUSY,
119454 "unable to delete/modify collation sequence due to active statements");
119455 return SQLITE_BUSY;
119456 }
119457 sqlite3ExpirePreparedStatements(db);
 
119458
119459 /* If collation sequence pColl was created directly by a call to
119460 ** sqlite3_create_collation, and not generated by synthCollSeq(),
119461 ** then any copies made by synthCollSeq() need to be invalidated.
119462 ** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128435,10 +129847,15 @@
128435 }
128436 *ppCsr = pCsr;
128437 return rc;
128438 }
128439
 
 
 
 
 
128440
128441 /*
128442 ** Extract the next token from buffer z (length n) using the tokenizer
128443 ** and other information (column names etc.) in pParse. Create an Fts3Expr
128444 ** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
@@ -128469,11 +129886,35 @@
128469 const char *zToken;
128470 int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
128471 int nByte; /* total space to allocate */
128472
128473 rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
128474 if( rc==SQLITE_OK ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128475 nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
128476 pRet = (Fts3Expr *)fts3MallocZero(nByte);
128477 if( !pRet ){
128478 rc = SQLITE_NOMEM;
128479 }else{
@@ -128649,16 +130090,10 @@
128649 sqlite3_free(p);
128650 *ppExpr = 0;
128651 return SQLITE_NOMEM;
128652 }
128653
128654 /*
128655 ** Function getNextNode(), which is called by fts3ExprParse(), may itself
128656 ** call fts3ExprParse(). So this forward declaration is required.
128657 */
128658 static int fts3ExprParse(ParseContext *, const char *, int, Fts3Expr **, int *);
128659
128660 /*
128661 ** The output variable *ppExpr is populated with an allocated Fts3Expr
128662 ** structure, or set to 0 if the end of the input buffer is reached.
128663 **
128664 ** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM
@@ -128751,31 +130186,10 @@
128751 ** user has supplied a token such as "ORacle". Continue.
128752 */
128753 }
128754 }
128755
128756 /* Check for an open bracket. */
128757 if( sqlite3_fts3_enable_parentheses ){
128758 if( *zInput=='(' ){
128759 int nConsumed;
128760 pParse->nNest++;
128761 rc = fts3ExprParse(pParse, &zInput[1], nInput-1, ppExpr, &nConsumed);
128762 if( rc==SQLITE_OK && !*ppExpr ){
128763 rc = SQLITE_DONE;
128764 }
128765 *pnConsumed = (int)((zInput - z) + 1 + nConsumed);
128766 return rc;
128767 }
128768
128769 /* Check for a close bracket. */
128770 if( *zInput==')' ){
128771 pParse->nNest--;
128772 *pnConsumed = (int)((zInput - z) + 1);
128773 return SQLITE_DONE;
128774 }
128775 }
128776
128777 /* See if we are dealing with a quoted phrase. If this is the case, then
128778 ** search for the closing quote and pass the whole string to getNextString()
128779 ** for processing. This is easy to do, as fts3 has no syntax for escaping
128780 ** a quote character embedded in a string.
128781 */
128782
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
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-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -527,10 +527,11 @@
527 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
528 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
529 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
530 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
531 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
532 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
533 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
534 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
535 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
536
537 /*
@@ -938,10 +939,18 @@
939 ** pointer is overwritten with the old value. The limit is not changed if
940 ** the value originally pointed to is negative, and so the current limit
941 ** can be queried by passing in a pointer to a negative number. This
942 ** file-control is used internally to implement [PRAGMA mmap_size].
943 **
944 ** <li>[[SQLITE_FCNTL_TRACE]]
945 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
946 ** to the VFS about what the higher layers of the SQLite stack are doing.
947 ** This file control is used by some VFS activity tracing [shims].
948 ** The argument is a zero-terminated string. Higher layers in the
949 ** SQLite stack may generate instances of this file control if
950 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
951 **
952 ** </ul>
953 */
954 #define SQLITE_FCNTL_LOCKSTATE 1
955 #define SQLITE_GET_LOCKPROXYFILE 2
956 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -957,10 +966,11 @@
966 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
967 #define SQLITE_FCNTL_PRAGMA 14
968 #define SQLITE_FCNTL_BUSYHANDLER 15
969 #define SQLITE_FCNTL_TEMPFILENAME 16
970 #define SQLITE_FCNTL_MMAP_SIZE 18
971 #define SQLITE_FCNTL_TRACE 19
972
973 /*
974 ** CAPI3REF: Mutex Handle
975 **
976 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1803,23 +1813,25 @@
1813 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
1814
1815 /*
1816 ** CAPI3REF: Last Insert Rowid
1817 **
1818 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1819 ** has a unique 64-bit signed
1820 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1821 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1822 ** names are not also used by explicitly declared columns. ^If
1823 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1824 ** is another alias for the rowid.
1825 **
1826 ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
1827 ** most recent successful [INSERT] into a rowid table or [virtual table]
1828 ** on database connection D.
1829 ** ^Inserts into [WITHOUT ROWID] tables are not recorded.
1830 ** ^If no successful [INSERT]s into rowid tables
1831 ** have ever occurred on the database connection D,
1832 ** then sqlite3_last_insert_rowid(D) returns zero.
1833 **
1834 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1835 ** method, then this routine will return the [rowid] of the inserted
1836 ** row as long as the trigger or virtual table method is running.
1837 ** But once the trigger or virtual table method ends, the value returned
@@ -4832,16 +4844,17 @@
4844 /*
4845 ** CAPI3REF: Data Change Notification Callbacks
4846 **
4847 ** ^The sqlite3_update_hook() interface registers a callback function
4848 ** with the [database connection] identified by the first argument
4849 ** to be invoked whenever a row is updated, inserted or deleted in
4850 ** a rowid table.
4851 ** ^Any callback set by a previous call to this function
4852 ** for the same database connection is overridden.
4853 **
4854 ** ^The second argument is a pointer to the function to invoke when a
4855 ** row is updated, inserted or deleted in a rowid table.
4856 ** ^The first argument to the callback is a copy of the third argument
4857 ** to sqlite3_update_hook().
4858 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
4859 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
4860 ** to be invoked.
@@ -4850,10 +4863,11 @@
4863 ** ^The final callback parameter is the [rowid] of the row.
4864 ** ^In the case of an update, this is the [rowid] after the update takes place.
4865 **
4866 ** ^(The update hook is not invoked when internal system tables are
4867 ** modified (i.e. sqlite_master and sqlite_sequence).)^
4868 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
4869 **
4870 ** ^In the current implementation, the update hook
4871 ** is not invoked when duplication rows are deleted because of an
4872 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
4873 ** invoked when rows are deleted using the [truncate optimization].
@@ -5539,10 +5553,13 @@
5553 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5554 ** the opened blob. ^The size of a blob may not be changed by this
5555 ** interface. Use the [UPDATE] SQL command to change the size of a
5556 ** blob.
5557 **
5558 ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5559 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5560 **
5561 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5562 ** and the built-in [zeroblob] SQL function can be used, if desired,
5563 ** to create an empty, zero-filled blob in which to read or write using
5564 ** this interface.
5565 **
@@ -7756,10 +7773,17 @@
7773 #endif
7774 #if defined(NDEBUG) && defined(SQLITE_DEBUG)
7775 # undef NDEBUG
7776 #endif
7777
7778 /*
7779 ** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on.
7780 */
7781 #if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG)
7782 # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
7783 #endif
7784
7785 /*
7786 ** The testcase() macro is used to aid in coverage testing. When
7787 ** doing coverage testing, the condition inside the argument to
7788 ** testcase() must be evaluated both true and false in order to
7789 ** get full branch coverage. The testcase() macro is inserted
@@ -7972,143 +7996,144 @@
7996 #define TK_EXISTS 20
7997 #define TK_TEMP 21
7998 #define TK_LP 22
7999 #define TK_RP 23
8000 #define TK_AS 24
8001 #define TK_WITHOUT 25
8002 #define TK_COMMA 26
8003 #define TK_ID 27
8004 #define TK_INDEXED 28
8005 #define TK_ABORT 29
8006 #define TK_ACTION 30
8007 #define TK_AFTER 31
8008 #define TK_ANALYZE 32
8009 #define TK_ASC 33
8010 #define TK_ATTACH 34
8011 #define TK_BEFORE 35
8012 #define TK_BY 36
8013 #define TK_CASCADE 37
8014 #define TK_CAST 38
8015 #define TK_COLUMNKW 39
8016 #define TK_CONFLICT 40
8017 #define TK_DATABASE 41
8018 #define TK_DESC 42
8019 #define TK_DETACH 43
8020 #define TK_EACH 44
8021 #define TK_FAIL 45
8022 #define TK_FOR 46
8023 #define TK_IGNORE 47
8024 #define TK_INITIALLY 48
8025 #define TK_INSTEAD 49
8026 #define TK_LIKE_KW 50
8027 #define TK_MATCH 51
8028 #define TK_NO 52
8029 #define TK_KEY 53
8030 #define TK_OF 54
8031 #define TK_OFFSET 55
8032 #define TK_PRAGMA 56
8033 #define TK_RAISE 57
8034 #define TK_REPLACE 58
8035 #define TK_RESTRICT 59
8036 #define TK_ROW 60
8037 #define TK_TRIGGER 61
8038 #define TK_VACUUM 62
8039 #define TK_VIEW 63
8040 #define TK_VIRTUAL 64
8041 #define TK_REINDEX 65
8042 #define TK_RENAME 66
8043 #define TK_CTIME_KW 67
8044 #define TK_ANY 68
8045 #define TK_OR 69
8046 #define TK_AND 70
8047 #define TK_IS 71
8048 #define TK_BETWEEN 72
8049 #define TK_IN 73
8050 #define TK_ISNULL 74
8051 #define TK_NOTNULL 75
8052 #define TK_NE 76
8053 #define TK_EQ 77
8054 #define TK_GT 78
8055 #define TK_LE 79
8056 #define TK_LT 80
8057 #define TK_GE 81
8058 #define TK_ESCAPE 82
8059 #define TK_BITAND 83
8060 #define TK_BITOR 84
8061 #define TK_LSHIFT 85
8062 #define TK_RSHIFT 86
8063 #define TK_PLUS 87
8064 #define TK_MINUS 88
8065 #define TK_STAR 89
8066 #define TK_SLASH 90
8067 #define TK_REM 91
8068 #define TK_CONCAT 92
8069 #define TK_COLLATE 93
8070 #define TK_BITNOT 94
8071 #define TK_STRING 95
8072 #define TK_JOIN_KW 96
8073 #define TK_CONSTRAINT 97
8074 #define TK_DEFAULT 98
8075 #define TK_NULL 99
8076 #define TK_PRIMARY 100
8077 #define TK_UNIQUE 101
8078 #define TK_CHECK 102
8079 #define TK_REFERENCES 103
8080 #define TK_AUTOINCR 104
8081 #define TK_ON 105
8082 #define TK_INSERT 106
8083 #define TK_DELETE 107
8084 #define TK_UPDATE 108
8085 #define TK_SET 109
8086 #define TK_DEFERRABLE 110
8087 #define TK_FOREIGN 111
8088 #define TK_DROP 112
8089 #define TK_UNION 113
8090 #define TK_ALL 114
8091 #define TK_EXCEPT 115
8092 #define TK_INTERSECT 116
8093 #define TK_SELECT 117
8094 #define TK_DISTINCT 118
8095 #define TK_DOT 119
8096 #define TK_FROM 120
8097 #define TK_JOIN 121
8098 #define TK_USING 122
8099 #define TK_ORDER 123
8100 #define TK_GROUP 124
8101 #define TK_HAVING 125
8102 #define TK_LIMIT 126
8103 #define TK_WHERE 127
8104 #define TK_INTO 128
8105 #define TK_VALUES 129
8106 #define TK_INTEGER 130
8107 #define TK_FLOAT 131
8108 #define TK_BLOB 132
8109 #define TK_REGISTER 133
8110 #define TK_VARIABLE 134
8111 #define TK_CASE 135
8112 #define TK_WHEN 136
8113 #define TK_THEN 137
8114 #define TK_ELSE 138
8115 #define TK_INDEX 139
8116 #define TK_ALTER 140
8117 #define TK_ADD 141
8118 #define TK_TO_TEXT 142
8119 #define TK_TO_BLOB 143
8120 #define TK_TO_NUMERIC 144
8121 #define TK_TO_INT 145
8122 #define TK_TO_REAL 146
8123 #define TK_ISNOT 147
8124 #define TK_END_OF_FILE 148
8125 #define TK_ILLEGAL 149
8126 #define TK_SPACE 150
8127 #define TK_UNCLOSED_STRING 151
8128 #define TK_FUNCTION 152
8129 #define TK_COLUMN 153
8130 #define TK_AGG_FUNCTION 154
8131 #define TK_AGG_COLUMN 155
8132 #define TK_CONST_FUNC 156
8133 #define TK_UMINUS 157
8134 #define TK_UPLUS 158
8135
8136 /************** End of parse.h ***********************************************/
8137 /************** Continuing where we left off in sqliteInt.h ******************/
8138 #include <stdio.h>
8139 #include <stdlib.h>
@@ -8881,11 +8906,11 @@
8906 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
8907 int *ai; /* Used when p4type is P4_INTARRAY */
8908 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
8909 int (*xAdvance)(BtCursor *, int *);
8910 } p4;
8911 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
8912 char *zComment; /* Comment to improve readability */
8913 #endif
8914 #ifdef VDBE_PROFILE
8915 int cnt; /* Number of times this instruction was executed */
8916 u64 cycles; /* Total time spent executing this instruction */
@@ -8937,19 +8962,15 @@
8962 #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
8963 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
8964 #define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */
8965 #define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
8966
8967 /* Error message codes for OP_Halt */
8968 #define P5_ConstraintNotNull 1
8969 #define P5_ConstraintUnique 2
8970 #define P5_ConstraintCheck 3
8971 #define P5_ConstraintFK 4
 
 
 
 
8972
8973 /*
8974 ** The Vdbe.aColName array contains 5n Mem structures, where n is the
8975 ** number of columns of data returned by the statement.
8976 */
@@ -8982,160 +9003,160 @@
9003 */
9004 /************** Include opcodes.h in the middle of vdbe.h ********************/
9005 /************** Begin file opcodes.h *****************************************/
9006 /* Automatically generated. Do not edit */
9007 /* See the mkopcodeh.awk script for details */
9008 #define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
9009 #define OP_Savepoint 2
9010 #define OP_AutoCommit 3
9011 #define OP_Transaction 4
9012 #define OP_SorterNext 5
9013 #define OP_Prev 6
9014 #define OP_Next 7
9015 #define OP_AggStep 8 /* synopsis: accum=r[P3] step(r[P2@P5]) */
9016 #define OP_Checkpoint 9
9017 #define OP_JournalMode 10
9018 #define OP_Vacuum 11
9019 #define OP_VFilter 12 /* synopsis: iPlan=r[P3] zPlan='P4' */
9020 #define OP_VUpdate 13 /* synopsis: data=r[P3@P2] */
9021 #define OP_Goto 14
9022 #define OP_Gosub 15
9023 #define OP_Return 16
9024 #define OP_Yield 17
9025 #define OP_HaltIfNull 18 /* synopsis: if r[P3] null then halt */
9026 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9027 #define OP_Halt 20
9028 #define OP_Integer 21 /* synopsis: r[P2]=P1 */
9029 #define OP_Int64 22 /* synopsis: r[P2]=P4 */
9030 #define OP_String 23 /* synopsis: r[P2]='P4' (len=P1) */
9031 #define OP_Null 24 /* synopsis: r[P2..P3]=NULL */
9032 #define OP_Blob 25 /* synopsis: r[P2]=P4 (len=P1) */
9033 #define OP_Variable 26 /* synopsis: r[P2]=parameter(P1,P4) */
9034 #define OP_Move 27 /* synopsis: r[P2@P3]=r[P1@P3] */
9035 #define OP_Copy 28 /* synopsis: r[P2@P3]=r[P1@P3] */
9036 #define OP_SCopy 29 /* synopsis: r[P2]=r[P1] */
9037 #define OP_ResultRow 30 /* synopsis: output=r[P1@P2] */
9038 #define OP_CollSeq 31
9039 #define OP_AddImm 32 /* synopsis: r[P1]=r[P1]+P2 */
9040 #define OP_MustBeInt 33
9041 #define OP_RealAffinity 34
9042 #define OP_Permutation 35
9043 #define OP_Compare 36
9044 #define OP_Jump 37
9045 #define OP_Once 38
9046 #define OP_If 39
9047 #define OP_IfNot 40
9048 #define OP_Column 41 /* synopsis: r[P3]=PX */
9049 #define OP_Affinity 42 /* synopsis: affinity(r[P1@P2]) */
9050 #define OP_MakeRecord 43 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9051 #define OP_Count 44 /* synopsis: r[P2]=count() */
9052 #define OP_ReadCookie 45
9053 #define OP_SetCookie 46
9054 #define OP_VerifyCookie 47
9055 #define OP_OpenRead 48 /* synopsis: root=P2 iDb=P3 */
9056 #define OP_OpenWrite 49 /* synopsis: root=P2 iDb=P3 */
9057 #define OP_OpenAutoindex 50 /* synopsis: nColumn=P2 */
9058 #define OP_OpenEphemeral 51 /* synopsis: nColumn=P2 */
9059 #define OP_SorterOpen 52
9060 #define OP_OpenPseudo 53 /* synopsis: content in r[P2@P3] */
9061 #define OP_Close 54
9062 #define OP_SeekLt 55 /* synopsis: key=r[P3@P4] */
9063 #define OP_SeekLe 56 /* synopsis: key=r[P3@P4] */
9064 #define OP_SeekGe 57 /* synopsis: key=r[P3@P4] */
9065 #define OP_SeekGt 58 /* synopsis: key=r[P3@P4] */
9066 #define OP_Seek 59 /* synopsis: intkey=r[P2] */
9067 #define OP_NoConflict 60 /* synopsis: key=r[P3@P4] */
9068 #define OP_NotFound 61 /* synopsis: key=r[P3@P4] */
9069 #define OP_Found 62 /* synopsis: key=r[P3@P4] */
9070 #define OP_NotExists 63 /* synopsis: intkey=r[P3] */
9071 #define OP_Sequence 64 /* synopsis: r[P2]=rowid */
9072 #define OP_NewRowid 65 /* synopsis: r[P2]=rowid */
9073 #define OP_Insert 66 /* synopsis: intkey=r[P3] data=r[P2] */
9074 #define OP_InsertInt 67 /* synopsis: intkey=P3 data=r[P2] */
9075 #define OP_Delete 68
9076 #define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9077 #define OP_And 70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9078 #define OP_ResetCount 71
9079 #define OP_SorterCompare 72 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9080 #define OP_SorterData 73 /* synopsis: r[P2]=data */
9081 #define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9082 #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9083 #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9084 #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9085 #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9086 #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9087 #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P3 */
9088 #define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9089 #define OP_RowKey 82 /* synopsis: r[P2]=key */
9090 #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9091 #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9092 #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9093 #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9094 #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
9095 #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9096 #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9097 #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P1]/r[P2] */
9098 #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P1]%r[P2] */
9099 #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9100 #define OP_RowData 93 /* synopsis: r[P2]=data */
9101 #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9102 #define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
9103 #define OP_Rowid 96 /* synopsis: r[P2]=rowid */
9104 #define OP_NullRow 97
9105 #define OP_Last 98
9106 #define OP_SorterSort 99
9107 #define OP_Sort 100
9108 #define OP_Rewind 101
9109 #define OP_SorterInsert 102
9110 #define OP_IdxInsert 103 /* synopsis: key=r[P2] */
9111 #define OP_IdxDelete 104 /* synopsis: key=r[P2@P3] */
9112 #define OP_IdxRowid 105 /* synopsis: r[P2]=rowid */
9113 #define OP_IdxLT 106 /* synopsis: key=r[P3@P4] */
9114 #define OP_IdxGE 107 /* synopsis: key=r[P3@P4] */
9115 #define OP_Destroy 108
9116 #define OP_Clear 109
9117 #define OP_CreateIndex 110 /* synopsis: r[P2]=root iDb=P1 */
9118 #define OP_CreateTable 111 /* synopsis: r[P2]=root iDb=P1 */
9119 #define OP_ParseSchema 112
9120 #define OP_LoadAnalysis 113
9121 #define OP_DropTable 114
9122 #define OP_DropIndex 115
9123 #define OP_DropTrigger 116
9124 #define OP_IntegrityCk 117
9125 #define OP_RowSetAdd 118 /* synopsis: rowset(P1)=r[P2] */
9126 #define OP_RowSetRead 119 /* synopsis: r[P3]=rowset(P1) */
9127 #define OP_RowSetTest 120 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9128 #define OP_Program 121
9129 #define OP_Param 122
9130 #define OP_FkCounter 123 /* synopsis: fkctr[P1]+=P2 */
9131 #define OP_FkIfZero 124 /* synopsis: if fkctr[P1]==0 goto P2 */
9132 #define OP_MemMax 125 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9133 #define OP_IfPos 126 /* synopsis: if r[P1]>0 goto P2 */
9134 #define OP_IfNeg 127 /* synopsis: if r[P1]<0 goto P2 */
9135 #define OP_IfZero 128 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9136 #define OP_AggFinal 129 /* synopsis: accum=r[P1] N=P2 */
9137 #define OP_IncrVacuum 130
9138 #define OP_Real 131 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9139 #define OP_Expire 132
9140 #define OP_TableLock 133 /* synopsis: iDb=P1 root=P2 write=P3 */
9141 #define OP_VBegin 134
9142 #define OP_VCreate 135
9143 #define OP_VDestroy 136
9144 #define OP_VOpen 137
9145 #define OP_VColumn 138 /* synopsis: r[P3]=vcolumn(P2) */
9146 #define OP_VNext 139
9147 #define OP_VRename 140
9148 #define OP_Pagecount 141
9149 #define OP_ToText 142 /* same as TK_TO_TEXT */
9150 #define OP_ToBlob 143 /* same as TK_TO_BLOB */
9151 #define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
9152 #define OP_ToInt 145 /* same as TK_TO_INT */
9153 #define OP_ToReal 146 /* same as TK_TO_REAL */
9154 #define OP_MaxPgcnt 147
9155 #define OP_Trace 148
9156 #define OP_Noop 149
9157 #define OP_Explain 150
9158
9159
9160 /* Properties such as "out2" or "jump" that are specified in
9161 ** comments following the "case" for each opcode in the vdbe.c
9162 ** are encoded into bitvectors as follows:
@@ -9149,26 +9170,26 @@
9170 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9171 #define OPFLG_INITIALIZER {\
9172 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9173 /* 8 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01,\
9174 /* 16 */ 0x04, 0x04, 0x10, 0x24, 0x00, 0x02, 0x02, 0x02,\
9175 /* 24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00,\
9176 /* 32 */ 0x04, 0x05, 0x04, 0x00, 0x00, 0x01, 0x01, 0x05,\
9177 /* 40 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00,\
9178 /* 48 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,\
9179 /* 56 */ 0x11, 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11,\
9180 /* 64 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c, 0x4c, 0x00,\
9181 /* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
9182 /* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9183 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
9184 /* 96 */ 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08,\
9185 /* 104 */ 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02, 0x02,\
9186 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
9187 /* 120 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05, 0x05,\
9188 /* 128 */ 0x05, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,\
9189 /* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x04, 0x04,\
9190 /* 144 */ 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,}
9191
9192 /************** End of opcodes.h *********************************************/
9193 /************** Continuing where we left off in vdbe.h ***********************/
9194
9195 /*
@@ -9189,10 +9210,11 @@
9210 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9211 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
9212 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
9213 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
9214 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
9215 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
9216 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
9217 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
9218 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
9219 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
9220 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
@@ -9227,19 +9249,31 @@
9249
9250 #ifndef SQLITE_OMIT_TRIGGER
9251 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9252 #endif
9253
9254 /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
9255 ** each VDBE opcode.
9256 **
9257 ** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
9258 ** comments in VDBE programs that show key decision points in the code
9259 ** generator.
9260 */
9261 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
9262 SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
9263 # define VdbeComment(X) sqlite3VdbeComment X
9264 SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
9265 # define VdbeNoopComment(X) sqlite3VdbeNoopComment X
9266 # ifdef SQLITE_ENABLE_MODULE_COMMENTS
9267 # define VdbeModuleComment(X) sqlite3VdbeNoopComment X
9268 # else
9269 # define VdbeModuleComment(X)
9270 # endif
9271 #else
9272 # define VdbeComment(X)
9273 # define VdbeNoopComment(X)
9274 # define VdbeModuleComment(X)
9275 #endif
9276
9277 #endif
9278
9279 /************** End of vdbe.h ************************************************/
@@ -10631,10 +10665,11 @@
10665 #define TF_Readonly 0x01 /* Read-only system table */
10666 #define TF_Ephemeral 0x02 /* An ephemeral table */
10667 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
10668 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
10669 #define TF_Virtual 0x10 /* Is a virtual table */
10670 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
10671
10672
10673 /*
10674 ** Test to see whether or not a table is a virtual table. This is
10675 ** done as a macro so that it will be optimized out when virtual
@@ -10646,10 +10681,13 @@
10681 #else
10682 # define IsVirtual(X) 0
10683 # define IsHiddenColumn(X) 0
10684 #endif
10685
10686 /* Does the table have a rowid */
10687 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
10688
10689 /*
10690 ** Each foreign key constraint is an instance of the following structure.
10691 **
10692 ** A foreign key is associated with two tables. The "from" table is
10693 ** the table that contains the REFERENCES clause that creates the foreign
@@ -10660,30 +10698,39 @@
10698 ** a INTEGER PRIMARY KEY,
10699 ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
10700 ** );
10701 **
10702 ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
10703 ** Equivalent names:
10704 **
10705 ** from-table == child-table
10706 ** to-table == parent-table
10707 **
10708 ** Each REFERENCES clause generates an instance of the following structure
10709 ** which is attached to the from-table. The to-table need not exist when
10710 ** the from-table is created. The existence of the to-table is not checked.
10711 **
10712 ** The list of all parents for child Table X is held at X.pFKey.
10713 **
10714 ** A list of all children for a table named Z (which might not even exist)
10715 ** is held in Schema.fkeyHash with a hash key of Z.
10716 */
10717 struct FKey {
10718 Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */
10719 FKey *pNextFrom; /* Next FKey with the same in pFrom. Next parent of pFrom */
10720 char *zTo; /* Name of table that the key points to (aka: Parent) */
10721 FKey *pNextTo; /* Next with the same zTo. Next child of zTo. */
10722 FKey *pPrevTo; /* Previous with the same zTo */
10723 int nCol; /* Number of columns in this key */
10724 /* EV: R-30323-21917 */
10725 u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
10726 u8 aAction[2]; /* ON DELETE and ON UPDATE actions, respectively */
10727 Trigger *apTrigger[2];/* Triggers for aAction[] actions */
10728 struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
10729 int iFrom; /* Index of column in pFrom */
10730 char *zCol; /* Name of column in zTo. If NULL use PRIMARY KEY */
10731 } aCol[1]; /* One entry for each of nCol columns */
10732 };
10733
10734 /*
10735 ** SQLite supports many different ways to resolve a constraint
10736 ** error. ROLLBACK processing means that a constraint violation
@@ -10732,13 +10779,15 @@
10779 ** Note that aSortOrder[] and aColl[] have nField+1 slots. There
10780 ** are nField slots for the columns of an index then one extra slot
10781 ** for the rowid at the end.
10782 */
10783 struct KeyInfo {
10784 u32 nRef; /* Number of references to this KeyInfo object */
10785 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
10786 u16 nField; /* Number of key columns in the index */
10787 u16 nXField; /* Number of columns beyond the key columns */
10788 sqlite3 *db; /* The database connection */
10789 u8 *aSortOrder; /* Sort order for each column. */
10790 CollSeq *aColl[1]; /* Collating sequence for each term of the key */
10791 };
10792
10793 /*
@@ -10757,20 +10806,18 @@
10806 */
10807 struct UnpackedRecord {
10808 KeyInfo *pKeyInfo; /* Collation and sort-order information */
10809 u16 nField; /* Number of entries in apMem[] */
10810 u8 flags; /* Boolean settings. UNPACKED_... below */
 
10811 Mem *aMem; /* Values */
10812 };
10813
10814 /*
10815 ** Allowed values of UnpackedRecord.flags
10816 */
10817 #define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
10818 #define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
 
10819
10820 /*
10821 ** Each SQL index is represented in memory by an
10822 ** instance of the following structure.
10823 **
@@ -10796,26 +10843,30 @@
10843 ** algorithm to employ whenever an attempt is made to insert a non-unique
10844 ** element.
10845 */
10846 struct Index {
10847 char *zName; /* Name of this index */
10848 i16 *aiColumn; /* Which columns are used by this index. 1st is 0 */
10849 tRowcnt *aiRowEst; /* From ANALYZE: Est. rows selected by each column */
10850 Table *pTable; /* The SQL table being indexed */
10851 char *zColAff; /* String defining the affinity of each column */
10852 Index *pNext; /* The next index associated with the same table */
10853 Schema *pSchema; /* Schema containing this index */
10854 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
10855 char **azColl; /* Array of collation sequence names for index */
10856 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
10857 KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */
10858 int tnum; /* DB Page containing root of this index */
10859 LogEst szIdxRow; /* Estimated average row size in bytes */
10860 u16 nKeyCol; /* Number of columns forming the key */
10861 u16 nColumn; /* Number of columns stored in the index */
10862 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10863 unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
10864 unsigned bUnordered:1; /* Use this index for == or IN queries only */
10865 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
10866 unsigned isResized:1; /* True if resizeIndexObject() has been called */
10867 unsigned isCovering:1; /* True if this is a covering index */
10868 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
10869 int nSample; /* Number of elements in aSample[] */
10870 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
10871 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
10872 IndexSample *aSample; /* Samples of the left-most key */
@@ -11490,10 +11541,12 @@
11541 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
11542
11543 /* Information used while coding trigger programs. */
11544 Parse *pToplevel; /* Parse structure for main program (or NULL) */
11545 Table *pTriggerTab; /* Table triggers are being coded for */
11546 int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */
11547 int addrSkipPK; /* Address of instruction to skip PRIMARY KEY index */
11548 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
11549 u32 oldmask; /* Mask of old.* columns referenced */
11550 u32 newmask; /* Mask of new.* columns referenced */
11551 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
11552 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
@@ -11502,10 +11555,11 @@
11555 /* Above is constant between recursions. Below is reset before and after
11556 ** each recursion */
11557
11558 int nVar; /* Number of '?' variables seen in the SQL so far */
11559 int nzVar; /* Number of available slots in azVar[] */
11560 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
11561 u8 explain; /* True if the EXPLAIN flag is found on the query */
11562 #ifndef SQLITE_OMIT_VIRTUALTABLE
11563 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
11564 int nVtabLock; /* Number of virtual tables to lock */
11565 #endif
@@ -11515,11 +11569,10 @@
11569 int iSelectId; /* ID of current select for EXPLAIN output */
11570 int iNextSelectId; /* Next available select ID for EXPLAIN output */
11571 #endif
11572 char **azVar; /* Pointers to names of parameters */
11573 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
 
11574 const char *zTail; /* All SQL text past the last semicolon parsed */
11575 Table *pNewTable; /* A table being constructed by CREATE TABLE */
11576 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
11577 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
11578 Token sNameToken; /* Token with unqualified schema object name */
@@ -11984,19 +12037,21 @@
12037 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
12038 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
12039 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
12040 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
12041 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
12042 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
12043 SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
12044 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
12045 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*);
12046 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
12047 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
12048 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
12049 SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
12050 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
12051 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
12052 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
12053 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
12054 sqlite3_vfs**,char**,char **);
12055 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
12056 SQLITE_PRIVATE int sqlite3CodeOnce(Parse *);
12057
@@ -12045,10 +12100,11 @@
12100 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
12101 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
12102 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
12103 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
12104 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
12105 SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
12106 SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
12107 Expr*, int, int);
12108 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
12109 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
12110 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
@@ -12067,11 +12123,11 @@
12123 SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo*);
12124 SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
12125 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
12126 SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
12127 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
12128 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
12129 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
12130 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
12131 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
12132 SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
12133 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
@@ -12121,21 +12177,23 @@
12177 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12178 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12179 SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
12180 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12181 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12182 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
12183 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12184 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
12185 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
12186 u8,u8,int,int*);
12187 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12188 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, int*, int*);
12189 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
12190 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
12191 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
12192 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
12193 SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
12194 SQLITE_PRIVATE void sqlite3RowidConstraint(Parse*, int, Table*);
12195 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
12196 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
12197 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
12198 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
12199 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int);
@@ -12349,12 +12407,17 @@
12407 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
12408 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
12409 SQLITE_PRIVATE void sqlite3SchemaClear(void *);
12410 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
12411 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
12412 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
12413 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
12414 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
12415 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
12416 #ifdef SQLITE_DEBUG
12417 SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*);
12418 #endif
12419 SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
12420 void (*)(sqlite3_context*,int,sqlite3_value **),
12421 void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
12422 FuncDestructor *pDestructor
12423 );
@@ -13350,12 +13413,11 @@
13413 i64 seqCount; /* Sequence counter */
13414 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13415 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
13416 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
13417
13418 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */
 
13419 int seekResult;
13420
13421 /* Cached information about the header for the data record that the
13422 ** cursor is currently pointing to. Only valid if cacheStatus matches
13423 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -13716,11 +13778,11 @@
13778 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
13779 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
13780 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
13781 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, const VdbeCursor *, int *);
13782 SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, const VdbeCursor *, Mem *);
13783 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
13784
13785 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
13786 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
13787 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
13788 #else
@@ -22794,163 +22856,168 @@
22856
22857 /************** End of hash.c ************************************************/
22858 /************** Begin file opcodes.c *****************************************/
22859 /* Automatically generated. Do not edit */
22860 /* See the mkopcodec.awk script for details. */
22861 #if !defined(SQLITE_OMIT_EXPLAIN) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
22862 #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) || defined(SQLITE_DEBUG)
22863 # define OpHelp(X) "\0" X
22864 #else
22865 # define OpHelp(X)
22866 #endif
22867 SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
22868 static const char *const azName[] = { "?",
22869 /* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
22870 /* 2 */ "Savepoint" OpHelp(""),
22871 /* 3 */ "AutoCommit" OpHelp(""),
22872 /* 4 */ "Transaction" OpHelp(""),
22873 /* 5 */ "SorterNext" OpHelp(""),
22874 /* 6 */ "Prev" OpHelp(""),
22875 /* 7 */ "Next" OpHelp(""),
22876 /* 8 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
22877 /* 9 */ "Checkpoint" OpHelp(""),
22878 /* 10 */ "JournalMode" OpHelp(""),
22879 /* 11 */ "Vacuum" OpHelp(""),
22880 /* 12 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"),
22881 /* 13 */ "VUpdate" OpHelp("data=r[P3@P2]"),
22882 /* 14 */ "Goto" OpHelp(""),
22883 /* 15 */ "Gosub" OpHelp(""),
22884 /* 16 */ "Return" OpHelp(""),
22885 /* 17 */ "Yield" OpHelp(""),
22886 /* 18 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
22887 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
22888 /* 20 */ "Halt" OpHelp(""),
22889 /* 21 */ "Integer" OpHelp("r[P2]=P1"),
22890 /* 22 */ "Int64" OpHelp("r[P2]=P4"),
22891 /* 23 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
22892 /* 24 */ "Null" OpHelp("r[P2..P3]=NULL"),
22893 /* 25 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
22894 /* 26 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
22895 /* 27 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
22896 /* 28 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
22897 /* 29 */ "SCopy" OpHelp("r[P2]=r[P1]"),
22898 /* 30 */ "ResultRow" OpHelp("output=r[P1@P2]"),
22899 /* 31 */ "CollSeq" OpHelp(""),
22900 /* 32 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
22901 /* 33 */ "MustBeInt" OpHelp(""),
22902 /* 34 */ "RealAffinity" OpHelp(""),
22903 /* 35 */ "Permutation" OpHelp(""),
22904 /* 36 */ "Compare" OpHelp(""),
22905 /* 37 */ "Jump" OpHelp(""),
22906 /* 38 */ "Once" OpHelp(""),
22907 /* 39 */ "If" OpHelp(""),
22908 /* 40 */ "IfNot" OpHelp(""),
22909 /* 41 */ "Column" OpHelp("r[P3]=PX"),
22910 /* 42 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
22911 /* 43 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
22912 /* 44 */ "Count" OpHelp("r[P2]=count()"),
22913 /* 45 */ "ReadCookie" OpHelp(""),
22914 /* 46 */ "SetCookie" OpHelp(""),
22915 /* 47 */ "VerifyCookie" OpHelp(""),
22916 /* 48 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
22917 /* 49 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
22918 /* 50 */ "OpenAutoindex" OpHelp("nColumn=P2"),
22919 /* 51 */ "OpenEphemeral" OpHelp("nColumn=P2"),
22920 /* 52 */ "SorterOpen" OpHelp(""),
22921 /* 53 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
22922 /* 54 */ "Close" OpHelp(""),
22923 /* 55 */ "SeekLt" OpHelp("key=r[P3@P4]"),
22924 /* 56 */ "SeekLe" OpHelp("key=r[P3@P4]"),
22925 /* 57 */ "SeekGe" OpHelp("key=r[P3@P4]"),
22926 /* 58 */ "SeekGt" OpHelp("key=r[P3@P4]"),
22927 /* 59 */ "Seek" OpHelp("intkey=r[P2]"),
22928 /* 60 */ "NoConflict" OpHelp("key=r[P3@P4]"),
22929 /* 61 */ "NotFound" OpHelp("key=r[P3@P4]"),
22930 /* 62 */ "Found" OpHelp("key=r[P3@P4]"),
22931 /* 63 */ "NotExists" OpHelp("intkey=r[P3]"),
22932 /* 64 */ "Sequence" OpHelp("r[P2]=rowid"),
22933 /* 65 */ "NewRowid" OpHelp("r[P2]=rowid"),
22934 /* 66 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
22935 /* 67 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
22936 /* 68 */ "Delete" OpHelp(""),
22937 /* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
22938 /* 70 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
22939 /* 71 */ "ResetCount" OpHelp(""),
22940 /* 72 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
22941 /* 73 */ "SorterData" OpHelp("r[P2]=data"),
22942 /* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
22943 /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
22944 /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
22945 /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
22946 /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
22947 /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22948 /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P3"),
22949 /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
22950 /* 82 */ "RowKey" OpHelp("r[P2]=key"),
22951 /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
22952 /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
22953 /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
22954 /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
22955 /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
22956 /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
22957 /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22958 /* 90 */ "Divide" OpHelp("r[P3]=r[P1]/r[P2]"),
22959 /* 91 */ "Remainder" OpHelp("r[P3]=r[P1]%r[P2]"),
22960 /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22961 /* 93 */ "RowData" OpHelp("r[P2]=data"),
22962 /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
22963 /* 95 */ "String8" OpHelp("r[P2]='P4'"),
22964 /* 96 */ "Rowid" OpHelp("r[P2]=rowid"),
22965 /* 97 */ "NullRow" OpHelp(""),
22966 /* 98 */ "Last" OpHelp(""),
22967 /* 99 */ "SorterSort" OpHelp(""),
22968 /* 100 */ "Sort" OpHelp(""),
22969 /* 101 */ "Rewind" OpHelp(""),
22970 /* 102 */ "SorterInsert" OpHelp(""),
22971 /* 103 */ "IdxInsert" OpHelp("key=r[P2]"),
22972 /* 104 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
22973 /* 105 */ "IdxRowid" OpHelp("r[P2]=rowid"),
22974 /* 106 */ "IdxLT" OpHelp("key=r[P3@P4]"),
22975 /* 107 */ "IdxGE" OpHelp("key=r[P3@P4]"),
22976 /* 108 */ "Destroy" OpHelp(""),
22977 /* 109 */ "Clear" OpHelp(""),
22978 /* 110 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
22979 /* 111 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
22980 /* 112 */ "ParseSchema" OpHelp(""),
22981 /* 113 */ "LoadAnalysis" OpHelp(""),
22982 /* 114 */ "DropTable" OpHelp(""),
22983 /* 115 */ "DropIndex" OpHelp(""),
22984 /* 116 */ "DropTrigger" OpHelp(""),
22985 /* 117 */ "IntegrityCk" OpHelp(""),
22986 /* 118 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
22987 /* 119 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
22988 /* 120 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
22989 /* 121 */ "Program" OpHelp(""),
22990 /* 122 */ "Param" OpHelp(""),
22991 /* 123 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
22992 /* 124 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
22993 /* 125 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
22994 /* 126 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
22995 /* 127 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
22996 /* 128 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
22997 /* 129 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
22998 /* 130 */ "IncrVacuum" OpHelp(""),
22999 /* 131 */ "Real" OpHelp("r[P2]=P4"),
23000 /* 132 */ "Expire" OpHelp(""),
23001 /* 133 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23002 /* 134 */ "VBegin" OpHelp(""),
23003 /* 135 */ "VCreate" OpHelp(""),
23004 /* 136 */ "VDestroy" OpHelp(""),
23005 /* 137 */ "VOpen" OpHelp(""),
23006 /* 138 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23007 /* 139 */ "VNext" OpHelp(""),
23008 /* 140 */ "VRename" OpHelp(""),
23009 /* 141 */ "Pagecount" OpHelp(""),
23010 /* 142 */ "ToText" OpHelp(""),
23011 /* 143 */ "ToBlob" OpHelp(""),
23012 /* 144 */ "ToNumeric" OpHelp(""),
23013 /* 145 */ "ToInt" OpHelp(""),
23014 /* 146 */ "ToReal" OpHelp(""),
23015 /* 147 */ "MaxPgcnt" OpHelp(""),
23016 /* 148 */ "Trace" OpHelp(""),
23017 /* 149 */ "Noop" OpHelp(""),
23018 /* 150 */ "Explain" OpHelp(""),
23019 };
23020 return azName[i];
23021 }
23022 #endif
23023
@@ -25053,11 +25120,13 @@
25120 **
25121 ** If the locking level of the file descriptor is already at or below
25122 ** the requested locking level, this routine is a no-op.
25123 */
25124 static int unixUnlock(sqlite3_file *id, int eFileLock){
25125 #if SQLITE_MAX_MMAP_SIZE>0
25126 assert( eFileLock==SHARED_LOCK || ((unixFile *)id)->nFetchOut==0 );
25127 #endif
25128 return posixUnlock(id, eFileLock, 0);
25129 }
25130
25131 #if SQLITE_MAX_MMAP_SIZE>0
25132 static int unixMapfile(unixFile *pFd, i64 nByte);
@@ -30878,38 +30947,52 @@
30947 #if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
30948 # error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
30949 must be defined."
30950 #endif
30951
30952 /*
30953 ** This constant should already be defined (in the "WinDef.h" SDK file).
30954 */
30955 #ifndef MAX_PATH
30956 # define MAX_PATH (260)
30957 #endif
30958
30959 /*
30960 ** Maximum pathname length (in chars) for Win32. This should normally be
30961 ** MAX_PATH.
30962 */
30963 #ifndef SQLITE_WIN32_MAX_PATH_CHARS
30964 # define SQLITE_WIN32_MAX_PATH_CHARS (MAX_PATH)
30965 #endif
30966
30967 /*
30968 ** This constant should already be defined (in the "WinNT.h" SDK file).
30969 */
30970 #ifndef UNICODE_STRING_MAX_CHARS
30971 # define UNICODE_STRING_MAX_CHARS (32767)
30972 #endif
30973
30974 /*
30975 ** Maximum pathname length (in chars) for WinNT. This should normally be
30976 ** UNICODE_STRING_MAX_CHARS.
30977 */
30978 #ifndef SQLITE_WINNT_MAX_PATH_CHARS
30979 # define SQLITE_WINNT_MAX_PATH_CHARS (UNICODE_STRING_MAX_CHARS)
30980 #endif
30981
30982 /*
30983 ** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in
30984 ** characters, so we allocate 4 bytes per character assuming worst-case of
30985 ** 4-bytes-per-character for UTF8.
30986 */
30987 #ifndef SQLITE_WIN32_MAX_PATH_BYTES
30988 # define SQLITE_WIN32_MAX_PATH_BYTES (SQLITE_WIN32_MAX_PATH_CHARS*4)
30989 #endif
30990
30991 /*
30992 ** Maximum pathname length (in bytes) for WinNT. This should normally be
30993 ** UNICODE_STRING_MAX_CHARS * sizeof(WCHAR).
30994 */
30995 #ifndef SQLITE_WINNT_MAX_PATH_BYTES
30996 # define SQLITE_WINNT_MAX_PATH_BYTES \
30997 (sizeof(WCHAR) * SQLITE_WINNT_MAX_PATH_CHARS)
30998 #endif
@@ -30936,18 +31019,14 @@
31019 #ifndef UNUSED_VARIABLE_VALUE
31020 # define UNUSED_VARIABLE_VALUE(x) (void)(x)
31021 #endif
31022
31023 /*
31024 ** Returns the character that should be used as the directory separator.
31025 */
31026 #ifndef winGetDirSep
31027 # define winGetDirSep() '\\'
 
 
 
 
31028 #endif
31029
31030 /*
31031 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
31032 ** mode (e.g. these APIs are available in the Windows CE SDK; however, they
@@ -31135,34 +31214,45 @@
31214 ** sqlite3_mem_methods implementation.
31215 */
31216 typedef struct winMemData winMemData;
31217 struct winMemData {
31218 #ifndef NDEBUG
31219 u32 magic1; /* Magic number to detect structure corruption. */
31220 #endif
31221 HANDLE hHeap; /* The handle to our heap. */
31222 BOOL bOwned; /* Do we own the heap (i.e. destroy it on shutdown)? */
31223 #ifndef NDEBUG
31224 u32 magic2; /* Magic number to detect structure corruption. */
31225 #endif
31226 };
31227
31228 #ifndef NDEBUG
31229 #define WINMEM_MAGIC1 0x42b2830b
31230 #define WINMEM_MAGIC2 0xbd4d7cf4
31231 #endif
31232
31233 static struct winMemData win_mem_data = {
31234 #ifndef NDEBUG
31235 WINMEM_MAGIC1,
31236 #endif
31237 NULL, FALSE
31238 #ifndef NDEBUG
31239 ,WINMEM_MAGIC2
31240 #endif
31241 };
31242
31243 #ifndef NDEBUG
31244 #define winMemAssertMagic1() assert( win_mem_data.magic1==WINMEM_MAGIC1 )
31245 #define winMemAssertMagic2() assert( win_mem_data.magic2==WINMEM_MAGIC2 )
31246 #define winMemAssertMagic() winMemAssertMagic1(); winMemAssertMagic2();
31247 #else
31248 #define winMemAssertMagic()
31249 #endif
31250
31251 #define winMemGetDataPtr() &win_mem_data
31252 #define winMemGetHeap() win_mem_data.hHeap
31253 #define winMemGetOwned() win_mem_data.bOwned
31254
31255 static void *winMemMalloc(int nBytes);
31256 static void winMemFree(void *pPrior);
31257 static void *winMemRealloc(void *pPrior, int nBytes);
31258 static int winMemSize(void *p);
@@ -31555,44 +31645,52 @@
31645 #endif
31646
31647 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
31648 LPCVOID))aSyscall[42].pCurrent)
31649
31650 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31651 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
31652 #else
31653 { "HeapCompact", (SYSCALL)0, 0 },
31654 #endif
31655
31656 #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[43].pCurrent)
31657
31658 #if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31659 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
31660 #else
31661 { "LoadLibraryA", (SYSCALL)0, 0 },
31662 #endif
31663
31664 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
31665
31666 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
31667 !defined(SQLITE_OMIT_LOAD_EXTENSION)
31668 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
31669 #else
31670 { "LoadLibraryW", (SYSCALL)0, 0 },
31671 #endif
31672
31673 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[45].pCurrent)
31674
31675 #if !SQLITE_OS_WINRT
31676 { "LocalFree", (SYSCALL)LocalFree, 0 },
31677 #else
31678 { "LocalFree", (SYSCALL)0, 0 },
31679 #endif
31680
31681 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[46].pCurrent)
31682
31683 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31684 { "LockFile", (SYSCALL)LockFile, 0 },
31685 #else
31686 { "LockFile", (SYSCALL)0, 0 },
31687 #endif
31688
31689 #ifndef osLockFile
31690 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31691 DWORD))aSyscall[47].pCurrent)
31692 #endif
31693
31694 #if !SQLITE_OS_WINCE
31695 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
31696 #else
@@ -31599,218 +31697,218 @@
31697 { "LockFileEx", (SYSCALL)0, 0 },
31698 #endif
31699
31700 #ifndef osLockFileEx
31701 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
31702 LPOVERLAPPED))aSyscall[48].pCurrent)
31703 #endif
31704
31705 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
31706 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
31707 #else
31708 { "MapViewOfFile", (SYSCALL)0, 0 },
31709 #endif
31710
31711 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31712 SIZE_T))aSyscall[49].pCurrent)
31713
31714 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
31715
31716 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
31717 int))aSyscall[50].pCurrent)
31718
31719 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
31720
31721 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
31722 LARGE_INTEGER*))aSyscall[51].pCurrent)
31723
31724 { "ReadFile", (SYSCALL)ReadFile, 0 },
31725
31726 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
31727 LPOVERLAPPED))aSyscall[52].pCurrent)
31728
31729 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
31730
31731 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[53].pCurrent)
31732
31733 #if !SQLITE_OS_WINRT
31734 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
31735 #else
31736 { "SetFilePointer", (SYSCALL)0, 0 },
31737 #endif
31738
31739 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
31740 DWORD))aSyscall[54].pCurrent)
31741
31742 #if !SQLITE_OS_WINRT
31743 { "Sleep", (SYSCALL)Sleep, 0 },
31744 #else
31745 { "Sleep", (SYSCALL)0, 0 },
31746 #endif
31747
31748 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent)
31749
31750 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
31751
31752 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
31753 LPFILETIME))aSyscall[56].pCurrent)
31754
31755 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31756 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
31757 #else
31758 { "UnlockFile", (SYSCALL)0, 0 },
31759 #endif
31760
31761 #ifndef osUnlockFile
31762 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31763 DWORD))aSyscall[57].pCurrent)
31764 #endif
31765
31766 #if !SQLITE_OS_WINCE
31767 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
31768 #else
31769 { "UnlockFileEx", (SYSCALL)0, 0 },
31770 #endif
31771
31772 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31773 LPOVERLAPPED))aSyscall[58].pCurrent)
31774
31775 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
31776 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
31777 #else
31778 { "UnmapViewOfFile", (SYSCALL)0, 0 },
31779 #endif
31780
31781 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[59].pCurrent)
31782
31783 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
31784
31785 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
31786 LPCSTR,LPBOOL))aSyscall[60].pCurrent)
31787
31788 { "WriteFile", (SYSCALL)WriteFile, 0 },
31789
31790 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
31791 LPOVERLAPPED))aSyscall[61].pCurrent)
31792
31793 #if SQLITE_OS_WINRT
31794 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
31795 #else
31796 { "CreateEventExW", (SYSCALL)0, 0 },
31797 #endif
31798
31799 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
31800 DWORD,DWORD))aSyscall[62].pCurrent)
31801
31802 #if !SQLITE_OS_WINRT
31803 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
31804 #else
31805 { "WaitForSingleObject", (SYSCALL)0, 0 },
31806 #endif
31807
31808 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
31809 DWORD))aSyscall[63].pCurrent)
31810
31811 #if SQLITE_OS_WINRT
31812 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
31813 #else
31814 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
31815 #endif
31816
31817 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
31818 BOOL))aSyscall[64].pCurrent)
31819
31820 #if SQLITE_OS_WINRT
31821 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
31822 #else
31823 { "SetFilePointerEx", (SYSCALL)0, 0 },
31824 #endif
31825
31826 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
31827 PLARGE_INTEGER,DWORD))aSyscall[65].pCurrent)
31828
31829 #if SQLITE_OS_WINRT
31830 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
31831 #else
31832 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
31833 #endif
31834
31835 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
31836 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
31837
31838 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31839 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
31840 #else
31841 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
31842 #endif
31843
31844 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
31845 SIZE_T))aSyscall[67].pCurrent)
31846
31847 #if SQLITE_OS_WINRT
31848 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
31849 #else
31850 { "CreateFile2", (SYSCALL)0, 0 },
31851 #endif
31852
31853 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
31854 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[68].pCurrent)
31855
31856 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31857 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
31858 #else
31859 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
31860 #endif
31861
31862 #define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
31863 DWORD))aSyscall[69].pCurrent)
31864
31865 #if SQLITE_OS_WINRT
31866 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
31867 #else
31868 { "GetTickCount64", (SYSCALL)0, 0 },
31869 #endif
31870
31871 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[70].pCurrent)
31872
31873 #if SQLITE_OS_WINRT
31874 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
31875 #else
31876 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
31877 #endif
31878
31879 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
31880 LPSYSTEM_INFO))aSyscall[71].pCurrent)
31881
31882 #if defined(SQLITE_WIN32_HAS_ANSI)
31883 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
31884 #else
31885 { "OutputDebugStringA", (SYSCALL)0, 0 },
31886 #endif
31887
31888 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[72].pCurrent)
31889
31890 #if defined(SQLITE_WIN32_HAS_WIDE)
31891 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
31892 #else
31893 { "OutputDebugStringW", (SYSCALL)0, 0 },
31894 #endif
31895
31896 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[73].pCurrent)
31897
31898 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
31899
31900 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
31901
31902 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31903 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
31904 #else
31905 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
31906 #endif
31907
31908 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
31909 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent)
31910
31911 }; /* End of the overrideable system calls */
31912
31913 /*
31914 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -31893,10 +31991,98 @@
31991 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
31992 }
31993 return 0;
31994 }
31995
31996 #ifdef SQLITE_WIN32_MALLOC
31997 /*
31998 ** If a Win32 native heap has been configured, this function will attempt to
31999 ** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one
32000 ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The
32001 ** "pnLargest" argument, if non-zero, will be used to return the size of the
32002 ** largest committed free block in the heap, in bytes.
32003 */
32004 SQLITE_API int sqlite3_win32_compact_heap(LPUINT pnLargest){
32005 int rc = SQLITE_OK;
32006 UINT nLargest = 0;
32007 HANDLE hHeap;
32008
32009 winMemAssertMagic();
32010 hHeap = winMemGetHeap();
32011 assert( hHeap!=0 );
32012 assert( hHeap!=INVALID_HANDLE_VALUE );
32013 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32014 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32015 #endif
32016 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
32017 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){
32018 DWORD lastErrno = osGetLastError();
32019 if( lastErrno==NO_ERROR ){
32020 sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p",
32021 (void*)hHeap);
32022 rc = SQLITE_NOMEM;
32023 }else{
32024 sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p",
32025 osGetLastError(), (void*)hHeap);
32026 rc = SQLITE_ERROR;
32027 }
32028 }
32029 #else
32030 sqlite3_log(SQLITE_NOTFOUND, "failed to HeapCompact, heap=%p",
32031 (void*)hHeap);
32032 rc = SQLITE_NOTFOUND;
32033 #endif
32034 if( pnLargest ) *pnLargest = nLargest;
32035 return rc;
32036 }
32037
32038 /*
32039 ** If a Win32 native heap has been configured, this function will attempt to
32040 ** destroy and recreate it. If the Win32 native heap is not isolated and/or
32041 ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
32042 ** be returned and no changes will be made to the Win32 native heap.
32043 */
32044 SQLITE_API int sqlite3_win32_reset_heap(){
32045 int rc;
32046 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
32047 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
32048 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
32049 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
32050 sqlite3_mutex_enter(pMaster);
32051 sqlite3_mutex_enter(pMem);
32052 winMemAssertMagic();
32053 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
32054 /*
32055 ** At this point, there should be no outstanding memory allocations on
32056 ** the heap. Also, since both the master and memsys locks are currently
32057 ** being held by us, no other function (i.e. from another thread) should
32058 ** be able to even access the heap. Attempt to destroy and recreate our
32059 ** isolated Win32 native heap now.
32060 */
32061 assert( winMemGetHeap()!=NULL );
32062 assert( winMemGetOwned() );
32063 assert( sqlite3_memory_used()==0 );
32064 winMemShutdown(winMemGetDataPtr());
32065 assert( winMemGetHeap()==NULL );
32066 assert( !winMemGetOwned() );
32067 assert( sqlite3_memory_used()==0 );
32068 rc = winMemInit(winMemGetDataPtr());
32069 assert( rc!=SQLITE_OK || winMemGetHeap()!=NULL );
32070 assert( rc!=SQLITE_OK || winMemGetOwned() );
32071 assert( rc!=SQLITE_OK || sqlite3_memory_used()==0 );
32072 }else{
32073 /*
32074 ** The Win32 native heap cannot be modified because it may be in use.
32075 */
32076 rc = SQLITE_BUSY;
32077 }
32078 sqlite3_mutex_leave(pMem);
32079 sqlite3_mutex_leave(pMaster);
32080 return rc;
32081 }
32082 #endif /* SQLITE_WIN32_MALLOC */
32083
32084 /*
32085 ** This function outputs the specified (ANSI) string to the Win32 debugger
32086 ** (if available).
32087 */
32088
@@ -32001,11 +32187,11 @@
32187 winMemAssertMagic();
32188 hHeap = winMemGetHeap();
32189 assert( hHeap!=0 );
32190 assert( hHeap!=INVALID_HANDLE_VALUE );
32191 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32192 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32193 #endif
32194 assert( nBytes>=0 );
32195 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
32196 if( !p ){
32197 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%lu), heap=%p",
@@ -32023,11 +32209,11 @@
32209 winMemAssertMagic();
32210 hHeap = winMemGetHeap();
32211 assert( hHeap!=0 );
32212 assert( hHeap!=INVALID_HANDLE_VALUE );
32213 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32214 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32215 #endif
32216 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
32217 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
32218 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%lu), heap=%p",
32219 pPrior, osGetLastError(), (void*)hHeap);
@@ -32044,11 +32230,11 @@
32230 winMemAssertMagic();
32231 hHeap = winMemGetHeap();
32232 assert( hHeap!=0 );
32233 assert( hHeap!=INVALID_HANDLE_VALUE );
32234 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32235 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
32236 #endif
32237 assert( nBytes>=0 );
32238 if( !pPrior ){
32239 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
32240 }else{
@@ -32072,11 +32258,11 @@
32258 winMemAssertMagic();
32259 hHeap = winMemGetHeap();
32260 assert( hHeap!=0 );
32261 assert( hHeap!=INVALID_HANDLE_VALUE );
32262 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32263 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, p) );
32264 #endif
32265 if( !p ) return 0;
32266 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
32267 if( n==(SIZE_T)-1 ){
32268 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%lu), heap=%p",
@@ -32098,11 +32284,12 @@
32284 */
32285 static int winMemInit(void *pAppData){
32286 winMemData *pWinMemData = (winMemData *)pAppData;
32287
32288 if( !pWinMemData ) return SQLITE_ERROR;
32289 assert( pWinMemData->magic1==WINMEM_MAGIC1 );
32290 assert( pWinMemData->magic2==WINMEM_MAGIC2 );
32291
32292 #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
32293 if( !pWinMemData->hHeap ){
32294 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
32295 SQLITE_WIN32_HEAP_INIT_SIZE,
@@ -32140,10 +32327,13 @@
32327 */
32328 static void winMemShutdown(void *pAppData){
32329 winMemData *pWinMemData = (winMemData *)pAppData;
32330
32331 if( !pWinMemData ) return;
32332 assert( pWinMemData->magic1==WINMEM_MAGIC1 );
32333 assert( pWinMemData->magic2==WINMEM_MAGIC2 );
32334
32335 if( pWinMemData->hHeap ){
32336 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
32337 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32338 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32339 #endif
@@ -34809,16 +34999,25 @@
34999 return zConverted;
35000 }
35001
35002 /*
35003 ** This function returns non-zero if the specified UTF-8 string buffer
35004 ** ends with a directory separator character or one was successfully
35005 ** added to it.
35006 */
35007 static int winMakeEndInDirSep(int nBuf, char *zBuf){
35008 if( zBuf ){
35009 int nLen = sqlite3Strlen30(zBuf);
35010 if( nLen>0 ){
35011 if( winIsDirSep(zBuf[nLen-1]) ){
35012 return 1;
35013 }else if( nLen+1<nBuf ){
35014 zBuf[nLen] = winGetDirSep();
35015 zBuf[nLen+1] = '\0';
35016 return 1;
35017 }
35018 }
35019 }
35020 return 0;
35021 }
35022
35023 /*
@@ -34829,11 +35028,12 @@
35028 static char zChars[] =
35029 "abcdefghijklmnopqrstuvwxyz"
35030 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
35031 "0123456789";
35032 size_t i, j;
35033 int nPre = sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX);
35034 int nMax, nBuf, nDir, nLen;
35035 char *zBuf;
35036
35037 /* It's odd to simulate an io-error here, but really this is just
35038 ** using the io-error infrastructure to test that SQLite handles this
35039 ** function failing.
@@ -34841,26 +35041,36 @@
35041 SimulateIOError( return SQLITE_IOERR );
35042
35043 /* Allocate a temporary buffer to store the fully qualified file
35044 ** name for the temporary file. If this fails, we cannot continue.
35045 */
35046 nMax = pVfs->mxPathname; nBuf = nMax + 2;
35047 zBuf = sqlite3MallocZero( nBuf );
35048 if( !zBuf ){
35049 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35050 return SQLITE_IOERR_NOMEM;
35051 }
35052
35053 /* Figure out the effective temporary directory. First, check if one
35054 ** has been explicitly set by the application; otherwise, use the one
35055 ** configured by the operating system.
35056 */
35057 nDir = nMax - (nPre + 15);
35058 assert( nDir>0 );
35059 if( sqlite3_temp_directory ){
35060 int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
35061 if( nDirLen>0 ){
35062 if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
35063 nDirLen++;
35064 }
35065 if( nDirLen>nDir ){
35066 sqlite3_free(zBuf);
35067 OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
35068 return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
35069 }
35070 sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
35071 }
35072 }
35073 #if defined(__CYGWIN__)
35074 else{
35075 static const char *azDirs[] = {
35076 0, /* getenv("SQLITE_TMPDIR") */
@@ -34885,41 +35095,41 @@
35095 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
35096 void *zConverted;
35097 if( zDir==0 ) continue;
35098 /* If the path starts with a drive letter followed by the colon
35099 ** character, assume it is already a native Win32 path; otherwise,
35100 ** it must be converted to a native Win32 path via the Cygwin API
35101 ** prior to using it.
35102 */
35103 if( winIsDriveLetterAndColon(zDir) ){
35104 zConverted = winConvertFromUtf8Filename(zDir);
35105 if( !zConverted ){
35106 sqlite3_free(zBuf);
35107 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35108 return SQLITE_IOERR_NOMEM;
35109 }
35110 if( winIsDir(zConverted) ){
35111 sqlite3_snprintf(nMax, zBuf, "%s", zDir);
35112 sqlite3_free(zConverted);
35113 break;
35114 }
35115 sqlite3_free(zConverted);
35116 }else{
35117 zConverted = sqlite3MallocZero( nMax+1 );
35118 if( !zConverted ){
35119 sqlite3_free(zBuf);
35120 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35121 return SQLITE_IOERR_NOMEM;
35122 }
35123 if( cygwin_conv_path(
35124 osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
35125 zConverted, nMax+1)<0 ){
35126 sqlite3_free(zConverted);
35127 sqlite3_free(zBuf);
35128 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
35129 return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
35130 "winGetTempname2", zDir);
35131 }
35132 if( winIsDir(zConverted) ){
35133 /* At this point, we know the candidate directory exists and should
35134 ** be used. However, we may need to convert the string containing
35135 ** its name into UTF-8 (i.e. if it is UTF-16 right now).
@@ -34930,16 +35140,16 @@
35140 sqlite3_free(zConverted);
35141 sqlite3_free(zBuf);
35142 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35143 return SQLITE_IOERR_NOMEM;
35144 }
35145 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
35146 sqlite3_free(zUtf8);
35147 sqlite3_free(zConverted);
35148 break;
35149 }else{
35150 sqlite3_snprintf(nMax, zBuf, "%s", zConverted);
35151 sqlite3_free(zConverted);
35152 break;
35153 }
35154 }
35155 sqlite3_free(zConverted);
@@ -34947,26 +35157,26 @@
35157 }
35158 }
35159 #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__)
35160 else if( osIsNT() ){
35161 char *zMulti;
35162 LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
35163 if( !zWidePath ){
35164 sqlite3_free(zBuf);
35165 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35166 return SQLITE_IOERR_NOMEM;
35167 }
35168 if( osGetTempPathW(nMax, zWidePath)==0 ){
35169 sqlite3_free(zWidePath);
35170 sqlite3_free(zBuf);
35171 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
35172 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
35173 "winGetTempname2", 0);
35174 }
35175 zMulti = winUnicodeToUtf8(zWidePath);
35176 if( zMulti ){
35177 sqlite3_snprintf(nMax, zBuf, "%s", zMulti);
35178 sqlite3_free(zMulti);
35179 sqlite3_free(zWidePath);
35180 }else{
35181 sqlite3_free(zWidePath);
35182 sqlite3_free(zBuf);
@@ -34975,25 +35185,25 @@
35185 }
35186 }
35187 #ifdef SQLITE_WIN32_HAS_ANSI
35188 else{
35189 char *zUtf8;
35190 char *zMbcsPath = sqlite3MallocZero( nMax );
35191 if( !zMbcsPath ){
35192 sqlite3_free(zBuf);
35193 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35194 return SQLITE_IOERR_NOMEM;
35195 }
35196 if( osGetTempPathA(nMax, zMbcsPath)==0 ){
35197 sqlite3_free(zBuf);
35198 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
35199 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
35200 "winGetTempname3", 0);
35201 }
35202 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
35203 if( zUtf8 ){
35204 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
35205 sqlite3_free(zUtf8);
35206 }else{
35207 sqlite3_free(zBuf);
35208 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35209 return SQLITE_IOERR_NOMEM;
@@ -35000,22 +35210,40 @@
35210 }
35211 }
35212 #endif /* SQLITE_WIN32_HAS_ANSI */
35213 #endif /* !SQLITE_OS_WINRT */
35214
35215 /*
35216 ** Check to make sure the temporary directory ends with an appropriate
35217 ** separator. If it does not and there is not enough space left to add
35218 ** one, fail.
35219 */
35220 if( !winMakeEndInDirSep(nDir+1, zBuf) ){
35221 sqlite3_free(zBuf);
35222 OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
35223 return winLogError(SQLITE_ERROR, 0, "winGetTempname4", 0);
35224 }
35225
35226 /*
35227 ** Check that the output buffer is large enough for the temporary file
35228 ** name in the following format:
35229 **
35230 ** "<temporary_directory>/etilqs_XXXXXXXXXXXXXXX\0\0"
35231 **
35232 ** If not, return SQLITE_ERROR. The number 17 is used here in order to
35233 ** account for the space used by the 15 character random suffix and the
35234 ** two trailing NUL characters. The final directory separator character
35235 ** has already added if it was not already present.
35236 */
35237 nLen = sqlite3Strlen30(zBuf);
35238 if( (nLen + nPre + 17) > nBuf ){
 
35239 sqlite3_free(zBuf);
35240 OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
35241 return winLogError(SQLITE_ERROR, 0, "winGetTempname5", 0);
35242 }
35243
35244 sqlite3_snprintf(nBuf-16-nLen, zBuf+nLen, SQLITE_TEMP_FILE_PREFIX);
35245
35246 j = sqlite3Strlen30(zBuf);
35247 sqlite3_randomness(15, &zBuf[j]);
35248 for(i=0; i<15; i++, j++){
35249 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
@@ -35066,11 +35294,11 @@
35294 sqlite3_file *id, /* Write the SQLite file handle here */
35295 int flags, /* Open mode flags */
35296 int *pOutFlags /* Status return flags */
35297 ){
35298 HANDLE h;
35299 DWORD lastErrno = 0;
35300 DWORD dwDesiredAccess;
35301 DWORD dwShareMode;
35302 DWORD dwCreationDisposition;
35303 DWORD dwFlagsAndAttributes = 0;
35304 #if SQLITE_OS_WINCE
@@ -35357,11 +35585,11 @@
35585 int syncDir /* Not used on win32 */
35586 ){
35587 int cnt = 0;
35588 int rc;
35589 DWORD attr;
35590 DWORD lastErrno = 0;
35591 void *zConverted;
35592 UNUSED_PARAMETER(pVfs);
35593 UNUSED_PARAMETER(syncDir);
35594
35595 SimulateIOError(return SQLITE_IOERR_DELETE);
@@ -35465,11 +35693,11 @@
35693 int flags, /* Type of test to make on this file */
35694 int *pResOut /* OUT: Result */
35695 ){
35696 DWORD attr;
35697 int rc = 0;
35698 DWORD lastErrno = 0;
35699 void *zConverted;
35700 UNUSED_PARAMETER(pVfs);
35701
35702 SimulateIOError( return SQLITE_IOERR_ACCESS; );
35703 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
@@ -35611,12 +35839,12 @@
35839 pVfs->mxPathname+1)<0 ){
35840 sqlite3_free(zOut);
35841 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
35842 "winFullPathname1", zRelative);
35843 }
35844 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35845 sqlite3_data_directory, winGetDirSep(), zOut);
35846 sqlite3_free(zOut);
35847 }else{
35848 if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){
35849 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
35850 "winFullPathname2", zRelative);
@@ -35634,12 +35862,12 @@
35862 ** NOTE: We are dealing with a relative path name and the data
35863 ** directory has been set. Therefore, use it as the basis
35864 ** for converting the relative path name to an absolute
35865 ** one by prepending the data directory and a backslash.
35866 */
35867 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35868 sqlite3_data_directory, winGetDirSep(), zRelative);
35869 }else{
35870 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
35871 }
35872 return SQLITE_OK;
35873 #endif
@@ -35667,12 +35895,12 @@
35895 ** NOTE: We are dealing with a relative path name and the data
35896 ** directory has been set. Therefore, use it as the basis
35897 ** for converting the relative path name to an absolute
35898 ** one by prepending the data directory and a backslash.
35899 */
35900 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35901 sqlite3_data_directory, winGetDirSep(), zRelative);
35902 return SQLITE_OK;
35903 }
35904 zConverted = winConvertFromUtf8Filename(zRelative);
35905 if( zConverted==0 ){
35906 return SQLITE_IOERR_NOMEM;
@@ -36006,11 +36234,11 @@
36234 };
36235 #endif
36236
36237 /* Double-check that the aSyscall[] array has been constructed
36238 ** correctly. See ticket [bb3a86e890c8e96ab] */
36239 assert( ArraySize(aSyscall)==76 );
36240
36241 /* get memory map allocation granularity */
36242 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
36243 #if SQLITE_OS_WINRT
36244 osGetNativeSystemInfo(&winSysInfo);
@@ -50676,11 +50904,11 @@
50904 int bias, /* Bias search to the high end */
50905 int *pRes /* Write search results here */
50906 ){
50907 int rc; /* Status code */
50908 UnpackedRecord *pIdxKey; /* Unpacked index key */
50909 char aSpace[200]; /* Temp space for pIdxKey - to avoid a malloc */
50910 char *pFree = 0;
50911
50912 if( pKey ){
50913 assert( nKey==(i64)(int)nKey );
50914 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
@@ -60294,19 +60522,19 @@
60522
60523 if( pRec==0 ){
60524 Index *pIdx = p->pIdx; /* Index being probed */
60525 int nByte; /* Bytes of space to allocate */
60526 int i; /* Counter variable */
60527 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
60528
60529 nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord);
60530 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
60531 if( pRec ){
60532 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
60533 if( pRec->pKeyInfo ){
60534 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60535 assert( pRec->pKeyInfo->enc==ENC(db) );
60536 pRec->flags = UNPACKED_PREFIX_MATCH;
60537 pRec->aMem = (Mem *)&pRec[1];
60538 for(i=0; i<nCol; i++){
60539 pRec->aMem[i].flags = MEM_Null;
60540 pRec->aMem[i].type = SQLITE_NULL;
@@ -60625,17 +60853,17 @@
60853 ** the object.
60854 */
60855 SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){
60856 if( pRec ){
60857 int i;
60858 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
60859 Mem *aMem = pRec->aMem;
60860 sqlite3 *db = aMem[0].db;
60861 for(i=0; i<nCol; i++){
60862 sqlite3DbFree(db, aMem[i].zMalloc);
60863 }
60864 sqlite3KeyInfoUnref(pRec->pKeyInfo);
60865 sqlite3DbFree(db, pRec);
60866 }
60867 }
60868 #endif /* ifdef SQLITE_ENABLE_STAT4 */
60869
@@ -60784,10 +61012,21 @@
61012 p->aOp = pNew;
61013 }
61014 return (pNew ? SQLITE_OK : SQLITE_NOMEM);
61015 }
61016
61017 #ifdef SQLITE_DEBUG
61018 /* This routine is just a convenient place to set a breakpoint that will
61019 ** fire after each opcode is inserted and displayed using
61020 ** "PRAGMA vdbe_addoptrace=on".
61021 */
61022 static void test_addop_breakpoint(void){
61023 static int n = 0;
61024 n++;
61025 }
61026 #endif
61027
61028 /*
61029 ** Add a new instruction to the list of instructions current in the
61030 ** VDBE. Return the address of the new instruction.
61031 **
61032 ** Parameters:
@@ -60821,14 +61060,17 @@
61060 pOp->p1 = p1;
61061 pOp->p2 = p2;
61062 pOp->p3 = p3;
61063 pOp->p4.p = 0;
61064 pOp->p4type = P4_NOTUSED;
61065 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61066 pOp->zComment = 0;
61067 #endif
61068 #ifdef SQLITE_DEBUG
61069 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61070 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
61071 test_addop_breakpoint();
61072 }
61073 #endif
61074 #ifdef VDBE_PROFILE
61075 pOp->cycles = 0;
61076 pOp->cnt = 0;
@@ -61200,21 +61442,24 @@
61442 for(i=0; i<nOp; i++, pIn++){
61443 int p2 = pIn->p2;
61444 VdbeOp *pOut = &p->aOp[i+addr];
61445 pOut->opcode = pIn->opcode;
61446 pOut->p1 = pIn->p1;
61447 if( p2<0 ){
61448 assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
61449 pOut->p2 = addr + ADDR(p2);
61450 }else{
61451 pOut->p2 = p2;
61452 }
61453 pOut->p3 = pIn->p3;
61454 pOut->p4type = P4_NOTUSED;
61455 pOut->p4.p = 0;
61456 pOut->p5 = 0;
61457 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61458 pOut->zComment = 0;
61459 #endif
61460 #ifdef SQLITE_DEBUG
61461 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61462 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
61463 }
61464 #endif
61465 }
@@ -61298,15 +61543,17 @@
61543 assert( db );
61544 switch( p4type ){
61545 case P4_REAL:
61546 case P4_INT64:
61547 case P4_DYNAMIC:
61548 case P4_INTARRAY: {
 
 
61549 sqlite3DbFree(db, p4);
61550 break;
61551 }
61552 case P4_KEYINFO: {
61553 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
61554 break;
61555 }
61556 case P4_MPRINTF: {
61557 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
61558 break;
61559 }
@@ -61340,11 +61587,11 @@
61587 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
61588 if( aOp ){
61589 Op *pOp;
61590 for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
61591 freeP4(db, pOp->p4type, pOp->p4.p);
61592 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61593 sqlite3DbFree(db, pOp->zComment);
61594 #endif
61595 }
61596 }
61597 sqlite3DbFree(db, aOp);
@@ -61368,10 +61615,11 @@
61615 VdbeOp *pOp = &p->aOp[addr];
61616 sqlite3 *db = p->db;
61617 freeP4(db, pOp->p4type, pOp->p4.p);
61618 memset(pOp, 0, sizeof(pOp[0]));
61619 pOp->opcode = OP_Noop;
61620 if( addr==p->nOp-1 ) p->nOp--;
61621 }
61622 }
61623
61624 /*
61625 ** Change the value of the P4 operand for a specific instruction.
@@ -61381,18 +61629,10 @@
61629 **
61630 ** If n>=0 then the P4 operand is dynamic, meaning that a copy of
61631 ** the string is made into memory obtained from sqlite3_malloc().
61632 ** A value of n==0 means copy bytes of zP4 up to and including the
61633 ** first null byte. If n>0 then copy n+1 bytes of zP4.
 
 
 
 
 
 
 
 
61634 **
61635 ** Other values of n (P4_STATIC, P4_COLLSEQ etc.) indicate that zP4 points
61636 ** to a string or structure that is guaranteed to exist for the lifetime of
61637 ** the Vdbe. In these cases we can just copy the pointer.
61638 **
@@ -61403,11 +61643,11 @@
61643 sqlite3 *db;
61644 assert( p!=0 );
61645 db = p->db;
61646 assert( p->magic==VDBE_MAGIC_INIT );
61647 if( p->aOp==0 || db->mallocFailed ){
61648 if( n!=P4_VTAB ){
61649 freeP4(db, n, (void*)*(char**)&zP4);
61650 }
61651 return;
61652 }
61653 assert( p->nOp>0 );
@@ -61426,23 +61666,10 @@
61666 pOp->p4type = P4_INT32;
61667 }else if( zP4==0 ){
61668 pOp->p4.p = 0;
61669 pOp->p4type = P4_NOTUSED;
61670 }else if( n==P4_KEYINFO ){
 
 
 
 
 
 
 
 
 
 
 
 
 
61671 pOp->p4.p = (void*)zP4;
61672 pOp->p4type = P4_KEYINFO;
61673 }else if( n==P4_VTAB ){
61674 pOp->p4.p = (void*)zP4;
61675 pOp->p4type = P4_VTAB;
@@ -61456,11 +61683,23 @@
61683 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
61684 pOp->p4type = P4_DYNAMIC;
61685 }
61686 }
61687
61688 /*
61689 ** Set the P4 on the most recently added opcode to the KeyInfo for the
61690 ** index given.
61691 */
61692 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
61693 Vdbe *v = pParse->pVdbe;
61694 assert( v!=0 );
61695 assert( pIdx!=0 );
61696 sqlite3VdbeChangeP4(v, -1, (char*)sqlite3KeyInfoOfIndex(pParse, pIdx),
61697 P4_KEYINFO);
61698 }
61699
61700 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61701 /*
61702 ** Change the comment on the most recently coded instruction. Or
61703 ** insert a No-op and add the comment to that new instruction. This
61704 ** makes the code easier to read during debugging. None of this happens
61705 ** in a production build.
@@ -61530,10 +61769,85 @@
61769 return (VdbeOp*)&dummy;
61770 }else{
61771 return &p->aOp[addr];
61772 }
61773 }
61774
61775 #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
61776 /*
61777 ** Return an integer value for one of the parameters to the opcode pOp
61778 ** determined by character c.
61779 */
61780 static int translateP(char c, const Op *pOp){
61781 if( c=='1' ) return pOp->p1;
61782 if( c=='2' ) return pOp->p2;
61783 if( c=='3' ) return pOp->p3;
61784 if( c=='4' ) return pOp->p4.i;
61785 return pOp->p5;
61786 }
61787
61788 /*
61789 ** Compute a string for the "comment" field of a VDBE opcode listing
61790 */
61791 static int displayComment(
61792 const Op *pOp, /* The opcode to be commented */
61793 const char *zP4, /* Previously obtained value for P4 */
61794 char *zTemp, /* Write result here */
61795 int nTemp /* Space available in zTemp[] */
61796 ){
61797 const char *zOpName;
61798 const char *zSynopsis;
61799 int nOpName;
61800 int ii, jj;
61801 zOpName = sqlite3OpcodeName(pOp->opcode);
61802 nOpName = sqlite3Strlen30(zOpName);
61803 if( zOpName[nOpName+1] ){
61804 int seenCom = 0;
61805 char c;
61806 zSynopsis = zOpName += nOpName + 1;
61807 for(ii=jj=0; jj<nTemp-1 && (c = zSynopsis[ii])!=0; ii++){
61808 if( c=='P' ){
61809 c = zSynopsis[++ii];
61810 if( c=='4' ){
61811 sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zP4);
61812 }else if( c=='X' ){
61813 sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", pOp->zComment);
61814 seenCom = 1;
61815 }else{
61816 int v1 = translateP(c, pOp);
61817 int v2;
61818 sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
61819 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
61820 ii += 3;
61821 jj += sqlite3Strlen30(zTemp+jj);
61822 v2 = translateP(zSynopsis[ii], pOp);
61823 if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
61824 }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
61825 ii += 4;
61826 }
61827 }
61828 jj += sqlite3Strlen30(zTemp+jj);
61829 }else{
61830 zTemp[jj++] = c;
61831 }
61832 }
61833 if( !seenCom && jj<nTemp-5 && pOp->zComment ){
61834 sqlite3_snprintf(nTemp-jj, zTemp+jj, "; %s", pOp->zComment);
61835 jj += sqlite3Strlen30(zTemp+jj);
61836 }
61837 if( jj<nTemp ) zTemp[jj] = 0;
61838 }else if( pOp->zComment ){
61839 sqlite3_snprintf(nTemp, zTemp, "%s", pOp->zComment);
61840 jj = sqlite3Strlen30(zTemp);
61841 }else{
61842 zTemp[0] = 0;
61843 jj = 0;
61844 }
61845 return jj;
61846 }
61847 #endif /* SQLITE_DEBUG */
61848
61849
61850 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \
61851 || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
61852 /*
61853 ** Compute a string that describes the P4 parameter for an opcode.
@@ -61541,21 +61855,24 @@
61855 */
61856 static char *displayP4(Op *pOp, char *zTemp, int nTemp){
61857 char *zP4 = zTemp;
61858 assert( nTemp>=20 );
61859 switch( pOp->p4type ){
 
61860 case P4_KEYINFO: {
61861 int i, j;
61862 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
61863 assert( pKeyInfo->aSortOrder!=0 );
61864 sqlite3_snprintf(nTemp, zTemp, "k(%d", pKeyInfo->nField);
61865 i = sqlite3Strlen30(zTemp);
61866 for(j=0; j<pKeyInfo->nField; j++){
61867 CollSeq *pColl = pKeyInfo->aColl[j];
61868 const char *zColl = pColl ? pColl->zName : "nil";
61869 int n = sqlite3Strlen30(zColl);
61870 if( n==6 && memcmp(zColl,"BINARY",6)==0 ){
61871 zColl = "B";
61872 n = 1;
61873 }
61874 if( i+n>nTemp-6 ){
61875 memcpy(&zTemp[i],",...",4);
61876 break;
61877 }
61878 zTemp[i++] = ',';
@@ -61724,20 +62041,22 @@
62041 ** Print a single opcode. This routine is used for debugging only.
62042 */
62043 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
62044 char *zP4;
62045 char zPtr[50];
62046 char zCom[100];
62047 static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-13s %.2X %s\n";
62048 if( pOut==0 ) pOut = stdout;
62049 zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
62050 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62051 displayComment(pOp, zP4, zCom, sizeof(zCom));
62052 #else
62053 zCom[0] = 0
62054 #endif
62055 fprintf(pOut, zFormat1, pc,
62056 sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
62057 zCom
 
 
 
 
62058 );
62059 fflush(pOut);
62060 }
62061 #endif
62062
@@ -61879,11 +62198,11 @@
62198 }else if( db->u1.isInterrupted ){
62199 p->rc = SQLITE_INTERRUPT;
62200 rc = SQLITE_ERROR;
62201 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
62202 }else{
62203 char *zP4;
62204 Op *pOp;
62205 if( i<p->nOp ){
62206 /* The output line number is small enough that we are still in the
62207 ** main program. */
62208 pOp = &p->aOp[i];
@@ -61902,11 +62221,11 @@
62221 pMem->type = SQLITE_INTEGER;
62222 pMem->u.i = i; /* Program counter */
62223 pMem++;
62224
62225 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
62226 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
62227 assert( pMem->z!=0 );
62228 pMem->n = sqlite3Strlen30(pMem->z);
62229 pMem->type = SQLITE_TEXT;
62230 pMem->enc = SQLITE_UTF8;
62231 pMem++;
@@ -61949,13 +62268,13 @@
62268 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62269 assert( p->db->mallocFailed );
62270 return SQLITE_ERROR;
62271 }
62272 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62273 zP4 = displayP4(pOp, pMem->z, 32);
62274 if( zP4!=pMem->z ){
62275 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
62276 }else{
62277 assert( pMem->z!=0 );
62278 pMem->n = sqlite3Strlen30(pMem->z);
62279 pMem->enc = SQLITE_UTF8;
62280 }
@@ -61972,23 +62291,23 @@
62291 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62292 pMem->type = SQLITE_TEXT;
62293 pMem->enc = SQLITE_UTF8;
62294 pMem++;
62295
62296 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62297 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
62298 assert( p->db->mallocFailed );
62299 return SQLITE_ERROR;
62300 }
62301 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62302 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62303 pMem->type = SQLITE_TEXT;
62304 pMem->enc = SQLITE_UTF8;
62305 #else
62306 pMem->flags = MEM_Null; /* Comment */
62307 pMem->type = SQLITE_NULL;
62308 #endif
 
 
 
 
62309 }
62310
62311 p->nResColumn = 8 - 4*(p->explain-1);
62312 p->pResultSet = &p->aMem[1];
62313 p->rc = SQLITE_OK;
@@ -62775,11 +63094,11 @@
63094 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
63095 || (!deferred && p->nFkConstraint>0)
63096 ){
63097 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
63098 p->errorAction = OE_Abort;
63099 sqlite3SetString(&p->zErrMsg, db, "FOREIGN KEY constraint failed");
63100 return SQLITE_ERROR;
63101 }
63102 return SQLITE_OK;
63103 }
63104 #endif
@@ -63706,11 +64025,11 @@
64025 */
64026 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
64027
64028 idx1 = getVarint32(aKey1, szHdr1);
64029 d1 = szHdr1;
64030 assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField );
64031 assert( pKeyInfo->aSortOrder!=0 );
64032 while( idx1<szHdr1 && i<pPKey2->nField ){
64033 u32 serial_type1;
64034
64035 /* Read the serial types for the next element in each key. */
@@ -63735,28 +64054,13 @@
64054 /* Do the comparison
64055 */
64056 rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
64057 if( rc!=0 ){
64058 assert( mem1.zMalloc==0 ); /* See comment below */
 
 
64059 if( pKeyInfo->aSortOrder[i] ){
64060 rc = -rc; /* Invert the result for DESC sort order. */
64061 }
 
 
 
 
 
 
 
 
 
 
 
 
 
64062 return rc;
64063 }
64064 i++;
64065 }
64066
@@ -66271,77 +66575,81 @@
66575 */
66576 union vdbeExecUnion {
66577 struct OP_Yield_stack_vars {
66578 int pcDest;
66579 } aa;
66580 struct OP_Halt_stack_vars {
66581 const char *zType;
66582 const char *zLogFmt;
66583 } ab;
66584 struct OP_Null_stack_vars {
66585 int cnt;
66586 u16 nullFlag;
66587 } ac;
66588 struct OP_Variable_stack_vars {
66589 Mem *pVar; /* Value being transferred */
66590 } ad;
66591 struct OP_Move_stack_vars {
66592 char *zMalloc; /* Holding variable for allocated memory */
66593 int n; /* Number of registers left to copy */
66594 int p1; /* Register to copy from */
66595 int p2; /* Register to copy to */
66596 } ae;
66597 struct OP_Copy_stack_vars {
66598 int n;
66599 } af;
66600 struct OP_ResultRow_stack_vars {
66601 Mem *pMem;
66602 int i;
66603 } ag;
66604 struct OP_Concat_stack_vars {
66605 i64 nByte;
66606 } ah;
66607 struct OP_Remainder_stack_vars {
66608 char bIntint; /* Started out as two integer operands */
66609 int flags; /* Combined MEM_* flags from both inputs */
66610 i64 iA; /* Integer value of left operand */
66611 i64 iB; /* Integer value of right operand */
66612 double rA; /* Real value of left operand */
66613 double rB; /* Real value of right operand */
66614 } ai;
66615 struct OP_Function_stack_vars {
66616 int i;
66617 Mem *pArg;
66618 sqlite3_context ctx;
66619 sqlite3_value **apVal;
66620 int n;
66621 } aj;
66622 struct OP_ShiftRight_stack_vars {
66623 i64 iA;
66624 u64 uA;
66625 i64 iB;
66626 u8 op;
66627 } ak;
66628 struct OP_Ge_stack_vars {
66629 int res; /* Result of the comparison of pIn1 against pIn3 */
66630 char affinity; /* Affinity to use for comparison */
66631 u16 flags1; /* Copy of initial value of pIn1->flags */
66632 u16 flags3; /* Copy of initial value of pIn3->flags */
66633 } al;
66634 struct OP_Compare_stack_vars {
66635 int n;
66636 int i;
66637 int p1;
66638 int p2;
66639 const KeyInfo *pKeyInfo;
66640 int idx;
66641 CollSeq *pColl; /* Collating sequence to use on this term */
66642 int bRev; /* True for DESCENDING sort order */
66643 } am;
66644 struct OP_Or_stack_vars {
66645 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66646 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66647 } an;
66648 struct OP_IfNot_stack_vars {
66649 int c;
66650 } ao;
66651 struct OP_Column_stack_vars {
66652 u32 payloadSize; /* Number of bytes in the record */
66653 i64 payloadSize64; /* Number of bytes in the record */
66654 int p1; /* P1 value of the opcode */
66655 int p2; /* column number to retrieve */
@@ -66362,15 +66670,15 @@
66670 u32 szField; /* Number of bytes in the content of a field */
66671 int szHdr; /* Size of the header size field at start of record */
66672 int avail; /* Number of bytes of available data */
66673 u32 t; /* A type code from the record header */
66674 Mem *pReg; /* PseudoTable input register */
66675 } ap;
66676 struct OP_Affinity_stack_vars {
66677 const char *zAffinity; /* The affinity to be applied */
66678 char cAff; /* A single character of affinity */
66679 } aq;
66680 struct OP_MakeRecord_stack_vars {
66681 u8 *zNewRecord; /* A buffer to hold the data for the new record */
66682 Mem *pRec; /* The new record */
66683 u64 nData; /* Number of bytes of data space */
66684 int nHdr; /* Number of bytes of header space */
@@ -66383,93 +66691,86 @@
66691 int nField; /* Number of fields in the record */
66692 char *zAffinity; /* The affinity string for the record */
66693 int file_format; /* File format to use for encoding */
66694 int i; /* Space used in zNewRecord[] */
66695 int len; /* Length of a field */
66696 } ar;
66697 struct OP_Count_stack_vars {
66698 i64 nEntry;
66699 BtCursor *pCrsr;
66700 } as;
66701 struct OP_Savepoint_stack_vars {
66702 int p1; /* Value of P1 operand */
66703 char *zName; /* Name of savepoint */
66704 int nName;
66705 Savepoint *pNew;
66706 Savepoint *pSavepoint;
66707 Savepoint *pTmp;
66708 int iSavepoint;
66709 int ii;
66710 } at;
66711 struct OP_AutoCommit_stack_vars {
66712 int desiredAutoCommit;
66713 int iRollback;
66714 int turnOnAC;
66715 } au;
66716 struct OP_Transaction_stack_vars {
66717 Btree *pBt;
66718 } av;
66719 struct OP_ReadCookie_stack_vars {
66720 int iMeta;
66721 int iDb;
66722 int iCookie;
66723 } aw;
66724 struct OP_SetCookie_stack_vars {
66725 Db *pDb;
66726 } ax;
66727 struct OP_VerifyCookie_stack_vars {
66728 int iMeta;
66729 int iGen;
66730 Btree *pBt;
66731 } ay;
66732 struct OP_OpenWrite_stack_vars {
66733 int nField;
66734 KeyInfo *pKeyInfo;
66735 int p2;
66736 int iDb;
66737 int wrFlag;
66738 Btree *pX;
66739 VdbeCursor *pCur;
66740 Db *pDb;
66741 } az;
66742 struct OP_OpenEphemeral_stack_vars {
66743 VdbeCursor *pCx;
66744 KeyInfo *pKeyInfo;
66745 } ba;
66746 struct OP_SorterOpen_stack_vars {
66747 VdbeCursor *pCx;
66748 } bb;
66749 struct OP_OpenPseudo_stack_vars {
66750 VdbeCursor *pCx;
66751 } bc;
66752 struct OP_SeekGt_stack_vars {
66753 int res;
66754 int oc;
66755 VdbeCursor *pC;
66756 UnpackedRecord r;
66757 int nField;
66758 i64 iKey; /* The rowid we are to seek to */
66759 } bd;
66760 struct OP_Seek_stack_vars {
66761 VdbeCursor *pC;
66762 } be;
66763 struct OP_Found_stack_vars {
66764 int alreadyExists;
66765 int ii;
66766 VdbeCursor *pC;
66767 int res;
66768 char *pFree;
66769 UnpackedRecord *pIdxKey;
66770 UnpackedRecord r;
66771 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
 
 
 
 
 
 
 
 
 
66772 } bf;
66773 struct OP_NotExists_stack_vars {
66774 VdbeCursor *pC;
66775 BtCursor *pCrsr;
66776 int res;
@@ -66499,10 +66800,11 @@
66800 VdbeCursor *pC;
66801 } bj;
66802 struct OP_SorterCompare_stack_vars {
66803 VdbeCursor *pC;
66804 int res;
66805 int nIgnore;
66806 } bk;
66807 struct OP_SorterData_stack_vars {
66808 VdbeCursor *pC;
66809 } bl;
66810 struct OP_RowData_stack_vars {
@@ -66939,23 +67241,25 @@
67241 REGISTER_TRACE(pOp->p1, pIn1);
67242 pc = u.aa.pcDest;
67243 break;
67244 }
67245
67246 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67247 ** Synopsis: if r[P3] null then halt
67248 **
67249 ** Check the value in register P3. If it is NULL then Halt using
67250 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the
67251 ** value in register P3 is not NULL, then this routine is a no-op.
67252 ** The P5 parameter should be 1.
67253 */
67254 case OP_HaltIfNull: { /* in3 */
67255 pIn3 = &aMem[pOp->p3];
67256 if( (pIn3->flags & MEM_Null)==0 ) break;
67257 /* Fall through into OP_Halt */
67258 }
67259
67260 /* Opcode: Halt P1 P2 * P4 P5
67261 **
67262 ** Exit immediately. All open cursors, etc are closed
67263 ** automatically.
67264 **
67265 ** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
@@ -66965,26 +67269,42 @@
67269 ** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
67270 ** then back out all changes that have occurred during this execution of the
67271 ** VDBE, but do not rollback the transaction.
67272 **
67273 ** If P4 is not null then it is an error message string.
67274 **
67275 ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
67276 **
67277 ** 0: (no change)
67278 ** 1: NOT NULL contraint failed: P4
67279 ** 2: UNIQUE constraint failed: P4
67280 ** 3: CHECK constraint failed: P4
67281 ** 4: FOREIGN KEY constraint failed: P4
67282 **
67283 ** If P5 is not zero and P4 is NULL, then everything after the ":" is
67284 ** omitted.
67285 **
67286 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
67287 ** every program. So a jump past the last instruction of the program
67288 ** is the same as executing Halt.
67289 */
67290 case OP_Halt: {
67291 #if 0 /* local variables moved into u.ab */
67292 const char *zType;
67293 const char *zLogFmt;
67294 #endif /* local variables moved into u.ab */
67295
67296 if( pOp->p1==SQLITE_OK && p->pFrame ){
67297 /* Halt the sub-program. Return control to the parent frame. */
67298 VdbeFrame *pFrame = p->pFrame;
67299 p->pFrame = pFrame->pParent;
67300 p->nFrame--;
67301 sqlite3VdbeSetChanges(db, p->nChange);
67302 pc = sqlite3VdbeFrameRestore(pFrame);
67303 lastRowid = db->lastRowid;
67304 if( pOp->p2==OE_Ignore ){
67305 /* Instruction pc is the OP_Program that invoked the sub-program
67306 ** currently being halted. If the p2 instruction of this OP_Halt
67307 ** instruction is set to OE_Ignore, then the sub-program is throwing
67308 ** an IGNORE exception. In this case jump to the address specified
67309 ** as the p2 of the calling OP_Program. */
67310 pc = p->aOp[pc].p2-1;
@@ -66991,22 +67311,37 @@
67311 }
67312 aOp = p->aOp;
67313 aMem = p->aMem;
67314 break;
67315 }
 
67316 p->rc = pOp->p1;
67317 p->errorAction = (u8)pOp->p2;
67318 p->pc = pc;
67319 if( p->rc ){
67320 if( pOp->p5 ){
67321 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
67322 "FOREIGN KEY" };
67323 assert( pOp->p5>=1 && pOp->p5<=4 );
67324 testcase( pOp->p5==1 );
67325 testcase( pOp->p5==2 );
67326 testcase( pOp->p5==3 );
67327 testcase( pOp->p5==4 );
67328 u.ab.zType = azType[pOp->p5-1];
67329 }else{
67330 u.ab.zType = 0;
67331 }
67332 assert( u.ab.zType!=0 || pOp->p4.z!=0 );
67333 u.ab.zLogFmt = "abort at %d in [%s]: %s";
67334 if( u.ab.zType && pOp->p4.z ){
67335 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67336 u.ab.zType, pOp->p4.z);
67337 }else if( pOp->p4.z ){
67338 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67339 }else{
67340 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
67341 }
67342 sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
67343 }
67344 rc = sqlite3VdbeHalt(p);
67345 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67346 if( rc==SQLITE_BUSY ){
67347 p->rc = rc = SQLITE_BUSY;
@@ -67017,19 +67352,21 @@
67352 }
67353 goto vdbe_return;
67354 }
67355
67356 /* Opcode: Integer P1 P2 * * *
67357 ** Synopsis: r[P2]=P1
67358 **
67359 ** The 32-bit integer value P1 is written into register P2.
67360 */
67361 case OP_Integer: { /* out2-prerelease */
67362 pOut->u.i = pOp->p1;
67363 break;
67364 }
67365
67366 /* Opcode: Int64 * P2 * P4 *
67367 ** Synopsis: r[P2]=P4
67368 **
67369 ** P4 is a pointer to a 64-bit integer value.
67370 ** Write that value into register P2.
67371 */
67372 case OP_Int64: { /* out2-prerelease */
@@ -67038,10 +67375,11 @@
67375 break;
67376 }
67377
67378 #ifndef SQLITE_OMIT_FLOATING_POINT
67379 /* Opcode: Real * P2 * P4 *
67380 ** Synopsis: r[P2]=P4
67381 **
67382 ** P4 is a pointer to a 64-bit floating point value.
67383 ** Write that value into register P2.
67384 */
67385 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
@@ -67051,10 +67389,11 @@
67389 break;
67390 }
67391 #endif
67392
67393 /* Opcode: String8 * P2 * P4 *
67394 ** Synopsis: r[P2]='P4'
67395 **
67396 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67397 ** into an OP_String before it is executed for the first time.
67398 */
67399 case OP_String8: { /* same as TK_STRING, out2-prerelease */
@@ -67085,10 +67424,11 @@
67424 }
67425 /* Fall through to the next case, OP_String */
67426 }
67427
67428 /* Opcode: String P1 P2 * P4 *
67429 ** Synopsis: r[P2]='P4' (len=P1)
67430 **
67431 ** The string value P4 of length P1 (bytes) is stored in register P2.
67432 */
67433 case OP_String: { /* out2-prerelease */
67434 assert( pOp->p4.z!=0 );
@@ -67099,10 +67439,11 @@
67439 UPDATE_MAX_BLOBSIZE(pOut);
67440 break;
67441 }
67442
67443 /* Opcode: Null P1 P2 P3 * *
67444 ** Synopsis: r[P2..P3]=NULL
67445 **
67446 ** Write a NULL into registers P2. If P3 greater than P2, then also write
67447 ** NULL into register P3 and every register in between P2 and P3. If P3
67448 ** is less than P2 (typically P3 is zero) then only register P2 is
67449 ** set to NULL.
@@ -67110,29 +67451,30 @@
67451 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67452 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67453 ** OP_Ne or OP_Eq.
67454 */
67455 case OP_Null: { /* out2-prerelease */
67456 #if 0 /* local variables moved into u.ac */
67457 int cnt;
67458 u16 nullFlag;
67459 #endif /* local variables moved into u.ac */
67460 u.ac.cnt = pOp->p3-pOp->p2;
67461 assert( pOp->p3<=(p->nMem-p->nCursor) );
67462 pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67463 while( u.ac.cnt>0 ){
67464 pOut++;
67465 memAboutToChange(p, pOut);
67466 VdbeMemRelease(pOut);
67467 pOut->flags = u.ac.nullFlag;
67468 u.ac.cnt--;
67469 }
67470 break;
67471 }
67472
67473
67474 /* Opcode: Blob P1 P2 * P4
67475 ** Synopsis: r[P2]=P4 (len=P1)
67476 **
67477 ** P4 points to a blob of data P1 bytes long. Store this
67478 ** blob in register P2.
67479 */
67480 case OP_Blob: { /* out2-prerelease */
@@ -67142,107 +67484,111 @@
67484 UPDATE_MAX_BLOBSIZE(pOut);
67485 break;
67486 }
67487
67488 /* Opcode: Variable P1 P2 * P4 *
67489 ** Synopsis: r[P2]=parameter(P1,P4)
67490 **
67491 ** Transfer the values of bound parameter P1 into register P2
67492 **
67493 ** If the parameter is named, then its name appears in P4 and P3==1.
67494 ** The P4 value is used by sqlite3_bind_parameter_name().
67495 */
67496 case OP_Variable: { /* out2-prerelease */
67497 #if 0 /* local variables moved into u.ad */
67498 Mem *pVar; /* Value being transferred */
67499 #endif /* local variables moved into u.ad */
67500
67501 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67502 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67503 u.ad.pVar = &p->aVar[pOp->p1 - 1];
67504 if( sqlite3VdbeMemTooBig(u.ad.pVar) ){
67505 goto too_big;
67506 }
67507 sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
67508 UPDATE_MAX_BLOBSIZE(pOut);
67509 break;
67510 }
67511
67512 /* Opcode: Move P1 P2 P3 * *
67513 ** Synopsis: r[P2@P3]=r[P1@P3]
67514 **
67515 ** Move the values in register P1..P1+P3 over into
67516 ** registers P2..P2+P3. Registers P1..P1+P3 are
67517 ** left holding a NULL. It is an error for register ranges
67518 ** P1..P1+P3 and P2..P2+P3 to overlap.
67519 */
67520 case OP_Move: {
67521 #if 0 /* local variables moved into u.ae */
67522 char *zMalloc; /* Holding variable for allocated memory */
67523 int n; /* Number of registers left to copy */
67524 int p1; /* Register to copy from */
67525 int p2; /* Register to copy to */
67526 #endif /* local variables moved into u.ae */
67527
67528 u.ae.n = pOp->p3 + 1;
67529 u.ae.p1 = pOp->p1;
67530 u.ae.p2 = pOp->p2;
67531 assert( u.ae.n>0 && u.ae.p1>0 && u.ae.p2>0 );
67532 assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67533
67534 pIn1 = &aMem[u.ae.p1];
67535 pOut = &aMem[u.ae.p2];
67536 while( u.ae.n-- ){
67537 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67538 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67539 assert( memIsValid(pIn1) );
67540 memAboutToChange(p, pOut);
67541 u.ae.zMalloc = pOut->zMalloc;
67542 pOut->zMalloc = 0;
67543 sqlite3VdbeMemMove(pOut, pIn1);
67544 #ifdef SQLITE_DEBUG
67545 if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){
67546 pOut->pScopyFrom += u.ae.p1 - pOp->p2;
67547 }
67548 #endif
67549 pIn1->zMalloc = u.ae.zMalloc;
67550 REGISTER_TRACE(u.ae.p2++, pOut);
67551 pIn1++;
67552 pOut++;
67553 }
67554 break;
67555 }
67556
67557 /* Opcode: Copy P1 P2 P3 * *
67558 ** Synopsis: r[P2@P3]=r[P1@P3]
67559 **
67560 ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
67561 **
67562 ** This instruction makes a deep copy of the value. A duplicate
67563 ** is made of any string or blob constant. See also OP_SCopy.
67564 */
67565 case OP_Copy: {
67566 #if 0 /* local variables moved into u.af */
67567 int n;
67568 #endif /* local variables moved into u.af */
67569
67570 u.af.n = pOp->p3;
67571 pIn1 = &aMem[pOp->p1];
67572 pOut = &aMem[pOp->p2];
67573 assert( pOut!=pIn1 );
67574 while( 1 ){
67575 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67576 Deephemeralize(pOut);
67577 #ifdef SQLITE_DEBUG
67578 pOut->pScopyFrom = 0;
67579 #endif
67580 REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut);
67581 if( (u.af.n--)==0 ) break;
67582 pOut++;
67583 pIn1++;
67584 }
67585 break;
67586 }
67587
67588 /* Opcode: SCopy P1 P2 * * *
67589 ** Synopsis: r[P2]=r[P1]
67590 **
67591 ** Make a shallow copy of register P1 into register P2.
67592 **
67593 ** This instruction makes a shallow copy of the value. If the value
67594 ** is a string or blob, then the copy is only a pointer to the
@@ -67250,35 +67596,35 @@
67596 ** Worse, if the original is deallocated, the copy becomes invalid.
67597 ** Thus the program must guarantee that the original will not change
67598 ** during the lifetime of the copy. Use OP_Copy to make a complete
67599 ** copy.
67600 */
67601 case OP_SCopy: { /* out2 */
67602 pIn1 = &aMem[pOp->p1];
67603 pOut = &aMem[pOp->p2];
67604 assert( pOut!=pIn1 );
67605 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67606 #ifdef SQLITE_DEBUG
67607 if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1;
67608 #endif
 
67609 break;
67610 }
67611
67612 /* Opcode: ResultRow P1 P2 * * *
67613 ** Synopsis: output=r[P1@P2]
67614 **
67615 ** The registers P1 through P1+P2-1 contain a single row of
67616 ** results. This opcode causes the sqlite3_step() call to terminate
67617 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67618 ** structure to provide access to the top P1 values as the result
67619 ** row.
67620 */
67621 case OP_ResultRow: {
67622 #if 0 /* local variables moved into u.ag */
67623 Mem *pMem;
67624 int i;
67625 #endif /* local variables moved into u.ag */
67626 assert( p->nResColumn==pOp->p2 );
67627 assert( pOp->p1>0 );
67628 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67629
67630 /* If this statement has violated immediate foreign key constraints, do
@@ -67316,19 +67662,19 @@
67662
67663 /* Make sure the results of the current row are \000 terminated
67664 ** and have an assigned type. The results are de-ephemeralized as
67665 ** a side effect.
67666 */
67667 u.ag.pMem = p->pResultSet = &aMem[pOp->p1];
67668 for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){
67669 assert( memIsValid(&u.ag.pMem[u.ag.i]) );
67670 Deephemeralize(&u.ag.pMem[u.ag.i]);
67671 assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0
67672 || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 );
67673 sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]);
67674 sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]);
67675 REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]);
67676 }
67677 if( db->mallocFailed ) goto no_mem;
67678
67679 /* Return SQLITE_ROW
67680 */
@@ -67336,10 +67682,11 @@
67682 rc = SQLITE_ROW;
67683 goto vdbe_return;
67684 }
67685
67686 /* Opcode: Concat P1 P2 P3 * *
67687 ** Synopsis: r[P3]=r[P2]+r[P1]
67688 **
67689 ** Add the text in register P1 onto the end of the text in
67690 ** register P2 and store the result in register P3.
67691 ** If either the P1 or P2 text are NULL then store NULL in P3.
67692 **
@@ -67348,13 +67695,13 @@
67695 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67696 ** if P3 is the same register as P2, the implementation is able
67697 ** to avoid a memcpy().
67698 */
67699 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67700 #if 0 /* local variables moved into u.ah */
67701 i64 nByte;
67702 #endif /* local variables moved into u.ah */
67703
67704 pIn1 = &aMem[pOp->p1];
67705 pIn2 = &aMem[pOp->p2];
67706 pOut = &aMem[pOp->p3];
67707 assert( pIn1!=pOut );
@@ -67363,58 +67710,63 @@
67710 break;
67711 }
67712 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67713 Stringify(pIn1, encoding);
67714 Stringify(pIn2, encoding);
67715 u.ah.nByte = pIn1->n + pIn2->n;
67716 if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67717 goto too_big;
67718 }
67719 MemSetTypeFlag(pOut, MEM_Str);
67720 if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
67721 goto no_mem;
67722 }
67723 if( pOut!=pIn2 ){
67724 memcpy(pOut->z, pIn2->z, pIn2->n);
67725 }
67726 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67727 pOut->z[u.ah.nByte]=0;
67728 pOut->z[u.ah.nByte+1] = 0;
67729 pOut->flags |= MEM_Term;
67730 pOut->n = (int)u.ah.nByte;
67731 pOut->enc = encoding;
67732 UPDATE_MAX_BLOBSIZE(pOut);
67733 break;
67734 }
67735
67736 /* Opcode: Add P1 P2 P3 * *
67737 ** Synopsis: r[P3]=r[P1]+r[P2]
67738 **
67739 ** Add the value in register P1 to the value in register P2
67740 ** and store the result in register P3.
67741 ** If either input is NULL, the result is NULL.
67742 */
67743 /* Opcode: Multiply P1 P2 P3 * *
67744 ** Synopsis: r[P3]=r[P1]*r[P2]
67745 **
67746 **
67747 ** Multiply the value in register P1 by the value in register P2
67748 ** and store the result in register P3.
67749 ** If either input is NULL, the result is NULL.
67750 */
67751 /* Opcode: Subtract P1 P2 P3 * *
67752 ** Synopsis: r[P3]=r[P2]-r[P1]
67753 **
67754 ** Subtract the value in register P1 from the value in register P2
67755 ** and store the result in register P3.
67756 ** If either input is NULL, the result is NULL.
67757 */
67758 /* Opcode: Divide P1 P2 P3 * *
67759 ** Synopsis: r[P3]=r[P1]/r[P2]
67760 **
67761 ** Divide the value in register P1 by the value in register P2
67762 ** and store the result in register P3 (P3=P2/P1). If the value in
67763 ** register P1 is zero, then the result is NULL. If either input is
67764 ** NULL, the result is NULL.
67765 */
67766 /* Opcode: Remainder P1 P2 P3 * *
67767 ** Synopsis: r[P3]=r[P1]%r[P2]
67768 **
67769 ** Compute the remainder after integer division of the value in
67770 ** register P1 by the value in register P2 and store the result in P3.
67771 ** If the value in register P2 is zero the result is NULL.
67772 ** If either operand is NULL, the result is NULL.
@@ -67422,83 +67774,83 @@
67774 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67775 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67776 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67777 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67778 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67779 #if 0 /* local variables moved into u.ai */
67780 char bIntint; /* Started out as two integer operands */
67781 int flags; /* Combined MEM_* flags from both inputs */
67782 i64 iA; /* Integer value of left operand */
67783 i64 iB; /* Integer value of right operand */
67784 double rA; /* Real value of left operand */
67785 double rB; /* Real value of right operand */
67786 #endif /* local variables moved into u.ai */
67787
67788 pIn1 = &aMem[pOp->p1];
67789 applyNumericAffinity(pIn1);
67790 pIn2 = &aMem[pOp->p2];
67791 applyNumericAffinity(pIn2);
67792 pOut = &aMem[pOp->p3];
67793 u.ai.flags = pIn1->flags | pIn2->flags;
67794 if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67795 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67796 u.ai.iA = pIn1->u.i;
67797 u.ai.iB = pIn2->u.i;
67798 u.ai.bIntint = 1;
67799 switch( pOp->opcode ){
67800 case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67801 case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67802 case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67803 case OP_Divide: {
67804 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67805 if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math;
67806 u.ai.iB /= u.ai.iA;
67807 break;
67808 }
67809 default: {
67810 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67811 if( u.ai.iA==-1 ) u.ai.iA = 1;
67812 u.ai.iB %= u.ai.iA;
67813 break;
67814 }
67815 }
67816 pOut->u.i = u.ai.iB;
67817 MemSetTypeFlag(pOut, MEM_Int);
67818 }else{
67819 u.ai.bIntint = 0;
67820 fp_math:
67821 u.ai.rA = sqlite3VdbeRealValue(pIn1);
67822 u.ai.rB = sqlite3VdbeRealValue(pIn2);
67823 switch( pOp->opcode ){
67824 case OP_Add: u.ai.rB += u.ai.rA; break;
67825 case OP_Subtract: u.ai.rB -= u.ai.rA; break;
67826 case OP_Multiply: u.ai.rB *= u.ai.rA; break;
67827 case OP_Divide: {
67828 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67829 if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null;
67830 u.ai.rB /= u.ai.rA;
67831 break;
67832 }
67833 default: {
67834 u.ai.iA = (i64)u.ai.rA;
67835 u.ai.iB = (i64)u.ai.rB;
67836 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67837 if( u.ai.iA==-1 ) u.ai.iA = 1;
67838 u.ai.rB = (double)(u.ai.iB % u.ai.iA);
67839 break;
67840 }
67841 }
67842 #ifdef SQLITE_OMIT_FLOATING_POINT
67843 pOut->u.i = u.ai.rB;
67844 MemSetTypeFlag(pOut, MEM_Int);
67845 #else
67846 if( sqlite3IsNaN(u.ai.rB) ){
67847 goto arithmetic_result_is_null;
67848 }
67849 pOut->r = u.ai.rB;
67850 MemSetTypeFlag(pOut, MEM_Real);
67851 if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
67852 sqlite3VdbeIntegerAffinity(pOut);
67853 }
67854 #endif
67855 }
67856 break;
@@ -67530,10 +67882,11 @@
67882 }
67883 break;
67884 }
67885
67886 /* Opcode: Function P1 P2 P3 P4 P5
67887 ** Synopsis: r[P3]=func(r[P2@P5])
67888 **
67889 ** Invoke a user function (P4 is a pointer to a Function structure that
67890 ** defines the function) with P5 arguments taken from register P2 and
67891 ** successors. The result of the function is stored in register P3.
67892 ** Register P3 must not be one of the function inputs.
@@ -67546,85 +67899,85 @@
67899 ** invocation of this opcode.
67900 **
67901 ** See also: AggStep and AggFinal
67902 */
67903 case OP_Function: {
67904 #if 0 /* local variables moved into u.aj */
67905 int i;
67906 Mem *pArg;
67907 sqlite3_context ctx;
67908 sqlite3_value **apVal;
67909 int n;
67910 #endif /* local variables moved into u.aj */
67911
67912 u.aj.n = pOp->p5;
67913 u.aj.apVal = p->apArg;
67914 assert( u.aj.apVal || u.aj.n==0 );
67915 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
67916 pOut = &aMem[pOp->p3];
67917 memAboutToChange(p, pOut);
67918
67919 assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) );
67920 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n );
67921 u.aj.pArg = &aMem[pOp->p2];
67922 for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){
67923 assert( memIsValid(u.aj.pArg) );
67924 u.aj.apVal[u.aj.i] = u.aj.pArg;
67925 Deephemeralize(u.aj.pArg);
67926 sqlite3VdbeMemStoreType(u.aj.pArg);
67927 REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
67928 }
67929
67930 assert( pOp->p4type==P4_FUNCDEF );
67931 u.aj.ctx.pFunc = pOp->p4.pFunc;
67932 u.aj.ctx.s.flags = MEM_Null;
67933 u.aj.ctx.s.db = db;
67934 u.aj.ctx.s.xDel = 0;
67935 u.aj.ctx.s.zMalloc = 0;
67936 u.aj.ctx.iOp = pc;
67937 u.aj.ctx.pVdbe = p;
67938
67939 /* The output cell may already have a buffer allocated. Move
67940 ** the pointer to u.aj.ctx.s so in case the user-function can use
67941 ** the already allocated buffer instead of allocating a new one.
67942 */
67943 sqlite3VdbeMemMove(&u.aj.ctx.s, pOut);
67944 MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
67945
67946 u.aj.ctx.fErrorOrAux = 0;
67947 if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67948 assert( pOp>aOp );
67949 assert( pOp[-1].p4type==P4_COLLSEQ );
67950 assert( pOp[-1].opcode==OP_CollSeq );
67951 u.aj.ctx.pColl = pOp[-1].p4.pColl;
67952 }
67953 db->lastRowid = lastRowid;
67954 (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */
67955 lastRowid = db->lastRowid;
67956
67957 if( db->mallocFailed ){
67958 /* Even though a malloc() has failed, the implementation of the
67959 ** user function may have called an sqlite3_result_XXX() function
67960 ** to return a value. The following call releases any resources
67961 ** associated with such a value.
67962 */
67963 sqlite3VdbeMemRelease(&u.aj.ctx.s);
67964 goto no_mem;
67965 }
67966
67967 /* If the function returned an error, throw an exception */
67968 if( u.aj.ctx.fErrorOrAux ){
67969 if( u.aj.ctx.isError ){
67970 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s));
67971 rc = u.aj.ctx.isError;
67972 }
67973 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
67974 }
67975
67976 /* Copy the result of the function into register P3 */
67977 sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
67978 sqlite3VdbeMemMove(pOut, &u.aj.ctx.s);
67979 if( sqlite3VdbeMemTooBig(pOut) ){
67980 goto too_big;
67981 }
67982
67983 #if 0
@@ -67639,29 +67992,33 @@
67992 UPDATE_MAX_BLOBSIZE(pOut);
67993 break;
67994 }
67995
67996 /* Opcode: BitAnd P1 P2 P3 * *
67997 ** Synopsis: r[P3]=r[P1]&r[P2]
67998 **
67999 ** Take the bit-wise AND of the values in register P1 and P2 and
68000 ** store the result in register P3.
68001 ** If either input is NULL, the result is NULL.
68002 */
68003 /* Opcode: BitOr P1 P2 P3 * *
68004 ** Synopsis: r[P3]=r[P1]|r[P2]
68005 **
68006 ** Take the bit-wise OR of the values in register P1 and P2 and
68007 ** store the result in register P3.
68008 ** If either input is NULL, the result is NULL.
68009 */
68010 /* Opcode: ShiftLeft P1 P2 P3 * *
68011 ** Synopsis: r[P3]=r[P2]<<r[P1]
68012 **
68013 ** Shift the integer value in register P2 to the left by the
68014 ** number of bits specified by the integer in register P1.
68015 ** Store the result in register P3.
68016 ** If either input is NULL, the result is NULL.
68017 */
68018 /* Opcode: ShiftRight P1 P2 P3 * *
68019 ** Synopsis: r[P3]=r[P2]>>r[P1]
68020 **
68021 ** Shift the integer value in register P2 to the right by the
68022 ** number of bits specified by the integer in register P1.
68023 ** Store the result in register P3.
68024 ** If either input is NULL, the result is NULL.
@@ -67668,61 +68025,62 @@
68025 */
68026 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
68027 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
68028 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
68029 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
68030 #if 0 /* local variables moved into u.ak */
68031 i64 iA;
68032 u64 uA;
68033 i64 iB;
68034 u8 op;
68035 #endif /* local variables moved into u.ak */
68036
68037 pIn1 = &aMem[pOp->p1];
68038 pIn2 = &aMem[pOp->p2];
68039 pOut = &aMem[pOp->p3];
68040 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
68041 sqlite3VdbeMemSetNull(pOut);
68042 break;
68043 }
68044 u.ak.iA = sqlite3VdbeIntValue(pIn2);
68045 u.ak.iB = sqlite3VdbeIntValue(pIn1);
68046 u.ak.op = pOp->opcode;
68047 if( u.ak.op==OP_BitAnd ){
68048 u.ak.iA &= u.ak.iB;
68049 }else if( u.ak.op==OP_BitOr ){
68050 u.ak.iA |= u.ak.iB;
68051 }else if( u.ak.iB!=0 ){
68052 assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft );
68053
68054 /* If shifting by a negative amount, shift in the other direction */
68055 if( u.ak.iB<0 ){
68056 assert( OP_ShiftRight==OP_ShiftLeft+1 );
68057 u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op;
68058 u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64;
68059 }
68060
68061 if( u.ak.iB>=64 ){
68062 u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1;
68063 }else{
68064 memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA));
68065 if( u.ak.op==OP_ShiftLeft ){
68066 u.ak.uA <<= u.ak.iB;
68067 }else{
68068 u.ak.uA >>= u.ak.iB;
68069 /* Sign-extend on a right shift of a negative number */
68070 if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB);
68071 }
68072 memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
68073 }
68074 }
68075 pOut->u.i = u.ak.iA;
68076 MemSetTypeFlag(pOut, MEM_Int);
68077 break;
68078 }
68079
68080 /* Opcode: AddImm P1 P2 * * *
68081 ** Synopsis: r[P1]=r[P1]+P2
68082 **
68083 ** Add the constant P2 to the value in register P1.
68084 ** The result is always an integer.
68085 **
68086 ** To force any register to be an integer, just add 0.
@@ -67877,10 +68235,11 @@
68235 break;
68236 }
68237 #endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
68238
68239 /* Opcode: Lt P1 P2 P3 P4 P5
68240 ** Synopsis: if r[P1]<r[P3] goto P3
68241 **
68242 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
68243 ** jump to address P2.
68244 **
68245 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -67911,10 +68270,11 @@
68270 ** If the SQLITE_NULLEQ bit is set in P5, then NULL values are considered
68271 ** equal to one another, provided that they do not have their MEM_Cleared
68272 ** bit set.
68273 */
68274 /* Opcode: Ne P1 P2 P3 P4 P5
68275 ** Synopsis: if r[P1]!=r[P3] goto P2
68276 **
68277 ** This works just like the Lt opcode except that the jump is taken if
68278 ** the operands in registers P1 and P3 are not equal. See the Lt opcode for
68279 ** additional information.
68280 **
@@ -67923,10 +68283,11 @@
68283 ** of comparison is false. If either operand is NULL then the result is true.
68284 ** If neither operand is NULL the result is the same as it would be if
68285 ** the SQLITE_NULLEQ flag were omitted from P5.
68286 */
68287 /* Opcode: Eq P1 P2 P3 P4 P5
68288 ** Synopsis: if r[P1]==r[P3] goto P2
68289 **
68290 ** This works just like the Lt opcode except that the jump is taken if
68291 ** the operands in registers P1 and P3 are equal.
68292 ** See the Lt opcode for additional information.
68293 **
@@ -67935,22 +68296,25 @@
68296 ** of comparison is true. If either operand is NULL then the result is false.
68297 ** If neither operand is NULL the result is the same as it would be if
68298 ** the SQLITE_NULLEQ flag were omitted from P5.
68299 */
68300 /* Opcode: Le P1 P2 P3 P4 P5
68301 ** Synopsis: if r[P1]<=r[P3] goto P2
68302 **
68303 ** This works just like the Lt opcode except that the jump is taken if
68304 ** the content of register P3 is less than or equal to the content of
68305 ** register P1. See the Lt opcode for additional information.
68306 */
68307 /* Opcode: Gt P1 P2 P3 P4 P5
68308 ** Synopsis: if r[P1]>r[P3] goto P2
68309 **
68310 ** This works just like the Lt opcode except that the jump is taken if
68311 ** the content of register P3 is greater than the content of
68312 ** register P1. See the Lt opcode for additional information.
68313 */
68314 /* Opcode: Ge P1 P2 P3 P4 P5
68315 ** Synopsis: if r[P1]>=r[P3] goto P2
68316 **
68317 ** This works just like the Lt opcode except that the jump is taken if
68318 ** the content of register P3 is greater than or equal to the content of
68319 ** register P1. See the Lt opcode for additional information.
68320 */
@@ -67958,37 +68322,37 @@
68322 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
68323 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
68324 case OP_Le: /* same as TK_LE, jump, in1, in3 */
68325 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
68326 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
68327 #if 0 /* local variables moved into u.al */
68328 int res; /* Result of the comparison of pIn1 against pIn3 */
68329 char affinity; /* Affinity to use for comparison */
68330 u16 flags1; /* Copy of initial value of pIn1->flags */
68331 u16 flags3; /* Copy of initial value of pIn3->flags */
68332 #endif /* local variables moved into u.al */
68333
68334 pIn1 = &aMem[pOp->p1];
68335 pIn3 = &aMem[pOp->p3];
68336 u.al.flags1 = pIn1->flags;
68337 u.al.flags3 = pIn3->flags;
68338 if( (u.al.flags1 | u.al.flags3)&MEM_Null ){
68339 /* One or both operands are NULL */
68340 if( pOp->p5 & SQLITE_NULLEQ ){
68341 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
68342 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68343 ** or not both operands are null.
68344 */
68345 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68346 assert( (u.al.flags1 & MEM_Cleared)==0 );
68347 if( (u.al.flags1&MEM_Null)!=0
68348 && (u.al.flags3&MEM_Null)!=0
68349 && (u.al.flags3&MEM_Cleared)==0
68350 ){
68351 u.al.res = 0; /* Results are equal */
68352 }else{
68353 u.al.res = 1; /* Results are not equal */
68354 }
68355 }else{
68356 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68357 ** then the result is always NULL.
68358 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68002,44 +68366,44 @@
68366 }
68367 break;
68368 }
68369 }else{
68370 /* Neither operand is NULL. Do a comparison. */
68371 u.al.affinity = pOp->p5 & SQLITE_AFF_MASK;
68372 if( u.al.affinity ){
68373 applyAffinity(pIn1, u.al.affinity, encoding);
68374 applyAffinity(pIn3, u.al.affinity, encoding);
68375 if( db->mallocFailed ) goto no_mem;
68376 }
68377
68378 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68379 ExpandBlob(pIn1);
68380 ExpandBlob(pIn3);
68381 u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68382 }
68383 switch( pOp->opcode ){
68384 case OP_Eq: u.al.res = u.al.res==0; break;
68385 case OP_Ne: u.al.res = u.al.res!=0; break;
68386 case OP_Lt: u.al.res = u.al.res<0; break;
68387 case OP_Le: u.al.res = u.al.res<=0; break;
68388 case OP_Gt: u.al.res = u.al.res>0; break;
68389 default: u.al.res = u.al.res>=0; break;
68390 }
68391
68392 if( pOp->p5 & SQLITE_STOREP2 ){
68393 pOut = &aMem[pOp->p2];
68394 memAboutToChange(p, pOut);
68395 MemSetTypeFlag(pOut, MEM_Int);
68396 pOut->u.i = u.al.res;
68397 REGISTER_TRACE(pOp->p2, pOut);
68398 }else if( u.al.res ){
68399 pc = pOp->p2-1;
68400 }
68401
68402 /* Undo any changes made by applyAffinity() to the input registers. */
68403 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask);
68404 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask);
68405 break;
68406 }
68407
68408 /* Opcode: Permutation * * * P4 *
68409 **
@@ -68075,51 +68439,51 @@
68439 ** The comparison is a sort comparison, so NULLs compare equal,
68440 ** NULLs are less than numbers, numbers are less than strings,
68441 ** and strings are less than blobs.
68442 */
68443 case OP_Compare: {
68444 #if 0 /* local variables moved into u.am */
68445 int n;
68446 int i;
68447 int p1;
68448 int p2;
68449 const KeyInfo *pKeyInfo;
68450 int idx;
68451 CollSeq *pColl; /* Collating sequence to use on this term */
68452 int bRev; /* True for DESCENDING sort order */
68453 #endif /* local variables moved into u.am */
68454
68455 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68456 u.am.n = pOp->p3;
68457 u.am.pKeyInfo = pOp->p4.pKeyInfo;
68458 assert( u.am.n>0 );
68459 assert( u.am.pKeyInfo!=0 );
68460 u.am.p1 = pOp->p1;
68461 u.am.p2 = pOp->p2;
68462 #if SQLITE_DEBUG
68463 if( aPermute ){
68464 int k, mx = 0;
68465 for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68466 assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 );
68467 assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 );
68468 }else{
68469 assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 );
68470 assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 );
68471 }
68472 #endif /* SQLITE_DEBUG */
68473 for(u.am.i=0; u.am.i<u.am.n; u.am.i++){
68474 u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i;
68475 assert( memIsValid(&aMem[u.am.p1+u.am.idx]) );
68476 assert( memIsValid(&aMem[u.am.p2+u.am.idx]) );
68477 REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]);
68478 REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]);
68479 assert( u.am.i<u.am.pKeyInfo->nField );
68480 u.am.pColl = u.am.pKeyInfo->aColl[u.am.i];
68481 u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i];
68482 iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl);
68483 if( iCompare ){
68484 if( u.am.bRev ) iCompare = -iCompare;
68485 break;
68486 }
68487 }
68488 aPermute = 0;
68489 break;
@@ -68141,19 +68505,21 @@
68505 }
68506 break;
68507 }
68508
68509 /* Opcode: And P1 P2 P3 * *
68510 ** Synopsis: r[P3]=(r[P1] && r[P2])
68511 **
68512 ** Take the logical AND of the values in registers P1 and P2 and
68513 ** write the result into register P3.
68514 **
68515 ** If either P1 or P2 is 0 (false) then the result is 0 even if
68516 ** the other input is NULL. A NULL and true or two NULLs give
68517 ** a NULL output.
68518 */
68519 /* Opcode: Or P1 P2 P3 * *
68520 ** Synopsis: r[P3]=(r[P1] || r[P2])
68521 **
68522 ** Take the logical OR of the values in register P1 and P2 and
68523 ** store the answer in register P3.
68524 **
68525 ** If either P1 or P2 is nonzero (true) then the result is 1 (true)
@@ -68160,45 +68526,46 @@
68526 ** even if the other input is NULL. A NULL and false or two NULLs
68527 ** give a NULL output.
68528 */
68529 case OP_And: /* same as TK_AND, in1, in2, out3 */
68530 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68531 #if 0 /* local variables moved into u.an */
68532 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68533 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68534 #endif /* local variables moved into u.an */
68535
68536 pIn1 = &aMem[pOp->p1];
68537 if( pIn1->flags & MEM_Null ){
68538 u.an.v1 = 2;
68539 }else{
68540 u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68541 }
68542 pIn2 = &aMem[pOp->p2];
68543 if( pIn2->flags & MEM_Null ){
68544 u.an.v2 = 2;
68545 }else{
68546 u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68547 }
68548 if( pOp->opcode==OP_And ){
68549 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68550 u.an.v1 = and_logic[u.an.v1*3+u.an.v2];
68551 }else{
68552 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68553 u.an.v1 = or_logic[u.an.v1*3+u.an.v2];
68554 }
68555 pOut = &aMem[pOp->p3];
68556 if( u.an.v1==2 ){
68557 MemSetTypeFlag(pOut, MEM_Null);
68558 }else{
68559 pOut->u.i = u.an.v1;
68560 MemSetTypeFlag(pOut, MEM_Int);
68561 }
68562 break;
68563 }
68564
68565 /* Opcode: Not P1 P2 * * *
68566 ** Synopsis: r[P2]= !r[P1]
68567 **
68568 ** Interpret the value in register P1 as a boolean value. Store the
68569 ** boolean complement in register P2. If the value in register P1 is
68570 ** NULL, then a NULL is stored in P2.
68571 */
@@ -68212,10 +68579,11 @@
68579 }
68580 break;
68581 }
68582
68583 /* Opcode: BitNot P1 P2 * * *
68584 ** Synopsis: r[P1]= ~r[P1]
68585 **
68586 ** Interpret the content of register P1 as an integer. Store the
68587 ** ones-complement of the P1 value into register P2. If P1 holds
68588 ** a NULL then store a NULL in P2.
68589 */
@@ -68257,31 +68625,32 @@
68625 ** is considered false if it has a numeric value of zero. If the value
68626 ** in P1 is NULL then take the jump if P3 is zero.
68627 */
68628 case OP_If: /* jump, in1 */
68629 case OP_IfNot: { /* jump, in1 */
68630 #if 0 /* local variables moved into u.ao */
68631 int c;
68632 #endif /* local variables moved into u.ao */
68633 pIn1 = &aMem[pOp->p1];
68634 if( pIn1->flags & MEM_Null ){
68635 u.ao.c = pOp->p3;
68636 }else{
68637 #ifdef SQLITE_OMIT_FLOATING_POINT
68638 u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
68639 #else
68640 u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68641 #endif
68642 if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
68643 }
68644 if( u.ao.c ){
68645 pc = pOp->p2-1;
68646 }
68647 break;
68648 }
68649
68650 /* Opcode: IsNull P1 P2 * * *
68651 ** Synopsis: if r[P1]==NULL goto P2
68652 **
68653 ** Jump to P2 if the value in register P1 is NULL.
68654 */
68655 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
68656 pIn1 = &aMem[pOp->p1];
@@ -68290,10 +68659,11 @@
68659 }
68660 break;
68661 }
68662
68663 /* Opcode: NotNull P1 P2 * * *
68664 ** Synopsis: if r[P1]!=NULL goto P2
68665 **
68666 ** Jump to P2 if the value in register P1 is not NULL.
68667 */
68668 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
68669 pIn1 = &aMem[pOp->p1];
@@ -68302,10 +68672,11 @@
68672 }
68673 break;
68674 }
68675
68676 /* Opcode: Column P1 P2 P3 P4 P5
68677 ** Synopsis: r[P3]=PX
68678 **
68679 ** Interpret the data that cursor P1 points to as a structure built using
68680 ** the MakeRecord instruction. (See the MakeRecord opcode for additional
68681 ** information about the format of the data.) Extract the P2-th column
68682 ** from this record. If there are less that (P2+1)
@@ -68326,11 +68697,11 @@
68697 ** the result is guaranteed to only be used as the argument of a length()
68698 ** or typeof() function, respectively. The loading of large blobs can be
68699 ** skipped for length() and all content loading can be skipped for typeof().
68700 */
68701 case OP_Column: {
68702 #if 0 /* local variables moved into u.ap */
68703 u32 payloadSize; /* Number of bytes in the record */
68704 i64 payloadSize64; /* Number of bytes in the record */
68705 int p1; /* P1 value of the opcode */
68706 int p2; /* column number to retrieve */
68707 VdbeCursor *pC; /* The VDBE cursor */
@@ -68350,135 +68721,133 @@
68721 u32 szField; /* Number of bytes in the content of a field */
68722 int szHdr; /* Size of the header size field at start of record */
68723 int avail; /* Number of bytes of available data */
68724 u32 t; /* A type code from the record header */
68725 Mem *pReg; /* PseudoTable input register */
68726 #endif /* local variables moved into u.ap */
68727
68728
68729 u.ap.p1 = pOp->p1;
68730 u.ap.p2 = pOp->p2;
68731 u.ap.pC = 0;
68732 memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
68733 assert( u.ap.p1<p->nCursor );
68734 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68735 u.ap.pDest = &aMem[pOp->p3];
68736 memAboutToChange(p, u.ap.pDest);
68737 u.ap.zRec = 0;
68738
68739 /* This block sets the variable u.ap.payloadSize to be the total number of
68740 ** bytes in the record.
68741 **
68742 ** u.ap.zRec is set to be the complete text of the record if it is available.
68743 ** The complete record text is always available for pseudo-tables
68744 ** If the record is stored in a cursor, the complete record text
68745 ** might be available in the u.ap.pC->aRow cache. Or it might not be.
68746 ** If the data is unavailable, u.ap.zRec is set to NULL.
68747 **
68748 ** We also compute the number of columns in the record. For cursors,
68749 ** the number of columns is stored in the VdbeCursor.nField element.
68750 */
68751 u.ap.pC = p->apCsr[u.ap.p1];
68752 assert( u.ap.pC!=0 );
68753 #ifndef SQLITE_OMIT_VIRTUALTABLE
68754 assert( u.ap.pC->pVtabCursor==0 );
68755 #endif
68756 u.ap.pCrsr = u.ap.pC->pCursor;
68757 if( u.ap.pCrsr!=0 ){
68758 /* The record is stored in a B-Tree */
68759 rc = sqlite3VdbeCursorMoveto(u.ap.pC);
68760 if( rc ) goto abort_due_to_error;
68761 if( u.ap.pC->nullRow ){
68762 u.ap.payloadSize = 0;
68763 }else if( u.ap.pC->cacheStatus==p->cacheCtr ){
68764 u.ap.payloadSize = u.ap.pC->payloadSize;
68765 u.ap.zRec = (char*)u.ap.pC->aRow;
68766 }else if( u.ap.pC->isIndex ){
68767 assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68768 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
68769 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68770 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68771 ** payload size, so it is impossible for u.ap.payloadSize64 to be
68772 ** larger than 32 bits. */
68773 assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
68774 u.ap.payloadSize = (u32)u.ap.payloadSize64;
68775 }else{
68776 assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68777 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.payloadSize);
68778 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68779 }
68780 }else{
68781 assert( u.ap.pC->pseudoTableReg>0 );
68782 u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
68783 if( u.ap.pC->multiPseudo ){
68784 sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
68785 Deephemeralize(u.ap.pDest);
68786 goto op_column_out;
68787 }
68788 assert( u.ap.pReg->flags & MEM_Blob );
68789 assert( memIsValid(u.ap.pReg) );
68790 u.ap.payloadSize = u.ap.pReg->n;
68791 u.ap.zRec = u.ap.pReg->z;
68792 u.ap.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
68793 assert( u.ap.payloadSize==0 || u.ap.zRec!=0 );
 
 
 
68794 }
68795
68796 /* If u.ap.payloadSize is 0, then just store a NULL. This can happen because of
68797 ** nullRow or because of a corrupt database. */
68798 if( u.ap.payloadSize==0 ){
68799 MemSetTypeFlag(u.ap.pDest, MEM_Null);
68800 goto op_column_out;
68801 }
68802 assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
68803 if( u.ap.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68804 goto too_big;
68805 }
68806
68807 u.ap.nField = u.ap.pC->nField;
68808 assert( u.ap.p2<u.ap.nField );
68809
68810 /* Read and parse the table header. Store the results of the parse
68811 ** into the record header cache fields of the cursor.
68812 */
68813 u.ap.aType = u.ap.pC->aType;
68814 if( u.ap.pC->cacheStatus==p->cacheCtr ){
68815 u.ap.aOffset = u.ap.pC->aOffset;
68816 }else{
68817 assert(u.ap.aType);
68818 u.ap.avail = 0;
68819 u.ap.pC->aOffset = u.ap.aOffset = &u.ap.aType[u.ap.nField];
68820 u.ap.pC->payloadSize = u.ap.payloadSize;
68821 u.ap.pC->cacheStatus = p->cacheCtr;
68822
68823 /* Figure out how many bytes are in the header */
68824 if( u.ap.zRec ){
68825 u.ap.zData = u.ap.zRec;
68826 }else{
68827 if( u.ap.pC->isIndex ){
68828 u.ap.zData = (char*)sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
68829 }else{
68830 u.ap.zData = (char*)sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
68831 }
68832 /* If KeyFetch()/DataFetch() managed to get the entire payload,
68833 ** save the payload in the u.ap.pC->aRow cache. That will save us from
68834 ** having to make additional calls to fetch the content portion of
68835 ** the record.
68836 */
68837 assert( u.ap.avail>=0 );
68838 if( u.ap.payloadSize <= (u32)u.ap.avail ){
68839 u.ap.zRec = u.ap.zData;
68840 u.ap.pC->aRow = (u8*)u.ap.zData;
68841 }else{
68842 u.ap.pC->aRow = 0;
68843 }
68844 }
68845 /* The following assert is true in all cases except when
68846 ** the database file has been corrupted externally.
68847 ** assert( u.ap.zRec!=0 || u.ap.avail>=u.ap.payloadSize || u.ap.avail>=9 ); */
68848 u.ap.szHdr = getVarint32((u8*)u.ap.zData, u.ap.offset);
68849
68850 /* Make sure a corrupt database has not given us an oversize header.
68851 ** Do this now to avoid an oversize memory allocation.
68852 **
68853 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68485,193 +68854,195 @@
68854 ** types use so much data space that there can only be 4096 and 32 of
68855 ** them, respectively. So the maximum header length results from a
68856 ** 3-byte type for each of the maximum of 32768 columns plus three
68857 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68858 */
68859 if( u.ap.offset > 98307 ){
68860 rc = SQLITE_CORRUPT_BKPT;
68861 goto op_column_out;
68862 }
68863
68864 /* Compute in u.ap.len the number of bytes of data we need to read in order
68865 ** to get u.ap.nField type values. u.ap.offset is an upper bound on this. But
68866 ** u.ap.nField might be significantly less than the true number of columns
68867 ** in the table, and in that case, 5*u.ap.nField+3 might be smaller than u.ap.offset.
68868 ** We want to minimize u.ap.len in order to limit the size of the memory
68869 ** allocation, especially if a corrupt database file has caused u.ap.offset
68870 ** to be oversized. Offset is limited to 98307 above. But 98307 might
68871 ** still exceed Robson memory allocation limits on some configurations.
68872 ** On systems that cannot tolerate large memory allocations, u.ap.nField*5+3
68873 ** will likely be much smaller since u.ap.nField will likely be less than
68874 ** 20 or so. This insures that Robson memory allocation limits are
68875 ** not exceeded even for corrupt database files.
68876 */
68877 u.ap.len = u.ap.nField*5 + 3;
68878 if( u.ap.len > (int)u.ap.offset ) u.ap.len = (int)u.ap.offset;
68879
68880 /* The KeyFetch() or DataFetch() above are fast and will get the entire
68881 ** record header in most cases. But they will fail to get the complete
68882 ** record header if the record header does not fit on a single page
68883 ** in the B-Tree. When that happens, use sqlite3VdbeMemFromBtree() to
68884 ** acquire the complete header text.
68885 */
68886 if( !u.ap.zRec && u.ap.avail<u.ap.len ){
68887 u.ap.sMem.flags = 0;
68888 u.ap.sMem.db = 0;
68889 rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.len, u.ap.pC->isIndex, &u.ap.sMem);
68890 if( rc!=SQLITE_OK ){
68891 goto op_column_out;
68892 }
68893 u.ap.zData = u.ap.sMem.z;
68894 }
68895 u.ap.zEndHdr = (u8 *)&u.ap.zData[u.ap.len];
68896 u.ap.zIdx = (u8 *)&u.ap.zData[u.ap.szHdr];
68897
68898 /* Scan the header and use it to fill in the u.ap.aType[] and u.ap.aOffset[]
68899 ** arrays. u.ap.aType[u.ap.i] will contain the type integer for the u.ap.i-th
68900 ** column and u.ap.aOffset[u.ap.i] will contain the u.ap.offset from the beginning
68901 ** of the record to the start of the data for the u.ap.i-th column
68902 */
68903 for(u.ap.i=0; u.ap.i<u.ap.nField; u.ap.i++){
68904 if( u.ap.zIdx<u.ap.zEndHdr ){
68905 u.ap.aOffset[u.ap.i] = u.ap.offset;
68906 if( u.ap.zIdx[0]<0x80 ){
68907 u.ap.t = u.ap.zIdx[0];
68908 u.ap.zIdx++;
68909 }else{
68910 u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t);
68911 }
68912 u.ap.aType[u.ap.i] = u.ap.t;
68913 u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68914 u.ap.offset += u.ap.szField;
68915 if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */
68916 u.ap.zIdx = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68917 break;
68918 }
68919 }else{
68920 /* If u.ap.i is less that u.ap.nField, then there are fewer fields in this
68921 ** record than SetNumColumns indicated there are columns in the
68922 ** table. Set the u.ap.offset for any extra columns not present in
68923 ** the record to 0. This tells code below to store the default value
68924 ** for the column instead of deserializing a value from the record.
68925 */
68926 u.ap.aOffset[u.ap.i] = 0;
68927 }
68928 }
68929 sqlite3VdbeMemRelease(&u.ap.sMem);
68930 u.ap.sMem.flags = MEM_Null;
68931
68932 /* If we have read more header data than was contained in the header,
68933 ** or if the end of the last field appears to be past the end of the
68934 ** record, or if the end of the last field appears to be before the end
68935 ** of the record (when all fields present), then we must be dealing
68936 ** with a corrupt database.
68937 */
68938 if( (u.ap.zIdx > u.ap.zEndHdr) || (u.ap.offset > u.ap.payloadSize)
68939 || (u.ap.zIdx==u.ap.zEndHdr && u.ap.offset!=u.ap.payloadSize) ){
68940 rc = SQLITE_CORRUPT_BKPT;
68941 goto op_column_out;
68942 }
68943 }
68944
68945 /* Get the column information. If u.ap.aOffset[u.ap.p2] is non-zero, then
68946 ** deserialize the value from the record. If u.ap.aOffset[u.ap.p2] is zero,
68947 ** then there are not enough fields in the record to satisfy the
68948 ** request. In this case, set the value NULL or to P4 if P4 is
68949 ** a pointer to a Mem object.
68950 */
68951 if( u.ap.aOffset[u.ap.p2] ){
68952 assert( rc==SQLITE_OK );
68953 if( u.ap.zRec ){
68954 /* This is the common case where the whole row fits on a single page */
68955 VdbeMemRelease(u.ap.pDest);
68956 sqlite3VdbeSerialGet((u8 *)&u.ap.zRec[u.ap.aOffset[u.ap.p2]], u.ap.aType[u.ap.p2], u.ap.pDest);
68957 }else{
68958 /* This branch happens only when the row overflows onto multiple pages */
68959 u.ap.t = u.ap.aType[u.ap.p2];
68960 if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68961 && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)
68962 ){
68963 /* Content is irrelevant for the typeof() function and for
68964 ** the length(X) function if X is a blob. So we might as well use
68965 ** bogus content rather than reading content from disk. NULL works
68966 ** for text and blob and whatever is in the u.ap.payloadSize64 variable
68967 ** will work for everything else. */
68968 u.ap.zData = u.ap.t<12 ? (char*)&u.ap.payloadSize64 : 0;
68969 }else{
68970 u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t);
68971 sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
68972 rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, u.ap.pC->isIndex,
68973 &u.ap.sMem);
68974 if( rc!=SQLITE_OK ){
68975 goto op_column_out;
68976 }
68977 u.ap.zData = u.ap.sMem.z;
68978 }
68979 sqlite3VdbeSerialGet((u8*)u.ap.zData, u.ap.t, u.ap.pDest);
68980 }
68981 u.ap.pDest->enc = encoding;
68982 }else{
68983 if( pOp->p4type==P4_MEM ){
68984 sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
68985 }else{
68986 MemSetTypeFlag(u.ap.pDest, MEM_Null);
68987 }
68988 }
68989
68990 /* If we dynamically allocated space to hold the data (in the
68991 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68992 ** dynamically allocated space over to the u.ap.pDest structure.
68993 ** This prevents a memory copy.
68994 */
68995 if( u.ap.sMem.zMalloc ){
68996 assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
68997 assert( !(u.ap.pDest->flags & MEM_Dyn) );
68998 assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
68999 u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
69000 u.ap.pDest->flags |= MEM_Term;
69001 u.ap.pDest->z = u.ap.sMem.z;
69002 u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
69003 }
69004
69005 rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
69006
69007 op_column_out:
69008 UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69009 REGISTER_TRACE(pOp->p3, u.ap.pDest);
69010 break;
69011 }
69012
69013 /* Opcode: Affinity P1 P2 * P4 *
69014 ** Synopsis: affinity(r[P1@P2])
69015 **
69016 ** Apply affinities to a range of P2 registers starting with P1.
69017 **
69018 ** P4 is a string that is P2 characters long. The nth character of the
69019 ** string indicates the column affinity that should be used for the nth
69020 ** memory cell in the range.
69021 */
69022 case OP_Affinity: {
69023 #if 0 /* local variables moved into u.aq */
69024 const char *zAffinity; /* The affinity to be applied */
69025 char cAff; /* A single character of affinity */
69026 #endif /* local variables moved into u.aq */
69027
69028 u.aq.zAffinity = pOp->p4.z;
69029 assert( u.aq.zAffinity!=0 );
69030 assert( u.aq.zAffinity[pOp->p2]==0 );
69031 pIn1 = &aMem[pOp->p1];
69032 while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
69033 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
69034 assert( memIsValid(pIn1) );
69035 ExpandBlob(pIn1);
69036 applyAffinity(pIn1, u.aq.cAff, encoding);
69037 pIn1++;
69038 }
69039 break;
69040 }
69041
69042 /* Opcode: MakeRecord P1 P2 P3 P4 *
69043 ** Synopsis: r[P3]=mkrec(r[P1@P2])
69044 **
69045 ** Convert P2 registers beginning with P1 into the [record format]
69046 ** use as a data record in a database table or as a key
69047 ** in an index. The OP_Column opcode can decode the record later.
69048 **
@@ -68683,11 +69054,11 @@
69054 ** macros defined in sqliteInt.h.
69055 **
69056 ** If P4 is NULL then all index fields have the affinity NONE.
69057 */
69058 case OP_MakeRecord: {
69059 #if 0 /* local variables moved into u.ar */
69060 u8 *zNewRecord; /* A buffer to hold the data for the new record */
69061 Mem *pRec; /* The new record */
69062 u64 nData; /* Number of bytes of data space */
69063 int nHdr; /* Number of bytes of header space */
69064 i64 nByte; /* Data space required for this record */
@@ -68699,11 +69070,11 @@
69070 int nField; /* Number of fields in the record */
69071 char *zAffinity; /* The affinity string for the record */
69072 int file_format; /* File format to use for encoding */
69073 int i; /* Space used in zNewRecord[] */
69074 int len; /* Length of a field */
69075 #endif /* local variables moved into u.ar */
69076
69077 /* Assuming the record contains N fields, the record format looks
69078 ** like this:
69079 **
69080 ** ------------------------------------------------------------------------
@@ -68716,114 +69087,112 @@
69087 ** Each type field is a varint representing the serial type of the
69088 ** corresponding data element (see sqlite3VdbeSerialType()). The
69089 ** hdr-size field is also a varint which is the offset from the beginning
69090 ** of the record to data0.
69091 */
69092 u.ar.nData = 0; /* Number of bytes of data space */
69093 u.ar.nHdr = 0; /* Number of bytes of header space */
69094 u.ar.nZero = 0; /* Number of zero bytes at the end of the record */
69095 u.ar.nField = pOp->p1;
69096 u.ar.zAffinity = pOp->p4.z;
69097 assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 );
69098 u.ar.pData0 = &aMem[u.ar.nField];
69099 u.ar.nField = pOp->p2;
69100 u.ar.pLast = &u.ar.pData0[u.ar.nField-1];
69101 u.ar.file_format = p->minWriteFileFormat;
69102
69103 /* Identify the output register */
69104 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
69105 pOut = &aMem[pOp->p3];
69106 memAboutToChange(p, pOut);
69107
69108 /* Loop through the elements that will make up the record to figure
69109 ** out how much space is required for the new record.
69110 */
69111 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69112 assert( memIsValid(u.ar.pRec) );
69113 if( u.ar.zAffinity ){
69114 applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding);
69115 }
69116 if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){
69117 sqlite3VdbeMemExpandBlob(u.ar.pRec);
69118 }
69119 u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69120 u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type);
69121 u.ar.nData += u.ar.len;
69122 u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type);
69123 if( u.ar.pRec->flags & MEM_Zero ){
69124 /* Only pure zero-filled BLOBs can be input to this Opcode.
69125 ** We do not allow blobs with a prefix and a zero-filled tail. */
69126 u.ar.nZero += u.ar.pRec->u.nZero;
69127 }else if( u.ar.len ){
69128 u.ar.nZero = 0;
69129 }
69130 }
69131
69132 /* Add the initial header varint and total the size */
69133 u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr);
69134 if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){
69135 u.ar.nHdr++;
69136 }
69137 u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero;
69138 if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69139 goto too_big;
69140 }
69141
69142 /* Make sure the output register has a buffer large enough to store
69143 ** the new record. The output register (pOp->p3) is not allowed to
69144 ** be one of the input registers (because the following call to
69145 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
69146 */
69147 if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
69148 goto no_mem;
69149 }
69150 u.ar.zNewRecord = (u8 *)pOut->z;
69151
69152 /* Write the record */
69153 u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr);
69154 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69155 u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69156 u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */
69157 }
69158 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */
69159 u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format);
69160 }
69161 assert( u.ar.i==u.ar.nByte );
69162
69163 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69164 pOut->n = (int)u.ar.nByte;
69165 pOut->flags = MEM_Blob | MEM_Dyn;
69166 pOut->xDel = 0;
69167 if( u.ar.nZero ){
69168 pOut->u.nZero = u.ar.nZero;
69169 pOut->flags |= MEM_Zero;
69170 }
69171 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
69172 REGISTER_TRACE(pOp->p3, pOut);
69173 UPDATE_MAX_BLOBSIZE(pOut);
69174 break;
69175 }
69176
69177 /* Opcode: Count P1 P2 * * *
69178 ** Synopsis: r[P2]=count()
69179 **
69180 ** Store the number of entries (an integer value) in the table or index
69181 ** opened by cursor P1 in register P2
69182 */
69183 #ifndef SQLITE_OMIT_BTREECOUNT
69184 case OP_Count: { /* out2-prerelease */
69185 #if 0 /* local variables moved into u.as */
69186 i64 nEntry;
69187 BtCursor *pCrsr;
69188 #endif /* local variables moved into u.as */
69189
69190 u.as.pCrsr = p->apCsr[pOp->p1]->pCursor;
69191 assert( u.as.pCrsr );
69192 rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry);
69193 pOut->u.i = u.as.nEntry;
 
 
 
69194 break;
69195 }
69196 #endif
69197
69198 /* Opcode: Savepoint P1 * * P4 *
@@ -68831,43 +69200,43 @@
69200 ** Open, release or rollback the savepoint named by parameter P4, depending
69201 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
69202 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
69203 */
69204 case OP_Savepoint: {
69205 #if 0 /* local variables moved into u.at */
69206 int p1; /* Value of P1 operand */
69207 char *zName; /* Name of savepoint */
69208 int nName;
69209 Savepoint *pNew;
69210 Savepoint *pSavepoint;
69211 Savepoint *pTmp;
69212 int iSavepoint;
69213 int ii;
69214 #endif /* local variables moved into u.at */
69215
69216 u.at.p1 = pOp->p1;
69217 u.at.zName = pOp->p4.z;
69218
69219 /* Assert that the u.at.p1 parameter is valid. Also that if there is no open
69220 ** transaction, then there cannot be any savepoints.
69221 */
69222 assert( db->pSavepoint==0 || db->autoCommit==0 );
69223 assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK );
69224 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
69225 assert( checkSavepointCount(db) );
69226 assert( p->bIsReader );
69227
69228 if( u.at.p1==SAVEPOINT_BEGIN ){
69229 if( db->nVdbeWrite>0 ){
69230 /* A new savepoint cannot be created if there are active write
69231 ** statements (i.e. open read/write incremental blob handles).
69232 */
69233 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
69234 "SQL statements in progress");
69235 rc = SQLITE_BUSY;
69236 }else{
69237 u.at.nName = sqlite3Strlen30(u.at.zName);
69238
69239 #ifndef SQLITE_OMIT_VIRTUALTABLE
69240 /* This call is Ok even if this savepoint is actually a transaction
69241 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
69242 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -68877,14 +69246,14 @@
69246 db->nStatement+db->nSavepoint);
69247 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69248 #endif
69249
69250 /* Create a new savepoint structure. */
69251 u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1);
69252 if( u.at.pNew ){
69253 u.at.pNew->zName = (char *)&u.at.pNew[1];
69254 memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1);
69255
69256 /* If there is no open transaction, then mark this as a special
69257 ** "transaction savepoint". */
69258 if( db->autoCommit ){
69259 db->autoCommit = 0;
@@ -68892,32 +69261,32 @@
69261 }else{
69262 db->nSavepoint++;
69263 }
69264
69265 /* Link the new savepoint into the database handle's list. */
69266 u.at.pNew->pNext = db->pSavepoint;
69267 db->pSavepoint = u.at.pNew;
69268 u.at.pNew->nDeferredCons = db->nDeferredCons;
69269 u.at.pNew->nDeferredImmCons = db->nDeferredImmCons;
69270 }
69271 }
69272 }else{
69273 u.at.iSavepoint = 0;
69274
69275 /* Find the named savepoint. If there is no such savepoint, then an
69276 ** an error is returned to the user. */
69277 for(
69278 u.at.pSavepoint = db->pSavepoint;
69279 u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName);
69280 u.at.pSavepoint = u.at.pSavepoint->pNext
69281 ){
69282 u.at.iSavepoint++;
69283 }
69284 if( !u.at.pSavepoint ){
69285 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName);
69286 rc = SQLITE_ERROR;
69287 }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){
69288 /* It is not possible to release (commit) a savepoint if there are
69289 ** active write statements.
69290 */
69291 sqlite3SetString(&p->zErrMsg, db,
69292 "cannot release savepoint - SQL statements in progress"
@@ -68927,12 +69296,12 @@
69296
69297 /* Determine whether or not this is a transaction savepoint. If so,
69298 ** and this is a RELEASE command, then the current transaction
69299 ** is committed.
69300 */
69301 int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint;
69302 if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){
69303 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69304 goto vdbe_return;
69305 }
69306 db->autoCommit = 1;
69307 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -68942,56 +69311,56 @@
69311 goto vdbe_return;
69312 }
69313 db->isTransactionSavepoint = 0;
69314 rc = p->rc;
69315 }else{
69316 u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1;
69317 if( u.at.p1==SAVEPOINT_ROLLBACK ){
69318 for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69319 sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT);
69320 }
69321 }
69322 for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69323 rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint);
69324 if( rc!=SQLITE_OK ){
69325 goto abort_due_to_error;
69326 }
69327 }
69328 if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
69329 sqlite3ExpirePreparedStatements(db);
69330 sqlite3ResetAllSchemasOfConnection(db);
69331 db->flags = (db->flags | SQLITE_InternChanges);
69332 }
69333 }
69334
69335 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
69336 ** savepoints nested inside of the savepoint being operated on. */
69337 while( db->pSavepoint!=u.at.pSavepoint ){
69338 u.at.pTmp = db->pSavepoint;
69339 db->pSavepoint = u.at.pTmp->pNext;
69340 sqlite3DbFree(db, u.at.pTmp);
69341 db->nSavepoint--;
69342 }
69343
69344 /* If it is a RELEASE, then destroy the savepoint being operated on
69345 ** too. If it is a ROLLBACK TO, then set the number of deferred
69346 ** constraint violations present in the database to the value stored
69347 ** when the savepoint was created. */
69348 if( u.at.p1==SAVEPOINT_RELEASE ){
69349 assert( u.at.pSavepoint==db->pSavepoint );
69350 db->pSavepoint = u.at.pSavepoint->pNext;
69351 sqlite3DbFree(db, u.at.pSavepoint);
69352 if( !isTransaction ){
69353 db->nSavepoint--;
69354 }
69355 }else{
69356 db->nDeferredCons = u.at.pSavepoint->nDeferredCons;
69357 db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons;
69358 }
69359
69360 if( !isTransaction ){
69361 rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
69362 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69363 }
69364 }
69365 }
69366
@@ -69006,54 +69375,54 @@
69375 ** there are active writing VMs or active VMs that use shared cache.
69376 **
69377 ** This instruction causes the VM to halt.
69378 */
69379 case OP_AutoCommit: {
69380 #if 0 /* local variables moved into u.au */
69381 int desiredAutoCommit;
69382 int iRollback;
69383 int turnOnAC;
69384 #endif /* local variables moved into u.au */
69385
69386 u.au.desiredAutoCommit = pOp->p1;
69387 u.au.iRollback = pOp->p2;
69388 u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit;
69389 assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 );
69390 assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 );
69391 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
69392 assert( p->bIsReader );
69393
69394 #if 0
69395 if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
69396 /* If this instruction implements a ROLLBACK and other VMs are
69397 ** still running, and a transaction is active, return an error indicating
69398 ** that the other VMs must complete first.
69399 */
69400 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69401 "SQL statements in progress");
69402 rc = SQLITE_BUSY;
69403 }else
69404 #endif
69405 if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
69406 /* If this instruction implements a COMMIT and other VMs are writing
69407 ** return an error indicating that the other VMs must complete first.
69408 */
69409 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69410 "SQL statements in progress");
69411 rc = SQLITE_BUSY;
69412 }else if( u.au.desiredAutoCommit!=db->autoCommit ){
69413 if( u.au.iRollback ){
69414 assert( u.au.desiredAutoCommit==1 );
69415 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69416 db->autoCommit = 1;
69417 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69418 goto vdbe_return;
69419 }else{
69420 db->autoCommit = (u8)u.au.desiredAutoCommit;
69421 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69422 p->pc = pc;
69423 db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
69424 p->rc = rc = SQLITE_BUSY;
69425 goto vdbe_return;
69426 }
69427 }
69428 assert( db->nStatement==0 );
@@ -69064,12 +69433,12 @@
69433 rc = SQLITE_ERROR;
69434 }
69435 goto vdbe_return;
69436 }else{
69437 sqlite3SetString(&p->zErrMsg, db,
69438 (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69439 (u.au.iRollback)?"cannot rollback - no transaction is active":
69440 "cannot commit - no transaction is active"));
69441
69442 rc = SQLITE_ERROR;
69443 }
69444 break;
@@ -69105,26 +69474,26 @@
69474 ** will automatically commit when the VDBE halts.
69475 **
69476 ** If P2 is zero, then a read-lock is obtained on the database file.
69477 */
69478 case OP_Transaction: {
69479 #if 0 /* local variables moved into u.av */
69480 Btree *pBt;
69481 #endif /* local variables moved into u.av */
69482
69483 assert( p->bIsReader );
69484 assert( p->readOnly==0 || pOp->p2==0 );
69485 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69486 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69487 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69488 rc = SQLITE_READONLY;
69489 goto abort_due_to_error;
69490 }
69491 u.av.pBt = db->aDb[pOp->p1].pBt;
69492
69493 if( u.av.pBt ){
69494 rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
69495 if( rc==SQLITE_BUSY ){
69496 p->pc = pc;
69497 p->rc = rc = SQLITE_BUSY;
69498 goto vdbe_return;
69499 }
@@ -69133,20 +69502,20 @@
69502 }
69503
69504 if( pOp->p2 && p->usesStmtJournal
69505 && (db->autoCommit==0 || db->nVdbeRead>1)
69506 ){
69507 assert( sqlite3BtreeIsInTrans(u.av.pBt) );
69508 if( p->iStatement==0 ){
69509 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69510 db->nStatement++;
69511 p->iStatement = db->nSavepoint + db->nStatement;
69512 }
69513
69514 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69515 if( rc==SQLITE_OK ){
69516 rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
69517 }
69518
69519 /* Store the current value of the database handles deferred constraint
69520 ** counter. If the statement transaction needs to be rolled back,
69521 ** the value of this counter needs to be restored too. */
@@ -69168,26 +69537,26 @@
69537 ** There must be a read-lock on the database (either a transaction
69538 ** must be started or there must be an open cursor) before
69539 ** executing this instruction.
69540 */
69541 case OP_ReadCookie: { /* out2-prerelease */
69542 #if 0 /* local variables moved into u.aw */
69543 int iMeta;
69544 int iDb;
69545 int iCookie;
69546 #endif /* local variables moved into u.aw */
69547
69548 assert( p->bIsReader );
69549 u.aw.iDb = pOp->p1;
69550 u.aw.iCookie = pOp->p3;
69551 assert( pOp->p3<SQLITE_N_BTREE_META );
69552 assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
69553 assert( db->aDb[u.aw.iDb].pBt!=0 );
69554 assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 );
69555
69556 sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta);
69557 pOut->u.i = u.aw.iMeta;
69558 break;
69559 }
69560
69561 /* Opcode: SetCookie P1 P2 P3 * *
69562 **
@@ -69198,31 +69567,31 @@
69567 ** database file used to store temporary tables.
69568 **
69569 ** A transaction must be started before executing this opcode.
69570 */
69571 case OP_SetCookie: { /* in3 */
69572 #if 0 /* local variables moved into u.ax */
69573 Db *pDb;
69574 #endif /* local variables moved into u.ax */
69575 assert( pOp->p2<SQLITE_N_BTREE_META );
69576 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69577 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69578 assert( p->readOnly==0 );
69579 u.ax.pDb = &db->aDb[pOp->p1];
69580 assert( u.ax.pDb->pBt!=0 );
69581 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69582 pIn3 = &aMem[pOp->p3];
69583 sqlite3VdbeMemIntegerify(pIn3);
69584 /* See note about index shifting on OP_ReadCookie */
69585 rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i);
69586 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69587 /* When the schema cookie changes, record the new cookie internally */
69588 u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69589 db->flags |= SQLITE_InternChanges;
69590 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69591 /* Record changes in the file format */
69592 u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i;
69593 }
69594 if( pOp->p1==1 ){
69595 /* Invalidate all prepared statements whenever the TEMP database
69596 ** schema is changed. Ticket #1644 */
69597 sqlite3ExpirePreparedStatements(db);
@@ -69248,28 +69617,28 @@
69617 ** Either a transaction needs to have been started or an OP_Open needs
69618 ** to be executed (to establish a read lock) before this opcode is
69619 ** invoked.
69620 */
69621 case OP_VerifyCookie: {
69622 #if 0 /* local variables moved into u.ay */
69623 int iMeta;
69624 int iGen;
69625 Btree *pBt;
69626 #endif /* local variables moved into u.ay */
69627
69628 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69629 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69630 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69631 assert( p->bIsReader );
69632 u.ay.pBt = db->aDb[pOp->p1].pBt;
69633 if( u.ay.pBt ){
69634 sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta);
69635 u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69636 }else{
69637 u.ay.iGen = u.ay.iMeta = 0;
69638 }
69639 if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
69640 sqlite3DbFree(db, p->zErrMsg);
69641 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69642 /* If the schema-cookie from the database file matches the cookie
69643 ** stored with the in-memory representation of the schema, do
69644 ** not reload the schema from the database file.
@@ -69281,11 +69650,11 @@
69650 ** discard the database schema, as the user code implementing the
69651 ** v-table would have to be ready for the sqlite3_vtab structure itself
69652 ** to be invalidated whenever sqlite3_step() is called from within
69653 ** a v-table method.
69654 */
69655 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
69656 sqlite3ResetOneSchema(db, pOp->p1);
69657 }
69658
69659 p->expired = 1;
69660 rc = SQLITE_SCHEMA;
@@ -69292,10 +69661,11 @@
69661 }
69662 break;
69663 }
69664
69665 /* Opcode: OpenRead P1 P2 P3 P4 P5
69666 ** Synopsis: root=P2 iDb=P3
69667 **
69668 ** Open a read-only cursor for the database table whose root page is
69669 ** P2 in a database file. The database file is determined by P3.
69670 ** P3==0 means the main database, P3==1 means the database used for
69671 ** temporary tables, and P3>1 means used the corresponding attached
@@ -69322,10 +69692,11 @@
69692 ** value, it is set to the number of columns in the table.
69693 **
69694 ** See also OpenWrite.
69695 */
69696 /* Opcode: OpenWrite P1 P2 P3 P4 P5
69697 ** Synopsis: root=P2 iDb=P3
69698 **
69699 ** Open a read/write cursor named P1 on the table or index whose root
69700 ** page is P2. Or if P5!=0 use the content of register P2 to find the
69701 ** root page.
69702 **
@@ -69342,20 +69713,20 @@
69713 **
69714 ** See also OpenRead.
69715 */
69716 case OP_OpenRead:
69717 case OP_OpenWrite: {
69718 #if 0 /* local variables moved into u.az */
69719 int nField;
69720 KeyInfo *pKeyInfo;
69721 int p2;
69722 int iDb;
69723 int wrFlag;
69724 Btree *pX;
69725 VdbeCursor *pCur;
69726 Db *pDb;
69727 #endif /* local variables moved into u.az */
69728
69729 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69730 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69731 assert( p->bIsReader );
69732 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69363,76 +69734,78 @@
69734 if( p->expired ){
69735 rc = SQLITE_ABORT;
69736 break;
69737 }
69738
69739 u.az.nField = 0;
69740 u.az.pKeyInfo = 0;
69741 u.az.p2 = pOp->p2;
69742 u.az.iDb = pOp->p3;
69743 assert( u.az.iDb>=0 && u.az.iDb<db->nDb );
69744 assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 );
69745 u.az.pDb = &db->aDb[u.az.iDb];
69746 u.az.pX = u.az.pDb->pBt;
69747 assert( u.az.pX!=0 );
69748 if( pOp->opcode==OP_OpenWrite ){
69749 u.az.wrFlag = 1;
69750 assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) );
69751 if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){
69752 p->minWriteFileFormat = u.az.pDb->pSchema->file_format;
69753 }
69754 }else{
69755 u.az.wrFlag = 0;
69756 }
69757 if( pOp->p5 & OPFLAG_P2ISREG ){
69758 assert( u.az.p2>0 );
69759 assert( u.az.p2<=(p->nMem-p->nCursor) );
69760 pIn2 = &aMem[u.az.p2];
69761 assert( memIsValid(pIn2) );
69762 assert( (pIn2->flags & MEM_Int)!=0 );
69763 sqlite3VdbeMemIntegerify(pIn2);
69764 u.az.p2 = (int)pIn2->u.i;
69765 /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and
69766 ** that opcode will always set the u.az.p2 value to 2 or more or else fail.
69767 ** If there were a failure, the prepared statement would have halted
69768 ** before reaching this instruction. */
69769 if( NEVER(u.az.p2<2) ) {
69770 rc = SQLITE_CORRUPT_BKPT;
69771 goto abort_due_to_error;
69772 }
69773 }
69774 if( pOp->p4type==P4_KEYINFO ){
69775 u.az.pKeyInfo = pOp->p4.pKeyInfo;
69776 assert( u.az.pKeyInfo->enc==ENC(db) );
69777 assert( u.az.pKeyInfo->db==db );
69778 u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
69779 }else if( pOp->p4type==P4_INT32 ){
69780 u.az.nField = pOp->p4.i;
69781 }
69782 assert( pOp->p1>=0 );
69783 u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69784 if( u.az.pCur==0 ) goto no_mem;
69785 u.az.pCur->nullRow = 1;
69786 u.az.pCur->isOrdered = 1;
69787 rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
69788 u.az.pCur->pKeyInfo = u.az.pKeyInfo;
69789 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69790 sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69791
69792 /* Since it performs no memory allocation or IO, the only value that
69793 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69794 assert( rc==SQLITE_OK );
69795
69796 /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
69797 ** SQLite used to check if the root-page flags were sane at this point
69798 ** and report database corruption if they were not, but this check has
69799 ** since moved into the btree layer. */
69800 u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69801 u.az.pCur->isIndex = !u.az.pCur->isTable;
69802 break;
69803 }
69804
69805 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69806 ** Synopsis: nColumn=P2
69807 **
69808 ** Open a new cursor P1 to a transient table.
69809 ** The cursor is always opened read/write even if
69810 ** the main database is read-only. The ephemeral
69811 ** table is deleted automatically when the cursor is closed.
@@ -69440,98 +69813,96 @@
69813 ** P2 is the number of columns in the ephemeral table.
69814 ** The cursor points to a BTree table if P4==0 and to a BTree index
69815 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
69816 ** that defines the format of keys in the index.
69817 **
 
 
 
 
 
 
69818 ** The P5 parameter can be a mask of the BTREE_* flags defined
69819 ** in btree.h. These flags control aspects of the operation of
69820 ** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
69821 ** added automatically.
69822 */
69823 /* Opcode: OpenAutoindex P1 P2 * P4 *
69824 ** Synopsis: nColumn=P2
69825 **
69826 ** This opcode works the same as OP_OpenEphemeral. It has a
69827 ** different name to distinguish its use. Tables created using
69828 ** by this opcode will be used for automatically created transient
69829 ** indices in joins.
69830 */
69831 case OP_OpenAutoindex:
69832 case OP_OpenEphemeral: {
69833 #if 0 /* local variables moved into u.ba */
69834 VdbeCursor *pCx;
69835 KeyInfo *pKeyInfo;
69836 #endif /* local variables moved into u.ba */
69837
69838 static const int vfsFlags =
69839 SQLITE_OPEN_READWRITE |
69840 SQLITE_OPEN_CREATE |
69841 SQLITE_OPEN_EXCLUSIVE |
69842 SQLITE_OPEN_DELETEONCLOSE |
69843 SQLITE_OPEN_TRANSIENT_DB;
 
69844 assert( pOp->p1>=0 );
69845 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69846 if( u.ba.pCx==0 ) goto no_mem;
69847 u.ba.pCx->nullRow = 1;
69848 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
69849 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69850 if( rc==SQLITE_OK ){
69851 rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
69852 }
69853 if( rc==SQLITE_OK ){
69854 /* If a transient index is required, create it by calling
69855 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69856 ** opening it. If a transient table is required, just use the
69857 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69858 */
69859 if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69860 int pgno;
69861 assert( pOp->p4type==P4_KEYINFO );
69862 rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69863 if( rc==SQLITE_OK ){
69864 assert( pgno==MASTER_ROOT+1 );
69865 assert( u.ba.pKeyInfo->db==db );
69866 assert( u.ba.pKeyInfo->enc==ENC(db) );
69867 u.ba.pCx->pKeyInfo = u.ba.pKeyInfo;
69868 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor);
69869 }
69870 u.ba.pCx->isTable = 0;
69871 }else{
69872 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69873 u.ba.pCx->isTable = 1;
69874 }
69875 }
69876 u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69877 u.ba.pCx->isIndex = !u.ba.pCx->isTable;
69878 break;
69879 }
69880
69881 /* Opcode: SorterOpen P1 * * P4 *
69882 **
69883 ** This opcode works like OP_OpenEphemeral except that it opens
69884 ** a transient index that is specifically designed to sort large
69885 ** tables using an external merge-sort algorithm.
69886 */
69887 case OP_SorterOpen: {
69888 #if 0 /* local variables moved into u.bb */
69889 VdbeCursor *pCx;
69890 #endif /* local variables moved into u.bb */
69891
69892 u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69893 if( u.bb.pCx==0 ) goto no_mem;
69894 u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69895 assert( u.bb.pCx->pKeyInfo->db==db );
69896 assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69897 u.bb.pCx->isSorter = 1;
69898 rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
69899 break;
69900 }
69901
69902 /* Opcode: OpenPseudo P1 P2 P3 * P5
69903 ** Synopsis: content in r[P2@P3]
69904 **
69905 ** Open a new cursor that points to a fake table that contains a single
69906 ** row of data. The content of that one row in the content of memory
69907 ** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
69908 ** MEM_Blob content contained in register P2. When P5==1, then the
@@ -69544,22 +69915,22 @@
69915 **
69916 ** P3 is the number of fields in the records that will be stored by
69917 ** the pseudo-table.
69918 */
69919 case OP_OpenPseudo: {
69920 #if 0 /* local variables moved into u.bc */
69921 VdbeCursor *pCx;
69922 #endif /* local variables moved into u.bc */
69923
69924 assert( pOp->p1>=0 );
69925 u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69926 if( u.bc.pCx==0 ) goto no_mem;
69927 u.bc.pCx->nullRow = 1;
69928 u.bc.pCx->pseudoTableReg = pOp->p2;
69929 u.bc.pCx->isTable = 1;
69930 u.bc.pCx->isIndex = 0;
69931 u.bc.pCx->multiPseudo = pOp->p5;
69932 break;
69933 }
69934
69935 /* Opcode: Close P1 * * * *
69936 **
@@ -69572,10 +69943,11 @@
69943 p->apCsr[pOp->p1] = 0;
69944 break;
69945 }
69946
69947 /* Opcode: SeekGe P1 P2 P3 P4 *
69948 ** Synopsis: key=r[P3@P4]
69949 **
69950 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69951 ** use the value in register P3 as the key. If cursor P1 refers
69952 ** to an SQL index, then P3 is the first in an array of P4 registers
69953 ** that are used as an unpacked index key.
@@ -69585,10 +69957,11 @@
69957 ** greater than or equal to the key and P2 is not zero, then jump to P2.
69958 **
69959 ** See also: Found, NotFound, Distinct, SeekLt, SeekGt, SeekLe
69960 */
69961 /* Opcode: SeekGt P1 P2 P3 P4 *
69962 ** Synopsis: key=r[P3@P4]
69963 **
69964 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69965 ** use the value in register P3 as a key. If cursor P1 refers
69966 ** to an SQL index, then P3 is the first in an array of P4 registers
69967 ** that are used as an unpacked index key.
@@ -69598,10 +69971,11 @@
69971 ** the key and P2 is not zero, then jump to P2.
69972 **
69973 ** See also: Found, NotFound, Distinct, SeekLt, SeekGe, SeekLe
69974 */
69975 /* Opcode: SeekLt P1 P2 P3 P4 *
69976 ** Synopsis: key=r[P3@P4]
69977 **
69978 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69979 ** use the value in register P3 as a key. If cursor P1 refers
69980 ** to an SQL index, then P3 is the first in an array of P4 registers
69981 ** that are used as an unpacked index key.
@@ -69611,10 +69985,11 @@
69985 ** the key and P2 is not zero, then jump to P2.
69986 **
69987 ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLe
69988 */
69989 /* Opcode: SeekLe P1 P2 P3 P4 *
69990 ** Synopsis: key=r[P3@P4]
69991 **
69992 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
69993 ** use the value in register P3 as a key. If cursor P1 refers
69994 ** to an SQL index, then P3 is the first in an array of P4 registers
69995 ** that are used as an unpacked index key.
@@ -69627,200 +70002,197 @@
70002 */
70003 case OP_SeekLt: /* jump, in3 */
70004 case OP_SeekLe: /* jump, in3 */
70005 case OP_SeekGe: /* jump, in3 */
70006 case OP_SeekGt: { /* jump, in3 */
70007 #if 0 /* local variables moved into u.bd */
70008 int res;
70009 int oc;
70010 VdbeCursor *pC;
70011 UnpackedRecord r;
70012 int nField;
70013 i64 iKey; /* The rowid we are to seek to */
70014 #endif /* local variables moved into u.bd */
70015
70016 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70017 assert( pOp->p2!=0 );
70018 u.bd.pC = p->apCsr[pOp->p1];
70019 assert( u.bd.pC!=0 );
70020 assert( u.bd.pC->pseudoTableReg==0 );
70021 assert( OP_SeekLe == OP_SeekLt+1 );
70022 assert( OP_SeekGe == OP_SeekLt+2 );
70023 assert( OP_SeekGt == OP_SeekLt+3 );
70024 assert( u.bd.pC->isOrdered );
70025 assert( u.bd.pC->pCursor!=0 );
70026 u.bd.oc = pOp->opcode;
70027 u.bd.pC->nullRow = 0;
70028 if( u.bd.pC->isTable ){
70029 /* The input value in P3 might be of any type: integer, real, string,
70030 ** blob, or NULL. But it needs to be an integer before we can do
70031 ** the seek, so covert it. */
70032 pIn3 = &aMem[pOp->p3];
70033 applyNumericAffinity(pIn3);
70034 u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70035 u.bd.pC->rowidIsValid = 0;
70036
70037 /* If the P3 value could not be converted into an integer without
70038 ** loss of information, then special processing is required... */
70039 if( (pIn3->flags & MEM_Int)==0 ){
70040 if( (pIn3->flags & MEM_Real)==0 ){
70041 /* If the P3 value cannot be converted into any kind of a number,
70042 ** then the seek is not possible, so jump to P2 */
70043 pc = pOp->p2 - 1;
70044 break;
70045 }
70046 /* If we reach this point, then the P3 value must be a floating
70047 ** point number. */
70048 assert( (pIn3->flags & MEM_Real)!=0 );
70049
70050 if( u.bd.iKey==SMALLEST_INT64 && (pIn3->r<(double)u.bd.iKey || pIn3->r>0) ){
70051 /* The P3 value is too large in magnitude to be expressed as an
70052 ** integer. */
70053 u.bd.res = 1;
70054 if( pIn3->r<0 ){
70055 if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70056 rc = sqlite3BtreeFirst(u.bd.pC->pCursor, &u.bd.res);
70057 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70058 }
70059 }else{
70060 if( u.bd.oc<=OP_SeekLe ){ assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70061 rc = sqlite3BtreeLast(u.bd.pC->pCursor, &u.bd.res);
70062 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70063 }
70064 }
70065 if( u.bd.res ){
70066 pc = pOp->p2 - 1;
70067 }
70068 break;
70069 }else if( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekGe ){
70070 /* Use the ceiling() function to convert real->int */
70071 if( pIn3->r > (double)u.bd.iKey ) u.bd.iKey++;
70072 }else{
70073 /* Use the floor() function to convert real->int */
70074 assert( u.bd.oc==OP_SeekLe || u.bd.oc==OP_SeekGt );
70075 if( pIn3->r < (double)u.bd.iKey ) u.bd.iKey--;
70076 }
70077 }
70078 rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res);
70079 if( rc!=SQLITE_OK ){
70080 goto abort_due_to_error;
70081 }
70082 if( u.bd.res==0 ){
70083 u.bd.pC->rowidIsValid = 1;
70084 u.bd.pC->lastRowid = u.bd.iKey;
70085 }
70086 }else{
70087 u.bd.nField = pOp->p4.i;
70088 assert( pOp->p4type==P4_INT32 );
70089 assert( u.bd.nField>0 );
70090 u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo;
70091 u.bd.r.nField = (u16)u.bd.nField;
70092
70093 /* The next line of code computes as follows, only faster:
70094 ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){
70095 ** u.bd.r.flags = UNPACKED_INCRKEY;
70096 ** }else{
70097 ** u.bd.r.flags = 0;
70098 ** }
70099 */
70100 u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt)));
70101 assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY );
70102 assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY );
70103 assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 );
70104 assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 );
70105
70106 u.bd.r.aMem = &aMem[pOp->p3];
70107 #ifdef SQLITE_DEBUG
70108 { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); }
70109 #endif
70110 ExpandBlob(u.bd.r.aMem);
70111 rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res);
70112 if( rc!=SQLITE_OK ){
70113 goto abort_due_to_error;
70114 }
70115 u.bd.pC->rowidIsValid = 0;
70116 }
70117 u.bd.pC->deferredMoveto = 0;
70118 u.bd.pC->cacheStatus = CACHE_STALE;
70119 #ifdef SQLITE_TEST
70120 sqlite3_search_count++;
70121 #endif
70122 if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70123 if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){
70124 rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res);
70125 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70126 u.bd.pC->rowidIsValid = 0;
70127 }else{
70128 u.bd.res = 0;
70129 }
70130 }else{
70131 assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70132 if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){
70133 rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res);
70134 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70135 u.bd.pC->rowidIsValid = 0;
70136 }else{
70137 /* u.bd.res might be negative because the table is empty. Check to
70138 ** see if this is the case.
70139 */
70140 u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor);
70141 }
70142 }
70143 assert( pOp->p2>0 );
70144 if( u.bd.res ){
 
 
 
 
 
 
 
70145 pc = pOp->p2 - 1;
70146 }
70147 break;
70148 }
70149
70150 /* Opcode: Seek P1 P2 * * *
70151 ** Synopsis: intkey=r[P2]
70152 **
70153 ** P1 is an open table cursor and P2 is a rowid integer. Arrange
70154 ** for P1 to move so that it points to the rowid given by P2.
70155 **
70156 ** This is actually a deferred seek. Nothing actually happens until
70157 ** the cursor is used to read a record. That way, if no reads
70158 ** occur, no unnecessary I/O happens.
70159 */
70160 case OP_Seek: { /* in2 */
70161 #if 0 /* local variables moved into u.be */
70162 VdbeCursor *pC;
70163 #endif /* local variables moved into u.be */
70164
70165 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70166 u.be.pC = p->apCsr[pOp->p1];
70167 assert( u.be.pC!=0 );
70168 assert( u.be.pC->pCursor!=0 );
70169 assert( u.be.pC->isTable );
70170 u.be.pC->nullRow = 0;
70171 pIn2 = &aMem[pOp->p2];
70172 u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
70173 u.be.pC->rowidIsValid = 0;
70174 u.be.pC->deferredMoveto = 1;
 
70175 break;
70176 }
70177
70178
70179 /* Opcode: Found P1 P2 P3 P4 *
70180 ** Synopsis: key=r[P3@P4]
70181 **
70182 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
70183 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
70184 ** record.
70185 **
70186 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
70187 ** is a prefix of any entry in P1 then a jump is made to P2 and
70188 ** P1 is left pointing at the matching entry.
70189 **
70190 ** See also: NotFound, NoConflict, NotExists. SeekGe
70191 */
70192 /* Opcode: NotFound P1 P2 P3 P4 *
70193 ** Synopsis: key=r[P3@P4]
70194 **
70195 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
70196 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
70197 ** record.
70198 **
@@ -69828,177 +70200,126 @@
70200 ** is not the prefix of any entry in P1 then a jump is made to P2. If P1
70201 ** does contain an entry whose prefix matches the P3/P4 record then control
70202 ** falls through to the next instruction and P1 is left pointing at the
70203 ** matching entry.
70204 **
70205 ** See also: Found, NotExists, NoConflict
70206 */
70207 /* Opcode: NoConflict P1 P2 P3 P4 *
70208 ** Synopsis: key=r[P3@P4]
70209 **
70210 ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
70211 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
70212 ** record.
70213 **
70214 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
70215 ** contains any NULL value, jump immediately to P2. If all terms of the
70216 ** record are not-NULL then a check is done to determine if any row in the
70217 ** P1 index btree has a matching key prefix. If there are no matches, jump
70218 ** immediately to P2. If there is a match, fall through and leave the P1
70219 ** cursor pointing to the matching row.
70220 **
70221 ** This opcode is similar to OP_NotFound with the exceptions that the
70222 ** branch is always taken if any part of the search key input is NULL.
70223 **
70224 ** See also: NotFound, Found, NotExists
70225 */
70226 case OP_NoConflict: /* jump, in3 */
70227 case OP_NotFound: /* jump, in3 */
70228 case OP_Found: { /* jump, in3 */
70229 #if 0 /* local variables moved into u.bf */
70230 int alreadyExists;
70231 int ii;
70232 VdbeCursor *pC;
70233 int res;
70234 char *pFree;
70235 UnpackedRecord *pIdxKey;
70236 UnpackedRecord r;
70237 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70238 #endif /* local variables moved into u.bf */
70239
70240 #ifdef SQLITE_TEST
70241 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
70242 #endif
70243
70244 u.bf.alreadyExists = 0;
70245 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70246 assert( pOp->p4type==P4_INT32 );
70247 u.bf.pC = p->apCsr[pOp->p1];
70248 assert( u.bf.pC!=0 );
70249 pIn3 = &aMem[pOp->p3];
70250 assert( u.bf.pC->pCursor!=0 );
70251 assert( u.bf.pC->isTable==0 );
70252 if( pOp->p4.i>0 ){
70253 u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo;
70254 u.bf.r.nField = (u16)pOp->p4.i;
70255 u.bf.r.aMem = pIn3;
70256 #ifdef SQLITE_DEBUG
70257 {
70258 int i;
70259 for(i=0; i<u.bf.r.nField; i++){
70260 assert( memIsValid(&u.bf.r.aMem[i]) );
70261 if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]);
70262 }
70263 }
70264 #endif
70265 u.bf.r.flags = UNPACKED_PREFIX_MATCH;
70266 u.bf.pIdxKey = &u.bf.r;
70267 }else{
70268 u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70269 u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree
70270 );
70271 if( u.bf.pIdxKey==0 ) goto no_mem;
70272 assert( pIn3->flags & MEM_Blob );
70273 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70274 sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey);
70275 u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70276 }
70277 if( pOp->opcode==OP_NoConflict ){
70278 /* For the OP_NoConflict opcode, take the jump if any of the
70279 ** input fields are NULL, since any key with a NULL will not
70280 ** conflict */
70281 for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){
70282 if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){
70283 pc = pOp->p2 - 1;
70284 break;
70285 }
70286 }
70287 }
70288 rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
70289 if( pOp->p4.i==0 ){
70290 sqlite3DbFree(db, u.bf.pFree);
70291 }
70292 if( rc!=SQLITE_OK ){
70293 break;
70294 }
70295 u.bf.pC->seekResult = u.bf.res;
70296 u.bf.alreadyExists = (u.bf.res==0);
70297 u.bf.pC->nullRow = 1-u.bf.alreadyExists;
70298 u.bf.pC->deferredMoveto = 0;
70299 u.bf.pC->cacheStatus = CACHE_STALE;
70300 if( pOp->opcode==OP_Found ){
70301 if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
70302 }else{
70303 if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70304 }
70305 break;
70306 }
70307
70308 /* Opcode: NotExists P1 P2 P3 * *
70309 ** Synopsis: intkey=r[P3]
70310 **
70311 ** P1 is the index of a cursor open on an SQL table btree (with integer
70312 ** keys). P3 is an integer rowid. If P1 does not contain a record with
70313 ** rowid P3 then jump immediately to P2. If P1 does contain a record
70314 ** with rowid P3 then leave the cursor pointing at that record and fall
70315 ** through to the next instruction.
70316 **
70317 ** The OP_NotFound opcode performs the same operation on index btrees
70318 ** (with arbitrary multi-value keys).
70319 **
70320 ** See also: Found, NotFound, NoConflict
70321 */
70322 case OP_NotExists: { /* jump, in3 */
70323 #if 0 /* local variables moved into u.bg */
70324 VdbeCursor *pC;
70325 BtCursor *pCrsr;
@@ -70012,36 +70333,29 @@
70333 u.bg.pC = p->apCsr[pOp->p1];
70334 assert( u.bg.pC!=0 );
70335 assert( u.bg.pC->isTable );
70336 assert( u.bg.pC->pseudoTableReg==0 );
70337 u.bg.pCrsr = u.bg.pC->pCursor;
70338 assert( u.bg.pCrsr!=0 );
70339 u.bg.res = 0;
70340 u.bg.iKey = pIn3->u.i;
70341 rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70342 u.bg.pC->lastRowid = pIn3->u.i;
70343 u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70344 u.bg.pC->nullRow = 0;
70345 u.bg.pC->cacheStatus = CACHE_STALE;
70346 u.bg.pC->deferredMoveto = 0;
70347 if( u.bg.res!=0 ){
70348 pc = pOp->p2 - 1;
70349 assert( u.bg.pC->rowidIsValid==0 );
70350 }
70351 u.bg.pC->seekResult = u.bg.res;
 
 
 
 
 
 
 
 
70352 break;
70353 }
70354
70355 /* Opcode: Sequence P1 P2 * * *
70356 ** Synopsis: r[P2]=rowid
70357 **
70358 ** Find the next available sequence number for cursor P1.
70359 ** Write the sequence number into register P2.
70360 ** The sequence number on the cursor is incremented after this
70361 ** instruction.
@@ -70053,10 +70367,11 @@
70367 break;
70368 }
70369
70370
70371 /* Opcode: NewRowid P1 P2 P3 * *
70372 ** Synopsis: r[P2]=rowid
70373 **
70374 ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
70375 ** The record number is not previously used as a key in the database
70376 ** table that cursor P1 points to. The new record number is written
70377 ** written to register P2.
@@ -70204,10 +70519,11 @@
70519 pOut->u.i = u.bh.v;
70520 break;
70521 }
70522
70523 /* Opcode: Insert P1 P2 P3 P4 P5
70524 ** Synopsis: intkey=r[P3] data=r[P2]
70525 **
70526 ** Write an entry into the table of cursor P1. A new entry is
70527 ** created if it doesn't already exist or the data for an existing
70528 ** entry is overwritten. The data is the value MEM_Blob stored in register
70529 ** number P2. The key is stored in register P3. The key must
@@ -70243,10 +70559,11 @@
70559 **
70560 ** This instruction only works on tables. The equivalent instruction
70561 ** for indices is OP_IdxInsert.
70562 */
70563 /* Opcode: InsertInt P1 P2 P3 P4 P5
70564 ** Synopsis: intkey=P3 data=r[P2]
70565 **
70566 ** This works exactly like OP_Insert except that the key is the
70567 ** integer value P3, not the value of the integer stored in register P3.
70568 */
70569 case OP_Insert:
@@ -70396,34 +70713,46 @@
70713 sqlite3VdbeSetChanges(db, p->nChange);
70714 p->nChange = 0;
70715 break;
70716 }
70717
70718 /* Opcode: SorterCompare P1 P2 P3 P4
70719 ** Synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2
70720 **
70721 ** P1 is a sorter cursor. This instruction compares a prefix of the
70722 ** the record blob in register P3 against a prefix of the entry that
70723 ** the sorter cursor currently points to. The final P4 fields of both
70724 ** the P3 and sorter record are ignored.
70725 **
70726 ** If either P3 or the sorter contains a NULL in one of their significant
70727 ** fields (not counting the P4 fields at the end which are ignored) then
70728 ** the comparison is assumed to be equal.
70729 **
70730 ** Fall through to next instruction if the two records compare equal to
70731 ** each other. Jump to P2 if they are different.
70732 */
70733 case OP_SorterCompare: {
70734 #if 0 /* local variables moved into u.bk */
70735 VdbeCursor *pC;
70736 int res;
70737 int nIgnore;
70738 #endif /* local variables moved into u.bk */
70739
70740 u.bk.pC = p->apCsr[pOp->p1];
70741 assert( isSorter(u.bk.pC) );
70742 assert( pOp->p4type==P4_INT32 );
70743 pIn3 = &aMem[pOp->p3];
70744 u.bk.nIgnore = pOp->p4.i;
70745 rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res);
70746 if( u.bk.res ){
70747 pc = pOp->p2-1;
70748 }
70749 break;
70750 };
70751
70752 /* Opcode: SorterData P1 P2 * * *
70753 ** Synopsis: r[P2]=data
70754 **
70755 ** Write into register P2 the current sorter data for sorter cursor P1.
70756 */
70757 case OP_SorterData: {
70758 #if 0 /* local variables moved into u.bl */
@@ -70436,10 +70765,11 @@
70765 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
70766 break;
70767 }
70768
70769 /* Opcode: RowData P1 P2 * * *
70770 ** Synopsis: r[P2]=data
70771 **
70772 ** Write into register P2 the complete row data for cursor P1.
70773 ** There is no interpretation of the data.
70774 ** It is just copied onto the P2 register exactly as
70775 ** it is found in the database file.
@@ -70446,10 +70776,11 @@
70776 **
70777 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70778 ** of a real table, not a pseudo-table.
70779 */
70780 /* Opcode: RowKey P1 P2 * * *
70781 ** Synopsis: r[P2]=key
70782 **
70783 ** Write into register P2 the complete row key for cursor P1.
70784 ** There is no interpretation of the data.
70785 ** The key is copied onto the P3 register exactly as
70786 ** it is found in the database file.
@@ -70516,14 +70847,16 @@
70847 }else{
70848 rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70849 }
70850 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70851 UPDATE_MAX_BLOBSIZE(pOut);
70852 REGISTER_TRACE(pOp->p2, pOut);
70853 break;
70854 }
70855
70856 /* Opcode: Rowid P1 P2 * * *
70857 ** Synopsis: r[P2]=rowid
70858 **
70859 ** Store in register P2 an integer which is the key of the table entry that
70860 ** P1 is currently point to.
70861 **
70862 ** P1 can be either an ordinary table or a virtual table. There used to
@@ -70611,13 +70944,12 @@
70944 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70945 u.bp.pC = p->apCsr[pOp->p1];
70946 assert( u.bp.pC!=0 );
70947 u.bp.pCrsr = u.bp.pC->pCursor;
70948 u.bp.res = 0;
70949 assert( u.bp.pCrsr!=0 );
70950 rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
 
70951 u.bp.pC->nullRow = (u8)u.bp.res;
70952 u.bp.pC->deferredMoveto = 0;
70953 u.bp.pC->rowidIsValid = 0;
70954 u.bp.pC->cacheStatus = CACHE_STALE;
70955 if( pOp->p2>0 && u.bp.res ){
@@ -70685,11 +71017,11 @@
71017 pc = pOp->p2 - 1;
71018 }
71019 break;
71020 }
71021
71022 /* Opcode: Next P1 P2 * * P5
71023 **
71024 ** Advance cursor P1 so that it points to the next key/data pair in its
71025 ** table or index. If there are no more key/value pairs then fall through
71026 ** to the following instruction. But if the cursor advance was successful,
71027 ** jump immediately to P2.
@@ -70757,10 +71089,11 @@
71089 u.br.pC->rowidIsValid = 0;
71090 goto check_for_interrupt;
71091 }
71092
71093 /* Opcode: IdxInsert P1 P2 P3 * P5
71094 ** Synopsis: key=r[P2]
71095 **
71096 ** Register P2 holds an SQL index key made using the
71097 ** MakeRecord instructions. This opcode writes that key
71098 ** into the index P1. Data for the entry is nil.
71099 **
@@ -70784,31 +71117,32 @@
71117 assert( u.bs.pC!=0 );
71118 assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) );
71119 pIn2 = &aMem[pOp->p2];
71120 assert( pIn2->flags & MEM_Blob );
71121 u.bs.pCrsr = u.bs.pC->pCursor;
71122 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71123 assert( u.bs.pCrsr!=0 );
71124 assert( u.bs.pC->isTable==0 );
71125 rc = ExpandBlob(pIn2);
71126 if( rc==SQLITE_OK ){
71127 if( isSorter(u.bs.pC) ){
71128 rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
71129 }else{
71130 u.bs.nKey = pIn2->n;
71131 u.bs.zKey = pIn2->z;
71132 rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
71133 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
71134 );
71135 assert( u.bs.pC->deferredMoveto==0 );
71136 u.bs.pC->cacheStatus = CACHE_STALE;
71137 }
71138 }
71139 break;
71140 }
71141
71142 /* Opcode: IdxDelete P1 P2 P3 * *
71143 ** Synopsis: key=r[P2@P3]
71144 **
71145 ** The content of P3 registers starting at register P2 form
71146 ** an unpacked index key. This opcode removes that entry from the
71147 ** index opened by cursor P1.
71148 */
@@ -70824,29 +71158,30 @@
71158 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
71159 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71160 u.bt.pC = p->apCsr[pOp->p1];
71161 assert( u.bt.pC!=0 );
71162 u.bt.pCrsr = u.bt.pC->pCursor;
71163 assert( u.bt.pCrsr!=0 );
71164 assert( pOp->p5==0 );
71165 u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
71166 u.bt.r.nField = (u16)pOp->p3;
71167 u.bt.r.flags = UNPACKED_PREFIX_MATCH;
71168 u.bt.r.aMem = &aMem[pOp->p2];
71169 #ifdef SQLITE_DEBUG
71170 { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
71171 #endif
71172 rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
71173 if( rc==SQLITE_OK && u.bt.res==0 ){
71174 rc = sqlite3BtreeDelete(u.bt.pCrsr);
 
 
 
71175 }
71176 assert( u.bt.pC->deferredMoveto==0 );
71177 u.bt.pC->cacheStatus = CACHE_STALE;
71178 break;
71179 }
71180
71181 /* Opcode: IdxRowid P1 P2 * * *
71182 ** Synopsis: r[P2]=rowid
71183 **
71184 ** Write into register P2 an integer which is the last entry in the record at
71185 ** the end of the index key pointed to by cursor P1. This integer should be
71186 ** the rowid of the table entry to which this index entry points.
71187 **
@@ -70861,29 +71196,29 @@
71196
71197 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71198 u.bu.pC = p->apCsr[pOp->p1];
71199 assert( u.bu.pC!=0 );
71200 u.bu.pCrsr = u.bu.pC->pCursor;
71201 assert( u.bu.pCrsr!=0 );
71202 pOut->flags = MEM_Null;
71203 rc = sqlite3VdbeCursorMoveto(u.bu.pC);
71204 if( NEVER(rc) ) goto abort_due_to_error;
71205 assert( u.bu.pC->deferredMoveto==0 );
71206 assert( u.bu.pC->isTable==0 );
71207 if( !u.bu.pC->nullRow ){
71208 rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
71209 if( rc!=SQLITE_OK ){
71210 goto abort_due_to_error;
71211 }
71212 pOut->u.i = u.bu.rowid;
71213 pOut->flags = MEM_Int;
 
 
71214 }
71215 break;
71216 }
71217
71218 /* Opcode: IdxGE P1 P2 P3 P4 P5
71219 ** Synopsis: key=r[P3@P4]
71220 **
71221 ** The P4 register values beginning with P3 form an unpacked index
71222 ** key that omits the ROWID. Compare this key value against the index
71223 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
71224 **
@@ -70894,10 +71229,11 @@
71229 ** prior to the comparison. This make the opcode work like IdxGT except
71230 ** that if the key from register P3 is a prefix of the key in the cursor,
71231 ** the result is false whereas it would be true with IdxGT.
71232 */
71233 /* Opcode: IdxLT P1 P2 P3 P4 P5
71234 ** Synopsis: key=r[P3@P4]
71235 **
71236 ** The P4 register values beginning with P3 form an unpacked index
71237 ** key that omits the ROWID. Compare this key value against the index
71238 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
71239 **
@@ -70917,35 +71253,34 @@
71253
71254 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71255 u.bv.pC = p->apCsr[pOp->p1];
71256 assert( u.bv.pC!=0 );
71257 assert( u.bv.pC->isOrdered );
71258 assert( u.bv.pC->pCursor!=0);
71259 assert( u.bv.pC->deferredMoveto==0 );
71260 assert( pOp->p5==0 || pOp->p5==1 );
71261 assert( pOp->p4type==P4_INT32 );
71262 u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
71263 u.bv.r.nField = (u16)pOp->p4.i;
71264 if( pOp->p5 ){
71265 u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71266 }else{
71267 u.bv.r.flags = UNPACKED_PREFIX_MATCH;
71268 }
71269 u.bv.r.aMem = &aMem[pOp->p3];
71270 #ifdef SQLITE_DEBUG
71271 { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
71272 #endif
71273 rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
71274 if( pOp->opcode==OP_IdxLT ){
71275 u.bv.res = -u.bv.res;
71276 }else{
71277 assert( pOp->opcode==OP_IdxGE );
71278 u.bv.res++;
71279 }
71280 if( u.bv.res>0 ){
71281 pc = pOp->p2 - 1 ;
 
71282 }
71283 break;
71284 }
71285
71286 /* Opcode: Destroy P1 P2 P3 * *
@@ -71052,10 +71387,11 @@
71387 }
71388 break;
71389 }
71390
71391 /* Opcode: CreateTable P1 P2 * * *
71392 ** Synopsis: r[P2]=root iDb=P1
71393 **
71394 ** Allocate a new table in the main database file if P1==0 or in the
71395 ** auxiliary database file if P1==1 or in an attached database if
71396 ** P1>1. Write the root page number of the new table into
71397 ** register P2
@@ -71065,10 +71401,11 @@
71401 ** has an arbitrary key but no data.
71402 **
71403 ** See also: CreateIndex
71404 */
71405 /* Opcode: CreateIndex P1 P2 * * *
71406 ** Synopsis: r[P2]=root iDb=P1
71407 **
71408 ** Allocate a new index in the main database file if P1==0 or in the
71409 ** auxiliary database file if P1==1 or in an attached database if
71410 ** P1>1. Write the root page number of the new table into
71411 ** register P2.
@@ -71272,10 +71609,11 @@
71609 break;
71610 }
71611 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
71612
71613 /* Opcode: RowSetAdd P1 P2 * * *
71614 ** Synopsis: rowset(P1)=r[P2]
71615 **
71616 ** Insert the integer value held by register P2 into a boolean index
71617 ** held in register P1.
71618 **
71619 ** An assertion fails if P2 is not an integer.
@@ -71291,10 +71629,11 @@
71629 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn2->u.i);
71630 break;
71631 }
71632
71633 /* Opcode: RowSetRead P1 P2 P3 * *
71634 ** Synopsis: r[P3]=rowset(P1)
71635 **
71636 ** Extract the smallest value from boolean index P1 and put that value into
71637 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71638 ** unchanged and jump to instruction P2.
71639 */
@@ -71316,10 +71655,11 @@
71655 }
71656 goto check_for_interrupt;
71657 }
71658
71659 /* Opcode: RowSetTest P1 P2 P3 P4
71660 ** Synopsis: if r[P3] in rowset(P1) goto P2
71661 **
71662 ** Register P3 is assumed to hold a 64-bit integer value. If register P1
71663 ** contains a RowSet object and that RowSet object contains
71664 ** the value held in P3, jump to register P2. Otherwise, insert the
71665 ** integer in P3 into the RowSet and continue on to the
@@ -71525,10 +71865,11 @@
71865
71866 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71867
71868 #ifndef SQLITE_OMIT_FOREIGN_KEY
71869 /* Opcode: FkCounter P1 P2 * * *
71870 ** Synopsis: fkctr[P1]+=P2
71871 **
71872 ** Increment a "constraint counter" by P2 (P2 may be negative or positive).
71873 ** If P1 is non-zero, the database constraint counter is incremented
71874 ** (deferred foreign key constraints). Otherwise, if P1 is zero, the
71875 ** statement counter is incremented (immediate foreign key constraints).
@@ -71543,10 +71884,11 @@
71884 }
71885 break;
71886 }
71887
71888 /* Opcode: FkIfZero P1 P2 * * *
71889 ** Synopsis: if fkctr[P1]==0 goto P2
71890 **
71891 ** This opcode tests if a foreign key constraint-counter is currently zero.
71892 ** If so, jump to instruction P2. Otherwise, fall through to the next
71893 ** instruction.
71894 **
@@ -71565,10 +71907,11 @@
71907 }
71908 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
71909
71910 #ifndef SQLITE_OMIT_AUTOINCREMENT
71911 /* Opcode: MemMax P1 P2 * * *
71912 ** Synopsis: r[P1]=max(r[P1],r[P2])
71913 **
71914 ** P1 is a register in the root frame of this VM (the root frame is
71915 ** different from the current frame if this instruction is being executed
71916 ** within a sub-program). Set the value of register P1 to the maximum of
71917 ** its current value and the value in register P2.
@@ -71597,10 +71940,11 @@
71940 break;
71941 }
71942 #endif /* SQLITE_OMIT_AUTOINCREMENT */
71943
71944 /* Opcode: IfPos P1 P2 * * *
71945 ** Synopsis: if r[P1]>0 goto P2
71946 **
71947 ** If the value of register P1 is 1 or greater, jump to P2.
71948 **
71949 ** It is illegal to use this instruction on a register that does
71950 ** not contain an integer. An assertion fault will result if you try.
@@ -71613,10 +71957,11 @@
71957 }
71958 break;
71959 }
71960
71961 /* Opcode: IfNeg P1 P2 * * *
71962 ** Synopsis: if r[P1]<0 goto P2
71963 **
71964 ** If the value of register P1 is less than zero, jump to P2.
71965 **
71966 ** It is illegal to use this instruction on a register that does
71967 ** not contain an integer. An assertion fault will result if you try.
@@ -71629,10 +71974,11 @@
71974 }
71975 break;
71976 }
71977
71978 /* Opcode: IfZero P1 P2 P3 * *
71979 ** Synopsis: r[P1]+=P3, if r[P1]==0 goto P2
71980 **
71981 ** The register P1 must contain an integer. Add literal P3 to the
71982 ** value in register P1. If the result is exactly 0, jump to P2.
71983 **
71984 ** It is illegal to use this instruction on a register that does
@@ -71647,10 +71993,11 @@
71993 }
71994 break;
71995 }
71996
71997 /* Opcode: AggStep * P2 P3 P4 P5
71998 ** Synopsis: accum=r[P3] step(r[P2@P5])
71999 **
72000 ** Execute the step function for an aggregate. The
72001 ** function has P5 arguments. P4 is a pointer to the FuncDef
72002 ** structure that specifies the function. Use register
72003 ** P3 as the accumulator.
@@ -71712,10 +72059,11 @@
72059
72060 break;
72061 }
72062
72063 /* Opcode: AggFinal P1 P2 * P4 *
72064 ** Synopsis: accum=r[P1] N=P2
72065 **
72066 ** Execute the finalizer function for an aggregate. P1 is
72067 ** the memory location that is the accumulator for the aggregate.
72068 **
72069 ** P2 is the number of arguments that the step function takes and
@@ -71947,10 +72295,11 @@
72295 break;
72296 }
72297
72298 #ifndef SQLITE_OMIT_SHARED_CACHE
72299 /* Opcode: TableLock P1 P2 P3 P4 *
72300 ** Synopsis: iDb=P1 root=P2 write=P3
72301 **
72302 ** Obtain a lock on a particular table. This instruction is only used when
72303 ** the shared-cache feature is enabled.
72304 **
72305 ** P1 is the index of the database in sqlite3.aDb[] of the database
@@ -72067,10 +72416,11 @@
72416 }
72417 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72418
72419 #ifndef SQLITE_OMIT_VIRTUALTABLE
72420 /* Opcode: VFilter P1 P2 P3 P4 *
72421 ** Synopsis: iPlan=r[P3] zPlan='P4'
72422 **
72423 ** P1 is a cursor opened using VOpen. P2 is an address to jump to if
72424 ** the filtered result set is empty.
72425 **
72426 ** P4 is either NULL or a string that was generated by the xBestIndex
@@ -72143,10 +72493,11 @@
72493 }
72494 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72495
72496 #ifndef SQLITE_OMIT_VIRTUALTABLE
72497 /* Opcode: VColumn P1 P2 P3 * *
72498 ** Synopsis: r[P3]=vcolumn(P2)
72499 **
72500 ** Store the value of the P2-th column of
72501 ** the row of the virtual-table that the
72502 ** P1 cursor is pointing to into register P3.
72503 */
@@ -72282,10 +72633,11 @@
72633 }
72634 #endif
72635
72636 #ifndef SQLITE_OMIT_VIRTUALTABLE
72637 /* Opcode: VUpdate P1 P2 P3 P4 *
72638 ** Synopsis: data=r[P3@P2]
72639 **
72640 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72641 ** This opcode invokes the corresponding xUpdate method. P2 values
72642 ** are contiguous memory cells starting at P3 to pass to the xUpdate
72643 ** invocation. The value in register (P3+P2-1) corresponds to the
@@ -72413,10 +72765,20 @@
72765 ){
72766 u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
72767 db->xTrace(db->pTraceArg, u.cs.z);
72768 sqlite3DbFree(db, u.cs.z);
72769 }
72770 #ifdef SQLITE_USE_FCNTL_TRACE
72771 u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72772 if( u.cs.zTrace ){
72773 int i;
72774 for(i=0; i<db->nDb; i++){
72775 if( ((1<<i) & p->btreeMask)==0 ) continue;
72776 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace);
72777 }
72778 }
72779 #endif /* SQLITE_USE_FCNTL_TRACE */
72780 #ifdef SQLITE_DEBUG
72781 if( (db->flags & SQLITE_SqlTrace)!=0
72782 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72783 ){
72784 sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
@@ -72727,10 +73089,14 @@
73089 pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
73090 if( pTab && IsVirtual(pTab) ){
73091 pTab = 0;
73092 sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
73093 }
73094 if( pTab && !HasRowid(pTab) ){
73095 pTab = 0;
73096 sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
73097 }
73098 #ifndef SQLITE_OMIT_VIEW
73099 if( pTab && pTab->pSelect ){
73100 pTab = 0;
73101 sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
73102 }
@@ -72784,11 +73150,11 @@
73150 }
73151 }
73152 #endif
73153 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
73154 int j;
73155 for(j=0; j<pIdx->nKeyCol; j++){
73156 if( pIdx->aiColumn[j]==iCol ){
73157 zFault = "indexed";
73158 }
73159 }
73160 }
@@ -73405,11 +73771,11 @@
73771 ** If pKey2 is passed a NULL pointer, then it is assumed that the pCsr->aSpace
73772 ** has been allocated and contains an unpacked record that is used as key2.
73773 */
73774 static void vdbeSorterCompare(
73775 const VdbeCursor *pCsr, /* Cursor object (for pKeyInfo) */
73776 int nIgnore, /* Ignore the last nIgnore fields */
73777 const void *pKey1, int nKey1, /* Left side of comparison */
73778 const void *pKey2, int nKey2, /* Right side of comparison */
73779 int *pRes /* OUT: Result of comparison */
73780 ){
73781 KeyInfo *pKeyInfo = pCsr->pKeyInfo;
@@ -73419,12 +73785,12 @@
73785
73786 if( pKey2 ){
73787 sqlite3VdbeRecordUnpack(pKeyInfo, nKey2, pKey2, r2);
73788 }
73789
73790 if( nIgnore ){
73791 r2->nField = pKeyInfo->nField - nIgnore;
73792 assert( r2->nField>0 );
73793 for(i=0; i<r2->nField; i++){
73794 if( r2->aMem[i].flags & MEM_Null ){
73795 *pRes = -1;
73796 return;
@@ -74046,17 +74412,18 @@
74412 ** key.
74413 */
74414 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(
74415 const VdbeCursor *pCsr, /* Sorter cursor */
74416 Mem *pVal, /* Value to compare to current sorter key */
74417 int nIgnore, /* Ignore this many fields at the end */
74418 int *pRes /* OUT: Result of comparison */
74419 ){
74420 VdbeSorter *pSorter = pCsr->pSorter;
74421 void *pKey; int nKey; /* Sorter key to compare pVal with */
74422
74423 pKey = vdbeSorterRowkey(pSorter, &nKey);
74424 vdbeSorterCompare(pCsr, nIgnore, pVal->z, pVal->n, pKey, nKey, pRes);
74425 return SQLITE_OK;
74426 }
74427
74428 /************** End of vdbesort.c ********************************************/
74429 /************** Begin file journal.c *****************************************/
@@ -74955,11 +75322,13 @@
75322 sqlite3 *db = pParse->db; /* The database connection */
75323 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
75324 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
75325 NameContext *pTopNC = pNC; /* First namecontext in the list */
75326 Schema *pSchema = 0; /* Schema of the expression */
75327 int isTrigger = 0; /* True if resolved to a trigger column */
75328 Table *pTab = 0; /* Table hold the row */
75329 Column *pCol; /* A column of pTab */
75330
75331 assert( pNC ); /* the name context cannot be NULL. */
75332 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
75333 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
75334
@@ -74996,13 +75365,10 @@
75365 ExprList *pEList;
75366 SrcList *pSrcList = pNC->pSrcList;
75367
75368 if( pSrcList ){
75369 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
 
 
 
75370 pTab = pItem->pTab;
75371 assert( pTab!=0 && pTab->zName!=0 );
75372 assert( pTab->nCol>0 );
75373 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
75374 int hit = 0;
@@ -75058,13 +75424,12 @@
75424
75425 #ifndef SQLITE_OMIT_TRIGGER
75426 /* If we have not already resolved the name, then maybe
75427 ** it is a new.* or old.* trigger argument reference
75428 */
75429 if( zDb==0 && zTab!=0 && cntTab==0 && pParse->pTriggerTab!=0 ){
75430 int op = pParse->eTriggerOp;
 
75431 assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
75432 if( op!=TK_DELETE && sqlite3StrICmp("new",zTab) == 0 ){
75433 pExpr->iTable = 1;
75434 pTab = pParse->pTriggerTab;
75435 }else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
@@ -75074,20 +75439,19 @@
75439
75440 if( pTab ){
75441 int iCol;
75442 pSchema = pTab->pSchema;
75443 cntTab++;
75444 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
 
75445 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
75446 if( iCol==pTab->iPKey ){
75447 iCol = -1;
75448 }
75449 break;
75450 }
75451 }
75452 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75453 iCol = -1; /* IMP: R-44911-55124 */
75454 }
75455 if( iCol<pTab->nCol ){
75456 cnt++;
75457 if( iCol<0 ){
@@ -75110,11 +75474,12 @@
75474 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75475
75476 /*
75477 ** Perhaps the name is a reference to the ROWID
75478 */
75479 assert( pTab!=0 || cntTab==0 );
75480 if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75481 cnt = 1;
75482 pExpr->iColumn = -1; /* IMP: R-44911-55124 */
75483 pExpr->affinity = SQLITE_AFF_INTEGER;
75484 }
75485
@@ -77714,20 +78079,20 @@
78079 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
78080 if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
78081 sqlite3 *db = pParse->db; /* Database connection */
78082 Table *pTab; /* Table <table>. */
78083 Expr *pExpr; /* Expression <column> */
78084 i16 iCol; /* Index of column <column> */
78085 i16 iDb; /* Database idx for pTab */
78086
78087 assert( p ); /* Because of isCandidateForInOpt(p) */
78088 assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
78089 assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
78090 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
78091 pTab = p->pSrc->a[0].pTab;
78092 pExpr = p->pEList->a[0].pExpr;
78093 iCol = (i16)pExpr->iColumn;
78094
78095 /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
78096 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
78097 sqlite3CodeVerifySchema(pParse, iDb);
78098 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
@@ -77761,20 +78126,15 @@
78126 int affinity_ok = sqlite3IndexAffinityOk(pX, pTab->aCol[iCol].affinity);
78127
78128 for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
78129 if( (pIdx->aiColumn[0]==iCol)
78130 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
78131 && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
78132 ){
78133 int iAddr = sqlite3CodeOnce(pParse);
78134 sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
78135 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
 
 
 
 
 
78136 VdbeComment((v, "%s", pIdx->zName));
78137 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
78138 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
78139
78140 sqlite3VdbeJumpHere(v, iAddr);
@@ -77910,11 +78270,11 @@
78270 ** is used.
78271 */
78272 pExpr->iTable = pParse->nTab++;
78273 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
78274 if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
78275 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
78276
78277 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
78278 /* Case 1: expr IN (SELECT ...)
78279 **
78280 ** Generate code to write the results of the select into the temporary
@@ -77928,17 +78288,18 @@
78288 dest.affSdst = (u8)affinity;
78289 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
78290 pExpr->x.pSelect->iLimit = 0;
78291 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
78292 if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
78293 sqlite3KeyInfoUnref(pKeyInfo);
78294 return 0;
78295 }
78296 pEList = pExpr->x.pSelect->pEList;
78297 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
78298 assert( pEList!=0 );
78299 assert( pEList->nExpr>0 );
78300 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
78301 pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
78302 pEList->a[0].pExpr);
78303 }else if( ALWAYS(pExpr->x.pList!=0) ){
78304 /* Case 2: expr IN (exprlist)
78305 **
@@ -77954,10 +78315,11 @@
78315
78316 if( !affinity ){
78317 affinity = SQLITE_AFF_NONE;
78318 }
78319 if( pKeyInfo ){
78320 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
78321 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
78322 }
78323
78324 /* Loop through each expression in <exprlist>. */
78325 r1 = sqlite3GetTempReg(pParse);
@@ -77995,11 +78357,11 @@
78357 }
78358 sqlite3ReleaseTempReg(pParse, r1);
78359 sqlite3ReleaseTempReg(pParse, r2);
78360 }
78361 if( pKeyInfo ){
78362 sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
78363 }
78364 break;
78365 }
78366
78367 case TK_EXISTS:
@@ -78396,19 +78758,23 @@
78758 ** Generate code to extract the value of the iCol-th column of a table.
78759 */
78760 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
78761 Vdbe *v, /* The VDBE under construction */
78762 Table *pTab, /* The table containing the value */
78763 int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
78764 int iCol, /* Index of the column to extract */
78765 int regOut /* Extract the value into this register */
78766 ){
78767 if( iCol<0 || iCol==pTab->iPKey ){
78768 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
78769 }else{
78770 int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
78771 int x = iCol;
78772 if( !HasRowid(pTab) ){
78773 x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol);
78774 }
78775 sqlite3VdbeAddOp3(v, op, iTabCur, x, regOut);
78776 }
78777 if( iCol>=0 ){
78778 sqlite3ColumnDefault(v, pTab, iCol, regOut);
78779 }
78780 }
@@ -79150,11 +79516,11 @@
79516 if( pExpr->affinity==OE_Ignore ){
79517 sqlite3VdbeAddOp4(
79518 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
79519 }else{
79520 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
79521 pExpr->affinity, pExpr->u.zToken, 0, 0);
79522 }
79523
79524 break;
79525 }
79526 #endif
@@ -81526,12 +81892,11 @@
81892 }
81893
81894 /* Open the sqlite_stat[134] tables for writing. */
81895 for(i=0; aTable[i].zCols; i++){
81896 assert( i<ArraySize(aTable) );
81897 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb, 3);
 
81898 sqlite3VdbeChangeP5(v, aCreateTbl[i]);
81899 }
81900 }
81901
81902 /*
@@ -81551,11 +81916,15 @@
81916 struct Stat4Sample {
81917 tRowcnt *anEq; /* sqlite_stat4.nEq */
81918 tRowcnt *anDLt; /* sqlite_stat4.nDLt */
81919 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81920 tRowcnt *anLt; /* sqlite_stat4.nLt */
81921 union {
81922 i64 iRowid; /* Rowid in main table of the key */
81923 u8 *aRowid; /* Key for WITHOUT ROWID tables */
81924 } u;
81925 u32 nRowid; /* Sizeof aRowid[] */
81926 u8 isPSample; /* True if a periodic sample */
81927 int iCol; /* If !isPSample, the reason for inclusion */
81928 u32 iHash; /* Tiebreaker hash */
81929 #endif
81930 };
@@ -81564,16 +81933,90 @@
81933 tRowcnt nPSample; /* How often to do a periodic sample */
81934 int nCol; /* Number of columns in index + rowid */
81935 int mxSample; /* Maximum number of samples to accumulate */
81936 Stat4Sample current; /* Current row as a Stat4Sample */
81937 u32 iPrn; /* Pseudo-random number used for sampling */
81938 Stat4Sample *aBest; /* Array of nCol best samples */
81939 int iMin; /* Index in a[] of entry with minimum score */
81940 int nSample; /* Current number of samples */
81941 int iGet; /* Index of current sample accessed by stat_get() */
81942 Stat4Sample *a; /* Array of mxSample Stat4Sample objects */
81943 sqlite3 *db; /* Database connection, for malloc() */
81944 };
81945
81946 /* Reclaim memory used by a Stat4Sample
81947 */
81948 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81949 static void sampleClear(sqlite3 *db, Stat4Sample *p){
81950 assert( db!=0 );
81951 if( p->nRowid ){
81952 sqlite3DbFree(db, p->u.aRowid);
81953 p->nRowid = 0;
81954 }
81955 }
81956 #endif
81957
81958 /* Initialize the BLOB value of a ROWID
81959 */
81960 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81961 static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){
81962 assert( db!=0 );
81963 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
81964 p->u.aRowid = sqlite3DbMallocRaw(db, n);
81965 if( p->u.aRowid ){
81966 p->nRowid = n;
81967 memcpy(p->u.aRowid, pData, n);
81968 }else{
81969 p->nRowid = 0;
81970 }
81971 }
81972 #endif
81973
81974 /* Initialize the INTEGER value of a ROWID.
81975 */
81976 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81977 static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){
81978 assert( db!=0 );
81979 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
81980 p->nRowid = 0;
81981 p->u.iRowid = iRowid;
81982 }
81983 #endif
81984
81985
81986 /*
81987 ** Copy the contents of object (*pFrom) into (*pTo).
81988 */
81989 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
81990 static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){
81991 pTo->isPSample = pFrom->isPSample;
81992 pTo->iCol = pFrom->iCol;
81993 pTo->iHash = pFrom->iHash;
81994 memcpy(pTo->anEq, pFrom->anEq, sizeof(tRowcnt)*p->nCol);
81995 memcpy(pTo->anLt, pFrom->anLt, sizeof(tRowcnt)*p->nCol);
81996 memcpy(pTo->anDLt, pFrom->anDLt, sizeof(tRowcnt)*p->nCol);
81997 if( pFrom->nRowid ){
81998 sampleSetRowid(p->db, pTo, pFrom->nRowid, pFrom->u.aRowid);
81999 }else{
82000 sampleSetRowidInt64(p->db, pTo, pFrom->u.iRowid);
82001 }
82002 }
82003 #endif
82004
82005 /*
82006 ** Reclaim all memory of a Stat4Accum structure.
82007 */
82008 static void stat4Destructor(void *pOld){
82009 Stat4Accum *p = (Stat4Accum*)pOld;
82010 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
82011 int i;
82012 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
82013 for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
82014 sampleClear(p->db, &p->current);
82015 #endif
82016 sqlite3DbFree(p->db, p);
82017 }
82018
82019 /*
82020 ** Implementation of the stat_init(N,C) SQL function. The two parameters
82021 ** are the number of rows in the table or index (C) and the number of columns
82022 ** in the index (N). The second argument (C) is only used for STAT3 and STAT4.
@@ -81589,10 +82032,11 @@
82032 ){
82033 Stat4Accum *p;
82034 int nCol; /* Number of columns in index being sampled */
82035 int nColUp; /* nCol rounded up for alignment */
82036 int n; /* Bytes of space to allocate */
82037 sqlite3 *db; /* Database connection */
82038 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
82039 int mxSample = SQLITE_STAT4_SAMPLES;
82040 #endif
82041
82042 /* Decode the three function arguments */
@@ -81605,20 +82049,22 @@
82049 n = sizeof(*p)
82050 + sizeof(tRowcnt)*nColUp /* Stat4Accum.anEq */
82051 + sizeof(tRowcnt)*nColUp /* Stat4Accum.anDLt */
82052 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
82053 + sizeof(tRowcnt)*nColUp /* Stat4Accum.anLt */
82054 + sizeof(Stat4Sample)*(nCol+mxSample) /* Stat4Accum.aBest[], a[] */
82055 + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample)
82056 #endif
82057 ;
82058 db = sqlite3_context_db_handle(context);
82059 p = sqlite3DbMallocZero(db, n);
82060 if( p==0 ){
82061 sqlite3_result_error_nomem(context);
82062 return;
82063 }
82064
82065 p->db = db;
82066 p->nRow = 0;
82067 p->nCol = nCol;
82068 p->current.anDLt = (tRowcnt*)&p[1];
82069 p->current.anEq = &p->current.anDLt[nColUp];
82070
@@ -81649,11 +82095,11 @@
82095 }
82096 }
82097 #endif
82098
82099 /* Return a pointer to the allocated object to the caller */
82100 sqlite3_result_blob(context, p, sizeof(p), stat4Destructor);
82101 }
82102 static const FuncDef statInitFuncdef = {
82103 1+IsStat34, /* nArg */
82104 SQLITE_UTF8, /* funcFlags */
82105 0, /* pUserData */
@@ -81723,29 +82169,16 @@
82169 #else
82170 return (nEqNew==nEqOld && pNew->iHash>pOld->iHash);
82171 #endif
82172 }
82173
 
 
 
 
 
 
 
 
 
 
 
 
 
82174 /*
82175 ** Copy the contents of sample *pNew into the p->a[] array. If necessary,
82176 ** remove the least desirable sample from p->a[] to make room.
82177 */
82178 static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
82179 Stat4Sample *pSample = 0;
82180 int i;
82181
82182 assert( IsStat4 || nEqZero==0 );
82183
82184 #ifdef SQLITE_ENABLE_STAT4
@@ -81781,12 +82214,14 @@
82214 if( p->nSample>=p->mxSample ){
82215 Stat4Sample *pMin = &p->a[p->iMin];
82216 tRowcnt *anEq = pMin->anEq;
82217 tRowcnt *anLt = pMin->anLt;
82218 tRowcnt *anDLt = pMin->anDLt;
82219 sampleClear(p->db, pMin);
82220 memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-p->iMin-1));
82221 pSample = &p->a[p->nSample-1];
82222 pSample->nRowid = 0;
82223 pSample->anEq = anEq;
82224 pSample->anDLt = anDLt;
82225 pSample->anLt = anLt;
82226 p->nSample = p->mxSample-1;
82227 }
@@ -81879,20 +82314,21 @@
82314 UNUSED_PARAMETER( iChng );
82315 #endif
82316 }
82317
82318 /*
82319 ** Implementation of the stat_push SQL function: stat_push(P,C,R)
82320 ** Arguments:
82321 **
82322 ** P Pointer to the Stat4Accum object created by stat_init()
82323 ** C Index of left-most column to differ from previous row
82324 ** R Rowid for the current row. Might be a key record for
82325 ** WITHOUT ROWID tables.
82326 **
82327 ** The SQL function always returns NULL.
82328 **
82329 ** The R parameter is only used for STAT3 and STAT4
82330 */
82331 static void statPush(
82332 sqlite3_context *context,
82333 int argc,
82334 sqlite3_value **argv
@@ -81928,11 +82364,16 @@
82364 p->current.anEq[i] = 1;
82365 }
82366 }
82367 p->nRow++;
82368 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
82369 if( sqlite3_value_type(argv[2])==SQLITE_INTEGER ){
82370 sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2]));
82371 }else{
82372 sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
82373 sqlite3_value_blob(argv[2]));
82374 }
82375 p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345;
82376 #endif
82377
82378 #ifdef SQLITE_ENABLE_STAT4
82379 {
@@ -82052,11 +82493,17 @@
82493 if( p->iGet<0 ){
82494 samplePushPrevious(p, 0);
82495 p->iGet = 0;
82496 }
82497 if( p->iGet<p->nSample ){
82498 Stat4Sample *pS = p->a + p->iGet;
82499 if( pS->nRowid==0 ){
82500 sqlite3_result_int64(context, pS->u.iRowid);
82501 }else{
82502 sqlite3_result_blob(context, pS->u.aRowid, pS->nRowid,
82503 SQLITE_TRANSIENT);
82504 }
82505 }
82506 }else{
82507 tRowcnt *aCnt = 0;
82508
82509 assert( p->iGet<p->nSample );
@@ -82189,26 +82636,30 @@
82636 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
82637 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
82638
82639 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
82640 int nCol; /* Number of columns indexed by pIdx */
 
82641 int *aGotoChng; /* Array of jump instruction addresses */
82642 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
82643 int addrGotoChng0; /* Address of "Goto addr_chng_0" */
82644 int addrNextRow; /* Address of "next_row:" */
82645 const char *zIdxName; /* Name of the index */
82646
82647 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
82648 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
82649 VdbeNoopComment((v, "Begin analysis of %s", pIdx->zName));
82650 nCol = pIdx->nKeyCol;
82651 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
82652 if( aGotoChng==0 ) continue;
 
82653
82654 /* Populate the register containing the index name. */
82655 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
82656 zIdxName = pTab->zName;
82657 }else{
82658 zIdxName = pIdx->zName;
82659 }
82660 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
82661
82662 /*
82663 ** Pseudo-code for loop that calls stat_push():
82664 **
82665 ** Rewind csr
@@ -82247,11 +82698,11 @@
82698 pParse->nMem = MAX(pParse->nMem, regPrev+nCol);
82699
82700 /* Open a read-only cursor on the index being analyzed. */
82701 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
82702 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
82703 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
82704 VdbeComment((v, "%s", pIdx->zName));
82705
82706 /* Invoke the stat_init() function. The arguments are:
82707 **
82708 ** (1) the number of columns in the index including the rowid,
@@ -82321,12 +82772,25 @@
82772 ** Next csr
82773 ** if !eof(csr) goto next_row;
82774 */
82775 sqlite3VdbeJumpHere(v, aGotoChng[nCol]);
82776 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 
82777 assert( regRowid==(regStat4+2) );
82778 if( HasRowid(pTab) ){
82779 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
82780 }else{
82781 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
82782 int j, k, regKey;
82783 regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
82784 for(j=0; j<pPk->nKeyCol; j++){
82785 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
82786 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
82787 VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
82788 }
82789 sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
82790 sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
82791 }
82792 #endif
82793 assert( regChng==(regStat4+1) );
82794 sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
82795 sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
82796 sqlite3VdbeChangeP5(v, 2+IsStat34);
@@ -82348,26 +82812,27 @@
82812 int regSample = regStat1+3;
82813 int regCol = regStat1+4;
82814 int regSampleRowid = regCol + nCol;
82815 int addrNext;
82816 int addrIsNull;
82817 u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
82818
82819 pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
82820
82821 addrNext = sqlite3VdbeCurrentAddr(v);
82822 callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
82823 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
82824 callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
82825 callStatGet(v, regStat4, STAT_GET_NLT, regLt);
82826 callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
82827 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
82828 #ifdef SQLITE_ENABLE_STAT3
82829 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
82830 pIdx->aiColumn[0], regSample);
82831 #else
82832 for(i=0; i<nCol; i++){
82833 i16 iCol = pIdx->aiColumn[i];
82834 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
82835 }
82836 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
82837 #endif
82838 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0);
@@ -82619,11 +83084,11 @@
83084 pIndex = 0;
83085 }
83086 z = argv[2];
83087
83088 if( pIndex ){
83089 decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
83090 if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0];
83091 }else{
83092 Index fakeIdx;
83093 fakeIdx.szIdxRow = pTable->szTabRow;
83094 decodeIntArray((char*)z, 1, &pTable->nRowEst, &fakeIdx);
@@ -82665,11 +83130,11 @@
83130 static void initAvgEq(Index *pIdx){
83131 if( pIdx ){
83132 IndexSample *aSample = pIdx->aSample;
83133 IndexSample *pFinal = &aSample[pIdx->nSample-1];
83134 int iCol;
83135 for(iCol=0; iCol<pIdx->nKeyCol; iCol++){
83136 int i; /* Used to iterate through samples */
83137 tRowcnt sumEq = 0; /* Sum of the nEq values */
83138 tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
83139 tRowcnt avgEq = 0;
83140 tRowcnt nDLt = pFinal->anDLt[iCol];
@@ -82692,10 +83157,27 @@
83157 pIdx->aAvgEq[iCol] = avgEq;
83158 if( pIdx->nSampleCol==1 ) break;
83159 }
83160 }
83161 }
83162
83163 /*
83164 ** Look up an index by name. Or, if the name of a WITHOUT ROWID table
83165 ** is supplied instead, find the PRIMARY KEY index for that table.
83166 */
83167 static Index *findIndexOrPrimaryKey(
83168 sqlite3 *db,
83169 const char *zName,
83170 const char *zDb
83171 ){
83172 Index *pIdx = sqlite3FindIndex(db, zName, zDb);
83173 if( pIdx==0 ){
83174 Table *pTab = sqlite3FindTable(db, zName, zDb);
83175 if( pTab && !HasRowid(pTab) ) pIdx = sqlite3PrimaryKeyIndex(pTab);
83176 }
83177 return pIdx;
83178 }
83179
83180 /*
83181 ** Load the content from either the sqlite_stat4 or sqlite_stat3 table
83182 ** into the relevant Index.aSample[] arrays.
83183 **
@@ -82742,18 +83224,18 @@
83224 tRowcnt *pSpace;
83225
83226 zIndex = (char *)sqlite3_column_text(pStmt, 0);
83227 if( zIndex==0 ) continue;
83228 nSample = sqlite3_column_int(pStmt, 1);
83229 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
83230 assert( pIdx==0 || bStat3 || pIdx->nSample==0 );
83231 /* Index.nSample is non-zero at this point if data has already been
83232 ** loaded from the stat4 table. In this case ignore stat3 data. */
83233 if( pIdx==0 || pIdx->nSample ) continue;
83234 if( bStat3==0 ){
83235 nIdxCol = pIdx->nKeyCol+1;
83236 nAvgCol = pIdx->nKeyCol;
83237 }
83238 pIdx->nSampleCol = nIdxCol;
83239 nByte = sizeof(IndexSample) * nSample;
83240 nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
83241 nByte += nAvgCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
@@ -82788,11 +83270,11 @@
83270 Index *pIdx; /* Pointer to the index object */
83271 int nCol = 1; /* Number of columns in index */
83272
83273 zIndex = (char *)sqlite3_column_text(pStmt, 0);
83274 if( zIndex==0 ) continue;
83275 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
83276 if( pIdx==0 ) continue;
83277 /* This next condition is true if data has already been loaded from
83278 ** the sqlite_stat4 table. In this case ignore stat3 data. */
83279 nCol = pIdx->nSampleCol;
83280 if( bStat3 && nCol>1 ) continue;
@@ -84144,12 +84626,14 @@
84626 */
84627 static void freeIndex(sqlite3 *db, Index *p){
84628 #ifndef SQLITE_OMIT_ANALYZE
84629 sqlite3DeleteIndexSamples(db, p);
84630 #endif
84631 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
84632 sqlite3ExprDelete(db, p->pPartIdxWhere);
84633 sqlite3DbFree(db, p->zColAff);
84634 if( p->isResized ) sqlite3DbFree(db, p->azColl);
84635 sqlite3DbFree(db, p);
84636 }
84637
84638 /*
84639 ** For the index called zIdxName which is found in the database iDb,
@@ -84403,12 +84887,11 @@
84887 ** writing. The table is opened using cursor 0.
84888 */
84889 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
84890 Vdbe *v = sqlite3GetVdbe(p);
84891 sqlite3TableLock(p, iDb, MASTER_ROOT, 1, SCHEMA_TABLE(iDb));
84892 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5);
 
84893 if( p->nTab==0 ){
84894 p->nTab = 1;
84895 }
84896 }
84897
@@ -84508,10 +84991,31 @@
84991 sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s", zName);
84992 return SQLITE_ERROR;
84993 }
84994 return SQLITE_OK;
84995 }
84996
84997 /*
84998 ** Return the PRIMARY KEY index of a table
84999 */
85000 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
85001 Index *p;
85002 for(p=pTab->pIndex; p && p->autoIndex!=2; p=p->pNext){}
85003 return p;
85004 }
85005
85006 /*
85007 ** Return the column of index pIdx that corresponds to table
85008 ** column iCol. Return -1 if not found.
85009 */
85010 SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index *pIdx, i16 iCol){
85011 int i;
85012 for(i=0; i<pIdx->nColumn; i++){
85013 if( iCol==pIdx->aiColumn[i] ) return i;
85014 }
85015 return -1;
85016 }
85017
85018 /*
85019 ** Begin constructing a new table representation in memory. This is
85020 ** the first of several action routines that get called in response
85021 ** to a CREATE TABLE statement. In particular, this routine is called
@@ -84708,11 +85212,11 @@
85212 if( isView || isVirtual ){
85213 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
85214 }else
85215 #endif
85216 {
85217 pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
85218 }
85219 sqlite3OpenMasterTable(pParse, iDb);
85220 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
85221 sqlite3VdbeAddOp2(v, OP_Null, 0, reg3);
85222 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
@@ -84976,10 +85480,11 @@
85480 int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */
85481 ){
85482 Table *pTab = pParse->pNewTable;
85483 char *zType = 0;
85484 int iCol = -1, i;
85485 int nTerm;
85486 if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
85487 if( pTab->tabFlags & TF_HasPrimaryKey ){
85488 sqlite3ErrorMsg(pParse,
85489 "table \"%s\" has more than one primary key", pTab->zName);
85490 goto primary_key_exit;
@@ -84986,43 +85491,47 @@
85491 }
85492 pTab->tabFlags |= TF_HasPrimaryKey;
85493 if( pList==0 ){
85494 iCol = pTab->nCol - 1;
85495 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
85496 zType = pTab->aCol[iCol].zType;
85497 nTerm = 1;
85498 }else{
85499 nTerm = pList->nExpr;
85500 for(i=0; i<nTerm; i++){
85501 for(iCol=0; iCol<pTab->nCol; iCol++){
85502 if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
85503 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
85504 zType = pTab->aCol[iCol].zType;
85505 break;
85506 }
85507 }
85508 }
85509 }
85510 if( nTerm==1
85511 && zType && sqlite3StrICmp(zType, "INTEGER")==0
85512 && sortOrder==SQLITE_SO_ASC
85513 ){
 
 
 
 
 
85514 pTab->iPKey = iCol;
85515 pTab->keyConf = (u8)onError;
85516 assert( autoInc==0 || autoInc==1 );
85517 pTab->tabFlags |= autoInc*TF_Autoincrement;
85518 if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
85519 }else if( autoInc ){
85520 #ifndef SQLITE_OMIT_AUTOINCREMENT
85521 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
85522 "INTEGER PRIMARY KEY");
85523 #endif
85524 }else{
85525 Vdbe *v = pParse->pVdbe;
85526 Index *p;
85527 if( v ) pParse->addrSkipPK = sqlite3VdbeAddOp0(v, OP_Noop);
85528 p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
85529 0, sortOrder, 0);
85530 if( p ){
85531 p->autoIndex = 2;
85532 if( v ) sqlite3VdbeJumpHere(v, pParse->addrSkipPK);
85533 }
85534 pList = 0;
85535 }
85536
85537 primary_key_exit:
@@ -85075,11 +85584,11 @@
85584 /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
85585 ** then an index may have been created on this column before the
85586 ** collation type was added. Correct this if it is the case.
85587 */
85588 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
85589 assert( pIdx->nKeyCol==1 );
85590 if( pIdx->aiColumn[0]==i ){
85591 pIdx->azColl[0] = p->aCol[i].zColl;
85592 }
85593 }
85594 }else{
@@ -85266,10 +85775,35 @@
85775 assert( k<=n );
85776 }
85777 sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd);
85778 return zStmt;
85779 }
85780
85781 /*
85782 ** Resize an Index object to hold N columns total. Return SQLITE_OK
85783 ** on success and SQLITE_NOMEM on an OOM error.
85784 */
85785 static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){
85786 char *zExtra;
85787 int nByte;
85788 if( pIdx->nColumn>=N ) return SQLITE_OK;
85789 assert( pIdx->isResized==0 );
85790 nByte = (sizeof(char*) + sizeof(i16) + 1)*N;
85791 zExtra = sqlite3DbMallocZero(db, nByte);
85792 if( zExtra==0 ) return SQLITE_NOMEM;
85793 memcpy(zExtra, pIdx->azColl, sizeof(char*)*pIdx->nColumn);
85794 pIdx->azColl = (char**)zExtra;
85795 zExtra += sizeof(char*)*N;
85796 memcpy(zExtra, pIdx->aiColumn, sizeof(i16)*pIdx->nColumn);
85797 pIdx->aiColumn = (i16*)zExtra;
85798 zExtra += sizeof(i16)*N;
85799 memcpy(zExtra, pIdx->aSortOrder, pIdx->nColumn);
85800 pIdx->aSortOrder = (u8*)zExtra;
85801 pIdx->nColumn = N;
85802 pIdx->isResized = 1;
85803 return SQLITE_OK;
85804 }
85805
85806 /*
85807 ** Estimate the total row width for a table.
85808 */
85809 static void estimateTableWidth(Table *pTab){
@@ -85285,19 +85819,151 @@
85819
85820 /*
85821 ** Estimate the average size of a row for an index.
85822 */
85823 static void estimateIndexWidth(Index *pIdx){
85824 unsigned wIndex = 0;
85825 int i;
85826 const Column *aCol = pIdx->pTable->aCol;
85827 for(i=0; i<pIdx->nColumn; i++){
85828 i16 x = pIdx->aiColumn[i];
85829 assert( x<pIdx->pTable->nCol );
85830 wIndex += x<0 ? 1 : aCol[pIdx->aiColumn[i]].szEst;
85831 }
85832 pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
85833 }
85834
85835 /* Return true if value x is found any of the first nCol entries of aiCol[]
85836 */
85837 static int hasColumn(const i16 *aiCol, int nCol, int x){
85838 while( nCol-- > 0 ) if( x==*(aiCol++) ) return 1;
85839 return 0;
85840 }
85841
85842 /*
85843 ** This routine runs at the end of parsing a CREATE TABLE statement that
85844 ** has a WITHOUT ROWID clause. The job of this routine is to convert both
85845 ** internal schema data structures and the generated VDBE code so that they
85846 ** are appropriate for a WITHOUT ROWID table instead of a rowid table.
85847 ** Changes include:
85848 **
85849 ** (1) Convert the OP_CreateTable into an OP_CreateIndex. There is
85850 ** no rowid btree for a WITHOUT ROWID. Instead, the canonical
85851 ** data storage is a covering index btree.
85852 ** (2) Bypass the creation of the sqlite_master table entry
85853 ** for the PRIMARY KEY as the the primary key index is now
85854 ** identified by the sqlite_master table entry of the table itself.
85855 ** (3) Set the Index.tnum of the PRIMARY KEY Index object in the
85856 ** schema to the rootpage from the main table.
85857 ** (4) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
85858 ** (5) Add all table columns to the PRIMARY KEY Index object
85859 ** so that the PRIMARY KEY is a covering index. The surplus
85860 ** columns are part of KeyInfo.nXField and are not used for
85861 ** sorting or lookup or uniqueness checks.
85862 ** (6) Replace the rowid tail on all automatically generated UNIQUE
85863 ** indices with the PRIMARY KEY columns.
85864 */
85865 static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
85866 Index *pIdx;
85867 Index *pPk;
85868 int nPk;
85869 int i, j;
85870 sqlite3 *db = pParse->db;
85871 Vdbe *v = pParse->pVdbe;
85872
85873 /* Convert the OP_CreateTable opcode that would normally create the
85874 ** root-page for the table into a OP_CreateIndex opcode. The index
85875 ** created will become the PRIMARY KEY index.
85876 */
85877 if( pParse->addrCrTab ){
85878 assert( v );
85879 sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
85880 }
85881
85882 /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
85883 ** table entry.
85884 */
85885 if( pParse->addrSkipPK ){
85886 assert( v );
85887 sqlite3VdbeGetOp(v, pParse->addrSkipPK)->opcode = OP_Goto;
85888 }
85889
85890 /* Locate the PRIMARY KEY index. Or, if this table was originally
85891 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
85892 */
85893 if( pTab->iPKey>=0 ){
85894 ExprList *pList;
85895 pList = sqlite3ExprListAppend(pParse, 0, 0);
85896 if( pList==0 ) return;
85897 pList->a[0].zName = sqlite3DbStrDup(pParse->db,
85898 pTab->aCol[pTab->iPKey].zName);
85899 pList->a[0].sortOrder = pParse->iPkSortOrder;
85900 assert( pParse->pNewTable==pTab );
85901 pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
85902 if( pPk==0 ) return;
85903 pPk->autoIndex = 2;
85904 pTab->iPKey = -1;
85905 }else{
85906 pPk = sqlite3PrimaryKeyIndex(pTab);
85907 }
85908 pPk->isCovering = 1;
85909 assert( pPk!=0 );
85910 nPk = pPk->nKeyCol;
85911
85912 /* Make sure every column of the PRIMARY KEY is NOT NULL */
85913 for(i=0; i<nPk; i++){
85914 pTab->aCol[pPk->aiColumn[i]].notNull = 1;
85915 }
85916 pPk->uniqNotNull = 1;
85917
85918 /* The root page of the PRIMARY KEY is the table root page */
85919 pPk->tnum = pTab->tnum;
85920
85921 /* Update the in-memory representation of all UNIQUE indices by converting
85922 ** the final rowid column into one or more columns of the PRIMARY KEY.
85923 */
85924 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
85925 int n;
85926 if( pIdx->autoIndex==2 ) continue;
85927 for(i=n=0; i<nPk; i++){
85928 if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
85929 }
85930 if( n==0 ){
85931 /* This index is a superset of the primary key */
85932 pIdx->nColumn = pIdx->nKeyCol;
85933 continue;
85934 }
85935 if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
85936 for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
85937 if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ){
85938 pIdx->aiColumn[j] = pPk->aiColumn[i];
85939 pIdx->azColl[j] = pPk->azColl[i];
85940 j++;
85941 }
85942 }
85943 assert( pIdx->nColumn>=pIdx->nKeyCol+n );
85944 assert( pIdx->nColumn>=j );
85945 }
85946
85947 /* Add all table columns to the PRIMARY KEY index
85948 */
85949 if( nPk<pTab->nCol ){
85950 if( resizeIndexObject(db, pPk, pTab->nCol) ) return;
85951 for(i=0, j=nPk; i<pTab->nCol; i++){
85952 if( !hasColumn(pPk->aiColumn, j, i) ){
85953 assert( j<pPk->nColumn );
85954 pPk->aiColumn[j] = i;
85955 pPk->azColl[j] = "BINARY";
85956 j++;
85957 }
85958 }
85959 assert( pPk->nColumn==j );
85960 assert( pTab->nCol==j );
85961 }else{
85962 pPk->nColumn = pTab->nCol;
85963 }
85964 }
85965
85966 /*
85967 ** This routine is called to report the final ")" that terminates
85968 ** a CREATE TABLE statement.
85969 **
@@ -85318,11 +85984,12 @@
85984 ** the new table will match the result set of the SELECT.
85985 */
85986 SQLITE_PRIVATE void sqlite3EndTable(
85987 Parse *pParse, /* Parse context */
85988 Token *pCons, /* The ',' token after the last column defn. */
85989 Token *pEnd, /* The ')' before options in the CREATE TABLE */
85990 u8 tabOpts, /* Extra table options. Usually 0. */
85991 Select *pSelect /* Select from a "CREATE ... AS SELECT" */
85992 ){
85993 Table *p; /* The new table */
85994 sqlite3 *db = pParse->db; /* The database connection */
85995 int iDb; /* Database in which the table lives */
@@ -85333,10 +86000,35 @@
86000 }
86001 p = pParse->pNewTable;
86002 if( p==0 ) return;
86003
86004 assert( !db->init.busy || !pSelect );
86005
86006 /* If the db->init.busy is 1 it means we are reading the SQL off the
86007 ** "sqlite_master" or "sqlite_temp_master" table on the disk.
86008 ** So do not write to the disk again. Extract the root page number
86009 ** for the table from the db->init.newTnum field. (The page number
86010 ** should have been put there by the sqliteOpenCb routine.)
86011 */
86012 if( db->init.busy ){
86013 p->tnum = db->init.newTnum;
86014 }
86015
86016 /* Special processing for WITHOUT ROWID Tables */
86017 if( tabOpts & TF_WithoutRowid ){
86018 if( (p->tabFlags & TF_Autoincrement) ){
86019 sqlite3ErrorMsg(pParse,
86020 "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
86021 return;
86022 }
86023 if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
86024 sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
86025 }else{
86026 p->tabFlags |= TF_WithoutRowid;
86027 convertToWithoutRowidTable(pParse, p);
86028 }
86029 }
86030
86031 iDb = sqlite3SchemaToIndex(db, p->pSchema);
86032
86033 #ifndef SQLITE_OMIT_CHECK
86034 /* Resolve names in all CHECK constraint expressions.
@@ -85350,20 +86042,10 @@
86042 estimateTableWidth(p);
86043 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
86044 estimateIndexWidth(pIdx);
86045 }
86046
 
 
 
 
 
 
 
 
 
 
86047 /* If not initializing, then create a record for the new table
86048 ** in the SQLITE_MASTER table of the database.
86049 **
86050 ** If this is a TEMPORARY table, write the entry into the auxiliary
86051 ** file instead of into the main database file.
@@ -85433,11 +86115,13 @@
86115
86116 /* Compute the complete text of the CREATE statement */
86117 if( pSelect ){
86118 zStmt = createTableStmt(db, p);
86119 }else{
86120 Token *pEnd2 = tabOpts ? &pParse->sLastToken : pEnd;
86121 n = (int)(pEnd2->z - pParse->sNameToken.z);
86122 if( pEnd2->z[0]!=';' ) n += pEnd2->n;
86123 zStmt = sqlite3MPrintf(db,
86124 "CREATE %s %.*s", zType2, n, pParse->sNameToken.z
86125 );
86126 }
86127
@@ -85476,11 +86160,11 @@
86160 }
86161 #endif
86162
86163 /* Reparse everything to update our internal data structures */
86164 sqlite3VdbeAddParseSchemaOp(v, iDb,
86165 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
86166 }
86167
86168
86169 /* Add the table to the in-memory representation of the database.
86170 */
@@ -85581,11 +86265,11 @@
86265 while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
86266 sEnd.z = &z[n-1];
86267 sEnd.n = 1;
86268
86269 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
86270 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
86271 return;
86272 }
86273 #endif /* SQLITE_OMIT_VIEW */
86274
86275 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -86036,12 +86720,12 @@
86720 /*
86721 ** This routine is called to create a new foreign key on the table
86722 ** currently under construction. pFromCol determines which columns
86723 ** in the current table point to the foreign key. If pFromCol==0 then
86724 ** connect the key to the last column inserted. pTo is the name of
86725 ** the table referred to (a.k.a the "parent" table). pToCol is a list
86726 ** of tables in the parent pTo table. flags contains all
86727 ** information about the conflict resolution algorithms specified
86728 ** in the ON DELETE, ON UPDATE and ON INSERT clauses.
86729 **
86730 ** An FKey structure is created and added to the table currently
86731 ** under construction in the pParse->pNewTable field.
@@ -86220,41 +86904,43 @@
86904 if( v==0 ) return;
86905 if( memRootPage>=0 ){
86906 tnum = memRootPage;
86907 }else{
86908 tnum = pIndex->tnum;
 
86909 }
86910 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
 
 
 
86911
86912 /* Open the sorter cursor if we are to use one. */
86913 iSorter = pParse->nTab++;
86914 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)
86915 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
86916
86917 /* Open the table. Loop through all rows of the table, inserting index
86918 ** records into the sorter. */
86919 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86920 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
86921 regRecord = sqlite3GetTempReg(pParse);
86922
86923 sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 0, &iPartIdxLabel);
86924 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
86925 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86926 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
86927 sqlite3VdbeJumpHere(v, addr1);
86928 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
86929 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86930 (char *)pKey, P4_KEYINFO);
86931 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86932
86933 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
86934 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
86935 if( pIndex->onError!=OE_None && pKey!=0 ){
86936 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
86937 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
86938 addr2 = sqlite3VdbeCurrentAddr(v);
86939 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86940 pKey->nField - pIndex->nKeyCol);
86941 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
 
86942 }else{
86943 addr2 = sqlite3VdbeCurrentAddr(v);
86944 }
86945 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
86946 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
@@ -86265,10 +86951,45 @@
86951
86952 sqlite3VdbeAddOp1(v, OP_Close, iTab);
86953 sqlite3VdbeAddOp1(v, OP_Close, iIdx);
86954 sqlite3VdbeAddOp1(v, OP_Close, iSorter);
86955 }
86956
86957 /*
86958 ** Allocate heap space to hold an Index object with nCol columns.
86959 **
86960 ** Increase the allocation size to provide an extra nExtra bytes
86961 ** of 8-byte aligned space after the Index object and return a
86962 ** pointer to this extra space in *ppExtra.
86963 */
86964 SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(
86965 sqlite3 *db, /* Database connection */
86966 i16 nCol, /* Total number of columns in the index */
86967 int nExtra, /* Number of bytes of extra space to alloc */
86968 char **ppExtra /* Pointer to the "extra" space */
86969 ){
86970 Index *p; /* Allocated index object */
86971 int nByte; /* Bytes of space for Index object + arrays */
86972
86973 nByte = ROUND8(sizeof(Index)) + /* Index structure */
86974 ROUND8(sizeof(char*)*nCol) + /* Index.azColl */
86975 ROUND8(sizeof(tRowcnt)*(nCol+1) + /* Index.aiRowEst */
86976 sizeof(i16)*nCol + /* Index.aiColumn */
86977 sizeof(u8)*nCol); /* Index.aSortOrder */
86978 p = sqlite3DbMallocZero(db, nByte + nExtra);
86979 if( p ){
86980 char *pExtra = ((char*)p)+ROUND8(sizeof(Index));
86981 p->azColl = (char**)pExtra; pExtra += ROUND8(sizeof(char*)*nCol);
86982 p->aiRowEst = (tRowcnt*)pExtra; pExtra += sizeof(tRowcnt)*(nCol+1);
86983 p->aiColumn = (i16*)pExtra; pExtra += sizeof(i16)*nCol;
86984 p->aSortOrder = (u8*)pExtra;
86985 p->nColumn = nCol;
86986 p->nKeyCol = nCol - 1;
86987 *ppExtra = ((char*)p) + nByte;
86988 }
86989 return p;
86990 }
86991
86992 /*
86993 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
86994 ** and pTblList is the name of the table that is to be indexed. Both will
86995 ** be NULL for a primary key or an index that is created to satisfy a
@@ -86300,22 +87021,22 @@
87021 Table *pTab = 0; /* Table to be indexed */
87022 Index *pIndex = 0; /* The index to be created */
87023 char *zName = 0; /* Name of the index */
87024 int nName; /* Number of characters in zName */
87025 int i, j;
 
87026 DbFixer sFix; /* For assigning database names to pTable */
87027 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
87028 sqlite3 *db = pParse->db;
87029 Db *pDb; /* The specific table containing the indexed database */
87030 int iDb; /* Index of the database that is being written */
87031 Token *pName = 0; /* Unqualified name of the index to create */
87032 struct ExprList_item *pListItem; /* For looping over pList */
87033 const Column *pTabCol; /* A column in the table */
 
87034 int nExtra = 0; /* Space allocated for zExtra[] */
87035 int nExtraCol; /* Number of extra columns needed */
87036 char *zExtra; /* Extra space after the Index object */
87037 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
87038
87039 assert( pParse->nErr==0 ); /* Never called with prior errors */
87040 if( db->mallocFailed || IN_DECLARE_VTAB ){
87041 goto exit_create_index;
87042 }
@@ -86363,10 +87084,11 @@
87084 sqlite3ErrorMsg(pParse,
87085 "cannot create a TEMP index on non-TEMP table \"%s\"",
87086 pTab->zName);
87087 goto exit_create_index;
87088 }
87089 if( !HasRowid(pTab) ) pPk = sqlite3PrimaryKeyIndex(pTab);
87090 }else{
87091 assert( pName==0 );
87092 assert( pStart==0 );
87093 pTab = pParse->pNewTable;
87094 if( !pTab ) goto exit_create_index;
@@ -86458,15 +87180,14 @@
87180 /* If pList==0, it means this routine was called to make a primary
87181 ** key out of the last column added to the table under construction.
87182 ** So create a fake list to simulate this.
87183 */
87184 if( pList==0 ){
 
 
87185 pList = sqlite3ExprListAppend(pParse, 0, 0);
87186 if( pList==0 ) goto exit_create_index;
87187 pList->a[0].zName = sqlite3DbStrDup(pParse->db,
87188 pTab->aCol[pTab->nCol-1].zName);
87189 pList->a[0].sortOrder = (u8)sortOrder;
87190 }
87191
87192 /* Figure out how many bytes of space are required to store explicitly
87193 ** specified collation sequence names.
@@ -86481,40 +87202,27 @@
87202
87203 /*
87204 ** Allocate the index structure.
87205 */
87206 nName = sqlite3Strlen30(zName);
87207 nExtraCol = pPk ? pPk->nKeyCol : 1;
87208 pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
87209 nName + nExtra + 1, &zExtra);
 
 
 
 
 
 
 
87210 if( db->mallocFailed ){
87211 goto exit_create_index;
87212 }
 
 
 
 
87213 assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowEst) );
87214 assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
87215 pIndex->zName = zExtra;
87216 zExtra += nName + 1;
 
 
87217 memcpy(pIndex->zName, zName, nName+1);
87218 pIndex->pTable = pTab;
 
87219 pIndex->onError = (u8)onError;
87220 pIndex->uniqNotNull = onError!=OE_None;
87221 pIndex->autoIndex = (u8)(pName==0);
87222 pIndex->pSchema = db->aDb[iDb].pSchema;
87223 pIndex->nKeyCol = pList->nExpr;
87224 if( pPIWhere ){
87225 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
87226 pIndex->pPartIdxWhere = pPIWhere;
87227 pPIWhere = 0;
87228 }
@@ -86550,11 +87258,12 @@
87258 sqlite3ErrorMsg(pParse, "table %s has no column named %s",
87259 pTab->zName, zColName);
87260 pParse->checkSchema = 1;
87261 goto exit_create_index;
87262 }
87263 assert( pTab->nCol<=0x7fff && j<=0x7fff );
87264 pIndex->aiColumn[i] = (i16)j;
87265 if( pListItem->pExpr ){
87266 int nColl;
87267 assert( pListItem->pExpr->op==TK_COLLATE );
87268 zColl = pListItem->pExpr->u.zToken;
87269 nColl = sqlite3Strlen30(zColl) + 1;
@@ -86573,10 +87282,27 @@
87282 pIndex->azColl[i] = zColl;
87283 requestedSortOrder = pListItem->sortOrder & sortOrderMask;
87284 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
87285 if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
87286 }
87287 if( pPk ){
87288 for(j=0; j<pPk->nKeyCol; j++){
87289 int x = pPk->aiColumn[j];
87290 if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
87291 pIndex->nColumn--;
87292 }else{
87293 pIndex->aiColumn[i] = x;
87294 pIndex->azColl[i] = pPk->azColl[j];
87295 pIndex->aSortOrder[i] = pPk->aSortOrder[j];
87296 i++;
87297 }
87298 }
87299 assert( i==pIndex->nColumn );
87300 }else{
87301 pIndex->aiColumn[i] = -1;
87302 pIndex->azColl[i] = "BINARY";
87303 }
87304 sqlite3DefaultRowEst(pIndex);
87305 if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
87306
87307 if( pTab==pParse->pNewTable ){
87308 /* This routine has been called to create an automatic index as a
@@ -86605,20 +87331,20 @@
87331 int k;
87332 assert( pIdx->onError!=OE_None );
87333 assert( pIdx->autoIndex );
87334 assert( pIndex->onError!=OE_None );
87335
87336 if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
87337 for(k=0; k<pIdx->nKeyCol; k++){
87338 const char *z1;
87339 const char *z2;
87340 if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
87341 z1 = pIdx->azColl[k];
87342 z2 = pIndex->azColl[k];
87343 if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
87344 }
87345 if( k==pIdx->nKeyCol ){
87346 if( pIdx->onError!=pIndex->onError ){
87347 /* This constraint creates the same index as a previous
87348 ** constraint specified somewhere in the CREATE TABLE statement.
87349 ** However the ON CONFLICT clauses are different. If both this
87350 ** constraint and the previous equivalent constraint have explicit
@@ -86656,26 +87382,24 @@
87382 if( pTblName!=0 ){
87383 pIndex->tnum = db->init.newTnum;
87384 }
87385 }
87386
87387 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
87388 ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
87389 ** emit code to allocate the index rootpage on disk and make an entry for
87390 ** the index in the sqlite_master table and populate the index with
87391 ** content. But, do not do this if we are simply reading the sqlite_master
87392 ** table to parse the schema, or if this index is the PRIMARY KEY index
87393 ** of a WITHOUT ROWID table.
87394 **
87395 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
87396 ** or UNIQUE index in a CREATE TABLE statement. Since the table
 
 
87397 ** has just been created, it contains no data and the index initialization
87398 ** step can be skipped.
87399 */
87400 else if( pParse->nErr==0 && (HasRowid(pTab) || pTblName!=0) ){
87401 Vdbe *v;
87402 char *zStmt;
87403 int iMem = ++pParse->nMem;
87404
87405 v = sqlite3GetVdbe(pParse);
@@ -86783,16 +87507,16 @@
87507 tRowcnt n;
87508 assert( a!=0 );
87509 a[0] = pIdx->pTable->nRowEst;
87510 if( a[0]<10 ) a[0] = 10;
87511 n = 10;
87512 for(i=1; i<=pIdx->nKeyCol; i++){
87513 a[i] = n;
87514 if( n>5 ) n--;
87515 }
87516 if( pIdx->onError!=OE_None ){
87517 a[pIdx->nKeyCol] = 1;
87518 }
87519 }
87520
87521 /*
87522 ** This routine will drop an existing named index. This routine
@@ -87476,18 +88200,71 @@
88200 SQLITE_PRIVATE void sqlite3HaltConstraint(
88201 Parse *pParse, /* Parsing context */
88202 int errCode, /* extended error code */
88203 int onError, /* Constraint type */
88204 char *p4, /* Error message */
88205 i8 p4type, /* P4_STATIC or P4_TRANSIENT */
88206 u8 p5Errmsg /* P5_ErrMsg type */
88207 ){
88208 Vdbe *v = sqlite3GetVdbe(pParse);
88209 assert( (errCode&0xff)==SQLITE_CONSTRAINT );
88210 if( onError==OE_Abort ){
88211 sqlite3MayAbort(pParse);
88212 }
88213 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
88214 if( p5Errmsg ) sqlite3VdbeChangeP5(v, p5Errmsg);
88215 }
88216
88217 /*
88218 ** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation.
88219 */
88220 SQLITE_PRIVATE void sqlite3UniqueConstraint(
88221 Parse *pParse, /* Parsing context */
88222 int onError, /* Constraint type */
88223 Index *pIdx /* The index that triggers the constraint */
88224 ){
88225 char *zErr;
88226 int j;
88227 StrAccum errMsg;
88228 Table *pTab = pIdx->pTable;
88229
88230 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
88231 errMsg.db = pParse->db;
88232 for(j=0; j<pIdx->nKeyCol; j++){
88233 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
88234 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
88235 sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
88236 sqlite3StrAccumAppend(&errMsg, ".", 1);
88237 sqlite3StrAccumAppend(&errMsg, zCol, -1);
88238 }
88239 zErr = sqlite3StrAccumFinish(&errMsg);
88240 sqlite3HaltConstraint(pParse,
88241 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
88242 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
88243 }
88244
88245
88246 /*
88247 ** Code an OP_Halt due to non-unique rowid.
88248 */
88249 SQLITE_PRIVATE void sqlite3RowidConstraint(
88250 Parse *pParse, /* Parsing context */
88251 int onError, /* Conflict resolution algorithm */
88252 Table *pTab /* The table with the non-unique rowid */
88253 ){
88254 char *zMsg;
88255 int rc;
88256 if( pTab->iPKey>=0 ){
88257 zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
88258 pTab->aCol[pTab->iPKey].zName);
88259 rc = SQLITE_CONSTRAINT_PRIMARYKEY;
88260 }else{
88261 zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
88262 rc = SQLITE_CONSTRAINT_ROWID;
88263 }
88264 sqlite3HaltConstraint(pParse, rc, onError, zMsg, P4_DYNAMIC,
88265 P5_ConstraintUnique);
88266 }
88267
88268 /*
88269 ** Check to see if pIndex uses the collating sequence pColl. Return
88270 ** true if it does and false if it does not.
@@ -87496,12 +88273,12 @@
88273 static int collationMatch(const char *zColl, Index *pIndex){
88274 int i;
88275 assert( zColl!=0 );
88276 for(i=0; i<pIndex->nColumn; i++){
88277 const char *z = pIndex->azColl[i];
88278 assert( z!=0 || pIndex->aiColumn[i]<0 );
88279 if( pIndex->aiColumn[i]>=0 && 0==sqlite3StrICmp(z, zColl) ){
88280 return 1;
88281 }
88282 }
88283 return 0;
88284 }
@@ -87616,39 +88393,53 @@
88393 sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
88394 }
88395 #endif
88396
88397 /*
88398 ** Return a KeyInfo structure that is appropriate for the given Index.
88399 **
88400 ** The KeyInfo structure for an index is cached in the Index object.
88401 ** So there might be multiple references to the returned pointer. The
88402 ** caller should not try to modify the KeyInfo object.
88403 **
88404 ** The caller should invoke sqlite3KeyInfoUnref() on the returned object
88405 ** when it has finished using it.
88406 */
88407 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
88408 if( pParse->nErr ) return 0;
88409 #ifndef SQLITE_OMIT_SHARED_CACHE
88410 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){
88411 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
88412 pIdx->pKeyInfo = 0;
88413 }
88414 #endif
88415 if( pIdx->pKeyInfo==0 ){
88416 int i;
88417 int nCol = pIdx->nColumn;
88418 int nKey = pIdx->nKeyCol;
88419 KeyInfo *pKey;
88420 if( pIdx->uniqNotNull ){
88421 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
88422 }else{
88423 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
88424 }
88425 if( pKey ){
88426 assert( sqlite3KeyInfoIsWriteable(pKey) );
88427 for(i=0; i<nCol; i++){
88428 char *zColl = pIdx->azColl[i];
88429 if( NEVER(zColl==0) ) zColl = "BINARY";
88430 pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
88431 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
88432 }
88433 if( pParse->nErr ){
88434 sqlite3KeyInfoUnref(pKey);
88435 }else{
88436 pIdx->pKeyInfo = pKey;
88437 }
88438 }
88439 }
88440 return sqlite3KeyInfoRef(pIdx->pKeyInfo);
88441 }
88442
88443 /************** End of build.c ***********************************************/
88444 /************** Begin file callback.c ****************************************/
88445 /*
@@ -88264,11 +89055,11 @@
89055 SrcList *pSrc, /* the FROM clause -- which tables to scan */
89056 Expr *pWhere, /* The WHERE clause. May be null */
89057 ExprList *pOrderBy, /* The ORDER BY clause. May be null */
89058 Expr *pLimit, /* The LIMIT clause. May be null */
89059 Expr *pOffset, /* The OFFSET clause. May be null */
89060 char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
89061 ){
89062 Expr *pWhereRowid = NULL; /* WHERE rowid .. */
89063 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
89064 Expr *pSelectRowid = NULL; /* SELECT rowid ... */
89065 ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */
@@ -88339,11 +89130,12 @@
89130 sqlite3ExprListDelete(pParse->db, pOrderBy);
89131 sqlite3ExprDelete(pParse->db, pLimit);
89132 sqlite3ExprDelete(pParse->db, pOffset);
89133 return 0;
89134 }
89135 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */
89136 /* && !defined(SQLITE_OMIT_SUBQUERY) */
89137
89138 /*
89139 ** Generate code for a DELETE FROM statement.
89140 **
89141 ** DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
@@ -88360,11 +89152,13 @@
89152 const char *zDb; /* Name of database holding pTab */
89153 int end, addr = 0; /* A couple addresses of generated code */
89154 int i; /* Loop counter */
89155 WhereInfo *pWInfo; /* Information about the WHERE clause */
89156 Index *pIdx; /* For looping over indices of the table */
89157 int iTabCur; /* Cursor number for the table */
89158 int iDataCur; /* VDBE cursor for the canonical data source */
89159 int iIdxCur; /* Cursor number of the first index */
89160 sqlite3 *db; /* Main database structure */
89161 AuthContext sContext; /* Authorization context */
89162 NameContext sNC; /* Name context to resolve expressions in */
89163 int iDb; /* Database number */
89164 int memCnt = -1; /* Memory cell used for change counting */
@@ -88425,11 +89219,11 @@
89219 assert(!isView || pTrigger);
89220
89221 /* Assign cursor number to the table and all its indices.
89222 */
89223 assert( pTabList->nSrc==1 );
89224 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
89225 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
89226 pParse->nTab++;
89227 }
89228
89229 /* Start the view context
@@ -88450,11 +89244,12 @@
89244 /* If we are trying to delete from a view, realize that view into
89245 ** a ephemeral table.
89246 */
89247 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
89248 if( isView ){
89249 sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur);
89250 iDataCur = iIdxCur = iTabCur;
89251 }
89252 #endif
89253
89254 /* Resolve the column names in the WHERE clause.
89255 */
@@ -88481,22 +89276,78 @@
89276 if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab)
89277 && 0==sqlite3FkRequired(pParse, pTab, 0, 0)
89278 ){
89279 assert( !isView );
89280 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
89281 if( HasRowid(pTab) ){
89282 sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
89283 pTab->zName, P4_STATIC);
89284 }
89285 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
89286 assert( pIdx->pSchema==pTab->pSchema );
89287 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
89288 }
89289 }else
89290 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
89291 if( !HasRowid(pTab) ){
89292 /* There is a WHERE clause on a WITHOUT ROWID table.
89293 */
89294 Index *pPk; /* The PRIMARY KEY index on the table */
89295 int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
89296 int iEph; /* Ephemeral table holding all primary key values */
89297 int iKey; /* Key value inserting into iEph */
89298 i16 nPk; /* Number of components of the PRIMARY KEY */
89299
89300 pPk = sqlite3PrimaryKeyIndex(pTab);
89301 assert( pPk!=0 );
89302 nPk = pPk->nKeyCol;
89303 iPk = pParse->nMem+1;
89304 pParse->nMem += nPk;
89305 iKey = ++pParse->nMem;
89306 iEph = pParse->nTab++;
89307
89308 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
89309 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89310 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 0, 0);
89311 if( pWInfo==0 ) goto delete_from_cleanup;
89312 for(i=0; i<nPk; i++){
89313 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, pPk->aiColumn[i],iPk+i);
89314 }
89315 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89316 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89317 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, iKey);
89318 if( db->flags & SQLITE_CountRows ){
89319 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89320 }
89321 sqlite3WhereEnd(pWInfo);
89322
89323 /* Open cursors for all indices of the table.
89324 */
89325 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite,
89326 iTabCur, &iDataCur, &iIdxCur);
89327
89328 /* Loop over the primary keys to be deleted. */
89329 addr = sqlite3VdbeAddOp1(v, OP_Rewind, iEph);
89330 sqlite3VdbeAddOp2(v, OP_RowKey, iEph, iPk);
89331
89332 /* Delete the row */
89333 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89334 iPk, 0, 1, OE_Default, 0);
89335
89336 /* End of the delete loop */
89337 sqlite3VdbeAddOp2(v, OP_Next, iEph, addr+1);
89338 sqlite3VdbeJumpHere(v, addr);
89339
89340 /* Close the cursors open on the table and its indexes. */
89341 assert( iDataCur>=iIdxCur );
89342 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89343 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur+i);
89344 }
89345 }else{
89346 /* There is a WHERE clause on a rowid table. Run a loop that extracts
89347 ** all rowids to be deleted into a RowSet.
89348 */
89349 int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
89350 int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
89351 int regRowid; /* Actual register containing rowids */
89352
89353 /* Collect rowids of every row to be deleted.
@@ -88504,11 +89355,11 @@
89355 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
89356 pWInfo = sqlite3WhereBegin(
89357 pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
89358 );
89359 if( pWInfo==0 ) goto delete_from_cleanup;
89360 regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iRowid, 0);
89361 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
89362 if( db->flags & SQLITE_CountRows ){
89363 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89364 }
89365 sqlite3WhereEnd(pWInfo);
@@ -88521,11 +89372,14 @@
89372 /* Unless this is a view, open cursors for the table we are
89373 ** deleting from and all its indices. If this is a view, then the
89374 ** only effect this statement has is to fire the INSTEAD OF
89375 ** triggers. */
89376 if( !isView ){
89377 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur,
89378 &iDataCur, &iIdxCur);
89379 assert( iDataCur==iTabCur );
89380 assert( iIdxCur==iDataCur+1 );
89381 }
89382
89383 addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);
89384
89385 /* Delete the row */
@@ -88538,23 +89392,24 @@
89392 sqlite3MayAbort(pParse);
89393 }else
89394 #endif
89395 {
89396 int count = (pParse->nested==0); /* True to count changes */
89397 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89398 iRowid, 1, count, OE_Default, 0);
89399 }
89400
89401 /* End of the delete loop */
89402 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
89403 sqlite3VdbeResolveLabel(v, end);
89404
89405 /* Close the cursors open on the table and its indexes. */
89406 if( !isView && !IsVirtual(pTab) ){
89407 sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
89408 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89409 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
89410 }
 
89411 }
89412 }
89413
89414 /* Update the sqlite_sequence table by storing the content of the
89415 ** maximum rowid counter values recorded while inserting into
@@ -88590,48 +89445,56 @@
89445 #undef pTrigger
89446 #endif
89447
89448 /*
89449 ** This routine generates VDBE code that causes a single row of a
89450 ** single table to be deleted. Both the original table entry and
89451 ** all indices are removed.
89452 **
89453 ** Preconditions:
 
89454 **
89455 ** 1. iDataCur is an open cursor on the btree that is the canonical data
89456 ** store for the table. (This will be either the table itself,
89457 ** in the case of a rowid table, or the PRIMARY KEY index in the case
89458 ** of a WITHOUT ROWID table.)
89459 **
89460 ** 2. Read/write cursors for all indices of pTab must be open as
89461 ** cursor number iIdxCur+i for the i-th index.
89462 **
89463 ** 3. The primary key for the row to be deleted must be stored in a
89464 ** sequence of nPk memory cells starting at iPk. If nPk==0 that means
89465 ** that a search record formed from OP_MakeRecord is contained in the
89466 ** single memory location iPk.
 
89467 */
89468 SQLITE_PRIVATE void sqlite3GenerateRowDelete(
89469 Parse *pParse, /* Parsing context */
89470 Table *pTab, /* Table containing the row to be deleted */
 
 
 
89471 Trigger *pTrigger, /* List of triggers to (potentially) fire */
89472 int iDataCur, /* Cursor from which column data is extracted */
89473 int iIdxCur, /* First index cursor */
89474 int iPk, /* First memory cell containing the PRIMARY KEY */
89475 i16 nPk, /* Number of PRIMARY KEY memory cells */
89476 u8 count, /* If non-zero, increment the row change counter */
89477 u8 onconf, /* Default ON CONFLICT policy for triggers */
89478 u8 bNoSeek /* iDataCur is already pointing to the row to delete */
89479 ){
89480 Vdbe *v = pParse->pVdbe; /* Vdbe */
89481 int iOld = 0; /* First register in OLD.* array */
89482 int iLabel; /* Label resolved to end of generated code */
89483 u8 opSeek; /* Seek opcode */
89484
89485 /* Vdbe is guaranteed to have been allocated by this stage. */
89486 assert( v );
89487 VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
89488 iDataCur, iIdxCur, iPk, (int)nPk));
89489
89490 /* Seek cursor iCur to the row to delete. If this row no longer exists
89491 ** (this can happen if a trigger program has already deleted it), do
89492 ** not attempt to delete it or fire any DELETE triggers. */
89493 iLabel = sqlite3VdbeMakeLabel(v);
89494 opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89495 if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89496
89497 /* If there are any triggers to fire, allocate a range of registers to
89498 ** use for the old.* references in the triggers. */
89499 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89500 u32 mask; /* Mask of OLD.* columns in use */
@@ -88646,14 +89509,14 @@
89509 iOld = pParse->nMem+1;
89510 pParse->nMem += (1 + pTab->nCol);
89511
89512 /* Populate the OLD.* pseudo-table register array. These values will be
89513 ** used by any BEFORE and AFTER triggers that exist. */
89514 sqlite3VdbeAddOp2(v, OP_Copy, iPk, iOld);
89515 for(iCol=0; iCol<pTab->nCol; iCol++){
89516 if( mask==0xffffffff || mask&(1<<iCol) ){
89517 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
89518 }
89519 }
89520
89521 /* Invoke BEFORE DELETE trigger programs. */
89522 sqlite3CodeRowTrigger(pParse, pTrigger,
@@ -88662,11 +89525,11 @@
89525
89526 /* Seek the cursor to the row to be deleted again. It may be that
89527 ** the BEFORE triggers coded above have already removed the row
89528 ** being deleted. Do not attempt to delete the row a second time, and
89529 ** do not fire AFTER triggers. */
89530 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89531
89532 /* Do FK processing. This call checks that any FK constraints that
89533 ** refer to this table (i.e. constraints attached to other tables)
89534 ** are not violated by deleting this row. */
89535 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -88674,12 +89537,12 @@
89537
89538 /* Delete the index and table entries. Skip this step if pTab is really
89539 ** a view (in which case the only effect of the DELETE statement is to
89540 ** fire the INSTEAD OF triggers). */
89541 if( pTab->pSelect==0 ){
89542 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
89543 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
89544 if( count ){
89545 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
89546 }
89547 }
89548
@@ -88695,53 +89558,65 @@
89558
89559 /* Jump here if the row had already been deleted before any BEFORE
89560 ** trigger programs were invoked. Or if a trigger program throws a
89561 ** RAISE(IGNORE) exception. */
89562 sqlite3VdbeResolveLabel(v, iLabel);
89563 VdbeModuleComment((v, "END: GenRowDel()"));
89564 }
89565
89566 /*
89567 ** This routine generates VDBE code that causes the deletion of all
89568 ** index entries associated with a single row of a single table, pTab
89569 **
89570 ** Preconditions:
 
89571 **
89572 ** 1. A read/write cursor "iDataCur" must be open on the canonical storage
89573 ** btree for the table pTab. (This will be either the table itself
89574 ** for rowid tables or to the primary key index for WITHOUT ROWID
89575 ** tables.)
89576 **
89577 ** 2. Read/write cursors for all indices of pTab must be open as
89578 ** cursor number iIdxCur+i for the i-th index. (The pTab->pIndex
89579 ** index is the 0-th index.)
89580 **
89581 ** 3. The "iDataCur" cursor must be already be positioned on the row
89582 ** that is to be deleted.
89583 */
89584 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(
89585 Parse *pParse, /* Parsing and code generating context */
89586 Table *pTab, /* Table containing the row to be deleted */
89587 int iDataCur, /* Cursor of table holding data. */
89588 int iIdxCur, /* First index cursor */
89589 int *aRegIdx /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */
89590 ){
89591 int i; /* Index loop counter */
89592 int r1; /* Register holding an index key */
89593 int iPartIdxLabel; /* Jump destination for skipping partial index entries */
89594 Index *pIdx; /* Current index */
89595 Vdbe *v; /* The prepared statement under construction */
89596 Index *pPk; /* PRIMARY KEY index, or NULL for rowid tables */
89597
89598 v = pParse->pVdbe;
89599 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
89600 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89601 assert( iIdxCur+i!=iDataCur || pPk==pIdx );
89602 if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
89603 if( pIdx==pPk ) continue;
89604 VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));
89605 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, &iPartIdxLabel);
89606 sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1,
89607 pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn);
89608 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
89609 }
89610 }
89611
89612 /*
89613 ** Generate code that will assemble an index key and stores it in register
89614 ** regOut. The key with be for index pIdx which is an index on pTab.
89615 ** iCur is the index of a cursor open on the pTab table and pointing to
89616 ** the entry that needs indexing. If pTab is a WITHOUT ROWID table, then
89617 ** iCur must be the cursor of the PRIMARY KEY index.
89618 **
89619 ** Return a register number which is the first in a block of
89620 ** registers that holds the elements of the index key. The
89621 ** block of registers has already been deallocated by the time
89622 ** this routine returns.
@@ -88754,56 +89629,58 @@
89629 ** sqlite3VdbeResolveLabel().
89630 */
89631 SQLITE_PRIVATE int sqlite3GenerateIndexKey(
89632 Parse *pParse, /* Parsing context */
89633 Index *pIdx, /* The index for which to generate a key */
89634 int iDataCur, /* Cursor number from which to take column data */
89635 int regOut, /* Put the new key into this register if not 0 */
89636 int prefixOnly, /* Compute only a unique prefix of the key */
89637 int *piPartIdxLabel /* OUT: Jump to this label to skip partial index */
89638 ){
89639 Vdbe *v = pParse->pVdbe;
89640 int j;
89641 Table *pTab = pIdx->pTable;
89642 int regBase;
89643 int nCol;
89644 Index *pPk;
89645
89646 if( piPartIdxLabel ){
89647 if( pIdx->pPartIdxWhere ){
89648 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
89649 pParse->iPartIdxTab = iDataCur;
89650 sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
89651 SQLITE_JUMPIFNULL);
89652 }else{
89653 *piPartIdxLabel = 0;
89654 }
89655 }
89656 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
89657 regBase = sqlite3GetTempRange(pParse, nCol);
89658 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
89659 for(j=0; j<nCol; j++){
89660 i16 idx = pIdx->aiColumn[j];
89661 if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx);
89662 if( idx<0 || idx==pTab->iPKey ){
89663 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j);
89664 }else{
89665 sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j);
89666 sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1);
89667 }
89668 }
89669 if( regOut ){
89670 const char *zAff;
89671 if( pTab->pSelect
89672 || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
89673 ){
89674 zAff = 0;
89675 }else{
89676 zAff = sqlite3IndexAffinityStr(v, pIdx);
89677 }
89678 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
89679 sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
89680 }
89681 sqlite3ReleaseTempRange(pParse, regBase, nCol);
89682 return regBase;
89683 }
89684
89685 /************** End of delete.c **********************************************/
89686 /************** Begin file func.c ********************************************/
@@ -88943,12 +89820,12 @@
89820 switch( sqlite3_value_type(argv[0]) ){
89821 case SQLITE_INTEGER: {
89822 i64 iVal = sqlite3_value_int64(argv[0]);
89823 if( iVal<0 ){
89824 if( (iVal<<1)==0 ){
89825 /* IMP: R-31676-45509 If X is the integer -9223372036854775808
89826 ** then abs(X) throws an integer overflow error since there is no
89827 ** equivalent positive 64-bit two complement value. */
89828 sqlite3_result_error(context, "integer overflow", -1);
89829 return;
89830 }
89831 iVal = -iVal;
@@ -90755,11 +91632,11 @@
91632 if( !aiCol ) return 1;
91633 *paiCol = aiCol;
91634 }
91635
91636 for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
91637 if( pIdx->nKeyCol==nCol && pIdx->onError!=OE_None ){
91638 /* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
91639 ** of columns. If each indexed column corresponds to a foreign key
91640 ** column of pFKey, then this index is a winner. */
91641
91642 if( zKey==0 ){
@@ -90778,11 +91655,11 @@
91655 ** map to an explicit list of columns in table pParent. Check if this
91656 ** index matches those columns. Also, check that the index uses
91657 ** the default collation sequences for each column. */
91658 int i, j;
91659 for(i=0; i<nCol; i++){
91660 i16 iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
91661 char *zDfltColl; /* Def. collation for column */
91662 char *zIdxCol; /* Name of indexed column */
91663
91664 /* If the index uses a collation sequence that is different from
91665 ** the default collation sequence for the column, this index is
@@ -90909,14 +91786,13 @@
91786 sqlite3ReleaseTempReg(pParse, regTemp);
91787 }else{
91788 int nCol = pFKey->nCol;
91789 int regTemp = sqlite3GetTempRange(pParse, nCol);
91790 int regRec = sqlite3GetTempReg(pParse);
 
91791
91792 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
91793 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
91794 for(i=0; i<nCol; i++){
91795 sqlite3VdbeAddOp2(v, OP_Copy, aiCol[i]+1+regData, regTemp+i);
91796 }
91797
91798 /* If the parent table is the same as the child table, and we are about
@@ -90962,12 +91838,11 @@
91838 ** one row into the table, raise a constraint immediately instead of
91839 ** incrementing a counter. This is necessary as the VM code is being
91840 ** generated for will not open a statement transaction. */
91841 assert( nIncr==1 );
91842 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
91843 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
 
91844 }else{
91845 if( nIncr>0 && pFKey->isDeferred==0 ){
91846 sqlite3ParseToplevel(pParse)->mayAbort = 1;
91847 }
91848 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
@@ -90975,10 +91850,66 @@
91850
91851 sqlite3VdbeResolveLabel(v, iOk);
91852 sqlite3VdbeAddOp1(v, OP_Close, iCur);
91853 }
91854
91855
91856 /*
91857 ** Return an Expr object that refers to a memory register corresponding
91858 ** to column iCol of table pTab.
91859 **
91860 ** regBase is the first of an array of register that contains the data
91861 ** for pTab. regBase itself holds the rowid. regBase+1 holds the first
91862 ** column. regBase+2 holds the second column, and so forth.
91863 */
91864 static Expr *exprTableRegister(
91865 Parse *pParse, /* Parsing and code generating context */
91866 Table *pTab, /* The table whose content is at r[regBase]... */
91867 int regBase, /* Contents of table pTab */
91868 i16 iCol /* Which column of pTab is desired */
91869 ){
91870 Expr *pExpr;
91871 Column *pCol;
91872 const char *zColl;
91873 sqlite3 *db = pParse->db;
91874
91875 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
91876 if( pExpr ){
91877 if( iCol>=0 && iCol!=pTab->iPKey ){
91878 pCol = &pTab->aCol[iCol];
91879 pExpr->iTable = regBase + iCol + 1;
91880 pExpr->affinity = pCol->affinity;
91881 zColl = pCol->zColl;
91882 if( zColl==0 ) zColl = db->pDfltColl->zName;
91883 pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl);
91884 }else{
91885 pExpr->iTable = regBase;
91886 pExpr->affinity = SQLITE_AFF_INTEGER;
91887 }
91888 }
91889 return pExpr;
91890 }
91891
91892 /*
91893 ** Return an Expr object that refers to column iCol of table pTab which
91894 ** has cursor iCur.
91895 */
91896 static Expr *exprTableColumn(
91897 sqlite3 *db, /* The database connection */
91898 Table *pTab, /* The table whose column is desired */
91899 int iCursor, /* The open cursor on the table */
91900 i16 iCol /* The column that is wanted */
91901 ){
91902 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
91903 if( pExpr ){
91904 pExpr->pTab = pTab;
91905 pExpr->iTable = iCursor;
91906 pExpr->iColumn = iCol;
91907 }
91908 return pExpr;
91909 }
91910
91911 /*
91912 ** This function is called to generate code executed when a row is deleted
91913 ** from the parent table of foreign key constraint pFKey and, if pFKey is
91914 ** deferred, when a row is inserted into the same table. When generating
91915 ** code for an SQL UPDATE operation, this function may be called twice -
@@ -90990,31 +91921,31 @@
91921 **
91922 ** Operation | FK type | Action taken
91923 ** --------------------------------------------------------------------------
91924 ** DELETE immediate Increment the "immediate constraint counter".
91925 ** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
91926 ** throw a "FOREIGN KEY constraint failed" exception.
91927 **
91928 ** INSERT immediate Decrement the "immediate constraint counter".
91929 **
91930 ** DELETE deferred Increment the "deferred constraint counter".
91931 ** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
91932 ** throw a "FOREIGN KEY constraint failed" exception.
91933 **
91934 ** INSERT deferred Decrement the "deferred constraint counter".
91935 **
91936 ** These operations are identified in the comment at the top of this file
91937 ** (fkey.c) as "I.2" and "D.2".
91938 */
91939 static void fkScanChildren(
91940 Parse *pParse, /* Parse context */
91941 SrcList *pSrc, /* The child table to be scanned */
91942 Table *pTab, /* The parent table */
91943 Index *pIdx, /* Index on parent covering the foreign key */
91944 FKey *pFKey, /* The foreign key linking pSrc to pTab */
91945 int *aiCol, /* Map from pIdx cols to child table cols */
91946 int regData, /* Parent row data starts here */
91947 int nIncr /* Amount to increment deferred counter by */
91948 ){
91949 sqlite3 *db = pParse->db; /* Database handle */
91950 int i; /* Iterator variable */
91951 Expr *pWhere = 0; /* WHERE clause to scan with */
@@ -91021,11 +91952,13 @@
91952 NameContext sNameContext; /* Context used to resolve WHERE clause */
91953 WhereInfo *pWInfo; /* Context used by sqlite3WhereXXX() */
91954 int iFkIfZero = 0; /* Address of OP_FkIfZero */
91955 Vdbe *v = sqlite3GetVdbe(pParse);
91956
91957 assert( pIdx==0 || pIdx->pTable==pTab );
91958 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
91959 assert( pIdx!=0 || pFKey->nCol==1 );
91960
91961 if( nIncr<0 ){
91962 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
91963 }
91964
@@ -91039,59 +91972,55 @@
91972 */
91973 for(i=0; i<pFKey->nCol; i++){
91974 Expr *pLeft; /* Value from parent table row */
91975 Expr *pRight; /* Column ref to child table */
91976 Expr *pEq; /* Expression (pLeft = pRight) */
91977 i16 iCol; /* Index of column in child table */
91978 const char *zCol; /* Name of column in child table */
91979
91980 iCol = pIdx ? pIdx->aiColumn[i] : -1;
91981 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91982 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
91983 assert( iCol>=0 );
91984 zCol = pFKey->pFrom->aCol[iCol].zName;
91985 pRight = sqlite3Expr(db, TK_ID, zCol);
91986 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
91987 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
91988 }
91989
91990 /* If the child table is the same as the parent table, then add terms
91991 ** to the WHERE clause that prevent this entry from being scanned.
91992 ** The added WHERE clause terms are like this:
91993 **
91994 ** $current_rowid!=rowid
91995 ** NOT( $current_a==a AND $current_b==b AND ... )
91996 **
91997 ** The first form is used for rowid tables. The second form is used
91998 ** for WITHOUT ROWID tables. In the second form, the primary key is
91999 ** (a,b,...)
92000 */
92001 if( pTab==pFKey->pFrom && nIncr>0 ){
92002 Expr *pNe; /* Expression (pLeft != pRight) */
92003 Expr *pLeft; /* Value from parent table row */
92004 Expr *pRight; /* Column ref to child table */
92005 if( HasRowid(pTab) ){
92006 pLeft = exprTableRegister(pParse, pTab, regData, -1);
92007 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
92008 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
92009 }else{
92010 Expr *pEq, *pAll = 0;
92011 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
92012 for(i=0; i<pPk->nKeyCol; i++){
92013 i16 iCol = pIdx->aiColumn[i];
92014 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
92015 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
92016 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
92017 pAll = sqlite3ExprAnd(db, pAll, pEq);
92018 }
92019 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0, 0);
92020 }
92021 pWhere = sqlite3ExprAnd(db, pWhere, pNe);
92022 }
92023
92024 /* Resolve the references in the WHERE clause. */
92025 memset(&sNameContext, 0, sizeof(NameContext));
92026 sNameContext.pSrcList = pSrc;
@@ -91117,12 +92046,12 @@
92046 sqlite3VdbeJumpHere(v, iFkIfZero);
92047 }
92048 }
92049
92050 /*
92051 ** This function returns a linked list of FKey objects (connected by
92052 ** FKey.pNextTo) holding all children of table pTab. For example,
92053 ** given the following schema:
92054 **
92055 ** CREATE TABLE t1(a PRIMARY KEY);
92056 ** CREATE TABLE t2(b REFERENCES t1(a);
92057 **
@@ -91209,12 +92138,11 @@
92138 ** constraints are violated.
92139 */
92140 if( (db->flags & SQLITE_DeferFKs)==0 ){
92141 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
92142 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
92143 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
 
92144 }
92145
92146 if( iSkip ){
92147 sqlite3VdbeResolveLabel(v, iSkip);
92148 }
@@ -91420,11 +92348,12 @@
92348 }
92349
92350 sqlite3DbFree(db, aiFree);
92351 }
92352
92353 /* Loop through all the foreign key constraints that refer to this table.
92354 ** (the "child" constraints) */
92355 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
92356 Index *pIdx = 0; /* Foreign key index for pFKey */
92357 SrcList *pSrc;
92358 int *aiCol = 0;
92359
@@ -91445,13 +92374,12 @@
92374 if( !isIgnoreErrors || db->mallocFailed ) return;
92375 continue;
92376 }
92377 assert( aiCol || pFKey->nCol==1 );
92378
92379 /* Create a SrcList structure containing the child table. We need the
92380 ** child table as a SrcList for sqlite3WhereBegin() */
 
92381 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
92382 if( pSrc ){
92383 struct SrcList_item *pItem = pSrc->a;
92384 pItem->pTab = pFKey->pFrom;
92385 pItem->zName = pFKey->pFrom->zName;
@@ -91496,11 +92424,11 @@
92424 }
92425 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
92426 Index *pIdx = 0;
92427 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
92428 if( pIdx ){
92429 for(i=0; i<pIdx->nKeyCol; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]);
92430 }
92431 }
92432 }
92433 return mask;
92434 }
@@ -91688,11 +92616,11 @@
92616 Token tFrom;
92617 Expr *pRaise;
92618
92619 tFrom.z = zFrom;
92620 tFrom.n = nFrom;
92621 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
92622 if( pRaise ){
92623 pRaise->affinity = OE_Abort;
92624 }
92625 pSelect = sqlite3SelectNew(pParse,
92626 sqlite3ExprListAppend(pParse, 0, pRaise),
@@ -91852,27 +92780,42 @@
92780 ** This file contains C code routines that are called by the parser
92781 ** to handle INSERT statements in SQLite.
92782 */
92783
92784 /*
92785 ** Generate code that will
92786 **
92787 ** (1) acquire a lock for table pTab then
92788 ** (2) open pTab as cursor iCur.
92789 **
92790 ** If pTab is a WITHOUT ROWID table, then it is the PRIMARY KEY index
92791 ** for that table that is actually opened.
92792 */
92793 SQLITE_PRIVATE void sqlite3OpenTable(
92794 Parse *pParse, /* Generate code into this VDBE */
92795 int iCur, /* The cursor number of the table */
92796 int iDb, /* The database index in sqlite3.aDb[] */
92797 Table *pTab, /* The table to be opened */
92798 int opcode /* OP_OpenRead or OP_OpenWrite */
92799 ){
92800 Vdbe *v;
92801 assert( !IsVirtual(pTab) );
92802 v = sqlite3GetVdbe(pParse);
92803 assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
92804 sqlite3TableLock(pParse, iDb, pTab->tnum,
92805 (opcode==OP_OpenWrite)?1:0, pTab->zName);
92806 if( HasRowid(pTab) ){
92807 sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nCol);
92808 VdbeComment((v, "%s", pTab->zName));
92809 }else{
92810 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
92811 assert( pPk!=0 );
92812 assert( pPk->tnum=pTab->tnum );
92813 sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
92814 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
92815 VdbeComment((v, "%s", pTab->zName));
92816 }
92817 }
92818
92819 /*
92820 ** Return a pointer to the column affinity string associated with index
92821 ** pIdx. A column affinity string has one character for each column in
@@ -91904,19 +92847,19 @@
92847 ** up.
92848 */
92849 int n;
92850 Table *pTab = pIdx->pTable;
92851 sqlite3 *db = sqlite3VdbeDb(v);
92852 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
92853 if( !pIdx->zColAff ){
92854 db->mallocFailed = 1;
92855 return 0;
92856 }
92857 for(n=0; n<pIdx->nColumn; n++){
92858 i16 x = pIdx->aiColumn[n];
92859 pIdx->zColAff[n] = x<0 ? SQLITE_AFF_INTEGER : pTab->aCol[x].affinity;
92860 }
 
92861 pIdx->zColAff[n] = 0;
92862 }
92863
92864 return pIdx->zColAff;
92865 }
@@ -92258,11 +93201,11 @@
93201 int onError, /* How to handle constraint errors */
93202 int iDbDest /* The database of pDest */
93203 );
93204
93205 /*
93206 ** This routine is called to handle SQL of the following forms:
93207 **
93208 ** insert into TABLE (IDLIST) values(EXPRLIST)
93209 ** insert into TABLE (IDLIST) select
93210 **
93211 ** The IDLIST following the table name is always optional. If omitted,
@@ -92273,16 +93216,16 @@
93216 ** statement above, and pSelect is NULL. For the second form, pList is
93217 ** NULL and pSelect is a pointer to the select statement used to generate
93218 ** data for the insert.
93219 **
93220 ** The code generated follows one of four templates. For a simple
93221 ** insert with data coming from a VALUES clause, the code executes
93222 ** once straight down through. Pseudo-code follows (we call this
93223 ** the "1st template"):
93224 **
93225 ** open write cursor to <table> and its indices
93226 ** put VALUES clause expressions into registers
93227 ** write the resulting record into <table>
93228 ** cleanup
93229 **
93230 ** The three remaining templates assume the statement is of the form
93231 **
@@ -92376,12 +93319,13 @@
93319 int i, j, idx; /* Loop counters */
93320 Vdbe *v; /* Generate code into this virtual machine */
93321 Index *pIdx; /* For looping over indices of the table */
93322 int nColumn; /* Number of columns in the data */
93323 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
93324 int iDataCur = 0; /* VDBE cursor that is the main data repository */
93325 int iIdxCur = 0; /* First index cursor */
93326 int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
93327 int endOfLoop; /* Label for the end of the insertion loop */
93328 int useTempTable = 0; /* Store SELECT results in intermediate table */
93329 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
93330 int addrInsTop = 0; /* Jump to label "D" */
93331 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
@@ -92388,10 +93332,11 @@
93332 int addrSelect = 0; /* Address of coroutine that implements the SELECT */
93333 SelectDest dest; /* Destination for SELECT on rhs of INSERT */
93334 int iDb; /* Index of database holding TABLE */
93335 Db *pDb; /* The database containing table being inserted into */
93336 int appendFlag = 0; /* True if the insert is likely to be an append */
93337 int withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
93338
93339 /* Register allocations */
93340 int regFromSelect = 0;/* Base register for data coming from SELECT */
93341 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
93342 int regRowCount = 0; /* Memory cell used for the row counter */
@@ -92427,10 +93372,11 @@
93372 pDb = &db->aDb[iDb];
93373 zDb = pDb->zName;
93374 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
93375 goto insert_cleanup;
93376 }
93377 withoutRowid = !HasRowid(pTab);
93378
93379 /* Figure out if we have any triggers and if the table being
93380 ** inserted into is a view
93381 */
93382 #ifndef SQLITE_OMIT_TRIGGER
@@ -92446,20 +93392,17 @@
93392 # define isView 0
93393 #endif
93394 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
93395
93396 /* If pTab is really a view, make sure it has been initialized.
93397 ** ViewGetColumnNames() is a no-op if pTab is not a view.
 
93398 */
93399 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
93400 goto insert_cleanup;
93401 }
93402
93403 /* Cannot insert into a read-only table.
 
 
93404 */
93405 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
93406 goto insert_cleanup;
93407 }
93408
@@ -92496,12 +93439,11 @@
93439 ** is coming from a SELECT statement, then generate a co-routine that
93440 ** produces a single row of the SELECT on each invocation. The
93441 ** co-routine is the common header to the 3rd and 4th templates.
93442 */
93443 if( pSelect ){
93444 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
 
93445 int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
93446 if( rc ) goto insert_cleanup;
93447
93448 regEof = dest.iSDParm + 1;
93449 regFromSelect = dest.iSdst;
@@ -92509,11 +93451,11 @@
93451 nColumn = pSelect->pEList->nExpr;
93452 assert( dest.nSdst==nColumn );
93453
93454 /* Set useTempTable to TRUE if the result of the SELECT statement
93455 ** should be written into a temporary table (template 4). Set to
93456 ** FALSE if each output row of the SELECT can be written directly into
93457 ** the destination table (template 3).
93458 **
93459 ** A temp table must be used if the table being updated is also one
93460 ** of the tables being read by the SELECT statement. Also use a
93461 ** temp table in the case of row triggers.
@@ -92592,15 +93534,15 @@
93534 /* If the INSERT statement included an IDLIST term, then make sure
93535 ** all elements of the IDLIST really are columns of the table and
93536 ** remember the column indices.
93537 **
93538 ** If the table has an INTEGER PRIMARY KEY column and that column
93539 ** is named in the IDLIST, then record in the ipkColumn variable
93540 ** the index into IDLIST of the primary key column. ipkColumn is
93541 ** the index of the primary key as it appears in IDLIST, not as
93542 ** is appears in the original table. (The index of the INTEGER
93543 ** PRIMARY KEY in the original table is pTab->iPKey.)
93544 */
93545 if( pColumn ){
93546 for(i=0; i<pColumn->nId; i++){
93547 pColumn->a[i].idx = -1;
93548 }
@@ -92607,18 +93549,18 @@
93549 for(i=0; i<pColumn->nId; i++){
93550 for(j=0; j<pTab->nCol; j++){
93551 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93552 pColumn->a[i].idx = j;
93553 if( j==pTab->iPKey ){
93554 ipkColumn = i; assert( !withoutRowid );
93555 }
93556 break;
93557 }
93558 }
93559 if( j>=pTab->nCol ){
93560 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93561 ipkColumn = i;
93562 }else{
93563 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93564 pTabList, 0, pColumn->a[i].zName);
93565 pParse->checkSchema = 1;
93566 goto insert_cleanup;
@@ -92626,15 +93568,15 @@
93568 }
93569 }
93570 }
93571
93572 /* If there is no IDLIST term but the table has an integer primary
93573 ** key, the set the ipkColumn variable to the integer primary key
93574 ** column index in the original table definition.
93575 */
93576 if( pColumn==0 && nColumn>0 ){
93577 ipkColumn = pTab->iPKey;
93578 }
93579
93580 /* Initialize the count of rows to be inserted
93581 */
93582 if( db->flags & SQLITE_CountRows ){
@@ -92643,13 +93585,12 @@
93585 }
93586
93587 /* If this is not a view, open the table and and all indices */
93588 if( !isView ){
93589 int nIdx;
93590 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1,
93591 &iDataCur, &iIdxCur);
 
93592 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
93593 if( aRegIdx==0 ){
93594 goto insert_cleanup;
93595 }
93596 for(i=0; i<nIdx; i++){
@@ -92705,19 +93646,20 @@
93646 ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
93647 ** translated into a unique ID for the row. But on a BEFORE trigger,
93648 ** we do not know what the unique ID will be (because the insert has
93649 ** not happened yet) so we substitute a rowid of -1
93650 */
93651 if( ipkColumn<0 ){
93652 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
93653 }else{
93654 int j1;
93655 assert( !withoutRowid );
93656 if( useTempTable ){
93657 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
93658 }else{
93659 assert( pSelect==0 ); /* Otherwise useTempTable is true */
93660 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
93661 }
93662 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
93663 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
93664 sqlite3VdbeJumpHere(v, j1);
93665 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
@@ -92763,33 +93705,31 @@
93705 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
93706
93707 sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
93708 }
93709
93710 /* Compute the content of the next row to insert into a range of
93711 ** registers beginning at regIns.
 
 
93712 */
93713 if( !isView ){
93714 if( IsVirtual(pTab) ){
93715 /* The row that the VUpdate opcode will delete: none */
93716 sqlite3VdbeAddOp2(v, OP_Null, 0, regIns);
93717 }
93718 if( ipkColumn>=0 ){
93719 if( useTempTable ){
93720 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
93721 }else if( pSelect ){
93722 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid);
93723 }else{
93724 VdbeOp *pOp;
93725 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
93726 pOp = sqlite3VdbeGetOp(v, -1);
93727 if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
93728 appendFlag = 1;
93729 pOp->opcode = OP_NewRowid;
93730 pOp->p1 = iDataCur;
93731 pOp->p2 = regRowid;
93732 pOp->p3 = regAutoinc;
93733 }
93734 }
93735 /* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
@@ -92797,36 +93737,36 @@
93737 */
93738 if( !appendFlag ){
93739 int j1;
93740 if( !IsVirtual(pTab) ){
93741 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
93742 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
93743 sqlite3VdbeJumpHere(v, j1);
93744 }else{
93745 j1 = sqlite3VdbeCurrentAddr(v);
93746 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
93747 }
93748 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
93749 }
93750 }else if( IsVirtual(pTab) || withoutRowid ){
93751 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
93752 }else{
93753 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
93754 appendFlag = 1;
93755 }
93756 autoIncStep(pParse, regAutoinc, regRowid);
93757
93758 /* Compute data for all columns of the new entry, beginning
93759 ** with the first column.
93760 */
93761 nHidden = 0;
93762 for(i=0; i<pTab->nCol; i++){
93763 int iRegStore = regRowid+1+i;
93764 if( i==pTab->iPKey ){
93765 /* The value of the INTEGER PRIMARY KEY column is always a NULL.
93766 ** Whenever this column is read, the rowid will be substituted
93767 ** in its place. Hence, fill this column with a NULL to avoid
93768 ** taking up data space with information that will never be used. */
93769 sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
93770 continue;
93771 }
93772 if( pColumn==0 ){
@@ -92865,17 +93805,16 @@
93805 sqlite3MayAbort(pParse);
93806 }else
93807 #endif
93808 {
93809 int isReplace; /* Set to true if constraints may cause a replace */
93810 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
93811 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace
93812 );
93813 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
93814 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
93815 regIns, aRegIdx, 0, appendFlag, isReplace==0);
 
93816 }
93817 }
93818
93819 /* Update the count of rows that are inserted
93820 */
@@ -92902,13 +93841,13 @@
93841 sqlite3VdbeJumpHere(v, addrInsTop);
93842 }
93843
93844 if( !IsVirtual(pTab) && !isView ){
93845 /* Close all tables opened */
93846 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
93847 for(idx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
93848 sqlite3VdbeAddOp1(v, OP_Close, idx+iIdxCur);
93849 }
93850 }
93851
93852 insert_end:
93853 /* Update the sqlite_sequence table by storing the content of the
@@ -92949,65 +93888,78 @@
93888 #endif
93889 #ifdef tmask
93890 #undef tmask
93891 #endif
93892
 
93893 /*
93894 ** Generate code to do constraint checks prior to an INSERT or an UPDATE
93895 ** on table pTab.
93896 **
93897 ** The regNewData parameter is the first register in a range that contains
93898 ** the data to be inserted or the data after the update. There will be
93899 ** pTab->nCol+1 registers in this range. The first register (the one
93900 ** that regNewData points to) will contain the new rowid, or NULL in the
93901 ** case of a WITHOUT ROWID table. The second register in the range will
93902 ** contain the content of the first table column. The third register will
93903 ** contain the content of the second table column. And so forth.
93904 **
93905 ** The regOldData parameter is similar to regNewData except that it contains
93906 ** the data prior to an UPDATE rather than afterwards. regOldData is zero
93907 ** for an INSERT. This routine can distinguish between UPDATE and INSERT by
93908 ** checking regOldData for zero.
93909 **
93910 ** For an UPDATE, the pkChng boolean is true if the true primary key (the
93911 ** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
93912 ** might be modified by the UPDATE. If pkChng is false, then the key of
93913 ** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
93914 **
93915 ** For an INSERT, the pkChng boolean indicates whether or not the rowid
93916 ** was explicitly specified as part of the INSERT statement. If pkChng
93917 ** is zero, it means that the either rowid is computed automatically or
93918 ** that the table is a WITHOUT ROWID table and has no rowid. On an INSERT,
93919 ** pkChng will only be true if the INSERT statement provides an integer
93920 ** value for either the rowid column or its INTEGER PRIMARY KEY alias.
93921 **
93922 ** The code generated by this routine will store new index entries into
93923 ** registers identified by aRegIdx[]. No index entry is created for
93924 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
93925 ** the same as the order of indices on the linked list of indices
93926 ** at pTab->pIndex.
93927 **
93928 ** The caller must have already opened writeable cursors on the main
93929 ** table and all applicable indices (that is to say, all indices for which
93930 ** aRegIdx[] is not zero). iDataCur is the cursor for the main table when
93931 ** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
93932 ** index when operating on a WITHOUT ROWID table. iIdxCur is the cursor
93933 ** for the first index in the pTab->pIndex list. Cursors for other indices
93934 ** are at iIdxCur+N for the N-th element of the pTab->pIndex list.
93935 **
93936 ** This routine also generates code to check constraints. NOT NULL,
93937 ** CHECK, and UNIQUE constraints are all checked. If a constraint fails,
93938 ** then the appropriate action is performed. There are five possible
93939 ** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
93940 **
93941 ** Constraint type Action What Happens
93942 ** --------------- ---------- ----------------------------------------
93943 ** any ROLLBACK The current transaction is rolled back and
93944 ** sqlite3_step() returns immediately with a
93945 ** return code of SQLITE_CONSTRAINT.
93946 **
93947 ** any ABORT Back out changes from the current command
93948 ** only (do not do a complete rollback) then
93949 ** cause sqlite3_step() to return immediately
93950 ** with SQLITE_CONSTRAINT.
93951 **
93952 ** any FAIL Sqlite3_step() returns immediately with a
93953 ** return code of SQLITE_CONSTRAINT. The
93954 ** transaction is not rolled back and any
93955 ** changes to prior rows are retained.
93956 **
93957 ** any IGNORE The attempt in insert or update the current
93958 ** row is skipped, without throwing an error.
93959 ** Processing continues with the next row.
93960 ** (There is an immediate jump to ignoreDest.)
93961 **
93962 ** NOT NULL REPLACE The NULL value is replace by the default
93963 ** value for that column. If the default value
93964 ** is NULL, the action is the same as ABORT.
93965 **
@@ -93018,48 +93970,61 @@
93970 **
93971 ** Which action to take is determined by the overrideError parameter.
93972 ** Or if overrideError==OE_Default, then the pParse->onError parameter
93973 ** is used. Or if pParse->onError==OE_Default then the onError value
93974 ** for the constraint is used.
 
 
 
 
 
 
93975 */
93976 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(
93977 Parse *pParse, /* The parser context */
93978 Table *pTab, /* The table being inserted or updated */
93979 int *aRegIdx, /* Use register aRegIdx[i] for index i. 0 for unused */
93980 int iDataCur, /* Canonical data cursor (main table or PK index) */
93981 int iIdxCur, /* First index cursor */
93982 int regNewData, /* First register in a range holding values to insert */
93983 int regOldData, /* Previous content. 0 for INSERTs */
93984 u8 pkChng, /* Non-zero if the rowid or PRIMARY KEY changed */
93985 u8 overrideError, /* Override onError to this if not OE_Default */
93986 int ignoreDest, /* Jump to this label on an OE_Ignore resolution */
93987 int *pbMayReplace /* OUT: Set to true if constraint may cause a replace */
93988 ){
93989 Vdbe *v; /* VDBE under constrution */
 
 
 
 
 
 
 
93990 Index *pIdx; /* Pointer to one of the indices */
93991 Index *pPk = 0; /* The PRIMARY KEY index */
93992 sqlite3 *db; /* Database connection */
93993 int i; /* loop counter */
93994 int ix; /* Index loop counter */
93995 int nCol; /* Number of columns */
93996 int onError; /* Conflict resolution strategy */
93997 int j1; /* Addresss of jump instruction */
93998 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
93999 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
94000 int ipkTop = 0; /* Top of the rowid change constraint check */
94001 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
94002 u8 isUpdate; /* True if this is an UPDATE operation */
94003
94004 isUpdate = regOldData!=0;
94005 db = pParse->db;
94006 v = sqlite3GetVdbe(pParse);
94007 assert( v!=0 );
94008 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
94009 nCol = pTab->nCol;
94010
94011 /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
94012 ** normal rowid tables. nPkField is the number of key fields in the
94013 ** pPk index or 1 for a rowid table. In other words, nPkField is the
94014 ** number of fields in the true primary key of the table. */
94015 if( HasRowid(pTab) ){
94016 pPk = 0;
94017 nPkField = 1;
94018 }else{
94019 pPk = sqlite3PrimaryKeyIndex(pTab);
94020 nPkField = pPk->nKeyCol;
94021 }
94022
94023 /* Record that this module has started */
94024 VdbeModuleComment((v, "BEGIN: GenCnstCks(%d,%d,%d,%d,%d)",
94025 iDataCur, iIdxCur, regNewData, regOldData, pkChng));
94026
94027 /* Test all NOT NULL constraints.
94028 */
94029 for(i=0; i<nCol; i++){
94030 if( i==pTab->iPKey ){
@@ -93078,28 +94043,28 @@
94043 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
94044 || onError==OE_Ignore || onError==OE_Replace );
94045 switch( onError ){
94046 case OE_Abort:
94047 sqlite3MayAbort(pParse);
94048 /* Fall through */
94049 case OE_Rollback:
94050 case OE_Fail: {
94051 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
94052 pTab->aCol[i].zName);
94053 sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
94054 regNewData+1+i, zMsg, P4_DYNAMIC);
94055 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
 
94056 break;
94057 }
94058 case OE_Ignore: {
94059 sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
94060 break;
94061 }
94062 default: {
94063 assert( onError==OE_Replace );
94064 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
94065 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
94066 sqlite3VdbeJumpHere(v, j1);
94067 break;
94068 }
94069 }
94070 }
@@ -93107,59 +94072,79 @@
94072 /* Test all CHECK constraints
94073 */
94074 #ifndef SQLITE_OMIT_CHECK
94075 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
94076 ExprList *pCheck = pTab->pCheck;
94077 pParse->ckBase = regNewData+1;
94078 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
94079 for(i=0; i<pCheck->nExpr; i++){
94080 int allOk = sqlite3VdbeMakeLabel(v);
94081 sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
94082 if( onError==OE_Ignore ){
94083 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
94084 }else{
94085 char *zName = pCheck->a[i].zName;
94086 if( zName==0 ) zName = pTab->zName;
94087 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
 
 
 
 
 
94088 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
94089 onError, zName, P4_TRANSIENT,
94090 P5_ConstraintCheck);
94091 }
94092 sqlite3VdbeResolveLabel(v, allOk);
94093 }
94094 }
94095 #endif /* !defined(SQLITE_OMIT_CHECK) */
94096
94097 /* If rowid is changing, make sure the new rowid does not previously
94098 ** exist in the table.
 
94099 */
94100 if( pkChng && pPk==0 ){
94101 int addrRowidOk = sqlite3VdbeMakeLabel(v);
94102
94103 /* Figure out what action to take in case of a rowid collision */
94104 onError = pTab->keyConf;
94105 if( overrideError!=OE_Default ){
94106 onError = overrideError;
94107 }else if( onError==OE_Default ){
94108 onError = OE_Abort;
94109 }
94110
94111 if( isUpdate ){
94112 /* pkChng!=0 does not mean that the rowid has change, only that
94113 ** it might have changed. Skip the conflict logic below if the rowid
94114 ** is unchanged. */
94115 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
94116 }
94117
94118 /* If the response to a rowid conflict is REPLACE but the response
94119 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
94120 ** to defer the running of the rowid conflict checking until after
94121 ** the UNIQUE constraints have run.
94122 */
94123 if( onError==OE_Replace && overrideError!=OE_Replace ){
94124 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
94125 if( pIdx->onError==OE_Ignore || pIdx->onError==OE_Fail ){
94126 ipkTop = sqlite3VdbeAddOp0(v, OP_Goto);
94127 break;
94128 }
94129 }
94130 }
94131
94132 /* Check to see if the new rowid already exists in the table. Skip
94133 ** the following conflict logic if it does not. */
94134 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
94135
94136 /* Generate code that deals with a rowid collision */
94137 switch( onError ){
94138 default: {
94139 onError = OE_Abort;
94140 /* Fall thru into the next case */
94141 }
94142 case OE_Rollback:
94143 case OE_Abort:
94144 case OE_Fail: {
94145 sqlite3RowidConstraint(pParse, onError, pTab);
 
94146 break;
94147 }
94148 case OE_Replace: {
94149 /* If there are DELETE triggers on this table and the
94150 ** recursive-triggers flag is set, call GenerateRowDelete() to
@@ -93187,123 +94172,162 @@
94172 if( db->flags&SQLITE_RecTriggers ){
94173 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
94174 }
94175 if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){
94176 sqlite3MultiWrite(pParse);
94177 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
94178 regNewData, 1, 0, OE_Replace, 1);
 
94179 }else if( pTab->pIndex ){
94180 sqlite3MultiWrite(pParse);
94181 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
94182 }
94183 seenReplace = 1;
94184 break;
94185 }
94186 case OE_Ignore: {
94187 /*assert( seenReplace==0 );*/
94188 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
94189 break;
94190 }
94191 }
94192 sqlite3VdbeResolveLabel(v, addrRowidOk);
94193 if( ipkTop ){
94194 ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
94195 sqlite3VdbeJumpHere(v, ipkTop);
94196 }
94197 }
94198
94199 /* Test all UNIQUE constraints by creating entries for each UNIQUE
94200 ** index and making sure that duplicate entries do not already exist.
94201 ** Compute the revised record entries for indices as we go.
94202 **
94203 ** This loop also handles the case of the PRIMARY KEY index for a
94204 ** WITHOUT ROWID table.
94205 */
94206 for(ix=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, ix++){
94207 int regIdx; /* Range of registers hold conent for pIdx */
94208 int regR; /* Range of registers holding conflicting PK */
94209 int iThisCur; /* Cursor for this UNIQUE index */
94210 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
94211
94212 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
94213 iThisCur = iIdxCur+ix;
94214 addrUniqueOk = sqlite3VdbeMakeLabel(v);
94215
94216 /* Skip partial indices for which the WHERE clause is not true */
94217 if( pIdx->pPartIdxWhere ){
94218 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
94219 pParse->ckBase = regNewData+1;
94220 sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
 
94221 SQLITE_JUMPIFNULL);
94222 pParse->ckBase = 0;
94223 }
94224
94225 /* Create a record for this index entry as it should appear after
94226 ** the insert or update. Store that record in the aRegIdx[ix] register
94227 */
94228 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
94229 for(i=0; i<pIdx->nColumn; i++){
94230 int iField = pIdx->aiColumn[i];
94231 int x;
94232 if( iField<0 || iField==pTab->iPKey ){
94233 x = regNewData;
94234 }else{
94235 x = iField + regNewData + 1;
94236 }
94237 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94238 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
94239 }
94240 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
 
94241 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
94242 VdbeComment((v, "for %s", pIdx->zName));
94243 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
94244
94245 /* In an UPDATE operation, if this index is the PRIMARY KEY index
94246 ** of a WITHOUT ROWID table and there has been no change the
94247 ** primary key, then no collision is possible. The collision detection
94248 ** logic below can all be skipped. */
94249 if( isUpdate && pPk==pIdx && pkChng==0 ){
94250 sqlite3VdbeResolveLabel(v, addrUniqueOk);
94251 continue;
94252 }
94253
94254 /* Find out what action to take in case there is a uniqueness conflict */
94255 onError = pIdx->onError;
94256 if( onError==OE_None ){
94257 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
94258 sqlite3VdbeResolveLabel(v, addrUniqueOk);
94259 continue; /* pIdx is not a UNIQUE index */
94260 }
94261 if( overrideError!=OE_Default ){
94262 onError = overrideError;
94263 }else if( onError==OE_Default ){
94264 onError = OE_Abort;
94265 }
 
 
 
 
94266
94267 /* Check to see if the new index entry will be unique */
94268 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94269 regIdx, pIdx->nKeyCol);
94270
94271 /* Generate code to handle collisions */
94272 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94273 if( HasRowid(pTab) ){
94274 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94275 /* Conflict only if the rowid of the existing index entry
94276 ** is different from old-rowid */
94277 if( isUpdate ){
94278 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94279 }
94280 }else{
94281 int x;
94282 /* Extract the PRIMARY KEY from the end of the index entry and
94283 ** store it in registers regR..regR+nPk-1 */
94284 if( (isUpdate || onError==OE_Replace) && pIdx!=pPk ){
94285 for(i=0; i<pPk->nKeyCol; i++){
94286 x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
94287 sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
94288 VdbeComment((v, "%s.%s", pTab->zName,
94289 pTab->aCol[pPk->aiColumn[i]].zName));
94290 }
94291 }
94292 if( isUpdate ){
94293 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
94294 ** table, only conflict if the new PRIMARY KEY values are actually
94295 ** different from the old.
94296 **
94297 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
94298 ** of the matched index row are different from the original PRIMARY
94299 ** KEY values of this row before the update. */
94300 int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
94301 int op = OP_Ne;
94302 int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
94303
94304 for(i=0; i<pPk->nKeyCol; i++){
94305 char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
94306 x = pPk->aiColumn[i];
94307 if( i==(pPk->nKeyCol-1) ){
94308 addrJump = addrUniqueOk;
94309 op = OP_Eq;
94310 }
94311 sqlite3VdbeAddOp4(v, op,
94312 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94313 );
94314 }
94315 }
94316 }
94317
94318 /* Generate code that executes if the new index entry is not unique */
94319 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
94320 || onError==OE_Ignore || onError==OE_Replace );
94321 switch( onError ){
94322 case OE_Rollback:
94323 case OE_Abort:
94324 case OE_Fail: {
94325 sqlite3UniqueConstraint(pParse, onError, pIdx);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94326 break;
94327 }
94328 case OE_Ignore: {
 
94329 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
94330 break;
94331 }
94332 default: {
94333 Trigger *pTrigger = 0;
@@ -93310,67 +94334,75 @@
94334 assert( onError==OE_Replace );
94335 sqlite3MultiWrite(pParse);
94336 if( db->flags&SQLITE_RecTriggers ){
94337 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
94338 }
94339 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
94340 regR, nPkField, 0, OE_Replace, pIdx==pPk);
 
94341 seenReplace = 1;
94342 break;
94343 }
94344 }
94345 sqlite3VdbeResolveLabel(v, addrUniqueOk);
94346 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
94347 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
94348 }
94349 if( ipkTop ){
94350 sqlite3VdbeAddOp2(v, OP_Goto, 0, ipkTop+1);
94351 sqlite3VdbeJumpHere(v, ipkBottom);
94352 }
94353
94354 *pbMayReplace = seenReplace;
94355 VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
 
94356 }
94357
94358 /*
94359 ** This routine generates code to finish the INSERT or UPDATE operation
94360 ** that was started by a prior call to sqlite3GenerateConstraintChecks.
94361 ** A consecutive range of registers starting at regNewData contains the
94362 ** rowid and the content to be inserted.
94363 **
94364 ** The arguments to this routine should be the same as the first six
94365 ** arguments to sqlite3GenerateConstraintChecks.
94366 */
94367 SQLITE_PRIVATE void sqlite3CompleteInsertion(
94368 Parse *pParse, /* The parser context */
94369 Table *pTab, /* the table into which we are inserting */
94370 int iDataCur, /* Cursor of the canonical data source */
94371 int iIdxCur, /* First index cursor */
94372 int regNewData, /* Range of content */
94373 int *aRegIdx, /* Register used by each index. 0 for unused indices */
94374 int isUpdate, /* True for UPDATE, False for INSERT */
94375 int appendBias, /* True if this is likely to be an append */
94376 int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */
94377 ){
94378 Vdbe *v; /* Prepared statements under construction */
94379 Index *pIdx; /* An index being inserted or updated */
94380 u8 pik_flags; /* flag values passed to the btree insert */
94381 int regData; /* Content registers (after the rowid) */
94382 int regRec; /* Register holding assemblied record for the table */
94383 int i; /* Loop counter */
94384
94385 v = sqlite3GetVdbe(pParse);
94386 assert( v!=0 );
94387 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
94388 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94389 if( aRegIdx[i]==0 ) continue;
94390 if( pIdx->pPartIdxWhere ){
94391 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
94392 }
94393 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
94394 pik_flags = 0;
94395 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
94396 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
94397 assert( pParse->nested==0 );
94398 pik_flags |= OPFLAG_NCHANGE;
94399 }
94400 if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags);
94401 }
94402 if( !HasRowid(pTab) ) return;
94403 regData = regNewData + 1;
94404 regRec = sqlite3GetTempReg(pParse);
94405 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
94406 sqlite3TableAffinityStr(v, pTab);
94407 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
94408 if( pParse->nested ){
@@ -93383,51 +94415,75 @@
94415 pik_flags |= OPFLAG_APPEND;
94416 }
94417 if( useSeekResult ){
94418 pik_flags |= OPFLAG_USESEEKRESULT;
94419 }
94420 sqlite3VdbeAddOp3(v, OP_Insert, iDataCur, regRec, regNewData);
94421 if( !pParse->nested ){
94422 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
94423 }
94424 sqlite3VdbeChangeP5(v, pik_flags);
94425 }
94426
94427 /*
94428 ** Allocate cursors for the pTab table and all its indices and generate
94429 ** code to open and initialized those cursors.
 
94430 **
94431 ** The cursor for the object that contains the complete data (normally
94432 ** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
94433 ** ROWID table) is returned in *piDataCur. The first index cursor is
94434 ** returned in *piIdxCur. The number of indices is returned.
94435 **
94436 ** Use iBase as the first cursor (either the *piDataCur for rowid tables
94437 ** or the first index for WITHOUT ROWID tables) if it is non-negative.
94438 ** If iBase is negative, then allocate the next available cursor.
94439 **
94440 ** For a rowid table, *piDataCur will be exactly one less than *piIdxCur.
94441 ** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
94442 ** of *piIdxCurs, depending on where the PRIMARY KEY index appears on the
94443 ** pTab->pIndex list.
94444 */
94445 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
94446 Parse *pParse, /* Parsing context */
94447 Table *pTab, /* Table to be opened */
94448 int op, /* OP_OpenRead or OP_OpenWrite */
94449 int iBase, /* Use this for the table cursor, if there is one */
94450 int *piDataCur, /* Write the database source cursor number here */
94451 int *piIdxCur /* Write the first index cursor number here */
94452 ){
94453 int i;
94454 int iDb;
94455 Index *pIdx;
94456 Vdbe *v;
94457
94458 assert( op==OP_OpenRead || op==OP_OpenWrite );
94459 if( IsVirtual(pTab) ){
94460 *piDataCur = 0;
94461 *piIdxCur = 1;
94462 return 0;
94463 }
94464 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94465 v = sqlite3GetVdbe(pParse);
94466 assert( v!=0 );
94467 if( iBase<0 ) iBase = pParse->nTab;
94468 if( HasRowid(pTab) ){
94469 *piDataCur = iBase++;
94470 sqlite3OpenTable(pParse, *piDataCur, iDb, pTab, op);
94471 }else{
94472 sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
94473 }
94474 *piIdxCur = iBase;
94475 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94476 int iIdxCur = iBase++;
94477 assert( pIdx->pSchema==pTab->pSchema );
94478 if( pIdx->autoIndex==2 && !HasRowid(pTab) ) *piDataCur = iIdxCur;
94479 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94480 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
94481 VdbeComment((v, "%s", pIdx->zName));
94482 }
94483 if( iBase>pParse->nTab ) pParse->nTab = iBase;
94484 return i;
 
 
94485 }
94486
94487
94488 #ifdef SQLITE_TEST
94489 /*
@@ -93468,17 +94524,17 @@
94524 */
94525 static int xferCompatibleIndex(Index *pDest, Index *pSrc){
94526 int i;
94527 assert( pDest && pSrc );
94528 assert( pDest->pTable!=pSrc->pTable );
94529 if( pDest->nKeyCol!=pSrc->nKeyCol ){
94530 return 0; /* Different number of columns */
94531 }
94532 if( pDest->onError!=pSrc->onError ){
94533 return 0; /* Different conflict resolution strategies */
94534 }
94535 for(i=0; i<pSrc->nKeyCol; i++){
94536 if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
94537 return 0; /* Different columns indexed */
94538 }
94539 if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
94540 return 0; /* Different sort orders */
@@ -93533,14 +94589,13 @@
94589 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
94590 int i; /* Loop counter */
94591 int iDbSrc; /* The database of pSrc */
94592 int iSrc, iDest; /* Cursors from source and destination */
94593 int addr1, addr2; /* Loop addresses */
94594 int emptyDestTest = 0; /* Address of test for empty pDest */
94595 int emptySrcTest = 0; /* Address of test for empty pSrc */
94596 Vdbe *v; /* The VDBE we are building */
 
94597 int regAutoinc; /* Memory register used by AUTOINC */
94598 int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
94599 int regData, regRowid; /* Registers holding data and rowid */
94600
94601 if( pSelect==0 ){
@@ -93606,10 +94661,13 @@
94661 return 0; /* FROM clause does not contain a real table */
94662 }
94663 if( pSrc==pDest ){
94664 return 0; /* tab1 and tab2 may not be the same table */
94665 }
94666 if( HasRowid(pDest)!=HasRowid(pSrc) ){
94667 return 0; /* source and destination must both be WITHOUT ROWID or not */
94668 }
94669 #ifndef SQLITE_OMIT_VIRTUALTABLE
94670 if( pSrc->tabFlags & TF_Virtual ){
94671 return 0; /* tab2 must not be a virtual table */
94672 }
94673 #endif
@@ -93676,11 +94734,14 @@
94734 v = sqlite3GetVdbe(pParse);
94735 sqlite3CodeVerifySchema(pParse, iDbSrc);
94736 iSrc = pParse->nTab++;
94737 iDest = pParse->nTab++;
94738 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
94739 regData = sqlite3GetTempReg(pParse);
94740 regRowid = sqlite3GetTempReg(pParse);
94741 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
94742 assert( HasRowid(pDest) || destHasUniqueIdx );
94743 if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
94744 || destHasUniqueIdx /* (2) */
94745 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
94746 ){
94747 /* In some circumstances, we are able to run the xfer optimization
@@ -93698,62 +94759,60 @@
94759 ** (3) onError is something other than OE_Abort and OE_Rollback.
94760 */
94761 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
94762 emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
94763 sqlite3VdbeJumpHere(v, addr1);
94764 }
94765 if( HasRowid(pSrc) ){
94766 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94767 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94768 if( pDest->iPKey>=0 ){
94769 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94770 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
94771 sqlite3RowidConstraint(pParse, onError, pDest);
94772 sqlite3VdbeJumpHere(v, addr2);
94773 autoIncStep(pParse, regAutoinc, regRowid);
94774 }else if( pDest->pIndex==0 ){
94775 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
94776 }else{
94777 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94778 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
94779 }
94780 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
94781 sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
94782 sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
94783 sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94784 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
94785 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94786 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94787 }else{
94788 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
94789 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
94790 }
94791 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
94792 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
94793 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
94794 }
94795 assert( pSrcIdx );
94796 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
94797 sqlite3VdbeSetP4KeyInfo(pParse, pSrcIdx);
 
 
 
94798 VdbeComment((v, "%s", pSrcIdx->zName));
94799 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
94800 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
 
94801 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
94802 VdbeComment((v, "%s", pDestIdx->zName));
94803 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94804 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
94805 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
94806 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
94807 sqlite3VdbeJumpHere(v, addr1);
94808 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94809 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94810 }
94811 sqlite3VdbeJumpHere(v, emptySrcTest);
94812 sqlite3ReleaseTempReg(pParse, regRowid);
94813 sqlite3ReleaseTempReg(pParse, regData);
 
 
94814 if( emptyDestTest ){
94815 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
94816 sqlite3VdbeJumpHere(v, emptyDestTest);
94817 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94818 return 0;
@@ -95251,15 +96310,17 @@
96310 { /* zName: */ "auto_vacuum",
96311 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
96312 /* ePragFlag: */ PragFlag_NeedSchema,
96313 /* iArg: */ 0 },
96314 #endif
96315 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96316 #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
96317 { /* zName: */ "automatic_index",
96318 /* ePragTyp: */ PragTyp_FLAG,
96319 /* ePragFlag: */ 0,
96320 /* iArg: */ SQLITE_AutoIndex },
96321 #endif
96322 #endif
96323 { /* zName: */ "busy_timeout",
96324 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
96325 /* ePragFlag: */ 0,
96326 /* iArg: */ 0 },
@@ -95267,22 +96328,26 @@
96328 { /* zName: */ "cache_size",
96329 /* ePragTyp: */ PragTyp_CACHE_SIZE,
96330 /* ePragFlag: */ PragFlag_NeedSchema,
96331 /* iArg: */ 0 },
96332 #endif
96333 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96334 { /* zName: */ "cache_spill",
96335 /* ePragTyp: */ PragTyp_FLAG,
96336 /* ePragFlag: */ 0,
96337 /* iArg: */ SQLITE_CacheSpill },
96338 #endif
96339 { /* zName: */ "case_sensitive_like",
96340 /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
96341 /* ePragFlag: */ 0,
96342 /* iArg: */ 0 },
96343 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96344 { /* zName: */ "checkpoint_fullfsync",
96345 /* ePragTyp: */ PragTyp_FLAG,
96346 /* ePragFlag: */ 0,
96347 /* iArg: */ SQLITE_CkptFullFSync },
96348 #endif
96349 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
96350 { /* zName: */ "collation_list",
96351 /* ePragTyp: */ PragTyp_COLLATION_LIST,
96352 /* ePragFlag: */ 0,
96353 /* iArg: */ 0 },
@@ -95291,14 +96356,16 @@
96356 { /* zName: */ "compile_options",
96357 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
96358 /* ePragFlag: */ 0,
96359 /* iArg: */ 0 },
96360 #endif
96361 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96362 { /* zName: */ "count_changes",
96363 /* ePragTyp: */ PragTyp_FLAG,
96364 /* ePragFlag: */ 0,
96365 /* iArg: */ SQLITE_CountRows },
96366 #endif
96367 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
96368 { /* zName: */ "data_store_directory",
96369 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
96370 /* ePragFlag: */ 0,
96371 /* iArg: */ 0 },
@@ -95313,20 +96380,24 @@
96380 { /* zName: */ "default_cache_size",
96381 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
96382 /* ePragFlag: */ PragFlag_NeedSchema,
96383 /* iArg: */ 0 },
96384 #endif
96385 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96386 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
96387 { /* zName: */ "defer_foreign_keys",
96388 /* ePragTyp: */ PragTyp_FLAG,
96389 /* ePragFlag: */ 0,
96390 /* iArg: */ SQLITE_DeferFKs },
96391 #endif
96392 #endif
96393 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96394 { /* zName: */ "empty_result_callbacks",
96395 /* ePragTyp: */ PragTyp_FLAG,
96396 /* ePragFlag: */ 0,
96397 /* iArg: */ SQLITE_NullCallback },
96398 #endif
96399 #if !defined(SQLITE_OMIT_UTF16)
96400 { /* zName: */ "encoding",
96401 /* ePragTyp: */ PragTyp_ENCODING,
96402 /* ePragFlag: */ 0,
96403 /* iArg: */ 0 },
@@ -95341,30 +96412,34 @@
96412 { /* zName: */ "foreign_key_list",
96413 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
96414 /* ePragFlag: */ PragFlag_NeedSchema,
96415 /* iArg: */ 0 },
96416 #endif
96417 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96418 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
96419 { /* zName: */ "foreign_keys",
96420 /* ePragTyp: */ PragTyp_FLAG,
96421 /* ePragFlag: */ 0,
96422 /* iArg: */ SQLITE_ForeignKeys },
96423 #endif
96424 #endif
96425 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
96426 { /* zName: */ "freelist_count",
96427 /* ePragTyp: */ PragTyp_HEADER_VALUE,
96428 /* ePragFlag: */ 0,
96429 /* iArg: */ 0 },
96430 #endif
96431 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96432 { /* zName: */ "full_column_names",
96433 /* ePragTyp: */ PragTyp_FLAG,
96434 /* ePragFlag: */ 0,
96435 /* iArg: */ SQLITE_FullColNames },
96436 { /* zName: */ "fullfsync",
96437 /* ePragTyp: */ PragTyp_FLAG,
96438 /* ePragFlag: */ 0,
96439 /* iArg: */ SQLITE_FullFSync },
96440 #endif
96441 #if defined(SQLITE_HAS_CODEC)
96442 { /* zName: */ "hexkey",
96443 /* ePragTyp: */ PragTyp_HEXKEY,
96444 /* ePragFlag: */ 0,
96445 /* iArg: */ 0 },
@@ -95371,15 +96446,17 @@
96446 { /* zName: */ "hexrekey",
96447 /* ePragTyp: */ PragTyp_HEXKEY,
96448 /* ePragFlag: */ 0,
96449 /* iArg: */ 0 },
96450 #endif
96451 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96452 #if !defined(SQLITE_OMIT_CHECK)
96453 { /* zName: */ "ignore_check_constraints",
96454 /* ePragTyp: */ PragTyp_FLAG,
96455 /* ePragFlag: */ 0,
96456 /* iArg: */ SQLITE_IgnoreChecks },
96457 #endif
96458 #endif
96459 #if !defined(SQLITE_OMIT_AUTOVACUUM)
96460 { /* zName: */ "incremental_vacuum",
96461 /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
96462 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -95415,14 +96492,16 @@
96492 { /* zName: */ "key",
96493 /* ePragTyp: */ PragTyp_KEY,
96494 /* ePragFlag: */ 0,
96495 /* iArg: */ 0 },
96496 #endif
96497 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96498 { /* zName: */ "legacy_file_format",
96499 /* ePragTyp: */ PragTyp_FLAG,
96500 /* ePragFlag: */ 0,
96501 /* iArg: */ SQLITE_LegacyFileFmt },
96502 #endif
96503 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
96504 { /* zName: */ "lock_proxy_file",
96505 /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
96506 /* ePragFlag: */ 0,
96507 /* iArg: */ 0 },
@@ -95459,38 +96538,44 @@
96538 { /* zName: */ "parser_trace",
96539 /* ePragTyp: */ PragTyp_PARSER_TRACE,
96540 /* ePragFlag: */ 0,
96541 /* iArg: */ 0 },
96542 #endif
96543 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96544 { /* zName: */ "query_only",
96545 /* ePragTyp: */ PragTyp_FLAG,
96546 /* ePragFlag: */ 0,
96547 /* iArg: */ SQLITE_QueryOnly },
96548 #endif
96549 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
96550 { /* zName: */ "quick_check",
96551 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
96552 /* ePragFlag: */ PragFlag_NeedSchema,
96553 /* iArg: */ 0 },
96554 #endif
96555 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96556 { /* zName: */ "read_uncommitted",
96557 /* ePragTyp: */ PragTyp_FLAG,
96558 /* ePragFlag: */ 0,
96559 /* iArg: */ SQLITE_ReadUncommitted },
96560 { /* zName: */ "recursive_triggers",
96561 /* ePragTyp: */ PragTyp_FLAG,
96562 /* ePragFlag: */ 0,
96563 /* iArg: */ SQLITE_RecTriggers },
96564 #endif
96565 #if defined(SQLITE_HAS_CODEC)
96566 { /* zName: */ "rekey",
96567 /* ePragTyp: */ PragTyp_REKEY,
96568 /* ePragFlag: */ 0,
96569 /* iArg: */ 0 },
96570 #endif
96571 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96572 { /* zName: */ "reverse_unordered_selects",
96573 /* ePragTyp: */ PragTyp_FLAG,
96574 /* ePragFlag: */ 0,
96575 /* iArg: */ SQLITE_ReverseOrder },
96576 #endif
96577 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
96578 { /* zName: */ "schema_version",
96579 /* ePragTyp: */ PragTyp_HEADER_VALUE,
96580 /* ePragFlag: */ 0,
96581 /* iArg: */ 0 },
@@ -95499,27 +96584,31 @@
96584 { /* zName: */ "secure_delete",
96585 /* ePragTyp: */ PragTyp_SECURE_DELETE,
96586 /* ePragFlag: */ 0,
96587 /* iArg: */ 0 },
96588 #endif
96589 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96590 { /* zName: */ "short_column_names",
96591 /* ePragTyp: */ PragTyp_FLAG,
96592 /* ePragFlag: */ 0,
96593 /* iArg: */ SQLITE_ShortColNames },
96594 #endif
96595 { /* zName: */ "shrink_memory",
96596 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
96597 /* ePragFlag: */ 0,
96598 /* iArg: */ 0 },
96599 { /* zName: */ "soft_heap_limit",
96600 /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
96601 /* ePragFlag: */ 0,
96602 /* iArg: */ 0 },
96603 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96604 #if defined(SQLITE_DEBUG)
96605 { /* zName: */ "sql_trace",
96606 /* ePragTyp: */ PragTyp_FLAG,
96607 /* ePragFlag: */ 0,
96608 /* iArg: */ SQLITE_SqlTrace },
96609 #endif
96610 #endif
96611 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
96612 { /* zName: */ "stats",
96613 /* ePragTyp: */ PragTyp_STATS,
96614 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -95551,10 +96640,11 @@
96640 { /* zName: */ "user_version",
96641 /* ePragTyp: */ PragTyp_HEADER_VALUE,
96642 /* ePragFlag: */ 0,
96643 /* iArg: */ 0 },
96644 #endif
96645 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96646 #if defined(SQLITE_DEBUG)
96647 { /* zName: */ "vdbe_addoptrace",
96648 /* ePragTyp: */ PragTyp_FLAG,
96649 /* ePragFlag: */ 0,
96650 /* iArg: */ SQLITE_VdbeAddopTrace },
@@ -95568,10 +96658,11 @@
96658 /* iArg: */ SQLITE_VdbeListing },
96659 { /* zName: */ "vdbe_trace",
96660 /* ePragTyp: */ PragTyp_FLAG,
96661 /* ePragFlag: */ 0,
96662 /* iArg: */ SQLITE_VdbeTrace },
96663 #endif
96664 #endif
96665 #if !defined(SQLITE_OMIT_WAL)
96666 { /* zName: */ "wal_autocheckpoint",
96667 /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
96668 /* ePragFlag: */ 0,
@@ -95579,14 +96670,16 @@
96670 { /* zName: */ "wal_checkpoint",
96671 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
96672 /* ePragFlag: */ PragFlag_NeedSchema,
96673 /* iArg: */ 0 },
96674 #endif
96675 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
96676 { /* zName: */ "writable_schema",
96677 /* ePragTyp: */ PragTyp_FLAG,
96678 /* ePragFlag: */ 0,
96679 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
96680 #endif
96681 };
96682 /* Number of pragmas: 56 on by default, 68 total. */
96683 /* End of the automatically generated pragma table.
96684 ***************************************************************************/
96685
@@ -96548,12 +97641,11 @@
97641 pTab = sqlite3FindTable(db, zRight, zDb);
97642 if( pTab ){
97643 int i, k;
97644 int nHidden = 0;
97645 Column *pCol;
97646 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
 
97647 sqlite3VdbeSetNumCols(v, 6);
97648 pParse->nMem = 6;
97649 sqlite3CodeVerifySchema(pParse, iDb);
97650 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
97651 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
@@ -96632,12 +97724,12 @@
97724 pParse->nMem = 3;
97725 sqlite3CodeVerifySchema(pParse, iDb);
97726 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
97727 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
97728 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
97729 for(i=0; i<pIdx->nKeyCol; i++){
97730 i16 cnum = pIdx->aiColumn[i];
97731 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
97732 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
97733 assert( pTab->nCol>cnum );
97734 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
97735 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
@@ -96804,13 +97896,12 @@
97896 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
97897 if( x==0 ){
97898 if( pIdx==0 ){
97899 sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead);
97900 }else{
 
97901 sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb);
97902 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
97903 }
97904 }else{
97905 k = 0;
97906 break;
97907 }
@@ -96970,20 +98061,24 @@
98061 assert( sqlite3SchemaMutexHeld(db, i, 0) );
98062 pTbls = &db->aDb[i].pSchema->tblHash;
98063 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
98064 Table *pTab = sqliteHashData(x);
98065 Index *pIdx;
98066 if( HasRowid(pTab) ){
98067 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
98068 VdbeComment((v, "%s", pTab->zName));
98069 cnt++;
98070 }
98071 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
98072 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt);
98073 VdbeComment((v, "%s", pIdx->zName));
98074 cnt++;
98075 }
98076 }
98077
98078 /* Make sure sufficient number of registers have been allocated */
98079 pParse->nMem = MAX( pParse->nMem, cnt+8 );
98080
98081 /* Do the b-tree integrity checks */
98082 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
98083 sqlite3VdbeChangeP5(v, (u8)i);
98084 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
@@ -96997,62 +98092,64 @@
98092
98093 /* Make sure all the indices are constructed correctly.
98094 */
98095 for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
98096 Table *pTab = sqliteHashData(x);
98097 Index *pIdx, *pPk;
98098 int loopTop;
98099 int iDataCur, iIdxCur;
98100
98101 if( pTab->pIndex==0 ) continue;
98102 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
98103 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98104 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98105 sqlite3VdbeJumpHere(v, addr);
98106 sqlite3ExprCacheClear(pParse);
98107 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98108 1, &iDataCur, &iIdxCur);
98109 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98110 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98111 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98112 }
98113 pParse->nMem = MAX(pParse->nMem, 8+j);
98114 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0);
98115 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
98116 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98117 int jmp2, jmp3, jmp4;
98118 int r1;
98119 if( pPk==pIdx ) continue;
98120 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3);
98121 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
98122 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98123 pIdx->nColumn);
98124 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
98125 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
98126 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
98127 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
98128 P4_STATIC);
98129 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98130 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
98131 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98132 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98133 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
98134 sqlite3VdbeAddOp0(v, OP_Halt);
98135 sqlite3VdbeJumpHere(v, jmp4);
 
 
 
 
98136 sqlite3VdbeJumpHere(v, jmp2);
98137 sqlite3VdbeResolveLabel(v, jmp3);
98138 }
98139 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop);
98140 sqlite3VdbeJumpHere(v, loopTop-1);
98141 #ifndef SQLITE_OMIT_BTREECOUNT
98142 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
98143 "wrong # of entries in index ", P4_STATIC);
98144 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98145 if( pPk==pIdx ) continue;
98146 addr = sqlite3VdbeCurrentAddr(v);
98147 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
98148 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98149 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98150 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3);
98151 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
98152 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
98153 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
98154 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
98155 }
@@ -99096,28 +100193,61 @@
100193 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
100194 }
100195 }
100196
100197 /*
100198 ** Allocate a KeyInfo object sufficient for an index of N key columns and
100199 ** X extra columns.
 
 
 
100200 */
100201 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
100202 KeyInfo *p = sqlite3DbMallocZero(0,
100203 sizeof(KeyInfo) + (N+X)*(sizeof(CollSeq*)+1));
100204 if( p ){
100205 p->aSortOrder = (u8*)&p->aColl[N+X];
100206 p->nField = (u16)N;
100207 p->nXField = (u16)X;
100208 p->enc = ENC(db);
100209 p->db = db;
100210 p->nRef = 1;
100211 }else{
100212 db->mallocFailed = 1;
100213 }
100214 return p;
100215 }
100216
100217 /*
100218 ** Deallocate a KeyInfo object
100219 */
100220 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
100221 if( p ){
100222 assert( p->nRef>0 );
100223 p->nRef--;
100224 if( p->nRef==0 ) sqlite3DbFree(0, p);
100225 }
100226 }
100227
100228 /*
100229 ** Make a new pointer to a KeyInfo object
100230 */
100231 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo *p){
100232 if( p ){
100233 assert( p->nRef>0 );
100234 p->nRef++;
100235 }
100236 return p;
100237 }
100238
100239 #ifdef SQLITE_DEBUG
100240 /*
100241 ** Return TRUE if a KeyInfo object can be change. The KeyInfo object
100242 ** can only be changed if this is just a single reference to the object.
100243 **
100244 ** This routine is used only inside of assert() statements.
100245 */
100246 SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo *p){ return p->nRef==1; }
100247 #endif /* SQLITE_DEBUG */
100248
100249 /*
100250 ** Given an expression list, generate a KeyInfo structure that records
100251 ** the collating sequence for each expression in that expression list.
100252 **
100253 ** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
@@ -99126,23 +100256,23 @@
100256 ** then the KeyInfo structure is appropriate for initializing a virtual
100257 ** index to implement a DISTINCT test.
100258 **
100259 ** Space to hold the KeyInfo structure is obtain from malloc. The calling
100260 ** function is responsible for seeing that this structure is eventually
100261 ** freed.
 
100262 */
100263 static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
100264 int nExpr;
100265 KeyInfo *pInfo;
100266 struct ExprList_item *pItem;
100267 sqlite3 *db = pParse->db;
100268 int i;
100269
100270 nExpr = pList->nExpr;
100271 pInfo = sqlite3KeyInfoAlloc(db, nExpr, 1);
100272 if( pInfo ){
100273 assert( sqlite3KeyInfoIsWriteable(pInfo) );
100274 for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
100275 CollSeq *pColl;
100276 pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
100277 if( !pColl ) pColl = db->pDfltColl;
100278 pInfo->aColl[i] = pColl;
@@ -100281,11 +101411,11 @@
101411 CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
101412 int nCol; /* Number of columns in result set */
101413
101414 assert( p->pRightmost==p );
101415 nCol = p->pEList->nExpr;
101416 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
101417 if( !pKeyInfo ){
101418 rc = SQLITE_NOMEM;
101419 goto multi_select_end;
101420 }
101421 for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
@@ -100303,15 +101433,16 @@
101433 ** always safely abort as soon as the first unused slot is found */
101434 assert( pLoop->addrOpenEphm[1]<0 );
101435 break;
101436 }
101437 sqlite3VdbeChangeP2(v, addr, nCol);
101438 sqlite3VdbeChangeP4(v, addr, (char*)sqlite3KeyInfoRef(pKeyInfo),
101439 P4_KEYINFO);
101440 pLoop->addrOpenEphm[i] = -1;
101441 }
101442 }
101443 sqlite3KeyInfoUnref(pKeyInfo);
101444 }
101445
101446 multi_select_end:
101447 pDest->iSdst = dest.iSdst;
101448 pDest->nSdst = dest.nSdst;
@@ -100346,11 +101477,10 @@
101477 SelectDest *pIn, /* Coroutine supplying data */
101478 SelectDest *pDest, /* Where to send the data */
101479 int regReturn, /* The return address register */
101480 int regPrev, /* Previous result register. No uniqueness if 0 */
101481 KeyInfo *pKeyInfo, /* For comparing with previous entry */
 
101482 int iBreak /* Jump here if we hit the LIMIT */
101483 ){
101484 Vdbe *v = pParse->pVdbe;
101485 int iContinue;
101486 int addr;
@@ -100362,11 +101492,11 @@
101492 */
101493 if( regPrev ){
101494 int j1, j2;
101495 j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
101496 j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
101497 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
101498 sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
101499 sqlite3VdbeJumpHere(v, j1);
101500 sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
101501 sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
101502 }
@@ -100660,11 +101790,11 @@
101790 struct ExprList_item *pItem;
101791 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
101792 assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
101793 aPermute[i] = pItem->iOrderByCol - 1;
101794 }
101795 pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
101796 if( pKeyMerge ){
101797 for(i=0; i<nOrderBy; i++){
101798 CollSeq *pColl;
101799 Expr *pTerm = pOrderBy->a[i].pExpr;
101800 if( pTerm->flags & EP_Collate ){
@@ -100673,10 +101803,11 @@
101803 pColl = multiSelectCollSeq(pParse, p, aPermute[i]);
101804 if( pColl==0 ) pColl = db->pDfltColl;
101805 pOrderBy->a[i].pExpr =
101806 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
101807 }
101808 assert( sqlite3KeyInfoIsWriteable(pKeyMerge) );
101809 pKeyMerge->aColl[i] = pColl;
101810 pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder;
101811 }
101812 }
101813 }else{
@@ -100698,12 +101829,13 @@
101829 int nExpr = p->pEList->nExpr;
101830 assert( nOrderBy>=nExpr || db->mallocFailed );
101831 regPrev = pParse->nMem+1;
101832 pParse->nMem += nExpr+1;
101833 sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
101834 pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
101835 if( pKeyDup ){
101836 assert( sqlite3KeyInfoIsWriteable(pKeyDup) );
101837 for(i=0; i<nExpr; i++){
101838 pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
101839 pKeyDup->aSortOrder[i] = 0;
101840 }
101841 }
@@ -100781,21 +101913,22 @@
101913 ** select as the next output row of the compound select.
101914 */
101915 VdbeNoopComment((v, "Output routine for A"));
101916 addrOutA = generateOutputSubroutine(pParse,
101917 p, &destA, pDest, regOutA,
101918 regPrev, pKeyDup, labelEnd);
101919
101920 /* Generate a subroutine that outputs the current row of the B
101921 ** select as the next output row of the compound select.
101922 */
101923 if( op==TK_ALL || op==TK_UNION ){
101924 VdbeNoopComment((v, "Output routine for B"));
101925 addrOutB = generateOutputSubroutine(pParse,
101926 p, &destB, pDest, regOutB,
101927 regPrev, pKeyDup, labelEnd);
101928 }
101929 sqlite3KeyInfoUnref(pKeyDup);
101930
101931 /* Generate a subroutine to run when the results from select A
101932 ** are exhausted and only data in select B remains.
101933 */
101934 VdbeNoopComment((v, "eof-A subroutine"));
@@ -100870,11 +102003,11 @@
102003 /* Implement the main merge loop
102004 */
102005 sqlite3VdbeResolveLabel(v, labelCmpr);
102006 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
102007 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
102008 (char*)pKeyMerge, P4_KEYINFO);
102009 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
102010 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
102011
102012 /* Jump to the this point in order to terminate the query.
102013 */
@@ -102096,11 +103229,11 @@
103229 "argument");
103230 pFunc->iDistinct = -1;
103231 }else{
103232 KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->x.pList);
103233 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
103234 (char*)pKeyInfo, P4_KEYINFO);
103235 }
103236 }
103237 }
103238 }
103239
@@ -102551,11 +103684,11 @@
103684 pKeyInfo = keyInfoFromExprList(pParse, pOrderBy);
103685 pOrderBy->iECursor = pParse->nTab++;
103686 p->addrOpenEphm[2] = addrSortIndex =
103687 sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
103688 pOrderBy->iECursor, pOrderBy->nExpr+2, 0,
103689 (char*)pKeyInfo, P4_KEYINFO);
103690 }else{
103691 addrSortIndex = -1;
103692 }
103693
103694 /* If the output is destined for a temporary table, open that table.
@@ -102579,11 +103712,11 @@
103712 if( p->selFlags & SF_Distinct ){
103713 sDistinct.tabTnct = pParse->nTab++;
103714 sDistinct.addrTnct = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
103715 sDistinct.tabTnct, 0, 0,
103716 (char*)keyInfoFromExprList(pParse, p->pEList),
103717 P4_KEYINFO);
103718 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
103719 sDistinct.eTnctType = WHERE_DISTINCT_UNORDERED;
103720 }else{
103721 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
103722 }
@@ -102703,11 +103836,11 @@
103836 */
103837 sAggInfo.sortingIdx = pParse->nTab++;
103838 pKeyInfo = keyInfoFromExprList(pParse, pGroupBy);
103839 addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
103840 sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
103841 0, (char*)pKeyInfo, P4_KEYINFO);
103842
103843 /* Initialize memory locations used by GROUP BY aggregate processing
103844 */
103845 iUseFlag = ++pParse->nMem;
103846 iAbortFlag = ++pParse->nMem;
@@ -102817,11 +103950,11 @@
103950 sAggInfo.directMode = 1;
103951 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
103952 }
103953 }
103954 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
103955 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
103956 j1 = sqlite3VdbeCurrentAddr(v);
103957 sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
103958
103959 /* Generate code that runs whenever the GROUP BY changes.
103960 ** Changes in the GROUP BY are detected by the previous code
@@ -102943,17 +104076,17 @@
104076 pBest = pIdx;
104077 }
104078 }
104079 if( pBest ){
104080 iRoot = pBest->tnum;
104081 pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest);
104082 }
104083
104084 /* Open a read-only cursor, execute the OP_Count, close the cursor. */
104085 sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, iRoot, iDb, 1);
104086 if( pKeyInfo ){
104087 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
104088 }
104089 sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
104090 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
104091 explainSimpleCount(pParse, pTab, pBest);
104092 }else
@@ -104155,11 +105288,11 @@
105288 }
105289
105290 return 0;
105291 }
105292
105293 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
105294 /*
105295 ** This function is used to add VdbeComment() annotations to a VDBE
105296 ** program. It is not used in production code, only for debugging.
105297 */
105298 static const char *onErrorText(int onError){
@@ -104603,44 +105736,54 @@
105736 Expr *pWhere, /* The WHERE clause. May be null */
105737 int onError /* How to handle constraint errors */
105738 ){
105739 int i, j; /* Loop counters */
105740 Table *pTab; /* The table to be updated */
105741 int addrTop = 0; /* VDBE instruction address of the start of the loop */
105742 WhereInfo *pWInfo; /* Information about the WHERE clause */
105743 Vdbe *v; /* The virtual database engine */
105744 Index *pIdx; /* For looping over indices */
105745 Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
105746 int nIdx; /* Number of indices that need updating */
105747 int iDataCur; /* Cursor for the canonical data btree */
105748 int iIdxCur; /* Cursor for the first index */
105749 sqlite3 *db; /* The database structure */
105750 int *aRegIdx = 0; /* One register assigned to each index to be updated */
105751 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
105752 ** an expression for the i-th column of the table.
105753 ** aXRef[i]==-1 if the i-th column is not changed. */
105754 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105755 u8 chngRowid; /* Rowid changed in a normal table */
105756 u8 chngKey; /* Either chngPk or chngRowid */
105757 Expr *pRowidExpr = 0; /* Expression defining the new record number */
105758 int openAll = 0; /* True if all indices need to be opened */
105759 AuthContext sContext; /* The authorization context */
105760 NameContext sNC; /* The name-context to resolve expressions in */
105761 int iDb; /* Database containing the table being updated */
105762 int okOnePass; /* True for one-pass algorithm without the FIFO */
105763 int hasFK; /* True if foreign key processing is required */
105764 int labelBreak; /* Jump here to break out of UPDATE loop */
105765 int labelContinue; /* Jump here to continue next step of UPDATE loop */
105766
105767 #ifndef SQLITE_OMIT_TRIGGER
105768 int isView; /* True when updating a view (INSTEAD OF trigger) */
105769 Trigger *pTrigger; /* List of triggers on pTab, if required */
105770 int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
105771 #endif
105772 int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */
105773 int iEph = 0; /* Ephemeral table holding all primary key values */
105774 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
105775 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
105776
105777 /* Register Allocations */
105778 int regRowCount = 0; /* A count of rows changed */
105779 int regOldRowid; /* The old rowid */
105780 int regNewRowid; /* The new rowid */
105781 int regNew; /* Content of the NEW.* table in triggers */
105782 int regOld = 0; /* Content of OLD.* table in triggers */
105783 int regRowSet = 0; /* Rowset of rows to be updated */
105784 int regKey = 0; /* composite PRIMARY KEY value */
105785
105786 memset(&sContext, 0, sizeof(sContext));
105787 db = pParse->db;
105788 if( pParse->nErr || db->mallocFailed ){
105789 goto update_cleanup;
@@ -104683,12 +105826,18 @@
105826 /* Allocate a cursors for the main database table and for all indices.
105827 ** The index cursors might not be used, but if they are used they
105828 ** need to occur right after the database cursor. So go ahead and
105829 ** allocate enough space, just in case.
105830 */
105831 pTabList->a[0].iCursor = iDataCur = pParse->nTab++;
105832 iIdxCur = iDataCur+1;
105833 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105834 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105835 if( pIdx->autoIndex==2 && pPk!=0 ){
105836 iDataCur = pParse->nTab;
105837 pTabList->a[0].iCursor = iDataCur;
105838 }
105839 pParse->nTab++;
105840 }
105841
105842 /* Initialize the name-context */
105843 memset(&sNC, 0, sizeof(sNC));
@@ -104699,27 +105848,29 @@
105848 ** of the UPDATE statement. Also find the column index
105849 ** for each column to be updated in the pChanges array. For each
105850 ** column to be updated, make sure we have authorization to change
105851 ** that column.
105852 */
105853 chngRowid = chngPk = 0;
105854 for(i=0; i<pChanges->nExpr; i++){
105855 if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
105856 goto update_cleanup;
105857 }
105858 for(j=0; j<pTab->nCol; j++){
105859 if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
105860 if( j==pTab->iPKey ){
105861 chngRowid = 1;
105862 pRowidExpr = pChanges->a[i].pExpr;
105863 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
105864 chngPk = 1;
105865 }
105866 aXRef[j] = i;
105867 break;
105868 }
105869 }
105870 if( j>=pTab->nCol ){
105871 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zName) ){
105872 j = -1;
105873 chngRowid = 1;
105874 pRowidExpr = pChanges->a[i].pExpr;
105875 }else{
105876 sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
@@ -104739,30 +105890,33 @@
105890 aXRef[j] = -1;
105891 }
105892 }
105893 #endif
105894 }
105895 assert( (chngRowid & chngPk)==0 );
105896 assert( chngRowid==0 || chngRowid==1 );
105897 assert( chngPk==0 || chngPk==1 );
105898 chngKey = chngRowid + chngPk;
105899
105900 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
105901
105902 /* Allocate memory for the array aRegIdx[]. There is one entry in the
105903 ** array for each index associated with table being updated. Fill in
105904 ** the value with a register number for indices that are to be used
105905 ** and with zero for unused indices.
105906 */
 
105907 if( nIdx>0 ){
105908 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
105909 if( aRegIdx==0 ) goto update_cleanup;
105910 }
105911 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
105912 int reg;
105913 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
105914 reg = ++pParse->nMem;
105915 }else{
105916 reg = 0;
105917 for(i=0; i<pIdx->nKeyCol; i++){
105918 if( aXRef[pIdx->aiColumn[i]]>=0 ){
105919 reg = ++pParse->nMem;
105920 break;
105921 }
105922 }
@@ -104788,15 +105942,15 @@
105942 #endif
105943
105944 /* Allocate required registers. */
105945 regRowSet = ++pParse->nMem;
105946 regOldRowid = regNewRowid = ++pParse->nMem;
105947 if( chngPk || pTrigger || hasFK ){
105948 regOld = pParse->nMem + 1;
105949 pParse->nMem += pTab->nCol;
105950 }
105951 if( chngKey || pTrigger || hasFK ){
105952 regNewRowid = ++pParse->nMem;
105953 }
105954 regNew = pParse->nMem + 1;
105955 pParse->nMem += pTab->nCol;
105956
@@ -104808,11 +105962,11 @@
105962 /* If we are trying to update a view, realize that view into
105963 ** a ephemeral table.
105964 */
105965 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
105966 if( isView ){
105967 sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur);
105968 }
105969 #endif
105970
105971 /* Resolve the column names in all the expressions in the
105972 ** WHERE clause.
@@ -104821,43 +105975,81 @@
105975 goto update_cleanup;
105976 }
105977
105978 /* Begin the database scan
105979 */
105980 if( HasRowid(pTab) ){
105981 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
105982 pWInfo = sqlite3WhereBegin(
105983 pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, iIdxCur
105984 );
105985 if( pWInfo==0 ) goto update_cleanup;
105986 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
105987
105988 /* Remember the rowid of every item to be updated.
105989 */
105990 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
105991 if( !okOnePass ){
105992 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
105993 }
105994
105995 /* End the database scan loop.
105996 */
105997 sqlite3WhereEnd(pWInfo);
105998 }else{
105999 int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
106000 i16 nPk; /* Number of components of the PRIMARY KEY */
106001 int addrOpen; /* Address of the OpenEphemeral instruction */
106002
106003 assert( pPk!=0 );
106004 nPk = pPk->nKeyCol;
106005 iPk = pParse->nMem+1;
106006 pParse->nMem += nPk;
106007 regKey = ++pParse->nMem;
106008 iEph = pParse->nTab++;
106009 sqlite3VdbeAddOp2(v, OP_Null, 0, iPk);
106010 addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
106011 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
106012 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
106013 WHERE_ONEPASS_DESIRED, iIdxCur);
106014 if( pWInfo==0 ) goto update_cleanup;
106015 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
106016 for(i=0; i<nPk; i++){
106017 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
106018 iPk+i);
106019 }
106020 if( okOnePass ){
106021 sqlite3VdbeChangeToNoop(v, addrOpen);
106022 nKey = nPk;
106023 regKey = iPk;
106024 }else{
106025 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106026 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
106027 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106028 }
106029 sqlite3WhereEnd(pWInfo);
106030 }
106031
106032 /* Initialize the count of updated rows
106033 */
106034 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
106035 regRowCount = ++pParse->nMem;
106036 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
106037 }
106038
106039 labelBreak = sqlite3VdbeMakeLabel(v);
106040 if( !isView ){
106041 /*
106042 ** Open every index that needs updating. Note that if any
106043 ** index could potentially invoke a REPLACE conflict resolution
106044 ** action, then we need to open all indices because we might need
106045 ** to be deleting some records.
106046 */
106047 if( !okOnePass && HasRowid(pTab) ){
106048 sqlite3OpenTable(pParse, iDataCur, iDb, pTab, OP_OpenWrite);
106049 }
106050 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
106051 if( onError==OE_Replace ){
106052 openAll = 1;
106053 }else{
106054 openAll = 0;
106055 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
@@ -104866,59 +106058,71 @@
106058 break;
106059 }
106060 }
106061 }
106062 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106063 int iThisCur = iIdxCur+i;
106064 assert( aRegIdx );
106065 if( (openAll || aRegIdx[i]>0)
106066 && iThisCur!=aiCurOnePass[1]
106067 ){
106068 assert( iThisCur!=aiCurOnePass[0] );
106069 sqlite3VdbeAddOp3(v, OP_OpenWrite, iThisCur, pIdx->tnum, iDb);
106070 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
106071 assert( pParse->nTab>iThisCur );
106072 VdbeComment((v, "%s", pIdx->zName));
106073 if( okOnePass && pPk && iThisCur==iDataCur ){
106074 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak,
106075 regKey, nKey);
106076 }
106077 }
106078 }
106079 }
106080
106081 /* Top of the update loop */
106082 if( okOnePass ){
106083 labelContinue = labelBreak;
106084 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106085 }else if( pPk ){
106086 labelContinue = sqlite3VdbeMakeLabel(v);
106087 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
106088 addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106089 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
106090 }else{
106091 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106092 regOldRowid);
106093 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106094 }
106095
 
 
 
 
 
106096 /* If the record number will change, set register regNewRowid to
106097 ** contain the new value. If the record number is not being modified,
106098 ** then regNewRowid is the same register as regOldRowid, which is
106099 ** already populated. */
106100 assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
106101 if( chngRowid ){
106102 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
106103 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
106104 }
106105
106106 /* Compute the old pre-UPDATE content of the row being changed, if that
106107 ** information is needed */
106108 if( chngPk || hasFK || pTrigger ){
106109 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
106110 oldmask |= sqlite3TriggerColmask(pParse,
106111 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
106112 );
106113 for(i=0; i<pTab->nCol; i++){
106114 if( oldmask==0xffffffff
106115 || (i<32 && (oldmask & (1<<i)))
106116 || (pTab->aCol[i].colFlags & COLFLAG_PRIMKEY)!=0
106117 ){
106118 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regOld+i);
106119 }else{
106120 sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
106121 }
106122 }
106123 if( chngRowid==0 && pPk==0 ){
106124 sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);
106125 }
106126 }
106127
106128 /* Populate the array of registers beginning at regNew with the new
@@ -104951,12 +106155,11 @@
106155 ** if there are one or more BEFORE triggers that use this value via
106156 ** a new.* reference in a trigger program.
106157 */
106158 testcase( i==31 );
106159 testcase( i==32 );
106160 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
 
106161 }
106162 }
106163 }
106164
106165 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
@@ -104964,67 +106167,85 @@
106167 */
106168 if( tmask&TRIGGER_BEFORE ){
106169 sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
106170 sqlite3TableAffinityStr(v, pTab);
106171 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106172 TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
106173
106174 /* The row-trigger may have deleted the row being updated. In this
106175 ** case, jump to the next row. No updates or AFTER triggers are
106176 ** required. This behavior - what happens when the row being updated
106177 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
106178 ** documentation.
106179 */
106180 if( pPk ){
106181 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
106182 }else{
106183 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106184 }
106185
106186 /* If it did not delete it, the row-trigger may still have modified
106187 ** some of the columns of the row being updated. Load the values for
106188 ** all columns not modified by the update statement into their
106189 ** registers in case this has happened.
106190 */
106191 for(i=0; i<pTab->nCol; i++){
106192 if( aXRef[i]<0 && i!=pTab->iPKey ){
106193 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
 
106194 }
106195 }
106196 }
106197
106198 if( !isView ){
106199 int j1 = 0; /* Address of jump instruction */
106200 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
106201
106202 /* Do constraint checks. */
106203 assert( regOldRowid>0 );
106204 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
106205 regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace);
106206
106207 /* Do FK constraint checks. */
106208 if( hasFK ){
106209 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
106210 }
106211
106212 /* Delete the index entries associated with the current record. */
106213 if( bReplace || chngKey ){
106214 if( pPk ){
106215 j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106216 }else{
106217 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106218 }
106219 }
106220 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
106221
106222 /* If changing the record number, delete the old record. */
106223 if( hasFK || chngKey || pPk!=0 ){
106224 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
106225 }
106226 if( bReplace || chngKey ){
106227 if( sqlite3VdbeCurrentAddr(v)==j1+1 ){
106228 sqlite3VdbeChangeToNoop(v, j1);
106229 }else{
106230 sqlite3VdbeJumpHere(v, j1);
106231 }
106232 }
106233
106234 if( hasFK ){
106235 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
106236 }
106237
106238 /* Insert the new index entries and the new record. */
106239 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
106240 regNewRowid, aRegIdx, 1, 0, 0);
106241
106242 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
106243 ** handle rows (possibly in other tables) that refer via a foreign key
106244 ** to the row just updated. */
106245 if( hasFK ){
106246 sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngKey);
106247 }
106248 }
106249
106250 /* Increment the row counter
106251 */
@@ -105031,26 +106252,33 @@
106252 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
106253 sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1);
106254 }
106255
106256 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106257 TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue);
106258
106259 /* Repeat the above with the next record to be updated, until
106260 ** all record selected by the WHERE clause have been updated.
106261 */
106262 if( okOnePass ){
106263 /* Nothing to do at end-of-loop for a single-pass */
106264 }else if( pPk ){
106265 sqlite3VdbeResolveLabel(v, labelContinue);
106266 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop);
106267 }else{
106268 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106269 }
106270 sqlite3VdbeResolveLabel(v, labelBreak);
106271
106272 /* Close all tables */
106273 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106274 assert( aRegIdx );
106275 if( openAll || aRegIdx[i]>0 ){
106276 sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
106277 }
106278 }
106279 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
106280
106281 /* Update the sqlite_sequence table by storing the content of the
106282 ** maximum rowid counter values recorded while inserting into
106283 ** autoincrement tables.
106284 */
@@ -105418,11 +106646,11 @@
106646 ** in the temporary database.
106647 */
106648 rc = execExecSql(db, pzErrMsg,
106649 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
106650 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
106651 " AND coalesce(rootpage,1)>0"
106652 );
106653 if( rc!=SQLITE_OK ) goto end_of_vacuum;
106654 rc = execExecSql(db, pzErrMsg,
106655 "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
106656 " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
@@ -105439,11 +106667,11 @@
106667 rc = execExecSql(db, pzErrMsg,
106668 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
106669 "|| ' SELECT * FROM main.' || quote(name) || ';'"
106670 "FROM main.sqlite_master "
106671 "WHERE type = 'table' AND name!='sqlite_sequence' "
106672 " AND coalesce(rootpage,1)>0"
106673 );
106674 if( rc!=SQLITE_OK ) goto end_of_vacuum;
106675
106676 /* Copy over the sequence table
106677 */
@@ -107062,10 +108290,11 @@
108290 u8 nLevel; /* Number of nested loop */
108291 int iTop; /* The very beginning of the WHERE loop */
108292 int iContinue; /* Jump here to continue with next record */
108293 int iBreak; /* Jump here to break out of the loop */
108294 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
108295 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
108296 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
108297 WhereClause sWC; /* Decomposition of the WHERE clause */
108298 WhereLevel a[1]; /* Information about each nest loop in WHERE */
108299 };
108300
@@ -107154,12 +108383,23 @@
108383
108384 /*
108385 ** Return TRUE if an UPDATE or DELETE statement can operate directly on
108386 ** the rowids returned by a WHERE clause. Return FALSE if doing an
108387 ** UPDATE or DELETE might change subsequent WHERE clause results.
108388 **
108389 ** If the ONEPASS optimization is used (if this routine returns true)
108390 ** then also write the indices of open cursors used by ONEPASS
108391 ** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data
108392 ** table and iaCur[1] gets the cursor used by an auxiliary index.
108393 ** Either value may be -1, indicating that cursor is not used.
108394 ** Any cursors returned will have been opened for writing.
108395 **
108396 ** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
108397 ** unable to use the ONEPASS optimization.
108398 */
108399 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo, int *aiCur){
108400 memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);
108401 return pWInfo->okOnePass;
108402 }
108403
108404 /*
108405 ** Move the content of pSrc into pDest
@@ -107531,11 +108771,14 @@
108771 while( pScan->iEquiv<=pScan->nEquiv ){
108772 iCur = pScan->aEquiv[pScan->iEquiv-2];
108773 iColumn = pScan->aEquiv[pScan->iEquiv-1];
108774 while( (pWC = pScan->pWC)!=0 ){
108775 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
108776 if( pTerm->leftCursor==iCur
108777 && pTerm->u.leftColumn==iColumn
108778 && (pScan->iEquiv<=2 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
108779 ){
108780 if( (pTerm->eOperator & WO_EQUIV)!=0
108781 && pScan->nEquiv<ArraySize(pScan->aEquiv)
108782 ){
108783 int j;
108784 pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
@@ -107621,11 +108864,11 @@
108864 pScan->pOrigWC = pWC;
108865 pScan->pWC = pWC;
108866 if( pIdx && iColumn>=0 ){
108867 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
108868 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
108869 if( NEVER(j>=pIdx->nKeyCol) ) return 0;
108870 }
108871 pScan->zCollName = pIdx->azColl[j];
108872 }else{
108873 pScan->idxaff = 0;
108874 pScan->zCollName = 0;
@@ -108551,20 +109794,20 @@
109794 ** 3. All of those index columns for which the WHERE clause does not
109795 ** contain a "col=X" term are subject to a NOT NULL constraint.
109796 */
109797 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
109798 if( pIdx->onError==OE_None ) continue;
109799 for(i=0; i<pIdx->nKeyCol; i++){
109800 i16 iCol = pIdx->aiColumn[i];
109801 if( 0==findTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
109802 int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i);
109803 if( iIdxCol<0 || pTab->aCol[iCol].notNull==0 ){
109804 break;
109805 }
109806 }
109807 }
109808 if( i==pIdx->nKeyCol ){
109809 /* This index implies that the DISTINCT qualifier is redundant. */
109810 return 1;
109811 }
109812 }
109813
@@ -108658,26 +109901,25 @@
109901 WhereClause *pWC, /* The WHERE clause */
109902 struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
109903 Bitmask notReady, /* Mask of cursors that are not available */
109904 WhereLevel *pLevel /* Write new index here */
109905 ){
109906 int nKeyCol; /* Number of columns in the constructed index */
109907 WhereTerm *pTerm; /* A single term of the WHERE clause */
109908 WhereTerm *pWCEnd; /* End of pWC->a[] */
 
109909 Index *pIdx; /* Object describing the transient index */
109910 Vdbe *v; /* Prepared statement under construction */
109911 int addrInit; /* Address of the initialization bypass jump */
109912 Table *pTable; /* The table being indexed */
 
109913 int addrTop; /* Top of the index fill loop */
109914 int regRecord; /* Register holding an index record */
109915 int n; /* Column counter */
109916 int i; /* Loop counter */
109917 int mxBitCol; /* Maximum column in pSrc->colUsed */
109918 CollSeq *pColl; /* Collating sequence to on a column */
109919 WhereLoop *pLoop; /* The Loop object */
109920 char *zNotUsed; /* Extra space on the end of pIdx */
109921 Bitmask idxCols; /* Bitmap of columns used for indexing */
109922 Bitmask extraCols; /* Bitmap of additional columns */
109923 u8 sentWarning = 0; /* True if a warnning has been issued */
109924
109925 /* Generate code to skip over the creation and initialization of the
@@ -108686,11 +109928,11 @@
109928 assert( v!=0 );
109929 addrInit = sqlite3CodeOnce(pParse);
109930
109931 /* Count the number of columns that will be added to the index
109932 ** and used to match WHERE clause constraints */
109933 nKeyCol = 0;
109934 pTable = pSrc->pTab;
109935 pWCEnd = &pWC->a[pWC->nTerm];
109936 pLoop = pLevel->pWLoop;
109937 idxCols = 0;
109938 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
@@ -108704,18 +109946,18 @@
109946 "automatic index on %s(%s)", pTable->zName,
109947 pTable->aCol[iCol].zName);
109948 sentWarning = 1;
109949 }
109950 if( (idxCols & cMask)==0 ){
109951 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
109952 pLoop->aLTerm[nKeyCol++] = pTerm;
109953 idxCols |= cMask;
109954 }
109955 }
109956 }
109957 assert( nKeyCol>0 );
109958 pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;
109959 pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
109960 | WHERE_AUTO_INDEX;
109961
109962 /* Count the number of additional columns needed to create a
109963 ** covering index. A "covering index" is an index that contains all
@@ -108728,30 +109970,22 @@
109970 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
109971 mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
109972 testcase( pTable->nCol==BMS-1 );
109973 testcase( pTable->nCol==BMS-2 );
109974 for(i=0; i<mxBitCol; i++){
109975 if( extraCols & MASKBIT(i) ) nKeyCol++;
109976 }
109977 if( pSrc->colUsed & MASKBIT(BMS-1) ){
109978 nKeyCol += pTable->nCol - BMS + 1;
109979 }
109980 pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;
109981
109982 /* Construct the Index object to describe this index */
109983 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
 
 
 
 
109984 if( pIdx==0 ) return;
109985 pLoop->u.btree.pIndex = pIdx;
 
 
 
109986 pIdx->zName = "auto-index";
 
109987 pIdx->pTable = pTable;
109988 n = 0;
109989 idxCols = 0;
109990 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
109991 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -108785,24 +110019,25 @@
110019 pIdx->aiColumn[n] = i;
110020 pIdx->azColl[n] = "BINARY";
110021 n++;
110022 }
110023 }
110024 assert( n==nKeyCol );
110025 pIdx->aiColumn[n] = -1;
110026 pIdx->azColl[n] = "BINARY";
110027
110028 /* Create the automatic index */
 
110029 assert( pLevel->iIdxCur>=0 );
110030 pLevel->iIdxCur = pParse->nTab++;
110031 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110032 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
110033 VdbeComment((v, "for %s", pTable->zName));
110034
110035 /* Fill the automatic index with content */
110036 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
110037 regRecord = sqlite3GetTempReg(pParse);
110038 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0);
110039 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
110040 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
110041 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
110042 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
110043 sqlite3VdbeJumpHere(v, addrTop);
@@ -109045,11 +110280,11 @@
110280 iUpper = aSample[0].anLt[iCol];
110281 }else{
110282 iUpper = i>=pIdx->nSample ? pIdx->aiRowEst[0] : aSample[i].anLt[iCol];
110283 iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol];
110284 }
110285 aStat[1] = (pIdx->nKeyCol>iCol ? pIdx->aAvgEq[iCol] : 1);
110286 if( iLower>=iUpper ){
110287 iGap = 0;
110288 }else{
110289 iGap = iUpper - iLower;
110290 }
@@ -109145,11 +110380,11 @@
110380 ** of iUpper are requested of whereKeyStats() and the smaller used.
110381 */
110382 tRowcnt iLower;
110383 tRowcnt iUpper;
110384
110385 if( nEq==p->nKeyCol ){
110386 aff = SQLITE_AFF_INTEGER;
110387 }else{
110388 aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
110389 }
110390 /* Determine iLower and iUpper using ($P) only. */
@@ -109203,11 +110438,11 @@
110438 }
110439 if( nNew<nOut ){
110440 nOut = nNew;
110441 }
110442 pLoop->nOut = (LogEst)nOut;
110443 WHERETRACE(0x10, ("range scan regions: %u..%u est=%d\n",
110444 (u32)iLower, (u32)iUpper, nOut));
110445 return SQLITE_OK;
110446 }
110447 }
110448 #else
@@ -109263,11 +110498,11 @@
110498 int rc; /* Subfunction return code */
110499 tRowcnt a[2]; /* Statistics */
110500 int bOk;
110501
110502 assert( nEq>=1 );
110503 assert( nEq<=(p->nKeyCol+1) );
110504 assert( p->aSample!=0 );
110505 assert( p->nSample>0 );
110506 assert( pBuilder->nRecValid<nEq );
110507
110508 /* If values are not available for all fields of the index to the left
@@ -109276,11 +110511,11 @@
110511 return SQLITE_NOTFOUND;
110512 }
110513
110514 /* This is an optimization only. The call to sqlite3Stat4ProbeSetValue()
110515 ** below would return the same value. */
110516 if( nEq>p->nKeyCol ){
110517 *pnRow = 1;
110518 return SQLITE_OK;
110519 }
110520
110521 aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity;
@@ -109289,11 +110524,11 @@
110524 if( rc!=SQLITE_OK ) return rc;
110525 if( bOk==0 ) return SQLITE_NOTFOUND;
110526 pBuilder->nRecValid = nEq;
110527
110528 whereKeyStats(pParse, p, pRec, 0, a);
110529 WHERETRACE(0x10,("equality scan regions: %d\n", (int)a[1]));
110530 *pnRow = a[1];
110531
110532 return rc;
110533 }
110534 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -109337,11 +110572,11 @@
110572 }
110573
110574 if( rc==SQLITE_OK ){
110575 if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
110576 *pnRow = nRowEst;
110577 WHERETRACE(0x10,("IN row estimate: est=%g\n", nRowEst));
110578 }
110579 assert( pBuilder->nRecValid==nRecValid );
110580 return rc;
110581 }
110582 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -109663,31 +110898,31 @@
110898 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
110899 Index *pIndex = pLoop->u.btree.pIndex;
110900 int nEq = pLoop->u.btree.nEq;
110901 int i, j;
110902 Column *aCol = pTab->aCol;
110903 i16 *aiColumn = pIndex->aiColumn;
110904 StrAccum txt;
110905
110906 if( nEq==0 && (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ){
110907 return 0;
110908 }
110909 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
110910 txt.db = db;
110911 sqlite3StrAccumAppend(&txt, " (", 2);
110912 for(i=0; i<nEq; i++){
110913 char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
110914 explainAppendTerm(&txt, i, z, "=");
110915 }
110916
110917 j = i;
110918 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
110919 char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
110920 explainAppendTerm(&txt, i++, z, ">");
110921 }
110922 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
110923 char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
110924 explainAppendTerm(&txt, i, z, "<");
110925 }
110926 sqlite3StrAccumAppend(&txt, ")", 1);
110927 return sqlite3StrAccumFinish(&txt);
110928 }
@@ -109810,11 +111045,11 @@
111045 iCur = pTabItem->iCursor;
111046 pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
111047 bRev = (pWInfo->revMask>>iLevel)&1;
111048 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
111049 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
111050 VdbeNoopComment((v, "Begin WHERE-Loop %d: %s", iLevel,pTabItem->pTab->zName));
111051
111052 /* Create labels for the "break" and "continue" instructions
111053 ** for the current loop. Jump to addrBrk to break out of a loop.
111054 ** Jump to cont to go immediately to the next iteration of the
111055 ** loop.
@@ -110067,11 +111302,11 @@
111302 ** the first one after the nEq equality constraints in the index,
111303 ** this requires some special handling.
111304 */
111305 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111306 && (pWInfo->bOBSat!=0)
111307 && (pIdx->nKeyCol>nEq)
111308 ){
111309 /* assert( pOrderBy->nExpr==1 ); */
111310 /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
111311 isMinQuery = 1;
111312 nExtraReg = 1;
@@ -110100,12 +111335,12 @@
111335
111336 /* If we are doing a reverse order scan on an ascending index, or
111337 ** a forward order scan on a descending index, interchange the
111338 ** start and end terms (pRangeStart and pRangeEnd).
111339 */
111340 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111341 || (bRev && pIdx->nKeyCol==nEq)
111342 ){
111343 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
111344 }
111345
111346 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
@@ -110210,15 +111445,26 @@
111445 sqlite3ReleaseTempReg(pParse, r1);
111446
111447 /* Seek the table cursor, if required */
111448 disableTerm(pLevel, pRangeStart);
111449 disableTerm(pLevel, pRangeEnd);
111450 if( omitTable ){
111451 /* pIdx is a covering index. No need to access the main table. */
111452 }else if( HasRowid(pIdx->pTable) ){
111453 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
111454 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
111455 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111456 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
111457 }else{
111458 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
111459 iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
111460 for(j=0; j<pPk->nKeyCol; j++){
111461 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
111462 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
111463 }
111464 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
111465 iRowidReg, pPk->nKeyCol);
111466 }
111467
111468 /* Record the instruction used to terminate the loop. Disable
111469 ** WHERE clause terms made redundant by the index range scan.
111470 */
@@ -110541,27 +111787,43 @@
111787 }
111788 sqlite3ReleaseTempReg(pParse, iReleaseReg);
111789
111790 return pLevel->notReady;
111791 }
111792
111793 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
111794 /*
111795 ** Generate "Explanation" text for a WhereTerm.
111796 */
111797 static void whereExplainTerm(Vdbe *v, WhereTerm *pTerm){
111798 char zType[4];
111799 memcpy(zType, "...", 4);
111800 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
111801 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
111802 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
111803 sqlite3ExplainPrintf(v, "%s ", zType);
111804 sqlite3ExplainExpr(v, pTerm->pExpr);
111805 }
111806 #endif /* WHERETRACE_ENABLED && SQLITE_ENABLE_TREE_EXPLAIN */
111807
111808
111809 #ifdef WHERETRACE_ENABLED
111810 /*
111811 ** Print a WhereLoop object for debugging purposes
111812 */
111813 static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
111814 WhereInfo *pWInfo = pWC->pWInfo;
111815 int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
111816 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
111817 Table *pTab = pItem->pTab;
111818 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
111819 p->iTab, nb, p->maskSelf, nb, p->prereq);
111820 sqlite3DebugPrintf(" %12s",
111821 pItem->zAlias ? pItem->zAlias : pTab->zName);
111822 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
111823 const char *zName;
111824 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
 
111825 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
111826 int i = sqlite3Strlen30(zName) - 1;
111827 while( zName[i]!='_' ) i--;
111828 zName += i;
111829 }
@@ -110580,10 +111842,30 @@
111842 sqlite3DebugPrintf(" %-19s", z);
111843 sqlite3_free(z);
111844 }
111845 sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
111846 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
111847 #ifdef SQLITE_ENABLE_TREE_EXPLAIN
111848 /* If the 0x100 bit of wheretracing is set, then show all of the constraint
111849 ** expressions in the WhereLoop.aLTerm[] array.
111850 */
111851 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ /* WHERETRACE 0x100 */
111852 int i;
111853 Vdbe *v = pWInfo->pParse->pVdbe;
111854 sqlite3ExplainBegin(v);
111855 for(i=0; i<p->nLTerm; i++){
111856 WhereTerm *pTerm = p->aLTerm[i];
111857 sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111858 sqlite3ExplainPush(v);
111859 whereExplainTerm(v, pTerm);
111860 sqlite3ExplainPop(v);
111861 sqlite3ExplainNL(v);
111862 }
111863 sqlite3ExplainFinish(v);
111864 sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
111865 }
111866 #endif
111867 }
111868 #endif
111869
111870 /*
111871 ** Convert bulk memory into a valid WhereLoop that can be passed
@@ -110605,10 +111887,11 @@
111887 sqlite3_free(p->u.vtab.idxStr);
111888 p->u.vtab.needFree = 0;
111889 p->u.vtab.idxStr = 0;
111890 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
111891 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
111892 sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo);
111893 sqlite3DbFree(db, p->u.btree.pIndex);
111894 p->u.btree.pIndex = 0;
111895 }
111896 }
111897 }
@@ -110719,14 +112002,14 @@
112002 u16 n = pBuilder->pOrSet->n;
112003 int x =
112004 #endif
112005 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
112006 pTemplate->nOut);
112007 #if WHERETRACE_ENABLED /* 0x8 */
112008 if( sqlite3WhereTrace & 0x8 ){
112009 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
112010 whereLoopPrint(pTemplate, pBuilder->pWC);
112011 }
112012 #endif
112013 return SQLITE_OK;
112014 }
112015
@@ -110792,18 +112075,18 @@
112075
112076 /* If we reach this point it means that either p[] should be overwritten
112077 ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
112078 ** WhereLoop and insert it.
112079 */
112080 #if WHERETRACE_ENABLED /* 0x8 */
112081 if( sqlite3WhereTrace & 0x8 ){
112082 if( p!=0 ){
112083 sqlite3DebugPrintf("ins-del: ");
112084 whereLoopPrint(p, pBuilder->pWC);
112085 }
112086 sqlite3DebugPrintf("ins-new: ");
112087 whereLoopPrint(pTemplate, pBuilder->pWC);
112088 }
112089 #endif
112090 if( p==0 ){
112091 p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
112092 if( p==0 ) return SQLITE_NOMEM;
@@ -110820,14 +112103,14 @@
112103 }
112104 return SQLITE_OK;
112105
112106 /* Jump here if the insert is a no-op */
112107 whereLoopInsert_noop:
112108 #if WHERETRACE_ENABLED /* 0x8 */
112109 if( sqlite3WhereTrace & 0x8 ){
112110 sqlite3DebugPrintf("ins-noop: ");
112111 whereLoopPrint(pTemplate, pBuilder->pWC);
112112 }
112113 #endif
112114 return SQLITE_OK;
112115 }
112116
@@ -110904,12 +112187,12 @@
112187 }else{
112188 opMask = WO_EQ|WO_IN|WO_ISNULL|WO_GT|WO_GE|WO_LT|WO_LE;
112189 }
112190 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
112191
112192 assert( pNew->u.btree.nEq<=pProbe->nKeyCol );
112193 if( pNew->u.btree.nEq < pProbe->nKeyCol ){
112194 iCol = pProbe->aiColumn[pNew->u.btree.nEq];
112195 nRowEst = sqlite3LogEst(pProbe->aiRowEst[pNew->u.btree.nEq+1]);
112196 if( nRowEst==0 && pProbe->onError==OE_None ) nRowEst = 1;
112197 }else{
112198 iCol = -1;
@@ -110962,11 +112245,11 @@
112245 assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
112246 || nInMul==0 );
112247 pNew->wsFlags |= WHERE_COLUMN_EQ;
112248 if( iCol<0
112249 || (pProbe->onError!=OE_None && nInMul==0
112250 && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112251 ){
112252 assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
112253 pNew->wsFlags |= WHERE_ONEROW;
112254 }
112255 pNew->u.btree.nEq++;
@@ -111028,11 +112311,11 @@
112311 /* Step cost for each output row */
112312 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut);
112313 whereLoopOutputAdjust(pBuilder->pWC, pNew);
112314 rc = whereLoopInsert(pBuilder, pNew);
112315 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
112316 && pNew->u.btree.nEq<(pProbe->nKeyCol + (pProbe->zName!=0))
112317 ){
112318 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
112319 }
112320 pNew->nOut = saved_nOut;
112321 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -111067,11 +112350,11 @@
112350 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
112351 for(ii=0; ii<pOB->nExpr; ii++){
112352 Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr);
112353 if( pExpr->op!=TK_COLUMN ) return 0;
112354 if( pExpr->iTable==iCursor ){
112355 for(jj=0; jj<pIndex->nKeyCol; jj++){
112356 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
112357 }
112358 }
112359 }
112360 return 0;
@@ -111084,14 +112367,15 @@
112367 static Bitmask columnsInIndex(Index *pIdx){
112368 Bitmask m = 0;
112369 int j;
112370 for(j=pIdx->nColumn-1; j>=0; j--){
112371 int x = pIdx->aiColumn[j];
112372 if( x>=0 ){
112373 testcase( x==BMS-1 );
112374 testcase( x==BMS-2 );
112375 if( x<BMS-1 ) m |= MASKBIT(x);
112376 }
112377 }
112378 return m;
112379 }
112380
112381 /* Check to see if a partial index with pPartIndexWhere can be used
@@ -111117,11 +112401,11 @@
112401 ){
112402 WhereInfo *pWInfo; /* WHERE analysis context */
112403 Index *pProbe; /* An index we are evaluating */
112404 Index sPk; /* A fake index object for the primary key */
112405 tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
112406 i16 aiColumnPk = -1; /* The aColumn[] value for the sPk index */
112407 SrcList *pTabList; /* The FROM clause */
112408 struct SrcList_item *pSrc; /* The FROM clause btree term to add */
112409 WhereLoop *pNew; /* Template WhereLoop object */
112410 int rc = SQLITE_OK; /* Return code */
112411 int iSortIdx = 1; /* Index number */
@@ -111140,18 +112424,20 @@
112424 assert( !IsVirtual(pSrc->pTab) );
112425
112426 if( pSrc->pIndex ){
112427 /* An INDEXED BY clause specifies a particular index to use */
112428 pProbe = pSrc->pIndex;
112429 }else if( !HasRowid(pTab) ){
112430 pProbe = pTab->pIndex;
112431 }else{
112432 /* There is no INDEXED BY clause. Create a fake Index object in local
112433 ** variable sPk to represent the rowid primary key index. Make this
112434 ** fake index the first in a chain of Index objects with all of the real
112435 ** indices to follow */
112436 Index *pFirst; /* First of real indices on the table */
112437 memset(&sPk, 0, sizeof(Index));
112438 sPk.nKeyCol = 1;
112439 sPk.aiColumn = &aiColumnPk;
112440 sPk.aiRowEst = aiRowEstPk;
112441 sPk.onError = OE_Replace;
112442 sPk.pTable = pTab;
112443 aiRowEstPk[0] = pTab->nRowEst;
@@ -111172,10 +112458,11 @@
112458 if( !pBuilder->pOrSet
112459 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
112460 && pSrc->pIndex==0
112461 && !pSrc->viaCoroutine
112462 && !pSrc->notIndexed
112463 && HasRowid(pTab)
112464 && !pSrc->isCorrelated
112465 ){
112466 /* Generate auto-index WhereLoops */
112467 WhereTerm *pTerm;
112468 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
@@ -111234,18 +112521,25 @@
112521 whereLoopOutputAdjust(pWC, pNew);
112522 rc = whereLoopInsert(pBuilder, pNew);
112523 pNew->nOut = rSize;
112524 if( rc ) break;
112525 }else{
112526 Bitmask m;
112527 if( pProbe->isCovering ){
112528 pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
112529 m = 0;
112530 }else{
112531 m = pSrc->colUsed & ~columnsInIndex(pProbe);
112532 pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
112533 }
112534
112535 /* Full scan via index */
112536 if( b
112537 || !HasRowid(pTab)
112538 || ( m==0
112539 && pProbe->bUnordered==0
112540 && (pProbe->szIdxRow<pTab->szTabRow)
112541 && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
112542 && sqlite3GlobalConfig.bUseCis
112543 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan)
112544 )
112545 ){
@@ -111257,11 +112551,10 @@
112551 ** is smaller for smaller indices, thus favoring them.
112552 */
112553 pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 1 +
112554 (15*pProbe->szIdxRow)/pTab->szTabRow;
112555 }else{
 
112556 /* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N)
112557 ** which we will simplify to just N*log2(N) */
112558 pNew->rRun = rSize + rLogSize;
112559 }
112560 whereLoopOutputAdjust(pWC, pNew);
@@ -111473,10 +112766,11 @@
112766 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
112767 pWCEnd = pWC->a + pWC->nTerm;
112768 pNew = pBuilder->pNew;
112769 memset(&sSum, 0, sizeof(sSum));
112770 pItem = pWInfo->pTabList->a + pNew->iTab;
112771 if( !HasRowid(pItem->pTab) ) return SQLITE_OK;
112772 iCur = pItem->iCursor;
112773
112774 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
112775 if( (pTerm->eOperator & WO_OR)!=0
112776 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
@@ -111622,11 +112916,12 @@
112916 u8 rev; /* Composite sort order */
112917 u8 revIdx; /* Index sort order */
112918 u8 isOrderDistinct; /* All prior WhereLoops are order-distinct */
112919 u8 distinctColumns; /* True if the loop has UNIQUE NOT NULL columns */
112920 u8 isMatch; /* iColumn matches a term of the ORDER BY clause */
112921 u16 nKeyCol; /* Number of key columns in pIndex */
112922 u16 nColumn; /* Total number of ordered columns in the index */
112923 u16 nOrderBy; /* Number terms in the ORDER BY clause */
112924 int iLoop; /* Index of WhereLoop in pPath being processed */
112925 int i, j; /* Loop counters */
112926 int iCur; /* Cursor number for current WhereLoop */
112927 int iColumn; /* A column number within table iCur */
@@ -111714,24 +113009,28 @@
113009 }
113010
113011 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
113012 if( pLoop->wsFlags & WHERE_IPK ){
113013 pIndex = 0;
113014 nKeyCol = 0;
113015 nColumn = 1;
113016 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
113017 return 0;
113018 }else{
113019 nKeyCol = pIndex->nKeyCol;
113020 nColumn = pIndex->nColumn;
113021 assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
113022 assert( pIndex->aiColumn[nColumn-1]==(-1) || !HasRowid(pIndex->pTable));
113023 isOrderDistinct = pIndex->onError!=OE_None;
113024 }
113025
113026 /* Loop through all columns of the index and deal with the ones
113027 ** that are not constrained by == or IN.
113028 */
113029 rev = revSet = 0;
113030 distinctColumns = 0;
113031 for(j=0; j<nColumn; j++){
113032 u8 bOnce; /* True to run the ORDER BY search loop */
113033
113034 /* Skip over == and IS NULL terms */
113035 if( j<pLoop->u.btree.nEq
113036 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
@@ -111744,24 +113043,21 @@
113043 }
113044
113045 /* Get the column number in the table (iColumn) and sort order
113046 ** (revIdx) for the j-th column of the index.
113047 */
113048 if( pIndex ){
 
113049 iColumn = pIndex->aiColumn[j];
113050 revIdx = pIndex->aSortOrder[j];
113051 if( iColumn==pIndex->pTable->iPKey ) iColumn = -1;
113052 }else{
 
 
113053 iColumn = -1;
113054 revIdx = 0;
113055 }
113056
113057 /* An unconstrained column that might be NULL means that this
113058 ** WhereLoop is not well-ordered
113059 */
113060 if( isOrderDistinct
113061 && iColumn>=0
113062 && j>=pLoop->u.btree.nEq
113063 && pIndex->pTable->aCol[iColumn].notNull==0
@@ -111808,11 +113104,11 @@
113104 revSet = 1;
113105 }
113106 }
113107 }else{
113108 /* No match found */
113109 if( j==0 || j<nKeyCol ){
113110 testcase( isOrderDistinct!=0 );
113111 isOrderDistinct = 0;
113112 }
113113 break;
113114 }
@@ -111981,11 +113277,11 @@
113277 break;
113278 }
113279 }
113280 if( jj>=nTo ){
113281 if( nTo>=mxChoice && rCost>=mxCost ){
113282 #ifdef WHERETRACE_ENABLED /* 0x4 */
113283 if( sqlite3WhereTrace&0x4 ){
113284 sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
113285 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
113286 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
113287 }
@@ -111999,20 +113295,20 @@
113295 }else{
113296 /* New path replaces the prior worst to keep count below mxChoice */
113297 jj = mxI;
113298 }
113299 pTo = &aTo[jj];
113300 #ifdef WHERETRACE_ENABLED /* 0x4 */
113301 if( sqlite3WhereTrace&0x4 ){
113302 sqlite3DebugPrintf("New %s cost=%-3d,%3d order=%c\n",
113303 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
113304 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
113305 }
113306 #endif
113307 }else{
113308 if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
113309 #ifdef WHERETRACE_ENABLED /* 0x4 */
113310 if( sqlite3WhereTrace&0x4 ){
113311 sqlite3DebugPrintf(
113312 "Skip %s cost=%-3d,%3d order=%c",
113313 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
113314 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -112024,11 +113320,11 @@
113320 testcase( pTo->rCost==rCost );
113321 continue;
113322 }
113323 testcase( pTo->rCost==rCost+1 );
113324 /* A new and better score for a previously created equivalent path */
113325 #ifdef WHERETRACE_ENABLED /* 0x4 */
113326 if( sqlite3WhereTrace&0x4 ){
113327 sqlite3DebugPrintf(
113328 "Update %s cost=%-3d,%3d order=%c",
113329 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
113330 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -112060,11 +113356,11 @@
113356 }
113357 }
113358 }
113359 }
113360
113361 #ifdef WHERETRACE_ENABLED /* >=2 */
113362 if( sqlite3WhereTrace>=2 ){
113363 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
113364 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
113365 sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
113366 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
@@ -112174,20 +113470,20 @@
113470 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
113471 assert( pLoop->aLTermSpace==pLoop->aLTerm );
113472 assert( ArraySize(pLoop->aLTermSpace)==4 );
113473 if( pIdx->onError==OE_None
113474 || pIdx->pPartIdxWhere!=0
113475 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
113476 ) continue;
113477 for(j=0; j<pIdx->nKeyCol; j++){
113478 pTerm = findTerm(pWC, iCur, pIdx->aiColumn[j], 0, WO_EQ, pIdx);
113479 if( pTerm==0 ) break;
113480 pLoop->aLTerm[j] = pTerm;
113481 }
113482 if( j!=pIdx->nKeyCol ) continue;
113483 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW|WHERE_INDEXED;
113484 if( pIdx->isCovering || (pItem->colUsed & ~columnsInIndex(pIdx))==0 ){
113485 pLoop->wsFlags |= WHERE_IDX_ONLY;
113486 }
113487 pLoop->nLTerm = j;
113488 pLoop->u.btree.nEq = j;
113489 pLoop->u.btree.pIndex = pIdx;
@@ -112291,10 +113587,18 @@
113587 **
113588 ** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
113589 ** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
113590 ** if there is one. If there is no ORDER BY clause or if this routine
113591 ** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
113592 **
113593 ** The iIdxCur parameter is the cursor number of an index. If
113594 ** WHERE_ONETABLE_ONLY is set, iIdxCur is the cursor number of an index
113595 ** to use for OR clause processing. The WHERE clause should use this
113596 ** specific cursor. If WHERE_ONEPASS_DESIRED is set, then iIdxCur is
113597 ** the first cursor in an array of cursors for all indices. iIdxCur should
113598 ** be used to compute the appropriate cursor depending on which index is
113599 ** used.
113600 */
113601 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
113602 Parse *pParse, /* The parser context */
113603 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
113604 Expr *pWhere, /* The WHERE clause */
@@ -112356,10 +113660,11 @@
113660 if( db->mallocFailed ){
113661 sqlite3DbFree(db, pWInfo);
113662 pWInfo = 0;
113663 goto whereBeginError;
113664 }
113665 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
113666 pWInfo->nLevel = nTabList;
113667 pWInfo->pParse = pParse;
113668 pWInfo->pTabList = pTabList;
113669 pWInfo->pOrderBy = pOrderBy;
113670 pWInfo->pResultSet = pResultSet;
@@ -112469,24 +113774,41 @@
113774 }
113775 }
113776
113777 /* Construct the WhereLoop objects */
113778 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
113779 /* Display all terms of the WHERE clause */
113780 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
113781 if( sqlite3WhereTrace & 0x100 ){
113782 int i;
113783 Vdbe *v = pParse->pVdbe;
113784 sqlite3ExplainBegin(v);
113785 for(i=0; i<sWLB.pWC->nTerm; i++){
113786 sqlite3ExplainPrintf(v, "#%-2d ", i);
113787 sqlite3ExplainPush(v);
113788 whereExplainTerm(v, &sWLB.pWC->a[i]);
113789 sqlite3ExplainPop(v);
113790 sqlite3ExplainNL(v);
113791 }
113792 sqlite3ExplainFinish(v);
113793 sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
113794 }
113795 #endif
113796 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
113797 rc = whereLoopAddAll(&sWLB);
113798 if( rc ) goto whereBeginError;
113799
113800 /* Display all of the WhereLoop objects if wheretrace is enabled */
113801 #ifdef WHERETRACE_ENABLED /* !=0 */
113802 if( sqlite3WhereTrace ){
113803 WhereLoop *p;
113804 int i;
113805 static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
113806 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
113807 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
113808 p->cId = zLabel[i%sizeof(zLabel)];
113809 whereLoopPrint(p, sWLB.pWC);
113810 }
113811 }
113812 #endif
113813
113814 wherePathSolver(pWInfo, 0);
@@ -112500,11 +113822,11 @@
113822 pWInfo->revMask = (Bitmask)(-1);
113823 }
113824 if( pParse->nErr || NEVER(db->mallocFailed) ){
113825 goto whereBeginError;
113826 }
113827 #ifdef WHERETRACE_ENABLED /* !=0 */
113828 if( sqlite3WhereTrace ){
113829 int ii;
113830 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
113831 if( pWInfo->bOBSat ){
113832 sqlite3DebugPrintf(" ORDERBY=0x%llx", pWInfo->revMask);
@@ -112523,11 +113845,11 @@
113845 break;
113846 }
113847 }
113848 sqlite3DebugPrintf("\n");
113849 for(ii=0; ii<pWInfo->nLevel; ii++){
113850 whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
113851 }
113852 }
113853 #endif
113854 /* Attempt to omit tables from the join that do not effect the result */
113855 if( pWInfo->nLevel>=2
@@ -112570,11 +113892,13 @@
113892 */
113893 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
113894 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
113895 && (pWInfo->a[0].pWLoop->wsFlags & WHERE_ONEROW)!=0 ){
113896 pWInfo->okOnePass = 1;
113897 if( HasRowid(pTabList->a[0].pTab) ){
113898 pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY;
113899 }
113900 }
113901
113902 /* Open all tables in the pTabList and any indices selected for
113903 ** searching those tables.
113904 */
@@ -112600,15 +113924,20 @@
113924 /* noop */
113925 }else
113926 #endif
113927 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
113928 && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){
113929 int op = OP_OpenRead;
113930 if( pWInfo->okOnePass ){
113931 op = OP_OpenWrite;
113932 pWInfo->aiCurOnePass[0] = pTabItem->iCursor;
113933 };
113934 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
113935 assert( pTabItem->iCursor==pLevel->iTabCur );
113936 testcase( !pWInfo->okOnePass && pTab->nCol==BMS-1 );
113937 testcase( !pWInfo->okOnePass && pTab->nCol==BMS );
113938 if( !pWInfo->okOnePass && pTab->nCol<BMS && HasRowid(pTab) ){
113939 Bitmask b = pTabItem->colUsed;
113940 int n = 0;
113941 for(; b; b=b>>1, n++){}
113942 sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1,
113943 SQLITE_INT_TO_PTR(n), P4_INT32);
@@ -112617,17 +113946,34 @@
113946 }else{
113947 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
113948 }
113949 if( pLoop->wsFlags & WHERE_INDEXED ){
113950 Index *pIx = pLoop->u.btree.pIndex;
113951 int iIndexCur;
113952 int op = OP_OpenRead;
113953 /* iIdxCur is always set if to a positive value if ONEPASS is possible */
113954 assert( iIdxCur!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
113955 if( pWInfo->okOnePass ){
113956 Index *pJ = pTabItem->pTab->pIndex;
113957 iIndexCur = iIdxCur;
113958 assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
113959 while( ALWAYS(pJ) && pJ!=pIx ){
113960 iIndexCur++;
113961 pJ = pJ->pNext;
113962 }
113963 op = OP_OpenWrite;
113964 pWInfo->aiCurOnePass[1] = iIndexCur;
113965 }else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){
113966 iIndexCur = iIdxCur;
113967 }else{
113968 iIndexCur = pParse->nTab++;
113969 }
113970 pLevel->iIdxCur = iIndexCur;
113971 assert( pIx->pSchema==pTab->pSchema );
113972 assert( iIndexCur>=0 );
113973 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
113974 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
113975 VdbeComment((v, "%s", pIx->zName));
113976 }
113977 sqlite3CodeVerifySchema(pParse, iDb);
113978 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
113979 }
@@ -112718,35 +114064,44 @@
114064 }else{
114065 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
114066 }
114067 sqlite3VdbeJumpHere(v, addr);
114068 }
114069 VdbeNoopComment((v, "End WHERE-Loop %d: %s", i,
114070 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
114071 }
114072
114073 /* The "break" point is here, just past the end of the outer loop.
114074 ** Set it.
114075 */
114076 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
114077
 
 
114078 assert( pWInfo->nLevel<=pTabList->nSrc );
114079 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
114080 Index *pIdx = 0;
114081 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
114082 Table *pTab = pTabItem->pTab;
114083 assert( pTab!=0 );
114084 pLoop = pLevel->pWLoop;
114085
114086 /* Close all of the cursors that were opened by sqlite3WhereBegin.
114087 ** Except, do not close cursors that will be reused by the OR optimization
114088 ** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114089 ** created for the ONEPASS optimization.
114090 */
114091 if( (pTab->tabFlags & TF_Ephemeral)==0
114092 && pTab->pSelect==0
114093 && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
114094 ){
114095 int ws = pLoop->wsFlags;
114096 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
114097 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
114098 }
114099 if( (ws & WHERE_INDEXED)!=0
114100 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0
114101 && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
114102 ){
114103 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
114104 }
114105 }
114106
114107 /* If this scan uses an index, make VDBE code substitutions to read data
@@ -112764,27 +114119,31 @@
114119 pIdx = pLoop->u.btree.pIndex;
114120 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
114121 pIdx = pLevel->u.pCovidx;
114122 }
114123 if( pIdx && !db->mallocFailed ){
114124 int k, last;
114125 VdbeOp *pOp;
114126
114127 last = sqlite3VdbeCurrentAddr(v);
114128 k = pLevel->addrBody;
114129 pOp = sqlite3VdbeGetOp(v, k);
114130 for(; k<last; k++, pOp++){
114131 if( pOp->p1!=pLevel->iTabCur ) continue;
114132 if( pOp->opcode==OP_Column ){
114133 int x = pOp->p2;
114134 assert( pIdx->pTable==pTab );
114135 if( !HasRowid(pTab) ){
114136 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
114137 x = pPk->aiColumn[x];
114138 }
114139 x = sqlite3ColumnOfIndex(pIdx, x);
114140 if( x>=0 ){
114141 pOp->p2 = x;
114142 pOp->p1 = pLevel->iIdxCur;
114143 }
114144 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 );
114145 }else if( pOp->opcode==OP_Rowid ){
114146 pOp->p1 = pLevel->iIdxCur;
114147 pOp->opcode = OP_IdxRowid;
114148 }
114149 }
@@ -112988,42 +114347,42 @@
114347 ** YYNRULE the number of rules in the grammar
114348 ** YYERRORSYMBOL is the code number of the error symbol. If not
114349 ** defined, then do no error processing.
114350 */
114351 #define YYCODETYPE unsigned char
114352 #define YYNOCODE 253
114353 #define YYACTIONTYPE unsigned short int
114354 #define YYWILDCARD 68
114355 #define sqlite3ParserTOKENTYPE Token
114356 typedef union {
114357 int yyinit;
114358 sqlite3ParserTOKENTYPE yy0;
114359 int yy4;
114360 struct TrigEvent yy90;
114361 ExprSpan yy118;
114362 u16 yy177;
114363 TriggerStep* yy203;
114364 u8 yy210;
114365 struct {int value; int mask;} yy215;
114366 SrcList* yy259;
114367 struct ValueList yy260;
114368 struct LimitVal yy292;
114369 Expr* yy314;
114370 ExprList* yy322;
114371 struct LikeOp yy342;
114372 IdList* yy384;
114373 Select* yy387;
114374 } YYMINORTYPE;
114375 #ifndef YYSTACKDEPTH
114376 #define YYSTACKDEPTH 100
114377 #endif
114378 #define sqlite3ParserARG_SDECL Parse *pParse;
114379 #define sqlite3ParserARG_PDECL ,Parse *pParse
114380 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
114381 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
114382 #define YYNSTATE 631
114383 #define YYNRULE 329
114384 #define YYFALLBACK 1
114385 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
114386 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
114387 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
114388
@@ -113089,478 +114448,484 @@
114448 ** shifting terminals.
114449 ** yy_reduce_ofst[] For each state, the offset into yy_action for
114450 ** shifting non-terminals after a reduce.
114451 ** yy_default[] Default action for each state.
114452 */
114453 #define YY_ACTTAB_COUNT (1582)
114454 static const YYACTIONTYPE yy_action[] = {
114455 /* 0 */ 312, 961, 185, 420, 2, 171, 516, 515, 597, 56,
114456 /* 10 */ 56, 56, 56, 49, 54, 54, 54, 54, 53, 53,
114457 /* 20 */ 52, 52, 52, 51, 234, 197, 196, 195, 624, 623,
114458 /* 30 */ 301, 590, 584, 56, 56, 56, 56, 156, 54, 54,
114459 /* 40 */ 54, 54, 53, 53, 52, 52, 52, 51, 234, 628,
114460 /* 50 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114461 /* 60 */ 56, 56, 56, 466, 54, 54, 54, 54, 53, 53,
114462 /* 70 */ 52, 52, 52, 51, 234, 312, 597, 52, 52, 52,
114463 /* 80 */ 51, 234, 33, 54, 54, 54, 54, 53, 53, 52,
114464 /* 90 */ 52, 52, 51, 234, 624, 623, 621, 620, 165, 624,
114465 /* 100 */ 623, 383, 380, 379, 214, 328, 590, 584, 624, 623,
114466 /* 110 */ 467, 59, 378, 619, 618, 617, 53, 53, 52, 52,
114467 /* 120 */ 52, 51, 234, 506, 507, 57, 58, 48, 582, 581,
114468 /* 130 */ 583, 583, 55, 55, 56, 56, 56, 56, 30, 54,
114469 /* 140 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114470 /* 150 */ 312, 50, 47, 146, 233, 232, 207, 474, 256, 349,
114471 /* 160 */ 255, 475, 621, 620, 554, 438, 298, 621, 620, 236,
114472 /* 170 */ 674, 435, 440, 553, 439, 366, 621, 620, 540, 224,
114473 /* 180 */ 551, 590, 584, 176, 138, 282, 386, 277, 385, 168,
114474 /* 190 */ 600, 422, 951, 548, 622, 951, 273, 572, 572, 566,
114475 /* 200 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114476 /* 210 */ 56, 56, 56, 354, 54, 54, 54, 54, 53, 53,
114477 /* 220 */ 52, 52, 52, 51, 234, 312, 561, 526, 62, 675,
114478 /* 230 */ 132, 595, 410, 348, 579, 579, 492, 426, 577, 419,
114479 /* 240 */ 627, 65, 329, 560, 441, 237, 676, 123, 607, 67,
114480 /* 250 */ 542, 532, 622, 170, 205, 500, 590, 584, 166, 559,
114481 /* 260 */ 622, 403, 593, 593, 593, 442, 443, 271, 422, 950,
114482 /* 270 */ 166, 223, 950, 483, 190, 57, 58, 48, 582, 581,
114483 /* 280 */ 583, 583, 55, 55, 56, 56, 56, 56, 600, 54,
114484 /* 290 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114485 /* 300 */ 312, 441, 412, 376, 175, 165, 166, 391, 383, 380,
114486 /* 310 */ 379, 342, 412, 203, 426, 66, 392, 622, 415, 378,
114487 /* 320 */ 597, 166, 442, 338, 444, 571, 601, 74, 415, 624,
114488 /* 330 */ 623, 590, 584, 624, 623, 174, 601, 92, 333, 171,
114489 /* 340 */ 1, 410, 597, 579, 579, 624, 623, 600, 306, 425,
114490 /* 350 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114491 /* 360 */ 56, 56, 56, 580, 54, 54, 54, 54, 53, 53,
114492 /* 370 */ 52, 52, 52, 51, 234, 312, 472, 262, 399, 68,
114493 /* 380 */ 412, 339, 571, 389, 624, 623, 578, 602, 597, 589,
114494 /* 390 */ 588, 603, 412, 622, 423, 533, 415, 621, 620, 513,
114495 /* 400 */ 257, 621, 620, 166, 601, 91, 590, 584, 415, 45,
114496 /* 410 */ 597, 586, 585, 621, 620, 250, 601, 92, 39, 347,
114497 /* 420 */ 576, 336, 597, 547, 567, 57, 58, 48, 582, 581,
114498 /* 430 */ 583, 583, 55, 55, 56, 56, 56, 56, 587, 54,
114499 /* 440 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114500 /* 450 */ 312, 561, 621, 620, 531, 291, 470, 188, 399, 375,
114501 /* 460 */ 247, 492, 249, 350, 412, 476, 476, 368, 560, 299,
114502 /* 470 */ 334, 412, 281, 482, 67, 565, 410, 622, 579, 579,
114503 /* 480 */ 415, 590, 584, 280, 559, 467, 520, 415, 601, 92,
114504 /* 490 */ 597, 167, 544, 36, 877, 601, 16, 519, 564, 6,
114505 /* 500 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114506 /* 510 */ 56, 56, 56, 200, 54, 54, 54, 54, 53, 53,
114507 /* 520 */ 52, 52, 52, 51, 234, 312, 183, 412, 236, 528,
114508 /* 530 */ 395, 535, 358, 256, 349, 255, 397, 412, 248, 182,
114509 /* 540 */ 353, 359, 549, 415, 236, 317, 563, 50, 47, 146,
114510 /* 550 */ 273, 601, 73, 415, 7, 311, 590, 584, 568, 493,
114511 /* 560 */ 213, 601, 92, 233, 232, 410, 173, 579, 579, 330,
114512 /* 570 */ 575, 574, 631, 629, 332, 57, 58, 48, 582, 581,
114513 /* 580 */ 583, 583, 55, 55, 56, 56, 56, 56, 199, 54,
114514 /* 590 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114515 /* 600 */ 312, 492, 340, 320, 511, 505, 572, 572, 460, 562,
114516 /* 610 */ 549, 170, 145, 430, 67, 558, 410, 622, 579, 579,
114517 /* 620 */ 384, 236, 600, 412, 408, 575, 574, 504, 572, 572,
114518 /* 630 */ 571, 590, 584, 353, 198, 143, 268, 549, 316, 415,
114519 /* 640 */ 306, 424, 207, 50, 47, 146, 167, 601, 69, 546,
114520 /* 650 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114521 /* 660 */ 56, 56, 56, 555, 54, 54, 54, 54, 53, 53,
114522 /* 670 */ 52, 52, 52, 51, 234, 312, 600, 326, 412, 270,
114523 /* 680 */ 145, 264, 274, 266, 459, 571, 423, 35, 412, 568,
114524 /* 690 */ 407, 213, 428, 388, 415, 308, 212, 143, 622, 354,
114525 /* 700 */ 317, 12, 601, 94, 415, 549, 590, 584, 50, 47,
114526 /* 710 */ 146, 365, 601, 97, 552, 362, 318, 147, 602, 361,
114527 /* 720 */ 325, 15, 603, 187, 206, 57, 58, 48, 582, 581,
114528 /* 730 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114529 /* 740 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114530 /* 750 */ 312, 412, 35, 412, 415, 22, 630, 2, 600, 50,
114531 /* 760 */ 47, 146, 601, 95, 412, 485, 510, 415, 412, 415,
114532 /* 770 */ 412, 11, 235, 486, 412, 601, 104, 601, 103, 19,
114533 /* 780 */ 415, 590, 584, 352, 415, 40, 415, 38, 601, 105,
114534 /* 790 */ 415, 32, 601, 106, 601, 133, 544, 169, 601, 134,
114535 /* 800 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114536 /* 810 */ 56, 56, 56, 412, 54, 54, 54, 54, 53, 53,
114537 /* 820 */ 52, 52, 52, 51, 234, 312, 412, 274, 412, 415,
114538 /* 830 */ 412, 274, 274, 274, 201, 230, 721, 601, 98, 484,
114539 /* 840 */ 427, 307, 415, 622, 415, 540, 415, 622, 622, 622,
114540 /* 850 */ 601, 102, 601, 101, 601, 93, 590, 584, 262, 21,
114541 /* 860 */ 129, 622, 522, 521, 554, 222, 469, 521, 600, 324,
114542 /* 870 */ 323, 322, 211, 553, 622, 57, 58, 48, 582, 581,
114543 /* 880 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114544 /* 890 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114545 /* 900 */ 312, 412, 261, 412, 415, 412, 600, 210, 625, 367,
114546 /* 910 */ 51, 234, 601, 100, 538, 606, 142, 415, 355, 415,
114547 /* 920 */ 412, 415, 412, 496, 622, 601, 77, 601, 96, 601,
114548 /* 930 */ 137, 590, 584, 530, 622, 529, 415, 141, 415, 28,
114549 /* 940 */ 524, 600, 229, 544, 601, 136, 601, 135, 604, 204,
114550 /* 950 */ 57, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114551 /* 960 */ 56, 56, 56, 412, 54, 54, 54, 54, 53, 53,
114552 /* 970 */ 52, 52, 52, 51, 234, 312, 412, 360, 412, 415,
114553 /* 980 */ 412, 360, 286, 600, 503, 220, 127, 601, 76, 629,
114554 /* 990 */ 332, 382, 415, 622, 415, 540, 415, 622, 412, 613,
114555 /* 1000 */ 601, 90, 601, 89, 601, 75, 590, 584, 341, 272,
114556 /* 1010 */ 377, 622, 126, 27, 415, 622, 164, 544, 125, 280,
114557 /* 1020 */ 373, 122, 601, 88, 480, 57, 46, 48, 582, 581,
114558 /* 1030 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114559 /* 1040 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114560 /* 1050 */ 312, 412, 360, 412, 415, 412, 284, 186, 369, 321,
114561 /* 1060 */ 477, 170, 601, 87, 121, 473, 221, 415, 622, 415,
114562 /* 1070 */ 254, 415, 412, 355, 412, 601, 99, 601, 86, 601,
114563 /* 1080 */ 17, 590, 584, 259, 612, 120, 159, 158, 415, 622,
114564 /* 1090 */ 415, 14, 465, 157, 462, 25, 601, 85, 601, 84,
114565 /* 1100 */ 622, 58, 48, 582, 581, 583, 583, 55, 55, 56,
114566 /* 1110 */ 56, 56, 56, 412, 54, 54, 54, 54, 53, 53,
114567 /* 1120 */ 52, 52, 52, 51, 234, 312, 412, 262, 412, 415,
114568 /* 1130 */ 412, 262, 118, 611, 117, 24, 10, 601, 83, 351,
114569 /* 1140 */ 216, 219, 415, 622, 415, 608, 415, 622, 412, 622,
114570 /* 1150 */ 601, 72, 601, 71, 601, 82, 590, 584, 262, 4,
114571 /* 1160 */ 605, 622, 458, 115, 415, 456, 252, 154, 452, 110,
114572 /* 1170 */ 108, 453, 601, 81, 622, 451, 622, 48, 582, 581,
114573 /* 1180 */ 583, 583, 55, 55, 56, 56, 56, 56, 412, 54,
114574 /* 1190 */ 54, 54, 54, 53, 53, 52, 52, 52, 51, 234,
114575 /* 1200 */ 44, 406, 450, 3, 415, 412, 262, 107, 416, 623,
114576 /* 1210 */ 446, 437, 601, 80, 436, 335, 238, 189, 411, 409,
114577 /* 1220 */ 594, 415, 622, 44, 406, 401, 3, 412, 557, 601,
114578 /* 1230 */ 70, 416, 623, 412, 622, 149, 622, 421, 404, 64,
114579 /* 1240 */ 412, 622, 409, 415, 622, 331, 139, 148, 566, 415,
114580 /* 1250 */ 449, 601, 18, 228, 124, 626, 415, 601, 79, 315,
114581 /* 1260 */ 181, 404, 412, 545, 601, 78, 262, 541, 41, 42,
114582 /* 1270 */ 534, 566, 390, 202, 262, 43, 414, 413, 415, 622,
114583 /* 1280 */ 595, 314, 622, 622, 180, 539, 601, 92, 415, 276,
114584 /* 1290 */ 622, 41, 42, 509, 616, 615, 601, 9, 43, 414,
114585 /* 1300 */ 413, 622, 418, 595, 262, 622, 275, 600, 614, 622,
114586 /* 1310 */ 218, 593, 593, 593, 592, 591, 13, 178, 217, 417,
114587 /* 1320 */ 622, 236, 622, 44, 406, 490, 3, 269, 399, 267,
114588 /* 1330 */ 609, 416, 623, 400, 593, 593, 593, 592, 591, 13,
114589 /* 1340 */ 265, 622, 409, 622, 263, 622, 34, 406, 244, 3,
114590 /* 1350 */ 258, 363, 464, 463, 416, 623, 622, 356, 251, 8,
114591 /* 1360 */ 622, 404, 177, 599, 455, 409, 622, 622, 622, 622,
114592 /* 1370 */ 445, 566, 243, 622, 622, 236, 295, 240, 31, 239,
114593 /* 1380 */ 622, 431, 30, 396, 404, 290, 622, 294, 622, 293,
114594 /* 1390 */ 144, 41, 42, 622, 566, 622, 394, 622, 43, 414,
114595 /* 1400 */ 413, 622, 289, 595, 398, 60, 622, 292, 37, 231,
114596 /* 1410 */ 598, 172, 622, 29, 41, 42, 393, 523, 622, 556,
114597 /* 1420 */ 184, 43, 414, 413, 287, 387, 595, 543, 285, 518,
114598 /* 1430 */ 537, 536, 517, 327, 593, 593, 593, 592, 591, 13,
114599 /* 1440 */ 215, 283, 278, 514, 513, 304, 303, 302, 179, 300,
114600 /* 1450 */ 512, 310, 454, 128, 227, 226, 309, 593, 593, 593,
114601 /* 1460 */ 592, 591, 13, 494, 489, 225, 488, 150, 487, 242,
114602 /* 1470 */ 163, 61, 374, 481, 162, 161, 624, 623, 241, 372,
114603 /* 1480 */ 209, 479, 370, 260, 26, 160, 478, 364, 468, 471,
114604 /* 1490 */ 140, 152, 119, 467, 131, 116, 155, 153, 345, 457,
114605 /* 1500 */ 151, 346, 130, 114, 113, 112, 111, 448, 319, 23,
114606 /* 1510 */ 109, 434, 20, 433, 432, 429, 566, 610, 573, 596,
114607 /* 1520 */ 63, 405, 191, 279, 510, 296, 498, 288, 570, 495,
114608 /* 1530 */ 499, 497, 461, 194, 5, 305, 193, 192, 381, 569,
114609 /* 1540 */ 357, 256, 344, 245, 526, 246, 253, 313, 595, 343,
114610 /* 1550 */ 447, 297, 236, 402, 550, 491, 508, 502, 501, 527,
114611 /* 1560 */ 234, 208, 525, 962, 962, 962, 371, 962, 962, 962,
114612 /* 1570 */ 962, 962, 962, 962, 962, 337, 962, 962, 962, 593,
114613 /* 1580 */ 593, 593,
114614 };
114615 static const YYCODETYPE yy_lookahead[] = {
114616 /* 0 */ 19, 143, 144, 145, 146, 24, 7, 8, 27, 78,
114617 /* 10 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
114618 /* 20 */ 89, 90, 91, 92, 93, 106, 107, 108, 27, 28,
114619 /* 30 */ 15, 50, 51, 78, 79, 80, 81, 26, 83, 84,
114620 /* 40 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 1,
114621 /* 50 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114622 /* 60 */ 79, 80, 81, 11, 83, 84, 85, 86, 87, 88,
114623 /* 70 */ 89, 90, 91, 92, 93, 19, 95, 89, 90, 91,
114624 /* 80 */ 92, 93, 26, 83, 84, 85, 86, 87, 88, 89,
114625 /* 90 */ 90, 91, 92, 93, 27, 28, 95, 96, 97, 27,
114626 /* 100 */ 28, 100, 101, 102, 22, 19, 50, 51, 27, 28,
114627 /* 110 */ 58, 55, 111, 7, 8, 9, 87, 88, 89, 90,
114628 /* 120 */ 91, 92, 93, 98, 99, 69, 70, 71, 72, 73,
114629 /* 130 */ 74, 75, 76, 77, 78, 79, 80, 81, 127, 83,
114630 /* 140 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114631 /* 150 */ 19, 223, 224, 225, 87, 88, 162, 31, 106, 107,
114632 /* 160 */ 108, 35, 95, 96, 33, 98, 23, 95, 96, 117,
114633 /* 170 */ 119, 243, 105, 42, 107, 49, 95, 96, 151, 93,
114634 /* 180 */ 26, 50, 51, 97, 98, 99, 100, 101, 102, 103,
114635 /* 190 */ 196, 22, 23, 121, 167, 26, 110, 130, 131, 67,
114636 /* 200 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114637 /* 210 */ 79, 80, 81, 219, 83, 84, 85, 86, 87, 88,
114638 /* 220 */ 89, 90, 91, 92, 93, 19, 12, 95, 234, 119,
114639 /* 230 */ 24, 99, 113, 239, 115, 116, 151, 68, 23, 147,
114640 /* 240 */ 148, 26, 215, 29, 151, 153, 119, 155, 163, 164,
114641 /* 250 */ 23, 23, 167, 26, 162, 23, 50, 51, 26, 45,
114642 /* 260 */ 167, 47, 130, 131, 132, 172, 173, 23, 22, 23,
114643 /* 270 */ 26, 186, 26, 188, 120, 69, 70, 71, 72, 73,
114644 /* 280 */ 74, 75, 76, 77, 78, 79, 80, 81, 196, 83,
114645 /* 290 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114646 /* 300 */ 19, 151, 151, 23, 119, 97, 26, 19, 100, 101,
114647 /* 310 */ 102, 219, 151, 162, 68, 22, 28, 167, 167, 111,
114648 /* 320 */ 27, 26, 172, 173, 231, 232, 175, 176, 167, 27,
114649 /* 330 */ 28, 50, 51, 27, 28, 119, 175, 176, 246, 24,
114650 /* 340 */ 22, 113, 27, 115, 116, 27, 28, 196, 22, 23,
114651 /* 350 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114652 /* 360 */ 79, 80, 81, 114, 83, 84, 85, 86, 87, 88,
114653 /* 370 */ 89, 90, 91, 92, 93, 19, 21, 151, 217, 22,
114654 /* 380 */ 151, 231, 232, 222, 27, 28, 23, 114, 95, 50,
114655 /* 390 */ 51, 118, 151, 167, 68, 89, 167, 95, 96, 104,
114656 /* 400 */ 23, 95, 96, 26, 175, 176, 50, 51, 167, 22,
114657 /* 410 */ 95, 72, 73, 95, 96, 16, 175, 176, 137, 64,
114658 /* 420 */ 23, 195, 27, 121, 23, 69, 70, 71, 72, 73,
114659 /* 430 */ 74, 75, 76, 77, 78, 79, 80, 81, 99, 83,
114660 /* 440 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114661 /* 450 */ 19, 12, 95, 96, 23, 226, 101, 22, 217, 19,
114662 /* 460 */ 61, 151, 63, 222, 151, 106, 107, 108, 29, 159,
114663 /* 470 */ 244, 151, 99, 163, 164, 23, 113, 167, 115, 116,
114664 /* 480 */ 167, 50, 51, 110, 45, 58, 47, 167, 175, 176,
114665 /* 490 */ 95, 51, 168, 137, 139, 175, 176, 58, 11, 22,
114666 /* 500 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114667 /* 510 */ 79, 80, 81, 22, 83, 84, 85, 86, 87, 88,
114668 /* 520 */ 89, 90, 91, 92, 93, 19, 23, 151, 117, 23,
114669 /* 530 */ 217, 207, 19, 106, 107, 108, 216, 151, 139, 23,
114670 /* 540 */ 129, 28, 26, 167, 117, 105, 23, 223, 224, 225,
114671 /* 550 */ 110, 175, 176, 167, 77, 165, 50, 51, 168, 169,
114672 /* 560 */ 170, 175, 176, 87, 88, 113, 26, 115, 116, 171,
114673 /* 570 */ 172, 173, 0, 1, 2, 69, 70, 71, 72, 73,
114674 /* 580 */ 74, 75, 76, 77, 78, 79, 80, 81, 162, 83,
114675 /* 590 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114676 /* 600 */ 19, 151, 98, 217, 23, 37, 130, 131, 23, 23,
114677 /* 610 */ 26, 26, 96, 163, 164, 23, 113, 167, 115, 116,
114678 /* 620 */ 52, 117, 196, 151, 171, 172, 173, 59, 130, 131,
114679 /* 630 */ 232, 50, 51, 129, 208, 209, 16, 121, 156, 167,
114680 /* 640 */ 22, 23, 162, 223, 224, 225, 51, 175, 176, 121,
114681 /* 650 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114682 /* 660 */ 79, 80, 81, 178, 83, 84, 85, 86, 87, 88,
114683 /* 670 */ 89, 90, 91, 92, 93, 19, 196, 109, 151, 23,
114684 /* 680 */ 96, 61, 151, 63, 23, 232, 68, 26, 151, 168,
114685 /* 690 */ 169, 170, 23, 89, 167, 26, 208, 209, 167, 219,
114686 /* 700 */ 105, 36, 175, 176, 167, 121, 50, 51, 223, 224,
114687 /* 710 */ 225, 229, 175, 176, 178, 233, 247, 248, 114, 239,
114688 /* 720 */ 189, 22, 118, 24, 162, 69, 70, 71, 72, 73,
114689 /* 730 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114690 /* 740 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114691 /* 750 */ 19, 151, 26, 151, 167, 24, 145, 146, 196, 223,
114692 /* 760 */ 224, 225, 175, 176, 151, 182, 183, 167, 151, 167,
114693 /* 770 */ 151, 36, 199, 190, 151, 175, 176, 175, 176, 206,
114694 /* 780 */ 167, 50, 51, 221, 167, 136, 167, 138, 175, 176,
114695 /* 790 */ 167, 26, 175, 176, 175, 176, 168, 36, 175, 176,
114696 /* 800 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114697 /* 810 */ 79, 80, 81, 151, 83, 84, 85, 86, 87, 88,
114698 /* 820 */ 89, 90, 91, 92, 93, 19, 151, 151, 151, 167,
114699 /* 830 */ 151, 151, 151, 151, 162, 207, 23, 175, 176, 26,
114700 /* 840 */ 249, 250, 167, 167, 167, 151, 167, 167, 167, 167,
114701 /* 850 */ 175, 176, 175, 176, 175, 176, 50, 51, 151, 53,
114702 /* 860 */ 22, 167, 192, 193, 33, 189, 192, 193, 196, 189,
114703 /* 870 */ 189, 189, 162, 42, 167, 69, 70, 71, 72, 73,
114704 /* 880 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114705 /* 890 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114706 /* 900 */ 19, 151, 195, 151, 167, 151, 196, 162, 151, 215,
114707 /* 910 */ 92, 93, 175, 176, 28, 174, 119, 167, 151, 167,
114708 /* 920 */ 151, 167, 151, 182, 167, 175, 176, 175, 176, 175,
114709 /* 930 */ 176, 50, 51, 23, 167, 23, 167, 40, 167, 22,
114710 /* 940 */ 167, 196, 53, 168, 175, 176, 175, 176, 175, 162,
114711 /* 950 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114712 /* 960 */ 79, 80, 81, 151, 83, 84, 85, 86, 87, 88,
114713 /* 970 */ 89, 90, 91, 92, 93, 19, 151, 151, 151, 167,
114714 /* 980 */ 151, 151, 207, 196, 30, 218, 22, 175, 176, 1,
114715 /* 990 */ 2, 53, 167, 167, 167, 151, 167, 167, 151, 151,
114716 /* 1000 */ 175, 176, 175, 176, 175, 176, 50, 51, 221, 23,
114717 /* 1010 */ 53, 167, 22, 22, 167, 167, 103, 168, 22, 110,
114718 /* 1020 */ 19, 105, 175, 176, 20, 69, 70, 71, 72, 73,
114719 /* 1030 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114720 /* 1040 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114721 /* 1050 */ 19, 151, 151, 151, 167, 151, 207, 24, 44, 215,
114722 /* 1060 */ 60, 26, 175, 176, 54, 54, 240, 167, 167, 167,
114723 /* 1070 */ 240, 167, 151, 151, 151, 175, 176, 175, 176, 175,
114724 /* 1080 */ 176, 50, 51, 139, 151, 22, 105, 119, 167, 167,
114725 /* 1090 */ 167, 5, 1, 36, 28, 77, 175, 176, 175, 176,
114726 /* 1100 */ 167, 70, 71, 72, 73, 74, 75, 76, 77, 78,
114727 /* 1110 */ 79, 80, 81, 151, 83, 84, 85, 86, 87, 88,
114728 /* 1120 */ 89, 90, 91, 92, 93, 19, 151, 151, 151, 167,
114729 /* 1130 */ 151, 151, 109, 151, 128, 77, 22, 175, 176, 26,
114730 /* 1140 */ 218, 240, 167, 167, 167, 151, 167, 167, 151, 167,
114731 /* 1150 */ 175, 176, 175, 176, 175, 176, 50, 51, 151, 22,
114732 /* 1160 */ 151, 167, 23, 120, 167, 1, 16, 122, 20, 120,
114733 /* 1170 */ 109, 195, 175, 176, 167, 195, 167, 71, 72, 73,
114734 /* 1180 */ 74, 75, 76, 77, 78, 79, 80, 81, 151, 83,
114735 /* 1190 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
114736 /* 1200 */ 19, 20, 195, 22, 167, 151, 151, 128, 27, 28,
114737 /* 1210 */ 129, 23, 175, 176, 23, 66, 141, 22, 151, 38,
114738 /* 1220 */ 151, 167, 167, 19, 20, 151, 22, 151, 151, 175,
114739 /* 1230 */ 176, 27, 28, 151, 167, 15, 167, 4, 57, 16,
114740 /* 1240 */ 151, 167, 38, 167, 167, 3, 166, 248, 67, 167,
114741 /* 1250 */ 195, 175, 176, 181, 181, 150, 167, 175, 176, 251,
114742 /* 1260 */ 6, 57, 151, 151, 175, 176, 151, 151, 87, 88,
114743 /* 1270 */ 89, 67, 151, 162, 151, 94, 95, 96, 167, 167,
114744 /* 1280 */ 99, 251, 167, 167, 152, 151, 175, 176, 167, 151,
114745 /* 1290 */ 167, 87, 88, 151, 150, 150, 175, 176, 94, 95,
114746 /* 1300 */ 96, 167, 150, 99, 151, 167, 151, 196, 13, 167,
114747 /* 1310 */ 195, 130, 131, 132, 133, 134, 135, 152, 195, 160,
114748 /* 1320 */ 167, 117, 167, 19, 20, 151, 22, 151, 217, 151,
114749 /* 1330 */ 161, 27, 28, 222, 130, 131, 132, 133, 134, 135,
114750 /* 1340 */ 151, 167, 38, 167, 151, 167, 19, 20, 195, 22,
114751 /* 1350 */ 151, 151, 151, 151, 27, 28, 167, 151, 151, 26,
114752 /* 1360 */ 167, 57, 25, 196, 151, 38, 167, 167, 167, 167,
114753 /* 1370 */ 151, 67, 151, 167, 167, 117, 201, 151, 125, 151,
114754 /* 1380 */ 167, 151, 127, 124, 57, 151, 167, 202, 167, 203,
114755 /* 1390 */ 151, 87, 88, 167, 67, 167, 151, 167, 94, 95,
114756 /* 1400 */ 96, 167, 151, 99, 123, 126, 167, 204, 136, 227,
114757 /* 1410 */ 205, 119, 167, 105, 87, 88, 122, 177, 167, 158,
114758 /* 1420 */ 158, 94, 95, 96, 212, 105, 99, 213, 212, 177,
114759 /* 1430 */ 213, 213, 185, 48, 130, 131, 132, 133, 134, 135,
114760 /* 1440 */ 5, 212, 177, 179, 104, 10, 11, 12, 13, 14,
114761 /* 1450 */ 177, 180, 17, 22, 230, 93, 180, 130, 131, 132,
114762 /* 1460 */ 133, 134, 135, 185, 177, 230, 177, 32, 177, 34,
114763 /* 1470 */ 157, 22, 18, 158, 157, 157, 27, 28, 43, 158,
114764 /* 1480 */ 158, 158, 46, 237, 136, 157, 238, 158, 191, 201,
114765 /* 1490 */ 69, 56, 191, 58, 220, 22, 157, 62, 18, 201,
114766 /* 1500 */ 65, 158, 220, 194, 194, 194, 194, 201, 158, 242,
114767 /* 1510 */ 191, 41, 242, 158, 158, 39, 67, 154, 232, 168,
114768 /* 1520 */ 245, 228, 198, 178, 183, 200, 168, 211, 232, 168,
114769 /* 1530 */ 178, 178, 201, 187, 198, 149, 87, 88, 179, 168,
114770 /* 1540 */ 241, 106, 107, 108, 95, 211, 241, 112, 99, 211,
114771 /* 1550 */ 201, 197, 117, 193, 210, 188, 184, 184, 184, 175,
114772 /* 1560 */ 93, 235, 175, 252, 252, 252, 236, 252, 252, 252,
114773 /* 1570 */ 252, 252, 252, 252, 252, 140, 252, 252, 252, 130,
114774 /* 1580 */ 131, 132,
114775 };
114776 #define YY_SHIFT_USE_DFLT (-82)
114777 #define YY_SHIFT_COUNT (419)
114778 #define YY_SHIFT_MIN (-81)
114779 #define YY_SHIFT_MAX (1480)
114780 static const short yy_shift_ofst[] = {
114781 /* 0 */ 988, 1204, 1435, 1204, 1304, 1304, 67, 67, 1, -19,
114782 /* 10 */ 1304, 1304, 1304, 1304, 427, 81, 131, 131, 806, 1181,
114783 /* 20 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304,
114784 /* 30 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304,
114785 /* 40 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1327, 1304,
114786 /* 50 */ 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304,
114787 /* 60 */ 1304, 1304, 52, 81, 81, 476, 476, 395, 1258, 56,
114788 /* 70 */ 731, 656, 581, 506, 431, 356, 281, 206, 881, 881,
114789 /* 80 */ 881, 881, 881, 881, 881, 881, 881, 881, 881, 881,
114790 /* 90 */ 881, 881, 881, 956, 881, 1031, 1106, 1106, -69, -45,
114791 /* 100 */ -45, -45, -45, -45, 0, 29, -12, 81, 81, 81,
114792 /* 110 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114793 /* 120 */ 81, 81, 81, 355, 440, 81, 81, 81, 81, 81,
114794 /* 130 */ 504, 411, 395, 818, 1467, -82, -82, -82, 1449, 86,
114795 /* 140 */ 439, 439, 306, 357, 302, 72, 318, 246, 169, 81,
114796 /* 150 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114797 /* 160 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114798 /* 170 */ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
114799 /* 180 */ 81, 81, 315, 315, 315, 572, 1258, 1258, 1258, -82,
114800 /* 190 */ -82, -82, 132, 132, 208, 568, 568, 568, 516, 503,
114801 /* 200 */ 214, 452, 363, 228, 119, 119, 119, 119, 359, 126,
114802 /* 210 */ 119, 119, 584, 293, 604, 106, 11, 288, 288, 513,
114803 /* 220 */ 11, 513, 295, 813, 395, 831, 395, 831, 595, 831,
114804 /* 230 */ 288, 649, 498, 498, 395, 154, 273, 699, 1476, 1292,
114805 /* 240 */ 1292, 1470, 1470, 1292, 1473, 1421, 1255, 1480, 1480, 1480,
114806 /* 250 */ 1480, 1292, 1454, 1255, 1473, 1421, 1421, 1255, 1292, 1454,
114807 /* 260 */ 1348, 1436, 1292, 1292, 1454, 1292, 1454, 1292, 1454, 1431,
114808 /* 270 */ 1320, 1320, 1320, 1385, 1362, 1362, 1431, 1320, 1340, 1320,
114809 /* 280 */ 1385, 1320, 1320, 1294, 1308, 1294, 1308, 1294, 1308, 1292,
114810 /* 290 */ 1292, 1272, 1279, 1281, 1253, 1259, 1255, 1258, 1337, 1333,
114811 /* 300 */ 1295, 1295, 1254, 1254, 1254, 1254, -82, -82, -82, -82,
114812 /* 310 */ -82, -82, 339, 399, 618, 326, 620, -81, 669, 477,
114813 /* 320 */ 661, 585, 377, 280, 244, 232, 25, -1, 373, 227,
114814 /* 330 */ 215, 1233, 1242, 1195, 1075, 1220, 1149, 1223, 1191, 1188,
114815 /* 340 */ 1081, 1113, 1079, 1061, 1049, 1148, 1045, 1150, 1164, 1043,
114816 /* 350 */ 1139, 1137, 1113, 1114, 1006, 1058, 1018, 1023, 1066, 1057,
114817 /* 360 */ 968, 1091, 1086, 1063, 981, 944, 1011, 1035, 1010, 1000,
114818 /* 370 */ 1014, 916, 1033, 1004, 1001, 909, 913, 996, 957, 991,
114819 /* 380 */ 990, 986, 964, 938, 954, 917, 889, 897, 912, 910,
114820 /* 390 */ 797, 886, 761, 838, 528, 726, 735, 765, 665, 726,
114821 /* 400 */ 592, 586, 540, 523, 491, 487, 435, 401, 397, 387,
114822 /* 410 */ 249, 216, 185, 127, 110, 51, 82, 143, 15, 48,
114823 };
114824 #define YY_REDUCE_USE_DFLT (-143)
114825 #define YY_REDUCE_COUNT (311)
114826 #define YY_REDUCE_MIN (-142)
114827 #define YY_REDUCE_MAX (1387)
114828 static const short yy_reduce_ofst[] = {
114829 /* 0 */ -142, 1111, 92, 151, 241, 161, 150, 93, 85, 324,
114830 /* 10 */ 386, 313, 320, 229, -6, 310, 536, 485, -72, 1121,
114831 /* 20 */ 1089, 1082, 1076, 1054, 1037, 997, 979, 977, 975, 962,
114832 /* 30 */ 923, 921, 904, 902, 900, 887, 847, 829, 827, 825,
114833 /* 40 */ 812, 771, 769, 754, 752, 750, 737, 679, 677, 675,
114834 /* 50 */ 662, 623, 619, 617, 613, 602, 600, 587, 537, 527,
114835 /* 60 */ 472, 376, 480, 450, 226, 453, 398, 390, 426, 420,
114836 /* 70 */ 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
114837 /* 80 */ 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
114838 /* 90 */ 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
114839 /* 100 */ 420, 420, 420, 420, 420, 420, 420, 1153, 922, 1123,
114840 /* 110 */ 1115, 1055, 1007, 980, 976, 901, 844, 830, 767, 826,
114841 /* 120 */ 682, 694, 707, 482, 583, 681, 680, 676, 531, 27,
114842 /* 130 */ 787, 562, 521, 420, 420, 420, 420, 420, 773, 741,
114843 /* 140 */ 674, 670, 1067, 1251, 1245, 1239, 1234, 591, 591, 1230,
114844 /* 150 */ 1228, 1226, 1221, 1219, 1213, 1207, 1206, 1202, 1201, 1200,
114845 /* 160 */ 1199, 1193, 1189, 1178, 1176, 1174, 1155, 1142, 1138, 1134,
114846 /* 170 */ 1116, 1112, 1077, 1074, 1069, 1067, 1009, 994, 982, 933,
114847 /* 180 */ 848, 757, 849, 775, 628, 611, 745, 710, 672, 469,
114848 /* 190 */ 488, 573, 1387, 1384, 1367, 1374, 1373, 1372, 1344, 1354,
114849 /* 200 */ 1360, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1330, 1326,
114850 /* 210 */ 1354, 1354, 1344, 1371, 1336, 1386, 1349, 1338, 1334, 1305,
114851 /* 220 */ 1331, 1299, 1359, 1346, 1361, 1353, 1358, 1352, 1341, 1345,
114852 /* 230 */ 1316, 1293, 1296, 1286, 1351, 1325, 1324, 1363, 1275, 1356,
114853 /* 240 */ 1355, 1270, 1267, 1350, 1282, 1319, 1306, 1312, 1311, 1310,
114854 /* 250 */ 1309, 1343, 1339, 1298, 1274, 1301, 1297, 1288, 1329, 1328,
114855 /* 260 */ 1248, 1246, 1323, 1322, 1318, 1321, 1317, 1315, 1313, 1276,
114856 /* 270 */ 1291, 1289, 1287, 1278, 1235, 1224, 1271, 1273, 1264, 1265,
114857 /* 280 */ 1247, 1252, 1240, 1218, 1229, 1217, 1216, 1214, 1212, 1262,
114858 /* 290 */ 1261, 1182, 1205, 1203, 1186, 1185, 1175, 1167, 1169, 1159,
114859 /* 300 */ 1165, 1132, 1152, 1145, 1144, 1105, 1030, 1008, 999, 1073,
114860 /* 310 */ 1072, 1080,
114861 };
114862 static const YYACTIONTYPE yy_default[] = {
114863 /* 0 */ 636, 872, 960, 960, 872, 872, 960, 960, 960, 762,
114864 /* 10 */ 960, 960, 960, 870, 960, 960, 790, 790, 934, 960,
114865 /* 20 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114866 /* 30 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114867 /* 40 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114868 /* 50 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114869 /* 60 */ 960, 960, 960, 960, 960, 960, 960, 677, 766, 796,
114870 /* 70 */ 960, 960, 960, 960, 960, 960, 960, 960, 933, 935,
114871 /* 80 */ 804, 803, 913, 777, 801, 794, 798, 873, 866, 867,
114872 /* 90 */ 865, 869, 874, 960, 797, 833, 850, 832, 844, 849,
114873 /* 100 */ 856, 848, 845, 835, 834, 836, 837, 960, 960, 960,
114874 /* 110 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114875 /* 120 */ 960, 960, 960, 662, 731, 960, 960, 960, 960, 960,
114876 /* 130 */ 960, 960, 960, 838, 839, 853, 852, 851, 960, 669,
114877 /* 140 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114878 /* 150 */ 940, 938, 960, 885, 960, 960, 960, 960, 960, 960,
114879 /* 160 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114880 /* 170 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114881 /* 180 */ 960, 642, 762, 762, 762, 636, 960, 960, 960, 952,
114882 /* 190 */ 766, 756, 960, 960, 960, 960, 960, 960, 960, 960,
114883 /* 200 */ 960, 960, 960, 960, 806, 745, 923, 925, 960, 906,
114884 /* 210 */ 743, 664, 764, 679, 754, 644, 800, 779, 779, 918,
114885 /* 220 */ 800, 918, 702, 725, 960, 790, 960, 790, 699, 790,
114886 /* 230 */ 779, 868, 960, 960, 960, 763, 754, 960, 945, 770,
114887 /* 240 */ 770, 937, 937, 770, 812, 735, 800, 742, 742, 742,
114888 /* 250 */ 742, 770, 659, 800, 812, 735, 735, 800, 770, 659,
114889 /* 260 */ 912, 910, 770, 770, 659, 770, 659, 770, 659, 878,
114890 /* 270 */ 733, 733, 733, 717, 882, 882, 878, 733, 702, 733,
114891 /* 280 */ 717, 733, 733, 783, 778, 783, 778, 783, 778, 770,
114892 /* 290 */ 770, 960, 795, 784, 793, 791, 800, 960, 665, 720,
114893 /* 300 */ 652, 652, 641, 641, 641, 641, 957, 957, 952, 704,
114894 /* 310 */ 704, 687, 960, 960, 960, 960, 960, 960, 960, 887,
114895 /* 320 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114896 /* 330 */ 960, 960, 637, 947, 960, 960, 944, 960, 960, 960,
114897 /* 340 */ 960, 805, 960, 960, 960, 960, 960, 960, 960, 960,
114898 /* 350 */ 960, 960, 922, 960, 960, 960, 960, 960, 960, 960,
114899 /* 360 */ 916, 960, 960, 960, 960, 960, 960, 909, 908, 960,
114900 /* 370 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114901 /* 380 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114902 /* 390 */ 960, 960, 960, 960, 960, 792, 960, 785, 960, 871,
114903 /* 400 */ 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
114904 /* 410 */ 748, 821, 960, 820, 824, 819, 671, 960, 650, 960,
114905 /* 420 */ 633, 638, 956, 959, 958, 955, 954, 953, 948, 946,
114906 /* 430 */ 943, 942, 941, 939, 936, 932, 891, 889, 896, 895,
114907 /* 440 */ 894, 893, 892, 890, 888, 886, 807, 802, 799, 931,
114908 /* 450 */ 884, 744, 741, 740, 658, 949, 915, 924, 811, 810,
114909 /* 460 */ 813, 921, 920, 919, 917, 914, 901, 809, 808, 736,
114910 /* 470 */ 876, 875, 661, 905, 904, 903, 907, 911, 902, 772,
114911 /* 480 */ 660, 657, 668, 723, 724, 732, 730, 729, 728, 727,
114912 /* 490 */ 726, 722, 670, 678, 716, 701, 700, 881, 883, 880,
114913 /* 500 */ 879, 709, 708, 714, 713, 712, 711, 710, 707, 706,
114914 /* 510 */ 705, 698, 697, 703, 696, 719, 718, 715, 695, 739,
114915 /* 520 */ 738, 737, 734, 694, 693, 692, 824, 691, 690, 830,
114916 /* 530 */ 829, 817, 860, 759, 758, 757, 769, 768, 781, 780,
114917 /* 540 */ 815, 814, 782, 767, 761, 760, 776, 775, 774, 773,
114918 /* 550 */ 765, 755, 787, 789, 788, 786, 862, 771, 859, 930,
114919 /* 560 */ 929, 928, 927, 926, 864, 863, 831, 828, 682, 683,
114920 /* 570 */ 899, 898, 900, 897, 685, 684, 681, 680, 861, 750,
114921 /* 580 */ 749, 857, 854, 846, 842, 858, 855, 847, 843, 841,
114922 /* 590 */ 840, 826, 825, 823, 822, 818, 827, 673, 751, 747,
114923 /* 600 */ 746, 816, 753, 752, 689, 688, 686, 667, 666, 663,
114924 /* 610 */ 656, 654, 653, 655, 651, 649, 648, 647, 646, 645,
114925 /* 620 */ 676, 675, 674, 672, 671, 643, 640, 639, 635, 634,
114926 /* 630 */ 632,
114927 };
114928
114929 /* The next table maps tokens into fallback tokens. If a construct
114930 ** like the following:
114931 **
@@ -113573,75 +114938,76 @@
114938 */
114939 #ifdef YYFALLBACK
114940 static const YYCODETYPE yyFallback[] = {
114941 0, /* $ => nothing */
114942 0, /* SEMI => nothing */
114943 27, /* EXPLAIN => ID */
114944 27, /* QUERY => ID */
114945 27, /* PLAN => ID */
114946 27, /* BEGIN => ID */
114947 0, /* TRANSACTION => nothing */
114948 27, /* DEFERRED => ID */
114949 27, /* IMMEDIATE => ID */
114950 27, /* EXCLUSIVE => ID */
114951 0, /* COMMIT => nothing */
114952 27, /* END => ID */
114953 27, /* ROLLBACK => ID */
114954 27, /* SAVEPOINT => ID */
114955 27, /* RELEASE => ID */
114956 0, /* TO => nothing */
114957 0, /* TABLE => nothing */
114958 0, /* CREATE => nothing */
114959 27, /* IF => ID */
114960 0, /* NOT => nothing */
114961 0, /* EXISTS => nothing */
114962 27, /* TEMP => ID */
114963 0, /* LP => nothing */
114964 0, /* RP => nothing */
114965 0, /* AS => nothing */
114966 27, /* WITHOUT => ID */
114967 0, /* COMMA => nothing */
114968 0, /* ID => nothing */
114969 0, /* INDEXED => nothing */
114970 27, /* ABORT => ID */
114971 27, /* ACTION => ID */
114972 27, /* AFTER => ID */
114973 27, /* ANALYZE => ID */
114974 27, /* ASC => ID */
114975 27, /* ATTACH => ID */
114976 27, /* BEFORE => ID */
114977 27, /* BY => ID */
114978 27, /* CASCADE => ID */
114979 27, /* CAST => ID */
114980 27, /* COLUMNKW => ID */
114981 27, /* CONFLICT => ID */
114982 27, /* DATABASE => ID */
114983 27, /* DESC => ID */
114984 27, /* DETACH => ID */
114985 27, /* EACH => ID */
114986 27, /* FAIL => ID */
114987 27, /* FOR => ID */
114988 27, /* IGNORE => ID */
114989 27, /* INITIALLY => ID */
114990 27, /* INSTEAD => ID */
114991 27, /* LIKE_KW => ID */
114992 27, /* MATCH => ID */
114993 27, /* NO => ID */
114994 27, /* KEY => ID */
114995 27, /* OF => ID */
114996 27, /* OFFSET => ID */
114997 27, /* PRAGMA => ID */
114998 27, /* RAISE => ID */
114999 27, /* REPLACE => ID */
115000 27, /* RESTRICT => ID */
115001 27, /* ROW => ID */
115002 27, /* TRIGGER => ID */
115003 27, /* VACUUM => ID */
115004 27, /* VIEW => ID */
115005 27, /* VIRTUAL => ID */
115006 27, /* REINDEX => ID */
115007 27, /* RENAME => ID */
115008 27, /* CTIME_KW => ID */
115009 };
115010 #endif /* YYFALLBACK */
115011
115012 /* The following structure represents a single element of the
115013 ** parser's stack. Information stored includes:
@@ -113722,67 +115088,67 @@
115088 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
115089 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
115090 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
115091 "TABLE", "CREATE", "IF", "NOT",
115092 "EXISTS", "TEMP", "LP", "RP",
115093 "AS", "WITHOUT", "COMMA", "ID",
115094 "INDEXED", "ABORT", "ACTION", "AFTER",
115095 "ANALYZE", "ASC", "ATTACH", "BEFORE",
115096 "BY", "CASCADE", "CAST", "COLUMNKW",
115097 "CONFLICT", "DATABASE", "DESC", "DETACH",
115098 "EACH", "FAIL", "FOR", "IGNORE",
115099 "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
115100 "NO", "KEY", "OF", "OFFSET",
115101 "PRAGMA", "RAISE", "REPLACE", "RESTRICT",
115102 "ROW", "TRIGGER", "VACUUM", "VIEW",
115103 "VIRTUAL", "REINDEX", "RENAME", "CTIME_KW",
115104 "ANY", "OR", "AND", "IS",
115105 "BETWEEN", "IN", "ISNULL", "NOTNULL",
115106 "NE", "EQ", "GT", "LE",
115107 "LT", "GE", "ESCAPE", "BITAND",
115108 "BITOR", "LSHIFT", "RSHIFT", "PLUS",
115109 "MINUS", "STAR", "SLASH", "REM",
115110 "CONCAT", "COLLATE", "BITNOT", "STRING",
115111 "JOIN_KW", "CONSTRAINT", "DEFAULT", "NULL",
115112 "PRIMARY", "UNIQUE", "CHECK", "REFERENCES",
115113 "AUTOINCR", "ON", "INSERT", "DELETE",
115114 "UPDATE", "SET", "DEFERRABLE", "FOREIGN",
115115 "DROP", "UNION", "ALL", "EXCEPT",
115116 "INTERSECT", "SELECT", "DISTINCT", "DOT",
115117 "FROM", "JOIN", "USING", "ORDER",
115118 "GROUP", "HAVING", "LIMIT", "WHERE",
115119 "INTO", "VALUES", "INTEGER", "FLOAT",
115120 "BLOB", "REGISTER", "VARIABLE", "CASE",
115121 "WHEN", "THEN", "ELSE", "INDEX",
115122 "ALTER", "ADD", "error", "input",
115123 "cmdlist", "ecmd", "explain", "cmdx",
115124 "cmd", "transtype", "trans_opt", "nm",
115125 "savepoint_opt", "create_table", "create_table_args", "createkw",
115126 "temp", "ifnotexists", "dbnm", "columnlist",
115127 "conslist_opt", "table_options", "select", "column",
115128 "columnid", "type", "carglist", "id",
115129 "ids", "typetoken", "typename", "signed",
115130 "plus_num", "minus_num", "ccons", "term",
115131 "expr", "onconf", "sortorder", "autoinc",
115132 "idxlist_opt", "refargs", "defer_subclause", "refarg",
115133 "refact", "init_deferred_pred_opt", "conslist", "tconscomma",
115134 "tcons", "idxlist", "defer_subclause_opt", "orconf",
115135 "resolvetype", "raisetype", "ifexists", "fullname",
115136 "oneselect", "multiselect_op", "distinct", "selcollist",
115137 "from", "where_opt", "groupby_opt", "having_opt",
115138 "orderby_opt", "limit_opt", "sclp", "as",
115139 "seltablist", "stl_prefix", "joinop", "indexed_opt",
115140 "on_opt", "using_opt", "joinop2", "idlist",
115141 "sortlist", "nexprlist", "setlist", "insert_cmd",
115142 "inscollist_opt", "valuelist", "exprlist", "likeop",
115143 "between_op", "in_op", "case_operand", "case_exprlist",
115144 "case_else", "uniqueflag", "collate", "nmnum",
115145 "number", "trigger_decl", "trigger_cmd_list", "trigger_time",
115146 "trigger_event", "foreach_clause", "when_clause", "trigger_cmd",
115147 "trnm", "tridxby", "database_kw_opt", "key_opt",
115148 "add_column_fullname", "kwcolumn_opt", "create_vtab", "vtabarglist",
115149 "vtabarg", "vtabargtoken", "lp", "anylist",
115150 };
115151 #endif /* NDEBUG */
115152
115153 #ifndef NDEBUG
115154 /* For tracing reduce actions, the names of all rules are required.
@@ -113818,305 +115184,307 @@
115184 /* 27 */ "createkw ::= CREATE",
115185 /* 28 */ "ifnotexists ::=",
115186 /* 29 */ "ifnotexists ::= IF NOT EXISTS",
115187 /* 30 */ "temp ::= TEMP",
115188 /* 31 */ "temp ::=",
115189 /* 32 */ "create_table_args ::= LP columnlist conslist_opt RP table_options",
115190 /* 33 */ "create_table_args ::= AS select",
115191 /* 34 */ "table_options ::=",
115192 /* 35 */ "table_options ::= WITHOUT nm",
115193 /* 36 */ "columnlist ::= columnlist COMMA column",
115194 /* 37 */ "columnlist ::= column",
115195 /* 38 */ "column ::= columnid type carglist",
115196 /* 39 */ "columnid ::= nm",
115197 /* 40 */ "id ::= ID",
115198 /* 41 */ "id ::= INDEXED",
115199 /* 42 */ "ids ::= ID|STRING",
115200 /* 43 */ "nm ::= id",
115201 /* 44 */ "nm ::= STRING",
115202 /* 45 */ "nm ::= JOIN_KW",
115203 /* 46 */ "type ::=",
115204 /* 47 */ "type ::= typetoken",
115205 /* 48 */ "typetoken ::= typename",
115206 /* 49 */ "typetoken ::= typename LP signed RP",
115207 /* 50 */ "typetoken ::= typename LP signed COMMA signed RP",
115208 /* 51 */ "typename ::= ids",
115209 /* 52 */ "typename ::= typename ids",
115210 /* 53 */ "signed ::= plus_num",
115211 /* 54 */ "signed ::= minus_num",
115212 /* 55 */ "carglist ::= carglist ccons",
115213 /* 56 */ "carglist ::=",
115214 /* 57 */ "ccons ::= CONSTRAINT nm",
115215 /* 58 */ "ccons ::= DEFAULT term",
115216 /* 59 */ "ccons ::= DEFAULT LP expr RP",
115217 /* 60 */ "ccons ::= DEFAULT PLUS term",
115218 /* 61 */ "ccons ::= DEFAULT MINUS term",
115219 /* 62 */ "ccons ::= DEFAULT id",
115220 /* 63 */ "ccons ::= NULL onconf",
115221 /* 64 */ "ccons ::= NOT NULL onconf",
115222 /* 65 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
115223 /* 66 */ "ccons ::= UNIQUE onconf",
115224 /* 67 */ "ccons ::= CHECK LP expr RP",
115225 /* 68 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
115226 /* 69 */ "ccons ::= defer_subclause",
115227 /* 70 */ "ccons ::= COLLATE ids",
115228 /* 71 */ "autoinc ::=",
115229 /* 72 */ "autoinc ::= AUTOINCR",
115230 /* 73 */ "refargs ::=",
115231 /* 74 */ "refargs ::= refargs refarg",
115232 /* 75 */ "refarg ::= MATCH nm",
115233 /* 76 */ "refarg ::= ON INSERT refact",
115234 /* 77 */ "refarg ::= ON DELETE refact",
115235 /* 78 */ "refarg ::= ON UPDATE refact",
115236 /* 79 */ "refact ::= SET NULL",
115237 /* 80 */ "refact ::= SET DEFAULT",
115238 /* 81 */ "refact ::= CASCADE",
115239 /* 82 */ "refact ::= RESTRICT",
115240 /* 83 */ "refact ::= NO ACTION",
115241 /* 84 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
115242 /* 85 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
115243 /* 86 */ "init_deferred_pred_opt ::=",
115244 /* 87 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
115245 /* 88 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
115246 /* 89 */ "conslist_opt ::=",
115247 /* 90 */ "conslist_opt ::= COMMA conslist",
115248 /* 91 */ "conslist ::= conslist tconscomma tcons",
115249 /* 92 */ "conslist ::= tcons",
115250 /* 93 */ "tconscomma ::= COMMA",
115251 /* 94 */ "tconscomma ::=",
115252 /* 95 */ "tcons ::= CONSTRAINT nm",
115253 /* 96 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
115254 /* 97 */ "tcons ::= UNIQUE LP idxlist RP onconf",
115255 /* 98 */ "tcons ::= CHECK LP expr RP onconf",
115256 /* 99 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
115257 /* 100 */ "defer_subclause_opt ::=",
115258 /* 101 */ "defer_subclause_opt ::= defer_subclause",
115259 /* 102 */ "onconf ::=",
115260 /* 103 */ "onconf ::= ON CONFLICT resolvetype",
115261 /* 104 */ "orconf ::=",
115262 /* 105 */ "orconf ::= OR resolvetype",
115263 /* 106 */ "resolvetype ::= raisetype",
115264 /* 107 */ "resolvetype ::= IGNORE",
115265 /* 108 */ "resolvetype ::= REPLACE",
115266 /* 109 */ "cmd ::= DROP TABLE ifexists fullname",
115267 /* 110 */ "ifexists ::= IF EXISTS",
115268 /* 111 */ "ifexists ::=",
115269 /* 112 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select",
115270 /* 113 */ "cmd ::= DROP VIEW ifexists fullname",
115271 /* 114 */ "cmd ::= select",
115272 /* 115 */ "select ::= oneselect",
115273 /* 116 */ "select ::= select multiselect_op oneselect",
115274 /* 117 */ "multiselect_op ::= UNION",
115275 /* 118 */ "multiselect_op ::= UNION ALL",
115276 /* 119 */ "multiselect_op ::= EXCEPT|INTERSECT",
115277 /* 120 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
115278 /* 121 */ "distinct ::= DISTINCT",
115279 /* 122 */ "distinct ::= ALL",
115280 /* 123 */ "distinct ::=",
115281 /* 124 */ "sclp ::= selcollist COMMA",
115282 /* 125 */ "sclp ::=",
115283 /* 126 */ "selcollist ::= sclp expr as",
115284 /* 127 */ "selcollist ::= sclp STAR",
115285 /* 128 */ "selcollist ::= sclp nm DOT STAR",
115286 /* 129 */ "as ::= AS nm",
115287 /* 130 */ "as ::= ids",
115288 /* 131 */ "as ::=",
115289 /* 132 */ "from ::=",
115290 /* 133 */ "from ::= FROM seltablist",
115291 /* 134 */ "stl_prefix ::= seltablist joinop",
115292 /* 135 */ "stl_prefix ::=",
115293 /* 136 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
115294 /* 137 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
115295 /* 138 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
115296 /* 139 */ "dbnm ::=",
115297 /* 140 */ "dbnm ::= DOT nm",
115298 /* 141 */ "fullname ::= nm dbnm",
115299 /* 142 */ "joinop ::= COMMA|JOIN",
115300 /* 143 */ "joinop ::= JOIN_KW JOIN",
115301 /* 144 */ "joinop ::= JOIN_KW nm JOIN",
115302 /* 145 */ "joinop ::= JOIN_KW nm nm JOIN",
115303 /* 146 */ "on_opt ::= ON expr",
115304 /* 147 */ "on_opt ::=",
115305 /* 148 */ "indexed_opt ::=",
115306 /* 149 */ "indexed_opt ::= INDEXED BY nm",
115307 /* 150 */ "indexed_opt ::= NOT INDEXED",
115308 /* 151 */ "using_opt ::= USING LP idlist RP",
115309 /* 152 */ "using_opt ::=",
115310 /* 153 */ "orderby_opt ::=",
115311 /* 154 */ "orderby_opt ::= ORDER BY sortlist",
115312 /* 155 */ "sortlist ::= sortlist COMMA expr sortorder",
115313 /* 156 */ "sortlist ::= expr sortorder",
115314 /* 157 */ "sortorder ::= ASC",
115315 /* 158 */ "sortorder ::= DESC",
115316 /* 159 */ "sortorder ::=",
115317 /* 160 */ "groupby_opt ::=",
115318 /* 161 */ "groupby_opt ::= GROUP BY nexprlist",
115319 /* 162 */ "having_opt ::=",
115320 /* 163 */ "having_opt ::= HAVING expr",
115321 /* 164 */ "limit_opt ::=",
115322 /* 165 */ "limit_opt ::= LIMIT expr",
115323 /* 166 */ "limit_opt ::= LIMIT expr OFFSET expr",
115324 /* 167 */ "limit_opt ::= LIMIT expr COMMA expr",
115325 /* 168 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
115326 /* 169 */ "where_opt ::=",
115327 /* 170 */ "where_opt ::= WHERE expr",
115328 /* 171 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
115329 /* 172 */ "setlist ::= setlist COMMA nm EQ expr",
115330 /* 173 */ "setlist ::= nm EQ expr",
115331 /* 174 */ "cmd ::= insert_cmd INTO fullname inscollist_opt valuelist",
115332 /* 175 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
115333 /* 176 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
115334 /* 177 */ "insert_cmd ::= INSERT orconf",
115335 /* 178 */ "insert_cmd ::= REPLACE",
115336 /* 179 */ "valuelist ::= VALUES LP nexprlist RP",
115337 /* 180 */ "valuelist ::= valuelist COMMA LP exprlist RP",
115338 /* 181 */ "inscollist_opt ::=",
115339 /* 182 */ "inscollist_opt ::= LP idlist RP",
115340 /* 183 */ "idlist ::= idlist COMMA nm",
115341 /* 184 */ "idlist ::= nm",
115342 /* 185 */ "expr ::= term",
115343 /* 186 */ "expr ::= LP expr RP",
115344 /* 187 */ "term ::= NULL",
115345 /* 188 */ "expr ::= id",
115346 /* 189 */ "expr ::= JOIN_KW",
115347 /* 190 */ "expr ::= nm DOT nm",
115348 /* 191 */ "expr ::= nm DOT nm DOT nm",
115349 /* 192 */ "term ::= INTEGER|FLOAT|BLOB",
115350 /* 193 */ "term ::= STRING",
115351 /* 194 */ "expr ::= REGISTER",
115352 /* 195 */ "expr ::= VARIABLE",
115353 /* 196 */ "expr ::= expr COLLATE ids",
115354 /* 197 */ "expr ::= CAST LP expr AS typetoken RP",
115355 /* 198 */ "expr ::= ID LP distinct exprlist RP",
115356 /* 199 */ "expr ::= ID LP STAR RP",
115357 /* 200 */ "term ::= CTIME_KW",
115358 /* 201 */ "expr ::= expr AND expr",
115359 /* 202 */ "expr ::= expr OR expr",
115360 /* 203 */ "expr ::= expr LT|GT|GE|LE expr",
115361 /* 204 */ "expr ::= expr EQ|NE expr",
115362 /* 205 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
115363 /* 206 */ "expr ::= expr PLUS|MINUS expr",
115364 /* 207 */ "expr ::= expr STAR|SLASH|REM expr",
115365 /* 208 */ "expr ::= expr CONCAT expr",
115366 /* 209 */ "likeop ::= LIKE_KW",
115367 /* 210 */ "likeop ::= NOT LIKE_KW",
115368 /* 211 */ "likeop ::= MATCH",
115369 /* 212 */ "likeop ::= NOT MATCH",
115370 /* 213 */ "expr ::= expr likeop expr",
115371 /* 214 */ "expr ::= expr likeop expr ESCAPE expr",
115372 /* 215 */ "expr ::= expr ISNULL|NOTNULL",
115373 /* 216 */ "expr ::= expr NOT NULL",
115374 /* 217 */ "expr ::= expr IS expr",
115375 /* 218 */ "expr ::= expr IS NOT expr",
115376 /* 219 */ "expr ::= NOT expr",
115377 /* 220 */ "expr ::= BITNOT expr",
115378 /* 221 */ "expr ::= MINUS expr",
115379 /* 222 */ "expr ::= PLUS expr",
115380 /* 223 */ "between_op ::= BETWEEN",
115381 /* 224 */ "between_op ::= NOT BETWEEN",
115382 /* 225 */ "expr ::= expr between_op expr AND expr",
115383 /* 226 */ "in_op ::= IN",
115384 /* 227 */ "in_op ::= NOT IN",
115385 /* 228 */ "expr ::= expr in_op LP exprlist RP",
115386 /* 229 */ "expr ::= LP select RP",
115387 /* 230 */ "expr ::= expr in_op LP select RP",
115388 /* 231 */ "expr ::= expr in_op nm dbnm",
115389 /* 232 */ "expr ::= EXISTS LP select RP",
115390 /* 233 */ "expr ::= CASE case_operand case_exprlist case_else END",
115391 /* 234 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
115392 /* 235 */ "case_exprlist ::= WHEN expr THEN expr",
115393 /* 236 */ "case_else ::= ELSE expr",
115394 /* 237 */ "case_else ::=",
115395 /* 238 */ "case_operand ::= expr",
115396 /* 239 */ "case_operand ::=",
115397 /* 240 */ "exprlist ::= nexprlist",
115398 /* 241 */ "exprlist ::=",
115399 /* 242 */ "nexprlist ::= nexprlist COMMA expr",
115400 /* 243 */ "nexprlist ::= expr",
115401 /* 244 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt",
115402 /* 245 */ "uniqueflag ::= UNIQUE",
115403 /* 246 */ "uniqueflag ::=",
115404 /* 247 */ "idxlist_opt ::=",
115405 /* 248 */ "idxlist_opt ::= LP idxlist RP",
115406 /* 249 */ "idxlist ::= idxlist COMMA nm collate sortorder",
115407 /* 250 */ "idxlist ::= nm collate sortorder",
115408 /* 251 */ "collate ::=",
115409 /* 252 */ "collate ::= COLLATE ids",
115410 /* 253 */ "cmd ::= DROP INDEX ifexists fullname",
115411 /* 254 */ "cmd ::= VACUUM",
115412 /* 255 */ "cmd ::= VACUUM nm",
115413 /* 256 */ "cmd ::= PRAGMA nm dbnm",
115414 /* 257 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
115415 /* 258 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
115416 /* 259 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
115417 /* 260 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
115418 /* 261 */ "nmnum ::= plus_num",
115419 /* 262 */ "nmnum ::= nm",
115420 /* 263 */ "nmnum ::= ON",
115421 /* 264 */ "nmnum ::= DELETE",
115422 /* 265 */ "nmnum ::= DEFAULT",
115423 /* 266 */ "plus_num ::= PLUS number",
115424 /* 267 */ "plus_num ::= number",
115425 /* 268 */ "minus_num ::= MINUS number",
115426 /* 269 */ "number ::= INTEGER|FLOAT",
115427 /* 270 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
115428 /* 271 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
115429 /* 272 */ "trigger_time ::= BEFORE",
115430 /* 273 */ "trigger_time ::= AFTER",
115431 /* 274 */ "trigger_time ::= INSTEAD OF",
115432 /* 275 */ "trigger_time ::=",
115433 /* 276 */ "trigger_event ::= DELETE|INSERT",
115434 /* 277 */ "trigger_event ::= UPDATE",
115435 /* 278 */ "trigger_event ::= UPDATE OF idlist",
115436 /* 279 */ "foreach_clause ::=",
115437 /* 280 */ "foreach_clause ::= FOR EACH ROW",
115438 /* 281 */ "when_clause ::=",
115439 /* 282 */ "when_clause ::= WHEN expr",
115440 /* 283 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
115441 /* 284 */ "trigger_cmd_list ::= trigger_cmd SEMI",
115442 /* 285 */ "trnm ::= nm",
115443 /* 286 */ "trnm ::= nm DOT nm",
115444 /* 287 */ "tridxby ::=",
115445 /* 288 */ "tridxby ::= INDEXED BY nm",
115446 /* 289 */ "tridxby ::= NOT INDEXED",
115447 /* 290 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
115448 /* 291 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist",
115449 /* 292 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
115450 /* 293 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
115451 /* 294 */ "trigger_cmd ::= select",
115452 /* 295 */ "expr ::= RAISE LP IGNORE RP",
115453 /* 296 */ "expr ::= RAISE LP raisetype COMMA nm RP",
115454 /* 297 */ "raisetype ::= ROLLBACK",
115455 /* 298 */ "raisetype ::= ABORT",
115456 /* 299 */ "raisetype ::= FAIL",
115457 /* 300 */ "cmd ::= DROP TRIGGER ifexists fullname",
115458 /* 301 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
115459 /* 302 */ "cmd ::= DETACH database_kw_opt expr",
115460 /* 303 */ "key_opt ::=",
115461 /* 304 */ "key_opt ::= KEY expr",
115462 /* 305 */ "database_kw_opt ::= DATABASE",
115463 /* 306 */ "database_kw_opt ::=",
115464 /* 307 */ "cmd ::= REINDEX",
115465 /* 308 */ "cmd ::= REINDEX nm dbnm",
115466 /* 309 */ "cmd ::= ANALYZE",
115467 /* 310 */ "cmd ::= ANALYZE nm dbnm",
115468 /* 311 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
115469 /* 312 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
115470 /* 313 */ "add_column_fullname ::= fullname",
115471 /* 314 */ "kwcolumn_opt ::=",
115472 /* 315 */ "kwcolumn_opt ::= COLUMNKW",
115473 /* 316 */ "cmd ::= create_vtab",
115474 /* 317 */ "cmd ::= create_vtab LP vtabarglist RP",
115475 /* 318 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
115476 /* 319 */ "vtabarglist ::= vtabarg",
115477 /* 320 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
115478 /* 321 */ "vtabarg ::=",
115479 /* 322 */ "vtabarg ::= vtabarg vtabargtoken",
115480 /* 323 */ "vtabargtoken ::= ANY",
115481 /* 324 */ "vtabargtoken ::= lp anylist RP",
115482 /* 325 */ "lp ::= LP",
115483 /* 326 */ "anylist ::=",
115484 /* 327 */ "anylist ::= anylist LP anylist RP",
115485 /* 328 */ "anylist ::= anylist ANY",
115486 };
115487 #endif /* NDEBUG */
115488
115489
115490 #if YYSTACKDEPTH<=0
@@ -114191,80 +115559,80 @@
115559 **
115560 ** Note: during a reduce, the only symbols destroyed are those
115561 ** which appear on the RHS of the rule, but which are not used
115562 ** inside the C code.
115563 */
115564 case 162: /* select */
115565 case 196: /* oneselect */
115566 {
115567 sqlite3SelectDelete(pParse->db, (yypminor->yy387));
115568 }
115569 break;
115570 case 175: /* term */
115571 case 176: /* expr */
115572 {
115573 sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
115574 }
115575 break;
115576 case 180: /* idxlist_opt */
115577 case 189: /* idxlist */
115578 case 199: /* selcollist */
115579 case 202: /* groupby_opt */
115580 case 204: /* orderby_opt */
115581 case 206: /* sclp */
115582 case 216: /* sortlist */
115583 case 217: /* nexprlist */
115584 case 218: /* setlist */
115585 case 222: /* exprlist */
115586 case 227: /* case_exprlist */
115587 {
115588 sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
115589 }
115590 break;
115591 case 195: /* fullname */
115592 case 200: /* from */
115593 case 208: /* seltablist */
115594 case 209: /* stl_prefix */
115595 {
115596 sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
115597 }
115598 break;
115599 case 201: /* where_opt */
115600 case 203: /* having_opt */
115601 case 212: /* on_opt */
115602 case 226: /* case_operand */
115603 case 228: /* case_else */
115604 case 238: /* when_clause */
115605 case 243: /* key_opt */
115606 {
115607 sqlite3ExprDelete(pParse->db, (yypminor->yy314));
115608 }
115609 break;
115610 case 213: /* using_opt */
115611 case 215: /* idlist */
115612 case 220: /* inscollist_opt */
115613 {
115614 sqlite3IdListDelete(pParse->db, (yypminor->yy384));
115615 }
115616 break;
115617 case 221: /* valuelist */
115618 {
115619
115620 sqlite3ExprListDelete(pParse->db, (yypminor->yy260).pList);
115621 sqlite3SelectDelete(pParse->db, (yypminor->yy260).pSelect);
115622
115623 }
115624 break;
115625 case 234: /* trigger_cmd_list */
115626 case 239: /* trigger_cmd */
115627 {
115628 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
115629 }
115630 break;
115631 case 236: /* trigger_event */
115632 {
115633 sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
115634 }
115635 break;
115636 default: break; /* If no destructor action specified: do nothing */
115637 }
115638 }
@@ -114505,337 +115873,339 @@
115873 */
115874 static const struct {
115875 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
115876 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
115877 } yyRuleInfo[] = {
115878 { 143, 1 },
115879 { 144, 2 },
115880 { 144, 1 },
115881 { 145, 1 },
115882 { 145, 3 },
115883 { 146, 0 },
115884 { 146, 1 },
115885 { 146, 3 },
115886 { 147, 1 },
115887 { 148, 3 },
115888 { 150, 0 },
115889 { 150, 1 },
115890 { 150, 2 },
115891 { 149, 0 },
115892 { 149, 1 },
115893 { 149, 1 },
115894 { 149, 1 },
115895 { 148, 2 },
115896 { 148, 2 },
115897 { 148, 2 },
115898 { 152, 1 },
115899 { 152, 0 },
115900 { 148, 2 },
115901 { 148, 3 },
115902 { 148, 5 },
115903 { 148, 2 },
115904 { 153, 6 },
115905 { 155, 1 },
115906 { 157, 0 },
115907 { 157, 3 },
115908 { 156, 1 },
115909 { 156, 0 },
115910 { 154, 5 },
115911 { 154, 2 },
115912 { 161, 0 },
115913 { 161, 2 },
115914 { 159, 3 },
115915 { 159, 1 },
115916 { 163, 3 },
115917 { 164, 1 },
115918 { 167, 1 },
115919 { 167, 1 },
115920 { 168, 1 },
115921 { 151, 1 },
115922 { 151, 1 },
115923 { 151, 1 },
115924 { 165, 0 },
115925 { 165, 1 },
115926 { 169, 1 },
115927 { 169, 4 },
115928 { 169, 6 },
115929 { 170, 1 },
115930 { 170, 2 },
115931 { 171, 1 },
115932 { 171, 1 },
115933 { 166, 2 },
115934 { 166, 0 },
115935 { 174, 2 },
115936 { 174, 2 },
115937 { 174, 4 },
115938 { 174, 3 },
115939 { 174, 3 },
115940 { 174, 2 },
115941 { 174, 2 },
115942 { 174, 3 },
115943 { 174, 5 },
115944 { 174, 2 },
115945 { 174, 4 },
115946 { 174, 4 },
115947 { 174, 1 },
115948 { 174, 2 },
115949 { 179, 0 },
115950 { 179, 1 },
115951 { 181, 0 },
115952 { 181, 2 },
115953 { 183, 2 },
115954 { 183, 3 },
115955 { 183, 3 },
115956 { 183, 3 },
115957 { 184, 2 },
115958 { 184, 2 },
115959 { 184, 1 },
115960 { 184, 1 },
115961 { 184, 2 },
115962 { 182, 3 },
115963 { 182, 2 },
115964 { 185, 0 },
115965 { 185, 2 },
115966 { 185, 2 },
115967 { 160, 0 },
115968 { 160, 2 },
115969 { 186, 3 },
115970 { 186, 1 },
115971 { 187, 1 },
115972 { 187, 0 },
115973 { 188, 2 },
115974 { 188, 7 },
115975 { 188, 5 },
115976 { 188, 5 },
115977 { 188, 10 },
115978 { 190, 0 },
115979 { 190, 1 },
115980 { 177, 0 },
115981 { 177, 3 },
115982 { 191, 0 },
115983 { 191, 2 },
115984 { 192, 1 },
115985 { 192, 1 },
115986 { 192, 1 },
115987 { 148, 4 },
115988 { 194, 2 },
115989 { 194, 0 },
115990 { 148, 8 },
115991 { 148, 4 },
115992 { 148, 1 },
115993 { 162, 1 },
115994 { 162, 3 },
115995 { 197, 1 },
115996 { 197, 2 },
115997 { 197, 1 },
115998 { 196, 9 },
115999 { 198, 1 },
116000 { 198, 1 },
116001 { 198, 0 },
116002 { 206, 2 },
116003 { 206, 0 },
116004 { 199, 3 },
116005 { 199, 2 },
116006 { 199, 4 },
116007 { 207, 2 },
116008 { 207, 1 },
116009 { 207, 0 },
116010 { 200, 0 },
116011 { 200, 2 },
116012 { 209, 2 },
116013 { 209, 0 },
116014 { 208, 7 },
116015 { 208, 7 },
116016 { 208, 7 },
116017 { 158, 0 },
116018 { 158, 2 },
116019 { 195, 2 },
116020 { 210, 1 },
116021 { 210, 2 },
116022 { 210, 3 },
116023 { 210, 4 },
116024 { 212, 2 },
116025 { 212, 0 },
116026 { 211, 0 },
116027 { 211, 3 },
116028 { 211, 2 },
116029 { 213, 4 },
116030 { 213, 0 },
116031 { 204, 0 },
116032 { 204, 3 },
116033 { 216, 4 },
116034 { 216, 2 },
116035 { 178, 1 },
116036 { 178, 1 },
116037 { 178, 0 },
116038 { 202, 0 },
116039 { 202, 3 },
116040 { 203, 0 },
116041 { 203, 2 },
116042 { 205, 0 },
116043 { 205, 2 },
116044 { 205, 4 },
116045 { 205, 4 },
116046 { 148, 5 },
116047 { 201, 0 },
116048 { 201, 2 },
116049 { 148, 7 },
116050 { 218, 5 },
116051 { 218, 3 },
116052 { 148, 5 },
116053 { 148, 5 },
116054 { 148, 6 },
116055 { 219, 2 },
116056 { 219, 1 },
116057 { 221, 4 },
116058 { 221, 5 },
116059 { 220, 0 },
116060 { 220, 3 },
116061 { 215, 3 },
116062 { 215, 1 },
116063 { 176, 1 },
116064 { 176, 3 },
116065 { 175, 1 },
116066 { 176, 1 },
116067 { 176, 1 },
116068 { 176, 3 },
116069 { 176, 5 },
116070 { 175, 1 },
116071 { 175, 1 },
116072 { 176, 1 },
116073 { 176, 1 },
116074 { 176, 3 },
116075 { 176, 6 },
116076 { 176, 5 },
116077 { 176, 4 },
116078 { 175, 1 },
116079 { 176, 3 },
116080 { 176, 3 },
116081 { 176, 3 },
116082 { 176, 3 },
116083 { 176, 3 },
116084 { 176, 3 },
116085 { 176, 3 },
116086 { 176, 3 },
116087 { 223, 1 },
116088 { 223, 2 },
116089 { 223, 1 },
116090 { 223, 2 },
116091 { 176, 3 },
116092 { 176, 5 },
116093 { 176, 2 },
116094 { 176, 3 },
116095 { 176, 3 },
116096 { 176, 4 },
116097 { 176, 2 },
116098 { 176, 2 },
116099 { 176, 2 },
116100 { 176, 2 },
116101 { 224, 1 },
116102 { 224, 2 },
116103 { 176, 5 },
116104 { 225, 1 },
116105 { 225, 2 },
116106 { 176, 5 },
116107 { 176, 3 },
116108 { 176, 5 },
116109 { 176, 4 },
116110 { 176, 4 },
116111 { 176, 5 },
116112 { 227, 5 },
116113 { 227, 4 },
116114 { 228, 2 },
116115 { 228, 0 },
116116 { 226, 1 },
116117 { 226, 0 },
116118 { 222, 1 },
116119 { 222, 0 },
116120 { 217, 3 },
116121 { 217, 1 },
116122 { 148, 12 },
116123 { 229, 1 },
116124 { 229, 0 },
116125 { 180, 0 },
116126 { 180, 3 },
116127 { 189, 5 },
116128 { 189, 3 },
116129 { 230, 0 },
116130 { 230, 2 },
116131 { 148, 4 },
116132 { 148, 1 },
116133 { 148, 2 },
116134 { 148, 3 },
116135 { 148, 5 },
116136 { 148, 6 },
116137 { 148, 5 },
116138 { 148, 6 },
116139 { 231, 1 },
116140 { 231, 1 },
116141 { 231, 1 },
116142 { 231, 1 },
116143 { 231, 1 },
116144 { 172, 2 },
116145 { 172, 1 },
116146 { 173, 2 },
116147 { 232, 1 },
116148 { 148, 5 },
116149 { 233, 11 },
116150 { 235, 1 },
116151 { 235, 1 },
116152 { 235, 2 },
116153 { 235, 0 },
116154 { 236, 1 },
116155 { 236, 1 },
116156 { 236, 3 },
116157 { 237, 0 },
116158 { 237, 3 },
116159 { 238, 0 },
116160 { 238, 2 },
116161 { 234, 3 },
116162 { 234, 2 },
116163 { 240, 1 },
116164 { 240, 3 },
116165 { 241, 0 },
116166 { 241, 3 },
116167 { 241, 2 },
116168 { 239, 7 },
116169 { 239, 5 },
116170 { 239, 5 },
116171 { 239, 5 },
116172 { 239, 1 },
116173 { 176, 4 },
116174 { 176, 6 },
116175 { 193, 1 },
116176 { 193, 1 },
116177 { 193, 1 },
116178 { 148, 4 },
116179 { 148, 6 },
116180 { 148, 3 },
116181 { 243, 0 },
116182 { 243, 2 },
116183 { 242, 1 },
116184 { 242, 0 },
116185 { 148, 1 },
116186 { 148, 3 },
116187 { 148, 1 },
116188 { 148, 3 },
116189 { 148, 6 },
116190 { 148, 6 },
116191 { 244, 1 },
116192 { 245, 0 },
116193 { 245, 1 },
116194 { 148, 1 },
116195 { 148, 4 },
116196 { 246, 8 },
116197 { 247, 1 },
116198 { 247, 3 },
116199 { 248, 0 },
116200 { 248, 2 },
116201 { 249, 1 },
116202 { 249, 3 },
116203 { 250, 1 },
116204 { 251, 0 },
116205 { 251, 4 },
116206 { 251, 2 },
116207 };
116208
116209 static void yy_accept(yyParser*); /* Forward Declaration */
116210
116211 /*
@@ -114899,21 +116269,21 @@
116269 break;
116270 case 8: /* cmdx ::= cmd */
116271 { sqlite3FinishCoding(pParse); }
116272 break;
116273 case 9: /* cmd ::= BEGIN transtype trans_opt */
116274 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
116275 break;
116276 case 13: /* transtype ::= */
116277 {yygotominor.yy4 = TK_DEFERRED;}
116278 break;
116279 case 14: /* transtype ::= DEFERRED */
116280 case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15);
116281 case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16);
116282 case 117: /* multiselect_op ::= UNION */ yytestcase(yyruleno==117);
116283 case 119: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==119);
116284 {yygotominor.yy4 = yymsp[0].major;}
116285 break;
116286 case 17: /* cmd ::= COMMIT trans_opt */
116287 case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18);
116288 {sqlite3CommitTransaction(pParse);}
116289 break;
@@ -114935,11 +116305,11 @@
116305 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
116306 }
116307 break;
116308 case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
116309 {
116310 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
116311 }
116312 break;
116313 case 27: /* createkw ::= CREATE */
116314 {
116315 pParse->db->lookaside.bEnabled = 0;
@@ -114946,1051 +116316,1064 @@
116316 yygotominor.yy0 = yymsp[0].minor.yy0;
116317 }
116318 break;
116319 case 28: /* ifnotexists ::= */
116320 case 31: /* temp ::= */ yytestcase(yyruleno==31);
116321 case 71: /* autoinc ::= */ yytestcase(yyruleno==71);
116322 case 84: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==84);
116323 case 86: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==86);
116324 case 88: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==88);
116325 case 100: /* defer_subclause_opt ::= */ yytestcase(yyruleno==100);
116326 case 111: /* ifexists ::= */ yytestcase(yyruleno==111);
116327 case 223: /* between_op ::= BETWEEN */ yytestcase(yyruleno==223);
116328 case 226: /* in_op ::= IN */ yytestcase(yyruleno==226);
116329 {yygotominor.yy4 = 0;}
116330 break;
116331 case 29: /* ifnotexists ::= IF NOT EXISTS */
116332 case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
116333 case 72: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==72);
116334 case 87: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==87);
116335 case 110: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==110);
116336 case 224: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==224);
116337 case 227: /* in_op ::= NOT IN */ yytestcase(yyruleno==227);
116338 {yygotominor.yy4 = 1;}
116339 break;
116340 case 32: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
116341 {
116342 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy210,0);
116343 }
116344 break;
116345 case 33: /* create_table_args ::= AS select */
116346 {
116347 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy387);
116348 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
116349 }
116350 break;
116351 case 34: /* table_options ::= */
116352 {yygotominor.yy210 = 0;}
116353 break;
116354 case 35: /* table_options ::= WITHOUT nm */
116355 {
116356 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
116357 yygotominor.yy210 = TF_WithoutRowid;
116358 }else{
116359 yygotominor.yy210 = 0;
116360 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
116361 }
116362 }
116363 break;
116364 case 38: /* column ::= columnid type carglist */
116365 {
116366 yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
116367 yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
116368 }
116369 break;
116370 case 39: /* columnid ::= nm */
116371 {
116372 sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
116373 yygotominor.yy0 = yymsp[0].minor.yy0;
116374 pParse->constraintName.n = 0;
116375 }
116376 break;
116377 case 40: /* id ::= ID */
116378 case 41: /* id ::= INDEXED */ yytestcase(yyruleno==41);
116379 case 42: /* ids ::= ID|STRING */ yytestcase(yyruleno==42);
116380 case 43: /* nm ::= id */ yytestcase(yyruleno==43);
116381 case 44: /* nm ::= STRING */ yytestcase(yyruleno==44);
116382 case 45: /* nm ::= JOIN_KW */ yytestcase(yyruleno==45);
116383 case 48: /* typetoken ::= typename */ yytestcase(yyruleno==48);
116384 case 51: /* typename ::= ids */ yytestcase(yyruleno==51);
116385 case 129: /* as ::= AS nm */ yytestcase(yyruleno==129);
116386 case 130: /* as ::= ids */ yytestcase(yyruleno==130);
116387 case 140: /* dbnm ::= DOT nm */ yytestcase(yyruleno==140);
116388 case 149: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==149);
116389 case 252: /* collate ::= COLLATE ids */ yytestcase(yyruleno==252);
116390 case 261: /* nmnum ::= plus_num */ yytestcase(yyruleno==261);
116391 case 262: /* nmnum ::= nm */ yytestcase(yyruleno==262);
116392 case 263: /* nmnum ::= ON */ yytestcase(yyruleno==263);
116393 case 264: /* nmnum ::= DELETE */ yytestcase(yyruleno==264);
116394 case 265: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==265);
116395 case 266: /* plus_num ::= PLUS number */ yytestcase(yyruleno==266);
116396 case 267: /* plus_num ::= number */ yytestcase(yyruleno==267);
116397 case 268: /* minus_num ::= MINUS number */ yytestcase(yyruleno==268);
116398 case 269: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==269);
116399 case 285: /* trnm ::= nm */ yytestcase(yyruleno==285);
116400 {yygotominor.yy0 = yymsp[0].minor.yy0;}
116401 break;
116402 case 47: /* type ::= typetoken */
116403 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
116404 break;
116405 case 49: /* typetoken ::= typename LP signed RP */
116406 {
116407 yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
116408 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
116409 }
116410 break;
116411 case 50: /* typetoken ::= typename LP signed COMMA signed RP */
116412 {
116413 yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
116414 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
116415 }
116416 break;
116417 case 52: /* typename ::= typename ids */
116418 {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
116419 break;
116420 case 57: /* ccons ::= CONSTRAINT nm */
116421 case 95: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==95);
116422 {pParse->constraintName = yymsp[0].minor.yy0;}
116423 break;
116424 case 58: /* ccons ::= DEFAULT term */
116425 case 60: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==60);
116426 {sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy118);}
116427 break;
116428 case 59: /* ccons ::= DEFAULT LP expr RP */
116429 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy118);}
116430 break;
116431 case 61: /* ccons ::= DEFAULT MINUS term */
116432 {
116433 ExprSpan v;
116434 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy118.pExpr, 0, 0);
116435 v.zStart = yymsp[-1].minor.yy0.z;
116436 v.zEnd = yymsp[0].minor.yy118.zEnd;
116437 sqlite3AddDefaultValue(pParse,&v);
116438 }
116439 break;
116440 case 62: /* ccons ::= DEFAULT id */
116441 {
116442 ExprSpan v;
116443 spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0);
116444 sqlite3AddDefaultValue(pParse,&v);
116445 }
116446 break;
116447 case 64: /* ccons ::= NOT NULL onconf */
116448 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
116449 break;
116450 case 65: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
116451 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
116452 break;
116453 case 66: /* ccons ::= UNIQUE onconf */
116454 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0);}
116455 break;
116456 case 67: /* ccons ::= CHECK LP expr RP */
116457 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy118.pExpr);}
116458 break;
116459 case 68: /* ccons ::= REFERENCES nm idxlist_opt refargs */
116460 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
116461 break;
116462 case 69: /* ccons ::= defer_subclause */
116463 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
116464 break;
116465 case 70: /* ccons ::= COLLATE ids */
116466 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
116467 break;
116468 case 73: /* refargs ::= */
116469 { yygotominor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
116470 break;
116471 case 74: /* refargs ::= refargs refarg */
116472 { yygotominor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
116473 break;
116474 case 75: /* refarg ::= MATCH nm */
116475 case 76: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==76);
116476 { yygotominor.yy215.value = 0; yygotominor.yy215.mask = 0x000000; }
116477 break;
116478 case 77: /* refarg ::= ON DELETE refact */
116479 { yygotominor.yy215.value = yymsp[0].minor.yy4; yygotominor.yy215.mask = 0x0000ff; }
116480 break;
116481 case 78: /* refarg ::= ON UPDATE refact */
116482 { yygotominor.yy215.value = yymsp[0].minor.yy4<<8; yygotominor.yy215.mask = 0x00ff00; }
116483 break;
116484 case 79: /* refact ::= SET NULL */
116485 { yygotominor.yy4 = OE_SetNull; /* EV: R-33326-45252 */}
116486 break;
116487 case 80: /* refact ::= SET DEFAULT */
116488 { yygotominor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */}
116489 break;
116490 case 81: /* refact ::= CASCADE */
116491 { yygotominor.yy4 = OE_Cascade; /* EV: R-33326-45252 */}
116492 break;
116493 case 82: /* refact ::= RESTRICT */
116494 { yygotominor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
116495 break;
116496 case 83: /* refact ::= NO ACTION */
116497 { yygotominor.yy4 = OE_None; /* EV: R-33326-45252 */}
116498 break;
116499 case 85: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
116500 case 101: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==101);
116501 case 103: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==103);
116502 case 106: /* resolvetype ::= raisetype */ yytestcase(yyruleno==106);
116503 {yygotominor.yy4 = yymsp[0].minor.yy4;}
116504 break;
116505 case 89: /* conslist_opt ::= */
116506 {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
116507 break;
116508 case 90: /* conslist_opt ::= COMMA conslist */
116509 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
116510 break;
116511 case 93: /* tconscomma ::= COMMA */
116512 {pParse->constraintName.n = 0;}
116513 break;
116514 case 96: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
116515 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
116516 break;
116517 case 97: /* tcons ::= UNIQUE LP idxlist RP onconf */
116518 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0);}
116519 break;
116520 case 98: /* tcons ::= CHECK LP expr RP onconf */
116521 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy118.pExpr);}
116522 break;
116523 case 99: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
116524 {
116525 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
116526 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
116527 }
116528 break;
116529 case 102: /* onconf ::= */
116530 {yygotominor.yy4 = OE_Default;}
116531 break;
116532 case 104: /* orconf ::= */
116533 {yygotominor.yy210 = OE_Default;}
116534 break;
116535 case 105: /* orconf ::= OR resolvetype */
116536 {yygotominor.yy210 = (u8)yymsp[0].minor.yy4;}
116537 break;
116538 case 107: /* resolvetype ::= IGNORE */
116539 {yygotominor.yy4 = OE_Ignore;}
116540 break;
116541 case 108: /* resolvetype ::= REPLACE */
116542 {yygotominor.yy4 = OE_Replace;}
116543 break;
116544 case 109: /* cmd ::= DROP TABLE ifexists fullname */
116545 {
116546 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
116547 }
116548 break;
116549 case 112: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
116550 {
116551 sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy387, yymsp[-6].minor.yy4, yymsp[-4].minor.yy4);
116552 }
116553 break;
116554 case 113: /* cmd ::= DROP VIEW ifexists fullname */
116555 {
116556 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
116557 }
116558 break;
116559 case 114: /* cmd ::= select */
116560 {
116561 SelectDest dest = {SRT_Output, 0, 0, 0, 0};
116562 sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
116563 sqlite3ExplainBegin(pParse->pVdbe);
116564 sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy387);
116565 sqlite3ExplainFinish(pParse->pVdbe);
116566 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
116567 }
116568 break;
116569 case 115: /* select ::= oneselect */
116570 {yygotominor.yy387 = yymsp[0].minor.yy387;}
116571 break;
116572 case 116: /* select ::= select multiselect_op oneselect */
116573 {
116574 if( yymsp[0].minor.yy387 ){
116575 yymsp[0].minor.yy387->op = (u8)yymsp[-1].minor.yy4;
116576 yymsp[0].minor.yy387->pPrior = yymsp[-2].minor.yy387;
116577 if( yymsp[-1].minor.yy4!=TK_ALL ) pParse->hasCompound = 1;
116578 }else{
116579 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
116580 }
116581 yygotominor.yy387 = yymsp[0].minor.yy387;
116582 }
116583 break;
116584 case 118: /* multiselect_op ::= UNION ALL */
116585 {yygotominor.yy4 = TK_ALL;}
116586 break;
116587 case 120: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
116588 {
116589 yygotominor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy177,yymsp[0].minor.yy292.pLimit,yymsp[0].minor.yy292.pOffset);
116590 }
116591 break;
116592 case 121: /* distinct ::= DISTINCT */
116593 {yygotominor.yy177 = SF_Distinct;}
116594 break;
116595 case 122: /* distinct ::= ALL */
116596 case 123: /* distinct ::= */ yytestcase(yyruleno==123);
116597 {yygotominor.yy177 = 0;}
116598 break;
116599 case 124: /* sclp ::= selcollist COMMA */
116600 case 248: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==248);
116601 {yygotominor.yy322 = yymsp[-1].minor.yy322;}
116602 break;
116603 case 125: /* sclp ::= */
116604 case 153: /* orderby_opt ::= */ yytestcase(yyruleno==153);
116605 case 160: /* groupby_opt ::= */ yytestcase(yyruleno==160);
116606 case 241: /* exprlist ::= */ yytestcase(yyruleno==241);
116607 case 247: /* idxlist_opt ::= */ yytestcase(yyruleno==247);
116608 {yygotominor.yy322 = 0;}
116609 break;
116610 case 126: /* selcollist ::= sclp expr as */
116611 {
116612 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, yymsp[-1].minor.yy118.pExpr);
116613 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[0].minor.yy0, 1);
116614 sqlite3ExprListSetSpan(pParse,yygotominor.yy322,&yymsp[-1].minor.yy118);
116615 }
116616 break;
116617 case 127: /* selcollist ::= sclp STAR */
116618 {
116619 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
116620 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy322, p);
116621 }
116622 break;
116623 case 128: /* selcollist ::= sclp nm DOT STAR */
116624 {
116625 Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
116626 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
116627 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
116628 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, pDot);
116629 }
116630 break;
116631 case 131: /* as ::= */
116632 {yygotominor.yy0.n = 0;}
116633 break;
116634 case 132: /* from ::= */
116635 {yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
116636 break;
116637 case 133: /* from ::= FROM seltablist */
116638 {
116639 yygotominor.yy259 = yymsp[0].minor.yy259;
116640 sqlite3SrcListShiftJoinType(yygotominor.yy259);
116641 }
116642 break;
116643 case 134: /* stl_prefix ::= seltablist joinop */
116644 {
116645 yygotominor.yy259 = yymsp[-1].minor.yy259;
116646 if( ALWAYS(yygotominor.yy259 && yygotominor.yy259->nSrc>0) ) yygotominor.yy259->a[yygotominor.yy259->nSrc-1].jointype = (u8)yymsp[0].minor.yy4;
116647 }
116648 break;
116649 case 135: /* stl_prefix ::= */
116650 {yygotominor.yy259 = 0;}
116651 break;
116652 case 136: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
116653 {
116654 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
116655 sqlite3SrcListIndexedBy(pParse, yygotominor.yy259, &yymsp[-2].minor.yy0);
116656 }
116657 break;
116658 case 137: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
116659 {
116660 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
116661 }
116662 break;
116663 case 138: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
116664 {
116665 if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
116666 yygotominor.yy259 = yymsp[-4].minor.yy259;
116667 }else if( yymsp[-4].minor.yy259->nSrc==1 ){
116668 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
116669 if( yygotominor.yy259 ){
116670 struct SrcList_item *pNew = &yygotominor.yy259->a[yygotominor.yy259->nSrc-1];
116671 struct SrcList_item *pOld = yymsp[-4].minor.yy259->a;
116672 pNew->zName = pOld->zName;
116673 pNew->zDatabase = pOld->zDatabase;
116674 pNew->pSelect = pOld->pSelect;
116675 pOld->zName = pOld->zDatabase = 0;
116676 pOld->pSelect = 0;
116677 }
116678 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy259);
116679 }else{
116680 Select *pSubquery;
116681 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
116682 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,SF_NestedFrom,0,0);
116683 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
116684 }
116685 }
116686 break;
116687 case 139: /* dbnm ::= */
116688 case 148: /* indexed_opt ::= */ yytestcase(yyruleno==148);
116689 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
116690 break;
116691 case 141: /* fullname ::= nm dbnm */
116692 {yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
116693 break;
116694 case 142: /* joinop ::= COMMA|JOIN */
116695 { yygotominor.yy4 = JT_INNER; }
116696 break;
116697 case 143: /* joinop ::= JOIN_KW JOIN */
116698 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
116699 break;
116700 case 144: /* joinop ::= JOIN_KW nm JOIN */
116701 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
116702 break;
116703 case 145: /* joinop ::= JOIN_KW nm nm JOIN */
116704 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
116705 break;
116706 case 146: /* on_opt ::= ON expr */
116707 case 163: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==163);
116708 case 170: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==170);
116709 case 236: /* case_else ::= ELSE expr */ yytestcase(yyruleno==236);
116710 case 238: /* case_operand ::= expr */ yytestcase(yyruleno==238);
116711 {yygotominor.yy314 = yymsp[0].minor.yy118.pExpr;}
116712 break;
116713 case 147: /* on_opt ::= */
116714 case 162: /* having_opt ::= */ yytestcase(yyruleno==162);
116715 case 169: /* where_opt ::= */ yytestcase(yyruleno==169);
116716 case 237: /* case_else ::= */ yytestcase(yyruleno==237);
116717 case 239: /* case_operand ::= */ yytestcase(yyruleno==239);
116718 {yygotominor.yy314 = 0;}
116719 break;
116720 case 150: /* indexed_opt ::= NOT INDEXED */
116721 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
116722 break;
116723 case 151: /* using_opt ::= USING LP idlist RP */
116724 case 182: /* inscollist_opt ::= LP idlist RP */ yytestcase(yyruleno==182);
116725 {yygotominor.yy384 = yymsp[-1].minor.yy384;}
116726 break;
116727 case 152: /* using_opt ::= */
116728 case 181: /* inscollist_opt ::= */ yytestcase(yyruleno==181);
116729 {yygotominor.yy384 = 0;}
116730 break;
116731 case 154: /* orderby_opt ::= ORDER BY sortlist */
116732 case 161: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==161);
116733 case 240: /* exprlist ::= nexprlist */ yytestcase(yyruleno==240);
116734 {yygotominor.yy322 = yymsp[0].minor.yy322;}
116735 break;
116736 case 155: /* sortlist ::= sortlist COMMA expr sortorder */
116737 {
116738 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy118.pExpr);
116739 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
116740 }
116741 break;
116742 case 156: /* sortlist ::= expr sortorder */
116743 {
116744 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy118.pExpr);
116745 if( yygotominor.yy322 && ALWAYS(yygotominor.yy322->a) ) yygotominor.yy322->a[0].sortOrder = (u8)yymsp[0].minor.yy4;
116746 }
116747 break;
116748 case 157: /* sortorder ::= ASC */
116749 case 159: /* sortorder ::= */ yytestcase(yyruleno==159);
116750 {yygotominor.yy4 = SQLITE_SO_ASC;}
116751 break;
116752 case 158: /* sortorder ::= DESC */
116753 {yygotominor.yy4 = SQLITE_SO_DESC;}
116754 break;
116755 case 164: /* limit_opt ::= */
116756 {yygotominor.yy292.pLimit = 0; yygotominor.yy292.pOffset = 0;}
116757 break;
116758 case 165: /* limit_opt ::= LIMIT expr */
116759 {yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr; yygotominor.yy292.pOffset = 0;}
116760 break;
116761 case 166: /* limit_opt ::= LIMIT expr OFFSET expr */
116762 {yygotominor.yy292.pLimit = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pOffset = yymsp[0].minor.yy118.pExpr;}
116763 break;
116764 case 167: /* limit_opt ::= LIMIT expr COMMA expr */
116765 {yygotominor.yy292.pOffset = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr;}
116766 break;
116767 case 168: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
116768 {
116769 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
116770 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314);
116771 }
116772 break;
116773 case 171: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
116774 {
116775 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
116776 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list");
116777 sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy210);
116778 }
116779 break;
116780 case 172: /* setlist ::= setlist COMMA nm EQ expr */
116781 {
116782 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy118.pExpr);
116783 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
116784 }
116785 break;
116786 case 173: /* setlist ::= nm EQ expr */
116787 {
116788 yygotominor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy118.pExpr);
116789 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
116790 }
116791 break;
116792 case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt valuelist */
116793 {sqlite3Insert(pParse, yymsp[-2].minor.yy259, yymsp[0].minor.yy260.pList, yymsp[0].minor.yy260.pSelect, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
116794 break;
116795 case 175: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
116796 {sqlite3Insert(pParse, yymsp[-2].minor.yy259, 0, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
116797 break;
116798 case 176: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
116799 {sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy210);}
116800 break;
116801 case 177: /* insert_cmd ::= INSERT orconf */
116802 {yygotominor.yy210 = yymsp[0].minor.yy210;}
116803 break;
116804 case 178: /* insert_cmd ::= REPLACE */
116805 {yygotominor.yy210 = OE_Replace;}
116806 break;
116807 case 179: /* valuelist ::= VALUES LP nexprlist RP */
116808 {
116809 yygotominor.yy260.pList = yymsp[-1].minor.yy322;
116810 yygotominor.yy260.pSelect = 0;
116811 }
116812 break;
116813 case 180: /* valuelist ::= valuelist COMMA LP exprlist RP */
116814 {
116815 Select *pRight = sqlite3SelectNew(pParse, yymsp[-1].minor.yy322, 0, 0, 0, 0, 0, 0, 0, 0);
116816 if( yymsp[-4].minor.yy260.pList ){
116817 yymsp[-4].minor.yy260.pSelect = sqlite3SelectNew(pParse, yymsp[-4].minor.yy260.pList, 0, 0, 0, 0, 0, 0, 0, 0);
116818 yymsp[-4].minor.yy260.pList = 0;
116819 }
116820 yygotominor.yy260.pList = 0;
116821 if( yymsp[-4].minor.yy260.pSelect==0 || pRight==0 ){
116822 sqlite3SelectDelete(pParse->db, pRight);
116823 sqlite3SelectDelete(pParse->db, yymsp[-4].minor.yy260.pSelect);
116824 yygotominor.yy260.pSelect = 0;
116825 }else{
116826 pRight->op = TK_ALL;
116827 pRight->pPrior = yymsp[-4].minor.yy260.pSelect;
116828 pRight->selFlags |= SF_Values;
116829 pRight->pPrior->selFlags |= SF_Values;
116830 yygotominor.yy260.pSelect = pRight;
116831 }
116832 }
116833 break;
116834 case 183: /* idlist ::= idlist COMMA nm */
116835 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
116836 break;
116837 case 184: /* idlist ::= nm */
116838 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
116839 break;
116840 case 185: /* expr ::= term */
116841 {yygotominor.yy118 = yymsp[0].minor.yy118;}
116842 break;
116843 case 186: /* expr ::= LP expr RP */
116844 {yygotominor.yy118.pExpr = yymsp[-1].minor.yy118.pExpr; spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
116845 break;
116846 case 187: /* term ::= NULL */
116847 case 192: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==192);
116848 case 193: /* term ::= STRING */ yytestcase(yyruleno==193);
116849 {spanExpr(&yygotominor.yy118, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
116850 break;
116851 case 188: /* expr ::= id */
116852 case 189: /* expr ::= JOIN_KW */ yytestcase(yyruleno==189);
116853 {spanExpr(&yygotominor.yy118, pParse, TK_ID, &yymsp[0].minor.yy0);}
116854 break;
116855 case 190: /* expr ::= nm DOT nm */
116856 {
116857 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
116858 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
116859 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
116860 spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
116861 }
116862 break;
116863 case 191: /* expr ::= nm DOT nm DOT nm */
116864 {
116865 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
116866 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
116867 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
116868 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
116869 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
116870 spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
116871 }
116872 break;
116873 case 194: /* expr ::= REGISTER */
116874 {
116875 /* When doing a nested parse, one can include terms in an expression
116876 ** that look like this: #1 #2 ... These terms refer to registers
116877 ** in the virtual machine. #N is the N-th register. */
116878 if( pParse->nested==0 ){
116879 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &yymsp[0].minor.yy0);
116880 yygotominor.yy118.pExpr = 0;
116881 }else{
116882 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
116883 if( yygotominor.yy118.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy118.pExpr->iTable);
116884 }
116885 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116886 }
116887 break;
116888 case 195: /* expr ::= VARIABLE */
116889 {
116890 spanExpr(&yygotominor.yy118, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
116891 sqlite3ExprAssignVarNumber(pParse, yygotominor.yy118.pExpr);
116892 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116893 }
116894 break;
116895 case 196: /* expr ::= expr COLLATE ids */
116896 {
116897 yygotominor.yy118.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
116898 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
116899 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
116900 }
116901 break;
116902 case 197: /* expr ::= CAST LP expr AS typetoken RP */
116903 {
116904 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy118.pExpr, 0, &yymsp[-1].minor.yy0);
116905 spanSet(&yygotominor.yy118,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
116906 }
116907 break;
116908 case 198: /* expr ::= ID LP distinct exprlist RP */
116909 {
116910 if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
116911 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
116912 }
116913 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
116914 spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
116915 if( yymsp[-2].minor.yy177 && yygotominor.yy118.pExpr ){
116916 yygotominor.yy118.pExpr->flags |= EP_Distinct;
116917 }
116918 }
116919 break;
116920 case 199: /* expr ::= ID LP STAR RP */
116921 {
116922 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
116923 spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
116924 }
116925 break;
116926 case 200: /* term ::= CTIME_KW */
116927 {
116928 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
116929 ** treated as functions that return constants */
116930 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
116931 if( yygotominor.yy118.pExpr ){
116932 yygotominor.yy118.pExpr->op = TK_CONST_FUNC;
116933 }
116934 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116935 }
116936 break;
116937 case 201: /* expr ::= expr AND expr */
116938 case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
116939 case 203: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==203);
116940 case 204: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==204);
116941 case 205: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==205);
116942 case 206: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==206);
116943 case 207: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==207);
116944 case 208: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==208);
116945 {spanBinaryExpr(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);}
116946 break;
116947 case 209: /* likeop ::= LIKE_KW */
116948 case 211: /* likeop ::= MATCH */ yytestcase(yyruleno==211);
116949 {yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.bNot = 0;}
116950 break;
116951 case 210: /* likeop ::= NOT LIKE_KW */
116952 case 212: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==212);
116953 {yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.bNot = 1;}
116954 break;
116955 case 213: /* expr ::= expr likeop expr */
116956 {
116957 ExprList *pList;
116958 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy118.pExpr);
116959 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy118.pExpr);
116960 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy342.eOperator);
116961 if( yymsp[-1].minor.yy342.bNot ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
116962 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
116963 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
116964 if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
116965 }
116966 break;
116967 case 214: /* expr ::= expr likeop expr ESCAPE expr */
116968 {
116969 ExprList *pList;
116970 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
116971 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy118.pExpr);
116972 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
116973 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy342.eOperator);
116974 if( yymsp[-3].minor.yy342.bNot ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
116975 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
116976 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
116977 if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
116978 }
116979 break;
116980 case 215: /* expr ::= expr ISNULL|NOTNULL */
116981 {spanUnaryPostfix(&yygotominor.yy118,pParse,yymsp[0].major,&yymsp[-1].minor.yy118,&yymsp[0].minor.yy0);}
116982 break;
116983 case 216: /* expr ::= expr NOT NULL */
116984 {spanUnaryPostfix(&yygotominor.yy118,pParse,TK_NOTNULL,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy0);}
116985 break;
116986 case 217: /* expr ::= expr IS expr */
116987 {
116988 spanBinaryExpr(&yygotominor.yy118,pParse,TK_IS,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);
116989 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_ISNULL);
116990 }
116991 break;
116992 case 218: /* expr ::= expr IS NOT expr */
116993 {
116994 spanBinaryExpr(&yygotominor.yy118,pParse,TK_ISNOT,&yymsp[-3].minor.yy118,&yymsp[0].minor.yy118);
116995 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_NOTNULL);
116996 }
116997 break;
116998 case 219: /* expr ::= NOT expr */
116999 case 220: /* expr ::= BITNOT expr */ yytestcase(yyruleno==220);
117000 {spanUnaryPrefix(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
117001 break;
117002 case 221: /* expr ::= MINUS expr */
117003 {spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UMINUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
117004 break;
117005 case 222: /* expr ::= PLUS expr */
117006 {spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UPLUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
117007 break;
117008 case 225: /* expr ::= expr between_op expr AND expr */
117009 {
117010 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
117011 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
117012 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy118.pExpr, 0, 0);
117013 if( yygotominor.yy118.pExpr ){
117014 yygotominor.yy118.pExpr->x.pList = pList;
117015 }else{
117016 sqlite3ExprListDelete(pParse->db, pList);
117017 }
117018 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117019 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
117020 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
117021 }
117022 break;
117023 case 228: /* expr ::= expr in_op LP exprlist RP */
117024 {
117025 if( yymsp[-1].minor.yy322==0 ){
117026 /* Expressions of the form
117027 **
117028 ** expr1 IN ()
117029 ** expr1 NOT IN ()
117030 **
117031 ** simplify to constants 0 (false) and 1 (true), respectively,
117032 ** regardless of the value of expr1.
117033 */
117034 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy4]);
117035 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy118.pExpr);
117036 }else{
117037 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
117038 if( yygotominor.yy118.pExpr ){
117039 yygotominor.yy118.pExpr->x.pList = yymsp[-1].minor.yy322;
117040 sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117041 }else{
117042 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
117043 }
117044 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117045 }
117046 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
117047 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117048 }
117049 break;
117050 case 229: /* expr ::= LP select RP */
117051 {
117052 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
117053 if( yygotominor.yy118.pExpr ){
117054 yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
117055 ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
117056 sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117057 }else{
117058 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
117059 }
117060 yygotominor.yy118.zStart = yymsp[-2].minor.yy0.z;
117061 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117062 }
117063 break;
117064 case 230: /* expr ::= expr in_op LP select RP */
117065 {
117066 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
117067 if( yygotominor.yy118.pExpr ){
117068 yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
117069 ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
117070 sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117071 }else{
117072 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
117073 }
117074 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117075 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
117076 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117077 }
117078 break;
117079 case 231: /* expr ::= expr in_op nm dbnm */
117080 {
117081 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
117082 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy118.pExpr, 0, 0);
117083 if( yygotominor.yy118.pExpr ){
117084 yygotominor.yy118.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
117085 ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
117086 sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117087 }else{
117088 sqlite3SrcListDelete(pParse->db, pSrc);
117089 }
117090 if( yymsp[-2].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
117091 yygotominor.yy118.zStart = yymsp[-3].minor.yy118.zStart;
117092 yygotominor.yy118.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
117093 }
117094 break;
117095 case 232: /* expr ::= EXISTS LP select RP */
117096 {
117097 Expr *p = yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
117098 if( p ){
117099 p->x.pSelect = yymsp[-1].minor.yy387;
117100 ExprSetProperty(p, EP_xIsSelect);
117101 sqlite3ExprSetHeight(pParse, p);
117102 }else{
117103 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
117104 }
117105 yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
117106 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117107 }
117108 break;
117109 case 233: /* expr ::= CASE case_operand case_exprlist case_else END */
117110 {
117111 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, 0, 0);
117112 if( yygotominor.yy118.pExpr ){
117113 yygotominor.yy118.pExpr->x.pList = yymsp[-1].minor.yy314 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy314) : yymsp[-2].minor.yy322;
117114 sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
117115 }else{
117116 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
117117 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy314);
117118 }
117119 yygotominor.yy118.zStart = yymsp[-4].minor.yy0.z;
117120 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117121 }
117122 break;
117123 case 234: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
117124 {
117125 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy118.pExpr);
117126 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
117127 }
117128 break;
117129 case 235: /* case_exprlist ::= WHEN expr THEN expr */
117130 {
117131 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
117132 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
117133 }
117134 break;
117135 case 242: /* nexprlist ::= nexprlist COMMA expr */
117136 {yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy118.pExpr);}
117137 break;
117138 case 243: /* nexprlist ::= expr */
117139 {yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy118.pExpr);}
117140 break;
117141 case 244: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt */
117142 {
117143 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
117144 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy4,
117145 &yymsp[-11].minor.yy0, yymsp[0].minor.yy314, SQLITE_SO_ASC, yymsp[-8].minor.yy4);
117146 }
117147 break;
117148 case 245: /* uniqueflag ::= UNIQUE */
117149 case 298: /* raisetype ::= ABORT */ yytestcase(yyruleno==298);
117150 {yygotominor.yy4 = OE_Abort;}
117151 break;
117152 case 246: /* uniqueflag ::= */
117153 {yygotominor.yy4 = OE_None;}
117154 break;
117155 case 249: /* idxlist ::= idxlist COMMA nm collate sortorder */
117156 {
117157 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
117158 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
117159 sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
117160 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
117161 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
117162 }
117163 break;
117164 case 250: /* idxlist ::= nm collate sortorder */
117165 {
117166 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
117167 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
117168 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
117169 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
117170 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
117171 }
117172 break;
117173 case 251: /* collate ::= */
117174 {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
117175 break;
117176 case 253: /* cmd ::= DROP INDEX ifexists fullname */
117177 {sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
117178 break;
117179 case 254: /* cmd ::= VACUUM */
117180 case 255: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==255);
117181 {sqlite3Vacuum(pParse);}
117182 break;
117183 case 256: /* cmd ::= PRAGMA nm dbnm */
117184 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
117185 break;
117186 case 257: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
117187 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
117188 break;
117189 case 258: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
117190 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
117191 break;
117192 case 259: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
117193 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
117194 break;
117195 case 260: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
117196 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
117197 break;
117198 case 270: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
117199 {
117200 Token all;
117201 all.z = yymsp[-3].minor.yy0.z;
117202 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
117203 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
117204 }
117205 break;
117206 case 271: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
117207 {
117208 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
117209 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
117210 }
117211 break;
117212 case 272: /* trigger_time ::= BEFORE */
117213 case 275: /* trigger_time ::= */ yytestcase(yyruleno==275);
117214 { yygotominor.yy4 = TK_BEFORE; }
117215 break;
117216 case 273: /* trigger_time ::= AFTER */
117217 { yygotominor.yy4 = TK_AFTER; }
117218 break;
117219 case 274: /* trigger_time ::= INSTEAD OF */
117220 { yygotominor.yy4 = TK_INSTEAD;}
117221 break;
117222 case 276: /* trigger_event ::= DELETE|INSERT */
117223 case 277: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==277);
117224 {yygotominor.yy90.a = yymsp[0].major; yygotominor.yy90.b = 0;}
117225 break;
117226 case 278: /* trigger_event ::= UPDATE OF idlist */
117227 {yygotominor.yy90.a = TK_UPDATE; yygotominor.yy90.b = yymsp[0].minor.yy384;}
117228 break;
117229 case 281: /* when_clause ::= */
117230 case 303: /* key_opt ::= */ yytestcase(yyruleno==303);
117231 { yygotominor.yy314 = 0; }
117232 break;
117233 case 282: /* when_clause ::= WHEN expr */
117234 case 304: /* key_opt ::= KEY expr */ yytestcase(yyruleno==304);
117235 { yygotominor.yy314 = yymsp[0].minor.yy118.pExpr; }
117236 break;
117237 case 283: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
117238 {
117239 assert( yymsp[-2].minor.yy203!=0 );
117240 yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
117241 yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
117242 yygotominor.yy203 = yymsp[-2].minor.yy203;
117243 }
117244 break;
117245 case 284: /* trigger_cmd_list ::= trigger_cmd SEMI */
117246 {
117247 assert( yymsp[-1].minor.yy203!=0 );
117248 yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
117249 yygotominor.yy203 = yymsp[-1].minor.yy203;
117250 }
117251 break;
117252 case 286: /* trnm ::= nm DOT nm */
117253 {
117254 yygotominor.yy0 = yymsp[0].minor.yy0;
117255 sqlite3ErrorMsg(pParse,
117256 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
117257 "statements within triggers");
117258 }
117259 break;
117260 case 288: /* tridxby ::= INDEXED BY nm */
117261 {
117262 sqlite3ErrorMsg(pParse,
117263 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
117264 "within triggers");
117265 }
117266 break;
117267 case 289: /* tridxby ::= NOT INDEXED */
117268 {
117269 sqlite3ErrorMsg(pParse,
117270 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
117271 "within triggers");
117272 }
117273 break;
117274 case 290: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
117275 { yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
117276 break;
117277 case 291: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt valuelist */
117278 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, yymsp[0].minor.yy260.pList, yymsp[0].minor.yy260.pSelect, yymsp[-4].minor.yy210);}
117279 break;
117280 case 292: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
117281 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
117282 break;
117283 case 293: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
117284 {yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
117285 break;
117286 case 294: /* trigger_cmd ::= select */
117287 {yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
117288 break;
117289 case 295: /* expr ::= RAISE LP IGNORE RP */
117290 {
117291 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
117292 if( yygotominor.yy118.pExpr ){
117293 yygotominor.yy118.pExpr->affinity = OE_Ignore;
117294 }
117295 yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
117296 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117297 }
117298 break;
117299 case 296: /* expr ::= RAISE LP raisetype COMMA nm RP */
117300 {
117301 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
117302 if( yygotominor.yy118.pExpr ) {
117303 yygotominor.yy118.pExpr->affinity = (char)yymsp[-3].minor.yy4;
117304 }
117305 yygotominor.yy118.zStart = yymsp[-5].minor.yy0.z;
117306 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
117307 }
117308 break;
117309 case 297: /* raisetype ::= ROLLBACK */
117310 {yygotominor.yy4 = OE_Rollback;}
117311 break;
117312 case 299: /* raisetype ::= FAIL */
117313 {yygotominor.yy4 = OE_Fail;}
117314 break;
117315 case 300: /* cmd ::= DROP TRIGGER ifexists fullname */
117316 {
117317 sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
117318 }
117319 break;
117320 case 301: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
117321 {
117322 sqlite3Attach(pParse, yymsp[-3].minor.yy118.pExpr, yymsp[-1].minor.yy118.pExpr, yymsp[0].minor.yy314);
117323 }
117324 break;
117325 case 302: /* cmd ::= DETACH database_kw_opt expr */
117326 {
117327 sqlite3Detach(pParse, yymsp[0].minor.yy118.pExpr);
117328 }
117329 break;
117330 case 307: /* cmd ::= REINDEX */
117331 {sqlite3Reindex(pParse, 0, 0);}
117332 break;
117333 case 308: /* cmd ::= REINDEX nm dbnm */
117334 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
117335 break;
117336 case 309: /* cmd ::= ANALYZE */
117337 {sqlite3Analyze(pParse, 0, 0);}
117338 break;
117339 case 310: /* cmd ::= ANALYZE nm dbnm */
117340 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
117341 break;
117342 case 311: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
117343 {
117344 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
117345 }
117346 break;
117347 case 312: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
117348 {
117349 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
117350 }
117351 break;
117352 case 313: /* add_column_fullname ::= fullname */
117353 {
117354 pParse->db->lookaside.bEnabled = 0;
117355 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
117356 }
117357 break;
117358 case 316: /* cmd ::= create_vtab */
117359 {sqlite3VtabFinishParse(pParse,0);}
117360 break;
117361 case 317: /* cmd ::= create_vtab LP vtabarglist RP */
117362 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
117363 break;
117364 case 318: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
117365 {
117366 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy4);
117367 }
117368 break;
117369 case 321: /* vtabarg ::= */
117370 {sqlite3VtabArgInit(pParse);}
117371 break;
117372 case 323: /* vtabargtoken ::= ANY */
117373 case 324: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==324);
117374 case 325: /* lp ::= LP */ yytestcase(yyruleno==325);
117375 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
117376 break;
117377 default:
117378 /* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
117379 /* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
@@ -116001,34 +117384,34 @@
117384 /* (11) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==11);
117385 /* (12) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==12);
117386 /* (20) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==20);
117387 /* (21) savepoint_opt ::= */ yytestcase(yyruleno==21);
117388 /* (25) cmd ::= create_table create_table_args */ yytestcase(yyruleno==25);
117389 /* (36) columnlist ::= columnlist COMMA column */ yytestcase(yyruleno==36);
117390 /* (37) columnlist ::= column */ yytestcase(yyruleno==37);
117391 /* (46) type ::= */ yytestcase(yyruleno==46);
117392 /* (53) signed ::= plus_num */ yytestcase(yyruleno==53);
117393 /* (54) signed ::= minus_num */ yytestcase(yyruleno==54);
117394 /* (55) carglist ::= carglist ccons */ yytestcase(yyruleno==55);
117395 /* (56) carglist ::= */ yytestcase(yyruleno==56);
117396 /* (63) ccons ::= NULL onconf */ yytestcase(yyruleno==63);
117397 /* (91) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==91);
117398 /* (92) conslist ::= tcons */ yytestcase(yyruleno==92);
117399 /* (94) tconscomma ::= */ yytestcase(yyruleno==94);
117400 /* (279) foreach_clause ::= */ yytestcase(yyruleno==279);
117401 /* (280) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==280);
117402 /* (287) tridxby ::= */ yytestcase(yyruleno==287);
117403 /* (305) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==305);
117404 /* (306) database_kw_opt ::= */ yytestcase(yyruleno==306);
117405 /* (314) kwcolumn_opt ::= */ yytestcase(yyruleno==314);
117406 /* (315) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==315);
117407 /* (319) vtabarglist ::= vtabarg */ yytestcase(yyruleno==319);
117408 /* (320) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==320);
117409 /* (322) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==322);
117410 /* (326) anylist ::= */ yytestcase(yyruleno==326);
117411 /* (327) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==327);
117412 /* (328) anylist ::= anylist ANY */ yytestcase(yyruleno==328);
117413 break;
117414 };
117415 assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
117416 yygoto = yyRuleInfo[yyruleno].lhs;
117417 yysize = yyRuleInfo[yyruleno].nrhs;
@@ -116363,24 +117746,24 @@
117746 ** might be implemented more directly using a hand-written hash table.
117747 ** But by using this automatically generated code, the size of the code
117748 ** is substantially reduced. This is important for embedded applications
117749 ** on platforms with limited memory.
117750 */
117751 /* Hash score: 177 */
117752 static int keywordCode(const char *z, int n){
117753 /* zText[] encodes 819 bytes of keywords in 545 bytes */
117754 /* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
117755 /* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
117756 /* XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY */
117757 /* UNIQUERYWITHOUTERELEASEATTACHAVINGROUPDATEBEGINNERENAMEBETWEEN */
117758 /* OTNULLIKECASCADELETECASECOLLATECREATECURRENT_DATEDETACH */
117759 /* IMMEDIATEJOINSERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHEN */
117760 /* WHEREPLACEAFTERESTRICTANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMIT */
117761 /* CONFLICTCROSSCURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAIL */
117762 /* FROMFULLGLOBYIFISNULLORDERIGHTROLLBACKROWUNIONUSINGVACUUMVIEW */
117763 /* INITIALLY */
117764 static const char zText[544] = {
117765 'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
117766 'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
117767 'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
117768 'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
117769 'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
@@ -116387,105 +117770,106 @@
117770 'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
117771 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
117772 'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
117773 'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
117774 'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
117775 'U','E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S',
117776 'E','A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A',
117777 'T','E','B','E','G','I','N','N','E','R','E','N','A','M','E','B','E','T',
117778 'W','E','E','N','O','T','N','U','L','L','I','K','E','C','A','S','C','A',
117779 'D','E','L','E','T','E','C','A','S','E','C','O','L','L','A','T','E','C',
117780 'R','E','A','T','E','C','U','R','R','E','N','T','_','D','A','T','E','D',
117781 'E','T','A','C','H','I','M','M','E','D','I','A','T','E','J','O','I','N',
117782 'S','E','R','T','M','A','T','C','H','P','L','A','N','A','L','Y','Z','E',
117783 'P','R','A','G','M','A','B','O','R','T','V','A','L','U','E','S','V','I',
117784 'R','T','U','A','L','I','M','I','T','W','H','E','N','W','H','E','R','E',
117785 'P','L','A','C','E','A','F','T','E','R','E','S','T','R','I','C','T','A',
117786 'N','D','E','F','A','U','L','T','A','U','T','O','I','N','C','R','E','M',
117787 'E','N','T','C','A','S','T','C','O','L','U','M','N','C','O','M','M','I',
117788 'T','C','O','N','F','L','I','C','T','C','R','O','S','S','C','U','R','R',
117789 'E','N','T','_','T','I','M','E','S','T','A','M','P','R','I','M','A','R',
117790 'Y','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T','D','R',
117791 'O','P','F','A','I','L','F','R','O','M','F','U','L','L','G','L','O','B',
117792 'Y','I','F','I','S','N','U','L','L','O','R','D','E','R','I','G','H','T',
117793 'R','O','L','L','B','A','C','K','R','O','W','U','N','I','O','N','U','S',
117794 'I','N','G','V','A','C','U','U','M','V','I','E','W','I','N','I','T','I',
117795 'A','L','L','Y',
117796 };
117797 static const unsigned char aHash[127] = {
117798 75, 104, 115, 73, 0, 45, 0, 0, 81, 0, 76, 0, 0,
117799 42, 12, 77, 15, 0, 114, 84, 53, 111, 0, 19, 0, 0,
117800 119, 0, 117, 88, 0, 22, 92, 0, 9, 0, 0, 69, 70,
117801 0, 68, 6, 0, 48, 89, 101, 0, 116, 100, 0, 0, 44,
117802 0, 102, 24, 0, 17, 0, 120, 52, 23, 0, 5, 109, 25,
117803 95, 0, 0, 122, 105, 59, 121, 56, 28, 54, 0, 90, 0,
117804 99, 26, 0, 98, 0, 0, 0, 94, 91, 96, 87, 108, 14,
117805 39, 107, 0, 80, 0, 18, 86, 110, 32, 0, 118, 79, 112,
117806 61, 46, 83, 0, 0, 93, 40, 0, 113, 0, 36, 0, 0,
117807 29, 0, 85, 62, 63, 0, 20, 60, 0, 55,
117808 };
117809 static const unsigned char aNext[122] = {
117810 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
117811 0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
117812 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117813 0, 0, 0, 0, 33, 0, 21, 0, 0, 0, 0, 0, 0,
117814 43, 3, 47, 0, 0, 0, 0, 30, 0, 57, 0, 38, 0,
117815 0, 0, 1, 65, 0, 0, 66, 0, 41, 0, 0, 0, 0,
117816 0, 0, 49, 64, 0, 0, 0, 51, 31, 0, 16, 34, 10,
117817 0, 0, 0, 0, 0, 0, 0, 11, 71, 78, 0, 8, 0,
117818 103, 97, 0, 106, 0, 58, 0, 74, 50, 27, 37, 72, 82,
117819 0, 35, 67, 0, 0,
117820 };
117821 static const unsigned char aLen[122] = {
117822 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
117823 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
117824 11, 6, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10,
117825 4, 6, 2, 3, 9, 4, 2, 6, 5, 7, 5, 7, 6,
117826 6, 5, 6, 5, 5, 6, 7, 7, 3, 2, 4, 4, 7,
117827 3, 6, 4, 7, 6, 12, 6, 9, 4, 6, 5, 4, 7,
117828 6, 5, 6, 7, 5, 4, 5, 7, 5, 8, 3, 7, 13,
117829 2, 2, 4, 6, 6, 8, 5, 17, 12, 7, 8, 8, 2,
117830 4, 4, 4, 4, 4, 2, 2, 6, 5, 5, 8, 3, 5,
117831 5, 6, 4, 9, 3,
117832 };
117833 static const unsigned short int aOffset[122] = {
117834 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
117835 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
117836 86, 91, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152,
117837 159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 188, 192, 199,
117838 204, 209, 212, 218, 221, 225, 231, 237, 237, 237, 240, 243, 247,
117839 248, 252, 258, 262, 269, 275, 287, 293, 302, 304, 310, 315, 317,
117840 324, 329, 334, 340, 346, 351, 355, 358, 365, 369, 377, 379, 386,
117841 388, 390, 399, 403, 409, 415, 423, 428, 428, 444, 451, 458, 459,
117842 466, 470, 474, 478, 482, 485, 487, 489, 495, 499, 504, 512, 515,
117843 520, 525, 531, 535, 540,
117844 };
117845 static const unsigned char aCode[122] = {
117846 TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
117847 TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
117848 TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
117849 TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
117850 TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
117851 TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
117852 TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT,
117853 TK_INTERSECT, TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO,
117854 TK_OFFSET, TK_OF, TK_SET, TK_TEMP, TK_TEMP,
117855 TK_OR, TK_UNIQUE, TK_QUERY, TK_WITHOUT, TK_JOIN_KW,
117856 TK_RELEASE, TK_ATTACH, TK_HAVING, TK_GROUP, TK_UPDATE,
117857 TK_BEGIN, TK_JOIN_KW, TK_RENAME, TK_BETWEEN, TK_NOTNULL,
117858 TK_NOT, TK_NO, TK_NULL, TK_LIKE_KW, TK_CASCADE,
117859 TK_ASC, TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE,
117860 TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT,
117861 TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT,
117862 TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_WHERE,
117863 TK_REPLACE, TK_AFTER, TK_RESTRICT, TK_AND, TK_DEFAULT,
117864 TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW,
117865 TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW,
117866 TK_PRIMARY, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP,
117867 TK_FAIL, TK_FROM, TK_JOIN_KW, TK_LIKE_KW, TK_BY,
117868 TK_IF, TK_ISNULL, TK_ORDER, TK_JOIN_KW, TK_ROLLBACK,
117869 TK_ROW, TK_UNION, TK_USING, TK_VACUUM, TK_VIEW,
117870 TK_INITIALLY, TK_ALL,
117871 };
117872 int h, i;
117873 if( n<2 ) return TK_ID;
117874 h = ((charMap(z[0])*4) ^
117875 (charMap(z[n-1])*3) ^
@@ -116538,92 +117922,93 @@
117922 testcase( i==43 ); /* TEMPORARY */
117923 testcase( i==44 ); /* TEMP */
117924 testcase( i==45 ); /* OR */
117925 testcase( i==46 ); /* UNIQUE */
117926 testcase( i==47 ); /* QUERY */
117927 testcase( i==48 ); /* WITHOUT */
117928 testcase( i==49 ); /* OUTER */
117929 testcase( i==50 ); /* RELEASE */
117930 testcase( i==51 ); /* ATTACH */
117931 testcase( i==52 ); /* HAVING */
117932 testcase( i==53 ); /* GROUP */
117933 testcase( i==54 ); /* UPDATE */
117934 testcase( i==55 ); /* BEGIN */
117935 testcase( i==56 ); /* INNER */
117936 testcase( i==57 ); /* RENAME */
117937 testcase( i==58 ); /* BETWEEN */
117938 testcase( i==59 ); /* NOTNULL */
117939 testcase( i==60 ); /* NOT */
117940 testcase( i==61 ); /* NO */
117941 testcase( i==62 ); /* NULL */
117942 testcase( i==63 ); /* LIKE */
117943 testcase( i==64 ); /* CASCADE */
117944 testcase( i==65 ); /* ASC */
117945 testcase( i==66 ); /* DELETE */
117946 testcase( i==67 ); /* CASE */
117947 testcase( i==68 ); /* COLLATE */
117948 testcase( i==69 ); /* CREATE */
117949 testcase( i==70 ); /* CURRENT_DATE */
117950 testcase( i==71 ); /* DETACH */
117951 testcase( i==72 ); /* IMMEDIATE */
117952 testcase( i==73 ); /* JOIN */
117953 testcase( i==74 ); /* INSERT */
117954 testcase( i==75 ); /* MATCH */
117955 testcase( i==76 ); /* PLAN */
117956 testcase( i==77 ); /* ANALYZE */
117957 testcase( i==78 ); /* PRAGMA */
117958 testcase( i==79 ); /* ABORT */
117959 testcase( i==80 ); /* VALUES */
117960 testcase( i==81 ); /* VIRTUAL */
117961 testcase( i==82 ); /* LIMIT */
117962 testcase( i==83 ); /* WHEN */
117963 testcase( i==84 ); /* WHERE */
117964 testcase( i==85 ); /* REPLACE */
117965 testcase( i==86 ); /* AFTER */
117966 testcase( i==87 ); /* RESTRICT */
117967 testcase( i==88 ); /* AND */
117968 testcase( i==89 ); /* DEFAULT */
117969 testcase( i==90 ); /* AUTOINCREMENT */
117970 testcase( i==91 ); /* TO */
117971 testcase( i==92 ); /* IN */
117972 testcase( i==93 ); /* CAST */
117973 testcase( i==94 ); /* COLUMN */
117974 testcase( i==95 ); /* COMMIT */
117975 testcase( i==96 ); /* CONFLICT */
117976 testcase( i==97 ); /* CROSS */
117977 testcase( i==98 ); /* CURRENT_TIMESTAMP */
117978 testcase( i==99 ); /* CURRENT_TIME */
117979 testcase( i==100 ); /* PRIMARY */
117980 testcase( i==101 ); /* DEFERRED */
117981 testcase( i==102 ); /* DISTINCT */
117982 testcase( i==103 ); /* IS */
117983 testcase( i==104 ); /* DROP */
117984 testcase( i==105 ); /* FAIL */
117985 testcase( i==106 ); /* FROM */
117986 testcase( i==107 ); /* FULL */
117987 testcase( i==108 ); /* GLOB */
117988 testcase( i==109 ); /* BY */
117989 testcase( i==110 ); /* IF */
117990 testcase( i==111 ); /* ISNULL */
117991 testcase( i==112 ); /* ORDER */
117992 testcase( i==113 ); /* RIGHT */
117993 testcase( i==114 ); /* ROLLBACK */
117994 testcase( i==115 ); /* ROW */
117995 testcase( i==116 ); /* UNION */
117996 testcase( i==117 ); /* USING */
117997 testcase( i==118 ); /* VACUUM */
117998 testcase( i==119 ); /* VIEW */
117999 testcase( i==120 ); /* INITIALLY */
118000 testcase( i==121 ); /* ALL */
118001 return aCode[i];
118002 }
118003 }
118004 return TK_ID;
118005 }
118006 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
118007 return keywordCode((char*)z, n);
118008 }
118009 #define SQLITE_N_KEYWORD 122
118010
118011 /************** End of keywordhash.h *****************************************/
118012 /************** Continuing where we left off in tokenize.c *******************/
118013
118014
@@ -117066,11 +118451,10 @@
118451 }
118452
118453 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
118454 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
118455 sqlite3DbFree(db, pParse->azVar);
 
118456 while( pParse->pAinc ){
118457 AutoincInfo *p = pParse->pAinc;
118458 pParse->pAinc = p->pNext;
118459 sqlite3DbFree(db, p);
118460 }
@@ -118594,10 +119978,11 @@
119978 case SQLITE_CONSTRAINT_COMMITHOOK:
119979 zName = "SQLITE_CONSTRAINT_COMMITHOOK"; break;
119980 case SQLITE_CONSTRAINT_VTAB: zName = "SQLITE_CONSTRAINT_VTAB"; break;
119981 case SQLITE_CONSTRAINT_FUNCTION:
119982 zName = "SQLITE_CONSTRAINT_FUNCTION"; break;
119983 case SQLITE_CONSTRAINT_ROWID: zName = "SQLITE_CONSTRAINT_ROWID"; break;
119984 case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
119985 case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
119986 case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
119987 case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
119988 case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
@@ -119408,10 +120793,36 @@
120793 ** function.
120794 */
120795 SQLITE_API const char *sqlite3_errstr(int rc){
120796 return sqlite3ErrStr(rc);
120797 }
120798
120799 /*
120800 ** Invalidate all cached KeyInfo objects for database connection "db"
120801 */
120802 static void invalidateCachedKeyInfo(sqlite3 *db){
120803 Db *pDb; /* A single database */
120804 int iDb; /* The database index number */
120805 HashElem *k; /* For looping over tables in pDb */
120806 Table *pTab; /* A table in the database */
120807 Index *pIdx; /* Each index */
120808
120809 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
120810 if( pDb->pBt==0 ) continue;
120811 sqlite3BtreeEnter(pDb->pBt);
120812 for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
120813 pTab = (Table*)sqliteHashData(k);
120814 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120815 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){
120816 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
120817 pIdx->pKeyInfo = 0;
120818 }
120819 }
120820 }
120821 sqlite3BtreeLeave(pDb->pBt);
120822 }
120823 }
120824
120825 /*
120826 ** Create a new collating function for database "db". The name is zName
120827 ** and the encoding is enc.
120828 */
@@ -119453,10 +120864,11 @@
120864 sqlite3Error(db, SQLITE_BUSY,
120865 "unable to delete/modify collation sequence due to active statements");
120866 return SQLITE_BUSY;
120867 }
120868 sqlite3ExpirePreparedStatements(db);
120869 invalidateCachedKeyInfo(db);
120870
120871 /* If collation sequence pColl was created directly by a call to
120872 ** sqlite3_create_collation, and not generated by synthCollSeq(),
120873 ** then any copies made by synthCollSeq() need to be invalidated.
120874 ** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128435,10 +129847,15 @@
129847 }
129848 *ppCsr = pCsr;
129849 return rc;
129850 }
129851
129852 /*
129853 ** Function getNextNode(), which is called by fts3ExprParse(), may itself
129854 ** call fts3ExprParse(). So this forward declaration is required.
129855 */
129856 static int fts3ExprParse(ParseContext *, const char *, int, Fts3Expr **, int *);
129857
129858 /*
129859 ** Extract the next token from buffer z (length n) using the tokenizer
129860 ** and other information (column names etc.) in pParse. Create an Fts3Expr
129861 ** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
@@ -128469,11 +129886,35 @@
129886 const char *zToken;
129887 int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
129888 int nByte; /* total space to allocate */
129889
129890 rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
129891
129892 if( (rc==SQLITE_OK || rc==SQLITE_DONE) && sqlite3_fts3_enable_parentheses ){
129893 int i;
129894 if( rc==SQLITE_DONE ) iStart = n;
129895 for(i=0; i<iStart; i++){
129896 if( z[i]=='(' ){
129897 pParse->nNest++;
129898 rc = fts3ExprParse(pParse, &z[i+1], n-i-1, &pRet, &nConsumed);
129899 if( rc==SQLITE_OK && !pRet ){
129900 rc = SQLITE_DONE;
129901 }
129902 nConsumed = (int)(i + 1 + nConsumed);
129903 break;
129904 }
129905
129906 if( z[i]==')' ){
129907 rc = SQLITE_DONE;
129908 pParse->nNest--;
129909 nConsumed = i+1;
129910 break;
129911 }
129912 }
129913 }
129914
129915 if( nConsumed==0 && rc==SQLITE_OK ){
129916 nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
129917 pRet = (Fts3Expr *)fts3MallocZero(nByte);
129918 if( !pRet ){
129919 rc = SQLITE_NOMEM;
129920 }else{
@@ -128649,16 +130090,10 @@
130090 sqlite3_free(p);
130091 *ppExpr = 0;
130092 return SQLITE_NOMEM;
130093 }
130094
 
 
 
 
 
 
130095 /*
130096 ** The output variable *ppExpr is populated with an allocated Fts3Expr
130097 ** structure, or set to 0 if the end of the input buffer is reached.
130098 **
130099 ** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM
@@ -128751,31 +130186,10 @@
130186 ** user has supplied a token such as "ORacle". Continue.
130187 */
130188 }
130189 }
130190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130191 /* See if we are dealing with a quoted phrase. If this is the case, then
130192 ** search for the closing quote and pass the whole string to getNextString()
130193 ** for processing. This is easy to do, as fts3 has no syntax for escaping
130194 ** a quote character embedded in a string.
130195 */
130196
+29 -12
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.8.1"
111
-#define SQLITE_VERSION_NUMBER 3008001
112
-#define SQLITE_SOURCE_ID "2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a"
110
+#define SQLITE_VERSION "3.8.2"
111
+#define SQLITE_VERSION_NUMBER 3008002
112
+#define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -499,10 +499,11 @@
499499
#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
500500
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
501501
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
502502
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
503503
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
504
+#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
504505
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
505506
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
506507
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
507508
508509
/*
@@ -910,10 +911,18 @@
910911
** pointer is overwritten with the old value. The limit is not changed if
911912
** the value originally pointed to is negative, and so the current limit
912913
** can be queried by passing in a pointer to a negative number. This
913914
** file-control is used internally to implement [PRAGMA mmap_size].
914915
**
916
+** <li>[[SQLITE_FCNTL_TRACE]]
917
+** The [SQLITE_FCNTL_TRACE] file control provides advisory information
918
+** to the VFS about what the higher layers of the SQLite stack are doing.
919
+** This file control is used by some VFS activity tracing [shims].
920
+** The argument is a zero-terminated string. Higher layers in the
921
+** SQLite stack may generate instances of this file control if
922
+** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
923
+**
915924
** </ul>
916925
*/
917926
#define SQLITE_FCNTL_LOCKSTATE 1
918927
#define SQLITE_GET_LOCKPROXYFILE 2
919928
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -929,10 +938,11 @@
929938
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
930939
#define SQLITE_FCNTL_PRAGMA 14
931940
#define SQLITE_FCNTL_BUSYHANDLER 15
932941
#define SQLITE_FCNTL_TEMPFILENAME 16
933942
#define SQLITE_FCNTL_MMAP_SIZE 18
943
+#define SQLITE_FCNTL_TRACE 19
934944
935945
/*
936946
** CAPI3REF: Mutex Handle
937947
**
938948
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1775,23 +1785,25 @@
17751785
SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
17761786
17771787
/*
17781788
** CAPI3REF: Last Insert Rowid
17791789
**
1780
-** ^Each entry in an SQLite table has a unique 64-bit signed
1790
+** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1791
+** has a unique 64-bit signed
17811792
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
17821793
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
17831794
** names are not also used by explicitly declared columns. ^If
17841795
** the table has a column of type [INTEGER PRIMARY KEY] then that column
17851796
** is another alias for the rowid.
17861797
**
1787
-** ^This routine returns the [rowid] of the most recent
1788
-** successful [INSERT] into the database from the [database connection]
1789
-** in the first argument. ^As of SQLite version 3.7.7, this routines
1790
-** records the last insert rowid of both ordinary tables and [virtual tables].
1791
-** ^If no successful [INSERT]s
1792
-** have ever occurred on that database connection, zero is returned.
1798
+** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
1799
+** most recent successful [INSERT] into a rowid table or [virtual table]
1800
+** on database connection D.
1801
+** ^Inserts into [WITHOUT ROWID] tables are not recorded.
1802
+** ^If no successful [INSERT]s into rowid tables
1803
+** have ever occurred on the database connection D,
1804
+** then sqlite3_last_insert_rowid(D) returns zero.
17931805
**
17941806
** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
17951807
** method, then this routine will return the [rowid] of the inserted
17961808
** row as long as the trigger or virtual table method is running.
17971809
** But once the trigger or virtual table method ends, the value returned
@@ -4804,16 +4816,17 @@
48044816
/*
48054817
** CAPI3REF: Data Change Notification Callbacks
48064818
**
48074819
** ^The sqlite3_update_hook() interface registers a callback function
48084820
** with the [database connection] identified by the first argument
4809
-** to be invoked whenever a row is updated, inserted or deleted.
4821
+** to be invoked whenever a row is updated, inserted or deleted in
4822
+** a rowid table.
48104823
** ^Any callback set by a previous call to this function
48114824
** for the same database connection is overridden.
48124825
**
48134826
** ^The second argument is a pointer to the function to invoke when a
4814
-** row is updated, inserted or deleted.
4827
+** row is updated, inserted or deleted in a rowid table.
48154828
** ^The first argument to the callback is a copy of the third argument
48164829
** to sqlite3_update_hook().
48174830
** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
48184831
** or [SQLITE_UPDATE], depending on the operation that caused the callback
48194832
** to be invoked.
@@ -4822,10 +4835,11 @@
48224835
** ^The final callback parameter is the [rowid] of the row.
48234836
** ^In the case of an update, this is the [rowid] after the update takes place.
48244837
**
48254838
** ^(The update hook is not invoked when internal system tables are
48264839
** modified (i.e. sqlite_master and sqlite_sequence).)^
4840
+** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
48274841
**
48284842
** ^In the current implementation, the update hook
48294843
** is not invoked when duplication rows are deleted because of an
48304844
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
48314845
** invoked when rows are deleted using the [truncate optimization].
@@ -5511,10 +5525,13 @@
55115525
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
55125526
** the opened blob. ^The size of a blob may not be changed by this
55135527
** interface. Use the [UPDATE] SQL command to change the size of a
55145528
** blob.
55155529
**
5530
+** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5531
+** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5532
+**
55165533
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
55175534
** and the built-in [zeroblob] SQL function can be used, if desired,
55185535
** to create an empty, zero-filled blob in which to read or write using
55195536
** this interface.
55205537
**
55215538
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.1"
111 #define SQLITE_VERSION_NUMBER 3008001
112 #define SQLITE_SOURCE_ID "2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -499,10 +499,11 @@
499 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
500 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
501 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
502 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
503 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
 
504 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
505 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
506 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
507
508 /*
@@ -910,10 +911,18 @@
910 ** pointer is overwritten with the old value. The limit is not changed if
911 ** the value originally pointed to is negative, and so the current limit
912 ** can be queried by passing in a pointer to a negative number. This
913 ** file-control is used internally to implement [PRAGMA mmap_size].
914 **
 
 
 
 
 
 
 
 
915 ** </ul>
916 */
917 #define SQLITE_FCNTL_LOCKSTATE 1
918 #define SQLITE_GET_LOCKPROXYFILE 2
919 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -929,10 +938,11 @@
929 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
930 #define SQLITE_FCNTL_PRAGMA 14
931 #define SQLITE_FCNTL_BUSYHANDLER 15
932 #define SQLITE_FCNTL_TEMPFILENAME 16
933 #define SQLITE_FCNTL_MMAP_SIZE 18
 
934
935 /*
936 ** CAPI3REF: Mutex Handle
937 **
938 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1775,23 +1785,25 @@
1775 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
1776
1777 /*
1778 ** CAPI3REF: Last Insert Rowid
1779 **
1780 ** ^Each entry in an SQLite table has a unique 64-bit signed
 
1781 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1782 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1783 ** names are not also used by explicitly declared columns. ^If
1784 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1785 ** is another alias for the rowid.
1786 **
1787 ** ^This routine returns the [rowid] of the most recent
1788 ** successful [INSERT] into the database from the [database connection]
1789 ** in the first argument. ^As of SQLite version 3.7.7, this routines
1790 ** records the last insert rowid of both ordinary tables and [virtual tables].
1791 ** ^If no successful [INSERT]s
1792 ** have ever occurred on that database connection, zero is returned.
 
1793 **
1794 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1795 ** method, then this routine will return the [rowid] of the inserted
1796 ** row as long as the trigger or virtual table method is running.
1797 ** But once the trigger or virtual table method ends, the value returned
@@ -4804,16 +4816,17 @@
4804 /*
4805 ** CAPI3REF: Data Change Notification Callbacks
4806 **
4807 ** ^The sqlite3_update_hook() interface registers a callback function
4808 ** with the [database connection] identified by the first argument
4809 ** to be invoked whenever a row is updated, inserted or deleted.
 
4810 ** ^Any callback set by a previous call to this function
4811 ** for the same database connection is overridden.
4812 **
4813 ** ^The second argument is a pointer to the function to invoke when a
4814 ** row is updated, inserted or deleted.
4815 ** ^The first argument to the callback is a copy of the third argument
4816 ** to sqlite3_update_hook().
4817 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
4818 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
4819 ** to be invoked.
@@ -4822,10 +4835,11 @@
4822 ** ^The final callback parameter is the [rowid] of the row.
4823 ** ^In the case of an update, this is the [rowid] after the update takes place.
4824 **
4825 ** ^(The update hook is not invoked when internal system tables are
4826 ** modified (i.e. sqlite_master and sqlite_sequence).)^
 
4827 **
4828 ** ^In the current implementation, the update hook
4829 ** is not invoked when duplication rows are deleted because of an
4830 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
4831 ** invoked when rows are deleted using the [truncate optimization].
@@ -5511,10 +5525,13 @@
5511 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5512 ** the opened blob. ^The size of a blob may not be changed by this
5513 ** interface. Use the [UPDATE] SQL command to change the size of a
5514 ** blob.
5515 **
 
 
 
5516 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5517 ** and the built-in [zeroblob] SQL function can be used, if desired,
5518 ** to create an empty, zero-filled blob in which to read or write using
5519 ** this interface.
5520 **
5521
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
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-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -499,10 +499,11 @@
499 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
500 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
501 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
502 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
503 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
504 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
505 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
506 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
507 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
508
509 /*
@@ -910,10 +911,18 @@
911 ** pointer is overwritten with the old value. The limit is not changed if
912 ** the value originally pointed to is negative, and so the current limit
913 ** can be queried by passing in a pointer to a negative number. This
914 ** file-control is used internally to implement [PRAGMA mmap_size].
915 **
916 ** <li>[[SQLITE_FCNTL_TRACE]]
917 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
918 ** to the VFS about what the higher layers of the SQLite stack are doing.
919 ** This file control is used by some VFS activity tracing [shims].
920 ** The argument is a zero-terminated string. Higher layers in the
921 ** SQLite stack may generate instances of this file control if
922 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
923 **
924 ** </ul>
925 */
926 #define SQLITE_FCNTL_LOCKSTATE 1
927 #define SQLITE_GET_LOCKPROXYFILE 2
928 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -929,10 +938,11 @@
938 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
939 #define SQLITE_FCNTL_PRAGMA 14
940 #define SQLITE_FCNTL_BUSYHANDLER 15
941 #define SQLITE_FCNTL_TEMPFILENAME 16
942 #define SQLITE_FCNTL_MMAP_SIZE 18
943 #define SQLITE_FCNTL_TRACE 19
944
945 /*
946 ** CAPI3REF: Mutex Handle
947 **
948 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1775,23 +1785,25 @@
1785 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
1786
1787 /*
1788 ** CAPI3REF: Last Insert Rowid
1789 **
1790 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1791 ** has a unique 64-bit signed
1792 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1793 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1794 ** names are not also used by explicitly declared columns. ^If
1795 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1796 ** is another alias for the rowid.
1797 **
1798 ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
1799 ** most recent successful [INSERT] into a rowid table or [virtual table]
1800 ** on database connection D.
1801 ** ^Inserts into [WITHOUT ROWID] tables are not recorded.
1802 ** ^If no successful [INSERT]s into rowid tables
1803 ** have ever occurred on the database connection D,
1804 ** then sqlite3_last_insert_rowid(D) returns zero.
1805 **
1806 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1807 ** method, then this routine will return the [rowid] of the inserted
1808 ** row as long as the trigger or virtual table method is running.
1809 ** But once the trigger or virtual table method ends, the value returned
@@ -4804,16 +4816,17 @@
4816 /*
4817 ** CAPI3REF: Data Change Notification Callbacks
4818 **
4819 ** ^The sqlite3_update_hook() interface registers a callback function
4820 ** with the [database connection] identified by the first argument
4821 ** to be invoked whenever a row is updated, inserted or deleted in
4822 ** a rowid table.
4823 ** ^Any callback set by a previous call to this function
4824 ** for the same database connection is overridden.
4825 **
4826 ** ^The second argument is a pointer to the function to invoke when a
4827 ** row is updated, inserted or deleted in a rowid table.
4828 ** ^The first argument to the callback is a copy of the third argument
4829 ** to sqlite3_update_hook().
4830 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
4831 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
4832 ** to be invoked.
@@ -4822,10 +4835,11 @@
4835 ** ^The final callback parameter is the [rowid] of the row.
4836 ** ^In the case of an update, this is the [rowid] after the update takes place.
4837 **
4838 ** ^(The update hook is not invoked when internal system tables are
4839 ** modified (i.e. sqlite_master and sqlite_sequence).)^
4840 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
4841 **
4842 ** ^In the current implementation, the update hook
4843 ** is not invoked when duplication rows are deleted because of an
4844 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
4845 ** invoked when rows are deleted using the [truncate optimization].
@@ -5511,10 +5525,13 @@
5525 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5526 ** the opened blob. ^The size of a blob may not be changed by this
5527 ** interface. Use the [UPDATE] SQL command to change the size of a
5528 ** blob.
5529 **
5530 ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5531 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5532 **
5533 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5534 ** and the built-in [zeroblob] SQL function can be used, if desired,
5535 ** to create an empty, zero-filled blob in which to read or write using
5536 ** this interface.
5537 **
5538
+3
--- src/stat.c
+++ src/stat.c
@@ -124,10 +124,13 @@
124124
@ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
125125
@ (%h(RELEASE_VERSION)) [compiled using %h(COMPILER_NAME)]
126126
@ </td></tr>
127127
@ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(SQLITE_SOURCE_ID)
128128
@ [%.10s(&SQLITE_SOURCE_ID[20])] (%s(SQLITE_VERSION))</td></tr>
129
+ @ <tr><th>Repository Rebuilt:</th><td>
130
+ @ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
131
+ @ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
129132
@ <tr><th>Database&nbsp;Stats:</th><td>
130133
zDb = db_name("repository");
131134
@ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages,
132135
@ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page,
133136
@ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages,
134137
--- src/stat.c
+++ src/stat.c
@@ -124,10 +124,13 @@
124 @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
125 @ (%h(RELEASE_VERSION)) [compiled using %h(COMPILER_NAME)]
126 @ </td></tr>
127 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(SQLITE_SOURCE_ID)
128 @ [%.10s(&SQLITE_SOURCE_ID[20])] (%s(SQLITE_VERSION))</td></tr>
 
 
 
129 @ <tr><th>Database&nbsp;Stats:</th><td>
130 zDb = db_name("repository");
131 @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages,
132 @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page,
133 @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages,
134
--- src/stat.c
+++ src/stat.c
@@ -124,10 +124,13 @@
124 @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
125 @ (%h(RELEASE_VERSION)) [compiled using %h(COMPILER_NAME)]
126 @ </td></tr>
127 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(SQLITE_SOURCE_ID)
128 @ [%.10s(&SQLITE_SOURCE_ID[20])] (%s(SQLITE_VERSION))</td></tr>
129 @ <tr><th>Repository Rebuilt:</th><td>
130 @ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
131 @ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
132 @ <tr><th>Database&nbsp;Stats:</th><td>
133 zDb = db_name("repository");
134 @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages,
135 @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page,
136 @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages,
137
+1 -1
--- src/style.c
+++ src/style.c
@@ -1226,7 +1226,7 @@
12261226
**
12271227
** WEBPAGE: honeypot
12281228
*/
12291229
void honeypot_page(void){
12301230
cgi_set_status(403, "Forbidden");
1231
- @ <p>Access by spiders and robots is forbidden</p>
1231
+ @ <p>Please enable javascript or log in to see this content</p>
12321232
}
12331233
--- src/style.c
+++ src/style.c
@@ -1226,7 +1226,7 @@
1226 **
1227 ** WEBPAGE: honeypot
1228 */
1229 void honeypot_page(void){
1230 cgi_set_status(403, "Forbidden");
1231 @ <p>Access by spiders and robots is forbidden</p>
1232 }
1233
--- src/style.c
+++ src/style.c
@@ -1226,7 +1226,7 @@
1226 **
1227 ** WEBPAGE: honeypot
1228 */
1229 void honeypot_page(void){
1230 cgi_set_status(403, "Forbidden");
1231 @ <p>Please enable javascript or log in to see this content</p>
1232 }
1233
+4 -1
--- src/sync.c
+++ src/sync.c
@@ -54,10 +54,11 @@
5454
if( g.urlUser!=0 && g.urlPasswd==0 ){
5555
g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
5656
g.urlFlags |= URL_PROMPT_PW;
5757
url_prompt_for_password();
5858
}
59
+ url_remember();
5960
#if 0 /* Disabled for now */
6061
if( (flags & AUTOSYNC_PULL)!=0 && db_get_boolean("auto-shun",1) ){
6162
/* When doing an automatic pull, also automatically pull shuns from
6263
** the server if pull_shuns is enabled.
6364
**
@@ -115,10 +116,11 @@
115116
}
116117
if( urlFlags & URL_REMEMBER ){
117118
clone_ssh_db_set_options();
118119
}
119120
url_parse(zUrl, urlFlags);
121
+ url_remember();
120122
if( g.urlProtocol==0 ){
121123
if( urlOptional ) fossil_exit(0);
122124
usage("URL");
123125
}
124126
user_select();
@@ -262,16 +264,17 @@
262264
}
263265
if( g.argc==3 ){
264266
db_unset("last-sync-url", 0);
265267
db_unset("last-sync-pw", 0);
266268
if( is_false(g.argv[2]) ) return;
267
- url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW);
269
+ url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW|URL_ASK_REMEMBER_PW);
268270
}
271
+ url_remember();
269272
zUrl = db_get("last-sync-url", 0);
270273
if( zUrl==0 ){
271274
fossil_print("off\n");
272275
return;
273276
}else{
274277
url_parse(zUrl, 0);
275278
fossil_print("%s\n", g.urlCanonical);
276279
}
277280
}
278281
--- src/sync.c
+++ src/sync.c
@@ -54,10 +54,11 @@
54 if( g.urlUser!=0 && g.urlPasswd==0 ){
55 g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
56 g.urlFlags |= URL_PROMPT_PW;
57 url_prompt_for_password();
58 }
 
59 #if 0 /* Disabled for now */
60 if( (flags & AUTOSYNC_PULL)!=0 && db_get_boolean("auto-shun",1) ){
61 /* When doing an automatic pull, also automatically pull shuns from
62 ** the server if pull_shuns is enabled.
63 **
@@ -115,10 +116,11 @@
115 }
116 if( urlFlags & URL_REMEMBER ){
117 clone_ssh_db_set_options();
118 }
119 url_parse(zUrl, urlFlags);
 
120 if( g.urlProtocol==0 ){
121 if( urlOptional ) fossil_exit(0);
122 usage("URL");
123 }
124 user_select();
@@ -262,16 +264,17 @@
262 }
263 if( g.argc==3 ){
264 db_unset("last-sync-url", 0);
265 db_unset("last-sync-pw", 0);
266 if( is_false(g.argv[2]) ) return;
267 url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW);
268 }
 
269 zUrl = db_get("last-sync-url", 0);
270 if( zUrl==0 ){
271 fossil_print("off\n");
272 return;
273 }else{
274 url_parse(zUrl, 0);
275 fossil_print("%s\n", g.urlCanonical);
276 }
277 }
278
--- src/sync.c
+++ src/sync.c
@@ -54,10 +54,11 @@
54 if( g.urlUser!=0 && g.urlPasswd==0 ){
55 g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
56 g.urlFlags |= URL_PROMPT_PW;
57 url_prompt_for_password();
58 }
59 url_remember();
60 #if 0 /* Disabled for now */
61 if( (flags & AUTOSYNC_PULL)!=0 && db_get_boolean("auto-shun",1) ){
62 /* When doing an automatic pull, also automatically pull shuns from
63 ** the server if pull_shuns is enabled.
64 **
@@ -115,10 +116,11 @@
116 }
117 if( urlFlags & URL_REMEMBER ){
118 clone_ssh_db_set_options();
119 }
120 url_parse(zUrl, urlFlags);
121 url_remember();
122 if( g.urlProtocol==0 ){
123 if( urlOptional ) fossil_exit(0);
124 usage("URL");
125 }
126 user_select();
@@ -262,16 +264,17 @@
264 }
265 if( g.argc==3 ){
266 db_unset("last-sync-url", 0);
267 db_unset("last-sync-pw", 0);
268 if( is_false(g.argv[2]) ) return;
269 url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW|URL_ASK_REMEMBER_PW);
270 }
271 url_remember();
272 zUrl = db_get("last-sync-url", 0);
273 if( zUrl==0 ){
274 fossil_print("off\n");
275 return;
276 }else{
277 url_parse(zUrl, 0);
278 fossil_print("%s\n", g.urlCanonical);
279 }
280 }
281
+3 -6
--- src/tag.c
+++ src/tag.c
@@ -389,11 +389,11 @@
389389
int n;
390390
int fRaw = find_option("raw","",0)!=0;
391391
int fPropagate = find_option("propagate","",0)!=0;
392392
const char *zPrefix = fRaw ? "" : "sym-";
393393
char const * zFindLimit = find_option("limit","n",1);
394
- int const nFindLimit = zFindLimit ? atoi(zFindLimit) : 0;
394
+ int const nFindLimit = zFindLimit ? atoi(zFindLimit) : -2000;
395395
396396
db_find_and_open_repository(0, 0);
397397
if( g.argc<3 ){
398398
goto tag_cmd_usage;
399399
}
@@ -444,11 +444,11 @@
444444
" WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
445445
" AND tagxref.tagtype>0"
446446
" AND blob.rid=tagxref.rid",
447447
g.argv[3]
448448
);
449
- if(nFindLimit>0){
449
+ if( nFindLimit>0 ){
450450
blob_appendf(&sql, " LIMIT %d", nFindLimit);
451451
}
452452
db_prepare(&q, "%s", blob_str(&sql));
453453
blob_reset(&sql);
454454
while( db_step(&q)==SQLITE_ROW ){
@@ -467,16 +467,13 @@
467467
" WHERE tagtype>0 AND tagid=%d"
468468
")"
469469
" ORDER BY event.mtime DESC",
470470
timeline_query_for_tty(), zType, tagid
471471
);
472
- if(nFindLimit>0){
473
- blob_appendf(&sql, " LIMIT %d", nFindLimit);
474
- }
475472
db_prepare(&q, "%s", blob_str(&sql));
476473
blob_reset(&sql);
477
- print_timeline(&q, 2000, 0);
474
+ print_timeline(&q, nFindLimit, 79, 0);
478475
db_finalize(&q);
479476
}
480477
}
481478
}else
482479
483480
--- src/tag.c
+++ src/tag.c
@@ -389,11 +389,11 @@
389 int n;
390 int fRaw = find_option("raw","",0)!=0;
391 int fPropagate = find_option("propagate","",0)!=0;
392 const char *zPrefix = fRaw ? "" : "sym-";
393 char const * zFindLimit = find_option("limit","n",1);
394 int const nFindLimit = zFindLimit ? atoi(zFindLimit) : 0;
395
396 db_find_and_open_repository(0, 0);
397 if( g.argc<3 ){
398 goto tag_cmd_usage;
399 }
@@ -444,11 +444,11 @@
444 " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
445 " AND tagxref.tagtype>0"
446 " AND blob.rid=tagxref.rid",
447 g.argv[3]
448 );
449 if(nFindLimit>0){
450 blob_appendf(&sql, " LIMIT %d", nFindLimit);
451 }
452 db_prepare(&q, "%s", blob_str(&sql));
453 blob_reset(&sql);
454 while( db_step(&q)==SQLITE_ROW ){
@@ -467,16 +467,13 @@
467 " WHERE tagtype>0 AND tagid=%d"
468 ")"
469 " ORDER BY event.mtime DESC",
470 timeline_query_for_tty(), zType, tagid
471 );
472 if(nFindLimit>0){
473 blob_appendf(&sql, " LIMIT %d", nFindLimit);
474 }
475 db_prepare(&q, "%s", blob_str(&sql));
476 blob_reset(&sql);
477 print_timeline(&q, 2000, 0);
478 db_finalize(&q);
479 }
480 }
481 }else
482
483
--- src/tag.c
+++ src/tag.c
@@ -389,11 +389,11 @@
389 int n;
390 int fRaw = find_option("raw","",0)!=0;
391 int fPropagate = find_option("propagate","",0)!=0;
392 const char *zPrefix = fRaw ? "" : "sym-";
393 char const * zFindLimit = find_option("limit","n",1);
394 int const nFindLimit = zFindLimit ? atoi(zFindLimit) : -2000;
395
396 db_find_and_open_repository(0, 0);
397 if( g.argc<3 ){
398 goto tag_cmd_usage;
399 }
@@ -444,11 +444,11 @@
444 " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
445 " AND tagxref.tagtype>0"
446 " AND blob.rid=tagxref.rid",
447 g.argv[3]
448 );
449 if( nFindLimit>0 ){
450 blob_appendf(&sql, " LIMIT %d", nFindLimit);
451 }
452 db_prepare(&q, "%s", blob_str(&sql));
453 blob_reset(&sql);
454 while( db_step(&q)==SQLITE_ROW ){
@@ -467,16 +467,13 @@
467 " WHERE tagtype>0 AND tagid=%d"
468 ")"
469 " ORDER BY event.mtime DESC",
470 timeline_query_for_tty(), zType, tagid
471 );
 
 
 
472 db_prepare(&q, "%s", blob_str(&sql));
473 blob_reset(&sql);
474 print_timeline(&q, nFindLimit, 79, 0);
475 db_finalize(&q);
476 }
477 }
478 }else
479
480
+1 -2
--- src/th_main.c
+++ src/th_main.c
@@ -529,16 +529,15 @@
529529
void *p,
530530
int argc,
531531
const char **argv,
532532
int *argl
533533
){
534
- int openRepository;
535
-
536534
if( argc!=1 && argc!=2 ){
537535
return Th_WrongNumArgs(interp, "repository ?BOOLEAN?");
538536
}
539537
if( argc==2 ){
538
+ int openRepository = 0;
540539
if( Th_ToInt(interp, argv[1], argl[1], &openRepository) ){
541540
return TH_ERROR;
542541
}
543542
if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
544543
}
545544
--- src/th_main.c
+++ src/th_main.c
@@ -529,16 +529,15 @@
529 void *p,
530 int argc,
531 const char **argv,
532 int *argl
533 ){
534 int openRepository;
535
536 if( argc!=1 && argc!=2 ){
537 return Th_WrongNumArgs(interp, "repository ?BOOLEAN?");
538 }
539 if( argc==2 ){
 
540 if( Th_ToInt(interp, argv[1], argl[1], &openRepository) ){
541 return TH_ERROR;
542 }
543 if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
544 }
545
--- src/th_main.c
+++ src/th_main.c
@@ -529,16 +529,15 @@
529 void *p,
530 int argc,
531 const char **argv,
532 int *argl
533 ){
 
 
534 if( argc!=1 && argc!=2 ){
535 return Th_WrongNumArgs(interp, "repository ?BOOLEAN?");
536 }
537 if( argc==2 ){
538 int openRepository = 0;
539 if( Th_ToInt(interp, argv[1], argl[1], &openRepository) ){
540 return TH_ERROR;
541 }
542 if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
543 }
544
+19 -19
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -30,24 +30,24 @@
3030
** arguments from TH1 to Tcl.
3131
*/
3232
#define USE_ARGV_TO_OBJV() \
3333
int objc; \
3434
Tcl_Obj **objv; \
35
- int i;
35
+ int obji;
3636
3737
#define COPY_ARGV_TO_OBJV() \
3838
objc = argc-1; \
3939
objv = (Tcl_Obj **)ckalloc((unsigned)(objc * sizeof(Tcl_Obj *))); \
40
- for(i=1; i<argc; i++){ \
41
- objv[i-1] = Tcl_NewStringObj(argv[i], argl[i]); \
42
- Tcl_IncrRefCount(objv[i-1]); \
40
+ for(obji=1; obji<argc; obji++){ \
41
+ objv[obji-1] = Tcl_NewStringObj(argv[obji], argl[obji]); \
42
+ Tcl_IncrRefCount(objv[obji-1]); \
4343
}
4444
45
-#define FREE_ARGV_TO_OBJV() \
46
- for(i=1; i<argc; i++){ \
47
- Tcl_DecrRefCount(objv[i-1]); \
48
- } \
45
+#define FREE_ARGV_TO_OBJV() \
46
+ for(obji=1; obji<argc; obji++){ \
47
+ Tcl_DecrRefCount(objv[obji-1]); \
48
+ } \
4949
ckfree((char *)objv);
5050
5151
/*
5252
** Fetch the Tcl interpreter from the specified void pointer, cast to a Tcl
5353
** context.
@@ -109,20 +109,20 @@
109109
# define TCL_MINOR_OFFSET (8)
110110
# endif
111111
# endif /* defined(__CYGWIN__) */
112112
# endif /* defined(_WIN32) */
113113
# ifndef TCL_FINDEXECUTABLE_NAME
114
-# define TCL_FINDEXECUTABLE_NAME "_Tcl_FindExecutable"
114
+# define TCL_FINDEXECUTABLE_NAME "_Tcl_FindExecutable\0"
115115
# endif
116116
# ifndef TCL_CREATEINTERP_NAME
117
-# define TCL_CREATEINTERP_NAME "_Tcl_CreateInterp"
117
+# define TCL_CREATEINTERP_NAME "_Tcl_CreateInterp\0"
118118
# endif
119119
# ifndef TCL_DELETEINTERP_NAME
120
-# define TCL_DELETEINTERP_NAME "_Tcl_DeleteInterp"
120
+# define TCL_DELETEINTERP_NAME "_Tcl_DeleteInterp\0"
121121
# endif
122122
# ifndef TCL_FINALIZE_NAME
123
-# define TCL_FINALIZE_NAME "_Tcl_Finalize"
123
+# define TCL_FINALIZE_NAME "_Tcl_Finalize\0"
124124
# endif
125125
#endif /* defined(USE_TCL_STUBS) */
126126
127127
/*
128128
** The function types for Tcl_FindExecutable and Tcl_CreateInterp are needed
@@ -311,17 +311,17 @@
311311
int rc
312312
){
313313
struct TclContext *tclContext = (struct TclContext *)ctx;
314314
tcl_NotifyProc *xNotifyProc;
315315
316
- if ( !tclContext ){
316
+ if( !tclContext ){
317317
Th_ErrorMessage(interp,
318318
"invalid Tcl context", (const char *)"", 0);
319319
return TH_ERROR;
320320
}
321321
xNotifyProc = bIsPost ? tclContext->xPostEval : tclContext->xPreEval;
322
- if ( xNotifyProc ){
322
+ if( xNotifyProc ){
323323
rc = xNotifyProc(bIsPost ?
324324
tclContext->pPostContext : tclContext->pPreContext,
325325
interp, ctx, argc, argv, argl, rc);
326326
}
327327
return rc;
@@ -783,16 +783,16 @@
783783
char **argv;
784784
char *argv0 = 0;
785785
Tcl_Interp *tclInterp;
786786
char *setup;
787787
788
- if ( !tclContext ){
788
+ if( !tclContext ){
789789
Th_ErrorMessage(interp,
790790
"invalid Tcl context", (const char *)"", 0);
791791
return TH_ERROR;
792792
}
793
- if ( tclContext->interp ){
793
+ if( tclContext->interp ){
794794
return TH_OK;
795795
}
796796
if( loadTcl(interp, &tclContext->library, &tclContext->xFindExecutable,
797797
&tclContext->xCreateInterp, &tclContext->xDeleteInterp,
798798
&tclContext->xFinalize)!=TH_OK ){
@@ -882,11 +882,11 @@
882882
tcl_FinalizeProc *xFinalize;
883883
#if defined(USE_TCL_STUBS)
884884
void *library;
885885
#endif /* defined(USE_TCL_STUBS) */
886886
887
- if ( !tclContext ){
887
+ if( !tclContext ){
888888
Th_ErrorMessage(interp,
889889
"invalid Tcl context", (const char *)"", 0);
890890
return TH_ERROR;
891891
}
892892
/*
@@ -897,11 +897,11 @@
897897
xFinalize = tclContext->xFinalize;
898898
/*
899899
** If the Tcl interpreter has been created, formally delete it now.
900900
*/
901901
tclInterp = tclContext->interp;
902
- if ( tclInterp ){
902
+ if( tclInterp ){
903903
Tcl_DeleteInterp(tclInterp);
904904
tclContext->interp = tclInterp = 0;
905905
}
906906
/*
907907
** If the Tcl library is not finalized prior to unloading it, a deadlock
@@ -939,15 +939,15 @@
939939
int i;
940940
941941
/* Add the Tcl integration commands to TH1. */
942942
for(i=0; i<(sizeof(aCommand)/sizeof(aCommand[0])); i++){
943943
void *ctx;
944
- if ( !aCommand[i].zName || !aCommand[i].xProc ) continue;
944
+ if( !aCommand[i].zName || !aCommand[i].xProc ) continue;
945945
ctx = aCommand[i].pContext;
946946
/* Use Tcl interpreter for context? */
947947
if( !ctx ) ctx = pContext;
948948
Th_CreateCommand(interp, aCommand[i].zName, aCommand[i].xProc, ctx, 0);
949949
}
950950
return TH_OK;
951951
}
952952
953953
#endif /* FOSSIL_ENABLE_TCL */
954954
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -30,24 +30,24 @@
30 ** arguments from TH1 to Tcl.
31 */
32 #define USE_ARGV_TO_OBJV() \
33 int objc; \
34 Tcl_Obj **objv; \
35 int i;
36
37 #define COPY_ARGV_TO_OBJV() \
38 objc = argc-1; \
39 objv = (Tcl_Obj **)ckalloc((unsigned)(objc * sizeof(Tcl_Obj *))); \
40 for(i=1; i<argc; i++){ \
41 objv[i-1] = Tcl_NewStringObj(argv[i], argl[i]); \
42 Tcl_IncrRefCount(objv[i-1]); \
43 }
44
45 #define FREE_ARGV_TO_OBJV() \
46 for(i=1; i<argc; i++){ \
47 Tcl_DecrRefCount(objv[i-1]); \
48 } \
49 ckfree((char *)objv);
50
51 /*
52 ** Fetch the Tcl interpreter from the specified void pointer, cast to a Tcl
53 ** context.
@@ -109,20 +109,20 @@
109 # define TCL_MINOR_OFFSET (8)
110 # endif
111 # endif /* defined(__CYGWIN__) */
112 # endif /* defined(_WIN32) */
113 # ifndef TCL_FINDEXECUTABLE_NAME
114 # define TCL_FINDEXECUTABLE_NAME "_Tcl_FindExecutable"
115 # endif
116 # ifndef TCL_CREATEINTERP_NAME
117 # define TCL_CREATEINTERP_NAME "_Tcl_CreateInterp"
118 # endif
119 # ifndef TCL_DELETEINTERP_NAME
120 # define TCL_DELETEINTERP_NAME "_Tcl_DeleteInterp"
121 # endif
122 # ifndef TCL_FINALIZE_NAME
123 # define TCL_FINALIZE_NAME "_Tcl_Finalize"
124 # endif
125 #endif /* defined(USE_TCL_STUBS) */
126
127 /*
128 ** The function types for Tcl_FindExecutable and Tcl_CreateInterp are needed
@@ -311,17 +311,17 @@
311 int rc
312 ){
313 struct TclContext *tclContext = (struct TclContext *)ctx;
314 tcl_NotifyProc *xNotifyProc;
315
316 if ( !tclContext ){
317 Th_ErrorMessage(interp,
318 "invalid Tcl context", (const char *)"", 0);
319 return TH_ERROR;
320 }
321 xNotifyProc = bIsPost ? tclContext->xPostEval : tclContext->xPreEval;
322 if ( xNotifyProc ){
323 rc = xNotifyProc(bIsPost ?
324 tclContext->pPostContext : tclContext->pPreContext,
325 interp, ctx, argc, argv, argl, rc);
326 }
327 return rc;
@@ -783,16 +783,16 @@
783 char **argv;
784 char *argv0 = 0;
785 Tcl_Interp *tclInterp;
786 char *setup;
787
788 if ( !tclContext ){
789 Th_ErrorMessage(interp,
790 "invalid Tcl context", (const char *)"", 0);
791 return TH_ERROR;
792 }
793 if ( tclContext->interp ){
794 return TH_OK;
795 }
796 if( loadTcl(interp, &tclContext->library, &tclContext->xFindExecutable,
797 &tclContext->xCreateInterp, &tclContext->xDeleteInterp,
798 &tclContext->xFinalize)!=TH_OK ){
@@ -882,11 +882,11 @@
882 tcl_FinalizeProc *xFinalize;
883 #if defined(USE_TCL_STUBS)
884 void *library;
885 #endif /* defined(USE_TCL_STUBS) */
886
887 if ( !tclContext ){
888 Th_ErrorMessage(interp,
889 "invalid Tcl context", (const char *)"", 0);
890 return TH_ERROR;
891 }
892 /*
@@ -897,11 +897,11 @@
897 xFinalize = tclContext->xFinalize;
898 /*
899 ** If the Tcl interpreter has been created, formally delete it now.
900 */
901 tclInterp = tclContext->interp;
902 if ( tclInterp ){
903 Tcl_DeleteInterp(tclInterp);
904 tclContext->interp = tclInterp = 0;
905 }
906 /*
907 ** If the Tcl library is not finalized prior to unloading it, a deadlock
@@ -939,15 +939,15 @@
939 int i;
940
941 /* Add the Tcl integration commands to TH1. */
942 for(i=0; i<(sizeof(aCommand)/sizeof(aCommand[0])); i++){
943 void *ctx;
944 if ( !aCommand[i].zName || !aCommand[i].xProc ) continue;
945 ctx = aCommand[i].pContext;
946 /* Use Tcl interpreter for context? */
947 if( !ctx ) ctx = pContext;
948 Th_CreateCommand(interp, aCommand[i].zName, aCommand[i].xProc, ctx, 0);
949 }
950 return TH_OK;
951 }
952
953 #endif /* FOSSIL_ENABLE_TCL */
954
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -30,24 +30,24 @@
30 ** arguments from TH1 to Tcl.
31 */
32 #define USE_ARGV_TO_OBJV() \
33 int objc; \
34 Tcl_Obj **objv; \
35 int obji;
36
37 #define COPY_ARGV_TO_OBJV() \
38 objc = argc-1; \
39 objv = (Tcl_Obj **)ckalloc((unsigned)(objc * sizeof(Tcl_Obj *))); \
40 for(obji=1; obji<argc; obji++){ \
41 objv[obji-1] = Tcl_NewStringObj(argv[obji], argl[obji]); \
42 Tcl_IncrRefCount(objv[obji-1]); \
43 }
44
45 #define FREE_ARGV_TO_OBJV() \
46 for(obji=1; obji<argc; obji++){ \
47 Tcl_DecrRefCount(objv[obji-1]); \
48 } \
49 ckfree((char *)objv);
50
51 /*
52 ** Fetch the Tcl interpreter from the specified void pointer, cast to a Tcl
53 ** context.
@@ -109,20 +109,20 @@
109 # define TCL_MINOR_OFFSET (8)
110 # endif
111 # endif /* defined(__CYGWIN__) */
112 # endif /* defined(_WIN32) */
113 # ifndef TCL_FINDEXECUTABLE_NAME
114 # define TCL_FINDEXECUTABLE_NAME "_Tcl_FindExecutable\0"
115 # endif
116 # ifndef TCL_CREATEINTERP_NAME
117 # define TCL_CREATEINTERP_NAME "_Tcl_CreateInterp\0"
118 # endif
119 # ifndef TCL_DELETEINTERP_NAME
120 # define TCL_DELETEINTERP_NAME "_Tcl_DeleteInterp\0"
121 # endif
122 # ifndef TCL_FINALIZE_NAME
123 # define TCL_FINALIZE_NAME "_Tcl_Finalize\0"
124 # endif
125 #endif /* defined(USE_TCL_STUBS) */
126
127 /*
128 ** The function types for Tcl_FindExecutable and Tcl_CreateInterp are needed
@@ -311,17 +311,17 @@
311 int rc
312 ){
313 struct TclContext *tclContext = (struct TclContext *)ctx;
314 tcl_NotifyProc *xNotifyProc;
315
316 if( !tclContext ){
317 Th_ErrorMessage(interp,
318 "invalid Tcl context", (const char *)"", 0);
319 return TH_ERROR;
320 }
321 xNotifyProc = bIsPost ? tclContext->xPostEval : tclContext->xPreEval;
322 if( xNotifyProc ){
323 rc = xNotifyProc(bIsPost ?
324 tclContext->pPostContext : tclContext->pPreContext,
325 interp, ctx, argc, argv, argl, rc);
326 }
327 return rc;
@@ -783,16 +783,16 @@
783 char **argv;
784 char *argv0 = 0;
785 Tcl_Interp *tclInterp;
786 char *setup;
787
788 if( !tclContext ){
789 Th_ErrorMessage(interp,
790 "invalid Tcl context", (const char *)"", 0);
791 return TH_ERROR;
792 }
793 if( tclContext->interp ){
794 return TH_OK;
795 }
796 if( loadTcl(interp, &tclContext->library, &tclContext->xFindExecutable,
797 &tclContext->xCreateInterp, &tclContext->xDeleteInterp,
798 &tclContext->xFinalize)!=TH_OK ){
@@ -882,11 +882,11 @@
882 tcl_FinalizeProc *xFinalize;
883 #if defined(USE_TCL_STUBS)
884 void *library;
885 #endif /* defined(USE_TCL_STUBS) */
886
887 if( !tclContext ){
888 Th_ErrorMessage(interp,
889 "invalid Tcl context", (const char *)"", 0);
890 return TH_ERROR;
891 }
892 /*
@@ -897,11 +897,11 @@
897 xFinalize = tclContext->xFinalize;
898 /*
899 ** If the Tcl interpreter has been created, formally delete it now.
900 */
901 tclInterp = tclContext->interp;
902 if( tclInterp ){
903 Tcl_DeleteInterp(tclInterp);
904 tclContext->interp = tclInterp = 0;
905 }
906 /*
907 ** If the Tcl library is not finalized prior to unloading it, a deadlock
@@ -939,15 +939,15 @@
939 int i;
940
941 /* Add the Tcl integration commands to TH1. */
942 for(i=0; i<(sizeof(aCommand)/sizeof(aCommand[0])); i++){
943 void *ctx;
944 if( !aCommand[i].zName || !aCommand[i].xProc ) continue;
945 ctx = aCommand[i].pContext;
946 /* Use Tcl interpreter for context? */
947 if( !ctx ) ctx = pContext;
948 Th_CreateCommand(interp, aCommand[i].zName, aCommand[i].xProc, ctx, 0);
949 }
950 return TH_OK;
951 }
952
953 #endif /* FOSSIL_ENABLE_TCL */
954
+51 -14
--- src/timeline.c
+++ src/timeline.c
@@ -1494,14 +1494,17 @@
14941494
14951495
/*
14961496
** The input query q selects various records. Print a human-readable
14971497
** summary of those records.
14981498
**
1499
-** Limit the number of lines printed to mxLine. If mxLine is zero or
1500
-** negative there is no limit. The line limit is approximate because
1501
-** it is only checked on a per-entry basis. In verbose mode, the file
1502
-** name details are considered to be part of the entry.
1499
+** Limit number of lines or entries printed to nLimit. If nLimit is zero
1500
+** there is no limit. If nLimit is greater than zero, limit the number of
1501
+** complete entries printed. If nLimit is less than zero, attempt to limit
1502
+** the number of lines printed (this is basically the legacy behavior).
1503
+** The line limit, if used, is approximate because it is only checked on a
1504
+** per-entry basis. If verbose mode, the file name details are considered
1505
+** to be part of the entry.
15031506
**
15041507
** The query should return these columns:
15051508
**
15061509
** 0. rid
15071510
** 1. uuid
@@ -1510,24 +1513,26 @@
15101513
** 4. Number of non-merge children
15111514
** 5. Number of parents
15121515
** 6. mtime
15131516
** 7. branch
15141517
*/
1515
-void print_timeline(Stmt *q, int mxLine, int verboseFlag){
1518
+void print_timeline(Stmt *q, int nLimit, int width, int verboseFlag){
1519
+ int nAbsLimit = (nLimit >= 0) ? nLimit : -nLimit;
15161520
int nLine = 0;
1521
+ int nEntry = 0;
15171522
char zPrevDate[20];
1518
- const char *zCurrentUuid=0;
1523
+ const char *zCurrentUuid = 0;
15191524
int fchngQueryInit = 0; /* True if fchngQuery is initialized */
15201525
Stmt fchngQuery; /* Query for file changes on check-ins */
1521
- zPrevDate[0] = 0;
15221526
1527
+ zPrevDate[0] = 0;
15231528
if( g.localOpen ){
15241529
int rid = db_lget_int("checkout", 0);
15251530
zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
15261531
}
15271532
1528
- while( db_step(q)==SQLITE_ROW && (mxLine<=0 || nLine<=mxLine) ){
1533
+ while( db_step(q)==SQLITE_ROW ){
15291534
int rid = db_column_int(q, 0);
15301535
const char *zId = db_column_text(q, 1);
15311536
const char *zDate = db_column_text(q, 2);
15321537
const char *zCom = db_column_text(q, 3);
15331538
int nChild = db_column_int(q, 4);
@@ -1535,10 +1540,19 @@
15351540
char *zFree = 0;
15361541
int n = 0;
15371542
char zPrefix[80];
15381543
char zUuid[UUID_SIZE+1];
15391544
1545
+ if( nAbsLimit!=0 ){
1546
+ if( nLimit<0 && nLine>=nAbsLimit ){
1547
+ fossil_print("--- line limit (%d) reached ---\n", nAbsLimit);
1548
+ break; /* line count limit hit, stop. */
1549
+ }else if( nEntry>=nAbsLimit ){
1550
+ fossil_print("--- entry limit (%d) reached ---\n", nAbsLimit);
1551
+ break; /* entry count limit hit, stop. */
1552
+ }
1553
+ }
15401554
sqlite3_snprintf(sizeof(zUuid), zUuid, "%.10s", zId);
15411555
if( memcmp(zDate, zPrevDate, 10) ){
15421556
fossil_print("=== %.10s ===\n", zDate);
15431557
memcpy(zPrevDate, zDate, 10);
15441558
nLine++; /* record another line */
@@ -1563,11 +1577,11 @@
15631577
if( fossil_strcmp(zCurrentUuid,zId)==0 ){
15641578
sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
15651579
n += strlen(zPrefix);
15661580
}
15671581
zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1568
- nLine += comment_print(zFree, 9, 79); /* record another X lines */
1582
+ nLine += comment_print(zFree, 9, width); /* record another X lines */
15691583
sqlite3_free(zFree);
15701584
15711585
if(verboseFlag){
15721586
if( !fchngQueryInit ){
15731587
db_prepare(&fchngQuery,
@@ -1596,10 +1610,11 @@
15961610
}
15971611
nLine++; /* record another line */
15981612
}
15991613
db_reset(&fchngQuery);
16001614
}
1615
+ nEntry++; /* record another complete entry */
16011616
}
16021617
if( fchngQueryInit ) db_finalize(&fchngQuery);
16031618
}
16041619
16051620
/*
@@ -1666,47 +1681,66 @@
16661681
** The DATETIME should be in the ISO8601 format. For
16671682
** examples: "2007-08-18 07:21:21". You can also say "current"
16681683
** for the current version or "now" for the current time.
16691684
**
16701685
** Options:
1671
-** -n|--limit N Output the first N changes (default 20)
1686
+** -n|--limit N Output the first N entries (default 20 lines).
1687
+** N=0 means no limit.
1688
+** --offset P skip P changes
16721689
** -t|--type TYPE Output items from the given types only, such as:
16731690
** ci = file commits only
16741691
** e = events only
16751692
** t = tickets only
16761693
** w = wiki commits only
16771694
** -v|--verbose Output the list of files changed by each commit
16781695
** and the type of each change (edited, deleted,
16791696
** etc.) after the checkin comment.
1697
+** -W|--width <num> With of lines (default 79). Must be >20 or 0
1698
+** (= no limit, resulting in a single line per entry).
16801699
*/
16811700
void timeline_cmd(void){
16821701
Stmt q;
1683
- int n, k;
1702
+ int n, k, width;
16841703
const char *zLimit;
1704
+ const char *zWidth;
1705
+ const char *zOffset;
16851706
const char *zType;
16861707
char *zOrigin;
16871708
char *zDate;
16881709
Blob sql;
16891710
int objid = 0;
16901711
Blob uuid;
16911712
int mode = 0 ; /* 0:none 1: before 2:after 3:children 4:parents */
16921713
int verboseFlag = 0 ;
1714
+ int iOffset;
1715
+
16931716
verboseFlag = find_option("verbose","v", 0)!=0;
16941717
if( !verboseFlag){
16951718
verboseFlag = find_option("showfiles","f", 0)!=0; /* deprecated */
16961719
}
16971720
db_find_and_open_repository(0, 0);
16981721
zLimit = find_option("limit","n",1);
1722
+ zWidth = find_option("width","W",1);
16991723
zType = find_option("type","t",1);
17001724
if ( !zLimit ){
17011725
zLimit = find_option("count",0,1);
17021726
}
17031727
if( zLimit ){
17041728
n = atoi(zLimit);
17051729
}else{
1706
- n = 20;
1730
+ n = -20;
1731
+ }
1732
+ if( zWidth ){
1733
+ width = atoi(zWidth);
1734
+ if( (width!=0) && (width<=20) ){
1735
+ fossil_fatal("--width|-W value must be >20 or 0");
1736
+ }
1737
+ }else{
1738
+ width = 79;
17071739
}
1740
+ zOffset = find_option("offset",0,1);
1741
+ iOffset = zOffset ? atoi(zOffset) : 0;
17081742
if( g.argc>=4 ){
17091743
k = strlen(g.argv[2]);
17101744
if( strncmp(g.argv[2],"before",k)==0 ){
17111745
mode = 1;
17121746
}else if( strncmp(g.argv[2],"after",k)==0 && k>1 ){
@@ -1718,11 +1752,11 @@
17181752
}else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
17191753
mode = 4;
17201754
}else if( strncmp(g.argv[2],"parents",k)==0 ){
17211755
mode = 4;
17221756
}else if(!zType && !zLimit){
1723
- usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit N? ?-t|--type TYPE?");
1757
+ usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit #? ?-t|--type TYPE? ?-W|--width WIDTH?");
17241758
}
17251759
if( '-' != *g.argv[3] ){
17261760
zOrigin = g.argv[3];
17271761
}else{
17281762
zOrigin = "now";
@@ -1778,13 +1812,16 @@
17781812
}
17791813
if( zType && (zType[0]!='a') ){
17801814
blob_appendf(&sql, " AND event.type=%Q ", zType);
17811815
}
17821816
blob_appendf(&sql, " ORDER BY event.mtime DESC");
1817
+ if( iOffset>0 ){
1818
+ blob_appendf(&sql, " LIMIT %d OFFSET %d", n>0?n+1:99999, iOffset);
1819
+ }
17831820
db_prepare(&q, blob_str(&sql));
17841821
blob_reset(&sql);
1785
- print_timeline(&q, n, verboseFlag);
1822
+ print_timeline(&q, n, width, verboseFlag);
17861823
db_finalize(&q);
17871824
}
17881825
17891826
/*
17901827
** This is a version of the "localtime()" function from the standard
17911828
--- src/timeline.c
+++ src/timeline.c
@@ -1494,14 +1494,17 @@
1494
1495 /*
1496 ** The input query q selects various records. Print a human-readable
1497 ** summary of those records.
1498 **
1499 ** Limit the number of lines printed to mxLine. If mxLine is zero or
1500 ** negative there is no limit. The line limit is approximate because
1501 ** it is only checked on a per-entry basis. In verbose mode, the file
1502 ** name details are considered to be part of the entry.
 
 
 
1503 **
1504 ** The query should return these columns:
1505 **
1506 ** 0. rid
1507 ** 1. uuid
@@ -1510,24 +1513,26 @@
1510 ** 4. Number of non-merge children
1511 ** 5. Number of parents
1512 ** 6. mtime
1513 ** 7. branch
1514 */
1515 void print_timeline(Stmt *q, int mxLine, int verboseFlag){
 
1516 int nLine = 0;
 
1517 char zPrevDate[20];
1518 const char *zCurrentUuid=0;
1519 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1520 Stmt fchngQuery; /* Query for file changes on check-ins */
1521 zPrevDate[0] = 0;
1522
 
1523 if( g.localOpen ){
1524 int rid = db_lget_int("checkout", 0);
1525 zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1526 }
1527
1528 while( db_step(q)==SQLITE_ROW && (mxLine<=0 || nLine<=mxLine) ){
1529 int rid = db_column_int(q, 0);
1530 const char *zId = db_column_text(q, 1);
1531 const char *zDate = db_column_text(q, 2);
1532 const char *zCom = db_column_text(q, 3);
1533 int nChild = db_column_int(q, 4);
@@ -1535,10 +1540,19 @@
1535 char *zFree = 0;
1536 int n = 0;
1537 char zPrefix[80];
1538 char zUuid[UUID_SIZE+1];
1539
 
 
 
 
 
 
 
 
 
1540 sqlite3_snprintf(sizeof(zUuid), zUuid, "%.10s", zId);
1541 if( memcmp(zDate, zPrevDate, 10) ){
1542 fossil_print("=== %.10s ===\n", zDate);
1543 memcpy(zPrevDate, zDate, 10);
1544 nLine++; /* record another line */
@@ -1563,11 +1577,11 @@
1563 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1564 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1565 n += strlen(zPrefix);
1566 }
1567 zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1568 nLine += comment_print(zFree, 9, 79); /* record another X lines */
1569 sqlite3_free(zFree);
1570
1571 if(verboseFlag){
1572 if( !fchngQueryInit ){
1573 db_prepare(&fchngQuery,
@@ -1596,10 +1610,11 @@
1596 }
1597 nLine++; /* record another line */
1598 }
1599 db_reset(&fchngQuery);
1600 }
 
1601 }
1602 if( fchngQueryInit ) db_finalize(&fchngQuery);
1603 }
1604
1605 /*
@@ -1666,47 +1681,66 @@
1666 ** The DATETIME should be in the ISO8601 format. For
1667 ** examples: "2007-08-18 07:21:21". You can also say "current"
1668 ** for the current version or "now" for the current time.
1669 **
1670 ** Options:
1671 ** -n|--limit N Output the first N changes (default 20)
 
 
1672 ** -t|--type TYPE Output items from the given types only, such as:
1673 ** ci = file commits only
1674 ** e = events only
1675 ** t = tickets only
1676 ** w = wiki commits only
1677 ** -v|--verbose Output the list of files changed by each commit
1678 ** and the type of each change (edited, deleted,
1679 ** etc.) after the checkin comment.
 
 
1680 */
1681 void timeline_cmd(void){
1682 Stmt q;
1683 int n, k;
1684 const char *zLimit;
 
 
1685 const char *zType;
1686 char *zOrigin;
1687 char *zDate;
1688 Blob sql;
1689 int objid = 0;
1690 Blob uuid;
1691 int mode = 0 ; /* 0:none 1: before 2:after 3:children 4:parents */
1692 int verboseFlag = 0 ;
 
 
1693 verboseFlag = find_option("verbose","v", 0)!=0;
1694 if( !verboseFlag){
1695 verboseFlag = find_option("showfiles","f", 0)!=0; /* deprecated */
1696 }
1697 db_find_and_open_repository(0, 0);
1698 zLimit = find_option("limit","n",1);
 
1699 zType = find_option("type","t",1);
1700 if ( !zLimit ){
1701 zLimit = find_option("count",0,1);
1702 }
1703 if( zLimit ){
1704 n = atoi(zLimit);
1705 }else{
1706 n = 20;
 
 
 
 
 
 
 
 
1707 }
 
 
1708 if( g.argc>=4 ){
1709 k = strlen(g.argv[2]);
1710 if( strncmp(g.argv[2],"before",k)==0 ){
1711 mode = 1;
1712 }else if( strncmp(g.argv[2],"after",k)==0 && k>1 ){
@@ -1718,11 +1752,11 @@
1718 }else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
1719 mode = 4;
1720 }else if( strncmp(g.argv[2],"parents",k)==0 ){
1721 mode = 4;
1722 }else if(!zType && !zLimit){
1723 usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit N? ?-t|--type TYPE?");
1724 }
1725 if( '-' != *g.argv[3] ){
1726 zOrigin = g.argv[3];
1727 }else{
1728 zOrigin = "now";
@@ -1778,13 +1812,16 @@
1778 }
1779 if( zType && (zType[0]!='a') ){
1780 blob_appendf(&sql, " AND event.type=%Q ", zType);
1781 }
1782 blob_appendf(&sql, " ORDER BY event.mtime DESC");
 
 
 
1783 db_prepare(&q, blob_str(&sql));
1784 blob_reset(&sql);
1785 print_timeline(&q, n, verboseFlag);
1786 db_finalize(&q);
1787 }
1788
1789 /*
1790 ** This is a version of the "localtime()" function from the standard
1791
--- src/timeline.c
+++ src/timeline.c
@@ -1494,14 +1494,17 @@
1494
1495 /*
1496 ** The input query q selects various records. Print a human-readable
1497 ** summary of those records.
1498 **
1499 ** Limit number of lines or entries printed to nLimit. If nLimit is zero
1500 ** there is no limit. If nLimit is greater than zero, limit the number of
1501 ** complete entries printed. If nLimit is less than zero, attempt to limit
1502 ** the number of lines printed (this is basically the legacy behavior).
1503 ** The line limit, if used, is approximate because it is only checked on a
1504 ** per-entry basis. If verbose mode, the file name details are considered
1505 ** to be part of the entry.
1506 **
1507 ** The query should return these columns:
1508 **
1509 ** 0. rid
1510 ** 1. uuid
@@ -1510,24 +1513,26 @@
1513 ** 4. Number of non-merge children
1514 ** 5. Number of parents
1515 ** 6. mtime
1516 ** 7. branch
1517 */
1518 void print_timeline(Stmt *q, int nLimit, int width, int verboseFlag){
1519 int nAbsLimit = (nLimit >= 0) ? nLimit : -nLimit;
1520 int nLine = 0;
1521 int nEntry = 0;
1522 char zPrevDate[20];
1523 const char *zCurrentUuid = 0;
1524 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1525 Stmt fchngQuery; /* Query for file changes on check-ins */
 
1526
1527 zPrevDate[0] = 0;
1528 if( g.localOpen ){
1529 int rid = db_lget_int("checkout", 0);
1530 zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1531 }
1532
1533 while( db_step(q)==SQLITE_ROW ){
1534 int rid = db_column_int(q, 0);
1535 const char *zId = db_column_text(q, 1);
1536 const char *zDate = db_column_text(q, 2);
1537 const char *zCom = db_column_text(q, 3);
1538 int nChild = db_column_int(q, 4);
@@ -1535,10 +1540,19 @@
1540 char *zFree = 0;
1541 int n = 0;
1542 char zPrefix[80];
1543 char zUuid[UUID_SIZE+1];
1544
1545 if( nAbsLimit!=0 ){
1546 if( nLimit<0 && nLine>=nAbsLimit ){
1547 fossil_print("--- line limit (%d) reached ---\n", nAbsLimit);
1548 break; /* line count limit hit, stop. */
1549 }else if( nEntry>=nAbsLimit ){
1550 fossil_print("--- entry limit (%d) reached ---\n", nAbsLimit);
1551 break; /* entry count limit hit, stop. */
1552 }
1553 }
1554 sqlite3_snprintf(sizeof(zUuid), zUuid, "%.10s", zId);
1555 if( memcmp(zDate, zPrevDate, 10) ){
1556 fossil_print("=== %.10s ===\n", zDate);
1557 memcpy(zPrevDate, zDate, 10);
1558 nLine++; /* record another line */
@@ -1563,11 +1577,11 @@
1577 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1578 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1579 n += strlen(zPrefix);
1580 }
1581 zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1582 nLine += comment_print(zFree, 9, width); /* record another X lines */
1583 sqlite3_free(zFree);
1584
1585 if(verboseFlag){
1586 if( !fchngQueryInit ){
1587 db_prepare(&fchngQuery,
@@ -1596,10 +1610,11 @@
1610 }
1611 nLine++; /* record another line */
1612 }
1613 db_reset(&fchngQuery);
1614 }
1615 nEntry++; /* record another complete entry */
1616 }
1617 if( fchngQueryInit ) db_finalize(&fchngQuery);
1618 }
1619
1620 /*
@@ -1666,47 +1681,66 @@
1681 ** The DATETIME should be in the ISO8601 format. For
1682 ** examples: "2007-08-18 07:21:21". You can also say "current"
1683 ** for the current version or "now" for the current time.
1684 **
1685 ** Options:
1686 ** -n|--limit N Output the first N entries (default 20 lines).
1687 ** N=0 means no limit.
1688 ** --offset P skip P changes
1689 ** -t|--type TYPE Output items from the given types only, such as:
1690 ** ci = file commits only
1691 ** e = events only
1692 ** t = tickets only
1693 ** w = wiki commits only
1694 ** -v|--verbose Output the list of files changed by each commit
1695 ** and the type of each change (edited, deleted,
1696 ** etc.) after the checkin comment.
1697 ** -W|--width <num> With of lines (default 79). Must be >20 or 0
1698 ** (= no limit, resulting in a single line per entry).
1699 */
1700 void timeline_cmd(void){
1701 Stmt q;
1702 int n, k, width;
1703 const char *zLimit;
1704 const char *zWidth;
1705 const char *zOffset;
1706 const char *zType;
1707 char *zOrigin;
1708 char *zDate;
1709 Blob sql;
1710 int objid = 0;
1711 Blob uuid;
1712 int mode = 0 ; /* 0:none 1: before 2:after 3:children 4:parents */
1713 int verboseFlag = 0 ;
1714 int iOffset;
1715
1716 verboseFlag = find_option("verbose","v", 0)!=0;
1717 if( !verboseFlag){
1718 verboseFlag = find_option("showfiles","f", 0)!=0; /* deprecated */
1719 }
1720 db_find_and_open_repository(0, 0);
1721 zLimit = find_option("limit","n",1);
1722 zWidth = find_option("width","W",1);
1723 zType = find_option("type","t",1);
1724 if ( !zLimit ){
1725 zLimit = find_option("count",0,1);
1726 }
1727 if( zLimit ){
1728 n = atoi(zLimit);
1729 }else{
1730 n = -20;
1731 }
1732 if( zWidth ){
1733 width = atoi(zWidth);
1734 if( (width!=0) && (width<=20) ){
1735 fossil_fatal("--width|-W value must be >20 or 0");
1736 }
1737 }else{
1738 width = 79;
1739 }
1740 zOffset = find_option("offset",0,1);
1741 iOffset = zOffset ? atoi(zOffset) : 0;
1742 if( g.argc>=4 ){
1743 k = strlen(g.argv[2]);
1744 if( strncmp(g.argv[2],"before",k)==0 ){
1745 mode = 1;
1746 }else if( strncmp(g.argv[2],"after",k)==0 && k>1 ){
@@ -1718,11 +1752,11 @@
1752 }else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
1753 mode = 4;
1754 }else if( strncmp(g.argv[2],"parents",k)==0 ){
1755 mode = 4;
1756 }else if(!zType && !zLimit){
1757 usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit #? ?-t|--type TYPE? ?-W|--width WIDTH?");
1758 }
1759 if( '-' != *g.argv[3] ){
1760 zOrigin = g.argv[3];
1761 }else{
1762 zOrigin = "now";
@@ -1778,13 +1812,16 @@
1812 }
1813 if( zType && (zType[0]!='a') ){
1814 blob_appendf(&sql, " AND event.type=%Q ", zType);
1815 }
1816 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1817 if( iOffset>0 ){
1818 blob_appendf(&sql, " LIMIT %d OFFSET %d", n>0?n+1:99999, iOffset);
1819 }
1820 db_prepare(&q, blob_str(&sql));
1821 blob_reset(&sql);
1822 print_timeline(&q, n, width, verboseFlag);
1823 db_finalize(&q);
1824 }
1825
1826 /*
1827 ** This is a version of the "localtime()" function from the standard
1828
+2 -5
--- src/update.c
+++ src/update.c
@@ -125,13 +125,10 @@
125125
debugFlag = find_option("debug",0,0)!=0;
126126
setmtimeFlag = find_option("setmtime",0,0)!=0;
127127
capture_case_sensitive_option();
128128
db_must_be_within_tree();
129129
vid = db_lget_int("checkout", 0);
130
- if( vid==0 ){
131
- fossil_fatal("cannot find current version");
132
- }
133130
user_select();
134131
if( !dryRunFlag && !internalUpdate ){
135132
autosync(SYNC_PULL + SYNC_VERBOSE*verboseFlag);
136133
}
137134
@@ -188,11 +185,11 @@
188185
"%s "
189186
" AND event.objid IN leaves"
190187
" ORDER BY event.mtime DESC",
191188
timeline_query_for_tty()
192189
);
193
- print_timeline(&q, 100, 0);
190
+ print_timeline(&q, -100, 79, 0);
194191
db_finalize(&q);
195192
fossil_fatal("Multiple descendants");
196193
}
197194
}
198195
tid = db_int(0, "SELECT rid FROM leaves, event"
@@ -200,11 +197,11 @@
200197
" ORDER BY event.mtime DESC");
201198
if( tid==0 ) tid = vid;
202199
}
203200
204201
if( tid==0 ){
205
- fossil_panic("unable to find a version to update to.");
202
+ return;
206203
}
207204
208205
db_begin_transaction();
209206
vfile_check_signature(vid, CKSIG_ENOTFILE);
210207
if( !dryRunFlag && !internalUpdate ) undo_begin();
211208
--- src/update.c
+++ src/update.c
@@ -125,13 +125,10 @@
125 debugFlag = find_option("debug",0,0)!=0;
126 setmtimeFlag = find_option("setmtime",0,0)!=0;
127 capture_case_sensitive_option();
128 db_must_be_within_tree();
129 vid = db_lget_int("checkout", 0);
130 if( vid==0 ){
131 fossil_fatal("cannot find current version");
132 }
133 user_select();
134 if( !dryRunFlag && !internalUpdate ){
135 autosync(SYNC_PULL + SYNC_VERBOSE*verboseFlag);
136 }
137
@@ -188,11 +185,11 @@
188 "%s "
189 " AND event.objid IN leaves"
190 " ORDER BY event.mtime DESC",
191 timeline_query_for_tty()
192 );
193 print_timeline(&q, 100, 0);
194 db_finalize(&q);
195 fossil_fatal("Multiple descendants");
196 }
197 }
198 tid = db_int(0, "SELECT rid FROM leaves, event"
@@ -200,11 +197,11 @@
200 " ORDER BY event.mtime DESC");
201 if( tid==0 ) tid = vid;
202 }
203
204 if( tid==0 ){
205 fossil_panic("unable to find a version to update to.");
206 }
207
208 db_begin_transaction();
209 vfile_check_signature(vid, CKSIG_ENOTFILE);
210 if( !dryRunFlag && !internalUpdate ) undo_begin();
211
--- src/update.c
+++ src/update.c
@@ -125,13 +125,10 @@
125 debugFlag = find_option("debug",0,0)!=0;
126 setmtimeFlag = find_option("setmtime",0,0)!=0;
127 capture_case_sensitive_option();
128 db_must_be_within_tree();
129 vid = db_lget_int("checkout", 0);
 
 
 
130 user_select();
131 if( !dryRunFlag && !internalUpdate ){
132 autosync(SYNC_PULL + SYNC_VERBOSE*verboseFlag);
133 }
134
@@ -188,11 +185,11 @@
185 "%s "
186 " AND event.objid IN leaves"
187 " ORDER BY event.mtime DESC",
188 timeline_query_for_tty()
189 );
190 print_timeline(&q, -100, 79, 0);
191 db_finalize(&q);
192 fossil_fatal("Multiple descendants");
193 }
194 }
195 tid = db_int(0, "SELECT rid FROM leaves, event"
@@ -200,11 +197,11 @@
197 " ORDER BY event.mtime DESC");
198 if( tid==0 ) tid = vid;
199 }
200
201 if( tid==0 ){
202 return;
203 }
204
205 db_begin_transaction();
206 vfile_check_signature(vid, CKSIG_ENOTFILE);
207 if( !dryRunFlag && !internalUpdate ) undo_begin();
208
+33 -27
--- src/url.c
+++ src/url.c
@@ -17,10 +17,16 @@
1717
**
1818
** This file contains code for parsing URLs that appear on the command-line
1919
*/
2020
#include "config.h"
2121
#include "url.h"
22
+#include <stdio.h>
23
+#ifdef _WIN32
24
+#include <io.h>
25
+#define isatty(d) _isatty(d)
26
+#define fileno(s) _fileno(s)
27
+#endif
2228
2329
#if INTERFACE
2430
/*
2531
** Flags for url_parse()
2632
*/
@@ -64,24 +70,23 @@
6470
**
6571
** http://userid:password@host:port/path
6672
**
6773
** SSH url format is:
6874
**
69
-** ssh://userid:password@host:port/path?fossil=path/to/fossil.exe
75
+** ssh://userid@host:port/path?fossil=path/to/fossil.exe
7076
**
7177
*/
7278
void url_parse(const char *zUrl, unsigned int urlFlags){
7379
int i, j, c;
7480
char *zFile = 0;
75
- int bPrompted = 0;
76
- int bSetUrl = 1;
7781
7882
if( zUrl==0 ){
7983
zUrl = db_get("last-sync-url", 0);
8084
if( zUrl==0 ) return;
81
- g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
82
- bSetUrl = 0;
85
+ if( g.urlPasswd==0 ){
86
+ g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
87
+ }
8388
}
8489
8590
if( strncmp(zUrl, "http://", 7)==0
8691
|| strncmp(zUrl, "https://", 8)==0
8792
|| strncmp(zUrl, "ssh://", 6)==0
@@ -115,18 +120,20 @@
115120
/* Parse up the user-id and password */
116121
for(j=iStart; j<i && zUrl[j]!=':'; j++){}
117122
g.urlUser = mprintf("%.*s", j-iStart, &zUrl[iStart]);
118123
dehttpize(g.urlUser);
119124
if( j<i ){
125
+ if( ( urlFlags & URL_REMEMBER ) && g.urlIsSsh==0 ){
126
+ urlFlags |= URL_ASK_REMEMBER_PW;
127
+ }
120128
g.urlPasswd = mprintf("%.*s", i-j-1, &zUrl[j+1]);
121129
dehttpize(g.urlPasswd);
122130
}
123
- if( g.urlIsSsh && g.urlPasswd ){
124
- zLogin = mprintf("%t:*@", g.urlUser);
125
- }else{
126
- zLogin = mprintf("%t@", g.urlUser);
131
+ if( g.urlIsSsh ){
132
+ urlFlags &= ~URL_ASK_REMEMBER_PW;
127133
}
134
+ zLogin = mprintf("%t@", g.urlUser);
128135
for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
129136
g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
130137
i = j;
131138
}else{
132139
for(i=iStart; (c=zUrl[i])!=0 && c!='/' && c!=':'; i++){}
@@ -211,11 +218,11 @@
211218
fossil_fatal("unknown repository: %s", zUrl);
212219
}
213220
}else{
214221
fossil_fatal("unknown repository: %s", zUrl);
215222
}
216
- g.urlFlags = urlFlags;
223
+ if( urlFlags ) g.urlFlags = urlFlags;
217224
if( g.urlIsFile ){
218225
Blob cfile;
219226
dehttpize(zFile);
220227
file_canonical_name(zFile, &cfile, 0);
221228
free(zFile);
@@ -224,18 +231,17 @@
224231
g.urlName = mprintf("%b", &cfile);
225232
g.urlCanonical = mprintf("file://%T", g.urlName);
226233
blob_reset(&cfile);
227234
}else if( g.urlUser!=0 && g.urlPasswd==0 && (urlFlags & URL_PROMPT_PW) ){
228235
url_prompt_for_password();
229
- bPrompted = 1;
230
- }
231
- if( urlFlags & URL_REMEMBER ){
232
- if( bSetUrl ){
233
- db_set("last-sync-url", g.urlCanonical, 0);
234
- }
235
- if( !bPrompted && g.urlPasswd && g.urlUser ){
236
- db_set("last-sync-pw", obscure(g.urlPasswd), 0);
236
+ }else if( g.urlUser!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){
237
+ if( isatty(fileno(stdin)) ){
238
+ if( save_password_prompt() ){
239
+ g.urlFlags = urlFlags |= URL_REMEMBER_PW;
240
+ }else{
241
+ g.urlFlags = urlFlags &= ~URL_REMEMBER_PW;
242
+ }
237243
}
238244
}
239245
}
240246
241247
/*
@@ -452,38 +458,38 @@
452458
if( g.urlPasswd[0]
453459
&& (g.urlFlags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
454460
){
455461
if( save_password_prompt() ){
456462
g.urlFlags |= URL_REMEMBER_PW;
457
- if( g.urlFlags & URL_REMEMBER ){
458
- db_set("last-sync-pw", obscure(g.urlPasswd), 0);
459
- }
463
+ }else{
464
+ g.urlFlags &= ~URL_REMEMBER_PW;
460465
}
461466
}
462467
}else{
463468
fossil_fatal("missing or incorrect password for user \"%s\"",
464469
g.urlUser);
465470
}
466471
}
467472
468473
/*
469
-** Remember the URL if requested.
474
+** Remember the URL and password if requested.
470475
*/
471476
void url_remember(void){
472
- db_set("last-sync-url", g.urlCanonical, 0);
473
- if( g.urlFlags & URL_REMEMBER_PW ){
474
- db_set("last-sync-pw", obscure(g.urlPasswd), 0);
477
+ if( g.urlFlags & URL_REMEMBER ){
478
+ db_set("last-sync-url", g.urlCanonical, 0);
479
+ if( g.urlUser!=0 && g.urlPasswd!=0 && ( g.urlFlags & URL_REMEMBER_PW ) ){
480
+ db_set("last-sync-pw", obscure(g.urlPasswd), 0);
481
+ }
475482
}
476
- g.urlFlags |= URL_REMEMBER;
477483
}
478484
479485
/* Preemptively prompt for a password if a username is given in the
480486
** URL but no password.
481487
*/
482488
void url_get_password_if_needed(void){
483489
if( (g.urlUser && g.urlUser[0])
484490
&& (g.urlPasswd==0 || g.urlPasswd[0]==0)
485
- && isatty(fileno(stdin))
491
+ && isatty(fileno(stdin))
486492
){
487493
url_prompt_for_password();
488494
}
489495
}
490496
--- src/url.c
+++ src/url.c
@@ -17,10 +17,16 @@
17 **
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
 
 
 
 
 
 
22
23 #if INTERFACE
24 /*
25 ** Flags for url_parse()
26 */
@@ -64,24 +70,23 @@
64 **
65 ** http://userid:password@host:port/path
66 **
67 ** SSH url format is:
68 **
69 ** ssh://userid:password@host:port/path?fossil=path/to/fossil.exe
70 **
71 */
72 void url_parse(const char *zUrl, unsigned int urlFlags){
73 int i, j, c;
74 char *zFile = 0;
75 int bPrompted = 0;
76 int bSetUrl = 1;
77
78 if( zUrl==0 ){
79 zUrl = db_get("last-sync-url", 0);
80 if( zUrl==0 ) return;
81 g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
82 bSetUrl = 0;
 
83 }
84
85 if( strncmp(zUrl, "http://", 7)==0
86 || strncmp(zUrl, "https://", 8)==0
87 || strncmp(zUrl, "ssh://", 6)==0
@@ -115,18 +120,20 @@
115 /* Parse up the user-id and password */
116 for(j=iStart; j<i && zUrl[j]!=':'; j++){}
117 g.urlUser = mprintf("%.*s", j-iStart, &zUrl[iStart]);
118 dehttpize(g.urlUser);
119 if( j<i ){
 
 
 
120 g.urlPasswd = mprintf("%.*s", i-j-1, &zUrl[j+1]);
121 dehttpize(g.urlPasswd);
122 }
123 if( g.urlIsSsh && g.urlPasswd ){
124 zLogin = mprintf("%t:*@", g.urlUser);
125 }else{
126 zLogin = mprintf("%t@", g.urlUser);
127 }
 
128 for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
129 g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
130 i = j;
131 }else{
132 for(i=iStart; (c=zUrl[i])!=0 && c!='/' && c!=':'; i++){}
@@ -211,11 +218,11 @@
211 fossil_fatal("unknown repository: %s", zUrl);
212 }
213 }else{
214 fossil_fatal("unknown repository: %s", zUrl);
215 }
216 g.urlFlags = urlFlags;
217 if( g.urlIsFile ){
218 Blob cfile;
219 dehttpize(zFile);
220 file_canonical_name(zFile, &cfile, 0);
221 free(zFile);
@@ -224,18 +231,17 @@
224 g.urlName = mprintf("%b", &cfile);
225 g.urlCanonical = mprintf("file://%T", g.urlName);
226 blob_reset(&cfile);
227 }else if( g.urlUser!=0 && g.urlPasswd==0 && (urlFlags & URL_PROMPT_PW) ){
228 url_prompt_for_password();
229 bPrompted = 1;
230 }
231 if( urlFlags & URL_REMEMBER ){
232 if( bSetUrl ){
233 db_set("last-sync-url", g.urlCanonical, 0);
234 }
235 if( !bPrompted && g.urlPasswd && g.urlUser ){
236 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
237 }
238 }
239 }
240
241 /*
@@ -452,38 +458,38 @@
452 if( g.urlPasswd[0]
453 && (g.urlFlags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
454 ){
455 if( save_password_prompt() ){
456 g.urlFlags |= URL_REMEMBER_PW;
457 if( g.urlFlags & URL_REMEMBER ){
458 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
459 }
460 }
461 }
462 }else{
463 fossil_fatal("missing or incorrect password for user \"%s\"",
464 g.urlUser);
465 }
466 }
467
468 /*
469 ** Remember the URL if requested.
470 */
471 void url_remember(void){
472 db_set("last-sync-url", g.urlCanonical, 0);
473 if( g.urlFlags & URL_REMEMBER_PW ){
474 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
 
 
475 }
476 g.urlFlags |= URL_REMEMBER;
477 }
478
479 /* Preemptively prompt for a password if a username is given in the
480 ** URL but no password.
481 */
482 void url_get_password_if_needed(void){
483 if( (g.urlUser && g.urlUser[0])
484 && (g.urlPasswd==0 || g.urlPasswd[0]==0)
485 && isatty(fileno(stdin))
486 ){
487 url_prompt_for_password();
488 }
489 }
490
--- src/url.c
+++ src/url.c
@@ -17,10 +17,16 @@
17 **
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
22 #include <stdio.h>
23 #ifdef _WIN32
24 #include <io.h>
25 #define isatty(d) _isatty(d)
26 #define fileno(s) _fileno(s)
27 #endif
28
29 #if INTERFACE
30 /*
31 ** Flags for url_parse()
32 */
@@ -64,24 +70,23 @@
70 **
71 ** http://userid:password@host:port/path
72 **
73 ** SSH url format is:
74 **
75 ** ssh://userid@host:port/path?fossil=path/to/fossil.exe
76 **
77 */
78 void url_parse(const char *zUrl, unsigned int urlFlags){
79 int i, j, c;
80 char *zFile = 0;
 
 
81
82 if( zUrl==0 ){
83 zUrl = db_get("last-sync-url", 0);
84 if( zUrl==0 ) return;
85 if( g.urlPasswd==0 ){
86 g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
87 }
88 }
89
90 if( strncmp(zUrl, "http://", 7)==0
91 || strncmp(zUrl, "https://", 8)==0
92 || strncmp(zUrl, "ssh://", 6)==0
@@ -115,18 +120,20 @@
120 /* Parse up the user-id and password */
121 for(j=iStart; j<i && zUrl[j]!=':'; j++){}
122 g.urlUser = mprintf("%.*s", j-iStart, &zUrl[iStart]);
123 dehttpize(g.urlUser);
124 if( j<i ){
125 if( ( urlFlags & URL_REMEMBER ) && g.urlIsSsh==0 ){
126 urlFlags |= URL_ASK_REMEMBER_PW;
127 }
128 g.urlPasswd = mprintf("%.*s", i-j-1, &zUrl[j+1]);
129 dehttpize(g.urlPasswd);
130 }
131 if( g.urlIsSsh ){
132 urlFlags &= ~URL_ASK_REMEMBER_PW;
 
 
133 }
134 zLogin = mprintf("%t@", g.urlUser);
135 for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
136 g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
137 i = j;
138 }else{
139 for(i=iStart; (c=zUrl[i])!=0 && c!='/' && c!=':'; i++){}
@@ -211,11 +218,11 @@
218 fossil_fatal("unknown repository: %s", zUrl);
219 }
220 }else{
221 fossil_fatal("unknown repository: %s", zUrl);
222 }
223 if( urlFlags ) g.urlFlags = urlFlags;
224 if( g.urlIsFile ){
225 Blob cfile;
226 dehttpize(zFile);
227 file_canonical_name(zFile, &cfile, 0);
228 free(zFile);
@@ -224,18 +231,17 @@
231 g.urlName = mprintf("%b", &cfile);
232 g.urlCanonical = mprintf("file://%T", g.urlName);
233 blob_reset(&cfile);
234 }else if( g.urlUser!=0 && g.urlPasswd==0 && (urlFlags & URL_PROMPT_PW) ){
235 url_prompt_for_password();
236 }else if( g.urlUser!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){
237 if( isatty(fileno(stdin)) ){
238 if( save_password_prompt() ){
239 g.urlFlags = urlFlags |= URL_REMEMBER_PW;
240 }else{
241 g.urlFlags = urlFlags &= ~URL_REMEMBER_PW;
242 }
 
243 }
244 }
245 }
246
247 /*
@@ -452,38 +458,38 @@
458 if( g.urlPasswd[0]
459 && (g.urlFlags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
460 ){
461 if( save_password_prompt() ){
462 g.urlFlags |= URL_REMEMBER_PW;
463 }else{
464 g.urlFlags &= ~URL_REMEMBER_PW;
 
465 }
466 }
467 }else{
468 fossil_fatal("missing or incorrect password for user \"%s\"",
469 g.urlUser);
470 }
471 }
472
473 /*
474 ** Remember the URL and password if requested.
475 */
476 void url_remember(void){
477 if( g.urlFlags & URL_REMEMBER ){
478 db_set("last-sync-url", g.urlCanonical, 0);
479 if( g.urlUser!=0 && g.urlPasswd!=0 && ( g.urlFlags & URL_REMEMBER_PW ) ){
480 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
481 }
482 }
 
483 }
484
485 /* Preemptively prompt for a password if a username is given in the
486 ** URL but no password.
487 */
488 void url_get_password_if_needed(void){
489 if( (g.urlUser && g.urlUser[0])
490 && (g.urlPasswd==0 || g.urlPasswd[0]==0)
491 && isatty(fileno(stdin))
492 ){
493 url_prompt_for_password();
494 }
495 }
496
+33 -27
--- src/url.c
+++ src/url.c
@@ -17,10 +17,16 @@
1717
**
1818
** This file contains code for parsing URLs that appear on the command-line
1919
*/
2020
#include "config.h"
2121
#include "url.h"
22
+#include <stdio.h>
23
+#ifdef _WIN32
24
+#include <io.h>
25
+#define isatty(d) _isatty(d)
26
+#define fileno(s) _fileno(s)
27
+#endif
2228
2329
#if INTERFACE
2430
/*
2531
** Flags for url_parse()
2632
*/
@@ -64,24 +70,23 @@
6470
**
6571
** http://userid:password@host:port/path
6672
**
6773
** SSH url format is:
6874
**
69
-** ssh://userid:password@host:port/path?fossil=path/to/fossil.exe
75
+** ssh://userid@host:port/path?fossil=path/to/fossil.exe
7076
**
7177
*/
7278
void url_parse(const char *zUrl, unsigned int urlFlags){
7379
int i, j, c;
7480
char *zFile = 0;
75
- int bPrompted = 0;
76
- int bSetUrl = 1;
7781
7882
if( zUrl==0 ){
7983
zUrl = db_get("last-sync-url", 0);
8084
if( zUrl==0 ) return;
81
- g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
82
- bSetUrl = 0;
85
+ if( g.urlPasswd==0 ){
86
+ g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
87
+ }
8388
}
8489
8590
if( strncmp(zUrl, "http://", 7)==0
8691
|| strncmp(zUrl, "https://", 8)==0
8792
|| strncmp(zUrl, "ssh://", 6)==0
@@ -115,18 +120,20 @@
115120
/* Parse up the user-id and password */
116121
for(j=iStart; j<i && zUrl[j]!=':'; j++){}
117122
g.urlUser = mprintf("%.*s", j-iStart, &zUrl[iStart]);
118123
dehttpize(g.urlUser);
119124
if( j<i ){
125
+ if( ( urlFlags & URL_REMEMBER ) && g.urlIsSsh==0 ){
126
+ urlFlags |= URL_ASK_REMEMBER_PW;
127
+ }
120128
g.urlPasswd = mprintf("%.*s", i-j-1, &zUrl[j+1]);
121129
dehttpize(g.urlPasswd);
122130
}
123
- if( g.urlIsSsh && g.urlPasswd ){
124
- zLogin = mprintf("%t:*@", g.urlUser);
125
- }else{
126
- zLogin = mprintf("%t@", g.urlUser);
131
+ if( g.urlIsSsh ){
132
+ urlFlags &= ~URL_ASK_REMEMBER_PW;
127133
}
134
+ zLogin = mprintf("%t@", g.urlUser);
128135
for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
129136
g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
130137
i = j;
131138
}else{
132139
for(i=iStart; (c=zUrl[i])!=0 && c!='/' && c!=':'; i++){}
@@ -211,11 +218,11 @@
211218
fossil_fatal("unknown repository: %s", zUrl);
212219
}
213220
}else{
214221
fossil_fatal("unknown repository: %s", zUrl);
215222
}
216
- g.urlFlags = urlFlags;
223
+ if( urlFlags ) g.urlFlags = urlFlags;
217224
if( g.urlIsFile ){
218225
Blob cfile;
219226
dehttpize(zFile);
220227
file_canonical_name(zFile, &cfile, 0);
221228
free(zFile);
@@ -224,18 +231,17 @@
224231
g.urlName = mprintf("%b", &cfile);
225232
g.urlCanonical = mprintf("file://%T", g.urlName);
226233
blob_reset(&cfile);
227234
}else if( g.urlUser!=0 && g.urlPasswd==0 && (urlFlags & URL_PROMPT_PW) ){
228235
url_prompt_for_password();
229
- bPrompted = 1;
230
- }
231
- if( urlFlags & URL_REMEMBER ){
232
- if( bSetUrl ){
233
- db_set("last-sync-url", g.urlCanonical, 0);
234
- }
235
- if( !bPrompted && g.urlPasswd && g.urlUser ){
236
- db_set("last-sync-pw", obscure(g.urlPasswd), 0);
236
+ }else if( g.urlUser!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){
237
+ if( isatty(fileno(stdin)) ){
238
+ if( save_password_prompt() ){
239
+ g.urlFlags = urlFlags |= URL_REMEMBER_PW;
240
+ }else{
241
+ g.urlFlags = urlFlags &= ~URL_REMEMBER_PW;
242
+ }
237243
}
238244
}
239245
}
240246
241247
/*
@@ -452,38 +458,38 @@
452458
if( g.urlPasswd[0]
453459
&& (g.urlFlags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
454460
){
455461
if( save_password_prompt() ){
456462
g.urlFlags |= URL_REMEMBER_PW;
457
- if( g.urlFlags & URL_REMEMBER ){
458
- db_set("last-sync-pw", obscure(g.urlPasswd), 0);
459
- }
463
+ }else{
464
+ g.urlFlags &= ~URL_REMEMBER_PW;
460465
}
461466
}
462467
}else{
463468
fossil_fatal("missing or incorrect password for user \"%s\"",
464469
g.urlUser);
465470
}
466471
}
467472
468473
/*
469
-** Remember the URL if requested.
474
+** Remember the URL and password if requested.
470475
*/
471476
void url_remember(void){
472
- db_set("last-sync-url", g.urlCanonical, 0);
473
- if( g.urlFlags & URL_REMEMBER_PW ){
474
- db_set("last-sync-pw", obscure(g.urlPasswd), 0);
477
+ if( g.urlFlags & URL_REMEMBER ){
478
+ db_set("last-sync-url", g.urlCanonical, 0);
479
+ if( g.urlUser!=0 && g.urlPasswd!=0 && ( g.urlFlags & URL_REMEMBER_PW ) ){
480
+ db_set("last-sync-pw", obscure(g.urlPasswd), 0);
481
+ }
475482
}
476
- g.urlFlags |= URL_REMEMBER;
477483
}
478484
479485
/* Preemptively prompt for a password if a username is given in the
480486
** URL but no password.
481487
*/
482488
void url_get_password_if_needed(void){
483489
if( (g.urlUser && g.urlUser[0])
484490
&& (g.urlPasswd==0 || g.urlPasswd[0]==0)
485
- && isatty(fileno(stdin))
491
+ && isatty(fileno(stdin))
486492
){
487493
url_prompt_for_password();
488494
}
489495
}
490496
--- src/url.c
+++ src/url.c
@@ -17,10 +17,16 @@
17 **
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
 
 
 
 
 
 
22
23 #if INTERFACE
24 /*
25 ** Flags for url_parse()
26 */
@@ -64,24 +70,23 @@
64 **
65 ** http://userid:password@host:port/path
66 **
67 ** SSH url format is:
68 **
69 ** ssh://userid:password@host:port/path?fossil=path/to/fossil.exe
70 **
71 */
72 void url_parse(const char *zUrl, unsigned int urlFlags){
73 int i, j, c;
74 char *zFile = 0;
75 int bPrompted = 0;
76 int bSetUrl = 1;
77
78 if( zUrl==0 ){
79 zUrl = db_get("last-sync-url", 0);
80 if( zUrl==0 ) return;
81 g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
82 bSetUrl = 0;
 
83 }
84
85 if( strncmp(zUrl, "http://", 7)==0
86 || strncmp(zUrl, "https://", 8)==0
87 || strncmp(zUrl, "ssh://", 6)==0
@@ -115,18 +120,20 @@
115 /* Parse up the user-id and password */
116 for(j=iStart; j<i && zUrl[j]!=':'; j++){}
117 g.urlUser = mprintf("%.*s", j-iStart, &zUrl[iStart]);
118 dehttpize(g.urlUser);
119 if( j<i ){
 
 
 
120 g.urlPasswd = mprintf("%.*s", i-j-1, &zUrl[j+1]);
121 dehttpize(g.urlPasswd);
122 }
123 if( g.urlIsSsh && g.urlPasswd ){
124 zLogin = mprintf("%t:*@", g.urlUser);
125 }else{
126 zLogin = mprintf("%t@", g.urlUser);
127 }
 
128 for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
129 g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
130 i = j;
131 }else{
132 for(i=iStart; (c=zUrl[i])!=0 && c!='/' && c!=':'; i++){}
@@ -211,11 +218,11 @@
211 fossil_fatal("unknown repository: %s", zUrl);
212 }
213 }else{
214 fossil_fatal("unknown repository: %s", zUrl);
215 }
216 g.urlFlags = urlFlags;
217 if( g.urlIsFile ){
218 Blob cfile;
219 dehttpize(zFile);
220 file_canonical_name(zFile, &cfile, 0);
221 free(zFile);
@@ -224,18 +231,17 @@
224 g.urlName = mprintf("%b", &cfile);
225 g.urlCanonical = mprintf("file://%T", g.urlName);
226 blob_reset(&cfile);
227 }else if( g.urlUser!=0 && g.urlPasswd==0 && (urlFlags & URL_PROMPT_PW) ){
228 url_prompt_for_password();
229 bPrompted = 1;
230 }
231 if( urlFlags & URL_REMEMBER ){
232 if( bSetUrl ){
233 db_set("last-sync-url", g.urlCanonical, 0);
234 }
235 if( !bPrompted && g.urlPasswd && g.urlUser ){
236 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
237 }
238 }
239 }
240
241 /*
@@ -452,38 +458,38 @@
452 if( g.urlPasswd[0]
453 && (g.urlFlags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
454 ){
455 if( save_password_prompt() ){
456 g.urlFlags |= URL_REMEMBER_PW;
457 if( g.urlFlags & URL_REMEMBER ){
458 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
459 }
460 }
461 }
462 }else{
463 fossil_fatal("missing or incorrect password for user \"%s\"",
464 g.urlUser);
465 }
466 }
467
468 /*
469 ** Remember the URL if requested.
470 */
471 void url_remember(void){
472 db_set("last-sync-url", g.urlCanonical, 0);
473 if( g.urlFlags & URL_REMEMBER_PW ){
474 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
 
 
475 }
476 g.urlFlags |= URL_REMEMBER;
477 }
478
479 /* Preemptively prompt for a password if a username is given in the
480 ** URL but no password.
481 */
482 void url_get_password_if_needed(void){
483 if( (g.urlUser && g.urlUser[0])
484 && (g.urlPasswd==0 || g.urlPasswd[0]==0)
485 && isatty(fileno(stdin))
486 ){
487 url_prompt_for_password();
488 }
489 }
490
--- src/url.c
+++ src/url.c
@@ -17,10 +17,16 @@
17 **
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
22 #include <stdio.h>
23 #ifdef _WIN32
24 #include <io.h>
25 #define isatty(d) _isatty(d)
26 #define fileno(s) _fileno(s)
27 #endif
28
29 #if INTERFACE
30 /*
31 ** Flags for url_parse()
32 */
@@ -64,24 +70,23 @@
70 **
71 ** http://userid:password@host:port/path
72 **
73 ** SSH url format is:
74 **
75 ** ssh://userid@host:port/path?fossil=path/to/fossil.exe
76 **
77 */
78 void url_parse(const char *zUrl, unsigned int urlFlags){
79 int i, j, c;
80 char *zFile = 0;
 
 
81
82 if( zUrl==0 ){
83 zUrl = db_get("last-sync-url", 0);
84 if( zUrl==0 ) return;
85 if( g.urlPasswd==0 ){
86 g.urlPasswd = unobscure(db_get("last-sync-pw", 0));
87 }
88 }
89
90 if( strncmp(zUrl, "http://", 7)==0
91 || strncmp(zUrl, "https://", 8)==0
92 || strncmp(zUrl, "ssh://", 6)==0
@@ -115,18 +120,20 @@
120 /* Parse up the user-id and password */
121 for(j=iStart; j<i && zUrl[j]!=':'; j++){}
122 g.urlUser = mprintf("%.*s", j-iStart, &zUrl[iStart]);
123 dehttpize(g.urlUser);
124 if( j<i ){
125 if( ( urlFlags & URL_REMEMBER ) && g.urlIsSsh==0 ){
126 urlFlags |= URL_ASK_REMEMBER_PW;
127 }
128 g.urlPasswd = mprintf("%.*s", i-j-1, &zUrl[j+1]);
129 dehttpize(g.urlPasswd);
130 }
131 if( g.urlIsSsh ){
132 urlFlags &= ~URL_ASK_REMEMBER_PW;
 
 
133 }
134 zLogin = mprintf("%t@", g.urlUser);
135 for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
136 g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
137 i = j;
138 }else{
139 for(i=iStart; (c=zUrl[i])!=0 && c!='/' && c!=':'; i++){}
@@ -211,11 +218,11 @@
218 fossil_fatal("unknown repository: %s", zUrl);
219 }
220 }else{
221 fossil_fatal("unknown repository: %s", zUrl);
222 }
223 if( urlFlags ) g.urlFlags = urlFlags;
224 if( g.urlIsFile ){
225 Blob cfile;
226 dehttpize(zFile);
227 file_canonical_name(zFile, &cfile, 0);
228 free(zFile);
@@ -224,18 +231,17 @@
231 g.urlName = mprintf("%b", &cfile);
232 g.urlCanonical = mprintf("file://%T", g.urlName);
233 blob_reset(&cfile);
234 }else if( g.urlUser!=0 && g.urlPasswd==0 && (urlFlags & URL_PROMPT_PW) ){
235 url_prompt_for_password();
236 }else if( g.urlUser!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){
237 if( isatty(fileno(stdin)) ){
238 if( save_password_prompt() ){
239 g.urlFlags = urlFlags |= URL_REMEMBER_PW;
240 }else{
241 g.urlFlags = urlFlags &= ~URL_REMEMBER_PW;
242 }
 
243 }
244 }
245 }
246
247 /*
@@ -452,38 +458,38 @@
458 if( g.urlPasswd[0]
459 && (g.urlFlags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
460 ){
461 if( save_password_prompt() ){
462 g.urlFlags |= URL_REMEMBER_PW;
463 }else{
464 g.urlFlags &= ~URL_REMEMBER_PW;
 
465 }
466 }
467 }else{
468 fossil_fatal("missing or incorrect password for user \"%s\"",
469 g.urlUser);
470 }
471 }
472
473 /*
474 ** Remember the URL and password if requested.
475 */
476 void url_remember(void){
477 if( g.urlFlags & URL_REMEMBER ){
478 db_set("last-sync-url", g.urlCanonical, 0);
479 if( g.urlUser!=0 && g.urlPasswd!=0 && ( g.urlFlags & URL_REMEMBER_PW ) ){
480 db_set("last-sync-pw", obscure(g.urlPasswd), 0);
481 }
482 }
 
483 }
484
485 /* Preemptively prompt for a password if a username is given in the
486 ** URL but no password.
487 */
488 void url_get_password_if_needed(void){
489 if( (g.urlUser && g.urlUser[0])
490 && (g.urlPasswd==0 || g.urlPasswd[0]==0)
491 && isatty(fileno(stdin))
492 ){
493 url_prompt_for_password();
494 }
495 }
496
+5 -1
--- src/user.c
+++ src/user.c
@@ -135,10 +135,14 @@
135135
** Prompt to save Fossil user password
136136
*/
137137
int save_password_prompt(){
138138
Blob x;
139139
char c;
140
+ const char *old = db_get("last-sync-pw", 0);
141
+ if( (old!=0) && fossil_strcmp(unobscure(old), g.urlPasswd)==0 ){
142
+ return 0;
143
+ }
140144
prompt_user("remember password (Y/n)? ", &x);
141145
c = blob_str(&x)[0];
142146
blob_reset(&x);
143147
return ( c!='n' && c!='N' );
144148
}
@@ -290,11 +294,11 @@
290294
free(zSecret);
291295
}
292296
}else if( n>=2 && strncmp(g.argv[2],"capabilities",2)==0 ){
293297
int uid;
294298
if( g.argc!=4 && g.argc!=5 ){
295
- usage("user capabilities USERNAME ?PERMISSIONS?");
299
+ usage("capabilities USERNAME ?PERMISSIONS?");
296300
}
297301
uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.argv[3]);
298302
if( uid==0 ){
299303
fossil_fatal("no such user: %s", g.argv[3]);
300304
}
301305
--- src/user.c
+++ src/user.c
@@ -135,10 +135,14 @@
135 ** Prompt to save Fossil user password
136 */
137 int save_password_prompt(){
138 Blob x;
139 char c;
 
 
 
 
140 prompt_user("remember password (Y/n)? ", &x);
141 c = blob_str(&x)[0];
142 blob_reset(&x);
143 return ( c!='n' && c!='N' );
144 }
@@ -290,11 +294,11 @@
290 free(zSecret);
291 }
292 }else if( n>=2 && strncmp(g.argv[2],"capabilities",2)==0 ){
293 int uid;
294 if( g.argc!=4 && g.argc!=5 ){
295 usage("user capabilities USERNAME ?PERMISSIONS?");
296 }
297 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.argv[3]);
298 if( uid==0 ){
299 fossil_fatal("no such user: %s", g.argv[3]);
300 }
301
--- src/user.c
+++ src/user.c
@@ -135,10 +135,14 @@
135 ** Prompt to save Fossil user password
136 */
137 int save_password_prompt(){
138 Blob x;
139 char c;
140 const char *old = db_get("last-sync-pw", 0);
141 if( (old!=0) && fossil_strcmp(unobscure(old), g.urlPasswd)==0 ){
142 return 0;
143 }
144 prompt_user("remember password (Y/n)? ", &x);
145 c = blob_str(&x)[0];
146 blob_reset(&x);
147 return ( c!='n' && c!='N' );
148 }
@@ -290,11 +294,11 @@
294 free(zSecret);
295 }
296 }else if( n>=2 && strncmp(g.argv[2],"capabilities",2)==0 ){
297 int uid;
298 if( g.argc!=4 && g.argc!=5 ){
299 usage("capabilities USERNAME ?PERMISSIONS?");
300 }
301 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.argv[3]);
302 if( uid==0 ){
303 fossil_fatal("no such user: %s", g.argv[3]);
304 }
305
+2
--- src/xfer.c
+++ src/xfer.c
@@ -1781,11 +1781,13 @@
17811781
if( nCycle<2 ){
17821782
g.urlPasswd = 0;
17831783
go = 1;
17841784
if( g.cgiOutput==0 ){
17851785
g.urlFlags |= URL_PROMPT_PW;
1786
+ g.urlFlags &= ~URL_PROMPTED;
17861787
url_prompt_for_password();
1788
+ url_remember();
17871789
}
17881790
}
17891791
}else{
17901792
blob_appendf(&xfer.err, "server says: %s\n", zMsg);
17911793
nErr++;
17921794
--- src/xfer.c
+++ src/xfer.c
@@ -1781,11 +1781,13 @@
1781 if( nCycle<2 ){
1782 g.urlPasswd = 0;
1783 go = 1;
1784 if( g.cgiOutput==0 ){
1785 g.urlFlags |= URL_PROMPT_PW;
 
1786 url_prompt_for_password();
 
1787 }
1788 }
1789 }else{
1790 blob_appendf(&xfer.err, "server says: %s\n", zMsg);
1791 nErr++;
1792
--- src/xfer.c
+++ src/xfer.c
@@ -1781,11 +1781,13 @@
1781 if( nCycle<2 ){
1782 g.urlPasswd = 0;
1783 go = 1;
1784 if( g.cgiOutput==0 ){
1785 g.urlFlags |= URL_PROMPT_PW;
1786 g.urlFlags &= ~URL_PROMPTED;
1787 url_prompt_for_password();
1788 url_remember();
1789 }
1790 }
1791 }else{
1792 blob_appendf(&xfer.err, "server says: %s\n", zMsg);
1793 nErr++;
1794
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -89,11 +89,11 @@
8989
9090
# define the sqlite shell files, which need special flags on compile
9191
SQLITESHELLSRC=shell.c
9292
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
9393
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94
-SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob
94
+SQLITESHELLDEFINES=-Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
9595
9696
# define the th scripting files, which need special flags on compile
9797
THSRC=th.c th_lang.c
9898
ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
9999
THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
100100
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -89,11 +89,11 @@
89
90 # define the sqlite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob
95
96 # define the th scripting files, which need special flags on compile
97 THSRC=th.c th_lang.c
98 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
99 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
100
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -89,11 +89,11 @@
89
90 # define the sqlite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
95
96 # define the th scripting files, which need special flags on compile
97 THSRC=th.c th_lang.c
98 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
99 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
100
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -66,11 +66,11 @@
6666
6767
version$E: $B\src\mkversion.c
6868
$(BCC) -o$@ $**
6969
7070
$(OBJDIR)\shell$O : $(SRCDIR)\shell.c
71
- $(TCC) -o$@ -c -Dmain=sqlite3_shell $(SQLITE_OPTIONS) $**
71
+ $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
7272
7373
$(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
7474
$(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
7575
7676
$(OBJDIR)\th$O : $(SRCDIR)\th.c
7777
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -66,11 +66,11 @@
66
67 version$E: $B\src\mkversion.c
68 $(BCC) -o$@ $**
69
70 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
71 $(TCC) -o$@ -c -Dmain=sqlite3_shell $(SQLITE_OPTIONS) $**
72
73 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
74 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
75
76 $(OBJDIR)\th$O : $(SRCDIR)\th.c
77
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -66,11 +66,11 @@
66
67 version$E: $B\src\mkversion.c
68 $(BCC) -o$@ $**
69
70 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
71 $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
72
73 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
74 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
75
76 $(OBJDIR)\th$O : $(SRCDIR)\th.c
77
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1693,11 +1693,11 @@
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
16971697
$(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698
- $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1698
+ $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
16991699
17001700
$(OBJDIR)/th.o: $(SRCDIR)/th.c
17011701
$(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
17021702
17031703
$(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
17041704
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1693,11 +1693,11 @@
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
1697 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698 $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1699
1700 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1701 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1702
1703 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1704
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1693,11 +1693,11 @@
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
1697 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698 $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1699
1700 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1701 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1702
1703 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1704
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -1693,11 +1693,11 @@
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
16971697
$(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698
- $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1698
+ $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
16991699
17001700
$(OBJDIR)/th.o: $(SRCDIR)/th.c
17011701
$(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
17021702
17031703
$(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
17041704
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -1693,11 +1693,11 @@
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
1697 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698 $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1699
1700 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1701 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1702
1703 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1704
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -1693,11 +1693,11 @@
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
1697 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698 $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1699
1700 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1701 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1702
1703 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1704
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -440,11 +440,11 @@
440440
441441
mkversion$E: $B\src\mkversion.c
442442
$(BCC) $**
443443
444444
$(OX)\shell$O : $(SRCDIR)\shell.c
445
- $(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
445
+ $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
446446
447447
$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
448448
$(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
449449
450450
$(OX)\th$O : $(SRCDIR)\th.c
451451
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -440,11 +440,11 @@
440
441 mkversion$E: $B\src\mkversion.c
442 $(BCC) $**
443
444 $(OX)\shell$O : $(SRCDIR)\shell.c
445 $(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
446
447 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
448 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
449
450 $(OX)\th$O : $(SRCDIR)\th.c
451
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -440,11 +440,11 @@
440
441 mkversion$E: $B\src\mkversion.c
442 $(BCC) $**
443
444 $(OX)\shell$O : $(SRCDIR)\shell.c
445 $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
446
447 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
448 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
449
450 $(OX)\th$O : $(SRCDIR)\th.c
451
--- www/changes.wiki
+++ www/changes.wiki
@@ -18,10 +18,21 @@
1818
supply REQUEST_URI.
1919
* Add options --dirsonly, --emptydirs, and --allckouts to the
2020
"[/help?cmd=clean | fossil clean]" command.
2121
* Ten-fold performance improvement in large "fossil blame" or
2222
"fossil annotate" commands.
23
+ * Add option -W|--width and --offset to "[/help?cmd=timeline | fossil timeline]"
24
+ and "[/help?cmd=finfo | fossil finfo]" commands.
25
+ * Option -n|--limit of "[/help?cmd=timeline | fossil timeline]" now
26
+ specifies the number of entries, just like all other commands which
27
+ have the -n|--limit option. The various timeline-related functions
28
+ now output "--- ?? limit (??) reached ---" at the end whenever
29
+ appropriate. Use "-n 0" if no limit is desired.
30
+ * Fix handling of password embedded in Fossil URL.
31
+ * New --once option to [/help?cmd=clone | fossil clone] command which does
32
+ not store the URL or password when cloning.
33
+ * Modify [/help?cmd=ui | fossil ui] to respect "default user" in open repository.
2334
2435
<h2>Changes For Version 1.27 (2013-09-11)</h2>
2536
* Enhance the [/help?cmd=changes | fossil changes],
2637
[/help?cmd=clean | fossil clean], [/help?cmd=extras | fossil extras],
2738
[/help?cmd=ls | fossil ls] and [/help?cmd=status | fossil status] commands
2839
--- www/changes.wiki
+++ www/changes.wiki
@@ -18,10 +18,21 @@
18 supply REQUEST_URI.
19 * Add options --dirsonly, --emptydirs, and --allckouts to the
20 "[/help?cmd=clean | fossil clean]" command.
21 * Ten-fold performance improvement in large "fossil blame" or
22 "fossil annotate" commands.
 
 
 
 
 
 
 
 
 
 
 
23
24 <h2>Changes For Version 1.27 (2013-09-11)</h2>
25 * Enhance the [/help?cmd=changes | fossil changes],
26 [/help?cmd=clean | fossil clean], [/help?cmd=extras | fossil extras],
27 [/help?cmd=ls | fossil ls] and [/help?cmd=status | fossil status] commands
28
--- www/changes.wiki
+++ www/changes.wiki
@@ -18,10 +18,21 @@
18 supply REQUEST_URI.
19 * Add options --dirsonly, --emptydirs, and --allckouts to the
20 "[/help?cmd=clean | fossil clean]" command.
21 * Ten-fold performance improvement in large "fossil blame" or
22 "fossil annotate" commands.
23 * Add option -W|--width and --offset to "[/help?cmd=timeline | fossil timeline]"
24 and "[/help?cmd=finfo | fossil finfo]" commands.
25 * Option -n|--limit of "[/help?cmd=timeline | fossil timeline]" now
26 specifies the number of entries, just like all other commands which
27 have the -n|--limit option. The various timeline-related functions
28 now output "--- ?? limit (??) reached ---" at the end whenever
29 appropriate. Use "-n 0" if no limit is desired.
30 * Fix handling of password embedded in Fossil URL.
31 * New --once option to [/help?cmd=clone | fossil clone] command which does
32 not store the URL or password when cloning.
33 * Modify [/help?cmd=ui | fossil ui] to respect "default user" in open repository.
34
35 <h2>Changes For Version 1.27 (2013-09-11)</h2>
36 * Enhance the [/help?cmd=changes | fossil changes],
37 [/help?cmd=clean | fossil clean], [/help?cmd=extras | fossil extras],
38 [/help?cmd=ls | fossil ls] and [/help?cmd=status | fossil status] commands
39
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -220,11 +220,11 @@
220220
date/time stamp. ([./checkin_names.wiki | more info])
221221
If you omit
222222
the <i>VERSION</i>, then fossil moves you to the
223223
latest version of the branch your are currently on.</p>
224224
225
- <p>The default behaviors is for [./concepts.wiki#workflow|autosync] to
225
+ <p>The default behavior is for [./concepts.wiki#workflow|autosync] to
226226
be turned on. That means that a [/help/pull|pull] automatically occurs
227227
when you run [/help/update|update] and a [/help/push|push] happens
228228
automatically after you [/help/commit|commit]. So in normal practice,
229229
the push, pull, and sync commands are rarely used. But it is important
230230
to know about them, all the same.</p>
231231
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -220,11 +220,11 @@
220 date/time stamp. ([./checkin_names.wiki | more info])
221 If you omit
222 the <i>VERSION</i>, then fossil moves you to the
223 latest version of the branch your are currently on.</p>
224
225 <p>The default behaviors is for [./concepts.wiki#workflow|autosync] to
226 be turned on. That means that a [/help/pull|pull] automatically occurs
227 when you run [/help/update|update] and a [/help/push|push] happens
228 automatically after you [/help/commit|commit]. So in normal practice,
229 the push, pull, and sync commands are rarely used. But it is important
230 to know about them, all the same.</p>
231
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -220,11 +220,11 @@
220 date/time stamp. ([./checkin_names.wiki | more info])
221 If you omit
222 the <i>VERSION</i>, then fossil moves you to the
223 latest version of the branch your are currently on.</p>
224
225 <p>The default behavior is for [./concepts.wiki#workflow|autosync] to
226 be turned on. That means that a [/help/pull|pull] automatically occurs
227 when you run [/help/update|update] and a [/help/push|push] happens
228 automatically after you [/help/commit|commit]. So in normal practice,
229 the push, pull, and sync commands are rarely used. But it is important
230 to know about them, all the same.</p>
231

Keyboard Shortcuts

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