Fossil SCM

Merge in latest fixes/development from trunk.

andybradford 2014-02-27 15:40 http-auth merge
Commit 1fb468edf7f46969073f71023def256debc1a1c0
+11 -11
--- auto.def
+++ auto.def
@@ -89,21 +89,10 @@
8989
if {[opt-bool static]} {
9090
# XXX: This will not work on all systems.
9191
define-append EXTRA_LDFLAGS -static
9292
}
9393
94
-# Check for zlib, using the given location if specified
95
-set zlibpath [opt-val with-zlib]
96
-if {$zlibpath ne ""} {
97
- cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
98
- define-append EXTRA_CFLAGS -I$zlibpath
99
- define-append EXTRA_LDFLAGS -L$zlibpath
100
-}
101
-if {![cc-check-includes zlib.h] || ![cc-check-function-in-lib inflateEnd z]} {
102
- user-error "zlib not found please install it or specify the location with --with-zlib"
103
-}
104
-
10594
set tclpath [opt-val with-tcl]
10695
if {$tclpath ne ""} {
10796
set tclprivatestubs [opt-bool with-tcl-private-stubs]
10897
# Note parse-tclconfig-sh is in autosetup/local.tcl
10998
if {$tclpath eq "1"} {
@@ -226,10 +215,21 @@
226215
}
227216
} else {
228217
user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
229218
}
230219
}
220
+
221
+# Check for zlib, using the given location if specified
222
+set zlibpath [opt-val with-zlib]
223
+if {$zlibpath ne ""} {
224
+ cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
225
+ define-append EXTRA_CFLAGS -I$zlibpath
226
+ define-append EXTRA_LDFLAGS -L$zlibpath
227
+}
228
+if {![cc-check-includes zlib.h] || ![cc-check-function-in-lib inflateEnd z]} {
229
+ user-error "zlib not found please install it or specify the location with --with-zlib"
230
+}
231231
232232
if {[opt-bool lineedit]} {
233233
# Need readline-compatible line editing
234234
cc-with {-includes stdio.h} {
235235
if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
236236
--- auto.def
+++ auto.def
@@ -89,21 +89,10 @@
89 if {[opt-bool static]} {
90 # XXX: This will not work on all systems.
91 define-append EXTRA_LDFLAGS -static
92 }
93
94 # Check for zlib, using the given location if specified
95 set zlibpath [opt-val with-zlib]
96 if {$zlibpath ne ""} {
97 cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
98 define-append EXTRA_CFLAGS -I$zlibpath
99 define-append EXTRA_LDFLAGS -L$zlibpath
100 }
101 if {![cc-check-includes zlib.h] || ![cc-check-function-in-lib inflateEnd z]} {
102 user-error "zlib not found please install it or specify the location with --with-zlib"
103 }
104
105 set tclpath [opt-val with-tcl]
106 if {$tclpath ne ""} {
107 set tclprivatestubs [opt-bool with-tcl-private-stubs]
108 # Note parse-tclconfig-sh is in autosetup/local.tcl
109 if {$tclpath eq "1"} {
@@ -226,10 +215,21 @@
226 }
227 } else {
228 user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
229 }
230 }
 
 
 
 
 
 
 
 
 
 
 
231
232 if {[opt-bool lineedit]} {
233 # Need readline-compatible line editing
234 cc-with {-includes stdio.h} {
235 if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
236
--- auto.def
+++ auto.def
@@ -89,21 +89,10 @@
89 if {[opt-bool static]} {
90 # XXX: This will not work on all systems.
91 define-append EXTRA_LDFLAGS -static
92 }
93
 
 
 
 
 
 
 
 
 
 
 
94 set tclpath [opt-val with-tcl]
95 if {$tclpath ne ""} {
96 set tclprivatestubs [opt-bool with-tcl-private-stubs]
97 # Note parse-tclconfig-sh is in autosetup/local.tcl
98 if {$tclpath eq "1"} {
@@ -226,10 +215,21 @@
215 }
216 } else {
217 user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
218 }
219 }
220
221 # Check for zlib, using the given location if specified
222 set zlibpath [opt-val with-zlib]
223 if {$zlibpath ne ""} {
224 cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
225 define-append EXTRA_CFLAGS -I$zlibpath
226 define-append EXTRA_LDFLAGS -L$zlibpath
227 }
228 if {![cc-check-includes zlib.h] || ![cc-check-function-in-lib inflateEnd z]} {
229 user-error "zlib not found please install it or specify the location with --with-zlib"
230 }
231
232 if {[opt-bool lineedit]} {
233 # Need readline-compatible line editing
234 cc-with {-includes stdio.h} {
235 if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
236
+22
--- src/add.c
+++ src/add.c
@@ -221,19 +221,24 @@
221221
** The --ignore and --clean options are comma-separate lists of glob patterns
222222
** for files to be excluded. Example: '*.o,*.obj,*.exe' If the --ignore
223223
** option does not appear on the command line then the "ignore-glob" setting
224224
** is used. If the --clean option does not appear on the command line then
225225
** the "clean-glob" setting is used.
226
+**
227
+** If files are attempted to be added explicitly on the command line which
228
+** match "ignore-glob", a confirmation is asked first. This can be prevented
229
+** using the -f|--force option.
226230
**
227231
** The --case-sensitive option determines whether or not filenames should
228232
** be treated case sensitive or not. If the option is not given, the default
229233
** depends on the global setting, or the operating system default, if not set.
230234
**
231235
** Options:
232236
**
233237
** --case-sensitive <BOOL> override case-sensitive setting
234238
** --dotfiles include files beginning with a dot (".")
239
+** -f|--force Add files without prompting
235240
** --ignore <CSG> ignore files matching patterns from the
236241
** comma separated list of glob patterns.
237242
** --clean <CSG> also ignore files matching patterns from
238243
** the comma separated list of glob patterns.
239244
**
@@ -245,13 +250,15 @@
245250
int nRoot; /* Full path characters in g.zLocalRoot */
246251
const char *zCleanFlag; /* The --clean option or clean-glob setting */
247252
const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
248253
Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
249254
unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
255
+ int forceFlag;
250256
251257
zCleanFlag = find_option("clean",0,1);
252258
zIgnoreFlag = find_option("ignore",0,1);
259
+ forceFlag = find_option("force","f",0)!=0;
253260
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
254261
capture_case_sensitive_option();
255262
db_must_be_within_tree();
256263
if( zCleanFlag==0 ){
257264
zCleanFlag = db_get("clean-glob", 0);
@@ -287,10 +294,25 @@
287294
fossil_warning("not found: %s", zName);
288295
}else if( file_access(zName, R_OK) ){
289296
fossil_fatal("cannot open %s", zName);
290297
}else{
291298
char *zTreeName = &zName[nRoot];
299
+ if( !forceFlag && glob_match(pIgnore, zTreeName) ){
300
+ Blob ans;
301
+ char cReply;
302
+ char *prompt = mprintf("file \"%s\" matches \"ignore-glob\". "
303
+ "Add it (a=all/y/N)? ", zTreeName);
304
+ prompt_user(prompt, &ans);
305
+ cReply = blob_str(&ans)[0];
306
+ blob_reset(&ans);
307
+ if( cReply=='a' || cReply=='A' ){
308
+ forceFlag = 1;
309
+ }else if( cReply!='y' && cReply!='Y' ){
310
+ blob_reset(&fullName);
311
+ continue;
312
+ }
313
+ }
292314
db_multi_exec(
293315
"INSERT OR IGNORE INTO sfile(x) VALUES(%Q)",
294316
zTreeName
295317
);
296318
}
297319
--- src/add.c
+++ src/add.c
@@ -221,19 +221,24 @@
221 ** The --ignore and --clean options are comma-separate lists of glob patterns
222 ** for files to be excluded. Example: '*.o,*.obj,*.exe' If the --ignore
223 ** option does not appear on the command line then the "ignore-glob" setting
224 ** is used. If the --clean option does not appear on the command line then
225 ** the "clean-glob" setting is used.
 
 
 
 
226 **
227 ** The --case-sensitive option determines whether or not filenames should
228 ** be treated case sensitive or not. If the option is not given, the default
229 ** depends on the global setting, or the operating system default, if not set.
230 **
231 ** Options:
232 **
233 ** --case-sensitive <BOOL> override case-sensitive setting
234 ** --dotfiles include files beginning with a dot (".")
 
235 ** --ignore <CSG> ignore files matching patterns from the
236 ** comma separated list of glob patterns.
237 ** --clean <CSG> also ignore files matching patterns from
238 ** the comma separated list of glob patterns.
239 **
@@ -245,13 +250,15 @@
245 int nRoot; /* Full path characters in g.zLocalRoot */
246 const char *zCleanFlag; /* The --clean option or clean-glob setting */
247 const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
248 Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
249 unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
 
250
251 zCleanFlag = find_option("clean",0,1);
252 zIgnoreFlag = find_option("ignore",0,1);
 
253 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
254 capture_case_sensitive_option();
255 db_must_be_within_tree();
256 if( zCleanFlag==0 ){
257 zCleanFlag = db_get("clean-glob", 0);
@@ -287,10 +294,25 @@
287 fossil_warning("not found: %s", zName);
288 }else if( file_access(zName, R_OK) ){
289 fossil_fatal("cannot open %s", zName);
290 }else{
291 char *zTreeName = &zName[nRoot];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292 db_multi_exec(
293 "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)",
294 zTreeName
295 );
296 }
297
--- src/add.c
+++ src/add.c
@@ -221,19 +221,24 @@
221 ** The --ignore and --clean options are comma-separate lists of glob patterns
222 ** for files to be excluded. Example: '*.o,*.obj,*.exe' If the --ignore
223 ** option does not appear on the command line then the "ignore-glob" setting
224 ** is used. If the --clean option does not appear on the command line then
225 ** the "clean-glob" setting is used.
226 **
227 ** If files are attempted to be added explicitly on the command line which
228 ** match "ignore-glob", a confirmation is asked first. This can be prevented
229 ** using the -f|--force option.
230 **
231 ** The --case-sensitive option determines whether or not filenames should
232 ** be treated case sensitive or not. If the option is not given, the default
233 ** depends on the global setting, or the operating system default, if not set.
234 **
235 ** Options:
236 **
237 ** --case-sensitive <BOOL> override case-sensitive setting
238 ** --dotfiles include files beginning with a dot (".")
239 ** -f|--force Add files without prompting
240 ** --ignore <CSG> ignore files matching patterns from the
241 ** comma separated list of glob patterns.
242 ** --clean <CSG> also ignore files matching patterns from
243 ** the comma separated list of glob patterns.
244 **
@@ -245,13 +250,15 @@
250 int nRoot; /* Full path characters in g.zLocalRoot */
251 const char *zCleanFlag; /* The --clean option or clean-glob setting */
252 const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
253 Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
254 unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
255 int forceFlag;
256
257 zCleanFlag = find_option("clean",0,1);
258 zIgnoreFlag = find_option("ignore",0,1);
259 forceFlag = find_option("force","f",0)!=0;
260 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
261 capture_case_sensitive_option();
262 db_must_be_within_tree();
263 if( zCleanFlag==0 ){
264 zCleanFlag = db_get("clean-glob", 0);
@@ -287,10 +294,25 @@
294 fossil_warning("not found: %s", zName);
295 }else if( file_access(zName, R_OK) ){
296 fossil_fatal("cannot open %s", zName);
297 }else{
298 char *zTreeName = &zName[nRoot];
299 if( !forceFlag && glob_match(pIgnore, zTreeName) ){
300 Blob ans;
301 char cReply;
302 char *prompt = mprintf("file \"%s\" matches \"ignore-glob\". "
303 "Add it (a=all/y/N)? ", zTreeName);
304 prompt_user(prompt, &ans);
305 cReply = blob_str(&ans)[0];
306 blob_reset(&ans);
307 if( cReply=='a' || cReply=='A' ){
308 forceFlag = 1;
309 }else if( cReply!='y' && cReply!='Y' ){
310 blob_reset(&fullName);
311 continue;
312 }
313 }
314 db_multi_exec(
315 "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)",
316 zTreeName
317 );
318 }
319
--- src/branch.c
+++ src/branch.c
@@ -140,11 +140,10 @@
140140
md5sum_blob(&branch, &mcksum);
141141
blob_appendf(&branch, "Z %b\n", &mcksum);
142142
if( !noSign && clearsign(&branch, &branch) ){
143143
Blob ans;
144144
char cReply;
145
- blob_zero(&ans);
146145
prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
147146
cReply = blob_str(&ans)[0];
148147
if( cReply!='y' && cReply!='Y'){
149148
db_end_transaction(1);
150149
fossil_exit(1);
151150
--- src/branch.c
+++ src/branch.c
@@ -140,11 +140,10 @@
140 md5sum_blob(&branch, &mcksum);
141 blob_appendf(&branch, "Z %b\n", &mcksum);
142 if( !noSign && clearsign(&branch, &branch) ){
143 Blob ans;
144 char cReply;
145 blob_zero(&ans);
146 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
147 cReply = blob_str(&ans)[0];
148 if( cReply!='y' && cReply!='Y'){
149 db_end_transaction(1);
150 fossil_exit(1);
151
--- src/branch.c
+++ src/branch.c
@@ -140,11 +140,10 @@
140 md5sum_blob(&branch, &mcksum);
141 blob_appendf(&branch, "Z %b\n", &mcksum);
142 if( !noSign && clearsign(&branch, &branch) ){
143 Blob ans;
144 char cReply;
 
145 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
146 cReply = blob_str(&ans)[0];
147 if( cReply!='y' && cReply!='Y'){
148 db_end_transaction(1);
149 fossil_exit(1);
150
+3 -10
--- src/checkin.c
+++ src/checkin.c
@@ -600,11 +600,10 @@
600600
if( !allFileFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
601601
Blob ans;
602602
char cReply;
603603
char *prompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
604604
zName+nRoot);
605
- blob_zero(&ans);
606605
prompt_user(prompt, &ans);
607606
cReply = blob_str(&ans)[0];
608607
if( cReply=='a' || cReply=='A' ){
609608
allFileFlag = 1;
610609
}else if( cReply!='y' && cReply!='Y' ){
@@ -642,11 +641,10 @@
642641
if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
643642
Blob ans;
644643
char cReply;
645644
char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ",
646645
zName+nRoot);
647
- blob_zero(&ans);
648646
prompt_user(prompt, &ans);
649647
cReply = blob_str(&ans)[0];
650648
if( cReply=='a' || cReply=='A' ){
651649
allDirFlag = 1;
652650
}else if( cReply!='y' && cReply!='Y' ){
@@ -1288,11 +1286,10 @@
12881286
}
12891287
zWarning = "Unicode";
12901288
zDisable = "\"encoding-glob\" setting";
12911289
}
12921290
file_relative_name(zFilename, &fname, 0);
1293
- blob_zero(&ans);
12941291
zMsg = mprintf(
12951292
"%s contains %s. Use --no-warnings or the %s to disable this warning.\n"
12961293
"Commit anyhow (a=all/%sy/N)? ",
12971294
blob_str(&fname), zWarning, zDisable, zConvert);
12981295
prompt_user(zMsg, &ans);
@@ -1520,20 +1517,21 @@
15201517
forceBaseline = 1;
15211518
}
15221519
15231520
/* Get the ID of the parent manifest artifact */
15241521
vid = db_lget_int("checkout", 0);
1525
- if( content_is_private(vid) ){
1522
+ if( vid==0 ){
1523
+ useCksum = 1;
1524
+ }else if( content_is_private(vid) ){
15261525
g.markPrivate = 1;
15271526
}
15281527
15291528
/*
15301529
** Autosync if autosync is enabled and this is not a private check-in.
15311530
*/
15321531
if( !g.markPrivate ){
15331532
if( autosync(SYNC_PULL) ){
1534
- blob_zero(&ans);
15351533
prompt_user("continue in spite of sync failure (y/N)? ", &ans);
15361534
cReply = blob_str(&ans)[0];
15371535
if( cReply!='y' && cReply!='Y' ){
15381536
fossil_exit(1);
15391537
}
@@ -1542,11 +1540,10 @@
15421540
15431541
/* Require confirmation to continue with the check-in if there is
15441542
** clock skew
15451543
*/
15461544
if( g.clockSkewSeen ){
1547
- blob_zero(&ans);
15481545
prompt_user("continue in spite of time skew (y/N)? ", &ans);
15491546
cReply = blob_str(&ans)[0];
15501547
if( cReply!='y' && cReply!='Y' ){
15511548
fossil_exit(1);
15521549
}
@@ -1561,11 +1558,10 @@
15611558
** array is allocated to contain the "id" field from the vfile table
15621559
** for each file to be committed. Or, if aCommitFile is NULL, all files
15631560
** should be committed.
15641561
*/
15651562
if( select_commit_files() ){
1566
- blob_zero(&ans);
15671563
prompt_user("continue (y/N)? ", &ans);
15681564
cReply = blob_str(&ans)[0];
15691565
if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
15701566
}
15711567
isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0 OR id<-2");
@@ -1662,20 +1658,18 @@
16621658
blob_zero(&comment);
16631659
}else{
16641660
char *zInit = db_text(0, "SELECT value FROM vvar WHERE name='ci-comment'");
16651661
prepare_commit_comment(&comment, zInit, &sCiInfo, vid);
16661662
if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
1667
- blob_zero(&ans);
16681663
prompt_user("unchanged check-in comment. continue (y/N)? ", &ans);
16691664
cReply = blob_str(&ans)[0];
16701665
if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
16711666
}
16721667
free(zInit);
16731668
}
16741669
if( blob_size(&comment)==0 ){
16751670
if( !dryRunFlag ){
1676
- blob_zero(&ans);
16771671
prompt_user("empty check-in comment. continue (y/N)? ", &ans);
16781672
cReply = blob_str(&ans)[0];
16791673
if( cReply!='y' && cReply!='Y' ){
16801674
fossil_exit(1);
16811675
}
@@ -1804,11 +1798,10 @@
18041798
}else if( forceDelta ){
18051799
fossil_fatal("unable to find a baseline-manifest for the delta");
18061800
}
18071801
}
18081802
if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
1809
- blob_zero(&ans);
18101803
prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
18111804
cReply = blob_str(&ans)[0];
18121805
if( cReply!='y' && cReply!='Y' ){
18131806
fossil_exit(1);
18141807
}
18151808
--- src/checkin.c
+++ src/checkin.c
@@ -600,11 +600,10 @@
600 if( !allFileFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
601 Blob ans;
602 char cReply;
603 char *prompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
604 zName+nRoot);
605 blob_zero(&ans);
606 prompt_user(prompt, &ans);
607 cReply = blob_str(&ans)[0];
608 if( cReply=='a' || cReply=='A' ){
609 allFileFlag = 1;
610 }else if( cReply!='y' && cReply!='Y' ){
@@ -642,11 +641,10 @@
642 if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
643 Blob ans;
644 char cReply;
645 char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ",
646 zName+nRoot);
647 blob_zero(&ans);
648 prompt_user(prompt, &ans);
649 cReply = blob_str(&ans)[0];
650 if( cReply=='a' || cReply=='A' ){
651 allDirFlag = 1;
652 }else if( cReply!='y' && cReply!='Y' ){
@@ -1288,11 +1286,10 @@
1288 }
1289 zWarning = "Unicode";
1290 zDisable = "\"encoding-glob\" setting";
1291 }
1292 file_relative_name(zFilename, &fname, 0);
1293 blob_zero(&ans);
1294 zMsg = mprintf(
1295 "%s contains %s. Use --no-warnings or the %s to disable this warning.\n"
1296 "Commit anyhow (a=all/%sy/N)? ",
1297 blob_str(&fname), zWarning, zDisable, zConvert);
1298 prompt_user(zMsg, &ans);
@@ -1520,20 +1517,21 @@
1520 forceBaseline = 1;
1521 }
1522
1523 /* Get the ID of the parent manifest artifact */
1524 vid = db_lget_int("checkout", 0);
1525 if( content_is_private(vid) ){
 
 
1526 g.markPrivate = 1;
1527 }
1528
1529 /*
1530 ** Autosync if autosync is enabled and this is not a private check-in.
1531 */
1532 if( !g.markPrivate ){
1533 if( autosync(SYNC_PULL) ){
1534 blob_zero(&ans);
1535 prompt_user("continue in spite of sync failure (y/N)? ", &ans);
1536 cReply = blob_str(&ans)[0];
1537 if( cReply!='y' && cReply!='Y' ){
1538 fossil_exit(1);
1539 }
@@ -1542,11 +1540,10 @@
1542
1543 /* Require confirmation to continue with the check-in if there is
1544 ** clock skew
1545 */
1546 if( g.clockSkewSeen ){
1547 blob_zero(&ans);
1548 prompt_user("continue in spite of time skew (y/N)? ", &ans);
1549 cReply = blob_str(&ans)[0];
1550 if( cReply!='y' && cReply!='Y' ){
1551 fossil_exit(1);
1552 }
@@ -1561,11 +1558,10 @@
1561 ** array is allocated to contain the "id" field from the vfile table
1562 ** for each file to be committed. Or, if aCommitFile is NULL, all files
1563 ** should be committed.
1564 */
1565 if( select_commit_files() ){
1566 blob_zero(&ans);
1567 prompt_user("continue (y/N)? ", &ans);
1568 cReply = blob_str(&ans)[0];
1569 if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
1570 }
1571 isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0 OR id<-2");
@@ -1662,20 +1658,18 @@
1662 blob_zero(&comment);
1663 }else{
1664 char *zInit = db_text(0, "SELECT value FROM vvar WHERE name='ci-comment'");
1665 prepare_commit_comment(&comment, zInit, &sCiInfo, vid);
1666 if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
1667 blob_zero(&ans);
1668 prompt_user("unchanged check-in comment. continue (y/N)? ", &ans);
1669 cReply = blob_str(&ans)[0];
1670 if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
1671 }
1672 free(zInit);
1673 }
1674 if( blob_size(&comment)==0 ){
1675 if( !dryRunFlag ){
1676 blob_zero(&ans);
1677 prompt_user("empty check-in comment. continue (y/N)? ", &ans);
1678 cReply = blob_str(&ans)[0];
1679 if( cReply!='y' && cReply!='Y' ){
1680 fossil_exit(1);
1681 }
@@ -1804,11 +1798,10 @@
1804 }else if( forceDelta ){
1805 fossil_fatal("unable to find a baseline-manifest for the delta");
1806 }
1807 }
1808 if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
1809 blob_zero(&ans);
1810 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
1811 cReply = blob_str(&ans)[0];
1812 if( cReply!='y' && cReply!='Y' ){
1813 fossil_exit(1);
1814 }
1815
--- src/checkin.c
+++ src/checkin.c
@@ -600,11 +600,10 @@
600 if( !allFileFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
601 Blob ans;
602 char cReply;
603 char *prompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
604 zName+nRoot);
 
605 prompt_user(prompt, &ans);
606 cReply = blob_str(&ans)[0];
607 if( cReply=='a' || cReply=='A' ){
608 allFileFlag = 1;
609 }else if( cReply!='y' && cReply!='Y' ){
@@ -642,11 +641,10 @@
641 if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
642 Blob ans;
643 char cReply;
644 char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ",
645 zName+nRoot);
 
646 prompt_user(prompt, &ans);
647 cReply = blob_str(&ans)[0];
648 if( cReply=='a' || cReply=='A' ){
649 allDirFlag = 1;
650 }else if( cReply!='y' && cReply!='Y' ){
@@ -1288,11 +1286,10 @@
1286 }
1287 zWarning = "Unicode";
1288 zDisable = "\"encoding-glob\" setting";
1289 }
1290 file_relative_name(zFilename, &fname, 0);
 
1291 zMsg = mprintf(
1292 "%s contains %s. Use --no-warnings or the %s to disable this warning.\n"
1293 "Commit anyhow (a=all/%sy/N)? ",
1294 blob_str(&fname), zWarning, zDisable, zConvert);
1295 prompt_user(zMsg, &ans);
@@ -1520,20 +1517,21 @@
1517 forceBaseline = 1;
1518 }
1519
1520 /* Get the ID of the parent manifest artifact */
1521 vid = db_lget_int("checkout", 0);
1522 if( vid==0 ){
1523 useCksum = 1;
1524 }else if( content_is_private(vid) ){
1525 g.markPrivate = 1;
1526 }
1527
1528 /*
1529 ** Autosync if autosync is enabled and this is not a private check-in.
1530 */
1531 if( !g.markPrivate ){
1532 if( autosync(SYNC_PULL) ){
 
1533 prompt_user("continue in spite of sync failure (y/N)? ", &ans);
1534 cReply = blob_str(&ans)[0];
1535 if( cReply!='y' && cReply!='Y' ){
1536 fossil_exit(1);
1537 }
@@ -1542,11 +1540,10 @@
1540
1541 /* Require confirmation to continue with the check-in if there is
1542 ** clock skew
1543 */
1544 if( g.clockSkewSeen ){
 
1545 prompt_user("continue in spite of time skew (y/N)? ", &ans);
1546 cReply = blob_str(&ans)[0];
1547 if( cReply!='y' && cReply!='Y' ){
1548 fossil_exit(1);
1549 }
@@ -1561,11 +1558,10 @@
1558 ** array is allocated to contain the "id" field from the vfile table
1559 ** for each file to be committed. Or, if aCommitFile is NULL, all files
1560 ** should be committed.
1561 */
1562 if( select_commit_files() ){
 
1563 prompt_user("continue (y/N)? ", &ans);
1564 cReply = blob_str(&ans)[0];
1565 if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
1566 }
1567 isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0 OR id<-2");
@@ -1662,20 +1658,18 @@
1658 blob_zero(&comment);
1659 }else{
1660 char *zInit = db_text(0, "SELECT value FROM vvar WHERE name='ci-comment'");
1661 prepare_commit_comment(&comment, zInit, &sCiInfo, vid);
1662 if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
 
1663 prompt_user("unchanged check-in comment. continue (y/N)? ", &ans);
1664 cReply = blob_str(&ans)[0];
1665 if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
1666 }
1667 free(zInit);
1668 }
1669 if( blob_size(&comment)==0 ){
1670 if( !dryRunFlag ){
 
1671 prompt_user("empty check-in comment. continue (y/N)? ", &ans);
1672 cReply = blob_str(&ans)[0];
1673 if( cReply!='y' && cReply!='Y' ){
1674 fossil_exit(1);
1675 }
@@ -1804,11 +1798,10 @@
1798 }else if( forceDelta ){
1799 fossil_fatal("unable to find a baseline-manifest for the delta");
1800 }
1801 }
1802 if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
 
1803 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
1804 cReply = blob_str(&ans)[0];
1805 if( cReply!='y' && cReply!='Y' ){
1806 fossil_exit(1);
1807 }
1808
+60 -7
--- src/config.h
+++ src/config.h
@@ -62,30 +62,83 @@
6262
# include <sys/types.h>
6363
# include <signal.h>
6464
# include <pwd.h>
6565
#endif
6666
67
+/*
68
+** Utility macro to wrap an argument with double quotes.
69
+*/
70
+#if !defined(COMPILER_STRINGIFY)
71
+# define COMPILER_STRINGIFY(x) COMPILER_STRINGIFY1(x)
72
+# define COMPILER_STRINGIFY1(x) #x
73
+#endif
74
+
6775
/*
6876
** Define the compiler variant, used to compile the project
6977
*/
7078
#if !defined(COMPILER_NAME)
7179
# if defined(__DMC__)
72
-# define COMPILER_NAME "dmc"
80
+# if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
81
+# define COMPILER_NAME "dmc-" COMPILER_VERSION
82
+# else
83
+# define COMPILER_NAME "dmc"
84
+# endif
7385
# elif defined(__POCC__)
7486
# if defined(_M_X64)
75
-# define COMPILER_NAME "pellesc64"
87
+# if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
88
+# define COMPILER_NAME "pellesc64-" COMPILER_VERSION
89
+# else
90
+# define COMPILER_NAME "pellesc64"
91
+# endif
7692
# else
77
-# define COMPILER_NAME "pellesc32"
93
+# if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
94
+# define COMPILER_NAME "pellesc32-" COMPILER_VERSION
95
+# else
96
+# define COMPILER_NAME "pellesc32"
97
+# endif
7898
# endif
7999
# elif defined(_MSC_VER)
80
-# define COMPILER_NAME "msc"
100
+# if !defined(COMPILER_VERSION)
101
+# define COMPILER_VERSION COMPILER_STRINGIFY(_MSC_VER)
102
+# endif
103
+# if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
104
+# define COMPILER_NAME "msc-" COMPILER_VERSION
105
+# else
106
+# define COMPILER_NAME "msc"
107
+# endif
81108
# elif defined(__MINGW32__)
82
-# define COMPILER_NAME "mingw32"
109
+# if !defined(COMPILER_VERSION)
110
+# if defined(__MINGW32_VERSION)
111
+# if defined(__GNUC__)
112
+# if defined(__VERSION__)
113
+# define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION) "-gcc-" __VERSION__
114
+# else
115
+# define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION) "-gcc"
116
+# endif
117
+# else
118
+# define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION)
119
+# endif
120
+# endif
121
+# endif
122
+# if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
123
+# define COMPILER_NAME "mingw32-" COMPILER_VERSION
124
+# else
125
+# define COMPILER_NAME "mingw32"
126
+# endif
83127
# elif defined(_WIN32)
84128
# define COMPILER_NAME "win32"
85129
# elif defined(__GNUC__)
86
-# define COMPILER_NAME "gcc-" __VERSION__
130
+# if !defined(COMPILER_VERSION)
131
+# if defined(__VERSION__)
132
+# define COMPILER_VERSION __VERSION__
133
+# endif
134
+# endif
135
+# if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
136
+# define COMPILER_NAME "gcc-" COMPILER_VERSION
137
+# else
138
+# define COMPILER_NAME "gcc"
139
+# endif
87140
# else
88141
# define COMPILER_NAME "unknown"
89142
# endif
90143
#endif
91144
@@ -123,11 +176,11 @@
123176
** The following macros are used to cast pointers to integers and
124177
** integers to pointers. The way you do this varies from one compiler
125178
** to the next, so we have developed the following set of #if statements
126179
** to generate appropriate macros for a wide range of compilers.
127180
**
128
-** The correct "ANSI" way to do this is to use the intptr_t type.
181
+** The correct "ANSI" way to do this is to use the intptr_t type.
129182
** Unfortunately, that typedef is not available on all compilers, or
130183
** if it is available, it requires an #include of specific headers
131184
** that vary from one machine to the next.
132185
*/
133186
#if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */
134187
--- src/config.h
+++ src/config.h
@@ -62,30 +62,83 @@
62 # include <sys/types.h>
63 # include <signal.h>
64 # include <pwd.h>
65 #endif
66
 
 
 
 
 
 
 
 
67 /*
68 ** Define the compiler variant, used to compile the project
69 */
70 #if !defined(COMPILER_NAME)
71 # if defined(__DMC__)
72 # define COMPILER_NAME "dmc"
 
 
 
 
73 # elif defined(__POCC__)
74 # if defined(_M_X64)
75 # define COMPILER_NAME "pellesc64"
 
 
 
 
76 # else
77 # define COMPILER_NAME "pellesc32"
 
 
 
 
78 # endif
79 # elif defined(_MSC_VER)
80 # define COMPILER_NAME "msc"
 
 
 
 
 
 
 
81 # elif defined(__MINGW32__)
82 # define COMPILER_NAME "mingw32"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83 # elif defined(_WIN32)
84 # define COMPILER_NAME "win32"
85 # elif defined(__GNUC__)
86 # define COMPILER_NAME "gcc-" __VERSION__
 
 
 
 
 
 
 
 
 
87 # else
88 # define COMPILER_NAME "unknown"
89 # endif
90 #endif
91
@@ -123,11 +176,11 @@
123 ** The following macros are used to cast pointers to integers and
124 ** integers to pointers. The way you do this varies from one compiler
125 ** to the next, so we have developed the following set of #if statements
126 ** to generate appropriate macros for a wide range of compilers.
127 **
128 ** The correct "ANSI" way to do this is to use the intptr_t type.
129 ** Unfortunately, that typedef is not available on all compilers, or
130 ** if it is available, it requires an #include of specific headers
131 ** that vary from one machine to the next.
132 */
133 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */
134
--- src/config.h
+++ src/config.h
@@ -62,30 +62,83 @@
62 # include <sys/types.h>
63 # include <signal.h>
64 # include <pwd.h>
65 #endif
66
67 /*
68 ** Utility macro to wrap an argument with double quotes.
69 */
70 #if !defined(COMPILER_STRINGIFY)
71 # define COMPILER_STRINGIFY(x) COMPILER_STRINGIFY1(x)
72 # define COMPILER_STRINGIFY1(x) #x
73 #endif
74
75 /*
76 ** Define the compiler variant, used to compile the project
77 */
78 #if !defined(COMPILER_NAME)
79 # if defined(__DMC__)
80 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
81 # define COMPILER_NAME "dmc-" COMPILER_VERSION
82 # else
83 # define COMPILER_NAME "dmc"
84 # endif
85 # elif defined(__POCC__)
86 # if defined(_M_X64)
87 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
88 # define COMPILER_NAME "pellesc64-" COMPILER_VERSION
89 # else
90 # define COMPILER_NAME "pellesc64"
91 # endif
92 # else
93 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
94 # define COMPILER_NAME "pellesc32-" COMPILER_VERSION
95 # else
96 # define COMPILER_NAME "pellesc32"
97 # endif
98 # endif
99 # elif defined(_MSC_VER)
100 # if !defined(COMPILER_VERSION)
101 # define COMPILER_VERSION COMPILER_STRINGIFY(_MSC_VER)
102 # endif
103 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
104 # define COMPILER_NAME "msc-" COMPILER_VERSION
105 # else
106 # define COMPILER_NAME "msc"
107 # endif
108 # elif defined(__MINGW32__)
109 # if !defined(COMPILER_VERSION)
110 # if defined(__MINGW32_VERSION)
111 # if defined(__GNUC__)
112 # if defined(__VERSION__)
113 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION) "-gcc-" __VERSION__
114 # else
115 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION) "-gcc"
116 # endif
117 # else
118 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION)
119 # endif
120 # endif
121 # endif
122 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
123 # define COMPILER_NAME "mingw32-" COMPILER_VERSION
124 # else
125 # define COMPILER_NAME "mingw32"
126 # endif
127 # elif defined(_WIN32)
128 # define COMPILER_NAME "win32"
129 # elif defined(__GNUC__)
130 # if !defined(COMPILER_VERSION)
131 # if defined(__VERSION__)
132 # define COMPILER_VERSION __VERSION__
133 # endif
134 # endif
135 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION)
136 # define COMPILER_NAME "gcc-" COMPILER_VERSION
137 # else
138 # define COMPILER_NAME "gcc"
139 # endif
140 # else
141 # define COMPILER_NAME "unknown"
142 # endif
143 #endif
144
@@ -123,11 +176,11 @@
176 ** The following macros are used to cast pointers to integers and
177 ** integers to pointers. The way you do this varies from one compiler
178 ** to the next, so we have developed the following set of #if statements
179 ** to generate appropriate macros for a wide range of compilers.
180 **
181 ** The correct "ANSI" way to do this is to use the intptr_t type.
182 ** Unfortunately, that typedef is not available on all compilers, or
183 ** if it is available, it requires an #include of specific headers
184 ** that vary from one machine to the next.
185 */
186 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */
187
+69 -60
--- src/db.c
+++ src/db.c
@@ -715,11 +715,11 @@
715715
*/
716716
LOCAL sqlite3 *db_open(const char *zDbName){
717717
int rc;
718718
sqlite3 *db;
719719
720
-#if defined(__CYGWIN__)
720
+#if defined(__CYGWIN__) && !defined(USE_SYSTEM_SQLITE)
721721
zDbName = fossil_utf8_to_filename(zDbName);
722722
#endif
723723
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
724724
rc = sqlite3_open_v2(
725725
zDbName, &db,
@@ -1989,23 +1989,28 @@
19891989
** If VERSION is specified then that version is checked out. Otherwise
19901990
** the latest version is checked out. No files other than "manifest"
19911991
** and "manifest.uuid" are modified if the --keep option is present.
19921992
**
19931993
** Options:
1994
+** --empty Initialize checkout as being empty, but still connected
1995
+** with the local repository. If you commit this checkout,
1996
+** it will become a new "initial" commit in the repository.
19941997
** --keep Only modify the manifest and manifest.uuid files
19951998
** --nested Allow opening a repository inside an opened checkout
19961999
**
19972000
** See also: close
19982001
*/
19992002
void cmd_open(void){
2003
+ int emptyFlag;
20002004
int keepFlag;
20012005
int allowNested;
20022006
char **oldArgv;
20032007
int oldArgc;
20042008
static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
20052009
20062010
url_proxy_options();
2011
+ emptyFlag = find_option("empty",0,0)!=0;
20072012
keepFlag = find_option("keep",0,0)!=0;
20082013
allowNested = find_option("nested",0,0)!=0;
20092014
if( g.argc!=3 && g.argc!=4 ){
20102015
usage("REPOSITORY-FILENAME ?VERSION?");
20112016
}
@@ -2030,22 +2035,24 @@
20302035
db_lset_int("checkout", 0);
20312036
oldArgv = g.argv;
20322037
oldArgc = g.argc;
20332038
azNewArgv[0] = g.argv[0];
20342039
g.argv = azNewArgv;
2035
- g.argc = 3;
2036
- if( oldArgc==4 ){
2037
- azNewArgv[g.argc-1] = oldArgv[3];
2038
- }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2039
- azNewArgv[g.argc-1] = "--latest";
2040
- }else{
2041
- azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2042
- }
2043
- if( keepFlag ){
2044
- azNewArgv[g.argc++] = "--keep";
2045
- }
2046
- checkout_cmd();
2040
+ if( !emptyFlag){
2041
+ g.argc = 3;
2042
+ if( oldArgc==4 ){
2043
+ azNewArgv[g.argc-1] = oldArgv[3];
2044
+ }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2045
+ azNewArgv[g.argc-1] = "--latest";
2046
+ }else{
2047
+ azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2048
+ }
2049
+ if( keepFlag ){
2050
+ azNewArgv[g.argc++] = "--keep";
2051
+ }
2052
+ checkout_cmd();
2053
+ }
20472054
g.argc = 2;
20482055
info_cmd();
20492056
}
20502057
20512058
/*
@@ -2101,66 +2108,68 @@
21012108
*/
21022109
#if INTERFACE
21032110
struct stControlSettings {
21042111
char const *name; /* Name of the setting */
21052112
char const *var; /* Internal variable name used by db_set() */
2106
- int width; /* Width of display. 0 for boolean values */
2113
+ int width; /* Width of display. 0 for boolean values. */
21072114
int versionable; /* Is this setting versionable? */
2115
+ int forceTextArea; /* Force using a text area for display? */
21082116
char const *def; /* Default value */
21092117
};
21102118
#endif /* INTERFACE */
21112119
struct stControlSettings const ctrlSettings[] = {
2112
- { "access-log", 0, 0, 0, "off" },
2113
- { "allow-symlinks",0, 0, 1, "off" },
2114
- { "auto-captcha", "autocaptcha", 0, 0, "on" },
2115
- { "auto-hyperlink",0, 0, 0, "on", },
2116
- { "auto-shun", 0, 0, 0, "on" },
2117
- { "autosync", 0, 0, 0, "on" },
2118
- { "binary-glob", 0, 40, 1, "" },
2119
- { "clearsign", 0, 0, 0, "off" },
2120
-#if defined(_WIN32) || defined(__CYGWIN__) || defined(__DARWIN__) || defined(__APPLE__)
2121
- { "case-sensitive",0, 0, 0, "off" },
2120
+ { "access-log", 0, 0, 0, 0, "off" },
2121
+ { "allow-symlinks", 0, 0, 1, 0, "off" },
2122
+ { "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
2123
+ { "auto-hyperlink", 0, 0, 0, 0, "on", },
2124
+ { "auto-shun", 0, 0, 0, 0, "on" },
2125
+ { "autosync", 0, 0, 0, 0, "on" },
2126
+ { "binary-glob", 0, 40, 1, 0, "" },
2127
+ { "clearsign", 0, 0, 0, 0, "off" },
2128
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(__DARWIN__) || \
2129
+ defined(__APPLE__)
2130
+ { "case-sensitive", 0, 0, 0, 0, "off" },
21222131
#else
2123
- { "case-sensitive",0, 0, 0, "on" },
2132
+ { "case-sensitive", 0, 0, 0, 0, "on" },
21242133
#endif
2125
- { "clean-glob", 0, 40, 1, "" },
2126
- { "crnl-glob", 0, 40, 1, "" },
2127
- { "default-perms", 0, 16, 0, "u" },
2128
- { "diff-binary", 0, 0, 0, "on" },
2129
- { "diff-command", 0, 40, 0, "" },
2130
- { "dont-push", 0, 0, 0, "off" },
2131
- { "editor", 0, 32, 0, "" },
2132
- { "empty-dirs", 0, 40, 1, "" },
2133
- { "encoding-glob", 0, 40, 1, "" },
2134
- { "gdiff-command", 0, 40, 0, "gdiff" },
2135
- { "gmerge-command",0, 40, 0, "" },
2136
- { "http-port", 0, 16, 0, "8080" },
2137
- { "https-login", 0, 0, 0, "off" },
2138
- { "ignore-glob", 0, 40, 1, "" },
2139
- { "keep-glob", 0, 40, 1, "" },
2140
- { "localauth", 0, 0, 0, "off" },
2141
- { "main-branch", 0, 40, 0, "trunk" },
2142
- { "manifest", 0, 0, 1, "off" },
2143
- { "max-upload", 0, 25, 0, "250000" },
2144
- { "mtime-changes", 0, 0, 0, "on" },
2145
- { "pgp-command", 0, 40, 0, "gpg --clearsign -o " },
2146
- { "proxy", 0, 32, 0, "off" },
2147
- { "relative-paths",0, 0, 0, "on" },
2148
- { "repo-cksum", 0, 0, 0, "on" },
2149
- { "self-register", 0, 0, 0, "off" },
2150
- { "ssh-command", 0, 40, 0, "" },
2151
- { "ssl-ca-location",0, 40, 0, "" },
2152
- { "ssl-identity", 0, 40, 0, "" },
2134
+ { "clean-glob", 0, 40, 1, 0, "" },
2135
+ { "crnl-glob", 0, 40, 1, 0, "" },
2136
+ { "default-perms", 0, 16, 0, 0, "u" },
2137
+ { "diff-binary", 0, 0, 0, 0, "on" },
2138
+ { "diff-command", 0, 40, 0, 0, "" },
2139
+ { "dont-push", 0, 0, 0, 0, "off" },
2140
+ { "editor", 0, 32, 0, 0, "" },
2141
+ { "empty-dirs", 0, 40, 1, 0, "" },
2142
+ { "encoding-glob", 0, 40, 1, 0, "" },
2143
+ { "gdiff-command", 0, 40, 0, 0, "gdiff" },
2144
+ { "gmerge-command", 0, 40, 0, 0, "" },
2145
+ { "http-port", 0, 16, 0, 0, "8080" },
2146
+ { "https-login", 0, 0, 0, 0, "off" },
2147
+ { "ignore-glob", 0, 40, 1, 0, "" },
2148
+ { "keep-glob", 0, 40, 1, 0, "" },
2149
+ { "localauth", 0, 0, 0, 0, "off" },
2150
+ { "main-branch", 0, 40, 0, 0, "trunk" },
2151
+ { "manifest", 0, 0, 1, 0, "off" },
2152
+ { "max-upload", 0, 25, 0, 0, "250000" },
2153
+ { "mtime-changes", 0, 0, 0, 0, "on" },
2154
+ { "pgp-command", 0, 40, 0, 0, "gpg --clearsign -o " },
2155
+ { "proxy", 0, 32, 0, 0, "off" },
2156
+ { "relative-paths", 0, 0, 0, 0, "on" },
2157
+ { "repo-cksum", 0, 0, 0, 0, "on" },
2158
+ { "self-register", 0, 0, 0, 0, "off" },
2159
+ { "ssh-command", 0, 40, 0, 0, "" },
2160
+ { "ssl-ca-location", 0, 40, 0, 0, "" },
2161
+ { "ssl-identity", 0, 40, 0, 0, "" },
21532162
#ifdef FOSSIL_ENABLE_TCL
2154
- { "tcl", 0, 0, 0, "off" },
2155
- { "tcl-setup", 0, 40, 0, "" },
2163
+ { "tcl", 0, 0, 0, 0, "off" },
2164
+ { "tcl-setup", 0, 40, 0, 1, "" },
21562165
#endif
2157
- { "th1-setup", 0, 40, 0, "" },
2158
- { "th1-uri-regexp",0, 40, 0, "" },
2159
- { "web-browser", 0, 32, 0, "" },
2160
- { "white-foreground", 0, 0, 0, "off" },
2161
- { 0,0,0,0,0 }
2166
+ { "th1-setup", 0, 40, 0, 1, "" },
2167
+ { "th1-uri-regexp", 0, 40, 0, 0, "" },
2168
+ { "web-browser", 0, 32, 0, 0, "" },
2169
+ { "white-foreground", 0, 0, 0, 0, "off" },
2170
+ { 0,0,0,0,0,0 }
21622171
};
21632172
21642173
/*
21652174
** COMMAND: settings
21662175
** COMMAND: unset*
21672176
--- src/db.c
+++ src/db.c
@@ -715,11 +715,11 @@
715 */
716 LOCAL sqlite3 *db_open(const char *zDbName){
717 int rc;
718 sqlite3 *db;
719
720 #if defined(__CYGWIN__)
721 zDbName = fossil_utf8_to_filename(zDbName);
722 #endif
723 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
724 rc = sqlite3_open_v2(
725 zDbName, &db,
@@ -1989,23 +1989,28 @@
1989 ** If VERSION is specified then that version is checked out. Otherwise
1990 ** the latest version is checked out. No files other than "manifest"
1991 ** and "manifest.uuid" are modified if the --keep option is present.
1992 **
1993 ** Options:
 
 
 
1994 ** --keep Only modify the manifest and manifest.uuid files
1995 ** --nested Allow opening a repository inside an opened checkout
1996 **
1997 ** See also: close
1998 */
1999 void cmd_open(void){
 
2000 int keepFlag;
2001 int allowNested;
2002 char **oldArgv;
2003 int oldArgc;
2004 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2005
2006 url_proxy_options();
 
2007 keepFlag = find_option("keep",0,0)!=0;
2008 allowNested = find_option("nested",0,0)!=0;
2009 if( g.argc!=3 && g.argc!=4 ){
2010 usage("REPOSITORY-FILENAME ?VERSION?");
2011 }
@@ -2030,22 +2035,24 @@
2030 db_lset_int("checkout", 0);
2031 oldArgv = g.argv;
2032 oldArgc = g.argc;
2033 azNewArgv[0] = g.argv[0];
2034 g.argv = azNewArgv;
2035 g.argc = 3;
2036 if( oldArgc==4 ){
2037 azNewArgv[g.argc-1] = oldArgv[3];
2038 }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2039 azNewArgv[g.argc-1] = "--latest";
2040 }else{
2041 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2042 }
2043 if( keepFlag ){
2044 azNewArgv[g.argc++] = "--keep";
2045 }
2046 checkout_cmd();
 
 
2047 g.argc = 2;
2048 info_cmd();
2049 }
2050
2051 /*
@@ -2101,66 +2108,68 @@
2101 */
2102 #if INTERFACE
2103 struct stControlSettings {
2104 char const *name; /* Name of the setting */
2105 char const *var; /* Internal variable name used by db_set() */
2106 int width; /* Width of display. 0 for boolean values */
2107 int versionable; /* Is this setting versionable? */
 
2108 char const *def; /* Default value */
2109 };
2110 #endif /* INTERFACE */
2111 struct stControlSettings const ctrlSettings[] = {
2112 { "access-log", 0, 0, 0, "off" },
2113 { "allow-symlinks",0, 0, 1, "off" },
2114 { "auto-captcha", "autocaptcha", 0, 0, "on" },
2115 { "auto-hyperlink",0, 0, 0, "on", },
2116 { "auto-shun", 0, 0, 0, "on" },
2117 { "autosync", 0, 0, 0, "on" },
2118 { "binary-glob", 0, 40, 1, "" },
2119 { "clearsign", 0, 0, 0, "off" },
2120 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__DARWIN__) || defined(__APPLE__)
2121 { "case-sensitive",0, 0, 0, "off" },
 
2122 #else
2123 { "case-sensitive",0, 0, 0, "on" },
2124 #endif
2125 { "clean-glob", 0, 40, 1, "" },
2126 { "crnl-glob", 0, 40, 1, "" },
2127 { "default-perms", 0, 16, 0, "u" },
2128 { "diff-binary", 0, 0, 0, "on" },
2129 { "diff-command", 0, 40, 0, "" },
2130 { "dont-push", 0, 0, 0, "off" },
2131 { "editor", 0, 32, 0, "" },
2132 { "empty-dirs", 0, 40, 1, "" },
2133 { "encoding-glob", 0, 40, 1, "" },
2134 { "gdiff-command", 0, 40, 0, "gdiff" },
2135 { "gmerge-command",0, 40, 0, "" },
2136 { "http-port", 0, 16, 0, "8080" },
2137 { "https-login", 0, 0, 0, "off" },
2138 { "ignore-glob", 0, 40, 1, "" },
2139 { "keep-glob", 0, 40, 1, "" },
2140 { "localauth", 0, 0, 0, "off" },
2141 { "main-branch", 0, 40, 0, "trunk" },
2142 { "manifest", 0, 0, 1, "off" },
2143 { "max-upload", 0, 25, 0, "250000" },
2144 { "mtime-changes", 0, 0, 0, "on" },
2145 { "pgp-command", 0, 40, 0, "gpg --clearsign -o " },
2146 { "proxy", 0, 32, 0, "off" },
2147 { "relative-paths",0, 0, 0, "on" },
2148 { "repo-cksum", 0, 0, 0, "on" },
2149 { "self-register", 0, 0, 0, "off" },
2150 { "ssh-command", 0, 40, 0, "" },
2151 { "ssl-ca-location",0, 40, 0, "" },
2152 { "ssl-identity", 0, 40, 0, "" },
2153 #ifdef FOSSIL_ENABLE_TCL
2154 { "tcl", 0, 0, 0, "off" },
2155 { "tcl-setup", 0, 40, 0, "" },
2156 #endif
2157 { "th1-setup", 0, 40, 0, "" },
2158 { "th1-uri-regexp",0, 40, 0, "" },
2159 { "web-browser", 0, 32, 0, "" },
2160 { "white-foreground", 0, 0, 0, "off" },
2161 { 0,0,0,0,0 }
2162 };
2163
2164 /*
2165 ** COMMAND: settings
2166 ** COMMAND: unset*
2167
--- src/db.c
+++ src/db.c
@@ -715,11 +715,11 @@
715 */
716 LOCAL sqlite3 *db_open(const char *zDbName){
717 int rc;
718 sqlite3 *db;
719
720 #if defined(__CYGWIN__) && !defined(USE_SYSTEM_SQLITE)
721 zDbName = fossil_utf8_to_filename(zDbName);
722 #endif
723 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
724 rc = sqlite3_open_v2(
725 zDbName, &db,
@@ -1989,23 +1989,28 @@
1989 ** If VERSION is specified then that version is checked out. Otherwise
1990 ** the latest version is checked out. No files other than "manifest"
1991 ** and "manifest.uuid" are modified if the --keep option is present.
1992 **
1993 ** Options:
1994 ** --empty Initialize checkout as being empty, but still connected
1995 ** with the local repository. If you commit this checkout,
1996 ** it will become a new "initial" commit in the repository.
1997 ** --keep Only modify the manifest and manifest.uuid files
1998 ** --nested Allow opening a repository inside an opened checkout
1999 **
2000 ** See also: close
2001 */
2002 void cmd_open(void){
2003 int emptyFlag;
2004 int keepFlag;
2005 int allowNested;
2006 char **oldArgv;
2007 int oldArgc;
2008 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2009
2010 url_proxy_options();
2011 emptyFlag = find_option("empty",0,0)!=0;
2012 keepFlag = find_option("keep",0,0)!=0;
2013 allowNested = find_option("nested",0,0)!=0;
2014 if( g.argc!=3 && g.argc!=4 ){
2015 usage("REPOSITORY-FILENAME ?VERSION?");
2016 }
@@ -2030,22 +2035,24 @@
2035 db_lset_int("checkout", 0);
2036 oldArgv = g.argv;
2037 oldArgc = g.argc;
2038 azNewArgv[0] = g.argv[0];
2039 g.argv = azNewArgv;
2040 if( !emptyFlag){
2041 g.argc = 3;
2042 if( oldArgc==4 ){
2043 azNewArgv[g.argc-1] = oldArgv[3];
2044 }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2045 azNewArgv[g.argc-1] = "--latest";
2046 }else{
2047 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2048 }
2049 if( keepFlag ){
2050 azNewArgv[g.argc++] = "--keep";
2051 }
2052 checkout_cmd();
2053 }
2054 g.argc = 2;
2055 info_cmd();
2056 }
2057
2058 /*
@@ -2101,66 +2108,68 @@
2108 */
2109 #if INTERFACE
2110 struct stControlSettings {
2111 char const *name; /* Name of the setting */
2112 char const *var; /* Internal variable name used by db_set() */
2113 int width; /* Width of display. 0 for boolean values. */
2114 int versionable; /* Is this setting versionable? */
2115 int forceTextArea; /* Force using a text area for display? */
2116 char const *def; /* Default value */
2117 };
2118 #endif /* INTERFACE */
2119 struct stControlSettings const ctrlSettings[] = {
2120 { "access-log", 0, 0, 0, 0, "off" },
2121 { "allow-symlinks", 0, 0, 1, 0, "off" },
2122 { "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
2123 { "auto-hyperlink", 0, 0, 0, 0, "on", },
2124 { "auto-shun", 0, 0, 0, 0, "on" },
2125 { "autosync", 0, 0, 0, 0, "on" },
2126 { "binary-glob", 0, 40, 1, 0, "" },
2127 { "clearsign", 0, 0, 0, 0, "off" },
2128 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__DARWIN__) || \
2129 defined(__APPLE__)
2130 { "case-sensitive", 0, 0, 0, 0, "off" },
2131 #else
2132 { "case-sensitive", 0, 0, 0, 0, "on" },
2133 #endif
2134 { "clean-glob", 0, 40, 1, 0, "" },
2135 { "crnl-glob", 0, 40, 1, 0, "" },
2136 { "default-perms", 0, 16, 0, 0, "u" },
2137 { "diff-binary", 0, 0, 0, 0, "on" },
2138 { "diff-command", 0, 40, 0, 0, "" },
2139 { "dont-push", 0, 0, 0, 0, "off" },
2140 { "editor", 0, 32, 0, 0, "" },
2141 { "empty-dirs", 0, 40, 1, 0, "" },
2142 { "encoding-glob", 0, 40, 1, 0, "" },
2143 { "gdiff-command", 0, 40, 0, 0, "gdiff" },
2144 { "gmerge-command", 0, 40, 0, 0, "" },
2145 { "http-port", 0, 16, 0, 0, "8080" },
2146 { "https-login", 0, 0, 0, 0, "off" },
2147 { "ignore-glob", 0, 40, 1, 0, "" },
2148 { "keep-glob", 0, 40, 1, 0, "" },
2149 { "localauth", 0, 0, 0, 0, "off" },
2150 { "main-branch", 0, 40, 0, 0, "trunk" },
2151 { "manifest", 0, 0, 1, 0, "off" },
2152 { "max-upload", 0, 25, 0, 0, "250000" },
2153 { "mtime-changes", 0, 0, 0, 0, "on" },
2154 { "pgp-command", 0, 40, 0, 0, "gpg --clearsign -o " },
2155 { "proxy", 0, 32, 0, 0, "off" },
2156 { "relative-paths", 0, 0, 0, 0, "on" },
2157 { "repo-cksum", 0, 0, 0, 0, "on" },
2158 { "self-register", 0, 0, 0, 0, "off" },
2159 { "ssh-command", 0, 40, 0, 0, "" },
2160 { "ssl-ca-location", 0, 40, 0, 0, "" },
2161 { "ssl-identity", 0, 40, 0, 0, "" },
2162 #ifdef FOSSIL_ENABLE_TCL
2163 { "tcl", 0, 0, 0, 0, "off" },
2164 { "tcl-setup", 0, 40, 0, 1, "" },
2165 #endif
2166 { "th1-setup", 0, 40, 0, 1, "" },
2167 { "th1-uri-regexp", 0, 40, 0, 0, "" },
2168 { "web-browser", 0, 32, 0, 0, "" },
2169 { "white-foreground", 0, 0, 0, 0, "off" },
2170 { 0,0,0,0,0,0 }
2171 };
2172
2173 /*
2174 ** COMMAND: settings
2175 ** COMMAND: unset*
2176
+1 -1
--- src/json.c
+++ src/json.c
@@ -30,12 +30,12 @@
3030
** dispatch to a JSON-mode-specific command/page handler with the type fossil_json_f().
3131
** See the API docs for that typedef (below) for the semantics of the callbacks.
3232
**
3333
**
3434
*/
35
-#include "config.h"
3635
#include "VERSION.h"
36
+#include "config.h"
3737
#include "json.h"
3838
#include <assert.h>
3939
#include <time.h>
4040
4141
#if INTERFACE
4242
--- src/json.c
+++ src/json.c
@@ -30,12 +30,12 @@
30 ** dispatch to a JSON-mode-specific command/page handler with the type fossil_json_f().
31 ** See the API docs for that typedef (below) for the semantics of the callbacks.
32 **
33 **
34 */
35 #include "config.h"
36 #include "VERSION.h"
 
37 #include "json.h"
38 #include <assert.h>
39 #include <time.h>
40
41 #if INTERFACE
42
--- src/json.c
+++ src/json.c
@@ -30,12 +30,12 @@
30 ** dispatch to a JSON-mode-specific command/page handler with the type fossil_json_f().
31 ** See the API docs for that typedef (below) for the semantics of the callbacks.
32 **
33 **
34 */
 
35 #include "VERSION.h"
36 #include "config.h"
37 #include "json.h"
38 #include <assert.h>
39 #include <time.h>
40
41 #if INTERFACE
42
+1
--- src/main.c
+++ src/main.c
@@ -16,10 +16,11 @@
1616
*******************************************************************************
1717
**
1818
** This module codes the main() procedure that runs first when the
1919
** program is invoked.
2020
*/
21
+#include "VERSION.h"
2122
#include "config.h"
2223
#include "main.h"
2324
#include <string.h>
2425
#include <time.h>
2526
#include <fcntl.h>
2627
--- src/main.c
+++ src/main.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This module codes the main() procedure that runs first when the
19 ** program is invoked.
20 */
 
21 #include "config.h"
22 #include "main.h"
23 #include <string.h>
24 #include <time.h>
25 #include <fcntl.h>
26
--- src/main.c
+++ src/main.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This module codes the main() procedure that runs first when the
19 ** program is invoked.
20 */
21 #include "VERSION.h"
22 #include "config.h"
23 #include "main.h"
24 #include <string.h>
25 #include <time.h>
26 #include <fcntl.h>
27
+1
--- src/main.c
+++ src/main.c
@@ -16,10 +16,11 @@
1616
*******************************************************************************
1717
**
1818
** This module codes the main() procedure that runs first when the
1919
** program is invoked.
2020
*/
21
+#include "VERSION.h"
2122
#include "config.h"
2223
#include "main.h"
2324
#include <string.h>
2425
#include <time.h>
2526
#include <fcntl.h>
2627
--- src/main.c
+++ src/main.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This module codes the main() procedure that runs first when the
19 ** program is invoked.
20 */
 
21 #include "config.h"
22 #include "main.h"
23 #include <string.h>
24 #include <time.h>
25 #include <fcntl.h>
26
--- src/main.c
+++ src/main.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This module codes the main() procedure that runs first when the
19 ** program is invoked.
20 */
21 #include "VERSION.h"
22 #include "config.h"
23 #include "main.h"
24 #include <string.h>
25 #include <time.h>
26 #include <fcntl.h>
27
+3 -1
--- src/main.mk
+++ src/main.mk
@@ -385,11 +385,13 @@
385385
-DSQLITE_OMIT_DEPRECATED \
386386
-DSQLITE_ENABLE_EXPLAIN_COMMENTS
387387
388388
# Setup the options used to compile the included SQLite shell.
389389
SHELL_OPTIONS = -Dmain=sqlite3_shell \
390
- -DSQLITE_OMIT_LOAD_EXTENSION=1
390
+ -DSQLITE_OMIT_LOAD_EXTENSION=1 \
391
+ -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
392
+ -DSQLITE_SHELL_DBNAME_PROC=fossil_open
391393
392394
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
393395
# to 1. If it is set to 1, then there is no need to build or link
394396
# the sqlite3.o object. Instead, the system sqlite will be linked
395397
# using -lsqlite3.
396398
--- src/main.mk
+++ src/main.mk
@@ -385,11 +385,13 @@
385 -DSQLITE_OMIT_DEPRECATED \
386 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
387
388 # Setup the options used to compile the included SQLite shell.
389 SHELL_OPTIONS = -Dmain=sqlite3_shell \
390 -DSQLITE_OMIT_LOAD_EXTENSION=1
 
 
391
392 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
393 # to 1. If it is set to 1, then there is no need to build or link
394 # the sqlite3.o object. Instead, the system sqlite will be linked
395 # using -lsqlite3.
396
--- src/main.mk
+++ src/main.mk
@@ -385,11 +385,13 @@
385 -DSQLITE_OMIT_DEPRECATED \
386 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
387
388 # Setup the options used to compile the included SQLite shell.
389 SHELL_OPTIONS = -Dmain=sqlite3_shell \
390 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
391 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
392 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
393
394 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
395 # to 1. If it is set to 1, then there is no need to build or link
396 # the sqlite3.o object. Instead, the system sqlite will be linked
397 # using -lsqlite3.
398
+56 -21
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -146,10 +146,12 @@
146146
# Options used to compile the included SQLite shell.
147147
#
148148
set SHELL_OPTIONS {
149149
-Dmain=sqlite3_shell
150150
-DSQLITE_OMIT_LOAD_EXTENSION=1
151
+ -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE)
152
+ -DSQLITE_SHELL_DBNAME_PROC=fossil_open
151153
}
152154
153155
# Options used to compile the included SQLite shell on Windows.
154156
#
155157
set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
@@ -1015,54 +1017,78 @@
10151017
# Uncomment to enable JSON API
10161018
# FOSSIL_ENABLE_JSON = 1
10171019
10181020
# Uncomment to enable SSL support
10191021
# FOSSIL_ENABLE_SSL = 1
1022
+
1023
+# Uncomment to enable Tcl support
1024
+# FOSSIL_ENABLE_TCL = 1
10201025
10211026
!ifdef FOSSIL_ENABLE_SSL
10221027
SSLINCDIR = $(B)\compat\openssl-1.0.1f\include
10231028
SSLLIBDIR = $(B)\compat\openssl-1.0.1f\out32
10241029
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
10251030
!endif
1031
+
1032
+!ifdef FOSSIL_ENABLE_TCL
1033
+TCLDIR = $(B)\compat\tcl-8.6
1034
+TCLSRCDIR = $(TCLDIR)
1035
+TCLINCDIR = $(TCLSRCDIR)\generic
1036
+!endif
10261037
10271038
# zlib options
10281039
ZINCDIR = $(B)\compat\zlib
10291040
ZLIBDIR = $(B)\compat\zlib
10301041
ZLIB = zlib.lib
10311042
1032
-INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(ZINCDIR)
1043
+INCL = /I. /I$(SRCDIR) /I$B\win\include /I$(ZINCDIR)
10331044
10341045
!ifdef FOSSIL_ENABLE_SSL
1035
-INCL = $(INCL) -I$(SSLINCDIR)
1046
+INCL = $(INCL) /I$(SSLINCDIR)
1047
+!endif
1048
+
1049
+!ifdef FOSSIL_ENABLE_TCL
1050
+INCL = $(INCL) /I$(TCLINCDIR)
10361051
!endif
10371052
1038
-CFLAGS = -nologo
1053
+CFLAGS = /nologo
10391054
LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
10401055
10411056
!ifdef DEBUG
1042
-CFLAGS = $(CFLAGS) -Zi -MTd -Od
1057
+CFLAGS = $(CFLAGS) /Zi /MTd /Od
10431058
LDFLAGS = $(LDFLAGS) /DEBUG
10441059
!else
1045
-CFLAGS = $(CFLAGS) -MT -O2
1060
+CFLAGS = $(CFLAGS) /MT /O2
10461061
!endif
10471062
10481063
BCC = $(CC) $(CFLAGS)
1049
-TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(INCL)
1050
-RCC = rc -D_WIN32 -D_MSC_VER $(MSCDEF) $(INCL)
1064
+TCC = $(CC) /c $(CFLAGS) $(MSCDEF) $(INCL)
1065
+RCC = rc /D_WIN32 /D_MSC_VER $(MSCDEF) $(INCL)
10511066
LIBS = $(ZLIB) ws2_32.lib advapi32.lib
1052
-LIBDIR = -LIBPATH:$(ZLIBDIR)
1067
+LIBDIR = /LIBPATH:$(ZLIBDIR)
10531068
10541069
!ifdef FOSSIL_ENABLE_JSON
1055
-TCC = $(TCC) -DFOSSIL_ENABLE_JSON=1
1056
-RCC = $(RCC) -DFOSSIL_ENABLE_JSON=1
1070
+TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
1071
+RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
10571072
!endif
10581073
10591074
!ifdef FOSSIL_ENABLE_SSL
1060
-TCC = $(TCC) -DFOSSIL_ENABLE_SSL=1
1061
-RCC = $(RCC) -DFOSSIL_ENABLE_SSL=1
1075
+TCC = $(TCC) /DFOSSIL_ENABLE_SSL=1
1076
+RCC = $(RCC) /DFOSSIL_ENABLE_SSL=1
10621077
LIBS = $(LIBS) $(SSLLIB)
1063
-LIBDIR = $(LIBDIR) -LIBPATH:$(SSLLIBDIR)
1078
+LIBDIR = $(LIBDIR) /LIBPATH:$(SSLLIBDIR)
1079
+!endif
1080
+
1081
+!ifdef FOSSIL_ENABLE_TCL
1082
+TCC = $(TCC) /DFOSSIL_ENABLE_TCL=1
1083
+RCC = $(RCC) /DFOSSIL_ENABLE_TCL=1
1084
+TCC = $(TCC) /DFOSSIL_ENABLE_TCL_STUBS=1
1085
+RCC = $(RCC) /DFOSSIL_ENABLE_TCL_STUBS=1
1086
+TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1087
+RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1088
+TCC = $(TCC) /DUSE_TCL_STUBS=1
1089
+RCC = $(RCC) /DUSE_TCL_STUBS=1
10641090
!endif
10651091
}
10661092
regsub -all {[-]D} [join $SQLITE_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
10671093
set j " \\\n "
10681094
writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
@@ -1090,11 +1116,14 @@
10901116
writeln -nonewline " "
10911117
}
10921118
writeln -nonewline "\$(OX)\\$s\$O"; incr i
10931119
}
10941120
writeln " \\"
1095
-writeln -nonewline " \$(OX)\\fossil.res\n"
1121
+writeln -nonewline " \$(OX)\\fossil.res\n\n"
1122
+writeln "!ifdef FOSSIL_ENABLE_TCL"
1123
+writeln "OBJ = \$(OBJ) \$(OX)\\th_tcl\$O"
1124
+writeln "!endif"
10961125
writeln {
10971126
APPNAME = $(OX)\fossil$(E)
10981127
PDBNAME = $(OX)\fossil$(P)
10991128
11001129
all: $(OX) $(APPNAME)
@@ -1103,22 +1132,24 @@
11031132
@echo Building zlib from "$(ZLIBDIR)"...
11041133
@pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd
11051134
11061135
$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib
11071136
cd $(OX)
1108
- link $(LDFLAGS) -OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
1137
+ link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
11091138
11101139
$(OX)\linkopts: $B\win\Makefile.msc}
11111140
set redir {>}
11121141
foreach s [lsort [concat $src $AdditionalObj]] {
11131142
writeln "\techo \$(OX)\\$s.obj $redir \$@"
11141143
set redir {>>}
11151144
}
1116
-writeln "\techo \$(LIBS) >> \$@\n\n"
1117
-
1145
+writeln "!ifdef FOSSIL_ENABLE_TCL"
1146
+writeln "\techo \$(OX)\\th_tcl.obj $redir \$@"
1147
+set redir {>>}
1148
+writeln "!endif"
1149
+writeln "\techo \$(LIBS) $redir \$@"
11181150
writeln {
1119
-
11201151
$(OX):
11211152
@-mkdir $@
11221153
11231154
translate$E: $(SRCDIR)\translate.c
11241155
$(BCC) $**
@@ -1141,15 +1172,20 @@
11411172
$(OX)\th$O : $(SRCDIR)\th.c
11421173
$(TCC) /Fo$@ -c $**
11431174
11441175
$(OX)\th_lang$O : $(SRCDIR)\th_lang.c
11451176
$(TCC) /Fo$@ -c $**
1177
+
1178
+!ifdef FOSSIL_ENABLE_TCL
1179
+$(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
1180
+ $(TCC) /Fo$@ -c $**
1181
+!endif
11461182
11471183
VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
11481184
$** > $@
11491185
$(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
1150
- $(TCC) /Fo$@ -c $**
1186
+ $(TCC) /Fo$@ /c $**
11511187
11521188
page_index.h: mkindex$E $(SRC)
11531189
$** > $@
11541190
11551191
clean:
@@ -1184,21 +1220,20 @@
11841220
$(OBJDIR)\json_status$O : $(SRCDIR)\json_detail.h
11851221
$(OBJDIR)\json_tag$O : $(SRCDIR)\json_detail.h
11861222
$(OBJDIR)\json_timeline$O : $(SRCDIR)\json_detail.h
11871223
$(OBJDIR)\json_user$O : $(SRCDIR)\json_detail.h
11881224
$(OBJDIR)\json_wiki$O : $(SRCDIR)\json_detail.h
1189
-
11901225
}
11911226
foreach s [lsort $src] {
11921227
writeln "\$(OX)\\$s\$O : ${s}_.c ${s}.h"
11931228
writeln "\t\$(TCC) /Fo\$@ -c ${s}_.c\n"
11941229
writeln "${s}_.c : \$(SRCDIR)\\$s.c"
11951230
writeln "\ttranslate\$E \$** > \$@\n"
11961231
}
11971232
11981233
writeln "fossil.res : \$B\\win\\fossil.rc"
1199
-writeln "\t\$(RCC) -fo \$@ \$**"
1234
+writeln "\t\$(RCC) /fo \$@ \$**\n"
12001235
12011236
writeln "headers: makeheaders\$E page_index.h VERSION.h"
12021237
writeln -nonewline "\tmakeheaders\$E "
12031238
set i 0
12041239
foreach s [lsort $src] {
12051240
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -146,10 +146,12 @@
146 # Options used to compile the included SQLite shell.
147 #
148 set SHELL_OPTIONS {
149 -Dmain=sqlite3_shell
150 -DSQLITE_OMIT_LOAD_EXTENSION=1
 
 
151 }
152
153 # Options used to compile the included SQLite shell on Windows.
154 #
155 set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
@@ -1015,54 +1017,78 @@
1015 # Uncomment to enable JSON API
1016 # FOSSIL_ENABLE_JSON = 1
1017
1018 # Uncomment to enable SSL support
1019 # FOSSIL_ENABLE_SSL = 1
 
 
 
1020
1021 !ifdef FOSSIL_ENABLE_SSL
1022 SSLINCDIR = $(B)\compat\openssl-1.0.1f\include
1023 SSLLIBDIR = $(B)\compat\openssl-1.0.1f\out32
1024 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1025 !endif
 
 
 
 
 
 
1026
1027 # zlib options
1028 ZINCDIR = $(B)\compat\zlib
1029 ZLIBDIR = $(B)\compat\zlib
1030 ZLIB = zlib.lib
1031
1032 INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(ZINCDIR)
1033
1034 !ifdef FOSSIL_ENABLE_SSL
1035 INCL = $(INCL) -I$(SSLINCDIR)
 
 
 
 
1036 !endif
1037
1038 CFLAGS = -nologo
1039 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
1040
1041 !ifdef DEBUG
1042 CFLAGS = $(CFLAGS) -Zi -MTd -Od
1043 LDFLAGS = $(LDFLAGS) /DEBUG
1044 !else
1045 CFLAGS = $(CFLAGS) -MT -O2
1046 !endif
1047
1048 BCC = $(CC) $(CFLAGS)
1049 TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(INCL)
1050 RCC = rc -D_WIN32 -D_MSC_VER $(MSCDEF) $(INCL)
1051 LIBS = $(ZLIB) ws2_32.lib advapi32.lib
1052 LIBDIR = -LIBPATH:$(ZLIBDIR)
1053
1054 !ifdef FOSSIL_ENABLE_JSON
1055 TCC = $(TCC) -DFOSSIL_ENABLE_JSON=1
1056 RCC = $(RCC) -DFOSSIL_ENABLE_JSON=1
1057 !endif
1058
1059 !ifdef FOSSIL_ENABLE_SSL
1060 TCC = $(TCC) -DFOSSIL_ENABLE_SSL=1
1061 RCC = $(RCC) -DFOSSIL_ENABLE_SSL=1
1062 LIBS = $(LIBS) $(SSLLIB)
1063 LIBDIR = $(LIBDIR) -LIBPATH:$(SSLLIBDIR)
 
 
 
 
 
 
 
 
 
 
 
1064 !endif
1065 }
1066 regsub -all {[-]D} [join $SQLITE_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
1067 set j " \\\n "
1068 writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
@@ -1090,11 +1116,14 @@
1090 writeln -nonewline " "
1091 }
1092 writeln -nonewline "\$(OX)\\$s\$O"; incr i
1093 }
1094 writeln " \\"
1095 writeln -nonewline " \$(OX)\\fossil.res\n"
 
 
 
1096 writeln {
1097 APPNAME = $(OX)\fossil$(E)
1098 PDBNAME = $(OX)\fossil$(P)
1099
1100 all: $(OX) $(APPNAME)
@@ -1103,22 +1132,24 @@
1103 @echo Building zlib from "$(ZLIBDIR)"...
1104 @pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd
1105
1106 $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib
1107 cd $(OX)
1108 link $(LDFLAGS) -OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
1109
1110 $(OX)\linkopts: $B\win\Makefile.msc}
1111 set redir {>}
1112 foreach s [lsort [concat $src $AdditionalObj]] {
1113 writeln "\techo \$(OX)\\$s.obj $redir \$@"
1114 set redir {>>}
1115 }
1116 writeln "\techo \$(LIBS) >> \$@\n\n"
1117
 
 
 
1118 writeln {
1119
1120 $(OX):
1121 @-mkdir $@
1122
1123 translate$E: $(SRCDIR)\translate.c
1124 $(BCC) $**
@@ -1141,15 +1172,20 @@
1141 $(OX)\th$O : $(SRCDIR)\th.c
1142 $(TCC) /Fo$@ -c $**
1143
1144 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
1145 $(TCC) /Fo$@ -c $**
 
 
 
 
 
1146
1147 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
1148 $** > $@
1149 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
1150 $(TCC) /Fo$@ -c $**
1151
1152 page_index.h: mkindex$E $(SRC)
1153 $** > $@
1154
1155 clean:
@@ -1184,21 +1220,20 @@
1184 $(OBJDIR)\json_status$O : $(SRCDIR)\json_detail.h
1185 $(OBJDIR)\json_tag$O : $(SRCDIR)\json_detail.h
1186 $(OBJDIR)\json_timeline$O : $(SRCDIR)\json_detail.h
1187 $(OBJDIR)\json_user$O : $(SRCDIR)\json_detail.h
1188 $(OBJDIR)\json_wiki$O : $(SRCDIR)\json_detail.h
1189
1190 }
1191 foreach s [lsort $src] {
1192 writeln "\$(OX)\\$s\$O : ${s}_.c ${s}.h"
1193 writeln "\t\$(TCC) /Fo\$@ -c ${s}_.c\n"
1194 writeln "${s}_.c : \$(SRCDIR)\\$s.c"
1195 writeln "\ttranslate\$E \$** > \$@\n"
1196 }
1197
1198 writeln "fossil.res : \$B\\win\\fossil.rc"
1199 writeln "\t\$(RCC) -fo \$@ \$**"
1200
1201 writeln "headers: makeheaders\$E page_index.h VERSION.h"
1202 writeln -nonewline "\tmakeheaders\$E "
1203 set i 0
1204 foreach s [lsort $src] {
1205
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -146,10 +146,12 @@
146 # Options used to compile the included SQLite shell.
147 #
148 set SHELL_OPTIONS {
149 -Dmain=sqlite3_shell
150 -DSQLITE_OMIT_LOAD_EXTENSION=1
151 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE)
152 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
153 }
154
155 # Options used to compile the included SQLite shell on Windows.
156 #
157 set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
@@ -1015,54 +1017,78 @@
1017 # Uncomment to enable JSON API
1018 # FOSSIL_ENABLE_JSON = 1
1019
1020 # Uncomment to enable SSL support
1021 # FOSSIL_ENABLE_SSL = 1
1022
1023 # Uncomment to enable Tcl support
1024 # FOSSIL_ENABLE_TCL = 1
1025
1026 !ifdef FOSSIL_ENABLE_SSL
1027 SSLINCDIR = $(B)\compat\openssl-1.0.1f\include
1028 SSLLIBDIR = $(B)\compat\openssl-1.0.1f\out32
1029 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1030 !endif
1031
1032 !ifdef FOSSIL_ENABLE_TCL
1033 TCLDIR = $(B)\compat\tcl-8.6
1034 TCLSRCDIR = $(TCLDIR)
1035 TCLINCDIR = $(TCLSRCDIR)\generic
1036 !endif
1037
1038 # zlib options
1039 ZINCDIR = $(B)\compat\zlib
1040 ZLIBDIR = $(B)\compat\zlib
1041 ZLIB = zlib.lib
1042
1043 INCL = /I. /I$(SRCDIR) /I$B\win\include /I$(ZINCDIR)
1044
1045 !ifdef FOSSIL_ENABLE_SSL
1046 INCL = $(INCL) /I$(SSLINCDIR)
1047 !endif
1048
1049 !ifdef FOSSIL_ENABLE_TCL
1050 INCL = $(INCL) /I$(TCLINCDIR)
1051 !endif
1052
1053 CFLAGS = /nologo
1054 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
1055
1056 !ifdef DEBUG
1057 CFLAGS = $(CFLAGS) /Zi /MTd /Od
1058 LDFLAGS = $(LDFLAGS) /DEBUG
1059 !else
1060 CFLAGS = $(CFLAGS) /MT /O2
1061 !endif
1062
1063 BCC = $(CC) $(CFLAGS)
1064 TCC = $(CC) /c $(CFLAGS) $(MSCDEF) $(INCL)
1065 RCC = rc /D_WIN32 /D_MSC_VER $(MSCDEF) $(INCL)
1066 LIBS = $(ZLIB) ws2_32.lib advapi32.lib
1067 LIBDIR = /LIBPATH:$(ZLIBDIR)
1068
1069 !ifdef FOSSIL_ENABLE_JSON
1070 TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
1071 RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
1072 !endif
1073
1074 !ifdef FOSSIL_ENABLE_SSL
1075 TCC = $(TCC) /DFOSSIL_ENABLE_SSL=1
1076 RCC = $(RCC) /DFOSSIL_ENABLE_SSL=1
1077 LIBS = $(LIBS) $(SSLLIB)
1078 LIBDIR = $(LIBDIR) /LIBPATH:$(SSLLIBDIR)
1079 !endif
1080
1081 !ifdef FOSSIL_ENABLE_TCL
1082 TCC = $(TCC) /DFOSSIL_ENABLE_TCL=1
1083 RCC = $(RCC) /DFOSSIL_ENABLE_TCL=1
1084 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_STUBS=1
1085 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_STUBS=1
1086 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1087 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1088 TCC = $(TCC) /DUSE_TCL_STUBS=1
1089 RCC = $(RCC) /DUSE_TCL_STUBS=1
1090 !endif
1091 }
1092 regsub -all {[-]D} [join $SQLITE_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
1093 set j " \\\n "
1094 writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
@@ -1090,11 +1116,14 @@
1116 writeln -nonewline " "
1117 }
1118 writeln -nonewline "\$(OX)\\$s\$O"; incr i
1119 }
1120 writeln " \\"
1121 writeln -nonewline " \$(OX)\\fossil.res\n\n"
1122 writeln "!ifdef FOSSIL_ENABLE_TCL"
1123 writeln "OBJ = \$(OBJ) \$(OX)\\th_tcl\$O"
1124 writeln "!endif"
1125 writeln {
1126 APPNAME = $(OX)\fossil$(E)
1127 PDBNAME = $(OX)\fossil$(P)
1128
1129 all: $(OX) $(APPNAME)
@@ -1103,22 +1132,24 @@
1132 @echo Building zlib from "$(ZLIBDIR)"...
1133 @pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd
1134
1135 $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib
1136 cd $(OX)
1137 link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
1138
1139 $(OX)\linkopts: $B\win\Makefile.msc}
1140 set redir {>}
1141 foreach s [lsort [concat $src $AdditionalObj]] {
1142 writeln "\techo \$(OX)\\$s.obj $redir \$@"
1143 set redir {>>}
1144 }
1145 writeln "!ifdef FOSSIL_ENABLE_TCL"
1146 writeln "\techo \$(OX)\\th_tcl.obj $redir \$@"
1147 set redir {>>}
1148 writeln "!endif"
1149 writeln "\techo \$(LIBS) $redir \$@"
1150 writeln {
 
1151 $(OX):
1152 @-mkdir $@
1153
1154 translate$E: $(SRCDIR)\translate.c
1155 $(BCC) $**
@@ -1141,15 +1172,20 @@
1172 $(OX)\th$O : $(SRCDIR)\th.c
1173 $(TCC) /Fo$@ -c $**
1174
1175 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
1176 $(TCC) /Fo$@ -c $**
1177
1178 !ifdef FOSSIL_ENABLE_TCL
1179 $(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
1180 $(TCC) /Fo$@ -c $**
1181 !endif
1182
1183 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
1184 $** > $@
1185 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
1186 $(TCC) /Fo$@ /c $**
1187
1188 page_index.h: mkindex$E $(SRC)
1189 $** > $@
1190
1191 clean:
@@ -1184,21 +1220,20 @@
1220 $(OBJDIR)\json_status$O : $(SRCDIR)\json_detail.h
1221 $(OBJDIR)\json_tag$O : $(SRCDIR)\json_detail.h
1222 $(OBJDIR)\json_timeline$O : $(SRCDIR)\json_detail.h
1223 $(OBJDIR)\json_user$O : $(SRCDIR)\json_detail.h
1224 $(OBJDIR)\json_wiki$O : $(SRCDIR)\json_detail.h
 
1225 }
1226 foreach s [lsort $src] {
1227 writeln "\$(OX)\\$s\$O : ${s}_.c ${s}.h"
1228 writeln "\t\$(TCC) /Fo\$@ -c ${s}_.c\n"
1229 writeln "${s}_.c : \$(SRCDIR)\\$s.c"
1230 writeln "\ttranslate\$E \$** > \$@\n"
1231 }
1232
1233 writeln "fossil.res : \$B\\win\\fossil.rc"
1234 writeln "\t\$(RCC) /fo \$@ \$**\n"
1235
1236 writeln "headers: makeheaders\$E page_index.h VERSION.h"
1237 writeln -nonewline "\tmakeheaders\$E "
1238 set i 0
1239 foreach s [lsort $src] {
1240
--- src/mkversion.c
+++ src/mkversion.c
@@ -69,7 +69,21 @@
6969
}
7070
}
7171
printf("#define RELEASE_RESOURCE_VERSION %s", vx);
7272
while( d<3 ){ printf(",0"); d++; }
7373
printf("\n");
74
+#if defined(__DMC__) /* e.g. 0x857 */
75
+ d = (__DMC__ & 0xF00) >> 8; /* major */
76
+ x = (__DMC__ & 0x0F0) >> 4; /* minor */
77
+ i = (__DMC__ & 0x00F); /* revision */
78
+ printf("#define COMPILER_VERSION \"%d.%d.%d\"\n", d, x, i);
79
+#elif defined(__POCC__) /* e.g. 700 */
80
+ d = (__POCC__ / 100); /* major */
81
+ x = (__POCC__ % 100); /* minor */
82
+ printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
83
+#elif defined(_MSC_VER) /* e.g. 1800 */
84
+ d = (_MSC_VER / 100); /* major */
85
+ x = (_MSC_VER % 100); /* minor */
86
+ printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
87
+#endif
7488
return 0;
7589
}
7690
--- src/mkversion.c
+++ src/mkversion.c
@@ -69,7 +69,21 @@
69 }
70 }
71 printf("#define RELEASE_RESOURCE_VERSION %s", vx);
72 while( d<3 ){ printf(",0"); d++; }
73 printf("\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74 return 0;
75 }
76
--- src/mkversion.c
+++ src/mkversion.c
@@ -69,7 +69,21 @@
69 }
70 }
71 printf("#define RELEASE_RESOURCE_VERSION %s", vx);
72 while( d<3 ){ printf(",0"); d++; }
73 printf("\n");
74 #if defined(__DMC__) /* e.g. 0x857 */
75 d = (__DMC__ & 0xF00) >> 8; /* major */
76 x = (__DMC__ & 0x0F0) >> 4; /* minor */
77 i = (__DMC__ & 0x00F); /* revision */
78 printf("#define COMPILER_VERSION \"%d.%d.%d\"\n", d, x, i);
79 #elif defined(__POCC__) /* e.g. 700 */
80 d = (__POCC__ / 100); /* major */
81 x = (__POCC__ % 100); /* minor */
82 printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
83 #elif defined(_MSC_VER) /* e.g. 1800 */
84 d = (_MSC_VER / 100); /* major */
85 x = (_MSC_VER % 100); /* minor */
86 printf("#define COMPILER_VERSION \"%d.%02d\"\n", d, x);
87 #endif
88 return 0;
89 }
90
+7 -2
--- src/rebuild.c
+++ src/rebuild.c
@@ -793,11 +793,10 @@
793793
db_close(1);
794794
db_open_repository(g.zRepositoryName);
795795
if( !bForce ){
796796
Blob ans;
797797
char cReply;
798
- blob_zero(&ans);
799798
prompt_user(
800799
"Scrubbing the repository will permanently delete information.\n"
801800
"Changes cannot be undone. Continue (y/N)? ", &ans);
802801
cReply = blob_str(&ans)[0];
803802
if( cReply!='y' && cReply!='Y' ){
@@ -859,11 +858,17 @@
859858
continue;
860859
}
861860
zUtf8Name = fossil_filename_to_utf8(pEntry->d_name);
862861
zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
863862
fossil_filename_free(zUtf8Name);
864
- if( file_isdir(zSubpath)==1 ){
863
+#ifdef _DIRENT_HAVE_D_TYPE
864
+ if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
865
+ ? (file_isdir(zSubpath)==1) : (pEntry->d_type==DT_DIR) )
866
+#else
867
+ if( file_isdir(zSubpath)==1 )
868
+#endif
869
+ {
865870
recon_read_dir(zSubpath);
866871
}else{
867872
blob_init(&path, 0, 0);
868873
blob_appendf(&path, "%s", zSubpath);
869874
if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
870875
--- src/rebuild.c
+++ src/rebuild.c
@@ -793,11 +793,10 @@
793 db_close(1);
794 db_open_repository(g.zRepositoryName);
795 if( !bForce ){
796 Blob ans;
797 char cReply;
798 blob_zero(&ans);
799 prompt_user(
800 "Scrubbing the repository will permanently delete information.\n"
801 "Changes cannot be undone. Continue (y/N)? ", &ans);
802 cReply = blob_str(&ans)[0];
803 if( cReply!='y' && cReply!='Y' ){
@@ -859,11 +858,17 @@
859 continue;
860 }
861 zUtf8Name = fossil_filename_to_utf8(pEntry->d_name);
862 zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
863 fossil_filename_free(zUtf8Name);
864 if( file_isdir(zSubpath)==1 ){
 
 
 
 
 
 
865 recon_read_dir(zSubpath);
866 }else{
867 blob_init(&path, 0, 0);
868 blob_appendf(&path, "%s", zSubpath);
869 if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
870
--- src/rebuild.c
+++ src/rebuild.c
@@ -793,11 +793,10 @@
793 db_close(1);
794 db_open_repository(g.zRepositoryName);
795 if( !bForce ){
796 Blob ans;
797 char cReply;
 
798 prompt_user(
799 "Scrubbing the repository will permanently delete information.\n"
800 "Changes cannot be undone. Continue (y/N)? ", &ans);
801 cReply = blob_str(&ans)[0];
802 if( cReply!='y' && cReply!='Y' ){
@@ -859,11 +858,17 @@
858 continue;
859 }
860 zUtf8Name = fossil_filename_to_utf8(pEntry->d_name);
861 zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
862 fossil_filename_free(zUtf8Name);
863 #ifdef _DIRENT_HAVE_D_TYPE
864 if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
865 ? (file_isdir(zSubpath)==1) : (pEntry->d_type==DT_DIR) )
866 #else
867 if( file_isdir(zSubpath)==1 )
868 #endif
869 {
870 recon_read_dir(zSubpath);
871 }else{
872 blob_init(&path, 0, 0);
873 blob_appendf(&path, "%s", zSubpath);
874 if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
875
+1 -1
--- src/report.c
+++ src/report.c
@@ -925,11 +925,11 @@
925925
if( xCallback(pArg, nCol, azVals, azCols) ){
926926
break;
927927
}
928928
}
929929
rc = sqlite3_finalize(pStmt);
930
- fossil_free(azVals);
930
+ fossil_free((void *)azVals);
931931
return rc;
932932
}
933933
934934
/*
935935
** Output Javascript code that will enables sorting of the table with
936936
--- src/report.c
+++ src/report.c
@@ -925,11 +925,11 @@
925 if( xCallback(pArg, nCol, azVals, azCols) ){
926 break;
927 }
928 }
929 rc = sqlite3_finalize(pStmt);
930 fossil_free(azVals);
931 return rc;
932 }
933
934 /*
935 ** Output Javascript code that will enables sorting of the table with
936
--- src/report.c
+++ src/report.c
@@ -925,11 +925,11 @@
925 if( xCallback(pArg, nCol, azVals, azCols) ){
926 break;
927 }
928 }
929 rc = sqlite3_finalize(pStmt);
930 fossil_free((void *)azVals);
931 return rc;
932 }
933
934 /*
935 ** Output Javascript code that will enables sorting of the table with
936
+14 -5
--- src/setup.c
+++ src/setup.c
@@ -1261,32 +1261,41 @@
12611261
} else {
12621262
@ <br />
12631263
}
12641264
}
12651265
}
1266
+ @ <br /><input type="submit" name="submit" value="Apply Changes" />
12661267
@ </td><td style="width:50px;"></td><td valign="top">
12671268
for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1268
- if( pSet->width!=0 && !pSet->versionable){
1269
+ if( pSet->width!=0 && !pSet->versionable && !pSet->forceTextArea ){
12691270
entry_attribute(pSet->name, /*pSet->width*/ 25, pSet->name,
12701271
pSet->var!=0 ? pSet->var : pSet->name,
12711272
(char*)pSet->def, 0);
12721273
@ <br />
12731274
}
1275
+ }
1276
+ for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1277
+ if( pSet->width!=0 && !pSet->versionable && pSet->forceTextArea ){
1278
+ @<b>%s(pSet->name)</b><br />
1279
+ textarea_attribute("", /*rows*/ 3, /*cols*/ 50, pSet->name,
1280
+ pSet->var!=0 ? pSet->var : pSet->name,
1281
+ (char*)pSet->def, 0);
1282
+ @ <br />
1283
+ }
12741284
}
12751285
@ </td><td style="width:50px;"></td><td valign="top">
12761286
for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1277
- int hasVersionableValue = db_get_do_versionable(pSet->name, NULL)!=0;
1278
- if( pSet->width!=0 && pSet->versionable){
1287
+ if( pSet->width!=0 && pSet->versionable ){
1288
+ int hasVersionableValue = db_get_do_versionable(pSet->name, NULL)!=0;
12791289
@<b>%s(pSet->name)</b> (v)<br />
12801290
textarea_attribute("", /*rows*/ 3, /*cols*/ 20, pSet->name,
12811291
pSet->var!=0 ? pSet->var : pSet->name,
12821292
(char*)pSet->def, hasVersionableValue);
12831293
@<br />
12841294
}
12851295
}
12861296
@ </td></tr></table>
1287
- @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
12881297
@ </div></form>
12891298
@ <p>Settings marked with (v) are 'versionable' and will be overridden
12901299
@ by the contents of files named <tt>.fossil-settings/PROPERTY</tt>.
12911300
@ If such a file is present, the corresponding field above is not
12921301
@ editable.</p><hr /><p>
@@ -1469,11 +1478,11 @@
14691478
@ </div></form>
14701479
@ <hr />
14711480
@ The default header is shown below for reference. Other examples
14721481
@ of headers can be seen on the <a href="setup_skin">skins page</a>.
14731482
@ See also the <a href="setup_editcss">CSS</a> and
1474
- @ <a href="setup_footer">footer</a> editing screeens.
1483
+ @ <a href="setup_footer">footer</a> editing screens.
14751484
@ <blockquote><pre>
14761485
@ %h(zDefaultHeader)
14771486
@ </pre></blockquote>
14781487
style_footer();
14791488
db_end_transaction(0);
14801489
--- src/setup.c
+++ src/setup.c
@@ -1261,32 +1261,41 @@
1261 } else {
1262 @ <br />
1263 }
1264 }
1265 }
 
1266 @ </td><td style="width:50px;"></td><td valign="top">
1267 for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1268 if( pSet->width!=0 && !pSet->versionable){
1269 entry_attribute(pSet->name, /*pSet->width*/ 25, pSet->name,
1270 pSet->var!=0 ? pSet->var : pSet->name,
1271 (char*)pSet->def, 0);
1272 @ <br />
1273 }
 
 
 
 
 
 
 
 
 
1274 }
1275 @ </td><td style="width:50px;"></td><td valign="top">
1276 for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1277 int hasVersionableValue = db_get_do_versionable(pSet->name, NULL)!=0;
1278 if( pSet->width!=0 && pSet->versionable){
1279 @<b>%s(pSet->name)</b> (v)<br />
1280 textarea_attribute("", /*rows*/ 3, /*cols*/ 20, pSet->name,
1281 pSet->var!=0 ? pSet->var : pSet->name,
1282 (char*)pSet->def, hasVersionableValue);
1283 @<br />
1284 }
1285 }
1286 @ </td></tr></table>
1287 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
1288 @ </div></form>
1289 @ <p>Settings marked with (v) are 'versionable' and will be overridden
1290 @ by the contents of files named <tt>.fossil-settings/PROPERTY</tt>.
1291 @ If such a file is present, the corresponding field above is not
1292 @ editable.</p><hr /><p>
@@ -1469,11 +1478,11 @@
1469 @ </div></form>
1470 @ <hr />
1471 @ The default header is shown below for reference. Other examples
1472 @ of headers can be seen on the <a href="setup_skin">skins page</a>.
1473 @ See also the <a href="setup_editcss">CSS</a> and
1474 @ <a href="setup_footer">footer</a> editing screeens.
1475 @ <blockquote><pre>
1476 @ %h(zDefaultHeader)
1477 @ </pre></blockquote>
1478 style_footer();
1479 db_end_transaction(0);
1480
--- src/setup.c
+++ src/setup.c
@@ -1261,32 +1261,41 @@
1261 } else {
1262 @ <br />
1263 }
1264 }
1265 }
1266 @ <br /><input type="submit" name="submit" value="Apply Changes" />
1267 @ </td><td style="width:50px;"></td><td valign="top">
1268 for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1269 if( pSet->width!=0 && !pSet->versionable && !pSet->forceTextArea ){
1270 entry_attribute(pSet->name, /*pSet->width*/ 25, pSet->name,
1271 pSet->var!=0 ? pSet->var : pSet->name,
1272 (char*)pSet->def, 0);
1273 @ <br />
1274 }
1275 }
1276 for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1277 if( pSet->width!=0 && !pSet->versionable && pSet->forceTextArea ){
1278 @<b>%s(pSet->name)</b><br />
1279 textarea_attribute("", /*rows*/ 3, /*cols*/ 50, pSet->name,
1280 pSet->var!=0 ? pSet->var : pSet->name,
1281 (char*)pSet->def, 0);
1282 @ <br />
1283 }
1284 }
1285 @ </td><td style="width:50px;"></td><td valign="top">
1286 for(pSet=ctrlSettings; pSet->name!=0; pSet++){
1287 if( pSet->width!=0 && pSet->versionable ){
1288 int hasVersionableValue = db_get_do_versionable(pSet->name, NULL)!=0;
1289 @<b>%s(pSet->name)</b> (v)<br />
1290 textarea_attribute("", /*rows*/ 3, /*cols*/ 20, pSet->name,
1291 pSet->var!=0 ? pSet->var : pSet->name,
1292 (char*)pSet->def, hasVersionableValue);
1293 @<br />
1294 }
1295 }
1296 @ </td></tr></table>
 
1297 @ </div></form>
1298 @ <p>Settings marked with (v) are 'versionable' and will be overridden
1299 @ by the contents of files named <tt>.fossil-settings/PROPERTY</tt>.
1300 @ If such a file is present, the corresponding field above is not
1301 @ editable.</p><hr /><p>
@@ -1469,11 +1478,11 @@
1478 @ </div></form>
1479 @ <hr />
1480 @ The default header is shown below for reference. Other examples
1481 @ of headers can be seen on the <a href="setup_skin">skins page</a>.
1482 @ See also the <a href="setup_editcss">CSS</a> and
1483 @ <a href="setup_footer">footer</a> editing screens.
1484 @ <blockquote><pre>
1485 @ %h(zDefaultHeader)
1486 @ </pre></blockquote>
1487 style_footer();
1488 db_end_transaction(0);
1489
+11 -11
--- src/shell.c
+++ src/shell.c
@@ -1891,11 +1891,11 @@
18911891
csv_append_char(p, c);
18921892
c = fgetc(p->in);
18931893
}
18941894
if( c=='\n' ){
18951895
p->nLine++;
1896
- if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1896
+ if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
18971897
}
18981898
p->cTerm = c;
18991899
}
19001900
if( p->z ) p->z[p->n] = 0;
19011901
return p->z;
@@ -3546,15 +3546,17 @@
35463546
char *zFirstCmd = 0;
35473547
int i;
35483548
int rc = 0;
35493549
int warnInmemoryDb = 0;
35503550
3551
- if( sqlite3_libversion_number()<3008003 ){
3552
- fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3",
3553
- sqlite3_libversion());
3551
+#if USE_SYSTEM_SQLITE+0!=1
3552
+ if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
3553
+ fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
3554
+ sqlite3_sourceid(), SQLITE_SOURCE_ID);
35543555
exit(1);
35553556
}
3557
+#endif
35563558
Argv0 = argv[0];
35573559
main_init(&data);
35583560
stdin_is_interactive = isatty(0);
35593561
35603562
/* Make sure we have a valid signal handler early, before anything
@@ -3644,17 +3646,15 @@
36443646
warnInmemoryDb = argc==1;
36453647
#else
36463648
fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
36473649
return 1;
36483650
#endif
3649
- /***** Begin Fossil Patch *****/
3650
- {
3651
- extern void fossil_open(const char **);
3652
- fossil_open(&data.zDbFilename);
3653
- warnInmemoryDb = 0;
3654
- }
3655
- /***** End Fossil Patch *****/
3651
+#ifdef SQLITE_SHELL_DBNAME_PROC
3652
+ { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
3653
+ SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
3654
+ warnInmemoryDb = 0; }
3655
+#endif
36563656
}
36573657
data.out = stdout;
36583658
36593659
/* Go ahead and open the database file if it already exists. If the
36603660
** file does not exist, delay opening it. This prevents empty database
36613661
--- src/shell.c
+++ src/shell.c
@@ -1891,11 +1891,11 @@
1891 csv_append_char(p, c);
1892 c = fgetc(p->in);
1893 }
1894 if( c=='\n' ){
1895 p->nLine++;
1896 if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1897 }
1898 p->cTerm = c;
1899 }
1900 if( p->z ) p->z[p->n] = 0;
1901 return p->z;
@@ -3546,15 +3546,17 @@
3546 char *zFirstCmd = 0;
3547 int i;
3548 int rc = 0;
3549 int warnInmemoryDb = 0;
3550
3551 if( sqlite3_libversion_number()<3008003 ){
3552 fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3",
3553 sqlite3_libversion());
 
3554 exit(1);
3555 }
 
3556 Argv0 = argv[0];
3557 main_init(&data);
3558 stdin_is_interactive = isatty(0);
3559
3560 /* Make sure we have a valid signal handler early, before anything
@@ -3644,17 +3646,15 @@
3644 warnInmemoryDb = argc==1;
3645 #else
3646 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
3647 return 1;
3648 #endif
3649 /***** Begin Fossil Patch *****/
3650 {
3651 extern void fossil_open(const char **);
3652 fossil_open(&data.zDbFilename);
3653 warnInmemoryDb = 0;
3654 }
3655 /***** End Fossil Patch *****/
3656 }
3657 data.out = stdout;
3658
3659 /* Go ahead and open the database file if it already exists. If the
3660 ** file does not exist, delay opening it. This prevents empty database
3661
--- src/shell.c
+++ src/shell.c
@@ -1891,11 +1891,11 @@
1891 csv_append_char(p, c);
1892 c = fgetc(p->in);
1893 }
1894 if( c=='\n' ){
1895 p->nLine++;
1896 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
1897 }
1898 p->cTerm = c;
1899 }
1900 if( p->z ) p->z[p->n] = 0;
1901 return p->z;
@@ -3546,15 +3546,17 @@
3546 char *zFirstCmd = 0;
3547 int i;
3548 int rc = 0;
3549 int warnInmemoryDb = 0;
3550
3551 #if USE_SYSTEM_SQLITE+0!=1
3552 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
3553 fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
3554 sqlite3_sourceid(), SQLITE_SOURCE_ID);
3555 exit(1);
3556 }
3557 #endif
3558 Argv0 = argv[0];
3559 main_init(&data);
3560 stdin_is_interactive = isatty(0);
3561
3562 /* Make sure we have a valid signal handler early, before anything
@@ -3644,17 +3646,15 @@
3646 warnInmemoryDb = argc==1;
3647 #else
3648 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
3649 return 1;
3650 #endif
3651 #ifdef SQLITE_SHELL_DBNAME_PROC
3652 { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
3653 SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
3654 warnInmemoryDb = 0; }
3655 #endif
 
 
3656 }
3657 data.out = stdout;
3658
3659 /* Go ahead and open the database file if it already exists. If the
3660 ** file does not exist, delay opening it. This prevents empty database
3661
+1686 -1576
--- 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.3.1. By combining all the individual C code files into this
3
+** version 3.8.4. 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.
@@ -23,10 +23,64 @@
2323
# define SQLITE_PRIVATE static
2424
#endif
2525
#ifndef SQLITE_API
2626
# define SQLITE_API
2727
#endif
28
+/************** Begin file sqliteInt.h ***************************************/
29
+/*
30
+** 2001 September 15
31
+**
32
+** The author disclaims copyright to this source code. In place of
33
+** a legal notice, here is a blessing:
34
+**
35
+** May you do good and not evil.
36
+** May you find forgiveness for yourself and forgive others.
37
+** May you share freely, never taking more than you give.
38
+**
39
+*************************************************************************
40
+** Internal interface definitions for SQLite.
41
+**
42
+*/
43
+#ifndef _SQLITEINT_H_
44
+#define _SQLITEINT_H_
45
+
46
+/*
47
+** These #defines should enable >2GB file support on POSIX if the
48
+** underlying operating system supports it. If the OS lacks
49
+** large file support, or if the OS is windows, these should be no-ops.
50
+**
51
+** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
52
+** system #includes. Hence, this block of code must be the very first
53
+** code in all source files.
54
+**
55
+** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
56
+** on the compiler command line. This is necessary if you are compiling
57
+** on a recent machine (ex: Red Hat 7.2) but you want your code to work
58
+** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
59
+** without this option, LFS is enable. But LFS does not exist in the kernel
60
+** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
61
+** portability you should omit LFS.
62
+**
63
+** The previous paragraph was written in 2005. (This paragraph is written
64
+** on 2008-11-28.) These days, all Linux kernels support large files, so
65
+** you should probably leave LFS enabled. But some embedded platforms might
66
+** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
67
+**
68
+** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
69
+*/
70
+#ifndef SQLITE_DISABLE_LFS
71
+# define _LARGE_FILE 1
72
+# ifndef _FILE_OFFSET_BITS
73
+# define _FILE_OFFSET_BITS 64
74
+# endif
75
+# define _LARGEFILE_SOURCE 1
76
+#endif
77
+
78
+/* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear
79
+** first in QNX.
80
+*/
81
+/************** Include sqlite3.h in the middle of sqliteInt.h ***************/
2882
/************** Begin file sqlite3.h *****************************************/
2983
/*
3084
** 2001 September 15
3185
**
3286
** The author disclaims copyright to this source code. In place of
@@ -133,13 +187,13 @@
133187
**
134188
** See also: [sqlite3_libversion()],
135189
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136190
** [sqlite_version()] and [sqlite_source_id()].
137191
*/
138
-#define SQLITE_VERSION "3.8.3.1"
139
-#define SQLITE_VERSION_NUMBER 3008003
140
-#define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
192
+#define SQLITE_VERSION "3.8.4"
193
+#define SQLITE_VERSION_NUMBER 3008004
194
+#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
141195
142196
/*
143197
** CAPI3REF: Run-Time Library Version Numbers
144198
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145199
**
@@ -6148,11 +6202,12 @@
61486202
#define SQLITE_TESTCTRL_ISKEYWORD 16
61496203
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
61506204
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
61516205
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
61526206
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6153
-#define SQLITE_TESTCTRL_LAST 20
6207
+#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6208
+#define SQLITE_TESTCTRL_LAST 21
61546209
61556210
/*
61566211
** CAPI3REF: SQLite Runtime Status
61576212
**
61586213
** ^This interface is used to retrieve runtime status information
@@ -7411,54 +7466,11 @@
74117466
74127467
#endif /* ifndef _SQLITE3RTREE_H_ */
74137468
74147469
74157470
/************** End of sqlite3.h *********************************************/
7416
-/************** Begin file sqliteInt.h ***************************************/
7417
-/*
7418
-** 2001 September 15
7419
-**
7420
-** The author disclaims copyright to this source code. In place of
7421
-** a legal notice, here is a blessing:
7422
-**
7423
-** May you do good and not evil.
7424
-** May you find forgiveness for yourself and forgive others.
7425
-** May you share freely, never taking more than you give.
7426
-**
7427
-*************************************************************************
7428
-** Internal interface definitions for SQLite.
7429
-**
7430
-*/
7431
-#ifndef _SQLITEINT_H_
7432
-#define _SQLITEINT_H_
7433
-
7434
-/*
7435
-** These #defines should enable >2GB file support on POSIX if the
7436
-** underlying operating system supports it. If the OS lacks
7437
-** large file support, or if the OS is windows, these should be no-ops.
7438
-**
7439
-** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
7440
-** system #includes. Hence, this block of code must be the very first
7441
-** code in all source files.
7442
-**
7443
-** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
7444
-** on the compiler command line. This is necessary if you are compiling
7445
-** on a recent machine (ex: Red Hat 7.2) but you want your code to work
7446
-** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
7447
-** without this option, LFS is enable. But LFS does not exist in the kernel
7448
-** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
7449
-** portability you should omit LFS.
7450
-**
7451
-** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
7452
-*/
7453
-#ifndef SQLITE_DISABLE_LFS
7454
-# define _LARGE_FILE 1
7455
-# ifndef _FILE_OFFSET_BITS
7456
-# define _FILE_OFFSET_BITS 64
7457
-# endif
7458
-# define _LARGEFILE_SOURCE 1
7459
-#endif
7471
+/************** Continuing where we left off in sqliteInt.h ******************/
74607472
74617473
/*
74627474
** Include the configuration header output by 'configure' if we're using the
74637475
** autoconf-based build
74647476
*/
@@ -8841,12 +8853,10 @@
88418853
SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
88428854
SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
88438855
SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
88448856
SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
88458857
SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8846
-SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8847
-SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
88488858
88498859
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
88508860
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
88518861
88528862
SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
@@ -8982,13 +8992,16 @@
89828992
} p4;
89838993
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
89848994
char *zComment; /* Comment to improve readability */
89858995
#endif
89868996
#ifdef VDBE_PROFILE
8987
- int cnt; /* Number of times this instruction was executed */
8997
+ u32 cnt; /* Number of times this instruction was executed */
89888998
u64 cycles; /* Total time spent executing this instruction */
89898999
#endif
9000
+#ifdef SQLITE_VDBE_COVERAGE
9001
+ int iSrcLine; /* Source-code line that generated this opcode */
9002
+#endif
89909003
};
89919004
typedef struct VdbeOp VdbeOp;
89929005
89939006
89949007
/*
@@ -9094,75 +9107,75 @@
90949107
#define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
90959108
#define OP_Goto 16
90969109
#define OP_Gosub 17
90979110
#define OP_Return 18
90989111
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9099
-#define OP_Yield 20
9100
-#define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */
9101
-#define OP_Halt 22
9102
-#define OP_Integer 23 /* synopsis: r[P2]=P1 */
9103
-#define OP_Int64 24 /* synopsis: r[P2]=P4 */
9104
-#define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9105
-#define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9106
-#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9107
-#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9108
-#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9109
-#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9110
-#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9111
-#define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9112
-#define OP_CollSeq 33
9113
-#define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9114
-#define OP_MustBeInt 35
9115
-#define OP_RealAffinity 36
9116
-#define OP_Permutation 37
9117
-#define OP_Compare 38
9118
-#define OP_Jump 39
9119
-#define OP_Once 40
9120
-#define OP_If 41
9121
-#define OP_IfNot 42
9122
-#define OP_Column 43 /* synopsis: r[P3]=PX */
9123
-#define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */
9124
-#define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9125
-#define OP_Count 46 /* synopsis: r[P2]=count() */
9126
-#define OP_ReadCookie 47
9127
-#define OP_SetCookie 48
9128
-#define OP_VerifyCookie 49
9129
-#define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9130
-#define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9131
-#define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9132
-#define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9133
-#define OP_SorterOpen 54
9134
-#define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9135
-#define OP_Close 56
9136
-#define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9137
-#define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9138
-#define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9139
-#define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9140
-#define OP_Seek 61 /* synopsis: intkey=r[P2] */
9141
-#define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9142
-#define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9143
-#define OP_Found 64 /* synopsis: key=r[P3@P4] */
9144
-#define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9145
-#define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9146
-#define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9147
-#define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
9148
-#define OP_InsertInt 69 /* synopsis: intkey=P3 data=r[P2] */
9149
-#define OP_Delete 70
9112
+#define OP_InitCoroutine 20
9113
+#define OP_EndCoroutine 21
9114
+#define OP_Yield 22
9115
+#define OP_HaltIfNull 23 /* synopsis: if r[P3]=null halt */
9116
+#define OP_Halt 24
9117
+#define OP_Integer 25 /* synopsis: r[P2]=P1 */
9118
+#define OP_Int64 26 /* synopsis: r[P2]=P4 */
9119
+#define OP_String 27 /* synopsis: r[P2]='P4' (len=P1) */
9120
+#define OP_Null 28 /* synopsis: r[P2..P3]=NULL */
9121
+#define OP_SoftNull 29 /* synopsis: r[P1]=NULL */
9122
+#define OP_Blob 30 /* synopsis: r[P2]=P4 (len=P1) */
9123
+#define OP_Variable 31 /* synopsis: r[P2]=parameter(P1,P4) */
9124
+#define OP_Move 32 /* synopsis: r[P2@P3]=r[P1@P3] */
9125
+#define OP_Copy 33 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9126
+#define OP_SCopy 34 /* synopsis: r[P2]=r[P1] */
9127
+#define OP_ResultRow 35 /* synopsis: output=r[P1@P2] */
9128
+#define OP_CollSeq 36
9129
+#define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
9130
+#define OP_MustBeInt 38
9131
+#define OP_RealAffinity 39
9132
+#define OP_Permutation 40
9133
+#define OP_Compare 41
9134
+#define OP_Jump 42
9135
+#define OP_Once 43
9136
+#define OP_If 44
9137
+#define OP_IfNot 45
9138
+#define OP_Column 46 /* synopsis: r[P3]=PX */
9139
+#define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */
9140
+#define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9141
+#define OP_Count 49 /* synopsis: r[P2]=count() */
9142
+#define OP_ReadCookie 50
9143
+#define OP_SetCookie 51
9144
+#define OP_OpenRead 52 /* synopsis: root=P2 iDb=P3 */
9145
+#define OP_OpenWrite 53 /* synopsis: root=P2 iDb=P3 */
9146
+#define OP_OpenAutoindex 54 /* synopsis: nColumn=P2 */
9147
+#define OP_OpenEphemeral 55 /* synopsis: nColumn=P2 */
9148
+#define OP_SorterOpen 56
9149
+#define OP_OpenPseudo 57 /* synopsis: P3 columns in r[P2] */
9150
+#define OP_Close 58
9151
+#define OP_SeekLT 59
9152
+#define OP_SeekLE 60
9153
+#define OP_SeekGE 61
9154
+#define OP_SeekGT 62
9155
+#define OP_Seek 63 /* synopsis: intkey=r[P2] */
9156
+#define OP_NoConflict 64 /* synopsis: key=r[P3@P4] */
9157
+#define OP_NotFound 65 /* synopsis: key=r[P3@P4] */
9158
+#define OP_Found 66 /* synopsis: key=r[P3@P4] */
9159
+#define OP_NotExists 67 /* synopsis: intkey=r[P3] */
9160
+#define OP_Sequence 68 /* synopsis: r[P2]=rowid */
9161
+#define OP_NewRowid 69 /* synopsis: r[P2]=rowid */
9162
+#define OP_Insert 70 /* synopsis: intkey=r[P3] data=r[P2] */
91509163
#define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
91519164
#define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9152
-#define OP_ResetCount 73
9153
-#define OP_SorterCompare 74 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9154
-#define OP_SorterData 75 /* synopsis: r[P2]=data */
9165
+#define OP_InsertInt 73 /* synopsis: intkey=P3 data=r[P2] */
9166
+#define OP_Delete 74
9167
+#define OP_ResetCount 75
91559168
#define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
91569169
#define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
91579170
#define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
91589171
#define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
91599172
#define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
91609173
#define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
91619174
#define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
91629175
#define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9163
-#define OP_RowKey 84 /* synopsis: r[P2]=key */
9176
+#define OP_SorterCompare 84 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
91649177
#define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
91659178
#define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
91669179
#define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
91679180
#define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
91689181
#define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9169,68 +9182,72 @@
91699182
#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
91709183
#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
91719184
#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
91729185
#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
91739186
#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9174
-#define OP_RowData 95 /* synopsis: r[P2]=data */
9187
+#define OP_SorterData 95 /* synopsis: r[P2]=data */
91759188
#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
91769189
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9177
-#define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9178
-#define OP_NullRow 99
9179
-#define OP_Last 100
9180
-#define OP_SorterSort 101
9181
-#define OP_Sort 102
9182
-#define OP_Rewind 103
9183
-#define OP_SorterInsert 104
9184
-#define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9185
-#define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9186
-#define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9187
-#define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9188
-#define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9189
-#define OP_Destroy 110
9190
-#define OP_Clear 111
9191
-#define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9192
-#define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9193
-#define OP_ParseSchema 114
9194
-#define OP_LoadAnalysis 115
9195
-#define OP_DropTable 116
9196
-#define OP_DropIndex 117
9197
-#define OP_DropTrigger 118
9198
-#define OP_IntegrityCk 119
9199
-#define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9200
-#define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9201
-#define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9202
-#define OP_Program 123
9203
-#define OP_Param 124
9204
-#define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9205
-#define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9206
-#define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9207
-#define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9208
-#define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9209
-#define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9210
-#define OP_AggFinal 131 /* synopsis: accum=r[P1] N=P2 */
9211
-#define OP_IncrVacuum 132
9190
+#define OP_RowKey 98 /* synopsis: r[P2]=key */
9191
+#define OP_RowData 99 /* synopsis: r[P2]=data */
9192
+#define OP_Rowid 100 /* synopsis: r[P2]=rowid */
9193
+#define OP_NullRow 101
9194
+#define OP_Last 102
9195
+#define OP_SorterSort 103
9196
+#define OP_Sort 104
9197
+#define OP_Rewind 105
9198
+#define OP_SorterInsert 106
9199
+#define OP_IdxInsert 107 /* synopsis: key=r[P2] */
9200
+#define OP_IdxDelete 108 /* synopsis: key=r[P2@P3] */
9201
+#define OP_IdxRowid 109 /* synopsis: r[P2]=rowid */
9202
+#define OP_IdxLE 110 /* synopsis: key=r[P3@P4] */
9203
+#define OP_IdxGT 111 /* synopsis: key=r[P3@P4] */
9204
+#define OP_IdxLT 112 /* synopsis: key=r[P3@P4] */
9205
+#define OP_IdxGE 113 /* synopsis: key=r[P3@P4] */
9206
+#define OP_Destroy 114
9207
+#define OP_Clear 115
9208
+#define OP_CreateIndex 116 /* synopsis: r[P2]=root iDb=P1 */
9209
+#define OP_CreateTable 117 /* synopsis: r[P2]=root iDb=P1 */
9210
+#define OP_ParseSchema 118
9211
+#define OP_LoadAnalysis 119
9212
+#define OP_DropTable 120
9213
+#define OP_DropIndex 121
9214
+#define OP_DropTrigger 122
9215
+#define OP_IntegrityCk 123
9216
+#define OP_RowSetAdd 124 /* synopsis: rowset(P1)=r[P2] */
9217
+#define OP_RowSetRead 125 /* synopsis: r[P3]=rowset(P1) */
9218
+#define OP_RowSetTest 126 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9219
+#define OP_Program 127
9220
+#define OP_Param 128
9221
+#define OP_FkCounter 129 /* synopsis: fkctr[P1]+=P2 */
9222
+#define OP_FkIfZero 130 /* synopsis: if fkctr[P1]==0 goto P2 */
9223
+#define OP_MemMax 131 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9224
+#define OP_IfPos 132 /* synopsis: if r[P1]>0 goto P2 */
92129225
#define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9213
-#define OP_Expire 134
9214
-#define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9215
-#define OP_VBegin 136
9216
-#define OP_VCreate 137
9217
-#define OP_VDestroy 138
9218
-#define OP_VOpen 139
9219
-#define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9220
-#define OP_VNext 141
9221
-#define OP_VRename 142
9226
+#define OP_IfNeg 134 /* synopsis: if r[P1]<0 goto P2 */
9227
+#define OP_IfZero 135 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9228
+#define OP_AggFinal 136 /* synopsis: accum=r[P1] N=P2 */
9229
+#define OP_IncrVacuum 137
9230
+#define OP_Expire 138
9231
+#define OP_TableLock 139 /* synopsis: iDb=P1 root=P2 write=P3 */
9232
+#define OP_VBegin 140
9233
+#define OP_VCreate 141
9234
+#define OP_VDestroy 142
92229235
#define OP_ToText 143 /* same as TK_TO_TEXT */
92239236
#define OP_ToBlob 144 /* same as TK_TO_BLOB */
92249237
#define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
92259238
#define OP_ToInt 146 /* same as TK_TO_INT */
92269239
#define OP_ToReal 147 /* same as TK_TO_REAL */
9227
-#define OP_Pagecount 148
9228
-#define OP_MaxPgcnt 149
9229
-#define OP_Trace 150
9230
-#define OP_Noop 151
9231
-#define OP_Explain 152
9240
+#define OP_VOpen 148
9241
+#define OP_VColumn 149 /* synopsis: r[P3]=vcolumn(P2) */
9242
+#define OP_VNext 150
9243
+#define OP_VRename 151
9244
+#define OP_Pagecount 152
9245
+#define OP_MaxPgcnt 153
9246
+#define OP_Init 154 /* synopsis: Start at P2 */
9247
+#define OP_Noop 155
9248
+#define OP_Explain 156
92329249
92339250
92349251
/* Properties such as "out2" or "jump" that are specified in
92359252
** comments following the "case" for each opcode in the vdbe.c
92369253
** are encoded into bitvectors as follows:
@@ -9243,28 +9260,28 @@
92439260
#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
92449261
#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
92459262
#define OPFLG_INITIALIZER {\
92469263
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
92479264
/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9248
-/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9249
-/* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9250
-/* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9251
-/* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9252
-/* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9253
-/* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9254
-/* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c,\
9265
+/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9266
+/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9267
+/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9268
+/* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\
9269
+/* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\
9270
+/* 56 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
9271
+/* 64 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c,\
92559272
/* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
92569273
/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
92579274
/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9258
-/* 96 */ 0x24, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9259
-/* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9260
-/* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9261
-/* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9262
-/* 128 */ 0x05, 0x05, 0x05, 0x00, 0x01, 0x02, 0x00, 0x00,\
9263
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,\
9264
-/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00,\
9265
-/* 152 */ 0x00,}
9275
+/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
9276
+/* 104 */ 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01,\
9277
+/* 112 */ 0x01, 0x01, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00,\
9278
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45, 0x15, 0x01,\
9279
+/* 128 */ 0x02, 0x00, 0x01, 0x08, 0x05, 0x02, 0x05, 0x05,\
9280
+/* 136 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,\
9281
+/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x01, 0x00,\
9282
+/* 152 */ 0x02, 0x02, 0x01, 0x00, 0x00,}
92669283
92679284
/************** End of opcodes.h *********************************************/
92689285
/************** Continuing where we left off in vdbe.h ***********************/
92699286
92709287
/*
@@ -9276,11 +9293,11 @@
92769293
SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
92779294
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
92789295
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
92799296
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
92809297
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
9281
-SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
9298
+SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
92829299
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
92839300
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
92849301
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
92859302
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
92869303
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
@@ -9347,10 +9364,45 @@
93479364
# define VdbeComment(X)
93489365
# define VdbeNoopComment(X)
93499366
# define VdbeModuleComment(X)
93509367
#endif
93519368
9369
+/*
9370
+** The VdbeCoverage macros are used to set a coverage testing point
9371
+** for VDBE branch instructions. The coverage testing points are line
9372
+** numbers in the sqlite3.c source file. VDBE branch coverage testing
9373
+** only works with an amalagmation build. That's ok since a VDBE branch
9374
+** coverage build designed for testing the test suite only. No application
9375
+** should ever ship with VDBE branch coverage measuring turned on.
9376
+**
9377
+** VdbeCoverage(v) // Mark the previously coded instruction
9378
+** // as a branch
9379
+**
9380
+** VdbeCoverageIf(v, conditional) // Mark previous if conditional true
9381
+**
9382
+** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken
9383
+**
9384
+** VdbeCoverageNeverTaken(v) // Previous branch is never taken
9385
+**
9386
+** Every VDBE branch operation must be tagged with one of the macros above.
9387
+** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
9388
+** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
9389
+** routine in vdbe.c, alerting the developer to the missed tag.
9390
+*/
9391
+#ifdef SQLITE_VDBE_COVERAGE
9392
+SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe*,int);
9393
+# define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
9394
+# define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
9395
+# define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2);
9396
+# define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1);
9397
+#else
9398
+# define VdbeCoverage(v)
9399
+# define VdbeCoverageIf(v,x)
9400
+# define VdbeCoverageAlwaysTaken(v)
9401
+# define VdbeCoverageNeverTaken(v)
9402
+#endif
9403
+
93529404
#endif
93539405
93549406
/************** End of vdbe.h ************************************************/
93559407
/************** Continuing where we left off in sqliteInt.h ******************/
93569408
/************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -10404,12 +10456,11 @@
1040410456
1040510457
/*
1040610458
** Return true if it OK to factor constant expressions into the initialization
1040710459
** code. The argument is a Parse object for the code generator.
1040810460
*/
10409
-#define ConstFactorOk(P) \
10410
- ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))
10461
+#define ConstFactorOk(P) ((P)->okConstFactor)
1041110462
1041210463
/*
1041310464
** Possible values for the sqlite.magic field.
1041410465
** The numbers are obtained at random and have no special meaning, other
1041510466
** than being distinct from one another.
@@ -10631,14 +10682,20 @@
1063110682
#define SQLITE_AFF_MASK 0x67
1063210683
1063310684
/*
1063410685
** Additional bit values that can be ORed with an affinity without
1063510686
** changing the affinity.
10687
+**
10688
+** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
10689
+** It causes an assert() to fire if either operand to a comparison
10690
+** operator is NULL. It is added to certain comparison operators to
10691
+** prove that the operands are always NOT NULL.
1063610692
*/
1063710693
#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
1063810694
#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
1063910695
#define SQLITE_NULLEQ 0x80 /* NULL=NULL */
10696
+#define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */
1064010697
1064110698
/*
1064210699
** An object of this type is created for each virtual table present in
1064310700
** the database schema.
1064410701
**
@@ -11336,10 +11393,11 @@
1133611393
char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
1133711394
Table *pTab; /* An SQL table corresponding to zName */
1133811395
Select *pSelect; /* A SELECT statement used in place of a table name */
1133911396
int addrFillSub; /* Address of subroutine to manifest a subquery */
1134011397
int regReturn; /* Register holding return address of addrFillSub */
11398
+ int regResult; /* Registers holding results of a co-routine */
1134111399
u8 jointype; /* Type of join between this able and the previous */
1134211400
unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
1134311401
unsigned isCorrelated :1; /* True if sub-query is correlated */
1134411402
unsigned viaCoroutine :1; /* Implemented as a co-routine */
1134511403
unsigned isRecursive :1; /* True for recursive reference in WITH */
@@ -11464,11 +11522,10 @@
1146411522
ExprList *pGroupBy; /* The GROUP BY clause */
1146511523
Expr *pHaving; /* The HAVING clause */
1146611524
ExprList *pOrderBy; /* The ORDER BY clause */
1146711525
Select *pPrior; /* Prior select in a compound select statement */
1146811526
Select *pNext; /* Next select to the left in a compound */
11469
- Select *pRightmost; /* Right-most select in a compound select statement */
1147011527
Expr *pLimit; /* LIMIT expression. NULL means not used. */
1147111528
Expr *pOffset; /* OFFSET expression. NULL means not used. */
1147211529
With *pWith; /* WITH clause attached to this select. Or NULL. */
1147311530
};
1147411531
@@ -11482,14 +11539,15 @@
1148211539
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1148311540
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1148411541
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
1148511542
#define SF_UseSorter 0x0040 /* Sort using a sorter */
1148611543
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
11487
-#define SF_Materialize 0x0100 /* Force materialization of views */
11544
+#define SF_Materialize 0x0100 /* NOT USED */
1148811545
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1148911546
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1149011547
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11548
+#define SF_Compound 0x1000 /* Part of a compound query */
1149111549
1149211550
1149311551
/*
1149411552
** The results of a SELECT can be distributed in several ways, as defined
1149511553
** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -11664,49 +11722,48 @@
1166411722
int rc; /* Return code from execution */
1166511723
u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
1166611724
u8 checkSchema; /* Causes schema cookie check after an error */
1166711725
u8 nested; /* Number of nested calls to the parser/code generator */
1166811726
u8 nTempReg; /* Number of temporary registers in aTempReg[] */
11669
- u8 nTempInUse; /* Number of aTempReg[] currently checked out */
1167011727
u8 nColCache; /* Number of entries in aColCache[] */
1167111728
u8 iColCache; /* Next entry in aColCache[] to replace */
1167211729
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
1167311730
u8 mayAbort; /* True if statement may throw an ABORT exception */
1167411731
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
11732
+ u8 okConstFactor; /* OK to factor out constants */
1167511733
int aTempReg[8]; /* Holding area for temporary registers */
1167611734
int nRangeReg; /* Size of the temporary register block */
1167711735
int iRangeReg; /* First register in temporary register block */
1167811736
int nErr; /* Number of errors seen */
1167911737
int nTab; /* Number of previously allocated VDBE cursors */
1168011738
int nMem; /* Number of memory cells used so far */
1168111739
int nSet; /* Number of sets used so far */
1168211740
int nOnce; /* Number of OP_Once instructions so far */
1168311741
int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11684
- int nLabel; /* Number of labels used */
11685
- int *aLabel; /* Space to hold the labels */
1168611742
int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
1168711743
int ckBase; /* Base register of data during check constraints */
1168811744
int iPartIdxTab; /* Table corresponding to a partial index */
1168911745
int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
1169011746
int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11747
+ int nLabel; /* Number of labels used */
11748
+ int *aLabel; /* Space to hold the labels */
1169111749
struct yColCache {
1169211750
int iTable; /* Table cursor number */
11693
- int iColumn; /* Table column number */
11751
+ i16 iColumn; /* Table column number */
1169411752
u8 tempReg; /* iReg is a temp register that needs to be freed */
1169511753
int iLevel; /* Nesting level */
1169611754
int iReg; /* Reg with value of this column. 0 means none. */
1169711755
int lru; /* Least recently used entry has the smallest value */
1169811756
} aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
1169911757
ExprList *pConstExpr;/* Constant expressions */
11758
+ Token constraintName;/* Name of the constraint currently being parsed */
1170011759
yDbMask writeMask; /* Start a write transaction on these databases */
1170111760
yDbMask cookieMask; /* Bitmask of schema verified databases */
11702
- int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
1170311761
int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
1170411762
int regRowid; /* Register holding rowid of CREATE TABLE entry */
1170511763
int regRoot; /* Register holding root page number for new objects */
1170611764
int nMaxArg; /* Max args passed to user function by sub-program */
11707
- Token constraintName;/* Name of the constraint currently being parsed */
1170811765
#ifndef SQLITE_OMIT_SHARED_CACHE
1170911766
int nTableLock; /* Number of locks in aTableLock */
1171011767
TableLock *aTableLock; /* Required table locks for shared-cache mode */
1171111768
#endif
1171211769
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -11721,16 +11778,21 @@
1172111778
u32 newmask; /* Mask of new.* columns referenced */
1172211779
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
1172311780
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
1172411781
u8 disableTriggers; /* True to disable triggers */
1172511782
11726
- /* Above is constant between recursions. Below is reset before and after
11727
- ** each recursion */
11783
+ /************************************************************************
11784
+ ** Above is constant between recursions. Below is reset before and after
11785
+ ** each recursion. The boundary between these two regions is determined
11786
+ ** using offsetof(Parse,nVar) so the nVar field must be the first field
11787
+ ** in the recursive region.
11788
+ ************************************************************************/
1172811789
1172911790
int nVar; /* Number of '?' variables seen in the SQL so far */
1173011791
int nzVar; /* Number of available slots in azVar[] */
1173111792
u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
11793
+ u8 bFreeWith; /* True if pWith should be freed with parser */
1173211794
u8 explain; /* True if the EXPLAIN flag is found on the query */
1173311795
#ifndef SQLITE_OMIT_VIRTUALTABLE
1173411796
u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
1173511797
int nVtabLock; /* Number of virtual tables to lock */
1173611798
#endif
@@ -11753,11 +11815,10 @@
1175311815
Table **apVtabLock; /* Pointer to virtual tables needing locking */
1175411816
#endif
1175511817
Table *pZombieTab; /* List of Table objects to delete after code gen */
1175611818
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
1175711819
With *pWith; /* Current WITH clause, or NULL */
11758
- u8 bFreeWith; /* True if pWith should be freed with parser */
1175911820
};
1176011821
1176111822
/*
1176211823
** Return true if currently inside an sqlite3_declare_vtab() call.
1176311824
*/
@@ -11969,10 +12030,17 @@
1196912030
int bLocaltimeFault; /* True to fail localtime() calls */
1197012031
#ifdef SQLITE_ENABLE_SQLLOG
1197112032
void(*xSqllog)(void*,sqlite3*,const char*, int);
1197212033
void *pSqllogArg;
1197312034
#endif
12035
+#ifdef SQLITE_VDBE_COVERAGE
12036
+ /* The following callback (if not NULL) is invoked on every VDBE branch
12037
+ ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
12038
+ */
12039
+ void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
12040
+ void *pVdbeBranchArg; /* 1st argument */
12041
+#endif
1197412042
};
1197512043
1197612044
/*
1197712045
** This macro is used inside of assert() statements to indicate that
1197812046
** the assert is only valid on a well-formed database. Instead of:
@@ -12302,11 +12370,10 @@
1230212370
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
1230312371
#else
1230412372
# define sqlite3AutoincrementBegin(X)
1230512373
# define sqlite3AutoincrementEnd(X)
1230612374
#endif
12307
-SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse*, Select*, SelectDest*);
1230812375
SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int);
1230912376
SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
1231012377
SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
1231112378
SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
1231212379
SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -12350,15 +12417,16 @@
1235012417
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
1235112418
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
1235212419
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
1235312420
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
1235412421
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12355
-SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12422
+SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
12423
+SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
1235612424
SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
1235712425
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1235812426
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12359
-SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12427
+SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
1236012428
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
1236112429
#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
1236212430
#define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
1236312431
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1236412432
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
@@ -12392,11 +12460,10 @@
1239212460
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1239312461
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1239412462
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
1239512463
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1239612464
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12397
-SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
1239812465
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
1239912466
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
1240012467
SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
1240112468
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
1240212469
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
@@ -12536,11 +12603,11 @@
1253612603
#define getVarint sqlite3GetVarint
1253712604
#define putVarint sqlite3PutVarint
1253812605
1253912606
1254012607
SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
12541
-SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
12608
+SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
1254212609
SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
1254312610
SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
1254412611
SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
1254512612
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
1254612613
SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
@@ -13640,11 +13707,10 @@
1364013707
u8 rowidIsValid; /* True if lastRowid is valid */
1364113708
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1364213709
Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
1364313710
Bool isTable:1; /* True if a table requiring integer keys */
1364413711
Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13645
- Bool multiPseudo:1; /* Multi-register pseudo-cursor */
1364613712
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1364713713
i64 seqCount; /* Sequence counter */
1364813714
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1364913715
i64 lastRowid; /* Rowid being deleted by OP_Delete */
1365013716
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -13734,11 +13800,11 @@
1373413800
RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
1373513801
VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
1373613802
} u;
1373713803
int n; /* Number of characters in string value, excluding '\0' */
1373813804
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
13739
- u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
13805
+ u8 memType; /* Lower 5 bits of flags */
1374013806
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
1374113807
#ifdef SQLITE_DEBUG
1374213808
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
1374313809
void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
1374413810
#endif
@@ -13763,11 +13829,11 @@
1376313829
#define MEM_Int 0x0004 /* Value is an integer */
1376413830
#define MEM_Real 0x0008 /* Value is a real number */
1376513831
#define MEM_Blob 0x0010 /* Value is a BLOB */
1376613832
#define MEM_RowSet 0x0020 /* Value is a RowSet object */
1376713833
#define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
13768
-#define MEM_Invalid 0x0080 /* Value is undefined */
13834
+#define MEM_Undefined 0x0080 /* Value is undefined */
1376913835
#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
1377013836
#define MEM_TypeMask 0x01ff /* Mask of type bits */
1377113837
1377213838
1377313839
/* Whenever Mem contains a valid string or blob representation, one of
@@ -13795,11 +13861,11 @@
1379513861
/*
1379613862
** Return true if a memory cell is not marked as invalid. This macro
1379713863
** is for use inside assert() statements only.
1379813864
*/
1379913865
#ifdef SQLITE_DEBUG
13800
-#define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13866
+#define memIsValid(M) ((M)->flags & MEM_Undefined)==0
1380113867
#endif
1380213868
1380313869
/*
1380413870
** Each auxilliary data pointer stored by a user defined function
1380513871
** implementation calling sqlite3_set_auxdata() is stored in an instance
@@ -13990,20 +14056,22 @@
1399014056
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
1399114057
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
1399214058
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
1399314059
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
1399414060
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
14061
+#define VdbeMemDynamic(X) \
14062
+ (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
1399514063
#define VdbeMemRelease(X) \
13996
- if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
13997
- sqlite3VdbeMemReleaseExternal(X);
14064
+ if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X);
1399814065
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
1399914066
SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
1400014067
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
1400114068
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
1400214069
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
1400314070
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14004
-SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
14071
+#define sqlite3VdbeMemStoreType(X) (X)->memType = (u8)((X)->flags&0x1f)
14072
+/* void sqlite3VdbeMemStoreType(Mem *pMem); */
1400514073
SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
1400614074
1400714075
SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
1400814076
SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
1400914077
SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
@@ -17767,10 +17835,16 @@
1776717835
mem5.totalExcess += iFullSz - nByte;
1776817836
mem5.currentCount++;
1776917837
mem5.currentOut += iFullSz;
1777017838
if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
1777117839
if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
17840
+
17841
+#ifdef SQLITE_DEBUG
17842
+ /* Make sure the allocated memory does not assume that it is set to zero
17843
+ ** or retains a value from a previous allocation */
17844
+ memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz);
17845
+#endif
1777217846
1777317847
/* Return a pointer to the allocated memory. */
1777417848
return (void*)&mem5.zPool[i*mem5.szAtom];
1777517849
}
1777617850
@@ -17825,10 +17899,17 @@
1782517899
mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
1782617900
mem5.aCtrl[iBuddy] = 0;
1782717901
}
1782817902
size *= 2;
1782917903
}
17904
+
17905
+#ifdef SQLITE_DEBUG
17906
+ /* Overwrite freed memory with the 0x55 bit pattern to verify that it is
17907
+ ** not used after being freed */
17908
+ memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size);
17909
+#endif
17910
+
1783017911
memsys5Link(iBlock, iLogsize);
1783117912
}
1783217913
1783317914
/*
1783417915
** Allocate nBytes of memory.
@@ -22728,17 +22809,16 @@
2272822809
testcase( iB==-1 ); testcase( iB==0 );
2272922810
if( iB>=0 ){
2273022811
testcase( iA>0 && LARGEST_INT64 - iA == iB );
2273122812
testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
2273222813
if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
22733
- *pA += iB;
2273422814
}else{
2273522815
testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
2273622816
testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
2273722817
if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
22738
- *pA += iB;
2273922818
}
22819
+ *pA += iB;
2274022820
return 0;
2274122821
}
2274222822
SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
2274322823
testcase( iB==SMALLEST_INT64+1 );
2274422824
if( iB==SMALLEST_INT64 ){
@@ -22758,13 +22838,22 @@
2275822838
2275922839
iA1 = iA/TWOPOWER32;
2276022840
iA0 = iA % TWOPOWER32;
2276122841
iB1 = iB/TWOPOWER32;
2276222842
iB0 = iB % TWOPOWER32;
22763
- if( iA1*iB1 != 0 ) return 1;
22764
- assert( iA1*iB0==0 || iA0*iB1==0 );
22765
- r = iA1*iB0 + iA0*iB1;
22843
+ if( iA1==0 ){
22844
+ if( iB1==0 ){
22845
+ *pA *= iB;
22846
+ return 0;
22847
+ }
22848
+ r = iA0*iB1;
22849
+ }else if( iB1==0 ){
22850
+ r = iA1*iB0;
22851
+ }else{
22852
+ /* If both iA1 and iB1 are non-zero, overflow will result */
22853
+ return 1;
22854
+ }
2276622855
testcase( r==(-TWOPOWER31)-1 );
2276722856
testcase( r==(-TWOPOWER31) );
2276822857
testcase( r==TWOPOWER31 );
2276922858
testcase( r==TWOPOWER31-1 );
2277022859
if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
@@ -23206,75 +23295,75 @@
2320623295
/* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
2320723296
/* 16 */ "Goto" OpHelp(""),
2320823297
/* 17 */ "Gosub" OpHelp(""),
2320923298
/* 18 */ "Return" OpHelp(""),
2321023299
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
23211
- /* 20 */ "Yield" OpHelp(""),
23212
- /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
23213
- /* 22 */ "Halt" OpHelp(""),
23214
- /* 23 */ "Integer" OpHelp("r[P2]=P1"),
23215
- /* 24 */ "Int64" OpHelp("r[P2]=P4"),
23216
- /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23217
- /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
23218
- /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23219
- /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23220
- /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23221
- /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23222
- /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23223
- /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23224
- /* 33 */ "CollSeq" OpHelp(""),
23225
- /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23226
- /* 35 */ "MustBeInt" OpHelp(""),
23227
- /* 36 */ "RealAffinity" OpHelp(""),
23228
- /* 37 */ "Permutation" OpHelp(""),
23229
- /* 38 */ "Compare" OpHelp(""),
23230
- /* 39 */ "Jump" OpHelp(""),
23231
- /* 40 */ "Once" OpHelp(""),
23232
- /* 41 */ "If" OpHelp(""),
23233
- /* 42 */ "IfNot" OpHelp(""),
23234
- /* 43 */ "Column" OpHelp("r[P3]=PX"),
23235
- /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23236
- /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23237
- /* 46 */ "Count" OpHelp("r[P2]=count()"),
23238
- /* 47 */ "ReadCookie" OpHelp(""),
23239
- /* 48 */ "SetCookie" OpHelp(""),
23240
- /* 49 */ "VerifyCookie" OpHelp(""),
23241
- /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23242
- /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23243
- /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23244
- /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23245
- /* 54 */ "SorterOpen" OpHelp(""),
23246
- /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23247
- /* 56 */ "Close" OpHelp(""),
23248
- /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23249
- /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23250
- /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23251
- /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23252
- /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23253
- /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23254
- /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23255
- /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23256
- /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23257
- /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23258
- /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23259
- /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23260
- /* 69 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23261
- /* 70 */ "Delete" OpHelp(""),
23300
+ /* 20 */ "InitCoroutine" OpHelp(""),
23301
+ /* 21 */ "EndCoroutine" OpHelp(""),
23302
+ /* 22 */ "Yield" OpHelp(""),
23303
+ /* 23 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
23304
+ /* 24 */ "Halt" OpHelp(""),
23305
+ /* 25 */ "Integer" OpHelp("r[P2]=P1"),
23306
+ /* 26 */ "Int64" OpHelp("r[P2]=P4"),
23307
+ /* 27 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23308
+ /* 28 */ "Null" OpHelp("r[P2..P3]=NULL"),
23309
+ /* 29 */ "SoftNull" OpHelp("r[P1]=NULL"),
23310
+ /* 30 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23311
+ /* 31 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23312
+ /* 32 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23313
+ /* 33 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23314
+ /* 34 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23315
+ /* 35 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23316
+ /* 36 */ "CollSeq" OpHelp(""),
23317
+ /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23318
+ /* 38 */ "MustBeInt" OpHelp(""),
23319
+ /* 39 */ "RealAffinity" OpHelp(""),
23320
+ /* 40 */ "Permutation" OpHelp(""),
23321
+ /* 41 */ "Compare" OpHelp(""),
23322
+ /* 42 */ "Jump" OpHelp(""),
23323
+ /* 43 */ "Once" OpHelp(""),
23324
+ /* 44 */ "If" OpHelp(""),
23325
+ /* 45 */ "IfNot" OpHelp(""),
23326
+ /* 46 */ "Column" OpHelp("r[P3]=PX"),
23327
+ /* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23328
+ /* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23329
+ /* 49 */ "Count" OpHelp("r[P2]=count()"),
23330
+ /* 50 */ "ReadCookie" OpHelp(""),
23331
+ /* 51 */ "SetCookie" OpHelp(""),
23332
+ /* 52 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23333
+ /* 53 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23334
+ /* 54 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23335
+ /* 55 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23336
+ /* 56 */ "SorterOpen" OpHelp(""),
23337
+ /* 57 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23338
+ /* 58 */ "Close" OpHelp(""),
23339
+ /* 59 */ "SeekLT" OpHelp(""),
23340
+ /* 60 */ "SeekLE" OpHelp(""),
23341
+ /* 61 */ "SeekGE" OpHelp(""),
23342
+ /* 62 */ "SeekGT" OpHelp(""),
23343
+ /* 63 */ "Seek" OpHelp("intkey=r[P2]"),
23344
+ /* 64 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23345
+ /* 65 */ "NotFound" OpHelp("key=r[P3@P4]"),
23346
+ /* 66 */ "Found" OpHelp("key=r[P3@P4]"),
23347
+ /* 67 */ "NotExists" OpHelp("intkey=r[P3]"),
23348
+ /* 68 */ "Sequence" OpHelp("r[P2]=rowid"),
23349
+ /* 69 */ "NewRowid" OpHelp("r[P2]=rowid"),
23350
+ /* 70 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
2326223351
/* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
2326323352
/* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23264
- /* 73 */ "ResetCount" OpHelp(""),
23265
- /* 74 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23266
- /* 75 */ "SorterData" OpHelp("r[P2]=data"),
23353
+ /* 73 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23354
+ /* 74 */ "Delete" OpHelp(""),
23355
+ /* 75 */ "ResetCount" OpHelp(""),
2326723356
/* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
2326823357
/* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
2326923358
/* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
2327023359
/* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
2327123360
/* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
2327223361
/* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
2327323362
/* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
2327423363
/* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23275
- /* 84 */ "RowKey" OpHelp("r[P2]=key"),
23364
+ /* 84 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
2327623365
/* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
2327723366
/* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
2327823367
/* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
2327923368
/* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
2328023369
/* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23281,68 +23370,72 @@
2328123370
/* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2328223371
/* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
2328323372
/* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
2328423373
/* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2328523374
/* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23286
- /* 95 */ "RowData" OpHelp("r[P2]=data"),
23375
+ /* 95 */ "SorterData" OpHelp("r[P2]=data"),
2328723376
/* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2328823377
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
23289
- /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23290
- /* 99 */ "NullRow" OpHelp(""),
23291
- /* 100 */ "Last" OpHelp(""),
23292
- /* 101 */ "SorterSort" OpHelp(""),
23293
- /* 102 */ "Sort" OpHelp(""),
23294
- /* 103 */ "Rewind" OpHelp(""),
23295
- /* 104 */ "SorterInsert" OpHelp(""),
23296
- /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23297
- /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23298
- /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23299
- /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23300
- /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23301
- /* 110 */ "Destroy" OpHelp(""),
23302
- /* 111 */ "Clear" OpHelp(""),
23303
- /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23304
- /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23305
- /* 114 */ "ParseSchema" OpHelp(""),
23306
- /* 115 */ "LoadAnalysis" OpHelp(""),
23307
- /* 116 */ "DropTable" OpHelp(""),
23308
- /* 117 */ "DropIndex" OpHelp(""),
23309
- /* 118 */ "DropTrigger" OpHelp(""),
23310
- /* 119 */ "IntegrityCk" OpHelp(""),
23311
- /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23312
- /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23313
- /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23314
- /* 123 */ "Program" OpHelp(""),
23315
- /* 124 */ "Param" OpHelp(""),
23316
- /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23317
- /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23318
- /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23319
- /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23320
- /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23321
- /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23322
- /* 131 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23323
- /* 132 */ "IncrVacuum" OpHelp(""),
23378
+ /* 98 */ "RowKey" OpHelp("r[P2]=key"),
23379
+ /* 99 */ "RowData" OpHelp("r[P2]=data"),
23380
+ /* 100 */ "Rowid" OpHelp("r[P2]=rowid"),
23381
+ /* 101 */ "NullRow" OpHelp(""),
23382
+ /* 102 */ "Last" OpHelp(""),
23383
+ /* 103 */ "SorterSort" OpHelp(""),
23384
+ /* 104 */ "Sort" OpHelp(""),
23385
+ /* 105 */ "Rewind" OpHelp(""),
23386
+ /* 106 */ "SorterInsert" OpHelp(""),
23387
+ /* 107 */ "IdxInsert" OpHelp("key=r[P2]"),
23388
+ /* 108 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23389
+ /* 109 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23390
+ /* 110 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23391
+ /* 111 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23392
+ /* 112 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23393
+ /* 113 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23394
+ /* 114 */ "Destroy" OpHelp(""),
23395
+ /* 115 */ "Clear" OpHelp(""),
23396
+ /* 116 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23397
+ /* 117 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23398
+ /* 118 */ "ParseSchema" OpHelp(""),
23399
+ /* 119 */ "LoadAnalysis" OpHelp(""),
23400
+ /* 120 */ "DropTable" OpHelp(""),
23401
+ /* 121 */ "DropIndex" OpHelp(""),
23402
+ /* 122 */ "DropTrigger" OpHelp(""),
23403
+ /* 123 */ "IntegrityCk" OpHelp(""),
23404
+ /* 124 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23405
+ /* 125 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23406
+ /* 126 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23407
+ /* 127 */ "Program" OpHelp(""),
23408
+ /* 128 */ "Param" OpHelp(""),
23409
+ /* 129 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23410
+ /* 130 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23411
+ /* 131 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23412
+ /* 132 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
2332423413
/* 133 */ "Real" OpHelp("r[P2]=P4"),
23325
- /* 134 */ "Expire" OpHelp(""),
23326
- /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23327
- /* 136 */ "VBegin" OpHelp(""),
23328
- /* 137 */ "VCreate" OpHelp(""),
23329
- /* 138 */ "VDestroy" OpHelp(""),
23330
- /* 139 */ "VOpen" OpHelp(""),
23331
- /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23332
- /* 141 */ "VNext" OpHelp(""),
23333
- /* 142 */ "VRename" OpHelp(""),
23414
+ /* 134 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23415
+ /* 135 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23416
+ /* 136 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23417
+ /* 137 */ "IncrVacuum" OpHelp(""),
23418
+ /* 138 */ "Expire" OpHelp(""),
23419
+ /* 139 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23420
+ /* 140 */ "VBegin" OpHelp(""),
23421
+ /* 141 */ "VCreate" OpHelp(""),
23422
+ /* 142 */ "VDestroy" OpHelp(""),
2333423423
/* 143 */ "ToText" OpHelp(""),
2333523424
/* 144 */ "ToBlob" OpHelp(""),
2333623425
/* 145 */ "ToNumeric" OpHelp(""),
2333723426
/* 146 */ "ToInt" OpHelp(""),
2333823427
/* 147 */ "ToReal" OpHelp(""),
23339
- /* 148 */ "Pagecount" OpHelp(""),
23340
- /* 149 */ "MaxPgcnt" OpHelp(""),
23341
- /* 150 */ "Trace" OpHelp(""),
23342
- /* 151 */ "Noop" OpHelp(""),
23343
- /* 152 */ "Explain" OpHelp(""),
23428
+ /* 148 */ "VOpen" OpHelp(""),
23429
+ /* 149 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23430
+ /* 150 */ "VNext" OpHelp(""),
23431
+ /* 151 */ "VRename" OpHelp(""),
23432
+ /* 152 */ "Pagecount" OpHelp(""),
23433
+ /* 153 */ "MaxPgcnt" OpHelp(""),
23434
+ /* 154 */ "Init" OpHelp("Start at P2"),
23435
+ /* 155 */ "Noop" OpHelp(""),
23436
+ /* 156 */ "Explain" OpHelp(""),
2334423437
};
2334523438
return azName[i];
2334623439
}
2334723440
#endif
2334823441
@@ -23430,36 +23523,10 @@
2343023523
# else
2343123524
# define OS_VXWORKS 0
2343223525
# endif
2343323526
#endif
2343423527
23435
-/*
23436
-** These #defines should enable >2GB file support on Posix if the
23437
-** underlying operating system supports it. If the OS lacks
23438
-** large file support, these should be no-ops.
23439
-**
23440
-** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
23441
-** on the compiler command line. This is necessary if you are compiling
23442
-** on a recent machine (ex: RedHat 7.2) but you want your code to work
23443
-** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
23444
-** without this option, LFS is enable. But LFS does not exist in the kernel
23445
-** in RedHat 6.0, so the code won't work. Hence, for maximum binary
23446
-** portability you should omit LFS.
23447
-**
23448
-** The previous paragraph was written in 2005. (This paragraph is written
23449
-** on 2008-11-28.) These days, all Linux kernels support large files, so
23450
-** you should probably leave LFS enabled. But some embedded platforms might
23451
-** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
23452
-*/
23453
-#ifndef SQLITE_DISABLE_LFS
23454
-# define _LARGE_FILE 1
23455
-# ifndef _FILE_OFFSET_BITS
23456
-# define _FILE_OFFSET_BITS 64
23457
-# endif
23458
-# define _LARGEFILE_SOURCE 1
23459
-#endif
23460
-
2346123528
/*
2346223529
** standard include files.
2346323530
*/
2346423531
#include <sys/types.h>
2346523532
#include <sys/stat.h>
@@ -34444,11 +34511,11 @@
3444434511
** Windows will only let you create file view mappings
3444534512
** on allocation size granularity boundaries.
3444634513
** During sqlite3_os_init() we do a GetSystemInfo()
3444734514
** to get the granularity size.
3444834515
*/
34449
-SYSTEM_INFO winSysInfo;
34516
+static SYSTEM_INFO winSysInfo;
3445034517
3445134518
#ifndef SQLITE_OMIT_WAL
3445234519
3445334520
/*
3445434521
** Helper functions to obtain and relinquish the global mutex. The
@@ -36378,19 +36445,16 @@
3637836445
#ifndef SQLITE_OMIT_LOAD_EXTENSION
3637936446
/*
3638036447
** Interfaces for opening a shared library, finding entry points
3638136448
** within the shared library, and closing the shared library.
3638236449
*/
36383
-/*
36384
-** Interfaces for opening a shared library, finding entry points
36385
-** within the shared library, and closing the shared library.
36386
-*/
3638736450
static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
3638836451
HANDLE h;
3638936452
void *zConverted = winConvertFromUtf8Filename(zFilename);
3639036453
UNUSED_PARAMETER(pVfs);
3639136454
if( zConverted==0 ){
36455
+ OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
3639236456
return 0;
3639336457
}
3639436458
if( osIsNT() ){
3639536459
#if SQLITE_OS_WINRT
3639636460
h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
@@ -36401,24 +36465,30 @@
3640136465
#ifdef SQLITE_WIN32_HAS_ANSI
3640236466
else{
3640336467
h = osLoadLibraryA((char*)zConverted);
3640436468
}
3640536469
#endif
36470
+ OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
3640636471
sqlite3_free(zConverted);
3640736472
return (void*)h;
3640836473
}
3640936474
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
3641036475
UNUSED_PARAMETER(pVfs);
3641136476
winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
3641236477
}
3641336478
static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
36479
+ FARPROC proc;
3641436480
UNUSED_PARAMETER(pVfs);
36415
- return (void(*)(void))osGetProcAddressA((HANDLE)pH, zSym);
36481
+ proc = osGetProcAddressA((HANDLE)pH, zSym);
36482
+ OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n",
36483
+ (void*)pH, zSym, (void*)proc));
36484
+ return (void(*)(void))proc;
3641636485
}
3641736486
static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
3641836487
UNUSED_PARAMETER(pVfs);
3641936488
osFreeLibrary((HANDLE)pHandle);
36489
+ OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
3642036490
}
3642136491
#else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
3642236492
#define winDlOpen 0
3642336493
#define winDlError 0
3642436494
#define winDlSym 0
@@ -37110,11 +37180,12 @@
3711037180
PgHdr *pSynced; /* Last synced page in dirty page list */
3711137181
int nRef; /* Number of referenced pages */
3711237182
int szCache; /* Configured cache size */
3711337183
int szPage; /* Size of every page in this cache */
3711437184
int szExtra; /* Size of extra space for each page */
37115
- int bPurgeable; /* True if pages are on backing store */
37185
+ u8 bPurgeable; /* True if pages are on backing store */
37186
+ u8 eCreate; /* eCreate value for for xFetch() */
3711637187
int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
3711737188
void *pStress; /* Argument to xStress */
3711837189
sqlite3_pcache *pCache; /* Pluggable cache module */
3711937190
PgHdr *pPage1; /* Reference to page 1 */
3712037191
};
@@ -37177,10 +37248,14 @@
3717737248
if( pPage->pDirtyPrev ){
3717837249
pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
3717937250
}else{
3718037251
assert( pPage==p->pDirty );
3718137252
p->pDirty = pPage->pDirtyNext;
37253
+ if( p->pDirty==0 && p->bPurgeable ){
37254
+ assert( p->eCreate==1 );
37255
+ p->eCreate = 2;
37256
+ }
3718237257
}
3718337258
pPage->pDirtyNext = 0;
3718437259
pPage->pDirtyPrev = 0;
3718537260
3718637261
expensive_assert( pcacheCheckSynced(p) );
@@ -37197,10 +37272,13 @@
3719737272
3719837273
pPage->pDirtyNext = p->pDirty;
3719937274
if( pPage->pDirtyNext ){
3720037275
assert( pPage->pDirtyNext->pDirtyPrev==0 );
3720137276
pPage->pDirtyNext->pDirtyPrev = pPage;
37277
+ }else if( p->bPurgeable ){
37278
+ assert( p->eCreate==2 );
37279
+ p->eCreate = 1;
3720237280
}
3720337281
p->pDirty = pPage;
3720437282
if( !p->pDirtyTail ){
3720537283
p->pDirtyTail = pPage;
3720637284
}
@@ -37266,10 +37344,11 @@
3726637344
){
3726737345
memset(p, 0, sizeof(PCache));
3726837346
p->szPage = szPage;
3726937347
p->szExtra = szExtra;
3727037348
p->bPurgeable = bPurgeable;
37349
+ p->eCreate = 2;
3727137350
p->xStress = xStress;
3727237351
p->pStress = pStress;
3727337352
p->szCache = 100;
3727437353
}
3727537354
@@ -37305,11 +37384,11 @@
3730537384
PCache *pCache, /* Obtain the page from this cache */
3730637385
Pgno pgno, /* Page number to obtain */
3730737386
int createFlag, /* If true, create page if it does not exist already */
3730837387
PgHdr **ppPage /* Write the page here */
3730937388
){
37310
- sqlite3_pcache_page *pPage = 0;
37389
+ sqlite3_pcache_page *pPage;
3731137390
PgHdr *pPgHdr = 0;
3731237391
int eCreate;
3731337392
3731437393
assert( pCache!=0 );
3731537394
assert( createFlag==1 || createFlag==0 );
@@ -37316,12 +37395,16 @@
3731637395
assert( pgno>0 );
3731737396
3731837397
/* If the pluggable cache (sqlite3_pcache*) has not been allocated,
3731937398
** allocate it now.
3732037399
*/
37321
- if( !pCache->pCache && createFlag ){
37400
+ if( !pCache->pCache ){
3732237401
sqlite3_pcache *p;
37402
+ if( !createFlag ){
37403
+ *ppPage = 0;
37404
+ return SQLITE_OK;
37405
+ }
3732337406
p = sqlite3GlobalConfig.pcache2.xCreate(
3732437407
pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
3732537408
);
3732637409
if( !p ){
3732737410
return SQLITE_NOMEM;
@@ -37328,15 +37411,20 @@
3732837411
}
3732937412
sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
3733037413
pCache->pCache = p;
3733137414
}
3733237415
37333
- eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
37334
- if( pCache->pCache ){
37335
- pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
37336
- }
37337
-
37416
+ /* eCreate defines what to do if the page does not exist.
37417
+ ** 0 Do not allocate a new page. (createFlag==0)
37418
+ ** 1 Allocate a new page if doing so is inexpensive.
37419
+ ** (createFlag==1 AND bPurgeable AND pDirty)
37420
+ ** 2 Allocate a new page even it doing so is difficult.
37421
+ ** (createFlag==1 AND !(bPurgeable AND pDirty)
37422
+ */
37423
+ eCreate = createFlag==0 ? 0 : pCache->eCreate;
37424
+ assert( (createFlag*(1+(!pCache->bPurgeable||!pCache->pDirty)))==eCreate );
37425
+ pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
3733837426
if( !pPage && eCreate==1 ){
3733937427
PgHdr *pPg;
3734037428
3734137429
/* Find a dirty page to write-out and recycle. First try to find a
3734237430
** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
@@ -47920,11 +48008,11 @@
4792048008
if( rc!=SQLITE_OK ){
4792148009
walIndexClose(pRet, 0);
4792248010
sqlite3OsClose(pRet->pWalFd);
4792348011
sqlite3_free(pRet);
4792448012
}else{
47925
- int iDC = sqlite3OsDeviceCharacteristics(pRet->pWalFd);
48013
+ int iDC = sqlite3OsDeviceCharacteristics(pDbFd);
4792648014
if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
4792748015
if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
4792848016
pRet->padToSectorBoundary = 0;
4792948017
}
4793048018
*ppWal = pRet;
@@ -49291,11 +49379,11 @@
4929149379
if( rc ) return rc;
4929249380
iOffset += iFirstAmt;
4929349381
iAmt -= iFirstAmt;
4929449382
pContent = (void*)(iFirstAmt + (char*)pContent);
4929549383
assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
49296
- rc = sqlite3OsSync(p->pFd, p->syncFlags);
49384
+ rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK);
4929749385
if( iAmt==0 || rc ) return rc;
4929849386
}
4929949387
rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
4930049388
return rc;
4930149389
}
@@ -50229,11 +50317,10 @@
5022950317
struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
5023050318
#ifndef SQLITE_OMIT_INCRBLOB
5023150319
Pgno *aOverflow; /* Cache of overflow page locations */
5023250320
#endif
5023350321
Pgno pgnoRoot; /* The root page of this tree */
50234
- sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
5023550322
CellInfo info; /* A parse of the cell we are pointing at */
5023650323
i64 nKey; /* Size of pKey, or last integer key */
5023750324
void *pKey; /* Saved key that was cursor's last known position */
5023850325
int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
5023950326
u8 wrFlag; /* True if writable */
@@ -52213,17 +52300,16 @@
5221352300
assert( sqlite3_mutex_held(pBt->mutex) );
5221452301
if( pBt->btsFlags & BTS_SECURE_DELETE ){
5221552302
memset(&data[hdr], 0, pBt->usableSize - hdr);
5221652303
}
5221752304
data[hdr] = (char)flags;
52218
- first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0);
52305
+ first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
5221952306
memset(&data[hdr+1], 0, 4);
5222052307
data[hdr+7] = 0;
5222152308
put2byte(&data[hdr+5], pBt->usableSize);
5222252309
pPage->nFree = (u16)(pBt->usableSize - first);
5222352310
decodeFlags(pPage, flags);
52224
- pPage->hdrOffset = hdr;
5222552311
pPage->cellOffset = first;
5222652312
pPage->aDataEnd = &data[pBt->usableSize];
5222752313
pPage->aCellIdx = &data[first];
5222852314
pPage->nOverflow = 0;
5222952315
assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
@@ -54303,11 +54389,10 @@
5430354389
if( pCur->pNext ){
5430454390
pCur->pNext->pPrev = pCur;
5430554391
}
5430654392
pBt->pCursor = pCur;
5430754393
pCur->eState = CURSOR_INVALID;
54308
- pCur->cachedRowid = 0;
5430954394
return SQLITE_OK;
5431054395
}
5431154396
SQLITE_PRIVATE int sqlite3BtreeCursor(
5431254397
Btree *p, /* The btree */
5431354398
int iTable, /* Root page of table to open */
@@ -54344,40 +54429,10 @@
5434454429
*/
5434554430
SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){
5434654431
memset(p, 0, offsetof(BtCursor, iPage));
5434754432
}
5434854433
54349
-/*
54350
-** Set the cached rowid value of every cursor in the same database file
54351
-** as pCur and having the same root page number as pCur. The value is
54352
-** set to iRowid.
54353
-**
54354
-** Only positive rowid values are considered valid for this cache.
54355
-** The cache is initialized to zero, indicating an invalid cache.
54356
-** A btree will work fine with zero or negative rowids. We just cannot
54357
-** cache zero or negative rowids, which means tables that use zero or
54358
-** negative rowids might run a little slower. But in practice, zero
54359
-** or negative rowids are very uncommon so this should not be a problem.
54360
-*/
54361
-SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor *pCur, sqlite3_int64 iRowid){
54362
- BtCursor *p;
54363
- for(p=pCur->pBt->pCursor; p; p=p->pNext){
54364
- if( p->pgnoRoot==pCur->pgnoRoot ) p->cachedRowid = iRowid;
54365
- }
54366
- assert( pCur->cachedRowid==iRowid );
54367
-}
54368
-
54369
-/*
54370
-** Return the cached rowid for the given cursor. A negative or zero
54371
-** return value indicates that the rowid cache is invalid and should be
54372
-** ignored. If the rowid cache has never before been set, then a
54373
-** zero is returned.
54374
-*/
54375
-SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor *pCur){
54376
- return pCur->cachedRowid;
54377
-}
54378
-
5437954434
/*
5438054435
** Close a cursor. The read lock on the database file is released
5438154436
** when the last cursor is closed.
5438254437
*/
5438354438
SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
@@ -55448,18 +55503,28 @@
5544855503
/*
5544955504
** Advance the cursor to the next entry in the database. If
5545055505
** successful then set *pRes=0. If the cursor
5545155506
** was already pointing to the last entry in the database before
5545255507
** this routine was called, then set *pRes=1.
55508
+**
55509
+** The calling function will set *pRes to 0 or 1. The initial *pRes value
55510
+** will be 1 if the cursor being stepped corresponds to an SQL index and
55511
+** if this routine could have been skipped if that SQL index had been
55512
+** a unique index. Otherwise the caller will have set *pRes to zero.
55513
+** Zero is the common case. The btree implementation is free to use the
55514
+** initial *pRes value as a hint to improve performance, but the current
55515
+** SQLite btree implementation does not. (Note that the comdb2 btree
55516
+** implementation does use this hint, however.)
5545355517
*/
5545455518
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
5545555519
int rc;
5545655520
int idx;
5545755521
MemPage *pPage;
5545855522
5545955523
assert( cursorHoldsMutex(pCur) );
5546055524
assert( pRes!=0 );
55525
+ assert( *pRes==0 || *pRes==1 );
5546155526
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
5546255527
if( pCur->eState!=CURSOR_VALID ){
5546355528
rc = restoreCursorPosition(pCur);
5546455529
if( rc!=SQLITE_OK ){
5546555530
*pRes = 0;
@@ -55534,17 +55599,27 @@
5553455599
/*
5553555600
** Step the cursor to the back to the previous entry in the database. If
5553655601
** successful then set *pRes=0. If the cursor
5553755602
** was already pointing to the first entry in the database before
5553855603
** this routine was called, then set *pRes=1.
55604
+**
55605
+** The calling function will set *pRes to 0 or 1. The initial *pRes value
55606
+** will be 1 if the cursor being stepped corresponds to an SQL index and
55607
+** if this routine could have been skipped if that SQL index had been
55608
+** a unique index. Otherwise the caller will have set *pRes to zero.
55609
+** Zero is the common case. The btree implementation is free to use the
55610
+** initial *pRes value as a hint to improve performance, but the current
55611
+** SQLite btree implementation does not. (Note that the comdb2 btree
55612
+** implementation does use this hint, however.)
5553955613
*/
5554055614
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
5554155615
int rc;
5554255616
MemPage *pPage;
5554355617
5554455618
assert( cursorHoldsMutex(pCur) );
5554555619
assert( pRes!=0 );
55620
+ assert( *pRes==0 || *pRes==1 );
5554655621
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
5554755622
pCur->atLast = 0;
5554855623
if( pCur->eState!=CURSOR_VALID ){
5554955624
if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){
5555055625
rc = btreeRestoreCursorPosition(pCur);
@@ -57637,15 +57712,21 @@
5763757712
** not to clear the cursor here.
5763857713
*/
5763957714
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
5764057715
if( rc ) return rc;
5764157716
57642
- /* If this is an insert into a table b-tree, invalidate any incrblob
57643
- ** cursors open on the row being replaced (assuming this is a replace
57644
- ** operation - if it is not, the following is a no-op). */
5764557717
if( pCur->pKeyInfo==0 ){
57718
+ /* If this is an insert into a table b-tree, invalidate any incrblob
57719
+ ** cursors open on the row being replaced */
5764657720
invalidateIncrblobCursors(p, nKey, 0);
57721
+
57722
+ /* If the cursor is currently on the last row and we are appending a
57723
+ ** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
57724
+ ** call */
57725
+ if( pCur->validNKey && nKey>0 && pCur->info.nKey==nKey-1 ){
57726
+ loc = -1;
57727
+ }
5764757728
}
5764857729
5764957730
if( !loc ){
5765057731
rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
5765157732
if( rc ) return rc;
@@ -57711,12 +57792,12 @@
5771157792
** entry in the table, and the next row inserted has an integer key
5771257793
** larger than the largest existing key, it is possible to insert the
5771357794
** row without seeking the cursor. This can be a big performance boost.
5771457795
*/
5771557796
pCur->info.nSize = 0;
57716
- pCur->validNKey = 0;
5771757797
if( rc==SQLITE_OK && pPage->nOverflow ){
57798
+ pCur->validNKey = 0;
5771857799
rc = balance(pCur);
5771957800
5772057801
/* Must make sure nOverflow is reset to zero even if the balance()
5772157802
** fails. Internal data structure corruption will result otherwise.
5772257803
** Also, set the cursor state to invalid. This stops saveCursorPosition()
@@ -57767,11 +57848,11 @@
5776757848
** from the internal node. The 'previous' entry is used for this instead
5776857849
** of the 'next' entry, as the previous entry is always a part of the
5776957850
** sub-tree headed by the child page of the cell being deleted. This makes
5777057851
** balancing the tree following the delete operation easier. */
5777157852
if( !pPage->leaf ){
57772
- int notUsed;
57853
+ int notUsed = 0;
5777357854
rc = sqlite3BtreePrevious(pCur, &notUsed);
5777457855
if( rc ) return rc;
5777557856
}
5777657857
5777757858
/* Save the positions of any other cursors open on this table before
@@ -60192,11 +60273,11 @@
6019260273
}
6019360274
6019460275
/*
6019560276
** Release any memory held by the Mem. This may leave the Mem in an
6019660277
** inconsistent state, for example with (Mem.z==0) and
60197
-** (Mem.type==SQLITE_TEXT).
60278
+** (Mem.memType==MEM_Str).
6019860279
*/
6019960280
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
6020060281
VdbeMemRelease(p);
6020160282
if( p->zMalloc ){
6020260283
sqlite3DbFree(p->db, p->zMalloc);
@@ -60383,11 +60464,11 @@
6038360464
}
6038460465
if( pMem->flags & MEM_RowSet ){
6038560466
sqlite3RowSetClear(pMem->u.pRowSet);
6038660467
}
6038760468
MemSetTypeFlag(pMem, MEM_Null);
60388
- pMem->type = SQLITE_NULL;
60469
+ pMem->memType = MEM_Null;
6038960470
}
6039060471
SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
6039160472
sqlite3VdbeMemSetNull((Mem*)p);
6039260473
}
6039360474
@@ -60396,11 +60477,11 @@
6039660477
** n containing all zeros.
6039760478
*/
6039860479
SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
6039960480
sqlite3VdbeMemRelease(pMem);
6040060481
pMem->flags = MEM_Blob|MEM_Zero;
60401
- pMem->type = SQLITE_BLOB;
60482
+ pMem->memType = MEM_Blob;
6040260483
pMem->n = 0;
6040360484
if( n<0 ) n = 0;
6040460485
pMem->u.nZero = n;
6040560486
pMem->enc = SQLITE_UTF8;
6040660487
@@ -60419,11 +60500,11 @@
6041960500
*/
6042060501
SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
6042160502
sqlite3VdbeMemRelease(pMem);
6042260503
pMem->u.i = val;
6042360504
pMem->flags = MEM_Int;
60424
- pMem->type = SQLITE_INTEGER;
60505
+ pMem->memType = MEM_Int;
6042560506
}
6042660507
6042760508
#ifndef SQLITE_OMIT_FLOATING_POINT
6042860509
/*
6042960510
** Delete any previous value and set the value stored in *pMem to val,
@@ -60434,11 +60515,11 @@
6043460515
sqlite3VdbeMemSetNull(pMem);
6043560516
}else{
6043660517
sqlite3VdbeMemRelease(pMem);
6043760518
pMem->r = val;
6043860519
pMem->flags = MEM_Real;
60439
- pMem->type = SQLITE_FLOAT;
60520
+ pMem->memType = MEM_Real;
6044060521
}
6044160522
}
6044260523
#endif
6044360524
6044460525
/*
@@ -60490,11 +60571,11 @@
6049060571
SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
6049160572
int i;
6049260573
Mem *pX;
6049360574
for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
6049460575
if( pX->pScopyFrom==pMem ){
60495
- pX->flags |= MEM_Invalid;
60576
+ pX->flags |= MEM_Undefined;
6049660577
pX->pScopyFrom = 0;
6049760578
}
6049860579
}
6049960580
pMem->pScopyFrom = 0;
6050060581
}
@@ -60642,11 +60723,11 @@
6064260723
}
6064360724
6064460725
pMem->n = nByte;
6064560726
pMem->flags = flags;
6064660727
pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
60647
- pMem->type = (enc==0 ? SQLITE_BLOB : SQLITE_TEXT);
60728
+ pMem->memType = flags&0x1f;
6064860729
6064960730
#ifndef SQLITE_OMIT_UTF16
6065060731
if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
6065160732
return SQLITE_NOMEM;
6065260733
}
@@ -60813,11 +60894,11 @@
6081360894
pMem->z = &zData[offset];
6081460895
pMem->flags = MEM_Blob|MEM_Ephem;
6081560896
}else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
6081660897
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
6081760898
pMem->enc = 0;
60818
- pMem->type = SQLITE_BLOB;
60899
+ pMem->memType = MEM_Blob;
6081960900
if( key ){
6082060901
rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
6082160902
}else{
6082260903
rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
6082360904
}
@@ -60883,11 +60964,11 @@
6088360964
*/
6088460965
SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
6088560966
Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
6088660967
if( p ){
6088760968
p->flags = MEM_Null;
60888
- p->type = SQLITE_NULL;
60969
+ p->memType = MEM_Null;
6088960970
p->db = db;
6089060971
}
6089160972
return p;
6089260973
}
6089360974
@@ -60933,11 +61014,11 @@
6093361014
assert( pRec->pKeyInfo->enc==ENC(db) );
6093461015
pRec->flags = UNPACKED_PREFIX_MATCH;
6093561016
pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
6093661017
for(i=0; i<nCol; i++){
6093761018
pRec->aMem[i].flags = MEM_Null;
60938
- pRec->aMem[i].type = SQLITE_NULL;
61019
+ pRec->aMem[i].memType = MEM_Null;
6093961020
pRec->aMem[i].db = db;
6094061021
}
6094161022
}else{
6094261023
sqlite3DbFree(db, pRec);
6094361024
pRec = 0;
@@ -61006,11 +61087,11 @@
6100661087
sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
6100761088
}else{
6100861089
zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
6100961090
if( zVal==0 ) goto no_mem;
6101061091
sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
61011
- if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
61092
+ if( op==TK_FLOAT ) pVal->memType = MEM_Real;
6101261093
}
6101361094
if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
6101461095
sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
6101561096
}else{
6101661097
sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
@@ -61464,10 +61545,13 @@
6146461545
#endif
6146561546
#ifdef VDBE_PROFILE
6146661547
pOp->cycles = 0;
6146761548
pOp->cnt = 0;
6146861549
#endif
61550
+#ifdef SQLITE_VDBE_COVERAGE
61551
+ pOp->iSrcLine = 0;
61552
+#endif
6146961553
return i;
6147061554
}
6147161555
SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *p, int op){
6147261556
return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
6147361557
}
@@ -61825,11 +61909,11 @@
6182561909
6182661910
/*
6182761911
** Add a whole list of operations to the operation stack. Return the
6182861912
** address of the first operation added.
6182961913
*/
61830
-SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61914
+SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
6183161915
int addr;
6183261916
assert( p->magic==VDBE_MAGIC_INIT );
6183361917
if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
6183461918
return 0;
6183561919
}
@@ -61852,10 +61936,15 @@
6185261936
pOut->p4type = P4_NOTUSED;
6185361937
pOut->p4.p = 0;
6185461938
pOut->p5 = 0;
6185561939
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6185661940
pOut->zComment = 0;
61941
+#endif
61942
+#ifdef SQLITE_VDBE_COVERAGE
61943
+ pOut->iSrcLine = iLineno+i;
61944
+#else
61945
+ (void)iLineno;
6185761946
#endif
6185861947
#ifdef SQLITE_DEBUG
6185961948
if( p->db->flags & SQLITE_VdbeAddopTrace ){
6186061949
sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
6186161950
}
@@ -62141,10 +62230,19 @@
6214162230
va_end(ap);
6214262231
}
6214362232
}
6214462233
#endif /* NDEBUG */
6214562234
62235
+#ifdef SQLITE_VDBE_COVERAGE
62236
+/*
62237
+** Set the value if the iSrcLine field for the previously coded instruction.
62238
+*/
62239
+SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
62240
+ sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine;
62241
+}
62242
+#endif /* SQLITE_VDBE_COVERAGE */
62243
+
6214662244
/*
6214762245
** Return the opcode for a given address. If the address is -1, then
6214862246
** return the most recently inserted opcode.
6214962247
**
6215062248
** If a memory allocation error has occurred prior to the calling of this
@@ -62153,28 +62251,17 @@
6215362251
** The return of a dummy opcode allows the call to continue functioning
6215462252
** after a OOM fault without having to check to see if the return from
6215562253
** this routine is a valid pointer. But because the dummy.opcode is 0,
6215662254
** dummy will never be written to. This is verified by code inspection and
6215762255
** by running with Valgrind.
62158
-**
62159
-** About the #ifdef SQLITE_OMIT_TRACE: Normally, this routine is never called
62160
-** unless p->nOp>0. This is because in the absense of SQLITE_OMIT_TRACE,
62161
-** an OP_Trace instruction is always inserted by sqlite3VdbeGet() as soon as
62162
-** a new VDBE is created. So we are free to set addr to p->nOp-1 without
62163
-** having to double-check to make sure that the result is non-negative. But
62164
-** if SQLITE_OMIT_TRACE is defined, the OP_Trace is omitted and we do need to
62165
-** check the value of p->nOp-1 before continuing.
6216662256
*/
6216762257
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
6216862258
/* C89 specifies that the constant "dummy" will be initialized to all
6216962259
** zeros, which is correct. MSVC generates a warning, nevertheless. */
6217062260
static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
6217162261
assert( p->magic==VDBE_MAGIC_INIT );
6217262262
if( addr<0 ){
62173
-#ifdef SQLITE_OMIT_TRACE
62174
- if( p->nOp==0 ) return (VdbeOp*)&dummy;
62175
-#endif
6217662263
addr = p->nOp - 1;
6217762264
}
6217862265
assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
6217962266
if( p->db->mallocFailed ){
6218062267
return (VdbeOp*)&dummy;
@@ -62475,11 +62562,11 @@
6247562562
if( pOut==0 ) pOut = stdout;
6247662563
zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
6247762564
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6247862565
displayComment(pOp, zP4, zCom, sizeof(zCom));
6247962566
#else
62480
- zCom[0] = 0
62567
+ zCom[0] = 0;
6248162568
#endif
6248262569
/* NB: The sqlite3OpcodeName() function is implemented by code created
6248362570
** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
6248462571
** information from the vdbe.c source text */
6248562572
fprintf(pOut, zFormat1, pc,
@@ -62524,11 +62611,11 @@
6252462611
}else if( p->zMalloc ){
6252562612
sqlite3DbFree(db, p->zMalloc);
6252662613
p->zMalloc = 0;
6252762614
}
6252862615
62529
- p->flags = MEM_Invalid;
62616
+ p->flags = MEM_Undefined;
6253062617
}
6253162618
db->mallocFailed = malloc_failed;
6253262619
}
6253362620
}
6253462621
@@ -62646,19 +62733,19 @@
6264662733
}
6264762734
pOp = &apSub[j]->aOp[i];
6264862735
}
6264962736
if( p->explain==1 ){
6265062737
pMem->flags = MEM_Int;
62651
- pMem->type = SQLITE_INTEGER;
62738
+ pMem->memType = MEM_Int;
6265262739
pMem->u.i = i; /* Program counter */
6265362740
pMem++;
6265462741
6265562742
pMem->flags = MEM_Static|MEM_Str|MEM_Term;
6265662743
pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
6265762744
assert( pMem->z!=0 );
6265862745
pMem->n = sqlite3Strlen30(pMem->z);
62659
- pMem->type = SQLITE_TEXT;
62746
+ pMem->memType = MEM_Str;
6266062747
pMem->enc = SQLITE_UTF8;
6266162748
pMem++;
6266262749
6266362750
/* When an OP_Program opcode is encounter (the only opcode that has
6266462751
** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
@@ -62680,21 +62767,21 @@
6268062767
}
6268162768
}
6268262769
6268362770
pMem->flags = MEM_Int;
6268462771
pMem->u.i = pOp->p1; /* P1 */
62685
- pMem->type = SQLITE_INTEGER;
62772
+ pMem->memType = MEM_Int;
6268662773
pMem++;
6268762774
6268862775
pMem->flags = MEM_Int;
6268962776
pMem->u.i = pOp->p2; /* P2 */
62690
- pMem->type = SQLITE_INTEGER;
62777
+ pMem->memType = MEM_Int;
6269162778
pMem++;
6269262779
6269362780
pMem->flags = MEM_Int;
6269462781
pMem->u.i = pOp->p3; /* P3 */
62695
- pMem->type = SQLITE_INTEGER;
62782
+ pMem->memType = MEM_Int;
6269662783
pMem++;
6269762784
6269862785
if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
6269962786
assert( p->db->mallocFailed );
6270062787
return SQLITE_ERROR;
@@ -62706,11 +62793,11 @@
6270662793
}else{
6270762794
assert( pMem->z!=0 );
6270862795
pMem->n = sqlite3Strlen30(pMem->z);
6270962796
pMem->enc = SQLITE_UTF8;
6271062797
}
62711
- pMem->type = SQLITE_TEXT;
62798
+ pMem->memType = MEM_Str;
6271262799
pMem++;
6271362800
6271462801
if( p->explain==1 ){
6271562802
if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
6271662803
assert( p->db->mallocFailed );
@@ -62717,11 +62804,11 @@
6271762804
return SQLITE_ERROR;
6271862805
}
6271962806
pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
6272062807
pMem->n = 2;
6272162808
sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62722
- pMem->type = SQLITE_TEXT;
62809
+ pMem->memType = MEM_Str;
6272362810
pMem->enc = SQLITE_UTF8;
6272462811
pMem++;
6272562812
6272662813
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6272762814
if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
@@ -62728,15 +62815,15 @@
6272862815
assert( p->db->mallocFailed );
6272962816
return SQLITE_ERROR;
6273062817
}
6273162818
pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
6273262819
pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62733
- pMem->type = SQLITE_TEXT;
62820
+ pMem->memType = MEM_Str;
6273462821
pMem->enc = SQLITE_UTF8;
6273562822
#else
6273662823
pMem->flags = MEM_Null; /* Comment */
62737
- pMem->type = SQLITE_NULL;
62824
+ pMem->memType = MEM_Null;
6273862825
#endif
6273962826
}
6274062827
6274162828
p->nResColumn = 8 - 4*(p->explain-1);
6274262829
p->pResultSet = &p->aMem[1];
@@ -62755,11 +62842,11 @@
6275562842
const char *z = 0;
6275662843
if( p->zSql ){
6275762844
z = p->zSql;
6275862845
}else if( p->nOp>=1 ){
6275962846
const VdbeOp *pOp = &p->aOp[0];
62760
- if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62847
+ if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
6276162848
z = pOp->p4.z;
6276262849
while( sqlite3Isspace(*z) ) z++;
6276362850
}
6276462851
}
6276562852
if( z ) printf("SQL: [%s]\n", z);
@@ -62774,11 +62861,11 @@
6277462861
int nOp = p->nOp;
6277562862
VdbeOp *pOp;
6277662863
if( sqlite3IoTrace==0 ) return;
6277762864
if( nOp<1 ) return;
6277862865
pOp = &p->aOp[0];
62779
- if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62866
+ if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
6278062867
int i, j;
6278162868
char z[1000];
6278262869
sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z);
6278362870
for(i=0; sqlite3Isspace(z[i]); i++){}
6278462871
for(j=0; z[i]; i++){
@@ -62992,11 +63079,11 @@
6299263079
}
6299363080
if( p->aMem ){
6299463081
p->aMem--; /* aMem[] goes from 1..nMem */
6299563082
p->nMem = nMem; /* not from 0..nMem-1 */
6299663083
for(n=1; n<=nMem; n++){
62997
- p->aMem[n].flags = MEM_Invalid;
63084
+ p->aMem[n].flags = MEM_Undefined;
6299863085
p->aMem[n].db = db;
6299963086
}
6300063087
}
6300163088
p->explain = pParse->explain;
6300263089
sqlite3VdbeRewind(p);
@@ -63104,11 +63191,11 @@
6310463191
/* Execute assert() statements to ensure that the Vdbe.apCsr[] and
6310563192
** Vdbe.aMem[] arrays have already been cleaned up. */
6310663193
int i;
6310763194
if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
6310863195
if( p->aMem ){
63109
- for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Invalid );
63196
+ for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
6311063197
}
6311163198
#endif
6311263199
6311363200
sqlite3DbFree(db, p->zErrMsg);
6311463201
p->zErrMsg = 0;
@@ -63853,16 +63940,28 @@
6385363940
fprintf(out, "---- ");
6385463941
for(i=0; i<p->nOp; i++){
6385563942
fprintf(out, "%02x", p->aOp[i].opcode);
6385663943
}
6385763944
fprintf(out, "\n");
63945
+ if( p->zSql ){
63946
+ char c, pc = 0;
63947
+ fprintf(out, "-- ");
63948
+ for(i=0; (c = p->zSql[i])!=0; i++){
63949
+ if( pc=='\n' ) fprintf(out, "-- ");
63950
+ putc(c, out);
63951
+ pc = c;
63952
+ }
63953
+ if( pc!='\n' ) fprintf(out, "\n");
63954
+ }
6385863955
for(i=0; i<p->nOp; i++){
63859
- fprintf(out, "%6d %10lld %8lld ",
63956
+ char zHdr[100];
63957
+ sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
6386063958
p->aOp[i].cnt,
6386163959
p->aOp[i].cycles,
6386263960
p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
6386363961
);
63962
+ fprintf(out, "%s", zHdr);
6386463963
sqlite3VdbePrintOp(out, i, &p->aOp[i]);
6386563964
}
6386663965
fclose(out);
6386763966
}
6386863967
}
@@ -64895,11 +64994,45 @@
6489564994
SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
6489664995
return sqlite3ValueText(pVal, SQLITE_UTF16LE);
6489764996
}
6489864997
#endif /* SQLITE_OMIT_UTF16 */
6489964998
SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
64900
- return pVal->type;
64999
+ static const u8 aType[] = {
65000
+ SQLITE_BLOB, /* 0x00 */
65001
+ SQLITE_NULL, /* 0x01 */
65002
+ SQLITE_TEXT, /* 0x02 */
65003
+ SQLITE_NULL, /* 0x03 */
65004
+ SQLITE_INTEGER, /* 0x04 */
65005
+ SQLITE_NULL, /* 0x05 */
65006
+ SQLITE_INTEGER, /* 0x06 */
65007
+ SQLITE_NULL, /* 0x07 */
65008
+ SQLITE_FLOAT, /* 0x08 */
65009
+ SQLITE_NULL, /* 0x09 */
65010
+ SQLITE_FLOAT, /* 0x0a */
65011
+ SQLITE_NULL, /* 0x0b */
65012
+ SQLITE_INTEGER, /* 0x0c */
65013
+ SQLITE_NULL, /* 0x0d */
65014
+ SQLITE_INTEGER, /* 0x0e */
65015
+ SQLITE_NULL, /* 0x0f */
65016
+ SQLITE_BLOB, /* 0x10 */
65017
+ SQLITE_NULL, /* 0x11 */
65018
+ SQLITE_TEXT, /* 0x12 */
65019
+ SQLITE_NULL, /* 0x13 */
65020
+ SQLITE_INTEGER, /* 0x14 */
65021
+ SQLITE_NULL, /* 0x15 */
65022
+ SQLITE_INTEGER, /* 0x16 */
65023
+ SQLITE_NULL, /* 0x17 */
65024
+ SQLITE_FLOAT, /* 0x18 */
65025
+ SQLITE_NULL, /* 0x19 */
65026
+ SQLITE_FLOAT, /* 0x1a */
65027
+ SQLITE_NULL, /* 0x1b */
65028
+ SQLITE_INTEGER, /* 0x1c */
65029
+ SQLITE_NULL, /* 0x1d */
65030
+ SQLITE_INTEGER, /* 0x1e */
65031
+ SQLITE_NULL, /* 0x1f */
65032
+ };
65033
+ return aType[pVal->memType&0x1f];
6490165034
}
6490265035
6490365036
/**************************** sqlite3_result_ *******************************
6490465037
** The following routines are used by user-defined functions to specify
6490565038
** the function result.
@@ -65854,11 +65987,11 @@
6585465987
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
6585565988
}
6585665989
#endif /* SQLITE_OMIT_UTF16 */
6585765990
SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
6585865991
int rc;
65859
- switch( pValue->type ){
65992
+ switch( sqlite3_value_type((sqlite3_value*)pValue) ){
6586065993
case SQLITE_INTEGER: {
6586165994
rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
6586265995
break;
6586365996
}
6586465997
case SQLITE_FLOAT: {
@@ -66355,37 +66488,12 @@
6635566488
** May you do good and not evil.
6635666489
** May you find forgiveness for yourself and forgive others.
6635766490
** May you share freely, never taking more than you give.
6635866491
**
6635966492
*************************************************************************
66360
-** The code in this file implements execution method of the
66361
-** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c")
66362
-** handles housekeeping details such as creating and deleting
66363
-** VDBE instances. This file is solely interested in executing
66364
-** the VDBE program.
66365
-**
66366
-** In the external interface, an "sqlite3_stmt*" is an opaque pointer
66367
-** to a VDBE.
66368
-**
66369
-** The SQL parser generates a program which is then executed by
66370
-** the VDBE to do the work of the SQL statement. VDBE programs are
66371
-** similar in form to assembly language. The program consists of
66372
-** a linear sequence of operations. Each operation has an opcode
66373
-** and 5 operands. Operands P1, P2, and P3 are integers. Operand P4
66374
-** is a null-terminated string. Operand P5 is an unsigned character.
66375
-** Few opcodes use all 5 operands.
66376
-**
66377
-** Computation results are stored on a set of registers numbered beginning
66378
-** with 1 and going up to Vdbe.nMem. Each register can store
66379
-** either an integer, a null-terminated string, a floating point
66380
-** number, or the SQL "NULL" value. An implicit conversion from one
66381
-** type to the other occurs as necessary.
66382
-**
66383
-** Most of the code in this file is taken up by the sqlite3VdbeExec()
66384
-** function which does the work of interpreting a VDBE program.
66385
-** But other routines are also provided to help in building up
66386
-** a program instruction by instruction.
66493
+** The code in this file implements the function that runs the
66494
+** bytecode of a prepared statement.
6638766495
**
6638866496
** Various scripts scan this source file in order to generate HTML
6638966497
** documentation, headers files, or other derived files. The formatting
6639066498
** of the code in this file is, therefore, important. See other comments
6639166499
** in this file for details. If in doubt, do not deviate from existing
@@ -66393,11 +66501,15 @@
6639366501
*/
6639466502
6639566503
/*
6639666504
** Invoke this macro on memory cells just prior to changing the
6639766505
** value of the cell. This macro verifies that shallow copies are
66398
-** not misused.
66506
+** not misused. A shallow copy of a string or blob just copies a
66507
+** pointer to the string or blob, not the content. If the original
66508
+** is changed while the copy is still in use, the string or blob might
66509
+** be changed out from under the copy. This macro verifies that nothing
66510
+** like that every happens.
6639966511
*/
6640066512
#ifdef SQLITE_DEBUG
6640166513
# define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
6640266514
#else
6640366515
# define memAboutToChange(P,M)
@@ -66452,11 +66564,11 @@
6645266564
}
6645366565
}
6645466566
#endif
6645566567
6645666568
/*
66457
-** The next global variable is incremented each type the OP_Found opcode
66569
+** The next global variable is incremented each time the OP_Found opcode
6645866570
** is executed. This is used to test whether or not the foreign key
6645966571
** operation implemented using OP_FkIsZero is working. This variable
6646066572
** has no function other than to help verify the correct operation of the
6646166573
** library.
6646266574
*/
@@ -66472,10 +66584,38 @@
6647266584
# define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
6647366585
#else
6647466586
# define UPDATE_MAX_BLOBSIZE(P)
6647566587
#endif
6647666588
66589
+/*
66590
+** Invoke the VDBE coverage callback, if that callback is defined. This
66591
+** feature is used for test suite validation only and does not appear an
66592
+** production builds.
66593
+**
66594
+** M is an integer, 2 or 3, that indices how many different ways the
66595
+** branch can go. It is usually 2. "I" is the direction the branch
66596
+** goes. 0 means falls through. 1 means branch is taken. 2 means the
66597
+** second alternative branch is taken.
66598
+*/
66599
+#if !defined(SQLITE_VDBE_COVERAGE)
66600
+# define VdbeBranchTaken(I,M)
66601
+#else
66602
+# define VdbeBranchTaken(I,M) vdbeTakeBranch(pOp->iSrcLine,I,M)
66603
+ static void vdbeTakeBranch(int iSrcLine, u8 I, u8 M){
66604
+ if( iSrcLine<=2 && ALWAYS(iSrcLine>0) ){
66605
+ M = iSrcLine;
66606
+ /* Assert the truth of VdbeCoverageAlwaysTaken() and
66607
+ ** VdbeCoverageNeverTaken() */
66608
+ assert( (M & I)==I );
66609
+ }else{
66610
+ if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
66611
+ sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
66612
+ iSrcLine,I,M);
66613
+ }
66614
+ }
66615
+#endif
66616
+
6647766617
/*
6647866618
** Convert the given register into a string if it isn't one
6647966619
** already. Return non-zero if a malloc() fails.
6648066620
*/
6648166621
#define Stringify(P, enc) \
@@ -66496,35 +66636,11 @@
6649666636
#define Deephemeralize(P) \
6649766637
if( ((P)->flags&MEM_Ephem)!=0 \
6649866638
&& sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
6649966639
6650066640
/* Return true if the cursor was opened using the OP_OpenSorter opcode. */
66501
-# define isSorter(x) ((x)->pSorter!=0)
66502
-
66503
-/*
66504
-** Argument pMem points at a register that will be passed to a
66505
-** user-defined function or returned to the user as the result of a query.
66506
-** This routine sets the pMem->type variable used by the sqlite3_value_*()
66507
-** routines.
66508
-*/
66509
-SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem){
66510
- int flags = pMem->flags;
66511
- if( flags & MEM_Null ){
66512
- pMem->type = SQLITE_NULL;
66513
- }
66514
- else if( flags & MEM_Int ){
66515
- pMem->type = SQLITE_INTEGER;
66516
- }
66517
- else if( flags & MEM_Real ){
66518
- pMem->type = SQLITE_FLOAT;
66519
- }
66520
- else if( flags & MEM_Str ){
66521
- pMem->type = SQLITE_TEXT;
66522
- }else{
66523
- pMem->type = SQLITE_BLOB;
66524
- }
66525
-}
66641
+#define isSorter(x) ((x)->pSorter!=0)
6652666642
6652766643
/*
6652866644
** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
6652966645
** if we run out of memory.
6653066646
*/
@@ -66650,16 +66766,18 @@
6665066766
** into a numeric representation. Use either INTEGER or REAL whichever
6665166767
** is appropriate. But only do the conversion if it is possible without
6665266768
** loss of information and return the revised type of the argument.
6665366769
*/
6665466770
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
66655
- Mem *pMem = (Mem*)pVal;
66656
- if( pMem->type==SQLITE_TEXT ){
66771
+ int eType = sqlite3_value_type(pVal);
66772
+ if( eType==SQLITE_TEXT ){
66773
+ Mem *pMem = (Mem*)pVal;
6665766774
applyNumericAffinity(pMem);
6665866775
sqlite3VdbeMemStoreType(pMem);
66776
+ eType = sqlite3_value_type(pVal);
6665966777
}
66660
- return pMem->type;
66778
+ return eType;
6666166779
}
6666266780
6666366781
/*
6666466782
** Exported version of applyAffinity(). This one works on sqlite3_value*,
6666566783
** not the internal Mem* type.
@@ -66758,11 +66876,11 @@
6675866876
#ifdef SQLITE_DEBUG
6675966877
/*
6676066878
** Print the value of a register for tracing purposes:
6676166879
*/
6676266880
static void memTracePrint(Mem *p){
66763
- if( p->flags & MEM_Invalid ){
66881
+ if( p->flags & MEM_Undefined ){
6676466882
printf(" undefined");
6676566883
}else if( p->flags & MEM_Null ){
6676666884
printf(" NULL");
6676766885
}else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
6676866886
printf(" si:%lld", p->u.i);
@@ -66890,24 +67008,10 @@
6689067008
6689167009
/************** End of hwtime.h **********************************************/
6689267010
/************** Continuing where we left off in vdbe.c ***********************/
6689367011
6689467012
#endif
66895
-
66896
-/*
66897
-** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
66898
-** sqlite3_interrupt() routine has been called. If it has been, then
66899
-** processing of the VDBE program is interrupted.
66900
-**
66901
-** This macro added to every instruction that does a jump in order to
66902
-** implement a loop. This test used to be on every single instruction,
66903
-** but that meant we more testing than we needed. By only testing the
66904
-** flag on jump instructions, we get a (small) speed improvement.
66905
-*/
66906
-#define CHECK_FOR_INTERRUPT \
66907
- if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
66908
-
6690967013
6691067014
#ifndef NDEBUG
6691167015
/*
6691267016
** This function is only called from within an assert() expression. It
6691367017
** checks that the sqlite3.nTransaction variable is correctly set to
@@ -66927,39 +67031,12 @@
6692767031
}
6692867032
#endif
6692967033
6693067034
6693167035
/*
66932
-** Execute as much of a VDBE program as we can then return.
66933
-**
66934
-** sqlite3VdbeMakeReady() must be called before this routine in order to
66935
-** close the program with a final OP_Halt and to set up the callbacks
66936
-** and the error message pointer.
66937
-**
66938
-** Whenever a row or result data is available, this routine will either
66939
-** invoke the result callback (if there is one) or return with
66940
-** SQLITE_ROW.
66941
-**
66942
-** If an attempt is made to open a locked database, then this routine
66943
-** will either invoke the busy callback (if there is one) or it will
66944
-** return SQLITE_BUSY.
66945
-**
66946
-** If an error occurs, an error message is written to memory obtained
66947
-** from sqlite3_malloc() and p->zErrMsg is made to point to that memory.
66948
-** The error code is stored in p->rc and this routine returns SQLITE_ERROR.
66949
-**
66950
-** If the callback ever returns non-zero, then the program exits
66951
-** immediately. There will be no error message but the p->rc field is
66952
-** set to SQLITE_ABORT and this routine will return SQLITE_ERROR.
66953
-**
66954
-** A memory allocation error causes p->rc to be set to SQLITE_NOMEM and this
66955
-** routine to return SQLITE_ERROR.
66956
-**
66957
-** Other fatal errors return SQLITE_ERROR.
66958
-**
66959
-** After this routine has finished, sqlite3VdbeFinalize() should be
66960
-** used to clean up the mess that was left behind.
67036
+** Execute as much of a VDBE program as we can.
67037
+** This is the core of sqlite3_step().
6696167038
*/
6696267039
SQLITE_PRIVATE int sqlite3VdbeExec(
6696367040
Vdbe *p /* The VDBE */
6696467041
){
6696567042
int pc=0; /* The program counter */
@@ -66981,11 +67058,10 @@
6698167058
Mem *pOut = 0; /* Output operand */
6698267059
int *aPermute = 0; /* Permutation of columns for OP_Compare */
6698367060
i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6698467061
#ifdef VDBE_PROFILE
6698567062
u64 start; /* CPU clock count at start of opcode */
66986
- int origPc; /* Program counter at start of opcode */
6698767063
#endif
6698867064
/*** INSERT STACK UNION HERE ***/
6698967065
6699067066
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
6699167067
sqlite3VdbeEnter(p);
@@ -66999,11 +67075,11 @@
6699967075
p->rc = SQLITE_OK;
6700067076
p->iCurrentTime = 0;
6700167077
assert( p->explain==0 );
6700267078
p->pResultSet = 0;
6700367079
db->busyHandler.nBusy = 0;
67004
- CHECK_FOR_INTERRUPT;
67080
+ if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
6700567081
sqlite3VdbeIOTraceSql(p);
6700667082
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
6700767083
if( db->xProgress ){
6700867084
assert( 0 < db->nProgressOps );
6700967085
nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
@@ -67043,11 +67119,10 @@
6704367119
#endif
6704467120
for(pc=p->pc; rc==SQLITE_OK; pc++){
6704567121
assert( pc>=0 && pc<p->nOp );
6704667122
if( db->mallocFailed ) goto no_mem;
6704767123
#ifdef VDBE_PROFILE
67048
- origPc = pc;
6704967124
start = sqlite3Hwtime();
6705067125
#endif
6705167126
nVmStep++;
6705267127
pOp = &aOp[pc];
6705367128
@@ -67175,11 +67250,11 @@
6717567250
** But that is not due to sloppy coding habits. The code is written this
6717667251
** way for performance, to avoid having to run the interrupt and progress
6717767252
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
6717867253
** faster according to "valgrind --tool=cachegrind" */
6717967254
check_for_interrupt:
67180
- CHECK_FOR_INTERRUPT;
67255
+ if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
6718167256
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
6718267257
/* Call the progress callback if it is configured and the required number
6718367258
** of VDBE ops have been executed (either since this invocation of
6718467259
** sqlite3VdbeExec() or since last time the progress callback was called).
6718567260
** If the progress callback returns non-zero, exit the virtual machine with
@@ -67215,24 +67290,70 @@
6721567290
break;
6721667291
}
6721767292
6721867293
/* Opcode: Return P1 * * * *
6721967294
**
67220
-** Jump to the next instruction after the address in register P1.
67295
+** Jump to the next instruction after the address in register P1. After
67296
+** the jump, register P1 becomes undefined.
6722167297
*/
6722267298
case OP_Return: { /* in1 */
6722367299
pIn1 = &aMem[pOp->p1];
67224
- assert( pIn1->flags & MEM_Int );
67300
+ assert( pIn1->flags==MEM_Int );
6722567301
pc = (int)pIn1->u.i;
67302
+ pIn1->flags = MEM_Undefined;
6722667303
break;
6722767304
}
6722867305
67229
-/* Opcode: Yield P1 * * * *
67306
+/* Opcode: InitCoroutine P1 P2 P3 * *
67307
+**
67308
+** Set up register P1 so that it will OP_Yield to the co-routine
67309
+** located at address P3.
67310
+**
67311
+** If P2!=0 then the co-routine implementation immediately follows
67312
+** this opcode. So jump over the co-routine implementation to
67313
+** address P2.
67314
+*/
67315
+case OP_InitCoroutine: { /* jump */
67316
+ assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67317
+ assert( pOp->p2>=0 && pOp->p2<p->nOp );
67318
+ assert( pOp->p3>=0 && pOp->p3<p->nOp );
67319
+ pOut = &aMem[pOp->p1];
67320
+ assert( !VdbeMemDynamic(pOut) );
67321
+ pOut->u.i = pOp->p3 - 1;
67322
+ pOut->flags = MEM_Int;
67323
+ if( pOp->p2 ) pc = pOp->p2 - 1;
67324
+ break;
67325
+}
67326
+
67327
+/* Opcode: EndCoroutine P1 * * * *
67328
+**
67329
+** The instruction at the address in register P1 is an OP_Yield.
67330
+** Jump to the P2 parameter of that OP_Yield.
67331
+** After the jump, register P1 becomes undefined.
67332
+*/
67333
+case OP_EndCoroutine: { /* in1 */
67334
+ VdbeOp *pCaller;
67335
+ pIn1 = &aMem[pOp->p1];
67336
+ assert( pIn1->flags==MEM_Int );
67337
+ assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
67338
+ pCaller = &aOp[pIn1->u.i];
67339
+ assert( pCaller->opcode==OP_Yield );
67340
+ assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
67341
+ pc = pCaller->p2 - 1;
67342
+ pIn1->flags = MEM_Undefined;
67343
+ break;
67344
+}
67345
+
67346
+/* Opcode: Yield P1 P2 * * *
6723067347
**
6723167348
** Swap the program counter with the value in register P1.
67349
+**
67350
+** If the co-routine ends with OP_Yield or OP_Return then continue
67351
+** to the next instruction. But if the co-routine ends with
67352
+** OP_EndCoroutine, jump immediately to P2.
6723267353
*/
67233
-case OP_Yield: { /* in1 */
67354
+case OP_Yield: { /* in1, jump */
6723467355
int pcDest;
6723567356
pIn1 = &aMem[pOp->p1];
6723667357
assert( (pIn1->flags & MEM_Dyn)==0 );
6723767358
pIn1->flags = MEM_Int;
6723867359
pcDest = (int)pIn1->u.i;
@@ -67241,11 +67362,11 @@
6724167362
pc = pcDest;
6724267363
break;
6724367364
}
6724467365
6724567366
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
67246
-** Synopsis: if r[P3] null then halt
67367
+** Synopsis: if r[P3]=null halt
6724767368
**
6724867369
** Check the value in register P3. If it is NULL then Halt using
6724967370
** parameter P1, P2, and P4 as if this were a Halt instruction. If the
6725067371
** value in register P3 is not NULL, then this routine is a no-op.
6725167372
** The P5 parameter should be 1.
@@ -67389,11 +67510,13 @@
6738967510
6739067511
/* Opcode: String8 * P2 * P4 *
6739167512
** Synopsis: r[P2]='P4'
6739267513
**
6739367514
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67394
-** into an OP_String before it is executed for the first time.
67515
+** into an OP_String before it is executed for the first time. During
67516
+** this transformation, the length of string P4 is computed and stored
67517
+** as the P1 parameter.
6739567518
*/
6739667519
case OP_String8: { /* same as TK_STRING, out2-prerelease */
6739767520
assert( pOp->p4.z!=0 );
6739867521
pOp->opcode = OP_String;
6739967522
pOp->p1 = sqlite3Strlen30(pOp->p4.z);
@@ -67463,12 +67586,26 @@
6746367586
cnt--;
6746467587
}
6746567588
break;
6746667589
}
6746767590
67591
+/* Opcode: SoftNull P1 * * * *
67592
+** Synopsis: r[P1]=NULL
67593
+**
67594
+** Set register P1 to have the value NULL as seen by the OP_MakeRecord
67595
+** instruction, but do not free any string or blob memory associated with
67596
+** the register, so that if the value was a string or blob that was
67597
+** previously copied using OP_SCopy, the copies will continue to be valid.
67598
+*/
67599
+case OP_SoftNull: {
67600
+ assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67601
+ pOut = &aMem[pOp->p1];
67602
+ pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
67603
+ break;
67604
+}
6746867605
67469
-/* Opcode: Blob P1 P2 * P4
67606
+/* Opcode: Blob P1 P2 * P4 *
6747067607
** Synopsis: r[P2]=P4 (len=P1)
6747167608
**
6747267609
** P4 points to a blob of data P1 bytes long. Store this
6747367610
** blob in register P2.
6747467611
*/
@@ -67483,11 +67620,11 @@
6748367620
/* Opcode: Variable P1 P2 * P4 *
6748467621
** Synopsis: r[P2]=parameter(P1,P4)
6748567622
**
6748667623
** Transfer the values of bound parameter P1 into register P2
6748767624
**
67488
-** If the parameter is named, then its name appears in P4 and P3==1.
67625
+** If the parameter is named, then its name appears in P4.
6748967626
** The P4 value is used by sqlite3_bind_parameter_name().
6749067627
*/
6749167628
case OP_Variable: { /* out2-prerelease */
6749267629
Mem *pVar; /* Value being transferred */
6749367630
@@ -67602,12 +67739,12 @@
6760267739
** Synopsis: output=r[P1@P2]
6760367740
**
6760467741
** The registers P1 through P1+P2-1 contain a single row of
6760567742
** results. This opcode causes the sqlite3_step() call to terminate
6760667743
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67607
-** structure to provide access to the top P1 values as the result
67608
-** row.
67744
+** structure to provide access to the r(P1)..r(P1+P2-1) values as
67745
+** the result row.
6760967746
*/
6761067747
case OP_ResultRow: {
6761167748
Mem *pMem;
6761267749
int i;
6761367750
assert( p->nResColumn==pOp->p2 );
@@ -68093,10 +68230,11 @@
6809368230
*/
6809468231
case OP_MustBeInt: { /* jump, in1 */
6809568232
pIn1 = &aMem[pOp->p1];
6809668233
if( (pIn1->flags & MEM_Int)==0 ){
6809768234
applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
68235
+ VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
6809868236
if( (pIn1->flags & MEM_Int)==0 ){
6809968237
if( pOp->p2==0 ){
6810068238
rc = SQLITE_MISMATCH;
6810168239
goto abort_due_to_error;
6810268240
}else{
@@ -68131,11 +68269,11 @@
6813168269
#ifndef SQLITE_OMIT_CAST
6813268270
/* Opcode: ToText P1 * * * *
6813368271
**
6813468272
** Force the value in register P1 to be text.
6813568273
** If the value is numeric, convert it to a string using the
68136
-** equivalent of printf(). Blob values are unchanged and
68274
+** equivalent of sprintf(). Blob values are unchanged and
6813768275
** are afterwards simply interpreted as text.
6813868276
**
6813968277
** A NULL value is not changed by this routine. It remains NULL.
6814068278
*/
6814168279
case OP_ToText: { /* same as TK_TO_TEXT, in1 */
@@ -68333,10 +68471,11 @@
6833368471
** OP_Eq or OP_Ne) then take the jump or not depending on whether
6833468472
** or not both operands are null.
6833568473
*/
6833668474
assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
6833768475
assert( (flags1 & MEM_Cleared)==0 );
68476
+ assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 );
6833868477
if( (flags1&MEM_Null)!=0
6833968478
&& (flags3&MEM_Null)!=0
6834068479
&& (flags3&MEM_Cleared)==0
6834168480
){
6834268481
res = 0; /* Results are equal */
@@ -68346,16 +68485,19 @@
6834668485
}else{
6834768486
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
6834868487
** then the result is always NULL.
6834968488
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
6835068489
*/
68351
- if( pOp->p5 & SQLITE_JUMPIFNULL ){
68352
- pc = pOp->p2-1;
68353
- }else if( pOp->p5 & SQLITE_STOREP2 ){
68490
+ if( pOp->p5 & SQLITE_STOREP2 ){
6835468491
pOut = &aMem[pOp->p2];
6835568492
MemSetTypeFlag(pOut, MEM_Null);
6835668493
REGISTER_TRACE(pOp->p2, pOut);
68494
+ }else{
68495
+ VdbeBranchTaken(2,3);
68496
+ if( pOp->p5 & SQLITE_JUMPIFNULL ){
68497
+ pc = pOp->p2-1;
68498
+ }
6835768499
}
6835868500
break;
6835968501
}
6836068502
}else{
6836168503
/* Neither operand is NULL. Do a comparison. */
@@ -68384,14 +68526,16 @@
6838468526
pOut = &aMem[pOp->p2];
6838568527
memAboutToChange(p, pOut);
6838668528
MemSetTypeFlag(pOut, MEM_Int);
6838768529
pOut->u.i = res;
6838868530
REGISTER_TRACE(pOp->p2, pOut);
68389
- }else if( res ){
68390
- pc = pOp->p2-1;
68531
+ }else{
68532
+ VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
68533
+ if( res ){
68534
+ pc = pOp->p2-1;
68535
+ }
6839168536
}
68392
-
6839368537
/* Undo any changes made by applyAffinity() to the input registers. */
6839468538
pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
6839568539
pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
6839668540
break;
6839768541
}
@@ -68484,15 +68628,15 @@
6848468628
** in the most recent OP_Compare instruction the P1 vector was less than
6848568629
** equal to, or greater than the P2 vector, respectively.
6848668630
*/
6848768631
case OP_Jump: { /* jump */
6848868632
if( iCompare<0 ){
68489
- pc = pOp->p1 - 1;
68633
+ pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
6849068634
}else if( iCompare==0 ){
68491
- pc = pOp->p2 - 1;
68635
+ pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
6849268636
}else{
68493
- pc = pOp->p3 - 1;
68637
+ pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
6849468638
}
6849568639
break;
6849668640
}
6849768641
6849868642
/* Opcode: And P1 P2 P3 * *
@@ -68586,14 +68730,17 @@
6858668730
}
6858768731
6858868732
/* Opcode: Once P1 P2 * * *
6858968733
**
6859068734
** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
68591
-** set the flag and fall through to the next instruction.
68735
+** set the flag and fall through to the next instruction. In other words,
68736
+** this opcode causes all following up codes up through P2 (but not including
68737
+** P2) to run just once and skipped on subsequent times through the loop.
6859268738
*/
6859368739
case OP_Once: { /* jump */
6859468740
assert( pOp->p1<p->nOnceFlag );
68741
+ VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
6859568742
if( p->aOnceFlag[pOp->p1] ){
6859668743
pc = pOp->p2-1;
6859768744
}else{
6859868745
p->aOnceFlag[pOp->p1] = 1;
6859968746
}
@@ -68624,10 +68771,11 @@
6862468771
#else
6862568772
c = sqlite3VdbeRealValue(pIn1)!=0.0;
6862668773
#endif
6862768774
if( pOp->opcode==OP_IfNot ) c = !c;
6862868775
}
68776
+ VdbeBranchTaken(c!=0, 2);
6862968777
if( c ){
6863068778
pc = pOp->p2-1;
6863168779
}
6863268780
break;
6863368781
}
@@ -68637,10 +68785,11 @@
6863768785
**
6863868786
** Jump to P2 if the value in register P1 is NULL.
6863968787
*/
6864068788
case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
6864168789
pIn1 = &aMem[pOp->p1];
68790
+ VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
6864268791
if( (pIn1->flags & MEM_Null)!=0 ){
6864368792
pc = pOp->p2 - 1;
6864468793
}
6864568794
break;
6864668795
}
@@ -68650,10 +68799,11 @@
6865068799
**
6865168800
** Jump to P2 if the value in register P1 is not NULL.
6865268801
*/
6865368802
case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
6865468803
pIn1 = &aMem[pOp->p1];
68804
+ VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
6865568805
if( (pIn1->flags & MEM_Null)==0 ){
6865668806
pc = pOp->p2 - 1;
6865768807
}
6865868808
break;
6865968809
}
@@ -68726,15 +68876,10 @@
6872668876
if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
6872768877
if( pC->nullRow ){
6872868878
if( pCrsr==0 ){
6872968879
assert( pC->pseudoTableReg>0 );
6873068880
pReg = &aMem[pC->pseudoTableReg];
68731
- if( pC->multiPseudo ){
68732
- sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68733
- Deephemeralize(pDest);
68734
- goto op_column_out;
68735
- }
6873668881
assert( pReg->flags & MEM_Blob );
6873768882
assert( memIsValid(pReg) );
6873868883
pC->payloadSize = pC->szRow = avail = pReg->n;
6873968884
pC->aRow = (u8*)pReg->z;
6874068885
}else{
@@ -68956,11 +69101,10 @@
6895669101
assert( zAffinity[pOp->p2]==0 );
6895769102
pIn1 = &aMem[pOp->p1];
6895869103
while( (cAff = *(zAffinity++))!=0 ){
6895969104
assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
6896069105
assert( memIsValid(pIn1) );
68961
- ExpandBlob(pIn1);
6896269106
applyAffinity(pIn1, cAff, encoding);
6896369107
pIn1++;
6896469108
}
6896569109
break;
6896669110
}
@@ -69034,12 +69178,13 @@
6903469178
*/
6903569179
assert( pData0<=pLast );
6903669180
if( zAffinity ){
6903769181
pRec = pData0;
6903869182
do{
69039
- applyAffinity(pRec, *(zAffinity++), encoding);
69040
- }while( (++pRec)<=pLast );
69183
+ applyAffinity(pRec++, *(zAffinity++), encoding);
69184
+ assert( zAffinity[0]==0 || pRec<=pLast );
69185
+ }while( zAffinity[0] );
6904169186
}
6904269187
6904369188
/* Loop through the elements that will make up the record to figure
6904469189
** out how much space is required for the new record.
6904569190
*/
@@ -69379,29 +69524,23 @@
6937969524
rc = SQLITE_ERROR;
6938069525
}
6938169526
break;
6938269527
}
6938369528
69384
-/* Opcode: Transaction P1 P2 * * *
69529
+/* Opcode: Transaction P1 P2 P3 P4 P5
6938569530
**
69386
-** Begin a transaction. The transaction ends when a Commit or Rollback
69387
-** opcode is encountered. Depending on the ON CONFLICT setting, the
69388
-** transaction might also be rolled back if an error is encountered.
69531
+** Begin a transaction on database P1 if a transaction is not already
69532
+** active.
69533
+** If P2 is non-zero, then a write-transaction is started, or if a
69534
+** read-transaction is already active, it is upgraded to a write-transaction.
69535
+** If P2 is zero, then a read-transaction is started.
6938969536
**
6939069537
** P1 is the index of the database file on which the transaction is
6939169538
** started. Index 0 is the main database file and index 1 is the
6939269539
** file used for temporary tables. Indices of 2 or more are used for
6939369540
** attached databases.
6939469541
**
69395
-** If P2 is non-zero, then a write-transaction is started. A RESERVED lock is
69396
-** obtained on the database file when a write-transaction is started. No
69397
-** other process can start another write transaction while this transaction is
69398
-** underway. Starting a write transaction also creates a rollback journal. A
69399
-** write transaction must be started before any changes can be made to the
69400
-** database. If P2 is greater than or equal to 2 then an EXCLUSIVE lock is
69401
-** also obtained on the file.
69402
-**
6940369542
** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
6940469543
** true (this flag is set if the Vdbe may modify more than one row and may
6940569544
** throw an ABORT exception), a statement transaction may also be opened.
6940669545
** More specifically, a statement transaction is opened iff the database
6940769546
** connection is currently not in autocommit mode, or if there are other
@@ -69408,14 +69547,25 @@
6940869547
** active statements. A statement transaction allows the changes made by this
6940969548
** VDBE to be rolled back after an error without having to roll back the
6941069549
** entire transaction. If no error is encountered, the statement transaction
6941169550
** will automatically commit when the VDBE halts.
6941269551
**
69413
-** If P2 is zero, then a read-lock is obtained on the database file.
69552
+** If P5!=0 then this opcode also checks the schema cookie against P3
69553
+** and the schema generation counter against P4.
69554
+** The cookie changes its value whenever the database schema changes.
69555
+** This operation is used to detect when that the cookie has changed
69556
+** and that the current process needs to reread the schema. If the schema
69557
+** cookie in P3 differs from the schema cookie in the database header or
69558
+** if the schema generation counter in P4 differs from the current
69559
+** generation counter, then an SQLITE_SCHEMA error is raised and execution
69560
+** halts. The sqlite3_step() wrapper function might then reprepare the
69561
+** statement and rerun it from the beginning.
6941469562
*/
6941569563
case OP_Transaction: {
6941669564
Btree *pBt;
69565
+ int iMeta;
69566
+ int iGen;
6941769567
6941869568
assert( p->bIsReader );
6941969569
assert( p->readOnly==0 || pOp->p2==0 );
6942069570
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6942169571
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
@@ -69455,10 +69605,39 @@
6945569605
** counter. If the statement transaction needs to be rolled back,
6945669606
** the value of this counter needs to be restored too. */
6945769607
p->nStmtDefCons = db->nDeferredCons;
6945869608
p->nStmtDefImmCons = db->nDeferredImmCons;
6945969609
}
69610
+
69611
+ /* Gather the schema version number for checking */
69612
+ sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69613
+ iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69614
+ }else{
69615
+ iGen = iMeta = 0;
69616
+ }
69617
+ assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
69618
+ if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){
69619
+ sqlite3DbFree(db, p->zErrMsg);
69620
+ p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69621
+ /* If the schema-cookie from the database file matches the cookie
69622
+ ** stored with the in-memory representation of the schema, do
69623
+ ** not reload the schema from the database file.
69624
+ **
69625
+ ** If virtual-tables are in use, this is not just an optimization.
69626
+ ** Often, v-tables store their data in other SQLite tables, which
69627
+ ** are queried from within xNext() and other v-table methods using
69628
+ ** prepared queries. If such a query is out-of-date, we do not want to
69629
+ ** discard the database schema, as the user code implementing the
69630
+ ** v-table would have to be ready for the sqlite3_vtab structure itself
69631
+ ** to be invalidated whenever sqlite3_step() is called from within
69632
+ ** a v-table method.
69633
+ */
69634
+ if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69635
+ sqlite3ResetOneSchema(db, pOp->p1);
69636
+ }
69637
+ p->expired = 1;
69638
+ rc = SQLITE_SCHEMA;
6946069639
}
6946169640
break;
6946269641
}
6946369642
6946469643
/* Opcode: ReadCookie P1 P2 P3 * *
@@ -69526,70 +69705,10 @@
6952669705
/* Invalidate all prepared statements whenever the TEMP database
6952769706
** schema is changed. Ticket #1644 */
6952869707
sqlite3ExpirePreparedStatements(db);
6952969708
p->expired = 0;
6953069709
}
69531
- break;
69532
-}
69533
-
69534
-/* Opcode: VerifyCookie P1 P2 P3 * *
69535
-**
69536
-** Check the value of global database parameter number 0 (the
69537
-** schema version) and make sure it is equal to P2 and that the
69538
-** generation counter on the local schema parse equals P3.
69539
-**
69540
-** P1 is the database number which is 0 for the main database file
69541
-** and 1 for the file holding temporary tables and some higher number
69542
-** for auxiliary databases.
69543
-**
69544
-** The cookie changes its value whenever the database schema changes.
69545
-** This operation is used to detect when that the cookie has changed
69546
-** and that the current process needs to reread the schema.
69547
-**
69548
-** Either a transaction needs to have been started or an OP_Open needs
69549
-** to be executed (to establish a read lock) before this opcode is
69550
-** invoked.
69551
-*/
69552
-case OP_VerifyCookie: {
69553
- int iMeta;
69554
- int iGen;
69555
- Btree *pBt;
69556
-
69557
- assert( pOp->p1>=0 && pOp->p1<db->nDb );
69558
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69559
- assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69560
- assert( p->bIsReader );
69561
- pBt = db->aDb[pOp->p1].pBt;
69562
- if( pBt ){
69563
- sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69564
- iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69565
- }else{
69566
- iGen = iMeta = 0;
69567
- }
69568
- if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69569
- sqlite3DbFree(db, p->zErrMsg);
69570
- p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69571
- /* If the schema-cookie from the database file matches the cookie
69572
- ** stored with the in-memory representation of the schema, do
69573
- ** not reload the schema from the database file.
69574
- **
69575
- ** If virtual-tables are in use, this is not just an optimization.
69576
- ** Often, v-tables store their data in other SQLite tables, which
69577
- ** are queried from within xNext() and other v-table methods using
69578
- ** prepared queries. If such a query is out-of-date, we do not want to
69579
- ** discard the database schema, as the user code implementing the
69580
- ** v-table would have to be ready for the sqlite3_vtab structure itself
69581
- ** to be invalidated whenever sqlite3_step() is called from within
69582
- ** a v-table method.
69583
- */
69584
- if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69585
- sqlite3ResetOneSchema(db, pOp->p1);
69586
- }
69587
-
69588
- p->expired = 1;
69589
- rc = SQLITE_SCHEMA;
69590
- }
6959169710
break;
6959269711
}
6959369712
6959469713
/* Opcode: OpenRead P1 P2 P3 P4 P5
6959569714
** Synopsis: root=P2 iDb=P3
@@ -69802,11 +69921,11 @@
6980269921
}
6980369922
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
6980469923
break;
6980569924
}
6980669925
69807
-/* Opcode: SorterOpen P1 * * P4 *
69926
+/* Opcode: SorterOpen P1 P2 * P4 *
6980869927
**
6980969928
** This opcode works like OP_OpenEphemeral except that it opens
6981069929
** a transient index that is specifically designed to sort large
6981169930
** tables using an external merge-sort algorithm.
6981269931
*/
@@ -69822,18 +69941,17 @@
6982269941
assert( pCx->pKeyInfo->enc==ENC(db) );
6982369942
rc = sqlite3VdbeSorterInit(db, pCx);
6982469943
break;
6982569944
}
6982669945
69827
-/* Opcode: OpenPseudo P1 P2 P3 * P5
69828
-** Synopsis: content in r[P2@P3]
69946
+/* Opcode: OpenPseudo P1 P2 P3 * *
69947
+** Synopsis: P3 columns in r[P2]
6982969948
**
6983069949
** Open a new cursor that points to a fake table that contains a single
69831
-** row of data. The content of that one row in the content of memory
69832
-** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
69833
-** MEM_Blob content contained in register P2. When P5==1, then the
69834
-** row is represented by P3 consecutive registers beginning with P2.
69950
+** row of data. The content of that one row is the content of memory
69951
+** register P2. In other words, cursor P1 becomes an alias for the
69952
+** MEM_Blob content contained in register P2.
6983569953
**
6983669954
** A pseudo-table created by this opcode is used to hold a single
6983769955
** row output from the sorter so that the row can be decomposed into
6983869956
** individual columns using the OP_Column opcode. The OP_Column opcode
6983969957
** is the only cursor opcode that works with a pseudo-table.
@@ -69849,11 +69967,11 @@
6984969967
pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
6985069968
if( pCx==0 ) goto no_mem;
6985169969
pCx->nullRow = 1;
6985269970
pCx->pseudoTableReg = pOp->p2;
6985369971
pCx->isTable = 1;
69854
- pCx->multiPseudo = pOp->p5;
69972
+ assert( pOp->p5==0 );
6985569973
break;
6985669974
}
6985769975
6985869976
/* Opcode: Close P1 * * * *
6985969977
**
@@ -69921,14 +70039,14 @@
6992170039
** is less than or equal to the key value. If there are no records
6992270040
** less than or equal to the key and P2 is not zero, then jump to P2.
6992370041
**
6992470042
** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
6992570043
*/
69926
-case OP_SeekLt: /* jump, in3 */
69927
-case OP_SeekLe: /* jump, in3 */
69928
-case OP_SeekGe: /* jump, in3 */
69929
-case OP_SeekGt: { /* jump, in3 */
70044
+case OP_SeekLT: /* jump, in3 */
70045
+case OP_SeekLE: /* jump, in3 */
70046
+case OP_SeekGE: /* jump, in3 */
70047
+case OP_SeekGT: { /* jump, in3 */
6993070048
int res;
6993170049
int oc;
6993270050
VdbeCursor *pC;
6993370051
UnpackedRecord r;
6993470052
int nField;
@@ -69937,13 +70055,13 @@
6993770055
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6993870056
assert( pOp->p2!=0 );
6993970057
pC = p->apCsr[pOp->p1];
6994070058
assert( pC!=0 );
6994170059
assert( pC->pseudoTableReg==0 );
69942
- assert( OP_SeekLe == OP_SeekLt+1 );
69943
- assert( OP_SeekGe == OP_SeekLt+2 );
69944
- assert( OP_SeekGt == OP_SeekLt+3 );
70060
+ assert( OP_SeekLE == OP_SeekLT+1 );
70061
+ assert( OP_SeekGE == OP_SeekLT+2 );
70062
+ assert( OP_SeekGT == OP_SeekLT+3 );
6994570063
assert( pC->isOrdered );
6994670064
assert( pC->pCursor!=0 );
6994770065
oc = pOp->opcode;
6994870066
pC->nullRow = 0;
6994970067
if( pC->isTable ){
@@ -69959,11 +70077,11 @@
6995970077
** loss of information, then special processing is required... */
6996070078
if( (pIn3->flags & MEM_Int)==0 ){
6996170079
if( (pIn3->flags & MEM_Real)==0 ){
6996270080
/* If the P3 value cannot be converted into any kind of a number,
6996370081
** then the seek is not possible, so jump to P2 */
69964
- pc = pOp->p2 - 1;
70082
+ pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
6996570083
break;
6996670084
}
6996770085
6996870086
/* If the approximation iKey is larger than the actual real search
6996970087
** term, substitute >= for > and < for <=. e.g. if the search term
@@ -69971,23 +70089,23 @@
6997170089
**
6997270090
** (x > 4.9) -> (x >= 5)
6997370091
** (x <= 4.9) -> (x < 5)
6997470092
*/
6997570093
if( pIn3->r<(double)iKey ){
69976
- assert( OP_SeekGe==(OP_SeekGt-1) );
69977
- assert( OP_SeekLt==(OP_SeekLe-1) );
69978
- assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69979
- if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
70094
+ assert( OP_SeekGE==(OP_SeekGT-1) );
70095
+ assert( OP_SeekLT==(OP_SeekLE-1) );
70096
+ assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
70097
+ if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
6998070098
}
6998170099
6998270100
/* If the approximation iKey is smaller than the actual real search
6998370101
** term, substitute <= for < and > for >=. */
6998470102
else if( pIn3->r>(double)iKey ){
69985
- assert( OP_SeekLe==(OP_SeekLt+1) );
69986
- assert( OP_SeekGt==(OP_SeekGe+1) );
69987
- assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69988
- if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
70103
+ assert( OP_SeekLE==(OP_SeekLT+1) );
70104
+ assert( OP_SeekGT==(OP_SeekGE+1) );
70105
+ assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
70106
+ if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
6998970107
}
6999070108
}
6999170109
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
6999270110
if( rc!=SQLITE_OK ){
6999370111
goto abort_due_to_error;
@@ -70002,21 +70120,21 @@
7000270120
assert( nField>0 );
7000370121
r.pKeyInfo = pC->pKeyInfo;
7000470122
r.nField = (u16)nField;
7000570123
7000670124
/* The next line of code computes as follows, only faster:
70007
- ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
70125
+ ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
7000870126
** r.flags = UNPACKED_INCRKEY;
7000970127
** }else{
7001070128
** r.flags = 0;
7001170129
** }
7001270130
*/
70013
- r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
70014
- assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
70015
- assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
70016
- assert( oc!=OP_SeekGe || r.flags==0 );
70017
- assert( oc!=OP_SeekLt || r.flags==0 );
70131
+ r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132
+ assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133
+ assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134
+ assert( oc!=OP_SeekGE || r.flags==0 );
70135
+ assert( oc!=OP_SeekLT || r.flags==0 );
7001870136
7001970137
r.aMem = &aMem[pOp->p3];
7002070138
#ifdef SQLITE_DEBUG
7002170139
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7002270140
#endif
@@ -70030,21 +70148,23 @@
7003070148
pC->deferredMoveto = 0;
7003170149
pC->cacheStatus = CACHE_STALE;
7003270150
#ifdef SQLITE_TEST
7003370151
sqlite3_search_count++;
7003470152
#endif
70035
- if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
70036
- if( res<0 || (res==0 && oc==OP_SeekGt) ){
70153
+ if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
70154
+ if( res<0 || (res==0 && oc==OP_SeekGT) ){
70155
+ res = 0;
7003770156
rc = sqlite3BtreeNext(pC->pCursor, &res);
7003870157
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7003970158
pC->rowidIsValid = 0;
7004070159
}else{
7004170160
res = 0;
7004270161
}
7004370162
}else{
70044
- assert( oc==OP_SeekLt || oc==OP_SeekLe );
70045
- if( res>0 || (res==0 && oc==OP_SeekLt) ){
70163
+ assert( oc==OP_SeekLT || oc==OP_SeekLE );
70164
+ if( res>0 || (res==0 && oc==OP_SeekLT) ){
70165
+ res = 0;
7004670166
rc = sqlite3BtreePrevious(pC->pCursor, &res);
7004770167
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7004870168
pC->rowidIsValid = 0;
7004970169
}else{
7005070170
/* res might be negative because the table is empty. Check to
@@ -70052,10 +70172,11 @@
7005270172
*/
7005370173
res = sqlite3BtreeEof(pC->pCursor);
7005470174
}
7005570175
}
7005670176
assert( pOp->p2>0 );
70177
+ VdbeBranchTaken(res!=0,2);
7005770178
if( res ){
7005870179
pc = pOp->p2 - 1;
7005970180
}
7006070181
break;
7006170182
}
@@ -70160,19 +70281,17 @@
7016070281
pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
7016170282
if( pOp->p4.i>0 ){
7016270283
r.pKeyInfo = pC->pKeyInfo;
7016370284
r.nField = (u16)pOp->p4.i;
7016470285
r.aMem = pIn3;
70286
+ for(ii=0; ii<r.nField; ii++){
70287
+ assert( memIsValid(&r.aMem[ii]) );
70288
+ ExpandBlob(&r.aMem[ii]);
7016570289
#ifdef SQLITE_DEBUG
70166
- {
70167
- int i;
70168
- for(i=0; i<r.nField; i++){
70169
- assert( memIsValid(&r.aMem[i]) );
70170
- if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
70171
- }
70172
- }
70173
-#endif
70290
+ if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70291
+#endif
70292
+ }
7017470293
r.flags = UNPACKED_PREFIX_MATCH;
7017570294
pIdxKey = &r;
7017670295
}else{
7017770296
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
7017870297
pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
@@ -70187,11 +70306,11 @@
7018770306
/* For the OP_NoConflict opcode, take the jump if any of the
7018870307
** input fields are NULL, since any key with a NULL will not
7018970308
** conflict */
7019070309
for(ii=0; ii<r.nField; ii++){
7019170310
if( r.aMem[ii].flags & MEM_Null ){
70192
- pc = pOp->p2 - 1;
70311
+ pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
7019370312
break;
7019470313
}
7019570314
}
7019670315
}
7019770316
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
@@ -70205,12 +70324,14 @@
7020570324
alreadyExists = (res==0);
7020670325
pC->nullRow = 1-alreadyExists;
7020770326
pC->deferredMoveto = 0;
7020870327
pC->cacheStatus = CACHE_STALE;
7020970328
if( pOp->opcode==OP_Found ){
70329
+ VdbeBranchTaken(alreadyExists!=0,2);
7021070330
if( alreadyExists ) pc = pOp->p2 - 1;
7021170331
}else{
70332
+ VdbeBranchTaken(alreadyExists==0,2);
7021270333
if( !alreadyExists ) pc = pOp->p2 - 1;
7021370334
}
7021470335
break;
7021570336
}
7021670337
@@ -70249,10 +70370,11 @@
7024970370
pC->lastRowid = pIn3->u.i;
7025070371
pC->rowidIsValid = res==0 ?1:0;
7025170372
pC->nullRow = 0;
7025270373
pC->cacheStatus = CACHE_STALE;
7025370374
pC->deferredMoveto = 0;
70375
+ VdbeBranchTaken(res!=0,2);
7025470376
if( res!=0 ){
7025570377
pc = pOp->p2 - 1;
7025670378
assert( pC->rowidIsValid==0 );
7025770379
}
7025870380
pC->seekResult = res;
@@ -70330,63 +70452,58 @@
7033070452
*/
7033170453
# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
7033270454
#endif
7033370455
7033470456
if( !pC->useRandomRowid ){
70335
- v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70336
- if( v==0 ){
70337
- rc = sqlite3BtreeLast(pC->pCursor, &res);
70338
- if( rc!=SQLITE_OK ){
70339
- goto abort_due_to_error;
70340
- }
70341
- if( res ){
70342
- v = 1; /* IMP: R-61914-48074 */
70343
- }else{
70344
- assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70345
- rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70346
- assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70347
- if( v>=MAX_ROWID ){
70348
- pC->useRandomRowid = 1;
70349
- }else{
70350
- v++; /* IMP: R-29538-34987 */
70351
- }
70352
- }
70353
- }
70354
-
70355
-#ifndef SQLITE_OMIT_AUTOINCREMENT
70356
- if( pOp->p3 ){
70357
- /* Assert that P3 is a valid memory cell. */
70358
- assert( pOp->p3>0 );
70359
- if( p->pFrame ){
70360
- for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70361
- /* Assert that P3 is a valid memory cell. */
70362
- assert( pOp->p3<=pFrame->nMem );
70363
- pMem = &pFrame->aMem[pOp->p3];
70364
- }else{
70365
- /* Assert that P3 is a valid memory cell. */
70366
- assert( pOp->p3<=(p->nMem-p->nCursor) );
70367
- pMem = &aMem[pOp->p3];
70368
- memAboutToChange(p, pMem);
70369
- }
70370
- assert( memIsValid(pMem) );
70371
-
70372
- REGISTER_TRACE(pOp->p3, pMem);
70373
- sqlite3VdbeMemIntegerify(pMem);
70374
- assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70375
- if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70376
- rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70377
- goto abort_due_to_error;
70378
- }
70379
- if( v<pMem->u.i+1 ){
70380
- v = pMem->u.i + 1;
70381
- }
70382
- pMem->u.i = v;
70383
- }
70384
-#endif
70385
-
70386
- sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70387
- }
70457
+ rc = sqlite3BtreeLast(pC->pCursor, &res);
70458
+ if( rc!=SQLITE_OK ){
70459
+ goto abort_due_to_error;
70460
+ }
70461
+ if( res ){
70462
+ v = 1; /* IMP: R-61914-48074 */
70463
+ }else{
70464
+ assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70465
+ rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70466
+ assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70467
+ if( v>=MAX_ROWID ){
70468
+ pC->useRandomRowid = 1;
70469
+ }else{
70470
+ v++; /* IMP: R-29538-34987 */
70471
+ }
70472
+ }
70473
+ }
70474
+
70475
+#ifndef SQLITE_OMIT_AUTOINCREMENT
70476
+ if( pOp->p3 ){
70477
+ /* Assert that P3 is a valid memory cell. */
70478
+ assert( pOp->p3>0 );
70479
+ if( p->pFrame ){
70480
+ for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70481
+ /* Assert that P3 is a valid memory cell. */
70482
+ assert( pOp->p3<=pFrame->nMem );
70483
+ pMem = &pFrame->aMem[pOp->p3];
70484
+ }else{
70485
+ /* Assert that P3 is a valid memory cell. */
70486
+ assert( pOp->p3<=(p->nMem-p->nCursor) );
70487
+ pMem = &aMem[pOp->p3];
70488
+ memAboutToChange(p, pMem);
70489
+ }
70490
+ assert( memIsValid(pMem) );
70491
+
70492
+ REGISTER_TRACE(pOp->p3, pMem);
70493
+ sqlite3VdbeMemIntegerify(pMem);
70494
+ assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70495
+ if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70496
+ rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70497
+ goto abort_due_to_error;
70498
+ }
70499
+ if( v<pMem->u.i+1 ){
70500
+ v = pMem->u.i + 1;
70501
+ }
70502
+ pMem->u.i = v;
70503
+ }
70504
+#endif
7038870505
if( pC->useRandomRowid ){
7038970506
/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
7039070507
** largest possible integer (9223372036854775807) then the database
7039170508
** engine starts picking positive candidate ROWIDs at random until
7039270509
** it finds one that is not previously used. */
@@ -70516,11 +70633,10 @@
7051670633
if( pData->flags & MEM_Zero ){
7051770634
nZero = pData->u.nZero;
7051870635
}else{
7051970636
nZero = 0;
7052070637
}
70521
- sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
7052270638
rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
7052370639
pData->z, pData->n, nZero,
7052470640
(pOp->p5 & OPFLAG_APPEND)!=0, seekResult
7052570641
);
7052670642
pC->rowidIsValid = 0;
@@ -70578,11 +70694,10 @@
7057870694
**/
7057970695
assert( pC->deferredMoveto==0 );
7058070696
rc = sqlite3VdbeCursorMoveto(pC);
7058170697
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7058270698
70583
- sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
7058470699
rc = sqlite3BtreeDelete(pC->pCursor);
7058570700
pC->cacheStatus = CACHE_STALE;
7058670701
7058770702
/* Invoke the update-hook if required. */
7058870703
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
@@ -70630,10 +70745,11 @@
7063070745
assert( isSorter(pC) );
7063170746
assert( pOp->p4type==P4_INT32 );
7063270747
pIn3 = &aMem[pOp->p3];
7063370748
nIgnore = pOp->p4.i;
7063470749
rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70750
+ VdbeBranchTaken(res!=0,2);
7063570751
if( res ){
7063670752
pc = pOp->p2-1;
7063770753
}
7063870754
break;
7063970755
};
@@ -70667,11 +70783,11 @@
7066770783
/* Opcode: RowKey P1 P2 * * *
7066870784
** Synopsis: r[P2]=key
7066970785
**
7067070786
** Write into register P2 the complete row key for cursor P1.
7067170787
** There is no interpretation of the data.
70672
-** The key is copied onto the P3 register exactly as
70788
+** The key is copied onto the P2 register exactly as
7067370789
** it is found in the database file.
7067470790
**
7067570791
** If the P1 cursor must be pointing to a valid row (not a NULL row)
7067670792
** of a real table, not a pseudo-table.
7067770793
*/
@@ -70829,12 +70945,13 @@
7082970945
rc = sqlite3BtreeLast(pCrsr, &res);
7083070946
pC->nullRow = (u8)res;
7083170947
pC->deferredMoveto = 0;
7083270948
pC->rowidIsValid = 0;
7083370949
pC->cacheStatus = CACHE_STALE;
70834
- if( pOp->p2>0 && res ){
70835
- pc = pOp->p2 - 1;
70950
+ if( pOp->p2>0 ){
70951
+ VdbeBranchTaken(res!=0,2);
70952
+ if( res ) pc = pOp->p2 - 1;
7083670953
}
7083770954
break;
7083870955
}
7083970956
7084070957
@@ -70887,56 +71004,67 @@
7088771004
pC->cacheStatus = CACHE_STALE;
7088871005
pC->rowidIsValid = 0;
7088971006
}
7089071007
pC->nullRow = (u8)res;
7089171008
assert( pOp->p2>0 && pOp->p2<p->nOp );
71009
+ VdbeBranchTaken(res!=0,2);
7089271010
if( res ){
7089371011
pc = pOp->p2 - 1;
7089471012
}
7089571013
break;
7089671014
}
7089771015
70898
-/* Opcode: Next P1 P2 * * P5
71016
+/* Opcode: Next P1 P2 P3 P4 P5
7089971017
**
7090071018
** Advance cursor P1 so that it points to the next key/data pair in its
7090171019
** table or index. If there are no more key/value pairs then fall through
7090271020
** to the following instruction. But if the cursor advance was successful,
7090371021
** jump immediately to P2.
7090471022
**
7090571023
** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
7090671024
** been opened prior to this opcode or the program will segfault.
71025
+**
71026
+** The P3 value is a hint to the btree implementation. If P3==1, that
71027
+** means P1 is an SQL index and that this instruction could have been
71028
+** omitted if that index had been unique. P3 is usually 0. P3 is
71029
+** always either 0 or 1.
7090771030
**
7090871031
** P4 is always of type P4_ADVANCE. The function pointer points to
7090971032
** sqlite3BtreeNext().
7091071033
**
7091171034
** If P5 is positive and the jump is taken, then event counter
7091271035
** number P5-1 in the prepared statement is incremented.
7091371036
**
7091471037
** See also: Prev, NextIfOpen
7091571038
*/
70916
-/* Opcode: NextIfOpen P1 P2 * * P5
71039
+/* Opcode: NextIfOpen P1 P2 P3 P4 P5
7091771040
**
7091871041
** This opcode works just like OP_Next except that if cursor P1 is not
7091971042
** open it behaves a no-op.
7092071043
*/
70921
-/* Opcode: Prev P1 P2 * * P5
71044
+/* Opcode: Prev P1 P2 P3 P4 P5
7092271045
**
7092371046
** Back up cursor P1 so that it points to the previous key/data pair in its
7092471047
** table or index. If there is no previous key/value pairs then fall through
7092571048
** to the following instruction. But if the cursor backup was successful,
7092671049
** jump immediately to P2.
7092771050
**
7092871051
** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
7092971052
** not open then the behavior is undefined.
71053
+**
71054
+** The P3 value is a hint to the btree implementation. If P3==1, that
71055
+** means P1 is an SQL index and that this instruction could have been
71056
+** omitted if that index had been unique. P3 is usually 0. P3 is
71057
+** always either 0 or 1.
7093071058
**
7093171059
** P4 is always of type P4_ADVANCE. The function pointer points to
7093271060
** sqlite3BtreePrevious().
7093371061
**
7093471062
** If P5 is positive and the jump is taken, then event counter
7093571063
** number P5-1 in the prepared statement is incremented.
7093671064
*/
70937
-/* Opcode: PrevIfOpen P1 P2 * * P5
71065
+/* Opcode: PrevIfOpen P1 P2 P3 P4 P5
7093871066
**
7093971067
** This opcode works just like OP_Prev except that if cursor P1 is not
7094071068
** open it behaves a no-op.
7094171069
*/
7094271070
case OP_SorterNext: { /* jump */
@@ -70954,20 +71082,24 @@
7095471082
case OP_Prev: /* jump */
7095571083
case OP_Next: /* jump */
7095671084
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7095771085
assert( pOp->p5<ArraySize(p->aCounter) );
7095871086
pC = p->apCsr[pOp->p1];
71087
+ res = pOp->p3;
7095971088
assert( pC!=0 );
7096071089
assert( pC->deferredMoveto==0 );
7096171090
assert( pC->pCursor );
71091
+ assert( res==0 || (res==1 && pC->isTable==0) );
71092
+ testcase( res==1 );
7096271093
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
7096371094
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
7096471095
assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
7096571096
assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
7096671097
rc = pOp->p4.xAdvance(pC->pCursor, &res);
7096771098
next_tail:
7096871099
pC->cacheStatus = CACHE_STALE;
71100
+ VdbeBranchTaken(res==0,2);
7096971101
if( res==0 ){
7097071102
pC->nullRow = 0;
7097171103
pc = pOp->p2 - 1;
7097271104
p->aCounter[pOp->p5]++;
7097371105
#ifdef SQLITE_TEST
@@ -70987,10 +71119,18 @@
7098771119
** MakeRecord instructions. This opcode writes that key
7098871120
** into the index P1. Data for the entry is nil.
7098971121
**
7099071122
** P3 is a flag that provides a hint to the b-tree layer that this
7099171123
** insert is likely to be an append.
71124
+**
71125
+** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
71126
+** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
71127
+** then the change counter is unchanged.
71128
+**
71129
+** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have
71130
+** just done a seek to the spot where the new entry is to be inserted.
71131
+** This flag avoids doing an extra seek.
7099271132
**
7099371133
** This instruction only works for indices. The equivalent instruction
7099471134
** for tables is OP_Insert.
7099571135
*/
7099671136
case OP_SorterInsert: /* in2 */
@@ -71102,36 +71242,54 @@
7110271242
7110371243
/* Opcode: IdxGE P1 P2 P3 P4 P5
7110471244
** Synopsis: key=r[P3@P4]
7110571245
**
7110671246
** The P4 register values beginning with P3 form an unpacked index
71107
-** key that omits the ROWID. Compare this key value against the index
71108
-** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
71247
+** key that omits the PRIMARY KEY. Compare this key value against the index
71248
+** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71249
+** fields at the end.
7110971250
**
7111071251
** If the P1 index entry is greater than or equal to the key value
7111171252
** then jump to P2. Otherwise fall through to the next instruction.
71253
+*/
71254
+/* Opcode: IdxGT P1 P2 P3 P4 P5
71255
+** Synopsis: key=r[P3@P4]
7111271256
**
71113
-** If P5 is non-zero then the key value is increased by an epsilon
71114
-** prior to the comparison. This make the opcode work like IdxGT except
71115
-** that if the key from register P3 is a prefix of the key in the cursor,
71116
-** the result is false whereas it would be true with IdxGT.
71257
+** The P4 register values beginning with P3 form an unpacked index
71258
+** key that omits the PRIMARY KEY. Compare this key value against the index
71259
+** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71260
+** fields at the end.
71261
+**
71262
+** If the P1 index entry is greater than the key value
71263
+** then jump to P2. Otherwise fall through to the next instruction.
7111771264
*/
7111871265
/* Opcode: IdxLT P1 P2 P3 P4 P5
7111971266
** Synopsis: key=r[P3@P4]
7112071267
**
7112171268
** The P4 register values beginning with P3 form an unpacked index
71122
-** key that omits the ROWID. Compare this key value against the index
71123
-** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
71269
+** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71270
+** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71271
+** ROWID on the P1 index.
7112471272
**
7112571273
** If the P1 index entry is less than the key value then jump to P2.
7112671274
** Otherwise fall through to the next instruction.
71275
+*/
71276
+/* Opcode: IdxLE P1 P2 P3 P4 P5
71277
+** Synopsis: key=r[P3@P4]
7112771278
**
71128
-** If P5 is non-zero then the key value is increased by an epsilon prior
71129
-** to the comparison. This makes the opcode work like IdxLE.
71279
+** The P4 register values beginning with P3 form an unpacked index
71280
+** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71281
+** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71282
+** ROWID on the P1 index.
71283
+**
71284
+** If the P1 index entry is less than or equal to the key value then jump
71285
+** to P2. Otherwise fall through to the next instruction.
7113071286
*/
71287
+case OP_IdxLE: /* jump */
71288
+case OP_IdxGT: /* jump */
7113171289
case OP_IdxLT: /* jump */
71132
-case OP_IdxGE: { /* jump */
71290
+case OP_IdxGE: { /* jump */
7113371291
VdbeCursor *pC;
7113471292
int res;
7113571293
UnpackedRecord r;
7113671294
7113771295
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -71142,27 +71300,32 @@
7114271300
assert( pC->deferredMoveto==0 );
7114371301
assert( pOp->p5==0 || pOp->p5==1 );
7114471302
assert( pOp->p4type==P4_INT32 );
7114571303
r.pKeyInfo = pC->pKeyInfo;
7114671304
r.nField = (u16)pOp->p4.i;
71147
- if( pOp->p5 ){
71305
+ if( pOp->opcode<OP_IdxLT ){
71306
+ assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
7114871307
r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
7114971308
}else{
71309
+ assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
7115071310
r.flags = UNPACKED_PREFIX_MATCH;
7115171311
}
7115271312
r.aMem = &aMem[pOp->p3];
7115371313
#ifdef SQLITE_DEBUG
7115471314
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7115571315
#endif
7115671316
res = 0; /* Not needed. Only used to silence a warning. */
7115771317
rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71158
- if( pOp->opcode==OP_IdxLT ){
71318
+ assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
71319
+ if( (pOp->opcode&1)==(OP_IdxLT&1) ){
71320
+ assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
7115971321
res = -res;
7116071322
}else{
71161
- assert( pOp->opcode==OP_IdxGE );
71323
+ assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
7116271324
res++;
7116371325
}
71326
+ VdbeBranchTaken(res>0,2);
7116471327
if( res>0 ){
7116571328
pc = pOp->p2 - 1 ;
7116671329
}
7116771330
break;
7116871331
}
@@ -71251,11 +71414,10 @@
7125171414
case OP_Clear: {
7125271415
int nChange;
7125371416
7125471417
nChange = 0;
7125571418
assert( p->readOnly==0 );
71256
- assert( pOp->p1!=1 );
7125771419
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
7125871420
rc = sqlite3BtreeClearTable(
7125971421
db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
7126071422
);
7126171423
if( pOp->p3 ){
@@ -71520,13 +71682,15 @@
7152071682
|| sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
7152171683
){
7152271684
/* The boolean index is empty */
7152371685
sqlite3VdbeMemSetNull(pIn1);
7152471686
pc = pOp->p2 - 1;
71687
+ VdbeBranchTaken(1,2);
7152571688
}else{
7152671689
/* A value was pulled from the index */
7152771690
sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71691
+ VdbeBranchTaken(0,2);
7152871692
}
7152971693
goto check_for_interrupt;
7153071694
}
7153171695
7153271696
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -71574,10 +71738,11 @@
7157471738
assert( iSet==-1 || iSet>=0 );
7157571739
if( iSet ){
7157671740
exists = sqlite3RowSetTest(pIn1->u.pRowSet,
7157771741
(u8)(iSet>=0 ? iSet & 0xf : 0xff),
7157871742
pIn3->u.i);
71743
+ VdbeBranchTaken(exists!=0,2);
7157971744
if( exists ){
7158071745
pc = pOp->p2 - 1;
7158171746
break;
7158271747
}
7158371748
}
@@ -71588,11 +71753,11 @@
7158871753
}
7158971754
7159071755
7159171756
#ifndef SQLITE_OMIT_TRIGGER
7159271757
71593
-/* Opcode: Program P1 P2 P3 P4 *
71758
+/* Opcode: Program P1 P2 P3 P4 P5
7159471759
**
7159571760
** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
7159671761
**
7159771762
** P1 contains the address of the memory cell that contains the first memory
7159871763
** cell in an array of values used as arguments to the sub-program. P2
@@ -71600,10 +71765,12 @@
7160071765
** exception using the RAISE() function. Register P3 contains the address
7160171766
** of a memory cell in this (the parent) VM that is used to allocate the
7160271767
** memory required by the sub-vdbe at runtime.
7160371768
**
7160471769
** P4 is a pointer to the VM containing the trigger program.
71770
+**
71771
+** If P5 is non-zero, then recursive program invocation is enabled.
7160571772
*/
7160671773
case OP_Program: { /* jump */
7160771774
int nMem; /* Number of memory registers for sub-program */
7160871775
int nByte; /* Bytes of runtime space required for sub-program */
7160971776
Mem *pRt; /* Register to allocate runtime space */
@@ -71677,11 +71844,11 @@
7167771844
pFrame->aOnceFlag = p->aOnceFlag;
7167871845
pFrame->nOnceFlag = p->nOnceFlag;
7167971846
7168071847
pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
7168171848
for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71682
- pMem->flags = MEM_Invalid;
71849
+ pMem->flags = MEM_Undefined;
7168371850
pMem->db = db;
7168471851
}
7168571852
}else{
7168671853
pFrame = pRt->u.pFrame;
7168771854
assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
@@ -71764,12 +71931,14 @@
7176471931
** zero, the jump is taken if the statement constraint-counter is zero
7176571932
** (immediate foreign key constraint violations).
7176671933
*/
7176771934
case OP_FkIfZero: { /* jump */
7176871935
if( pOp->p1 ){
71936
+ VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
7176971937
if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
7177071938
}else{
71939
+ VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
7177171940
if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
7177271941
}
7177371942
break;
7177471943
}
7177571944
#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
@@ -71814,10 +71983,11 @@
7181471983
** not contain an integer. An assertion fault will result if you try.
7181571984
*/
7181671985
case OP_IfPos: { /* jump, in1 */
7181771986
pIn1 = &aMem[pOp->p1];
7181871987
assert( pIn1->flags&MEM_Int );
71988
+ VdbeBranchTaken( pIn1->u.i>0, 2);
7181971989
if( pIn1->u.i>0 ){
7182071990
pc = pOp->p2 - 1;
7182171991
}
7182271992
break;
7182371993
}
@@ -71831,10 +72001,11 @@
7183172001
** not contain an integer. An assertion fault will result if you try.
7183272002
*/
7183372003
case OP_IfNeg: { /* jump, in1 */
7183472004
pIn1 = &aMem[pOp->p1];
7183572005
assert( pIn1->flags&MEM_Int );
72006
+ VdbeBranchTaken(pIn1->u.i<0, 2);
7183672007
if( pIn1->u.i<0 ){
7183772008
pc = pOp->p2 - 1;
7183872009
}
7183972010
break;
7184072011
}
@@ -71850,10 +72021,11 @@
7185072021
*/
7185172022
case OP_IfZero: { /* jump, in1 */
7185272023
pIn1 = &aMem[pOp->p1];
7185372024
assert( pIn1->flags&MEM_Int );
7185472025
pIn1->u.i += pOp->p3;
72026
+ VdbeBranchTaken(pIn1->u.i==0, 2);
7185572027
if( pIn1->u.i==0 ){
7185672028
pc = pOp->p2 - 1;
7185772029
}
7185872030
break;
7185972031
}
@@ -71987,11 +72159,11 @@
7198772159
break;
7198872160
};
7198972161
#endif
7199072162
7199172163
#ifndef SQLITE_OMIT_PRAGMA
71992
-/* Opcode: JournalMode P1 P2 P3 * P5
72164
+/* Opcode: JournalMode P1 P2 P3 * *
7199372165
**
7199472166
** Change the journal mode of database P1 to P3. P3 must be one of the
7199572167
** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
7199672168
** modes (delete, truncate, persist, off and memory), this is a simple
7199772169
** operation. No IO is required.
@@ -72121,10 +72293,11 @@
7212172293
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7212272294
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7212372295
assert( p->readOnly==0 );
7212472296
pBt = db->aDb[pOp->p1].pBt;
7212572297
rc = sqlite3BtreeIncrVacuum(pBt);
72298
+ VdbeBranchTaken(rc==SQLITE_DONE,2);
7212672299
if( rc==SQLITE_DONE ){
7212772300
pc = pOp->p2 - 1;
7212872301
rc = SQLITE_OK;
7212972302
}
7213072303
break;
@@ -72327,11 +72500,11 @@
7232772500
p->inVtabMethod = 0;
7232872501
sqlite3VtabImportErrmsg(p, pVtab);
7232972502
if( rc==SQLITE_OK ){
7233072503
res = pModule->xEof(pVtabCursor);
7233172504
}
72332
-
72505
+ VdbeBranchTaken(res!=0,2);
7233372506
if( res ){
7233472507
pc = pOp->p2 - 1;
7233572508
}
7233672509
}
7233772510
pCur->nullRow = 0;
@@ -72432,11 +72605,11 @@
7243272605
p->inVtabMethod = 0;
7243372606
sqlite3VtabImportErrmsg(p, pVtab);
7243472607
if( rc==SQLITE_OK ){
7243572608
res = pModule->xEof(pCur->pVtabCursor);
7243672609
}
72437
-
72610
+ VdbeBranchTaken(!res,2);
7243872611
if( !res ){
7243972612
/* If there is data, jump to P2 */
7244072613
pc = pOp->p2 - 1;
7244172614
}
7244272615
goto check_for_interrupt;
@@ -72473,11 +72646,11 @@
7247372646
break;
7247472647
}
7247572648
#endif
7247672649
7247772650
#ifndef SQLITE_OMIT_VIRTUALTABLE
72478
-/* Opcode: VUpdate P1 P2 P3 P4 *
72651
+/* Opcode: VUpdate P1 P2 P3 P4 P5
7247972652
** Synopsis: data=r[P3@P2]
7248072653
**
7248172654
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7248272655
** This opcode invokes the corresponding xUpdate method. P2 values
7248372656
** are contiguous memory cells starting at P3 to pass to the xUpdate
@@ -72496,10 +72669,13 @@
7249672669
** a row to delete.
7249772670
**
7249872671
** P1 is a boolean flag. If it is set to true and the xUpdate call
7249972672
** is successful, then the value returned by sqlite3_last_insert_rowid()
7250072673
** is set to the value of the rowid for the row just inserted.
72674
+**
72675
+** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
72676
+** apply in the case of a constraint failure on an insert or update.
7250172677
*/
7250272678
case OP_VUpdate: {
7250372679
sqlite3_vtab *pVtab;
7250472680
sqlite3_module *pModule;
7250572681
int nArg;
@@ -72584,20 +72760,30 @@
7258472760
break;
7258572761
}
7258672762
#endif
7258772763
7258872764
72589
-#ifndef SQLITE_OMIT_TRACE
72590
-/* Opcode: Trace * * * P4 *
72765
+/* Opcode: Init * P2 * P4 *
72766
+** Synopsis: Start at P2
72767
+**
72768
+** Programs contain a single instance of this opcode as the very first
72769
+** opcode.
7259172770
**
7259272771
** If tracing is enabled (by the sqlite3_trace()) interface, then
7259372772
** the UTF-8 string contained in P4 is emitted on the trace callback.
72773
+** Or if P4 is blank, use the string returned by sqlite3_sql().
72774
+**
72775
+** If P2 is not zero, jump to instruction P2.
7259472776
*/
72595
-case OP_Trace: {
72777
+case OP_Init: { /* jump */
7259672778
char *zTrace;
7259772779
char *z;
7259872780
72781
+ if( pOp->p2 ){
72782
+ pc = pOp->p2 - 1;
72783
+ }
72784
+#ifndef SQLITE_OMIT_TRACE
7259972785
if( db->xTrace
7260072786
&& !p->doingRerun
7260172787
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7260272788
){
7260372789
z = sqlite3VdbeExpandSql(p, zTrace);
@@ -72619,13 +72805,13 @@
7261972805
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7262072806
){
7262172807
sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
7262272808
}
7262372809
#endif /* SQLITE_DEBUG */
72810
+#endif /* SQLITE_OMIT_TRACE */
7262472811
break;
7262572812
}
72626
-#endif
7262772813
7262872814
7262972815
/* Opcode: Noop * * * * *
7263072816
**
7263172817
** Do nothing. This instruction is often useful as a jump
@@ -72653,14 +72839,10 @@
7265372839
#ifdef VDBE_PROFILE
7265472840
{
7265572841
u64 elapsed = sqlite3Hwtime() - start;
7265672842
pOp->cycles += elapsed;
7265772843
pOp->cnt++;
72658
-#if 0
72659
- fprintf(stdout, "%10llu ", elapsed);
72660
- sqlite3VdbePrintOp(stdout, origPc, &aOp[origPc]);
72661
-#endif
7266272844
}
7266372845
#endif
7266472846
7266572847
/* The following code adds nothing to the actual functionality
7266672848
** of the program. It is only here for testing and debugging.
@@ -72882,26 +73064,24 @@
7288273064
**
7288373065
** The sqlite3_blob_close() function finalizes the vdbe program,
7288473066
** which closes the b-tree cursor and (possibly) commits the
7288573067
** transaction.
7288673068
*/
73069
+ static const int iLn = __LINE__+4;
7288773070
static const VdbeOpList openBlob[] = {
72888
- {OP_Transaction, 0, 0, 0}, /* 0: Start a transaction */
72889
- {OP_VerifyCookie, 0, 0, 0}, /* 1: Check the schema cookie */
72890
- {OP_TableLock, 0, 0, 0}, /* 2: Acquire a read or write lock */
72891
-
73071
+ /* {OP_Transaction, 0, 0, 0}, // 0: Inserted separately */
73072
+ {OP_TableLock, 0, 0, 0}, /* 1: Acquire a read or write lock */
7289273073
/* One of the following two instructions is replaced by an OP_Noop. */
72893
- {OP_OpenRead, 0, 0, 0}, /* 3: Open cursor 0 for reading */
72894
- {OP_OpenWrite, 0, 0, 0}, /* 4: Open cursor 0 for read/write */
72895
-
72896
- {OP_Variable, 1, 1, 1}, /* 5: Push the rowid to the stack */
72897
- {OP_NotExists, 0, 10, 1}, /* 6: Seek the cursor */
72898
- {OP_Column, 0, 0, 1}, /* 7 */
72899
- {OP_ResultRow, 1, 0, 0}, /* 8 */
72900
- {OP_Goto, 0, 5, 0}, /* 9 */
72901
- {OP_Close, 0, 0, 0}, /* 10 */
72902
- {OP_Halt, 0, 0, 0}, /* 11 */
73074
+ {OP_OpenRead, 0, 0, 0}, /* 2: Open cursor 0 for reading */
73075
+ {OP_OpenWrite, 0, 0, 0}, /* 3: Open cursor 0 for read/write */
73076
+ {OP_Variable, 1, 1, 1}, /* 4: Push the rowid to the stack */
73077
+ {OP_NotExists, 0, 10, 1}, /* 5: Seek the cursor */
73078
+ {OP_Column, 0, 0, 1}, /* 6 */
73079
+ {OP_ResultRow, 1, 0, 0}, /* 7 */
73080
+ {OP_Goto, 0, 4, 0}, /* 8 */
73081
+ {OP_Close, 0, 0, 0}, /* 9 */
73082
+ {OP_Halt, 0, 0, 0}, /* 10 */
7290373083
};
7290473084
7290573085
int rc = SQLITE_OK;
7290673086
char *zErr = 0;
7290773087
Table *pTab;
@@ -73010,50 +73190,45 @@
7301073190
assert( pBlob->pStmt || db->mallocFailed );
7301173191
if( pBlob->pStmt ){
7301273192
Vdbe *v = (Vdbe *)pBlob->pStmt;
7301373193
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7301473194
73015
- sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
73016
-
73017
-
73018
- /* Configure the OP_Transaction */
73019
- sqlite3VdbeChangeP1(v, 0, iDb);
73020
- sqlite3VdbeChangeP2(v, 0, flags);
73021
-
73022
- /* Configure the OP_VerifyCookie */
73023
- sqlite3VdbeChangeP1(v, 1, iDb);
73024
- sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
73025
- sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration);
73195
+
73196
+ sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags,
73197
+ pTab->pSchema->schema_cookie,
73198
+ pTab->pSchema->iGeneration);
73199
+ sqlite3VdbeChangeP5(v, 1);
73200
+ sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
7302673201
7302773202
/* Make sure a mutex is held on the table to be accessed */
7302873203
sqlite3VdbeUsesBtree(v, iDb);
7302973204
7303073205
/* Configure the OP_TableLock instruction */
7303173206
#ifdef SQLITE_OMIT_SHARED_CACHE
73032
- sqlite3VdbeChangeToNoop(v, 2);
73207
+ sqlite3VdbeChangeToNoop(v, 1);
7303373208
#else
73034
- sqlite3VdbeChangeP1(v, 2, iDb);
73035
- sqlite3VdbeChangeP2(v, 2, pTab->tnum);
73036
- sqlite3VdbeChangeP3(v, 2, flags);
73037
- sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
73209
+ sqlite3VdbeChangeP1(v, 1, iDb);
73210
+ sqlite3VdbeChangeP2(v, 1, pTab->tnum);
73211
+ sqlite3VdbeChangeP3(v, 1, flags);
73212
+ sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
7303873213
#endif
7303973214
7304073215
/* Remove either the OP_OpenWrite or OpenRead. Set the P2
7304173216
** parameter of the other to pTab->tnum. */
73042
- sqlite3VdbeChangeToNoop(v, 4 - flags);
73043
- sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
73044
- sqlite3VdbeChangeP3(v, 3 + flags, iDb);
73217
+ sqlite3VdbeChangeToNoop(v, 3 - flags);
73218
+ sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum);
73219
+ sqlite3VdbeChangeP3(v, 2 + flags, iDb);
7304573220
7304673221
/* Configure the number of columns. Configure the cursor to
7304773222
** think that the table has one more column than it really
7304873223
** does. An OP_Column to retrieve this imaginary column will
7304973224
** always return an SQL NULL. This is useful because it means
7305073225
** we can invoke OP_Column to fill in the vdbe cursors type
7305173226
** and offset cache without causing any IO.
7305273227
*/
73053
- sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73054
- sqlite3VdbeChangeP2(v, 7, pTab->nCol);
73228
+ sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73229
+ sqlite3VdbeChangeP2(v, 6, pTab->nCol);
7305573230
if( !db->mallocFailed ){
7305673231
pParse->nVar = 1;
7305773232
pParse->nMem = 1;
7305873233
pParse->nTab = 1;
7305973234
sqlite3VdbeMakeReady(v, pParse);
@@ -75317,12 +75492,12 @@
7531775492
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
7531875493
7531975494
/*
7532075495
** Perhaps the name is a reference to the ROWID
7532175496
*/
75322
- assert( pTab!=0 || cntTab==0 );
75323
- if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75497
+ if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol)
75498
+ && HasRowid(pMatch->pTab) ){
7532475499
cnt = 1;
7532575500
pExpr->iColumn = -1; /* IMP: R-44911-55124 */
7532675501
pExpr->affinity = SQLITE_AFF_INTEGER;
7532775502
}
7532875503
@@ -77449,11 +77624,10 @@
7744977624
pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
7745077625
pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
7745177626
pNew->iLimit = 0;
7745277627
pNew->iOffset = 0;
7745377628
pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
77454
- pNew->pRightmost = 0;
7745577629
pNew->addrOpenEphm[0] = -1;
7745677630
pNew->addrOpenEphm[1] = -1;
7745777631
pNew->addrOpenEphm[2] = -1;
7745877632
pNew->nSelectRow = p->nSelectRow;
7745977633
pNew->pWith = withDup(db, p->pWith);
@@ -77759,28 +77933,10 @@
7775977933
default:
7776077934
return 1;
7776177935
}
7776277936
}
7776377937
77764
-/*
77765
-** Generate an OP_IsNull instruction that tests register iReg and jumps
77766
-** to location iDest if the value in iReg is NULL. The value in iReg
77767
-** was computed by pExpr. If we can look at pExpr at compile-time and
77768
-** determine that it can never generate a NULL, then the OP_IsNull operation
77769
-** can be omitted.
77770
-*/
77771
-SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(
77772
- Vdbe *v, /* The VDBE under construction */
77773
- const Expr *pExpr, /* Only generate OP_IsNull if this expr can be NULL */
77774
- int iReg, /* Test the value in this register for NULL */
77775
- int iDest /* Jump here if the value is null */
77776
-){
77777
- if( sqlite3ExprCanBeNull(pExpr) ){
77778
- sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest);
77779
- }
77780
-}
77781
-
7778277938
/*
7778377939
** Return TRUE if the given expression is a constant which would be
7778477940
** unchanged by OP_Affinity with the affinity given in the second
7778577941
** argument.
7778677942
**
@@ -77973,11 +78129,11 @@
7797378129
assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
7797478130
pTab = p->pSrc->a[0].pTab;
7797578131
pExpr = p->pEList->a[0].pExpr;
7797678132
iCol = (i16)pExpr->iColumn;
7797778133
77978
- /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
78134
+ /* Code an OP_Transaction and OP_TableLock for <table>. */
7797978135
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7798078136
sqlite3CodeVerifySchema(pParse, iDb);
7798178137
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
7798278138
7798378139
/* This function is only called from two places. In both cases the vdbe
@@ -77984,13 +78140,12 @@
7798478140
** has already been allocated. So assume sqlite3GetVdbe() is always
7798578141
** successful here.
7798678142
*/
7798778143
assert(v);
7798878144
if( iCol<0 ){
77989
- int iAddr;
77990
-
77991
- iAddr = sqlite3CodeOnce(pParse);
78145
+ int iAddr = sqlite3CodeOnce(pParse);
78146
+ VdbeCoverage(v);
7799278147
7799378148
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
7799478149
eType = IN_INDEX_ROWID;
7799578150
7799678151
sqlite3VdbeJumpHere(v, iAddr);
@@ -78011,22 +78166,22 @@
7801178166
for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
7801278167
if( (pIdx->aiColumn[0]==iCol)
7801378168
&& sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
7801478169
&& (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
7801578170
){
78016
- int iAddr = sqlite3CodeOnce(pParse);
78171
+ int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
7801778172
sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
7801878173
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
7801978174
VdbeComment((v, "%s", pIdx->zName));
7802078175
assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
7802178176
eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
7802278177
78023
- sqlite3VdbeJumpHere(v, iAddr);
7802478178
if( prNotFound && !pTab->aCol[iCol].notNull ){
7802578179
*prNotFound = ++pParse->nMem;
7802678180
sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
7802778181
}
78182
+ sqlite3VdbeJumpHere(v, iAddr);
7802878183
}
7802978184
}
7803078185
}
7803178186
}
7803278187
@@ -78111,11 +78266,11 @@
7811178266
**
7811278267
** If all of the above are false, then we can run this code just once
7811378268
** save the results, and reuse the same result on subsequent invocations.
7811478269
*/
7811578270
if( !ExprHasProperty(pExpr, EP_VarSelect) ){
78116
- testAddr = sqlite3CodeOnce(pParse);
78271
+ testAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
7811778272
}
7811878273
7811978274
#ifndef SQLITE_OMIT_EXPLAIN
7812078275
if( pParse->explain==2 ){
7812178276
char *zMsg = sqlite3MPrintf(
@@ -78152,11 +78307,10 @@
7815278307
** 'x' nor the SELECT... statement are columns, then numeric affinity
7815378308
** is used.
7815478309
*/
7815578310
pExpr->iTable = pParse->nTab++;
7815678311
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
78157
- if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
7815878312
pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
7815978313
7816078314
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
7816178315
/* Case 1: expr IN (SELECT ...)
7816278316
**
@@ -78228,10 +78382,11 @@
7822878382
}else{
7822978383
r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
7823078384
if( isRowid ){
7823178385
sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
7823278386
sqlite3VdbeCurrentAddr(v)+2);
78387
+ VdbeCoverage(v);
7823378388
sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
7823478389
}else{
7823578390
sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
7823678391
sqlite3ExprCacheAffinityChange(pParse, r3, 1);
7823778392
sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
@@ -78351,23 +78506,25 @@
7835178506
** on whether the RHS is empty or not, respectively.
7835278507
*/
7835378508
if( destIfNull==destIfFalse ){
7835478509
/* Shortcut for the common case where the false and NULL outcomes are
7835578510
** the same. */
78356
- sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull);
78511
+ sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
7835778512
}else{
78358
- int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1);
78513
+ int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
7835978514
sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
78515
+ VdbeCoverage(v);
7836078516
sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
7836178517
sqlite3VdbeJumpHere(v, addr1);
7836278518
}
7836378519
7836478520
if( eType==IN_INDEX_ROWID ){
7836578521
/* In this case, the RHS is the ROWID of table b-tree
7836678522
*/
78367
- sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse);
78523
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); VdbeCoverage(v);
7836878524
sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
78525
+ VdbeCoverage(v);
7836978526
}else{
7837078527
/* In this case, the RHS is an index b-tree.
7837178528
*/
7837278529
sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
7837378530
@@ -78384,42 +78541,40 @@
7838478541
**
7838578542
** Also run this branch if NULL is equivalent to FALSE
7838678543
** for this particular IN operator.
7838778544
*/
7838878545
sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1);
78389
-
78546
+ VdbeCoverage(v);
7839078547
}else{
7839178548
/* In this branch, the RHS of the IN might contain a NULL and
7839278549
** the presence of a NULL on the RHS makes a difference in the
7839378550
** outcome.
7839478551
*/
78395
- int j1, j2, j3;
78552
+ int j1, j2;
7839678553
7839778554
/* First check to see if the LHS is contained in the RHS. If so,
7839878555
** then the presence of NULLs in the RHS does not matter, so jump
7839978556
** over all of the code that follows.
7840078557
*/
7840178558
j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
78559
+ VdbeCoverage(v);
7840278560
7840378561
/* Here we begin generating code that runs if the LHS is not
7840478562
** contained within the RHS. Generate additional code that
7840578563
** tests the RHS for NULLs. If the RHS contains a NULL then
7840678564
** jump to destIfNull. If there are no NULLs in the RHS then
7840778565
** jump to destIfFalse.
7840878566
*/
78409
- j2 = sqlite3VdbeAddOp1(v, OP_NotNull, rRhsHasNull);
78410
- j3 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78411
- sqlite3VdbeAddOp2(v, OP_Integer, -1, rRhsHasNull);
78412
- sqlite3VdbeJumpHere(v, j3);
78413
- sqlite3VdbeAddOp2(v, OP_AddImm, rRhsHasNull, 1);
78567
+ sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull); VdbeCoverage(v);
78568
+ sqlite3VdbeAddOp2(v, OP_IfNot, rRhsHasNull, destIfFalse); VdbeCoverage(v);
78569
+ j2 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78570
+ VdbeCoverage(v);
78571
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, rRhsHasNull);
78572
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
7841478573
sqlite3VdbeJumpHere(v, j2);
78415
-
78416
- /* Jump to the appropriate target depending on whether or not
78417
- ** the RHS contains a NULL
78418
- */
78419
- sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull);
78420
- sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
78574
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, rRhsHasNull);
78575
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
7842178576
7842278577
/* The OP_Found at the top of this branch jumps here when true,
7842378578
** causing the overall IN expression evaluation to fall through.
7842478579
*/
7842578580
sqlite3VdbeJumpHere(v, j1);
@@ -78936,26 +79091,20 @@
7893679091
case TK_LE:
7893779092
case TK_GT:
7893879093
case TK_GE:
7893979094
case TK_NE:
7894079095
case TK_EQ: {
78941
- assert( TK_LT==OP_Lt );
78942
- assert( TK_LE==OP_Le );
78943
- assert( TK_GT==OP_Gt );
78944
- assert( TK_GE==OP_Ge );
78945
- assert( TK_EQ==OP_Eq );
78946
- assert( TK_NE==OP_Ne );
78947
- testcase( op==TK_LT );
78948
- testcase( op==TK_LE );
78949
- testcase( op==TK_GT );
78950
- testcase( op==TK_GE );
78951
- testcase( op==TK_EQ );
78952
- testcase( op==TK_NE );
7895379096
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7895479097
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
7895579098
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
7895679099
r1, r2, inReg, SQLITE_STOREP2);
79100
+ assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
79101
+ assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
79102
+ assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
79103
+ assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
79104
+ assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
79105
+ assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
7895779106
testcase( regFree1==0 );
7895879107
testcase( regFree2==0 );
7895979108
break;
7896079109
}
7896179110
case TK_IS:
@@ -78965,10 +79114,12 @@
7896579114
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7896679115
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
7896779116
op = (op==TK_IS) ? TK_EQ : TK_NE;
7896879117
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
7896979118
r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
79119
+ VdbeCoverageIf(v, op==TK_EQ);
79120
+ VdbeCoverageIf(v, op==TK_NE);
7897079121
testcase( regFree1==0 );
7897179122
testcase( regFree2==0 );
7897279123
break;
7897379124
}
7897479125
case TK_AND:
@@ -78981,32 +79132,21 @@
7898179132
case TK_BITOR:
7898279133
case TK_SLASH:
7898379134
case TK_LSHIFT:
7898479135
case TK_RSHIFT:
7898579136
case TK_CONCAT: {
78986
- assert( TK_AND==OP_And );
78987
- assert( TK_OR==OP_Or );
78988
- assert( TK_PLUS==OP_Add );
78989
- assert( TK_MINUS==OP_Subtract );
78990
- assert( TK_REM==OP_Remainder );
78991
- assert( TK_BITAND==OP_BitAnd );
78992
- assert( TK_BITOR==OP_BitOr );
78993
- assert( TK_SLASH==OP_Divide );
78994
- assert( TK_LSHIFT==OP_ShiftLeft );
78995
- assert( TK_RSHIFT==OP_ShiftRight );
78996
- assert( TK_CONCAT==OP_Concat );
78997
- testcase( op==TK_AND );
78998
- testcase( op==TK_OR );
78999
- testcase( op==TK_PLUS );
79000
- testcase( op==TK_MINUS );
79001
- testcase( op==TK_REM );
79002
- testcase( op==TK_BITAND );
79003
- testcase( op==TK_BITOR );
79004
- testcase( op==TK_SLASH );
79005
- testcase( op==TK_LSHIFT );
79006
- testcase( op==TK_RSHIFT );
79007
- testcase( op==TK_CONCAT );
79137
+ assert( TK_AND==OP_And ); testcase( op==TK_AND );
79138
+ assert( TK_OR==OP_Or ); testcase( op==TK_OR );
79139
+ assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
79140
+ assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
79141
+ assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
79142
+ assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
79143
+ assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
79144
+ assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
79145
+ assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
79146
+ assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
79147
+ assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
7900879148
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7900979149
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
7901079150
sqlite3VdbeAddOp3(v, op, r2, r1, target);
7901179151
testcase( regFree1==0 );
7901279152
testcase( regFree2==0 );
@@ -79034,31 +79174,29 @@
7903479174
inReg = target;
7903579175
break;
7903679176
}
7903779177
case TK_BITNOT:
7903879178
case TK_NOT: {
79039
- assert( TK_BITNOT==OP_BitNot );
79040
- assert( TK_NOT==OP_Not );
79041
- testcase( op==TK_BITNOT );
79042
- testcase( op==TK_NOT );
79179
+ assert( TK_BITNOT==OP_BitNot ); testcase( op==TK_BITNOT );
79180
+ assert( TK_NOT==OP_Not ); testcase( op==TK_NOT );
7904379181
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7904479182
testcase( regFree1==0 );
7904579183
inReg = target;
7904679184
sqlite3VdbeAddOp2(v, op, r1, inReg);
7904779185
break;
7904879186
}
7904979187
case TK_ISNULL:
7905079188
case TK_NOTNULL: {
7905179189
int addr;
79052
- assert( TK_ISNULL==OP_IsNull );
79053
- assert( TK_NOTNULL==OP_NotNull );
79054
- testcase( op==TK_ISNULL );
79055
- testcase( op==TK_NOTNULL );
79190
+ assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
79191
+ assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
7905679192
sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
7905779193
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7905879194
testcase( regFree1==0 );
7905979195
addr = sqlite3VdbeAddOp1(v, op, r1);
79196
+ VdbeCoverageIf(v, op==TK_ISNULL);
79197
+ VdbeCoverageIf(v, op==TK_NOTNULL);
7906079198
sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
7906179199
sqlite3VdbeJumpHere(v, addr);
7906279200
break;
7906379201
}
7906479202
case TK_AGG_FUNCTION: {
@@ -79106,10 +79244,11 @@
7910679244
int endCoalesce = sqlite3VdbeMakeLabel(v);
7910779245
assert( nFarg>=2 );
7910879246
sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
7910979247
for(i=1; i<nFarg; i++){
7911079248
sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
79249
+ VdbeCoverage(v);
7911179250
sqlite3ExprCacheRemove(pParse, target, 1);
7911279251
sqlite3ExprCachePush(pParse);
7911379252
sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
7911479253
sqlite3ExprCachePop(pParse, 1);
7911579254
}
@@ -79243,17 +79382,18 @@
7924379382
testcase( regFree1==0 );
7924479383
testcase( regFree2==0 );
7924579384
r3 = sqlite3GetTempReg(pParse);
7924679385
r4 = sqlite3GetTempReg(pParse);
7924779386
codeCompare(pParse, pLeft, pRight, OP_Ge,
79248
- r1, r2, r3, SQLITE_STOREP2);
79387
+ r1, r2, r3, SQLITE_STOREP2); VdbeCoverage(v);
7924979388
pLItem++;
7925079389
pRight = pLItem->pExpr;
7925179390
sqlite3ReleaseTempReg(pParse, regFree2);
7925279391
r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
7925379392
testcase( regFree2==0 );
7925479393
codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
79394
+ VdbeCoverage(v);
7925579395
sqlite3VdbeAddOp3(v, OP_And, r3, r4, target);
7925679396
sqlite3ReleaseTempReg(pParse, r3);
7925779397
sqlite3ReleaseTempReg(pParse, r4);
7925879398
break;
7925979399
}
@@ -79416,10 +79556,11 @@
7941679556
}
7941779557
assert( !ExprHasProperty(pExpr, EP_IntValue) );
7941879558
if( pExpr->affinity==OE_Ignore ){
7941979559
sqlite3VdbeAddOp4(
7942079560
v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
79561
+ VdbeCoverage(v);
7942179562
}else{
7942279563
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
7942379564
pExpr->affinity, pExpr->u.zToken, 0, 0);
7942479565
}
7942579566
@@ -79503,11 +79644,11 @@
7950379644
/*
7950479645
** Generate code that will evaluate expression pExpr and store the
7950579646
** results in register target. The results are guaranteed to appear
7950679647
** in register target.
7950779648
*/
79508
-SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
79649
+SQLITE_PRIVATE void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
7950979650
int inReg;
7951079651
7951179652
assert( target>0 && target<=pParse->nMem );
7951279653
if( pExpr && pExpr->op==TK_REGISTER ){
7951379654
sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
@@ -79516,11 +79657,24 @@
7951679657
assert( pParse->pVdbe || pParse->db->mallocFailed );
7951779658
if( inReg!=target && pParse->pVdbe ){
7951879659
sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
7951979660
}
7952079661
}
79521
- return target;
79662
+}
79663
+
79664
+/*
79665
+** Generate code that will evaluate expression pExpr and store the
79666
+** results in register target. The results are guaranteed to appear
79667
+** in register target. If the expression is constant, then this routine
79668
+** might choose to code the expression at initialization time.
79669
+*/
79670
+SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
79671
+ if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
79672
+ sqlite3ExprCodeAtInit(pParse, pExpr, target, 0);
79673
+ }else{
79674
+ sqlite3ExprCode(pParse, pExpr, target);
79675
+ }
7952279676
}
7952379677
7952479678
/*
7952579679
** Generate code that evalutes the given expression and puts the result
7952679680
** in register target.
@@ -79531,29 +79685,20 @@
7953179685
**
7953279686
** This routine is used for expressions that are used multiple
7953379687
** times. They are evaluated once and the results of the expression
7953479688
** are reused.
7953579689
*/
79536
-SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79690
+SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
7953779691
Vdbe *v = pParse->pVdbe;
79538
- int inReg;
79539
- inReg = sqlite3ExprCode(pParse, pExpr, target);
79692
+ int iMem;
79693
+
7954079694
assert( target>0 );
79541
- /* The only place, other than this routine, where expressions can be
79542
- ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79543
- ** CASE operators. Neither ever calls this routine. And this routine
79544
- ** is never called twice on the same expression. Hence it is impossible
79545
- ** for the input to this routine to already be a register. Nevertheless,
79546
- ** it seems prudent to keep the ALWAYS() in case the conditions above
79547
- ** change with future modifications or enhancements. */
79548
- if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79549
- int iMem;
79550
- iMem = ++pParse->nMem;
79551
- sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79552
- exprToRegister(pExpr, iMem);
79553
- }
79554
- return inReg;
79695
+ assert( pExpr->op!=TK_REGISTER );
79696
+ sqlite3ExprCode(pParse, pExpr, target);
79697
+ iMem = ++pParse->nMem;
79698
+ sqlite3VdbeAddOp2(v, OP_Copy, target, iMem);
79699
+ exprToRegister(pExpr, iMem);
7955579700
}
7955679701
7955779702
#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
7955879703
/*
7955979704
** Generate a human-readable explanation of an expression tree.
@@ -79984,27 +80129,21 @@
7998480129
case TK_LE:
7998580130
case TK_GT:
7998680131
case TK_GE:
7998780132
case TK_NE:
7998880133
case TK_EQ: {
79989
- assert( TK_LT==OP_Lt );
79990
- assert( TK_LE==OP_Le );
79991
- assert( TK_GT==OP_Gt );
79992
- assert( TK_GE==OP_Ge );
79993
- assert( TK_EQ==OP_Eq );
79994
- assert( TK_NE==OP_Ne );
79995
- testcase( op==TK_LT );
79996
- testcase( op==TK_LE );
79997
- testcase( op==TK_GT );
79998
- testcase( op==TK_GE );
79999
- testcase( op==TK_EQ );
80000
- testcase( op==TK_NE );
8000180134
testcase( jumpIfNull==0 );
8000280135
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8000380136
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
8000480137
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
8000580138
r1, r2, dest, jumpIfNull);
80139
+ assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80140
+ assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80141
+ assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80142
+ assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80143
+ assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80144
+ assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
8000680145
testcase( regFree1==0 );
8000780146
testcase( regFree2==0 );
8000880147
break;
8000980148
}
8001080149
case TK_IS:
@@ -80014,22 +80153,24 @@
8001480153
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8001580154
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
8001680155
op = (op==TK_IS) ? TK_EQ : TK_NE;
8001780156
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
8001880157
r1, r2, dest, SQLITE_NULLEQ);
80158
+ VdbeCoverageIf(v, op==TK_EQ);
80159
+ VdbeCoverageIf(v, op==TK_NE);
8001980160
testcase( regFree1==0 );
8002080161
testcase( regFree2==0 );
8002180162
break;
8002280163
}
8002380164
case TK_ISNULL:
8002480165
case TK_NOTNULL: {
80025
- assert( TK_ISNULL==OP_IsNull );
80026
- assert( TK_NOTNULL==OP_NotNull );
80027
- testcase( op==TK_ISNULL );
80028
- testcase( op==TK_NOTNULL );
80166
+ assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
80167
+ assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
8002980168
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8003080169
sqlite3VdbeAddOp2(v, op, r1, dest);
80170
+ VdbeCoverageIf(v, op==TK_ISNULL);
80171
+ VdbeCoverageIf(v, op==TK_NOTNULL);
8003180172
testcase( regFree1==0 );
8003280173
break;
8003380174
}
8003480175
case TK_BETWEEN: {
8003580176
testcase( jumpIfNull==0 );
@@ -80052,10 +80193,11 @@
8005280193
}else if( exprAlwaysFalse(pExpr) ){
8005380194
/* No-op */
8005480195
}else{
8005580196
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
8005680197
sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
80198
+ VdbeCoverage(v);
8005780199
testcase( regFree1==0 );
8005880200
testcase( jumpIfNull==0 );
8005980201
}
8006080202
break;
8006180203
}
@@ -80143,21 +80285,21 @@
8014380285
case TK_LE:
8014480286
case TK_GT:
8014580287
case TK_GE:
8014680288
case TK_NE:
8014780289
case TK_EQ: {
80148
- testcase( op==TK_LT );
80149
- testcase( op==TK_LE );
80150
- testcase( op==TK_GT );
80151
- testcase( op==TK_GE );
80152
- testcase( op==TK_EQ );
80153
- testcase( op==TK_NE );
8015480290
testcase( jumpIfNull==0 );
8015580291
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8015680292
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
8015780293
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
8015880294
r1, r2, dest, jumpIfNull);
80295
+ assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80296
+ assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80297
+ assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80298
+ assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80299
+ assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80300
+ assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
8015980301
testcase( regFree1==0 );
8016080302
testcase( regFree2==0 );
8016180303
break;
8016280304
}
8016380305
case TK_IS:
@@ -80167,20 +80309,22 @@
8016780309
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8016880310
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
8016980311
op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
8017080312
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
8017180313
r1, r2, dest, SQLITE_NULLEQ);
80314
+ VdbeCoverageIf(v, op==TK_EQ);
80315
+ VdbeCoverageIf(v, op==TK_NE);
8017280316
testcase( regFree1==0 );
8017380317
testcase( regFree2==0 );
8017480318
break;
8017580319
}
8017680320
case TK_ISNULL:
8017780321
case TK_NOTNULL: {
80178
- testcase( op==TK_ISNULL );
80179
- testcase( op==TK_NOTNULL );
8018080322
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8018180323
sqlite3VdbeAddOp2(v, op, r1, dest);
80324
+ testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
80325
+ testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
8018280326
testcase( regFree1==0 );
8018380327
break;
8018480328
}
8018580329
case TK_BETWEEN: {
8018680330
testcase( jumpIfNull==0 );
@@ -80205,10 +80349,11 @@
8020580349
}else if( exprAlwaysTrue(pExpr) ){
8020680350
/* no-op */
8020780351
}else{
8020880352
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
8020980353
sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80354
+ VdbeCoverage(v);
8021080355
testcase( regFree1==0 );
8021180356
testcase( jumpIfNull==0 );
8021280357
}
8021380358
break;
8021480359
}
@@ -80751,12 +80896,12 @@
8075180896
len = sqlite3GetToken(zCsr, &token);
8075280897
} while( token==TK_SPACE );
8075380898
assert( len>0 );
8075480899
} while( token!=TK_LP && token!=TK_USING );
8075580900
80756
- zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80757
- zTableName, tname.z+tname.n);
80901
+ zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
80902
+ zSql, zTableName, tname.z+tname.n);
8075880903
sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
8075980904
}
8076080905
}
8076180906
8076280907
/*
@@ -80804,11 +80949,11 @@
8080480949
zParent = sqlite3DbStrNDup(db, (const char *)z, n);
8080580950
if( zParent==0 ) break;
8080680951
sqlite3Dequote(zParent);
8080780952
if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
8080880953
char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
80809
- (zOutput?zOutput:""), z-zInput, zInput, (const char *)zNew
80954
+ (zOutput?zOutput:""), (int)(z-zInput), zInput, (const char *)zNew
8081080955
);
8081180956
sqlite3DbFree(db, zOutput);
8081280957
zOutput = zOut;
8081380958
zInput = &z[n];
8081480959
}
@@ -80890,12 +81035,12 @@
8089081035
} while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
8089181036
8089281037
/* Variable tname now contains the token that is the old table-name
8089381038
** in the CREATE TRIGGER statement.
8089481039
*/
80895
- zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80896
- zTableName, tname.z+tname.n);
81040
+ zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
81041
+ zSql, zTableName, tname.z+tname.n);
8089781042
sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
8089881043
}
8089981044
}
8090081045
#endif /* !SQLITE_OMIT_TRIGGER */
8090181046
@@ -81143,11 +81288,11 @@
8114381288
pVTab = 0;
8114481289
}
8114581290
}
8114681291
#endif
8114781292
81148
- /* Begin a transaction and code the VerifyCookie for database iDb.
81293
+ /* Begin a transaction for database iDb.
8114981294
** Then modify the schema cookie (since the ALTER TABLE modifies the
8115081295
** schema). Open a statement transaction if the table is a virtual
8115181296
** table.
8115281297
*/
8115381298
v = sqlite3GetVdbe(pParse);
@@ -81279,10 +81424,11 @@
8127981424
int j1;
8128081425
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
8128181426
sqlite3VdbeUsesBtree(v, iDb);
8128281427
sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
8128381428
j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
81429
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
8128481430
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
8128581431
sqlite3VdbeJumpHere(v, j1);
8128681432
sqlite3ReleaseTempReg(pParse, r1);
8128781433
sqlite3ReleaseTempReg(pParse, r2);
8128881434
}
@@ -82579,10 +82725,11 @@
8257982725
** regChng = 0
8258082726
** goto next_push_0;
8258182727
**
8258282728
*/
8258382729
addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
82730
+ VdbeCoverage(v);
8258482731
sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
8258582732
addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
8258682733
8258782734
/*
8258882735
** next_row:
@@ -82600,10 +82747,11 @@
8260082747
sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
8260182748
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
8260282749
aGotoChng[i] =
8260382750
sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
8260482751
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
82752
+ VdbeCoverage(v);
8260582753
}
8260682754
sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
8260782755
aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
8260882756
8260982757
/*
@@ -82646,11 +82794,11 @@
8264682794
#endif
8264782795
assert( regChng==(regStat4+1) );
8264882796
sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
8264982797
sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
8265082798
sqlite3VdbeChangeP5(v, 2+IsStat34);
82651
- sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow);
82799
+ sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
8265282800
8265382801
/* Add the entry to the stat1 table. */
8265482802
callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
8265582803
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
8265682804
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
@@ -82673,14 +82821,16 @@
8267382821
pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
8267482822
8267582823
addrNext = sqlite3VdbeCurrentAddr(v);
8267682824
callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
8267782825
addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
82826
+ VdbeCoverage(v);
8267882827
callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
8267982828
callStatGet(v, regStat4, STAT_GET_NLT, regLt);
8268082829
callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
8268182830
sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
82831
+ VdbeCoverage(v);
8268282832
#ifdef SQLITE_ENABLE_STAT3
8268382833
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
8268482834
pIdx->aiColumn[0], regSample);
8268582835
#else
8268682836
for(i=0; i<nCol; i++){
@@ -82687,11 +82837,11 @@
8268782837
i16 iCol = pIdx->aiColumn[i];
8268882838
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
8268982839
}
8269082840
sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
8269182841
#endif
82692
- sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0);
82842
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
8269382843
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
8269482844
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
8269582845
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
8269682846
sqlite3VdbeJumpHere(v, addrIsNull);
8269782847
}
@@ -82707,11 +82857,11 @@
8270782857
** name and the row count as the content.
8270882858
*/
8270982859
if( pOnlyIdx==0 && needTableCnt ){
8271082860
VdbeComment((v, "%s", pTab->zName));
8271182861
sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
82712
- jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
82862
+ jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
8271382863
sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
8271482864
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
8271582865
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
8271682866
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
8271782867
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -84245,24 +84395,26 @@
8424584395
** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
8424684396
** set for each database that is used. Generate code to start a
8424784397
** transaction on each used database and to verify the schema cookie
8424884398
** on each used database.
8424984399
*/
84250
- if( pParse->cookieGoto>0 ){
84400
+ if( db->mallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){
8425184401
yDbMask mask;
84252
- int iDb, i, addr;
84253
- sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
84402
+ int iDb, i;
84403
+ assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
84404
+ sqlite3VdbeJumpHere(v, 0);
8425484405
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
8425584406
if( (mask & pParse->cookieMask)==0 ) continue;
8425684407
sqlite3VdbeUsesBtree(v, iDb);
84257
- sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
84258
- if( db->init.busy==0 ){
84259
- assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84260
- sqlite3VdbeAddOp3(v, OP_VerifyCookie,
84261
- iDb, pParse->cookieValue[iDb],
84262
- db->aDb[iDb].pSchema->iGeneration);
84263
- }
84408
+ sqlite3VdbeAddOp4Int(v,
84409
+ OP_Transaction, /* Opcode */
84410
+ iDb, /* P1 */
84411
+ (mask & pParse->writeMask)!=0, /* P2 */
84412
+ pParse->cookieValue[iDb], /* P3 */
84413
+ db->aDb[iDb].pSchema->iGeneration /* P4 */
84414
+ );
84415
+ if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
8426484416
}
8426584417
#ifndef SQLITE_OMIT_VIRTUALTABLE
8426684418
for(i=0; i<pParse->nVtabLock; i++){
8426784419
char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
8426884420
sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
@@ -84279,21 +84431,20 @@
8427984431
/* Initialize any AUTOINCREMENT data structures required.
8428084432
*/
8428184433
sqlite3AutoincrementBegin(pParse);
8428284434
8428384435
/* Code constant expressions that where factored out of inner loops */
84284
- addr = pParse->cookieGoto;
8428584436
if( pParse->pConstExpr ){
8428684437
ExprList *pEL = pParse->pConstExpr;
84287
- pParse->cookieGoto = 0;
84438
+ pParse->okConstFactor = 0;
8428884439
for(i=0; i<pEL->nExpr; i++){
8428984440
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
8429084441
}
8429184442
}
8429284443
8429384444
/* Finally, jump back to the beginning of the executable code. */
84294
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
84445
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
8429584446
}
8429684447
}
8429784448
8429884449
8429984450
/* Get the VDBE program ready for execution
@@ -84312,11 +84463,10 @@
8431284463
pParse->nTab = 0;
8431384464
pParse->nMem = 0;
8431484465
pParse->nSet = 0;
8431584466
pParse->nVar = 0;
8431684467
pParse->cookieMask = 0;
84317
- pParse->cookieGoto = 0;
8431884468
}
8431984469
8432084470
/*
8432184471
** Run the parser and code generator recursively in order to generate
8432284472
** code for the SQL statement given onto the end of the pParse context
@@ -85044,11 +85194,11 @@
8504485194
reg1 = pParse->regRowid = ++pParse->nMem;
8504585195
reg2 = pParse->regRoot = ++pParse->nMem;
8504685196
reg3 = ++pParse->nMem;
8504785197
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
8504885198
sqlite3VdbeUsesBtree(v, iDb);
85049
- j1 = sqlite3VdbeAddOp1(v, OP_If, reg3);
85199
+ j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
8505085200
fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
8505185201
1 : SQLITE_MAX_FILE_FORMAT;
8505285202
sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
8505385203
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
8505485204
sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
@@ -86771,40 +86921,40 @@
8677186921
sqlite3KeyInfoRef(pKey), P4_KEYINFO);
8677286922
8677386923
/* Open the table. Loop through all rows of the table, inserting index
8677486924
** records into the sorter. */
8677586925
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86776
- addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
86926
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
8677786927
regRecord = sqlite3GetTempReg(pParse);
8677886928
8677986929
sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
8678086930
sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
8678186931
sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86782
- sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
86932
+ sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
8678386933
sqlite3VdbeJumpHere(v, addr1);
8678486934
if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
8678586935
sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
8678686936
(char *)pKey, P4_KEYINFO);
8678786937
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
8678886938
86789
- addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
86939
+ addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
8679086940
assert( pKey!=0 || db->mallocFailed || pParse->nErr );
8679186941
if( pIndex->onError!=OE_None && pKey!=0 ){
8679286942
int j2 = sqlite3VdbeCurrentAddr(v) + 3;
8679386943
sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
8679486944
addr2 = sqlite3VdbeCurrentAddr(v);
8679586945
sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86796
- pKey->nField - pIndex->nKeyCol);
86946
+ pKey->nField - pIndex->nKeyCol); VdbeCoverage(v);
8679786947
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
8679886948
}else{
8679986949
addr2 = sqlite3VdbeCurrentAddr(v);
8680086950
}
8680186951
sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
8680286952
sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
8680386953
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
8680486954
sqlite3ReleaseTempReg(pParse, regRecord);
86805
- sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
86955
+ sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
8680686956
sqlite3VdbeJumpHere(v, addr1);
8680786957
8680886958
sqlite3VdbeAddOp1(v, OP_Close, iTab);
8680986959
sqlite3VdbeAddOp1(v, OP_Close, iIdx);
8681086960
sqlite3VdbeAddOp1(v, OP_Close, iSorter);
@@ -87921,63 +88071,30 @@
8792188071
}
8792288072
return 0;
8792388073
}
8792488074
8792588075
/*
87926
-** Generate VDBE code that will verify the schema cookie and start
87927
-** a read-transaction for all named database files.
87928
-**
87929
-** It is important that all schema cookies be verified and all
87930
-** read transactions be started before anything else happens in
87931
-** the VDBE program. But this routine can be called after much other
87932
-** code has been generated. So here is what we do:
87933
-**
87934
-** The first time this routine is called, we code an OP_Goto that
87935
-** will jump to a subroutine at the end of the program. Then we
87936
-** record every database that needs its schema verified in the
87937
-** pParse->cookieMask field. Later, after all other code has been
87938
-** generated, the subroutine that does the cookie verifications and
87939
-** starts the transactions will be coded and the OP_Goto P2 value
87940
-** will be made to point to that subroutine. The generation of the
87941
-** cookie verification subroutine code happens in sqlite3FinishCoding().
87942
-**
87943
-** If iDb<0 then code the OP_Goto only - don't set flag to verify the
87944
-** schema on any databases. This can be used to position the OP_Goto
87945
-** early in the code, before we know if any database tables will be used.
88076
+** Record the fact that the schema cookie will need to be verified
88077
+** for database iDb. The code to actually verify the schema cookie
88078
+** will occur at the end of the top-level VDBE and will be generated
88079
+** later, by sqlite3FinishCoding().
8794688080
*/
8794788081
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
8794888082
Parse *pToplevel = sqlite3ParseToplevel(pParse);
87949
-
87950
-#ifndef SQLITE_OMIT_TRIGGER
87951
- if( pToplevel!=pParse ){
87952
- /* This branch is taken if a trigger is currently being coded. In this
87953
- ** case, set cookieGoto to a non-zero value to show that this function
87954
- ** has been called. This is used by the sqlite3ExprCodeConstants()
87955
- ** function. */
87956
- pParse->cookieGoto = -1;
87957
- }
87958
-#endif
87959
- if( pToplevel->cookieGoto==0 ){
87960
- Vdbe *v = sqlite3GetVdbe(pToplevel);
87961
- if( v==0 ) return; /* This only happens if there was a prior error */
87962
- pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
87963
- }
87964
- if( iDb>=0 ){
87965
- sqlite3 *db = pToplevel->db;
87966
- yDbMask mask;
87967
-
87968
- assert( iDb<db->nDb );
87969
- assert( db->aDb[iDb].pBt!=0 || iDb==1 );
87970
- assert( iDb<SQLITE_MAX_ATTACHED+2 );
87971
- assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87972
- mask = ((yDbMask)1)<<iDb;
87973
- if( (pToplevel->cookieMask & mask)==0 ){
87974
- pToplevel->cookieMask |= mask;
87975
- pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
87976
- if( !OMIT_TEMPDB && iDb==1 ){
87977
- sqlite3OpenTempDatabase(pToplevel);
87978
- }
88083
+ sqlite3 *db = pToplevel->db;
88084
+ yDbMask mask;
88085
+
88086
+ assert( iDb>=0 && iDb<db->nDb );
88087
+ assert( db->aDb[iDb].pBt!=0 || iDb==1 );
88088
+ assert( iDb<SQLITE_MAX_ATTACHED+2 );
88089
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88090
+ mask = ((yDbMask)1)<<iDb;
88091
+ if( (pToplevel->cookieMask & mask)==0 ){
88092
+ pToplevel->cookieMask |= mask;
88093
+ pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
88094
+ if( !OMIT_TEMPDB && iDb==1 ){
88095
+ sqlite3OpenTempDatabase(pToplevel);
8797988096
}
8798088097
}
8798188098
}
8798288099
8798388100
/*
@@ -88944,25 +89061,20 @@
8894489061
SelectDest dest;
8894589062
Select *pSel;
8894689063
SrcList *pFrom;
8894789064
sqlite3 *db = pParse->db;
8894889065
int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
88949
-
8895089066
pWhere = sqlite3ExprDup(db, pWhere, 0);
8895189067
pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
88952
-
8895389068
if( pFrom ){
8895489069
assert( pFrom->nSrc==1 );
8895589070
pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
8895689071
pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
8895789072
assert( pFrom->a[0].pOn==0 );
8895889073
assert( pFrom->a[0].pUsing==0 );
8895989074
}
88960
-
8896189075
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
88962
- if( pSel ) pSel->selFlags |= SF_Materialize;
88963
-
8896489076
sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
8896589077
sqlite3Select(pParse, pSel, &dest);
8896689078
sqlite3SelectDelete(db, pSel);
8896789079
}
8896889080
#endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -89295,11 +89407,11 @@
8929589407
}else if( pPk ){
8929689408
/* Construct a composite key for the row to be deleted and remember it */
8929789409
iKey = ++pParse->nMem;
8929889410
nKey = 0; /* Zero tells OP_Found to use a composite key */
8929989411
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89300
- sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89412
+ sqlite3IndexAffinityStr(v, pPk), nPk);
8930189413
sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
8930289414
}else{
8930389415
/* Get the rowid of the row to be deleted and remember it in the RowSet */
8930489416
nKey = 1; /* OP_Seek always uses a single rowid */
8930589417
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -89333,17 +89445,19 @@
8933389445
/* Just one row. Hence the top-of-loop is a no-op */
8933489446
assert( nKey==nPk ); /* OP_Found will use an unpacked key */
8933589447
if( aToOpen[iDataCur-iTabCur] ){
8933689448
assert( pPk!=0 );
8933789449
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
89450
+ VdbeCoverage(v);
8933889451
}
8933989452
}else if( pPk ){
89340
- addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
89453
+ addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
8934189454
sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
8934289455
assert( nKey==0 ); /* OP_Found will use a composite key */
8934389456
}else{
8934489457
addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
89458
+ VdbeCoverage(v);
8934589459
assert( nKey==1 );
8934689460
}
8934789461
8934889462
/* Delete the row */
8934989463
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -89363,11 +89477,11 @@
8936389477
8936489478
/* End of the loop over all rowids/primary-keys. */
8936589479
if( okOnePass ){
8936689480
sqlite3VdbeResolveLabel(v, addrBypass);
8936789481
}else if( pPk ){
89368
- sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
89482
+ sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
8936989483
sqlite3VdbeJumpHere(v, addrLoop);
8937089484
}else{
8937189485
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
8937289486
sqlite3VdbeJumpHere(v, addrLoop);
8937389487
}
@@ -89461,11 +89575,15 @@
8946189575
/* Seek cursor iCur to the row to delete. If this row no longer exists
8946289576
** (this can happen if a trigger program has already deleted it), do
8946389577
** not attempt to delete it or fire any DELETE triggers. */
8946489578
iLabel = sqlite3VdbeMakeLabel(v);
8946589579
opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89466
- if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89580
+ if( !bNoSeek ){
89581
+ sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89582
+ VdbeCoverageIf(v, opSeek==OP_NotExists);
89583
+ VdbeCoverageIf(v, opSeek==OP_NotFound);
89584
+ }
8946789585
8946889586
/* If there are any triggers to fire, allocate a range of registers to
8946989587
** use for the old.* references in the triggers. */
8947089588
if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
8947189589
u32 mask; /* Mask of OLD.* columns in use */
@@ -89503,10 +89621,12 @@
8950389621
** the cursor or of already deleted the row that the cursor was
8950489622
** pointing to.
8950589623
*/
8950689624
if( addrStart<sqlite3VdbeCurrentAddr(v) ){
8950789625
sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89626
+ VdbeCoverageIf(v, opSeek==OP_NotExists);
89627
+ VdbeCoverageIf(v, opSeek==OP_NotFound);
8950889628
}
8950989629
8951089630
/* Do FK processing. This call checks that any FK constraints that
8951189631
** refer to this table (i.e. constraints attached to other tables)
8951289632
** are not violated by deleting this row. */
@@ -91760,14 +91880,15 @@
9176091880
** Check if any of the key columns in the child table row are NULL. If
9176191881
** any are, then the constraint is considered satisfied. No need to
9176291882
** search for a matching row in the parent table. */
9176391883
if( nIncr<0 ){
9176491884
sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
91885
+ VdbeCoverage(v);
9176591886
}
9176691887
for(i=0; i<pFKey->nCol; i++){
9176791888
int iReg = aiCol[i] + regData + 1;
91768
- sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk);
91889
+ sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v);
9176991890
}
9177091891
9177191892
if( isIgnore==0 ){
9177291893
if( pIdx==0 ){
9177391894
/* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
@@ -91780,21 +91901,23 @@
9178091901
** is no matching parent key. Before using MustBeInt, make a copy of
9178191902
** the value. Otherwise, the value inserted into the child key column
9178291903
** will have INTEGER affinity applied to it, which may not be correct. */
9178391904
sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
9178491905
iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
91906
+ VdbeCoverage(v);
9178591907
9178691908
/* If the parent table is the same as the child table, and we are about
9178791909
** to increment the constraint-counter (i.e. this is an INSERT operation),
9178891910
** then check if the row being inserted matches itself. If so, do not
9178991911
** increment the constraint-counter. */
9179091912
if( pTab==pFKey->pFrom && nIncr==1 ){
91791
- sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp);
91913
+ sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
91914
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
9179291915
}
9179391916
9179491917
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
91795
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp);
91918
+ sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
9179691919
sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
9179791920
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
9179891921
sqlite3VdbeJumpHere(v, iMustBeInt);
9179991922
sqlite3ReleaseTempReg(pParse, regTemp);
9180091923
}else{
@@ -91826,19 +91949,19 @@
9182691949
assert( aiCol[i]!=pTab->iPKey );
9182791950
if( pIdx->aiColumn[i]==pTab->iPKey ){
9182891951
/* The parent key is a composite key that includes the IPK column */
9182991952
iParent = regData;
9183091953
}
91831
- sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent);
91954
+ sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
9183291955
sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
9183391956
}
9183491957
sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
9183591958
}
9183691959
91837
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec);
91838
- sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
91839
- sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
91960
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
91961
+ sqlite3IndexAffinityStr(v,pIdx), nCol);
91962
+ sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
9184091963
9184191964
sqlite3ReleaseTempReg(pParse, regRec);
9184291965
sqlite3ReleaseTempRange(pParse, regTemp, nCol);
9184391966
}
9184491967
}
@@ -91972,10 +92095,11 @@
9197292095
assert( pIdx!=0 || pFKey->nCol==1 );
9197392096
assert( pIdx!=0 || HasRowid(pTab) );
9197492097
9197592098
if( nIncr<0 ){
9197692099
iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
92100
+ VdbeCoverage(v);
9197792101
}
9197892102
9197992103
/* Create an Expr object representing an SQL expression like:
9198092104
**
9198192105
** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
@@ -92134,11 +92258,11 @@
9213492258
for(p=pTab->pFKey; p; p=p->pNextFrom){
9213592259
if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
9213692260
}
9213792261
if( !p ) return;
9213892262
iSkip = sqlite3VdbeMakeLabel(v);
92139
- sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip);
92263
+ sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
9214092264
}
9214192265
9214292266
pParse->disableTriggers = 1;
9214392267
sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
9214492268
pParse->disableTriggers = 0;
@@ -92152,10 +92276,11 @@
9215292276
** the statement transaction will not be rolled back even if FK
9215392277
** constraints are violated.
9215492278
*/
9215592279
if( (db->flags & SQLITE_DeferFKs)==0 ){
9215692280
sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
92281
+ VdbeCoverage(v);
9215792282
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
9215892283
OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
9215992284
}
9216092285
9216192286
if( iSkip ){
@@ -92311,11 +92436,11 @@
9231192436
*/
9231292437
Vdbe *v = sqlite3GetVdbe(pParse);
9231392438
int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
9231492439
for(i=0; i<pFKey->nCol; i++){
9231592440
int iReg = pFKey->aCol[i].iFrom + regOld + 1;
92316
- sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump);
92441
+ sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); VdbeCoverage(v);
9231792442
}
9231892443
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
9231992444
}
9232092445
continue;
9232192446
}
@@ -92878,69 +93003,74 @@
9287893003
9287993004
return pIdx->zColAff;
9288093005
}
9288193006
9288293007
/*
92883
-** Set P4 of the most recently inserted opcode to a column affinity
92884
-** string for table pTab. A column affinity string has one character
92885
-** for each column indexed by the index, according to the affinity of the
92886
-** column:
93008
+** Compute the affinity string for table pTab, if it has not already been
93009
+** computed. As an optimization, omit trailing SQLITE_AFF_NONE affinities.
93010
+**
93011
+** If the affinity exists (if it is no entirely SQLITE_AFF_NONE values and
93012
+** if iReg>0 then code an OP_Affinity opcode that will set the affinities
93013
+** for register iReg and following. Or if affinities exists and iReg==0,
93014
+** then just set the P4 operand of the previous opcode (which should be
93015
+** an OP_MakeRecord) to the affinity string.
93016
+**
93017
+** A column affinity string has one character column:
9288793018
**
9288893019
** Character Column affinity
9288993020
** ------------------------------
9289093021
** 'a' TEXT
9289193022
** 'b' NONE
9289293023
** 'c' NUMERIC
9289393024
** 'd' INTEGER
9289493025
** 'e' REAL
9289593026
*/
92896
-SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
92897
- /* The first time a column affinity string for a particular table
92898
- ** is required, it is allocated and populated here. It is then
92899
- ** stored as a member of the Table structure for subsequent use.
92900
- **
92901
- ** The column affinity string will eventually be deleted by
92902
- ** sqlite3DeleteTable() when the Table structure itself is cleaned up.
92903
- */
92904
- if( !pTab->zColAff ){
92905
- char *zColAff;
92906
- int i;
93027
+SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
93028
+ int i;
93029
+ char *zColAff = pTab->zColAff;
93030
+ if( zColAff==0 ){
9290793031
sqlite3 *db = sqlite3VdbeDb(v);
92908
-
9290993032
zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
9291093033
if( !zColAff ){
9291193034
db->mallocFailed = 1;
9291293035
return;
9291393036
}
9291493037
9291593038
for(i=0; i<pTab->nCol; i++){
9291693039
zColAff[i] = pTab->aCol[i].affinity;
9291793040
}
92918
- zColAff[pTab->nCol] = '\0';
92919
-
93041
+ do{
93042
+ zColAff[i--] = 0;
93043
+ }while( i>=0 && zColAff[i]==SQLITE_AFF_NONE );
9292093044
pTab->zColAff = zColAff;
9292193045
}
92922
-
92923
- sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT);
93046
+ i = sqlite3Strlen30(zColAff);
93047
+ if( i ){
93048
+ if( iReg ){
93049
+ sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
93050
+ }else{
93051
+ sqlite3VdbeChangeP4(v, -1, zColAff, i);
93052
+ }
93053
+ }
9292493054
}
9292593055
9292693056
/*
9292793057
** Return non-zero if the table pTab in database iDb or any of its indices
9292893058
** have been opened at any point in the VDBE program beginning at location
9292993059
** iStartAddr throught the end of the program. This is used to see if
9293093060
** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
9293193061
** run without using temporary table for the results of the SELECT.
9293293062
*/
92933
-static int readsTable(Parse *p, int iStartAddr, int iDb, Table *pTab){
93063
+static int readsTable(Parse *p, int iDb, Table *pTab){
9293493064
Vdbe *v = sqlite3GetVdbe(p);
9293593065
int i;
9293693066
int iEnd = sqlite3VdbeCurrentAddr(v);
9293793067
#ifndef SQLITE_OMIT_VIRTUALTABLE
9293893068
VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
9293993069
#endif
9294093070
92941
- for(i=iStartAddr; i<iEnd; i++){
93071
+ for(i=1; i<iEnd; i++){
9294293072
VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
9294393073
assert( pOp!=0 );
9294493074
if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
9294593075
Index *pIndex;
9294693076
int tnum = pOp->p2;
@@ -93037,18 +93167,18 @@
9303793167
assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
9303893168
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
9303993169
sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
9304093170
addr = sqlite3VdbeCurrentAddr(v);
9304193171
sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
93042
- sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
93172
+ sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
9304393173
sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
93044
- sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId);
93174
+ sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
9304593175
sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
9304693176
sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
9304793177
sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
9304893178
sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
93049
- sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2);
93179
+ sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
9305093180
sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
9305193181
sqlite3VdbeAddOp0(v, OP_Close);
9305293182
}
9305393183
}
9305493184
@@ -93079,29 +93209,20 @@
9307993209
sqlite3 *db = pParse->db;
9308093210
9308193211
assert( v );
9308293212
for(p = pParse->pAinc; p; p = p->pNext){
9308393213
Db *pDb = &db->aDb[p->iDb];
93084
- int j1, j2, j3, j4, j5;
93214
+ int j1;
9308593215
int iRec;
9308693216
int memId = p->regCtr;
9308793217
9308893218
iRec = sqlite3GetTempReg(pParse);
9308993219
assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
9309093220
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
93091
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
93092
- j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
93093
- j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
93094
- j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
93095
- sqlite3VdbeAddOp2(v, OP_Next, 0, j3);
93096
- sqlite3VdbeJumpHere(v, j2);
93221
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); VdbeCoverage(v);
9309793222
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
93098
- j5 = sqlite3VdbeAddOp0(v, OP_Goto);
93099
- sqlite3VdbeJumpHere(v, j4);
93100
- sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
9310193223
sqlite3VdbeJumpHere(v, j1);
93102
- sqlite3VdbeJumpHere(v, j5);
9310393224
sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec);
9310493225
sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1);
9310593226
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
9310693227
sqlite3VdbeAddOp0(v, OP_Close);
9310793228
sqlite3ReleaseTempReg(pParse, iRec);
@@ -93113,101 +93234,10 @@
9311393234
** above are all no-ops
9311493235
*/
9311593236
# define autoIncBegin(A,B,C) (0)
9311693237
# define autoIncStep(A,B,C)
9311793238
#endif /* SQLITE_OMIT_AUTOINCREMENT */
93118
-
93119
-
93120
-/*
93121
-** Generate code for a co-routine that will evaluate a subquery one
93122
-** row at a time.
93123
-**
93124
-** The pSelect parameter is the subquery that the co-routine will evaluation.
93125
-** Information about the location of co-routine and the registers it will use
93126
-** is returned by filling in the pDest object.
93127
-**
93128
-** Registers are allocated as follows:
93129
-**
93130
-** pDest->iSDParm The register holding the next entry-point of the
93131
-** co-routine. Run the co-routine to its next breakpoint
93132
-** by calling "OP_Yield $X" where $X is pDest->iSDParm.
93133
-**
93134
-** pDest->iSDParm+1 The register holding the "completed" flag for the
93135
-** co-routine. This register is 0 if the previous Yield
93136
-** generated a new result row, or 1 if the subquery
93137
-** has completed. If the Yield is called again
93138
-** after this register becomes 1, then the VDBE will
93139
-** halt with an SQLITE_INTERNAL error.
93140
-**
93141
-** pDest->iSdst First result register.
93142
-**
93143
-** pDest->nSdst Number of result registers.
93144
-**
93145
-** This routine handles all of the register allocation and fills in the
93146
-** pDest structure appropriately.
93147
-**
93148
-** Here is a schematic of the generated code assuming that X is the
93149
-** co-routine entry-point register reg[pDest->iSDParm], that EOF is the
93150
-** completed flag reg[pDest->iSDParm+1], and R and S are the range of
93151
-** registers that hold the result set, reg[pDest->iSdst] through
93152
-** reg[pDest->iSdst+pDest->nSdst-1]:
93153
-**
93154
-** X <- A
93155
-** EOF <- 0
93156
-** goto B
93157
-** A: setup for the SELECT
93158
-** loop rows in the SELECT
93159
-** load results into registers R..S
93160
-** yield X
93161
-** end loop
93162
-** cleanup after the SELECT
93163
-** EOF <- 1
93164
-** yield X
93165
-** halt-error
93166
-** B:
93167
-**
93168
-** To use this subroutine, the caller generates code as follows:
93169
-**
93170
-** [ Co-routine generated by this subroutine, shown above ]
93171
-** S: yield X
93172
-** if EOF goto E
93173
-** if skip this row, goto C
93174
-** if terminate loop, goto E
93175
-** deal with this row
93176
-** C: goto S
93177
-** E:
93178
-*/
93179
-SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse *pParse, Select *pSelect, SelectDest *pDest){
93180
- int regYield; /* Register holding co-routine entry-point */
93181
- int regEof; /* Register holding co-routine completion flag */
93182
- int addrTop; /* Top of the co-routine */
93183
- int j1; /* Jump instruction */
93184
- int rc; /* Result code */
93185
- Vdbe *v; /* VDBE under construction */
93186
-
93187
- regYield = ++pParse->nMem;
93188
- regEof = ++pParse->nMem;
93189
- v = sqlite3GetVdbe(pParse);
93190
- addrTop = sqlite3VdbeCurrentAddr(v);
93191
- sqlite3VdbeAddOp2(v, OP_Integer, addrTop+2, regYield); /* X <- A */
93192
- VdbeComment((v, "Co-routine entry point"));
93193
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
93194
- VdbeComment((v, "Co-routine completion flag"));
93195
- sqlite3SelectDestInit(pDest, SRT_Coroutine, regYield);
93196
- j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
93197
- rc = sqlite3Select(pParse, pSelect, pDest);
93198
- assert( pParse->nErr==0 || rc );
93199
- if( pParse->db->mallocFailed && rc==SQLITE_OK ) rc = SQLITE_NOMEM;
93200
- if( rc ) return rc;
93201
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
93202
- sqlite3VdbeAddOp1(v, OP_Yield, regYield); /* yield X */
93203
- sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
93204
- VdbeComment((v, "End of coroutine"));
93205
- sqlite3VdbeJumpHere(v, j1); /* label B: */
93206
- return rc;
93207
-}
93208
-
9320993239
9321093240
9321193241
/* Forward declaration */
9321293242
static int xferOptimization(
9321393243
Parse *pParse, /* Parser context */
@@ -93268,25 +93298,21 @@
9326893298
**
9326993299
** The 3rd template is for when the second template does not apply
9327093300
** and the SELECT clause does not read from <table> at any time.
9327193301
** The generated code follows this template:
9327293302
**
93273
-** EOF <- 0
9327493303
** X <- A
9327593304
** goto B
9327693305
** A: setup for the SELECT
9327793306
** loop over the rows in the SELECT
9327893307
** load values into registers R..R+n
9327993308
** yield X
9328093309
** end loop
9328193310
** cleanup after the SELECT
93282
-** EOF <- 1
93283
-** yield X
93284
-** goto A
93311
+** end-coroutine X
9328593312
** B: open write cursor to <table> and its indices
93286
-** C: yield X
93287
-** if EOF goto D
93313
+** C: yield X, at EOF goto D
9328893314
** insert the select result into <table> from R..R+n
9328993315
** goto C
9329093316
** D: cleanup
9329193317
**
9329293318
** The 4th template is used if the insert statement takes its
@@ -93293,25 +93319,21 @@
9329393319
** values from a SELECT but the data is being inserted into a table
9329493320
** that is also read as part of the SELECT. In the third form,
9329593321
** we have to use a intermediate table to store the results of
9329693322
** the select. The template is like this:
9329793323
**
93298
-** EOF <- 0
9329993324
** X <- A
9330093325
** goto B
9330193326
** A: setup for the SELECT
9330293327
** loop over the tables in the SELECT
9330393328
** load value into register R..R+n
9330493329
** yield X
9330593330
** end loop
9330693331
** cleanup after the SELECT
93307
-** EOF <- 1
93308
-** yield X
93309
-** halt-error
93332
+** end co-routine R
9331093333
** B: open temp table
93311
-** L: yield X
93312
-** if EOF goto M
93334
+** L: yield X, at EOF goto M
9331393335
** insert row from R..R+n into temp table
9331493336
** goto L
9331593337
** M: open write cursor to <table> and its indices
9331693338
** rewind temp table
9331793339
** C: loop over rows of intermediate table
@@ -93337,30 +93359,29 @@
9333793359
int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
9333893360
int iDataCur = 0; /* VDBE cursor that is the main data repository */
9333993361
int iIdxCur = 0; /* First index cursor */
9334093362
int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
9334193363
int endOfLoop; /* Label for the end of the insertion loop */
93342
- int useTempTable = 0; /* Store SELECT results in intermediate table */
9334393364
int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
9334493365
int addrInsTop = 0; /* Jump to label "D" */
9334593366
int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
93346
- int addrSelect = 0; /* Address of coroutine that implements the SELECT */
9334793367
SelectDest dest; /* Destination for SELECT on rhs of INSERT */
9334893368
int iDb; /* Index of database holding TABLE */
9334993369
Db *pDb; /* The database containing table being inserted into */
93350
- int appendFlag = 0; /* True if the insert is likely to be an append */
93351
- int withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
93370
+ u8 useTempTable = 0; /* Store SELECT results in intermediate table */
93371
+ u8 appendFlag = 0; /* True if the insert is likely to be an append */
93372
+ u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
93373
+ u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
9335293374
ExprList *pList = 0; /* List of VALUES() to be inserted */
9335393375
9335493376
/* Register allocations */
9335593377
int regFromSelect = 0;/* Base register for data coming from SELECT */
9335693378
int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
9335793379
int regRowCount = 0; /* Memory cell used for the row counter */
9335893380
int regIns; /* Block of regs holding rowid+data being inserted */
9335993381
int regRowid; /* registers holding insert rowid */
9336093382
int regData; /* register holding first column to insert */
93361
- int regEof = 0; /* Register recording end of SELECT data */
9336293383
int *aRegIdx = 0; /* One register allocated to each index */
9336393384
9336493385
#ifndef SQLITE_OMIT_TRIGGER
9336593386
int isView; /* True if attempting to insert into a view */
9336693387
Trigger *pTrigger; /* List of triggers on pTab, if required */
@@ -93458,26 +93479,86 @@
9345893479
9345993480
/* If this is an AUTOINCREMENT table, look up the sequence number in the
9346093481
** sqlite_sequence table and store it in memory cell regAutoinc.
9346193482
*/
9346293483
regAutoinc = autoIncBegin(pParse, iDb, pTab);
93484
+
93485
+ /* Allocate registers for holding the rowid of the new row,
93486
+ ** the content of the new row, and the assemblied row record.
93487
+ */
93488
+ regRowid = regIns = pParse->nMem+1;
93489
+ pParse->nMem += pTab->nCol + 1;
93490
+ if( IsVirtual(pTab) ){
93491
+ regRowid++;
93492
+ pParse->nMem++;
93493
+ }
93494
+ regData = regRowid+1;
93495
+
93496
+ /* If the INSERT statement included an IDLIST term, then make sure
93497
+ ** all elements of the IDLIST really are columns of the table and
93498
+ ** remember the column indices.
93499
+ **
93500
+ ** If the table has an INTEGER PRIMARY KEY column and that column
93501
+ ** is named in the IDLIST, then record in the ipkColumn variable
93502
+ ** the index into IDLIST of the primary key column. ipkColumn is
93503
+ ** the index of the primary key as it appears in IDLIST, not as
93504
+ ** is appears in the original table. (The index of the INTEGER
93505
+ ** PRIMARY KEY in the original table is pTab->iPKey.)
93506
+ */
93507
+ if( pColumn ){
93508
+ for(i=0; i<pColumn->nId; i++){
93509
+ pColumn->a[i].idx = -1;
93510
+ }
93511
+ for(i=0; i<pColumn->nId; i++){
93512
+ for(j=0; j<pTab->nCol; j++){
93513
+ if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93514
+ pColumn->a[i].idx = j;
93515
+ if( i!=j ) bIdListInOrder = 0;
93516
+ if( j==pTab->iPKey ){
93517
+ ipkColumn = i; assert( !withoutRowid );
93518
+ }
93519
+ break;
93520
+ }
93521
+ }
93522
+ if( j>=pTab->nCol ){
93523
+ if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93524
+ ipkColumn = i;
93525
+ }else{
93526
+ sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93527
+ pTabList, 0, pColumn->a[i].zName);
93528
+ pParse->checkSchema = 1;
93529
+ goto insert_cleanup;
93530
+ }
93531
+ }
93532
+ }
93533
+ }
9346393534
9346493535
/* Figure out how many columns of data are supplied. If the data
9346593536
** is coming from a SELECT statement, then generate a co-routine that
9346693537
** produces a single row of the SELECT on each invocation. The
9346793538
** co-routine is the common header to the 3rd and 4th templates.
9346893539
*/
9346993540
if( pSelect ){
9347093541
/* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
93471
- int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
93472
- if( rc ) goto insert_cleanup;
93542
+ int regYield; /* Register holding co-routine entry-point */
93543
+ int addrTop; /* Top of the co-routine */
93544
+ int rc; /* Result code */
9347393545
93474
- regEof = dest.iSDParm + 1;
93546
+ regYield = ++pParse->nMem;
93547
+ addrTop = sqlite3VdbeCurrentAddr(v) + 1;
93548
+ sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
93549
+ sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
93550
+ dest.iSdst = bIdListInOrder ? regData : 0;
93551
+ dest.nSdst = pTab->nCol;
93552
+ rc = sqlite3Select(pParse, pSelect, &dest);
9347593553
regFromSelect = dest.iSdst;
93554
+ assert( pParse->nErr==0 || rc );
93555
+ if( rc || db->mallocFailed ) goto insert_cleanup;
93556
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
93557
+ sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
9347693558
assert( pSelect->pEList );
9347793559
nColumn = pSelect->pEList->nExpr;
93478
- assert( dest.nSdst==nColumn );
9347993560
9348093561
/* Set useTempTable to TRUE if the result of the SELECT statement
9348193562
** should be written into a temporary table (template 4). Set to
9348293563
** FALSE if each output row of the SELECT can be written directly into
9348393564
** the destination table (template 3).
@@ -93484,42 +93565,39 @@
9348493565
**
9348593566
** A temp table must be used if the table being updated is also one
9348693567
** of the tables being read by the SELECT statement. Also use a
9348793568
** temp table in the case of row triggers.
9348893569
*/
93489
- if( pTrigger || readsTable(pParse, addrSelect, iDb, pTab) ){
93570
+ if( pTrigger || readsTable(pParse, iDb, pTab) ){
9349093571
useTempTable = 1;
9349193572
}
9349293573
9349393574
if( useTempTable ){
9349493575
/* Invoke the coroutine to extract information from the SELECT
9349593576
** and add it to a transient table srcTab. The code generated
9349693577
** here is from the 4th template:
9349793578
**
9349893579
** B: open temp table
93499
- ** L: yield X
93500
- ** if EOF goto M
93580
+ ** L: yield X, goto M at EOF
9350193581
** insert row from R..R+n into temp table
9350293582
** goto L
9350393583
** M: ...
9350493584
*/
9350593585
int regRec; /* Register to hold packed record */
9350693586
int regTempRowid; /* Register to hold temp table ROWID */
93507
- int addrTop; /* Label "L" */
93508
- int addrIf; /* Address of jump to M */
93587
+ int addrL; /* Label "L" */
9350993588
9351093589
srcTab = pParse->nTab++;
9351193590
regRec = sqlite3GetTempReg(pParse);
9351293591
regTempRowid = sqlite3GetTempReg(pParse);
9351393592
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
93514
- addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93515
- addrIf = sqlite3VdbeAddOp1(v, OP_If, regEof);
93593
+ addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
9351693594
sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
9351793595
sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
9351893596
sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
93519
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
93520
- sqlite3VdbeJumpHere(v, addrIf);
93597
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
93598
+ sqlite3VdbeJumpHere(v, addrL);
9352193599
sqlite3ReleaseTempReg(pParse, regRec);
9352293600
sqlite3ReleaseTempReg(pParse, regTempRowid);
9352393601
}
9352493602
}else{
9352593603
/* This is the case if the data for the INSERT is coming from a VALUES
@@ -93535,10 +93613,18 @@
9353593613
if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
9353693614
goto insert_cleanup;
9353793615
}
9353893616
}
9353993617
}
93618
+
93619
+ /* If there is no IDLIST term but the table has an integer primary
93620
+ ** key, the set the ipkColumn variable to the integer primary key
93621
+ ** column index in the original table definition.
93622
+ */
93623
+ if( pColumn==0 && nColumn>0 ){
93624
+ ipkColumn = pTab->iPKey;
93625
+ }
9354093626
9354193627
/* Make sure the number of columns in the source data matches the number
9354293628
** of columns to be inserted into the table.
9354393629
*/
9354493630
if( IsVirtual(pTab) ){
@@ -93554,56 +93640,10 @@
9355493640
}
9355593641
if( pColumn!=0 && nColumn!=pColumn->nId ){
9355693642
sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
9355793643
goto insert_cleanup;
9355893644
}
93559
-
93560
- /* If the INSERT statement included an IDLIST term, then make sure
93561
- ** all elements of the IDLIST really are columns of the table and
93562
- ** remember the column indices.
93563
- **
93564
- ** If the table has an INTEGER PRIMARY KEY column and that column
93565
- ** is named in the IDLIST, then record in the ipkColumn variable
93566
- ** the index into IDLIST of the primary key column. ipkColumn is
93567
- ** the index of the primary key as it appears in IDLIST, not as
93568
- ** is appears in the original table. (The index of the INTEGER
93569
- ** PRIMARY KEY in the original table is pTab->iPKey.)
93570
- */
93571
- if( pColumn ){
93572
- for(i=0; i<pColumn->nId; i++){
93573
- pColumn->a[i].idx = -1;
93574
- }
93575
- for(i=0; i<pColumn->nId; i++){
93576
- for(j=0; j<pTab->nCol; j++){
93577
- if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93578
- pColumn->a[i].idx = j;
93579
- if( j==pTab->iPKey ){
93580
- ipkColumn = i; assert( !withoutRowid );
93581
- }
93582
- break;
93583
- }
93584
- }
93585
- if( j>=pTab->nCol ){
93586
- if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93587
- ipkColumn = i;
93588
- }else{
93589
- sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93590
- pTabList, 0, pColumn->a[i].zName);
93591
- pParse->checkSchema = 1;
93592
- goto insert_cleanup;
93593
- }
93594
- }
93595
- }
93596
- }
93597
-
93598
- /* If there is no IDLIST term but the table has an integer primary
93599
- ** key, the set the ipkColumn variable to the integer primary key
93600
- ** column index in the original table definition.
93601
- */
93602
- if( pColumn==0 && nColumn>0 ){
93603
- ipkColumn = pTab->iPKey;
93604
- }
9360593645
9360693646
/* Initialize the count of rows to be inserted
9360793647
*/
9360893648
if( db->flags & SQLITE_CountRows ){
9360993649
regRowCount = ++pParse->nMem;
@@ -93627,42 +93667,30 @@
9362793667
/* This is the top of the main insertion loop */
9362893668
if( useTempTable ){
9362993669
/* This block codes the top of loop only. The complete loop is the
9363093670
** following pseudocode (template 4):
9363193671
**
93632
- ** rewind temp table
93672
+ ** rewind temp table, if empty goto D
9363393673
** C: loop over rows of intermediate table
9363493674
** transfer values form intermediate table into <table>
9363593675
** end loop
9363693676
** D: ...
9363793677
*/
93638
- addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab);
93678
+ addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); VdbeCoverage(v);
9363993679
addrCont = sqlite3VdbeCurrentAddr(v);
9364093680
}else if( pSelect ){
9364193681
/* This block codes the top of loop only. The complete loop is the
9364293682
** following pseudocode (template 3):
9364393683
**
93644
- ** C: yield X
93645
- ** if EOF goto D
93684
+ ** C: yield X, at EOF goto D
9364693685
** insert the select result into <table> from R..R+n
9364793686
** goto C
9364893687
** D: ...
9364993688
*/
93650
- addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93651
- addrInsTop = sqlite3VdbeAddOp1(v, OP_If, regEof);
93652
- }
93653
-
93654
- /* Allocate registers for holding the rowid of the new row,
93655
- ** the content of the new row, and the assemblied row record.
93656
- */
93657
- regRowid = regIns = pParse->nMem+1;
93658
- pParse->nMem += pTab->nCol + 1;
93659
- if( IsVirtual(pTab) ){
93660
- regRowid++;
93661
- pParse->nMem++;
93662
- }
93663
- regData = regRowid+1;
93689
+ addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93690
+ VdbeCoverage(v);
93691
+ }
9366493692
9366593693
/* Run the BEFORE and INSTEAD OF triggers, if there are any
9366693694
*/
9366793695
endOfLoop = sqlite3VdbeMakeLabel(v);
9366893696
if( tmask & TRIGGER_BEFORE ){
@@ -93683,14 +93711,14 @@
9368393711
sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
9368493712
}else{
9368593713
assert( pSelect==0 ); /* Otherwise useTempTable is true */
9368693714
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
9368793715
}
93688
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
93716
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
9368993717
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
9369093718
sqlite3VdbeJumpHere(v, j1);
93691
- sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
93719
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
9369293720
}
9369393721
9369493722
/* Cannot have triggers on a virtual table. If it were possible,
9369593723
** this block would have to account for hidden column.
9369693724
*/
@@ -93720,12 +93748,11 @@
9372093748
** do not attempt any conversions before assembling the record.
9372193749
** If this is a real table, attempt conversions as required by the
9372293750
** table column affinities.
9372393751
*/
9372493752
if( !isView ){
93725
- sqlite3VdbeAddOp2(v, OP_Affinity, regCols+1, pTab->nCol);
93726
- sqlite3TableAffinityStr(v, pTab);
93753
+ sqlite3TableAffinity(v, pTab, regCols+1);
9372793754
}
9372893755
9372993756
/* Fire BEFORE or INSTEAD OF triggers */
9373093757
sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
9373193758
pTab, regCols-pTab->nCol-1, onError, endOfLoop);
@@ -93743,11 +93770,11 @@
9374393770
}
9374493771
if( ipkColumn>=0 ){
9374593772
if( useTempTable ){
9374693773
sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
9374793774
}else if( pSelect ){
93748
- sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid);
93775
+ sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid);
9374993776
}else{
9375093777
VdbeOp *pOp;
9375193778
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
9375293779
pOp = sqlite3VdbeGetOp(v, -1);
9375393780
if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
@@ -93762,18 +93789,18 @@
9376293789
** to generate a unique primary key value.
9376393790
*/
9376493791
if( !appendFlag ){
9376593792
int j1;
9376693793
if( !IsVirtual(pTab) ){
93767
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
93794
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); VdbeCoverage(v);
9376893795
sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
9376993796
sqlite3VdbeJumpHere(v, j1);
9377093797
}else{
9377193798
j1 = sqlite3VdbeCurrentAddr(v);
93772
- sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
93799
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); VdbeCoverage(v);
9377393800
}
93774
- sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
93801
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
9377593802
}
9377693803
}else if( IsVirtual(pTab) || withoutRowid ){
9377793804
sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
9377893805
}else{
9377993806
sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -93789,12 +93816,13 @@
9378993816
int iRegStore = regRowid+1+i;
9379093817
if( i==pTab->iPKey ){
9379193818
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
9379293819
** Whenever this column is read, the rowid will be substituted
9379393820
** in its place. Hence, fill this column with a NULL to avoid
93794
- ** taking up data space with information that will never be used. */
93795
- sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
93821
+ ** taking up data space with information that will never be used.
93822
+ ** As there may be shallow copies of this value, make it a soft-NULL */
93823
+ sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
9379693824
continue;
9379793825
}
9379893826
if( pColumn==0 ){
9379993827
if( IsHiddenColumn(&pTab->aCol[i]) ){
9380093828
assert( IsVirtual(pTab) );
@@ -93807,15 +93835,17 @@
9380793835
for(j=0; j<pColumn->nId; j++){
9380893836
if( pColumn->a[j].idx==i ) break;
9380993837
}
9381093838
}
9381193839
if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){
93812
- sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, iRegStore);
93840
+ sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
9381393841
}else if( useTempTable ){
9381493842
sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, iRegStore);
9381593843
}else if( pSelect ){
93816
- sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
93844
+ if( regFromSelect!=regData ){
93845
+ sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
93846
+ }
9381793847
}else{
9381893848
sqlite3ExprCode(pParse, pList->a[j].pExpr, iRegStore);
9381993849
}
9382093850
}
9382193851
@@ -93857,11 +93887,11 @@
9385793887
/* The bottom of the main insertion loop, if the data source
9385893888
** is a SELECT statement.
9385993889
*/
9386093890
sqlite3VdbeResolveLabel(v, endOfLoop);
9386193891
if( useTempTable ){
93862
- sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont);
93892
+ sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
9386393893
sqlite3VdbeJumpHere(v, addrInsTop);
9386493894
sqlite3VdbeAddOp1(v, OP_Close, srcTab);
9386593895
}else if( pSelect ){
9386693896
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
9386793897
sqlite3VdbeJumpHere(v, addrInsTop);
@@ -94024,10 +94054,11 @@
9402494054
int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
9402594055
int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
9402694056
int ipkTop = 0; /* Top of the rowid change constraint check */
9402794057
int ipkBottom = 0; /* Bottom of the rowid change constraint check */
9402894058
u8 isUpdate; /* True if this is an UPDATE operation */
94059
+ u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
9402994060
int regRowid = -1; /* Register holding ROWID value */
9403094061
9403194062
isUpdate = regOldData!=0;
9403294063
db = pParse->db;
9403394064
v = sqlite3GetVdbe(pParse);
@@ -94078,19 +94109,21 @@
9407894109
char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
9407994110
pTab->aCol[i].zName);
9408094111
sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
9408194112
regNewData+1+i, zMsg, P4_DYNAMIC);
9408294113
sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
94114
+ VdbeCoverage(v);
9408394115
break;
9408494116
}
9408594117
case OE_Ignore: {
9408694118
sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
94119
+ VdbeCoverage(v);
9408794120
break;
9408894121
}
9408994122
default: {
9409094123
assert( onError==OE_Replace );
94091
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
94124
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i); VdbeCoverage(v);
9409294125
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
9409394126
sqlite3VdbeJumpHere(v, j1);
9409494127
break;
9409594128
}
9409694129
}
@@ -94138,10 +94171,12 @@
9413894171
if( isUpdate ){
9413994172
/* pkChng!=0 does not mean that the rowid has change, only that
9414094173
** it might have changed. Skip the conflict logic below if the rowid
9414194174
** is unchanged. */
9414294175
sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
94176
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94177
+ VdbeCoverage(v);
9414394178
}
9414494179
9414594180
/* If the response to a rowid conflict is REPLACE but the response
9414694181
** to some other UNIQUE constraint is FAIL or IGNORE, then we need
9414794182
** to defer the running of the rowid conflict checking until after
@@ -94157,10 +94192,11 @@
9415794192
}
9415894193
9415994194
/* Check to see if the new rowid already exists in the table. Skip
9416094195
** the following conflict logic if it does not. */
9416194196
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
94197
+ VdbeCoverage(v);
9416294198
9416394199
/* Generate code that deals with a rowid collision */
9416494200
switch( onError ){
9416594201
default: {
9416694202
onError = OE_Abort;
@@ -94235,10 +94271,14 @@
9423594271
int regR; /* Range of registers holding conflicting PK */
9423694272
int iThisCur; /* Cursor for this UNIQUE index */
9423794273
int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
9423894274
9423994275
if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
94276
+ if( bAffinityDone==0 ){
94277
+ sqlite3TableAffinity(v, pTab, regNewData+1);
94278
+ bAffinityDone = 1;
94279
+ }
9424094280
iThisCur = iIdxCur+ix;
9424194281
addrUniqueOk = sqlite3VdbeMakeLabel(v);
9424294282
9424394283
/* Skip partial indices for which the WHERE clause is not true */
9424494284
if( pIdx->pPartIdxWhere ){
@@ -94265,11 +94305,10 @@
9426594305
}
9426694306
sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
9426794307
VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
9426894308
}
9426994309
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
94270
- sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
9427194310
VdbeComment((v, "for %s", pIdx->zName));
9427294311
sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
9427394312
9427494313
/* In an UPDATE operation, if this index is the PRIMARY KEY index
9427594314
** of a WITHOUT ROWID table and there has been no change the
@@ -94293,11 +94332,11 @@
9429394332
onError = OE_Abort;
9429494333
}
9429594334
9429694335
/* Check to see if the new index entry will be unique */
9429794336
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94298
- regIdx, pIdx->nKeyCol);
94337
+ regIdx, pIdx->nKeyCol); VdbeCoverage(v);
9429994338
9430094339
/* Generate code to handle collisions */
9430194340
regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
9430294341
if( isUpdate || onError==OE_Replace ){
9430394342
if( HasRowid(pTab) ){
@@ -94304,10 +94343,12 @@
9430494343
sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
9430594344
/* Conflict only if the rowid of the existing index entry
9430694345
** is different from old-rowid */
9430794346
if( isUpdate ){
9430894347
sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94348
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94349
+ VdbeCoverage(v);
9430994350
}
9431094351
}else{
9431194352
int x;
9431294353
/* Extract the PRIMARY KEY from the end of the index entry and
9431394354
** store it in registers regR..regR+nPk-1 */
@@ -94339,10 +94380,13 @@
9433994380
op = OP_Eq;
9434094381
}
9434194382
sqlite3VdbeAddOp4(v, op,
9434294383
regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
9434394384
);
94385
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94386
+ VdbeCoverageIf(v, op==OP_Eq);
94387
+ VdbeCoverageIf(v, op==OP_Ne);
9434494388
}
9434594389
}
9434694390
}
9434794391
}
9434894392
@@ -94410,18 +94454,21 @@
9441094454
Index *pIdx; /* An index being inserted or updated */
9441194455
u8 pik_flags; /* flag values passed to the btree insert */
9441294456
int regData; /* Content registers (after the rowid) */
9441394457
int regRec; /* Register holding assemblied record for the table */
9441494458
int i; /* Loop counter */
94459
+ u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
9441594460
9441694461
v = sqlite3GetVdbe(pParse);
9441794462
assert( v!=0 );
9441894463
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
9441994464
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
9442094465
if( aRegIdx[i]==0 ) continue;
94466
+ bAffinityDone = 1;
9442194467
if( pIdx->pPartIdxWhere ){
9442294468
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
94469
+ VdbeCoverage(v);
9442394470
}
9442494471
sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
9442594472
pik_flags = 0;
9442694473
if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
9442794474
if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
@@ -94432,11 +94479,11 @@
9443294479
}
9443394480
if( !HasRowid(pTab) ) return;
9443494481
regData = regNewData + 1;
9443594482
regRec = sqlite3GetTempReg(pParse);
9443694483
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
94437
- sqlite3TableAffinityStr(v, pTab);
94484
+ if( !bAffinityDone ) sqlite3TableAffinity(v, pTab, 0);
9443894485
sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
9443994486
if( pParse->nested ){
9444094487
pik_flags = 0;
9444194488
}else{
9444294489
pik_flags = OPFLAG_NCHANGE;
@@ -94801,20 +94848,21 @@
9480194848
** (2) The destination has a unique index. (The xfer optimization
9480294849
** is unable to test uniqueness.)
9480394850
**
9480494851
** (3) onError is something other than OE_Abort and OE_Rollback.
9480594852
*/
94806
- addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
94853
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
9480794854
emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
9480894855
sqlite3VdbeJumpHere(v, addr1);
9480994856
}
9481094857
if( HasRowid(pSrc) ){
9481194858
sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94812
- emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94859
+ emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
9481394860
if( pDest->iPKey>=0 ){
9481494861
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
9481594862
addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
94863
+ VdbeCoverage(v);
9481694864
sqlite3RowidConstraint(pParse, onError, pDest);
9481794865
sqlite3VdbeJumpHere(v, addr2);
9481894866
autoIncStep(pParse, regAutoinc, regRowid);
9481994867
}else if( pDest->pIndex==0 ){
9482094868
addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
@@ -94824,11 +94872,11 @@
9482494872
}
9482594873
sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
9482694874
sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
9482794875
sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
9482894876
sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94829
- sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
94877
+ sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
9483094878
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
9483194879
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
9483294880
}else{
9483394881
sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
9483494882
sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
@@ -94843,19 +94891,19 @@
9484394891
VdbeComment((v, "%s", pSrcIdx->zName));
9484494892
sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
9484594893
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
9484694894
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
9484794895
VdbeComment((v, "%s", pDestIdx->zName));
94848
- addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94896
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
9484994897
sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
9485094898
sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
94851
- sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
94899
+ sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
9485294900
sqlite3VdbeJumpHere(v, addr1);
9485394901
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
9485494902
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
9485594903
}
94856
- sqlite3VdbeJumpHere(v, emptySrcTest);
94904
+ if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest);
9485794905
sqlite3ReleaseTempReg(pParse, regRowid);
9485894906
sqlite3ReleaseTempReg(pParse, regData);
9485994907
if( emptyDestTest ){
9486094908
sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
9486194909
sqlite3VdbeJumpHere(v, emptyDestTest);
@@ -97085,10 +97133,11 @@
9708597133
** is always on by default regardless of the sign of the default cache
9708697134
** size. But continue to take the absolute value of the default cache
9708797135
** size of historical compatibility.
9708897136
*/
9708997137
case PragTyp_DEFAULT_CACHE_SIZE: {
97138
+ static const int iLn = __LINE__+2;
9709097139
static const VdbeOpList getCacheSize[] = {
9709197140
{ OP_Transaction, 0, 0, 0}, /* 0 */
9709297141
{ OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
9709397142
{ OP_IfPos, 1, 8, 0},
9709497143
{ OP_Integer, 0, 2, 0},
@@ -97102,11 +97151,11 @@
9710297151
sqlite3VdbeUsesBtree(v, iDb);
9710397152
if( !zRight ){
9710497153
sqlite3VdbeSetNumCols(v, 1);
9710597154
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
9710697155
pParse->nMem += 2;
97107
- addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
97156
+ addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
9710897157
sqlite3VdbeChangeP1(v, addr, iDb);
9710997158
sqlite3VdbeChangeP1(v, addr+1, iDb);
9711097159
sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
9711197160
}else{
9711297161
int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
@@ -97347,20 +97396,21 @@
9734797396
/* When setting the auto_vacuum mode to either "full" or
9734897397
** "incremental", write the value of meta[6] in the database
9734997398
** file. Before writing to meta[6], check that meta[3] indicates
9735097399
** that this really is an auto-vacuum capable database.
9735197400
*/
97401
+ static const int iLn = __LINE__+2;
9735297402
static const VdbeOpList setMeta6[] = {
9735397403
{ OP_Transaction, 0, 1, 0}, /* 0 */
9735497404
{ OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
9735597405
{ OP_If, 1, 0, 0}, /* 2 */
9735697406
{ OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
9735797407
{ OP_Integer, 0, 1, 0}, /* 4 */
9735897408
{ OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
9735997409
};
9736097410
int iAddr;
97361
- iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
97411
+ iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
9736297412
sqlite3VdbeChangeP1(v, iAddr, iDb);
9736397413
sqlite3VdbeChangeP1(v, iAddr+1, iDb);
9736497414
sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
9736597415
sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
9736697416
sqlite3VdbeChangeP1(v, iAddr+5, iDb);
@@ -97382,14 +97432,14 @@
9738297432
if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
9738397433
iLimit = 0x7fffffff;
9738497434
}
9738597435
sqlite3BeginWriteOperation(pParse, 0, iDb);
9738697436
sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
97387
- addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
97437
+ addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
9738897438
sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
9738997439
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
97390
- sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
97440
+ sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
9739197441
sqlite3VdbeJumpHere(v, addr);
9739297442
break;
9739397443
}
9739497444
#endif
9739597445
@@ -97956,11 +98006,11 @@
9795698006
}
9795798007
}
9795898008
assert( pParse->nErr>0 || pFK==0 );
9795998009
if( pFK ) break;
9796098010
if( pParse->nTab<i ) pParse->nTab = i;
97961
- addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0);
98011
+ addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
9796298012
for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
9796398013
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
9796498014
pIdx = 0;
9796598015
aiCols = 0;
9796698016
if( pParent ){
@@ -97972,30 +98022,30 @@
9797298022
int iKey = pFK->aCol[0].iFrom;
9797398023
assert( iKey>=0 && iKey<pTab->nCol );
9797498024
if( iKey!=pTab->iPKey ){
9797598025
sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
9797698026
sqlite3ColumnDefault(v, pTab, iKey, regRow);
97977
- sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk);
97978
- sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
97979
- sqlite3VdbeCurrentAddr(v)+3);
98027
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
98028
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
98029
+ sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
9798098030
}else{
9798198031
sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
9798298032
}
97983
- sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow);
98033
+ sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
9798498034
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
9798598035
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
9798698036
}else{
9798798037
for(j=0; j<pFK->nCol; j++){
9798898038
sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
9798998039
aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
97990
- sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk);
98040
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
9799198041
}
9799298042
if( pParent ){
97993
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey);
97994
- sqlite3VdbeChangeP4(v, -1,
97995
- sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
98043
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
98044
+ sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
9799698045
sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
98046
+ VdbeCoverage(v);
9799798047
}
9799898048
}
9799998049
sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
9800098050
sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
9800198051
pFK->zTo, P4_TRANSIENT);
@@ -98002,11 +98052,11 @@
9800298052
sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
9800398053
sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
9800498054
sqlite3VdbeResolveLabel(v, addrOk);
9800598055
sqlite3DbFree(db, aiCols);
9800698056
}
98007
- sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
98057
+ sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
9800898058
sqlite3VdbeJumpHere(v, addrTop);
9800998059
}
9801098060
}
9801198061
break;
9801298062
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
@@ -98049,10 +98099,11 @@
9804998099
9805098100
/* Code that appears at the end of the integrity check. If no error
9805198101
** messages have been generated, output OK. Otherwise output the
9805298102
** error message
9805398103
*/
98104
+ static const int iLn = __LINE__+2;
9805498105
static const VdbeOpList endCode[] = {
9805598106
{ OP_AddImm, 1, 0, 0}, /* 0 */
9805698107
{ OP_IfNeg, 1, 0, 0}, /* 1 */
9805798108
{ OP_String8, 0, 3, 0}, /* 2 */
9805898109
{ OP_ResultRow, 3, 1, 0},
@@ -98097,10 +98148,11 @@
9809798148
if( OMIT_TEMPDB && i==1 ) continue;
9809898149
if( iDb>=0 && i!=iDb ) continue;
9809998150
9810098151
sqlite3CodeVerifySchema(pParse, i);
9810198152
addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
98153
+ VdbeCoverage(v);
9810298154
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9810398155
sqlite3VdbeJumpHere(v, addr);
9810498156
9810598157
/* Do an integrity check of the B-Tree
9810698158
**
@@ -98128,11 +98180,11 @@
9812898180
pParse->nMem = MAX( pParse->nMem, cnt+8 );
9812998181
9813098182
/* Do the b-tree integrity checks */
9813198183
sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
9813298184
sqlite3VdbeChangeP5(v, (u8)i);
98133
- addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
98185
+ addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
9813498186
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
9813598187
sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
9813698188
P4_DYNAMIC);
9813798189
sqlite3VdbeAddOp2(v, OP_Move, 2, 4);
9813898190
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
@@ -98150,10 +98202,11 @@
9815098202
int r1 = -1;
9815198203
9815298204
if( pTab->pIndex==0 ) continue;
9815398205
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
9815498206
addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98207
+ VdbeCoverage(v);
9815598208
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9815698209
sqlite3VdbeJumpHere(v, addr);
9815798210
sqlite3ExprCacheClear(pParse);
9815898211
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
9815998212
1, 0, &iDataCur, &iIdxCur);
@@ -98160,57 +98213,58 @@
9816098213
sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
9816198214
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9816298215
sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
9816398216
}
9816498217
pParse->nMem = MAX(pParse->nMem, 8+j);
98165
- sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0);
98218
+ sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
9816698219
loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
9816798220
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9816898221
int jmp2, jmp3, jmp4;
9816998222
if( pPk==pIdx ) continue;
9817098223
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
9817198224
pPrior, r1);
9817298225
pPrior = pIdx;
9817398226
sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
9817498227
jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98175
- pIdx->nColumn);
98228
+ pIdx->nColumn); VdbeCoverage(v);
9817698229
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
9817798230
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
9817898231
sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
9817998232
sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
9818098233
P4_STATIC);
9818198234
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
9818298235
sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
9818398236
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
9818498237
sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98185
- jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
98238
+ jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
9818698239
sqlite3VdbeAddOp0(v, OP_Halt);
9818798240
sqlite3VdbeJumpHere(v, jmp4);
9818898241
sqlite3VdbeJumpHere(v, jmp2);
9818998242
sqlite3VdbeResolveLabel(v, jmp3);
9819098243
}
98191
- sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop);
98244
+ sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
9819298245
sqlite3VdbeJumpHere(v, loopTop-1);
9819398246
#ifndef SQLITE_OMIT_BTREECOUNT
9819498247
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
9819598248
"wrong # of entries in index ", P4_STATIC);
9819698249
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9819798250
if( pPk==pIdx ) continue;
9819898251
addr = sqlite3VdbeCurrentAddr(v);
98199
- sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
98252
+ sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
9820098253
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9820198254
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98202
- sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3);
98255
+ sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
98256
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
9820398257
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
9820498258
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
9820598259
sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
9820698260
sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
9820798261
}
9820898262
#endif /* SQLITE_OMIT_BTREECOUNT */
9820998263
}
9821098264
}
98211
- addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
98265
+ addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
9821298266
sqlite3VdbeChangeP2(v, addr, -mxErr);
9821398267
sqlite3VdbeJumpHere(v, addr+1);
9821498268
sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
9821598269
}
9821698270
break;
@@ -98344,11 +98398,11 @@
9834498398
static const VdbeOpList setCookie[] = {
9834598399
{ OP_Transaction, 0, 1, 0}, /* 0 */
9834698400
{ OP_Integer, 0, 1, 0}, /* 1 */
9834798401
{ OP_SetCookie, 0, 0, 1}, /* 2 */
9834898402
};
98349
- int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
98403
+ int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
9835098404
sqlite3VdbeChangeP1(v, addr, iDb);
9835198405
sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
9835298406
sqlite3VdbeChangeP1(v, addr+2, iDb);
9835398407
sqlite3VdbeChangeP2(v, addr+2, iCookie);
9835498408
}else{
@@ -98356,11 +98410,11 @@
9835698410
static const VdbeOpList readCookie[] = {
9835798411
{ OP_Transaction, 0, 0, 0}, /* 0 */
9835898412
{ OP_ReadCookie, 0, 1, 0}, /* 1 */
9835998413
{ OP_ResultRow, 1, 1, 0}
9836098414
};
98361
- int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
98415
+ int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0);
9836298416
sqlite3VdbeChangeP1(v, addr, iDb);
9836398417
sqlite3VdbeChangeP1(v, addr+1, iDb);
9836498418
sqlite3VdbeChangeP3(v, addr+1, iCookie);
9836598419
sqlite3VdbeSetNumCols(v, 1);
9836698420
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
@@ -99562,10 +99616,18 @@
9956299616
if( p ){
9956399617
clearSelect(db, p);
9956499618
sqlite3DbFree(db, p);
9956599619
}
9956699620
}
99621
+
99622
+/*
99623
+** Return a pointer to the right-most SELECT statement in a compound.
99624
+*/
99625
+static Select *findRightmost(Select *p){
99626
+ while( p->pNext ) p = p->pNext;
99627
+ return p;
99628
+}
9956799629
9956899630
/*
9956999631
** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
9957099632
** type of join. Return an integer constant that expresses that type
9957199633
** in terms of the following bit values:
@@ -99901,11 +99963,11 @@
9990199963
if( pSelect->iOffset ){
9990299964
iLimit = pSelect->iOffset+1;
9990399965
}else{
9990499966
iLimit = pSelect->iLimit;
9990599967
}
99906
- addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit);
99968
+ addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v);
9990799969
sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
9990899970
addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
9990999971
sqlite3VdbeJumpHere(v, addr1);
9991099972
sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
9991199973
sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
@@ -99922,11 +99984,11 @@
9992299984
int iContinue /* Jump here to skip the current record */
9992399985
){
9992499986
if( iOffset>0 && iContinue!=0 ){
9992599987
int addr;
9992699988
sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99927
- addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset);
99989
+ addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); VdbeCoverage(v);
9992899990
sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
9992999991
VdbeComment((v, "skip OFFSET records"));
9993099992
sqlite3VdbeJumpHere(v, addr);
9993199993
}
9993299994
}
@@ -99950,11 +100012,11 @@
99950100012
Vdbe *v;
99951100013
int r1;
99952100014
99953100015
v = pParse->pVdbe;
99954100016
r1 = sqlite3GetTempReg(pParse);
99955
- sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N);
100017
+ sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
99956100018
sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
99957100019
sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
99958100020
sqlite3ReleaseTempReg(pParse, r1);
99959100021
}
99960100022
@@ -100031,17 +100093,23 @@
100031100093
}
100032100094
100033100095
/* Pull the requested columns.
100034100096
*/
100035100097
nResultCol = pEList->nExpr;
100098
+
100036100099
if( pDest->iSdst==0 ){
100037100100
pDest->iSdst = pParse->nMem+1;
100038
- pDest->nSdst = nResultCol;
100101
+ pParse->nMem += nResultCol;
100102
+ }else if( pDest->iSdst+nResultCol > pParse->nMem ){
100103
+ /* This is an error condition that can result, for example, when a SELECT
100104
+ ** on the right-hand side of an INSERT contains more result columns than
100105
+ ** there are columns in the table on the left. The error will be caught
100106
+ ** and reported later. But we need to make sure enough memory is allocated
100107
+ ** to avoid other spurious errors in the meantime. */
100039100108
pParse->nMem += nResultCol;
100040
- }else{
100041
- assert( pDest->nSdst==nResultCol );
100042100109
}
100110
+ pDest->nSdst = nResultCol;
100043100111
regResult = pDest->iSdst;
100044100112
if( srcTab>=0 ){
100045100113
for(i=0; i<nResultCol; i++){
100046100114
sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100047100115
VdbeComment((v, "%s", pEList->a[i].zName));
@@ -100084,13 +100152,15 @@
100084100152
iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100085100153
for(i=0; i<nResultCol; i++){
100086100154
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100087100155
if( i<nResultCol-1 ){
100088100156
sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
100157
+ VdbeCoverage(v);
100089100158
}else{
100090100159
sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100091
- }
100160
+ VdbeCoverage(v);
100161
+ }
100092100162
sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100093100163
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100094100164
}
100095100165
assert( sqlite3VdbeCurrentAddr(v)==iJump );
100096100166
sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
@@ -100152,11 +100222,11 @@
100152100222
** on an ephemeral index. If the current row is already present
100153100223
** in the index, do not write it to the output. If not, add the
100154100224
** current row to the index and proceed with writing it to the
100155100225
** output table as well. */
100156100226
int addr = sqlite3VdbeCurrentAddr(v) + 4;
100157
- sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
100227
+ sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0); VdbeCoverage(v);
100158100228
sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
100159100229
assert( pOrderBy==0 );
100160100230
}
100161100231
#endif
100162100232
if( pOrderBy ){
@@ -100219,16 +100289,12 @@
100219100289
}
100220100290
break;
100221100291
}
100222100292
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
100223100293
100224
- /* Send the data to the callback function or to a subroutine. In the
100225
- ** case of a subroutine, the subroutine itself is responsible for
100226
- ** popping the data from the stack.
100227
- */
100228
- case SRT_Coroutine:
100229
- case SRT_Output: {
100294
+ case SRT_Coroutine: /* Send data to a co-routine */
100295
+ case SRT_Output: { /* Return the results */
100230100296
testcase( eDest==SRT_Coroutine );
100231100297
testcase( eDest==SRT_Output );
100232100298
if( pOrderBy ){
100233100299
int r1 = sqlite3GetTempReg(pParse);
100234100300
sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
@@ -100260,17 +100326,20 @@
100260100326
assert( pSO );
100261100327
nKey = pSO->nExpr;
100262100328
r1 = sqlite3GetTempReg(pParse);
100263100329
r2 = sqlite3GetTempRange(pParse, nKey+2);
100264100330
r3 = r2+nKey+1;
100265
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100266100331
if( eDest==SRT_DistQueue ){
100267100332
/* If the destination is DistQueue, then cursor (iParm+1) is open
100268100333
** on a second ephemeral index that holds all values every previously
100269
- ** added to the queue. Only add this new value if it has never before
100270
- ** been added */
100271
- addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0);
100334
+ ** added to the queue. */
100335
+ addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
100336
+ regResult, nResultCol);
100337
+ VdbeCoverage(v);
100338
+ }
100339
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100340
+ if( eDest==SRT_DistQueue ){
100272100341
sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100273100342
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
100274100343
}
100275100344
for(i=0; i<nKey; i++){
100276100345
sqlite3VdbeAddOp2(v, OP_SCopy,
@@ -100305,11 +100374,11 @@
100305100374
/* Jump to the end of the loop if the LIMIT is reached. Except, if
100306100375
** there is a sorter, in which case the sorter has already limited
100307100376
** the output for us.
100308100377
*/
100309100378
if( pOrderBy==0 && p->iLimit ){
100310
- sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
100379
+ sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
100311100380
}
100312100381
}
100313100382
100314100383
/*
100315100384
** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -100524,16 +100593,17 @@
100524100593
if( p->selFlags & SF_UseSorter ){
100525100594
int regSortOut = ++pParse->nMem;
100526100595
int ptab2 = pParse->nTab++;
100527100596
sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100528100597
addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
100598
+ VdbeCoverage(v);
100529100599
codeOffset(v, p->iOffset, addrContinue);
100530100600
sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100531100601
sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100532100602
sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100533100603
}else{
100534
- addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
100604
+ addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
100535100605
codeOffset(v, p->iOffset, addrContinue);
100536100606
sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100537100607
}
100538100608
switch( eDest ){
100539100609
case SRT_Table:
@@ -100587,13 +100657,13 @@
100587100657
100588100658
/* The bottom of the loop
100589100659
*/
100590100660
sqlite3VdbeResolveLabel(v, addrContinue);
100591100661
if( p->selFlags & SF_UseSorter ){
100592
- sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr);
100662
+ sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
100593100663
}else{
100594
- sqlite3VdbeAddOp2(v, OP_Next, iTab, addr);
100664
+ sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
100595100665
}
100596100666
sqlite3VdbeResolveLabel(v, addrBreak);
100597100667
if( eDest==SRT_Output || eDest==SRT_Coroutine ){
100598100668
sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
100599100669
}
@@ -101073,15 +101143,17 @@
101073101143
*/
101074101144
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
101075101145
Vdbe *v = pParse->pVdbe;
101076101146
if( v==0 ){
101077101147
v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
101078
-#ifndef SQLITE_OMIT_TRACE
101079
- if( v ){
101080
- sqlite3VdbeAddOp0(v, OP_Trace);
101148
+ if( v ) sqlite3VdbeAddOp0(v, OP_Init);
101149
+ if( pParse->pToplevel==0
101150
+ && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
101151
+ ){
101152
+ pParse->okConstFactor = 1;
101081101153
}
101082
-#endif
101154
+
101083101155
}
101084101156
return v;
101085101157
}
101086101158
101087101159
@@ -101135,26 +101207,26 @@
101135101207
}else if( n>=0 && p->nSelectRow>(u64)n ){
101136101208
p->nSelectRow = n;
101137101209
}
101138101210
}else{
101139101211
sqlite3ExprCode(pParse, p->pLimit, iLimit);
101140
- sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit);
101212
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
101141101213
VdbeComment((v, "LIMIT counter"));
101142
- sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak);
101214
+ sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v);
101143101215
}
101144101216
if( p->pOffset ){
101145101217
p->iOffset = iOffset = ++pParse->nMem;
101146101218
pParse->nMem++; /* Allocate an extra register for limit+offset */
101147101219
sqlite3ExprCode(pParse, p->pOffset, iOffset);
101148
- sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset);
101220
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
101149101221
VdbeComment((v, "OFFSET counter"));
101150
- addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset);
101222
+ addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v);
101151101223
sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
101152101224
sqlite3VdbeJumpHere(v, addr1);
101153101225
sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
101154101226
VdbeComment((v, "LIMIT+OFFSET"));
101155
- addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit);
101227
+ addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v);
101156101228
sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
101157101229
sqlite3VdbeJumpHere(v, addr1);
101158101230
}
101159101231
}
101160101232
}
@@ -101333,15 +101405,17 @@
101333101405
101334101406
/* Detach the ORDER BY clause from the compound SELECT */
101335101407
p->pOrderBy = 0;
101336101408
101337101409
/* Store the results of the setup-query in Queue. */
101410
+ pSetup->pNext = 0;
101338101411
rc = sqlite3Select(pParse, pSetup, &destQueue);
101412
+ pSetup->pNext = p;
101339101413
if( rc ) goto end_of_recursive_query;
101340101414
101341101415
/* Find the next row in the Queue and output that row */
101342
- addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak);
101416
+ addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); VdbeCoverage(v);
101343101417
101344101418
/* Transfer the next row in Queue over to Current */
101345101419
sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101346101420
if( pOrderBy ){
101347101421
sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
@@ -101353,11 +101427,14 @@
101353101427
/* Output the single row in Current */
101354101428
addrCont = sqlite3VdbeMakeLabel(v);
101355101429
codeOffset(v, regOffset, addrCont);
101356101430
selectInnerLoop(pParse, p, p->pEList, iCurrent,
101357101431
0, 0, pDest, addrCont, addrBreak);
101358
- if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101432
+ if( regLimit ){
101433
+ sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101434
+ VdbeCoverage(v);
101435
+ }
101359101436
sqlite3VdbeResolveLabel(v, addrCont);
101360101437
101361101438
/* Execute the recursive SELECT taking the single row in Current as
101362101439
** the value for the recursive-table. Store the results in the Queue.
101363101440
*/
@@ -101438,12 +101515,10 @@
101438101515
*/
101439101516
assert( p && p->pPrior ); /* Calling function guarantees this much */
101440101517
assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
101441101518
db = pParse->db;
101442101519
pPrior = p->pPrior;
101443
- assert( pPrior->pRightmost!=pPrior );
101444
- assert( pPrior->pRightmost==p->pRightmost );
101445101520
dest = *pDest;
101446101521
if( pPrior->pOrderBy ){
101447101522
sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
101448101523
selectOpName(p->op));
101449101524
rc = 1;
@@ -101515,11 +101590,11 @@
101515101590
}
101516101591
p->pPrior = 0;
101517101592
p->iLimit = pPrior->iLimit;
101518101593
p->iOffset = pPrior->iOffset;
101519101594
if( p->iLimit ){
101520
- addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit);
101595
+ addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v);
101521101596
VdbeComment((v, "Jump ahead if LIMIT reached"));
101522101597
}
101523101598
explainSetInteger(iSub2, pParse->iNextSelectId);
101524101599
rc = sqlite3Select(pParse, p, &dest);
101525101600
testcase( rc!=SQLITE_OK );
@@ -101547,16 +101622,14 @@
101547101622
SelectDest uniondest;
101548101623
101549101624
testcase( p->op==TK_EXCEPT );
101550101625
testcase( p->op==TK_UNION );
101551101626
priorOp = SRT_Union;
101552
- if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){
101627
+ if( dest.eDest==priorOp ){
101553101628
/* We can reuse a temporary table generated by a SELECT to our
101554101629
** right.
101555101630
*/
101556
- assert( p->pRightmost!=p ); /* Can only happen for leftward elements
101557
- ** of a 3-way or more compound */
101558101631
assert( p->pLimit==0 ); /* Not allowed on leftward elements */
101559101632
assert( p->pOffset==0 ); /* Not allowed on leftward elements */
101560101633
unionTab = dest.iSDParm;
101561101634
}else{
101562101635
/* We will need to create our own temporary table to hold the
@@ -101565,11 +101638,11 @@
101565101638
unionTab = pParse->nTab++;
101566101639
assert( p->pOrderBy==0 );
101567101640
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
101568101641
assert( p->addrOpenEphm[0] == -1 );
101569101642
p->addrOpenEphm[0] = addr;
101570
- p->pRightmost->selFlags |= SF_UsesEphemeral;
101643
+ findRightmost(p)->selFlags |= SF_UsesEphemeral;
101571101644
assert( p->pEList );
101572101645
}
101573101646
101574101647
/* Code the SELECT statements to our left
101575101648
*/
@@ -101624,16 +101697,16 @@
101624101697
generateColumnNames(pParse, 0, pFirst->pEList);
101625101698
}
101626101699
iBreak = sqlite3VdbeMakeLabel(v);
101627101700
iCont = sqlite3VdbeMakeLabel(v);
101628101701
computeLimitRegisters(pParse, p, iBreak);
101629
- sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
101702
+ sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
101630101703
iStart = sqlite3VdbeCurrentAddr(v);
101631101704
selectInnerLoop(pParse, p, p->pEList, unionTab,
101632101705
0, 0, &dest, iCont, iBreak);
101633101706
sqlite3VdbeResolveLabel(v, iCont);
101634
- sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
101707
+ sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
101635101708
sqlite3VdbeResolveLabel(v, iBreak);
101636101709
sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
101637101710
}
101638101711
break;
101639101712
}
@@ -101654,11 +101727,11 @@
101654101727
assert( p->pOrderBy==0 );
101655101728
101656101729
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
101657101730
assert( p->addrOpenEphm[0] == -1 );
101658101731
p->addrOpenEphm[0] = addr;
101659
- p->pRightmost->selFlags |= SF_UsesEphemeral;
101732
+ findRightmost(p)->selFlags |= SF_UsesEphemeral;
101660101733
assert( p->pEList );
101661101734
101662101735
/* Code the SELECTs to our left into temporary table "tab1".
101663101736
*/
101664101737
sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1);
@@ -101699,19 +101772,19 @@
101699101772
generateColumnNames(pParse, 0, pFirst->pEList);
101700101773
}
101701101774
iBreak = sqlite3VdbeMakeLabel(v);
101702101775
iCont = sqlite3VdbeMakeLabel(v);
101703101776
computeLimitRegisters(pParse, p, iBreak);
101704
- sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
101777
+ sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
101705101778
r1 = sqlite3GetTempReg(pParse);
101706101779
iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101707
- sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
101780
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
101708101781
sqlite3ReleaseTempReg(pParse, r1);
101709101782
selectInnerLoop(pParse, p, p->pEList, tab1,
101710101783
0, 0, &dest, iCont, iBreak);
101711101784
sqlite3VdbeResolveLabel(v, iCont);
101712
- sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
101785
+ sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
101713101786
sqlite3VdbeResolveLabel(v, iBreak);
101714101787
sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
101715101788
sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
101716101789
break;
101717101790
}
@@ -101733,11 +101806,11 @@
101733101806
KeyInfo *pKeyInfo; /* Collating sequence for the result set */
101734101807
Select *pLoop; /* For looping through SELECT statements */
101735101808
CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
101736101809
int nCol; /* Number of columns in result set */
101737101810
101738
- assert( p->pRightmost==p );
101811
+ assert( p->pNext==0 );
101739101812
nCol = p->pEList->nExpr;
101740101813
pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
101741101814
if( !pKeyInfo ){
101742101815
rc = SQLITE_NOMEM;
101743101816
goto multi_select_end;
@@ -101814,14 +101887,14 @@
101814101887
101815101888
/* Suppress duplicates for UNION, EXCEPT, and INTERSECT
101816101889
*/
101817101890
if( regPrev ){
101818101891
int j1, j2;
101819
- j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
101892
+ j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
101820101893
j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
101821101894
(char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
101822
- sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
101895
+ sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); VdbeCoverage(v);
101823101896
sqlite3VdbeJumpHere(v, j1);
101824101897
sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
101825101898
sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
101826101899
}
101827101900
if( pParse->db->mallocFailed ) return 0;
@@ -101918,11 +101991,11 @@
101918101991
}
101919101992
101920101993
/* Jump to the end of the loop if the LIMIT is reached.
101921101994
*/
101922101995
if( p->iLimit ){
101923
- sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
101996
+ sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
101924101997
}
101925101998
101926101999
/* Generate the subroutine return
101927102000
*/
101928102001
sqlite3VdbeResolveLabel(v, iContinue);
@@ -102026,20 +102099,19 @@
102026102099
Select *pPrior; /* Another SELECT immediately to our left */
102027102100
Vdbe *v; /* Generate code to this VDBE */
102028102101
SelectDest destA; /* Destination for coroutine A */
102029102102
SelectDest destB; /* Destination for coroutine B */
102030102103
int regAddrA; /* Address register for select-A coroutine */
102031
- int regEofA; /* Flag to indicate when select-A is complete */
102032102104
int regAddrB; /* Address register for select-B coroutine */
102033
- int regEofB; /* Flag to indicate when select-B is complete */
102034102105
int addrSelectA; /* Address of the select-A coroutine */
102035102106
int addrSelectB; /* Address of the select-B coroutine */
102036102107
int regOutA; /* Address register for the output-A subroutine */
102037102108
int regOutB; /* Address register for the output-B subroutine */
102038102109
int addrOutA; /* Address of the output-A subroutine */
102039102110
int addrOutB = 0; /* Address of the output-B subroutine */
102040102111
int addrEofA; /* Address of the select-A-exhausted subroutine */
102112
+ int addrEofA_noB; /* Alternate addrEofA if B is uninitialized */
102041102113
int addrEofB; /* Address of the select-B-exhausted subroutine */
102042102114
int addrAltB; /* Address of the A<B subroutine */
102043102115
int addrAeqB; /* Address of the A==B subroutine */
102044102116
int addrAgtB; /* Address of the A>B subroutine */
102045102117
int regLimitA; /* Limit register for select-A */
@@ -102150,10 +102222,11 @@
102150102222
}
102151102223
102152102224
/* Separate the left and the right query from one another
102153102225
*/
102154102226
p->pPrior = 0;
102227
+ pPrior->pNext = 0;
102155102228
sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
102156102229
if( pPrior->pPrior==0 ){
102157102230
sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
102158102231
}
102159102232
@@ -102172,52 +102245,43 @@
102172102245
p->pLimit = 0;
102173102246
sqlite3ExprDelete(db, p->pOffset);
102174102247
p->pOffset = 0;
102175102248
102176102249
regAddrA = ++pParse->nMem;
102177
- regEofA = ++pParse->nMem;
102178102250
regAddrB = ++pParse->nMem;
102179
- regEofB = ++pParse->nMem;
102180102251
regOutA = ++pParse->nMem;
102181102252
regOutB = ++pParse->nMem;
102182102253
sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
102183102254
sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
102184
-
102185
- /* Jump past the various subroutines and coroutines to the main
102186
- ** merge loop
102187
- */
102188
- j1 = sqlite3VdbeAddOp0(v, OP_Goto);
102189
- addrSelectA = sqlite3VdbeCurrentAddr(v);
102190
-
102191102255
102192102256
/* Generate a coroutine to evaluate the SELECT statement to the
102193102257
** left of the compound operator - the "A" select.
102194102258
*/
102195
- VdbeNoopComment((v, "Begin coroutine for left SELECT"));
102259
+ addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
102260
+ j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
102261
+ VdbeComment((v, "left SELECT"));
102196102262
pPrior->iLimit = regLimitA;
102197102263
explainSetInteger(iSub1, pParse->iNextSelectId);
102198102264
sqlite3Select(pParse, pPrior, &destA);
102199
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofA);
102200
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102201
- VdbeNoopComment((v, "End coroutine for left SELECT"));
102265
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrA);
102266
+ sqlite3VdbeJumpHere(v, j1);
102202102267
102203102268
/* Generate a coroutine to evaluate the SELECT statement on
102204102269
** the right - the "B" select
102205102270
*/
102206
- addrSelectB = sqlite3VdbeCurrentAddr(v);
102207
- VdbeNoopComment((v, "Begin coroutine for right SELECT"));
102271
+ addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
102272
+ j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
102273
+ VdbeComment((v, "right SELECT"));
102208102274
savedLimit = p->iLimit;
102209102275
savedOffset = p->iOffset;
102210102276
p->iLimit = regLimitB;
102211102277
p->iOffset = 0;
102212102278
explainSetInteger(iSub2, pParse->iNextSelectId);
102213102279
sqlite3Select(pParse, p, &destB);
102214102280
p->iLimit = savedLimit;
102215102281
p->iOffset = savedOffset;
102216
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofB);
102217
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102218
- VdbeNoopComment((v, "End coroutine for right SELECT"));
102282
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrB);
102219102283
102220102284
/* Generate a subroutine that outputs the current row of the A
102221102285
** select as the next output row of the compound select.
102222102286
*/
102223102287
VdbeNoopComment((v, "Output routine for A"));
@@ -102237,17 +102301,17 @@
102237102301
sqlite3KeyInfoUnref(pKeyDup);
102238102302
102239102303
/* Generate a subroutine to run when the results from select A
102240102304
** are exhausted and only data in select B remains.
102241102305
*/
102242
- VdbeNoopComment((v, "eof-A subroutine"));
102243102306
if( op==TK_EXCEPT || op==TK_INTERSECT ){
102244
- addrEofA = sqlite3VdbeAddOp2(v, OP_Goto, 0, labelEnd);
102307
+ addrEofA_noB = addrEofA = labelEnd;
102245102308
}else{
102246
- addrEofA = sqlite3VdbeAddOp2(v, OP_If, regEofB, labelEnd);
102247
- sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102248
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102309
+ VdbeNoopComment((v, "eof-A subroutine"));
102310
+ addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102311
+ addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
102312
+ VdbeCoverage(v);
102249102313
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
102250102314
p->nSelectRow += pPrior->nSelectRow;
102251102315
}
102252102316
102253102317
/* Generate a subroutine to run when the results from select B
@@ -102256,22 +102320,20 @@
102256102320
if( op==TK_INTERSECT ){
102257102321
addrEofB = addrEofA;
102258102322
if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
102259102323
}else{
102260102324
VdbeNoopComment((v, "eof-B subroutine"));
102261
- addrEofB = sqlite3VdbeAddOp2(v, OP_If, regEofA, labelEnd);
102262
- sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102263
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102325
+ addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102326
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
102264102327
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
102265102328
}
102266102329
102267102330
/* Generate code to handle the case of A<B
102268102331
*/
102269102332
VdbeNoopComment((v, "A-lt-B subroutine"));
102270102333
addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102271
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102272
- sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102334
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
102273102335
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102274102336
102275102337
/* Generate code to handle the case of A==B
102276102338
*/
102277102339
if( op==TK_ALL ){
@@ -102280,12 +102342,11 @@
102280102342
addrAeqB = addrAltB;
102281102343
addrAltB++;
102282102344
}else{
102283102345
VdbeNoopComment((v, "A-eq-B subroutine"));
102284102346
addrAeqB =
102285
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102286
- sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102347
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
102287102348
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102288102349
}
102289102350
102290102351
/* Generate code to handle the case of A>B
102291102352
*/
@@ -102292,32 +102353,27 @@
102292102353
VdbeNoopComment((v, "A-gt-B subroutine"));
102293102354
addrAgtB = sqlite3VdbeCurrentAddr(v);
102294102355
if( op==TK_ALL || op==TK_UNION ){
102295102356
sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102296102357
}
102297
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102298
- sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102358
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
102299102359
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102300102360
102301102361
/* This code runs once to initialize everything.
102302102362
*/
102303102363
sqlite3VdbeJumpHere(v, j1);
102304
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofA);
102305
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofB);
102306
- sqlite3VdbeAddOp2(v, OP_Gosub, regAddrA, addrSelectA);
102307
- sqlite3VdbeAddOp2(v, OP_Gosub, regAddrB, addrSelectB);
102308
- sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102309
- sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102364
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
102365
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
102310102366
102311102367
/* Implement the main merge loop
102312102368
*/
102313102369
sqlite3VdbeResolveLabel(v, labelCmpr);
102314102370
sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
102315102371
sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
102316102372
(char*)pKeyMerge, P4_KEYINFO);
102317102373
sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
102318
- sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
102374
+ sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
102319102375
102320102376
/* Jump to the this point in order to terminate the query.
102321102377
*/
102322102378
sqlite3VdbeResolveLabel(v, labelEnd);
102323102379
@@ -102333,10 +102389,11 @@
102333102389
** by the calling function */
102334102390
if( p->pPrior ){
102335102391
sqlite3SelectDelete(db, p->pPrior);
102336102392
}
102337102393
p->pPrior = pPrior;
102394
+ pPrior->pNext = p;
102338102395
102339102396
/*** TBD: Insert subroutine calls to close cursors on incomplete
102340102397
**** subqueries ****/
102341102398
explainComposite(pParse, p->op, iSub1, iSub2, 0);
102342102399
return SQLITE_OK;
@@ -102598,11 +102655,11 @@
102598102655
** because they could be computed at compile-time. But when LIMIT and OFFSET
102599102656
** became arbitrary expressions, we were forced to add restrictions (13)
102600102657
** and (14). */
102601102658
if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
102602102659
if( pSub->pOffset ) return 0; /* Restriction (14) */
102603
- if( p->pRightmost && pSub->pLimit ){
102660
+ if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
102604102661
return 0; /* Restriction (15) */
102605102662
}
102606102663
if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
102607102664
if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (5) */
102608102665
if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){
@@ -102749,18 +102806,18 @@
102749102806
p->pOffset = pOffset;
102750102807
p->pLimit = pLimit;
102751102808
p->pOrderBy = pOrderBy;
102752102809
p->pSrc = pSrc;
102753102810
p->op = TK_ALL;
102754
- p->pRightmost = 0;
102755102811
if( pNew==0 ){
102756
- pNew = pPrior;
102812
+ p->pPrior = pPrior;
102757102813
}else{
102758102814
pNew->pPrior = pPrior;
102759
- pNew->pRightmost = 0;
102815
+ if( pPrior ) pPrior->pNext = pNew;
102816
+ pNew->pNext = p;
102817
+ p->pPrior = pNew;
102760102818
}
102761
- p->pPrior = pNew;
102762102819
if( db->mallocFailed ) return 1;
102763102820
}
102764102821
102765102822
/* Begin flattening the iFrom-th entry of the FROM clause
102766102823
** in the outer query.
@@ -103095,10 +103152,14 @@
103095103152
p->pWhere = 0;
103096103153
pNew->pGroupBy = 0;
103097103154
pNew->pHaving = 0;
103098103155
pNew->pOrderBy = 0;
103099103156
p->pPrior = 0;
103157
+ p->pNext = 0;
103158
+ p->selFlags &= ~SF_Compound;
103159
+ assert( pNew->pPrior!=0 );
103160
+ pNew->pPrior->pNext = pNew;
103100103161
pNew->pLimit = 0;
103101103162
pNew->pOffset = 0;
103102103163
return WRC_Continue;
103103103164
}
103104103165
@@ -103282,13 +103343,14 @@
103282103343
** sqlite3SelectExpand() when walking a SELECT tree to resolve table
103283103344
** names and other FROM clause elements.
103284103345
*/
103285103346
static void selectPopWith(Walker *pWalker, Select *p){
103286103347
Parse *pParse = pWalker->pParse;
103287
- if( p->pWith ){
103288
- assert( pParse->pWith==p->pWith );
103289
- pParse->pWith = p->pWith->pOuter;
103348
+ With *pWith = findRightmost(p)->pWith;
103349
+ if( pWith!=0 ){
103350
+ assert( pParse->pWith==pWith );
103351
+ pParse->pWith = pWith->pOuter;
103290103352
}
103291103353
}
103292103354
#else
103293103355
#define selectPopWith 0
103294103356
#endif
@@ -103334,11 +103396,11 @@
103334103396
if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
103335103397
return WRC_Prune;
103336103398
}
103337103399
pTabList = p->pSrc;
103338103400
pEList = p->pEList;
103339
- sqlite3WithPush(pParse, p->pWith, 0);
103401
+ sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
103340103402
103341103403
/* Make sure cursor numbers have been assigned to all entries in
103342103404
** the FROM clause of the SELECT statement.
103343103405
*/
103344103406
sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -103847,11 +103909,11 @@
103847103909
**
103848103910
** Another solution would be to change the OP_SCopy used to copy cached
103849103911
** values to an OP_Copy.
103850103912
*/
103851103913
if( regHit ){
103852
- addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit);
103914
+ addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
103853103915
}
103854103916
sqlite3ExprCacheClear(pParse);
103855103917
for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
103856103918
sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
103857103919
}
@@ -104006,46 +104068,28 @@
104006104068
if( isAggSub ){
104007104069
isAgg = 1;
104008104070
p->selFlags |= SF_Aggregate;
104009104071
}
104010104072
i = -1;
104011
- }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0
104012
- && OptimizationEnabled(db, SQLITE_SubqCoroutine)
104073
+ }else if( pTabList->nSrc==1
104074
+ && OptimizationEnabled(db, SQLITE_SubqCoroutine)
104013104075
){
104014104076
/* Implement a co-routine that will return a single row of the result
104015104077
** set on each invocation.
104016104078
*/
104017
- int addrTop;
104018
- int addrEof;
104079
+ int addrTop = sqlite3VdbeCurrentAddr(v)+1;
104019104080
pItem->regReturn = ++pParse->nMem;
104020
- addrEof = ++pParse->nMem;
104021
- /* Before coding the OP_Goto to jump to the start of the main routine,
104022
- ** ensure that the jump to the verify-schema routine has already
104023
- ** been coded. Otherwise, the verify-schema would likely be coded as
104024
- ** part of the co-routine. If the main routine then accessed the
104025
- ** database before invoking the co-routine for the first time (for
104026
- ** example to initialize a LIMIT register from a sub-select), it would
104027
- ** be doing so without having verified the schema version and obtained
104028
- ** the required db locks. See ticket d6b36be38. */
104029
- sqlite3CodeVerifySchema(pParse, -1);
104030
- sqlite3VdbeAddOp0(v, OP_Goto);
104031
- addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor);
104032
- sqlite3VdbeChangeP5(v, 1);
104033
- VdbeComment((v, "coroutine for %s", pItem->pTab->zName));
104081
+ sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
104082
+ VdbeComment((v, "%s", pItem->pTab->zName));
104034104083
pItem->addrFillSub = addrTop;
104035
- sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof);
104036
- sqlite3VdbeChangeP5(v, 1);
104037104084
sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
104038104085
explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104039104086
sqlite3Select(pParse, pSub, &dest);
104040104087
pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
104041104088
pItem->viaCoroutine = 1;
104042
- sqlite3VdbeChangeP2(v, addrTop, dest.iSdst);
104043
- sqlite3VdbeChangeP3(v, addrTop, dest.nSdst);
104044
- sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof);
104045
- sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn);
104046
- VdbeComment((v, "end %s", pItem->pTab->zName));
104089
+ pItem->regResult = dest.iSdst;
104090
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
104047104091
sqlite3VdbeJumpHere(v, addrTop-1);
104048104092
sqlite3ClearTempRegCache(pParse);
104049104093
}else{
104050104094
/* Generate a subroutine that will fill an ephemeral table with
104051104095
** the content of this subquery. pItem->addrFillSub will point
@@ -104057,16 +104101,18 @@
104057104101
int retAddr;
104058104102
assert( pItem->addrFillSub==0 );
104059104103
pItem->regReturn = ++pParse->nMem;
104060104104
topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
104061104105
pItem->addrFillSub = topAddr+1;
104062
- VdbeNoopComment((v, "materialize %s", pItem->pTab->zName));
104063104106
if( pItem->isCorrelated==0 ){
104064104107
/* If the subquery is not correlated and if we are not inside of
104065104108
** a trigger, then we only need to compute the value of the subquery
104066104109
** once. */
104067
- onceAddr = sqlite3CodeOnce(pParse);
104110
+ onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
104111
+ VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
104112
+ }else{
104113
+ VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
104068104114
}
104069104115
sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
104070104116
explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104071104117
sqlite3Select(pParse, pSub, &dest);
104072104118
pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
@@ -104094,25 +104140,10 @@
104094104140
104095104141
#ifndef SQLITE_OMIT_COMPOUND_SELECT
104096104142
/* If there is are a sequence of queries, do the earlier ones first.
104097104143
*/
104098104144
if( p->pPrior ){
104099
- if( p->pRightmost==0 ){
104100
- Select *pLoop, *pRight = 0;
104101
- int cnt = 0;
104102
- int mxSelect;
104103
- for(pLoop=p; pLoop; pLoop=pLoop->pPrior, cnt++){
104104
- pLoop->pRightmost = p;
104105
- pLoop->pNext = pRight;
104106
- pRight = pLoop;
104107
- }
104108
- mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
104109
- if( mxSelect && cnt>mxSelect ){
104110
- sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
104111
- goto select_end;
104112
- }
104113
- }
104114104145
rc = multiSelect(pParse, p, pDest);
104115104146
explainSetInteger(pParse->iSelectId, iRestoreSelectId);
104116104147
return rc;
104117104148
}
104118104149
#endif
@@ -104412,11 +104443,11 @@
104412104443
sqlite3WhereEnd(pWInfo);
104413104444
sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
104414104445
sortOut = sqlite3GetTempReg(pParse);
104415104446
sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
104416104447
sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
104417
- VdbeComment((v, "GROUP BY sort"));
104448
+ VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
104418104449
sAggInfo.useSortingIdx = 1;
104419104450
sqlite3ExprCacheClear(pParse);
104420104451
}
104421104452
104422104453
/* Evaluate the current GROUP BY terms and store in b0, b1, b2...
@@ -104439,11 +104470,11 @@
104439104470
}
104440104471
}
104441104472
sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
104442104473
(char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
104443104474
j1 = sqlite3VdbeCurrentAddr(v);
104444
- sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
104475
+ sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); VdbeCoverage(v);
104445104476
104446104477
/* Generate code that runs whenever the GROUP BY changes.
104447104478
** Changes in the GROUP BY are detected by the previous code
104448104479
** block. If there were no changes, this block is skipped.
104449104480
**
@@ -104453,11 +104484,11 @@
104453104484
** for the next GROUP BY batch.
104454104485
*/
104455104486
sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
104456104487
sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
104457104488
VdbeComment((v, "output one row"));
104458
- sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd);
104489
+ sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
104459104490
VdbeComment((v, "check abort flag"));
104460104491
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
104461104492
VdbeComment((v, "reset accumulator"));
104462104493
104463104494
/* Update the aggregate accumulators based on the content of
@@ -104470,10 +104501,11 @@
104470104501
104471104502
/* End of the loop
104472104503
*/
104473104504
if( groupBySort ){
104474104505
sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
104506
+ VdbeCoverage(v);
104475104507
}else{
104476104508
sqlite3WhereEnd(pWInfo);
104477104509
sqlite3VdbeChangeToNoop(v, addrSortingIdx);
104478104510
}
104479104511
@@ -104497,11 +104529,11 @@
104497104529
sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
104498104530
VdbeComment((v, "set abort flag"));
104499104531
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104500104532
sqlite3VdbeResolveLabel(v, addrOutputRow);
104501104533
addrOutputRow = sqlite3VdbeCurrentAddr(v);
104502
- sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
104534
+ sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); VdbeCoverage(v);
104503104535
VdbeComment((v, "Groupby result generator entry point"));
104504104536
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104505104537
finalizeAggFunctions(pParse, &sAggInfo);
104506104538
sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104507104539
selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
@@ -104770,14 +104802,10 @@
104770104802
SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
104771104803
if( p==0 ){
104772104804
sqlite3ExplainPrintf(pVdbe, "(null-select)");
104773104805
return;
104774104806
}
104775
- while( p->pPrior ){
104776
- p->pPrior->pNext = p;
104777
- p = p->pPrior;
104778
- }
104779104807
sqlite3ExplainPush(pVdbe);
104780104808
while( p ){
104781104809
explainOneSelect(pVdbe, p);
104782104810
p = p->pNext;
104783104811
if( p==0 ) break;
@@ -105558,10 +105586,11 @@
105558105586
/* Generate code to destroy the database record of the trigger.
105559105587
*/
105560105588
assert( pTable!=0 );
105561105589
if( (v = sqlite3GetVdbe(pParse))!=0 ){
105562105590
int base;
105591
+ static const int iLn = __LINE__+2;
105563105592
static const VdbeOpList dropTrigger[] = {
105564105593
{ OP_Rewind, 0, ADDR(9), 0},
105565105594
{ OP_String8, 0, 1, 0}, /* 1 */
105566105595
{ OP_Column, 0, 1, 2},
105567105596
{ OP_Ne, 2, ADDR(8), 1},
@@ -105572,11 +105601,11 @@
105572105601
{ OP_Next, 0, ADDR(1), 0}, /* 8 */
105573105602
};
105574105603
105575105604
sqlite3BeginWriteOperation(pParse, 0, iDb);
105576105605
sqlite3OpenMasterTable(pParse, iDb);
105577
- base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
105606
+ base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger, iLn);
105578105607
sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
105579105608
sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
105580105609
sqlite3ChangeCookie(pParse, iDb);
105581105610
sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
105582105611
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
@@ -105718,19 +105747,11 @@
105718105747
**
105719105748
** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
105720105749
** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
105721105750
*/
105722105751
pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
105723
-
105724
- /* Clear the cookieGoto flag. When coding triggers, the cookieGoto
105725
- ** variable is used as a flag to indicate to sqlite3ExprCodeConstants()
105726
- ** that it is not safe to refactor constants (this happens after the
105727
- ** start of the first loop in the SQL statement is coded - at that
105728
- ** point code may be conditionally executed, so it is no longer safe to
105729
- ** initialize constant register values). */
105730
- assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 );
105731
- pParse->cookieGoto = 0;
105752
+ assert( pParse->okConstFactor==0 );
105732105753
105733105754
switch( pStep->op ){
105734105755
case TK_UPDATE: {
105735105756
sqlite3Update(pParse,
105736105757
targetSrcList(pParse, pStep),
@@ -106515,11 +106536,11 @@
106515106536
sqlite3VdbeChangeToNoop(v, addrOpen);
106516106537
nKey = nPk;
106517106538
regKey = iPk;
106518106539
}else{
106519106540
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106520
- sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
106541
+ sqlite3IndexAffinityStr(v, pPk), nPk);
106521106542
sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106522106543
}
106523106544
sqlite3WhereEnd(pWInfo);
106524106545
}
106525106546
@@ -106559,32 +106580,37 @@
106559106580
/* Top of the update loop */
106560106581
if( okOnePass ){
106561106582
if( aToOpen[iDataCur-iBaseCur] ){
106562106583
assert( pPk!=0 );
106563106584
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
106585
+ VdbeCoverageNeverTaken(v);
106564106586
}
106565106587
labelContinue = labelBreak;
106566106588
sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106589
+ VdbeCoverage(v);
106567106590
}else if( pPk ){
106568106591
labelContinue = sqlite3VdbeMakeLabel(v);
106569
- sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
106592
+ sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
106570106593
addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106571106594
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
106595
+ VdbeCoverage(v);
106572106596
}else{
106573106597
labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106574106598
regOldRowid);
106599
+ VdbeCoverage(v);
106575106600
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106601
+ VdbeCoverage(v);
106576106602
}
106577106603
106578106604
/* If the record number will change, set register regNewRowid to
106579106605
** contain the new value. If the record number is not being modified,
106580106606
** then regNewRowid is the same register as regOldRowid, which is
106581106607
** already populated. */
106582106608
assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
106583106609
if( chngRowid ){
106584106610
sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
106585
- sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
106611
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
106586106612
}
106587106613
106588106614
/* Compute the old pre-UPDATE content of the row being changed, if that
106589106615
** information is needed */
106590106616
if( chngPk || hasFK || pTrigger ){
@@ -106649,12 +106675,11 @@
106649106675
106650106676
/* Fire any BEFORE UPDATE triggers. This happens before constraints are
106651106677
** verified. One could argue that this is wrong.
106652106678
*/
106653106679
if( tmask&TRIGGER_BEFORE ){
106654
- sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
106655
- sqlite3TableAffinityStr(v, pTab);
106680
+ sqlite3TableAffinity(v, pTab, regNew);
106656106681
sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106657106682
TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
106658106683
106659106684
/* The row-trigger may have deleted the row being updated. In this
106660106685
** case, jump to the next row. No updates or AFTER triggers are
@@ -106662,12 +106687,14 @@
106662106687
** is deleted or renamed by a BEFORE trigger - is left undefined in the
106663106688
** documentation.
106664106689
*/
106665106690
if( pPk ){
106666106691
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
106692
+ VdbeCoverage(v);
106667106693
}else{
106668106694
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106695
+ VdbeCoverage(v);
106669106696
}
106670106697
106671106698
/* If it did not delete it, the row-trigger may still have modified
106672106699
** some of the columns of the row being updated. Load the values for
106673106700
** all columns not modified by the update statement into their
@@ -106699,10 +106726,11 @@
106699106726
if( pPk ){
106700106727
j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106701106728
}else{
106702106729
j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106703106730
}
106731
+ VdbeCoverageNeverTaken(v);
106704106732
}
106705106733
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
106706106734
106707106735
/* If changing the record number, delete the old record. */
106708106736
if( hasFK || chngKey || pPk!=0 ){
@@ -106742,11 +106770,11 @@
106742106770
*/
106743106771
if( okOnePass ){
106744106772
/* Nothing to do at end-of-loop for a single-pass */
106745106773
}else if( pPk ){
106746106774
sqlite3VdbeResolveLabel(v, labelContinue);
106747
- sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop);
106775
+ sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
106748106776
}else{
106749106777
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106750106778
}
106751106779
sqlite3VdbeResolveLabel(v, labelBreak);
106752106780
@@ -106871,21 +106899,21 @@
106871106899
sqlite3Select(pParse, pSelect, &dest);
106872106900
106873106901
/* Generate code to scan the ephemeral table and call VUpdate. */
106874106902
iReg = ++pParse->nMem;
106875106903
pParse->nMem += pTab->nCol+1;
106876
- addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);
106904
+ addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); VdbeCoverage(v);
106877106905
sqlite3VdbeAddOp3(v, OP_Column, ephemTab, 0, iReg);
106878106906
sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
106879106907
for(i=0; i<pTab->nCol; i++){
106880106908
sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
106881106909
}
106882106910
sqlite3VtabMakeWritable(pParse, pTab);
106883106911
sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
106884106912
sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
106885106913
sqlite3MayAbort(pParse);
106886
- sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
106914
+ sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);
106887106915
sqlite3VdbeJumpHere(v, addr);
106888106916
sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
106889106917
106890106918
/* Cleanup */
106891106919
sqlite3SelectDelete(db, pSelect);
@@ -108453,11 +108481,11 @@
108453108481
int addrSkip; /* Jump here for next iteration of skip-scan */
108454108482
int addrCont; /* Jump here to continue with the next loop cycle */
108455108483
int addrFirst; /* First instruction of interior of the loop */
108456108484
int addrBody; /* Beginning of the body of this loop */
108457108485
u8 iFrom; /* Which entry in the FROM clause */
108458
- u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
108486
+ u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
108459108487
int p1, p2; /* Operands of the opcode used to ends the loop */
108460108488
union { /* Information that depends on pWLoop->wsFlags */
108461108489
struct {
108462108490
int nIn; /* Number of entries in aInLoop[] */
108463108491
struct InLoop {
@@ -108840,10 +108868,11 @@
108840108868
#define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108841108869
#define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108842108870
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108843108871
#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108844108872
#define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
108873
+#define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
108845108874
108846108875
/************** End of whereInt.h ********************************************/
108847108876
/************** Continuing where we left off in where.c **********************/
108848108877
108849108878
/*
@@ -110426,11 +110455,11 @@
110426110455
110427110456
/* Generate code to skip over the creation and initialization of the
110428110457
** transient index on 2nd and subsequent iterations of the loop. */
110429110458
v = pParse->pVdbe;
110430110459
assert( v!=0 );
110431
- addrInit = sqlite3CodeOnce(pParse);
110460
+ addrInit = sqlite3CodeOnce(pParse); VdbeCoverage(v);
110432110461
110433110462
/* Count the number of columns that will be added to the index
110434110463
** and used to match WHERE clause constraints */
110435110464
nKeyCol = 0;
110436110465
pTable = pSrc->pTab;
@@ -110533,16 +110562,16 @@
110533110562
sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110534110563
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
110535110564
VdbeComment((v, "for %s", pTable->zName));
110536110565
110537110566
/* Fill the automatic index with content */
110538
- addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
110567
+ addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
110539110568
regRecord = sqlite3GetTempReg(pParse);
110540110569
sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
110541110570
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
110542110571
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
110543
- sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
110572
+ sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
110544110573
sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
110545110574
sqlite3VdbeJumpHere(v, addrTop);
110546110575
sqlite3ReleaseTempReg(pParse, regRecord);
110547110576
110548110577
/* Jump here when skipping the initialization */
@@ -111214,10 +111243,12 @@
111214111243
testcase( bRev );
111215111244
bRev = !bRev;
111216111245
}
111217111246
iTab = pX->iTable;
111218111247
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
111248
+ VdbeCoverageIf(v, bRev);
111249
+ VdbeCoverageIf(v, !bRev);
111219111250
assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
111220111251
pLoop->wsFlags |= WHERE_IN_ABLE;
111221111252
if( pLevel->u.in.nIn==0 ){
111222111253
pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
111223111254
}
@@ -111233,11 +111264,11 @@
111233111264
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
111234111265
}else{
111235111266
pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
111236111267
}
111237111268
pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
111238
- sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
111269
+ sqlite3VdbeAddOp1(v, OP_IsNull, iReg); VdbeCoverage(v);
111239111270
}else{
111240111271
pLevel->u.in.nIn = 0;
111241111272
}
111242111273
#endif
111243111274
}
@@ -111328,14 +111359,18 @@
111328111359
}
111329111360
111330111361
if( nSkip ){
111331111362
int iIdxCur = pLevel->iIdxCur;
111332111363
sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
111364
+ VdbeCoverageIf(v, bRev==0);
111365
+ VdbeCoverageIf(v, bRev!=0);
111333111366
VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
111334111367
j = sqlite3VdbeAddOp0(v, OP_Goto);
111335
- pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
111368
+ pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
111336111369
iIdxCur, 0, regBase, nSkip);
111370
+ VdbeCoverageIf(v, bRev==0);
111371
+ VdbeCoverageIf(v, bRev!=0);
111337111372
sqlite3VdbeJumpHere(v, j);
111338111373
for(j=0; j<nSkip; j++){
111339111374
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
111340111375
assert( pIdx->aiColumn[j]>=0 );
111341111376
VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
@@ -111364,11 +111399,14 @@
111364111399
}
111365111400
testcase( pTerm->eOperator & WO_ISNULL );
111366111401
testcase( pTerm->eOperator & WO_IN );
111367111402
if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
111368111403
Expr *pRight = pTerm->pExpr->pRight;
111369
- sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk);
111404
+ if( sqlite3ExprCanBeNull(pRight) ){
111405
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
111406
+ VdbeCoverage(v);
111407
+ }
111370111408
if( zAff ){
111371111409
if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
111372111410
zAff[j] = SQLITE_AFF_NONE;
111373111411
}
111374111412
if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
@@ -111610,14 +111648,14 @@
111610111648
}
111611111649
111612111650
/* Special case of a FROM clause subquery implemented as a co-routine */
111613111651
if( pTabItem->viaCoroutine ){
111614111652
int regYield = pTabItem->regReturn;
111615
- sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield);
111616
- pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
111617
- VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName));
111618
- sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk);
111653
+ sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
111654
+ pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
111655
+ VdbeCoverage(v);
111656
+ VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
111619111657
pLevel->op = OP_Goto;
111620111658
}else
111621111659
111622111660
#ifndef SQLITE_OMIT_VIRTUALTABLE
111623111661
if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -111645,10 +111683,11 @@
111645111683
sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
111646111684
sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
111647111685
sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
111648111686
pLoop->u.vtab.idxStr,
111649111687
pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
111688
+ VdbeCoverage(v);
111650111689
pLoop->u.vtab.needFree = 0;
111651111690
for(j=0; j<nConstraint && j<16; j++){
111652111691
if( (pLoop->u.vtab.omitMask>>j)&1 ){
111653111692
disableTerm(pLevel, pLoop->aLTerm[j]);
111654111693
}
@@ -111668,20 +111707,22 @@
111668111707
** equality comparison against the ROWID field. Or
111669111708
** we reference multiple rows using a "rowid IN (...)"
111670111709
** construct.
111671111710
*/
111672111711
assert( pLoop->u.btree.nEq==1 );
111673
- iReleaseReg = sqlite3GetTempReg(pParse);
111674111712
pTerm = pLoop->aLTerm[0];
111675111713
assert( pTerm!=0 );
111676111714
assert( pTerm->pExpr!=0 );
111677111715
assert( omitTable==0 );
111678111716
testcase( pTerm->wtFlags & TERM_VIRTUAL );
111717
+ iReleaseReg = ++pParse->nMem;
111679111718
iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
111719
+ if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
111680111720
addrNxt = pLevel->addrNxt;
111681
- sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
111721
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); VdbeCoverage(v);
111682111722
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
111723
+ VdbeCoverage(v);
111683111724
sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
111684111725
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111685111726
VdbeComment((v, "pk"));
111686111727
pLevel->op = OP_Noop;
111687111728
}else if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -111711,14 +111752,14 @@
111711111752
111712111753
/* The following constant maps TK_xx codes into corresponding
111713111754
** seek opcodes. It depends on a particular ordering of TK_xx
111714111755
*/
111715111756
const u8 aMoveOp[] = {
111716
- /* TK_GT */ OP_SeekGt,
111717
- /* TK_LE */ OP_SeekLe,
111718
- /* TK_LT */ OP_SeekLt,
111719
- /* TK_GE */ OP_SeekGe
111757
+ /* TK_GT */ OP_SeekGT,
111758
+ /* TK_LE */ OP_SeekLE,
111759
+ /* TK_LT */ OP_SeekLT,
111760
+ /* TK_GE */ OP_SeekGE
111720111761
};
111721111762
assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
111722111763
assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
111723111764
assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
111724111765
@@ -111728,15 +111769,21 @@
111728111769
assert( pX!=0 );
111729111770
testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
111730111771
r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
111731111772
sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
111732111773
VdbeComment((v, "pk"));
111774
+ VdbeCoverageIf(v, pX->op==TK_GT);
111775
+ VdbeCoverageIf(v, pX->op==TK_LE);
111776
+ VdbeCoverageIf(v, pX->op==TK_LT);
111777
+ VdbeCoverageIf(v, pX->op==TK_GE);
111733111778
sqlite3ExprCacheAffinityChange(pParse, r1, 1);
111734111779
sqlite3ReleaseTempReg(pParse, rTemp);
111735111780
disableTerm(pLevel, pStart);
111736111781
}else{
111737111782
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
111783
+ VdbeCoverageIf(v, bRev==0);
111784
+ VdbeCoverageIf(v, bRev!=0);
111738111785
}
111739111786
if( pEnd ){
111740111787
Expr *pX;
111741111788
pX = pEnd->pExpr;
111742111789
assert( pX!=0 );
@@ -111756,14 +111803,18 @@
111756111803
pLevel->op = bRev ? OP_Prev : OP_Next;
111757111804
pLevel->p1 = iCur;
111758111805
pLevel->p2 = start;
111759111806
assert( pLevel->p5==0 );
111760111807
if( testOp!=OP_Noop ){
111761
- iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
111808
+ iRowidReg = ++pParse->nMem;
111762111809
sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
111763111810
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111764111811
sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
111812
+ VdbeCoverageIf(v, testOp==OP_Le);
111813
+ VdbeCoverageIf(v, testOp==OP_Lt);
111814
+ VdbeCoverageIf(v, testOp==OP_Ge);
111815
+ VdbeCoverageIf(v, testOp==OP_Gt);
111765111816
sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
111766111817
}
111767111818
}else if( pLoop->wsFlags & WHERE_INDEXED ){
111768111819
/* Case 4: A scan using an index.
111769111820
**
@@ -111799,24 +111850,23 @@
111799111850
static const u8 aStartOp[] = {
111800111851
0,
111801111852
0,
111802111853
OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
111803111854
OP_Last, /* 3: (!start_constraints && startEq && bRev) */
111804
- OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
111805
- OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
111806
- OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
111807
- OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
111855
+ OP_SeekGT, /* 4: (start_constraints && !startEq && !bRev) */
111856
+ OP_SeekLT, /* 5: (start_constraints && !startEq && bRev) */
111857
+ OP_SeekGE, /* 6: (start_constraints && startEq && !bRev) */
111858
+ OP_SeekLE /* 7: (start_constraints && startEq && bRev) */
111808111859
};
111809111860
static const u8 aEndOp[] = {
111810
- OP_Noop, /* 0: (!end_constraints) */
111811
- OP_IdxGE, /* 1: (end_constraints && !bRev) */
111812
- OP_IdxLT /* 2: (end_constraints && bRev) */
111861
+ OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
111862
+ OP_IdxGT, /* 1: (end_constraints && !bRev && endEq) */
111863
+ OP_IdxLE, /* 2: (end_constraints && bRev && !endEq) */
111864
+ OP_IdxLT, /* 3: (end_constraints && bRev && endEq) */
111813111865
};
111814111866
u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111815
- int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111816111867
int regBase; /* Base register holding constraint values */
111817
- int r1; /* Temp register */
111818111868
WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111819111869
WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111820111870
int startEq; /* True if range start uses ==, >= or <= */
111821111871
int endEq; /* True if range end uses ==, >= or <= */
111822111872
int start_constraints; /* Start of range is constrained */
@@ -111825,10 +111875,12 @@
111825111875
int iIdxCur; /* The VDBE cursor for the index */
111826111876
int nExtraReg = 0; /* Number of extra registers needed */
111827111877
int op; /* Instruction opcode */
111828111878
char *zStartAff; /* Affinity for start of range constraint */
111829111879
char cEndAff = 0; /* Affinity for end of range constraint */
111880
+ u8 bSeekPastNull = 0; /* True to seek past initial nulls */
111881
+ u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
111830111882
111831111883
pIdx = pLoop->u.btree.pIndex;
111832111884
iIdxCur = pLevel->iIdxCur;
111833111885
assert( nEq>=pLoop->u.btree.nSkip );
111834111886
@@ -111843,11 +111895,11 @@
111843111895
if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111844111896
&& (pWInfo->bOBSat!=0)
111845111897
&& (pIdx->nKeyCol>nEq)
111846111898
){
111847111899
assert( pLoop->u.btree.nSkip==0 );
111848
- isMinQuery = 1;
111900
+ bSeekPastNull = 1;
111849111901
nExtraReg = 1;
111850111902
}
111851111903
111852111904
/* Find any inequality constraint terms for the start and end
111853111905
** of the range.
@@ -111858,10 +111910,17 @@
111858111910
nExtraReg = 1;
111859111911
}
111860111912
if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
111861111913
pRangeEnd = pLoop->aLTerm[j++];
111862111914
nExtraReg = 1;
111915
+ if( pRangeStart==0
111916
+ && (pRangeEnd->wtFlags & TERM_VNULL)==0
111917
+ && (j = pIdx->aiColumn[nEq])>=0
111918
+ && pIdx->pTable->aCol[j].notNull==0
111919
+ ){
111920
+ bSeekPastNull = 1;
111921
+ }
111863111922
}
111864111923
111865111924
/* Generate code to evaluate all constraint terms using == or IN
111866111925
** and store the values of those terms in an array of registers
111867111926
** starting at regBase.
@@ -111877,10 +111936,11 @@
111877111936
*/
111878111937
if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111879111938
|| (bRev && pIdx->nKeyCol==nEq)
111880111939
){
111881111940
SWAP(WhereTerm *, pRangeEnd, pRangeStart);
111941
+ SWAP(u8, bSeekPastNull, bStopAtNull);
111882111942
}
111883111943
111884111944
testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
111885111945
testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
111886111946
testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
@@ -111892,12 +111952,15 @@
111892111952
/* Seek the index cursor to the start of the range. */
111893111953
nConstraint = nEq;
111894111954
if( pRangeStart ){
111895111955
Expr *pRight = pRangeStart->pExpr->pRight;
111896111956
sqlite3ExprCode(pParse, pRight, regBase+nEq);
111897
- if( (pRangeStart->wtFlags & TERM_VNULL)==0 ){
111898
- sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
111957
+ if( (pRangeStart->wtFlags & TERM_VNULL)==0
111958
+ && sqlite3ExprCanBeNull(pRight)
111959
+ ){
111960
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
111961
+ VdbeCoverage(v);
111899111962
}
111900111963
if( zStartAff ){
111901111964
if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){
111902111965
/* Since the comparison is to be performed with no conversions
111903111966
** applied to the operands, set the affinity to apply to pRight to
@@ -111908,86 +111971,76 @@
111908111971
zStartAff[nEq] = SQLITE_AFF_NONE;
111909111972
}
111910111973
}
111911111974
nConstraint++;
111912111975
testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
111913
- }else if( isMinQuery ){
111976
+ }else if( bSeekPastNull ){
111914111977
sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
111915111978
nConstraint++;
111916111979
startEq = 0;
111917111980
start_constraints = 1;
111918111981
}
111919
- codeApplyAffinity(pParse, regBase, nConstraint, zStartAff);
111982
+ codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
111920111983
op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
111921111984
assert( op!=0 );
111922
- testcase( op==OP_Rewind );
111923
- testcase( op==OP_Last );
111924
- testcase( op==OP_SeekGt );
111925
- testcase( op==OP_SeekGe );
111926
- testcase( op==OP_SeekLe );
111927
- testcase( op==OP_SeekLt );
111928111985
sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111986
+ VdbeCoverage(v);
111987
+ VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
111988
+ VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
111989
+ VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
111990
+ VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
111991
+ VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
111992
+ VdbeCoverageIf(v, op==OP_SeekLT); testcase( op==OP_SeekLT );
111929111993
111930111994
/* Load the value for the inequality constraint at the end of the
111931111995
** range (if any).
111932111996
*/
111933111997
nConstraint = nEq;
111934111998
if( pRangeEnd ){
111935111999
Expr *pRight = pRangeEnd->pExpr->pRight;
111936112000
sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111937112001
sqlite3ExprCode(pParse, pRight, regBase+nEq);
111938
- if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111939
- sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
112002
+ if( (pRangeEnd->wtFlags & TERM_VNULL)==0
112003
+ && sqlite3ExprCanBeNull(pRight)
112004
+ ){
112005
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
112006
+ VdbeCoverage(v);
111940112007
}
111941112008
if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
111942112009
&& !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
111943112010
){
111944112011
codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
111945112012
}
111946112013
nConstraint++;
111947112014
testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
112015
+ }else if( bStopAtNull ){
112016
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
112017
+ endEq = 0;
112018
+ nConstraint++;
111948112019
}
111949112020
sqlite3DbFree(db, zStartAff);
111950112021
111951112022
/* Top of the loop body */
111952112023
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111953112024
111954112025
/* Check if the index cursor is past the end of the range. */
111955
- op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
111956
- testcase( op==OP_Noop );
111957
- testcase( op==OP_IdxGE );
111958
- testcase( op==OP_IdxLT );
111959
- if( op!=OP_Noop ){
112026
+ if( nConstraint ){
112027
+ op = aEndOp[bRev*2 + endEq];
111960112028
sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111961
- sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
111962
- }
111963
-
111964
- /* If there are inequality constraints, check that the value
111965
- ** of the table column that the inequality contrains is not NULL.
111966
- ** If it is, jump to the next iteration of the loop.
111967
- */
111968
- r1 = sqlite3GetTempReg(pParse);
111969
- testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111970
- testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111971
- if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111972
- && (j = pIdx->aiColumn[nEq])>=0
111973
- && pIdx->pTable->aCol[j].notNull==0
111974
- && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111975
- ){
111976
- sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111977
- VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111978
- sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111979
- }
111980
- sqlite3ReleaseTempReg(pParse, r1);
112029
+ testcase( op==OP_IdxGT ); VdbeCoverageIf(v, op==OP_IdxGT );
112030
+ testcase( op==OP_IdxGE ); VdbeCoverageIf(v, op==OP_IdxGE );
112031
+ testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT );
112032
+ testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE );
112033
+ }
111981112034
111982112035
/* Seek the table cursor, if required */
111983112036
disableTerm(pLevel, pRangeStart);
111984112037
disableTerm(pLevel, pRangeEnd);
111985112038
if( omitTable ){
111986112039
/* pIdx is a covering index. No need to access the main table. */
111987112040
}else if( HasRowid(pIdx->pTable) ){
111988
- iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
112041
+ iRowidReg = ++pParse->nMem;
111989112042
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
111990112043
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111991112044
sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
111992112045
}else{
111993112046
Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
@@ -111995,11 +112048,11 @@
111995112048
for(j=0; j<pPk->nKeyCol; j++){
111996112049
k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
111997112050
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
111998112051
}
111999112052
sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
112000
- iRowidReg, pPk->nKeyCol);
112053
+ iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
112001112054
}
112002112055
112003112056
/* Record the instruction used to terminate the loop. Disable
112004112057
** WHERE clause terms made redundant by the index range scan.
112005112058
*/
@@ -112009,10 +112062,12 @@
112009112062
pLevel->op = OP_Prev;
112010112063
}else{
112011112064
pLevel->op = OP_Next;
112012112065
}
112013112066
pLevel->p1 = iIdxCur;
112067
+ assert( (WHERE_UNQ_WANTED>>16)==1 );
112068
+ pLevel->p3 = (pLoop->wsFlags>>16)&1;
112014112069
if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
112015112070
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112016112071
}else{
112017112072
assert( pLevel->p5==0 );
112018112073
}
@@ -112177,10 +112232,11 @@
112177112232
int r;
112178112233
r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
112179112234
regRowid, 0);
112180112235
sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
112181112236
sqlite3VdbeCurrentAddr(v)+2, r, iSet);
112237
+ VdbeCoverage(v);
112182112238
}
112183112239
sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
112184112240
112185112241
/* The pSubWInfo->untestedTerms flag means that this OR term
112186112242
** contained one or more AND term from a notReady table. The
@@ -112245,10 +112301,12 @@
112245112301
pLevel->op = OP_Noop;
112246112302
}else{
112247112303
pLevel->op = aStep[bRev];
112248112304
pLevel->p1 = iCur;
112249112305
pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112306
+ VdbeCoverageIf(v, bRev==0);
112307
+ VdbeCoverageIf(v, bRev!=0);
112250112308
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112251112309
}
112252112310
}
112253112311
112254112312
/* Insert code to test every subexpression that can be completely
@@ -112326,11 +112384,10 @@
112326112384
assert( pTerm->pExpr );
112327112385
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
112328112386
pTerm->wtFlags |= TERM_CODED;
112329112387
}
112330112388
}
112331
- sqlite3ReleaseTempReg(pParse, iReleaseReg);
112332112389
112333112390
return pLevel->notReady;
112334112391
}
112335112392
112336112393
#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -112813,16 +112870,17 @@
112813112870
assert(
112814112871
(pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112815112872
|| nInMul==0
112816112873
);
112817112874
pNew->wsFlags |= WHERE_COLUMN_EQ;
112818
- if( iCol<0
112819
- || (pProbe->onError!=OE_None && nInMul==0
112820
- && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112821
- ){
112875
+ if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1)){
112822112876
assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
112823
- pNew->wsFlags |= WHERE_ONEROW;
112877
+ if( iCol>=0 && pProbe->onError==OE_None ){
112878
+ pNew->wsFlags |= WHERE_UNQ_WANTED;
112879
+ }else{
112880
+ pNew->wsFlags |= WHERE_ONEROW;
112881
+ }
112824112882
}
112825112883
pNew->u.btree.nEq++;
112826112884
pNew->nOut = nRowEst + nInMul;
112827112885
}else if( pTerm->eOperator & (WO_ISNULL) ){
112828112886
pNew->wsFlags |= WHERE_COLUMN_NULL;
@@ -113697,13 +113755,16 @@
113697113755
/* Mark off any other ORDER BY terms that reference pLoop */
113698113756
if( isOrderDistinct ){
113699113757
orderDistinctMask |= pLoop->maskSelf;
113700113758
for(i=0; i<nOrderBy; i++){
113701113759
Expr *p;
113760
+ Bitmask mTerm;
113702113761
if( MASKBIT(i) & obSat ) continue;
113703113762
p = pOrderBy->a[i].pExpr;
113704
- if( (exprTableUsage(&pWInfo->sMaskSet, p)&~orderDistinctMask)==0 ){
113763
+ mTerm = exprTableUsage(&pWInfo->sMaskSet,p);
113764
+ if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue;
113765
+ if( (mTerm&~orderDistinctMask)==0 ){
113705113766
obSat |= MASKBIT(i);
113706113767
}
113707113768
}
113708113769
}
113709113770
} /* End the loop over all WhereLoops from outer-most down to inner-most */
@@ -114261,11 +114322,10 @@
114261114322
** subexpression is separated by an AND operator.
114262114323
*/
114263114324
initMaskSet(pMaskSet);
114264114325
whereClauseInit(&pWInfo->sWC, pWInfo);
114265114326
whereSplit(&pWInfo->sWC, pWhere, TK_AND);
114266
- sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
114267114327
114268114328
/* Special case: a WHERE clause that is constant. Evaluate the
114269114329
** expression and either jump over all of the code or fall thru.
114270114330
*/
114271114331
for(ii=0; ii<sWLB.pWC->nTerm; ii++){
@@ -114323,26 +114383,10 @@
114323114383
exprAnalyzeAll(pTabList, &pWInfo->sWC);
114324114384
if( db->mallocFailed ){
114325114385
goto whereBeginError;
114326114386
}
114327114387
114328
- /* If the ORDER BY (or GROUP BY) clause contains references to general
114329
- ** expressions, then we won't be able to satisfy it using indices, so
114330
- ** go ahead and disable it now.
114331
- */
114332
- if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
114333
- for(ii=0; ii<pOrderBy->nExpr; ii++){
114334
- Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
114335
- if( pExpr->op!=TK_COLUMN ){
114336
- pWInfo->pOrderBy = pOrderBy = 0;
114337
- break;
114338
- }else if( pExpr->iColumn<0 ){
114339
- break;
114340
- }
114341
- }
114342
- }
114343
-
114344114388
if( wctrlFlags & WHERE_WANT_DISTINCT ){
114345114389
if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
114346114390
/* The DISTINCT marking is pointless. Ignore it. */
114347114391
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
114348114392
}else if( pOrderBy==0 ){
@@ -114550,11 +114594,11 @@
114550114594
assert( iIndexCur>=0 );
114551114595
sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
114552114596
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
114553114597
VdbeComment((v, "%s", pIx->zName));
114554114598
}
114555
- sqlite3CodeVerifySchema(pParse, iDb);
114599
+ if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
114556114600
notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
114557114601
}
114558114602
pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
114559114603
if( db->mallocFailed ) goto whereBeginError;
114560114604
@@ -114612,20 +114656,27 @@
114612114656
int addr;
114613114657
pLevel = &pWInfo->a[i];
114614114658
pLoop = pLevel->pWLoop;
114615114659
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114616114660
if( pLevel->op!=OP_Noop ){
114617
- sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
114661
+ sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
114618114662
sqlite3VdbeChangeP5(v, pLevel->p5);
114663
+ VdbeCoverage(v);
114664
+ VdbeCoverageIf(v, pLevel->op==OP_Next);
114665
+ VdbeCoverageIf(v, pLevel->op==OP_Prev);
114666
+ VdbeCoverageIf(v, pLevel->op==OP_VNext);
114619114667
}
114620114668
if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
114621114669
struct InLoop *pIn;
114622114670
int j;
114623114671
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
114624114672
for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
114625114673
sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
114626114674
sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
114675
+ VdbeCoverage(v);
114676
+ VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
114677
+ VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
114627114678
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114628114679
}
114629114680
sqlite3DbFree(db, pLevel->u.in.aInLoop);
114630114681
}
114631114682
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
@@ -114634,11 +114685,11 @@
114634114685
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114635114686
sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114636114687
sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114637114688
}
114638114689
if( pLevel->iLeftJoin ){
114639
- addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114690
+ addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
114640114691
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114641114692
|| (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114642114693
if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114643114694
sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
114644114695
}
@@ -114661,15 +114712,41 @@
114661114712
*/
114662114713
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
114663114714
114664114715
assert( pWInfo->nLevel<=pTabList->nSrc );
114665114716
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
114717
+ int k, last;
114718
+ VdbeOp *pOp;
114666114719
Index *pIdx = 0;
114667114720
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
114668114721
Table *pTab = pTabItem->pTab;
114669114722
assert( pTab!=0 );
114670114723
pLoop = pLevel->pWLoop;
114724
+
114725
+ /* For a co-routine, change all OP_Column references to the table of
114726
+ ** the co-routine into OP_SCopy of result contained in a register.
114727
+ ** OP_Rowid becomes OP_Null.
114728
+ */
114729
+ if( pTabItem->viaCoroutine ){
114730
+ last = sqlite3VdbeCurrentAddr(v);
114731
+ k = pLevel->addrBody;
114732
+ pOp = sqlite3VdbeGetOp(v, k);
114733
+ for(; k<last; k++, pOp++){
114734
+ if( pOp->p1!=pLevel->iTabCur ) continue;
114735
+ if( pOp->opcode==OP_Column ){
114736
+ pOp->opcode = OP_SCopy;
114737
+ pOp->p1 = pOp->p2 + pTabItem->regResult;
114738
+ pOp->p2 = pOp->p3;
114739
+ pOp->p3 = 0;
114740
+ }else if( pOp->opcode==OP_Rowid ){
114741
+ pOp->opcode = OP_Null;
114742
+ pOp->p1 = 0;
114743
+ pOp->p3 = 0;
114744
+ }
114745
+ }
114746
+ continue;
114747
+ }
114671114748
114672114749
/* Close all of the cursors that were opened by sqlite3WhereBegin.
114673114750
** Except, do not close cursors that will be reused by the OR optimization
114674114751
** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114675114752
** created for the ONEPASS optimization.
@@ -114705,13 +114782,10 @@
114705114782
pIdx = pLoop->u.btree.pIndex;
114706114783
}else if( pLoop->wsFlags & WHERE_MULTI_OR ){
114707114784
pIdx = pLevel->u.pCovidx;
114708114785
}
114709114786
if( pIdx && !db->mallocFailed ){
114710
- int k, last;
114711
- VdbeOp *pOp;
114712
-
114713114787
last = sqlite3VdbeCurrentAddr(v);
114714114788
k = pLevel->addrBody;
114715114789
pOp = sqlite3VdbeGetOp(v, k);
114716114790
for(; k<last; k++, pOp++){
114717114791
if( pOp->p1!=pLevel->iTabCur ) continue;
@@ -117121,33 +117195,54 @@
117121117195
sqlite3ExplainFinish(pParse->pVdbe);
117122117196
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
117123117197
}
117124117198
break;
117125117199
case 112: /* select ::= with selectnowith */
117126
-{
117127
- if( yymsp[0].minor.yy3 ){
117128
- yymsp[0].minor.yy3->pWith = yymsp[-1].minor.yy59;
117200
+{
117201
+ Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
117202
+ if( p ){
117203
+ int cnt = 0, mxSelect;
117204
+ p->pWith = yymsp[-1].minor.yy59;
117205
+ if( p->pPrior ){
117206
+ pNext = 0;
117207
+ for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
117208
+ pLoop->pNext = pNext;
117209
+ pLoop->selFlags |= SF_Compound;
117210
+ }
117211
+ mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
117212
+ if( mxSelect && cnt>mxSelect ){
117213
+ sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
117214
+ }
117215
+ }
117129117216
}else{
117130117217
sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
117131117218
}
117132
- yygotominor.yy3 = yymsp[0].minor.yy3;
117219
+ yygotominor.yy3 = p;
117133117220
}
117134117221
break;
117135117222
case 113: /* selectnowith ::= oneselect */
117136117223
case 119: /* oneselect ::= values */ yytestcase(yyruleno==119);
117137117224
{yygotominor.yy3 = yymsp[0].minor.yy3;}
117138117225
break;
117139117226
case 114: /* selectnowith ::= selectnowith multiselect_op oneselect */
117140117227
{
117141
- if( yymsp[0].minor.yy3 ){
117142
- yymsp[0].minor.yy3->op = (u8)yymsp[-1].minor.yy328;
117143
- yymsp[0].minor.yy3->pPrior = yymsp[-2].minor.yy3;
117228
+ Select *pRhs = yymsp[0].minor.yy3;
117229
+ if( pRhs && pRhs->pPrior ){
117230
+ SrcList *pFrom;
117231
+ Token x;
117232
+ x.n = 0;
117233
+ pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
117234
+ pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
117235
+ }
117236
+ if( pRhs ){
117237
+ pRhs->op = (u8)yymsp[-1].minor.yy328;
117238
+ pRhs->pPrior = yymsp[-2].minor.yy3;
117144117239
if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
117145117240
}else{
117146117241
sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
117147117242
}
117148
- yygotominor.yy3 = yymsp[0].minor.yy3;
117243
+ yygotominor.yy3 = pRhs;
117149117244
}
117150117245
break;
117151117246
case 116: /* multiselect_op ::= UNION ALL */
117152117247
{yygotominor.yy328 = TK_ALL;}
117153117248
break;
@@ -122711,10 +122806,25 @@
122711122806
case SQLITE_TESTCTRL_NEVER_CORRUPT: {
122712122807
sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
122713122808
break;
122714122809
}
122715122810
122811
+
122812
+ /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
122813
+ **
122814
+ ** Set the VDBE coverage callback function to xCallback with context
122815
+ ** pointer ptr.
122816
+ */
122817
+ case SQLITE_TESTCTRL_VDBE_COVERAGE: {
122818
+#ifdef SQLITE_VDBE_COVERAGE
122819
+ typedef void (*branch_callback)(void*,int,u8,u8);
122820
+ sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
122821
+ sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
122822
+#endif
122823
+ break;
122824
+ }
122825
+
122716122826
}
122717122827
va_end(ap);
122718122828
#endif /* SQLITE_OMIT_BUILTIN_TEST */
122719122829
return rc;
122720122830
}
122721122831
--- 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.3.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.
@@ -23,10 +23,64 @@
23 # define SQLITE_PRIVATE static
24 #endif
25 #ifndef SQLITE_API
26 # define SQLITE_API
27 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28 /************** Begin file sqlite3.h *****************************************/
29 /*
30 ** 2001 September 15
31 **
32 ** The author disclaims copyright to this source code. In place of
@@ -133,13 +187,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.3.1"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -6148,11 +6202,12 @@
6148 #define SQLITE_TESTCTRL_ISKEYWORD 16
6149 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6150 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6151 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6152 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6153 #define SQLITE_TESTCTRL_LAST 20
 
6154
6155 /*
6156 ** CAPI3REF: SQLite Runtime Status
6157 **
6158 ** ^This interface is used to retrieve runtime status information
@@ -7411,54 +7466,11 @@
7411
7412 #endif /* ifndef _SQLITE3RTREE_H_ */
7413
7414
7415 /************** End of sqlite3.h *********************************************/
7416 /************** Begin file sqliteInt.h ***************************************/
7417 /*
7418 ** 2001 September 15
7419 **
7420 ** The author disclaims copyright to this source code. In place of
7421 ** a legal notice, here is a blessing:
7422 **
7423 ** May you do good and not evil.
7424 ** May you find forgiveness for yourself and forgive others.
7425 ** May you share freely, never taking more than you give.
7426 **
7427 *************************************************************************
7428 ** Internal interface definitions for SQLite.
7429 **
7430 */
7431 #ifndef _SQLITEINT_H_
7432 #define _SQLITEINT_H_
7433
7434 /*
7435 ** These #defines should enable >2GB file support on POSIX if the
7436 ** underlying operating system supports it. If the OS lacks
7437 ** large file support, or if the OS is windows, these should be no-ops.
7438 **
7439 ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
7440 ** system #includes. Hence, this block of code must be the very first
7441 ** code in all source files.
7442 **
7443 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
7444 ** on the compiler command line. This is necessary if you are compiling
7445 ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
7446 ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
7447 ** without this option, LFS is enable. But LFS does not exist in the kernel
7448 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
7449 ** portability you should omit LFS.
7450 **
7451 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
7452 */
7453 #ifndef SQLITE_DISABLE_LFS
7454 # define _LARGE_FILE 1
7455 # ifndef _FILE_OFFSET_BITS
7456 # define _FILE_OFFSET_BITS 64
7457 # endif
7458 # define _LARGEFILE_SOURCE 1
7459 #endif
7460
7461 /*
7462 ** Include the configuration header output by 'configure' if we're using the
7463 ** autoconf-based build
7464 */
@@ -8841,12 +8853,10 @@
8841 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8842 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
8843 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
8844 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8845 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8846 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8847 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
8848
8849 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
8850 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
8851
8852 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
@@ -8982,13 +8992,16 @@
8982 } p4;
8983 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
8984 char *zComment; /* Comment to improve readability */
8985 #endif
8986 #ifdef VDBE_PROFILE
8987 int cnt; /* Number of times this instruction was executed */
8988 u64 cycles; /* Total time spent executing this instruction */
8989 #endif
 
 
 
8990 };
8991 typedef struct VdbeOp VdbeOp;
8992
8993
8994 /*
@@ -9094,75 +9107,75 @@
9094 #define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
9095 #define OP_Goto 16
9096 #define OP_Gosub 17
9097 #define OP_Return 18
9098 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9099 #define OP_Yield 20
9100 #define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */
9101 #define OP_Halt 22
9102 #define OP_Integer 23 /* synopsis: r[P2]=P1 */
9103 #define OP_Int64 24 /* synopsis: r[P2]=P4 */
9104 #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9105 #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9106 #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9107 #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9108 #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9109 #define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9110 #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9111 #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9112 #define OP_CollSeq 33
9113 #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9114 #define OP_MustBeInt 35
9115 #define OP_RealAffinity 36
9116 #define OP_Permutation 37
9117 #define OP_Compare 38
9118 #define OP_Jump 39
9119 #define OP_Once 40
9120 #define OP_If 41
9121 #define OP_IfNot 42
9122 #define OP_Column 43 /* synopsis: r[P3]=PX */
9123 #define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */
9124 #define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9125 #define OP_Count 46 /* synopsis: r[P2]=count() */
9126 #define OP_ReadCookie 47
9127 #define OP_SetCookie 48
9128 #define OP_VerifyCookie 49
9129 #define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9130 #define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9131 #define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9132 #define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9133 #define OP_SorterOpen 54
9134 #define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9135 #define OP_Close 56
9136 #define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9137 #define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9138 #define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9139 #define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9140 #define OP_Seek 61 /* synopsis: intkey=r[P2] */
9141 #define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9142 #define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9143 #define OP_Found 64 /* synopsis: key=r[P3@P4] */
9144 #define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9145 #define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9146 #define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9147 #define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
9148 #define OP_InsertInt 69 /* synopsis: intkey=P3 data=r[P2] */
9149 #define OP_Delete 70
9150 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9151 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9152 #define OP_ResetCount 73
9153 #define OP_SorterCompare 74 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9154 #define OP_SorterData 75 /* synopsis: r[P2]=data */
9155 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9156 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9157 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9158 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9159 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9160 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9161 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9162 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9163 #define OP_RowKey 84 /* synopsis: r[P2]=key */
9164 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9165 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9166 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9167 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9168 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9169,68 +9182,72 @@
9169 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9170 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9171 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9172 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9173 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9174 #define OP_RowData 95 /* synopsis: r[P2]=data */
9175 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9176 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9177 #define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9178 #define OP_NullRow 99
9179 #define OP_Last 100
9180 #define OP_SorterSort 101
9181 #define OP_Sort 102
9182 #define OP_Rewind 103
9183 #define OP_SorterInsert 104
9184 #define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9185 #define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9186 #define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9187 #define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9188 #define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9189 #define OP_Destroy 110
9190 #define OP_Clear 111
9191 #define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9192 #define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9193 #define OP_ParseSchema 114
9194 #define OP_LoadAnalysis 115
9195 #define OP_DropTable 116
9196 #define OP_DropIndex 117
9197 #define OP_DropTrigger 118
9198 #define OP_IntegrityCk 119
9199 #define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9200 #define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9201 #define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9202 #define OP_Program 123
9203 #define OP_Param 124
9204 #define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9205 #define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9206 #define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9207 #define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9208 #define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9209 #define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9210 #define OP_AggFinal 131 /* synopsis: accum=r[P1] N=P2 */
9211 #define OP_IncrVacuum 132
9212 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9213 #define OP_Expire 134
9214 #define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9215 #define OP_VBegin 136
9216 #define OP_VCreate 137
9217 #define OP_VDestroy 138
9218 #define OP_VOpen 139
9219 #define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9220 #define OP_VNext 141
9221 #define OP_VRename 142
9222 #define OP_ToText 143 /* same as TK_TO_TEXT */
9223 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9224 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9225 #define OP_ToInt 146 /* same as TK_TO_INT */
9226 #define OP_ToReal 147 /* same as TK_TO_REAL */
9227 #define OP_Pagecount 148
9228 #define OP_MaxPgcnt 149
9229 #define OP_Trace 150
9230 #define OP_Noop 151
9231 #define OP_Explain 152
 
 
 
 
9232
9233
9234 /* Properties such as "out2" or "jump" that are specified in
9235 ** comments following the "case" for each opcode in the vdbe.c
9236 ** are encoded into bitvectors as follows:
@@ -9243,28 +9260,28 @@
9243 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9244 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9245 #define OPFLG_INITIALIZER {\
9246 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9247 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9248 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9249 /* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9250 /* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9251 /* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9252 /* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9253 /* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9254 /* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c,\
9255 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9256 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9257 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9258 /* 96 */ 0x24, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9259 /* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9260 /* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9261 /* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9262 /* 128 */ 0x05, 0x05, 0x05, 0x00, 0x01, 0x02, 0x00, 0x00,\
9263 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,\
9264 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00,\
9265 /* 152 */ 0x00,}
9266
9267 /************** End of opcodes.h *********************************************/
9268 /************** Continuing where we left off in vdbe.h ***********************/
9269
9270 /*
@@ -9276,11 +9293,11 @@
9276 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
9277 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
9278 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
9279 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
9280 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
9281 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
9282 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
9283 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
9284 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9285 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9286 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
@@ -9347,10 +9364,45 @@
9347 # define VdbeComment(X)
9348 # define VdbeNoopComment(X)
9349 # define VdbeModuleComment(X)
9350 #endif
9351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9352 #endif
9353
9354 /************** End of vdbe.h ************************************************/
9355 /************** Continuing where we left off in sqliteInt.h ******************/
9356 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -10404,12 +10456,11 @@
10404
10405 /*
10406 ** Return true if it OK to factor constant expressions into the initialization
10407 ** code. The argument is a Parse object for the code generator.
10408 */
10409 #define ConstFactorOk(P) \
10410 ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))
10411
10412 /*
10413 ** Possible values for the sqlite.magic field.
10414 ** The numbers are obtained at random and have no special meaning, other
10415 ** than being distinct from one another.
@@ -10631,14 +10682,20 @@
10631 #define SQLITE_AFF_MASK 0x67
10632
10633 /*
10634 ** Additional bit values that can be ORed with an affinity without
10635 ** changing the affinity.
 
 
 
 
 
10636 */
10637 #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
10638 #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
10639 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
 
10640
10641 /*
10642 ** An object of this type is created for each virtual table present in
10643 ** the database schema.
10644 **
@@ -11336,10 +11393,11 @@
11336 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
11337 Table *pTab; /* An SQL table corresponding to zName */
11338 Select *pSelect; /* A SELECT statement used in place of a table name */
11339 int addrFillSub; /* Address of subroutine to manifest a subquery */
11340 int regReturn; /* Register holding return address of addrFillSub */
 
11341 u8 jointype; /* Type of join between this able and the previous */
11342 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
11343 unsigned isCorrelated :1; /* True if sub-query is correlated */
11344 unsigned viaCoroutine :1; /* Implemented as a co-routine */
11345 unsigned isRecursive :1; /* True for recursive reference in WITH */
@@ -11464,11 +11522,10 @@
11464 ExprList *pGroupBy; /* The GROUP BY clause */
11465 Expr *pHaving; /* The HAVING clause */
11466 ExprList *pOrderBy; /* The ORDER BY clause */
11467 Select *pPrior; /* Prior select in a compound select statement */
11468 Select *pNext; /* Next select to the left in a compound */
11469 Select *pRightmost; /* Right-most select in a compound select statement */
11470 Expr *pLimit; /* LIMIT expression. NULL means not used. */
11471 Expr *pOffset; /* OFFSET expression. NULL means not used. */
11472 With *pWith; /* WITH clause attached to this select. Or NULL. */
11473 };
11474
@@ -11482,14 +11539,15 @@
11482 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11483 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11484 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11485 #define SF_UseSorter 0x0040 /* Sort using a sorter */
11486 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11487 #define SF_Materialize 0x0100 /* Force materialization of views */
11488 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11489 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11490 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
 
11491
11492
11493 /*
11494 ** The results of a SELECT can be distributed in several ways, as defined
11495 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -11664,49 +11722,48 @@
11664 int rc; /* Return code from execution */
11665 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
11666 u8 checkSchema; /* Causes schema cookie check after an error */
11667 u8 nested; /* Number of nested calls to the parser/code generator */
11668 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
11669 u8 nTempInUse; /* Number of aTempReg[] currently checked out */
11670 u8 nColCache; /* Number of entries in aColCache[] */
11671 u8 iColCache; /* Next entry in aColCache[] to replace */
11672 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
11673 u8 mayAbort; /* True if statement may throw an ABORT exception */
11674 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
 
11675 int aTempReg[8]; /* Holding area for temporary registers */
11676 int nRangeReg; /* Size of the temporary register block */
11677 int iRangeReg; /* First register in temporary register block */
11678 int nErr; /* Number of errors seen */
11679 int nTab; /* Number of previously allocated VDBE cursors */
11680 int nMem; /* Number of memory cells used so far */
11681 int nSet; /* Number of sets used so far */
11682 int nOnce; /* Number of OP_Once instructions so far */
11683 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11684 int nLabel; /* Number of labels used */
11685 int *aLabel; /* Space to hold the labels */
11686 int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
11687 int ckBase; /* Base register of data during check constraints */
11688 int iPartIdxTab; /* Table corresponding to a partial index */
11689 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11690 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
 
 
11691 struct yColCache {
11692 int iTable; /* Table cursor number */
11693 int iColumn; /* Table column number */
11694 u8 tempReg; /* iReg is a temp register that needs to be freed */
11695 int iLevel; /* Nesting level */
11696 int iReg; /* Reg with value of this column. 0 means none. */
11697 int lru; /* Least recently used entry has the smallest value */
11698 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11699 ExprList *pConstExpr;/* Constant expressions */
 
11700 yDbMask writeMask; /* Start a write transaction on these databases */
11701 yDbMask cookieMask; /* Bitmask of schema verified databases */
11702 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
11703 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11704 int regRowid; /* Register holding rowid of CREATE TABLE entry */
11705 int regRoot; /* Register holding root page number for new objects */
11706 int nMaxArg; /* Max args passed to user function by sub-program */
11707 Token constraintName;/* Name of the constraint currently being parsed */
11708 #ifndef SQLITE_OMIT_SHARED_CACHE
11709 int nTableLock; /* Number of locks in aTableLock */
11710 TableLock *aTableLock; /* Required table locks for shared-cache mode */
11711 #endif
11712 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -11721,16 +11778,21 @@
11721 u32 newmask; /* Mask of new.* columns referenced */
11722 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
11723 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
11724 u8 disableTriggers; /* True to disable triggers */
11725
11726 /* Above is constant between recursions. Below is reset before and after
11727 ** each recursion */
 
 
 
 
11728
11729 int nVar; /* Number of '?' variables seen in the SQL so far */
11730 int nzVar; /* Number of available slots in azVar[] */
11731 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
 
11732 u8 explain; /* True if the EXPLAIN flag is found on the query */
11733 #ifndef SQLITE_OMIT_VIRTUALTABLE
11734 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
11735 int nVtabLock; /* Number of virtual tables to lock */
11736 #endif
@@ -11753,11 +11815,10 @@
11753 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11754 #endif
11755 Table *pZombieTab; /* List of Table objects to delete after code gen */
11756 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11757 With *pWith; /* Current WITH clause, or NULL */
11758 u8 bFreeWith; /* True if pWith should be freed with parser */
11759 };
11760
11761 /*
11762 ** Return true if currently inside an sqlite3_declare_vtab() call.
11763 */
@@ -11969,10 +12030,17 @@
11969 int bLocaltimeFault; /* True to fail localtime() calls */
11970 #ifdef SQLITE_ENABLE_SQLLOG
11971 void(*xSqllog)(void*,sqlite3*,const char*, int);
11972 void *pSqllogArg;
11973 #endif
 
 
 
 
 
 
 
11974 };
11975
11976 /*
11977 ** This macro is used inside of assert() statements to indicate that
11978 ** the assert is only valid on a well-formed database. Instead of:
@@ -12302,11 +12370,10 @@
12302 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
12303 #else
12304 # define sqlite3AutoincrementBegin(X)
12305 # define sqlite3AutoincrementEnd(X)
12306 #endif
12307 SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse*, Select*, SelectDest*);
12308 SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int);
12309 SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
12310 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
12311 SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
12312 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -12350,15 +12417,16 @@
12350 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
12351 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12352 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12353 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12354 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12355 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
 
12356 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
12357 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12358 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12359 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12360 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
12361 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
12362 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
12363 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12364 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
@@ -12392,11 +12460,10 @@
12392 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12393 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12394 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
12395 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12396 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12397 SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
12398 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12399 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12400 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
12401 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12402 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
@@ -12536,11 +12603,11 @@
12536 #define getVarint sqlite3GetVarint
12537 #define putVarint sqlite3PutVarint
12538
12539
12540 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
12541 SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
12542 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
12543 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
12544 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
12545 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
12546 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
@@ -13640,11 +13707,10 @@
13640 u8 rowidIsValid; /* True if lastRowid is valid */
13641 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13642 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13643 Bool isTable:1; /* True if a table requiring integer keys */
13644 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13645 Bool multiPseudo:1; /* Multi-register pseudo-cursor */
13646 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13647 i64 seqCount; /* Sequence counter */
13648 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13649 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13650 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -13734,11 +13800,11 @@
13734 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
13735 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
13736 } u;
13737 int n; /* Number of characters in string value, excluding '\0' */
13738 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
13739 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
13740 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
13741 #ifdef SQLITE_DEBUG
13742 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
13743 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
13744 #endif
@@ -13763,11 +13829,11 @@
13763 #define MEM_Int 0x0004 /* Value is an integer */
13764 #define MEM_Real 0x0008 /* Value is a real number */
13765 #define MEM_Blob 0x0010 /* Value is a BLOB */
13766 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
13767 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
13768 #define MEM_Invalid 0x0080 /* Value is undefined */
13769 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
13770 #define MEM_TypeMask 0x01ff /* Mask of type bits */
13771
13772
13773 /* Whenever Mem contains a valid string or blob representation, one of
@@ -13795,11 +13861,11 @@
13795 /*
13796 ** Return true if a memory cell is not marked as invalid. This macro
13797 ** is for use inside assert() statements only.
13798 */
13799 #ifdef SQLITE_DEBUG
13800 #define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13801 #endif
13802
13803 /*
13804 ** Each auxilliary data pointer stored by a user defined function
13805 ** implementation calling sqlite3_set_auxdata() is stored in an instance
@@ -13990,20 +14056,22 @@
13990 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
13991 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
13992 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
13993 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
13994 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
 
 
13995 #define VdbeMemRelease(X) \
13996 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
13997 sqlite3VdbeMemReleaseExternal(X);
13998 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
13999 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
14000 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
14001 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
14002 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
14003 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14004 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
 
14005 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
14006
14007 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
14008 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
14009 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
@@ -17767,10 +17835,16 @@
17767 mem5.totalExcess += iFullSz - nByte;
17768 mem5.currentCount++;
17769 mem5.currentOut += iFullSz;
17770 if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
17771 if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
 
 
 
 
 
 
17772
17773 /* Return a pointer to the allocated memory. */
17774 return (void*)&mem5.zPool[i*mem5.szAtom];
17775 }
17776
@@ -17825,10 +17899,17 @@
17825 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
17826 mem5.aCtrl[iBuddy] = 0;
17827 }
17828 size *= 2;
17829 }
 
 
 
 
 
 
 
17830 memsys5Link(iBlock, iLogsize);
17831 }
17832
17833 /*
17834 ** Allocate nBytes of memory.
@@ -22728,17 +22809,16 @@
22728 testcase( iB==-1 ); testcase( iB==0 );
22729 if( iB>=0 ){
22730 testcase( iA>0 && LARGEST_INT64 - iA == iB );
22731 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
22732 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
22733 *pA += iB;
22734 }else{
22735 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
22736 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
22737 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
22738 *pA += iB;
22739 }
 
22740 return 0;
22741 }
22742 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
22743 testcase( iB==SMALLEST_INT64+1 );
22744 if( iB==SMALLEST_INT64 ){
@@ -22758,13 +22838,22 @@
22758
22759 iA1 = iA/TWOPOWER32;
22760 iA0 = iA % TWOPOWER32;
22761 iB1 = iB/TWOPOWER32;
22762 iB0 = iB % TWOPOWER32;
22763 if( iA1*iB1 != 0 ) return 1;
22764 assert( iA1*iB0==0 || iA0*iB1==0 );
22765 r = iA1*iB0 + iA0*iB1;
 
 
 
 
 
 
 
 
 
22766 testcase( r==(-TWOPOWER31)-1 );
22767 testcase( r==(-TWOPOWER31) );
22768 testcase( r==TWOPOWER31 );
22769 testcase( r==TWOPOWER31-1 );
22770 if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
@@ -23206,75 +23295,75 @@
23206 /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
23207 /* 16 */ "Goto" OpHelp(""),
23208 /* 17 */ "Gosub" OpHelp(""),
23209 /* 18 */ "Return" OpHelp(""),
23210 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
23211 /* 20 */ "Yield" OpHelp(""),
23212 /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
23213 /* 22 */ "Halt" OpHelp(""),
23214 /* 23 */ "Integer" OpHelp("r[P2]=P1"),
23215 /* 24 */ "Int64" OpHelp("r[P2]=P4"),
23216 /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23217 /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
23218 /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23219 /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23220 /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23221 /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23222 /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23223 /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23224 /* 33 */ "CollSeq" OpHelp(""),
23225 /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23226 /* 35 */ "MustBeInt" OpHelp(""),
23227 /* 36 */ "RealAffinity" OpHelp(""),
23228 /* 37 */ "Permutation" OpHelp(""),
23229 /* 38 */ "Compare" OpHelp(""),
23230 /* 39 */ "Jump" OpHelp(""),
23231 /* 40 */ "Once" OpHelp(""),
23232 /* 41 */ "If" OpHelp(""),
23233 /* 42 */ "IfNot" OpHelp(""),
23234 /* 43 */ "Column" OpHelp("r[P3]=PX"),
23235 /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23236 /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23237 /* 46 */ "Count" OpHelp("r[P2]=count()"),
23238 /* 47 */ "ReadCookie" OpHelp(""),
23239 /* 48 */ "SetCookie" OpHelp(""),
23240 /* 49 */ "VerifyCookie" OpHelp(""),
23241 /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23242 /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23243 /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23244 /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23245 /* 54 */ "SorterOpen" OpHelp(""),
23246 /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23247 /* 56 */ "Close" OpHelp(""),
23248 /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23249 /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23250 /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23251 /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23252 /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23253 /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23254 /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23255 /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23256 /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23257 /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23258 /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23259 /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23260 /* 69 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23261 /* 70 */ "Delete" OpHelp(""),
23262 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23263 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23264 /* 73 */ "ResetCount" OpHelp(""),
23265 /* 74 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23266 /* 75 */ "SorterData" OpHelp("r[P2]=data"),
23267 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23268 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23269 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23270 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23271 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23272 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23273 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23274 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23275 /* 84 */ "RowKey" OpHelp("r[P2]=key"),
23276 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23277 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23278 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23279 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23280 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23281,68 +23370,72 @@
23281 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23282 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23283 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23284 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23285 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23286 /* 95 */ "RowData" OpHelp("r[P2]=data"),
23287 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23288 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23289 /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23290 /* 99 */ "NullRow" OpHelp(""),
23291 /* 100 */ "Last" OpHelp(""),
23292 /* 101 */ "SorterSort" OpHelp(""),
23293 /* 102 */ "Sort" OpHelp(""),
23294 /* 103 */ "Rewind" OpHelp(""),
23295 /* 104 */ "SorterInsert" OpHelp(""),
23296 /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23297 /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23298 /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23299 /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23300 /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23301 /* 110 */ "Destroy" OpHelp(""),
23302 /* 111 */ "Clear" OpHelp(""),
23303 /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23304 /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23305 /* 114 */ "ParseSchema" OpHelp(""),
23306 /* 115 */ "LoadAnalysis" OpHelp(""),
23307 /* 116 */ "DropTable" OpHelp(""),
23308 /* 117 */ "DropIndex" OpHelp(""),
23309 /* 118 */ "DropTrigger" OpHelp(""),
23310 /* 119 */ "IntegrityCk" OpHelp(""),
23311 /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23312 /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23313 /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23314 /* 123 */ "Program" OpHelp(""),
23315 /* 124 */ "Param" OpHelp(""),
23316 /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23317 /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23318 /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23319 /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23320 /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23321 /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23322 /* 131 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23323 /* 132 */ "IncrVacuum" OpHelp(""),
23324 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23325 /* 134 */ "Expire" OpHelp(""),
23326 /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23327 /* 136 */ "VBegin" OpHelp(""),
23328 /* 137 */ "VCreate" OpHelp(""),
23329 /* 138 */ "VDestroy" OpHelp(""),
23330 /* 139 */ "VOpen" OpHelp(""),
23331 /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23332 /* 141 */ "VNext" OpHelp(""),
23333 /* 142 */ "VRename" OpHelp(""),
23334 /* 143 */ "ToText" OpHelp(""),
23335 /* 144 */ "ToBlob" OpHelp(""),
23336 /* 145 */ "ToNumeric" OpHelp(""),
23337 /* 146 */ "ToInt" OpHelp(""),
23338 /* 147 */ "ToReal" OpHelp(""),
23339 /* 148 */ "Pagecount" OpHelp(""),
23340 /* 149 */ "MaxPgcnt" OpHelp(""),
23341 /* 150 */ "Trace" OpHelp(""),
23342 /* 151 */ "Noop" OpHelp(""),
23343 /* 152 */ "Explain" OpHelp(""),
 
 
 
 
23344 };
23345 return azName[i];
23346 }
23347 #endif
23348
@@ -23430,36 +23523,10 @@
23430 # else
23431 # define OS_VXWORKS 0
23432 # endif
23433 #endif
23434
23435 /*
23436 ** These #defines should enable >2GB file support on Posix if the
23437 ** underlying operating system supports it. If the OS lacks
23438 ** large file support, these should be no-ops.
23439 **
23440 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
23441 ** on the compiler command line. This is necessary if you are compiling
23442 ** on a recent machine (ex: RedHat 7.2) but you want your code to work
23443 ** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
23444 ** without this option, LFS is enable. But LFS does not exist in the kernel
23445 ** in RedHat 6.0, so the code won't work. Hence, for maximum binary
23446 ** portability you should omit LFS.
23447 **
23448 ** The previous paragraph was written in 2005. (This paragraph is written
23449 ** on 2008-11-28.) These days, all Linux kernels support large files, so
23450 ** you should probably leave LFS enabled. But some embedded platforms might
23451 ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
23452 */
23453 #ifndef SQLITE_DISABLE_LFS
23454 # define _LARGE_FILE 1
23455 # ifndef _FILE_OFFSET_BITS
23456 # define _FILE_OFFSET_BITS 64
23457 # endif
23458 # define _LARGEFILE_SOURCE 1
23459 #endif
23460
23461 /*
23462 ** standard include files.
23463 */
23464 #include <sys/types.h>
23465 #include <sys/stat.h>
@@ -34444,11 +34511,11 @@
34444 ** Windows will only let you create file view mappings
34445 ** on allocation size granularity boundaries.
34446 ** During sqlite3_os_init() we do a GetSystemInfo()
34447 ** to get the granularity size.
34448 */
34449 SYSTEM_INFO winSysInfo;
34450
34451 #ifndef SQLITE_OMIT_WAL
34452
34453 /*
34454 ** Helper functions to obtain and relinquish the global mutex. The
@@ -36378,19 +36445,16 @@
36378 #ifndef SQLITE_OMIT_LOAD_EXTENSION
36379 /*
36380 ** Interfaces for opening a shared library, finding entry points
36381 ** within the shared library, and closing the shared library.
36382 */
36383 /*
36384 ** Interfaces for opening a shared library, finding entry points
36385 ** within the shared library, and closing the shared library.
36386 */
36387 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
36388 HANDLE h;
36389 void *zConverted = winConvertFromUtf8Filename(zFilename);
36390 UNUSED_PARAMETER(pVfs);
36391 if( zConverted==0 ){
 
36392 return 0;
36393 }
36394 if( osIsNT() ){
36395 #if SQLITE_OS_WINRT
36396 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
@@ -36401,24 +36465,30 @@
36401 #ifdef SQLITE_WIN32_HAS_ANSI
36402 else{
36403 h = osLoadLibraryA((char*)zConverted);
36404 }
36405 #endif
 
36406 sqlite3_free(zConverted);
36407 return (void*)h;
36408 }
36409 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
36410 UNUSED_PARAMETER(pVfs);
36411 winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
36412 }
36413 static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
 
36414 UNUSED_PARAMETER(pVfs);
36415 return (void(*)(void))osGetProcAddressA((HANDLE)pH, zSym);
 
 
 
36416 }
36417 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
36418 UNUSED_PARAMETER(pVfs);
36419 osFreeLibrary((HANDLE)pHandle);
 
36420 }
36421 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
36422 #define winDlOpen 0
36423 #define winDlError 0
36424 #define winDlSym 0
@@ -37110,11 +37180,12 @@
37110 PgHdr *pSynced; /* Last synced page in dirty page list */
37111 int nRef; /* Number of referenced pages */
37112 int szCache; /* Configured cache size */
37113 int szPage; /* Size of every page in this cache */
37114 int szExtra; /* Size of extra space for each page */
37115 int bPurgeable; /* True if pages are on backing store */
 
37116 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
37117 void *pStress; /* Argument to xStress */
37118 sqlite3_pcache *pCache; /* Pluggable cache module */
37119 PgHdr *pPage1; /* Reference to page 1 */
37120 };
@@ -37177,10 +37248,14 @@
37177 if( pPage->pDirtyPrev ){
37178 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
37179 }else{
37180 assert( pPage==p->pDirty );
37181 p->pDirty = pPage->pDirtyNext;
 
 
 
 
37182 }
37183 pPage->pDirtyNext = 0;
37184 pPage->pDirtyPrev = 0;
37185
37186 expensive_assert( pcacheCheckSynced(p) );
@@ -37197,10 +37272,13 @@
37197
37198 pPage->pDirtyNext = p->pDirty;
37199 if( pPage->pDirtyNext ){
37200 assert( pPage->pDirtyNext->pDirtyPrev==0 );
37201 pPage->pDirtyNext->pDirtyPrev = pPage;
 
 
 
37202 }
37203 p->pDirty = pPage;
37204 if( !p->pDirtyTail ){
37205 p->pDirtyTail = pPage;
37206 }
@@ -37266,10 +37344,11 @@
37266 ){
37267 memset(p, 0, sizeof(PCache));
37268 p->szPage = szPage;
37269 p->szExtra = szExtra;
37270 p->bPurgeable = bPurgeable;
 
37271 p->xStress = xStress;
37272 p->pStress = pStress;
37273 p->szCache = 100;
37274 }
37275
@@ -37305,11 +37384,11 @@
37305 PCache *pCache, /* Obtain the page from this cache */
37306 Pgno pgno, /* Page number to obtain */
37307 int createFlag, /* If true, create page if it does not exist already */
37308 PgHdr **ppPage /* Write the page here */
37309 ){
37310 sqlite3_pcache_page *pPage = 0;
37311 PgHdr *pPgHdr = 0;
37312 int eCreate;
37313
37314 assert( pCache!=0 );
37315 assert( createFlag==1 || createFlag==0 );
@@ -37316,12 +37395,16 @@
37316 assert( pgno>0 );
37317
37318 /* If the pluggable cache (sqlite3_pcache*) has not been allocated,
37319 ** allocate it now.
37320 */
37321 if( !pCache->pCache && createFlag ){
37322 sqlite3_pcache *p;
 
 
 
 
37323 p = sqlite3GlobalConfig.pcache2.xCreate(
37324 pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
37325 );
37326 if( !p ){
37327 return SQLITE_NOMEM;
@@ -37328,15 +37411,20 @@
37328 }
37329 sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
37330 pCache->pCache = p;
37331 }
37332
37333 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
37334 if( pCache->pCache ){
37335 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
37336 }
37337
 
 
 
 
 
37338 if( !pPage && eCreate==1 ){
37339 PgHdr *pPg;
37340
37341 /* Find a dirty page to write-out and recycle. First try to find a
37342 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
@@ -47920,11 +48008,11 @@
47920 if( rc!=SQLITE_OK ){
47921 walIndexClose(pRet, 0);
47922 sqlite3OsClose(pRet->pWalFd);
47923 sqlite3_free(pRet);
47924 }else{
47925 int iDC = sqlite3OsDeviceCharacteristics(pRet->pWalFd);
47926 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
47927 if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
47928 pRet->padToSectorBoundary = 0;
47929 }
47930 *ppWal = pRet;
@@ -49291,11 +49379,11 @@
49291 if( rc ) return rc;
49292 iOffset += iFirstAmt;
49293 iAmt -= iFirstAmt;
49294 pContent = (void*)(iFirstAmt + (char*)pContent);
49295 assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
49296 rc = sqlite3OsSync(p->pFd, p->syncFlags);
49297 if( iAmt==0 || rc ) return rc;
49298 }
49299 rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
49300 return rc;
49301 }
@@ -50229,11 +50317,10 @@
50229 struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
50230 #ifndef SQLITE_OMIT_INCRBLOB
50231 Pgno *aOverflow; /* Cache of overflow page locations */
50232 #endif
50233 Pgno pgnoRoot; /* The root page of this tree */
50234 sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
50235 CellInfo info; /* A parse of the cell we are pointing at */
50236 i64 nKey; /* Size of pKey, or last integer key */
50237 void *pKey; /* Saved key that was cursor's last known position */
50238 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
50239 u8 wrFlag; /* True if writable */
@@ -52213,17 +52300,16 @@
52213 assert( sqlite3_mutex_held(pBt->mutex) );
52214 if( pBt->btsFlags & BTS_SECURE_DELETE ){
52215 memset(&data[hdr], 0, pBt->usableSize - hdr);
52216 }
52217 data[hdr] = (char)flags;
52218 first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0);
52219 memset(&data[hdr+1], 0, 4);
52220 data[hdr+7] = 0;
52221 put2byte(&data[hdr+5], pBt->usableSize);
52222 pPage->nFree = (u16)(pBt->usableSize - first);
52223 decodeFlags(pPage, flags);
52224 pPage->hdrOffset = hdr;
52225 pPage->cellOffset = first;
52226 pPage->aDataEnd = &data[pBt->usableSize];
52227 pPage->aCellIdx = &data[first];
52228 pPage->nOverflow = 0;
52229 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
@@ -54303,11 +54389,10 @@
54303 if( pCur->pNext ){
54304 pCur->pNext->pPrev = pCur;
54305 }
54306 pBt->pCursor = pCur;
54307 pCur->eState = CURSOR_INVALID;
54308 pCur->cachedRowid = 0;
54309 return SQLITE_OK;
54310 }
54311 SQLITE_PRIVATE int sqlite3BtreeCursor(
54312 Btree *p, /* The btree */
54313 int iTable, /* Root page of table to open */
@@ -54344,40 +54429,10 @@
54344 */
54345 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){
54346 memset(p, 0, offsetof(BtCursor, iPage));
54347 }
54348
54349 /*
54350 ** Set the cached rowid value of every cursor in the same database file
54351 ** as pCur and having the same root page number as pCur. The value is
54352 ** set to iRowid.
54353 **
54354 ** Only positive rowid values are considered valid for this cache.
54355 ** The cache is initialized to zero, indicating an invalid cache.
54356 ** A btree will work fine with zero or negative rowids. We just cannot
54357 ** cache zero or negative rowids, which means tables that use zero or
54358 ** negative rowids might run a little slower. But in practice, zero
54359 ** or negative rowids are very uncommon so this should not be a problem.
54360 */
54361 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor *pCur, sqlite3_int64 iRowid){
54362 BtCursor *p;
54363 for(p=pCur->pBt->pCursor; p; p=p->pNext){
54364 if( p->pgnoRoot==pCur->pgnoRoot ) p->cachedRowid = iRowid;
54365 }
54366 assert( pCur->cachedRowid==iRowid );
54367 }
54368
54369 /*
54370 ** Return the cached rowid for the given cursor. A negative or zero
54371 ** return value indicates that the rowid cache is invalid and should be
54372 ** ignored. If the rowid cache has never before been set, then a
54373 ** zero is returned.
54374 */
54375 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor *pCur){
54376 return pCur->cachedRowid;
54377 }
54378
54379 /*
54380 ** Close a cursor. The read lock on the database file is released
54381 ** when the last cursor is closed.
54382 */
54383 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
@@ -55448,18 +55503,28 @@
55448 /*
55449 ** Advance the cursor to the next entry in the database. If
55450 ** successful then set *pRes=0. If the cursor
55451 ** was already pointing to the last entry in the database before
55452 ** this routine was called, then set *pRes=1.
 
 
 
 
 
 
 
 
 
55453 */
55454 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
55455 int rc;
55456 int idx;
55457 MemPage *pPage;
55458
55459 assert( cursorHoldsMutex(pCur) );
55460 assert( pRes!=0 );
 
55461 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55462 if( pCur->eState!=CURSOR_VALID ){
55463 rc = restoreCursorPosition(pCur);
55464 if( rc!=SQLITE_OK ){
55465 *pRes = 0;
@@ -55534,17 +55599,27 @@
55534 /*
55535 ** Step the cursor to the back to the previous entry in the database. If
55536 ** successful then set *pRes=0. If the cursor
55537 ** was already pointing to the first entry in the database before
55538 ** this routine was called, then set *pRes=1.
 
 
 
 
 
 
 
 
 
55539 */
55540 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
55541 int rc;
55542 MemPage *pPage;
55543
55544 assert( cursorHoldsMutex(pCur) );
55545 assert( pRes!=0 );
 
55546 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55547 pCur->atLast = 0;
55548 if( pCur->eState!=CURSOR_VALID ){
55549 if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){
55550 rc = btreeRestoreCursorPosition(pCur);
@@ -57637,15 +57712,21 @@
57637 ** not to clear the cursor here.
57638 */
57639 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
57640 if( rc ) return rc;
57641
57642 /* If this is an insert into a table b-tree, invalidate any incrblob
57643 ** cursors open on the row being replaced (assuming this is a replace
57644 ** operation - if it is not, the following is a no-op). */
57645 if( pCur->pKeyInfo==0 ){
 
 
57646 invalidateIncrblobCursors(p, nKey, 0);
 
 
 
 
 
 
 
57647 }
57648
57649 if( !loc ){
57650 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
57651 if( rc ) return rc;
@@ -57711,12 +57792,12 @@
57711 ** entry in the table, and the next row inserted has an integer key
57712 ** larger than the largest existing key, it is possible to insert the
57713 ** row without seeking the cursor. This can be a big performance boost.
57714 */
57715 pCur->info.nSize = 0;
57716 pCur->validNKey = 0;
57717 if( rc==SQLITE_OK && pPage->nOverflow ){
 
57718 rc = balance(pCur);
57719
57720 /* Must make sure nOverflow is reset to zero even if the balance()
57721 ** fails. Internal data structure corruption will result otherwise.
57722 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
@@ -57767,11 +57848,11 @@
57767 ** from the internal node. The 'previous' entry is used for this instead
57768 ** of the 'next' entry, as the previous entry is always a part of the
57769 ** sub-tree headed by the child page of the cell being deleted. This makes
57770 ** balancing the tree following the delete operation easier. */
57771 if( !pPage->leaf ){
57772 int notUsed;
57773 rc = sqlite3BtreePrevious(pCur, &notUsed);
57774 if( rc ) return rc;
57775 }
57776
57777 /* Save the positions of any other cursors open on this table before
@@ -60192,11 +60273,11 @@
60192 }
60193
60194 /*
60195 ** Release any memory held by the Mem. This may leave the Mem in an
60196 ** inconsistent state, for example with (Mem.z==0) and
60197 ** (Mem.type==SQLITE_TEXT).
60198 */
60199 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60200 VdbeMemRelease(p);
60201 if( p->zMalloc ){
60202 sqlite3DbFree(p->db, p->zMalloc);
@@ -60383,11 +60464,11 @@
60383 }
60384 if( pMem->flags & MEM_RowSet ){
60385 sqlite3RowSetClear(pMem->u.pRowSet);
60386 }
60387 MemSetTypeFlag(pMem, MEM_Null);
60388 pMem->type = SQLITE_NULL;
60389 }
60390 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60391 sqlite3VdbeMemSetNull((Mem*)p);
60392 }
60393
@@ -60396,11 +60477,11 @@
60396 ** n containing all zeros.
60397 */
60398 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
60399 sqlite3VdbeMemRelease(pMem);
60400 pMem->flags = MEM_Blob|MEM_Zero;
60401 pMem->type = SQLITE_BLOB;
60402 pMem->n = 0;
60403 if( n<0 ) n = 0;
60404 pMem->u.nZero = n;
60405 pMem->enc = SQLITE_UTF8;
60406
@@ -60419,11 +60500,11 @@
60419 */
60420 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
60421 sqlite3VdbeMemRelease(pMem);
60422 pMem->u.i = val;
60423 pMem->flags = MEM_Int;
60424 pMem->type = SQLITE_INTEGER;
60425 }
60426
60427 #ifndef SQLITE_OMIT_FLOATING_POINT
60428 /*
60429 ** Delete any previous value and set the value stored in *pMem to val,
@@ -60434,11 +60515,11 @@
60434 sqlite3VdbeMemSetNull(pMem);
60435 }else{
60436 sqlite3VdbeMemRelease(pMem);
60437 pMem->r = val;
60438 pMem->flags = MEM_Real;
60439 pMem->type = SQLITE_FLOAT;
60440 }
60441 }
60442 #endif
60443
60444 /*
@@ -60490,11 +60571,11 @@
60490 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
60491 int i;
60492 Mem *pX;
60493 for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
60494 if( pX->pScopyFrom==pMem ){
60495 pX->flags |= MEM_Invalid;
60496 pX->pScopyFrom = 0;
60497 }
60498 }
60499 pMem->pScopyFrom = 0;
60500 }
@@ -60642,11 +60723,11 @@
60642 }
60643
60644 pMem->n = nByte;
60645 pMem->flags = flags;
60646 pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
60647 pMem->type = (enc==0 ? SQLITE_BLOB : SQLITE_TEXT);
60648
60649 #ifndef SQLITE_OMIT_UTF16
60650 if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
60651 return SQLITE_NOMEM;
60652 }
@@ -60813,11 +60894,11 @@
60813 pMem->z = &zData[offset];
60814 pMem->flags = MEM_Blob|MEM_Ephem;
60815 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60816 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60817 pMem->enc = 0;
60818 pMem->type = SQLITE_BLOB;
60819 if( key ){
60820 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60821 }else{
60822 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
60823 }
@@ -60883,11 +60964,11 @@
60883 */
60884 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
60885 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
60886 if( p ){
60887 p->flags = MEM_Null;
60888 p->type = SQLITE_NULL;
60889 p->db = db;
60890 }
60891 return p;
60892 }
60893
@@ -60933,11 +61014,11 @@
60933 assert( pRec->pKeyInfo->enc==ENC(db) );
60934 pRec->flags = UNPACKED_PREFIX_MATCH;
60935 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
60936 for(i=0; i<nCol; i++){
60937 pRec->aMem[i].flags = MEM_Null;
60938 pRec->aMem[i].type = SQLITE_NULL;
60939 pRec->aMem[i].db = db;
60940 }
60941 }else{
60942 sqlite3DbFree(db, pRec);
60943 pRec = 0;
@@ -61006,11 +61087,11 @@
61006 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
61007 }else{
61008 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
61009 if( zVal==0 ) goto no_mem;
61010 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
61011 if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
61012 }
61013 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
61014 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
61015 }else{
61016 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
@@ -61464,10 +61545,13 @@
61464 #endif
61465 #ifdef VDBE_PROFILE
61466 pOp->cycles = 0;
61467 pOp->cnt = 0;
61468 #endif
 
 
 
61469 return i;
61470 }
61471 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *p, int op){
61472 return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
61473 }
@@ -61825,11 +61909,11 @@
61825
61826 /*
61827 ** Add a whole list of operations to the operation stack. Return the
61828 ** address of the first operation added.
61829 */
61830 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61831 int addr;
61832 assert( p->magic==VDBE_MAGIC_INIT );
61833 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
61834 return 0;
61835 }
@@ -61852,10 +61936,15 @@
61852 pOut->p4type = P4_NOTUSED;
61853 pOut->p4.p = 0;
61854 pOut->p5 = 0;
61855 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61856 pOut->zComment = 0;
 
 
 
 
 
61857 #endif
61858 #ifdef SQLITE_DEBUG
61859 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61860 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
61861 }
@@ -62141,10 +62230,19 @@
62141 va_end(ap);
62142 }
62143 }
62144 #endif /* NDEBUG */
62145
 
 
 
 
 
 
 
 
 
62146 /*
62147 ** Return the opcode for a given address. If the address is -1, then
62148 ** return the most recently inserted opcode.
62149 **
62150 ** If a memory allocation error has occurred prior to the calling of this
@@ -62153,28 +62251,17 @@
62153 ** The return of a dummy opcode allows the call to continue functioning
62154 ** after a OOM fault without having to check to see if the return from
62155 ** this routine is a valid pointer. But because the dummy.opcode is 0,
62156 ** dummy will never be written to. This is verified by code inspection and
62157 ** by running with Valgrind.
62158 **
62159 ** About the #ifdef SQLITE_OMIT_TRACE: Normally, this routine is never called
62160 ** unless p->nOp>0. This is because in the absense of SQLITE_OMIT_TRACE,
62161 ** an OP_Trace instruction is always inserted by sqlite3VdbeGet() as soon as
62162 ** a new VDBE is created. So we are free to set addr to p->nOp-1 without
62163 ** having to double-check to make sure that the result is non-negative. But
62164 ** if SQLITE_OMIT_TRACE is defined, the OP_Trace is omitted and we do need to
62165 ** check the value of p->nOp-1 before continuing.
62166 */
62167 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
62168 /* C89 specifies that the constant "dummy" will be initialized to all
62169 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
62170 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
62171 assert( p->magic==VDBE_MAGIC_INIT );
62172 if( addr<0 ){
62173 #ifdef SQLITE_OMIT_TRACE
62174 if( p->nOp==0 ) return (VdbeOp*)&dummy;
62175 #endif
62176 addr = p->nOp - 1;
62177 }
62178 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
62179 if( p->db->mallocFailed ){
62180 return (VdbeOp*)&dummy;
@@ -62475,11 +62562,11 @@
62475 if( pOut==0 ) pOut = stdout;
62476 zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
62477 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62478 displayComment(pOp, zP4, zCom, sizeof(zCom));
62479 #else
62480 zCom[0] = 0
62481 #endif
62482 /* NB: The sqlite3OpcodeName() function is implemented by code created
62483 ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
62484 ** information from the vdbe.c source text */
62485 fprintf(pOut, zFormat1, pc,
@@ -62524,11 +62611,11 @@
62524 }else if( p->zMalloc ){
62525 sqlite3DbFree(db, p->zMalloc);
62526 p->zMalloc = 0;
62527 }
62528
62529 p->flags = MEM_Invalid;
62530 }
62531 db->mallocFailed = malloc_failed;
62532 }
62533 }
62534
@@ -62646,19 +62733,19 @@
62646 }
62647 pOp = &apSub[j]->aOp[i];
62648 }
62649 if( p->explain==1 ){
62650 pMem->flags = MEM_Int;
62651 pMem->type = SQLITE_INTEGER;
62652 pMem->u.i = i; /* Program counter */
62653 pMem++;
62654
62655 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
62656 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
62657 assert( pMem->z!=0 );
62658 pMem->n = sqlite3Strlen30(pMem->z);
62659 pMem->type = SQLITE_TEXT;
62660 pMem->enc = SQLITE_UTF8;
62661 pMem++;
62662
62663 /* When an OP_Program opcode is encounter (the only opcode that has
62664 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
@@ -62680,21 +62767,21 @@
62680 }
62681 }
62682
62683 pMem->flags = MEM_Int;
62684 pMem->u.i = pOp->p1; /* P1 */
62685 pMem->type = SQLITE_INTEGER;
62686 pMem++;
62687
62688 pMem->flags = MEM_Int;
62689 pMem->u.i = pOp->p2; /* P2 */
62690 pMem->type = SQLITE_INTEGER;
62691 pMem++;
62692
62693 pMem->flags = MEM_Int;
62694 pMem->u.i = pOp->p3; /* P3 */
62695 pMem->type = SQLITE_INTEGER;
62696 pMem++;
62697
62698 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62699 assert( p->db->mallocFailed );
62700 return SQLITE_ERROR;
@@ -62706,11 +62793,11 @@
62706 }else{
62707 assert( pMem->z!=0 );
62708 pMem->n = sqlite3Strlen30(pMem->z);
62709 pMem->enc = SQLITE_UTF8;
62710 }
62711 pMem->type = SQLITE_TEXT;
62712 pMem++;
62713
62714 if( p->explain==1 ){
62715 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62716 assert( p->db->mallocFailed );
@@ -62717,11 +62804,11 @@
62717 return SQLITE_ERROR;
62718 }
62719 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62720 pMem->n = 2;
62721 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62722 pMem->type = SQLITE_TEXT;
62723 pMem->enc = SQLITE_UTF8;
62724 pMem++;
62725
62726 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62727 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
@@ -62728,15 +62815,15 @@
62728 assert( p->db->mallocFailed );
62729 return SQLITE_ERROR;
62730 }
62731 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62732 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62733 pMem->type = SQLITE_TEXT;
62734 pMem->enc = SQLITE_UTF8;
62735 #else
62736 pMem->flags = MEM_Null; /* Comment */
62737 pMem->type = SQLITE_NULL;
62738 #endif
62739 }
62740
62741 p->nResColumn = 8 - 4*(p->explain-1);
62742 p->pResultSet = &p->aMem[1];
@@ -62755,11 +62842,11 @@
62755 const char *z = 0;
62756 if( p->zSql ){
62757 z = p->zSql;
62758 }else if( p->nOp>=1 ){
62759 const VdbeOp *pOp = &p->aOp[0];
62760 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62761 z = pOp->p4.z;
62762 while( sqlite3Isspace(*z) ) z++;
62763 }
62764 }
62765 if( z ) printf("SQL: [%s]\n", z);
@@ -62774,11 +62861,11 @@
62774 int nOp = p->nOp;
62775 VdbeOp *pOp;
62776 if( sqlite3IoTrace==0 ) return;
62777 if( nOp<1 ) return;
62778 pOp = &p->aOp[0];
62779 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62780 int i, j;
62781 char z[1000];
62782 sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z);
62783 for(i=0; sqlite3Isspace(z[i]); i++){}
62784 for(j=0; z[i]; i++){
@@ -62992,11 +63079,11 @@
62992 }
62993 if( p->aMem ){
62994 p->aMem--; /* aMem[] goes from 1..nMem */
62995 p->nMem = nMem; /* not from 0..nMem-1 */
62996 for(n=1; n<=nMem; n++){
62997 p->aMem[n].flags = MEM_Invalid;
62998 p->aMem[n].db = db;
62999 }
63000 }
63001 p->explain = pParse->explain;
63002 sqlite3VdbeRewind(p);
@@ -63104,11 +63191,11 @@
63104 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
63105 ** Vdbe.aMem[] arrays have already been cleaned up. */
63106 int i;
63107 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
63108 if( p->aMem ){
63109 for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Invalid );
63110 }
63111 #endif
63112
63113 sqlite3DbFree(db, p->zErrMsg);
63114 p->zErrMsg = 0;
@@ -63853,16 +63940,28 @@
63853 fprintf(out, "---- ");
63854 for(i=0; i<p->nOp; i++){
63855 fprintf(out, "%02x", p->aOp[i].opcode);
63856 }
63857 fprintf(out, "\n");
 
 
 
 
 
 
 
 
 
 
63858 for(i=0; i<p->nOp; i++){
63859 fprintf(out, "%6d %10lld %8lld ",
 
63860 p->aOp[i].cnt,
63861 p->aOp[i].cycles,
63862 p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
63863 );
 
63864 sqlite3VdbePrintOp(out, i, &p->aOp[i]);
63865 }
63866 fclose(out);
63867 }
63868 }
@@ -64895,11 +64994,45 @@
64895 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
64896 return sqlite3ValueText(pVal, SQLITE_UTF16LE);
64897 }
64898 #endif /* SQLITE_OMIT_UTF16 */
64899 SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
64900 return pVal->type;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64901 }
64902
64903 /**************************** sqlite3_result_ *******************************
64904 ** The following routines are used by user-defined functions to specify
64905 ** the function result.
@@ -65854,11 +65987,11 @@
65854 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
65855 }
65856 #endif /* SQLITE_OMIT_UTF16 */
65857 SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
65858 int rc;
65859 switch( pValue->type ){
65860 case SQLITE_INTEGER: {
65861 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
65862 break;
65863 }
65864 case SQLITE_FLOAT: {
@@ -66355,37 +66488,12 @@
66355 ** May you do good and not evil.
66356 ** May you find forgiveness for yourself and forgive others.
66357 ** May you share freely, never taking more than you give.
66358 **
66359 *************************************************************************
66360 ** The code in this file implements execution method of the
66361 ** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c")
66362 ** handles housekeeping details such as creating and deleting
66363 ** VDBE instances. This file is solely interested in executing
66364 ** the VDBE program.
66365 **
66366 ** In the external interface, an "sqlite3_stmt*" is an opaque pointer
66367 ** to a VDBE.
66368 **
66369 ** The SQL parser generates a program which is then executed by
66370 ** the VDBE to do the work of the SQL statement. VDBE programs are
66371 ** similar in form to assembly language. The program consists of
66372 ** a linear sequence of operations. Each operation has an opcode
66373 ** and 5 operands. Operands P1, P2, and P3 are integers. Operand P4
66374 ** is a null-terminated string. Operand P5 is an unsigned character.
66375 ** Few opcodes use all 5 operands.
66376 **
66377 ** Computation results are stored on a set of registers numbered beginning
66378 ** with 1 and going up to Vdbe.nMem. Each register can store
66379 ** either an integer, a null-terminated string, a floating point
66380 ** number, or the SQL "NULL" value. An implicit conversion from one
66381 ** type to the other occurs as necessary.
66382 **
66383 ** Most of the code in this file is taken up by the sqlite3VdbeExec()
66384 ** function which does the work of interpreting a VDBE program.
66385 ** But other routines are also provided to help in building up
66386 ** a program instruction by instruction.
66387 **
66388 ** Various scripts scan this source file in order to generate HTML
66389 ** documentation, headers files, or other derived files. The formatting
66390 ** of the code in this file is, therefore, important. See other comments
66391 ** in this file for details. If in doubt, do not deviate from existing
@@ -66393,11 +66501,15 @@
66393 */
66394
66395 /*
66396 ** Invoke this macro on memory cells just prior to changing the
66397 ** value of the cell. This macro verifies that shallow copies are
66398 ** not misused.
 
 
 
 
66399 */
66400 #ifdef SQLITE_DEBUG
66401 # define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
66402 #else
66403 # define memAboutToChange(P,M)
@@ -66452,11 +66564,11 @@
66452 }
66453 }
66454 #endif
66455
66456 /*
66457 ** The next global variable is incremented each type the OP_Found opcode
66458 ** is executed. This is used to test whether or not the foreign key
66459 ** operation implemented using OP_FkIsZero is working. This variable
66460 ** has no function other than to help verify the correct operation of the
66461 ** library.
66462 */
@@ -66472,10 +66584,38 @@
66472 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
66473 #else
66474 # define UPDATE_MAX_BLOBSIZE(P)
66475 #endif
66476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66477 /*
66478 ** Convert the given register into a string if it isn't one
66479 ** already. Return non-zero if a malloc() fails.
66480 */
66481 #define Stringify(P, enc) \
@@ -66496,35 +66636,11 @@
66496 #define Deephemeralize(P) \
66497 if( ((P)->flags&MEM_Ephem)!=0 \
66498 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
66499
66500 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
66501 # define isSorter(x) ((x)->pSorter!=0)
66502
66503 /*
66504 ** Argument pMem points at a register that will be passed to a
66505 ** user-defined function or returned to the user as the result of a query.
66506 ** This routine sets the pMem->type variable used by the sqlite3_value_*()
66507 ** routines.
66508 */
66509 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem){
66510 int flags = pMem->flags;
66511 if( flags & MEM_Null ){
66512 pMem->type = SQLITE_NULL;
66513 }
66514 else if( flags & MEM_Int ){
66515 pMem->type = SQLITE_INTEGER;
66516 }
66517 else if( flags & MEM_Real ){
66518 pMem->type = SQLITE_FLOAT;
66519 }
66520 else if( flags & MEM_Str ){
66521 pMem->type = SQLITE_TEXT;
66522 }else{
66523 pMem->type = SQLITE_BLOB;
66524 }
66525 }
66526
66527 /*
66528 ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
66529 ** if we run out of memory.
66530 */
@@ -66650,16 +66766,18 @@
66650 ** into a numeric representation. Use either INTEGER or REAL whichever
66651 ** is appropriate. But only do the conversion if it is possible without
66652 ** loss of information and return the revised type of the argument.
66653 */
66654 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
66655 Mem *pMem = (Mem*)pVal;
66656 if( pMem->type==SQLITE_TEXT ){
 
66657 applyNumericAffinity(pMem);
66658 sqlite3VdbeMemStoreType(pMem);
 
66659 }
66660 return pMem->type;
66661 }
66662
66663 /*
66664 ** Exported version of applyAffinity(). This one works on sqlite3_value*,
66665 ** not the internal Mem* type.
@@ -66758,11 +66876,11 @@
66758 #ifdef SQLITE_DEBUG
66759 /*
66760 ** Print the value of a register for tracing purposes:
66761 */
66762 static void memTracePrint(Mem *p){
66763 if( p->flags & MEM_Invalid ){
66764 printf(" undefined");
66765 }else if( p->flags & MEM_Null ){
66766 printf(" NULL");
66767 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66768 printf(" si:%lld", p->u.i);
@@ -66890,24 +67008,10 @@
66890
66891 /************** End of hwtime.h **********************************************/
66892 /************** Continuing where we left off in vdbe.c ***********************/
66893
66894 #endif
66895
66896 /*
66897 ** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
66898 ** sqlite3_interrupt() routine has been called. If it has been, then
66899 ** processing of the VDBE program is interrupted.
66900 **
66901 ** This macro added to every instruction that does a jump in order to
66902 ** implement a loop. This test used to be on every single instruction,
66903 ** but that meant we more testing than we needed. By only testing the
66904 ** flag on jump instructions, we get a (small) speed improvement.
66905 */
66906 #define CHECK_FOR_INTERRUPT \
66907 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
66908
66909
66910 #ifndef NDEBUG
66911 /*
66912 ** This function is only called from within an assert() expression. It
66913 ** checks that the sqlite3.nTransaction variable is correctly set to
@@ -66927,39 +67031,12 @@
66927 }
66928 #endif
66929
66930
66931 /*
66932 ** Execute as much of a VDBE program as we can then return.
66933 **
66934 ** sqlite3VdbeMakeReady() must be called before this routine in order to
66935 ** close the program with a final OP_Halt and to set up the callbacks
66936 ** and the error message pointer.
66937 **
66938 ** Whenever a row or result data is available, this routine will either
66939 ** invoke the result callback (if there is one) or return with
66940 ** SQLITE_ROW.
66941 **
66942 ** If an attempt is made to open a locked database, then this routine
66943 ** will either invoke the busy callback (if there is one) or it will
66944 ** return SQLITE_BUSY.
66945 **
66946 ** If an error occurs, an error message is written to memory obtained
66947 ** from sqlite3_malloc() and p->zErrMsg is made to point to that memory.
66948 ** The error code is stored in p->rc and this routine returns SQLITE_ERROR.
66949 **
66950 ** If the callback ever returns non-zero, then the program exits
66951 ** immediately. There will be no error message but the p->rc field is
66952 ** set to SQLITE_ABORT and this routine will return SQLITE_ERROR.
66953 **
66954 ** A memory allocation error causes p->rc to be set to SQLITE_NOMEM and this
66955 ** routine to return SQLITE_ERROR.
66956 **
66957 ** Other fatal errors return SQLITE_ERROR.
66958 **
66959 ** After this routine has finished, sqlite3VdbeFinalize() should be
66960 ** used to clean up the mess that was left behind.
66961 */
66962 SQLITE_PRIVATE int sqlite3VdbeExec(
66963 Vdbe *p /* The VDBE */
66964 ){
66965 int pc=0; /* The program counter */
@@ -66981,11 +67058,10 @@
66981 Mem *pOut = 0; /* Output operand */
66982 int *aPermute = 0; /* Permutation of columns for OP_Compare */
66983 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66984 #ifdef VDBE_PROFILE
66985 u64 start; /* CPU clock count at start of opcode */
66986 int origPc; /* Program counter at start of opcode */
66987 #endif
66988 /*** INSERT STACK UNION HERE ***/
66989
66990 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
66991 sqlite3VdbeEnter(p);
@@ -66999,11 +67075,11 @@
66999 p->rc = SQLITE_OK;
67000 p->iCurrentTime = 0;
67001 assert( p->explain==0 );
67002 p->pResultSet = 0;
67003 db->busyHandler.nBusy = 0;
67004 CHECK_FOR_INTERRUPT;
67005 sqlite3VdbeIOTraceSql(p);
67006 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67007 if( db->xProgress ){
67008 assert( 0 < db->nProgressOps );
67009 nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
@@ -67043,11 +67119,10 @@
67043 #endif
67044 for(pc=p->pc; rc==SQLITE_OK; pc++){
67045 assert( pc>=0 && pc<p->nOp );
67046 if( db->mallocFailed ) goto no_mem;
67047 #ifdef VDBE_PROFILE
67048 origPc = pc;
67049 start = sqlite3Hwtime();
67050 #endif
67051 nVmStep++;
67052 pOp = &aOp[pc];
67053
@@ -67175,11 +67250,11 @@
67175 ** But that is not due to sloppy coding habits. The code is written this
67176 ** way for performance, to avoid having to run the interrupt and progress
67177 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
67178 ** faster according to "valgrind --tool=cachegrind" */
67179 check_for_interrupt:
67180 CHECK_FOR_INTERRUPT;
67181 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67182 /* Call the progress callback if it is configured and the required number
67183 ** of VDBE ops have been executed (either since this invocation of
67184 ** sqlite3VdbeExec() or since last time the progress callback was called).
67185 ** If the progress callback returns non-zero, exit the virtual machine with
@@ -67215,24 +67290,70 @@
67215 break;
67216 }
67217
67218 /* Opcode: Return P1 * * * *
67219 **
67220 ** Jump to the next instruction after the address in register P1.
 
67221 */
67222 case OP_Return: { /* in1 */
67223 pIn1 = &aMem[pOp->p1];
67224 assert( pIn1->flags & MEM_Int );
67225 pc = (int)pIn1->u.i;
 
67226 break;
67227 }
67228
67229 /* Opcode: Yield P1 * * * *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67230 **
67231 ** Swap the program counter with the value in register P1.
 
 
 
 
67232 */
67233 case OP_Yield: { /* in1 */
67234 int pcDest;
67235 pIn1 = &aMem[pOp->p1];
67236 assert( (pIn1->flags & MEM_Dyn)==0 );
67237 pIn1->flags = MEM_Int;
67238 pcDest = (int)pIn1->u.i;
@@ -67241,11 +67362,11 @@
67241 pc = pcDest;
67242 break;
67243 }
67244
67245 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67246 ** Synopsis: if r[P3] null then halt
67247 **
67248 ** Check the value in register P3. If it is NULL then Halt using
67249 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the
67250 ** value in register P3 is not NULL, then this routine is a no-op.
67251 ** The P5 parameter should be 1.
@@ -67389,11 +67510,13 @@
67389
67390 /* Opcode: String8 * P2 * P4 *
67391 ** Synopsis: r[P2]='P4'
67392 **
67393 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67394 ** into an OP_String before it is executed for the first time.
 
 
67395 */
67396 case OP_String8: { /* same as TK_STRING, out2-prerelease */
67397 assert( pOp->p4.z!=0 );
67398 pOp->opcode = OP_String;
67399 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
@@ -67463,12 +67586,26 @@
67463 cnt--;
67464 }
67465 break;
67466 }
67467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67468
67469 /* Opcode: Blob P1 P2 * P4
67470 ** Synopsis: r[P2]=P4 (len=P1)
67471 **
67472 ** P4 points to a blob of data P1 bytes long. Store this
67473 ** blob in register P2.
67474 */
@@ -67483,11 +67620,11 @@
67483 /* Opcode: Variable P1 P2 * P4 *
67484 ** Synopsis: r[P2]=parameter(P1,P4)
67485 **
67486 ** Transfer the values of bound parameter P1 into register P2
67487 **
67488 ** If the parameter is named, then its name appears in P4 and P3==1.
67489 ** The P4 value is used by sqlite3_bind_parameter_name().
67490 */
67491 case OP_Variable: { /* out2-prerelease */
67492 Mem *pVar; /* Value being transferred */
67493
@@ -67602,12 +67739,12 @@
67602 ** Synopsis: output=r[P1@P2]
67603 **
67604 ** The registers P1 through P1+P2-1 contain a single row of
67605 ** results. This opcode causes the sqlite3_step() call to terminate
67606 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67607 ** structure to provide access to the top P1 values as the result
67608 ** row.
67609 */
67610 case OP_ResultRow: {
67611 Mem *pMem;
67612 int i;
67613 assert( p->nResColumn==pOp->p2 );
@@ -68093,10 +68230,11 @@
68093 */
68094 case OP_MustBeInt: { /* jump, in1 */
68095 pIn1 = &aMem[pOp->p1];
68096 if( (pIn1->flags & MEM_Int)==0 ){
68097 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
 
68098 if( (pIn1->flags & MEM_Int)==0 ){
68099 if( pOp->p2==0 ){
68100 rc = SQLITE_MISMATCH;
68101 goto abort_due_to_error;
68102 }else{
@@ -68131,11 +68269,11 @@
68131 #ifndef SQLITE_OMIT_CAST
68132 /* Opcode: ToText P1 * * * *
68133 **
68134 ** Force the value in register P1 to be text.
68135 ** If the value is numeric, convert it to a string using the
68136 ** equivalent of printf(). Blob values are unchanged and
68137 ** are afterwards simply interpreted as text.
68138 **
68139 ** A NULL value is not changed by this routine. It remains NULL.
68140 */
68141 case OP_ToText: { /* same as TK_TO_TEXT, in1 */
@@ -68333,10 +68471,11 @@
68333 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68334 ** or not both operands are null.
68335 */
68336 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68337 assert( (flags1 & MEM_Cleared)==0 );
 
68338 if( (flags1&MEM_Null)!=0
68339 && (flags3&MEM_Null)!=0
68340 && (flags3&MEM_Cleared)==0
68341 ){
68342 res = 0; /* Results are equal */
@@ -68346,16 +68485,19 @@
68346 }else{
68347 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68348 ** then the result is always NULL.
68349 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
68350 */
68351 if( pOp->p5 & SQLITE_JUMPIFNULL ){
68352 pc = pOp->p2-1;
68353 }else if( pOp->p5 & SQLITE_STOREP2 ){
68354 pOut = &aMem[pOp->p2];
68355 MemSetTypeFlag(pOut, MEM_Null);
68356 REGISTER_TRACE(pOp->p2, pOut);
 
 
 
 
 
68357 }
68358 break;
68359 }
68360 }else{
68361 /* Neither operand is NULL. Do a comparison. */
@@ -68384,14 +68526,16 @@
68384 pOut = &aMem[pOp->p2];
68385 memAboutToChange(p, pOut);
68386 MemSetTypeFlag(pOut, MEM_Int);
68387 pOut->u.i = res;
68388 REGISTER_TRACE(pOp->p2, pOut);
68389 }else if( res ){
68390 pc = pOp->p2-1;
 
 
 
68391 }
68392
68393 /* Undo any changes made by applyAffinity() to the input registers. */
68394 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68395 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68396 break;
68397 }
@@ -68484,15 +68628,15 @@
68484 ** in the most recent OP_Compare instruction the P1 vector was less than
68485 ** equal to, or greater than the P2 vector, respectively.
68486 */
68487 case OP_Jump: { /* jump */
68488 if( iCompare<0 ){
68489 pc = pOp->p1 - 1;
68490 }else if( iCompare==0 ){
68491 pc = pOp->p2 - 1;
68492 }else{
68493 pc = pOp->p3 - 1;
68494 }
68495 break;
68496 }
68497
68498 /* Opcode: And P1 P2 P3 * *
@@ -68586,14 +68730,17 @@
68586 }
68587
68588 /* Opcode: Once P1 P2 * * *
68589 **
68590 ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
68591 ** set the flag and fall through to the next instruction.
 
 
68592 */
68593 case OP_Once: { /* jump */
68594 assert( pOp->p1<p->nOnceFlag );
 
68595 if( p->aOnceFlag[pOp->p1] ){
68596 pc = pOp->p2-1;
68597 }else{
68598 p->aOnceFlag[pOp->p1] = 1;
68599 }
@@ -68624,10 +68771,11 @@
68624 #else
68625 c = sqlite3VdbeRealValue(pIn1)!=0.0;
68626 #endif
68627 if( pOp->opcode==OP_IfNot ) c = !c;
68628 }
 
68629 if( c ){
68630 pc = pOp->p2-1;
68631 }
68632 break;
68633 }
@@ -68637,10 +68785,11 @@
68637 **
68638 ** Jump to P2 if the value in register P1 is NULL.
68639 */
68640 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
68641 pIn1 = &aMem[pOp->p1];
 
68642 if( (pIn1->flags & MEM_Null)!=0 ){
68643 pc = pOp->p2 - 1;
68644 }
68645 break;
68646 }
@@ -68650,10 +68799,11 @@
68650 **
68651 ** Jump to P2 if the value in register P1 is not NULL.
68652 */
68653 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
68654 pIn1 = &aMem[pOp->p1];
 
68655 if( (pIn1->flags & MEM_Null)==0 ){
68656 pc = pOp->p2 - 1;
68657 }
68658 break;
68659 }
@@ -68726,15 +68876,10 @@
68726 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68727 if( pC->nullRow ){
68728 if( pCrsr==0 ){
68729 assert( pC->pseudoTableReg>0 );
68730 pReg = &aMem[pC->pseudoTableReg];
68731 if( pC->multiPseudo ){
68732 sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68733 Deephemeralize(pDest);
68734 goto op_column_out;
68735 }
68736 assert( pReg->flags & MEM_Blob );
68737 assert( memIsValid(pReg) );
68738 pC->payloadSize = pC->szRow = avail = pReg->n;
68739 pC->aRow = (u8*)pReg->z;
68740 }else{
@@ -68956,11 +69101,10 @@
68956 assert( zAffinity[pOp->p2]==0 );
68957 pIn1 = &aMem[pOp->p1];
68958 while( (cAff = *(zAffinity++))!=0 ){
68959 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
68960 assert( memIsValid(pIn1) );
68961 ExpandBlob(pIn1);
68962 applyAffinity(pIn1, cAff, encoding);
68963 pIn1++;
68964 }
68965 break;
68966 }
@@ -69034,12 +69178,13 @@
69034 */
69035 assert( pData0<=pLast );
69036 if( zAffinity ){
69037 pRec = pData0;
69038 do{
69039 applyAffinity(pRec, *(zAffinity++), encoding);
69040 }while( (++pRec)<=pLast );
 
69041 }
69042
69043 /* Loop through the elements that will make up the record to figure
69044 ** out how much space is required for the new record.
69045 */
@@ -69379,29 +69524,23 @@
69379 rc = SQLITE_ERROR;
69380 }
69381 break;
69382 }
69383
69384 /* Opcode: Transaction P1 P2 * * *
69385 **
69386 ** Begin a transaction. The transaction ends when a Commit or Rollback
69387 ** opcode is encountered. Depending on the ON CONFLICT setting, the
69388 ** transaction might also be rolled back if an error is encountered.
 
 
69389 **
69390 ** P1 is the index of the database file on which the transaction is
69391 ** started. Index 0 is the main database file and index 1 is the
69392 ** file used for temporary tables. Indices of 2 or more are used for
69393 ** attached databases.
69394 **
69395 ** If P2 is non-zero, then a write-transaction is started. A RESERVED lock is
69396 ** obtained on the database file when a write-transaction is started. No
69397 ** other process can start another write transaction while this transaction is
69398 ** underway. Starting a write transaction also creates a rollback journal. A
69399 ** write transaction must be started before any changes can be made to the
69400 ** database. If P2 is greater than or equal to 2 then an EXCLUSIVE lock is
69401 ** also obtained on the file.
69402 **
69403 ** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
69404 ** true (this flag is set if the Vdbe may modify more than one row and may
69405 ** throw an ABORT exception), a statement transaction may also be opened.
69406 ** More specifically, a statement transaction is opened iff the database
69407 ** connection is currently not in autocommit mode, or if there are other
@@ -69408,14 +69547,25 @@
69408 ** active statements. A statement transaction allows the changes made by this
69409 ** VDBE to be rolled back after an error without having to roll back the
69410 ** entire transaction. If no error is encountered, the statement transaction
69411 ** will automatically commit when the VDBE halts.
69412 **
69413 ** If P2 is zero, then a read-lock is obtained on the database file.
 
 
 
 
 
 
 
 
 
69414 */
69415 case OP_Transaction: {
69416 Btree *pBt;
 
 
69417
69418 assert( p->bIsReader );
69419 assert( p->readOnly==0 || pOp->p2==0 );
69420 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69421 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
@@ -69455,10 +69605,39 @@
69455 ** counter. If the statement transaction needs to be rolled back,
69456 ** the value of this counter needs to be restored too. */
69457 p->nStmtDefCons = db->nDeferredCons;
69458 p->nStmtDefImmCons = db->nDeferredImmCons;
69459 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69460 }
69461 break;
69462 }
69463
69464 /* Opcode: ReadCookie P1 P2 P3 * *
@@ -69526,70 +69705,10 @@
69526 /* Invalidate all prepared statements whenever the TEMP database
69527 ** schema is changed. Ticket #1644 */
69528 sqlite3ExpirePreparedStatements(db);
69529 p->expired = 0;
69530 }
69531 break;
69532 }
69533
69534 /* Opcode: VerifyCookie P1 P2 P3 * *
69535 **
69536 ** Check the value of global database parameter number 0 (the
69537 ** schema version) and make sure it is equal to P2 and that the
69538 ** generation counter on the local schema parse equals P3.
69539 **
69540 ** P1 is the database number which is 0 for the main database file
69541 ** and 1 for the file holding temporary tables and some higher number
69542 ** for auxiliary databases.
69543 **
69544 ** The cookie changes its value whenever the database schema changes.
69545 ** This operation is used to detect when that the cookie has changed
69546 ** and that the current process needs to reread the schema.
69547 **
69548 ** Either a transaction needs to have been started or an OP_Open needs
69549 ** to be executed (to establish a read lock) before this opcode is
69550 ** invoked.
69551 */
69552 case OP_VerifyCookie: {
69553 int iMeta;
69554 int iGen;
69555 Btree *pBt;
69556
69557 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69558 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69559 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69560 assert( p->bIsReader );
69561 pBt = db->aDb[pOp->p1].pBt;
69562 if( pBt ){
69563 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69564 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69565 }else{
69566 iGen = iMeta = 0;
69567 }
69568 if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69569 sqlite3DbFree(db, p->zErrMsg);
69570 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69571 /* If the schema-cookie from the database file matches the cookie
69572 ** stored with the in-memory representation of the schema, do
69573 ** not reload the schema from the database file.
69574 **
69575 ** If virtual-tables are in use, this is not just an optimization.
69576 ** Often, v-tables store their data in other SQLite tables, which
69577 ** are queried from within xNext() and other v-table methods using
69578 ** prepared queries. If such a query is out-of-date, we do not want to
69579 ** discard the database schema, as the user code implementing the
69580 ** v-table would have to be ready for the sqlite3_vtab structure itself
69581 ** to be invalidated whenever sqlite3_step() is called from within
69582 ** a v-table method.
69583 */
69584 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69585 sqlite3ResetOneSchema(db, pOp->p1);
69586 }
69587
69588 p->expired = 1;
69589 rc = SQLITE_SCHEMA;
69590 }
69591 break;
69592 }
69593
69594 /* Opcode: OpenRead P1 P2 P3 P4 P5
69595 ** Synopsis: root=P2 iDb=P3
@@ -69802,11 +69921,11 @@
69802 }
69803 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69804 break;
69805 }
69806
69807 /* Opcode: SorterOpen P1 * * P4 *
69808 **
69809 ** This opcode works like OP_OpenEphemeral except that it opens
69810 ** a transient index that is specifically designed to sort large
69811 ** tables using an external merge-sort algorithm.
69812 */
@@ -69822,18 +69941,17 @@
69822 assert( pCx->pKeyInfo->enc==ENC(db) );
69823 rc = sqlite3VdbeSorterInit(db, pCx);
69824 break;
69825 }
69826
69827 /* Opcode: OpenPseudo P1 P2 P3 * P5
69828 ** Synopsis: content in r[P2@P3]
69829 **
69830 ** Open a new cursor that points to a fake table that contains a single
69831 ** row of data. The content of that one row in the content of memory
69832 ** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
69833 ** MEM_Blob content contained in register P2. When P5==1, then the
69834 ** row is represented by P3 consecutive registers beginning with P2.
69835 **
69836 ** A pseudo-table created by this opcode is used to hold a single
69837 ** row output from the sorter so that the row can be decomposed into
69838 ** individual columns using the OP_Column opcode. The OP_Column opcode
69839 ** is the only cursor opcode that works with a pseudo-table.
@@ -69849,11 +69967,11 @@
69849 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69850 if( pCx==0 ) goto no_mem;
69851 pCx->nullRow = 1;
69852 pCx->pseudoTableReg = pOp->p2;
69853 pCx->isTable = 1;
69854 pCx->multiPseudo = pOp->p5;
69855 break;
69856 }
69857
69858 /* Opcode: Close P1 * * * *
69859 **
@@ -69921,14 +70039,14 @@
69921 ** is less than or equal to the key value. If there are no records
69922 ** less than or equal to the key and P2 is not zero, then jump to P2.
69923 **
69924 ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
69925 */
69926 case OP_SeekLt: /* jump, in3 */
69927 case OP_SeekLe: /* jump, in3 */
69928 case OP_SeekGe: /* jump, in3 */
69929 case OP_SeekGt: { /* jump, in3 */
69930 int res;
69931 int oc;
69932 VdbeCursor *pC;
69933 UnpackedRecord r;
69934 int nField;
@@ -69937,13 +70055,13 @@
69937 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69938 assert( pOp->p2!=0 );
69939 pC = p->apCsr[pOp->p1];
69940 assert( pC!=0 );
69941 assert( pC->pseudoTableReg==0 );
69942 assert( OP_SeekLe == OP_SeekLt+1 );
69943 assert( OP_SeekGe == OP_SeekLt+2 );
69944 assert( OP_SeekGt == OP_SeekLt+3 );
69945 assert( pC->isOrdered );
69946 assert( pC->pCursor!=0 );
69947 oc = pOp->opcode;
69948 pC->nullRow = 0;
69949 if( pC->isTable ){
@@ -69959,11 +70077,11 @@
69959 ** loss of information, then special processing is required... */
69960 if( (pIn3->flags & MEM_Int)==0 ){
69961 if( (pIn3->flags & MEM_Real)==0 ){
69962 /* If the P3 value cannot be converted into any kind of a number,
69963 ** then the seek is not possible, so jump to P2 */
69964 pc = pOp->p2 - 1;
69965 break;
69966 }
69967
69968 /* If the approximation iKey is larger than the actual real search
69969 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -69971,23 +70089,23 @@
69971 **
69972 ** (x > 4.9) -> (x >= 5)
69973 ** (x <= 4.9) -> (x < 5)
69974 */
69975 if( pIn3->r<(double)iKey ){
69976 assert( OP_SeekGe==(OP_SeekGt-1) );
69977 assert( OP_SeekLt==(OP_SeekLe-1) );
69978 assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69979 if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
69980 }
69981
69982 /* If the approximation iKey is smaller than the actual real search
69983 ** term, substitute <= for < and > for >=. */
69984 else if( pIn3->r>(double)iKey ){
69985 assert( OP_SeekLe==(OP_SeekLt+1) );
69986 assert( OP_SeekGt==(OP_SeekGe+1) );
69987 assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69988 if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
69989 }
69990 }
69991 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
69992 if( rc!=SQLITE_OK ){
69993 goto abort_due_to_error;
@@ -70002,21 +70120,21 @@
70002 assert( nField>0 );
70003 r.pKeyInfo = pC->pKeyInfo;
70004 r.nField = (u16)nField;
70005
70006 /* The next line of code computes as follows, only faster:
70007 ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
70008 ** r.flags = UNPACKED_INCRKEY;
70009 ** }else{
70010 ** r.flags = 0;
70011 ** }
70012 */
70013 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
70014 assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
70015 assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
70016 assert( oc!=OP_SeekGe || r.flags==0 );
70017 assert( oc!=OP_SeekLt || r.flags==0 );
70018
70019 r.aMem = &aMem[pOp->p3];
70020 #ifdef SQLITE_DEBUG
70021 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70022 #endif
@@ -70030,21 +70148,23 @@
70030 pC->deferredMoveto = 0;
70031 pC->cacheStatus = CACHE_STALE;
70032 #ifdef SQLITE_TEST
70033 sqlite3_search_count++;
70034 #endif
70035 if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
70036 if( res<0 || (res==0 && oc==OP_SeekGt) ){
 
70037 rc = sqlite3BtreeNext(pC->pCursor, &res);
70038 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70039 pC->rowidIsValid = 0;
70040 }else{
70041 res = 0;
70042 }
70043 }else{
70044 assert( oc==OP_SeekLt || oc==OP_SeekLe );
70045 if( res>0 || (res==0 && oc==OP_SeekLt) ){
 
70046 rc = sqlite3BtreePrevious(pC->pCursor, &res);
70047 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70048 pC->rowidIsValid = 0;
70049 }else{
70050 /* res might be negative because the table is empty. Check to
@@ -70052,10 +70172,11 @@
70052 */
70053 res = sqlite3BtreeEof(pC->pCursor);
70054 }
70055 }
70056 assert( pOp->p2>0 );
 
70057 if( res ){
70058 pc = pOp->p2 - 1;
70059 }
70060 break;
70061 }
@@ -70160,19 +70281,17 @@
70160 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
70161 if( pOp->p4.i>0 ){
70162 r.pKeyInfo = pC->pKeyInfo;
70163 r.nField = (u16)pOp->p4.i;
70164 r.aMem = pIn3;
 
 
 
70165 #ifdef SQLITE_DEBUG
70166 {
70167 int i;
70168 for(i=0; i<r.nField; i++){
70169 assert( memIsValid(&r.aMem[i]) );
70170 if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
70171 }
70172 }
70173 #endif
70174 r.flags = UNPACKED_PREFIX_MATCH;
70175 pIdxKey = &r;
70176 }else{
70177 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70178 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
@@ -70187,11 +70306,11 @@
70187 /* For the OP_NoConflict opcode, take the jump if any of the
70188 ** input fields are NULL, since any key with a NULL will not
70189 ** conflict */
70190 for(ii=0; ii<r.nField; ii++){
70191 if( r.aMem[ii].flags & MEM_Null ){
70192 pc = pOp->p2 - 1;
70193 break;
70194 }
70195 }
70196 }
70197 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
@@ -70205,12 +70324,14 @@
70205 alreadyExists = (res==0);
70206 pC->nullRow = 1-alreadyExists;
70207 pC->deferredMoveto = 0;
70208 pC->cacheStatus = CACHE_STALE;
70209 if( pOp->opcode==OP_Found ){
 
70210 if( alreadyExists ) pc = pOp->p2 - 1;
70211 }else{
 
70212 if( !alreadyExists ) pc = pOp->p2 - 1;
70213 }
70214 break;
70215 }
70216
@@ -70249,10 +70370,11 @@
70249 pC->lastRowid = pIn3->u.i;
70250 pC->rowidIsValid = res==0 ?1:0;
70251 pC->nullRow = 0;
70252 pC->cacheStatus = CACHE_STALE;
70253 pC->deferredMoveto = 0;
 
70254 if( res!=0 ){
70255 pc = pOp->p2 - 1;
70256 assert( pC->rowidIsValid==0 );
70257 }
70258 pC->seekResult = res;
@@ -70330,63 +70452,58 @@
70330 */
70331 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70332 #endif
70333
70334 if( !pC->useRandomRowid ){
70335 v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70336 if( v==0 ){
70337 rc = sqlite3BtreeLast(pC->pCursor, &res);
70338 if( rc!=SQLITE_OK ){
70339 goto abort_due_to_error;
70340 }
70341 if( res ){
70342 v = 1; /* IMP: R-61914-48074 */
70343 }else{
70344 assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70345 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70346 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70347 if( v>=MAX_ROWID ){
70348 pC->useRandomRowid = 1;
70349 }else{
70350 v++; /* IMP: R-29538-34987 */
70351 }
70352 }
70353 }
70354
70355 #ifndef SQLITE_OMIT_AUTOINCREMENT
70356 if( pOp->p3 ){
70357 /* Assert that P3 is a valid memory cell. */
70358 assert( pOp->p3>0 );
70359 if( p->pFrame ){
70360 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70361 /* Assert that P3 is a valid memory cell. */
70362 assert( pOp->p3<=pFrame->nMem );
70363 pMem = &pFrame->aMem[pOp->p3];
70364 }else{
70365 /* Assert that P3 is a valid memory cell. */
70366 assert( pOp->p3<=(p->nMem-p->nCursor) );
70367 pMem = &aMem[pOp->p3];
70368 memAboutToChange(p, pMem);
70369 }
70370 assert( memIsValid(pMem) );
70371
70372 REGISTER_TRACE(pOp->p3, pMem);
70373 sqlite3VdbeMemIntegerify(pMem);
70374 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70375 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70376 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70377 goto abort_due_to_error;
70378 }
70379 if( v<pMem->u.i+1 ){
70380 v = pMem->u.i + 1;
70381 }
70382 pMem->u.i = v;
70383 }
70384 #endif
70385
70386 sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70387 }
70388 if( pC->useRandomRowid ){
70389 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70390 ** largest possible integer (9223372036854775807) then the database
70391 ** engine starts picking positive candidate ROWIDs at random until
70392 ** it finds one that is not previously used. */
@@ -70516,11 +70633,10 @@
70516 if( pData->flags & MEM_Zero ){
70517 nZero = pData->u.nZero;
70518 }else{
70519 nZero = 0;
70520 }
70521 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70522 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70523 pData->z, pData->n, nZero,
70524 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
70525 );
70526 pC->rowidIsValid = 0;
@@ -70578,11 +70694,10 @@
70578 **/
70579 assert( pC->deferredMoveto==0 );
70580 rc = sqlite3VdbeCursorMoveto(pC);
70581 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70582
70583 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70584 rc = sqlite3BtreeDelete(pC->pCursor);
70585 pC->cacheStatus = CACHE_STALE;
70586
70587 /* Invoke the update-hook if required. */
70588 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
@@ -70630,10 +70745,11 @@
70630 assert( isSorter(pC) );
70631 assert( pOp->p4type==P4_INT32 );
70632 pIn3 = &aMem[pOp->p3];
70633 nIgnore = pOp->p4.i;
70634 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
 
70635 if( res ){
70636 pc = pOp->p2-1;
70637 }
70638 break;
70639 };
@@ -70667,11 +70783,11 @@
70667 /* Opcode: RowKey P1 P2 * * *
70668 ** Synopsis: r[P2]=key
70669 **
70670 ** Write into register P2 the complete row key for cursor P1.
70671 ** There is no interpretation of the data.
70672 ** The key is copied onto the P3 register exactly as
70673 ** it is found in the database file.
70674 **
70675 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70676 ** of a real table, not a pseudo-table.
70677 */
@@ -70829,12 +70945,13 @@
70829 rc = sqlite3BtreeLast(pCrsr, &res);
70830 pC->nullRow = (u8)res;
70831 pC->deferredMoveto = 0;
70832 pC->rowidIsValid = 0;
70833 pC->cacheStatus = CACHE_STALE;
70834 if( pOp->p2>0 && res ){
70835 pc = pOp->p2 - 1;
 
70836 }
70837 break;
70838 }
70839
70840
@@ -70887,56 +71004,67 @@
70887 pC->cacheStatus = CACHE_STALE;
70888 pC->rowidIsValid = 0;
70889 }
70890 pC->nullRow = (u8)res;
70891 assert( pOp->p2>0 && pOp->p2<p->nOp );
 
70892 if( res ){
70893 pc = pOp->p2 - 1;
70894 }
70895 break;
70896 }
70897
70898 /* Opcode: Next P1 P2 * * P5
70899 **
70900 ** Advance cursor P1 so that it points to the next key/data pair in its
70901 ** table or index. If there are no more key/value pairs then fall through
70902 ** to the following instruction. But if the cursor advance was successful,
70903 ** jump immediately to P2.
70904 **
70905 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
70906 ** been opened prior to this opcode or the program will segfault.
 
 
 
 
 
70907 **
70908 ** P4 is always of type P4_ADVANCE. The function pointer points to
70909 ** sqlite3BtreeNext().
70910 **
70911 ** If P5 is positive and the jump is taken, then event counter
70912 ** number P5-1 in the prepared statement is incremented.
70913 **
70914 ** See also: Prev, NextIfOpen
70915 */
70916 /* Opcode: NextIfOpen P1 P2 * * P5
70917 **
70918 ** This opcode works just like OP_Next except that if cursor P1 is not
70919 ** open it behaves a no-op.
70920 */
70921 /* Opcode: Prev P1 P2 * * P5
70922 **
70923 ** Back up cursor P1 so that it points to the previous key/data pair in its
70924 ** table or index. If there is no previous key/value pairs then fall through
70925 ** to the following instruction. But if the cursor backup was successful,
70926 ** jump immediately to P2.
70927 **
70928 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
70929 ** not open then the behavior is undefined.
 
 
 
 
 
70930 **
70931 ** P4 is always of type P4_ADVANCE. The function pointer points to
70932 ** sqlite3BtreePrevious().
70933 **
70934 ** If P5 is positive and the jump is taken, then event counter
70935 ** number P5-1 in the prepared statement is incremented.
70936 */
70937 /* Opcode: PrevIfOpen P1 P2 * * P5
70938 **
70939 ** This opcode works just like OP_Prev except that if cursor P1 is not
70940 ** open it behaves a no-op.
70941 */
70942 case OP_SorterNext: { /* jump */
@@ -70954,20 +71082,24 @@
70954 case OP_Prev: /* jump */
70955 case OP_Next: /* jump */
70956 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70957 assert( pOp->p5<ArraySize(p->aCounter) );
70958 pC = p->apCsr[pOp->p1];
 
70959 assert( pC!=0 );
70960 assert( pC->deferredMoveto==0 );
70961 assert( pC->pCursor );
 
 
70962 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
70963 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
70964 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
70965 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
70966 rc = pOp->p4.xAdvance(pC->pCursor, &res);
70967 next_tail:
70968 pC->cacheStatus = CACHE_STALE;
 
70969 if( res==0 ){
70970 pC->nullRow = 0;
70971 pc = pOp->p2 - 1;
70972 p->aCounter[pOp->p5]++;
70973 #ifdef SQLITE_TEST
@@ -70987,10 +71119,18 @@
70987 ** MakeRecord instructions. This opcode writes that key
70988 ** into the index P1. Data for the entry is nil.
70989 **
70990 ** P3 is a flag that provides a hint to the b-tree layer that this
70991 ** insert is likely to be an append.
 
 
 
 
 
 
 
 
70992 **
70993 ** This instruction only works for indices. The equivalent instruction
70994 ** for tables is OP_Insert.
70995 */
70996 case OP_SorterInsert: /* in2 */
@@ -71102,36 +71242,54 @@
71102
71103 /* Opcode: IdxGE P1 P2 P3 P4 P5
71104 ** Synopsis: key=r[P3@P4]
71105 **
71106 ** The P4 register values beginning with P3 form an unpacked index
71107 ** key that omits the ROWID. Compare this key value against the index
71108 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
 
71109 **
71110 ** If the P1 index entry is greater than or equal to the key value
71111 ** then jump to P2. Otherwise fall through to the next instruction.
 
 
 
71112 **
71113 ** If P5 is non-zero then the key value is increased by an epsilon
71114 ** prior to the comparison. This make the opcode work like IdxGT except
71115 ** that if the key from register P3 is a prefix of the key in the cursor,
71116 ** the result is false whereas it would be true with IdxGT.
 
 
 
71117 */
71118 /* Opcode: IdxLT P1 P2 P3 P4 P5
71119 ** Synopsis: key=r[P3@P4]
71120 **
71121 ** The P4 register values beginning with P3 form an unpacked index
71122 ** key that omits the ROWID. Compare this key value against the index
71123 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
 
71124 **
71125 ** If the P1 index entry is less than the key value then jump to P2.
71126 ** Otherwise fall through to the next instruction.
 
 
 
71127 **
71128 ** If P5 is non-zero then the key value is increased by an epsilon prior
71129 ** to the comparison. This makes the opcode work like IdxLE.
 
 
 
 
 
71130 */
 
 
71131 case OP_IdxLT: /* jump */
71132 case OP_IdxGE: { /* jump */
71133 VdbeCursor *pC;
71134 int res;
71135 UnpackedRecord r;
71136
71137 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -71142,27 +71300,32 @@
71142 assert( pC->deferredMoveto==0 );
71143 assert( pOp->p5==0 || pOp->p5==1 );
71144 assert( pOp->p4type==P4_INT32 );
71145 r.pKeyInfo = pC->pKeyInfo;
71146 r.nField = (u16)pOp->p4.i;
71147 if( pOp->p5 ){
 
71148 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71149 }else{
 
71150 r.flags = UNPACKED_PREFIX_MATCH;
71151 }
71152 r.aMem = &aMem[pOp->p3];
71153 #ifdef SQLITE_DEBUG
71154 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71155 #endif
71156 res = 0; /* Not needed. Only used to silence a warning. */
71157 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71158 if( pOp->opcode==OP_IdxLT ){
 
 
71159 res = -res;
71160 }else{
71161 assert( pOp->opcode==OP_IdxGE );
71162 res++;
71163 }
 
71164 if( res>0 ){
71165 pc = pOp->p2 - 1 ;
71166 }
71167 break;
71168 }
@@ -71251,11 +71414,10 @@
71251 case OP_Clear: {
71252 int nChange;
71253
71254 nChange = 0;
71255 assert( p->readOnly==0 );
71256 assert( pOp->p1!=1 );
71257 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71258 rc = sqlite3BtreeClearTable(
71259 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
71260 );
71261 if( pOp->p3 ){
@@ -71520,13 +71682,15 @@
71520 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71521 ){
71522 /* The boolean index is empty */
71523 sqlite3VdbeMemSetNull(pIn1);
71524 pc = pOp->p2 - 1;
 
71525 }else{
71526 /* A value was pulled from the index */
71527 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
 
71528 }
71529 goto check_for_interrupt;
71530 }
71531
71532 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71574,10 +71738,11 @@
71574 assert( iSet==-1 || iSet>=0 );
71575 if( iSet ){
71576 exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71577 (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71578 pIn3->u.i);
 
71579 if( exists ){
71580 pc = pOp->p2 - 1;
71581 break;
71582 }
71583 }
@@ -71588,11 +71753,11 @@
71588 }
71589
71590
71591 #ifndef SQLITE_OMIT_TRIGGER
71592
71593 /* Opcode: Program P1 P2 P3 P4 *
71594 **
71595 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
71596 **
71597 ** P1 contains the address of the memory cell that contains the first memory
71598 ** cell in an array of values used as arguments to the sub-program. P2
@@ -71600,10 +71765,12 @@
71600 ** exception using the RAISE() function. Register P3 contains the address
71601 ** of a memory cell in this (the parent) VM that is used to allocate the
71602 ** memory required by the sub-vdbe at runtime.
71603 **
71604 ** P4 is a pointer to the VM containing the trigger program.
 
 
71605 */
71606 case OP_Program: { /* jump */
71607 int nMem; /* Number of memory registers for sub-program */
71608 int nByte; /* Bytes of runtime space required for sub-program */
71609 Mem *pRt; /* Register to allocate runtime space */
@@ -71677,11 +71844,11 @@
71677 pFrame->aOnceFlag = p->aOnceFlag;
71678 pFrame->nOnceFlag = p->nOnceFlag;
71679
71680 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71681 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71682 pMem->flags = MEM_Invalid;
71683 pMem->db = db;
71684 }
71685 }else{
71686 pFrame = pRt->u.pFrame;
71687 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
@@ -71764,12 +71931,14 @@
71764 ** zero, the jump is taken if the statement constraint-counter is zero
71765 ** (immediate foreign key constraint violations).
71766 */
71767 case OP_FkIfZero: { /* jump */
71768 if( pOp->p1 ){
 
71769 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71770 }else{
 
71771 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71772 }
71773 break;
71774 }
71775 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
@@ -71814,10 +71983,11 @@
71814 ** not contain an integer. An assertion fault will result if you try.
71815 */
71816 case OP_IfPos: { /* jump, in1 */
71817 pIn1 = &aMem[pOp->p1];
71818 assert( pIn1->flags&MEM_Int );
 
71819 if( pIn1->u.i>0 ){
71820 pc = pOp->p2 - 1;
71821 }
71822 break;
71823 }
@@ -71831,10 +72001,11 @@
71831 ** not contain an integer. An assertion fault will result if you try.
71832 */
71833 case OP_IfNeg: { /* jump, in1 */
71834 pIn1 = &aMem[pOp->p1];
71835 assert( pIn1->flags&MEM_Int );
 
71836 if( pIn1->u.i<0 ){
71837 pc = pOp->p2 - 1;
71838 }
71839 break;
71840 }
@@ -71850,10 +72021,11 @@
71850 */
71851 case OP_IfZero: { /* jump, in1 */
71852 pIn1 = &aMem[pOp->p1];
71853 assert( pIn1->flags&MEM_Int );
71854 pIn1->u.i += pOp->p3;
 
71855 if( pIn1->u.i==0 ){
71856 pc = pOp->p2 - 1;
71857 }
71858 break;
71859 }
@@ -71987,11 +72159,11 @@
71987 break;
71988 };
71989 #endif
71990
71991 #ifndef SQLITE_OMIT_PRAGMA
71992 /* Opcode: JournalMode P1 P2 P3 * P5
71993 **
71994 ** Change the journal mode of database P1 to P3. P3 must be one of the
71995 ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
71996 ** modes (delete, truncate, persist, off and memory), this is a simple
71997 ** operation. No IO is required.
@@ -72121,10 +72293,11 @@
72121 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72122 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72123 assert( p->readOnly==0 );
72124 pBt = db->aDb[pOp->p1].pBt;
72125 rc = sqlite3BtreeIncrVacuum(pBt);
 
72126 if( rc==SQLITE_DONE ){
72127 pc = pOp->p2 - 1;
72128 rc = SQLITE_OK;
72129 }
72130 break;
@@ -72327,11 +72500,11 @@
72327 p->inVtabMethod = 0;
72328 sqlite3VtabImportErrmsg(p, pVtab);
72329 if( rc==SQLITE_OK ){
72330 res = pModule->xEof(pVtabCursor);
72331 }
72332
72333 if( res ){
72334 pc = pOp->p2 - 1;
72335 }
72336 }
72337 pCur->nullRow = 0;
@@ -72432,11 +72605,11 @@
72432 p->inVtabMethod = 0;
72433 sqlite3VtabImportErrmsg(p, pVtab);
72434 if( rc==SQLITE_OK ){
72435 res = pModule->xEof(pCur->pVtabCursor);
72436 }
72437
72438 if( !res ){
72439 /* If there is data, jump to P2 */
72440 pc = pOp->p2 - 1;
72441 }
72442 goto check_for_interrupt;
@@ -72473,11 +72646,11 @@
72473 break;
72474 }
72475 #endif
72476
72477 #ifndef SQLITE_OMIT_VIRTUALTABLE
72478 /* Opcode: VUpdate P1 P2 P3 P4 *
72479 ** Synopsis: data=r[P3@P2]
72480 **
72481 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72482 ** This opcode invokes the corresponding xUpdate method. P2 values
72483 ** are contiguous memory cells starting at P3 to pass to the xUpdate
@@ -72496,10 +72669,13 @@
72496 ** a row to delete.
72497 **
72498 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72499 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72500 ** is set to the value of the rowid for the row just inserted.
 
 
 
72501 */
72502 case OP_VUpdate: {
72503 sqlite3_vtab *pVtab;
72504 sqlite3_module *pModule;
72505 int nArg;
@@ -72584,20 +72760,30 @@
72584 break;
72585 }
72586 #endif
72587
72588
72589 #ifndef SQLITE_OMIT_TRACE
72590 /* Opcode: Trace * * * P4 *
 
 
 
72591 **
72592 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72593 ** the UTF-8 string contained in P4 is emitted on the trace callback.
 
 
 
72594 */
72595 case OP_Trace: {
72596 char *zTrace;
72597 char *z;
72598
 
 
 
 
72599 if( db->xTrace
72600 && !p->doingRerun
72601 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72602 ){
72603 z = sqlite3VdbeExpandSql(p, zTrace);
@@ -72619,13 +72805,13 @@
72619 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72620 ){
72621 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72622 }
72623 #endif /* SQLITE_DEBUG */
 
72624 break;
72625 }
72626 #endif
72627
72628
72629 /* Opcode: Noop * * * * *
72630 **
72631 ** Do nothing. This instruction is often useful as a jump
@@ -72653,14 +72839,10 @@
72653 #ifdef VDBE_PROFILE
72654 {
72655 u64 elapsed = sqlite3Hwtime() - start;
72656 pOp->cycles += elapsed;
72657 pOp->cnt++;
72658 #if 0
72659 fprintf(stdout, "%10llu ", elapsed);
72660 sqlite3VdbePrintOp(stdout, origPc, &aOp[origPc]);
72661 #endif
72662 }
72663 #endif
72664
72665 /* The following code adds nothing to the actual functionality
72666 ** of the program. It is only here for testing and debugging.
@@ -72882,26 +73064,24 @@
72882 **
72883 ** The sqlite3_blob_close() function finalizes the vdbe program,
72884 ** which closes the b-tree cursor and (possibly) commits the
72885 ** transaction.
72886 */
 
72887 static const VdbeOpList openBlob[] = {
72888 {OP_Transaction, 0, 0, 0}, /* 0: Start a transaction */
72889 {OP_VerifyCookie, 0, 0, 0}, /* 1: Check the schema cookie */
72890 {OP_TableLock, 0, 0, 0}, /* 2: Acquire a read or write lock */
72891
72892 /* One of the following two instructions is replaced by an OP_Noop. */
72893 {OP_OpenRead, 0, 0, 0}, /* 3: Open cursor 0 for reading */
72894 {OP_OpenWrite, 0, 0, 0}, /* 4: Open cursor 0 for read/write */
72895
72896 {OP_Variable, 1, 1, 1}, /* 5: Push the rowid to the stack */
72897 {OP_NotExists, 0, 10, 1}, /* 6: Seek the cursor */
72898 {OP_Column, 0, 0, 1}, /* 7 */
72899 {OP_ResultRow, 1, 0, 0}, /* 8 */
72900 {OP_Goto, 0, 5, 0}, /* 9 */
72901 {OP_Close, 0, 0, 0}, /* 10 */
72902 {OP_Halt, 0, 0, 0}, /* 11 */
72903 };
72904
72905 int rc = SQLITE_OK;
72906 char *zErr = 0;
72907 Table *pTab;
@@ -73010,50 +73190,45 @@
73010 assert( pBlob->pStmt || db->mallocFailed );
73011 if( pBlob->pStmt ){
73012 Vdbe *v = (Vdbe *)pBlob->pStmt;
73013 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73014
73015 sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
73016
73017
73018 /* Configure the OP_Transaction */
73019 sqlite3VdbeChangeP1(v, 0, iDb);
73020 sqlite3VdbeChangeP2(v, 0, flags);
73021
73022 /* Configure the OP_VerifyCookie */
73023 sqlite3VdbeChangeP1(v, 1, iDb);
73024 sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
73025 sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration);
73026
73027 /* Make sure a mutex is held on the table to be accessed */
73028 sqlite3VdbeUsesBtree(v, iDb);
73029
73030 /* Configure the OP_TableLock instruction */
73031 #ifdef SQLITE_OMIT_SHARED_CACHE
73032 sqlite3VdbeChangeToNoop(v, 2);
73033 #else
73034 sqlite3VdbeChangeP1(v, 2, iDb);
73035 sqlite3VdbeChangeP2(v, 2, pTab->tnum);
73036 sqlite3VdbeChangeP3(v, 2, flags);
73037 sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
73038 #endif
73039
73040 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
73041 ** parameter of the other to pTab->tnum. */
73042 sqlite3VdbeChangeToNoop(v, 4 - flags);
73043 sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
73044 sqlite3VdbeChangeP3(v, 3 + flags, iDb);
73045
73046 /* Configure the number of columns. Configure the cursor to
73047 ** think that the table has one more column than it really
73048 ** does. An OP_Column to retrieve this imaginary column will
73049 ** always return an SQL NULL. This is useful because it means
73050 ** we can invoke OP_Column to fill in the vdbe cursors type
73051 ** and offset cache without causing any IO.
73052 */
73053 sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73054 sqlite3VdbeChangeP2(v, 7, pTab->nCol);
73055 if( !db->mallocFailed ){
73056 pParse->nVar = 1;
73057 pParse->nMem = 1;
73058 pParse->nTab = 1;
73059 sqlite3VdbeMakeReady(v, pParse);
@@ -75317,12 +75492,12 @@
75317 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75318
75319 /*
75320 ** Perhaps the name is a reference to the ROWID
75321 */
75322 assert( pTab!=0 || cntTab==0 );
75323 if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75324 cnt = 1;
75325 pExpr->iColumn = -1; /* IMP: R-44911-55124 */
75326 pExpr->affinity = SQLITE_AFF_INTEGER;
75327 }
75328
@@ -77449,11 +77624,10 @@
77449 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
77450 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
77451 pNew->iLimit = 0;
77452 pNew->iOffset = 0;
77453 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
77454 pNew->pRightmost = 0;
77455 pNew->addrOpenEphm[0] = -1;
77456 pNew->addrOpenEphm[1] = -1;
77457 pNew->addrOpenEphm[2] = -1;
77458 pNew->nSelectRow = p->nSelectRow;
77459 pNew->pWith = withDup(db, p->pWith);
@@ -77759,28 +77933,10 @@
77759 default:
77760 return 1;
77761 }
77762 }
77763
77764 /*
77765 ** Generate an OP_IsNull instruction that tests register iReg and jumps
77766 ** to location iDest if the value in iReg is NULL. The value in iReg
77767 ** was computed by pExpr. If we can look at pExpr at compile-time and
77768 ** determine that it can never generate a NULL, then the OP_IsNull operation
77769 ** can be omitted.
77770 */
77771 SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(
77772 Vdbe *v, /* The VDBE under construction */
77773 const Expr *pExpr, /* Only generate OP_IsNull if this expr can be NULL */
77774 int iReg, /* Test the value in this register for NULL */
77775 int iDest /* Jump here if the value is null */
77776 ){
77777 if( sqlite3ExprCanBeNull(pExpr) ){
77778 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest);
77779 }
77780 }
77781
77782 /*
77783 ** Return TRUE if the given expression is a constant which would be
77784 ** unchanged by OP_Affinity with the affinity given in the second
77785 ** argument.
77786 **
@@ -77973,11 +78129,11 @@
77973 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
77974 pTab = p->pSrc->a[0].pTab;
77975 pExpr = p->pEList->a[0].pExpr;
77976 iCol = (i16)pExpr->iColumn;
77977
77978 /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
77979 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
77980 sqlite3CodeVerifySchema(pParse, iDb);
77981 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
77982
77983 /* This function is only called from two places. In both cases the vdbe
@@ -77984,13 +78140,12 @@
77984 ** has already been allocated. So assume sqlite3GetVdbe() is always
77985 ** successful here.
77986 */
77987 assert(v);
77988 if( iCol<0 ){
77989 int iAddr;
77990
77991 iAddr = sqlite3CodeOnce(pParse);
77992
77993 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
77994 eType = IN_INDEX_ROWID;
77995
77996 sqlite3VdbeJumpHere(v, iAddr);
@@ -78011,22 +78166,22 @@
78011 for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
78012 if( (pIdx->aiColumn[0]==iCol)
78013 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
78014 && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
78015 ){
78016 int iAddr = sqlite3CodeOnce(pParse);
78017 sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
78018 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
78019 VdbeComment((v, "%s", pIdx->zName));
78020 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
78021 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
78022
78023 sqlite3VdbeJumpHere(v, iAddr);
78024 if( prNotFound && !pTab->aCol[iCol].notNull ){
78025 *prNotFound = ++pParse->nMem;
78026 sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
78027 }
 
78028 }
78029 }
78030 }
78031 }
78032
@@ -78111,11 +78266,11 @@
78111 **
78112 ** If all of the above are false, then we can run this code just once
78113 ** save the results, and reuse the same result on subsequent invocations.
78114 */
78115 if( !ExprHasProperty(pExpr, EP_VarSelect) ){
78116 testAddr = sqlite3CodeOnce(pParse);
78117 }
78118
78119 #ifndef SQLITE_OMIT_EXPLAIN
78120 if( pParse->explain==2 ){
78121 char *zMsg = sqlite3MPrintf(
@@ -78152,11 +78307,10 @@
78152 ** 'x' nor the SELECT... statement are columns, then numeric affinity
78153 ** is used.
78154 */
78155 pExpr->iTable = pParse->nTab++;
78156 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
78157 if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
78158 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
78159
78160 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
78161 /* Case 1: expr IN (SELECT ...)
78162 **
@@ -78228,10 +78382,11 @@
78228 }else{
78229 r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
78230 if( isRowid ){
78231 sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
78232 sqlite3VdbeCurrentAddr(v)+2);
 
78233 sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
78234 }else{
78235 sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
78236 sqlite3ExprCacheAffinityChange(pParse, r3, 1);
78237 sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
@@ -78351,23 +78506,25 @@
78351 ** on whether the RHS is empty or not, respectively.
78352 */
78353 if( destIfNull==destIfFalse ){
78354 /* Shortcut for the common case where the false and NULL outcomes are
78355 ** the same. */
78356 sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull);
78357 }else{
78358 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1);
78359 sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
 
78360 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
78361 sqlite3VdbeJumpHere(v, addr1);
78362 }
78363
78364 if( eType==IN_INDEX_ROWID ){
78365 /* In this case, the RHS is the ROWID of table b-tree
78366 */
78367 sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse);
78368 sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
 
78369 }else{
78370 /* In this case, the RHS is an index b-tree.
78371 */
78372 sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
78373
@@ -78384,42 +78541,40 @@
78384 **
78385 ** Also run this branch if NULL is equivalent to FALSE
78386 ** for this particular IN operator.
78387 */
78388 sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1);
78389
78390 }else{
78391 /* In this branch, the RHS of the IN might contain a NULL and
78392 ** the presence of a NULL on the RHS makes a difference in the
78393 ** outcome.
78394 */
78395 int j1, j2, j3;
78396
78397 /* First check to see if the LHS is contained in the RHS. If so,
78398 ** then the presence of NULLs in the RHS does not matter, so jump
78399 ** over all of the code that follows.
78400 */
78401 j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
 
78402
78403 /* Here we begin generating code that runs if the LHS is not
78404 ** contained within the RHS. Generate additional code that
78405 ** tests the RHS for NULLs. If the RHS contains a NULL then
78406 ** jump to destIfNull. If there are no NULLs in the RHS then
78407 ** jump to destIfFalse.
78408 */
78409 j2 = sqlite3VdbeAddOp1(v, OP_NotNull, rRhsHasNull);
78410 j3 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78411 sqlite3VdbeAddOp2(v, OP_Integer, -1, rRhsHasNull);
78412 sqlite3VdbeJumpHere(v, j3);
78413 sqlite3VdbeAddOp2(v, OP_AddImm, rRhsHasNull, 1);
 
78414 sqlite3VdbeJumpHere(v, j2);
78415
78416 /* Jump to the appropriate target depending on whether or not
78417 ** the RHS contains a NULL
78418 */
78419 sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull);
78420 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
78421
78422 /* The OP_Found at the top of this branch jumps here when true,
78423 ** causing the overall IN expression evaluation to fall through.
78424 */
78425 sqlite3VdbeJumpHere(v, j1);
@@ -78936,26 +79091,20 @@
78936 case TK_LE:
78937 case TK_GT:
78938 case TK_GE:
78939 case TK_NE:
78940 case TK_EQ: {
78941 assert( TK_LT==OP_Lt );
78942 assert( TK_LE==OP_Le );
78943 assert( TK_GT==OP_Gt );
78944 assert( TK_GE==OP_Ge );
78945 assert( TK_EQ==OP_Eq );
78946 assert( TK_NE==OP_Ne );
78947 testcase( op==TK_LT );
78948 testcase( op==TK_LE );
78949 testcase( op==TK_GT );
78950 testcase( op==TK_GE );
78951 testcase( op==TK_EQ );
78952 testcase( op==TK_NE );
78953 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
78954 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
78955 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
78956 r1, r2, inReg, SQLITE_STOREP2);
 
 
 
 
 
 
78957 testcase( regFree1==0 );
78958 testcase( regFree2==0 );
78959 break;
78960 }
78961 case TK_IS:
@@ -78965,10 +79114,12 @@
78965 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
78966 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
78967 op = (op==TK_IS) ? TK_EQ : TK_NE;
78968 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
78969 r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
 
 
78970 testcase( regFree1==0 );
78971 testcase( regFree2==0 );
78972 break;
78973 }
78974 case TK_AND:
@@ -78981,32 +79132,21 @@
78981 case TK_BITOR:
78982 case TK_SLASH:
78983 case TK_LSHIFT:
78984 case TK_RSHIFT:
78985 case TK_CONCAT: {
78986 assert( TK_AND==OP_And );
78987 assert( TK_OR==OP_Or );
78988 assert( TK_PLUS==OP_Add );
78989 assert( TK_MINUS==OP_Subtract );
78990 assert( TK_REM==OP_Remainder );
78991 assert( TK_BITAND==OP_BitAnd );
78992 assert( TK_BITOR==OP_BitOr );
78993 assert( TK_SLASH==OP_Divide );
78994 assert( TK_LSHIFT==OP_ShiftLeft );
78995 assert( TK_RSHIFT==OP_ShiftRight );
78996 assert( TK_CONCAT==OP_Concat );
78997 testcase( op==TK_AND );
78998 testcase( op==TK_OR );
78999 testcase( op==TK_PLUS );
79000 testcase( op==TK_MINUS );
79001 testcase( op==TK_REM );
79002 testcase( op==TK_BITAND );
79003 testcase( op==TK_BITOR );
79004 testcase( op==TK_SLASH );
79005 testcase( op==TK_LSHIFT );
79006 testcase( op==TK_RSHIFT );
79007 testcase( op==TK_CONCAT );
79008 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79009 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79010 sqlite3VdbeAddOp3(v, op, r2, r1, target);
79011 testcase( regFree1==0 );
79012 testcase( regFree2==0 );
@@ -79034,31 +79174,29 @@
79034 inReg = target;
79035 break;
79036 }
79037 case TK_BITNOT:
79038 case TK_NOT: {
79039 assert( TK_BITNOT==OP_BitNot );
79040 assert( TK_NOT==OP_Not );
79041 testcase( op==TK_BITNOT );
79042 testcase( op==TK_NOT );
79043 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79044 testcase( regFree1==0 );
79045 inReg = target;
79046 sqlite3VdbeAddOp2(v, op, r1, inReg);
79047 break;
79048 }
79049 case TK_ISNULL:
79050 case TK_NOTNULL: {
79051 int addr;
79052 assert( TK_ISNULL==OP_IsNull );
79053 assert( TK_NOTNULL==OP_NotNull );
79054 testcase( op==TK_ISNULL );
79055 testcase( op==TK_NOTNULL );
79056 sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
79057 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79058 testcase( regFree1==0 );
79059 addr = sqlite3VdbeAddOp1(v, op, r1);
 
 
79060 sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
79061 sqlite3VdbeJumpHere(v, addr);
79062 break;
79063 }
79064 case TK_AGG_FUNCTION: {
@@ -79106,10 +79244,11 @@
79106 int endCoalesce = sqlite3VdbeMakeLabel(v);
79107 assert( nFarg>=2 );
79108 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
79109 for(i=1; i<nFarg; i++){
79110 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
 
79111 sqlite3ExprCacheRemove(pParse, target, 1);
79112 sqlite3ExprCachePush(pParse);
79113 sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
79114 sqlite3ExprCachePop(pParse, 1);
79115 }
@@ -79243,17 +79382,18 @@
79243 testcase( regFree1==0 );
79244 testcase( regFree2==0 );
79245 r3 = sqlite3GetTempReg(pParse);
79246 r4 = sqlite3GetTempReg(pParse);
79247 codeCompare(pParse, pLeft, pRight, OP_Ge,
79248 r1, r2, r3, SQLITE_STOREP2);
79249 pLItem++;
79250 pRight = pLItem->pExpr;
79251 sqlite3ReleaseTempReg(pParse, regFree2);
79252 r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
79253 testcase( regFree2==0 );
79254 codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
 
79255 sqlite3VdbeAddOp3(v, OP_And, r3, r4, target);
79256 sqlite3ReleaseTempReg(pParse, r3);
79257 sqlite3ReleaseTempReg(pParse, r4);
79258 break;
79259 }
@@ -79416,10 +79556,11 @@
79416 }
79417 assert( !ExprHasProperty(pExpr, EP_IntValue) );
79418 if( pExpr->affinity==OE_Ignore ){
79419 sqlite3VdbeAddOp4(
79420 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
 
79421 }else{
79422 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
79423 pExpr->affinity, pExpr->u.zToken, 0, 0);
79424 }
79425
@@ -79503,11 +79644,11 @@
79503 /*
79504 ** Generate code that will evaluate expression pExpr and store the
79505 ** results in register target. The results are guaranteed to appear
79506 ** in register target.
79507 */
79508 SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
79509 int inReg;
79510
79511 assert( target>0 && target<=pParse->nMem );
79512 if( pExpr && pExpr->op==TK_REGISTER ){
79513 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
@@ -79516,11 +79657,24 @@
79516 assert( pParse->pVdbe || pParse->db->mallocFailed );
79517 if( inReg!=target && pParse->pVdbe ){
79518 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
79519 }
79520 }
79521 return target;
 
 
 
 
 
 
 
 
 
 
 
 
 
79522 }
79523
79524 /*
79525 ** Generate code that evalutes the given expression and puts the result
79526 ** in register target.
@@ -79531,29 +79685,20 @@
79531 **
79532 ** This routine is used for expressions that are used multiple
79533 ** times. They are evaluated once and the results of the expression
79534 ** are reused.
79535 */
79536 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79537 Vdbe *v = pParse->pVdbe;
79538 int inReg;
79539 inReg = sqlite3ExprCode(pParse, pExpr, target);
79540 assert( target>0 );
79541 /* The only place, other than this routine, where expressions can be
79542 ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79543 ** CASE operators. Neither ever calls this routine. And this routine
79544 ** is never called twice on the same expression. Hence it is impossible
79545 ** for the input to this routine to already be a register. Nevertheless,
79546 ** it seems prudent to keep the ALWAYS() in case the conditions above
79547 ** change with future modifications or enhancements. */
79548 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79549 int iMem;
79550 iMem = ++pParse->nMem;
79551 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79552 exprToRegister(pExpr, iMem);
79553 }
79554 return inReg;
79555 }
79556
79557 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
79558 /*
79559 ** Generate a human-readable explanation of an expression tree.
@@ -79984,27 +80129,21 @@
79984 case TK_LE:
79985 case TK_GT:
79986 case TK_GE:
79987 case TK_NE:
79988 case TK_EQ: {
79989 assert( TK_LT==OP_Lt );
79990 assert( TK_LE==OP_Le );
79991 assert( TK_GT==OP_Gt );
79992 assert( TK_GE==OP_Ge );
79993 assert( TK_EQ==OP_Eq );
79994 assert( TK_NE==OP_Ne );
79995 testcase( op==TK_LT );
79996 testcase( op==TK_LE );
79997 testcase( op==TK_GT );
79998 testcase( op==TK_GE );
79999 testcase( op==TK_EQ );
80000 testcase( op==TK_NE );
80001 testcase( jumpIfNull==0 );
80002 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80003 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80004 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80005 r1, r2, dest, jumpIfNull);
 
 
 
 
 
 
80006 testcase( regFree1==0 );
80007 testcase( regFree2==0 );
80008 break;
80009 }
80010 case TK_IS:
@@ -80014,22 +80153,24 @@
80014 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80015 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80016 op = (op==TK_IS) ? TK_EQ : TK_NE;
80017 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80018 r1, r2, dest, SQLITE_NULLEQ);
 
 
80019 testcase( regFree1==0 );
80020 testcase( regFree2==0 );
80021 break;
80022 }
80023 case TK_ISNULL:
80024 case TK_NOTNULL: {
80025 assert( TK_ISNULL==OP_IsNull );
80026 assert( TK_NOTNULL==OP_NotNull );
80027 testcase( op==TK_ISNULL );
80028 testcase( op==TK_NOTNULL );
80029 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80030 sqlite3VdbeAddOp2(v, op, r1, dest);
 
 
80031 testcase( regFree1==0 );
80032 break;
80033 }
80034 case TK_BETWEEN: {
80035 testcase( jumpIfNull==0 );
@@ -80052,10 +80193,11 @@
80052 }else if( exprAlwaysFalse(pExpr) ){
80053 /* No-op */
80054 }else{
80055 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80056 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
 
80057 testcase( regFree1==0 );
80058 testcase( jumpIfNull==0 );
80059 }
80060 break;
80061 }
@@ -80143,21 +80285,21 @@
80143 case TK_LE:
80144 case TK_GT:
80145 case TK_GE:
80146 case TK_NE:
80147 case TK_EQ: {
80148 testcase( op==TK_LT );
80149 testcase( op==TK_LE );
80150 testcase( op==TK_GT );
80151 testcase( op==TK_GE );
80152 testcase( op==TK_EQ );
80153 testcase( op==TK_NE );
80154 testcase( jumpIfNull==0 );
80155 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80156 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80157 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80158 r1, r2, dest, jumpIfNull);
 
 
 
 
 
 
80159 testcase( regFree1==0 );
80160 testcase( regFree2==0 );
80161 break;
80162 }
80163 case TK_IS:
@@ -80167,20 +80309,22 @@
80167 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80168 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80169 op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
80170 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80171 r1, r2, dest, SQLITE_NULLEQ);
 
 
80172 testcase( regFree1==0 );
80173 testcase( regFree2==0 );
80174 break;
80175 }
80176 case TK_ISNULL:
80177 case TK_NOTNULL: {
80178 testcase( op==TK_ISNULL );
80179 testcase( op==TK_NOTNULL );
80180 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80181 sqlite3VdbeAddOp2(v, op, r1, dest);
 
 
80182 testcase( regFree1==0 );
80183 break;
80184 }
80185 case TK_BETWEEN: {
80186 testcase( jumpIfNull==0 );
@@ -80205,10 +80349,11 @@
80205 }else if( exprAlwaysTrue(pExpr) ){
80206 /* no-op */
80207 }else{
80208 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80209 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
 
80210 testcase( regFree1==0 );
80211 testcase( jumpIfNull==0 );
80212 }
80213 break;
80214 }
@@ -80751,12 +80896,12 @@
80751 len = sqlite3GetToken(zCsr, &token);
80752 } while( token==TK_SPACE );
80753 assert( len>0 );
80754 } while( token!=TK_LP && token!=TK_USING );
80755
80756 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80757 zTableName, tname.z+tname.n);
80758 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
80759 }
80760 }
80761
80762 /*
@@ -80804,11 +80949,11 @@
80804 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
80805 if( zParent==0 ) break;
80806 sqlite3Dequote(zParent);
80807 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
80808 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
80809 (zOutput?zOutput:""), z-zInput, zInput, (const char *)zNew
80810 );
80811 sqlite3DbFree(db, zOutput);
80812 zOutput = zOut;
80813 zInput = &z[n];
80814 }
@@ -80890,12 +81035,12 @@
80890 } while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
80891
80892 /* Variable tname now contains the token that is the old table-name
80893 ** in the CREATE TRIGGER statement.
80894 */
80895 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80896 zTableName, tname.z+tname.n);
80897 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
80898 }
80899 }
80900 #endif /* !SQLITE_OMIT_TRIGGER */
80901
@@ -81143,11 +81288,11 @@
81143 pVTab = 0;
81144 }
81145 }
81146 #endif
81147
81148 /* Begin a transaction and code the VerifyCookie for database iDb.
81149 ** Then modify the schema cookie (since the ALTER TABLE modifies the
81150 ** schema). Open a statement transaction if the table is a virtual
81151 ** table.
81152 */
81153 v = sqlite3GetVdbe(pParse);
@@ -81279,10 +81424,11 @@
81279 int j1;
81280 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
81281 sqlite3VdbeUsesBtree(v, iDb);
81282 sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
81283 j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
 
81284 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
81285 sqlite3VdbeJumpHere(v, j1);
81286 sqlite3ReleaseTempReg(pParse, r1);
81287 sqlite3ReleaseTempReg(pParse, r2);
81288 }
@@ -82579,10 +82725,11 @@
82579 ** regChng = 0
82580 ** goto next_push_0;
82581 **
82582 */
82583 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
 
82584 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
82585 addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
82586
82587 /*
82588 ** next_row:
@@ -82600,10 +82747,11 @@
82600 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
82601 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
82602 aGotoChng[i] =
82603 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
82604 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
 
82605 }
82606 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
82607 aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
82608
82609 /*
@@ -82646,11 +82794,11 @@
82646 #endif
82647 assert( regChng==(regStat4+1) );
82648 sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
82649 sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
82650 sqlite3VdbeChangeP5(v, 2+IsStat34);
82651 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow);
82652
82653 /* Add the entry to the stat1 table. */
82654 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
82655 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82656 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
@@ -82673,14 +82821,16 @@
82673 pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
82674
82675 addrNext = sqlite3VdbeCurrentAddr(v);
82676 callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
82677 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
 
82678 callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
82679 callStatGet(v, regStat4, STAT_GET_NLT, regLt);
82680 callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
82681 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
 
82682 #ifdef SQLITE_ENABLE_STAT3
82683 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
82684 pIdx->aiColumn[0], regSample);
82685 #else
82686 for(i=0; i<nCol; i++){
@@ -82687,11 +82837,11 @@
82687 i16 iCol = pIdx->aiColumn[i];
82688 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
82689 }
82690 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
82691 #endif
82692 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0);
82693 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
82694 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
82695 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
82696 sqlite3VdbeJumpHere(v, addrIsNull);
82697 }
@@ -82707,11 +82857,11 @@
82707 ** name and the row count as the content.
82708 */
82709 if( pOnlyIdx==0 && needTableCnt ){
82710 VdbeComment((v, "%s", pTab->zName));
82711 sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
82712 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
82713 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
82714 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82715 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
82716 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
82717 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -84245,24 +84395,26 @@
84245 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
84246 ** set for each database that is used. Generate code to start a
84247 ** transaction on each used database and to verify the schema cookie
84248 ** on each used database.
84249 */
84250 if( pParse->cookieGoto>0 ){
84251 yDbMask mask;
84252 int iDb, i, addr;
84253 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
 
84254 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
84255 if( (mask & pParse->cookieMask)==0 ) continue;
84256 sqlite3VdbeUsesBtree(v, iDb);
84257 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
84258 if( db->init.busy==0 ){
84259 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84260 sqlite3VdbeAddOp3(v, OP_VerifyCookie,
84261 iDb, pParse->cookieValue[iDb],
84262 db->aDb[iDb].pSchema->iGeneration);
84263 }
 
84264 }
84265 #ifndef SQLITE_OMIT_VIRTUALTABLE
84266 for(i=0; i<pParse->nVtabLock; i++){
84267 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84268 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
@@ -84279,21 +84431,20 @@
84279 /* Initialize any AUTOINCREMENT data structures required.
84280 */
84281 sqlite3AutoincrementBegin(pParse);
84282
84283 /* Code constant expressions that where factored out of inner loops */
84284 addr = pParse->cookieGoto;
84285 if( pParse->pConstExpr ){
84286 ExprList *pEL = pParse->pConstExpr;
84287 pParse->cookieGoto = 0;
84288 for(i=0; i<pEL->nExpr; i++){
84289 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
84290 }
84291 }
84292
84293 /* Finally, jump back to the beginning of the executable code. */
84294 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
84295 }
84296 }
84297
84298
84299 /* Get the VDBE program ready for execution
@@ -84312,11 +84463,10 @@
84312 pParse->nTab = 0;
84313 pParse->nMem = 0;
84314 pParse->nSet = 0;
84315 pParse->nVar = 0;
84316 pParse->cookieMask = 0;
84317 pParse->cookieGoto = 0;
84318 }
84319
84320 /*
84321 ** Run the parser and code generator recursively in order to generate
84322 ** code for the SQL statement given onto the end of the pParse context
@@ -85044,11 +85194,11 @@
85044 reg1 = pParse->regRowid = ++pParse->nMem;
85045 reg2 = pParse->regRoot = ++pParse->nMem;
85046 reg3 = ++pParse->nMem;
85047 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
85048 sqlite3VdbeUsesBtree(v, iDb);
85049 j1 = sqlite3VdbeAddOp1(v, OP_If, reg3);
85050 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
85051 1 : SQLITE_MAX_FILE_FORMAT;
85052 sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
85053 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
85054 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
@@ -86771,40 +86921,40 @@
86771 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
86772
86773 /* Open the table. Loop through all rows of the table, inserting index
86774 ** records into the sorter. */
86775 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86776 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
86777 regRecord = sqlite3GetTempReg(pParse);
86778
86779 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
86780 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
86781 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86782 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
86783 sqlite3VdbeJumpHere(v, addr1);
86784 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
86785 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86786 (char *)pKey, P4_KEYINFO);
86787 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86788
86789 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
86790 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
86791 if( pIndex->onError!=OE_None && pKey!=0 ){
86792 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
86793 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
86794 addr2 = sqlite3VdbeCurrentAddr(v);
86795 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86796 pKey->nField - pIndex->nKeyCol);
86797 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
86798 }else{
86799 addr2 = sqlite3VdbeCurrentAddr(v);
86800 }
86801 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
86802 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
86803 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
86804 sqlite3ReleaseTempReg(pParse, regRecord);
86805 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
86806 sqlite3VdbeJumpHere(v, addr1);
86807
86808 sqlite3VdbeAddOp1(v, OP_Close, iTab);
86809 sqlite3VdbeAddOp1(v, OP_Close, iIdx);
86810 sqlite3VdbeAddOp1(v, OP_Close, iSorter);
@@ -87921,63 +88071,30 @@
87921 }
87922 return 0;
87923 }
87924
87925 /*
87926 ** Generate VDBE code that will verify the schema cookie and start
87927 ** a read-transaction for all named database files.
87928 **
87929 ** It is important that all schema cookies be verified and all
87930 ** read transactions be started before anything else happens in
87931 ** the VDBE program. But this routine can be called after much other
87932 ** code has been generated. So here is what we do:
87933 **
87934 ** The first time this routine is called, we code an OP_Goto that
87935 ** will jump to a subroutine at the end of the program. Then we
87936 ** record every database that needs its schema verified in the
87937 ** pParse->cookieMask field. Later, after all other code has been
87938 ** generated, the subroutine that does the cookie verifications and
87939 ** starts the transactions will be coded and the OP_Goto P2 value
87940 ** will be made to point to that subroutine. The generation of the
87941 ** cookie verification subroutine code happens in sqlite3FinishCoding().
87942 **
87943 ** If iDb<0 then code the OP_Goto only - don't set flag to verify the
87944 ** schema on any databases. This can be used to position the OP_Goto
87945 ** early in the code, before we know if any database tables will be used.
87946 */
87947 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
87948 Parse *pToplevel = sqlite3ParseToplevel(pParse);
87949
87950 #ifndef SQLITE_OMIT_TRIGGER
87951 if( pToplevel!=pParse ){
87952 /* This branch is taken if a trigger is currently being coded. In this
87953 ** case, set cookieGoto to a non-zero value to show that this function
87954 ** has been called. This is used by the sqlite3ExprCodeConstants()
87955 ** function. */
87956 pParse->cookieGoto = -1;
87957 }
87958 #endif
87959 if( pToplevel->cookieGoto==0 ){
87960 Vdbe *v = sqlite3GetVdbe(pToplevel);
87961 if( v==0 ) return; /* This only happens if there was a prior error */
87962 pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
87963 }
87964 if( iDb>=0 ){
87965 sqlite3 *db = pToplevel->db;
87966 yDbMask mask;
87967
87968 assert( iDb<db->nDb );
87969 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
87970 assert( iDb<SQLITE_MAX_ATTACHED+2 );
87971 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87972 mask = ((yDbMask)1)<<iDb;
87973 if( (pToplevel->cookieMask & mask)==0 ){
87974 pToplevel->cookieMask |= mask;
87975 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
87976 if( !OMIT_TEMPDB && iDb==1 ){
87977 sqlite3OpenTempDatabase(pToplevel);
87978 }
87979 }
87980 }
87981 }
87982
87983 /*
@@ -88944,25 +89061,20 @@
88944 SelectDest dest;
88945 Select *pSel;
88946 SrcList *pFrom;
88947 sqlite3 *db = pParse->db;
88948 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
88949
88950 pWhere = sqlite3ExprDup(db, pWhere, 0);
88951 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
88952
88953 if( pFrom ){
88954 assert( pFrom->nSrc==1 );
88955 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
88956 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
88957 assert( pFrom->a[0].pOn==0 );
88958 assert( pFrom->a[0].pUsing==0 );
88959 }
88960
88961 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
88962 if( pSel ) pSel->selFlags |= SF_Materialize;
88963
88964 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
88965 sqlite3Select(pParse, pSel, &dest);
88966 sqlite3SelectDelete(db, pSel);
88967 }
88968 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -89295,11 +89407,11 @@
89295 }else if( pPk ){
89296 /* Construct a composite key for the row to be deleted and remember it */
89297 iKey = ++pParse->nMem;
89298 nKey = 0; /* Zero tells OP_Found to use a composite key */
89299 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89300 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89301 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
89302 }else{
89303 /* Get the rowid of the row to be deleted and remember it in the RowSet */
89304 nKey = 1; /* OP_Seek always uses a single rowid */
89305 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -89333,17 +89445,19 @@
89333 /* Just one row. Hence the top-of-loop is a no-op */
89334 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
89335 if( aToOpen[iDataCur-iTabCur] ){
89336 assert( pPk!=0 );
89337 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
 
89338 }
89339 }else if( pPk ){
89340 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
89341 sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
89342 assert( nKey==0 ); /* OP_Found will use a composite key */
89343 }else{
89344 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
 
89345 assert( nKey==1 );
89346 }
89347
89348 /* Delete the row */
89349 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -89363,11 +89477,11 @@
89363
89364 /* End of the loop over all rowids/primary-keys. */
89365 if( okOnePass ){
89366 sqlite3VdbeResolveLabel(v, addrBypass);
89367 }else if( pPk ){
89368 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
89369 sqlite3VdbeJumpHere(v, addrLoop);
89370 }else{
89371 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
89372 sqlite3VdbeJumpHere(v, addrLoop);
89373 }
@@ -89461,11 +89575,15 @@
89461 /* Seek cursor iCur to the row to delete. If this row no longer exists
89462 ** (this can happen if a trigger program has already deleted it), do
89463 ** not attempt to delete it or fire any DELETE triggers. */
89464 iLabel = sqlite3VdbeMakeLabel(v);
89465 opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89466 if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
 
 
 
 
89467
89468 /* If there are any triggers to fire, allocate a range of registers to
89469 ** use for the old.* references in the triggers. */
89470 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89471 u32 mask; /* Mask of OLD.* columns in use */
@@ -89503,10 +89621,12 @@
89503 ** the cursor or of already deleted the row that the cursor was
89504 ** pointing to.
89505 */
89506 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89507 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
 
 
89508 }
89509
89510 /* Do FK processing. This call checks that any FK constraints that
89511 ** refer to this table (i.e. constraints attached to other tables)
89512 ** are not violated by deleting this row. */
@@ -91760,14 +91880,15 @@
91760 ** Check if any of the key columns in the child table row are NULL. If
91761 ** any are, then the constraint is considered satisfied. No need to
91762 ** search for a matching row in the parent table. */
91763 if( nIncr<0 ){
91764 sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
 
91765 }
91766 for(i=0; i<pFKey->nCol; i++){
91767 int iReg = aiCol[i] + regData + 1;
91768 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk);
91769 }
91770
91771 if( isIgnore==0 ){
91772 if( pIdx==0 ){
91773 /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
@@ -91780,21 +91901,23 @@
91780 ** is no matching parent key. Before using MustBeInt, make a copy of
91781 ** the value. Otherwise, the value inserted into the child key column
91782 ** will have INTEGER affinity applied to it, which may not be correct. */
91783 sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
91784 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
 
91785
91786 /* If the parent table is the same as the child table, and we are about
91787 ** to increment the constraint-counter (i.e. this is an INSERT operation),
91788 ** then check if the row being inserted matches itself. If so, do not
91789 ** increment the constraint-counter. */
91790 if( pTab==pFKey->pFrom && nIncr==1 ){
91791 sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp);
 
91792 }
91793
91794 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
91795 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp);
91796 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91797 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
91798 sqlite3VdbeJumpHere(v, iMustBeInt);
91799 sqlite3ReleaseTempReg(pParse, regTemp);
91800 }else{
@@ -91826,19 +91949,19 @@
91826 assert( aiCol[i]!=pTab->iPKey );
91827 if( pIdx->aiColumn[i]==pTab->iPKey ){
91828 /* The parent key is a composite key that includes the IPK column */
91829 iParent = regData;
91830 }
91831 sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent);
91832 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
91833 }
91834 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91835 }
91836
91837 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec);
91838 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
91839 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
91840
91841 sqlite3ReleaseTempReg(pParse, regRec);
91842 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
91843 }
91844 }
@@ -91972,10 +92095,11 @@
91972 assert( pIdx!=0 || pFKey->nCol==1 );
91973 assert( pIdx!=0 || HasRowid(pTab) );
91974
91975 if( nIncr<0 ){
91976 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
 
91977 }
91978
91979 /* Create an Expr object representing an SQL expression like:
91980 **
91981 ** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
@@ -92134,11 +92258,11 @@
92134 for(p=pTab->pFKey; p; p=p->pNextFrom){
92135 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
92136 }
92137 if( !p ) return;
92138 iSkip = sqlite3VdbeMakeLabel(v);
92139 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip);
92140 }
92141
92142 pParse->disableTriggers = 1;
92143 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
92144 pParse->disableTriggers = 0;
@@ -92152,10 +92276,11 @@
92152 ** the statement transaction will not be rolled back even if FK
92153 ** constraints are violated.
92154 */
92155 if( (db->flags & SQLITE_DeferFKs)==0 ){
92156 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
 
92157 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
92158 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
92159 }
92160
92161 if( iSkip ){
@@ -92311,11 +92436,11 @@
92311 */
92312 Vdbe *v = sqlite3GetVdbe(pParse);
92313 int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
92314 for(i=0; i<pFKey->nCol; i++){
92315 int iReg = pFKey->aCol[i].iFrom + regOld + 1;
92316 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump);
92317 }
92318 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
92319 }
92320 continue;
92321 }
@@ -92878,69 +93003,74 @@
92878
92879 return pIdx->zColAff;
92880 }
92881
92882 /*
92883 ** Set P4 of the most recently inserted opcode to a column affinity
92884 ** string for table pTab. A column affinity string has one character
92885 ** for each column indexed by the index, according to the affinity of the
92886 ** column:
 
 
 
 
 
 
92887 **
92888 ** Character Column affinity
92889 ** ------------------------------
92890 ** 'a' TEXT
92891 ** 'b' NONE
92892 ** 'c' NUMERIC
92893 ** 'd' INTEGER
92894 ** 'e' REAL
92895 */
92896 SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
92897 /* The first time a column affinity string for a particular table
92898 ** is required, it is allocated and populated here. It is then
92899 ** stored as a member of the Table structure for subsequent use.
92900 **
92901 ** The column affinity string will eventually be deleted by
92902 ** sqlite3DeleteTable() when the Table structure itself is cleaned up.
92903 */
92904 if( !pTab->zColAff ){
92905 char *zColAff;
92906 int i;
92907 sqlite3 *db = sqlite3VdbeDb(v);
92908
92909 zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
92910 if( !zColAff ){
92911 db->mallocFailed = 1;
92912 return;
92913 }
92914
92915 for(i=0; i<pTab->nCol; i++){
92916 zColAff[i] = pTab->aCol[i].affinity;
92917 }
92918 zColAff[pTab->nCol] = '\0';
92919
 
92920 pTab->zColAff = zColAff;
92921 }
92922
92923 sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT);
 
 
 
 
 
 
92924 }
92925
92926 /*
92927 ** Return non-zero if the table pTab in database iDb or any of its indices
92928 ** have been opened at any point in the VDBE program beginning at location
92929 ** iStartAddr throught the end of the program. This is used to see if
92930 ** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
92931 ** run without using temporary table for the results of the SELECT.
92932 */
92933 static int readsTable(Parse *p, int iStartAddr, int iDb, Table *pTab){
92934 Vdbe *v = sqlite3GetVdbe(p);
92935 int i;
92936 int iEnd = sqlite3VdbeCurrentAddr(v);
92937 #ifndef SQLITE_OMIT_VIRTUALTABLE
92938 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
92939 #endif
92940
92941 for(i=iStartAddr; i<iEnd; i++){
92942 VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
92943 assert( pOp!=0 );
92944 if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
92945 Index *pIndex;
92946 int tnum = pOp->p2;
@@ -93037,18 +93167,18 @@
93037 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93038 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
93039 sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
93040 addr = sqlite3VdbeCurrentAddr(v);
93041 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
93042 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
93043 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
93044 sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId);
93045 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
93046 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
93047 sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
93048 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
93049 sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2);
93050 sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
93051 sqlite3VdbeAddOp0(v, OP_Close);
93052 }
93053 }
93054
@@ -93079,29 +93209,20 @@
93079 sqlite3 *db = pParse->db;
93080
93081 assert( v );
93082 for(p = pParse->pAinc; p; p = p->pNext){
93083 Db *pDb = &db->aDb[p->iDb];
93084 int j1, j2, j3, j4, j5;
93085 int iRec;
93086 int memId = p->regCtr;
93087
93088 iRec = sqlite3GetTempReg(pParse);
93089 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93090 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
93091 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
93092 j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
93093 j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
93094 j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
93095 sqlite3VdbeAddOp2(v, OP_Next, 0, j3);
93096 sqlite3VdbeJumpHere(v, j2);
93097 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
93098 j5 = sqlite3VdbeAddOp0(v, OP_Goto);
93099 sqlite3VdbeJumpHere(v, j4);
93100 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
93101 sqlite3VdbeJumpHere(v, j1);
93102 sqlite3VdbeJumpHere(v, j5);
93103 sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec);
93104 sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1);
93105 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
93106 sqlite3VdbeAddOp0(v, OP_Close);
93107 sqlite3ReleaseTempReg(pParse, iRec);
@@ -93113,101 +93234,10 @@
93113 ** above are all no-ops
93114 */
93115 # define autoIncBegin(A,B,C) (0)
93116 # define autoIncStep(A,B,C)
93117 #endif /* SQLITE_OMIT_AUTOINCREMENT */
93118
93119
93120 /*
93121 ** Generate code for a co-routine that will evaluate a subquery one
93122 ** row at a time.
93123 **
93124 ** The pSelect parameter is the subquery that the co-routine will evaluation.
93125 ** Information about the location of co-routine and the registers it will use
93126 ** is returned by filling in the pDest object.
93127 **
93128 ** Registers are allocated as follows:
93129 **
93130 ** pDest->iSDParm The register holding the next entry-point of the
93131 ** co-routine. Run the co-routine to its next breakpoint
93132 ** by calling "OP_Yield $X" where $X is pDest->iSDParm.
93133 **
93134 ** pDest->iSDParm+1 The register holding the "completed" flag for the
93135 ** co-routine. This register is 0 if the previous Yield
93136 ** generated a new result row, or 1 if the subquery
93137 ** has completed. If the Yield is called again
93138 ** after this register becomes 1, then the VDBE will
93139 ** halt with an SQLITE_INTERNAL error.
93140 **
93141 ** pDest->iSdst First result register.
93142 **
93143 ** pDest->nSdst Number of result registers.
93144 **
93145 ** This routine handles all of the register allocation and fills in the
93146 ** pDest structure appropriately.
93147 **
93148 ** Here is a schematic of the generated code assuming that X is the
93149 ** co-routine entry-point register reg[pDest->iSDParm], that EOF is the
93150 ** completed flag reg[pDest->iSDParm+1], and R and S are the range of
93151 ** registers that hold the result set, reg[pDest->iSdst] through
93152 ** reg[pDest->iSdst+pDest->nSdst-1]:
93153 **
93154 ** X <- A
93155 ** EOF <- 0
93156 ** goto B
93157 ** A: setup for the SELECT
93158 ** loop rows in the SELECT
93159 ** load results into registers R..S
93160 ** yield X
93161 ** end loop
93162 ** cleanup after the SELECT
93163 ** EOF <- 1
93164 ** yield X
93165 ** halt-error
93166 ** B:
93167 **
93168 ** To use this subroutine, the caller generates code as follows:
93169 **
93170 ** [ Co-routine generated by this subroutine, shown above ]
93171 ** S: yield X
93172 ** if EOF goto E
93173 ** if skip this row, goto C
93174 ** if terminate loop, goto E
93175 ** deal with this row
93176 ** C: goto S
93177 ** E:
93178 */
93179 SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse *pParse, Select *pSelect, SelectDest *pDest){
93180 int regYield; /* Register holding co-routine entry-point */
93181 int regEof; /* Register holding co-routine completion flag */
93182 int addrTop; /* Top of the co-routine */
93183 int j1; /* Jump instruction */
93184 int rc; /* Result code */
93185 Vdbe *v; /* VDBE under construction */
93186
93187 regYield = ++pParse->nMem;
93188 regEof = ++pParse->nMem;
93189 v = sqlite3GetVdbe(pParse);
93190 addrTop = sqlite3VdbeCurrentAddr(v);
93191 sqlite3VdbeAddOp2(v, OP_Integer, addrTop+2, regYield); /* X <- A */
93192 VdbeComment((v, "Co-routine entry point"));
93193 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
93194 VdbeComment((v, "Co-routine completion flag"));
93195 sqlite3SelectDestInit(pDest, SRT_Coroutine, regYield);
93196 j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
93197 rc = sqlite3Select(pParse, pSelect, pDest);
93198 assert( pParse->nErr==0 || rc );
93199 if( pParse->db->mallocFailed && rc==SQLITE_OK ) rc = SQLITE_NOMEM;
93200 if( rc ) return rc;
93201 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
93202 sqlite3VdbeAddOp1(v, OP_Yield, regYield); /* yield X */
93203 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
93204 VdbeComment((v, "End of coroutine"));
93205 sqlite3VdbeJumpHere(v, j1); /* label B: */
93206 return rc;
93207 }
93208
93209
93210
93211 /* Forward declaration */
93212 static int xferOptimization(
93213 Parse *pParse, /* Parser context */
@@ -93268,25 +93298,21 @@
93268 **
93269 ** The 3rd template is for when the second template does not apply
93270 ** and the SELECT clause does not read from <table> at any time.
93271 ** The generated code follows this template:
93272 **
93273 ** EOF <- 0
93274 ** X <- A
93275 ** goto B
93276 ** A: setup for the SELECT
93277 ** loop over the rows in the SELECT
93278 ** load values into registers R..R+n
93279 ** yield X
93280 ** end loop
93281 ** cleanup after the SELECT
93282 ** EOF <- 1
93283 ** yield X
93284 ** goto A
93285 ** B: open write cursor to <table> and its indices
93286 ** C: yield X
93287 ** if EOF goto D
93288 ** insert the select result into <table> from R..R+n
93289 ** goto C
93290 ** D: cleanup
93291 **
93292 ** The 4th template is used if the insert statement takes its
@@ -93293,25 +93319,21 @@
93293 ** values from a SELECT but the data is being inserted into a table
93294 ** that is also read as part of the SELECT. In the third form,
93295 ** we have to use a intermediate table to store the results of
93296 ** the select. The template is like this:
93297 **
93298 ** EOF <- 0
93299 ** X <- A
93300 ** goto B
93301 ** A: setup for the SELECT
93302 ** loop over the tables in the SELECT
93303 ** load value into register R..R+n
93304 ** yield X
93305 ** end loop
93306 ** cleanup after the SELECT
93307 ** EOF <- 1
93308 ** yield X
93309 ** halt-error
93310 ** B: open temp table
93311 ** L: yield X
93312 ** if EOF goto M
93313 ** insert row from R..R+n into temp table
93314 ** goto L
93315 ** M: open write cursor to <table> and its indices
93316 ** rewind temp table
93317 ** C: loop over rows of intermediate table
@@ -93337,30 +93359,29 @@
93337 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
93338 int iDataCur = 0; /* VDBE cursor that is the main data repository */
93339 int iIdxCur = 0; /* First index cursor */
93340 int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
93341 int endOfLoop; /* Label for the end of the insertion loop */
93342 int useTempTable = 0; /* Store SELECT results in intermediate table */
93343 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
93344 int addrInsTop = 0; /* Jump to label "D" */
93345 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
93346 int addrSelect = 0; /* Address of coroutine that implements the SELECT */
93347 SelectDest dest; /* Destination for SELECT on rhs of INSERT */
93348 int iDb; /* Index of database holding TABLE */
93349 Db *pDb; /* The database containing table being inserted into */
93350 int appendFlag = 0; /* True if the insert is likely to be an append */
93351 int withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
 
 
93352 ExprList *pList = 0; /* List of VALUES() to be inserted */
93353
93354 /* Register allocations */
93355 int regFromSelect = 0;/* Base register for data coming from SELECT */
93356 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
93357 int regRowCount = 0; /* Memory cell used for the row counter */
93358 int regIns; /* Block of regs holding rowid+data being inserted */
93359 int regRowid; /* registers holding insert rowid */
93360 int regData; /* register holding first column to insert */
93361 int regEof = 0; /* Register recording end of SELECT data */
93362 int *aRegIdx = 0; /* One register allocated to each index */
93363
93364 #ifndef SQLITE_OMIT_TRIGGER
93365 int isView; /* True if attempting to insert into a view */
93366 Trigger *pTrigger; /* List of triggers on pTab, if required */
@@ -93458,26 +93479,86 @@
93458
93459 /* If this is an AUTOINCREMENT table, look up the sequence number in the
93460 ** sqlite_sequence table and store it in memory cell regAutoinc.
93461 */
93462 regAutoinc = autoIncBegin(pParse, iDb, pTab);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93463
93464 /* Figure out how many columns of data are supplied. If the data
93465 ** is coming from a SELECT statement, then generate a co-routine that
93466 ** produces a single row of the SELECT on each invocation. The
93467 ** co-routine is the common header to the 3rd and 4th templates.
93468 */
93469 if( pSelect ){
93470 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
93471 int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
93472 if( rc ) goto insert_cleanup;
 
93473
93474 regEof = dest.iSDParm + 1;
 
 
 
 
 
 
93475 regFromSelect = dest.iSdst;
 
 
 
 
93476 assert( pSelect->pEList );
93477 nColumn = pSelect->pEList->nExpr;
93478 assert( dest.nSdst==nColumn );
93479
93480 /* Set useTempTable to TRUE if the result of the SELECT statement
93481 ** should be written into a temporary table (template 4). Set to
93482 ** FALSE if each output row of the SELECT can be written directly into
93483 ** the destination table (template 3).
@@ -93484,42 +93565,39 @@
93484 **
93485 ** A temp table must be used if the table being updated is also one
93486 ** of the tables being read by the SELECT statement. Also use a
93487 ** temp table in the case of row triggers.
93488 */
93489 if( pTrigger || readsTable(pParse, addrSelect, iDb, pTab) ){
93490 useTempTable = 1;
93491 }
93492
93493 if( useTempTable ){
93494 /* Invoke the coroutine to extract information from the SELECT
93495 ** and add it to a transient table srcTab. The code generated
93496 ** here is from the 4th template:
93497 **
93498 ** B: open temp table
93499 ** L: yield X
93500 ** if EOF goto M
93501 ** insert row from R..R+n into temp table
93502 ** goto L
93503 ** M: ...
93504 */
93505 int regRec; /* Register to hold packed record */
93506 int regTempRowid; /* Register to hold temp table ROWID */
93507 int addrTop; /* Label "L" */
93508 int addrIf; /* Address of jump to M */
93509
93510 srcTab = pParse->nTab++;
93511 regRec = sqlite3GetTempReg(pParse);
93512 regTempRowid = sqlite3GetTempReg(pParse);
93513 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
93514 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93515 addrIf = sqlite3VdbeAddOp1(v, OP_If, regEof);
93516 sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
93517 sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
93518 sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
93519 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
93520 sqlite3VdbeJumpHere(v, addrIf);
93521 sqlite3ReleaseTempReg(pParse, regRec);
93522 sqlite3ReleaseTempReg(pParse, regTempRowid);
93523 }
93524 }else{
93525 /* This is the case if the data for the INSERT is coming from a VALUES
@@ -93535,10 +93613,18 @@
93535 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
93536 goto insert_cleanup;
93537 }
93538 }
93539 }
 
 
 
 
 
 
 
 
93540
93541 /* Make sure the number of columns in the source data matches the number
93542 ** of columns to be inserted into the table.
93543 */
93544 if( IsVirtual(pTab) ){
@@ -93554,56 +93640,10 @@
93554 }
93555 if( pColumn!=0 && nColumn!=pColumn->nId ){
93556 sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
93557 goto insert_cleanup;
93558 }
93559
93560 /* If the INSERT statement included an IDLIST term, then make sure
93561 ** all elements of the IDLIST really are columns of the table and
93562 ** remember the column indices.
93563 **
93564 ** If the table has an INTEGER PRIMARY KEY column and that column
93565 ** is named in the IDLIST, then record in the ipkColumn variable
93566 ** the index into IDLIST of the primary key column. ipkColumn is
93567 ** the index of the primary key as it appears in IDLIST, not as
93568 ** is appears in the original table. (The index of the INTEGER
93569 ** PRIMARY KEY in the original table is pTab->iPKey.)
93570 */
93571 if( pColumn ){
93572 for(i=0; i<pColumn->nId; i++){
93573 pColumn->a[i].idx = -1;
93574 }
93575 for(i=0; i<pColumn->nId; i++){
93576 for(j=0; j<pTab->nCol; j++){
93577 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93578 pColumn->a[i].idx = j;
93579 if( j==pTab->iPKey ){
93580 ipkColumn = i; assert( !withoutRowid );
93581 }
93582 break;
93583 }
93584 }
93585 if( j>=pTab->nCol ){
93586 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93587 ipkColumn = i;
93588 }else{
93589 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93590 pTabList, 0, pColumn->a[i].zName);
93591 pParse->checkSchema = 1;
93592 goto insert_cleanup;
93593 }
93594 }
93595 }
93596 }
93597
93598 /* If there is no IDLIST term but the table has an integer primary
93599 ** key, the set the ipkColumn variable to the integer primary key
93600 ** column index in the original table definition.
93601 */
93602 if( pColumn==0 && nColumn>0 ){
93603 ipkColumn = pTab->iPKey;
93604 }
93605
93606 /* Initialize the count of rows to be inserted
93607 */
93608 if( db->flags & SQLITE_CountRows ){
93609 regRowCount = ++pParse->nMem;
@@ -93627,42 +93667,30 @@
93627 /* This is the top of the main insertion loop */
93628 if( useTempTable ){
93629 /* This block codes the top of loop only. The complete loop is the
93630 ** following pseudocode (template 4):
93631 **
93632 ** rewind temp table
93633 ** C: loop over rows of intermediate table
93634 ** transfer values form intermediate table into <table>
93635 ** end loop
93636 ** D: ...
93637 */
93638 addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab);
93639 addrCont = sqlite3VdbeCurrentAddr(v);
93640 }else if( pSelect ){
93641 /* This block codes the top of loop only. The complete loop is the
93642 ** following pseudocode (template 3):
93643 **
93644 ** C: yield X
93645 ** if EOF goto D
93646 ** insert the select result into <table> from R..R+n
93647 ** goto C
93648 ** D: ...
93649 */
93650 addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93651 addrInsTop = sqlite3VdbeAddOp1(v, OP_If, regEof);
93652 }
93653
93654 /* Allocate registers for holding the rowid of the new row,
93655 ** the content of the new row, and the assemblied row record.
93656 */
93657 regRowid = regIns = pParse->nMem+1;
93658 pParse->nMem += pTab->nCol + 1;
93659 if( IsVirtual(pTab) ){
93660 regRowid++;
93661 pParse->nMem++;
93662 }
93663 regData = regRowid+1;
93664
93665 /* Run the BEFORE and INSTEAD OF triggers, if there are any
93666 */
93667 endOfLoop = sqlite3VdbeMakeLabel(v);
93668 if( tmask & TRIGGER_BEFORE ){
@@ -93683,14 +93711,14 @@
93683 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
93684 }else{
93685 assert( pSelect==0 ); /* Otherwise useTempTable is true */
93686 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
93687 }
93688 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
93689 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
93690 sqlite3VdbeJumpHere(v, j1);
93691 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
93692 }
93693
93694 /* Cannot have triggers on a virtual table. If it were possible,
93695 ** this block would have to account for hidden column.
93696 */
@@ -93720,12 +93748,11 @@
93720 ** do not attempt any conversions before assembling the record.
93721 ** If this is a real table, attempt conversions as required by the
93722 ** table column affinities.
93723 */
93724 if( !isView ){
93725 sqlite3VdbeAddOp2(v, OP_Affinity, regCols+1, pTab->nCol);
93726 sqlite3TableAffinityStr(v, pTab);
93727 }
93728
93729 /* Fire BEFORE or INSTEAD OF triggers */
93730 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
93731 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
@@ -93743,11 +93770,11 @@
93743 }
93744 if( ipkColumn>=0 ){
93745 if( useTempTable ){
93746 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
93747 }else if( pSelect ){
93748 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid);
93749 }else{
93750 VdbeOp *pOp;
93751 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
93752 pOp = sqlite3VdbeGetOp(v, -1);
93753 if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
@@ -93762,18 +93789,18 @@
93762 ** to generate a unique primary key value.
93763 */
93764 if( !appendFlag ){
93765 int j1;
93766 if( !IsVirtual(pTab) ){
93767 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
93768 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
93769 sqlite3VdbeJumpHere(v, j1);
93770 }else{
93771 j1 = sqlite3VdbeCurrentAddr(v);
93772 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
93773 }
93774 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
93775 }
93776 }else if( IsVirtual(pTab) || withoutRowid ){
93777 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
93778 }else{
93779 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -93789,12 +93816,13 @@
93789 int iRegStore = regRowid+1+i;
93790 if( i==pTab->iPKey ){
93791 /* The value of the INTEGER PRIMARY KEY column is always a NULL.
93792 ** Whenever this column is read, the rowid will be substituted
93793 ** in its place. Hence, fill this column with a NULL to avoid
93794 ** taking up data space with information that will never be used. */
93795 sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
 
93796 continue;
93797 }
93798 if( pColumn==0 ){
93799 if( IsHiddenColumn(&pTab->aCol[i]) ){
93800 assert( IsVirtual(pTab) );
@@ -93807,15 +93835,17 @@
93807 for(j=0; j<pColumn->nId; j++){
93808 if( pColumn->a[j].idx==i ) break;
93809 }
93810 }
93811 if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){
93812 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, iRegStore);
93813 }else if( useTempTable ){
93814 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, iRegStore);
93815 }else if( pSelect ){
93816 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
 
 
93817 }else{
93818 sqlite3ExprCode(pParse, pList->a[j].pExpr, iRegStore);
93819 }
93820 }
93821
@@ -93857,11 +93887,11 @@
93857 /* The bottom of the main insertion loop, if the data source
93858 ** is a SELECT statement.
93859 */
93860 sqlite3VdbeResolveLabel(v, endOfLoop);
93861 if( useTempTable ){
93862 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont);
93863 sqlite3VdbeJumpHere(v, addrInsTop);
93864 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
93865 }else if( pSelect ){
93866 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
93867 sqlite3VdbeJumpHere(v, addrInsTop);
@@ -94024,10 +94054,11 @@
94024 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
94025 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
94026 int ipkTop = 0; /* Top of the rowid change constraint check */
94027 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
94028 u8 isUpdate; /* True if this is an UPDATE operation */
 
94029 int regRowid = -1; /* Register holding ROWID value */
94030
94031 isUpdate = regOldData!=0;
94032 db = pParse->db;
94033 v = sqlite3GetVdbe(pParse);
@@ -94078,19 +94109,21 @@
94078 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
94079 pTab->aCol[i].zName);
94080 sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
94081 regNewData+1+i, zMsg, P4_DYNAMIC);
94082 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
 
94083 break;
94084 }
94085 case OE_Ignore: {
94086 sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
 
94087 break;
94088 }
94089 default: {
94090 assert( onError==OE_Replace );
94091 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
94092 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
94093 sqlite3VdbeJumpHere(v, j1);
94094 break;
94095 }
94096 }
@@ -94138,10 +94171,12 @@
94138 if( isUpdate ){
94139 /* pkChng!=0 does not mean that the rowid has change, only that
94140 ** it might have changed. Skip the conflict logic below if the rowid
94141 ** is unchanged. */
94142 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
 
 
94143 }
94144
94145 /* If the response to a rowid conflict is REPLACE but the response
94146 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
94147 ** to defer the running of the rowid conflict checking until after
@@ -94157,10 +94192,11 @@
94157 }
94158
94159 /* Check to see if the new rowid already exists in the table. Skip
94160 ** the following conflict logic if it does not. */
94161 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
 
94162
94163 /* Generate code that deals with a rowid collision */
94164 switch( onError ){
94165 default: {
94166 onError = OE_Abort;
@@ -94235,10 +94271,14 @@
94235 int regR; /* Range of registers holding conflicting PK */
94236 int iThisCur; /* Cursor for this UNIQUE index */
94237 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
94238
94239 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
 
 
 
 
94240 iThisCur = iIdxCur+ix;
94241 addrUniqueOk = sqlite3VdbeMakeLabel(v);
94242
94243 /* Skip partial indices for which the WHERE clause is not true */
94244 if( pIdx->pPartIdxWhere ){
@@ -94265,11 +94305,10 @@
94265 }
94266 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94267 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
94268 }
94269 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
94270 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
94271 VdbeComment((v, "for %s", pIdx->zName));
94272 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
94273
94274 /* In an UPDATE operation, if this index is the PRIMARY KEY index
94275 ** of a WITHOUT ROWID table and there has been no change the
@@ -94293,11 +94332,11 @@
94293 onError = OE_Abort;
94294 }
94295
94296 /* Check to see if the new index entry will be unique */
94297 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94298 regIdx, pIdx->nKeyCol);
94299
94300 /* Generate code to handle collisions */
94301 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94302 if( isUpdate || onError==OE_Replace ){
94303 if( HasRowid(pTab) ){
@@ -94304,10 +94343,12 @@
94304 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94305 /* Conflict only if the rowid of the existing index entry
94306 ** is different from old-rowid */
94307 if( isUpdate ){
94308 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
 
 
94309 }
94310 }else{
94311 int x;
94312 /* Extract the PRIMARY KEY from the end of the index entry and
94313 ** store it in registers regR..regR+nPk-1 */
@@ -94339,10 +94380,13 @@
94339 op = OP_Eq;
94340 }
94341 sqlite3VdbeAddOp4(v, op,
94342 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94343 );
 
 
 
94344 }
94345 }
94346 }
94347 }
94348
@@ -94410,18 +94454,21 @@
94410 Index *pIdx; /* An index being inserted or updated */
94411 u8 pik_flags; /* flag values passed to the btree insert */
94412 int regData; /* Content registers (after the rowid) */
94413 int regRec; /* Register holding assemblied record for the table */
94414 int i; /* Loop counter */
 
94415
94416 v = sqlite3GetVdbe(pParse);
94417 assert( v!=0 );
94418 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
94419 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94420 if( aRegIdx[i]==0 ) continue;
 
94421 if( pIdx->pPartIdxWhere ){
94422 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
 
94423 }
94424 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
94425 pik_flags = 0;
94426 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
94427 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
@@ -94432,11 +94479,11 @@
94432 }
94433 if( !HasRowid(pTab) ) return;
94434 regData = regNewData + 1;
94435 regRec = sqlite3GetTempReg(pParse);
94436 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
94437 sqlite3TableAffinityStr(v, pTab);
94438 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
94439 if( pParse->nested ){
94440 pik_flags = 0;
94441 }else{
94442 pik_flags = OPFLAG_NCHANGE;
@@ -94801,20 +94848,21 @@
94801 ** (2) The destination has a unique index. (The xfer optimization
94802 ** is unable to test uniqueness.)
94803 **
94804 ** (3) onError is something other than OE_Abort and OE_Rollback.
94805 */
94806 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
94807 emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
94808 sqlite3VdbeJumpHere(v, addr1);
94809 }
94810 if( HasRowid(pSrc) ){
94811 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94812 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94813 if( pDest->iPKey>=0 ){
94814 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94815 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
 
94816 sqlite3RowidConstraint(pParse, onError, pDest);
94817 sqlite3VdbeJumpHere(v, addr2);
94818 autoIncStep(pParse, regAutoinc, regRowid);
94819 }else if( pDest->pIndex==0 ){
94820 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
@@ -94824,11 +94872,11 @@
94824 }
94825 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
94826 sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
94827 sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
94828 sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94829 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
94830 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94831 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94832 }else{
94833 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
94834 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
@@ -94843,19 +94891,19 @@
94843 VdbeComment((v, "%s", pSrcIdx->zName));
94844 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
94845 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
94846 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
94847 VdbeComment((v, "%s", pDestIdx->zName));
94848 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94849 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
94850 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
94851 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
94852 sqlite3VdbeJumpHere(v, addr1);
94853 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94854 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94855 }
94856 sqlite3VdbeJumpHere(v, emptySrcTest);
94857 sqlite3ReleaseTempReg(pParse, regRowid);
94858 sqlite3ReleaseTempReg(pParse, regData);
94859 if( emptyDestTest ){
94860 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
94861 sqlite3VdbeJumpHere(v, emptyDestTest);
@@ -97085,10 +97133,11 @@
97085 ** is always on by default regardless of the sign of the default cache
97086 ** size. But continue to take the absolute value of the default cache
97087 ** size of historical compatibility.
97088 */
97089 case PragTyp_DEFAULT_CACHE_SIZE: {
 
97090 static const VdbeOpList getCacheSize[] = {
97091 { OP_Transaction, 0, 0, 0}, /* 0 */
97092 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
97093 { OP_IfPos, 1, 8, 0},
97094 { OP_Integer, 0, 2, 0},
@@ -97102,11 +97151,11 @@
97102 sqlite3VdbeUsesBtree(v, iDb);
97103 if( !zRight ){
97104 sqlite3VdbeSetNumCols(v, 1);
97105 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
97106 pParse->nMem += 2;
97107 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
97108 sqlite3VdbeChangeP1(v, addr, iDb);
97109 sqlite3VdbeChangeP1(v, addr+1, iDb);
97110 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
97111 }else{
97112 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
@@ -97347,20 +97396,21 @@
97347 /* When setting the auto_vacuum mode to either "full" or
97348 ** "incremental", write the value of meta[6] in the database
97349 ** file. Before writing to meta[6], check that meta[3] indicates
97350 ** that this really is an auto-vacuum capable database.
97351 */
 
97352 static const VdbeOpList setMeta6[] = {
97353 { OP_Transaction, 0, 1, 0}, /* 0 */
97354 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
97355 { OP_If, 1, 0, 0}, /* 2 */
97356 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
97357 { OP_Integer, 0, 1, 0}, /* 4 */
97358 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
97359 };
97360 int iAddr;
97361 iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
97362 sqlite3VdbeChangeP1(v, iAddr, iDb);
97363 sqlite3VdbeChangeP1(v, iAddr+1, iDb);
97364 sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
97365 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
97366 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
@@ -97382,14 +97432,14 @@
97382 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
97383 iLimit = 0x7fffffff;
97384 }
97385 sqlite3BeginWriteOperation(pParse, 0, iDb);
97386 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
97387 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
97388 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
97389 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
97390 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
97391 sqlite3VdbeJumpHere(v, addr);
97392 break;
97393 }
97394 #endif
97395
@@ -97956,11 +98006,11 @@
97956 }
97957 }
97958 assert( pParse->nErr>0 || pFK==0 );
97959 if( pFK ) break;
97960 if( pParse->nTab<i ) pParse->nTab = i;
97961 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0);
97962 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
97963 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
97964 pIdx = 0;
97965 aiCols = 0;
97966 if( pParent ){
@@ -97972,30 +98022,30 @@
97972 int iKey = pFK->aCol[0].iFrom;
97973 assert( iKey>=0 && iKey<pTab->nCol );
97974 if( iKey!=pTab->iPKey ){
97975 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
97976 sqlite3ColumnDefault(v, pTab, iKey, regRow);
97977 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk);
97978 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
97979 sqlite3VdbeCurrentAddr(v)+3);
97980 }else{
97981 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
97982 }
97983 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow);
97984 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
97985 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
97986 }else{
97987 for(j=0; j<pFK->nCol; j++){
97988 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
97989 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
97990 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk);
97991 }
97992 if( pParent ){
97993 sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey);
97994 sqlite3VdbeChangeP4(v, -1,
97995 sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
97996 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
 
97997 }
97998 }
97999 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
98000 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
98001 pFK->zTo, P4_TRANSIENT);
@@ -98002,11 +98052,11 @@
98002 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
98003 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
98004 sqlite3VdbeResolveLabel(v, addrOk);
98005 sqlite3DbFree(db, aiCols);
98006 }
98007 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
98008 sqlite3VdbeJumpHere(v, addrTop);
98009 }
98010 }
98011 break;
98012 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
@@ -98049,10 +98099,11 @@
98049
98050 /* Code that appears at the end of the integrity check. If no error
98051 ** messages have been generated, output OK. Otherwise output the
98052 ** error message
98053 */
 
98054 static const VdbeOpList endCode[] = {
98055 { OP_AddImm, 1, 0, 0}, /* 0 */
98056 { OP_IfNeg, 1, 0, 0}, /* 1 */
98057 { OP_String8, 0, 3, 0}, /* 2 */
98058 { OP_ResultRow, 3, 1, 0},
@@ -98097,10 +98148,11 @@
98097 if( OMIT_TEMPDB && i==1 ) continue;
98098 if( iDb>=0 && i!=iDb ) continue;
98099
98100 sqlite3CodeVerifySchema(pParse, i);
98101 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
 
98102 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98103 sqlite3VdbeJumpHere(v, addr);
98104
98105 /* Do an integrity check of the B-Tree
98106 **
@@ -98128,11 +98180,11 @@
98128 pParse->nMem = MAX( pParse->nMem, cnt+8 );
98129
98130 /* Do the b-tree integrity checks */
98131 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
98132 sqlite3VdbeChangeP5(v, (u8)i);
98133 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
98134 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
98135 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
98136 P4_DYNAMIC);
98137 sqlite3VdbeAddOp2(v, OP_Move, 2, 4);
98138 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
@@ -98150,10 +98202,11 @@
98150 int r1 = -1;
98151
98152 if( pTab->pIndex==0 ) continue;
98153 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
98154 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
 
98155 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98156 sqlite3VdbeJumpHere(v, addr);
98157 sqlite3ExprCacheClear(pParse);
98158 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98159 1, 0, &iDataCur, &iIdxCur);
@@ -98160,57 +98213,58 @@
98160 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98161 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98162 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98163 }
98164 pParse->nMem = MAX(pParse->nMem, 8+j);
98165 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0);
98166 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
98167 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98168 int jmp2, jmp3, jmp4;
98169 if( pPk==pIdx ) continue;
98170 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
98171 pPrior, r1);
98172 pPrior = pIdx;
98173 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
98174 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98175 pIdx->nColumn);
98176 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
98177 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
98178 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
98179 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
98180 P4_STATIC);
98181 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98182 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
98183 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98184 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98185 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
98186 sqlite3VdbeAddOp0(v, OP_Halt);
98187 sqlite3VdbeJumpHere(v, jmp4);
98188 sqlite3VdbeJumpHere(v, jmp2);
98189 sqlite3VdbeResolveLabel(v, jmp3);
98190 }
98191 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop);
98192 sqlite3VdbeJumpHere(v, loopTop-1);
98193 #ifndef SQLITE_OMIT_BTREECOUNT
98194 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
98195 "wrong # of entries in index ", P4_STATIC);
98196 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98197 if( pPk==pIdx ) continue;
98198 addr = sqlite3VdbeCurrentAddr(v);
98199 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
98200 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98201 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98202 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3);
 
98203 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
98204 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
98205 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
98206 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
98207 }
98208 #endif /* SQLITE_OMIT_BTREECOUNT */
98209 }
98210 }
98211 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
98212 sqlite3VdbeChangeP2(v, addr, -mxErr);
98213 sqlite3VdbeJumpHere(v, addr+1);
98214 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
98215 }
98216 break;
@@ -98344,11 +98398,11 @@
98344 static const VdbeOpList setCookie[] = {
98345 { OP_Transaction, 0, 1, 0}, /* 0 */
98346 { OP_Integer, 0, 1, 0}, /* 1 */
98347 { OP_SetCookie, 0, 0, 1}, /* 2 */
98348 };
98349 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
98350 sqlite3VdbeChangeP1(v, addr, iDb);
98351 sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
98352 sqlite3VdbeChangeP1(v, addr+2, iDb);
98353 sqlite3VdbeChangeP2(v, addr+2, iCookie);
98354 }else{
@@ -98356,11 +98410,11 @@
98356 static const VdbeOpList readCookie[] = {
98357 { OP_Transaction, 0, 0, 0}, /* 0 */
98358 { OP_ReadCookie, 0, 1, 0}, /* 1 */
98359 { OP_ResultRow, 1, 1, 0}
98360 };
98361 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
98362 sqlite3VdbeChangeP1(v, addr, iDb);
98363 sqlite3VdbeChangeP1(v, addr+1, iDb);
98364 sqlite3VdbeChangeP3(v, addr+1, iCookie);
98365 sqlite3VdbeSetNumCols(v, 1);
98366 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
@@ -99562,10 +99616,18 @@
99562 if( p ){
99563 clearSelect(db, p);
99564 sqlite3DbFree(db, p);
99565 }
99566 }
 
 
 
 
 
 
 
 
99567
99568 /*
99569 ** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
99570 ** type of join. Return an integer constant that expresses that type
99571 ** in terms of the following bit values:
@@ -99901,11 +99963,11 @@
99901 if( pSelect->iOffset ){
99902 iLimit = pSelect->iOffset+1;
99903 }else{
99904 iLimit = pSelect->iLimit;
99905 }
99906 addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit);
99907 sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
99908 addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
99909 sqlite3VdbeJumpHere(v, addr1);
99910 sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
99911 sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
@@ -99922,11 +99984,11 @@
99922 int iContinue /* Jump here to skip the current record */
99923 ){
99924 if( iOffset>0 && iContinue!=0 ){
99925 int addr;
99926 sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99927 addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset);
99928 sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
99929 VdbeComment((v, "skip OFFSET records"));
99930 sqlite3VdbeJumpHere(v, addr);
99931 }
99932 }
@@ -99950,11 +100012,11 @@
99950 Vdbe *v;
99951 int r1;
99952
99953 v = pParse->pVdbe;
99954 r1 = sqlite3GetTempReg(pParse);
99955 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N);
99956 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
99957 sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
99958 sqlite3ReleaseTempReg(pParse, r1);
99959 }
99960
@@ -100031,17 +100093,23 @@
100031 }
100032
100033 /* Pull the requested columns.
100034 */
100035 nResultCol = pEList->nExpr;
 
100036 if( pDest->iSdst==0 ){
100037 pDest->iSdst = pParse->nMem+1;
100038 pDest->nSdst = nResultCol;
 
 
 
 
 
 
100039 pParse->nMem += nResultCol;
100040 }else{
100041 assert( pDest->nSdst==nResultCol );
100042 }
 
100043 regResult = pDest->iSdst;
100044 if( srcTab>=0 ){
100045 for(i=0; i<nResultCol; i++){
100046 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100047 VdbeComment((v, "%s", pEList->a[i].zName));
@@ -100084,13 +100152,15 @@
100084 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100085 for(i=0; i<nResultCol; i++){
100086 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100087 if( i<nResultCol-1 ){
100088 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
 
100089 }else{
100090 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100091 }
 
100092 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100093 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100094 }
100095 assert( sqlite3VdbeCurrentAddr(v)==iJump );
100096 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
@@ -100152,11 +100222,11 @@
100152 ** on an ephemeral index. If the current row is already present
100153 ** in the index, do not write it to the output. If not, add the
100154 ** current row to the index and proceed with writing it to the
100155 ** output table as well. */
100156 int addr = sqlite3VdbeCurrentAddr(v) + 4;
100157 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
100158 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
100159 assert( pOrderBy==0 );
100160 }
100161 #endif
100162 if( pOrderBy ){
@@ -100219,16 +100289,12 @@
100219 }
100220 break;
100221 }
100222 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
100223
100224 /* Send the data to the callback function or to a subroutine. In the
100225 ** case of a subroutine, the subroutine itself is responsible for
100226 ** popping the data from the stack.
100227 */
100228 case SRT_Coroutine:
100229 case SRT_Output: {
100230 testcase( eDest==SRT_Coroutine );
100231 testcase( eDest==SRT_Output );
100232 if( pOrderBy ){
100233 int r1 = sqlite3GetTempReg(pParse);
100234 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
@@ -100260,17 +100326,20 @@
100260 assert( pSO );
100261 nKey = pSO->nExpr;
100262 r1 = sqlite3GetTempReg(pParse);
100263 r2 = sqlite3GetTempRange(pParse, nKey+2);
100264 r3 = r2+nKey+1;
100265 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100266 if( eDest==SRT_DistQueue ){
100267 /* If the destination is DistQueue, then cursor (iParm+1) is open
100268 ** on a second ephemeral index that holds all values every previously
100269 ** added to the queue. Only add this new value if it has never before
100270 ** been added */
100271 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0);
 
 
 
 
100272 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100273 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
100274 }
100275 for(i=0; i<nKey; i++){
100276 sqlite3VdbeAddOp2(v, OP_SCopy,
@@ -100305,11 +100374,11 @@
100305 /* Jump to the end of the loop if the LIMIT is reached. Except, if
100306 ** there is a sorter, in which case the sorter has already limited
100307 ** the output for us.
100308 */
100309 if( pOrderBy==0 && p->iLimit ){
100310 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
100311 }
100312 }
100313
100314 /*
100315 ** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -100524,16 +100593,17 @@
100524 if( p->selFlags & SF_UseSorter ){
100525 int regSortOut = ++pParse->nMem;
100526 int ptab2 = pParse->nTab++;
100527 sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100528 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
 
100529 codeOffset(v, p->iOffset, addrContinue);
100530 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100531 sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100532 sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100533 }else{
100534 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
100535 codeOffset(v, p->iOffset, addrContinue);
100536 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100537 }
100538 switch( eDest ){
100539 case SRT_Table:
@@ -100587,13 +100657,13 @@
100587
100588 /* The bottom of the loop
100589 */
100590 sqlite3VdbeResolveLabel(v, addrContinue);
100591 if( p->selFlags & SF_UseSorter ){
100592 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr);
100593 }else{
100594 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr);
100595 }
100596 sqlite3VdbeResolveLabel(v, addrBreak);
100597 if( eDest==SRT_Output || eDest==SRT_Coroutine ){
100598 sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
100599 }
@@ -101073,15 +101143,17 @@
101073 */
101074 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
101075 Vdbe *v = pParse->pVdbe;
101076 if( v==0 ){
101077 v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
101078 #ifndef SQLITE_OMIT_TRACE
101079 if( v ){
101080 sqlite3VdbeAddOp0(v, OP_Trace);
 
 
101081 }
101082 #endif
101083 }
101084 return v;
101085 }
101086
101087
@@ -101135,26 +101207,26 @@
101135 }else if( n>=0 && p->nSelectRow>(u64)n ){
101136 p->nSelectRow = n;
101137 }
101138 }else{
101139 sqlite3ExprCode(pParse, p->pLimit, iLimit);
101140 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit);
101141 VdbeComment((v, "LIMIT counter"));
101142 sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak);
101143 }
101144 if( p->pOffset ){
101145 p->iOffset = iOffset = ++pParse->nMem;
101146 pParse->nMem++; /* Allocate an extra register for limit+offset */
101147 sqlite3ExprCode(pParse, p->pOffset, iOffset);
101148 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset);
101149 VdbeComment((v, "OFFSET counter"));
101150 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset);
101151 sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
101152 sqlite3VdbeJumpHere(v, addr1);
101153 sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
101154 VdbeComment((v, "LIMIT+OFFSET"));
101155 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit);
101156 sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
101157 sqlite3VdbeJumpHere(v, addr1);
101158 }
101159 }
101160 }
@@ -101333,15 +101405,17 @@
101333
101334 /* Detach the ORDER BY clause from the compound SELECT */
101335 p->pOrderBy = 0;
101336
101337 /* Store the results of the setup-query in Queue. */
 
101338 rc = sqlite3Select(pParse, pSetup, &destQueue);
 
101339 if( rc ) goto end_of_recursive_query;
101340
101341 /* Find the next row in the Queue and output that row */
101342 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak);
101343
101344 /* Transfer the next row in Queue over to Current */
101345 sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101346 if( pOrderBy ){
101347 sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
@@ -101353,11 +101427,14 @@
101353 /* Output the single row in Current */
101354 addrCont = sqlite3VdbeMakeLabel(v);
101355 codeOffset(v, regOffset, addrCont);
101356 selectInnerLoop(pParse, p, p->pEList, iCurrent,
101357 0, 0, pDest, addrCont, addrBreak);
101358 if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
 
 
 
101359 sqlite3VdbeResolveLabel(v, addrCont);
101360
101361 /* Execute the recursive SELECT taking the single row in Current as
101362 ** the value for the recursive-table. Store the results in the Queue.
101363 */
@@ -101438,12 +101515,10 @@
101438 */
101439 assert( p && p->pPrior ); /* Calling function guarantees this much */
101440 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
101441 db = pParse->db;
101442 pPrior = p->pPrior;
101443 assert( pPrior->pRightmost!=pPrior );
101444 assert( pPrior->pRightmost==p->pRightmost );
101445 dest = *pDest;
101446 if( pPrior->pOrderBy ){
101447 sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
101448 selectOpName(p->op));
101449 rc = 1;
@@ -101515,11 +101590,11 @@
101515 }
101516 p->pPrior = 0;
101517 p->iLimit = pPrior->iLimit;
101518 p->iOffset = pPrior->iOffset;
101519 if( p->iLimit ){
101520 addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit);
101521 VdbeComment((v, "Jump ahead if LIMIT reached"));
101522 }
101523 explainSetInteger(iSub2, pParse->iNextSelectId);
101524 rc = sqlite3Select(pParse, p, &dest);
101525 testcase( rc!=SQLITE_OK );
@@ -101547,16 +101622,14 @@
101547 SelectDest uniondest;
101548
101549 testcase( p->op==TK_EXCEPT );
101550 testcase( p->op==TK_UNION );
101551 priorOp = SRT_Union;
101552 if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){
101553 /* We can reuse a temporary table generated by a SELECT to our
101554 ** right.
101555 */
101556 assert( p->pRightmost!=p ); /* Can only happen for leftward elements
101557 ** of a 3-way or more compound */
101558 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
101559 assert( p->pOffset==0 ); /* Not allowed on leftward elements */
101560 unionTab = dest.iSDParm;
101561 }else{
101562 /* We will need to create our own temporary table to hold the
@@ -101565,11 +101638,11 @@
101565 unionTab = pParse->nTab++;
101566 assert( p->pOrderBy==0 );
101567 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
101568 assert( p->addrOpenEphm[0] == -1 );
101569 p->addrOpenEphm[0] = addr;
101570 p->pRightmost->selFlags |= SF_UsesEphemeral;
101571 assert( p->pEList );
101572 }
101573
101574 /* Code the SELECT statements to our left
101575 */
@@ -101624,16 +101697,16 @@
101624 generateColumnNames(pParse, 0, pFirst->pEList);
101625 }
101626 iBreak = sqlite3VdbeMakeLabel(v);
101627 iCont = sqlite3VdbeMakeLabel(v);
101628 computeLimitRegisters(pParse, p, iBreak);
101629 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
101630 iStart = sqlite3VdbeCurrentAddr(v);
101631 selectInnerLoop(pParse, p, p->pEList, unionTab,
101632 0, 0, &dest, iCont, iBreak);
101633 sqlite3VdbeResolveLabel(v, iCont);
101634 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
101635 sqlite3VdbeResolveLabel(v, iBreak);
101636 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
101637 }
101638 break;
101639 }
@@ -101654,11 +101727,11 @@
101654 assert( p->pOrderBy==0 );
101655
101656 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
101657 assert( p->addrOpenEphm[0] == -1 );
101658 p->addrOpenEphm[0] = addr;
101659 p->pRightmost->selFlags |= SF_UsesEphemeral;
101660 assert( p->pEList );
101661
101662 /* Code the SELECTs to our left into temporary table "tab1".
101663 */
101664 sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1);
@@ -101699,19 +101772,19 @@
101699 generateColumnNames(pParse, 0, pFirst->pEList);
101700 }
101701 iBreak = sqlite3VdbeMakeLabel(v);
101702 iCont = sqlite3VdbeMakeLabel(v);
101703 computeLimitRegisters(pParse, p, iBreak);
101704 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
101705 r1 = sqlite3GetTempReg(pParse);
101706 iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101707 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
101708 sqlite3ReleaseTempReg(pParse, r1);
101709 selectInnerLoop(pParse, p, p->pEList, tab1,
101710 0, 0, &dest, iCont, iBreak);
101711 sqlite3VdbeResolveLabel(v, iCont);
101712 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
101713 sqlite3VdbeResolveLabel(v, iBreak);
101714 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
101715 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
101716 break;
101717 }
@@ -101733,11 +101806,11 @@
101733 KeyInfo *pKeyInfo; /* Collating sequence for the result set */
101734 Select *pLoop; /* For looping through SELECT statements */
101735 CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
101736 int nCol; /* Number of columns in result set */
101737
101738 assert( p->pRightmost==p );
101739 nCol = p->pEList->nExpr;
101740 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
101741 if( !pKeyInfo ){
101742 rc = SQLITE_NOMEM;
101743 goto multi_select_end;
@@ -101814,14 +101887,14 @@
101814
101815 /* Suppress duplicates for UNION, EXCEPT, and INTERSECT
101816 */
101817 if( regPrev ){
101818 int j1, j2;
101819 j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
101820 j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
101821 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
101822 sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
101823 sqlite3VdbeJumpHere(v, j1);
101824 sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
101825 sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
101826 }
101827 if( pParse->db->mallocFailed ) return 0;
@@ -101918,11 +101991,11 @@
101918 }
101919
101920 /* Jump to the end of the loop if the LIMIT is reached.
101921 */
101922 if( p->iLimit ){
101923 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
101924 }
101925
101926 /* Generate the subroutine return
101927 */
101928 sqlite3VdbeResolveLabel(v, iContinue);
@@ -102026,20 +102099,19 @@
102026 Select *pPrior; /* Another SELECT immediately to our left */
102027 Vdbe *v; /* Generate code to this VDBE */
102028 SelectDest destA; /* Destination for coroutine A */
102029 SelectDest destB; /* Destination for coroutine B */
102030 int regAddrA; /* Address register for select-A coroutine */
102031 int regEofA; /* Flag to indicate when select-A is complete */
102032 int regAddrB; /* Address register for select-B coroutine */
102033 int regEofB; /* Flag to indicate when select-B is complete */
102034 int addrSelectA; /* Address of the select-A coroutine */
102035 int addrSelectB; /* Address of the select-B coroutine */
102036 int regOutA; /* Address register for the output-A subroutine */
102037 int regOutB; /* Address register for the output-B subroutine */
102038 int addrOutA; /* Address of the output-A subroutine */
102039 int addrOutB = 0; /* Address of the output-B subroutine */
102040 int addrEofA; /* Address of the select-A-exhausted subroutine */
 
102041 int addrEofB; /* Address of the select-B-exhausted subroutine */
102042 int addrAltB; /* Address of the A<B subroutine */
102043 int addrAeqB; /* Address of the A==B subroutine */
102044 int addrAgtB; /* Address of the A>B subroutine */
102045 int regLimitA; /* Limit register for select-A */
@@ -102150,10 +102222,11 @@
102150 }
102151
102152 /* Separate the left and the right query from one another
102153 */
102154 p->pPrior = 0;
 
102155 sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
102156 if( pPrior->pPrior==0 ){
102157 sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
102158 }
102159
@@ -102172,52 +102245,43 @@
102172 p->pLimit = 0;
102173 sqlite3ExprDelete(db, p->pOffset);
102174 p->pOffset = 0;
102175
102176 regAddrA = ++pParse->nMem;
102177 regEofA = ++pParse->nMem;
102178 regAddrB = ++pParse->nMem;
102179 regEofB = ++pParse->nMem;
102180 regOutA = ++pParse->nMem;
102181 regOutB = ++pParse->nMem;
102182 sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
102183 sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
102184
102185 /* Jump past the various subroutines and coroutines to the main
102186 ** merge loop
102187 */
102188 j1 = sqlite3VdbeAddOp0(v, OP_Goto);
102189 addrSelectA = sqlite3VdbeCurrentAddr(v);
102190
102191
102192 /* Generate a coroutine to evaluate the SELECT statement to the
102193 ** left of the compound operator - the "A" select.
102194 */
102195 VdbeNoopComment((v, "Begin coroutine for left SELECT"));
 
 
102196 pPrior->iLimit = regLimitA;
102197 explainSetInteger(iSub1, pParse->iNextSelectId);
102198 sqlite3Select(pParse, pPrior, &destA);
102199 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofA);
102200 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102201 VdbeNoopComment((v, "End coroutine for left SELECT"));
102202
102203 /* Generate a coroutine to evaluate the SELECT statement on
102204 ** the right - the "B" select
102205 */
102206 addrSelectB = sqlite3VdbeCurrentAddr(v);
102207 VdbeNoopComment((v, "Begin coroutine for right SELECT"));
 
102208 savedLimit = p->iLimit;
102209 savedOffset = p->iOffset;
102210 p->iLimit = regLimitB;
102211 p->iOffset = 0;
102212 explainSetInteger(iSub2, pParse->iNextSelectId);
102213 sqlite3Select(pParse, p, &destB);
102214 p->iLimit = savedLimit;
102215 p->iOffset = savedOffset;
102216 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofB);
102217 sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102218 VdbeNoopComment((v, "End coroutine for right SELECT"));
102219
102220 /* Generate a subroutine that outputs the current row of the A
102221 ** select as the next output row of the compound select.
102222 */
102223 VdbeNoopComment((v, "Output routine for A"));
@@ -102237,17 +102301,17 @@
102237 sqlite3KeyInfoUnref(pKeyDup);
102238
102239 /* Generate a subroutine to run when the results from select A
102240 ** are exhausted and only data in select B remains.
102241 */
102242 VdbeNoopComment((v, "eof-A subroutine"));
102243 if( op==TK_EXCEPT || op==TK_INTERSECT ){
102244 addrEofA = sqlite3VdbeAddOp2(v, OP_Goto, 0, labelEnd);
102245 }else{
102246 addrEofA = sqlite3VdbeAddOp2(v, OP_If, regEofB, labelEnd);
102247 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102248 sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
 
102249 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
102250 p->nSelectRow += pPrior->nSelectRow;
102251 }
102252
102253 /* Generate a subroutine to run when the results from select B
@@ -102256,22 +102320,20 @@
102256 if( op==TK_INTERSECT ){
102257 addrEofB = addrEofA;
102258 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
102259 }else{
102260 VdbeNoopComment((v, "eof-B subroutine"));
102261 addrEofB = sqlite3VdbeAddOp2(v, OP_If, regEofA, labelEnd);
102262 sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102263 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102264 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
102265 }
102266
102267 /* Generate code to handle the case of A<B
102268 */
102269 VdbeNoopComment((v, "A-lt-B subroutine"));
102270 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102271 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102272 sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102273 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102274
102275 /* Generate code to handle the case of A==B
102276 */
102277 if( op==TK_ALL ){
@@ -102280,12 +102342,11 @@
102280 addrAeqB = addrAltB;
102281 addrAltB++;
102282 }else{
102283 VdbeNoopComment((v, "A-eq-B subroutine"));
102284 addrAeqB =
102285 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102286 sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102287 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102288 }
102289
102290 /* Generate code to handle the case of A>B
102291 */
@@ -102292,32 +102353,27 @@
102292 VdbeNoopComment((v, "A-gt-B subroutine"));
102293 addrAgtB = sqlite3VdbeCurrentAddr(v);
102294 if( op==TK_ALL || op==TK_UNION ){
102295 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102296 }
102297 sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102298 sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102299 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102300
102301 /* This code runs once to initialize everything.
102302 */
102303 sqlite3VdbeJumpHere(v, j1);
102304 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofA);
102305 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofB);
102306 sqlite3VdbeAddOp2(v, OP_Gosub, regAddrA, addrSelectA);
102307 sqlite3VdbeAddOp2(v, OP_Gosub, regAddrB, addrSelectB);
102308 sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102309 sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102310
102311 /* Implement the main merge loop
102312 */
102313 sqlite3VdbeResolveLabel(v, labelCmpr);
102314 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
102315 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
102316 (char*)pKeyMerge, P4_KEYINFO);
102317 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
102318 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
102319
102320 /* Jump to the this point in order to terminate the query.
102321 */
102322 sqlite3VdbeResolveLabel(v, labelEnd);
102323
@@ -102333,10 +102389,11 @@
102333 ** by the calling function */
102334 if( p->pPrior ){
102335 sqlite3SelectDelete(db, p->pPrior);
102336 }
102337 p->pPrior = pPrior;
 
102338
102339 /*** TBD: Insert subroutine calls to close cursors on incomplete
102340 **** subqueries ****/
102341 explainComposite(pParse, p->op, iSub1, iSub2, 0);
102342 return SQLITE_OK;
@@ -102598,11 +102655,11 @@
102598 ** because they could be computed at compile-time. But when LIMIT and OFFSET
102599 ** became arbitrary expressions, we were forced to add restrictions (13)
102600 ** and (14). */
102601 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
102602 if( pSub->pOffset ) return 0; /* Restriction (14) */
102603 if( p->pRightmost && pSub->pLimit ){
102604 return 0; /* Restriction (15) */
102605 }
102606 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
102607 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (5) */
102608 if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){
@@ -102749,18 +102806,18 @@
102749 p->pOffset = pOffset;
102750 p->pLimit = pLimit;
102751 p->pOrderBy = pOrderBy;
102752 p->pSrc = pSrc;
102753 p->op = TK_ALL;
102754 p->pRightmost = 0;
102755 if( pNew==0 ){
102756 pNew = pPrior;
102757 }else{
102758 pNew->pPrior = pPrior;
102759 pNew->pRightmost = 0;
 
 
102760 }
102761 p->pPrior = pNew;
102762 if( db->mallocFailed ) return 1;
102763 }
102764
102765 /* Begin flattening the iFrom-th entry of the FROM clause
102766 ** in the outer query.
@@ -103095,10 +103152,14 @@
103095 p->pWhere = 0;
103096 pNew->pGroupBy = 0;
103097 pNew->pHaving = 0;
103098 pNew->pOrderBy = 0;
103099 p->pPrior = 0;
 
 
 
 
103100 pNew->pLimit = 0;
103101 pNew->pOffset = 0;
103102 return WRC_Continue;
103103 }
103104
@@ -103282,13 +103343,14 @@
103282 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
103283 ** names and other FROM clause elements.
103284 */
103285 static void selectPopWith(Walker *pWalker, Select *p){
103286 Parse *pParse = pWalker->pParse;
103287 if( p->pWith ){
103288 assert( pParse->pWith==p->pWith );
103289 pParse->pWith = p->pWith->pOuter;
 
103290 }
103291 }
103292 #else
103293 #define selectPopWith 0
103294 #endif
@@ -103334,11 +103396,11 @@
103334 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
103335 return WRC_Prune;
103336 }
103337 pTabList = p->pSrc;
103338 pEList = p->pEList;
103339 sqlite3WithPush(pParse, p->pWith, 0);
103340
103341 /* Make sure cursor numbers have been assigned to all entries in
103342 ** the FROM clause of the SELECT statement.
103343 */
103344 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -103847,11 +103909,11 @@
103847 **
103848 ** Another solution would be to change the OP_SCopy used to copy cached
103849 ** values to an OP_Copy.
103850 */
103851 if( regHit ){
103852 addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit);
103853 }
103854 sqlite3ExprCacheClear(pParse);
103855 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
103856 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
103857 }
@@ -104006,46 +104068,28 @@
104006 if( isAggSub ){
104007 isAgg = 1;
104008 p->selFlags |= SF_Aggregate;
104009 }
104010 i = -1;
104011 }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0
104012 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
104013 ){
104014 /* Implement a co-routine that will return a single row of the result
104015 ** set on each invocation.
104016 */
104017 int addrTop;
104018 int addrEof;
104019 pItem->regReturn = ++pParse->nMem;
104020 addrEof = ++pParse->nMem;
104021 /* Before coding the OP_Goto to jump to the start of the main routine,
104022 ** ensure that the jump to the verify-schema routine has already
104023 ** been coded. Otherwise, the verify-schema would likely be coded as
104024 ** part of the co-routine. If the main routine then accessed the
104025 ** database before invoking the co-routine for the first time (for
104026 ** example to initialize a LIMIT register from a sub-select), it would
104027 ** be doing so without having verified the schema version and obtained
104028 ** the required db locks. See ticket d6b36be38. */
104029 sqlite3CodeVerifySchema(pParse, -1);
104030 sqlite3VdbeAddOp0(v, OP_Goto);
104031 addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor);
104032 sqlite3VdbeChangeP5(v, 1);
104033 VdbeComment((v, "coroutine for %s", pItem->pTab->zName));
104034 pItem->addrFillSub = addrTop;
104035 sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof);
104036 sqlite3VdbeChangeP5(v, 1);
104037 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
104038 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104039 sqlite3Select(pParse, pSub, &dest);
104040 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
104041 pItem->viaCoroutine = 1;
104042 sqlite3VdbeChangeP2(v, addrTop, dest.iSdst);
104043 sqlite3VdbeChangeP3(v, addrTop, dest.nSdst);
104044 sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof);
104045 sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn);
104046 VdbeComment((v, "end %s", pItem->pTab->zName));
104047 sqlite3VdbeJumpHere(v, addrTop-1);
104048 sqlite3ClearTempRegCache(pParse);
104049 }else{
104050 /* Generate a subroutine that will fill an ephemeral table with
104051 ** the content of this subquery. pItem->addrFillSub will point
@@ -104057,16 +104101,18 @@
104057 int retAddr;
104058 assert( pItem->addrFillSub==0 );
104059 pItem->regReturn = ++pParse->nMem;
104060 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
104061 pItem->addrFillSub = topAddr+1;
104062 VdbeNoopComment((v, "materialize %s", pItem->pTab->zName));
104063 if( pItem->isCorrelated==0 ){
104064 /* If the subquery is not correlated and if we are not inside of
104065 ** a trigger, then we only need to compute the value of the subquery
104066 ** once. */
104067 onceAddr = sqlite3CodeOnce(pParse);
 
 
 
104068 }
104069 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
104070 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104071 sqlite3Select(pParse, pSub, &dest);
104072 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
@@ -104094,25 +104140,10 @@
104094
104095 #ifndef SQLITE_OMIT_COMPOUND_SELECT
104096 /* If there is are a sequence of queries, do the earlier ones first.
104097 */
104098 if( p->pPrior ){
104099 if( p->pRightmost==0 ){
104100 Select *pLoop, *pRight = 0;
104101 int cnt = 0;
104102 int mxSelect;
104103 for(pLoop=p; pLoop; pLoop=pLoop->pPrior, cnt++){
104104 pLoop->pRightmost = p;
104105 pLoop->pNext = pRight;
104106 pRight = pLoop;
104107 }
104108 mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
104109 if( mxSelect && cnt>mxSelect ){
104110 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
104111 goto select_end;
104112 }
104113 }
104114 rc = multiSelect(pParse, p, pDest);
104115 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
104116 return rc;
104117 }
104118 #endif
@@ -104412,11 +104443,11 @@
104412 sqlite3WhereEnd(pWInfo);
104413 sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
104414 sortOut = sqlite3GetTempReg(pParse);
104415 sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
104416 sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
104417 VdbeComment((v, "GROUP BY sort"));
104418 sAggInfo.useSortingIdx = 1;
104419 sqlite3ExprCacheClear(pParse);
104420 }
104421
104422 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
@@ -104439,11 +104470,11 @@
104439 }
104440 }
104441 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
104442 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
104443 j1 = sqlite3VdbeCurrentAddr(v);
104444 sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
104445
104446 /* Generate code that runs whenever the GROUP BY changes.
104447 ** Changes in the GROUP BY are detected by the previous code
104448 ** block. If there were no changes, this block is skipped.
104449 **
@@ -104453,11 +104484,11 @@
104453 ** for the next GROUP BY batch.
104454 */
104455 sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
104456 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
104457 VdbeComment((v, "output one row"));
104458 sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd);
104459 VdbeComment((v, "check abort flag"));
104460 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
104461 VdbeComment((v, "reset accumulator"));
104462
104463 /* Update the aggregate accumulators based on the content of
@@ -104470,10 +104501,11 @@
104470
104471 /* End of the loop
104472 */
104473 if( groupBySort ){
104474 sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
 
104475 }else{
104476 sqlite3WhereEnd(pWInfo);
104477 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
104478 }
104479
@@ -104497,11 +104529,11 @@
104497 sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
104498 VdbeComment((v, "set abort flag"));
104499 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104500 sqlite3VdbeResolveLabel(v, addrOutputRow);
104501 addrOutputRow = sqlite3VdbeCurrentAddr(v);
104502 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
104503 VdbeComment((v, "Groupby result generator entry point"));
104504 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104505 finalizeAggFunctions(pParse, &sAggInfo);
104506 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104507 selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
@@ -104770,14 +104802,10 @@
104770 SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
104771 if( p==0 ){
104772 sqlite3ExplainPrintf(pVdbe, "(null-select)");
104773 return;
104774 }
104775 while( p->pPrior ){
104776 p->pPrior->pNext = p;
104777 p = p->pPrior;
104778 }
104779 sqlite3ExplainPush(pVdbe);
104780 while( p ){
104781 explainOneSelect(pVdbe, p);
104782 p = p->pNext;
104783 if( p==0 ) break;
@@ -105558,10 +105586,11 @@
105558 /* Generate code to destroy the database record of the trigger.
105559 */
105560 assert( pTable!=0 );
105561 if( (v = sqlite3GetVdbe(pParse))!=0 ){
105562 int base;
 
105563 static const VdbeOpList dropTrigger[] = {
105564 { OP_Rewind, 0, ADDR(9), 0},
105565 { OP_String8, 0, 1, 0}, /* 1 */
105566 { OP_Column, 0, 1, 2},
105567 { OP_Ne, 2, ADDR(8), 1},
@@ -105572,11 +105601,11 @@
105572 { OP_Next, 0, ADDR(1), 0}, /* 8 */
105573 };
105574
105575 sqlite3BeginWriteOperation(pParse, 0, iDb);
105576 sqlite3OpenMasterTable(pParse, iDb);
105577 base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
105578 sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
105579 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
105580 sqlite3ChangeCookie(pParse, iDb);
105581 sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
105582 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
@@ -105718,19 +105747,11 @@
105718 **
105719 ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
105720 ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
105721 */
105722 pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
105723
105724 /* Clear the cookieGoto flag. When coding triggers, the cookieGoto
105725 ** variable is used as a flag to indicate to sqlite3ExprCodeConstants()
105726 ** that it is not safe to refactor constants (this happens after the
105727 ** start of the first loop in the SQL statement is coded - at that
105728 ** point code may be conditionally executed, so it is no longer safe to
105729 ** initialize constant register values). */
105730 assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 );
105731 pParse->cookieGoto = 0;
105732
105733 switch( pStep->op ){
105734 case TK_UPDATE: {
105735 sqlite3Update(pParse,
105736 targetSrcList(pParse, pStep),
@@ -106515,11 +106536,11 @@
106515 sqlite3VdbeChangeToNoop(v, addrOpen);
106516 nKey = nPk;
106517 regKey = iPk;
106518 }else{
106519 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106520 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
106521 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106522 }
106523 sqlite3WhereEnd(pWInfo);
106524 }
106525
@@ -106559,32 +106580,37 @@
106559 /* Top of the update loop */
106560 if( okOnePass ){
106561 if( aToOpen[iDataCur-iBaseCur] ){
106562 assert( pPk!=0 );
106563 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
 
106564 }
106565 labelContinue = labelBreak;
106566 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
 
106567 }else if( pPk ){
106568 labelContinue = sqlite3VdbeMakeLabel(v);
106569 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
106570 addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106571 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
 
106572 }else{
106573 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106574 regOldRowid);
 
106575 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
 
106576 }
106577
106578 /* If the record number will change, set register regNewRowid to
106579 ** contain the new value. If the record number is not being modified,
106580 ** then regNewRowid is the same register as regOldRowid, which is
106581 ** already populated. */
106582 assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
106583 if( chngRowid ){
106584 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
106585 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
106586 }
106587
106588 /* Compute the old pre-UPDATE content of the row being changed, if that
106589 ** information is needed */
106590 if( chngPk || hasFK || pTrigger ){
@@ -106649,12 +106675,11 @@
106649
106650 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
106651 ** verified. One could argue that this is wrong.
106652 */
106653 if( tmask&TRIGGER_BEFORE ){
106654 sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
106655 sqlite3TableAffinityStr(v, pTab);
106656 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106657 TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
106658
106659 /* The row-trigger may have deleted the row being updated. In this
106660 ** case, jump to the next row. No updates or AFTER triggers are
@@ -106662,12 +106687,14 @@
106662 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
106663 ** documentation.
106664 */
106665 if( pPk ){
106666 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
 
106667 }else{
106668 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
 
106669 }
106670
106671 /* If it did not delete it, the row-trigger may still have modified
106672 ** some of the columns of the row being updated. Load the values for
106673 ** all columns not modified by the update statement into their
@@ -106699,10 +106726,11 @@
106699 if( pPk ){
106700 j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106701 }else{
106702 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106703 }
 
106704 }
106705 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
106706
106707 /* If changing the record number, delete the old record. */
106708 if( hasFK || chngKey || pPk!=0 ){
@@ -106742,11 +106770,11 @@
106742 */
106743 if( okOnePass ){
106744 /* Nothing to do at end-of-loop for a single-pass */
106745 }else if( pPk ){
106746 sqlite3VdbeResolveLabel(v, labelContinue);
106747 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop);
106748 }else{
106749 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106750 }
106751 sqlite3VdbeResolveLabel(v, labelBreak);
106752
@@ -106871,21 +106899,21 @@
106871 sqlite3Select(pParse, pSelect, &dest);
106872
106873 /* Generate code to scan the ephemeral table and call VUpdate. */
106874 iReg = ++pParse->nMem;
106875 pParse->nMem += pTab->nCol+1;
106876 addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);
106877 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, 0, iReg);
106878 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
106879 for(i=0; i<pTab->nCol; i++){
106880 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
106881 }
106882 sqlite3VtabMakeWritable(pParse, pTab);
106883 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
106884 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
106885 sqlite3MayAbort(pParse);
106886 sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
106887 sqlite3VdbeJumpHere(v, addr);
106888 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
106889
106890 /* Cleanup */
106891 sqlite3SelectDelete(db, pSelect);
@@ -108453,11 +108481,11 @@
108453 int addrSkip; /* Jump here for next iteration of skip-scan */
108454 int addrCont; /* Jump here to continue with the next loop cycle */
108455 int addrFirst; /* First instruction of interior of the loop */
108456 int addrBody; /* Beginning of the body of this loop */
108457 u8 iFrom; /* Which entry in the FROM clause */
108458 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
108459 int p1, p2; /* Operands of the opcode used to ends the loop */
108460 union { /* Information that depends on pWLoop->wsFlags */
108461 struct {
108462 int nIn; /* Number of entries in aInLoop[] */
108463 struct InLoop {
@@ -108840,10 +108868,11 @@
108840 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108841 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108842 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108843 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108844 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
 
108845
108846 /************** End of whereInt.h ********************************************/
108847 /************** Continuing where we left off in where.c **********************/
108848
108849 /*
@@ -110426,11 +110455,11 @@
110426
110427 /* Generate code to skip over the creation and initialization of the
110428 ** transient index on 2nd and subsequent iterations of the loop. */
110429 v = pParse->pVdbe;
110430 assert( v!=0 );
110431 addrInit = sqlite3CodeOnce(pParse);
110432
110433 /* Count the number of columns that will be added to the index
110434 ** and used to match WHERE clause constraints */
110435 nKeyCol = 0;
110436 pTable = pSrc->pTab;
@@ -110533,16 +110562,16 @@
110533 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110534 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
110535 VdbeComment((v, "for %s", pTable->zName));
110536
110537 /* Fill the automatic index with content */
110538 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
110539 regRecord = sqlite3GetTempReg(pParse);
110540 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
110541 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
110542 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
110543 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
110544 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
110545 sqlite3VdbeJumpHere(v, addrTop);
110546 sqlite3ReleaseTempReg(pParse, regRecord);
110547
110548 /* Jump here when skipping the initialization */
@@ -111214,10 +111243,12 @@
111214 testcase( bRev );
111215 bRev = !bRev;
111216 }
111217 iTab = pX->iTable;
111218 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
 
 
111219 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
111220 pLoop->wsFlags |= WHERE_IN_ABLE;
111221 if( pLevel->u.in.nIn==0 ){
111222 pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
111223 }
@@ -111233,11 +111264,11 @@
111233 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
111234 }else{
111235 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
111236 }
111237 pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
111238 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
111239 }else{
111240 pLevel->u.in.nIn = 0;
111241 }
111242 #endif
111243 }
@@ -111328,14 +111359,18 @@
111328 }
111329
111330 if( nSkip ){
111331 int iIdxCur = pLevel->iIdxCur;
111332 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
 
 
111333 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
111334 j = sqlite3VdbeAddOp0(v, OP_Goto);
111335 pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
111336 iIdxCur, 0, regBase, nSkip);
 
 
111337 sqlite3VdbeJumpHere(v, j);
111338 for(j=0; j<nSkip; j++){
111339 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
111340 assert( pIdx->aiColumn[j]>=0 );
111341 VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
@@ -111364,11 +111399,14 @@
111364 }
111365 testcase( pTerm->eOperator & WO_ISNULL );
111366 testcase( pTerm->eOperator & WO_IN );
111367 if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
111368 Expr *pRight = pTerm->pExpr->pRight;
111369 sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk);
 
 
 
111370 if( zAff ){
111371 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
111372 zAff[j] = SQLITE_AFF_NONE;
111373 }
111374 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
@@ -111610,14 +111648,14 @@
111610 }
111611
111612 /* Special case of a FROM clause subquery implemented as a co-routine */
111613 if( pTabItem->viaCoroutine ){
111614 int regYield = pTabItem->regReturn;
111615 sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield);
111616 pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
111617 VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName));
111618 sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk);
111619 pLevel->op = OP_Goto;
111620 }else
111621
111622 #ifndef SQLITE_OMIT_VIRTUALTABLE
111623 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -111645,10 +111683,11 @@
111645 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
111646 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
111647 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
111648 pLoop->u.vtab.idxStr,
111649 pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
 
111650 pLoop->u.vtab.needFree = 0;
111651 for(j=0; j<nConstraint && j<16; j++){
111652 if( (pLoop->u.vtab.omitMask>>j)&1 ){
111653 disableTerm(pLevel, pLoop->aLTerm[j]);
111654 }
@@ -111668,20 +111707,22 @@
111668 ** equality comparison against the ROWID field. Or
111669 ** we reference multiple rows using a "rowid IN (...)"
111670 ** construct.
111671 */
111672 assert( pLoop->u.btree.nEq==1 );
111673 iReleaseReg = sqlite3GetTempReg(pParse);
111674 pTerm = pLoop->aLTerm[0];
111675 assert( pTerm!=0 );
111676 assert( pTerm->pExpr!=0 );
111677 assert( omitTable==0 );
111678 testcase( pTerm->wtFlags & TERM_VIRTUAL );
 
111679 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
 
111680 addrNxt = pLevel->addrNxt;
111681 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
111682 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
 
111683 sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
111684 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111685 VdbeComment((v, "pk"));
111686 pLevel->op = OP_Noop;
111687 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -111711,14 +111752,14 @@
111711
111712 /* The following constant maps TK_xx codes into corresponding
111713 ** seek opcodes. It depends on a particular ordering of TK_xx
111714 */
111715 const u8 aMoveOp[] = {
111716 /* TK_GT */ OP_SeekGt,
111717 /* TK_LE */ OP_SeekLe,
111718 /* TK_LT */ OP_SeekLt,
111719 /* TK_GE */ OP_SeekGe
111720 };
111721 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
111722 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
111723 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
111724
@@ -111728,15 +111769,21 @@
111728 assert( pX!=0 );
111729 testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
111730 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
111731 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
111732 VdbeComment((v, "pk"));
 
 
 
 
111733 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
111734 sqlite3ReleaseTempReg(pParse, rTemp);
111735 disableTerm(pLevel, pStart);
111736 }else{
111737 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
 
 
111738 }
111739 if( pEnd ){
111740 Expr *pX;
111741 pX = pEnd->pExpr;
111742 assert( pX!=0 );
@@ -111756,14 +111803,18 @@
111756 pLevel->op = bRev ? OP_Prev : OP_Next;
111757 pLevel->p1 = iCur;
111758 pLevel->p2 = start;
111759 assert( pLevel->p5==0 );
111760 if( testOp!=OP_Noop ){
111761 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
111762 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
111763 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111764 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
 
 
 
 
111765 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
111766 }
111767 }else if( pLoop->wsFlags & WHERE_INDEXED ){
111768 /* Case 4: A scan using an index.
111769 **
@@ -111799,24 +111850,23 @@
111799 static const u8 aStartOp[] = {
111800 0,
111801 0,
111802 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
111803 OP_Last, /* 3: (!start_constraints && startEq && bRev) */
111804 OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
111805 OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
111806 OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
111807 OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
111808 };
111809 static const u8 aEndOp[] = {
111810 OP_Noop, /* 0: (!end_constraints) */
111811 OP_IdxGE, /* 1: (end_constraints && !bRev) */
111812 OP_IdxLT /* 2: (end_constraints && bRev) */
 
111813 };
111814 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111815 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111816 int regBase; /* Base register holding constraint values */
111817 int r1; /* Temp register */
111818 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111819 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111820 int startEq; /* True if range start uses ==, >= or <= */
111821 int endEq; /* True if range end uses ==, >= or <= */
111822 int start_constraints; /* Start of range is constrained */
@@ -111825,10 +111875,12 @@
111825 int iIdxCur; /* The VDBE cursor for the index */
111826 int nExtraReg = 0; /* Number of extra registers needed */
111827 int op; /* Instruction opcode */
111828 char *zStartAff; /* Affinity for start of range constraint */
111829 char cEndAff = 0; /* Affinity for end of range constraint */
 
 
111830
111831 pIdx = pLoop->u.btree.pIndex;
111832 iIdxCur = pLevel->iIdxCur;
111833 assert( nEq>=pLoop->u.btree.nSkip );
111834
@@ -111843,11 +111895,11 @@
111843 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111844 && (pWInfo->bOBSat!=0)
111845 && (pIdx->nKeyCol>nEq)
111846 ){
111847 assert( pLoop->u.btree.nSkip==0 );
111848 isMinQuery = 1;
111849 nExtraReg = 1;
111850 }
111851
111852 /* Find any inequality constraint terms for the start and end
111853 ** of the range.
@@ -111858,10 +111910,17 @@
111858 nExtraReg = 1;
111859 }
111860 if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
111861 pRangeEnd = pLoop->aLTerm[j++];
111862 nExtraReg = 1;
 
 
 
 
 
 
 
111863 }
111864
111865 /* Generate code to evaluate all constraint terms using == or IN
111866 ** and store the values of those terms in an array of registers
111867 ** starting at regBase.
@@ -111877,10 +111936,11 @@
111877 */
111878 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111879 || (bRev && pIdx->nKeyCol==nEq)
111880 ){
111881 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
 
111882 }
111883
111884 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
111885 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
111886 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
@@ -111892,12 +111952,15 @@
111892 /* Seek the index cursor to the start of the range. */
111893 nConstraint = nEq;
111894 if( pRangeStart ){
111895 Expr *pRight = pRangeStart->pExpr->pRight;
111896 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111897 if( (pRangeStart->wtFlags & TERM_VNULL)==0 ){
111898 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
 
 
 
111899 }
111900 if( zStartAff ){
111901 if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){
111902 /* Since the comparison is to be performed with no conversions
111903 ** applied to the operands, set the affinity to apply to pRight to
@@ -111908,86 +111971,76 @@
111908 zStartAff[nEq] = SQLITE_AFF_NONE;
111909 }
111910 }
111911 nConstraint++;
111912 testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
111913 }else if( isMinQuery ){
111914 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
111915 nConstraint++;
111916 startEq = 0;
111917 start_constraints = 1;
111918 }
111919 codeApplyAffinity(pParse, regBase, nConstraint, zStartAff);
111920 op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
111921 assert( op!=0 );
111922 testcase( op==OP_Rewind );
111923 testcase( op==OP_Last );
111924 testcase( op==OP_SeekGt );
111925 testcase( op==OP_SeekGe );
111926 testcase( op==OP_SeekLe );
111927 testcase( op==OP_SeekLt );
111928 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
 
 
 
 
 
 
 
111929
111930 /* Load the value for the inequality constraint at the end of the
111931 ** range (if any).
111932 */
111933 nConstraint = nEq;
111934 if( pRangeEnd ){
111935 Expr *pRight = pRangeEnd->pExpr->pRight;
111936 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111937 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111938 if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111939 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
 
 
 
111940 }
111941 if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
111942 && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
111943 ){
111944 codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
111945 }
111946 nConstraint++;
111947 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
 
 
 
 
111948 }
111949 sqlite3DbFree(db, zStartAff);
111950
111951 /* Top of the loop body */
111952 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111953
111954 /* Check if the index cursor is past the end of the range. */
111955 op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
111956 testcase( op==OP_Noop );
111957 testcase( op==OP_IdxGE );
111958 testcase( op==OP_IdxLT );
111959 if( op!=OP_Noop ){
111960 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111961 sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
111962 }
111963
111964 /* If there are inequality constraints, check that the value
111965 ** of the table column that the inequality contrains is not NULL.
111966 ** If it is, jump to the next iteration of the loop.
111967 */
111968 r1 = sqlite3GetTempReg(pParse);
111969 testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111970 testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111971 if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111972 && (j = pIdx->aiColumn[nEq])>=0
111973 && pIdx->pTable->aCol[j].notNull==0
111974 && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111975 ){
111976 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111977 VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111978 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111979 }
111980 sqlite3ReleaseTempReg(pParse, r1);
111981
111982 /* Seek the table cursor, if required */
111983 disableTerm(pLevel, pRangeStart);
111984 disableTerm(pLevel, pRangeEnd);
111985 if( omitTable ){
111986 /* pIdx is a covering index. No need to access the main table. */
111987 }else if( HasRowid(pIdx->pTable) ){
111988 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
111989 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
111990 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111991 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
111992 }else{
111993 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
@@ -111995,11 +112048,11 @@
111995 for(j=0; j<pPk->nKeyCol; j++){
111996 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
111997 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
111998 }
111999 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
112000 iRowidReg, pPk->nKeyCol);
112001 }
112002
112003 /* Record the instruction used to terminate the loop. Disable
112004 ** WHERE clause terms made redundant by the index range scan.
112005 */
@@ -112009,10 +112062,12 @@
112009 pLevel->op = OP_Prev;
112010 }else{
112011 pLevel->op = OP_Next;
112012 }
112013 pLevel->p1 = iIdxCur;
 
 
112014 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
112015 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112016 }else{
112017 assert( pLevel->p5==0 );
112018 }
@@ -112177,10 +112232,11 @@
112177 int r;
112178 r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
112179 regRowid, 0);
112180 sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
112181 sqlite3VdbeCurrentAddr(v)+2, r, iSet);
 
112182 }
112183 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
112184
112185 /* The pSubWInfo->untestedTerms flag means that this OR term
112186 ** contained one or more AND term from a notReady table. The
@@ -112245,10 +112301,12 @@
112245 pLevel->op = OP_Noop;
112246 }else{
112247 pLevel->op = aStep[bRev];
112248 pLevel->p1 = iCur;
112249 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
 
 
112250 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112251 }
112252 }
112253
112254 /* Insert code to test every subexpression that can be completely
@@ -112326,11 +112384,10 @@
112326 assert( pTerm->pExpr );
112327 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
112328 pTerm->wtFlags |= TERM_CODED;
112329 }
112330 }
112331 sqlite3ReleaseTempReg(pParse, iReleaseReg);
112332
112333 return pLevel->notReady;
112334 }
112335
112336 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -112813,16 +112870,17 @@
112813 assert(
112814 (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112815 || nInMul==0
112816 );
112817 pNew->wsFlags |= WHERE_COLUMN_EQ;
112818 if( iCol<0
112819 || (pProbe->onError!=OE_None && nInMul==0
112820 && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112821 ){
112822 assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
112823 pNew->wsFlags |= WHERE_ONEROW;
 
 
 
 
112824 }
112825 pNew->u.btree.nEq++;
112826 pNew->nOut = nRowEst + nInMul;
112827 }else if( pTerm->eOperator & (WO_ISNULL) ){
112828 pNew->wsFlags |= WHERE_COLUMN_NULL;
@@ -113697,13 +113755,16 @@
113697 /* Mark off any other ORDER BY terms that reference pLoop */
113698 if( isOrderDistinct ){
113699 orderDistinctMask |= pLoop->maskSelf;
113700 for(i=0; i<nOrderBy; i++){
113701 Expr *p;
 
113702 if( MASKBIT(i) & obSat ) continue;
113703 p = pOrderBy->a[i].pExpr;
113704 if( (exprTableUsage(&pWInfo->sMaskSet, p)&~orderDistinctMask)==0 ){
 
 
113705 obSat |= MASKBIT(i);
113706 }
113707 }
113708 }
113709 } /* End the loop over all WhereLoops from outer-most down to inner-most */
@@ -114261,11 +114322,10 @@
114261 ** subexpression is separated by an AND operator.
114262 */
114263 initMaskSet(pMaskSet);
114264 whereClauseInit(&pWInfo->sWC, pWInfo);
114265 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
114266 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
114267
114268 /* Special case: a WHERE clause that is constant. Evaluate the
114269 ** expression and either jump over all of the code or fall thru.
114270 */
114271 for(ii=0; ii<sWLB.pWC->nTerm; ii++){
@@ -114323,26 +114383,10 @@
114323 exprAnalyzeAll(pTabList, &pWInfo->sWC);
114324 if( db->mallocFailed ){
114325 goto whereBeginError;
114326 }
114327
114328 /* If the ORDER BY (or GROUP BY) clause contains references to general
114329 ** expressions, then we won't be able to satisfy it using indices, so
114330 ** go ahead and disable it now.
114331 */
114332 if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
114333 for(ii=0; ii<pOrderBy->nExpr; ii++){
114334 Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
114335 if( pExpr->op!=TK_COLUMN ){
114336 pWInfo->pOrderBy = pOrderBy = 0;
114337 break;
114338 }else if( pExpr->iColumn<0 ){
114339 break;
114340 }
114341 }
114342 }
114343
114344 if( wctrlFlags & WHERE_WANT_DISTINCT ){
114345 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
114346 /* The DISTINCT marking is pointless. Ignore it. */
114347 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
114348 }else if( pOrderBy==0 ){
@@ -114550,11 +114594,11 @@
114550 assert( iIndexCur>=0 );
114551 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
114552 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
114553 VdbeComment((v, "%s", pIx->zName));
114554 }
114555 sqlite3CodeVerifySchema(pParse, iDb);
114556 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
114557 }
114558 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
114559 if( db->mallocFailed ) goto whereBeginError;
114560
@@ -114612,20 +114656,27 @@
114612 int addr;
114613 pLevel = &pWInfo->a[i];
114614 pLoop = pLevel->pWLoop;
114615 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114616 if( pLevel->op!=OP_Noop ){
114617 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
114618 sqlite3VdbeChangeP5(v, pLevel->p5);
 
 
 
 
114619 }
114620 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
114621 struct InLoop *pIn;
114622 int j;
114623 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
114624 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
114625 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
114626 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
 
 
 
114627 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114628 }
114629 sqlite3DbFree(db, pLevel->u.in.aInLoop);
114630 }
114631 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
@@ -114634,11 +114685,11 @@
114634 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114635 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114636 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114637 }
114638 if( pLevel->iLeftJoin ){
114639 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114640 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114641 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114642 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114643 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
114644 }
@@ -114661,15 +114712,41 @@
114661 */
114662 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
114663
114664 assert( pWInfo->nLevel<=pTabList->nSrc );
114665 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
 
 
114666 Index *pIdx = 0;
114667 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
114668 Table *pTab = pTabItem->pTab;
114669 assert( pTab!=0 );
114670 pLoop = pLevel->pWLoop;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114671
114672 /* Close all of the cursors that were opened by sqlite3WhereBegin.
114673 ** Except, do not close cursors that will be reused by the OR optimization
114674 ** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114675 ** created for the ONEPASS optimization.
@@ -114705,13 +114782,10 @@
114705 pIdx = pLoop->u.btree.pIndex;
114706 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
114707 pIdx = pLevel->u.pCovidx;
114708 }
114709 if( pIdx && !db->mallocFailed ){
114710 int k, last;
114711 VdbeOp *pOp;
114712
114713 last = sqlite3VdbeCurrentAddr(v);
114714 k = pLevel->addrBody;
114715 pOp = sqlite3VdbeGetOp(v, k);
114716 for(; k<last; k++, pOp++){
114717 if( pOp->p1!=pLevel->iTabCur ) continue;
@@ -117121,33 +117195,54 @@
117121 sqlite3ExplainFinish(pParse->pVdbe);
117122 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
117123 }
117124 break;
117125 case 112: /* select ::= with selectnowith */
117126 {
117127 if( yymsp[0].minor.yy3 ){
117128 yymsp[0].minor.yy3->pWith = yymsp[-1].minor.yy59;
 
 
 
 
 
 
 
 
 
 
 
 
 
117129 }else{
117130 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
117131 }
117132 yygotominor.yy3 = yymsp[0].minor.yy3;
117133 }
117134 break;
117135 case 113: /* selectnowith ::= oneselect */
117136 case 119: /* oneselect ::= values */ yytestcase(yyruleno==119);
117137 {yygotominor.yy3 = yymsp[0].minor.yy3;}
117138 break;
117139 case 114: /* selectnowith ::= selectnowith multiselect_op oneselect */
117140 {
117141 if( yymsp[0].minor.yy3 ){
117142 yymsp[0].minor.yy3->op = (u8)yymsp[-1].minor.yy328;
117143 yymsp[0].minor.yy3->pPrior = yymsp[-2].minor.yy3;
 
 
 
 
 
 
 
 
117144 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
117145 }else{
117146 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
117147 }
117148 yygotominor.yy3 = yymsp[0].minor.yy3;
117149 }
117150 break;
117151 case 116: /* multiselect_op ::= UNION ALL */
117152 {yygotominor.yy328 = TK_ALL;}
117153 break;
@@ -122711,10 +122806,25 @@
122711 case SQLITE_TESTCTRL_NEVER_CORRUPT: {
122712 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
122713 break;
122714 }
122715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122716 }
122717 va_end(ap);
122718 #endif /* SQLITE_OMIT_BUILTIN_TEST */
122719 return rc;
122720 }
122721
--- 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.4. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -23,10 +23,64 @@
23 # define SQLITE_PRIVATE static
24 #endif
25 #ifndef SQLITE_API
26 # define SQLITE_API
27 #endif
28 /************** Begin file sqliteInt.h ***************************************/
29 /*
30 ** 2001 September 15
31 **
32 ** The author disclaims copyright to this source code. In place of
33 ** a legal notice, here is a blessing:
34 **
35 ** May you do good and not evil.
36 ** May you find forgiveness for yourself and forgive others.
37 ** May you share freely, never taking more than you give.
38 **
39 *************************************************************************
40 ** Internal interface definitions for SQLite.
41 **
42 */
43 #ifndef _SQLITEINT_H_
44 #define _SQLITEINT_H_
45
46 /*
47 ** These #defines should enable >2GB file support on POSIX if the
48 ** underlying operating system supports it. If the OS lacks
49 ** large file support, or if the OS is windows, these should be no-ops.
50 **
51 ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
52 ** system #includes. Hence, this block of code must be the very first
53 ** code in all source files.
54 **
55 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
56 ** on the compiler command line. This is necessary if you are compiling
57 ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
58 ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
59 ** without this option, LFS is enable. But LFS does not exist in the kernel
60 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
61 ** portability you should omit LFS.
62 **
63 ** The previous paragraph was written in 2005. (This paragraph is written
64 ** on 2008-11-28.) These days, all Linux kernels support large files, so
65 ** you should probably leave LFS enabled. But some embedded platforms might
66 ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
67 **
68 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
69 */
70 #ifndef SQLITE_DISABLE_LFS
71 # define _LARGE_FILE 1
72 # ifndef _FILE_OFFSET_BITS
73 # define _FILE_OFFSET_BITS 64
74 # endif
75 # define _LARGEFILE_SOURCE 1
76 #endif
77
78 /* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear
79 ** first in QNX.
80 */
81 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
82 /************** Begin file sqlite3.h *****************************************/
83 /*
84 ** 2001 September 15
85 **
86 ** The author disclaims copyright to this source code. In place of
@@ -133,13 +187,13 @@
187 **
188 ** See also: [sqlite3_libversion()],
189 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190 ** [sqlite_version()] and [sqlite_source_id()].
191 */
192 #define SQLITE_VERSION "3.8.4"
193 #define SQLITE_VERSION_NUMBER 3008004
194 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
195
196 /*
197 ** CAPI3REF: Run-Time Library Version Numbers
198 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
199 **
@@ -6148,11 +6202,12 @@
6202 #define SQLITE_TESTCTRL_ISKEYWORD 16
6203 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6204 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6205 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6206 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6207 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6208 #define SQLITE_TESTCTRL_LAST 21
6209
6210 /*
6211 ** CAPI3REF: SQLite Runtime Status
6212 **
6213 ** ^This interface is used to retrieve runtime status information
@@ -7411,54 +7466,11 @@
7466
7467 #endif /* ifndef _SQLITE3RTREE_H_ */
7468
7469
7470 /************** End of sqlite3.h *********************************************/
7471 /************** Continuing where we left off in sqliteInt.h ******************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7472
7473 /*
7474 ** Include the configuration header output by 'configure' if we're using the
7475 ** autoconf-based build
7476 */
@@ -8841,12 +8853,10 @@
8853 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8854 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
8855 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
8856 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8857 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
 
 
8858
8859 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
8860 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
8861
8862 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
@@ -8982,13 +8992,16 @@
8992 } p4;
8993 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
8994 char *zComment; /* Comment to improve readability */
8995 #endif
8996 #ifdef VDBE_PROFILE
8997 u32 cnt; /* Number of times this instruction was executed */
8998 u64 cycles; /* Total time spent executing this instruction */
8999 #endif
9000 #ifdef SQLITE_VDBE_COVERAGE
9001 int iSrcLine; /* Source-code line that generated this opcode */
9002 #endif
9003 };
9004 typedef struct VdbeOp VdbeOp;
9005
9006
9007 /*
@@ -9094,75 +9107,75 @@
9107 #define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
9108 #define OP_Goto 16
9109 #define OP_Gosub 17
9110 #define OP_Return 18
9111 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9112 #define OP_InitCoroutine 20
9113 #define OP_EndCoroutine 21
9114 #define OP_Yield 22
9115 #define OP_HaltIfNull 23 /* synopsis: if r[P3]=null halt */
9116 #define OP_Halt 24
9117 #define OP_Integer 25 /* synopsis: r[P2]=P1 */
9118 #define OP_Int64 26 /* synopsis: r[P2]=P4 */
9119 #define OP_String 27 /* synopsis: r[P2]='P4' (len=P1) */
9120 #define OP_Null 28 /* synopsis: r[P2..P3]=NULL */
9121 #define OP_SoftNull 29 /* synopsis: r[P1]=NULL */
9122 #define OP_Blob 30 /* synopsis: r[P2]=P4 (len=P1) */
9123 #define OP_Variable 31 /* synopsis: r[P2]=parameter(P1,P4) */
9124 #define OP_Move 32 /* synopsis: r[P2@P3]=r[P1@P3] */
9125 #define OP_Copy 33 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9126 #define OP_SCopy 34 /* synopsis: r[P2]=r[P1] */
9127 #define OP_ResultRow 35 /* synopsis: output=r[P1@P2] */
9128 #define OP_CollSeq 36
9129 #define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
9130 #define OP_MustBeInt 38
9131 #define OP_RealAffinity 39
9132 #define OP_Permutation 40
9133 #define OP_Compare 41
9134 #define OP_Jump 42
9135 #define OP_Once 43
9136 #define OP_If 44
9137 #define OP_IfNot 45
9138 #define OP_Column 46 /* synopsis: r[P3]=PX */
9139 #define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */
9140 #define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9141 #define OP_Count 49 /* synopsis: r[P2]=count() */
9142 #define OP_ReadCookie 50
9143 #define OP_SetCookie 51
9144 #define OP_OpenRead 52 /* synopsis: root=P2 iDb=P3 */
9145 #define OP_OpenWrite 53 /* synopsis: root=P2 iDb=P3 */
9146 #define OP_OpenAutoindex 54 /* synopsis: nColumn=P2 */
9147 #define OP_OpenEphemeral 55 /* synopsis: nColumn=P2 */
9148 #define OP_SorterOpen 56
9149 #define OP_OpenPseudo 57 /* synopsis: P3 columns in r[P2] */
9150 #define OP_Close 58
9151 #define OP_SeekLT 59
9152 #define OP_SeekLE 60
9153 #define OP_SeekGE 61
9154 #define OP_SeekGT 62
9155 #define OP_Seek 63 /* synopsis: intkey=r[P2] */
9156 #define OP_NoConflict 64 /* synopsis: key=r[P3@P4] */
9157 #define OP_NotFound 65 /* synopsis: key=r[P3@P4] */
9158 #define OP_Found 66 /* synopsis: key=r[P3@P4] */
9159 #define OP_NotExists 67 /* synopsis: intkey=r[P3] */
9160 #define OP_Sequence 68 /* synopsis: r[P2]=rowid */
9161 #define OP_NewRowid 69 /* synopsis: r[P2]=rowid */
9162 #define OP_Insert 70 /* synopsis: intkey=r[P3] data=r[P2] */
9163 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9164 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9165 #define OP_InsertInt 73 /* synopsis: intkey=P3 data=r[P2] */
9166 #define OP_Delete 74
9167 #define OP_ResetCount 75
9168 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9169 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9170 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9171 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9172 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9173 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9174 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9175 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9176 #define OP_SorterCompare 84 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9177 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9178 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9179 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9180 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9181 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9169,68 +9182,72 @@
9182 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9183 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9184 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9185 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9186 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9187 #define OP_SorterData 95 /* synopsis: r[P2]=data */
9188 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9189 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9190 #define OP_RowKey 98 /* synopsis: r[P2]=key */
9191 #define OP_RowData 99 /* synopsis: r[P2]=data */
9192 #define OP_Rowid 100 /* synopsis: r[P2]=rowid */
9193 #define OP_NullRow 101
9194 #define OP_Last 102
9195 #define OP_SorterSort 103
9196 #define OP_Sort 104
9197 #define OP_Rewind 105
9198 #define OP_SorterInsert 106
9199 #define OP_IdxInsert 107 /* synopsis: key=r[P2] */
9200 #define OP_IdxDelete 108 /* synopsis: key=r[P2@P3] */
9201 #define OP_IdxRowid 109 /* synopsis: r[P2]=rowid */
9202 #define OP_IdxLE 110 /* synopsis: key=r[P3@P4] */
9203 #define OP_IdxGT 111 /* synopsis: key=r[P3@P4] */
9204 #define OP_IdxLT 112 /* synopsis: key=r[P3@P4] */
9205 #define OP_IdxGE 113 /* synopsis: key=r[P3@P4] */
9206 #define OP_Destroy 114
9207 #define OP_Clear 115
9208 #define OP_CreateIndex 116 /* synopsis: r[P2]=root iDb=P1 */
9209 #define OP_CreateTable 117 /* synopsis: r[P2]=root iDb=P1 */
9210 #define OP_ParseSchema 118
9211 #define OP_LoadAnalysis 119
9212 #define OP_DropTable 120
9213 #define OP_DropIndex 121
9214 #define OP_DropTrigger 122
9215 #define OP_IntegrityCk 123
9216 #define OP_RowSetAdd 124 /* synopsis: rowset(P1)=r[P2] */
9217 #define OP_RowSetRead 125 /* synopsis: r[P3]=rowset(P1) */
9218 #define OP_RowSetTest 126 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9219 #define OP_Program 127
9220 #define OP_Param 128
9221 #define OP_FkCounter 129 /* synopsis: fkctr[P1]+=P2 */
9222 #define OP_FkIfZero 130 /* synopsis: if fkctr[P1]==0 goto P2 */
9223 #define OP_MemMax 131 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9224 #define OP_IfPos 132 /* synopsis: if r[P1]>0 goto P2 */
9225 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9226 #define OP_IfNeg 134 /* synopsis: if r[P1]<0 goto P2 */
9227 #define OP_IfZero 135 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9228 #define OP_AggFinal 136 /* synopsis: accum=r[P1] N=P2 */
9229 #define OP_IncrVacuum 137
9230 #define OP_Expire 138
9231 #define OP_TableLock 139 /* synopsis: iDb=P1 root=P2 write=P3 */
9232 #define OP_VBegin 140
9233 #define OP_VCreate 141
9234 #define OP_VDestroy 142
9235 #define OP_ToText 143 /* same as TK_TO_TEXT */
9236 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9237 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9238 #define OP_ToInt 146 /* same as TK_TO_INT */
9239 #define OP_ToReal 147 /* same as TK_TO_REAL */
9240 #define OP_VOpen 148
9241 #define OP_VColumn 149 /* synopsis: r[P3]=vcolumn(P2) */
9242 #define OP_VNext 150
9243 #define OP_VRename 151
9244 #define OP_Pagecount 152
9245 #define OP_MaxPgcnt 153
9246 #define OP_Init 154 /* synopsis: Start at P2 */
9247 #define OP_Noop 155
9248 #define OP_Explain 156
9249
9250
9251 /* Properties such as "out2" or "jump" that are specified in
9252 ** comments following the "case" for each opcode in the vdbe.c
9253 ** are encoded into bitvectors as follows:
@@ -9243,28 +9260,28 @@
9260 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9261 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9262 #define OPFLG_INITIALIZER {\
9263 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9264 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9265 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9266 /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9267 /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9268 /* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\
9269 /* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\
9270 /* 56 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
9271 /* 64 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c,\
9272 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9273 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9274 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9275 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
9276 /* 104 */ 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01,\
9277 /* 112 */ 0x01, 0x01, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00,\
9278 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45, 0x15, 0x01,\
9279 /* 128 */ 0x02, 0x00, 0x01, 0x08, 0x05, 0x02, 0x05, 0x05,\
9280 /* 136 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,\
9281 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x01, 0x00,\
9282 /* 152 */ 0x02, 0x02, 0x01, 0x00, 0x00,}
9283
9284 /************** End of opcodes.h *********************************************/
9285 /************** Continuing where we left off in vdbe.h ***********************/
9286
9287 /*
@@ -9276,11 +9293,11 @@
9293 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
9294 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
9295 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
9296 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
9297 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
9298 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
9299 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
9300 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
9301 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9302 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9303 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
@@ -9347,10 +9364,45 @@
9364 # define VdbeComment(X)
9365 # define VdbeNoopComment(X)
9366 # define VdbeModuleComment(X)
9367 #endif
9368
9369 /*
9370 ** The VdbeCoverage macros are used to set a coverage testing point
9371 ** for VDBE branch instructions. The coverage testing points are line
9372 ** numbers in the sqlite3.c source file. VDBE branch coverage testing
9373 ** only works with an amalagmation build. That's ok since a VDBE branch
9374 ** coverage build designed for testing the test suite only. No application
9375 ** should ever ship with VDBE branch coverage measuring turned on.
9376 **
9377 ** VdbeCoverage(v) // Mark the previously coded instruction
9378 ** // as a branch
9379 **
9380 ** VdbeCoverageIf(v, conditional) // Mark previous if conditional true
9381 **
9382 ** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken
9383 **
9384 ** VdbeCoverageNeverTaken(v) // Previous branch is never taken
9385 **
9386 ** Every VDBE branch operation must be tagged with one of the macros above.
9387 ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
9388 ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
9389 ** routine in vdbe.c, alerting the developer to the missed tag.
9390 */
9391 #ifdef SQLITE_VDBE_COVERAGE
9392 SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe*,int);
9393 # define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
9394 # define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
9395 # define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2);
9396 # define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1);
9397 #else
9398 # define VdbeCoverage(v)
9399 # define VdbeCoverageIf(v,x)
9400 # define VdbeCoverageAlwaysTaken(v)
9401 # define VdbeCoverageNeverTaken(v)
9402 #endif
9403
9404 #endif
9405
9406 /************** End of vdbe.h ************************************************/
9407 /************** Continuing where we left off in sqliteInt.h ******************/
9408 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -10404,12 +10456,11 @@
10456
10457 /*
10458 ** Return true if it OK to factor constant expressions into the initialization
10459 ** code. The argument is a Parse object for the code generator.
10460 */
10461 #define ConstFactorOk(P) ((P)->okConstFactor)
 
10462
10463 /*
10464 ** Possible values for the sqlite.magic field.
10465 ** The numbers are obtained at random and have no special meaning, other
10466 ** than being distinct from one another.
@@ -10631,14 +10682,20 @@
10682 #define SQLITE_AFF_MASK 0x67
10683
10684 /*
10685 ** Additional bit values that can be ORed with an affinity without
10686 ** changing the affinity.
10687 **
10688 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
10689 ** It causes an assert() to fire if either operand to a comparison
10690 ** operator is NULL. It is added to certain comparison operators to
10691 ** prove that the operands are always NOT NULL.
10692 */
10693 #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
10694 #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
10695 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
10696 #define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */
10697
10698 /*
10699 ** An object of this type is created for each virtual table present in
10700 ** the database schema.
10701 **
@@ -11336,10 +11393,11 @@
11393 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
11394 Table *pTab; /* An SQL table corresponding to zName */
11395 Select *pSelect; /* A SELECT statement used in place of a table name */
11396 int addrFillSub; /* Address of subroutine to manifest a subquery */
11397 int regReturn; /* Register holding return address of addrFillSub */
11398 int regResult; /* Registers holding results of a co-routine */
11399 u8 jointype; /* Type of join between this able and the previous */
11400 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
11401 unsigned isCorrelated :1; /* True if sub-query is correlated */
11402 unsigned viaCoroutine :1; /* Implemented as a co-routine */
11403 unsigned isRecursive :1; /* True for recursive reference in WITH */
@@ -11464,11 +11522,10 @@
11522 ExprList *pGroupBy; /* The GROUP BY clause */
11523 Expr *pHaving; /* The HAVING clause */
11524 ExprList *pOrderBy; /* The ORDER BY clause */
11525 Select *pPrior; /* Prior select in a compound select statement */
11526 Select *pNext; /* Next select to the left in a compound */
 
11527 Expr *pLimit; /* LIMIT expression. NULL means not used. */
11528 Expr *pOffset; /* OFFSET expression. NULL means not used. */
11529 With *pWith; /* WITH clause attached to this select. Or NULL. */
11530 };
11531
@@ -11482,14 +11539,15 @@
11539 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11540 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11541 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11542 #define SF_UseSorter 0x0040 /* Sort using a sorter */
11543 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11544 #define SF_Materialize 0x0100 /* NOT USED */
11545 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11546 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11547 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11548 #define SF_Compound 0x1000 /* Part of a compound query */
11549
11550
11551 /*
11552 ** The results of a SELECT can be distributed in several ways, as defined
11553 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -11664,49 +11722,48 @@
11722 int rc; /* Return code from execution */
11723 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
11724 u8 checkSchema; /* Causes schema cookie check after an error */
11725 u8 nested; /* Number of nested calls to the parser/code generator */
11726 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
 
11727 u8 nColCache; /* Number of entries in aColCache[] */
11728 u8 iColCache; /* Next entry in aColCache[] to replace */
11729 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
11730 u8 mayAbort; /* True if statement may throw an ABORT exception */
11731 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
11732 u8 okConstFactor; /* OK to factor out constants */
11733 int aTempReg[8]; /* Holding area for temporary registers */
11734 int nRangeReg; /* Size of the temporary register block */
11735 int iRangeReg; /* First register in temporary register block */
11736 int nErr; /* Number of errors seen */
11737 int nTab; /* Number of previously allocated VDBE cursors */
11738 int nMem; /* Number of memory cells used so far */
11739 int nSet; /* Number of sets used so far */
11740 int nOnce; /* Number of OP_Once instructions so far */
11741 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
 
 
11742 int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
11743 int ckBase; /* Base register of data during check constraints */
11744 int iPartIdxTab; /* Table corresponding to a partial index */
11745 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11746 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11747 int nLabel; /* Number of labels used */
11748 int *aLabel; /* Space to hold the labels */
11749 struct yColCache {
11750 int iTable; /* Table cursor number */
11751 i16 iColumn; /* Table column number */
11752 u8 tempReg; /* iReg is a temp register that needs to be freed */
11753 int iLevel; /* Nesting level */
11754 int iReg; /* Reg with value of this column. 0 means none. */
11755 int lru; /* Least recently used entry has the smallest value */
11756 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11757 ExprList *pConstExpr;/* Constant expressions */
11758 Token constraintName;/* Name of the constraint currently being parsed */
11759 yDbMask writeMask; /* Start a write transaction on these databases */
11760 yDbMask cookieMask; /* Bitmask of schema verified databases */
 
11761 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11762 int regRowid; /* Register holding rowid of CREATE TABLE entry */
11763 int regRoot; /* Register holding root page number for new objects */
11764 int nMaxArg; /* Max args passed to user function by sub-program */
 
11765 #ifndef SQLITE_OMIT_SHARED_CACHE
11766 int nTableLock; /* Number of locks in aTableLock */
11767 TableLock *aTableLock; /* Required table locks for shared-cache mode */
11768 #endif
11769 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -11721,16 +11778,21 @@
11778 u32 newmask; /* Mask of new.* columns referenced */
11779 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
11780 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
11781 u8 disableTriggers; /* True to disable triggers */
11782
11783 /************************************************************************
11784 ** Above is constant between recursions. Below is reset before and after
11785 ** each recursion. The boundary between these two regions is determined
11786 ** using offsetof(Parse,nVar) so the nVar field must be the first field
11787 ** in the recursive region.
11788 ************************************************************************/
11789
11790 int nVar; /* Number of '?' variables seen in the SQL so far */
11791 int nzVar; /* Number of available slots in azVar[] */
11792 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
11793 u8 bFreeWith; /* True if pWith should be freed with parser */
11794 u8 explain; /* True if the EXPLAIN flag is found on the query */
11795 #ifndef SQLITE_OMIT_VIRTUALTABLE
11796 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
11797 int nVtabLock; /* Number of virtual tables to lock */
11798 #endif
@@ -11753,11 +11815,10 @@
11815 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11816 #endif
11817 Table *pZombieTab; /* List of Table objects to delete after code gen */
11818 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11819 With *pWith; /* Current WITH clause, or NULL */
 
11820 };
11821
11822 /*
11823 ** Return true if currently inside an sqlite3_declare_vtab() call.
11824 */
@@ -11969,10 +12030,17 @@
12030 int bLocaltimeFault; /* True to fail localtime() calls */
12031 #ifdef SQLITE_ENABLE_SQLLOG
12032 void(*xSqllog)(void*,sqlite3*,const char*, int);
12033 void *pSqllogArg;
12034 #endif
12035 #ifdef SQLITE_VDBE_COVERAGE
12036 /* The following callback (if not NULL) is invoked on every VDBE branch
12037 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
12038 */
12039 void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
12040 void *pVdbeBranchArg; /* 1st argument */
12041 #endif
12042 };
12043
12044 /*
12045 ** This macro is used inside of assert() statements to indicate that
12046 ** the assert is only valid on a well-formed database. Instead of:
@@ -12302,11 +12370,10 @@
12370 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
12371 #else
12372 # define sqlite3AutoincrementBegin(X)
12373 # define sqlite3AutoincrementEnd(X)
12374 #endif
 
12375 SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int);
12376 SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
12377 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
12378 SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
12379 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -12350,15 +12417,16 @@
12417 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
12418 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12419 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12420 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12421 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12422 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
12423 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
12424 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
12425 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12426 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12427 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12428 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
12429 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
12430 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
12431 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12432 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
@@ -12392,11 +12460,10 @@
12460 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12461 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12462 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
12463 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12464 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
 
12465 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12466 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12467 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
12468 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12469 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
@@ -12536,11 +12603,11 @@
12603 #define getVarint sqlite3GetVarint
12604 #define putVarint sqlite3PutVarint
12605
12606
12607 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
12608 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
12609 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
12610 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
12611 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
12612 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
12613 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
@@ -13640,11 +13707,10 @@
13707 u8 rowidIsValid; /* True if lastRowid is valid */
13708 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13709 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13710 Bool isTable:1; /* True if a table requiring integer keys */
13711 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
 
13712 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13713 i64 seqCount; /* Sequence counter */
13714 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13715 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13716 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -13734,11 +13800,11 @@
13800 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
13801 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
13802 } u;
13803 int n; /* Number of characters in string value, excluding '\0' */
13804 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
13805 u8 memType; /* Lower 5 bits of flags */
13806 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
13807 #ifdef SQLITE_DEBUG
13808 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
13809 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
13810 #endif
@@ -13763,11 +13829,11 @@
13829 #define MEM_Int 0x0004 /* Value is an integer */
13830 #define MEM_Real 0x0008 /* Value is a real number */
13831 #define MEM_Blob 0x0010 /* Value is a BLOB */
13832 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
13833 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
13834 #define MEM_Undefined 0x0080 /* Value is undefined */
13835 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
13836 #define MEM_TypeMask 0x01ff /* Mask of type bits */
13837
13838
13839 /* Whenever Mem contains a valid string or blob representation, one of
@@ -13795,11 +13861,11 @@
13861 /*
13862 ** Return true if a memory cell is not marked as invalid. This macro
13863 ** is for use inside assert() statements only.
13864 */
13865 #ifdef SQLITE_DEBUG
13866 #define memIsValid(M) ((M)->flags & MEM_Undefined)==0
13867 #endif
13868
13869 /*
13870 ** Each auxilliary data pointer stored by a user defined function
13871 ** implementation calling sqlite3_set_auxdata() is stored in an instance
@@ -13990,20 +14056,22 @@
14056 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
14057 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
14058 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
14059 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
14060 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
14061 #define VdbeMemDynamic(X) \
14062 (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
14063 #define VdbeMemRelease(X) \
14064 if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X);
 
14065 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
14066 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
14067 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
14068 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
14069 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
14070 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14071 #define sqlite3VdbeMemStoreType(X) (X)->memType = (u8)((X)->flags&0x1f)
14072 /* void sqlite3VdbeMemStoreType(Mem *pMem); */
14073 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
14074
14075 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
14076 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
14077 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
@@ -17767,10 +17835,16 @@
17835 mem5.totalExcess += iFullSz - nByte;
17836 mem5.currentCount++;
17837 mem5.currentOut += iFullSz;
17838 if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
17839 if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
17840
17841 #ifdef SQLITE_DEBUG
17842 /* Make sure the allocated memory does not assume that it is set to zero
17843 ** or retains a value from a previous allocation */
17844 memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz);
17845 #endif
17846
17847 /* Return a pointer to the allocated memory. */
17848 return (void*)&mem5.zPool[i*mem5.szAtom];
17849 }
17850
@@ -17825,10 +17899,17 @@
17899 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
17900 mem5.aCtrl[iBuddy] = 0;
17901 }
17902 size *= 2;
17903 }
17904
17905 #ifdef SQLITE_DEBUG
17906 /* Overwrite freed memory with the 0x55 bit pattern to verify that it is
17907 ** not used after being freed */
17908 memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size);
17909 #endif
17910
17911 memsys5Link(iBlock, iLogsize);
17912 }
17913
17914 /*
17915 ** Allocate nBytes of memory.
@@ -22728,17 +22809,16 @@
22809 testcase( iB==-1 ); testcase( iB==0 );
22810 if( iB>=0 ){
22811 testcase( iA>0 && LARGEST_INT64 - iA == iB );
22812 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
22813 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
 
22814 }else{
22815 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
22816 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
22817 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
 
22818 }
22819 *pA += iB;
22820 return 0;
22821 }
22822 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
22823 testcase( iB==SMALLEST_INT64+1 );
22824 if( iB==SMALLEST_INT64 ){
@@ -22758,13 +22838,22 @@
22838
22839 iA1 = iA/TWOPOWER32;
22840 iA0 = iA % TWOPOWER32;
22841 iB1 = iB/TWOPOWER32;
22842 iB0 = iB % TWOPOWER32;
22843 if( iA1==0 ){
22844 if( iB1==0 ){
22845 *pA *= iB;
22846 return 0;
22847 }
22848 r = iA0*iB1;
22849 }else if( iB1==0 ){
22850 r = iA1*iB0;
22851 }else{
22852 /* If both iA1 and iB1 are non-zero, overflow will result */
22853 return 1;
22854 }
22855 testcase( r==(-TWOPOWER31)-1 );
22856 testcase( r==(-TWOPOWER31) );
22857 testcase( r==TWOPOWER31 );
22858 testcase( r==TWOPOWER31-1 );
22859 if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
@@ -23206,75 +23295,75 @@
23295 /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
23296 /* 16 */ "Goto" OpHelp(""),
23297 /* 17 */ "Gosub" OpHelp(""),
23298 /* 18 */ "Return" OpHelp(""),
23299 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
23300 /* 20 */ "InitCoroutine" OpHelp(""),
23301 /* 21 */ "EndCoroutine" OpHelp(""),
23302 /* 22 */ "Yield" OpHelp(""),
23303 /* 23 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
23304 /* 24 */ "Halt" OpHelp(""),
23305 /* 25 */ "Integer" OpHelp("r[P2]=P1"),
23306 /* 26 */ "Int64" OpHelp("r[P2]=P4"),
23307 /* 27 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23308 /* 28 */ "Null" OpHelp("r[P2..P3]=NULL"),
23309 /* 29 */ "SoftNull" OpHelp("r[P1]=NULL"),
23310 /* 30 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23311 /* 31 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23312 /* 32 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23313 /* 33 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23314 /* 34 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23315 /* 35 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23316 /* 36 */ "CollSeq" OpHelp(""),
23317 /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23318 /* 38 */ "MustBeInt" OpHelp(""),
23319 /* 39 */ "RealAffinity" OpHelp(""),
23320 /* 40 */ "Permutation" OpHelp(""),
23321 /* 41 */ "Compare" OpHelp(""),
23322 /* 42 */ "Jump" OpHelp(""),
23323 /* 43 */ "Once" OpHelp(""),
23324 /* 44 */ "If" OpHelp(""),
23325 /* 45 */ "IfNot" OpHelp(""),
23326 /* 46 */ "Column" OpHelp("r[P3]=PX"),
23327 /* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23328 /* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23329 /* 49 */ "Count" OpHelp("r[P2]=count()"),
23330 /* 50 */ "ReadCookie" OpHelp(""),
23331 /* 51 */ "SetCookie" OpHelp(""),
23332 /* 52 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23333 /* 53 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23334 /* 54 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23335 /* 55 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23336 /* 56 */ "SorterOpen" OpHelp(""),
23337 /* 57 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23338 /* 58 */ "Close" OpHelp(""),
23339 /* 59 */ "SeekLT" OpHelp(""),
23340 /* 60 */ "SeekLE" OpHelp(""),
23341 /* 61 */ "SeekGE" OpHelp(""),
23342 /* 62 */ "SeekGT" OpHelp(""),
23343 /* 63 */ "Seek" OpHelp("intkey=r[P2]"),
23344 /* 64 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23345 /* 65 */ "NotFound" OpHelp("key=r[P3@P4]"),
23346 /* 66 */ "Found" OpHelp("key=r[P3@P4]"),
23347 /* 67 */ "NotExists" OpHelp("intkey=r[P3]"),
23348 /* 68 */ "Sequence" OpHelp("r[P2]=rowid"),
23349 /* 69 */ "NewRowid" OpHelp("r[P2]=rowid"),
23350 /* 70 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23351 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23352 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23353 /* 73 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23354 /* 74 */ "Delete" OpHelp(""),
23355 /* 75 */ "ResetCount" OpHelp(""),
23356 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23357 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23358 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23359 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23360 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23361 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23362 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23363 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23364 /* 84 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23365 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23366 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23367 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23368 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23369 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23281,68 +23370,72 @@
23370 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23371 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23372 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23373 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23374 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23375 /* 95 */ "SorterData" OpHelp("r[P2]=data"),
23376 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23377 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23378 /* 98 */ "RowKey" OpHelp("r[P2]=key"),
23379 /* 99 */ "RowData" OpHelp("r[P2]=data"),
23380 /* 100 */ "Rowid" OpHelp("r[P2]=rowid"),
23381 /* 101 */ "NullRow" OpHelp(""),
23382 /* 102 */ "Last" OpHelp(""),
23383 /* 103 */ "SorterSort" OpHelp(""),
23384 /* 104 */ "Sort" OpHelp(""),
23385 /* 105 */ "Rewind" OpHelp(""),
23386 /* 106 */ "SorterInsert" OpHelp(""),
23387 /* 107 */ "IdxInsert" OpHelp("key=r[P2]"),
23388 /* 108 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23389 /* 109 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23390 /* 110 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23391 /* 111 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23392 /* 112 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23393 /* 113 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23394 /* 114 */ "Destroy" OpHelp(""),
23395 /* 115 */ "Clear" OpHelp(""),
23396 /* 116 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23397 /* 117 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23398 /* 118 */ "ParseSchema" OpHelp(""),
23399 /* 119 */ "LoadAnalysis" OpHelp(""),
23400 /* 120 */ "DropTable" OpHelp(""),
23401 /* 121 */ "DropIndex" OpHelp(""),
23402 /* 122 */ "DropTrigger" OpHelp(""),
23403 /* 123 */ "IntegrityCk" OpHelp(""),
23404 /* 124 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23405 /* 125 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23406 /* 126 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23407 /* 127 */ "Program" OpHelp(""),
23408 /* 128 */ "Param" OpHelp(""),
23409 /* 129 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23410 /* 130 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23411 /* 131 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23412 /* 132 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23413 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23414 /* 134 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23415 /* 135 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23416 /* 136 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23417 /* 137 */ "IncrVacuum" OpHelp(""),
23418 /* 138 */ "Expire" OpHelp(""),
23419 /* 139 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23420 /* 140 */ "VBegin" OpHelp(""),
23421 /* 141 */ "VCreate" OpHelp(""),
23422 /* 142 */ "VDestroy" OpHelp(""),
23423 /* 143 */ "ToText" OpHelp(""),
23424 /* 144 */ "ToBlob" OpHelp(""),
23425 /* 145 */ "ToNumeric" OpHelp(""),
23426 /* 146 */ "ToInt" OpHelp(""),
23427 /* 147 */ "ToReal" OpHelp(""),
23428 /* 148 */ "VOpen" OpHelp(""),
23429 /* 149 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23430 /* 150 */ "VNext" OpHelp(""),
23431 /* 151 */ "VRename" OpHelp(""),
23432 /* 152 */ "Pagecount" OpHelp(""),
23433 /* 153 */ "MaxPgcnt" OpHelp(""),
23434 /* 154 */ "Init" OpHelp("Start at P2"),
23435 /* 155 */ "Noop" OpHelp(""),
23436 /* 156 */ "Explain" OpHelp(""),
23437 };
23438 return azName[i];
23439 }
23440 #endif
23441
@@ -23430,36 +23523,10 @@
23523 # else
23524 # define OS_VXWORKS 0
23525 # endif
23526 #endif
23527
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23528 /*
23529 ** standard include files.
23530 */
23531 #include <sys/types.h>
23532 #include <sys/stat.h>
@@ -34444,11 +34511,11 @@
34511 ** Windows will only let you create file view mappings
34512 ** on allocation size granularity boundaries.
34513 ** During sqlite3_os_init() we do a GetSystemInfo()
34514 ** to get the granularity size.
34515 */
34516 static SYSTEM_INFO winSysInfo;
34517
34518 #ifndef SQLITE_OMIT_WAL
34519
34520 /*
34521 ** Helper functions to obtain and relinquish the global mutex. The
@@ -36378,19 +36445,16 @@
36445 #ifndef SQLITE_OMIT_LOAD_EXTENSION
36446 /*
36447 ** Interfaces for opening a shared library, finding entry points
36448 ** within the shared library, and closing the shared library.
36449 */
 
 
 
 
36450 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
36451 HANDLE h;
36452 void *zConverted = winConvertFromUtf8Filename(zFilename);
36453 UNUSED_PARAMETER(pVfs);
36454 if( zConverted==0 ){
36455 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
36456 return 0;
36457 }
36458 if( osIsNT() ){
36459 #if SQLITE_OS_WINRT
36460 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
@@ -36401,24 +36465,30 @@
36465 #ifdef SQLITE_WIN32_HAS_ANSI
36466 else{
36467 h = osLoadLibraryA((char*)zConverted);
36468 }
36469 #endif
36470 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
36471 sqlite3_free(zConverted);
36472 return (void*)h;
36473 }
36474 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
36475 UNUSED_PARAMETER(pVfs);
36476 winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
36477 }
36478 static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
36479 FARPROC proc;
36480 UNUSED_PARAMETER(pVfs);
36481 proc = osGetProcAddressA((HANDLE)pH, zSym);
36482 OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n",
36483 (void*)pH, zSym, (void*)proc));
36484 return (void(*)(void))proc;
36485 }
36486 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
36487 UNUSED_PARAMETER(pVfs);
36488 osFreeLibrary((HANDLE)pHandle);
36489 OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
36490 }
36491 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
36492 #define winDlOpen 0
36493 #define winDlError 0
36494 #define winDlSym 0
@@ -37110,11 +37180,12 @@
37180 PgHdr *pSynced; /* Last synced page in dirty page list */
37181 int nRef; /* Number of referenced pages */
37182 int szCache; /* Configured cache size */
37183 int szPage; /* Size of every page in this cache */
37184 int szExtra; /* Size of extra space for each page */
37185 u8 bPurgeable; /* True if pages are on backing store */
37186 u8 eCreate; /* eCreate value for for xFetch() */
37187 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
37188 void *pStress; /* Argument to xStress */
37189 sqlite3_pcache *pCache; /* Pluggable cache module */
37190 PgHdr *pPage1; /* Reference to page 1 */
37191 };
@@ -37177,10 +37248,14 @@
37248 if( pPage->pDirtyPrev ){
37249 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
37250 }else{
37251 assert( pPage==p->pDirty );
37252 p->pDirty = pPage->pDirtyNext;
37253 if( p->pDirty==0 && p->bPurgeable ){
37254 assert( p->eCreate==1 );
37255 p->eCreate = 2;
37256 }
37257 }
37258 pPage->pDirtyNext = 0;
37259 pPage->pDirtyPrev = 0;
37260
37261 expensive_assert( pcacheCheckSynced(p) );
@@ -37197,10 +37272,13 @@
37272
37273 pPage->pDirtyNext = p->pDirty;
37274 if( pPage->pDirtyNext ){
37275 assert( pPage->pDirtyNext->pDirtyPrev==0 );
37276 pPage->pDirtyNext->pDirtyPrev = pPage;
37277 }else if( p->bPurgeable ){
37278 assert( p->eCreate==2 );
37279 p->eCreate = 1;
37280 }
37281 p->pDirty = pPage;
37282 if( !p->pDirtyTail ){
37283 p->pDirtyTail = pPage;
37284 }
@@ -37266,10 +37344,11 @@
37344 ){
37345 memset(p, 0, sizeof(PCache));
37346 p->szPage = szPage;
37347 p->szExtra = szExtra;
37348 p->bPurgeable = bPurgeable;
37349 p->eCreate = 2;
37350 p->xStress = xStress;
37351 p->pStress = pStress;
37352 p->szCache = 100;
37353 }
37354
@@ -37305,11 +37384,11 @@
37384 PCache *pCache, /* Obtain the page from this cache */
37385 Pgno pgno, /* Page number to obtain */
37386 int createFlag, /* If true, create page if it does not exist already */
37387 PgHdr **ppPage /* Write the page here */
37388 ){
37389 sqlite3_pcache_page *pPage;
37390 PgHdr *pPgHdr = 0;
37391 int eCreate;
37392
37393 assert( pCache!=0 );
37394 assert( createFlag==1 || createFlag==0 );
@@ -37316,12 +37395,16 @@
37395 assert( pgno>0 );
37396
37397 /* If the pluggable cache (sqlite3_pcache*) has not been allocated,
37398 ** allocate it now.
37399 */
37400 if( !pCache->pCache ){
37401 sqlite3_pcache *p;
37402 if( !createFlag ){
37403 *ppPage = 0;
37404 return SQLITE_OK;
37405 }
37406 p = sqlite3GlobalConfig.pcache2.xCreate(
37407 pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
37408 );
37409 if( !p ){
37410 return SQLITE_NOMEM;
@@ -37328,15 +37411,20 @@
37411 }
37412 sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
37413 pCache->pCache = p;
37414 }
37415
37416 /* eCreate defines what to do if the page does not exist.
37417 ** 0 Do not allocate a new page. (createFlag==0)
37418 ** 1 Allocate a new page if doing so is inexpensive.
37419 ** (createFlag==1 AND bPurgeable AND pDirty)
37420 ** 2 Allocate a new page even it doing so is difficult.
37421 ** (createFlag==1 AND !(bPurgeable AND pDirty)
37422 */
37423 eCreate = createFlag==0 ? 0 : pCache->eCreate;
37424 assert( (createFlag*(1+(!pCache->bPurgeable||!pCache->pDirty)))==eCreate );
37425 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
37426 if( !pPage && eCreate==1 ){
37427 PgHdr *pPg;
37428
37429 /* Find a dirty page to write-out and recycle. First try to find a
37430 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
@@ -47920,11 +48008,11 @@
48008 if( rc!=SQLITE_OK ){
48009 walIndexClose(pRet, 0);
48010 sqlite3OsClose(pRet->pWalFd);
48011 sqlite3_free(pRet);
48012 }else{
48013 int iDC = sqlite3OsDeviceCharacteristics(pDbFd);
48014 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
48015 if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
48016 pRet->padToSectorBoundary = 0;
48017 }
48018 *ppWal = pRet;
@@ -49291,11 +49379,11 @@
49379 if( rc ) return rc;
49380 iOffset += iFirstAmt;
49381 iAmt -= iFirstAmt;
49382 pContent = (void*)(iFirstAmt + (char*)pContent);
49383 assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
49384 rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK);
49385 if( iAmt==0 || rc ) return rc;
49386 }
49387 rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
49388 return rc;
49389 }
@@ -50229,11 +50317,10 @@
50317 struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
50318 #ifndef SQLITE_OMIT_INCRBLOB
50319 Pgno *aOverflow; /* Cache of overflow page locations */
50320 #endif
50321 Pgno pgnoRoot; /* The root page of this tree */
 
50322 CellInfo info; /* A parse of the cell we are pointing at */
50323 i64 nKey; /* Size of pKey, or last integer key */
50324 void *pKey; /* Saved key that was cursor's last known position */
50325 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
50326 u8 wrFlag; /* True if writable */
@@ -52213,17 +52300,16 @@
52300 assert( sqlite3_mutex_held(pBt->mutex) );
52301 if( pBt->btsFlags & BTS_SECURE_DELETE ){
52302 memset(&data[hdr], 0, pBt->usableSize - hdr);
52303 }
52304 data[hdr] = (char)flags;
52305 first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
52306 memset(&data[hdr+1], 0, 4);
52307 data[hdr+7] = 0;
52308 put2byte(&data[hdr+5], pBt->usableSize);
52309 pPage->nFree = (u16)(pBt->usableSize - first);
52310 decodeFlags(pPage, flags);
 
52311 pPage->cellOffset = first;
52312 pPage->aDataEnd = &data[pBt->usableSize];
52313 pPage->aCellIdx = &data[first];
52314 pPage->nOverflow = 0;
52315 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
@@ -54303,11 +54389,10 @@
54389 if( pCur->pNext ){
54390 pCur->pNext->pPrev = pCur;
54391 }
54392 pBt->pCursor = pCur;
54393 pCur->eState = CURSOR_INVALID;
 
54394 return SQLITE_OK;
54395 }
54396 SQLITE_PRIVATE int sqlite3BtreeCursor(
54397 Btree *p, /* The btree */
54398 int iTable, /* Root page of table to open */
@@ -54344,40 +54429,10 @@
54429 */
54430 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){
54431 memset(p, 0, offsetof(BtCursor, iPage));
54432 }
54433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54434 /*
54435 ** Close a cursor. The read lock on the database file is released
54436 ** when the last cursor is closed.
54437 */
54438 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
@@ -55448,18 +55503,28 @@
55503 /*
55504 ** Advance the cursor to the next entry in the database. If
55505 ** successful then set *pRes=0. If the cursor
55506 ** was already pointing to the last entry in the database before
55507 ** this routine was called, then set *pRes=1.
55508 **
55509 ** The calling function will set *pRes to 0 or 1. The initial *pRes value
55510 ** will be 1 if the cursor being stepped corresponds to an SQL index and
55511 ** if this routine could have been skipped if that SQL index had been
55512 ** a unique index. Otherwise the caller will have set *pRes to zero.
55513 ** Zero is the common case. The btree implementation is free to use the
55514 ** initial *pRes value as a hint to improve performance, but the current
55515 ** SQLite btree implementation does not. (Note that the comdb2 btree
55516 ** implementation does use this hint, however.)
55517 */
55518 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
55519 int rc;
55520 int idx;
55521 MemPage *pPage;
55522
55523 assert( cursorHoldsMutex(pCur) );
55524 assert( pRes!=0 );
55525 assert( *pRes==0 || *pRes==1 );
55526 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55527 if( pCur->eState!=CURSOR_VALID ){
55528 rc = restoreCursorPosition(pCur);
55529 if( rc!=SQLITE_OK ){
55530 *pRes = 0;
@@ -55534,17 +55599,27 @@
55599 /*
55600 ** Step the cursor to the back to the previous entry in the database. If
55601 ** successful then set *pRes=0. If the cursor
55602 ** was already pointing to the first entry in the database before
55603 ** this routine was called, then set *pRes=1.
55604 **
55605 ** The calling function will set *pRes to 0 or 1. The initial *pRes value
55606 ** will be 1 if the cursor being stepped corresponds to an SQL index and
55607 ** if this routine could have been skipped if that SQL index had been
55608 ** a unique index. Otherwise the caller will have set *pRes to zero.
55609 ** Zero is the common case. The btree implementation is free to use the
55610 ** initial *pRes value as a hint to improve performance, but the current
55611 ** SQLite btree implementation does not. (Note that the comdb2 btree
55612 ** implementation does use this hint, however.)
55613 */
55614 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
55615 int rc;
55616 MemPage *pPage;
55617
55618 assert( cursorHoldsMutex(pCur) );
55619 assert( pRes!=0 );
55620 assert( *pRes==0 || *pRes==1 );
55621 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55622 pCur->atLast = 0;
55623 if( pCur->eState!=CURSOR_VALID ){
55624 if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){
55625 rc = btreeRestoreCursorPosition(pCur);
@@ -57637,15 +57712,21 @@
57712 ** not to clear the cursor here.
57713 */
57714 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
57715 if( rc ) return rc;
57716
 
 
 
57717 if( pCur->pKeyInfo==0 ){
57718 /* If this is an insert into a table b-tree, invalidate any incrblob
57719 ** cursors open on the row being replaced */
57720 invalidateIncrblobCursors(p, nKey, 0);
57721
57722 /* If the cursor is currently on the last row and we are appending a
57723 ** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
57724 ** call */
57725 if( pCur->validNKey && nKey>0 && pCur->info.nKey==nKey-1 ){
57726 loc = -1;
57727 }
57728 }
57729
57730 if( !loc ){
57731 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
57732 if( rc ) return rc;
@@ -57711,12 +57792,12 @@
57792 ** entry in the table, and the next row inserted has an integer key
57793 ** larger than the largest existing key, it is possible to insert the
57794 ** row without seeking the cursor. This can be a big performance boost.
57795 */
57796 pCur->info.nSize = 0;
 
57797 if( rc==SQLITE_OK && pPage->nOverflow ){
57798 pCur->validNKey = 0;
57799 rc = balance(pCur);
57800
57801 /* Must make sure nOverflow is reset to zero even if the balance()
57802 ** fails. Internal data structure corruption will result otherwise.
57803 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
@@ -57767,11 +57848,11 @@
57848 ** from the internal node. The 'previous' entry is used for this instead
57849 ** of the 'next' entry, as the previous entry is always a part of the
57850 ** sub-tree headed by the child page of the cell being deleted. This makes
57851 ** balancing the tree following the delete operation easier. */
57852 if( !pPage->leaf ){
57853 int notUsed = 0;
57854 rc = sqlite3BtreePrevious(pCur, &notUsed);
57855 if( rc ) return rc;
57856 }
57857
57858 /* Save the positions of any other cursors open on this table before
@@ -60192,11 +60273,11 @@
60273 }
60274
60275 /*
60276 ** Release any memory held by the Mem. This may leave the Mem in an
60277 ** inconsistent state, for example with (Mem.z==0) and
60278 ** (Mem.memType==MEM_Str).
60279 */
60280 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60281 VdbeMemRelease(p);
60282 if( p->zMalloc ){
60283 sqlite3DbFree(p->db, p->zMalloc);
@@ -60383,11 +60464,11 @@
60464 }
60465 if( pMem->flags & MEM_RowSet ){
60466 sqlite3RowSetClear(pMem->u.pRowSet);
60467 }
60468 MemSetTypeFlag(pMem, MEM_Null);
60469 pMem->memType = MEM_Null;
60470 }
60471 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60472 sqlite3VdbeMemSetNull((Mem*)p);
60473 }
60474
@@ -60396,11 +60477,11 @@
60477 ** n containing all zeros.
60478 */
60479 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
60480 sqlite3VdbeMemRelease(pMem);
60481 pMem->flags = MEM_Blob|MEM_Zero;
60482 pMem->memType = MEM_Blob;
60483 pMem->n = 0;
60484 if( n<0 ) n = 0;
60485 pMem->u.nZero = n;
60486 pMem->enc = SQLITE_UTF8;
60487
@@ -60419,11 +60500,11 @@
60500 */
60501 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
60502 sqlite3VdbeMemRelease(pMem);
60503 pMem->u.i = val;
60504 pMem->flags = MEM_Int;
60505 pMem->memType = MEM_Int;
60506 }
60507
60508 #ifndef SQLITE_OMIT_FLOATING_POINT
60509 /*
60510 ** Delete any previous value and set the value stored in *pMem to val,
@@ -60434,11 +60515,11 @@
60515 sqlite3VdbeMemSetNull(pMem);
60516 }else{
60517 sqlite3VdbeMemRelease(pMem);
60518 pMem->r = val;
60519 pMem->flags = MEM_Real;
60520 pMem->memType = MEM_Real;
60521 }
60522 }
60523 #endif
60524
60525 /*
@@ -60490,11 +60571,11 @@
60571 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
60572 int i;
60573 Mem *pX;
60574 for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
60575 if( pX->pScopyFrom==pMem ){
60576 pX->flags |= MEM_Undefined;
60577 pX->pScopyFrom = 0;
60578 }
60579 }
60580 pMem->pScopyFrom = 0;
60581 }
@@ -60642,11 +60723,11 @@
60723 }
60724
60725 pMem->n = nByte;
60726 pMem->flags = flags;
60727 pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
60728 pMem->memType = flags&0x1f;
60729
60730 #ifndef SQLITE_OMIT_UTF16
60731 if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
60732 return SQLITE_NOMEM;
60733 }
@@ -60813,11 +60894,11 @@
60894 pMem->z = &zData[offset];
60895 pMem->flags = MEM_Blob|MEM_Ephem;
60896 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60897 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60898 pMem->enc = 0;
60899 pMem->memType = MEM_Blob;
60900 if( key ){
60901 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60902 }else{
60903 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
60904 }
@@ -60883,11 +60964,11 @@
60964 */
60965 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
60966 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
60967 if( p ){
60968 p->flags = MEM_Null;
60969 p->memType = MEM_Null;
60970 p->db = db;
60971 }
60972 return p;
60973 }
60974
@@ -60933,11 +61014,11 @@
61014 assert( pRec->pKeyInfo->enc==ENC(db) );
61015 pRec->flags = UNPACKED_PREFIX_MATCH;
61016 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
61017 for(i=0; i<nCol; i++){
61018 pRec->aMem[i].flags = MEM_Null;
61019 pRec->aMem[i].memType = MEM_Null;
61020 pRec->aMem[i].db = db;
61021 }
61022 }else{
61023 sqlite3DbFree(db, pRec);
61024 pRec = 0;
@@ -61006,11 +61087,11 @@
61087 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
61088 }else{
61089 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
61090 if( zVal==0 ) goto no_mem;
61091 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
61092 if( op==TK_FLOAT ) pVal->memType = MEM_Real;
61093 }
61094 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
61095 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
61096 }else{
61097 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
@@ -61464,10 +61545,13 @@
61545 #endif
61546 #ifdef VDBE_PROFILE
61547 pOp->cycles = 0;
61548 pOp->cnt = 0;
61549 #endif
61550 #ifdef SQLITE_VDBE_COVERAGE
61551 pOp->iSrcLine = 0;
61552 #endif
61553 return i;
61554 }
61555 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *p, int op){
61556 return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
61557 }
@@ -61825,11 +61909,11 @@
61909
61910 /*
61911 ** Add a whole list of operations to the operation stack. Return the
61912 ** address of the first operation added.
61913 */
61914 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
61915 int addr;
61916 assert( p->magic==VDBE_MAGIC_INIT );
61917 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
61918 return 0;
61919 }
@@ -61852,10 +61936,15 @@
61936 pOut->p4type = P4_NOTUSED;
61937 pOut->p4.p = 0;
61938 pOut->p5 = 0;
61939 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61940 pOut->zComment = 0;
61941 #endif
61942 #ifdef SQLITE_VDBE_COVERAGE
61943 pOut->iSrcLine = iLineno+i;
61944 #else
61945 (void)iLineno;
61946 #endif
61947 #ifdef SQLITE_DEBUG
61948 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61949 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
61950 }
@@ -62141,10 +62230,19 @@
62230 va_end(ap);
62231 }
62232 }
62233 #endif /* NDEBUG */
62234
62235 #ifdef SQLITE_VDBE_COVERAGE
62236 /*
62237 ** Set the value if the iSrcLine field for the previously coded instruction.
62238 */
62239 SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
62240 sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine;
62241 }
62242 #endif /* SQLITE_VDBE_COVERAGE */
62243
62244 /*
62245 ** Return the opcode for a given address. If the address is -1, then
62246 ** return the most recently inserted opcode.
62247 **
62248 ** If a memory allocation error has occurred prior to the calling of this
@@ -62153,28 +62251,17 @@
62251 ** The return of a dummy opcode allows the call to continue functioning
62252 ** after a OOM fault without having to check to see if the return from
62253 ** this routine is a valid pointer. But because the dummy.opcode is 0,
62254 ** dummy will never be written to. This is verified by code inspection and
62255 ** by running with Valgrind.
 
 
 
 
 
 
 
 
62256 */
62257 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
62258 /* C89 specifies that the constant "dummy" will be initialized to all
62259 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
62260 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
62261 assert( p->magic==VDBE_MAGIC_INIT );
62262 if( addr<0 ){
 
 
 
62263 addr = p->nOp - 1;
62264 }
62265 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
62266 if( p->db->mallocFailed ){
62267 return (VdbeOp*)&dummy;
@@ -62475,11 +62562,11 @@
62562 if( pOut==0 ) pOut = stdout;
62563 zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
62564 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62565 displayComment(pOp, zP4, zCom, sizeof(zCom));
62566 #else
62567 zCom[0] = 0;
62568 #endif
62569 /* NB: The sqlite3OpcodeName() function is implemented by code created
62570 ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
62571 ** information from the vdbe.c source text */
62572 fprintf(pOut, zFormat1, pc,
@@ -62524,11 +62611,11 @@
62611 }else if( p->zMalloc ){
62612 sqlite3DbFree(db, p->zMalloc);
62613 p->zMalloc = 0;
62614 }
62615
62616 p->flags = MEM_Undefined;
62617 }
62618 db->mallocFailed = malloc_failed;
62619 }
62620 }
62621
@@ -62646,19 +62733,19 @@
62733 }
62734 pOp = &apSub[j]->aOp[i];
62735 }
62736 if( p->explain==1 ){
62737 pMem->flags = MEM_Int;
62738 pMem->memType = MEM_Int;
62739 pMem->u.i = i; /* Program counter */
62740 pMem++;
62741
62742 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
62743 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
62744 assert( pMem->z!=0 );
62745 pMem->n = sqlite3Strlen30(pMem->z);
62746 pMem->memType = MEM_Str;
62747 pMem->enc = SQLITE_UTF8;
62748 pMem++;
62749
62750 /* When an OP_Program opcode is encounter (the only opcode that has
62751 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
@@ -62680,21 +62767,21 @@
62767 }
62768 }
62769
62770 pMem->flags = MEM_Int;
62771 pMem->u.i = pOp->p1; /* P1 */
62772 pMem->memType = MEM_Int;
62773 pMem++;
62774
62775 pMem->flags = MEM_Int;
62776 pMem->u.i = pOp->p2; /* P2 */
62777 pMem->memType = MEM_Int;
62778 pMem++;
62779
62780 pMem->flags = MEM_Int;
62781 pMem->u.i = pOp->p3; /* P3 */
62782 pMem->memType = MEM_Int;
62783 pMem++;
62784
62785 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62786 assert( p->db->mallocFailed );
62787 return SQLITE_ERROR;
@@ -62706,11 +62793,11 @@
62793 }else{
62794 assert( pMem->z!=0 );
62795 pMem->n = sqlite3Strlen30(pMem->z);
62796 pMem->enc = SQLITE_UTF8;
62797 }
62798 pMem->memType = MEM_Str;
62799 pMem++;
62800
62801 if( p->explain==1 ){
62802 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62803 assert( p->db->mallocFailed );
@@ -62717,11 +62804,11 @@
62804 return SQLITE_ERROR;
62805 }
62806 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62807 pMem->n = 2;
62808 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62809 pMem->memType = MEM_Str;
62810 pMem->enc = SQLITE_UTF8;
62811 pMem++;
62812
62813 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62814 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
@@ -62728,15 +62815,15 @@
62815 assert( p->db->mallocFailed );
62816 return SQLITE_ERROR;
62817 }
62818 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62819 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62820 pMem->memType = MEM_Str;
62821 pMem->enc = SQLITE_UTF8;
62822 #else
62823 pMem->flags = MEM_Null; /* Comment */
62824 pMem->memType = MEM_Null;
62825 #endif
62826 }
62827
62828 p->nResColumn = 8 - 4*(p->explain-1);
62829 p->pResultSet = &p->aMem[1];
@@ -62755,11 +62842,11 @@
62842 const char *z = 0;
62843 if( p->zSql ){
62844 z = p->zSql;
62845 }else if( p->nOp>=1 ){
62846 const VdbeOp *pOp = &p->aOp[0];
62847 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
62848 z = pOp->p4.z;
62849 while( sqlite3Isspace(*z) ) z++;
62850 }
62851 }
62852 if( z ) printf("SQL: [%s]\n", z);
@@ -62774,11 +62861,11 @@
62861 int nOp = p->nOp;
62862 VdbeOp *pOp;
62863 if( sqlite3IoTrace==0 ) return;
62864 if( nOp<1 ) return;
62865 pOp = &p->aOp[0];
62866 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
62867 int i, j;
62868 char z[1000];
62869 sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z);
62870 for(i=0; sqlite3Isspace(z[i]); i++){}
62871 for(j=0; z[i]; i++){
@@ -62992,11 +63079,11 @@
63079 }
63080 if( p->aMem ){
63081 p->aMem--; /* aMem[] goes from 1..nMem */
63082 p->nMem = nMem; /* not from 0..nMem-1 */
63083 for(n=1; n<=nMem; n++){
63084 p->aMem[n].flags = MEM_Undefined;
63085 p->aMem[n].db = db;
63086 }
63087 }
63088 p->explain = pParse->explain;
63089 sqlite3VdbeRewind(p);
@@ -63104,11 +63191,11 @@
63191 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
63192 ** Vdbe.aMem[] arrays have already been cleaned up. */
63193 int i;
63194 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
63195 if( p->aMem ){
63196 for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
63197 }
63198 #endif
63199
63200 sqlite3DbFree(db, p->zErrMsg);
63201 p->zErrMsg = 0;
@@ -63853,16 +63940,28 @@
63940 fprintf(out, "---- ");
63941 for(i=0; i<p->nOp; i++){
63942 fprintf(out, "%02x", p->aOp[i].opcode);
63943 }
63944 fprintf(out, "\n");
63945 if( p->zSql ){
63946 char c, pc = 0;
63947 fprintf(out, "-- ");
63948 for(i=0; (c = p->zSql[i])!=0; i++){
63949 if( pc=='\n' ) fprintf(out, "-- ");
63950 putc(c, out);
63951 pc = c;
63952 }
63953 if( pc!='\n' ) fprintf(out, "\n");
63954 }
63955 for(i=0; i<p->nOp; i++){
63956 char zHdr[100];
63957 sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
63958 p->aOp[i].cnt,
63959 p->aOp[i].cycles,
63960 p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
63961 );
63962 fprintf(out, "%s", zHdr);
63963 sqlite3VdbePrintOp(out, i, &p->aOp[i]);
63964 }
63965 fclose(out);
63966 }
63967 }
@@ -64895,11 +64994,45 @@
64994 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
64995 return sqlite3ValueText(pVal, SQLITE_UTF16LE);
64996 }
64997 #endif /* SQLITE_OMIT_UTF16 */
64998 SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
64999 static const u8 aType[] = {
65000 SQLITE_BLOB, /* 0x00 */
65001 SQLITE_NULL, /* 0x01 */
65002 SQLITE_TEXT, /* 0x02 */
65003 SQLITE_NULL, /* 0x03 */
65004 SQLITE_INTEGER, /* 0x04 */
65005 SQLITE_NULL, /* 0x05 */
65006 SQLITE_INTEGER, /* 0x06 */
65007 SQLITE_NULL, /* 0x07 */
65008 SQLITE_FLOAT, /* 0x08 */
65009 SQLITE_NULL, /* 0x09 */
65010 SQLITE_FLOAT, /* 0x0a */
65011 SQLITE_NULL, /* 0x0b */
65012 SQLITE_INTEGER, /* 0x0c */
65013 SQLITE_NULL, /* 0x0d */
65014 SQLITE_INTEGER, /* 0x0e */
65015 SQLITE_NULL, /* 0x0f */
65016 SQLITE_BLOB, /* 0x10 */
65017 SQLITE_NULL, /* 0x11 */
65018 SQLITE_TEXT, /* 0x12 */
65019 SQLITE_NULL, /* 0x13 */
65020 SQLITE_INTEGER, /* 0x14 */
65021 SQLITE_NULL, /* 0x15 */
65022 SQLITE_INTEGER, /* 0x16 */
65023 SQLITE_NULL, /* 0x17 */
65024 SQLITE_FLOAT, /* 0x18 */
65025 SQLITE_NULL, /* 0x19 */
65026 SQLITE_FLOAT, /* 0x1a */
65027 SQLITE_NULL, /* 0x1b */
65028 SQLITE_INTEGER, /* 0x1c */
65029 SQLITE_NULL, /* 0x1d */
65030 SQLITE_INTEGER, /* 0x1e */
65031 SQLITE_NULL, /* 0x1f */
65032 };
65033 return aType[pVal->memType&0x1f];
65034 }
65035
65036 /**************************** sqlite3_result_ *******************************
65037 ** The following routines are used by user-defined functions to specify
65038 ** the function result.
@@ -65854,11 +65987,11 @@
65987 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
65988 }
65989 #endif /* SQLITE_OMIT_UTF16 */
65990 SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
65991 int rc;
65992 switch( sqlite3_value_type((sqlite3_value*)pValue) ){
65993 case SQLITE_INTEGER: {
65994 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
65995 break;
65996 }
65997 case SQLITE_FLOAT: {
@@ -66355,37 +66488,12 @@
66488 ** May you do good and not evil.
66489 ** May you find forgiveness for yourself and forgive others.
66490 ** May you share freely, never taking more than you give.
66491 **
66492 *************************************************************************
66493 ** The code in this file implements the function that runs the
66494 ** bytecode of a prepared statement.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66495 **
66496 ** Various scripts scan this source file in order to generate HTML
66497 ** documentation, headers files, or other derived files. The formatting
66498 ** of the code in this file is, therefore, important. See other comments
66499 ** in this file for details. If in doubt, do not deviate from existing
@@ -66393,11 +66501,15 @@
66501 */
66502
66503 /*
66504 ** Invoke this macro on memory cells just prior to changing the
66505 ** value of the cell. This macro verifies that shallow copies are
66506 ** not misused. A shallow copy of a string or blob just copies a
66507 ** pointer to the string or blob, not the content. If the original
66508 ** is changed while the copy is still in use, the string or blob might
66509 ** be changed out from under the copy. This macro verifies that nothing
66510 ** like that every happens.
66511 */
66512 #ifdef SQLITE_DEBUG
66513 # define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
66514 #else
66515 # define memAboutToChange(P,M)
@@ -66452,11 +66564,11 @@
66564 }
66565 }
66566 #endif
66567
66568 /*
66569 ** The next global variable is incremented each time the OP_Found opcode
66570 ** is executed. This is used to test whether or not the foreign key
66571 ** operation implemented using OP_FkIsZero is working. This variable
66572 ** has no function other than to help verify the correct operation of the
66573 ** library.
66574 */
@@ -66472,10 +66584,38 @@
66584 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
66585 #else
66586 # define UPDATE_MAX_BLOBSIZE(P)
66587 #endif
66588
66589 /*
66590 ** Invoke the VDBE coverage callback, if that callback is defined. This
66591 ** feature is used for test suite validation only and does not appear an
66592 ** production builds.
66593 **
66594 ** M is an integer, 2 or 3, that indices how many different ways the
66595 ** branch can go. It is usually 2. "I" is the direction the branch
66596 ** goes. 0 means falls through. 1 means branch is taken. 2 means the
66597 ** second alternative branch is taken.
66598 */
66599 #if !defined(SQLITE_VDBE_COVERAGE)
66600 # define VdbeBranchTaken(I,M)
66601 #else
66602 # define VdbeBranchTaken(I,M) vdbeTakeBranch(pOp->iSrcLine,I,M)
66603 static void vdbeTakeBranch(int iSrcLine, u8 I, u8 M){
66604 if( iSrcLine<=2 && ALWAYS(iSrcLine>0) ){
66605 M = iSrcLine;
66606 /* Assert the truth of VdbeCoverageAlwaysTaken() and
66607 ** VdbeCoverageNeverTaken() */
66608 assert( (M & I)==I );
66609 }else{
66610 if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
66611 sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
66612 iSrcLine,I,M);
66613 }
66614 }
66615 #endif
66616
66617 /*
66618 ** Convert the given register into a string if it isn't one
66619 ** already. Return non-zero if a malloc() fails.
66620 */
66621 #define Stringify(P, enc) \
@@ -66496,35 +66636,11 @@
66636 #define Deephemeralize(P) \
66637 if( ((P)->flags&MEM_Ephem)!=0 \
66638 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
66639
66640 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
66641 #define isSorter(x) ((x)->pSorter!=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66642
66643 /*
66644 ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
66645 ** if we run out of memory.
66646 */
@@ -66650,16 +66766,18 @@
66766 ** into a numeric representation. Use either INTEGER or REAL whichever
66767 ** is appropriate. But only do the conversion if it is possible without
66768 ** loss of information and return the revised type of the argument.
66769 */
66770 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
66771 int eType = sqlite3_value_type(pVal);
66772 if( eType==SQLITE_TEXT ){
66773 Mem *pMem = (Mem*)pVal;
66774 applyNumericAffinity(pMem);
66775 sqlite3VdbeMemStoreType(pMem);
66776 eType = sqlite3_value_type(pVal);
66777 }
66778 return eType;
66779 }
66780
66781 /*
66782 ** Exported version of applyAffinity(). This one works on sqlite3_value*,
66783 ** not the internal Mem* type.
@@ -66758,11 +66876,11 @@
66876 #ifdef SQLITE_DEBUG
66877 /*
66878 ** Print the value of a register for tracing purposes:
66879 */
66880 static void memTracePrint(Mem *p){
66881 if( p->flags & MEM_Undefined ){
66882 printf(" undefined");
66883 }else if( p->flags & MEM_Null ){
66884 printf(" NULL");
66885 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66886 printf(" si:%lld", p->u.i);
@@ -66890,24 +67008,10 @@
67008
67009 /************** End of hwtime.h **********************************************/
67010 /************** Continuing where we left off in vdbe.c ***********************/
67011
67012 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67013
67014 #ifndef NDEBUG
67015 /*
67016 ** This function is only called from within an assert() expression. It
67017 ** checks that the sqlite3.nTransaction variable is correctly set to
@@ -66927,39 +67031,12 @@
67031 }
67032 #endif
67033
67034
67035 /*
67036 ** Execute as much of a VDBE program as we can.
67037 ** This is the core of sqlite3_step().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67038 */
67039 SQLITE_PRIVATE int sqlite3VdbeExec(
67040 Vdbe *p /* The VDBE */
67041 ){
67042 int pc=0; /* The program counter */
@@ -66981,11 +67058,10 @@
67058 Mem *pOut = 0; /* Output operand */
67059 int *aPermute = 0; /* Permutation of columns for OP_Compare */
67060 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
67061 #ifdef VDBE_PROFILE
67062 u64 start; /* CPU clock count at start of opcode */
 
67063 #endif
67064 /*** INSERT STACK UNION HERE ***/
67065
67066 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
67067 sqlite3VdbeEnter(p);
@@ -66999,11 +67075,11 @@
67075 p->rc = SQLITE_OK;
67076 p->iCurrentTime = 0;
67077 assert( p->explain==0 );
67078 p->pResultSet = 0;
67079 db->busyHandler.nBusy = 0;
67080 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
67081 sqlite3VdbeIOTraceSql(p);
67082 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67083 if( db->xProgress ){
67084 assert( 0 < db->nProgressOps );
67085 nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
@@ -67043,11 +67119,10 @@
67119 #endif
67120 for(pc=p->pc; rc==SQLITE_OK; pc++){
67121 assert( pc>=0 && pc<p->nOp );
67122 if( db->mallocFailed ) goto no_mem;
67123 #ifdef VDBE_PROFILE
 
67124 start = sqlite3Hwtime();
67125 #endif
67126 nVmStep++;
67127 pOp = &aOp[pc];
67128
@@ -67175,11 +67250,11 @@
67250 ** But that is not due to sloppy coding habits. The code is written this
67251 ** way for performance, to avoid having to run the interrupt and progress
67252 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
67253 ** faster according to "valgrind --tool=cachegrind" */
67254 check_for_interrupt:
67255 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
67256 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67257 /* Call the progress callback if it is configured and the required number
67258 ** of VDBE ops have been executed (either since this invocation of
67259 ** sqlite3VdbeExec() or since last time the progress callback was called).
67260 ** If the progress callback returns non-zero, exit the virtual machine with
@@ -67215,24 +67290,70 @@
67290 break;
67291 }
67292
67293 /* Opcode: Return P1 * * * *
67294 **
67295 ** Jump to the next instruction after the address in register P1. After
67296 ** the jump, register P1 becomes undefined.
67297 */
67298 case OP_Return: { /* in1 */
67299 pIn1 = &aMem[pOp->p1];
67300 assert( pIn1->flags==MEM_Int );
67301 pc = (int)pIn1->u.i;
67302 pIn1->flags = MEM_Undefined;
67303 break;
67304 }
67305
67306 /* Opcode: InitCoroutine P1 P2 P3 * *
67307 **
67308 ** Set up register P1 so that it will OP_Yield to the co-routine
67309 ** located at address P3.
67310 **
67311 ** If P2!=0 then the co-routine implementation immediately follows
67312 ** this opcode. So jump over the co-routine implementation to
67313 ** address P2.
67314 */
67315 case OP_InitCoroutine: { /* jump */
67316 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67317 assert( pOp->p2>=0 && pOp->p2<p->nOp );
67318 assert( pOp->p3>=0 && pOp->p3<p->nOp );
67319 pOut = &aMem[pOp->p1];
67320 assert( !VdbeMemDynamic(pOut) );
67321 pOut->u.i = pOp->p3 - 1;
67322 pOut->flags = MEM_Int;
67323 if( pOp->p2 ) pc = pOp->p2 - 1;
67324 break;
67325 }
67326
67327 /* Opcode: EndCoroutine P1 * * * *
67328 **
67329 ** The instruction at the address in register P1 is an OP_Yield.
67330 ** Jump to the P2 parameter of that OP_Yield.
67331 ** After the jump, register P1 becomes undefined.
67332 */
67333 case OP_EndCoroutine: { /* in1 */
67334 VdbeOp *pCaller;
67335 pIn1 = &aMem[pOp->p1];
67336 assert( pIn1->flags==MEM_Int );
67337 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
67338 pCaller = &aOp[pIn1->u.i];
67339 assert( pCaller->opcode==OP_Yield );
67340 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
67341 pc = pCaller->p2 - 1;
67342 pIn1->flags = MEM_Undefined;
67343 break;
67344 }
67345
67346 /* Opcode: Yield P1 P2 * * *
67347 **
67348 ** Swap the program counter with the value in register P1.
67349 **
67350 ** If the co-routine ends with OP_Yield or OP_Return then continue
67351 ** to the next instruction. But if the co-routine ends with
67352 ** OP_EndCoroutine, jump immediately to P2.
67353 */
67354 case OP_Yield: { /* in1, jump */
67355 int pcDest;
67356 pIn1 = &aMem[pOp->p1];
67357 assert( (pIn1->flags & MEM_Dyn)==0 );
67358 pIn1->flags = MEM_Int;
67359 pcDest = (int)pIn1->u.i;
@@ -67241,11 +67362,11 @@
67362 pc = pcDest;
67363 break;
67364 }
67365
67366 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67367 ** Synopsis: if r[P3]=null halt
67368 **
67369 ** Check the value in register P3. If it is NULL then Halt using
67370 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the
67371 ** value in register P3 is not NULL, then this routine is a no-op.
67372 ** The P5 parameter should be 1.
@@ -67389,11 +67510,13 @@
67510
67511 /* Opcode: String8 * P2 * P4 *
67512 ** Synopsis: r[P2]='P4'
67513 **
67514 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67515 ** into an OP_String before it is executed for the first time. During
67516 ** this transformation, the length of string P4 is computed and stored
67517 ** as the P1 parameter.
67518 */
67519 case OP_String8: { /* same as TK_STRING, out2-prerelease */
67520 assert( pOp->p4.z!=0 );
67521 pOp->opcode = OP_String;
67522 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
@@ -67463,12 +67586,26 @@
67586 cnt--;
67587 }
67588 break;
67589 }
67590
67591 /* Opcode: SoftNull P1 * * * *
67592 ** Synopsis: r[P1]=NULL
67593 **
67594 ** Set register P1 to have the value NULL as seen by the OP_MakeRecord
67595 ** instruction, but do not free any string or blob memory associated with
67596 ** the register, so that if the value was a string or blob that was
67597 ** previously copied using OP_SCopy, the copies will continue to be valid.
67598 */
67599 case OP_SoftNull: {
67600 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67601 pOut = &aMem[pOp->p1];
67602 pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
67603 break;
67604 }
67605
67606 /* Opcode: Blob P1 P2 * P4 *
67607 ** Synopsis: r[P2]=P4 (len=P1)
67608 **
67609 ** P4 points to a blob of data P1 bytes long. Store this
67610 ** blob in register P2.
67611 */
@@ -67483,11 +67620,11 @@
67620 /* Opcode: Variable P1 P2 * P4 *
67621 ** Synopsis: r[P2]=parameter(P1,P4)
67622 **
67623 ** Transfer the values of bound parameter P1 into register P2
67624 **
67625 ** If the parameter is named, then its name appears in P4.
67626 ** The P4 value is used by sqlite3_bind_parameter_name().
67627 */
67628 case OP_Variable: { /* out2-prerelease */
67629 Mem *pVar; /* Value being transferred */
67630
@@ -67602,12 +67739,12 @@
67739 ** Synopsis: output=r[P1@P2]
67740 **
67741 ** The registers P1 through P1+P2-1 contain a single row of
67742 ** results. This opcode causes the sqlite3_step() call to terminate
67743 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67744 ** structure to provide access to the r(P1)..r(P1+P2-1) values as
67745 ** the result row.
67746 */
67747 case OP_ResultRow: {
67748 Mem *pMem;
67749 int i;
67750 assert( p->nResColumn==pOp->p2 );
@@ -68093,10 +68230,11 @@
68230 */
68231 case OP_MustBeInt: { /* jump, in1 */
68232 pIn1 = &aMem[pOp->p1];
68233 if( (pIn1->flags & MEM_Int)==0 ){
68234 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
68235 VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
68236 if( (pIn1->flags & MEM_Int)==0 ){
68237 if( pOp->p2==0 ){
68238 rc = SQLITE_MISMATCH;
68239 goto abort_due_to_error;
68240 }else{
@@ -68131,11 +68269,11 @@
68269 #ifndef SQLITE_OMIT_CAST
68270 /* Opcode: ToText P1 * * * *
68271 **
68272 ** Force the value in register P1 to be text.
68273 ** If the value is numeric, convert it to a string using the
68274 ** equivalent of sprintf(). Blob values are unchanged and
68275 ** are afterwards simply interpreted as text.
68276 **
68277 ** A NULL value is not changed by this routine. It remains NULL.
68278 */
68279 case OP_ToText: { /* same as TK_TO_TEXT, in1 */
@@ -68333,10 +68471,11 @@
68471 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68472 ** or not both operands are null.
68473 */
68474 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68475 assert( (flags1 & MEM_Cleared)==0 );
68476 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 );
68477 if( (flags1&MEM_Null)!=0
68478 && (flags3&MEM_Null)!=0
68479 && (flags3&MEM_Cleared)==0
68480 ){
68481 res = 0; /* Results are equal */
@@ -68346,16 +68485,19 @@
68485 }else{
68486 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68487 ** then the result is always NULL.
68488 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
68489 */
68490 if( pOp->p5 & SQLITE_STOREP2 ){
 
 
68491 pOut = &aMem[pOp->p2];
68492 MemSetTypeFlag(pOut, MEM_Null);
68493 REGISTER_TRACE(pOp->p2, pOut);
68494 }else{
68495 VdbeBranchTaken(2,3);
68496 if( pOp->p5 & SQLITE_JUMPIFNULL ){
68497 pc = pOp->p2-1;
68498 }
68499 }
68500 break;
68501 }
68502 }else{
68503 /* Neither operand is NULL. Do a comparison. */
@@ -68384,14 +68526,16 @@
68526 pOut = &aMem[pOp->p2];
68527 memAboutToChange(p, pOut);
68528 MemSetTypeFlag(pOut, MEM_Int);
68529 pOut->u.i = res;
68530 REGISTER_TRACE(pOp->p2, pOut);
68531 }else{
68532 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
68533 if( res ){
68534 pc = pOp->p2-1;
68535 }
68536 }
 
68537 /* Undo any changes made by applyAffinity() to the input registers. */
68538 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68539 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68540 break;
68541 }
@@ -68484,15 +68628,15 @@
68628 ** in the most recent OP_Compare instruction the P1 vector was less than
68629 ** equal to, or greater than the P2 vector, respectively.
68630 */
68631 case OP_Jump: { /* jump */
68632 if( iCompare<0 ){
68633 pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
68634 }else if( iCompare==0 ){
68635 pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
68636 }else{
68637 pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
68638 }
68639 break;
68640 }
68641
68642 /* Opcode: And P1 P2 P3 * *
@@ -68586,14 +68730,17 @@
68730 }
68731
68732 /* Opcode: Once P1 P2 * * *
68733 **
68734 ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
68735 ** set the flag and fall through to the next instruction. In other words,
68736 ** this opcode causes all following up codes up through P2 (but not including
68737 ** P2) to run just once and skipped on subsequent times through the loop.
68738 */
68739 case OP_Once: { /* jump */
68740 assert( pOp->p1<p->nOnceFlag );
68741 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
68742 if( p->aOnceFlag[pOp->p1] ){
68743 pc = pOp->p2-1;
68744 }else{
68745 p->aOnceFlag[pOp->p1] = 1;
68746 }
@@ -68624,10 +68771,11 @@
68771 #else
68772 c = sqlite3VdbeRealValue(pIn1)!=0.0;
68773 #endif
68774 if( pOp->opcode==OP_IfNot ) c = !c;
68775 }
68776 VdbeBranchTaken(c!=0, 2);
68777 if( c ){
68778 pc = pOp->p2-1;
68779 }
68780 break;
68781 }
@@ -68637,10 +68785,11 @@
68785 **
68786 ** Jump to P2 if the value in register P1 is NULL.
68787 */
68788 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
68789 pIn1 = &aMem[pOp->p1];
68790 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
68791 if( (pIn1->flags & MEM_Null)!=0 ){
68792 pc = pOp->p2 - 1;
68793 }
68794 break;
68795 }
@@ -68650,10 +68799,11 @@
68799 **
68800 ** Jump to P2 if the value in register P1 is not NULL.
68801 */
68802 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
68803 pIn1 = &aMem[pOp->p1];
68804 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
68805 if( (pIn1->flags & MEM_Null)==0 ){
68806 pc = pOp->p2 - 1;
68807 }
68808 break;
68809 }
@@ -68726,15 +68876,10 @@
68876 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68877 if( pC->nullRow ){
68878 if( pCrsr==0 ){
68879 assert( pC->pseudoTableReg>0 );
68880 pReg = &aMem[pC->pseudoTableReg];
 
 
 
 
 
68881 assert( pReg->flags & MEM_Blob );
68882 assert( memIsValid(pReg) );
68883 pC->payloadSize = pC->szRow = avail = pReg->n;
68884 pC->aRow = (u8*)pReg->z;
68885 }else{
@@ -68956,11 +69101,10 @@
69101 assert( zAffinity[pOp->p2]==0 );
69102 pIn1 = &aMem[pOp->p1];
69103 while( (cAff = *(zAffinity++))!=0 ){
69104 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
69105 assert( memIsValid(pIn1) );
 
69106 applyAffinity(pIn1, cAff, encoding);
69107 pIn1++;
69108 }
69109 break;
69110 }
@@ -69034,12 +69178,13 @@
69178 */
69179 assert( pData0<=pLast );
69180 if( zAffinity ){
69181 pRec = pData0;
69182 do{
69183 applyAffinity(pRec++, *(zAffinity++), encoding);
69184 assert( zAffinity[0]==0 || pRec<=pLast );
69185 }while( zAffinity[0] );
69186 }
69187
69188 /* Loop through the elements that will make up the record to figure
69189 ** out how much space is required for the new record.
69190 */
@@ -69379,29 +69524,23 @@
69524 rc = SQLITE_ERROR;
69525 }
69526 break;
69527 }
69528
69529 /* Opcode: Transaction P1 P2 P3 P4 P5
69530 **
69531 ** Begin a transaction on database P1 if a transaction is not already
69532 ** active.
69533 ** If P2 is non-zero, then a write-transaction is started, or if a
69534 ** read-transaction is already active, it is upgraded to a write-transaction.
69535 ** If P2 is zero, then a read-transaction is started.
69536 **
69537 ** P1 is the index of the database file on which the transaction is
69538 ** started. Index 0 is the main database file and index 1 is the
69539 ** file used for temporary tables. Indices of 2 or more are used for
69540 ** attached databases.
69541 **
 
 
 
 
 
 
 
 
69542 ** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
69543 ** true (this flag is set if the Vdbe may modify more than one row and may
69544 ** throw an ABORT exception), a statement transaction may also be opened.
69545 ** More specifically, a statement transaction is opened iff the database
69546 ** connection is currently not in autocommit mode, or if there are other
@@ -69408,14 +69547,25 @@
69547 ** active statements. A statement transaction allows the changes made by this
69548 ** VDBE to be rolled back after an error without having to roll back the
69549 ** entire transaction. If no error is encountered, the statement transaction
69550 ** will automatically commit when the VDBE halts.
69551 **
69552 ** If P5!=0 then this opcode also checks the schema cookie against P3
69553 ** and the schema generation counter against P4.
69554 ** The cookie changes its value whenever the database schema changes.
69555 ** This operation is used to detect when that the cookie has changed
69556 ** and that the current process needs to reread the schema. If the schema
69557 ** cookie in P3 differs from the schema cookie in the database header or
69558 ** if the schema generation counter in P4 differs from the current
69559 ** generation counter, then an SQLITE_SCHEMA error is raised and execution
69560 ** halts. The sqlite3_step() wrapper function might then reprepare the
69561 ** statement and rerun it from the beginning.
69562 */
69563 case OP_Transaction: {
69564 Btree *pBt;
69565 int iMeta;
69566 int iGen;
69567
69568 assert( p->bIsReader );
69569 assert( p->readOnly==0 || pOp->p2==0 );
69570 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69571 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
@@ -69455,10 +69605,39 @@
69605 ** counter. If the statement transaction needs to be rolled back,
69606 ** the value of this counter needs to be restored too. */
69607 p->nStmtDefCons = db->nDeferredCons;
69608 p->nStmtDefImmCons = db->nDeferredImmCons;
69609 }
69610
69611 /* Gather the schema version number for checking */
69612 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69613 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69614 }else{
69615 iGen = iMeta = 0;
69616 }
69617 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
69618 if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){
69619 sqlite3DbFree(db, p->zErrMsg);
69620 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69621 /* If the schema-cookie from the database file matches the cookie
69622 ** stored with the in-memory representation of the schema, do
69623 ** not reload the schema from the database file.
69624 **
69625 ** If virtual-tables are in use, this is not just an optimization.
69626 ** Often, v-tables store their data in other SQLite tables, which
69627 ** are queried from within xNext() and other v-table methods using
69628 ** prepared queries. If such a query is out-of-date, we do not want to
69629 ** discard the database schema, as the user code implementing the
69630 ** v-table would have to be ready for the sqlite3_vtab structure itself
69631 ** to be invalidated whenever sqlite3_step() is called from within
69632 ** a v-table method.
69633 */
69634 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69635 sqlite3ResetOneSchema(db, pOp->p1);
69636 }
69637 p->expired = 1;
69638 rc = SQLITE_SCHEMA;
69639 }
69640 break;
69641 }
69642
69643 /* Opcode: ReadCookie P1 P2 P3 * *
@@ -69526,70 +69705,10 @@
69705 /* Invalidate all prepared statements whenever the TEMP database
69706 ** schema is changed. Ticket #1644 */
69707 sqlite3ExpirePreparedStatements(db);
69708 p->expired = 0;
69709 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69710 break;
69711 }
69712
69713 /* Opcode: OpenRead P1 P2 P3 P4 P5
69714 ** Synopsis: root=P2 iDb=P3
@@ -69802,11 +69921,11 @@
69921 }
69922 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69923 break;
69924 }
69925
69926 /* Opcode: SorterOpen P1 P2 * P4 *
69927 **
69928 ** This opcode works like OP_OpenEphemeral except that it opens
69929 ** a transient index that is specifically designed to sort large
69930 ** tables using an external merge-sort algorithm.
69931 */
@@ -69822,18 +69941,17 @@
69941 assert( pCx->pKeyInfo->enc==ENC(db) );
69942 rc = sqlite3VdbeSorterInit(db, pCx);
69943 break;
69944 }
69945
69946 /* Opcode: OpenPseudo P1 P2 P3 * *
69947 ** Synopsis: P3 columns in r[P2]
69948 **
69949 ** Open a new cursor that points to a fake table that contains a single
69950 ** row of data. The content of that one row is the content of memory
69951 ** register P2. In other words, cursor P1 becomes an alias for the
69952 ** MEM_Blob content contained in register P2.
 
69953 **
69954 ** A pseudo-table created by this opcode is used to hold a single
69955 ** row output from the sorter so that the row can be decomposed into
69956 ** individual columns using the OP_Column opcode. The OP_Column opcode
69957 ** is the only cursor opcode that works with a pseudo-table.
@@ -69849,11 +69967,11 @@
69967 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69968 if( pCx==0 ) goto no_mem;
69969 pCx->nullRow = 1;
69970 pCx->pseudoTableReg = pOp->p2;
69971 pCx->isTable = 1;
69972 assert( pOp->p5==0 );
69973 break;
69974 }
69975
69976 /* Opcode: Close P1 * * * *
69977 **
@@ -69921,14 +70039,14 @@
70039 ** is less than or equal to the key value. If there are no records
70040 ** less than or equal to the key and P2 is not zero, then jump to P2.
70041 **
70042 ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
70043 */
70044 case OP_SeekLT: /* jump, in3 */
70045 case OP_SeekLE: /* jump, in3 */
70046 case OP_SeekGE: /* jump, in3 */
70047 case OP_SeekGT: { /* jump, in3 */
70048 int res;
70049 int oc;
70050 VdbeCursor *pC;
70051 UnpackedRecord r;
70052 int nField;
@@ -69937,13 +70055,13 @@
70055 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70056 assert( pOp->p2!=0 );
70057 pC = p->apCsr[pOp->p1];
70058 assert( pC!=0 );
70059 assert( pC->pseudoTableReg==0 );
70060 assert( OP_SeekLE == OP_SeekLT+1 );
70061 assert( OP_SeekGE == OP_SeekLT+2 );
70062 assert( OP_SeekGT == OP_SeekLT+3 );
70063 assert( pC->isOrdered );
70064 assert( pC->pCursor!=0 );
70065 oc = pOp->opcode;
70066 pC->nullRow = 0;
70067 if( pC->isTable ){
@@ -69959,11 +70077,11 @@
70077 ** loss of information, then special processing is required... */
70078 if( (pIn3->flags & MEM_Int)==0 ){
70079 if( (pIn3->flags & MEM_Real)==0 ){
70080 /* If the P3 value cannot be converted into any kind of a number,
70081 ** then the seek is not possible, so jump to P2 */
70082 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
70083 break;
70084 }
70085
70086 /* If the approximation iKey is larger than the actual real search
70087 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -69971,23 +70089,23 @@
70089 **
70090 ** (x > 4.9) -> (x >= 5)
70091 ** (x <= 4.9) -> (x < 5)
70092 */
70093 if( pIn3->r<(double)iKey ){
70094 assert( OP_SeekGE==(OP_SeekGT-1) );
70095 assert( OP_SeekLT==(OP_SeekLE-1) );
70096 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
70097 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
70098 }
70099
70100 /* If the approximation iKey is smaller than the actual real search
70101 ** term, substitute <= for < and > for >=. */
70102 else if( pIn3->r>(double)iKey ){
70103 assert( OP_SeekLE==(OP_SeekLT+1) );
70104 assert( OP_SeekGT==(OP_SeekGE+1) );
70105 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
70106 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
70107 }
70108 }
70109 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
70110 if( rc!=SQLITE_OK ){
70111 goto abort_due_to_error;
@@ -70002,21 +70120,21 @@
70120 assert( nField>0 );
70121 r.pKeyInfo = pC->pKeyInfo;
70122 r.nField = (u16)nField;
70123
70124 /* The next line of code computes as follows, only faster:
70125 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70126 ** r.flags = UNPACKED_INCRKEY;
70127 ** }else{
70128 ** r.flags = 0;
70129 ** }
70130 */
70131 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132 assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133 assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134 assert( oc!=OP_SeekGE || r.flags==0 );
70135 assert( oc!=OP_SeekLT || r.flags==0 );
70136
70137 r.aMem = &aMem[pOp->p3];
70138 #ifdef SQLITE_DEBUG
70139 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70140 #endif
@@ -70030,21 +70148,23 @@
70148 pC->deferredMoveto = 0;
70149 pC->cacheStatus = CACHE_STALE;
70150 #ifdef SQLITE_TEST
70151 sqlite3_search_count++;
70152 #endif
70153 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
70154 if( res<0 || (res==0 && oc==OP_SeekGT) ){
70155 res = 0;
70156 rc = sqlite3BtreeNext(pC->pCursor, &res);
70157 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70158 pC->rowidIsValid = 0;
70159 }else{
70160 res = 0;
70161 }
70162 }else{
70163 assert( oc==OP_SeekLT || oc==OP_SeekLE );
70164 if( res>0 || (res==0 && oc==OP_SeekLT) ){
70165 res = 0;
70166 rc = sqlite3BtreePrevious(pC->pCursor, &res);
70167 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70168 pC->rowidIsValid = 0;
70169 }else{
70170 /* res might be negative because the table is empty. Check to
@@ -70052,10 +70172,11 @@
70172 */
70173 res = sqlite3BtreeEof(pC->pCursor);
70174 }
70175 }
70176 assert( pOp->p2>0 );
70177 VdbeBranchTaken(res!=0,2);
70178 if( res ){
70179 pc = pOp->p2 - 1;
70180 }
70181 break;
70182 }
@@ -70160,19 +70281,17 @@
70281 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
70282 if( pOp->p4.i>0 ){
70283 r.pKeyInfo = pC->pKeyInfo;
70284 r.nField = (u16)pOp->p4.i;
70285 r.aMem = pIn3;
70286 for(ii=0; ii<r.nField; ii++){
70287 assert( memIsValid(&r.aMem[ii]) );
70288 ExpandBlob(&r.aMem[ii]);
70289 #ifdef SQLITE_DEBUG
70290 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70291 #endif
70292 }
 
 
 
 
 
70293 r.flags = UNPACKED_PREFIX_MATCH;
70294 pIdxKey = &r;
70295 }else{
70296 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70297 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
@@ -70187,11 +70306,11 @@
70306 /* For the OP_NoConflict opcode, take the jump if any of the
70307 ** input fields are NULL, since any key with a NULL will not
70308 ** conflict */
70309 for(ii=0; ii<r.nField; ii++){
70310 if( r.aMem[ii].flags & MEM_Null ){
70311 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
70312 break;
70313 }
70314 }
70315 }
70316 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
@@ -70205,12 +70324,14 @@
70324 alreadyExists = (res==0);
70325 pC->nullRow = 1-alreadyExists;
70326 pC->deferredMoveto = 0;
70327 pC->cacheStatus = CACHE_STALE;
70328 if( pOp->opcode==OP_Found ){
70329 VdbeBranchTaken(alreadyExists!=0,2);
70330 if( alreadyExists ) pc = pOp->p2 - 1;
70331 }else{
70332 VdbeBranchTaken(alreadyExists==0,2);
70333 if( !alreadyExists ) pc = pOp->p2 - 1;
70334 }
70335 break;
70336 }
70337
@@ -70249,10 +70370,11 @@
70370 pC->lastRowid = pIn3->u.i;
70371 pC->rowidIsValid = res==0 ?1:0;
70372 pC->nullRow = 0;
70373 pC->cacheStatus = CACHE_STALE;
70374 pC->deferredMoveto = 0;
70375 VdbeBranchTaken(res!=0,2);
70376 if( res!=0 ){
70377 pc = pOp->p2 - 1;
70378 assert( pC->rowidIsValid==0 );
70379 }
70380 pC->seekResult = res;
@@ -70330,63 +70452,58 @@
70452 */
70453 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70454 #endif
70455
70456 if( !pC->useRandomRowid ){
70457 rc = sqlite3BtreeLast(pC->pCursor, &res);
70458 if( rc!=SQLITE_OK ){
70459 goto abort_due_to_error;
70460 }
70461 if( res ){
70462 v = 1; /* IMP: R-61914-48074 */
70463 }else{
70464 assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70465 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70466 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70467 if( v>=MAX_ROWID ){
70468 pC->useRandomRowid = 1;
70469 }else{
70470 v++; /* IMP: R-29538-34987 */
70471 }
70472 }
70473 }
70474
70475 #ifndef SQLITE_OMIT_AUTOINCREMENT
70476 if( pOp->p3 ){
70477 /* Assert that P3 is a valid memory cell. */
70478 assert( pOp->p3>0 );
70479 if( p->pFrame ){
70480 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70481 /* Assert that P3 is a valid memory cell. */
70482 assert( pOp->p3<=pFrame->nMem );
70483 pMem = &pFrame->aMem[pOp->p3];
70484 }else{
70485 /* Assert that P3 is a valid memory cell. */
70486 assert( pOp->p3<=(p->nMem-p->nCursor) );
70487 pMem = &aMem[pOp->p3];
70488 memAboutToChange(p, pMem);
70489 }
70490 assert( memIsValid(pMem) );
70491
70492 REGISTER_TRACE(pOp->p3, pMem);
70493 sqlite3VdbeMemIntegerify(pMem);
70494 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70495 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70496 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70497 goto abort_due_to_error;
70498 }
70499 if( v<pMem->u.i+1 ){
70500 v = pMem->u.i + 1;
70501 }
70502 pMem->u.i = v;
70503 }
70504 #endif
 
 
 
 
 
70505 if( pC->useRandomRowid ){
70506 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70507 ** largest possible integer (9223372036854775807) then the database
70508 ** engine starts picking positive candidate ROWIDs at random until
70509 ** it finds one that is not previously used. */
@@ -70516,11 +70633,10 @@
70633 if( pData->flags & MEM_Zero ){
70634 nZero = pData->u.nZero;
70635 }else{
70636 nZero = 0;
70637 }
 
70638 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70639 pData->z, pData->n, nZero,
70640 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
70641 );
70642 pC->rowidIsValid = 0;
@@ -70578,11 +70694,10 @@
70694 **/
70695 assert( pC->deferredMoveto==0 );
70696 rc = sqlite3VdbeCursorMoveto(pC);
70697 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70698
 
70699 rc = sqlite3BtreeDelete(pC->pCursor);
70700 pC->cacheStatus = CACHE_STALE;
70701
70702 /* Invoke the update-hook if required. */
70703 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
@@ -70630,10 +70745,11 @@
70745 assert( isSorter(pC) );
70746 assert( pOp->p4type==P4_INT32 );
70747 pIn3 = &aMem[pOp->p3];
70748 nIgnore = pOp->p4.i;
70749 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70750 VdbeBranchTaken(res!=0,2);
70751 if( res ){
70752 pc = pOp->p2-1;
70753 }
70754 break;
70755 };
@@ -70667,11 +70783,11 @@
70783 /* Opcode: RowKey P1 P2 * * *
70784 ** Synopsis: r[P2]=key
70785 **
70786 ** Write into register P2 the complete row key for cursor P1.
70787 ** There is no interpretation of the data.
70788 ** The key is copied onto the P2 register exactly as
70789 ** it is found in the database file.
70790 **
70791 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70792 ** of a real table, not a pseudo-table.
70793 */
@@ -70829,12 +70945,13 @@
70945 rc = sqlite3BtreeLast(pCrsr, &res);
70946 pC->nullRow = (u8)res;
70947 pC->deferredMoveto = 0;
70948 pC->rowidIsValid = 0;
70949 pC->cacheStatus = CACHE_STALE;
70950 if( pOp->p2>0 ){
70951 VdbeBranchTaken(res!=0,2);
70952 if( res ) pc = pOp->p2 - 1;
70953 }
70954 break;
70955 }
70956
70957
@@ -70887,56 +71004,67 @@
71004 pC->cacheStatus = CACHE_STALE;
71005 pC->rowidIsValid = 0;
71006 }
71007 pC->nullRow = (u8)res;
71008 assert( pOp->p2>0 && pOp->p2<p->nOp );
71009 VdbeBranchTaken(res!=0,2);
71010 if( res ){
71011 pc = pOp->p2 - 1;
71012 }
71013 break;
71014 }
71015
71016 /* Opcode: Next P1 P2 P3 P4 P5
71017 **
71018 ** Advance cursor P1 so that it points to the next key/data pair in its
71019 ** table or index. If there are no more key/value pairs then fall through
71020 ** to the following instruction. But if the cursor advance was successful,
71021 ** jump immediately to P2.
71022 **
71023 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
71024 ** been opened prior to this opcode or the program will segfault.
71025 **
71026 ** The P3 value is a hint to the btree implementation. If P3==1, that
71027 ** means P1 is an SQL index and that this instruction could have been
71028 ** omitted if that index had been unique. P3 is usually 0. P3 is
71029 ** always either 0 or 1.
71030 **
71031 ** P4 is always of type P4_ADVANCE. The function pointer points to
71032 ** sqlite3BtreeNext().
71033 **
71034 ** If P5 is positive and the jump is taken, then event counter
71035 ** number P5-1 in the prepared statement is incremented.
71036 **
71037 ** See also: Prev, NextIfOpen
71038 */
71039 /* Opcode: NextIfOpen P1 P2 P3 P4 P5
71040 **
71041 ** This opcode works just like OP_Next except that if cursor P1 is not
71042 ** open it behaves a no-op.
71043 */
71044 /* Opcode: Prev P1 P2 P3 P4 P5
71045 **
71046 ** Back up cursor P1 so that it points to the previous key/data pair in its
71047 ** table or index. If there is no previous key/value pairs then fall through
71048 ** to the following instruction. But if the cursor backup was successful,
71049 ** jump immediately to P2.
71050 **
71051 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
71052 ** not open then the behavior is undefined.
71053 **
71054 ** The P3 value is a hint to the btree implementation. If P3==1, that
71055 ** means P1 is an SQL index and that this instruction could have been
71056 ** omitted if that index had been unique. P3 is usually 0. P3 is
71057 ** always either 0 or 1.
71058 **
71059 ** P4 is always of type P4_ADVANCE. The function pointer points to
71060 ** sqlite3BtreePrevious().
71061 **
71062 ** If P5 is positive and the jump is taken, then event counter
71063 ** number P5-1 in the prepared statement is incremented.
71064 */
71065 /* Opcode: PrevIfOpen P1 P2 P3 P4 P5
71066 **
71067 ** This opcode works just like OP_Prev except that if cursor P1 is not
71068 ** open it behaves a no-op.
71069 */
71070 case OP_SorterNext: { /* jump */
@@ -70954,20 +71082,24 @@
71082 case OP_Prev: /* jump */
71083 case OP_Next: /* jump */
71084 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71085 assert( pOp->p5<ArraySize(p->aCounter) );
71086 pC = p->apCsr[pOp->p1];
71087 res = pOp->p3;
71088 assert( pC!=0 );
71089 assert( pC->deferredMoveto==0 );
71090 assert( pC->pCursor );
71091 assert( res==0 || (res==1 && pC->isTable==0) );
71092 testcase( res==1 );
71093 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
71094 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
71095 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
71096 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
71097 rc = pOp->p4.xAdvance(pC->pCursor, &res);
71098 next_tail:
71099 pC->cacheStatus = CACHE_STALE;
71100 VdbeBranchTaken(res==0,2);
71101 if( res==0 ){
71102 pC->nullRow = 0;
71103 pc = pOp->p2 - 1;
71104 p->aCounter[pOp->p5]++;
71105 #ifdef SQLITE_TEST
@@ -70987,10 +71119,18 @@
71119 ** MakeRecord instructions. This opcode writes that key
71120 ** into the index P1. Data for the entry is nil.
71121 **
71122 ** P3 is a flag that provides a hint to the b-tree layer that this
71123 ** insert is likely to be an append.
71124 **
71125 ** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
71126 ** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
71127 ** then the change counter is unchanged.
71128 **
71129 ** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have
71130 ** just done a seek to the spot where the new entry is to be inserted.
71131 ** This flag avoids doing an extra seek.
71132 **
71133 ** This instruction only works for indices. The equivalent instruction
71134 ** for tables is OP_Insert.
71135 */
71136 case OP_SorterInsert: /* in2 */
@@ -71102,36 +71242,54 @@
71242
71243 /* Opcode: IdxGE P1 P2 P3 P4 P5
71244 ** Synopsis: key=r[P3@P4]
71245 **
71246 ** The P4 register values beginning with P3 form an unpacked index
71247 ** key that omits the PRIMARY KEY. Compare this key value against the index
71248 ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71249 ** fields at the end.
71250 **
71251 ** If the P1 index entry is greater than or equal to the key value
71252 ** then jump to P2. Otherwise fall through to the next instruction.
71253 */
71254 /* Opcode: IdxGT P1 P2 P3 P4 P5
71255 ** Synopsis: key=r[P3@P4]
71256 **
71257 ** The P4 register values beginning with P3 form an unpacked index
71258 ** key that omits the PRIMARY KEY. Compare this key value against the index
71259 ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71260 ** fields at the end.
71261 **
71262 ** If the P1 index entry is greater than the key value
71263 ** then jump to P2. Otherwise fall through to the next instruction.
71264 */
71265 /* Opcode: IdxLT P1 P2 P3 P4 P5
71266 ** Synopsis: key=r[P3@P4]
71267 **
71268 ** The P4 register values beginning with P3 form an unpacked index
71269 ** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71270 ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71271 ** ROWID on the P1 index.
71272 **
71273 ** If the P1 index entry is less than the key value then jump to P2.
71274 ** Otherwise fall through to the next instruction.
71275 */
71276 /* Opcode: IdxLE P1 P2 P3 P4 P5
71277 ** Synopsis: key=r[P3@P4]
71278 **
71279 ** The P4 register values beginning with P3 form an unpacked index
71280 ** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71281 ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71282 ** ROWID on the P1 index.
71283 **
71284 ** If the P1 index entry is less than or equal to the key value then jump
71285 ** to P2. Otherwise fall through to the next instruction.
71286 */
71287 case OP_IdxLE: /* jump */
71288 case OP_IdxGT: /* jump */
71289 case OP_IdxLT: /* jump */
71290 case OP_IdxGE: { /* jump */
71291 VdbeCursor *pC;
71292 int res;
71293 UnpackedRecord r;
71294
71295 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -71142,27 +71300,32 @@
71300 assert( pC->deferredMoveto==0 );
71301 assert( pOp->p5==0 || pOp->p5==1 );
71302 assert( pOp->p4type==P4_INT32 );
71303 r.pKeyInfo = pC->pKeyInfo;
71304 r.nField = (u16)pOp->p4.i;
71305 if( pOp->opcode<OP_IdxLT ){
71306 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71307 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71308 }else{
71309 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71310 r.flags = UNPACKED_PREFIX_MATCH;
71311 }
71312 r.aMem = &aMem[pOp->p3];
71313 #ifdef SQLITE_DEBUG
71314 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71315 #endif
71316 res = 0; /* Not needed. Only used to silence a warning. */
71317 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71318 assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
71319 if( (pOp->opcode&1)==(OP_IdxLT&1) ){
71320 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
71321 res = -res;
71322 }else{
71323 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
71324 res++;
71325 }
71326 VdbeBranchTaken(res>0,2);
71327 if( res>0 ){
71328 pc = pOp->p2 - 1 ;
71329 }
71330 break;
71331 }
@@ -71251,11 +71414,10 @@
71414 case OP_Clear: {
71415 int nChange;
71416
71417 nChange = 0;
71418 assert( p->readOnly==0 );
 
71419 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71420 rc = sqlite3BtreeClearTable(
71421 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
71422 );
71423 if( pOp->p3 ){
@@ -71520,13 +71682,15 @@
71682 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71683 ){
71684 /* The boolean index is empty */
71685 sqlite3VdbeMemSetNull(pIn1);
71686 pc = pOp->p2 - 1;
71687 VdbeBranchTaken(1,2);
71688 }else{
71689 /* A value was pulled from the index */
71690 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71691 VdbeBranchTaken(0,2);
71692 }
71693 goto check_for_interrupt;
71694 }
71695
71696 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71574,10 +71738,11 @@
71738 assert( iSet==-1 || iSet>=0 );
71739 if( iSet ){
71740 exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71741 (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71742 pIn3->u.i);
71743 VdbeBranchTaken(exists!=0,2);
71744 if( exists ){
71745 pc = pOp->p2 - 1;
71746 break;
71747 }
71748 }
@@ -71588,11 +71753,11 @@
71753 }
71754
71755
71756 #ifndef SQLITE_OMIT_TRIGGER
71757
71758 /* Opcode: Program P1 P2 P3 P4 P5
71759 **
71760 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
71761 **
71762 ** P1 contains the address of the memory cell that contains the first memory
71763 ** cell in an array of values used as arguments to the sub-program. P2
@@ -71600,10 +71765,12 @@
71765 ** exception using the RAISE() function. Register P3 contains the address
71766 ** of a memory cell in this (the parent) VM that is used to allocate the
71767 ** memory required by the sub-vdbe at runtime.
71768 **
71769 ** P4 is a pointer to the VM containing the trigger program.
71770 **
71771 ** If P5 is non-zero, then recursive program invocation is enabled.
71772 */
71773 case OP_Program: { /* jump */
71774 int nMem; /* Number of memory registers for sub-program */
71775 int nByte; /* Bytes of runtime space required for sub-program */
71776 Mem *pRt; /* Register to allocate runtime space */
@@ -71677,11 +71844,11 @@
71844 pFrame->aOnceFlag = p->aOnceFlag;
71845 pFrame->nOnceFlag = p->nOnceFlag;
71846
71847 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71848 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71849 pMem->flags = MEM_Undefined;
71850 pMem->db = db;
71851 }
71852 }else{
71853 pFrame = pRt->u.pFrame;
71854 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
@@ -71764,12 +71931,14 @@
71931 ** zero, the jump is taken if the statement constraint-counter is zero
71932 ** (immediate foreign key constraint violations).
71933 */
71934 case OP_FkIfZero: { /* jump */
71935 if( pOp->p1 ){
71936 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
71937 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71938 }else{
71939 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
71940 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71941 }
71942 break;
71943 }
71944 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
@@ -71814,10 +71983,11 @@
71983 ** not contain an integer. An assertion fault will result if you try.
71984 */
71985 case OP_IfPos: { /* jump, in1 */
71986 pIn1 = &aMem[pOp->p1];
71987 assert( pIn1->flags&MEM_Int );
71988 VdbeBranchTaken( pIn1->u.i>0, 2);
71989 if( pIn1->u.i>0 ){
71990 pc = pOp->p2 - 1;
71991 }
71992 break;
71993 }
@@ -71831,10 +72001,11 @@
72001 ** not contain an integer. An assertion fault will result if you try.
72002 */
72003 case OP_IfNeg: { /* jump, in1 */
72004 pIn1 = &aMem[pOp->p1];
72005 assert( pIn1->flags&MEM_Int );
72006 VdbeBranchTaken(pIn1->u.i<0, 2);
72007 if( pIn1->u.i<0 ){
72008 pc = pOp->p2 - 1;
72009 }
72010 break;
72011 }
@@ -71850,10 +72021,11 @@
72021 */
72022 case OP_IfZero: { /* jump, in1 */
72023 pIn1 = &aMem[pOp->p1];
72024 assert( pIn1->flags&MEM_Int );
72025 pIn1->u.i += pOp->p3;
72026 VdbeBranchTaken(pIn1->u.i==0, 2);
72027 if( pIn1->u.i==0 ){
72028 pc = pOp->p2 - 1;
72029 }
72030 break;
72031 }
@@ -71987,11 +72159,11 @@
72159 break;
72160 };
72161 #endif
72162
72163 #ifndef SQLITE_OMIT_PRAGMA
72164 /* Opcode: JournalMode P1 P2 P3 * *
72165 **
72166 ** Change the journal mode of database P1 to P3. P3 must be one of the
72167 ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
72168 ** modes (delete, truncate, persist, off and memory), this is a simple
72169 ** operation. No IO is required.
@@ -72121,10 +72293,11 @@
72293 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72294 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72295 assert( p->readOnly==0 );
72296 pBt = db->aDb[pOp->p1].pBt;
72297 rc = sqlite3BtreeIncrVacuum(pBt);
72298 VdbeBranchTaken(rc==SQLITE_DONE,2);
72299 if( rc==SQLITE_DONE ){
72300 pc = pOp->p2 - 1;
72301 rc = SQLITE_OK;
72302 }
72303 break;
@@ -72327,11 +72500,11 @@
72500 p->inVtabMethod = 0;
72501 sqlite3VtabImportErrmsg(p, pVtab);
72502 if( rc==SQLITE_OK ){
72503 res = pModule->xEof(pVtabCursor);
72504 }
72505 VdbeBranchTaken(res!=0,2);
72506 if( res ){
72507 pc = pOp->p2 - 1;
72508 }
72509 }
72510 pCur->nullRow = 0;
@@ -72432,11 +72605,11 @@
72605 p->inVtabMethod = 0;
72606 sqlite3VtabImportErrmsg(p, pVtab);
72607 if( rc==SQLITE_OK ){
72608 res = pModule->xEof(pCur->pVtabCursor);
72609 }
72610 VdbeBranchTaken(!res,2);
72611 if( !res ){
72612 /* If there is data, jump to P2 */
72613 pc = pOp->p2 - 1;
72614 }
72615 goto check_for_interrupt;
@@ -72473,11 +72646,11 @@
72646 break;
72647 }
72648 #endif
72649
72650 #ifndef SQLITE_OMIT_VIRTUALTABLE
72651 /* Opcode: VUpdate P1 P2 P3 P4 P5
72652 ** Synopsis: data=r[P3@P2]
72653 **
72654 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72655 ** This opcode invokes the corresponding xUpdate method. P2 values
72656 ** are contiguous memory cells starting at P3 to pass to the xUpdate
@@ -72496,10 +72669,13 @@
72669 ** a row to delete.
72670 **
72671 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72672 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72673 ** is set to the value of the rowid for the row just inserted.
72674 **
72675 ** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
72676 ** apply in the case of a constraint failure on an insert or update.
72677 */
72678 case OP_VUpdate: {
72679 sqlite3_vtab *pVtab;
72680 sqlite3_module *pModule;
72681 int nArg;
@@ -72584,20 +72760,30 @@
72760 break;
72761 }
72762 #endif
72763
72764
72765 /* Opcode: Init * P2 * P4 *
72766 ** Synopsis: Start at P2
72767 **
72768 ** Programs contain a single instance of this opcode as the very first
72769 ** opcode.
72770 **
72771 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72772 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72773 ** Or if P4 is blank, use the string returned by sqlite3_sql().
72774 **
72775 ** If P2 is not zero, jump to instruction P2.
72776 */
72777 case OP_Init: { /* jump */
72778 char *zTrace;
72779 char *z;
72780
72781 if( pOp->p2 ){
72782 pc = pOp->p2 - 1;
72783 }
72784 #ifndef SQLITE_OMIT_TRACE
72785 if( db->xTrace
72786 && !p->doingRerun
72787 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72788 ){
72789 z = sqlite3VdbeExpandSql(p, zTrace);
@@ -72619,13 +72805,13 @@
72805 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72806 ){
72807 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72808 }
72809 #endif /* SQLITE_DEBUG */
72810 #endif /* SQLITE_OMIT_TRACE */
72811 break;
72812 }
 
72813
72814
72815 /* Opcode: Noop * * * * *
72816 **
72817 ** Do nothing. This instruction is often useful as a jump
@@ -72653,14 +72839,10 @@
72839 #ifdef VDBE_PROFILE
72840 {
72841 u64 elapsed = sqlite3Hwtime() - start;
72842 pOp->cycles += elapsed;
72843 pOp->cnt++;
 
 
 
 
72844 }
72845 #endif
72846
72847 /* The following code adds nothing to the actual functionality
72848 ** of the program. It is only here for testing and debugging.
@@ -72882,26 +73064,24 @@
73064 **
73065 ** The sqlite3_blob_close() function finalizes the vdbe program,
73066 ** which closes the b-tree cursor and (possibly) commits the
73067 ** transaction.
73068 */
73069 static const int iLn = __LINE__+4;
73070 static const VdbeOpList openBlob[] = {
73071 /* {OP_Transaction, 0, 0, 0}, // 0: Inserted separately */
73072 {OP_TableLock, 0, 0, 0}, /* 1: Acquire a read or write lock */
 
 
73073 /* One of the following two instructions is replaced by an OP_Noop. */
73074 {OP_OpenRead, 0, 0, 0}, /* 2: Open cursor 0 for reading */
73075 {OP_OpenWrite, 0, 0, 0}, /* 3: Open cursor 0 for read/write */
73076 {OP_Variable, 1, 1, 1}, /* 4: Push the rowid to the stack */
73077 {OP_NotExists, 0, 10, 1}, /* 5: Seek the cursor */
73078 {OP_Column, 0, 0, 1}, /* 6 */
73079 {OP_ResultRow, 1, 0, 0}, /* 7 */
73080 {OP_Goto, 0, 4, 0}, /* 8 */
73081 {OP_Close, 0, 0, 0}, /* 9 */
73082 {OP_Halt, 0, 0, 0}, /* 10 */
 
73083 };
73084
73085 int rc = SQLITE_OK;
73086 char *zErr = 0;
73087 Table *pTab;
@@ -73010,50 +73190,45 @@
73190 assert( pBlob->pStmt || db->mallocFailed );
73191 if( pBlob->pStmt ){
73192 Vdbe *v = (Vdbe *)pBlob->pStmt;
73193 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73194
73195
73196 sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags,
73197 pTab->pSchema->schema_cookie,
73198 pTab->pSchema->iGeneration);
73199 sqlite3VdbeChangeP5(v, 1);
73200 sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
 
 
 
 
 
73201
73202 /* Make sure a mutex is held on the table to be accessed */
73203 sqlite3VdbeUsesBtree(v, iDb);
73204
73205 /* Configure the OP_TableLock instruction */
73206 #ifdef SQLITE_OMIT_SHARED_CACHE
73207 sqlite3VdbeChangeToNoop(v, 1);
73208 #else
73209 sqlite3VdbeChangeP1(v, 1, iDb);
73210 sqlite3VdbeChangeP2(v, 1, pTab->tnum);
73211 sqlite3VdbeChangeP3(v, 1, flags);
73212 sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
73213 #endif
73214
73215 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
73216 ** parameter of the other to pTab->tnum. */
73217 sqlite3VdbeChangeToNoop(v, 3 - flags);
73218 sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum);
73219 sqlite3VdbeChangeP3(v, 2 + flags, iDb);
73220
73221 /* Configure the number of columns. Configure the cursor to
73222 ** think that the table has one more column than it really
73223 ** does. An OP_Column to retrieve this imaginary column will
73224 ** always return an SQL NULL. This is useful because it means
73225 ** we can invoke OP_Column to fill in the vdbe cursors type
73226 ** and offset cache without causing any IO.
73227 */
73228 sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73229 sqlite3VdbeChangeP2(v, 6, pTab->nCol);
73230 if( !db->mallocFailed ){
73231 pParse->nVar = 1;
73232 pParse->nMem = 1;
73233 pParse->nTab = 1;
73234 sqlite3VdbeMakeReady(v, pParse);
@@ -75317,12 +75492,12 @@
75492 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75493
75494 /*
75495 ** Perhaps the name is a reference to the ROWID
75496 */
75497 if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol)
75498 && HasRowid(pMatch->pTab) ){
75499 cnt = 1;
75500 pExpr->iColumn = -1; /* IMP: R-44911-55124 */
75501 pExpr->affinity = SQLITE_AFF_INTEGER;
75502 }
75503
@@ -77449,11 +77624,10 @@
77624 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
77625 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
77626 pNew->iLimit = 0;
77627 pNew->iOffset = 0;
77628 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
 
77629 pNew->addrOpenEphm[0] = -1;
77630 pNew->addrOpenEphm[1] = -1;
77631 pNew->addrOpenEphm[2] = -1;
77632 pNew->nSelectRow = p->nSelectRow;
77633 pNew->pWith = withDup(db, p->pWith);
@@ -77759,28 +77933,10 @@
77933 default:
77934 return 1;
77935 }
77936 }
77937
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77938 /*
77939 ** Return TRUE if the given expression is a constant which would be
77940 ** unchanged by OP_Affinity with the affinity given in the second
77941 ** argument.
77942 **
@@ -77973,11 +78129,11 @@
78129 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
78130 pTab = p->pSrc->a[0].pTab;
78131 pExpr = p->pEList->a[0].pExpr;
78132 iCol = (i16)pExpr->iColumn;
78133
78134 /* Code an OP_Transaction and OP_TableLock for <table>. */
78135 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
78136 sqlite3CodeVerifySchema(pParse, iDb);
78137 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
78138
78139 /* This function is only called from two places. In both cases the vdbe
@@ -77984,13 +78140,12 @@
78140 ** has already been allocated. So assume sqlite3GetVdbe() is always
78141 ** successful here.
78142 */
78143 assert(v);
78144 if( iCol<0 ){
78145 int iAddr = sqlite3CodeOnce(pParse);
78146 VdbeCoverage(v);
 
78147
78148 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
78149 eType = IN_INDEX_ROWID;
78150
78151 sqlite3VdbeJumpHere(v, iAddr);
@@ -78011,22 +78166,22 @@
78166 for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
78167 if( (pIdx->aiColumn[0]==iCol)
78168 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
78169 && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
78170 ){
78171 int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
78172 sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
78173 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
78174 VdbeComment((v, "%s", pIdx->zName));
78175 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
78176 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
78177
 
78178 if( prNotFound && !pTab->aCol[iCol].notNull ){
78179 *prNotFound = ++pParse->nMem;
78180 sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
78181 }
78182 sqlite3VdbeJumpHere(v, iAddr);
78183 }
78184 }
78185 }
78186 }
78187
@@ -78111,11 +78266,11 @@
78266 **
78267 ** If all of the above are false, then we can run this code just once
78268 ** save the results, and reuse the same result on subsequent invocations.
78269 */
78270 if( !ExprHasProperty(pExpr, EP_VarSelect) ){
78271 testAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
78272 }
78273
78274 #ifndef SQLITE_OMIT_EXPLAIN
78275 if( pParse->explain==2 ){
78276 char *zMsg = sqlite3MPrintf(
@@ -78152,11 +78307,10 @@
78307 ** 'x' nor the SELECT... statement are columns, then numeric affinity
78308 ** is used.
78309 */
78310 pExpr->iTable = pParse->nTab++;
78311 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
 
78312 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
78313
78314 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
78315 /* Case 1: expr IN (SELECT ...)
78316 **
@@ -78228,10 +78382,11 @@
78382 }else{
78383 r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
78384 if( isRowid ){
78385 sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
78386 sqlite3VdbeCurrentAddr(v)+2);
78387 VdbeCoverage(v);
78388 sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
78389 }else{
78390 sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
78391 sqlite3ExprCacheAffinityChange(pParse, r3, 1);
78392 sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
@@ -78351,23 +78506,25 @@
78506 ** on whether the RHS is empty or not, respectively.
78507 */
78508 if( destIfNull==destIfFalse ){
78509 /* Shortcut for the common case where the false and NULL outcomes are
78510 ** the same. */
78511 sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
78512 }else{
78513 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
78514 sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
78515 VdbeCoverage(v);
78516 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
78517 sqlite3VdbeJumpHere(v, addr1);
78518 }
78519
78520 if( eType==IN_INDEX_ROWID ){
78521 /* In this case, the RHS is the ROWID of table b-tree
78522 */
78523 sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); VdbeCoverage(v);
78524 sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
78525 VdbeCoverage(v);
78526 }else{
78527 /* In this case, the RHS is an index b-tree.
78528 */
78529 sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
78530
@@ -78384,42 +78541,40 @@
78541 **
78542 ** Also run this branch if NULL is equivalent to FALSE
78543 ** for this particular IN operator.
78544 */
78545 sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1);
78546 VdbeCoverage(v);
78547 }else{
78548 /* In this branch, the RHS of the IN might contain a NULL and
78549 ** the presence of a NULL on the RHS makes a difference in the
78550 ** outcome.
78551 */
78552 int j1, j2;
78553
78554 /* First check to see if the LHS is contained in the RHS. If so,
78555 ** then the presence of NULLs in the RHS does not matter, so jump
78556 ** over all of the code that follows.
78557 */
78558 j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
78559 VdbeCoverage(v);
78560
78561 /* Here we begin generating code that runs if the LHS is not
78562 ** contained within the RHS. Generate additional code that
78563 ** tests the RHS for NULLs. If the RHS contains a NULL then
78564 ** jump to destIfNull. If there are no NULLs in the RHS then
78565 ** jump to destIfFalse.
78566 */
78567 sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull); VdbeCoverage(v);
78568 sqlite3VdbeAddOp2(v, OP_IfNot, rRhsHasNull, destIfFalse); VdbeCoverage(v);
78569 j2 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78570 VdbeCoverage(v);
78571 sqlite3VdbeAddOp2(v, OP_Integer, 0, rRhsHasNull);
78572 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
78573 sqlite3VdbeJumpHere(v, j2);
78574 sqlite3VdbeAddOp2(v, OP_Integer, 1, rRhsHasNull);
78575 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
 
 
 
 
78576
78577 /* The OP_Found at the top of this branch jumps here when true,
78578 ** causing the overall IN expression evaluation to fall through.
78579 */
78580 sqlite3VdbeJumpHere(v, j1);
@@ -78936,26 +79091,20 @@
79091 case TK_LE:
79092 case TK_GT:
79093 case TK_GE:
79094 case TK_NE:
79095 case TK_EQ: {
 
 
 
 
 
 
 
 
 
 
 
 
79096 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79097 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79098 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
79099 r1, r2, inReg, SQLITE_STOREP2);
79100 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
79101 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
79102 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
79103 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
79104 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
79105 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
79106 testcase( regFree1==0 );
79107 testcase( regFree2==0 );
79108 break;
79109 }
79110 case TK_IS:
@@ -78965,10 +79114,12 @@
79114 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79115 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79116 op = (op==TK_IS) ? TK_EQ : TK_NE;
79117 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
79118 r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
79119 VdbeCoverageIf(v, op==TK_EQ);
79120 VdbeCoverageIf(v, op==TK_NE);
79121 testcase( regFree1==0 );
79122 testcase( regFree2==0 );
79123 break;
79124 }
79125 case TK_AND:
@@ -78981,32 +79132,21 @@
79132 case TK_BITOR:
79133 case TK_SLASH:
79134 case TK_LSHIFT:
79135 case TK_RSHIFT:
79136 case TK_CONCAT: {
79137 assert( TK_AND==OP_And ); testcase( op==TK_AND );
79138 assert( TK_OR==OP_Or ); testcase( op==TK_OR );
79139 assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
79140 assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
79141 assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
79142 assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
79143 assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
79144 assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
79145 assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
79146 assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
79147 assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
 
 
 
 
 
 
 
 
 
 
 
79148 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79149 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79150 sqlite3VdbeAddOp3(v, op, r2, r1, target);
79151 testcase( regFree1==0 );
79152 testcase( regFree2==0 );
@@ -79034,31 +79174,29 @@
79174 inReg = target;
79175 break;
79176 }
79177 case TK_BITNOT:
79178 case TK_NOT: {
79179 assert( TK_BITNOT==OP_BitNot ); testcase( op==TK_BITNOT );
79180 assert( TK_NOT==OP_Not ); testcase( op==TK_NOT );
 
 
79181 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79182 testcase( regFree1==0 );
79183 inReg = target;
79184 sqlite3VdbeAddOp2(v, op, r1, inReg);
79185 break;
79186 }
79187 case TK_ISNULL:
79188 case TK_NOTNULL: {
79189 int addr;
79190 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
79191 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
 
 
79192 sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
79193 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79194 testcase( regFree1==0 );
79195 addr = sqlite3VdbeAddOp1(v, op, r1);
79196 VdbeCoverageIf(v, op==TK_ISNULL);
79197 VdbeCoverageIf(v, op==TK_NOTNULL);
79198 sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
79199 sqlite3VdbeJumpHere(v, addr);
79200 break;
79201 }
79202 case TK_AGG_FUNCTION: {
@@ -79106,10 +79244,11 @@
79244 int endCoalesce = sqlite3VdbeMakeLabel(v);
79245 assert( nFarg>=2 );
79246 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
79247 for(i=1; i<nFarg; i++){
79248 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
79249 VdbeCoverage(v);
79250 sqlite3ExprCacheRemove(pParse, target, 1);
79251 sqlite3ExprCachePush(pParse);
79252 sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
79253 sqlite3ExprCachePop(pParse, 1);
79254 }
@@ -79243,17 +79382,18 @@
79382 testcase( regFree1==0 );
79383 testcase( regFree2==0 );
79384 r3 = sqlite3GetTempReg(pParse);
79385 r4 = sqlite3GetTempReg(pParse);
79386 codeCompare(pParse, pLeft, pRight, OP_Ge,
79387 r1, r2, r3, SQLITE_STOREP2); VdbeCoverage(v);
79388 pLItem++;
79389 pRight = pLItem->pExpr;
79390 sqlite3ReleaseTempReg(pParse, regFree2);
79391 r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
79392 testcase( regFree2==0 );
79393 codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
79394 VdbeCoverage(v);
79395 sqlite3VdbeAddOp3(v, OP_And, r3, r4, target);
79396 sqlite3ReleaseTempReg(pParse, r3);
79397 sqlite3ReleaseTempReg(pParse, r4);
79398 break;
79399 }
@@ -79416,10 +79556,11 @@
79556 }
79557 assert( !ExprHasProperty(pExpr, EP_IntValue) );
79558 if( pExpr->affinity==OE_Ignore ){
79559 sqlite3VdbeAddOp4(
79560 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
79561 VdbeCoverage(v);
79562 }else{
79563 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
79564 pExpr->affinity, pExpr->u.zToken, 0, 0);
79565 }
79566
@@ -79503,11 +79644,11 @@
79644 /*
79645 ** Generate code that will evaluate expression pExpr and store the
79646 ** results in register target. The results are guaranteed to appear
79647 ** in register target.
79648 */
79649 SQLITE_PRIVATE void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
79650 int inReg;
79651
79652 assert( target>0 && target<=pParse->nMem );
79653 if( pExpr && pExpr->op==TK_REGISTER ){
79654 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
@@ -79516,11 +79657,24 @@
79657 assert( pParse->pVdbe || pParse->db->mallocFailed );
79658 if( inReg!=target && pParse->pVdbe ){
79659 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
79660 }
79661 }
79662 }
79663
79664 /*
79665 ** Generate code that will evaluate expression pExpr and store the
79666 ** results in register target. The results are guaranteed to appear
79667 ** in register target. If the expression is constant, then this routine
79668 ** might choose to code the expression at initialization time.
79669 */
79670 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
79671 if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
79672 sqlite3ExprCodeAtInit(pParse, pExpr, target, 0);
79673 }else{
79674 sqlite3ExprCode(pParse, pExpr, target);
79675 }
79676 }
79677
79678 /*
79679 ** Generate code that evalutes the given expression and puts the result
79680 ** in register target.
@@ -79531,29 +79685,20 @@
79685 **
79686 ** This routine is used for expressions that are used multiple
79687 ** times. They are evaluated once and the results of the expression
79688 ** are reused.
79689 */
79690 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79691 Vdbe *v = pParse->pVdbe;
79692 int iMem;
79693
79694 assert( target>0 );
79695 assert( pExpr->op!=TK_REGISTER );
79696 sqlite3ExprCode(pParse, pExpr, target);
79697 iMem = ++pParse->nMem;
79698 sqlite3VdbeAddOp2(v, OP_Copy, target, iMem);
79699 exprToRegister(pExpr, iMem);
 
 
 
 
 
 
 
 
 
79700 }
79701
79702 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
79703 /*
79704 ** Generate a human-readable explanation of an expression tree.
@@ -79984,27 +80129,21 @@
80129 case TK_LE:
80130 case TK_GT:
80131 case TK_GE:
80132 case TK_NE:
80133 case TK_EQ: {
 
 
 
 
 
 
 
 
 
 
 
 
80134 testcase( jumpIfNull==0 );
80135 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80136 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80137 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80138 r1, r2, dest, jumpIfNull);
80139 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80140 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80141 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80142 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80143 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80144 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
80145 testcase( regFree1==0 );
80146 testcase( regFree2==0 );
80147 break;
80148 }
80149 case TK_IS:
@@ -80014,22 +80153,24 @@
80153 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80154 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80155 op = (op==TK_IS) ? TK_EQ : TK_NE;
80156 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80157 r1, r2, dest, SQLITE_NULLEQ);
80158 VdbeCoverageIf(v, op==TK_EQ);
80159 VdbeCoverageIf(v, op==TK_NE);
80160 testcase( regFree1==0 );
80161 testcase( regFree2==0 );
80162 break;
80163 }
80164 case TK_ISNULL:
80165 case TK_NOTNULL: {
80166 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
80167 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
 
 
80168 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80169 sqlite3VdbeAddOp2(v, op, r1, dest);
80170 VdbeCoverageIf(v, op==TK_ISNULL);
80171 VdbeCoverageIf(v, op==TK_NOTNULL);
80172 testcase( regFree1==0 );
80173 break;
80174 }
80175 case TK_BETWEEN: {
80176 testcase( jumpIfNull==0 );
@@ -80052,10 +80193,11 @@
80193 }else if( exprAlwaysFalse(pExpr) ){
80194 /* No-op */
80195 }else{
80196 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80197 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
80198 VdbeCoverage(v);
80199 testcase( regFree1==0 );
80200 testcase( jumpIfNull==0 );
80201 }
80202 break;
80203 }
@@ -80143,21 +80285,21 @@
80285 case TK_LE:
80286 case TK_GT:
80287 case TK_GE:
80288 case TK_NE:
80289 case TK_EQ: {
 
 
 
 
 
 
80290 testcase( jumpIfNull==0 );
80291 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80292 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80293 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80294 r1, r2, dest, jumpIfNull);
80295 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80296 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80297 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80298 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80299 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80300 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
80301 testcase( regFree1==0 );
80302 testcase( regFree2==0 );
80303 break;
80304 }
80305 case TK_IS:
@@ -80167,20 +80309,22 @@
80309 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80310 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80311 op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
80312 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80313 r1, r2, dest, SQLITE_NULLEQ);
80314 VdbeCoverageIf(v, op==TK_EQ);
80315 VdbeCoverageIf(v, op==TK_NE);
80316 testcase( regFree1==0 );
80317 testcase( regFree2==0 );
80318 break;
80319 }
80320 case TK_ISNULL:
80321 case TK_NOTNULL: {
 
 
80322 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80323 sqlite3VdbeAddOp2(v, op, r1, dest);
80324 testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
80325 testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
80326 testcase( regFree1==0 );
80327 break;
80328 }
80329 case TK_BETWEEN: {
80330 testcase( jumpIfNull==0 );
@@ -80205,10 +80349,11 @@
80349 }else if( exprAlwaysTrue(pExpr) ){
80350 /* no-op */
80351 }else{
80352 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80353 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80354 VdbeCoverage(v);
80355 testcase( regFree1==0 );
80356 testcase( jumpIfNull==0 );
80357 }
80358 break;
80359 }
@@ -80751,12 +80896,12 @@
80896 len = sqlite3GetToken(zCsr, &token);
80897 } while( token==TK_SPACE );
80898 assert( len>0 );
80899 } while( token!=TK_LP && token!=TK_USING );
80900
80901 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
80902 zSql, zTableName, tname.z+tname.n);
80903 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
80904 }
80905 }
80906
80907 /*
@@ -80804,11 +80949,11 @@
80949 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
80950 if( zParent==0 ) break;
80951 sqlite3Dequote(zParent);
80952 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
80953 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
80954 (zOutput?zOutput:""), (int)(z-zInput), zInput, (const char *)zNew
80955 );
80956 sqlite3DbFree(db, zOutput);
80957 zOutput = zOut;
80958 zInput = &z[n];
80959 }
@@ -80890,12 +81035,12 @@
81035 } while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
81036
81037 /* Variable tname now contains the token that is the old table-name
81038 ** in the CREATE TRIGGER statement.
81039 */
81040 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
81041 zSql, zTableName, tname.z+tname.n);
81042 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
81043 }
81044 }
81045 #endif /* !SQLITE_OMIT_TRIGGER */
81046
@@ -81143,11 +81288,11 @@
81288 pVTab = 0;
81289 }
81290 }
81291 #endif
81292
81293 /* Begin a transaction for database iDb.
81294 ** Then modify the schema cookie (since the ALTER TABLE modifies the
81295 ** schema). Open a statement transaction if the table is a virtual
81296 ** table.
81297 */
81298 v = sqlite3GetVdbe(pParse);
@@ -81279,10 +81424,11 @@
81424 int j1;
81425 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
81426 sqlite3VdbeUsesBtree(v, iDb);
81427 sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
81428 j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
81429 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
81430 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
81431 sqlite3VdbeJumpHere(v, j1);
81432 sqlite3ReleaseTempReg(pParse, r1);
81433 sqlite3ReleaseTempReg(pParse, r2);
81434 }
@@ -82579,10 +82725,11 @@
82725 ** regChng = 0
82726 ** goto next_push_0;
82727 **
82728 */
82729 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
82730 VdbeCoverage(v);
82731 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
82732 addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
82733
82734 /*
82735 ** next_row:
@@ -82600,10 +82747,11 @@
82747 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
82748 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
82749 aGotoChng[i] =
82750 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
82751 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
82752 VdbeCoverage(v);
82753 }
82754 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
82755 aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
82756
82757 /*
@@ -82646,11 +82794,11 @@
82794 #endif
82795 assert( regChng==(regStat4+1) );
82796 sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
82797 sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
82798 sqlite3VdbeChangeP5(v, 2+IsStat34);
82799 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
82800
82801 /* Add the entry to the stat1 table. */
82802 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
82803 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82804 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
@@ -82673,14 +82821,16 @@
82821 pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
82822
82823 addrNext = sqlite3VdbeCurrentAddr(v);
82824 callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
82825 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
82826 VdbeCoverage(v);
82827 callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
82828 callStatGet(v, regStat4, STAT_GET_NLT, regLt);
82829 callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
82830 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
82831 VdbeCoverage(v);
82832 #ifdef SQLITE_ENABLE_STAT3
82833 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
82834 pIdx->aiColumn[0], regSample);
82835 #else
82836 for(i=0; i<nCol; i++){
@@ -82687,11 +82837,11 @@
82837 i16 iCol = pIdx->aiColumn[i];
82838 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
82839 }
82840 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
82841 #endif
82842 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
82843 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
82844 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
82845 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
82846 sqlite3VdbeJumpHere(v, addrIsNull);
82847 }
@@ -82707,11 +82857,11 @@
82857 ** name and the row count as the content.
82858 */
82859 if( pOnlyIdx==0 && needTableCnt ){
82860 VdbeComment((v, "%s", pTab->zName));
82861 sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
82862 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
82863 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
82864 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82865 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
82866 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
82867 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -84245,24 +84395,26 @@
84395 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
84396 ** set for each database that is used. Generate code to start a
84397 ** transaction on each used database and to verify the schema cookie
84398 ** on each used database.
84399 */
84400 if( db->mallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){
84401 yDbMask mask;
84402 int iDb, i;
84403 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
84404 sqlite3VdbeJumpHere(v, 0);
84405 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
84406 if( (mask & pParse->cookieMask)==0 ) continue;
84407 sqlite3VdbeUsesBtree(v, iDb);
84408 sqlite3VdbeAddOp4Int(v,
84409 OP_Transaction, /* Opcode */
84410 iDb, /* P1 */
84411 (mask & pParse->writeMask)!=0, /* P2 */
84412 pParse->cookieValue[iDb], /* P3 */
84413 db->aDb[iDb].pSchema->iGeneration /* P4 */
84414 );
84415 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
84416 }
84417 #ifndef SQLITE_OMIT_VIRTUALTABLE
84418 for(i=0; i<pParse->nVtabLock; i++){
84419 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84420 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
@@ -84279,21 +84431,20 @@
84431 /* Initialize any AUTOINCREMENT data structures required.
84432 */
84433 sqlite3AutoincrementBegin(pParse);
84434
84435 /* Code constant expressions that where factored out of inner loops */
 
84436 if( pParse->pConstExpr ){
84437 ExprList *pEL = pParse->pConstExpr;
84438 pParse->okConstFactor = 0;
84439 for(i=0; i<pEL->nExpr; i++){
84440 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
84441 }
84442 }
84443
84444 /* Finally, jump back to the beginning of the executable code. */
84445 sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
84446 }
84447 }
84448
84449
84450 /* Get the VDBE program ready for execution
@@ -84312,11 +84463,10 @@
84463 pParse->nTab = 0;
84464 pParse->nMem = 0;
84465 pParse->nSet = 0;
84466 pParse->nVar = 0;
84467 pParse->cookieMask = 0;
 
84468 }
84469
84470 /*
84471 ** Run the parser and code generator recursively in order to generate
84472 ** code for the SQL statement given onto the end of the pParse context
@@ -85044,11 +85194,11 @@
85194 reg1 = pParse->regRowid = ++pParse->nMem;
85195 reg2 = pParse->regRoot = ++pParse->nMem;
85196 reg3 = ++pParse->nMem;
85197 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
85198 sqlite3VdbeUsesBtree(v, iDb);
85199 j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
85200 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
85201 1 : SQLITE_MAX_FILE_FORMAT;
85202 sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
85203 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
85204 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
@@ -86771,40 +86921,40 @@
86921 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
86922
86923 /* Open the table. Loop through all rows of the table, inserting index
86924 ** records into the sorter. */
86925 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86926 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
86927 regRecord = sqlite3GetTempReg(pParse);
86928
86929 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
86930 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
86931 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86932 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
86933 sqlite3VdbeJumpHere(v, addr1);
86934 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
86935 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86936 (char *)pKey, P4_KEYINFO);
86937 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86938
86939 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
86940 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
86941 if( pIndex->onError!=OE_None && pKey!=0 ){
86942 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
86943 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
86944 addr2 = sqlite3VdbeCurrentAddr(v);
86945 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86946 pKey->nField - pIndex->nKeyCol); VdbeCoverage(v);
86947 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
86948 }else{
86949 addr2 = sqlite3VdbeCurrentAddr(v);
86950 }
86951 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
86952 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
86953 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
86954 sqlite3ReleaseTempReg(pParse, regRecord);
86955 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
86956 sqlite3VdbeJumpHere(v, addr1);
86957
86958 sqlite3VdbeAddOp1(v, OP_Close, iTab);
86959 sqlite3VdbeAddOp1(v, OP_Close, iIdx);
86960 sqlite3VdbeAddOp1(v, OP_Close, iSorter);
@@ -87921,63 +88071,30 @@
88071 }
88072 return 0;
88073 }
88074
88075 /*
88076 ** Record the fact that the schema cookie will need to be verified
88077 ** for database iDb. The code to actually verify the schema cookie
88078 ** will occur at the end of the top-level VDBE and will be generated
88079 ** later, by sqlite3FinishCoding().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88080 */
88081 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
88082 Parse *pToplevel = sqlite3ParseToplevel(pParse);
88083 sqlite3 *db = pToplevel->db;
88084 yDbMask mask;
88085
88086 assert( iDb>=0 && iDb<db->nDb );
88087 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
88088 assert( iDb<SQLITE_MAX_ATTACHED+2 );
88089 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88090 mask = ((yDbMask)1)<<iDb;
88091 if( (pToplevel->cookieMask & mask)==0 ){
88092 pToplevel->cookieMask |= mask;
88093 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
88094 if( !OMIT_TEMPDB && iDb==1 ){
88095 sqlite3OpenTempDatabase(pToplevel);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88096 }
88097 }
88098 }
88099
88100 /*
@@ -88944,25 +89061,20 @@
89061 SelectDest dest;
89062 Select *pSel;
89063 SrcList *pFrom;
89064 sqlite3 *db = pParse->db;
89065 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
 
89066 pWhere = sqlite3ExprDup(db, pWhere, 0);
89067 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
 
89068 if( pFrom ){
89069 assert( pFrom->nSrc==1 );
89070 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
89071 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
89072 assert( pFrom->a[0].pOn==0 );
89073 assert( pFrom->a[0].pUsing==0 );
89074 }
 
89075 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
 
 
89076 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
89077 sqlite3Select(pParse, pSel, &dest);
89078 sqlite3SelectDelete(db, pSel);
89079 }
89080 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -89295,11 +89407,11 @@
89407 }else if( pPk ){
89408 /* Construct a composite key for the row to be deleted and remember it */
89409 iKey = ++pParse->nMem;
89410 nKey = 0; /* Zero tells OP_Found to use a composite key */
89411 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89412 sqlite3IndexAffinityStr(v, pPk), nPk);
89413 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
89414 }else{
89415 /* Get the rowid of the row to be deleted and remember it in the RowSet */
89416 nKey = 1; /* OP_Seek always uses a single rowid */
89417 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -89333,17 +89445,19 @@
89445 /* Just one row. Hence the top-of-loop is a no-op */
89446 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
89447 if( aToOpen[iDataCur-iTabCur] ){
89448 assert( pPk!=0 );
89449 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
89450 VdbeCoverage(v);
89451 }
89452 }else if( pPk ){
89453 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
89454 sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
89455 assert( nKey==0 ); /* OP_Found will use a composite key */
89456 }else{
89457 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
89458 VdbeCoverage(v);
89459 assert( nKey==1 );
89460 }
89461
89462 /* Delete the row */
89463 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -89363,11 +89477,11 @@
89477
89478 /* End of the loop over all rowids/primary-keys. */
89479 if( okOnePass ){
89480 sqlite3VdbeResolveLabel(v, addrBypass);
89481 }else if( pPk ){
89482 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
89483 sqlite3VdbeJumpHere(v, addrLoop);
89484 }else{
89485 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
89486 sqlite3VdbeJumpHere(v, addrLoop);
89487 }
@@ -89461,11 +89575,15 @@
89575 /* Seek cursor iCur to the row to delete. If this row no longer exists
89576 ** (this can happen if a trigger program has already deleted it), do
89577 ** not attempt to delete it or fire any DELETE triggers. */
89578 iLabel = sqlite3VdbeMakeLabel(v);
89579 opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89580 if( !bNoSeek ){
89581 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89582 VdbeCoverageIf(v, opSeek==OP_NotExists);
89583 VdbeCoverageIf(v, opSeek==OP_NotFound);
89584 }
89585
89586 /* If there are any triggers to fire, allocate a range of registers to
89587 ** use for the old.* references in the triggers. */
89588 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89589 u32 mask; /* Mask of OLD.* columns in use */
@@ -89503,10 +89621,12 @@
89621 ** the cursor or of already deleted the row that the cursor was
89622 ** pointing to.
89623 */
89624 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89625 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89626 VdbeCoverageIf(v, opSeek==OP_NotExists);
89627 VdbeCoverageIf(v, opSeek==OP_NotFound);
89628 }
89629
89630 /* Do FK processing. This call checks that any FK constraints that
89631 ** refer to this table (i.e. constraints attached to other tables)
89632 ** are not violated by deleting this row. */
@@ -91760,14 +91880,15 @@
91880 ** Check if any of the key columns in the child table row are NULL. If
91881 ** any are, then the constraint is considered satisfied. No need to
91882 ** search for a matching row in the parent table. */
91883 if( nIncr<0 ){
91884 sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
91885 VdbeCoverage(v);
91886 }
91887 for(i=0; i<pFKey->nCol; i++){
91888 int iReg = aiCol[i] + regData + 1;
91889 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v);
91890 }
91891
91892 if( isIgnore==0 ){
91893 if( pIdx==0 ){
91894 /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
@@ -91780,21 +91901,23 @@
91901 ** is no matching parent key. Before using MustBeInt, make a copy of
91902 ** the value. Otherwise, the value inserted into the child key column
91903 ** will have INTEGER affinity applied to it, which may not be correct. */
91904 sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
91905 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
91906 VdbeCoverage(v);
91907
91908 /* If the parent table is the same as the child table, and we are about
91909 ** to increment the constraint-counter (i.e. this is an INSERT operation),
91910 ** then check if the row being inserted matches itself. If so, do not
91911 ** increment the constraint-counter. */
91912 if( pTab==pFKey->pFrom && nIncr==1 ){
91913 sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
91914 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
91915 }
91916
91917 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
91918 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
91919 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91920 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
91921 sqlite3VdbeJumpHere(v, iMustBeInt);
91922 sqlite3ReleaseTempReg(pParse, regTemp);
91923 }else{
@@ -91826,19 +91949,19 @@
91949 assert( aiCol[i]!=pTab->iPKey );
91950 if( pIdx->aiColumn[i]==pTab->iPKey ){
91951 /* The parent key is a composite key that includes the IPK column */
91952 iParent = regData;
91953 }
91954 sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
91955 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
91956 }
91957 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91958 }
91959
91960 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
91961 sqlite3IndexAffinityStr(v,pIdx), nCol);
91962 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
91963
91964 sqlite3ReleaseTempReg(pParse, regRec);
91965 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
91966 }
91967 }
@@ -91972,10 +92095,11 @@
92095 assert( pIdx!=0 || pFKey->nCol==1 );
92096 assert( pIdx!=0 || HasRowid(pTab) );
92097
92098 if( nIncr<0 ){
92099 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
92100 VdbeCoverage(v);
92101 }
92102
92103 /* Create an Expr object representing an SQL expression like:
92104 **
92105 ** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
@@ -92134,11 +92258,11 @@
92258 for(p=pTab->pFKey; p; p=p->pNextFrom){
92259 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
92260 }
92261 if( !p ) return;
92262 iSkip = sqlite3VdbeMakeLabel(v);
92263 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
92264 }
92265
92266 pParse->disableTriggers = 1;
92267 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
92268 pParse->disableTriggers = 0;
@@ -92152,10 +92276,11 @@
92276 ** the statement transaction will not be rolled back even if FK
92277 ** constraints are violated.
92278 */
92279 if( (db->flags & SQLITE_DeferFKs)==0 ){
92280 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
92281 VdbeCoverage(v);
92282 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
92283 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
92284 }
92285
92286 if( iSkip ){
@@ -92311,11 +92436,11 @@
92436 */
92437 Vdbe *v = sqlite3GetVdbe(pParse);
92438 int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
92439 for(i=0; i<pFKey->nCol; i++){
92440 int iReg = pFKey->aCol[i].iFrom + regOld + 1;
92441 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); VdbeCoverage(v);
92442 }
92443 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
92444 }
92445 continue;
92446 }
@@ -92878,69 +93003,74 @@
93003
93004 return pIdx->zColAff;
93005 }
93006
93007 /*
93008 ** Compute the affinity string for table pTab, if it has not already been
93009 ** computed. As an optimization, omit trailing SQLITE_AFF_NONE affinities.
93010 **
93011 ** If the affinity exists (if it is no entirely SQLITE_AFF_NONE values and
93012 ** if iReg>0 then code an OP_Affinity opcode that will set the affinities
93013 ** for register iReg and following. Or if affinities exists and iReg==0,
93014 ** then just set the P4 operand of the previous opcode (which should be
93015 ** an OP_MakeRecord) to the affinity string.
93016 **
93017 ** A column affinity string has one character column:
93018 **
93019 ** Character Column affinity
93020 ** ------------------------------
93021 ** 'a' TEXT
93022 ** 'b' NONE
93023 ** 'c' NUMERIC
93024 ** 'd' INTEGER
93025 ** 'e' REAL
93026 */
93027 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
93028 int i;
93029 char *zColAff = pTab->zColAff;
93030 if( zColAff==0 ){
 
 
 
 
 
 
 
93031 sqlite3 *db = sqlite3VdbeDb(v);
 
93032 zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
93033 if( !zColAff ){
93034 db->mallocFailed = 1;
93035 return;
93036 }
93037
93038 for(i=0; i<pTab->nCol; i++){
93039 zColAff[i] = pTab->aCol[i].affinity;
93040 }
93041 do{
93042 zColAff[i--] = 0;
93043 }while( i>=0 && zColAff[i]==SQLITE_AFF_NONE );
93044 pTab->zColAff = zColAff;
93045 }
93046 i = sqlite3Strlen30(zColAff);
93047 if( i ){
93048 if( iReg ){
93049 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
93050 }else{
93051 sqlite3VdbeChangeP4(v, -1, zColAff, i);
93052 }
93053 }
93054 }
93055
93056 /*
93057 ** Return non-zero if the table pTab in database iDb or any of its indices
93058 ** have been opened at any point in the VDBE program beginning at location
93059 ** iStartAddr throught the end of the program. This is used to see if
93060 ** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
93061 ** run without using temporary table for the results of the SELECT.
93062 */
93063 static int readsTable(Parse *p, int iDb, Table *pTab){
93064 Vdbe *v = sqlite3GetVdbe(p);
93065 int i;
93066 int iEnd = sqlite3VdbeCurrentAddr(v);
93067 #ifndef SQLITE_OMIT_VIRTUALTABLE
93068 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
93069 #endif
93070
93071 for(i=1; i<iEnd; i++){
93072 VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
93073 assert( pOp!=0 );
93074 if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
93075 Index *pIndex;
93076 int tnum = pOp->p2;
@@ -93037,18 +93167,18 @@
93167 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93168 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
93169 sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
93170 addr = sqlite3VdbeCurrentAddr(v);
93171 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
93172 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
93173 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
93174 sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
93175 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
93176 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
93177 sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
93178 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
93179 sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
93180 sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
93181 sqlite3VdbeAddOp0(v, OP_Close);
93182 }
93183 }
93184
@@ -93079,29 +93209,20 @@
93209 sqlite3 *db = pParse->db;
93210
93211 assert( v );
93212 for(p = pParse->pAinc; p; p = p->pNext){
93213 Db *pDb = &db->aDb[p->iDb];
93214 int j1;
93215 int iRec;
93216 int memId = p->regCtr;
93217
93218 iRec = sqlite3GetTempReg(pParse);
93219 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93220 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
93221 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); VdbeCoverage(v);
 
 
 
 
 
93222 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
 
 
 
93223 sqlite3VdbeJumpHere(v, j1);
 
93224 sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec);
93225 sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1);
93226 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
93227 sqlite3VdbeAddOp0(v, OP_Close);
93228 sqlite3ReleaseTempReg(pParse, iRec);
@@ -93113,101 +93234,10 @@
93234 ** above are all no-ops
93235 */
93236 # define autoIncBegin(A,B,C) (0)
93237 # define autoIncStep(A,B,C)
93238 #endif /* SQLITE_OMIT_AUTOINCREMENT */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93239
93240
93241 /* Forward declaration */
93242 static int xferOptimization(
93243 Parse *pParse, /* Parser context */
@@ -93268,25 +93298,21 @@
93298 **
93299 ** The 3rd template is for when the second template does not apply
93300 ** and the SELECT clause does not read from <table> at any time.
93301 ** The generated code follows this template:
93302 **
 
93303 ** X <- A
93304 ** goto B
93305 ** A: setup for the SELECT
93306 ** loop over the rows in the SELECT
93307 ** load values into registers R..R+n
93308 ** yield X
93309 ** end loop
93310 ** cleanup after the SELECT
93311 ** end-coroutine X
 
 
93312 ** B: open write cursor to <table> and its indices
93313 ** C: yield X, at EOF goto D
 
93314 ** insert the select result into <table> from R..R+n
93315 ** goto C
93316 ** D: cleanup
93317 **
93318 ** The 4th template is used if the insert statement takes its
@@ -93293,25 +93319,21 @@
93319 ** values from a SELECT but the data is being inserted into a table
93320 ** that is also read as part of the SELECT. In the third form,
93321 ** we have to use a intermediate table to store the results of
93322 ** the select. The template is like this:
93323 **
 
93324 ** X <- A
93325 ** goto B
93326 ** A: setup for the SELECT
93327 ** loop over the tables in the SELECT
93328 ** load value into register R..R+n
93329 ** yield X
93330 ** end loop
93331 ** cleanup after the SELECT
93332 ** end co-routine R
 
 
93333 ** B: open temp table
93334 ** L: yield X, at EOF goto M
 
93335 ** insert row from R..R+n into temp table
93336 ** goto L
93337 ** M: open write cursor to <table> and its indices
93338 ** rewind temp table
93339 ** C: loop over rows of intermediate table
@@ -93337,30 +93359,29 @@
93359 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
93360 int iDataCur = 0; /* VDBE cursor that is the main data repository */
93361 int iIdxCur = 0; /* First index cursor */
93362 int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
93363 int endOfLoop; /* Label for the end of the insertion loop */
 
93364 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
93365 int addrInsTop = 0; /* Jump to label "D" */
93366 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
 
93367 SelectDest dest; /* Destination for SELECT on rhs of INSERT */
93368 int iDb; /* Index of database holding TABLE */
93369 Db *pDb; /* The database containing table being inserted into */
93370 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
93371 u8 appendFlag = 0; /* True if the insert is likely to be an append */
93372 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
93373 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
93374 ExprList *pList = 0; /* List of VALUES() to be inserted */
93375
93376 /* Register allocations */
93377 int regFromSelect = 0;/* Base register for data coming from SELECT */
93378 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
93379 int regRowCount = 0; /* Memory cell used for the row counter */
93380 int regIns; /* Block of regs holding rowid+data being inserted */
93381 int regRowid; /* registers holding insert rowid */
93382 int regData; /* register holding first column to insert */
 
93383 int *aRegIdx = 0; /* One register allocated to each index */
93384
93385 #ifndef SQLITE_OMIT_TRIGGER
93386 int isView; /* True if attempting to insert into a view */
93387 Trigger *pTrigger; /* List of triggers on pTab, if required */
@@ -93458,26 +93479,86 @@
93479
93480 /* If this is an AUTOINCREMENT table, look up the sequence number in the
93481 ** sqlite_sequence table and store it in memory cell regAutoinc.
93482 */
93483 regAutoinc = autoIncBegin(pParse, iDb, pTab);
93484
93485 /* Allocate registers for holding the rowid of the new row,
93486 ** the content of the new row, and the assemblied row record.
93487 */
93488 regRowid = regIns = pParse->nMem+1;
93489 pParse->nMem += pTab->nCol + 1;
93490 if( IsVirtual(pTab) ){
93491 regRowid++;
93492 pParse->nMem++;
93493 }
93494 regData = regRowid+1;
93495
93496 /* If the INSERT statement included an IDLIST term, then make sure
93497 ** all elements of the IDLIST really are columns of the table and
93498 ** remember the column indices.
93499 **
93500 ** If the table has an INTEGER PRIMARY KEY column and that column
93501 ** is named in the IDLIST, then record in the ipkColumn variable
93502 ** the index into IDLIST of the primary key column. ipkColumn is
93503 ** the index of the primary key as it appears in IDLIST, not as
93504 ** is appears in the original table. (The index of the INTEGER
93505 ** PRIMARY KEY in the original table is pTab->iPKey.)
93506 */
93507 if( pColumn ){
93508 for(i=0; i<pColumn->nId; i++){
93509 pColumn->a[i].idx = -1;
93510 }
93511 for(i=0; i<pColumn->nId; i++){
93512 for(j=0; j<pTab->nCol; j++){
93513 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93514 pColumn->a[i].idx = j;
93515 if( i!=j ) bIdListInOrder = 0;
93516 if( j==pTab->iPKey ){
93517 ipkColumn = i; assert( !withoutRowid );
93518 }
93519 break;
93520 }
93521 }
93522 if( j>=pTab->nCol ){
93523 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93524 ipkColumn = i;
93525 }else{
93526 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93527 pTabList, 0, pColumn->a[i].zName);
93528 pParse->checkSchema = 1;
93529 goto insert_cleanup;
93530 }
93531 }
93532 }
93533 }
93534
93535 /* Figure out how many columns of data are supplied. If the data
93536 ** is coming from a SELECT statement, then generate a co-routine that
93537 ** produces a single row of the SELECT on each invocation. The
93538 ** co-routine is the common header to the 3rd and 4th templates.
93539 */
93540 if( pSelect ){
93541 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
93542 int regYield; /* Register holding co-routine entry-point */
93543 int addrTop; /* Top of the co-routine */
93544 int rc; /* Result code */
93545
93546 regYield = ++pParse->nMem;
93547 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
93548 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
93549 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
93550 dest.iSdst = bIdListInOrder ? regData : 0;
93551 dest.nSdst = pTab->nCol;
93552 rc = sqlite3Select(pParse, pSelect, &dest);
93553 regFromSelect = dest.iSdst;
93554 assert( pParse->nErr==0 || rc );
93555 if( rc || db->mallocFailed ) goto insert_cleanup;
93556 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
93557 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
93558 assert( pSelect->pEList );
93559 nColumn = pSelect->pEList->nExpr;
 
93560
93561 /* Set useTempTable to TRUE if the result of the SELECT statement
93562 ** should be written into a temporary table (template 4). Set to
93563 ** FALSE if each output row of the SELECT can be written directly into
93564 ** the destination table (template 3).
@@ -93484,42 +93565,39 @@
93565 **
93566 ** A temp table must be used if the table being updated is also one
93567 ** of the tables being read by the SELECT statement. Also use a
93568 ** temp table in the case of row triggers.
93569 */
93570 if( pTrigger || readsTable(pParse, iDb, pTab) ){
93571 useTempTable = 1;
93572 }
93573
93574 if( useTempTable ){
93575 /* Invoke the coroutine to extract information from the SELECT
93576 ** and add it to a transient table srcTab. The code generated
93577 ** here is from the 4th template:
93578 **
93579 ** B: open temp table
93580 ** L: yield X, goto M at EOF
 
93581 ** insert row from R..R+n into temp table
93582 ** goto L
93583 ** M: ...
93584 */
93585 int regRec; /* Register to hold packed record */
93586 int regTempRowid; /* Register to hold temp table ROWID */
93587 int addrL; /* Label "L" */
 
93588
93589 srcTab = pParse->nTab++;
93590 regRec = sqlite3GetTempReg(pParse);
93591 regTempRowid = sqlite3GetTempReg(pParse);
93592 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
93593 addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
 
93594 sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
93595 sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
93596 sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
93597 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
93598 sqlite3VdbeJumpHere(v, addrL);
93599 sqlite3ReleaseTempReg(pParse, regRec);
93600 sqlite3ReleaseTempReg(pParse, regTempRowid);
93601 }
93602 }else{
93603 /* This is the case if the data for the INSERT is coming from a VALUES
@@ -93535,10 +93613,18 @@
93613 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
93614 goto insert_cleanup;
93615 }
93616 }
93617 }
93618
93619 /* If there is no IDLIST term but the table has an integer primary
93620 ** key, the set the ipkColumn variable to the integer primary key
93621 ** column index in the original table definition.
93622 */
93623 if( pColumn==0 && nColumn>0 ){
93624 ipkColumn = pTab->iPKey;
93625 }
93626
93627 /* Make sure the number of columns in the source data matches the number
93628 ** of columns to be inserted into the table.
93629 */
93630 if( IsVirtual(pTab) ){
@@ -93554,56 +93640,10 @@
93640 }
93641 if( pColumn!=0 && nColumn!=pColumn->nId ){
93642 sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
93643 goto insert_cleanup;
93644 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93645
93646 /* Initialize the count of rows to be inserted
93647 */
93648 if( db->flags & SQLITE_CountRows ){
93649 regRowCount = ++pParse->nMem;
@@ -93627,42 +93667,30 @@
93667 /* This is the top of the main insertion loop */
93668 if( useTempTable ){
93669 /* This block codes the top of loop only. The complete loop is the
93670 ** following pseudocode (template 4):
93671 **
93672 ** rewind temp table, if empty goto D
93673 ** C: loop over rows of intermediate table
93674 ** transfer values form intermediate table into <table>
93675 ** end loop
93676 ** D: ...
93677 */
93678 addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); VdbeCoverage(v);
93679 addrCont = sqlite3VdbeCurrentAddr(v);
93680 }else if( pSelect ){
93681 /* This block codes the top of loop only. The complete loop is the
93682 ** following pseudocode (template 3):
93683 **
93684 ** C: yield X, at EOF goto D
 
93685 ** insert the select result into <table> from R..R+n
93686 ** goto C
93687 ** D: ...
93688 */
93689 addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93690 VdbeCoverage(v);
93691 }
 
 
 
 
 
 
 
 
 
 
 
93692
93693 /* Run the BEFORE and INSTEAD OF triggers, if there are any
93694 */
93695 endOfLoop = sqlite3VdbeMakeLabel(v);
93696 if( tmask & TRIGGER_BEFORE ){
@@ -93683,14 +93711,14 @@
93711 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
93712 }else{
93713 assert( pSelect==0 ); /* Otherwise useTempTable is true */
93714 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
93715 }
93716 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
93717 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
93718 sqlite3VdbeJumpHere(v, j1);
93719 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
93720 }
93721
93722 /* Cannot have triggers on a virtual table. If it were possible,
93723 ** this block would have to account for hidden column.
93724 */
@@ -93720,12 +93748,11 @@
93748 ** do not attempt any conversions before assembling the record.
93749 ** If this is a real table, attempt conversions as required by the
93750 ** table column affinities.
93751 */
93752 if( !isView ){
93753 sqlite3TableAffinity(v, pTab, regCols+1);
 
93754 }
93755
93756 /* Fire BEFORE or INSTEAD OF triggers */
93757 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
93758 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
@@ -93743,11 +93770,11 @@
93770 }
93771 if( ipkColumn>=0 ){
93772 if( useTempTable ){
93773 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
93774 }else if( pSelect ){
93775 sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid);
93776 }else{
93777 VdbeOp *pOp;
93778 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
93779 pOp = sqlite3VdbeGetOp(v, -1);
93780 if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
@@ -93762,18 +93789,18 @@
93789 ** to generate a unique primary key value.
93790 */
93791 if( !appendFlag ){
93792 int j1;
93793 if( !IsVirtual(pTab) ){
93794 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); VdbeCoverage(v);
93795 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
93796 sqlite3VdbeJumpHere(v, j1);
93797 }else{
93798 j1 = sqlite3VdbeCurrentAddr(v);
93799 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); VdbeCoverage(v);
93800 }
93801 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
93802 }
93803 }else if( IsVirtual(pTab) || withoutRowid ){
93804 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
93805 }else{
93806 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -93789,12 +93816,13 @@
93816 int iRegStore = regRowid+1+i;
93817 if( i==pTab->iPKey ){
93818 /* The value of the INTEGER PRIMARY KEY column is always a NULL.
93819 ** Whenever this column is read, the rowid will be substituted
93820 ** in its place. Hence, fill this column with a NULL to avoid
93821 ** taking up data space with information that will never be used.
93822 ** As there may be shallow copies of this value, make it a soft-NULL */
93823 sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
93824 continue;
93825 }
93826 if( pColumn==0 ){
93827 if( IsHiddenColumn(&pTab->aCol[i]) ){
93828 assert( IsVirtual(pTab) );
@@ -93807,15 +93835,17 @@
93835 for(j=0; j<pColumn->nId; j++){
93836 if( pColumn->a[j].idx==i ) break;
93837 }
93838 }
93839 if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){
93840 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
93841 }else if( useTempTable ){
93842 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, iRegStore);
93843 }else if( pSelect ){
93844 if( regFromSelect!=regData ){
93845 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
93846 }
93847 }else{
93848 sqlite3ExprCode(pParse, pList->a[j].pExpr, iRegStore);
93849 }
93850 }
93851
@@ -93857,11 +93887,11 @@
93887 /* The bottom of the main insertion loop, if the data source
93888 ** is a SELECT statement.
93889 */
93890 sqlite3VdbeResolveLabel(v, endOfLoop);
93891 if( useTempTable ){
93892 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
93893 sqlite3VdbeJumpHere(v, addrInsTop);
93894 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
93895 }else if( pSelect ){
93896 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
93897 sqlite3VdbeJumpHere(v, addrInsTop);
@@ -94024,10 +94054,11 @@
94054 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
94055 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
94056 int ipkTop = 0; /* Top of the rowid change constraint check */
94057 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
94058 u8 isUpdate; /* True if this is an UPDATE operation */
94059 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
94060 int regRowid = -1; /* Register holding ROWID value */
94061
94062 isUpdate = regOldData!=0;
94063 db = pParse->db;
94064 v = sqlite3GetVdbe(pParse);
@@ -94078,19 +94109,21 @@
94109 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
94110 pTab->aCol[i].zName);
94111 sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
94112 regNewData+1+i, zMsg, P4_DYNAMIC);
94113 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
94114 VdbeCoverage(v);
94115 break;
94116 }
94117 case OE_Ignore: {
94118 sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
94119 VdbeCoverage(v);
94120 break;
94121 }
94122 default: {
94123 assert( onError==OE_Replace );
94124 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i); VdbeCoverage(v);
94125 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
94126 sqlite3VdbeJumpHere(v, j1);
94127 break;
94128 }
94129 }
@@ -94138,10 +94171,12 @@
94171 if( isUpdate ){
94172 /* pkChng!=0 does not mean that the rowid has change, only that
94173 ** it might have changed. Skip the conflict logic below if the rowid
94174 ** is unchanged. */
94175 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
94176 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94177 VdbeCoverage(v);
94178 }
94179
94180 /* If the response to a rowid conflict is REPLACE but the response
94181 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
94182 ** to defer the running of the rowid conflict checking until after
@@ -94157,10 +94192,11 @@
94192 }
94193
94194 /* Check to see if the new rowid already exists in the table. Skip
94195 ** the following conflict logic if it does not. */
94196 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
94197 VdbeCoverage(v);
94198
94199 /* Generate code that deals with a rowid collision */
94200 switch( onError ){
94201 default: {
94202 onError = OE_Abort;
@@ -94235,10 +94271,14 @@
94271 int regR; /* Range of registers holding conflicting PK */
94272 int iThisCur; /* Cursor for this UNIQUE index */
94273 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
94274
94275 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
94276 if( bAffinityDone==0 ){
94277 sqlite3TableAffinity(v, pTab, regNewData+1);
94278 bAffinityDone = 1;
94279 }
94280 iThisCur = iIdxCur+ix;
94281 addrUniqueOk = sqlite3VdbeMakeLabel(v);
94282
94283 /* Skip partial indices for which the WHERE clause is not true */
94284 if( pIdx->pPartIdxWhere ){
@@ -94265,11 +94305,10 @@
94305 }
94306 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94307 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
94308 }
94309 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
 
94310 VdbeComment((v, "for %s", pIdx->zName));
94311 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
94312
94313 /* In an UPDATE operation, if this index is the PRIMARY KEY index
94314 ** of a WITHOUT ROWID table and there has been no change the
@@ -94293,11 +94332,11 @@
94332 onError = OE_Abort;
94333 }
94334
94335 /* Check to see if the new index entry will be unique */
94336 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94337 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
94338
94339 /* Generate code to handle collisions */
94340 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94341 if( isUpdate || onError==OE_Replace ){
94342 if( HasRowid(pTab) ){
@@ -94304,10 +94343,12 @@
94343 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94344 /* Conflict only if the rowid of the existing index entry
94345 ** is different from old-rowid */
94346 if( isUpdate ){
94347 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94348 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94349 VdbeCoverage(v);
94350 }
94351 }else{
94352 int x;
94353 /* Extract the PRIMARY KEY from the end of the index entry and
94354 ** store it in registers regR..regR+nPk-1 */
@@ -94339,10 +94380,13 @@
94380 op = OP_Eq;
94381 }
94382 sqlite3VdbeAddOp4(v, op,
94383 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94384 );
94385 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94386 VdbeCoverageIf(v, op==OP_Eq);
94387 VdbeCoverageIf(v, op==OP_Ne);
94388 }
94389 }
94390 }
94391 }
94392
@@ -94410,18 +94454,21 @@
94454 Index *pIdx; /* An index being inserted or updated */
94455 u8 pik_flags; /* flag values passed to the btree insert */
94456 int regData; /* Content registers (after the rowid) */
94457 int regRec; /* Register holding assemblied record for the table */
94458 int i; /* Loop counter */
94459 u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
94460
94461 v = sqlite3GetVdbe(pParse);
94462 assert( v!=0 );
94463 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
94464 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94465 if( aRegIdx[i]==0 ) continue;
94466 bAffinityDone = 1;
94467 if( pIdx->pPartIdxWhere ){
94468 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
94469 VdbeCoverage(v);
94470 }
94471 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
94472 pik_flags = 0;
94473 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
94474 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
@@ -94432,11 +94479,11 @@
94479 }
94480 if( !HasRowid(pTab) ) return;
94481 regData = regNewData + 1;
94482 regRec = sqlite3GetTempReg(pParse);
94483 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
94484 if( !bAffinityDone ) sqlite3TableAffinity(v, pTab, 0);
94485 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
94486 if( pParse->nested ){
94487 pik_flags = 0;
94488 }else{
94489 pik_flags = OPFLAG_NCHANGE;
@@ -94801,20 +94848,21 @@
94848 ** (2) The destination has a unique index. (The xfer optimization
94849 ** is unable to test uniqueness.)
94850 **
94851 ** (3) onError is something other than OE_Abort and OE_Rollback.
94852 */
94853 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
94854 emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
94855 sqlite3VdbeJumpHere(v, addr1);
94856 }
94857 if( HasRowid(pSrc) ){
94858 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94859 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
94860 if( pDest->iPKey>=0 ){
94861 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94862 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
94863 VdbeCoverage(v);
94864 sqlite3RowidConstraint(pParse, onError, pDest);
94865 sqlite3VdbeJumpHere(v, addr2);
94866 autoIncStep(pParse, regAutoinc, regRowid);
94867 }else if( pDest->pIndex==0 ){
94868 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
@@ -94824,11 +94872,11 @@
94872 }
94873 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
94874 sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
94875 sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
94876 sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94877 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
94878 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94879 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94880 }else{
94881 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
94882 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
@@ -94843,19 +94891,19 @@
94891 VdbeComment((v, "%s", pSrcIdx->zName));
94892 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
94893 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
94894 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
94895 VdbeComment((v, "%s", pDestIdx->zName));
94896 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
94897 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
94898 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
94899 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
94900 sqlite3VdbeJumpHere(v, addr1);
94901 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94902 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94903 }
94904 if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest);
94905 sqlite3ReleaseTempReg(pParse, regRowid);
94906 sqlite3ReleaseTempReg(pParse, regData);
94907 if( emptyDestTest ){
94908 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
94909 sqlite3VdbeJumpHere(v, emptyDestTest);
@@ -97085,10 +97133,11 @@
97133 ** is always on by default regardless of the sign of the default cache
97134 ** size. But continue to take the absolute value of the default cache
97135 ** size of historical compatibility.
97136 */
97137 case PragTyp_DEFAULT_CACHE_SIZE: {
97138 static const int iLn = __LINE__+2;
97139 static const VdbeOpList getCacheSize[] = {
97140 { OP_Transaction, 0, 0, 0}, /* 0 */
97141 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
97142 { OP_IfPos, 1, 8, 0},
97143 { OP_Integer, 0, 2, 0},
@@ -97102,11 +97151,11 @@
97151 sqlite3VdbeUsesBtree(v, iDb);
97152 if( !zRight ){
97153 sqlite3VdbeSetNumCols(v, 1);
97154 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
97155 pParse->nMem += 2;
97156 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
97157 sqlite3VdbeChangeP1(v, addr, iDb);
97158 sqlite3VdbeChangeP1(v, addr+1, iDb);
97159 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
97160 }else{
97161 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
@@ -97347,20 +97396,21 @@
97396 /* When setting the auto_vacuum mode to either "full" or
97397 ** "incremental", write the value of meta[6] in the database
97398 ** file. Before writing to meta[6], check that meta[3] indicates
97399 ** that this really is an auto-vacuum capable database.
97400 */
97401 static const int iLn = __LINE__+2;
97402 static const VdbeOpList setMeta6[] = {
97403 { OP_Transaction, 0, 1, 0}, /* 0 */
97404 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
97405 { OP_If, 1, 0, 0}, /* 2 */
97406 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
97407 { OP_Integer, 0, 1, 0}, /* 4 */
97408 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
97409 };
97410 int iAddr;
97411 iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
97412 sqlite3VdbeChangeP1(v, iAddr, iDb);
97413 sqlite3VdbeChangeP1(v, iAddr+1, iDb);
97414 sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
97415 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
97416 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
@@ -97382,14 +97432,14 @@
97432 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
97433 iLimit = 0x7fffffff;
97434 }
97435 sqlite3BeginWriteOperation(pParse, 0, iDb);
97436 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
97437 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
97438 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
97439 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
97440 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
97441 sqlite3VdbeJumpHere(v, addr);
97442 break;
97443 }
97444 #endif
97445
@@ -97956,11 +98006,11 @@
98006 }
98007 }
98008 assert( pParse->nErr>0 || pFK==0 );
98009 if( pFK ) break;
98010 if( pParse->nTab<i ) pParse->nTab = i;
98011 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
98012 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
98013 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
98014 pIdx = 0;
98015 aiCols = 0;
98016 if( pParent ){
@@ -97972,30 +98022,30 @@
98022 int iKey = pFK->aCol[0].iFrom;
98023 assert( iKey>=0 && iKey<pTab->nCol );
98024 if( iKey!=pTab->iPKey ){
98025 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
98026 sqlite3ColumnDefault(v, pTab, iKey, regRow);
98027 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
98028 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
98029 sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
98030 }else{
98031 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
98032 }
98033 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
98034 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
98035 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
98036 }else{
98037 for(j=0; j<pFK->nCol; j++){
98038 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
98039 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
98040 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
98041 }
98042 if( pParent ){
98043 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
98044 sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
 
98045 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
98046 VdbeCoverage(v);
98047 }
98048 }
98049 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
98050 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
98051 pFK->zTo, P4_TRANSIENT);
@@ -98002,11 +98052,11 @@
98052 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
98053 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
98054 sqlite3VdbeResolveLabel(v, addrOk);
98055 sqlite3DbFree(db, aiCols);
98056 }
98057 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
98058 sqlite3VdbeJumpHere(v, addrTop);
98059 }
98060 }
98061 break;
98062 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
@@ -98049,10 +98099,11 @@
98099
98100 /* Code that appears at the end of the integrity check. If no error
98101 ** messages have been generated, output OK. Otherwise output the
98102 ** error message
98103 */
98104 static const int iLn = __LINE__+2;
98105 static const VdbeOpList endCode[] = {
98106 { OP_AddImm, 1, 0, 0}, /* 0 */
98107 { OP_IfNeg, 1, 0, 0}, /* 1 */
98108 { OP_String8, 0, 3, 0}, /* 2 */
98109 { OP_ResultRow, 3, 1, 0},
@@ -98097,10 +98148,11 @@
98148 if( OMIT_TEMPDB && i==1 ) continue;
98149 if( iDb>=0 && i!=iDb ) continue;
98150
98151 sqlite3CodeVerifySchema(pParse, i);
98152 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
98153 VdbeCoverage(v);
98154 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98155 sqlite3VdbeJumpHere(v, addr);
98156
98157 /* Do an integrity check of the B-Tree
98158 **
@@ -98128,11 +98180,11 @@
98180 pParse->nMem = MAX( pParse->nMem, cnt+8 );
98181
98182 /* Do the b-tree integrity checks */
98183 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
98184 sqlite3VdbeChangeP5(v, (u8)i);
98185 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
98186 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
98187 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
98188 P4_DYNAMIC);
98189 sqlite3VdbeAddOp2(v, OP_Move, 2, 4);
98190 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
@@ -98150,10 +98202,11 @@
98202 int r1 = -1;
98203
98204 if( pTab->pIndex==0 ) continue;
98205 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
98206 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98207 VdbeCoverage(v);
98208 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98209 sqlite3VdbeJumpHere(v, addr);
98210 sqlite3ExprCacheClear(pParse);
98211 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98212 1, 0, &iDataCur, &iIdxCur);
@@ -98160,57 +98213,58 @@
98213 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98214 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98215 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98216 }
98217 pParse->nMem = MAX(pParse->nMem, 8+j);
98218 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
98219 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
98220 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98221 int jmp2, jmp3, jmp4;
98222 if( pPk==pIdx ) continue;
98223 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
98224 pPrior, r1);
98225 pPrior = pIdx;
98226 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
98227 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98228 pIdx->nColumn); VdbeCoverage(v);
98229 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
98230 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
98231 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
98232 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
98233 P4_STATIC);
98234 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98235 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
98236 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98237 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98238 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
98239 sqlite3VdbeAddOp0(v, OP_Halt);
98240 sqlite3VdbeJumpHere(v, jmp4);
98241 sqlite3VdbeJumpHere(v, jmp2);
98242 sqlite3VdbeResolveLabel(v, jmp3);
98243 }
98244 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
98245 sqlite3VdbeJumpHere(v, loopTop-1);
98246 #ifndef SQLITE_OMIT_BTREECOUNT
98247 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
98248 "wrong # of entries in index ", P4_STATIC);
98249 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98250 if( pPk==pIdx ) continue;
98251 addr = sqlite3VdbeCurrentAddr(v);
98252 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
98253 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98254 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98255 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
98256 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
98257 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
98258 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
98259 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
98260 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
98261 }
98262 #endif /* SQLITE_OMIT_BTREECOUNT */
98263 }
98264 }
98265 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
98266 sqlite3VdbeChangeP2(v, addr, -mxErr);
98267 sqlite3VdbeJumpHere(v, addr+1);
98268 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
98269 }
98270 break;
@@ -98344,11 +98398,11 @@
98398 static const VdbeOpList setCookie[] = {
98399 { OP_Transaction, 0, 1, 0}, /* 0 */
98400 { OP_Integer, 0, 1, 0}, /* 1 */
98401 { OP_SetCookie, 0, 0, 1}, /* 2 */
98402 };
98403 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
98404 sqlite3VdbeChangeP1(v, addr, iDb);
98405 sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
98406 sqlite3VdbeChangeP1(v, addr+2, iDb);
98407 sqlite3VdbeChangeP2(v, addr+2, iCookie);
98408 }else{
@@ -98356,11 +98410,11 @@
98410 static const VdbeOpList readCookie[] = {
98411 { OP_Transaction, 0, 0, 0}, /* 0 */
98412 { OP_ReadCookie, 0, 1, 0}, /* 1 */
98413 { OP_ResultRow, 1, 1, 0}
98414 };
98415 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0);
98416 sqlite3VdbeChangeP1(v, addr, iDb);
98417 sqlite3VdbeChangeP1(v, addr+1, iDb);
98418 sqlite3VdbeChangeP3(v, addr+1, iCookie);
98419 sqlite3VdbeSetNumCols(v, 1);
98420 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
@@ -99562,10 +99616,18 @@
99616 if( p ){
99617 clearSelect(db, p);
99618 sqlite3DbFree(db, p);
99619 }
99620 }
99621
99622 /*
99623 ** Return a pointer to the right-most SELECT statement in a compound.
99624 */
99625 static Select *findRightmost(Select *p){
99626 while( p->pNext ) p = p->pNext;
99627 return p;
99628 }
99629
99630 /*
99631 ** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
99632 ** type of join. Return an integer constant that expresses that type
99633 ** in terms of the following bit values:
@@ -99901,11 +99963,11 @@
99963 if( pSelect->iOffset ){
99964 iLimit = pSelect->iOffset+1;
99965 }else{
99966 iLimit = pSelect->iLimit;
99967 }
99968 addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v);
99969 sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
99970 addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
99971 sqlite3VdbeJumpHere(v, addr1);
99972 sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
99973 sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
@@ -99922,11 +99984,11 @@
99984 int iContinue /* Jump here to skip the current record */
99985 ){
99986 if( iOffset>0 && iContinue!=0 ){
99987 int addr;
99988 sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99989 addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); VdbeCoverage(v);
99990 sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
99991 VdbeComment((v, "skip OFFSET records"));
99992 sqlite3VdbeJumpHere(v, addr);
99993 }
99994 }
@@ -99950,11 +100012,11 @@
100012 Vdbe *v;
100013 int r1;
100014
100015 v = pParse->pVdbe;
100016 r1 = sqlite3GetTempReg(pParse);
100017 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
100018 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
100019 sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
100020 sqlite3ReleaseTempReg(pParse, r1);
100021 }
100022
@@ -100031,17 +100093,23 @@
100093 }
100094
100095 /* Pull the requested columns.
100096 */
100097 nResultCol = pEList->nExpr;
100098
100099 if( pDest->iSdst==0 ){
100100 pDest->iSdst = pParse->nMem+1;
100101 pParse->nMem += nResultCol;
100102 }else if( pDest->iSdst+nResultCol > pParse->nMem ){
100103 /* This is an error condition that can result, for example, when a SELECT
100104 ** on the right-hand side of an INSERT contains more result columns than
100105 ** there are columns in the table on the left. The error will be caught
100106 ** and reported later. But we need to make sure enough memory is allocated
100107 ** to avoid other spurious errors in the meantime. */
100108 pParse->nMem += nResultCol;
 
 
100109 }
100110 pDest->nSdst = nResultCol;
100111 regResult = pDest->iSdst;
100112 if( srcTab>=0 ){
100113 for(i=0; i<nResultCol; i++){
100114 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100115 VdbeComment((v, "%s", pEList->a[i].zName));
@@ -100084,13 +100152,15 @@
100152 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100153 for(i=0; i<nResultCol; i++){
100154 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100155 if( i<nResultCol-1 ){
100156 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
100157 VdbeCoverage(v);
100158 }else{
100159 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100160 VdbeCoverage(v);
100161 }
100162 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100163 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100164 }
100165 assert( sqlite3VdbeCurrentAddr(v)==iJump );
100166 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
@@ -100152,11 +100222,11 @@
100222 ** on an ephemeral index. If the current row is already present
100223 ** in the index, do not write it to the output. If not, add the
100224 ** current row to the index and proceed with writing it to the
100225 ** output table as well. */
100226 int addr = sqlite3VdbeCurrentAddr(v) + 4;
100227 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0); VdbeCoverage(v);
100228 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
100229 assert( pOrderBy==0 );
100230 }
100231 #endif
100232 if( pOrderBy ){
@@ -100219,16 +100289,12 @@
100289 }
100290 break;
100291 }
100292 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
100293
100294 case SRT_Coroutine: /* Send data to a co-routine */
100295 case SRT_Output: { /* Return the results */
 
 
 
 
100296 testcase( eDest==SRT_Coroutine );
100297 testcase( eDest==SRT_Output );
100298 if( pOrderBy ){
100299 int r1 = sqlite3GetTempReg(pParse);
100300 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
@@ -100260,17 +100326,20 @@
100326 assert( pSO );
100327 nKey = pSO->nExpr;
100328 r1 = sqlite3GetTempReg(pParse);
100329 r2 = sqlite3GetTempRange(pParse, nKey+2);
100330 r3 = r2+nKey+1;
 
100331 if( eDest==SRT_DistQueue ){
100332 /* If the destination is DistQueue, then cursor (iParm+1) is open
100333 ** on a second ephemeral index that holds all values every previously
100334 ** added to the queue. */
100335 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
100336 regResult, nResultCol);
100337 VdbeCoverage(v);
100338 }
100339 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100340 if( eDest==SRT_DistQueue ){
100341 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100342 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
100343 }
100344 for(i=0; i<nKey; i++){
100345 sqlite3VdbeAddOp2(v, OP_SCopy,
@@ -100305,11 +100374,11 @@
100374 /* Jump to the end of the loop if the LIMIT is reached. Except, if
100375 ** there is a sorter, in which case the sorter has already limited
100376 ** the output for us.
100377 */
100378 if( pOrderBy==0 && p->iLimit ){
100379 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
100380 }
100381 }
100382
100383 /*
100384 ** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -100524,16 +100593,17 @@
100593 if( p->selFlags & SF_UseSorter ){
100594 int regSortOut = ++pParse->nMem;
100595 int ptab2 = pParse->nTab++;
100596 sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100597 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
100598 VdbeCoverage(v);
100599 codeOffset(v, p->iOffset, addrContinue);
100600 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100601 sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100602 sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100603 }else{
100604 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
100605 codeOffset(v, p->iOffset, addrContinue);
100606 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100607 }
100608 switch( eDest ){
100609 case SRT_Table:
@@ -100587,13 +100657,13 @@
100657
100658 /* The bottom of the loop
100659 */
100660 sqlite3VdbeResolveLabel(v, addrContinue);
100661 if( p->selFlags & SF_UseSorter ){
100662 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
100663 }else{
100664 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
100665 }
100666 sqlite3VdbeResolveLabel(v, addrBreak);
100667 if( eDest==SRT_Output || eDest==SRT_Coroutine ){
100668 sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
100669 }
@@ -101073,15 +101143,17 @@
101143 */
101144 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
101145 Vdbe *v = pParse->pVdbe;
101146 if( v==0 ){
101147 v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
101148 if( v ) sqlite3VdbeAddOp0(v, OP_Init);
101149 if( pParse->pToplevel==0
101150 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
101151 ){
101152 pParse->okConstFactor = 1;
101153 }
101154
101155 }
101156 return v;
101157 }
101158
101159
@@ -101135,26 +101207,26 @@
101207 }else if( n>=0 && p->nSelectRow>(u64)n ){
101208 p->nSelectRow = n;
101209 }
101210 }else{
101211 sqlite3ExprCode(pParse, p->pLimit, iLimit);
101212 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
101213 VdbeComment((v, "LIMIT counter"));
101214 sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v);
101215 }
101216 if( p->pOffset ){
101217 p->iOffset = iOffset = ++pParse->nMem;
101218 pParse->nMem++; /* Allocate an extra register for limit+offset */
101219 sqlite3ExprCode(pParse, p->pOffset, iOffset);
101220 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
101221 VdbeComment((v, "OFFSET counter"));
101222 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v);
101223 sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
101224 sqlite3VdbeJumpHere(v, addr1);
101225 sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
101226 VdbeComment((v, "LIMIT+OFFSET"));
101227 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v);
101228 sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
101229 sqlite3VdbeJumpHere(v, addr1);
101230 }
101231 }
101232 }
@@ -101333,15 +101405,17 @@
101405
101406 /* Detach the ORDER BY clause from the compound SELECT */
101407 p->pOrderBy = 0;
101408
101409 /* Store the results of the setup-query in Queue. */
101410 pSetup->pNext = 0;
101411 rc = sqlite3Select(pParse, pSetup, &destQueue);
101412 pSetup->pNext = p;
101413 if( rc ) goto end_of_recursive_query;
101414
101415 /* Find the next row in the Queue and output that row */
101416 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); VdbeCoverage(v);
101417
101418 /* Transfer the next row in Queue over to Current */
101419 sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101420 if( pOrderBy ){
101421 sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
@@ -101353,11 +101427,14 @@
101427 /* Output the single row in Current */
101428 addrCont = sqlite3VdbeMakeLabel(v);
101429 codeOffset(v, regOffset, addrCont);
101430 selectInnerLoop(pParse, p, p->pEList, iCurrent,
101431 0, 0, pDest, addrCont, addrBreak);
101432 if( regLimit ){
101433 sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101434 VdbeCoverage(v);
101435 }
101436 sqlite3VdbeResolveLabel(v, addrCont);
101437
101438 /* Execute the recursive SELECT taking the single row in Current as
101439 ** the value for the recursive-table. Store the results in the Queue.
101440 */
@@ -101438,12 +101515,10 @@
101515 */
101516 assert( p && p->pPrior ); /* Calling function guarantees this much */
101517 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
101518 db = pParse->db;
101519 pPrior = p->pPrior;
 
 
101520 dest = *pDest;
101521 if( pPrior->pOrderBy ){
101522 sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
101523 selectOpName(p->op));
101524 rc = 1;
@@ -101515,11 +101590,11 @@
101590 }
101591 p->pPrior = 0;
101592 p->iLimit = pPrior->iLimit;
101593 p->iOffset = pPrior->iOffset;
101594 if( p->iLimit ){
101595 addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v);
101596 VdbeComment((v, "Jump ahead if LIMIT reached"));
101597 }
101598 explainSetInteger(iSub2, pParse->iNextSelectId);
101599 rc = sqlite3Select(pParse, p, &dest);
101600 testcase( rc!=SQLITE_OK );
@@ -101547,16 +101622,14 @@
101622 SelectDest uniondest;
101623
101624 testcase( p->op==TK_EXCEPT );
101625 testcase( p->op==TK_UNION );
101626 priorOp = SRT_Union;
101627 if( dest.eDest==priorOp ){
101628 /* We can reuse a temporary table generated by a SELECT to our
101629 ** right.
101630 */
 
 
101631 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
101632 assert( p->pOffset==0 ); /* Not allowed on leftward elements */
101633 unionTab = dest.iSDParm;
101634 }else{
101635 /* We will need to create our own temporary table to hold the
@@ -101565,11 +101638,11 @@
101638 unionTab = pParse->nTab++;
101639 assert( p->pOrderBy==0 );
101640 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
101641 assert( p->addrOpenEphm[0] == -1 );
101642 p->addrOpenEphm[0] = addr;
101643 findRightmost(p)->selFlags |= SF_UsesEphemeral;
101644 assert( p->pEList );
101645 }
101646
101647 /* Code the SELECT statements to our left
101648 */
@@ -101624,16 +101697,16 @@
101697 generateColumnNames(pParse, 0, pFirst->pEList);
101698 }
101699 iBreak = sqlite3VdbeMakeLabel(v);
101700 iCont = sqlite3VdbeMakeLabel(v);
101701 computeLimitRegisters(pParse, p, iBreak);
101702 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
101703 iStart = sqlite3VdbeCurrentAddr(v);
101704 selectInnerLoop(pParse, p, p->pEList, unionTab,
101705 0, 0, &dest, iCont, iBreak);
101706 sqlite3VdbeResolveLabel(v, iCont);
101707 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
101708 sqlite3VdbeResolveLabel(v, iBreak);
101709 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
101710 }
101711 break;
101712 }
@@ -101654,11 +101727,11 @@
101727 assert( p->pOrderBy==0 );
101728
101729 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
101730 assert( p->addrOpenEphm[0] == -1 );
101731 p->addrOpenEphm[0] = addr;
101732 findRightmost(p)->selFlags |= SF_UsesEphemeral;
101733 assert( p->pEList );
101734
101735 /* Code the SELECTs to our left into temporary table "tab1".
101736 */
101737 sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1);
@@ -101699,19 +101772,19 @@
101772 generateColumnNames(pParse, 0, pFirst->pEList);
101773 }
101774 iBreak = sqlite3VdbeMakeLabel(v);
101775 iCont = sqlite3VdbeMakeLabel(v);
101776 computeLimitRegisters(pParse, p, iBreak);
101777 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
101778 r1 = sqlite3GetTempReg(pParse);
101779 iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101780 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
101781 sqlite3ReleaseTempReg(pParse, r1);
101782 selectInnerLoop(pParse, p, p->pEList, tab1,
101783 0, 0, &dest, iCont, iBreak);
101784 sqlite3VdbeResolveLabel(v, iCont);
101785 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
101786 sqlite3VdbeResolveLabel(v, iBreak);
101787 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
101788 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
101789 break;
101790 }
@@ -101733,11 +101806,11 @@
101806 KeyInfo *pKeyInfo; /* Collating sequence for the result set */
101807 Select *pLoop; /* For looping through SELECT statements */
101808 CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
101809 int nCol; /* Number of columns in result set */
101810
101811 assert( p->pNext==0 );
101812 nCol = p->pEList->nExpr;
101813 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
101814 if( !pKeyInfo ){
101815 rc = SQLITE_NOMEM;
101816 goto multi_select_end;
@@ -101814,14 +101887,14 @@
101887
101888 /* Suppress duplicates for UNION, EXCEPT, and INTERSECT
101889 */
101890 if( regPrev ){
101891 int j1, j2;
101892 j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
101893 j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
101894 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
101895 sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); VdbeCoverage(v);
101896 sqlite3VdbeJumpHere(v, j1);
101897 sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
101898 sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
101899 }
101900 if( pParse->db->mallocFailed ) return 0;
@@ -101918,11 +101991,11 @@
101991 }
101992
101993 /* Jump to the end of the loop if the LIMIT is reached.
101994 */
101995 if( p->iLimit ){
101996 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
101997 }
101998
101999 /* Generate the subroutine return
102000 */
102001 sqlite3VdbeResolveLabel(v, iContinue);
@@ -102026,20 +102099,19 @@
102099 Select *pPrior; /* Another SELECT immediately to our left */
102100 Vdbe *v; /* Generate code to this VDBE */
102101 SelectDest destA; /* Destination for coroutine A */
102102 SelectDest destB; /* Destination for coroutine B */
102103 int regAddrA; /* Address register for select-A coroutine */
 
102104 int regAddrB; /* Address register for select-B coroutine */
 
102105 int addrSelectA; /* Address of the select-A coroutine */
102106 int addrSelectB; /* Address of the select-B coroutine */
102107 int regOutA; /* Address register for the output-A subroutine */
102108 int regOutB; /* Address register for the output-B subroutine */
102109 int addrOutA; /* Address of the output-A subroutine */
102110 int addrOutB = 0; /* Address of the output-B subroutine */
102111 int addrEofA; /* Address of the select-A-exhausted subroutine */
102112 int addrEofA_noB; /* Alternate addrEofA if B is uninitialized */
102113 int addrEofB; /* Address of the select-B-exhausted subroutine */
102114 int addrAltB; /* Address of the A<B subroutine */
102115 int addrAeqB; /* Address of the A==B subroutine */
102116 int addrAgtB; /* Address of the A>B subroutine */
102117 int regLimitA; /* Limit register for select-A */
@@ -102150,10 +102222,11 @@
102222 }
102223
102224 /* Separate the left and the right query from one another
102225 */
102226 p->pPrior = 0;
102227 pPrior->pNext = 0;
102228 sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
102229 if( pPrior->pPrior==0 ){
102230 sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
102231 }
102232
@@ -102172,52 +102245,43 @@
102245 p->pLimit = 0;
102246 sqlite3ExprDelete(db, p->pOffset);
102247 p->pOffset = 0;
102248
102249 regAddrA = ++pParse->nMem;
 
102250 regAddrB = ++pParse->nMem;
 
102251 regOutA = ++pParse->nMem;
102252 regOutB = ++pParse->nMem;
102253 sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
102254 sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
 
 
 
 
 
 
 
102255
102256 /* Generate a coroutine to evaluate the SELECT statement to the
102257 ** left of the compound operator - the "A" select.
102258 */
102259 addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
102260 j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
102261 VdbeComment((v, "left SELECT"));
102262 pPrior->iLimit = regLimitA;
102263 explainSetInteger(iSub1, pParse->iNextSelectId);
102264 sqlite3Select(pParse, pPrior, &destA);
102265 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrA);
102266 sqlite3VdbeJumpHere(v, j1);
 
102267
102268 /* Generate a coroutine to evaluate the SELECT statement on
102269 ** the right - the "B" select
102270 */
102271 addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
102272 j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
102273 VdbeComment((v, "right SELECT"));
102274 savedLimit = p->iLimit;
102275 savedOffset = p->iOffset;
102276 p->iLimit = regLimitB;
102277 p->iOffset = 0;
102278 explainSetInteger(iSub2, pParse->iNextSelectId);
102279 sqlite3Select(pParse, p, &destB);
102280 p->iLimit = savedLimit;
102281 p->iOffset = savedOffset;
102282 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrB);
 
 
102283
102284 /* Generate a subroutine that outputs the current row of the A
102285 ** select as the next output row of the compound select.
102286 */
102287 VdbeNoopComment((v, "Output routine for A"));
@@ -102237,17 +102301,17 @@
102301 sqlite3KeyInfoUnref(pKeyDup);
102302
102303 /* Generate a subroutine to run when the results from select A
102304 ** are exhausted and only data in select B remains.
102305 */
 
102306 if( op==TK_EXCEPT || op==TK_INTERSECT ){
102307 addrEofA_noB = addrEofA = labelEnd;
102308 }else{
102309 VdbeNoopComment((v, "eof-A subroutine"));
102310 addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102311 addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
102312 VdbeCoverage(v);
102313 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
102314 p->nSelectRow += pPrior->nSelectRow;
102315 }
102316
102317 /* Generate a subroutine to run when the results from select B
@@ -102256,22 +102320,20 @@
102320 if( op==TK_INTERSECT ){
102321 addrEofB = addrEofA;
102322 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
102323 }else{
102324 VdbeNoopComment((v, "eof-B subroutine"));
102325 addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102326 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
 
102327 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
102328 }
102329
102330 /* Generate code to handle the case of A<B
102331 */
102332 VdbeNoopComment((v, "A-lt-B subroutine"));
102333 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102334 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
 
102335 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102336
102337 /* Generate code to handle the case of A==B
102338 */
102339 if( op==TK_ALL ){
@@ -102280,12 +102342,11 @@
102342 addrAeqB = addrAltB;
102343 addrAltB++;
102344 }else{
102345 VdbeNoopComment((v, "A-eq-B subroutine"));
102346 addrAeqB =
102347 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
 
102348 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102349 }
102350
102351 /* Generate code to handle the case of A>B
102352 */
@@ -102292,32 +102353,27 @@
102353 VdbeNoopComment((v, "A-gt-B subroutine"));
102354 addrAgtB = sqlite3VdbeCurrentAddr(v);
102355 if( op==TK_ALL || op==TK_UNION ){
102356 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102357 }
102358 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
 
102359 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102360
102361 /* This code runs once to initialize everything.
102362 */
102363 sqlite3VdbeJumpHere(v, j1);
102364 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
102365 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
 
 
 
 
102366
102367 /* Implement the main merge loop
102368 */
102369 sqlite3VdbeResolveLabel(v, labelCmpr);
102370 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
102371 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
102372 (char*)pKeyMerge, P4_KEYINFO);
102373 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
102374 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
102375
102376 /* Jump to the this point in order to terminate the query.
102377 */
102378 sqlite3VdbeResolveLabel(v, labelEnd);
102379
@@ -102333,10 +102389,11 @@
102389 ** by the calling function */
102390 if( p->pPrior ){
102391 sqlite3SelectDelete(db, p->pPrior);
102392 }
102393 p->pPrior = pPrior;
102394 pPrior->pNext = p;
102395
102396 /*** TBD: Insert subroutine calls to close cursors on incomplete
102397 **** subqueries ****/
102398 explainComposite(pParse, p->op, iSub1, iSub2, 0);
102399 return SQLITE_OK;
@@ -102598,11 +102655,11 @@
102655 ** because they could be computed at compile-time. But when LIMIT and OFFSET
102656 ** became arbitrary expressions, we were forced to add restrictions (13)
102657 ** and (14). */
102658 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
102659 if( pSub->pOffset ) return 0; /* Restriction (14) */
102660 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
102661 return 0; /* Restriction (15) */
102662 }
102663 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
102664 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (5) */
102665 if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){
@@ -102749,18 +102806,18 @@
102806 p->pOffset = pOffset;
102807 p->pLimit = pLimit;
102808 p->pOrderBy = pOrderBy;
102809 p->pSrc = pSrc;
102810 p->op = TK_ALL;
 
102811 if( pNew==0 ){
102812 p->pPrior = pPrior;
102813 }else{
102814 pNew->pPrior = pPrior;
102815 if( pPrior ) pPrior->pNext = pNew;
102816 pNew->pNext = p;
102817 p->pPrior = pNew;
102818 }
 
102819 if( db->mallocFailed ) return 1;
102820 }
102821
102822 /* Begin flattening the iFrom-th entry of the FROM clause
102823 ** in the outer query.
@@ -103095,10 +103152,14 @@
103152 p->pWhere = 0;
103153 pNew->pGroupBy = 0;
103154 pNew->pHaving = 0;
103155 pNew->pOrderBy = 0;
103156 p->pPrior = 0;
103157 p->pNext = 0;
103158 p->selFlags &= ~SF_Compound;
103159 assert( pNew->pPrior!=0 );
103160 pNew->pPrior->pNext = pNew;
103161 pNew->pLimit = 0;
103162 pNew->pOffset = 0;
103163 return WRC_Continue;
103164 }
103165
@@ -103282,13 +103343,14 @@
103343 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
103344 ** names and other FROM clause elements.
103345 */
103346 static void selectPopWith(Walker *pWalker, Select *p){
103347 Parse *pParse = pWalker->pParse;
103348 With *pWith = findRightmost(p)->pWith;
103349 if( pWith!=0 ){
103350 assert( pParse->pWith==pWith );
103351 pParse->pWith = pWith->pOuter;
103352 }
103353 }
103354 #else
103355 #define selectPopWith 0
103356 #endif
@@ -103334,11 +103396,11 @@
103396 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
103397 return WRC_Prune;
103398 }
103399 pTabList = p->pSrc;
103400 pEList = p->pEList;
103401 sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
103402
103403 /* Make sure cursor numbers have been assigned to all entries in
103404 ** the FROM clause of the SELECT statement.
103405 */
103406 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -103847,11 +103909,11 @@
103909 **
103910 ** Another solution would be to change the OP_SCopy used to copy cached
103911 ** values to an OP_Copy.
103912 */
103913 if( regHit ){
103914 addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
103915 }
103916 sqlite3ExprCacheClear(pParse);
103917 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
103918 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
103919 }
@@ -104006,46 +104068,28 @@
104068 if( isAggSub ){
104069 isAgg = 1;
104070 p->selFlags |= SF_Aggregate;
104071 }
104072 i = -1;
104073 }else if( pTabList->nSrc==1
104074 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
104075 ){
104076 /* Implement a co-routine that will return a single row of the result
104077 ** set on each invocation.
104078 */
104079 int addrTop = sqlite3VdbeCurrentAddr(v)+1;
 
104080 pItem->regReturn = ++pParse->nMem;
104081 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
104082 VdbeComment((v, "%s", pItem->pTab->zName));
 
 
 
 
 
 
 
 
 
 
 
 
104083 pItem->addrFillSub = addrTop;
 
 
104084 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
104085 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104086 sqlite3Select(pParse, pSub, &dest);
104087 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
104088 pItem->viaCoroutine = 1;
104089 pItem->regResult = dest.iSdst;
104090 sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
 
 
 
104091 sqlite3VdbeJumpHere(v, addrTop-1);
104092 sqlite3ClearTempRegCache(pParse);
104093 }else{
104094 /* Generate a subroutine that will fill an ephemeral table with
104095 ** the content of this subquery. pItem->addrFillSub will point
@@ -104057,16 +104101,18 @@
104101 int retAddr;
104102 assert( pItem->addrFillSub==0 );
104103 pItem->regReturn = ++pParse->nMem;
104104 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
104105 pItem->addrFillSub = topAddr+1;
 
104106 if( pItem->isCorrelated==0 ){
104107 /* If the subquery is not correlated and if we are not inside of
104108 ** a trigger, then we only need to compute the value of the subquery
104109 ** once. */
104110 onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
104111 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
104112 }else{
104113 VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
104114 }
104115 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
104116 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104117 sqlite3Select(pParse, pSub, &dest);
104118 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
@@ -104094,25 +104140,10 @@
104140
104141 #ifndef SQLITE_OMIT_COMPOUND_SELECT
104142 /* If there is are a sequence of queries, do the earlier ones first.
104143 */
104144 if( p->pPrior ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104145 rc = multiSelect(pParse, p, pDest);
104146 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
104147 return rc;
104148 }
104149 #endif
@@ -104412,11 +104443,11 @@
104443 sqlite3WhereEnd(pWInfo);
104444 sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
104445 sortOut = sqlite3GetTempReg(pParse);
104446 sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
104447 sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
104448 VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
104449 sAggInfo.useSortingIdx = 1;
104450 sqlite3ExprCacheClear(pParse);
104451 }
104452
104453 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
@@ -104439,11 +104470,11 @@
104470 }
104471 }
104472 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
104473 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
104474 j1 = sqlite3VdbeCurrentAddr(v);
104475 sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); VdbeCoverage(v);
104476
104477 /* Generate code that runs whenever the GROUP BY changes.
104478 ** Changes in the GROUP BY are detected by the previous code
104479 ** block. If there were no changes, this block is skipped.
104480 **
@@ -104453,11 +104484,11 @@
104484 ** for the next GROUP BY batch.
104485 */
104486 sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
104487 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
104488 VdbeComment((v, "output one row"));
104489 sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
104490 VdbeComment((v, "check abort flag"));
104491 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
104492 VdbeComment((v, "reset accumulator"));
104493
104494 /* Update the aggregate accumulators based on the content of
@@ -104470,10 +104501,11 @@
104501
104502 /* End of the loop
104503 */
104504 if( groupBySort ){
104505 sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
104506 VdbeCoverage(v);
104507 }else{
104508 sqlite3WhereEnd(pWInfo);
104509 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
104510 }
104511
@@ -104497,11 +104529,11 @@
104529 sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
104530 VdbeComment((v, "set abort flag"));
104531 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104532 sqlite3VdbeResolveLabel(v, addrOutputRow);
104533 addrOutputRow = sqlite3VdbeCurrentAddr(v);
104534 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); VdbeCoverage(v);
104535 VdbeComment((v, "Groupby result generator entry point"));
104536 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104537 finalizeAggFunctions(pParse, &sAggInfo);
104538 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104539 selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
@@ -104770,14 +104802,10 @@
104802 SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
104803 if( p==0 ){
104804 sqlite3ExplainPrintf(pVdbe, "(null-select)");
104805 return;
104806 }
 
 
 
 
104807 sqlite3ExplainPush(pVdbe);
104808 while( p ){
104809 explainOneSelect(pVdbe, p);
104810 p = p->pNext;
104811 if( p==0 ) break;
@@ -105558,10 +105586,11 @@
105586 /* Generate code to destroy the database record of the trigger.
105587 */
105588 assert( pTable!=0 );
105589 if( (v = sqlite3GetVdbe(pParse))!=0 ){
105590 int base;
105591 static const int iLn = __LINE__+2;
105592 static const VdbeOpList dropTrigger[] = {
105593 { OP_Rewind, 0, ADDR(9), 0},
105594 { OP_String8, 0, 1, 0}, /* 1 */
105595 { OP_Column, 0, 1, 2},
105596 { OP_Ne, 2, ADDR(8), 1},
@@ -105572,11 +105601,11 @@
105601 { OP_Next, 0, ADDR(1), 0}, /* 8 */
105602 };
105603
105604 sqlite3BeginWriteOperation(pParse, 0, iDb);
105605 sqlite3OpenMasterTable(pParse, iDb);
105606 base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger, iLn);
105607 sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
105608 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
105609 sqlite3ChangeCookie(pParse, iDb);
105610 sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
105611 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
@@ -105718,19 +105747,11 @@
105747 **
105748 ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
105749 ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
105750 */
105751 pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
105752 assert( pParse->okConstFactor==0 );
 
 
 
 
 
 
 
 
105753
105754 switch( pStep->op ){
105755 case TK_UPDATE: {
105756 sqlite3Update(pParse,
105757 targetSrcList(pParse, pStep),
@@ -106515,11 +106536,11 @@
106536 sqlite3VdbeChangeToNoop(v, addrOpen);
106537 nKey = nPk;
106538 regKey = iPk;
106539 }else{
106540 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106541 sqlite3IndexAffinityStr(v, pPk), nPk);
106542 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106543 }
106544 sqlite3WhereEnd(pWInfo);
106545 }
106546
@@ -106559,32 +106580,37 @@
106580 /* Top of the update loop */
106581 if( okOnePass ){
106582 if( aToOpen[iDataCur-iBaseCur] ){
106583 assert( pPk!=0 );
106584 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
106585 VdbeCoverageNeverTaken(v);
106586 }
106587 labelContinue = labelBreak;
106588 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106589 VdbeCoverage(v);
106590 }else if( pPk ){
106591 labelContinue = sqlite3VdbeMakeLabel(v);
106592 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
106593 addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106594 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
106595 VdbeCoverage(v);
106596 }else{
106597 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106598 regOldRowid);
106599 VdbeCoverage(v);
106600 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106601 VdbeCoverage(v);
106602 }
106603
106604 /* If the record number will change, set register regNewRowid to
106605 ** contain the new value. If the record number is not being modified,
106606 ** then regNewRowid is the same register as regOldRowid, which is
106607 ** already populated. */
106608 assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
106609 if( chngRowid ){
106610 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
106611 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
106612 }
106613
106614 /* Compute the old pre-UPDATE content of the row being changed, if that
106615 ** information is needed */
106616 if( chngPk || hasFK || pTrigger ){
@@ -106649,12 +106675,11 @@
106675
106676 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
106677 ** verified. One could argue that this is wrong.
106678 */
106679 if( tmask&TRIGGER_BEFORE ){
106680 sqlite3TableAffinity(v, pTab, regNew);
 
106681 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106682 TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
106683
106684 /* The row-trigger may have deleted the row being updated. In this
106685 ** case, jump to the next row. No updates or AFTER triggers are
@@ -106662,12 +106687,14 @@
106687 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
106688 ** documentation.
106689 */
106690 if( pPk ){
106691 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
106692 VdbeCoverage(v);
106693 }else{
106694 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106695 VdbeCoverage(v);
106696 }
106697
106698 /* If it did not delete it, the row-trigger may still have modified
106699 ** some of the columns of the row being updated. Load the values for
106700 ** all columns not modified by the update statement into their
@@ -106699,10 +106726,11 @@
106726 if( pPk ){
106727 j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106728 }else{
106729 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106730 }
106731 VdbeCoverageNeverTaken(v);
106732 }
106733 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
106734
106735 /* If changing the record number, delete the old record. */
106736 if( hasFK || chngKey || pPk!=0 ){
@@ -106742,11 +106770,11 @@
106770 */
106771 if( okOnePass ){
106772 /* Nothing to do at end-of-loop for a single-pass */
106773 }else if( pPk ){
106774 sqlite3VdbeResolveLabel(v, labelContinue);
106775 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
106776 }else{
106777 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106778 }
106779 sqlite3VdbeResolveLabel(v, labelBreak);
106780
@@ -106871,21 +106899,21 @@
106899 sqlite3Select(pParse, pSelect, &dest);
106900
106901 /* Generate code to scan the ephemeral table and call VUpdate. */
106902 iReg = ++pParse->nMem;
106903 pParse->nMem += pTab->nCol+1;
106904 addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); VdbeCoverage(v);
106905 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, 0, iReg);
106906 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
106907 for(i=0; i<pTab->nCol; i++){
106908 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
106909 }
106910 sqlite3VtabMakeWritable(pParse, pTab);
106911 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
106912 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
106913 sqlite3MayAbort(pParse);
106914 sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);
106915 sqlite3VdbeJumpHere(v, addr);
106916 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
106917
106918 /* Cleanup */
106919 sqlite3SelectDelete(db, pSelect);
@@ -108453,11 +108481,11 @@
108481 int addrSkip; /* Jump here for next iteration of skip-scan */
108482 int addrCont; /* Jump here to continue with the next loop cycle */
108483 int addrFirst; /* First instruction of interior of the loop */
108484 int addrBody; /* Beginning of the body of this loop */
108485 u8 iFrom; /* Which entry in the FROM clause */
108486 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
108487 int p1, p2; /* Operands of the opcode used to ends the loop */
108488 union { /* Information that depends on pWLoop->wsFlags */
108489 struct {
108490 int nIn; /* Number of entries in aInLoop[] */
108491 struct InLoop {
@@ -108840,10 +108868,11 @@
108868 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108869 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108870 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108871 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108872 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
108873 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
108874
108875 /************** End of whereInt.h ********************************************/
108876 /************** Continuing where we left off in where.c **********************/
108877
108878 /*
@@ -110426,11 +110455,11 @@
110455
110456 /* Generate code to skip over the creation and initialization of the
110457 ** transient index on 2nd and subsequent iterations of the loop. */
110458 v = pParse->pVdbe;
110459 assert( v!=0 );
110460 addrInit = sqlite3CodeOnce(pParse); VdbeCoverage(v);
110461
110462 /* Count the number of columns that will be added to the index
110463 ** and used to match WHERE clause constraints */
110464 nKeyCol = 0;
110465 pTable = pSrc->pTab;
@@ -110533,16 +110562,16 @@
110562 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110563 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
110564 VdbeComment((v, "for %s", pTable->zName));
110565
110566 /* Fill the automatic index with content */
110567 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
110568 regRecord = sqlite3GetTempReg(pParse);
110569 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
110570 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
110571 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
110572 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
110573 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
110574 sqlite3VdbeJumpHere(v, addrTop);
110575 sqlite3ReleaseTempReg(pParse, regRecord);
110576
110577 /* Jump here when skipping the initialization */
@@ -111214,10 +111243,12 @@
111243 testcase( bRev );
111244 bRev = !bRev;
111245 }
111246 iTab = pX->iTable;
111247 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
111248 VdbeCoverageIf(v, bRev);
111249 VdbeCoverageIf(v, !bRev);
111250 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
111251 pLoop->wsFlags |= WHERE_IN_ABLE;
111252 if( pLevel->u.in.nIn==0 ){
111253 pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
111254 }
@@ -111233,11 +111264,11 @@
111264 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
111265 }else{
111266 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
111267 }
111268 pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
111269 sqlite3VdbeAddOp1(v, OP_IsNull, iReg); VdbeCoverage(v);
111270 }else{
111271 pLevel->u.in.nIn = 0;
111272 }
111273 #endif
111274 }
@@ -111328,14 +111359,18 @@
111359 }
111360
111361 if( nSkip ){
111362 int iIdxCur = pLevel->iIdxCur;
111363 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
111364 VdbeCoverageIf(v, bRev==0);
111365 VdbeCoverageIf(v, bRev!=0);
111366 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
111367 j = sqlite3VdbeAddOp0(v, OP_Goto);
111368 pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
111369 iIdxCur, 0, regBase, nSkip);
111370 VdbeCoverageIf(v, bRev==0);
111371 VdbeCoverageIf(v, bRev!=0);
111372 sqlite3VdbeJumpHere(v, j);
111373 for(j=0; j<nSkip; j++){
111374 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
111375 assert( pIdx->aiColumn[j]>=0 );
111376 VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
@@ -111364,11 +111399,14 @@
111399 }
111400 testcase( pTerm->eOperator & WO_ISNULL );
111401 testcase( pTerm->eOperator & WO_IN );
111402 if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
111403 Expr *pRight = pTerm->pExpr->pRight;
111404 if( sqlite3ExprCanBeNull(pRight) ){
111405 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
111406 VdbeCoverage(v);
111407 }
111408 if( zAff ){
111409 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
111410 zAff[j] = SQLITE_AFF_NONE;
111411 }
111412 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
@@ -111610,14 +111648,14 @@
111648 }
111649
111650 /* Special case of a FROM clause subquery implemented as a co-routine */
111651 if( pTabItem->viaCoroutine ){
111652 int regYield = pTabItem->regReturn;
111653 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
111654 pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
111655 VdbeCoverage(v);
111656 VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
111657 pLevel->op = OP_Goto;
111658 }else
111659
111660 #ifndef SQLITE_OMIT_VIRTUALTABLE
111661 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -111645,10 +111683,11 @@
111683 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
111684 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
111685 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
111686 pLoop->u.vtab.idxStr,
111687 pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
111688 VdbeCoverage(v);
111689 pLoop->u.vtab.needFree = 0;
111690 for(j=0; j<nConstraint && j<16; j++){
111691 if( (pLoop->u.vtab.omitMask>>j)&1 ){
111692 disableTerm(pLevel, pLoop->aLTerm[j]);
111693 }
@@ -111668,20 +111707,22 @@
111707 ** equality comparison against the ROWID field. Or
111708 ** we reference multiple rows using a "rowid IN (...)"
111709 ** construct.
111710 */
111711 assert( pLoop->u.btree.nEq==1 );
 
111712 pTerm = pLoop->aLTerm[0];
111713 assert( pTerm!=0 );
111714 assert( pTerm->pExpr!=0 );
111715 assert( omitTable==0 );
111716 testcase( pTerm->wtFlags & TERM_VIRTUAL );
111717 iReleaseReg = ++pParse->nMem;
111718 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
111719 if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
111720 addrNxt = pLevel->addrNxt;
111721 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); VdbeCoverage(v);
111722 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
111723 VdbeCoverage(v);
111724 sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
111725 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111726 VdbeComment((v, "pk"));
111727 pLevel->op = OP_Noop;
111728 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -111711,14 +111752,14 @@
111752
111753 /* The following constant maps TK_xx codes into corresponding
111754 ** seek opcodes. It depends on a particular ordering of TK_xx
111755 */
111756 const u8 aMoveOp[] = {
111757 /* TK_GT */ OP_SeekGT,
111758 /* TK_LE */ OP_SeekLE,
111759 /* TK_LT */ OP_SeekLT,
111760 /* TK_GE */ OP_SeekGE
111761 };
111762 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
111763 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
111764 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
111765
@@ -111728,15 +111769,21 @@
111769 assert( pX!=0 );
111770 testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
111771 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
111772 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
111773 VdbeComment((v, "pk"));
111774 VdbeCoverageIf(v, pX->op==TK_GT);
111775 VdbeCoverageIf(v, pX->op==TK_LE);
111776 VdbeCoverageIf(v, pX->op==TK_LT);
111777 VdbeCoverageIf(v, pX->op==TK_GE);
111778 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
111779 sqlite3ReleaseTempReg(pParse, rTemp);
111780 disableTerm(pLevel, pStart);
111781 }else{
111782 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
111783 VdbeCoverageIf(v, bRev==0);
111784 VdbeCoverageIf(v, bRev!=0);
111785 }
111786 if( pEnd ){
111787 Expr *pX;
111788 pX = pEnd->pExpr;
111789 assert( pX!=0 );
@@ -111756,14 +111803,18 @@
111803 pLevel->op = bRev ? OP_Prev : OP_Next;
111804 pLevel->p1 = iCur;
111805 pLevel->p2 = start;
111806 assert( pLevel->p5==0 );
111807 if( testOp!=OP_Noop ){
111808 iRowidReg = ++pParse->nMem;
111809 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
111810 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111811 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
111812 VdbeCoverageIf(v, testOp==OP_Le);
111813 VdbeCoverageIf(v, testOp==OP_Lt);
111814 VdbeCoverageIf(v, testOp==OP_Ge);
111815 VdbeCoverageIf(v, testOp==OP_Gt);
111816 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
111817 }
111818 }else if( pLoop->wsFlags & WHERE_INDEXED ){
111819 /* Case 4: A scan using an index.
111820 **
@@ -111799,24 +111850,23 @@
111850 static const u8 aStartOp[] = {
111851 0,
111852 0,
111853 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
111854 OP_Last, /* 3: (!start_constraints && startEq && bRev) */
111855 OP_SeekGT, /* 4: (start_constraints && !startEq && !bRev) */
111856 OP_SeekLT, /* 5: (start_constraints && !startEq && bRev) */
111857 OP_SeekGE, /* 6: (start_constraints && startEq && !bRev) */
111858 OP_SeekLE /* 7: (start_constraints && startEq && bRev) */
111859 };
111860 static const u8 aEndOp[] = {
111861 OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
111862 OP_IdxGT, /* 1: (end_constraints && !bRev && endEq) */
111863 OP_IdxLE, /* 2: (end_constraints && bRev && !endEq) */
111864 OP_IdxLT, /* 3: (end_constraints && bRev && endEq) */
111865 };
111866 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
 
111867 int regBase; /* Base register holding constraint values */
 
111868 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111869 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111870 int startEq; /* True if range start uses ==, >= or <= */
111871 int endEq; /* True if range end uses ==, >= or <= */
111872 int start_constraints; /* Start of range is constrained */
@@ -111825,10 +111875,12 @@
111875 int iIdxCur; /* The VDBE cursor for the index */
111876 int nExtraReg = 0; /* Number of extra registers needed */
111877 int op; /* Instruction opcode */
111878 char *zStartAff; /* Affinity for start of range constraint */
111879 char cEndAff = 0; /* Affinity for end of range constraint */
111880 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
111881 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
111882
111883 pIdx = pLoop->u.btree.pIndex;
111884 iIdxCur = pLevel->iIdxCur;
111885 assert( nEq>=pLoop->u.btree.nSkip );
111886
@@ -111843,11 +111895,11 @@
111895 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111896 && (pWInfo->bOBSat!=0)
111897 && (pIdx->nKeyCol>nEq)
111898 ){
111899 assert( pLoop->u.btree.nSkip==0 );
111900 bSeekPastNull = 1;
111901 nExtraReg = 1;
111902 }
111903
111904 /* Find any inequality constraint terms for the start and end
111905 ** of the range.
@@ -111858,10 +111910,17 @@
111910 nExtraReg = 1;
111911 }
111912 if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
111913 pRangeEnd = pLoop->aLTerm[j++];
111914 nExtraReg = 1;
111915 if( pRangeStart==0
111916 && (pRangeEnd->wtFlags & TERM_VNULL)==0
111917 && (j = pIdx->aiColumn[nEq])>=0
111918 && pIdx->pTable->aCol[j].notNull==0
111919 ){
111920 bSeekPastNull = 1;
111921 }
111922 }
111923
111924 /* Generate code to evaluate all constraint terms using == or IN
111925 ** and store the values of those terms in an array of registers
111926 ** starting at regBase.
@@ -111877,10 +111936,11 @@
111936 */
111937 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111938 || (bRev && pIdx->nKeyCol==nEq)
111939 ){
111940 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
111941 SWAP(u8, bSeekPastNull, bStopAtNull);
111942 }
111943
111944 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
111945 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
111946 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
@@ -111892,12 +111952,15 @@
111952 /* Seek the index cursor to the start of the range. */
111953 nConstraint = nEq;
111954 if( pRangeStart ){
111955 Expr *pRight = pRangeStart->pExpr->pRight;
111956 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111957 if( (pRangeStart->wtFlags & TERM_VNULL)==0
111958 && sqlite3ExprCanBeNull(pRight)
111959 ){
111960 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
111961 VdbeCoverage(v);
111962 }
111963 if( zStartAff ){
111964 if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){
111965 /* Since the comparison is to be performed with no conversions
111966 ** applied to the operands, set the affinity to apply to pRight to
@@ -111908,86 +111971,76 @@
111971 zStartAff[nEq] = SQLITE_AFF_NONE;
111972 }
111973 }
111974 nConstraint++;
111975 testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
111976 }else if( bSeekPastNull ){
111977 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
111978 nConstraint++;
111979 startEq = 0;
111980 start_constraints = 1;
111981 }
111982 codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
111983 op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
111984 assert( op!=0 );
 
 
 
 
 
 
111985 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111986 VdbeCoverage(v);
111987 VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
111988 VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
111989 VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
111990 VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
111991 VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
111992 VdbeCoverageIf(v, op==OP_SeekLT); testcase( op==OP_SeekLT );
111993
111994 /* Load the value for the inequality constraint at the end of the
111995 ** range (if any).
111996 */
111997 nConstraint = nEq;
111998 if( pRangeEnd ){
111999 Expr *pRight = pRangeEnd->pExpr->pRight;
112000 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
112001 sqlite3ExprCode(pParse, pRight, regBase+nEq);
112002 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
112003 && sqlite3ExprCanBeNull(pRight)
112004 ){
112005 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
112006 VdbeCoverage(v);
112007 }
112008 if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
112009 && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
112010 ){
112011 codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
112012 }
112013 nConstraint++;
112014 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
112015 }else if( bStopAtNull ){
112016 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
112017 endEq = 0;
112018 nConstraint++;
112019 }
112020 sqlite3DbFree(db, zStartAff);
112021
112022 /* Top of the loop body */
112023 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
112024
112025 /* Check if the index cursor is past the end of the range. */
112026 if( nConstraint ){
112027 op = aEndOp[bRev*2 + endEq];
 
 
 
112028 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
112029 testcase( op==OP_IdxGT ); VdbeCoverageIf(v, op==OP_IdxGT );
112030 testcase( op==OP_IdxGE ); VdbeCoverageIf(v, op==OP_IdxGE );
112031 testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT );
112032 testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE );
112033 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112034
112035 /* Seek the table cursor, if required */
112036 disableTerm(pLevel, pRangeStart);
112037 disableTerm(pLevel, pRangeEnd);
112038 if( omitTable ){
112039 /* pIdx is a covering index. No need to access the main table. */
112040 }else if( HasRowid(pIdx->pTable) ){
112041 iRowidReg = ++pParse->nMem;
112042 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
112043 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
112044 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
112045 }else{
112046 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
@@ -111995,11 +112048,11 @@
112048 for(j=0; j<pPk->nKeyCol; j++){
112049 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
112050 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
112051 }
112052 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
112053 iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
112054 }
112055
112056 /* Record the instruction used to terminate the loop. Disable
112057 ** WHERE clause terms made redundant by the index range scan.
112058 */
@@ -112009,10 +112062,12 @@
112062 pLevel->op = OP_Prev;
112063 }else{
112064 pLevel->op = OP_Next;
112065 }
112066 pLevel->p1 = iIdxCur;
112067 assert( (WHERE_UNQ_WANTED>>16)==1 );
112068 pLevel->p3 = (pLoop->wsFlags>>16)&1;
112069 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
112070 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112071 }else{
112072 assert( pLevel->p5==0 );
112073 }
@@ -112177,10 +112232,11 @@
112232 int r;
112233 r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
112234 regRowid, 0);
112235 sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
112236 sqlite3VdbeCurrentAddr(v)+2, r, iSet);
112237 VdbeCoverage(v);
112238 }
112239 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
112240
112241 /* The pSubWInfo->untestedTerms flag means that this OR term
112242 ** contained one or more AND term from a notReady table. The
@@ -112245,10 +112301,12 @@
112301 pLevel->op = OP_Noop;
112302 }else{
112303 pLevel->op = aStep[bRev];
112304 pLevel->p1 = iCur;
112305 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112306 VdbeCoverageIf(v, bRev==0);
112307 VdbeCoverageIf(v, bRev!=0);
112308 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112309 }
112310 }
112311
112312 /* Insert code to test every subexpression that can be completely
@@ -112326,11 +112384,10 @@
112384 assert( pTerm->pExpr );
112385 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
112386 pTerm->wtFlags |= TERM_CODED;
112387 }
112388 }
 
112389
112390 return pLevel->notReady;
112391 }
112392
112393 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -112813,16 +112870,17 @@
112870 assert(
112871 (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112872 || nInMul==0
112873 );
112874 pNew->wsFlags |= WHERE_COLUMN_EQ;
112875 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1)){
 
 
 
112876 assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
112877 if( iCol>=0 && pProbe->onError==OE_None ){
112878 pNew->wsFlags |= WHERE_UNQ_WANTED;
112879 }else{
112880 pNew->wsFlags |= WHERE_ONEROW;
112881 }
112882 }
112883 pNew->u.btree.nEq++;
112884 pNew->nOut = nRowEst + nInMul;
112885 }else if( pTerm->eOperator & (WO_ISNULL) ){
112886 pNew->wsFlags |= WHERE_COLUMN_NULL;
@@ -113697,13 +113755,16 @@
113755 /* Mark off any other ORDER BY terms that reference pLoop */
113756 if( isOrderDistinct ){
113757 orderDistinctMask |= pLoop->maskSelf;
113758 for(i=0; i<nOrderBy; i++){
113759 Expr *p;
113760 Bitmask mTerm;
113761 if( MASKBIT(i) & obSat ) continue;
113762 p = pOrderBy->a[i].pExpr;
113763 mTerm = exprTableUsage(&pWInfo->sMaskSet,p);
113764 if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue;
113765 if( (mTerm&~orderDistinctMask)==0 ){
113766 obSat |= MASKBIT(i);
113767 }
113768 }
113769 }
113770 } /* End the loop over all WhereLoops from outer-most down to inner-most */
@@ -114261,11 +114322,10 @@
114322 ** subexpression is separated by an AND operator.
114323 */
114324 initMaskSet(pMaskSet);
114325 whereClauseInit(&pWInfo->sWC, pWInfo);
114326 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
 
114327
114328 /* Special case: a WHERE clause that is constant. Evaluate the
114329 ** expression and either jump over all of the code or fall thru.
114330 */
114331 for(ii=0; ii<sWLB.pWC->nTerm; ii++){
@@ -114323,26 +114383,10 @@
114383 exprAnalyzeAll(pTabList, &pWInfo->sWC);
114384 if( db->mallocFailed ){
114385 goto whereBeginError;
114386 }
114387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114388 if( wctrlFlags & WHERE_WANT_DISTINCT ){
114389 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
114390 /* The DISTINCT marking is pointless. Ignore it. */
114391 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
114392 }else if( pOrderBy==0 ){
@@ -114550,11 +114594,11 @@
114594 assert( iIndexCur>=0 );
114595 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
114596 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
114597 VdbeComment((v, "%s", pIx->zName));
114598 }
114599 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
114600 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
114601 }
114602 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
114603 if( db->mallocFailed ) goto whereBeginError;
114604
@@ -114612,20 +114656,27 @@
114656 int addr;
114657 pLevel = &pWInfo->a[i];
114658 pLoop = pLevel->pWLoop;
114659 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114660 if( pLevel->op!=OP_Noop ){
114661 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
114662 sqlite3VdbeChangeP5(v, pLevel->p5);
114663 VdbeCoverage(v);
114664 VdbeCoverageIf(v, pLevel->op==OP_Next);
114665 VdbeCoverageIf(v, pLevel->op==OP_Prev);
114666 VdbeCoverageIf(v, pLevel->op==OP_VNext);
114667 }
114668 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
114669 struct InLoop *pIn;
114670 int j;
114671 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
114672 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
114673 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
114674 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
114675 VdbeCoverage(v);
114676 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
114677 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
114678 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114679 }
114680 sqlite3DbFree(db, pLevel->u.in.aInLoop);
114681 }
114682 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
@@ -114634,11 +114685,11 @@
114685 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114686 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114687 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114688 }
114689 if( pLevel->iLeftJoin ){
114690 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
114691 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114692 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114693 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114694 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
114695 }
@@ -114661,15 +114712,41 @@
114712 */
114713 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
114714
114715 assert( pWInfo->nLevel<=pTabList->nSrc );
114716 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
114717 int k, last;
114718 VdbeOp *pOp;
114719 Index *pIdx = 0;
114720 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
114721 Table *pTab = pTabItem->pTab;
114722 assert( pTab!=0 );
114723 pLoop = pLevel->pWLoop;
114724
114725 /* For a co-routine, change all OP_Column references to the table of
114726 ** the co-routine into OP_SCopy of result contained in a register.
114727 ** OP_Rowid becomes OP_Null.
114728 */
114729 if( pTabItem->viaCoroutine ){
114730 last = sqlite3VdbeCurrentAddr(v);
114731 k = pLevel->addrBody;
114732 pOp = sqlite3VdbeGetOp(v, k);
114733 for(; k<last; k++, pOp++){
114734 if( pOp->p1!=pLevel->iTabCur ) continue;
114735 if( pOp->opcode==OP_Column ){
114736 pOp->opcode = OP_SCopy;
114737 pOp->p1 = pOp->p2 + pTabItem->regResult;
114738 pOp->p2 = pOp->p3;
114739 pOp->p3 = 0;
114740 }else if( pOp->opcode==OP_Rowid ){
114741 pOp->opcode = OP_Null;
114742 pOp->p1 = 0;
114743 pOp->p3 = 0;
114744 }
114745 }
114746 continue;
114747 }
114748
114749 /* Close all of the cursors that were opened by sqlite3WhereBegin.
114750 ** Except, do not close cursors that will be reused by the OR optimization
114751 ** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114752 ** created for the ONEPASS optimization.
@@ -114705,13 +114782,10 @@
114782 pIdx = pLoop->u.btree.pIndex;
114783 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
114784 pIdx = pLevel->u.pCovidx;
114785 }
114786 if( pIdx && !db->mallocFailed ){
 
 
 
114787 last = sqlite3VdbeCurrentAddr(v);
114788 k = pLevel->addrBody;
114789 pOp = sqlite3VdbeGetOp(v, k);
114790 for(; k<last; k++, pOp++){
114791 if( pOp->p1!=pLevel->iTabCur ) continue;
@@ -117121,33 +117195,54 @@
117195 sqlite3ExplainFinish(pParse->pVdbe);
117196 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
117197 }
117198 break;
117199 case 112: /* select ::= with selectnowith */
117200 {
117201 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
117202 if( p ){
117203 int cnt = 0, mxSelect;
117204 p->pWith = yymsp[-1].minor.yy59;
117205 if( p->pPrior ){
117206 pNext = 0;
117207 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
117208 pLoop->pNext = pNext;
117209 pLoop->selFlags |= SF_Compound;
117210 }
117211 mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
117212 if( mxSelect && cnt>mxSelect ){
117213 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
117214 }
117215 }
117216 }else{
117217 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
117218 }
117219 yygotominor.yy3 = p;
117220 }
117221 break;
117222 case 113: /* selectnowith ::= oneselect */
117223 case 119: /* oneselect ::= values */ yytestcase(yyruleno==119);
117224 {yygotominor.yy3 = yymsp[0].minor.yy3;}
117225 break;
117226 case 114: /* selectnowith ::= selectnowith multiselect_op oneselect */
117227 {
117228 Select *pRhs = yymsp[0].minor.yy3;
117229 if( pRhs && pRhs->pPrior ){
117230 SrcList *pFrom;
117231 Token x;
117232 x.n = 0;
117233 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
117234 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
117235 }
117236 if( pRhs ){
117237 pRhs->op = (u8)yymsp[-1].minor.yy328;
117238 pRhs->pPrior = yymsp[-2].minor.yy3;
117239 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
117240 }else{
117241 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
117242 }
117243 yygotominor.yy3 = pRhs;
117244 }
117245 break;
117246 case 116: /* multiselect_op ::= UNION ALL */
117247 {yygotominor.yy328 = TK_ALL;}
117248 break;
@@ -122711,10 +122806,25 @@
122806 case SQLITE_TESTCTRL_NEVER_CORRUPT: {
122807 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
122808 break;
122809 }
122810
122811
122812 /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
122813 **
122814 ** Set the VDBE coverage callback function to xCallback with context
122815 ** pointer ptr.
122816 */
122817 case SQLITE_TESTCTRL_VDBE_COVERAGE: {
122818 #ifdef SQLITE_VDBE_COVERAGE
122819 typedef void (*branch_callback)(void*,int,u8,u8);
122820 sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
122821 sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
122822 #endif
122823 break;
122824 }
122825
122826 }
122827 va_end(ap);
122828 #endif /* SQLITE_OMIT_BUILTIN_TEST */
122829 return rc;
122830 }
122831
+5 -4
--- 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.3.1"
111
-#define SQLITE_VERSION_NUMBER 3008003
112
-#define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
110
+#define SQLITE_VERSION "3.8.4"
111
+#define SQLITE_VERSION_NUMBER 3008004
112
+#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -6120,11 +6120,12 @@
61206120
#define SQLITE_TESTCTRL_ISKEYWORD 16
61216121
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
61226122
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
61236123
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
61246124
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6125
-#define SQLITE_TESTCTRL_LAST 20
6125
+#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6126
+#define SQLITE_TESTCTRL_LAST 21
61266127
61276128
/*
61286129
** CAPI3REF: SQLite Runtime Status
61296130
**
61306131
** ^This interface is used to retrieve runtime status information
61316132
--- 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.3.1"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -6120,11 +6120,12 @@
6120 #define SQLITE_TESTCTRL_ISKEYWORD 16
6121 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6122 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6123 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6124 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6125 #define SQLITE_TESTCTRL_LAST 20
 
6126
6127 /*
6128 ** CAPI3REF: SQLite Runtime Status
6129 **
6130 ** ^This interface is used to retrieve runtime status information
6131
--- 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.4"
111 #define SQLITE_VERSION_NUMBER 3008004
112 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -6120,11 +6120,12 @@
6120 #define SQLITE_TESTCTRL_ISKEYWORD 16
6121 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6122 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6123 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6124 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6125 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6126 #define SQLITE_TESTCTRL_LAST 21
6127
6128 /*
6129 ** CAPI3REF: SQLite Runtime Status
6130 **
6131 ** ^This interface is used to retrieve runtime status information
6132
+3 -3
--- src/stash.c
+++ src/stash.c
@@ -311,11 +311,11 @@
311311
int isLink = db_column_int(&q, 3);
312312
int isBin1, isBin2;
313313
const char *zOrig = db_column_text(&q, 4);
314314
const char *zNew = db_column_text(&q, 5);
315315
char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
316
- Blob delta, a, b, disk;
316
+ Blob a, b;
317317
if( rid==0 ){
318318
db_ephemeral_blob(&q, 6, &a);
319319
fossil_print("ADDED %s\n", zNew);
320320
diff_print_index(zNew, diffFlags);
321321
isBin1 = 0;
@@ -337,10 +337,11 @@
337337
isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
338338
isBin2 = 0;
339339
diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
340340
zBinGlob, fIncludeBinary, diffFlags);
341341
}else{
342
+ Blob delta, disk;
342343
int isOrigLink = file_wd_islink(zOPath);
343344
db_ephemeral_blob(&q, 6, &delta);
344345
if( fBaseline==0 ){
345346
if( isOrigLink ){
346347
blob_read_link(&disk, zOPath);
@@ -363,12 +364,12 @@
363364
zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
364365
blob_reset(&a);
365366
blob_reset(&b);
366367
}
367368
if( !fBaseline ) blob_reset(&disk);
369
+ blob_reset(&delta);
368370
}
369
- blob_reset(&delta);
370371
}
371372
db_finalize(&q);
372373
}
373374
374375
/*
@@ -568,11 +569,10 @@
568569
if( memcmp(zCmd, "drop", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0 ){
569570
int allFlag = find_option("all", "a", 0)!=0;
570571
if( allFlag ){
571572
Blob ans;
572573
char cReply;
573
- blob_zero(&ans);
574574
prompt_user("This action is not undoable. Continue (y/N)? ", &ans);
575575
cReply = blob_str(&ans)[0];
576576
if( cReply=='y' || cReply=='Y' ){
577577
db_multi_exec("DELETE FROM stash; DELETE FROM stashfile;");
578578
}
579579
--- src/stash.c
+++ src/stash.c
@@ -311,11 +311,11 @@
311 int isLink = db_column_int(&q, 3);
312 int isBin1, isBin2;
313 const char *zOrig = db_column_text(&q, 4);
314 const char *zNew = db_column_text(&q, 5);
315 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
316 Blob delta, a, b, disk;
317 if( rid==0 ){
318 db_ephemeral_blob(&q, 6, &a);
319 fossil_print("ADDED %s\n", zNew);
320 diff_print_index(zNew, diffFlags);
321 isBin1 = 0;
@@ -337,10 +337,11 @@
337 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
338 isBin2 = 0;
339 diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
340 zBinGlob, fIncludeBinary, diffFlags);
341 }else{
 
342 int isOrigLink = file_wd_islink(zOPath);
343 db_ephemeral_blob(&q, 6, &delta);
344 if( fBaseline==0 ){
345 if( isOrigLink ){
346 blob_read_link(&disk, zOPath);
@@ -363,12 +364,12 @@
363 zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
364 blob_reset(&a);
365 blob_reset(&b);
366 }
367 if( !fBaseline ) blob_reset(&disk);
 
368 }
369 blob_reset(&delta);
370 }
371 db_finalize(&q);
372 }
373
374 /*
@@ -568,11 +569,10 @@
568 if( memcmp(zCmd, "drop", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0 ){
569 int allFlag = find_option("all", "a", 0)!=0;
570 if( allFlag ){
571 Blob ans;
572 char cReply;
573 blob_zero(&ans);
574 prompt_user("This action is not undoable. Continue (y/N)? ", &ans);
575 cReply = blob_str(&ans)[0];
576 if( cReply=='y' || cReply=='Y' ){
577 db_multi_exec("DELETE FROM stash; DELETE FROM stashfile;");
578 }
579
--- src/stash.c
+++ src/stash.c
@@ -311,11 +311,11 @@
311 int isLink = db_column_int(&q, 3);
312 int isBin1, isBin2;
313 const char *zOrig = db_column_text(&q, 4);
314 const char *zNew = db_column_text(&q, 5);
315 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
316 Blob a, b;
317 if( rid==0 ){
318 db_ephemeral_blob(&q, 6, &a);
319 fossil_print("ADDED %s\n", zNew);
320 diff_print_index(zNew, diffFlags);
321 isBin1 = 0;
@@ -337,10 +337,11 @@
337 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
338 isBin2 = 0;
339 diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
340 zBinGlob, fIncludeBinary, diffFlags);
341 }else{
342 Blob delta, disk;
343 int isOrigLink = file_wd_islink(zOPath);
344 db_ephemeral_blob(&q, 6, &delta);
345 if( fBaseline==0 ){
346 if( isOrigLink ){
347 blob_read_link(&disk, zOPath);
@@ -363,12 +364,12 @@
364 zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
365 blob_reset(&a);
366 blob_reset(&b);
367 }
368 if( !fBaseline ) blob_reset(&disk);
369 blob_reset(&delta);
370 }
 
371 }
372 db_finalize(&q);
373 }
374
375 /*
@@ -568,11 +569,10 @@
569 if( memcmp(zCmd, "drop", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0 ){
570 int allFlag = find_option("all", "a", 0)!=0;
571 if( allFlag ){
572 Blob ans;
573 char cReply;
 
574 prompt_user("This action is not undoable. Continue (y/N)? ", &ans);
575 cReply = blob_str(&ans)[0];
576 if( cReply=='y' || cReply=='Y' ){
577 db_multi_exec("DELETE FROM stash; DELETE FROM stashfile;");
578 }
579
+1
--- src/stat.c
+++ src/stat.c
@@ -16,10 +16,11 @@
1616
*******************************************************************************
1717
**
1818
** This file contains code to implement the stat web page
1919
**
2020
*/
21
+#include "VERSION.h"
2122
#include "config.h"
2223
#include <string.h>
2324
#include "stat.h"
2425
2526
/*
2627
--- src/stat.c
+++ src/stat.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This file contains code to implement the stat web page
19 **
20 */
 
21 #include "config.h"
22 #include <string.h>
23 #include "stat.h"
24
25 /*
26
--- src/stat.c
+++ src/stat.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This file contains code to implement the stat web page
19 **
20 */
21 #include "VERSION.h"
22 #include "config.h"
23 #include <string.h>
24 #include "stat.h"
25
26 /*
27
--- src/style.c
+++ src/style.c
@@ -16,10 +16,11 @@
1616
*******************************************************************************
1717
**
1818
** This file contains code to implement the basic web page look and feel.
1919
**
2020
*/
21
+#include "VERSION.h"
2122
#include "config.h"
2223
#include "style.h"
2324
2425
2526
/*
2627
--- src/style.c
+++ src/style.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This file contains code to implement the basic web page look and feel.
19 **
20 */
 
21 #include "config.h"
22 #include "style.h"
23
24
25 /*
26
--- src/style.c
+++ src/style.c
@@ -16,10 +16,11 @@
16 *******************************************************************************
17 **
18 ** This file contains code to implement the basic web page look and feel.
19 **
20 */
21 #include "VERSION.h"
22 #include "config.h"
23 #include "style.h"
24
25
26 /*
27
+1 -1
--- src/th.h
+++ src/th.h
@@ -7,15 +7,15 @@
77
/*
88
** Before creating an interpreter, the application must allocate and
99
** populate an instance of the following structure. It must remain valid
1010
** for the lifetime of the interpreter.
1111
*/
12
+typedef struct Th_Vtab Th_Vtab;
1213
struct Th_Vtab {
1314
void *(*xMalloc)(unsigned int);
1415
void (*xFree)(void *);
1516
};
16
-typedef struct Th_Vtab Th_Vtab;
1717
1818
/*
1919
** Opaque handle for interpeter.
2020
*/
2121
typedef struct Th_Interp Th_Interp;
2222
--- src/th.h
+++ src/th.h
@@ -7,15 +7,15 @@
7 /*
8 ** Before creating an interpreter, the application must allocate and
9 ** populate an instance of the following structure. It must remain valid
10 ** for the lifetime of the interpreter.
11 */
 
12 struct Th_Vtab {
13 void *(*xMalloc)(unsigned int);
14 void (*xFree)(void *);
15 };
16 typedef struct Th_Vtab Th_Vtab;
17
18 /*
19 ** Opaque handle for interpeter.
20 */
21 typedef struct Th_Interp Th_Interp;
22
--- src/th.h
+++ src/th.h
@@ -7,15 +7,15 @@
7 /*
8 ** Before creating an interpreter, the application must allocate and
9 ** populate an instance of the following structure. It must remain valid
10 ** for the lifetime of the interpreter.
11 */
12 typedef struct Th_Vtab Th_Vtab;
13 struct Th_Vtab {
14 void *(*xMalloc)(unsigned int);
15 void (*xFree)(void *);
16 };
 
17
18 /*
19 ** Opaque handle for interpeter.
20 */
21 typedef struct Th_Interp Th_Interp;
22
+11 -13
--- src/update.c
+++ src/update.c
@@ -717,16 +717,12 @@
717717
db_multi_exec(
718718
"REPLACE INTO torevert VALUES(%B);"
719719
"INSERT OR IGNORE INTO torevert"
720720
" SELECT pathname"
721721
" FROM vfile"
722
- " WHERE origname IN(%B)"
723
- " UNION ALL"
724
- " SELECT origname"
725
- " FROM vfile"
726
- " WHERE pathname IN(%B) AND origname IS NOT NULL;",
727
- &fname, &fname, &fname
722
+ " WHERE origname=%B;",
723
+ &fname, &fname
728724
);
729725
blob_reset(&fname);
730726
}
731727
}else{
732728
int vid;
@@ -735,17 +731,19 @@
735731
db_multi_exec(
736732
"DELETE FROM vmerge;"
737733
"INSERT OR IGNORE INTO torevert "
738734
" SELECT pathname"
739735
" FROM vfile "
740
- " WHERE chnged OR deleted OR rid=0 OR pathname!=origname "
741
- " UNION ALL "
742
- " SELECT origname"
743
- " FROM vfile"
744
- " WHERE origname!=pathname;"
736
+ " WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
745737
);
746738
}
739
+ db_multi_exec(
740
+ "INSERT OR IGNORE INTO torevert"
741
+ " SELECT origname"
742
+ " FROM vfile"
743
+ " WHERE origname!=pathname AND pathname IN (SELECT name FROM torevert);"
744
+ );
747745
blob_zero(&record);
748746
db_prepare(&q, "SELECT name FROM torevert");
749747
if( zRevision==0 ){
750748
int vid = db_lget_int("checkout", 0);
751749
zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
@@ -766,13 +764,13 @@
766764
undo_save(zFile);
767765
file_delete(zFull);
768766
fossil_print("DELETE: %s\n", zFile);
769767
}
770768
db_multi_exec(
771
- "UPDATE vfile"
769
+ "UPDATE OR REPLACE vfile"
772770
" SET pathname=origname, origname=NULL"
773
- " WHERE pathname=%Q AND origname!=pathname AND origname IS NOT NULL;"
771
+ " WHERE pathname=%Q AND origname!=pathname;"
774772
"DELETE FROM vfile WHERE pathname=%Q",
775773
zFile, zFile
776774
);
777775
}else{
778776
sqlite3_int64 mtime;
779777
--- src/update.c
+++ src/update.c
@@ -717,16 +717,12 @@
717 db_multi_exec(
718 "REPLACE INTO torevert VALUES(%B);"
719 "INSERT OR IGNORE INTO torevert"
720 " SELECT pathname"
721 " FROM vfile"
722 " WHERE origname IN(%B)"
723 " UNION ALL"
724 " SELECT origname"
725 " FROM vfile"
726 " WHERE pathname IN(%B) AND origname IS NOT NULL;",
727 &fname, &fname, &fname
728 );
729 blob_reset(&fname);
730 }
731 }else{
732 int vid;
@@ -735,17 +731,19 @@
735 db_multi_exec(
736 "DELETE FROM vmerge;"
737 "INSERT OR IGNORE INTO torevert "
738 " SELECT pathname"
739 " FROM vfile "
740 " WHERE chnged OR deleted OR rid=0 OR pathname!=origname "
741 " UNION ALL "
742 " SELECT origname"
743 " FROM vfile"
744 " WHERE origname!=pathname;"
745 );
746 }
 
 
 
 
 
 
747 blob_zero(&record);
748 db_prepare(&q, "SELECT name FROM torevert");
749 if( zRevision==0 ){
750 int vid = db_lget_int("checkout", 0);
751 zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
@@ -766,13 +764,13 @@
766 undo_save(zFile);
767 file_delete(zFull);
768 fossil_print("DELETE: %s\n", zFile);
769 }
770 db_multi_exec(
771 "UPDATE vfile"
772 " SET pathname=origname, origname=NULL"
773 " WHERE pathname=%Q AND origname!=pathname AND origname IS NOT NULL;"
774 "DELETE FROM vfile WHERE pathname=%Q",
775 zFile, zFile
776 );
777 }else{
778 sqlite3_int64 mtime;
779
--- src/update.c
+++ src/update.c
@@ -717,16 +717,12 @@
717 db_multi_exec(
718 "REPLACE INTO torevert VALUES(%B);"
719 "INSERT OR IGNORE INTO torevert"
720 " SELECT pathname"
721 " FROM vfile"
722 " WHERE origname=%B;",
723 &fname, &fname
 
 
 
 
724 );
725 blob_reset(&fname);
726 }
727 }else{
728 int vid;
@@ -735,17 +731,19 @@
731 db_multi_exec(
732 "DELETE FROM vmerge;"
733 "INSERT OR IGNORE INTO torevert "
734 " SELECT pathname"
735 " FROM vfile "
736 " WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
 
 
 
 
737 );
738 }
739 db_multi_exec(
740 "INSERT OR IGNORE INTO torevert"
741 " SELECT origname"
742 " FROM vfile"
743 " WHERE origname!=pathname AND pathname IN (SELECT name FROM torevert);"
744 );
745 blob_zero(&record);
746 db_prepare(&q, "SELECT name FROM torevert");
747 if( zRevision==0 ){
748 int vid = db_lget_int("checkout", 0);
749 zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
@@ -766,13 +764,13 @@
764 undo_save(zFile);
765 file_delete(zFull);
766 fossil_print("DELETE: %s\n", zFile);
767 }
768 db_multi_exec(
769 "UPDATE OR REPLACE vfile"
770 " SET pathname=origname, origname=NULL"
771 " WHERE pathname=%Q AND origname!=pathname;"
772 "DELETE FROM vfile WHERE pathname=%Q",
773 zFile, zFile
774 );
775 }else{
776 sqlite3_int64 mtime;
777
+23 -3
--- src/vfile.c
+++ src/vfile.c
@@ -486,15 +486,25 @@
486486
blob_appendf(pPath, "/%s", zUtf8);
487487
zPath = blob_str(pPath);
488488
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
489489
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
490490
/* do nothing */
491
+#ifdef _DIRENT_HAVE_D_TYPE
492
+ }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
493
+ ? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
494
+#else
491495
}else if( file_wd_isdir(zPath)==1 ){
496
+#endif
492497
if( !vfile_top_of_checkout(zPath) ){
493498
vfile_scan(pPath, nPrefix, scanFlags, pIgnore1, pIgnore2);
494499
}
500
+#ifdef _DIRENT_HAVE_D_TYPE
501
+ }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
502
+ ? (file_wd_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
503
+#else
495504
}else if( file_wd_isfile_or_link(zPath) ){
505
+#endif
496506
if( (scanFlags & SCAN_TEMP)==0 || is_temporary_file(zUtf8) ){
497507
db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
498508
db_step(&ins);
499509
db_reset(&ins);
500510
}
@@ -593,11 +603,16 @@
593603
zPath = blob_str(pPath);
594604
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
595605
glob_match(pIgnore2, &zPath[nPrefix+1]) ||
596606
glob_match(pIgnore3, &zPath[nPrefix+1]) ){
597607
/* do nothing */
608
+#ifdef _DIRENT_HAVE_D_TYPE
609
+ }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
610
+ ? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
611
+#else
598612
}else if( file_wd_isdir(zPath)==1 ){
613
+#endif
599614
if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
600615
char *zSavePath = mprintf("%s", zPath);
601616
int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
602617
pIgnore2, pIgnore3);
603618
db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
@@ -605,11 +620,16 @@
605620
db_step(&ins);
606621
db_reset(&ins);
607622
fossil_free(zSavePath);
608623
result += count; /* found X normal files? */
609624
}
625
+#ifdef _DIRENT_HAVE_D_TYPE
626
+ }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
627
+ ? (file_wd_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
628
+#else
610629
}else if( file_wd_isfile_or_link(zPath) ){
630
+#endif
611631
db_bind_text(&upd, ":file", zOrigPath);
612632
db_step(&upd);
613633
db_reset(&upd);
614634
result++; /* found 1 normal file */
615635
}
@@ -704,11 +724,11 @@
704724
const char *zOrigName = db_column_text(&q, 2);
705725
char zBuf[100];
706726
Blob file;
707727
708728
if( zOrigName ) zName = zOrigName;
709
- if( rid>0 ){
729
+ if( rid>0 || vid==0 ){
710730
md5sum_step_text(zName, -1);
711731
blob_zero(&file);
712732
content_get(rid, &file);
713733
sqlite3_snprintf(sizeof(zBuf), zBuf, " %d\n", blob_size(&file));
714734
md5sum_step_text(zBuf, -1);
@@ -813,13 +833,13 @@
813833
db_must_be_within_tree();
814834
815835
db_prepare(&q, "SELECT pathname, origname, rid, is_selected(id)"
816836
" FROM vfile"
817837
" WHERE (NOT deleted OR NOT is_selected(id))"
818
- " AND rid>0 AND vid=%d"
838
+ " %s AND vid=%d"
819839
" ORDER BY if_selected(id,pathname,origname) /*scan*/",
820
- vid);
840
+ (vid ? "AND rid>0" : ""), vid);
821841
blob_zero(&file);
822842
md5sum_init();
823843
while( db_step(&q)==SQLITE_ROW ){
824844
const char *zName = db_column_text(&q, 0);
825845
const char *zOrigName = db_column_text(&q, 1);
826846
--- src/vfile.c
+++ src/vfile.c
@@ -486,15 +486,25 @@
486 blob_appendf(pPath, "/%s", zUtf8);
487 zPath = blob_str(pPath);
488 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
489 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
490 /* do nothing */
 
 
 
 
491 }else if( file_wd_isdir(zPath)==1 ){
 
492 if( !vfile_top_of_checkout(zPath) ){
493 vfile_scan(pPath, nPrefix, scanFlags, pIgnore1, pIgnore2);
494 }
 
 
 
 
495 }else if( file_wd_isfile_or_link(zPath) ){
 
496 if( (scanFlags & SCAN_TEMP)==0 || is_temporary_file(zUtf8) ){
497 db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
498 db_step(&ins);
499 db_reset(&ins);
500 }
@@ -593,11 +603,16 @@
593 zPath = blob_str(pPath);
594 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
595 glob_match(pIgnore2, &zPath[nPrefix+1]) ||
596 glob_match(pIgnore3, &zPath[nPrefix+1]) ){
597 /* do nothing */
 
 
 
 
598 }else if( file_wd_isdir(zPath)==1 ){
 
599 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
600 char *zSavePath = mprintf("%s", zPath);
601 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
602 pIgnore2, pIgnore3);
603 db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
@@ -605,11 +620,16 @@
605 db_step(&ins);
606 db_reset(&ins);
607 fossil_free(zSavePath);
608 result += count; /* found X normal files? */
609 }
 
 
 
 
610 }else if( file_wd_isfile_or_link(zPath) ){
 
611 db_bind_text(&upd, ":file", zOrigPath);
612 db_step(&upd);
613 db_reset(&upd);
614 result++; /* found 1 normal file */
615 }
@@ -704,11 +724,11 @@
704 const char *zOrigName = db_column_text(&q, 2);
705 char zBuf[100];
706 Blob file;
707
708 if( zOrigName ) zName = zOrigName;
709 if( rid>0 ){
710 md5sum_step_text(zName, -1);
711 blob_zero(&file);
712 content_get(rid, &file);
713 sqlite3_snprintf(sizeof(zBuf), zBuf, " %d\n", blob_size(&file));
714 md5sum_step_text(zBuf, -1);
@@ -813,13 +833,13 @@
813 db_must_be_within_tree();
814
815 db_prepare(&q, "SELECT pathname, origname, rid, is_selected(id)"
816 " FROM vfile"
817 " WHERE (NOT deleted OR NOT is_selected(id))"
818 " AND rid>0 AND vid=%d"
819 " ORDER BY if_selected(id,pathname,origname) /*scan*/",
820 vid);
821 blob_zero(&file);
822 md5sum_init();
823 while( db_step(&q)==SQLITE_ROW ){
824 const char *zName = db_column_text(&q, 0);
825 const char *zOrigName = db_column_text(&q, 1);
826
--- src/vfile.c
+++ src/vfile.c
@@ -486,15 +486,25 @@
486 blob_appendf(pPath, "/%s", zUtf8);
487 zPath = blob_str(pPath);
488 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
489 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
490 /* do nothing */
491 #ifdef _DIRENT_HAVE_D_TYPE
492 }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
493 ? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
494 #else
495 }else if( file_wd_isdir(zPath)==1 ){
496 #endif
497 if( !vfile_top_of_checkout(zPath) ){
498 vfile_scan(pPath, nPrefix, scanFlags, pIgnore1, pIgnore2);
499 }
500 #ifdef _DIRENT_HAVE_D_TYPE
501 }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
502 ? (file_wd_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
503 #else
504 }else if( file_wd_isfile_or_link(zPath) ){
505 #endif
506 if( (scanFlags & SCAN_TEMP)==0 || is_temporary_file(zUtf8) ){
507 db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
508 db_step(&ins);
509 db_reset(&ins);
510 }
@@ -593,11 +603,16 @@
603 zPath = blob_str(pPath);
604 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
605 glob_match(pIgnore2, &zPath[nPrefix+1]) ||
606 glob_match(pIgnore3, &zPath[nPrefix+1]) ){
607 /* do nothing */
608 #ifdef _DIRENT_HAVE_D_TYPE
609 }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
610 ? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
611 #else
612 }else if( file_wd_isdir(zPath)==1 ){
613 #endif
614 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
615 char *zSavePath = mprintf("%s", zPath);
616 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
617 pIgnore2, pIgnore3);
618 db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
@@ -605,11 +620,16 @@
620 db_step(&ins);
621 db_reset(&ins);
622 fossil_free(zSavePath);
623 result += count; /* found X normal files? */
624 }
625 #ifdef _DIRENT_HAVE_D_TYPE
626 }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
627 ? (file_wd_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
628 #else
629 }else if( file_wd_isfile_or_link(zPath) ){
630 #endif
631 db_bind_text(&upd, ":file", zOrigPath);
632 db_step(&upd);
633 db_reset(&upd);
634 result++; /* found 1 normal file */
635 }
@@ -704,11 +724,11 @@
724 const char *zOrigName = db_column_text(&q, 2);
725 char zBuf[100];
726 Blob file;
727
728 if( zOrigName ) zName = zOrigName;
729 if( rid>0 || vid==0 ){
730 md5sum_step_text(zName, -1);
731 blob_zero(&file);
732 content_get(rid, &file);
733 sqlite3_snprintf(sizeof(zBuf), zBuf, " %d\n", blob_size(&file));
734 md5sum_step_text(zBuf, -1);
@@ -813,13 +833,13 @@
833 db_must_be_within_tree();
834
835 db_prepare(&q, "SELECT pathname, origname, rid, is_selected(id)"
836 " FROM vfile"
837 " WHERE (NOT deleted OR NOT is_selected(id))"
838 " %s AND vid=%d"
839 " ORDER BY if_selected(id,pathname,origname) /*scan*/",
840 (vid ? "AND rid>0" : ""), vid);
841 blob_zero(&file);
842 md5sum_init();
843 while( db_step(&q)==SQLITE_ROW ){
844 const char *zName = db_column_text(&q, 0);
845 const char *zOrigName = db_column_text(&q, 1);
846
+85 -56
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -164,62 +164,68 @@
164164
** in aAllowedMarkup[].
165165
*/
166166
#define MARKUP_INVALID 0
167167
#define MARKUP_A 1
168168
#define MARKUP_ADDRESS 2
169
-#define MARKUP_B 3
170
-#define MARKUP_BIG 4
171
-#define MARKUP_BLOCKQUOTE 5
172
-#define MARKUP_BR 6
173
-#define MARKUP_CENTER 7
174
-#define MARKUP_CITE 8
175
-#define MARKUP_CODE 9
176
-#define MARKUP_COL 10
177
-#define MARKUP_COLGROUP 11
178
-#define MARKUP_DD 12
179
-#define MARKUP_DFN 13
180
-#define MARKUP_DIV 14
181
-#define MARKUP_DL 15
182
-#define MARKUP_DT 16
183
-#define MARKUP_EM 17
184
-#define MARKUP_FONT 18
185
-#define MARKUP_H1 19
186
-#define MARKUP_H2 20
187
-#define MARKUP_H3 21
188
-#define MARKUP_H4 22
189
-#define MARKUP_H5 23
190
-#define MARKUP_H6 24
191
-#define MARKUP_HR 25
192
-#define MARKUP_I 26
193
-#define MARKUP_IMG 27
194
-#define MARKUP_KBD 28
195
-#define MARKUP_LI 29
196
-#define MARKUP_NOBR 30
197
-#define MARKUP_NOWIKI 31
198
-#define MARKUP_OL 32
199
-#define MARKUP_P 33
200
-#define MARKUP_PRE 34
201
-#define MARKUP_S 35
202
-#define MARKUP_SAMP 36
203
-#define MARKUP_SMALL 37
204
-#define MARKUP_SPAN 38
205
-#define MARKUP_STRIKE 39
206
-#define MARKUP_STRONG 40
207
-#define MARKUP_SUB 41
208
-#define MARKUP_SUP 42
209
-#define MARKUP_TABLE 43
210
-#define MARKUP_TBODY 44
211
-#define MARKUP_TD 45
212
-#define MARKUP_TFOOT 46
213
-#define MARKUP_TH 47
214
-#define MARKUP_THEAD 48
215
-#define MARKUP_TR 49
216
-#define MARKUP_TT 50
217
-#define MARKUP_U 51
218
-#define MARKUP_UL 52
219
-#define MARKUP_VAR 53
220
-#define MARKUP_VERBATIM 54
169
+#define MARKUP_HTML5_ARTICLE 3
170
+#define MARKUP_HTML5_ASIDE 4
171
+#define MARKUP_B 5
172
+#define MARKUP_BIG 6
173
+#define MARKUP_BLOCKQUOTE 7
174
+#define MARKUP_BR 8
175
+#define MARKUP_CENTER 9
176
+#define MARKUP_CITE 10
177
+#define MARKUP_CODE 11
178
+#define MARKUP_COL 12
179
+#define MARKUP_COLGROUP 13
180
+#define MARKUP_DD 14
181
+#define MARKUP_DFN 15
182
+#define MARKUP_DIV 16
183
+#define MARKUP_DL 17
184
+#define MARKUP_DT 18
185
+#define MARKUP_EM 19
186
+#define MARKUP_FONT 20
187
+#define MARKUP_HTML5_FOOTER 21
188
+#define MARKUP_H1 22
189
+#define MARKUP_H2 23
190
+#define MARKUP_H3 24
191
+#define MARKUP_H4 25
192
+#define MARKUP_H5 26
193
+#define MARKUP_H6 27
194
+#define MARKUP_HTML5_HEADER 28
195
+#define MARKUP_HR 29
196
+#define MARKUP_I 30
197
+#define MARKUP_IMG 31
198
+#define MARKUP_KBD 32
199
+#define MARKUP_LI 33
200
+#define MARKUP_HTML5_NAV 34
201
+#define MARKUP_NOBR 35
202
+#define MARKUP_NOWIKI 36
203
+#define MARKUP_OL 37
204
+#define MARKUP_P 38
205
+#define MARKUP_PRE 39
206
+#define MARKUP_S 40
207
+#define MARKUP_SAMP 41
208
+#define MARKUP_HTML5_SECTION 42
209
+#define MARKUP_SMALL 43
210
+#define MARKUP_SPAN 44
211
+#define MARKUP_STRIKE 45
212
+#define MARKUP_STRONG 46
213
+#define MARKUP_SUB 47
214
+#define MARKUP_SUP 48
215
+#define MARKUP_TABLE 49
216
+#define MARKUP_TBODY 50
217
+#define MARKUP_TD 51
218
+#define MARKUP_TFOOT 52
219
+#define MARKUP_TH 53
220
+#define MARKUP_THEAD 54
221
+#define MARKUP_TR 55
222
+#define MARKUP_TT 56
223
+#define MARKUP_U 57
224
+#define MARKUP_UL 58
225
+#define MARKUP_VAR 59
226
+#define MARKUP_VERBATIM 60
221227
222228
/*
223229
** The various markup is divided into the following types:
224230
*/
225231
#define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -251,10 +257,15 @@
251257
} aMarkup[] = {
252258
{ 0, MARKUP_INVALID, 0, 0 },
253259
{ "a", MARKUP_A, MUTYPE_HYPERLINK,
254260
AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE },
255261
{ "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
262
+ { "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
263
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE },
264
+ { "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
265
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE },
266
+
256267
{ "b", MARKUP_B, MUTYPE_FONT, AMSK_STYLE },
257268
{ "big", MARKUP_BIG, MUTYPE_FONT, AMSK_STYLE },
258269
{ "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, AMSK_STYLE },
259270
{ "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
260271
{ "center", MARKUP_CENTER, MUTYPE_BLOCK, AMSK_STYLE },
@@ -272,10 +283,13 @@
272283
AMSK_COMPACT|AMSK_STYLE },
273284
{ "dt", MARKUP_DT, MUTYPE_LI, AMSK_STYLE },
274285
{ "em", MARKUP_EM, MUTYPE_FONT, AMSK_STYLE },
275286
{ "font", MARKUP_FONT, MUTYPE_FONT,
276287
AMSK_COLOR|AMSK_FACE|AMSK_SIZE|AMSK_STYLE },
288
+ { "footer", MARKUP_HTML5_FOOTER, MUTYPE_BLOCK,
289
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE },
290
+
277291
{ "h1", MARKUP_H1, MUTYPE_BLOCK,
278292
AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
279293
{ "h2", MARKUP_H2, MUTYPE_BLOCK,
280294
AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
281295
{ "h3", MARKUP_H3, MUTYPE_BLOCK,
@@ -284,10 +298,14 @@
284298
AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
285299
{ "h5", MARKUP_H5, MUTYPE_BLOCK,
286300
AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
287301
{ "h6", MARKUP_H6, MUTYPE_BLOCK,
288302
AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
303
+
304
+ { "header", MARKUP_HTML5_HEADER, MUTYPE_BLOCK,
305
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE },
306
+
289307
{ "hr", MARKUP_HR, MUTYPE_SINGLE,
290308
AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH|
291309
AMSK_STYLE|AMSK_CLASS },
292310
{ "i", MARKUP_I, MUTYPE_FONT, AMSK_STYLE },
293311
{ "img", MARKUP_IMG, MUTYPE_SINGLE,
@@ -294,19 +312,23 @@
294312
AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT|
295313
AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH|AMSK_STYLE },
296314
{ "kbd", MARKUP_KBD, MUTYPE_FONT, AMSK_STYLE },
297315
{ "li", MARKUP_LI, MUTYPE_LI,
298316
AMSK_TYPE|AMSK_VALUE|AMSK_STYLE },
317
+ { "nav", MARKUP_HTML5_NAV, MUTYPE_BLOCK,
318
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE },
299319
{ "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 },
300320
{ "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 },
301321
{ "ol", MARKUP_OL, MUTYPE_LIST,
302322
AMSK_START|AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE },
303323
{ "p", MARKUP_P, MUTYPE_BLOCK,
304324
AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
305325
{ "pre", MARKUP_PRE, MUTYPE_BLOCK, AMSK_STYLE },
306326
{ "s", MARKUP_S, MUTYPE_FONT, AMSK_STYLE },
307327
{ "samp", MARKUP_SAMP, MUTYPE_FONT, AMSK_STYLE },
328
+ { "section", MARKUP_HTML5_SECTION, MUTYPE_BLOCK,
329
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE },
308330
{ "small", MARKUP_SMALL, MUTYPE_FONT, AMSK_STYLE },
309331
{ "span", MARKUP_SPAN, MUTYPE_BLOCK,
310332
AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
311333
{ "strike", MARKUP_STRIKE, MUTYPE_FONT, AMSK_STYLE },
312334
{ "strong", MARKUP_STRONG, MUTYPE_FONT, AMSK_STYLE },
@@ -339,11 +361,10 @@
339361
AMSK_ID|AMSK_TYPE },
340362
};
341363
342364
void show_allowed_wiki_markup( void ){
343365
int i; /* loop over allowedAttr */
344
-
345366
for( i=1 ; i<=sizeof(aMarkup)/sizeof(aMarkup[0]) - 1 ; i++ ){
346367
@ &lt;%s(aMarkup[i].zName)&gt;
347368
}
348369
}
349370
@@ -1718,14 +1739,22 @@
17181739
z = blob_str(pIn);
17191740
for(i=0; fossil_isspace(z[i]); i++){}
17201741
if( z[i]!='<' ) return 0;
17211742
i++;
17221743
if( strncmp(&z[i],"title>", 6)!=0 ) return 0;
1723
- iStart = i+6;
1744
+ for(iStart=i+6; fossil_isspace(z[iStart]); iStart++){}
17241745
for(i=iStart; z[i] && (z[i]!='<' || strncmp(&z[i],"</title>",8)!=0); i++){}
1725
- if( z[i]!='<' ) return 0;
1726
- blob_init(pTitle, &z[iStart], i-iStart);
1746
+ if( strncmp(&z[i],"</title>",8)!=0 ){
1747
+ blob_init(pTitle, 0, 0);
1748
+ blob_init(pTail, &z[iStart], -1);
1749
+ return 1;
1750
+ }
1751
+ if( i-iStart>0 ){
1752
+ blob_init(pTitle, &z[iStart], i-iStart);
1753
+ }else{
1754
+ blob_init(pTitle, 0, 0);
1755
+ }
17271756
blob_init(pTail, &z[i+8], -1);
17281757
return 1;
17291758
}
17301759
17311760
/*
17321761
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -164,62 +164,68 @@
164 ** in aAllowedMarkup[].
165 */
166 #define MARKUP_INVALID 0
167 #define MARKUP_A 1
168 #define MARKUP_ADDRESS 2
169 #define MARKUP_B 3
170 #define MARKUP_BIG 4
171 #define MARKUP_BLOCKQUOTE 5
172 #define MARKUP_BR 6
173 #define MARKUP_CENTER 7
174 #define MARKUP_CITE 8
175 #define MARKUP_CODE 9
176 #define MARKUP_COL 10
177 #define MARKUP_COLGROUP 11
178 #define MARKUP_DD 12
179 #define MARKUP_DFN 13
180 #define MARKUP_DIV 14
181 #define MARKUP_DL 15
182 #define MARKUP_DT 16
183 #define MARKUP_EM 17
184 #define MARKUP_FONT 18
185 #define MARKUP_H1 19
186 #define MARKUP_H2 20
187 #define MARKUP_H3 21
188 #define MARKUP_H4 22
189 #define MARKUP_H5 23
190 #define MARKUP_H6 24
191 #define MARKUP_HR 25
192 #define MARKUP_I 26
193 #define MARKUP_IMG 27
194 #define MARKUP_KBD 28
195 #define MARKUP_LI 29
196 #define MARKUP_NOBR 30
197 #define MARKUP_NOWIKI 31
198 #define MARKUP_OL 32
199 #define MARKUP_P 33
200 #define MARKUP_PRE 34
201 #define MARKUP_S 35
202 #define MARKUP_SAMP 36
203 #define MARKUP_SMALL 37
204 #define MARKUP_SPAN 38
205 #define MARKUP_STRIKE 39
206 #define MARKUP_STRONG 40
207 #define MARKUP_SUB 41
208 #define MARKUP_SUP 42
209 #define MARKUP_TABLE 43
210 #define MARKUP_TBODY 44
211 #define MARKUP_TD 45
212 #define MARKUP_TFOOT 46
213 #define MARKUP_TH 47
214 #define MARKUP_THEAD 48
215 #define MARKUP_TR 49
216 #define MARKUP_TT 50
217 #define MARKUP_U 51
218 #define MARKUP_UL 52
219 #define MARKUP_VAR 53
220 #define MARKUP_VERBATIM 54
 
 
 
 
 
 
221
222 /*
223 ** The various markup is divided into the following types:
224 */
225 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -251,10 +257,15 @@
251 } aMarkup[] = {
252 { 0, MARKUP_INVALID, 0, 0 },
253 { "a", MARKUP_A, MUTYPE_HYPERLINK,
254 AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE },
255 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
 
 
 
 
 
256 { "b", MARKUP_B, MUTYPE_FONT, AMSK_STYLE },
257 { "big", MARKUP_BIG, MUTYPE_FONT, AMSK_STYLE },
258 { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, AMSK_STYLE },
259 { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
260 { "center", MARKUP_CENTER, MUTYPE_BLOCK, AMSK_STYLE },
@@ -272,10 +283,13 @@
272 AMSK_COMPACT|AMSK_STYLE },
273 { "dt", MARKUP_DT, MUTYPE_LI, AMSK_STYLE },
274 { "em", MARKUP_EM, MUTYPE_FONT, AMSK_STYLE },
275 { "font", MARKUP_FONT, MUTYPE_FONT,
276 AMSK_COLOR|AMSK_FACE|AMSK_SIZE|AMSK_STYLE },
 
 
 
277 { "h1", MARKUP_H1, MUTYPE_BLOCK,
278 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
279 { "h2", MARKUP_H2, MUTYPE_BLOCK,
280 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
281 { "h3", MARKUP_H3, MUTYPE_BLOCK,
@@ -284,10 +298,14 @@
284 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
285 { "h5", MARKUP_H5, MUTYPE_BLOCK,
286 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
287 { "h6", MARKUP_H6, MUTYPE_BLOCK,
288 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
 
 
 
 
289 { "hr", MARKUP_HR, MUTYPE_SINGLE,
290 AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH|
291 AMSK_STYLE|AMSK_CLASS },
292 { "i", MARKUP_I, MUTYPE_FONT, AMSK_STYLE },
293 { "img", MARKUP_IMG, MUTYPE_SINGLE,
@@ -294,19 +312,23 @@
294 AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT|
295 AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH|AMSK_STYLE },
296 { "kbd", MARKUP_KBD, MUTYPE_FONT, AMSK_STYLE },
297 { "li", MARKUP_LI, MUTYPE_LI,
298 AMSK_TYPE|AMSK_VALUE|AMSK_STYLE },
 
 
299 { "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 },
300 { "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 },
301 { "ol", MARKUP_OL, MUTYPE_LIST,
302 AMSK_START|AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE },
303 { "p", MARKUP_P, MUTYPE_BLOCK,
304 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
305 { "pre", MARKUP_PRE, MUTYPE_BLOCK, AMSK_STYLE },
306 { "s", MARKUP_S, MUTYPE_FONT, AMSK_STYLE },
307 { "samp", MARKUP_SAMP, MUTYPE_FONT, AMSK_STYLE },
 
 
308 { "small", MARKUP_SMALL, MUTYPE_FONT, AMSK_STYLE },
309 { "span", MARKUP_SPAN, MUTYPE_BLOCK,
310 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
311 { "strike", MARKUP_STRIKE, MUTYPE_FONT, AMSK_STYLE },
312 { "strong", MARKUP_STRONG, MUTYPE_FONT, AMSK_STYLE },
@@ -339,11 +361,10 @@
339 AMSK_ID|AMSK_TYPE },
340 };
341
342 void show_allowed_wiki_markup( void ){
343 int i; /* loop over allowedAttr */
344
345 for( i=1 ; i<=sizeof(aMarkup)/sizeof(aMarkup[0]) - 1 ; i++ ){
346 @ &lt;%s(aMarkup[i].zName)&gt;
347 }
348 }
349
@@ -1718,14 +1739,22 @@
1718 z = blob_str(pIn);
1719 for(i=0; fossil_isspace(z[i]); i++){}
1720 if( z[i]!='<' ) return 0;
1721 i++;
1722 if( strncmp(&z[i],"title>", 6)!=0 ) return 0;
1723 iStart = i+6;
1724 for(i=iStart; z[i] && (z[i]!='<' || strncmp(&z[i],"</title>",8)!=0); i++){}
1725 if( z[i]!='<' ) return 0;
1726 blob_init(pTitle, &z[iStart], i-iStart);
 
 
 
 
 
 
 
 
1727 blob_init(pTail, &z[i+8], -1);
1728 return 1;
1729 }
1730
1731 /*
1732
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -164,62 +164,68 @@
164 ** in aAllowedMarkup[].
165 */
166 #define MARKUP_INVALID 0
167 #define MARKUP_A 1
168 #define MARKUP_ADDRESS 2
169 #define MARKUP_HTML5_ARTICLE 3
170 #define MARKUP_HTML5_ASIDE 4
171 #define MARKUP_B 5
172 #define MARKUP_BIG 6
173 #define MARKUP_BLOCKQUOTE 7
174 #define MARKUP_BR 8
175 #define MARKUP_CENTER 9
176 #define MARKUP_CITE 10
177 #define MARKUP_CODE 11
178 #define MARKUP_COL 12
179 #define MARKUP_COLGROUP 13
180 #define MARKUP_DD 14
181 #define MARKUP_DFN 15
182 #define MARKUP_DIV 16
183 #define MARKUP_DL 17
184 #define MARKUP_DT 18
185 #define MARKUP_EM 19
186 #define MARKUP_FONT 20
187 #define MARKUP_HTML5_FOOTER 21
188 #define MARKUP_H1 22
189 #define MARKUP_H2 23
190 #define MARKUP_H3 24
191 #define MARKUP_H4 25
192 #define MARKUP_H5 26
193 #define MARKUP_H6 27
194 #define MARKUP_HTML5_HEADER 28
195 #define MARKUP_HR 29
196 #define MARKUP_I 30
197 #define MARKUP_IMG 31
198 #define MARKUP_KBD 32
199 #define MARKUP_LI 33
200 #define MARKUP_HTML5_NAV 34
201 #define MARKUP_NOBR 35
202 #define MARKUP_NOWIKI 36
203 #define MARKUP_OL 37
204 #define MARKUP_P 38
205 #define MARKUP_PRE 39
206 #define MARKUP_S 40
207 #define MARKUP_SAMP 41
208 #define MARKUP_HTML5_SECTION 42
209 #define MARKUP_SMALL 43
210 #define MARKUP_SPAN 44
211 #define MARKUP_STRIKE 45
212 #define MARKUP_STRONG 46
213 #define MARKUP_SUB 47
214 #define MARKUP_SUP 48
215 #define MARKUP_TABLE 49
216 #define MARKUP_TBODY 50
217 #define MARKUP_TD 51
218 #define MARKUP_TFOOT 52
219 #define MARKUP_TH 53
220 #define MARKUP_THEAD 54
221 #define MARKUP_TR 55
222 #define MARKUP_TT 56
223 #define MARKUP_U 57
224 #define MARKUP_UL 58
225 #define MARKUP_VAR 59
226 #define MARKUP_VERBATIM 60
227
228 /*
229 ** The various markup is divided into the following types:
230 */
231 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -251,10 +257,15 @@
257 } aMarkup[] = {
258 { 0, MARKUP_INVALID, 0, 0 },
259 { "a", MARKUP_A, MUTYPE_HYPERLINK,
260 AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE },
261 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
262 { "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
263 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
264 { "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
265 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
266
267 { "b", MARKUP_B, MUTYPE_FONT, AMSK_STYLE },
268 { "big", MARKUP_BIG, MUTYPE_FONT, AMSK_STYLE },
269 { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, AMSK_STYLE },
270 { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
271 { "center", MARKUP_CENTER, MUTYPE_BLOCK, AMSK_STYLE },
@@ -272,10 +283,13 @@
283 AMSK_COMPACT|AMSK_STYLE },
284 { "dt", MARKUP_DT, MUTYPE_LI, AMSK_STYLE },
285 { "em", MARKUP_EM, MUTYPE_FONT, AMSK_STYLE },
286 { "font", MARKUP_FONT, MUTYPE_FONT,
287 AMSK_COLOR|AMSK_FACE|AMSK_SIZE|AMSK_STYLE },
288 { "footer", MARKUP_HTML5_FOOTER, MUTYPE_BLOCK,
289 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
290
291 { "h1", MARKUP_H1, MUTYPE_BLOCK,
292 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
293 { "h2", MARKUP_H2, MUTYPE_BLOCK,
294 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
295 { "h3", MARKUP_H3, MUTYPE_BLOCK,
@@ -284,10 +298,14 @@
298 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
299 { "h5", MARKUP_H5, MUTYPE_BLOCK,
300 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
301 { "h6", MARKUP_H6, MUTYPE_BLOCK,
302 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
303
304 { "header", MARKUP_HTML5_HEADER, MUTYPE_BLOCK,
305 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
306
307 { "hr", MARKUP_HR, MUTYPE_SINGLE,
308 AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH|
309 AMSK_STYLE|AMSK_CLASS },
310 { "i", MARKUP_I, MUTYPE_FONT, AMSK_STYLE },
311 { "img", MARKUP_IMG, MUTYPE_SINGLE,
@@ -294,19 +312,23 @@
312 AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT|
313 AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH|AMSK_STYLE },
314 { "kbd", MARKUP_KBD, MUTYPE_FONT, AMSK_STYLE },
315 { "li", MARKUP_LI, MUTYPE_LI,
316 AMSK_TYPE|AMSK_VALUE|AMSK_STYLE },
317 { "nav", MARKUP_HTML5_NAV, MUTYPE_BLOCK,
318 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
319 { "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 },
320 { "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 },
321 { "ol", MARKUP_OL, MUTYPE_LIST,
322 AMSK_START|AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE },
323 { "p", MARKUP_P, MUTYPE_BLOCK,
324 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
325 { "pre", MARKUP_PRE, MUTYPE_BLOCK, AMSK_STYLE },
326 { "s", MARKUP_S, MUTYPE_FONT, AMSK_STYLE },
327 { "samp", MARKUP_SAMP, MUTYPE_FONT, AMSK_STYLE },
328 { "section", MARKUP_HTML5_SECTION, MUTYPE_BLOCK,
329 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
330 { "small", MARKUP_SMALL, MUTYPE_FONT, AMSK_STYLE },
331 { "span", MARKUP_SPAN, MUTYPE_BLOCK,
332 AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE },
333 { "strike", MARKUP_STRIKE, MUTYPE_FONT, AMSK_STYLE },
334 { "strong", MARKUP_STRONG, MUTYPE_FONT, AMSK_STYLE },
@@ -339,11 +361,10 @@
361 AMSK_ID|AMSK_TYPE },
362 };
363
364 void show_allowed_wiki_markup( void ){
365 int i; /* loop over allowedAttr */
 
366 for( i=1 ; i<=sizeof(aMarkup)/sizeof(aMarkup[0]) - 1 ; i++ ){
367 @ &lt;%s(aMarkup[i].zName)&gt;
368 }
369 }
370
@@ -1718,14 +1739,22 @@
1739 z = blob_str(pIn);
1740 for(i=0; fossil_isspace(z[i]); i++){}
1741 if( z[i]!='<' ) return 0;
1742 i++;
1743 if( strncmp(&z[i],"title>", 6)!=0 ) return 0;
1744 for(iStart=i+6; fossil_isspace(z[iStart]); iStart++){}
1745 for(i=iStart; z[i] && (z[i]!='<' || strncmp(&z[i],"</title>",8)!=0); i++){}
1746 if( strncmp(&z[i],"</title>",8)!=0 ){
1747 blob_init(pTitle, 0, 0);
1748 blob_init(pTail, &z[iStart], -1);
1749 return 1;
1750 }
1751 if( i-iStart>0 ){
1752 blob_init(pTitle, &z[iStart], i-iStart);
1753 }else{
1754 blob_init(pTitle, 0, 0);
1755 }
1756 blob_init(pTail, &z[i+8], -1);
1757 return 1;
1758 }
1759
1760 /*
1761
+5 -5
--- src/zip.c
+++ src/zip.c
@@ -81,11 +81,11 @@
8181
** Set the date and time from a julian day number.
8282
*/
8383
void zip_set_timedate(double rDate){
8484
char *zDate = db_text(0, "SELECT datetime(%.17g)", rDate);
8585
zip_set_timedate_from_str(zDate);
86
- free(zDate);
86
+ fossil_free(zDate);
8787
unixTime = (rDate - 2440587.5)*86400.0;
8888
}
8989
9090
/*
9191
** If the given filename includes one or more directory entries, make
@@ -267,13 +267,13 @@
267267
blob_reset(&toc);
268268
*pZip = body;
269269
blob_zero(&body);
270270
nEntry = 0;
271271
for(i=0; i<nDir; i++){
272
- free(azDir[i]);
272
+ fossil_free(azDir[i]);
273273
}
274
- free(azDir);
274
+ fossil_free(azDir);
275275
nDir = 0;
276276
azDir = 0;
277277
}
278278
279279
/*
@@ -444,10 +444,10 @@
444444
@ Not found
445445
return;
446446
}
447447
if( nRid==0 && nName>10 ) zName[10] = 0;
448448
zip_of_baseline(rid, &zip, zName);
449
- free( zName );
450
- free( zRid );
449
+ fossil_free( zName );
450
+ fossil_free( zRid );
451451
cgi_set_content(&zip);
452452
cgi_set_content_type("application/zip");
453453
}
454454
--- src/zip.c
+++ src/zip.c
@@ -81,11 +81,11 @@
81 ** Set the date and time from a julian day number.
82 */
83 void zip_set_timedate(double rDate){
84 char *zDate = db_text(0, "SELECT datetime(%.17g)", rDate);
85 zip_set_timedate_from_str(zDate);
86 free(zDate);
87 unixTime = (rDate - 2440587.5)*86400.0;
88 }
89
90 /*
91 ** If the given filename includes one or more directory entries, make
@@ -267,13 +267,13 @@
267 blob_reset(&toc);
268 *pZip = body;
269 blob_zero(&body);
270 nEntry = 0;
271 for(i=0; i<nDir; i++){
272 free(azDir[i]);
273 }
274 free(azDir);
275 nDir = 0;
276 azDir = 0;
277 }
278
279 /*
@@ -444,10 +444,10 @@
444 @ Not found
445 return;
446 }
447 if( nRid==0 && nName>10 ) zName[10] = 0;
448 zip_of_baseline(rid, &zip, zName);
449 free( zName );
450 free( zRid );
451 cgi_set_content(&zip);
452 cgi_set_content_type("application/zip");
453 }
454
--- src/zip.c
+++ src/zip.c
@@ -81,11 +81,11 @@
81 ** Set the date and time from a julian day number.
82 */
83 void zip_set_timedate(double rDate){
84 char *zDate = db_text(0, "SELECT datetime(%.17g)", rDate);
85 zip_set_timedate_from_str(zDate);
86 fossil_free(zDate);
87 unixTime = (rDate - 2440587.5)*86400.0;
88 }
89
90 /*
91 ** If the given filename includes one or more directory entries, make
@@ -267,13 +267,13 @@
267 blob_reset(&toc);
268 *pZip = body;
269 blob_zero(&body);
270 nEntry = 0;
271 for(i=0; i<nDir; i++){
272 fossil_free(azDir[i]);
273 }
274 fossil_free(azDir);
275 nDir = 0;
276 azDir = 0;
277 }
278
279 /*
@@ -444,10 +444,10 @@
444 @ Not found
445 return;
446 }
447 if( nRid==0 && nName>10 ) zName[10] = 0;
448 zip_of_baseline(rid, &zip, zName);
449 fossil_free( zName );
450 fossil_free( zRid );
451 cgi_set_content(&zip);
452 cgi_set_content_type("application/zip");
453 }
454
--- test/merge5.test
+++ test/merge5.test
@@ -52,10 +52,11 @@
5252
# Construct a test repository
5353
#
5454
exec sqlite3 m5.fossil <$testdir/${testfile}_repo.sql
5555
fossil rebuild m5.fossil
5656
fossil open m5.fossil
57
+fossil user default drh --user drh
5758
fossil update baseline
5859
checkout-test 10 {
5960
da5c8346496f3421cb58f84b6e59e9531d9d424d one.txt
6061
ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4 three.txt
6162
278a402316510f6ae4a77186796a6bde78c7dbc1 two.txt
6263
--- test/merge5.test
+++ test/merge5.test
@@ -52,10 +52,11 @@
52 # Construct a test repository
53 #
54 exec sqlite3 m5.fossil <$testdir/${testfile}_repo.sql
55 fossil rebuild m5.fossil
56 fossil open m5.fossil
 
57 fossil update baseline
58 checkout-test 10 {
59 da5c8346496f3421cb58f84b6e59e9531d9d424d one.txt
60 ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4 three.txt
61 278a402316510f6ae4a77186796a6bde78c7dbc1 two.txt
62
--- test/merge5.test
+++ test/merge5.test
@@ -52,10 +52,11 @@
52 # Construct a test repository
53 #
54 exec sqlite3 m5.fossil <$testdir/${testfile}_repo.sql
55 fossil rebuild m5.fossil
56 fossil open m5.fossil
57 fossil user default drh --user drh
58 fossil update baseline
59 checkout-test 10 {
60 da5c8346496f3421cb58f84b6e59e9531d9d424d one.txt
61 ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4 three.txt
62 278a402316510f6ae4a77186796a6bde78c7dbc1 two.txt
63
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,30 +1,16 @@
11
#
22
# Tests for merging with renames
33
#
44
#
5
-
6
-catch {exec $::fossilexe info} res
7
-puts res=$res
8
-if {![regexp {use --repository} $res]} {
9
- puts stderr "Cannot run this test within an open checkout"
10
- return
11
-}
12
-
13
-
14
-# Fossil will write data on $HOME, running 'fossil new' here.
15
-# We need not to clutter the $HOME of the test caller.
16
-set env(HOME) [pwd]
17
-
185
196
######################################
207
# Test 1 #
218
# Reported: Ticket [554f44ee74e3d] #
229
######################################
2310
24
-fossil new rep.fossil
25
-fossil open rep.fossil
11
+repo_init
2612
2713
write_file f1 "line"
2814
fossil add f1
2915
fossil commit -m "c1"
3016
fossil tag add pivot current
@@ -73,20 +59,16 @@
7359
test merge_renames-1 0
7460
} else {
7561
test merge_renames-1 1
7662
}
7763
78
-fossil close -f
79
-file delete rep.fossil
80
-
8164
######################################
8265
# Test 2 #
8366
# Reported: Ticket [74413366fe5067] #
8467
######################################
8568
86
-fossil new rep.fossil
87
-fossil open rep.fossil
69
+repo_init
8870
8971
write_file f1 "line"
9072
fossil add f1
9173
fossil commit -m "base file"
9274
fossil tag add pivot current
@@ -125,20 +107,16 @@
125107
test merge_renames-2 0
126108
} else {
127109
test merge_renames-2 1
128110
}
129111
130
-fossil close -f
131
-file delete rep.fossil
132
-
133112
######################################
134113
# Test 3 #
135114
# Reported: Ticket [30b28cf351] #
136115
######################################
137116
138
-fossil new rep.fossil
139
-fossil open rep.fossil
117
+repo_init
140118
141119
write_file f1 "line"
142120
fossil add f1
143121
fossil commit -m "base file"
144122
fossil tag add pivot current
@@ -177,13 +155,10 @@
177155
test merge_renames-2 0
178156
} else {
179157
test merge_renames-2 1
180158
}
181159
182
-fossil close -f
183
-file delete rep.fossil
184
-
185160
######################################
186161
# Test 4 #
187162
# Reported: Ticket [67176c3aa4] #
188163
######################################
189164
190165
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,30 +1,16 @@
1 #
2 # Tests for merging with renames
3 #
4 #
5
6 catch {exec $::fossilexe info} res
7 puts res=$res
8 if {![regexp {use --repository} $res]} {
9 puts stderr "Cannot run this test within an open checkout"
10 return
11 }
12
13
14 # Fossil will write data on $HOME, running 'fossil new' here.
15 # We need not to clutter the $HOME of the test caller.
16 set env(HOME) [pwd]
17
18
19 ######################################
20 # Test 1 #
21 # Reported: Ticket [554f44ee74e3d] #
22 ######################################
23
24 fossil new rep.fossil
25 fossil open rep.fossil
26
27 write_file f1 "line"
28 fossil add f1
29 fossil commit -m "c1"
30 fossil tag add pivot current
@@ -73,20 +59,16 @@
73 test merge_renames-1 0
74 } else {
75 test merge_renames-1 1
76 }
77
78 fossil close -f
79 file delete rep.fossil
80
81 ######################################
82 # Test 2 #
83 # Reported: Ticket [74413366fe5067] #
84 ######################################
85
86 fossil new rep.fossil
87 fossil open rep.fossil
88
89 write_file f1 "line"
90 fossil add f1
91 fossil commit -m "base file"
92 fossil tag add pivot current
@@ -125,20 +107,16 @@
125 test merge_renames-2 0
126 } else {
127 test merge_renames-2 1
128 }
129
130 fossil close -f
131 file delete rep.fossil
132
133 ######################################
134 # Test 3 #
135 # Reported: Ticket [30b28cf351] #
136 ######################################
137
138 fossil new rep.fossil
139 fossil open rep.fossil
140
141 write_file f1 "line"
142 fossil add f1
143 fossil commit -m "base file"
144 fossil tag add pivot current
@@ -177,13 +155,10 @@
177 test merge_renames-2 0
178 } else {
179 test merge_renames-2 1
180 }
181
182 fossil close -f
183 file delete rep.fossil
184
185 ######################################
186 # Test 4 #
187 # Reported: Ticket [67176c3aa4] #
188 ######################################
189
190
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,30 +1,16 @@
1 #
2 # Tests for merging with renames
3 #
4 #
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6 ######################################
7 # Test 1 #
8 # Reported: Ticket [554f44ee74e3d] #
9 ######################################
10
11 repo_init
 
12
13 write_file f1 "line"
14 fossil add f1
15 fossil commit -m "c1"
16 fossil tag add pivot current
@@ -73,20 +59,16 @@
59 test merge_renames-1 0
60 } else {
61 test merge_renames-1 1
62 }
63
 
 
 
64 ######################################
65 # Test 2 #
66 # Reported: Ticket [74413366fe5067] #
67 ######################################
68
69 repo_init
 
70
71 write_file f1 "line"
72 fossil add f1
73 fossil commit -m "base file"
74 fossil tag add pivot current
@@ -125,20 +107,16 @@
107 test merge_renames-2 0
108 } else {
109 test merge_renames-2 1
110 }
111
 
 
 
112 ######################################
113 # Test 3 #
114 # Reported: Ticket [30b28cf351] #
115 ######################################
116
117 repo_init
 
118
119 write_file f1 "line"
120 fossil add f1
121 fossil commit -m "base file"
122 fossil tag add pivot current
@@ -177,13 +155,10 @@
155 test merge_renames-2 0
156 } else {
157 test merge_renames-2 1
158 }
159
 
 
 
160 ######################################
161 # Test 4 #
162 # Reported: Ticket [67176c3aa4] #
163 ######################################
164
165
+59 -55
--- test/revert.test
+++ test/revert.test
@@ -1,65 +1,30 @@
11
#
22
# Tests for 'fossil revert'
33
#
44
#
55
6
-catch {exec $::fossilexe info} res
7
-puts res=$res
8
-if {![regexp {use --repository} $res]} {
9
- puts stderr "Cannot run this test within an open checkout"
10
- return
11
-}
12
-
13
-# Fossil will write data on $HOME, running 'fossil new' here.
14
-# We need not to clutter the $HOME of the test caller.
15
-#
16
-set env(HOME) [pwd]
17
-
18
-
19
-# Normalize file status lists (like those returned by 'fossil changes')
20
-# so they can be compared using simple string comparison
21
-#
22
-proc normalize-status-list {list} {
23
- set normalized [list]
24
- set matches [regexp -all -inline -line {^\s*([A-Z]+)\s+(.*)$} $list]
25
- foreach {_ status file} $matches {
26
- lappend normalized [list $status [string trim $file]]
27
- }
28
- set normalized [lsort -index 1 $normalized]
29
- return $normalized
30
-}
31
-
326
# Test 'fossil revert' against expected results from 'fossil changes' and
33
-# 'fossil addremove --test', as well as by verifying the existence of files
7
+# 'fossil addremove -n', as well as by verifying the existence of files
348
# on the file system. 'fossil undo' is called after each test
359
#
36
-proc revert-test {testid args} {
10
+proc revert-test {testid revertArgs expectedRevertOutput args} {
3711
global RESULT
3812
set passed 1
3913
40
- if {[llength $args] % 2} {
41
- set revertArgs [lindex $args 0]
42
- set args [lrange $args 1 end]
43
- } else {
44
- set revertArgs {}
45
- }
4614
set args [dict merge {
4715
-changes {} -addremove {} -exists {} -notexists {}
4816
} $args]
4917
50
- fossil revert {*}$revertArgs
18
+ set result [fossil revert {*}$revertArgs]
19
+ test_status_list revert-$testid $result $expectedRevertOutput
5120
52
- set statusListTests [list -changes changes -addremove {addremove --test}]
21
+ set statusListTests [list -changes changes -addremove {addremove -n}]
5322
foreach {key fossilArgs} $statusListTests {
54
- set expected [normalize-status-list [dict get $args $key]]
55
- set result [normalize-status-list [fossil {*}$fossilArgs]]
56
- if {$result ne $expected} {
57
- set passed 0
58
- protOut " Expected:\n [join $expected "\n "]"
59
- protOut " Got:\n [join $result "\n "]"
60
- }
23
+ set expected [dict get $args $key]
24
+ set result [fossil {*}$fossilArgs]
25
+ test_status_list revert-$testid$key $result $expected
6126
}
6227
6328
set fileExistsTests [list -exists 1 does -notexists 0 should]
6429
foreach {key expected verb} $fileExistsTests {
6530
foreach path [dict get $args $key] {
@@ -66,20 +31,17 @@
6631
if {[file exists $path] != $expected} {
6732
set passed 0
6833
protOut " Failure: File $verb not exist: $path"
6934
}
7035
}
36
+ test revert-$testid$key $passed
7137
}
7238
7339
fossil undo
74
- test revert-$testid $passed
7540
}
7641
77
-# Create the repo
78
-#
79
-fossil new rep.fossil
80
-fossil open rep.fossil
42
+repo_init
8143
8244
# Prepare first commit
8345
#
8446
write_file f1 "f1"
8547
write_file f2 "f2"
@@ -101,53 +63,95 @@
10163
file rename -force f3 f3n
10264
fossil mv f3 f3n
10365
10466
# Test 'fossil revert' with no arguments
10567
#
106
-revert-test 1 -addremove {
68
+revert-test 1-1 {} {
69
+ UNMANAGE: f0
70
+ REVERTED: f1
71
+ REVERTED: f2
72
+ REVERTED: f3
73
+ DELETE: f3n
74
+} -addremove {
10775
ADDED f0
10876
} -exists {f0 f1 f2 f3} -notexists f3n
10977
11078
# Test with a single filename argument
11179
#
112
-revert-test 2 f0 -changes {
80
+revert-test 1-2 f0 {
81
+ UNMANAGE: f0
82
+} -changes {
11383
DELETED f1
11484
EDITED f2
11585
RENAMED f3n
11686
} -addremove {
11787
ADDED f0
11888
} -exists {f0 f2 f3n} -notexists f3
11989
120
-revert-test 3 f1 -changes {
90
+revert-test 1-3 f1 {
91
+ REVERTED: f1
92
+} -changes {
12193
ADDED f0
12294
EDITED f2
12395
RENAMED f3n
12496
} -exists {f0 f1 f2 f3n} -notexists f3
12597
126
-revert-test 4 f2 -changes {
98
+revert-test 1-4 f2 {
99
+ REVERTED: f2
100
+} -changes {
127101
ADDED f0
128102
DELETED f1
129103
RENAMED f3n
130104
} -exists {f0 f2 f3n} -notexists {f1 f3}
131105
132106
# Both files involved in a rename are reverted regardless of which filename
133107
# is used as an argument to 'fossil revert'
134108
#
135
-revert-test 5 f3 -changes {
109
+revert-test 1-5 f3 {
110
+ REVERTED: f3
111
+ DELETE: f3n
112
+} -changes {
136113
ADDED f0
137114
DELETED f1
138115
EDITED f2
139116
} -exists {f0 f2 f3} -notexists {f1 f3n}
140117
141
-revert-test 6 f3n -changes {
118
+revert-test 1-6 f3n {
119
+ REVERTED: f3
120
+ DELETE: f3n
121
+} -changes {
142122
ADDED f0
143123
DELETED f1
144124
EDITED f2
145125
} -exists {f0 f2 f3} -notexists {f1 f3n}
146126
147127
# Test with multiple filename arguments
148128
#
149
-revert-test 7 {f0 f2 f3n} -changes {
129
+revert-test 1-7 {f0 f2 f3n} {
130
+ UNMANAGE: f0
131
+ REVERTED: f2
132
+ REVERTED: f3
133
+ DELETE: f3n
134
+} -changes {
150135
DELETED f1
151136
} -addremove {
152137
ADDED f0
153138
} -exists {f0 f2 f3} -notexists {f1 f3n}
139
+
140
+
141
+# Test reverting the combination of a renamed file and an added file that
142
+# uses the renamed file's original filename.
143
+#
144
+repo_init
145
+write_file f1 "f1"
146
+fossil add f1
147
+fossil commit -m "add f1"
148
+
149
+write_file f1n "f1n"
150
+fossil mv f1 f1n
151
+write_file f1 "f1b"
152
+fossil add f1
153
+
154
+revert-test 2-1 {} {
155
+ REVERTED: f1
156
+ DELETE: f1n
157
+} -exists {f1} -notexists {f1n}
154158
--- test/revert.test
+++ test/revert.test
@@ -1,65 +1,30 @@
1 #
2 # Tests for 'fossil revert'
3 #
4 #
5
6 catch {exec $::fossilexe info} res
7 puts res=$res
8 if {![regexp {use --repository} $res]} {
9 puts stderr "Cannot run this test within an open checkout"
10 return
11 }
12
13 # Fossil will write data on $HOME, running 'fossil new' here.
14 # We need not to clutter the $HOME of the test caller.
15 #
16 set env(HOME) [pwd]
17
18
19 # Normalize file status lists (like those returned by 'fossil changes')
20 # so they can be compared using simple string comparison
21 #
22 proc normalize-status-list {list} {
23 set normalized [list]
24 set matches [regexp -all -inline -line {^\s*([A-Z]+)\s+(.*)$} $list]
25 foreach {_ status file} $matches {
26 lappend normalized [list $status [string trim $file]]
27 }
28 set normalized [lsort -index 1 $normalized]
29 return $normalized
30 }
31
32 # Test 'fossil revert' against expected results from 'fossil changes' and
33 # 'fossil addremove --test', as well as by verifying the existence of files
34 # on the file system. 'fossil undo' is called after each test
35 #
36 proc revert-test {testid args} {
37 global RESULT
38 set passed 1
39
40 if {[llength $args] % 2} {
41 set revertArgs [lindex $args 0]
42 set args [lrange $args 1 end]
43 } else {
44 set revertArgs {}
45 }
46 set args [dict merge {
47 -changes {} -addremove {} -exists {} -notexists {}
48 } $args]
49
50 fossil revert {*}$revertArgs
 
51
52 set statusListTests [list -changes changes -addremove {addremove --test}]
53 foreach {key fossilArgs} $statusListTests {
54 set expected [normalize-status-list [dict get $args $key]]
55 set result [normalize-status-list [fossil {*}$fossilArgs]]
56 if {$result ne $expected} {
57 set passed 0
58 protOut " Expected:\n [join $expected "\n "]"
59 protOut " Got:\n [join $result "\n "]"
60 }
61 }
62
63 set fileExistsTests [list -exists 1 does -notexists 0 should]
64 foreach {key expected verb} $fileExistsTests {
65 foreach path [dict get $args $key] {
@@ -66,20 +31,17 @@
66 if {[file exists $path] != $expected} {
67 set passed 0
68 protOut " Failure: File $verb not exist: $path"
69 }
70 }
 
71 }
72
73 fossil undo
74 test revert-$testid $passed
75 }
76
77 # Create the repo
78 #
79 fossil new rep.fossil
80 fossil open rep.fossil
81
82 # Prepare first commit
83 #
84 write_file f1 "f1"
85 write_file f2 "f2"
@@ -101,53 +63,95 @@
101 file rename -force f3 f3n
102 fossil mv f3 f3n
103
104 # Test 'fossil revert' with no arguments
105 #
106 revert-test 1 -addremove {
 
 
 
 
 
 
107 ADDED f0
108 } -exists {f0 f1 f2 f3} -notexists f3n
109
110 # Test with a single filename argument
111 #
112 revert-test 2 f0 -changes {
 
 
113 DELETED f1
114 EDITED f2
115 RENAMED f3n
116 } -addremove {
117 ADDED f0
118 } -exists {f0 f2 f3n} -notexists f3
119
120 revert-test 3 f1 -changes {
 
 
121 ADDED f0
122 EDITED f2
123 RENAMED f3n
124 } -exists {f0 f1 f2 f3n} -notexists f3
125
126 revert-test 4 f2 -changes {
 
 
127 ADDED f0
128 DELETED f1
129 RENAMED f3n
130 } -exists {f0 f2 f3n} -notexists {f1 f3}
131
132 # Both files involved in a rename are reverted regardless of which filename
133 # is used as an argument to 'fossil revert'
134 #
135 revert-test 5 f3 -changes {
 
 
 
136 ADDED f0
137 DELETED f1
138 EDITED f2
139 } -exists {f0 f2 f3} -notexists {f1 f3n}
140
141 revert-test 6 f3n -changes {
 
 
 
142 ADDED f0
143 DELETED f1
144 EDITED f2
145 } -exists {f0 f2 f3} -notexists {f1 f3n}
146
147 # Test with multiple filename arguments
148 #
149 revert-test 7 {f0 f2 f3n} -changes {
 
 
 
 
 
150 DELETED f1
151 } -addremove {
152 ADDED f0
153 } -exists {f0 f2 f3} -notexists {f1 f3n}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
--- test/revert.test
+++ test/revert.test
@@ -1,65 +1,30 @@
1 #
2 # Tests for 'fossil revert'
3 #
4 #
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6 # Test 'fossil revert' against expected results from 'fossil changes' and
7 # 'fossil addremove -n', as well as by verifying the existence of files
8 # on the file system. 'fossil undo' is called after each test
9 #
10 proc revert-test {testid revertArgs expectedRevertOutput args} {
11 global RESULT
12 set passed 1
13
 
 
 
 
 
 
14 set args [dict merge {
15 -changes {} -addremove {} -exists {} -notexists {}
16 } $args]
17
18 set result [fossil revert {*}$revertArgs]
19 test_status_list revert-$testid $result $expectedRevertOutput
20
21 set statusListTests [list -changes changes -addremove {addremove -n}]
22 foreach {key fossilArgs} $statusListTests {
23 set expected [dict get $args $key]
24 set result [fossil {*}$fossilArgs]
25 test_status_list revert-$testid$key $result $expected
 
 
 
 
26 }
27
28 set fileExistsTests [list -exists 1 does -notexists 0 should]
29 foreach {key expected verb} $fileExistsTests {
30 foreach path [dict get $args $key] {
@@ -66,20 +31,17 @@
31 if {[file exists $path] != $expected} {
32 set passed 0
33 protOut " Failure: File $verb not exist: $path"
34 }
35 }
36 test revert-$testid$key $passed
37 }
38
39 fossil undo
 
40 }
41
42 repo_init
 
 
 
43
44 # Prepare first commit
45 #
46 write_file f1 "f1"
47 write_file f2 "f2"
@@ -101,53 +63,95 @@
63 file rename -force f3 f3n
64 fossil mv f3 f3n
65
66 # Test 'fossil revert' with no arguments
67 #
68 revert-test 1-1 {} {
69 UNMANAGE: f0
70 REVERTED: f1
71 REVERTED: f2
72 REVERTED: f3
73 DELETE: f3n
74 } -addremove {
75 ADDED f0
76 } -exists {f0 f1 f2 f3} -notexists f3n
77
78 # Test with a single filename argument
79 #
80 revert-test 1-2 f0 {
81 UNMANAGE: f0
82 } -changes {
83 DELETED f1
84 EDITED f2
85 RENAMED f3n
86 } -addremove {
87 ADDED f0
88 } -exists {f0 f2 f3n} -notexists f3
89
90 revert-test 1-3 f1 {
91 REVERTED: f1
92 } -changes {
93 ADDED f0
94 EDITED f2
95 RENAMED f3n
96 } -exists {f0 f1 f2 f3n} -notexists f3
97
98 revert-test 1-4 f2 {
99 REVERTED: f2
100 } -changes {
101 ADDED f0
102 DELETED f1
103 RENAMED f3n
104 } -exists {f0 f2 f3n} -notexists {f1 f3}
105
106 # Both files involved in a rename are reverted regardless of which filename
107 # is used as an argument to 'fossil revert'
108 #
109 revert-test 1-5 f3 {
110 REVERTED: f3
111 DELETE: f3n
112 } -changes {
113 ADDED f0
114 DELETED f1
115 EDITED f2
116 } -exists {f0 f2 f3} -notexists {f1 f3n}
117
118 revert-test 1-6 f3n {
119 REVERTED: f3
120 DELETE: f3n
121 } -changes {
122 ADDED f0
123 DELETED f1
124 EDITED f2
125 } -exists {f0 f2 f3} -notexists {f1 f3n}
126
127 # Test with multiple filename arguments
128 #
129 revert-test 1-7 {f0 f2 f3n} {
130 UNMANAGE: f0
131 REVERTED: f2
132 REVERTED: f3
133 DELETE: f3n
134 } -changes {
135 DELETED f1
136 } -addremove {
137 ADDED f0
138 } -exists {f0 f2 f3} -notexists {f1 f3n}
139
140
141 # Test reverting the combination of a renamed file and an added file that
142 # uses the renamed file's original filename.
143 #
144 repo_init
145 write_file f1 "f1"
146 fossil add f1
147 fossil commit -m "add f1"
148
149 write_file f1n "f1n"
150 fossil mv f1 f1n
151 write_file f1 "f1b"
152 fossil add f1
153
154 revert-test 2-1 {} {
155 REVERTED: f1
156 DELETE: f1n
157 } -exists {f1} -notexists {f1n}
158
--- test/tester.tcl
+++ test/tester.tcl
@@ -120,10 +120,57 @@
120120
regsub -all { +\n} $x \n x
121121
set y [read_file $b]
122122
regsub -all { +\n} $y \n y
123123
return [expr {$x==$y}]
124124
}
125
+
126
+# Create and open a new Fossil repository and clean the checkout
127
+#
128
+proc repo_init {{filename ".rep.fossil"}} {
129
+ if {$::env(HOME) ne [pwd]} {
130
+ catch {exec $::fossilexe info} res
131
+ if {![regexp {use --repository} $res]} {
132
+ error "In an open checkout: cannot initialize a new repository here."
133
+ }
134
+ # Fossil will write data on $HOME, running 'fossil new' here.
135
+ # We need not to clutter the $HOME of the test caller.
136
+ #
137
+ set ::env(HOME) [pwd]
138
+ }
139
+ catch {exec $::fossilexe close -f}
140
+ file delete $filename
141
+ exec $::fossilexe new $filename
142
+ exec $::fossilexe open $filename
143
+ exec $::fossilexe clean -f
144
+}
145
+
146
+# Normalize file status lists (like those returned by 'fossil changes')
147
+# so they can be compared using simple string comparison
148
+#
149
+proc normalize_status_list {list} {
150
+ set normalized [list]
151
+ set matches [regexp -all -inline -line {^\s*([A-Z_]+:?)\x20+(\S.*)$} $list]
152
+ foreach {_ status file} $matches {
153
+ lappend normalized [list $status [string trim $file]]
154
+ }
155
+ set normalized [lsort -index 1 $normalized]
156
+ return $normalized
157
+}
158
+
159
+# Perform a test comparing two status lists
160
+#
161
+proc test_status_list {name result expected} {
162
+ set expected [normalize_status_list $expected]
163
+ set result [normalize_status_list $result]
164
+ if {$result eq $expected} {
165
+ test $name 1
166
+ } else {
167
+ protOut " Expected:\n [join $expected "\n "]"
168
+ protOut " Got:\n [join $result "\n "]"
169
+ test $name 0
170
+ }
171
+}
125172
126173
# Perform a test
127174
#
128175
set test_count 0
129176
proc test {name expr} {
130177
--- test/tester.tcl
+++ test/tester.tcl
@@ -120,10 +120,57 @@
120 regsub -all { +\n} $x \n x
121 set y [read_file $b]
122 regsub -all { +\n} $y \n y
123 return [expr {$x==$y}]
124 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
126 # Perform a test
127 #
128 set test_count 0
129 proc test {name expr} {
130
--- test/tester.tcl
+++ test/tester.tcl
@@ -120,10 +120,57 @@
120 regsub -all { +\n} $x \n x
121 set y [read_file $b]
122 regsub -all { +\n} $y \n y
123 return [expr {$x==$y}]
124 }
125
126 # Create and open a new Fossil repository and clean the checkout
127 #
128 proc repo_init {{filename ".rep.fossil"}} {
129 if {$::env(HOME) ne [pwd]} {
130 catch {exec $::fossilexe info} res
131 if {![regexp {use --repository} $res]} {
132 error "In an open checkout: cannot initialize a new repository here."
133 }
134 # Fossil will write data on $HOME, running 'fossil new' here.
135 # We need not to clutter the $HOME of the test caller.
136 #
137 set ::env(HOME) [pwd]
138 }
139 catch {exec $::fossilexe close -f}
140 file delete $filename
141 exec $::fossilexe new $filename
142 exec $::fossilexe open $filename
143 exec $::fossilexe clean -f
144 }
145
146 # Normalize file status lists (like those returned by 'fossil changes')
147 # so they can be compared using simple string comparison
148 #
149 proc normalize_status_list {list} {
150 set normalized [list]
151 set matches [regexp -all -inline -line {^\s*([A-Z_]+:?)\x20+(\S.*)$} $list]
152 foreach {_ status file} $matches {
153 lappend normalized [list $status [string trim $file]]
154 }
155 set normalized [lsort -index 1 $normalized]
156 return $normalized
157 }
158
159 # Perform a test comparing two status lists
160 #
161 proc test_status_list {name result expected} {
162 set expected [normalize_status_list $expected]
163 set result [normalize_status_list $result]
164 if {$result eq $expected} {
165 test $name 1
166 } else {
167 protOut " Expected:\n [join $expected "\n "]"
168 protOut " Got:\n [join $result "\n "]"
169 test $name 0
170 }
171 }
172
173 # Perform a test
174 #
175 set test_count 0
176 proc test {name expr} {
177
+2 -2
--- test/th1.test
+++ test/th1.test
@@ -37,16 +37,16 @@
3737
test th1-setting-4 {$RESULT eq {TH_ERROR: no value for setting "abc"}}
3838
3939
###############################################################################
4040
4141
fossil test-th-eval --th-open-config "setting autosync"
42
-test th1-setting-5 {$RESULT eq 1}
42
+test th1-setting-5 {$RESULT eq 0 || $RESULT eq 1}
4343
4444
###############################################################################
4545
4646
fossil test-th-eval --th-open-config "setting -strict autosync"
47
-test th1-setting-6 {$RESULT eq 1}
47
+test th1-setting-6 {$RESULT eq 0 || $RESULT eq 1}
4848
4949
###############################################################################
5050
5151
fossil test-th-eval --th-open-config "setting --"
5252
test th1-setting-7 {$RESULT eq \
5353
--- test/th1.test
+++ test/th1.test
@@ -37,16 +37,16 @@
37 test th1-setting-4 {$RESULT eq {TH_ERROR: no value for setting "abc"}}
38
39 ###############################################################################
40
41 fossil test-th-eval --th-open-config "setting autosync"
42 test th1-setting-5 {$RESULT eq 1}
43
44 ###############################################################################
45
46 fossil test-th-eval --th-open-config "setting -strict autosync"
47 test th1-setting-6 {$RESULT eq 1}
48
49 ###############################################################################
50
51 fossil test-th-eval --th-open-config "setting --"
52 test th1-setting-7 {$RESULT eq \
53
--- test/th1.test
+++ test/th1.test
@@ -37,16 +37,16 @@
37 test th1-setting-4 {$RESULT eq {TH_ERROR: no value for setting "abc"}}
38
39 ###############################################################################
40
41 fossil test-th-eval --th-open-config "setting autosync"
42 test th1-setting-5 {$RESULT eq 0 || $RESULT eq 1}
43
44 ###############################################################################
45
46 fossil test-th-eval --th-open-config "setting -strict autosync"
47 test th1-setting-6 {$RESULT eq 0 || $RESULT eq 1}
48
49 ###############################################################################
50
51 fossil test-th-eval --th-open-config "setting --"
52 test th1-setting-7 {$RESULT eq \
53
--- 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 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
94
+SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
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 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
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 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
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
@@ -26,11 +26,11 @@
2626
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2727
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
2828
2929
SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
3030
31
-SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
31
+SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3232
3333
SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
3434
3535
OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
3636
3737
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,11 +26,11 @@
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,11 +26,11 @@
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1710,10 +1710,12 @@
17101710
-DSQLITE_USE_MALLOC_H \
17111711
-DSQLITE_USE_MSIZE
17121712
17131713
SHELL_OPTIONS = -Dmain=sqlite3_shell \
17141714
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
1715
+ -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
1716
+ -DSQLITE_SHELL_DBNAME_PROC=fossil_open \
17151717
-Dgetenv=fossil_getenv \
17161718
-Dfopen=fossil_fopen
17171719
17181720
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
17191721
$(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
17201722
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1710,10 +1710,12 @@
1710 -DSQLITE_USE_MALLOC_H \
1711 -DSQLITE_USE_MSIZE
1712
1713 SHELL_OPTIONS = -Dmain=sqlite3_shell \
1714 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
 
 
1715 -Dgetenv=fossil_getenv \
1716 -Dfopen=fossil_fopen
1717
1718 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
1719 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1720
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1710,10 +1710,12 @@
1710 -DSQLITE_USE_MALLOC_H \
1711 -DSQLITE_USE_MSIZE
1712
1713 SHELL_OPTIONS = -Dmain=sqlite3_shell \
1714 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1715 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
1716 -DSQLITE_SHELL_DBNAME_PROC=fossil_open \
1717 -Dgetenv=fossil_getenv \
1718 -Dfopen=fossil_fopen
1719
1720 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
1721 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1722
+55 -20
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -21,54 +21,78 @@
2121
# Uncomment to enable JSON API
2222
# FOSSIL_ENABLE_JSON = 1
2323
2424
# Uncomment to enable SSL support
2525
# FOSSIL_ENABLE_SSL = 1
26
+
27
+# Uncomment to enable Tcl support
28
+# FOSSIL_ENABLE_TCL = 1
2629
2730
!ifdef FOSSIL_ENABLE_SSL
2831
SSLINCDIR = $(B)\compat\openssl-1.0.1f\include
2932
SSLLIBDIR = $(B)\compat\openssl-1.0.1f\out32
3033
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
3134
!endif
35
+
36
+!ifdef FOSSIL_ENABLE_TCL
37
+TCLDIR = $(B)\compat\tcl-8.6
38
+TCLSRCDIR = $(TCLDIR)
39
+TCLINCDIR = $(TCLSRCDIR)\generic
40
+!endif
3241
3342
# zlib options
3443
ZINCDIR = $(B)\compat\zlib
3544
ZLIBDIR = $(B)\compat\zlib
3645
ZLIB = zlib.lib
3746
38
-INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(ZINCDIR)
47
+INCL = /I. /I$(SRCDIR) /I$B\win\include /I$(ZINCDIR)
3948
4049
!ifdef FOSSIL_ENABLE_SSL
41
-INCL = $(INCL) -I$(SSLINCDIR)
50
+INCL = $(INCL) /I$(SSLINCDIR)
51
+!endif
52
+
53
+!ifdef FOSSIL_ENABLE_TCL
54
+INCL = $(INCL) /I$(TCLINCDIR)
4255
!endif
4356
44
-CFLAGS = -nologo
57
+CFLAGS = /nologo
4558
LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
4659
4760
!ifdef DEBUG
48
-CFLAGS = $(CFLAGS) -Zi -MTd -Od
61
+CFLAGS = $(CFLAGS) /Zi /MTd /Od
4962
LDFLAGS = $(LDFLAGS) /DEBUG
5063
!else
51
-CFLAGS = $(CFLAGS) -MT -O2
64
+CFLAGS = $(CFLAGS) /MT /O2
5265
!endif
5366
5467
BCC = $(CC) $(CFLAGS)
55
-TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(INCL)
56
-RCC = rc -D_WIN32 -D_MSC_VER $(MSCDEF) $(INCL)
68
+TCC = $(CC) /c $(CFLAGS) $(MSCDEF) $(INCL)
69
+RCC = rc /D_WIN32 /D_MSC_VER $(MSCDEF) $(INCL)
5770
LIBS = $(ZLIB) ws2_32.lib advapi32.lib
58
-LIBDIR = -LIBPATH:$(ZLIBDIR)
71
+LIBDIR = /LIBPATH:$(ZLIBDIR)
5972
6073
!ifdef FOSSIL_ENABLE_JSON
61
-TCC = $(TCC) -DFOSSIL_ENABLE_JSON=1
62
-RCC = $(RCC) -DFOSSIL_ENABLE_JSON=1
74
+TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
75
+RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
6376
!endif
6477
6578
!ifdef FOSSIL_ENABLE_SSL
66
-TCC = $(TCC) -DFOSSIL_ENABLE_SSL=1
67
-RCC = $(RCC) -DFOSSIL_ENABLE_SSL=1
79
+TCC = $(TCC) /DFOSSIL_ENABLE_SSL=1
80
+RCC = $(RCC) /DFOSSIL_ENABLE_SSL=1
6881
LIBS = $(LIBS) $(SSLLIB)
69
-LIBDIR = $(LIBDIR) -LIBPATH:$(SSLLIBDIR)
82
+LIBDIR = $(LIBDIR) /LIBPATH:$(SSLLIBDIR)
83
+!endif
84
+
85
+!ifdef FOSSIL_ENABLE_TCL
86
+TCC = $(TCC) /DFOSSIL_ENABLE_TCL=1
87
+RCC = $(RCC) /DFOSSIL_ENABLE_TCL=1
88
+TCC = $(TCC) /DFOSSIL_ENABLE_TCL_STUBS=1
89
+RCC = $(RCC) /DFOSSIL_ENABLE_TCL_STUBS=1
90
+TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
91
+RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
92
+TCC = $(TCC) /DUSE_TCL_STUBS=1
93
+RCC = $(RCC) /DUSE_TCL_STUBS=1
7094
!endif
7195
7296
SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
7397
/DSQLITE_ENABLE_LOCKING_STYLE=0 \
7498
/DSQLITE_THREADSAFE=0 \
@@ -76,10 +100,12 @@
76100
/DSQLITE_OMIT_DEPRECATED \
77101
/DSQLITE_ENABLE_EXPLAIN_COMMENTS
78102
79103
SHELL_OPTIONS = /Dmain=sqlite3_shell \
80104
/DSQLITE_OMIT_LOAD_EXTENSION=1 \
105
+ /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
106
+ /DSQLITE_SHELL_DBNAME_PROC=fossil_open \
81107
/Dgetenv=fossil_getenv \
82108
/Dfopen=fossil_fopen
83109
84110
SRC = add_.c \
85111
allrepo_.c \
@@ -302,10 +328,14 @@
302328
$(OX)\wysiwyg$O \
303329
$(OX)\xfer$O \
304330
$(OX)\xfersetup$O \
305331
$(OX)\zip$O \
306332
$(OX)\fossil.res
333
+
334
+!ifdef FOSSIL_ENABLE_TCL
335
+OBJ = $(OBJ) $(OX)\th_tcl$O
336
+!endif
307337
308338
APPNAME = $(OX)\fossil$(E)
309339
PDBNAME = $(OX)\fossil$(P)
310340
311341
all: $(OX) $(APPNAME)
@@ -314,11 +344,11 @@
314344
@echo Building zlib from "$(ZLIBDIR)"...
315345
@pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd
316346
317347
$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib
318348
cd $(OX)
319
- link $(LDFLAGS) -OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
349
+ link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
320350
321351
$(OX)\linkopts: $B\win\Makefile.msc
322352
echo $(OX)\add.obj > $@
323353
echo $(OX)\allrepo.obj >> $@
324354
echo $(OX)\attach.obj >> $@
@@ -430,14 +460,14 @@
430460
echo $(OX)\winhttp.obj >> $@
431461
echo $(OX)\wysiwyg.obj >> $@
432462
echo $(OX)\xfer.obj >> $@
433463
echo $(OX)\xfersetup.obj >> $@
434464
echo $(OX)\zip.obj >> $@
465
+!ifdef FOSSIL_ENABLE_TCL
466
+ echo $(OX)\th_tcl.obj >> $@
467
+!endif
435468
echo $(LIBS) >> $@
436
-
437
-
438
-
439469
440470
$(OX):
441471
@-mkdir $@
442472
443473
translate$E: $(SRCDIR)\translate.c
@@ -461,15 +491,20 @@
461491
$(OX)\th$O : $(SRCDIR)\th.c
462492
$(TCC) /Fo$@ -c $**
463493
464494
$(OX)\th_lang$O : $(SRCDIR)\th_lang.c
465495
$(TCC) /Fo$@ -c $**
496
+
497
+!ifdef FOSSIL_ENABLE_TCL
498
+$(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
499
+ $(TCC) /Fo$@ -c $**
500
+!endif
466501
467502
VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
468503
$** > $@
469504
$(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
470
- $(TCC) /Fo$@ -c $**
505
+ $(TCC) /Fo$@ /c $**
471506
472507
page_index.h: mkindex$E $(SRC)
473508
$** > $@
474509
475510
clean:
@@ -504,11 +539,10 @@
504539
$(OBJDIR)\json_status$O : $(SRCDIR)\json_detail.h
505540
$(OBJDIR)\json_tag$O : $(SRCDIR)\json_detail.h
506541
$(OBJDIR)\json_timeline$O : $(SRCDIR)\json_detail.h
507542
$(OBJDIR)\json_user$O : $(SRCDIR)\json_detail.h
508543
$(OBJDIR)\json_wiki$O : $(SRCDIR)\json_detail.h
509
-
510544
511545
$(OX)\add$O : add_.c add.h
512546
$(TCC) /Fo$@ -c add_.c
513547
514548
add_.c : $(SRCDIR)\add.c
@@ -1155,11 +1189,12 @@
11551189
11561190
zip_.c : $(SRCDIR)\zip.c
11571191
translate$E $** > $@
11581192
11591193
fossil.res : $B\win\fossil.rc
1160
- $(RCC) -fo $@ $**
1194
+ $(RCC) /fo $@ $**
1195
+
11611196
headers: makeheaders$E page_index.h VERSION.h
11621197
makeheaders$E add_.c:add.h \
11631198
allrepo_.c:allrepo.h \
11641199
attach_.c:attach.h \
11651200
bag_.c:bag.h \
11661201
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -21,54 +21,78 @@
21 # Uncomment to enable JSON API
22 # FOSSIL_ENABLE_JSON = 1
23
24 # Uncomment to enable SSL support
25 # FOSSIL_ENABLE_SSL = 1
 
 
 
26
27 !ifdef FOSSIL_ENABLE_SSL
28 SSLINCDIR = $(B)\compat\openssl-1.0.1f\include
29 SSLLIBDIR = $(B)\compat\openssl-1.0.1f\out32
30 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
31 !endif
 
 
 
 
 
 
32
33 # zlib options
34 ZINCDIR = $(B)\compat\zlib
35 ZLIBDIR = $(B)\compat\zlib
36 ZLIB = zlib.lib
37
38 INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(ZINCDIR)
39
40 !ifdef FOSSIL_ENABLE_SSL
41 INCL = $(INCL) -I$(SSLINCDIR)
 
 
 
 
42 !endif
43
44 CFLAGS = -nologo
45 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
46
47 !ifdef DEBUG
48 CFLAGS = $(CFLAGS) -Zi -MTd -Od
49 LDFLAGS = $(LDFLAGS) /DEBUG
50 !else
51 CFLAGS = $(CFLAGS) -MT -O2
52 !endif
53
54 BCC = $(CC) $(CFLAGS)
55 TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(INCL)
56 RCC = rc -D_WIN32 -D_MSC_VER $(MSCDEF) $(INCL)
57 LIBS = $(ZLIB) ws2_32.lib advapi32.lib
58 LIBDIR = -LIBPATH:$(ZLIBDIR)
59
60 !ifdef FOSSIL_ENABLE_JSON
61 TCC = $(TCC) -DFOSSIL_ENABLE_JSON=1
62 RCC = $(RCC) -DFOSSIL_ENABLE_JSON=1
63 !endif
64
65 !ifdef FOSSIL_ENABLE_SSL
66 TCC = $(TCC) -DFOSSIL_ENABLE_SSL=1
67 RCC = $(RCC) -DFOSSIL_ENABLE_SSL=1
68 LIBS = $(LIBS) $(SSLLIB)
69 LIBDIR = $(LIBDIR) -LIBPATH:$(SSLLIBDIR)
 
 
 
 
 
 
 
 
 
 
 
70 !endif
71
72 SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
73 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
74 /DSQLITE_THREADSAFE=0 \
@@ -76,10 +100,12 @@
76 /DSQLITE_OMIT_DEPRECATED \
77 /DSQLITE_ENABLE_EXPLAIN_COMMENTS
78
79 SHELL_OPTIONS = /Dmain=sqlite3_shell \
80 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
 
 
81 /Dgetenv=fossil_getenv \
82 /Dfopen=fossil_fopen
83
84 SRC = add_.c \
85 allrepo_.c \
@@ -302,10 +328,14 @@
302 $(OX)\wysiwyg$O \
303 $(OX)\xfer$O \
304 $(OX)\xfersetup$O \
305 $(OX)\zip$O \
306 $(OX)\fossil.res
 
 
 
 
307
308 APPNAME = $(OX)\fossil$(E)
309 PDBNAME = $(OX)\fossil$(P)
310
311 all: $(OX) $(APPNAME)
@@ -314,11 +344,11 @@
314 @echo Building zlib from "$(ZLIBDIR)"...
315 @pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd
316
317 $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib
318 cd $(OX)
319 link $(LDFLAGS) -OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
320
321 $(OX)\linkopts: $B\win\Makefile.msc
322 echo $(OX)\add.obj > $@
323 echo $(OX)\allrepo.obj >> $@
324 echo $(OX)\attach.obj >> $@
@@ -430,14 +460,14 @@
430 echo $(OX)\winhttp.obj >> $@
431 echo $(OX)\wysiwyg.obj >> $@
432 echo $(OX)\xfer.obj >> $@
433 echo $(OX)\xfersetup.obj >> $@
434 echo $(OX)\zip.obj >> $@
 
 
 
435 echo $(LIBS) >> $@
436
437
438
439
440 $(OX):
441 @-mkdir $@
442
443 translate$E: $(SRCDIR)\translate.c
@@ -461,15 +491,20 @@
461 $(OX)\th$O : $(SRCDIR)\th.c
462 $(TCC) /Fo$@ -c $**
463
464 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
465 $(TCC) /Fo$@ -c $**
 
 
 
 
 
466
467 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
468 $** > $@
469 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
470 $(TCC) /Fo$@ -c $**
471
472 page_index.h: mkindex$E $(SRC)
473 $** > $@
474
475 clean:
@@ -504,11 +539,10 @@
504 $(OBJDIR)\json_status$O : $(SRCDIR)\json_detail.h
505 $(OBJDIR)\json_tag$O : $(SRCDIR)\json_detail.h
506 $(OBJDIR)\json_timeline$O : $(SRCDIR)\json_detail.h
507 $(OBJDIR)\json_user$O : $(SRCDIR)\json_detail.h
508 $(OBJDIR)\json_wiki$O : $(SRCDIR)\json_detail.h
509
510
511 $(OX)\add$O : add_.c add.h
512 $(TCC) /Fo$@ -c add_.c
513
514 add_.c : $(SRCDIR)\add.c
@@ -1155,11 +1189,12 @@
1155
1156 zip_.c : $(SRCDIR)\zip.c
1157 translate$E $** > $@
1158
1159 fossil.res : $B\win\fossil.rc
1160 $(RCC) -fo $@ $**
 
1161 headers: makeheaders$E page_index.h VERSION.h
1162 makeheaders$E add_.c:add.h \
1163 allrepo_.c:allrepo.h \
1164 attach_.c:attach.h \
1165 bag_.c:bag.h \
1166
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -21,54 +21,78 @@
21 # Uncomment to enable JSON API
22 # FOSSIL_ENABLE_JSON = 1
23
24 # Uncomment to enable SSL support
25 # FOSSIL_ENABLE_SSL = 1
26
27 # Uncomment to enable Tcl support
28 # FOSSIL_ENABLE_TCL = 1
29
30 !ifdef FOSSIL_ENABLE_SSL
31 SSLINCDIR = $(B)\compat\openssl-1.0.1f\include
32 SSLLIBDIR = $(B)\compat\openssl-1.0.1f\out32
33 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
34 !endif
35
36 !ifdef FOSSIL_ENABLE_TCL
37 TCLDIR = $(B)\compat\tcl-8.6
38 TCLSRCDIR = $(TCLDIR)
39 TCLINCDIR = $(TCLSRCDIR)\generic
40 !endif
41
42 # zlib options
43 ZINCDIR = $(B)\compat\zlib
44 ZLIBDIR = $(B)\compat\zlib
45 ZLIB = zlib.lib
46
47 INCL = /I. /I$(SRCDIR) /I$B\win\include /I$(ZINCDIR)
48
49 !ifdef FOSSIL_ENABLE_SSL
50 INCL = $(INCL) /I$(SSLINCDIR)
51 !endif
52
53 !ifdef FOSSIL_ENABLE_TCL
54 INCL = $(INCL) /I$(TCLINCDIR)
55 !endif
56
57 CFLAGS = /nologo
58 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
59
60 !ifdef DEBUG
61 CFLAGS = $(CFLAGS) /Zi /MTd /Od
62 LDFLAGS = $(LDFLAGS) /DEBUG
63 !else
64 CFLAGS = $(CFLAGS) /MT /O2
65 !endif
66
67 BCC = $(CC) $(CFLAGS)
68 TCC = $(CC) /c $(CFLAGS) $(MSCDEF) $(INCL)
69 RCC = rc /D_WIN32 /D_MSC_VER $(MSCDEF) $(INCL)
70 LIBS = $(ZLIB) ws2_32.lib advapi32.lib
71 LIBDIR = /LIBPATH:$(ZLIBDIR)
72
73 !ifdef FOSSIL_ENABLE_JSON
74 TCC = $(TCC) /DFOSSIL_ENABLE_JSON=1
75 RCC = $(RCC) /DFOSSIL_ENABLE_JSON=1
76 !endif
77
78 !ifdef FOSSIL_ENABLE_SSL
79 TCC = $(TCC) /DFOSSIL_ENABLE_SSL=1
80 RCC = $(RCC) /DFOSSIL_ENABLE_SSL=1
81 LIBS = $(LIBS) $(SSLLIB)
82 LIBDIR = $(LIBDIR) /LIBPATH:$(SSLLIBDIR)
83 !endif
84
85 !ifdef FOSSIL_ENABLE_TCL
86 TCC = $(TCC) /DFOSSIL_ENABLE_TCL=1
87 RCC = $(RCC) /DFOSSIL_ENABLE_TCL=1
88 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_STUBS=1
89 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_STUBS=1
90 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
91 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
92 TCC = $(TCC) /DUSE_TCL_STUBS=1
93 RCC = $(RCC) /DUSE_TCL_STUBS=1
94 !endif
95
96 SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
97 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
98 /DSQLITE_THREADSAFE=0 \
@@ -76,10 +100,12 @@
100 /DSQLITE_OMIT_DEPRECATED \
101 /DSQLITE_ENABLE_EXPLAIN_COMMENTS
102
103 SHELL_OPTIONS = /Dmain=sqlite3_shell \
104 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
105 /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
106 /DSQLITE_SHELL_DBNAME_PROC=fossil_open \
107 /Dgetenv=fossil_getenv \
108 /Dfopen=fossil_fopen
109
110 SRC = add_.c \
111 allrepo_.c \
@@ -302,10 +328,14 @@
328 $(OX)\wysiwyg$O \
329 $(OX)\xfer$O \
330 $(OX)\xfersetup$O \
331 $(OX)\zip$O \
332 $(OX)\fossil.res
333
334 !ifdef FOSSIL_ENABLE_TCL
335 OBJ = $(OBJ) $(OX)\th_tcl$O
336 !endif
337
338 APPNAME = $(OX)\fossil$(E)
339 PDBNAME = $(OX)\fossil$(P)
340
341 all: $(OX) $(APPNAME)
@@ -314,11 +344,11 @@
344 @echo Building zlib from "$(ZLIBDIR)"...
345 @pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd
346
347 $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib
348 cd $(OX)
349 link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
350
351 $(OX)\linkopts: $B\win\Makefile.msc
352 echo $(OX)\add.obj > $@
353 echo $(OX)\allrepo.obj >> $@
354 echo $(OX)\attach.obj >> $@
@@ -430,14 +460,14 @@
460 echo $(OX)\winhttp.obj >> $@
461 echo $(OX)\wysiwyg.obj >> $@
462 echo $(OX)\xfer.obj >> $@
463 echo $(OX)\xfersetup.obj >> $@
464 echo $(OX)\zip.obj >> $@
465 !ifdef FOSSIL_ENABLE_TCL
466 echo $(OX)\th_tcl.obj >> $@
467 !endif
468 echo $(LIBS) >> $@
 
 
 
469
470 $(OX):
471 @-mkdir $@
472
473 translate$E: $(SRCDIR)\translate.c
@@ -461,15 +491,20 @@
491 $(OX)\th$O : $(SRCDIR)\th.c
492 $(TCC) /Fo$@ -c $**
493
494 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
495 $(TCC) /Fo$@ -c $**
496
497 !ifdef FOSSIL_ENABLE_TCL
498 $(OX)\th_tcl$O : $(SRCDIR)\th_tcl.c
499 $(TCC) /Fo$@ -c $**
500 !endif
501
502 VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
503 $** > $@
504 $(OX)\cson_amalgamation$O : $(SRCDIR)\cson_amalgamation.c
505 $(TCC) /Fo$@ /c $**
506
507 page_index.h: mkindex$E $(SRC)
508 $** > $@
509
510 clean:
@@ -504,11 +539,10 @@
539 $(OBJDIR)\json_status$O : $(SRCDIR)\json_detail.h
540 $(OBJDIR)\json_tag$O : $(SRCDIR)\json_detail.h
541 $(OBJDIR)\json_timeline$O : $(SRCDIR)\json_detail.h
542 $(OBJDIR)\json_user$O : $(SRCDIR)\json_detail.h
543 $(OBJDIR)\json_wiki$O : $(SRCDIR)\json_detail.h
 
544
545 $(OX)\add$O : add_.c add.h
546 $(TCC) /Fo$@ -c add_.c
547
548 add_.c : $(SRCDIR)\add.c
@@ -1155,11 +1189,12 @@
1189
1190 zip_.c : $(SRCDIR)\zip.c
1191 translate$E $** > $@
1192
1193 fossil.res : $B\win\fossil.rc
1194 $(RCC) /fo $@ $**
1195
1196 headers: makeheaders$E page_index.h VERSION.h
1197 makeheaders$E add_.c:add.h \
1198 allrepo_.c:allrepo.h \
1199 attach_.c:attach.h \
1200 bag_.c:bag.h \
1201
+23 -22
--- www/changes.wiki
+++ www/changes.wiki
@@ -7,10 +7,11 @@
77
* The [/reports] page now requires Read ("o") permissions. The "byweek"
88
report now properly propagates the selected year through the event type
99
filter links.
1010
* The [/help/info | info command] now shows leaf status of the checkout.
1111
* Add support for tunneling https through a http proxy (Ticket [e854101c4f]).
12
+ * Add option --empty to the "[/help?cmd=open | fossil open]" command.
1213
1314
<h2>Changes For Version 1.28 (2014-01-27)</h2>
1415
* Enhance [/help?cmd=/reports | /reports] to support event type filtering.
1516
* When cloning a repository, the user name passed via the URL (if any)
1617
is now used as the default local admin user's name.
@@ -26,40 +27,40 @@
2627
Admin/Configuration.
2728
* Fix CGI processing so that it works on web servers that do not
2829
supply REQUEST_URI.
2930
* Add options --dirsonly, --emptydirs, and --allckouts to the
3031
"[/help?cmd=clean | fossil clean]" command.
31
- * Ten-fold performance improvement in large "fossil blame" or
32
+ * Ten-fold performance improvement in large "fossil blame" or
3233
"fossil annotate" commands.
3334
* Add option -W|--width and --offset to "[/help?cmd=timeline | fossil timeline]"
3435
and "[/help?cmd=finfo | fossil finfo]" commands.
3536
* Option -n|--limit of "[/help?cmd=timeline | fossil timeline]" now
3637
specifies the number of entries, just like all other commands which
3738
have the -n|--limit option. The various timeline-related functions
3839
now output "--- ?? limit (??) reached ---" at the end whenever
3940
appropriate. Use "-n 0" if no limit is desired.
4041
* Fix handling of password embedded in Fossil URL.
41
- * New <tt>--once</tt> option to [/help?cmd=clone | fossil clone] command
42
+ * New <tt>--once</tt> option to [/help?cmd=clone | fossil clone] command
4243
which does not store the URL or password when cloning.
4344
* Modify [/help?cmd=ui | fossil ui] to respect "default user" in an open
4445
repository.
4546
* Fossil now hides check-ins that have the "hidden" tag in timeline webpages.
4647
* Enhance <tt>/ci_edit</tt> page to add the "hidden" tag to check-ins.
4748
* Advanced possibilities for commit and ticket change notifications over
4849
http using TH1 scripting.
49
- * Add --sha1sum and --integrate options
50
+ * Add --sha1sum and --integrate options
5051
to the "[/help?cmd=commit | fossil commit]" command.
51
- * Add the "clean" and "extra" subcommands to the
52
+ * Add the "clean" and "extra" subcommands to the
5253
"[/help?cmd=all | fossil all]" command
5354
* Add the --whatif option to "[/help?cmd=clean|fossil clean]" that works the
5455
same as "--dry-run",
5556
so that the name does not collide with the --dry-run option of "fossil all".
5657
* Provide a configuration option to show dates on the web timeline
5758
as "YYMMMDD HH:MM"
5859
* Add an option to the "stats" webpage that allows an administrator to see
5960
the current repository schema.
60
- * Enhancements to the "[/help?cmd=/vdiff|/vdiff]" webpage for more difference
61
+ * Enhancements to the "[/help?cmd=/vdiff|/vdiff]" webpage for more difference
6162
display options.
6263
* Added the "[/tree?ci=trunk&expand | /tree]" webpage as an alternative
6364
to "/dir" and make it the default way of showing file lists.
6465
* Send gzipped HTTP responses to clients that support it.
6566
@@ -118,11 +119,11 @@
118119
See
119120
[http://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-casesensitive]
120121
* Enhancements to /timeline.rss, adding more flags for filtering
121122
results, including the ability to subscribe to changes made
122123
to individual tickets. For example: [/timeline.rss?y=t&tkt=12fceeec82].
123
- * Improved handling of the differences between case-sensitive and
124
+ * Improved handling of the differences between case-sensitive and
124125
case-insensitive filesystems.
125126
* JSON API: added the 'status' command to report local checkout status.
126127
* Fixes to the <tt>--args</tt> support and documented this feature in the help.
127128
* Added [/stats_report] page.
128129
* Added <tt>ym=YYYY-MM</tt> filter to the [/timeline?ym=2013-06].
@@ -136,15 +137,15 @@
136137
137138
<h2>Changes For Version 1.25 (2013-02-16)</h2>
138139
* Enhancements to ticket processing. There are now two tables: TICKET and
139140
TICKETCHNG. There is one row in TICKETCHNG for each ticket artifact.
140141
Fields from ticket artifacts go into either or both of TICKET and
141
- TICKETCHNG, whichever contain matching column names. Default ticket
142
+ TICKETCHNG, whichever contain matching column names. Default ticket
142143
edit and viewing scripts are updated to use TICKETCHNG. The TH1
143144
scripting language is enhanced to support this, including the new
144145
"query" command for doing SQL queries against the repository database.
145
- All changes should be backwards compatible.
146
+ All changes should be backwards compatible.
146147
* Add the ability to moderate ticket and wiki changes. Unmoderated changes
147148
do not sync and may be deleted by the moderator if found to contain spam
148149
or other objectionable content.
149150
* Add javascript so that clicking on a node of the timeline graph selects
150151
that node. Then clicking on a second node shows a diff between the
@@ -157,16 +158,16 @@
157158
* Add the "fossil cat" command which is basically an alias for
158159
"fossil finfo -p".
159160
* Hyperlinks with the class "button" are rendered as submenu buttons
160161
on embedded documentation.
161162
* The check-in comment editor on windows now defaults to NotePad.exe.
162
- * Correctly deal with BOMs in check-in comments. Also attempt to convert
163
+ * Correctly deal with BOMs in check-in comments. Also attempt to convert
163164
check-in comments to UTF8 from other encodings.
164165
* Allow the deletion of multiple stash entries using multiple arguments
165166
to the "fossil stash rm" command.
166167
* Enhance the "fossil server DIRECTORY" command to serve static content
167
- files contained in DIRECTORY. For security, only files with a
168
+ files contained in DIRECTORY. For security, only files with a
168169
recognized suffix (such as *.html, *.jpg, *.txt, etc) will be delivered
169170
as static content, and *.fossil files are not on the list of recognized
170171
suffixes. There are additional restrictions on the names of the files.
171172
* Allow the "fossil ui" command to specify a directory as long as the
172173
the --notfound option is used.
@@ -189,11 +190,11 @@
189190
* Add options to "fossil commit" to override the various sanity checks.
190191
Options added: --allow-empty, --allow-fork, --allow-older, and
191192
--allow-conflict.
192193
* Optionally require a CAPTCHA (controlled by a setting on the
193194
Admin/Access webpage) when a user who is not logged in tries to
194
- edit wiki, or a ticket, or an attachment.
195
+ edit wiki, or a ticket, or an attachment.
195196
* Improvements to the "ssh://" sync protocol, to help it move past
196197
noisey motd comments.
197198
* Add the uf=FILE-SHA1-HASH query parameter to the timeline, causing the
198199
timeline to show only check-ins that contain the specific file identified
199200
by FILE-SHA1-HASH. ("uf" stands for "uses file".)
@@ -302,16 +303,16 @@
302303
* Added the "public-pages" glob pattern that can be configured to allow
303304
anonymous users to see embedded documentation on sites where source
304305
code should not be accessible to anonymous users.
305306
* Allow multiple --tag options on the same "fossil commit" command.
306307
* Change the meaning of the --bgcolor option for "fossil commit" to only
307
- change the color for that one commit. The new --branchcolor option
308
+ change the color for that one commit. The new --branchcolor option
308309
is available to set a persistent background color.
309310
* Add the branch= query parameter to the vdiff page and the --branch option
310311
to the "fossil diff" command.
311312
* Check-in names of the form "root:BRANCH" now refer to the origin of
312
- the branch. Hence to see all changes in a branch, use
313
+ the branch. Hence to see all changes in a branch, use
313314
"fossil diff --from root:BRANCH --to BRANCH". The --branch option on
314315
the diff command is an alias for the same.
315316
* Add the ability to configure ad-units to be displayed between the menu
316317
bar and the content.
317318
* Add the ability to set a background image as part of server configuration.
@@ -318,18 +319,18 @@
318319
* Allow partial commits of cherrypick merges.
319320
* Updates against an uncommitted merge are now a warning, not a fatal error.
320321
* Prompt the user to continue if a check-in comment is unedited.
321322
* Fixes to case sensitivity settings with the /dir webpage.
322323
* Repositories now try to remember the locations of all checkouts and
323
- web-access URLs and display this information with the
324
+ web-access URLs and display this information with the
324325
"fossil info $REPO" command.
325326
* Improved defense against spiders: The src= attribute of
326327
&lt;a&gt; elements is set using javascript after the page loads.
327328
* Enhanced formatting of the user list page.
328329
* If a file named in "fossil add" is missing, that is now a warning instead
329330
of a fatal error.
330
- * Fix side-by-side diff so that it displays correctly with
331
+ * Fix side-by-side diff so that it displays correctly with
331332
multi-byte UTF8 characters.
332333
* Performance improvements in the diff logic.
333334
* Other performance tweaks and documentation updates.
334335
335336
<h2>Changes For Version 1.22 (2012-03-17)</h2>
@@ -338,11 +339,11 @@
338339
* Promote "allow-symlinks" to a versionable setting
339340
* Harden the CGI processing logic against DOS attacks
340341
* Add the ability to run TH1 scripts after sync requests
341342
* Store the repository name in _FOSSIL_ as it is type in the "open" command,
342343
possibly as a relative pathname.
343
- * Make ".fslckout" the alternative name for the "_FOSSIL_" file.
344
+ * Make ".fslckout" the alternative name for the "_FOSSIL_" file.
344345
* Change the "ssh:" transfer method to allow all access regardless of
345346
user permission.
346347
* Improvements to the timeline messages associated with tag changes.
347348
(Requires a "[/help/rebuild | fossil rebuild]" to take effect.)
348349
* Various additions and fixes for the JSON API.
@@ -352,17 +353,17 @@
352353
* Update to use SQLite version 3.7.11.
353354
* Various minor bug fixes.
354355
355356
<h2>Changes For Version 1.21 (2011-12-13)</h2>
356357
* Added side-by-side diffs in the command-line interface
357
- * Automatically enable hyperlinks if the UserAgent string in the
358
+ * Automatically enable hyperlinks if the UserAgent string in the
358359
HTTP header suggests that the requestor is a human and not a bot.
359360
* Show only commonly used commands with "fossil help". Use
360361
"fossil help --all" to see the complete list now.
361
- * Improvements to the "stash" command: (1) Stash all files, not just
362
- those below the working directory. (2) Add the --detail option to
363
- "list". (3) Confirm before "drop --all". (4) Add the "help"
362
+ * Improvements to the "stash" command: (1) Stash all files, not just
363
+ those below the working directory. (2) Add the --detail option to
364
+ "list". (3) Confirm before "drop --all". (4) Add the "help"
364365
subcommand.
365366
* Add an Admin/Access setting to change the number of octets of the
366367
IP address that are saved in login cookies - allowing this setting
367368
to be changed to zero
368369
* Promote the "test-md5sum" command to "md5sum".
@@ -381,11 +382,11 @@
381382
* Added side-by-side diffs in HTML interface. [0bde74ea1e]
382383
* Added support for symlinks. (Controlled by "allow-symlinks" setting,
383384
off by default). [e4f1c1fe95]
384385
* Fixed CLI annotate to show the proper file version in case there
385386
are multiple equal versions in history. [e161670939]
386
- * Timeline now shows tag changes (requires rebuild).[87540ed6e6]
387
+ * Timeline now shows tag changes (requires rebuild).[87540ed6e6]
387388
* Fixed annotate to show "more relevant" versions of lines in
388389
some cases. [e161670939]
389390
* New command: ticket history. [98a855c508]
390391
* Disabled SSLv2 in HTTPS client.[ea1d369d23]
391392
* Fixed constant prompting regarding previously-saved SSL
@@ -396,11 +397,11 @@
396397
always identical for any given checkin. [e080560378]
397398
* A number of minor HTML-related tweaks and fixes.
398399
* Added --args FILENAME global CLI argument to import arbitrary
399400
CLI arguments from a file (e.g. long file lists). [e080560378]
400401
* Fixed significant memory leak in annotation of files with long
401
- histories.[9929bab702]
402
+ histories.[9929bab702]
402403
* Added warnings when a merge operation overwrites local copies
403404
(UNDO is available, but previously this condition normally went
404405
silently unnoticed). [39f979b08c]
405406
* Improved performance when adding many files. [a369dc7721]
406407
* Improve merges which contain many file renames. [0b93b0f958]
407408
--- www/changes.wiki
+++ www/changes.wiki
@@ -7,10 +7,11 @@
7 * The [/reports] page now requires Read ("o") permissions. The "byweek"
8 report now properly propagates the selected year through the event type
9 filter links.
10 * The [/help/info | info command] now shows leaf status of the checkout.
11 * Add support for tunneling https through a http proxy (Ticket [e854101c4f]).
 
12
13 <h2>Changes For Version 1.28 (2014-01-27)</h2>
14 * Enhance [/help?cmd=/reports | /reports] to support event type filtering.
15 * When cloning a repository, the user name passed via the URL (if any)
16 is now used as the default local admin user's name.
@@ -26,40 +27,40 @@
26 Admin/Configuration.
27 * Fix CGI processing so that it works on web servers that do not
28 supply REQUEST_URI.
29 * Add options --dirsonly, --emptydirs, and --allckouts to the
30 "[/help?cmd=clean | fossil clean]" command.
31 * Ten-fold performance improvement in large "fossil blame" or
32 "fossil annotate" commands.
33 * Add option -W|--width and --offset to "[/help?cmd=timeline | fossil timeline]"
34 and "[/help?cmd=finfo | fossil finfo]" commands.
35 * Option -n|--limit of "[/help?cmd=timeline | fossil timeline]" now
36 specifies the number of entries, just like all other commands which
37 have the -n|--limit option. The various timeline-related functions
38 now output "--- ?? limit (??) reached ---" at the end whenever
39 appropriate. Use "-n 0" if no limit is desired.
40 * Fix handling of password embedded in Fossil URL.
41 * New <tt>--once</tt> option to [/help?cmd=clone | fossil clone] command
42 which does not store the URL or password when cloning.
43 * Modify [/help?cmd=ui | fossil ui] to respect "default user" in an open
44 repository.
45 * Fossil now hides check-ins that have the "hidden" tag in timeline webpages.
46 * Enhance <tt>/ci_edit</tt> page to add the "hidden" tag to check-ins.
47 * Advanced possibilities for commit and ticket change notifications over
48 http using TH1 scripting.
49 * Add --sha1sum and --integrate options
50 to the "[/help?cmd=commit | fossil commit]" command.
51 * Add the "clean" and "extra" subcommands to the
52 "[/help?cmd=all | fossil all]" command
53 * Add the --whatif option to "[/help?cmd=clean|fossil clean]" that works the
54 same as "--dry-run",
55 so that the name does not collide with the --dry-run option of "fossil all".
56 * Provide a configuration option to show dates on the web timeline
57 as "YYMMMDD HH:MM"
58 * Add an option to the "stats" webpage that allows an administrator to see
59 the current repository schema.
60 * Enhancements to the "[/help?cmd=/vdiff|/vdiff]" webpage for more difference
61 display options.
62 * Added the "[/tree?ci=trunk&expand | /tree]" webpage as an alternative
63 to "/dir" and make it the default way of showing file lists.
64 * Send gzipped HTTP responses to clients that support it.
65
@@ -118,11 +119,11 @@
118 See
119 [http://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-casesensitive]
120 * Enhancements to /timeline.rss, adding more flags for filtering
121 results, including the ability to subscribe to changes made
122 to individual tickets. For example: [/timeline.rss?y=t&tkt=12fceeec82].
123 * Improved handling of the differences between case-sensitive and
124 case-insensitive filesystems.
125 * JSON API: added the 'status' command to report local checkout status.
126 * Fixes to the <tt>--args</tt> support and documented this feature in the help.
127 * Added [/stats_report] page.
128 * Added <tt>ym=YYYY-MM</tt> filter to the [/timeline?ym=2013-06].
@@ -136,15 +137,15 @@
136
137 <h2>Changes For Version 1.25 (2013-02-16)</h2>
138 * Enhancements to ticket processing. There are now two tables: TICKET and
139 TICKETCHNG. There is one row in TICKETCHNG for each ticket artifact.
140 Fields from ticket artifacts go into either or both of TICKET and
141 TICKETCHNG, whichever contain matching column names. Default ticket
142 edit and viewing scripts are updated to use TICKETCHNG. The TH1
143 scripting language is enhanced to support this, including the new
144 "query" command for doing SQL queries against the repository database.
145 All changes should be backwards compatible.
146 * Add the ability to moderate ticket and wiki changes. Unmoderated changes
147 do not sync and may be deleted by the moderator if found to contain spam
148 or other objectionable content.
149 * Add javascript so that clicking on a node of the timeline graph selects
150 that node. Then clicking on a second node shows a diff between the
@@ -157,16 +158,16 @@
157 * Add the "fossil cat" command which is basically an alias for
158 "fossil finfo -p".
159 * Hyperlinks with the class "button" are rendered as submenu buttons
160 on embedded documentation.
161 * The check-in comment editor on windows now defaults to NotePad.exe.
162 * Correctly deal with BOMs in check-in comments. Also attempt to convert
163 check-in comments to UTF8 from other encodings.
164 * Allow the deletion of multiple stash entries using multiple arguments
165 to the "fossil stash rm" command.
166 * Enhance the "fossil server DIRECTORY" command to serve static content
167 files contained in DIRECTORY. For security, only files with a
168 recognized suffix (such as *.html, *.jpg, *.txt, etc) will be delivered
169 as static content, and *.fossil files are not on the list of recognized
170 suffixes. There are additional restrictions on the names of the files.
171 * Allow the "fossil ui" command to specify a directory as long as the
172 the --notfound option is used.
@@ -189,11 +190,11 @@
189 * Add options to "fossil commit" to override the various sanity checks.
190 Options added: --allow-empty, --allow-fork, --allow-older, and
191 --allow-conflict.
192 * Optionally require a CAPTCHA (controlled by a setting on the
193 Admin/Access webpage) when a user who is not logged in tries to
194 edit wiki, or a ticket, or an attachment.
195 * Improvements to the "ssh://" sync protocol, to help it move past
196 noisey motd comments.
197 * Add the uf=FILE-SHA1-HASH query parameter to the timeline, causing the
198 timeline to show only check-ins that contain the specific file identified
199 by FILE-SHA1-HASH. ("uf" stands for "uses file".)
@@ -302,16 +303,16 @@
302 * Added the "public-pages" glob pattern that can be configured to allow
303 anonymous users to see embedded documentation on sites where source
304 code should not be accessible to anonymous users.
305 * Allow multiple --tag options on the same "fossil commit" command.
306 * Change the meaning of the --bgcolor option for "fossil commit" to only
307 change the color for that one commit. The new --branchcolor option
308 is available to set a persistent background color.
309 * Add the branch= query parameter to the vdiff page and the --branch option
310 to the "fossil diff" command.
311 * Check-in names of the form "root:BRANCH" now refer to the origin of
312 the branch. Hence to see all changes in a branch, use
313 "fossil diff --from root:BRANCH --to BRANCH". The --branch option on
314 the diff command is an alias for the same.
315 * Add the ability to configure ad-units to be displayed between the menu
316 bar and the content.
317 * Add the ability to set a background image as part of server configuration.
@@ -318,18 +319,18 @@
318 * Allow partial commits of cherrypick merges.
319 * Updates against an uncommitted merge are now a warning, not a fatal error.
320 * Prompt the user to continue if a check-in comment is unedited.
321 * Fixes to case sensitivity settings with the /dir webpage.
322 * Repositories now try to remember the locations of all checkouts and
323 web-access URLs and display this information with the
324 "fossil info $REPO" command.
325 * Improved defense against spiders: The src= attribute of
326 &lt;a&gt; elements is set using javascript after the page loads.
327 * Enhanced formatting of the user list page.
328 * If a file named in "fossil add" is missing, that is now a warning instead
329 of a fatal error.
330 * Fix side-by-side diff so that it displays correctly with
331 multi-byte UTF8 characters.
332 * Performance improvements in the diff logic.
333 * Other performance tweaks and documentation updates.
334
335 <h2>Changes For Version 1.22 (2012-03-17)</h2>
@@ -338,11 +339,11 @@
338 * Promote "allow-symlinks" to a versionable setting
339 * Harden the CGI processing logic against DOS attacks
340 * Add the ability to run TH1 scripts after sync requests
341 * Store the repository name in _FOSSIL_ as it is type in the "open" command,
342 possibly as a relative pathname.
343 * Make ".fslckout" the alternative name for the "_FOSSIL_" file.
344 * Change the "ssh:" transfer method to allow all access regardless of
345 user permission.
346 * Improvements to the timeline messages associated with tag changes.
347 (Requires a "[/help/rebuild | fossil rebuild]" to take effect.)
348 * Various additions and fixes for the JSON API.
@@ -352,17 +353,17 @@
352 * Update to use SQLite version 3.7.11.
353 * Various minor bug fixes.
354
355 <h2>Changes For Version 1.21 (2011-12-13)</h2>
356 * Added side-by-side diffs in the command-line interface
357 * Automatically enable hyperlinks if the UserAgent string in the
358 HTTP header suggests that the requestor is a human and not a bot.
359 * Show only commonly used commands with "fossil help". Use
360 "fossil help --all" to see the complete list now.
361 * Improvements to the "stash" command: (1) Stash all files, not just
362 those below the working directory. (2) Add the --detail option to
363 "list". (3) Confirm before "drop --all". (4) Add the "help"
364 subcommand.
365 * Add an Admin/Access setting to change the number of octets of the
366 IP address that are saved in login cookies - allowing this setting
367 to be changed to zero
368 * Promote the "test-md5sum" command to "md5sum".
@@ -381,11 +382,11 @@
381 * Added side-by-side diffs in HTML interface. [0bde74ea1e]
382 * Added support for symlinks. (Controlled by "allow-symlinks" setting,
383 off by default). [e4f1c1fe95]
384 * Fixed CLI annotate to show the proper file version in case there
385 are multiple equal versions in history. [e161670939]
386 * Timeline now shows tag changes (requires rebuild).[87540ed6e6]
387 * Fixed annotate to show "more relevant" versions of lines in
388 some cases. [e161670939]
389 * New command: ticket history. [98a855c508]
390 * Disabled SSLv2 in HTTPS client.[ea1d369d23]
391 * Fixed constant prompting regarding previously-saved SSL
@@ -396,11 +397,11 @@
396 always identical for any given checkin. [e080560378]
397 * A number of minor HTML-related tweaks and fixes.
398 * Added --args FILENAME global CLI argument to import arbitrary
399 CLI arguments from a file (e.g. long file lists). [e080560378]
400 * Fixed significant memory leak in annotation of files with long
401 histories.[9929bab702]
402 * Added warnings when a merge operation overwrites local copies
403 (UNDO is available, but previously this condition normally went
404 silently unnoticed). [39f979b08c]
405 * Improved performance when adding many files. [a369dc7721]
406 * Improve merges which contain many file renames. [0b93b0f958]
407
--- www/changes.wiki
+++ www/changes.wiki
@@ -7,10 +7,11 @@
7 * The [/reports] page now requires Read ("o") permissions. The "byweek"
8 report now properly propagates the selected year through the event type
9 filter links.
10 * The [/help/info | info command] now shows leaf status of the checkout.
11 * Add support for tunneling https through a http proxy (Ticket [e854101c4f]).
12 * Add option --empty to the "[/help?cmd=open | fossil open]" command.
13
14 <h2>Changes For Version 1.28 (2014-01-27)</h2>
15 * Enhance [/help?cmd=/reports | /reports] to support event type filtering.
16 * When cloning a repository, the user name passed via the URL (if any)
17 is now used as the default local admin user's name.
@@ -26,40 +27,40 @@
27 Admin/Configuration.
28 * Fix CGI processing so that it works on web servers that do not
29 supply REQUEST_URI.
30 * Add options --dirsonly, --emptydirs, and --allckouts to the
31 "[/help?cmd=clean | fossil clean]" command.
32 * Ten-fold performance improvement in large "fossil blame" or
33 "fossil annotate" commands.
34 * Add option -W|--width and --offset to "[/help?cmd=timeline | fossil timeline]"
35 and "[/help?cmd=finfo | fossil finfo]" commands.
36 * Option -n|--limit of "[/help?cmd=timeline | fossil timeline]" now
37 specifies the number of entries, just like all other commands which
38 have the -n|--limit option. The various timeline-related functions
39 now output "--- ?? limit (??) reached ---" at the end whenever
40 appropriate. Use "-n 0" if no limit is desired.
41 * Fix handling of password embedded in Fossil URL.
42 * New <tt>--once</tt> option to [/help?cmd=clone | fossil clone] command
43 which does not store the URL or password when cloning.
44 * Modify [/help?cmd=ui | fossil ui] to respect "default user" in an open
45 repository.
46 * Fossil now hides check-ins that have the "hidden" tag in timeline webpages.
47 * Enhance <tt>/ci_edit</tt> page to add the "hidden" tag to check-ins.
48 * Advanced possibilities for commit and ticket change notifications over
49 http using TH1 scripting.
50 * Add --sha1sum and --integrate options
51 to the "[/help?cmd=commit | fossil commit]" command.
52 * Add the "clean" and "extra" subcommands to the
53 "[/help?cmd=all | fossil all]" command
54 * Add the --whatif option to "[/help?cmd=clean|fossil clean]" that works the
55 same as "--dry-run",
56 so that the name does not collide with the --dry-run option of "fossil all".
57 * Provide a configuration option to show dates on the web timeline
58 as "YYMMMDD HH:MM"
59 * Add an option to the "stats" webpage that allows an administrator to see
60 the current repository schema.
61 * Enhancements to the "[/help?cmd=/vdiff|/vdiff]" webpage for more difference
62 display options.
63 * Added the "[/tree?ci=trunk&expand | /tree]" webpage as an alternative
64 to "/dir" and make it the default way of showing file lists.
65 * Send gzipped HTTP responses to clients that support it.
66
@@ -118,11 +119,11 @@
119 See
120 [http://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-casesensitive]
121 * Enhancements to /timeline.rss, adding more flags for filtering
122 results, including the ability to subscribe to changes made
123 to individual tickets. For example: [/timeline.rss?y=t&tkt=12fceeec82].
124 * Improved handling of the differences between case-sensitive and
125 case-insensitive filesystems.
126 * JSON API: added the 'status' command to report local checkout status.
127 * Fixes to the <tt>--args</tt> support and documented this feature in the help.
128 * Added [/stats_report] page.
129 * Added <tt>ym=YYYY-MM</tt> filter to the [/timeline?ym=2013-06].
@@ -136,15 +137,15 @@
137
138 <h2>Changes For Version 1.25 (2013-02-16)</h2>
139 * Enhancements to ticket processing. There are now two tables: TICKET and
140 TICKETCHNG. There is one row in TICKETCHNG for each ticket artifact.
141 Fields from ticket artifacts go into either or both of TICKET and
142 TICKETCHNG, whichever contain matching column names. Default ticket
143 edit and viewing scripts are updated to use TICKETCHNG. The TH1
144 scripting language is enhanced to support this, including the new
145 "query" command for doing SQL queries against the repository database.
146 All changes should be backwards compatible.
147 * Add the ability to moderate ticket and wiki changes. Unmoderated changes
148 do not sync and may be deleted by the moderator if found to contain spam
149 or other objectionable content.
150 * Add javascript so that clicking on a node of the timeline graph selects
151 that node. Then clicking on a second node shows a diff between the
@@ -157,16 +158,16 @@
158 * Add the "fossil cat" command which is basically an alias for
159 "fossil finfo -p".
160 * Hyperlinks with the class "button" are rendered as submenu buttons
161 on embedded documentation.
162 * The check-in comment editor on windows now defaults to NotePad.exe.
163 * Correctly deal with BOMs in check-in comments. Also attempt to convert
164 check-in comments to UTF8 from other encodings.
165 * Allow the deletion of multiple stash entries using multiple arguments
166 to the "fossil stash rm" command.
167 * Enhance the "fossil server DIRECTORY" command to serve static content
168 files contained in DIRECTORY. For security, only files with a
169 recognized suffix (such as *.html, *.jpg, *.txt, etc) will be delivered
170 as static content, and *.fossil files are not on the list of recognized
171 suffixes. There are additional restrictions on the names of the files.
172 * Allow the "fossil ui" command to specify a directory as long as the
173 the --notfound option is used.
@@ -189,11 +190,11 @@
190 * Add options to "fossil commit" to override the various sanity checks.
191 Options added: --allow-empty, --allow-fork, --allow-older, and
192 --allow-conflict.
193 * Optionally require a CAPTCHA (controlled by a setting on the
194 Admin/Access webpage) when a user who is not logged in tries to
195 edit wiki, or a ticket, or an attachment.
196 * Improvements to the "ssh://" sync protocol, to help it move past
197 noisey motd comments.
198 * Add the uf=FILE-SHA1-HASH query parameter to the timeline, causing the
199 timeline to show only check-ins that contain the specific file identified
200 by FILE-SHA1-HASH. ("uf" stands for "uses file".)
@@ -302,16 +303,16 @@
303 * Added the "public-pages" glob pattern that can be configured to allow
304 anonymous users to see embedded documentation on sites where source
305 code should not be accessible to anonymous users.
306 * Allow multiple --tag options on the same "fossil commit" command.
307 * Change the meaning of the --bgcolor option for "fossil commit" to only
308 change the color for that one commit. The new --branchcolor option
309 is available to set a persistent background color.
310 * Add the branch= query parameter to the vdiff page and the --branch option
311 to the "fossil diff" command.
312 * Check-in names of the form "root:BRANCH" now refer to the origin of
313 the branch. Hence to see all changes in a branch, use
314 "fossil diff --from root:BRANCH --to BRANCH". The --branch option on
315 the diff command is an alias for the same.
316 * Add the ability to configure ad-units to be displayed between the menu
317 bar and the content.
318 * Add the ability to set a background image as part of server configuration.
@@ -318,18 +319,18 @@
319 * Allow partial commits of cherrypick merges.
320 * Updates against an uncommitted merge are now a warning, not a fatal error.
321 * Prompt the user to continue if a check-in comment is unedited.
322 * Fixes to case sensitivity settings with the /dir webpage.
323 * Repositories now try to remember the locations of all checkouts and
324 web-access URLs and display this information with the
325 "fossil info $REPO" command.
326 * Improved defense against spiders: The src= attribute of
327 &lt;a&gt; elements is set using javascript after the page loads.
328 * Enhanced formatting of the user list page.
329 * If a file named in "fossil add" is missing, that is now a warning instead
330 of a fatal error.
331 * Fix side-by-side diff so that it displays correctly with
332 multi-byte UTF8 characters.
333 * Performance improvements in the diff logic.
334 * Other performance tweaks and documentation updates.
335
336 <h2>Changes For Version 1.22 (2012-03-17)</h2>
@@ -338,11 +339,11 @@
339 * Promote "allow-symlinks" to a versionable setting
340 * Harden the CGI processing logic against DOS attacks
341 * Add the ability to run TH1 scripts after sync requests
342 * Store the repository name in _FOSSIL_ as it is type in the "open" command,
343 possibly as a relative pathname.
344 * Make ".fslckout" the alternative name for the "_FOSSIL_" file.
345 * Change the "ssh:" transfer method to allow all access regardless of
346 user permission.
347 * Improvements to the timeline messages associated with tag changes.
348 (Requires a "[/help/rebuild | fossil rebuild]" to take effect.)
349 * Various additions and fixes for the JSON API.
@@ -352,17 +353,17 @@
353 * Update to use SQLite version 3.7.11.
354 * Various minor bug fixes.
355
356 <h2>Changes For Version 1.21 (2011-12-13)</h2>
357 * Added side-by-side diffs in the command-line interface
358 * Automatically enable hyperlinks if the UserAgent string in the
359 HTTP header suggests that the requestor is a human and not a bot.
360 * Show only commonly used commands with "fossil help". Use
361 "fossil help --all" to see the complete list now.
362 * Improvements to the "stash" command: (1) Stash all files, not just
363 those below the working directory. (2) Add the --detail option to
364 "list". (3) Confirm before "drop --all". (4) Add the "help"
365 subcommand.
366 * Add an Admin/Access setting to change the number of octets of the
367 IP address that are saved in login cookies - allowing this setting
368 to be changed to zero
369 * Promote the "test-md5sum" command to "md5sum".
@@ -381,11 +382,11 @@
382 * Added side-by-side diffs in HTML interface. [0bde74ea1e]
383 * Added support for symlinks. (Controlled by "allow-symlinks" setting,
384 off by default). [e4f1c1fe95]
385 * Fixed CLI annotate to show the proper file version in case there
386 are multiple equal versions in history. [e161670939]
387 * Timeline now shows tag changes (requires rebuild).[87540ed6e6]
388 * Fixed annotate to show "more relevant" versions of lines in
389 some cases. [e161670939]
390 * New command: ticket history. [98a855c508]
391 * Disabled SSLv2 in HTTPS client.[ea1d369d23]
392 * Fixed constant prompting regarding previously-saved SSL
@@ -396,11 +397,11 @@
397 always identical for any given checkin. [e080560378]
398 * A number of minor HTML-related tweaks and fixes.
399 * Added --args FILENAME global CLI argument to import arbitrary
400 CLI arguments from a file (e.g. long file lists). [e080560378]
401 * Fixed significant memory leak in annotation of files with long
402 histories.[9929bab702]
403 * Added warnings when a merge operation overwrites local copies
404 (UNDO is available, but previously this condition normally went
405 silently unnoticed). [39f979b08c]
406 * Improved performance when adding many files. [a369dc7721]
407 * Improve merges which contain many file renames. [0b93b0f958]
408
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -138,31 +138,31 @@
138138
<i>YYYY</i><b>-</b><i>MM</i><b>-</b><i>DD</i><b>T</b><i>HH</i><b>:</b><i>MM</i><b>:</b><i>SS</i><br>
139139
<i>YYYY</i><b>-</b><i>MM</i><b>-</b><i>DD</i><b>T</b><i>HH</i><b>:</b><i>MM</i><b>:</b><i>SS</i><b>.</b><i>SSS</i>
140140
</blockquote>
141141
142142
A manifest has zero or more F-cards. Each F-card identifies a file
143
-that is part of the check-in. There are one, two, three, or four arguments.
144
-The first argument
145
-is the pathname of the file in the check-in relative to the root
146
-of the project file hierarchy. No ".." or "." directories are allowed
147
-within the filename. Space characters are escaped as in C-card
148
-comment text. Backslash characters and newlines are not allowed
149
-within filenames. The directory separator character is a forward
150
-slash (ASCII 0x2F). The second argument to the F-card is the
151
-full 40-character lower-case hexadecimal SHA1 hash of the content
152
-artifact. The second argument is required for baseline manifests
153
-but is optional for delta manifests. When the second argument to the
154
-F-card is omitted, it means that the file has been deleted relative
155
-to the baseline. The optional 3rd argument defines any special access
156
-permissions associated with the file. The only special code currently
157
-defined is "x" which means that the file is executable. All files are
158
-always readable and writable. This can be expressed by "w" permission
159
-if desired but is optional. The file format might be extended with
160
-new permission letters in the future.
161
-The optional 4th argument is the name of the same file as it existed in
162
-the parent check-in. If the name of the file is unchanged from its
163
-parent, then the 4th argument is omitted.
143
+that is part of the check-in. There are one, two, three, or four
144
+arguments. The first argument is the pathname of the file in the
145
+check-in relative to the root of the project file hierarchy. No ".."
146
+or "." directories are allowed within the filename. Space characters
147
+are escaped as in C-card comment text. Backslash characters and
148
+newlines are not allowed within filenames. The directory separator
149
+character is a forward slash (ASCII 0x2F). The second argument to the
150
+F-card is the full 40-character lower-case hexadecimal SHA1 hash of
151
+the content artifact. The second argument is required for baseline
152
+manifests but is optional for delta manifests. When the second
153
+argument to the F-card is omitted, it means that the file has been
154
+deleted relative to the baseline (files removed in baseline manifests
155
+versions are <em>not</em> added as F-cards). The optional 3rd argument
156
+defines any special access permissions associated with the file. This
157
+can be defined as "x" to mean that the file is executable or "l"
158
+(small letter ell) to mean a symlink. All files are always readable
159
+and writable. This can be expressed by "w" permission if desired but
160
+is optional. The file format might be extended with new permission
161
+letters in the future. The optional 4th argument is the name of the
162
+same file as it existed in the parent check-in. If the name of the
163
+file is unchanged from its parent, then the 4th argument is omitted.
164164
165165
A manifest has zero or one N-cards. The N-card specifies the mimetype for the
166166
text in the comment of the C-card. If the N-card is omitted, a default mimetype
167167
is used.
168168
169169
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -138,31 +138,31 @@
138 <i>YYYY</i><b>-</b><i>MM</i><b>-</b><i>DD</i><b>T</b><i>HH</i><b>:</b><i>MM</i><b>:</b><i>SS</i><br>
139 <i>YYYY</i><b>-</b><i>MM</i><b>-</b><i>DD</i><b>T</b><i>HH</i><b>:</b><i>MM</i><b>:</b><i>SS</i><b>.</b><i>SSS</i>
140 </blockquote>
141
142 A manifest has zero or more F-cards. Each F-card identifies a file
143 that is part of the check-in. There are one, two, three, or four arguments.
144 The first argument
145 is the pathname of the file in the check-in relative to the root
146 of the project file hierarchy. No ".." or "." directories are allowed
147 within the filename. Space characters are escaped as in C-card
148 comment text. Backslash characters and newlines are not allowed
149 within filenames. The directory separator character is a forward
150 slash (ASCII 0x2F). The second argument to the F-card is the
151 full 40-character lower-case hexadecimal SHA1 hash of the content
152 artifact. The second argument is required for baseline manifests
153 but is optional for delta manifests. When the second argument to the
154 F-card is omitted, it means that the file has been deleted relative
155 to the baseline. The optional 3rd argument defines any special access
156 permissions associated with the file. The only special code currently
157 defined is "x" which means that the file is executable. All files are
158 always readable and writable. This can be expressed by "w" permission
159 if desired but is optional. The file format might be extended with
160 new permission letters in the future.
161 The optional 4th argument is the name of the same file as it existed in
162 the parent check-in. If the name of the file is unchanged from its
163 parent, then the 4th argument is omitted.
164
165 A manifest has zero or one N-cards. The N-card specifies the mimetype for the
166 text in the comment of the C-card. If the N-card is omitted, a default mimetype
167 is used.
168
169
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -138,31 +138,31 @@
138 <i>YYYY</i><b>-</b><i>MM</i><b>-</b><i>DD</i><b>T</b><i>HH</i><b>:</b><i>MM</i><b>:</b><i>SS</i><br>
139 <i>YYYY</i><b>-</b><i>MM</i><b>-</b><i>DD</i><b>T</b><i>HH</i><b>:</b><i>MM</i><b>:</b><i>SS</i><b>.</b><i>SSS</i>
140 </blockquote>
141
142 A manifest has zero or more F-cards. Each F-card identifies a file
143 that is part of the check-in. There are one, two, three, or four
144 arguments. The first argument is the pathname of the file in the
145 check-in relative to the root of the project file hierarchy. No ".."
146 or "." directories are allowed within the filename. Space characters
147 are escaped as in C-card comment text. Backslash characters and
148 newlines are not allowed within filenames. The directory separator
149 character is a forward slash (ASCII 0x2F). The second argument to the
150 F-card is the full 40-character lower-case hexadecimal SHA1 hash of
151 the content artifact. The second argument is required for baseline
152 manifests but is optional for delta manifests. When the second
153 argument to the F-card is omitted, it means that the file has been
154 deleted relative to the baseline (files removed in baseline manifests
155 versions are <em>not</em> added as F-cards). The optional 3rd argument
156 defines any special access permissions associated with the file. This
157 can be defined as "x" to mean that the file is executable or "l"
158 (small letter ell) to mean a symlink. All files are always readable
159 and writable. This can be expressed by "w" permission if desired but
160 is optional. The file format might be extended with new permission
161 letters in the future. The optional 4th argument is the name of the
162 same file as it existed in the parent check-in. If the name of the
163 file is unchanged from its parent, then the 4th argument is omitted.
164
165 A manifest has zero or one N-cards. The N-card specifies the mimetype for the
166 text in the comment of the C-card. If the N-card is omitted, a default mimetype
167 is used.
168
169
+1 -1
--- www/index.wiki
+++ www/index.wiki
@@ -23,11 +23,11 @@
2323
<li> [/timeline | Recent changes]
2424
<li> [./faq.wiki | FAQ]
2525
<li> [./hacker-howto.wiki | Hacker How-To]
2626
<li> [./changes.wiki | Change Log]
2727
<li> [./hints.wiki | Tip &amp; Hints]
28
-<li> [./permutedindex.wiki#pindex | Documentation Index]
28
+<li> [./permutedindex.wiki | Documentation Index]
2929
<li> [http://www.fossil-scm.org/schimpf-book/home | Jim Schimpf's book]
3030
<li> Mailing list
3131
<ul>
3232
<li> [http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users | sign-up]
3333
<li> [http://www.mail-archive.com/[email protected] | archives]
3434
--- www/index.wiki
+++ www/index.wiki
@@ -23,11 +23,11 @@
23 <li> [/timeline | Recent changes]
24 <li> [./faq.wiki | FAQ]
25 <li> [./hacker-howto.wiki | Hacker How-To]
26 <li> [./changes.wiki | Change Log]
27 <li> [./hints.wiki | Tip &amp; Hints]
28 <li> [./permutedindex.wiki#pindex | Documentation Index]
29 <li> [http://www.fossil-scm.org/schimpf-book/home | Jim Schimpf's book]
30 <li> Mailing list
31 <ul>
32 <li> [http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users | sign-up]
33 <li> [http://www.mail-archive.com/[email protected] | archives]
34
--- www/index.wiki
+++ www/index.wiki
@@ -23,11 +23,11 @@
23 <li> [/timeline | Recent changes]
24 <li> [./faq.wiki | FAQ]
25 <li> [./hacker-howto.wiki | Hacker How-To]
26 <li> [./changes.wiki | Change Log]
27 <li> [./hints.wiki | Tip &amp; Hints]
28 <li> [./permutedindex.wiki | Documentation Index]
29 <li> [http://www.fossil-scm.org/schimpf-book/home | Jim Schimpf's book]
30 <li> Mailing list
31 <ul>
32 <li> [http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users | sign-up]
33 <li> [http://www.mail-archive.com/[email protected] | archives]
34

Keyboard Shortcuts

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