Fossil SCM

Merge trunk. Fix uninitialized variable. Less copying of complete structure content.

jan.nijtmans 2013-12-13 11:31 tkt-change-hook merge
Commit 85528ef5078f2d99e37cd94fafb64b075246db10
--- a/Makefile.Cygwin.in
+++ b/Makefile.Cygwin.in
@@ -0,0 +1,52 @@
1
+#!/usr/bin/make
2
+#
3
+# This is the top-level makefile for Fossil when the build is occurring
4
+# on the Cygwin platform.
5
+#
6
+#### The toplevel directory of the source tree. Fossil can be built
7
+# in a directory that is separate from the source tree. Just change
8
+# the following to point from the build directory to the src/ folder.
9
+#
10
+SRCDIR = @srcdir@/src
11
+
12
+#### The directory into which object code files should be written.
13
+# Having a "./" prefix in the value of this variable breaks our use of the
14
+# "makeheaders" tool when running make on the MinGW platform, apparently
15
+# due to some command line argument manipulation performed automatically
16
+# by the shell.
17
+#
18
+#
19
+OBJDIR = bld
20
+
21
+#### C Compiler and options for use in building executables that
22
+# will run on the platform that is doing the build. This is used
23
+# to compile code-generator programs as part of the build process.
24
+# See TCC below for the C compiler for building the finished binary.
25
+#
26
+BCC = @CC_FOR_BUILD@
27
+
28
+#### The suffix to add to final executable file. When cross-compiling
29
+# to windows, make this ".exe". Otherwise leave it blank.
30
+#
31
+E = @EXEEXT@
32
+
33
+TCC = @CC@
34
+
35
+#### Tcl shell for use in running the fossil testsuite. If you do not
36
+# care about testing the end result, this can be blank.
37
+#
38
+TCLSH = tclsh
39
+
40
+LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
41
+TCC += @EXTRA_CFLAGS@ @CPPFLAGS@ @
42
+INSTALLDIR =$(DESTDIR)@prefix@/bin
43
+USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
44
+FOSSIL_ENABLE_TCL = @FOSSIL_ENABLE_TCL@
45
+FOSSIL_ENABLE_TCL_STUBS = @FOSSIL_ENABLE_TCL_STUBS@
46
+FOSSIL_ENABLE_TCL_PRIVATE_STUBS = @FOSSIL_ENABLE_TCL_PRIVATE_STUBS@
47
+SQLITE_CFLAG -DSQLITE_WINNT_MAX_PATH_CHARS=4096BYTES=4096
48
+SQLITE_CFLAGS +=TE_MAX_MMAP_SIZE=0x7fff0000
49
+
50
+include $(SRCDIR)/main.mk
51
+
52
+dis
--- a/Makefile.Cygwin.in
+++ b/Makefile.Cygwin.in
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/Makefile.Cygwin.in
+++ b/Makefile.Cygwin.in
@@ -0,0 +1,52 @@
1 #!/usr/bin/make
2 #
3 # This is the top-level makefile for Fossil when the build is occurring
4 # on the Cygwin platform.
5 #
6 #### The toplevel directory of the source tree. Fossil can be built
7 # in a directory that is separate from the source tree. Just change
8 # the following to point from the build directory to the src/ folder.
9 #
10 SRCDIR = @srcdir@/src
11
12 #### The directory into which object code files should be written.
13 # Having a "./" prefix in the value of this variable breaks our use of the
14 # "makeheaders" tool when running make on the MinGW platform, apparently
15 # due to some command line argument manipulation performed automatically
16 # by the shell.
17 #
18 #
19 OBJDIR = bld
20
21 #### C Compiler and options for use in building executables that
22 # will run on the platform that is doing the build. This is used
23 # to compile code-generator programs as part of the build process.
24 # See TCC below for the C compiler for building the finished binary.
25 #
26 BCC = @CC_FOR_BUILD@
27
28 #### The suffix to add to final executable file. When cross-compiling
29 # to windows, make this ".exe". Otherwise leave it blank.
30 #
31 E = @EXEEXT@
32
33 TCC = @CC@
34
35 #### Tcl shell for use in running the fossil testsuite. If you do not
36 # care about testing the end result, this can be blank.
37 #
38 TCLSH = tclsh
39
40 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
41 TCC += @EXTRA_CFLAGS@ @CPPFLAGS@ @
42 INSTALLDIR =$(DESTDIR)@prefix@/bin
43 USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
44 FOSSIL_ENABLE_TCL = @FOSSIL_ENABLE_TCL@
45 FOSSIL_ENABLE_TCL_STUBS = @FOSSIL_ENABLE_TCL_STUBS@
46 FOSSIL_ENABLE_TCL_PRIVATE_STUBS = @FOSSIL_ENABLE_TCL_PRIVATE_STUBS@
47 SQLITE_CFLAG -DSQLITE_WINNT_MAX_PATH_CHARS=4096BYTES=4096
48 SQLITE_CFLAGS +=TE_MAX_MMAP_SIZE=0x7fff0000
49
50 include $(SRCDIR)/main.mk
51
52 dis
+1
--- auto.def
+++ auto.def
@@ -257,6 +257,7 @@
257257
cc-check-function-in-lib getpass bsd
258258
}
259259
cc-check-function-in-lib dlopen dl
260260
261261
make-template Makefile.in
262
+make-template Makefile.Cygwin.in
262263
make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
263264
--- auto.def
+++ auto.def
@@ -257,6 +257,7 @@
257 cc-check-function-in-lib getpass bsd
258 }
259 cc-check-function-in-lib dlopen dl
260
261 make-template Makefile.in
 
262 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
263
--- auto.def
+++ auto.def
@@ -257,6 +257,7 @@
257 cc-check-function-in-lib getpass bsd
258 }
259 cc-check-function-in-lib dlopen dl
260
261 make-template Makefile.in
262 make-template Makefile.Cygwin.in
263 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
264
+1 -6
--- src/add.c
+++ src/add.c
@@ -316,19 +316,14 @@
316316
**
317317
** See also: addremove, add
318318
*/
319319
void delete_cmd(void){
320320
int i;
321
- int vid;
322321
Stmt loop;
323322
324323
capture_case_sensitive_option();
325324
db_must_be_within_tree();
326
- vid = db_lget_int("checkout", 0);
327
- if( vid==0 ){
328
- fossil_fatal("no checkout to remove from");
329
- }
330325
db_begin_transaction();
331326
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
332327
filename_collation());
333328
for(i=2; i<g.argc; i++){
334329
Blob treeName;
@@ -553,11 +548,11 @@
553548
**
554549
** The original name of the file is zOrig. The new filename is zNew.
555550
*/
556551
static void mv_one_file(int vid, const char *zOrig, const char *zNew){
557552
int x = db_int(-1, "SELECT deleted FROM vfile WHERE pathname=%Q %s",
558
- zNew, filename_collation());
553
+ zNew, filename_collation());
559554
if( x>=0 ){
560555
if( x==0 ){
561556
fossil_fatal("cannot rename '%s' to '%s' since another file named '%s'"
562557
" is currently under management", zOrig, zNew, zNew);
563558
}else{
564559
--- src/add.c
+++ src/add.c
@@ -316,19 +316,14 @@
316 **
317 ** See also: addremove, add
318 */
319 void delete_cmd(void){
320 int i;
321 int vid;
322 Stmt loop;
323
324 capture_case_sensitive_option();
325 db_must_be_within_tree();
326 vid = db_lget_int("checkout", 0);
327 if( vid==0 ){
328 fossil_fatal("no checkout to remove from");
329 }
330 db_begin_transaction();
331 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
332 filename_collation());
333 for(i=2; i<g.argc; i++){
334 Blob treeName;
@@ -553,11 +548,11 @@
553 **
554 ** The original name of the file is zOrig. The new filename is zNew.
555 */
556 static void mv_one_file(int vid, const char *zOrig, const char *zNew){
557 int x = db_int(-1, "SELECT deleted FROM vfile WHERE pathname=%Q %s",
558 zNew, filename_collation());
559 if( x>=0 ){
560 if( x==0 ){
561 fossil_fatal("cannot rename '%s' to '%s' since another file named '%s'"
562 " is currently under management", zOrig, zNew, zNew);
563 }else{
564
--- src/add.c
+++ src/add.c
@@ -316,19 +316,14 @@
316 **
317 ** See also: addremove, add
318 */
319 void delete_cmd(void){
320 int i;
 
321 Stmt loop;
322
323 capture_case_sensitive_option();
324 db_must_be_within_tree();
 
 
 
 
325 db_begin_transaction();
326 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
327 filename_collation());
328 for(i=2; i<g.argc; i++){
329 Blob treeName;
@@ -553,11 +548,11 @@
548 **
549 ** The original name of the file is zOrig. The new filename is zNew.
550 */
551 static void mv_one_file(int vid, const char *zOrig, const char *zNew){
552 int x = db_int(-1, "SELECT deleted FROM vfile WHERE pathname=%Q %s",
553 zNew, filename_collation());
554 if( x>=0 ){
555 if( x==0 ){
556 fossil_fatal("cannot rename '%s' to '%s' since another file named '%s'"
557 " is currently under management", zOrig, zNew, zNew);
558 }else{
559
+16 -27
--- src/allrepo.c
+++ src/allrepo.c
@@ -141,11 +141,11 @@
141141
int useCheckouts = 0;
142142
int quiet = 0;
143143
int dryRunFlag = 0;
144144
int stopOnError = find_option("dontstop",0,0)==0;
145145
int rc;
146
- Bag outOfDate;
146
+ int nToDel = 0;
147147
148148
dryRunFlag = find_option("dry-run","n",0)!=0;
149149
if( !dryRunFlag ){
150150
dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
151151
}
@@ -243,33 +243,32 @@
243243
}
244244
verify_all_options();
245245
zFossil = quoteFilename(g.nameOfExe);
246246
if( useCheckouts ){
247247
db_prepare(&q,
248
- "SELECT substr(name, 7) COLLATE nocase, max(rowid)"
248
+ "SELECT DISTINCT substr(name, 7), name COLLATE nocase"
249249
" FROM global_config"
250250
" WHERE substr(name, 1, 6)=='ckout:'"
251
- " GROUP BY 1 ORDER BY 1"
251
+ " ORDER BY 1"
252252
);
253253
}else{
254254
db_prepare(&q,
255
- "SELECT substr(name, 6) COLLATE nocase, max(rowid)"
255
+ "SELECT DISTINCT substr(name, 6), name COLLATE nocase"
256256
" FROM global_config"
257257
" WHERE substr(name, 1, 5)=='repo:'"
258
- " GROUP BY 1 ORDER BY 1"
258
+ " ORDER BY 1"
259259
);
260260
}
261
- bag_init(&outOfDate);
261
+ db_multi_exec("CREATE TEMP TABLE todel(x TEXT)");
262262
while( db_step(&q)==SQLITE_ROW ){
263263
const char *zFilename = db_column_text(&q, 0);
264
- int rowid = db_column_int(&q, 1);
265
- if( file_access(zFilename, 0) || !file_is_canonical(zFilename) ){
266
- bag_insert(&outOfDate, rowid);
267
- continue;
268
- }
269
- if( useCheckouts && file_isdir(zFilename)!=1 ){
270
- bag_insert(&outOfDate, rowid);
264
+ if( file_access(zFilename, 0)
265
+ || !file_is_canonical(zFilename)
266
+ || (useCheckouts && file_isdir(zFilename)!=1)
267
+ ){
268
+ db_multi_exec("INSERT INTO todel VALUES(%Q)", db_column_text(&q, 1));
269
+ nToDel++;
271270
continue;
272271
}
273272
if( zCmd[0]=='l' ){
274273
fossil_print("%s\n", zFilename);
275274
continue;
@@ -291,24 +290,14 @@
291290
db_finalize(&q);
292291
293292
/* If any repositories whose names appear in the ~/.fossil file could not
294293
** be found, remove those names from the ~/.fossil file.
295294
*/
296
- if( bag_count(&outOfDate)>0 ){
297
- Blob sql;
298
- char *zSep = "(";
299
- int rowid;
300
- blob_zero(&sql);
301
- blob_appendf(&sql, "DELETE FROM global_config WHERE rowid IN ");
302
- for(rowid=bag_first(&outOfDate); rowid>0; rowid=bag_next(&outOfDate,rowid)){
303
- blob_appendf(&sql, "%s%d", zSep, rowid);
304
- zSep = ",";
305
- }
306
- blob_appendf(&sql, ")");
295
+ if( nToDel>0 ){
296
+ const char *zSql = "DELETE FROM global_config WHERE name IN toDel";
307297
if( dryRunFlag ){
308
- fossil_print("%s\n", blob_str(&sql));
298
+ fossil_print("%s\n", zSql);
309299
}else{
310
- db_multi_exec(blob_str(&sql));
300
+ db_multi_exec(zSql);
311301
}
312
- blob_reset(&sql);
313302
}
314303
}
315304
--- src/allrepo.c
+++ src/allrepo.c
@@ -141,11 +141,11 @@
141 int useCheckouts = 0;
142 int quiet = 0;
143 int dryRunFlag = 0;
144 int stopOnError = find_option("dontstop",0,0)==0;
145 int rc;
146 Bag outOfDate;
147
148 dryRunFlag = find_option("dry-run","n",0)!=0;
149 if( !dryRunFlag ){
150 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
151 }
@@ -243,33 +243,32 @@
243 }
244 verify_all_options();
245 zFossil = quoteFilename(g.nameOfExe);
246 if( useCheckouts ){
247 db_prepare(&q,
248 "SELECT substr(name, 7) COLLATE nocase, max(rowid)"
249 " FROM global_config"
250 " WHERE substr(name, 1, 6)=='ckout:'"
251 " GROUP BY 1 ORDER BY 1"
252 );
253 }else{
254 db_prepare(&q,
255 "SELECT substr(name, 6) COLLATE nocase, max(rowid)"
256 " FROM global_config"
257 " WHERE substr(name, 1, 5)=='repo:'"
258 " GROUP BY 1 ORDER BY 1"
259 );
260 }
261 bag_init(&outOfDate);
262 while( db_step(&q)==SQLITE_ROW ){
263 const char *zFilename = db_column_text(&q, 0);
264 int rowid = db_column_int(&q, 1);
265 if( file_access(zFilename, 0) || !file_is_canonical(zFilename) ){
266 bag_insert(&outOfDate, rowid);
267 continue;
268 }
269 if( useCheckouts && file_isdir(zFilename)!=1 ){
270 bag_insert(&outOfDate, rowid);
271 continue;
272 }
273 if( zCmd[0]=='l' ){
274 fossil_print("%s\n", zFilename);
275 continue;
@@ -291,24 +290,14 @@
291 db_finalize(&q);
292
293 /* If any repositories whose names appear in the ~/.fossil file could not
294 ** be found, remove those names from the ~/.fossil file.
295 */
296 if( bag_count(&outOfDate)>0 ){
297 Blob sql;
298 char *zSep = "(";
299 int rowid;
300 blob_zero(&sql);
301 blob_appendf(&sql, "DELETE FROM global_config WHERE rowid IN ");
302 for(rowid=bag_first(&outOfDate); rowid>0; rowid=bag_next(&outOfDate,rowid)){
303 blob_appendf(&sql, "%s%d", zSep, rowid);
304 zSep = ",";
305 }
306 blob_appendf(&sql, ")");
307 if( dryRunFlag ){
308 fossil_print("%s\n", blob_str(&sql));
309 }else{
310 db_multi_exec(blob_str(&sql));
311 }
312 blob_reset(&sql);
313 }
314 }
315
--- src/allrepo.c
+++ src/allrepo.c
@@ -141,11 +141,11 @@
141 int useCheckouts = 0;
142 int quiet = 0;
143 int dryRunFlag = 0;
144 int stopOnError = find_option("dontstop",0,0)==0;
145 int rc;
146 int nToDel = 0;
147
148 dryRunFlag = find_option("dry-run","n",0)!=0;
149 if( !dryRunFlag ){
150 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
151 }
@@ -243,33 +243,32 @@
243 }
244 verify_all_options();
245 zFossil = quoteFilename(g.nameOfExe);
246 if( useCheckouts ){
247 db_prepare(&q,
248 "SELECT DISTINCT substr(name, 7), name COLLATE nocase"
249 " FROM global_config"
250 " WHERE substr(name, 1, 6)=='ckout:'"
251 " ORDER BY 1"
252 );
253 }else{
254 db_prepare(&q,
255 "SELECT DISTINCT substr(name, 6), name COLLATE nocase"
256 " FROM global_config"
257 " WHERE substr(name, 1, 5)=='repo:'"
258 " ORDER BY 1"
259 );
260 }
261 db_multi_exec("CREATE TEMP TABLE todel(x TEXT)");
262 while( db_step(&q)==SQLITE_ROW ){
263 const char *zFilename = db_column_text(&q, 0);
264 if( file_access(zFilename, 0)
265 || !file_is_canonical(zFilename)
266 || (useCheckouts && file_isdir(zFilename)!=1)
267 ){
268 db_multi_exec("INSERT INTO todel VALUES(%Q)", db_column_text(&q, 1));
269 nToDel++;
 
270 continue;
271 }
272 if( zCmd[0]=='l' ){
273 fossil_print("%s\n", zFilename);
274 continue;
@@ -291,24 +290,14 @@
290 db_finalize(&q);
291
292 /* If any repositories whose names appear in the ~/.fossil file could not
293 ** be found, remove those names from the ~/.fossil file.
294 */
295 if( nToDel>0 ){
296 const char *zSql = "DELETE FROM global_config WHERE name IN toDel";
 
 
 
 
 
 
 
 
 
297 if( dryRunFlag ){
298 fossil_print("%s\n", zSql);
299 }else{
300 db_multi_exec(zSql);
301 }
 
302 }
303 }
304
--- src/configure.c
+++ src/configure.c
@@ -403,10 +403,25 @@
403403
@ DROP TABLE _xfer_user;
404404
@ DROP TABLE _xfer_reportfmt;
405405
;
406406
db_multi_exec(zSQL);
407407
}
408
+
409
+/*
410
+** Mask of modified configuration sets
411
+*/
412
+static int rebuildMask = 0;
413
+
414
+/*
415
+** Rebuild auxiliary tables as required by configuration changes.
416
+*/
417
+void configure_rebuild(void){
418
+ if( rebuildMask & CONFIGSET_TKT ){
419
+ ticket_rebuild();
420
+ }
421
+ rebuildMask = 0;
422
+}
408423
409424
/*
410425
** Return true if z[] is not a "safe" SQL token. A safe token is one of:
411426
**
412427
** * A string literal
@@ -569,10 +584,11 @@
569584
blob_appendf(&sql, " WHERE %s=%s AND mtime<%s",
570585
aType[ii].zPrimKey, azToken[1], azToken[0]);
571586
db_multi_exec("%s", blob_str(&sql));
572587
}
573588
blob_reset(&sql);
589
+ rebuildMask |= thisMask;
574590
}else{
575591
/* Otherwise, the old format */
576592
if( (configure_is_exportable(zName) & groupMask)==0 ) return;
577593
if( fossil_strcmp(zName, "logo-image")==0 ){
578594
Stmt ins;
@@ -951,11 +967,13 @@
951967
}
952968
db_end_transaction(0);
953969
fossil_print("Configuration reset to factory defaults.\n");
954970
fossil_print("To recover, use: %s %s import %s\n",
955971
g.argv[0], g.argv[1], zBackup);
972
+ rebuildMask |= mask;
956973
}else
957974
{
958975
fossil_fatal("METHOD should be one of:"
959976
" export import merge pull push reset");
960977
}
978
+ configure_rebuild();
961979
}
962980
--- src/configure.c
+++ src/configure.c
@@ -403,10 +403,25 @@
403 @ DROP TABLE _xfer_user;
404 @ DROP TABLE _xfer_reportfmt;
405 ;
406 db_multi_exec(zSQL);
407 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
409 /*
410 ** Return true if z[] is not a "safe" SQL token. A safe token is one of:
411 **
412 ** * A string literal
@@ -569,10 +584,11 @@
569 blob_appendf(&sql, " WHERE %s=%s AND mtime<%s",
570 aType[ii].zPrimKey, azToken[1], azToken[0]);
571 db_multi_exec("%s", blob_str(&sql));
572 }
573 blob_reset(&sql);
 
574 }else{
575 /* Otherwise, the old format */
576 if( (configure_is_exportable(zName) & groupMask)==0 ) return;
577 if( fossil_strcmp(zName, "logo-image")==0 ){
578 Stmt ins;
@@ -951,11 +967,13 @@
951 }
952 db_end_transaction(0);
953 fossil_print("Configuration reset to factory defaults.\n");
954 fossil_print("To recover, use: %s %s import %s\n",
955 g.argv[0], g.argv[1], zBackup);
 
956 }else
957 {
958 fossil_fatal("METHOD should be one of:"
959 " export import merge pull push reset");
960 }
 
961 }
962
--- src/configure.c
+++ src/configure.c
@@ -403,10 +403,25 @@
403 @ DROP TABLE _xfer_user;
404 @ DROP TABLE _xfer_reportfmt;
405 ;
406 db_multi_exec(zSQL);
407 }
408
409 /*
410 ** Mask of modified configuration sets
411 */
412 static int rebuildMask = 0;
413
414 /*
415 ** Rebuild auxiliary tables as required by configuration changes.
416 */
417 void configure_rebuild(void){
418 if( rebuildMask & CONFIGSET_TKT ){
419 ticket_rebuild();
420 }
421 rebuildMask = 0;
422 }
423
424 /*
425 ** Return true if z[] is not a "safe" SQL token. A safe token is one of:
426 **
427 ** * A string literal
@@ -569,10 +584,11 @@
584 blob_appendf(&sql, " WHERE %s=%s AND mtime<%s",
585 aType[ii].zPrimKey, azToken[1], azToken[0]);
586 db_multi_exec("%s", blob_str(&sql));
587 }
588 blob_reset(&sql);
589 rebuildMask |= thisMask;
590 }else{
591 /* Otherwise, the old format */
592 if( (configure_is_exportable(zName) & groupMask)==0 ) return;
593 if( fossil_strcmp(zName, "logo-image")==0 ){
594 Stmt ins;
@@ -951,11 +967,13 @@
967 }
968 db_end_transaction(0);
969 fossil_print("Configuration reset to factory defaults.\n");
970 fossil_print("To recover, use: %s %s import %s\n",
971 g.argv[0], g.argv[1], zBackup);
972 rebuildMask |= mask;
973 }else
974 {
975 fossil_fatal("METHOD should be one of:"
976 " export import merge pull push reset");
977 }
978 configure_rebuild();
979 }
980
--- src/configure.c
+++ src/configure.c
@@ -403,10 +403,25 @@
403403
@ DROP TABLE _xfer_user;
404404
@ DROP TABLE _xfer_reportfmt;
405405
;
406406
db_multi_exec(zSQL);
407407
}
408
+
409
+/*
410
+** Mask of modified configuration sets
411
+*/
412
+static int rebuildMask = 0;
413
+
414
+/*
415
+** Rebuild auxiliary tables as required by configuration changes.
416
+*/
417
+void configure_rebuild(void){
418
+ if( rebuildMask & CONFIGSET_TKT ){
419
+ ticket_rebuild();
420
+ }
421
+ rebuildMask = 0;
422
+}
408423
409424
/*
410425
** Return true if z[] is not a "safe" SQL token. A safe token is one of:
411426
**
412427
** * A string literal
@@ -569,10 +584,11 @@
569584
blob_appendf(&sql, " WHERE %s=%s AND mtime<%s",
570585
aType[ii].zPrimKey, azToken[1], azToken[0]);
571586
db_multi_exec("%s", blob_str(&sql));
572587
}
573588
blob_reset(&sql);
589
+ rebuildMask |= thisMask;
574590
}else{
575591
/* Otherwise, the old format */
576592
if( (configure_is_exportable(zName) & groupMask)==0 ) return;
577593
if( fossil_strcmp(zName, "logo-image")==0 ){
578594
Stmt ins;
@@ -951,11 +967,13 @@
951967
}
952968
db_end_transaction(0);
953969
fossil_print("Configuration reset to factory defaults.\n");
954970
fossil_print("To recover, use: %s %s import %s\n",
955971
g.argv[0], g.argv[1], zBackup);
972
+ rebuildMask |= mask;
956973
}else
957974
{
958975
fossil_fatal("METHOD should be one of:"
959976
" export import merge pull push reset");
960977
}
978
+ configure_rebuild();
961979
}
962980
--- src/configure.c
+++ src/configure.c
@@ -403,10 +403,25 @@
403 @ DROP TABLE _xfer_user;
404 @ DROP TABLE _xfer_reportfmt;
405 ;
406 db_multi_exec(zSQL);
407 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
409 /*
410 ** Return true if z[] is not a "safe" SQL token. A safe token is one of:
411 **
412 ** * A string literal
@@ -569,10 +584,11 @@
569 blob_appendf(&sql, " WHERE %s=%s AND mtime<%s",
570 aType[ii].zPrimKey, azToken[1], azToken[0]);
571 db_multi_exec("%s", blob_str(&sql));
572 }
573 blob_reset(&sql);
 
574 }else{
575 /* Otherwise, the old format */
576 if( (configure_is_exportable(zName) & groupMask)==0 ) return;
577 if( fossil_strcmp(zName, "logo-image")==0 ){
578 Stmt ins;
@@ -951,11 +967,13 @@
951 }
952 db_end_transaction(0);
953 fossil_print("Configuration reset to factory defaults.\n");
954 fossil_print("To recover, use: %s %s import %s\n",
955 g.argv[0], g.argv[1], zBackup);
 
956 }else
957 {
958 fossil_fatal("METHOD should be one of:"
959 " export import merge pull push reset");
960 }
 
961 }
962
--- src/configure.c
+++ src/configure.c
@@ -403,10 +403,25 @@
403 @ DROP TABLE _xfer_user;
404 @ DROP TABLE _xfer_reportfmt;
405 ;
406 db_multi_exec(zSQL);
407 }
408
409 /*
410 ** Mask of modified configuration sets
411 */
412 static int rebuildMask = 0;
413
414 /*
415 ** Rebuild auxiliary tables as required by configuration changes.
416 */
417 void configure_rebuild(void){
418 if( rebuildMask & CONFIGSET_TKT ){
419 ticket_rebuild();
420 }
421 rebuildMask = 0;
422 }
423
424 /*
425 ** Return true if z[] is not a "safe" SQL token. A safe token is one of:
426 **
427 ** * A string literal
@@ -569,10 +584,11 @@
584 blob_appendf(&sql, " WHERE %s=%s AND mtime<%s",
585 aType[ii].zPrimKey, azToken[1], azToken[0]);
586 db_multi_exec("%s", blob_str(&sql));
587 }
588 blob_reset(&sql);
589 rebuildMask |= thisMask;
590 }else{
591 /* Otherwise, the old format */
592 if( (configure_is_exportable(zName) & groupMask)==0 ) return;
593 if( fossil_strcmp(zName, "logo-image")==0 ){
594 Stmt ins;
@@ -951,11 +967,13 @@
967 }
968 db_end_transaction(0);
969 fossil_print("Configuration reset to factory defaults.\n");
970 fossil_print("To recover, use: %s %s import %s\n",
971 g.argv[0], g.argv[1], zBackup);
972 rebuildMask |= mask;
973 }else
974 {
975 fossil_fatal("METHOD should be one of:"
976 " export import merge pull push reset");
977 }
978 configure_rebuild();
979 }
980
+24 -33
--- src/db.c
+++ src/db.c
@@ -709,22 +709,20 @@
709709
** Open a database file. Return a pointer to the new database
710710
** connection. An error results in process abort.
711711
*/
712712
LOCAL sqlite3 *db_open(const char *zDbName){
713713
int rc;
714
- const char *zVfs;
715714
sqlite3 *db;
716715
717716
#if defined(__CYGWIN__)
718717
zDbName = fossil_utf8_to_filename(zDbName);
719718
#endif
720719
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
721
- zVfs = fossil_getenv("FOSSIL_VFS");
722720
rc = sqlite3_open_v2(
723721
zDbName, &db,
724722
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
725
- zVfs
723
+ g.zVfsName
726724
);
727725
if( rc!=SQLITE_OK ){
728726
db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
729727
}
730728
sqlite3_busy_timeout(db, 5000);
@@ -1366,11 +1364,12 @@
13661364
*/
13671365
db_multi_exec(
13681366
"INSERT OR REPLACE INTO config"
13691367
" SELECT name,value,mtime FROM settingSrc.config"
13701368
" WHERE (name IN %s OR name IN %s)"
1371
- " AND name NOT GLOB 'project-*';",
1369
+ " AND name NOT GLOB 'project-*'"
1370
+ " AND name NOT GLOB 'short-project-*';",
13721371
configure_inop_rhs(CONFIGSET_ALL),
13731372
db_setting_inop_rhs()
13741373
);
13751374
db_multi_exec(
13761375
"REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;"
@@ -1805,15 +1804,10 @@
18051804
char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
18061805
char *z = 0;
18071806
if( g.repositoryOpen ){
18081807
z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
18091808
}
1810
- if( z==0 && g.zConfigDbName ){
1811
- db_swap_connections();
1812
- z = db_text(0, "SELECT mtime FROM global_config WHERE name=%Q", zName);
1813
- db_swap_connections();
1814
- }
18151809
if( z==0 ){
18161810
z = zDefault;
18171811
}else if( zFormat!=0 ){
18181812
z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
18191813
}
@@ -2000,13 +1994,14 @@
20001994
** --nested Allow opening a repository inside an opened checkout
20011995
**
20021996
** See also: close
20031997
*/
20041998
void cmd_open(void){
2005
- int vid;
20061999
int keepFlag;
20072000
int allowNested;
2001
+ char **oldArgv;
2002
+ int oldArgc;
20082003
static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
20092004
20102005
url_proxy_options();
20112006
keepFlag = find_option("keep",0,0)!=0;
20122007
allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2024,29 @@
20292024
(char*)0);
20302025
db_delete_on_failure(LOCALDB_NAME);
20312026
db_open_local(0);
20322027
db_lset("repository", g.argv[2]);
20332028
db_record_repository_filename(g.argv[2]);
2034
- vid = db_int(0, "SELECT pid FROM plink y"
2035
- " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
2036
- if( vid==0 ){
2037
- db_lset_int("checkout", 1);
2038
- }else{
2039
- char **oldArgv = g.argv;
2040
- int oldArgc = g.argc;
2041
- db_lset_int("checkout", vid);
2042
- azNewArgv[0] = g.argv[0];
2043
- g.argv = azNewArgv;
2044
- g.argc = 3;
2045
- if( oldArgc==4 ){
2046
- azNewArgv[g.argc-1] = oldArgv[3];
2047
- }else{
2048
- azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2049
- }
2050
- if( keepFlag ){
2051
- azNewArgv[g.argc++] = "--keep";
2052
- }
2053
- checkout_cmd();
2054
- g.argc = 2;
2055
- info_cmd();
2056
- }
2029
+ db_lset_int("checkout", 0);
2030
+ oldArgv = g.argv;
2031
+ oldArgc = g.argc;
2032
+ azNewArgv[0] = g.argv[0];
2033
+ g.argv = azNewArgv;
2034
+ g.argc = 3;
2035
+ if( oldArgc==4 ){
2036
+ azNewArgv[g.argc-1] = oldArgv[3];
2037
+ }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2038
+ azNewArgv[g.argc-1] = "--latest";
2039
+ }else{
2040
+ azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2041
+ }
2042
+ if( keepFlag ){
2043
+ azNewArgv[g.argc++] = "--keep";
2044
+ }
2045
+ checkout_cmd();
2046
+ g.argc = 2;
2047
+ info_cmd();
20572048
}
20582049
20592050
/*
20602051
** Print the value of a setting named zName
20612052
*/
20622053
--- src/db.c
+++ src/db.c
@@ -709,22 +709,20 @@
709 ** Open a database file. Return a pointer to the new database
710 ** connection. An error results in process abort.
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
714 const char *zVfs;
715 sqlite3 *db;
716
717 #if defined(__CYGWIN__)
718 zDbName = fossil_utf8_to_filename(zDbName);
719 #endif
720 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
721 zVfs = fossil_getenv("FOSSIL_VFS");
722 rc = sqlite3_open_v2(
723 zDbName, &db,
724 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
725 zVfs
726 );
727 if( rc!=SQLITE_OK ){
728 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
729 }
730 sqlite3_busy_timeout(db, 5000);
@@ -1366,11 +1364,12 @@
1366 */
1367 db_multi_exec(
1368 "INSERT OR REPLACE INTO config"
1369 " SELECT name,value,mtime FROM settingSrc.config"
1370 " WHERE (name IN %s OR name IN %s)"
1371 " AND name NOT GLOB 'project-*';",
 
1372 configure_inop_rhs(CONFIGSET_ALL),
1373 db_setting_inop_rhs()
1374 );
1375 db_multi_exec(
1376 "REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;"
@@ -1805,15 +1804,10 @@
1805 char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
1806 char *z = 0;
1807 if( g.repositoryOpen ){
1808 z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
1809 }
1810 if( z==0 && g.zConfigDbName ){
1811 db_swap_connections();
1812 z = db_text(0, "SELECT mtime FROM global_config WHERE name=%Q", zName);
1813 db_swap_connections();
1814 }
1815 if( z==0 ){
1816 z = zDefault;
1817 }else if( zFormat!=0 ){
1818 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
1819 }
@@ -2000,13 +1994,14 @@
2000 ** --nested Allow opening a repository inside an opened checkout
2001 **
2002 ** See also: close
2003 */
2004 void cmd_open(void){
2005 int vid;
2006 int keepFlag;
2007 int allowNested;
 
 
2008 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2009
2010 url_proxy_options();
2011 keepFlag = find_option("keep",0,0)!=0;
2012 allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2024,29 @@
2029 (char*)0);
2030 db_delete_on_failure(LOCALDB_NAME);
2031 db_open_local(0);
2032 db_lset("repository", g.argv[2]);
2033 db_record_repository_filename(g.argv[2]);
2034 vid = db_int(0, "SELECT pid FROM plink y"
2035 " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
2036 if( vid==0 ){
2037 db_lset_int("checkout", 1);
2038 }else{
2039 char **oldArgv = g.argv;
2040 int oldArgc = g.argc;
2041 db_lset_int("checkout", vid);
2042 azNewArgv[0] = g.argv[0];
2043 g.argv = azNewArgv;
2044 g.argc = 3;
2045 if( oldArgc==4 ){
2046 azNewArgv[g.argc-1] = oldArgv[3];
2047 }else{
2048 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2049 }
2050 if( keepFlag ){
2051 azNewArgv[g.argc++] = "--keep";
2052 }
2053 checkout_cmd();
2054 g.argc = 2;
2055 info_cmd();
2056 }
2057 }
2058
2059 /*
2060 ** Print the value of a setting named zName
2061 */
2062
--- src/db.c
+++ src/db.c
@@ -709,22 +709,20 @@
709 ** Open a database file. Return a pointer to the new database
710 ** connection. An error results in process abort.
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
 
714 sqlite3 *db;
715
716 #if defined(__CYGWIN__)
717 zDbName = fossil_utf8_to_filename(zDbName);
718 #endif
719 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
 
720 rc = sqlite3_open_v2(
721 zDbName, &db,
722 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
723 g.zVfsName
724 );
725 if( rc!=SQLITE_OK ){
726 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
727 }
728 sqlite3_busy_timeout(db, 5000);
@@ -1366,11 +1364,12 @@
1364 */
1365 db_multi_exec(
1366 "INSERT OR REPLACE INTO config"
1367 " SELECT name,value,mtime FROM settingSrc.config"
1368 " WHERE (name IN %s OR name IN %s)"
1369 " AND name NOT GLOB 'project-*'"
1370 " AND name NOT GLOB 'short-project-*';",
1371 configure_inop_rhs(CONFIGSET_ALL),
1372 db_setting_inop_rhs()
1373 );
1374 db_multi_exec(
1375 "REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;"
@@ -1805,15 +1804,10 @@
1804 char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
1805 char *z = 0;
1806 if( g.repositoryOpen ){
1807 z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
1808 }
 
 
 
 
 
1809 if( z==0 ){
1810 z = zDefault;
1811 }else if( zFormat!=0 ){
1812 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
1813 }
@@ -2000,13 +1994,14 @@
1994 ** --nested Allow opening a repository inside an opened checkout
1995 **
1996 ** See also: close
1997 */
1998 void cmd_open(void){
 
1999 int keepFlag;
2000 int allowNested;
2001 char **oldArgv;
2002 int oldArgc;
2003 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2004
2005 url_proxy_options();
2006 keepFlag = find_option("keep",0,0)!=0;
2007 allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2024,29 @@
2024 (char*)0);
2025 db_delete_on_failure(LOCALDB_NAME);
2026 db_open_local(0);
2027 db_lset("repository", g.argv[2]);
2028 db_record_repository_filename(g.argv[2]);
2029 db_lset_int("checkout", 0);
2030 oldArgv = g.argv;
2031 oldArgc = g.argc;
2032 azNewArgv[0] = g.argv[0];
2033 g.argv = azNewArgv;
2034 g.argc = 3;
2035 if( oldArgc==4 ){
2036 azNewArgv[g.argc-1] = oldArgv[3];
2037 }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2038 azNewArgv[g.argc-1] = "--latest";
2039 }else{
2040 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2041 }
2042 if( keepFlag ){
2043 azNewArgv[g.argc++] = "--keep";
2044 }
2045 checkout_cmd();
2046 g.argc = 2;
2047 info_cmd();
 
 
 
 
2048 }
2049
2050 /*
2051 ** Print the value of a setting named zName
2052 */
2053
+24 -33
--- src/db.c
+++ src/db.c
@@ -709,22 +709,20 @@
709709
** Open a database file. Return a pointer to the new database
710710
** connection. An error results in process abort.
711711
*/
712712
LOCAL sqlite3 *db_open(const char *zDbName){
713713
int rc;
714
- const char *zVfs;
715714
sqlite3 *db;
716715
717716
#if defined(__CYGWIN__)
718717
zDbName = fossil_utf8_to_filename(zDbName);
719718
#endif
720719
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
721
- zVfs = fossil_getenv("FOSSIL_VFS");
722720
rc = sqlite3_open_v2(
723721
zDbName, &db,
724722
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
725
- zVfs
723
+ g.zVfsName
726724
);
727725
if( rc!=SQLITE_OK ){
728726
db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
729727
}
730728
sqlite3_busy_timeout(db, 5000);
@@ -1366,11 +1364,12 @@
13661364
*/
13671365
db_multi_exec(
13681366
"INSERT OR REPLACE INTO config"
13691367
" SELECT name,value,mtime FROM settingSrc.config"
13701368
" WHERE (name IN %s OR name IN %s)"
1371
- " AND name NOT GLOB 'project-*';",
1369
+ " AND name NOT GLOB 'project-*'"
1370
+ " AND name NOT GLOB 'short-project-*';",
13721371
configure_inop_rhs(CONFIGSET_ALL),
13731372
db_setting_inop_rhs()
13741373
);
13751374
db_multi_exec(
13761375
"REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;"
@@ -1805,15 +1804,10 @@
18051804
char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
18061805
char *z = 0;
18071806
if( g.repositoryOpen ){
18081807
z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
18091808
}
1810
- if( z==0 && g.zConfigDbName ){
1811
- db_swap_connections();
1812
- z = db_text(0, "SELECT mtime FROM global_config WHERE name=%Q", zName);
1813
- db_swap_connections();
1814
- }
18151809
if( z==0 ){
18161810
z = zDefault;
18171811
}else if( zFormat!=0 ){
18181812
z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
18191813
}
@@ -2000,13 +1994,14 @@
20001994
** --nested Allow opening a repository inside an opened checkout
20011995
**
20021996
** See also: close
20031997
*/
20041998
void cmd_open(void){
2005
- int vid;
20061999
int keepFlag;
20072000
int allowNested;
2001
+ char **oldArgv;
2002
+ int oldArgc;
20082003
static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
20092004
20102005
url_proxy_options();
20112006
keepFlag = find_option("keep",0,0)!=0;
20122007
allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2024,29 @@
20292024
(char*)0);
20302025
db_delete_on_failure(LOCALDB_NAME);
20312026
db_open_local(0);
20322027
db_lset("repository", g.argv[2]);
20332028
db_record_repository_filename(g.argv[2]);
2034
- vid = db_int(0, "SELECT pid FROM plink y"
2035
- " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
2036
- if( vid==0 ){
2037
- db_lset_int("checkout", 1);
2038
- }else{
2039
- char **oldArgv = g.argv;
2040
- int oldArgc = g.argc;
2041
- db_lset_int("checkout", vid);
2042
- azNewArgv[0] = g.argv[0];
2043
- g.argv = azNewArgv;
2044
- g.argc = 3;
2045
- if( oldArgc==4 ){
2046
- azNewArgv[g.argc-1] = oldArgv[3];
2047
- }else{
2048
- azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2049
- }
2050
- if( keepFlag ){
2051
- azNewArgv[g.argc++] = "--keep";
2052
- }
2053
- checkout_cmd();
2054
- g.argc = 2;
2055
- info_cmd();
2056
- }
2029
+ db_lset_int("checkout", 0);
2030
+ oldArgv = g.argv;
2031
+ oldArgc = g.argc;
2032
+ azNewArgv[0] = g.argv[0];
2033
+ g.argv = azNewArgv;
2034
+ g.argc = 3;
2035
+ if( oldArgc==4 ){
2036
+ azNewArgv[g.argc-1] = oldArgv[3];
2037
+ }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2038
+ azNewArgv[g.argc-1] = "--latest";
2039
+ }else{
2040
+ azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2041
+ }
2042
+ if( keepFlag ){
2043
+ azNewArgv[g.argc++] = "--keep";
2044
+ }
2045
+ checkout_cmd();
2046
+ g.argc = 2;
2047
+ info_cmd();
20572048
}
20582049
20592050
/*
20602051
** Print the value of a setting named zName
20612052
*/
20622053
--- src/db.c
+++ src/db.c
@@ -709,22 +709,20 @@
709 ** Open a database file. Return a pointer to the new database
710 ** connection. An error results in process abort.
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
714 const char *zVfs;
715 sqlite3 *db;
716
717 #if defined(__CYGWIN__)
718 zDbName = fossil_utf8_to_filename(zDbName);
719 #endif
720 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
721 zVfs = fossil_getenv("FOSSIL_VFS");
722 rc = sqlite3_open_v2(
723 zDbName, &db,
724 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
725 zVfs
726 );
727 if( rc!=SQLITE_OK ){
728 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
729 }
730 sqlite3_busy_timeout(db, 5000);
@@ -1366,11 +1364,12 @@
1366 */
1367 db_multi_exec(
1368 "INSERT OR REPLACE INTO config"
1369 " SELECT name,value,mtime FROM settingSrc.config"
1370 " WHERE (name IN %s OR name IN %s)"
1371 " AND name NOT GLOB 'project-*';",
 
1372 configure_inop_rhs(CONFIGSET_ALL),
1373 db_setting_inop_rhs()
1374 );
1375 db_multi_exec(
1376 "REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;"
@@ -1805,15 +1804,10 @@
1805 char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
1806 char *z = 0;
1807 if( g.repositoryOpen ){
1808 z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
1809 }
1810 if( z==0 && g.zConfigDbName ){
1811 db_swap_connections();
1812 z = db_text(0, "SELECT mtime FROM global_config WHERE name=%Q", zName);
1813 db_swap_connections();
1814 }
1815 if( z==0 ){
1816 z = zDefault;
1817 }else if( zFormat!=0 ){
1818 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
1819 }
@@ -2000,13 +1994,14 @@
2000 ** --nested Allow opening a repository inside an opened checkout
2001 **
2002 ** See also: close
2003 */
2004 void cmd_open(void){
2005 int vid;
2006 int keepFlag;
2007 int allowNested;
 
 
2008 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2009
2010 url_proxy_options();
2011 keepFlag = find_option("keep",0,0)!=0;
2012 allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2024,29 @@
2029 (char*)0);
2030 db_delete_on_failure(LOCALDB_NAME);
2031 db_open_local(0);
2032 db_lset("repository", g.argv[2]);
2033 db_record_repository_filename(g.argv[2]);
2034 vid = db_int(0, "SELECT pid FROM plink y"
2035 " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
2036 if( vid==0 ){
2037 db_lset_int("checkout", 1);
2038 }else{
2039 char **oldArgv = g.argv;
2040 int oldArgc = g.argc;
2041 db_lset_int("checkout", vid);
2042 azNewArgv[0] = g.argv[0];
2043 g.argv = azNewArgv;
2044 g.argc = 3;
2045 if( oldArgc==4 ){
2046 azNewArgv[g.argc-1] = oldArgv[3];
2047 }else{
2048 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2049 }
2050 if( keepFlag ){
2051 azNewArgv[g.argc++] = "--keep";
2052 }
2053 checkout_cmd();
2054 g.argc = 2;
2055 info_cmd();
2056 }
2057 }
2058
2059 /*
2060 ** Print the value of a setting named zName
2061 */
2062
--- src/db.c
+++ src/db.c
@@ -709,22 +709,20 @@
709 ** Open a database file. Return a pointer to the new database
710 ** connection. An error results in process abort.
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
 
714 sqlite3 *db;
715
716 #if defined(__CYGWIN__)
717 zDbName = fossil_utf8_to_filename(zDbName);
718 #endif
719 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
 
720 rc = sqlite3_open_v2(
721 zDbName, &db,
722 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
723 g.zVfsName
724 );
725 if( rc!=SQLITE_OK ){
726 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
727 }
728 sqlite3_busy_timeout(db, 5000);
@@ -1366,11 +1364,12 @@
1364 */
1365 db_multi_exec(
1366 "INSERT OR REPLACE INTO config"
1367 " SELECT name,value,mtime FROM settingSrc.config"
1368 " WHERE (name IN %s OR name IN %s)"
1369 " AND name NOT GLOB 'project-*'"
1370 " AND name NOT GLOB 'short-project-*';",
1371 configure_inop_rhs(CONFIGSET_ALL),
1372 db_setting_inop_rhs()
1373 );
1374 db_multi_exec(
1375 "REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;"
@@ -1805,15 +1804,10 @@
1804 char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
1805 char *z = 0;
1806 if( g.repositoryOpen ){
1807 z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
1808 }
 
 
 
 
 
1809 if( z==0 ){
1810 z = zDefault;
1811 }else if( zFormat!=0 ){
1812 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
1813 }
@@ -2000,13 +1994,14 @@
1994 ** --nested Allow opening a repository inside an opened checkout
1995 **
1996 ** See also: close
1997 */
1998 void cmd_open(void){
 
1999 int keepFlag;
2000 int allowNested;
2001 char **oldArgv;
2002 int oldArgc;
2003 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2004
2005 url_proxy_options();
2006 keepFlag = find_option("keep",0,0)!=0;
2007 allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2024,29 @@
2024 (char*)0);
2025 db_delete_on_failure(LOCALDB_NAME);
2026 db_open_local(0);
2027 db_lset("repository", g.argv[2]);
2028 db_record_repository_filename(g.argv[2]);
2029 db_lset_int("checkout", 0);
2030 oldArgv = g.argv;
2031 oldArgc = g.argc;
2032 azNewArgv[0] = g.argv[0];
2033 g.argv = azNewArgv;
2034 g.argc = 3;
2035 if( oldArgc==4 ){
2036 azNewArgv[g.argc-1] = oldArgv[3];
2037 }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2038 azNewArgv[g.argc-1] = "--latest";
2039 }else{
2040 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2041 }
2042 if( keepFlag ){
2043 azNewArgv[g.argc++] = "--keep";
2044 }
2045 checkout_cmd();
2046 g.argc = 2;
2047 info_cmd();
 
 
 
 
2048 }
2049
2050 /*
2051 ** Print the value of a setting named zName
2052 */
2053
+26 -9
--- src/diff.c
+++ src/diff.c
@@ -2123,10 +2123,11 @@
21232123
return c;
21242124
}
21252125
21262126
/*
21272127
** WEBPAGE: annotate
2128
+** WEBPAGE: blame
21282129
**
21292130
** Query parameters:
21302131
**
21312132
** checkin=ID The manifest ID at which to start the annotation
21322133
** filename=FILENAME The filename.
@@ -2145,10 +2146,11 @@
21452146
const char *zCI; /* The check-in containing zFilename */
21462147
Annotator ann;
21472148
HQuery url;
21482149
struct AnnVers *p;
21492150
unsigned clr1, clr2, clr;
2151
+ int bBlame = g.zPath[0]=='b';/* True for BLAME output. False for ANNOTATE. */
21502152
21512153
/* Gather query parameters */
21522154
showLog = atoi(PD("log","1"));
21532155
login_check_credentials();
21542156
if( !g.perm.Read ){ login_needed(); return; }
@@ -2251,20 +2253,35 @@
22512253
char *z = (char*)ann.aOrig[i].z;
22522254
int n = ann.aOrig[i].n;
22532255
char zPrefix[300];
22542256
z[n] = 0;
22552257
if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2256
- if( iVers>=0 ){
2257
- struct AnnVers *p = ann.aVers+iVers;
2258
- char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2259
- sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2260
- "<span style='background-color:%s'>"
2261
- "%s%.10s</a> %s</span> %4d:",
2262
- p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2263
- fossil_free(zLink);
2258
+
2259
+ if( bBlame ){
2260
+ if( iVers>=0 ){
2261
+ struct AnnVers *p = ann.aVers+iVers;
2262
+ char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2263
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2264
+ "<span style='background-color:%s'>"
2265
+ "%s%.10s</a> %s</span> %13.13s:",
2266
+ p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2267
+ fossil_free(zLink);
2268
+ }else{
2269
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2270
+ }
22642271
}else{
2265
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2272
+ if( iVers>=0 ){
2273
+ struct AnnVers *p = ann.aVers+iVers;
2274
+ char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2275
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2276
+ "<span style='background-color:%s'>"
2277
+ "%s%.10s</a> %s</span> %4d:",
2278
+ p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2279
+ fossil_free(zLink);
2280
+ }else{
2281
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2282
+ }
22662283
}
22672284
@ %s(zPrefix) %h(z)
22682285
22692286
}
22702287
@ </pre>
22712288
--- src/diff.c
+++ src/diff.c
@@ -2123,10 +2123,11 @@
2123 return c;
2124 }
2125
2126 /*
2127 ** WEBPAGE: annotate
 
2128 **
2129 ** Query parameters:
2130 **
2131 ** checkin=ID The manifest ID at which to start the annotation
2132 ** filename=FILENAME The filename.
@@ -2145,10 +2146,11 @@
2145 const char *zCI; /* The check-in containing zFilename */
2146 Annotator ann;
2147 HQuery url;
2148 struct AnnVers *p;
2149 unsigned clr1, clr2, clr;
 
2150
2151 /* Gather query parameters */
2152 showLog = atoi(PD("log","1"));
2153 login_check_credentials();
2154 if( !g.perm.Read ){ login_needed(); return; }
@@ -2251,20 +2253,35 @@
2251 char *z = (char*)ann.aOrig[i].z;
2252 int n = ann.aOrig[i].n;
2253 char zPrefix[300];
2254 z[n] = 0;
2255 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2256 if( iVers>=0 ){
2257 struct AnnVers *p = ann.aVers+iVers;
2258 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2259 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2260 "<span style='background-color:%s'>"
2261 "%s%.10s</a> %s</span> %4d:",
2262 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2263 fossil_free(zLink);
 
 
 
 
 
2264 }else{
2265 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
 
 
 
 
 
 
 
 
 
 
2266 }
2267 @ %s(zPrefix) %h(z)
2268
2269 }
2270 @ </pre>
2271
--- src/diff.c
+++ src/diff.c
@@ -2123,10 +2123,11 @@
2123 return c;
2124 }
2125
2126 /*
2127 ** WEBPAGE: annotate
2128 ** WEBPAGE: blame
2129 **
2130 ** Query parameters:
2131 **
2132 ** checkin=ID The manifest ID at which to start the annotation
2133 ** filename=FILENAME The filename.
@@ -2145,10 +2146,11 @@
2146 const char *zCI; /* The check-in containing zFilename */
2147 Annotator ann;
2148 HQuery url;
2149 struct AnnVers *p;
2150 unsigned clr1, clr2, clr;
2151 int bBlame = g.zPath[0]=='b';/* True for BLAME output. False for ANNOTATE. */
2152
2153 /* Gather query parameters */
2154 showLog = atoi(PD("log","1"));
2155 login_check_credentials();
2156 if( !g.perm.Read ){ login_needed(); return; }
@@ -2251,20 +2253,35 @@
2253 char *z = (char*)ann.aOrig[i].z;
2254 int n = ann.aOrig[i].n;
2255 char zPrefix[300];
2256 z[n] = 0;
2257 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2258
2259 if( bBlame ){
2260 if( iVers>=0 ){
2261 struct AnnVers *p = ann.aVers+iVers;
2262 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2263 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2264 "<span style='background-color:%s'>"
2265 "%s%.10s</a> %s</span> %13.13s:",
2266 p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2267 fossil_free(zLink);
2268 }else{
2269 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2270 }
2271 }else{
2272 if( iVers>=0 ){
2273 struct AnnVers *p = ann.aVers+iVers;
2274 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2275 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2276 "<span style='background-color:%s'>"
2277 "%s%.10s</a> %s</span> %4d:",
2278 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2279 fossil_free(zLink);
2280 }else{
2281 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2282 }
2283 }
2284 @ %s(zPrefix) %h(z)
2285
2286 }
2287 @ </pre>
2288
+20 -4
--- src/file.c
+++ src/file.c
@@ -47,11 +47,16 @@
4747
** Use _stati64 rather than stat on windows, in order to handle files
4848
** larger than 2GB.
4949
*/
5050
#if defined(_WIN32) && (defined(__MSVCRT__) || defined(_MSC_VER))
5151
# undef stat
52
-# define stat _stati64
52
+# define stat _fossil_stati64
53
+struct stat {
54
+ i64 st_size;
55
+ i64 st_mtime;
56
+ int st_mode;
57
+};
5358
#endif
5459
/*
5560
** On Windows S_ISLNK always returns FALSE.
5661
*/
5762
#if !defined(S_ISLNK)
@@ -73,12 +78,22 @@
7378
rc = lstat(zMbcs, buf);
7479
}else{
7580
rc = stat(zMbcs, buf);
7681
}
7782
#else
83
+ WIN32_FILE_ATTRIBUTE_DATA attr;
7884
wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
79
- rc = _wstati64(zMbcs, buf);
85
+ rc = !GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &attr);
86
+ if( !rc ){
87
+ ULARGE_INTEGER ull;
88
+ ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
89
+ ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
90
+ buf->st_mode = (attr.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)?
91
+ S_IFDIR:S_IFREG;
92
+ buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow;
93
+ buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL;
94
+ }
8095
#endif
8196
fossil_filename_free(zMbcs);
8297
return rc;
8398
}
8499
@@ -321,11 +336,11 @@
321336
** (UNIX only)
322337
*/
323338
int file_chdir(const char *zChDir, int bChroot){
324339
#ifdef _WIN32
325340
wchar_t *zPath = fossil_utf8_to_filename(zChDir);
326
- int rc = _wchdir(zPath);
341
+ int rc = SetCurrentDirectoryW(zPath)==0;
327342
#else
328343
char *zPath = fossil_utf8_to_filename(zChDir);
329344
int rc = chdir(zPath);
330345
if( !rc && bChroot ){
331346
rc = chroot(zPath);
@@ -420,15 +435,16 @@
420435
/*
421436
** Set the mtime for a file.
422437
*/
423438
void file_set_mtime(const char *zFilename, i64 newMTime){
424439
#if !defined(_WIN32)
440
+ char *zMbcs;
425441
struct timeval tv[2];
426442
memset(tv, 0, sizeof(tv[0])*2);
427443
tv[0].tv_sec = newMTime;
428444
tv[1].tv_sec = newMTime;
429
- char *zMbcs = fossil_utf8_to_filename(zFilename);
445
+ zMbcs = fossil_utf8_to_filename(zFilename);
430446
utimes(zMbcs, tv);
431447
#else
432448
struct _utimbuf tb;
433449
wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
434450
tb.actime = newMTime;
435451
--- src/file.c
+++ src/file.c
@@ -47,11 +47,16 @@
47 ** Use _stati64 rather than stat on windows, in order to handle files
48 ** larger than 2GB.
49 */
50 #if defined(_WIN32) && (defined(__MSVCRT__) || defined(_MSC_VER))
51 # undef stat
52 # define stat _stati64
 
 
 
 
 
53 #endif
54 /*
55 ** On Windows S_ISLNK always returns FALSE.
56 */
57 #if !defined(S_ISLNK)
@@ -73,12 +78,22 @@
73 rc = lstat(zMbcs, buf);
74 }else{
75 rc = stat(zMbcs, buf);
76 }
77 #else
 
78 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
79 rc = _wstati64(zMbcs, buf);
 
 
 
 
 
 
 
 
 
80 #endif
81 fossil_filename_free(zMbcs);
82 return rc;
83 }
84
@@ -321,11 +336,11 @@
321 ** (UNIX only)
322 */
323 int file_chdir(const char *zChDir, int bChroot){
324 #ifdef _WIN32
325 wchar_t *zPath = fossil_utf8_to_filename(zChDir);
326 int rc = _wchdir(zPath);
327 #else
328 char *zPath = fossil_utf8_to_filename(zChDir);
329 int rc = chdir(zPath);
330 if( !rc && bChroot ){
331 rc = chroot(zPath);
@@ -420,15 +435,16 @@
420 /*
421 ** Set the mtime for a file.
422 */
423 void file_set_mtime(const char *zFilename, i64 newMTime){
424 #if !defined(_WIN32)
 
425 struct timeval tv[2];
426 memset(tv, 0, sizeof(tv[0])*2);
427 tv[0].tv_sec = newMTime;
428 tv[1].tv_sec = newMTime;
429 char *zMbcs = fossil_utf8_to_filename(zFilename);
430 utimes(zMbcs, tv);
431 #else
432 struct _utimbuf tb;
433 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
434 tb.actime = newMTime;
435
--- src/file.c
+++ src/file.c
@@ -47,11 +47,16 @@
47 ** Use _stati64 rather than stat on windows, in order to handle files
48 ** larger than 2GB.
49 */
50 #if defined(_WIN32) && (defined(__MSVCRT__) || defined(_MSC_VER))
51 # undef stat
52 # define stat _fossil_stati64
53 struct stat {
54 i64 st_size;
55 i64 st_mtime;
56 int st_mode;
57 };
58 #endif
59 /*
60 ** On Windows S_ISLNK always returns FALSE.
61 */
62 #if !defined(S_ISLNK)
@@ -73,12 +78,22 @@
78 rc = lstat(zMbcs, buf);
79 }else{
80 rc = stat(zMbcs, buf);
81 }
82 #else
83 WIN32_FILE_ATTRIBUTE_DATA attr;
84 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
85 rc = !GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &attr);
86 if( !rc ){
87 ULARGE_INTEGER ull;
88 ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
89 ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
90 buf->st_mode = (attr.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)?
91 S_IFDIR:S_IFREG;
92 buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow;
93 buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL;
94 }
95 #endif
96 fossil_filename_free(zMbcs);
97 return rc;
98 }
99
@@ -321,11 +336,11 @@
336 ** (UNIX only)
337 */
338 int file_chdir(const char *zChDir, int bChroot){
339 #ifdef _WIN32
340 wchar_t *zPath = fossil_utf8_to_filename(zChDir);
341 int rc = SetCurrentDirectoryW(zPath)==0;
342 #else
343 char *zPath = fossil_utf8_to_filename(zChDir);
344 int rc = chdir(zPath);
345 if( !rc && bChroot ){
346 rc = chroot(zPath);
@@ -420,15 +435,16 @@
435 /*
436 ** Set the mtime for a file.
437 */
438 void file_set_mtime(const char *zFilename, i64 newMTime){
439 #if !defined(_WIN32)
440 char *zMbcs;
441 struct timeval tv[2];
442 memset(tv, 0, sizeof(tv[0])*2);
443 tv[0].tv_sec = newMTime;
444 tv[1].tv_sec = newMTime;
445 zMbcs = fossil_utf8_to_filename(zFilename);
446 utimes(zMbcs, tv);
447 #else
448 struct _utimbuf tb;
449 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
450 tb.actime = newMTime;
451
+5 -3
--- src/finfo.c
+++ src/finfo.c
@@ -463,16 +463,18 @@
463463
@ %w(zCom) (user:
464464
hyperlink_to_user(zUser, zDate, "");
465465
@ branch: %h(zBr))
466466
if( g.perm.Hyperlink && zUuid ){
467467
const char *z = zFilename;
468
+ @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
469
+ @ [annotate]</a>
470
+ @ %z(href("%R/blame?checkin=%S&filename=%h",zCkin,z))
471
+ @ [blame]</a>
472
+ @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
468473
if( fpid ){
469474
@ %z(href("%R/fdiff?v1=%S&v2=%S&sbs=1",zPUuid,zUuid))[diff]</a>
470475
}
471
- @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
472
- @ [annotate]</a>
473
- @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
474476
}
475477
if( fDebug & FINFO_DEBUG_MLINK ){
476478
int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
477479
int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
478480
@ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
479481
--- src/finfo.c
+++ src/finfo.c
@@ -463,16 +463,18 @@
463 @ %w(zCom) (user:
464 hyperlink_to_user(zUser, zDate, "");
465 @ branch: %h(zBr))
466 if( g.perm.Hyperlink && zUuid ){
467 const char *z = zFilename;
 
 
 
 
 
468 if( fpid ){
469 @ %z(href("%R/fdiff?v1=%S&v2=%S&sbs=1",zPUuid,zUuid))[diff]</a>
470 }
471 @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
472 @ [annotate]</a>
473 @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
474 }
475 if( fDebug & FINFO_DEBUG_MLINK ){
476 int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
477 int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
478 @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
479
--- src/finfo.c
+++ src/finfo.c
@@ -463,16 +463,18 @@
463 @ %w(zCom) (user:
464 hyperlink_to_user(zUser, zDate, "");
465 @ branch: %h(zBr))
466 if( g.perm.Hyperlink && zUuid ){
467 const char *z = zFilename;
468 @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
469 @ [annotate]</a>
470 @ %z(href("%R/blame?checkin=%S&filename=%h",zCkin,z))
471 @ [blame]</a>
472 @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
473 if( fpid ){
474 @ %z(href("%R/fdiff?v1=%S&v2=%S&sbs=1",zPUuid,zUuid))[diff]</a>
475 }
 
 
 
476 }
477 if( fDebug & FINFO_DEBUG_MLINK ){
478 int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
479 int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
480 @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
481
+64 -24
--- src/info.c
+++ src/info.c
@@ -965,10 +965,15 @@
965965
}
966966
verboseFlag = (zVerbose!=0) && !is_false(zVerbose);
967967
if( !verboseFlag && sideBySide ) verboseFlag = 1;
968968
zFrom = P("from");
969969
zTo = P("to");
970
+ if( sideBySide || verboseFlag ){
971
+ style_submenu_element("Hide Diff", "hidediff",
972
+ "%R/vdiff?from=%T&to=%T&sbs=0",
973
+ zFrom, zTo);
974
+ }
970975
if( !sideBySide ){
971976
style_submenu_element("Side-by-side Diff", "sbsdiff",
972977
"%R/vdiff?from=%T&to=%T&sbs=1",
973978
zFrom, zTo);
974979
}
@@ -1128,13 +1133,15 @@
11281133
@ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
11291134
}
11301135
@ - %!w(zCom) (user:
11311136
hyperlink_to_user(zUser,zDate,")");
11321137
if( g.perm.Hyperlink ){
1138
+ @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
11331139
@ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
11341140
@ [annotate]</a>
1135
- @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1141
+ @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142
+ @ [blame]</a>
11361143
}
11371144
cnt++;
11381145
if( pDownloadName && blob_size(pDownloadName)==0 ){
11391146
blob_append(pDownloadName, zName, -1);
11401147
}
@@ -1310,11 +1317,11 @@
13101317
text_diff(&c1, &c2, pOut, pRe, diffFlags);
13111318
blob_reset(&c1);
13121319
blob_reset(&c2);
13131320
return;
13141321
}
1315
-
1322
+
13161323
sideBySide = !is_false(PD("sbs","1"));
13171324
zV1 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v1);
13181325
zV2 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v2);
13191326
diffFlags = construct_diff_flags(1, sideBySide) | DIFF_HTML;
13201327
@@ -1660,12 +1667,12 @@
16601667
content_get(rid, &content);
16611668
if( renderAsWiki ){
16621669
wiki_convert(&content, 0, 0);
16631670
}else if( renderAsHtml ){
16641671
@ <iframe src="%R/raw/%T(blob_str(&downloadName))?name=%s(zUuid)"
1665
- @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1666
- @ sandbox="allow-same-origin"
1672
+ @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1673
+ @ sandbox="allow-same-origin"
16671674
@ onload="this.height = this.contentDocument.documentElement.scrollHeight;">
16681675
@ </iframe>
16691676
}else{
16701677
style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
16711678
zMime = mimetype_from_content(&content);
@@ -2046,13 +2053,15 @@
20462053
const char *zNewBrFlag;
20472054
const char *zNewBranch;
20482055
const char *zCloseFlag;
20492056
int fPropagateColor; /* True if color propagates before edit */
20502057
int fNewPropagateColor; /* True if color propagates after edit */
2058
+ int fHasClosed = 0; /* True if closed tag already set */
20512059
const char *zChngTime = 0; /* Value of chngtime= query param, if any */
20522060
char *zUuid;
20532061
Blob comment;
2062
+ char *zBranchName = "";
20542063
Stmt q;
20552064
20562065
login_check_credentials();
20572066
if( !g.perm.Write ){ login_needed(); return; }
20582067
rid = name_to_typed_rid(P("r"), "ci");
@@ -2137,11 +2146,12 @@
21372146
db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
21382147
}
21392148
}
21402149
db_finalize(&q);
21412150
if( zCloseFlag[0] ){
2142
- db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)");
2151
+ db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2152
+ is_a_leaf(rid)?"+":"*");
21432153
}
21442154
if( zNewTagFlag[0] && zNewTag[0] ){
21452155
db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
21462156
}
21472157
if( zNewBrFlag[0] && zNewBranch[0] ){
@@ -2188,10 +2198,21 @@
21882198
}
21892199
blob_zero(&comment);
21902200
blob_append(&comment, zNewComment, -1);
21912201
zUuid[10] = 0;
21922202
style_header("Edit Check-in [%s]", zUuid);
2203
+ /*
2204
+ ** chgbn: Handle change of branch name in remaining of form.
2205
+ */
2206
+ @ <script>
2207
+ @ function chgbn(val, branch){
2208
+ @ if (!val) val=branch;
2209
+ @ gebi('newbr').checked=(val!=branch);
2210
+ @ cidbrid = document.getElementById('cbranch');
2211
+ @ if( cidbrid ) cidbrid.textContent = val;
2212
+ @ }
2213
+ @ </script>
21932214
if( P("preview") ){
21942215
Blob suffix;
21952216
int nTag = 0;
21962217
@ <b>Preview:</b>
21972218
@ <blockquote>
@@ -2268,31 +2289,44 @@
22682289
@ <label><input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
22692290
@ Add the following new tag name to this check-in:</label>
22702291
@ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
22712292
@ onkeyup="gebi('newtag').checked=!!this.value" />
22722293
db_prepare(&q,
2273
- "SELECT tag.tagid, tagname FROM tagxref, tag"
2294
+ "SELECT tag.tagid, tagname, tagxref.value FROM tagxref, tag"
22742295
" WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
22752296
" ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
22762297
" ELSE tagname END /*sort*/",
22772298
rid
22782299
);
22792300
while( db_step(&q)==SQLITE_ROW ){
22802301
int tagid = db_column_int(&q, 0);
22812302
const char *zTagName = db_column_text(&q, 1);
2303
+ int isSpecialTag = strncmp(zTagName, "sym-", 4)!=0;
22822304
char zLabel[30];
2305
+
2306
+ if (tagid == TAG_CLOSED){
2307
+ fHasClosed = 1;
2308
+ }else if (tagid == TAG_COMMENT){
2309
+ continue;
2310
+ }else if (tagid == TAG_BRANCH){
2311
+ zBranchName = mprintf("%s", db_column_text(&q, 2));
2312
+ continue;
2313
+ }else if( !isSpecialTag && zBranchName &&
2314
+ strcmp(&zTagName[4], zBranchName)==0){
2315
+ continue;
2316
+ }
22832317
sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
22842318
@ <br /><label>
22852319
if( P(zLabel) ){
22862320
@ <input type="checkbox" name="c%d(tagid)" checked="checked" />
22872321
}else{
22882322
@ <input type="checkbox" name="c%d(tagid)" />
22892323
}
2290
- if( strncmp(zTagName, "sym-", 4)==0 ){
2291
- @ Cancel tag <b>%h(&zTagName[4])</b></label>
2324
+ if( isSpecialTag ){
2325
+ @ Cancel special tag <b>%h(zTagName)</b></label>
22922326
}else{
2293
- @ Cancel special tag <b>%h(zTagName)</b></label>
2327
+ @ Cancel tag <b>%h(&zTagName[4])</b></label>
22942328
}
22952329
}
22962330
db_finalize(&q);
22972331
@ </td></tr>
22982332
@@ -2299,25 +2333,31 @@
22992333
@ <tr><th align="right" valign="top">Branching:</th>
23002334
@ <td valign="top">
23012335
@ <label><input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
23022336
@ Make this check-in the start of a new branch named:</label>
23032337
@ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2304
- @ onkeyup="gebi('newbr').checked=!!this.value" />
2305
- @ </td></tr>
2306
-
2307
- if( is_a_leaf(rid)
2308
- && !db_exists("SELECT 1 FROM tagxref "
2309
- " WHERE tagid=%d AND rid=%d AND tagtype>0",
2310
- TAG_CLOSED, rid)
2311
- ){
2312
- @ <tr><th align="right" valign="top">Leaf Closure:</th>
2313
- @ <td valign="top">
2314
- @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2315
- @ Mark this leaf as "closed" so that it no longer appears on the
2316
- @ "leaves" page and is no longer labeled as a "<b>Leaf</b>".</label>
2317
- @ </td></tr>
2318
- }
2338
+ @ onkeyup="chgbn(this.value,'%h(zBranchName)')" /></td></tr>
2339
+ if( !fHasClosed ){
2340
+ if( is_a_leaf(rid) ){
2341
+ @ <tr><th align="right" valign="top">Leaf Closure:</th>
2342
+ @ <td valign="top">
2343
+ @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2344
+ @ Mark this leaf as "closed" so that it no longer appears on the
2345
+ @ "leaves" page and is no longer labeled as a "<b>Leaf</b>"</label>
2346
+ @ </td></tr>
2347
+ }else if( zBranchName ){
2348
+ @ <tr><th align="right" valign="top">Branch Closure:</th>
2349
+ @ <td valign="top">
2350
+ @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2351
+ @ Mark branch
2352
+ @ <span style="font-weight:bold" id="cbranch">%h(zBranchName)</span>
2353
+ @ as "closed" so that its leafs no longer appear on the "leaves" page
2354
+ @ and are no longer labeled as a leaf "<b>Leaf</b>"</label>
2355
+ @ </td></tr>
2356
+ }
2357
+ }
2358
+ if(zBranchName) fossil_free(zBranchName);
23192359
23202360
23212361
@ <tr><td colspan="2">
23222362
@ <input type="submit" name="preview" value="Preview" />
23232363
@ <input type="submit" name="apply" value="Apply Changes" />
23242364
--- src/info.c
+++ src/info.c
@@ -965,10 +965,15 @@
965 }
966 verboseFlag = (zVerbose!=0) && !is_false(zVerbose);
967 if( !verboseFlag && sideBySide ) verboseFlag = 1;
968 zFrom = P("from");
969 zTo = P("to");
 
 
 
 
 
970 if( !sideBySide ){
971 style_submenu_element("Side-by-side Diff", "sbsdiff",
972 "%R/vdiff?from=%T&to=%T&sbs=1",
973 zFrom, zTo);
974 }
@@ -1128,13 +1133,15 @@
1128 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1129 }
1130 @ - %!w(zCom) (user:
1131 hyperlink_to_user(zUser,zDate,")");
1132 if( g.perm.Hyperlink ){
 
1133 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1134 @ [annotate]</a>
1135 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
 
1136 }
1137 cnt++;
1138 if( pDownloadName && blob_size(pDownloadName)==0 ){
1139 blob_append(pDownloadName, zName, -1);
1140 }
@@ -1310,11 +1317,11 @@
1310 text_diff(&c1, &c2, pOut, pRe, diffFlags);
1311 blob_reset(&c1);
1312 blob_reset(&c2);
1313 return;
1314 }
1315
1316 sideBySide = !is_false(PD("sbs","1"));
1317 zV1 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v1);
1318 zV2 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v2);
1319 diffFlags = construct_diff_flags(1, sideBySide) | DIFF_HTML;
1320
@@ -1660,12 +1667,12 @@
1660 content_get(rid, &content);
1661 if( renderAsWiki ){
1662 wiki_convert(&content, 0, 0);
1663 }else if( renderAsHtml ){
1664 @ <iframe src="%R/raw/%T(blob_str(&downloadName))?name=%s(zUuid)"
1665 @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1666 @ sandbox="allow-same-origin"
1667 @ onload="this.height = this.contentDocument.documentElement.scrollHeight;">
1668 @ </iframe>
1669 }else{
1670 style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
1671 zMime = mimetype_from_content(&content);
@@ -2046,13 +2053,15 @@
2046 const char *zNewBrFlag;
2047 const char *zNewBranch;
2048 const char *zCloseFlag;
2049 int fPropagateColor; /* True if color propagates before edit */
2050 int fNewPropagateColor; /* True if color propagates after edit */
 
2051 const char *zChngTime = 0; /* Value of chngtime= query param, if any */
2052 char *zUuid;
2053 Blob comment;
 
2054 Stmt q;
2055
2056 login_check_credentials();
2057 if( !g.perm.Write ){ login_needed(); return; }
2058 rid = name_to_typed_rid(P("r"), "ci");
@@ -2137,11 +2146,12 @@
2137 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2138 }
2139 }
2140 db_finalize(&q);
2141 if( zCloseFlag[0] ){
2142 db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)");
 
2143 }
2144 if( zNewTagFlag[0] && zNewTag[0] ){
2145 db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
2146 }
2147 if( zNewBrFlag[0] && zNewBranch[0] ){
@@ -2188,10 +2198,21 @@
2188 }
2189 blob_zero(&comment);
2190 blob_append(&comment, zNewComment, -1);
2191 zUuid[10] = 0;
2192 style_header("Edit Check-in [%s]", zUuid);
 
 
 
 
 
 
 
 
 
 
 
2193 if( P("preview") ){
2194 Blob suffix;
2195 int nTag = 0;
2196 @ <b>Preview:</b>
2197 @ <blockquote>
@@ -2268,31 +2289,44 @@
2268 @ <label><input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
2269 @ Add the following new tag name to this check-in:</label>
2270 @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
2271 @ onkeyup="gebi('newtag').checked=!!this.value" />
2272 db_prepare(&q,
2273 "SELECT tag.tagid, tagname FROM tagxref, tag"
2274 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
2275 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
2276 " ELSE tagname END /*sort*/",
2277 rid
2278 );
2279 while( db_step(&q)==SQLITE_ROW ){
2280 int tagid = db_column_int(&q, 0);
2281 const char *zTagName = db_column_text(&q, 1);
 
2282 char zLabel[30];
 
 
 
 
 
 
 
 
 
 
 
 
2283 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
2284 @ <br /><label>
2285 if( P(zLabel) ){
2286 @ <input type="checkbox" name="c%d(tagid)" checked="checked" />
2287 }else{
2288 @ <input type="checkbox" name="c%d(tagid)" />
2289 }
2290 if( strncmp(zTagName, "sym-", 4)==0 ){
2291 @ Cancel tag <b>%h(&zTagName[4])</b></label>
2292 }else{
2293 @ Cancel special tag <b>%h(zTagName)</b></label>
2294 }
2295 }
2296 db_finalize(&q);
2297 @ </td></tr>
2298
@@ -2299,25 +2333,31 @@
2299 @ <tr><th align="right" valign="top">Branching:</th>
2300 @ <td valign="top">
2301 @ <label><input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
2302 @ Make this check-in the start of a new branch named:</label>
2303 @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2304 @ onkeyup="gebi('newbr').checked=!!this.value" />
2305 @ </td></tr>
2306
2307 if( is_a_leaf(rid)
2308 && !db_exists("SELECT 1 FROM tagxref "
2309 " WHERE tagid=%d AND rid=%d AND tagtype>0",
2310 TAG_CLOSED, rid)
2311 ){
2312 @ <tr><th align="right" valign="top">Leaf Closure:</th>
2313 @ <td valign="top">
2314 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2315 @ Mark this leaf as "closed" so that it no longer appears on the
2316 @ "leaves" page and is no longer labeled as a "<b>Leaf</b>".</label>
2317 @ </td></tr>
2318 }
 
 
 
 
 
 
2319
2320
2321 @ <tr><td colspan="2">
2322 @ <input type="submit" name="preview" value="Preview" />
2323 @ <input type="submit" name="apply" value="Apply Changes" />
2324
--- src/info.c
+++ src/info.c
@@ -965,10 +965,15 @@
965 }
966 verboseFlag = (zVerbose!=0) && !is_false(zVerbose);
967 if( !verboseFlag && sideBySide ) verboseFlag = 1;
968 zFrom = P("from");
969 zTo = P("to");
970 if( sideBySide || verboseFlag ){
971 style_submenu_element("Hide Diff", "hidediff",
972 "%R/vdiff?from=%T&to=%T&sbs=0",
973 zFrom, zTo);
974 }
975 if( !sideBySide ){
976 style_submenu_element("Side-by-side Diff", "sbsdiff",
977 "%R/vdiff?from=%T&to=%T&sbs=1",
978 zFrom, zTo);
979 }
@@ -1128,13 +1133,15 @@
1133 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1134 }
1135 @ - %!w(zCom) (user:
1136 hyperlink_to_user(zUser,zDate,")");
1137 if( g.perm.Hyperlink ){
1138 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1139 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1140 @ [annotate]</a>
1141 @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142 @ [blame]</a>
1143 }
1144 cnt++;
1145 if( pDownloadName && blob_size(pDownloadName)==0 ){
1146 blob_append(pDownloadName, zName, -1);
1147 }
@@ -1310,11 +1317,11 @@
1317 text_diff(&c1, &c2, pOut, pRe, diffFlags);
1318 blob_reset(&c1);
1319 blob_reset(&c2);
1320 return;
1321 }
1322
1323 sideBySide = !is_false(PD("sbs","1"));
1324 zV1 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v1);
1325 zV2 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v2);
1326 diffFlags = construct_diff_flags(1, sideBySide) | DIFF_HTML;
1327
@@ -1660,12 +1667,12 @@
1667 content_get(rid, &content);
1668 if( renderAsWiki ){
1669 wiki_convert(&content, 0, 0);
1670 }else if( renderAsHtml ){
1671 @ <iframe src="%R/raw/%T(blob_str(&downloadName))?name=%s(zUuid)"
1672 @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1673 @ sandbox="allow-same-origin"
1674 @ onload="this.height = this.contentDocument.documentElement.scrollHeight;">
1675 @ </iframe>
1676 }else{
1677 style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
1678 zMime = mimetype_from_content(&content);
@@ -2046,13 +2053,15 @@
2053 const char *zNewBrFlag;
2054 const char *zNewBranch;
2055 const char *zCloseFlag;
2056 int fPropagateColor; /* True if color propagates before edit */
2057 int fNewPropagateColor; /* True if color propagates after edit */
2058 int fHasClosed = 0; /* True if closed tag already set */
2059 const char *zChngTime = 0; /* Value of chngtime= query param, if any */
2060 char *zUuid;
2061 Blob comment;
2062 char *zBranchName = "";
2063 Stmt q;
2064
2065 login_check_credentials();
2066 if( !g.perm.Write ){ login_needed(); return; }
2067 rid = name_to_typed_rid(P("r"), "ci");
@@ -2137,11 +2146,12 @@
2146 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2147 }
2148 }
2149 db_finalize(&q);
2150 if( zCloseFlag[0] ){
2151 db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2152 is_a_leaf(rid)?"+":"*");
2153 }
2154 if( zNewTagFlag[0] && zNewTag[0] ){
2155 db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
2156 }
2157 if( zNewBrFlag[0] && zNewBranch[0] ){
@@ -2188,10 +2198,21 @@
2198 }
2199 blob_zero(&comment);
2200 blob_append(&comment, zNewComment, -1);
2201 zUuid[10] = 0;
2202 style_header("Edit Check-in [%s]", zUuid);
2203 /*
2204 ** chgbn: Handle change of branch name in remaining of form.
2205 */
2206 @ <script>
2207 @ function chgbn(val, branch){
2208 @ if (!val) val=branch;
2209 @ gebi('newbr').checked=(val!=branch);
2210 @ cidbrid = document.getElementById('cbranch');
2211 @ if( cidbrid ) cidbrid.textContent = val;
2212 @ }
2213 @ </script>
2214 if( P("preview") ){
2215 Blob suffix;
2216 int nTag = 0;
2217 @ <b>Preview:</b>
2218 @ <blockquote>
@@ -2268,31 +2289,44 @@
2289 @ <label><input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
2290 @ Add the following new tag name to this check-in:</label>
2291 @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
2292 @ onkeyup="gebi('newtag').checked=!!this.value" />
2293 db_prepare(&q,
2294 "SELECT tag.tagid, tagname, tagxref.value FROM tagxref, tag"
2295 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
2296 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
2297 " ELSE tagname END /*sort*/",
2298 rid
2299 );
2300 while( db_step(&q)==SQLITE_ROW ){
2301 int tagid = db_column_int(&q, 0);
2302 const char *zTagName = db_column_text(&q, 1);
2303 int isSpecialTag = strncmp(zTagName, "sym-", 4)!=0;
2304 char zLabel[30];
2305
2306 if (tagid == TAG_CLOSED){
2307 fHasClosed = 1;
2308 }else if (tagid == TAG_COMMENT){
2309 continue;
2310 }else if (tagid == TAG_BRANCH){
2311 zBranchName = mprintf("%s", db_column_text(&q, 2));
2312 continue;
2313 }else if( !isSpecialTag && zBranchName &&
2314 strcmp(&zTagName[4], zBranchName)==0){
2315 continue;
2316 }
2317 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
2318 @ <br /><label>
2319 if( P(zLabel) ){
2320 @ <input type="checkbox" name="c%d(tagid)" checked="checked" />
2321 }else{
2322 @ <input type="checkbox" name="c%d(tagid)" />
2323 }
2324 if( isSpecialTag ){
2325 @ Cancel special tag <b>%h(zTagName)</b></label>
2326 }else{
2327 @ Cancel tag <b>%h(&zTagName[4])</b></label>
2328 }
2329 }
2330 db_finalize(&q);
2331 @ </td></tr>
2332
@@ -2299,25 +2333,31 @@
2333 @ <tr><th align="right" valign="top">Branching:</th>
2334 @ <td valign="top">
2335 @ <label><input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
2336 @ Make this check-in the start of a new branch named:</label>
2337 @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2338 @ onkeyup="chgbn(this.value,'%h(zBranchName)')" /></td></tr>
2339 if( !fHasClosed ){
2340 if( is_a_leaf(rid) ){
2341 @ <tr><th align="right" valign="top">Leaf Closure:</th>
2342 @ <td valign="top">
2343 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2344 @ Mark this leaf as "closed" so that it no longer appears on the
2345 @ "leaves" page and is no longer labeled as a "<b>Leaf</b>"</label>
2346 @ </td></tr>
2347 }else if( zBranchName ){
2348 @ <tr><th align="right" valign="top">Branch Closure:</th>
2349 @ <td valign="top">
2350 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2351 @ Mark branch
2352 @ <span style="font-weight:bold" id="cbranch">%h(zBranchName)</span>
2353 @ as "closed" so that its leafs no longer appear on the "leaves" page
2354 @ and are no longer labeled as a leaf "<b>Leaf</b>"</label>
2355 @ </td></tr>
2356 }
2357 }
2358 if(zBranchName) fossil_free(zBranchName);
2359
2360
2361 @ <tr><td colspan="2">
2362 @ <input type="submit" name="preview" value="Preview" />
2363 @ <input type="submit" name="apply" value="Apply Changes" />
2364
+64 -24
--- src/info.c
+++ src/info.c
@@ -965,10 +965,15 @@
965965
}
966966
verboseFlag = (zVerbose!=0) && !is_false(zVerbose);
967967
if( !verboseFlag && sideBySide ) verboseFlag = 1;
968968
zFrom = P("from");
969969
zTo = P("to");
970
+ if( sideBySide || verboseFlag ){
971
+ style_submenu_element("Hide Diff", "hidediff",
972
+ "%R/vdiff?from=%T&to=%T&sbs=0",
973
+ zFrom, zTo);
974
+ }
970975
if( !sideBySide ){
971976
style_submenu_element("Side-by-side Diff", "sbsdiff",
972977
"%R/vdiff?from=%T&to=%T&sbs=1",
973978
zFrom, zTo);
974979
}
@@ -1128,13 +1133,15 @@
11281133
@ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
11291134
}
11301135
@ - %!w(zCom) (user:
11311136
hyperlink_to_user(zUser,zDate,")");
11321137
if( g.perm.Hyperlink ){
1138
+ @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
11331139
@ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
11341140
@ [annotate]</a>
1135
- @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1141
+ @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142
+ @ [blame]</a>
11361143
}
11371144
cnt++;
11381145
if( pDownloadName && blob_size(pDownloadName)==0 ){
11391146
blob_append(pDownloadName, zName, -1);
11401147
}
@@ -1310,11 +1317,11 @@
13101317
text_diff(&c1, &c2, pOut, pRe, diffFlags);
13111318
blob_reset(&c1);
13121319
blob_reset(&c2);
13131320
return;
13141321
}
1315
-
1322
+
13161323
sideBySide = !is_false(PD("sbs","1"));
13171324
zV1 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v1);
13181325
zV2 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v2);
13191326
diffFlags = construct_diff_flags(1, sideBySide) | DIFF_HTML;
13201327
@@ -1660,12 +1667,12 @@
16601667
content_get(rid, &content);
16611668
if( renderAsWiki ){
16621669
wiki_convert(&content, 0, 0);
16631670
}else if( renderAsHtml ){
16641671
@ <iframe src="%R/raw/%T(blob_str(&downloadName))?name=%s(zUuid)"
1665
- @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1666
- @ sandbox="allow-same-origin"
1672
+ @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1673
+ @ sandbox="allow-same-origin"
16671674
@ onload="this.height = this.contentDocument.documentElement.scrollHeight;">
16681675
@ </iframe>
16691676
}else{
16701677
style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
16711678
zMime = mimetype_from_content(&content);
@@ -2046,13 +2053,15 @@
20462053
const char *zNewBrFlag;
20472054
const char *zNewBranch;
20482055
const char *zCloseFlag;
20492056
int fPropagateColor; /* True if color propagates before edit */
20502057
int fNewPropagateColor; /* True if color propagates after edit */
2058
+ int fHasClosed = 0; /* True if closed tag already set */
20512059
const char *zChngTime = 0; /* Value of chngtime= query param, if any */
20522060
char *zUuid;
20532061
Blob comment;
2062
+ char *zBranchName = "";
20542063
Stmt q;
20552064
20562065
login_check_credentials();
20572066
if( !g.perm.Write ){ login_needed(); return; }
20582067
rid = name_to_typed_rid(P("r"), "ci");
@@ -2137,11 +2146,12 @@
21372146
db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
21382147
}
21392148
}
21402149
db_finalize(&q);
21412150
if( zCloseFlag[0] ){
2142
- db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)");
2151
+ db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2152
+ is_a_leaf(rid)?"+":"*");
21432153
}
21442154
if( zNewTagFlag[0] && zNewTag[0] ){
21452155
db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
21462156
}
21472157
if( zNewBrFlag[0] && zNewBranch[0] ){
@@ -2188,10 +2198,21 @@
21882198
}
21892199
blob_zero(&comment);
21902200
blob_append(&comment, zNewComment, -1);
21912201
zUuid[10] = 0;
21922202
style_header("Edit Check-in [%s]", zUuid);
2203
+ /*
2204
+ ** chgbn: Handle change of branch name in remaining of form.
2205
+ */
2206
+ @ <script>
2207
+ @ function chgbn(val, branch){
2208
+ @ if (!val) val=branch;
2209
+ @ gebi('newbr').checked=(val!=branch);
2210
+ @ cidbrid = document.getElementById('cbranch');
2211
+ @ if( cidbrid ) cidbrid.textContent = val;
2212
+ @ }
2213
+ @ </script>
21932214
if( P("preview") ){
21942215
Blob suffix;
21952216
int nTag = 0;
21962217
@ <b>Preview:</b>
21972218
@ <blockquote>
@@ -2268,31 +2289,44 @@
22682289
@ <label><input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
22692290
@ Add the following new tag name to this check-in:</label>
22702291
@ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
22712292
@ onkeyup="gebi('newtag').checked=!!this.value" />
22722293
db_prepare(&q,
2273
- "SELECT tag.tagid, tagname FROM tagxref, tag"
2294
+ "SELECT tag.tagid, tagname, tagxref.value FROM tagxref, tag"
22742295
" WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
22752296
" ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
22762297
" ELSE tagname END /*sort*/",
22772298
rid
22782299
);
22792300
while( db_step(&q)==SQLITE_ROW ){
22802301
int tagid = db_column_int(&q, 0);
22812302
const char *zTagName = db_column_text(&q, 1);
2303
+ int isSpecialTag = strncmp(zTagName, "sym-", 4)!=0;
22822304
char zLabel[30];
2305
+
2306
+ if (tagid == TAG_CLOSED){
2307
+ fHasClosed = 1;
2308
+ }else if (tagid == TAG_COMMENT){
2309
+ continue;
2310
+ }else if (tagid == TAG_BRANCH){
2311
+ zBranchName = mprintf("%s", db_column_text(&q, 2));
2312
+ continue;
2313
+ }else if( !isSpecialTag && zBranchName &&
2314
+ strcmp(&zTagName[4], zBranchName)==0){
2315
+ continue;
2316
+ }
22832317
sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
22842318
@ <br /><label>
22852319
if( P(zLabel) ){
22862320
@ <input type="checkbox" name="c%d(tagid)" checked="checked" />
22872321
}else{
22882322
@ <input type="checkbox" name="c%d(tagid)" />
22892323
}
2290
- if( strncmp(zTagName, "sym-", 4)==0 ){
2291
- @ Cancel tag <b>%h(&zTagName[4])</b></label>
2324
+ if( isSpecialTag ){
2325
+ @ Cancel special tag <b>%h(zTagName)</b></label>
22922326
}else{
2293
- @ Cancel special tag <b>%h(zTagName)</b></label>
2327
+ @ Cancel tag <b>%h(&zTagName[4])</b></label>
22942328
}
22952329
}
22962330
db_finalize(&q);
22972331
@ </td></tr>
22982332
@@ -2299,25 +2333,31 @@
22992333
@ <tr><th align="right" valign="top">Branching:</th>
23002334
@ <td valign="top">
23012335
@ <label><input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
23022336
@ Make this check-in the start of a new branch named:</label>
23032337
@ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2304
- @ onkeyup="gebi('newbr').checked=!!this.value" />
2305
- @ </td></tr>
2306
-
2307
- if( is_a_leaf(rid)
2308
- && !db_exists("SELECT 1 FROM tagxref "
2309
- " WHERE tagid=%d AND rid=%d AND tagtype>0",
2310
- TAG_CLOSED, rid)
2311
- ){
2312
- @ <tr><th align="right" valign="top">Leaf Closure:</th>
2313
- @ <td valign="top">
2314
- @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2315
- @ Mark this leaf as "closed" so that it no longer appears on the
2316
- @ "leaves" page and is no longer labeled as a "<b>Leaf</b>".</label>
2317
- @ </td></tr>
2318
- }
2338
+ @ onkeyup="chgbn(this.value,'%h(zBranchName)')" /></td></tr>
2339
+ if( !fHasClosed ){
2340
+ if( is_a_leaf(rid) ){
2341
+ @ <tr><th align="right" valign="top">Leaf Closure:</th>
2342
+ @ <td valign="top">
2343
+ @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2344
+ @ Mark this leaf as "closed" so that it no longer appears on the
2345
+ @ "leaves" page and is no longer labeled as a "<b>Leaf</b>"</label>
2346
+ @ </td></tr>
2347
+ }else if( zBranchName ){
2348
+ @ <tr><th align="right" valign="top">Branch Closure:</th>
2349
+ @ <td valign="top">
2350
+ @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2351
+ @ Mark branch
2352
+ @ <span style="font-weight:bold" id="cbranch">%h(zBranchName)</span>
2353
+ @ as "closed" so that its leafs no longer appear on the "leaves" page
2354
+ @ and are no longer labeled as a leaf "<b>Leaf</b>"</label>
2355
+ @ </td></tr>
2356
+ }
2357
+ }
2358
+ if(zBranchName) fossil_free(zBranchName);
23192359
23202360
23212361
@ <tr><td colspan="2">
23222362
@ <input type="submit" name="preview" value="Preview" />
23232363
@ <input type="submit" name="apply" value="Apply Changes" />
23242364
--- src/info.c
+++ src/info.c
@@ -965,10 +965,15 @@
965 }
966 verboseFlag = (zVerbose!=0) && !is_false(zVerbose);
967 if( !verboseFlag && sideBySide ) verboseFlag = 1;
968 zFrom = P("from");
969 zTo = P("to");
 
 
 
 
 
970 if( !sideBySide ){
971 style_submenu_element("Side-by-side Diff", "sbsdiff",
972 "%R/vdiff?from=%T&to=%T&sbs=1",
973 zFrom, zTo);
974 }
@@ -1128,13 +1133,15 @@
1128 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1129 }
1130 @ - %!w(zCom) (user:
1131 hyperlink_to_user(zUser,zDate,")");
1132 if( g.perm.Hyperlink ){
 
1133 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1134 @ [annotate]</a>
1135 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
 
1136 }
1137 cnt++;
1138 if( pDownloadName && blob_size(pDownloadName)==0 ){
1139 blob_append(pDownloadName, zName, -1);
1140 }
@@ -1310,11 +1317,11 @@
1310 text_diff(&c1, &c2, pOut, pRe, diffFlags);
1311 blob_reset(&c1);
1312 blob_reset(&c2);
1313 return;
1314 }
1315
1316 sideBySide = !is_false(PD("sbs","1"));
1317 zV1 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v1);
1318 zV2 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v2);
1319 diffFlags = construct_diff_flags(1, sideBySide) | DIFF_HTML;
1320
@@ -1660,12 +1667,12 @@
1660 content_get(rid, &content);
1661 if( renderAsWiki ){
1662 wiki_convert(&content, 0, 0);
1663 }else if( renderAsHtml ){
1664 @ <iframe src="%R/raw/%T(blob_str(&downloadName))?name=%s(zUuid)"
1665 @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1666 @ sandbox="allow-same-origin"
1667 @ onload="this.height = this.contentDocument.documentElement.scrollHeight;">
1668 @ </iframe>
1669 }else{
1670 style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
1671 zMime = mimetype_from_content(&content);
@@ -2046,13 +2053,15 @@
2046 const char *zNewBrFlag;
2047 const char *zNewBranch;
2048 const char *zCloseFlag;
2049 int fPropagateColor; /* True if color propagates before edit */
2050 int fNewPropagateColor; /* True if color propagates after edit */
 
2051 const char *zChngTime = 0; /* Value of chngtime= query param, if any */
2052 char *zUuid;
2053 Blob comment;
 
2054 Stmt q;
2055
2056 login_check_credentials();
2057 if( !g.perm.Write ){ login_needed(); return; }
2058 rid = name_to_typed_rid(P("r"), "ci");
@@ -2137,11 +2146,12 @@
2137 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2138 }
2139 }
2140 db_finalize(&q);
2141 if( zCloseFlag[0] ){
2142 db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)");
 
2143 }
2144 if( zNewTagFlag[0] && zNewTag[0] ){
2145 db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
2146 }
2147 if( zNewBrFlag[0] && zNewBranch[0] ){
@@ -2188,10 +2198,21 @@
2188 }
2189 blob_zero(&comment);
2190 blob_append(&comment, zNewComment, -1);
2191 zUuid[10] = 0;
2192 style_header("Edit Check-in [%s]", zUuid);
 
 
 
 
 
 
 
 
 
 
 
2193 if( P("preview") ){
2194 Blob suffix;
2195 int nTag = 0;
2196 @ <b>Preview:</b>
2197 @ <blockquote>
@@ -2268,31 +2289,44 @@
2268 @ <label><input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
2269 @ Add the following new tag name to this check-in:</label>
2270 @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
2271 @ onkeyup="gebi('newtag').checked=!!this.value" />
2272 db_prepare(&q,
2273 "SELECT tag.tagid, tagname FROM tagxref, tag"
2274 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
2275 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
2276 " ELSE tagname END /*sort*/",
2277 rid
2278 );
2279 while( db_step(&q)==SQLITE_ROW ){
2280 int tagid = db_column_int(&q, 0);
2281 const char *zTagName = db_column_text(&q, 1);
 
2282 char zLabel[30];
 
 
 
 
 
 
 
 
 
 
 
 
2283 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
2284 @ <br /><label>
2285 if( P(zLabel) ){
2286 @ <input type="checkbox" name="c%d(tagid)" checked="checked" />
2287 }else{
2288 @ <input type="checkbox" name="c%d(tagid)" />
2289 }
2290 if( strncmp(zTagName, "sym-", 4)==0 ){
2291 @ Cancel tag <b>%h(&zTagName[4])</b></label>
2292 }else{
2293 @ Cancel special tag <b>%h(zTagName)</b></label>
2294 }
2295 }
2296 db_finalize(&q);
2297 @ </td></tr>
2298
@@ -2299,25 +2333,31 @@
2299 @ <tr><th align="right" valign="top">Branching:</th>
2300 @ <td valign="top">
2301 @ <label><input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
2302 @ Make this check-in the start of a new branch named:</label>
2303 @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2304 @ onkeyup="gebi('newbr').checked=!!this.value" />
2305 @ </td></tr>
2306
2307 if( is_a_leaf(rid)
2308 && !db_exists("SELECT 1 FROM tagxref "
2309 " WHERE tagid=%d AND rid=%d AND tagtype>0",
2310 TAG_CLOSED, rid)
2311 ){
2312 @ <tr><th align="right" valign="top">Leaf Closure:</th>
2313 @ <td valign="top">
2314 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2315 @ Mark this leaf as "closed" so that it no longer appears on the
2316 @ "leaves" page and is no longer labeled as a "<b>Leaf</b>".</label>
2317 @ </td></tr>
2318 }
 
 
 
 
 
 
2319
2320
2321 @ <tr><td colspan="2">
2322 @ <input type="submit" name="preview" value="Preview" />
2323 @ <input type="submit" name="apply" value="Apply Changes" />
2324
--- src/info.c
+++ src/info.c
@@ -965,10 +965,15 @@
965 }
966 verboseFlag = (zVerbose!=0) && !is_false(zVerbose);
967 if( !verboseFlag && sideBySide ) verboseFlag = 1;
968 zFrom = P("from");
969 zTo = P("to");
970 if( sideBySide || verboseFlag ){
971 style_submenu_element("Hide Diff", "hidediff",
972 "%R/vdiff?from=%T&to=%T&sbs=0",
973 zFrom, zTo);
974 }
975 if( !sideBySide ){
976 style_submenu_element("Side-by-side Diff", "sbsdiff",
977 "%R/vdiff?from=%T&to=%T&sbs=1",
978 zFrom, zTo);
979 }
@@ -1128,13 +1133,15 @@
1133 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1134 }
1135 @ - %!w(zCom) (user:
1136 hyperlink_to_user(zUser,zDate,")");
1137 if( g.perm.Hyperlink ){
1138 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1139 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1140 @ [annotate]</a>
1141 @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142 @ [blame]</a>
1143 }
1144 cnt++;
1145 if( pDownloadName && blob_size(pDownloadName)==0 ){
1146 blob_append(pDownloadName, zName, -1);
1147 }
@@ -1310,11 +1317,11 @@
1317 text_diff(&c1, &c2, pOut, pRe, diffFlags);
1318 blob_reset(&c1);
1319 blob_reset(&c2);
1320 return;
1321 }
1322
1323 sideBySide = !is_false(PD("sbs","1"));
1324 zV1 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v1);
1325 zV2 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v2);
1326 diffFlags = construct_diff_flags(1, sideBySide) | DIFF_HTML;
1327
@@ -1660,12 +1667,12 @@
1667 content_get(rid, &content);
1668 if( renderAsWiki ){
1669 wiki_convert(&content, 0, 0);
1670 }else if( renderAsHtml ){
1671 @ <iframe src="%R/raw/%T(blob_str(&downloadName))?name=%s(zUuid)"
1672 @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
1673 @ sandbox="allow-same-origin"
1674 @ onload="this.height = this.contentDocument.documentElement.scrollHeight;">
1675 @ </iframe>
1676 }else{
1677 style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
1678 zMime = mimetype_from_content(&content);
@@ -2046,13 +2053,15 @@
2053 const char *zNewBrFlag;
2054 const char *zNewBranch;
2055 const char *zCloseFlag;
2056 int fPropagateColor; /* True if color propagates before edit */
2057 int fNewPropagateColor; /* True if color propagates after edit */
2058 int fHasClosed = 0; /* True if closed tag already set */
2059 const char *zChngTime = 0; /* Value of chngtime= query param, if any */
2060 char *zUuid;
2061 Blob comment;
2062 char *zBranchName = "";
2063 Stmt q;
2064
2065 login_check_credentials();
2066 if( !g.perm.Write ){ login_needed(); return; }
2067 rid = name_to_typed_rid(P("r"), "ci");
@@ -2137,11 +2146,12 @@
2146 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2147 }
2148 }
2149 db_finalize(&q);
2150 if( zCloseFlag[0] ){
2151 db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2152 is_a_leaf(rid)?"+":"*");
2153 }
2154 if( zNewTagFlag[0] && zNewTag[0] ){
2155 db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
2156 }
2157 if( zNewBrFlag[0] && zNewBranch[0] ){
@@ -2188,10 +2198,21 @@
2198 }
2199 blob_zero(&comment);
2200 blob_append(&comment, zNewComment, -1);
2201 zUuid[10] = 0;
2202 style_header("Edit Check-in [%s]", zUuid);
2203 /*
2204 ** chgbn: Handle change of branch name in remaining of form.
2205 */
2206 @ <script>
2207 @ function chgbn(val, branch){
2208 @ if (!val) val=branch;
2209 @ gebi('newbr').checked=(val!=branch);
2210 @ cidbrid = document.getElementById('cbranch');
2211 @ if( cidbrid ) cidbrid.textContent = val;
2212 @ }
2213 @ </script>
2214 if( P("preview") ){
2215 Blob suffix;
2216 int nTag = 0;
2217 @ <b>Preview:</b>
2218 @ <blockquote>
@@ -2268,31 +2289,44 @@
2289 @ <label><input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
2290 @ Add the following new tag name to this check-in:</label>
2291 @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
2292 @ onkeyup="gebi('newtag').checked=!!this.value" />
2293 db_prepare(&q,
2294 "SELECT tag.tagid, tagname, tagxref.value FROM tagxref, tag"
2295 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
2296 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
2297 " ELSE tagname END /*sort*/",
2298 rid
2299 );
2300 while( db_step(&q)==SQLITE_ROW ){
2301 int tagid = db_column_int(&q, 0);
2302 const char *zTagName = db_column_text(&q, 1);
2303 int isSpecialTag = strncmp(zTagName, "sym-", 4)!=0;
2304 char zLabel[30];
2305
2306 if (tagid == TAG_CLOSED){
2307 fHasClosed = 1;
2308 }else if (tagid == TAG_COMMENT){
2309 continue;
2310 }else if (tagid == TAG_BRANCH){
2311 zBranchName = mprintf("%s", db_column_text(&q, 2));
2312 continue;
2313 }else if( !isSpecialTag && zBranchName &&
2314 strcmp(&zTagName[4], zBranchName)==0){
2315 continue;
2316 }
2317 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
2318 @ <br /><label>
2319 if( P(zLabel) ){
2320 @ <input type="checkbox" name="c%d(tagid)" checked="checked" />
2321 }else{
2322 @ <input type="checkbox" name="c%d(tagid)" />
2323 }
2324 if( isSpecialTag ){
2325 @ Cancel special tag <b>%h(zTagName)</b></label>
2326 }else{
2327 @ Cancel tag <b>%h(&zTagName[4])</b></label>
2328 }
2329 }
2330 db_finalize(&q);
2331 @ </td></tr>
2332
@@ -2299,25 +2333,31 @@
2333 @ <tr><th align="right" valign="top">Branching:</th>
2334 @ <td valign="top">
2335 @ <label><input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
2336 @ Make this check-in the start of a new branch named:</label>
2337 @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2338 @ onkeyup="chgbn(this.value,'%h(zBranchName)')" /></td></tr>
2339 if( !fHasClosed ){
2340 if( is_a_leaf(rid) ){
2341 @ <tr><th align="right" valign="top">Leaf Closure:</th>
2342 @ <td valign="top">
2343 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2344 @ Mark this leaf as "closed" so that it no longer appears on the
2345 @ "leaves" page and is no longer labeled as a "<b>Leaf</b>"</label>
2346 @ </td></tr>
2347 }else if( zBranchName ){
2348 @ <tr><th align="right" valign="top">Branch Closure:</th>
2349 @ <td valign="top">
2350 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2351 @ Mark branch
2352 @ <span style="font-weight:bold" id="cbranch">%h(zBranchName)</span>
2353 @ as "closed" so that its leafs no longer appear on the "leaves" page
2354 @ and are no longer labeled as a leaf "<b>Leaf</b>"</label>
2355 @ </td></tr>
2356 }
2357 }
2358 if(zBranchName) fossil_free(zBranchName);
2359
2360
2361 @ <tr><td colspan="2">
2362 @ <input type="submit" name="preview" value="Preview" />
2363 @ <input type="submit" name="apply" value="Apply Changes" />
2364
+1 -1
--- src/json.c
+++ src/json.c
@@ -1980,11 +1980,11 @@
19801980
19811981
jv2 = cson_value_new_object();
19821982
jo2 = cson_value_get_object(jv2);
19831983
cson_object_set(jo, "sqlite", jv2);
19841984
sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
1985
- SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION);
1985
+ sqlite3_sourceid(), &sqlite3_sourceid()[20], sqlite3_libversion());
19861986
SETBUF(jo2, "version");
19871987
zDb = db_name("repository");
19881988
cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_count", zDb)));
19891989
cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_size", zDb)));
19901990
cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.freelist_count", zDb)));
19911991
--- src/json.c
+++ src/json.c
@@ -1980,11 +1980,11 @@
1980
1981 jv2 = cson_value_new_object();
1982 jo2 = cson_value_get_object(jv2);
1983 cson_object_set(jo, "sqlite", jv2);
1984 sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
1985 SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION);
1986 SETBUF(jo2, "version");
1987 zDb = db_name("repository");
1988 cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_count", zDb)));
1989 cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_size", zDb)));
1990 cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.freelist_count", zDb)));
1991
--- src/json.c
+++ src/json.c
@@ -1980,11 +1980,11 @@
1980
1981 jv2 = cson_value_new_object();
1982 jo2 = cson_value_get_object(jv2);
1983 cson_object_set(jo, "sqlite", jv2);
1984 sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
1985 sqlite3_sourceid(), &sqlite3_sourceid()[20], sqlite3_libversion());
1986 SETBUF(jo2, "version");
1987 zDb = db_name("repository");
1988 cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_count", zDb)));
1989 cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_size", zDb)));
1990 cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.freelist_count", zDb)));
1991
--- src/json_finfo.c
+++ src/json_finfo.c
@@ -74,11 +74,11 @@
7474
/*6*/ " (SELECT uuid FROM blob WHERE rid=mlink.pid)," /* Parent file uuid */
7575
/*7*/ " event.bgcolor,"
7676
/*8*/ " b.size,"
7777
/*9*/ " (mlink.pid==0) AS isNew,"
7878
/*10*/ " (mlink.fid==0) AS isDel"
79
- " FROM mlink, blob b, event, blob ci, filename"
79
+ " FROM mlink, blob b, event, blob ci, filename"
8080
" WHERE filename.name=%Q"
8181
" AND mlink.fnid=filename.fnid"
8282
" AND b.rid=mlink.fid"
8383
" AND event.objid=mlink.mid"
8484
" AND event.objid=ci.rid",
8585
--- src/json_finfo.c
+++ src/json_finfo.c
@@ -74,11 +74,11 @@
74 /*6*/ " (SELECT uuid FROM blob WHERE rid=mlink.pid)," /* Parent file uuid */
75 /*7*/ " event.bgcolor,"
76 /*8*/ " b.size,"
77 /*9*/ " (mlink.pid==0) AS isNew,"
78 /*10*/ " (mlink.fid==0) AS isDel"
79 " FROM mlink, blob b, event, blob ci, filename"
80 " WHERE filename.name=%Q"
81 " AND mlink.fnid=filename.fnid"
82 " AND b.rid=mlink.fid"
83 " AND event.objid=mlink.mid"
84 " AND event.objid=ci.rid",
85
--- src/json_finfo.c
+++ src/json_finfo.c
@@ -74,11 +74,11 @@
74 /*6*/ " (SELECT uuid FROM blob WHERE rid=mlink.pid)," /* Parent file uuid */
75 /*7*/ " event.bgcolor,"
76 /*8*/ " b.size,"
77 /*9*/ " (mlink.pid==0) AS isNew,"
78 /*10*/ " (mlink.fid==0) AS isDel"
79 " FROM mlink, blob b, event, blob ci, filename"
80 " WHERE filename.name=%Q"
81 " AND mlink.fnid=filename.fnid"
82 " AND b.rid=mlink.fid"
83 " AND event.objid=mlink.mid"
84 " AND event.objid=ci.rid",
85
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -145,10 +145,11 @@
145145
static char json_timeline_add_tag_branch_clause(Blob *pSql,
146146
cson_object * pPayload){
147147
char const * zTag = NULL;
148148
char const * zBranch = NULL;
149149
char const * zMiOnly = NULL;
150
+ char const * zUnhide = NULL;
150151
int tagid = 0;
151152
if(! g.perm.Read ){
152153
return 0;
153154
}
154155
zTag = json_find_option_cstr("tag",NULL,NULL);
@@ -158,10 +159,11 @@
158159
return 0;
159160
}
160161
zTag = zBranch;
161162
zMiOnly = json_find_option_cstr("mionly",NULL,NULL);
162163
}
164
+ zUnhide = json_find_option_cstr("unhide",NULL,NULL);
163165
tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",
164166
zTag);
165167
if(tagid<=0){
166168
return -1;
167169
}
@@ -171,21 +173,39 @@
171173
blob_appendf(pSql,
172174
" AND ("
173175
" EXISTS(SELECT 1 FROM tagxref"
174176
" WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)",
175177
tagid);
178
+ if(!zUnhide){
179
+ blob_appendf(pSql,
180
+ " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=blob.rid"
181
+ " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)",
182
+ TAG_HIDDEN);
183
+ }
176184
if(zBranch){
177185
/* from "r" flag code in page_timeline().*/
178186
blob_appendf(pSql,
179187
" OR EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid"
180188
" WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
181189
tagid);
190
+ if( !zUnhide ){
191
+ blob_appendf(pSql,
192
+ " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid"
193
+ " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
194
+ TAG_HIDDEN);
195
+ }
182196
if( zMiOnly==0 ){
183197
blob_appendf(pSql,
184198
" OR EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid"
185199
" WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
186200
tagid);
201
+ if( !zUnhide ){
202
+ blob_appendf(pSql,
203
+ " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid"
204
+ " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
205
+ TAG_HIDDEN);
206
+ }
187207
}
188208
}
189209
blob_append(pSql," ) ",3);
190210
return 1;
191211
}
192212
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -145,10 +145,11 @@
145 static char json_timeline_add_tag_branch_clause(Blob *pSql,
146 cson_object * pPayload){
147 char const * zTag = NULL;
148 char const * zBranch = NULL;
149 char const * zMiOnly = NULL;
 
150 int tagid = 0;
151 if(! g.perm.Read ){
152 return 0;
153 }
154 zTag = json_find_option_cstr("tag",NULL,NULL);
@@ -158,10 +159,11 @@
158 return 0;
159 }
160 zTag = zBranch;
161 zMiOnly = json_find_option_cstr("mionly",NULL,NULL);
162 }
 
163 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",
164 zTag);
165 if(tagid<=0){
166 return -1;
167 }
@@ -171,21 +173,39 @@
171 blob_appendf(pSql,
172 " AND ("
173 " EXISTS(SELECT 1 FROM tagxref"
174 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)",
175 tagid);
 
 
 
 
 
 
176 if(zBranch){
177 /* from "r" flag code in page_timeline().*/
178 blob_appendf(pSql,
179 " OR EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid"
180 " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
181 tagid);
 
 
 
 
 
 
182 if( zMiOnly==0 ){
183 blob_appendf(pSql,
184 " OR EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid"
185 " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
186 tagid);
 
 
 
 
 
 
187 }
188 }
189 blob_append(pSql," ) ",3);
190 return 1;
191 }
192
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -145,10 +145,11 @@
145 static char json_timeline_add_tag_branch_clause(Blob *pSql,
146 cson_object * pPayload){
147 char const * zTag = NULL;
148 char const * zBranch = NULL;
149 char const * zMiOnly = NULL;
150 char const * zUnhide = NULL;
151 int tagid = 0;
152 if(! g.perm.Read ){
153 return 0;
154 }
155 zTag = json_find_option_cstr("tag",NULL,NULL);
@@ -158,10 +159,11 @@
159 return 0;
160 }
161 zTag = zBranch;
162 zMiOnly = json_find_option_cstr("mionly",NULL,NULL);
163 }
164 zUnhide = json_find_option_cstr("unhide",NULL,NULL);
165 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",
166 zTag);
167 if(tagid<=0){
168 return -1;
169 }
@@ -171,21 +173,39 @@
173 blob_appendf(pSql,
174 " AND ("
175 " EXISTS(SELECT 1 FROM tagxref"
176 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)",
177 tagid);
178 if(!zUnhide){
179 blob_appendf(pSql,
180 " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=blob.rid"
181 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)",
182 TAG_HIDDEN);
183 }
184 if(zBranch){
185 /* from "r" flag code in page_timeline().*/
186 blob_appendf(pSql,
187 " OR EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid"
188 " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
189 tagid);
190 if( !zUnhide ){
191 blob_appendf(pSql,
192 " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid"
193 " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
194 TAG_HIDDEN);
195 }
196 if( zMiOnly==0 ){
197 blob_appendf(pSql,
198 " OR EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid"
199 " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
200 tagid);
201 if( !zUnhide ){
202 blob_appendf(pSql,
203 " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid"
204 " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
205 TAG_HIDDEN);
206 }
207 }
208 }
209 blob_append(pSql," ) ",3);
210 return 1;
211 }
212
+18 -6
--- src/login.c
+++ src/login.c
@@ -474,11 +474,11 @@
474474
char *zSha1Pw;
475475
const char *zIpAddr; /* IP address of requestor */
476476
477477
login_check_credentials();
478478
sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
479
- constant_time_cmp_function, 0, 0);
479
+ constant_time_cmp_function, 0, 0);
480480
zUsername = P("u");
481481
zPasswd = P("p");
482482
anonFlag = P("anon")!=0;
483483
if( P("out")!=0 ){
484484
login_clear_login_data();
@@ -695,15 +695,19 @@
695695
"SELECT value FROM config WHERE name='peer-repo-%q'",
696696
zCode
697697
);
698698
if( zOtherRepo==0 ) return 0; /* No such peer repository */
699699
700
- rc = sqlite3_open(zOtherRepo, &pOther);
700
+ rc = sqlite3_open_v2(
701
+ zOtherRepo, &pOther,
702
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
703
+ g.zVfsName
704
+ );
701705
if( rc==SQLITE_OK ){
702706
sqlite3_create_function(pOther,"now",0,SQLITE_ANY,0,db_now_function,0,0);
703707
sqlite3_create_function(pOther, "constant_time_cmp", 2, SQLITE_UTF8, 0,
704
- constant_time_cmp_function, 0, 0);
708
+ constant_time_cmp_function, 0, 0);
705709
sqlite3_busy_timeout(pOther, 5000);
706710
zSQL = mprintf(
707711
"SELECT cexpire FROM user"
708712
" WHERE login=%Q"
709713
" AND ipaddr=%Q"
@@ -784,11 +788,11 @@
784788
785789
/* Only run this check once. */
786790
if( g.userUid!=0 ) return;
787791
788792
sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
789
- constant_time_cmp_function, 0, 0);
793
+ constant_time_cmp_function, 0, 0);
790794
791795
/* If the HTTP connection is coming over 127.0.0.1 and if
792796
** local login is disabled and if we are using HTTP and not HTTPS,
793797
** then there is no need to check user credentials.
794798
**
@@ -1372,11 +1376,15 @@
13721376
"DELETE FROM config WHERE name GLOB 'peer-*-%q'",
13731377
&zLabel[10]
13741378
);
13751379
continue;
13761380
}
1377
- rc = sqlite3_open_v2(zRepoName, &pPeer, SQLITE_OPEN_READWRITE, 0);
1381
+ rc = sqlite3_open_v2(
1382
+ zRepoName, &pPeer,
1383
+ SQLITE_OPEN_READWRITE,
1384
+ g.zVfsName
1385
+ );
13781386
if( rc!=SQLITE_OK ){
13791387
blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName,
13801388
sqlite3_errmsg(pPeer), zSuffix);
13811389
nErr++;
13821390
sqlite3_close(pPeer);
@@ -1459,11 +1467,15 @@
14591467
/* Make sure the other repository is a valid Fossil database */
14601468
if( file_size(zRepo)<0 ){
14611469
*pzErrMsg = mprintf("repository file \"%s\" does not exist", zRepo);
14621470
return;
14631471
}
1464
- rc = sqlite3_open(zRepo, &pOther);
1472
+ rc = sqlite3_open_v2(
1473
+ zRepo, &pOther,
1474
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
1475
+ g.zVfsName
1476
+ );
14651477
if( rc!=SQLITE_OK ){
14661478
*pzErrMsg = mprintf(sqlite3_errmsg(pOther));
14671479
}else{
14681480
rc = sqlite3_exec(pOther, "SELECT count(*) FROM user", 0, 0, pzErrMsg);
14691481
}
14701482
--- src/login.c
+++ src/login.c
@@ -474,11 +474,11 @@
474 char *zSha1Pw;
475 const char *zIpAddr; /* IP address of requestor */
476
477 login_check_credentials();
478 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
479 constant_time_cmp_function, 0, 0);
480 zUsername = P("u");
481 zPasswd = P("p");
482 anonFlag = P("anon")!=0;
483 if( P("out")!=0 ){
484 login_clear_login_data();
@@ -695,15 +695,19 @@
695 "SELECT value FROM config WHERE name='peer-repo-%q'",
696 zCode
697 );
698 if( zOtherRepo==0 ) return 0; /* No such peer repository */
699
700 rc = sqlite3_open(zOtherRepo, &pOther);
 
 
 
 
701 if( rc==SQLITE_OK ){
702 sqlite3_create_function(pOther,"now",0,SQLITE_ANY,0,db_now_function,0,0);
703 sqlite3_create_function(pOther, "constant_time_cmp", 2, SQLITE_UTF8, 0,
704 constant_time_cmp_function, 0, 0);
705 sqlite3_busy_timeout(pOther, 5000);
706 zSQL = mprintf(
707 "SELECT cexpire FROM user"
708 " WHERE login=%Q"
709 " AND ipaddr=%Q"
@@ -784,11 +788,11 @@
784
785 /* Only run this check once. */
786 if( g.userUid!=0 ) return;
787
788 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
789 constant_time_cmp_function, 0, 0);
790
791 /* If the HTTP connection is coming over 127.0.0.1 and if
792 ** local login is disabled and if we are using HTTP and not HTTPS,
793 ** then there is no need to check user credentials.
794 **
@@ -1372,11 +1376,15 @@
1372 "DELETE FROM config WHERE name GLOB 'peer-*-%q'",
1373 &zLabel[10]
1374 );
1375 continue;
1376 }
1377 rc = sqlite3_open_v2(zRepoName, &pPeer, SQLITE_OPEN_READWRITE, 0);
 
 
 
 
1378 if( rc!=SQLITE_OK ){
1379 blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName,
1380 sqlite3_errmsg(pPeer), zSuffix);
1381 nErr++;
1382 sqlite3_close(pPeer);
@@ -1459,11 +1467,15 @@
1459 /* Make sure the other repository is a valid Fossil database */
1460 if( file_size(zRepo)<0 ){
1461 *pzErrMsg = mprintf("repository file \"%s\" does not exist", zRepo);
1462 return;
1463 }
1464 rc = sqlite3_open(zRepo, &pOther);
 
 
 
 
1465 if( rc!=SQLITE_OK ){
1466 *pzErrMsg = mprintf(sqlite3_errmsg(pOther));
1467 }else{
1468 rc = sqlite3_exec(pOther, "SELECT count(*) FROM user", 0, 0, pzErrMsg);
1469 }
1470
--- src/login.c
+++ src/login.c
@@ -474,11 +474,11 @@
474 char *zSha1Pw;
475 const char *zIpAddr; /* IP address of requestor */
476
477 login_check_credentials();
478 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
479 constant_time_cmp_function, 0, 0);
480 zUsername = P("u");
481 zPasswd = P("p");
482 anonFlag = P("anon")!=0;
483 if( P("out")!=0 ){
484 login_clear_login_data();
@@ -695,15 +695,19 @@
695 "SELECT value FROM config WHERE name='peer-repo-%q'",
696 zCode
697 );
698 if( zOtherRepo==0 ) return 0; /* No such peer repository */
699
700 rc = sqlite3_open_v2(
701 zOtherRepo, &pOther,
702 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
703 g.zVfsName
704 );
705 if( rc==SQLITE_OK ){
706 sqlite3_create_function(pOther,"now",0,SQLITE_ANY,0,db_now_function,0,0);
707 sqlite3_create_function(pOther, "constant_time_cmp", 2, SQLITE_UTF8, 0,
708 constant_time_cmp_function, 0, 0);
709 sqlite3_busy_timeout(pOther, 5000);
710 zSQL = mprintf(
711 "SELECT cexpire FROM user"
712 " WHERE login=%Q"
713 " AND ipaddr=%Q"
@@ -784,11 +788,11 @@
788
789 /* Only run this check once. */
790 if( g.userUid!=0 ) return;
791
792 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
793 constant_time_cmp_function, 0, 0);
794
795 /* If the HTTP connection is coming over 127.0.0.1 and if
796 ** local login is disabled and if we are using HTTP and not HTTPS,
797 ** then there is no need to check user credentials.
798 **
@@ -1372,11 +1376,15 @@
1376 "DELETE FROM config WHERE name GLOB 'peer-*-%q'",
1377 &zLabel[10]
1378 );
1379 continue;
1380 }
1381 rc = sqlite3_open_v2(
1382 zRepoName, &pPeer,
1383 SQLITE_OPEN_READWRITE,
1384 g.zVfsName
1385 );
1386 if( rc!=SQLITE_OK ){
1387 blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName,
1388 sqlite3_errmsg(pPeer), zSuffix);
1389 nErr++;
1390 sqlite3_close(pPeer);
@@ -1459,11 +1467,15 @@
1467 /* Make sure the other repository is a valid Fossil database */
1468 if( file_size(zRepo)<0 ){
1469 *pzErrMsg = mprintf("repository file \"%s\" does not exist", zRepo);
1470 return;
1471 }
1472 rc = sqlite3_open_v2(
1473 zRepo, &pOther,
1474 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
1475 g.zVfsName
1476 );
1477 if( rc!=SQLITE_OK ){
1478 *pzErrMsg = mprintf(sqlite3_errmsg(pOther));
1479 }else{
1480 rc = sqlite3_exec(pOther, "SELECT count(*) FROM user", 0, 0, pzErrMsg);
1481 }
1482
+20 -1
--- src/main.c
+++ src/main.c
@@ -121,10 +121,11 @@
121121
struct Global {
122122
int argc; char **argv; /* Command-line arguments to the program */
123123
char *nameOfExe; /* Full path of executable. */
124124
const char *zErrlog; /* Log errors to this file, if not NULL */
125125
int isConst; /* True if the output is unchanging */
126
+ const char *zVfsName; /* The VFS to use for database connections */
126127
sqlite3 *db; /* The connection to the databases */
127128
sqlite3 *dbConfig; /* Separate connection for global_config table */
128129
int useAttach; /* True if global_config is attached to repository */
129130
const char *zConfigDbName;/* Path of the config database. NULL if not open */
130131
sqlite3_int64 now; /* Seconds since 1970 */
@@ -557,10 +558,11 @@
557558
#endif
558559
{
559560
const char *zCmdName = "unknown";
560561
int idx;
561562
int rc;
563
+ sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
562564
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
563565
memset(&g, 0, sizeof(g));
564566
g.now = time(0);
565567
g.httpHeader = empty_blob;
566568
#ifdef FOSSIL_ENABLE_JSON
@@ -581,10 +583,27 @@
581583
memset(&g.tcl, 0, sizeof(TclContext));
582584
g.tcl.argc = g.argc;
583585
g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
584586
#endif
585587
g.mainTimerId = fossil_timer_start();
588
+ g.zVfsName = find_option("vfs",0,1);
589
+ if( g.zVfsName==0 ){
590
+ g.zVfsName = fossil_getenv("FOSSIL_VFS");
591
+#if defined(__CYGWIN__)
592
+ if( g.zVfsName==0 && sqlite3_libversion_number()>=3008001 ){
593
+ g.zVfsName = "win32-longpath";
594
+ }
595
+#endif
596
+ }
597
+ if( g.zVfsName ){
598
+ sqlite3_vfs *pVfs = sqlite3_vfs_find(g.zVfsName);
599
+ if( pVfs ){
600
+ sqlite3_vfs_register(pVfs, 1);
601
+ }else{
602
+ fossil_fatal("no such VFS: \"%s\"", g.zVfsName);
603
+ }
604
+ }
586605
if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
587606
zCmdName = "cgi";
588607
g.isHTTP = 1;
589608
}else if( g.argc<2 ){
590609
fossil_print(
@@ -840,11 +859,11 @@
840859
int rc;
841860
const char *zRc;
842861
#endif
843862
fossil_print("Compiled on %s %s using %s (%d-bit)\n",
844863
__DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
845
- fossil_print("SQLite %s %.30s\n", SQLITE_VERSION, SQLITE_SOURCE_ID);
864
+ fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
846865
fossil_print("Schema version %s\n", AUX_SCHEMA);
847866
fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
848867
#if defined(FOSSIL_ENABLE_SSL)
849868
fossil_print("SSL (%s)\n", OPENSSL_VERSION_TEXT);
850869
#endif
851870
--- src/main.c
+++ src/main.c
@@ -121,10 +121,11 @@
121 struct Global {
122 int argc; char **argv; /* Command-line arguments to the program */
123 char *nameOfExe; /* Full path of executable. */
124 const char *zErrlog; /* Log errors to this file, if not NULL */
125 int isConst; /* True if the output is unchanging */
 
126 sqlite3 *db; /* The connection to the databases */
127 sqlite3 *dbConfig; /* Separate connection for global_config table */
128 int useAttach; /* True if global_config is attached to repository */
129 const char *zConfigDbName;/* Path of the config database. NULL if not open */
130 sqlite3_int64 now; /* Seconds since 1970 */
@@ -557,10 +558,11 @@
557 #endif
558 {
559 const char *zCmdName = "unknown";
560 int idx;
561 int rc;
 
562 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
563 memset(&g, 0, sizeof(g));
564 g.now = time(0);
565 g.httpHeader = empty_blob;
566 #ifdef FOSSIL_ENABLE_JSON
@@ -581,10 +583,27 @@
581 memset(&g.tcl, 0, sizeof(TclContext));
582 g.tcl.argc = g.argc;
583 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
584 #endif
585 g.mainTimerId = fossil_timer_start();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586 if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
587 zCmdName = "cgi";
588 g.isHTTP = 1;
589 }else if( g.argc<2 ){
590 fossil_print(
@@ -840,11 +859,11 @@
840 int rc;
841 const char *zRc;
842 #endif
843 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
844 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
845 fossil_print("SQLite %s %.30s\n", SQLITE_VERSION, SQLITE_SOURCE_ID);
846 fossil_print("Schema version %s\n", AUX_SCHEMA);
847 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
848 #if defined(FOSSIL_ENABLE_SSL)
849 fossil_print("SSL (%s)\n", OPENSSL_VERSION_TEXT);
850 #endif
851
--- src/main.c
+++ src/main.c
@@ -121,10 +121,11 @@
121 struct Global {
122 int argc; char **argv; /* Command-line arguments to the program */
123 char *nameOfExe; /* Full path of executable. */
124 const char *zErrlog; /* Log errors to this file, if not NULL */
125 int isConst; /* True if the output is unchanging */
126 const char *zVfsName; /* The VFS to use for database connections */
127 sqlite3 *db; /* The connection to the databases */
128 sqlite3 *dbConfig; /* Separate connection for global_config table */
129 int useAttach; /* True if global_config is attached to repository */
130 const char *zConfigDbName;/* Path of the config database. NULL if not open */
131 sqlite3_int64 now; /* Seconds since 1970 */
@@ -557,10 +558,11 @@
558 #endif
559 {
560 const char *zCmdName = "unknown";
561 int idx;
562 int rc;
563 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
564 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
565 memset(&g, 0, sizeof(g));
566 g.now = time(0);
567 g.httpHeader = empty_blob;
568 #ifdef FOSSIL_ENABLE_JSON
@@ -581,10 +583,27 @@
583 memset(&g.tcl, 0, sizeof(TclContext));
584 g.tcl.argc = g.argc;
585 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
586 #endif
587 g.mainTimerId = fossil_timer_start();
588 g.zVfsName = find_option("vfs",0,1);
589 if( g.zVfsName==0 ){
590 g.zVfsName = fossil_getenv("FOSSIL_VFS");
591 #if defined(__CYGWIN__)
592 if( g.zVfsName==0 && sqlite3_libversion_number()>=3008001 ){
593 g.zVfsName = "win32-longpath";
594 }
595 #endif
596 }
597 if( g.zVfsName ){
598 sqlite3_vfs *pVfs = sqlite3_vfs_find(g.zVfsName);
599 if( pVfs ){
600 sqlite3_vfs_register(pVfs, 1);
601 }else{
602 fossil_fatal("no such VFS: \"%s\"", g.zVfsName);
603 }
604 }
605 if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
606 zCmdName = "cgi";
607 g.isHTTP = 1;
608 }else if( g.argc<2 ){
609 fossil_print(
@@ -840,11 +859,11 @@
859 int rc;
860 const char *zRc;
861 #endif
862 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
863 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
864 fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
865 fossil_print("Schema version %s\n", AUX_SCHEMA);
866 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
867 #if defined(FOSSIL_ENABLE_SSL)
868 fossil_print("SSL (%s)\n", OPENSSL_VERSION_TEXT);
869 #endif
870
+20 -1
--- src/main.c
+++ src/main.c
@@ -121,10 +121,11 @@
121121
struct Global {
122122
int argc; char **argv; /* Command-line arguments to the program */
123123
char *nameOfExe; /* Full path of executable. */
124124
const char *zErrlog; /* Log errors to this file, if not NULL */
125125
int isConst; /* True if the output is unchanging */
126
+ const char *zVfsName; /* The VFS to use for database connections */
126127
sqlite3 *db; /* The connection to the databases */
127128
sqlite3 *dbConfig; /* Separate connection for global_config table */
128129
int useAttach; /* True if global_config is attached to repository */
129130
const char *zConfigDbName;/* Path of the config database. NULL if not open */
130131
sqlite3_int64 now; /* Seconds since 1970 */
@@ -557,10 +558,11 @@
557558
#endif
558559
{
559560
const char *zCmdName = "unknown";
560561
int idx;
561562
int rc;
563
+ sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
562564
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
563565
memset(&g, 0, sizeof(g));
564566
g.now = time(0);
565567
g.httpHeader = empty_blob;
566568
#ifdef FOSSIL_ENABLE_JSON
@@ -581,10 +583,27 @@
581583
memset(&g.tcl, 0, sizeof(TclContext));
582584
g.tcl.argc = g.argc;
583585
g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
584586
#endif
585587
g.mainTimerId = fossil_timer_start();
588
+ g.zVfsName = find_option("vfs",0,1);
589
+ if( g.zVfsName==0 ){
590
+ g.zVfsName = fossil_getenv("FOSSIL_VFS");
591
+#if defined(__CYGWIN__)
592
+ if( g.zVfsName==0 && sqlite3_libversion_number()>=3008001 ){
593
+ g.zVfsName = "win32-longpath";
594
+ }
595
+#endif
596
+ }
597
+ if( g.zVfsName ){
598
+ sqlite3_vfs *pVfs = sqlite3_vfs_find(g.zVfsName);
599
+ if( pVfs ){
600
+ sqlite3_vfs_register(pVfs, 1);
601
+ }else{
602
+ fossil_fatal("no such VFS: \"%s\"", g.zVfsName);
603
+ }
604
+ }
586605
if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
587606
zCmdName = "cgi";
588607
g.isHTTP = 1;
589608
}else if( g.argc<2 ){
590609
fossil_print(
@@ -840,11 +859,11 @@
840859
int rc;
841860
const char *zRc;
842861
#endif
843862
fossil_print("Compiled on %s %s using %s (%d-bit)\n",
844863
__DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
845
- fossil_print("SQLite %s %.30s\n", SQLITE_VERSION, SQLITE_SOURCE_ID);
864
+ fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
846865
fossil_print("Schema version %s\n", AUX_SCHEMA);
847866
fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
848867
#if defined(FOSSIL_ENABLE_SSL)
849868
fossil_print("SSL (%s)\n", OPENSSL_VERSION_TEXT);
850869
#endif
851870
--- src/main.c
+++ src/main.c
@@ -121,10 +121,11 @@
121 struct Global {
122 int argc; char **argv; /* Command-line arguments to the program */
123 char *nameOfExe; /* Full path of executable. */
124 const char *zErrlog; /* Log errors to this file, if not NULL */
125 int isConst; /* True if the output is unchanging */
 
126 sqlite3 *db; /* The connection to the databases */
127 sqlite3 *dbConfig; /* Separate connection for global_config table */
128 int useAttach; /* True if global_config is attached to repository */
129 const char *zConfigDbName;/* Path of the config database. NULL if not open */
130 sqlite3_int64 now; /* Seconds since 1970 */
@@ -557,10 +558,11 @@
557 #endif
558 {
559 const char *zCmdName = "unknown";
560 int idx;
561 int rc;
 
562 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
563 memset(&g, 0, sizeof(g));
564 g.now = time(0);
565 g.httpHeader = empty_blob;
566 #ifdef FOSSIL_ENABLE_JSON
@@ -581,10 +583,27 @@
581 memset(&g.tcl, 0, sizeof(TclContext));
582 g.tcl.argc = g.argc;
583 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
584 #endif
585 g.mainTimerId = fossil_timer_start();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586 if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
587 zCmdName = "cgi";
588 g.isHTTP = 1;
589 }else if( g.argc<2 ){
590 fossil_print(
@@ -840,11 +859,11 @@
840 int rc;
841 const char *zRc;
842 #endif
843 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
844 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
845 fossil_print("SQLite %s %.30s\n", SQLITE_VERSION, SQLITE_SOURCE_ID);
846 fossil_print("Schema version %s\n", AUX_SCHEMA);
847 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
848 #if defined(FOSSIL_ENABLE_SSL)
849 fossil_print("SSL (%s)\n", OPENSSL_VERSION_TEXT);
850 #endif
851
--- src/main.c
+++ src/main.c
@@ -121,10 +121,11 @@
121 struct Global {
122 int argc; char **argv; /* Command-line arguments to the program */
123 char *nameOfExe; /* Full path of executable. */
124 const char *zErrlog; /* Log errors to this file, if not NULL */
125 int isConst; /* True if the output is unchanging */
126 const char *zVfsName; /* The VFS to use for database connections */
127 sqlite3 *db; /* The connection to the databases */
128 sqlite3 *dbConfig; /* Separate connection for global_config table */
129 int useAttach; /* True if global_config is attached to repository */
130 const char *zConfigDbName;/* Path of the config database. NULL if not open */
131 sqlite3_int64 now; /* Seconds since 1970 */
@@ -557,10 +558,11 @@
558 #endif
559 {
560 const char *zCmdName = "unknown";
561 int idx;
562 int rc;
563 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
564 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
565 memset(&g, 0, sizeof(g));
566 g.now = time(0);
567 g.httpHeader = empty_blob;
568 #ifdef FOSSIL_ENABLE_JSON
@@ -581,10 +583,27 @@
583 memset(&g.tcl, 0, sizeof(TclContext));
584 g.tcl.argc = g.argc;
585 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
586 #endif
587 g.mainTimerId = fossil_timer_start();
588 g.zVfsName = find_option("vfs",0,1);
589 if( g.zVfsName==0 ){
590 g.zVfsName = fossil_getenv("FOSSIL_VFS");
591 #if defined(__CYGWIN__)
592 if( g.zVfsName==0 && sqlite3_libversion_number()>=3008001 ){
593 g.zVfsName = "win32-longpath";
594 }
595 #endif
596 }
597 if( g.zVfsName ){
598 sqlite3_vfs *pVfs = sqlite3_vfs_find(g.zVfsName);
599 if( pVfs ){
600 sqlite3_vfs_register(pVfs, 1);
601 }else{
602 fossil_fatal("no such VFS: \"%s\"", g.zVfsName);
603 }
604 }
605 if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
606 zCmdName = "cgi";
607 g.isHTTP = 1;
608 }else if( g.argc<2 ){
609 fossil_print(
@@ -840,11 +859,11 @@
859 int rc;
860 const char *zRc;
861 #endif
862 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
863 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
864 fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
865 fossil_print("Schema version %s\n", AUX_SCHEMA);
866 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
867 #if defined(FOSSIL_ENABLE_SSL)
868 fossil_print("SSL (%s)\n", OPENSSL_VERSION_TEXT);
869 #endif
870
+16 -2
--- src/main.mk
+++ src/main.mk
@@ -371,10 +371,24 @@
371371
test: $(OBJDIR) $(APPNAME)
372372
$(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME)
373373
374374
$(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
375375
$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
376
+
377
+# Setup the options used to compile the included SQLite library.
378
+SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 \
379
+ -DSQLITE_THREADSAFE=0 \
380
+ -DSQLITE_DEFAULT_FILE_FORMAT=4 \
381
+ -DSQLITE_OMIT_DEPRECATED \
382
+ -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
383
+ -Dlocaltime=fossil_localtime \
384
+ -DSQLITE_ENABLE_LOCKING_STYLE=0
385
+
386
+# Setup the options used to compile the included SQLite shell.
387
+SHELL_OPTIONS = -Dmain=sqlite3_shell \
388
+ -DSQLITE_OMIT_LOAD_EXTENSION=1 \
389
+ -Dsqlite3_strglob=strglob
376390
377391
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
378392
# to 1. If it is set to 1, then there is no need to build or link
379393
# the sqlite3.o object. Instead, the system sqlite will be linked
380394
# using -lsqlite3.
@@ -1160,14 +1174,14 @@
11601174
$(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
11611175
$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
11621176
11631177
$(OBJDIR)/zip.h: $(OBJDIR)/headers
11641178
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1165
- $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1179
+ $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
11661180
11671181
$(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1168
- $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1182
+ $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
11691183
11701184
$(OBJDIR)/th.o: $(SRCDIR)/th.c
11711185
$(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
11721186
11731187
$(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
11741188
--- src/main.mk
+++ src/main.mk
@@ -371,10 +371,24 @@
371 test: $(OBJDIR) $(APPNAME)
372 $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME)
373
374 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
375 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
377 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
378 # to 1. If it is set to 1, then there is no need to build or link
379 # the sqlite3.o object. Instead, the system sqlite will be linked
380 # using -lsqlite3.
@@ -1160,14 +1174,14 @@
1160 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1161 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1162
1163 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1164 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1165 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1166
1167 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1168 $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1169
1170 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1171 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1172
1173 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1174
--- src/main.mk
+++ src/main.mk
@@ -371,10 +371,24 @@
371 test: $(OBJDIR) $(APPNAME)
372 $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME)
373
374 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
375 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
376
377 # Setup the options used to compile the included SQLite library.
378 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 \
379 -DSQLITE_THREADSAFE=0 \
380 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
381 -DSQLITE_OMIT_DEPRECATED \
382 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
383 -Dlocaltime=fossil_localtime \
384 -DSQLITE_ENABLE_LOCKING_STYLE=0
385
386 # Setup the options used to compile the included SQLite shell.
387 SHELL_OPTIONS = -Dmain=sqlite3_shell \
388 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
389 -Dsqlite3_strglob=strglob
390
391 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
392 # to 1. If it is set to 1, then there is no need to build or link
393 # the sqlite3.o object. Instead, the system sqlite will be linked
394 # using -lsqlite3.
@@ -1160,14 +1174,14 @@
1174 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1175 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1176
1177 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1178 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1179 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1180
1181 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1182 $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1183
1184 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1185 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1186
1187 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1188
+74 -39
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -125,10 +125,40 @@
125125
xfersetup
126126
zip
127127
http_ssl
128128
}
129129
130
+# Options used to compile the included SQLite library.
131
+#
132
+set SQLITE_OPTIONS {
133
+ -DSQLITE_OMIT_LOAD_EXTENSION=1
134
+ -DSQLITE_THREADSAFE=0
135
+ -DSQLITE_DEFAULT_FILE_FORMAT=4
136
+ -DSQLITE_OMIT_DEPRECATED
137
+ -DSQLITE_ENABLE_EXPLAIN_COMMENTS
138
+ -Dlocaltime=fossil_localtime
139
+ -DSQLITE_ENABLE_LOCKING_STYLE=0
140
+}
141
+#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
142
+#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
143
+#lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
144
+#lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
145
+
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
+ -Dsqlite3_strglob=strglob
152
+}
153
+
154
+# Options used to compile the included SQLite shell on Windows.
155
+#
156
+set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
157
+lappend SHELL_WIN32_OPTIONS -Dgetenv=fossil_getenv
158
+lappend SHELL_WIN32_OPTIONS -Dfopen=fossil_fopen
159
+
130160
# Name of the final application
131161
#
132162
set name fossil
133163
134164
# The "writeln" command sends output to the target makefile.
@@ -186,11 +216,13 @@
186216
}
187217
writeln "\n"
188218
writeln "APPNAME = $name\$(E)"
189219
writeln "\n"
190220
191
-writeln {
221
+writeln [string map [list \
222
+ <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
223
+ <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "]] {
192224
all: $(OBJDIR) $(APPNAME)
193225
194226
install: $(APPNAME)
195227
mkdir -p $(INSTALLDIR)
196228
mv $(APPNAME) $(INSTALLDIR)
@@ -218,10 +250,16 @@
218250
219251
$(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
220252
$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
221253
$(SRCDIR)/../manifest \
222254
$(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
255
+
256
+# Setup the options used to compile the included SQLite library.
257
+SQLITE_OPTIONS = <<<SQLITE_OPTIONS>>>
258
+
259
+# Setup the options used to compile the included SQLite shell.
260
+SHELL_OPTIONS = <<<SHELL_OPTIONS>>>
223261
224262
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
225263
# to 1. If it is set to 1, then there is no need to build or link
226264
# the sqlite3.o object. Instead, the system sqlite will be linked
227265
# using -lsqlite3.
@@ -254,11 +292,11 @@
254292
# noop
255293
256294
clean:
257295
rm -rf $(OBJDIR)/* $(APPNAME)
258296
259
-}
297
+}]
260298
261299
set mhargs {}
262300
foreach s [lsort $src] {
263301
append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h"
264302
set extra_h($s) {}
@@ -283,27 +321,15 @@
283321
writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
284322
writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
285323
writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers"
286324
}
287325
288
-
289326
writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
290
-set opt {-DSQLITE_OMIT_LOAD_EXTENSION=1}
291
-append opt " -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4"
292
-#append opt " -DSQLITE_ENABLE_FTS3=1"
293
-append opt " -DSQLITE_ENABLE_STAT3"
294
-append opt " -Dlocaltime=fossil_localtime"
295
-append opt " -DSQLITE_ENABLE_LOCKING_STYLE=0"
296
-append opt " -DSQLITE_WIN32_NO_ANSI"
297
-set SQLITE_OPTIONS $opt
298
-writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
327
+writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
299328
300329
writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
301
-set opt {-Dmain=sqlite3_shell}
302
-append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
303
-append opt " -Dsqlite3_strglob=strglob"
304
-writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
330
+writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
305331
306332
writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
307333
writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
308334
309335
writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
@@ -310,11 +336,10 @@
310336
writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$(OBJDIR)/th_lang.o\n"
311337
312338
writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
313339
writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$(OBJDIR)/th_tcl.o\n"
314340
315
-set opt {}
316341
writeln {
317342
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
318343
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
319344
320345
#
@@ -646,13 +671,15 @@
646671
647672
$(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
648673
ifdef USE_WINDOWS
649674
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
650675
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
676
+ $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
651677
else
652678
$(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
653679
$(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
680
+ $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
654681
endif
655682
$(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
656683
657684
install: $(OBJDIR) $(APPNAME)
658685
ifdef USE_WINDOWS
@@ -768,28 +795,29 @@
768795
writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
769796
writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
770797
writeln "\$(OBJDIR)/${s}.h:\t\$(OBJDIR)/headers\n"
771798
}
772799
800
+set MINGW_SQLITE_OPTIONS $SQLITE_OPTIONS
801
+lappend MINGW_SQLITE_OPTIONS -D_HAVE_SQLITE_CONFIG_H
802
+lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MALLOC_H
803
+lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MSIZE
804
+
805
+set j " \\\n "
806
+writeln "SQLITE_OPTIONS = [join $MINGW_SQLITE_OPTIONS $j]\n"
807
+set j " \\\n "
808
+writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
773809
774810
writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
775
-set opt $SQLITE_OPTIONS
776
-append opt " -D_HAVE_SQLITE_CONFIG_H"
777
-writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
811
+writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
778812
779
-set opt {}
780813
writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
781
-writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
814
+writeln "\t\$(XTCC) -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
782815
writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_finfo.o \$(OBJDIR)/json_login.o \$(OBJDIR)/json_query.o \$(OBJDIR)/json_report.o \$(OBJDIR)/json_status.o \$(OBJDIR)/json_tag.o \$(OBJDIR)/json_timeline.o \$(OBJDIR)/json_user.o \$(OBJDIR)/json_wiki.o : \$(SRCDIR)/json_detail.h\n"
783816
784817
writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
785
-set opt {-Dmain=sqlite3_shell}
786
-append opt " -Dsqlite3_strglob=strglob"
787
-append opt " -Dgetenv=fossil_getenv"
788
-append opt " -Dfopen=fossil_fopen"
789
-append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
790
-writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
818
+writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
791819
792820
writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
793821
writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
794822
795823
writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
@@ -838,11 +866,12 @@
838866
CFLAGS = -o
839867
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
840868
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
841869
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
842870
}
843
-writeln "SQLITE_OPTIONS = $SQLITE_OPTIONS\n"
871
+writeln "SQLITE_OPTIONS = [join $SQLITE_OPTIONS { }]\n"
872
+writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS { }]\n"
844873
writeln -nonewline "SRC = "
845874
foreach s [lsort $src] {
846875
writeln -nonewline "${s}_.c "
847876
}
848877
writeln "\n"
@@ -891,14 +920,14 @@
891920
892921
version$E: $B\src\mkversion.c
893922
$(BCC) -o$@ $**
894923
895924
$(OBJDIR)\shell$O : $(SRCDIR)\shell.c
896
- $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
925
+ $(TCC) -o$@ -c $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) $**
897926
898927
$(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
899
- $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
928
+ $(TCC) -o$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
900929
901930
$(OBJDIR)\th$O : $(SRCDIR)\th.c
902931
$(TCC) -o$@ -c $**
903932
904933
$(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -1030,13 +1059,18 @@
10301059
RCC = $(RCC) -DFOSSIL_ENABLE_SSL=1
10311060
LIBS = $(LIBS) $(SSLLIB)
10321061
LIBDIR = $(LIBDIR) -LIBPATH:$(SSLLIBDIR)
10331062
!endif
10341063
}
1035
-regsub -all {[-]D} $SQLITE_OPTIONS {/D} MSC_SQLITE_OPTIONS
1064
+regsub -all {[-]D} [join $SQLITE_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
10361065
set j " \\\n "
10371066
writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
1067
+
1068
+regsub -all {[-]D} [join $SHELL_WIN32_OPTIONS { }] {/D} MSC_SHELL_OPTIONS
1069
+set j " \\\n "
1070
+writeln "SHELL_OPTIONS = [join $MSC_SHELL_OPTIONS $j]\n"
1071
+
10381072
writeln -nonewline "SRC = "
10391073
set i 0
10401074
foreach s [lsort $src] {
10411075
if {$i > 0} {
10421076
writeln " \\"
@@ -1094,14 +1128,14 @@
10941128
10951129
mkversion$E: $B\src\mkversion.c
10961130
$(BCC) $**
10971131
10981132
$(OX)\shell$O : $(SRCDIR)\shell.c
1099
- $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
1133
+ $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
11001134
11011135
$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
1102
- $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
1136
+ $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
11031137
11041138
$(OX)\th$O : $(SRCDIR)\th.c
11051139
$(TCC) /Fo$@ -c $**
11061140
11071141
$(OX)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -1119,11 +1153,10 @@
11191153
-del $(OX)\*.obj
11201154
-del *.obj
11211155
-del *_.c
11221156
-del *.h
11231157
-del *.map
1124
- -del *.manifest
11251158
-del headers
11261159
-del linkopts
11271160
-del *.res
11281161
11291162
realclean: clean
@@ -1187,11 +1220,13 @@
11871220
#
11881221
puts "building ../win/Makefile.PellesCGMake"
11891222
set output_file [open ../win/Makefile.PellesCGMake w]
11901223
fconfigure $output_file -translation binary
11911224
1192
-writeln {#
1225
+writeln [string map [list \
1226
+ <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS { }] \
1227
+ <<<SHELL_OPTIONS>>> [join $SHELL_WIN32_OPTIONS { }]] {#
11931228
##############################################################################
11941229
# WARNING: DO NOT EDIT, AUTOMATICALLY GENERATED FILE (SEE "src/makemake.tcl")
11951230
##############################################################################
11961231
#
11971232
# This file is automatically generated. Instead of editing this
@@ -1274,17 +1309,17 @@
12741309
12751310
# define the sqlite files, which need special flags on compile
12761311
SQLITESRC=sqlite3.c
12771312
ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
12781313
SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
1279
-SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
1314
+SQLITEDEFINES=<<<SQLITE_OPTIONS>>>
12801315
12811316
# define the sqlite shell files, which need special flags on compile
12821317
SQLITESHELLSRC=shell.c
12831318
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
12841319
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1285
-SQLITESHELLDEFINES=-Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
1320
+SQLITESHELLDEFINES=<<<SHELL_OPTIONS>>>
12861321
12871322
# define the th scripting files, which need special flags on compile
12881323
THSRC=th.c th_lang.c
12891324
ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
12901325
THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
@@ -1377,6 +1412,6 @@
13771412
del /F $(RESOURCE)
13781413
13791414
.PHONY: clobber
13801415
clobber: clean
13811416
del /F *.exe
1382
-}
1417
+}]
13831418
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -125,10 +125,40 @@
125 xfersetup
126 zip
127 http_ssl
128 }
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130 # Name of the final application
131 #
132 set name fossil
133
134 # The "writeln" command sends output to the target makefile.
@@ -186,11 +216,13 @@
186 }
187 writeln "\n"
188 writeln "APPNAME = $name\$(E)"
189 writeln "\n"
190
191 writeln {
 
 
192 all: $(OBJDIR) $(APPNAME)
193
194 install: $(APPNAME)
195 mkdir -p $(INSTALLDIR)
196 mv $(APPNAME) $(INSTALLDIR)
@@ -218,10 +250,16 @@
218
219 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
220 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
221 $(SRCDIR)/../manifest \
222 $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
 
 
 
 
 
 
223
224 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
225 # to 1. If it is set to 1, then there is no need to build or link
226 # the sqlite3.o object. Instead, the system sqlite will be linked
227 # using -lsqlite3.
@@ -254,11 +292,11 @@
254 # noop
255
256 clean:
257 rm -rf $(OBJDIR)/* $(APPNAME)
258
259 }
260
261 set mhargs {}
262 foreach s [lsort $src] {
263 append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h"
264 set extra_h($s) {}
@@ -283,27 +321,15 @@
283 writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
284 writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
285 writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers"
286 }
287
288
289 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
290 set opt {-DSQLITE_OMIT_LOAD_EXTENSION=1}
291 append opt " -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4"
292 #append opt " -DSQLITE_ENABLE_FTS3=1"
293 append opt " -DSQLITE_ENABLE_STAT3"
294 append opt " -Dlocaltime=fossil_localtime"
295 append opt " -DSQLITE_ENABLE_LOCKING_STYLE=0"
296 append opt " -DSQLITE_WIN32_NO_ANSI"
297 set SQLITE_OPTIONS $opt
298 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
299
300 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
301 set opt {-Dmain=sqlite3_shell}
302 append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
303 append opt " -Dsqlite3_strglob=strglob"
304 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
305
306 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
307 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
308
309 writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
@@ -310,11 +336,10 @@
310 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$(OBJDIR)/th_lang.o\n"
311
312 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
313 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$(OBJDIR)/th_tcl.o\n"
314
315 set opt {}
316 writeln {
317 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
318 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
319
320 #
@@ -646,13 +671,15 @@
646
647 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
648 ifdef USE_WINDOWS
649 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
650 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
 
651 else
652 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
653 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
 
654 endif
655 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
656
657 install: $(OBJDIR) $(APPNAME)
658 ifdef USE_WINDOWS
@@ -768,28 +795,29 @@
768 writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
769 writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
770 writeln "\$(OBJDIR)/${s}.h:\t\$(OBJDIR)/headers\n"
771 }
772
 
 
 
 
 
 
 
 
 
773
774 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
775 set opt $SQLITE_OPTIONS
776 append opt " -D_HAVE_SQLITE_CONFIG_H"
777 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
778
779 set opt {}
780 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
781 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
782 writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_finfo.o \$(OBJDIR)/json_login.o \$(OBJDIR)/json_query.o \$(OBJDIR)/json_report.o \$(OBJDIR)/json_status.o \$(OBJDIR)/json_tag.o \$(OBJDIR)/json_timeline.o \$(OBJDIR)/json_user.o \$(OBJDIR)/json_wiki.o : \$(SRCDIR)/json_detail.h\n"
783
784 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
785 set opt {-Dmain=sqlite3_shell}
786 append opt " -Dsqlite3_strglob=strglob"
787 append opt " -Dgetenv=fossil_getenv"
788 append opt " -Dfopen=fossil_fopen"
789 append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
790 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
791
792 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
793 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
794
795 writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
@@ -838,11 +866,12 @@
838 CFLAGS = -o
839 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
840 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
841 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
842 }
843 writeln "SQLITE_OPTIONS = $SQLITE_OPTIONS\n"
 
844 writeln -nonewline "SRC = "
845 foreach s [lsort $src] {
846 writeln -nonewline "${s}_.c "
847 }
848 writeln "\n"
@@ -891,14 +920,14 @@
891
892 version$E: $B\src\mkversion.c
893 $(BCC) -o$@ $**
894
895 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
896 $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
897
898 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
899 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
900
901 $(OBJDIR)\th$O : $(SRCDIR)\th.c
902 $(TCC) -o$@ -c $**
903
904 $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -1030,13 +1059,18 @@
1030 RCC = $(RCC) -DFOSSIL_ENABLE_SSL=1
1031 LIBS = $(LIBS) $(SSLLIB)
1032 LIBDIR = $(LIBDIR) -LIBPATH:$(SSLLIBDIR)
1033 !endif
1034 }
1035 regsub -all {[-]D} $SQLITE_OPTIONS {/D} MSC_SQLITE_OPTIONS
1036 set j " \\\n "
1037 writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
 
 
 
 
 
1038 writeln -nonewline "SRC = "
1039 set i 0
1040 foreach s [lsort $src] {
1041 if {$i > 0} {
1042 writeln " \\"
@@ -1094,14 +1128,14 @@
1094
1095 mkversion$E: $B\src\mkversion.c
1096 $(BCC) $**
1097
1098 $(OX)\shell$O : $(SRCDIR)\shell.c
1099 $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
1100
1101 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
1102 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
1103
1104 $(OX)\th$O : $(SRCDIR)\th.c
1105 $(TCC) /Fo$@ -c $**
1106
1107 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -1119,11 +1153,10 @@
1119 -del $(OX)\*.obj
1120 -del *.obj
1121 -del *_.c
1122 -del *.h
1123 -del *.map
1124 -del *.manifest
1125 -del headers
1126 -del linkopts
1127 -del *.res
1128
1129 realclean: clean
@@ -1187,11 +1220,13 @@
1187 #
1188 puts "building ../win/Makefile.PellesCGMake"
1189 set output_file [open ../win/Makefile.PellesCGMake w]
1190 fconfigure $output_file -translation binary
1191
1192 writeln {#
 
 
1193 ##############################################################################
1194 # WARNING: DO NOT EDIT, AUTOMATICALLY GENERATED FILE (SEE "src/makemake.tcl")
1195 ##############################################################################
1196 #
1197 # This file is automatically generated. Instead of editing this
@@ -1274,17 +1309,17 @@
1274
1275 # define the sqlite files, which need special flags on compile
1276 SQLITESRC=sqlite3.c
1277 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
1278 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
1279 SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
1280
1281 # define the sqlite shell files, which need special flags on compile
1282 SQLITESHELLSRC=shell.c
1283 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
1284 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1285 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
1286
1287 # define the th scripting files, which need special flags on compile
1288 THSRC=th.c th_lang.c
1289 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
1290 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
@@ -1377,6 +1412,6 @@
1377 del /F $(RESOURCE)
1378
1379 .PHONY: clobber
1380 clobber: clean
1381 del /F *.exe
1382 }
1383
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -125,10 +125,40 @@
125 xfersetup
126 zip
127 http_ssl
128 }
129
130 # Options used to compile the included SQLite library.
131 #
132 set SQLITE_OPTIONS {
133 -DSQLITE_OMIT_LOAD_EXTENSION=1
134 -DSQLITE_THREADSAFE=0
135 -DSQLITE_DEFAULT_FILE_FORMAT=4
136 -DSQLITE_OMIT_DEPRECATED
137 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
138 -Dlocaltime=fossil_localtime
139 -DSQLITE_ENABLE_LOCKING_STYLE=0
140 }
141 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
142 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
143 #lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
144 #lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
145
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 -Dsqlite3_strglob=strglob
152 }
153
154 # Options used to compile the included SQLite shell on Windows.
155 #
156 set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
157 lappend SHELL_WIN32_OPTIONS -Dgetenv=fossil_getenv
158 lappend SHELL_WIN32_OPTIONS -Dfopen=fossil_fopen
159
160 # Name of the final application
161 #
162 set name fossil
163
164 # The "writeln" command sends output to the target makefile.
@@ -186,11 +216,13 @@
216 }
217 writeln "\n"
218 writeln "APPNAME = $name\$(E)"
219 writeln "\n"
220
221 writeln [string map [list \
222 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
223 <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "]] {
224 all: $(OBJDIR) $(APPNAME)
225
226 install: $(APPNAME)
227 mkdir -p $(INSTALLDIR)
228 mv $(APPNAME) $(INSTALLDIR)
@@ -218,10 +250,16 @@
250
251 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
252 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
253 $(SRCDIR)/../manifest \
254 $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
255
256 # Setup the options used to compile the included SQLite library.
257 SQLITE_OPTIONS = <<<SQLITE_OPTIONS>>>
258
259 # Setup the options used to compile the included SQLite shell.
260 SHELL_OPTIONS = <<<SHELL_OPTIONS>>>
261
262 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
263 # to 1. If it is set to 1, then there is no need to build or link
264 # the sqlite3.o object. Instead, the system sqlite will be linked
265 # using -lsqlite3.
@@ -254,11 +292,11 @@
292 # noop
293
294 clean:
295 rm -rf $(OBJDIR)/* $(APPNAME)
296
297 }]
298
299 set mhargs {}
300 foreach s [lsort $src] {
301 append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h"
302 set extra_h($s) {}
@@ -283,27 +321,15 @@
321 writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
322 writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
323 writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers"
324 }
325
 
326 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
327 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
 
 
 
 
 
 
 
 
328
329 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
330 writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
 
 
 
331
332 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
333 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
334
335 writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
@@ -310,11 +336,10 @@
336 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$(OBJDIR)/th_lang.o\n"
337
338 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
339 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$(OBJDIR)/th_tcl.o\n"
340
 
341 writeln {
342 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
343 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
344
345 #
@@ -646,13 +671,15 @@
671
672 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
673 ifdef USE_WINDOWS
674 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
675 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
676 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
677 else
678 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
679 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
680 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
681 endif
682 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
683
684 install: $(OBJDIR) $(APPNAME)
685 ifdef USE_WINDOWS
@@ -768,28 +795,29 @@
795 writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
796 writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
797 writeln "\$(OBJDIR)/${s}.h:\t\$(OBJDIR)/headers\n"
798 }
799
800 set MINGW_SQLITE_OPTIONS $SQLITE_OPTIONS
801 lappend MINGW_SQLITE_OPTIONS -D_HAVE_SQLITE_CONFIG_H
802 lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MALLOC_H
803 lappend MINGW_SQLITE_OPTIONS -DSQLITE_USE_MSIZE
804
805 set j " \\\n "
806 writeln "SQLITE_OPTIONS = [join $MINGW_SQLITE_OPTIONS $j]\n"
807 set j " \\\n "
808 writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
809
810 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
811 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
 
 
812
 
813 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
814 writeln "\t\$(XTCC) -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
815 writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_finfo.o \$(OBJDIR)/json_login.o \$(OBJDIR)/json_query.o \$(OBJDIR)/json_report.o \$(OBJDIR)/json_status.o \$(OBJDIR)/json_tag.o \$(OBJDIR)/json_timeline.o \$(OBJDIR)/json_user.o \$(OBJDIR)/json_wiki.o : \$(SRCDIR)/json_detail.h\n"
816
817 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
818 writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
 
 
 
 
 
819
820 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
821 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
822
823 writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
@@ -838,11 +866,12 @@
866 CFLAGS = -o
867 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
868 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
869 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
870 }
871 writeln "SQLITE_OPTIONS = [join $SQLITE_OPTIONS { }]\n"
872 writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS { }]\n"
873 writeln -nonewline "SRC = "
874 foreach s [lsort $src] {
875 writeln -nonewline "${s}_.c "
876 }
877 writeln "\n"
@@ -891,14 +920,14 @@
920
921 version$E: $B\src\mkversion.c
922 $(BCC) -o$@ $**
923
924 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
925 $(TCC) -o$@ -c $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) $**
926
927 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
928 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
929
930 $(OBJDIR)\th$O : $(SRCDIR)\th.c
931 $(TCC) -o$@ -c $**
932
933 $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -1030,13 +1059,18 @@
1059 RCC = $(RCC) -DFOSSIL_ENABLE_SSL=1
1060 LIBS = $(LIBS) $(SSLLIB)
1061 LIBDIR = $(LIBDIR) -LIBPATH:$(SSLLIBDIR)
1062 !endif
1063 }
1064 regsub -all {[-]D} [join $SQLITE_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
1065 set j " \\\n "
1066 writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
1067
1068 regsub -all {[-]D} [join $SHELL_WIN32_OPTIONS { }] {/D} MSC_SHELL_OPTIONS
1069 set j " \\\n "
1070 writeln "SHELL_OPTIONS = [join $MSC_SHELL_OPTIONS $j]\n"
1071
1072 writeln -nonewline "SRC = "
1073 set i 0
1074 foreach s [lsort $src] {
1075 if {$i > 0} {
1076 writeln " \\"
@@ -1094,14 +1128,14 @@
1128
1129 mkversion$E: $B\src\mkversion.c
1130 $(BCC) $**
1131
1132 $(OX)\shell$O : $(SRCDIR)\shell.c
1133 $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
1134
1135 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
1136 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
1137
1138 $(OX)\th$O : $(SRCDIR)\th.c
1139 $(TCC) /Fo$@ -c $**
1140
1141 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -1119,11 +1153,10 @@
1153 -del $(OX)\*.obj
1154 -del *.obj
1155 -del *_.c
1156 -del *.h
1157 -del *.map
 
1158 -del headers
1159 -del linkopts
1160 -del *.res
1161
1162 realclean: clean
@@ -1187,11 +1220,13 @@
1220 #
1221 puts "building ../win/Makefile.PellesCGMake"
1222 set output_file [open ../win/Makefile.PellesCGMake w]
1223 fconfigure $output_file -translation binary
1224
1225 writeln [string map [list \
1226 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS { }] \
1227 <<<SHELL_OPTIONS>>> [join $SHELL_WIN32_OPTIONS { }]] {#
1228 ##############################################################################
1229 # WARNING: DO NOT EDIT, AUTOMATICALLY GENERATED FILE (SEE "src/makemake.tcl")
1230 ##############################################################################
1231 #
1232 # This file is automatically generated. Instead of editing this
@@ -1274,17 +1309,17 @@
1309
1310 # define the sqlite files, which need special flags on compile
1311 SQLITESRC=sqlite3.c
1312 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
1313 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
1314 SQLITEDEFINES=<<<SQLITE_OPTIONS>>>
1315
1316 # define the sqlite shell files, which need special flags on compile
1317 SQLITESHELLSRC=shell.c
1318 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
1319 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1320 SQLITESHELLDEFINES=<<<SHELL_OPTIONS>>>
1321
1322 # define the th scripting files, which need special flags on compile
1323 THSRC=th.c th_lang.c
1324 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
1325 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
@@ -1377,6 +1412,6 @@
1412 del /F $(RESOURCE)
1413
1414 .PHONY: clobber
1415 clobber: clean
1416 del /F *.exe
1417 }]
1418
+1 -1
--- src/md5.c
+++ src/md5.c
@@ -164,11 +164,11 @@
164164
/*
165165
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
166166
* initialization constants.
167167
*/
168168
static void MD5Init(MD5Context *ctx){
169
- ctx->isInit = 1;
169
+ ctx->isInit = 1;
170170
ctx->buf[0] = 0x67452301;
171171
ctx->buf[1] = 0xefcdab89;
172172
ctx->buf[2] = 0x98badcfe;
173173
ctx->buf[3] = 0x10325476;
174174
ctx->bits[0] = 0;
175175
--- src/md5.c
+++ src/md5.c
@@ -164,11 +164,11 @@
164 /*
165 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
166 * initialization constants.
167 */
168 static void MD5Init(MD5Context *ctx){
169 ctx->isInit = 1;
170 ctx->buf[0] = 0x67452301;
171 ctx->buf[1] = 0xefcdab89;
172 ctx->buf[2] = 0x98badcfe;
173 ctx->buf[3] = 0x10325476;
174 ctx->bits[0] = 0;
175
--- src/md5.c
+++ src/md5.c
@@ -164,11 +164,11 @@
164 /*
165 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
166 * initialization constants.
167 */
168 static void MD5Init(MD5Context *ctx){
169 ctx->isInit = 1;
170 ctx->buf[0] = 0x67452301;
171 ctx->buf[1] = 0xefcdab89;
172 ctx->buf[2] = 0x98badcfe;
173 ctx->buf[3] = 0x10325476;
174 ctx->bits[0] = 0;
175
+2 -2
--- src/schema.c
+++ src/schema.c
@@ -435,12 +435,12 @@
435435
#if INTERFACE
436436
# define TAG_BGCOLOR 1 /* Set the background color for display */
437437
# define TAG_COMMENT 2 /* The check-in comment */
438438
# define TAG_USER 3 /* User who made a checking */
439439
# define TAG_DATE 4 /* The date of a check-in */
440
-# define TAG_HIDDEN 5 /* Do not display or sync */
441
-# define TAG_PRIVATE 6 /* Display but do not sync */
440
+# define TAG_HIDDEN 5 /* Do not display in timeline */
441
+# define TAG_PRIVATE 6 /* Do not sync */
442442
# define TAG_CLUSTER 7 /* A cluster */
443443
# define TAG_BRANCH 8 /* Value is name of the current branch */
444444
# define TAG_CLOSED 9 /* Do not display this check-in as a leaf */
445445
# define TAG_PARENT 10 /* Change to parentage on a checkin */
446446
#endif
447447
--- src/schema.c
+++ src/schema.c
@@ -435,12 +435,12 @@
435 #if INTERFACE
436 # define TAG_BGCOLOR 1 /* Set the background color for display */
437 # define TAG_COMMENT 2 /* The check-in comment */
438 # define TAG_USER 3 /* User who made a checking */
439 # define TAG_DATE 4 /* The date of a check-in */
440 # define TAG_HIDDEN 5 /* Do not display or sync */
441 # define TAG_PRIVATE 6 /* Display but do not sync */
442 # define TAG_CLUSTER 7 /* A cluster */
443 # define TAG_BRANCH 8 /* Value is name of the current branch */
444 # define TAG_CLOSED 9 /* Do not display this check-in as a leaf */
445 # define TAG_PARENT 10 /* Change to parentage on a checkin */
446 #endif
447
--- src/schema.c
+++ src/schema.c
@@ -435,12 +435,12 @@
435 #if INTERFACE
436 # define TAG_BGCOLOR 1 /* Set the background color for display */
437 # define TAG_COMMENT 2 /* The check-in comment */
438 # define TAG_USER 3 /* User who made a checking */
439 # define TAG_DATE 4 /* The date of a check-in */
440 # define TAG_HIDDEN 5 /* Do not display in timeline */
441 # define TAG_PRIVATE 6 /* Do not sync */
442 # define TAG_CLUSTER 7 /* A cluster */
443 # define TAG_BRANCH 8 /* Value is name of the current branch */
444 # define TAG_CLOSED 9 /* Do not display this check-in as a leaf */
445 # define TAG_PARENT 10 /* Change to parentage on a checkin */
446 #endif
447
+1 -1
--- src/setup.c
+++ src/setup.c
@@ -1211,11 +1211,11 @@
12111211
@ and time is shown on every timeline entry (using the CSS class "timelineTime").</p>
12121212
12131213
@ <hr />
12141214
onoff_attribute("Show version differences by default",
12151215
"show-version-diffs", "vdiff", 0, 0);
1216
- @ <p>On the version-information pages linked from the timeline can either
1216
+ @ <p>The version-information pages linked from the timeline can either
12171217
@ show complete diffs of all file changes, or can just list the names of
12181218
@ the files that have changed. Users can get to either page by
12191219
@ clicking. This setting selects the default.</p>
12201220
12211221
@ <hr />
12221222
--- src/setup.c
+++ src/setup.c
@@ -1211,11 +1211,11 @@
1211 @ and time is shown on every timeline entry (using the CSS class "timelineTime").</p>
1212
1213 @ <hr />
1214 onoff_attribute("Show version differences by default",
1215 "show-version-diffs", "vdiff", 0, 0);
1216 @ <p>On the version-information pages linked from the timeline can either
1217 @ show complete diffs of all file changes, or can just list the names of
1218 @ the files that have changed. Users can get to either page by
1219 @ clicking. This setting selects the default.</p>
1220
1221 @ <hr />
1222
--- src/setup.c
+++ src/setup.c
@@ -1211,11 +1211,11 @@
1211 @ and time is shown on every timeline entry (using the CSS class "timelineTime").</p>
1212
1213 @ <hr />
1214 onoff_attribute("Show version differences by default",
1215 "show-version-diffs", "vdiff", 0, 0);
1216 @ <p>The version-information pages linked from the timeline can either
1217 @ show complete diffs of all file changes, or can just list the names of
1218 @ the files that have changed. Users can get to either page by
1219 @ clicking. This setting selects the default.</p>
1220
1221 @ <hr />
1222
+13 -13
--- src/sha1.c
+++ src/sha1.c
@@ -161,20 +161,20 @@
161161
){
162162
unsigned int i, j;
163163
164164
j = context->count[0];
165165
if ((context->count[0] += len << 3) < j)
166
- context->count[1] += (len>>29)+1;
166
+ context->count[1] += (len>>29)+1;
167167
j = (j >> 3) & 63;
168168
if ((j + len) > 63) {
169
- (void)memcpy(&context->buffer[j], data, (i = 64-j));
170
- SHA1Transform(context->state, context->buffer);
171
- for ( ; i + 63 < len; i += 64)
172
- SHA1Transform(context->state, &data[i]);
173
- j = 0;
169
+ (void)memcpy(&context->buffer[j], data, (i = 64-j));
170
+ SHA1Transform(context->state, context->buffer);
171
+ for ( ; i + 63 < len; i += 64)
172
+ SHA1Transform(context->state, &data[i]);
173
+ j = 0;
174174
} else {
175
- i = 0;
175
+ i = 0;
176176
}
177177
(void)memcpy(&context->buffer[j], &data[i], len - i);
178178
}
179179
180180
@@ -184,22 +184,22 @@
184184
static void SHA1Final(SHA1Context *context, unsigned char digest[20]){
185185
unsigned int i;
186186
unsigned char finalcount[8];
187187
188188
for (i = 0; i < 8; i++) {
189
- finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
190
- >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
189
+ finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
190
+ >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
191191
}
192192
SHA1Update(context, (const unsigned char *)"\200", 1);
193193
while ((context->count[0] & 504) != 448)
194
- SHA1Update(context, (const unsigned char *)"\0", 1);
194
+ SHA1Update(context, (const unsigned char *)"\0", 1);
195195
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
196196
197197
if (digest) {
198
- for (i = 0; i < 20; i++)
199
- digest[i] = (unsigned char)
200
- ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
198
+ for (i = 0; i < 20; i++)
199
+ digest[i] = (unsigned char)
200
+ ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
201201
}
202202
}
203203
204204
205205
/*
206206
--- src/sha1.c
+++ src/sha1.c
@@ -161,20 +161,20 @@
161 ){
162 unsigned int i, j;
163
164 j = context->count[0];
165 if ((context->count[0] += len << 3) < j)
166 context->count[1] += (len>>29)+1;
167 j = (j >> 3) & 63;
168 if ((j + len) > 63) {
169 (void)memcpy(&context->buffer[j], data, (i = 64-j));
170 SHA1Transform(context->state, context->buffer);
171 for ( ; i + 63 < len; i += 64)
172 SHA1Transform(context->state, &data[i]);
173 j = 0;
174 } else {
175 i = 0;
176 }
177 (void)memcpy(&context->buffer[j], &data[i], len - i);
178 }
179
180
@@ -184,22 +184,22 @@
184 static void SHA1Final(SHA1Context *context, unsigned char digest[20]){
185 unsigned int i;
186 unsigned char finalcount[8];
187
188 for (i = 0; i < 8; i++) {
189 finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
190 >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
191 }
192 SHA1Update(context, (const unsigned char *)"\200", 1);
193 while ((context->count[0] & 504) != 448)
194 SHA1Update(context, (const unsigned char *)"\0", 1);
195 SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
196
197 if (digest) {
198 for (i = 0; i < 20; i++)
199 digest[i] = (unsigned char)
200 ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
201 }
202 }
203
204
205 /*
206
--- src/sha1.c
+++ src/sha1.c
@@ -161,20 +161,20 @@
161 ){
162 unsigned int i, j;
163
164 j = context->count[0];
165 if ((context->count[0] += len << 3) < j)
166 context->count[1] += (len>>29)+1;
167 j = (j >> 3) & 63;
168 if ((j + len) > 63) {
169 (void)memcpy(&context->buffer[j], data, (i = 64-j));
170 SHA1Transform(context->state, context->buffer);
171 for ( ; i + 63 < len; i += 64)
172 SHA1Transform(context->state, &data[i]);
173 j = 0;
174 } else {
175 i = 0;
176 }
177 (void)memcpy(&context->buffer[j], &data[i], len - i);
178 }
179
180
@@ -184,22 +184,22 @@
184 static void SHA1Final(SHA1Context *context, unsigned char digest[20]){
185 unsigned int i;
186 unsigned char finalcount[8];
187
188 for (i = 0; i < 8; i++) {
189 finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
190 >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
191 }
192 SHA1Update(context, (const unsigned char *)"\200", 1);
193 while ((context->count[0] & 504) != 448)
194 SHA1Update(context, (const unsigned char *)"\0", 1);
195 SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
196
197 if (digest) {
198 for (i = 0; i < 20; i++)
199 digest[i] = (unsigned char)
200 ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
201 }
202 }
203
204
205 /*
206
+114 -3
--- src/shell.c
+++ src/shell.c
@@ -462,10 +462,13 @@
462462
const char *zDbFilename; /* name of the database file */
463463
char *zFreeOnClose; /* Filename to free when closing */
464464
const char *zVfs; /* Name of VFS to use */
465465
sqlite3_stmt *pStmt; /* Current statement if any. */
466466
FILE *pLog; /* Write log output here */
467
+ int *aiIndent; /* Array of indents used in MODE_Explain */
468
+ int nIndent; /* Size of array aiIndent[] */
469
+ int iIndent; /* Index of current op in aiIndent[] */
467470
};
468471
469472
/*
470473
** These are the allowed modes.
471474
*/
@@ -763,13 +766,18 @@
763766
if( i<ArraySize(p->actualWidth) ){
764767
w = p->actualWidth[i];
765768
}else{
766769
w = 10;
767770
}
768
- if( p->mode==MODE_Explain && azArg[i] &&
769
- strlen30(azArg[i])>w ){
771
+ if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
770772
w = strlen30(azArg[i]);
773
+ }
774
+ if( i==1 && p->aiIndent && p->pStmt ){
775
+ if( p->iIndent<p->nIndent ){
776
+ fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
777
+ }
778
+ p->iIndent++;
771779
}
772780
if( w<0 ){
773781
fprintf(p->out,"%*.*s%s",-w,-w,
774782
azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
775783
}else{
@@ -1138,10 +1146,105 @@
11381146
fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
11391147
}
11401148
11411149
return 0;
11421150
}
1151
+
1152
+/*
1153
+** Parameter azArray points to a zero-terminated array of strings. zStr
1154
+** points to a single nul-terminated string. Return non-zero if zStr
1155
+** is equal, according to strcmp(), to any of the strings in the array.
1156
+** Otherwise, return zero.
1157
+*/
1158
+static int str_in_array(const char *zStr, const char **azArray){
1159
+ int i;
1160
+ for(i=0; azArray[i]; i++){
1161
+ if( 0==strcmp(zStr, azArray[i]) ) return 1;
1162
+ }
1163
+ return 0;
1164
+}
1165
+
1166
+/*
1167
+** If compiled statement pSql appears to be an EXPLAIN statement, allocate
1168
+** and populate the callback_data.aiIndent[] array with the number of
1169
+** spaces each opcode should be indented before it is output.
1170
+**
1171
+** The indenting rules are:
1172
+**
1173
+** * For each "Next", "Prev", "VNext" or "VPrev" instruction, indent
1174
+** all opcodes that occur between the p2 jump destination and the opcode
1175
+** itself by 2 spaces.
1176
+**
1177
+** * For each "Goto", if the jump destination is earlier in the program
1178
+** and ends on one of:
1179
+** Yield SeekGt SeekLt RowSetRead
1180
+** then indent all opcodes between the earlier instruction
1181
+** and "Goto" by 2 spaces.
1182
+*/
1183
+static void explain_data_prepare(struct callback_data *p, sqlite3_stmt *pSql){
1184
+ const char *zSql; /* The text of the SQL statement */
1185
+ const char *z; /* Used to check if this is an EXPLAIN */
1186
+ int *abYield = 0; /* True if op is an OP_Yield */
1187
+ int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1188
+ int iOp; /* Index of operation in p->aiIndent[] */
1189
+
1190
+ const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext", 0 };
1191
+ const char *azYield[] = { "Yield", "SeekLt", "SeekGt", "RowSetRead", 0 };
1192
+ const char *azGoto[] = { "Goto", 0 };
1193
+
1194
+ /* Try to figure out if this is really an EXPLAIN statement. If this
1195
+ ** cannot be verified, return early. */
1196
+ zSql = sqlite3_sql(pSql);
1197
+ if( zSql==0 ) return;
1198
+ for(z=zSql; *z==' ' || *z=='\t' || *z=='\n' || *z=='\f' || *z=='\r'; z++);
1199
+ if( sqlite3_strnicmp(z, "explain", 7) ) return;
1200
+
1201
+ for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
1202
+ int i;
1203
+ int iAddr = sqlite3_column_int(pSql, 0);
1204
+ const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
1205
+
1206
+ /* Set p2 to the P2 field of the current opcode. Then, assuming that
1207
+ ** p2 is an instruction address, set variable p2op to the index of that
1208
+ ** instruction in the aiIndent[] array. p2 and p2op may be different if
1209
+ ** the current instruction is part of a sub-program generated by an
1210
+ ** SQL trigger or foreign key. */
1211
+ int p2 = sqlite3_column_int(pSql, 3);
1212
+ int p2op = (p2 + (iOp-iAddr));
1213
+
1214
+ /* Grow the p->aiIndent array as required */
1215
+ if( iOp>=nAlloc ){
1216
+ nAlloc += 100;
1217
+ p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int));
1218
+ abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int));
1219
+ }
1220
+ abYield[iOp] = str_in_array(zOp, azYield);
1221
+ p->aiIndent[iOp] = 0;
1222
+ p->nIndent = iOp+1;
1223
+
1224
+ if( str_in_array(zOp, azNext) ){
1225
+ for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1226
+ }
1227
+ if( str_in_array(zOp, azGoto) && p2op<p->nIndent && abYield[p2op] ){
1228
+ for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1229
+ }
1230
+ }
1231
+
1232
+ p->iIndent = 0;
1233
+ sqlite3_free(abYield);
1234
+ sqlite3_reset(pSql);
1235
+}
1236
+
1237
+/*
1238
+** Free the array allocated by explain_data_prepare().
1239
+*/
1240
+static void explain_data_delete(struct callback_data *p){
1241
+ sqlite3_free(p->aiIndent);
1242
+ p->aiIndent = 0;
1243
+ p->nIndent = 0;
1244
+ p->iIndent = 0;
1245
+}
11431246
11441247
/*
11451248
** Execute a statement or set of statements. Print
11461249
** any result rows/columns depending on the current mode
11471250
** set via the supplied callback.
@@ -1199,10 +1302,16 @@
11991302
sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
12001303
if( zExplain && zExplain[0] ){
12011304
fprintf(pArg->out, "%s", zExplain);
12021305
}
12031306
}
1307
+
1308
+ /* If the shell is currently in ".explain" mode, gather the extra
1309
+ ** data required to add indents to the output.*/
1310
+ if( pArg && pArg->mode==MODE_Explain ){
1311
+ explain_data_prepare(pArg, pStmt);
1312
+ }
12041313
12051314
/* perform the first step. this will tell us if we
12061315
** have a result set or not and how wide it is.
12071316
*/
12081317
rc = sqlite3_step(pStmt);
@@ -1256,10 +1365,12 @@
12561365
do{
12571366
rc = sqlite3_step(pStmt);
12581367
} while( rc == SQLITE_ROW );
12591368
}
12601369
}
1370
+
1371
+ explain_data_delete(pArg);
12611372
12621373
/* print usage stats if stats on */
12631374
if( pArg && pArg->statsOn ){
12641375
display_stats(db, pArg, 0);
12651376
}
@@ -1983,11 +2094,11 @@
19832094
** did an .explain followed by a .width, .mode or .header
19842095
** command.
19852096
*/
19862097
p->mode = MODE_Explain;
19872098
p->showHeader = 1;
1988
- memset(p->colWidth,0,ArraySize(p->colWidth));
2099
+ memset(p->colWidth,0,sizeof(p->colWidth));
19892100
p->colWidth[0] = 4; /* addr */
19902101
p->colWidth[1] = 13; /* opcode */
19912102
p->colWidth[2] = 4; /* P1 */
19922103
p->colWidth[3] = 4; /* P2 */
19932104
p->colWidth[4] = 4; /* P3 */
19942105
--- src/shell.c
+++ src/shell.c
@@ -462,10 +462,13 @@
462 const char *zDbFilename; /* name of the database file */
463 char *zFreeOnClose; /* Filename to free when closing */
464 const char *zVfs; /* Name of VFS to use */
465 sqlite3_stmt *pStmt; /* Current statement if any. */
466 FILE *pLog; /* Write log output here */
 
 
 
467 };
468
469 /*
470 ** These are the allowed modes.
471 */
@@ -763,13 +766,18 @@
763 if( i<ArraySize(p->actualWidth) ){
764 w = p->actualWidth[i];
765 }else{
766 w = 10;
767 }
768 if( p->mode==MODE_Explain && azArg[i] &&
769 strlen30(azArg[i])>w ){
770 w = strlen30(azArg[i]);
 
 
 
 
 
 
771 }
772 if( w<0 ){
773 fprintf(p->out,"%*.*s%s",-w,-w,
774 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
775 }else{
@@ -1138,10 +1146,105 @@
1138 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1139 }
1140
1141 return 0;
1142 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1143
1144 /*
1145 ** Execute a statement or set of statements. Print
1146 ** any result rows/columns depending on the current mode
1147 ** set via the supplied callback.
@@ -1199,10 +1302,16 @@
1199 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1200 if( zExplain && zExplain[0] ){
1201 fprintf(pArg->out, "%s", zExplain);
1202 }
1203 }
 
 
 
 
 
 
1204
1205 /* perform the first step. this will tell us if we
1206 ** have a result set or not and how wide it is.
1207 */
1208 rc = sqlite3_step(pStmt);
@@ -1256,10 +1365,12 @@
1256 do{
1257 rc = sqlite3_step(pStmt);
1258 } while( rc == SQLITE_ROW );
1259 }
1260 }
 
 
1261
1262 /* print usage stats if stats on */
1263 if( pArg && pArg->statsOn ){
1264 display_stats(db, pArg, 0);
1265 }
@@ -1983,11 +2094,11 @@
1983 ** did an .explain followed by a .width, .mode or .header
1984 ** command.
1985 */
1986 p->mode = MODE_Explain;
1987 p->showHeader = 1;
1988 memset(p->colWidth,0,ArraySize(p->colWidth));
1989 p->colWidth[0] = 4; /* addr */
1990 p->colWidth[1] = 13; /* opcode */
1991 p->colWidth[2] = 4; /* P1 */
1992 p->colWidth[3] = 4; /* P2 */
1993 p->colWidth[4] = 4; /* P3 */
1994
--- src/shell.c
+++ src/shell.c
@@ -462,10 +462,13 @@
462 const char *zDbFilename; /* name of the database file */
463 char *zFreeOnClose; /* Filename to free when closing */
464 const char *zVfs; /* Name of VFS to use */
465 sqlite3_stmt *pStmt; /* Current statement if any. */
466 FILE *pLog; /* Write log output here */
467 int *aiIndent; /* Array of indents used in MODE_Explain */
468 int nIndent; /* Size of array aiIndent[] */
469 int iIndent; /* Index of current op in aiIndent[] */
470 };
471
472 /*
473 ** These are the allowed modes.
474 */
@@ -763,13 +766,18 @@
766 if( i<ArraySize(p->actualWidth) ){
767 w = p->actualWidth[i];
768 }else{
769 w = 10;
770 }
771 if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
 
772 w = strlen30(azArg[i]);
773 }
774 if( i==1 && p->aiIndent && p->pStmt ){
775 if( p->iIndent<p->nIndent ){
776 fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
777 }
778 p->iIndent++;
779 }
780 if( w<0 ){
781 fprintf(p->out,"%*.*s%s",-w,-w,
782 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
783 }else{
@@ -1138,10 +1146,105 @@
1146 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1147 }
1148
1149 return 0;
1150 }
1151
1152 /*
1153 ** Parameter azArray points to a zero-terminated array of strings. zStr
1154 ** points to a single nul-terminated string. Return non-zero if zStr
1155 ** is equal, according to strcmp(), to any of the strings in the array.
1156 ** Otherwise, return zero.
1157 */
1158 static int str_in_array(const char *zStr, const char **azArray){
1159 int i;
1160 for(i=0; azArray[i]; i++){
1161 if( 0==strcmp(zStr, azArray[i]) ) return 1;
1162 }
1163 return 0;
1164 }
1165
1166 /*
1167 ** If compiled statement pSql appears to be an EXPLAIN statement, allocate
1168 ** and populate the callback_data.aiIndent[] array with the number of
1169 ** spaces each opcode should be indented before it is output.
1170 **
1171 ** The indenting rules are:
1172 **
1173 ** * For each "Next", "Prev", "VNext" or "VPrev" instruction, indent
1174 ** all opcodes that occur between the p2 jump destination and the opcode
1175 ** itself by 2 spaces.
1176 **
1177 ** * For each "Goto", if the jump destination is earlier in the program
1178 ** and ends on one of:
1179 ** Yield SeekGt SeekLt RowSetRead
1180 ** then indent all opcodes between the earlier instruction
1181 ** and "Goto" by 2 spaces.
1182 */
1183 static void explain_data_prepare(struct callback_data *p, sqlite3_stmt *pSql){
1184 const char *zSql; /* The text of the SQL statement */
1185 const char *z; /* Used to check if this is an EXPLAIN */
1186 int *abYield = 0; /* True if op is an OP_Yield */
1187 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1188 int iOp; /* Index of operation in p->aiIndent[] */
1189
1190 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext", 0 };
1191 const char *azYield[] = { "Yield", "SeekLt", "SeekGt", "RowSetRead", 0 };
1192 const char *azGoto[] = { "Goto", 0 };
1193
1194 /* Try to figure out if this is really an EXPLAIN statement. If this
1195 ** cannot be verified, return early. */
1196 zSql = sqlite3_sql(pSql);
1197 if( zSql==0 ) return;
1198 for(z=zSql; *z==' ' || *z=='\t' || *z=='\n' || *z=='\f' || *z=='\r'; z++);
1199 if( sqlite3_strnicmp(z, "explain", 7) ) return;
1200
1201 for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
1202 int i;
1203 int iAddr = sqlite3_column_int(pSql, 0);
1204 const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
1205
1206 /* Set p2 to the P2 field of the current opcode. Then, assuming that
1207 ** p2 is an instruction address, set variable p2op to the index of that
1208 ** instruction in the aiIndent[] array. p2 and p2op may be different if
1209 ** the current instruction is part of a sub-program generated by an
1210 ** SQL trigger or foreign key. */
1211 int p2 = sqlite3_column_int(pSql, 3);
1212 int p2op = (p2 + (iOp-iAddr));
1213
1214 /* Grow the p->aiIndent array as required */
1215 if( iOp>=nAlloc ){
1216 nAlloc += 100;
1217 p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int));
1218 abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int));
1219 }
1220 abYield[iOp] = str_in_array(zOp, azYield);
1221 p->aiIndent[iOp] = 0;
1222 p->nIndent = iOp+1;
1223
1224 if( str_in_array(zOp, azNext) ){
1225 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1226 }
1227 if( str_in_array(zOp, azGoto) && p2op<p->nIndent && abYield[p2op] ){
1228 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1229 }
1230 }
1231
1232 p->iIndent = 0;
1233 sqlite3_free(abYield);
1234 sqlite3_reset(pSql);
1235 }
1236
1237 /*
1238 ** Free the array allocated by explain_data_prepare().
1239 */
1240 static void explain_data_delete(struct callback_data *p){
1241 sqlite3_free(p->aiIndent);
1242 p->aiIndent = 0;
1243 p->nIndent = 0;
1244 p->iIndent = 0;
1245 }
1246
1247 /*
1248 ** Execute a statement or set of statements. Print
1249 ** any result rows/columns depending on the current mode
1250 ** set via the supplied callback.
@@ -1199,10 +1302,16 @@
1302 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1303 if( zExplain && zExplain[0] ){
1304 fprintf(pArg->out, "%s", zExplain);
1305 }
1306 }
1307
1308 /* If the shell is currently in ".explain" mode, gather the extra
1309 ** data required to add indents to the output.*/
1310 if( pArg && pArg->mode==MODE_Explain ){
1311 explain_data_prepare(pArg, pStmt);
1312 }
1313
1314 /* perform the first step. this will tell us if we
1315 ** have a result set or not and how wide it is.
1316 */
1317 rc = sqlite3_step(pStmt);
@@ -1256,10 +1365,12 @@
1365 do{
1366 rc = sqlite3_step(pStmt);
1367 } while( rc == SQLITE_ROW );
1368 }
1369 }
1370
1371 explain_data_delete(pArg);
1372
1373 /* print usage stats if stats on */
1374 if( pArg && pArg->statsOn ){
1375 display_stats(db, pArg, 0);
1376 }
@@ -1983,11 +2094,11 @@
2094 ** did an .explain followed by a .width, .mode or .header
2095 ** command.
2096 */
2097 p->mode = MODE_Explain;
2098 p->showHeader = 1;
2099 memset(p->colWidth,0,sizeof(p->colWidth));
2100 p->colWidth[0] = 4; /* addr */
2101 p->colWidth[1] = 13; /* opcode */
2102 p->colWidth[2] = 4; /* P1 */
2103 p->colWidth[3] = 4; /* P2 */
2104 p->colWidth[4] = 4; /* P3 */
2105
--- src/skins.c
+++ src/skins.c
@@ -117,10 +117,17 @@
117117
@ }
118118
@ /* Hyperlink colors */
119119
@ div.content a { color: #604000; }
120120
@ div.content a:link { color: #604000;}
121121
@ div.content a:visited { color: #600000; }
122
+@
123
+@ /* <verbatim> blocks */
124
+@ pre.verbatim {
125
+@ background-color: #ffffff;
126
+@ padding: 0.5em;
127
+@ white-space: pre-wrap;
128
+@ }
122129
@
123130
@ /* Some pages have section dividers */
124131
@ div.section {
125132
@ margin-bottom: 0px;
126133
@ margin-top: 1em;
127134
--- src/skins.c
+++ src/skins.c
@@ -117,10 +117,17 @@
117 @ }
118 @ /* Hyperlink colors */
119 @ div.content a { color: #604000; }
120 @ div.content a:link { color: #604000;}
121 @ div.content a:visited { color: #600000; }
 
 
 
 
 
 
 
122 @
123 @ /* Some pages have section dividers */
124 @ div.section {
125 @ margin-bottom: 0px;
126 @ margin-top: 1em;
127
--- src/skins.c
+++ src/skins.c
@@ -117,10 +117,17 @@
117 @ }
118 @ /* Hyperlink colors */
119 @ div.content a { color: #604000; }
120 @ div.content a:link { color: #604000;}
121 @ div.content a:visited { color: #600000; }
122 @
123 @ /* <verbatim> blocks */
124 @ pre.verbatim {
125 @ background-color: #ffffff;
126 @ padding: 0.5em;
127 @ white-space: pre-wrap;
128 @ }
129 @
130 @ /* Some pages have section dividers */
131 @ div.section {
132 @ margin-bottom: 0px;
133 @ margin-top: 1em;
134
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -123,11 +123,10 @@
123123
re_add_sql_func(db);
124124
g.repositoryOpen = 1;
125125
g.db = db;
126126
return SQLITE_OK;
127127
}
128
-
129128
130129
/*
131130
** COMMAND: sqlite3
132131
**
133132
** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
134133
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -123,11 +123,10 @@
123 re_add_sql_func(db);
124 g.repositoryOpen = 1;
125 g.db = db;
126 return SQLITE_OK;
127 }
128
129
130 /*
131 ** COMMAND: sqlite3
132 **
133 ** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
134
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -123,11 +123,10 @@
123 re_add_sql_func(db);
124 g.repositoryOpen = 1;
125 g.db = db;
126 return SQLITE_OK;
127 }
 
128
129 /*
130 ** COMMAND: sqlite3
131 **
132 ** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
133
+3120 -3402
--- 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.2. By combining all the individual C code files into this
3
+** version 3.8.3. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -133,13 +133,13 @@
133133
**
134134
** See also: [sqlite3_libversion()],
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138
-#define SQLITE_VERSION "3.8.2"
139
-#define SQLITE_VERSION_NUMBER 3008002
140
-#define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
138
+#define SQLITE_VERSION "3.8.3"
139
+#define SQLITE_VERSION_NUMBER 3008003
140
+#define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -396,11 +396,11 @@
396396
** Restrictions:
397397
**
398398
** <ul>
399399
** <li> The application must insure that the 1st parameter to sqlite3_exec()
400400
** is a valid and open [database connection].
401
-** <li> The application must not close [database connection] specified by
401
+** <li> The application must not close the [database connection] specified by
402402
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
403403
** <li> The application must not modify the SQL statement text passed into
404404
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
405405
** </ul>
406406
*/
@@ -473,11 +473,11 @@
473473
** about errors. The extended result codes are enabled or disabled
474474
** on a per database connection basis using the
475475
** [sqlite3_extended_result_codes()] API.
476476
**
477477
** Some of the available extended result codes are listed here.
478
-** One may expect the number of extended result codes will be expand
478
+** One may expect the number of extended result codes will increase
479479
** over time. Software that uses extended result codes should expect
480480
** to see new result codes in future releases of SQLite.
481481
**
482482
** The SQLITE_OK result code will never be extended. It will always
483483
** be exactly zero.
@@ -517,10 +517,11 @@
517517
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518518
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519519
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520520
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521521
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
522
+#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
522523
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
523524
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
524525
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
525526
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
526527
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -584,11 +585,12 @@
584585
** information is written to disk in the same order as calls
585586
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
586587
** after reboot following a crash or power loss, the only bytes in a
587588
** file that were written at the application level might have changed
588589
** and that adjacent bytes, even bytes within the same sector are
589
-** guaranteed to be unchanged.
590
+** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
591
+** flag indicate that a file cannot be deleted when open.
590592
*/
591593
#define SQLITE_IOCAP_ATOMIC 0x00000001
592594
#define SQLITE_IOCAP_ATOMIC512 0x00000002
593595
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
594596
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -947,10 +949,16 @@
947949
** This file control is used by some VFS activity tracing [shims].
948950
** The argument is a zero-terminated string. Higher layers in the
949951
** SQLite stack may generate instances of this file control if
950952
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
951953
**
954
+** <li>[[SQLITE_FCNTL_HAS_MOVED]]
955
+** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
956
+** pointer to an integer and it writes a boolean into that integer depending
957
+** on whether or not the file has been renamed, moved, or deleted since it
958
+** was first opened.
959
+**
952960
** </ul>
953961
*/
954962
#define SQLITE_FCNTL_LOCKSTATE 1
955963
#define SQLITE_GET_LOCKPROXYFILE 2
956964
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -967,10 +975,11 @@
967975
#define SQLITE_FCNTL_PRAGMA 14
968976
#define SQLITE_FCNTL_BUSYHANDLER 15
969977
#define SQLITE_FCNTL_TEMPFILENAME 16
970978
#define SQLITE_FCNTL_MMAP_SIZE 18
971979
#define SQLITE_FCNTL_TRACE 19
980
+#define SQLITE_FCNTL_HAS_MOVED 20
972981
973982
/*
974983
** CAPI3REF: Mutex Handle
975984
**
976985
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1411,11 +1420,11 @@
14111420
** of 8. Some allocators round up to a larger multiple or to a power of 2.
14121421
** Every memory allocation request coming in through [sqlite3_malloc()]
14131422
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
14141423
** that causes the corresponding memory allocation to fail.
14151424
**
1416
-** The xInit method initializes the memory allocator. (For example,
1425
+** The xInit method initializes the memory allocator. For example,
14171426
** it might allocate any require mutexes or initialize internal data
14181427
** structures. The xShutdown method is invoked (indirectly) by
14191428
** [sqlite3_shutdown()] and should deallocate any resources acquired
14201429
** by xInit. The pAppData pointer is used as the only parameter to
14211430
** xInit and xShutdown.
@@ -1713,10 +1722,17 @@
17131722
** cannot be changed at run-time. Nor may the maximum allowed mmap size
17141723
** exceed the compile-time maximum mmap size set by the
17151724
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
17161725
** ^If either argument to this option is negative, then that argument is
17171726
** changed to its compile-time default.
1727
+**
1728
+** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1729
+** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1730
+** <dd>^This option is only available if SQLite is compiled for Windows
1731
+** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1732
+** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1733
+** that specifies the maximum size of the created heap.
17181734
** </dl>
17191735
*/
17201736
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17211737
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
17221738
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1737,10 +1753,11 @@
17371753
#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
17381754
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
17391755
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
17401756
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
17411757
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1758
+#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
17421759
17431760
/*
17441761
** CAPI3REF: Database Connection Configuration Options
17451762
**
17461763
** These constants are the available integer configuration options that
@@ -3137,11 +3154,10 @@
31373154
** to the [sqlite3_bind_text | bindings] of that [parameter].
31383155
** ^The specific value of WHERE-clause [parameter] might influence the
31393156
** choice of query plan if the parameter is the left-hand side of a [LIKE]
31403157
** or [GLOB] operator or if the parameter is compared to an indexed column
31413158
** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3142
-** the
31433159
** </li>
31443160
** </ol>
31453161
*/
31463162
SQLITE_API int sqlite3_prepare(
31473163
sqlite3 *db, /* Database handle */
@@ -3799,23 +3815,23 @@
37993815
** <table border="1">
38003816
** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
38013817
**
38023818
** <tr><td> NULL <td> INTEGER <td> Result is 0
38033819
** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3804
-** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
3805
-** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
3820
+** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
3821
+** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
38063822
** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
38073823
** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
38083824
** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3809
-** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
3825
+** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
38103826
** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3811
-** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
3812
-** <tr><td> TEXT <td> INTEGER <td> Use atoi()
3813
-** <tr><td> TEXT <td> FLOAT <td> Use atof()
3827
+** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
3828
+** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
3829
+** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
38143830
** <tr><td> TEXT <td> BLOB <td> No change
3815
-** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
3816
-** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
3831
+** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
3832
+** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
38173833
** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
38183834
** </table>
38193835
** </blockquote>)^
38203836
**
38213837
** The table above makes reference to standard C library functions atoi()
@@ -3867,11 +3883,11 @@
38673883
**
38683884
** ^The pointers returned are valid until a type conversion occurs as
38693885
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
38703886
** [sqlite3_finalize()] is called. ^The memory space used to hold strings
38713887
** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3872
-** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3888
+** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
38733889
** [sqlite3_free()].
38743890
**
38753891
** ^(If a memory allocation error occurs during the evaluation of any
38763892
** of these routines, a default value is returned. The default value
38773893
** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4945,12 +4961,12 @@
49454961
/*
49464962
** CAPI3REF: Free Memory Used By A Database Connection
49474963
**
49484964
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
49494965
** memory as possible from database connection D. Unlike the
4950
-** [sqlite3_release_memory()] interface, this interface is effect even
4951
-** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4966
+** [sqlite3_release_memory()] interface, this interface is in effect even
4967
+** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
49524968
** omitted.
49534969
**
49544970
** See also: [sqlite3_release_memory()]
49554971
*/
49564972
SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -5321,14 +5337,26 @@
53215337
**
53225338
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
53235339
** the correct order to satisfy the ORDER BY clause so that no separate
53245340
** sorting step is required.
53255341
**
5326
-** ^The estimatedCost value is an estimate of the cost of doing the
5327
-** particular lookup. A full scan of a table with N entries should have
5328
-** a cost of N. A binary search of a table of N entries should have a
5329
-** cost of approximately log(N).
5342
+** ^The estimatedCost value is an estimate of the cost of a particular
5343
+** strategy. A cost of N indicates that the cost of the strategy is similar
5344
+** to a linear scan of an SQLite table with N rows. A cost of log(N)
5345
+** indicates that the expense of the operation is similar to that of a
5346
+** binary search on a unique indexed field of an SQLite table with N rows.
5347
+**
5348
+** ^The estimatedRows value is an estimate of the number of rows that
5349
+** will be returned by the strategy.
5350
+**
5351
+** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5352
+** structure for SQLite version 3.8.2. If a virtual table extension is
5353
+** used with an SQLite version earlier than 3.8.2, the results of attempting
5354
+** to read or write the estimatedRows field are undefined (but are likely
5355
+** to included crashing the application). The estimatedRows field should
5356
+** therefore only be used if [sqlite3_libversion_number()] returns a
5357
+** value greater than or equal to 3008002.
53305358
*/
53315359
struct sqlite3_index_info {
53325360
/* Inputs */
53335361
int nConstraint; /* Number of entries in aConstraint */
53345362
struct sqlite3_index_constraint {
@@ -5349,11 +5377,13 @@
53495377
} *aConstraintUsage;
53505378
int idxNum; /* Number used to identify the index */
53515379
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
53525380
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
53535381
int orderByConsumed; /* True if output is already ordered */
5354
- double estimatedCost; /* Estimated cost of using this index */
5382
+ double estimatedCost; /* Estimated cost of using this index */
5383
+ /* Fields below are only available in SQLite 3.8.2 and later */
5384
+ sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
53555385
};
53565386
53575387
/*
53585388
** CAPI3REF: Virtual Table Constraint Operator Codes
53595389
**
@@ -6079,11 +6109,12 @@
60796109
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
60806110
#define SQLITE_TESTCTRL_ISKEYWORD 16
60816111
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
60826112
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
60836113
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6084
-#define SQLITE_TESTCTRL_LAST 19
6114
+#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6115
+#define SQLITE_TESTCTRL_LAST 20
60856116
60866117
/*
60876118
** CAPI3REF: SQLite Runtime Status
60886119
**
60896120
** ^This interface is used to retrieve runtime status information
@@ -8127,13 +8158,12 @@
81278158
#define TK_UNCLOSED_STRING 151
81288159
#define TK_FUNCTION 152
81298160
#define TK_COLUMN 153
81308161
#define TK_AGG_FUNCTION 154
81318162
#define TK_AGG_COLUMN 155
8132
-#define TK_CONST_FUNC 156
8133
-#define TK_UMINUS 157
8134
-#define TK_UPLUS 158
8163
+#define TK_UMINUS 156
8164
+#define TK_UPLUS 157
81358165
81368166
/************** End of parse.h ***********************************************/
81378167
/************** Continuing where we left off in sqliteInt.h ******************/
81388168
#include <stdio.h>
81398169
#include <stdlib.h>
@@ -8765,12 +8795,12 @@
87658795
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
87668796
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
87678797
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
87688798
SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
87698799
SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8770
-SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
8771
-SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
8800
+SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
8801
+SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
87728802
SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
87738803
SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
87748804
SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
87758805
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
87768806
@@ -9008,155 +9038,157 @@
90089038
#define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
90099039
#define OP_Savepoint 2
90109040
#define OP_AutoCommit 3
90119041
#define OP_Transaction 4
90129042
#define OP_SorterNext 5
9013
-#define OP_Prev 6
9014
-#define OP_Next 7
9015
-#define OP_AggStep 8 /* synopsis: accum=r[P3] step(r[P2@P5]) */
9016
-#define OP_Checkpoint 9
9017
-#define OP_JournalMode 10
9018
-#define OP_Vacuum 11
9019
-#define OP_VFilter 12 /* synopsis: iPlan=r[P3] zPlan='P4' */
9020
-#define OP_VUpdate 13 /* synopsis: data=r[P3@P2] */
9021
-#define OP_Goto 14
9022
-#define OP_Gosub 15
9023
-#define OP_Return 16
9024
-#define OP_Yield 17
9025
-#define OP_HaltIfNull 18 /* synopsis: if r[P3] null then halt */
9043
+#define OP_PrevIfOpen 6
9044
+#define OP_NextIfOpen 7
9045
+#define OP_Prev 8
9046
+#define OP_Next 9
9047
+#define OP_AggStep 10 /* synopsis: accum=r[P3] step(r[P2@P5]) */
9048
+#define OP_Checkpoint 11
9049
+#define OP_JournalMode 12
9050
+#define OP_Vacuum 13
9051
+#define OP_VFilter 14 /* synopsis: iPlan=r[P3] zPlan='P4' */
9052
+#define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
9053
+#define OP_Goto 16
9054
+#define OP_Gosub 17
9055
+#define OP_Return 18
90269056
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9027
-#define OP_Halt 20
9028
-#define OP_Integer 21 /* synopsis: r[P2]=P1 */
9029
-#define OP_Int64 22 /* synopsis: r[P2]=P4 */
9030
-#define OP_String 23 /* synopsis: r[P2]='P4' (len=P1) */
9031
-#define OP_Null 24 /* synopsis: r[P2..P3]=NULL */
9032
-#define OP_Blob 25 /* synopsis: r[P2]=P4 (len=P1) */
9033
-#define OP_Variable 26 /* synopsis: r[P2]=parameter(P1,P4) */
9034
-#define OP_Move 27 /* synopsis: r[P2@P3]=r[P1@P3] */
9035
-#define OP_Copy 28 /* synopsis: r[P2@P3]=r[P1@P3] */
9036
-#define OP_SCopy 29 /* synopsis: r[P2]=r[P1] */
9037
-#define OP_ResultRow 30 /* synopsis: output=r[P1@P2] */
9038
-#define OP_CollSeq 31
9039
-#define OP_AddImm 32 /* synopsis: r[P1]=r[P1]+P2 */
9040
-#define OP_MustBeInt 33
9041
-#define OP_RealAffinity 34
9042
-#define OP_Permutation 35
9043
-#define OP_Compare 36
9044
-#define OP_Jump 37
9045
-#define OP_Once 38
9046
-#define OP_If 39
9047
-#define OP_IfNot 40
9048
-#define OP_Column 41 /* synopsis: r[P3]=PX */
9049
-#define OP_Affinity 42 /* synopsis: affinity(r[P1@P2]) */
9050
-#define OP_MakeRecord 43 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9051
-#define OP_Count 44 /* synopsis: r[P2]=count() */
9052
-#define OP_ReadCookie 45
9053
-#define OP_SetCookie 46
9054
-#define OP_VerifyCookie 47
9055
-#define OP_OpenRead 48 /* synopsis: root=P2 iDb=P3 */
9056
-#define OP_OpenWrite 49 /* synopsis: root=P2 iDb=P3 */
9057
-#define OP_OpenAutoindex 50 /* synopsis: nColumn=P2 */
9058
-#define OP_OpenEphemeral 51 /* synopsis: nColumn=P2 */
9059
-#define OP_SorterOpen 52
9060
-#define OP_OpenPseudo 53 /* synopsis: content in r[P2@P3] */
9061
-#define OP_Close 54
9062
-#define OP_SeekLt 55 /* synopsis: key=r[P3@P4] */
9063
-#define OP_SeekLe 56 /* synopsis: key=r[P3@P4] */
9064
-#define OP_SeekGe 57 /* synopsis: key=r[P3@P4] */
9065
-#define OP_SeekGt 58 /* synopsis: key=r[P3@P4] */
9066
-#define OP_Seek 59 /* synopsis: intkey=r[P2] */
9067
-#define OP_NoConflict 60 /* synopsis: key=r[P3@P4] */
9068
-#define OP_NotFound 61 /* synopsis: key=r[P3@P4] */
9069
-#define OP_Found 62 /* synopsis: key=r[P3@P4] */
9070
-#define OP_NotExists 63 /* synopsis: intkey=r[P3] */
9071
-#define OP_Sequence 64 /* synopsis: r[P2]=rowid */
9072
-#define OP_NewRowid 65 /* synopsis: r[P2]=rowid */
9073
-#define OP_Insert 66 /* synopsis: intkey=r[P3] data=r[P2] */
9074
-#define OP_InsertInt 67 /* synopsis: intkey=P3 data=r[P2] */
9075
-#define OP_Delete 68
9057
+#define OP_Yield 20
9058
+#define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */
9059
+#define OP_Halt 22
9060
+#define OP_Integer 23 /* synopsis: r[P2]=P1 */
9061
+#define OP_Int64 24 /* synopsis: r[P2]=P4 */
9062
+#define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9063
+#define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9064
+#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9065
+#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9066
+#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9067
+#define OP_Copy 30 /* synopsis: r[P2@P3]=r[P1@P3] */
9068
+#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9069
+#define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9070
+#define OP_CollSeq 33
9071
+#define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9072
+#define OP_MustBeInt 35
9073
+#define OP_RealAffinity 36
9074
+#define OP_Permutation 37
9075
+#define OP_Compare 38
9076
+#define OP_Jump 39
9077
+#define OP_Once 40
9078
+#define OP_If 41
9079
+#define OP_IfNot 42
9080
+#define OP_Column 43 /* synopsis: r[P3]=PX */
9081
+#define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */
9082
+#define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9083
+#define OP_Count 46 /* synopsis: r[P2]=count() */
9084
+#define OP_ReadCookie 47
9085
+#define OP_SetCookie 48
9086
+#define OP_VerifyCookie 49
9087
+#define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9088
+#define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9089
+#define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9090
+#define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9091
+#define OP_SorterOpen 54
9092
+#define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9093
+#define OP_Close 56
9094
+#define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9095
+#define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9096
+#define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9097
+#define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9098
+#define OP_Seek 61 /* synopsis: intkey=r[P2] */
9099
+#define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9100
+#define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9101
+#define OP_Found 64 /* synopsis: key=r[P3@P4] */
9102
+#define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9103
+#define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9104
+#define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9105
+#define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
90769106
#define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
90779107
#define OP_And 70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9078
-#define OP_ResetCount 71
9079
-#define OP_SorterCompare 72 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9080
-#define OP_SorterData 73 /* synopsis: r[P2]=data */
9108
+#define OP_InsertInt 71 /* synopsis: intkey=P3 data=r[P2] */
9109
+#define OP_Delete 72
9110
+#define OP_ResetCount 73
90819111
#define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
90829112
#define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
90839113
#define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
90849114
#define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
90859115
#define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
90869116
#define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9087
-#define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P3 */
9117
+#define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
90889118
#define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9089
-#define OP_RowKey 82 /* synopsis: r[P2]=key */
9119
+#define OP_SorterCompare 82 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
90909120
#define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
90919121
#define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
90929122
#define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
90939123
#define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
90949124
#define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
90959125
#define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
90969126
#define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9097
-#define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P1]/r[P2] */
9098
-#define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P1]%r[P2] */
9127
+#define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9128
+#define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
90999129
#define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9100
-#define OP_RowData 93 /* synopsis: r[P2]=data */
9130
+#define OP_SorterData 93 /* synopsis: r[P2]=data */
91019131
#define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
91029132
#define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
9103
-#define OP_Rowid 96 /* synopsis: r[P2]=rowid */
9104
-#define OP_NullRow 97
9105
-#define OP_Last 98
9106
-#define OP_SorterSort 99
9107
-#define OP_Sort 100
9108
-#define OP_Rewind 101
9109
-#define OP_SorterInsert 102
9110
-#define OP_IdxInsert 103 /* synopsis: key=r[P2] */
9111
-#define OP_IdxDelete 104 /* synopsis: key=r[P2@P3] */
9112
-#define OP_IdxRowid 105 /* synopsis: r[P2]=rowid */
9113
-#define OP_IdxLT 106 /* synopsis: key=r[P3@P4] */
9114
-#define OP_IdxGE 107 /* synopsis: key=r[P3@P4] */
9115
-#define OP_Destroy 108
9116
-#define OP_Clear 109
9117
-#define OP_CreateIndex 110 /* synopsis: r[P2]=root iDb=P1 */
9118
-#define OP_CreateTable 111 /* synopsis: r[P2]=root iDb=P1 */
9119
-#define OP_ParseSchema 112
9120
-#define OP_LoadAnalysis 113
9121
-#define OP_DropTable 114
9122
-#define OP_DropIndex 115
9123
-#define OP_DropTrigger 116
9124
-#define OP_IntegrityCk 117
9125
-#define OP_RowSetAdd 118 /* synopsis: rowset(P1)=r[P2] */
9126
-#define OP_RowSetRead 119 /* synopsis: r[P3]=rowset(P1) */
9127
-#define OP_RowSetTest 120 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9128
-#define OP_Program 121
9129
-#define OP_Param 122
9130
-#define OP_FkCounter 123 /* synopsis: fkctr[P1]+=P2 */
9131
-#define OP_FkIfZero 124 /* synopsis: if fkctr[P1]==0 goto P2 */
9132
-#define OP_MemMax 125 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9133
-#define OP_IfPos 126 /* synopsis: if r[P1]>0 goto P2 */
9134
-#define OP_IfNeg 127 /* synopsis: if r[P1]<0 goto P2 */
9135
-#define OP_IfZero 128 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9136
-#define OP_AggFinal 129 /* synopsis: accum=r[P1] N=P2 */
9137
-#define OP_IncrVacuum 130
9133
+#define OP_RowKey 96 /* synopsis: r[P2]=key */
9134
+#define OP_RowData 97 /* synopsis: r[P2]=data */
9135
+#define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9136
+#define OP_NullRow 99
9137
+#define OP_Last 100
9138
+#define OP_SorterSort 101
9139
+#define OP_Sort 102
9140
+#define OP_Rewind 103
9141
+#define OP_SorterInsert 104
9142
+#define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9143
+#define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9144
+#define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9145
+#define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9146
+#define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9147
+#define OP_Destroy 110
9148
+#define OP_Clear 111
9149
+#define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9150
+#define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9151
+#define OP_ParseSchema 114
9152
+#define OP_LoadAnalysis 115
9153
+#define OP_DropTable 116
9154
+#define OP_DropIndex 117
9155
+#define OP_DropTrigger 118
9156
+#define OP_IntegrityCk 119
9157
+#define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9158
+#define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9159
+#define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9160
+#define OP_Program 123
9161
+#define OP_Param 124
9162
+#define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9163
+#define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9164
+#define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9165
+#define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9166
+#define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9167
+#define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
91389168
#define OP_Real 131 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9139
-#define OP_Expire 132
9140
-#define OP_TableLock 133 /* synopsis: iDb=P1 root=P2 write=P3 */
9141
-#define OP_VBegin 134
9142
-#define OP_VCreate 135
9143
-#define OP_VDestroy 136
9144
-#define OP_VOpen 137
9145
-#define OP_VColumn 138 /* synopsis: r[P3]=vcolumn(P2) */
9146
-#define OP_VNext 139
9147
-#define OP_VRename 140
9148
-#define OP_Pagecount 141
9169
+#define OP_AggFinal 132 /* synopsis: accum=r[P1] N=P2 */
9170
+#define OP_IncrVacuum 133
9171
+#define OP_Expire 134
9172
+#define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9173
+#define OP_VBegin 136
9174
+#define OP_VCreate 137
9175
+#define OP_VDestroy 138
9176
+#define OP_VOpen 139
9177
+#define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9178
+#define OP_VNext 141
91499179
#define OP_ToText 142 /* same as TK_TO_TEXT */
91509180
#define OP_ToBlob 143 /* same as TK_TO_BLOB */
91519181
#define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
91529182
#define OP_ToInt 145 /* same as TK_TO_INT */
91539183
#define OP_ToReal 146 /* same as TK_TO_REAL */
9154
-#define OP_MaxPgcnt 147
9155
-#define OP_Trace 148
9156
-#define OP_Noop 149
9157
-#define OP_Explain 150
9184
+#define OP_VRename 147
9185
+#define OP_Pagecount 148
9186
+#define OP_MaxPgcnt 149
9187
+#define OP_Trace 150
9188
+#define OP_Noop 151
9189
+#define OP_Explain 152
91589190
91599191
91609192
/* Properties such as "out2" or "jump" that are specified in
91619193
** comments following the "case" for each opcode in the vdbe.c
91629194
** are encoded into bitvectors as follows:
@@ -9168,28 +9200,29 @@
91689200
#define OPFLG_IN3 0x0010 /* in3: P3 is an input */
91699201
#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
91709202
#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
91719203
#define OPFLG_INITIALIZER {\
91729204
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9173
-/* 8 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01,\
9174
-/* 16 */ 0x04, 0x04, 0x10, 0x24, 0x00, 0x02, 0x02, 0x02,\
9175
-/* 24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00,\
9176
-/* 32 */ 0x04, 0x05, 0x04, 0x00, 0x00, 0x01, 0x01, 0x05,\
9177
-/* 40 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00,\
9178
-/* 48 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,\
9179
-/* 56 */ 0x11, 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11,\
9180
-/* 64 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c, 0x4c, 0x00,\
9205
+/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9206
+/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9207
+/* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9208
+/* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9209
+/* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9210
+/* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9211
+/* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9212
+/* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c, 0x4c, 0x00,\
91819213
/* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
91829214
/* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
91839215
/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
9184
-/* 96 */ 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08,\
9185
-/* 104 */ 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02, 0x02,\
9186
-/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
9187
-/* 120 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05, 0x05,\
9188
-/* 128 */ 0x05, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,\
9189
-/* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x04, 0x04,\
9190
-/* 144 */ 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,}
9216
+/* 96 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9217
+/* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9218
+/* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9219
+/* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9220
+/* 128 */ 0x05, 0x05, 0x05, 0x02, 0x00, 0x01, 0x00, 0x00,\
9221
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x04,\
9222
+/* 144 */ 0x04, 0x04, 0x04, 0x00, 0x02, 0x02, 0x00, 0x00,\
9223
+/* 152 */ 0x00,}
91919224
91929225
/************** End of opcodes.h *********************************************/
91939226
/************** Continuing where we left off in vdbe.h ***********************/
91949227
91959228
/*
@@ -9223,11 +9256,10 @@
92239256
SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
92249257
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
92259258
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
92269259
#ifdef SQLITE_DEBUG
92279260
SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
9228
-SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
92299261
#endif
92309262
SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
92319263
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
92329264
SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
92339265
SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
@@ -10290,10 +10322,11 @@
1029010322
#define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
1029110323
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
1029210324
#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
1029310325
#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
1029410326
#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
10327
+#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
1029510328
1029610329
1029710330
/*
1029810331
** Bits of the sqlite3.dbOptFlags field that are used by the
1029910332
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -10323,10 +10356,17 @@
1032310356
#else
1032410357
#define OptimizationDisabled(db, mask) 0
1032510358
#define OptimizationEnabled(db, mask) 1
1032610359
#endif
1032710360
10361
+/*
10362
+** Return true if it OK to factor constant expressions into the initialization
10363
+** code. The argument is a Parse object for the code generator.
10364
+*/
10365
+#define ConstFactorOk(P) \
10366
+ ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))
10367
+
1032810368
/*
1032910369
** Possible values for the sqlite.magic field.
1033010370
** The numbers are obtained at random and have no special meaning, other
1033110371
** than being distinct from one another.
1033210372
*/
@@ -10389,10 +10429,11 @@
1038910429
#define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
1039010430
#define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
1039110431
#define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
1039210432
#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
1039310433
#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10434
+#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
1039410435
1039510436
/*
1039610437
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1039710438
** used to create the initializers for the FuncDef structures.
1039810439
**
@@ -10401,10 +10442,13 @@
1040110442
** implemented by C function xFunc that accepts nArg arguments. The
1040210443
** value passed as iArg is cast to a (void*) and made available
1040310444
** as the user-data (sqlite3_user_data()) for the function. If
1040410445
** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
1040510446
**
10447
+** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
10448
+** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
10449
+**
1040610450
** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
1040710451
** Used to create an aggregate function definition implemented by
1040810452
** the C functions xStep and xFinal. The first four parameters
1040910453
** are interpreted in the same way as the first 4 parameters to
1041010454
** FUNCTION().
@@ -10416,20 +10460,24 @@
1041610460
** available as the function user-data (sqlite3_user_data()). The
1041710461
** FuncDef.flags variable is set to the value passed as the flags
1041810462
** parameter.
1041910463
*/
1042010464
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
10465
+ {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10466
+ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10467
+#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1042110468
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1042210469
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1042310470
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10424
- {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
10471
+ {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
1042510472
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1042610473
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10427
- {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10474
+ {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1042810475
pArg, 0, xFunc, 0, 0, #zName, 0, 0}
1042910476
#define LIKEFUNC(zName, nArg, arg, flags) \
10430
- {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10477
+ {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
10478
+ (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
1043110479
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
1043210480
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
1043310481
SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
1043410482
1043510483
/*
@@ -11075,20 +11123,21 @@
1107511123
#define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
1107611124
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
1107711125
#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
1107811126
#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
1107911127
#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11080
-#define EP_FixedDest 0x000200 /* Result needed in a specific register */
11128
+ /* unused 0x000200 */
1108111129
#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
1108211130
#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
1108311131
#define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
1108411132
#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
1108511133
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
1108611134
#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
1108711135
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
1108811136
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
1108911137
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11138
+#define EP_Constant 0x080000 /* Node is a constant */
1109011139
1109111140
/*
1109211141
** These macros can be used to test, set, or clear bits in the
1109311142
** Expr.flags field.
1109411143
*/
@@ -11146,12 +11195,18 @@
1114611195
char *zName; /* Token associated with this expression */
1114711196
char *zSpan; /* Original text of the expression */
1114811197
u8 sortOrder; /* 1 for DESC or 0 for ASC */
1114911198
unsigned done :1; /* A flag to indicate when processing is finished */
1115011199
unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11151
- u16 iOrderByCol; /* For ORDER BY, column number in result set */
11152
- u16 iAlias; /* Index into Parse.aAlias[] for zName */
11200
+ unsigned reusable :1; /* Constant expression is reusable */
11201
+ union {
11202
+ struct {
11203
+ u16 iOrderByCol; /* For ORDER BY, column number in result set */
11204
+ u16 iAlias; /* Index into Parse.aAlias[] for zName */
11205
+ } x;
11206
+ int iConstExprReg; /* Register in which Expr value is cached */
11207
+ } u;
1115311208
} *a; /* Alloc a power of two greater or equal to nExpr */
1115411209
};
1115511210
1115611211
/*
1115711212
** An instance of this structure is used by the parser to record both
@@ -11524,10 +11579,11 @@
1152411579
u8 tempReg; /* iReg is a temp register that needs to be freed */
1152511580
int iLevel; /* Nesting level */
1152611581
int iReg; /* Reg with value of this column. 0 means none. */
1152711582
int lru; /* Least recently used entry has the smallest value */
1152811583
} aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11584
+ ExprList *pConstExpr;/* Constant expressions */
1152911585
yDbMask writeMask; /* Start a write transaction on these databases */
1153011586
yDbMask cookieMask; /* Bitmask of schema verified databases */
1153111587
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
1153211588
int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
1153311589
int regRowid; /* Register holding rowid of CREATE TABLE entry */
@@ -11761,10 +11817,11 @@
1176111817
int bCoreMutex; /* True to enable core mutexing */
1176211818
int bFullMutex; /* True to enable full mutexing */
1176311819
int bOpenUri; /* True to interpret filenames as URIs */
1176411820
int bUseCis; /* Use covering indices for full-scans */
1176511821
int mxStrlen; /* Maximum string length */
11822
+ int neverCorrupt; /* Database is always well-formed */
1176611823
int szLookaside; /* Default lookaside buffer size */
1176711824
int nLookaside; /* Default lookaside buffer count */
1176811825
sqlite3_mem_methods m; /* Low-level memory allocation interface */
1176911826
sqlite3_mutex_methods mutex; /* Low-level mutex interface */
1177011827
sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */
@@ -11797,10 +11854,28 @@
1179711854
void(*xSqllog)(void*,sqlite3*,const char*, int);
1179811855
void *pSqllogArg;
1179911856
#endif
1180011857
};
1180111858
11859
+/*
11860
+** This macro is used inside of assert() statements to indicate that
11861
+** the assert is only valid on a well-formed database. Instead of:
11862
+**
11863
+** assert( X );
11864
+**
11865
+** One writes:
11866
+**
11867
+** assert( X || CORRUPT_DB );
11868
+**
11869
+** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate
11870
+** that the database is definitely corrupt, only that it might be corrupt.
11871
+** For most test cases, CORRUPT_DB is set to false using a special
11872
+** sqlite3_test_control(). This enables assert() statements to prove
11873
+** things that are always true for well-formed databases.
11874
+*/
11875
+#define CORRUPT_DB (sqlite3Config.neverCorrupt==0)
11876
+
1180211877
/*
1180311878
** Context pointer passed down through the tree-walk.
1180411879
*/
1180511880
struct Walker {
1180611881
int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
@@ -12134,15 +12209,17 @@
1213412209
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
1213512210
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
1213612211
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
1213712212
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
1213812213
SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12214
+SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
1213912215
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1214012216
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
1214112217
SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12142
-SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
12143
-SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
12218
+SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
12219
+#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
12220
+#define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
1214412221
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1214512222
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
1214612223
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
1214712224
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
1214812225
SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
@@ -12183,11 +12260,11 @@
1218312260
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
1218412261
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
1218512262
SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
1218612263
u8,u8,int,int*);
1218712264
SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12188
-SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, int*, int*);
12265
+SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*);
1218912266
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
1219012267
SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
1219112268
SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
1219212269
SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
1219312270
SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
@@ -12424,10 +12501,11 @@
1242412501
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1242512502
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1242612503
1242712504
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
1242812505
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
12506
+SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
1242912507
SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
1243012508
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
1243112509
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
1243212510
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
1243312511
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -12505,10 +12583,11 @@
1250512583
SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
1250612584
SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
1250712585
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
1250812586
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
1250912587
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
12588
+SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
1251012589
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
1251112590
SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
1251212591
SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
1251312592
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
1251412593
SQLITE_PRIVATE const char *sqlite3JournalModename(int);
@@ -12821,10 +12900,11 @@
1282112900
1, /* bCoreMutex */
1282212901
SQLITE_THREADSAFE==1, /* bFullMutex */
1282312902
SQLITE_USE_URI, /* bOpenUri */
1282412903
SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
1282512904
0x7ffffffe, /* mxStrlen */
12905
+ 0, /* neverCorrupt */
1282612906
128, /* szLookaside */
1282712907
500, /* nLookaside */
1282812908
{0,0,0,0,0,0,0,0}, /* m */
1282912909
{0,0,0,0,0,0,0,0,0}, /* mutex */
1283012910
{0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
@@ -12855,11 +12935,10 @@
1285512935
#ifdef SQLITE_ENABLE_SQLLOG
1285612936
0, /* xSqllog */
1285712937
0 /* pSqllogArg */
1285812938
#endif
1285912939
};
12860
-
1286112940
1286212941
/*
1286312942
** Hash table for global functions - functions common to all
1286412943
** database connections. After initialization, this table is
1286512944
** read-only.
@@ -13253,10 +13332,13 @@
1325313332
"SMALL_STACK",
1325413333
#endif
1325513334
#ifdef SQLITE_SOUNDEX
1325613335
"SOUNDEX",
1325713336
#endif
13337
+#ifdef SQLITE_SYSTEM_MALLOC
13338
+ "SYSTEM_MALLOC",
13339
+#endif
1325813340
#ifdef SQLITE_TCL
1325913341
"TCL",
1326013342
#endif
1326113343
#if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
1326213344
"TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
@@ -13267,10 +13349,13 @@
1326713349
#if defined(SQLITE_THREADSAFE)
1326813350
"THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
1326913351
#endif
1327013352
#ifdef SQLITE_USE_ALLOCA
1327113353
"USE_ALLOCA",
13354
+#endif
13355
+#ifdef SQLITE_WIN32_MALLOC
13356
+ "WIN32_MALLOC",
1327213357
#endif
1327313358
#ifdef SQLITE_ZERO_MALLOC
1327413359
"ZERO_MALLOC"
1327513360
#endif
1327613361
};
@@ -13367,11 +13452,11 @@
1336713452
typedef struct VdbeOp Op;
1336813453
1336913454
/*
1337013455
** Boolean values
1337113456
*/
13372
-typedef unsigned char Bool;
13457
+typedef unsigned Bool;
1337313458
1337413459
/* Opaque type used by code in vdbesort.c */
1337513460
typedef struct VdbeSorter VdbeSorter;
1337613461
1337713462
/* Opaque type used by the explainer */
@@ -13384,42 +13469,39 @@
1338413469
** A cursor is a pointer into a single BTree within a database file.
1338513470
** The cursor can seek to a BTree entry with a particular key, or
1338613471
** loop over all entries of the Btree. You can also insert new BTree
1338713472
** entries or retrieve the key or data from the entry that the cursor
1338813473
** is currently pointing to.
13474
+**
13475
+** Cursors can also point to virtual tables, sorters, or "pseudo-tables".
13476
+** A pseudo-table is a single-row table implemented by registers.
1338913477
**
1339013478
** Every cursor that the virtual machine has open is represented by an
1339113479
** instance of the following structure.
1339213480
*/
1339313481
struct VdbeCursor {
1339413482
BtCursor *pCursor; /* The cursor structure of the backend */
1339513483
Btree *pBt; /* Separate file holding temporary table */
1339613484
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
13397
- int iDb; /* Index of cursor database in db->aDb[] (or -1) */
13485
+ int seekResult; /* Result of previous sqlite3BtreeMoveto() */
1339813486
int pseudoTableReg; /* Register holding pseudotable content. */
13399
- int nField; /* Number of fields in the header */
13400
- Bool zeroed; /* True if zeroed out and ready for reuse */
13401
- Bool rowidIsValid; /* True if lastRowid is valid */
13402
- Bool atFirst; /* True if pointing to first entry */
13403
- Bool useRandomRowid; /* Generate new record numbers semi-randomly */
13404
- Bool nullRow; /* True if pointing to a row with no data */
13405
- Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13406
- Bool isTable; /* True if a table requiring integer keys */
13407
- Bool isIndex; /* True if an index containing keys only - no data */
13408
- Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
13409
- Bool isSorter; /* True if a new-style sorter */
13410
- Bool multiPseudo; /* Multi-register pseudo-cursor */
13487
+ i16 nField; /* Number of fields in the header */
13488
+ u16 nHdrParsed; /* Number of header fields parsed so far */
13489
+ i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
13490
+ u8 nullRow; /* True if pointing to a row with no data */
13491
+ u8 rowidIsValid; /* True if lastRowid is valid */
13492
+ u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13493
+ Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13494
+ Bool isTable:1; /* True if a table requiring integer keys */
13495
+ Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13496
+ Bool multiPseudo:1; /* Multi-register pseudo-cursor */
1341113497
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13412
- const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
1341313498
i64 seqCount; /* Sequence counter */
1341413499
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13415
- i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
13500
+ i64 lastRowid; /* Rowid being deleted by OP_Delete */
1341613501
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
1341713502
13418
- /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */
13419
- int seekResult;
13420
-
1342113503
/* Cached information about the header for the data record that the
1342213504
** cursor is currently pointing to. Only valid if cacheStatus matches
1342313505
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
1342413506
** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
1342513507
** the cache is out of date.
@@ -13426,14 +13508,18 @@
1342613508
**
1342713509
** aRow might point to (ephemeral) data for the current row, or it might
1342813510
** be NULL.
1342913511
*/
1343013512
u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
13431
- int payloadSize; /* Total number of bytes in the record */
13432
- u32 *aType; /* Type values for all entries in the record */
13433
- u32 *aOffset; /* Cached offsets to the start of each columns data */
13434
- u8 *aRow; /* Data for the current row, if all on one page */
13513
+ u32 payloadSize; /* Total number of bytes in the record */
13514
+ u32 szRow; /* Byte available in aRow */
13515
+ u32 iHdrOffset; /* Offset to next unparsed byte of the header */
13516
+ const u8 *aRow; /* Data for the current row, if all on one page */
13517
+ u32 aType[1]; /* Type values for all entries in the record */
13518
+ /* 2*nField extra array elements allocated for aType[], beyond the one
13519
+ ** static element declared in the structure. nField total array slots for
13520
+ ** aType[] and nField+1 array slots for aOffset[] */
1343513521
};
1343613522
typedef struct VdbeCursor VdbeCursor;
1343713523
1343813524
/*
1343913525
** When a sub-program is executed (OP_Program), a structure of this type
@@ -13686,13 +13772,10 @@
1368613772
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1368713773
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
1368813774
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
1368913775
char *zSql; /* Text of the SQL statement that generated this */
1369013776
void *pFree; /* Free this when deleting the vdbe */
13691
-#ifdef SQLITE_DEBUG
13692
- FILE *trace; /* Write an execution trace here, if not NULL */
13693
-#endif
1369413777
#ifdef SQLITE_ENABLE_TREE_EXPLAIN
1369513778
Explain *pExplain; /* The explainer */
1369613779
char *zExplain; /* Explanation of data structures */
1369713780
#endif
1369813781
VdbeFrame *pFrame; /* Parent frame */
@@ -13722,11 +13805,11 @@
1372213805
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
1372313806
SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
1372413807
#endif
1372513808
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
1372613809
SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13727
-SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13810
+SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
1372813811
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
1372913812
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1373013813
1373113814
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
1373213815
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -13757,11 +13840,11 @@
1375713840
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
1375813841
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
1375913842
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
1376013843
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
1376113844
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
13762
-SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
13845
+SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
1376313846
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
1376413847
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
1376513848
#define VdbeMemRelease(X) \
1376613849
if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
1376713850
sqlite3VdbeMemReleaseExternal(X);
@@ -15782,20 +15865,10 @@
1578215865
** This version of the memory allocator is the default. It is
1578315866
** used when no other memory allocator is specified using compile-time
1578415867
** macros.
1578515868
*/
1578615869
#ifdef SQLITE_SYSTEM_MALLOC
15787
-
15788
-/*
15789
-** The MSVCRT has malloc_usable_size() but it is called _msize().
15790
-** The use of _msize() is automatic, but can be disabled by compiling
15791
-** with -DSQLITE_WITHOUT_MSIZE
15792
-*/
15793
-#if defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15794
-# define SQLITE_MALLOCSIZE _msize
15795
-#endif
15796
-
1579715870
#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
1579815871
1579915872
/*
1580015873
** Use the zone allocator available on apple products unless the
1580115874
** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
@@ -15814,25 +15887,51 @@
1581415887
1581515888
/*
1581615889
** Use standard C library malloc and free on non-Apple systems.
1581715890
** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
1581815891
*/
15819
-#define SQLITE_MALLOC(x) malloc(x)
15820
-#define SQLITE_FREE(x) free(x)
15821
-#define SQLITE_REALLOC(x,y) realloc((x),(y))
15822
-
15823
-#if (defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)) \
15824
- || (defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE))
15825
-# include <malloc.h> /* Needed for malloc_usable_size on linux */
15826
-#endif
15827
-#ifdef HAVE_MALLOC_USABLE_SIZE
15828
-# ifndef SQLITE_MALLOCSIZE
15829
-# define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15830
-# endif
15831
-#else
15832
-# undef SQLITE_MALLOCSIZE
15833
-#endif
15892
+#define SQLITE_MALLOC(x) malloc(x)
15893
+#define SQLITE_FREE(x) free(x)
15894
+#define SQLITE_REALLOC(x,y) realloc((x),(y))
15895
+
15896
+/*
15897
+** The malloc.h header file is needed for malloc_usable_size() function
15898
+** on some systems (e.g. Linux).
15899
+*/
15900
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
15901
+# define SQLITE_USE_MALLOC_H
15902
+# define SQLITE_USE_MALLOC_USABLE_SIZE
15903
+/*
15904
+** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
15905
+** use of _msize() is automatic, but can be disabled by compiling with
15906
+** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
15907
+** the malloc.h header file.
15908
+*/
15909
+#elif defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15910
+# define SQLITE_USE_MALLOC_H
15911
+# define SQLITE_USE_MSIZE
15912
+#endif
15913
+
15914
+/*
15915
+** Include the malloc.h header file, if necessary. Also set define macro
15916
+** SQLITE_MALLOCSIZE to the appropriate function name, which is _msize()
15917
+** for MSVC and malloc_usable_size() for most other systems (e.g. Linux).
15918
+** The memory size function can always be overridden manually by defining
15919
+** the macro SQLITE_MALLOCSIZE to the desired function name.
15920
+*/
15921
+#if defined(SQLITE_USE_MALLOC_H)
15922
+# include <malloc.h>
15923
+# if defined(SQLITE_USE_MALLOC_USABLE_SIZE)
15924
+# if !defined(SQLITE_MALLOCSIZE)
15925
+# define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15926
+# endif
15927
+# elif defined(SQLITE_USE_MSIZE)
15928
+# if !defined(SQLITE_MALLOCSIZE)
15929
+# define SQLITE_MALLOCSIZE _msize
15930
+# endif
15931
+# endif
15932
+#endif /* defined(SQLITE_USE_MALLOC_H) */
1583415933
1583515934
#endif /* __APPLE__ or not __APPLE__ */
1583615935
1583715936
/*
1583815937
** Like malloc(), but remember the size of the allocation
@@ -17435,36 +17534,17 @@
1743517534
** works for chunks that are currently checked out.
1743617535
*/
1743717536
static int memsys5Size(void *p){
1743817537
int iSize = 0;
1743917538
if( p ){
17440
- int i = ((u8 *)p-mem5.zPool)/mem5.szAtom;
17539
+ int i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom);
1744117540
assert( i>=0 && i<mem5.nBlock );
1744217541
iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
1744317542
}
1744417543
return iSize;
1744517544
}
1744617545
17447
-/*
17448
-** Find the first entry on the freelist iLogsize. Unlink that
17449
-** entry and return its index.
17450
-*/
17451
-static int memsys5UnlinkFirst(int iLogsize){
17452
- int i;
17453
- int iFirst;
17454
-
17455
- assert( iLogsize>=0 && iLogsize<=LOGMAX );
17456
- i = iFirst = mem5.aiFreelist[iLogsize];
17457
- assert( iFirst>=0 );
17458
- while( i>0 ){
17459
- if( i<iFirst ) iFirst = i;
17460
- i = MEM5LINK(i)->next;
17461
- }
17462
- memsys5Unlink(iFirst, iLogsize);
17463
- return iFirst;
17464
-}
17465
-
1746617546
/*
1746717547
** Return a block of memory of at least nBytes in size.
1746817548
** Return NULL if unable. Return NULL if nBytes==0.
1746917549
**
1747017550
** The caller guarantees that nByte is positive.
@@ -17506,11 +17586,12 @@
1750617586
if( iBin>LOGMAX ){
1750717587
testcase( sqlite3GlobalConfig.xLog!=0 );
1750817588
sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes", nByte);
1750917589
return 0;
1751017590
}
17511
- i = memsys5UnlinkFirst(iBin);
17591
+ i = mem5.aiFreelist[iBin];
17592
+ memsys5Unlink(i, iBin);
1751217593
while( iBin>iLogsize ){
1751317594
int newSize;
1751417595
1751517596
iBin--;
1751617597
newSize = 1 << iBin;
@@ -17540,11 +17621,11 @@
1754017621
int iBlock;
1754117622
1754217623
/* Set iBlock to the index of the block pointed to by pOld in
1754317624
** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
1754417625
*/
17545
- iBlock = ((u8 *)pOld-mem5.zPool)/mem5.szAtom;
17626
+ iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom);
1754617627
1754717628
/* Check that the pointer pOld points to a valid, non-free block. */
1754817629
assert( iBlock>=0 && iBlock<mem5.nBlock );
1754917630
assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
1755017631
assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
@@ -19309,11 +19390,11 @@
1930919390
/*
1931019391
** TRUE if p is a lookaside memory allocation from db
1931119392
*/
1931219393
#ifndef SQLITE_OMIT_LOOKASIDE
1931319394
static int isLookaside(sqlite3 *db, void *p){
19314
- return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19395
+ return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
1931519396
}
1931619397
#else
1931719398
#define isLookaside(A,B) 0
1931819399
#endif
1931919400
@@ -19325,12 +19406,13 @@
1932519406
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1932619407
assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
1932719408
return sqlite3GlobalConfig.m.xSize(p);
1932819409
}
1932919410
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19330
- assert( db==0 || sqlite3_mutex_held(db->mutex) );
19331
- if( db && isLookaside(db, p) ){
19411
+ assert( db!=0 );
19412
+ assert( sqlite3_mutex_held(db->mutex) );
19413
+ if( isLookaside(db, p) ){
1933219414
return db->lookaside.sz;
1933319415
}else{
1933419416
assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
1933519417
assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
1933619418
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19808,10 +19890,18 @@
1980819890
}
1980919891
if( N>0 ){
1981019892
sqlite3StrAccumAppend(pAccum, zSpaces, N);
1981119893
}
1981219894
}
19895
+
19896
+/*
19897
+** Set the StrAccum object to an error mode.
19898
+*/
19899
+void setStrAccumError(StrAccum *p, u8 eError){
19900
+ p->accError = eError;
19901
+ p->nAlloc = 0;
19902
+}
1981319903
1981419904
/*
1981519905
** On machines with a small stack size, you can redefine the
1981619906
** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
1981719907
*/
@@ -20020,11 +20110,11 @@
2002020110
zOut = buf;
2002120111
}else{
2002220112
nOut = precision + 10;
2002320113
zOut = zExtra = sqlite3Malloc( nOut );
2002420114
if( zOut==0 ){
20025
- pAccum->accError = STRACCUM_NOMEM;
20115
+ setStrAccumError(pAccum, STRACCUM_NOMEM);
2002620116
return;
2002720117
}
2002820118
}
2002920119
bufpt = &zOut[nOut-1];
2003020120
if( xtype==etORDINAL ){
@@ -20132,11 +20222,11 @@
2013220222
e2 = exp;
2013320223
}
2013420224
if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
2013520225
bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
2013620226
if( bufpt==0 ){
20137
- pAccum->accError = STRACCUM_NOMEM;
20227
+ setStrAccumError(pAccum, STRACCUM_NOMEM);
2013820228
return;
2013920229
}
2014020230
}
2014120231
zOut = bufpt;
2014220232
nsd = 16 + flag_altform2*10;
@@ -20267,11 +20357,11 @@
2026720357
needQuote = !isnull && xtype==etSQLESCAPE2;
2026820358
n += i + 1 + needQuote*2;
2026920359
if( n>etBUFSIZE ){
2027020360
bufpt = zExtra = sqlite3Malloc( n );
2027120361
if( bufpt==0 ){
20272
- pAccum->accError = STRACCUM_NOMEM;
20362
+ setStrAccumError(pAccum, STRACCUM_NOMEM);
2027320363
return;
2027420364
}
2027520365
}else{
2027620366
bufpt = buf;
2027720367
}
@@ -20290,11 +20380,11 @@
2029020380
** if( precision>=0 && precision<length ) length = precision; */
2029120381
break;
2029220382
}
2029320383
case etTOKEN: {
2029420384
Token *pToken = va_arg(ap, Token*);
20295
- if( pToken ){
20385
+ if( pToken && pToken->n ){
2029620386
sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
2029720387
}
2029820388
length = width = 0;
2029920389
break;
2030020390
}
@@ -20302,14 +20392,14 @@
2030220392
SrcList *pSrc = va_arg(ap, SrcList*);
2030320393
int k = va_arg(ap, int);
2030420394
struct SrcList_item *pItem = &pSrc->a[k];
2030520395
assert( k>=0 && k<pSrc->nSrc );
2030620396
if( pItem->zDatabase ){
20307
- sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
20397
+ sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
2030820398
sqlite3StrAccumAppend(pAccum, ".", 1);
2030920399
}
20310
- sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
20400
+ sqlite3StrAccumAppendAll(pAccum, pItem->zName);
2031120401
length = width = 0;
2031220402
break;
2031320403
}
2031420404
default: {
2031520405
assert( xtype==etINVALID );
@@ -20344,36 +20434,34 @@
2034420434
2034520435
/*
2034620436
** Append N bytes of text from z to the StrAccum object.
2034720437
*/
2034820438
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20349
- assert( z!=0 || N==0 );
20350
- if( p->accError ){
20351
- testcase(p->accError==STRACCUM_TOOBIG);
20352
- testcase(p->accError==STRACCUM_NOMEM);
20353
- return;
20354
- }
20355
- assert( p->zText!=0 || p->nChar==0 );
20356
- if( N<=0 ){
20357
- if( N==0 || z[0]==0 ) return;
20358
- N = sqlite3Strlen30(z);
20359
- }
20439
+ assert( z!=0 );
20440
+ assert( p->zText!=0 || p->nChar==0 || p->accError );
20441
+ assert( N>=0 );
20442
+ assert( p->accError==0 || p->nAlloc==0 );
2036020443
if( p->nChar+N >= p->nAlloc ){
2036120444
char *zNew;
20445
+ if( p->accError ){
20446
+ testcase(p->accError==STRACCUM_TOOBIG);
20447
+ testcase(p->accError==STRACCUM_NOMEM);
20448
+ return;
20449
+ }
2036220450
if( !p->useMalloc ){
20363
- p->accError = STRACCUM_TOOBIG;
2036420451
N = p->nAlloc - p->nChar - 1;
20452
+ setStrAccumError(p, STRACCUM_TOOBIG);
2036520453
if( N<=0 ){
2036620454
return;
2036720455
}
2036820456
}else{
2036920457
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
2037020458
i64 szNew = p->nChar;
2037120459
szNew += N + 1;
2037220460
if( szNew > p->mxAlloc ){
2037320461
sqlite3StrAccumReset(p);
20374
- p->accError = STRACCUM_TOOBIG;
20462
+ setStrAccumError(p, STRACCUM_TOOBIG);
2037520463
return;
2037620464
}else{
2037720465
p->nAlloc = (int)szNew;
2037820466
}
2037920467
if( p->useMalloc==1 ){
@@ -20383,20 +20471,28 @@
2038320471
}
2038420472
if( zNew ){
2038520473
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2038620474
p->zText = zNew;
2038720475
}else{
20388
- p->accError = STRACCUM_NOMEM;
2038920476
sqlite3StrAccumReset(p);
20477
+ setStrAccumError(p, STRACCUM_NOMEM);
2039020478
return;
2039120479
}
2039220480
}
2039320481
}
2039420482
assert( p->zText );
2039520483
memcpy(&p->zText[p->nChar], z, N);
2039620484
p->nChar += N;
2039720485
}
20486
+
20487
+/*
20488
+** Append the complete text of zero-terminated string z[] to the p string.
20489
+*/
20490
+SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){
20491
+ sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z));
20492
+}
20493
+
2039820494
2039920495
/*
2040020496
** Finish off a string by making sure it is zero-terminated.
2040120497
** Return a pointer to the resulting string. Return a NULL
2040220498
** pointer if any kind of error was encountered.
@@ -20411,11 +20507,11 @@
2041120507
p->zText = sqlite3_malloc(p->nChar+1);
2041220508
}
2041320509
if( p->zText ){
2041420510
memcpy(p->zText, p->zBase, p->nChar+1);
2041520511
}else{
20416
- p->accError = STRACCUM_NOMEM;
20512
+ setStrAccumError(p, STRACCUM_NOMEM);
2041720513
}
2041820514
}
2041920515
}
2042020516
return p->zText;
2042120517
}
@@ -21748,16 +21844,16 @@
2174821844
** Convert zNum to a 64-bit signed integer.
2174921845
**
2175021846
** If the zNum value is representable as a 64-bit twos-complement
2175121847
** integer, then write that value into *pNum and return 0.
2175221848
**
21753
-** If zNum is exactly 9223372036854665808, return 2. This special
21754
-** case is broken out because while 9223372036854665808 cannot be a
21755
-** signed 64-bit integer, its negative -9223372036854665808 can be.
21849
+** If zNum is exactly 9223372036854775808, return 2. This special
21850
+** case is broken out because while 9223372036854775808 cannot be a
21851
+** signed 64-bit integer, its negative -9223372036854775808 can be.
2175621852
**
2175721853
** If zNum is too big for a 64-bit integer and is not
21758
-** 9223372036854665808 or if zNum contains any non-numeric text,
21854
+** 9223372036854775808 or if zNum contains any non-numeric text,
2175921855
** then return 1.
2176021856
**
2176121857
** length is the number of bytes in the string (bytes, not characters).
2176221858
** The string is not necessarily zero-terminated. The encoding is
2176321859
** given by enc.
@@ -21795,11 +21891,11 @@
2179521891
while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
2179621892
for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
2179721893
u = u*10 + c - '0';
2179821894
}
2179921895
if( u>LARGEST_INT64 ){
21800
- *pNum = SMALLEST_INT64;
21896
+ *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
2180121897
}else if( neg ){
2180221898
*pNum = -(i64)u;
2180321899
}else{
2180421900
*pNum = (i64)u;
2180521901
}
@@ -21826,11 +21922,10 @@
2182621922
return 1;
2182721923
}else{
2182821924
/* zNum is exactly 9223372036854775808. Fits if negative. The
2182921925
** special case 2 overflow if positive */
2183021926
assert( u-1==LARGEST_INT64 );
21831
- assert( (*pNum)==SMALLEST_INT64 );
2183221927
return neg ? 0 : 2;
2183321928
}
2183421929
}
2183521930
}
2183621931
@@ -22565,11 +22660,13 @@
2256522660
if( x<10 ) return 1;
2256622661
n = x%10;
2256722662
x /= 10;
2256822663
if( n>=5 ) n -= 2;
2256922664
else if( n>=1 ) n -= 1;
22570
- if( x>=3 ) return (n+8)<<(x-3);
22665
+ if( x>=3 ){
22666
+ return x>60 ? (u64)LARGEST_INT64 : (n+8)<<(x-3);
22667
+ }
2257122668
return (n+8)>>(3-x);
2257222669
}
2257322670
2257422671
/************** End of util.c ************************************************/
2257522672
/************** Begin file hash.c ********************************************/
@@ -22869,155 +22966,157 @@
2286922966
/* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
2287022967
/* 2 */ "Savepoint" OpHelp(""),
2287122968
/* 3 */ "AutoCommit" OpHelp(""),
2287222969
/* 4 */ "Transaction" OpHelp(""),
2287322970
/* 5 */ "SorterNext" OpHelp(""),
22874
- /* 6 */ "Prev" OpHelp(""),
22875
- /* 7 */ "Next" OpHelp(""),
22876
- /* 8 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
22877
- /* 9 */ "Checkpoint" OpHelp(""),
22878
- /* 10 */ "JournalMode" OpHelp(""),
22879
- /* 11 */ "Vacuum" OpHelp(""),
22880
- /* 12 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"),
22881
- /* 13 */ "VUpdate" OpHelp("data=r[P3@P2]"),
22882
- /* 14 */ "Goto" OpHelp(""),
22883
- /* 15 */ "Gosub" OpHelp(""),
22884
- /* 16 */ "Return" OpHelp(""),
22885
- /* 17 */ "Yield" OpHelp(""),
22886
- /* 18 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
22971
+ /* 6 */ "PrevIfOpen" OpHelp(""),
22972
+ /* 7 */ "NextIfOpen" OpHelp(""),
22973
+ /* 8 */ "Prev" OpHelp(""),
22974
+ /* 9 */ "Next" OpHelp(""),
22975
+ /* 10 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
22976
+ /* 11 */ "Checkpoint" OpHelp(""),
22977
+ /* 12 */ "JournalMode" OpHelp(""),
22978
+ /* 13 */ "Vacuum" OpHelp(""),
22979
+ /* 14 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"),
22980
+ /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
22981
+ /* 16 */ "Goto" OpHelp(""),
22982
+ /* 17 */ "Gosub" OpHelp(""),
22983
+ /* 18 */ "Return" OpHelp(""),
2288722984
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
22888
- /* 20 */ "Halt" OpHelp(""),
22889
- /* 21 */ "Integer" OpHelp("r[P2]=P1"),
22890
- /* 22 */ "Int64" OpHelp("r[P2]=P4"),
22891
- /* 23 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
22892
- /* 24 */ "Null" OpHelp("r[P2..P3]=NULL"),
22893
- /* 25 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
22894
- /* 26 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
22895
- /* 27 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
22896
- /* 28 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
22897
- /* 29 */ "SCopy" OpHelp("r[P2]=r[P1]"),
22898
- /* 30 */ "ResultRow" OpHelp("output=r[P1@P2]"),
22899
- /* 31 */ "CollSeq" OpHelp(""),
22900
- /* 32 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
22901
- /* 33 */ "MustBeInt" OpHelp(""),
22902
- /* 34 */ "RealAffinity" OpHelp(""),
22903
- /* 35 */ "Permutation" OpHelp(""),
22904
- /* 36 */ "Compare" OpHelp(""),
22905
- /* 37 */ "Jump" OpHelp(""),
22906
- /* 38 */ "Once" OpHelp(""),
22907
- /* 39 */ "If" OpHelp(""),
22908
- /* 40 */ "IfNot" OpHelp(""),
22909
- /* 41 */ "Column" OpHelp("r[P3]=PX"),
22910
- /* 42 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
22911
- /* 43 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
22912
- /* 44 */ "Count" OpHelp("r[P2]=count()"),
22913
- /* 45 */ "ReadCookie" OpHelp(""),
22914
- /* 46 */ "SetCookie" OpHelp(""),
22915
- /* 47 */ "VerifyCookie" OpHelp(""),
22916
- /* 48 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
22917
- /* 49 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
22918
- /* 50 */ "OpenAutoindex" OpHelp("nColumn=P2"),
22919
- /* 51 */ "OpenEphemeral" OpHelp("nColumn=P2"),
22920
- /* 52 */ "SorterOpen" OpHelp(""),
22921
- /* 53 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
22922
- /* 54 */ "Close" OpHelp(""),
22923
- /* 55 */ "SeekLt" OpHelp("key=r[P3@P4]"),
22924
- /* 56 */ "SeekLe" OpHelp("key=r[P3@P4]"),
22925
- /* 57 */ "SeekGe" OpHelp("key=r[P3@P4]"),
22926
- /* 58 */ "SeekGt" OpHelp("key=r[P3@P4]"),
22927
- /* 59 */ "Seek" OpHelp("intkey=r[P2]"),
22928
- /* 60 */ "NoConflict" OpHelp("key=r[P3@P4]"),
22929
- /* 61 */ "NotFound" OpHelp("key=r[P3@P4]"),
22930
- /* 62 */ "Found" OpHelp("key=r[P3@P4]"),
22931
- /* 63 */ "NotExists" OpHelp("intkey=r[P3]"),
22932
- /* 64 */ "Sequence" OpHelp("r[P2]=rowid"),
22933
- /* 65 */ "NewRowid" OpHelp("r[P2]=rowid"),
22934
- /* 66 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
22935
- /* 67 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
22936
- /* 68 */ "Delete" OpHelp(""),
22985
+ /* 20 */ "Yield" OpHelp(""),
22986
+ /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
22987
+ /* 22 */ "Halt" OpHelp(""),
22988
+ /* 23 */ "Integer" OpHelp("r[P2]=P1"),
22989
+ /* 24 */ "Int64" OpHelp("r[P2]=P4"),
22990
+ /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
22991
+ /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
22992
+ /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
22993
+ /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
22994
+ /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
22995
+ /* 30 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
22996
+ /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
22997
+ /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
22998
+ /* 33 */ "CollSeq" OpHelp(""),
22999
+ /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23000
+ /* 35 */ "MustBeInt" OpHelp(""),
23001
+ /* 36 */ "RealAffinity" OpHelp(""),
23002
+ /* 37 */ "Permutation" OpHelp(""),
23003
+ /* 38 */ "Compare" OpHelp(""),
23004
+ /* 39 */ "Jump" OpHelp(""),
23005
+ /* 40 */ "Once" OpHelp(""),
23006
+ /* 41 */ "If" OpHelp(""),
23007
+ /* 42 */ "IfNot" OpHelp(""),
23008
+ /* 43 */ "Column" OpHelp("r[P3]=PX"),
23009
+ /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23010
+ /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23011
+ /* 46 */ "Count" OpHelp("r[P2]=count()"),
23012
+ /* 47 */ "ReadCookie" OpHelp(""),
23013
+ /* 48 */ "SetCookie" OpHelp(""),
23014
+ /* 49 */ "VerifyCookie" OpHelp(""),
23015
+ /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23016
+ /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23017
+ /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23018
+ /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23019
+ /* 54 */ "SorterOpen" OpHelp(""),
23020
+ /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23021
+ /* 56 */ "Close" OpHelp(""),
23022
+ /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23023
+ /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23024
+ /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23025
+ /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23026
+ /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23027
+ /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23028
+ /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23029
+ /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23030
+ /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23031
+ /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23032
+ /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23033
+ /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
2293723034
/* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
2293823035
/* 70 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
22939
- /* 71 */ "ResetCount" OpHelp(""),
22940
- /* 72 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
22941
- /* 73 */ "SorterData" OpHelp("r[P2]=data"),
23036
+ /* 71 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23037
+ /* 72 */ "Delete" OpHelp(""),
23038
+ /* 73 */ "ResetCount" OpHelp(""),
2294223039
/* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
2294323040
/* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
2294423041
/* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
2294523042
/* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
2294623043
/* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
2294723044
/* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22948
- /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P3"),
23045
+ /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
2294923046
/* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
22950
- /* 82 */ "RowKey" OpHelp("r[P2]=key"),
23047
+ /* 82 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
2295123048
/* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
2295223049
/* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
2295323050
/* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
2295423051
/* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
2295523052
/* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
2295623053
/* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2295723054
/* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22958
- /* 90 */ "Divide" OpHelp("r[P3]=r[P1]/r[P2]"),
22959
- /* 91 */ "Remainder" OpHelp("r[P3]=r[P1]%r[P2]"),
23055
+ /* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23056
+ /* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2296023057
/* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22961
- /* 93 */ "RowData" OpHelp("r[P2]=data"),
23058
+ /* 93 */ "SorterData" OpHelp("r[P2]=data"),
2296223059
/* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2296323060
/* 95 */ "String8" OpHelp("r[P2]='P4'"),
22964
- /* 96 */ "Rowid" OpHelp("r[P2]=rowid"),
22965
- /* 97 */ "NullRow" OpHelp(""),
22966
- /* 98 */ "Last" OpHelp(""),
22967
- /* 99 */ "SorterSort" OpHelp(""),
22968
- /* 100 */ "Sort" OpHelp(""),
22969
- /* 101 */ "Rewind" OpHelp(""),
22970
- /* 102 */ "SorterInsert" OpHelp(""),
22971
- /* 103 */ "IdxInsert" OpHelp("key=r[P2]"),
22972
- /* 104 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
22973
- /* 105 */ "IdxRowid" OpHelp("r[P2]=rowid"),
22974
- /* 106 */ "IdxLT" OpHelp("key=r[P3@P4]"),
22975
- /* 107 */ "IdxGE" OpHelp("key=r[P3@P4]"),
22976
- /* 108 */ "Destroy" OpHelp(""),
22977
- /* 109 */ "Clear" OpHelp(""),
22978
- /* 110 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
22979
- /* 111 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
22980
- /* 112 */ "ParseSchema" OpHelp(""),
22981
- /* 113 */ "LoadAnalysis" OpHelp(""),
22982
- /* 114 */ "DropTable" OpHelp(""),
22983
- /* 115 */ "DropIndex" OpHelp(""),
22984
- /* 116 */ "DropTrigger" OpHelp(""),
22985
- /* 117 */ "IntegrityCk" OpHelp(""),
22986
- /* 118 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
22987
- /* 119 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
22988
- /* 120 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
22989
- /* 121 */ "Program" OpHelp(""),
22990
- /* 122 */ "Param" OpHelp(""),
22991
- /* 123 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
22992
- /* 124 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
22993
- /* 125 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
22994
- /* 126 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
22995
- /* 127 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
22996
- /* 128 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
22997
- /* 129 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
22998
- /* 130 */ "IncrVacuum" OpHelp(""),
23061
+ /* 96 */ "RowKey" OpHelp("r[P2]=key"),
23062
+ /* 97 */ "RowData" OpHelp("r[P2]=data"),
23063
+ /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23064
+ /* 99 */ "NullRow" OpHelp(""),
23065
+ /* 100 */ "Last" OpHelp(""),
23066
+ /* 101 */ "SorterSort" OpHelp(""),
23067
+ /* 102 */ "Sort" OpHelp(""),
23068
+ /* 103 */ "Rewind" OpHelp(""),
23069
+ /* 104 */ "SorterInsert" OpHelp(""),
23070
+ /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23071
+ /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23072
+ /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23073
+ /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23074
+ /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23075
+ /* 110 */ "Destroy" OpHelp(""),
23076
+ /* 111 */ "Clear" OpHelp(""),
23077
+ /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23078
+ /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23079
+ /* 114 */ "ParseSchema" OpHelp(""),
23080
+ /* 115 */ "LoadAnalysis" OpHelp(""),
23081
+ /* 116 */ "DropTable" OpHelp(""),
23082
+ /* 117 */ "DropIndex" OpHelp(""),
23083
+ /* 118 */ "DropTrigger" OpHelp(""),
23084
+ /* 119 */ "IntegrityCk" OpHelp(""),
23085
+ /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23086
+ /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23087
+ /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23088
+ /* 123 */ "Program" OpHelp(""),
23089
+ /* 124 */ "Param" OpHelp(""),
23090
+ /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23091
+ /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23092
+ /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23093
+ /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23094
+ /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23095
+ /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
2299923096
/* 131 */ "Real" OpHelp("r[P2]=P4"),
23000
- /* 132 */ "Expire" OpHelp(""),
23001
- /* 133 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23002
- /* 134 */ "VBegin" OpHelp(""),
23003
- /* 135 */ "VCreate" OpHelp(""),
23004
- /* 136 */ "VDestroy" OpHelp(""),
23005
- /* 137 */ "VOpen" OpHelp(""),
23006
- /* 138 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23007
- /* 139 */ "VNext" OpHelp(""),
23008
- /* 140 */ "VRename" OpHelp(""),
23009
- /* 141 */ "Pagecount" OpHelp(""),
23097
+ /* 132 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23098
+ /* 133 */ "IncrVacuum" OpHelp(""),
23099
+ /* 134 */ "Expire" OpHelp(""),
23100
+ /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23101
+ /* 136 */ "VBegin" OpHelp(""),
23102
+ /* 137 */ "VCreate" OpHelp(""),
23103
+ /* 138 */ "VDestroy" OpHelp(""),
23104
+ /* 139 */ "VOpen" OpHelp(""),
23105
+ /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23106
+ /* 141 */ "VNext" OpHelp(""),
2301023107
/* 142 */ "ToText" OpHelp(""),
2301123108
/* 143 */ "ToBlob" OpHelp(""),
2301223109
/* 144 */ "ToNumeric" OpHelp(""),
2301323110
/* 145 */ "ToInt" OpHelp(""),
2301423111
/* 146 */ "ToReal" OpHelp(""),
23015
- /* 147 */ "MaxPgcnt" OpHelp(""),
23016
- /* 148 */ "Trace" OpHelp(""),
23017
- /* 149 */ "Noop" OpHelp(""),
23018
- /* 150 */ "Explain" OpHelp(""),
23112
+ /* 147 */ "VRename" OpHelp(""),
23113
+ /* 148 */ "Pagecount" OpHelp(""),
23114
+ /* 149 */ "MaxPgcnt" OpHelp(""),
23115
+ /* 150 */ "Trace" OpHelp(""),
23116
+ /* 151 */ "Noop" OpHelp(""),
23117
+ /* 152 */ "Explain" OpHelp(""),
2301923118
};
2302023119
return azName[i];
2302123120
}
2302223121
#endif
2302323122
@@ -24545,10 +24644,19 @@
2454524644
}
2454624645
*ppInode = pInode;
2454724646
return SQLITE_OK;
2454824647
}
2454924648
24649
+/*
24650
+** Return TRUE if pFile has been renamed or unlinked since it was first opened.
24651
+*/
24652
+static int fileHasMoved(unixFile *pFile){
24653
+ struct stat buf;
24654
+ return pFile->pInode!=0 &&
24655
+ (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
24656
+}
24657
+
2455024658
2455124659
/*
2455224660
** Check a unixFile that is a database. Verify the following:
2455324661
**
2455424662
** (1) There is exactly one hard link on the file
@@ -24579,14 +24687,11 @@
2457924687
if( buf.st_nlink>1 ){
2458024688
sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
2458124689
pFile->ctrlFlags |= UNIXFILE_WARNED;
2458224690
return;
2458324691
}
24584
- if( pFile->pInode!=0
24585
- && ((rc = osStat(pFile->zPath, &buf))!=0
24586
- || buf.st_ino!=pFile->pInode->fileId.ino)
24587
- ){
24692
+ if( fileHasMoved(pFile) ){
2458824693
sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
2458924694
pFile->ctrlFlags |= UNIXFILE_WARNED;
2459024695
return;
2459124696
}
2459224697
}
@@ -27030,10 +27135,14 @@
2703027135
if( zTFile ){
2703127136
unixGetTempname(pFile->pVfs->mxPathname, zTFile);
2703227137
*(char**)pArg = zTFile;
2703327138
}
2703427139
return SQLITE_OK;
27140
+ }
27141
+ case SQLITE_FCNTL_HAS_MOVED: {
27142
+ *(int*)pArg = fileHasMoved(pFile);
27143
+ return SQLITE_OK;
2703527144
}
2703627145
#if SQLITE_MAX_MMAP_SIZE>0
2703727146
case SQLITE_FCNTL_MMAP_SIZE: {
2703827147
i64 newLimit = *(i64*)pArg;
2703927148
int rc = SQLITE_OK;
@@ -27311,11 +27420,11 @@
2731127420
2731227421
/* Update the global lock state and do debug tracing */
2731327422
#ifdef SQLITE_DEBUG
2731427423
{ u16 mask;
2731527424
OSTRACE(("SHM-LOCK "));
27316
- mask = (1<<(ofst+n)) - (1<<ofst);
27425
+ mask = ofst>31 ? 0xffffffff : (1<<(ofst+n)) - (1<<ofst);
2731727426
if( rc==SQLITE_OK ){
2731827427
if( lockType==F_UNLCK ){
2731927428
OSTRACE(("unlock %d ok", ofst));
2732027429
pShmNode->exclMask &= ~mask;
2732127430
pShmNode->sharedMask &= ~mask;
@@ -30947,10 +31056,38 @@
3094731056
#if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
3094831057
# error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
3094931058
must be defined."
3095031059
#endif
3095131060
31061
+/*
31062
+** Define the required Windows SDK version constants if they are not
31063
+** already available.
31064
+*/
31065
+#ifndef NTDDI_WIN8
31066
+# define NTDDI_WIN8 0x06020000
31067
+#endif
31068
+
31069
+#ifndef NTDDI_WINBLUE
31070
+# define NTDDI_WINBLUE 0x06030000
31071
+#endif
31072
+
31073
+/*
31074
+** Check if the GetVersionEx[AW] functions should be considered deprecated
31075
+** and avoid using them in that case. It should be noted here that if the
31076
+** value of the SQLITE_WIN32_GETVERSIONEX pre-processor macro is zero
31077
+** (whether via this block or via being manually specified), that implies
31078
+** the underlying operating system will always be based on the Windows NT
31079
+** Kernel.
31080
+*/
31081
+#ifndef SQLITE_WIN32_GETVERSIONEX
31082
+# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE
31083
+# define SQLITE_WIN32_GETVERSIONEX 0
31084
+# else
31085
+# define SQLITE_WIN32_GETVERSIONEX 1
31086
+# endif
31087
+#endif
31088
+
3095231089
/*
3095331090
** This constant should already be defined (in the "WinDef.h" SDK file).
3095431091
*/
3095531092
#ifndef MAX_PATH
3095631093
# define MAX_PATH (260)
@@ -31582,20 +31719,22 @@
3158231719
{ "GetTickCount", (SYSCALL)0, 0 },
3158331720
#endif
3158431721
3158531722
#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
3158631723
31587
-#if defined(SQLITE_WIN32_HAS_ANSI)
31724
+#if defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_GETVERSIONEX) && \
31725
+ SQLITE_WIN32_GETVERSIONEX
3158831726
{ "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
3158931727
#else
3159031728
{ "GetVersionExA", (SYSCALL)0, 0 },
3159131729
#endif
3159231730
3159331731
#define osGetVersionExA ((BOOL(WINAPI*)( \
3159431732
LPOSVERSIONINFOA))aSyscall[34].pCurrent)
3159531733
31596
-#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
31734
+#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
31735
+ defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
3159731736
{ "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
3159831737
#else
3159931738
{ "GetVersionExW", (SYSCALL)0, 0 },
3160031739
#endif
3160131740
@@ -32148,15 +32287,14 @@
3214832287
** API as long as we don't call it when running Win95/98/ME. A call to
3214932288
** this routine is used to determine if the host is Win95/98/ME or
3215032289
** WinNT/2K/XP so that we will know whether or not we can safely call
3215132290
** the LockFileEx() API.
3215232291
*/
32153
-#ifndef NTDDI_WIN8
32154
-# define NTDDI_WIN8 0x06020000
32155
-#endif
3215632292
32157
-#if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
32293
+#if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX
32294
+# define osIsNT() (1)
32295
+#elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
3215832296
# define osIsNT() (1)
3215932297
#elif !defined(SQLITE_WIN32_HAS_WIDE)
3216032298
# define osIsNT() (0)
3216132299
#else
3216232300
static int osIsNT(void){
@@ -32289,18 +32427,24 @@
3228932427
assert( pWinMemData->magic1==WINMEM_MAGIC1 );
3229032428
assert( pWinMemData->magic2==WINMEM_MAGIC2 );
3229132429
3229232430
#if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
3229332431
if( !pWinMemData->hHeap ){
32432
+ DWORD dwInitialSize = SQLITE_WIN32_HEAP_INIT_SIZE;
32433
+ DWORD dwMaximumSize = (DWORD)sqlite3GlobalConfig.nHeap;
32434
+ if( dwMaximumSize==0 ){
32435
+ dwMaximumSize = SQLITE_WIN32_HEAP_MAX_SIZE;
32436
+ }else if( dwInitialSize>dwMaximumSize ){
32437
+ dwInitialSize = dwMaximumSize;
32438
+ }
3229432439
pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
32295
- SQLITE_WIN32_HEAP_INIT_SIZE,
32296
- SQLITE_WIN32_HEAP_MAX_SIZE);
32440
+ dwInitialSize, dwMaximumSize);
3229732441
if( !pWinMemData->hHeap ){
3229832442
sqlite3_log(SQLITE_NOMEM,
32299
- "failed to HeapCreate (%lu), flags=%u, initSize=%u, maxSize=%u",
32300
- osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
32301
- SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
32443
+ "failed to HeapCreate (%lu), flags=%u, initSize=%lu, maxSize=%lu",
32444
+ osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, dwInitialSize,
32445
+ dwMaximumSize);
3230232446
return SQLITE_NOMEM;
3230332447
}
3230432448
pWinMemData->bOwned = TRUE;
3230532449
assert( pWinMemData->bOwned );
3230632450
}
@@ -33972,11 +34116,11 @@
3397234116
winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
3397334117
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
3397434118
return SQLITE_OK;
3397534119
}
3397634120
case SQLITE_FCNTL_VFSNAME: {
33977
- *(char**)pArg = sqlite3_mprintf("win32");
34121
+ *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
3397834122
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
3397934123
return SQLITE_OK;
3398034124
}
3398134125
case SQLITE_FCNTL_WIN32_AV_RETRY: {
3398234126
int *a = (int*)pArg;
@@ -34956,11 +35100,11 @@
3495635100
**
3495735101
** This division contains the implementation of methods on the
3495835102
** sqlite3_vfs object.
3495935103
*/
3496035104
34961
-#if 0
35105
+#if defined(__CYGWIN__)
3496235106
/*
3496335107
** Convert a filename from whatever the underlying operating system
3496435108
** supports for filenames into UTF-8. Space to hold the result is
3496535109
** obtained from malloc and must be freed by the calling function.
3496635110
*/
@@ -35132,27 +35276,21 @@
3513235276
if( winIsDir(zConverted) ){
3513335277
/* At this point, we know the candidate directory exists and should
3513435278
** be used. However, we may need to convert the string containing
3513535279
** its name into UTF-8 (i.e. if it is UTF-16 right now).
3513635280
*/
35137
- if( osIsNT() ){
35138
- char *zUtf8 = winUnicodeToUtf8(zConverted);
35139
- if( !zUtf8 ){
35140
- sqlite3_free(zConverted);
35141
- sqlite3_free(zBuf);
35142
- OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35143
- return SQLITE_IOERR_NOMEM;
35144
- }
35145
- sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
35146
- sqlite3_free(zUtf8);
35147
- sqlite3_free(zConverted);
35148
- break;
35149
- }else{
35150
- sqlite3_snprintf(nMax, zBuf, "%s", zConverted);
35151
- sqlite3_free(zConverted);
35152
- break;
35153
- }
35281
+ char *zUtf8 = winConvertToUtf8Filename(zConverted);
35282
+ if( !zUtf8 ){
35283
+ sqlite3_free(zConverted);
35284
+ sqlite3_free(zBuf);
35285
+ OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35286
+ return SQLITE_IOERR_NOMEM;
35287
+ }
35288
+ sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
35289
+ sqlite3_free(zUtf8);
35290
+ sqlite3_free(zConverted);
35291
+ break;
3515435292
}
3515535293
sqlite3_free(zConverted);
3515635294
}
3515735295
}
3515835296
}
@@ -35833,23 +35971,47 @@
3583335971
*/
3583435972
char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
3583535973
if( !zOut ){
3583635974
return SQLITE_IOERR_NOMEM;
3583735975
}
35838
- if( cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut,
35839
- pVfs->mxPathname+1)<0 ){
35976
+ if( cygwin_conv_path(
35977
+ (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
35978
+ CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){
3584035979
sqlite3_free(zOut);
3584135980
return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
3584235981
"winFullPathname1", zRelative);
35982
+ }else{
35983
+ char *zUtf8 = winConvertToUtf8Filename(zOut);
35984
+ if( !zUtf8 ){
35985
+ sqlite3_free(zOut);
35986
+ return SQLITE_IOERR_NOMEM;
35987
+ }
35988
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35989
+ sqlite3_data_directory, winGetDirSep(), zUtf8);
35990
+ sqlite3_free(zUtf8);
35991
+ sqlite3_free(zOut);
3584335992
}
35844
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35845
- sqlite3_data_directory, winGetDirSep(), zOut);
35846
- sqlite3_free(zOut);
3584735993
}else{
35848
- if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){
35994
+ char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
35995
+ if( !zOut ){
35996
+ return SQLITE_IOERR_NOMEM;
35997
+ }
35998
+ if( cygwin_conv_path(
35999
+ (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A),
36000
+ zRelative, zOut, pVfs->mxPathname+1)<0 ){
36001
+ sqlite3_free(zOut);
3584936002
return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
3585036003
"winFullPathname2", zRelative);
36004
+ }else{
36005
+ char *zUtf8 = winConvertToUtf8Filename(zOut);
36006
+ if( !zUtf8 ){
36007
+ sqlite3_free(zOut);
36008
+ return SQLITE_IOERR_NOMEM;
36009
+ }
36010
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
36011
+ sqlite3_free(zUtf8);
36012
+ sqlite3_free(zOut);
3585136013
}
3585236014
}
3585336015
return SQLITE_OK;
3585436016
#endif
3585536017
@@ -43770,10 +43932,34 @@
4377043932
*ppPager = pPager;
4377143933
return SQLITE_OK;
4377243934
}
4377343935
4377443936
43937
+/* Verify that the database file has not be deleted or renamed out from
43938
+** under the pager. Return SQLITE_OK if the database is still were it ought
43939
+** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error
43940
+** code from sqlite3OsAccess()) if the database has gone missing.
43941
+*/
43942
+static int databaseIsUnmoved(Pager *pPager){
43943
+ int bHasMoved = 0;
43944
+ int rc;
43945
+
43946
+ if( pPager->tempFile ) return SQLITE_OK;
43947
+ if( pPager->dbSize==0 ) return SQLITE_OK;
43948
+ assert( pPager->zFilename && pPager->zFilename[0] );
43949
+ rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved);
43950
+ if( rc==SQLITE_NOTFOUND ){
43951
+ /* If the HAS_MOVED file-control is unimplemented, assume that the file
43952
+ ** has not been moved. That is the historical behavior of SQLite: prior to
43953
+ ** version 3.8.3, it never checked */
43954
+ rc = SQLITE_OK;
43955
+ }else if( rc==SQLITE_OK && bHasMoved ){
43956
+ rc = SQLITE_READONLY_DBMOVED;
43957
+ }
43958
+ return rc;
43959
+}
43960
+
4377543961
4377643962
/*
4377743963
** This function is called after transitioning from PAGER_UNLOCK to
4377843964
** PAGER_SHARED state. It tests if there is a hot journal present in
4377943965
** the file-system for the given pager. A hot journal is one that
@@ -44241,11 +44427,11 @@
4424144427
if( bMmapOk && pagerUseWal(pPager) ){
4424244428
rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
4424344429
if( rc!=SQLITE_OK ) goto pager_acquire_err;
4424444430
}
4424544431
44246
- if( iFrame==0 && bMmapOk ){
44432
+ if( bMmapOk && iFrame==0 ){
4424744433
void *pData = 0;
4424844434
4424944435
rc = sqlite3OsFetch(pPager->fd,
4425044436
(i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
4425144437
);
@@ -44446,17 +44632,23 @@
4444644632
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
4444744633
(pPager->tempFile ?
4444844634
(SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
4444944635
(SQLITE_OPEN_MAIN_JOURNAL)
4445044636
);
44451
- #ifdef SQLITE_ENABLE_ATOMIC_WRITE
44452
- rc = sqlite3JournalOpen(
44453
- pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44454
- );
44455
- #else
44456
- rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44457
- #endif
44637
+
44638
+ /* Verify that the database still has the same name as it did when
44639
+ ** it was originally opened. */
44640
+ rc = databaseIsUnmoved(pPager);
44641
+ if( rc==SQLITE_OK ){
44642
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
44643
+ rc = sqlite3JournalOpen(
44644
+ pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44645
+ );
44646
+#else
44647
+ rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44648
+#endif
44649
+ }
4445844650
}
4445944651
assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
4446044652
}
4446144653
4446244654
@@ -44586,18 +44778,12 @@
4458644778
assert( pPager->eState==PAGER_WRITER_LOCKED
4458744779
|| pPager->eState==PAGER_WRITER_CACHEMOD
4458844780
|| pPager->eState==PAGER_WRITER_DBMOD
4458944781
);
4459044782
assert( assert_pager_state(pPager) );
44591
-
44592
- /* If an error has been previously detected, report the same error
44593
- ** again. This should not happen, but the check provides robustness. */
44594
- if( NEVER(pPager->errCode) ) return pPager->errCode;
44595
-
44596
- /* Higher-level routines never call this function if database is not
44597
- ** writable. But check anyway, just for robustness. */
44598
- if( NEVER(pPager->readOnly) ) return SQLITE_PERM;
44783
+ assert( pPager->errCode==0 );
44784
+ assert( pPager->readOnly==0 );
4459944785
4460044786
CHECK_PAGE(pPg);
4460144787
4460244788
/* The journal file needs to be opened. Higher level routines have already
4460344789
** obtained the necessary locks to begin the write-transaction, but the
@@ -44722,23 +44908,23 @@
4472244908
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
4472344909
int rc = SQLITE_OK;
4472444910
4472544911
PgHdr *pPg = pDbPage;
4472644912
Pager *pPager = pPg->pPager;
44727
- Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
4472844913
4472944914
assert( (pPg->flags & PGHDR_MMAP)==0 );
4473044915
assert( pPager->eState>=PAGER_WRITER_LOCKED );
4473144916
assert( pPager->eState!=PAGER_ERROR );
4473244917
assert( assert_pager_state(pPager) );
4473344918
44734
- if( nPagePerSector>1 ){
44919
+ if( pPager->sectorSize > (u32)pPager->pageSize ){
4473544920
Pgno nPageCount; /* Total number of pages in database file */
4473644921
Pgno pg1; /* First page of the sector pPg is located on. */
4473744922
int nPage = 0; /* Number of pages starting at pg1 to journal */
4473844923
int ii; /* Loop counter */
4473944924
int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
44925
+ Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
4474044926
4474144927
/* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
4474244928
** a journal header to be written between the pages journaled by
4474344929
** this function.
4474444930
*/
@@ -50914,10 +51100,14 @@
5091451100
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
5091551101
pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
5091651102
);
5091751103
if( pIdxKey==0 ) return SQLITE_NOMEM;
5091851104
sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
51105
+ if( pIdxKey->nField==0 ){
51106
+ sqlite3DbFree(pCur->pKeyInfo->db, pFree);
51107
+ return SQLITE_CORRUPT_BKPT;
51108
+ }
5091951109
}else{
5092051110
pIdxKey = 0;
5092151111
}
5092251112
rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
5092351113
if( pFree ){
@@ -51868,11 +52058,11 @@
5186852058
5186952059
if( pgno>btreePagecount(pBt) ){
5187052060
rc = SQLITE_CORRUPT_BKPT;
5187152061
}else{
5187252062
rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
51873
- if( rc==SQLITE_OK ){
52063
+ if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
5187452064
rc = btreeInitPage(*ppPage);
5187552065
if( rc!=SQLITE_OK ){
5187652066
releasePage(*ppPage);
5187752067
}
5187852068
}
@@ -54408,14 +54598,14 @@
5440854598
}
5440954599
5441054600
/*
5441154601
** Return a pointer to payload information from the entry that the
5441254602
** pCur cursor is pointing to. The pointer is to the beginning of
54413
-** the key if skipKey==0 and it points to the beginning of data if
54414
-** skipKey==1. The number of bytes of available key/data is written
54415
-** into *pAmt. If *pAmt==0, then the value returned will not be
54416
-** a valid pointer.
54603
+** the key if index btrees (pPage->intKey==0) and is the data for
54604
+** table btrees (pPage->intKey==1). The number of bytes of available
54605
+** key/data is written into *pAmt. If *pAmt==0, then the value
54606
+** returned will not be a valid pointer.
5441754607
**
5441854608
** This routine is an optimization. It is common for the entire key
5441954609
** and data to fit on the local page and for there to be no overflow
5442054610
** pages. When that is so, this routine can be used to access the
5442154611
** key and data without making a copy. If the key and/or data spills
@@ -54424,45 +54614,25 @@
5442454614
**
5442554615
** The pointer returned by this routine looks directly into the cached
5442654616
** page of the database. The data might change or move the next time
5442754617
** any btree routine is called.
5442854618
*/
54429
-static const unsigned char *fetchPayload(
54619
+static const void *fetchPayload(
5443054620
BtCursor *pCur, /* Cursor pointing to entry to read from */
54431
- int *pAmt, /* Write the number of available bytes here */
54432
- int skipKey /* read beginning at data if this is true */
54621
+ u32 *pAmt /* Write the number of available bytes here */
5443354622
){
54434
- unsigned char *aPayload;
54435
- MemPage *pPage;
54436
- u32 nKey;
54437
- u32 nLocal;
54438
-
5443954623
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
5444054624
assert( pCur->eState==CURSOR_VALID );
54625
+ assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5444154626
assert( cursorHoldsMutex(pCur) );
54442
- pPage = pCur->apPage[pCur->iPage];
54443
- assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
54444
- if( NEVER(pCur->info.nSize==0) ){
54627
+ assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
54628
+ if( pCur->info.nSize==0 ){
5444554629
btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
5444654630
&pCur->info);
5444754631
}
54448
- aPayload = pCur->info.pCell;
54449
- aPayload += pCur->info.nHeader;
54450
- if( pPage->intKey ){
54451
- nKey = 0;
54452
- }else{
54453
- nKey = (int)pCur->info.nKey;
54454
- }
54455
- if( skipKey ){
54456
- aPayload += nKey;
54457
- nLocal = pCur->info.nLocal - nKey;
54458
- }else{
54459
- nLocal = pCur->info.nLocal;
54460
- assert( nLocal<=nKey );
54461
- }
54462
- *pAmt = nLocal;
54463
- return aPayload;
54632
+ *pAmt = pCur->info.nLocal;
54633
+ return (void*)(pCur->info.pCell + pCur->info.nHeader);
5446454634
}
5446554635
5446654636
5446754637
/*
5446854638
** For the entry that cursor pCur is point to, return as
@@ -54476,27 +54646,15 @@
5447654646
** this routine.
5447754647
**
5447854648
** These routines is used to get quick access to key and data
5447954649
** in the common case where no overflow pages are used.
5448054650
*/
54481
-SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
54482
- const void *p = 0;
54483
- assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54484
- assert( cursorHoldsMutex(pCur) );
54485
- if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54486
- p = (const void*)fetchPayload(pCur, pAmt, 0);
54487
- }
54488
- return p;
54489
-}
54490
-SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
54491
- const void *p = 0;
54492
- assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54493
- assert( cursorHoldsMutex(pCur) );
54494
- if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54495
- p = (const void*)fetchPayload(pCur, pAmt, 1);
54496
- }
54497
- return p;
54651
+SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
54652
+ return fetchPayload(pCur, pAmt);
54653
+}
54654
+SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
54655
+ return fetchPayload(pCur, pAmt);
5449854656
}
5449954657
5450054658
5450154659
/*
5450254660
** Move the cursor down to a new child page. The newPgno argument is the
@@ -54611,12 +54769,10 @@
5461154769
** b-tree).
5461254770
*/
5461354771
static int moveToRoot(BtCursor *pCur){
5461454772
MemPage *pRoot;
5461554773
int rc = SQLITE_OK;
54616
- Btree *p = pCur->pBtree;
54617
- BtShared *pBt = p->pBt;
5461854774
5461954775
assert( cursorHoldsMutex(pCur) );
5462054776
assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
5462154777
assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
5462254778
assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54627,20 +54783,16 @@
5462754783
}
5462854784
sqlite3BtreeClearCursor(pCur);
5462954785
}
5463054786
5463154787
if( pCur->iPage>=0 ){
54632
- int i;
54633
- for(i=1; i<=pCur->iPage; i++){
54634
- releasePage(pCur->apPage[i]);
54635
- }
54636
- pCur->iPage = 0;
54788
+ while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]);
5463754789
}else if( pCur->pgnoRoot==0 ){
5463854790
pCur->eState = CURSOR_INVALID;
5463954791
return SQLITE_OK;
5464054792
}else{
54641
- rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
54793
+ rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
5464254794
pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
5464354795
if( rc!=SQLITE_OK ){
5464454796
pCur->eState = CURSOR_INVALID;
5464554797
return rc;
5464654798
}
@@ -54669,18 +54821,20 @@
5466954821
pCur->aiIdx[0] = 0;
5467054822
pCur->info.nSize = 0;
5467154823
pCur->atLast = 0;
5467254824
pCur->validNKey = 0;
5467354825
54674
- if( pRoot->nCell==0 && !pRoot->leaf ){
54826
+ if( pRoot->nCell>0 ){
54827
+ pCur->eState = CURSOR_VALID;
54828
+ }else if( !pRoot->leaf ){
5467554829
Pgno subpage;
5467654830
if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
5467754831
subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
5467854832
pCur->eState = CURSOR_VALID;
5467954833
rc = moveToChild(pCur, subpage);
5468054834
}else{
54681
- pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
54835
+ pCur->eState = CURSOR_INVALID;
5468254836
}
5468354837
return rc;
5468454838
}
5468554839
5468654840
/*
@@ -54867,14 +55021,14 @@
5486755021
assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
5486855022
return SQLITE_OK;
5486955023
}
5487055024
assert( pCur->apPage[0]->intKey || pIdxKey );
5487155025
for(;;){
54872
- int lwr, upr, idx;
55026
+ int lwr, upr, idx, c;
5487355027
Pgno chldPg;
5487455028
MemPage *pPage = pCur->apPage[pCur->iPage];
54875
- int c;
55029
+ u8 *pCell; /* Pointer to current cell in pPage */
5487655030
5487755031
/* pPage->nCell must be greater than zero. If this is the root-page
5487855032
** the cursor would have been INVALID above and this for(;;) loop
5487955033
** not run. If this is not the root-page, then the moveToChild() routine
5488055034
** would have already detected db corruption. Similarly, pPage must
@@ -54882,59 +55036,68 @@
5488255036
** a moveToChild() or moveToRoot() call would have detected corruption. */
5488355037
assert( pPage->nCell>0 );
5488455038
assert( pPage->intKey==(pIdxKey==0) );
5488555039
lwr = 0;
5488655040
upr = pPage->nCell-1;
54887
- if( biasRight ){
54888
- pCur->aiIdx[pCur->iPage] = (u16)(idx = upr);
54889
- }else{
54890
- pCur->aiIdx[pCur->iPage] = (u16)(idx = (upr+lwr)/2);
54891
- }
54892
- for(;;){
54893
- u8 *pCell; /* Pointer to current cell in pPage */
54894
-
54895
- assert( idx==pCur->aiIdx[pCur->iPage] );
54896
- pCur->info.nSize = 0;
54897
- pCell = findCell(pPage, idx) + pPage->childPtrSize;
54898
- if( pPage->intKey ){
55041
+ assert( biasRight==0 || biasRight==1 );
55042
+ idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
55043
+ pCur->aiIdx[pCur->iPage] = (u16)idx;
55044
+ if( pPage->intKey ){
55045
+ for(;;){
5489955046
i64 nCellKey;
55047
+ pCell = findCell(pPage, idx) + pPage->childPtrSize;
5490055048
if( pPage->hasData ){
54901
- u32 dummy;
54902
- pCell += getVarint32(pCell, dummy);
55049
+ while( 0x80 <= *(pCell++) ){
55050
+ if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
55051
+ }
5490355052
}
5490455053
getVarint(pCell, (u64*)&nCellKey);
54905
- if( nCellKey==intKey ){
54906
- c = 0;
54907
- }else if( nCellKey<intKey ){
54908
- c = -1;
54909
- }else{
54910
- assert( nCellKey>intKey );
54911
- c = +1;
54912
- }
54913
- pCur->validNKey = 1;
54914
- pCur->info.nKey = nCellKey;
54915
- }else{
55054
+ if( nCellKey<intKey ){
55055
+ lwr = idx+1;
55056
+ if( lwr>upr ){ c = -1; break; }
55057
+ }else if( nCellKey>intKey ){
55058
+ upr = idx-1;
55059
+ if( lwr>upr ){ c = +1; break; }
55060
+ }else{
55061
+ assert( nCellKey==intKey );
55062
+ pCur->validNKey = 1;
55063
+ pCur->info.nKey = nCellKey;
55064
+ pCur->aiIdx[pCur->iPage] = (u16)idx;
55065
+ if( !pPage->leaf ){
55066
+ lwr = idx;
55067
+ goto moveto_next_layer;
55068
+ }else{
55069
+ *pRes = 0;
55070
+ rc = SQLITE_OK;
55071
+ goto moveto_finish;
55072
+ }
55073
+ }
55074
+ assert( lwr+upr>=0 );
55075
+ idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
55076
+ }
55077
+ }else{
55078
+ for(;;){
55079
+ int nCell;
55080
+ pCell = findCell(pPage, idx) + pPage->childPtrSize;
55081
+
5491655082
/* The maximum supported page-size is 65536 bytes. This means that
5491755083
** the maximum number of record bytes stored on an index B-Tree
5491855084
** page is less than 16384 bytes and may be stored as a 2-byte
5491955085
** varint. This information is used to attempt to avoid parsing
5492055086
** the entire cell by checking for the cases where the record is
5492155087
** stored entirely within the b-tree page by inspecting the first
5492255088
** 2 bytes of the cell.
5492355089
*/
54924
- int nCell = pCell[0];
54925
- if( nCell<=pPage->max1bytePayload
54926
- /* && (pCell+nCell)<pPage->aDataEnd */
54927
- ){
55090
+ nCell = pCell[0];
55091
+ if( nCell<=pPage->max1bytePayload ){
5492855092
/* This branch runs if the record-size field of the cell is a
5492955093
** single byte varint and the record fits entirely on the main
5493055094
** b-tree page. */
5493155095
testcase( pCell+nCell+1==pPage->aDataEnd );
5493255096
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
5493355097
}else if( !(pCell[1] & 0x80)
5493455098
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
54935
- /* && (pCell+nCell+2)<=pPage->aDataEnd */
5493655099
){
5493755100
/* The record-size field is a 2 byte varint and the record
5493855101
** fits entirely on the main b-tree page. */
5493955102
testcase( pCell+nCell+2==pPage->aDataEnd );
5494055103
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -54950,61 +55113,57 @@
5495055113
pCellKey = sqlite3Malloc( nCell );
5495155114
if( pCellKey==0 ){
5495255115
rc = SQLITE_NOMEM;
5495355116
goto moveto_finish;
5495455117
}
55118
+ pCur->aiIdx[pCur->iPage] = (u16)idx;
5495555119
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
5495655120
if( rc ){
5495755121
sqlite3_free(pCellKey);
5495855122
goto moveto_finish;
5495955123
}
5496055124
c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
5496155125
sqlite3_free(pCellKey);
5496255126
}
54963
- }
54964
- if( c==0 ){
54965
- if( pPage->intKey && !pPage->leaf ){
54966
- lwr = idx;
54967
- break;
55127
+ if( c<0 ){
55128
+ lwr = idx+1;
55129
+ }else if( c>0 ){
55130
+ upr = idx-1;
5496855131
}else{
55132
+ assert( c==0 );
5496955133
*pRes = 0;
5497055134
rc = SQLITE_OK;
55135
+ pCur->aiIdx[pCur->iPage] = (u16)idx;
5497155136
goto moveto_finish;
5497255137
}
54973
- }
54974
- if( c<0 ){
54975
- lwr = idx+1;
54976
- }else{
54977
- upr = idx-1;
54978
- }
54979
- if( lwr>upr ){
54980
- break;
54981
- }
54982
- pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
55138
+ if( lwr>upr ) break;
55139
+ assert( lwr+upr>=0 );
55140
+ idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
55141
+ }
5498355142
}
5498455143
assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
5498555144
assert( pPage->isInit );
5498655145
if( pPage->leaf ){
54987
- chldPg = 0;
54988
- }else if( lwr>=pPage->nCell ){
54989
- chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
54990
- }else{
54991
- chldPg = get4byte(findCell(pPage, lwr));
54992
- }
54993
- if( chldPg==0 ){
5499455146
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
55147
+ pCur->aiIdx[pCur->iPage] = (u16)idx;
5499555148
*pRes = c;
5499655149
rc = SQLITE_OK;
5499755150
goto moveto_finish;
5499855151
}
55152
+moveto_next_layer:
55153
+ if( lwr>=pPage->nCell ){
55154
+ chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
55155
+ }else{
55156
+ chldPg = get4byte(findCell(pPage, lwr));
55157
+ }
5499955158
pCur->aiIdx[pCur->iPage] = (u16)lwr;
55000
- pCur->info.nSize = 0;
55001
- pCur->validNKey = 0;
5500255159
rc = moveToChild(pCur, chldPg);
55003
- if( rc ) goto moveto_finish;
55160
+ if( rc ) break;
5500455161
}
5500555162
moveto_finish:
55163
+ pCur->info.nSize = 0;
55164
+ pCur->validNKey = 0;
5500655165
return rc;
5500755166
}
5500855167
5500955168
5501055169
/*
@@ -55758,11 +55917,11 @@
5575855917
nHeader = 0;
5575955918
if( !pPage->leaf ){
5576055919
nHeader += 4;
5576155920
}
5576255921
if( pPage->hasData ){
55763
- nHeader += putVarint(&pCell[nHeader], nData+nZero);
55922
+ nHeader += putVarint32(&pCell[nHeader], nData+nZero);
5576455923
}else{
5576555924
nData = nZero = 0;
5576655925
}
5576755926
nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
5576855927
btreeParseCellPtr(pPage, pCell, &info);
@@ -55886,11 +56045,10 @@
5588656045
*/
5588756046
static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
5588856047
u32 pc; /* Offset to cell content of cell being deleted */
5588956048
u8 *data; /* pPage->aData */
5589056049
u8 *ptr; /* Used to move bytes around within data[] */
55891
- u8 *endPtr; /* End of loop */
5589256050
int rc; /* The return code */
5589356051
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
5589456052
5589556053
if( *pRC ) return;
5589656054
@@ -55911,17 +56069,12 @@
5591156069
rc = freeSpace(pPage, pc, sz);
5591256070
if( rc ){
5591356071
*pRC = rc;
5591456072
return;
5591556073
}
55916
- endPtr = &pPage->aCellIdx[2*pPage->nCell - 2];
55917
- assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
55918
- while( ptr<endPtr ){
55919
- *(u16*)ptr = *(u16*)&ptr[2];
55920
- ptr += 2;
55921
- }
5592256074
pPage->nCell--;
56075
+ memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
5592356076
put2byte(&data[hdr+3], pPage->nCell);
5592456077
pPage->nFree += 2;
5592556078
}
5592656079
5592756080
/*
@@ -55954,13 +56107,10 @@
5595456107
int j; /* Loop counter */
5595556108
int end; /* First byte past the last cell pointer in data[] */
5595656109
int ins; /* Index in data[] where new cell pointer is inserted */
5595756110
int cellOffset; /* Address of first cell pointer in data[] */
5595856111
u8 *data; /* The content of the whole page */
55959
- u8 *ptr; /* Used for moving information around in data[] */
55960
- u8 *endPtr; /* End of the loop */
55961
-
5596256112
int nSkip = (iChild ? 4 : 0);
5596356113
5596456114
if( *pRC ) return;
5596556115
5596656116
assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56007,17 +56157,11 @@
5600756157
pPage->nFree -= (u16)(2 + sz);
5600856158
memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
5600956159
if( iChild ){
5601056160
put4byte(&data[idx], iChild);
5601156161
}
56012
- ptr = &data[end];
56013
- endPtr = &data[ins];
56014
- assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
56015
- while( ptr>endPtr ){
56016
- *(u16*)ptr = *(u16*)&ptr[-2];
56017
- ptr -= 2;
56018
- }
56162
+ memmove(&data[ins+2], &data[ins], end-ins);
5601956163
put2byte(&data[ins], idx);
5602056164
put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
5602156165
#ifndef SQLITE_OMIT_AUTOVACUUM
5602256166
if( pPage->pBt->autoVacuum ){
5602356167
/* The cell may contain a pointer to an overflow page. If so, write
@@ -57975,11 +58119,11 @@
5797558119
va_start(ap, zFormat);
5797658120
if( pCheck->errMsg.nChar ){
5797758121
sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
5797858122
}
5797958123
if( zMsg1 ){
57980
- sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
58124
+ sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
5798158125
}
5798258126
sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
5798358127
va_end(ap);
5798458128
if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
5798558129
pCheck->mallocFailed = 1;
@@ -58839,10 +58983,11 @@
5883958983
if( sqlite3OpenTempDatabase(pParse) ){
5884058984
sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
5884158985
rc = SQLITE_ERROR;
5884258986
}
5884358987
sqlite3DbFree(pErrorDb, pParse->zErrMsg);
58988
+ sqlite3ParserReset(pParse);
5884458989
sqlite3StackFree(pErrorDb, pParse);
5884558990
}
5884658991
if( rc ){
5884758992
return 0;
5884858993
}
@@ -59550,61 +59695,59 @@
5955059695
#endif
5955159696
}
5955259697
5955359698
/*
5955459699
** Make sure pMem->z points to a writable allocation of at least
59555
-** n bytes.
59556
-**
59557
-** If the third argument passed to this function is true, then memory
59558
-** cell pMem must contain a string or blob. In this case the content is
59559
-** preserved. Otherwise, if the third parameter to this function is false,
59560
-** any current string or blob value may be discarded.
59561
-**
59562
-** This function sets the MEM_Dyn flag and clears any xDel callback.
59563
-** It also clears MEM_Ephem and MEM_Static. If the preserve flag is
59564
-** not set, Mem.n is zeroed.
59565
-*/
59566
-SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
59700
+** min(n,32) bytes.
59701
+**
59702
+** If the bPreserve argument is true, then copy of the content of
59703
+** pMem->z into the new allocation. pMem must be either a string or
59704
+** blob if bPreserve is true. If bPreserve is false, any prior content
59705
+** in pMem->z is discarded.
59706
+*/
59707
+SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
5956759708
assert( 1 >=
5956859709
((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
5956959710
(((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
5957059711
((pMem->flags&MEM_Ephem) ? 1 : 0) +
5957159712
((pMem->flags&MEM_Static) ? 1 : 0)
5957259713
);
5957359714
assert( (pMem->flags&MEM_RowSet)==0 );
5957459715
59575
- /* If the preserve flag is set to true, then the memory cell must already
59716
+ /* If the bPreserve flag is set to true, then the memory cell must already
5957659717
** contain a valid string or blob value. */
59577
- assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
59718
+ assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
59719
+ testcase( bPreserve && pMem->z==0 );
5957859720
59579
- if( n<32 ) n = 32;
59580
- if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59581
- if( preserve && pMem->z==pMem->zMalloc ){
59721
+ if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59722
+ if( n<32 ) n = 32;
59723
+ if( bPreserve && pMem->z==pMem->zMalloc ){
5958259724
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59583
- preserve = 0;
59725
+ bPreserve = 0;
5958459726
}else{
5958559727
sqlite3DbFree(pMem->db, pMem->zMalloc);
5958659728
pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
5958759729
}
59730
+ if( pMem->zMalloc==0 ){
59731
+ sqlite3VdbeMemRelease(pMem);
59732
+ pMem->flags = MEM_Null;
59733
+ return SQLITE_NOMEM;
59734
+ }
5958859735
}
5958959736
59590
- if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
59737
+ if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
5959159738
memcpy(pMem->zMalloc, pMem->z, pMem->n);
5959259739
}
59593
- if( pMem->flags&MEM_Dyn && pMem->xDel ){
59740
+ if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
5959459741
assert( pMem->xDel!=SQLITE_DYNAMIC );
5959559742
pMem->xDel((void *)(pMem->z));
5959659743
}
5959759744
5959859745
pMem->z = pMem->zMalloc;
59599
- if( pMem->z==0 ){
59600
- pMem->flags = MEM_Null;
59601
- }else{
59602
- pMem->flags &= ~(MEM_Ephem|MEM_Static);
59603
- }
59746
+ pMem->flags &= ~(MEM_Ephem|MEM_Static);
5960459747
pMem->xDel = 0;
59605
- return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
59748
+ return SQLITE_OK;
5960659749
}
5960759750
5960859751
/*
5960959752
** Make the given Mem object MEM_Dyn. In other words, make it so
5961059753
** that any TEXT or BLOB content is stored in memory obtained from
@@ -59786,27 +59929,22 @@
5978659929
** inconsistent state, for example with (Mem.z==0) and
5978759930
** (Mem.type==SQLITE_TEXT).
5978859931
*/
5978959932
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
5979059933
VdbeMemRelease(p);
59791
- sqlite3DbFree(p->db, p->zMalloc);
59934
+ if( p->zMalloc ){
59935
+ sqlite3DbFree(p->db, p->zMalloc);
59936
+ p->zMalloc = 0;
59937
+ }
5979259938
p->z = 0;
59793
- p->zMalloc = 0;
59794
- p->xDel = 0;
59939
+ assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */
5979559940
}
5979659941
5979759942
/*
5979859943
** Convert a 64-bit IEEE double into a 64-bit signed integer.
59799
-** If the double is too large, return 0x8000000000000000.
59800
-**
59801
-** Most systems appear to do this simply by assigning
59802
-** variables and without the extra range tests. But
59803
-** there are reports that windows throws an expection
59804
-** if the floating point value is out of range. (See ticket #2880.)
59805
-** Because we do not completely understand the problem, we will
59806
-** take the conservative approach and always do range tests
59807
-** before attempting the conversion.
59944
+** If the double is out of range of a 64-bit signed integer then
59945
+** return the closest available 64-bit signed integer.
5980859946
*/
5980959947
static i64 doubleToInt64(double r){
5981059948
#ifdef SQLITE_OMIT_FLOATING_POINT
5981159949
/* When floating-point is omitted, double and int64 are the same thing */
5981259950
return r;
@@ -59819,18 +59957,14 @@
5981959957
** larger than a 32-bit integer constant.
5982059958
*/
5982159959
static const i64 maxInt = LARGEST_INT64;
5982259960
static const i64 minInt = SMALLEST_INT64;
5982359961
59824
- if( r<(double)minInt ){
59825
- return minInt;
59826
- }else if( r>(double)maxInt ){
59827
- /* minInt is correct here - not maxInt. It turns out that assigning
59828
- ** a very large positive number to an integer results in a very large
59829
- ** negative integer. This makes no sense, but it is what x86 hardware
59830
- ** does so for compatibility we will do the same in software. */
59831
- return minInt;
59962
+ if( r<=(double)minInt ){
59963
+ return minInt;
59964
+ }else if( r>=(double)maxInt ){
59965
+ return maxInt;
5983259966
}else{
5983359967
return (i64)r;
5983459968
}
5983559969
#endif
5983659970
}
@@ -59908,21 +60042,15 @@
5990860042
** (2) The integer is neither the largest nor the smallest
5990960043
** possible integer (ticket #3922)
5991060044
**
5991160045
** The second and third terms in the following conditional enforces
5991260046
** the second condition under the assumption that addition overflow causes
59913
- ** values to wrap around. On x86 hardware, the third term is always
59914
- ** true and could be omitted. But we leave it in because other
59915
- ** architectures might behave differently.
60047
+ ** values to wrap around.
5991660048
*/
5991760049
if( pMem->r==(double)pMem->u.i
5991860050
&& pMem->u.i>SMALLEST_INT64
59919
-#if defined(__i486__) || defined(__x86_64__)
59920
- && ALWAYS(pMem->u.i<LARGEST_INT64)
59921
-#else
5992260051
&& pMem->u.i<LARGEST_INT64
59923
-#endif
5992460052
){
5992560053
pMem->flags |= MEM_Int;
5992660054
}
5992760055
}
5992860056
@@ -60387,17 +60515,17 @@
6038760515
** If this routine fails for any reason (malloc returns NULL or unable
6038860516
** to read from the disk) then the pMem is left in an inconsistent state.
6038960517
*/
6039060518
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
6039160519
BtCursor *pCur, /* Cursor pointing at record to retrieve. */
60392
- int offset, /* Offset from the start of data to return bytes from. */
60393
- int amt, /* Number of bytes to return. */
60520
+ u32 offset, /* Offset from the start of data to return bytes from. */
60521
+ u32 amt, /* Number of bytes to return. */
6039460522
int key, /* If true, retrieve from the btree key, not data. */
6039560523
Mem *pMem /* OUT: Return data in this Mem structure. */
6039660524
){
6039760525
char *zData; /* Data from the btree layer */
60398
- int available = 0; /* Number of bytes available on the local btree page */
60526
+ u32 available = 0; /* Number of bytes available on the local btree page */
6039960527
int rc = SQLITE_OK; /* Return code */
6040060528
6040160529
assert( sqlite3BtreeCursorIsValid(pCur) );
6040260530
6040360531
/* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
@@ -60408,11 +60536,11 @@
6040860536
}else{
6040960537
zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
6041060538
}
6041160539
assert( zData!=0 );
6041260540
60413
- if( offset+amt<=available && (pMem->flags&MEM_Dyn)==0 ){
60541
+ if( offset+amt<=available ){
6041460542
sqlite3VdbeMemRelease(pMem);
6041560543
pMem->z = &zData[offset];
6041660544
pMem->flags = MEM_Blob|MEM_Ephem;
6041760545
}else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
6041860546
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
@@ -60427,11 +60555,11 @@
6042760555
pMem->z[amt+1] = 0;
6042860556
if( rc!=SQLITE_OK ){
6042960557
sqlite3VdbeMemRelease(pMem);
6043060558
}
6043160559
}
60432
- pMem->n = amt;
60560
+ pMem->n = (int)amt;
6043360561
6043460562
return rc;
6043560563
}
6043660564
6043760565
/* This function is only available internally, it is not part of the
@@ -60524,19 +60652,19 @@
6052460652
Index *pIdx = p->pIdx; /* Index being probed */
6052560653
int nByte; /* Bytes of space to allocate */
6052660654
int i; /* Counter variable */
6052760655
int nCol = pIdx->nColumn; /* Number of index columns including rowid */
6052860656
60529
- nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord);
60657
+ nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
6053060658
pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
6053160659
if( pRec ){
6053260660
pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
6053360661
if( pRec->pKeyInfo ){
6053460662
assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
6053560663
assert( pRec->pKeyInfo->enc==ENC(db) );
6053660664
pRec->flags = UNPACKED_PREFIX_MATCH;
60537
- pRec->aMem = (Mem *)&pRec[1];
60665
+ pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
6053860666
for(i=0; i<nCol; i++){
6053960667
pRec->aMem[i].flags = MEM_Null;
6054060668
pRec->aMem[i].type = SQLITE_NULL;
6054160669
pRec->aMem[i].db = db;
6054260670
}
@@ -60586,20 +60714,11 @@
6058660714
if( !pExpr ){
6058760715
*ppVal = 0;
6058860716
return SQLITE_OK;
6058960717
}
6059060718
op = pExpr->op;
60591
-
60592
- /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT4.
60593
- ** The ifdef here is to enable us to achieve 100% branch test coverage even
60594
- ** when SQLITE_ENABLE_STAT4 is omitted.
60595
- */
60596
-#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
60597
- if( op==TK_REGISTER ) op = pExpr->op2;
60598
-#else
6059960719
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
60600
-#endif
6060160720
6060260721
/* Handle negative integers in a single step. This is needed in the
6060360722
** case when the value is -9223372036854775808.
6060460723
*/
6060560724
if( op==TK_UMINUS
@@ -60736,11 +60855,11 @@
6073660855
if( aRet==0 ){
6073760856
sqlite3_result_error_nomem(context);
6073860857
}else{
6073960858
aRet[0] = nSerial+1;
6074060859
sqlite3PutVarint(&aRet[1], iSerial);
60741
- sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
60860
+ sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
6074260861
sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
6074360862
sqlite3DbFree(db, aRet);
6074460863
}
6074560864
}
6074660865
@@ -60814,14 +60933,13 @@
6081460933
6081560934
if( !pExpr ){
6081660935
pVal = valueNew(db, &alloc);
6081760936
if( pVal ){
6081860937
sqlite3VdbeMemSetNull((Mem*)pVal);
60819
- *pbOk = 1;
6082060938
}
6082160939
}else if( pExpr->op==TK_VARIABLE
60822
- || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
60940
+ || NEVER(pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
6082360941
){
6082460942
Vdbe *v;
6082560943
int iBindVar = pExpr->iColumn;
6082660944
sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
6082760945
if( (v = pParse->pReprepare)!=0 ){
@@ -60830,20 +60948,17 @@
6083060948
rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
6083160949
if( rc==SQLITE_OK ){
6083260950
sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
6083360951
}
6083460952
pVal->db = pParse->db;
60835
- *pbOk = 1;
6083660953
sqlite3VdbeMemStoreType((Mem*)pVal);
6083760954
}
60838
- }else{
60839
- *pbOk = 0;
6084060955
}
6084160956
}else{
6084260957
rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
60843
- *pbOk = (pVal!=0);
6084460958
}
60959
+ *pbOk = (pVal!=0);
6084560960
6084660961
assert( pVal==0 || pVal->db==db );
6084760962
return rc;
6084860963
}
6084960964
@@ -60983,19 +61098,10 @@
6098361098
pA->zSql = pB->zSql;
6098461099
pB->zSql = zTmp;
6098561100
pB->isPrepareV2 = pA->isPrepareV2;
6098661101
}
6098761102
60988
-#ifdef SQLITE_DEBUG
60989
-/*
60990
-** Turn tracing on or off
60991
-*/
60992
-SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
60993
- p->trace = trace;
60994
-}
60995
-#endif
60996
-
6099761103
/*
6099861104
** Resize the Vdbe.aOp array so that it is at least one op larger than
6099961105
** it was.
6100061106
**
6100161107
** If an out-of-memory error occurs while resizing the array, return
@@ -61367,16 +61473,18 @@
6136761473
if( n>nMaxArgs ) nMaxArgs = n;
6136861474
break;
6136961475
}
6137061476
#endif
6137161477
case OP_Next:
61478
+ case OP_NextIfOpen:
6137261479
case OP_SorterNext: {
6137361480
pOp->p4.xAdvance = sqlite3BtreeNext;
6137461481
pOp->p4type = P4_ADVANCE;
6137561482
break;
6137661483
}
61377
- case OP_Prev: {
61484
+ case OP_Prev:
61485
+ case OP_PrevIfOpen: {
6137861486
pOp->p4.xAdvance = sqlite3BtreePrevious;
6137961487
pOp->p4type = P4_ADVANCE;
6138061488
break;
6138161489
}
6138261490
}
@@ -61887,11 +61995,11 @@
6188761995
assert( i<nTemp );
6188861996
break;
6188961997
}
6189061998
case P4_COLLSEQ: {
6189161999
CollSeq *pColl = pOp->p4.pColl;
61892
- sqlite3_snprintf(nTemp, zTemp, "collseq(%.20s)", pColl->zName);
62000
+ sqlite3_snprintf(nTemp, zTemp, "(%.20s)", pColl->zName);
6189362001
break;
6189462002
}
6189562003
case P4_FUNCDEF: {
6189662004
FuncDef *pDef = pOp->p4.pFunc;
6189762005
sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
@@ -62320,19 +62428,21 @@
6232062428
#ifdef SQLITE_DEBUG
6232162429
/*
6232262430
** Print the SQL that was used to generate a VDBE program.
6232362431
*/
6232462432
SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
62325
- int nOp = p->nOp;
62326
- VdbeOp *pOp;
62327
- if( nOp<1 ) return;
62328
- pOp = &p->aOp[0];
62329
- if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62330
- const char *z = pOp->p4.z;
62331
- while( sqlite3Isspace(*z) ) z++;
62332
- printf("SQL: [%s]\n", z);
62333
- }
62433
+ const char *z = 0;
62434
+ if( p->zSql ){
62435
+ z = p->zSql;
62436
+ }else if( p->nOp>=1 ){
62437
+ const VdbeOp *pOp = &p->aOp[0];
62438
+ if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62439
+ z = pOp->p4.z;
62440
+ while( sqlite3Isspace(*z) ) z++;
62441
+ }
62442
+ }
62443
+ if( z ) printf("SQL: [%s]\n", z);
6233462444
}
6233562445
#endif
6233662446
6233762447
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
6233862448
/*
@@ -62586,11 +62696,11 @@
6258662696
sqlite3BtreeCloseCursor(pCx->pCursor);
6258762697
}
6258862698
#ifndef SQLITE_OMIT_VIRTUALTABLE
6258962699
if( pCx->pVtabCursor ){
6259062700
sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
62591
- const sqlite3_module *pModule = pCx->pModule;
62701
+ const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
6259262702
p->inVtabMethod = 1;
6259362703
pModule->xClose(pVtabCursor);
6259462704
p->inVtabMethod = 0;
6259562705
}
6259662706
#endif
@@ -63570,11 +63680,11 @@
6357063680
#ifdef SQLITE_TEST
6357163681
sqlite3_search_count++;
6357263682
#endif
6357363683
p->deferredMoveto = 0;
6357463684
p->cacheStatus = CACHE_STALE;
63575
- }else if( ALWAYS(p->pCursor) ){
63685
+ }else if( p->pCursor ){
6357663686
int hasMoved;
6357763687
int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
6357863688
if( rc ) return rc;
6357963689
if( hasMoved ){
6358063690
p->cacheStatus = CACHE_STALE;
@@ -63737,25 +63847,19 @@
6373763847
/*
6373863848
** Write the serialized data blob for the value stored in pMem into
6373963849
** buf. It is assumed that the caller has allocated sufficient space.
6374063850
** Return the number of bytes written.
6374163851
**
63742
-** nBuf is the amount of space left in buf[]. nBuf must always be
63743
-** large enough to hold the entire field. Except, if the field is
63744
-** a blob with a zero-filled tail, then buf[] might be just the right
63745
-** size to hold everything except for the zero-filled tail. If buf[]
63746
-** is only big enough to hold the non-zero prefix, then only write that
63747
-** prefix into buf[]. But if buf[] is large enough to hold both the
63748
-** prefix and the tail then write the prefix and set the tail to all
63749
-** zeros.
63852
+** nBuf is the amount of space left in buf[]. The caller is responsible
63853
+** for allocating enough space to buf[] to hold the entire field, exclusive
63854
+** of the pMem->u.nZero bytes for a MEM_Zero value.
6375063855
**
6375163856
** Return the number of bytes actually written into buf[]. The number
6375263857
** of bytes in the zero-filled tail is included in the return value only
6375363858
** if those bytes were zeroed in buf[].
6375463859
*/
63755
-SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
63756
- u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
63860
+SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
6375763861
u32 len;
6375863862
6375963863
/* Integer and Real */
6376063864
if( serial_type<=7 && serial_type>0 ){
6376163865
u64 v;
@@ -63766,11 +63870,10 @@
6376663870
swapMixedEndianFloat(v);
6376763871
}else{
6376863872
v = pMem->u.i;
6376963873
}
6377063874
len = i = sqlite3VdbeSerialTypeLen(serial_type);
63771
- assert( len<=(u32)nBuf );
6377263875
while( i-- ){
6377363876
buf[i] = (u8)(v&0xFF);
6377463877
v >>= 8;
6377563878
}
6377663879
return len;
@@ -63778,21 +63881,12 @@
6377863881
6377963882
/* String or blob */
6378063883
if( serial_type>=12 ){
6378163884
assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
6378263885
== (int)sqlite3VdbeSerialTypeLen(serial_type) );
63783
- assert( pMem->n<=nBuf );
6378463886
len = pMem->n;
6378563887
memcpy(buf, pMem->z, len);
63786
- if( pMem->flags & MEM_Zero ){
63787
- len += pMem->u.nZero;
63788
- assert( nBuf>=0 );
63789
- if( len > (u32)nBuf ){
63790
- len = (u32)nBuf;
63791
- }
63792
- memset(&buf[pMem->n], 0, len-pMem->n);
63793
- }
6379463888
return len;
6379563889
}
6379663890
6379763891
/* NULL or constants 0 or 1 */
6379863892
return 0;
@@ -63878,19 +63972,16 @@
6387863972
pMem->u.i = serial_type-8;
6387963973
pMem->flags = MEM_Int;
6388063974
return 0;
6388163975
}
6388263976
default: {
63977
+ static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
6388363978
u32 len = (serial_type-12)/2;
6388463979
pMem->z = (char *)buf;
6388563980
pMem->n = len;
6388663981
pMem->xDel = 0;
63887
- if( serial_type&0x01 ){
63888
- pMem->flags = MEM_Str | MEM_Ephem;
63889
- }else{
63890
- pMem->flags = MEM_Blob | MEM_Ephem;
63891
- }
63982
+ pMem->flags = aFlag[serial_type&1];
6389263983
return len;
6389363984
}
6389463985
}
6389563986
return 0;
6389663987
}
@@ -64025,13 +64116,15 @@
6402564116
*/
6402664117
/* mem1.u.i = 0; // not needed, here to silence compiler warning */
6402764118
6402864119
idx1 = getVarint32(aKey1, szHdr1);
6402964120
d1 = szHdr1;
64030
- assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField );
64121
+ assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
6403164122
assert( pKeyInfo->aSortOrder!=0 );
64032
- while( idx1<szHdr1 && i<pPKey2->nField ){
64123
+ assert( pKeyInfo->nField>0 );
64124
+ assert( idx1<=szHdr1 || CORRUPT_DB );
64125
+ do{
6403364126
u32 serial_type1;
6403464127
6403564128
/* Read the serial types for the next element in each key. */
6403664129
idx1 += getVarint32( aKey1+idx1, serial_type1 );
6403764130
@@ -64060,11 +64153,11 @@
6406064153
rc = -rc; /* Invert the result for DESC sort order. */
6406164154
}
6406264155
return rc;
6406364156
}
6406464157
i++;
64065
- }
64158
+ }while( idx1<szHdr1 && i<pPKey2->nField );
6406664159
6406764160
/* No memory allocation is ever used on mem1. Prove this using
6406864161
** the following assert(). If the assert() fails, it indicates a
6406964162
** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
6407064163
*/
@@ -64118,11 +64211,11 @@
6411864211
assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
6411964212
assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
6412064213
6412164214
/* Read in the complete content of the index entry */
6412264215
memset(&m, 0, sizeof(m));
64123
- rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
64216
+ rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
6412464217
if( rc ){
6412564218
return rc;
6412664219
}
6412764220
6412864221
/* The index entry must begin with a header size */
@@ -64196,11 +64289,11 @@
6419664289
if( nCellKey<=0 || nCellKey>0x7fffffff ){
6419764290
*res = 0;
6419864291
return SQLITE_CORRUPT_BKPT;
6419964292
}
6420064293
memset(&m, 0, sizeof(m));
64201
- rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m);
64294
+ rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
6420264295
if( rc ){
6420364296
return rc;
6420464297
}
6420564298
assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
6420664299
*res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
@@ -65715,10 +65808,11 @@
6571565808
if( db->nVdbeExec>1 ){
6571665809
while( *zRawSql ){
6571765810
const char *zStart = zRawSql;
6571865811
while( *(zRawSql++)!='\n' && *zRawSql );
6571965812
sqlite3StrAccumAppend(&out, "-- ", 3);
65813
+ assert( (zRawSql - zStart) > 0 );
6572065814
sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
6572165815
}
6572265816
}else{
6572365817
while( zRawSql[0] ){
6572465818
n = findNextHostParameter(zRawSql, &nToken);
@@ -66131,13 +66225,12 @@
6613166225
Mem *pMem = &p->aMem[p->nMem-iCur];
6613266226
6613366227
int nByte;
6613466228
VdbeCursor *pCx = 0;
6613566229
nByte =
66136
- ROUND8(sizeof(VdbeCursor)) +
66137
- (isBtreeCursor?sqlite3BtreeCursorSize():0) +
66138
- 2*nField*sizeof(u32);
66230
+ ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
66231
+ (isBtreeCursor?sqlite3BtreeCursorSize():0);
6613966232
6614066233
assert( iCur<p->nCursor );
6614166234
if( p->apCsr[iCur] ){
6614266235
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
6614366236
p->apCsr[iCur] = 0;
@@ -66145,16 +66238,13 @@
6614566238
if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
6614666239
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
6614766240
memset(pCx, 0, sizeof(VdbeCursor));
6614866241
pCx->iDb = iDb;
6614966242
pCx->nField = nField;
66150
- if( nField ){
66151
- pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))];
66152
- }
6615366243
if( isBtreeCursor ){
6615466244
pCx->pCursor = (BtCursor*)
66155
- &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)];
66245
+ &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
6615666246
sqlite3BtreeCursorZero(pCx->pCursor);
6615766247
}
6615866248
}
6615966249
return pCx;
6616066250
}
@@ -66336,41 +66426,40 @@
6633666426
6633766427
#ifdef SQLITE_DEBUG
6633866428
/*
6633966429
** Print the value of a register for tracing purposes:
6634066430
*/
66341
-static void memTracePrint(FILE *out, Mem *p){
66431
+static void memTracePrint(Mem *p){
6634266432
if( p->flags & MEM_Invalid ){
66343
- fprintf(out, " undefined");
66433
+ printf(" undefined");
6634466434
}else if( p->flags & MEM_Null ){
66345
- fprintf(out, " NULL");
66435
+ printf(" NULL");
6634666436
}else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66347
- fprintf(out, " si:%lld", p->u.i);
66437
+ printf(" si:%lld", p->u.i);
6634866438
}else if( p->flags & MEM_Int ){
66349
- fprintf(out, " i:%lld", p->u.i);
66439
+ printf(" i:%lld", p->u.i);
6635066440
#ifndef SQLITE_OMIT_FLOATING_POINT
6635166441
}else if( p->flags & MEM_Real ){
66352
- fprintf(out, " r:%g", p->r);
66442
+ printf(" r:%g", p->r);
6635366443
#endif
6635466444
}else if( p->flags & MEM_RowSet ){
66355
- fprintf(out, " (rowset)");
66445
+ printf(" (rowset)");
6635666446
}else{
6635766447
char zBuf[200];
6635866448
sqlite3VdbeMemPrettyPrint(p, zBuf);
66359
- fprintf(out, " ");
66360
- fprintf(out, "%s", zBuf);
66449
+ printf(" %s", zBuf);
6636166450
}
6636266451
}
66363
-static void registerTrace(FILE *out, int iReg, Mem *p){
66364
- fprintf(out, "REG[%d] = ", iReg);
66365
- memTracePrint(out, p);
66366
- fprintf(out, "\n");
66452
+static void registerTrace(int iReg, Mem *p){
66453
+ printf("REG[%d] = ", iReg);
66454
+ memTracePrint(p);
66455
+ printf("\n");
6636766456
}
6636866457
#endif
6636966458
6637066459
#ifdef SQLITE_DEBUG
66371
-# define REGISTER_TRACE(R,M) if(p->trace)registerTrace(p->trace,R,M)
66460
+# define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
6637266461
#else
6637366462
# define REGISTER_TRACE(R,M)
6637466463
#endif
6637566464
6637666465
@@ -66563,438 +66652,11 @@
6656366652
i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6656466653
#ifdef VDBE_PROFILE
6656566654
u64 start; /* CPU clock count at start of opcode */
6656666655
int origPc; /* Program counter at start of opcode */
6656766656
#endif
66568
- /********************************************************************
66569
- ** Automatically generated code
66570
- **
66571
- ** The following union is automatically generated by the
66572
- ** vdbe-compress.tcl script. The purpose of this union is to
66573
- ** reduce the amount of stack space required by this function.
66574
- ** See comments in the vdbe-compress.tcl script for details.
66575
- */
66576
- union vdbeExecUnion {
66577
- struct OP_Yield_stack_vars {
66578
- int pcDest;
66579
- } aa;
66580
- struct OP_Halt_stack_vars {
66581
- const char *zType;
66582
- const char *zLogFmt;
66583
- } ab;
66584
- struct OP_Null_stack_vars {
66585
- int cnt;
66586
- u16 nullFlag;
66587
- } ac;
66588
- struct OP_Variable_stack_vars {
66589
- Mem *pVar; /* Value being transferred */
66590
- } ad;
66591
- struct OP_Move_stack_vars {
66592
- char *zMalloc; /* Holding variable for allocated memory */
66593
- int n; /* Number of registers left to copy */
66594
- int p1; /* Register to copy from */
66595
- int p2; /* Register to copy to */
66596
- } ae;
66597
- struct OP_Copy_stack_vars {
66598
- int n;
66599
- } af;
66600
- struct OP_ResultRow_stack_vars {
66601
- Mem *pMem;
66602
- int i;
66603
- } ag;
66604
- struct OP_Concat_stack_vars {
66605
- i64 nByte;
66606
- } ah;
66607
- struct OP_Remainder_stack_vars {
66608
- char bIntint; /* Started out as two integer operands */
66609
- int flags; /* Combined MEM_* flags from both inputs */
66610
- i64 iA; /* Integer value of left operand */
66611
- i64 iB; /* Integer value of right operand */
66612
- double rA; /* Real value of left operand */
66613
- double rB; /* Real value of right operand */
66614
- } ai;
66615
- struct OP_Function_stack_vars {
66616
- int i;
66617
- Mem *pArg;
66618
- sqlite3_context ctx;
66619
- sqlite3_value **apVal;
66620
- int n;
66621
- } aj;
66622
- struct OP_ShiftRight_stack_vars {
66623
- i64 iA;
66624
- u64 uA;
66625
- i64 iB;
66626
- u8 op;
66627
- } ak;
66628
- struct OP_Ge_stack_vars {
66629
- int res; /* Result of the comparison of pIn1 against pIn3 */
66630
- char affinity; /* Affinity to use for comparison */
66631
- u16 flags1; /* Copy of initial value of pIn1->flags */
66632
- u16 flags3; /* Copy of initial value of pIn3->flags */
66633
- } al;
66634
- struct OP_Compare_stack_vars {
66635
- int n;
66636
- int i;
66637
- int p1;
66638
- int p2;
66639
- const KeyInfo *pKeyInfo;
66640
- int idx;
66641
- CollSeq *pColl; /* Collating sequence to use on this term */
66642
- int bRev; /* True for DESCENDING sort order */
66643
- } am;
66644
- struct OP_Or_stack_vars {
66645
- int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66646
- int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66647
- } an;
66648
- struct OP_IfNot_stack_vars {
66649
- int c;
66650
- } ao;
66651
- struct OP_Column_stack_vars {
66652
- u32 payloadSize; /* Number of bytes in the record */
66653
- i64 payloadSize64; /* Number of bytes in the record */
66654
- int p1; /* P1 value of the opcode */
66655
- int p2; /* column number to retrieve */
66656
- VdbeCursor *pC; /* The VDBE cursor */
66657
- char *zRec; /* Pointer to complete record-data */
66658
- BtCursor *pCrsr; /* The BTree cursor */
66659
- u32 *aType; /* aType[i] holds the numeric type of the i-th column */
66660
- u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
66661
- int nField; /* number of fields in the record */
66662
- int len; /* The length of the serialized data for the column */
66663
- int i; /* Loop counter */
66664
- char *zData; /* Part of the record being decoded */
66665
- Mem *pDest; /* Where to write the extracted value */
66666
- Mem sMem; /* For storing the record being decoded */
66667
- u8 *zIdx; /* Index into header */
66668
- u8 *zEndHdr; /* Pointer to first byte after the header */
66669
- u32 offset; /* Offset into the data */
66670
- u32 szField; /* Number of bytes in the content of a field */
66671
- int szHdr; /* Size of the header size field at start of record */
66672
- int avail; /* Number of bytes of available data */
66673
- u32 t; /* A type code from the record header */
66674
- Mem *pReg; /* PseudoTable input register */
66675
- } ap;
66676
- struct OP_Affinity_stack_vars {
66677
- const char *zAffinity; /* The affinity to be applied */
66678
- char cAff; /* A single character of affinity */
66679
- } aq;
66680
- struct OP_MakeRecord_stack_vars {
66681
- u8 *zNewRecord; /* A buffer to hold the data for the new record */
66682
- Mem *pRec; /* The new record */
66683
- u64 nData; /* Number of bytes of data space */
66684
- int nHdr; /* Number of bytes of header space */
66685
- i64 nByte; /* Data space required for this record */
66686
- int nZero; /* Number of zero bytes at the end of the record */
66687
- int nVarint; /* Number of bytes in a varint */
66688
- u32 serial_type; /* Type field */
66689
- Mem *pData0; /* First field to be combined into the record */
66690
- Mem *pLast; /* Last field of the record */
66691
- int nField; /* Number of fields in the record */
66692
- char *zAffinity; /* The affinity string for the record */
66693
- int file_format; /* File format to use for encoding */
66694
- int i; /* Space used in zNewRecord[] */
66695
- int len; /* Length of a field */
66696
- } ar;
66697
- struct OP_Count_stack_vars {
66698
- i64 nEntry;
66699
- BtCursor *pCrsr;
66700
- } as;
66701
- struct OP_Savepoint_stack_vars {
66702
- int p1; /* Value of P1 operand */
66703
- char *zName; /* Name of savepoint */
66704
- int nName;
66705
- Savepoint *pNew;
66706
- Savepoint *pSavepoint;
66707
- Savepoint *pTmp;
66708
- int iSavepoint;
66709
- int ii;
66710
- } at;
66711
- struct OP_AutoCommit_stack_vars {
66712
- int desiredAutoCommit;
66713
- int iRollback;
66714
- int turnOnAC;
66715
- } au;
66716
- struct OP_Transaction_stack_vars {
66717
- Btree *pBt;
66718
- } av;
66719
- struct OP_ReadCookie_stack_vars {
66720
- int iMeta;
66721
- int iDb;
66722
- int iCookie;
66723
- } aw;
66724
- struct OP_SetCookie_stack_vars {
66725
- Db *pDb;
66726
- } ax;
66727
- struct OP_VerifyCookie_stack_vars {
66728
- int iMeta;
66729
- int iGen;
66730
- Btree *pBt;
66731
- } ay;
66732
- struct OP_OpenWrite_stack_vars {
66733
- int nField;
66734
- KeyInfo *pKeyInfo;
66735
- int p2;
66736
- int iDb;
66737
- int wrFlag;
66738
- Btree *pX;
66739
- VdbeCursor *pCur;
66740
- Db *pDb;
66741
- } az;
66742
- struct OP_OpenEphemeral_stack_vars {
66743
- VdbeCursor *pCx;
66744
- KeyInfo *pKeyInfo;
66745
- } ba;
66746
- struct OP_SorterOpen_stack_vars {
66747
- VdbeCursor *pCx;
66748
- } bb;
66749
- struct OP_OpenPseudo_stack_vars {
66750
- VdbeCursor *pCx;
66751
- } bc;
66752
- struct OP_SeekGt_stack_vars {
66753
- int res;
66754
- int oc;
66755
- VdbeCursor *pC;
66756
- UnpackedRecord r;
66757
- int nField;
66758
- i64 iKey; /* The rowid we are to seek to */
66759
- } bd;
66760
- struct OP_Seek_stack_vars {
66761
- VdbeCursor *pC;
66762
- } be;
66763
- struct OP_Found_stack_vars {
66764
- int alreadyExists;
66765
- int ii;
66766
- VdbeCursor *pC;
66767
- int res;
66768
- char *pFree;
66769
- UnpackedRecord *pIdxKey;
66770
- UnpackedRecord r;
66771
- char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
66772
- } bf;
66773
- struct OP_NotExists_stack_vars {
66774
- VdbeCursor *pC;
66775
- BtCursor *pCrsr;
66776
- int res;
66777
- u64 iKey;
66778
- } bg;
66779
- struct OP_NewRowid_stack_vars {
66780
- i64 v; /* The new rowid */
66781
- VdbeCursor *pC; /* Cursor of table to get the new rowid */
66782
- int res; /* Result of an sqlite3BtreeLast() */
66783
- int cnt; /* Counter to limit the number of searches */
66784
- Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
66785
- VdbeFrame *pFrame; /* Root frame of VDBE */
66786
- } bh;
66787
- struct OP_InsertInt_stack_vars {
66788
- Mem *pData; /* MEM cell holding data for the record to be inserted */
66789
- Mem *pKey; /* MEM cell holding key for the record */
66790
- i64 iKey; /* The integer ROWID or key for the record to be inserted */
66791
- VdbeCursor *pC; /* Cursor to table into which insert is written */
66792
- int nZero; /* Number of zero-bytes to append */
66793
- int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
66794
- const char *zDb; /* database name - used by the update hook */
66795
- const char *zTbl; /* Table name - used by the opdate hook */
66796
- int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
66797
- } bi;
66798
- struct OP_Delete_stack_vars {
66799
- i64 iKey;
66800
- VdbeCursor *pC;
66801
- } bj;
66802
- struct OP_SorterCompare_stack_vars {
66803
- VdbeCursor *pC;
66804
- int res;
66805
- int nIgnore;
66806
- } bk;
66807
- struct OP_SorterData_stack_vars {
66808
- VdbeCursor *pC;
66809
- } bl;
66810
- struct OP_RowData_stack_vars {
66811
- VdbeCursor *pC;
66812
- BtCursor *pCrsr;
66813
- u32 n;
66814
- i64 n64;
66815
- } bm;
66816
- struct OP_Rowid_stack_vars {
66817
- VdbeCursor *pC;
66818
- i64 v;
66819
- sqlite3_vtab *pVtab;
66820
- const sqlite3_module *pModule;
66821
- } bn;
66822
- struct OP_NullRow_stack_vars {
66823
- VdbeCursor *pC;
66824
- } bo;
66825
- struct OP_Last_stack_vars {
66826
- VdbeCursor *pC;
66827
- BtCursor *pCrsr;
66828
- int res;
66829
- } bp;
66830
- struct OP_Rewind_stack_vars {
66831
- VdbeCursor *pC;
66832
- BtCursor *pCrsr;
66833
- int res;
66834
- } bq;
66835
- struct OP_Next_stack_vars {
66836
- VdbeCursor *pC;
66837
- int res;
66838
- } br;
66839
- struct OP_IdxInsert_stack_vars {
66840
- VdbeCursor *pC;
66841
- BtCursor *pCrsr;
66842
- int nKey;
66843
- const char *zKey;
66844
- } bs;
66845
- struct OP_IdxDelete_stack_vars {
66846
- VdbeCursor *pC;
66847
- BtCursor *pCrsr;
66848
- int res;
66849
- UnpackedRecord r;
66850
- } bt;
66851
- struct OP_IdxRowid_stack_vars {
66852
- BtCursor *pCrsr;
66853
- VdbeCursor *pC;
66854
- i64 rowid;
66855
- } bu;
66856
- struct OP_IdxGE_stack_vars {
66857
- VdbeCursor *pC;
66858
- int res;
66859
- UnpackedRecord r;
66860
- } bv;
66861
- struct OP_Destroy_stack_vars {
66862
- int iMoved;
66863
- int iCnt;
66864
- Vdbe *pVdbe;
66865
- int iDb;
66866
- } bw;
66867
- struct OP_Clear_stack_vars {
66868
- int nChange;
66869
- } bx;
66870
- struct OP_CreateTable_stack_vars {
66871
- int pgno;
66872
- int flags;
66873
- Db *pDb;
66874
- } by;
66875
- struct OP_ParseSchema_stack_vars {
66876
- int iDb;
66877
- const char *zMaster;
66878
- char *zSql;
66879
- InitData initData;
66880
- } bz;
66881
- struct OP_IntegrityCk_stack_vars {
66882
- int nRoot; /* Number of tables to check. (Number of root pages.) */
66883
- int *aRoot; /* Array of rootpage numbers for tables to be checked */
66884
- int j; /* Loop counter */
66885
- int nErr; /* Number of errors reported */
66886
- char *z; /* Text of the error report */
66887
- Mem *pnErr; /* Register keeping track of errors remaining */
66888
- } ca;
66889
- struct OP_RowSetRead_stack_vars {
66890
- i64 val;
66891
- } cb;
66892
- struct OP_RowSetTest_stack_vars {
66893
- int iSet;
66894
- int exists;
66895
- } cc;
66896
- struct OP_Program_stack_vars {
66897
- int nMem; /* Number of memory registers for sub-program */
66898
- int nByte; /* Bytes of runtime space required for sub-program */
66899
- Mem *pRt; /* Register to allocate runtime space */
66900
- Mem *pMem; /* Used to iterate through memory cells */
66901
- Mem *pEnd; /* Last memory cell in new array */
66902
- VdbeFrame *pFrame; /* New vdbe frame to execute in */
66903
- SubProgram *pProgram; /* Sub-program to execute */
66904
- void *t; /* Token identifying trigger */
66905
- } cd;
66906
- struct OP_Param_stack_vars {
66907
- VdbeFrame *pFrame;
66908
- Mem *pIn;
66909
- } ce;
66910
- struct OP_MemMax_stack_vars {
66911
- Mem *pIn1;
66912
- VdbeFrame *pFrame;
66913
- } cf;
66914
- struct OP_AggStep_stack_vars {
66915
- int n;
66916
- int i;
66917
- Mem *pMem;
66918
- Mem *pRec;
66919
- sqlite3_context ctx;
66920
- sqlite3_value **apVal;
66921
- } cg;
66922
- struct OP_AggFinal_stack_vars {
66923
- Mem *pMem;
66924
- } ch;
66925
- struct OP_Checkpoint_stack_vars {
66926
- int i; /* Loop counter */
66927
- int aRes[3]; /* Results */
66928
- Mem *pMem; /* Write results here */
66929
- } ci;
66930
- struct OP_JournalMode_stack_vars {
66931
- Btree *pBt; /* Btree to change journal mode of */
66932
- Pager *pPager; /* Pager associated with pBt */
66933
- int eNew; /* New journal mode */
66934
- int eOld; /* The old journal mode */
66935
-#ifndef SQLITE_OMIT_WAL
66936
- const char *zFilename; /* Name of database file for pPager */
66937
-#endif
66938
- } cj;
66939
- struct OP_IncrVacuum_stack_vars {
66940
- Btree *pBt;
66941
- } ck;
66942
- struct OP_VBegin_stack_vars {
66943
- VTable *pVTab;
66944
- } cl;
66945
- struct OP_VOpen_stack_vars {
66946
- VdbeCursor *pCur;
66947
- sqlite3_vtab_cursor *pVtabCursor;
66948
- sqlite3_vtab *pVtab;
66949
- sqlite3_module *pModule;
66950
- } cm;
66951
- struct OP_VFilter_stack_vars {
66952
- int nArg;
66953
- int iQuery;
66954
- const sqlite3_module *pModule;
66955
- Mem *pQuery;
66956
- Mem *pArgc;
66957
- sqlite3_vtab_cursor *pVtabCursor;
66958
- sqlite3_vtab *pVtab;
66959
- VdbeCursor *pCur;
66960
- int res;
66961
- int i;
66962
- Mem **apArg;
66963
- } cn;
66964
- struct OP_VColumn_stack_vars {
66965
- sqlite3_vtab *pVtab;
66966
- const sqlite3_module *pModule;
66967
- Mem *pDest;
66968
- sqlite3_context sContext;
66969
- } co;
66970
- struct OP_VNext_stack_vars {
66971
- sqlite3_vtab *pVtab;
66972
- const sqlite3_module *pModule;
66973
- int res;
66974
- VdbeCursor *pCur;
66975
- } cp;
66976
- struct OP_VRename_stack_vars {
66977
- sqlite3_vtab *pVtab;
66978
- Mem *pName;
66979
- } cq;
66980
- struct OP_VUpdate_stack_vars {
66981
- sqlite3_vtab *pVtab;
66982
- sqlite3_module *pModule;
66983
- int nArg;
66984
- int i;
66985
- sqlite_int64 rowid;
66986
- Mem **apArg;
66987
- Mem *pX;
66988
- } cr;
66989
- struct OP_Trace_stack_vars {
66990
- char *zTrace;
66991
- char *z;
66992
- } cs;
66993
- } u;
66994
- /* End automatically generated code
66995
- ********************************************************************/
66657
+ /*** INSERT STACK UNION HERE ***/
6699666658
6699766659
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
6699866660
sqlite3VdbeEnter(p);
6699966661
if( p->rc==SQLITE_NOMEM ){
6700066662
/* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67021,17 +66683,32 @@
6702166683
}
6702266684
}
6702366685
#endif
6702466686
#ifdef SQLITE_DEBUG
6702566687
sqlite3BeginBenignMalloc();
67026
- if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
66688
+ if( p->pc==0
66689
+ && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
66690
+ ){
6702766691
int i;
67028
- printf("VDBE Program Listing:\n");
66692
+ int once = 1;
6702966693
sqlite3VdbePrintSql(p);
67030
- for(i=0; i<p->nOp; i++){
67031
- sqlite3VdbePrintOp(stdout, i, &aOp[i]);
66694
+ if( p->db->flags & SQLITE_VdbeListing ){
66695
+ printf("VDBE Program Listing:\n");
66696
+ for(i=0; i<p->nOp; i++){
66697
+ sqlite3VdbePrintOp(stdout, i, &aOp[i]);
66698
+ }
6703266699
}
66700
+ if( p->db->flags & SQLITE_VdbeEQP ){
66701
+ for(i=0; i<p->nOp; i++){
66702
+ if( aOp[i].opcode==OP_Explain ){
66703
+ if( once ) printf("VDBE Query Plan:\n");
66704
+ printf("%s\n", aOp[i].p4.z);
66705
+ once = 0;
66706
+ }
66707
+ }
66708
+ }
66709
+ if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
6703366710
}
6703466711
sqlite3EndBenignMalloc();
6703566712
#endif
6703666713
for(pc=p->pc; rc==SQLITE_OK; pc++){
6703766714
assert( pc>=0 && pc<p->nOp );
@@ -67044,16 +66721,12 @@
6704466721
pOp = &aOp[pc];
6704566722
6704666723
/* Only allow tracing if SQLITE_DEBUG is defined.
6704766724
*/
6704866725
#ifdef SQLITE_DEBUG
67049
- if( p->trace ){
67050
- if( pc==0 ){
67051
- printf("VDBE Execution Trace:\n");
67052
- sqlite3VdbePrintSql(p);
67053
- }
67054
- sqlite3VdbePrintOp(p->trace, pc, pOp);
66726
+ if( db->flags & SQLITE_VdbeTrace ){
66727
+ sqlite3VdbePrintOp(stdout, pc, pOp);
6705566728
}
6705666729
#endif
6705766730
6705866731
6705966732
/* Check to see if we need to simulate an interrupt. This only happens
@@ -67180,19 +66853,16 @@
6718066853
** sqlite3VdbeExec() or since last time the progress callback was called).
6718166854
** If the progress callback returns non-zero, exit the virtual machine with
6718266855
** a return code SQLITE_ABORT.
6718366856
*/
6718466857
if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
67185
- int prc;
67186
- prc = db->xProgress(db->pProgressArg);
67187
- if( prc!=0 ){
66858
+ assert( db->nProgressOps!=0 );
66859
+ nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
66860
+ if( db->xProgress(db->pProgressArg) ){
6718866861
rc = SQLITE_INTERRUPT;
6718966862
goto vdbe_error_halt;
6719066863
}
67191
- if( db->xProgress!=0 ){
67192
- nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
67193
- }
6719466864
}
6719566865
#endif
6719666866
6719766867
break;
6719866868
}
@@ -67228,20 +66898,18 @@
6722866898
/* Opcode: Yield P1 * * * *
6722966899
**
6723066900
** Swap the program counter with the value in register P1.
6723166901
*/
6723266902
case OP_Yield: { /* in1 */
67233
-#if 0 /* local variables moved into u.aa */
6723466903
int pcDest;
67235
-#endif /* local variables moved into u.aa */
6723666904
pIn1 = &aMem[pOp->p1];
6723766905
assert( (pIn1->flags & MEM_Dyn)==0 );
6723866906
pIn1->flags = MEM_Int;
67239
- u.aa.pcDest = (int)pIn1->u.i;
66907
+ pcDest = (int)pIn1->u.i;
6724066908
pIn1->u.i = pc;
6724166909
REGISTER_TRACE(pOp->p1, pIn1);
67242
- pc = u.aa.pcDest;
66910
+ pc = pcDest;
6724366911
break;
6724466912
}
6724566913
6724666914
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
6724766915
** Synopsis: if r[P3] null then halt
@@ -67286,14 +66954,12 @@
6728666954
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
6728766955
** every program. So a jump past the last instruction of the program
6728866956
** is the same as executing Halt.
6728966957
*/
6729066958
case OP_Halt: {
67291
-#if 0 /* local variables moved into u.ab */
6729266959
const char *zType;
6729366960
const char *zLogFmt;
67294
-#endif /* local variables moved into u.ab */
6729566961
6729666962
if( pOp->p1==SQLITE_OK && p->pFrame ){
6729766963
/* Halt the sub-program. Return control to the parent frame. */
6729866964
VdbeFrame *pFrame = p->pFrame;
6729966965
p->pFrame = pFrame->pParent;
@@ -67300,11 +66966,11 @@
6730066966
p->nFrame--;
6730166967
sqlite3VdbeSetChanges(db, p->nChange);
6730266968
pc = sqlite3VdbeFrameRestore(pFrame);
6730366969
lastRowid = db->lastRowid;
6730466970
if( pOp->p2==OE_Ignore ){
67305
- /* Instruction pc is the OP_Program that invoked the sub-program
66971
+ /* Instruction pc is the OP_Program that invoked the sub-program
6730666972
** currently being halted. If the p2 instruction of this OP_Halt
6730766973
** instruction is set to OE_Ignore, then the sub-program is throwing
6730866974
** an IGNORE exception. In this case jump to the address specified
6730966975
** as the p2 of the calling OP_Program. */
6731066976
pc = p->aOp[pc].p2-1;
@@ -67323,25 +66989,25 @@
6732366989
assert( pOp->p5>=1 && pOp->p5<=4 );
6732466990
testcase( pOp->p5==1 );
6732566991
testcase( pOp->p5==2 );
6732666992
testcase( pOp->p5==3 );
6732766993
testcase( pOp->p5==4 );
67328
- u.ab.zType = azType[pOp->p5-1];
66994
+ zType = azType[pOp->p5-1];
6732966995
}else{
67330
- u.ab.zType = 0;
66996
+ zType = 0;
6733166997
}
67332
- assert( u.ab.zType!=0 || pOp->p4.z!=0 );
67333
- u.ab.zLogFmt = "abort at %d in [%s]: %s";
67334
- if( u.ab.zType && pOp->p4.z ){
67335
- sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67336
- u.ab.zType, pOp->p4.z);
66998
+ assert( zType!=0 || pOp->p4.z!=0 );
66999
+ zLogFmt = "abort at %d in [%s]: %s";
67000
+ if( zType && pOp->p4.z ){
67001
+ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67002
+ zType, pOp->p4.z);
6733767003
}else if( pOp->p4.z ){
6733867004
sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
6733967005
}else{
67340
- sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
67006
+ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
6734167007
}
67342
- sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
67008
+ sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
6734367009
}
6734467010
rc = sqlite3VdbeHalt(p);
6734567011
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
6734667012
if( rc==SQLITE_BUSY ){
6734767013
p->rc = rc = SQLITE_BUSY;
@@ -67451,23 +67117,21 @@
6745167117
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
6745267118
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
6745367119
** OP_Ne or OP_Eq.
6745467120
*/
6745567121
case OP_Null: { /* out2-prerelease */
67456
-#if 0 /* local variables moved into u.ac */
6745767122
int cnt;
6745867123
u16 nullFlag;
67459
-#endif /* local variables moved into u.ac */
67460
- u.ac.cnt = pOp->p3-pOp->p2;
67124
+ cnt = pOp->p3-pOp->p2;
6746167125
assert( pOp->p3<=(p->nMem-p->nCursor) );
67462
- pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67463
- while( u.ac.cnt>0 ){
67126
+ pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67127
+ while( cnt>0 ){
6746467128
pOut++;
6746567129
memAboutToChange(p, pOut);
6746667130
VdbeMemRelease(pOut);
67467
- pOut->flags = u.ac.nullFlag;
67468
- u.ac.cnt--;
67131
+ pOut->flags = nullFlag;
67132
+ cnt--;
6746967133
}
6747067134
break;
6747167135
}
6747267136
6747367137
@@ -67492,21 +67156,19 @@
6749267156
**
6749367157
** If the parameter is named, then its name appears in P4 and P3==1.
6749467158
** The P4 value is used by sqlite3_bind_parameter_name().
6749567159
*/
6749667160
case OP_Variable: { /* out2-prerelease */
67497
-#if 0 /* local variables moved into u.ad */
6749867161
Mem *pVar; /* Value being transferred */
67499
-#endif /* local variables moved into u.ad */
6750067162
6750167163
assert( pOp->p1>0 && pOp->p1<=p->nVar );
6750267164
assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67503
- u.ad.pVar = &p->aVar[pOp->p1 - 1];
67504
- if( sqlite3VdbeMemTooBig(u.ad.pVar) ){
67165
+ pVar = &p->aVar[pOp->p1 - 1];
67166
+ if( sqlite3VdbeMemTooBig(pVar) ){
6750567167
goto too_big;
6750667168
}
67507
- sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
67169
+ sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
6750867170
UPDATE_MAX_BLOBSIZE(pOut);
6750967171
break;
6751067172
}
6751167173
6751267174
/* Opcode: Move P1 P2 P3 * *
@@ -67516,43 +67178,41 @@
6751667178
** registers P2..P2+P3. Registers P1..P1+P3 are
6751767179
** left holding a NULL. It is an error for register ranges
6751867180
** P1..P1+P3 and P2..P2+P3 to overlap.
6751967181
*/
6752067182
case OP_Move: {
67521
-#if 0 /* local variables moved into u.ae */
6752267183
char *zMalloc; /* Holding variable for allocated memory */
6752367184
int n; /* Number of registers left to copy */
6752467185
int p1; /* Register to copy from */
6752567186
int p2; /* Register to copy to */
67526
-#endif /* local variables moved into u.ae */
67527
-
67528
- u.ae.n = pOp->p3 + 1;
67529
- u.ae.p1 = pOp->p1;
67530
- u.ae.p2 = pOp->p2;
67531
- assert( u.ae.n>0 && u.ae.p1>0 && u.ae.p2>0 );
67532
- assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67533
-
67534
- pIn1 = &aMem[u.ae.p1];
67535
- pOut = &aMem[u.ae.p2];
67536
- while( u.ae.n-- ){
67187
+
67188
+ n = pOp->p3;
67189
+ p1 = pOp->p1;
67190
+ p2 = pOp->p2;
67191
+ assert( n>=0 && p1>0 && p2>0 );
67192
+ assert( p1+n<=p2 || p2+n<=p1 );
67193
+
67194
+ pIn1 = &aMem[p1];
67195
+ pOut = &aMem[p2];
67196
+ do{
6753767197
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6753867198
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6753967199
assert( memIsValid(pIn1) );
6754067200
memAboutToChange(p, pOut);
67541
- u.ae.zMalloc = pOut->zMalloc;
67201
+ zMalloc = pOut->zMalloc;
6754267202
pOut->zMalloc = 0;
6754367203
sqlite3VdbeMemMove(pOut, pIn1);
6754467204
#ifdef SQLITE_DEBUG
67545
- if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){
67546
- pOut->pScopyFrom += u.ae.p1 - pOp->p2;
67205
+ if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
67206
+ pOut->pScopyFrom += p1 - pOp->p2;
6754767207
}
6754867208
#endif
67549
- pIn1->zMalloc = u.ae.zMalloc;
67550
- REGISTER_TRACE(u.ae.p2++, pOut);
67209
+ pIn1->zMalloc = zMalloc;
67210
+ REGISTER_TRACE(p2++, pOut);
6755167211
pIn1++;
6755267212
pOut++;
67553
- }
67213
+ }while( n-- );
6755467214
break;
6755567215
}
6755667216
6755767217
/* Opcode: Copy P1 P2 P3 * *
6755867218
** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67561,26 +67221,24 @@
6756167221
**
6756267222
** This instruction makes a deep copy of the value. A duplicate
6756367223
** is made of any string or blob constant. See also OP_SCopy.
6756467224
*/
6756567225
case OP_Copy: {
67566
-#if 0 /* local variables moved into u.af */
6756767226
int n;
67568
-#endif /* local variables moved into u.af */
6756967227
67570
- u.af.n = pOp->p3;
67228
+ n = pOp->p3;
6757167229
pIn1 = &aMem[pOp->p1];
6757267230
pOut = &aMem[pOp->p2];
6757367231
assert( pOut!=pIn1 );
6757467232
while( 1 ){
6757567233
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
6757667234
Deephemeralize(pOut);
6757767235
#ifdef SQLITE_DEBUG
6757867236
pOut->pScopyFrom = 0;
6757967237
#endif
67580
- REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut);
67581
- if( (u.af.n--)==0 ) break;
67238
+ REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
67239
+ if( (n--)==0 ) break;
6758267240
pOut++;
6758367241
pIn1++;
6758467242
}
6758567243
break;
6758667244
}
@@ -67617,17 +67275,27 @@
6761767275
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
6761867276
** structure to provide access to the top P1 values as the result
6761967277
** row.
6762067278
*/
6762167279
case OP_ResultRow: {
67622
-#if 0 /* local variables moved into u.ag */
6762367280
Mem *pMem;
6762467281
int i;
67625
-#endif /* local variables moved into u.ag */
6762667282
assert( p->nResColumn==pOp->p2 );
6762767283
assert( pOp->p1>0 );
6762867284
assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67285
+
67286
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67287
+ /* Run the progress counter just before returning.
67288
+ */
67289
+ if( db->xProgress!=0
67290
+ && nVmStep>=nProgressLimit
67291
+ && db->xProgress(db->pProgressArg)!=0
67292
+ ){
67293
+ rc = SQLITE_INTERRUPT;
67294
+ goto vdbe_error_halt;
67295
+ }
67296
+#endif
6762967297
6763067298
/* If this statement has violated immediate foreign key constraints, do
6763167299
** not return the number of rows modified. And do not RELEASE the statement
6763267300
** transaction. It needs to be rolled back. */
6763367301
if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
@@ -67634,12 +67302,12 @@
6763467302
assert( db->flags&SQLITE_CountRows );
6763567303
assert( p->usesStmtJournal );
6763667304
break;
6763767305
}
6763867306
67639
- /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67640
- ** DML statements invoke this opcode to return the number of rows
67307
+ /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67308
+ ** DML statements invoke this opcode to return the number of rows
6764167309
** modified to the user. This is the only way that a VM that
6764267310
** opens a statement transaction may invoke this opcode.
6764367311
**
6764467312
** In case this is such a statement, close any statement transaction
6764567313
** opened by this VM before returning control to the user. This is to
@@ -67662,19 +67330,19 @@
6766267330
6766367331
/* Make sure the results of the current row are \000 terminated
6766467332
** and have an assigned type. The results are de-ephemeralized as
6766567333
** a side effect.
6766667334
*/
67667
- u.ag.pMem = p->pResultSet = &aMem[pOp->p1];
67668
- for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){
67669
- assert( memIsValid(&u.ag.pMem[u.ag.i]) );
67670
- Deephemeralize(&u.ag.pMem[u.ag.i]);
67671
- assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0
67672
- || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 );
67673
- sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]);
67674
- sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]);
67675
- REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]);
67335
+ pMem = p->pResultSet = &aMem[pOp->p1];
67336
+ for(i=0; i<pOp->p2; i++){
67337
+ assert( memIsValid(&pMem[i]) );
67338
+ Deephemeralize(&pMem[i]);
67339
+ assert( (pMem[i].flags & MEM_Ephem)==0
67340
+ || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
67341
+ sqlite3VdbeMemNulTerminate(&pMem[i]);
67342
+ sqlite3VdbeMemStoreType(&pMem[i]);
67343
+ REGISTER_TRACE(pOp->p1+i, &pMem[i]);
6767667344
}
6767767345
if( db->mallocFailed ) goto no_mem;
6767867346
6767967347
/* Return SQLITE_ROW
6768067348
*/
@@ -67695,13 +67363,11 @@
6769567363
** It is illegal for P1 and P3 to be the same register. Sometimes,
6769667364
** if P3 is the same register as P2, the implementation is able
6769767365
** to avoid a memcpy().
6769867366
*/
6769967367
case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67700
-#if 0 /* local variables moved into u.ah */
6770167368
i64 nByte;
67702
-#endif /* local variables moved into u.ah */
6770367369
6770467370
pIn1 = &aMem[pOp->p1];
6770567371
pIn2 = &aMem[pOp->p2];
6770667372
pOut = &aMem[pOp->p3];
6770767373
assert( pIn1!=pOut );
@@ -67710,26 +67376,26 @@
6771067376
break;
6771167377
}
6771267378
if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
6771367379
Stringify(pIn1, encoding);
6771467380
Stringify(pIn2, encoding);
67715
- u.ah.nByte = pIn1->n + pIn2->n;
67716
- if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67381
+ nByte = pIn1->n + pIn2->n;
67382
+ if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6771767383
goto too_big;
6771867384
}
6771967385
MemSetTypeFlag(pOut, MEM_Str);
67720
- if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
67386
+ if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
6772167387
goto no_mem;
6772267388
}
6772367389
if( pOut!=pIn2 ){
6772467390
memcpy(pOut->z, pIn2->z, pIn2->n);
6772567391
}
6772667392
memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67727
- pOut->z[u.ah.nByte]=0;
67728
- pOut->z[u.ah.nByte+1] = 0;
67393
+ pOut->z[nByte]=0;
67394
+ pOut->z[nByte+1] = 0;
6772967395
pOut->flags |= MEM_Term;
67730
- pOut->n = (int)u.ah.nByte;
67396
+ pOut->n = (int)nByte;
6773167397
pOut->enc = encoding;
6773267398
UPDATE_MAX_BLOBSIZE(pOut);
6773367399
break;
6773467400
}
6773567401
@@ -67754,103 +67420,101 @@
6775467420
** Subtract the value in register P1 from the value in register P2
6775567421
** and store the result in register P3.
6775667422
** If either input is NULL, the result is NULL.
6775767423
*/
6775867424
/* Opcode: Divide P1 P2 P3 * *
67759
-** Synopsis: r[P3]=r[P1]/r[P2]
67425
+** Synopsis: r[P3]=r[P2]/r[P1]
6776067426
**
6776167427
** Divide the value in register P1 by the value in register P2
6776267428
** and store the result in register P3 (P3=P2/P1). If the value in
6776367429
** register P1 is zero, then the result is NULL. If either input is
6776467430
** NULL, the result is NULL.
6776567431
*/
6776667432
/* Opcode: Remainder P1 P2 P3 * *
67767
-** Synopsis: r[P3]=r[P1]%r[P2]
67433
+** Synopsis: r[P3]=r[P2]%r[P1]
6776867434
**
67769
-** Compute the remainder after integer division of the value in
67770
-** register P1 by the value in register P2 and store the result in P3.
67771
-** If the value in register P2 is zero the result is NULL.
67435
+** Compute the remainder after integer register P2 is divided by
67436
+** register P1 and store the result in register P3.
67437
+** If the value in register P1 is zero the result is NULL.
6777267438
** If either operand is NULL, the result is NULL.
6777367439
*/
6777467440
case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
6777567441
case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
6777667442
case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
6777767443
case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
6777867444
case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67779
-#if 0 /* local variables moved into u.ai */
6778067445
char bIntint; /* Started out as two integer operands */
6778167446
int flags; /* Combined MEM_* flags from both inputs */
6778267447
i64 iA; /* Integer value of left operand */
6778367448
i64 iB; /* Integer value of right operand */
6778467449
double rA; /* Real value of left operand */
6778567450
double rB; /* Real value of right operand */
67786
-#endif /* local variables moved into u.ai */
6778767451
6778867452
pIn1 = &aMem[pOp->p1];
6778967453
applyNumericAffinity(pIn1);
6779067454
pIn2 = &aMem[pOp->p2];
6779167455
applyNumericAffinity(pIn2);
6779267456
pOut = &aMem[pOp->p3];
67793
- u.ai.flags = pIn1->flags | pIn2->flags;
67794
- if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67457
+ flags = pIn1->flags | pIn2->flags;
67458
+ if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
6779567459
if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67796
- u.ai.iA = pIn1->u.i;
67797
- u.ai.iB = pIn2->u.i;
67798
- u.ai.bIntint = 1;
67460
+ iA = pIn1->u.i;
67461
+ iB = pIn2->u.i;
67462
+ bIntint = 1;
6779967463
switch( pOp->opcode ){
67800
- case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67801
- case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67802
- case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67464
+ case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
67465
+ case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
67466
+ case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break;
6780367467
case OP_Divide: {
67804
- if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67805
- if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math;
67806
- u.ai.iB /= u.ai.iA;
67468
+ if( iA==0 ) goto arithmetic_result_is_null;
67469
+ if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math;
67470
+ iB /= iA;
6780767471
break;
6780867472
}
6780967473
default: {
67810
- if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67811
- if( u.ai.iA==-1 ) u.ai.iA = 1;
67812
- u.ai.iB %= u.ai.iA;
67474
+ if( iA==0 ) goto arithmetic_result_is_null;
67475
+ if( iA==-1 ) iA = 1;
67476
+ iB %= iA;
6781367477
break;
6781467478
}
6781567479
}
67816
- pOut->u.i = u.ai.iB;
67480
+ pOut->u.i = iB;
6781767481
MemSetTypeFlag(pOut, MEM_Int);
6781867482
}else{
67819
- u.ai.bIntint = 0;
67483
+ bIntint = 0;
6782067484
fp_math:
67821
- u.ai.rA = sqlite3VdbeRealValue(pIn1);
67822
- u.ai.rB = sqlite3VdbeRealValue(pIn2);
67485
+ rA = sqlite3VdbeRealValue(pIn1);
67486
+ rB = sqlite3VdbeRealValue(pIn2);
6782367487
switch( pOp->opcode ){
67824
- case OP_Add: u.ai.rB += u.ai.rA; break;
67825
- case OP_Subtract: u.ai.rB -= u.ai.rA; break;
67826
- case OP_Multiply: u.ai.rB *= u.ai.rA; break;
67488
+ case OP_Add: rB += rA; break;
67489
+ case OP_Subtract: rB -= rA; break;
67490
+ case OP_Multiply: rB *= rA; break;
6782767491
case OP_Divide: {
6782867492
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67829
- if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null;
67830
- u.ai.rB /= u.ai.rA;
67493
+ if( rA==(double)0 ) goto arithmetic_result_is_null;
67494
+ rB /= rA;
6783167495
break;
6783267496
}
6783367497
default: {
67834
- u.ai.iA = (i64)u.ai.rA;
67835
- u.ai.iB = (i64)u.ai.rB;
67836
- if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67837
- if( u.ai.iA==-1 ) u.ai.iA = 1;
67838
- u.ai.rB = (double)(u.ai.iB % u.ai.iA);
67498
+ iA = (i64)rA;
67499
+ iB = (i64)rB;
67500
+ if( iA==0 ) goto arithmetic_result_is_null;
67501
+ if( iA==-1 ) iA = 1;
67502
+ rB = (double)(iB % iA);
6783967503
break;
6784067504
}
6784167505
}
6784267506
#ifdef SQLITE_OMIT_FLOATING_POINT
67843
- pOut->u.i = u.ai.rB;
67507
+ pOut->u.i = rB;
6784467508
MemSetTypeFlag(pOut, MEM_Int);
6784567509
#else
67846
- if( sqlite3IsNaN(u.ai.rB) ){
67510
+ if( sqlite3IsNaN(rB) ){
6784767511
goto arithmetic_result_is_null;
6784867512
}
67849
- pOut->r = u.ai.rB;
67513
+ pOut->r = rB;
6785067514
MemSetTypeFlag(pOut, MEM_Real);
67851
- if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
67515
+ if( (flags & MEM_Real)==0 && !bIntint ){
6785267516
sqlite3VdbeIntegerAffinity(pOut);
6785367517
}
6785467518
#endif
6785567519
}
6785667520
break;
@@ -67899,85 +67563,83 @@
6789967563
** invocation of this opcode.
6790067564
**
6790167565
** See also: AggStep and AggFinal
6790267566
*/
6790367567
case OP_Function: {
67904
-#if 0 /* local variables moved into u.aj */
6790567568
int i;
6790667569
Mem *pArg;
6790767570
sqlite3_context ctx;
6790867571
sqlite3_value **apVal;
6790967572
int n;
67910
-#endif /* local variables moved into u.aj */
6791167573
67912
- u.aj.n = pOp->p5;
67913
- u.aj.apVal = p->apArg;
67914
- assert( u.aj.apVal || u.aj.n==0 );
67574
+ n = pOp->p5;
67575
+ apVal = p->apArg;
67576
+ assert( apVal || n==0 );
6791567577
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
6791667578
pOut = &aMem[pOp->p3];
6791767579
memAboutToChange(p, pOut);
6791867580
67919
- assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) );
67920
- assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n );
67921
- u.aj.pArg = &aMem[pOp->p2];
67922
- for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){
67923
- assert( memIsValid(u.aj.pArg) );
67924
- u.aj.apVal[u.aj.i] = u.aj.pArg;
67925
- Deephemeralize(u.aj.pArg);
67926
- sqlite3VdbeMemStoreType(u.aj.pArg);
67927
- REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
67581
+ assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) );
67582
+ assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
67583
+ pArg = &aMem[pOp->p2];
67584
+ for(i=0; i<n; i++, pArg++){
67585
+ assert( memIsValid(pArg) );
67586
+ apVal[i] = pArg;
67587
+ Deephemeralize(pArg);
67588
+ sqlite3VdbeMemStoreType(pArg);
67589
+ REGISTER_TRACE(pOp->p2+i, pArg);
6792867590
}
6792967591
6793067592
assert( pOp->p4type==P4_FUNCDEF );
67931
- u.aj.ctx.pFunc = pOp->p4.pFunc;
67932
- u.aj.ctx.s.flags = MEM_Null;
67933
- u.aj.ctx.s.db = db;
67934
- u.aj.ctx.s.xDel = 0;
67935
- u.aj.ctx.s.zMalloc = 0;
67936
- u.aj.ctx.iOp = pc;
67937
- u.aj.ctx.pVdbe = p;
67593
+ ctx.pFunc = pOp->p4.pFunc;
67594
+ ctx.iOp = pc;
67595
+ ctx.pVdbe = p;
6793867596
6793967597
/* The output cell may already have a buffer allocated. Move
67940
- ** the pointer to u.aj.ctx.s so in case the user-function can use
67598
+ ** the pointer to ctx.s so in case the user-function can use
6794167599
** the already allocated buffer instead of allocating a new one.
6794267600
*/
67943
- sqlite3VdbeMemMove(&u.aj.ctx.s, pOut);
67944
- MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
67601
+ memcpy(&ctx.s, pOut, sizeof(Mem));
67602
+ pOut->flags = MEM_Null;
67603
+ pOut->xDel = 0;
67604
+ pOut->zMalloc = 0;
67605
+ MemSetTypeFlag(&ctx.s, MEM_Null);
6794567606
67946
- u.aj.ctx.fErrorOrAux = 0;
67947
- if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67607
+ ctx.fErrorOrAux = 0;
67608
+ if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
6794867609
assert( pOp>aOp );
6794967610
assert( pOp[-1].p4type==P4_COLLSEQ );
6795067611
assert( pOp[-1].opcode==OP_CollSeq );
67951
- u.aj.ctx.pColl = pOp[-1].p4.pColl;
67612
+ ctx.pColl = pOp[-1].p4.pColl;
6795267613
}
6795367614
db->lastRowid = lastRowid;
67954
- (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */
67615
+ (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
6795567616
lastRowid = db->lastRowid;
6795667617
6795767618
if( db->mallocFailed ){
6795867619
/* Even though a malloc() has failed, the implementation of the
6795967620
** user function may have called an sqlite3_result_XXX() function
6796067621
** to return a value. The following call releases any resources
6796167622
** associated with such a value.
6796267623
*/
67963
- sqlite3VdbeMemRelease(&u.aj.ctx.s);
67624
+ sqlite3VdbeMemRelease(&ctx.s);
6796467625
goto no_mem;
6796567626
}
6796667627
6796767628
/* If the function returned an error, throw an exception */
67968
- if( u.aj.ctx.fErrorOrAux ){
67969
- if( u.aj.ctx.isError ){
67970
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s));
67971
- rc = u.aj.ctx.isError;
67629
+ if( ctx.fErrorOrAux ){
67630
+ if( ctx.isError ){
67631
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
67632
+ rc = ctx.isError;
6797267633
}
6797367634
sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
6797467635
}
6797567636
6797667637
/* Copy the result of the function into register P3 */
67977
- sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
67978
- sqlite3VdbeMemMove(pOut, &u.aj.ctx.s);
67638
+ sqlite3VdbeChangeEncoding(&ctx.s, encoding);
67639
+ assert( pOut->flags==MEM_Null );
67640
+ memcpy(pOut, &ctx.s, sizeof(Mem));
6797967641
if( sqlite3VdbeMemTooBig(pOut) ){
6798067642
goto too_big;
6798167643
}
6798267644
6798367645
#if 0
@@ -68025,56 +67687,54 @@
6802567687
*/
6802667688
case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
6802767689
case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
6802867690
case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
6802967691
case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
68030
-#if 0 /* local variables moved into u.ak */
6803167692
i64 iA;
6803267693
u64 uA;
6803367694
i64 iB;
6803467695
u8 op;
68035
-#endif /* local variables moved into u.ak */
6803667696
6803767697
pIn1 = &aMem[pOp->p1];
6803867698
pIn2 = &aMem[pOp->p2];
6803967699
pOut = &aMem[pOp->p3];
6804067700
if( (pIn1->flags | pIn2->flags) & MEM_Null ){
6804167701
sqlite3VdbeMemSetNull(pOut);
6804267702
break;
6804367703
}
68044
- u.ak.iA = sqlite3VdbeIntValue(pIn2);
68045
- u.ak.iB = sqlite3VdbeIntValue(pIn1);
68046
- u.ak.op = pOp->opcode;
68047
- if( u.ak.op==OP_BitAnd ){
68048
- u.ak.iA &= u.ak.iB;
68049
- }else if( u.ak.op==OP_BitOr ){
68050
- u.ak.iA |= u.ak.iB;
68051
- }else if( u.ak.iB!=0 ){
68052
- assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft );
67704
+ iA = sqlite3VdbeIntValue(pIn2);
67705
+ iB = sqlite3VdbeIntValue(pIn1);
67706
+ op = pOp->opcode;
67707
+ if( op==OP_BitAnd ){
67708
+ iA &= iB;
67709
+ }else if( op==OP_BitOr ){
67710
+ iA |= iB;
67711
+ }else if( iB!=0 ){
67712
+ assert( op==OP_ShiftRight || op==OP_ShiftLeft );
6805367713
6805467714
/* If shifting by a negative amount, shift in the other direction */
68055
- if( u.ak.iB<0 ){
67715
+ if( iB<0 ){
6805667716
assert( OP_ShiftRight==OP_ShiftLeft+1 );
68057
- u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op;
68058
- u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64;
67717
+ op = 2*OP_ShiftLeft + 1 - op;
67718
+ iB = iB>(-64) ? -iB : 64;
6805967719
}
6806067720
68061
- if( u.ak.iB>=64 ){
68062
- u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1;
68063
- }else{
68064
- memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA));
68065
- if( u.ak.op==OP_ShiftLeft ){
68066
- u.ak.uA <<= u.ak.iB;
68067
- }else{
68068
- u.ak.uA >>= u.ak.iB;
67721
+ if( iB>=64 ){
67722
+ iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
67723
+ }else{
67724
+ memcpy(&uA, &iA, sizeof(uA));
67725
+ if( op==OP_ShiftLeft ){
67726
+ uA <<= iB;
67727
+ }else{
67728
+ uA >>= iB;
6806967729
/* Sign-extend on a right shift of a negative number */
68070
- if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB);
67730
+ if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
6807167731
}
68072
- memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
67732
+ memcpy(&iA, &uA, sizeof(iA));
6807367733
}
6807467734
}
68075
- pOut->u.i = u.ak.iA;
67735
+ pOut->u.i = iA;
6807667736
MemSetTypeFlag(pOut, MEM_Int);
6807767737
break;
6807867738
}
6807967739
6808067740
/* Opcode: AddImm P1 P2 * * *
@@ -68100,21 +67760,23 @@
6810067760
** without data loss, then jump immediately to P2, or if P2==0
6810167761
** raise an SQLITE_MISMATCH exception.
6810267762
*/
6810367763
case OP_MustBeInt: { /* jump, in1 */
6810467764
pIn1 = &aMem[pOp->p1];
68105
- applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
6810667765
if( (pIn1->flags & MEM_Int)==0 ){
68107
- if( pOp->p2==0 ){
68108
- rc = SQLITE_MISMATCH;
68109
- goto abort_due_to_error;
68110
- }else{
68111
- pc = pOp->p2 - 1;
68112
- }
68113
- }else{
68114
- MemSetTypeFlag(pIn1, MEM_Int);
68115
- }
67766
+ applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
67767
+ if( (pIn1->flags & MEM_Int)==0 ){
67768
+ if( pOp->p2==0 ){
67769
+ rc = SQLITE_MISMATCH;
67770
+ goto abort_due_to_error;
67771
+ }else{
67772
+ pc = pOp->p2 - 1;
67773
+ break;
67774
+ }
67775
+ }
67776
+ }
67777
+ MemSetTypeFlag(pIn1, MEM_Int);
6811667778
break;
6811767779
}
6811867780
6811967781
#ifndef SQLITE_OMIT_FLOATING_POINT
6812067782
/* Opcode: RealAffinity P1 * * * *
@@ -68235,11 +67897,11 @@
6823567897
break;
6823667898
}
6823767899
#endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
6823867900
6823967901
/* Opcode: Lt P1 P2 P3 P4 P5
68240
-** Synopsis: if r[P1]<r[P3] goto P3
67902
+** Synopsis: if r[P1]<r[P3] goto P2
6824167903
**
6824267904
** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
6824367905
** jump to address P2.
6824467906
**
6824567907
** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -68322,37 +67984,35 @@
6832267984
case OP_Ne: /* same as TK_NE, jump, in1, in3 */
6832367985
case OP_Lt: /* same as TK_LT, jump, in1, in3 */
6832467986
case OP_Le: /* same as TK_LE, jump, in1, in3 */
6832567987
case OP_Gt: /* same as TK_GT, jump, in1, in3 */
6832667988
case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
68327
-#if 0 /* local variables moved into u.al */
6832867989
int res; /* Result of the comparison of pIn1 against pIn3 */
6832967990
char affinity; /* Affinity to use for comparison */
6833067991
u16 flags1; /* Copy of initial value of pIn1->flags */
6833167992
u16 flags3; /* Copy of initial value of pIn3->flags */
68332
-#endif /* local variables moved into u.al */
6833367993
6833467994
pIn1 = &aMem[pOp->p1];
6833567995
pIn3 = &aMem[pOp->p3];
68336
- u.al.flags1 = pIn1->flags;
68337
- u.al.flags3 = pIn3->flags;
68338
- if( (u.al.flags1 | u.al.flags3)&MEM_Null ){
67996
+ flags1 = pIn1->flags;
67997
+ flags3 = pIn3->flags;
67998
+ if( (flags1 | flags3)&MEM_Null ){
6833967999
/* One or both operands are NULL */
6834068000
if( pOp->p5 & SQLITE_NULLEQ ){
6834168001
/* If SQLITE_NULLEQ is set (which will only happen if the operator is
6834268002
** OP_Eq or OP_Ne) then take the jump or not depending on whether
6834368003
** or not both operands are null.
6834468004
*/
6834568005
assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68346
- assert( (u.al.flags1 & MEM_Cleared)==0 );
68347
- if( (u.al.flags1&MEM_Null)!=0
68348
- && (u.al.flags3&MEM_Null)!=0
68349
- && (u.al.flags3&MEM_Cleared)==0
68006
+ assert( (flags1 & MEM_Cleared)==0 );
68007
+ if( (flags1&MEM_Null)!=0
68008
+ && (flags3&MEM_Null)!=0
68009
+ && (flags3&MEM_Cleared)==0
6835068010
){
68351
- u.al.res = 0; /* Results are equal */
68011
+ res = 0; /* Results are equal */
6835268012
}else{
68353
- u.al.res = 1; /* Results are not equal */
68013
+ res = 1; /* Results are not equal */
6835468014
}
6835568015
}else{
6835668016
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
6835768017
** then the result is always NULL.
6835868018
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68366,44 +68026,44 @@
6836668026
}
6836768027
break;
6836868028
}
6836968029
}else{
6837068030
/* Neither operand is NULL. Do a comparison. */
68371
- u.al.affinity = pOp->p5 & SQLITE_AFF_MASK;
68372
- if( u.al.affinity ){
68373
- applyAffinity(pIn1, u.al.affinity, encoding);
68374
- applyAffinity(pIn3, u.al.affinity, encoding);
68031
+ affinity = pOp->p5 & SQLITE_AFF_MASK;
68032
+ if( affinity ){
68033
+ applyAffinity(pIn1, affinity, encoding);
68034
+ applyAffinity(pIn3, affinity, encoding);
6837568035
if( db->mallocFailed ) goto no_mem;
6837668036
}
6837768037
6837868038
assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
6837968039
ExpandBlob(pIn1);
6838068040
ExpandBlob(pIn3);
68381
- u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68041
+ res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
6838268042
}
6838368043
switch( pOp->opcode ){
68384
- case OP_Eq: u.al.res = u.al.res==0; break;
68385
- case OP_Ne: u.al.res = u.al.res!=0; break;
68386
- case OP_Lt: u.al.res = u.al.res<0; break;
68387
- case OP_Le: u.al.res = u.al.res<=0; break;
68388
- case OP_Gt: u.al.res = u.al.res>0; break;
68389
- default: u.al.res = u.al.res>=0; break;
68044
+ case OP_Eq: res = res==0; break;
68045
+ case OP_Ne: res = res!=0; break;
68046
+ case OP_Lt: res = res<0; break;
68047
+ case OP_Le: res = res<=0; break;
68048
+ case OP_Gt: res = res>0; break;
68049
+ default: res = res>=0; break;
6839068050
}
6839168051
6839268052
if( pOp->p5 & SQLITE_STOREP2 ){
6839368053
pOut = &aMem[pOp->p2];
6839468054
memAboutToChange(p, pOut);
6839568055
MemSetTypeFlag(pOut, MEM_Int);
68396
- pOut->u.i = u.al.res;
68056
+ pOut->u.i = res;
6839768057
REGISTER_TRACE(pOp->p2, pOut);
68398
- }else if( u.al.res ){
68058
+ }else if( res ){
6839968059
pc = pOp->p2-1;
6840068060
}
6840168061
6840268062
/* Undo any changes made by applyAffinity() to the input registers. */
68403
- pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask);
68404
- pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask);
68063
+ pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68064
+ pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
6840568065
break;
6840668066
}
6840768067
6840868068
/* Opcode: Permutation * * * P4 *
6840968069
**
@@ -68439,51 +68099,49 @@
6843968099
** The comparison is a sort comparison, so NULLs compare equal,
6844068100
** NULLs are less than numbers, numbers are less than strings,
6844168101
** and strings are less than blobs.
6844268102
*/
6844368103
case OP_Compare: {
68444
-#if 0 /* local variables moved into u.am */
6844568104
int n;
6844668105
int i;
6844768106
int p1;
6844868107
int p2;
6844968108
const KeyInfo *pKeyInfo;
6845068109
int idx;
6845168110
CollSeq *pColl; /* Collating sequence to use on this term */
6845268111
int bRev; /* True for DESCENDING sort order */
68453
-#endif /* local variables moved into u.am */
6845468112
6845568113
if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68456
- u.am.n = pOp->p3;
68457
- u.am.pKeyInfo = pOp->p4.pKeyInfo;
68458
- assert( u.am.n>0 );
68459
- assert( u.am.pKeyInfo!=0 );
68460
- u.am.p1 = pOp->p1;
68461
- u.am.p2 = pOp->p2;
68114
+ n = pOp->p3;
68115
+ pKeyInfo = pOp->p4.pKeyInfo;
68116
+ assert( n>0 );
68117
+ assert( pKeyInfo!=0 );
68118
+ p1 = pOp->p1;
68119
+ p2 = pOp->p2;
6846268120
#if SQLITE_DEBUG
6846368121
if( aPermute ){
6846468122
int k, mx = 0;
68465
- for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68466
- assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 );
68467
- assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 );
68123
+ for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68124
+ assert( p1>0 && p1+mx<=(p->nMem-p->nCursor)+1 );
68125
+ assert( p2>0 && p2+mx<=(p->nMem-p->nCursor)+1 );
6846868126
}else{
68469
- assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 );
68470
- assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 );
68127
+ assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 );
68128
+ assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 );
6847168129
}
6847268130
#endif /* SQLITE_DEBUG */
68473
- for(u.am.i=0; u.am.i<u.am.n; u.am.i++){
68474
- u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i;
68475
- assert( memIsValid(&aMem[u.am.p1+u.am.idx]) );
68476
- assert( memIsValid(&aMem[u.am.p2+u.am.idx]) );
68477
- REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]);
68478
- REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]);
68479
- assert( u.am.i<u.am.pKeyInfo->nField );
68480
- u.am.pColl = u.am.pKeyInfo->aColl[u.am.i];
68481
- u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i];
68482
- iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl);
68131
+ for(i=0; i<n; i++){
68132
+ idx = aPermute ? aPermute[i] : i;
68133
+ assert( memIsValid(&aMem[p1+idx]) );
68134
+ assert( memIsValid(&aMem[p2+idx]) );
68135
+ REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
68136
+ REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
68137
+ assert( i<pKeyInfo->nField );
68138
+ pColl = pKeyInfo->aColl[i];
68139
+ bRev = pKeyInfo->aSortOrder[i];
68140
+ iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
6848368141
if( iCompare ){
68484
- if( u.am.bRev ) iCompare = -iCompare;
68142
+ if( bRev ) iCompare = -iCompare;
6848568143
break;
6848668144
}
6848768145
}
6848868146
aPermute = 0;
6848968147
break;
@@ -68526,39 +68184,37 @@
6852668184
** even if the other input is NULL. A NULL and false or two NULLs
6852768185
** give a NULL output.
6852868186
*/
6852968187
case OP_And: /* same as TK_AND, in1, in2, out3 */
6853068188
case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68531
-#if 0 /* local variables moved into u.an */
6853268189
int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
6853368190
int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68534
-#endif /* local variables moved into u.an */
6853568191
6853668192
pIn1 = &aMem[pOp->p1];
6853768193
if( pIn1->flags & MEM_Null ){
68538
- u.an.v1 = 2;
68194
+ v1 = 2;
6853968195
}else{
68540
- u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68196
+ v1 = sqlite3VdbeIntValue(pIn1)!=0;
6854168197
}
6854268198
pIn2 = &aMem[pOp->p2];
6854368199
if( pIn2->flags & MEM_Null ){
68544
- u.an.v2 = 2;
68200
+ v2 = 2;
6854568201
}else{
68546
- u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68202
+ v2 = sqlite3VdbeIntValue(pIn2)!=0;
6854768203
}
6854868204
if( pOp->opcode==OP_And ){
6854968205
static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68550
- u.an.v1 = and_logic[u.an.v1*3+u.an.v2];
68206
+ v1 = and_logic[v1*3+v2];
6855168207
}else{
6855268208
static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68553
- u.an.v1 = or_logic[u.an.v1*3+u.an.v2];
68209
+ v1 = or_logic[v1*3+v2];
6855468210
}
6855568211
pOut = &aMem[pOp->p3];
68556
- if( u.an.v1==2 ){
68212
+ if( v1==2 ){
6855768213
MemSetTypeFlag(pOut, MEM_Null);
6855868214
}else{
68559
- pOut->u.i = u.an.v1;
68215
+ pOut->u.i = v1;
6856068216
MemSetTypeFlag(pOut, MEM_Int);
6856168217
}
6856268218
break;
6856368219
}
6856468220
@@ -68625,25 +68281,23 @@
6862568281
** is considered false if it has a numeric value of zero. If the value
6862668282
** in P1 is NULL then take the jump if P3 is zero.
6862768283
*/
6862868284
case OP_If: /* jump, in1 */
6862968285
case OP_IfNot: { /* jump, in1 */
68630
-#if 0 /* local variables moved into u.ao */
6863168286
int c;
68632
-#endif /* local variables moved into u.ao */
6863368287
pIn1 = &aMem[pOp->p1];
6863468288
if( pIn1->flags & MEM_Null ){
68635
- u.ao.c = pOp->p3;
68289
+ c = pOp->p3;
6863668290
}else{
6863768291
#ifdef SQLITE_OMIT_FLOATING_POINT
68638
- u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
68292
+ c = sqlite3VdbeIntValue(pIn1)!=0;
6863968293
#else
68640
- u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68294
+ c = sqlite3VdbeRealValue(pIn1)!=0.0;
6864168295
#endif
68642
- if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
68296
+ if( pOp->opcode==OP_IfNot ) c = !c;
6864368297
}
68644
- if( u.ao.c ){
68298
+ if( c ){
6864568299
pc = pOp->p2-1;
6864668300
}
6864768301
break;
6864868302
}
6864968303
@@ -68697,157 +68351,107 @@
6869768351
** the result is guaranteed to only be used as the argument of a length()
6869868352
** or typeof() function, respectively. The loading of large blobs can be
6869968353
** skipped for length() and all content loading can be skipped for typeof().
6870068354
*/
6870168355
case OP_Column: {
68702
-#if 0 /* local variables moved into u.ap */
68703
- u32 payloadSize; /* Number of bytes in the record */
6870468356
i64 payloadSize64; /* Number of bytes in the record */
68705
- int p1; /* P1 value of the opcode */
6870668357
int p2; /* column number to retrieve */
6870768358
VdbeCursor *pC; /* The VDBE cursor */
68708
- char *zRec; /* Pointer to complete record-data */
6870968359
BtCursor *pCrsr; /* The BTree cursor */
6871068360
u32 *aType; /* aType[i] holds the numeric type of the i-th column */
6871168361
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
68712
- int nField; /* number of fields in the record */
6871368362
int len; /* The length of the serialized data for the column */
6871468363
int i; /* Loop counter */
68715
- char *zData; /* Part of the record being decoded */
6871668364
Mem *pDest; /* Where to write the extracted value */
6871768365
Mem sMem; /* For storing the record being decoded */
68718
- u8 *zIdx; /* Index into header */
68719
- u8 *zEndHdr; /* Pointer to first byte after the header */
68366
+ const u8 *zData; /* Part of the record being decoded */
68367
+ const u8 *zHdr; /* Next unparsed byte of the header */
68368
+ const u8 *zEndHdr; /* Pointer to first byte after the header */
6872068369
u32 offset; /* Offset into the data */
6872168370
u32 szField; /* Number of bytes in the content of a field */
68722
- int szHdr; /* Size of the header size field at start of record */
68723
- int avail; /* Number of bytes of available data */
68371
+ u32 avail; /* Number of bytes of available data */
6872468372
u32 t; /* A type code from the record header */
6872568373
Mem *pReg; /* PseudoTable input register */
68726
-#endif /* local variables moved into u.ap */
68727
-
68728
-
68729
- u.ap.p1 = pOp->p1;
68730
- u.ap.p2 = pOp->p2;
68731
- u.ap.pC = 0;
68732
- memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
68733
- assert( u.ap.p1<p->nCursor );
68374
+
68375
+ p2 = pOp->p2;
6873468376
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68735
- u.ap.pDest = &aMem[pOp->p3];
68736
- memAboutToChange(p, u.ap.pDest);
68737
- u.ap.zRec = 0;
68738
-
68739
- /* This block sets the variable u.ap.payloadSize to be the total number of
68740
- ** bytes in the record.
68741
- **
68742
- ** u.ap.zRec is set to be the complete text of the record if it is available.
68743
- ** The complete record text is always available for pseudo-tables
68744
- ** If the record is stored in a cursor, the complete record text
68745
- ** might be available in the u.ap.pC->aRow cache. Or it might not be.
68746
- ** If the data is unavailable, u.ap.zRec is set to NULL.
68747
- **
68748
- ** We also compute the number of columns in the record. For cursors,
68749
- ** the number of columns is stored in the VdbeCursor.nField element.
68750
- */
68751
- u.ap.pC = p->apCsr[u.ap.p1];
68752
- assert( u.ap.pC!=0 );
68377
+ pDest = &aMem[pOp->p3];
68378
+ memAboutToChange(p, pDest);
68379
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68380
+ pC = p->apCsr[pOp->p1];
68381
+ assert( pC!=0 );
68382
+ assert( p2<pC->nField );
68383
+ aType = pC->aType;
68384
+ aOffset = aType + pC->nField;
6875368385
#ifndef SQLITE_OMIT_VIRTUALTABLE
68754
- assert( u.ap.pC->pVtabCursor==0 );
68755
-#endif
68756
- u.ap.pCrsr = u.ap.pC->pCursor;
68757
- if( u.ap.pCrsr!=0 ){
68758
- /* The record is stored in a B-Tree */
68759
- rc = sqlite3VdbeCursorMoveto(u.ap.pC);
68760
- if( rc ) goto abort_due_to_error;
68761
- if( u.ap.pC->nullRow ){
68762
- u.ap.payloadSize = 0;
68763
- }else if( u.ap.pC->cacheStatus==p->cacheCtr ){
68764
- u.ap.payloadSize = u.ap.pC->payloadSize;
68765
- u.ap.zRec = (char*)u.ap.pC->aRow;
68766
- }else if( u.ap.pC->isIndex ){
68767
- assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68768
- VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
68769
- assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68770
- /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68771
- ** payload size, so it is impossible for u.ap.payloadSize64 to be
68772
- ** larger than 32 bits. */
68773
- assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
68774
- u.ap.payloadSize = (u32)u.ap.payloadSize64;
68775
- }else{
68776
- assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68777
- VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.payloadSize);
68778
- assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68779
- }
68780
- }else{
68781
- assert( u.ap.pC->pseudoTableReg>0 );
68782
- u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
68783
- if( u.ap.pC->multiPseudo ){
68784
- sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
68785
- Deephemeralize(u.ap.pDest);
68786
- goto op_column_out;
68787
- }
68788
- assert( u.ap.pReg->flags & MEM_Blob );
68789
- assert( memIsValid(u.ap.pReg) );
68790
- u.ap.payloadSize = u.ap.pReg->n;
68791
- u.ap.zRec = u.ap.pReg->z;
68792
- u.ap.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
68793
- assert( u.ap.payloadSize==0 || u.ap.zRec!=0 );
68794
- }
68795
-
68796
- /* If u.ap.payloadSize is 0, then just store a NULL. This can happen because of
68797
- ** nullRow or because of a corrupt database. */
68798
- if( u.ap.payloadSize==0 ){
68799
- MemSetTypeFlag(u.ap.pDest, MEM_Null);
68800
- goto op_column_out;
68801
- }
68802
- assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
68803
- if( u.ap.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68804
- goto too_big;
68805
- }
68806
-
68807
- u.ap.nField = u.ap.pC->nField;
68808
- assert( u.ap.p2<u.ap.nField );
68809
-
68810
- /* Read and parse the table header. Store the results of the parse
68811
- ** into the record header cache fields of the cursor.
68812
- */
68813
- u.ap.aType = u.ap.pC->aType;
68814
- if( u.ap.pC->cacheStatus==p->cacheCtr ){
68815
- u.ap.aOffset = u.ap.pC->aOffset;
68816
- }else{
68817
- assert(u.ap.aType);
68818
- u.ap.avail = 0;
68819
- u.ap.pC->aOffset = u.ap.aOffset = &u.ap.aType[u.ap.nField];
68820
- u.ap.pC->payloadSize = u.ap.payloadSize;
68821
- u.ap.pC->cacheStatus = p->cacheCtr;
68822
-
68823
- /* Figure out how many bytes are in the header */
68824
- if( u.ap.zRec ){
68825
- u.ap.zData = u.ap.zRec;
68826
- }else{
68827
- if( u.ap.pC->isIndex ){
68828
- u.ap.zData = (char*)sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
68829
- }else{
68830
- u.ap.zData = (char*)sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
68831
- }
68832
- /* If KeyFetch()/DataFetch() managed to get the entire payload,
68833
- ** save the payload in the u.ap.pC->aRow cache. That will save us from
68834
- ** having to make additional calls to fetch the content portion of
68835
- ** the record.
68836
- */
68837
- assert( u.ap.avail>=0 );
68838
- if( u.ap.payloadSize <= (u32)u.ap.avail ){
68839
- u.ap.zRec = u.ap.zData;
68840
- u.ap.pC->aRow = (u8*)u.ap.zData;
68841
- }else{
68842
- u.ap.pC->aRow = 0;
68843
- }
68844
- }
68845
- /* The following assert is true in all cases except when
68846
- ** the database file has been corrupted externally.
68847
- ** assert( u.ap.zRec!=0 || u.ap.avail>=u.ap.payloadSize || u.ap.avail>=9 ); */
68848
- u.ap.szHdr = getVarint32((u8*)u.ap.zData, u.ap.offset);
68386
+ assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
68387
+#endif
68388
+ pCrsr = pC->pCursor;
68389
+ assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
68390
+ assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
68391
+
68392
+ /* If the cursor cache is stale, bring it up-to-date */
68393
+ rc = sqlite3VdbeCursorMoveto(pC);
68394
+ if( rc ) goto abort_due_to_error;
68395
+ if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68396
+ if( pC->nullRow ){
68397
+ if( pCrsr==0 ){
68398
+ assert( pC->pseudoTableReg>0 );
68399
+ pReg = &aMem[pC->pseudoTableReg];
68400
+ if( pC->multiPseudo ){
68401
+ sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68402
+ Deephemeralize(pDest);
68403
+ goto op_column_out;
68404
+ }
68405
+ assert( pReg->flags & MEM_Blob );
68406
+ assert( memIsValid(pReg) );
68407
+ pC->payloadSize = pC->szRow = avail = pReg->n;
68408
+ pC->aRow = (u8*)pReg->z;
68409
+ }else{
68410
+ MemSetTypeFlag(pDest, MEM_Null);
68411
+ goto op_column_out;
68412
+ }
68413
+ }else{
68414
+ assert( pCrsr );
68415
+ if( pC->isTable==0 ){
68416
+ assert( sqlite3BtreeCursorIsValid(pCrsr) );
68417
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64);
68418
+ assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68419
+ /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68420
+ ** payload size, so it is impossible for payloadSize64 to be
68421
+ ** larger than 32 bits. */
68422
+ assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
68423
+ pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail);
68424
+ pC->payloadSize = (u32)payloadSize64;
68425
+ }else{
68426
+ assert( sqlite3BtreeCursorIsValid(pCrsr) );
68427
+ VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize);
68428
+ assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68429
+ pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail);
68430
+ }
68431
+ assert( avail<=65536 ); /* Maximum page size is 64KiB */
68432
+ if( pC->payloadSize <= (u32)avail ){
68433
+ pC->szRow = pC->payloadSize;
68434
+ }else{
68435
+ pC->szRow = avail;
68436
+ }
68437
+ if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68438
+ goto too_big;
68439
+ }
68440
+ }
68441
+ pC->cacheStatus = p->cacheCtr;
68442
+ pC->iHdrOffset = getVarint32(pC->aRow, offset);
68443
+ pC->nHdrParsed = 0;
68444
+ aOffset[0] = offset;
68445
+ if( avail<offset ){
68446
+ /* pC->aRow does not have to hold the entire row, but it does at least
68447
+ ** need to cover the header of the record. If pC->aRow does not contain
68448
+ ** the complete header, then set it to zero, forcing the header to be
68449
+ ** dynamically allocated. */
68450
+ pC->aRow = 0;
68451
+ pC->szRow = 0;
68452
+ }
6884968453
6885068454
/* Make sure a corrupt database has not given us an oversize header.
6885168455
** Do this now to avoid an oversize memory allocation.
6885268456
**
6885368457
** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68854,161 +68458,154 @@
6885468458
** types use so much data space that there can only be 4096 and 32 of
6885568459
** them, respectively. So the maximum header length results from a
6885668460
** 3-byte type for each of the maximum of 32768 columns plus three
6885768461
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
6885868462
*/
68859
- if( u.ap.offset > 98307 ){
68860
- rc = SQLITE_CORRUPT_BKPT;
68861
- goto op_column_out;
68862
- }
68863
-
68864
- /* Compute in u.ap.len the number of bytes of data we need to read in order
68865
- ** to get u.ap.nField type values. u.ap.offset is an upper bound on this. But
68866
- ** u.ap.nField might be significantly less than the true number of columns
68867
- ** in the table, and in that case, 5*u.ap.nField+3 might be smaller than u.ap.offset.
68868
- ** We want to minimize u.ap.len in order to limit the size of the memory
68869
- ** allocation, especially if a corrupt database file has caused u.ap.offset
68870
- ** to be oversized. Offset is limited to 98307 above. But 98307 might
68871
- ** still exceed Robson memory allocation limits on some configurations.
68872
- ** On systems that cannot tolerate large memory allocations, u.ap.nField*5+3
68873
- ** will likely be much smaller since u.ap.nField will likely be less than
68874
- ** 20 or so. This insures that Robson memory allocation limits are
68875
- ** not exceeded even for corrupt database files.
68876
- */
68877
- u.ap.len = u.ap.nField*5 + 3;
68878
- if( u.ap.len > (int)u.ap.offset ) u.ap.len = (int)u.ap.offset;
68879
-
68880
- /* The KeyFetch() or DataFetch() above are fast and will get the entire
68881
- ** record header in most cases. But they will fail to get the complete
68882
- ** record header if the record header does not fit on a single page
68883
- ** in the B-Tree. When that happens, use sqlite3VdbeMemFromBtree() to
68884
- ** acquire the complete header text.
68885
- */
68886
- if( !u.ap.zRec && u.ap.avail<u.ap.len ){
68887
- u.ap.sMem.flags = 0;
68888
- u.ap.sMem.db = 0;
68889
- rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.len, u.ap.pC->isIndex, &u.ap.sMem);
68890
- if( rc!=SQLITE_OK ){
68891
- goto op_column_out;
68892
- }
68893
- u.ap.zData = u.ap.sMem.z;
68894
- }
68895
- u.ap.zEndHdr = (u8 *)&u.ap.zData[u.ap.len];
68896
- u.ap.zIdx = (u8 *)&u.ap.zData[u.ap.szHdr];
68897
-
68898
- /* Scan the header and use it to fill in the u.ap.aType[] and u.ap.aOffset[]
68899
- ** arrays. u.ap.aType[u.ap.i] will contain the type integer for the u.ap.i-th
68900
- ** column and u.ap.aOffset[u.ap.i] will contain the u.ap.offset from the beginning
68901
- ** of the record to the start of the data for the u.ap.i-th column
68902
- */
68903
- for(u.ap.i=0; u.ap.i<u.ap.nField; u.ap.i++){
68904
- if( u.ap.zIdx<u.ap.zEndHdr ){
68905
- u.ap.aOffset[u.ap.i] = u.ap.offset;
68906
- if( u.ap.zIdx[0]<0x80 ){
68907
- u.ap.t = u.ap.zIdx[0];
68908
- u.ap.zIdx++;
68909
- }else{
68910
- u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t);
68911
- }
68912
- u.ap.aType[u.ap.i] = u.ap.t;
68913
- u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68914
- u.ap.offset += u.ap.szField;
68915
- if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */
68916
- u.ap.zIdx = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68917
- break;
68918
- }
68919
- }else{
68920
- /* If u.ap.i is less that u.ap.nField, then there are fewer fields in this
68921
- ** record than SetNumColumns indicated there are columns in the
68922
- ** table. Set the u.ap.offset for any extra columns not present in
68923
- ** the record to 0. This tells code below to store the default value
68924
- ** for the column instead of deserializing a value from the record.
68925
- */
68926
- u.ap.aOffset[u.ap.i] = 0;
68927
- }
68928
- }
68929
- sqlite3VdbeMemRelease(&u.ap.sMem);
68930
- u.ap.sMem.flags = MEM_Null;
68931
-
68932
- /* If we have read more header data than was contained in the header,
68933
- ** or if the end of the last field appears to be past the end of the
68934
- ** record, or if the end of the last field appears to be before the end
68935
- ** of the record (when all fields present), then we must be dealing
68936
- ** with a corrupt database.
68937
- */
68938
- if( (u.ap.zIdx > u.ap.zEndHdr) || (u.ap.offset > u.ap.payloadSize)
68939
- || (u.ap.zIdx==u.ap.zEndHdr && u.ap.offset!=u.ap.payloadSize) ){
68940
- rc = SQLITE_CORRUPT_BKPT;
68941
- goto op_column_out;
68942
- }
68943
- }
68944
-
68945
- /* Get the column information. If u.ap.aOffset[u.ap.p2] is non-zero, then
68946
- ** deserialize the value from the record. If u.ap.aOffset[u.ap.p2] is zero,
68947
- ** then there are not enough fields in the record to satisfy the
68948
- ** request. In this case, set the value NULL or to P4 if P4 is
68949
- ** a pointer to a Mem object.
68950
- */
68951
- if( u.ap.aOffset[u.ap.p2] ){
68952
- assert( rc==SQLITE_OK );
68953
- if( u.ap.zRec ){
68954
- /* This is the common case where the whole row fits on a single page */
68955
- VdbeMemRelease(u.ap.pDest);
68956
- sqlite3VdbeSerialGet((u8 *)&u.ap.zRec[u.ap.aOffset[u.ap.p2]], u.ap.aType[u.ap.p2], u.ap.pDest);
68957
- }else{
68958
- /* This branch happens only when the row overflows onto multiple pages */
68959
- u.ap.t = u.ap.aType[u.ap.p2];
68960
- if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68961
- && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)
68962
- ){
68963
- /* Content is irrelevant for the typeof() function and for
68964
- ** the length(X) function if X is a blob. So we might as well use
68965
- ** bogus content rather than reading content from disk. NULL works
68966
- ** for text and blob and whatever is in the u.ap.payloadSize64 variable
68967
- ** will work for everything else. */
68968
- u.ap.zData = u.ap.t<12 ? (char*)&u.ap.payloadSize64 : 0;
68969
- }else{
68970
- u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t);
68971
- sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
68972
- rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, u.ap.pC->isIndex,
68973
- &u.ap.sMem);
68974
- if( rc!=SQLITE_OK ){
68975
- goto op_column_out;
68976
- }
68977
- u.ap.zData = u.ap.sMem.z;
68978
- }
68979
- sqlite3VdbeSerialGet((u8*)u.ap.zData, u.ap.t, u.ap.pDest);
68980
- }
68981
- u.ap.pDest->enc = encoding;
68982
- }else{
68983
- if( pOp->p4type==P4_MEM ){
68984
- sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
68985
- }else{
68986
- MemSetTypeFlag(u.ap.pDest, MEM_Null);
68987
- }
68988
- }
68989
-
68990
- /* If we dynamically allocated space to hold the data (in the
68991
- ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68992
- ** dynamically allocated space over to the u.ap.pDest structure.
68993
- ** This prevents a memory copy.
68994
- */
68995
- if( u.ap.sMem.zMalloc ){
68996
- assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
68997
- assert( !(u.ap.pDest->flags & MEM_Dyn) );
68998
- assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
68999
- u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
69000
- u.ap.pDest->flags |= MEM_Term;
69001
- u.ap.pDest->z = u.ap.sMem.z;
69002
- u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
69003
- }
69004
-
69005
- rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
69006
-
69007
-op_column_out:
69008
- UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69009
- REGISTER_TRACE(pOp->p3, u.ap.pDest);
68463
+ if( offset > 98307 || offset > pC->payloadSize ){
68464
+ rc = SQLITE_CORRUPT_BKPT;
68465
+ goto op_column_error;
68466
+ }
68467
+ }
68468
+
68469
+ /* Make sure at least the first p2+1 entries of the header have been
68470
+ ** parsed and valid information is in aOffset[] and aType[].
68471
+ */
68472
+ if( pC->nHdrParsed<=p2 ){
68473
+ /* If there is more header available for parsing in the record, try
68474
+ ** to extract additional fields up through the p2+1-th field
68475
+ */
68476
+ if( pC->iHdrOffset<aOffset[0] ){
68477
+ /* Make sure zData points to enough of the record to cover the header. */
68478
+ if( pC->aRow==0 ){
68479
+ memset(&sMem, 0, sizeof(sMem));
68480
+ rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
68481
+ !pC->isTable, &sMem);
68482
+ if( rc!=SQLITE_OK ){
68483
+ goto op_column_error;
68484
+ }
68485
+ zData = (u8*)sMem.z;
68486
+ }else{
68487
+ zData = pC->aRow;
68488
+ }
68489
+
68490
+ /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
68491
+ i = pC->nHdrParsed;
68492
+ offset = aOffset[i];
68493
+ zHdr = zData + pC->iHdrOffset;
68494
+ zEndHdr = zData + aOffset[0];
68495
+ assert( i<=p2 && zHdr<zEndHdr );
68496
+ do{
68497
+ if( zHdr[0]<0x80 ){
68498
+ t = zHdr[0];
68499
+ zHdr++;
68500
+ }else{
68501
+ zHdr += sqlite3GetVarint32(zHdr, &t);
68502
+ }
68503
+ aType[i] = t;
68504
+ szField = sqlite3VdbeSerialTypeLen(t);
68505
+ offset += szField;
68506
+ if( offset<szField ){ /* True if offset overflows */
68507
+ zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68508
+ break;
68509
+ }
68510
+ i++;
68511
+ aOffset[i] = offset;
68512
+ }while( i<=p2 && zHdr<zEndHdr );
68513
+ pC->nHdrParsed = i;
68514
+ pC->iHdrOffset = (u32)(zHdr - zData);
68515
+ if( pC->aRow==0 ){
68516
+ sqlite3VdbeMemRelease(&sMem);
68517
+ sMem.flags = MEM_Null;
68518
+ }
68519
+
68520
+ /* If we have read more header data than was contained in the header,
68521
+ ** or if the end of the last field appears to be past the end of the
68522
+ ** record, or if the end of the last field appears to be before the end
68523
+ ** of the record (when all fields present), then we must be dealing
68524
+ ** with a corrupt database.
68525
+ */
68526
+ if( (zHdr > zEndHdr)
68527
+ || (offset > pC->payloadSize)
68528
+ || (zHdr==zEndHdr && offset!=pC->payloadSize)
68529
+ ){
68530
+ rc = SQLITE_CORRUPT_BKPT;
68531
+ goto op_column_error;
68532
+ }
68533
+ }
68534
+
68535
+ /* If after trying to extra new entries from the header, nHdrParsed is
68536
+ ** still not up to p2, that means that the record has fewer than p2
68537
+ ** columns. So the result will be either the default value or a NULL.
68538
+ */
68539
+ if( pC->nHdrParsed<=p2 ){
68540
+ if( pOp->p4type==P4_MEM ){
68541
+ sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
68542
+ }else{
68543
+ MemSetTypeFlag(pDest, MEM_Null);
68544
+ }
68545
+ goto op_column_out;
68546
+ }
68547
+ }
68548
+
68549
+ /* Extract the content for the p2+1-th column. Control can only
68550
+ ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
68551
+ ** all valid.
68552
+ */
68553
+ assert( p2<pC->nHdrParsed );
68554
+ assert( rc==SQLITE_OK );
68555
+ if( pC->szRow>=aOffset[p2+1] ){
68556
+ /* This is the common case where the desired content fits on the original
68557
+ ** page - where the content is not on an overflow page */
68558
+ VdbeMemRelease(pDest);
68559
+ sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
68560
+ }else{
68561
+ /* This branch happens only when content is on overflow pages */
68562
+ t = aType[p2];
68563
+ if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68564
+ && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
68565
+ || (len = sqlite3VdbeSerialTypeLen(t))==0
68566
+ ){
68567
+ /* Content is irrelevant for the typeof() function and for
68568
+ ** the length(X) function if X is a blob. So we might as well use
68569
+ ** bogus content rather than reading content from disk. NULL works
68570
+ ** for text and blob and whatever is in the payloadSize64 variable
68571
+ ** will work for everything else. Content is also irrelevant if
68572
+ ** the content length is 0. */
68573
+ zData = t<=13 ? (u8*)&payloadSize64 : 0;
68574
+ sMem.zMalloc = 0;
68575
+ }else{
68576
+ memset(&sMem, 0, sizeof(sMem));
68577
+ sqlite3VdbeMemMove(&sMem, pDest);
68578
+ rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
68579
+ &sMem);
68580
+ if( rc!=SQLITE_OK ){
68581
+ goto op_column_error;
68582
+ }
68583
+ zData = (u8*)sMem.z;
68584
+ }
68585
+ sqlite3VdbeSerialGet(zData, t, pDest);
68586
+ /* If we dynamically allocated space to hold the data (in the
68587
+ ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68588
+ ** dynamically allocated space over to the pDest structure.
68589
+ ** This prevents a memory copy. */
68590
+ if( sMem.zMalloc ){
68591
+ assert( sMem.z==sMem.zMalloc );
68592
+ assert( !(pDest->flags & MEM_Dyn) );
68593
+ assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
68594
+ pDest->flags &= ~(MEM_Ephem|MEM_Static);
68595
+ pDest->flags |= MEM_Term;
68596
+ pDest->z = sMem.z;
68597
+ pDest->zMalloc = sMem.zMalloc;
68598
+ }
68599
+ }
68600
+ pDest->enc = encoding;
68601
+
68602
+op_column_out:
68603
+ Deephemeralize(pDest);
68604
+op_column_error:
68605
+ UPDATE_MAX_BLOBSIZE(pDest);
68606
+ REGISTER_TRACE(pOp->p3, pDest);
6901068607
break;
6901168608
}
6901268609
6901368610
/* Opcode: Affinity P1 P2 * P4 *
6901468611
** Synopsis: affinity(r[P1@P2])
@@ -69018,24 +68615,22 @@
6901868615
** P4 is a string that is P2 characters long. The nth character of the
6901968616
** string indicates the column affinity that should be used for the nth
6902068617
** memory cell in the range.
6902168618
*/
6902268619
case OP_Affinity: {
69023
-#if 0 /* local variables moved into u.aq */
6902468620
const char *zAffinity; /* The affinity to be applied */
6902568621
char cAff; /* A single character of affinity */
69026
-#endif /* local variables moved into u.aq */
6902768622
69028
- u.aq.zAffinity = pOp->p4.z;
69029
- assert( u.aq.zAffinity!=0 );
69030
- assert( u.aq.zAffinity[pOp->p2]==0 );
68623
+ zAffinity = pOp->p4.z;
68624
+ assert( zAffinity!=0 );
68625
+ assert( zAffinity[pOp->p2]==0 );
6903168626
pIn1 = &aMem[pOp->p1];
69032
- while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
68627
+ while( (cAff = *(zAffinity++))!=0 ){
6903368628
assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
6903468629
assert( memIsValid(pIn1) );
6903568630
ExpandBlob(pIn1);
69036
- applyAffinity(pIn1, u.aq.cAff, encoding);
68631
+ applyAffinity(pIn1, cAff, encoding);
6903768632
pIn1++;
6903868633
}
6903968634
break;
6904068635
}
6904168636
@@ -69054,11 +68649,10 @@
6905468649
** macros defined in sqliteInt.h.
6905568650
**
6905668651
** If P4 is NULL then all index fields have the affinity NONE.
6905768652
*/
6905868653
case OP_MakeRecord: {
69059
-#if 0 /* local variables moved into u.ar */
6906068654
u8 *zNewRecord; /* A buffer to hold the data for the new record */
6906168655
Mem *pRec; /* The new record */
6906268656
u64 nData; /* Number of bytes of data space */
6906368657
int nHdr; /* Number of bytes of header space */
6906468658
i64 nByte; /* Data space required for this record */
@@ -69068,106 +68662,123 @@
6906868662
Mem *pData0; /* First field to be combined into the record */
6906968663
Mem *pLast; /* Last field of the record */
6907068664
int nField; /* Number of fields in the record */
6907168665
char *zAffinity; /* The affinity string for the record */
6907268666
int file_format; /* File format to use for encoding */
69073
- int i; /* Space used in zNewRecord[] */
68667
+ int i; /* Space used in zNewRecord[] header */
68668
+ int j; /* Space used in zNewRecord[] content */
6907468669
int len; /* Length of a field */
69075
-#endif /* local variables moved into u.ar */
6907668670
6907768671
/* Assuming the record contains N fields, the record format looks
6907868672
** like this:
6907968673
**
6908068674
** ------------------------------------------------------------------------
69081
- ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
68675
+ ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
6908268676
** ------------------------------------------------------------------------
6908368677
**
6908468678
** Data(0) is taken from register P1. Data(1) comes from register P1+1
6908568679
** and so froth.
6908668680
**
69087
- ** Each type field is a varint representing the serial type of the
68681
+ ** Each type field is a varint representing the serial type of the
6908868682
** corresponding data element (see sqlite3VdbeSerialType()). The
6908968683
** hdr-size field is also a varint which is the offset from the beginning
6909068684
** of the record to data0.
6909168685
*/
69092
- u.ar.nData = 0; /* Number of bytes of data space */
69093
- u.ar.nHdr = 0; /* Number of bytes of header space */
69094
- u.ar.nZero = 0; /* Number of zero bytes at the end of the record */
69095
- u.ar.nField = pOp->p1;
69096
- u.ar.zAffinity = pOp->p4.z;
69097
- assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 );
69098
- u.ar.pData0 = &aMem[u.ar.nField];
69099
- u.ar.nField = pOp->p2;
69100
- u.ar.pLast = &u.ar.pData0[u.ar.nField-1];
69101
- u.ar.file_format = p->minWriteFileFormat;
68686
+ nData = 0; /* Number of bytes of data space */
68687
+ nHdr = 0; /* Number of bytes of header space */
68688
+ nZero = 0; /* Number of zero bytes at the end of the record */
68689
+ nField = pOp->p1;
68690
+ zAffinity = pOp->p4.z;
68691
+ assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem-p->nCursor)+1 );
68692
+ pData0 = &aMem[nField];
68693
+ nField = pOp->p2;
68694
+ pLast = &pData0[nField-1];
68695
+ file_format = p->minWriteFileFormat;
6910268696
6910368697
/* Identify the output register */
6910468698
assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
6910568699
pOut = &aMem[pOp->p3];
6910668700
memAboutToChange(p, pOut);
68701
+
68702
+ /* Apply the requested affinity to all inputs
68703
+ */
68704
+ assert( pData0<=pLast );
68705
+ if( zAffinity ){
68706
+ pRec = pData0;
68707
+ do{
68708
+ applyAffinity(pRec, *(zAffinity++), encoding);
68709
+ }while( (++pRec)<=pLast );
68710
+ }
6910768711
6910868712
/* Loop through the elements that will make up the record to figure
6910968713
** out how much space is required for the new record.
6911068714
*/
69111
- for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69112
- assert( memIsValid(u.ar.pRec) );
69113
- if( u.ar.zAffinity ){
69114
- applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding);
69115
- }
69116
- if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){
69117
- sqlite3VdbeMemExpandBlob(u.ar.pRec);
69118
- }
69119
- u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69120
- u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type);
69121
- u.ar.nData += u.ar.len;
69122
- u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type);
69123
- if( u.ar.pRec->flags & MEM_Zero ){
69124
- /* Only pure zero-filled BLOBs can be input to this Opcode.
69125
- ** We do not allow blobs with a prefix and a zero-filled tail. */
69126
- u.ar.nZero += u.ar.pRec->u.nZero;
69127
- }else if( u.ar.len ){
69128
- u.ar.nZero = 0;
69129
- }
69130
- }
68715
+ pRec = pLast;
68716
+ do{
68717
+ assert( memIsValid(pRec) );
68718
+ serial_type = sqlite3VdbeSerialType(pRec, file_format);
68719
+ len = sqlite3VdbeSerialTypeLen(serial_type);
68720
+ if( pRec->flags & MEM_Zero ){
68721
+ if( nData ){
68722
+ sqlite3VdbeMemExpandBlob(pRec);
68723
+ }else{
68724
+ nZero += pRec->u.nZero;
68725
+ len -= pRec->u.nZero;
68726
+ }
68727
+ }
68728
+ nData += len;
68729
+ testcase( serial_type==127 );
68730
+ testcase( serial_type==128 );
68731
+ nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
68732
+ }while( (--pRec)>=pData0 );
6913168733
6913268734
/* Add the initial header varint and total the size */
69133
- u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr);
69134
- if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){
69135
- u.ar.nHdr++;
68735
+ testcase( nHdr==126 );
68736
+ testcase( nHdr==127 );
68737
+ if( nHdr<=126 ){
68738
+ /* The common case */
68739
+ nHdr += 1;
68740
+ }else{
68741
+ /* Rare case of a really large header */
68742
+ nVarint = sqlite3VarintLen(nHdr);
68743
+ nHdr += nVarint;
68744
+ if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
6913668745
}
69137
- u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero;
69138
- if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
68746
+ nByte = nHdr+nData;
68747
+ if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6913968748
goto too_big;
6914068749
}
6914168750
69142
- /* Make sure the output register has a buffer large enough to store
68751
+ /* Make sure the output register has a buffer large enough to store
6914368752
** the new record. The output register (pOp->p3) is not allowed to
6914468753
** be one of the input registers (because the following call to
6914568754
** sqlite3VdbeMemGrow() could clobber the value before it is used).
6914668755
*/
69147
- if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
68756
+ if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
6914868757
goto no_mem;
6914968758
}
69150
- u.ar.zNewRecord = (u8 *)pOut->z;
68759
+ zNewRecord = (u8 *)pOut->z;
6915168760
6915268761
/* Write the record */
69153
- u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr);
69154
- for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69155
- u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69156
- u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */
69157
- }
69158
- for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */
69159
- u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format);
69160
- }
69161
- assert( u.ar.i==u.ar.nByte );
68762
+ i = putVarint32(zNewRecord, nHdr);
68763
+ j = nHdr;
68764
+ assert( pData0<=pLast );
68765
+ pRec = pData0;
68766
+ do{
68767
+ serial_type = sqlite3VdbeSerialType(pRec, file_format);
68768
+ i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
68769
+ j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
68770
+ }while( (++pRec)<=pLast );
68771
+ assert( i==nHdr );
68772
+ assert( j==nByte );
6916268773
6916368774
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69164
- pOut->n = (int)u.ar.nByte;
68775
+ pOut->n = (int)nByte;
6916568776
pOut->flags = MEM_Blob | MEM_Dyn;
6916668777
pOut->xDel = 0;
69167
- if( u.ar.nZero ){
69168
- pOut->u.nZero = u.ar.nZero;
68778
+ if( nZero ){
68779
+ pOut->u.nZero = nZero;
6916968780
pOut->flags |= MEM_Zero;
6917068781
}
6917168782
pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
6917268783
REGISTER_TRACE(pOp->p3, pOut);
6917368784
UPDATE_MAX_BLOBSIZE(pOut);
@@ -69180,19 +68791,18 @@
6918068791
** Store the number of entries (an integer value) in the table or index
6918168792
** opened by cursor P1 in register P2
6918268793
*/
6918368794
#ifndef SQLITE_OMIT_BTREECOUNT
6918468795
case OP_Count: { /* out2-prerelease */
69185
-#if 0 /* local variables moved into u.as */
6918668796
i64 nEntry;
6918768797
BtCursor *pCrsr;
69188
-#endif /* local variables moved into u.as */
6918968798
69190
- u.as.pCrsr = p->apCsr[pOp->p1]->pCursor;
69191
- assert( u.as.pCrsr );
69192
- rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry);
69193
- pOut->u.i = u.as.nEntry;
68799
+ pCrsr = p->apCsr[pOp->p1]->pCursor;
68800
+ assert( pCrsr );
68801
+ nEntry = 0; /* Not needed. Only used to silence a warning. */
68802
+ rc = sqlite3BtreeCount(pCrsr, &nEntry);
68803
+ pOut->u.i = nEntry;
6919468804
break;
6919568805
}
6919668806
#endif
6919768807
6919868808
/* Opcode: Savepoint P1 * * P4 *
@@ -69200,43 +68810,41 @@
6920068810
** Open, release or rollback the savepoint named by parameter P4, depending
6920168811
** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
6920268812
** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
6920368813
*/
6920468814
case OP_Savepoint: {
69205
-#if 0 /* local variables moved into u.at */
6920668815
int p1; /* Value of P1 operand */
6920768816
char *zName; /* Name of savepoint */
6920868817
int nName;
6920968818
Savepoint *pNew;
6921068819
Savepoint *pSavepoint;
6921168820
Savepoint *pTmp;
6921268821
int iSavepoint;
6921368822
int ii;
69214
-#endif /* local variables moved into u.at */
6921568823
69216
- u.at.p1 = pOp->p1;
69217
- u.at.zName = pOp->p4.z;
68824
+ p1 = pOp->p1;
68825
+ zName = pOp->p4.z;
6921868826
69219
- /* Assert that the u.at.p1 parameter is valid. Also that if there is no open
69220
- ** transaction, then there cannot be any savepoints.
68827
+ /* Assert that the p1 parameter is valid. Also that if there is no open
68828
+ ** transaction, then there cannot be any savepoints.
6922168829
*/
6922268830
assert( db->pSavepoint==0 || db->autoCommit==0 );
69223
- assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK );
68831
+ assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK );
6922468832
assert( db->pSavepoint || db->isTransactionSavepoint==0 );
6922568833
assert( checkSavepointCount(db) );
6922668834
assert( p->bIsReader );
6922768835
69228
- if( u.at.p1==SAVEPOINT_BEGIN ){
68836
+ if( p1==SAVEPOINT_BEGIN ){
6922968837
if( db->nVdbeWrite>0 ){
69230
- /* A new savepoint cannot be created if there are active write
68838
+ /* A new savepoint cannot be created if there are active write
6923168839
** statements (i.e. open read/write incremental blob handles).
6923268840
*/
6923368841
sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
6923468842
"SQL statements in progress");
6923568843
rc = SQLITE_BUSY;
6923668844
}else{
69237
- u.at.nName = sqlite3Strlen30(u.at.zName);
68845
+ nName = sqlite3Strlen30(zName);
6923868846
6923968847
#ifndef SQLITE_OMIT_VIRTUALTABLE
6924068848
/* This call is Ok even if this savepoint is actually a transaction
6924168849
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
6924268850
** If this is a transaction savepoint being opened, it is guaranteed
@@ -69246,62 +68854,62 @@
6924668854
db->nStatement+db->nSavepoint);
6924768855
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6924868856
#endif
6924968857
6925068858
/* Create a new savepoint structure. */
69251
- u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1);
69252
- if( u.at.pNew ){
69253
- u.at.pNew->zName = (char *)&u.at.pNew[1];
69254
- memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1);
69255
-
68859
+ pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
68860
+ if( pNew ){
68861
+ pNew->zName = (char *)&pNew[1];
68862
+ memcpy(pNew->zName, zName, nName+1);
68863
+
6925668864
/* If there is no open transaction, then mark this as a special
6925768865
** "transaction savepoint". */
6925868866
if( db->autoCommit ){
6925968867
db->autoCommit = 0;
6926068868
db->isTransactionSavepoint = 1;
6926168869
}else{
6926268870
db->nSavepoint++;
6926368871
}
69264
-
68872
+
6926568873
/* Link the new savepoint into the database handle's list. */
69266
- u.at.pNew->pNext = db->pSavepoint;
69267
- db->pSavepoint = u.at.pNew;
69268
- u.at.pNew->nDeferredCons = db->nDeferredCons;
69269
- u.at.pNew->nDeferredImmCons = db->nDeferredImmCons;
68874
+ pNew->pNext = db->pSavepoint;
68875
+ db->pSavepoint = pNew;
68876
+ pNew->nDeferredCons = db->nDeferredCons;
68877
+ pNew->nDeferredImmCons = db->nDeferredImmCons;
6927068878
}
6927168879
}
6927268880
}else{
69273
- u.at.iSavepoint = 0;
68881
+ iSavepoint = 0;
6927468882
6927568883
/* Find the named savepoint. If there is no such savepoint, then an
6927668884
** an error is returned to the user. */
6927768885
for(
69278
- u.at.pSavepoint = db->pSavepoint;
69279
- u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName);
69280
- u.at.pSavepoint = u.at.pSavepoint->pNext
68886
+ pSavepoint = db->pSavepoint;
68887
+ pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
68888
+ pSavepoint = pSavepoint->pNext
6928168889
){
69282
- u.at.iSavepoint++;
68890
+ iSavepoint++;
6928368891
}
69284
- if( !u.at.pSavepoint ){
69285
- sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName);
68892
+ if( !pSavepoint ){
68893
+ sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
6928668894
rc = SQLITE_ERROR;
69287
- }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){
69288
- /* It is not possible to release (commit) a savepoint if there are
68895
+ }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
68896
+ /* It is not possible to release (commit) a savepoint if there are
6928968897
** active write statements.
6929068898
*/
69291
- sqlite3SetString(&p->zErrMsg, db,
68899
+ sqlite3SetString(&p->zErrMsg, db,
6929268900
"cannot release savepoint - SQL statements in progress"
6929368901
);
6929468902
rc = SQLITE_BUSY;
6929568903
}else{
6929668904
6929768905
/* Determine whether or not this is a transaction savepoint. If so,
69298
- ** and this is a RELEASE command, then the current transaction
69299
- ** is committed.
68906
+ ** and this is a RELEASE command, then the current transaction
68907
+ ** is committed.
6930068908
*/
69301
- int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint;
69302
- if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){
68909
+ int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
68910
+ if( isTransaction && p1==SAVEPOINT_RELEASE ){
6930368911
if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6930468912
goto vdbe_return;
6930568913
}
6930668914
db->autoCommit = 1;
6930768915
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69311,56 +68919,56 @@
6931168919
goto vdbe_return;
6931268920
}
6931368921
db->isTransactionSavepoint = 0;
6931468922
rc = p->rc;
6931568923
}else{
69316
- u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1;
69317
- if( u.at.p1==SAVEPOINT_ROLLBACK ){
69318
- for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69319
- sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT);
68924
+ iSavepoint = db->nSavepoint - iSavepoint - 1;
68925
+ if( p1==SAVEPOINT_ROLLBACK ){
68926
+ for(ii=0; ii<db->nDb; ii++){
68927
+ sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
6932068928
}
6932168929
}
69322
- for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69323
- rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint);
68930
+ for(ii=0; ii<db->nDb; ii++){
68931
+ rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
6932468932
if( rc!=SQLITE_OK ){
6932568933
goto abort_due_to_error;
6932668934
}
6932768935
}
69328
- if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
68936
+ if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
6932968937
sqlite3ExpirePreparedStatements(db);
6933068938
sqlite3ResetAllSchemasOfConnection(db);
6933168939
db->flags = (db->flags | SQLITE_InternChanges);
6933268940
}
6933368941
}
69334
-
69335
- /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
68942
+
68943
+ /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
6933668944
** savepoints nested inside of the savepoint being operated on. */
69337
- while( db->pSavepoint!=u.at.pSavepoint ){
69338
- u.at.pTmp = db->pSavepoint;
69339
- db->pSavepoint = u.at.pTmp->pNext;
69340
- sqlite3DbFree(db, u.at.pTmp);
68945
+ while( db->pSavepoint!=pSavepoint ){
68946
+ pTmp = db->pSavepoint;
68947
+ db->pSavepoint = pTmp->pNext;
68948
+ sqlite3DbFree(db, pTmp);
6934168949
db->nSavepoint--;
6934268950
}
6934368951
69344
- /* If it is a RELEASE, then destroy the savepoint being operated on
69345
- ** too. If it is a ROLLBACK TO, then set the number of deferred
68952
+ /* If it is a RELEASE, then destroy the savepoint being operated on
68953
+ ** too. If it is a ROLLBACK TO, then set the number of deferred
6934668954
** constraint violations present in the database to the value stored
6934768955
** when the savepoint was created. */
69348
- if( u.at.p1==SAVEPOINT_RELEASE ){
69349
- assert( u.at.pSavepoint==db->pSavepoint );
69350
- db->pSavepoint = u.at.pSavepoint->pNext;
69351
- sqlite3DbFree(db, u.at.pSavepoint);
68956
+ if( p1==SAVEPOINT_RELEASE ){
68957
+ assert( pSavepoint==db->pSavepoint );
68958
+ db->pSavepoint = pSavepoint->pNext;
68959
+ sqlite3DbFree(db, pSavepoint);
6935268960
if( !isTransaction ){
6935368961
db->nSavepoint--;
6935468962
}
6935568963
}else{
69356
- db->nDeferredCons = u.at.pSavepoint->nDeferredCons;
69357
- db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons;
68964
+ db->nDeferredCons = pSavepoint->nDeferredCons;
68965
+ db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
6935868966
}
6935968967
6936068968
if( !isTransaction ){
69361
- rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
68969
+ rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
6936268970
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6936368971
}
6936468972
}
6936568973
}
6936668974
@@ -69375,54 +68983,52 @@
6937568983
** there are active writing VMs or active VMs that use shared cache.
6937668984
**
6937768985
** This instruction causes the VM to halt.
6937868986
*/
6937968987
case OP_AutoCommit: {
69380
-#if 0 /* local variables moved into u.au */
6938168988
int desiredAutoCommit;
6938268989
int iRollback;
6938368990
int turnOnAC;
69384
-#endif /* local variables moved into u.au */
6938568991
69386
- u.au.desiredAutoCommit = pOp->p1;
69387
- u.au.iRollback = pOp->p2;
69388
- u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit;
69389
- assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 );
69390
- assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 );
68992
+ desiredAutoCommit = pOp->p1;
68993
+ iRollback = pOp->p2;
68994
+ turnOnAC = desiredAutoCommit && !db->autoCommit;
68995
+ assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
68996
+ assert( desiredAutoCommit==1 || iRollback==0 );
6939168997
assert( db->nVdbeActive>0 ); /* At least this one VM is active */
6939268998
assert( p->bIsReader );
6939368999
6939469000
#if 0
69395
- if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
69001
+ if( turnOnAC && iRollback && db->nVdbeActive>1 ){
6939669002
/* If this instruction implements a ROLLBACK and other VMs are
6939769003
** still running, and a transaction is active, return an error indicating
69398
- ** that the other VMs must complete first.
69004
+ ** that the other VMs must complete first.
6939969005
*/
6940069006
sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
6940169007
"SQL statements in progress");
6940269008
rc = SQLITE_BUSY;
6940369009
}else
6940469010
#endif
69405
- if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
69011
+ if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
6940669012
/* If this instruction implements a COMMIT and other VMs are writing
69407
- ** return an error indicating that the other VMs must complete first.
69013
+ ** return an error indicating that the other VMs must complete first.
6940869014
*/
6940969015
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
6941069016
"SQL statements in progress");
6941169017
rc = SQLITE_BUSY;
69412
- }else if( u.au.desiredAutoCommit!=db->autoCommit ){
69413
- if( u.au.iRollback ){
69414
- assert( u.au.desiredAutoCommit==1 );
69018
+ }else if( desiredAutoCommit!=db->autoCommit ){
69019
+ if( iRollback ){
69020
+ assert( desiredAutoCommit==1 );
6941569021
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6941669022
db->autoCommit = 1;
6941769023
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6941869024
goto vdbe_return;
6941969025
}else{
69420
- db->autoCommit = (u8)u.au.desiredAutoCommit;
69026
+ db->autoCommit = (u8)desiredAutoCommit;
6942169027
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
6942269028
p->pc = pc;
69423
- db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
69029
+ db->autoCommit = (u8)(1-desiredAutoCommit);
6942469030
p->rc = rc = SQLITE_BUSY;
6942569031
goto vdbe_return;
6942669032
}
6942769033
}
6942869034
assert( db->nStatement==0 );
@@ -69433,14 +69039,14 @@
6943369039
rc = SQLITE_ERROR;
6943469040
}
6943569041
goto vdbe_return;
6943669042
}else{
6943769043
sqlite3SetString(&p->zErrMsg, db,
69438
- (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69439
- (u.au.iRollback)?"cannot rollback - no transaction is active":
69044
+ (!desiredAutoCommit)?"cannot start a transaction within a transaction":(
69045
+ (iRollback)?"cannot rollback - no transaction is active":
6944069046
"cannot commit - no transaction is active"));
69441
-
69047
+
6944269048
rc = SQLITE_ERROR;
6944369049
}
6944469050
break;
6944569051
}
6944669052
@@ -69474,48 +69080,46 @@
6947469080
** will automatically commit when the VDBE halts.
6947569081
**
6947669082
** If P2 is zero, then a read-lock is obtained on the database file.
6947769083
*/
6947869084
case OP_Transaction: {
69479
-#if 0 /* local variables moved into u.av */
6948069085
Btree *pBt;
69481
-#endif /* local variables moved into u.av */
6948269086
6948369087
assert( p->bIsReader );
6948469088
assert( p->readOnly==0 || pOp->p2==0 );
6948569089
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6948669090
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6948769091
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
6948869092
rc = SQLITE_READONLY;
6948969093
goto abort_due_to_error;
6949069094
}
69491
- u.av.pBt = db->aDb[pOp->p1].pBt;
69095
+ pBt = db->aDb[pOp->p1].pBt;
6949269096
69493
- if( u.av.pBt ){
69494
- rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
69097
+ if( pBt ){
69098
+ rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
6949569099
if( rc==SQLITE_BUSY ){
6949669100
p->pc = pc;
6949769101
p->rc = rc = SQLITE_BUSY;
6949869102
goto vdbe_return;
6949969103
}
6950069104
if( rc!=SQLITE_OK ){
6950169105
goto abort_due_to_error;
6950269106
}
6950369107
69504
- if( pOp->p2 && p->usesStmtJournal
69505
- && (db->autoCommit==0 || db->nVdbeRead>1)
69108
+ if( pOp->p2 && p->usesStmtJournal
69109
+ && (db->autoCommit==0 || db->nVdbeRead>1)
6950669110
){
69507
- assert( sqlite3BtreeIsInTrans(u.av.pBt) );
69111
+ assert( sqlite3BtreeIsInTrans(pBt) );
6950869112
if( p->iStatement==0 ){
6950969113
assert( db->nStatement>=0 && db->nSavepoint>=0 );
69510
- db->nStatement++;
69114
+ db->nStatement++;
6951169115
p->iStatement = db->nSavepoint + db->nStatement;
6951269116
}
6951369117
6951469118
rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
6951569119
if( rc==SQLITE_OK ){
69516
- rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
69120
+ rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
6951769121
}
6951869122
6951969123
/* Store the current value of the database handles deferred constraint
6952069124
** counter. If the statement transaction needs to be rolled back,
6952169125
** the value of this counter needs to be restored too. */
@@ -69537,26 +69141,24 @@
6953769141
** There must be a read-lock on the database (either a transaction
6953869142
** must be started or there must be an open cursor) before
6953969143
** executing this instruction.
6954069144
*/
6954169145
case OP_ReadCookie: { /* out2-prerelease */
69542
-#if 0 /* local variables moved into u.aw */
6954369146
int iMeta;
6954469147
int iDb;
6954569148
int iCookie;
69546
-#endif /* local variables moved into u.aw */
6954769149
6954869150
assert( p->bIsReader );
69549
- u.aw.iDb = pOp->p1;
69550
- u.aw.iCookie = pOp->p3;
69151
+ iDb = pOp->p1;
69152
+ iCookie = pOp->p3;
6955169153
assert( pOp->p3<SQLITE_N_BTREE_META );
69552
- assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
69553
- assert( db->aDb[u.aw.iDb].pBt!=0 );
69554
- assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 );
69154
+ assert( iDb>=0 && iDb<db->nDb );
69155
+ assert( db->aDb[iDb].pBt!=0 );
69156
+ assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
6955569157
69556
- sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta);
69557
- pOut->u.i = u.aw.iMeta;
69158
+ sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
69159
+ pOut->u.i = iMeta;
6955869160
break;
6955969161
}
6956069162
6956169163
/* Opcode: SetCookie P1 P2 P3 * *
6956269164
**
@@ -69567,31 +69169,29 @@
6956769169
** database file used to store temporary tables.
6956869170
**
6956969171
** A transaction must be started before executing this opcode.
6957069172
*/
6957169173
case OP_SetCookie: { /* in3 */
69572
-#if 0 /* local variables moved into u.ax */
6957369174
Db *pDb;
69574
-#endif /* local variables moved into u.ax */
6957569175
assert( pOp->p2<SQLITE_N_BTREE_META );
6957669176
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6957769177
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6957869178
assert( p->readOnly==0 );
69579
- u.ax.pDb = &db->aDb[pOp->p1];
69580
- assert( u.ax.pDb->pBt!=0 );
69179
+ pDb = &db->aDb[pOp->p1];
69180
+ assert( pDb->pBt!=0 );
6958169181
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6958269182
pIn3 = &aMem[pOp->p3];
6958369183
sqlite3VdbeMemIntegerify(pIn3);
6958469184
/* See note about index shifting on OP_ReadCookie */
69585
- rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i);
69185
+ rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
6958669186
if( pOp->p2==BTREE_SCHEMA_VERSION ){
6958769187
/* When the schema cookie changes, record the new cookie internally */
69588
- u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69188
+ pDb->pSchema->schema_cookie = (int)pIn3->u.i;
6958969189
db->flags |= SQLITE_InternChanges;
6959069190
}else if( pOp->p2==BTREE_FILE_FORMAT ){
6959169191
/* Record changes in the file format */
69592
- u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i;
69192
+ pDb->pSchema->file_format = (u8)pIn3->u.i;
6959369193
}
6959469194
if( pOp->p1==1 ){
6959569195
/* Invalidate all prepared statements whenever the TEMP database
6959669196
** schema is changed. Ticket #1644 */
6959769197
sqlite3ExpirePreparedStatements(db);
@@ -69617,44 +69217,42 @@
6961769217
** Either a transaction needs to have been started or an OP_Open needs
6961869218
** to be executed (to establish a read lock) before this opcode is
6961969219
** invoked.
6962069220
*/
6962169221
case OP_VerifyCookie: {
69622
-#if 0 /* local variables moved into u.ay */
6962369222
int iMeta;
6962469223
int iGen;
6962569224
Btree *pBt;
69626
-#endif /* local variables moved into u.ay */
6962769225
6962869226
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6962969227
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6963069228
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6963169229
assert( p->bIsReader );
69632
- u.ay.pBt = db->aDb[pOp->p1].pBt;
69633
- if( u.ay.pBt ){
69634
- sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta);
69635
- u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69230
+ pBt = db->aDb[pOp->p1].pBt;
69231
+ if( pBt ){
69232
+ sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69233
+ iGen = db->aDb[pOp->p1].pSchema->iGeneration;
6963669234
}else{
69637
- u.ay.iGen = u.ay.iMeta = 0;
69235
+ iGen = iMeta = 0;
6963869236
}
69639
- if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
69237
+ if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
6964069238
sqlite3DbFree(db, p->zErrMsg);
6964169239
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69642
- /* If the schema-cookie from the database file matches the cookie
69240
+ /* If the schema-cookie from the database file matches the cookie
6964369241
** stored with the in-memory representation of the schema, do
6964469242
** not reload the schema from the database file.
6964569243
**
6964669244
** If virtual-tables are in use, this is not just an optimization.
6964769245
** Often, v-tables store their data in other SQLite tables, which
6964869246
** are queried from within xNext() and other v-table methods using
6964969247
** prepared queries. If such a query is out-of-date, we do not want to
6965069248
** discard the database schema, as the user code implementing the
6965169249
** v-table would have to be ready for the sqlite3_vtab structure itself
69652
- ** to be invalidated whenever sqlite3_step() is called from within
69250
+ ** to be invalidated whenever sqlite3_step() is called from within
6965369251
** a v-table method.
6965469252
*/
69655
- if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
69253
+ if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
6965669254
sqlite3ResetOneSchema(db, pOp->p1);
6965769255
}
6965869256
6965969257
p->expired = 1;
6966069258
rc = SQLITE_SCHEMA;
@@ -69713,20 +69311,18 @@
6971369311
**
6971469312
** See also OpenRead.
6971569313
*/
6971669314
case OP_OpenRead:
6971769315
case OP_OpenWrite: {
69718
-#if 0 /* local variables moved into u.az */
6971969316
int nField;
6972069317
KeyInfo *pKeyInfo;
6972169318
int p2;
6972269319
int iDb;
6972369320
int wrFlag;
6972469321
Btree *pX;
6972569322
VdbeCursor *pCur;
6972669323
Db *pDb;
69727
-#endif /* local variables moved into u.az */
6972869324
6972969325
assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
6973069326
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
6973169327
assert( p->bIsReader );
6973269328
assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69734,73 +69330,74 @@
6973469330
if( p->expired ){
6973569331
rc = SQLITE_ABORT;
6973669332
break;
6973769333
}
6973869334
69739
- u.az.nField = 0;
69740
- u.az.pKeyInfo = 0;
69741
- u.az.p2 = pOp->p2;
69742
- u.az.iDb = pOp->p3;
69743
- assert( u.az.iDb>=0 && u.az.iDb<db->nDb );
69744
- assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 );
69745
- u.az.pDb = &db->aDb[u.az.iDb];
69746
- u.az.pX = u.az.pDb->pBt;
69747
- assert( u.az.pX!=0 );
69335
+ nField = 0;
69336
+ pKeyInfo = 0;
69337
+ p2 = pOp->p2;
69338
+ iDb = pOp->p3;
69339
+ assert( iDb>=0 && iDb<db->nDb );
69340
+ assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69341
+ pDb = &db->aDb[iDb];
69342
+ pX = pDb->pBt;
69343
+ assert( pX!=0 );
6974869344
if( pOp->opcode==OP_OpenWrite ){
69749
- u.az.wrFlag = 1;
69750
- assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) );
69751
- if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){
69752
- p->minWriteFileFormat = u.az.pDb->pSchema->file_format;
69345
+ wrFlag = 1;
69346
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
69347
+ if( pDb->pSchema->file_format < p->minWriteFileFormat ){
69348
+ p->minWriteFileFormat = pDb->pSchema->file_format;
6975369349
}
6975469350
}else{
69755
- u.az.wrFlag = 0;
69351
+ wrFlag = 0;
6975669352
}
6975769353
if( pOp->p5 & OPFLAG_P2ISREG ){
69758
- assert( u.az.p2>0 );
69759
- assert( u.az.p2<=(p->nMem-p->nCursor) );
69760
- pIn2 = &aMem[u.az.p2];
69354
+ assert( p2>0 );
69355
+ assert( p2<=(p->nMem-p->nCursor) );
69356
+ pIn2 = &aMem[p2];
6976169357
assert( memIsValid(pIn2) );
6976269358
assert( (pIn2->flags & MEM_Int)!=0 );
6976369359
sqlite3VdbeMemIntegerify(pIn2);
69764
- u.az.p2 = (int)pIn2->u.i;
69765
- /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and
69766
- ** that opcode will always set the u.az.p2 value to 2 or more or else fail.
69360
+ p2 = (int)pIn2->u.i;
69361
+ /* The p2 value always comes from a prior OP_CreateTable opcode and
69362
+ ** that opcode will always set the p2 value to 2 or more or else fail.
6976769363
** If there were a failure, the prepared statement would have halted
6976869364
** before reaching this instruction. */
69769
- if( NEVER(u.az.p2<2) ) {
69365
+ if( NEVER(p2<2) ) {
6977069366
rc = SQLITE_CORRUPT_BKPT;
6977169367
goto abort_due_to_error;
6977269368
}
6977369369
}
6977469370
if( pOp->p4type==P4_KEYINFO ){
69775
- u.az.pKeyInfo = pOp->p4.pKeyInfo;
69776
- assert( u.az.pKeyInfo->enc==ENC(db) );
69777
- assert( u.az.pKeyInfo->db==db );
69778
- u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
69371
+ pKeyInfo = pOp->p4.pKeyInfo;
69372
+ assert( pKeyInfo->enc==ENC(db) );
69373
+ assert( pKeyInfo->db==db );
69374
+ nField = pKeyInfo->nField+pKeyInfo->nXField;
6977969375
}else if( pOp->p4type==P4_INT32 ){
69780
- u.az.nField = pOp->p4.i;
69376
+ nField = pOp->p4.i;
6978169377
}
6978269378
assert( pOp->p1>=0 );
69783
- u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69784
- if( u.az.pCur==0 ) goto no_mem;
69785
- u.az.pCur->nullRow = 1;
69786
- u.az.pCur->isOrdered = 1;
69787
- rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
69788
- u.az.pCur->pKeyInfo = u.az.pKeyInfo;
69379
+ assert( nField>=0 );
69380
+ testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
69381
+ pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
69382
+ if( pCur==0 ) goto no_mem;
69383
+ pCur->nullRow = 1;
69384
+ pCur->isOrdered = 1;
69385
+ rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
69386
+ pCur->pKeyInfo = pKeyInfo;
6978969387
assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69790
- sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69388
+ sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
6979169389
6979269390
/* Since it performs no memory allocation or IO, the only value that
6979369391
** sqlite3BtreeCursor() may return is SQLITE_OK. */
6979469392
assert( rc==SQLITE_OK );
6979569393
69796
- /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
69394
+ /* Set the VdbeCursor.isTable variable. Previous versions of
6979769395
** SQLite used to check if the root-page flags were sane at this point
6979869396
** and report database corruption if they were not, but this check has
69799
- ** since moved into the btree layer. */
69800
- u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69801
- u.az.pCur->isIndex = !u.az.pCur->isTable;
69397
+ ** since moved into the btree layer. */
69398
+ pCur->isTable = pOp->p4type!=P4_KEYINFO;
6980269399
break;
6980369400
}
6980469401
6980569402
/* Opcode: OpenEphemeral P1 P2 * P4 P5
6980669403
** Synopsis: nColumn=P2
@@ -69828,55 +69425,53 @@
6982869425
** by this opcode will be used for automatically created transient
6982969426
** indices in joins.
6983069427
*/
6983169428
case OP_OpenAutoindex:
6983269429
case OP_OpenEphemeral: {
69833
-#if 0 /* local variables moved into u.ba */
6983469430
VdbeCursor *pCx;
6983569431
KeyInfo *pKeyInfo;
69836
-#endif /* local variables moved into u.ba */
6983769432
69838
- static const int vfsFlags =
69433
+ static const int vfsFlags =
6983969434
SQLITE_OPEN_READWRITE |
6984069435
SQLITE_OPEN_CREATE |
6984169436
SQLITE_OPEN_EXCLUSIVE |
6984269437
SQLITE_OPEN_DELETEONCLOSE |
6984369438
SQLITE_OPEN_TRANSIENT_DB;
6984469439
assert( pOp->p1>=0 );
69845
- u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69846
- if( u.ba.pCx==0 ) goto no_mem;
69847
- u.ba.pCx->nullRow = 1;
69848
- rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
69440
+ assert( pOp->p2>=0 );
69441
+ pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69442
+ if( pCx==0 ) goto no_mem;
69443
+ pCx->nullRow = 1;
69444
+ rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
6984969445
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
6985069446
if( rc==SQLITE_OK ){
69851
- rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
69447
+ rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
6985269448
}
6985369449
if( rc==SQLITE_OK ){
6985469450
/* If a transient index is required, create it by calling
6985569451
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
6985669452
** opening it. If a transient table is required, just use the
6985769453
** automatically created table with root-page 1 (an BLOB_INTKEY table).
6985869454
*/
69859
- if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69455
+ if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
6986069456
int pgno;
6986169457
assert( pOp->p4type==P4_KEYINFO );
69862
- rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69458
+ rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
6986369459
if( rc==SQLITE_OK ){
6986469460
assert( pgno==MASTER_ROOT+1 );
69865
- assert( u.ba.pKeyInfo->db==db );
69866
- assert( u.ba.pKeyInfo->enc==ENC(db) );
69867
- u.ba.pCx->pKeyInfo = u.ba.pKeyInfo;
69868
- rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor);
69869
- }
69870
- u.ba.pCx->isTable = 0;
69871
- }else{
69872
- rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69873
- u.ba.pCx->isTable = 1;
69461
+ assert( pKeyInfo->db==db );
69462
+ assert( pKeyInfo->enc==ENC(db) );
69463
+ pCx->pKeyInfo = pKeyInfo;
69464
+ rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor);
69465
+ }
69466
+ pCx->isTable = 0;
69467
+ }else{
69468
+ rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor);
69469
+ pCx->isTable = 1;
6987469470
}
6987569471
}
69876
- u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69877
- u.ba.pCx->isIndex = !u.ba.pCx->isTable;
69472
+ pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
6987869473
break;
6987969474
}
6988069475
6988169476
/* Opcode: SorterOpen P1 * * P4 *
6988269477
**
@@ -69883,21 +69478,20 @@
6988369478
** This opcode works like OP_OpenEphemeral except that it opens
6988469479
** a transient index that is specifically designed to sort large
6988569480
** tables using an external merge-sort algorithm.
6988669481
*/
6988769482
case OP_SorterOpen: {
69888
-#if 0 /* local variables moved into u.bb */
6988969483
VdbeCursor *pCx;
69890
-#endif /* local variables moved into u.bb */
69891
-
69892
- u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69893
- if( u.bb.pCx==0 ) goto no_mem;
69894
- u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69895
- assert( u.bb.pCx->pKeyInfo->db==db );
69896
- assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69897
- u.bb.pCx->isSorter = 1;
69898
- rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
69484
+
69485
+ assert( pOp->p1>=0 );
69486
+ assert( pOp->p2>=0 );
69487
+ pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69488
+ if( pCx==0 ) goto no_mem;
69489
+ pCx->pKeyInfo = pOp->p4.pKeyInfo;
69490
+ assert( pCx->pKeyInfo->db==db );
69491
+ assert( pCx->pKeyInfo->enc==ENC(db) );
69492
+ rc = sqlite3VdbeSorterInit(db, pCx);
6989969493
break;
6990069494
}
6990169495
6990269496
/* Opcode: OpenPseudo P1 P2 P3 * P5
6990369497
** Synopsis: content in r[P2@P3]
@@ -69915,22 +69509,20 @@
6991569509
**
6991669510
** P3 is the number of fields in the records that will be stored by
6991769511
** the pseudo-table.
6991869512
*/
6991969513
case OP_OpenPseudo: {
69920
-#if 0 /* local variables moved into u.bc */
6992169514
VdbeCursor *pCx;
69922
-#endif /* local variables moved into u.bc */
6992369515
6992469516
assert( pOp->p1>=0 );
69925
- u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69926
- if( u.bc.pCx==0 ) goto no_mem;
69927
- u.bc.pCx->nullRow = 1;
69928
- u.bc.pCx->pseudoTableReg = pOp->p2;
69929
- u.bc.pCx->isTable = 1;
69930
- u.bc.pCx->isIndex = 0;
69931
- u.bc.pCx->multiPseudo = pOp->p5;
69517
+ assert( pOp->p3>=0 );
69518
+ pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69519
+ if( pCx==0 ) goto no_mem;
69520
+ pCx->nullRow = 1;
69521
+ pCx->pseudoTableReg = pOp->p2;
69522
+ pCx->isTable = 1;
69523
+ pCx->multiPseudo = pOp->p5;
6993269524
break;
6993369525
}
6993469526
6993569527
/* Opcode: Close P1 * * * *
6993669528
**
@@ -70002,39 +69594,37 @@
7000269594
*/
7000369595
case OP_SeekLt: /* jump, in3 */
7000469596
case OP_SeekLe: /* jump, in3 */
7000569597
case OP_SeekGe: /* jump, in3 */
7000669598
case OP_SeekGt: { /* jump, in3 */
70007
-#if 0 /* local variables moved into u.bd */
7000869599
int res;
7000969600
int oc;
7001069601
VdbeCursor *pC;
7001169602
UnpackedRecord r;
7001269603
int nField;
7001369604
i64 iKey; /* The rowid we are to seek to */
70014
-#endif /* local variables moved into u.bd */
7001569605
7001669606
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7001769607
assert( pOp->p2!=0 );
70018
- u.bd.pC = p->apCsr[pOp->p1];
70019
- assert( u.bd.pC!=0 );
70020
- assert( u.bd.pC->pseudoTableReg==0 );
69608
+ pC = p->apCsr[pOp->p1];
69609
+ assert( pC!=0 );
69610
+ assert( pC->pseudoTableReg==0 );
7002169611
assert( OP_SeekLe == OP_SeekLt+1 );
7002269612
assert( OP_SeekGe == OP_SeekLt+2 );
7002369613
assert( OP_SeekGt == OP_SeekLt+3 );
70024
- assert( u.bd.pC->isOrdered );
70025
- assert( u.bd.pC->pCursor!=0 );
70026
- u.bd.oc = pOp->opcode;
70027
- u.bd.pC->nullRow = 0;
70028
- if( u.bd.pC->isTable ){
69614
+ assert( pC->isOrdered );
69615
+ assert( pC->pCursor!=0 );
69616
+ oc = pOp->opcode;
69617
+ pC->nullRow = 0;
69618
+ if( pC->isTable ){
7002969619
/* The input value in P3 might be of any type: integer, real, string,
7003069620
** blob, or NULL. But it needs to be an integer before we can do
7003169621
** the seek, so covert it. */
7003269622
pIn3 = &aMem[pOp->p3];
7003369623
applyNumericAffinity(pIn3);
70034
- u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70035
- u.bd.pC->rowidIsValid = 0;
69624
+ iKey = sqlite3VdbeIntValue(pIn3);
69625
+ pC->rowidIsValid = 0;
7003669626
7003769627
/* If the P3 value could not be converted into an integer without
7003869628
** loss of information, then special processing is required... */
7003969629
if( (pIn3->flags & MEM_Int)==0 ){
7004069630
if( (pIn3->flags & MEM_Real)==0 ){
@@ -70041,109 +69631,101 @@
7004169631
/* If the P3 value cannot be converted into any kind of a number,
7004269632
** then the seek is not possible, so jump to P2 */
7004369633
pc = pOp->p2 - 1;
7004469634
break;
7004569635
}
70046
- /* If we reach this point, then the P3 value must be a floating
70047
- ** point number. */
70048
- assert( (pIn3->flags & MEM_Real)!=0 );
70049
-
70050
- if( u.bd.iKey==SMALLEST_INT64 && (pIn3->r<(double)u.bd.iKey || pIn3->r>0) ){
70051
- /* The P3 value is too large in magnitude to be expressed as an
70052
- ** integer. */
70053
- u.bd.res = 1;
70054
- if( pIn3->r<0 ){
70055
- if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70056
- rc = sqlite3BtreeFirst(u.bd.pC->pCursor, &u.bd.res);
70057
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
70058
- }
70059
- }else{
70060
- if( u.bd.oc<=OP_SeekLe ){ assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70061
- rc = sqlite3BtreeLast(u.bd.pC->pCursor, &u.bd.res);
70062
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
70063
- }
70064
- }
70065
- if( u.bd.res ){
70066
- pc = pOp->p2 - 1;
70067
- }
70068
- break;
70069
- }else if( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekGe ){
70070
- /* Use the ceiling() function to convert real->int */
70071
- if( pIn3->r > (double)u.bd.iKey ) u.bd.iKey++;
70072
- }else{
70073
- /* Use the floor() function to convert real->int */
70074
- assert( u.bd.oc==OP_SeekLe || u.bd.oc==OP_SeekGt );
70075
- if( pIn3->r < (double)u.bd.iKey ) u.bd.iKey--;
70076
- }
70077
- }
70078
- rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res);
70079
- if( rc!=SQLITE_OK ){
70080
- goto abort_due_to_error;
70081
- }
70082
- if( u.bd.res==0 ){
70083
- u.bd.pC->rowidIsValid = 1;
70084
- u.bd.pC->lastRowid = u.bd.iKey;
70085
- }
70086
- }else{
70087
- u.bd.nField = pOp->p4.i;
70088
- assert( pOp->p4type==P4_INT32 );
70089
- assert( u.bd.nField>0 );
70090
- u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo;
70091
- u.bd.r.nField = (u16)u.bd.nField;
70092
-
70093
- /* The next line of code computes as follows, only faster:
70094
- ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){
70095
- ** u.bd.r.flags = UNPACKED_INCRKEY;
70096
- ** }else{
70097
- ** u.bd.r.flags = 0;
70098
- ** }
70099
- */
70100
- u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt)));
70101
- assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY );
70102
- assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY );
70103
- assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 );
70104
- assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 );
70105
-
70106
- u.bd.r.aMem = &aMem[pOp->p3];
70107
-#ifdef SQLITE_DEBUG
70108
- { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); }
70109
-#endif
70110
- ExpandBlob(u.bd.r.aMem);
70111
- rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res);
70112
- if( rc!=SQLITE_OK ){
70113
- goto abort_due_to_error;
70114
- }
70115
- u.bd.pC->rowidIsValid = 0;
70116
- }
70117
- u.bd.pC->deferredMoveto = 0;
70118
- u.bd.pC->cacheStatus = CACHE_STALE;
70119
-#ifdef SQLITE_TEST
70120
- sqlite3_search_count++;
70121
-#endif
70122
- if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70123
- if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){
70124
- rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res);
70125
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
70126
- u.bd.pC->rowidIsValid = 0;
70127
- }else{
70128
- u.bd.res = 0;
70129
- }
70130
- }else{
70131
- assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70132
- if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){
70133
- rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res);
70134
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
70135
- u.bd.pC->rowidIsValid = 0;
70136
- }else{
70137
- /* u.bd.res might be negative because the table is empty. Check to
70138
- ** see if this is the case.
70139
- */
70140
- u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor);
70141
- }
70142
- }
70143
- assert( pOp->p2>0 );
70144
- if( u.bd.res ){
69636
+
69637
+ /* If the approximation iKey is larger than the actual real search
69638
+ ** term, substitute >= for > and < for <=. e.g. if the search term
69639
+ ** is 4.9 and the integer approximation 5:
69640
+ **
69641
+ ** (x > 4.9) -> (x >= 5)
69642
+ ** (x <= 4.9) -> (x < 5)
69643
+ */
69644
+ if( pIn3->r<(double)iKey ){
69645
+ assert( OP_SeekGe==(OP_SeekGt-1) );
69646
+ assert( OP_SeekLt==(OP_SeekLe-1) );
69647
+ assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69648
+ if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
69649
+ }
69650
+
69651
+ /* If the approximation iKey is smaller than the actual real search
69652
+ ** term, substitute <= for < and > for >=. */
69653
+ else if( pIn3->r>(double)iKey ){
69654
+ assert( OP_SeekLe==(OP_SeekLt+1) );
69655
+ assert( OP_SeekGt==(OP_SeekGe+1) );
69656
+ assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69657
+ if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
69658
+ }
69659
+ }
69660
+ rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
69661
+ if( rc!=SQLITE_OK ){
69662
+ goto abort_due_to_error;
69663
+ }
69664
+ if( res==0 ){
69665
+ pC->rowidIsValid = 1;
69666
+ pC->lastRowid = iKey;
69667
+ }
69668
+ }else{
69669
+ nField = pOp->p4.i;
69670
+ assert( pOp->p4type==P4_INT32 );
69671
+ assert( nField>0 );
69672
+ r.pKeyInfo = pC->pKeyInfo;
69673
+ r.nField = (u16)nField;
69674
+
69675
+ /* The next line of code computes as follows, only faster:
69676
+ ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
69677
+ ** r.flags = UNPACKED_INCRKEY;
69678
+ ** }else{
69679
+ ** r.flags = 0;
69680
+ ** }
69681
+ */
69682
+ r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
69683
+ assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
69684
+ assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
69685
+ assert( oc!=OP_SeekGe || r.flags==0 );
69686
+ assert( oc!=OP_SeekLt || r.flags==0 );
69687
+
69688
+ r.aMem = &aMem[pOp->p3];
69689
+#ifdef SQLITE_DEBUG
69690
+ { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
69691
+#endif
69692
+ ExpandBlob(r.aMem);
69693
+ rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
69694
+ if( rc!=SQLITE_OK ){
69695
+ goto abort_due_to_error;
69696
+ }
69697
+ pC->rowidIsValid = 0;
69698
+ }
69699
+ pC->deferredMoveto = 0;
69700
+ pC->cacheStatus = CACHE_STALE;
69701
+#ifdef SQLITE_TEST
69702
+ sqlite3_search_count++;
69703
+#endif
69704
+ if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
69705
+ if( res<0 || (res==0 && oc==OP_SeekGt) ){
69706
+ rc = sqlite3BtreeNext(pC->pCursor, &res);
69707
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
69708
+ pC->rowidIsValid = 0;
69709
+ }else{
69710
+ res = 0;
69711
+ }
69712
+ }else{
69713
+ assert( oc==OP_SeekLt || oc==OP_SeekLe );
69714
+ if( res>0 || (res==0 && oc==OP_SeekLt) ){
69715
+ rc = sqlite3BtreePrevious(pC->pCursor, &res);
69716
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
69717
+ pC->rowidIsValid = 0;
69718
+ }else{
69719
+ /* res might be negative because the table is empty. Check to
69720
+ ** see if this is the case.
69721
+ */
69722
+ res = sqlite3BtreeEof(pC->pCursor);
69723
+ }
69724
+ }
69725
+ assert( pOp->p2>0 );
69726
+ if( res ){
7014569727
pc = pOp->p2 - 1;
7014669728
}
7014769729
break;
7014869730
}
7014969731
@@ -70156,24 +69738,22 @@
7015669738
** This is actually a deferred seek. Nothing actually happens until
7015769739
** the cursor is used to read a record. That way, if no reads
7015869740
** occur, no unnecessary I/O happens.
7015969741
*/
7016069742
case OP_Seek: { /* in2 */
70161
-#if 0 /* local variables moved into u.be */
7016269743
VdbeCursor *pC;
70163
-#endif /* local variables moved into u.be */
7016469744
7016569745
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70166
- u.be.pC = p->apCsr[pOp->p1];
70167
- assert( u.be.pC!=0 );
70168
- assert( u.be.pC->pCursor!=0 );
70169
- assert( u.be.pC->isTable );
70170
- u.be.pC->nullRow = 0;
69746
+ pC = p->apCsr[pOp->p1];
69747
+ assert( pC!=0 );
69748
+ assert( pC->pCursor!=0 );
69749
+ assert( pC->isTable );
69750
+ pC->nullRow = 0;
7017169751
pIn2 = &aMem[pOp->p2];
70172
- u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
70173
- u.be.pC->rowidIsValid = 0;
70174
- u.be.pC->deferredMoveto = 1;
69752
+ pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
69753
+ pC->rowidIsValid = 0;
69754
+ pC->deferredMoveto = 1;
7017569755
break;
7017669756
}
7017769757
7017869758
7017969759
/* Opcode: Found P1 P2 P3 P4 *
@@ -70224,85 +69804,83 @@
7022469804
** See also: NotFound, Found, NotExists
7022569805
*/
7022669806
case OP_NoConflict: /* jump, in3 */
7022769807
case OP_NotFound: /* jump, in3 */
7022869808
case OP_Found: { /* jump, in3 */
70229
-#if 0 /* local variables moved into u.bf */
7023069809
int alreadyExists;
7023169810
int ii;
7023269811
VdbeCursor *pC;
7023369812
int res;
7023469813
char *pFree;
7023569814
UnpackedRecord *pIdxKey;
7023669815
UnpackedRecord r;
7023769816
char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70238
-#endif /* local variables moved into u.bf */
7023969817
7024069818
#ifdef SQLITE_TEST
7024169819
if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
7024269820
#endif
7024369821
70244
- u.bf.alreadyExists = 0;
7024569822
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7024669823
assert( pOp->p4type==P4_INT32 );
70247
- u.bf.pC = p->apCsr[pOp->p1];
70248
- assert( u.bf.pC!=0 );
69824
+ pC = p->apCsr[pOp->p1];
69825
+ assert( pC!=0 );
7024969826
pIn3 = &aMem[pOp->p3];
70250
- assert( u.bf.pC->pCursor!=0 );
70251
- assert( u.bf.pC->isTable==0 );
69827
+ assert( pC->pCursor!=0 );
69828
+ assert( pC->isTable==0 );
69829
+ pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
7025269830
if( pOp->p4.i>0 ){
70253
- u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo;
70254
- u.bf.r.nField = (u16)pOp->p4.i;
70255
- u.bf.r.aMem = pIn3;
69831
+ r.pKeyInfo = pC->pKeyInfo;
69832
+ r.nField = (u16)pOp->p4.i;
69833
+ r.aMem = pIn3;
7025669834
#ifdef SQLITE_DEBUG
7025769835
{
7025869836
int i;
70259
- for(i=0; i<u.bf.r.nField; i++){
70260
- assert( memIsValid(&u.bf.r.aMem[i]) );
70261
- if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]);
69837
+ for(i=0; i<r.nField; i++){
69838
+ assert( memIsValid(&r.aMem[i]) );
69839
+ if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
7026269840
}
7026369841
}
7026469842
#endif
70265
- u.bf.r.flags = UNPACKED_PREFIX_MATCH;
70266
- u.bf.pIdxKey = &u.bf.r;
69843
+ r.flags = UNPACKED_PREFIX_MATCH;
69844
+ pIdxKey = &r;
7026769845
}else{
70268
- u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70269
- u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree
70270
- );
70271
- if( u.bf.pIdxKey==0 ) goto no_mem;
69846
+ pIdxKey = sqlite3VdbeAllocUnpackedRecord(
69847
+ pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
69848
+ );
69849
+ if( pIdxKey==0 ) goto no_mem;
7027269850
assert( pIn3->flags & MEM_Blob );
7027369851
assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70274
- sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey);
70275
- u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
69852
+ sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
69853
+ pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
7027669854
}
7027769855
if( pOp->opcode==OP_NoConflict ){
7027869856
/* For the OP_NoConflict opcode, take the jump if any of the
7027969857
** input fields are NULL, since any key with a NULL will not
7028069858
** conflict */
70281
- for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){
70282
- if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){
69859
+ for(ii=0; ii<r.nField; ii++){
69860
+ if( r.aMem[ii].flags & MEM_Null ){
7028369861
pc = pOp->p2 - 1;
7028469862
break;
7028569863
}
7028669864
}
7028769865
}
70288
- rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
69866
+ rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
7028969867
if( pOp->p4.i==0 ){
70290
- sqlite3DbFree(db, u.bf.pFree);
69868
+ sqlite3DbFree(db, pFree);
7029169869
}
7029269870
if( rc!=SQLITE_OK ){
7029369871
break;
7029469872
}
70295
- u.bf.pC->seekResult = u.bf.res;
70296
- u.bf.alreadyExists = (u.bf.res==0);
70297
- u.bf.pC->nullRow = 1-u.bf.alreadyExists;
70298
- u.bf.pC->deferredMoveto = 0;
70299
- u.bf.pC->cacheStatus = CACHE_STALE;
69873
+ pC->seekResult = res;
69874
+ alreadyExists = (res==0);
69875
+ pC->nullRow = 1-alreadyExists;
69876
+ pC->deferredMoveto = 0;
69877
+ pC->cacheStatus = CACHE_STALE;
7030069878
if( pOp->opcode==OP_Found ){
70301
- if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
69879
+ if( alreadyExists ) pc = pOp->p2 - 1;
7030269880
}else{
70303
- if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
69881
+ if( !alreadyExists ) pc = pOp->p2 - 1;
7030469882
}
7030569883
break;
7030669884
}
7030769885
7030869886
/* Opcode: NotExists P1 P2 P3 * *
@@ -70318,39 +69896,37 @@
7031869896
** (with arbitrary multi-value keys).
7031969897
**
7032069898
** See also: Found, NotFound, NoConflict
7032169899
*/
7032269900
case OP_NotExists: { /* jump, in3 */
70323
-#if 0 /* local variables moved into u.bg */
7032469901
VdbeCursor *pC;
7032569902
BtCursor *pCrsr;
7032669903
int res;
7032769904
u64 iKey;
70328
-#endif /* local variables moved into u.bg */
7032969905
7033069906
pIn3 = &aMem[pOp->p3];
7033169907
assert( pIn3->flags & MEM_Int );
7033269908
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70333
- u.bg.pC = p->apCsr[pOp->p1];
70334
- assert( u.bg.pC!=0 );
70335
- assert( u.bg.pC->isTable );
70336
- assert( u.bg.pC->pseudoTableReg==0 );
70337
- u.bg.pCrsr = u.bg.pC->pCursor;
70338
- assert( u.bg.pCrsr!=0 );
70339
- u.bg.res = 0;
70340
- u.bg.iKey = pIn3->u.i;
70341
- rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70342
- u.bg.pC->lastRowid = pIn3->u.i;
70343
- u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70344
- u.bg.pC->nullRow = 0;
70345
- u.bg.pC->cacheStatus = CACHE_STALE;
70346
- u.bg.pC->deferredMoveto = 0;
70347
- if( u.bg.res!=0 ){
69909
+ pC = p->apCsr[pOp->p1];
69910
+ assert( pC!=0 );
69911
+ assert( pC->isTable );
69912
+ assert( pC->pseudoTableReg==0 );
69913
+ pCrsr = pC->pCursor;
69914
+ assert( pCrsr!=0 );
69915
+ res = 0;
69916
+ iKey = pIn3->u.i;
69917
+ rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
69918
+ pC->lastRowid = pIn3->u.i;
69919
+ pC->rowidIsValid = res==0 ?1:0;
69920
+ pC->nullRow = 0;
69921
+ pC->cacheStatus = CACHE_STALE;
69922
+ pC->deferredMoveto = 0;
69923
+ if( res!=0 ){
7034869924
pc = pOp->p2 - 1;
70349
- assert( u.bg.pC->rowidIsValid==0 );
69925
+ assert( pC->rowidIsValid==0 );
7035069926
}
70351
- u.bg.pC->seekResult = u.bg.res;
69927
+ pC->seekResult = res;
7035269928
break;
7035369929
}
7035469930
7035569931
/* Opcode: Sequence P1 P2 * * *
7035669932
** Synopsis: r[P2]=rowid
@@ -70382,25 +69958,23 @@
7038269958
** an SQLITE_FULL error is generated. The P3 register is updated with the '
7038369959
** generated record number. This P3 mechanism is used to help implement the
7038469960
** AUTOINCREMENT feature.
7038569961
*/
7038669962
case OP_NewRowid: { /* out2-prerelease */
70387
-#if 0 /* local variables moved into u.bh */
7038869963
i64 v; /* The new rowid */
7038969964
VdbeCursor *pC; /* Cursor of table to get the new rowid */
7039069965
int res; /* Result of an sqlite3BtreeLast() */
7039169966
int cnt; /* Counter to limit the number of searches */
7039269967
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
7039369968
VdbeFrame *pFrame; /* Root frame of VDBE */
70394
-#endif /* local variables moved into u.bh */
7039569969
70396
- u.bh.v = 0;
70397
- u.bh.res = 0;
69970
+ v = 0;
69971
+ res = 0;
7039869972
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70399
- u.bh.pC = p->apCsr[pOp->p1];
70400
- assert( u.bh.pC!=0 );
70401
- if( NEVER(u.bh.pC->pCursor==0) ){
69973
+ pC = p->apCsr[pOp->p1];
69974
+ assert( pC!=0 );
69975
+ if( NEVER(pC->pCursor==0) ){
7040269976
/* The zero initialization above is all that is needed */
7040369977
}else{
7040469978
/* The next rowid or record number (different terms for the same
7040569979
** thing) is obtained in a two-step algorithm.
7040669980
**
@@ -70412,11 +69986,11 @@
7041269986
** The second algorithm is to select a rowid at random and see if
7041369987
** it already exists in the table. If it does not exist, we have
7041469988
** succeeded. If the random rowid does exist, we select a new one
7041569989
** and try again, up to 100 times.
7041669990
*/
70417
- assert( u.bh.pC->isTable );
69991
+ assert( pC->isTable );
7041869992
7041969993
#ifdef SQLITE_32BIT_ROWID
7042069994
# define MAX_ROWID 0x7fffffff
7042169995
#else
7042269996
/* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70424,101 +69998,101 @@
7042469998
** to provide the constant while making all compilers happy.
7042569999
*/
7042670000
# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
7042770001
#endif
7042870002
70429
- if( !u.bh.pC->useRandomRowid ){
70430
- u.bh.v = sqlite3BtreeGetCachedRowid(u.bh.pC->pCursor);
70431
- if( u.bh.v==0 ){
70432
- rc = sqlite3BtreeLast(u.bh.pC->pCursor, &u.bh.res);
70003
+ if( !pC->useRandomRowid ){
70004
+ v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70005
+ if( v==0 ){
70006
+ rc = sqlite3BtreeLast(pC->pCursor, &res);
7043370007
if( rc!=SQLITE_OK ){
7043470008
goto abort_due_to_error;
7043570009
}
70436
- if( u.bh.res ){
70437
- u.bh.v = 1; /* IMP: R-61914-48074 */
70010
+ if( res ){
70011
+ v = 1; /* IMP: R-61914-48074 */
7043870012
}else{
70439
- assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) );
70440
- rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v);
70013
+ assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70014
+ rc = sqlite3BtreeKeySize(pC->pCursor, &v);
7044170015
assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70442
- if( u.bh.v>=MAX_ROWID ){
70443
- u.bh.pC->useRandomRowid = 1;
70016
+ if( v>=MAX_ROWID ){
70017
+ pC->useRandomRowid = 1;
7044470018
}else{
70445
- u.bh.v++; /* IMP: R-29538-34987 */
70019
+ v++; /* IMP: R-29538-34987 */
7044670020
}
7044770021
}
7044870022
}
7044970023
7045070024
#ifndef SQLITE_OMIT_AUTOINCREMENT
7045170025
if( pOp->p3 ){
7045270026
/* Assert that P3 is a valid memory cell. */
7045370027
assert( pOp->p3>0 );
7045470028
if( p->pFrame ){
70455
- for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent);
70029
+ for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
7045670030
/* Assert that P3 is a valid memory cell. */
70457
- assert( pOp->p3<=u.bh.pFrame->nMem );
70458
- u.bh.pMem = &u.bh.pFrame->aMem[pOp->p3];
70031
+ assert( pOp->p3<=pFrame->nMem );
70032
+ pMem = &pFrame->aMem[pOp->p3];
7045970033
}else{
7046070034
/* Assert that P3 is a valid memory cell. */
7046170035
assert( pOp->p3<=(p->nMem-p->nCursor) );
70462
- u.bh.pMem = &aMem[pOp->p3];
70463
- memAboutToChange(p, u.bh.pMem);
70464
- }
70465
- assert( memIsValid(u.bh.pMem) );
70466
-
70467
- REGISTER_TRACE(pOp->p3, u.bh.pMem);
70468
- sqlite3VdbeMemIntegerify(u.bh.pMem);
70469
- assert( (u.bh.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70470
- if( u.bh.pMem->u.i==MAX_ROWID || u.bh.pC->useRandomRowid ){
70036
+ pMem = &aMem[pOp->p3];
70037
+ memAboutToChange(p, pMem);
70038
+ }
70039
+ assert( memIsValid(pMem) );
70040
+
70041
+ REGISTER_TRACE(pOp->p3, pMem);
70042
+ sqlite3VdbeMemIntegerify(pMem);
70043
+ assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70044
+ if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
7047170045
rc = SQLITE_FULL; /* IMP: R-12275-61338 */
7047270046
goto abort_due_to_error;
7047370047
}
70474
- if( u.bh.v<u.bh.pMem->u.i+1 ){
70475
- u.bh.v = u.bh.pMem->u.i + 1;
70048
+ if( v<pMem->u.i+1 ){
70049
+ v = pMem->u.i + 1;
7047670050
}
70477
- u.bh.pMem->u.i = u.bh.v;
70051
+ pMem->u.i = v;
7047870052
}
7047970053
#endif
7048070054
70481
- sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0);
70055
+ sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
7048270056
}
70483
- if( u.bh.pC->useRandomRowid ){
70057
+ if( pC->useRandomRowid ){
7048470058
/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
7048570059
** largest possible integer (9223372036854775807) then the database
7048670060
** engine starts picking positive candidate ROWIDs at random until
7048770061
** it finds one that is not previously used. */
7048870062
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
7048970063
** an AUTOINCREMENT table. */
7049070064
/* on the first attempt, simply do one more than previous */
70491
- u.bh.v = lastRowid;
70492
- u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70493
- u.bh.v++; /* ensure non-zero */
70494
- u.bh.cnt = 0;
70495
- while( ((rc = sqlite3BtreeMovetoUnpacked(u.bh.pC->pCursor, 0, (u64)u.bh.v,
70496
- 0, &u.bh.res))==SQLITE_OK)
70497
- && (u.bh.res==0)
70498
- && (++u.bh.cnt<100)){
70065
+ v = lastRowid;
70066
+ v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70067
+ v++; /* ensure non-zero */
70068
+ cnt = 0;
70069
+ while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
70070
+ 0, &res))==SQLITE_OK)
70071
+ && (res==0)
70072
+ && (++cnt<100)){
7049970073
/* collision - try another random rowid */
70500
- sqlite3_randomness(sizeof(u.bh.v), &u.bh.v);
70501
- if( u.bh.cnt<5 ){
70074
+ sqlite3_randomness(sizeof(v), &v);
70075
+ if( cnt<5 ){
7050270076
/* try "small" random rowids for the initial attempts */
70503
- u.bh.v &= 0xffffff;
70077
+ v &= 0xffffff;
7050470078
}else{
70505
- u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70079
+ v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
7050670080
}
70507
- u.bh.v++; /* ensure non-zero */
70081
+ v++; /* ensure non-zero */
7050870082
}
70509
- if( rc==SQLITE_OK && u.bh.res==0 ){
70083
+ if( rc==SQLITE_OK && res==0 ){
7051070084
rc = SQLITE_FULL; /* IMP: R-38219-53002 */
7051170085
goto abort_due_to_error;
7051270086
}
70513
- assert( u.bh.v>0 ); /* EV: R-40812-03570 */
70087
+ assert( v>0 ); /* EV: R-40812-03570 */
7051470088
}
70515
- u.bh.pC->rowidIsValid = 0;
70516
- u.bh.pC->deferredMoveto = 0;
70517
- u.bh.pC->cacheStatus = CACHE_STALE;
70089
+ pC->rowidIsValid = 0;
70090
+ pC->deferredMoveto = 0;
70091
+ pC->cacheStatus = CACHE_STALE;
7051870092
}
70519
- pOut->u.i = u.bh.v;
70093
+ pOut->u.i = v;
7052070094
break;
7052170095
}
7052270096
7052370097
/* Opcode: Insert P1 P2 P3 P4 P5
7052470098
** Synopsis: intkey=r[P3] data=r[P2]
@@ -70566,74 +70140,72 @@
7056670140
** This works exactly like OP_Insert except that the key is the
7056770141
** integer value P3, not the value of the integer stored in register P3.
7056870142
*/
7056970143
case OP_Insert:
7057070144
case OP_InsertInt: {
70571
-#if 0 /* local variables moved into u.bi */
7057270145
Mem *pData; /* MEM cell holding data for the record to be inserted */
7057370146
Mem *pKey; /* MEM cell holding key for the record */
7057470147
i64 iKey; /* The integer ROWID or key for the record to be inserted */
7057570148
VdbeCursor *pC; /* Cursor to table into which insert is written */
7057670149
int nZero; /* Number of zero-bytes to append */
7057770150
int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
7057870151
const char *zDb; /* database name - used by the update hook */
7057970152
const char *zTbl; /* Table name - used by the opdate hook */
7058070153
int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
70581
-#endif /* local variables moved into u.bi */
7058270154
70583
- u.bi.pData = &aMem[pOp->p2];
70155
+ pData = &aMem[pOp->p2];
7058470156
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70585
- assert( memIsValid(u.bi.pData) );
70586
- u.bi.pC = p->apCsr[pOp->p1];
70587
- assert( u.bi.pC!=0 );
70588
- assert( u.bi.pC->pCursor!=0 );
70589
- assert( u.bi.pC->pseudoTableReg==0 );
70590
- assert( u.bi.pC->isTable );
70591
- REGISTER_TRACE(pOp->p2, u.bi.pData);
70157
+ assert( memIsValid(pData) );
70158
+ pC = p->apCsr[pOp->p1];
70159
+ assert( pC!=0 );
70160
+ assert( pC->pCursor!=0 );
70161
+ assert( pC->pseudoTableReg==0 );
70162
+ assert( pC->isTable );
70163
+ REGISTER_TRACE(pOp->p2, pData);
7059270164
7059370165
if( pOp->opcode==OP_Insert ){
70594
- u.bi.pKey = &aMem[pOp->p3];
70595
- assert( u.bi.pKey->flags & MEM_Int );
70596
- assert( memIsValid(u.bi.pKey) );
70597
- REGISTER_TRACE(pOp->p3, u.bi.pKey);
70598
- u.bi.iKey = u.bi.pKey->u.i;
70166
+ pKey = &aMem[pOp->p3];
70167
+ assert( pKey->flags & MEM_Int );
70168
+ assert( memIsValid(pKey) );
70169
+ REGISTER_TRACE(pOp->p3, pKey);
70170
+ iKey = pKey->u.i;
7059970171
}else{
7060070172
assert( pOp->opcode==OP_InsertInt );
70601
- u.bi.iKey = pOp->p3;
70173
+ iKey = pOp->p3;
7060270174
}
7060370175
7060470176
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70605
- if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bi.iKey;
70606
- if( u.bi.pData->flags & MEM_Null ){
70607
- u.bi.pData->z = 0;
70608
- u.bi.pData->n = 0;
70609
- }else{
70610
- assert( u.bi.pData->flags & (MEM_Blob|MEM_Str) );
70611
- }
70612
- u.bi.seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bi.pC->seekResult : 0);
70613
- if( u.bi.pData->flags & MEM_Zero ){
70614
- u.bi.nZero = u.bi.pData->u.nZero;
70615
- }else{
70616
- u.bi.nZero = 0;
70617
- }
70618
- sqlite3BtreeSetCachedRowid(u.bi.pC->pCursor, 0);
70619
- rc = sqlite3BtreeInsert(u.bi.pC->pCursor, 0, u.bi.iKey,
70620
- u.bi.pData->z, u.bi.pData->n, u.bi.nZero,
70621
- pOp->p5 & OPFLAG_APPEND, u.bi.seekResult
70177
+ if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
70178
+ if( pData->flags & MEM_Null ){
70179
+ pData->z = 0;
70180
+ pData->n = 0;
70181
+ }else{
70182
+ assert( pData->flags & (MEM_Blob|MEM_Str) );
70183
+ }
70184
+ seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
70185
+ if( pData->flags & MEM_Zero ){
70186
+ nZero = pData->u.nZero;
70187
+ }else{
70188
+ nZero = 0;
70189
+ }
70190
+ sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70191
+ rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70192
+ pData->z, pData->n, nZero,
70193
+ (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
7062270194
);
70623
- u.bi.pC->rowidIsValid = 0;
70624
- u.bi.pC->deferredMoveto = 0;
70625
- u.bi.pC->cacheStatus = CACHE_STALE;
70195
+ pC->rowidIsValid = 0;
70196
+ pC->deferredMoveto = 0;
70197
+ pC->cacheStatus = CACHE_STALE;
7062670198
7062770199
/* Invoke the update-hook if required. */
7062870200
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70629
- u.bi.zDb = db->aDb[u.bi.pC->iDb].zName;
70630
- u.bi.zTbl = pOp->p4.z;
70631
- u.bi.op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70632
- assert( u.bi.pC->isTable );
70633
- db->xUpdateCallback(db->pUpdateArg, u.bi.op, u.bi.zDb, u.bi.zTbl, u.bi.iKey);
70634
- assert( u.bi.pC->iDb>=0 );
70201
+ zDb = db->aDb[pC->iDb].zName;
70202
+ zTbl = pOp->p4.z;
70203
+ op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70204
+ assert( pC->isTable );
70205
+ db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
70206
+ assert( pC->iDb>=0 );
7063570207
}
7063670208
break;
7063770209
}
7063870210
7063970211
/* Opcode: Delete P1 P2 * P4 *
@@ -70655,51 +70227,39 @@
7065570227
** pointing to. The update hook will be invoked, if it exists.
7065670228
** If P4 is not NULL then the P1 cursor must have been positioned
7065770229
** using OP_NotFound prior to invoking this opcode.
7065870230
*/
7065970231
case OP_Delete: {
70660
-#if 0 /* local variables moved into u.bj */
7066170232
i64 iKey;
7066270233
VdbeCursor *pC;
70663
-#endif /* local variables moved into u.bj */
7066470234
70665
- u.bj.iKey = 0;
7066670235
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70667
- u.bj.pC = p->apCsr[pOp->p1];
70668
- assert( u.bj.pC!=0 );
70669
- assert( u.bj.pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70670
-
70671
- /* If the update-hook will be invoked, set u.bj.iKey to the rowid of the
70672
- ** row being deleted.
70673
- */
70674
- if( db->xUpdateCallback && pOp->p4.z ){
70675
- assert( u.bj.pC->isTable );
70676
- assert( u.bj.pC->rowidIsValid ); /* lastRowid set by previous OP_NotFound */
70677
- u.bj.iKey = u.bj.pC->lastRowid;
70678
- }
70236
+ pC = p->apCsr[pOp->p1];
70237
+ assert( pC!=0 );
70238
+ assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70239
+ iKey = pC->lastRowid; /* Only used for the update hook */
7067970240
7068070241
/* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
7068170242
** OP_Column on the same table without any intervening operations that
70682
- ** might move or invalidate the cursor. Hence cursor u.bj.pC is always pointing
70243
+ ** might move or invalidate the cursor. Hence cursor pC is always pointing
7068370244
** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
7068470245
** below is always a no-op and cannot fail. We will run it anyhow, though,
7068570246
** to guard against future changes to the code generator.
7068670247
**/
70687
- assert( u.bj.pC->deferredMoveto==0 );
70688
- rc = sqlite3VdbeCursorMoveto(u.bj.pC);
70248
+ assert( pC->deferredMoveto==0 );
70249
+ rc = sqlite3VdbeCursorMoveto(pC);
7068970250
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7069070251
70691
- sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0);
70692
- rc = sqlite3BtreeDelete(u.bj.pC->pCursor);
70693
- u.bj.pC->cacheStatus = CACHE_STALE;
70252
+ sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70253
+ rc = sqlite3BtreeDelete(pC->pCursor);
70254
+ pC->cacheStatus = CACHE_STALE;
7069470255
7069570256
/* Invoke the update-hook if required. */
70696
- if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70697
- const char *zDb = db->aDb[u.bj.pC->iDb].zName;
70698
- const char *zTbl = pOp->p4.z;
70699
- db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, u.bj.iKey);
70700
- assert( u.bj.pC->iDb>=0 );
70257
+ if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
70258
+ db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
70259
+ db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
70260
+ assert( pC->iDb>=0 );
7070170261
}
7070270262
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
7070370263
break;
7070470264
}
7070570265
/* Opcode: ResetCount * * * * *
@@ -70729,23 +70289,21 @@
7072970289
**
7073070290
** Fall through to next instruction if the two records compare equal to
7073170291
** each other. Jump to P2 if they are different.
7073270292
*/
7073370293
case OP_SorterCompare: {
70734
-#if 0 /* local variables moved into u.bk */
7073570294
VdbeCursor *pC;
7073670295
int res;
7073770296
int nIgnore;
70738
-#endif /* local variables moved into u.bk */
7073970297
70740
- u.bk.pC = p->apCsr[pOp->p1];
70741
- assert( isSorter(u.bk.pC) );
70298
+ pC = p->apCsr[pOp->p1];
70299
+ assert( isSorter(pC) );
7074270300
assert( pOp->p4type==P4_INT32 );
7074370301
pIn3 = &aMem[pOp->p3];
70744
- u.bk.nIgnore = pOp->p4.i;
70745
- rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res);
70746
- if( u.bk.res ){
70302
+ nIgnore = pOp->p4.i;
70303
+ rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70304
+ if( res ){
7074770305
pc = pOp->p2-1;
7074870306
}
7074970307
break;
7075070308
};
7075170309
@@ -70753,18 +70311,16 @@
7075370311
** Synopsis: r[P2]=data
7075470312
**
7075570313
** Write into register P2 the current sorter data for sorter cursor P1.
7075670314
*/
7075770315
case OP_SorterData: {
70758
-#if 0 /* local variables moved into u.bl */
7075970316
VdbeCursor *pC;
70760
-#endif /* local variables moved into u.bl */
7076170317
7076270318
pOut = &aMem[pOp->p2];
70763
- u.bl.pC = p->apCsr[pOp->p1];
70764
- assert( u.bl.pC->isSorter );
70765
- rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
70319
+ pC = p->apCsr[pOp->p1];
70320
+ assert( isSorter(pC) );
70321
+ rc = sqlite3VdbeSorterRowkey(pC, pOut);
7076670322
break;
7076770323
}
7076870324
7076970325
/* Opcode: RowData P1 P2 * * *
7077070326
** Synopsis: r[P2]=data
@@ -70788,66 +70344,64 @@
7078870344
** If the P1 cursor must be pointing to a valid row (not a NULL row)
7078970345
** of a real table, not a pseudo-table.
7079070346
*/
7079170347
case OP_RowKey:
7079270348
case OP_RowData: {
70793
-#if 0 /* local variables moved into u.bm */
7079470349
VdbeCursor *pC;
7079570350
BtCursor *pCrsr;
7079670351
u32 n;
7079770352
i64 n64;
70798
-#endif /* local variables moved into u.bm */
7079970353
7080070354
pOut = &aMem[pOp->p2];
7080170355
memAboutToChange(p, pOut);
7080270356
7080370357
/* Note that RowKey and RowData are really exactly the same instruction */
7080470358
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70805
- u.bm.pC = p->apCsr[pOp->p1];
70806
- assert( u.bm.pC->isSorter==0 );
70807
- assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
70808
- assert( u.bm.pC->isIndex || pOp->opcode==OP_RowData );
70809
- assert( u.bm.pC!=0 );
70810
- assert( u.bm.pC->nullRow==0 );
70811
- assert( u.bm.pC->pseudoTableReg==0 );
70812
- assert( u.bm.pC->pCursor!=0 );
70813
- u.bm.pCrsr = u.bm.pC->pCursor;
70814
- assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) );
70359
+ pC = p->apCsr[pOp->p1];
70360
+ assert( isSorter(pC)==0 );
70361
+ assert( pC->isTable || pOp->opcode!=OP_RowData );
70362
+ assert( pC->isTable==0 || pOp->opcode==OP_RowData );
70363
+ assert( pC!=0 );
70364
+ assert( pC->nullRow==0 );
70365
+ assert( pC->pseudoTableReg==0 );
70366
+ assert( pC->pCursor!=0 );
70367
+ pCrsr = pC->pCursor;
70368
+ assert( sqlite3BtreeCursorIsValid(pCrsr) );
7081570369
7081670370
/* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
7081770371
** OP_Rewind/Op_Next with no intervening instructions that might invalidate
7081870372
** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
7081970373
** a no-op and can never fail. But we leave it in place as a safety.
7082070374
*/
70821
- assert( u.bm.pC->deferredMoveto==0 );
70822
- rc = sqlite3VdbeCursorMoveto(u.bm.pC);
70823
- if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70824
-
70825
- if( u.bm.pC->isIndex ){
70826
- assert( !u.bm.pC->isTable );
70827
- VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
70828
- assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70829
- if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70830
- goto too_big;
70831
- }
70832
- u.bm.n = (u32)u.bm.n64;
70833
- }else{
70834
- VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bm.pCrsr, &u.bm.n);
70835
- assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70836
- if( u.bm.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70837
- goto too_big;
70838
- }
70839
- }
70840
- if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
70841
- goto no_mem;
70842
- }
70843
- pOut->n = u.bm.n;
70844
- MemSetTypeFlag(pOut, MEM_Blob);
70845
- if( u.bm.pC->isIndex ){
70846
- rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70847
- }else{
70848
- rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70375
+ assert( pC->deferredMoveto==0 );
70376
+ rc = sqlite3VdbeCursorMoveto(pC);
70377
+ if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70378
+
70379
+ if( pC->isTable==0 ){
70380
+ assert( !pC->isTable );
70381
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
70382
+ assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70383
+ if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70384
+ goto too_big;
70385
+ }
70386
+ n = (u32)n64;
70387
+ }else{
70388
+ VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n);
70389
+ assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70390
+ if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70391
+ goto too_big;
70392
+ }
70393
+ }
70394
+ if( sqlite3VdbeMemGrow(pOut, n, 0) ){
70395
+ goto no_mem;
70396
+ }
70397
+ pOut->n = n;
70398
+ MemSetTypeFlag(pOut, MEM_Blob);
70399
+ if( pC->isTable==0 ){
70400
+ rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z);
70401
+ }else{
70402
+ rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z);
7084970403
}
7085070404
pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
7085170405
UPDATE_MAX_BLOBSIZE(pOut);
7085270406
REGISTER_TRACE(pOp->p2, pOut);
7085370407
break;
@@ -70862,46 +70416,44 @@
7086270416
** P1 can be either an ordinary table or a virtual table. There used to
7086370417
** be a separate OP_VRowid opcode for use with virtual tables, but this
7086470418
** one opcode now works for both table types.
7086570419
*/
7086670420
case OP_Rowid: { /* out2-prerelease */
70867
-#if 0 /* local variables moved into u.bn */
7086870421
VdbeCursor *pC;
7086970422
i64 v;
7087070423
sqlite3_vtab *pVtab;
7087170424
const sqlite3_module *pModule;
70872
-#endif /* local variables moved into u.bn */
7087370425
7087470426
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70875
- u.bn.pC = p->apCsr[pOp->p1];
70876
- assert( u.bn.pC!=0 );
70877
- assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow );
70878
- if( u.bn.pC->nullRow ){
70427
+ pC = p->apCsr[pOp->p1];
70428
+ assert( pC!=0 );
70429
+ assert( pC->pseudoTableReg==0 || pC->nullRow );
70430
+ if( pC->nullRow ){
7087970431
pOut->flags = MEM_Null;
7088070432
break;
70881
- }else if( u.bn.pC->deferredMoveto ){
70882
- u.bn.v = u.bn.pC->movetoTarget;
70433
+ }else if( pC->deferredMoveto ){
70434
+ v = pC->movetoTarget;
7088370435
#ifndef SQLITE_OMIT_VIRTUALTABLE
70884
- }else if( u.bn.pC->pVtabCursor ){
70885
- u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab;
70886
- u.bn.pModule = u.bn.pVtab->pModule;
70887
- assert( u.bn.pModule->xRowid );
70888
- rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v);
70889
- sqlite3VtabImportErrmsg(p, u.bn.pVtab);
70436
+ }else if( pC->pVtabCursor ){
70437
+ pVtab = pC->pVtabCursor->pVtab;
70438
+ pModule = pVtab->pModule;
70439
+ assert( pModule->xRowid );
70440
+ rc = pModule->xRowid(pC->pVtabCursor, &v);
70441
+ sqlite3VtabImportErrmsg(p, pVtab);
7089070442
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7089170443
}else{
70892
- assert( u.bn.pC->pCursor!=0 );
70893
- rc = sqlite3VdbeCursorMoveto(u.bn.pC);
70444
+ assert( pC->pCursor!=0 );
70445
+ rc = sqlite3VdbeCursorMoveto(pC);
7089470446
if( rc ) goto abort_due_to_error;
70895
- if( u.bn.pC->rowidIsValid ){
70896
- u.bn.v = u.bn.pC->lastRowid;
70447
+ if( pC->rowidIsValid ){
70448
+ v = pC->lastRowid;
7089770449
}else{
70898
- rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v);
70450
+ rc = sqlite3BtreeKeySize(pC->pCursor, &v);
7089970451
assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
7090070452
}
7090170453
}
70902
- pOut->u.i = u.bn.v;
70454
+ pOut->u.i = v;
7090370455
break;
7090470456
}
7090570457
7090670458
/* Opcode: NullRow P1 * * * *
7090770459
**
@@ -70908,22 +70460,21 @@
7090870460
** Move the cursor P1 to a null row. Any OP_Column operations
7090970461
** that occur while the cursor is on the null row will always
7091070462
** write a NULL.
7091170463
*/
7091270464
case OP_NullRow: {
70913
-#if 0 /* local variables moved into u.bo */
7091470465
VdbeCursor *pC;
70915
-#endif /* local variables moved into u.bo */
7091670466
7091770467
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70918
- u.bo.pC = p->apCsr[pOp->p1];
70919
- assert( u.bo.pC!=0 );
70920
- u.bo.pC->nullRow = 1;
70921
- u.bo.pC->rowidIsValid = 0;
70922
- assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
70923
- if( u.bo.pC->pCursor ){
70924
- sqlite3BtreeClearCursor(u.bo.pC->pCursor);
70468
+ pC = p->apCsr[pOp->p1];
70469
+ assert( pC!=0 );
70470
+ pC->nullRow = 1;
70471
+ pC->rowidIsValid = 0;
70472
+ pC->cacheStatus = CACHE_STALE;
70473
+ assert( pC->pCursor || pC->pVtabCursor );
70474
+ if( pC->pCursor ){
70475
+ sqlite3BtreeClearCursor(pC->pCursor);
7092570476
}
7092670477
break;
7092770478
}
7092870479
7092970480
/* Opcode: Last P1 P2 * * *
@@ -70933,28 +70484,26 @@
7093370484
** If the table or index is empty and P2>0, then jump immediately to P2.
7093470485
** If P2 is 0 or if the table or index is not empty, fall through
7093570486
** to the following instruction.
7093670487
*/
7093770488
case OP_Last: { /* jump */
70938
-#if 0 /* local variables moved into u.bp */
7093970489
VdbeCursor *pC;
7094070490
BtCursor *pCrsr;
7094170491
int res;
70942
-#endif /* local variables moved into u.bp */
7094370492
7094470493
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70945
- u.bp.pC = p->apCsr[pOp->p1];
70946
- assert( u.bp.pC!=0 );
70947
- u.bp.pCrsr = u.bp.pC->pCursor;
70948
- u.bp.res = 0;
70949
- assert( u.bp.pCrsr!=0 );
70950
- rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
70951
- u.bp.pC->nullRow = (u8)u.bp.res;
70952
- u.bp.pC->deferredMoveto = 0;
70953
- u.bp.pC->rowidIsValid = 0;
70954
- u.bp.pC->cacheStatus = CACHE_STALE;
70955
- if( pOp->p2>0 && u.bp.res ){
70494
+ pC = p->apCsr[pOp->p1];
70495
+ assert( pC!=0 );
70496
+ pCrsr = pC->pCursor;
70497
+ res = 0;
70498
+ assert( pCrsr!=0 );
70499
+ rc = sqlite3BtreeLast(pCrsr, &res);
70500
+ pC->nullRow = (u8)res;
70501
+ pC->deferredMoveto = 0;
70502
+ pC->rowidIsValid = 0;
70503
+ pC->cacheStatus = CACHE_STALE;
70504
+ if( pOp->p2>0 && res ){
7095670505
pc = pOp->p2 - 1;
7095770506
}
7095870507
break;
7095970508
}
7096070509
@@ -70987,35 +70536,32 @@
7098770536
** If the table or index is empty and P2>0, then jump immediately to P2.
7098870537
** If P2 is 0 or if the table or index is not empty, fall through
7098970538
** to the following instruction.
7099070539
*/
7099170540
case OP_Rewind: { /* jump */
70992
-#if 0 /* local variables moved into u.bq */
7099370541
VdbeCursor *pC;
7099470542
BtCursor *pCrsr;
7099570543
int res;
70996
-#endif /* local variables moved into u.bq */
7099770544
7099870545
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70999
- u.bq.pC = p->apCsr[pOp->p1];
71000
- assert( u.bq.pC!=0 );
71001
- assert( u.bq.pC->isSorter==(pOp->opcode==OP_SorterSort) );
71002
- u.bq.res = 1;
71003
- if( isSorter(u.bq.pC) ){
71004
- rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
70546
+ pC = p->apCsr[pOp->p1];
70547
+ assert( pC!=0 );
70548
+ assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
70549
+ res = 1;
70550
+ if( isSorter(pC) ){
70551
+ rc = sqlite3VdbeSorterRewind(db, pC, &res);
7100570552
}else{
71006
- u.bq.pCrsr = u.bq.pC->pCursor;
71007
- assert( u.bq.pCrsr );
71008
- rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
71009
- u.bq.pC->atFirst = u.bq.res==0 ?1:0;
71010
- u.bq.pC->deferredMoveto = 0;
71011
- u.bq.pC->cacheStatus = CACHE_STALE;
71012
- u.bq.pC->rowidIsValid = 0;
71013
- }
71014
- u.bq.pC->nullRow = (u8)u.bq.res;
70553
+ pCrsr = pC->pCursor;
70554
+ assert( pCrsr );
70555
+ rc = sqlite3BtreeFirst(pCrsr, &res);
70556
+ pC->deferredMoveto = 0;
70557
+ pC->cacheStatus = CACHE_STALE;
70558
+ pC->rowidIsValid = 0;
70559
+ }
70560
+ pC->nullRow = (u8)res;
7101570561
assert( pOp->p2>0 && pOp->p2<p->nOp );
71016
- if( u.bq.res ){
70562
+ if( res ){
7101770563
pc = pOp->p2 - 1;
7101870564
}
7101970565
break;
7102070566
}
7102170567
@@ -71024,71 +70570,85 @@
7102470570
** Advance cursor P1 so that it points to the next key/data pair in its
7102570571
** table or index. If there are no more key/value pairs then fall through
7102670572
** to the following instruction. But if the cursor advance was successful,
7102770573
** jump immediately to P2.
7102870574
**
71029
-** The P1 cursor must be for a real table, not a pseudo-table.
70575
+** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
70576
+** been opened prior to this opcode or the program will segfault.
7103070577
**
7103170578
** P4 is always of type P4_ADVANCE. The function pointer points to
7103270579
** sqlite3BtreeNext().
7103370580
**
7103470581
** If P5 is positive and the jump is taken, then event counter
7103570582
** number P5-1 in the prepared statement is incremented.
7103670583
**
71037
-** See also: Prev
70584
+** See also: Prev, NextIfOpen
70585
+*/
70586
+/* Opcode: NextIfOpen P1 P2 * * P5
70587
+**
70588
+** This opcode works just like OP_Next except that if cursor P1 is not
70589
+** open it behaves a no-op.
7103870590
*/
7103970591
/* Opcode: Prev P1 P2 * * P5
7104070592
**
7104170593
** Back up cursor P1 so that it points to the previous key/data pair in its
7104270594
** table or index. If there is no previous key/value pairs then fall through
7104370595
** to the following instruction. But if the cursor backup was successful,
7104470596
** jump immediately to P2.
7104570597
**
71046
-** The P1 cursor must be for a real table, not a pseudo-table.
70598
+** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
70599
+** not open then the behavior is undefined.
7104770600
**
7104870601
** P4 is always of type P4_ADVANCE. The function pointer points to
7104970602
** sqlite3BtreePrevious().
7105070603
**
7105170604
** If P5 is positive and the jump is taken, then event counter
7105270605
** number P5-1 in the prepared statement is incremented.
7105370606
*/
71054
-case OP_SorterNext: /* jump */
70607
+/* Opcode: PrevIfOpen P1 P2 * * P5
70608
+**
70609
+** This opcode works just like OP_Prev except that if cursor P1 is not
70610
+** open it behaves a no-op.
70611
+*/
70612
+case OP_SorterNext: { /* jump */
70613
+ VdbeCursor *pC;
70614
+ int res;
70615
+
70616
+ pC = p->apCsr[pOp->p1];
70617
+ assert( isSorter(pC) );
70618
+ rc = sqlite3VdbeSorterNext(db, pC, &res);
70619
+ goto next_tail;
70620
+case OP_PrevIfOpen: /* jump */
70621
+case OP_NextIfOpen: /* jump */
70622
+ if( p->apCsr[pOp->p1]==0 ) break;
70623
+ /* Fall through */
7105570624
case OP_Prev: /* jump */
71056
-case OP_Next: { /* jump */
71057
-#if 0 /* local variables moved into u.br */
71058
- VdbeCursor *pC;
71059
- int res;
71060
-#endif /* local variables moved into u.br */
71061
-
70625
+case OP_Next: /* jump */
7106270626
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7106370627
assert( pOp->p5<ArraySize(p->aCounter) );
71064
- u.br.pC = p->apCsr[pOp->p1];
71065
- if( u.br.pC==0 ){
71066
- break; /* See ticket #2273 */
71067
- }
71068
- assert( u.br.pC->isSorter==(pOp->opcode==OP_SorterNext) );
71069
- if( isSorter(u.br.pC) ){
71070
- assert( pOp->opcode==OP_SorterNext );
71071
- rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res);
71072
- }else{
71073
- /* u.br.res = 1; // Always initialized by the xAdvance() call */
71074
- assert( u.br.pC->deferredMoveto==0 );
71075
- assert( u.br.pC->pCursor );
71076
- assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
71077
- assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
71078
- rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res);
71079
- }
71080
- u.br.pC->nullRow = (u8)u.br.res;
71081
- u.br.pC->cacheStatus = CACHE_STALE;
71082
- if( u.br.res==0 ){
70628
+ pC = p->apCsr[pOp->p1];
70629
+ assert( pC!=0 );
70630
+ assert( pC->deferredMoveto==0 );
70631
+ assert( pC->pCursor );
70632
+ assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
70633
+ assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
70634
+ assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
70635
+ assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
70636
+ rc = pOp->p4.xAdvance(pC->pCursor, &res);
70637
+next_tail:
70638
+ pC->cacheStatus = CACHE_STALE;
70639
+ if( res==0 ){
70640
+ pC->nullRow = 0;
7108370641
pc = pOp->p2 - 1;
7108470642
p->aCounter[pOp->p5]++;
7108570643
#ifdef SQLITE_TEST
7108670644
sqlite3_search_count++;
7108770645
#endif
70646
+ }else{
70647
+ pC->nullRow = 1;
7108870648
}
71089
- u.br.pC->rowidIsValid = 0;
70649
+ pC->rowidIsValid = 0;
7109070650
goto check_for_interrupt;
7109170651
}
7109270652
7109370653
/* Opcode: IdxInsert P1 P2 P3 * P5
7109470654
** Synopsis: key=r[P2]
@@ -71103,39 +70663,37 @@
7110370663
** This instruction only works for indices. The equivalent instruction
7110470664
** for tables is OP_Insert.
7110570665
*/
7110670666
case OP_SorterInsert: /* in2 */
7110770667
case OP_IdxInsert: { /* in2 */
71108
-#if 0 /* local variables moved into u.bs */
7110970668
VdbeCursor *pC;
7111070669
BtCursor *pCrsr;
7111170670
int nKey;
7111270671
const char *zKey;
71113
-#endif /* local variables moved into u.bs */
7111470672
7111570673
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71116
- u.bs.pC = p->apCsr[pOp->p1];
71117
- assert( u.bs.pC!=0 );
71118
- assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) );
70674
+ pC = p->apCsr[pOp->p1];
70675
+ assert( pC!=0 );
70676
+ assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) );
7111970677
pIn2 = &aMem[pOp->p2];
7112070678
assert( pIn2->flags & MEM_Blob );
71121
- u.bs.pCrsr = u.bs.pC->pCursor;
70679
+ pCrsr = pC->pCursor;
7112270680
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71123
- assert( u.bs.pCrsr!=0 );
71124
- assert( u.bs.pC->isTable==0 );
70681
+ assert( pCrsr!=0 );
70682
+ assert( pC->isTable==0 );
7112570683
rc = ExpandBlob(pIn2);
7112670684
if( rc==SQLITE_OK ){
71127
- if( isSorter(u.bs.pC) ){
71128
- rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
70685
+ if( isSorter(pC) ){
70686
+ rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
7112970687
}else{
71130
- u.bs.nKey = pIn2->n;
71131
- u.bs.zKey = pIn2->z;
71132
- rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
71133
- ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
70688
+ nKey = pIn2->n;
70689
+ zKey = pIn2->z;
70690
+ rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3,
70691
+ ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
7113470692
);
71135
- assert( u.bs.pC->deferredMoveto==0 );
71136
- u.bs.pC->cacheStatus = CACHE_STALE;
70693
+ assert( pC->deferredMoveto==0 );
70694
+ pC->cacheStatus = CACHE_STALE;
7113770695
}
7113870696
}
7113970697
break;
7114070698
}
7114170699
@@ -71145,38 +70703,36 @@
7114570703
** The content of P3 registers starting at register P2 form
7114670704
** an unpacked index key. This opcode removes that entry from the
7114770705
** index opened by cursor P1.
7114870706
*/
7114970707
case OP_IdxDelete: {
71150
-#if 0 /* local variables moved into u.bt */
7115170708
VdbeCursor *pC;
7115270709
BtCursor *pCrsr;
7115370710
int res;
7115470711
UnpackedRecord r;
71155
-#endif /* local variables moved into u.bt */
7115670712
7115770713
assert( pOp->p3>0 );
7115870714
assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
7115970715
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71160
- u.bt.pC = p->apCsr[pOp->p1];
71161
- assert( u.bt.pC!=0 );
71162
- u.bt.pCrsr = u.bt.pC->pCursor;
71163
- assert( u.bt.pCrsr!=0 );
70716
+ pC = p->apCsr[pOp->p1];
70717
+ assert( pC!=0 );
70718
+ pCrsr = pC->pCursor;
70719
+ assert( pCrsr!=0 );
7116470720
assert( pOp->p5==0 );
71165
- u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
71166
- u.bt.r.nField = (u16)pOp->p3;
71167
- u.bt.r.flags = UNPACKED_PREFIX_MATCH;
71168
- u.bt.r.aMem = &aMem[pOp->p2];
70721
+ r.pKeyInfo = pC->pKeyInfo;
70722
+ r.nField = (u16)pOp->p3;
70723
+ r.flags = UNPACKED_PREFIX_MATCH;
70724
+ r.aMem = &aMem[pOp->p2];
7116970725
#ifdef SQLITE_DEBUG
71170
- { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
70726
+ { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7117170727
#endif
71172
- rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
71173
- if( rc==SQLITE_OK && u.bt.res==0 ){
71174
- rc = sqlite3BtreeDelete(u.bt.pCrsr);
70728
+ rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
70729
+ if( rc==SQLITE_OK && res==0 ){
70730
+ rc = sqlite3BtreeDelete(pCrsr);
7117570731
}
71176
- assert( u.bt.pC->deferredMoveto==0 );
71177
- u.bt.pC->cacheStatus = CACHE_STALE;
70732
+ assert( pC->deferredMoveto==0 );
70733
+ pC->cacheStatus = CACHE_STALE;
7117870734
break;
7117970735
}
7118070736
7118170737
/* Opcode: IdxRowid P1 P2 * * *
7118270738
** Synopsis: r[P2]=rowid
@@ -71186,32 +70742,31 @@
7118670742
** the rowid of the table entry to which this index entry points.
7118770743
**
7118870744
** See also: Rowid, MakeRecord.
7118970745
*/
7119070746
case OP_IdxRowid: { /* out2-prerelease */
71191
-#if 0 /* local variables moved into u.bu */
7119270747
BtCursor *pCrsr;
7119370748
VdbeCursor *pC;
7119470749
i64 rowid;
71195
-#endif /* local variables moved into u.bu */
7119670750
7119770751
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71198
- u.bu.pC = p->apCsr[pOp->p1];
71199
- assert( u.bu.pC!=0 );
71200
- u.bu.pCrsr = u.bu.pC->pCursor;
71201
- assert( u.bu.pCrsr!=0 );
70752
+ pC = p->apCsr[pOp->p1];
70753
+ assert( pC!=0 );
70754
+ pCrsr = pC->pCursor;
70755
+ assert( pCrsr!=0 );
7120270756
pOut->flags = MEM_Null;
71203
- rc = sqlite3VdbeCursorMoveto(u.bu.pC);
70757
+ rc = sqlite3VdbeCursorMoveto(pC);
7120470758
if( NEVER(rc) ) goto abort_due_to_error;
71205
- assert( u.bu.pC->deferredMoveto==0 );
71206
- assert( u.bu.pC->isTable==0 );
71207
- if( !u.bu.pC->nullRow ){
71208
- rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
70759
+ assert( pC->deferredMoveto==0 );
70760
+ assert( pC->isTable==0 );
70761
+ if( !pC->nullRow ){
70762
+ rowid = 0; /* Not needed. Only used to silence a warning. */
70763
+ rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
7120970764
if( rc!=SQLITE_OK ){
7121070765
goto abort_due_to_error;
7121170766
}
71212
- pOut->u.i = u.bu.rowid;
70767
+ pOut->u.i = rowid;
7121370768
pOut->flags = MEM_Int;
7121470769
}
7121570770
break;
7121670771
}
7121770772
@@ -71243,43 +70798,42 @@
7124370798
** If P5 is non-zero then the key value is increased by an epsilon prior
7124470799
** to the comparison. This makes the opcode work like IdxLE.
7124570800
*/
7124670801
case OP_IdxLT: /* jump */
7124770802
case OP_IdxGE: { /* jump */
71248
-#if 0 /* local variables moved into u.bv */
7124970803
VdbeCursor *pC;
7125070804
int res;
7125170805
UnpackedRecord r;
71252
-#endif /* local variables moved into u.bv */
7125370806
7125470807
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71255
- u.bv.pC = p->apCsr[pOp->p1];
71256
- assert( u.bv.pC!=0 );
71257
- assert( u.bv.pC->isOrdered );
71258
- assert( u.bv.pC->pCursor!=0);
71259
- assert( u.bv.pC->deferredMoveto==0 );
70808
+ pC = p->apCsr[pOp->p1];
70809
+ assert( pC!=0 );
70810
+ assert( pC->isOrdered );
70811
+ assert( pC->pCursor!=0);
70812
+ assert( pC->deferredMoveto==0 );
7126070813
assert( pOp->p5==0 || pOp->p5==1 );
7126170814
assert( pOp->p4type==P4_INT32 );
71262
- u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
71263
- u.bv.r.nField = (u16)pOp->p4.i;
70815
+ r.pKeyInfo = pC->pKeyInfo;
70816
+ r.nField = (u16)pOp->p4.i;
7126470817
if( pOp->p5 ){
71265
- u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
70818
+ r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
7126670819
}else{
71267
- u.bv.r.flags = UNPACKED_PREFIX_MATCH;
70820
+ r.flags = UNPACKED_PREFIX_MATCH;
7126870821
}
71269
- u.bv.r.aMem = &aMem[pOp->p3];
70822
+ r.aMem = &aMem[pOp->p3];
7127070823
#ifdef SQLITE_DEBUG
71271
- { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
70824
+ { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7127270825
#endif
71273
- rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
70826
+ res = 0; /* Not needed. Only used to silence a warning. */
70827
+ rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
7127470828
if( pOp->opcode==OP_IdxLT ){
71275
- u.bv.res = -u.bv.res;
70829
+ res = -res;
7127670830
}else{
7127770831
assert( pOp->opcode==OP_IdxGE );
71278
- u.bv.res++;
70832
+ res++;
7127970833
}
71280
- if( u.bv.res>0 ){
70834
+ if( res>0 ){
7128170835
pc = pOp->p2 - 1 ;
7128270836
}
7128370837
break;
7128470838
}
7128570839
@@ -71302,47 +70856,46 @@
7130270856
** If AUTOVACUUM is disabled then a zero is stored in register P2.
7130370857
**
7130470858
** See also: Clear
7130570859
*/
7130670860
case OP_Destroy: { /* out2-prerelease */
71307
-#if 0 /* local variables moved into u.bw */
7130870861
int iMoved;
7130970862
int iCnt;
7131070863
Vdbe *pVdbe;
7131170864
int iDb;
71312
-#endif /* local variables moved into u.bw */
7131370865
7131470866
assert( p->readOnly==0 );
7131570867
#ifndef SQLITE_OMIT_VIRTUALTABLE
71316
- u.bw.iCnt = 0;
71317
- for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){
71318
- if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader
71319
- && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0
70868
+ iCnt = 0;
70869
+ for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){
70870
+ if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader
70871
+ && pVdbe->inVtabMethod<2 && pVdbe->pc>=0
7132070872
){
71321
- u.bw.iCnt++;
70873
+ iCnt++;
7132270874
}
7132370875
}
7132470876
#else
71325
- u.bw.iCnt = db->nVdbeRead;
70877
+ iCnt = db->nVdbeRead;
7132670878
#endif
7132770879
pOut->flags = MEM_Null;
71328
- if( u.bw.iCnt>1 ){
70880
+ if( iCnt>1 ){
7132970881
rc = SQLITE_LOCKED;
7133070882
p->errorAction = OE_Abort;
7133170883
}else{
71332
- u.bw.iDb = pOp->p3;
71333
- assert( u.bw.iCnt==1 );
71334
- assert( (p->btreeMask & (((yDbMask)1)<<u.bw.iDb))!=0 );
71335
- rc = sqlite3BtreeDropTable(db->aDb[u.bw.iDb].pBt, pOp->p1, &u.bw.iMoved);
70884
+ iDb = pOp->p3;
70885
+ assert( iCnt==1 );
70886
+ assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
70887
+ iMoved = 0; /* Not needed. Only to silence a warning. */
70888
+ rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
7133670889
pOut->flags = MEM_Int;
71337
- pOut->u.i = u.bw.iMoved;
70890
+ pOut->u.i = iMoved;
7133870891
#ifndef SQLITE_OMIT_AUTOVACUUM
71339
- if( rc==SQLITE_OK && u.bw.iMoved!=0 ){
71340
- sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1);
70892
+ if( rc==SQLITE_OK && iMoved!=0 ){
70893
+ sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
7134170894
/* All OP_Destroy operations occur on the same btree */
71342
- assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 );
71343
- resetSchemaOnFault = u.bw.iDb+1;
70895
+ assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
70896
+ resetSchemaOnFault = iDb+1;
7134470897
}
7134570898
#endif
7134670899
}
7134770900
break;
7134870901
}
@@ -71364,27 +70917,25 @@
7136470917
** also incremented by the number of rows in the table being cleared.
7136570918
**
7136670919
** See also: Destroy
7136770920
*/
7136870921
case OP_Clear: {
71369
-#if 0 /* local variables moved into u.bx */
7137070922
int nChange;
71371
-#endif /* local variables moved into u.bx */
71372
-
71373
- u.bx.nChange = 0;
70923
+
70924
+ nChange = 0;
7137470925
assert( p->readOnly==0 );
7137570926
assert( pOp->p1!=1 );
7137670927
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
7137770928
rc = sqlite3BtreeClearTable(
71378
- db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
70929
+ db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
7137970930
);
7138070931
if( pOp->p3 ){
71381
- p->nChange += u.bx.nChange;
70932
+ p->nChange += nChange;
7138270933
if( pOp->p3>0 ){
7138370934
assert( memIsValid(&aMem[pOp->p3]) );
7138470935
memAboutToChange(p, &aMem[pOp->p3]);
71385
- aMem[pOp->p3].u.i += u.bx.nChange;
70936
+ aMem[pOp->p3].u.i += nChange;
7138670937
}
7138770938
}
7138870939
break;
7138970940
}
7139070941
@@ -71412,30 +70963,28 @@
7141270963
**
7141370964
** See documentation on OP_CreateTable for additional information.
7141470965
*/
7141570966
case OP_CreateIndex: /* out2-prerelease */
7141670967
case OP_CreateTable: { /* out2-prerelease */
71417
-#if 0 /* local variables moved into u.by */
7141870968
int pgno;
7141970969
int flags;
7142070970
Db *pDb;
71421
-#endif /* local variables moved into u.by */
7142270971
71423
- u.by.pgno = 0;
70972
+ pgno = 0;
7142470973
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7142570974
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7142670975
assert( p->readOnly==0 );
71427
- u.by.pDb = &db->aDb[pOp->p1];
71428
- assert( u.by.pDb->pBt!=0 );
70976
+ pDb = &db->aDb[pOp->p1];
70977
+ assert( pDb->pBt!=0 );
7142970978
if( pOp->opcode==OP_CreateTable ){
71430
- /* u.by.flags = BTREE_INTKEY; */
71431
- u.by.flags = BTREE_INTKEY;
70979
+ /* flags = BTREE_INTKEY; */
70980
+ flags = BTREE_INTKEY;
7143270981
}else{
71433
- u.by.flags = BTREE_BLOBKEY;
70982
+ flags = BTREE_BLOBKEY;
7143470983
}
71435
- rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags);
71436
- pOut->u.i = u.by.pgno;
70984
+ rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
70985
+ pOut->u.i = pgno;
7143770986
break;
7143870987
}
7143970988
7144070989
/* Opcode: ParseSchema P1 * * P4 *
7144170990
**
@@ -71444,56 +70993,54 @@
7144470993
**
7144570994
** This opcode invokes the parser to create a new virtual machine,
7144670995
** then runs the new virtual machine. It is thus a re-entrant opcode.
7144770996
*/
7144870997
case OP_ParseSchema: {
71449
-#if 0 /* local variables moved into u.bz */
7145070998
int iDb;
7145170999
const char *zMaster;
7145271000
char *zSql;
7145371001
InitData initData;
71454
-#endif /* local variables moved into u.bz */
7145571002
7145671003
/* Any prepared statement that invokes this opcode will hold mutexes
71457
- ** on every btree. This is a prerequisite for invoking
71004
+ ** on every btree. This is a prerequisite for invoking
7145871005
** sqlite3InitCallback().
7145971006
*/
7146071007
#ifdef SQLITE_DEBUG
71461
- for(u.bz.iDb=0; u.bz.iDb<db->nDb; u.bz.iDb++){
71462
- assert( u.bz.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bz.iDb].pBt) );
71008
+ for(iDb=0; iDb<db->nDb; iDb++){
71009
+ assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
7146371010
}
7146471011
#endif
7146571012
71466
- u.bz.iDb = pOp->p1;
71467
- assert( u.bz.iDb>=0 && u.bz.iDb<db->nDb );
71468
- assert( DbHasProperty(db, u.bz.iDb, DB_SchemaLoaded) );
71013
+ iDb = pOp->p1;
71014
+ assert( iDb>=0 && iDb<db->nDb );
71015
+ assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
7146971016
/* Used to be a conditional */ {
71470
- u.bz.zMaster = SCHEMA_TABLE(u.bz.iDb);
71471
- u.bz.initData.db = db;
71472
- u.bz.initData.iDb = pOp->p1;
71473
- u.bz.initData.pzErrMsg = &p->zErrMsg;
71474
- u.bz.zSql = sqlite3MPrintf(db,
71017
+ zMaster = SCHEMA_TABLE(iDb);
71018
+ initData.db = db;
71019
+ initData.iDb = pOp->p1;
71020
+ initData.pzErrMsg = &p->zErrMsg;
71021
+ zSql = sqlite3MPrintf(db,
7147571022
"SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
71476
- db->aDb[u.bz.iDb].zName, u.bz.zMaster, pOp->p4.z);
71477
- if( u.bz.zSql==0 ){
71023
+ db->aDb[iDb].zName, zMaster, pOp->p4.z);
71024
+ if( zSql==0 ){
7147871025
rc = SQLITE_NOMEM;
7147971026
}else{
7148071027
assert( db->init.busy==0 );
7148171028
db->init.busy = 1;
71482
- u.bz.initData.rc = SQLITE_OK;
71029
+ initData.rc = SQLITE_OK;
7148371030
assert( !db->mallocFailed );
71484
- rc = sqlite3_exec(db, u.bz.zSql, sqlite3InitCallback, &u.bz.initData, 0);
71485
- if( rc==SQLITE_OK ) rc = u.bz.initData.rc;
71486
- sqlite3DbFree(db, u.bz.zSql);
71031
+ rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
71032
+ if( rc==SQLITE_OK ) rc = initData.rc;
71033
+ sqlite3DbFree(db, zSql);
7148771034
db->init.busy = 0;
7148871035
}
7148971036
}
7149071037
if( rc ) sqlite3ResetAllSchemasOfConnection(db);
7149171038
if( rc==SQLITE_NOMEM ){
7149271039
goto no_mem;
7149371040
}
71494
- break;
71041
+ break;
7149571042
}
7149671043
7149771044
#if !defined(SQLITE_OMIT_ANALYZE)
7149871045
/* Opcode: LoadAnalysis P1 * * * *
7149971046
**
@@ -71565,46 +71112,44 @@
7156571112
** file, not the main database file.
7156671113
**
7156771114
** This opcode is used to implement the integrity_check pragma.
7156871115
*/
7156971116
case OP_IntegrityCk: {
71570
-#if 0 /* local variables moved into u.ca */
7157171117
int nRoot; /* Number of tables to check. (Number of root pages.) */
7157271118
int *aRoot; /* Array of rootpage numbers for tables to be checked */
7157371119
int j; /* Loop counter */
7157471120
int nErr; /* Number of errors reported */
7157571121
char *z; /* Text of the error report */
7157671122
Mem *pnErr; /* Register keeping track of errors remaining */
71577
-#endif /* local variables moved into u.ca */
7157871123
7157971124
assert( p->bIsReader );
71580
- u.ca.nRoot = pOp->p2;
71581
- assert( u.ca.nRoot>0 );
71582
- u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) );
71583
- if( u.ca.aRoot==0 ) goto no_mem;
71125
+ nRoot = pOp->p2;
71126
+ assert( nRoot>0 );
71127
+ aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
71128
+ if( aRoot==0 ) goto no_mem;
7158471129
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71585
- u.ca.pnErr = &aMem[pOp->p3];
71586
- assert( (u.ca.pnErr->flags & MEM_Int)!=0 );
71587
- assert( (u.ca.pnErr->flags & (MEM_Str|MEM_Blob))==0 );
71130
+ pnErr = &aMem[pOp->p3];
71131
+ assert( (pnErr->flags & MEM_Int)!=0 );
71132
+ assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
7158871133
pIn1 = &aMem[pOp->p1];
71589
- for(u.ca.j=0; u.ca.j<u.ca.nRoot; u.ca.j++){
71590
- u.ca.aRoot[u.ca.j] = (int)sqlite3VdbeIntValue(&pIn1[u.ca.j]);
71134
+ for(j=0; j<nRoot; j++){
71135
+ aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
7159171136
}
71592
- u.ca.aRoot[u.ca.j] = 0;
71137
+ aRoot[j] = 0;
7159371138
assert( pOp->p5<db->nDb );
7159471139
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
71595
- u.ca.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.ca.aRoot, u.ca.nRoot,
71596
- (int)u.ca.pnErr->u.i, &u.ca.nErr);
71597
- sqlite3DbFree(db, u.ca.aRoot);
71598
- u.ca.pnErr->u.i -= u.ca.nErr;
71140
+ z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
71141
+ (int)pnErr->u.i, &nErr);
71142
+ sqlite3DbFree(db, aRoot);
71143
+ pnErr->u.i -= nErr;
7159971144
sqlite3VdbeMemSetNull(pIn1);
71600
- if( u.ca.nErr==0 ){
71601
- assert( u.ca.z==0 );
71602
- }else if( u.ca.z==0 ){
71145
+ if( nErr==0 ){
71146
+ assert( z==0 );
71147
+ }else if( z==0 ){
7160371148
goto no_mem;
7160471149
}else{
71605
- sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free);
71150
+ sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
7160671151
}
7160771152
UPDATE_MAX_BLOBSIZE(pIn1);
7160871153
sqlite3VdbeChangeEncoding(pIn1, encoding);
7160971154
break;
7161071155
}
@@ -71636,24 +71181,22 @@
7163671181
** Extract the smallest value from boolean index P1 and put that value into
7163771182
** register P3. Or, if boolean index P1 is initially empty, leave P3
7163871183
** unchanged and jump to instruction P2.
7163971184
*/
7164071185
case OP_RowSetRead: { /* jump, in1, out3 */
71641
-#if 0 /* local variables moved into u.cb */
7164271186
i64 val;
71643
-#endif /* local variables moved into u.cb */
7164471187
7164571188
pIn1 = &aMem[pOp->p1];
71646
- if( (pIn1->flags & MEM_RowSet)==0
71647
- || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
71189
+ if( (pIn1->flags & MEM_RowSet)==0
71190
+ || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
7164871191
){
7164971192
/* The boolean index is empty */
7165071193
sqlite3VdbeMemSetNull(pIn1);
7165171194
pc = pOp->p2 - 1;
7165271195
}else{
7165371196
/* A value was pulled from the index */
71654
- sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
71197
+ sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7165571198
}
7165671199
goto check_for_interrupt;
7165771200
}
7165871201
7165971202
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -71679,18 +71222,16 @@
7167971222
** inserted, there is no need to search to see if the same value was
7168071223
** previously inserted as part of set X (only if it was previously
7168171224
** inserted as part of some other set).
7168271225
*/
7168371226
case OP_RowSetTest: { /* jump, in1, in3 */
71684
-#if 0 /* local variables moved into u.cc */
7168571227
int iSet;
7168671228
int exists;
71687
-#endif /* local variables moved into u.cc */
7168871229
7168971230
pIn1 = &aMem[pOp->p1];
7169071231
pIn3 = &aMem[pOp->p3];
71691
- u.cc.iSet = pOp->p4.i;
71232
+ iSet = pOp->p4.i;
7169271233
assert( pIn3->flags&MEM_Int );
7169371234
7169471235
/* If there is anything other than a rowset object in memory cell P1,
7169571236
** delete it now and initialize P1 with an empty rowset
7169671237
*/
@@ -71698,21 +71239,21 @@
7169871239
sqlite3VdbeMemSetRowSet(pIn1);
7169971240
if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
7170071241
}
7170171242
7170271243
assert( pOp->p4type==P4_INT32 );
71703
- assert( u.cc.iSet==-1 || u.cc.iSet>=0 );
71704
- if( u.cc.iSet ){
71705
- u.cc.exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71706
- (u8)(u.cc.iSet>=0 ? u.cc.iSet & 0xf : 0xff),
71244
+ assert( iSet==-1 || iSet>=0 );
71245
+ if( iSet ){
71246
+ exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71247
+ (u8)(iSet>=0 ? iSet & 0xf : 0xff),
7170771248
pIn3->u.i);
71708
- if( u.cc.exists ){
71249
+ if( exists ){
7170971250
pc = pOp->p2 - 1;
7171071251
break;
7171171252
}
7171271253
}
71713
- if( u.cc.iSet>=0 ){
71254
+ if( iSet>=0 ){
7171471255
sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
7171571256
}
7171671257
break;
7171771258
}
7171871259
@@ -71731,111 +71272,109 @@
7173171272
** memory required by the sub-vdbe at runtime.
7173271273
**
7173371274
** P4 is a pointer to the VM containing the trigger program.
7173471275
*/
7173571276
case OP_Program: { /* jump */
71736
-#if 0 /* local variables moved into u.cd */
7173771277
int nMem; /* Number of memory registers for sub-program */
7173871278
int nByte; /* Bytes of runtime space required for sub-program */
7173971279
Mem *pRt; /* Register to allocate runtime space */
7174071280
Mem *pMem; /* Used to iterate through memory cells */
7174171281
Mem *pEnd; /* Last memory cell in new array */
7174271282
VdbeFrame *pFrame; /* New vdbe frame to execute in */
7174371283
SubProgram *pProgram; /* Sub-program to execute */
7174471284
void *t; /* Token identifying trigger */
71745
-#endif /* local variables moved into u.cd */
7174671285
71747
- u.cd.pProgram = pOp->p4.pProgram;
71748
- u.cd.pRt = &aMem[pOp->p3];
71749
- assert( u.cd.pProgram->nOp>0 );
71750
-
71751
- /* If the p5 flag is clear, then recursive invocation of triggers is
71286
+ pProgram = pOp->p4.pProgram;
71287
+ pRt = &aMem[pOp->p3];
71288
+ assert( pProgram->nOp>0 );
71289
+
71290
+ /* If the p5 flag is clear, then recursive invocation of triggers is
7175271291
** disabled for backwards compatibility (p5 is set if this sub-program
7175371292
** is really a trigger, not a foreign key action, and the flag set
7175471293
** and cleared by the "PRAGMA recursive_triggers" command is clear).
71755
- **
71756
- ** It is recursive invocation of triggers, at the SQL level, that is
71757
- ** disabled. In some cases a single trigger may generate more than one
71758
- ** SubProgram (if the trigger may be executed with more than one different
71294
+ **
71295
+ ** It is recursive invocation of triggers, at the SQL level, that is
71296
+ ** disabled. In some cases a single trigger may generate more than one
71297
+ ** SubProgram (if the trigger may be executed with more than one different
7175971298
** ON CONFLICT algorithm). SubProgram structures associated with a
71760
- ** single trigger all have the same value for the SubProgram.token
71299
+ ** single trigger all have the same value for the SubProgram.token
7176171300
** variable. */
7176271301
if( pOp->p5 ){
71763
- u.cd.t = u.cd.pProgram->token;
71764
- for(u.cd.pFrame=p->pFrame; u.cd.pFrame && u.cd.pFrame->token!=u.cd.t; u.cd.pFrame=u.cd.pFrame->pParent);
71765
- if( u.cd.pFrame ) break;
71302
+ t = pProgram->token;
71303
+ for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent);
71304
+ if( pFrame ) break;
7176671305
}
7176771306
7176871307
if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
7176971308
rc = SQLITE_ERROR;
7177071309
sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
7177171310
break;
7177271311
}
7177371312
71774
- /* Register u.cd.pRt is used to store the memory required to save the state
71313
+ /* Register pRt is used to store the memory required to save the state
7177571314
** of the current program, and the memory required at runtime to execute
71776
- ** the trigger program. If this trigger has been fired before, then u.cd.pRt
71315
+ ** the trigger program. If this trigger has been fired before, then pRt
7177771316
** is already allocated. Otherwise, it must be initialized. */
71778
- if( (u.cd.pRt->flags&MEM_Frame)==0 ){
71779
- /* SubProgram.nMem is set to the number of memory cells used by the
71317
+ if( (pRt->flags&MEM_Frame)==0 ){
71318
+ /* SubProgram.nMem is set to the number of memory cells used by the
7178071319
** program stored in SubProgram.aOp. As well as these, one memory
7178171320
** cell is required for each cursor used by the program. Set local
71782
- ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value.
71321
+ ** variable nMem (and later, VdbeFrame.nChildMem) to this value.
7178371322
*/
71784
- u.cd.nMem = u.cd.pProgram->nMem + u.cd.pProgram->nCsr;
71785
- u.cd.nByte = ROUND8(sizeof(VdbeFrame))
71786
- + u.cd.nMem * sizeof(Mem)
71787
- + u.cd.pProgram->nCsr * sizeof(VdbeCursor *)
71788
- + u.cd.pProgram->nOnce * sizeof(u8);
71789
- u.cd.pFrame = sqlite3DbMallocZero(db, u.cd.nByte);
71790
- if( !u.cd.pFrame ){
71323
+ nMem = pProgram->nMem + pProgram->nCsr;
71324
+ nByte = ROUND8(sizeof(VdbeFrame))
71325
+ + nMem * sizeof(Mem)
71326
+ + pProgram->nCsr * sizeof(VdbeCursor *)
71327
+ + pProgram->nOnce * sizeof(u8);
71328
+ pFrame = sqlite3DbMallocZero(db, nByte);
71329
+ if( !pFrame ){
7179171330
goto no_mem;
7179271331
}
71793
- sqlite3VdbeMemRelease(u.cd.pRt);
71794
- u.cd.pRt->flags = MEM_Frame;
71795
- u.cd.pRt->u.pFrame = u.cd.pFrame;
71796
-
71797
- u.cd.pFrame->v = p;
71798
- u.cd.pFrame->nChildMem = u.cd.nMem;
71799
- u.cd.pFrame->nChildCsr = u.cd.pProgram->nCsr;
71800
- u.cd.pFrame->pc = pc;
71801
- u.cd.pFrame->aMem = p->aMem;
71802
- u.cd.pFrame->nMem = p->nMem;
71803
- u.cd.pFrame->apCsr = p->apCsr;
71804
- u.cd.pFrame->nCursor = p->nCursor;
71805
- u.cd.pFrame->aOp = p->aOp;
71806
- u.cd.pFrame->nOp = p->nOp;
71807
- u.cd.pFrame->token = u.cd.pProgram->token;
71808
- u.cd.pFrame->aOnceFlag = p->aOnceFlag;
71809
- u.cd.pFrame->nOnceFlag = p->nOnceFlag;
71810
-
71811
- u.cd.pEnd = &VdbeFrameMem(u.cd.pFrame)[u.cd.pFrame->nChildMem];
71812
- for(u.cd.pMem=VdbeFrameMem(u.cd.pFrame); u.cd.pMem!=u.cd.pEnd; u.cd.pMem++){
71813
- u.cd.pMem->flags = MEM_Invalid;
71814
- u.cd.pMem->db = db;
71332
+ sqlite3VdbeMemRelease(pRt);
71333
+ pRt->flags = MEM_Frame;
71334
+ pRt->u.pFrame = pFrame;
71335
+
71336
+ pFrame->v = p;
71337
+ pFrame->nChildMem = nMem;
71338
+ pFrame->nChildCsr = pProgram->nCsr;
71339
+ pFrame->pc = pc;
71340
+ pFrame->aMem = p->aMem;
71341
+ pFrame->nMem = p->nMem;
71342
+ pFrame->apCsr = p->apCsr;
71343
+ pFrame->nCursor = p->nCursor;
71344
+ pFrame->aOp = p->aOp;
71345
+ pFrame->nOp = p->nOp;
71346
+ pFrame->token = pProgram->token;
71347
+ pFrame->aOnceFlag = p->aOnceFlag;
71348
+ pFrame->nOnceFlag = p->nOnceFlag;
71349
+
71350
+ pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71351
+ for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71352
+ pMem->flags = MEM_Invalid;
71353
+ pMem->db = db;
7181571354
}
7181671355
}else{
71817
- u.cd.pFrame = u.cd.pRt->u.pFrame;
71818
- assert( u.cd.pProgram->nMem+u.cd.pProgram->nCsr==u.cd.pFrame->nChildMem );
71819
- assert( u.cd.pProgram->nCsr==u.cd.pFrame->nChildCsr );
71820
- assert( pc==u.cd.pFrame->pc );
71356
+ pFrame = pRt->u.pFrame;
71357
+ assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
71358
+ assert( pProgram->nCsr==pFrame->nChildCsr );
71359
+ assert( pc==pFrame->pc );
7182171360
}
7182271361
7182371362
p->nFrame++;
71824
- u.cd.pFrame->pParent = p->pFrame;
71825
- u.cd.pFrame->lastRowid = lastRowid;
71826
- u.cd.pFrame->nChange = p->nChange;
71363
+ pFrame->pParent = p->pFrame;
71364
+ pFrame->lastRowid = lastRowid;
71365
+ pFrame->nChange = p->nChange;
7182771366
p->nChange = 0;
71828
- p->pFrame = u.cd.pFrame;
71829
- p->aMem = aMem = &VdbeFrameMem(u.cd.pFrame)[-1];
71830
- p->nMem = u.cd.pFrame->nChildMem;
71831
- p->nCursor = (u16)u.cd.pFrame->nChildCsr;
71367
+ p->pFrame = pFrame;
71368
+ p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
71369
+ p->nMem = pFrame->nChildMem;
71370
+ p->nCursor = (u16)pFrame->nChildCsr;
7183271371
p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71833
- p->aOp = aOp = u.cd.pProgram->aOp;
71834
- p->nOp = u.cd.pProgram->nOp;
71372
+ p->aOp = aOp = pProgram->aOp;
71373
+ p->nOp = pProgram->nOp;
7183571374
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71836
- p->nOnceFlag = u.cd.pProgram->nOnce;
71375
+ p->nOnceFlag = pProgram->nOnce;
7183771376
pc = -1;
7183871377
memset(p->aOnceFlag, 0, p->nOnceFlag);
7183971378
7184071379
break;
7184171380
}
@@ -71851,17 +71390,15 @@
7185171390
** The address of the cell in the parent frame is determined by adding
7185271391
** the value of the P1 argument to the value of the P1 argument to the
7185371392
** calling OP_Program instruction.
7185471393
*/
7185571394
case OP_Param: { /* out2-prerelease */
71856
-#if 0 /* local variables moved into u.ce */
7185771395
VdbeFrame *pFrame;
7185871396
Mem *pIn;
71859
-#endif /* local variables moved into u.ce */
71860
- u.ce.pFrame = p->pFrame;
71861
- u.ce.pIn = &u.ce.pFrame->aMem[pOp->p1 + u.ce.pFrame->aOp[u.ce.pFrame->pc].p1];
71862
- sqlite3VdbeMemShallowCopy(pOut, u.ce.pIn, MEM_Ephem);
71397
+ pFrame = p->pFrame;
71398
+ pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
71399
+ sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
7186371400
break;
7186471401
}
7186571402
7186671403
#endif /* #ifndef SQLITE_OMIT_TRIGGER */
7186771404
@@ -71918,26 +71455,23 @@
7191871455
**
7191971456
** This instruction throws an error if the memory cell is not initially
7192071457
** an integer.
7192171458
*/
7192271459
case OP_MemMax: { /* in2 */
71923
-#if 0 /* local variables moved into u.cf */
71924
- Mem *pIn1;
7192571460
VdbeFrame *pFrame;
71926
-#endif /* local variables moved into u.cf */
7192771461
if( p->pFrame ){
71928
- for(u.cf.pFrame=p->pFrame; u.cf.pFrame->pParent; u.cf.pFrame=u.cf.pFrame->pParent);
71929
- u.cf.pIn1 = &u.cf.pFrame->aMem[pOp->p1];
71462
+ for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
71463
+ pIn1 = &pFrame->aMem[pOp->p1];
7193071464
}else{
71931
- u.cf.pIn1 = &aMem[pOp->p1];
71465
+ pIn1 = &aMem[pOp->p1];
7193271466
}
71933
- assert( memIsValid(u.cf.pIn1) );
71934
- sqlite3VdbeMemIntegerify(u.cf.pIn1);
71467
+ assert( memIsValid(pIn1) );
71468
+ sqlite3VdbeMemIntegerify(pIn1);
7193571469
pIn2 = &aMem[pOp->p2];
7193671470
sqlite3VdbeMemIntegerify(pIn2);
71937
- if( u.cf.pIn1->u.i<pIn2->u.i){
71938
- u.cf.pIn1->u.i = pIn2->u.i;
71471
+ if( pIn1->u.i<pIn2->u.i){
71472
+ pIn1->u.i = pIn2->u.i;
7193971473
}
7194071474
break;
7194171475
}
7194271476
#endif /* SQLITE_OMIT_AUTOINCREMENT */
7194371477
@@ -72004,60 +71538,58 @@
7200471538
**
7200571539
** The P5 arguments are taken from register P2 and its
7200671540
** successors.
7200771541
*/
7200871542
case OP_AggStep: {
72009
-#if 0 /* local variables moved into u.cg */
7201071543
int n;
7201171544
int i;
7201271545
Mem *pMem;
7201371546
Mem *pRec;
7201471547
sqlite3_context ctx;
7201571548
sqlite3_value **apVal;
72016
-#endif /* local variables moved into u.cg */
72017
-
72018
- u.cg.n = pOp->p5;
72019
- assert( u.cg.n>=0 );
72020
- u.cg.pRec = &aMem[pOp->p2];
72021
- u.cg.apVal = p->apArg;
72022
- assert( u.cg.apVal || u.cg.n==0 );
72023
- for(u.cg.i=0; u.cg.i<u.cg.n; u.cg.i++, u.cg.pRec++){
72024
- assert( memIsValid(u.cg.pRec) );
72025
- u.cg.apVal[u.cg.i] = u.cg.pRec;
72026
- memAboutToChange(p, u.cg.pRec);
72027
- sqlite3VdbeMemStoreType(u.cg.pRec);
72028
- }
72029
- u.cg.ctx.pFunc = pOp->p4.pFunc;
71549
+
71550
+ n = pOp->p5;
71551
+ assert( n>=0 );
71552
+ pRec = &aMem[pOp->p2];
71553
+ apVal = p->apArg;
71554
+ assert( apVal || n==0 );
71555
+ for(i=0; i<n; i++, pRec++){
71556
+ assert( memIsValid(pRec) );
71557
+ apVal[i] = pRec;
71558
+ memAboutToChange(p, pRec);
71559
+ sqlite3VdbeMemStoreType(pRec);
71560
+ }
71561
+ ctx.pFunc = pOp->p4.pFunc;
7203071562
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72031
- u.cg.ctx.pMem = u.cg.pMem = &aMem[pOp->p3];
72032
- u.cg.pMem->n++;
72033
- u.cg.ctx.s.flags = MEM_Null;
72034
- u.cg.ctx.s.z = 0;
72035
- u.cg.ctx.s.zMalloc = 0;
72036
- u.cg.ctx.s.xDel = 0;
72037
- u.cg.ctx.s.db = db;
72038
- u.cg.ctx.isError = 0;
72039
- u.cg.ctx.pColl = 0;
72040
- u.cg.ctx.skipFlag = 0;
72041
- if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
71563
+ ctx.pMem = pMem = &aMem[pOp->p3];
71564
+ pMem->n++;
71565
+ ctx.s.flags = MEM_Null;
71566
+ ctx.s.z = 0;
71567
+ ctx.s.zMalloc = 0;
71568
+ ctx.s.xDel = 0;
71569
+ ctx.s.db = db;
71570
+ ctx.isError = 0;
71571
+ ctx.pColl = 0;
71572
+ ctx.skipFlag = 0;
71573
+ if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
7204271574
assert( pOp>p->aOp );
7204371575
assert( pOp[-1].p4type==P4_COLLSEQ );
7204471576
assert( pOp[-1].opcode==OP_CollSeq );
72045
- u.cg.ctx.pColl = pOp[-1].p4.pColl;
72046
- }
72047
- (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */
72048
- if( u.cg.ctx.isError ){
72049
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cg.ctx.s));
72050
- rc = u.cg.ctx.isError;
72051
- }
72052
- if( u.cg.ctx.skipFlag ){
71577
+ ctx.pColl = pOp[-1].p4.pColl;
71578
+ }
71579
+ (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
71580
+ if( ctx.isError ){
71581
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
71582
+ rc = ctx.isError;
71583
+ }
71584
+ if( ctx.skipFlag ){
7205371585
assert( pOp[-1].opcode==OP_CollSeq );
72054
- u.cg.i = pOp[-1].p1;
72055
- if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1);
71586
+ i = pOp[-1].p1;
71587
+ if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1);
7205671588
}
7205771589
72058
- sqlite3VdbeMemRelease(&u.cg.ctx.s);
71590
+ sqlite3VdbeMemRelease(&ctx.s);
7205971591
7206071592
break;
7206171593
}
7206271594
7206371595
/* Opcode: AggFinal P1 P2 * P4 *
@@ -72072,23 +71604,21 @@
7207271604
** functions that can take varying numbers of arguments. The
7207371605
** P4 argument is only needed for the degenerate case where
7207471606
** the step function was not previously called.
7207571607
*/
7207671608
case OP_AggFinal: {
72077
-#if 0 /* local variables moved into u.ch */
7207871609
Mem *pMem;
72079
-#endif /* local variables moved into u.ch */
7208071610
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
72081
- u.ch.pMem = &aMem[pOp->p1];
72082
- assert( (u.ch.pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
72083
- rc = sqlite3VdbeMemFinalize(u.ch.pMem, pOp->p4.pFunc);
71611
+ pMem = &aMem[pOp->p1];
71612
+ assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
71613
+ rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
7208471614
if( rc ){
72085
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem));
71615
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
7208671616
}
72087
- sqlite3VdbeChangeEncoding(u.ch.pMem, encoding);
72088
- UPDATE_MAX_BLOBSIZE(u.ch.pMem);
72089
- if( sqlite3VdbeMemTooBig(u.ch.pMem) ){
71617
+ sqlite3VdbeChangeEncoding(pMem, encoding);
71618
+ UPDATE_MAX_BLOBSIZE(pMem);
71619
+ if( sqlite3VdbeMemTooBig(pMem) ){
7209071620
goto too_big;
7209171621
}
7209271622
break;
7209371623
}
7209471624
@@ -72103,31 +71633,29 @@
7210371633
** in the WAL that have been checkpointed after the checkpoint
7210471634
** completes into mem[P3+2]. However on an error, mem[P3+1] and
7210571635
** mem[P3+2] are initialized to -1.
7210671636
*/
7210771637
case OP_Checkpoint: {
72108
-#if 0 /* local variables moved into u.ci */
7210971638
int i; /* Loop counter */
7211071639
int aRes[3]; /* Results */
7211171640
Mem *pMem; /* Write results here */
72112
-#endif /* local variables moved into u.ci */
7211371641
7211471642
assert( p->readOnly==0 );
72115
- u.ci.aRes[0] = 0;
72116
- u.ci.aRes[1] = u.ci.aRes[2] = -1;
71643
+ aRes[0] = 0;
71644
+ aRes[1] = aRes[2] = -1;
7211771645
assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
7211871646
|| pOp->p2==SQLITE_CHECKPOINT_FULL
7211971647
|| pOp->p2==SQLITE_CHECKPOINT_RESTART
7212071648
);
72121
- rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]);
71649
+ rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
7212271650
if( rc==SQLITE_BUSY ){
7212371651
rc = SQLITE_OK;
72124
- u.ci.aRes[0] = 1;
71652
+ aRes[0] = 1;
7212571653
}
72126
- for(u.ci.i=0, u.ci.pMem = &aMem[pOp->p3]; u.ci.i<3; u.ci.i++, u.ci.pMem++){
72127
- sqlite3VdbeMemSetInt64(u.ci.pMem, (i64)u.ci.aRes[u.ci.i]);
72128
- }
71654
+ for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
71655
+ sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]);
71656
+ }
7212971657
break;
7213071658
};
7213171659
#endif
7213271660
7213371661
#ifndef SQLITE_OMIT_PRAGMA
@@ -72141,98 +71669,96 @@
7214171669
** If changing into or out of WAL mode the procedure is more complicated.
7214271670
**
7214371671
** Write a string containing the final journal-mode to register P2.
7214471672
*/
7214571673
case OP_JournalMode: { /* out2-prerelease */
72146
-#if 0 /* local variables moved into u.cj */
7214771674
Btree *pBt; /* Btree to change journal mode of */
7214871675
Pager *pPager; /* Pager associated with pBt */
7214971676
int eNew; /* New journal mode */
7215071677
int eOld; /* The old journal mode */
7215171678
#ifndef SQLITE_OMIT_WAL
7215271679
const char *zFilename; /* Name of database file for pPager */
7215371680
#endif
72154
-#endif /* local variables moved into u.cj */
72155
-
72156
- u.cj.eNew = pOp->p3;
72157
- assert( u.cj.eNew==PAGER_JOURNALMODE_DELETE
72158
- || u.cj.eNew==PAGER_JOURNALMODE_TRUNCATE
72159
- || u.cj.eNew==PAGER_JOURNALMODE_PERSIST
72160
- || u.cj.eNew==PAGER_JOURNALMODE_OFF
72161
- || u.cj.eNew==PAGER_JOURNALMODE_MEMORY
72162
- || u.cj.eNew==PAGER_JOURNALMODE_WAL
72163
- || u.cj.eNew==PAGER_JOURNALMODE_QUERY
71681
+
71682
+ eNew = pOp->p3;
71683
+ assert( eNew==PAGER_JOURNALMODE_DELETE
71684
+ || eNew==PAGER_JOURNALMODE_TRUNCATE
71685
+ || eNew==PAGER_JOURNALMODE_PERSIST
71686
+ || eNew==PAGER_JOURNALMODE_OFF
71687
+ || eNew==PAGER_JOURNALMODE_MEMORY
71688
+ || eNew==PAGER_JOURNALMODE_WAL
71689
+ || eNew==PAGER_JOURNALMODE_QUERY
7216471690
);
7216571691
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7216671692
assert( p->readOnly==0 );
7216771693
72168
- u.cj.pBt = db->aDb[pOp->p1].pBt;
72169
- u.cj.pPager = sqlite3BtreePager(u.cj.pBt);
72170
- u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager);
72171
- if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld;
72172
- if( !sqlite3PagerOkToChangeJournalMode(u.cj.pPager) ) u.cj.eNew = u.cj.eOld;
71694
+ pBt = db->aDb[pOp->p1].pBt;
71695
+ pPager = sqlite3BtreePager(pBt);
71696
+ eOld = sqlite3PagerGetJournalMode(pPager);
71697
+ if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld;
71698
+ if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld;
7217371699
7217471700
#ifndef SQLITE_OMIT_WAL
72175
- u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1);
71701
+ zFilename = sqlite3PagerFilename(pPager, 1);
7217671702
7217771703
/* Do not allow a transition to journal_mode=WAL for a database
72178
- ** in temporary storage or if the VFS does not support shared memory
71704
+ ** in temporary storage or if the VFS does not support shared memory
7217971705
*/
72180
- if( u.cj.eNew==PAGER_JOURNALMODE_WAL
72181
- && (sqlite3Strlen30(u.cj.zFilename)==0 /* Temp file */
72182
- || !sqlite3PagerWalSupported(u.cj.pPager)) /* No shared-memory support */
71706
+ if( eNew==PAGER_JOURNALMODE_WAL
71707
+ && (sqlite3Strlen30(zFilename)==0 /* Temp file */
71708
+ || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */
7218371709
){
72184
- u.cj.eNew = u.cj.eOld;
71710
+ eNew = eOld;
7218571711
}
7218671712
72187
- if( (u.cj.eNew!=u.cj.eOld)
72188
- && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
71713
+ if( (eNew!=eOld)
71714
+ && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL)
7218971715
){
7219071716
if( !db->autoCommit || db->nVdbeRead>1 ){
7219171717
rc = SQLITE_ERROR;
72192
- sqlite3SetString(&p->zErrMsg, db,
71718
+ sqlite3SetString(&p->zErrMsg, db,
7219371719
"cannot change %s wal mode from within a transaction",
72194
- (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
71720
+ (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
7219571721
);
7219671722
break;
7219771723
}else{
72198
-
72199
- if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){
71724
+
71725
+ if( eOld==PAGER_JOURNALMODE_WAL ){
7220071726
/* If leaving WAL mode, close the log file. If successful, the call
72201
- ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
72202
- ** file. An EXCLUSIVE lock may still be held on the database file
72203
- ** after a successful return.
71727
+ ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
71728
+ ** file. An EXCLUSIVE lock may still be held on the database file
71729
+ ** after a successful return.
7220471730
*/
72205
- rc = sqlite3PagerCloseWal(u.cj.pPager);
71731
+ rc = sqlite3PagerCloseWal(pPager);
7220671732
if( rc==SQLITE_OK ){
72207
- sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
71733
+ sqlite3PagerSetJournalMode(pPager, eNew);
7220871734
}
72209
- }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){
71735
+ }else if( eOld==PAGER_JOURNALMODE_MEMORY ){
7221071736
/* Cannot transition directly from MEMORY to WAL. Use mode OFF
7221171737
** as an intermediate */
72212
- sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF);
71738
+ sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF);
7221371739
}
72214
-
71740
+
7221571741
/* Open a transaction on the database file. Regardless of the journal
7221671742
** mode, this transaction always uses a rollback journal.
7221771743
*/
72218
- assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 );
71744
+ assert( sqlite3BtreeIsInTrans(pBt)==0 );
7221971745
if( rc==SQLITE_OK ){
72220
- rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
71746
+ rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
7222171747
}
7222271748
}
7222371749
}
7222471750
#endif /* ifndef SQLITE_OMIT_WAL */
7222571751
7222671752
if( rc ){
72227
- u.cj.eNew = u.cj.eOld;
71753
+ eNew = eOld;
7222871754
}
72229
- u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
71755
+ eNew = sqlite3PagerSetJournalMode(pPager, eNew);
7223071756
7223171757
pOut = &aMem[pOp->p2];
7223271758
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
72233
- pOut->z = (char *)sqlite3JournalModename(u.cj.eNew);
71759
+ pOut->z = (char *)sqlite3JournalModename(eNew);
7223471760
pOut->n = sqlite3Strlen30(pOut->z);
7223571761
pOut->enc = SQLITE_UTF8;
7223671762
sqlite3VdbeChangeEncoding(pOut, encoding);
7223771763
break;
7223871764
};
@@ -72258,19 +71784,17 @@
7225871784
** Perform a single step of the incremental vacuum procedure on
7225971785
** the P1 database. If the vacuum has finished, jump to instruction
7226071786
** P2. Otherwise, fall through to the next instruction.
7226171787
*/
7226271788
case OP_IncrVacuum: { /* jump */
72263
-#if 0 /* local variables moved into u.ck */
7226471789
Btree *pBt;
72265
-#endif /* local variables moved into u.ck */
7226671790
7226771791
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7226871792
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7226971793
assert( p->readOnly==0 );
72270
- u.ck.pBt = db->aDb[pOp->p1].pBt;
72271
- rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
71794
+ pBt = db->aDb[pOp->p1].pBt;
71795
+ rc = sqlite3BtreeIncrVacuum(pBt);
7227271796
if( rc==SQLITE_DONE ){
7227371797
pc = pOp->p2 - 1;
7227471798
rc = SQLITE_OK;
7227571799
}
7227671800
break;
@@ -72337,16 +71861,14 @@
7233771861
** Also, whether or not P4 is set, check that this is not being called from
7233871862
** within a callback to a virtual table xSync() method. If it is, the error
7233971863
** code will be set to SQLITE_LOCKED.
7234071864
*/
7234171865
case OP_VBegin: {
72342
-#if 0 /* local variables moved into u.cl */
7234371866
VTable *pVTab;
72344
-#endif /* local variables moved into u.cl */
72345
- u.cl.pVTab = pOp->p4.pVtab;
72346
- rc = sqlite3VtabBegin(db, u.cl.pVTab);
72347
- if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab);
71867
+ pVTab = pOp->p4.pVtab;
71868
+ rc = sqlite3VtabBegin(db, pVTab);
71869
+ if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab);
7234871870
break;
7234971871
}
7235071872
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7235171873
7235271874
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72381,37 +71903,34 @@
7238171903
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7238271904
** P1 is a cursor number. This opcode opens a cursor to the virtual
7238371905
** table and stores that cursor in P1.
7238471906
*/
7238571907
case OP_VOpen: {
72386
-#if 0 /* local variables moved into u.cm */
7238771908
VdbeCursor *pCur;
7238871909
sqlite3_vtab_cursor *pVtabCursor;
7238971910
sqlite3_vtab *pVtab;
7239071911
sqlite3_module *pModule;
72391
-#endif /* local variables moved into u.cm */
7239271912
7239371913
assert( p->bIsReader );
72394
- u.cm.pCur = 0;
72395
- u.cm.pVtabCursor = 0;
72396
- u.cm.pVtab = pOp->p4.pVtab->pVtab;
72397
- u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
72398
- assert(u.cm.pVtab && u.cm.pModule);
72399
- rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor);
72400
- sqlite3VtabImportErrmsg(p, u.cm.pVtab);
71914
+ pCur = 0;
71915
+ pVtabCursor = 0;
71916
+ pVtab = pOp->p4.pVtab->pVtab;
71917
+ pModule = (sqlite3_module *)pVtab->pModule;
71918
+ assert(pVtab && pModule);
71919
+ rc = pModule->xOpen(pVtab, &pVtabCursor);
71920
+ sqlite3VtabImportErrmsg(p, pVtab);
7240171921
if( SQLITE_OK==rc ){
7240271922
/* Initialize sqlite3_vtab_cursor base class */
72403
- u.cm.pVtabCursor->pVtab = u.cm.pVtab;
71923
+ pVtabCursor->pVtab = pVtab;
7240471924
7240571925
/* Initialize vdbe cursor object */
72406
- u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72407
- if( u.cm.pCur ){
72408
- u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
72409
- u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
71926
+ pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
71927
+ if( pCur ){
71928
+ pCur->pVtabCursor = pVtabCursor;
7241071929
}else{
7241171930
db->mallocFailed = 1;
72412
- u.cm.pModule->xClose(u.cm.pVtabCursor);
71931
+ pModule->xClose(pVtabCursor);
7241371932
}
7241471933
}
7241571934
break;
7241671935
}
7241771936
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72435,11 +71954,10 @@
7243571954
** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
7243671955
**
7243771956
** A jump is made to P2 if the result set after filtering would be empty.
7243871957
*/
7243971958
case OP_VFilter: { /* jump */
72440
-#if 0 /* local variables moved into u.cn */
7244171959
int nArg;
7244271960
int iQuery;
7244371961
const sqlite3_module *pModule;
7244471962
Mem *pQuery;
7244571963
Mem *pArgc;
@@ -72447,49 +71965,48 @@
7244771965
sqlite3_vtab *pVtab;
7244871966
VdbeCursor *pCur;
7244971967
int res;
7245071968
int i;
7245171969
Mem **apArg;
72452
-#endif /* local variables moved into u.cn */
72453
-
72454
- u.cn.pQuery = &aMem[pOp->p3];
72455
- u.cn.pArgc = &u.cn.pQuery[1];
72456
- u.cn.pCur = p->apCsr[pOp->p1];
72457
- assert( memIsValid(u.cn.pQuery) );
72458
- REGISTER_TRACE(pOp->p3, u.cn.pQuery);
72459
- assert( u.cn.pCur->pVtabCursor );
72460
- u.cn.pVtabCursor = u.cn.pCur->pVtabCursor;
72461
- u.cn.pVtab = u.cn.pVtabCursor->pVtab;
72462
- u.cn.pModule = u.cn.pVtab->pModule;
71970
+
71971
+ pQuery = &aMem[pOp->p3];
71972
+ pArgc = &pQuery[1];
71973
+ pCur = p->apCsr[pOp->p1];
71974
+ assert( memIsValid(pQuery) );
71975
+ REGISTER_TRACE(pOp->p3, pQuery);
71976
+ assert( pCur->pVtabCursor );
71977
+ pVtabCursor = pCur->pVtabCursor;
71978
+ pVtab = pVtabCursor->pVtab;
71979
+ pModule = pVtab->pModule;
7246371980
7246471981
/* Grab the index number and argc parameters */
72465
- assert( (u.cn.pQuery->flags&MEM_Int)!=0 && u.cn.pArgc->flags==MEM_Int );
72466
- u.cn.nArg = (int)u.cn.pArgc->u.i;
72467
- u.cn.iQuery = (int)u.cn.pQuery->u.i;
71982
+ assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
71983
+ nArg = (int)pArgc->u.i;
71984
+ iQuery = (int)pQuery->u.i;
7246871985
7246971986
/* Invoke the xFilter method */
7247071987
{
72471
- u.cn.res = 0;
72472
- u.cn.apArg = p->apArg;
72473
- for(u.cn.i = 0; u.cn.i<u.cn.nArg; u.cn.i++){
72474
- u.cn.apArg[u.cn.i] = &u.cn.pArgc[u.cn.i+1];
72475
- sqlite3VdbeMemStoreType(u.cn.apArg[u.cn.i]);
71988
+ res = 0;
71989
+ apArg = p->apArg;
71990
+ for(i = 0; i<nArg; i++){
71991
+ apArg[i] = &pArgc[i+1];
71992
+ sqlite3VdbeMemStoreType(apArg[i]);
7247671993
}
7247771994
7247871995
p->inVtabMethod = 1;
72479
- rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
71996
+ rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
7248071997
p->inVtabMethod = 0;
72481
- sqlite3VtabImportErrmsg(p, u.cn.pVtab);
71998
+ sqlite3VtabImportErrmsg(p, pVtab);
7248271999
if( rc==SQLITE_OK ){
72483
- u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
72000
+ res = pModule->xEof(pVtabCursor);
7248472001
}
7248572002
72486
- if( u.cn.res ){
72003
+ if( res ){
7248772004
pc = pOp->p2 - 1;
7248872005
}
7248972006
}
72490
- u.cn.pCur->nullRow = 0;
72007
+ pCur->nullRow = 0;
7249172008
7249272009
break;
7249372010
}
7249472011
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7249572012
@@ -72500,55 +72017,53 @@
7250072017
** Store the value of the P2-th column of
7250172018
** the row of the virtual-table that the
7250272019
** P1 cursor is pointing to into register P3.
7250372020
*/
7250472021
case OP_VColumn: {
72505
-#if 0 /* local variables moved into u.co */
7250672022
sqlite3_vtab *pVtab;
7250772023
const sqlite3_module *pModule;
7250872024
Mem *pDest;
7250972025
sqlite3_context sContext;
72510
-#endif /* local variables moved into u.co */
7251172026
7251272027
VdbeCursor *pCur = p->apCsr[pOp->p1];
7251372028
assert( pCur->pVtabCursor );
7251472029
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72515
- u.co.pDest = &aMem[pOp->p3];
72516
- memAboutToChange(p, u.co.pDest);
72030
+ pDest = &aMem[pOp->p3];
72031
+ memAboutToChange(p, pDest);
7251772032
if( pCur->nullRow ){
72518
- sqlite3VdbeMemSetNull(u.co.pDest);
72033
+ sqlite3VdbeMemSetNull(pDest);
7251972034
break;
7252072035
}
72521
- u.co.pVtab = pCur->pVtabCursor->pVtab;
72522
- u.co.pModule = u.co.pVtab->pModule;
72523
- assert( u.co.pModule->xColumn );
72524
- memset(&u.co.sContext, 0, sizeof(u.co.sContext));
72036
+ pVtab = pCur->pVtabCursor->pVtab;
72037
+ pModule = pVtab->pModule;
72038
+ assert( pModule->xColumn );
72039
+ memset(&sContext, 0, sizeof(sContext));
7252572040
7252672041
/* The output cell may already have a buffer allocated. Move
72527
- ** the current contents to u.co.sContext.s so in case the user-function
72528
- ** can use the already allocated buffer instead of allocating a
72042
+ ** the current contents to sContext.s so in case the user-function
72043
+ ** can use the already allocated buffer instead of allocating a
7252972044
** new one.
7253072045
*/
72531
- sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
72532
- MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
72046
+ sqlite3VdbeMemMove(&sContext.s, pDest);
72047
+ MemSetTypeFlag(&sContext.s, MEM_Null);
7253372048
72534
- rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2);
72535
- sqlite3VtabImportErrmsg(p, u.co.pVtab);
72536
- if( u.co.sContext.isError ){
72537
- rc = u.co.sContext.isError;
72049
+ rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
72050
+ sqlite3VtabImportErrmsg(p, pVtab);
72051
+ if( sContext.isError ){
72052
+ rc = sContext.isError;
7253872053
}
7253972054
7254072055
/* Copy the result of the function to the P3 register. We
7254172056
** do this regardless of whether or not an error occurred to ensure any
72542
- ** dynamic allocation in u.co.sContext.s (a Mem struct) is released.
72057
+ ** dynamic allocation in sContext.s (a Mem struct) is released.
7254372058
*/
72544
- sqlite3VdbeChangeEncoding(&u.co.sContext.s, encoding);
72545
- sqlite3VdbeMemMove(u.co.pDest, &u.co.sContext.s);
72546
- REGISTER_TRACE(pOp->p3, u.co.pDest);
72547
- UPDATE_MAX_BLOBSIZE(u.co.pDest);
72059
+ sqlite3VdbeChangeEncoding(&sContext.s, encoding);
72060
+ sqlite3VdbeMemMove(pDest, &sContext.s);
72061
+ REGISTER_TRACE(pOp->p3, pDest);
72062
+ UPDATE_MAX_BLOBSIZE(pDest);
7254872063
72549
- if( sqlite3VdbeMemTooBig(u.co.pDest) ){
72064
+ if( sqlite3VdbeMemTooBig(pDest) ){
7255072065
goto too_big;
7255172066
}
7255272067
break;
7255372068
}
7255472069
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72559,42 +72074,40 @@
7255972074
** Advance virtual table P1 to the next row in its result set and
7256072075
** jump to instruction P2. Or, if the virtual table has reached
7256172076
** the end of its result set, then fall through to the next instruction.
7256272077
*/
7256372078
case OP_VNext: { /* jump */
72564
-#if 0 /* local variables moved into u.cp */
7256572079
sqlite3_vtab *pVtab;
7256672080
const sqlite3_module *pModule;
7256772081
int res;
7256872082
VdbeCursor *pCur;
72569
-#endif /* local variables moved into u.cp */
7257072083
72571
- u.cp.res = 0;
72572
- u.cp.pCur = p->apCsr[pOp->p1];
72573
- assert( u.cp.pCur->pVtabCursor );
72574
- if( u.cp.pCur->nullRow ){
72084
+ res = 0;
72085
+ pCur = p->apCsr[pOp->p1];
72086
+ assert( pCur->pVtabCursor );
72087
+ if( pCur->nullRow ){
7257572088
break;
7257672089
}
72577
- u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab;
72578
- u.cp.pModule = u.cp.pVtab->pModule;
72579
- assert( u.cp.pModule->xNext );
72090
+ pVtab = pCur->pVtabCursor->pVtab;
72091
+ pModule = pVtab->pModule;
72092
+ assert( pModule->xNext );
7258072093
7258172094
/* Invoke the xNext() method of the module. There is no way for the
7258272095
** underlying implementation to return an error if one occurs during
72583
- ** xNext(). Instead, if an error occurs, true is returned (indicating that
72096
+ ** xNext(). Instead, if an error occurs, true is returned (indicating that
7258472097
** data is available) and the error code returned when xColumn or
7258572098
** some other method is next invoked on the save virtual table cursor.
7258672099
*/
7258772100
p->inVtabMethod = 1;
72588
- rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
72101
+ rc = pModule->xNext(pCur->pVtabCursor);
7258972102
p->inVtabMethod = 0;
72590
- sqlite3VtabImportErrmsg(p, u.cp.pVtab);
72103
+ sqlite3VtabImportErrmsg(p, pVtab);
7259172104
if( rc==SQLITE_OK ){
72592
- u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
72105
+ res = pModule->xEof(pCur->pVtabCursor);
7259372106
}
7259472107
72595
- if( !u.cp.res ){
72108
+ if( !res ){
7259672109
/* If there is data, jump to P2 */
7259772110
pc = pOp->p2 - 1;
7259872111
}
7259972112
goto check_for_interrupt;
7260072113
}
@@ -72606,29 +72119,27 @@
7260672119
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7260772120
** This opcode invokes the corresponding xRename method. The value
7260872121
** in register P1 is passed as the zName argument to the xRename method.
7260972122
*/
7261072123
case OP_VRename: {
72611
-#if 0 /* local variables moved into u.cq */
7261272124
sqlite3_vtab *pVtab;
7261372125
Mem *pName;
72614
-#endif /* local variables moved into u.cq */
7261572126
72616
- u.cq.pVtab = pOp->p4.pVtab->pVtab;
72617
- u.cq.pName = &aMem[pOp->p1];
72618
- assert( u.cq.pVtab->pModule->xRename );
72619
- assert( memIsValid(u.cq.pName) );
72127
+ pVtab = pOp->p4.pVtab->pVtab;
72128
+ pName = &aMem[pOp->p1];
72129
+ assert( pVtab->pModule->xRename );
72130
+ assert( memIsValid(pName) );
7262072131
assert( p->readOnly==0 );
72621
- REGISTER_TRACE(pOp->p1, u.cq.pName);
72622
- assert( u.cq.pName->flags & MEM_Str );
72623
- testcase( u.cq.pName->enc==SQLITE_UTF8 );
72624
- testcase( u.cq.pName->enc==SQLITE_UTF16BE );
72625
- testcase( u.cq.pName->enc==SQLITE_UTF16LE );
72626
- rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8);
72132
+ REGISTER_TRACE(pOp->p1, pName);
72133
+ assert( pName->flags & MEM_Str );
72134
+ testcase( pName->enc==SQLITE_UTF8 );
72135
+ testcase( pName->enc==SQLITE_UTF16BE );
72136
+ testcase( pName->enc==SQLITE_UTF16LE );
72137
+ rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8);
7262772138
if( rc==SQLITE_OK ){
72628
- rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
72629
- sqlite3VtabImportErrmsg(p, u.cq.pVtab);
72139
+ rc = pVtab->pModule->xRename(pVtab, pName->z);
72140
+ sqlite3VtabImportErrmsg(p, pVtab);
7263072141
p->expired = 0;
7263172142
}
7263272143
break;
7263372144
}
7263472145
#endif
@@ -72657,46 +72168,44 @@
7265772168
** P1 is a boolean flag. If it is set to true and the xUpdate call
7265872169
** is successful, then the value returned by sqlite3_last_insert_rowid()
7265972170
** is set to the value of the rowid for the row just inserted.
7266072171
*/
7266172172
case OP_VUpdate: {
72662
-#if 0 /* local variables moved into u.cr */
7266372173
sqlite3_vtab *pVtab;
7266472174
sqlite3_module *pModule;
7266572175
int nArg;
7266672176
int i;
7266772177
sqlite_int64 rowid;
7266872178
Mem **apArg;
7266972179
Mem *pX;
72670
-#endif /* local variables moved into u.cr */
7267172180
72672
- assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72181
+ assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
7267372182
|| pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
7267472183
);
7267572184
assert( p->readOnly==0 );
72676
- u.cr.pVtab = pOp->p4.pVtab->pVtab;
72677
- u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule;
72678
- u.cr.nArg = pOp->p2;
72185
+ pVtab = pOp->p4.pVtab->pVtab;
72186
+ pModule = (sqlite3_module *)pVtab->pModule;
72187
+ nArg = pOp->p2;
7267972188
assert( pOp->p4type==P4_VTAB );
72680
- if( ALWAYS(u.cr.pModule->xUpdate) ){
72189
+ if( ALWAYS(pModule->xUpdate) ){
7268172190
u8 vtabOnConflict = db->vtabOnConflict;
72682
- u.cr.apArg = p->apArg;
72683
- u.cr.pX = &aMem[pOp->p3];
72684
- for(u.cr.i=0; u.cr.i<u.cr.nArg; u.cr.i++){
72685
- assert( memIsValid(u.cr.pX) );
72686
- memAboutToChange(p, u.cr.pX);
72687
- sqlite3VdbeMemStoreType(u.cr.pX);
72688
- u.cr.apArg[u.cr.i] = u.cr.pX;
72689
- u.cr.pX++;
72191
+ apArg = p->apArg;
72192
+ pX = &aMem[pOp->p3];
72193
+ for(i=0; i<nArg; i++){
72194
+ assert( memIsValid(pX) );
72195
+ memAboutToChange(p, pX);
72196
+ sqlite3VdbeMemStoreType(pX);
72197
+ apArg[i] = pX;
72198
+ pX++;
7269072199
}
7269172200
db->vtabOnConflict = pOp->p5;
72692
- rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
72201
+ rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
7269372202
db->vtabOnConflict = vtabOnConflict;
72694
- sqlite3VtabImportErrmsg(p, u.cr.pVtab);
72203
+ sqlite3VtabImportErrmsg(p, pVtab);
7269572204
if( rc==SQLITE_OK && pOp->p1 ){
72696
- assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) );
72697
- db->lastRowid = lastRowid = u.cr.rowid;
72205
+ assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
72206
+ db->lastRowid = lastRowid = rowid;
7269872207
}
7269972208
if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
7270072209
if( pOp->p5==OE_Ignore ){
7270172210
rc = SQLITE_OK;
7270272211
}else{
@@ -72752,38 +72261,36 @@
7275272261
**
7275372262
** If tracing is enabled (by the sqlite3_trace()) interface, then
7275472263
** the UTF-8 string contained in P4 is emitted on the trace callback.
7275572264
*/
7275672265
case OP_Trace: {
72757
-#if 0 /* local variables moved into u.cs */
7275872266
char *zTrace;
7275972267
char *z;
72760
-#endif /* local variables moved into u.cs */
7276172268
7276272269
if( db->xTrace
7276372270
&& !p->doingRerun
72764
- && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72271
+ && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7276572272
){
72766
- u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
72767
- db->xTrace(db->pTraceArg, u.cs.z);
72768
- sqlite3DbFree(db, u.cs.z);
72273
+ z = sqlite3VdbeExpandSql(p, zTrace);
72274
+ db->xTrace(db->pTraceArg, z);
72275
+ sqlite3DbFree(db, z);
7276972276
}
7277072277
#ifdef SQLITE_USE_FCNTL_TRACE
72771
- u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72772
- if( u.cs.zTrace ){
72278
+ zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72279
+ if( zTrace ){
7277372280
int i;
7277472281
for(i=0; i<db->nDb; i++){
7277572282
if( ((1<<i) & p->btreeMask)==0 ) continue;
72776
- sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace);
72283
+ sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
7277772284
}
7277872285
}
7277972286
#endif /* SQLITE_USE_FCNTL_TRACE */
7278072287
#ifdef SQLITE_DEBUG
7278172288
if( (db->flags & SQLITE_SqlTrace)!=0
72782
- && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72289
+ && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7278372290
){
72784
- sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
72291
+ sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
7278572292
}
7278672293
#endif /* SQLITE_DEBUG */
7278772294
break;
7278872295
}
7278972296
#endif
@@ -72832,17 +72339,17 @@
7283272339
*/
7283372340
#ifndef NDEBUG
7283472341
assert( pc>=-1 && pc<p->nOp );
7283572342
7283672343
#ifdef SQLITE_DEBUG
72837
- if( p->trace ){
72838
- if( rc!=0 ) fprintf(p->trace,"rc=%d\n",rc);
72344
+ if( db->flags & SQLITE_VdbeTrace ){
72345
+ if( rc!=0 ) printf("rc=%d\n",rc);
7283972346
if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
72840
- registerTrace(p->trace, pOp->p2, &aMem[pOp->p2]);
72347
+ registerTrace(pOp->p2, &aMem[pOp->p2]);
7284172348
}
7284272349
if( pOp->opflags & OPFLG_OUT3 ){
72843
- registerTrace(p->trace, pOp->p3, &aMem[pOp->p3]);
72350
+ registerTrace(pOp->p3, &aMem[pOp->p3]);
7284472351
}
7284572352
}
7284672353
#endif /* SQLITE_DEBUG */
7284772354
#endif /* NDEBUG */
7284872355
} /* The end of the for(;;) loop the loops through opcodes */
@@ -72908,10 +72415,11 @@
7290872415
rc = SQLITE_INTERRUPT;
7290972416
p->rc = rc;
7291072417
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
7291172418
goto vdbe_error_halt;
7291272419
}
72420
+
7291372421
7291472422
/************** End of vdbe.c ************************************************/
7291572423
/************** Begin file vdbeblob.c ****************************************/
7291672424
/*
7291772425
** 2007 May 1
@@ -72975,22 +72483,23 @@
7297572483
assert( v->aVar[0].flags&MEM_Int );
7297672484
v->aVar[0].u.i = iRow;
7297772485
7297872486
rc = sqlite3_step(p->pStmt);
7297972487
if( rc==SQLITE_ROW ){
72980
- u32 type = v->apCsr[0]->aType[p->iCol];
72488
+ VdbeCursor *pC = v->apCsr[0];
72489
+ u32 type = pC->aType[p->iCol];
7298172490
if( type<12 ){
7298272491
zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
7298372492
type==0?"null": type==7?"real": "integer"
7298472493
);
7298572494
rc = SQLITE_ERROR;
7298672495
sqlite3_finalize(p->pStmt);
7298772496
p->pStmt = 0;
7298872497
}else{
72989
- p->iOffset = v->apCsr[0]->aOffset[p->iCol];
72498
+ p->iOffset = pC->aType[p->iCol + pC->nField];
7299072499
p->nByte = sqlite3VdbeSerialTypeLen(type);
72991
- p->pCsr = v->apCsr[0]->pCursor;
72500
+ p->pCsr = pC->pCursor;
7299272501
sqlite3BtreeEnterCursor(p->pCsr);
7299372502
sqlite3BtreeCacheOverflow(p->pCsr);
7299472503
sqlite3BtreeLeaveCursor(p->pCsr);
7299572504
}
7299672505
}
@@ -73239,10 +72748,11 @@
7323972748
if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
7324072749
sqlite3DbFree(db, pBlob);
7324172750
}
7324272751
sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
7324372752
sqlite3DbFree(db, zErr);
72753
+ sqlite3ParserReset(pParse);
7324472754
sqlite3StackFree(db, pParse);
7324572755
rc = sqlite3ApiExit(db, rc);
7324672756
sqlite3_mutex_leave(db->mutex);
7324772757
return rc;
7324872758
}
@@ -75204,14 +74714,14 @@
7520474714
if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
7520574715
incrAggFunctionDepth(pDup, nSubquery);
7520674716
pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
7520774717
if( pDup==0 ) return;
7520874718
ExprSetProperty(pDup, EP_Skip);
75209
- if( pEList->a[iCol].iAlias==0 ){
75210
- pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
74719
+ if( pEList->a[iCol].u.x.iAlias==0 ){
74720
+ pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
7521174721
}
75212
- pDup->iTable = pEList->a[iCol].iAlias;
74722
+ pDup->iTable = pEList->a[iCol].u.x.iAlias;
7521374723
}
7521474724
if( pExpr->op==TK_COLLATE ){
7521574725
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
7521674726
}
7521774727
@@ -75448,11 +74958,13 @@
7544874958
}
7544974959
break;
7545074960
}
7545174961
}
7545274962
if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75453
- iCol = -1; /* IMP: R-44911-55124 */
74963
+ /* IMP: R-24309-18625 */
74964
+ /* IMP: R-44911-55124 */
74965
+ iCol = -1;
7545474966
}
7545574967
if( iCol<pTab->nCol ){
7545674968
cnt++;
7545774969
if( iCol<0 ){
7545874970
pExpr->affinity = SQLITE_AFF_INTEGER;
@@ -75763,11 +75275,10 @@
7576375275
return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
7576475276
}
7576575277
7576675278
/* Resolve function names
7576775279
*/
75768
- case TK_CONST_FUNC:
7576975280
case TK_FUNCTION: {
7577075281
ExprList *pList = pExpr->x.pList; /* The argument list */
7577175282
int n = pList ? pList->nExpr : 0; /* Number of arguments */
7577275283
int no_such_func = 0; /* True if no such function exists */
7577375284
int wrong_num_args = 0; /* True if wrong number of arguments */
@@ -75776,11 +75287,10 @@
7577675287
int nId; /* Number of characters in function name */
7577775288
const char *zId; /* The function name. */
7577875289
FuncDef *pDef; /* Information about the function */
7577975290
u8 enc = ENC(pParse->db); /* The database encoding */
7578075291
75781
- testcase( pExpr->op==TK_CONST_FUNC );
7578275292
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
7578375293
notValidPartIdxWhere(pParse, pNC, "functions");
7578475294
zId = pExpr->u.zToken;
7578575295
nId = sqlite3Strlen30(zId);
7578675296
pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
@@ -75821,10 +75331,11 @@
7582175331
pNC->nErr++;
7582275332
}
7582375333
pExpr->op = TK_NULL;
7582475334
return WRC_Prune;
7582575335
}
75336
+ if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
7582675337
}
7582775338
#endif
7582875339
if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
7582975340
sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
7583075341
pNC->nErr++;
@@ -76072,11 +75583,11 @@
7607275583
assert( pItem->pExpr->op==TK_COLLATE );
7607375584
assert( pItem->pExpr->pLeft==pE );
7607475585
pItem->pExpr->pLeft = pNew;
7607575586
}
7607675587
sqlite3ExprDelete(db, pE);
76077
- pItem->iOrderByCol = (u16)iCol;
75588
+ pItem->u.x.iOrderByCol = (u16)iCol;
7607875589
pItem->done = 1;
7607975590
}else{
7608075591
moreToDo = 1;
7608175592
}
7608275593
}
@@ -76093,12 +75604,12 @@
7609375604
}
7609475605
7609575606
/*
7609675607
** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
7609775608
** the SELECT statement pSelect. If any term is reference to a
76098
-** result set expression (as determined by the ExprList.a.iOrderByCol field)
76099
-** then convert that term into a copy of the corresponding result set
75609
+** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
75610
+** field) then convert that term into a copy of the corresponding result set
7610075611
** column.
7610175612
**
7610275613
** If any errors are detected, add an error message to pParse and
7610375614
** return non-zero. Return zero if no errors are seen.
7610475615
*/
@@ -76121,16 +75632,16 @@
7612175632
}
7612275633
#endif
7612375634
pEList = pSelect->pEList;
7612475635
assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
7612575636
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
76126
- if( pItem->iOrderByCol ){
76127
- if( pItem->iOrderByCol>pEList->nExpr ){
75637
+ if( pItem->u.x.iOrderByCol ){
75638
+ if( pItem->u.x.iOrderByCol>pEList->nExpr ){
7612875639
resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
7612975640
return 1;
7613075641
}
76131
- resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0);
75642
+ resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0);
7613275643
}
7613375644
}
7613475645
return 0;
7613575646
}
7613675647
@@ -76175,11 +75686,11 @@
7617575686
if( iCol>0 ){
7617675687
/* If an AS-name match is found, mark this ORDER BY column as being
7617775688
** a copy of the iCol-th result-set column. The subsequent call to
7617875689
** sqlite3ResolveOrderGroupBy() will convert the expression to a
7617975690
** copy of the iCol-th result-set expression. */
76180
- pItem->iOrderByCol = (u16)iCol;
75691
+ pItem->u.x.iOrderByCol = (u16)iCol;
7618175692
continue;
7618275693
}
7618375694
}
7618475695
if( sqlite3ExprIsInteger(pE2, &iCol) ){
7618575696
/* The ORDER BY term is an integer constant. Again, set the column
@@ -76187,22 +75698,22 @@
7618775698
** order-by term to a copy of the result-set expression */
7618875699
if( iCol<1 || iCol>0xffff ){
7618975700
resolveOutOfRangeError(pParse, zType, i+1, nResult);
7619075701
return 1;
7619175702
}
76192
- pItem->iOrderByCol = (u16)iCol;
75703
+ pItem->u.x.iOrderByCol = (u16)iCol;
7619375704
continue;
7619475705
}
7619575706
7619675707
/* Otherwise, treat the ORDER BY term as an ordinary expression */
76197
- pItem->iOrderByCol = 0;
75708
+ pItem->u.x.iOrderByCol = 0;
7619875709
if( sqlite3ResolveExprNames(pNC, pE) ){
7619975710
return 1;
7620075711
}
7620175712
for(j=0; j<pSelect->pEList->nExpr; j++){
7620275713
if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
76203
- pItem->iOrderByCol = j+1;
75714
+ pItem->u.x.iOrderByCol = j+1;
7620475715
}
7620575716
}
7620675717
}
7620775718
return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
7620875719
}
@@ -77477,12 +76988,11 @@
7747776988
pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
7747876989
pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
7747976990
pItem->sortOrder = pOldItem->sortOrder;
7748076991
pItem->done = 0;
7748176992
pItem->bSpanIsTab = pOldItem->bSpanIsTab;
77482
- pItem->iOrderByCol = pOldItem->iOrderByCol;
77483
- pItem->iAlias = pOldItem->iAlias;
76993
+ pItem->u = pOldItem->u;
7748476994
}
7748576995
return pNew;
7748676996
}
7748776997
7748876998
/*
@@ -77739,13 +77249,16 @@
7773977249
return WRC_Abort;
7774077250
}
7774177251
7774277252
switch( pExpr->op ){
7774377253
/* Consider functions to be constant if all their arguments are constant
77744
- ** and pWalker->u.i==2 */
77254
+ ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST
77255
+ ** flag. */
7774577256
case TK_FUNCTION:
77746
- if( pWalker->u.i==2 ) return 0;
77257
+ if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){
77258
+ return WRC_Continue;
77259
+ }
7774777260
/* Fall through */
7774877261
case TK_ID:
7774977262
case TK_COLUMN:
7775077263
case TK_AGG_FUNCTION:
7775177264
case TK_AGG_COLUMN:
@@ -78903,10 +78416,11 @@
7890378416
int inReg = target; /* Results stored in register inReg */
7890478417
int regFree1 = 0; /* If non-zero free this temporary register */
7890578418
int regFree2 = 0; /* If non-zero free this temporary register */
7890678419
int r1, r2, r3, r4; /* Various register numbers */
7890778420
sqlite3 *db = pParse->db; /* The database connection */
78421
+ Expr tempX; /* Temporary expression node */
7890878422
7890978423
assert( target>0 && target<=pParse->nMem );
7891078424
if( v==0 ){
7891178425
assert( pParse->db->mallocFailed );
7891278426
return 0;
@@ -79122,12 +78636,14 @@
7912278636
}else if( pLeft->op==TK_FLOAT ){
7912378637
assert( !ExprHasProperty(pExpr, EP_IntValue) );
7912478638
codeReal(v, pLeft->u.zToken, 1, target);
7912578639
#endif
7912678640
}else{
79127
- regFree1 = r1 = sqlite3GetTempReg(pParse);
79128
- sqlite3VdbeAddOp2(v, OP_Integer, 0, r1);
78641
+ tempX.op = TK_INTEGER;
78642
+ tempX.flags = EP_IntValue|EP_TokenOnly;
78643
+ tempX.u.iValue = 0;
78644
+ r1 = sqlite3ExprCodeTemp(pParse, &tempX, &regFree1);
7912978645
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree2);
7913078646
sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
7913178647
testcase( regFree2==0 );
7913278648
}
7913378649
inReg = target;
@@ -79168,11 +78684,10 @@
7916878684
}else{
7916978685
inReg = pInfo->aFunc[pExpr->iAgg].iMem;
7917078686
}
7917178687
break;
7917278688
}
79173
- case TK_CONST_FUNC:
7917478689
case TK_FUNCTION: {
7917578690
ExprList *pFarg; /* List of function arguments */
7917678691
int nFarg; /* Number of function arguments */
7917778692
FuncDef *pDef; /* The function definition object */
7917878693
int nId; /* Length of the function name in bytes */
@@ -79181,12 +78696,10 @@
7918178696
int i; /* Loop counter */
7918278697
u8 enc = ENC(db); /* The text encoding used by this database */
7918378698
CollSeq *pColl = 0; /* A collating sequence */
7918478699
7918578700
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79186
- testcase( op==TK_CONST_FUNC );
79187
- testcase( op==TK_FUNCTION );
7918878701
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
7918978702
pFarg = 0;
7919078703
}else{
7919178704
pFarg = pExpr->x.pList;
7919278705
}
@@ -79226,12 +78739,25 @@
7922678739
assert( nFarg>=1 );
7922778740
sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
7922878741
break;
7922978742
}
7923078743
78744
+ for(i=0; i<nFarg; i++){
78745
+ if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
78746
+ constMask |= (1<<i);
78747
+ }
78748
+ if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
78749
+ pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
78750
+ }
78751
+ }
7923178752
if( pFarg ){
79232
- r1 = sqlite3GetTempRange(pParse, nFarg);
78753
+ if( constMask ){
78754
+ r1 = pParse->nMem+1;
78755
+ pParse->nMem += nFarg;
78756
+ }else{
78757
+ r1 = sqlite3GetTempRange(pParse, nFarg);
78758
+ }
7923378759
7923478760
/* For length() and typeof() functions with a column argument,
7923578761
** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
7923678762
** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
7923778763
** loading.
@@ -79242,18 +78768,19 @@
7924278768
assert( pFarg->a[0].pExpr!=0 );
7924378769
exprOp = pFarg->a[0].pExpr->op;
7924478770
if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
7924578771
assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
7924678772
assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
79247
- testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK)
79248
- ==SQLITE_FUNC_LENGTH );
79249
- pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK;
78773
+ testcase( pDef->funcFlags & OPFLAG_LENGTHARG );
78774
+ pFarg->a[0].pExpr->op2 =
78775
+ pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
7925078776
}
7925178777
}
7925278778
7925378779
sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
79254
- sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
78780
+ sqlite3ExprCodeExprList(pParse, pFarg, r1,
78781
+ SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
7925578782
sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */
7925678783
}else{
7925778784
r1 = 0;
7925878785
}
7925978786
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -79273,26 +78800,18 @@
7927378800
pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
7927478801
}else if( nFarg>0 ){
7927578802
pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
7927678803
}
7927778804
#endif
79278
- for(i=0; i<nFarg; i++){
79279
- if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
79280
- constMask |= (1<<i);
79281
- }
79282
- if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
79283
- pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
79284
- }
79285
- }
7928678805
if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
7928778806
if( !pColl ) pColl = db->pDfltColl;
7928878807
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
7928978808
}
7929078809
sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
7929178810
(char*)pDef, P4_FUNCDEF);
7929278811
sqlite3VdbeChangeP5(v, (u8)nFarg);
79293
- if( nFarg ){
78812
+ if( nFarg && constMask==0 ){
7929478813
sqlite3ReleaseTempRange(pParse, r1, nFarg);
7929578814
}
7929678815
break;
7929778816
}
7929878817
#ifndef SQLITE_OMIT_SUBQUERY
@@ -79439,11 +78958,10 @@
7943978958
int nExpr; /* 2x number of WHEN terms */
7944078959
int i; /* Loop counter */
7944178960
ExprList *pEList; /* List of WHEN terms */
7944278961
struct ExprList_item *aListelem; /* Array of WHEN terms */
7944378962
Expr opCompare; /* The X==Ei expression */
79444
- Expr cacheX; /* Cached expression X */
7944578963
Expr *pX; /* The X expression */
7944678964
Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
7944778965
VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
7944878966
7944978967
assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
@@ -79451,17 +78969,16 @@
7945178969
pEList = pExpr->x.pList;
7945278970
aListelem = pEList->a;
7945378971
nExpr = pEList->nExpr;
7945478972
endLabel = sqlite3VdbeMakeLabel(v);
7945578973
if( (pX = pExpr->pLeft)!=0 ){
79456
- cacheX = *pX;
78974
+ tempX = *pX;
7945778975
testcase( pX->op==TK_COLUMN );
79458
- testcase( pX->op==TK_REGISTER );
79459
- exprToRegister(&cacheX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
78976
+ exprToRegister(&tempX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
7946078977
testcase( regFree1==0 );
7946178978
opCompare.op = TK_EQ;
79462
- opCompare.pLeft = &cacheX;
78979
+ opCompare.pLeft = &tempX;
7946378980
pTest = &opCompare;
7946478981
/* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
7946578982
** The value in regFree1 might get SCopy-ed into the file result.
7946678983
** So make sure that the regFree1 register is not reused for other
7946778984
** purposes and possibly overwritten. */
@@ -79477,11 +78994,10 @@
7947778994
}
7947878995
nextCase = sqlite3VdbeMakeLabel(v);
7947978996
testcase( pTest->op==TK_COLUMN );
7948078997
sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
7948178998
testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
79482
- testcase( aListelem[i+1].pExpr->op==TK_REGISTER );
7948378999
sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
7948479000
sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
7948579001
sqlite3ExprCachePop(pParse, 1);
7948679002
sqlite3VdbeResolveLabel(v, nextCase);
7948779003
}
@@ -79527,28 +79043,75 @@
7952779043
}
7952879044
sqlite3ReleaseTempReg(pParse, regFree1);
7952979045
sqlite3ReleaseTempReg(pParse, regFree2);
7953079046
return inReg;
7953179047
}
79048
+
79049
+/*
79050
+** Factor out the code of the given expression to initialization time.
79051
+*/
79052
+SQLITE_PRIVATE void sqlite3ExprCodeAtInit(
79053
+ Parse *pParse, /* Parsing context */
79054
+ Expr *pExpr, /* The expression to code when the VDBE initializes */
79055
+ int regDest, /* Store the value in this register */
79056
+ u8 reusable /* True if this expression is reusable */
79057
+){
79058
+ ExprList *p;
79059
+ assert( ConstFactorOk(pParse) );
79060
+ p = pParse->pConstExpr;
79061
+ pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
79062
+ p = sqlite3ExprListAppend(pParse, p, pExpr);
79063
+ if( p ){
79064
+ struct ExprList_item *pItem = &p->a[p->nExpr-1];
79065
+ pItem->u.iConstExprReg = regDest;
79066
+ pItem->reusable = reusable;
79067
+ }
79068
+ pParse->pConstExpr = p;
79069
+}
7953279070
7953379071
/*
7953479072
** Generate code to evaluate an expression and store the results
7953579073
** into a register. Return the register number where the results
7953679074
** are stored.
7953779075
**
7953879076
** If the register is a temporary register that can be deallocated,
7953979077
** then write its number into *pReg. If the result register is not
7954079078
** a temporary, then set *pReg to zero.
79079
+**
79080
+** If pExpr is a constant, then this routine might generate this
79081
+** code to fill the register in the initialization section of the
79082
+** VDBE program, in order to factor it out of the evaluation loop.
7954179083
*/
7954279084
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79543
- int r1 = sqlite3GetTempReg(pParse);
79544
- int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79545
- if( r2==r1 ){
79546
- *pReg = r1;
79085
+ int r2;
79086
+ pExpr = sqlite3ExprSkipCollate(pExpr);
79087
+ if( ConstFactorOk(pParse)
79088
+ && pExpr->op!=TK_REGISTER
79089
+ && sqlite3ExprIsConstantNotJoin(pExpr)
79090
+ ){
79091
+ ExprList *p = pParse->pConstExpr;
79092
+ int i;
79093
+ *pReg = 0;
79094
+ if( p ){
79095
+ struct ExprList_item *pItem;
79096
+ for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
79097
+ if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
79098
+ return pItem->u.iConstExprReg;
79099
+ }
79100
+ }
79101
+ }
79102
+ r2 = ++pParse->nMem;
79103
+ sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
7954779104
}else{
79548
- sqlite3ReleaseTempReg(pParse, r1);
79549
- *pReg = 0;
79105
+ int r1 = sqlite3GetTempReg(pParse);
79106
+ r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79107
+ if( r2==r1 ){
79108
+ *pReg = r1;
79109
+ }else{
79110
+ sqlite3ReleaseTempReg(pParse, r1);
79111
+ *pReg = 0;
79112
+ }
7955079113
}
7955179114
return r2;
7955279115
}
7955379116
7955479117
/*
@@ -79587,16 +79150,17 @@
7958779150
SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
7958879151
Vdbe *v = pParse->pVdbe;
7958979152
int inReg;
7959079153
inReg = sqlite3ExprCode(pParse, pExpr, target);
7959179154
assert( target>0 );
79592
- /* This routine is called for terms to INSERT or UPDATE. And the only
79593
- ** other place where expressions can be converted into TK_REGISTER is
79594
- ** in WHERE clause processing. So as currently implemented, there is
79595
- ** no way for a TK_REGISTER to exist here. But it seems prudent to
79596
- ** keep the ALWAYS() in case the conditions above change with future
79597
- ** modifications or enhancements. */
79155
+ /* The only place, other than this routine, where expressions can be
79156
+ ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79157
+ ** CASE operators. Neither ever calls this routine. And this routine
79158
+ ** is never called twice on the same expression. Hence it is impossible
79159
+ ** for the input to this routine to already be a register. Nevertheless,
79160
+ ** it seems prudent to keep the ALWAYS() in case the conditions above
79161
+ ** change with future modifications or enhancements. */
7959879162
if( ALWAYS(pExpr->op!=TK_REGISTER) ){
7959979163
int iMem;
7960079164
iMem = ++pParse->nMem;
7960179165
sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
7960279166
exprToRegister(pExpr, iMem);
@@ -79724,11 +79288,10 @@
7972479288
sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
7972579289
break;
7972679290
}
7972779291
7972879292
case TK_AGG_FUNCTION:
79729
- case TK_CONST_FUNC:
7973079293
case TK_FUNCTION: {
7973179294
ExprList *pFarg; /* List of function arguments */
7973279295
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
7973379296
pFarg = 0;
7973479297
}else{
@@ -79874,169 +79437,46 @@
7987479437
}
7987579438
sqlite3ExplainPop(pOut);
7987679439
}
7987779440
}
7987879441
#endif /* SQLITE_DEBUG */
79879
-
79880
-/*
79881
-** Return TRUE if pExpr is an constant expression that is appropriate
79882
-** for factoring out of a loop. Appropriate expressions are:
79883
-**
79884
-** * Any expression that evaluates to two or more opcodes.
79885
-**
79886
-** * Any OP_Integer, OP_Real, OP_String, OP_Blob, OP_Null,
79887
-** or OP_Variable that does not need to be placed in a
79888
-** specific register.
79889
-**
79890
-** There is no point in factoring out single-instruction constant
79891
-** expressions that need to be placed in a particular register.
79892
-** We could factor them out, but then we would end up adding an
79893
-** OP_SCopy instruction to move the value into the correct register
79894
-** later. We might as well just use the original instruction and
79895
-** avoid the OP_SCopy.
79896
-*/
79897
-static int isAppropriateForFactoring(Expr *p){
79898
- if( !sqlite3ExprIsConstantNotJoin(p) ){
79899
- return 0; /* Only constant expressions are appropriate for factoring */
79900
- }
79901
- if( (p->flags & EP_FixedDest)==0 ){
79902
- return 1; /* Any constant without a fixed destination is appropriate */
79903
- }
79904
- while( p->op==TK_UPLUS ) p = p->pLeft;
79905
- switch( p->op ){
79906
-#ifndef SQLITE_OMIT_BLOB_LITERAL
79907
- case TK_BLOB:
79908
-#endif
79909
- case TK_VARIABLE:
79910
- case TK_INTEGER:
79911
- case TK_FLOAT:
79912
- case TK_NULL:
79913
- case TK_STRING: {
79914
- testcase( p->op==TK_BLOB );
79915
- testcase( p->op==TK_VARIABLE );
79916
- testcase( p->op==TK_INTEGER );
79917
- testcase( p->op==TK_FLOAT );
79918
- testcase( p->op==TK_NULL );
79919
- testcase( p->op==TK_STRING );
79920
- /* Single-instruction constants with a fixed destination are
79921
- ** better done in-line. If we factor them, they will just end
79922
- ** up generating an OP_SCopy to move the value to the destination
79923
- ** register. */
79924
- return 0;
79925
- }
79926
- case TK_UMINUS: {
79927
- if( p->pLeft->op==TK_FLOAT || p->pLeft->op==TK_INTEGER ){
79928
- return 0;
79929
- }
79930
- break;
79931
- }
79932
- default: {
79933
- break;
79934
- }
79935
- }
79936
- return 1;
79937
-}
79938
-
79939
-/*
79940
-** If pExpr is a constant expression that is appropriate for
79941
-** factoring out of a loop, then evaluate the expression
79942
-** into a register and convert the expression into a TK_REGISTER
79943
-** expression.
79944
-*/
79945
-static int evalConstExpr(Walker *pWalker, Expr *pExpr){
79946
- Parse *pParse = pWalker->pParse;
79947
- switch( pExpr->op ){
79948
- case TK_IN:
79949
- case TK_REGISTER: {
79950
- return WRC_Prune;
79951
- }
79952
- case TK_COLLATE: {
79953
- return WRC_Continue;
79954
- }
79955
- case TK_FUNCTION:
79956
- case TK_AGG_FUNCTION:
79957
- case TK_CONST_FUNC: {
79958
- /* The arguments to a function have a fixed destination.
79959
- ** Mark them this way to avoid generated unneeded OP_SCopy
79960
- ** instructions.
79961
- */
79962
- ExprList *pList = pExpr->x.pList;
79963
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79964
- if( pList ){
79965
- int i = pList->nExpr;
79966
- struct ExprList_item *pItem = pList->a;
79967
- for(; i>0; i--, pItem++){
79968
- if( ALWAYS(pItem->pExpr) ) pItem->pExpr->flags |= EP_FixedDest;
79969
- }
79970
- }
79971
- break;
79972
- }
79973
- }
79974
- if( isAppropriateForFactoring(pExpr) ){
79975
- int r1 = ++pParse->nMem;
79976
- int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79977
- /* If r2!=r1, it means that register r1 is never used. That is harmless
79978
- ** but suboptimal, so we want to know about the situation to fix it.
79979
- ** Hence the following assert: */
79980
- assert( r2==r1 );
79981
- exprToRegister(pExpr, r2);
79982
- return WRC_Prune;
79983
- }
79984
- return WRC_Continue;
79985
-}
79986
-
79987
-/*
79988
-** Preevaluate constant subexpressions within pExpr and store the
79989
-** results in registers. Modify pExpr so that the constant subexpresions
79990
-** are TK_REGISTER opcodes that refer to the precomputed values.
79991
-**
79992
-** This routine is a no-op if the jump to the cookie-check code has
79993
-** already occur. Since the cookie-check jump is generated prior to
79994
-** any other serious processing, this check ensures that there is no
79995
-** way to accidently bypass the constant initializations.
79996
-**
79997
-** This routine is also a no-op if the SQLITE_FactorOutConst optimization
79998
-** is disabled via the sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS)
79999
-** interface. This allows test logic to verify that the same answer is
80000
-** obtained for queries regardless of whether or not constants are
80001
-** precomputed into registers or if they are inserted in-line.
80002
-*/
80003
-SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse *pParse, Expr *pExpr){
80004
- Walker w;
80005
- if( pParse->cookieGoto ) return;
80006
- if( OptimizationDisabled(pParse->db, SQLITE_FactorOutConst) ) return;
80007
- memset(&w, 0, sizeof(w));
80008
- w.xExprCallback = evalConstExpr;
80009
- w.pParse = pParse;
80010
- sqlite3WalkExpr(&w, pExpr);
80011
-}
80012
-
8001379442
8001479443
/*
8001579444
** Generate code that pushes the value of every element of the given
8001679445
** expression list into a sequence of registers beginning at target.
8001779446
**
8001879447
** Return the number of elements evaluated.
79448
+**
79449
+** The SQLITE_ECEL_DUP flag prevents the arguments from being
79450
+** filled using OP_SCopy. OP_Copy must be used instead.
79451
+**
79452
+** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
79453
+** factored out into initialization code.
8001979454
*/
8002079455
SQLITE_PRIVATE int sqlite3ExprCodeExprList(
8002179456
Parse *pParse, /* Parsing context */
8002279457
ExprList *pList, /* The expression list to be coded */
8002379458
int target, /* Where to write results */
80024
- int doHardCopy /* Make a hard copy of every element */
79459
+ u8 flags /* SQLITE_ECEL_* flags */
8002579460
){
8002679461
struct ExprList_item *pItem;
8002779462
int i, n;
79463
+ u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
8002879464
assert( pList!=0 );
8002979465
assert( target>0 );
8003079466
assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
8003179467
n = pList->nExpr;
79468
+ if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
8003279469
for(pItem=pList->a, i=0; i<n; i++, pItem++){
8003379470
Expr *pExpr = pItem->pExpr;
80034
- int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
80035
- if( inReg!=target+i ){
80036
- sqlite3VdbeAddOp2(pParse->pVdbe, doHardCopy ? OP_Copy : OP_SCopy,
80037
- inReg, target+i);
79471
+ if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
79472
+ sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
79473
+ }else{
79474
+ int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
79475
+ if( inReg!=target+i ){
79476
+ sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i);
79477
+ }
8003879478
}
8003979479
}
8004079480
return n;
8004179481
}
8004279482
@@ -80386,44 +79826,46 @@
8038679826
** this routine is used, it does not hurt to get an extra 2 - that
8038779827
** just might result in some slightly slower code. But returning
8038879828
** an incorrect 0 or 1 could lead to a malfunction.
8038979829
*/
8039079830
SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
80391
- if( pA==0||pB==0 ){
79831
+ u32 combinedFlags;
79832
+ if( pA==0 || pB==0 ){
8039279833
return pB==pA ? 0 : 2;
8039379834
}
80394
- assert( !ExprHasProperty(pA, EP_TokenOnly|EP_Reduced) );
80395
- assert( !ExprHasProperty(pB, EP_TokenOnly|EP_Reduced) );
80396
- if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
79835
+ combinedFlags = pA->flags | pB->flags;
79836
+ if( combinedFlags & EP_IntValue ){
79837
+ if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
79838
+ return 0;
79839
+ }
8039779840
return 2;
8039879841
}
80399
- if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
80400
- if( pA->op!=pB->op && (pA->op!=TK_REGISTER || pA->op2!=pB->op) ){
79842
+ if( pA->op!=pB->op ){
8040179843
if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB, iTab)<2 ){
8040279844
return 1;
8040379845
}
8040479846
if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
8040579847
return 1;
8040679848
}
8040779849
return 2;
8040879850
}
80409
- if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
80410
- if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
80411
- if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
80412
- if( pA->iColumn!=pB->iColumn ) return 2;
80413
- if( pA->iTable!=pB->iTable
80414
- && pA->op!=TK_REGISTER
80415
- && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
80416
- if( ExprHasProperty(pA, EP_IntValue) ){
80417
- if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
80418
- return 2;
80419
- }
80420
- }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){
80421
- if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
79851
+ if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
8042279852
if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
8042379853
return pA->op==TK_COLLATE ? 1 : 2;
8042479854
}
79855
+ }
79856
+ if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
79857
+ if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
79858
+ if( combinedFlags & EP_xIsSelect ) return 2;
79859
+ if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
79860
+ if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
79861
+ if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
79862
+ if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
79863
+ if( pA->iColumn!=pB->iColumn ) return 2;
79864
+ if( pA->iTable!=pB->iTable
79865
+ && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
79866
+ }
8042579867
}
8042679868
return 0;
8042779869
}
8042879870
8042979871
/*
@@ -83076,14 +82518,16 @@
8307682518
}
8307782519
pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
8307882520
if( pTable==0 ){
8307982521
return 0;
8308082522
}
83081
- if( argv[1] ){
83082
- pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
83083
- }else{
82523
+ if( argv[1]==0 ){
8308482524
pIndex = 0;
82525
+ }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
82526
+ pIndex = sqlite3PrimaryKeyIndex(pTable);
82527
+ }else{
82528
+ pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8308582529
}
8308682530
z = argv[2];
8308782531
8308882532
if( pIndex ){
8308982533
decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
@@ -84394,11 +83838,11 @@
8439483838
** transaction on each used database and to verify the schema cookie
8439583839
** on each used database.
8439683840
*/
8439783841
if( pParse->cookieGoto>0 ){
8439883842
yDbMask mask;
84399
- int iDb;
83843
+ int iDb, i, addr;
8440083844
sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
8440183845
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
8440283846
if( (mask & pParse->cookieMask)==0 ) continue;
8440383847
sqlite3VdbeUsesBtree(v, iDb);
8440483848
sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
@@ -84408,18 +83852,15 @@
8440883852
iDb, pParse->cookieValue[iDb],
8440983853
db->aDb[iDb].pSchema->iGeneration);
8441083854
}
8441183855
}
8441283856
#ifndef SQLITE_OMIT_VIRTUALTABLE
84413
- {
84414
- int i;
84415
- for(i=0; i<pParse->nVtabLock; i++){
84416
- char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84417
- sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
84418
- }
84419
- pParse->nVtabLock = 0;
84420
- }
83857
+ for(i=0; i<pParse->nVtabLock; i++){
83858
+ char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
83859
+ sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
83860
+ }
83861
+ pParse->nVtabLock = 0;
8442183862
#endif
8442283863
8442383864
/* Once all the cookies have been verified and transactions opened,
8442483865
** obtain the required table-locks. This is a no-op unless the
8442583866
** shared-cache feature is enabled.
@@ -84427,24 +83868,30 @@
8442783868
codeTableLocks(pParse);
8442883869
8442983870
/* Initialize any AUTOINCREMENT data structures required.
8443083871
*/
8443183872
sqlite3AutoincrementBegin(pParse);
83873
+
83874
+ /* Code constant expressions that where factored out of inner loops */
83875
+ addr = pParse->cookieGoto;
83876
+ if( pParse->pConstExpr ){
83877
+ ExprList *pEL = pParse->pConstExpr;
83878
+ pParse->cookieGoto = 0;
83879
+ for(i=0; i<pEL->nExpr; i++){
83880
+ sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
83881
+ }
83882
+ }
8443283883
8443383884
/* Finally, jump back to the beginning of the executable code. */
84434
- sqlite3VdbeAddOp2(v, OP_Goto, 0, pParse->cookieGoto);
83885
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
8443583886
}
8443683887
}
8443783888
8443883889
8443983890
/* Get the VDBE program ready for execution
8444083891
*/
8444183892
if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
84442
-#ifdef SQLITE_DEBUG
84443
- FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
84444
- sqlite3VdbeTrace(v, trace);
84445
-#endif
8444683893
assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
8444783894
/* A minimum of one cursor is required if autoincrement is used
8444883895
* See ticket [a696379c1f08866] */
8444983896
if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
8445083897
sqlite3VdbeMakeReady(v, pParse);
@@ -87031,11 +86478,11 @@
8703186478
Token *pName = 0; /* Unqualified name of the index to create */
8703286479
struct ExprList_item *pListItem; /* For looping over pList */
8703386480
const Column *pTabCol; /* A column in the table */
8703486481
int nExtra = 0; /* Space allocated for zExtra[] */
8703586482
int nExtraCol; /* Number of extra columns needed */
87036
- char *zExtra; /* Extra space after the Index object */
86483
+ char *zExtra = 0; /* Extra space after the Index object */
8703786484
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
8703886485
8703986486
assert( pParse->nErr==0 ); /* Never called with prior errors */
8704086487
if( db->mallocFailed || IN_DECLARE_VTAB ){
8704186488
goto exit_create_index;
@@ -88230,13 +87677,13 @@
8823087677
sqlite3StrAccumInit(&errMsg, 0, 0, 200);
8823187678
errMsg.db = pParse->db;
8823287679
for(j=0; j<pIdx->nKeyCol; j++){
8823387680
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
8823487681
if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
88235
- sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
87682
+ sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
8823687683
sqlite3StrAccumAppend(&errMsg, ".", 1);
88237
- sqlite3StrAccumAppend(&errMsg, zCol, -1);
87684
+ sqlite3StrAccumAppendAll(&errMsg, zCol);
8823887685
}
8823987686
zErr = sqlite3StrAccumFinish(&errMsg);
8824087687
sqlite3HaltConstraint(pParse,
8824187688
(pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
8824287689
onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88424,12 +87871,13 @@
8842487871
}
8842587872
if( pKey ){
8842687873
assert( sqlite3KeyInfoIsWriteable(pKey) );
8842787874
for(i=0; i<nCol; i++){
8842887875
char *zColl = pIdx->azColl[i];
88429
- if( NEVER(zColl==0) ) zColl = "BINARY";
88430
- pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
87876
+ assert( zColl!=0 );
87877
+ pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
87878
+ sqlite3LocateCollSeq(pParse, zColl);
8843187879
pKey->aSortOrder[i] = pIdx->aSortOrder[i];
8843287880
}
8843387881
if( pParse->nErr ){
8843487882
sqlite3KeyInfoUnref(pKey);
8843587883
}else{
@@ -89148,24 +88596,38 @@
8914888596
Expr *pWhere /* The WHERE clause. May be null */
8914988597
){
8915088598
Vdbe *v; /* The virtual database engine */
8915188599
Table *pTab; /* The table from which records will be deleted */
8915288600
const char *zDb; /* Name of database holding pTab */
89153
- int end, addr = 0; /* A couple addresses of generated code */
8915488601
int i; /* Loop counter */
8915588602
WhereInfo *pWInfo; /* Information about the WHERE clause */
8915688603
Index *pIdx; /* For looping over indices of the table */
8915788604
int iTabCur; /* Cursor number for the table */
8915888605
int iDataCur; /* VDBE cursor for the canonical data source */
8915988606
int iIdxCur; /* Cursor number of the first index */
88607
+ int nIdx; /* Number of indices */
8916088608
sqlite3 *db; /* Main database structure */
8916188609
AuthContext sContext; /* Authorization context */
8916288610
NameContext sNC; /* Name context to resolve expressions in */
8916388611
int iDb; /* Database number */
8916488612
int memCnt = -1; /* Memory cell used for change counting */
8916588613
int rcauth; /* Value returned by authorization callback */
89166
-
88614
+ int okOnePass; /* True for one-pass algorithm without the FIFO */
88615
+ int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
88616
+ u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
88617
+ Index *pPk; /* The PRIMARY KEY index on the table */
88618
+ int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */
88619
+ i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
88620
+ int iKey; /* Memory cell holding key of row to be deleted */
88621
+ i16 nKey; /* Number of memory cells in the row key */
88622
+ int iEphCur = 0; /* Ephemeral table holding all primary key values */
88623
+ int iRowSet = 0; /* Register for rowset of rows to delete */
88624
+ int addrBypass = 0; /* Address of jump over the delete logic */
88625
+ int addrLoop = 0; /* Top of the delete loop */
88626
+ int addrDelete = 0; /* Jump directly to the delete logic */
88627
+ int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
88628
+
8916788629
#ifndef SQLITE_OMIT_TRIGGER
8916888630
int isView; /* True if attempting to delete from a view */
8916988631
Trigger *pTrigger; /* List of table triggers, if required */
8917088632
#endif
8917188633
@@ -89216,15 +88678,15 @@
8921688678
if( rcauth==SQLITE_DENY ){
8921788679
goto delete_from_cleanup;
8921888680
}
8921988681
assert(!isView || pTrigger);
8922088682
89221
- /* Assign cursor number to the table and all its indices.
88683
+ /* Assign cursor numbers to the table and all its indices.
8922288684
*/
8922388685
assert( pTabList->nSrc==1 );
8922488686
iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
89225
- for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
88687
+ for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
8922688688
pParse->nTab++;
8922788689
}
8922888690
8922988691
/* Start the view context
8923088692
*/
@@ -89286,132 +88748,162 @@
8928688748
assert( pIdx->pSchema==pTab->pSchema );
8928788749
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
8928888750
}
8928988751
}else
8929088752
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
89291
- if( !HasRowid(pTab) ){
89292
- /* There is a WHERE clause on a WITHOUT ROWID table.
89293
- */
89294
- Index *pPk; /* The PRIMARY KEY index on the table */
89295
- int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
89296
- int iEph; /* Ephemeral table holding all primary key values */
89297
- int iKey; /* Key value inserting into iEph */
89298
- i16 nPk; /* Number of components of the PRIMARY KEY */
89299
-
89300
- pPk = sqlite3PrimaryKeyIndex(pTab);
89301
- assert( pPk!=0 );
89302
- nPk = pPk->nKeyCol;
89303
- iPk = pParse->nMem+1;
89304
- pParse->nMem += nPk;
89305
- iKey = ++pParse->nMem;
89306
- iEph = pParse->nTab++;
89307
-
89308
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
89309
- sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89310
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 0, 0);
89311
- if( pWInfo==0 ) goto delete_from_cleanup;
89312
- for(i=0; i<nPk; i++){
89313
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, pPk->aiColumn[i],iPk+i);
89314
- }
89315
- sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89316
- sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89317
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, iKey);
89318
- if( db->flags & SQLITE_CountRows ){
89319
- sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89320
- }
89321
- sqlite3WhereEnd(pWInfo);
89322
-
89323
- /* Open cursors for all indices of the table.
89324
- */
89325
- sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite,
89326
- iTabCur, &iDataCur, &iIdxCur);
89327
-
89328
- /* Loop over the primary keys to be deleted. */
89329
- addr = sqlite3VdbeAddOp1(v, OP_Rewind, iEph);
89330
- sqlite3VdbeAddOp2(v, OP_RowKey, iEph, iPk);
89331
-
89332
- /* Delete the row */
89333
- sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89334
- iPk, 0, 1, OE_Default, 0);
89335
-
89336
- /* End of the delete loop */
89337
- sqlite3VdbeAddOp2(v, OP_Next, iEph, addr+1);
89338
- sqlite3VdbeJumpHere(v, addr);
89339
-
89340
- /* Close the cursors open on the table and its indexes. */
89341
- assert( iDataCur>=iIdxCur );
89342
- for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89343
- sqlite3VdbeAddOp1(v, OP_Close, iIdxCur+i);
89344
- }
89345
- }else{
89346
- /* There is a WHERE clause on a rowid table. Run a loop that extracts
89347
- ** all rowids to be deleted into a RowSet.
89348
- */
89349
- int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
89350
- int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
89351
- int regRowid; /* Actual register containing rowids */
89352
-
89353
- /* Collect rowids of every row to be deleted.
89354
- */
89355
- sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
89356
- pWInfo = sqlite3WhereBegin(
89357
- pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
89358
- );
89359
- if( pWInfo==0 ) goto delete_from_cleanup;
89360
- regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iRowid, 0);
89361
- sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
89362
- if( db->flags & SQLITE_CountRows ){
89363
- sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89364
- }
89365
- sqlite3WhereEnd(pWInfo);
89366
-
89367
- /* Delete every item whose key was written to the list during the
89368
- ** database scan. We have to delete items after the scan is complete
89369
- ** because deleting an item can change the scan order. */
89370
- end = sqlite3VdbeMakeLabel(v);
89371
-
89372
- /* Unless this is a view, open cursors for the table we are
89373
- ** deleting from and all its indices. If this is a view, then the
89374
- ** only effect this statement has is to fire the INSTEAD OF
89375
- ** triggers. */
89376
- if( !isView ){
89377
- sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur,
89378
- &iDataCur, &iIdxCur);
89379
- assert( iDataCur==iTabCur );
89380
- assert( iIdxCur==iDataCur+1 );
89381
- }
89382
-
89383
- addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);
89384
-
88753
+ {
88754
+ if( HasRowid(pTab) ){
88755
+ /* For a rowid table, initialize the RowSet to an empty set */
88756
+ pPk = 0;
88757
+ nPk = 1;
88758
+ iRowSet = ++pParse->nMem;
88759
+ sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
88760
+ }else{
88761
+ /* For a WITHOUT ROWID table, create an ephermeral table used to
88762
+ ** hold all primary keys for rows to be deleted. */
88763
+ pPk = sqlite3PrimaryKeyIndex(pTab);
88764
+ assert( pPk!=0 );
88765
+ nPk = pPk->nKeyCol;
88766
+ iPk = pParse->nMem+1;
88767
+ pParse->nMem += nPk;
88768
+ iEphCur = pParse->nTab++;
88769
+ addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk);
88770
+ sqlite3VdbeSetP4KeyInfo(pParse, pPk);
88771
+ }
88772
+
88773
+ /* Construct a query to find the rowid or primary key for every row
88774
+ ** to be deleted, based on the WHERE clause.
88775
+ */
88776
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
88777
+ WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK,
88778
+ iTabCur+1);
88779
+ if( pWInfo==0 ) goto delete_from_cleanup;
88780
+ okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
88781
+
88782
+ /* Keep track of the number of rows to be deleted */
88783
+ if( db->flags & SQLITE_CountRows ){
88784
+ sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
88785
+ }
88786
+
88787
+ /* Extract the rowid or primary key for the current row */
88788
+ if( pPk ){
88789
+ for(i=0; i<nPk; i++){
88790
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
88791
+ pPk->aiColumn[i], iPk+i);
88792
+ }
88793
+ iKey = iPk;
88794
+ }else{
88795
+ iKey = pParse->nMem + 1;
88796
+ iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0);
88797
+ if( iKey>pParse->nMem ) pParse->nMem = iKey;
88798
+ }
88799
+
88800
+ if( okOnePass ){
88801
+ /* For ONEPASS, no need to store the rowid/primary-key. There is only
88802
+ ** one, so just keep it in its register(s) and fall through to the
88803
+ ** delete code.
88804
+ */
88805
+ nKey = nPk; /* OP_Found will use an unpacked key */
88806
+ aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
88807
+ if( aToOpen==0 ){
88808
+ sqlite3WhereEnd(pWInfo);
88809
+ goto delete_from_cleanup;
88810
+ }
88811
+ memset(aToOpen, 1, nIdx+1);
88812
+ aToOpen[nIdx+1] = 0;
88813
+ if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
88814
+ if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
88815
+ if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
88816
+ addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */
88817
+ }else if( pPk ){
88818
+ /* Construct a composite key for the row to be deleted and remember it */
88819
+ iKey = ++pParse->nMem;
88820
+ nKey = 0; /* Zero tells OP_Found to use a composite key */
88821
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
88822
+ sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
88823
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
88824
+ }else{
88825
+ /* Get the rowid of the row to be deleted and remember it in the RowSet */
88826
+ nKey = 1; /* OP_Seek always uses a single rowid */
88827
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
88828
+ }
88829
+
88830
+ /* End of the WHERE loop */
88831
+ sqlite3WhereEnd(pWInfo);
88832
+ if( okOnePass ){
88833
+ /* Bypass the delete logic below if the WHERE loop found zero rows */
88834
+ addrBypass = sqlite3VdbeMakeLabel(v);
88835
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
88836
+ sqlite3VdbeJumpHere(v, addrDelete);
88837
+ }
88838
+
88839
+ /* Unless this is a view, open cursors for the table we are
88840
+ ** deleting from and all its indices. If this is a view, then the
88841
+ ** only effect this statement has is to fire the INSTEAD OF
88842
+ ** triggers.
88843
+ */
88844
+ if( !isView ){
88845
+ sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen,
88846
+ &iDataCur, &iIdxCur);
88847
+ assert( pPk || iDataCur==iTabCur );
88848
+ assert( pPk || iIdxCur==iDataCur+1 );
88849
+ }
88850
+
88851
+ /* Set up a loop over the rowids/primary-keys that were found in the
88852
+ ** where-clause loop above.
88853
+ */
88854
+ if( okOnePass ){
88855
+ /* Just one row. Hence the top-of-loop is a no-op */
88856
+ assert( nKey==nPk ); /* OP_Found will use an unpacked key */
88857
+ if( aToOpen[iDataCur-iTabCur] ){
88858
+ assert( pPk!=0 );
88859
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
88860
+ }
88861
+ }else if( pPk ){
88862
+ addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
88863
+ sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
88864
+ assert( nKey==0 ); /* OP_Found will use a composite key */
88865
+ }else{
88866
+ addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
88867
+ assert( nKey==1 );
88868
+ }
88869
+
8938588870
/* Delete the row */
8938688871
#ifndef SQLITE_OMIT_VIRTUALTABLE
8938788872
if( IsVirtual(pTab) ){
8938888873
const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
8938988874
sqlite3VtabMakeWritable(pParse, pTab);
89390
- sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
88875
+ sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
8939188876
sqlite3VdbeChangeP5(v, OE_Abort);
8939288877
sqlite3MayAbort(pParse);
8939388878
}else
8939488879
#endif
8939588880
{
8939688881
int count = (pParse->nested==0); /* True to count changes */
8939788882
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89398
- iRowid, 1, count, OE_Default, 0);
88883
+ iKey, nKey, count, OE_Default, okOnePass);
8939988884
}
89400
-
89401
- /* End of the delete loop */
89402
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
89403
- sqlite3VdbeResolveLabel(v, end);
89404
-
88885
+
88886
+ /* End of the loop over all rowids/primary-keys. */
88887
+ if( okOnePass ){
88888
+ sqlite3VdbeResolveLabel(v, addrBypass);
88889
+ }else if( pPk ){
88890
+ sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
88891
+ sqlite3VdbeJumpHere(v, addrLoop);
88892
+ }else{
88893
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
88894
+ sqlite3VdbeJumpHere(v, addrLoop);
88895
+ }
88896
+
8940588897
/* Close the cursors open on the table and its indexes. */
8940688898
if( !isView && !IsVirtual(pTab) ){
89407
- sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
88899
+ if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
8940888900
for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
8940988901
sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
8941088902
}
8941188903
}
89412
- }
88904
+ } /* End non-truncate path */
8941388905
8941488906
/* Update the sqlite_sequence table by storing the content of the
8941588907
** maximum rowid counter values recorded while inserting into
8941688908
** autoincrement tables.
8941788909
*/
@@ -89431,10 +88923,11 @@
8943188923
8943288924
delete_from_cleanup:
8943388925
sqlite3AuthContextPop(&sContext);
8943488926
sqlite3SrcListDelete(db, pTabList);
8943588927
sqlite3ExprDelete(db, pWhere);
88928
+ sqlite3DbFree(db, aToOpen);
8943688929
return;
8943788930
}
8943888931
/* Make sure "isView" and other macros defined above are undefined. Otherwise
8943988932
** thely may interfere with compilation of other functions in this file
8944088933
** (or in another file, if this file becomes part of the amalgamation). */
@@ -89497,10 +88990,11 @@
8949788990
/* If there are any triggers to fire, allocate a range of registers to
8949888991
** use for the old.* references in the triggers. */
8949988992
if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
8950088993
u32 mask; /* Mask of OLD.* columns in use */
8950188994
int iCol; /* Iterator used while populating OLD.* */
88995
+ int addrStart; /* Start of BEFORE trigger programs */
8950288996
8950388997
/* TODO: Could use temporary registers here. Also could attempt to
8950488998
** avoid copying the contents of the rowid register. */
8950588999
mask = sqlite3TriggerColmask(
8950689000
pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
@@ -89517,19 +89011,23 @@
8951789011
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
8951889012
}
8951989013
}
8952089014
8952189015
/* Invoke BEFORE DELETE trigger programs. */
89016
+ addrStart = sqlite3VdbeCurrentAddr(v);
8952289017
sqlite3CodeRowTrigger(pParse, pTrigger,
8952389018
TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
8952489019
);
8952589020
89526
- /* Seek the cursor to the row to be deleted again. It may be that
89527
- ** the BEFORE triggers coded above have already removed the row
89528
- ** being deleted. Do not attempt to delete the row a second time, and
89529
- ** do not fire AFTER triggers. */
89530
- sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89021
+ /* If any BEFORE triggers were coded, then seek the cursor to the
89022
+ ** row to be deleted again. It may be that the BEFORE triggers moved
89023
+ ** the cursor or of already deleted the row that the cursor was
89024
+ ** pointing to.
89025
+ */
89026
+ if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89027
+ sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89028
+ }
8953189029
8953289030
/* Do FK processing. This call checks that any FK constraints that
8953389031
** refer to this table (i.e. constraints attached to other tables)
8953489032
** are not violated by deleting this row. */
8953589033
sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -91193,15 +90691,15 @@
9119390691
nSep = sqlite3_value_bytes(argv[1]);
9119490692
}else{
9119590693
zSep = ",";
9119690694
nSep = 1;
9119790695
}
91198
- sqlite3StrAccumAppend(pAccum, zSep, nSep);
90696
+ if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
9119990697
}
9120090698
zVal = (char*)sqlite3_value_text(argv[0]);
9120190699
nVal = sqlite3_value_bytes(argv[0]);
91202
- sqlite3StrAccumAppend(pAccum, zVal, nVal);
90700
+ if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
9120390701
}
9120490702
}
9120590703
static void groupConcatFinalize(sqlite3_context *context){
9120690704
StrAccum *pAccum;
9120790705
pAccum = sqlite3_aggregate_context(context, 0);
@@ -91346,24 +90844,24 @@
9134690844
FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
9134790845
FUNCTION(hex, 1, 0, 0, hexFunc ),
9134890846
FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
9134990847
FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
9135090848
FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
91351
- FUNCTION(random, 0, 0, 0, randomFunc ),
91352
- FUNCTION(randomblob, 1, 0, 0, randomBlob ),
90849
+ VFUNCTION(random, 0, 0, 0, randomFunc ),
90850
+ VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
9135390851
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
9135490852
FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
9135590853
FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
9135690854
FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
9135790855
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
9135890856
FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
9135990857
FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
9136090858
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
9136190859
FUNCTION(quote, 1, 0, 0, quoteFunc ),
91362
- FUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
91363
- FUNCTION(changes, 0, 0, 0, changes ),
91364
- FUNCTION(total_changes, 0, 0, 0, total_changes ),
90860
+ VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
90861
+ VFUNCTION(changes, 0, 0, 0, changes ),
90862
+ VFUNCTION(total_changes, 0, 0, 0, total_changes ),
9136590863
FUNCTION(replace, 3, 0, 0, replaceFunc ),
9136690864
FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
9136790865
#ifdef SQLITE_SOUNDEX
9136890866
FUNCTION(soundex, 1, 0, 0, soundexFunc ),
9136990867
#endif
@@ -91955,10 +91453,11 @@
9195591453
Vdbe *v = sqlite3GetVdbe(pParse);
9195691454
9195791455
assert( pIdx==0 || pIdx->pTable==pTab );
9195891456
assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
9195991457
assert( pIdx!=0 || pFKey->nCol==1 );
91458
+ assert( pIdx!=0 || HasRowid(pTab) );
9196091459
9196191460
if( nIncr<0 ){
9196291461
iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
9196391462
}
9196491463
@@ -92007,10 +91506,11 @@
9200791506
pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
9200891507
pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
9200991508
}else{
9201091509
Expr *pEq, *pAll = 0;
9201191510
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
91511
+ assert( pIdx!=0 );
9201291512
for(i=0; i<pPk->nKeyCol; i++){
9201391513
i16 iCol = pIdx->aiColumn[i];
9201491514
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
9201591515
pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
9201691516
pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
@@ -93585,11 +93085,11 @@
9358593085
}
9358693086
9358793087
/* If this is not a view, open the table and and all indices */
9358893088
if( !isView ){
9358993089
int nIdx;
93590
- nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1,
93090
+ nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1, 0,
9359193091
&iDataCur, &iIdxCur);
9359293092
aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
9359393093
if( aRegIdx==0 ){
9359493094
goto insert_cleanup;
9359593095
}
@@ -94445,42 +93945,50 @@
9444593945
SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
9444693946
Parse *pParse, /* Parsing context */
9444793947
Table *pTab, /* Table to be opened */
9444893948
int op, /* OP_OpenRead or OP_OpenWrite */
9444993949
int iBase, /* Use this for the table cursor, if there is one */
93950
+ u8 *aToOpen, /* If not NULL: boolean for each table and index */
9445093951
int *piDataCur, /* Write the database source cursor number here */
9445193952
int *piIdxCur /* Write the first index cursor number here */
9445293953
){
9445393954
int i;
9445493955
int iDb;
93956
+ int iDataCur;
9445593957
Index *pIdx;
9445693958
Vdbe *v;
9445793959
9445893960
assert( op==OP_OpenRead || op==OP_OpenWrite );
9445993961
if( IsVirtual(pTab) ){
93962
+ assert( aToOpen==0 );
9446093963
*piDataCur = 0;
9446193964
*piIdxCur = 1;
9446293965
return 0;
9446393966
}
9446493967
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
9446593968
v = sqlite3GetVdbe(pParse);
9446693969
assert( v!=0 );
9446793970
if( iBase<0 ) iBase = pParse->nTab;
94468
- if( HasRowid(pTab) ){
94469
- *piDataCur = iBase++;
94470
- sqlite3OpenTable(pParse, *piDataCur, iDb, pTab, op);
93971
+ iDataCur = iBase++;
93972
+ if( piDataCur ) *piDataCur = iDataCur;
93973
+ if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
93974
+ sqlite3OpenTable(pParse, iDataCur, iDb, pTab, op);
9447193975
}else{
9447293976
sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
9447393977
}
94474
- *piIdxCur = iBase;
93978
+ if( piIdxCur ) *piIdxCur = iBase;
9447593979
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
9447693980
int iIdxCur = iBase++;
9447793981
assert( pIdx->pSchema==pTab->pSchema );
94478
- if( pIdx->autoIndex==2 && !HasRowid(pTab) ) *piDataCur = iIdxCur;
94479
- sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94480
- sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
94481
- VdbeComment((v, "%s", pIdx->zName));
93982
+ if( pIdx->autoIndex==2 && !HasRowid(pTab) && piDataCur ){
93983
+ *piDataCur = iIdxCur;
93984
+ }
93985
+ if( aToOpen==0 || aToOpen[i+1] ){
93986
+ sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
93987
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
93988
+ VdbeComment((v, "%s", pIdx->zName));
93989
+ }
9448293990
}
9448393991
if( iBase>pParse->nTab ) pParse->nTab = iBase;
9448493992
return i;
9448593993
}
9448693994
@@ -96650,10 +96158,14 @@
9665096158
/* iArg: */ SQLITE_VdbeAddopTrace },
9665196159
{ /* zName: */ "vdbe_debug",
9665296160
/* ePragTyp: */ PragTyp_FLAG,
9665396161
/* ePragFlag: */ 0,
9665496162
/* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
96163
+ { /* zName: */ "vdbe_eqp",
96164
+ /* ePragTyp: */ PragTyp_FLAG,
96165
+ /* ePragFlag: */ 0,
96166
+ /* iArg: */ SQLITE_VdbeEQP },
9665596167
{ /* zName: */ "vdbe_listing",
9665696168
/* ePragTyp: */ PragTyp_FLAG,
9665796169
/* ePragFlag: */ 0,
9665896170
/* iArg: */ SQLITE_VdbeListing },
9665996171
{ /* zName: */ "vdbe_trace",
@@ -96677,11 +96189,11 @@
9667796189
/* ePragTyp: */ PragTyp_FLAG,
9667896190
/* ePragFlag: */ 0,
9667996191
/* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
9668096192
#endif
9668196193
};
96682
-/* Number of pragmas: 56 on by default, 68 total. */
96194
+/* Number of pragmas: 56 on by default, 69 total. */
9668396195
/* End of the automatically generated pragma table.
9668496196
***************************************************************************/
9668596197
9668696198
/*
9668796199
** Interpret the given string as a safety level. Return 0 for OFF,
@@ -98103,11 +97615,11 @@
9810397615
addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
9810497616
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9810597617
sqlite3VdbeJumpHere(v, addr);
9810697618
sqlite3ExprCacheClear(pParse);
9810797619
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98108
- 1, &iDataCur, &iIdxCur);
97620
+ 1, 0, &iDataCur, &iIdxCur);
9810997621
sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
9811097622
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9811197623
sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
9811297624
}
9811397625
pParse->nMem = MAX(pParse->nMem, 8+j);
@@ -99038,10 +98550,17 @@
9903898550
}
9903998551
assert( i>=0 && i<db->nDb );
9904098552
}
9904198553
return i;
9904298554
}
98555
+
98556
+/*
98557
+** Free all memory allocations in the pParse object
98558
+*/
98559
+SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
98560
+ if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
98561
+}
9904398562
9904498563
/*
9904598564
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
9904698565
*/
9904798566
static int sqlite3Prepare(
@@ -99196,10 +98715,11 @@
9919698715
sqlite3DbFree(db, pT);
9919798716
}
9919898717
9919998718
end_prepare:
9920098719
98720
+ sqlite3ParserReset(pParse);
9920198721
sqlite3StackFree(db, pParse);
9920298722
rc = sqlite3ApiExit(db, rc);
9920398723
assert( (rc&db->errMask)==rc );
9920498724
return rc;
9920598725
}
@@ -99989,11 +99509,12 @@
9998999509
}else if( eDest!=SRT_Exists ){
9999099510
/* If the destination is an EXISTS(...) expression, the actual
9999199511
** values returned by the SELECT are not required.
9999299512
*/
9999399513
sqlite3ExprCacheClear(pParse);
99994
- sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output);
99514
+ sqlite3ExprCodeExprList(pParse, pEList, regResult,
99515
+ (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
9999599516
}
9999699517
nColumn = nResultCol;
9999799518
9999899519
/* If the DISTINCT keyword was present on the SELECT statement
9999999520
** and this row has been seen before, then do not make this row
@@ -101762,20 +101283,20 @@
101762101283
*/
101763101284
if( op!=TK_ALL ){
101764101285
for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
101765101286
struct ExprList_item *pItem;
101766101287
for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
101767
- assert( pItem->iOrderByCol>0 );
101768
- if( pItem->iOrderByCol==i ) break;
101288
+ assert( pItem->u.x.iOrderByCol>0 );
101289
+ if( pItem->u.x.iOrderByCol==i ) break;
101769101290
}
101770101291
if( j==nOrderBy ){
101771101292
Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
101772101293
if( pNew==0 ) return SQLITE_NOMEM;
101773101294
pNew->flags |= EP_IntValue;
101774101295
pNew->u.iValue = i;
101775101296
pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
101776
- if( pOrderBy ) pOrderBy->a[nOrderBy++].iOrderByCol = (u16)i;
101297
+ if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
101777101298
}
101778101299
}
101779101300
}
101780101301
101781101302
/* Compute the comparison permutation and keyinfo that is used with
@@ -101787,12 +101308,13 @@
101787101308
*/
101788101309
aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
101789101310
if( aPermute ){
101790101311
struct ExprList_item *pItem;
101791101312
for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
101792
- assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
101793
- aPermute[i] = pItem->iOrderByCol - 1;
101313
+ assert( pItem->u.x.iOrderByCol>0
101314
+ && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
101315
+ aPermute[i] = pItem->u.x.iOrderByCol - 1;
101794101316
}
101795101317
pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
101796101318
if( pKeyMerge ){
101797101319
for(i=0; i<nOrderBy; i++){
101798101320
CollSeq *pColl;
@@ -102368,11 +101890,11 @@
102368101890
102369101891
/* Restriction 18. */
102370101892
if( p->pOrderBy ){
102371101893
int ii;
102372101894
for(ii=0; ii<p->pOrderBy->nExpr; ii++){
102373
- if( p->pOrderBy->a[ii].iOrderByCol==0 ) return 0;
101895
+ if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
102374101896
}
102375101897
}
102376101898
}
102377101899
102378101900
/***** If we reach this point, flattening is permitted. *****/
@@ -103274,11 +102796,11 @@
103274102796
ExprList *pList = pF->pExpr->x.pList;
103275102797
assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
103276102798
if( pList ){
103277102799
nArg = pList->nExpr;
103278102800
regAgg = sqlite3GetTempRange(pParse, nArg);
103279
- sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
102801
+ sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
103280102802
}else{
103281102803
nArg = 0;
103282102804
regAgg = 0;
103283102805
}
103284102806
if( pF->iDistinct>=0 ){
@@ -103775,14 +103297,14 @@
103775103297
if( pGroupBy ){
103776103298
int k; /* Loop counter */
103777103299
struct ExprList_item *pItem; /* For looping over expression in a list */
103778103300
103779103301
for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
103780
- pItem->iAlias = 0;
103302
+ pItem->u.x.iAlias = 0;
103781103303
}
103782103304
for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
103783
- pItem->iAlias = 0;
103305
+ pItem->u.x.iAlias = 0;
103784103306
}
103785103307
if( p->nSelectRow>100 ) p->nSelectRow = 100;
103786103308
}else{
103787103309
p->nSelectRow = 1;
103788103310
}
@@ -104060,15 +103582,16 @@
104060103582
104061103583
/* Search for the index that has the lowest scan cost.
104062103584
**
104063103585
** (2011-04-15) Do not do a full scan of an unordered index.
104064103586
**
104065
- ** (2013-10-03) Do not count the entires in a partial index.
103587
+ ** (2013-10-03) Do not count the entries in a partial index.
104066103588
**
104067103589
** In practice the KeyInfo structure will not be used. It is only
104068103590
** passed to keep OP_OpenRead happy.
104069103591
*/
103592
+ if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab);
104070103593
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
104071103594
if( pIdx->bUnordered==0
104072103595
&& pIdx->szIdxRow<pTab->szTabRow
104073103596
&& pIdx->pPartIdxWhere==0
104074103597
&& (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
@@ -105428,10 +104951,11 @@
105428104951
sqlite3VdbeDelete(v);
105429104952
}
105430104953
105431104954
assert( !pSubParse->pAinc && !pSubParse->pZombieTab );
105432104955
assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
104956
+ sqlite3ParserReset(pSubParse);
105433104957
sqlite3StackFree(db, pSubParse);
105434104958
105435104959
return pPrg;
105436104960
}
105437104961
@@ -105742,22 +105266,23 @@
105742105266
WhereInfo *pWInfo; /* Information about the WHERE clause */
105743105267
Vdbe *v; /* The virtual database engine */
105744105268
Index *pIdx; /* For looping over indices */
105745105269
Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
105746105270
int nIdx; /* Number of indices that need updating */
105271
+ int iBaseCur; /* Base cursor number */
105747105272
int iDataCur; /* Cursor for the canonical data btree */
105748105273
int iIdxCur; /* Cursor for the first index */
105749105274
sqlite3 *db; /* The database structure */
105750105275
int *aRegIdx = 0; /* One register assigned to each index to be updated */
105751105276
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
105752105277
** an expression for the i-th column of the table.
105753105278
** aXRef[i]==-1 if the i-th column is not changed. */
105279
+ u8 *aToOpen; /* 1 for tables and indices to be opened */
105754105280
u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105755105281
u8 chngRowid; /* Rowid changed in a normal table */
105756105282
u8 chngKey; /* Either chngPk or chngRowid */
105757105283
Expr *pRowidExpr = 0; /* Expression defining the new record number */
105758
- int openAll = 0; /* True if all indices need to be opened */
105759105284
AuthContext sContext; /* The authorization context */
105760105285
NameContext sNC; /* The name-context to resolve expressions in */
105761105286
int iDb; /* Database containing the table being updated */
105762105287
int okOnePass; /* True for one-pass algorithm without the FIFO */
105763105288
int hasFK; /* True if foreign key processing is required */
@@ -105817,29 +105342,37 @@
105817105342
goto update_cleanup;
105818105343
}
105819105344
if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
105820105345
goto update_cleanup;
105821105346
}
105822
- aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
105823
- if( aXRef==0 ) goto update_cleanup;
105824
- for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105825105347
105826105348
/* Allocate a cursors for the main database table and for all indices.
105827105349
** The index cursors might not be used, but if they are used they
105828105350
** need to occur right after the database cursor. So go ahead and
105829105351
** allocate enough space, just in case.
105830105352
*/
105831
- pTabList->a[0].iCursor = iDataCur = pParse->nTab++;
105353
+ pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++;
105832105354
iIdxCur = iDataCur+1;
105833105355
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105834105356
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105835105357
if( pIdx->autoIndex==2 && pPk!=0 ){
105836105358
iDataCur = pParse->nTab;
105837105359
pTabList->a[0].iCursor = iDataCur;
105838105360
}
105839105361
pParse->nTab++;
105840105362
}
105363
+
105364
+ /* Allocate space for aXRef[], aRegIdx[], and aToOpen[].
105365
+ ** Initialize aXRef[] and aToOpen[] to their default values.
105366
+ */
105367
+ aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 );
105368
+ if( aXRef==0 ) goto update_cleanup;
105369
+ aRegIdx = aXRef+pTab->nCol;
105370
+ aToOpen = (u8*)(aRegIdx+nIdx);
105371
+ memset(aToOpen, 1, nIdx+1);
105372
+ aToOpen[nIdx+1] = 0;
105373
+ for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105841105374
105842105375
/* Initialize the name-context */
105843105376
memset(&sNC, 0, sizeof(sNC));
105844105377
sNC.pParse = pParse;
105845105378
sNC.pSrcList = pTabList;
@@ -105894,22 +105427,22 @@
105894105427
}
105895105428
assert( (chngRowid & chngPk)==0 );
105896105429
assert( chngRowid==0 || chngRowid==1 );
105897105430
assert( chngPk==0 || chngPk==1 );
105898105431
chngKey = chngRowid + chngPk;
105432
+
105433
+ /* The SET expressions are not actually used inside the WHERE loop.
105434
+ ** So reset the colUsed mask
105435
+ */
105436
+ pTabList->a[0].colUsed = 0;
105899105437
105900105438
hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
105901105439
105902
- /* Allocate memory for the array aRegIdx[]. There is one entry in the
105903
- ** array for each index associated with table being updated. Fill in
105904
- ** the value with a register number for indices that are to be used
105905
- ** and with zero for unused indices.
105440
+ /* There is one entry in the aRegIdx[] array for each index on the table
105441
+ ** being updated. Fill in aRegIdx[] with a register number that will hold
105442
+ ** the key for accessing each index.
105906105443
*/
105907
- if( nIdx>0 ){
105908
- aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
105909
- if( aRegIdx==0 ) goto update_cleanup;
105910
- }
105911105444
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
105912105445
int reg;
105913105446
if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
105914105447
reg = ++pParse->nMem;
105915105448
}else{
@@ -105919,10 +105452,11 @@
105919105452
reg = ++pParse->nMem;
105920105453
break;
105921105454
}
105922105455
}
105923105456
}
105457
+ if( reg==0 ) aToOpen[j+1] = 0;
105924105458
aRegIdx[j] = reg;
105925105459
}
105926105460
105927105461
/* Begin generating code. */
105928105462
v = sqlite3GetVdbe(pParse);
@@ -106042,46 +105576,34 @@
106042105576
** Open every index that needs updating. Note that if any
106043105577
** index could potentially invoke a REPLACE conflict resolution
106044105578
** action, then we need to open all indices because we might need
106045105579
** to be deleting some records.
106046105580
*/
106047
- if( !okOnePass && HasRowid(pTab) ){
106048
- sqlite3OpenTable(pParse, iDataCur, iDb, pTab, OP_OpenWrite);
106049
- }
106050
- sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
106051105581
if( onError==OE_Replace ){
106052
- openAll = 1;
105582
+ memset(aToOpen, 1, nIdx+1);
106053105583
}else{
106054
- openAll = 0;
106055105584
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
106056105585
if( pIdx->onError==OE_Replace ){
106057
- openAll = 1;
105586
+ memset(aToOpen, 1, nIdx+1);
106058105587
break;
106059105588
}
106060105589
}
106061105590
}
106062
- for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106063
- int iThisCur = iIdxCur+i;
106064
- assert( aRegIdx );
106065
- if( (openAll || aRegIdx[i]>0)
106066
- && iThisCur!=aiCurOnePass[1]
106067
- ){
106068
- assert( iThisCur!=aiCurOnePass[0] );
106069
- sqlite3VdbeAddOp3(v, OP_OpenWrite, iThisCur, pIdx->tnum, iDb);
106070
- sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
106071
- assert( pParse->nTab>iThisCur );
106072
- VdbeComment((v, "%s", pIdx->zName));
106073
- if( okOnePass && pPk && iThisCur==iDataCur ){
106074
- sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak,
106075
- regKey, nKey);
106076
- }
106077
- }
106078
- }
105591
+ if( okOnePass ){
105592
+ if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
105593
+ if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
105594
+ }
105595
+ sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iBaseCur, aToOpen,
105596
+ 0, 0);
106079105597
}
106080105598
106081105599
/* Top of the update loop */
106082105600
if( okOnePass ){
105601
+ if( aToOpen[iDataCur-iBaseCur] ){
105602
+ assert( pPk!=0 );
105603
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
105604
+ }
106083105605
labelContinue = labelBreak;
106084105606
sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106085105607
}else if( pPk ){
106086105608
labelContinue = sqlite3VdbeMakeLabel(v);
106087105609
sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
@@ -106222,15 +105744,11 @@
106222105744
/* If changing the record number, delete the old record. */
106223105745
if( hasFK || chngKey || pPk!=0 ){
106224105746
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
106225105747
}
106226105748
if( bReplace || chngKey ){
106227
- if( sqlite3VdbeCurrentAddr(v)==j1+1 ){
106228
- sqlite3VdbeChangeToNoop(v, j1);
106229
- }else{
106230
- sqlite3VdbeJumpHere(v, j1);
106231
- }
105749
+ sqlite3VdbeJumpHere(v, j1);
106232105750
}
106233105751
106234105752
if( hasFK ){
106235105753
sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
106236105754
}
@@ -106270,11 +105788,11 @@
106270105788
sqlite3VdbeResolveLabel(v, labelBreak);
106271105789
106272105790
/* Close all tables */
106273105791
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106274105792
assert( aRegIdx );
106275
- if( openAll || aRegIdx[i]>0 ){
105793
+ if( aToOpen[i+1] ){
106276105794
sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
106277105795
}
106278105796
}
106279105797
if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
106280105798
@@ -106297,12 +105815,11 @@
106297105815
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
106298105816
}
106299105817
106300105818
update_cleanup:
106301105819
sqlite3AuthContextPop(&sContext);
106302
- sqlite3DbFree(db, aRegIdx);
106303
- sqlite3DbFree(db, aXRef);
105820
+ sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
106304105821
sqlite3SrcListDelete(db, pTabList);
106305105822
sqlite3ExprListDelete(db, pChanges);
106306105823
sqlite3ExprDelete(db, pWhere);
106307105824
return;
106308105825
}
@@ -107521,10 +107038,11 @@
107521107038
107522107039
if( pParse->pVdbe ){
107523107040
sqlite3VdbeFinalize(pParse->pVdbe);
107524107041
}
107525107042
sqlite3DeleteTable(db, pParse->pNewTable);
107043
+ sqlite3ParserReset(pParse);
107526107044
sqlite3StackFree(db, pParse);
107527107045
}
107528107046
107529107047
assert( (rc&0xff)==rc );
107530107048
rc = sqlite3ApiExit(db, rc);
@@ -107898,11 +107416,28 @@
107898107416
** generating the code that loops through a table looking for applicable
107899107417
** rows. Indices are selected and used to speed the search when doing
107900107418
** so is applicable. Because this module is responsible for selecting
107901107419
** indices, you might also think of this module as the "query optimizer".
107902107420
*/
107903
-
107421
+/************** Include whereInt.h in the middle of where.c ******************/
107422
+/************** Begin file whereInt.h ****************************************/
107423
+/*
107424
+** 2013-11-12
107425
+**
107426
+** The author disclaims copyright to this source code. In place of
107427
+** a legal notice, here is a blessing:
107428
+**
107429
+** May you do good and not evil.
107430
+** May you find forgiveness for yourself and forgive others.
107431
+** May you share freely, never taking more than you give.
107432
+**
107433
+*************************************************************************
107434
+**
107435
+** This file contains structure and macro definitions for the query
107436
+** planner logic in "where.c". These definitions are broken out into
107437
+** a separate source file for easier editing.
107438
+*/
107904107439
107905107440
/*
107906107441
** Trace output macros
107907107442
*/
107908107443
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
@@ -107950,10 +107485,11 @@
107950107485
int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
107951107486
int iTabCur; /* The VDBE cursor used to access the table */
107952107487
int iIdxCur; /* The VDBE cursor used to access pIdx */
107953107488
int addrBrk; /* Jump here to break out of the loop */
107954107489
int addrNxt; /* Jump here to start the next IN combination */
107490
+ int addrSkip; /* Jump here for next iteration of skip-scan */
107955107491
int addrCont; /* Jump here to continue with the next loop cycle */
107956107492
int addrFirst; /* First instruction of interior of the loop */
107957107493
int addrBody; /* Beginning of the body of this loop */
107958107494
u8 iFrom; /* Which entry in the FROM clause */
107959107495
u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
@@ -107998,11 +107534,12 @@
107998107534
LogEst rSetup; /* One-time setup cost (ex: create transient index) */
107999107535
LogEst rRun; /* Cost of running each loop */
108000107536
LogEst nOut; /* Estimated number of output rows */
108001107537
union {
108002107538
struct { /* Information for internal btree tables */
108003
- int nEq; /* Number of equality constraints */
107539
+ u16 nEq; /* Number of equality constraints */
107540
+ u16 nSkip; /* Number of initial index columns to skip */
108004107541
Index *pIndex; /* Index used, or NULL */
108005107542
} btree;
108006107543
struct { /* Information for virtual tables */
108007107544
int idxNum; /* Index number */
108008107545
u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -108339,10 +107876,14 @@
108339107876
#define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
108340107877
#define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108341107878
#define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108342107879
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108343107880
#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
107881
+#define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
107882
+
107883
+/************** End of whereInt.h ********************************************/
107884
+/************** Continuing where we left off in where.c **********************/
108344107885
108345107886
/*
108346107887
** Return the estimated number of output rows from a WHERE clause
108347107888
*/
108348107889
SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
@@ -108990,13 +108531,10 @@
108990108531
}
108991108532
assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
108992108533
108993108534
pRight = pList->a[0].pExpr;
108994108535
op = pRight->op;
108995
- if( op==TK_REGISTER ){
108996
- op = pRight->op2;
108997
- }
108998108536
if( op==TK_VARIABLE ){
108999108537
Vdbe *pReprepare = pParse->pReprepare;
109000108538
int iCol = pRight->iColumn;
109001108539
pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_NONE);
109002108540
if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
@@ -109859,10 +109397,11 @@
109859109397
}
109860109398
sqlite3DebugPrintf(" idxNum=%d\n", p->idxNum);
109861109399
sqlite3DebugPrintf(" idxStr=%s\n", p->idxStr);
109862109400
sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
109863109401
sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
109402
+ sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
109864109403
}
109865109404
#else
109866109405
#define TRACE_IDX_INPUTS(A)
109867109406
#define TRACE_IDX_OUTPUTS(A)
109868109407
#endif
@@ -110228,12 +109767,11 @@
110228109767
int res; /* Result of comparison operation */
110229109768
110230109769
#ifndef SQLITE_DEBUG
110231109770
UNUSED_PARAMETER( pParse );
110232109771
#endif
110233
- assert( pRec!=0 || pParse->db->mallocFailed );
110234
- if( pRec==0 ) return;
109772
+ assert( pRec!=0 );
110235109773
iCol = pRec->nField - 1;
110236109774
assert( pIdx->nSample>0 );
110237109775
assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110238109776
do{
110239109777
iTest = (iMin+i)/2;
@@ -110729,11 +110267,11 @@
110729110267
if( eType==IN_INDEX_ROWID ){
110730110268
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
110731110269
}else{
110732110270
pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
110733110271
}
110734
- pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
110272
+ pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
110735110273
sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
110736110274
}else{
110737110275
pLevel->u.in.nIn = 0;
110738110276
}
110739110277
#endif
@@ -110742,11 +110280,11 @@
110742110280
return iReg;
110743110281
}
110744110282
110745110283
/*
110746110284
** Generate code that will evaluate all == and IN constraints for an
110747
-** index.
110285
+** index scan.
110748110286
**
110749110287
** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
110750110288
** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
110751110289
** The index has as many as three equality constraints, but in this
110752110290
** example, the third "c" value is an inequality. So only two
@@ -110757,13 +110295,19 @@
110757110295
** In the example above nEq==2. But this subroutine works for any value
110758110296
** of nEq including 0. If nEq==0, this routine is nearly a no-op.
110759110297
** The only thing it does is allocate the pLevel->iMem memory cell and
110760110298
** compute the affinity string.
110761110299
**
110762
-** This routine always allocates at least one memory cell and returns
110763
-** the index of that memory cell. The code that
110764
-** calls this routine will use that memory cell to store the termination
110300
+** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
110301
+** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
110302
+** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
110303
+** occurs after the nEq quality constraints.
110304
+**
110305
+** This routine allocates a range of nEq+nExtraReg memory cells and returns
110306
+** the index of the first memory cell in that range. The code that
110307
+** calls this routine will use that memory range to store keys for
110308
+** start and termination conditions of the loop.
110765110309
** key value of the loop. If one or more IN operators appear, then
110766110310
** this routine allocates an additional nEq memory cells for internal
110767110311
** use.
110768110312
**
110769110313
** Before returning, *pzAff is set to point to a buffer containing a
@@ -110786,11 +110330,12 @@
110786110330
WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
110787110331
int bRev, /* Reverse the order of IN operators */
110788110332
int nExtraReg, /* Number of extra registers to allocate */
110789110333
char **pzAff /* OUT: Set to point to affinity string */
110790110334
){
110791
- int nEq; /* The number of == or IN constraints to code */
110335
+ u16 nEq; /* The number of == or IN constraints to code */
110336
+ u16 nSkip; /* Number of left-most columns to skip */
110792110337
Vdbe *v = pParse->pVdbe; /* The vm under construction */
110793110338
Index *pIdx; /* The index being used for this loop */
110794110339
WhereTerm *pTerm; /* A single constraint term */
110795110340
WhereLoop *pLoop; /* The WhereLoop object */
110796110341
int j; /* Loop counter */
@@ -110800,10 +110345,11 @@
110800110345
110801110346
/* This module is only called on query plans that use an index. */
110802110347
pLoop = pLevel->pWLoop;
110803110348
assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
110804110349
nEq = pLoop->u.btree.nEq;
110350
+ nSkip = pLoop->u.btree.nSkip;
110805110351
pIdx = pLoop->u.btree.pIndex;
110806110352
assert( pIdx!=0 );
110807110353
110808110354
/* Figure out how many memory cells we will need then allocate them.
110809110355
*/
@@ -110813,19 +110359,34 @@
110813110359
110814110360
zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
110815110361
if( !zAff ){
110816110362
pParse->db->mallocFailed = 1;
110817110363
}
110364
+
110365
+ if( nSkip ){
110366
+ int iIdxCur = pLevel->iIdxCur;
110367
+ sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
110368
+ VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
110369
+ j = sqlite3VdbeAddOp0(v, OP_Goto);
110370
+ pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
110371
+ iIdxCur, 0, regBase, nSkip);
110372
+ sqlite3VdbeJumpHere(v, j);
110373
+ for(j=0; j<nSkip; j++){
110374
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
110375
+ assert( pIdx->aiColumn[j]>=0 );
110376
+ VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
110377
+ }
110378
+ }
110818110379
110819110380
/* Evaluate the equality constraints
110820110381
*/
110821110382
assert( zAff==0 || (int)strlen(zAff)>=nEq );
110822
- for(j=0; j<nEq; j++){
110383
+ for(j=nSkip; j<nEq; j++){
110823110384
int r1;
110824110385
pTerm = pLoop->aLTerm[j];
110825110386
assert( pTerm!=0 );
110826
- /* The following true for indices with redundant columns.
110387
+ /* The following testcase is true for indices with redundant columns.
110827110388
** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
110828110389
testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
110829110390
testcase( pTerm->wtFlags & TERM_VIRTUAL );
110830110391
r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
110831110392
if( r1!=regBase+j ){
@@ -110869,11 +110430,11 @@
110869110430
int iTerm, /* Index of this term. First is zero */
110870110431
const char *zColumn, /* Name of the column */
110871110432
const char *zOp /* Name of the operator */
110872110433
){
110873110434
if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110874
- sqlite3StrAccumAppend(pStr, zColumn, -1);
110435
+ sqlite3StrAccumAppendAll(pStr, zColumn);
110875110436
sqlite3StrAccumAppend(pStr, zOp, 1);
110876110437
sqlite3StrAccumAppend(pStr, "?", 1);
110877110438
}
110878110439
110879110440
/*
@@ -110895,11 +110456,12 @@
110895110456
** It is the responsibility of the caller to free the buffer when it is
110896110457
** no longer required.
110897110458
*/
110898110459
static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
110899110460
Index *pIndex = pLoop->u.btree.pIndex;
110900
- int nEq = pLoop->u.btree.nEq;
110461
+ u16 nEq = pLoop->u.btree.nEq;
110462
+ u16 nSkip = pLoop->u.btree.nSkip;
110901110463
int i, j;
110902110464
Column *aCol = pTab->aCol;
110903110465
i16 *aiColumn = pIndex->aiColumn;
110904110466
StrAccum txt;
110905110467
@@ -110909,11 +110471,18 @@
110909110471
sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
110910110472
txt.db = db;
110911110473
sqlite3StrAccumAppend(&txt, " (", 2);
110912110474
for(i=0; i<nEq; i++){
110913110475
char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
110914
- explainAppendTerm(&txt, i, z, "=");
110476
+ if( i>=nSkip ){
110477
+ explainAppendTerm(&txt, i, z, "=");
110478
+ }else{
110479
+ if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
110480
+ sqlite3StrAccumAppend(&txt, "ANY(", 4);
110481
+ sqlite3StrAccumAppendAll(&txt, z);
110482
+ sqlite3StrAccumAppend(&txt, ")", 1);
110483
+ }
110915110484
}
110916110485
110917110486
j = i;
110918110487
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
110919110488
char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -110939,11 +110508,14 @@
110939110508
WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
110940110509
int iLevel, /* Value for "level" column of output */
110941110510
int iFrom, /* Value for "from" column of output */
110942110511
u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
110943110512
){
110944
- if( pParse->explain==2 ){
110513
+#ifndef SQLITE_DEBUG
110514
+ if( pParse->explain==2 )
110515
+#endif
110516
+ {
110945110517
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
110946110518
Vdbe *v = pParse->pVdbe; /* VM being constructed */
110947110519
sqlite3 *db = pParse->db; /* Database handle */
110948110520
char *zMsg; /* Text to add to EQP output */
110949110521
int iId = pParse->iSelectId; /* Select id (left-most output column) */
@@ -111045,11 +110617,11 @@
111045110617
iCur = pTabItem->iCursor;
111046110618
pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
111047110619
bRev = (pWInfo->revMask>>iLevel)&1;
111048110620
omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
111049110621
&& (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
111050
- VdbeNoopComment((v, "Begin WHERE-Loop %d: %s", iLevel,pTabItem->pTab->zName));
110622
+ VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
111051110623
111052110624
/* Create labels for the "break" and "continue" instructions
111053110625
** for the current loop. Jump to addrBrk to break out of a loop.
111054110626
** Jump to cont to go immediately to the next iteration of the
111055110627
** loop.
@@ -111272,12 +110844,12 @@
111272110844
static const u8 aEndOp[] = {
111273110845
OP_Noop, /* 0: (!end_constraints) */
111274110846
OP_IdxGE, /* 1: (end_constraints && !bRev) */
111275110847
OP_IdxLT /* 2: (end_constraints && bRev) */
111276110848
};
111277
- int nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111278
- int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
110849
+ u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
110850
+ int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111279110851
int regBase; /* Base register holding constraint values */
111280110852
int r1; /* Temp register */
111281110853
WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111282110854
WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111283110855
int startEq; /* True if range start uses ==, >= or <= */
@@ -111287,14 +110859,15 @@
111287110859
Index *pIdx; /* The index we will be using */
111288110860
int iIdxCur; /* The VDBE cursor for the index */
111289110861
int nExtraReg = 0; /* Number of extra registers needed */
111290110862
int op; /* Instruction opcode */
111291110863
char *zStartAff; /* Affinity for start of range constraint */
111292
- char *zEndAff; /* Affinity for end of range constraint */
110864
+ char cEndAff = 0; /* Affinity for end of range constraint */
111293110865
111294110866
pIdx = pLoop->u.btree.pIndex;
111295110867
iIdxCur = pLevel->iIdxCur;
110868
+ assert( nEq>=pLoop->u.btree.nSkip );
111296110869
111297110870
/* If this loop satisfies a sort order (pOrderBy) request that
111298110871
** was passed to this function to implement a "SELECT min(x) ..."
111299110872
** query, then the caller will only allow the loop to run for
111300110873
** a single iteration. This means that the first row returned
@@ -111304,12 +110877,11 @@
111304110877
*/
111305110878
if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111306110879
&& (pWInfo->bOBSat!=0)
111307110880
&& (pIdx->nKeyCol>nEq)
111308110881
){
111309
- /* assert( pOrderBy->nExpr==1 ); */
111310
- /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
110882
+ assert( pLoop->u.btree.nSkip==0 );
111311110883
isMinQuery = 1;
111312110884
nExtraReg = 1;
111313110885
}
111314110886
111315110887
/* Find any inequality constraint terms for the start and end
@@ -111328,11 +110900,12 @@
111328110900
/* Generate code to evaluate all constraint terms using == or IN
111329110901
** and store the values of those terms in an array of registers
111330110902
** starting at regBase.
111331110903
*/
111332110904
regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
111333
- zEndAff = sqlite3DbStrDup(db, zStartAff);
110905
+ assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
110906
+ if( zStartAff ) cEndAff = zStartAff[nEq];
111334110907
addrNxt = pLevel->addrNxt;
111335110908
111336110909
/* If we are doing a reverse order scan on an ascending index, or
111337110910
** a forward order scan on a descending index, interchange the
111338110911
** start and end terms (pRangeStart and pRangeEnd).
@@ -111398,27 +110971,19 @@
111398110971
sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111399110972
sqlite3ExprCode(pParse, pRight, regBase+nEq);
111400110973
if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111401110974
sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
111402110975
}
111403
- if( zEndAff ){
111404
- if( sqlite3CompareAffinity(pRight, zEndAff[nEq])==SQLITE_AFF_NONE){
111405
- /* Since the comparison is to be performed with no conversions
111406
- ** applied to the operands, set the affinity to apply to pRight to
111407
- ** SQLITE_AFF_NONE. */
111408
- zEndAff[nEq] = SQLITE_AFF_NONE;
111409
- }
111410
- if( sqlite3ExprNeedsNoAffinityChange(pRight, zEndAff[nEq]) ){
111411
- zEndAff[nEq] = SQLITE_AFF_NONE;
111412
- }
111413
- }
111414
- codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
110976
+ if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
110977
+ && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
110978
+ ){
110979
+ codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
110980
+ }
111415110981
nConstraint++;
111416110982
testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
111417110983
}
111418110984
sqlite3DbFree(db, zStartAff);
111419
- sqlite3DbFree(db, zEndAff);
111420110985
111421110986
/* Top of the loop body */
111422110987
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111423110988
111424110989
/* Check if the index cursor is past the end of the range. */
@@ -111436,12 +111001,17 @@
111436111001
** If it is, jump to the next iteration of the loop.
111437111002
*/
111438111003
r1 = sqlite3GetTempReg(pParse);
111439111004
testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111440111005
testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111441
- if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 ){
111006
+ if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111007
+ && (j = pIdx->aiColumn[nEq])>=0
111008
+ && pIdx->pTable->aCol[j].notNull==0
111009
+ && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111010
+ ){
111442111011
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111012
+ VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111443111013
sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111444111014
}
111445111015
sqlite3ReleaseTempReg(pParse, r1);
111446111016
111447111017
/* Seek the table cursor, if required */
@@ -111752,11 +111322,11 @@
111752111322
pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
111753111323
if( pAlt==0 ) continue;
111754111324
if( pAlt->wtFlags & (TERM_CODED) ) continue;
111755111325
testcase( pAlt->eOperator & WO_EQ );
111756111326
testcase( pAlt->eOperator & WO_IN );
111757
- VdbeNoopComment((v, "begin transitive constraint"));
111327
+ VdbeModuleComment((v, "begin transitive constraint"));
111758111328
pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
111759111329
if( pEAlt ){
111760111330
*pEAlt = *pAlt->pExpr;
111761111331
pEAlt->pLeft = pE->pLeft;
111762111332
sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL);
@@ -111852,10 +111422,11 @@
111852111422
int i;
111853111423
Vdbe *v = pWInfo->pParse->pVdbe;
111854111424
sqlite3ExplainBegin(v);
111855111425
for(i=0; i<p->nLTerm; i++){
111856111426
WhereTerm *pTerm = p->aLTerm[i];
111427
+ if( pTerm==0 ) continue;
111857111428
sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111858111429
sqlite3ExplainPush(v);
111859111430
whereExplainTerm(v, pTerm);
111860111431
sqlite3ExplainPop(v);
111861111432
sqlite3ExplainNL(v);
@@ -112135,10 +111706,11 @@
112135111706
if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
112136111707
if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
112137111708
if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
112138111709
for(j=pLoop->nLTerm-1; j>=0; j--){
112139111710
pX = pLoop->aLTerm[j];
111711
+ if( pX==0 ) continue;
112140111712
if( pX==pTerm ) break;
112141111713
if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
112142111714
}
112143111715
if( j<0 ) pLoop->nOut += pTerm->truthProb;
112144111716
}
@@ -112164,11 +111736,12 @@
112164111736
WhereTerm *pTerm; /* A WhereTerm under consideration */
112165111737
int opMask; /* Valid operators for constraints */
112166111738
WhereScan scan; /* Iterator for WHERE terms */
112167111739
Bitmask saved_prereq; /* Original value of pNew->prereq */
112168111740
u16 saved_nLTerm; /* Original value of pNew->nLTerm */
112169
- int saved_nEq; /* Original value of pNew->u.btree.nEq */
111741
+ u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
111742
+ u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
112170111743
u32 saved_wsFlags; /* Original value of pNew->wsFlags */
112171111744
LogEst saved_nOut; /* Original value of pNew->nOut */
112172111745
int iCol; /* Index of the column in the table */
112173111746
int rc = SQLITE_OK; /* Return code */
112174111747
LogEst nRowEst; /* Estimated index selectivity */
@@ -112199,16 +111772,37 @@
112199111772
nRowEst = 0;
112200111773
}
112201111774
pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
112202111775
opMask, pProbe);
112203111776
saved_nEq = pNew->u.btree.nEq;
111777
+ saved_nSkip = pNew->u.btree.nSkip;
112204111778
saved_nLTerm = pNew->nLTerm;
112205111779
saved_wsFlags = pNew->wsFlags;
112206111780
saved_prereq = pNew->prereq;
112207111781
saved_nOut = pNew->nOut;
112208111782
pNew->rSetup = 0;
112209111783
rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0]));
111784
+
111785
+ /* Consider using a skip-scan if there are no WHERE clause constraints
111786
+ ** available for the left-most terms of the index, and if the average
111787
+ ** number of repeats in the left-most terms is at least 18. The magic
111788
+ ** number 18 was found by experimentation to be the payoff point where
111789
+ ** skip-scan become faster than a full-scan.
111790
+ */
111791
+ if( pTerm==0
111792
+ && saved_nEq==saved_nSkip
111793
+ && saved_nEq+1<pProbe->nKeyCol
111794
+ && pProbe->aiRowEst[saved_nEq+1]>=18 /* TUNING: Minimum for skip-scan */
111795
+ ){
111796
+ LogEst nIter;
111797
+ pNew->u.btree.nEq++;
111798
+ pNew->u.btree.nSkip++;
111799
+ pNew->aLTerm[pNew->nLTerm++] = 0;
111800
+ pNew->wsFlags |= WHERE_SKIPSCAN;
111801
+ nIter = sqlite3LogEst(pProbe->aiRowEst[0]/pProbe->aiRowEst[saved_nEq+1]);
111802
+ whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter);
111803
+ }
112210111804
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
112211111805
int nIn = 0;
112212111806
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
112213111807
int nRecValid = pBuilder->nRecValid;
112214111808
#endif
@@ -112240,12 +111834,14 @@
112240111834
}
112241111835
pNew->rRun += nIn;
112242111836
pNew->u.btree.nEq++;
112243111837
pNew->nOut = nRowEst + nInMul + nIn;
112244111838
}else if( pTerm->eOperator & (WO_EQ) ){
112245
- assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
112246
- || nInMul==0 );
111839
+ assert(
111840
+ (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
111841
+ || nInMul==0
111842
+ );
112247111843
pNew->wsFlags |= WHERE_COLUMN_EQ;
112248111844
if( iCol<0
112249111845
|| (pProbe->onError!=OE_None && nInMul==0
112250111846
&& pNew->u.btree.nEq==pProbe->nKeyCol-1)
112251111847
){
@@ -112322,10 +111918,11 @@
112322111918
pBuilder->nRecValid = nRecValid;
112323111919
#endif
112324111920
}
112325111921
pNew->prereq = saved_prereq;
112326111922
pNew->u.btree.nEq = saved_nEq;
111923
+ pNew->u.btree.nSkip = saved_nSkip;
112327111924
pNew->wsFlags = saved_wsFlags;
112328111925
pNew->nOut = saved_nOut;
112329111926
pNew->nLTerm = saved_nLTerm;
112330111927
return rc;
112331111928
}
@@ -112468,10 +112065,11 @@
112468112065
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
112469112066
for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
112470112067
if( pTerm->prereqRight & pNew->maskSelf ) continue;
112471112068
if( termCanDriveIndex(pTerm, pSrc, 0) ){
112472112069
pNew->u.btree.nEq = 1;
112070
+ pNew->u.btree.nSkip = 0;
112473112071
pNew->u.btree.pIndex = 0;
112474112072
pNew->nLTerm = 1;
112475112073
pNew->aLTerm[0] = pTerm;
112476112074
/* TUNING: One-time cost for computing the automatic index is
112477112075
** approximately 7*N*log2(N) where N is the number of rows in
@@ -112497,10 +112095,11 @@
112497112095
if( pProbe->pPartIdxWhere!=0
112498112096
&& !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){
112499112097
continue; /* Partial index inappropriate for this query */
112500112098
}
112501112099
pNew->u.btree.nEq = 0;
112100
+ pNew->u.btree.nSkip = 0;
112502112101
pNew->nLTerm = 0;
112503112102
pNew->iSortIdx = 0;
112504112103
pNew->rSetup = 0;
112505112104
pNew->prereq = mExtra;
112506112105
pNew->nOut = rSize;
@@ -112582,11 +112181,12 @@
112582112181
/*
112583112182
** Add all WhereLoop objects for a table of the join identified by
112584112183
** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
112585112184
*/
112586112185
static int whereLoopAddVirtual(
112587
- WhereLoopBuilder *pBuilder /* WHERE clause information */
112186
+ WhereLoopBuilder *pBuilder, /* WHERE clause information */
112187
+ Bitmask mExtra
112588112188
){
112589112189
WhereInfo *pWInfo; /* WHERE analysis context */
112590112190
Parse *pParse; /* The parsing context */
112591112191
WhereClause *pWC; /* The WHERE clause */
112592112192
struct SrcList_item *pSrc; /* The FROM clause term to search */
@@ -112668,14 +112268,15 @@
112668112268
pIdxInfo->idxStr = 0;
112669112269
pIdxInfo->idxNum = 0;
112670112270
pIdxInfo->needToFreeIdxStr = 0;
112671112271
pIdxInfo->orderByConsumed = 0;
112672112272
pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
112273
+ pIdxInfo->estimatedRows = 25;
112673112274
rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112674112275
if( rc ) goto whereLoopAddVtab_exit;
112675112276
pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112676
- pNew->prereq = 0;
112277
+ pNew->prereq = mExtra;
112677112278
mxTerm = -1;
112678112279
assert( pNew->nLSlot>=nConstraint );
112679112280
for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
112680112281
pNew->u.vtab.omitMask = 0;
112681112282
for(i=0; i<nConstraint; i++, pIdxCons++){
@@ -112727,12 +112328,11 @@
112727112328
pNew->u.vtab.idxStr = pIdxInfo->idxStr;
112728112329
pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0)
112729112330
&& pIdxInfo->orderByConsumed);
112730112331
pNew->rSetup = 0;
112731112332
pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
112732
- /* TUNING: Every virtual table query returns 25 rows */
112733
- pNew->nOut = 46; assert( 46==sqlite3LogEst(25) );
112333
+ pNew->nOut = sqlite3LogEst(pIdxInfo->estimatedRows);
112734112334
whereLoopInsert(pBuilder, pNew);
112735112335
if( pNew->u.vtab.needFree ){
112736112336
sqlite3_free(pNew->u.vtab.idxStr);
112737112337
pNew->u.vtab.needFree = 0;
112738112338
}
@@ -112799,12 +112399,11 @@
112799112399
continue;
112800112400
}
112801112401
sCur.n = 0;
112802112402
#ifndef SQLITE_OMIT_VIRTUALTABLE
112803112403
if( IsVirtual(pItem->pTab) ){
112804
- rc = whereLoopAddVirtual(&sSubBuild);
112805
- for(i=0; i<sCur.n; i++) sCur.a[i].prereq |= mExtra;
112404
+ rc = whereLoopAddVirtual(&sSubBuild, mExtra);
112806112405
}else
112807112406
#endif
112808112407
{
112809112408
rc = whereLoopAddBtree(&sSubBuild, mExtra);
112810112409
}
@@ -112870,11 +112469,11 @@
112870112469
if( ((pItem->jointype|priorJoinType) & (JT_LEFT|JT_CROSS))!=0 ){
112871112470
mExtra = mPrior;
112872112471
}
112873112472
priorJoinType = pItem->jointype;
112874112473
if( IsVirtual(pItem->pTab) ){
112875
- rc = whereLoopAddVirtual(pBuilder);
112474
+ rc = whereLoopAddVirtual(pBuilder, mExtra);
112876112475
}else{
112877112476
rc = whereLoopAddBtree(pBuilder, mExtra);
112878112477
}
112879112478
if( rc==SQLITE_OK ){
112880112479
rc = whereLoopAddOr(pBuilder, mExtra);
@@ -113031,10 +112630,11 @@
113031112630
for(j=0; j<nColumn; j++){
113032112631
u8 bOnce; /* True to run the ORDER BY search loop */
113033112632
113034112633
/* Skip over == and IS NULL terms */
113035112634
if( j<pLoop->u.btree.nEq
112635
+ && pLoop->u.btree.nSkip==0
113036112636
&& ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
113037112637
){
113038112638
if( i & WO_ISNULL ){
113039112639
testcase( isOrderDistinct );
113040112640
isOrderDistinct = 0;
@@ -113456,10 +113056,11 @@
113456113056
if( pItem->zIndex ) return 0;
113457113057
iCur = pItem->iCursor;
113458113058
pWC = &pWInfo->sWC;
113459113059
pLoop = pBuilder->pNew;
113460113060
pLoop->wsFlags = 0;
113061
+ pLoop->u.btree.nSkip = 0;
113461113062
pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
113462113063
if( pTerm ){
113463113064
pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
113464113065
pLoop->aLTerm[0] = pTerm;
113465113066
pLoop->nLTerm = 1;
@@ -113684,11 +113285,10 @@
113684113285
/* Split the WHERE clause into separate subexpressions where each
113685113286
** subexpression is separated by an AND operator.
113686113287
*/
113687113288
initMaskSet(pMaskSet);
113688113289
whereClauseInit(&pWInfo->sWC, pWInfo);
113689
- sqlite3ExprCodeConstants(pParse, pWhere);
113690113290
whereSplit(&pWInfo->sWC, pWhere, TK_AND);
113691113291
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113692113292
113693113293
/* Special case: a WHERE clause that is constant. Evaluate the
113694113294
** expression and either jump over all of the code or fall thru.
@@ -113999,10 +113599,11 @@
113999113599
notReady = codeOneLoopStart(pWInfo, ii, notReady);
114000113600
pWInfo->iContinue = pLevel->addrCont;
114001113601
}
114002113602
114003113603
/* Done. */
113604
+ VdbeModuleComment((v, "Begin WHERE-core"));
114004113605
return pWInfo;
114005113606
114006113607
/* Jump here if malloc fails */
114007113608
whereBeginError:
114008113609
if( pWInfo ){
@@ -114025,12 +113626,14 @@
114025113626
SrcList *pTabList = pWInfo->pTabList;
114026113627
sqlite3 *db = pParse->db;
114027113628
114028113629
/* Generate loop termination code.
114029113630
*/
113631
+ VdbeModuleComment((v, "End WHERE-core"));
114030113632
sqlite3ExprCacheClear(pParse);
114031113633
for(i=pWInfo->nLevel-1; i>=0; i--){
113634
+ int addr;
114032113635
pLevel = &pWInfo->a[i];
114033113636
pLoop = pLevel->pWLoop;
114034113637
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114035113638
if( pLevel->op!=OP_Noop ){
114036113639
sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
@@ -114046,12 +113649,17 @@
114046113649
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114047113650
}
114048113651
sqlite3DbFree(db, pLevel->u.in.aInLoop);
114049113652
}
114050113653
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
113654
+ if( pLevel->addrSkip ){
113655
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
113656
+ VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
113657
+ sqlite3VdbeJumpHere(v, pLevel->addrSkip);
113658
+ sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
113659
+ }
114051113660
if( pLevel->iLeftJoin ){
114052
- int addr;
114053113661
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114054113662
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114055113663
|| (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114056113664
if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114057113665
sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
@@ -114064,11 +113672,11 @@
114064113672
}else{
114065113673
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
114066113674
}
114067113675
sqlite3VdbeJumpHere(v, addr);
114068113676
}
114069
- VdbeNoopComment((v, "End WHERE-Loop %d: %s", i,
113677
+ VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
114070113678
pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
114071113679
}
114072113680
114073113681
/* The "break" point is here, just past the end of the outer loop.
114074113682
** Set it.
@@ -116923,16 +116531,11 @@
116923116531
spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
116924116532
}
116925116533
break;
116926116534
case 200: /* term ::= CTIME_KW */
116927116535
{
116928
- /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
116929
- ** treated as functions that return constants */
116930
- yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
116931
- if( yygotominor.yy118.pExpr ){
116932
- yygotominor.yy118.pExpr->op = TK_CONST_FUNC;
116933
- }
116536
+ yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
116934116537
spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116935116538
}
116936116539
break;
116937116540
case 201: /* expr ::= expr AND expr */
116938116541
case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
@@ -119357,10 +118960,17 @@
119357118960
if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
119358118961
if( szMmap>mxMmap) szMmap = mxMmap;
119359118962
sqlite3GlobalConfig.szMmap = szMmap;
119360118963
break;
119361118964
}
118965
+
118966
+#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC)
118967
+ case SQLITE_CONFIG_WIN32_HEAPSIZE: {
118968
+ sqlite3GlobalConfig.nHeap = va_arg(ap, int);
118969
+ break;
118970
+ }
118971
+#endif
119362118972
119363118973
default: {
119364118974
rc = SQLITE_ERROR;
119365118975
break;
119366118976
}
@@ -119424,11 +119034,12 @@
119424119034
}
119425119035
db->lookaside.pEnd = p;
119426119036
db->lookaside.bEnabled = 1;
119427119037
db->lookaside.bMalloced = pBuf==0 ?1:0;
119428119038
}else{
119429
- db->lookaside.pEnd = 0;
119039
+ db->lookaside.pStart = db;
119040
+ db->lookaside.pEnd = db;
119430119041
db->lookaside.bEnabled = 0;
119431119042
db->lookaside.bMalloced = 0;
119432119043
}
119433119044
return SQLITE_OK;
119434119045
}
@@ -119922,10 +119533,11 @@
119922119533
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
119923119534
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
119924119535
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
119925119536
case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
119926119537
case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
119538
+ case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
119927119539
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
119928119540
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
119929119541
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
119930119542
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
119931119543
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -122132,10 +121744,23 @@
122132121744
*pzRet = sqlite3VdbeExplanation((Vdbe*)pStmt);
122133121745
break;
122134121746
}
122135121747
#endif
122136121748
121749
+ /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
121750
+ **
121751
+ ** Set or clear a flag that indicates that the database file is always well-
121752
+ ** formed and never corrupt. This flag is clear by default, indicating that
121753
+ ** database files might have arbitrary corruption. Setting the flag during
121754
+ ** testing causes certain assert() statements in the code to be activated
121755
+ ** that demonstrat invariants on well-formed database files.
121756
+ */
121757
+ case SQLITE_TESTCTRL_NEVER_CORRUPT: {
121758
+ sqlite3Config.neverCorrupt = va_arg(ap, int);
121759
+ break;
121760
+ }
121761
+
122137121762
}
122138121763
va_end(ap);
122139121764
#endif /* SQLITE_OMIT_BUILTIN_TEST */
122140121765
return rc;
122141121766
}
@@ -123649,10 +123274,14 @@
123649123274
char *aDoclist; /* Pointer to doclist buffer */
123650123275
int nDoclist; /* Size of aDoclist[] in bytes */
123651123276
};
123652123277
123653123278
SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
123279
+
123280
+#define fts3GetVarint32(p, piVal) ( \
123281
+ (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
123282
+)
123654123283
123655123284
/* fts3.c */
123656123285
SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
123657123286
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
123658123287
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
@@ -123757,36 +123386,63 @@
123757123386
q[-1] &= 0x7f; /* turn off high bit in final byte */
123758123387
assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
123759123388
return (int) (q - (unsigned char *)p);
123760123389
}
123761123390
123391
+#define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
123392
+ v = (v & mask1) | ( (*ptr++) << shift ); \
123393
+ if( (v & mask2)==0 ){ var = v; return ret; }
123394
+#define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
123395
+ v = (*ptr++); \
123396
+ if( (v & mask2)==0 ){ var = v; return ret; }
123397
+
123762123398
/*
123763123399
** Read a 64-bit variable-length integer from memory starting at p[0].
123764123400
** Return the number of bytes read, or 0 on error.
123765123401
** The value is stored in *v.
123766123402
*/
123767123403
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
123768
- const unsigned char *q = (const unsigned char *) p;
123769
- sqlite_uint64 x = 0, y = 1;
123770
- while( (*q&0x80)==0x80 && q-(unsigned char *)p<FTS3_VARINT_MAX ){
123771
- x += y * (*q++ & 0x7f);
123772
- y <<= 7;
123773
- }
123774
- x += y * (*q++);
123775
- *v = (sqlite_int64) x;
123776
- return (int) (q - (unsigned char *)p);
123404
+ const char *pStart = p;
123405
+ u32 a;
123406
+ u64 b;
123407
+ int shift;
123408
+
123409
+ GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
123410
+ GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *v, 2);
123411
+ GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *v, 3);
123412
+ GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *v, 4);
123413
+ b = (a & 0x0FFFFFFF );
123414
+
123415
+ for(shift=28; shift<=63; shift+=7){
123416
+ u64 c = *p++;
123417
+ b += (c&0x7F) << shift;
123418
+ if( (c & 0x80)==0 ) break;
123419
+ }
123420
+ *v = b;
123421
+ return (int)(p - pStart);
123777123422
}
123778123423
123779123424
/*
123780123425
** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
123781123426
** 32-bit integer before it is returned.
123782123427
*/
123783123428
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
123784
- sqlite_int64 i;
123785
- int ret = sqlite3Fts3GetVarint(p, &i);
123786
- *pi = (int) i;
123787
- return ret;
123429
+ u32 a;
123430
+
123431
+#ifndef fts3GetVarint32
123432
+ GETVARINT_INIT(a, p, 0, 0x00, 0x80, *pi, 1);
123433
+#else
123434
+ a = (*p++);
123435
+ assert( a & 0x80 );
123436
+#endif
123437
+
123438
+ GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
123439
+ GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
123440
+ GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
123441
+ a = (a & 0x0FFFFFFF );
123442
+ *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
123443
+ return 5;
123788123444
}
123789123445
123790123446
/*
123791123447
** Return the number of bytes required to encode v as a varint
123792123448
*/
@@ -125142,14 +124798,14 @@
125142124798
int nBuffer; /* Total term size */
125143124799
125144124800
/* Load the next term on the node into zBuffer. Use realloc() to expand
125145124801
** the size of zBuffer if required. */
125146124802
if( !isFirstTerm ){
125147
- zCsr += sqlite3Fts3GetVarint32(zCsr, &nPrefix);
124803
+ zCsr += fts3GetVarint32(zCsr, &nPrefix);
125148124804
}
125149124805
isFirstTerm = 0;
125150
- zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
124806
+ zCsr += fts3GetVarint32(zCsr, &nSuffix);
125151124807
125152124808
if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
125153124809
rc = FTS_CORRUPT_VTAB;
125154124810
goto finish_scan;
125155124811
}
@@ -125233,11 +124889,11 @@
125233124889
int rc; /* Return code */
125234124890
int iHeight; /* Height of this node in tree */
125235124891
125236124892
assert( piLeaf || piLeaf2 );
125237124893
125238
- sqlite3Fts3GetVarint32(zNode, &iHeight);
124894
+ fts3GetVarint32(zNode, &iHeight);
125239124895
rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
125240124896
assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
125241124897
125242124898
if( rc==SQLITE_OK && iHeight>1 ){
125243124899
char *zBlob = 0; /* Blob read from %_segments table */
@@ -125435,15 +125091,15 @@
125435125091
125436125092
while( *p1 || *p2 ){
125437125093
int iCol1; /* The current column index in pp1 */
125438125094
int iCol2; /* The current column index in pp2 */
125439125095
125440
- if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
125096
+ if( *p1==POS_COLUMN ) fts3GetVarint32(&p1[1], &iCol1);
125441125097
else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
125442125098
else iCol1 = 0;
125443125099
125444
- if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
125100
+ if( *p2==POS_COLUMN ) fts3GetVarint32(&p2[1], &iCol2);
125445125101
else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
125446125102
else iCol2 = 0;
125447125103
125448125104
if( iCol1==iCol2 ){
125449125105
sqlite3_int64 i1 = 0; /* Last position from pp1 */
@@ -125532,15 +125188,15 @@
125532125188
assert( isSaveLeft==0 || isExact==0 );
125533125189
125534125190
assert( p!=0 && *p1!=0 && *p2!=0 );
125535125191
if( *p1==POS_COLUMN ){
125536125192
p1++;
125537
- p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125193
+ p1 += fts3GetVarint32(p1, &iCol1);
125538125194
}
125539125195
if( *p2==POS_COLUMN ){
125540125196
p2++;
125541
- p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125197
+ p2 += fts3GetVarint32(p2, &iCol2);
125542125198
}
125543125199
125544125200
while( 1 ){
125545125201
if( iCol1==iCol2 ){
125546125202
char *pSave = p;
@@ -125586,13 +125242,13 @@
125586125242
fts3ColumnlistCopy(0, &p2);
125587125243
assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
125588125244
if( 0==*p1 || 0==*p2 ) break;
125589125245
125590125246
p1++;
125591
- p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125247
+ p1 += fts3GetVarint32(p1, &iCol1);
125592125248
p2++;
125593
- p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125249
+ p2 += fts3GetVarint32(p2, &iCol2);
125594125250
}
125595125251
125596125252
/* Advance pointer p1 or p2 (whichever corresponds to the smaller of
125597125253
** iCol1 and iCol2) so that it points to either the 0x00 that marks the
125598125254
** end of the position list, or the 0x01 that precedes the next
@@ -125600,16 +125256,16 @@
125600125256
*/
125601125257
else if( iCol1<iCol2 ){
125602125258
fts3ColumnlistCopy(0, &p1);
125603125259
if( 0==*p1 ) break;
125604125260
p1++;
125605
- p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125261
+ p1 += fts3GetVarint32(p1, &iCol1);
125606125262
}else{
125607125263
fts3ColumnlistCopy(0, &p2);
125608125264
if( 0==*p2 ) break;
125609125265
p2++;
125610
- p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125266
+ p2 += fts3GetVarint32(p2, &iCol2);
125611125267
}
125612125268
}
125613125269
125614125270
fts3PoslistCopy(0, &p2);
125615125271
fts3PoslistCopy(0, &p1);
@@ -128772,11 +128428,11 @@
128772128428
*/
128773128429
pExpr->aMI[iCol*3 + 1] += iCnt;
128774128430
pExpr->aMI[iCol*3 + 2] += (iCnt>0);
128775128431
if( *p==0x00 ) break;
128776128432
p++;
128777
- p += sqlite3Fts3GetVarint32(p, &iCol);
128433
+ p += fts3GetVarint32(p, &iCol);
128778128434
}
128779128435
}
128780128436
128781128437
fts3EvalUpdateCounts(pExpr->pLeft);
128782128438
fts3EvalUpdateCounts(pExpr->pRight);
@@ -129073,19 +128729,19 @@
129073128729
}
129074128730
if( pIter==0 ) return SQLITE_OK;
129075128731
129076128732
if( *pIter==0x01 ){
129077128733
pIter++;
129078
- pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
128734
+ pIter += fts3GetVarint32(pIter, &iThis);
129079128735
}else{
129080128736
iThis = 0;
129081128737
}
129082128738
while( iThis<iCol ){
129083128739
fts3ColumnlistCopy(0, &pIter);
129084128740
if( *pIter==0x00 ) return 0;
129085128741
pIter++;
129086
- pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
128742
+ pIter += fts3GetVarint32(pIter, &iThis);
129087128743
}
129088128744
129089128745
*ppOut = ((iCol==iThis)?pIter:0);
129090128746
return SQLITE_OK;
129091128747
}
@@ -134530,12 +134186,12 @@
134530134186
rc = fts3SegReaderRequire(pReader, pNext, FTS3_VARINT_MAX*2);
134531134187
if( rc!=SQLITE_OK ) return rc;
134532134188
134533134189
/* Because of the FTS3_NODE_PADDING bytes of padding, the following is
134534134190
** safe (no risk of overread) even if the node data is corrupted. */
134535
- pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
134536
- pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
134191
+ pNext += fts3GetVarint32(pNext, &nPrefix);
134192
+ pNext += fts3GetVarint32(pNext, &nSuffix);
134537134193
if( nPrefix<0 || nSuffix<=0
134538134194
|| &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
134539134195
){
134540134196
return FTS_CORRUPT_VTAB;
134541134197
}
@@ -134554,11 +134210,11 @@
134554134210
if( rc!=SQLITE_OK ) return rc;
134555134211
134556134212
memcpy(&pReader->zTerm[nPrefix], pNext, nSuffix);
134557134213
pReader->nTerm = nPrefix+nSuffix;
134558134214
pNext += nSuffix;
134559
- pNext += sqlite3Fts3GetVarint32(pNext, &pReader->nDoclist);
134215
+ pNext += fts3GetVarint32(pNext, &pReader->nDoclist);
134560134216
pReader->aDoclist = pNext;
134561134217
pReader->pOffsetList = 0;
134562134218
134563134219
/* Check that the doclist does not appear to extend past the end of the
134564134220
** b-tree node. And that the final byte of the doclist is 0x00. If either
@@ -135715,11 +135371,11 @@
135715135371
pList = p;
135716135372
if( nList==0 ){
135717135373
break;
135718135374
}
135719135375
p = &pList[1];
135720
- p += sqlite3Fts3GetVarint32(p, &iCurrent);
135376
+ p += fts3GetVarint32(p, &iCurrent);
135721135377
}
135722135378
135723135379
if( bZero && &pList[nList]!=pEnd ){
135724135380
memset(&pList[nList], 0, pEnd - &pList[nList]);
135725135381
}
@@ -136680,21 +136336,21 @@
136680136336
if( p->iOff>=p->nNode ){
136681136337
/* EOF */
136682136338
p->aNode = 0;
136683136339
}else{
136684136340
if( bFirst==0 ){
136685
- p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136341
+ p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136686136342
}
136687
- p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136343
+ p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136688136344
136689136345
blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
136690136346
if( rc==SQLITE_OK ){
136691136347
memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
136692136348
p->term.n = nPrefix+nSuffix;
136693136349
p->iOff += nSuffix;
136694136350
if( p->iChild==0 ){
136695
- p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136351
+ p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136696136352
p->aDoclist = &p->aNode[p->iOff];
136697136353
p->iOff += p->nDoclist;
136698136354
}
136699136355
}
136700136356
}
@@ -137742,11 +137398,11 @@
137742137398
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137743137399
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137744137400
137745137401
pHint->n = i;
137746137402
i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
137747
- i += sqlite3Fts3GetVarint32(&pHint->a[i], pnInput);
137403
+ i += fts3GetVarint32(&pHint->a[i], pnInput);
137748137404
if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
137749137405
137750137406
return SQLITE_OK;
137751137407
}
137752137408
@@ -138735,11 +138391,11 @@
138735138391
** After it returns, *piPos contains the value of the next element of the
138736138392
** list and *pp is advanced to the following varint.
138737138393
*/
138738138394
static void fts3GetDeltaPosition(char **pp, int *piPos){
138739138395
int iVal;
138740
- *pp += sqlite3Fts3GetVarint32(*pp, &iVal);
138396
+ *pp += fts3GetVarint32(*pp, &iVal);
138741138397
*piPos += (iVal-2);
138742138398
}
138743138399
138744138400
/*
138745138401
** Helper function for fts3ExprIterate() (see below).
@@ -141028,10 +140684,20 @@
141028140684
** ever contain very many entries, so a fixed number of buckets is
141029140685
** used.
141030140686
*/
141031140687
#define HASHSIZE 128
141032140688
140689
+/* The xBestIndex method of this virtual table requires an estimate of
140690
+** the number of rows in the virtual table to calculate the costs of
140691
+** various strategies. If possible, this estimate is loaded from the
140692
+** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
140693
+** Otherwise, if no sqlite_stat1 entry is available, use
140694
+** RTREE_DEFAULT_ROWEST.
140695
+*/
140696
+#define RTREE_DEFAULT_ROWEST 1048576
140697
+#define RTREE_MIN_ROWEST 100
140698
+
141033140699
/*
141034140700
** An rtree virtual-table object.
141035140701
*/
141036140702
struct Rtree {
141037140703
sqlite3_vtab base;
@@ -141042,10 +140708,11 @@
141042140708
int iDepth; /* Current depth of the r-tree structure */
141043140709
char *zDb; /* Name of database containing r-tree table */
141044140710
char *zName; /* Name of r-tree table */
141045140711
RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
141046140712
int nBusy; /* Current number of users of this structure */
140713
+ i64 nRowEst; /* Estimated number of rows in this table */
141047140714
141048140715
/* List of nodes removed during a CondenseTree operation. List is
141049140716
** linked together via the pointer normally used for hash chains -
141050140717
** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
141051140718
** headed by the node (leaf nodes have RtreeNode.iNode==0).
@@ -142233,10 +141900,23 @@
142233141900
}
142234141901
142235141902
rtreeRelease(pRtree);
142236141903
return rc;
142237141904
}
141905
+
141906
+/*
141907
+** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
141908
+** extension is currently being used by a version of SQLite too old to
141909
+** support estimatedRows. In that case this function is a no-op.
141910
+*/
141911
+static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
141912
+#if SQLITE_VERSION_NUMBER>=3008002
141913
+ if( sqlite3_libversion_number()>=3008002 ){
141914
+ pIdxInfo->estimatedRows = nRow;
141915
+ }
141916
+#endif
141917
+}
142238141918
142239141919
/*
142240141920
** Rtree virtual table module xBestIndex method. There are three
142241141921
** table scan strategies to choose from (in order from most to
142242141922
** least desirable):
@@ -142269,17 +141949,18 @@
142269141949
** The second of each pair of bytes identifies the coordinate column
142270141950
** to which the constraint applies. The leftmost coordinate column
142271141951
** is 'a', the second from the left 'b' etc.
142272141952
*/
142273141953
static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
141954
+ Rtree *pRtree = (Rtree*)tab;
142274141955
int rc = SQLITE_OK;
142275141956
int ii;
141957
+ i64 nRow; /* Estimated rows returned by this scan */
142276141958
142277141959
int iIdx = 0;
142278141960
char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
142279141961
memset(zIdxStr, 0, sizeof(zIdxStr));
142280
- UNUSED_PARAMETER(tab);
142281141962
142282141963
assert( pIdxInfo->idxStr==0 );
142283141964
for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
142284141965
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
142285141966
@@ -142295,13 +141976,15 @@
142295141976
pIdxInfo->aConstraintUsage[jj].omit = 1;
142296141977
142297141978
/* This strategy involves a two rowid lookups on an B-Tree structures
142298141979
** and then a linear search of an R-Tree node. This should be
142299141980
** considered almost as quick as a direct rowid lookup (for which
142300
- ** sqlite uses an internal cost of 0.0).
141981
+ ** sqlite uses an internal cost of 0.0). It is expected to return
141982
+ ** a single row.
142301141983
*/
142302
- pIdxInfo->estimatedCost = 10.0;
141984
+ pIdxInfo->estimatedCost = 30.0;
141985
+ setEstimatedRows(pIdxInfo, 1);
142303141986
return SQLITE_OK;
142304141987
}
142305141988
142306141989
if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
142307141990
u8 op;
@@ -142326,12 +142009,15 @@
142326142009
pIdxInfo->idxNum = 2;
142327142010
pIdxInfo->needToFreeIdxStr = 1;
142328142011
if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
142329142012
return SQLITE_NOMEM;
142330142013
}
142331
- assert( iIdx>=0 );
142332
- pIdxInfo->estimatedCost = (2000000.0 / (double)(iIdx + 1));
142014
+
142015
+ nRow = pRtree->nRowEst / (iIdx + 1);
142016
+ pIdxInfo->estimatedCost = (double)6.0 * (double)nRow;
142017
+ setEstimatedRows(pIdxInfo, nRow);
142018
+
142333142019
return rc;
142334142020
}
142335142021
142336142022
/*
142337142023
** Return the N-dimensional volumn of the cell stored in *p.
@@ -143801,10 +143487,41 @@
143801143487
rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
143802143488
sqlite3_free(zSql);
143803143489
}
143804143490
return rc;
143805143491
}
143492
+
143493
+/*
143494
+** This function populates the pRtree->nRowEst variable with an estimate
143495
+** of the number of rows in the virtual table. If possible, this is based
143496
+** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
143497
+*/
143498
+static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
143499
+ const char *zSql = "SELECT stat FROM sqlite_stat1 WHERE tbl= ? || '_rowid'";
143500
+ sqlite3_stmt *p;
143501
+ int rc;
143502
+ i64 nRow = 0;
143503
+
143504
+ rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
143505
+ if( rc==SQLITE_OK ){
143506
+ sqlite3_bind_text(p, 1, pRtree->zName, -1, SQLITE_STATIC);
143507
+ if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
143508
+ rc = sqlite3_finalize(p);
143509
+ }else if( rc!=SQLITE_NOMEM ){
143510
+ rc = SQLITE_OK;
143511
+ }
143512
+
143513
+ if( rc==SQLITE_OK ){
143514
+ if( nRow==0 ){
143515
+ pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
143516
+ }else{
143517
+ pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
143518
+ }
143519
+ }
143520
+
143521
+ return rc;
143522
+}
143806143523
143807143524
static sqlite3_module rtreeModule = {
143808143525
0, /* iVersion */
143809143526
rtreeCreate, /* xCreate - create a table */
143810143527
rtreeConnect, /* xConnect - connect to an existing table */
@@ -143887,10 +143604,11 @@
143887143604
appStmt[5] = &pRtree->pDeleteRowid;
143888143605
appStmt[6] = &pRtree->pReadParent;
143889143606
appStmt[7] = &pRtree->pWriteParent;
143890143607
appStmt[8] = &pRtree->pDeleteParent;
143891143608
143609
+ rc = rtreeQueryStat1(db, pRtree);
143892143610
for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
143893143611
char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
143894143612
if( zSql ){
143895143613
rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
143896143614
}else{
143897143615
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -396,11 +396,11 @@
396 ** Restrictions:
397 **
398 ** <ul>
399 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
400 ** is a valid and open [database connection].
401 ** <li> The application must not close [database connection] specified by
402 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
403 ** <li> The application must not modify the SQL statement text passed into
404 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
405 ** </ul>
406 */
@@ -473,11 +473,11 @@
473 ** about errors. The extended result codes are enabled or disabled
474 ** on a per database connection basis using the
475 ** [sqlite3_extended_result_codes()] API.
476 **
477 ** Some of the available extended result codes are listed here.
478 ** One may expect the number of extended result codes will be expand
479 ** over time. Software that uses extended result codes should expect
480 ** to see new result codes in future releases of SQLite.
481 **
482 ** The SQLITE_OK result code will never be extended. It will always
483 ** be exactly zero.
@@ -517,10 +517,11 @@
517 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
 
522 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
523 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
524 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
525 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
526 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -584,11 +585,12 @@
584 ** information is written to disk in the same order as calls
585 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
586 ** after reboot following a crash or power loss, the only bytes in a
587 ** file that were written at the application level might have changed
588 ** and that adjacent bytes, even bytes within the same sector are
589 ** guaranteed to be unchanged.
 
590 */
591 #define SQLITE_IOCAP_ATOMIC 0x00000001
592 #define SQLITE_IOCAP_ATOMIC512 0x00000002
593 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
594 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -947,10 +949,16 @@
947 ** This file control is used by some VFS activity tracing [shims].
948 ** The argument is a zero-terminated string. Higher layers in the
949 ** SQLite stack may generate instances of this file control if
950 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
951 **
 
 
 
 
 
 
952 ** </ul>
953 */
954 #define SQLITE_FCNTL_LOCKSTATE 1
955 #define SQLITE_GET_LOCKPROXYFILE 2
956 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -967,10 +975,11 @@
967 #define SQLITE_FCNTL_PRAGMA 14
968 #define SQLITE_FCNTL_BUSYHANDLER 15
969 #define SQLITE_FCNTL_TEMPFILENAME 16
970 #define SQLITE_FCNTL_MMAP_SIZE 18
971 #define SQLITE_FCNTL_TRACE 19
 
972
973 /*
974 ** CAPI3REF: Mutex Handle
975 **
976 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1411,11 +1420,11 @@
1411 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1412 ** Every memory allocation request coming in through [sqlite3_malloc()]
1413 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1414 ** that causes the corresponding memory allocation to fail.
1415 **
1416 ** The xInit method initializes the memory allocator. (For example,
1417 ** it might allocate any require mutexes or initialize internal data
1418 ** structures. The xShutdown method is invoked (indirectly) by
1419 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1420 ** by xInit. The pAppData pointer is used as the only parameter to
1421 ** xInit and xShutdown.
@@ -1713,10 +1722,17 @@
1713 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1714 ** exceed the compile-time maximum mmap size set by the
1715 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1716 ** ^If either argument to this option is negative, then that argument is
1717 ** changed to its compile-time default.
 
 
 
 
 
 
 
1718 ** </dl>
1719 */
1720 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1721 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1722 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1737,10 +1753,11 @@
1737 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
1738 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1739 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1740 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1741 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
 
1742
1743 /*
1744 ** CAPI3REF: Database Connection Configuration Options
1745 **
1746 ** These constants are the available integer configuration options that
@@ -3137,11 +3154,10 @@
3137 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3138 ** ^The specific value of WHERE-clause [parameter] might influence the
3139 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3140 ** or [GLOB] operator or if the parameter is compared to an indexed column
3141 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3142 ** the
3143 ** </li>
3144 ** </ol>
3145 */
3146 SQLITE_API int sqlite3_prepare(
3147 sqlite3 *db, /* Database handle */
@@ -3799,23 +3815,23 @@
3799 ** <table border="1">
3800 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
3801 **
3802 ** <tr><td> NULL <td> INTEGER <td> Result is 0
3803 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3804 ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
3805 ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
3806 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
3807 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
3808 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3809 ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
3810 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3811 ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
3812 ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
3813 ** <tr><td> TEXT <td> FLOAT <td> Use atof()
3814 ** <tr><td> TEXT <td> BLOB <td> No change
3815 ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
3816 ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
3817 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
3818 ** </table>
3819 ** </blockquote>)^
3820 **
3821 ** The table above makes reference to standard C library functions atoi()
@@ -3867,11 +3883,11 @@
3867 **
3868 ** ^The pointers returned are valid until a type conversion occurs as
3869 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3870 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3871 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3872 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3873 ** [sqlite3_free()].
3874 **
3875 ** ^(If a memory allocation error occurs during the evaluation of any
3876 ** of these routines, a default value is returned. The default value
3877 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4945,12 +4961,12 @@
4945 /*
4946 ** CAPI3REF: Free Memory Used By A Database Connection
4947 **
4948 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4949 ** memory as possible from database connection D. Unlike the
4950 ** [sqlite3_release_memory()] interface, this interface is effect even
4951 ** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4952 ** omitted.
4953 **
4954 ** See also: [sqlite3_release_memory()]
4955 */
4956 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -5321,14 +5337,26 @@
5321 **
5322 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5323 ** the correct order to satisfy the ORDER BY clause so that no separate
5324 ** sorting step is required.
5325 **
5326 ** ^The estimatedCost value is an estimate of the cost of doing the
5327 ** particular lookup. A full scan of a table with N entries should have
5328 ** a cost of N. A binary search of a table of N entries should have a
5329 ** cost of approximately log(N).
 
 
 
 
 
 
 
 
 
 
 
 
5330 */
5331 struct sqlite3_index_info {
5332 /* Inputs */
5333 int nConstraint; /* Number of entries in aConstraint */
5334 struct sqlite3_index_constraint {
@@ -5349,11 +5377,13 @@
5349 } *aConstraintUsage;
5350 int idxNum; /* Number used to identify the index */
5351 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5352 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5353 int orderByConsumed; /* True if output is already ordered */
5354 double estimatedCost; /* Estimated cost of using this index */
 
 
5355 };
5356
5357 /*
5358 ** CAPI3REF: Virtual Table Constraint Operator Codes
5359 **
@@ -6079,11 +6109,12 @@
6079 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6080 #define SQLITE_TESTCTRL_ISKEYWORD 16
6081 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6082 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6083 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6084 #define SQLITE_TESTCTRL_LAST 19
 
6085
6086 /*
6087 ** CAPI3REF: SQLite Runtime Status
6088 **
6089 ** ^This interface is used to retrieve runtime status information
@@ -8127,13 +8158,12 @@
8127 #define TK_UNCLOSED_STRING 151
8128 #define TK_FUNCTION 152
8129 #define TK_COLUMN 153
8130 #define TK_AGG_FUNCTION 154
8131 #define TK_AGG_COLUMN 155
8132 #define TK_CONST_FUNC 156
8133 #define TK_UMINUS 157
8134 #define TK_UPLUS 158
8135
8136 /************** End of parse.h ***********************************************/
8137 /************** Continuing where we left off in sqliteInt.h ******************/
8138 #include <stdio.h>
8139 #include <stdlib.h>
@@ -8765,12 +8795,12 @@
8765 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
8766 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
8767 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
8768 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
8769 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8770 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
8771 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
8772 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8773 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8774 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8775 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
8776
@@ -9008,155 +9038,157 @@
9008 #define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
9009 #define OP_Savepoint 2
9010 #define OP_AutoCommit 3
9011 #define OP_Transaction 4
9012 #define OP_SorterNext 5
9013 #define OP_Prev 6
9014 #define OP_Next 7
9015 #define OP_AggStep 8 /* synopsis: accum=r[P3] step(r[P2@P5]) */
9016 #define OP_Checkpoint 9
9017 #define OP_JournalMode 10
9018 #define OP_Vacuum 11
9019 #define OP_VFilter 12 /* synopsis: iPlan=r[P3] zPlan='P4' */
9020 #define OP_VUpdate 13 /* synopsis: data=r[P3@P2] */
9021 #define OP_Goto 14
9022 #define OP_Gosub 15
9023 #define OP_Return 16
9024 #define OP_Yield 17
9025 #define OP_HaltIfNull 18 /* synopsis: if r[P3] null then halt */
9026 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9027 #define OP_Halt 20
9028 #define OP_Integer 21 /* synopsis: r[P2]=P1 */
9029 #define OP_Int64 22 /* synopsis: r[P2]=P4 */
9030 #define OP_String 23 /* synopsis: r[P2]='P4' (len=P1) */
9031 #define OP_Null 24 /* synopsis: r[P2..P3]=NULL */
9032 #define OP_Blob 25 /* synopsis: r[P2]=P4 (len=P1) */
9033 #define OP_Variable 26 /* synopsis: r[P2]=parameter(P1,P4) */
9034 #define OP_Move 27 /* synopsis: r[P2@P3]=r[P1@P3] */
9035 #define OP_Copy 28 /* synopsis: r[P2@P3]=r[P1@P3] */
9036 #define OP_SCopy 29 /* synopsis: r[P2]=r[P1] */
9037 #define OP_ResultRow 30 /* synopsis: output=r[P1@P2] */
9038 #define OP_CollSeq 31
9039 #define OP_AddImm 32 /* synopsis: r[P1]=r[P1]+P2 */
9040 #define OP_MustBeInt 33
9041 #define OP_RealAffinity 34
9042 #define OP_Permutation 35
9043 #define OP_Compare 36
9044 #define OP_Jump 37
9045 #define OP_Once 38
9046 #define OP_If 39
9047 #define OP_IfNot 40
9048 #define OP_Column 41 /* synopsis: r[P3]=PX */
9049 #define OP_Affinity 42 /* synopsis: affinity(r[P1@P2]) */
9050 #define OP_MakeRecord 43 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9051 #define OP_Count 44 /* synopsis: r[P2]=count() */
9052 #define OP_ReadCookie 45
9053 #define OP_SetCookie 46
9054 #define OP_VerifyCookie 47
9055 #define OP_OpenRead 48 /* synopsis: root=P2 iDb=P3 */
9056 #define OP_OpenWrite 49 /* synopsis: root=P2 iDb=P3 */
9057 #define OP_OpenAutoindex 50 /* synopsis: nColumn=P2 */
9058 #define OP_OpenEphemeral 51 /* synopsis: nColumn=P2 */
9059 #define OP_SorterOpen 52
9060 #define OP_OpenPseudo 53 /* synopsis: content in r[P2@P3] */
9061 #define OP_Close 54
9062 #define OP_SeekLt 55 /* synopsis: key=r[P3@P4] */
9063 #define OP_SeekLe 56 /* synopsis: key=r[P3@P4] */
9064 #define OP_SeekGe 57 /* synopsis: key=r[P3@P4] */
9065 #define OP_SeekGt 58 /* synopsis: key=r[P3@P4] */
9066 #define OP_Seek 59 /* synopsis: intkey=r[P2] */
9067 #define OP_NoConflict 60 /* synopsis: key=r[P3@P4] */
9068 #define OP_NotFound 61 /* synopsis: key=r[P3@P4] */
9069 #define OP_Found 62 /* synopsis: key=r[P3@P4] */
9070 #define OP_NotExists 63 /* synopsis: intkey=r[P3] */
9071 #define OP_Sequence 64 /* synopsis: r[P2]=rowid */
9072 #define OP_NewRowid 65 /* synopsis: r[P2]=rowid */
9073 #define OP_Insert 66 /* synopsis: intkey=r[P3] data=r[P2] */
9074 #define OP_InsertInt 67 /* synopsis: intkey=P3 data=r[P2] */
9075 #define OP_Delete 68
9076 #define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9077 #define OP_And 70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9078 #define OP_ResetCount 71
9079 #define OP_SorterCompare 72 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9080 #define OP_SorterData 73 /* synopsis: r[P2]=data */
9081 #define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9082 #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9083 #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9084 #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9085 #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9086 #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9087 #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P3 */
9088 #define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9089 #define OP_RowKey 82 /* synopsis: r[P2]=key */
9090 #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9091 #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9092 #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9093 #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9094 #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
9095 #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9096 #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9097 #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P1]/r[P2] */
9098 #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P1]%r[P2] */
9099 #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9100 #define OP_RowData 93 /* synopsis: r[P2]=data */
9101 #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9102 #define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
9103 #define OP_Rowid 96 /* synopsis: r[P2]=rowid */
9104 #define OP_NullRow 97
9105 #define OP_Last 98
9106 #define OP_SorterSort 99
9107 #define OP_Sort 100
9108 #define OP_Rewind 101
9109 #define OP_SorterInsert 102
9110 #define OP_IdxInsert 103 /* synopsis: key=r[P2] */
9111 #define OP_IdxDelete 104 /* synopsis: key=r[P2@P3] */
9112 #define OP_IdxRowid 105 /* synopsis: r[P2]=rowid */
9113 #define OP_IdxLT 106 /* synopsis: key=r[P3@P4] */
9114 #define OP_IdxGE 107 /* synopsis: key=r[P3@P4] */
9115 #define OP_Destroy 108
9116 #define OP_Clear 109
9117 #define OP_CreateIndex 110 /* synopsis: r[P2]=root iDb=P1 */
9118 #define OP_CreateTable 111 /* synopsis: r[P2]=root iDb=P1 */
9119 #define OP_ParseSchema 112
9120 #define OP_LoadAnalysis 113
9121 #define OP_DropTable 114
9122 #define OP_DropIndex 115
9123 #define OP_DropTrigger 116
9124 #define OP_IntegrityCk 117
9125 #define OP_RowSetAdd 118 /* synopsis: rowset(P1)=r[P2] */
9126 #define OP_RowSetRead 119 /* synopsis: r[P3]=rowset(P1) */
9127 #define OP_RowSetTest 120 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9128 #define OP_Program 121
9129 #define OP_Param 122
9130 #define OP_FkCounter 123 /* synopsis: fkctr[P1]+=P2 */
9131 #define OP_FkIfZero 124 /* synopsis: if fkctr[P1]==0 goto P2 */
9132 #define OP_MemMax 125 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9133 #define OP_IfPos 126 /* synopsis: if r[P1]>0 goto P2 */
9134 #define OP_IfNeg 127 /* synopsis: if r[P1]<0 goto P2 */
9135 #define OP_IfZero 128 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9136 #define OP_AggFinal 129 /* synopsis: accum=r[P1] N=P2 */
9137 #define OP_IncrVacuum 130
9138 #define OP_Real 131 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9139 #define OP_Expire 132
9140 #define OP_TableLock 133 /* synopsis: iDb=P1 root=P2 write=P3 */
9141 #define OP_VBegin 134
9142 #define OP_VCreate 135
9143 #define OP_VDestroy 136
9144 #define OP_VOpen 137
9145 #define OP_VColumn 138 /* synopsis: r[P3]=vcolumn(P2) */
9146 #define OP_VNext 139
9147 #define OP_VRename 140
9148 #define OP_Pagecount 141
9149 #define OP_ToText 142 /* same as TK_TO_TEXT */
9150 #define OP_ToBlob 143 /* same as TK_TO_BLOB */
9151 #define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
9152 #define OP_ToInt 145 /* same as TK_TO_INT */
9153 #define OP_ToReal 146 /* same as TK_TO_REAL */
9154 #define OP_MaxPgcnt 147
9155 #define OP_Trace 148
9156 #define OP_Noop 149
9157 #define OP_Explain 150
 
 
9158
9159
9160 /* Properties such as "out2" or "jump" that are specified in
9161 ** comments following the "case" for each opcode in the vdbe.c
9162 ** are encoded into bitvectors as follows:
@@ -9168,28 +9200,29 @@
9168 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9169 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9170 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9171 #define OPFLG_INITIALIZER {\
9172 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9173 /* 8 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01,\
9174 /* 16 */ 0x04, 0x04, 0x10, 0x24, 0x00, 0x02, 0x02, 0x02,\
9175 /* 24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00,\
9176 /* 32 */ 0x04, 0x05, 0x04, 0x00, 0x00, 0x01, 0x01, 0x05,\
9177 /* 40 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00,\
9178 /* 48 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,\
9179 /* 56 */ 0x11, 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11,\
9180 /* 64 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c, 0x4c, 0x00,\
9181 /* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
9182 /* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9183 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
9184 /* 96 */ 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08,\
9185 /* 104 */ 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02, 0x02,\
9186 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
9187 /* 120 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05, 0x05,\
9188 /* 128 */ 0x05, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,\
9189 /* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x04, 0x04,\
9190 /* 144 */ 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,}
 
9191
9192 /************** End of opcodes.h *********************************************/
9193 /************** Continuing where we left off in vdbe.h ***********************/
9194
9195 /*
@@ -9223,11 +9256,10 @@
9223 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
9224 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
9225 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
9226 #ifdef SQLITE_DEBUG
9227 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
9228 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
9229 #endif
9230 SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
9231 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
9232 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
9233 SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
@@ -10290,10 +10322,11 @@
10290 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
10291 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
10292 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
10293 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
10294 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
 
10295
10296
10297 /*
10298 ** Bits of the sqlite3.dbOptFlags field that are used by the
10299 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -10323,10 +10356,17 @@
10323 #else
10324 #define OptimizationDisabled(db, mask) 0
10325 #define OptimizationEnabled(db, mask) 1
10326 #endif
10327
 
 
 
 
 
 
 
10328 /*
10329 ** Possible values for the sqlite.magic field.
10330 ** The numbers are obtained at random and have no special meaning, other
10331 ** than being distinct from one another.
10332 */
@@ -10389,10 +10429,11 @@
10389 #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
10390 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10391 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10392 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10393 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
 
10394
10395 /*
10396 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10397 ** used to create the initializers for the FuncDef structures.
10398 **
@@ -10401,10 +10442,13 @@
10401 ** implemented by C function xFunc that accepts nArg arguments. The
10402 ** value passed as iArg is cast to a (void*) and made available
10403 ** as the user-data (sqlite3_user_data()) for the function. If
10404 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
10405 **
 
 
 
10406 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
10407 ** Used to create an aggregate function definition implemented by
10408 ** the C functions xStep and xFinal. The first four parameters
10409 ** are interpreted in the same way as the first 4 parameters to
10410 ** FUNCTION().
@@ -10416,20 +10460,24 @@
10416 ** available as the function user-data (sqlite3_user_data()). The
10417 ** FuncDef.flags variable is set to the value passed as the flags
10418 ** parameter.
10419 */
10420 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
 
 
 
10421 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10422 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10423 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10424 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
10425 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10426 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10427 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10428 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
10429 #define LIKEFUNC(zName, nArg, arg, flags) \
10430 {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
 
10431 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10432 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
10433 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10434
10435 /*
@@ -11075,20 +11123,21 @@
11075 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
11076 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
11077 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
11078 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
11079 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11080 #define EP_FixedDest 0x000200 /* Result needed in a specific register */
11081 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
11082 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
11083 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
11084 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
11085 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11086 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11087 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11088 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11089 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
 
11090
11091 /*
11092 ** These macros can be used to test, set, or clear bits in the
11093 ** Expr.flags field.
11094 */
@@ -11146,12 +11195,18 @@
11146 char *zName; /* Token associated with this expression */
11147 char *zSpan; /* Original text of the expression */
11148 u8 sortOrder; /* 1 for DESC or 0 for ASC */
11149 unsigned done :1; /* A flag to indicate when processing is finished */
11150 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11151 u16 iOrderByCol; /* For ORDER BY, column number in result set */
11152 u16 iAlias; /* Index into Parse.aAlias[] for zName */
 
 
 
 
 
 
11153 } *a; /* Alloc a power of two greater or equal to nExpr */
11154 };
11155
11156 /*
11157 ** An instance of this structure is used by the parser to record both
@@ -11524,10 +11579,11 @@
11524 u8 tempReg; /* iReg is a temp register that needs to be freed */
11525 int iLevel; /* Nesting level */
11526 int iReg; /* Reg with value of this column. 0 means none. */
11527 int lru; /* Least recently used entry has the smallest value */
11528 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
 
11529 yDbMask writeMask; /* Start a write transaction on these databases */
11530 yDbMask cookieMask; /* Bitmask of schema verified databases */
11531 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
11532 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11533 int regRowid; /* Register holding rowid of CREATE TABLE entry */
@@ -11761,10 +11817,11 @@
11761 int bCoreMutex; /* True to enable core mutexing */
11762 int bFullMutex; /* True to enable full mutexing */
11763 int bOpenUri; /* True to interpret filenames as URIs */
11764 int bUseCis; /* Use covering indices for full-scans */
11765 int mxStrlen; /* Maximum string length */
 
11766 int szLookaside; /* Default lookaside buffer size */
11767 int nLookaside; /* Default lookaside buffer count */
11768 sqlite3_mem_methods m; /* Low-level memory allocation interface */
11769 sqlite3_mutex_methods mutex; /* Low-level mutex interface */
11770 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */
@@ -11797,10 +11854,28 @@
11797 void(*xSqllog)(void*,sqlite3*,const char*, int);
11798 void *pSqllogArg;
11799 #endif
11800 };
11801
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11802 /*
11803 ** Context pointer passed down through the tree-walk.
11804 */
11805 struct Walker {
11806 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
@@ -12134,15 +12209,17 @@
12134 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12135 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12136 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12137 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12138 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
 
12139 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12140 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12141 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12142 SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
12143 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
 
12144 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12145 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
12146 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
12147 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
12148 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
@@ -12183,11 +12260,11 @@
12183 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12184 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
12185 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
12186 u8,u8,int,int*);
12187 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12188 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, int*, int*);
12189 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
12190 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
12191 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
12192 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
12193 SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
@@ -12424,10 +12501,11 @@
12424 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
12425 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
12426
12427 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
12428 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
 
12429 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
12430 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
12431 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
12432 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
12433 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -12505,10 +12583,11 @@
12505 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
12506 SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
12507 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
12508 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
12509 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
 
12510 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
12511 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
12512 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
12513 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
12514 SQLITE_PRIVATE const char *sqlite3JournalModename(int);
@@ -12821,10 +12900,11 @@
12821 1, /* bCoreMutex */
12822 SQLITE_THREADSAFE==1, /* bFullMutex */
12823 SQLITE_USE_URI, /* bOpenUri */
12824 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
12825 0x7ffffffe, /* mxStrlen */
 
12826 128, /* szLookaside */
12827 500, /* nLookaside */
12828 {0,0,0,0,0,0,0,0}, /* m */
12829 {0,0,0,0,0,0,0,0,0}, /* mutex */
12830 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
@@ -12855,11 +12935,10 @@
12855 #ifdef SQLITE_ENABLE_SQLLOG
12856 0, /* xSqllog */
12857 0 /* pSqllogArg */
12858 #endif
12859 };
12860
12861
12862 /*
12863 ** Hash table for global functions - functions common to all
12864 ** database connections. After initialization, this table is
12865 ** read-only.
@@ -13253,10 +13332,13 @@
13253 "SMALL_STACK",
13254 #endif
13255 #ifdef SQLITE_SOUNDEX
13256 "SOUNDEX",
13257 #endif
 
 
 
13258 #ifdef SQLITE_TCL
13259 "TCL",
13260 #endif
13261 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
13262 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
@@ -13267,10 +13349,13 @@
13267 #if defined(SQLITE_THREADSAFE)
13268 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
13269 #endif
13270 #ifdef SQLITE_USE_ALLOCA
13271 "USE_ALLOCA",
 
 
 
13272 #endif
13273 #ifdef SQLITE_ZERO_MALLOC
13274 "ZERO_MALLOC"
13275 #endif
13276 };
@@ -13367,11 +13452,11 @@
13367 typedef struct VdbeOp Op;
13368
13369 /*
13370 ** Boolean values
13371 */
13372 typedef unsigned char Bool;
13373
13374 /* Opaque type used by code in vdbesort.c */
13375 typedef struct VdbeSorter VdbeSorter;
13376
13377 /* Opaque type used by the explainer */
@@ -13384,42 +13469,39 @@
13384 ** A cursor is a pointer into a single BTree within a database file.
13385 ** The cursor can seek to a BTree entry with a particular key, or
13386 ** loop over all entries of the Btree. You can also insert new BTree
13387 ** entries or retrieve the key or data from the entry that the cursor
13388 ** is currently pointing to.
 
 
 
13389 **
13390 ** Every cursor that the virtual machine has open is represented by an
13391 ** instance of the following structure.
13392 */
13393 struct VdbeCursor {
13394 BtCursor *pCursor; /* The cursor structure of the backend */
13395 Btree *pBt; /* Separate file holding temporary table */
13396 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
13397 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
13398 int pseudoTableReg; /* Register holding pseudotable content. */
13399 int nField; /* Number of fields in the header */
13400 Bool zeroed; /* True if zeroed out and ready for reuse */
13401 Bool rowidIsValid; /* True if lastRowid is valid */
13402 Bool atFirst; /* True if pointing to first entry */
13403 Bool useRandomRowid; /* Generate new record numbers semi-randomly */
13404 Bool nullRow; /* True if pointing to a row with no data */
13405 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13406 Bool isTable; /* True if a table requiring integer keys */
13407 Bool isIndex; /* True if an index containing keys only - no data */
13408 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
13409 Bool isSorter; /* True if a new-style sorter */
13410 Bool multiPseudo; /* Multi-register pseudo-cursor */
13411 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13412 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
13413 i64 seqCount; /* Sequence counter */
13414 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13415 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
13416 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
13417
13418 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */
13419 int seekResult;
13420
13421 /* Cached information about the header for the data record that the
13422 ** cursor is currently pointing to. Only valid if cacheStatus matches
13423 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
13424 ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
13425 ** the cache is out of date.
@@ -13426,14 +13508,18 @@
13426 **
13427 ** aRow might point to (ephemeral) data for the current row, or it might
13428 ** be NULL.
13429 */
13430 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
13431 int payloadSize; /* Total number of bytes in the record */
13432 u32 *aType; /* Type values for all entries in the record */
13433 u32 *aOffset; /* Cached offsets to the start of each columns data */
13434 u8 *aRow; /* Data for the current row, if all on one page */
 
 
 
 
13435 };
13436 typedef struct VdbeCursor VdbeCursor;
13437
13438 /*
13439 ** When a sub-program is executed (OP_Program), a structure of this type
@@ -13686,13 +13772,10 @@
13686 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13687 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13688 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
13689 char *zSql; /* Text of the SQL statement that generated this */
13690 void *pFree; /* Free this when deleting the vdbe */
13691 #ifdef SQLITE_DEBUG
13692 FILE *trace; /* Write an execution trace here, if not NULL */
13693 #endif
13694 #ifdef SQLITE_ENABLE_TREE_EXPLAIN
13695 Explain *pExplain; /* The explainer */
13696 char *zExplain; /* Explanation of data structures */
13697 #endif
13698 VdbeFrame *pFrame; /* Parent frame */
@@ -13722,11 +13805,11 @@
13722 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
13723 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
13724 #endif
13725 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13726 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13727 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13728 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13729 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13730
13731 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13732 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -13757,11 +13840,11 @@
13757 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
13758 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
13759 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
13760 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
13761 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
13762 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
13763 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
13764 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
13765 #define VdbeMemRelease(X) \
13766 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
13767 sqlite3VdbeMemReleaseExternal(X);
@@ -15782,20 +15865,10 @@
15782 ** This version of the memory allocator is the default. It is
15783 ** used when no other memory allocator is specified using compile-time
15784 ** macros.
15785 */
15786 #ifdef SQLITE_SYSTEM_MALLOC
15787
15788 /*
15789 ** The MSVCRT has malloc_usable_size() but it is called _msize().
15790 ** The use of _msize() is automatic, but can be disabled by compiling
15791 ** with -DSQLITE_WITHOUT_MSIZE
15792 */
15793 #if defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15794 # define SQLITE_MALLOCSIZE _msize
15795 #endif
15796
15797 #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
15798
15799 /*
15800 ** Use the zone allocator available on apple products unless the
15801 ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
@@ -15814,25 +15887,51 @@
15814
15815 /*
15816 ** Use standard C library malloc and free on non-Apple systems.
15817 ** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
15818 */
15819 #define SQLITE_MALLOC(x) malloc(x)
15820 #define SQLITE_FREE(x) free(x)
15821 #define SQLITE_REALLOC(x,y) realloc((x),(y))
15822
15823 #if (defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)) \
15824 || (defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE))
15825 # include <malloc.h> /* Needed for malloc_usable_size on linux */
15826 #endif
15827 #ifdef HAVE_MALLOC_USABLE_SIZE
15828 # ifndef SQLITE_MALLOCSIZE
15829 # define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15830 # endif
15831 #else
15832 # undef SQLITE_MALLOCSIZE
15833 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15834
15835 #endif /* __APPLE__ or not __APPLE__ */
15836
15837 /*
15838 ** Like malloc(), but remember the size of the allocation
@@ -17435,36 +17534,17 @@
17435 ** works for chunks that are currently checked out.
17436 */
17437 static int memsys5Size(void *p){
17438 int iSize = 0;
17439 if( p ){
17440 int i = ((u8 *)p-mem5.zPool)/mem5.szAtom;
17441 assert( i>=0 && i<mem5.nBlock );
17442 iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
17443 }
17444 return iSize;
17445 }
17446
17447 /*
17448 ** Find the first entry on the freelist iLogsize. Unlink that
17449 ** entry and return its index.
17450 */
17451 static int memsys5UnlinkFirst(int iLogsize){
17452 int i;
17453 int iFirst;
17454
17455 assert( iLogsize>=0 && iLogsize<=LOGMAX );
17456 i = iFirst = mem5.aiFreelist[iLogsize];
17457 assert( iFirst>=0 );
17458 while( i>0 ){
17459 if( i<iFirst ) iFirst = i;
17460 i = MEM5LINK(i)->next;
17461 }
17462 memsys5Unlink(iFirst, iLogsize);
17463 return iFirst;
17464 }
17465
17466 /*
17467 ** Return a block of memory of at least nBytes in size.
17468 ** Return NULL if unable. Return NULL if nBytes==0.
17469 **
17470 ** The caller guarantees that nByte is positive.
@@ -17506,11 +17586,12 @@
17506 if( iBin>LOGMAX ){
17507 testcase( sqlite3GlobalConfig.xLog!=0 );
17508 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes", nByte);
17509 return 0;
17510 }
17511 i = memsys5UnlinkFirst(iBin);
 
17512 while( iBin>iLogsize ){
17513 int newSize;
17514
17515 iBin--;
17516 newSize = 1 << iBin;
@@ -17540,11 +17621,11 @@
17540 int iBlock;
17541
17542 /* Set iBlock to the index of the block pointed to by pOld in
17543 ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
17544 */
17545 iBlock = ((u8 *)pOld-mem5.zPool)/mem5.szAtom;
17546
17547 /* Check that the pointer pOld points to a valid, non-free block. */
17548 assert( iBlock>=0 && iBlock<mem5.nBlock );
17549 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
17550 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
@@ -19309,11 +19390,11 @@
19309 /*
19310 ** TRUE if p is a lookaside memory allocation from db
19311 */
19312 #ifndef SQLITE_OMIT_LOOKASIDE
19313 static int isLookaside(sqlite3 *db, void *p){
19314 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19315 }
19316 #else
19317 #define isLookaside(A,B) 0
19318 #endif
19319
@@ -19325,12 +19406,13 @@
19325 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
19326 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
19327 return sqlite3GlobalConfig.m.xSize(p);
19328 }
19329 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19330 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19331 if( db && isLookaside(db, p) ){
 
19332 return db->lookaside.sz;
19333 }else{
19334 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
19335 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
19336 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19808,10 +19890,18 @@
19808 }
19809 if( N>0 ){
19810 sqlite3StrAccumAppend(pAccum, zSpaces, N);
19811 }
19812 }
 
 
 
 
 
 
 
 
19813
19814 /*
19815 ** On machines with a small stack size, you can redefine the
19816 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19817 */
@@ -20020,11 +20110,11 @@
20020 zOut = buf;
20021 }else{
20022 nOut = precision + 10;
20023 zOut = zExtra = sqlite3Malloc( nOut );
20024 if( zOut==0 ){
20025 pAccum->accError = STRACCUM_NOMEM;
20026 return;
20027 }
20028 }
20029 bufpt = &zOut[nOut-1];
20030 if( xtype==etORDINAL ){
@@ -20132,11 +20222,11 @@
20132 e2 = exp;
20133 }
20134 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20135 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20136 if( bufpt==0 ){
20137 pAccum->accError = STRACCUM_NOMEM;
20138 return;
20139 }
20140 }
20141 zOut = bufpt;
20142 nsd = 16 + flag_altform2*10;
@@ -20267,11 +20357,11 @@
20267 needQuote = !isnull && xtype==etSQLESCAPE2;
20268 n += i + 1 + needQuote*2;
20269 if( n>etBUFSIZE ){
20270 bufpt = zExtra = sqlite3Malloc( n );
20271 if( bufpt==0 ){
20272 pAccum->accError = STRACCUM_NOMEM;
20273 return;
20274 }
20275 }else{
20276 bufpt = buf;
20277 }
@@ -20290,11 +20380,11 @@
20290 ** if( precision>=0 && precision<length ) length = precision; */
20291 break;
20292 }
20293 case etTOKEN: {
20294 Token *pToken = va_arg(ap, Token*);
20295 if( pToken ){
20296 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20297 }
20298 length = width = 0;
20299 break;
20300 }
@@ -20302,14 +20392,14 @@
20302 SrcList *pSrc = va_arg(ap, SrcList*);
20303 int k = va_arg(ap, int);
20304 struct SrcList_item *pItem = &pSrc->a[k];
20305 assert( k>=0 && k<pSrc->nSrc );
20306 if( pItem->zDatabase ){
20307 sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
20308 sqlite3StrAccumAppend(pAccum, ".", 1);
20309 }
20310 sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
20311 length = width = 0;
20312 break;
20313 }
20314 default: {
20315 assert( xtype==etINVALID );
@@ -20344,36 +20434,34 @@
20344
20345 /*
20346 ** Append N bytes of text from z to the StrAccum object.
20347 */
20348 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20349 assert( z!=0 || N==0 );
20350 if( p->accError ){
20351 testcase(p->accError==STRACCUM_TOOBIG);
20352 testcase(p->accError==STRACCUM_NOMEM);
20353 return;
20354 }
20355 assert( p->zText!=0 || p->nChar==0 );
20356 if( N<=0 ){
20357 if( N==0 || z[0]==0 ) return;
20358 N = sqlite3Strlen30(z);
20359 }
20360 if( p->nChar+N >= p->nAlloc ){
20361 char *zNew;
 
 
 
 
 
20362 if( !p->useMalloc ){
20363 p->accError = STRACCUM_TOOBIG;
20364 N = p->nAlloc - p->nChar - 1;
 
20365 if( N<=0 ){
20366 return;
20367 }
20368 }else{
20369 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20370 i64 szNew = p->nChar;
20371 szNew += N + 1;
20372 if( szNew > p->mxAlloc ){
20373 sqlite3StrAccumReset(p);
20374 p->accError = STRACCUM_TOOBIG;
20375 return;
20376 }else{
20377 p->nAlloc = (int)szNew;
20378 }
20379 if( p->useMalloc==1 ){
@@ -20383,20 +20471,28 @@
20383 }
20384 if( zNew ){
20385 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20386 p->zText = zNew;
20387 }else{
20388 p->accError = STRACCUM_NOMEM;
20389 sqlite3StrAccumReset(p);
 
20390 return;
20391 }
20392 }
20393 }
20394 assert( p->zText );
20395 memcpy(&p->zText[p->nChar], z, N);
20396 p->nChar += N;
20397 }
 
 
 
 
 
 
 
 
20398
20399 /*
20400 ** Finish off a string by making sure it is zero-terminated.
20401 ** Return a pointer to the resulting string. Return a NULL
20402 ** pointer if any kind of error was encountered.
@@ -20411,11 +20507,11 @@
20411 p->zText = sqlite3_malloc(p->nChar+1);
20412 }
20413 if( p->zText ){
20414 memcpy(p->zText, p->zBase, p->nChar+1);
20415 }else{
20416 p->accError = STRACCUM_NOMEM;
20417 }
20418 }
20419 }
20420 return p->zText;
20421 }
@@ -21748,16 +21844,16 @@
21748 ** Convert zNum to a 64-bit signed integer.
21749 **
21750 ** If the zNum value is representable as a 64-bit twos-complement
21751 ** integer, then write that value into *pNum and return 0.
21752 **
21753 ** If zNum is exactly 9223372036854665808, return 2. This special
21754 ** case is broken out because while 9223372036854665808 cannot be a
21755 ** signed 64-bit integer, its negative -9223372036854665808 can be.
21756 **
21757 ** If zNum is too big for a 64-bit integer and is not
21758 ** 9223372036854665808 or if zNum contains any non-numeric text,
21759 ** then return 1.
21760 **
21761 ** length is the number of bytes in the string (bytes, not characters).
21762 ** The string is not necessarily zero-terminated. The encoding is
21763 ** given by enc.
@@ -21795,11 +21891,11 @@
21795 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
21796 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
21797 u = u*10 + c - '0';
21798 }
21799 if( u>LARGEST_INT64 ){
21800 *pNum = SMALLEST_INT64;
21801 }else if( neg ){
21802 *pNum = -(i64)u;
21803 }else{
21804 *pNum = (i64)u;
21805 }
@@ -21826,11 +21922,10 @@
21826 return 1;
21827 }else{
21828 /* zNum is exactly 9223372036854775808. Fits if negative. The
21829 ** special case 2 overflow if positive */
21830 assert( u-1==LARGEST_INT64 );
21831 assert( (*pNum)==SMALLEST_INT64 );
21832 return neg ? 0 : 2;
21833 }
21834 }
21835 }
21836
@@ -22565,11 +22660,13 @@
22565 if( x<10 ) return 1;
22566 n = x%10;
22567 x /= 10;
22568 if( n>=5 ) n -= 2;
22569 else if( n>=1 ) n -= 1;
22570 if( x>=3 ) return (n+8)<<(x-3);
 
 
22571 return (n+8)>>(3-x);
22572 }
22573
22574 /************** End of util.c ************************************************/
22575 /************** Begin file hash.c ********************************************/
@@ -22869,155 +22966,157 @@
22869 /* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
22870 /* 2 */ "Savepoint" OpHelp(""),
22871 /* 3 */ "AutoCommit" OpHelp(""),
22872 /* 4 */ "Transaction" OpHelp(""),
22873 /* 5 */ "SorterNext" OpHelp(""),
22874 /* 6 */ "Prev" OpHelp(""),
22875 /* 7 */ "Next" OpHelp(""),
22876 /* 8 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
22877 /* 9 */ "Checkpoint" OpHelp(""),
22878 /* 10 */ "JournalMode" OpHelp(""),
22879 /* 11 */ "Vacuum" OpHelp(""),
22880 /* 12 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"),
22881 /* 13 */ "VUpdate" OpHelp("data=r[P3@P2]"),
22882 /* 14 */ "Goto" OpHelp(""),
22883 /* 15 */ "Gosub" OpHelp(""),
22884 /* 16 */ "Return" OpHelp(""),
22885 /* 17 */ "Yield" OpHelp(""),
22886 /* 18 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
22887 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
22888 /* 20 */ "Halt" OpHelp(""),
22889 /* 21 */ "Integer" OpHelp("r[P2]=P1"),
22890 /* 22 */ "Int64" OpHelp("r[P2]=P4"),
22891 /* 23 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
22892 /* 24 */ "Null" OpHelp("r[P2..P3]=NULL"),
22893 /* 25 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
22894 /* 26 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
22895 /* 27 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
22896 /* 28 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
22897 /* 29 */ "SCopy" OpHelp("r[P2]=r[P1]"),
22898 /* 30 */ "ResultRow" OpHelp("output=r[P1@P2]"),
22899 /* 31 */ "CollSeq" OpHelp(""),
22900 /* 32 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
22901 /* 33 */ "MustBeInt" OpHelp(""),
22902 /* 34 */ "RealAffinity" OpHelp(""),
22903 /* 35 */ "Permutation" OpHelp(""),
22904 /* 36 */ "Compare" OpHelp(""),
22905 /* 37 */ "Jump" OpHelp(""),
22906 /* 38 */ "Once" OpHelp(""),
22907 /* 39 */ "If" OpHelp(""),
22908 /* 40 */ "IfNot" OpHelp(""),
22909 /* 41 */ "Column" OpHelp("r[P3]=PX"),
22910 /* 42 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
22911 /* 43 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
22912 /* 44 */ "Count" OpHelp("r[P2]=count()"),
22913 /* 45 */ "ReadCookie" OpHelp(""),
22914 /* 46 */ "SetCookie" OpHelp(""),
22915 /* 47 */ "VerifyCookie" OpHelp(""),
22916 /* 48 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
22917 /* 49 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
22918 /* 50 */ "OpenAutoindex" OpHelp("nColumn=P2"),
22919 /* 51 */ "OpenEphemeral" OpHelp("nColumn=P2"),
22920 /* 52 */ "SorterOpen" OpHelp(""),
22921 /* 53 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
22922 /* 54 */ "Close" OpHelp(""),
22923 /* 55 */ "SeekLt" OpHelp("key=r[P3@P4]"),
22924 /* 56 */ "SeekLe" OpHelp("key=r[P3@P4]"),
22925 /* 57 */ "SeekGe" OpHelp("key=r[P3@P4]"),
22926 /* 58 */ "SeekGt" OpHelp("key=r[P3@P4]"),
22927 /* 59 */ "Seek" OpHelp("intkey=r[P2]"),
22928 /* 60 */ "NoConflict" OpHelp("key=r[P3@P4]"),
22929 /* 61 */ "NotFound" OpHelp("key=r[P3@P4]"),
22930 /* 62 */ "Found" OpHelp("key=r[P3@P4]"),
22931 /* 63 */ "NotExists" OpHelp("intkey=r[P3]"),
22932 /* 64 */ "Sequence" OpHelp("r[P2]=rowid"),
22933 /* 65 */ "NewRowid" OpHelp("r[P2]=rowid"),
22934 /* 66 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
22935 /* 67 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
22936 /* 68 */ "Delete" OpHelp(""),
22937 /* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
22938 /* 70 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
22939 /* 71 */ "ResetCount" OpHelp(""),
22940 /* 72 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
22941 /* 73 */ "SorterData" OpHelp("r[P2]=data"),
22942 /* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
22943 /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
22944 /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
22945 /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
22946 /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
22947 /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22948 /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P3"),
22949 /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
22950 /* 82 */ "RowKey" OpHelp("r[P2]=key"),
22951 /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
22952 /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
22953 /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
22954 /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
22955 /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
22956 /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
22957 /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22958 /* 90 */ "Divide" OpHelp("r[P3]=r[P1]/r[P2]"),
22959 /* 91 */ "Remainder" OpHelp("r[P3]=r[P1]%r[P2]"),
22960 /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22961 /* 93 */ "RowData" OpHelp("r[P2]=data"),
22962 /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
22963 /* 95 */ "String8" OpHelp("r[P2]='P4'"),
22964 /* 96 */ "Rowid" OpHelp("r[P2]=rowid"),
22965 /* 97 */ "NullRow" OpHelp(""),
22966 /* 98 */ "Last" OpHelp(""),
22967 /* 99 */ "SorterSort" OpHelp(""),
22968 /* 100 */ "Sort" OpHelp(""),
22969 /* 101 */ "Rewind" OpHelp(""),
22970 /* 102 */ "SorterInsert" OpHelp(""),
22971 /* 103 */ "IdxInsert" OpHelp("key=r[P2]"),
22972 /* 104 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
22973 /* 105 */ "IdxRowid" OpHelp("r[P2]=rowid"),
22974 /* 106 */ "IdxLT" OpHelp("key=r[P3@P4]"),
22975 /* 107 */ "IdxGE" OpHelp("key=r[P3@P4]"),
22976 /* 108 */ "Destroy" OpHelp(""),
22977 /* 109 */ "Clear" OpHelp(""),
22978 /* 110 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
22979 /* 111 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
22980 /* 112 */ "ParseSchema" OpHelp(""),
22981 /* 113 */ "LoadAnalysis" OpHelp(""),
22982 /* 114 */ "DropTable" OpHelp(""),
22983 /* 115 */ "DropIndex" OpHelp(""),
22984 /* 116 */ "DropTrigger" OpHelp(""),
22985 /* 117 */ "IntegrityCk" OpHelp(""),
22986 /* 118 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
22987 /* 119 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
22988 /* 120 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
22989 /* 121 */ "Program" OpHelp(""),
22990 /* 122 */ "Param" OpHelp(""),
22991 /* 123 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
22992 /* 124 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
22993 /* 125 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
22994 /* 126 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
22995 /* 127 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
22996 /* 128 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
22997 /* 129 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
22998 /* 130 */ "IncrVacuum" OpHelp(""),
22999 /* 131 */ "Real" OpHelp("r[P2]=P4"),
23000 /* 132 */ "Expire" OpHelp(""),
23001 /* 133 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23002 /* 134 */ "VBegin" OpHelp(""),
23003 /* 135 */ "VCreate" OpHelp(""),
23004 /* 136 */ "VDestroy" OpHelp(""),
23005 /* 137 */ "VOpen" OpHelp(""),
23006 /* 138 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23007 /* 139 */ "VNext" OpHelp(""),
23008 /* 140 */ "VRename" OpHelp(""),
23009 /* 141 */ "Pagecount" OpHelp(""),
23010 /* 142 */ "ToText" OpHelp(""),
23011 /* 143 */ "ToBlob" OpHelp(""),
23012 /* 144 */ "ToNumeric" OpHelp(""),
23013 /* 145 */ "ToInt" OpHelp(""),
23014 /* 146 */ "ToReal" OpHelp(""),
23015 /* 147 */ "MaxPgcnt" OpHelp(""),
23016 /* 148 */ "Trace" OpHelp(""),
23017 /* 149 */ "Noop" OpHelp(""),
23018 /* 150 */ "Explain" OpHelp(""),
 
 
23019 };
23020 return azName[i];
23021 }
23022 #endif
23023
@@ -24545,10 +24644,19 @@
24545 }
24546 *ppInode = pInode;
24547 return SQLITE_OK;
24548 }
24549
 
 
 
 
 
 
 
 
 
24550
24551 /*
24552 ** Check a unixFile that is a database. Verify the following:
24553 **
24554 ** (1) There is exactly one hard link on the file
@@ -24579,14 +24687,11 @@
24579 if( buf.st_nlink>1 ){
24580 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
24581 pFile->ctrlFlags |= UNIXFILE_WARNED;
24582 return;
24583 }
24584 if( pFile->pInode!=0
24585 && ((rc = osStat(pFile->zPath, &buf))!=0
24586 || buf.st_ino!=pFile->pInode->fileId.ino)
24587 ){
24588 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
24589 pFile->ctrlFlags |= UNIXFILE_WARNED;
24590 return;
24591 }
24592 }
@@ -27030,10 +27135,14 @@
27030 if( zTFile ){
27031 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
27032 *(char**)pArg = zTFile;
27033 }
27034 return SQLITE_OK;
 
 
 
 
27035 }
27036 #if SQLITE_MAX_MMAP_SIZE>0
27037 case SQLITE_FCNTL_MMAP_SIZE: {
27038 i64 newLimit = *(i64*)pArg;
27039 int rc = SQLITE_OK;
@@ -27311,11 +27420,11 @@
27311
27312 /* Update the global lock state and do debug tracing */
27313 #ifdef SQLITE_DEBUG
27314 { u16 mask;
27315 OSTRACE(("SHM-LOCK "));
27316 mask = (1<<(ofst+n)) - (1<<ofst);
27317 if( rc==SQLITE_OK ){
27318 if( lockType==F_UNLCK ){
27319 OSTRACE(("unlock %d ok", ofst));
27320 pShmNode->exclMask &= ~mask;
27321 pShmNode->sharedMask &= ~mask;
@@ -30947,10 +31056,38 @@
30947 #if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
30948 # error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
30949 must be defined."
30950 #endif
30951
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30952 /*
30953 ** This constant should already be defined (in the "WinDef.h" SDK file).
30954 */
30955 #ifndef MAX_PATH
30956 # define MAX_PATH (260)
@@ -31582,20 +31719,22 @@
31582 { "GetTickCount", (SYSCALL)0, 0 },
31583 #endif
31584
31585 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
31586
31587 #if defined(SQLITE_WIN32_HAS_ANSI)
 
31588 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
31589 #else
31590 { "GetVersionExA", (SYSCALL)0, 0 },
31591 #endif
31592
31593 #define osGetVersionExA ((BOOL(WINAPI*)( \
31594 LPOSVERSIONINFOA))aSyscall[34].pCurrent)
31595
31596 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE)
 
31597 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
31598 #else
31599 { "GetVersionExW", (SYSCALL)0, 0 },
31600 #endif
31601
@@ -32148,15 +32287,14 @@
32148 ** API as long as we don't call it when running Win95/98/ME. A call to
32149 ** this routine is used to determine if the host is Win95/98/ME or
32150 ** WinNT/2K/XP so that we will know whether or not we can safely call
32151 ** the LockFileEx() API.
32152 */
32153 #ifndef NTDDI_WIN8
32154 # define NTDDI_WIN8 0x06020000
32155 #endif
32156
32157 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
 
 
32158 # define osIsNT() (1)
32159 #elif !defined(SQLITE_WIN32_HAS_WIDE)
32160 # define osIsNT() (0)
32161 #else
32162 static int osIsNT(void){
@@ -32289,18 +32427,24 @@
32289 assert( pWinMemData->magic1==WINMEM_MAGIC1 );
32290 assert( pWinMemData->magic2==WINMEM_MAGIC2 );
32291
32292 #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
32293 if( !pWinMemData->hHeap ){
 
 
 
 
 
 
 
32294 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
32295 SQLITE_WIN32_HEAP_INIT_SIZE,
32296 SQLITE_WIN32_HEAP_MAX_SIZE);
32297 if( !pWinMemData->hHeap ){
32298 sqlite3_log(SQLITE_NOMEM,
32299 "failed to HeapCreate (%lu), flags=%u, initSize=%u, maxSize=%u",
32300 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
32301 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
32302 return SQLITE_NOMEM;
32303 }
32304 pWinMemData->bOwned = TRUE;
32305 assert( pWinMemData->bOwned );
32306 }
@@ -33972,11 +34116,11 @@
33972 winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
33973 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
33974 return SQLITE_OK;
33975 }
33976 case SQLITE_FCNTL_VFSNAME: {
33977 *(char**)pArg = sqlite3_mprintf("win32");
33978 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
33979 return SQLITE_OK;
33980 }
33981 case SQLITE_FCNTL_WIN32_AV_RETRY: {
33982 int *a = (int*)pArg;
@@ -34956,11 +35100,11 @@
34956 **
34957 ** This division contains the implementation of methods on the
34958 ** sqlite3_vfs object.
34959 */
34960
34961 #if 0
34962 /*
34963 ** Convert a filename from whatever the underlying operating system
34964 ** supports for filenames into UTF-8. Space to hold the result is
34965 ** obtained from malloc and must be freed by the calling function.
34966 */
@@ -35132,27 +35276,21 @@
35132 if( winIsDir(zConverted) ){
35133 /* At this point, we know the candidate directory exists and should
35134 ** be used. However, we may need to convert the string containing
35135 ** its name into UTF-8 (i.e. if it is UTF-16 right now).
35136 */
35137 if( osIsNT() ){
35138 char *zUtf8 = winUnicodeToUtf8(zConverted);
35139 if( !zUtf8 ){
35140 sqlite3_free(zConverted);
35141 sqlite3_free(zBuf);
35142 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35143 return SQLITE_IOERR_NOMEM;
35144 }
35145 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
35146 sqlite3_free(zUtf8);
35147 sqlite3_free(zConverted);
35148 break;
35149 }else{
35150 sqlite3_snprintf(nMax, zBuf, "%s", zConverted);
35151 sqlite3_free(zConverted);
35152 break;
35153 }
35154 }
35155 sqlite3_free(zConverted);
35156 }
35157 }
35158 }
@@ -35833,23 +35971,47 @@
35833 */
35834 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
35835 if( !zOut ){
35836 return SQLITE_IOERR_NOMEM;
35837 }
35838 if( cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut,
35839 pVfs->mxPathname+1)<0 ){
 
35840 sqlite3_free(zOut);
35841 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
35842 "winFullPathname1", zRelative);
 
 
 
 
 
 
 
 
 
 
35843 }
35844 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35845 sqlite3_data_directory, winGetDirSep(), zOut);
35846 sqlite3_free(zOut);
35847 }else{
35848 if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){
 
 
 
 
 
 
 
35849 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
35850 "winFullPathname2", zRelative);
 
 
 
 
 
 
 
 
 
35851 }
35852 }
35853 return SQLITE_OK;
35854 #endif
35855
@@ -43770,10 +43932,34 @@
43770 *ppPager = pPager;
43771 return SQLITE_OK;
43772 }
43773
43774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43775
43776 /*
43777 ** This function is called after transitioning from PAGER_UNLOCK to
43778 ** PAGER_SHARED state. It tests if there is a hot journal present in
43779 ** the file-system for the given pager. A hot journal is one that
@@ -44241,11 +44427,11 @@
44241 if( bMmapOk && pagerUseWal(pPager) ){
44242 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
44243 if( rc!=SQLITE_OK ) goto pager_acquire_err;
44244 }
44245
44246 if( iFrame==0 && bMmapOk ){
44247 void *pData = 0;
44248
44249 rc = sqlite3OsFetch(pPager->fd,
44250 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
44251 );
@@ -44446,17 +44632,23 @@
44446 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
44447 (pPager->tempFile ?
44448 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
44449 (SQLITE_OPEN_MAIN_JOURNAL)
44450 );
44451 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
44452 rc = sqlite3JournalOpen(
44453 pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44454 );
44455 #else
44456 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44457 #endif
 
 
 
 
 
 
44458 }
44459 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
44460 }
44461
44462
@@ -44586,18 +44778,12 @@
44586 assert( pPager->eState==PAGER_WRITER_LOCKED
44587 || pPager->eState==PAGER_WRITER_CACHEMOD
44588 || pPager->eState==PAGER_WRITER_DBMOD
44589 );
44590 assert( assert_pager_state(pPager) );
44591
44592 /* If an error has been previously detected, report the same error
44593 ** again. This should not happen, but the check provides robustness. */
44594 if( NEVER(pPager->errCode) ) return pPager->errCode;
44595
44596 /* Higher-level routines never call this function if database is not
44597 ** writable. But check anyway, just for robustness. */
44598 if( NEVER(pPager->readOnly) ) return SQLITE_PERM;
44599
44600 CHECK_PAGE(pPg);
44601
44602 /* The journal file needs to be opened. Higher level routines have already
44603 ** obtained the necessary locks to begin the write-transaction, but the
@@ -44722,23 +44908,23 @@
44722 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
44723 int rc = SQLITE_OK;
44724
44725 PgHdr *pPg = pDbPage;
44726 Pager *pPager = pPg->pPager;
44727 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
44728
44729 assert( (pPg->flags & PGHDR_MMAP)==0 );
44730 assert( pPager->eState>=PAGER_WRITER_LOCKED );
44731 assert( pPager->eState!=PAGER_ERROR );
44732 assert( assert_pager_state(pPager) );
44733
44734 if( nPagePerSector>1 ){
44735 Pgno nPageCount; /* Total number of pages in database file */
44736 Pgno pg1; /* First page of the sector pPg is located on. */
44737 int nPage = 0; /* Number of pages starting at pg1 to journal */
44738 int ii; /* Loop counter */
44739 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
 
44740
44741 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
44742 ** a journal header to be written between the pages journaled by
44743 ** this function.
44744 */
@@ -50914,10 +51100,14 @@
50914 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
50915 pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
50916 );
50917 if( pIdxKey==0 ) return SQLITE_NOMEM;
50918 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
 
 
 
 
50919 }else{
50920 pIdxKey = 0;
50921 }
50922 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
50923 if( pFree ){
@@ -51868,11 +52058,11 @@
51868
51869 if( pgno>btreePagecount(pBt) ){
51870 rc = SQLITE_CORRUPT_BKPT;
51871 }else{
51872 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
51873 if( rc==SQLITE_OK ){
51874 rc = btreeInitPage(*ppPage);
51875 if( rc!=SQLITE_OK ){
51876 releasePage(*ppPage);
51877 }
51878 }
@@ -54408,14 +54598,14 @@
54408 }
54409
54410 /*
54411 ** Return a pointer to payload information from the entry that the
54412 ** pCur cursor is pointing to. The pointer is to the beginning of
54413 ** the key if skipKey==0 and it points to the beginning of data if
54414 ** skipKey==1. The number of bytes of available key/data is written
54415 ** into *pAmt. If *pAmt==0, then the value returned will not be
54416 ** a valid pointer.
54417 **
54418 ** This routine is an optimization. It is common for the entire key
54419 ** and data to fit on the local page and for there to be no overflow
54420 ** pages. When that is so, this routine can be used to access the
54421 ** key and data without making a copy. If the key and/or data spills
@@ -54424,45 +54614,25 @@
54424 **
54425 ** The pointer returned by this routine looks directly into the cached
54426 ** page of the database. The data might change or move the next time
54427 ** any btree routine is called.
54428 */
54429 static const unsigned char *fetchPayload(
54430 BtCursor *pCur, /* Cursor pointing to entry to read from */
54431 int *pAmt, /* Write the number of available bytes here */
54432 int skipKey /* read beginning at data if this is true */
54433 ){
54434 unsigned char *aPayload;
54435 MemPage *pPage;
54436 u32 nKey;
54437 u32 nLocal;
54438
54439 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
54440 assert( pCur->eState==CURSOR_VALID );
 
54441 assert( cursorHoldsMutex(pCur) );
54442 pPage = pCur->apPage[pCur->iPage];
54443 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
54444 if( NEVER(pCur->info.nSize==0) ){
54445 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
54446 &pCur->info);
54447 }
54448 aPayload = pCur->info.pCell;
54449 aPayload += pCur->info.nHeader;
54450 if( pPage->intKey ){
54451 nKey = 0;
54452 }else{
54453 nKey = (int)pCur->info.nKey;
54454 }
54455 if( skipKey ){
54456 aPayload += nKey;
54457 nLocal = pCur->info.nLocal - nKey;
54458 }else{
54459 nLocal = pCur->info.nLocal;
54460 assert( nLocal<=nKey );
54461 }
54462 *pAmt = nLocal;
54463 return aPayload;
54464 }
54465
54466
54467 /*
54468 ** For the entry that cursor pCur is point to, return as
@@ -54476,27 +54646,15 @@
54476 ** this routine.
54477 **
54478 ** These routines is used to get quick access to key and data
54479 ** in the common case where no overflow pages are used.
54480 */
54481 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
54482 const void *p = 0;
54483 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54484 assert( cursorHoldsMutex(pCur) );
54485 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54486 p = (const void*)fetchPayload(pCur, pAmt, 0);
54487 }
54488 return p;
54489 }
54490 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
54491 const void *p = 0;
54492 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54493 assert( cursorHoldsMutex(pCur) );
54494 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54495 p = (const void*)fetchPayload(pCur, pAmt, 1);
54496 }
54497 return p;
54498 }
54499
54500
54501 /*
54502 ** Move the cursor down to a new child page. The newPgno argument is the
@@ -54611,12 +54769,10 @@
54611 ** b-tree).
54612 */
54613 static int moveToRoot(BtCursor *pCur){
54614 MemPage *pRoot;
54615 int rc = SQLITE_OK;
54616 Btree *p = pCur->pBtree;
54617 BtShared *pBt = p->pBt;
54618
54619 assert( cursorHoldsMutex(pCur) );
54620 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
54621 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
54622 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54627,20 +54783,16 @@
54627 }
54628 sqlite3BtreeClearCursor(pCur);
54629 }
54630
54631 if( pCur->iPage>=0 ){
54632 int i;
54633 for(i=1; i<=pCur->iPage; i++){
54634 releasePage(pCur->apPage[i]);
54635 }
54636 pCur->iPage = 0;
54637 }else if( pCur->pgnoRoot==0 ){
54638 pCur->eState = CURSOR_INVALID;
54639 return SQLITE_OK;
54640 }else{
54641 rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
54642 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
54643 if( rc!=SQLITE_OK ){
54644 pCur->eState = CURSOR_INVALID;
54645 return rc;
54646 }
@@ -54669,18 +54821,20 @@
54669 pCur->aiIdx[0] = 0;
54670 pCur->info.nSize = 0;
54671 pCur->atLast = 0;
54672 pCur->validNKey = 0;
54673
54674 if( pRoot->nCell==0 && !pRoot->leaf ){
 
 
54675 Pgno subpage;
54676 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
54677 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
54678 pCur->eState = CURSOR_VALID;
54679 rc = moveToChild(pCur, subpage);
54680 }else{
54681 pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
54682 }
54683 return rc;
54684 }
54685
54686 /*
@@ -54867,14 +55021,14 @@
54867 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
54868 return SQLITE_OK;
54869 }
54870 assert( pCur->apPage[0]->intKey || pIdxKey );
54871 for(;;){
54872 int lwr, upr, idx;
54873 Pgno chldPg;
54874 MemPage *pPage = pCur->apPage[pCur->iPage];
54875 int c;
54876
54877 /* pPage->nCell must be greater than zero. If this is the root-page
54878 ** the cursor would have been INVALID above and this for(;;) loop
54879 ** not run. If this is not the root-page, then the moveToChild() routine
54880 ** would have already detected db corruption. Similarly, pPage must
@@ -54882,59 +55036,68 @@
54882 ** a moveToChild() or moveToRoot() call would have detected corruption. */
54883 assert( pPage->nCell>0 );
54884 assert( pPage->intKey==(pIdxKey==0) );
54885 lwr = 0;
54886 upr = pPage->nCell-1;
54887 if( biasRight ){
54888 pCur->aiIdx[pCur->iPage] = (u16)(idx = upr);
54889 }else{
54890 pCur->aiIdx[pCur->iPage] = (u16)(idx = (upr+lwr)/2);
54891 }
54892 for(;;){
54893 u8 *pCell; /* Pointer to current cell in pPage */
54894
54895 assert( idx==pCur->aiIdx[pCur->iPage] );
54896 pCur->info.nSize = 0;
54897 pCell = findCell(pPage, idx) + pPage->childPtrSize;
54898 if( pPage->intKey ){
54899 i64 nCellKey;
 
54900 if( pPage->hasData ){
54901 u32 dummy;
54902 pCell += getVarint32(pCell, dummy);
 
54903 }
54904 getVarint(pCell, (u64*)&nCellKey);
54905 if( nCellKey==intKey ){
54906 c = 0;
54907 }else if( nCellKey<intKey ){
54908 c = -1;
54909 }else{
54910 assert( nCellKey>intKey );
54911 c = +1;
54912 }
54913 pCur->validNKey = 1;
54914 pCur->info.nKey = nCellKey;
54915 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54916 /* The maximum supported page-size is 65536 bytes. This means that
54917 ** the maximum number of record bytes stored on an index B-Tree
54918 ** page is less than 16384 bytes and may be stored as a 2-byte
54919 ** varint. This information is used to attempt to avoid parsing
54920 ** the entire cell by checking for the cases where the record is
54921 ** stored entirely within the b-tree page by inspecting the first
54922 ** 2 bytes of the cell.
54923 */
54924 int nCell = pCell[0];
54925 if( nCell<=pPage->max1bytePayload
54926 /* && (pCell+nCell)<pPage->aDataEnd */
54927 ){
54928 /* This branch runs if the record-size field of the cell is a
54929 ** single byte varint and the record fits entirely on the main
54930 ** b-tree page. */
54931 testcase( pCell+nCell+1==pPage->aDataEnd );
54932 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
54933 }else if( !(pCell[1] & 0x80)
54934 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
54935 /* && (pCell+nCell+2)<=pPage->aDataEnd */
54936 ){
54937 /* The record-size field is a 2 byte varint and the record
54938 ** fits entirely on the main b-tree page. */
54939 testcase( pCell+nCell+2==pPage->aDataEnd );
54940 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -54950,61 +55113,57 @@
54950 pCellKey = sqlite3Malloc( nCell );
54951 if( pCellKey==0 ){
54952 rc = SQLITE_NOMEM;
54953 goto moveto_finish;
54954 }
 
54955 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
54956 if( rc ){
54957 sqlite3_free(pCellKey);
54958 goto moveto_finish;
54959 }
54960 c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
54961 sqlite3_free(pCellKey);
54962 }
54963 }
54964 if( c==0 ){
54965 if( pPage->intKey && !pPage->leaf ){
54966 lwr = idx;
54967 break;
54968 }else{
 
54969 *pRes = 0;
54970 rc = SQLITE_OK;
 
54971 goto moveto_finish;
54972 }
54973 }
54974 if( c<0 ){
54975 lwr = idx+1;
54976 }else{
54977 upr = idx-1;
54978 }
54979 if( lwr>upr ){
54980 break;
54981 }
54982 pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
54983 }
54984 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
54985 assert( pPage->isInit );
54986 if( pPage->leaf ){
54987 chldPg = 0;
54988 }else if( lwr>=pPage->nCell ){
54989 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
54990 }else{
54991 chldPg = get4byte(findCell(pPage, lwr));
54992 }
54993 if( chldPg==0 ){
54994 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
 
54995 *pRes = c;
54996 rc = SQLITE_OK;
54997 goto moveto_finish;
54998 }
 
 
 
 
 
 
54999 pCur->aiIdx[pCur->iPage] = (u16)lwr;
55000 pCur->info.nSize = 0;
55001 pCur->validNKey = 0;
55002 rc = moveToChild(pCur, chldPg);
55003 if( rc ) goto moveto_finish;
55004 }
55005 moveto_finish:
 
 
55006 return rc;
55007 }
55008
55009
55010 /*
@@ -55758,11 +55917,11 @@
55758 nHeader = 0;
55759 if( !pPage->leaf ){
55760 nHeader += 4;
55761 }
55762 if( pPage->hasData ){
55763 nHeader += putVarint(&pCell[nHeader], nData+nZero);
55764 }else{
55765 nData = nZero = 0;
55766 }
55767 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
55768 btreeParseCellPtr(pPage, pCell, &info);
@@ -55886,11 +56045,10 @@
55886 */
55887 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
55888 u32 pc; /* Offset to cell content of cell being deleted */
55889 u8 *data; /* pPage->aData */
55890 u8 *ptr; /* Used to move bytes around within data[] */
55891 u8 *endPtr; /* End of loop */
55892 int rc; /* The return code */
55893 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
55894
55895 if( *pRC ) return;
55896
@@ -55911,17 +56069,12 @@
55911 rc = freeSpace(pPage, pc, sz);
55912 if( rc ){
55913 *pRC = rc;
55914 return;
55915 }
55916 endPtr = &pPage->aCellIdx[2*pPage->nCell - 2];
55917 assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
55918 while( ptr<endPtr ){
55919 *(u16*)ptr = *(u16*)&ptr[2];
55920 ptr += 2;
55921 }
55922 pPage->nCell--;
 
55923 put2byte(&data[hdr+3], pPage->nCell);
55924 pPage->nFree += 2;
55925 }
55926
55927 /*
@@ -55954,13 +56107,10 @@
55954 int j; /* Loop counter */
55955 int end; /* First byte past the last cell pointer in data[] */
55956 int ins; /* Index in data[] where new cell pointer is inserted */
55957 int cellOffset; /* Address of first cell pointer in data[] */
55958 u8 *data; /* The content of the whole page */
55959 u8 *ptr; /* Used for moving information around in data[] */
55960 u8 *endPtr; /* End of the loop */
55961
55962 int nSkip = (iChild ? 4 : 0);
55963
55964 if( *pRC ) return;
55965
55966 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56007,17 +56157,11 @@
56007 pPage->nFree -= (u16)(2 + sz);
56008 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
56009 if( iChild ){
56010 put4byte(&data[idx], iChild);
56011 }
56012 ptr = &data[end];
56013 endPtr = &data[ins];
56014 assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
56015 while( ptr>endPtr ){
56016 *(u16*)ptr = *(u16*)&ptr[-2];
56017 ptr -= 2;
56018 }
56019 put2byte(&data[ins], idx);
56020 put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
56021 #ifndef SQLITE_OMIT_AUTOVACUUM
56022 if( pPage->pBt->autoVacuum ){
56023 /* The cell may contain a pointer to an overflow page. If so, write
@@ -57975,11 +58119,11 @@
57975 va_start(ap, zFormat);
57976 if( pCheck->errMsg.nChar ){
57977 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
57978 }
57979 if( zMsg1 ){
57980 sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
57981 }
57982 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
57983 va_end(ap);
57984 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
57985 pCheck->mallocFailed = 1;
@@ -58839,10 +58983,11 @@
58839 if( sqlite3OpenTempDatabase(pParse) ){
58840 sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
58841 rc = SQLITE_ERROR;
58842 }
58843 sqlite3DbFree(pErrorDb, pParse->zErrMsg);
 
58844 sqlite3StackFree(pErrorDb, pParse);
58845 }
58846 if( rc ){
58847 return 0;
58848 }
@@ -59550,61 +59695,59 @@
59550 #endif
59551 }
59552
59553 /*
59554 ** Make sure pMem->z points to a writable allocation of at least
59555 ** n bytes.
59556 **
59557 ** If the third argument passed to this function is true, then memory
59558 ** cell pMem must contain a string or blob. In this case the content is
59559 ** preserved. Otherwise, if the third parameter to this function is false,
59560 ** any current string or blob value may be discarded.
59561 **
59562 ** This function sets the MEM_Dyn flag and clears any xDel callback.
59563 ** It also clears MEM_Ephem and MEM_Static. If the preserve flag is
59564 ** not set, Mem.n is zeroed.
59565 */
59566 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
59567 assert( 1 >=
59568 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
59569 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
59570 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
59571 ((pMem->flags&MEM_Static) ? 1 : 0)
59572 );
59573 assert( (pMem->flags&MEM_RowSet)==0 );
59574
59575 /* If the preserve flag is set to true, then the memory cell must already
59576 ** contain a valid string or blob value. */
59577 assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
 
59578
59579 if( n<32 ) n = 32;
59580 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59581 if( preserve && pMem->z==pMem->zMalloc ){
59582 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59583 preserve = 0;
59584 }else{
59585 sqlite3DbFree(pMem->db, pMem->zMalloc);
59586 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
59587 }
 
 
 
 
 
59588 }
59589
59590 if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
59591 memcpy(pMem->zMalloc, pMem->z, pMem->n);
59592 }
59593 if( pMem->flags&MEM_Dyn && pMem->xDel ){
59594 assert( pMem->xDel!=SQLITE_DYNAMIC );
59595 pMem->xDel((void *)(pMem->z));
59596 }
59597
59598 pMem->z = pMem->zMalloc;
59599 if( pMem->z==0 ){
59600 pMem->flags = MEM_Null;
59601 }else{
59602 pMem->flags &= ~(MEM_Ephem|MEM_Static);
59603 }
59604 pMem->xDel = 0;
59605 return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
59606 }
59607
59608 /*
59609 ** Make the given Mem object MEM_Dyn. In other words, make it so
59610 ** that any TEXT or BLOB content is stored in memory obtained from
@@ -59786,27 +59929,22 @@
59786 ** inconsistent state, for example with (Mem.z==0) and
59787 ** (Mem.type==SQLITE_TEXT).
59788 */
59789 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
59790 VdbeMemRelease(p);
59791 sqlite3DbFree(p->db, p->zMalloc);
 
 
 
59792 p->z = 0;
59793 p->zMalloc = 0;
59794 p->xDel = 0;
59795 }
59796
59797 /*
59798 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
59799 ** If the double is too large, return 0x8000000000000000.
59800 **
59801 ** Most systems appear to do this simply by assigning
59802 ** variables and without the extra range tests. But
59803 ** there are reports that windows throws an expection
59804 ** if the floating point value is out of range. (See ticket #2880.)
59805 ** Because we do not completely understand the problem, we will
59806 ** take the conservative approach and always do range tests
59807 ** before attempting the conversion.
59808 */
59809 static i64 doubleToInt64(double r){
59810 #ifdef SQLITE_OMIT_FLOATING_POINT
59811 /* When floating-point is omitted, double and int64 are the same thing */
59812 return r;
@@ -59819,18 +59957,14 @@
59819 ** larger than a 32-bit integer constant.
59820 */
59821 static const i64 maxInt = LARGEST_INT64;
59822 static const i64 minInt = SMALLEST_INT64;
59823
59824 if( r<(double)minInt ){
59825 return minInt;
59826 }else if( r>(double)maxInt ){
59827 /* minInt is correct here - not maxInt. It turns out that assigning
59828 ** a very large positive number to an integer results in a very large
59829 ** negative integer. This makes no sense, but it is what x86 hardware
59830 ** does so for compatibility we will do the same in software. */
59831 return minInt;
59832 }else{
59833 return (i64)r;
59834 }
59835 #endif
59836 }
@@ -59908,21 +60042,15 @@
59908 ** (2) The integer is neither the largest nor the smallest
59909 ** possible integer (ticket #3922)
59910 **
59911 ** The second and third terms in the following conditional enforces
59912 ** the second condition under the assumption that addition overflow causes
59913 ** values to wrap around. On x86 hardware, the third term is always
59914 ** true and could be omitted. But we leave it in because other
59915 ** architectures might behave differently.
59916 */
59917 if( pMem->r==(double)pMem->u.i
59918 && pMem->u.i>SMALLEST_INT64
59919 #if defined(__i486__) || defined(__x86_64__)
59920 && ALWAYS(pMem->u.i<LARGEST_INT64)
59921 #else
59922 && pMem->u.i<LARGEST_INT64
59923 #endif
59924 ){
59925 pMem->flags |= MEM_Int;
59926 }
59927 }
59928
@@ -60387,17 +60515,17 @@
60387 ** If this routine fails for any reason (malloc returns NULL or unable
60388 ** to read from the disk) then the pMem is left in an inconsistent state.
60389 */
60390 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
60391 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
60392 int offset, /* Offset from the start of data to return bytes from. */
60393 int amt, /* Number of bytes to return. */
60394 int key, /* If true, retrieve from the btree key, not data. */
60395 Mem *pMem /* OUT: Return data in this Mem structure. */
60396 ){
60397 char *zData; /* Data from the btree layer */
60398 int available = 0; /* Number of bytes available on the local btree page */
60399 int rc = SQLITE_OK; /* Return code */
60400
60401 assert( sqlite3BtreeCursorIsValid(pCur) );
60402
60403 /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
@@ -60408,11 +60536,11 @@
60408 }else{
60409 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
60410 }
60411 assert( zData!=0 );
60412
60413 if( offset+amt<=available && (pMem->flags&MEM_Dyn)==0 ){
60414 sqlite3VdbeMemRelease(pMem);
60415 pMem->z = &zData[offset];
60416 pMem->flags = MEM_Blob|MEM_Ephem;
60417 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60418 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
@@ -60427,11 +60555,11 @@
60427 pMem->z[amt+1] = 0;
60428 if( rc!=SQLITE_OK ){
60429 sqlite3VdbeMemRelease(pMem);
60430 }
60431 }
60432 pMem->n = amt;
60433
60434 return rc;
60435 }
60436
60437 /* This function is only available internally, it is not part of the
@@ -60524,19 +60652,19 @@
60524 Index *pIdx = p->pIdx; /* Index being probed */
60525 int nByte; /* Bytes of space to allocate */
60526 int i; /* Counter variable */
60527 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
60528
60529 nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord);
60530 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
60531 if( pRec ){
60532 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
60533 if( pRec->pKeyInfo ){
60534 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60535 assert( pRec->pKeyInfo->enc==ENC(db) );
60536 pRec->flags = UNPACKED_PREFIX_MATCH;
60537 pRec->aMem = (Mem *)&pRec[1];
60538 for(i=0; i<nCol; i++){
60539 pRec->aMem[i].flags = MEM_Null;
60540 pRec->aMem[i].type = SQLITE_NULL;
60541 pRec->aMem[i].db = db;
60542 }
@@ -60586,20 +60714,11 @@
60586 if( !pExpr ){
60587 *ppVal = 0;
60588 return SQLITE_OK;
60589 }
60590 op = pExpr->op;
60591
60592 /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT4.
60593 ** The ifdef here is to enable us to achieve 100% branch test coverage even
60594 ** when SQLITE_ENABLE_STAT4 is omitted.
60595 */
60596 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
60597 if( op==TK_REGISTER ) op = pExpr->op2;
60598 #else
60599 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
60600 #endif
60601
60602 /* Handle negative integers in a single step. This is needed in the
60603 ** case when the value is -9223372036854775808.
60604 */
60605 if( op==TK_UMINUS
@@ -60736,11 +60855,11 @@
60736 if( aRet==0 ){
60737 sqlite3_result_error_nomem(context);
60738 }else{
60739 aRet[0] = nSerial+1;
60740 sqlite3PutVarint(&aRet[1], iSerial);
60741 sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
60742 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
60743 sqlite3DbFree(db, aRet);
60744 }
60745 }
60746
@@ -60814,14 +60933,13 @@
60814
60815 if( !pExpr ){
60816 pVal = valueNew(db, &alloc);
60817 if( pVal ){
60818 sqlite3VdbeMemSetNull((Mem*)pVal);
60819 *pbOk = 1;
60820 }
60821 }else if( pExpr->op==TK_VARIABLE
60822 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
60823 ){
60824 Vdbe *v;
60825 int iBindVar = pExpr->iColumn;
60826 sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
60827 if( (v = pParse->pReprepare)!=0 ){
@@ -60830,20 +60948,17 @@
60830 rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
60831 if( rc==SQLITE_OK ){
60832 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
60833 }
60834 pVal->db = pParse->db;
60835 *pbOk = 1;
60836 sqlite3VdbeMemStoreType((Mem*)pVal);
60837 }
60838 }else{
60839 *pbOk = 0;
60840 }
60841 }else{
60842 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
60843 *pbOk = (pVal!=0);
60844 }
 
60845
60846 assert( pVal==0 || pVal->db==db );
60847 return rc;
60848 }
60849
@@ -60983,19 +61098,10 @@
60983 pA->zSql = pB->zSql;
60984 pB->zSql = zTmp;
60985 pB->isPrepareV2 = pA->isPrepareV2;
60986 }
60987
60988 #ifdef SQLITE_DEBUG
60989 /*
60990 ** Turn tracing on or off
60991 */
60992 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
60993 p->trace = trace;
60994 }
60995 #endif
60996
60997 /*
60998 ** Resize the Vdbe.aOp array so that it is at least one op larger than
60999 ** it was.
61000 **
61001 ** If an out-of-memory error occurs while resizing the array, return
@@ -61367,16 +61473,18 @@
61367 if( n>nMaxArgs ) nMaxArgs = n;
61368 break;
61369 }
61370 #endif
61371 case OP_Next:
 
61372 case OP_SorterNext: {
61373 pOp->p4.xAdvance = sqlite3BtreeNext;
61374 pOp->p4type = P4_ADVANCE;
61375 break;
61376 }
61377 case OP_Prev: {
 
61378 pOp->p4.xAdvance = sqlite3BtreePrevious;
61379 pOp->p4type = P4_ADVANCE;
61380 break;
61381 }
61382 }
@@ -61887,11 +61995,11 @@
61887 assert( i<nTemp );
61888 break;
61889 }
61890 case P4_COLLSEQ: {
61891 CollSeq *pColl = pOp->p4.pColl;
61892 sqlite3_snprintf(nTemp, zTemp, "collseq(%.20s)", pColl->zName);
61893 break;
61894 }
61895 case P4_FUNCDEF: {
61896 FuncDef *pDef = pOp->p4.pFunc;
61897 sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
@@ -62320,19 +62428,21 @@
62320 #ifdef SQLITE_DEBUG
62321 /*
62322 ** Print the SQL that was used to generate a VDBE program.
62323 */
62324 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
62325 int nOp = p->nOp;
62326 VdbeOp *pOp;
62327 if( nOp<1 ) return;
62328 pOp = &p->aOp[0];
62329 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62330 const char *z = pOp->p4.z;
62331 while( sqlite3Isspace(*z) ) z++;
62332 printf("SQL: [%s]\n", z);
62333 }
 
 
62334 }
62335 #endif
62336
62337 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
62338 /*
@@ -62586,11 +62696,11 @@
62586 sqlite3BtreeCloseCursor(pCx->pCursor);
62587 }
62588 #ifndef SQLITE_OMIT_VIRTUALTABLE
62589 if( pCx->pVtabCursor ){
62590 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
62591 const sqlite3_module *pModule = pCx->pModule;
62592 p->inVtabMethod = 1;
62593 pModule->xClose(pVtabCursor);
62594 p->inVtabMethod = 0;
62595 }
62596 #endif
@@ -63570,11 +63680,11 @@
63570 #ifdef SQLITE_TEST
63571 sqlite3_search_count++;
63572 #endif
63573 p->deferredMoveto = 0;
63574 p->cacheStatus = CACHE_STALE;
63575 }else if( ALWAYS(p->pCursor) ){
63576 int hasMoved;
63577 int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
63578 if( rc ) return rc;
63579 if( hasMoved ){
63580 p->cacheStatus = CACHE_STALE;
@@ -63737,25 +63847,19 @@
63737 /*
63738 ** Write the serialized data blob for the value stored in pMem into
63739 ** buf. It is assumed that the caller has allocated sufficient space.
63740 ** Return the number of bytes written.
63741 **
63742 ** nBuf is the amount of space left in buf[]. nBuf must always be
63743 ** large enough to hold the entire field. Except, if the field is
63744 ** a blob with a zero-filled tail, then buf[] might be just the right
63745 ** size to hold everything except for the zero-filled tail. If buf[]
63746 ** is only big enough to hold the non-zero prefix, then only write that
63747 ** prefix into buf[]. But if buf[] is large enough to hold both the
63748 ** prefix and the tail then write the prefix and set the tail to all
63749 ** zeros.
63750 **
63751 ** Return the number of bytes actually written into buf[]. The number
63752 ** of bytes in the zero-filled tail is included in the return value only
63753 ** if those bytes were zeroed in buf[].
63754 */
63755 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
63756 u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
63757 u32 len;
63758
63759 /* Integer and Real */
63760 if( serial_type<=7 && serial_type>0 ){
63761 u64 v;
@@ -63766,11 +63870,10 @@
63766 swapMixedEndianFloat(v);
63767 }else{
63768 v = pMem->u.i;
63769 }
63770 len = i = sqlite3VdbeSerialTypeLen(serial_type);
63771 assert( len<=(u32)nBuf );
63772 while( i-- ){
63773 buf[i] = (u8)(v&0xFF);
63774 v >>= 8;
63775 }
63776 return len;
@@ -63778,21 +63881,12 @@
63778
63779 /* String or blob */
63780 if( serial_type>=12 ){
63781 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
63782 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
63783 assert( pMem->n<=nBuf );
63784 len = pMem->n;
63785 memcpy(buf, pMem->z, len);
63786 if( pMem->flags & MEM_Zero ){
63787 len += pMem->u.nZero;
63788 assert( nBuf>=0 );
63789 if( len > (u32)nBuf ){
63790 len = (u32)nBuf;
63791 }
63792 memset(&buf[pMem->n], 0, len-pMem->n);
63793 }
63794 return len;
63795 }
63796
63797 /* NULL or constants 0 or 1 */
63798 return 0;
@@ -63878,19 +63972,16 @@
63878 pMem->u.i = serial_type-8;
63879 pMem->flags = MEM_Int;
63880 return 0;
63881 }
63882 default: {
 
63883 u32 len = (serial_type-12)/2;
63884 pMem->z = (char *)buf;
63885 pMem->n = len;
63886 pMem->xDel = 0;
63887 if( serial_type&0x01 ){
63888 pMem->flags = MEM_Str | MEM_Ephem;
63889 }else{
63890 pMem->flags = MEM_Blob | MEM_Ephem;
63891 }
63892 return len;
63893 }
63894 }
63895 return 0;
63896 }
@@ -64025,13 +64116,15 @@
64025 */
64026 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
64027
64028 idx1 = getVarint32(aKey1, szHdr1);
64029 d1 = szHdr1;
64030 assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField );
64031 assert( pKeyInfo->aSortOrder!=0 );
64032 while( idx1<szHdr1 && i<pPKey2->nField ){
 
 
64033 u32 serial_type1;
64034
64035 /* Read the serial types for the next element in each key. */
64036 idx1 += getVarint32( aKey1+idx1, serial_type1 );
64037
@@ -64060,11 +64153,11 @@
64060 rc = -rc; /* Invert the result for DESC sort order. */
64061 }
64062 return rc;
64063 }
64064 i++;
64065 }
64066
64067 /* No memory allocation is ever used on mem1. Prove this using
64068 ** the following assert(). If the assert() fails, it indicates a
64069 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
64070 */
@@ -64118,11 +64211,11 @@
64118 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64119 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
64120
64121 /* Read in the complete content of the index entry */
64122 memset(&m, 0, sizeof(m));
64123 rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
64124 if( rc ){
64125 return rc;
64126 }
64127
64128 /* The index entry must begin with a header size */
@@ -64196,11 +64289,11 @@
64196 if( nCellKey<=0 || nCellKey>0x7fffffff ){
64197 *res = 0;
64198 return SQLITE_CORRUPT_BKPT;
64199 }
64200 memset(&m, 0, sizeof(m));
64201 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m);
64202 if( rc ){
64203 return rc;
64204 }
64205 assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64206 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
@@ -65715,10 +65808,11 @@
65715 if( db->nVdbeExec>1 ){
65716 while( *zRawSql ){
65717 const char *zStart = zRawSql;
65718 while( *(zRawSql++)!='\n' && *zRawSql );
65719 sqlite3StrAccumAppend(&out, "-- ", 3);
 
65720 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
65721 }
65722 }else{
65723 while( zRawSql[0] ){
65724 n = findNextHostParameter(zRawSql, &nToken);
@@ -66131,13 +66225,12 @@
66131 Mem *pMem = &p->aMem[p->nMem-iCur];
66132
66133 int nByte;
66134 VdbeCursor *pCx = 0;
66135 nByte =
66136 ROUND8(sizeof(VdbeCursor)) +
66137 (isBtreeCursor?sqlite3BtreeCursorSize():0) +
66138 2*nField*sizeof(u32);
66139
66140 assert( iCur<p->nCursor );
66141 if( p->apCsr[iCur] ){
66142 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
66143 p->apCsr[iCur] = 0;
@@ -66145,16 +66238,13 @@
66145 if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
66146 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
66147 memset(pCx, 0, sizeof(VdbeCursor));
66148 pCx->iDb = iDb;
66149 pCx->nField = nField;
66150 if( nField ){
66151 pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))];
66152 }
66153 if( isBtreeCursor ){
66154 pCx->pCursor = (BtCursor*)
66155 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)];
66156 sqlite3BtreeCursorZero(pCx->pCursor);
66157 }
66158 }
66159 return pCx;
66160 }
@@ -66336,41 +66426,40 @@
66336
66337 #ifdef SQLITE_DEBUG
66338 /*
66339 ** Print the value of a register for tracing purposes:
66340 */
66341 static void memTracePrint(FILE *out, Mem *p){
66342 if( p->flags & MEM_Invalid ){
66343 fprintf(out, " undefined");
66344 }else if( p->flags & MEM_Null ){
66345 fprintf(out, " NULL");
66346 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66347 fprintf(out, " si:%lld", p->u.i);
66348 }else if( p->flags & MEM_Int ){
66349 fprintf(out, " i:%lld", p->u.i);
66350 #ifndef SQLITE_OMIT_FLOATING_POINT
66351 }else if( p->flags & MEM_Real ){
66352 fprintf(out, " r:%g", p->r);
66353 #endif
66354 }else if( p->flags & MEM_RowSet ){
66355 fprintf(out, " (rowset)");
66356 }else{
66357 char zBuf[200];
66358 sqlite3VdbeMemPrettyPrint(p, zBuf);
66359 fprintf(out, " ");
66360 fprintf(out, "%s", zBuf);
66361 }
66362 }
66363 static void registerTrace(FILE *out, int iReg, Mem *p){
66364 fprintf(out, "REG[%d] = ", iReg);
66365 memTracePrint(out, p);
66366 fprintf(out, "\n");
66367 }
66368 #endif
66369
66370 #ifdef SQLITE_DEBUG
66371 # define REGISTER_TRACE(R,M) if(p->trace)registerTrace(p->trace,R,M)
66372 #else
66373 # define REGISTER_TRACE(R,M)
66374 #endif
66375
66376
@@ -66563,438 +66652,11 @@
66563 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66564 #ifdef VDBE_PROFILE
66565 u64 start; /* CPU clock count at start of opcode */
66566 int origPc; /* Program counter at start of opcode */
66567 #endif
66568 /********************************************************************
66569 ** Automatically generated code
66570 **
66571 ** The following union is automatically generated by the
66572 ** vdbe-compress.tcl script. The purpose of this union is to
66573 ** reduce the amount of stack space required by this function.
66574 ** See comments in the vdbe-compress.tcl script for details.
66575 */
66576 union vdbeExecUnion {
66577 struct OP_Yield_stack_vars {
66578 int pcDest;
66579 } aa;
66580 struct OP_Halt_stack_vars {
66581 const char *zType;
66582 const char *zLogFmt;
66583 } ab;
66584 struct OP_Null_stack_vars {
66585 int cnt;
66586 u16 nullFlag;
66587 } ac;
66588 struct OP_Variable_stack_vars {
66589 Mem *pVar; /* Value being transferred */
66590 } ad;
66591 struct OP_Move_stack_vars {
66592 char *zMalloc; /* Holding variable for allocated memory */
66593 int n; /* Number of registers left to copy */
66594 int p1; /* Register to copy from */
66595 int p2; /* Register to copy to */
66596 } ae;
66597 struct OP_Copy_stack_vars {
66598 int n;
66599 } af;
66600 struct OP_ResultRow_stack_vars {
66601 Mem *pMem;
66602 int i;
66603 } ag;
66604 struct OP_Concat_stack_vars {
66605 i64 nByte;
66606 } ah;
66607 struct OP_Remainder_stack_vars {
66608 char bIntint; /* Started out as two integer operands */
66609 int flags; /* Combined MEM_* flags from both inputs */
66610 i64 iA; /* Integer value of left operand */
66611 i64 iB; /* Integer value of right operand */
66612 double rA; /* Real value of left operand */
66613 double rB; /* Real value of right operand */
66614 } ai;
66615 struct OP_Function_stack_vars {
66616 int i;
66617 Mem *pArg;
66618 sqlite3_context ctx;
66619 sqlite3_value **apVal;
66620 int n;
66621 } aj;
66622 struct OP_ShiftRight_stack_vars {
66623 i64 iA;
66624 u64 uA;
66625 i64 iB;
66626 u8 op;
66627 } ak;
66628 struct OP_Ge_stack_vars {
66629 int res; /* Result of the comparison of pIn1 against pIn3 */
66630 char affinity; /* Affinity to use for comparison */
66631 u16 flags1; /* Copy of initial value of pIn1->flags */
66632 u16 flags3; /* Copy of initial value of pIn3->flags */
66633 } al;
66634 struct OP_Compare_stack_vars {
66635 int n;
66636 int i;
66637 int p1;
66638 int p2;
66639 const KeyInfo *pKeyInfo;
66640 int idx;
66641 CollSeq *pColl; /* Collating sequence to use on this term */
66642 int bRev; /* True for DESCENDING sort order */
66643 } am;
66644 struct OP_Or_stack_vars {
66645 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66646 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66647 } an;
66648 struct OP_IfNot_stack_vars {
66649 int c;
66650 } ao;
66651 struct OP_Column_stack_vars {
66652 u32 payloadSize; /* Number of bytes in the record */
66653 i64 payloadSize64; /* Number of bytes in the record */
66654 int p1; /* P1 value of the opcode */
66655 int p2; /* column number to retrieve */
66656 VdbeCursor *pC; /* The VDBE cursor */
66657 char *zRec; /* Pointer to complete record-data */
66658 BtCursor *pCrsr; /* The BTree cursor */
66659 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
66660 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
66661 int nField; /* number of fields in the record */
66662 int len; /* The length of the serialized data for the column */
66663 int i; /* Loop counter */
66664 char *zData; /* Part of the record being decoded */
66665 Mem *pDest; /* Where to write the extracted value */
66666 Mem sMem; /* For storing the record being decoded */
66667 u8 *zIdx; /* Index into header */
66668 u8 *zEndHdr; /* Pointer to first byte after the header */
66669 u32 offset; /* Offset into the data */
66670 u32 szField; /* Number of bytes in the content of a field */
66671 int szHdr; /* Size of the header size field at start of record */
66672 int avail; /* Number of bytes of available data */
66673 u32 t; /* A type code from the record header */
66674 Mem *pReg; /* PseudoTable input register */
66675 } ap;
66676 struct OP_Affinity_stack_vars {
66677 const char *zAffinity; /* The affinity to be applied */
66678 char cAff; /* A single character of affinity */
66679 } aq;
66680 struct OP_MakeRecord_stack_vars {
66681 u8 *zNewRecord; /* A buffer to hold the data for the new record */
66682 Mem *pRec; /* The new record */
66683 u64 nData; /* Number of bytes of data space */
66684 int nHdr; /* Number of bytes of header space */
66685 i64 nByte; /* Data space required for this record */
66686 int nZero; /* Number of zero bytes at the end of the record */
66687 int nVarint; /* Number of bytes in a varint */
66688 u32 serial_type; /* Type field */
66689 Mem *pData0; /* First field to be combined into the record */
66690 Mem *pLast; /* Last field of the record */
66691 int nField; /* Number of fields in the record */
66692 char *zAffinity; /* The affinity string for the record */
66693 int file_format; /* File format to use for encoding */
66694 int i; /* Space used in zNewRecord[] */
66695 int len; /* Length of a field */
66696 } ar;
66697 struct OP_Count_stack_vars {
66698 i64 nEntry;
66699 BtCursor *pCrsr;
66700 } as;
66701 struct OP_Savepoint_stack_vars {
66702 int p1; /* Value of P1 operand */
66703 char *zName; /* Name of savepoint */
66704 int nName;
66705 Savepoint *pNew;
66706 Savepoint *pSavepoint;
66707 Savepoint *pTmp;
66708 int iSavepoint;
66709 int ii;
66710 } at;
66711 struct OP_AutoCommit_stack_vars {
66712 int desiredAutoCommit;
66713 int iRollback;
66714 int turnOnAC;
66715 } au;
66716 struct OP_Transaction_stack_vars {
66717 Btree *pBt;
66718 } av;
66719 struct OP_ReadCookie_stack_vars {
66720 int iMeta;
66721 int iDb;
66722 int iCookie;
66723 } aw;
66724 struct OP_SetCookie_stack_vars {
66725 Db *pDb;
66726 } ax;
66727 struct OP_VerifyCookie_stack_vars {
66728 int iMeta;
66729 int iGen;
66730 Btree *pBt;
66731 } ay;
66732 struct OP_OpenWrite_stack_vars {
66733 int nField;
66734 KeyInfo *pKeyInfo;
66735 int p2;
66736 int iDb;
66737 int wrFlag;
66738 Btree *pX;
66739 VdbeCursor *pCur;
66740 Db *pDb;
66741 } az;
66742 struct OP_OpenEphemeral_stack_vars {
66743 VdbeCursor *pCx;
66744 KeyInfo *pKeyInfo;
66745 } ba;
66746 struct OP_SorterOpen_stack_vars {
66747 VdbeCursor *pCx;
66748 } bb;
66749 struct OP_OpenPseudo_stack_vars {
66750 VdbeCursor *pCx;
66751 } bc;
66752 struct OP_SeekGt_stack_vars {
66753 int res;
66754 int oc;
66755 VdbeCursor *pC;
66756 UnpackedRecord r;
66757 int nField;
66758 i64 iKey; /* The rowid we are to seek to */
66759 } bd;
66760 struct OP_Seek_stack_vars {
66761 VdbeCursor *pC;
66762 } be;
66763 struct OP_Found_stack_vars {
66764 int alreadyExists;
66765 int ii;
66766 VdbeCursor *pC;
66767 int res;
66768 char *pFree;
66769 UnpackedRecord *pIdxKey;
66770 UnpackedRecord r;
66771 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
66772 } bf;
66773 struct OP_NotExists_stack_vars {
66774 VdbeCursor *pC;
66775 BtCursor *pCrsr;
66776 int res;
66777 u64 iKey;
66778 } bg;
66779 struct OP_NewRowid_stack_vars {
66780 i64 v; /* The new rowid */
66781 VdbeCursor *pC; /* Cursor of table to get the new rowid */
66782 int res; /* Result of an sqlite3BtreeLast() */
66783 int cnt; /* Counter to limit the number of searches */
66784 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
66785 VdbeFrame *pFrame; /* Root frame of VDBE */
66786 } bh;
66787 struct OP_InsertInt_stack_vars {
66788 Mem *pData; /* MEM cell holding data for the record to be inserted */
66789 Mem *pKey; /* MEM cell holding key for the record */
66790 i64 iKey; /* The integer ROWID or key for the record to be inserted */
66791 VdbeCursor *pC; /* Cursor to table into which insert is written */
66792 int nZero; /* Number of zero-bytes to append */
66793 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
66794 const char *zDb; /* database name - used by the update hook */
66795 const char *zTbl; /* Table name - used by the opdate hook */
66796 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
66797 } bi;
66798 struct OP_Delete_stack_vars {
66799 i64 iKey;
66800 VdbeCursor *pC;
66801 } bj;
66802 struct OP_SorterCompare_stack_vars {
66803 VdbeCursor *pC;
66804 int res;
66805 int nIgnore;
66806 } bk;
66807 struct OP_SorterData_stack_vars {
66808 VdbeCursor *pC;
66809 } bl;
66810 struct OP_RowData_stack_vars {
66811 VdbeCursor *pC;
66812 BtCursor *pCrsr;
66813 u32 n;
66814 i64 n64;
66815 } bm;
66816 struct OP_Rowid_stack_vars {
66817 VdbeCursor *pC;
66818 i64 v;
66819 sqlite3_vtab *pVtab;
66820 const sqlite3_module *pModule;
66821 } bn;
66822 struct OP_NullRow_stack_vars {
66823 VdbeCursor *pC;
66824 } bo;
66825 struct OP_Last_stack_vars {
66826 VdbeCursor *pC;
66827 BtCursor *pCrsr;
66828 int res;
66829 } bp;
66830 struct OP_Rewind_stack_vars {
66831 VdbeCursor *pC;
66832 BtCursor *pCrsr;
66833 int res;
66834 } bq;
66835 struct OP_Next_stack_vars {
66836 VdbeCursor *pC;
66837 int res;
66838 } br;
66839 struct OP_IdxInsert_stack_vars {
66840 VdbeCursor *pC;
66841 BtCursor *pCrsr;
66842 int nKey;
66843 const char *zKey;
66844 } bs;
66845 struct OP_IdxDelete_stack_vars {
66846 VdbeCursor *pC;
66847 BtCursor *pCrsr;
66848 int res;
66849 UnpackedRecord r;
66850 } bt;
66851 struct OP_IdxRowid_stack_vars {
66852 BtCursor *pCrsr;
66853 VdbeCursor *pC;
66854 i64 rowid;
66855 } bu;
66856 struct OP_IdxGE_stack_vars {
66857 VdbeCursor *pC;
66858 int res;
66859 UnpackedRecord r;
66860 } bv;
66861 struct OP_Destroy_stack_vars {
66862 int iMoved;
66863 int iCnt;
66864 Vdbe *pVdbe;
66865 int iDb;
66866 } bw;
66867 struct OP_Clear_stack_vars {
66868 int nChange;
66869 } bx;
66870 struct OP_CreateTable_stack_vars {
66871 int pgno;
66872 int flags;
66873 Db *pDb;
66874 } by;
66875 struct OP_ParseSchema_stack_vars {
66876 int iDb;
66877 const char *zMaster;
66878 char *zSql;
66879 InitData initData;
66880 } bz;
66881 struct OP_IntegrityCk_stack_vars {
66882 int nRoot; /* Number of tables to check. (Number of root pages.) */
66883 int *aRoot; /* Array of rootpage numbers for tables to be checked */
66884 int j; /* Loop counter */
66885 int nErr; /* Number of errors reported */
66886 char *z; /* Text of the error report */
66887 Mem *pnErr; /* Register keeping track of errors remaining */
66888 } ca;
66889 struct OP_RowSetRead_stack_vars {
66890 i64 val;
66891 } cb;
66892 struct OP_RowSetTest_stack_vars {
66893 int iSet;
66894 int exists;
66895 } cc;
66896 struct OP_Program_stack_vars {
66897 int nMem; /* Number of memory registers for sub-program */
66898 int nByte; /* Bytes of runtime space required for sub-program */
66899 Mem *pRt; /* Register to allocate runtime space */
66900 Mem *pMem; /* Used to iterate through memory cells */
66901 Mem *pEnd; /* Last memory cell in new array */
66902 VdbeFrame *pFrame; /* New vdbe frame to execute in */
66903 SubProgram *pProgram; /* Sub-program to execute */
66904 void *t; /* Token identifying trigger */
66905 } cd;
66906 struct OP_Param_stack_vars {
66907 VdbeFrame *pFrame;
66908 Mem *pIn;
66909 } ce;
66910 struct OP_MemMax_stack_vars {
66911 Mem *pIn1;
66912 VdbeFrame *pFrame;
66913 } cf;
66914 struct OP_AggStep_stack_vars {
66915 int n;
66916 int i;
66917 Mem *pMem;
66918 Mem *pRec;
66919 sqlite3_context ctx;
66920 sqlite3_value **apVal;
66921 } cg;
66922 struct OP_AggFinal_stack_vars {
66923 Mem *pMem;
66924 } ch;
66925 struct OP_Checkpoint_stack_vars {
66926 int i; /* Loop counter */
66927 int aRes[3]; /* Results */
66928 Mem *pMem; /* Write results here */
66929 } ci;
66930 struct OP_JournalMode_stack_vars {
66931 Btree *pBt; /* Btree to change journal mode of */
66932 Pager *pPager; /* Pager associated with pBt */
66933 int eNew; /* New journal mode */
66934 int eOld; /* The old journal mode */
66935 #ifndef SQLITE_OMIT_WAL
66936 const char *zFilename; /* Name of database file for pPager */
66937 #endif
66938 } cj;
66939 struct OP_IncrVacuum_stack_vars {
66940 Btree *pBt;
66941 } ck;
66942 struct OP_VBegin_stack_vars {
66943 VTable *pVTab;
66944 } cl;
66945 struct OP_VOpen_stack_vars {
66946 VdbeCursor *pCur;
66947 sqlite3_vtab_cursor *pVtabCursor;
66948 sqlite3_vtab *pVtab;
66949 sqlite3_module *pModule;
66950 } cm;
66951 struct OP_VFilter_stack_vars {
66952 int nArg;
66953 int iQuery;
66954 const sqlite3_module *pModule;
66955 Mem *pQuery;
66956 Mem *pArgc;
66957 sqlite3_vtab_cursor *pVtabCursor;
66958 sqlite3_vtab *pVtab;
66959 VdbeCursor *pCur;
66960 int res;
66961 int i;
66962 Mem **apArg;
66963 } cn;
66964 struct OP_VColumn_stack_vars {
66965 sqlite3_vtab *pVtab;
66966 const sqlite3_module *pModule;
66967 Mem *pDest;
66968 sqlite3_context sContext;
66969 } co;
66970 struct OP_VNext_stack_vars {
66971 sqlite3_vtab *pVtab;
66972 const sqlite3_module *pModule;
66973 int res;
66974 VdbeCursor *pCur;
66975 } cp;
66976 struct OP_VRename_stack_vars {
66977 sqlite3_vtab *pVtab;
66978 Mem *pName;
66979 } cq;
66980 struct OP_VUpdate_stack_vars {
66981 sqlite3_vtab *pVtab;
66982 sqlite3_module *pModule;
66983 int nArg;
66984 int i;
66985 sqlite_int64 rowid;
66986 Mem **apArg;
66987 Mem *pX;
66988 } cr;
66989 struct OP_Trace_stack_vars {
66990 char *zTrace;
66991 char *z;
66992 } cs;
66993 } u;
66994 /* End automatically generated code
66995 ********************************************************************/
66996
66997 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
66998 sqlite3VdbeEnter(p);
66999 if( p->rc==SQLITE_NOMEM ){
67000 /* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67021,17 +66683,32 @@
67021 }
67022 }
67023 #endif
67024 #ifdef SQLITE_DEBUG
67025 sqlite3BeginBenignMalloc();
67026 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
 
 
67027 int i;
67028 printf("VDBE Program Listing:\n");
67029 sqlite3VdbePrintSql(p);
67030 for(i=0; i<p->nOp; i++){
67031 sqlite3VdbePrintOp(stdout, i, &aOp[i]);
 
 
 
67032 }
 
 
 
 
 
 
 
 
 
 
67033 }
67034 sqlite3EndBenignMalloc();
67035 #endif
67036 for(pc=p->pc; rc==SQLITE_OK; pc++){
67037 assert( pc>=0 && pc<p->nOp );
@@ -67044,16 +66721,12 @@
67044 pOp = &aOp[pc];
67045
67046 /* Only allow tracing if SQLITE_DEBUG is defined.
67047 */
67048 #ifdef SQLITE_DEBUG
67049 if( p->trace ){
67050 if( pc==0 ){
67051 printf("VDBE Execution Trace:\n");
67052 sqlite3VdbePrintSql(p);
67053 }
67054 sqlite3VdbePrintOp(p->trace, pc, pOp);
67055 }
67056 #endif
67057
67058
67059 /* Check to see if we need to simulate an interrupt. This only happens
@@ -67180,19 +66853,16 @@
67180 ** sqlite3VdbeExec() or since last time the progress callback was called).
67181 ** If the progress callback returns non-zero, exit the virtual machine with
67182 ** a return code SQLITE_ABORT.
67183 */
67184 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
67185 int prc;
67186 prc = db->xProgress(db->pProgressArg);
67187 if( prc!=0 ){
67188 rc = SQLITE_INTERRUPT;
67189 goto vdbe_error_halt;
67190 }
67191 if( db->xProgress!=0 ){
67192 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
67193 }
67194 }
67195 #endif
67196
67197 break;
67198 }
@@ -67228,20 +66898,18 @@
67228 /* Opcode: Yield P1 * * * *
67229 **
67230 ** Swap the program counter with the value in register P1.
67231 */
67232 case OP_Yield: { /* in1 */
67233 #if 0 /* local variables moved into u.aa */
67234 int pcDest;
67235 #endif /* local variables moved into u.aa */
67236 pIn1 = &aMem[pOp->p1];
67237 assert( (pIn1->flags & MEM_Dyn)==0 );
67238 pIn1->flags = MEM_Int;
67239 u.aa.pcDest = (int)pIn1->u.i;
67240 pIn1->u.i = pc;
67241 REGISTER_TRACE(pOp->p1, pIn1);
67242 pc = u.aa.pcDest;
67243 break;
67244 }
67245
67246 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67247 ** Synopsis: if r[P3] null then halt
@@ -67286,14 +66954,12 @@
67286 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
67287 ** every program. So a jump past the last instruction of the program
67288 ** is the same as executing Halt.
67289 */
67290 case OP_Halt: {
67291 #if 0 /* local variables moved into u.ab */
67292 const char *zType;
67293 const char *zLogFmt;
67294 #endif /* local variables moved into u.ab */
67295
67296 if( pOp->p1==SQLITE_OK && p->pFrame ){
67297 /* Halt the sub-program. Return control to the parent frame. */
67298 VdbeFrame *pFrame = p->pFrame;
67299 p->pFrame = pFrame->pParent;
@@ -67300,11 +66966,11 @@
67300 p->nFrame--;
67301 sqlite3VdbeSetChanges(db, p->nChange);
67302 pc = sqlite3VdbeFrameRestore(pFrame);
67303 lastRowid = db->lastRowid;
67304 if( pOp->p2==OE_Ignore ){
67305 /* Instruction pc is the OP_Program that invoked the sub-program
67306 ** currently being halted. If the p2 instruction of this OP_Halt
67307 ** instruction is set to OE_Ignore, then the sub-program is throwing
67308 ** an IGNORE exception. In this case jump to the address specified
67309 ** as the p2 of the calling OP_Program. */
67310 pc = p->aOp[pc].p2-1;
@@ -67323,25 +66989,25 @@
67323 assert( pOp->p5>=1 && pOp->p5<=4 );
67324 testcase( pOp->p5==1 );
67325 testcase( pOp->p5==2 );
67326 testcase( pOp->p5==3 );
67327 testcase( pOp->p5==4 );
67328 u.ab.zType = azType[pOp->p5-1];
67329 }else{
67330 u.ab.zType = 0;
67331 }
67332 assert( u.ab.zType!=0 || pOp->p4.z!=0 );
67333 u.ab.zLogFmt = "abort at %d in [%s]: %s";
67334 if( u.ab.zType && pOp->p4.z ){
67335 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67336 u.ab.zType, pOp->p4.z);
67337 }else if( pOp->p4.z ){
67338 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67339 }else{
67340 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
67341 }
67342 sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
67343 }
67344 rc = sqlite3VdbeHalt(p);
67345 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67346 if( rc==SQLITE_BUSY ){
67347 p->rc = rc = SQLITE_BUSY;
@@ -67451,23 +67117,21 @@
67451 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67452 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67453 ** OP_Ne or OP_Eq.
67454 */
67455 case OP_Null: { /* out2-prerelease */
67456 #if 0 /* local variables moved into u.ac */
67457 int cnt;
67458 u16 nullFlag;
67459 #endif /* local variables moved into u.ac */
67460 u.ac.cnt = pOp->p3-pOp->p2;
67461 assert( pOp->p3<=(p->nMem-p->nCursor) );
67462 pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67463 while( u.ac.cnt>0 ){
67464 pOut++;
67465 memAboutToChange(p, pOut);
67466 VdbeMemRelease(pOut);
67467 pOut->flags = u.ac.nullFlag;
67468 u.ac.cnt--;
67469 }
67470 break;
67471 }
67472
67473
@@ -67492,21 +67156,19 @@
67492 **
67493 ** If the parameter is named, then its name appears in P4 and P3==1.
67494 ** The P4 value is used by sqlite3_bind_parameter_name().
67495 */
67496 case OP_Variable: { /* out2-prerelease */
67497 #if 0 /* local variables moved into u.ad */
67498 Mem *pVar; /* Value being transferred */
67499 #endif /* local variables moved into u.ad */
67500
67501 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67502 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67503 u.ad.pVar = &p->aVar[pOp->p1 - 1];
67504 if( sqlite3VdbeMemTooBig(u.ad.pVar) ){
67505 goto too_big;
67506 }
67507 sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
67508 UPDATE_MAX_BLOBSIZE(pOut);
67509 break;
67510 }
67511
67512 /* Opcode: Move P1 P2 P3 * *
@@ -67516,43 +67178,41 @@
67516 ** registers P2..P2+P3. Registers P1..P1+P3 are
67517 ** left holding a NULL. It is an error for register ranges
67518 ** P1..P1+P3 and P2..P2+P3 to overlap.
67519 */
67520 case OP_Move: {
67521 #if 0 /* local variables moved into u.ae */
67522 char *zMalloc; /* Holding variable for allocated memory */
67523 int n; /* Number of registers left to copy */
67524 int p1; /* Register to copy from */
67525 int p2; /* Register to copy to */
67526 #endif /* local variables moved into u.ae */
67527
67528 u.ae.n = pOp->p3 + 1;
67529 u.ae.p1 = pOp->p1;
67530 u.ae.p2 = pOp->p2;
67531 assert( u.ae.n>0 && u.ae.p1>0 && u.ae.p2>0 );
67532 assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67533
67534 pIn1 = &aMem[u.ae.p1];
67535 pOut = &aMem[u.ae.p2];
67536 while( u.ae.n-- ){
67537 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67538 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67539 assert( memIsValid(pIn1) );
67540 memAboutToChange(p, pOut);
67541 u.ae.zMalloc = pOut->zMalloc;
67542 pOut->zMalloc = 0;
67543 sqlite3VdbeMemMove(pOut, pIn1);
67544 #ifdef SQLITE_DEBUG
67545 if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){
67546 pOut->pScopyFrom += u.ae.p1 - pOp->p2;
67547 }
67548 #endif
67549 pIn1->zMalloc = u.ae.zMalloc;
67550 REGISTER_TRACE(u.ae.p2++, pOut);
67551 pIn1++;
67552 pOut++;
67553 }
67554 break;
67555 }
67556
67557 /* Opcode: Copy P1 P2 P3 * *
67558 ** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67561,26 +67221,24 @@
67561 **
67562 ** This instruction makes a deep copy of the value. A duplicate
67563 ** is made of any string or blob constant. See also OP_SCopy.
67564 */
67565 case OP_Copy: {
67566 #if 0 /* local variables moved into u.af */
67567 int n;
67568 #endif /* local variables moved into u.af */
67569
67570 u.af.n = pOp->p3;
67571 pIn1 = &aMem[pOp->p1];
67572 pOut = &aMem[pOp->p2];
67573 assert( pOut!=pIn1 );
67574 while( 1 ){
67575 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67576 Deephemeralize(pOut);
67577 #ifdef SQLITE_DEBUG
67578 pOut->pScopyFrom = 0;
67579 #endif
67580 REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut);
67581 if( (u.af.n--)==0 ) break;
67582 pOut++;
67583 pIn1++;
67584 }
67585 break;
67586 }
@@ -67617,17 +67275,27 @@
67617 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67618 ** structure to provide access to the top P1 values as the result
67619 ** row.
67620 */
67621 case OP_ResultRow: {
67622 #if 0 /* local variables moved into u.ag */
67623 Mem *pMem;
67624 int i;
67625 #endif /* local variables moved into u.ag */
67626 assert( p->nResColumn==pOp->p2 );
67627 assert( pOp->p1>0 );
67628 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
 
 
 
 
 
 
 
 
 
 
 
 
67629
67630 /* If this statement has violated immediate foreign key constraints, do
67631 ** not return the number of rows modified. And do not RELEASE the statement
67632 ** transaction. It needs to be rolled back. */
67633 if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
@@ -67634,12 +67302,12 @@
67634 assert( db->flags&SQLITE_CountRows );
67635 assert( p->usesStmtJournal );
67636 break;
67637 }
67638
67639 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67640 ** DML statements invoke this opcode to return the number of rows
67641 ** modified to the user. This is the only way that a VM that
67642 ** opens a statement transaction may invoke this opcode.
67643 **
67644 ** In case this is such a statement, close any statement transaction
67645 ** opened by this VM before returning control to the user. This is to
@@ -67662,19 +67330,19 @@
67662
67663 /* Make sure the results of the current row are \000 terminated
67664 ** and have an assigned type. The results are de-ephemeralized as
67665 ** a side effect.
67666 */
67667 u.ag.pMem = p->pResultSet = &aMem[pOp->p1];
67668 for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){
67669 assert( memIsValid(&u.ag.pMem[u.ag.i]) );
67670 Deephemeralize(&u.ag.pMem[u.ag.i]);
67671 assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0
67672 || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 );
67673 sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]);
67674 sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]);
67675 REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]);
67676 }
67677 if( db->mallocFailed ) goto no_mem;
67678
67679 /* Return SQLITE_ROW
67680 */
@@ -67695,13 +67363,11 @@
67695 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67696 ** if P3 is the same register as P2, the implementation is able
67697 ** to avoid a memcpy().
67698 */
67699 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67700 #if 0 /* local variables moved into u.ah */
67701 i64 nByte;
67702 #endif /* local variables moved into u.ah */
67703
67704 pIn1 = &aMem[pOp->p1];
67705 pIn2 = &aMem[pOp->p2];
67706 pOut = &aMem[pOp->p3];
67707 assert( pIn1!=pOut );
@@ -67710,26 +67376,26 @@
67710 break;
67711 }
67712 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67713 Stringify(pIn1, encoding);
67714 Stringify(pIn2, encoding);
67715 u.ah.nByte = pIn1->n + pIn2->n;
67716 if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67717 goto too_big;
67718 }
67719 MemSetTypeFlag(pOut, MEM_Str);
67720 if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
67721 goto no_mem;
67722 }
67723 if( pOut!=pIn2 ){
67724 memcpy(pOut->z, pIn2->z, pIn2->n);
67725 }
67726 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67727 pOut->z[u.ah.nByte]=0;
67728 pOut->z[u.ah.nByte+1] = 0;
67729 pOut->flags |= MEM_Term;
67730 pOut->n = (int)u.ah.nByte;
67731 pOut->enc = encoding;
67732 UPDATE_MAX_BLOBSIZE(pOut);
67733 break;
67734 }
67735
@@ -67754,103 +67420,101 @@
67754 ** Subtract the value in register P1 from the value in register P2
67755 ** and store the result in register P3.
67756 ** If either input is NULL, the result is NULL.
67757 */
67758 /* Opcode: Divide P1 P2 P3 * *
67759 ** Synopsis: r[P3]=r[P1]/r[P2]
67760 **
67761 ** Divide the value in register P1 by the value in register P2
67762 ** and store the result in register P3 (P3=P2/P1). If the value in
67763 ** register P1 is zero, then the result is NULL. If either input is
67764 ** NULL, the result is NULL.
67765 */
67766 /* Opcode: Remainder P1 P2 P3 * *
67767 ** Synopsis: r[P3]=r[P1]%r[P2]
67768 **
67769 ** Compute the remainder after integer division of the value in
67770 ** register P1 by the value in register P2 and store the result in P3.
67771 ** If the value in register P2 is zero the result is NULL.
67772 ** If either operand is NULL, the result is NULL.
67773 */
67774 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67775 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67776 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67777 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67778 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67779 #if 0 /* local variables moved into u.ai */
67780 char bIntint; /* Started out as two integer operands */
67781 int flags; /* Combined MEM_* flags from both inputs */
67782 i64 iA; /* Integer value of left operand */
67783 i64 iB; /* Integer value of right operand */
67784 double rA; /* Real value of left operand */
67785 double rB; /* Real value of right operand */
67786 #endif /* local variables moved into u.ai */
67787
67788 pIn1 = &aMem[pOp->p1];
67789 applyNumericAffinity(pIn1);
67790 pIn2 = &aMem[pOp->p2];
67791 applyNumericAffinity(pIn2);
67792 pOut = &aMem[pOp->p3];
67793 u.ai.flags = pIn1->flags | pIn2->flags;
67794 if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67795 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67796 u.ai.iA = pIn1->u.i;
67797 u.ai.iB = pIn2->u.i;
67798 u.ai.bIntint = 1;
67799 switch( pOp->opcode ){
67800 case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67801 case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67802 case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67803 case OP_Divide: {
67804 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67805 if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math;
67806 u.ai.iB /= u.ai.iA;
67807 break;
67808 }
67809 default: {
67810 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67811 if( u.ai.iA==-1 ) u.ai.iA = 1;
67812 u.ai.iB %= u.ai.iA;
67813 break;
67814 }
67815 }
67816 pOut->u.i = u.ai.iB;
67817 MemSetTypeFlag(pOut, MEM_Int);
67818 }else{
67819 u.ai.bIntint = 0;
67820 fp_math:
67821 u.ai.rA = sqlite3VdbeRealValue(pIn1);
67822 u.ai.rB = sqlite3VdbeRealValue(pIn2);
67823 switch( pOp->opcode ){
67824 case OP_Add: u.ai.rB += u.ai.rA; break;
67825 case OP_Subtract: u.ai.rB -= u.ai.rA; break;
67826 case OP_Multiply: u.ai.rB *= u.ai.rA; break;
67827 case OP_Divide: {
67828 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67829 if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null;
67830 u.ai.rB /= u.ai.rA;
67831 break;
67832 }
67833 default: {
67834 u.ai.iA = (i64)u.ai.rA;
67835 u.ai.iB = (i64)u.ai.rB;
67836 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67837 if( u.ai.iA==-1 ) u.ai.iA = 1;
67838 u.ai.rB = (double)(u.ai.iB % u.ai.iA);
67839 break;
67840 }
67841 }
67842 #ifdef SQLITE_OMIT_FLOATING_POINT
67843 pOut->u.i = u.ai.rB;
67844 MemSetTypeFlag(pOut, MEM_Int);
67845 #else
67846 if( sqlite3IsNaN(u.ai.rB) ){
67847 goto arithmetic_result_is_null;
67848 }
67849 pOut->r = u.ai.rB;
67850 MemSetTypeFlag(pOut, MEM_Real);
67851 if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
67852 sqlite3VdbeIntegerAffinity(pOut);
67853 }
67854 #endif
67855 }
67856 break;
@@ -67899,85 +67563,83 @@
67899 ** invocation of this opcode.
67900 **
67901 ** See also: AggStep and AggFinal
67902 */
67903 case OP_Function: {
67904 #if 0 /* local variables moved into u.aj */
67905 int i;
67906 Mem *pArg;
67907 sqlite3_context ctx;
67908 sqlite3_value **apVal;
67909 int n;
67910 #endif /* local variables moved into u.aj */
67911
67912 u.aj.n = pOp->p5;
67913 u.aj.apVal = p->apArg;
67914 assert( u.aj.apVal || u.aj.n==0 );
67915 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
67916 pOut = &aMem[pOp->p3];
67917 memAboutToChange(p, pOut);
67918
67919 assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) );
67920 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n );
67921 u.aj.pArg = &aMem[pOp->p2];
67922 for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){
67923 assert( memIsValid(u.aj.pArg) );
67924 u.aj.apVal[u.aj.i] = u.aj.pArg;
67925 Deephemeralize(u.aj.pArg);
67926 sqlite3VdbeMemStoreType(u.aj.pArg);
67927 REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
67928 }
67929
67930 assert( pOp->p4type==P4_FUNCDEF );
67931 u.aj.ctx.pFunc = pOp->p4.pFunc;
67932 u.aj.ctx.s.flags = MEM_Null;
67933 u.aj.ctx.s.db = db;
67934 u.aj.ctx.s.xDel = 0;
67935 u.aj.ctx.s.zMalloc = 0;
67936 u.aj.ctx.iOp = pc;
67937 u.aj.ctx.pVdbe = p;
67938
67939 /* The output cell may already have a buffer allocated. Move
67940 ** the pointer to u.aj.ctx.s so in case the user-function can use
67941 ** the already allocated buffer instead of allocating a new one.
67942 */
67943 sqlite3VdbeMemMove(&u.aj.ctx.s, pOut);
67944 MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
 
 
 
67945
67946 u.aj.ctx.fErrorOrAux = 0;
67947 if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67948 assert( pOp>aOp );
67949 assert( pOp[-1].p4type==P4_COLLSEQ );
67950 assert( pOp[-1].opcode==OP_CollSeq );
67951 u.aj.ctx.pColl = pOp[-1].p4.pColl;
67952 }
67953 db->lastRowid = lastRowid;
67954 (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */
67955 lastRowid = db->lastRowid;
67956
67957 if( db->mallocFailed ){
67958 /* Even though a malloc() has failed, the implementation of the
67959 ** user function may have called an sqlite3_result_XXX() function
67960 ** to return a value. The following call releases any resources
67961 ** associated with such a value.
67962 */
67963 sqlite3VdbeMemRelease(&u.aj.ctx.s);
67964 goto no_mem;
67965 }
67966
67967 /* If the function returned an error, throw an exception */
67968 if( u.aj.ctx.fErrorOrAux ){
67969 if( u.aj.ctx.isError ){
67970 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s));
67971 rc = u.aj.ctx.isError;
67972 }
67973 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
67974 }
67975
67976 /* Copy the result of the function into register P3 */
67977 sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
67978 sqlite3VdbeMemMove(pOut, &u.aj.ctx.s);
 
67979 if( sqlite3VdbeMemTooBig(pOut) ){
67980 goto too_big;
67981 }
67982
67983 #if 0
@@ -68025,56 +67687,54 @@
68025 */
68026 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
68027 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
68028 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
68029 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
68030 #if 0 /* local variables moved into u.ak */
68031 i64 iA;
68032 u64 uA;
68033 i64 iB;
68034 u8 op;
68035 #endif /* local variables moved into u.ak */
68036
68037 pIn1 = &aMem[pOp->p1];
68038 pIn2 = &aMem[pOp->p2];
68039 pOut = &aMem[pOp->p3];
68040 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
68041 sqlite3VdbeMemSetNull(pOut);
68042 break;
68043 }
68044 u.ak.iA = sqlite3VdbeIntValue(pIn2);
68045 u.ak.iB = sqlite3VdbeIntValue(pIn1);
68046 u.ak.op = pOp->opcode;
68047 if( u.ak.op==OP_BitAnd ){
68048 u.ak.iA &= u.ak.iB;
68049 }else if( u.ak.op==OP_BitOr ){
68050 u.ak.iA |= u.ak.iB;
68051 }else if( u.ak.iB!=0 ){
68052 assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft );
68053
68054 /* If shifting by a negative amount, shift in the other direction */
68055 if( u.ak.iB<0 ){
68056 assert( OP_ShiftRight==OP_ShiftLeft+1 );
68057 u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op;
68058 u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64;
68059 }
68060
68061 if( u.ak.iB>=64 ){
68062 u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1;
68063 }else{
68064 memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA));
68065 if( u.ak.op==OP_ShiftLeft ){
68066 u.ak.uA <<= u.ak.iB;
68067 }else{
68068 u.ak.uA >>= u.ak.iB;
68069 /* Sign-extend on a right shift of a negative number */
68070 if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB);
68071 }
68072 memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
68073 }
68074 }
68075 pOut->u.i = u.ak.iA;
68076 MemSetTypeFlag(pOut, MEM_Int);
68077 break;
68078 }
68079
68080 /* Opcode: AddImm P1 P2 * * *
@@ -68100,21 +67760,23 @@
68100 ** without data loss, then jump immediately to P2, or if P2==0
68101 ** raise an SQLITE_MISMATCH exception.
68102 */
68103 case OP_MustBeInt: { /* jump, in1 */
68104 pIn1 = &aMem[pOp->p1];
68105 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
68106 if( (pIn1->flags & MEM_Int)==0 ){
68107 if( pOp->p2==0 ){
68108 rc = SQLITE_MISMATCH;
68109 goto abort_due_to_error;
68110 }else{
68111 pc = pOp->p2 - 1;
68112 }
68113 }else{
68114 MemSetTypeFlag(pIn1, MEM_Int);
68115 }
 
 
 
68116 break;
68117 }
68118
68119 #ifndef SQLITE_OMIT_FLOATING_POINT
68120 /* Opcode: RealAffinity P1 * * * *
@@ -68235,11 +67897,11 @@
68235 break;
68236 }
68237 #endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
68238
68239 /* Opcode: Lt P1 P2 P3 P4 P5
68240 ** Synopsis: if r[P1]<r[P3] goto P3
68241 **
68242 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
68243 ** jump to address P2.
68244 **
68245 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -68322,37 +67984,35 @@
68322 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
68323 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
68324 case OP_Le: /* same as TK_LE, jump, in1, in3 */
68325 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
68326 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
68327 #if 0 /* local variables moved into u.al */
68328 int res; /* Result of the comparison of pIn1 against pIn3 */
68329 char affinity; /* Affinity to use for comparison */
68330 u16 flags1; /* Copy of initial value of pIn1->flags */
68331 u16 flags3; /* Copy of initial value of pIn3->flags */
68332 #endif /* local variables moved into u.al */
68333
68334 pIn1 = &aMem[pOp->p1];
68335 pIn3 = &aMem[pOp->p3];
68336 u.al.flags1 = pIn1->flags;
68337 u.al.flags3 = pIn3->flags;
68338 if( (u.al.flags1 | u.al.flags3)&MEM_Null ){
68339 /* One or both operands are NULL */
68340 if( pOp->p5 & SQLITE_NULLEQ ){
68341 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
68342 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68343 ** or not both operands are null.
68344 */
68345 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68346 assert( (u.al.flags1 & MEM_Cleared)==0 );
68347 if( (u.al.flags1&MEM_Null)!=0
68348 && (u.al.flags3&MEM_Null)!=0
68349 && (u.al.flags3&MEM_Cleared)==0
68350 ){
68351 u.al.res = 0; /* Results are equal */
68352 }else{
68353 u.al.res = 1; /* Results are not equal */
68354 }
68355 }else{
68356 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68357 ** then the result is always NULL.
68358 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68366,44 +68026,44 @@
68366 }
68367 break;
68368 }
68369 }else{
68370 /* Neither operand is NULL. Do a comparison. */
68371 u.al.affinity = pOp->p5 & SQLITE_AFF_MASK;
68372 if( u.al.affinity ){
68373 applyAffinity(pIn1, u.al.affinity, encoding);
68374 applyAffinity(pIn3, u.al.affinity, encoding);
68375 if( db->mallocFailed ) goto no_mem;
68376 }
68377
68378 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68379 ExpandBlob(pIn1);
68380 ExpandBlob(pIn3);
68381 u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68382 }
68383 switch( pOp->opcode ){
68384 case OP_Eq: u.al.res = u.al.res==0; break;
68385 case OP_Ne: u.al.res = u.al.res!=0; break;
68386 case OP_Lt: u.al.res = u.al.res<0; break;
68387 case OP_Le: u.al.res = u.al.res<=0; break;
68388 case OP_Gt: u.al.res = u.al.res>0; break;
68389 default: u.al.res = u.al.res>=0; break;
68390 }
68391
68392 if( pOp->p5 & SQLITE_STOREP2 ){
68393 pOut = &aMem[pOp->p2];
68394 memAboutToChange(p, pOut);
68395 MemSetTypeFlag(pOut, MEM_Int);
68396 pOut->u.i = u.al.res;
68397 REGISTER_TRACE(pOp->p2, pOut);
68398 }else if( u.al.res ){
68399 pc = pOp->p2-1;
68400 }
68401
68402 /* Undo any changes made by applyAffinity() to the input registers. */
68403 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask);
68404 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask);
68405 break;
68406 }
68407
68408 /* Opcode: Permutation * * * P4 *
68409 **
@@ -68439,51 +68099,49 @@
68439 ** The comparison is a sort comparison, so NULLs compare equal,
68440 ** NULLs are less than numbers, numbers are less than strings,
68441 ** and strings are less than blobs.
68442 */
68443 case OP_Compare: {
68444 #if 0 /* local variables moved into u.am */
68445 int n;
68446 int i;
68447 int p1;
68448 int p2;
68449 const KeyInfo *pKeyInfo;
68450 int idx;
68451 CollSeq *pColl; /* Collating sequence to use on this term */
68452 int bRev; /* True for DESCENDING sort order */
68453 #endif /* local variables moved into u.am */
68454
68455 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68456 u.am.n = pOp->p3;
68457 u.am.pKeyInfo = pOp->p4.pKeyInfo;
68458 assert( u.am.n>0 );
68459 assert( u.am.pKeyInfo!=0 );
68460 u.am.p1 = pOp->p1;
68461 u.am.p2 = pOp->p2;
68462 #if SQLITE_DEBUG
68463 if( aPermute ){
68464 int k, mx = 0;
68465 for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68466 assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 );
68467 assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 );
68468 }else{
68469 assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 );
68470 assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 );
68471 }
68472 #endif /* SQLITE_DEBUG */
68473 for(u.am.i=0; u.am.i<u.am.n; u.am.i++){
68474 u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i;
68475 assert( memIsValid(&aMem[u.am.p1+u.am.idx]) );
68476 assert( memIsValid(&aMem[u.am.p2+u.am.idx]) );
68477 REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]);
68478 REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]);
68479 assert( u.am.i<u.am.pKeyInfo->nField );
68480 u.am.pColl = u.am.pKeyInfo->aColl[u.am.i];
68481 u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i];
68482 iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl);
68483 if( iCompare ){
68484 if( u.am.bRev ) iCompare = -iCompare;
68485 break;
68486 }
68487 }
68488 aPermute = 0;
68489 break;
@@ -68526,39 +68184,37 @@
68526 ** even if the other input is NULL. A NULL and false or two NULLs
68527 ** give a NULL output.
68528 */
68529 case OP_And: /* same as TK_AND, in1, in2, out3 */
68530 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68531 #if 0 /* local variables moved into u.an */
68532 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68533 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68534 #endif /* local variables moved into u.an */
68535
68536 pIn1 = &aMem[pOp->p1];
68537 if( pIn1->flags & MEM_Null ){
68538 u.an.v1 = 2;
68539 }else{
68540 u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68541 }
68542 pIn2 = &aMem[pOp->p2];
68543 if( pIn2->flags & MEM_Null ){
68544 u.an.v2 = 2;
68545 }else{
68546 u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68547 }
68548 if( pOp->opcode==OP_And ){
68549 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68550 u.an.v1 = and_logic[u.an.v1*3+u.an.v2];
68551 }else{
68552 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68553 u.an.v1 = or_logic[u.an.v1*3+u.an.v2];
68554 }
68555 pOut = &aMem[pOp->p3];
68556 if( u.an.v1==2 ){
68557 MemSetTypeFlag(pOut, MEM_Null);
68558 }else{
68559 pOut->u.i = u.an.v1;
68560 MemSetTypeFlag(pOut, MEM_Int);
68561 }
68562 break;
68563 }
68564
@@ -68625,25 +68281,23 @@
68625 ** is considered false if it has a numeric value of zero. If the value
68626 ** in P1 is NULL then take the jump if P3 is zero.
68627 */
68628 case OP_If: /* jump, in1 */
68629 case OP_IfNot: { /* jump, in1 */
68630 #if 0 /* local variables moved into u.ao */
68631 int c;
68632 #endif /* local variables moved into u.ao */
68633 pIn1 = &aMem[pOp->p1];
68634 if( pIn1->flags & MEM_Null ){
68635 u.ao.c = pOp->p3;
68636 }else{
68637 #ifdef SQLITE_OMIT_FLOATING_POINT
68638 u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
68639 #else
68640 u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68641 #endif
68642 if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
68643 }
68644 if( u.ao.c ){
68645 pc = pOp->p2-1;
68646 }
68647 break;
68648 }
68649
@@ -68697,157 +68351,107 @@
68697 ** the result is guaranteed to only be used as the argument of a length()
68698 ** or typeof() function, respectively. The loading of large blobs can be
68699 ** skipped for length() and all content loading can be skipped for typeof().
68700 */
68701 case OP_Column: {
68702 #if 0 /* local variables moved into u.ap */
68703 u32 payloadSize; /* Number of bytes in the record */
68704 i64 payloadSize64; /* Number of bytes in the record */
68705 int p1; /* P1 value of the opcode */
68706 int p2; /* column number to retrieve */
68707 VdbeCursor *pC; /* The VDBE cursor */
68708 char *zRec; /* Pointer to complete record-data */
68709 BtCursor *pCrsr; /* The BTree cursor */
68710 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
68711 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
68712 int nField; /* number of fields in the record */
68713 int len; /* The length of the serialized data for the column */
68714 int i; /* Loop counter */
68715 char *zData; /* Part of the record being decoded */
68716 Mem *pDest; /* Where to write the extracted value */
68717 Mem sMem; /* For storing the record being decoded */
68718 u8 *zIdx; /* Index into header */
68719 u8 *zEndHdr; /* Pointer to first byte after the header */
 
68720 u32 offset; /* Offset into the data */
68721 u32 szField; /* Number of bytes in the content of a field */
68722 int szHdr; /* Size of the header size field at start of record */
68723 int avail; /* Number of bytes of available data */
68724 u32 t; /* A type code from the record header */
68725 Mem *pReg; /* PseudoTable input register */
68726 #endif /* local variables moved into u.ap */
68727
68728
68729 u.ap.p1 = pOp->p1;
68730 u.ap.p2 = pOp->p2;
68731 u.ap.pC = 0;
68732 memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
68733 assert( u.ap.p1<p->nCursor );
68734 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68735 u.ap.pDest = &aMem[pOp->p3];
68736 memAboutToChange(p, u.ap.pDest);
68737 u.ap.zRec = 0;
68738
68739 /* This block sets the variable u.ap.payloadSize to be the total number of
68740 ** bytes in the record.
68741 **
68742 ** u.ap.zRec is set to be the complete text of the record if it is available.
68743 ** The complete record text is always available for pseudo-tables
68744 ** If the record is stored in a cursor, the complete record text
68745 ** might be available in the u.ap.pC->aRow cache. Or it might not be.
68746 ** If the data is unavailable, u.ap.zRec is set to NULL.
68747 **
68748 ** We also compute the number of columns in the record. For cursors,
68749 ** the number of columns is stored in the VdbeCursor.nField element.
68750 */
68751 u.ap.pC = p->apCsr[u.ap.p1];
68752 assert( u.ap.pC!=0 );
68753 #ifndef SQLITE_OMIT_VIRTUALTABLE
68754 assert( u.ap.pC->pVtabCursor==0 );
68755 #endif
68756 u.ap.pCrsr = u.ap.pC->pCursor;
68757 if( u.ap.pCrsr!=0 ){
68758 /* The record is stored in a B-Tree */
68759 rc = sqlite3VdbeCursorMoveto(u.ap.pC);
68760 if( rc ) goto abort_due_to_error;
68761 if( u.ap.pC->nullRow ){
68762 u.ap.payloadSize = 0;
68763 }else if( u.ap.pC->cacheStatus==p->cacheCtr ){
68764 u.ap.payloadSize = u.ap.pC->payloadSize;
68765 u.ap.zRec = (char*)u.ap.pC->aRow;
68766 }else if( u.ap.pC->isIndex ){
68767 assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68768 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
68769 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68770 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68771 ** payload size, so it is impossible for u.ap.payloadSize64 to be
68772 ** larger than 32 bits. */
68773 assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
68774 u.ap.payloadSize = (u32)u.ap.payloadSize64;
68775 }else{
68776 assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68777 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.payloadSize);
68778 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68779 }
68780 }else{
68781 assert( u.ap.pC->pseudoTableReg>0 );
68782 u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
68783 if( u.ap.pC->multiPseudo ){
68784 sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
68785 Deephemeralize(u.ap.pDest);
68786 goto op_column_out;
68787 }
68788 assert( u.ap.pReg->flags & MEM_Blob );
68789 assert( memIsValid(u.ap.pReg) );
68790 u.ap.payloadSize = u.ap.pReg->n;
68791 u.ap.zRec = u.ap.pReg->z;
68792 u.ap.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
68793 assert( u.ap.payloadSize==0 || u.ap.zRec!=0 );
68794 }
68795
68796 /* If u.ap.payloadSize is 0, then just store a NULL. This can happen because of
68797 ** nullRow or because of a corrupt database. */
68798 if( u.ap.payloadSize==0 ){
68799 MemSetTypeFlag(u.ap.pDest, MEM_Null);
68800 goto op_column_out;
68801 }
68802 assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
68803 if( u.ap.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68804 goto too_big;
68805 }
68806
68807 u.ap.nField = u.ap.pC->nField;
68808 assert( u.ap.p2<u.ap.nField );
68809
68810 /* Read and parse the table header. Store the results of the parse
68811 ** into the record header cache fields of the cursor.
68812 */
68813 u.ap.aType = u.ap.pC->aType;
68814 if( u.ap.pC->cacheStatus==p->cacheCtr ){
68815 u.ap.aOffset = u.ap.pC->aOffset;
68816 }else{
68817 assert(u.ap.aType);
68818 u.ap.avail = 0;
68819 u.ap.pC->aOffset = u.ap.aOffset = &u.ap.aType[u.ap.nField];
68820 u.ap.pC->payloadSize = u.ap.payloadSize;
68821 u.ap.pC->cacheStatus = p->cacheCtr;
68822
68823 /* Figure out how many bytes are in the header */
68824 if( u.ap.zRec ){
68825 u.ap.zData = u.ap.zRec;
68826 }else{
68827 if( u.ap.pC->isIndex ){
68828 u.ap.zData = (char*)sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
68829 }else{
68830 u.ap.zData = (char*)sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
68831 }
68832 /* If KeyFetch()/DataFetch() managed to get the entire payload,
68833 ** save the payload in the u.ap.pC->aRow cache. That will save us from
68834 ** having to make additional calls to fetch the content portion of
68835 ** the record.
68836 */
68837 assert( u.ap.avail>=0 );
68838 if( u.ap.payloadSize <= (u32)u.ap.avail ){
68839 u.ap.zRec = u.ap.zData;
68840 u.ap.pC->aRow = (u8*)u.ap.zData;
68841 }else{
68842 u.ap.pC->aRow = 0;
68843 }
68844 }
68845 /* The following assert is true in all cases except when
68846 ** the database file has been corrupted externally.
68847 ** assert( u.ap.zRec!=0 || u.ap.avail>=u.ap.payloadSize || u.ap.avail>=9 ); */
68848 u.ap.szHdr = getVarint32((u8*)u.ap.zData, u.ap.offset);
68849
68850 /* Make sure a corrupt database has not given us an oversize header.
68851 ** Do this now to avoid an oversize memory allocation.
68852 **
68853 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68854,161 +68458,154 @@
68854 ** types use so much data space that there can only be 4096 and 32 of
68855 ** them, respectively. So the maximum header length results from a
68856 ** 3-byte type for each of the maximum of 32768 columns plus three
68857 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68858 */
68859 if( u.ap.offset > 98307 ){
68860 rc = SQLITE_CORRUPT_BKPT;
68861 goto op_column_out;
68862 }
68863
68864 /* Compute in u.ap.len the number of bytes of data we need to read in order
68865 ** to get u.ap.nField type values. u.ap.offset is an upper bound on this. But
68866 ** u.ap.nField might be significantly less than the true number of columns
68867 ** in the table, and in that case, 5*u.ap.nField+3 might be smaller than u.ap.offset.
68868 ** We want to minimize u.ap.len in order to limit the size of the memory
68869 ** allocation, especially if a corrupt database file has caused u.ap.offset
68870 ** to be oversized. Offset is limited to 98307 above. But 98307 might
68871 ** still exceed Robson memory allocation limits on some configurations.
68872 ** On systems that cannot tolerate large memory allocations, u.ap.nField*5+3
68873 ** will likely be much smaller since u.ap.nField will likely be less than
68874 ** 20 or so. This insures that Robson memory allocation limits are
68875 ** not exceeded even for corrupt database files.
68876 */
68877 u.ap.len = u.ap.nField*5 + 3;
68878 if( u.ap.len > (int)u.ap.offset ) u.ap.len = (int)u.ap.offset;
68879
68880 /* The KeyFetch() or DataFetch() above are fast and will get the entire
68881 ** record header in most cases. But they will fail to get the complete
68882 ** record header if the record header does not fit on a single page
68883 ** in the B-Tree. When that happens, use sqlite3VdbeMemFromBtree() to
68884 ** acquire the complete header text.
68885 */
68886 if( !u.ap.zRec && u.ap.avail<u.ap.len ){
68887 u.ap.sMem.flags = 0;
68888 u.ap.sMem.db = 0;
68889 rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.len, u.ap.pC->isIndex, &u.ap.sMem);
68890 if( rc!=SQLITE_OK ){
68891 goto op_column_out;
68892 }
68893 u.ap.zData = u.ap.sMem.z;
68894 }
68895 u.ap.zEndHdr = (u8 *)&u.ap.zData[u.ap.len];
68896 u.ap.zIdx = (u8 *)&u.ap.zData[u.ap.szHdr];
68897
68898 /* Scan the header and use it to fill in the u.ap.aType[] and u.ap.aOffset[]
68899 ** arrays. u.ap.aType[u.ap.i] will contain the type integer for the u.ap.i-th
68900 ** column and u.ap.aOffset[u.ap.i] will contain the u.ap.offset from the beginning
68901 ** of the record to the start of the data for the u.ap.i-th column
68902 */
68903 for(u.ap.i=0; u.ap.i<u.ap.nField; u.ap.i++){
68904 if( u.ap.zIdx<u.ap.zEndHdr ){
68905 u.ap.aOffset[u.ap.i] = u.ap.offset;
68906 if( u.ap.zIdx[0]<0x80 ){
68907 u.ap.t = u.ap.zIdx[0];
68908 u.ap.zIdx++;
68909 }else{
68910 u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t);
68911 }
68912 u.ap.aType[u.ap.i] = u.ap.t;
68913 u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68914 u.ap.offset += u.ap.szField;
68915 if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */
68916 u.ap.zIdx = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68917 break;
68918 }
68919 }else{
68920 /* If u.ap.i is less that u.ap.nField, then there are fewer fields in this
68921 ** record than SetNumColumns indicated there are columns in the
68922 ** table. Set the u.ap.offset for any extra columns not present in
68923 ** the record to 0. This tells code below to store the default value
68924 ** for the column instead of deserializing a value from the record.
68925 */
68926 u.ap.aOffset[u.ap.i] = 0;
68927 }
68928 }
68929 sqlite3VdbeMemRelease(&u.ap.sMem);
68930 u.ap.sMem.flags = MEM_Null;
68931
68932 /* If we have read more header data than was contained in the header,
68933 ** or if the end of the last field appears to be past the end of the
68934 ** record, or if the end of the last field appears to be before the end
68935 ** of the record (when all fields present), then we must be dealing
68936 ** with a corrupt database.
68937 */
68938 if( (u.ap.zIdx > u.ap.zEndHdr) || (u.ap.offset > u.ap.payloadSize)
68939 || (u.ap.zIdx==u.ap.zEndHdr && u.ap.offset!=u.ap.payloadSize) ){
68940 rc = SQLITE_CORRUPT_BKPT;
68941 goto op_column_out;
68942 }
68943 }
68944
68945 /* Get the column information. If u.ap.aOffset[u.ap.p2] is non-zero, then
68946 ** deserialize the value from the record. If u.ap.aOffset[u.ap.p2] is zero,
68947 ** then there are not enough fields in the record to satisfy the
68948 ** request. In this case, set the value NULL or to P4 if P4 is
68949 ** a pointer to a Mem object.
68950 */
68951 if( u.ap.aOffset[u.ap.p2] ){
68952 assert( rc==SQLITE_OK );
68953 if( u.ap.zRec ){
68954 /* This is the common case where the whole row fits on a single page */
68955 VdbeMemRelease(u.ap.pDest);
68956 sqlite3VdbeSerialGet((u8 *)&u.ap.zRec[u.ap.aOffset[u.ap.p2]], u.ap.aType[u.ap.p2], u.ap.pDest);
68957 }else{
68958 /* This branch happens only when the row overflows onto multiple pages */
68959 u.ap.t = u.ap.aType[u.ap.p2];
68960 if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68961 && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)
68962 ){
68963 /* Content is irrelevant for the typeof() function and for
68964 ** the length(X) function if X is a blob. So we might as well use
68965 ** bogus content rather than reading content from disk. NULL works
68966 ** for text and blob and whatever is in the u.ap.payloadSize64 variable
68967 ** will work for everything else. */
68968 u.ap.zData = u.ap.t<12 ? (char*)&u.ap.payloadSize64 : 0;
68969 }else{
68970 u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t);
68971 sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
68972 rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, u.ap.pC->isIndex,
68973 &u.ap.sMem);
68974 if( rc!=SQLITE_OK ){
68975 goto op_column_out;
68976 }
68977 u.ap.zData = u.ap.sMem.z;
68978 }
68979 sqlite3VdbeSerialGet((u8*)u.ap.zData, u.ap.t, u.ap.pDest);
68980 }
68981 u.ap.pDest->enc = encoding;
68982 }else{
68983 if( pOp->p4type==P4_MEM ){
68984 sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
68985 }else{
68986 MemSetTypeFlag(u.ap.pDest, MEM_Null);
68987 }
68988 }
68989
68990 /* If we dynamically allocated space to hold the data (in the
68991 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68992 ** dynamically allocated space over to the u.ap.pDest structure.
68993 ** This prevents a memory copy.
68994 */
68995 if( u.ap.sMem.zMalloc ){
68996 assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
68997 assert( !(u.ap.pDest->flags & MEM_Dyn) );
68998 assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
68999 u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
69000 u.ap.pDest->flags |= MEM_Term;
69001 u.ap.pDest->z = u.ap.sMem.z;
69002 u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
69003 }
69004
69005 rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
69006
69007 op_column_out:
69008 UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69009 REGISTER_TRACE(pOp->p3, u.ap.pDest);
69010 break;
69011 }
69012
69013 /* Opcode: Affinity P1 P2 * P4 *
69014 ** Synopsis: affinity(r[P1@P2])
@@ -69018,24 +68615,22 @@
69018 ** P4 is a string that is P2 characters long. The nth character of the
69019 ** string indicates the column affinity that should be used for the nth
69020 ** memory cell in the range.
69021 */
69022 case OP_Affinity: {
69023 #if 0 /* local variables moved into u.aq */
69024 const char *zAffinity; /* The affinity to be applied */
69025 char cAff; /* A single character of affinity */
69026 #endif /* local variables moved into u.aq */
69027
69028 u.aq.zAffinity = pOp->p4.z;
69029 assert( u.aq.zAffinity!=0 );
69030 assert( u.aq.zAffinity[pOp->p2]==0 );
69031 pIn1 = &aMem[pOp->p1];
69032 while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
69033 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
69034 assert( memIsValid(pIn1) );
69035 ExpandBlob(pIn1);
69036 applyAffinity(pIn1, u.aq.cAff, encoding);
69037 pIn1++;
69038 }
69039 break;
69040 }
69041
@@ -69054,11 +68649,10 @@
69054 ** macros defined in sqliteInt.h.
69055 **
69056 ** If P4 is NULL then all index fields have the affinity NONE.
69057 */
69058 case OP_MakeRecord: {
69059 #if 0 /* local variables moved into u.ar */
69060 u8 *zNewRecord; /* A buffer to hold the data for the new record */
69061 Mem *pRec; /* The new record */
69062 u64 nData; /* Number of bytes of data space */
69063 int nHdr; /* Number of bytes of header space */
69064 i64 nByte; /* Data space required for this record */
@@ -69068,106 +68662,123 @@
69068 Mem *pData0; /* First field to be combined into the record */
69069 Mem *pLast; /* Last field of the record */
69070 int nField; /* Number of fields in the record */
69071 char *zAffinity; /* The affinity string for the record */
69072 int file_format; /* File format to use for encoding */
69073 int i; /* Space used in zNewRecord[] */
 
69074 int len; /* Length of a field */
69075 #endif /* local variables moved into u.ar */
69076
69077 /* Assuming the record contains N fields, the record format looks
69078 ** like this:
69079 **
69080 ** ------------------------------------------------------------------------
69081 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
69082 ** ------------------------------------------------------------------------
69083 **
69084 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
69085 ** and so froth.
69086 **
69087 ** Each type field is a varint representing the serial type of the
69088 ** corresponding data element (see sqlite3VdbeSerialType()). The
69089 ** hdr-size field is also a varint which is the offset from the beginning
69090 ** of the record to data0.
69091 */
69092 u.ar.nData = 0; /* Number of bytes of data space */
69093 u.ar.nHdr = 0; /* Number of bytes of header space */
69094 u.ar.nZero = 0; /* Number of zero bytes at the end of the record */
69095 u.ar.nField = pOp->p1;
69096 u.ar.zAffinity = pOp->p4.z;
69097 assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 );
69098 u.ar.pData0 = &aMem[u.ar.nField];
69099 u.ar.nField = pOp->p2;
69100 u.ar.pLast = &u.ar.pData0[u.ar.nField-1];
69101 u.ar.file_format = p->minWriteFileFormat;
69102
69103 /* Identify the output register */
69104 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
69105 pOut = &aMem[pOp->p3];
69106 memAboutToChange(p, pOut);
 
 
 
 
 
 
 
 
 
 
69107
69108 /* Loop through the elements that will make up the record to figure
69109 ** out how much space is required for the new record.
69110 */
69111 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69112 assert( memIsValid(u.ar.pRec) );
69113 if( u.ar.zAffinity ){
69114 applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding);
69115 }
69116 if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){
69117 sqlite3VdbeMemExpandBlob(u.ar.pRec);
69118 }
69119 u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69120 u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type);
69121 u.ar.nData += u.ar.len;
69122 u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type);
69123 if( u.ar.pRec->flags & MEM_Zero ){
69124 /* Only pure zero-filled BLOBs can be input to this Opcode.
69125 ** We do not allow blobs with a prefix and a zero-filled tail. */
69126 u.ar.nZero += u.ar.pRec->u.nZero;
69127 }else if( u.ar.len ){
69128 u.ar.nZero = 0;
69129 }
69130 }
69131
69132 /* Add the initial header varint and total the size */
69133 u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr);
69134 if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){
69135 u.ar.nHdr++;
 
 
 
 
 
 
 
69136 }
69137 u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero;
69138 if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69139 goto too_big;
69140 }
69141
69142 /* Make sure the output register has a buffer large enough to store
69143 ** the new record. The output register (pOp->p3) is not allowed to
69144 ** be one of the input registers (because the following call to
69145 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
69146 */
69147 if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
69148 goto no_mem;
69149 }
69150 u.ar.zNewRecord = (u8 *)pOut->z;
69151
69152 /* Write the record */
69153 u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr);
69154 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69155 u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69156 u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */
69157 }
69158 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */
69159 u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format);
69160 }
69161 assert( u.ar.i==u.ar.nByte );
 
 
69162
69163 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69164 pOut->n = (int)u.ar.nByte;
69165 pOut->flags = MEM_Blob | MEM_Dyn;
69166 pOut->xDel = 0;
69167 if( u.ar.nZero ){
69168 pOut->u.nZero = u.ar.nZero;
69169 pOut->flags |= MEM_Zero;
69170 }
69171 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
69172 REGISTER_TRACE(pOp->p3, pOut);
69173 UPDATE_MAX_BLOBSIZE(pOut);
@@ -69180,19 +68791,18 @@
69180 ** Store the number of entries (an integer value) in the table or index
69181 ** opened by cursor P1 in register P2
69182 */
69183 #ifndef SQLITE_OMIT_BTREECOUNT
69184 case OP_Count: { /* out2-prerelease */
69185 #if 0 /* local variables moved into u.as */
69186 i64 nEntry;
69187 BtCursor *pCrsr;
69188 #endif /* local variables moved into u.as */
69189
69190 u.as.pCrsr = p->apCsr[pOp->p1]->pCursor;
69191 assert( u.as.pCrsr );
69192 rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry);
69193 pOut->u.i = u.as.nEntry;
 
69194 break;
69195 }
69196 #endif
69197
69198 /* Opcode: Savepoint P1 * * P4 *
@@ -69200,43 +68810,41 @@
69200 ** Open, release or rollback the savepoint named by parameter P4, depending
69201 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
69202 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
69203 */
69204 case OP_Savepoint: {
69205 #if 0 /* local variables moved into u.at */
69206 int p1; /* Value of P1 operand */
69207 char *zName; /* Name of savepoint */
69208 int nName;
69209 Savepoint *pNew;
69210 Savepoint *pSavepoint;
69211 Savepoint *pTmp;
69212 int iSavepoint;
69213 int ii;
69214 #endif /* local variables moved into u.at */
69215
69216 u.at.p1 = pOp->p1;
69217 u.at.zName = pOp->p4.z;
69218
69219 /* Assert that the u.at.p1 parameter is valid. Also that if there is no open
69220 ** transaction, then there cannot be any savepoints.
69221 */
69222 assert( db->pSavepoint==0 || db->autoCommit==0 );
69223 assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK );
69224 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
69225 assert( checkSavepointCount(db) );
69226 assert( p->bIsReader );
69227
69228 if( u.at.p1==SAVEPOINT_BEGIN ){
69229 if( db->nVdbeWrite>0 ){
69230 /* A new savepoint cannot be created if there are active write
69231 ** statements (i.e. open read/write incremental blob handles).
69232 */
69233 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
69234 "SQL statements in progress");
69235 rc = SQLITE_BUSY;
69236 }else{
69237 u.at.nName = sqlite3Strlen30(u.at.zName);
69238
69239 #ifndef SQLITE_OMIT_VIRTUALTABLE
69240 /* This call is Ok even if this savepoint is actually a transaction
69241 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
69242 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -69246,62 +68854,62 @@
69246 db->nStatement+db->nSavepoint);
69247 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69248 #endif
69249
69250 /* Create a new savepoint structure. */
69251 u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1);
69252 if( u.at.pNew ){
69253 u.at.pNew->zName = (char *)&u.at.pNew[1];
69254 memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1);
69255
69256 /* If there is no open transaction, then mark this as a special
69257 ** "transaction savepoint". */
69258 if( db->autoCommit ){
69259 db->autoCommit = 0;
69260 db->isTransactionSavepoint = 1;
69261 }else{
69262 db->nSavepoint++;
69263 }
69264
69265 /* Link the new savepoint into the database handle's list. */
69266 u.at.pNew->pNext = db->pSavepoint;
69267 db->pSavepoint = u.at.pNew;
69268 u.at.pNew->nDeferredCons = db->nDeferredCons;
69269 u.at.pNew->nDeferredImmCons = db->nDeferredImmCons;
69270 }
69271 }
69272 }else{
69273 u.at.iSavepoint = 0;
69274
69275 /* Find the named savepoint. If there is no such savepoint, then an
69276 ** an error is returned to the user. */
69277 for(
69278 u.at.pSavepoint = db->pSavepoint;
69279 u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName);
69280 u.at.pSavepoint = u.at.pSavepoint->pNext
69281 ){
69282 u.at.iSavepoint++;
69283 }
69284 if( !u.at.pSavepoint ){
69285 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName);
69286 rc = SQLITE_ERROR;
69287 }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){
69288 /* It is not possible to release (commit) a savepoint if there are
69289 ** active write statements.
69290 */
69291 sqlite3SetString(&p->zErrMsg, db,
69292 "cannot release savepoint - SQL statements in progress"
69293 );
69294 rc = SQLITE_BUSY;
69295 }else{
69296
69297 /* Determine whether or not this is a transaction savepoint. If so,
69298 ** and this is a RELEASE command, then the current transaction
69299 ** is committed.
69300 */
69301 int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint;
69302 if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){
69303 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69304 goto vdbe_return;
69305 }
69306 db->autoCommit = 1;
69307 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69311,56 +68919,56 @@
69311 goto vdbe_return;
69312 }
69313 db->isTransactionSavepoint = 0;
69314 rc = p->rc;
69315 }else{
69316 u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1;
69317 if( u.at.p1==SAVEPOINT_ROLLBACK ){
69318 for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69319 sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT);
69320 }
69321 }
69322 for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69323 rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint);
69324 if( rc!=SQLITE_OK ){
69325 goto abort_due_to_error;
69326 }
69327 }
69328 if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
69329 sqlite3ExpirePreparedStatements(db);
69330 sqlite3ResetAllSchemasOfConnection(db);
69331 db->flags = (db->flags | SQLITE_InternChanges);
69332 }
69333 }
69334
69335 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
69336 ** savepoints nested inside of the savepoint being operated on. */
69337 while( db->pSavepoint!=u.at.pSavepoint ){
69338 u.at.pTmp = db->pSavepoint;
69339 db->pSavepoint = u.at.pTmp->pNext;
69340 sqlite3DbFree(db, u.at.pTmp);
69341 db->nSavepoint--;
69342 }
69343
69344 /* If it is a RELEASE, then destroy the savepoint being operated on
69345 ** too. If it is a ROLLBACK TO, then set the number of deferred
69346 ** constraint violations present in the database to the value stored
69347 ** when the savepoint was created. */
69348 if( u.at.p1==SAVEPOINT_RELEASE ){
69349 assert( u.at.pSavepoint==db->pSavepoint );
69350 db->pSavepoint = u.at.pSavepoint->pNext;
69351 sqlite3DbFree(db, u.at.pSavepoint);
69352 if( !isTransaction ){
69353 db->nSavepoint--;
69354 }
69355 }else{
69356 db->nDeferredCons = u.at.pSavepoint->nDeferredCons;
69357 db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons;
69358 }
69359
69360 if( !isTransaction ){
69361 rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
69362 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69363 }
69364 }
69365 }
69366
@@ -69375,54 +68983,52 @@
69375 ** there are active writing VMs or active VMs that use shared cache.
69376 **
69377 ** This instruction causes the VM to halt.
69378 */
69379 case OP_AutoCommit: {
69380 #if 0 /* local variables moved into u.au */
69381 int desiredAutoCommit;
69382 int iRollback;
69383 int turnOnAC;
69384 #endif /* local variables moved into u.au */
69385
69386 u.au.desiredAutoCommit = pOp->p1;
69387 u.au.iRollback = pOp->p2;
69388 u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit;
69389 assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 );
69390 assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 );
69391 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
69392 assert( p->bIsReader );
69393
69394 #if 0
69395 if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
69396 /* If this instruction implements a ROLLBACK and other VMs are
69397 ** still running, and a transaction is active, return an error indicating
69398 ** that the other VMs must complete first.
69399 */
69400 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69401 "SQL statements in progress");
69402 rc = SQLITE_BUSY;
69403 }else
69404 #endif
69405 if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
69406 /* If this instruction implements a COMMIT and other VMs are writing
69407 ** return an error indicating that the other VMs must complete first.
69408 */
69409 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69410 "SQL statements in progress");
69411 rc = SQLITE_BUSY;
69412 }else if( u.au.desiredAutoCommit!=db->autoCommit ){
69413 if( u.au.iRollback ){
69414 assert( u.au.desiredAutoCommit==1 );
69415 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69416 db->autoCommit = 1;
69417 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69418 goto vdbe_return;
69419 }else{
69420 db->autoCommit = (u8)u.au.desiredAutoCommit;
69421 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69422 p->pc = pc;
69423 db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
69424 p->rc = rc = SQLITE_BUSY;
69425 goto vdbe_return;
69426 }
69427 }
69428 assert( db->nStatement==0 );
@@ -69433,14 +69039,14 @@
69433 rc = SQLITE_ERROR;
69434 }
69435 goto vdbe_return;
69436 }else{
69437 sqlite3SetString(&p->zErrMsg, db,
69438 (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69439 (u.au.iRollback)?"cannot rollback - no transaction is active":
69440 "cannot commit - no transaction is active"));
69441
69442 rc = SQLITE_ERROR;
69443 }
69444 break;
69445 }
69446
@@ -69474,48 +69080,46 @@
69474 ** will automatically commit when the VDBE halts.
69475 **
69476 ** If P2 is zero, then a read-lock is obtained on the database file.
69477 */
69478 case OP_Transaction: {
69479 #if 0 /* local variables moved into u.av */
69480 Btree *pBt;
69481 #endif /* local variables moved into u.av */
69482
69483 assert( p->bIsReader );
69484 assert( p->readOnly==0 || pOp->p2==0 );
69485 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69486 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69487 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69488 rc = SQLITE_READONLY;
69489 goto abort_due_to_error;
69490 }
69491 u.av.pBt = db->aDb[pOp->p1].pBt;
69492
69493 if( u.av.pBt ){
69494 rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
69495 if( rc==SQLITE_BUSY ){
69496 p->pc = pc;
69497 p->rc = rc = SQLITE_BUSY;
69498 goto vdbe_return;
69499 }
69500 if( rc!=SQLITE_OK ){
69501 goto abort_due_to_error;
69502 }
69503
69504 if( pOp->p2 && p->usesStmtJournal
69505 && (db->autoCommit==0 || db->nVdbeRead>1)
69506 ){
69507 assert( sqlite3BtreeIsInTrans(u.av.pBt) );
69508 if( p->iStatement==0 ){
69509 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69510 db->nStatement++;
69511 p->iStatement = db->nSavepoint + db->nStatement;
69512 }
69513
69514 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69515 if( rc==SQLITE_OK ){
69516 rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
69517 }
69518
69519 /* Store the current value of the database handles deferred constraint
69520 ** counter. If the statement transaction needs to be rolled back,
69521 ** the value of this counter needs to be restored too. */
@@ -69537,26 +69141,24 @@
69537 ** There must be a read-lock on the database (either a transaction
69538 ** must be started or there must be an open cursor) before
69539 ** executing this instruction.
69540 */
69541 case OP_ReadCookie: { /* out2-prerelease */
69542 #if 0 /* local variables moved into u.aw */
69543 int iMeta;
69544 int iDb;
69545 int iCookie;
69546 #endif /* local variables moved into u.aw */
69547
69548 assert( p->bIsReader );
69549 u.aw.iDb = pOp->p1;
69550 u.aw.iCookie = pOp->p3;
69551 assert( pOp->p3<SQLITE_N_BTREE_META );
69552 assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
69553 assert( db->aDb[u.aw.iDb].pBt!=0 );
69554 assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 );
69555
69556 sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta);
69557 pOut->u.i = u.aw.iMeta;
69558 break;
69559 }
69560
69561 /* Opcode: SetCookie P1 P2 P3 * *
69562 **
@@ -69567,31 +69169,29 @@
69567 ** database file used to store temporary tables.
69568 **
69569 ** A transaction must be started before executing this opcode.
69570 */
69571 case OP_SetCookie: { /* in3 */
69572 #if 0 /* local variables moved into u.ax */
69573 Db *pDb;
69574 #endif /* local variables moved into u.ax */
69575 assert( pOp->p2<SQLITE_N_BTREE_META );
69576 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69577 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69578 assert( p->readOnly==0 );
69579 u.ax.pDb = &db->aDb[pOp->p1];
69580 assert( u.ax.pDb->pBt!=0 );
69581 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69582 pIn3 = &aMem[pOp->p3];
69583 sqlite3VdbeMemIntegerify(pIn3);
69584 /* See note about index shifting on OP_ReadCookie */
69585 rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i);
69586 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69587 /* When the schema cookie changes, record the new cookie internally */
69588 u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69589 db->flags |= SQLITE_InternChanges;
69590 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69591 /* Record changes in the file format */
69592 u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i;
69593 }
69594 if( pOp->p1==1 ){
69595 /* Invalidate all prepared statements whenever the TEMP database
69596 ** schema is changed. Ticket #1644 */
69597 sqlite3ExpirePreparedStatements(db);
@@ -69617,44 +69217,42 @@
69617 ** Either a transaction needs to have been started or an OP_Open needs
69618 ** to be executed (to establish a read lock) before this opcode is
69619 ** invoked.
69620 */
69621 case OP_VerifyCookie: {
69622 #if 0 /* local variables moved into u.ay */
69623 int iMeta;
69624 int iGen;
69625 Btree *pBt;
69626 #endif /* local variables moved into u.ay */
69627
69628 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69629 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69630 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69631 assert( p->bIsReader );
69632 u.ay.pBt = db->aDb[pOp->p1].pBt;
69633 if( u.ay.pBt ){
69634 sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta);
69635 u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69636 }else{
69637 u.ay.iGen = u.ay.iMeta = 0;
69638 }
69639 if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
69640 sqlite3DbFree(db, p->zErrMsg);
69641 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69642 /* If the schema-cookie from the database file matches the cookie
69643 ** stored with the in-memory representation of the schema, do
69644 ** not reload the schema from the database file.
69645 **
69646 ** If virtual-tables are in use, this is not just an optimization.
69647 ** Often, v-tables store their data in other SQLite tables, which
69648 ** are queried from within xNext() and other v-table methods using
69649 ** prepared queries. If such a query is out-of-date, we do not want to
69650 ** discard the database schema, as the user code implementing the
69651 ** v-table would have to be ready for the sqlite3_vtab structure itself
69652 ** to be invalidated whenever sqlite3_step() is called from within
69653 ** a v-table method.
69654 */
69655 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
69656 sqlite3ResetOneSchema(db, pOp->p1);
69657 }
69658
69659 p->expired = 1;
69660 rc = SQLITE_SCHEMA;
@@ -69713,20 +69311,18 @@
69713 **
69714 ** See also OpenRead.
69715 */
69716 case OP_OpenRead:
69717 case OP_OpenWrite: {
69718 #if 0 /* local variables moved into u.az */
69719 int nField;
69720 KeyInfo *pKeyInfo;
69721 int p2;
69722 int iDb;
69723 int wrFlag;
69724 Btree *pX;
69725 VdbeCursor *pCur;
69726 Db *pDb;
69727 #endif /* local variables moved into u.az */
69728
69729 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69730 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69731 assert( p->bIsReader );
69732 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69734,73 +69330,74 @@
69734 if( p->expired ){
69735 rc = SQLITE_ABORT;
69736 break;
69737 }
69738
69739 u.az.nField = 0;
69740 u.az.pKeyInfo = 0;
69741 u.az.p2 = pOp->p2;
69742 u.az.iDb = pOp->p3;
69743 assert( u.az.iDb>=0 && u.az.iDb<db->nDb );
69744 assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 );
69745 u.az.pDb = &db->aDb[u.az.iDb];
69746 u.az.pX = u.az.pDb->pBt;
69747 assert( u.az.pX!=0 );
69748 if( pOp->opcode==OP_OpenWrite ){
69749 u.az.wrFlag = 1;
69750 assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) );
69751 if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){
69752 p->minWriteFileFormat = u.az.pDb->pSchema->file_format;
69753 }
69754 }else{
69755 u.az.wrFlag = 0;
69756 }
69757 if( pOp->p5 & OPFLAG_P2ISREG ){
69758 assert( u.az.p2>0 );
69759 assert( u.az.p2<=(p->nMem-p->nCursor) );
69760 pIn2 = &aMem[u.az.p2];
69761 assert( memIsValid(pIn2) );
69762 assert( (pIn2->flags & MEM_Int)!=0 );
69763 sqlite3VdbeMemIntegerify(pIn2);
69764 u.az.p2 = (int)pIn2->u.i;
69765 /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and
69766 ** that opcode will always set the u.az.p2 value to 2 or more or else fail.
69767 ** If there were a failure, the prepared statement would have halted
69768 ** before reaching this instruction. */
69769 if( NEVER(u.az.p2<2) ) {
69770 rc = SQLITE_CORRUPT_BKPT;
69771 goto abort_due_to_error;
69772 }
69773 }
69774 if( pOp->p4type==P4_KEYINFO ){
69775 u.az.pKeyInfo = pOp->p4.pKeyInfo;
69776 assert( u.az.pKeyInfo->enc==ENC(db) );
69777 assert( u.az.pKeyInfo->db==db );
69778 u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
69779 }else if( pOp->p4type==P4_INT32 ){
69780 u.az.nField = pOp->p4.i;
69781 }
69782 assert( pOp->p1>=0 );
69783 u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69784 if( u.az.pCur==0 ) goto no_mem;
69785 u.az.pCur->nullRow = 1;
69786 u.az.pCur->isOrdered = 1;
69787 rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
69788 u.az.pCur->pKeyInfo = u.az.pKeyInfo;
 
 
69789 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69790 sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69791
69792 /* Since it performs no memory allocation or IO, the only value that
69793 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69794 assert( rc==SQLITE_OK );
69795
69796 /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
69797 ** SQLite used to check if the root-page flags were sane at this point
69798 ** and report database corruption if they were not, but this check has
69799 ** since moved into the btree layer. */
69800 u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69801 u.az.pCur->isIndex = !u.az.pCur->isTable;
69802 break;
69803 }
69804
69805 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69806 ** Synopsis: nColumn=P2
@@ -69828,55 +69425,53 @@
69828 ** by this opcode will be used for automatically created transient
69829 ** indices in joins.
69830 */
69831 case OP_OpenAutoindex:
69832 case OP_OpenEphemeral: {
69833 #if 0 /* local variables moved into u.ba */
69834 VdbeCursor *pCx;
69835 KeyInfo *pKeyInfo;
69836 #endif /* local variables moved into u.ba */
69837
69838 static const int vfsFlags =
69839 SQLITE_OPEN_READWRITE |
69840 SQLITE_OPEN_CREATE |
69841 SQLITE_OPEN_EXCLUSIVE |
69842 SQLITE_OPEN_DELETEONCLOSE |
69843 SQLITE_OPEN_TRANSIENT_DB;
69844 assert( pOp->p1>=0 );
69845 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69846 if( u.ba.pCx==0 ) goto no_mem;
69847 u.ba.pCx->nullRow = 1;
69848 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
 
69849 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69850 if( rc==SQLITE_OK ){
69851 rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
69852 }
69853 if( rc==SQLITE_OK ){
69854 /* If a transient index is required, create it by calling
69855 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69856 ** opening it. If a transient table is required, just use the
69857 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69858 */
69859 if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69860 int pgno;
69861 assert( pOp->p4type==P4_KEYINFO );
69862 rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69863 if( rc==SQLITE_OK ){
69864 assert( pgno==MASTER_ROOT+1 );
69865 assert( u.ba.pKeyInfo->db==db );
69866 assert( u.ba.pKeyInfo->enc==ENC(db) );
69867 u.ba.pCx->pKeyInfo = u.ba.pKeyInfo;
69868 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor);
69869 }
69870 u.ba.pCx->isTable = 0;
69871 }else{
69872 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69873 u.ba.pCx->isTable = 1;
69874 }
69875 }
69876 u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69877 u.ba.pCx->isIndex = !u.ba.pCx->isTable;
69878 break;
69879 }
69880
69881 /* Opcode: SorterOpen P1 * * P4 *
69882 **
@@ -69883,21 +69478,20 @@
69883 ** This opcode works like OP_OpenEphemeral except that it opens
69884 ** a transient index that is specifically designed to sort large
69885 ** tables using an external merge-sort algorithm.
69886 */
69887 case OP_SorterOpen: {
69888 #if 0 /* local variables moved into u.bb */
69889 VdbeCursor *pCx;
69890 #endif /* local variables moved into u.bb */
69891
69892 u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69893 if( u.bb.pCx==0 ) goto no_mem;
69894 u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69895 assert( u.bb.pCx->pKeyInfo->db==db );
69896 assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69897 u.bb.pCx->isSorter = 1;
69898 rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
69899 break;
69900 }
69901
69902 /* Opcode: OpenPseudo P1 P2 P3 * P5
69903 ** Synopsis: content in r[P2@P3]
@@ -69915,22 +69509,20 @@
69915 **
69916 ** P3 is the number of fields in the records that will be stored by
69917 ** the pseudo-table.
69918 */
69919 case OP_OpenPseudo: {
69920 #if 0 /* local variables moved into u.bc */
69921 VdbeCursor *pCx;
69922 #endif /* local variables moved into u.bc */
69923
69924 assert( pOp->p1>=0 );
69925 u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69926 if( u.bc.pCx==0 ) goto no_mem;
69927 u.bc.pCx->nullRow = 1;
69928 u.bc.pCx->pseudoTableReg = pOp->p2;
69929 u.bc.pCx->isTable = 1;
69930 u.bc.pCx->isIndex = 0;
69931 u.bc.pCx->multiPseudo = pOp->p5;
69932 break;
69933 }
69934
69935 /* Opcode: Close P1 * * * *
69936 **
@@ -70002,39 +69594,37 @@
70002 */
70003 case OP_SeekLt: /* jump, in3 */
70004 case OP_SeekLe: /* jump, in3 */
70005 case OP_SeekGe: /* jump, in3 */
70006 case OP_SeekGt: { /* jump, in3 */
70007 #if 0 /* local variables moved into u.bd */
70008 int res;
70009 int oc;
70010 VdbeCursor *pC;
70011 UnpackedRecord r;
70012 int nField;
70013 i64 iKey; /* The rowid we are to seek to */
70014 #endif /* local variables moved into u.bd */
70015
70016 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70017 assert( pOp->p2!=0 );
70018 u.bd.pC = p->apCsr[pOp->p1];
70019 assert( u.bd.pC!=0 );
70020 assert( u.bd.pC->pseudoTableReg==0 );
70021 assert( OP_SeekLe == OP_SeekLt+1 );
70022 assert( OP_SeekGe == OP_SeekLt+2 );
70023 assert( OP_SeekGt == OP_SeekLt+3 );
70024 assert( u.bd.pC->isOrdered );
70025 assert( u.bd.pC->pCursor!=0 );
70026 u.bd.oc = pOp->opcode;
70027 u.bd.pC->nullRow = 0;
70028 if( u.bd.pC->isTable ){
70029 /* The input value in P3 might be of any type: integer, real, string,
70030 ** blob, or NULL. But it needs to be an integer before we can do
70031 ** the seek, so covert it. */
70032 pIn3 = &aMem[pOp->p3];
70033 applyNumericAffinity(pIn3);
70034 u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70035 u.bd.pC->rowidIsValid = 0;
70036
70037 /* If the P3 value could not be converted into an integer without
70038 ** loss of information, then special processing is required... */
70039 if( (pIn3->flags & MEM_Int)==0 ){
70040 if( (pIn3->flags & MEM_Real)==0 ){
@@ -70041,109 +69631,101 @@
70041 /* If the P3 value cannot be converted into any kind of a number,
70042 ** then the seek is not possible, so jump to P2 */
70043 pc = pOp->p2 - 1;
70044 break;
70045 }
70046 /* If we reach this point, then the P3 value must be a floating
70047 ** point number. */
70048 assert( (pIn3->flags & MEM_Real)!=0 );
70049
70050 if( u.bd.iKey==SMALLEST_INT64 && (pIn3->r<(double)u.bd.iKey || pIn3->r>0) ){
70051 /* The P3 value is too large in magnitude to be expressed as an
70052 ** integer. */
70053 u.bd.res = 1;
70054 if( pIn3->r<0 ){
70055 if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70056 rc = sqlite3BtreeFirst(u.bd.pC->pCursor, &u.bd.res);
70057 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70058 }
70059 }else{
70060 if( u.bd.oc<=OP_SeekLe ){ assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70061 rc = sqlite3BtreeLast(u.bd.pC->pCursor, &u.bd.res);
70062 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70063 }
70064 }
70065 if( u.bd.res ){
70066 pc = pOp->p2 - 1;
70067 }
70068 break;
70069 }else if( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekGe ){
70070 /* Use the ceiling() function to convert real->int */
70071 if( pIn3->r > (double)u.bd.iKey ) u.bd.iKey++;
70072 }else{
70073 /* Use the floor() function to convert real->int */
70074 assert( u.bd.oc==OP_SeekLe || u.bd.oc==OP_SeekGt );
70075 if( pIn3->r < (double)u.bd.iKey ) u.bd.iKey--;
70076 }
70077 }
70078 rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res);
70079 if( rc!=SQLITE_OK ){
70080 goto abort_due_to_error;
70081 }
70082 if( u.bd.res==0 ){
70083 u.bd.pC->rowidIsValid = 1;
70084 u.bd.pC->lastRowid = u.bd.iKey;
70085 }
70086 }else{
70087 u.bd.nField = pOp->p4.i;
70088 assert( pOp->p4type==P4_INT32 );
70089 assert( u.bd.nField>0 );
70090 u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo;
70091 u.bd.r.nField = (u16)u.bd.nField;
70092
70093 /* The next line of code computes as follows, only faster:
70094 ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){
70095 ** u.bd.r.flags = UNPACKED_INCRKEY;
70096 ** }else{
70097 ** u.bd.r.flags = 0;
70098 ** }
70099 */
70100 u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt)));
70101 assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY );
70102 assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY );
70103 assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 );
70104 assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 );
70105
70106 u.bd.r.aMem = &aMem[pOp->p3];
70107 #ifdef SQLITE_DEBUG
70108 { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); }
70109 #endif
70110 ExpandBlob(u.bd.r.aMem);
70111 rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res);
70112 if( rc!=SQLITE_OK ){
70113 goto abort_due_to_error;
70114 }
70115 u.bd.pC->rowidIsValid = 0;
70116 }
70117 u.bd.pC->deferredMoveto = 0;
70118 u.bd.pC->cacheStatus = CACHE_STALE;
70119 #ifdef SQLITE_TEST
70120 sqlite3_search_count++;
70121 #endif
70122 if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70123 if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){
70124 rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res);
70125 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70126 u.bd.pC->rowidIsValid = 0;
70127 }else{
70128 u.bd.res = 0;
70129 }
70130 }else{
70131 assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70132 if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){
70133 rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res);
70134 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70135 u.bd.pC->rowidIsValid = 0;
70136 }else{
70137 /* u.bd.res might be negative because the table is empty. Check to
70138 ** see if this is the case.
70139 */
70140 u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor);
70141 }
70142 }
70143 assert( pOp->p2>0 );
70144 if( u.bd.res ){
70145 pc = pOp->p2 - 1;
70146 }
70147 break;
70148 }
70149
@@ -70156,24 +69738,22 @@
70156 ** This is actually a deferred seek. Nothing actually happens until
70157 ** the cursor is used to read a record. That way, if no reads
70158 ** occur, no unnecessary I/O happens.
70159 */
70160 case OP_Seek: { /* in2 */
70161 #if 0 /* local variables moved into u.be */
70162 VdbeCursor *pC;
70163 #endif /* local variables moved into u.be */
70164
70165 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70166 u.be.pC = p->apCsr[pOp->p1];
70167 assert( u.be.pC!=0 );
70168 assert( u.be.pC->pCursor!=0 );
70169 assert( u.be.pC->isTable );
70170 u.be.pC->nullRow = 0;
70171 pIn2 = &aMem[pOp->p2];
70172 u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
70173 u.be.pC->rowidIsValid = 0;
70174 u.be.pC->deferredMoveto = 1;
70175 break;
70176 }
70177
70178
70179 /* Opcode: Found P1 P2 P3 P4 *
@@ -70224,85 +69804,83 @@
70224 ** See also: NotFound, Found, NotExists
70225 */
70226 case OP_NoConflict: /* jump, in3 */
70227 case OP_NotFound: /* jump, in3 */
70228 case OP_Found: { /* jump, in3 */
70229 #if 0 /* local variables moved into u.bf */
70230 int alreadyExists;
70231 int ii;
70232 VdbeCursor *pC;
70233 int res;
70234 char *pFree;
70235 UnpackedRecord *pIdxKey;
70236 UnpackedRecord r;
70237 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70238 #endif /* local variables moved into u.bf */
70239
70240 #ifdef SQLITE_TEST
70241 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
70242 #endif
70243
70244 u.bf.alreadyExists = 0;
70245 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70246 assert( pOp->p4type==P4_INT32 );
70247 u.bf.pC = p->apCsr[pOp->p1];
70248 assert( u.bf.pC!=0 );
70249 pIn3 = &aMem[pOp->p3];
70250 assert( u.bf.pC->pCursor!=0 );
70251 assert( u.bf.pC->isTable==0 );
 
70252 if( pOp->p4.i>0 ){
70253 u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo;
70254 u.bf.r.nField = (u16)pOp->p4.i;
70255 u.bf.r.aMem = pIn3;
70256 #ifdef SQLITE_DEBUG
70257 {
70258 int i;
70259 for(i=0; i<u.bf.r.nField; i++){
70260 assert( memIsValid(&u.bf.r.aMem[i]) );
70261 if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]);
70262 }
70263 }
70264 #endif
70265 u.bf.r.flags = UNPACKED_PREFIX_MATCH;
70266 u.bf.pIdxKey = &u.bf.r;
70267 }else{
70268 u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70269 u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree
70270 );
70271 if( u.bf.pIdxKey==0 ) goto no_mem;
70272 assert( pIn3->flags & MEM_Blob );
70273 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70274 sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey);
70275 u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70276 }
70277 if( pOp->opcode==OP_NoConflict ){
70278 /* For the OP_NoConflict opcode, take the jump if any of the
70279 ** input fields are NULL, since any key with a NULL will not
70280 ** conflict */
70281 for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){
70282 if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){
70283 pc = pOp->p2 - 1;
70284 break;
70285 }
70286 }
70287 }
70288 rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
70289 if( pOp->p4.i==0 ){
70290 sqlite3DbFree(db, u.bf.pFree);
70291 }
70292 if( rc!=SQLITE_OK ){
70293 break;
70294 }
70295 u.bf.pC->seekResult = u.bf.res;
70296 u.bf.alreadyExists = (u.bf.res==0);
70297 u.bf.pC->nullRow = 1-u.bf.alreadyExists;
70298 u.bf.pC->deferredMoveto = 0;
70299 u.bf.pC->cacheStatus = CACHE_STALE;
70300 if( pOp->opcode==OP_Found ){
70301 if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
70302 }else{
70303 if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
70304 }
70305 break;
70306 }
70307
70308 /* Opcode: NotExists P1 P2 P3 * *
@@ -70318,39 +69896,37 @@
70318 ** (with arbitrary multi-value keys).
70319 **
70320 ** See also: Found, NotFound, NoConflict
70321 */
70322 case OP_NotExists: { /* jump, in3 */
70323 #if 0 /* local variables moved into u.bg */
70324 VdbeCursor *pC;
70325 BtCursor *pCrsr;
70326 int res;
70327 u64 iKey;
70328 #endif /* local variables moved into u.bg */
70329
70330 pIn3 = &aMem[pOp->p3];
70331 assert( pIn3->flags & MEM_Int );
70332 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70333 u.bg.pC = p->apCsr[pOp->p1];
70334 assert( u.bg.pC!=0 );
70335 assert( u.bg.pC->isTable );
70336 assert( u.bg.pC->pseudoTableReg==0 );
70337 u.bg.pCrsr = u.bg.pC->pCursor;
70338 assert( u.bg.pCrsr!=0 );
70339 u.bg.res = 0;
70340 u.bg.iKey = pIn3->u.i;
70341 rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70342 u.bg.pC->lastRowid = pIn3->u.i;
70343 u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70344 u.bg.pC->nullRow = 0;
70345 u.bg.pC->cacheStatus = CACHE_STALE;
70346 u.bg.pC->deferredMoveto = 0;
70347 if( u.bg.res!=0 ){
70348 pc = pOp->p2 - 1;
70349 assert( u.bg.pC->rowidIsValid==0 );
70350 }
70351 u.bg.pC->seekResult = u.bg.res;
70352 break;
70353 }
70354
70355 /* Opcode: Sequence P1 P2 * * *
70356 ** Synopsis: r[P2]=rowid
@@ -70382,25 +69958,23 @@
70382 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
70383 ** generated record number. This P3 mechanism is used to help implement the
70384 ** AUTOINCREMENT feature.
70385 */
70386 case OP_NewRowid: { /* out2-prerelease */
70387 #if 0 /* local variables moved into u.bh */
70388 i64 v; /* The new rowid */
70389 VdbeCursor *pC; /* Cursor of table to get the new rowid */
70390 int res; /* Result of an sqlite3BtreeLast() */
70391 int cnt; /* Counter to limit the number of searches */
70392 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
70393 VdbeFrame *pFrame; /* Root frame of VDBE */
70394 #endif /* local variables moved into u.bh */
70395
70396 u.bh.v = 0;
70397 u.bh.res = 0;
70398 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70399 u.bh.pC = p->apCsr[pOp->p1];
70400 assert( u.bh.pC!=0 );
70401 if( NEVER(u.bh.pC->pCursor==0) ){
70402 /* The zero initialization above is all that is needed */
70403 }else{
70404 /* The next rowid or record number (different terms for the same
70405 ** thing) is obtained in a two-step algorithm.
70406 **
@@ -70412,11 +69986,11 @@
70412 ** The second algorithm is to select a rowid at random and see if
70413 ** it already exists in the table. If it does not exist, we have
70414 ** succeeded. If the random rowid does exist, we select a new one
70415 ** and try again, up to 100 times.
70416 */
70417 assert( u.bh.pC->isTable );
70418
70419 #ifdef SQLITE_32BIT_ROWID
70420 # define MAX_ROWID 0x7fffffff
70421 #else
70422 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70424,101 +69998,101 @@
70424 ** to provide the constant while making all compilers happy.
70425 */
70426 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70427 #endif
70428
70429 if( !u.bh.pC->useRandomRowid ){
70430 u.bh.v = sqlite3BtreeGetCachedRowid(u.bh.pC->pCursor);
70431 if( u.bh.v==0 ){
70432 rc = sqlite3BtreeLast(u.bh.pC->pCursor, &u.bh.res);
70433 if( rc!=SQLITE_OK ){
70434 goto abort_due_to_error;
70435 }
70436 if( u.bh.res ){
70437 u.bh.v = 1; /* IMP: R-61914-48074 */
70438 }else{
70439 assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) );
70440 rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v);
70441 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70442 if( u.bh.v>=MAX_ROWID ){
70443 u.bh.pC->useRandomRowid = 1;
70444 }else{
70445 u.bh.v++; /* IMP: R-29538-34987 */
70446 }
70447 }
70448 }
70449
70450 #ifndef SQLITE_OMIT_AUTOINCREMENT
70451 if( pOp->p3 ){
70452 /* Assert that P3 is a valid memory cell. */
70453 assert( pOp->p3>0 );
70454 if( p->pFrame ){
70455 for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent);
70456 /* Assert that P3 is a valid memory cell. */
70457 assert( pOp->p3<=u.bh.pFrame->nMem );
70458 u.bh.pMem = &u.bh.pFrame->aMem[pOp->p3];
70459 }else{
70460 /* Assert that P3 is a valid memory cell. */
70461 assert( pOp->p3<=(p->nMem-p->nCursor) );
70462 u.bh.pMem = &aMem[pOp->p3];
70463 memAboutToChange(p, u.bh.pMem);
70464 }
70465 assert( memIsValid(u.bh.pMem) );
70466
70467 REGISTER_TRACE(pOp->p3, u.bh.pMem);
70468 sqlite3VdbeMemIntegerify(u.bh.pMem);
70469 assert( (u.bh.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70470 if( u.bh.pMem->u.i==MAX_ROWID || u.bh.pC->useRandomRowid ){
70471 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70472 goto abort_due_to_error;
70473 }
70474 if( u.bh.v<u.bh.pMem->u.i+1 ){
70475 u.bh.v = u.bh.pMem->u.i + 1;
70476 }
70477 u.bh.pMem->u.i = u.bh.v;
70478 }
70479 #endif
70480
70481 sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0);
70482 }
70483 if( u.bh.pC->useRandomRowid ){
70484 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70485 ** largest possible integer (9223372036854775807) then the database
70486 ** engine starts picking positive candidate ROWIDs at random until
70487 ** it finds one that is not previously used. */
70488 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
70489 ** an AUTOINCREMENT table. */
70490 /* on the first attempt, simply do one more than previous */
70491 u.bh.v = lastRowid;
70492 u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70493 u.bh.v++; /* ensure non-zero */
70494 u.bh.cnt = 0;
70495 while( ((rc = sqlite3BtreeMovetoUnpacked(u.bh.pC->pCursor, 0, (u64)u.bh.v,
70496 0, &u.bh.res))==SQLITE_OK)
70497 && (u.bh.res==0)
70498 && (++u.bh.cnt<100)){
70499 /* collision - try another random rowid */
70500 sqlite3_randomness(sizeof(u.bh.v), &u.bh.v);
70501 if( u.bh.cnt<5 ){
70502 /* try "small" random rowids for the initial attempts */
70503 u.bh.v &= 0xffffff;
70504 }else{
70505 u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70506 }
70507 u.bh.v++; /* ensure non-zero */
70508 }
70509 if( rc==SQLITE_OK && u.bh.res==0 ){
70510 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
70511 goto abort_due_to_error;
70512 }
70513 assert( u.bh.v>0 ); /* EV: R-40812-03570 */
70514 }
70515 u.bh.pC->rowidIsValid = 0;
70516 u.bh.pC->deferredMoveto = 0;
70517 u.bh.pC->cacheStatus = CACHE_STALE;
70518 }
70519 pOut->u.i = u.bh.v;
70520 break;
70521 }
70522
70523 /* Opcode: Insert P1 P2 P3 P4 P5
70524 ** Synopsis: intkey=r[P3] data=r[P2]
@@ -70566,74 +70140,72 @@
70566 ** This works exactly like OP_Insert except that the key is the
70567 ** integer value P3, not the value of the integer stored in register P3.
70568 */
70569 case OP_Insert:
70570 case OP_InsertInt: {
70571 #if 0 /* local variables moved into u.bi */
70572 Mem *pData; /* MEM cell holding data for the record to be inserted */
70573 Mem *pKey; /* MEM cell holding key for the record */
70574 i64 iKey; /* The integer ROWID or key for the record to be inserted */
70575 VdbeCursor *pC; /* Cursor to table into which insert is written */
70576 int nZero; /* Number of zero-bytes to append */
70577 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
70578 const char *zDb; /* database name - used by the update hook */
70579 const char *zTbl; /* Table name - used by the opdate hook */
70580 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
70581 #endif /* local variables moved into u.bi */
70582
70583 u.bi.pData = &aMem[pOp->p2];
70584 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70585 assert( memIsValid(u.bi.pData) );
70586 u.bi.pC = p->apCsr[pOp->p1];
70587 assert( u.bi.pC!=0 );
70588 assert( u.bi.pC->pCursor!=0 );
70589 assert( u.bi.pC->pseudoTableReg==0 );
70590 assert( u.bi.pC->isTable );
70591 REGISTER_TRACE(pOp->p2, u.bi.pData);
70592
70593 if( pOp->opcode==OP_Insert ){
70594 u.bi.pKey = &aMem[pOp->p3];
70595 assert( u.bi.pKey->flags & MEM_Int );
70596 assert( memIsValid(u.bi.pKey) );
70597 REGISTER_TRACE(pOp->p3, u.bi.pKey);
70598 u.bi.iKey = u.bi.pKey->u.i;
70599 }else{
70600 assert( pOp->opcode==OP_InsertInt );
70601 u.bi.iKey = pOp->p3;
70602 }
70603
70604 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70605 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bi.iKey;
70606 if( u.bi.pData->flags & MEM_Null ){
70607 u.bi.pData->z = 0;
70608 u.bi.pData->n = 0;
70609 }else{
70610 assert( u.bi.pData->flags & (MEM_Blob|MEM_Str) );
70611 }
70612 u.bi.seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bi.pC->seekResult : 0);
70613 if( u.bi.pData->flags & MEM_Zero ){
70614 u.bi.nZero = u.bi.pData->u.nZero;
70615 }else{
70616 u.bi.nZero = 0;
70617 }
70618 sqlite3BtreeSetCachedRowid(u.bi.pC->pCursor, 0);
70619 rc = sqlite3BtreeInsert(u.bi.pC->pCursor, 0, u.bi.iKey,
70620 u.bi.pData->z, u.bi.pData->n, u.bi.nZero,
70621 pOp->p5 & OPFLAG_APPEND, u.bi.seekResult
70622 );
70623 u.bi.pC->rowidIsValid = 0;
70624 u.bi.pC->deferredMoveto = 0;
70625 u.bi.pC->cacheStatus = CACHE_STALE;
70626
70627 /* Invoke the update-hook if required. */
70628 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70629 u.bi.zDb = db->aDb[u.bi.pC->iDb].zName;
70630 u.bi.zTbl = pOp->p4.z;
70631 u.bi.op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70632 assert( u.bi.pC->isTable );
70633 db->xUpdateCallback(db->pUpdateArg, u.bi.op, u.bi.zDb, u.bi.zTbl, u.bi.iKey);
70634 assert( u.bi.pC->iDb>=0 );
70635 }
70636 break;
70637 }
70638
70639 /* Opcode: Delete P1 P2 * P4 *
@@ -70655,51 +70227,39 @@
70655 ** pointing to. The update hook will be invoked, if it exists.
70656 ** If P4 is not NULL then the P1 cursor must have been positioned
70657 ** using OP_NotFound prior to invoking this opcode.
70658 */
70659 case OP_Delete: {
70660 #if 0 /* local variables moved into u.bj */
70661 i64 iKey;
70662 VdbeCursor *pC;
70663 #endif /* local variables moved into u.bj */
70664
70665 u.bj.iKey = 0;
70666 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70667 u.bj.pC = p->apCsr[pOp->p1];
70668 assert( u.bj.pC!=0 );
70669 assert( u.bj.pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70670
70671 /* If the update-hook will be invoked, set u.bj.iKey to the rowid of the
70672 ** row being deleted.
70673 */
70674 if( db->xUpdateCallback && pOp->p4.z ){
70675 assert( u.bj.pC->isTable );
70676 assert( u.bj.pC->rowidIsValid ); /* lastRowid set by previous OP_NotFound */
70677 u.bj.iKey = u.bj.pC->lastRowid;
70678 }
70679
70680 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
70681 ** OP_Column on the same table without any intervening operations that
70682 ** might move or invalidate the cursor. Hence cursor u.bj.pC is always pointing
70683 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
70684 ** below is always a no-op and cannot fail. We will run it anyhow, though,
70685 ** to guard against future changes to the code generator.
70686 **/
70687 assert( u.bj.pC->deferredMoveto==0 );
70688 rc = sqlite3VdbeCursorMoveto(u.bj.pC);
70689 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70690
70691 sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0);
70692 rc = sqlite3BtreeDelete(u.bj.pC->pCursor);
70693 u.bj.pC->cacheStatus = CACHE_STALE;
70694
70695 /* Invoke the update-hook if required. */
70696 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70697 const char *zDb = db->aDb[u.bj.pC->iDb].zName;
70698 const char *zTbl = pOp->p4.z;
70699 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, u.bj.iKey);
70700 assert( u.bj.pC->iDb>=0 );
70701 }
70702 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
70703 break;
70704 }
70705 /* Opcode: ResetCount * * * * *
@@ -70729,23 +70289,21 @@
70729 **
70730 ** Fall through to next instruction if the two records compare equal to
70731 ** each other. Jump to P2 if they are different.
70732 */
70733 case OP_SorterCompare: {
70734 #if 0 /* local variables moved into u.bk */
70735 VdbeCursor *pC;
70736 int res;
70737 int nIgnore;
70738 #endif /* local variables moved into u.bk */
70739
70740 u.bk.pC = p->apCsr[pOp->p1];
70741 assert( isSorter(u.bk.pC) );
70742 assert( pOp->p4type==P4_INT32 );
70743 pIn3 = &aMem[pOp->p3];
70744 u.bk.nIgnore = pOp->p4.i;
70745 rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res);
70746 if( u.bk.res ){
70747 pc = pOp->p2-1;
70748 }
70749 break;
70750 };
70751
@@ -70753,18 +70311,16 @@
70753 ** Synopsis: r[P2]=data
70754 **
70755 ** Write into register P2 the current sorter data for sorter cursor P1.
70756 */
70757 case OP_SorterData: {
70758 #if 0 /* local variables moved into u.bl */
70759 VdbeCursor *pC;
70760 #endif /* local variables moved into u.bl */
70761
70762 pOut = &aMem[pOp->p2];
70763 u.bl.pC = p->apCsr[pOp->p1];
70764 assert( u.bl.pC->isSorter );
70765 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
70766 break;
70767 }
70768
70769 /* Opcode: RowData P1 P2 * * *
70770 ** Synopsis: r[P2]=data
@@ -70788,66 +70344,64 @@
70788 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70789 ** of a real table, not a pseudo-table.
70790 */
70791 case OP_RowKey:
70792 case OP_RowData: {
70793 #if 0 /* local variables moved into u.bm */
70794 VdbeCursor *pC;
70795 BtCursor *pCrsr;
70796 u32 n;
70797 i64 n64;
70798 #endif /* local variables moved into u.bm */
70799
70800 pOut = &aMem[pOp->p2];
70801 memAboutToChange(p, pOut);
70802
70803 /* Note that RowKey and RowData are really exactly the same instruction */
70804 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70805 u.bm.pC = p->apCsr[pOp->p1];
70806 assert( u.bm.pC->isSorter==0 );
70807 assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
70808 assert( u.bm.pC->isIndex || pOp->opcode==OP_RowData );
70809 assert( u.bm.pC!=0 );
70810 assert( u.bm.pC->nullRow==0 );
70811 assert( u.bm.pC->pseudoTableReg==0 );
70812 assert( u.bm.pC->pCursor!=0 );
70813 u.bm.pCrsr = u.bm.pC->pCursor;
70814 assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) );
70815
70816 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
70817 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
70818 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
70819 ** a no-op and can never fail. But we leave it in place as a safety.
70820 */
70821 assert( u.bm.pC->deferredMoveto==0 );
70822 rc = sqlite3VdbeCursorMoveto(u.bm.pC);
70823 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70824
70825 if( u.bm.pC->isIndex ){
70826 assert( !u.bm.pC->isTable );
70827 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
70828 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70829 if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70830 goto too_big;
70831 }
70832 u.bm.n = (u32)u.bm.n64;
70833 }else{
70834 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bm.pCrsr, &u.bm.n);
70835 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70836 if( u.bm.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70837 goto too_big;
70838 }
70839 }
70840 if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
70841 goto no_mem;
70842 }
70843 pOut->n = u.bm.n;
70844 MemSetTypeFlag(pOut, MEM_Blob);
70845 if( u.bm.pC->isIndex ){
70846 rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70847 }else{
70848 rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70849 }
70850 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70851 UPDATE_MAX_BLOBSIZE(pOut);
70852 REGISTER_TRACE(pOp->p2, pOut);
70853 break;
@@ -70862,46 +70416,44 @@
70862 ** P1 can be either an ordinary table or a virtual table. There used to
70863 ** be a separate OP_VRowid opcode for use with virtual tables, but this
70864 ** one opcode now works for both table types.
70865 */
70866 case OP_Rowid: { /* out2-prerelease */
70867 #if 0 /* local variables moved into u.bn */
70868 VdbeCursor *pC;
70869 i64 v;
70870 sqlite3_vtab *pVtab;
70871 const sqlite3_module *pModule;
70872 #endif /* local variables moved into u.bn */
70873
70874 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70875 u.bn.pC = p->apCsr[pOp->p1];
70876 assert( u.bn.pC!=0 );
70877 assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow );
70878 if( u.bn.pC->nullRow ){
70879 pOut->flags = MEM_Null;
70880 break;
70881 }else if( u.bn.pC->deferredMoveto ){
70882 u.bn.v = u.bn.pC->movetoTarget;
70883 #ifndef SQLITE_OMIT_VIRTUALTABLE
70884 }else if( u.bn.pC->pVtabCursor ){
70885 u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab;
70886 u.bn.pModule = u.bn.pVtab->pModule;
70887 assert( u.bn.pModule->xRowid );
70888 rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v);
70889 sqlite3VtabImportErrmsg(p, u.bn.pVtab);
70890 #endif /* SQLITE_OMIT_VIRTUALTABLE */
70891 }else{
70892 assert( u.bn.pC->pCursor!=0 );
70893 rc = sqlite3VdbeCursorMoveto(u.bn.pC);
70894 if( rc ) goto abort_due_to_error;
70895 if( u.bn.pC->rowidIsValid ){
70896 u.bn.v = u.bn.pC->lastRowid;
70897 }else{
70898 rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v);
70899 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
70900 }
70901 }
70902 pOut->u.i = u.bn.v;
70903 break;
70904 }
70905
70906 /* Opcode: NullRow P1 * * * *
70907 **
@@ -70908,22 +70460,21 @@
70908 ** Move the cursor P1 to a null row. Any OP_Column operations
70909 ** that occur while the cursor is on the null row will always
70910 ** write a NULL.
70911 */
70912 case OP_NullRow: {
70913 #if 0 /* local variables moved into u.bo */
70914 VdbeCursor *pC;
70915 #endif /* local variables moved into u.bo */
70916
70917 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70918 u.bo.pC = p->apCsr[pOp->p1];
70919 assert( u.bo.pC!=0 );
70920 u.bo.pC->nullRow = 1;
70921 u.bo.pC->rowidIsValid = 0;
70922 assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
70923 if( u.bo.pC->pCursor ){
70924 sqlite3BtreeClearCursor(u.bo.pC->pCursor);
 
70925 }
70926 break;
70927 }
70928
70929 /* Opcode: Last P1 P2 * * *
@@ -70933,28 +70484,26 @@
70933 ** If the table or index is empty and P2>0, then jump immediately to P2.
70934 ** If P2 is 0 or if the table or index is not empty, fall through
70935 ** to the following instruction.
70936 */
70937 case OP_Last: { /* jump */
70938 #if 0 /* local variables moved into u.bp */
70939 VdbeCursor *pC;
70940 BtCursor *pCrsr;
70941 int res;
70942 #endif /* local variables moved into u.bp */
70943
70944 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70945 u.bp.pC = p->apCsr[pOp->p1];
70946 assert( u.bp.pC!=0 );
70947 u.bp.pCrsr = u.bp.pC->pCursor;
70948 u.bp.res = 0;
70949 assert( u.bp.pCrsr!=0 );
70950 rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
70951 u.bp.pC->nullRow = (u8)u.bp.res;
70952 u.bp.pC->deferredMoveto = 0;
70953 u.bp.pC->rowidIsValid = 0;
70954 u.bp.pC->cacheStatus = CACHE_STALE;
70955 if( pOp->p2>0 && u.bp.res ){
70956 pc = pOp->p2 - 1;
70957 }
70958 break;
70959 }
70960
@@ -70987,35 +70536,32 @@
70987 ** If the table or index is empty and P2>0, then jump immediately to P2.
70988 ** If P2 is 0 or if the table or index is not empty, fall through
70989 ** to the following instruction.
70990 */
70991 case OP_Rewind: { /* jump */
70992 #if 0 /* local variables moved into u.bq */
70993 VdbeCursor *pC;
70994 BtCursor *pCrsr;
70995 int res;
70996 #endif /* local variables moved into u.bq */
70997
70998 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70999 u.bq.pC = p->apCsr[pOp->p1];
71000 assert( u.bq.pC!=0 );
71001 assert( u.bq.pC->isSorter==(pOp->opcode==OP_SorterSort) );
71002 u.bq.res = 1;
71003 if( isSorter(u.bq.pC) ){
71004 rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
71005 }else{
71006 u.bq.pCrsr = u.bq.pC->pCursor;
71007 assert( u.bq.pCrsr );
71008 rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
71009 u.bq.pC->atFirst = u.bq.res==0 ?1:0;
71010 u.bq.pC->deferredMoveto = 0;
71011 u.bq.pC->cacheStatus = CACHE_STALE;
71012 u.bq.pC->rowidIsValid = 0;
71013 }
71014 u.bq.pC->nullRow = (u8)u.bq.res;
71015 assert( pOp->p2>0 && pOp->p2<p->nOp );
71016 if( u.bq.res ){
71017 pc = pOp->p2 - 1;
71018 }
71019 break;
71020 }
71021
@@ -71024,71 +70570,85 @@
71024 ** Advance cursor P1 so that it points to the next key/data pair in its
71025 ** table or index. If there are no more key/value pairs then fall through
71026 ** to the following instruction. But if the cursor advance was successful,
71027 ** jump immediately to P2.
71028 **
71029 ** The P1 cursor must be for a real table, not a pseudo-table.
 
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
 
 
 
 
 
71038 */
71039 /* Opcode: Prev P1 P2 * * P5
71040 **
71041 ** Back up cursor P1 so that it points to the previous key/data pair in its
71042 ** table or index. If there is no previous key/value pairs then fall through
71043 ** to the following instruction. But if the cursor backup was successful,
71044 ** jump immediately to P2.
71045 **
71046 ** The P1 cursor must be for a real table, not a pseudo-table.
 
71047 **
71048 ** P4 is always of type P4_ADVANCE. The function pointer points to
71049 ** sqlite3BtreePrevious().
71050 **
71051 ** If P5 is positive and the jump is taken, then event counter
71052 ** number P5-1 in the prepared statement is incremented.
71053 */
71054 case OP_SorterNext: /* jump */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71055 case OP_Prev: /* jump */
71056 case OP_Next: { /* jump */
71057 #if 0 /* local variables moved into u.br */
71058 VdbeCursor *pC;
71059 int res;
71060 #endif /* local variables moved into u.br */
71061
71062 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71063 assert( pOp->p5<ArraySize(p->aCounter) );
71064 u.br.pC = p->apCsr[pOp->p1];
71065 if( u.br.pC==0 ){
71066 break; /* See ticket #2273 */
71067 }
71068 assert( u.br.pC->isSorter==(pOp->opcode==OP_SorterNext) );
71069 if( isSorter(u.br.pC) ){
71070 assert( pOp->opcode==OP_SorterNext );
71071 rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res);
71072 }else{
71073 /* u.br.res = 1; // Always initialized by the xAdvance() call */
71074 assert( u.br.pC->deferredMoveto==0 );
71075 assert( u.br.pC->pCursor );
71076 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
71077 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
71078 rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res);
71079 }
71080 u.br.pC->nullRow = (u8)u.br.res;
71081 u.br.pC->cacheStatus = CACHE_STALE;
71082 if( u.br.res==0 ){
71083 pc = pOp->p2 - 1;
71084 p->aCounter[pOp->p5]++;
71085 #ifdef SQLITE_TEST
71086 sqlite3_search_count++;
71087 #endif
 
 
71088 }
71089 u.br.pC->rowidIsValid = 0;
71090 goto check_for_interrupt;
71091 }
71092
71093 /* Opcode: IdxInsert P1 P2 P3 * P5
71094 ** Synopsis: key=r[P2]
@@ -71103,39 +70663,37 @@
71103 ** This instruction only works for indices. The equivalent instruction
71104 ** for tables is OP_Insert.
71105 */
71106 case OP_SorterInsert: /* in2 */
71107 case OP_IdxInsert: { /* in2 */
71108 #if 0 /* local variables moved into u.bs */
71109 VdbeCursor *pC;
71110 BtCursor *pCrsr;
71111 int nKey;
71112 const char *zKey;
71113 #endif /* local variables moved into u.bs */
71114
71115 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71116 u.bs.pC = p->apCsr[pOp->p1];
71117 assert( u.bs.pC!=0 );
71118 assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) );
71119 pIn2 = &aMem[pOp->p2];
71120 assert( pIn2->flags & MEM_Blob );
71121 u.bs.pCrsr = u.bs.pC->pCursor;
71122 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71123 assert( u.bs.pCrsr!=0 );
71124 assert( u.bs.pC->isTable==0 );
71125 rc = ExpandBlob(pIn2);
71126 if( rc==SQLITE_OK ){
71127 if( isSorter(u.bs.pC) ){
71128 rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
71129 }else{
71130 u.bs.nKey = pIn2->n;
71131 u.bs.zKey = pIn2->z;
71132 rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
71133 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
71134 );
71135 assert( u.bs.pC->deferredMoveto==0 );
71136 u.bs.pC->cacheStatus = CACHE_STALE;
71137 }
71138 }
71139 break;
71140 }
71141
@@ -71145,38 +70703,36 @@
71145 ** The content of P3 registers starting at register P2 form
71146 ** an unpacked index key. This opcode removes that entry from the
71147 ** index opened by cursor P1.
71148 */
71149 case OP_IdxDelete: {
71150 #if 0 /* local variables moved into u.bt */
71151 VdbeCursor *pC;
71152 BtCursor *pCrsr;
71153 int res;
71154 UnpackedRecord r;
71155 #endif /* local variables moved into u.bt */
71156
71157 assert( pOp->p3>0 );
71158 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
71159 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71160 u.bt.pC = p->apCsr[pOp->p1];
71161 assert( u.bt.pC!=0 );
71162 u.bt.pCrsr = u.bt.pC->pCursor;
71163 assert( u.bt.pCrsr!=0 );
71164 assert( pOp->p5==0 );
71165 u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
71166 u.bt.r.nField = (u16)pOp->p3;
71167 u.bt.r.flags = UNPACKED_PREFIX_MATCH;
71168 u.bt.r.aMem = &aMem[pOp->p2];
71169 #ifdef SQLITE_DEBUG
71170 { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
71171 #endif
71172 rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
71173 if( rc==SQLITE_OK && u.bt.res==0 ){
71174 rc = sqlite3BtreeDelete(u.bt.pCrsr);
71175 }
71176 assert( u.bt.pC->deferredMoveto==0 );
71177 u.bt.pC->cacheStatus = CACHE_STALE;
71178 break;
71179 }
71180
71181 /* Opcode: IdxRowid P1 P2 * * *
71182 ** Synopsis: r[P2]=rowid
@@ -71186,32 +70742,31 @@
71186 ** the rowid of the table entry to which this index entry points.
71187 **
71188 ** See also: Rowid, MakeRecord.
71189 */
71190 case OP_IdxRowid: { /* out2-prerelease */
71191 #if 0 /* local variables moved into u.bu */
71192 BtCursor *pCrsr;
71193 VdbeCursor *pC;
71194 i64 rowid;
71195 #endif /* local variables moved into u.bu */
71196
71197 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71198 u.bu.pC = p->apCsr[pOp->p1];
71199 assert( u.bu.pC!=0 );
71200 u.bu.pCrsr = u.bu.pC->pCursor;
71201 assert( u.bu.pCrsr!=0 );
71202 pOut->flags = MEM_Null;
71203 rc = sqlite3VdbeCursorMoveto(u.bu.pC);
71204 if( NEVER(rc) ) goto abort_due_to_error;
71205 assert( u.bu.pC->deferredMoveto==0 );
71206 assert( u.bu.pC->isTable==0 );
71207 if( !u.bu.pC->nullRow ){
71208 rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
 
71209 if( rc!=SQLITE_OK ){
71210 goto abort_due_to_error;
71211 }
71212 pOut->u.i = u.bu.rowid;
71213 pOut->flags = MEM_Int;
71214 }
71215 break;
71216 }
71217
@@ -71243,43 +70798,42 @@
71243 ** If P5 is non-zero then the key value is increased by an epsilon prior
71244 ** to the comparison. This makes the opcode work like IdxLE.
71245 */
71246 case OP_IdxLT: /* jump */
71247 case OP_IdxGE: { /* jump */
71248 #if 0 /* local variables moved into u.bv */
71249 VdbeCursor *pC;
71250 int res;
71251 UnpackedRecord r;
71252 #endif /* local variables moved into u.bv */
71253
71254 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71255 u.bv.pC = p->apCsr[pOp->p1];
71256 assert( u.bv.pC!=0 );
71257 assert( u.bv.pC->isOrdered );
71258 assert( u.bv.pC->pCursor!=0);
71259 assert( u.bv.pC->deferredMoveto==0 );
71260 assert( pOp->p5==0 || pOp->p5==1 );
71261 assert( pOp->p4type==P4_INT32 );
71262 u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
71263 u.bv.r.nField = (u16)pOp->p4.i;
71264 if( pOp->p5 ){
71265 u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71266 }else{
71267 u.bv.r.flags = UNPACKED_PREFIX_MATCH;
71268 }
71269 u.bv.r.aMem = &aMem[pOp->p3];
71270 #ifdef SQLITE_DEBUG
71271 { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
71272 #endif
71273 rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
 
71274 if( pOp->opcode==OP_IdxLT ){
71275 u.bv.res = -u.bv.res;
71276 }else{
71277 assert( pOp->opcode==OP_IdxGE );
71278 u.bv.res++;
71279 }
71280 if( u.bv.res>0 ){
71281 pc = pOp->p2 - 1 ;
71282 }
71283 break;
71284 }
71285
@@ -71302,47 +70856,46 @@
71302 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
71303 **
71304 ** See also: Clear
71305 */
71306 case OP_Destroy: { /* out2-prerelease */
71307 #if 0 /* local variables moved into u.bw */
71308 int iMoved;
71309 int iCnt;
71310 Vdbe *pVdbe;
71311 int iDb;
71312 #endif /* local variables moved into u.bw */
71313
71314 assert( p->readOnly==0 );
71315 #ifndef SQLITE_OMIT_VIRTUALTABLE
71316 u.bw.iCnt = 0;
71317 for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){
71318 if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader
71319 && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0
71320 ){
71321 u.bw.iCnt++;
71322 }
71323 }
71324 #else
71325 u.bw.iCnt = db->nVdbeRead;
71326 #endif
71327 pOut->flags = MEM_Null;
71328 if( u.bw.iCnt>1 ){
71329 rc = SQLITE_LOCKED;
71330 p->errorAction = OE_Abort;
71331 }else{
71332 u.bw.iDb = pOp->p3;
71333 assert( u.bw.iCnt==1 );
71334 assert( (p->btreeMask & (((yDbMask)1)<<u.bw.iDb))!=0 );
71335 rc = sqlite3BtreeDropTable(db->aDb[u.bw.iDb].pBt, pOp->p1, &u.bw.iMoved);
 
71336 pOut->flags = MEM_Int;
71337 pOut->u.i = u.bw.iMoved;
71338 #ifndef SQLITE_OMIT_AUTOVACUUM
71339 if( rc==SQLITE_OK && u.bw.iMoved!=0 ){
71340 sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1);
71341 /* All OP_Destroy operations occur on the same btree */
71342 assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 );
71343 resetSchemaOnFault = u.bw.iDb+1;
71344 }
71345 #endif
71346 }
71347 break;
71348 }
@@ -71364,27 +70917,25 @@
71364 ** also incremented by the number of rows in the table being cleared.
71365 **
71366 ** See also: Destroy
71367 */
71368 case OP_Clear: {
71369 #if 0 /* local variables moved into u.bx */
71370 int nChange;
71371 #endif /* local variables moved into u.bx */
71372
71373 u.bx.nChange = 0;
71374 assert( p->readOnly==0 );
71375 assert( pOp->p1!=1 );
71376 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71377 rc = sqlite3BtreeClearTable(
71378 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
71379 );
71380 if( pOp->p3 ){
71381 p->nChange += u.bx.nChange;
71382 if( pOp->p3>0 ){
71383 assert( memIsValid(&aMem[pOp->p3]) );
71384 memAboutToChange(p, &aMem[pOp->p3]);
71385 aMem[pOp->p3].u.i += u.bx.nChange;
71386 }
71387 }
71388 break;
71389 }
71390
@@ -71412,30 +70963,28 @@
71412 **
71413 ** See documentation on OP_CreateTable for additional information.
71414 */
71415 case OP_CreateIndex: /* out2-prerelease */
71416 case OP_CreateTable: { /* out2-prerelease */
71417 #if 0 /* local variables moved into u.by */
71418 int pgno;
71419 int flags;
71420 Db *pDb;
71421 #endif /* local variables moved into u.by */
71422
71423 u.by.pgno = 0;
71424 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71425 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71426 assert( p->readOnly==0 );
71427 u.by.pDb = &db->aDb[pOp->p1];
71428 assert( u.by.pDb->pBt!=0 );
71429 if( pOp->opcode==OP_CreateTable ){
71430 /* u.by.flags = BTREE_INTKEY; */
71431 u.by.flags = BTREE_INTKEY;
71432 }else{
71433 u.by.flags = BTREE_BLOBKEY;
71434 }
71435 rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags);
71436 pOut->u.i = u.by.pgno;
71437 break;
71438 }
71439
71440 /* Opcode: ParseSchema P1 * * P4 *
71441 **
@@ -71444,56 +70993,54 @@
71444 **
71445 ** This opcode invokes the parser to create a new virtual machine,
71446 ** then runs the new virtual machine. It is thus a re-entrant opcode.
71447 */
71448 case OP_ParseSchema: {
71449 #if 0 /* local variables moved into u.bz */
71450 int iDb;
71451 const char *zMaster;
71452 char *zSql;
71453 InitData initData;
71454 #endif /* local variables moved into u.bz */
71455
71456 /* Any prepared statement that invokes this opcode will hold mutexes
71457 ** on every btree. This is a prerequisite for invoking
71458 ** sqlite3InitCallback().
71459 */
71460 #ifdef SQLITE_DEBUG
71461 for(u.bz.iDb=0; u.bz.iDb<db->nDb; u.bz.iDb++){
71462 assert( u.bz.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bz.iDb].pBt) );
71463 }
71464 #endif
71465
71466 u.bz.iDb = pOp->p1;
71467 assert( u.bz.iDb>=0 && u.bz.iDb<db->nDb );
71468 assert( DbHasProperty(db, u.bz.iDb, DB_SchemaLoaded) );
71469 /* Used to be a conditional */ {
71470 u.bz.zMaster = SCHEMA_TABLE(u.bz.iDb);
71471 u.bz.initData.db = db;
71472 u.bz.initData.iDb = pOp->p1;
71473 u.bz.initData.pzErrMsg = &p->zErrMsg;
71474 u.bz.zSql = sqlite3MPrintf(db,
71475 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
71476 db->aDb[u.bz.iDb].zName, u.bz.zMaster, pOp->p4.z);
71477 if( u.bz.zSql==0 ){
71478 rc = SQLITE_NOMEM;
71479 }else{
71480 assert( db->init.busy==0 );
71481 db->init.busy = 1;
71482 u.bz.initData.rc = SQLITE_OK;
71483 assert( !db->mallocFailed );
71484 rc = sqlite3_exec(db, u.bz.zSql, sqlite3InitCallback, &u.bz.initData, 0);
71485 if( rc==SQLITE_OK ) rc = u.bz.initData.rc;
71486 sqlite3DbFree(db, u.bz.zSql);
71487 db->init.busy = 0;
71488 }
71489 }
71490 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
71491 if( rc==SQLITE_NOMEM ){
71492 goto no_mem;
71493 }
71494 break;
71495 }
71496
71497 #if !defined(SQLITE_OMIT_ANALYZE)
71498 /* Opcode: LoadAnalysis P1 * * * *
71499 **
@@ -71565,46 +71112,44 @@
71565 ** file, not the main database file.
71566 **
71567 ** This opcode is used to implement the integrity_check pragma.
71568 */
71569 case OP_IntegrityCk: {
71570 #if 0 /* local variables moved into u.ca */
71571 int nRoot; /* Number of tables to check. (Number of root pages.) */
71572 int *aRoot; /* Array of rootpage numbers for tables to be checked */
71573 int j; /* Loop counter */
71574 int nErr; /* Number of errors reported */
71575 char *z; /* Text of the error report */
71576 Mem *pnErr; /* Register keeping track of errors remaining */
71577 #endif /* local variables moved into u.ca */
71578
71579 assert( p->bIsReader );
71580 u.ca.nRoot = pOp->p2;
71581 assert( u.ca.nRoot>0 );
71582 u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) );
71583 if( u.ca.aRoot==0 ) goto no_mem;
71584 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71585 u.ca.pnErr = &aMem[pOp->p3];
71586 assert( (u.ca.pnErr->flags & MEM_Int)!=0 );
71587 assert( (u.ca.pnErr->flags & (MEM_Str|MEM_Blob))==0 );
71588 pIn1 = &aMem[pOp->p1];
71589 for(u.ca.j=0; u.ca.j<u.ca.nRoot; u.ca.j++){
71590 u.ca.aRoot[u.ca.j] = (int)sqlite3VdbeIntValue(&pIn1[u.ca.j]);
71591 }
71592 u.ca.aRoot[u.ca.j] = 0;
71593 assert( pOp->p5<db->nDb );
71594 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
71595 u.ca.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.ca.aRoot, u.ca.nRoot,
71596 (int)u.ca.pnErr->u.i, &u.ca.nErr);
71597 sqlite3DbFree(db, u.ca.aRoot);
71598 u.ca.pnErr->u.i -= u.ca.nErr;
71599 sqlite3VdbeMemSetNull(pIn1);
71600 if( u.ca.nErr==0 ){
71601 assert( u.ca.z==0 );
71602 }else if( u.ca.z==0 ){
71603 goto no_mem;
71604 }else{
71605 sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free);
71606 }
71607 UPDATE_MAX_BLOBSIZE(pIn1);
71608 sqlite3VdbeChangeEncoding(pIn1, encoding);
71609 break;
71610 }
@@ -71636,24 +71181,22 @@
71636 ** Extract the smallest value from boolean index P1 and put that value into
71637 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71638 ** unchanged and jump to instruction P2.
71639 */
71640 case OP_RowSetRead: { /* jump, in1, out3 */
71641 #if 0 /* local variables moved into u.cb */
71642 i64 val;
71643 #endif /* local variables moved into u.cb */
71644
71645 pIn1 = &aMem[pOp->p1];
71646 if( (pIn1->flags & MEM_RowSet)==0
71647 || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
71648 ){
71649 /* The boolean index is empty */
71650 sqlite3VdbeMemSetNull(pIn1);
71651 pc = pOp->p2 - 1;
71652 }else{
71653 /* A value was pulled from the index */
71654 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
71655 }
71656 goto check_for_interrupt;
71657 }
71658
71659 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71679,18 +71222,16 @@
71679 ** inserted, there is no need to search to see if the same value was
71680 ** previously inserted as part of set X (only if it was previously
71681 ** inserted as part of some other set).
71682 */
71683 case OP_RowSetTest: { /* jump, in1, in3 */
71684 #if 0 /* local variables moved into u.cc */
71685 int iSet;
71686 int exists;
71687 #endif /* local variables moved into u.cc */
71688
71689 pIn1 = &aMem[pOp->p1];
71690 pIn3 = &aMem[pOp->p3];
71691 u.cc.iSet = pOp->p4.i;
71692 assert( pIn3->flags&MEM_Int );
71693
71694 /* If there is anything other than a rowset object in memory cell P1,
71695 ** delete it now and initialize P1 with an empty rowset
71696 */
@@ -71698,21 +71239,21 @@
71698 sqlite3VdbeMemSetRowSet(pIn1);
71699 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
71700 }
71701
71702 assert( pOp->p4type==P4_INT32 );
71703 assert( u.cc.iSet==-1 || u.cc.iSet>=0 );
71704 if( u.cc.iSet ){
71705 u.cc.exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71706 (u8)(u.cc.iSet>=0 ? u.cc.iSet & 0xf : 0xff),
71707 pIn3->u.i);
71708 if( u.cc.exists ){
71709 pc = pOp->p2 - 1;
71710 break;
71711 }
71712 }
71713 if( u.cc.iSet>=0 ){
71714 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
71715 }
71716 break;
71717 }
71718
@@ -71731,111 +71272,109 @@
71731 ** memory required by the sub-vdbe at runtime.
71732 **
71733 ** P4 is a pointer to the VM containing the trigger program.
71734 */
71735 case OP_Program: { /* jump */
71736 #if 0 /* local variables moved into u.cd */
71737 int nMem; /* Number of memory registers for sub-program */
71738 int nByte; /* Bytes of runtime space required for sub-program */
71739 Mem *pRt; /* Register to allocate runtime space */
71740 Mem *pMem; /* Used to iterate through memory cells */
71741 Mem *pEnd; /* Last memory cell in new array */
71742 VdbeFrame *pFrame; /* New vdbe frame to execute in */
71743 SubProgram *pProgram; /* Sub-program to execute */
71744 void *t; /* Token identifying trigger */
71745 #endif /* local variables moved into u.cd */
71746
71747 u.cd.pProgram = pOp->p4.pProgram;
71748 u.cd.pRt = &aMem[pOp->p3];
71749 assert( u.cd.pProgram->nOp>0 );
71750
71751 /* If the p5 flag is clear, then recursive invocation of triggers is
71752 ** disabled for backwards compatibility (p5 is set if this sub-program
71753 ** is really a trigger, not a foreign key action, and the flag set
71754 ** and cleared by the "PRAGMA recursive_triggers" command is clear).
71755 **
71756 ** It is recursive invocation of triggers, at the SQL level, that is
71757 ** disabled. In some cases a single trigger may generate more than one
71758 ** SubProgram (if the trigger may be executed with more than one different
71759 ** ON CONFLICT algorithm). SubProgram structures associated with a
71760 ** single trigger all have the same value for the SubProgram.token
71761 ** variable. */
71762 if( pOp->p5 ){
71763 u.cd.t = u.cd.pProgram->token;
71764 for(u.cd.pFrame=p->pFrame; u.cd.pFrame && u.cd.pFrame->token!=u.cd.t; u.cd.pFrame=u.cd.pFrame->pParent);
71765 if( u.cd.pFrame ) break;
71766 }
71767
71768 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
71769 rc = SQLITE_ERROR;
71770 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
71771 break;
71772 }
71773
71774 /* Register u.cd.pRt is used to store the memory required to save the state
71775 ** of the current program, and the memory required at runtime to execute
71776 ** the trigger program. If this trigger has been fired before, then u.cd.pRt
71777 ** is already allocated. Otherwise, it must be initialized. */
71778 if( (u.cd.pRt->flags&MEM_Frame)==0 ){
71779 /* SubProgram.nMem is set to the number of memory cells used by the
71780 ** program stored in SubProgram.aOp. As well as these, one memory
71781 ** cell is required for each cursor used by the program. Set local
71782 ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value.
71783 */
71784 u.cd.nMem = u.cd.pProgram->nMem + u.cd.pProgram->nCsr;
71785 u.cd.nByte = ROUND8(sizeof(VdbeFrame))
71786 + u.cd.nMem * sizeof(Mem)
71787 + u.cd.pProgram->nCsr * sizeof(VdbeCursor *)
71788 + u.cd.pProgram->nOnce * sizeof(u8);
71789 u.cd.pFrame = sqlite3DbMallocZero(db, u.cd.nByte);
71790 if( !u.cd.pFrame ){
71791 goto no_mem;
71792 }
71793 sqlite3VdbeMemRelease(u.cd.pRt);
71794 u.cd.pRt->flags = MEM_Frame;
71795 u.cd.pRt->u.pFrame = u.cd.pFrame;
71796
71797 u.cd.pFrame->v = p;
71798 u.cd.pFrame->nChildMem = u.cd.nMem;
71799 u.cd.pFrame->nChildCsr = u.cd.pProgram->nCsr;
71800 u.cd.pFrame->pc = pc;
71801 u.cd.pFrame->aMem = p->aMem;
71802 u.cd.pFrame->nMem = p->nMem;
71803 u.cd.pFrame->apCsr = p->apCsr;
71804 u.cd.pFrame->nCursor = p->nCursor;
71805 u.cd.pFrame->aOp = p->aOp;
71806 u.cd.pFrame->nOp = p->nOp;
71807 u.cd.pFrame->token = u.cd.pProgram->token;
71808 u.cd.pFrame->aOnceFlag = p->aOnceFlag;
71809 u.cd.pFrame->nOnceFlag = p->nOnceFlag;
71810
71811 u.cd.pEnd = &VdbeFrameMem(u.cd.pFrame)[u.cd.pFrame->nChildMem];
71812 for(u.cd.pMem=VdbeFrameMem(u.cd.pFrame); u.cd.pMem!=u.cd.pEnd; u.cd.pMem++){
71813 u.cd.pMem->flags = MEM_Invalid;
71814 u.cd.pMem->db = db;
71815 }
71816 }else{
71817 u.cd.pFrame = u.cd.pRt->u.pFrame;
71818 assert( u.cd.pProgram->nMem+u.cd.pProgram->nCsr==u.cd.pFrame->nChildMem );
71819 assert( u.cd.pProgram->nCsr==u.cd.pFrame->nChildCsr );
71820 assert( pc==u.cd.pFrame->pc );
71821 }
71822
71823 p->nFrame++;
71824 u.cd.pFrame->pParent = p->pFrame;
71825 u.cd.pFrame->lastRowid = lastRowid;
71826 u.cd.pFrame->nChange = p->nChange;
71827 p->nChange = 0;
71828 p->pFrame = u.cd.pFrame;
71829 p->aMem = aMem = &VdbeFrameMem(u.cd.pFrame)[-1];
71830 p->nMem = u.cd.pFrame->nChildMem;
71831 p->nCursor = (u16)u.cd.pFrame->nChildCsr;
71832 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71833 p->aOp = aOp = u.cd.pProgram->aOp;
71834 p->nOp = u.cd.pProgram->nOp;
71835 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71836 p->nOnceFlag = u.cd.pProgram->nOnce;
71837 pc = -1;
71838 memset(p->aOnceFlag, 0, p->nOnceFlag);
71839
71840 break;
71841 }
@@ -71851,17 +71390,15 @@
71851 ** The address of the cell in the parent frame is determined by adding
71852 ** the value of the P1 argument to the value of the P1 argument to the
71853 ** calling OP_Program instruction.
71854 */
71855 case OP_Param: { /* out2-prerelease */
71856 #if 0 /* local variables moved into u.ce */
71857 VdbeFrame *pFrame;
71858 Mem *pIn;
71859 #endif /* local variables moved into u.ce */
71860 u.ce.pFrame = p->pFrame;
71861 u.ce.pIn = &u.ce.pFrame->aMem[pOp->p1 + u.ce.pFrame->aOp[u.ce.pFrame->pc].p1];
71862 sqlite3VdbeMemShallowCopy(pOut, u.ce.pIn, MEM_Ephem);
71863 break;
71864 }
71865
71866 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71867
@@ -71918,26 +71455,23 @@
71918 **
71919 ** This instruction throws an error if the memory cell is not initially
71920 ** an integer.
71921 */
71922 case OP_MemMax: { /* in2 */
71923 #if 0 /* local variables moved into u.cf */
71924 Mem *pIn1;
71925 VdbeFrame *pFrame;
71926 #endif /* local variables moved into u.cf */
71927 if( p->pFrame ){
71928 for(u.cf.pFrame=p->pFrame; u.cf.pFrame->pParent; u.cf.pFrame=u.cf.pFrame->pParent);
71929 u.cf.pIn1 = &u.cf.pFrame->aMem[pOp->p1];
71930 }else{
71931 u.cf.pIn1 = &aMem[pOp->p1];
71932 }
71933 assert( memIsValid(u.cf.pIn1) );
71934 sqlite3VdbeMemIntegerify(u.cf.pIn1);
71935 pIn2 = &aMem[pOp->p2];
71936 sqlite3VdbeMemIntegerify(pIn2);
71937 if( u.cf.pIn1->u.i<pIn2->u.i){
71938 u.cf.pIn1->u.i = pIn2->u.i;
71939 }
71940 break;
71941 }
71942 #endif /* SQLITE_OMIT_AUTOINCREMENT */
71943
@@ -72004,60 +71538,58 @@
72004 **
72005 ** The P5 arguments are taken from register P2 and its
72006 ** successors.
72007 */
72008 case OP_AggStep: {
72009 #if 0 /* local variables moved into u.cg */
72010 int n;
72011 int i;
72012 Mem *pMem;
72013 Mem *pRec;
72014 sqlite3_context ctx;
72015 sqlite3_value **apVal;
72016 #endif /* local variables moved into u.cg */
72017
72018 u.cg.n = pOp->p5;
72019 assert( u.cg.n>=0 );
72020 u.cg.pRec = &aMem[pOp->p2];
72021 u.cg.apVal = p->apArg;
72022 assert( u.cg.apVal || u.cg.n==0 );
72023 for(u.cg.i=0; u.cg.i<u.cg.n; u.cg.i++, u.cg.pRec++){
72024 assert( memIsValid(u.cg.pRec) );
72025 u.cg.apVal[u.cg.i] = u.cg.pRec;
72026 memAboutToChange(p, u.cg.pRec);
72027 sqlite3VdbeMemStoreType(u.cg.pRec);
72028 }
72029 u.cg.ctx.pFunc = pOp->p4.pFunc;
72030 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72031 u.cg.ctx.pMem = u.cg.pMem = &aMem[pOp->p3];
72032 u.cg.pMem->n++;
72033 u.cg.ctx.s.flags = MEM_Null;
72034 u.cg.ctx.s.z = 0;
72035 u.cg.ctx.s.zMalloc = 0;
72036 u.cg.ctx.s.xDel = 0;
72037 u.cg.ctx.s.db = db;
72038 u.cg.ctx.isError = 0;
72039 u.cg.ctx.pColl = 0;
72040 u.cg.ctx.skipFlag = 0;
72041 if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
72042 assert( pOp>p->aOp );
72043 assert( pOp[-1].p4type==P4_COLLSEQ );
72044 assert( pOp[-1].opcode==OP_CollSeq );
72045 u.cg.ctx.pColl = pOp[-1].p4.pColl;
72046 }
72047 (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */
72048 if( u.cg.ctx.isError ){
72049 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cg.ctx.s));
72050 rc = u.cg.ctx.isError;
72051 }
72052 if( u.cg.ctx.skipFlag ){
72053 assert( pOp[-1].opcode==OP_CollSeq );
72054 u.cg.i = pOp[-1].p1;
72055 if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1);
72056 }
72057
72058 sqlite3VdbeMemRelease(&u.cg.ctx.s);
72059
72060 break;
72061 }
72062
72063 /* Opcode: AggFinal P1 P2 * P4 *
@@ -72072,23 +71604,21 @@
72072 ** functions that can take varying numbers of arguments. The
72073 ** P4 argument is only needed for the degenerate case where
72074 ** the step function was not previously called.
72075 */
72076 case OP_AggFinal: {
72077 #if 0 /* local variables moved into u.ch */
72078 Mem *pMem;
72079 #endif /* local variables moved into u.ch */
72080 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
72081 u.ch.pMem = &aMem[pOp->p1];
72082 assert( (u.ch.pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
72083 rc = sqlite3VdbeMemFinalize(u.ch.pMem, pOp->p4.pFunc);
72084 if( rc ){
72085 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem));
72086 }
72087 sqlite3VdbeChangeEncoding(u.ch.pMem, encoding);
72088 UPDATE_MAX_BLOBSIZE(u.ch.pMem);
72089 if( sqlite3VdbeMemTooBig(u.ch.pMem) ){
72090 goto too_big;
72091 }
72092 break;
72093 }
72094
@@ -72103,31 +71633,29 @@
72103 ** in the WAL that have been checkpointed after the checkpoint
72104 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
72105 ** mem[P3+2] are initialized to -1.
72106 */
72107 case OP_Checkpoint: {
72108 #if 0 /* local variables moved into u.ci */
72109 int i; /* Loop counter */
72110 int aRes[3]; /* Results */
72111 Mem *pMem; /* Write results here */
72112 #endif /* local variables moved into u.ci */
72113
72114 assert( p->readOnly==0 );
72115 u.ci.aRes[0] = 0;
72116 u.ci.aRes[1] = u.ci.aRes[2] = -1;
72117 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
72118 || pOp->p2==SQLITE_CHECKPOINT_FULL
72119 || pOp->p2==SQLITE_CHECKPOINT_RESTART
72120 );
72121 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]);
72122 if( rc==SQLITE_BUSY ){
72123 rc = SQLITE_OK;
72124 u.ci.aRes[0] = 1;
72125 }
72126 for(u.ci.i=0, u.ci.pMem = &aMem[pOp->p3]; u.ci.i<3; u.ci.i++, u.ci.pMem++){
72127 sqlite3VdbeMemSetInt64(u.ci.pMem, (i64)u.ci.aRes[u.ci.i]);
72128 }
72129 break;
72130 };
72131 #endif
72132
72133 #ifndef SQLITE_OMIT_PRAGMA
@@ -72141,98 +71669,96 @@
72141 ** If changing into or out of WAL mode the procedure is more complicated.
72142 **
72143 ** Write a string containing the final journal-mode to register P2.
72144 */
72145 case OP_JournalMode: { /* out2-prerelease */
72146 #if 0 /* local variables moved into u.cj */
72147 Btree *pBt; /* Btree to change journal mode of */
72148 Pager *pPager; /* Pager associated with pBt */
72149 int eNew; /* New journal mode */
72150 int eOld; /* The old journal mode */
72151 #ifndef SQLITE_OMIT_WAL
72152 const char *zFilename; /* Name of database file for pPager */
72153 #endif
72154 #endif /* local variables moved into u.cj */
72155
72156 u.cj.eNew = pOp->p3;
72157 assert( u.cj.eNew==PAGER_JOURNALMODE_DELETE
72158 || u.cj.eNew==PAGER_JOURNALMODE_TRUNCATE
72159 || u.cj.eNew==PAGER_JOURNALMODE_PERSIST
72160 || u.cj.eNew==PAGER_JOURNALMODE_OFF
72161 || u.cj.eNew==PAGER_JOURNALMODE_MEMORY
72162 || u.cj.eNew==PAGER_JOURNALMODE_WAL
72163 || u.cj.eNew==PAGER_JOURNALMODE_QUERY
72164 );
72165 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72166 assert( p->readOnly==0 );
72167
72168 u.cj.pBt = db->aDb[pOp->p1].pBt;
72169 u.cj.pPager = sqlite3BtreePager(u.cj.pBt);
72170 u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager);
72171 if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld;
72172 if( !sqlite3PagerOkToChangeJournalMode(u.cj.pPager) ) u.cj.eNew = u.cj.eOld;
72173
72174 #ifndef SQLITE_OMIT_WAL
72175 u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1);
72176
72177 /* Do not allow a transition to journal_mode=WAL for a database
72178 ** in temporary storage or if the VFS does not support shared memory
72179 */
72180 if( u.cj.eNew==PAGER_JOURNALMODE_WAL
72181 && (sqlite3Strlen30(u.cj.zFilename)==0 /* Temp file */
72182 || !sqlite3PagerWalSupported(u.cj.pPager)) /* No shared-memory support */
72183 ){
72184 u.cj.eNew = u.cj.eOld;
72185 }
72186
72187 if( (u.cj.eNew!=u.cj.eOld)
72188 && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
72189 ){
72190 if( !db->autoCommit || db->nVdbeRead>1 ){
72191 rc = SQLITE_ERROR;
72192 sqlite3SetString(&p->zErrMsg, db,
72193 "cannot change %s wal mode from within a transaction",
72194 (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
72195 );
72196 break;
72197 }else{
72198
72199 if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){
72200 /* If leaving WAL mode, close the log file. If successful, the call
72201 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
72202 ** file. An EXCLUSIVE lock may still be held on the database file
72203 ** after a successful return.
72204 */
72205 rc = sqlite3PagerCloseWal(u.cj.pPager);
72206 if( rc==SQLITE_OK ){
72207 sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
72208 }
72209 }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){
72210 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
72211 ** as an intermediate */
72212 sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF);
72213 }
72214
72215 /* Open a transaction on the database file. Regardless of the journal
72216 ** mode, this transaction always uses a rollback journal.
72217 */
72218 assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 );
72219 if( rc==SQLITE_OK ){
72220 rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
72221 }
72222 }
72223 }
72224 #endif /* ifndef SQLITE_OMIT_WAL */
72225
72226 if( rc ){
72227 u.cj.eNew = u.cj.eOld;
72228 }
72229 u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
72230
72231 pOut = &aMem[pOp->p2];
72232 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
72233 pOut->z = (char *)sqlite3JournalModename(u.cj.eNew);
72234 pOut->n = sqlite3Strlen30(pOut->z);
72235 pOut->enc = SQLITE_UTF8;
72236 sqlite3VdbeChangeEncoding(pOut, encoding);
72237 break;
72238 };
@@ -72258,19 +71784,17 @@
72258 ** Perform a single step of the incremental vacuum procedure on
72259 ** the P1 database. If the vacuum has finished, jump to instruction
72260 ** P2. Otherwise, fall through to the next instruction.
72261 */
72262 case OP_IncrVacuum: { /* jump */
72263 #if 0 /* local variables moved into u.ck */
72264 Btree *pBt;
72265 #endif /* local variables moved into u.ck */
72266
72267 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72268 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72269 assert( p->readOnly==0 );
72270 u.ck.pBt = db->aDb[pOp->p1].pBt;
72271 rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
72272 if( rc==SQLITE_DONE ){
72273 pc = pOp->p2 - 1;
72274 rc = SQLITE_OK;
72275 }
72276 break;
@@ -72337,16 +71861,14 @@
72337 ** Also, whether or not P4 is set, check that this is not being called from
72338 ** within a callback to a virtual table xSync() method. If it is, the error
72339 ** code will be set to SQLITE_LOCKED.
72340 */
72341 case OP_VBegin: {
72342 #if 0 /* local variables moved into u.cl */
72343 VTable *pVTab;
72344 #endif /* local variables moved into u.cl */
72345 u.cl.pVTab = pOp->p4.pVtab;
72346 rc = sqlite3VtabBegin(db, u.cl.pVTab);
72347 if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab);
72348 break;
72349 }
72350 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72351
72352 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72381,37 +71903,34 @@
72381 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72382 ** P1 is a cursor number. This opcode opens a cursor to the virtual
72383 ** table and stores that cursor in P1.
72384 */
72385 case OP_VOpen: {
72386 #if 0 /* local variables moved into u.cm */
72387 VdbeCursor *pCur;
72388 sqlite3_vtab_cursor *pVtabCursor;
72389 sqlite3_vtab *pVtab;
72390 sqlite3_module *pModule;
72391 #endif /* local variables moved into u.cm */
72392
72393 assert( p->bIsReader );
72394 u.cm.pCur = 0;
72395 u.cm.pVtabCursor = 0;
72396 u.cm.pVtab = pOp->p4.pVtab->pVtab;
72397 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
72398 assert(u.cm.pVtab && u.cm.pModule);
72399 rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor);
72400 sqlite3VtabImportErrmsg(p, u.cm.pVtab);
72401 if( SQLITE_OK==rc ){
72402 /* Initialize sqlite3_vtab_cursor base class */
72403 u.cm.pVtabCursor->pVtab = u.cm.pVtab;
72404
72405 /* Initialize vdbe cursor object */
72406 u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72407 if( u.cm.pCur ){
72408 u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
72409 u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
72410 }else{
72411 db->mallocFailed = 1;
72412 u.cm.pModule->xClose(u.cm.pVtabCursor);
72413 }
72414 }
72415 break;
72416 }
72417 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72435,11 +71954,10 @@
72435 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
72436 **
72437 ** A jump is made to P2 if the result set after filtering would be empty.
72438 */
72439 case OP_VFilter: { /* jump */
72440 #if 0 /* local variables moved into u.cn */
72441 int nArg;
72442 int iQuery;
72443 const sqlite3_module *pModule;
72444 Mem *pQuery;
72445 Mem *pArgc;
@@ -72447,49 +71965,48 @@
72447 sqlite3_vtab *pVtab;
72448 VdbeCursor *pCur;
72449 int res;
72450 int i;
72451 Mem **apArg;
72452 #endif /* local variables moved into u.cn */
72453
72454 u.cn.pQuery = &aMem[pOp->p3];
72455 u.cn.pArgc = &u.cn.pQuery[1];
72456 u.cn.pCur = p->apCsr[pOp->p1];
72457 assert( memIsValid(u.cn.pQuery) );
72458 REGISTER_TRACE(pOp->p3, u.cn.pQuery);
72459 assert( u.cn.pCur->pVtabCursor );
72460 u.cn.pVtabCursor = u.cn.pCur->pVtabCursor;
72461 u.cn.pVtab = u.cn.pVtabCursor->pVtab;
72462 u.cn.pModule = u.cn.pVtab->pModule;
72463
72464 /* Grab the index number and argc parameters */
72465 assert( (u.cn.pQuery->flags&MEM_Int)!=0 && u.cn.pArgc->flags==MEM_Int );
72466 u.cn.nArg = (int)u.cn.pArgc->u.i;
72467 u.cn.iQuery = (int)u.cn.pQuery->u.i;
72468
72469 /* Invoke the xFilter method */
72470 {
72471 u.cn.res = 0;
72472 u.cn.apArg = p->apArg;
72473 for(u.cn.i = 0; u.cn.i<u.cn.nArg; u.cn.i++){
72474 u.cn.apArg[u.cn.i] = &u.cn.pArgc[u.cn.i+1];
72475 sqlite3VdbeMemStoreType(u.cn.apArg[u.cn.i]);
72476 }
72477
72478 p->inVtabMethod = 1;
72479 rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
72480 p->inVtabMethod = 0;
72481 sqlite3VtabImportErrmsg(p, u.cn.pVtab);
72482 if( rc==SQLITE_OK ){
72483 u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
72484 }
72485
72486 if( u.cn.res ){
72487 pc = pOp->p2 - 1;
72488 }
72489 }
72490 u.cn.pCur->nullRow = 0;
72491
72492 break;
72493 }
72494 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72495
@@ -72500,55 +72017,53 @@
72500 ** Store the value of the P2-th column of
72501 ** the row of the virtual-table that the
72502 ** P1 cursor is pointing to into register P3.
72503 */
72504 case OP_VColumn: {
72505 #if 0 /* local variables moved into u.co */
72506 sqlite3_vtab *pVtab;
72507 const sqlite3_module *pModule;
72508 Mem *pDest;
72509 sqlite3_context sContext;
72510 #endif /* local variables moved into u.co */
72511
72512 VdbeCursor *pCur = p->apCsr[pOp->p1];
72513 assert( pCur->pVtabCursor );
72514 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72515 u.co.pDest = &aMem[pOp->p3];
72516 memAboutToChange(p, u.co.pDest);
72517 if( pCur->nullRow ){
72518 sqlite3VdbeMemSetNull(u.co.pDest);
72519 break;
72520 }
72521 u.co.pVtab = pCur->pVtabCursor->pVtab;
72522 u.co.pModule = u.co.pVtab->pModule;
72523 assert( u.co.pModule->xColumn );
72524 memset(&u.co.sContext, 0, sizeof(u.co.sContext));
72525
72526 /* The output cell may already have a buffer allocated. Move
72527 ** the current contents to u.co.sContext.s so in case the user-function
72528 ** can use the already allocated buffer instead of allocating a
72529 ** new one.
72530 */
72531 sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
72532 MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
72533
72534 rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2);
72535 sqlite3VtabImportErrmsg(p, u.co.pVtab);
72536 if( u.co.sContext.isError ){
72537 rc = u.co.sContext.isError;
72538 }
72539
72540 /* Copy the result of the function to the P3 register. We
72541 ** do this regardless of whether or not an error occurred to ensure any
72542 ** dynamic allocation in u.co.sContext.s (a Mem struct) is released.
72543 */
72544 sqlite3VdbeChangeEncoding(&u.co.sContext.s, encoding);
72545 sqlite3VdbeMemMove(u.co.pDest, &u.co.sContext.s);
72546 REGISTER_TRACE(pOp->p3, u.co.pDest);
72547 UPDATE_MAX_BLOBSIZE(u.co.pDest);
72548
72549 if( sqlite3VdbeMemTooBig(u.co.pDest) ){
72550 goto too_big;
72551 }
72552 break;
72553 }
72554 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72559,42 +72074,40 @@
72559 ** Advance virtual table P1 to the next row in its result set and
72560 ** jump to instruction P2. Or, if the virtual table has reached
72561 ** the end of its result set, then fall through to the next instruction.
72562 */
72563 case OP_VNext: { /* jump */
72564 #if 0 /* local variables moved into u.cp */
72565 sqlite3_vtab *pVtab;
72566 const sqlite3_module *pModule;
72567 int res;
72568 VdbeCursor *pCur;
72569 #endif /* local variables moved into u.cp */
72570
72571 u.cp.res = 0;
72572 u.cp.pCur = p->apCsr[pOp->p1];
72573 assert( u.cp.pCur->pVtabCursor );
72574 if( u.cp.pCur->nullRow ){
72575 break;
72576 }
72577 u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab;
72578 u.cp.pModule = u.cp.pVtab->pModule;
72579 assert( u.cp.pModule->xNext );
72580
72581 /* Invoke the xNext() method of the module. There is no way for the
72582 ** underlying implementation to return an error if one occurs during
72583 ** xNext(). Instead, if an error occurs, true is returned (indicating that
72584 ** data is available) and the error code returned when xColumn or
72585 ** some other method is next invoked on the save virtual table cursor.
72586 */
72587 p->inVtabMethod = 1;
72588 rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
72589 p->inVtabMethod = 0;
72590 sqlite3VtabImportErrmsg(p, u.cp.pVtab);
72591 if( rc==SQLITE_OK ){
72592 u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
72593 }
72594
72595 if( !u.cp.res ){
72596 /* If there is data, jump to P2 */
72597 pc = pOp->p2 - 1;
72598 }
72599 goto check_for_interrupt;
72600 }
@@ -72606,29 +72119,27 @@
72606 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72607 ** This opcode invokes the corresponding xRename method. The value
72608 ** in register P1 is passed as the zName argument to the xRename method.
72609 */
72610 case OP_VRename: {
72611 #if 0 /* local variables moved into u.cq */
72612 sqlite3_vtab *pVtab;
72613 Mem *pName;
72614 #endif /* local variables moved into u.cq */
72615
72616 u.cq.pVtab = pOp->p4.pVtab->pVtab;
72617 u.cq.pName = &aMem[pOp->p1];
72618 assert( u.cq.pVtab->pModule->xRename );
72619 assert( memIsValid(u.cq.pName) );
72620 assert( p->readOnly==0 );
72621 REGISTER_TRACE(pOp->p1, u.cq.pName);
72622 assert( u.cq.pName->flags & MEM_Str );
72623 testcase( u.cq.pName->enc==SQLITE_UTF8 );
72624 testcase( u.cq.pName->enc==SQLITE_UTF16BE );
72625 testcase( u.cq.pName->enc==SQLITE_UTF16LE );
72626 rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8);
72627 if( rc==SQLITE_OK ){
72628 rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
72629 sqlite3VtabImportErrmsg(p, u.cq.pVtab);
72630 p->expired = 0;
72631 }
72632 break;
72633 }
72634 #endif
@@ -72657,46 +72168,44 @@
72657 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72658 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72659 ** is set to the value of the rowid for the row just inserted.
72660 */
72661 case OP_VUpdate: {
72662 #if 0 /* local variables moved into u.cr */
72663 sqlite3_vtab *pVtab;
72664 sqlite3_module *pModule;
72665 int nArg;
72666 int i;
72667 sqlite_int64 rowid;
72668 Mem **apArg;
72669 Mem *pX;
72670 #endif /* local variables moved into u.cr */
72671
72672 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72673 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
72674 );
72675 assert( p->readOnly==0 );
72676 u.cr.pVtab = pOp->p4.pVtab->pVtab;
72677 u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule;
72678 u.cr.nArg = pOp->p2;
72679 assert( pOp->p4type==P4_VTAB );
72680 if( ALWAYS(u.cr.pModule->xUpdate) ){
72681 u8 vtabOnConflict = db->vtabOnConflict;
72682 u.cr.apArg = p->apArg;
72683 u.cr.pX = &aMem[pOp->p3];
72684 for(u.cr.i=0; u.cr.i<u.cr.nArg; u.cr.i++){
72685 assert( memIsValid(u.cr.pX) );
72686 memAboutToChange(p, u.cr.pX);
72687 sqlite3VdbeMemStoreType(u.cr.pX);
72688 u.cr.apArg[u.cr.i] = u.cr.pX;
72689 u.cr.pX++;
72690 }
72691 db->vtabOnConflict = pOp->p5;
72692 rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
72693 db->vtabOnConflict = vtabOnConflict;
72694 sqlite3VtabImportErrmsg(p, u.cr.pVtab);
72695 if( rc==SQLITE_OK && pOp->p1 ){
72696 assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) );
72697 db->lastRowid = lastRowid = u.cr.rowid;
72698 }
72699 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
72700 if( pOp->p5==OE_Ignore ){
72701 rc = SQLITE_OK;
72702 }else{
@@ -72752,38 +72261,36 @@
72752 **
72753 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72754 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72755 */
72756 case OP_Trace: {
72757 #if 0 /* local variables moved into u.cs */
72758 char *zTrace;
72759 char *z;
72760 #endif /* local variables moved into u.cs */
72761
72762 if( db->xTrace
72763 && !p->doingRerun
72764 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72765 ){
72766 u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
72767 db->xTrace(db->pTraceArg, u.cs.z);
72768 sqlite3DbFree(db, u.cs.z);
72769 }
72770 #ifdef SQLITE_USE_FCNTL_TRACE
72771 u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72772 if( u.cs.zTrace ){
72773 int i;
72774 for(i=0; i<db->nDb; i++){
72775 if( ((1<<i) & p->btreeMask)==0 ) continue;
72776 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace);
72777 }
72778 }
72779 #endif /* SQLITE_USE_FCNTL_TRACE */
72780 #ifdef SQLITE_DEBUG
72781 if( (db->flags & SQLITE_SqlTrace)!=0
72782 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72783 ){
72784 sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
72785 }
72786 #endif /* SQLITE_DEBUG */
72787 break;
72788 }
72789 #endif
@@ -72832,17 +72339,17 @@
72832 */
72833 #ifndef NDEBUG
72834 assert( pc>=-1 && pc<p->nOp );
72835
72836 #ifdef SQLITE_DEBUG
72837 if( p->trace ){
72838 if( rc!=0 ) fprintf(p->trace,"rc=%d\n",rc);
72839 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
72840 registerTrace(p->trace, pOp->p2, &aMem[pOp->p2]);
72841 }
72842 if( pOp->opflags & OPFLG_OUT3 ){
72843 registerTrace(p->trace, pOp->p3, &aMem[pOp->p3]);
72844 }
72845 }
72846 #endif /* SQLITE_DEBUG */
72847 #endif /* NDEBUG */
72848 } /* The end of the for(;;) loop the loops through opcodes */
@@ -72908,10 +72415,11 @@
72908 rc = SQLITE_INTERRUPT;
72909 p->rc = rc;
72910 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
72911 goto vdbe_error_halt;
72912 }
 
72913
72914 /************** End of vdbe.c ************************************************/
72915 /************** Begin file vdbeblob.c ****************************************/
72916 /*
72917 ** 2007 May 1
@@ -72975,22 +72483,23 @@
72975 assert( v->aVar[0].flags&MEM_Int );
72976 v->aVar[0].u.i = iRow;
72977
72978 rc = sqlite3_step(p->pStmt);
72979 if( rc==SQLITE_ROW ){
72980 u32 type = v->apCsr[0]->aType[p->iCol];
 
72981 if( type<12 ){
72982 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
72983 type==0?"null": type==7?"real": "integer"
72984 );
72985 rc = SQLITE_ERROR;
72986 sqlite3_finalize(p->pStmt);
72987 p->pStmt = 0;
72988 }else{
72989 p->iOffset = v->apCsr[0]->aOffset[p->iCol];
72990 p->nByte = sqlite3VdbeSerialTypeLen(type);
72991 p->pCsr = v->apCsr[0]->pCursor;
72992 sqlite3BtreeEnterCursor(p->pCsr);
72993 sqlite3BtreeCacheOverflow(p->pCsr);
72994 sqlite3BtreeLeaveCursor(p->pCsr);
72995 }
72996 }
@@ -73239,10 +72748,11 @@
73239 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
73240 sqlite3DbFree(db, pBlob);
73241 }
73242 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
73243 sqlite3DbFree(db, zErr);
 
73244 sqlite3StackFree(db, pParse);
73245 rc = sqlite3ApiExit(db, rc);
73246 sqlite3_mutex_leave(db->mutex);
73247 return rc;
73248 }
@@ -75204,14 +74714,14 @@
75204 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
75205 incrAggFunctionDepth(pDup, nSubquery);
75206 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
75207 if( pDup==0 ) return;
75208 ExprSetProperty(pDup, EP_Skip);
75209 if( pEList->a[iCol].iAlias==0 ){
75210 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
75211 }
75212 pDup->iTable = pEList->a[iCol].iAlias;
75213 }
75214 if( pExpr->op==TK_COLLATE ){
75215 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
75216 }
75217
@@ -75448,11 +74958,13 @@
75448 }
75449 break;
75450 }
75451 }
75452 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75453 iCol = -1; /* IMP: R-44911-55124 */
 
 
75454 }
75455 if( iCol<pTab->nCol ){
75456 cnt++;
75457 if( iCol<0 ){
75458 pExpr->affinity = SQLITE_AFF_INTEGER;
@@ -75763,11 +75275,10 @@
75763 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
75764 }
75765
75766 /* Resolve function names
75767 */
75768 case TK_CONST_FUNC:
75769 case TK_FUNCTION: {
75770 ExprList *pList = pExpr->x.pList; /* The argument list */
75771 int n = pList ? pList->nExpr : 0; /* Number of arguments */
75772 int no_such_func = 0; /* True if no such function exists */
75773 int wrong_num_args = 0; /* True if wrong number of arguments */
@@ -75776,11 +75287,10 @@
75776 int nId; /* Number of characters in function name */
75777 const char *zId; /* The function name. */
75778 FuncDef *pDef; /* Information about the function */
75779 u8 enc = ENC(pParse->db); /* The database encoding */
75780
75781 testcase( pExpr->op==TK_CONST_FUNC );
75782 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
75783 notValidPartIdxWhere(pParse, pNC, "functions");
75784 zId = pExpr->u.zToken;
75785 nId = sqlite3Strlen30(zId);
75786 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
@@ -75821,10 +75331,11 @@
75821 pNC->nErr++;
75822 }
75823 pExpr->op = TK_NULL;
75824 return WRC_Prune;
75825 }
 
75826 }
75827 #endif
75828 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
75829 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
75830 pNC->nErr++;
@@ -76072,11 +75583,11 @@
76072 assert( pItem->pExpr->op==TK_COLLATE );
76073 assert( pItem->pExpr->pLeft==pE );
76074 pItem->pExpr->pLeft = pNew;
76075 }
76076 sqlite3ExprDelete(db, pE);
76077 pItem->iOrderByCol = (u16)iCol;
76078 pItem->done = 1;
76079 }else{
76080 moreToDo = 1;
76081 }
76082 }
@@ -76093,12 +75604,12 @@
76093 }
76094
76095 /*
76096 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
76097 ** the SELECT statement pSelect. If any term is reference to a
76098 ** result set expression (as determined by the ExprList.a.iOrderByCol field)
76099 ** then convert that term into a copy of the corresponding result set
76100 ** column.
76101 **
76102 ** If any errors are detected, add an error message to pParse and
76103 ** return non-zero. Return zero if no errors are seen.
76104 */
@@ -76121,16 +75632,16 @@
76121 }
76122 #endif
76123 pEList = pSelect->pEList;
76124 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
76125 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
76126 if( pItem->iOrderByCol ){
76127 if( pItem->iOrderByCol>pEList->nExpr ){
76128 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
76129 return 1;
76130 }
76131 resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0);
76132 }
76133 }
76134 return 0;
76135 }
76136
@@ -76175,11 +75686,11 @@
76175 if( iCol>0 ){
76176 /* If an AS-name match is found, mark this ORDER BY column as being
76177 ** a copy of the iCol-th result-set column. The subsequent call to
76178 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
76179 ** copy of the iCol-th result-set expression. */
76180 pItem->iOrderByCol = (u16)iCol;
76181 continue;
76182 }
76183 }
76184 if( sqlite3ExprIsInteger(pE2, &iCol) ){
76185 /* The ORDER BY term is an integer constant. Again, set the column
@@ -76187,22 +75698,22 @@
76187 ** order-by term to a copy of the result-set expression */
76188 if( iCol<1 || iCol>0xffff ){
76189 resolveOutOfRangeError(pParse, zType, i+1, nResult);
76190 return 1;
76191 }
76192 pItem->iOrderByCol = (u16)iCol;
76193 continue;
76194 }
76195
76196 /* Otherwise, treat the ORDER BY term as an ordinary expression */
76197 pItem->iOrderByCol = 0;
76198 if( sqlite3ResolveExprNames(pNC, pE) ){
76199 return 1;
76200 }
76201 for(j=0; j<pSelect->pEList->nExpr; j++){
76202 if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
76203 pItem->iOrderByCol = j+1;
76204 }
76205 }
76206 }
76207 return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
76208 }
@@ -77477,12 +76988,11 @@
77477 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
77478 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
77479 pItem->sortOrder = pOldItem->sortOrder;
77480 pItem->done = 0;
77481 pItem->bSpanIsTab = pOldItem->bSpanIsTab;
77482 pItem->iOrderByCol = pOldItem->iOrderByCol;
77483 pItem->iAlias = pOldItem->iAlias;
77484 }
77485 return pNew;
77486 }
77487
77488 /*
@@ -77739,13 +77249,16 @@
77739 return WRC_Abort;
77740 }
77741
77742 switch( pExpr->op ){
77743 /* Consider functions to be constant if all their arguments are constant
77744 ** and pWalker->u.i==2 */
 
77745 case TK_FUNCTION:
77746 if( pWalker->u.i==2 ) return 0;
 
 
77747 /* Fall through */
77748 case TK_ID:
77749 case TK_COLUMN:
77750 case TK_AGG_FUNCTION:
77751 case TK_AGG_COLUMN:
@@ -78903,10 +78416,11 @@
78903 int inReg = target; /* Results stored in register inReg */
78904 int regFree1 = 0; /* If non-zero free this temporary register */
78905 int regFree2 = 0; /* If non-zero free this temporary register */
78906 int r1, r2, r3, r4; /* Various register numbers */
78907 sqlite3 *db = pParse->db; /* The database connection */
 
78908
78909 assert( target>0 && target<=pParse->nMem );
78910 if( v==0 ){
78911 assert( pParse->db->mallocFailed );
78912 return 0;
@@ -79122,12 +78636,14 @@
79122 }else if( pLeft->op==TK_FLOAT ){
79123 assert( !ExprHasProperty(pExpr, EP_IntValue) );
79124 codeReal(v, pLeft->u.zToken, 1, target);
79125 #endif
79126 }else{
79127 regFree1 = r1 = sqlite3GetTempReg(pParse);
79128 sqlite3VdbeAddOp2(v, OP_Integer, 0, r1);
 
 
79129 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree2);
79130 sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
79131 testcase( regFree2==0 );
79132 }
79133 inReg = target;
@@ -79168,11 +78684,10 @@
79168 }else{
79169 inReg = pInfo->aFunc[pExpr->iAgg].iMem;
79170 }
79171 break;
79172 }
79173 case TK_CONST_FUNC:
79174 case TK_FUNCTION: {
79175 ExprList *pFarg; /* List of function arguments */
79176 int nFarg; /* Number of function arguments */
79177 FuncDef *pDef; /* The function definition object */
79178 int nId; /* Length of the function name in bytes */
@@ -79181,12 +78696,10 @@
79181 int i; /* Loop counter */
79182 u8 enc = ENC(db); /* The text encoding used by this database */
79183 CollSeq *pColl = 0; /* A collating sequence */
79184
79185 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79186 testcase( op==TK_CONST_FUNC );
79187 testcase( op==TK_FUNCTION );
79188 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79189 pFarg = 0;
79190 }else{
79191 pFarg = pExpr->x.pList;
79192 }
@@ -79226,12 +78739,25 @@
79226 assert( nFarg>=1 );
79227 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
79228 break;
79229 }
79230
 
 
 
 
 
 
 
 
79231 if( pFarg ){
79232 r1 = sqlite3GetTempRange(pParse, nFarg);
 
 
 
 
 
79233
79234 /* For length() and typeof() functions with a column argument,
79235 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
79236 ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
79237 ** loading.
@@ -79242,18 +78768,19 @@
79242 assert( pFarg->a[0].pExpr!=0 );
79243 exprOp = pFarg->a[0].pExpr->op;
79244 if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
79245 assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
79246 assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
79247 testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK)
79248 ==SQLITE_FUNC_LENGTH );
79249 pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK;
79250 }
79251 }
79252
79253 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
79254 sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
 
79255 sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */
79256 }else{
79257 r1 = 0;
79258 }
79259 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -79273,26 +78800,18 @@
79273 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
79274 }else if( nFarg>0 ){
79275 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
79276 }
79277 #endif
79278 for(i=0; i<nFarg; i++){
79279 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
79280 constMask |= (1<<i);
79281 }
79282 if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
79283 pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
79284 }
79285 }
79286 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
79287 if( !pColl ) pColl = db->pDfltColl;
79288 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
79289 }
79290 sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
79291 (char*)pDef, P4_FUNCDEF);
79292 sqlite3VdbeChangeP5(v, (u8)nFarg);
79293 if( nFarg ){
79294 sqlite3ReleaseTempRange(pParse, r1, nFarg);
79295 }
79296 break;
79297 }
79298 #ifndef SQLITE_OMIT_SUBQUERY
@@ -79439,11 +78958,10 @@
79439 int nExpr; /* 2x number of WHEN terms */
79440 int i; /* Loop counter */
79441 ExprList *pEList; /* List of WHEN terms */
79442 struct ExprList_item *aListelem; /* Array of WHEN terms */
79443 Expr opCompare; /* The X==Ei expression */
79444 Expr cacheX; /* Cached expression X */
79445 Expr *pX; /* The X expression */
79446 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
79447 VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
79448
79449 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
@@ -79451,17 +78969,16 @@
79451 pEList = pExpr->x.pList;
79452 aListelem = pEList->a;
79453 nExpr = pEList->nExpr;
79454 endLabel = sqlite3VdbeMakeLabel(v);
79455 if( (pX = pExpr->pLeft)!=0 ){
79456 cacheX = *pX;
79457 testcase( pX->op==TK_COLUMN );
79458 testcase( pX->op==TK_REGISTER );
79459 exprToRegister(&cacheX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
79460 testcase( regFree1==0 );
79461 opCompare.op = TK_EQ;
79462 opCompare.pLeft = &cacheX;
79463 pTest = &opCompare;
79464 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
79465 ** The value in regFree1 might get SCopy-ed into the file result.
79466 ** So make sure that the regFree1 register is not reused for other
79467 ** purposes and possibly overwritten. */
@@ -79477,11 +78994,10 @@
79477 }
79478 nextCase = sqlite3VdbeMakeLabel(v);
79479 testcase( pTest->op==TK_COLUMN );
79480 sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
79481 testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
79482 testcase( aListelem[i+1].pExpr->op==TK_REGISTER );
79483 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
79484 sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
79485 sqlite3ExprCachePop(pParse, 1);
79486 sqlite3VdbeResolveLabel(v, nextCase);
79487 }
@@ -79527,28 +79043,75 @@
79527 }
79528 sqlite3ReleaseTempReg(pParse, regFree1);
79529 sqlite3ReleaseTempReg(pParse, regFree2);
79530 return inReg;
79531 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79532
79533 /*
79534 ** Generate code to evaluate an expression and store the results
79535 ** into a register. Return the register number where the results
79536 ** are stored.
79537 **
79538 ** If the register is a temporary register that can be deallocated,
79539 ** then write its number into *pReg. If the result register is not
79540 ** a temporary, then set *pReg to zero.
 
 
 
 
79541 */
79542 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79543 int r1 = sqlite3GetTempReg(pParse);
79544 int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79545 if( r2==r1 ){
79546 *pReg = r1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79547 }else{
79548 sqlite3ReleaseTempReg(pParse, r1);
79549 *pReg = 0;
 
 
 
 
 
 
79550 }
79551 return r2;
79552 }
79553
79554 /*
@@ -79587,16 +79150,17 @@
79587 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79588 Vdbe *v = pParse->pVdbe;
79589 int inReg;
79590 inReg = sqlite3ExprCode(pParse, pExpr, target);
79591 assert( target>0 );
79592 /* This routine is called for terms to INSERT or UPDATE. And the only
79593 ** other place where expressions can be converted into TK_REGISTER is
79594 ** in WHERE clause processing. So as currently implemented, there is
79595 ** no way for a TK_REGISTER to exist here. But it seems prudent to
79596 ** keep the ALWAYS() in case the conditions above change with future
79597 ** modifications or enhancements. */
 
79598 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79599 int iMem;
79600 iMem = ++pParse->nMem;
79601 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79602 exprToRegister(pExpr, iMem);
@@ -79724,11 +79288,10 @@
79724 sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
79725 break;
79726 }
79727
79728 case TK_AGG_FUNCTION:
79729 case TK_CONST_FUNC:
79730 case TK_FUNCTION: {
79731 ExprList *pFarg; /* List of function arguments */
79732 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79733 pFarg = 0;
79734 }else{
@@ -79874,169 +79437,46 @@
79874 }
79875 sqlite3ExplainPop(pOut);
79876 }
79877 }
79878 #endif /* SQLITE_DEBUG */
79879
79880 /*
79881 ** Return TRUE if pExpr is an constant expression that is appropriate
79882 ** for factoring out of a loop. Appropriate expressions are:
79883 **
79884 ** * Any expression that evaluates to two or more opcodes.
79885 **
79886 ** * Any OP_Integer, OP_Real, OP_String, OP_Blob, OP_Null,
79887 ** or OP_Variable that does not need to be placed in a
79888 ** specific register.
79889 **
79890 ** There is no point in factoring out single-instruction constant
79891 ** expressions that need to be placed in a particular register.
79892 ** We could factor them out, but then we would end up adding an
79893 ** OP_SCopy instruction to move the value into the correct register
79894 ** later. We might as well just use the original instruction and
79895 ** avoid the OP_SCopy.
79896 */
79897 static int isAppropriateForFactoring(Expr *p){
79898 if( !sqlite3ExprIsConstantNotJoin(p) ){
79899 return 0; /* Only constant expressions are appropriate for factoring */
79900 }
79901 if( (p->flags & EP_FixedDest)==0 ){
79902 return 1; /* Any constant without a fixed destination is appropriate */
79903 }
79904 while( p->op==TK_UPLUS ) p = p->pLeft;
79905 switch( p->op ){
79906 #ifndef SQLITE_OMIT_BLOB_LITERAL
79907 case TK_BLOB:
79908 #endif
79909 case TK_VARIABLE:
79910 case TK_INTEGER:
79911 case TK_FLOAT:
79912 case TK_NULL:
79913 case TK_STRING: {
79914 testcase( p->op==TK_BLOB );
79915 testcase( p->op==TK_VARIABLE );
79916 testcase( p->op==TK_INTEGER );
79917 testcase( p->op==TK_FLOAT );
79918 testcase( p->op==TK_NULL );
79919 testcase( p->op==TK_STRING );
79920 /* Single-instruction constants with a fixed destination are
79921 ** better done in-line. If we factor them, they will just end
79922 ** up generating an OP_SCopy to move the value to the destination
79923 ** register. */
79924 return 0;
79925 }
79926 case TK_UMINUS: {
79927 if( p->pLeft->op==TK_FLOAT || p->pLeft->op==TK_INTEGER ){
79928 return 0;
79929 }
79930 break;
79931 }
79932 default: {
79933 break;
79934 }
79935 }
79936 return 1;
79937 }
79938
79939 /*
79940 ** If pExpr is a constant expression that is appropriate for
79941 ** factoring out of a loop, then evaluate the expression
79942 ** into a register and convert the expression into a TK_REGISTER
79943 ** expression.
79944 */
79945 static int evalConstExpr(Walker *pWalker, Expr *pExpr){
79946 Parse *pParse = pWalker->pParse;
79947 switch( pExpr->op ){
79948 case TK_IN:
79949 case TK_REGISTER: {
79950 return WRC_Prune;
79951 }
79952 case TK_COLLATE: {
79953 return WRC_Continue;
79954 }
79955 case TK_FUNCTION:
79956 case TK_AGG_FUNCTION:
79957 case TK_CONST_FUNC: {
79958 /* The arguments to a function have a fixed destination.
79959 ** Mark them this way to avoid generated unneeded OP_SCopy
79960 ** instructions.
79961 */
79962 ExprList *pList = pExpr->x.pList;
79963 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79964 if( pList ){
79965 int i = pList->nExpr;
79966 struct ExprList_item *pItem = pList->a;
79967 for(; i>0; i--, pItem++){
79968 if( ALWAYS(pItem->pExpr) ) pItem->pExpr->flags |= EP_FixedDest;
79969 }
79970 }
79971 break;
79972 }
79973 }
79974 if( isAppropriateForFactoring(pExpr) ){
79975 int r1 = ++pParse->nMem;
79976 int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79977 /* If r2!=r1, it means that register r1 is never used. That is harmless
79978 ** but suboptimal, so we want to know about the situation to fix it.
79979 ** Hence the following assert: */
79980 assert( r2==r1 );
79981 exprToRegister(pExpr, r2);
79982 return WRC_Prune;
79983 }
79984 return WRC_Continue;
79985 }
79986
79987 /*
79988 ** Preevaluate constant subexpressions within pExpr and store the
79989 ** results in registers. Modify pExpr so that the constant subexpresions
79990 ** are TK_REGISTER opcodes that refer to the precomputed values.
79991 **
79992 ** This routine is a no-op if the jump to the cookie-check code has
79993 ** already occur. Since the cookie-check jump is generated prior to
79994 ** any other serious processing, this check ensures that there is no
79995 ** way to accidently bypass the constant initializations.
79996 **
79997 ** This routine is also a no-op if the SQLITE_FactorOutConst optimization
79998 ** is disabled via the sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS)
79999 ** interface. This allows test logic to verify that the same answer is
80000 ** obtained for queries regardless of whether or not constants are
80001 ** precomputed into registers or if they are inserted in-line.
80002 */
80003 SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse *pParse, Expr *pExpr){
80004 Walker w;
80005 if( pParse->cookieGoto ) return;
80006 if( OptimizationDisabled(pParse->db, SQLITE_FactorOutConst) ) return;
80007 memset(&w, 0, sizeof(w));
80008 w.xExprCallback = evalConstExpr;
80009 w.pParse = pParse;
80010 sqlite3WalkExpr(&w, pExpr);
80011 }
80012
80013
80014 /*
80015 ** Generate code that pushes the value of every element of the given
80016 ** expression list into a sequence of registers beginning at target.
80017 **
80018 ** Return the number of elements evaluated.
 
 
 
 
 
 
80019 */
80020 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
80021 Parse *pParse, /* Parsing context */
80022 ExprList *pList, /* The expression list to be coded */
80023 int target, /* Where to write results */
80024 int doHardCopy /* Make a hard copy of every element */
80025 ){
80026 struct ExprList_item *pItem;
80027 int i, n;
 
80028 assert( pList!=0 );
80029 assert( target>0 );
80030 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
80031 n = pList->nExpr;
 
80032 for(pItem=pList->a, i=0; i<n; i++, pItem++){
80033 Expr *pExpr = pItem->pExpr;
80034 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
80035 if( inReg!=target+i ){
80036 sqlite3VdbeAddOp2(pParse->pVdbe, doHardCopy ? OP_Copy : OP_SCopy,
80037 inReg, target+i);
 
 
 
80038 }
80039 }
80040 return n;
80041 }
80042
@@ -80386,44 +79826,46 @@
80386 ** this routine is used, it does not hurt to get an extra 2 - that
80387 ** just might result in some slightly slower code. But returning
80388 ** an incorrect 0 or 1 could lead to a malfunction.
80389 */
80390 SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
80391 if( pA==0||pB==0 ){
 
80392 return pB==pA ? 0 : 2;
80393 }
80394 assert( !ExprHasProperty(pA, EP_TokenOnly|EP_Reduced) );
80395 assert( !ExprHasProperty(pB, EP_TokenOnly|EP_Reduced) );
80396 if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
 
 
80397 return 2;
80398 }
80399 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
80400 if( pA->op!=pB->op && (pA->op!=TK_REGISTER || pA->op2!=pB->op) ){
80401 if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB, iTab)<2 ){
80402 return 1;
80403 }
80404 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
80405 return 1;
80406 }
80407 return 2;
80408 }
80409 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
80410 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
80411 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
80412 if( pA->iColumn!=pB->iColumn ) return 2;
80413 if( pA->iTable!=pB->iTable
80414 && pA->op!=TK_REGISTER
80415 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
80416 if( ExprHasProperty(pA, EP_IntValue) ){
80417 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
80418 return 2;
80419 }
80420 }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){
80421 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
80422 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
80423 return pA->op==TK_COLLATE ? 1 : 2;
80424 }
 
 
 
 
 
 
 
 
 
 
 
 
80425 }
80426 return 0;
80427 }
80428
80429 /*
@@ -83076,14 +82518,16 @@
83076 }
83077 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
83078 if( pTable==0 ){
83079 return 0;
83080 }
83081 if( argv[1] ){
83082 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
83083 }else{
83084 pIndex = 0;
 
 
 
 
83085 }
83086 z = argv[2];
83087
83088 if( pIndex ){
83089 decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
@@ -84394,11 +83838,11 @@
84394 ** transaction on each used database and to verify the schema cookie
84395 ** on each used database.
84396 */
84397 if( pParse->cookieGoto>0 ){
84398 yDbMask mask;
84399 int iDb;
84400 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
84401 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
84402 if( (mask & pParse->cookieMask)==0 ) continue;
84403 sqlite3VdbeUsesBtree(v, iDb);
84404 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
@@ -84408,18 +83852,15 @@
84408 iDb, pParse->cookieValue[iDb],
84409 db->aDb[iDb].pSchema->iGeneration);
84410 }
84411 }
84412 #ifndef SQLITE_OMIT_VIRTUALTABLE
84413 {
84414 int i;
84415 for(i=0; i<pParse->nVtabLock; i++){
84416 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84417 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
84418 }
84419 pParse->nVtabLock = 0;
84420 }
84421 #endif
84422
84423 /* Once all the cookies have been verified and transactions opened,
84424 ** obtain the required table-locks. This is a no-op unless the
84425 ** shared-cache feature is enabled.
@@ -84427,24 +83868,30 @@
84427 codeTableLocks(pParse);
84428
84429 /* Initialize any AUTOINCREMENT data structures required.
84430 */
84431 sqlite3AutoincrementBegin(pParse);
 
 
 
 
 
 
 
 
 
 
84432
84433 /* Finally, jump back to the beginning of the executable code. */
84434 sqlite3VdbeAddOp2(v, OP_Goto, 0, pParse->cookieGoto);
84435 }
84436 }
84437
84438
84439 /* Get the VDBE program ready for execution
84440 */
84441 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
84442 #ifdef SQLITE_DEBUG
84443 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
84444 sqlite3VdbeTrace(v, trace);
84445 #endif
84446 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
84447 /* A minimum of one cursor is required if autoincrement is used
84448 * See ticket [a696379c1f08866] */
84449 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
84450 sqlite3VdbeMakeReady(v, pParse);
@@ -87031,11 +86478,11 @@
87031 Token *pName = 0; /* Unqualified name of the index to create */
87032 struct ExprList_item *pListItem; /* For looping over pList */
87033 const Column *pTabCol; /* A column in the table */
87034 int nExtra = 0; /* Space allocated for zExtra[] */
87035 int nExtraCol; /* Number of extra columns needed */
87036 char *zExtra; /* Extra space after the Index object */
87037 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
87038
87039 assert( pParse->nErr==0 ); /* Never called with prior errors */
87040 if( db->mallocFailed || IN_DECLARE_VTAB ){
87041 goto exit_create_index;
@@ -88230,13 +87677,13 @@
88230 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
88231 errMsg.db = pParse->db;
88232 for(j=0; j<pIdx->nKeyCol; j++){
88233 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
88234 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
88235 sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
88236 sqlite3StrAccumAppend(&errMsg, ".", 1);
88237 sqlite3StrAccumAppend(&errMsg, zCol, -1);
88238 }
88239 zErr = sqlite3StrAccumFinish(&errMsg);
88240 sqlite3HaltConstraint(pParse,
88241 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
88242 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88424,12 +87871,13 @@
88424 }
88425 if( pKey ){
88426 assert( sqlite3KeyInfoIsWriteable(pKey) );
88427 for(i=0; i<nCol; i++){
88428 char *zColl = pIdx->azColl[i];
88429 if( NEVER(zColl==0) ) zColl = "BINARY";
88430 pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
 
88431 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
88432 }
88433 if( pParse->nErr ){
88434 sqlite3KeyInfoUnref(pKey);
88435 }else{
@@ -89148,24 +88596,38 @@
89148 Expr *pWhere /* The WHERE clause. May be null */
89149 ){
89150 Vdbe *v; /* The virtual database engine */
89151 Table *pTab; /* The table from which records will be deleted */
89152 const char *zDb; /* Name of database holding pTab */
89153 int end, addr = 0; /* A couple addresses of generated code */
89154 int i; /* Loop counter */
89155 WhereInfo *pWInfo; /* Information about the WHERE clause */
89156 Index *pIdx; /* For looping over indices of the table */
89157 int iTabCur; /* Cursor number for the table */
89158 int iDataCur; /* VDBE cursor for the canonical data source */
89159 int iIdxCur; /* Cursor number of the first index */
 
89160 sqlite3 *db; /* Main database structure */
89161 AuthContext sContext; /* Authorization context */
89162 NameContext sNC; /* Name context to resolve expressions in */
89163 int iDb; /* Database number */
89164 int memCnt = -1; /* Memory cell used for change counting */
89165 int rcauth; /* Value returned by authorization callback */
89166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89167 #ifndef SQLITE_OMIT_TRIGGER
89168 int isView; /* True if attempting to delete from a view */
89169 Trigger *pTrigger; /* List of table triggers, if required */
89170 #endif
89171
@@ -89216,15 +88678,15 @@
89216 if( rcauth==SQLITE_DENY ){
89217 goto delete_from_cleanup;
89218 }
89219 assert(!isView || pTrigger);
89220
89221 /* Assign cursor number to the table and all its indices.
89222 */
89223 assert( pTabList->nSrc==1 );
89224 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
89225 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
89226 pParse->nTab++;
89227 }
89228
89229 /* Start the view context
89230 */
@@ -89286,132 +88748,162 @@
89286 assert( pIdx->pSchema==pTab->pSchema );
89287 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
89288 }
89289 }else
89290 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
89291 if( !HasRowid(pTab) ){
89292 /* There is a WHERE clause on a WITHOUT ROWID table.
89293 */
89294 Index *pPk; /* The PRIMARY KEY index on the table */
89295 int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
89296 int iEph; /* Ephemeral table holding all primary key values */
89297 int iKey; /* Key value inserting into iEph */
89298 i16 nPk; /* Number of components of the PRIMARY KEY */
89299
89300 pPk = sqlite3PrimaryKeyIndex(pTab);
89301 assert( pPk!=0 );
89302 nPk = pPk->nKeyCol;
89303 iPk = pParse->nMem+1;
89304 pParse->nMem += nPk;
89305 iKey = ++pParse->nMem;
89306 iEph = pParse->nTab++;
89307
89308 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
89309 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89310 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 0, 0);
89311 if( pWInfo==0 ) goto delete_from_cleanup;
89312 for(i=0; i<nPk; i++){
89313 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, pPk->aiColumn[i],iPk+i);
89314 }
89315 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89316 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89317 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, iKey);
89318 if( db->flags & SQLITE_CountRows ){
89319 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89320 }
89321 sqlite3WhereEnd(pWInfo);
89322
89323 /* Open cursors for all indices of the table.
89324 */
89325 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite,
89326 iTabCur, &iDataCur, &iIdxCur);
89327
89328 /* Loop over the primary keys to be deleted. */
89329 addr = sqlite3VdbeAddOp1(v, OP_Rewind, iEph);
89330 sqlite3VdbeAddOp2(v, OP_RowKey, iEph, iPk);
89331
89332 /* Delete the row */
89333 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89334 iPk, 0, 1, OE_Default, 0);
89335
89336 /* End of the delete loop */
89337 sqlite3VdbeAddOp2(v, OP_Next, iEph, addr+1);
89338 sqlite3VdbeJumpHere(v, addr);
89339
89340 /* Close the cursors open on the table and its indexes. */
89341 assert( iDataCur>=iIdxCur );
89342 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89343 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur+i);
89344 }
89345 }else{
89346 /* There is a WHERE clause on a rowid table. Run a loop that extracts
89347 ** all rowids to be deleted into a RowSet.
89348 */
89349 int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
89350 int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
89351 int regRowid; /* Actual register containing rowids */
89352
89353 /* Collect rowids of every row to be deleted.
89354 */
89355 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
89356 pWInfo = sqlite3WhereBegin(
89357 pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
89358 );
89359 if( pWInfo==0 ) goto delete_from_cleanup;
89360 regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iRowid, 0);
89361 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
89362 if( db->flags & SQLITE_CountRows ){
89363 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89364 }
89365 sqlite3WhereEnd(pWInfo);
89366
89367 /* Delete every item whose key was written to the list during the
89368 ** database scan. We have to delete items after the scan is complete
89369 ** because deleting an item can change the scan order. */
89370 end = sqlite3VdbeMakeLabel(v);
89371
89372 /* Unless this is a view, open cursors for the table we are
89373 ** deleting from and all its indices. If this is a view, then the
89374 ** only effect this statement has is to fire the INSTEAD OF
89375 ** triggers. */
89376 if( !isView ){
89377 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur,
89378 &iDataCur, &iIdxCur);
89379 assert( iDataCur==iTabCur );
89380 assert( iIdxCur==iDataCur+1 );
89381 }
89382
89383 addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);
89384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89385 /* Delete the row */
89386 #ifndef SQLITE_OMIT_VIRTUALTABLE
89387 if( IsVirtual(pTab) ){
89388 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
89389 sqlite3VtabMakeWritable(pParse, pTab);
89390 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
89391 sqlite3VdbeChangeP5(v, OE_Abort);
89392 sqlite3MayAbort(pParse);
89393 }else
89394 #endif
89395 {
89396 int count = (pParse->nested==0); /* True to count changes */
89397 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89398 iRowid, 1, count, OE_Default, 0);
89399 }
89400
89401 /* End of the delete loop */
89402 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
89403 sqlite3VdbeResolveLabel(v, end);
89404
 
 
 
 
 
 
 
89405 /* Close the cursors open on the table and its indexes. */
89406 if( !isView && !IsVirtual(pTab) ){
89407 sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
89408 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89409 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
89410 }
89411 }
89412 }
89413
89414 /* Update the sqlite_sequence table by storing the content of the
89415 ** maximum rowid counter values recorded while inserting into
89416 ** autoincrement tables.
89417 */
@@ -89431,10 +88923,11 @@
89431
89432 delete_from_cleanup:
89433 sqlite3AuthContextPop(&sContext);
89434 sqlite3SrcListDelete(db, pTabList);
89435 sqlite3ExprDelete(db, pWhere);
 
89436 return;
89437 }
89438 /* Make sure "isView" and other macros defined above are undefined. Otherwise
89439 ** thely may interfere with compilation of other functions in this file
89440 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -89497,10 +88990,11 @@
89497 /* If there are any triggers to fire, allocate a range of registers to
89498 ** use for the old.* references in the triggers. */
89499 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89500 u32 mask; /* Mask of OLD.* columns in use */
89501 int iCol; /* Iterator used while populating OLD.* */
 
89502
89503 /* TODO: Could use temporary registers here. Also could attempt to
89504 ** avoid copying the contents of the rowid register. */
89505 mask = sqlite3TriggerColmask(
89506 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
@@ -89517,19 +89011,23 @@
89517 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
89518 }
89519 }
89520
89521 /* Invoke BEFORE DELETE trigger programs. */
 
89522 sqlite3CodeRowTrigger(pParse, pTrigger,
89523 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
89524 );
89525
89526 /* Seek the cursor to the row to be deleted again. It may be that
89527 ** the BEFORE triggers coded above have already removed the row
89528 ** being deleted. Do not attempt to delete the row a second time, and
89529 ** do not fire AFTER triggers. */
89530 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
 
 
 
89531
89532 /* Do FK processing. This call checks that any FK constraints that
89533 ** refer to this table (i.e. constraints attached to other tables)
89534 ** are not violated by deleting this row. */
89535 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -91193,15 +90691,15 @@
91193 nSep = sqlite3_value_bytes(argv[1]);
91194 }else{
91195 zSep = ",";
91196 nSep = 1;
91197 }
91198 sqlite3StrAccumAppend(pAccum, zSep, nSep);
91199 }
91200 zVal = (char*)sqlite3_value_text(argv[0]);
91201 nVal = sqlite3_value_bytes(argv[0]);
91202 sqlite3StrAccumAppend(pAccum, zVal, nVal);
91203 }
91204 }
91205 static void groupConcatFinalize(sqlite3_context *context){
91206 StrAccum *pAccum;
91207 pAccum = sqlite3_aggregate_context(context, 0);
@@ -91346,24 +90844,24 @@
91346 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
91347 FUNCTION(hex, 1, 0, 0, hexFunc ),
91348 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
91349 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
91350 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
91351 FUNCTION(random, 0, 0, 0, randomFunc ),
91352 FUNCTION(randomblob, 1, 0, 0, randomBlob ),
91353 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
91354 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
91355 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
91356 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
91357 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
91358 FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
91359 FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
91360 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
91361 FUNCTION(quote, 1, 0, 0, quoteFunc ),
91362 FUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
91363 FUNCTION(changes, 0, 0, 0, changes ),
91364 FUNCTION(total_changes, 0, 0, 0, total_changes ),
91365 FUNCTION(replace, 3, 0, 0, replaceFunc ),
91366 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
91367 #ifdef SQLITE_SOUNDEX
91368 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
91369 #endif
@@ -91955,10 +91453,11 @@
91955 Vdbe *v = sqlite3GetVdbe(pParse);
91956
91957 assert( pIdx==0 || pIdx->pTable==pTab );
91958 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
91959 assert( pIdx!=0 || pFKey->nCol==1 );
 
91960
91961 if( nIncr<0 ){
91962 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
91963 }
91964
@@ -92007,10 +91506,11 @@
92007 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
92008 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
92009 }else{
92010 Expr *pEq, *pAll = 0;
92011 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
 
92012 for(i=0; i<pPk->nKeyCol; i++){
92013 i16 iCol = pIdx->aiColumn[i];
92014 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
92015 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
92016 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
@@ -93585,11 +93085,11 @@
93585 }
93586
93587 /* If this is not a view, open the table and and all indices */
93588 if( !isView ){
93589 int nIdx;
93590 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1,
93591 &iDataCur, &iIdxCur);
93592 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
93593 if( aRegIdx==0 ){
93594 goto insert_cleanup;
93595 }
@@ -94445,42 +93945,50 @@
94445 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
94446 Parse *pParse, /* Parsing context */
94447 Table *pTab, /* Table to be opened */
94448 int op, /* OP_OpenRead or OP_OpenWrite */
94449 int iBase, /* Use this for the table cursor, if there is one */
 
94450 int *piDataCur, /* Write the database source cursor number here */
94451 int *piIdxCur /* Write the first index cursor number here */
94452 ){
94453 int i;
94454 int iDb;
 
94455 Index *pIdx;
94456 Vdbe *v;
94457
94458 assert( op==OP_OpenRead || op==OP_OpenWrite );
94459 if( IsVirtual(pTab) ){
 
94460 *piDataCur = 0;
94461 *piIdxCur = 1;
94462 return 0;
94463 }
94464 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94465 v = sqlite3GetVdbe(pParse);
94466 assert( v!=0 );
94467 if( iBase<0 ) iBase = pParse->nTab;
94468 if( HasRowid(pTab) ){
94469 *piDataCur = iBase++;
94470 sqlite3OpenTable(pParse, *piDataCur, iDb, pTab, op);
 
94471 }else{
94472 sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
94473 }
94474 *piIdxCur = iBase;
94475 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94476 int iIdxCur = iBase++;
94477 assert( pIdx->pSchema==pTab->pSchema );
94478 if( pIdx->autoIndex==2 && !HasRowid(pTab) ) *piDataCur = iIdxCur;
94479 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94480 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
94481 VdbeComment((v, "%s", pIdx->zName));
 
 
 
 
94482 }
94483 if( iBase>pParse->nTab ) pParse->nTab = iBase;
94484 return i;
94485 }
94486
@@ -96650,10 +96158,14 @@
96650 /* iArg: */ SQLITE_VdbeAddopTrace },
96651 { /* zName: */ "vdbe_debug",
96652 /* ePragTyp: */ PragTyp_FLAG,
96653 /* ePragFlag: */ 0,
96654 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
 
 
 
 
96655 { /* zName: */ "vdbe_listing",
96656 /* ePragTyp: */ PragTyp_FLAG,
96657 /* ePragFlag: */ 0,
96658 /* iArg: */ SQLITE_VdbeListing },
96659 { /* zName: */ "vdbe_trace",
@@ -96677,11 +96189,11 @@
96677 /* ePragTyp: */ PragTyp_FLAG,
96678 /* ePragFlag: */ 0,
96679 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
96680 #endif
96681 };
96682 /* Number of pragmas: 56 on by default, 68 total. */
96683 /* End of the automatically generated pragma table.
96684 ***************************************************************************/
96685
96686 /*
96687 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -98103,11 +97615,11 @@
98103 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98104 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98105 sqlite3VdbeJumpHere(v, addr);
98106 sqlite3ExprCacheClear(pParse);
98107 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98108 1, &iDataCur, &iIdxCur);
98109 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98110 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98111 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98112 }
98113 pParse->nMem = MAX(pParse->nMem, 8+j);
@@ -99038,10 +98550,17 @@
99038 }
99039 assert( i>=0 && i<db->nDb );
99040 }
99041 return i;
99042 }
 
 
 
 
 
 
 
99043
99044 /*
99045 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
99046 */
99047 static int sqlite3Prepare(
@@ -99196,10 +98715,11 @@
99196 sqlite3DbFree(db, pT);
99197 }
99198
99199 end_prepare:
99200
 
99201 sqlite3StackFree(db, pParse);
99202 rc = sqlite3ApiExit(db, rc);
99203 assert( (rc&db->errMask)==rc );
99204 return rc;
99205 }
@@ -99989,11 +99509,12 @@
99989 }else if( eDest!=SRT_Exists ){
99990 /* If the destination is an EXISTS(...) expression, the actual
99991 ** values returned by the SELECT are not required.
99992 */
99993 sqlite3ExprCacheClear(pParse);
99994 sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output);
 
99995 }
99996 nColumn = nResultCol;
99997
99998 /* If the DISTINCT keyword was present on the SELECT statement
99999 ** and this row has been seen before, then do not make this row
@@ -101762,20 +101283,20 @@
101762 */
101763 if( op!=TK_ALL ){
101764 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
101765 struct ExprList_item *pItem;
101766 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
101767 assert( pItem->iOrderByCol>0 );
101768 if( pItem->iOrderByCol==i ) break;
101769 }
101770 if( j==nOrderBy ){
101771 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
101772 if( pNew==0 ) return SQLITE_NOMEM;
101773 pNew->flags |= EP_IntValue;
101774 pNew->u.iValue = i;
101775 pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
101776 if( pOrderBy ) pOrderBy->a[nOrderBy++].iOrderByCol = (u16)i;
101777 }
101778 }
101779 }
101780
101781 /* Compute the comparison permutation and keyinfo that is used with
@@ -101787,12 +101308,13 @@
101787 */
101788 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
101789 if( aPermute ){
101790 struct ExprList_item *pItem;
101791 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
101792 assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
101793 aPermute[i] = pItem->iOrderByCol - 1;
 
101794 }
101795 pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
101796 if( pKeyMerge ){
101797 for(i=0; i<nOrderBy; i++){
101798 CollSeq *pColl;
@@ -102368,11 +101890,11 @@
102368
102369 /* Restriction 18. */
102370 if( p->pOrderBy ){
102371 int ii;
102372 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
102373 if( p->pOrderBy->a[ii].iOrderByCol==0 ) return 0;
102374 }
102375 }
102376 }
102377
102378 /***** If we reach this point, flattening is permitted. *****/
@@ -103274,11 +102796,11 @@
103274 ExprList *pList = pF->pExpr->x.pList;
103275 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
103276 if( pList ){
103277 nArg = pList->nExpr;
103278 regAgg = sqlite3GetTempRange(pParse, nArg);
103279 sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
103280 }else{
103281 nArg = 0;
103282 regAgg = 0;
103283 }
103284 if( pF->iDistinct>=0 ){
@@ -103775,14 +103297,14 @@
103775 if( pGroupBy ){
103776 int k; /* Loop counter */
103777 struct ExprList_item *pItem; /* For looping over expression in a list */
103778
103779 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
103780 pItem->iAlias = 0;
103781 }
103782 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
103783 pItem->iAlias = 0;
103784 }
103785 if( p->nSelectRow>100 ) p->nSelectRow = 100;
103786 }else{
103787 p->nSelectRow = 1;
103788 }
@@ -104060,15 +103582,16 @@
104060
104061 /* Search for the index that has the lowest scan cost.
104062 **
104063 ** (2011-04-15) Do not do a full scan of an unordered index.
104064 **
104065 ** (2013-10-03) Do not count the entires in a partial index.
104066 **
104067 ** In practice the KeyInfo structure will not be used. It is only
104068 ** passed to keep OP_OpenRead happy.
104069 */
 
104070 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
104071 if( pIdx->bUnordered==0
104072 && pIdx->szIdxRow<pTab->szTabRow
104073 && pIdx->pPartIdxWhere==0
104074 && (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
@@ -105428,10 +104951,11 @@
105428 sqlite3VdbeDelete(v);
105429 }
105430
105431 assert( !pSubParse->pAinc && !pSubParse->pZombieTab );
105432 assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
 
105433 sqlite3StackFree(db, pSubParse);
105434
105435 return pPrg;
105436 }
105437
@@ -105742,22 +105266,23 @@
105742 WhereInfo *pWInfo; /* Information about the WHERE clause */
105743 Vdbe *v; /* The virtual database engine */
105744 Index *pIdx; /* For looping over indices */
105745 Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
105746 int nIdx; /* Number of indices that need updating */
 
105747 int iDataCur; /* Cursor for the canonical data btree */
105748 int iIdxCur; /* Cursor for the first index */
105749 sqlite3 *db; /* The database structure */
105750 int *aRegIdx = 0; /* One register assigned to each index to be updated */
105751 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
105752 ** an expression for the i-th column of the table.
105753 ** aXRef[i]==-1 if the i-th column is not changed. */
 
105754 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105755 u8 chngRowid; /* Rowid changed in a normal table */
105756 u8 chngKey; /* Either chngPk or chngRowid */
105757 Expr *pRowidExpr = 0; /* Expression defining the new record number */
105758 int openAll = 0; /* True if all indices need to be opened */
105759 AuthContext sContext; /* The authorization context */
105760 NameContext sNC; /* The name-context to resolve expressions in */
105761 int iDb; /* Database containing the table being updated */
105762 int okOnePass; /* True for one-pass algorithm without the FIFO */
105763 int hasFK; /* True if foreign key processing is required */
@@ -105817,29 +105342,37 @@
105817 goto update_cleanup;
105818 }
105819 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
105820 goto update_cleanup;
105821 }
105822 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
105823 if( aXRef==0 ) goto update_cleanup;
105824 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105825
105826 /* Allocate a cursors for the main database table and for all indices.
105827 ** The index cursors might not be used, but if they are used they
105828 ** need to occur right after the database cursor. So go ahead and
105829 ** allocate enough space, just in case.
105830 */
105831 pTabList->a[0].iCursor = iDataCur = pParse->nTab++;
105832 iIdxCur = iDataCur+1;
105833 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105834 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105835 if( pIdx->autoIndex==2 && pPk!=0 ){
105836 iDataCur = pParse->nTab;
105837 pTabList->a[0].iCursor = iDataCur;
105838 }
105839 pParse->nTab++;
105840 }
 
 
 
 
 
 
 
 
 
 
 
105841
105842 /* Initialize the name-context */
105843 memset(&sNC, 0, sizeof(sNC));
105844 sNC.pParse = pParse;
105845 sNC.pSrcList = pTabList;
@@ -105894,22 +105427,22 @@
105894 }
105895 assert( (chngRowid & chngPk)==0 );
105896 assert( chngRowid==0 || chngRowid==1 );
105897 assert( chngPk==0 || chngPk==1 );
105898 chngKey = chngRowid + chngPk;
 
 
 
 
 
105899
105900 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
105901
105902 /* Allocate memory for the array aRegIdx[]. There is one entry in the
105903 ** array for each index associated with table being updated. Fill in
105904 ** the value with a register number for indices that are to be used
105905 ** and with zero for unused indices.
105906 */
105907 if( nIdx>0 ){
105908 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
105909 if( aRegIdx==0 ) goto update_cleanup;
105910 }
105911 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
105912 int reg;
105913 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
105914 reg = ++pParse->nMem;
105915 }else{
@@ -105919,10 +105452,11 @@
105919 reg = ++pParse->nMem;
105920 break;
105921 }
105922 }
105923 }
 
105924 aRegIdx[j] = reg;
105925 }
105926
105927 /* Begin generating code. */
105928 v = sqlite3GetVdbe(pParse);
@@ -106042,46 +105576,34 @@
106042 ** Open every index that needs updating. Note that if any
106043 ** index could potentially invoke a REPLACE conflict resolution
106044 ** action, then we need to open all indices because we might need
106045 ** to be deleting some records.
106046 */
106047 if( !okOnePass && HasRowid(pTab) ){
106048 sqlite3OpenTable(pParse, iDataCur, iDb, pTab, OP_OpenWrite);
106049 }
106050 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
106051 if( onError==OE_Replace ){
106052 openAll = 1;
106053 }else{
106054 openAll = 0;
106055 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
106056 if( pIdx->onError==OE_Replace ){
106057 openAll = 1;
106058 break;
106059 }
106060 }
106061 }
106062 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106063 int iThisCur = iIdxCur+i;
106064 assert( aRegIdx );
106065 if( (openAll || aRegIdx[i]>0)
106066 && iThisCur!=aiCurOnePass[1]
106067 ){
106068 assert( iThisCur!=aiCurOnePass[0] );
106069 sqlite3VdbeAddOp3(v, OP_OpenWrite, iThisCur, pIdx->tnum, iDb);
106070 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
106071 assert( pParse->nTab>iThisCur );
106072 VdbeComment((v, "%s", pIdx->zName));
106073 if( okOnePass && pPk && iThisCur==iDataCur ){
106074 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak,
106075 regKey, nKey);
106076 }
106077 }
106078 }
106079 }
106080
106081 /* Top of the update loop */
106082 if( okOnePass ){
 
 
 
 
106083 labelContinue = labelBreak;
106084 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106085 }else if( pPk ){
106086 labelContinue = sqlite3VdbeMakeLabel(v);
106087 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
@@ -106222,15 +105744,11 @@
106222 /* If changing the record number, delete the old record. */
106223 if( hasFK || chngKey || pPk!=0 ){
106224 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
106225 }
106226 if( bReplace || chngKey ){
106227 if( sqlite3VdbeCurrentAddr(v)==j1+1 ){
106228 sqlite3VdbeChangeToNoop(v, j1);
106229 }else{
106230 sqlite3VdbeJumpHere(v, j1);
106231 }
106232 }
106233
106234 if( hasFK ){
106235 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
106236 }
@@ -106270,11 +105788,11 @@
106270 sqlite3VdbeResolveLabel(v, labelBreak);
106271
106272 /* Close all tables */
106273 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106274 assert( aRegIdx );
106275 if( openAll || aRegIdx[i]>0 ){
106276 sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
106277 }
106278 }
106279 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
106280
@@ -106297,12 +105815,11 @@
106297 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
106298 }
106299
106300 update_cleanup:
106301 sqlite3AuthContextPop(&sContext);
106302 sqlite3DbFree(db, aRegIdx);
106303 sqlite3DbFree(db, aXRef);
106304 sqlite3SrcListDelete(db, pTabList);
106305 sqlite3ExprListDelete(db, pChanges);
106306 sqlite3ExprDelete(db, pWhere);
106307 return;
106308 }
@@ -107521,10 +107038,11 @@
107521
107522 if( pParse->pVdbe ){
107523 sqlite3VdbeFinalize(pParse->pVdbe);
107524 }
107525 sqlite3DeleteTable(db, pParse->pNewTable);
 
107526 sqlite3StackFree(db, pParse);
107527 }
107528
107529 assert( (rc&0xff)==rc );
107530 rc = sqlite3ApiExit(db, rc);
@@ -107898,11 +107416,28 @@
107898 ** generating the code that loops through a table looking for applicable
107899 ** rows. Indices are selected and used to speed the search when doing
107900 ** so is applicable. Because this module is responsible for selecting
107901 ** indices, you might also think of this module as the "query optimizer".
107902 */
107903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107904
107905 /*
107906 ** Trace output macros
107907 */
107908 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
@@ -107950,10 +107485,11 @@
107950 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
107951 int iTabCur; /* The VDBE cursor used to access the table */
107952 int iIdxCur; /* The VDBE cursor used to access pIdx */
107953 int addrBrk; /* Jump here to break out of the loop */
107954 int addrNxt; /* Jump here to start the next IN combination */
 
107955 int addrCont; /* Jump here to continue with the next loop cycle */
107956 int addrFirst; /* First instruction of interior of the loop */
107957 int addrBody; /* Beginning of the body of this loop */
107958 u8 iFrom; /* Which entry in the FROM clause */
107959 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
@@ -107998,11 +107534,12 @@
107998 LogEst rSetup; /* One-time setup cost (ex: create transient index) */
107999 LogEst rRun; /* Cost of running each loop */
108000 LogEst nOut; /* Estimated number of output rows */
108001 union {
108002 struct { /* Information for internal btree tables */
108003 int nEq; /* Number of equality constraints */
 
108004 Index *pIndex; /* Index used, or NULL */
108005 } btree;
108006 struct { /* Information for virtual tables */
108007 int idxNum; /* Index number */
108008 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -108339,10 +107876,14 @@
108339 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
108340 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108341 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108342 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108343 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
 
 
 
 
108344
108345 /*
108346 ** Return the estimated number of output rows from a WHERE clause
108347 */
108348 SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
@@ -108990,13 +108531,10 @@
108990 }
108991 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
108992
108993 pRight = pList->a[0].pExpr;
108994 op = pRight->op;
108995 if( op==TK_REGISTER ){
108996 op = pRight->op2;
108997 }
108998 if( op==TK_VARIABLE ){
108999 Vdbe *pReprepare = pParse->pReprepare;
109000 int iCol = pRight->iColumn;
109001 pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_NONE);
109002 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
@@ -109859,10 +109397,11 @@
109859 }
109860 sqlite3DebugPrintf(" idxNum=%d\n", p->idxNum);
109861 sqlite3DebugPrintf(" idxStr=%s\n", p->idxStr);
109862 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
109863 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
 
109864 }
109865 #else
109866 #define TRACE_IDX_INPUTS(A)
109867 #define TRACE_IDX_OUTPUTS(A)
109868 #endif
@@ -110228,12 +109767,11 @@
110228 int res; /* Result of comparison operation */
110229
110230 #ifndef SQLITE_DEBUG
110231 UNUSED_PARAMETER( pParse );
110232 #endif
110233 assert( pRec!=0 || pParse->db->mallocFailed );
110234 if( pRec==0 ) return;
110235 iCol = pRec->nField - 1;
110236 assert( pIdx->nSample>0 );
110237 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110238 do{
110239 iTest = (iMin+i)/2;
@@ -110729,11 +110267,11 @@
110729 if( eType==IN_INDEX_ROWID ){
110730 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
110731 }else{
110732 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
110733 }
110734 pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
110735 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
110736 }else{
110737 pLevel->u.in.nIn = 0;
110738 }
110739 #endif
@@ -110742,11 +110280,11 @@
110742 return iReg;
110743 }
110744
110745 /*
110746 ** Generate code that will evaluate all == and IN constraints for an
110747 ** index.
110748 **
110749 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
110750 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
110751 ** The index has as many as three equality constraints, but in this
110752 ** example, the third "c" value is an inequality. So only two
@@ -110757,13 +110295,19 @@
110757 ** In the example above nEq==2. But this subroutine works for any value
110758 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
110759 ** The only thing it does is allocate the pLevel->iMem memory cell and
110760 ** compute the affinity string.
110761 **
110762 ** This routine always allocates at least one memory cell and returns
110763 ** the index of that memory cell. The code that
110764 ** calls this routine will use that memory cell to store the termination
 
 
 
 
 
 
110765 ** key value of the loop. If one or more IN operators appear, then
110766 ** this routine allocates an additional nEq memory cells for internal
110767 ** use.
110768 **
110769 ** Before returning, *pzAff is set to point to a buffer containing a
@@ -110786,11 +110330,12 @@
110786 WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
110787 int bRev, /* Reverse the order of IN operators */
110788 int nExtraReg, /* Number of extra registers to allocate */
110789 char **pzAff /* OUT: Set to point to affinity string */
110790 ){
110791 int nEq; /* The number of == or IN constraints to code */
 
110792 Vdbe *v = pParse->pVdbe; /* The vm under construction */
110793 Index *pIdx; /* The index being used for this loop */
110794 WhereTerm *pTerm; /* A single constraint term */
110795 WhereLoop *pLoop; /* The WhereLoop object */
110796 int j; /* Loop counter */
@@ -110800,10 +110345,11 @@
110800
110801 /* This module is only called on query plans that use an index. */
110802 pLoop = pLevel->pWLoop;
110803 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
110804 nEq = pLoop->u.btree.nEq;
 
110805 pIdx = pLoop->u.btree.pIndex;
110806 assert( pIdx!=0 );
110807
110808 /* Figure out how many memory cells we will need then allocate them.
110809 */
@@ -110813,19 +110359,34 @@
110813
110814 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
110815 if( !zAff ){
110816 pParse->db->mallocFailed = 1;
110817 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110818
110819 /* Evaluate the equality constraints
110820 */
110821 assert( zAff==0 || (int)strlen(zAff)>=nEq );
110822 for(j=0; j<nEq; j++){
110823 int r1;
110824 pTerm = pLoop->aLTerm[j];
110825 assert( pTerm!=0 );
110826 /* The following true for indices with redundant columns.
110827 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
110828 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
110829 testcase( pTerm->wtFlags & TERM_VIRTUAL );
110830 r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
110831 if( r1!=regBase+j ){
@@ -110869,11 +110430,11 @@
110869 int iTerm, /* Index of this term. First is zero */
110870 const char *zColumn, /* Name of the column */
110871 const char *zOp /* Name of the operator */
110872 ){
110873 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110874 sqlite3StrAccumAppend(pStr, zColumn, -1);
110875 sqlite3StrAccumAppend(pStr, zOp, 1);
110876 sqlite3StrAccumAppend(pStr, "?", 1);
110877 }
110878
110879 /*
@@ -110895,11 +110456,12 @@
110895 ** It is the responsibility of the caller to free the buffer when it is
110896 ** no longer required.
110897 */
110898 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
110899 Index *pIndex = pLoop->u.btree.pIndex;
110900 int nEq = pLoop->u.btree.nEq;
 
110901 int i, j;
110902 Column *aCol = pTab->aCol;
110903 i16 *aiColumn = pIndex->aiColumn;
110904 StrAccum txt;
110905
@@ -110909,11 +110471,18 @@
110909 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
110910 txt.db = db;
110911 sqlite3StrAccumAppend(&txt, " (", 2);
110912 for(i=0; i<nEq; i++){
110913 char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
110914 explainAppendTerm(&txt, i, z, "=");
 
 
 
 
 
 
 
110915 }
110916
110917 j = i;
110918 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
110919 char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -110939,11 +110508,14 @@
110939 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
110940 int iLevel, /* Value for "level" column of output */
110941 int iFrom, /* Value for "from" column of output */
110942 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
110943 ){
110944 if( pParse->explain==2 ){
 
 
 
110945 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
110946 Vdbe *v = pParse->pVdbe; /* VM being constructed */
110947 sqlite3 *db = pParse->db; /* Database handle */
110948 char *zMsg; /* Text to add to EQP output */
110949 int iId = pParse->iSelectId; /* Select id (left-most output column) */
@@ -111045,11 +110617,11 @@
111045 iCur = pTabItem->iCursor;
111046 pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
111047 bRev = (pWInfo->revMask>>iLevel)&1;
111048 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
111049 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
111050 VdbeNoopComment((v, "Begin WHERE-Loop %d: %s", iLevel,pTabItem->pTab->zName));
111051
111052 /* Create labels for the "break" and "continue" instructions
111053 ** for the current loop. Jump to addrBrk to break out of a loop.
111054 ** Jump to cont to go immediately to the next iteration of the
111055 ** loop.
@@ -111272,12 +110844,12 @@
111272 static const u8 aEndOp[] = {
111273 OP_Noop, /* 0: (!end_constraints) */
111274 OP_IdxGE, /* 1: (end_constraints && !bRev) */
111275 OP_IdxLT /* 2: (end_constraints && bRev) */
111276 };
111277 int nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111278 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111279 int regBase; /* Base register holding constraint values */
111280 int r1; /* Temp register */
111281 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111282 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111283 int startEq; /* True if range start uses ==, >= or <= */
@@ -111287,14 +110859,15 @@
111287 Index *pIdx; /* The index we will be using */
111288 int iIdxCur; /* The VDBE cursor for the index */
111289 int nExtraReg = 0; /* Number of extra registers needed */
111290 int op; /* Instruction opcode */
111291 char *zStartAff; /* Affinity for start of range constraint */
111292 char *zEndAff; /* Affinity for end of range constraint */
111293
111294 pIdx = pLoop->u.btree.pIndex;
111295 iIdxCur = pLevel->iIdxCur;
 
111296
111297 /* If this loop satisfies a sort order (pOrderBy) request that
111298 ** was passed to this function to implement a "SELECT min(x) ..."
111299 ** query, then the caller will only allow the loop to run for
111300 ** a single iteration. This means that the first row returned
@@ -111304,12 +110877,11 @@
111304 */
111305 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111306 && (pWInfo->bOBSat!=0)
111307 && (pIdx->nKeyCol>nEq)
111308 ){
111309 /* assert( pOrderBy->nExpr==1 ); */
111310 /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
111311 isMinQuery = 1;
111312 nExtraReg = 1;
111313 }
111314
111315 /* Find any inequality constraint terms for the start and end
@@ -111328,11 +110900,12 @@
111328 /* Generate code to evaluate all constraint terms using == or IN
111329 ** and store the values of those terms in an array of registers
111330 ** starting at regBase.
111331 */
111332 regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
111333 zEndAff = sqlite3DbStrDup(db, zStartAff);
 
111334 addrNxt = pLevel->addrNxt;
111335
111336 /* If we are doing a reverse order scan on an ascending index, or
111337 ** a forward order scan on a descending index, interchange the
111338 ** start and end terms (pRangeStart and pRangeEnd).
@@ -111398,27 +110971,19 @@
111398 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111399 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111400 if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111401 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
111402 }
111403 if( zEndAff ){
111404 if( sqlite3CompareAffinity(pRight, zEndAff[nEq])==SQLITE_AFF_NONE){
111405 /* Since the comparison is to be performed with no conversions
111406 ** applied to the operands, set the affinity to apply to pRight to
111407 ** SQLITE_AFF_NONE. */
111408 zEndAff[nEq] = SQLITE_AFF_NONE;
111409 }
111410 if( sqlite3ExprNeedsNoAffinityChange(pRight, zEndAff[nEq]) ){
111411 zEndAff[nEq] = SQLITE_AFF_NONE;
111412 }
111413 }
111414 codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
111415 nConstraint++;
111416 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
111417 }
111418 sqlite3DbFree(db, zStartAff);
111419 sqlite3DbFree(db, zEndAff);
111420
111421 /* Top of the loop body */
111422 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111423
111424 /* Check if the index cursor is past the end of the range. */
@@ -111436,12 +111001,17 @@
111436 ** If it is, jump to the next iteration of the loop.
111437 */
111438 r1 = sqlite3GetTempReg(pParse);
111439 testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111440 testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111441 if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 ){
 
 
 
 
111442 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
 
111443 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111444 }
111445 sqlite3ReleaseTempReg(pParse, r1);
111446
111447 /* Seek the table cursor, if required */
@@ -111752,11 +111322,11 @@
111752 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
111753 if( pAlt==0 ) continue;
111754 if( pAlt->wtFlags & (TERM_CODED) ) continue;
111755 testcase( pAlt->eOperator & WO_EQ );
111756 testcase( pAlt->eOperator & WO_IN );
111757 VdbeNoopComment((v, "begin transitive constraint"));
111758 pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
111759 if( pEAlt ){
111760 *pEAlt = *pAlt->pExpr;
111761 pEAlt->pLeft = pE->pLeft;
111762 sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL);
@@ -111852,10 +111422,11 @@
111852 int i;
111853 Vdbe *v = pWInfo->pParse->pVdbe;
111854 sqlite3ExplainBegin(v);
111855 for(i=0; i<p->nLTerm; i++){
111856 WhereTerm *pTerm = p->aLTerm[i];
 
111857 sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111858 sqlite3ExplainPush(v);
111859 whereExplainTerm(v, pTerm);
111860 sqlite3ExplainPop(v);
111861 sqlite3ExplainNL(v);
@@ -112135,10 +111706,11 @@
112135 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
112136 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
112137 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
112138 for(j=pLoop->nLTerm-1; j>=0; j--){
112139 pX = pLoop->aLTerm[j];
 
112140 if( pX==pTerm ) break;
112141 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
112142 }
112143 if( j<0 ) pLoop->nOut += pTerm->truthProb;
112144 }
@@ -112164,11 +111736,12 @@
112164 WhereTerm *pTerm; /* A WhereTerm under consideration */
112165 int opMask; /* Valid operators for constraints */
112166 WhereScan scan; /* Iterator for WHERE terms */
112167 Bitmask saved_prereq; /* Original value of pNew->prereq */
112168 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
112169 int saved_nEq; /* Original value of pNew->u.btree.nEq */
 
112170 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
112171 LogEst saved_nOut; /* Original value of pNew->nOut */
112172 int iCol; /* Index of the column in the table */
112173 int rc = SQLITE_OK; /* Return code */
112174 LogEst nRowEst; /* Estimated index selectivity */
@@ -112199,16 +111772,37 @@
112199 nRowEst = 0;
112200 }
112201 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
112202 opMask, pProbe);
112203 saved_nEq = pNew->u.btree.nEq;
 
112204 saved_nLTerm = pNew->nLTerm;
112205 saved_wsFlags = pNew->wsFlags;
112206 saved_prereq = pNew->prereq;
112207 saved_nOut = pNew->nOut;
112208 pNew->rSetup = 0;
112209 rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0]));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112210 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
112211 int nIn = 0;
112212 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
112213 int nRecValid = pBuilder->nRecValid;
112214 #endif
@@ -112240,12 +111834,14 @@
112240 }
112241 pNew->rRun += nIn;
112242 pNew->u.btree.nEq++;
112243 pNew->nOut = nRowEst + nInMul + nIn;
112244 }else if( pTerm->eOperator & (WO_EQ) ){
112245 assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
112246 || nInMul==0 );
 
 
112247 pNew->wsFlags |= WHERE_COLUMN_EQ;
112248 if( iCol<0
112249 || (pProbe->onError!=OE_None && nInMul==0
112250 && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112251 ){
@@ -112322,10 +111918,11 @@
112322 pBuilder->nRecValid = nRecValid;
112323 #endif
112324 }
112325 pNew->prereq = saved_prereq;
112326 pNew->u.btree.nEq = saved_nEq;
 
112327 pNew->wsFlags = saved_wsFlags;
112328 pNew->nOut = saved_nOut;
112329 pNew->nLTerm = saved_nLTerm;
112330 return rc;
112331 }
@@ -112468,10 +112065,11 @@
112468 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
112469 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
112470 if( pTerm->prereqRight & pNew->maskSelf ) continue;
112471 if( termCanDriveIndex(pTerm, pSrc, 0) ){
112472 pNew->u.btree.nEq = 1;
 
112473 pNew->u.btree.pIndex = 0;
112474 pNew->nLTerm = 1;
112475 pNew->aLTerm[0] = pTerm;
112476 /* TUNING: One-time cost for computing the automatic index is
112477 ** approximately 7*N*log2(N) where N is the number of rows in
@@ -112497,10 +112095,11 @@
112497 if( pProbe->pPartIdxWhere!=0
112498 && !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){
112499 continue; /* Partial index inappropriate for this query */
112500 }
112501 pNew->u.btree.nEq = 0;
 
112502 pNew->nLTerm = 0;
112503 pNew->iSortIdx = 0;
112504 pNew->rSetup = 0;
112505 pNew->prereq = mExtra;
112506 pNew->nOut = rSize;
@@ -112582,11 +112181,12 @@
112582 /*
112583 ** Add all WhereLoop objects for a table of the join identified by
112584 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
112585 */
112586 static int whereLoopAddVirtual(
112587 WhereLoopBuilder *pBuilder /* WHERE clause information */
 
112588 ){
112589 WhereInfo *pWInfo; /* WHERE analysis context */
112590 Parse *pParse; /* The parsing context */
112591 WhereClause *pWC; /* The WHERE clause */
112592 struct SrcList_item *pSrc; /* The FROM clause term to search */
@@ -112668,14 +112268,15 @@
112668 pIdxInfo->idxStr = 0;
112669 pIdxInfo->idxNum = 0;
112670 pIdxInfo->needToFreeIdxStr = 0;
112671 pIdxInfo->orderByConsumed = 0;
112672 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
 
112673 rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112674 if( rc ) goto whereLoopAddVtab_exit;
112675 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112676 pNew->prereq = 0;
112677 mxTerm = -1;
112678 assert( pNew->nLSlot>=nConstraint );
112679 for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
112680 pNew->u.vtab.omitMask = 0;
112681 for(i=0; i<nConstraint; i++, pIdxCons++){
@@ -112727,12 +112328,11 @@
112727 pNew->u.vtab.idxStr = pIdxInfo->idxStr;
112728 pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0)
112729 && pIdxInfo->orderByConsumed);
112730 pNew->rSetup = 0;
112731 pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
112732 /* TUNING: Every virtual table query returns 25 rows */
112733 pNew->nOut = 46; assert( 46==sqlite3LogEst(25) );
112734 whereLoopInsert(pBuilder, pNew);
112735 if( pNew->u.vtab.needFree ){
112736 sqlite3_free(pNew->u.vtab.idxStr);
112737 pNew->u.vtab.needFree = 0;
112738 }
@@ -112799,12 +112399,11 @@
112799 continue;
112800 }
112801 sCur.n = 0;
112802 #ifndef SQLITE_OMIT_VIRTUALTABLE
112803 if( IsVirtual(pItem->pTab) ){
112804 rc = whereLoopAddVirtual(&sSubBuild);
112805 for(i=0; i<sCur.n; i++) sCur.a[i].prereq |= mExtra;
112806 }else
112807 #endif
112808 {
112809 rc = whereLoopAddBtree(&sSubBuild, mExtra);
112810 }
@@ -112870,11 +112469,11 @@
112870 if( ((pItem->jointype|priorJoinType) & (JT_LEFT|JT_CROSS))!=0 ){
112871 mExtra = mPrior;
112872 }
112873 priorJoinType = pItem->jointype;
112874 if( IsVirtual(pItem->pTab) ){
112875 rc = whereLoopAddVirtual(pBuilder);
112876 }else{
112877 rc = whereLoopAddBtree(pBuilder, mExtra);
112878 }
112879 if( rc==SQLITE_OK ){
112880 rc = whereLoopAddOr(pBuilder, mExtra);
@@ -113031,10 +112630,11 @@
113031 for(j=0; j<nColumn; j++){
113032 u8 bOnce; /* True to run the ORDER BY search loop */
113033
113034 /* Skip over == and IS NULL terms */
113035 if( j<pLoop->u.btree.nEq
 
113036 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
113037 ){
113038 if( i & WO_ISNULL ){
113039 testcase( isOrderDistinct );
113040 isOrderDistinct = 0;
@@ -113456,10 +113056,11 @@
113456 if( pItem->zIndex ) return 0;
113457 iCur = pItem->iCursor;
113458 pWC = &pWInfo->sWC;
113459 pLoop = pBuilder->pNew;
113460 pLoop->wsFlags = 0;
 
113461 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
113462 if( pTerm ){
113463 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
113464 pLoop->aLTerm[0] = pTerm;
113465 pLoop->nLTerm = 1;
@@ -113684,11 +113285,10 @@
113684 /* Split the WHERE clause into separate subexpressions where each
113685 ** subexpression is separated by an AND operator.
113686 */
113687 initMaskSet(pMaskSet);
113688 whereClauseInit(&pWInfo->sWC, pWInfo);
113689 sqlite3ExprCodeConstants(pParse, pWhere);
113690 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
113691 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113692
113693 /* Special case: a WHERE clause that is constant. Evaluate the
113694 ** expression and either jump over all of the code or fall thru.
@@ -113999,10 +113599,11 @@
113999 notReady = codeOneLoopStart(pWInfo, ii, notReady);
114000 pWInfo->iContinue = pLevel->addrCont;
114001 }
114002
114003 /* Done. */
 
114004 return pWInfo;
114005
114006 /* Jump here if malloc fails */
114007 whereBeginError:
114008 if( pWInfo ){
@@ -114025,12 +113626,14 @@
114025 SrcList *pTabList = pWInfo->pTabList;
114026 sqlite3 *db = pParse->db;
114027
114028 /* Generate loop termination code.
114029 */
 
114030 sqlite3ExprCacheClear(pParse);
114031 for(i=pWInfo->nLevel-1; i>=0; i--){
 
114032 pLevel = &pWInfo->a[i];
114033 pLoop = pLevel->pWLoop;
114034 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114035 if( pLevel->op!=OP_Noop ){
114036 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
@@ -114046,12 +113649,17 @@
114046 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114047 }
114048 sqlite3DbFree(db, pLevel->u.in.aInLoop);
114049 }
114050 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
 
 
 
 
 
 
114051 if( pLevel->iLeftJoin ){
114052 int addr;
114053 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114054 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114055 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114056 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114057 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
@@ -114064,11 +113672,11 @@
114064 }else{
114065 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
114066 }
114067 sqlite3VdbeJumpHere(v, addr);
114068 }
114069 VdbeNoopComment((v, "End WHERE-Loop %d: %s", i,
114070 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
114071 }
114072
114073 /* The "break" point is here, just past the end of the outer loop.
114074 ** Set it.
@@ -116923,16 +116531,11 @@
116923 spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
116924 }
116925 break;
116926 case 200: /* term ::= CTIME_KW */
116927 {
116928 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
116929 ** treated as functions that return constants */
116930 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
116931 if( yygotominor.yy118.pExpr ){
116932 yygotominor.yy118.pExpr->op = TK_CONST_FUNC;
116933 }
116934 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116935 }
116936 break;
116937 case 201: /* expr ::= expr AND expr */
116938 case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
@@ -119357,10 +118960,17 @@
119357 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
119358 if( szMmap>mxMmap) szMmap = mxMmap;
119359 sqlite3GlobalConfig.szMmap = szMmap;
119360 break;
119361 }
 
 
 
 
 
 
 
119362
119363 default: {
119364 rc = SQLITE_ERROR;
119365 break;
119366 }
@@ -119424,11 +119034,12 @@
119424 }
119425 db->lookaside.pEnd = p;
119426 db->lookaside.bEnabled = 1;
119427 db->lookaside.bMalloced = pBuf==0 ?1:0;
119428 }else{
119429 db->lookaside.pEnd = 0;
 
119430 db->lookaside.bEnabled = 0;
119431 db->lookaside.bMalloced = 0;
119432 }
119433 return SQLITE_OK;
119434 }
@@ -119922,10 +119533,11 @@
119922 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
119923 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
119924 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
119925 case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
119926 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
 
119927 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
119928 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
119929 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
119930 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
119931 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -122132,10 +121744,23 @@
122132 *pzRet = sqlite3VdbeExplanation((Vdbe*)pStmt);
122133 break;
122134 }
122135 #endif
122136
 
 
 
 
 
 
 
 
 
 
 
 
 
122137 }
122138 va_end(ap);
122139 #endif /* SQLITE_OMIT_BUILTIN_TEST */
122140 return rc;
122141 }
@@ -123649,10 +123274,14 @@
123649 char *aDoclist; /* Pointer to doclist buffer */
123650 int nDoclist; /* Size of aDoclist[] in bytes */
123651 };
123652
123653 SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
 
 
 
 
123654
123655 /* fts3.c */
123656 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
123657 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
123658 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
@@ -123757,36 +123386,63 @@
123757 q[-1] &= 0x7f; /* turn off high bit in final byte */
123758 assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
123759 return (int) (q - (unsigned char *)p);
123760 }
123761
 
 
 
 
 
 
 
123762 /*
123763 ** Read a 64-bit variable-length integer from memory starting at p[0].
123764 ** Return the number of bytes read, or 0 on error.
123765 ** The value is stored in *v.
123766 */
123767 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
123768 const unsigned char *q = (const unsigned char *) p;
123769 sqlite_uint64 x = 0, y = 1;
123770 while( (*q&0x80)==0x80 && q-(unsigned char *)p<FTS3_VARINT_MAX ){
123771 x += y * (*q++ & 0x7f);
123772 y <<= 7;
123773 }
123774 x += y * (*q++);
123775 *v = (sqlite_int64) x;
123776 return (int) (q - (unsigned char *)p);
 
 
 
 
 
 
 
 
 
123777 }
123778
123779 /*
123780 ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
123781 ** 32-bit integer before it is returned.
123782 */
123783 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
123784 sqlite_int64 i;
123785 int ret = sqlite3Fts3GetVarint(p, &i);
123786 *pi = (int) i;
123787 return ret;
 
 
 
 
 
 
 
 
 
 
 
123788 }
123789
123790 /*
123791 ** Return the number of bytes required to encode v as a varint
123792 */
@@ -125142,14 +124798,14 @@
125142 int nBuffer; /* Total term size */
125143
125144 /* Load the next term on the node into zBuffer. Use realloc() to expand
125145 ** the size of zBuffer if required. */
125146 if( !isFirstTerm ){
125147 zCsr += sqlite3Fts3GetVarint32(zCsr, &nPrefix);
125148 }
125149 isFirstTerm = 0;
125150 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
125151
125152 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
125153 rc = FTS_CORRUPT_VTAB;
125154 goto finish_scan;
125155 }
@@ -125233,11 +124889,11 @@
125233 int rc; /* Return code */
125234 int iHeight; /* Height of this node in tree */
125235
125236 assert( piLeaf || piLeaf2 );
125237
125238 sqlite3Fts3GetVarint32(zNode, &iHeight);
125239 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
125240 assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
125241
125242 if( rc==SQLITE_OK && iHeight>1 ){
125243 char *zBlob = 0; /* Blob read from %_segments table */
@@ -125435,15 +125091,15 @@
125435
125436 while( *p1 || *p2 ){
125437 int iCol1; /* The current column index in pp1 */
125438 int iCol2; /* The current column index in pp2 */
125439
125440 if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
125441 else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
125442 else iCol1 = 0;
125443
125444 if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
125445 else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
125446 else iCol2 = 0;
125447
125448 if( iCol1==iCol2 ){
125449 sqlite3_int64 i1 = 0; /* Last position from pp1 */
@@ -125532,15 +125188,15 @@
125532 assert( isSaveLeft==0 || isExact==0 );
125533
125534 assert( p!=0 && *p1!=0 && *p2!=0 );
125535 if( *p1==POS_COLUMN ){
125536 p1++;
125537 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125538 }
125539 if( *p2==POS_COLUMN ){
125540 p2++;
125541 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125542 }
125543
125544 while( 1 ){
125545 if( iCol1==iCol2 ){
125546 char *pSave = p;
@@ -125586,13 +125242,13 @@
125586 fts3ColumnlistCopy(0, &p2);
125587 assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
125588 if( 0==*p1 || 0==*p2 ) break;
125589
125590 p1++;
125591 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125592 p2++;
125593 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125594 }
125595
125596 /* Advance pointer p1 or p2 (whichever corresponds to the smaller of
125597 ** iCol1 and iCol2) so that it points to either the 0x00 that marks the
125598 ** end of the position list, or the 0x01 that precedes the next
@@ -125600,16 +125256,16 @@
125600 */
125601 else if( iCol1<iCol2 ){
125602 fts3ColumnlistCopy(0, &p1);
125603 if( 0==*p1 ) break;
125604 p1++;
125605 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125606 }else{
125607 fts3ColumnlistCopy(0, &p2);
125608 if( 0==*p2 ) break;
125609 p2++;
125610 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125611 }
125612 }
125613
125614 fts3PoslistCopy(0, &p2);
125615 fts3PoslistCopy(0, &p1);
@@ -128772,11 +128428,11 @@
128772 */
128773 pExpr->aMI[iCol*3 + 1] += iCnt;
128774 pExpr->aMI[iCol*3 + 2] += (iCnt>0);
128775 if( *p==0x00 ) break;
128776 p++;
128777 p += sqlite3Fts3GetVarint32(p, &iCol);
128778 }
128779 }
128780
128781 fts3EvalUpdateCounts(pExpr->pLeft);
128782 fts3EvalUpdateCounts(pExpr->pRight);
@@ -129073,19 +128729,19 @@
129073 }
129074 if( pIter==0 ) return SQLITE_OK;
129075
129076 if( *pIter==0x01 ){
129077 pIter++;
129078 pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
129079 }else{
129080 iThis = 0;
129081 }
129082 while( iThis<iCol ){
129083 fts3ColumnlistCopy(0, &pIter);
129084 if( *pIter==0x00 ) return 0;
129085 pIter++;
129086 pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
129087 }
129088
129089 *ppOut = ((iCol==iThis)?pIter:0);
129090 return SQLITE_OK;
129091 }
@@ -134530,12 +134186,12 @@
134530 rc = fts3SegReaderRequire(pReader, pNext, FTS3_VARINT_MAX*2);
134531 if( rc!=SQLITE_OK ) return rc;
134532
134533 /* Because of the FTS3_NODE_PADDING bytes of padding, the following is
134534 ** safe (no risk of overread) even if the node data is corrupted. */
134535 pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
134536 pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
134537 if( nPrefix<0 || nSuffix<=0
134538 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
134539 ){
134540 return FTS_CORRUPT_VTAB;
134541 }
@@ -134554,11 +134210,11 @@
134554 if( rc!=SQLITE_OK ) return rc;
134555
134556 memcpy(&pReader->zTerm[nPrefix], pNext, nSuffix);
134557 pReader->nTerm = nPrefix+nSuffix;
134558 pNext += nSuffix;
134559 pNext += sqlite3Fts3GetVarint32(pNext, &pReader->nDoclist);
134560 pReader->aDoclist = pNext;
134561 pReader->pOffsetList = 0;
134562
134563 /* Check that the doclist does not appear to extend past the end of the
134564 ** b-tree node. And that the final byte of the doclist is 0x00. If either
@@ -135715,11 +135371,11 @@
135715 pList = p;
135716 if( nList==0 ){
135717 break;
135718 }
135719 p = &pList[1];
135720 p += sqlite3Fts3GetVarint32(p, &iCurrent);
135721 }
135722
135723 if( bZero && &pList[nList]!=pEnd ){
135724 memset(&pList[nList], 0, pEnd - &pList[nList]);
135725 }
@@ -136680,21 +136336,21 @@
136680 if( p->iOff>=p->nNode ){
136681 /* EOF */
136682 p->aNode = 0;
136683 }else{
136684 if( bFirst==0 ){
136685 p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136686 }
136687 p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136688
136689 blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
136690 if( rc==SQLITE_OK ){
136691 memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
136692 p->term.n = nPrefix+nSuffix;
136693 p->iOff += nSuffix;
136694 if( p->iChild==0 ){
136695 p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136696 p->aDoclist = &p->aNode[p->iOff];
136697 p->iOff += p->nDoclist;
136698 }
136699 }
136700 }
@@ -137742,11 +137398,11 @@
137742 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137743 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137744
137745 pHint->n = i;
137746 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
137747 i += sqlite3Fts3GetVarint32(&pHint->a[i], pnInput);
137748 if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
137749
137750 return SQLITE_OK;
137751 }
137752
@@ -138735,11 +138391,11 @@
138735 ** After it returns, *piPos contains the value of the next element of the
138736 ** list and *pp is advanced to the following varint.
138737 */
138738 static void fts3GetDeltaPosition(char **pp, int *piPos){
138739 int iVal;
138740 *pp += sqlite3Fts3GetVarint32(*pp, &iVal);
138741 *piPos += (iVal-2);
138742 }
138743
138744 /*
138745 ** Helper function for fts3ExprIterate() (see below).
@@ -141028,10 +140684,20 @@
141028 ** ever contain very many entries, so a fixed number of buckets is
141029 ** used.
141030 */
141031 #define HASHSIZE 128
141032
 
 
 
 
 
 
 
 
 
 
141033 /*
141034 ** An rtree virtual-table object.
141035 */
141036 struct Rtree {
141037 sqlite3_vtab base;
@@ -141042,10 +140708,11 @@
141042 int iDepth; /* Current depth of the r-tree structure */
141043 char *zDb; /* Name of database containing r-tree table */
141044 char *zName; /* Name of r-tree table */
141045 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
141046 int nBusy; /* Current number of users of this structure */
 
141047
141048 /* List of nodes removed during a CondenseTree operation. List is
141049 ** linked together via the pointer normally used for hash chains -
141050 ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
141051 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
@@ -142233,10 +141900,23 @@
142233 }
142234
142235 rtreeRelease(pRtree);
142236 return rc;
142237 }
 
 
 
 
 
 
 
 
 
 
 
 
 
142238
142239 /*
142240 ** Rtree virtual table module xBestIndex method. There are three
142241 ** table scan strategies to choose from (in order from most to
142242 ** least desirable):
@@ -142269,17 +141949,18 @@
142269 ** The second of each pair of bytes identifies the coordinate column
142270 ** to which the constraint applies. The leftmost coordinate column
142271 ** is 'a', the second from the left 'b' etc.
142272 */
142273 static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
 
142274 int rc = SQLITE_OK;
142275 int ii;
 
142276
142277 int iIdx = 0;
142278 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
142279 memset(zIdxStr, 0, sizeof(zIdxStr));
142280 UNUSED_PARAMETER(tab);
142281
142282 assert( pIdxInfo->idxStr==0 );
142283 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
142284 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
142285
@@ -142295,13 +141976,15 @@
142295 pIdxInfo->aConstraintUsage[jj].omit = 1;
142296
142297 /* This strategy involves a two rowid lookups on an B-Tree structures
142298 ** and then a linear search of an R-Tree node. This should be
142299 ** considered almost as quick as a direct rowid lookup (for which
142300 ** sqlite uses an internal cost of 0.0).
 
142301 */
142302 pIdxInfo->estimatedCost = 10.0;
 
142303 return SQLITE_OK;
142304 }
142305
142306 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
142307 u8 op;
@@ -142326,12 +142009,15 @@
142326 pIdxInfo->idxNum = 2;
142327 pIdxInfo->needToFreeIdxStr = 1;
142328 if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
142329 return SQLITE_NOMEM;
142330 }
142331 assert( iIdx>=0 );
142332 pIdxInfo->estimatedCost = (2000000.0 / (double)(iIdx + 1));
 
 
 
142333 return rc;
142334 }
142335
142336 /*
142337 ** Return the N-dimensional volumn of the cell stored in *p.
@@ -143801,10 +143487,41 @@
143801 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
143802 sqlite3_free(zSql);
143803 }
143804 return rc;
143805 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143806
143807 static sqlite3_module rtreeModule = {
143808 0, /* iVersion */
143809 rtreeCreate, /* xCreate - create a table */
143810 rtreeConnect, /* xConnect - connect to an existing table */
@@ -143887,10 +143604,11 @@
143887 appStmt[5] = &pRtree->pDeleteRowid;
143888 appStmt[6] = &pRtree->pReadParent;
143889 appStmt[7] = &pRtree->pWriteParent;
143890 appStmt[8] = &pRtree->pDeleteParent;
143891
 
143892 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
143893 char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
143894 if( zSql ){
143895 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
143896 }else{
143897
--- 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. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -396,11 +396,11 @@
396 ** Restrictions:
397 **
398 ** <ul>
399 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
400 ** is a valid and open [database connection].
401 ** <li> The application must not close the [database connection] specified by
402 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
403 ** <li> The application must not modify the SQL statement text passed into
404 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
405 ** </ul>
406 */
@@ -473,11 +473,11 @@
473 ** about errors. The extended result codes are enabled or disabled
474 ** on a per database connection basis using the
475 ** [sqlite3_extended_result_codes()] API.
476 **
477 ** Some of the available extended result codes are listed here.
478 ** One may expect the number of extended result codes will increase
479 ** over time. Software that uses extended result codes should expect
480 ** to see new result codes in future releases of SQLite.
481 **
482 ** The SQLITE_OK result code will never be extended. It will always
483 ** be exactly zero.
@@ -517,10 +517,11 @@
517 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
522 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
523 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
524 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
525 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
526 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
527 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -584,11 +585,12 @@
585 ** information is written to disk in the same order as calls
586 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
587 ** after reboot following a crash or power loss, the only bytes in a
588 ** file that were written at the application level might have changed
589 ** and that adjacent bytes, even bytes within the same sector are
590 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
591 ** flag indicate that a file cannot be deleted when open.
592 */
593 #define SQLITE_IOCAP_ATOMIC 0x00000001
594 #define SQLITE_IOCAP_ATOMIC512 0x00000002
595 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
596 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -947,10 +949,16 @@
949 ** This file control is used by some VFS activity tracing [shims].
950 ** The argument is a zero-terminated string. Higher layers in the
951 ** SQLite stack may generate instances of this file control if
952 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
953 **
954 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
955 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
956 ** pointer to an integer and it writes a boolean into that integer depending
957 ** on whether or not the file has been renamed, moved, or deleted since it
958 ** was first opened.
959 **
960 ** </ul>
961 */
962 #define SQLITE_FCNTL_LOCKSTATE 1
963 #define SQLITE_GET_LOCKPROXYFILE 2
964 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -967,10 +975,11 @@
975 #define SQLITE_FCNTL_PRAGMA 14
976 #define SQLITE_FCNTL_BUSYHANDLER 15
977 #define SQLITE_FCNTL_TEMPFILENAME 16
978 #define SQLITE_FCNTL_MMAP_SIZE 18
979 #define SQLITE_FCNTL_TRACE 19
980 #define SQLITE_FCNTL_HAS_MOVED 20
981
982 /*
983 ** CAPI3REF: Mutex Handle
984 **
985 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1411,11 +1420,11 @@
1420 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1421 ** Every memory allocation request coming in through [sqlite3_malloc()]
1422 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1423 ** that causes the corresponding memory allocation to fail.
1424 **
1425 ** The xInit method initializes the memory allocator. For example,
1426 ** it might allocate any require mutexes or initialize internal data
1427 ** structures. The xShutdown method is invoked (indirectly) by
1428 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1429 ** by xInit. The pAppData pointer is used as the only parameter to
1430 ** xInit and xShutdown.
@@ -1713,10 +1722,17 @@
1722 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1723 ** exceed the compile-time maximum mmap size set by the
1724 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1725 ** ^If either argument to this option is negative, then that argument is
1726 ** changed to its compile-time default.
1727 **
1728 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1729 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1730 ** <dd>^This option is only available if SQLite is compiled for Windows
1731 ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1732 ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1733 ** that specifies the maximum size of the created heap.
1734 ** </dl>
1735 */
1736 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1737 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1738 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1737,10 +1753,11 @@
1753 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
1754 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1755 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1756 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1757 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1758 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1759
1760 /*
1761 ** CAPI3REF: Database Connection Configuration Options
1762 **
1763 ** These constants are the available integer configuration options that
@@ -3137,11 +3154,10 @@
3154 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3155 ** ^The specific value of WHERE-clause [parameter] might influence the
3156 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3157 ** or [GLOB] operator or if the parameter is compared to an indexed column
3158 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
 
3159 ** </li>
3160 ** </ol>
3161 */
3162 SQLITE_API int sqlite3_prepare(
3163 sqlite3 *db, /* Database handle */
@@ -3799,23 +3815,23 @@
3815 ** <table border="1">
3816 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
3817 **
3818 ** <tr><td> NULL <td> INTEGER <td> Result is 0
3819 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3820 ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
3821 ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
3822 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
3823 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
3824 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3825 ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
3826 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3827 ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
3828 ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
3829 ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
3830 ** <tr><td> TEXT <td> BLOB <td> No change
3831 ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
3832 ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
3833 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
3834 ** </table>
3835 ** </blockquote>)^
3836 **
3837 ** The table above makes reference to standard C library functions atoi()
@@ -3867,11 +3883,11 @@
3883 **
3884 ** ^The pointers returned are valid until a type conversion occurs as
3885 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3886 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3887 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3888 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3889 ** [sqlite3_free()].
3890 **
3891 ** ^(If a memory allocation error occurs during the evaluation of any
3892 ** of these routines, a default value is returned. The default value
3893 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4945,12 +4961,12 @@
4961 /*
4962 ** CAPI3REF: Free Memory Used By A Database Connection
4963 **
4964 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4965 ** memory as possible from database connection D. Unlike the
4966 ** [sqlite3_release_memory()] interface, this interface is in effect even
4967 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4968 ** omitted.
4969 **
4970 ** See also: [sqlite3_release_memory()]
4971 */
4972 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -5321,14 +5337,26 @@
5337 **
5338 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5339 ** the correct order to satisfy the ORDER BY clause so that no separate
5340 ** sorting step is required.
5341 **
5342 ** ^The estimatedCost value is an estimate of the cost of a particular
5343 ** strategy. A cost of N indicates that the cost of the strategy is similar
5344 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
5345 ** indicates that the expense of the operation is similar to that of a
5346 ** binary search on a unique indexed field of an SQLite table with N rows.
5347 **
5348 ** ^The estimatedRows value is an estimate of the number of rows that
5349 ** will be returned by the strategy.
5350 **
5351 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5352 ** structure for SQLite version 3.8.2. If a virtual table extension is
5353 ** used with an SQLite version earlier than 3.8.2, the results of attempting
5354 ** to read or write the estimatedRows field are undefined (but are likely
5355 ** to included crashing the application). The estimatedRows field should
5356 ** therefore only be used if [sqlite3_libversion_number()] returns a
5357 ** value greater than or equal to 3008002.
5358 */
5359 struct sqlite3_index_info {
5360 /* Inputs */
5361 int nConstraint; /* Number of entries in aConstraint */
5362 struct sqlite3_index_constraint {
@@ -5349,11 +5377,13 @@
5377 } *aConstraintUsage;
5378 int idxNum; /* Number used to identify the index */
5379 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5380 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5381 int orderByConsumed; /* True if output is already ordered */
5382 double estimatedCost; /* Estimated cost of using this index */
5383 /* Fields below are only available in SQLite 3.8.2 and later */
5384 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
5385 };
5386
5387 /*
5388 ** CAPI3REF: Virtual Table Constraint Operator Codes
5389 **
@@ -6079,11 +6109,12 @@
6109 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6110 #define SQLITE_TESTCTRL_ISKEYWORD 16
6111 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6112 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6113 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6114 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6115 #define SQLITE_TESTCTRL_LAST 20
6116
6117 /*
6118 ** CAPI3REF: SQLite Runtime Status
6119 **
6120 ** ^This interface is used to retrieve runtime status information
@@ -8127,13 +8158,12 @@
8158 #define TK_UNCLOSED_STRING 151
8159 #define TK_FUNCTION 152
8160 #define TK_COLUMN 153
8161 #define TK_AGG_FUNCTION 154
8162 #define TK_AGG_COLUMN 155
8163 #define TK_UMINUS 156
8164 #define TK_UPLUS 157
 
8165
8166 /************** End of parse.h ***********************************************/
8167 /************** Continuing where we left off in sqliteInt.h ******************/
8168 #include <stdio.h>
8169 #include <stdlib.h>
@@ -8765,12 +8795,12 @@
8795 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
8796 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
8797 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
8798 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
8799 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8800 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
8801 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
8802 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8803 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8804 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8805 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
8806
@@ -9008,155 +9038,157 @@
9038 #define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
9039 #define OP_Savepoint 2
9040 #define OP_AutoCommit 3
9041 #define OP_Transaction 4
9042 #define OP_SorterNext 5
9043 #define OP_PrevIfOpen 6
9044 #define OP_NextIfOpen 7
9045 #define OP_Prev 8
9046 #define OP_Next 9
9047 #define OP_AggStep 10 /* synopsis: accum=r[P3] step(r[P2@P5]) */
9048 #define OP_Checkpoint 11
9049 #define OP_JournalMode 12
9050 #define OP_Vacuum 13
9051 #define OP_VFilter 14 /* synopsis: iPlan=r[P3] zPlan='P4' */
9052 #define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
9053 #define OP_Goto 16
9054 #define OP_Gosub 17
9055 #define OP_Return 18
9056 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9057 #define OP_Yield 20
9058 #define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */
9059 #define OP_Halt 22
9060 #define OP_Integer 23 /* synopsis: r[P2]=P1 */
9061 #define OP_Int64 24 /* synopsis: r[P2]=P4 */
9062 #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9063 #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9064 #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9065 #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9066 #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9067 #define OP_Copy 30 /* synopsis: r[P2@P3]=r[P1@P3] */
9068 #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9069 #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9070 #define OP_CollSeq 33
9071 #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9072 #define OP_MustBeInt 35
9073 #define OP_RealAffinity 36
9074 #define OP_Permutation 37
9075 #define OP_Compare 38
9076 #define OP_Jump 39
9077 #define OP_Once 40
9078 #define OP_If 41
9079 #define OP_IfNot 42
9080 #define OP_Column 43 /* synopsis: r[P3]=PX */
9081 #define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */
9082 #define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9083 #define OP_Count 46 /* synopsis: r[P2]=count() */
9084 #define OP_ReadCookie 47
9085 #define OP_SetCookie 48
9086 #define OP_VerifyCookie 49
9087 #define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9088 #define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9089 #define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9090 #define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9091 #define OP_SorterOpen 54
9092 #define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9093 #define OP_Close 56
9094 #define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9095 #define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9096 #define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9097 #define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9098 #define OP_Seek 61 /* synopsis: intkey=r[P2] */
9099 #define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9100 #define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9101 #define OP_Found 64 /* synopsis: key=r[P3@P4] */
9102 #define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9103 #define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9104 #define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9105 #define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
9106 #define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9107 #define OP_And 70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9108 #define OP_InsertInt 71 /* synopsis: intkey=P3 data=r[P2] */
9109 #define OP_Delete 72
9110 #define OP_ResetCount 73
9111 #define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9112 #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9113 #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9114 #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9115 #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9116 #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9117 #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9118 #define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9119 #define OP_SorterCompare 82 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9120 #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9121 #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9122 #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9123 #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9124 #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
9125 #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9126 #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9127 #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9128 #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9129 #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9130 #define OP_SorterData 93 /* synopsis: r[P2]=data */
9131 #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9132 #define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
9133 #define OP_RowKey 96 /* synopsis: r[P2]=key */
9134 #define OP_RowData 97 /* synopsis: r[P2]=data */
9135 #define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9136 #define OP_NullRow 99
9137 #define OP_Last 100
9138 #define OP_SorterSort 101
9139 #define OP_Sort 102
9140 #define OP_Rewind 103
9141 #define OP_SorterInsert 104
9142 #define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9143 #define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9144 #define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9145 #define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9146 #define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9147 #define OP_Destroy 110
9148 #define OP_Clear 111
9149 #define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9150 #define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9151 #define OP_ParseSchema 114
9152 #define OP_LoadAnalysis 115
9153 #define OP_DropTable 116
9154 #define OP_DropIndex 117
9155 #define OP_DropTrigger 118
9156 #define OP_IntegrityCk 119
9157 #define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9158 #define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9159 #define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9160 #define OP_Program 123
9161 #define OP_Param 124
9162 #define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9163 #define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9164 #define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9165 #define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9166 #define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9167 #define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9168 #define OP_Real 131 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9169 #define OP_AggFinal 132 /* synopsis: accum=r[P1] N=P2 */
9170 #define OP_IncrVacuum 133
9171 #define OP_Expire 134
9172 #define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9173 #define OP_VBegin 136
9174 #define OP_VCreate 137
9175 #define OP_VDestroy 138
9176 #define OP_VOpen 139
9177 #define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9178 #define OP_VNext 141
9179 #define OP_ToText 142 /* same as TK_TO_TEXT */
9180 #define OP_ToBlob 143 /* same as TK_TO_BLOB */
9181 #define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
9182 #define OP_ToInt 145 /* same as TK_TO_INT */
9183 #define OP_ToReal 146 /* same as TK_TO_REAL */
9184 #define OP_VRename 147
9185 #define OP_Pagecount 148
9186 #define OP_MaxPgcnt 149
9187 #define OP_Trace 150
9188 #define OP_Noop 151
9189 #define OP_Explain 152
9190
9191
9192 /* Properties such as "out2" or "jump" that are specified in
9193 ** comments following the "case" for each opcode in the vdbe.c
9194 ** are encoded into bitvectors as follows:
@@ -9168,28 +9200,29 @@
9200 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9201 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9202 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9203 #define OPFLG_INITIALIZER {\
9204 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9205 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9206 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9207 /* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9208 /* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9209 /* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9210 /* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9211 /* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9212 /* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c, 0x4c, 0x00,\
9213 /* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
9214 /* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9215 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
9216 /* 96 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9217 /* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9218 /* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9219 /* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9220 /* 128 */ 0x05, 0x05, 0x05, 0x02, 0x00, 0x01, 0x00, 0x00,\
9221 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x04,\
9222 /* 144 */ 0x04, 0x04, 0x04, 0x00, 0x02, 0x02, 0x00, 0x00,\
9223 /* 152 */ 0x00,}
9224
9225 /************** End of opcodes.h *********************************************/
9226 /************** Continuing where we left off in vdbe.h ***********************/
9227
9228 /*
@@ -9223,11 +9256,10 @@
9256 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
9257 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
9258 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
9259 #ifdef SQLITE_DEBUG
9260 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
 
9261 #endif
9262 SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
9263 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
9264 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
9265 SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
@@ -10290,10 +10322,11 @@
10322 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
10323 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
10324 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
10325 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
10326 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
10327 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
10328
10329
10330 /*
10331 ** Bits of the sqlite3.dbOptFlags field that are used by the
10332 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -10323,10 +10356,17 @@
10356 #else
10357 #define OptimizationDisabled(db, mask) 0
10358 #define OptimizationEnabled(db, mask) 1
10359 #endif
10360
10361 /*
10362 ** Return true if it OK to factor constant expressions into the initialization
10363 ** code. The argument is a Parse object for the code generator.
10364 */
10365 #define ConstFactorOk(P) \
10366 ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))
10367
10368 /*
10369 ** Possible values for the sqlite.magic field.
10370 ** The numbers are obtained at random and have no special meaning, other
10371 ** than being distinct from one another.
10372 */
@@ -10389,10 +10429,11 @@
10429 #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
10430 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10431 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10432 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10433 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10434 #define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
10435
10436 /*
10437 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10438 ** used to create the initializers for the FuncDef structures.
10439 **
@@ -10401,10 +10442,13 @@
10442 ** implemented by C function xFunc that accepts nArg arguments. The
10443 ** value passed as iArg is cast to a (void*) and made available
10444 ** as the user-data (sqlite3_user_data()) for the function. If
10445 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
10446 **
10447 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
10448 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
10449 **
10450 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
10451 ** Used to create an aggregate function definition implemented by
10452 ** the C functions xStep and xFinal. The first four parameters
10453 ** are interpreted in the same way as the first 4 parameters to
10454 ** FUNCTION().
@@ -10416,20 +10460,24 @@
10460 ** available as the function user-data (sqlite3_user_data()). The
10461 ** FuncDef.flags variable is set to the value passed as the flags
10462 ** parameter.
10463 */
10464 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
10465 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10466 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10467 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
10468 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10469 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10470 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10471 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
10472 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10473 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10474 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10475 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
10476 #define LIKEFUNC(zName, nArg, arg, flags) \
10477 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
10478 (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10479 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10480 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
10481 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10482
10483 /*
@@ -11075,20 +11123,21 @@
11123 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
11124 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
11125 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
11126 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
11127 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11128 /* unused 0x000200 */
11129 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
11130 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
11131 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
11132 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
11133 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11134 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11135 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11136 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11137 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11138 #define EP_Constant 0x080000 /* Node is a constant */
11139
11140 /*
11141 ** These macros can be used to test, set, or clear bits in the
11142 ** Expr.flags field.
11143 */
@@ -11146,12 +11195,18 @@
11195 char *zName; /* Token associated with this expression */
11196 char *zSpan; /* Original text of the expression */
11197 u8 sortOrder; /* 1 for DESC or 0 for ASC */
11198 unsigned done :1; /* A flag to indicate when processing is finished */
11199 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11200 unsigned reusable :1; /* Constant expression is reusable */
11201 union {
11202 struct {
11203 u16 iOrderByCol; /* For ORDER BY, column number in result set */
11204 u16 iAlias; /* Index into Parse.aAlias[] for zName */
11205 } x;
11206 int iConstExprReg; /* Register in which Expr value is cached */
11207 } u;
11208 } *a; /* Alloc a power of two greater or equal to nExpr */
11209 };
11210
11211 /*
11212 ** An instance of this structure is used by the parser to record both
@@ -11524,10 +11579,11 @@
11579 u8 tempReg; /* iReg is a temp register that needs to be freed */
11580 int iLevel; /* Nesting level */
11581 int iReg; /* Reg with value of this column. 0 means none. */
11582 int lru; /* Least recently used entry has the smallest value */
11583 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11584 ExprList *pConstExpr;/* Constant expressions */
11585 yDbMask writeMask; /* Start a write transaction on these databases */
11586 yDbMask cookieMask; /* Bitmask of schema verified databases */
11587 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
11588 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11589 int regRowid; /* Register holding rowid of CREATE TABLE entry */
@@ -11761,10 +11817,11 @@
11817 int bCoreMutex; /* True to enable core mutexing */
11818 int bFullMutex; /* True to enable full mutexing */
11819 int bOpenUri; /* True to interpret filenames as URIs */
11820 int bUseCis; /* Use covering indices for full-scans */
11821 int mxStrlen; /* Maximum string length */
11822 int neverCorrupt; /* Database is always well-formed */
11823 int szLookaside; /* Default lookaside buffer size */
11824 int nLookaside; /* Default lookaside buffer count */
11825 sqlite3_mem_methods m; /* Low-level memory allocation interface */
11826 sqlite3_mutex_methods mutex; /* Low-level mutex interface */
11827 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */
@@ -11797,10 +11854,28 @@
11854 void(*xSqllog)(void*,sqlite3*,const char*, int);
11855 void *pSqllogArg;
11856 #endif
11857 };
11858
11859 /*
11860 ** This macro is used inside of assert() statements to indicate that
11861 ** the assert is only valid on a well-formed database. Instead of:
11862 **
11863 ** assert( X );
11864 **
11865 ** One writes:
11866 **
11867 ** assert( X || CORRUPT_DB );
11868 **
11869 ** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate
11870 ** that the database is definitely corrupt, only that it might be corrupt.
11871 ** For most test cases, CORRUPT_DB is set to false using a special
11872 ** sqlite3_test_control(). This enables assert() statements to prove
11873 ** things that are always true for well-formed databases.
11874 */
11875 #define CORRUPT_DB (sqlite3Config.neverCorrupt==0)
11876
11877 /*
11878 ** Context pointer passed down through the tree-walk.
11879 */
11880 struct Walker {
11881 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
@@ -12134,15 +12209,17 @@
12209 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12210 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12211 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12212 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12213 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12214 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
12215 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12216 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12217 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12218 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
12219 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
12220 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
12221 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12222 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
12223 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
12224 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
12225 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
@@ -12183,11 +12260,11 @@
12260 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12261 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
12262 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
12263 u8,u8,int,int*);
12264 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12265 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*);
12266 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
12267 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
12268 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
12269 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
12270 SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
@@ -12424,10 +12501,11 @@
12501 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
12502 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
12503
12504 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
12505 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
12506 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
12507 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
12508 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
12509 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
12510 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
12511 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -12505,10 +12583,11 @@
12583 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
12584 SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
12585 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
12586 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
12587 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
12588 SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
12589 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
12590 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
12591 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
12592 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
12593 SQLITE_PRIVATE const char *sqlite3JournalModename(int);
@@ -12821,10 +12900,11 @@
12900 1, /* bCoreMutex */
12901 SQLITE_THREADSAFE==1, /* bFullMutex */
12902 SQLITE_USE_URI, /* bOpenUri */
12903 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
12904 0x7ffffffe, /* mxStrlen */
12905 0, /* neverCorrupt */
12906 128, /* szLookaside */
12907 500, /* nLookaside */
12908 {0,0,0,0,0,0,0,0}, /* m */
12909 {0,0,0,0,0,0,0,0,0}, /* mutex */
12910 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
@@ -12855,11 +12935,10 @@
12935 #ifdef SQLITE_ENABLE_SQLLOG
12936 0, /* xSqllog */
12937 0 /* pSqllogArg */
12938 #endif
12939 };
 
12940
12941 /*
12942 ** Hash table for global functions - functions common to all
12943 ** database connections. After initialization, this table is
12944 ** read-only.
@@ -13253,10 +13332,13 @@
13332 "SMALL_STACK",
13333 #endif
13334 #ifdef SQLITE_SOUNDEX
13335 "SOUNDEX",
13336 #endif
13337 #ifdef SQLITE_SYSTEM_MALLOC
13338 "SYSTEM_MALLOC",
13339 #endif
13340 #ifdef SQLITE_TCL
13341 "TCL",
13342 #endif
13343 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
13344 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
@@ -13267,10 +13349,13 @@
13349 #if defined(SQLITE_THREADSAFE)
13350 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
13351 #endif
13352 #ifdef SQLITE_USE_ALLOCA
13353 "USE_ALLOCA",
13354 #endif
13355 #ifdef SQLITE_WIN32_MALLOC
13356 "WIN32_MALLOC",
13357 #endif
13358 #ifdef SQLITE_ZERO_MALLOC
13359 "ZERO_MALLOC"
13360 #endif
13361 };
@@ -13367,11 +13452,11 @@
13452 typedef struct VdbeOp Op;
13453
13454 /*
13455 ** Boolean values
13456 */
13457 typedef unsigned Bool;
13458
13459 /* Opaque type used by code in vdbesort.c */
13460 typedef struct VdbeSorter VdbeSorter;
13461
13462 /* Opaque type used by the explainer */
@@ -13384,42 +13469,39 @@
13469 ** A cursor is a pointer into a single BTree within a database file.
13470 ** The cursor can seek to a BTree entry with a particular key, or
13471 ** loop over all entries of the Btree. You can also insert new BTree
13472 ** entries or retrieve the key or data from the entry that the cursor
13473 ** is currently pointing to.
13474 **
13475 ** Cursors can also point to virtual tables, sorters, or "pseudo-tables".
13476 ** A pseudo-table is a single-row table implemented by registers.
13477 **
13478 ** Every cursor that the virtual machine has open is represented by an
13479 ** instance of the following structure.
13480 */
13481 struct VdbeCursor {
13482 BtCursor *pCursor; /* The cursor structure of the backend */
13483 Btree *pBt; /* Separate file holding temporary table */
13484 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
13485 int seekResult; /* Result of previous sqlite3BtreeMoveto() */
13486 int pseudoTableReg; /* Register holding pseudotable content. */
13487 i16 nField; /* Number of fields in the header */
13488 u16 nHdrParsed; /* Number of header fields parsed so far */
13489 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
13490 u8 nullRow; /* True if pointing to a row with no data */
13491 u8 rowidIsValid; /* True if lastRowid is valid */
13492 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13493 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13494 Bool isTable:1; /* True if a table requiring integer keys */
13495 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13496 Bool multiPseudo:1; /* Multi-register pseudo-cursor */
 
 
13497 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
 
13498 i64 seqCount; /* Sequence counter */
13499 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13500 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13501 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
13502
 
 
 
13503 /* Cached information about the header for the data record that the
13504 ** cursor is currently pointing to. Only valid if cacheStatus matches
13505 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
13506 ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
13507 ** the cache is out of date.
@@ -13426,14 +13508,18 @@
13508 **
13509 ** aRow might point to (ephemeral) data for the current row, or it might
13510 ** be NULL.
13511 */
13512 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
13513 u32 payloadSize; /* Total number of bytes in the record */
13514 u32 szRow; /* Byte available in aRow */
13515 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
13516 const u8 *aRow; /* Data for the current row, if all on one page */
13517 u32 aType[1]; /* Type values for all entries in the record */
13518 /* 2*nField extra array elements allocated for aType[], beyond the one
13519 ** static element declared in the structure. nField total array slots for
13520 ** aType[] and nField+1 array slots for aOffset[] */
13521 };
13522 typedef struct VdbeCursor VdbeCursor;
13523
13524 /*
13525 ** When a sub-program is executed (OP_Program), a structure of this type
@@ -13686,13 +13772,10 @@
13772 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13773 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13774 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
13775 char *zSql; /* Text of the SQL statement that generated this */
13776 void *pFree; /* Free this when deleting the vdbe */
 
 
 
13777 #ifdef SQLITE_ENABLE_TREE_EXPLAIN
13778 Explain *pExplain; /* The explainer */
13779 char *zExplain; /* Explanation of data structures */
13780 #endif
13781 VdbeFrame *pFrame; /* Parent frame */
@@ -13722,11 +13805,11 @@
13805 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
13806 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
13807 #endif
13808 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13809 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13810 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
13811 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13812 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13813
13814 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13815 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -13757,11 +13840,11 @@
13840 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
13841 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
13842 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
13843 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
13844 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
13845 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
13846 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
13847 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
13848 #define VdbeMemRelease(X) \
13849 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
13850 sqlite3VdbeMemReleaseExternal(X);
@@ -15782,20 +15865,10 @@
15865 ** This version of the memory allocator is the default. It is
15866 ** used when no other memory allocator is specified using compile-time
15867 ** macros.
15868 */
15869 #ifdef SQLITE_SYSTEM_MALLOC
 
 
 
 
 
 
 
 
 
 
15870 #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
15871
15872 /*
15873 ** Use the zone allocator available on apple products unless the
15874 ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
@@ -15814,25 +15887,51 @@
15887
15888 /*
15889 ** Use standard C library malloc and free on non-Apple systems.
15890 ** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
15891 */
15892 #define SQLITE_MALLOC(x) malloc(x)
15893 #define SQLITE_FREE(x) free(x)
15894 #define SQLITE_REALLOC(x,y) realloc((x),(y))
15895
15896 /*
15897 ** The malloc.h header file is needed for malloc_usable_size() function
15898 ** on some systems (e.g. Linux).
15899 */
15900 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
15901 # define SQLITE_USE_MALLOC_H
15902 # define SQLITE_USE_MALLOC_USABLE_SIZE
15903 /*
15904 ** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
15905 ** use of _msize() is automatic, but can be disabled by compiling with
15906 ** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
15907 ** the malloc.h header file.
15908 */
15909 #elif defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15910 # define SQLITE_USE_MALLOC_H
15911 # define SQLITE_USE_MSIZE
15912 #endif
15913
15914 /*
15915 ** Include the malloc.h header file, if necessary. Also set define macro
15916 ** SQLITE_MALLOCSIZE to the appropriate function name, which is _msize()
15917 ** for MSVC and malloc_usable_size() for most other systems (e.g. Linux).
15918 ** The memory size function can always be overridden manually by defining
15919 ** the macro SQLITE_MALLOCSIZE to the desired function name.
15920 */
15921 #if defined(SQLITE_USE_MALLOC_H)
15922 # include <malloc.h>
15923 # if defined(SQLITE_USE_MALLOC_USABLE_SIZE)
15924 # if !defined(SQLITE_MALLOCSIZE)
15925 # define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15926 # endif
15927 # elif defined(SQLITE_USE_MSIZE)
15928 # if !defined(SQLITE_MALLOCSIZE)
15929 # define SQLITE_MALLOCSIZE _msize
15930 # endif
15931 # endif
15932 #endif /* defined(SQLITE_USE_MALLOC_H) */
15933
15934 #endif /* __APPLE__ or not __APPLE__ */
15935
15936 /*
15937 ** Like malloc(), but remember the size of the allocation
@@ -17435,36 +17534,17 @@
17534 ** works for chunks that are currently checked out.
17535 */
17536 static int memsys5Size(void *p){
17537 int iSize = 0;
17538 if( p ){
17539 int i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom);
17540 assert( i>=0 && i<mem5.nBlock );
17541 iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
17542 }
17543 return iSize;
17544 }
17545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17546 /*
17547 ** Return a block of memory of at least nBytes in size.
17548 ** Return NULL if unable. Return NULL if nBytes==0.
17549 **
17550 ** The caller guarantees that nByte is positive.
@@ -17506,11 +17586,12 @@
17586 if( iBin>LOGMAX ){
17587 testcase( sqlite3GlobalConfig.xLog!=0 );
17588 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes", nByte);
17589 return 0;
17590 }
17591 i = mem5.aiFreelist[iBin];
17592 memsys5Unlink(i, iBin);
17593 while( iBin>iLogsize ){
17594 int newSize;
17595
17596 iBin--;
17597 newSize = 1 << iBin;
@@ -17540,11 +17621,11 @@
17621 int iBlock;
17622
17623 /* Set iBlock to the index of the block pointed to by pOld in
17624 ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
17625 */
17626 iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom);
17627
17628 /* Check that the pointer pOld points to a valid, non-free block. */
17629 assert( iBlock>=0 && iBlock<mem5.nBlock );
17630 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
17631 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
@@ -19309,11 +19390,11 @@
19390 /*
19391 ** TRUE if p is a lookaside memory allocation from db
19392 */
19393 #ifndef SQLITE_OMIT_LOOKASIDE
19394 static int isLookaside(sqlite3 *db, void *p){
19395 return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19396 }
19397 #else
19398 #define isLookaside(A,B) 0
19399 #endif
19400
@@ -19325,12 +19406,13 @@
19406 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
19407 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
19408 return sqlite3GlobalConfig.m.xSize(p);
19409 }
19410 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19411 assert( db!=0 );
19412 assert( sqlite3_mutex_held(db->mutex) );
19413 if( isLookaside(db, p) ){
19414 return db->lookaside.sz;
19415 }else{
19416 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
19417 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
19418 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19808,10 +19890,18 @@
19890 }
19891 if( N>0 ){
19892 sqlite3StrAccumAppend(pAccum, zSpaces, N);
19893 }
19894 }
19895
19896 /*
19897 ** Set the StrAccum object to an error mode.
19898 */
19899 void setStrAccumError(StrAccum *p, u8 eError){
19900 p->accError = eError;
19901 p->nAlloc = 0;
19902 }
19903
19904 /*
19905 ** On machines with a small stack size, you can redefine the
19906 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19907 */
@@ -20020,11 +20110,11 @@
20110 zOut = buf;
20111 }else{
20112 nOut = precision + 10;
20113 zOut = zExtra = sqlite3Malloc( nOut );
20114 if( zOut==0 ){
20115 setStrAccumError(pAccum, STRACCUM_NOMEM);
20116 return;
20117 }
20118 }
20119 bufpt = &zOut[nOut-1];
20120 if( xtype==etORDINAL ){
@@ -20132,11 +20222,11 @@
20222 e2 = exp;
20223 }
20224 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20225 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20226 if( bufpt==0 ){
20227 setStrAccumError(pAccum, STRACCUM_NOMEM);
20228 return;
20229 }
20230 }
20231 zOut = bufpt;
20232 nsd = 16 + flag_altform2*10;
@@ -20267,11 +20357,11 @@
20357 needQuote = !isnull && xtype==etSQLESCAPE2;
20358 n += i + 1 + needQuote*2;
20359 if( n>etBUFSIZE ){
20360 bufpt = zExtra = sqlite3Malloc( n );
20361 if( bufpt==0 ){
20362 setStrAccumError(pAccum, STRACCUM_NOMEM);
20363 return;
20364 }
20365 }else{
20366 bufpt = buf;
20367 }
@@ -20290,11 +20380,11 @@
20380 ** if( precision>=0 && precision<length ) length = precision; */
20381 break;
20382 }
20383 case etTOKEN: {
20384 Token *pToken = va_arg(ap, Token*);
20385 if( pToken && pToken->n ){
20386 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20387 }
20388 length = width = 0;
20389 break;
20390 }
@@ -20302,14 +20392,14 @@
20392 SrcList *pSrc = va_arg(ap, SrcList*);
20393 int k = va_arg(ap, int);
20394 struct SrcList_item *pItem = &pSrc->a[k];
20395 assert( k>=0 && k<pSrc->nSrc );
20396 if( pItem->zDatabase ){
20397 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
20398 sqlite3StrAccumAppend(pAccum, ".", 1);
20399 }
20400 sqlite3StrAccumAppendAll(pAccum, pItem->zName);
20401 length = width = 0;
20402 break;
20403 }
20404 default: {
20405 assert( xtype==etINVALID );
@@ -20344,36 +20434,34 @@
20434
20435 /*
20436 ** Append N bytes of text from z to the StrAccum object.
20437 */
20438 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20439 assert( z!=0 );
20440 assert( p->zText!=0 || p->nChar==0 || p->accError );
20441 assert( N>=0 );
20442 assert( p->accError==0 || p->nAlloc==0 );
 
 
 
 
 
 
 
20443 if( p->nChar+N >= p->nAlloc ){
20444 char *zNew;
20445 if( p->accError ){
20446 testcase(p->accError==STRACCUM_TOOBIG);
20447 testcase(p->accError==STRACCUM_NOMEM);
20448 return;
20449 }
20450 if( !p->useMalloc ){
 
20451 N = p->nAlloc - p->nChar - 1;
20452 setStrAccumError(p, STRACCUM_TOOBIG);
20453 if( N<=0 ){
20454 return;
20455 }
20456 }else{
20457 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20458 i64 szNew = p->nChar;
20459 szNew += N + 1;
20460 if( szNew > p->mxAlloc ){
20461 sqlite3StrAccumReset(p);
20462 setStrAccumError(p, STRACCUM_TOOBIG);
20463 return;
20464 }else{
20465 p->nAlloc = (int)szNew;
20466 }
20467 if( p->useMalloc==1 ){
@@ -20383,20 +20471,28 @@
20471 }
20472 if( zNew ){
20473 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20474 p->zText = zNew;
20475 }else{
 
20476 sqlite3StrAccumReset(p);
20477 setStrAccumError(p, STRACCUM_NOMEM);
20478 return;
20479 }
20480 }
20481 }
20482 assert( p->zText );
20483 memcpy(&p->zText[p->nChar], z, N);
20484 p->nChar += N;
20485 }
20486
20487 /*
20488 ** Append the complete text of zero-terminated string z[] to the p string.
20489 */
20490 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){
20491 sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z));
20492 }
20493
20494
20495 /*
20496 ** Finish off a string by making sure it is zero-terminated.
20497 ** Return a pointer to the resulting string. Return a NULL
20498 ** pointer if any kind of error was encountered.
@@ -20411,11 +20507,11 @@
20507 p->zText = sqlite3_malloc(p->nChar+1);
20508 }
20509 if( p->zText ){
20510 memcpy(p->zText, p->zBase, p->nChar+1);
20511 }else{
20512 setStrAccumError(p, STRACCUM_NOMEM);
20513 }
20514 }
20515 }
20516 return p->zText;
20517 }
@@ -21748,16 +21844,16 @@
21844 ** Convert zNum to a 64-bit signed integer.
21845 **
21846 ** If the zNum value is representable as a 64-bit twos-complement
21847 ** integer, then write that value into *pNum and return 0.
21848 **
21849 ** If zNum is exactly 9223372036854775808, return 2. This special
21850 ** case is broken out because while 9223372036854775808 cannot be a
21851 ** signed 64-bit integer, its negative -9223372036854775808 can be.
21852 **
21853 ** If zNum is too big for a 64-bit integer and is not
21854 ** 9223372036854775808 or if zNum contains any non-numeric text,
21855 ** then return 1.
21856 **
21857 ** length is the number of bytes in the string (bytes, not characters).
21858 ** The string is not necessarily zero-terminated. The encoding is
21859 ** given by enc.
@@ -21795,11 +21891,11 @@
21891 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
21892 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
21893 u = u*10 + c - '0';
21894 }
21895 if( u>LARGEST_INT64 ){
21896 *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
21897 }else if( neg ){
21898 *pNum = -(i64)u;
21899 }else{
21900 *pNum = (i64)u;
21901 }
@@ -21826,11 +21922,10 @@
21922 return 1;
21923 }else{
21924 /* zNum is exactly 9223372036854775808. Fits if negative. The
21925 ** special case 2 overflow if positive */
21926 assert( u-1==LARGEST_INT64 );
 
21927 return neg ? 0 : 2;
21928 }
21929 }
21930 }
21931
@@ -22565,11 +22660,13 @@
22660 if( x<10 ) return 1;
22661 n = x%10;
22662 x /= 10;
22663 if( n>=5 ) n -= 2;
22664 else if( n>=1 ) n -= 1;
22665 if( x>=3 ){
22666 return x>60 ? (u64)LARGEST_INT64 : (n+8)<<(x-3);
22667 }
22668 return (n+8)>>(3-x);
22669 }
22670
22671 /************** End of util.c ************************************************/
22672 /************** Begin file hash.c ********************************************/
@@ -22869,155 +22966,157 @@
22966 /* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
22967 /* 2 */ "Savepoint" OpHelp(""),
22968 /* 3 */ "AutoCommit" OpHelp(""),
22969 /* 4 */ "Transaction" OpHelp(""),
22970 /* 5 */ "SorterNext" OpHelp(""),
22971 /* 6 */ "PrevIfOpen" OpHelp(""),
22972 /* 7 */ "NextIfOpen" OpHelp(""),
22973 /* 8 */ "Prev" OpHelp(""),
22974 /* 9 */ "Next" OpHelp(""),
22975 /* 10 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
22976 /* 11 */ "Checkpoint" OpHelp(""),
22977 /* 12 */ "JournalMode" OpHelp(""),
22978 /* 13 */ "Vacuum" OpHelp(""),
22979 /* 14 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"),
22980 /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
22981 /* 16 */ "Goto" OpHelp(""),
22982 /* 17 */ "Gosub" OpHelp(""),
22983 /* 18 */ "Return" OpHelp(""),
22984 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
22985 /* 20 */ "Yield" OpHelp(""),
22986 /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
22987 /* 22 */ "Halt" OpHelp(""),
22988 /* 23 */ "Integer" OpHelp("r[P2]=P1"),
22989 /* 24 */ "Int64" OpHelp("r[P2]=P4"),
22990 /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
22991 /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
22992 /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
22993 /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
22994 /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
22995 /* 30 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
22996 /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
22997 /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
22998 /* 33 */ "CollSeq" OpHelp(""),
22999 /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23000 /* 35 */ "MustBeInt" OpHelp(""),
23001 /* 36 */ "RealAffinity" OpHelp(""),
23002 /* 37 */ "Permutation" OpHelp(""),
23003 /* 38 */ "Compare" OpHelp(""),
23004 /* 39 */ "Jump" OpHelp(""),
23005 /* 40 */ "Once" OpHelp(""),
23006 /* 41 */ "If" OpHelp(""),
23007 /* 42 */ "IfNot" OpHelp(""),
23008 /* 43 */ "Column" OpHelp("r[P3]=PX"),
23009 /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23010 /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23011 /* 46 */ "Count" OpHelp("r[P2]=count()"),
23012 /* 47 */ "ReadCookie" OpHelp(""),
23013 /* 48 */ "SetCookie" OpHelp(""),
23014 /* 49 */ "VerifyCookie" OpHelp(""),
23015 /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23016 /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23017 /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23018 /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23019 /* 54 */ "SorterOpen" OpHelp(""),
23020 /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23021 /* 56 */ "Close" OpHelp(""),
23022 /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23023 /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23024 /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23025 /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23026 /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23027 /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23028 /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23029 /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23030 /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23031 /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23032 /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23033 /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23034 /* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23035 /* 70 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23036 /* 71 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23037 /* 72 */ "Delete" OpHelp(""),
23038 /* 73 */ "ResetCount" OpHelp(""),
23039 /* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23040 /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23041 /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23042 /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23043 /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23044 /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23045 /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23046 /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23047 /* 82 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23048 /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23049 /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23050 /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23051 /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23052 /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
23053 /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23054 /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23055 /* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23056 /* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23057 /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23058 /* 93 */ "SorterData" OpHelp("r[P2]=data"),
23059 /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23060 /* 95 */ "String8" OpHelp("r[P2]='P4'"),
23061 /* 96 */ "RowKey" OpHelp("r[P2]=key"),
23062 /* 97 */ "RowData" OpHelp("r[P2]=data"),
23063 /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23064 /* 99 */ "NullRow" OpHelp(""),
23065 /* 100 */ "Last" OpHelp(""),
23066 /* 101 */ "SorterSort" OpHelp(""),
23067 /* 102 */ "Sort" OpHelp(""),
23068 /* 103 */ "Rewind" OpHelp(""),
23069 /* 104 */ "SorterInsert" OpHelp(""),
23070 /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23071 /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23072 /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23073 /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23074 /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23075 /* 110 */ "Destroy" OpHelp(""),
23076 /* 111 */ "Clear" OpHelp(""),
23077 /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23078 /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23079 /* 114 */ "ParseSchema" OpHelp(""),
23080 /* 115 */ "LoadAnalysis" OpHelp(""),
23081 /* 116 */ "DropTable" OpHelp(""),
23082 /* 117 */ "DropIndex" OpHelp(""),
23083 /* 118 */ "DropTrigger" OpHelp(""),
23084 /* 119 */ "IntegrityCk" OpHelp(""),
23085 /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23086 /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23087 /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23088 /* 123 */ "Program" OpHelp(""),
23089 /* 124 */ "Param" OpHelp(""),
23090 /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23091 /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23092 /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23093 /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23094 /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23095 /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23096 /* 131 */ "Real" OpHelp("r[P2]=P4"),
23097 /* 132 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23098 /* 133 */ "IncrVacuum" OpHelp(""),
23099 /* 134 */ "Expire" OpHelp(""),
23100 /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23101 /* 136 */ "VBegin" OpHelp(""),
23102 /* 137 */ "VCreate" OpHelp(""),
23103 /* 138 */ "VDestroy" OpHelp(""),
23104 /* 139 */ "VOpen" OpHelp(""),
23105 /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23106 /* 141 */ "VNext" OpHelp(""),
23107 /* 142 */ "ToText" OpHelp(""),
23108 /* 143 */ "ToBlob" OpHelp(""),
23109 /* 144 */ "ToNumeric" OpHelp(""),
23110 /* 145 */ "ToInt" OpHelp(""),
23111 /* 146 */ "ToReal" OpHelp(""),
23112 /* 147 */ "VRename" OpHelp(""),
23113 /* 148 */ "Pagecount" OpHelp(""),
23114 /* 149 */ "MaxPgcnt" OpHelp(""),
23115 /* 150 */ "Trace" OpHelp(""),
23116 /* 151 */ "Noop" OpHelp(""),
23117 /* 152 */ "Explain" OpHelp(""),
23118 };
23119 return azName[i];
23120 }
23121 #endif
23122
@@ -24545,10 +24644,19 @@
24644 }
24645 *ppInode = pInode;
24646 return SQLITE_OK;
24647 }
24648
24649 /*
24650 ** Return TRUE if pFile has been renamed or unlinked since it was first opened.
24651 */
24652 static int fileHasMoved(unixFile *pFile){
24653 struct stat buf;
24654 return pFile->pInode!=0 &&
24655 (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
24656 }
24657
24658
24659 /*
24660 ** Check a unixFile that is a database. Verify the following:
24661 **
24662 ** (1) There is exactly one hard link on the file
@@ -24579,14 +24687,11 @@
24687 if( buf.st_nlink>1 ){
24688 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
24689 pFile->ctrlFlags |= UNIXFILE_WARNED;
24690 return;
24691 }
24692 if( fileHasMoved(pFile) ){
 
 
 
24693 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
24694 pFile->ctrlFlags |= UNIXFILE_WARNED;
24695 return;
24696 }
24697 }
@@ -27030,10 +27135,14 @@
27135 if( zTFile ){
27136 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
27137 *(char**)pArg = zTFile;
27138 }
27139 return SQLITE_OK;
27140 }
27141 case SQLITE_FCNTL_HAS_MOVED: {
27142 *(int*)pArg = fileHasMoved(pFile);
27143 return SQLITE_OK;
27144 }
27145 #if SQLITE_MAX_MMAP_SIZE>0
27146 case SQLITE_FCNTL_MMAP_SIZE: {
27147 i64 newLimit = *(i64*)pArg;
27148 int rc = SQLITE_OK;
@@ -27311,11 +27420,11 @@
27420
27421 /* Update the global lock state and do debug tracing */
27422 #ifdef SQLITE_DEBUG
27423 { u16 mask;
27424 OSTRACE(("SHM-LOCK "));
27425 mask = ofst>31 ? 0xffffffff : (1<<(ofst+n)) - (1<<ofst);
27426 if( rc==SQLITE_OK ){
27427 if( lockType==F_UNLCK ){
27428 OSTRACE(("unlock %d ok", ofst));
27429 pShmNode->exclMask &= ~mask;
27430 pShmNode->sharedMask &= ~mask;
@@ -30947,10 +31056,38 @@
31056 #if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
31057 # error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
31058 must be defined."
31059 #endif
31060
31061 /*
31062 ** Define the required Windows SDK version constants if they are not
31063 ** already available.
31064 */
31065 #ifndef NTDDI_WIN8
31066 # define NTDDI_WIN8 0x06020000
31067 #endif
31068
31069 #ifndef NTDDI_WINBLUE
31070 # define NTDDI_WINBLUE 0x06030000
31071 #endif
31072
31073 /*
31074 ** Check if the GetVersionEx[AW] functions should be considered deprecated
31075 ** and avoid using them in that case. It should be noted here that if the
31076 ** value of the SQLITE_WIN32_GETVERSIONEX pre-processor macro is zero
31077 ** (whether via this block or via being manually specified), that implies
31078 ** the underlying operating system will always be based on the Windows NT
31079 ** Kernel.
31080 */
31081 #ifndef SQLITE_WIN32_GETVERSIONEX
31082 # if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE
31083 # define SQLITE_WIN32_GETVERSIONEX 0
31084 # else
31085 # define SQLITE_WIN32_GETVERSIONEX 1
31086 # endif
31087 #endif
31088
31089 /*
31090 ** This constant should already be defined (in the "WinDef.h" SDK file).
31091 */
31092 #ifndef MAX_PATH
31093 # define MAX_PATH (260)
@@ -31582,20 +31719,22 @@
31719 { "GetTickCount", (SYSCALL)0, 0 },
31720 #endif
31721
31722 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
31723
31724 #if defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_GETVERSIONEX) && \
31725 SQLITE_WIN32_GETVERSIONEX
31726 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
31727 #else
31728 { "GetVersionExA", (SYSCALL)0, 0 },
31729 #endif
31730
31731 #define osGetVersionExA ((BOOL(WINAPI*)( \
31732 LPOSVERSIONINFOA))aSyscall[34].pCurrent)
31733
31734 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
31735 defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
31736 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
31737 #else
31738 { "GetVersionExW", (SYSCALL)0, 0 },
31739 #endif
31740
@@ -32148,15 +32287,14 @@
32287 ** API as long as we don't call it when running Win95/98/ME. A call to
32288 ** this routine is used to determine if the host is Win95/98/ME or
32289 ** WinNT/2K/XP so that we will know whether or not we can safely call
32290 ** the LockFileEx() API.
32291 */
 
 
 
32292
32293 #if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX
32294 # define osIsNT() (1)
32295 #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
32296 # define osIsNT() (1)
32297 #elif !defined(SQLITE_WIN32_HAS_WIDE)
32298 # define osIsNT() (0)
32299 #else
32300 static int osIsNT(void){
@@ -32289,18 +32427,24 @@
32427 assert( pWinMemData->magic1==WINMEM_MAGIC1 );
32428 assert( pWinMemData->magic2==WINMEM_MAGIC2 );
32429
32430 #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
32431 if( !pWinMemData->hHeap ){
32432 DWORD dwInitialSize = SQLITE_WIN32_HEAP_INIT_SIZE;
32433 DWORD dwMaximumSize = (DWORD)sqlite3GlobalConfig.nHeap;
32434 if( dwMaximumSize==0 ){
32435 dwMaximumSize = SQLITE_WIN32_HEAP_MAX_SIZE;
32436 }else if( dwInitialSize>dwMaximumSize ){
32437 dwInitialSize = dwMaximumSize;
32438 }
32439 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
32440 dwInitialSize, dwMaximumSize);
 
32441 if( !pWinMemData->hHeap ){
32442 sqlite3_log(SQLITE_NOMEM,
32443 "failed to HeapCreate (%lu), flags=%u, initSize=%lu, maxSize=%lu",
32444 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, dwInitialSize,
32445 dwMaximumSize);
32446 return SQLITE_NOMEM;
32447 }
32448 pWinMemData->bOwned = TRUE;
32449 assert( pWinMemData->bOwned );
32450 }
@@ -33972,11 +34116,11 @@
34116 winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
34117 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34118 return SQLITE_OK;
34119 }
34120 case SQLITE_FCNTL_VFSNAME: {
34121 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
34122 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34123 return SQLITE_OK;
34124 }
34125 case SQLITE_FCNTL_WIN32_AV_RETRY: {
34126 int *a = (int*)pArg;
@@ -34956,11 +35100,11 @@
35100 **
35101 ** This division contains the implementation of methods on the
35102 ** sqlite3_vfs object.
35103 */
35104
35105 #if defined(__CYGWIN__)
35106 /*
35107 ** Convert a filename from whatever the underlying operating system
35108 ** supports for filenames into UTF-8. Space to hold the result is
35109 ** obtained from malloc and must be freed by the calling function.
35110 */
@@ -35132,27 +35276,21 @@
35276 if( winIsDir(zConverted) ){
35277 /* At this point, we know the candidate directory exists and should
35278 ** be used. However, we may need to convert the string containing
35279 ** its name into UTF-8 (i.e. if it is UTF-16 right now).
35280 */
35281 char *zUtf8 = winConvertToUtf8Filename(zConverted);
35282 if( !zUtf8 ){
35283 sqlite3_free(zConverted);
35284 sqlite3_free(zBuf);
35285 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
35286 return SQLITE_IOERR_NOMEM;
35287 }
35288 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
35289 sqlite3_free(zUtf8);
35290 sqlite3_free(zConverted);
35291 break;
 
 
 
 
 
 
35292 }
35293 sqlite3_free(zConverted);
35294 }
35295 }
35296 }
@@ -35833,23 +35971,47 @@
35971 */
35972 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
35973 if( !zOut ){
35974 return SQLITE_IOERR_NOMEM;
35975 }
35976 if( cygwin_conv_path(
35977 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
35978 CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){
35979 sqlite3_free(zOut);
35980 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
35981 "winFullPathname1", zRelative);
35982 }else{
35983 char *zUtf8 = winConvertToUtf8Filename(zOut);
35984 if( !zUtf8 ){
35985 sqlite3_free(zOut);
35986 return SQLITE_IOERR_NOMEM;
35987 }
35988 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
35989 sqlite3_data_directory, winGetDirSep(), zUtf8);
35990 sqlite3_free(zUtf8);
35991 sqlite3_free(zOut);
35992 }
 
 
 
35993 }else{
35994 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
35995 if( !zOut ){
35996 return SQLITE_IOERR_NOMEM;
35997 }
35998 if( cygwin_conv_path(
35999 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A),
36000 zRelative, zOut, pVfs->mxPathname+1)<0 ){
36001 sqlite3_free(zOut);
36002 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
36003 "winFullPathname2", zRelative);
36004 }else{
36005 char *zUtf8 = winConvertToUtf8Filename(zOut);
36006 if( !zUtf8 ){
36007 sqlite3_free(zOut);
36008 return SQLITE_IOERR_NOMEM;
36009 }
36010 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
36011 sqlite3_free(zUtf8);
36012 sqlite3_free(zOut);
36013 }
36014 }
36015 return SQLITE_OK;
36016 #endif
36017
@@ -43770,10 +43932,34 @@
43932 *ppPager = pPager;
43933 return SQLITE_OK;
43934 }
43935
43936
43937 /* Verify that the database file has not be deleted or renamed out from
43938 ** under the pager. Return SQLITE_OK if the database is still were it ought
43939 ** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error
43940 ** code from sqlite3OsAccess()) if the database has gone missing.
43941 */
43942 static int databaseIsUnmoved(Pager *pPager){
43943 int bHasMoved = 0;
43944 int rc;
43945
43946 if( pPager->tempFile ) return SQLITE_OK;
43947 if( pPager->dbSize==0 ) return SQLITE_OK;
43948 assert( pPager->zFilename && pPager->zFilename[0] );
43949 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved);
43950 if( rc==SQLITE_NOTFOUND ){
43951 /* If the HAS_MOVED file-control is unimplemented, assume that the file
43952 ** has not been moved. That is the historical behavior of SQLite: prior to
43953 ** version 3.8.3, it never checked */
43954 rc = SQLITE_OK;
43955 }else if( rc==SQLITE_OK && bHasMoved ){
43956 rc = SQLITE_READONLY_DBMOVED;
43957 }
43958 return rc;
43959 }
43960
43961
43962 /*
43963 ** This function is called after transitioning from PAGER_UNLOCK to
43964 ** PAGER_SHARED state. It tests if there is a hot journal present in
43965 ** the file-system for the given pager. A hot journal is one that
@@ -44241,11 +44427,11 @@
44427 if( bMmapOk && pagerUseWal(pPager) ){
44428 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
44429 if( rc!=SQLITE_OK ) goto pager_acquire_err;
44430 }
44431
44432 if( bMmapOk && iFrame==0 ){
44433 void *pData = 0;
44434
44435 rc = sqlite3OsFetch(pPager->fd,
44436 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
44437 );
@@ -44446,17 +44632,23 @@
44632 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
44633 (pPager->tempFile ?
44634 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
44635 (SQLITE_OPEN_MAIN_JOURNAL)
44636 );
44637
44638 /* Verify that the database still has the same name as it did when
44639 ** it was originally opened. */
44640 rc = databaseIsUnmoved(pPager);
44641 if( rc==SQLITE_OK ){
44642 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
44643 rc = sqlite3JournalOpen(
44644 pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44645 );
44646 #else
44647 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44648 #endif
44649 }
44650 }
44651 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
44652 }
44653
44654
@@ -44586,18 +44778,12 @@
44778 assert( pPager->eState==PAGER_WRITER_LOCKED
44779 || pPager->eState==PAGER_WRITER_CACHEMOD
44780 || pPager->eState==PAGER_WRITER_DBMOD
44781 );
44782 assert( assert_pager_state(pPager) );
44783 assert( pPager->errCode==0 );
44784 assert( pPager->readOnly==0 );
 
 
 
 
 
 
44785
44786 CHECK_PAGE(pPg);
44787
44788 /* The journal file needs to be opened. Higher level routines have already
44789 ** obtained the necessary locks to begin the write-transaction, but the
@@ -44722,23 +44908,23 @@
44908 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
44909 int rc = SQLITE_OK;
44910
44911 PgHdr *pPg = pDbPage;
44912 Pager *pPager = pPg->pPager;
 
44913
44914 assert( (pPg->flags & PGHDR_MMAP)==0 );
44915 assert( pPager->eState>=PAGER_WRITER_LOCKED );
44916 assert( pPager->eState!=PAGER_ERROR );
44917 assert( assert_pager_state(pPager) );
44918
44919 if( pPager->sectorSize > (u32)pPager->pageSize ){
44920 Pgno nPageCount; /* Total number of pages in database file */
44921 Pgno pg1; /* First page of the sector pPg is located on. */
44922 int nPage = 0; /* Number of pages starting at pg1 to journal */
44923 int ii; /* Loop counter */
44924 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
44925 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
44926
44927 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
44928 ** a journal header to be written between the pages journaled by
44929 ** this function.
44930 */
@@ -50914,10 +51100,14 @@
51100 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
51101 pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
51102 );
51103 if( pIdxKey==0 ) return SQLITE_NOMEM;
51104 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
51105 if( pIdxKey->nField==0 ){
51106 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
51107 return SQLITE_CORRUPT_BKPT;
51108 }
51109 }else{
51110 pIdxKey = 0;
51111 }
51112 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
51113 if( pFree ){
@@ -51868,11 +52058,11 @@
52058
52059 if( pgno>btreePagecount(pBt) ){
52060 rc = SQLITE_CORRUPT_BKPT;
52061 }else{
52062 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
52063 if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
52064 rc = btreeInitPage(*ppPage);
52065 if( rc!=SQLITE_OK ){
52066 releasePage(*ppPage);
52067 }
52068 }
@@ -54408,14 +54598,14 @@
54598 }
54599
54600 /*
54601 ** Return a pointer to payload information from the entry that the
54602 ** pCur cursor is pointing to. The pointer is to the beginning of
54603 ** the key if index btrees (pPage->intKey==0) and is the data for
54604 ** table btrees (pPage->intKey==1). The number of bytes of available
54605 ** key/data is written into *pAmt. If *pAmt==0, then the value
54606 ** returned will not be a valid pointer.
54607 **
54608 ** This routine is an optimization. It is common for the entire key
54609 ** and data to fit on the local page and for there to be no overflow
54610 ** pages. When that is so, this routine can be used to access the
54611 ** key and data without making a copy. If the key and/or data spills
@@ -54424,45 +54614,25 @@
54614 **
54615 ** The pointer returned by this routine looks directly into the cached
54616 ** page of the database. The data might change or move the next time
54617 ** any btree routine is called.
54618 */
54619 static const void *fetchPayload(
54620 BtCursor *pCur, /* Cursor pointing to entry to read from */
54621 u32 *pAmt /* Write the number of available bytes here */
 
54622 ){
 
 
 
 
 
54623 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
54624 assert( pCur->eState==CURSOR_VALID );
54625 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54626 assert( cursorHoldsMutex(pCur) );
54627 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
54628 if( pCur->info.nSize==0 ){
 
54629 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
54630 &pCur->info);
54631 }
54632 *pAmt = pCur->info.nLocal;
54633 return (void*)(pCur->info.pCell + pCur->info.nHeader);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54634 }
54635
54636
54637 /*
54638 ** For the entry that cursor pCur is point to, return as
@@ -54476,27 +54646,15 @@
54646 ** this routine.
54647 **
54648 ** These routines is used to get quick access to key and data
54649 ** in the common case where no overflow pages are used.
54650 */
54651 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
54652 return fetchPayload(pCur, pAmt);
54653 }
54654 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
54655 return fetchPayload(pCur, pAmt);
 
 
 
 
 
 
 
 
 
 
 
 
54656 }
54657
54658
54659 /*
54660 ** Move the cursor down to a new child page. The newPgno argument is the
@@ -54611,12 +54769,10 @@
54769 ** b-tree).
54770 */
54771 static int moveToRoot(BtCursor *pCur){
54772 MemPage *pRoot;
54773 int rc = SQLITE_OK;
 
 
54774
54775 assert( cursorHoldsMutex(pCur) );
54776 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
54777 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
54778 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54627,20 +54783,16 @@
54783 }
54784 sqlite3BtreeClearCursor(pCur);
54785 }
54786
54787 if( pCur->iPage>=0 ){
54788 while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]);
 
 
 
 
54789 }else if( pCur->pgnoRoot==0 ){
54790 pCur->eState = CURSOR_INVALID;
54791 return SQLITE_OK;
54792 }else{
54793 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
54794 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
54795 if( rc!=SQLITE_OK ){
54796 pCur->eState = CURSOR_INVALID;
54797 return rc;
54798 }
@@ -54669,18 +54821,20 @@
54821 pCur->aiIdx[0] = 0;
54822 pCur->info.nSize = 0;
54823 pCur->atLast = 0;
54824 pCur->validNKey = 0;
54825
54826 if( pRoot->nCell>0 ){
54827 pCur->eState = CURSOR_VALID;
54828 }else if( !pRoot->leaf ){
54829 Pgno subpage;
54830 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
54831 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
54832 pCur->eState = CURSOR_VALID;
54833 rc = moveToChild(pCur, subpage);
54834 }else{
54835 pCur->eState = CURSOR_INVALID;
54836 }
54837 return rc;
54838 }
54839
54840 /*
@@ -54867,14 +55021,14 @@
55021 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
55022 return SQLITE_OK;
55023 }
55024 assert( pCur->apPage[0]->intKey || pIdxKey );
55025 for(;;){
55026 int lwr, upr, idx, c;
55027 Pgno chldPg;
55028 MemPage *pPage = pCur->apPage[pCur->iPage];
55029 u8 *pCell; /* Pointer to current cell in pPage */
55030
55031 /* pPage->nCell must be greater than zero. If this is the root-page
55032 ** the cursor would have been INVALID above and this for(;;) loop
55033 ** not run. If this is not the root-page, then the moveToChild() routine
55034 ** would have already detected db corruption. Similarly, pPage must
@@ -54882,59 +55036,68 @@
55036 ** a moveToChild() or moveToRoot() call would have detected corruption. */
55037 assert( pPage->nCell>0 );
55038 assert( pPage->intKey==(pIdxKey==0) );
55039 lwr = 0;
55040 upr = pPage->nCell-1;
55041 assert( biasRight==0 || biasRight==1 );
55042 idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
55043 pCur->aiIdx[pCur->iPage] = (u16)idx;
55044 if( pPage->intKey ){
55045 for(;;){
 
 
 
 
 
 
 
55046 i64 nCellKey;
55047 pCell = findCell(pPage, idx) + pPage->childPtrSize;
55048 if( pPage->hasData ){
55049 while( 0x80 <= *(pCell++) ){
55050 if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
55051 }
55052 }
55053 getVarint(pCell, (u64*)&nCellKey);
55054 if( nCellKey<intKey ){
55055 lwr = idx+1;
55056 if( lwr>upr ){ c = -1; break; }
55057 }else if( nCellKey>intKey ){
55058 upr = idx-1;
55059 if( lwr>upr ){ c = +1; break; }
55060 }else{
55061 assert( nCellKey==intKey );
55062 pCur->validNKey = 1;
55063 pCur->info.nKey = nCellKey;
55064 pCur->aiIdx[pCur->iPage] = (u16)idx;
55065 if( !pPage->leaf ){
55066 lwr = idx;
55067 goto moveto_next_layer;
55068 }else{
55069 *pRes = 0;
55070 rc = SQLITE_OK;
55071 goto moveto_finish;
55072 }
55073 }
55074 assert( lwr+upr>=0 );
55075 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
55076 }
55077 }else{
55078 for(;;){
55079 int nCell;
55080 pCell = findCell(pPage, idx) + pPage->childPtrSize;
55081
55082 /* The maximum supported page-size is 65536 bytes. This means that
55083 ** the maximum number of record bytes stored on an index B-Tree
55084 ** page is less than 16384 bytes and may be stored as a 2-byte
55085 ** varint. This information is used to attempt to avoid parsing
55086 ** the entire cell by checking for the cases where the record is
55087 ** stored entirely within the b-tree page by inspecting the first
55088 ** 2 bytes of the cell.
55089 */
55090 nCell = pCell[0];
55091 if( nCell<=pPage->max1bytePayload ){
 
 
55092 /* This branch runs if the record-size field of the cell is a
55093 ** single byte varint and the record fits entirely on the main
55094 ** b-tree page. */
55095 testcase( pCell+nCell+1==pPage->aDataEnd );
55096 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55097 }else if( !(pCell[1] & 0x80)
55098 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
 
55099 ){
55100 /* The record-size field is a 2 byte varint and the record
55101 ** fits entirely on the main b-tree page. */
55102 testcase( pCell+nCell+2==pPage->aDataEnd );
55103 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -54950,61 +55113,57 @@
55113 pCellKey = sqlite3Malloc( nCell );
55114 if( pCellKey==0 ){
55115 rc = SQLITE_NOMEM;
55116 goto moveto_finish;
55117 }
55118 pCur->aiIdx[pCur->iPage] = (u16)idx;
55119 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
55120 if( rc ){
55121 sqlite3_free(pCellKey);
55122 goto moveto_finish;
55123 }
55124 c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
55125 sqlite3_free(pCellKey);
55126 }
55127 if( c<0 ){
55128 lwr = idx+1;
55129 }else if( c>0 ){
55130 upr = idx-1;
 
55131 }else{
55132 assert( c==0 );
55133 *pRes = 0;
55134 rc = SQLITE_OK;
55135 pCur->aiIdx[pCur->iPage] = (u16)idx;
55136 goto moveto_finish;
55137 }
55138 if( lwr>upr ) break;
55139 assert( lwr+upr>=0 );
55140 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
55141 }
 
 
 
 
 
 
55142 }
55143 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
55144 assert( pPage->isInit );
55145 if( pPage->leaf ){
 
 
 
 
 
 
 
55146 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
55147 pCur->aiIdx[pCur->iPage] = (u16)idx;
55148 *pRes = c;
55149 rc = SQLITE_OK;
55150 goto moveto_finish;
55151 }
55152 moveto_next_layer:
55153 if( lwr>=pPage->nCell ){
55154 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
55155 }else{
55156 chldPg = get4byte(findCell(pPage, lwr));
55157 }
55158 pCur->aiIdx[pCur->iPage] = (u16)lwr;
 
 
55159 rc = moveToChild(pCur, chldPg);
55160 if( rc ) break;
55161 }
55162 moveto_finish:
55163 pCur->info.nSize = 0;
55164 pCur->validNKey = 0;
55165 return rc;
55166 }
55167
55168
55169 /*
@@ -55758,11 +55917,11 @@
55917 nHeader = 0;
55918 if( !pPage->leaf ){
55919 nHeader += 4;
55920 }
55921 if( pPage->hasData ){
55922 nHeader += putVarint32(&pCell[nHeader], nData+nZero);
55923 }else{
55924 nData = nZero = 0;
55925 }
55926 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
55927 btreeParseCellPtr(pPage, pCell, &info);
@@ -55886,11 +56045,10 @@
56045 */
56046 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
56047 u32 pc; /* Offset to cell content of cell being deleted */
56048 u8 *data; /* pPage->aData */
56049 u8 *ptr; /* Used to move bytes around within data[] */
 
56050 int rc; /* The return code */
56051 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
56052
56053 if( *pRC ) return;
56054
@@ -55911,17 +56069,12 @@
56069 rc = freeSpace(pPage, pc, sz);
56070 if( rc ){
56071 *pRC = rc;
56072 return;
56073 }
 
 
 
 
 
 
56074 pPage->nCell--;
56075 memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
56076 put2byte(&data[hdr+3], pPage->nCell);
56077 pPage->nFree += 2;
56078 }
56079
56080 /*
@@ -55954,13 +56107,10 @@
56107 int j; /* Loop counter */
56108 int end; /* First byte past the last cell pointer in data[] */
56109 int ins; /* Index in data[] where new cell pointer is inserted */
56110 int cellOffset; /* Address of first cell pointer in data[] */
56111 u8 *data; /* The content of the whole page */
 
 
 
56112 int nSkip = (iChild ? 4 : 0);
56113
56114 if( *pRC ) return;
56115
56116 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56007,17 +56157,11 @@
56157 pPage->nFree -= (u16)(2 + sz);
56158 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
56159 if( iChild ){
56160 put4byte(&data[idx], iChild);
56161 }
56162 memmove(&data[ins+2], &data[ins], end-ins);
 
 
 
 
 
 
56163 put2byte(&data[ins], idx);
56164 put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
56165 #ifndef SQLITE_OMIT_AUTOVACUUM
56166 if( pPage->pBt->autoVacuum ){
56167 /* The cell may contain a pointer to an overflow page. If so, write
@@ -57975,11 +58119,11 @@
58119 va_start(ap, zFormat);
58120 if( pCheck->errMsg.nChar ){
58121 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
58122 }
58123 if( zMsg1 ){
58124 sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
58125 }
58126 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
58127 va_end(ap);
58128 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
58129 pCheck->mallocFailed = 1;
@@ -58839,10 +58983,11 @@
58983 if( sqlite3OpenTempDatabase(pParse) ){
58984 sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
58985 rc = SQLITE_ERROR;
58986 }
58987 sqlite3DbFree(pErrorDb, pParse->zErrMsg);
58988 sqlite3ParserReset(pParse);
58989 sqlite3StackFree(pErrorDb, pParse);
58990 }
58991 if( rc ){
58992 return 0;
58993 }
@@ -59550,61 +59695,59 @@
59695 #endif
59696 }
59697
59698 /*
59699 ** Make sure pMem->z points to a writable allocation of at least
59700 ** min(n,32) bytes.
59701 **
59702 ** If the bPreserve argument is true, then copy of the content of
59703 ** pMem->z into the new allocation. pMem must be either a string or
59704 ** blob if bPreserve is true. If bPreserve is false, any prior content
59705 ** in pMem->z is discarded.
59706 */
59707 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
 
 
 
 
59708 assert( 1 >=
59709 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
59710 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
59711 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
59712 ((pMem->flags&MEM_Static) ? 1 : 0)
59713 );
59714 assert( (pMem->flags&MEM_RowSet)==0 );
59715
59716 /* If the bPreserve flag is set to true, then the memory cell must already
59717 ** contain a valid string or blob value. */
59718 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
59719 testcase( bPreserve && pMem->z==0 );
59720
59721 if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59722 if( n<32 ) n = 32;
59723 if( bPreserve && pMem->z==pMem->zMalloc ){
59724 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59725 bPreserve = 0;
59726 }else{
59727 sqlite3DbFree(pMem->db, pMem->zMalloc);
59728 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
59729 }
59730 if( pMem->zMalloc==0 ){
59731 sqlite3VdbeMemRelease(pMem);
59732 pMem->flags = MEM_Null;
59733 return SQLITE_NOMEM;
59734 }
59735 }
59736
59737 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
59738 memcpy(pMem->zMalloc, pMem->z, pMem->n);
59739 }
59740 if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
59741 assert( pMem->xDel!=SQLITE_DYNAMIC );
59742 pMem->xDel((void *)(pMem->z));
59743 }
59744
59745 pMem->z = pMem->zMalloc;
59746 pMem->flags &= ~(MEM_Ephem|MEM_Static);
 
 
 
 
59747 pMem->xDel = 0;
59748 return SQLITE_OK;
59749 }
59750
59751 /*
59752 ** Make the given Mem object MEM_Dyn. In other words, make it so
59753 ** that any TEXT or BLOB content is stored in memory obtained from
@@ -59786,27 +59929,22 @@
59929 ** inconsistent state, for example with (Mem.z==0) and
59930 ** (Mem.type==SQLITE_TEXT).
59931 */
59932 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
59933 VdbeMemRelease(p);
59934 if( p->zMalloc ){
59935 sqlite3DbFree(p->db, p->zMalloc);
59936 p->zMalloc = 0;
59937 }
59938 p->z = 0;
59939 assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */
 
59940 }
59941
59942 /*
59943 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
59944 ** If the double is out of range of a 64-bit signed integer then
59945 ** return the closest available 64-bit signed integer.
 
 
 
 
 
 
 
59946 */
59947 static i64 doubleToInt64(double r){
59948 #ifdef SQLITE_OMIT_FLOATING_POINT
59949 /* When floating-point is omitted, double and int64 are the same thing */
59950 return r;
@@ -59819,18 +59957,14 @@
59957 ** larger than a 32-bit integer constant.
59958 */
59959 static const i64 maxInt = LARGEST_INT64;
59960 static const i64 minInt = SMALLEST_INT64;
59961
59962 if( r<=(double)minInt ){
59963 return minInt;
59964 }else if( r>=(double)maxInt ){
59965 return maxInt;
 
 
 
 
59966 }else{
59967 return (i64)r;
59968 }
59969 #endif
59970 }
@@ -59908,21 +60042,15 @@
60042 ** (2) The integer is neither the largest nor the smallest
60043 ** possible integer (ticket #3922)
60044 **
60045 ** The second and third terms in the following conditional enforces
60046 ** the second condition under the assumption that addition overflow causes
60047 ** values to wrap around.
 
 
60048 */
60049 if( pMem->r==(double)pMem->u.i
60050 && pMem->u.i>SMALLEST_INT64
 
 
 
60051 && pMem->u.i<LARGEST_INT64
 
60052 ){
60053 pMem->flags |= MEM_Int;
60054 }
60055 }
60056
@@ -60387,17 +60515,17 @@
60515 ** If this routine fails for any reason (malloc returns NULL or unable
60516 ** to read from the disk) then the pMem is left in an inconsistent state.
60517 */
60518 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
60519 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
60520 u32 offset, /* Offset from the start of data to return bytes from. */
60521 u32 amt, /* Number of bytes to return. */
60522 int key, /* If true, retrieve from the btree key, not data. */
60523 Mem *pMem /* OUT: Return data in this Mem structure. */
60524 ){
60525 char *zData; /* Data from the btree layer */
60526 u32 available = 0; /* Number of bytes available on the local btree page */
60527 int rc = SQLITE_OK; /* Return code */
60528
60529 assert( sqlite3BtreeCursorIsValid(pCur) );
60530
60531 /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
@@ -60408,11 +60536,11 @@
60536 }else{
60537 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
60538 }
60539 assert( zData!=0 );
60540
60541 if( offset+amt<=available ){
60542 sqlite3VdbeMemRelease(pMem);
60543 pMem->z = &zData[offset];
60544 pMem->flags = MEM_Blob|MEM_Ephem;
60545 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60546 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
@@ -60427,11 +60555,11 @@
60555 pMem->z[amt+1] = 0;
60556 if( rc!=SQLITE_OK ){
60557 sqlite3VdbeMemRelease(pMem);
60558 }
60559 }
60560 pMem->n = (int)amt;
60561
60562 return rc;
60563 }
60564
60565 /* This function is only available internally, it is not part of the
@@ -60524,19 +60652,19 @@
60652 Index *pIdx = p->pIdx; /* Index being probed */
60653 int nByte; /* Bytes of space to allocate */
60654 int i; /* Counter variable */
60655 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
60656
60657 nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
60658 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
60659 if( pRec ){
60660 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
60661 if( pRec->pKeyInfo ){
60662 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60663 assert( pRec->pKeyInfo->enc==ENC(db) );
60664 pRec->flags = UNPACKED_PREFIX_MATCH;
60665 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
60666 for(i=0; i<nCol; i++){
60667 pRec->aMem[i].flags = MEM_Null;
60668 pRec->aMem[i].type = SQLITE_NULL;
60669 pRec->aMem[i].db = db;
60670 }
@@ -60586,20 +60714,11 @@
60714 if( !pExpr ){
60715 *ppVal = 0;
60716 return SQLITE_OK;
60717 }
60718 op = pExpr->op;
 
 
 
 
 
 
 
 
60719 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
 
60720
60721 /* Handle negative integers in a single step. This is needed in the
60722 ** case when the value is -9223372036854775808.
60723 */
60724 if( op==TK_UMINUS
@@ -60736,11 +60855,11 @@
60855 if( aRet==0 ){
60856 sqlite3_result_error_nomem(context);
60857 }else{
60858 aRet[0] = nSerial+1;
60859 sqlite3PutVarint(&aRet[1], iSerial);
60860 sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
60861 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
60862 sqlite3DbFree(db, aRet);
60863 }
60864 }
60865
@@ -60814,14 +60933,13 @@
60933
60934 if( !pExpr ){
60935 pVal = valueNew(db, &alloc);
60936 if( pVal ){
60937 sqlite3VdbeMemSetNull((Mem*)pVal);
 
60938 }
60939 }else if( pExpr->op==TK_VARIABLE
60940 || NEVER(pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
60941 ){
60942 Vdbe *v;
60943 int iBindVar = pExpr->iColumn;
60944 sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
60945 if( (v = pParse->pReprepare)!=0 ){
@@ -60830,20 +60948,17 @@
60948 rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
60949 if( rc==SQLITE_OK ){
60950 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
60951 }
60952 pVal->db = pParse->db;
 
60953 sqlite3VdbeMemStoreType((Mem*)pVal);
60954 }
 
 
60955 }
60956 }else{
60957 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
 
60958 }
60959 *pbOk = (pVal!=0);
60960
60961 assert( pVal==0 || pVal->db==db );
60962 return rc;
60963 }
60964
@@ -60983,19 +61098,10 @@
61098 pA->zSql = pB->zSql;
61099 pB->zSql = zTmp;
61100 pB->isPrepareV2 = pA->isPrepareV2;
61101 }
61102
 
 
 
 
 
 
 
 
 
61103 /*
61104 ** Resize the Vdbe.aOp array so that it is at least one op larger than
61105 ** it was.
61106 **
61107 ** If an out-of-memory error occurs while resizing the array, return
@@ -61367,16 +61473,18 @@
61473 if( n>nMaxArgs ) nMaxArgs = n;
61474 break;
61475 }
61476 #endif
61477 case OP_Next:
61478 case OP_NextIfOpen:
61479 case OP_SorterNext: {
61480 pOp->p4.xAdvance = sqlite3BtreeNext;
61481 pOp->p4type = P4_ADVANCE;
61482 break;
61483 }
61484 case OP_Prev:
61485 case OP_PrevIfOpen: {
61486 pOp->p4.xAdvance = sqlite3BtreePrevious;
61487 pOp->p4type = P4_ADVANCE;
61488 break;
61489 }
61490 }
@@ -61887,11 +61995,11 @@
61995 assert( i<nTemp );
61996 break;
61997 }
61998 case P4_COLLSEQ: {
61999 CollSeq *pColl = pOp->p4.pColl;
62000 sqlite3_snprintf(nTemp, zTemp, "(%.20s)", pColl->zName);
62001 break;
62002 }
62003 case P4_FUNCDEF: {
62004 FuncDef *pDef = pOp->p4.pFunc;
62005 sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
@@ -62320,19 +62428,21 @@
62428 #ifdef SQLITE_DEBUG
62429 /*
62430 ** Print the SQL that was used to generate a VDBE program.
62431 */
62432 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
62433 const char *z = 0;
62434 if( p->zSql ){
62435 z = p->zSql;
62436 }else if( p->nOp>=1 ){
62437 const VdbeOp *pOp = &p->aOp[0];
62438 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62439 z = pOp->p4.z;
62440 while( sqlite3Isspace(*z) ) z++;
62441 }
62442 }
62443 if( z ) printf("SQL: [%s]\n", z);
62444 }
62445 #endif
62446
62447 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
62448 /*
@@ -62586,11 +62696,11 @@
62696 sqlite3BtreeCloseCursor(pCx->pCursor);
62697 }
62698 #ifndef SQLITE_OMIT_VIRTUALTABLE
62699 if( pCx->pVtabCursor ){
62700 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
62701 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
62702 p->inVtabMethod = 1;
62703 pModule->xClose(pVtabCursor);
62704 p->inVtabMethod = 0;
62705 }
62706 #endif
@@ -63570,11 +63680,11 @@
63680 #ifdef SQLITE_TEST
63681 sqlite3_search_count++;
63682 #endif
63683 p->deferredMoveto = 0;
63684 p->cacheStatus = CACHE_STALE;
63685 }else if( p->pCursor ){
63686 int hasMoved;
63687 int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
63688 if( rc ) return rc;
63689 if( hasMoved ){
63690 p->cacheStatus = CACHE_STALE;
@@ -63737,25 +63847,19 @@
63847 /*
63848 ** Write the serialized data blob for the value stored in pMem into
63849 ** buf. It is assumed that the caller has allocated sufficient space.
63850 ** Return the number of bytes written.
63851 **
63852 ** nBuf is the amount of space left in buf[]. The caller is responsible
63853 ** for allocating enough space to buf[] to hold the entire field, exclusive
63854 ** of the pMem->u.nZero bytes for a MEM_Zero value.
 
 
 
 
 
63855 **
63856 ** Return the number of bytes actually written into buf[]. The number
63857 ** of bytes in the zero-filled tail is included in the return value only
63858 ** if those bytes were zeroed in buf[].
63859 */
63860 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
 
63861 u32 len;
63862
63863 /* Integer and Real */
63864 if( serial_type<=7 && serial_type>0 ){
63865 u64 v;
@@ -63766,11 +63870,10 @@
63870 swapMixedEndianFloat(v);
63871 }else{
63872 v = pMem->u.i;
63873 }
63874 len = i = sqlite3VdbeSerialTypeLen(serial_type);
 
63875 while( i-- ){
63876 buf[i] = (u8)(v&0xFF);
63877 v >>= 8;
63878 }
63879 return len;
@@ -63778,21 +63881,12 @@
63881
63882 /* String or blob */
63883 if( serial_type>=12 ){
63884 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
63885 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
 
63886 len = pMem->n;
63887 memcpy(buf, pMem->z, len);
 
 
 
 
 
 
 
 
63888 return len;
63889 }
63890
63891 /* NULL or constants 0 or 1 */
63892 return 0;
@@ -63878,19 +63972,16 @@
63972 pMem->u.i = serial_type-8;
63973 pMem->flags = MEM_Int;
63974 return 0;
63975 }
63976 default: {
63977 static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
63978 u32 len = (serial_type-12)/2;
63979 pMem->z = (char *)buf;
63980 pMem->n = len;
63981 pMem->xDel = 0;
63982 pMem->flags = aFlag[serial_type&1];
 
 
 
 
63983 return len;
63984 }
63985 }
63986 return 0;
63987 }
@@ -64025,13 +64116,15 @@
64116 */
64117 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
64118
64119 idx1 = getVarint32(aKey1, szHdr1);
64120 d1 = szHdr1;
64121 assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
64122 assert( pKeyInfo->aSortOrder!=0 );
64123 assert( pKeyInfo->nField>0 );
64124 assert( idx1<=szHdr1 || CORRUPT_DB );
64125 do{
64126 u32 serial_type1;
64127
64128 /* Read the serial types for the next element in each key. */
64129 idx1 += getVarint32( aKey1+idx1, serial_type1 );
64130
@@ -64060,11 +64153,11 @@
64153 rc = -rc; /* Invert the result for DESC sort order. */
64154 }
64155 return rc;
64156 }
64157 i++;
64158 }while( idx1<szHdr1 && i<pPKey2->nField );
64159
64160 /* No memory allocation is ever used on mem1. Prove this using
64161 ** the following assert(). If the assert() fails, it indicates a
64162 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
64163 */
@@ -64118,11 +64211,11 @@
64211 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64212 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
64213
64214 /* Read in the complete content of the index entry */
64215 memset(&m, 0, sizeof(m));
64216 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
64217 if( rc ){
64218 return rc;
64219 }
64220
64221 /* The index entry must begin with a header size */
@@ -64196,11 +64289,11 @@
64289 if( nCellKey<=0 || nCellKey>0x7fffffff ){
64290 *res = 0;
64291 return SQLITE_CORRUPT_BKPT;
64292 }
64293 memset(&m, 0, sizeof(m));
64294 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
64295 if( rc ){
64296 return rc;
64297 }
64298 assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64299 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
@@ -65715,10 +65808,11 @@
65808 if( db->nVdbeExec>1 ){
65809 while( *zRawSql ){
65810 const char *zStart = zRawSql;
65811 while( *(zRawSql++)!='\n' && *zRawSql );
65812 sqlite3StrAccumAppend(&out, "-- ", 3);
65813 assert( (zRawSql - zStart) > 0 );
65814 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
65815 }
65816 }else{
65817 while( zRawSql[0] ){
65818 n = findNextHostParameter(zRawSql, &nToken);
@@ -66131,13 +66225,12 @@
66225 Mem *pMem = &p->aMem[p->nMem-iCur];
66226
66227 int nByte;
66228 VdbeCursor *pCx = 0;
66229 nByte =
66230 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
66231 (isBtreeCursor?sqlite3BtreeCursorSize():0);
 
66232
66233 assert( iCur<p->nCursor );
66234 if( p->apCsr[iCur] ){
66235 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
66236 p->apCsr[iCur] = 0;
@@ -66145,16 +66238,13 @@
66238 if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
66239 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
66240 memset(pCx, 0, sizeof(VdbeCursor));
66241 pCx->iDb = iDb;
66242 pCx->nField = nField;
 
 
 
66243 if( isBtreeCursor ){
66244 pCx->pCursor = (BtCursor*)
66245 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
66246 sqlite3BtreeCursorZero(pCx->pCursor);
66247 }
66248 }
66249 return pCx;
66250 }
@@ -66336,41 +66426,40 @@
66426
66427 #ifdef SQLITE_DEBUG
66428 /*
66429 ** Print the value of a register for tracing purposes:
66430 */
66431 static void memTracePrint(Mem *p){
66432 if( p->flags & MEM_Invalid ){
66433 printf(" undefined");
66434 }else if( p->flags & MEM_Null ){
66435 printf(" NULL");
66436 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66437 printf(" si:%lld", p->u.i);
66438 }else if( p->flags & MEM_Int ){
66439 printf(" i:%lld", p->u.i);
66440 #ifndef SQLITE_OMIT_FLOATING_POINT
66441 }else if( p->flags & MEM_Real ){
66442 printf(" r:%g", p->r);
66443 #endif
66444 }else if( p->flags & MEM_RowSet ){
66445 printf(" (rowset)");
66446 }else{
66447 char zBuf[200];
66448 sqlite3VdbeMemPrettyPrint(p, zBuf);
66449 printf(" %s", zBuf);
 
66450 }
66451 }
66452 static void registerTrace(int iReg, Mem *p){
66453 printf("REG[%d] = ", iReg);
66454 memTracePrint(p);
66455 printf("\n");
66456 }
66457 #endif
66458
66459 #ifdef SQLITE_DEBUG
66460 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
66461 #else
66462 # define REGISTER_TRACE(R,M)
66463 #endif
66464
66465
@@ -66563,438 +66652,11 @@
66652 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66653 #ifdef VDBE_PROFILE
66654 u64 start; /* CPU clock count at start of opcode */
66655 int origPc; /* Program counter at start of opcode */
66656 #endif
66657 /*** INSERT STACK UNION HERE ***/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66658
66659 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
66660 sqlite3VdbeEnter(p);
66661 if( p->rc==SQLITE_NOMEM ){
66662 /* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67021,17 +66683,32 @@
66683 }
66684 }
66685 #endif
66686 #ifdef SQLITE_DEBUG
66687 sqlite3BeginBenignMalloc();
66688 if( p->pc==0
66689 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
66690 ){
66691 int i;
66692 int once = 1;
66693 sqlite3VdbePrintSql(p);
66694 if( p->db->flags & SQLITE_VdbeListing ){
66695 printf("VDBE Program Listing:\n");
66696 for(i=0; i<p->nOp; i++){
66697 sqlite3VdbePrintOp(stdout, i, &aOp[i]);
66698 }
66699 }
66700 if( p->db->flags & SQLITE_VdbeEQP ){
66701 for(i=0; i<p->nOp; i++){
66702 if( aOp[i].opcode==OP_Explain ){
66703 if( once ) printf("VDBE Query Plan:\n");
66704 printf("%s\n", aOp[i].p4.z);
66705 once = 0;
66706 }
66707 }
66708 }
66709 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
66710 }
66711 sqlite3EndBenignMalloc();
66712 #endif
66713 for(pc=p->pc; rc==SQLITE_OK; pc++){
66714 assert( pc>=0 && pc<p->nOp );
@@ -67044,16 +66721,12 @@
66721 pOp = &aOp[pc];
66722
66723 /* Only allow tracing if SQLITE_DEBUG is defined.
66724 */
66725 #ifdef SQLITE_DEBUG
66726 if( db->flags & SQLITE_VdbeTrace ){
66727 sqlite3VdbePrintOp(stdout, pc, pOp);
 
 
 
 
66728 }
66729 #endif
66730
66731
66732 /* Check to see if we need to simulate an interrupt. This only happens
@@ -67180,19 +66853,16 @@
66853 ** sqlite3VdbeExec() or since last time the progress callback was called).
66854 ** If the progress callback returns non-zero, exit the virtual machine with
66855 ** a return code SQLITE_ABORT.
66856 */
66857 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
66858 assert( db->nProgressOps!=0 );
66859 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
66860 if( db->xProgress(db->pProgressArg) ){
66861 rc = SQLITE_INTERRUPT;
66862 goto vdbe_error_halt;
66863 }
 
 
 
66864 }
66865 #endif
66866
66867 break;
66868 }
@@ -67228,20 +66898,18 @@
66898 /* Opcode: Yield P1 * * * *
66899 **
66900 ** Swap the program counter with the value in register P1.
66901 */
66902 case OP_Yield: { /* in1 */
 
66903 int pcDest;
 
66904 pIn1 = &aMem[pOp->p1];
66905 assert( (pIn1->flags & MEM_Dyn)==0 );
66906 pIn1->flags = MEM_Int;
66907 pcDest = (int)pIn1->u.i;
66908 pIn1->u.i = pc;
66909 REGISTER_TRACE(pOp->p1, pIn1);
66910 pc = pcDest;
66911 break;
66912 }
66913
66914 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
66915 ** Synopsis: if r[P3] null then halt
@@ -67286,14 +66954,12 @@
66954 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
66955 ** every program. So a jump past the last instruction of the program
66956 ** is the same as executing Halt.
66957 */
66958 case OP_Halt: {
 
66959 const char *zType;
66960 const char *zLogFmt;
 
66961
66962 if( pOp->p1==SQLITE_OK && p->pFrame ){
66963 /* Halt the sub-program. Return control to the parent frame. */
66964 VdbeFrame *pFrame = p->pFrame;
66965 p->pFrame = pFrame->pParent;
@@ -67300,11 +66966,11 @@
66966 p->nFrame--;
66967 sqlite3VdbeSetChanges(db, p->nChange);
66968 pc = sqlite3VdbeFrameRestore(pFrame);
66969 lastRowid = db->lastRowid;
66970 if( pOp->p2==OE_Ignore ){
66971 /* Instruction pc is the OP_Program that invoked the sub-program
66972 ** currently being halted. If the p2 instruction of this OP_Halt
66973 ** instruction is set to OE_Ignore, then the sub-program is throwing
66974 ** an IGNORE exception. In this case jump to the address specified
66975 ** as the p2 of the calling OP_Program. */
66976 pc = p->aOp[pc].p2-1;
@@ -67323,25 +66989,25 @@
66989 assert( pOp->p5>=1 && pOp->p5<=4 );
66990 testcase( pOp->p5==1 );
66991 testcase( pOp->p5==2 );
66992 testcase( pOp->p5==3 );
66993 testcase( pOp->p5==4 );
66994 zType = azType[pOp->p5-1];
66995 }else{
66996 zType = 0;
66997 }
66998 assert( zType!=0 || pOp->p4.z!=0 );
66999 zLogFmt = "abort at %d in [%s]: %s";
67000 if( zType && pOp->p4.z ){
67001 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67002 zType, pOp->p4.z);
67003 }else if( pOp->p4.z ){
67004 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67005 }else{
67006 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
67007 }
67008 sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
67009 }
67010 rc = sqlite3VdbeHalt(p);
67011 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67012 if( rc==SQLITE_BUSY ){
67013 p->rc = rc = SQLITE_BUSY;
@@ -67451,23 +67117,21 @@
67117 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67118 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67119 ** OP_Ne or OP_Eq.
67120 */
67121 case OP_Null: { /* out2-prerelease */
 
67122 int cnt;
67123 u16 nullFlag;
67124 cnt = pOp->p3-pOp->p2;
 
67125 assert( pOp->p3<=(p->nMem-p->nCursor) );
67126 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67127 while( cnt>0 ){
67128 pOut++;
67129 memAboutToChange(p, pOut);
67130 VdbeMemRelease(pOut);
67131 pOut->flags = nullFlag;
67132 cnt--;
67133 }
67134 break;
67135 }
67136
67137
@@ -67492,21 +67156,19 @@
67156 **
67157 ** If the parameter is named, then its name appears in P4 and P3==1.
67158 ** The P4 value is used by sqlite3_bind_parameter_name().
67159 */
67160 case OP_Variable: { /* out2-prerelease */
 
67161 Mem *pVar; /* Value being transferred */
 
67162
67163 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67164 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67165 pVar = &p->aVar[pOp->p1 - 1];
67166 if( sqlite3VdbeMemTooBig(pVar) ){
67167 goto too_big;
67168 }
67169 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
67170 UPDATE_MAX_BLOBSIZE(pOut);
67171 break;
67172 }
67173
67174 /* Opcode: Move P1 P2 P3 * *
@@ -67516,43 +67178,41 @@
67178 ** registers P2..P2+P3. Registers P1..P1+P3 are
67179 ** left holding a NULL. It is an error for register ranges
67180 ** P1..P1+P3 and P2..P2+P3 to overlap.
67181 */
67182 case OP_Move: {
 
67183 char *zMalloc; /* Holding variable for allocated memory */
67184 int n; /* Number of registers left to copy */
67185 int p1; /* Register to copy from */
67186 int p2; /* Register to copy to */
67187
67188 n = pOp->p3;
67189 p1 = pOp->p1;
67190 p2 = pOp->p2;
67191 assert( n>=0 && p1>0 && p2>0 );
67192 assert( p1+n<=p2 || p2+n<=p1 );
67193
67194 pIn1 = &aMem[p1];
67195 pOut = &aMem[p2];
67196 do{
 
67197 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67198 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67199 assert( memIsValid(pIn1) );
67200 memAboutToChange(p, pOut);
67201 zMalloc = pOut->zMalloc;
67202 pOut->zMalloc = 0;
67203 sqlite3VdbeMemMove(pOut, pIn1);
67204 #ifdef SQLITE_DEBUG
67205 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
67206 pOut->pScopyFrom += p1 - pOp->p2;
67207 }
67208 #endif
67209 pIn1->zMalloc = zMalloc;
67210 REGISTER_TRACE(p2++, pOut);
67211 pIn1++;
67212 pOut++;
67213 }while( n-- );
67214 break;
67215 }
67216
67217 /* Opcode: Copy P1 P2 P3 * *
67218 ** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67561,26 +67221,24 @@
67221 **
67222 ** This instruction makes a deep copy of the value. A duplicate
67223 ** is made of any string or blob constant. See also OP_SCopy.
67224 */
67225 case OP_Copy: {
 
67226 int n;
 
67227
67228 n = pOp->p3;
67229 pIn1 = &aMem[pOp->p1];
67230 pOut = &aMem[pOp->p2];
67231 assert( pOut!=pIn1 );
67232 while( 1 ){
67233 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67234 Deephemeralize(pOut);
67235 #ifdef SQLITE_DEBUG
67236 pOut->pScopyFrom = 0;
67237 #endif
67238 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
67239 if( (n--)==0 ) break;
67240 pOut++;
67241 pIn1++;
67242 }
67243 break;
67244 }
@@ -67617,17 +67275,27 @@
67275 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67276 ** structure to provide access to the top P1 values as the result
67277 ** row.
67278 */
67279 case OP_ResultRow: {
 
67280 Mem *pMem;
67281 int i;
 
67282 assert( p->nResColumn==pOp->p2 );
67283 assert( pOp->p1>0 );
67284 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67285
67286 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67287 /* Run the progress counter just before returning.
67288 */
67289 if( db->xProgress!=0
67290 && nVmStep>=nProgressLimit
67291 && db->xProgress(db->pProgressArg)!=0
67292 ){
67293 rc = SQLITE_INTERRUPT;
67294 goto vdbe_error_halt;
67295 }
67296 #endif
67297
67298 /* If this statement has violated immediate foreign key constraints, do
67299 ** not return the number of rows modified. And do not RELEASE the statement
67300 ** transaction. It needs to be rolled back. */
67301 if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
@@ -67634,12 +67302,12 @@
67302 assert( db->flags&SQLITE_CountRows );
67303 assert( p->usesStmtJournal );
67304 break;
67305 }
67306
67307 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67308 ** DML statements invoke this opcode to return the number of rows
67309 ** modified to the user. This is the only way that a VM that
67310 ** opens a statement transaction may invoke this opcode.
67311 **
67312 ** In case this is such a statement, close any statement transaction
67313 ** opened by this VM before returning control to the user. This is to
@@ -67662,19 +67330,19 @@
67330
67331 /* Make sure the results of the current row are \000 terminated
67332 ** and have an assigned type. The results are de-ephemeralized as
67333 ** a side effect.
67334 */
67335 pMem = p->pResultSet = &aMem[pOp->p1];
67336 for(i=0; i<pOp->p2; i++){
67337 assert( memIsValid(&pMem[i]) );
67338 Deephemeralize(&pMem[i]);
67339 assert( (pMem[i].flags & MEM_Ephem)==0
67340 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
67341 sqlite3VdbeMemNulTerminate(&pMem[i]);
67342 sqlite3VdbeMemStoreType(&pMem[i]);
67343 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
67344 }
67345 if( db->mallocFailed ) goto no_mem;
67346
67347 /* Return SQLITE_ROW
67348 */
@@ -67695,13 +67363,11 @@
67363 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67364 ** if P3 is the same register as P2, the implementation is able
67365 ** to avoid a memcpy().
67366 */
67367 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
 
67368 i64 nByte;
 
67369
67370 pIn1 = &aMem[pOp->p1];
67371 pIn2 = &aMem[pOp->p2];
67372 pOut = &aMem[pOp->p3];
67373 assert( pIn1!=pOut );
@@ -67710,26 +67376,26 @@
67376 break;
67377 }
67378 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67379 Stringify(pIn1, encoding);
67380 Stringify(pIn2, encoding);
67381 nByte = pIn1->n + pIn2->n;
67382 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67383 goto too_big;
67384 }
67385 MemSetTypeFlag(pOut, MEM_Str);
67386 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
67387 goto no_mem;
67388 }
67389 if( pOut!=pIn2 ){
67390 memcpy(pOut->z, pIn2->z, pIn2->n);
67391 }
67392 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67393 pOut->z[nByte]=0;
67394 pOut->z[nByte+1] = 0;
67395 pOut->flags |= MEM_Term;
67396 pOut->n = (int)nByte;
67397 pOut->enc = encoding;
67398 UPDATE_MAX_BLOBSIZE(pOut);
67399 break;
67400 }
67401
@@ -67754,103 +67420,101 @@
67420 ** Subtract the value in register P1 from the value in register P2
67421 ** and store the result in register P3.
67422 ** If either input is NULL, the result is NULL.
67423 */
67424 /* Opcode: Divide P1 P2 P3 * *
67425 ** Synopsis: r[P3]=r[P2]/r[P1]
67426 **
67427 ** Divide the value in register P1 by the value in register P2
67428 ** and store the result in register P3 (P3=P2/P1). If the value in
67429 ** register P1 is zero, then the result is NULL. If either input is
67430 ** NULL, the result is NULL.
67431 */
67432 /* Opcode: Remainder P1 P2 P3 * *
67433 ** Synopsis: r[P3]=r[P2]%r[P1]
67434 **
67435 ** Compute the remainder after integer register P2 is divided by
67436 ** register P1 and store the result in register P3.
67437 ** If the value in register P1 is zero the result is NULL.
67438 ** If either operand is NULL, the result is NULL.
67439 */
67440 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67441 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67442 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67443 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67444 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
 
67445 char bIntint; /* Started out as two integer operands */
67446 int flags; /* Combined MEM_* flags from both inputs */
67447 i64 iA; /* Integer value of left operand */
67448 i64 iB; /* Integer value of right operand */
67449 double rA; /* Real value of left operand */
67450 double rB; /* Real value of right operand */
 
67451
67452 pIn1 = &aMem[pOp->p1];
67453 applyNumericAffinity(pIn1);
67454 pIn2 = &aMem[pOp->p2];
67455 applyNumericAffinity(pIn2);
67456 pOut = &aMem[pOp->p3];
67457 flags = pIn1->flags | pIn2->flags;
67458 if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67459 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67460 iA = pIn1->u.i;
67461 iB = pIn2->u.i;
67462 bIntint = 1;
67463 switch( pOp->opcode ){
67464 case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
67465 case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
67466 case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break;
67467 case OP_Divide: {
67468 if( iA==0 ) goto arithmetic_result_is_null;
67469 if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math;
67470 iB /= iA;
67471 break;
67472 }
67473 default: {
67474 if( iA==0 ) goto arithmetic_result_is_null;
67475 if( iA==-1 ) iA = 1;
67476 iB %= iA;
67477 break;
67478 }
67479 }
67480 pOut->u.i = iB;
67481 MemSetTypeFlag(pOut, MEM_Int);
67482 }else{
67483 bIntint = 0;
67484 fp_math:
67485 rA = sqlite3VdbeRealValue(pIn1);
67486 rB = sqlite3VdbeRealValue(pIn2);
67487 switch( pOp->opcode ){
67488 case OP_Add: rB += rA; break;
67489 case OP_Subtract: rB -= rA; break;
67490 case OP_Multiply: rB *= rA; break;
67491 case OP_Divide: {
67492 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67493 if( rA==(double)0 ) goto arithmetic_result_is_null;
67494 rB /= rA;
67495 break;
67496 }
67497 default: {
67498 iA = (i64)rA;
67499 iB = (i64)rB;
67500 if( iA==0 ) goto arithmetic_result_is_null;
67501 if( iA==-1 ) iA = 1;
67502 rB = (double)(iB % iA);
67503 break;
67504 }
67505 }
67506 #ifdef SQLITE_OMIT_FLOATING_POINT
67507 pOut->u.i = rB;
67508 MemSetTypeFlag(pOut, MEM_Int);
67509 #else
67510 if( sqlite3IsNaN(rB) ){
67511 goto arithmetic_result_is_null;
67512 }
67513 pOut->r = rB;
67514 MemSetTypeFlag(pOut, MEM_Real);
67515 if( (flags & MEM_Real)==0 && !bIntint ){
67516 sqlite3VdbeIntegerAffinity(pOut);
67517 }
67518 #endif
67519 }
67520 break;
@@ -67899,85 +67563,83 @@
67563 ** invocation of this opcode.
67564 **
67565 ** See also: AggStep and AggFinal
67566 */
67567 case OP_Function: {
 
67568 int i;
67569 Mem *pArg;
67570 sqlite3_context ctx;
67571 sqlite3_value **apVal;
67572 int n;
 
67573
67574 n = pOp->p5;
67575 apVal = p->apArg;
67576 assert( apVal || n==0 );
67577 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
67578 pOut = &aMem[pOp->p3];
67579 memAboutToChange(p, pOut);
67580
67581 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) );
67582 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
67583 pArg = &aMem[pOp->p2];
67584 for(i=0; i<n; i++, pArg++){
67585 assert( memIsValid(pArg) );
67586 apVal[i] = pArg;
67587 Deephemeralize(pArg);
67588 sqlite3VdbeMemStoreType(pArg);
67589 REGISTER_TRACE(pOp->p2+i, pArg);
67590 }
67591
67592 assert( pOp->p4type==P4_FUNCDEF );
67593 ctx.pFunc = pOp->p4.pFunc;
67594 ctx.iOp = pc;
67595 ctx.pVdbe = p;
 
 
 
 
67596
67597 /* The output cell may already have a buffer allocated. Move
67598 ** the pointer to ctx.s so in case the user-function can use
67599 ** the already allocated buffer instead of allocating a new one.
67600 */
67601 memcpy(&ctx.s, pOut, sizeof(Mem));
67602 pOut->flags = MEM_Null;
67603 pOut->xDel = 0;
67604 pOut->zMalloc = 0;
67605 MemSetTypeFlag(&ctx.s, MEM_Null);
67606
67607 ctx.fErrorOrAux = 0;
67608 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67609 assert( pOp>aOp );
67610 assert( pOp[-1].p4type==P4_COLLSEQ );
67611 assert( pOp[-1].opcode==OP_CollSeq );
67612 ctx.pColl = pOp[-1].p4.pColl;
67613 }
67614 db->lastRowid = lastRowid;
67615 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
67616 lastRowid = db->lastRowid;
67617
67618 if( db->mallocFailed ){
67619 /* Even though a malloc() has failed, the implementation of the
67620 ** user function may have called an sqlite3_result_XXX() function
67621 ** to return a value. The following call releases any resources
67622 ** associated with such a value.
67623 */
67624 sqlite3VdbeMemRelease(&ctx.s);
67625 goto no_mem;
67626 }
67627
67628 /* If the function returned an error, throw an exception */
67629 if( ctx.fErrorOrAux ){
67630 if( ctx.isError ){
67631 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
67632 rc = ctx.isError;
67633 }
67634 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
67635 }
67636
67637 /* Copy the result of the function into register P3 */
67638 sqlite3VdbeChangeEncoding(&ctx.s, encoding);
67639 assert( pOut->flags==MEM_Null );
67640 memcpy(pOut, &ctx.s, sizeof(Mem));
67641 if( sqlite3VdbeMemTooBig(pOut) ){
67642 goto too_big;
67643 }
67644
67645 #if 0
@@ -68025,56 +67687,54 @@
67687 */
67688 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
67689 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
67690 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
67691 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
 
67692 i64 iA;
67693 u64 uA;
67694 i64 iB;
67695 u8 op;
 
67696
67697 pIn1 = &aMem[pOp->p1];
67698 pIn2 = &aMem[pOp->p2];
67699 pOut = &aMem[pOp->p3];
67700 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
67701 sqlite3VdbeMemSetNull(pOut);
67702 break;
67703 }
67704 iA = sqlite3VdbeIntValue(pIn2);
67705 iB = sqlite3VdbeIntValue(pIn1);
67706 op = pOp->opcode;
67707 if( op==OP_BitAnd ){
67708 iA &= iB;
67709 }else if( op==OP_BitOr ){
67710 iA |= iB;
67711 }else if( iB!=0 ){
67712 assert( op==OP_ShiftRight || op==OP_ShiftLeft );
67713
67714 /* If shifting by a negative amount, shift in the other direction */
67715 if( iB<0 ){
67716 assert( OP_ShiftRight==OP_ShiftLeft+1 );
67717 op = 2*OP_ShiftLeft + 1 - op;
67718 iB = iB>(-64) ? -iB : 64;
67719 }
67720
67721 if( iB>=64 ){
67722 iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
67723 }else{
67724 memcpy(&uA, &iA, sizeof(uA));
67725 if( op==OP_ShiftLeft ){
67726 uA <<= iB;
67727 }else{
67728 uA >>= iB;
67729 /* Sign-extend on a right shift of a negative number */
67730 if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
67731 }
67732 memcpy(&iA, &uA, sizeof(iA));
67733 }
67734 }
67735 pOut->u.i = iA;
67736 MemSetTypeFlag(pOut, MEM_Int);
67737 break;
67738 }
67739
67740 /* Opcode: AddImm P1 P2 * * *
@@ -68100,21 +67760,23 @@
67760 ** without data loss, then jump immediately to P2, or if P2==0
67761 ** raise an SQLITE_MISMATCH exception.
67762 */
67763 case OP_MustBeInt: { /* jump, in1 */
67764 pIn1 = &aMem[pOp->p1];
 
67765 if( (pIn1->flags & MEM_Int)==0 ){
67766 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
67767 if( (pIn1->flags & MEM_Int)==0 ){
67768 if( pOp->p2==0 ){
67769 rc = SQLITE_MISMATCH;
67770 goto abort_due_to_error;
67771 }else{
67772 pc = pOp->p2 - 1;
67773 break;
67774 }
67775 }
67776 }
67777 MemSetTypeFlag(pIn1, MEM_Int);
67778 break;
67779 }
67780
67781 #ifndef SQLITE_OMIT_FLOATING_POINT
67782 /* Opcode: RealAffinity P1 * * * *
@@ -68235,11 +67897,11 @@
67897 break;
67898 }
67899 #endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
67900
67901 /* Opcode: Lt P1 P2 P3 P4 P5
67902 ** Synopsis: if r[P1]<r[P3] goto P2
67903 **
67904 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
67905 ** jump to address P2.
67906 **
67907 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -68322,37 +67984,35 @@
67984 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
67985 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
67986 case OP_Le: /* same as TK_LE, jump, in1, in3 */
67987 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
67988 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
 
67989 int res; /* Result of the comparison of pIn1 against pIn3 */
67990 char affinity; /* Affinity to use for comparison */
67991 u16 flags1; /* Copy of initial value of pIn1->flags */
67992 u16 flags3; /* Copy of initial value of pIn3->flags */
 
67993
67994 pIn1 = &aMem[pOp->p1];
67995 pIn3 = &aMem[pOp->p3];
67996 flags1 = pIn1->flags;
67997 flags3 = pIn3->flags;
67998 if( (flags1 | flags3)&MEM_Null ){
67999 /* One or both operands are NULL */
68000 if( pOp->p5 & SQLITE_NULLEQ ){
68001 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
68002 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68003 ** or not both operands are null.
68004 */
68005 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68006 assert( (flags1 & MEM_Cleared)==0 );
68007 if( (flags1&MEM_Null)!=0
68008 && (flags3&MEM_Null)!=0
68009 && (flags3&MEM_Cleared)==0
68010 ){
68011 res = 0; /* Results are equal */
68012 }else{
68013 res = 1; /* Results are not equal */
68014 }
68015 }else{
68016 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68017 ** then the result is always NULL.
68018 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68366,44 +68026,44 @@
68026 }
68027 break;
68028 }
68029 }else{
68030 /* Neither operand is NULL. Do a comparison. */
68031 affinity = pOp->p5 & SQLITE_AFF_MASK;
68032 if( affinity ){
68033 applyAffinity(pIn1, affinity, encoding);
68034 applyAffinity(pIn3, affinity, encoding);
68035 if( db->mallocFailed ) goto no_mem;
68036 }
68037
68038 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68039 ExpandBlob(pIn1);
68040 ExpandBlob(pIn3);
68041 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68042 }
68043 switch( pOp->opcode ){
68044 case OP_Eq: res = res==0; break;
68045 case OP_Ne: res = res!=0; break;
68046 case OP_Lt: res = res<0; break;
68047 case OP_Le: res = res<=0; break;
68048 case OP_Gt: res = res>0; break;
68049 default: res = res>=0; break;
68050 }
68051
68052 if( pOp->p5 & SQLITE_STOREP2 ){
68053 pOut = &aMem[pOp->p2];
68054 memAboutToChange(p, pOut);
68055 MemSetTypeFlag(pOut, MEM_Int);
68056 pOut->u.i = res;
68057 REGISTER_TRACE(pOp->p2, pOut);
68058 }else if( res ){
68059 pc = pOp->p2-1;
68060 }
68061
68062 /* Undo any changes made by applyAffinity() to the input registers. */
68063 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68064 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68065 break;
68066 }
68067
68068 /* Opcode: Permutation * * * P4 *
68069 **
@@ -68439,51 +68099,49 @@
68099 ** The comparison is a sort comparison, so NULLs compare equal,
68100 ** NULLs are less than numbers, numbers are less than strings,
68101 ** and strings are less than blobs.
68102 */
68103 case OP_Compare: {
 
68104 int n;
68105 int i;
68106 int p1;
68107 int p2;
68108 const KeyInfo *pKeyInfo;
68109 int idx;
68110 CollSeq *pColl; /* Collating sequence to use on this term */
68111 int bRev; /* True for DESCENDING sort order */
 
68112
68113 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68114 n = pOp->p3;
68115 pKeyInfo = pOp->p4.pKeyInfo;
68116 assert( n>0 );
68117 assert( pKeyInfo!=0 );
68118 p1 = pOp->p1;
68119 p2 = pOp->p2;
68120 #if SQLITE_DEBUG
68121 if( aPermute ){
68122 int k, mx = 0;
68123 for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68124 assert( p1>0 && p1+mx<=(p->nMem-p->nCursor)+1 );
68125 assert( p2>0 && p2+mx<=(p->nMem-p->nCursor)+1 );
68126 }else{
68127 assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 );
68128 assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 );
68129 }
68130 #endif /* SQLITE_DEBUG */
68131 for(i=0; i<n; i++){
68132 idx = aPermute ? aPermute[i] : i;
68133 assert( memIsValid(&aMem[p1+idx]) );
68134 assert( memIsValid(&aMem[p2+idx]) );
68135 REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
68136 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
68137 assert( i<pKeyInfo->nField );
68138 pColl = pKeyInfo->aColl[i];
68139 bRev = pKeyInfo->aSortOrder[i];
68140 iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
68141 if( iCompare ){
68142 if( bRev ) iCompare = -iCompare;
68143 break;
68144 }
68145 }
68146 aPermute = 0;
68147 break;
@@ -68526,39 +68184,37 @@
68184 ** even if the other input is NULL. A NULL and false or two NULLs
68185 ** give a NULL output.
68186 */
68187 case OP_And: /* same as TK_AND, in1, in2, out3 */
68188 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
 
68189 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68190 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
 
68191
68192 pIn1 = &aMem[pOp->p1];
68193 if( pIn1->flags & MEM_Null ){
68194 v1 = 2;
68195 }else{
68196 v1 = sqlite3VdbeIntValue(pIn1)!=0;
68197 }
68198 pIn2 = &aMem[pOp->p2];
68199 if( pIn2->flags & MEM_Null ){
68200 v2 = 2;
68201 }else{
68202 v2 = sqlite3VdbeIntValue(pIn2)!=0;
68203 }
68204 if( pOp->opcode==OP_And ){
68205 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68206 v1 = and_logic[v1*3+v2];
68207 }else{
68208 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68209 v1 = or_logic[v1*3+v2];
68210 }
68211 pOut = &aMem[pOp->p3];
68212 if( v1==2 ){
68213 MemSetTypeFlag(pOut, MEM_Null);
68214 }else{
68215 pOut->u.i = v1;
68216 MemSetTypeFlag(pOut, MEM_Int);
68217 }
68218 break;
68219 }
68220
@@ -68625,25 +68281,23 @@
68281 ** is considered false if it has a numeric value of zero. If the value
68282 ** in P1 is NULL then take the jump if P3 is zero.
68283 */
68284 case OP_If: /* jump, in1 */
68285 case OP_IfNot: { /* jump, in1 */
 
68286 int c;
 
68287 pIn1 = &aMem[pOp->p1];
68288 if( pIn1->flags & MEM_Null ){
68289 c = pOp->p3;
68290 }else{
68291 #ifdef SQLITE_OMIT_FLOATING_POINT
68292 c = sqlite3VdbeIntValue(pIn1)!=0;
68293 #else
68294 c = sqlite3VdbeRealValue(pIn1)!=0.0;
68295 #endif
68296 if( pOp->opcode==OP_IfNot ) c = !c;
68297 }
68298 if( c ){
68299 pc = pOp->p2-1;
68300 }
68301 break;
68302 }
68303
@@ -68697,157 +68351,107 @@
68351 ** the result is guaranteed to only be used as the argument of a length()
68352 ** or typeof() function, respectively. The loading of large blobs can be
68353 ** skipped for length() and all content loading can be skipped for typeof().
68354 */
68355 case OP_Column: {
 
 
68356 i64 payloadSize64; /* Number of bytes in the record */
 
68357 int p2; /* column number to retrieve */
68358 VdbeCursor *pC; /* The VDBE cursor */
 
68359 BtCursor *pCrsr; /* The BTree cursor */
68360 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
68361 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
 
68362 int len; /* The length of the serialized data for the column */
68363 int i; /* Loop counter */
 
68364 Mem *pDest; /* Where to write the extracted value */
68365 Mem sMem; /* For storing the record being decoded */
68366 const u8 *zData; /* Part of the record being decoded */
68367 const u8 *zHdr; /* Next unparsed byte of the header */
68368 const u8 *zEndHdr; /* Pointer to first byte after the header */
68369 u32 offset; /* Offset into the data */
68370 u32 szField; /* Number of bytes in the content of a field */
68371 u32 avail; /* Number of bytes of available data */
 
68372 u32 t; /* A type code from the record header */
68373 Mem *pReg; /* PseudoTable input register */
68374
68375 p2 = pOp->p2;
 
 
 
 
 
 
68376 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68377 pDest = &aMem[pOp->p3];
68378 memAboutToChange(p, pDest);
68379 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68380 pC = p->apCsr[pOp->p1];
68381 assert( pC!=0 );
68382 assert( p2<pC->nField );
68383 aType = pC->aType;
68384 aOffset = aType + pC->nField;
 
 
 
 
 
 
 
 
 
 
68385 #ifndef SQLITE_OMIT_VIRTUALTABLE
68386 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
68387 #endif
68388 pCrsr = pC->pCursor;
68389 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
68390 assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
68391
68392 /* If the cursor cache is stale, bring it up-to-date */
68393 rc = sqlite3VdbeCursorMoveto(pC);
68394 if( rc ) goto abort_due_to_error;
68395 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68396 if( pC->nullRow ){
68397 if( pCrsr==0 ){
68398 assert( pC->pseudoTableReg>0 );
68399 pReg = &aMem[pC->pseudoTableReg];
68400 if( pC->multiPseudo ){
68401 sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68402 Deephemeralize(pDest);
68403 goto op_column_out;
68404 }
68405 assert( pReg->flags & MEM_Blob );
68406 assert( memIsValid(pReg) );
68407 pC->payloadSize = pC->szRow = avail = pReg->n;
68408 pC->aRow = (u8*)pReg->z;
68409 }else{
68410 MemSetTypeFlag(pDest, MEM_Null);
68411 goto op_column_out;
68412 }
68413 }else{
68414 assert( pCrsr );
68415 if( pC->isTable==0 ){
68416 assert( sqlite3BtreeCursorIsValid(pCrsr) );
68417 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64);
68418 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68419 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68420 ** payload size, so it is impossible for payloadSize64 to be
68421 ** larger than 32 bits. */
68422 assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
68423 pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail);
68424 pC->payloadSize = (u32)payloadSize64;
68425 }else{
68426 assert( sqlite3BtreeCursorIsValid(pCrsr) );
68427 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize);
68428 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68429 pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail);
68430 }
68431 assert( avail<=65536 ); /* Maximum page size is 64KiB */
68432 if( pC->payloadSize <= (u32)avail ){
68433 pC->szRow = pC->payloadSize;
68434 }else{
68435 pC->szRow = avail;
68436 }
68437 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68438 goto too_big;
68439 }
68440 }
68441 pC->cacheStatus = p->cacheCtr;
68442 pC->iHdrOffset = getVarint32(pC->aRow, offset);
68443 pC->nHdrParsed = 0;
68444 aOffset[0] = offset;
68445 if( avail<offset ){
68446 /* pC->aRow does not have to hold the entire row, but it does at least
68447 ** need to cover the header of the record. If pC->aRow does not contain
68448 ** the complete header, then set it to zero, forcing the header to be
68449 ** dynamically allocated. */
68450 pC->aRow = 0;
68451 pC->szRow = 0;
68452 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68453
68454 /* Make sure a corrupt database has not given us an oversize header.
68455 ** Do this now to avoid an oversize memory allocation.
68456 **
68457 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68854,161 +68458,154 @@
68458 ** types use so much data space that there can only be 4096 and 32 of
68459 ** them, respectively. So the maximum header length results from a
68460 ** 3-byte type for each of the maximum of 32768 columns plus three
68461 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68462 */
68463 if( offset > 98307 || offset > pC->payloadSize ){
68464 rc = SQLITE_CORRUPT_BKPT;
68465 goto op_column_error;
68466 }
68467 }
68468
68469 /* Make sure at least the first p2+1 entries of the header have been
68470 ** parsed and valid information is in aOffset[] and aType[].
68471 */
68472 if( pC->nHdrParsed<=p2 ){
68473 /* If there is more header available for parsing in the record, try
68474 ** to extract additional fields up through the p2+1-th field
68475 */
68476 if( pC->iHdrOffset<aOffset[0] ){
68477 /* Make sure zData points to enough of the record to cover the header. */
68478 if( pC->aRow==0 ){
68479 memset(&sMem, 0, sizeof(sMem));
68480 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
68481 !pC->isTable, &sMem);
68482 if( rc!=SQLITE_OK ){
68483 goto op_column_error;
68484 }
68485 zData = (u8*)sMem.z;
68486 }else{
68487 zData = pC->aRow;
68488 }
68489
68490 /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
68491 i = pC->nHdrParsed;
68492 offset = aOffset[i];
68493 zHdr = zData + pC->iHdrOffset;
68494 zEndHdr = zData + aOffset[0];
68495 assert( i<=p2 && zHdr<zEndHdr );
68496 do{
68497 if( zHdr[0]<0x80 ){
68498 t = zHdr[0];
68499 zHdr++;
68500 }else{
68501 zHdr += sqlite3GetVarint32(zHdr, &t);
68502 }
68503 aType[i] = t;
68504 szField = sqlite3VdbeSerialTypeLen(t);
68505 offset += szField;
68506 if( offset<szField ){ /* True if offset overflows */
68507 zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68508 break;
68509 }
68510 i++;
68511 aOffset[i] = offset;
68512 }while( i<=p2 && zHdr<zEndHdr );
68513 pC->nHdrParsed = i;
68514 pC->iHdrOffset = (u32)(zHdr - zData);
68515 if( pC->aRow==0 ){
68516 sqlite3VdbeMemRelease(&sMem);
68517 sMem.flags = MEM_Null;
68518 }
68519
68520 /* If we have read more header data than was contained in the header,
68521 ** or if the end of the last field appears to be past the end of the
68522 ** record, or if the end of the last field appears to be before the end
68523 ** of the record (when all fields present), then we must be dealing
68524 ** with a corrupt database.
68525 */
68526 if( (zHdr > zEndHdr)
68527 || (offset > pC->payloadSize)
68528 || (zHdr==zEndHdr && offset!=pC->payloadSize)
68529 ){
68530 rc = SQLITE_CORRUPT_BKPT;
68531 goto op_column_error;
68532 }
68533 }
68534
68535 /* If after trying to extra new entries from the header, nHdrParsed is
68536 ** still not up to p2, that means that the record has fewer than p2
68537 ** columns. So the result will be either the default value or a NULL.
68538 */
68539 if( pC->nHdrParsed<=p2 ){
68540 if( pOp->p4type==P4_MEM ){
68541 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
68542 }else{
68543 MemSetTypeFlag(pDest, MEM_Null);
68544 }
68545 goto op_column_out;
68546 }
68547 }
68548
68549 /* Extract the content for the p2+1-th column. Control can only
68550 ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
68551 ** all valid.
68552 */
68553 assert( p2<pC->nHdrParsed );
68554 assert( rc==SQLITE_OK );
68555 if( pC->szRow>=aOffset[p2+1] ){
68556 /* This is the common case where the desired content fits on the original
68557 ** page - where the content is not on an overflow page */
68558 VdbeMemRelease(pDest);
68559 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
68560 }else{
68561 /* This branch happens only when content is on overflow pages */
68562 t = aType[p2];
68563 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68564 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
68565 || (len = sqlite3VdbeSerialTypeLen(t))==0
68566 ){
68567 /* Content is irrelevant for the typeof() function and for
68568 ** the length(X) function if X is a blob. So we might as well use
68569 ** bogus content rather than reading content from disk. NULL works
68570 ** for text and blob and whatever is in the payloadSize64 variable
68571 ** will work for everything else. Content is also irrelevant if
68572 ** the content length is 0. */
68573 zData = t<=13 ? (u8*)&payloadSize64 : 0;
68574 sMem.zMalloc = 0;
68575 }else{
68576 memset(&sMem, 0, sizeof(sMem));
68577 sqlite3VdbeMemMove(&sMem, pDest);
68578 rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
68579 &sMem);
68580 if( rc!=SQLITE_OK ){
68581 goto op_column_error;
68582 }
68583 zData = (u8*)sMem.z;
68584 }
68585 sqlite3VdbeSerialGet(zData, t, pDest);
68586 /* If we dynamically allocated space to hold the data (in the
68587 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68588 ** dynamically allocated space over to the pDest structure.
68589 ** This prevents a memory copy. */
68590 if( sMem.zMalloc ){
68591 assert( sMem.z==sMem.zMalloc );
68592 assert( !(pDest->flags & MEM_Dyn) );
68593 assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
68594 pDest->flags &= ~(MEM_Ephem|MEM_Static);
68595 pDest->flags |= MEM_Term;
68596 pDest->z = sMem.z;
68597 pDest->zMalloc = sMem.zMalloc;
68598 }
68599 }
68600 pDest->enc = encoding;
68601
68602 op_column_out:
68603 Deephemeralize(pDest);
68604 op_column_error:
68605 UPDATE_MAX_BLOBSIZE(pDest);
68606 REGISTER_TRACE(pOp->p3, pDest);
 
 
 
 
 
 
 
68607 break;
68608 }
68609
68610 /* Opcode: Affinity P1 P2 * P4 *
68611 ** Synopsis: affinity(r[P1@P2])
@@ -69018,24 +68615,22 @@
68615 ** P4 is a string that is P2 characters long. The nth character of the
68616 ** string indicates the column affinity that should be used for the nth
68617 ** memory cell in the range.
68618 */
68619 case OP_Affinity: {
 
68620 const char *zAffinity; /* The affinity to be applied */
68621 char cAff; /* A single character of affinity */
 
68622
68623 zAffinity = pOp->p4.z;
68624 assert( zAffinity!=0 );
68625 assert( zAffinity[pOp->p2]==0 );
68626 pIn1 = &aMem[pOp->p1];
68627 while( (cAff = *(zAffinity++))!=0 ){
68628 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
68629 assert( memIsValid(pIn1) );
68630 ExpandBlob(pIn1);
68631 applyAffinity(pIn1, cAff, encoding);
68632 pIn1++;
68633 }
68634 break;
68635 }
68636
@@ -69054,11 +68649,10 @@
68649 ** macros defined in sqliteInt.h.
68650 **
68651 ** If P4 is NULL then all index fields have the affinity NONE.
68652 */
68653 case OP_MakeRecord: {
 
68654 u8 *zNewRecord; /* A buffer to hold the data for the new record */
68655 Mem *pRec; /* The new record */
68656 u64 nData; /* Number of bytes of data space */
68657 int nHdr; /* Number of bytes of header space */
68658 i64 nByte; /* Data space required for this record */
@@ -69068,106 +68662,123 @@
68662 Mem *pData0; /* First field to be combined into the record */
68663 Mem *pLast; /* Last field of the record */
68664 int nField; /* Number of fields in the record */
68665 char *zAffinity; /* The affinity string for the record */
68666 int file_format; /* File format to use for encoding */
68667 int i; /* Space used in zNewRecord[] header */
68668 int j; /* Space used in zNewRecord[] content */
68669 int len; /* Length of a field */
 
68670
68671 /* Assuming the record contains N fields, the record format looks
68672 ** like this:
68673 **
68674 ** ------------------------------------------------------------------------
68675 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
68676 ** ------------------------------------------------------------------------
68677 **
68678 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
68679 ** and so froth.
68680 **
68681 ** Each type field is a varint representing the serial type of the
68682 ** corresponding data element (see sqlite3VdbeSerialType()). The
68683 ** hdr-size field is also a varint which is the offset from the beginning
68684 ** of the record to data0.
68685 */
68686 nData = 0; /* Number of bytes of data space */
68687 nHdr = 0; /* Number of bytes of header space */
68688 nZero = 0; /* Number of zero bytes at the end of the record */
68689 nField = pOp->p1;
68690 zAffinity = pOp->p4.z;
68691 assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem-p->nCursor)+1 );
68692 pData0 = &aMem[nField];
68693 nField = pOp->p2;
68694 pLast = &pData0[nField-1];
68695 file_format = p->minWriteFileFormat;
68696
68697 /* Identify the output register */
68698 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
68699 pOut = &aMem[pOp->p3];
68700 memAboutToChange(p, pOut);
68701
68702 /* Apply the requested affinity to all inputs
68703 */
68704 assert( pData0<=pLast );
68705 if( zAffinity ){
68706 pRec = pData0;
68707 do{
68708 applyAffinity(pRec, *(zAffinity++), encoding);
68709 }while( (++pRec)<=pLast );
68710 }
68711
68712 /* Loop through the elements that will make up the record to figure
68713 ** out how much space is required for the new record.
68714 */
68715 pRec = pLast;
68716 do{
68717 assert( memIsValid(pRec) );
68718 serial_type = sqlite3VdbeSerialType(pRec, file_format);
68719 len = sqlite3VdbeSerialTypeLen(serial_type);
68720 if( pRec->flags & MEM_Zero ){
68721 if( nData ){
68722 sqlite3VdbeMemExpandBlob(pRec);
68723 }else{
68724 nZero += pRec->u.nZero;
68725 len -= pRec->u.nZero;
68726 }
68727 }
68728 nData += len;
68729 testcase( serial_type==127 );
68730 testcase( serial_type==128 );
68731 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
68732 }while( (--pRec)>=pData0 );
 
 
68733
68734 /* Add the initial header varint and total the size */
68735 testcase( nHdr==126 );
68736 testcase( nHdr==127 );
68737 if( nHdr<=126 ){
68738 /* The common case */
68739 nHdr += 1;
68740 }else{
68741 /* Rare case of a really large header */
68742 nVarint = sqlite3VarintLen(nHdr);
68743 nHdr += nVarint;
68744 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
68745 }
68746 nByte = nHdr+nData;
68747 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
68748 goto too_big;
68749 }
68750
68751 /* Make sure the output register has a buffer large enough to store
68752 ** the new record. The output register (pOp->p3) is not allowed to
68753 ** be one of the input registers (because the following call to
68754 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
68755 */
68756 if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
68757 goto no_mem;
68758 }
68759 zNewRecord = (u8 *)pOut->z;
68760
68761 /* Write the record */
68762 i = putVarint32(zNewRecord, nHdr);
68763 j = nHdr;
68764 assert( pData0<=pLast );
68765 pRec = pData0;
68766 do{
68767 serial_type = sqlite3VdbeSerialType(pRec, file_format);
68768 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
68769 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
68770 }while( (++pRec)<=pLast );
68771 assert( i==nHdr );
68772 assert( j==nByte );
68773
68774 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68775 pOut->n = (int)nByte;
68776 pOut->flags = MEM_Blob | MEM_Dyn;
68777 pOut->xDel = 0;
68778 if( nZero ){
68779 pOut->u.nZero = nZero;
68780 pOut->flags |= MEM_Zero;
68781 }
68782 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
68783 REGISTER_TRACE(pOp->p3, pOut);
68784 UPDATE_MAX_BLOBSIZE(pOut);
@@ -69180,19 +68791,18 @@
68791 ** Store the number of entries (an integer value) in the table or index
68792 ** opened by cursor P1 in register P2
68793 */
68794 #ifndef SQLITE_OMIT_BTREECOUNT
68795 case OP_Count: { /* out2-prerelease */
 
68796 i64 nEntry;
68797 BtCursor *pCrsr;
 
68798
68799 pCrsr = p->apCsr[pOp->p1]->pCursor;
68800 assert( pCrsr );
68801 nEntry = 0; /* Not needed. Only used to silence a warning. */
68802 rc = sqlite3BtreeCount(pCrsr, &nEntry);
68803 pOut->u.i = nEntry;
68804 break;
68805 }
68806 #endif
68807
68808 /* Opcode: Savepoint P1 * * P4 *
@@ -69200,43 +68810,41 @@
68810 ** Open, release or rollback the savepoint named by parameter P4, depending
68811 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
68812 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
68813 */
68814 case OP_Savepoint: {
 
68815 int p1; /* Value of P1 operand */
68816 char *zName; /* Name of savepoint */
68817 int nName;
68818 Savepoint *pNew;
68819 Savepoint *pSavepoint;
68820 Savepoint *pTmp;
68821 int iSavepoint;
68822 int ii;
 
68823
68824 p1 = pOp->p1;
68825 zName = pOp->p4.z;
68826
68827 /* Assert that the p1 parameter is valid. Also that if there is no open
68828 ** transaction, then there cannot be any savepoints.
68829 */
68830 assert( db->pSavepoint==0 || db->autoCommit==0 );
68831 assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK );
68832 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
68833 assert( checkSavepointCount(db) );
68834 assert( p->bIsReader );
68835
68836 if( p1==SAVEPOINT_BEGIN ){
68837 if( db->nVdbeWrite>0 ){
68838 /* A new savepoint cannot be created if there are active write
68839 ** statements (i.e. open read/write incremental blob handles).
68840 */
68841 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
68842 "SQL statements in progress");
68843 rc = SQLITE_BUSY;
68844 }else{
68845 nName = sqlite3Strlen30(zName);
68846
68847 #ifndef SQLITE_OMIT_VIRTUALTABLE
68848 /* This call is Ok even if this savepoint is actually a transaction
68849 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
68850 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -69246,62 +68854,62 @@
68854 db->nStatement+db->nSavepoint);
68855 if( rc!=SQLITE_OK ) goto abort_due_to_error;
68856 #endif
68857
68858 /* Create a new savepoint structure. */
68859 pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
68860 if( pNew ){
68861 pNew->zName = (char *)&pNew[1];
68862 memcpy(pNew->zName, zName, nName+1);
68863
68864 /* If there is no open transaction, then mark this as a special
68865 ** "transaction savepoint". */
68866 if( db->autoCommit ){
68867 db->autoCommit = 0;
68868 db->isTransactionSavepoint = 1;
68869 }else{
68870 db->nSavepoint++;
68871 }
68872
68873 /* Link the new savepoint into the database handle's list. */
68874 pNew->pNext = db->pSavepoint;
68875 db->pSavepoint = pNew;
68876 pNew->nDeferredCons = db->nDeferredCons;
68877 pNew->nDeferredImmCons = db->nDeferredImmCons;
68878 }
68879 }
68880 }else{
68881 iSavepoint = 0;
68882
68883 /* Find the named savepoint. If there is no such savepoint, then an
68884 ** an error is returned to the user. */
68885 for(
68886 pSavepoint = db->pSavepoint;
68887 pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
68888 pSavepoint = pSavepoint->pNext
68889 ){
68890 iSavepoint++;
68891 }
68892 if( !pSavepoint ){
68893 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
68894 rc = SQLITE_ERROR;
68895 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
68896 /* It is not possible to release (commit) a savepoint if there are
68897 ** active write statements.
68898 */
68899 sqlite3SetString(&p->zErrMsg, db,
68900 "cannot release savepoint - SQL statements in progress"
68901 );
68902 rc = SQLITE_BUSY;
68903 }else{
68904
68905 /* Determine whether or not this is a transaction savepoint. If so,
68906 ** and this is a RELEASE command, then the current transaction
68907 ** is committed.
68908 */
68909 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
68910 if( isTransaction && p1==SAVEPOINT_RELEASE ){
68911 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
68912 goto vdbe_return;
68913 }
68914 db->autoCommit = 1;
68915 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69311,56 +68919,56 @@
68919 goto vdbe_return;
68920 }
68921 db->isTransactionSavepoint = 0;
68922 rc = p->rc;
68923 }else{
68924 iSavepoint = db->nSavepoint - iSavepoint - 1;
68925 if( p1==SAVEPOINT_ROLLBACK ){
68926 for(ii=0; ii<db->nDb; ii++){
68927 sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
68928 }
68929 }
68930 for(ii=0; ii<db->nDb; ii++){
68931 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
68932 if( rc!=SQLITE_OK ){
68933 goto abort_due_to_error;
68934 }
68935 }
68936 if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
68937 sqlite3ExpirePreparedStatements(db);
68938 sqlite3ResetAllSchemasOfConnection(db);
68939 db->flags = (db->flags | SQLITE_InternChanges);
68940 }
68941 }
68942
68943 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
68944 ** savepoints nested inside of the savepoint being operated on. */
68945 while( db->pSavepoint!=pSavepoint ){
68946 pTmp = db->pSavepoint;
68947 db->pSavepoint = pTmp->pNext;
68948 sqlite3DbFree(db, pTmp);
68949 db->nSavepoint--;
68950 }
68951
68952 /* If it is a RELEASE, then destroy the savepoint being operated on
68953 ** too. If it is a ROLLBACK TO, then set the number of deferred
68954 ** constraint violations present in the database to the value stored
68955 ** when the savepoint was created. */
68956 if( p1==SAVEPOINT_RELEASE ){
68957 assert( pSavepoint==db->pSavepoint );
68958 db->pSavepoint = pSavepoint->pNext;
68959 sqlite3DbFree(db, pSavepoint);
68960 if( !isTransaction ){
68961 db->nSavepoint--;
68962 }
68963 }else{
68964 db->nDeferredCons = pSavepoint->nDeferredCons;
68965 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
68966 }
68967
68968 if( !isTransaction ){
68969 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
68970 if( rc!=SQLITE_OK ) goto abort_due_to_error;
68971 }
68972 }
68973 }
68974
@@ -69375,54 +68983,52 @@
68983 ** there are active writing VMs or active VMs that use shared cache.
68984 **
68985 ** This instruction causes the VM to halt.
68986 */
68987 case OP_AutoCommit: {
 
68988 int desiredAutoCommit;
68989 int iRollback;
68990 int turnOnAC;
 
68991
68992 desiredAutoCommit = pOp->p1;
68993 iRollback = pOp->p2;
68994 turnOnAC = desiredAutoCommit && !db->autoCommit;
68995 assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
68996 assert( desiredAutoCommit==1 || iRollback==0 );
68997 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
68998 assert( p->bIsReader );
68999
69000 #if 0
69001 if( turnOnAC && iRollback && db->nVdbeActive>1 ){
69002 /* If this instruction implements a ROLLBACK and other VMs are
69003 ** still running, and a transaction is active, return an error indicating
69004 ** that the other VMs must complete first.
69005 */
69006 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69007 "SQL statements in progress");
69008 rc = SQLITE_BUSY;
69009 }else
69010 #endif
69011 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
69012 /* If this instruction implements a COMMIT and other VMs are writing
69013 ** return an error indicating that the other VMs must complete first.
69014 */
69015 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69016 "SQL statements in progress");
69017 rc = SQLITE_BUSY;
69018 }else if( desiredAutoCommit!=db->autoCommit ){
69019 if( iRollback ){
69020 assert( desiredAutoCommit==1 );
69021 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69022 db->autoCommit = 1;
69023 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69024 goto vdbe_return;
69025 }else{
69026 db->autoCommit = (u8)desiredAutoCommit;
69027 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69028 p->pc = pc;
69029 db->autoCommit = (u8)(1-desiredAutoCommit);
69030 p->rc = rc = SQLITE_BUSY;
69031 goto vdbe_return;
69032 }
69033 }
69034 assert( db->nStatement==0 );
@@ -69433,14 +69039,14 @@
69039 rc = SQLITE_ERROR;
69040 }
69041 goto vdbe_return;
69042 }else{
69043 sqlite3SetString(&p->zErrMsg, db,
69044 (!desiredAutoCommit)?"cannot start a transaction within a transaction":(
69045 (iRollback)?"cannot rollback - no transaction is active":
69046 "cannot commit - no transaction is active"));
69047
69048 rc = SQLITE_ERROR;
69049 }
69050 break;
69051 }
69052
@@ -69474,48 +69080,46 @@
69080 ** will automatically commit when the VDBE halts.
69081 **
69082 ** If P2 is zero, then a read-lock is obtained on the database file.
69083 */
69084 case OP_Transaction: {
 
69085 Btree *pBt;
 
69086
69087 assert( p->bIsReader );
69088 assert( p->readOnly==0 || pOp->p2==0 );
69089 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69090 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69091 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69092 rc = SQLITE_READONLY;
69093 goto abort_due_to_error;
69094 }
69095 pBt = db->aDb[pOp->p1].pBt;
69096
69097 if( pBt ){
69098 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
69099 if( rc==SQLITE_BUSY ){
69100 p->pc = pc;
69101 p->rc = rc = SQLITE_BUSY;
69102 goto vdbe_return;
69103 }
69104 if( rc!=SQLITE_OK ){
69105 goto abort_due_to_error;
69106 }
69107
69108 if( pOp->p2 && p->usesStmtJournal
69109 && (db->autoCommit==0 || db->nVdbeRead>1)
69110 ){
69111 assert( sqlite3BtreeIsInTrans(pBt) );
69112 if( p->iStatement==0 ){
69113 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69114 db->nStatement++;
69115 p->iStatement = db->nSavepoint + db->nStatement;
69116 }
69117
69118 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69119 if( rc==SQLITE_OK ){
69120 rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
69121 }
69122
69123 /* Store the current value of the database handles deferred constraint
69124 ** counter. If the statement transaction needs to be rolled back,
69125 ** the value of this counter needs to be restored too. */
@@ -69537,26 +69141,24 @@
69141 ** There must be a read-lock on the database (either a transaction
69142 ** must be started or there must be an open cursor) before
69143 ** executing this instruction.
69144 */
69145 case OP_ReadCookie: { /* out2-prerelease */
 
69146 int iMeta;
69147 int iDb;
69148 int iCookie;
 
69149
69150 assert( p->bIsReader );
69151 iDb = pOp->p1;
69152 iCookie = pOp->p3;
69153 assert( pOp->p3<SQLITE_N_BTREE_META );
69154 assert( iDb>=0 && iDb<db->nDb );
69155 assert( db->aDb[iDb].pBt!=0 );
69156 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69157
69158 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
69159 pOut->u.i = iMeta;
69160 break;
69161 }
69162
69163 /* Opcode: SetCookie P1 P2 P3 * *
69164 **
@@ -69567,31 +69169,29 @@
69169 ** database file used to store temporary tables.
69170 **
69171 ** A transaction must be started before executing this opcode.
69172 */
69173 case OP_SetCookie: { /* in3 */
 
69174 Db *pDb;
 
69175 assert( pOp->p2<SQLITE_N_BTREE_META );
69176 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69177 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69178 assert( p->readOnly==0 );
69179 pDb = &db->aDb[pOp->p1];
69180 assert( pDb->pBt!=0 );
69181 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69182 pIn3 = &aMem[pOp->p3];
69183 sqlite3VdbeMemIntegerify(pIn3);
69184 /* See note about index shifting on OP_ReadCookie */
69185 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
69186 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69187 /* When the schema cookie changes, record the new cookie internally */
69188 pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69189 db->flags |= SQLITE_InternChanges;
69190 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69191 /* Record changes in the file format */
69192 pDb->pSchema->file_format = (u8)pIn3->u.i;
69193 }
69194 if( pOp->p1==1 ){
69195 /* Invalidate all prepared statements whenever the TEMP database
69196 ** schema is changed. Ticket #1644 */
69197 sqlite3ExpirePreparedStatements(db);
@@ -69617,44 +69217,42 @@
69217 ** Either a transaction needs to have been started or an OP_Open needs
69218 ** to be executed (to establish a read lock) before this opcode is
69219 ** invoked.
69220 */
69221 case OP_VerifyCookie: {
 
69222 int iMeta;
69223 int iGen;
69224 Btree *pBt;
 
69225
69226 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69227 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69228 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69229 assert( p->bIsReader );
69230 pBt = db->aDb[pOp->p1].pBt;
69231 if( pBt ){
69232 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69233 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69234 }else{
69235 iGen = iMeta = 0;
69236 }
69237 if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69238 sqlite3DbFree(db, p->zErrMsg);
69239 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69240 /* If the schema-cookie from the database file matches the cookie
69241 ** stored with the in-memory representation of the schema, do
69242 ** not reload the schema from the database file.
69243 **
69244 ** If virtual-tables are in use, this is not just an optimization.
69245 ** Often, v-tables store their data in other SQLite tables, which
69246 ** are queried from within xNext() and other v-table methods using
69247 ** prepared queries. If such a query is out-of-date, we do not want to
69248 ** discard the database schema, as the user code implementing the
69249 ** v-table would have to be ready for the sqlite3_vtab structure itself
69250 ** to be invalidated whenever sqlite3_step() is called from within
69251 ** a v-table method.
69252 */
69253 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69254 sqlite3ResetOneSchema(db, pOp->p1);
69255 }
69256
69257 p->expired = 1;
69258 rc = SQLITE_SCHEMA;
@@ -69713,20 +69311,18 @@
69311 **
69312 ** See also OpenRead.
69313 */
69314 case OP_OpenRead:
69315 case OP_OpenWrite: {
 
69316 int nField;
69317 KeyInfo *pKeyInfo;
69318 int p2;
69319 int iDb;
69320 int wrFlag;
69321 Btree *pX;
69322 VdbeCursor *pCur;
69323 Db *pDb;
 
69324
69325 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69326 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69327 assert( p->bIsReader );
69328 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69734,73 +69330,74 @@
69330 if( p->expired ){
69331 rc = SQLITE_ABORT;
69332 break;
69333 }
69334
69335 nField = 0;
69336 pKeyInfo = 0;
69337 p2 = pOp->p2;
69338 iDb = pOp->p3;
69339 assert( iDb>=0 && iDb<db->nDb );
69340 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69341 pDb = &db->aDb[iDb];
69342 pX = pDb->pBt;
69343 assert( pX!=0 );
69344 if( pOp->opcode==OP_OpenWrite ){
69345 wrFlag = 1;
69346 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
69347 if( pDb->pSchema->file_format < p->minWriteFileFormat ){
69348 p->minWriteFileFormat = pDb->pSchema->file_format;
69349 }
69350 }else{
69351 wrFlag = 0;
69352 }
69353 if( pOp->p5 & OPFLAG_P2ISREG ){
69354 assert( p2>0 );
69355 assert( p2<=(p->nMem-p->nCursor) );
69356 pIn2 = &aMem[p2];
69357 assert( memIsValid(pIn2) );
69358 assert( (pIn2->flags & MEM_Int)!=0 );
69359 sqlite3VdbeMemIntegerify(pIn2);
69360 p2 = (int)pIn2->u.i;
69361 /* The p2 value always comes from a prior OP_CreateTable opcode and
69362 ** that opcode will always set the p2 value to 2 or more or else fail.
69363 ** If there were a failure, the prepared statement would have halted
69364 ** before reaching this instruction. */
69365 if( NEVER(p2<2) ) {
69366 rc = SQLITE_CORRUPT_BKPT;
69367 goto abort_due_to_error;
69368 }
69369 }
69370 if( pOp->p4type==P4_KEYINFO ){
69371 pKeyInfo = pOp->p4.pKeyInfo;
69372 assert( pKeyInfo->enc==ENC(db) );
69373 assert( pKeyInfo->db==db );
69374 nField = pKeyInfo->nField+pKeyInfo->nXField;
69375 }else if( pOp->p4type==P4_INT32 ){
69376 nField = pOp->p4.i;
69377 }
69378 assert( pOp->p1>=0 );
69379 assert( nField>=0 );
69380 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
69381 pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
69382 if( pCur==0 ) goto no_mem;
69383 pCur->nullRow = 1;
69384 pCur->isOrdered = 1;
69385 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
69386 pCur->pKeyInfo = pKeyInfo;
69387 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69388 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69389
69390 /* Since it performs no memory allocation or IO, the only value that
69391 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69392 assert( rc==SQLITE_OK );
69393
69394 /* Set the VdbeCursor.isTable variable. Previous versions of
69395 ** SQLite used to check if the root-page flags were sane at this point
69396 ** and report database corruption if they were not, but this check has
69397 ** since moved into the btree layer. */
69398 pCur->isTable = pOp->p4type!=P4_KEYINFO;
 
69399 break;
69400 }
69401
69402 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69403 ** Synopsis: nColumn=P2
@@ -69828,55 +69425,53 @@
69425 ** by this opcode will be used for automatically created transient
69426 ** indices in joins.
69427 */
69428 case OP_OpenAutoindex:
69429 case OP_OpenEphemeral: {
 
69430 VdbeCursor *pCx;
69431 KeyInfo *pKeyInfo;
 
69432
69433 static const int vfsFlags =
69434 SQLITE_OPEN_READWRITE |
69435 SQLITE_OPEN_CREATE |
69436 SQLITE_OPEN_EXCLUSIVE |
69437 SQLITE_OPEN_DELETEONCLOSE |
69438 SQLITE_OPEN_TRANSIENT_DB;
69439 assert( pOp->p1>=0 );
69440 assert( pOp->p2>=0 );
69441 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69442 if( pCx==0 ) goto no_mem;
69443 pCx->nullRow = 1;
69444 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
69445 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69446 if( rc==SQLITE_OK ){
69447 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
69448 }
69449 if( rc==SQLITE_OK ){
69450 /* If a transient index is required, create it by calling
69451 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69452 ** opening it. If a transient table is required, just use the
69453 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69454 */
69455 if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69456 int pgno;
69457 assert( pOp->p4type==P4_KEYINFO );
69458 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69459 if( rc==SQLITE_OK ){
69460 assert( pgno==MASTER_ROOT+1 );
69461 assert( pKeyInfo->db==db );
69462 assert( pKeyInfo->enc==ENC(db) );
69463 pCx->pKeyInfo = pKeyInfo;
69464 rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor);
69465 }
69466 pCx->isTable = 0;
69467 }else{
69468 rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor);
69469 pCx->isTable = 1;
69470 }
69471 }
69472 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
 
69473 break;
69474 }
69475
69476 /* Opcode: SorterOpen P1 * * P4 *
69477 **
@@ -69883,21 +69478,20 @@
69478 ** This opcode works like OP_OpenEphemeral except that it opens
69479 ** a transient index that is specifically designed to sort large
69480 ** tables using an external merge-sort algorithm.
69481 */
69482 case OP_SorterOpen: {
 
69483 VdbeCursor *pCx;
69484
69485 assert( pOp->p1>=0 );
69486 assert( pOp->p2>=0 );
69487 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69488 if( pCx==0 ) goto no_mem;
69489 pCx->pKeyInfo = pOp->p4.pKeyInfo;
69490 assert( pCx->pKeyInfo->db==db );
69491 assert( pCx->pKeyInfo->enc==ENC(db) );
69492 rc = sqlite3VdbeSorterInit(db, pCx);
69493 break;
69494 }
69495
69496 /* Opcode: OpenPseudo P1 P2 P3 * P5
69497 ** Synopsis: content in r[P2@P3]
@@ -69915,22 +69509,20 @@
69509 **
69510 ** P3 is the number of fields in the records that will be stored by
69511 ** the pseudo-table.
69512 */
69513 case OP_OpenPseudo: {
 
69514 VdbeCursor *pCx;
 
69515
69516 assert( pOp->p1>=0 );
69517 assert( pOp->p3>=0 );
69518 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69519 if( pCx==0 ) goto no_mem;
69520 pCx->nullRow = 1;
69521 pCx->pseudoTableReg = pOp->p2;
69522 pCx->isTable = 1;
69523 pCx->multiPseudo = pOp->p5;
69524 break;
69525 }
69526
69527 /* Opcode: Close P1 * * * *
69528 **
@@ -70002,39 +69594,37 @@
69594 */
69595 case OP_SeekLt: /* jump, in3 */
69596 case OP_SeekLe: /* jump, in3 */
69597 case OP_SeekGe: /* jump, in3 */
69598 case OP_SeekGt: { /* jump, in3 */
 
69599 int res;
69600 int oc;
69601 VdbeCursor *pC;
69602 UnpackedRecord r;
69603 int nField;
69604 i64 iKey; /* The rowid we are to seek to */
 
69605
69606 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69607 assert( pOp->p2!=0 );
69608 pC = p->apCsr[pOp->p1];
69609 assert( pC!=0 );
69610 assert( pC->pseudoTableReg==0 );
69611 assert( OP_SeekLe == OP_SeekLt+1 );
69612 assert( OP_SeekGe == OP_SeekLt+2 );
69613 assert( OP_SeekGt == OP_SeekLt+3 );
69614 assert( pC->isOrdered );
69615 assert( pC->pCursor!=0 );
69616 oc = pOp->opcode;
69617 pC->nullRow = 0;
69618 if( pC->isTable ){
69619 /* The input value in P3 might be of any type: integer, real, string,
69620 ** blob, or NULL. But it needs to be an integer before we can do
69621 ** the seek, so covert it. */
69622 pIn3 = &aMem[pOp->p3];
69623 applyNumericAffinity(pIn3);
69624 iKey = sqlite3VdbeIntValue(pIn3);
69625 pC->rowidIsValid = 0;
69626
69627 /* If the P3 value could not be converted into an integer without
69628 ** loss of information, then special processing is required... */
69629 if( (pIn3->flags & MEM_Int)==0 ){
69630 if( (pIn3->flags & MEM_Real)==0 ){
@@ -70041,109 +69631,101 @@
69631 /* If the P3 value cannot be converted into any kind of a number,
69632 ** then the seek is not possible, so jump to P2 */
69633 pc = pOp->p2 - 1;
69634 break;
69635 }
69636
69637 /* If the approximation iKey is larger than the actual real search
69638 ** term, substitute >= for > and < for <=. e.g. if the search term
69639 ** is 4.9 and the integer approximation 5:
69640 **
69641 ** (x > 4.9) -> (x >= 5)
69642 ** (x <= 4.9) -> (x < 5)
69643 */
69644 if( pIn3->r<(double)iKey ){
69645 assert( OP_SeekGe==(OP_SeekGt-1) );
69646 assert( OP_SeekLt==(OP_SeekLe-1) );
69647 assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69648 if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
69649 }
69650
69651 /* If the approximation iKey is smaller than the actual real search
69652 ** term, substitute <= for < and > for >=. */
69653 else if( pIn3->r>(double)iKey ){
69654 assert( OP_SeekLe==(OP_SeekLt+1) );
69655 assert( OP_SeekGt==(OP_SeekGe+1) );
69656 assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69657 if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
69658 }
69659 }
69660 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
69661 if( rc!=SQLITE_OK ){
69662 goto abort_due_to_error;
69663 }
69664 if( res==0 ){
69665 pC->rowidIsValid = 1;
69666 pC->lastRowid = iKey;
69667 }
69668 }else{
69669 nField = pOp->p4.i;
69670 assert( pOp->p4type==P4_INT32 );
69671 assert( nField>0 );
69672 r.pKeyInfo = pC->pKeyInfo;
69673 r.nField = (u16)nField;
69674
69675 /* The next line of code computes as follows, only faster:
69676 ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
69677 ** r.flags = UNPACKED_INCRKEY;
69678 ** }else{
69679 ** r.flags = 0;
69680 ** }
69681 */
69682 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
69683 assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
69684 assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
69685 assert( oc!=OP_SeekGe || r.flags==0 );
69686 assert( oc!=OP_SeekLt || r.flags==0 );
69687
69688 r.aMem = &aMem[pOp->p3];
69689 #ifdef SQLITE_DEBUG
69690 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
69691 #endif
69692 ExpandBlob(r.aMem);
69693 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
69694 if( rc!=SQLITE_OK ){
69695 goto abort_due_to_error;
69696 }
69697 pC->rowidIsValid = 0;
69698 }
69699 pC->deferredMoveto = 0;
69700 pC->cacheStatus = CACHE_STALE;
69701 #ifdef SQLITE_TEST
69702 sqlite3_search_count++;
69703 #endif
69704 if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
69705 if( res<0 || (res==0 && oc==OP_SeekGt) ){
69706 rc = sqlite3BtreeNext(pC->pCursor, &res);
69707 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69708 pC->rowidIsValid = 0;
69709 }else{
69710 res = 0;
69711 }
69712 }else{
69713 assert( oc==OP_SeekLt || oc==OP_SeekLe );
69714 if( res>0 || (res==0 && oc==OP_SeekLt) ){
69715 rc = sqlite3BtreePrevious(pC->pCursor, &res);
69716 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69717 pC->rowidIsValid = 0;
69718 }else{
69719 /* res might be negative because the table is empty. Check to
69720 ** see if this is the case.
69721 */
69722 res = sqlite3BtreeEof(pC->pCursor);
69723 }
69724 }
69725 assert( pOp->p2>0 );
69726 if( res ){
 
 
 
 
 
 
 
 
69727 pc = pOp->p2 - 1;
69728 }
69729 break;
69730 }
69731
@@ -70156,24 +69738,22 @@
69738 ** This is actually a deferred seek. Nothing actually happens until
69739 ** the cursor is used to read a record. That way, if no reads
69740 ** occur, no unnecessary I/O happens.
69741 */
69742 case OP_Seek: { /* in2 */
 
69743 VdbeCursor *pC;
 
69744
69745 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69746 pC = p->apCsr[pOp->p1];
69747 assert( pC!=0 );
69748 assert( pC->pCursor!=0 );
69749 assert( pC->isTable );
69750 pC->nullRow = 0;
69751 pIn2 = &aMem[pOp->p2];
69752 pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
69753 pC->rowidIsValid = 0;
69754 pC->deferredMoveto = 1;
69755 break;
69756 }
69757
69758
69759 /* Opcode: Found P1 P2 P3 P4 *
@@ -70224,85 +69804,83 @@
69804 ** See also: NotFound, Found, NotExists
69805 */
69806 case OP_NoConflict: /* jump, in3 */
69807 case OP_NotFound: /* jump, in3 */
69808 case OP_Found: { /* jump, in3 */
 
69809 int alreadyExists;
69810 int ii;
69811 VdbeCursor *pC;
69812 int res;
69813 char *pFree;
69814 UnpackedRecord *pIdxKey;
69815 UnpackedRecord r;
69816 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
 
69817
69818 #ifdef SQLITE_TEST
69819 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
69820 #endif
69821
 
69822 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69823 assert( pOp->p4type==P4_INT32 );
69824 pC = p->apCsr[pOp->p1];
69825 assert( pC!=0 );
69826 pIn3 = &aMem[pOp->p3];
69827 assert( pC->pCursor!=0 );
69828 assert( pC->isTable==0 );
69829 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
69830 if( pOp->p4.i>0 ){
69831 r.pKeyInfo = pC->pKeyInfo;
69832 r.nField = (u16)pOp->p4.i;
69833 r.aMem = pIn3;
69834 #ifdef SQLITE_DEBUG
69835 {
69836 int i;
69837 for(i=0; i<r.nField; i++){
69838 assert( memIsValid(&r.aMem[i]) );
69839 if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
69840 }
69841 }
69842 #endif
69843 r.flags = UNPACKED_PREFIX_MATCH;
69844 pIdxKey = &r;
69845 }else{
69846 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
69847 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
69848 );
69849 if( pIdxKey==0 ) goto no_mem;
69850 assert( pIn3->flags & MEM_Blob );
69851 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
69852 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
69853 pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
69854 }
69855 if( pOp->opcode==OP_NoConflict ){
69856 /* For the OP_NoConflict opcode, take the jump if any of the
69857 ** input fields are NULL, since any key with a NULL will not
69858 ** conflict */
69859 for(ii=0; ii<r.nField; ii++){
69860 if( r.aMem[ii].flags & MEM_Null ){
69861 pc = pOp->p2 - 1;
69862 break;
69863 }
69864 }
69865 }
69866 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
69867 if( pOp->p4.i==0 ){
69868 sqlite3DbFree(db, pFree);
69869 }
69870 if( rc!=SQLITE_OK ){
69871 break;
69872 }
69873 pC->seekResult = res;
69874 alreadyExists = (res==0);
69875 pC->nullRow = 1-alreadyExists;
69876 pC->deferredMoveto = 0;
69877 pC->cacheStatus = CACHE_STALE;
69878 if( pOp->opcode==OP_Found ){
69879 if( alreadyExists ) pc = pOp->p2 - 1;
69880 }else{
69881 if( !alreadyExists ) pc = pOp->p2 - 1;
69882 }
69883 break;
69884 }
69885
69886 /* Opcode: NotExists P1 P2 P3 * *
@@ -70318,39 +69896,37 @@
69896 ** (with arbitrary multi-value keys).
69897 **
69898 ** See also: Found, NotFound, NoConflict
69899 */
69900 case OP_NotExists: { /* jump, in3 */
 
69901 VdbeCursor *pC;
69902 BtCursor *pCrsr;
69903 int res;
69904 u64 iKey;
 
69905
69906 pIn3 = &aMem[pOp->p3];
69907 assert( pIn3->flags & MEM_Int );
69908 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69909 pC = p->apCsr[pOp->p1];
69910 assert( pC!=0 );
69911 assert( pC->isTable );
69912 assert( pC->pseudoTableReg==0 );
69913 pCrsr = pC->pCursor;
69914 assert( pCrsr!=0 );
69915 res = 0;
69916 iKey = pIn3->u.i;
69917 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
69918 pC->lastRowid = pIn3->u.i;
69919 pC->rowidIsValid = res==0 ?1:0;
69920 pC->nullRow = 0;
69921 pC->cacheStatus = CACHE_STALE;
69922 pC->deferredMoveto = 0;
69923 if( res!=0 ){
69924 pc = pOp->p2 - 1;
69925 assert( pC->rowidIsValid==0 );
69926 }
69927 pC->seekResult = res;
69928 break;
69929 }
69930
69931 /* Opcode: Sequence P1 P2 * * *
69932 ** Synopsis: r[P2]=rowid
@@ -70382,25 +69958,23 @@
69958 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
69959 ** generated record number. This P3 mechanism is used to help implement the
69960 ** AUTOINCREMENT feature.
69961 */
69962 case OP_NewRowid: { /* out2-prerelease */
 
69963 i64 v; /* The new rowid */
69964 VdbeCursor *pC; /* Cursor of table to get the new rowid */
69965 int res; /* Result of an sqlite3BtreeLast() */
69966 int cnt; /* Counter to limit the number of searches */
69967 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
69968 VdbeFrame *pFrame; /* Root frame of VDBE */
 
69969
69970 v = 0;
69971 res = 0;
69972 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69973 pC = p->apCsr[pOp->p1];
69974 assert( pC!=0 );
69975 if( NEVER(pC->pCursor==0) ){
69976 /* The zero initialization above is all that is needed */
69977 }else{
69978 /* The next rowid or record number (different terms for the same
69979 ** thing) is obtained in a two-step algorithm.
69980 **
@@ -70412,11 +69986,11 @@
69986 ** The second algorithm is to select a rowid at random and see if
69987 ** it already exists in the table. If it does not exist, we have
69988 ** succeeded. If the random rowid does exist, we select a new one
69989 ** and try again, up to 100 times.
69990 */
69991 assert( pC->isTable );
69992
69993 #ifdef SQLITE_32BIT_ROWID
69994 # define MAX_ROWID 0x7fffffff
69995 #else
69996 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70424,101 +69998,101 @@
69998 ** to provide the constant while making all compilers happy.
69999 */
70000 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70001 #endif
70002
70003 if( !pC->useRandomRowid ){
70004 v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70005 if( v==0 ){
70006 rc = sqlite3BtreeLast(pC->pCursor, &res);
70007 if( rc!=SQLITE_OK ){
70008 goto abort_due_to_error;
70009 }
70010 if( res ){
70011 v = 1; /* IMP: R-61914-48074 */
70012 }else{
70013 assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70014 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70015 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70016 if( v>=MAX_ROWID ){
70017 pC->useRandomRowid = 1;
70018 }else{
70019 v++; /* IMP: R-29538-34987 */
70020 }
70021 }
70022 }
70023
70024 #ifndef SQLITE_OMIT_AUTOINCREMENT
70025 if( pOp->p3 ){
70026 /* Assert that P3 is a valid memory cell. */
70027 assert( pOp->p3>0 );
70028 if( p->pFrame ){
70029 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70030 /* Assert that P3 is a valid memory cell. */
70031 assert( pOp->p3<=pFrame->nMem );
70032 pMem = &pFrame->aMem[pOp->p3];
70033 }else{
70034 /* Assert that P3 is a valid memory cell. */
70035 assert( pOp->p3<=(p->nMem-p->nCursor) );
70036 pMem = &aMem[pOp->p3];
70037 memAboutToChange(p, pMem);
70038 }
70039 assert( memIsValid(pMem) );
70040
70041 REGISTER_TRACE(pOp->p3, pMem);
70042 sqlite3VdbeMemIntegerify(pMem);
70043 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70044 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70045 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70046 goto abort_due_to_error;
70047 }
70048 if( v<pMem->u.i+1 ){
70049 v = pMem->u.i + 1;
70050 }
70051 pMem->u.i = v;
70052 }
70053 #endif
70054
70055 sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70056 }
70057 if( pC->useRandomRowid ){
70058 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70059 ** largest possible integer (9223372036854775807) then the database
70060 ** engine starts picking positive candidate ROWIDs at random until
70061 ** it finds one that is not previously used. */
70062 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
70063 ** an AUTOINCREMENT table. */
70064 /* on the first attempt, simply do one more than previous */
70065 v = lastRowid;
70066 v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70067 v++; /* ensure non-zero */
70068 cnt = 0;
70069 while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
70070 0, &res))==SQLITE_OK)
70071 && (res==0)
70072 && (++cnt<100)){
70073 /* collision - try another random rowid */
70074 sqlite3_randomness(sizeof(v), &v);
70075 if( cnt<5 ){
70076 /* try "small" random rowids for the initial attempts */
70077 v &= 0xffffff;
70078 }else{
70079 v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70080 }
70081 v++; /* ensure non-zero */
70082 }
70083 if( rc==SQLITE_OK && res==0 ){
70084 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
70085 goto abort_due_to_error;
70086 }
70087 assert( v>0 ); /* EV: R-40812-03570 */
70088 }
70089 pC->rowidIsValid = 0;
70090 pC->deferredMoveto = 0;
70091 pC->cacheStatus = CACHE_STALE;
70092 }
70093 pOut->u.i = v;
70094 break;
70095 }
70096
70097 /* Opcode: Insert P1 P2 P3 P4 P5
70098 ** Synopsis: intkey=r[P3] data=r[P2]
@@ -70566,74 +70140,72 @@
70140 ** This works exactly like OP_Insert except that the key is the
70141 ** integer value P3, not the value of the integer stored in register P3.
70142 */
70143 case OP_Insert:
70144 case OP_InsertInt: {
 
70145 Mem *pData; /* MEM cell holding data for the record to be inserted */
70146 Mem *pKey; /* MEM cell holding key for the record */
70147 i64 iKey; /* The integer ROWID or key for the record to be inserted */
70148 VdbeCursor *pC; /* Cursor to table into which insert is written */
70149 int nZero; /* Number of zero-bytes to append */
70150 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
70151 const char *zDb; /* database name - used by the update hook */
70152 const char *zTbl; /* Table name - used by the opdate hook */
70153 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
 
70154
70155 pData = &aMem[pOp->p2];
70156 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70157 assert( memIsValid(pData) );
70158 pC = p->apCsr[pOp->p1];
70159 assert( pC!=0 );
70160 assert( pC->pCursor!=0 );
70161 assert( pC->pseudoTableReg==0 );
70162 assert( pC->isTable );
70163 REGISTER_TRACE(pOp->p2, pData);
70164
70165 if( pOp->opcode==OP_Insert ){
70166 pKey = &aMem[pOp->p3];
70167 assert( pKey->flags & MEM_Int );
70168 assert( memIsValid(pKey) );
70169 REGISTER_TRACE(pOp->p3, pKey);
70170 iKey = pKey->u.i;
70171 }else{
70172 assert( pOp->opcode==OP_InsertInt );
70173 iKey = pOp->p3;
70174 }
70175
70176 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70177 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
70178 if( pData->flags & MEM_Null ){
70179 pData->z = 0;
70180 pData->n = 0;
70181 }else{
70182 assert( pData->flags & (MEM_Blob|MEM_Str) );
70183 }
70184 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
70185 if( pData->flags & MEM_Zero ){
70186 nZero = pData->u.nZero;
70187 }else{
70188 nZero = 0;
70189 }
70190 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70191 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70192 pData->z, pData->n, nZero,
70193 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
70194 );
70195 pC->rowidIsValid = 0;
70196 pC->deferredMoveto = 0;
70197 pC->cacheStatus = CACHE_STALE;
70198
70199 /* Invoke the update-hook if required. */
70200 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70201 zDb = db->aDb[pC->iDb].zName;
70202 zTbl = pOp->p4.z;
70203 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70204 assert( pC->isTable );
70205 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
70206 assert( pC->iDb>=0 );
70207 }
70208 break;
70209 }
70210
70211 /* Opcode: Delete P1 P2 * P4 *
@@ -70655,51 +70227,39 @@
70227 ** pointing to. The update hook will be invoked, if it exists.
70228 ** If P4 is not NULL then the P1 cursor must have been positioned
70229 ** using OP_NotFound prior to invoking this opcode.
70230 */
70231 case OP_Delete: {
 
70232 i64 iKey;
70233 VdbeCursor *pC;
 
70234
 
70235 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70236 pC = p->apCsr[pOp->p1];
70237 assert( pC!=0 );
70238 assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70239 iKey = pC->lastRowid; /* Only used for the update hook */
 
 
 
 
 
 
 
 
70240
70241 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
70242 ** OP_Column on the same table without any intervening operations that
70243 ** might move or invalidate the cursor. Hence cursor pC is always pointing
70244 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
70245 ** below is always a no-op and cannot fail. We will run it anyhow, though,
70246 ** to guard against future changes to the code generator.
70247 **/
70248 assert( pC->deferredMoveto==0 );
70249 rc = sqlite3VdbeCursorMoveto(pC);
70250 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70251
70252 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70253 rc = sqlite3BtreeDelete(pC->pCursor);
70254 pC->cacheStatus = CACHE_STALE;
70255
70256 /* Invoke the update-hook if required. */
70257 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
70258 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
70259 db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
70260 assert( pC->iDb>=0 );
 
70261 }
70262 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
70263 break;
70264 }
70265 /* Opcode: ResetCount * * * * *
@@ -70729,23 +70289,21 @@
70289 **
70290 ** Fall through to next instruction if the two records compare equal to
70291 ** each other. Jump to P2 if they are different.
70292 */
70293 case OP_SorterCompare: {
 
70294 VdbeCursor *pC;
70295 int res;
70296 int nIgnore;
 
70297
70298 pC = p->apCsr[pOp->p1];
70299 assert( isSorter(pC) );
70300 assert( pOp->p4type==P4_INT32 );
70301 pIn3 = &aMem[pOp->p3];
70302 nIgnore = pOp->p4.i;
70303 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70304 if( res ){
70305 pc = pOp->p2-1;
70306 }
70307 break;
70308 };
70309
@@ -70753,18 +70311,16 @@
70311 ** Synopsis: r[P2]=data
70312 **
70313 ** Write into register P2 the current sorter data for sorter cursor P1.
70314 */
70315 case OP_SorterData: {
 
70316 VdbeCursor *pC;
 
70317
70318 pOut = &aMem[pOp->p2];
70319 pC = p->apCsr[pOp->p1];
70320 assert( isSorter(pC) );
70321 rc = sqlite3VdbeSorterRowkey(pC, pOut);
70322 break;
70323 }
70324
70325 /* Opcode: RowData P1 P2 * * *
70326 ** Synopsis: r[P2]=data
@@ -70788,66 +70344,64 @@
70344 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70345 ** of a real table, not a pseudo-table.
70346 */
70347 case OP_RowKey:
70348 case OP_RowData: {
 
70349 VdbeCursor *pC;
70350 BtCursor *pCrsr;
70351 u32 n;
70352 i64 n64;
 
70353
70354 pOut = &aMem[pOp->p2];
70355 memAboutToChange(p, pOut);
70356
70357 /* Note that RowKey and RowData are really exactly the same instruction */
70358 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70359 pC = p->apCsr[pOp->p1];
70360 assert( isSorter(pC)==0 );
70361 assert( pC->isTable || pOp->opcode!=OP_RowData );
70362 assert( pC->isTable==0 || pOp->opcode==OP_RowData );
70363 assert( pC!=0 );
70364 assert( pC->nullRow==0 );
70365 assert( pC->pseudoTableReg==0 );
70366 assert( pC->pCursor!=0 );
70367 pCrsr = pC->pCursor;
70368 assert( sqlite3BtreeCursorIsValid(pCrsr) );
70369
70370 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
70371 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
70372 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
70373 ** a no-op and can never fail. But we leave it in place as a safety.
70374 */
70375 assert( pC->deferredMoveto==0 );
70376 rc = sqlite3VdbeCursorMoveto(pC);
70377 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70378
70379 if( pC->isTable==0 ){
70380 assert( !pC->isTable );
70381 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
70382 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70383 if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70384 goto too_big;
70385 }
70386 n = (u32)n64;
70387 }else{
70388 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n);
70389 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70390 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70391 goto too_big;
70392 }
70393 }
70394 if( sqlite3VdbeMemGrow(pOut, n, 0) ){
70395 goto no_mem;
70396 }
70397 pOut->n = n;
70398 MemSetTypeFlag(pOut, MEM_Blob);
70399 if( pC->isTable==0 ){
70400 rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z);
70401 }else{
70402 rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z);
70403 }
70404 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70405 UPDATE_MAX_BLOBSIZE(pOut);
70406 REGISTER_TRACE(pOp->p2, pOut);
70407 break;
@@ -70862,46 +70416,44 @@
70416 ** P1 can be either an ordinary table or a virtual table. There used to
70417 ** be a separate OP_VRowid opcode for use with virtual tables, but this
70418 ** one opcode now works for both table types.
70419 */
70420 case OP_Rowid: { /* out2-prerelease */
 
70421 VdbeCursor *pC;
70422 i64 v;
70423 sqlite3_vtab *pVtab;
70424 const sqlite3_module *pModule;
 
70425
70426 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70427 pC = p->apCsr[pOp->p1];
70428 assert( pC!=0 );
70429 assert( pC->pseudoTableReg==0 || pC->nullRow );
70430 if( pC->nullRow ){
70431 pOut->flags = MEM_Null;
70432 break;
70433 }else if( pC->deferredMoveto ){
70434 v = pC->movetoTarget;
70435 #ifndef SQLITE_OMIT_VIRTUALTABLE
70436 }else if( pC->pVtabCursor ){
70437 pVtab = pC->pVtabCursor->pVtab;
70438 pModule = pVtab->pModule;
70439 assert( pModule->xRowid );
70440 rc = pModule->xRowid(pC->pVtabCursor, &v);
70441 sqlite3VtabImportErrmsg(p, pVtab);
70442 #endif /* SQLITE_OMIT_VIRTUALTABLE */
70443 }else{
70444 assert( pC->pCursor!=0 );
70445 rc = sqlite3VdbeCursorMoveto(pC);
70446 if( rc ) goto abort_due_to_error;
70447 if( pC->rowidIsValid ){
70448 v = pC->lastRowid;
70449 }else{
70450 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70451 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
70452 }
70453 }
70454 pOut->u.i = v;
70455 break;
70456 }
70457
70458 /* Opcode: NullRow P1 * * * *
70459 **
@@ -70908,22 +70460,21 @@
70460 ** Move the cursor P1 to a null row. Any OP_Column operations
70461 ** that occur while the cursor is on the null row will always
70462 ** write a NULL.
70463 */
70464 case OP_NullRow: {
 
70465 VdbeCursor *pC;
 
70466
70467 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70468 pC = p->apCsr[pOp->p1];
70469 assert( pC!=0 );
70470 pC->nullRow = 1;
70471 pC->rowidIsValid = 0;
70472 pC->cacheStatus = CACHE_STALE;
70473 assert( pC->pCursor || pC->pVtabCursor );
70474 if( pC->pCursor ){
70475 sqlite3BtreeClearCursor(pC->pCursor);
70476 }
70477 break;
70478 }
70479
70480 /* Opcode: Last P1 P2 * * *
@@ -70933,28 +70484,26 @@
70484 ** If the table or index is empty and P2>0, then jump immediately to P2.
70485 ** If P2 is 0 or if the table or index is not empty, fall through
70486 ** to the following instruction.
70487 */
70488 case OP_Last: { /* jump */
 
70489 VdbeCursor *pC;
70490 BtCursor *pCrsr;
70491 int res;
 
70492
70493 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70494 pC = p->apCsr[pOp->p1];
70495 assert( pC!=0 );
70496 pCrsr = pC->pCursor;
70497 res = 0;
70498 assert( pCrsr!=0 );
70499 rc = sqlite3BtreeLast(pCrsr, &res);
70500 pC->nullRow = (u8)res;
70501 pC->deferredMoveto = 0;
70502 pC->rowidIsValid = 0;
70503 pC->cacheStatus = CACHE_STALE;
70504 if( pOp->p2>0 && res ){
70505 pc = pOp->p2 - 1;
70506 }
70507 break;
70508 }
70509
@@ -70987,35 +70536,32 @@
70536 ** If the table or index is empty and P2>0, then jump immediately to P2.
70537 ** If P2 is 0 or if the table or index is not empty, fall through
70538 ** to the following instruction.
70539 */
70540 case OP_Rewind: { /* jump */
 
70541 VdbeCursor *pC;
70542 BtCursor *pCrsr;
70543 int res;
 
70544
70545 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70546 pC = p->apCsr[pOp->p1];
70547 assert( pC!=0 );
70548 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
70549 res = 1;
70550 if( isSorter(pC) ){
70551 rc = sqlite3VdbeSorterRewind(db, pC, &res);
70552 }else{
70553 pCrsr = pC->pCursor;
70554 assert( pCrsr );
70555 rc = sqlite3BtreeFirst(pCrsr, &res);
70556 pC->deferredMoveto = 0;
70557 pC->cacheStatus = CACHE_STALE;
70558 pC->rowidIsValid = 0;
70559 }
70560 pC->nullRow = (u8)res;
 
70561 assert( pOp->p2>0 && pOp->p2<p->nOp );
70562 if( res ){
70563 pc = pOp->p2 - 1;
70564 }
70565 break;
70566 }
70567
@@ -71024,71 +70570,85 @@
70570 ** Advance cursor P1 so that it points to the next key/data pair in its
70571 ** table or index. If there are no more key/value pairs then fall through
70572 ** to the following instruction. But if the cursor advance was successful,
70573 ** jump immediately to P2.
70574 **
70575 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
70576 ** been opened prior to this opcode or the program will segfault.
70577 **
70578 ** P4 is always of type P4_ADVANCE. The function pointer points to
70579 ** sqlite3BtreeNext().
70580 **
70581 ** If P5 is positive and the jump is taken, then event counter
70582 ** number P5-1 in the prepared statement is incremented.
70583 **
70584 ** See also: Prev, NextIfOpen
70585 */
70586 /* Opcode: NextIfOpen P1 P2 * * P5
70587 **
70588 ** This opcode works just like OP_Next except that if cursor P1 is not
70589 ** open it behaves a no-op.
70590 */
70591 /* Opcode: Prev P1 P2 * * P5
70592 **
70593 ** Back up cursor P1 so that it points to the previous key/data pair in its
70594 ** table or index. If there is no previous key/value pairs then fall through
70595 ** to the following instruction. But if the cursor backup was successful,
70596 ** jump immediately to P2.
70597 **
70598 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
70599 ** not open then the behavior is undefined.
70600 **
70601 ** P4 is always of type P4_ADVANCE. The function pointer points to
70602 ** sqlite3BtreePrevious().
70603 **
70604 ** If P5 is positive and the jump is taken, then event counter
70605 ** number P5-1 in the prepared statement is incremented.
70606 */
70607 /* Opcode: PrevIfOpen P1 P2 * * P5
70608 **
70609 ** This opcode works just like OP_Prev except that if cursor P1 is not
70610 ** open it behaves a no-op.
70611 */
70612 case OP_SorterNext: { /* jump */
70613 VdbeCursor *pC;
70614 int res;
70615
70616 pC = p->apCsr[pOp->p1];
70617 assert( isSorter(pC) );
70618 rc = sqlite3VdbeSorterNext(db, pC, &res);
70619 goto next_tail;
70620 case OP_PrevIfOpen: /* jump */
70621 case OP_NextIfOpen: /* jump */
70622 if( p->apCsr[pOp->p1]==0 ) break;
70623 /* Fall through */
70624 case OP_Prev: /* jump */
70625 case OP_Next: /* jump */
 
 
 
 
 
70626 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70627 assert( pOp->p5<ArraySize(p->aCounter) );
70628 pC = p->apCsr[pOp->p1];
70629 assert( pC!=0 );
70630 assert( pC->deferredMoveto==0 );
70631 assert( pC->pCursor );
70632 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
70633 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
70634 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
70635 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
70636 rc = pOp->p4.xAdvance(pC->pCursor, &res);
70637 next_tail:
70638 pC->cacheStatus = CACHE_STALE;
70639 if( res==0 ){
70640 pC->nullRow = 0;
 
 
 
 
 
 
70641 pc = pOp->p2 - 1;
70642 p->aCounter[pOp->p5]++;
70643 #ifdef SQLITE_TEST
70644 sqlite3_search_count++;
70645 #endif
70646 }else{
70647 pC->nullRow = 1;
70648 }
70649 pC->rowidIsValid = 0;
70650 goto check_for_interrupt;
70651 }
70652
70653 /* Opcode: IdxInsert P1 P2 P3 * P5
70654 ** Synopsis: key=r[P2]
@@ -71103,39 +70663,37 @@
70663 ** This instruction only works for indices. The equivalent instruction
70664 ** for tables is OP_Insert.
70665 */
70666 case OP_SorterInsert: /* in2 */
70667 case OP_IdxInsert: { /* in2 */
 
70668 VdbeCursor *pC;
70669 BtCursor *pCrsr;
70670 int nKey;
70671 const char *zKey;
 
70672
70673 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70674 pC = p->apCsr[pOp->p1];
70675 assert( pC!=0 );
70676 assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) );
70677 pIn2 = &aMem[pOp->p2];
70678 assert( pIn2->flags & MEM_Blob );
70679 pCrsr = pC->pCursor;
70680 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70681 assert( pCrsr!=0 );
70682 assert( pC->isTable==0 );
70683 rc = ExpandBlob(pIn2);
70684 if( rc==SQLITE_OK ){
70685 if( isSorter(pC) ){
70686 rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
70687 }else{
70688 nKey = pIn2->n;
70689 zKey = pIn2->z;
70690 rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3,
70691 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
70692 );
70693 assert( pC->deferredMoveto==0 );
70694 pC->cacheStatus = CACHE_STALE;
70695 }
70696 }
70697 break;
70698 }
70699
@@ -71145,38 +70703,36 @@
70703 ** The content of P3 registers starting at register P2 form
70704 ** an unpacked index key. This opcode removes that entry from the
70705 ** index opened by cursor P1.
70706 */
70707 case OP_IdxDelete: {
 
70708 VdbeCursor *pC;
70709 BtCursor *pCrsr;
70710 int res;
70711 UnpackedRecord r;
 
70712
70713 assert( pOp->p3>0 );
70714 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
70715 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70716 pC = p->apCsr[pOp->p1];
70717 assert( pC!=0 );
70718 pCrsr = pC->pCursor;
70719 assert( pCrsr!=0 );
70720 assert( pOp->p5==0 );
70721 r.pKeyInfo = pC->pKeyInfo;
70722 r.nField = (u16)pOp->p3;
70723 r.flags = UNPACKED_PREFIX_MATCH;
70724 r.aMem = &aMem[pOp->p2];
70725 #ifdef SQLITE_DEBUG
70726 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70727 #endif
70728 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
70729 if( rc==SQLITE_OK && res==0 ){
70730 rc = sqlite3BtreeDelete(pCrsr);
70731 }
70732 assert( pC->deferredMoveto==0 );
70733 pC->cacheStatus = CACHE_STALE;
70734 break;
70735 }
70736
70737 /* Opcode: IdxRowid P1 P2 * * *
70738 ** Synopsis: r[P2]=rowid
@@ -71186,32 +70742,31 @@
70742 ** the rowid of the table entry to which this index entry points.
70743 **
70744 ** See also: Rowid, MakeRecord.
70745 */
70746 case OP_IdxRowid: { /* out2-prerelease */
 
70747 BtCursor *pCrsr;
70748 VdbeCursor *pC;
70749 i64 rowid;
 
70750
70751 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70752 pC = p->apCsr[pOp->p1];
70753 assert( pC!=0 );
70754 pCrsr = pC->pCursor;
70755 assert( pCrsr!=0 );
70756 pOut->flags = MEM_Null;
70757 rc = sqlite3VdbeCursorMoveto(pC);
70758 if( NEVER(rc) ) goto abort_due_to_error;
70759 assert( pC->deferredMoveto==0 );
70760 assert( pC->isTable==0 );
70761 if( !pC->nullRow ){
70762 rowid = 0; /* Not needed. Only used to silence a warning. */
70763 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
70764 if( rc!=SQLITE_OK ){
70765 goto abort_due_to_error;
70766 }
70767 pOut->u.i = rowid;
70768 pOut->flags = MEM_Int;
70769 }
70770 break;
70771 }
70772
@@ -71243,43 +70798,42 @@
70798 ** If P5 is non-zero then the key value is increased by an epsilon prior
70799 ** to the comparison. This makes the opcode work like IdxLE.
70800 */
70801 case OP_IdxLT: /* jump */
70802 case OP_IdxGE: { /* jump */
 
70803 VdbeCursor *pC;
70804 int res;
70805 UnpackedRecord r;
 
70806
70807 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70808 pC = p->apCsr[pOp->p1];
70809 assert( pC!=0 );
70810 assert( pC->isOrdered );
70811 assert( pC->pCursor!=0);
70812 assert( pC->deferredMoveto==0 );
70813 assert( pOp->p5==0 || pOp->p5==1 );
70814 assert( pOp->p4type==P4_INT32 );
70815 r.pKeyInfo = pC->pKeyInfo;
70816 r.nField = (u16)pOp->p4.i;
70817 if( pOp->p5 ){
70818 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
70819 }else{
70820 r.flags = UNPACKED_PREFIX_MATCH;
70821 }
70822 r.aMem = &aMem[pOp->p3];
70823 #ifdef SQLITE_DEBUG
70824 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70825 #endif
70826 res = 0; /* Not needed. Only used to silence a warning. */
70827 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
70828 if( pOp->opcode==OP_IdxLT ){
70829 res = -res;
70830 }else{
70831 assert( pOp->opcode==OP_IdxGE );
70832 res++;
70833 }
70834 if( res>0 ){
70835 pc = pOp->p2 - 1 ;
70836 }
70837 break;
70838 }
70839
@@ -71302,47 +70856,46 @@
70856 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
70857 **
70858 ** See also: Clear
70859 */
70860 case OP_Destroy: { /* out2-prerelease */
 
70861 int iMoved;
70862 int iCnt;
70863 Vdbe *pVdbe;
70864 int iDb;
 
70865
70866 assert( p->readOnly==0 );
70867 #ifndef SQLITE_OMIT_VIRTUALTABLE
70868 iCnt = 0;
70869 for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){
70870 if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader
70871 && pVdbe->inVtabMethod<2 && pVdbe->pc>=0
70872 ){
70873 iCnt++;
70874 }
70875 }
70876 #else
70877 iCnt = db->nVdbeRead;
70878 #endif
70879 pOut->flags = MEM_Null;
70880 if( iCnt>1 ){
70881 rc = SQLITE_LOCKED;
70882 p->errorAction = OE_Abort;
70883 }else{
70884 iDb = pOp->p3;
70885 assert( iCnt==1 );
70886 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
70887 iMoved = 0; /* Not needed. Only to silence a warning. */
70888 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
70889 pOut->flags = MEM_Int;
70890 pOut->u.i = iMoved;
70891 #ifndef SQLITE_OMIT_AUTOVACUUM
70892 if( rc==SQLITE_OK && iMoved!=0 ){
70893 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
70894 /* All OP_Destroy operations occur on the same btree */
70895 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
70896 resetSchemaOnFault = iDb+1;
70897 }
70898 #endif
70899 }
70900 break;
70901 }
@@ -71364,27 +70917,25 @@
70917 ** also incremented by the number of rows in the table being cleared.
70918 **
70919 ** See also: Destroy
70920 */
70921 case OP_Clear: {
 
70922 int nChange;
70923
70924 nChange = 0;
 
70925 assert( p->readOnly==0 );
70926 assert( pOp->p1!=1 );
70927 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
70928 rc = sqlite3BtreeClearTable(
70929 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
70930 );
70931 if( pOp->p3 ){
70932 p->nChange += nChange;
70933 if( pOp->p3>0 ){
70934 assert( memIsValid(&aMem[pOp->p3]) );
70935 memAboutToChange(p, &aMem[pOp->p3]);
70936 aMem[pOp->p3].u.i += nChange;
70937 }
70938 }
70939 break;
70940 }
70941
@@ -71412,30 +70963,28 @@
70963 **
70964 ** See documentation on OP_CreateTable for additional information.
70965 */
70966 case OP_CreateIndex: /* out2-prerelease */
70967 case OP_CreateTable: { /* out2-prerelease */
 
70968 int pgno;
70969 int flags;
70970 Db *pDb;
 
70971
70972 pgno = 0;
70973 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70974 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70975 assert( p->readOnly==0 );
70976 pDb = &db->aDb[pOp->p1];
70977 assert( pDb->pBt!=0 );
70978 if( pOp->opcode==OP_CreateTable ){
70979 /* flags = BTREE_INTKEY; */
70980 flags = BTREE_INTKEY;
70981 }else{
70982 flags = BTREE_BLOBKEY;
70983 }
70984 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
70985 pOut->u.i = pgno;
70986 break;
70987 }
70988
70989 /* Opcode: ParseSchema P1 * * P4 *
70990 **
@@ -71444,56 +70993,54 @@
70993 **
70994 ** This opcode invokes the parser to create a new virtual machine,
70995 ** then runs the new virtual machine. It is thus a re-entrant opcode.
70996 */
70997 case OP_ParseSchema: {
 
70998 int iDb;
70999 const char *zMaster;
71000 char *zSql;
71001 InitData initData;
 
71002
71003 /* Any prepared statement that invokes this opcode will hold mutexes
71004 ** on every btree. This is a prerequisite for invoking
71005 ** sqlite3InitCallback().
71006 */
71007 #ifdef SQLITE_DEBUG
71008 for(iDb=0; iDb<db->nDb; iDb++){
71009 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
71010 }
71011 #endif
71012
71013 iDb = pOp->p1;
71014 assert( iDb>=0 && iDb<db->nDb );
71015 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
71016 /* Used to be a conditional */ {
71017 zMaster = SCHEMA_TABLE(iDb);
71018 initData.db = db;
71019 initData.iDb = pOp->p1;
71020 initData.pzErrMsg = &p->zErrMsg;
71021 zSql = sqlite3MPrintf(db,
71022 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
71023 db->aDb[iDb].zName, zMaster, pOp->p4.z);
71024 if( zSql==0 ){
71025 rc = SQLITE_NOMEM;
71026 }else{
71027 assert( db->init.busy==0 );
71028 db->init.busy = 1;
71029 initData.rc = SQLITE_OK;
71030 assert( !db->mallocFailed );
71031 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
71032 if( rc==SQLITE_OK ) rc = initData.rc;
71033 sqlite3DbFree(db, zSql);
71034 db->init.busy = 0;
71035 }
71036 }
71037 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
71038 if( rc==SQLITE_NOMEM ){
71039 goto no_mem;
71040 }
71041 break;
71042 }
71043
71044 #if !defined(SQLITE_OMIT_ANALYZE)
71045 /* Opcode: LoadAnalysis P1 * * * *
71046 **
@@ -71565,46 +71112,44 @@
71112 ** file, not the main database file.
71113 **
71114 ** This opcode is used to implement the integrity_check pragma.
71115 */
71116 case OP_IntegrityCk: {
 
71117 int nRoot; /* Number of tables to check. (Number of root pages.) */
71118 int *aRoot; /* Array of rootpage numbers for tables to be checked */
71119 int j; /* Loop counter */
71120 int nErr; /* Number of errors reported */
71121 char *z; /* Text of the error report */
71122 Mem *pnErr; /* Register keeping track of errors remaining */
 
71123
71124 assert( p->bIsReader );
71125 nRoot = pOp->p2;
71126 assert( nRoot>0 );
71127 aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
71128 if( aRoot==0 ) goto no_mem;
71129 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71130 pnErr = &aMem[pOp->p3];
71131 assert( (pnErr->flags & MEM_Int)!=0 );
71132 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
71133 pIn1 = &aMem[pOp->p1];
71134 for(j=0; j<nRoot; j++){
71135 aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
71136 }
71137 aRoot[j] = 0;
71138 assert( pOp->p5<db->nDb );
71139 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
71140 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
71141 (int)pnErr->u.i, &nErr);
71142 sqlite3DbFree(db, aRoot);
71143 pnErr->u.i -= nErr;
71144 sqlite3VdbeMemSetNull(pIn1);
71145 if( nErr==0 ){
71146 assert( z==0 );
71147 }else if( z==0 ){
71148 goto no_mem;
71149 }else{
71150 sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
71151 }
71152 UPDATE_MAX_BLOBSIZE(pIn1);
71153 sqlite3VdbeChangeEncoding(pIn1, encoding);
71154 break;
71155 }
@@ -71636,24 +71181,22 @@
71181 ** Extract the smallest value from boolean index P1 and put that value into
71182 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71183 ** unchanged and jump to instruction P2.
71184 */
71185 case OP_RowSetRead: { /* jump, in1, out3 */
 
71186 i64 val;
 
71187
71188 pIn1 = &aMem[pOp->p1];
71189 if( (pIn1->flags & MEM_RowSet)==0
71190 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71191 ){
71192 /* The boolean index is empty */
71193 sqlite3VdbeMemSetNull(pIn1);
71194 pc = pOp->p2 - 1;
71195 }else{
71196 /* A value was pulled from the index */
71197 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71198 }
71199 goto check_for_interrupt;
71200 }
71201
71202 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71679,18 +71222,16 @@
71222 ** inserted, there is no need to search to see if the same value was
71223 ** previously inserted as part of set X (only if it was previously
71224 ** inserted as part of some other set).
71225 */
71226 case OP_RowSetTest: { /* jump, in1, in3 */
 
71227 int iSet;
71228 int exists;
 
71229
71230 pIn1 = &aMem[pOp->p1];
71231 pIn3 = &aMem[pOp->p3];
71232 iSet = pOp->p4.i;
71233 assert( pIn3->flags&MEM_Int );
71234
71235 /* If there is anything other than a rowset object in memory cell P1,
71236 ** delete it now and initialize P1 with an empty rowset
71237 */
@@ -71698,21 +71239,21 @@
71239 sqlite3VdbeMemSetRowSet(pIn1);
71240 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
71241 }
71242
71243 assert( pOp->p4type==P4_INT32 );
71244 assert( iSet==-1 || iSet>=0 );
71245 if( iSet ){
71246 exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71247 (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71248 pIn3->u.i);
71249 if( exists ){
71250 pc = pOp->p2 - 1;
71251 break;
71252 }
71253 }
71254 if( iSet>=0 ){
71255 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
71256 }
71257 break;
71258 }
71259
@@ -71731,111 +71272,109 @@
71272 ** memory required by the sub-vdbe at runtime.
71273 **
71274 ** P4 is a pointer to the VM containing the trigger program.
71275 */
71276 case OP_Program: { /* jump */
 
71277 int nMem; /* Number of memory registers for sub-program */
71278 int nByte; /* Bytes of runtime space required for sub-program */
71279 Mem *pRt; /* Register to allocate runtime space */
71280 Mem *pMem; /* Used to iterate through memory cells */
71281 Mem *pEnd; /* Last memory cell in new array */
71282 VdbeFrame *pFrame; /* New vdbe frame to execute in */
71283 SubProgram *pProgram; /* Sub-program to execute */
71284 void *t; /* Token identifying trigger */
 
71285
71286 pProgram = pOp->p4.pProgram;
71287 pRt = &aMem[pOp->p3];
71288 assert( pProgram->nOp>0 );
71289
71290 /* If the p5 flag is clear, then recursive invocation of triggers is
71291 ** disabled for backwards compatibility (p5 is set if this sub-program
71292 ** is really a trigger, not a foreign key action, and the flag set
71293 ** and cleared by the "PRAGMA recursive_triggers" command is clear).
71294 **
71295 ** It is recursive invocation of triggers, at the SQL level, that is
71296 ** disabled. In some cases a single trigger may generate more than one
71297 ** SubProgram (if the trigger may be executed with more than one different
71298 ** ON CONFLICT algorithm). SubProgram structures associated with a
71299 ** single trigger all have the same value for the SubProgram.token
71300 ** variable. */
71301 if( pOp->p5 ){
71302 t = pProgram->token;
71303 for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent);
71304 if( pFrame ) break;
71305 }
71306
71307 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
71308 rc = SQLITE_ERROR;
71309 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
71310 break;
71311 }
71312
71313 /* Register pRt is used to store the memory required to save the state
71314 ** of the current program, and the memory required at runtime to execute
71315 ** the trigger program. If this trigger has been fired before, then pRt
71316 ** is already allocated. Otherwise, it must be initialized. */
71317 if( (pRt->flags&MEM_Frame)==0 ){
71318 /* SubProgram.nMem is set to the number of memory cells used by the
71319 ** program stored in SubProgram.aOp. As well as these, one memory
71320 ** cell is required for each cursor used by the program. Set local
71321 ** variable nMem (and later, VdbeFrame.nChildMem) to this value.
71322 */
71323 nMem = pProgram->nMem + pProgram->nCsr;
71324 nByte = ROUND8(sizeof(VdbeFrame))
71325 + nMem * sizeof(Mem)
71326 + pProgram->nCsr * sizeof(VdbeCursor *)
71327 + pProgram->nOnce * sizeof(u8);
71328 pFrame = sqlite3DbMallocZero(db, nByte);
71329 if( !pFrame ){
71330 goto no_mem;
71331 }
71332 sqlite3VdbeMemRelease(pRt);
71333 pRt->flags = MEM_Frame;
71334 pRt->u.pFrame = pFrame;
71335
71336 pFrame->v = p;
71337 pFrame->nChildMem = nMem;
71338 pFrame->nChildCsr = pProgram->nCsr;
71339 pFrame->pc = pc;
71340 pFrame->aMem = p->aMem;
71341 pFrame->nMem = p->nMem;
71342 pFrame->apCsr = p->apCsr;
71343 pFrame->nCursor = p->nCursor;
71344 pFrame->aOp = p->aOp;
71345 pFrame->nOp = p->nOp;
71346 pFrame->token = pProgram->token;
71347 pFrame->aOnceFlag = p->aOnceFlag;
71348 pFrame->nOnceFlag = p->nOnceFlag;
71349
71350 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71351 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71352 pMem->flags = MEM_Invalid;
71353 pMem->db = db;
71354 }
71355 }else{
71356 pFrame = pRt->u.pFrame;
71357 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
71358 assert( pProgram->nCsr==pFrame->nChildCsr );
71359 assert( pc==pFrame->pc );
71360 }
71361
71362 p->nFrame++;
71363 pFrame->pParent = p->pFrame;
71364 pFrame->lastRowid = lastRowid;
71365 pFrame->nChange = p->nChange;
71366 p->nChange = 0;
71367 p->pFrame = pFrame;
71368 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
71369 p->nMem = pFrame->nChildMem;
71370 p->nCursor = (u16)pFrame->nChildCsr;
71371 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71372 p->aOp = aOp = pProgram->aOp;
71373 p->nOp = pProgram->nOp;
71374 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71375 p->nOnceFlag = pProgram->nOnce;
71376 pc = -1;
71377 memset(p->aOnceFlag, 0, p->nOnceFlag);
71378
71379 break;
71380 }
@@ -71851,17 +71390,15 @@
71390 ** The address of the cell in the parent frame is determined by adding
71391 ** the value of the P1 argument to the value of the P1 argument to the
71392 ** calling OP_Program instruction.
71393 */
71394 case OP_Param: { /* out2-prerelease */
 
71395 VdbeFrame *pFrame;
71396 Mem *pIn;
71397 pFrame = p->pFrame;
71398 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
71399 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
 
71400 break;
71401 }
71402
71403 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71404
@@ -71918,26 +71455,23 @@
71455 **
71456 ** This instruction throws an error if the memory cell is not initially
71457 ** an integer.
71458 */
71459 case OP_MemMax: { /* in2 */
 
 
71460 VdbeFrame *pFrame;
 
71461 if( p->pFrame ){
71462 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
71463 pIn1 = &pFrame->aMem[pOp->p1];
71464 }else{
71465 pIn1 = &aMem[pOp->p1];
71466 }
71467 assert( memIsValid(pIn1) );
71468 sqlite3VdbeMemIntegerify(pIn1);
71469 pIn2 = &aMem[pOp->p2];
71470 sqlite3VdbeMemIntegerify(pIn2);
71471 if( pIn1->u.i<pIn2->u.i){
71472 pIn1->u.i = pIn2->u.i;
71473 }
71474 break;
71475 }
71476 #endif /* SQLITE_OMIT_AUTOINCREMENT */
71477
@@ -72004,60 +71538,58 @@
71538 **
71539 ** The P5 arguments are taken from register P2 and its
71540 ** successors.
71541 */
71542 case OP_AggStep: {
 
71543 int n;
71544 int i;
71545 Mem *pMem;
71546 Mem *pRec;
71547 sqlite3_context ctx;
71548 sqlite3_value **apVal;
71549
71550 n = pOp->p5;
71551 assert( n>=0 );
71552 pRec = &aMem[pOp->p2];
71553 apVal = p->apArg;
71554 assert( apVal || n==0 );
71555 for(i=0; i<n; i++, pRec++){
71556 assert( memIsValid(pRec) );
71557 apVal[i] = pRec;
71558 memAboutToChange(p, pRec);
71559 sqlite3VdbeMemStoreType(pRec);
71560 }
71561 ctx.pFunc = pOp->p4.pFunc;
 
71562 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71563 ctx.pMem = pMem = &aMem[pOp->p3];
71564 pMem->n++;
71565 ctx.s.flags = MEM_Null;
71566 ctx.s.z = 0;
71567 ctx.s.zMalloc = 0;
71568 ctx.s.xDel = 0;
71569 ctx.s.db = db;
71570 ctx.isError = 0;
71571 ctx.pColl = 0;
71572 ctx.skipFlag = 0;
71573 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
71574 assert( pOp>p->aOp );
71575 assert( pOp[-1].p4type==P4_COLLSEQ );
71576 assert( pOp[-1].opcode==OP_CollSeq );
71577 ctx.pColl = pOp[-1].p4.pColl;
71578 }
71579 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
71580 if( ctx.isError ){
71581 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
71582 rc = ctx.isError;
71583 }
71584 if( ctx.skipFlag ){
71585 assert( pOp[-1].opcode==OP_CollSeq );
71586 i = pOp[-1].p1;
71587 if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1);
71588 }
71589
71590 sqlite3VdbeMemRelease(&ctx.s);
71591
71592 break;
71593 }
71594
71595 /* Opcode: AggFinal P1 P2 * P4 *
@@ -72072,23 +71604,21 @@
71604 ** functions that can take varying numbers of arguments. The
71605 ** P4 argument is only needed for the degenerate case where
71606 ** the step function was not previously called.
71607 */
71608 case OP_AggFinal: {
 
71609 Mem *pMem;
 
71610 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71611 pMem = &aMem[pOp->p1];
71612 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
71613 rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
71614 if( rc ){
71615 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
71616 }
71617 sqlite3VdbeChangeEncoding(pMem, encoding);
71618 UPDATE_MAX_BLOBSIZE(pMem);
71619 if( sqlite3VdbeMemTooBig(pMem) ){
71620 goto too_big;
71621 }
71622 break;
71623 }
71624
@@ -72103,31 +71633,29 @@
71633 ** in the WAL that have been checkpointed after the checkpoint
71634 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
71635 ** mem[P3+2] are initialized to -1.
71636 */
71637 case OP_Checkpoint: {
 
71638 int i; /* Loop counter */
71639 int aRes[3]; /* Results */
71640 Mem *pMem; /* Write results here */
 
71641
71642 assert( p->readOnly==0 );
71643 aRes[0] = 0;
71644 aRes[1] = aRes[2] = -1;
71645 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
71646 || pOp->p2==SQLITE_CHECKPOINT_FULL
71647 || pOp->p2==SQLITE_CHECKPOINT_RESTART
71648 );
71649 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
71650 if( rc==SQLITE_BUSY ){
71651 rc = SQLITE_OK;
71652 aRes[0] = 1;
71653 }
71654 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
71655 sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]);
71656 }
71657 break;
71658 };
71659 #endif
71660
71661 #ifndef SQLITE_OMIT_PRAGMA
@@ -72141,98 +71669,96 @@
71669 ** If changing into or out of WAL mode the procedure is more complicated.
71670 **
71671 ** Write a string containing the final journal-mode to register P2.
71672 */
71673 case OP_JournalMode: { /* out2-prerelease */
 
71674 Btree *pBt; /* Btree to change journal mode of */
71675 Pager *pPager; /* Pager associated with pBt */
71676 int eNew; /* New journal mode */
71677 int eOld; /* The old journal mode */
71678 #ifndef SQLITE_OMIT_WAL
71679 const char *zFilename; /* Name of database file for pPager */
71680 #endif
71681
71682 eNew = pOp->p3;
71683 assert( eNew==PAGER_JOURNALMODE_DELETE
71684 || eNew==PAGER_JOURNALMODE_TRUNCATE
71685 || eNew==PAGER_JOURNALMODE_PERSIST
71686 || eNew==PAGER_JOURNALMODE_OFF
71687 || eNew==PAGER_JOURNALMODE_MEMORY
71688 || eNew==PAGER_JOURNALMODE_WAL
71689 || eNew==PAGER_JOURNALMODE_QUERY
 
71690 );
71691 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71692 assert( p->readOnly==0 );
71693
71694 pBt = db->aDb[pOp->p1].pBt;
71695 pPager = sqlite3BtreePager(pBt);
71696 eOld = sqlite3PagerGetJournalMode(pPager);
71697 if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld;
71698 if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld;
71699
71700 #ifndef SQLITE_OMIT_WAL
71701 zFilename = sqlite3PagerFilename(pPager, 1);
71702
71703 /* Do not allow a transition to journal_mode=WAL for a database
71704 ** in temporary storage or if the VFS does not support shared memory
71705 */
71706 if( eNew==PAGER_JOURNALMODE_WAL
71707 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
71708 || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */
71709 ){
71710 eNew = eOld;
71711 }
71712
71713 if( (eNew!=eOld)
71714 && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL)
71715 ){
71716 if( !db->autoCommit || db->nVdbeRead>1 ){
71717 rc = SQLITE_ERROR;
71718 sqlite3SetString(&p->zErrMsg, db,
71719 "cannot change %s wal mode from within a transaction",
71720 (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
71721 );
71722 break;
71723 }else{
71724
71725 if( eOld==PAGER_JOURNALMODE_WAL ){
71726 /* If leaving WAL mode, close the log file. If successful, the call
71727 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
71728 ** file. An EXCLUSIVE lock may still be held on the database file
71729 ** after a successful return.
71730 */
71731 rc = sqlite3PagerCloseWal(pPager);
71732 if( rc==SQLITE_OK ){
71733 sqlite3PagerSetJournalMode(pPager, eNew);
71734 }
71735 }else if( eOld==PAGER_JOURNALMODE_MEMORY ){
71736 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
71737 ** as an intermediate */
71738 sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF);
71739 }
71740
71741 /* Open a transaction on the database file. Regardless of the journal
71742 ** mode, this transaction always uses a rollback journal.
71743 */
71744 assert( sqlite3BtreeIsInTrans(pBt)==0 );
71745 if( rc==SQLITE_OK ){
71746 rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
71747 }
71748 }
71749 }
71750 #endif /* ifndef SQLITE_OMIT_WAL */
71751
71752 if( rc ){
71753 eNew = eOld;
71754 }
71755 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
71756
71757 pOut = &aMem[pOp->p2];
71758 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71759 pOut->z = (char *)sqlite3JournalModename(eNew);
71760 pOut->n = sqlite3Strlen30(pOut->z);
71761 pOut->enc = SQLITE_UTF8;
71762 sqlite3VdbeChangeEncoding(pOut, encoding);
71763 break;
71764 };
@@ -72258,19 +71784,17 @@
71784 ** Perform a single step of the incremental vacuum procedure on
71785 ** the P1 database. If the vacuum has finished, jump to instruction
71786 ** P2. Otherwise, fall through to the next instruction.
71787 */
71788 case OP_IncrVacuum: { /* jump */
 
71789 Btree *pBt;
 
71790
71791 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71792 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71793 assert( p->readOnly==0 );
71794 pBt = db->aDb[pOp->p1].pBt;
71795 rc = sqlite3BtreeIncrVacuum(pBt);
71796 if( rc==SQLITE_DONE ){
71797 pc = pOp->p2 - 1;
71798 rc = SQLITE_OK;
71799 }
71800 break;
@@ -72337,16 +71861,14 @@
71861 ** Also, whether or not P4 is set, check that this is not being called from
71862 ** within a callback to a virtual table xSync() method. If it is, the error
71863 ** code will be set to SQLITE_LOCKED.
71864 */
71865 case OP_VBegin: {
 
71866 VTable *pVTab;
71867 pVTab = pOp->p4.pVtab;
71868 rc = sqlite3VtabBegin(db, pVTab);
71869 if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab);
 
71870 break;
71871 }
71872 #endif /* SQLITE_OMIT_VIRTUALTABLE */
71873
71874 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72381,37 +71903,34 @@
71903 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
71904 ** P1 is a cursor number. This opcode opens a cursor to the virtual
71905 ** table and stores that cursor in P1.
71906 */
71907 case OP_VOpen: {
 
71908 VdbeCursor *pCur;
71909 sqlite3_vtab_cursor *pVtabCursor;
71910 sqlite3_vtab *pVtab;
71911 sqlite3_module *pModule;
 
71912
71913 assert( p->bIsReader );
71914 pCur = 0;
71915 pVtabCursor = 0;
71916 pVtab = pOp->p4.pVtab->pVtab;
71917 pModule = (sqlite3_module *)pVtab->pModule;
71918 assert(pVtab && pModule);
71919 rc = pModule->xOpen(pVtab, &pVtabCursor);
71920 sqlite3VtabImportErrmsg(p, pVtab);
71921 if( SQLITE_OK==rc ){
71922 /* Initialize sqlite3_vtab_cursor base class */
71923 pVtabCursor->pVtab = pVtab;
71924
71925 /* Initialize vdbe cursor object */
71926 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
71927 if( pCur ){
71928 pCur->pVtabCursor = pVtabCursor;
 
71929 }else{
71930 db->mallocFailed = 1;
71931 pModule->xClose(pVtabCursor);
71932 }
71933 }
71934 break;
71935 }
71936 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72435,11 +71954,10 @@
71954 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
71955 **
71956 ** A jump is made to P2 if the result set after filtering would be empty.
71957 */
71958 case OP_VFilter: { /* jump */
 
71959 int nArg;
71960 int iQuery;
71961 const sqlite3_module *pModule;
71962 Mem *pQuery;
71963 Mem *pArgc;
@@ -72447,49 +71965,48 @@
71965 sqlite3_vtab *pVtab;
71966 VdbeCursor *pCur;
71967 int res;
71968 int i;
71969 Mem **apArg;
71970
71971 pQuery = &aMem[pOp->p3];
71972 pArgc = &pQuery[1];
71973 pCur = p->apCsr[pOp->p1];
71974 assert( memIsValid(pQuery) );
71975 REGISTER_TRACE(pOp->p3, pQuery);
71976 assert( pCur->pVtabCursor );
71977 pVtabCursor = pCur->pVtabCursor;
71978 pVtab = pVtabCursor->pVtab;
71979 pModule = pVtab->pModule;
 
71980
71981 /* Grab the index number and argc parameters */
71982 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
71983 nArg = (int)pArgc->u.i;
71984 iQuery = (int)pQuery->u.i;
71985
71986 /* Invoke the xFilter method */
71987 {
71988 res = 0;
71989 apArg = p->apArg;
71990 for(i = 0; i<nArg; i++){
71991 apArg[i] = &pArgc[i+1];
71992 sqlite3VdbeMemStoreType(apArg[i]);
71993 }
71994
71995 p->inVtabMethod = 1;
71996 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
71997 p->inVtabMethod = 0;
71998 sqlite3VtabImportErrmsg(p, pVtab);
71999 if( rc==SQLITE_OK ){
72000 res = pModule->xEof(pVtabCursor);
72001 }
72002
72003 if( res ){
72004 pc = pOp->p2 - 1;
72005 }
72006 }
72007 pCur->nullRow = 0;
72008
72009 break;
72010 }
72011 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72012
@@ -72500,55 +72017,53 @@
72017 ** Store the value of the P2-th column of
72018 ** the row of the virtual-table that the
72019 ** P1 cursor is pointing to into register P3.
72020 */
72021 case OP_VColumn: {
 
72022 sqlite3_vtab *pVtab;
72023 const sqlite3_module *pModule;
72024 Mem *pDest;
72025 sqlite3_context sContext;
 
72026
72027 VdbeCursor *pCur = p->apCsr[pOp->p1];
72028 assert( pCur->pVtabCursor );
72029 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72030 pDest = &aMem[pOp->p3];
72031 memAboutToChange(p, pDest);
72032 if( pCur->nullRow ){
72033 sqlite3VdbeMemSetNull(pDest);
72034 break;
72035 }
72036 pVtab = pCur->pVtabCursor->pVtab;
72037 pModule = pVtab->pModule;
72038 assert( pModule->xColumn );
72039 memset(&sContext, 0, sizeof(sContext));
72040
72041 /* The output cell may already have a buffer allocated. Move
72042 ** the current contents to sContext.s so in case the user-function
72043 ** can use the already allocated buffer instead of allocating a
72044 ** new one.
72045 */
72046 sqlite3VdbeMemMove(&sContext.s, pDest);
72047 MemSetTypeFlag(&sContext.s, MEM_Null);
72048
72049 rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
72050 sqlite3VtabImportErrmsg(p, pVtab);
72051 if( sContext.isError ){
72052 rc = sContext.isError;
72053 }
72054
72055 /* Copy the result of the function to the P3 register. We
72056 ** do this regardless of whether or not an error occurred to ensure any
72057 ** dynamic allocation in sContext.s (a Mem struct) is released.
72058 */
72059 sqlite3VdbeChangeEncoding(&sContext.s, encoding);
72060 sqlite3VdbeMemMove(pDest, &sContext.s);
72061 REGISTER_TRACE(pOp->p3, pDest);
72062 UPDATE_MAX_BLOBSIZE(pDest);
72063
72064 if( sqlite3VdbeMemTooBig(pDest) ){
72065 goto too_big;
72066 }
72067 break;
72068 }
72069 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72559,42 +72074,40 @@
72074 ** Advance virtual table P1 to the next row in its result set and
72075 ** jump to instruction P2. Or, if the virtual table has reached
72076 ** the end of its result set, then fall through to the next instruction.
72077 */
72078 case OP_VNext: { /* jump */
 
72079 sqlite3_vtab *pVtab;
72080 const sqlite3_module *pModule;
72081 int res;
72082 VdbeCursor *pCur;
 
72083
72084 res = 0;
72085 pCur = p->apCsr[pOp->p1];
72086 assert( pCur->pVtabCursor );
72087 if( pCur->nullRow ){
72088 break;
72089 }
72090 pVtab = pCur->pVtabCursor->pVtab;
72091 pModule = pVtab->pModule;
72092 assert( pModule->xNext );
72093
72094 /* Invoke the xNext() method of the module. There is no way for the
72095 ** underlying implementation to return an error if one occurs during
72096 ** xNext(). Instead, if an error occurs, true is returned (indicating that
72097 ** data is available) and the error code returned when xColumn or
72098 ** some other method is next invoked on the save virtual table cursor.
72099 */
72100 p->inVtabMethod = 1;
72101 rc = pModule->xNext(pCur->pVtabCursor);
72102 p->inVtabMethod = 0;
72103 sqlite3VtabImportErrmsg(p, pVtab);
72104 if( rc==SQLITE_OK ){
72105 res = pModule->xEof(pCur->pVtabCursor);
72106 }
72107
72108 if( !res ){
72109 /* If there is data, jump to P2 */
72110 pc = pOp->p2 - 1;
72111 }
72112 goto check_for_interrupt;
72113 }
@@ -72606,29 +72119,27 @@
72119 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72120 ** This opcode invokes the corresponding xRename method. The value
72121 ** in register P1 is passed as the zName argument to the xRename method.
72122 */
72123 case OP_VRename: {
 
72124 sqlite3_vtab *pVtab;
72125 Mem *pName;
 
72126
72127 pVtab = pOp->p4.pVtab->pVtab;
72128 pName = &aMem[pOp->p1];
72129 assert( pVtab->pModule->xRename );
72130 assert( memIsValid(pName) );
72131 assert( p->readOnly==0 );
72132 REGISTER_TRACE(pOp->p1, pName);
72133 assert( pName->flags & MEM_Str );
72134 testcase( pName->enc==SQLITE_UTF8 );
72135 testcase( pName->enc==SQLITE_UTF16BE );
72136 testcase( pName->enc==SQLITE_UTF16LE );
72137 rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8);
72138 if( rc==SQLITE_OK ){
72139 rc = pVtab->pModule->xRename(pVtab, pName->z);
72140 sqlite3VtabImportErrmsg(p, pVtab);
72141 p->expired = 0;
72142 }
72143 break;
72144 }
72145 #endif
@@ -72657,46 +72168,44 @@
72168 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72169 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72170 ** is set to the value of the rowid for the row just inserted.
72171 */
72172 case OP_VUpdate: {
 
72173 sqlite3_vtab *pVtab;
72174 sqlite3_module *pModule;
72175 int nArg;
72176 int i;
72177 sqlite_int64 rowid;
72178 Mem **apArg;
72179 Mem *pX;
 
72180
72181 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72182 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
72183 );
72184 assert( p->readOnly==0 );
72185 pVtab = pOp->p4.pVtab->pVtab;
72186 pModule = (sqlite3_module *)pVtab->pModule;
72187 nArg = pOp->p2;
72188 assert( pOp->p4type==P4_VTAB );
72189 if( ALWAYS(pModule->xUpdate) ){
72190 u8 vtabOnConflict = db->vtabOnConflict;
72191 apArg = p->apArg;
72192 pX = &aMem[pOp->p3];
72193 for(i=0; i<nArg; i++){
72194 assert( memIsValid(pX) );
72195 memAboutToChange(p, pX);
72196 sqlite3VdbeMemStoreType(pX);
72197 apArg[i] = pX;
72198 pX++;
72199 }
72200 db->vtabOnConflict = pOp->p5;
72201 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
72202 db->vtabOnConflict = vtabOnConflict;
72203 sqlite3VtabImportErrmsg(p, pVtab);
72204 if( rc==SQLITE_OK && pOp->p1 ){
72205 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
72206 db->lastRowid = lastRowid = rowid;
72207 }
72208 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
72209 if( pOp->p5==OE_Ignore ){
72210 rc = SQLITE_OK;
72211 }else{
@@ -72752,38 +72261,36 @@
72261 **
72262 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72263 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72264 */
72265 case OP_Trace: {
 
72266 char *zTrace;
72267 char *z;
 
72268
72269 if( db->xTrace
72270 && !p->doingRerun
72271 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72272 ){
72273 z = sqlite3VdbeExpandSql(p, zTrace);
72274 db->xTrace(db->pTraceArg, z);
72275 sqlite3DbFree(db, z);
72276 }
72277 #ifdef SQLITE_USE_FCNTL_TRACE
72278 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72279 if( zTrace ){
72280 int i;
72281 for(i=0; i<db->nDb; i++){
72282 if( ((1<<i) & p->btreeMask)==0 ) continue;
72283 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
72284 }
72285 }
72286 #endif /* SQLITE_USE_FCNTL_TRACE */
72287 #ifdef SQLITE_DEBUG
72288 if( (db->flags & SQLITE_SqlTrace)!=0
72289 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72290 ){
72291 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72292 }
72293 #endif /* SQLITE_DEBUG */
72294 break;
72295 }
72296 #endif
@@ -72832,17 +72339,17 @@
72339 */
72340 #ifndef NDEBUG
72341 assert( pc>=-1 && pc<p->nOp );
72342
72343 #ifdef SQLITE_DEBUG
72344 if( db->flags & SQLITE_VdbeTrace ){
72345 if( rc!=0 ) printf("rc=%d\n",rc);
72346 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
72347 registerTrace(pOp->p2, &aMem[pOp->p2]);
72348 }
72349 if( pOp->opflags & OPFLG_OUT3 ){
72350 registerTrace(pOp->p3, &aMem[pOp->p3]);
72351 }
72352 }
72353 #endif /* SQLITE_DEBUG */
72354 #endif /* NDEBUG */
72355 } /* The end of the for(;;) loop the loops through opcodes */
@@ -72908,10 +72415,11 @@
72415 rc = SQLITE_INTERRUPT;
72416 p->rc = rc;
72417 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
72418 goto vdbe_error_halt;
72419 }
72420
72421
72422 /************** End of vdbe.c ************************************************/
72423 /************** Begin file vdbeblob.c ****************************************/
72424 /*
72425 ** 2007 May 1
@@ -72975,22 +72483,23 @@
72483 assert( v->aVar[0].flags&MEM_Int );
72484 v->aVar[0].u.i = iRow;
72485
72486 rc = sqlite3_step(p->pStmt);
72487 if( rc==SQLITE_ROW ){
72488 VdbeCursor *pC = v->apCsr[0];
72489 u32 type = pC->aType[p->iCol];
72490 if( type<12 ){
72491 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
72492 type==0?"null": type==7?"real": "integer"
72493 );
72494 rc = SQLITE_ERROR;
72495 sqlite3_finalize(p->pStmt);
72496 p->pStmt = 0;
72497 }else{
72498 p->iOffset = pC->aType[p->iCol + pC->nField];
72499 p->nByte = sqlite3VdbeSerialTypeLen(type);
72500 p->pCsr = pC->pCursor;
72501 sqlite3BtreeEnterCursor(p->pCsr);
72502 sqlite3BtreeCacheOverflow(p->pCsr);
72503 sqlite3BtreeLeaveCursor(p->pCsr);
72504 }
72505 }
@@ -73239,10 +72748,11 @@
72748 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
72749 sqlite3DbFree(db, pBlob);
72750 }
72751 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
72752 sqlite3DbFree(db, zErr);
72753 sqlite3ParserReset(pParse);
72754 sqlite3StackFree(db, pParse);
72755 rc = sqlite3ApiExit(db, rc);
72756 sqlite3_mutex_leave(db->mutex);
72757 return rc;
72758 }
@@ -75204,14 +74714,14 @@
74714 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
74715 incrAggFunctionDepth(pDup, nSubquery);
74716 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
74717 if( pDup==0 ) return;
74718 ExprSetProperty(pDup, EP_Skip);
74719 if( pEList->a[iCol].u.x.iAlias==0 ){
74720 pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
74721 }
74722 pDup->iTable = pEList->a[iCol].u.x.iAlias;
74723 }
74724 if( pExpr->op==TK_COLLATE ){
74725 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
74726 }
74727
@@ -75448,11 +74958,13 @@
74958 }
74959 break;
74960 }
74961 }
74962 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
74963 /* IMP: R-24309-18625 */
74964 /* IMP: R-44911-55124 */
74965 iCol = -1;
74966 }
74967 if( iCol<pTab->nCol ){
74968 cnt++;
74969 if( iCol<0 ){
74970 pExpr->affinity = SQLITE_AFF_INTEGER;
@@ -75763,11 +75275,10 @@
75275 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
75276 }
75277
75278 /* Resolve function names
75279 */
 
75280 case TK_FUNCTION: {
75281 ExprList *pList = pExpr->x.pList; /* The argument list */
75282 int n = pList ? pList->nExpr : 0; /* Number of arguments */
75283 int no_such_func = 0; /* True if no such function exists */
75284 int wrong_num_args = 0; /* True if wrong number of arguments */
@@ -75776,11 +75287,10 @@
75287 int nId; /* Number of characters in function name */
75288 const char *zId; /* The function name. */
75289 FuncDef *pDef; /* Information about the function */
75290 u8 enc = ENC(pParse->db); /* The database encoding */
75291
 
75292 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
75293 notValidPartIdxWhere(pParse, pNC, "functions");
75294 zId = pExpr->u.zToken;
75295 nId = sqlite3Strlen30(zId);
75296 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
@@ -75821,10 +75331,11 @@
75331 pNC->nErr++;
75332 }
75333 pExpr->op = TK_NULL;
75334 return WRC_Prune;
75335 }
75336 if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
75337 }
75338 #endif
75339 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
75340 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
75341 pNC->nErr++;
@@ -76072,11 +75583,11 @@
75583 assert( pItem->pExpr->op==TK_COLLATE );
75584 assert( pItem->pExpr->pLeft==pE );
75585 pItem->pExpr->pLeft = pNew;
75586 }
75587 sqlite3ExprDelete(db, pE);
75588 pItem->u.x.iOrderByCol = (u16)iCol;
75589 pItem->done = 1;
75590 }else{
75591 moreToDo = 1;
75592 }
75593 }
@@ -76093,12 +75604,12 @@
75604 }
75605
75606 /*
75607 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
75608 ** the SELECT statement pSelect. If any term is reference to a
75609 ** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
75610 ** field) then convert that term into a copy of the corresponding result set
75611 ** column.
75612 **
75613 ** If any errors are detected, add an error message to pParse and
75614 ** return non-zero. Return zero if no errors are seen.
75615 */
@@ -76121,16 +75632,16 @@
75632 }
75633 #endif
75634 pEList = pSelect->pEList;
75635 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
75636 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
75637 if( pItem->u.x.iOrderByCol ){
75638 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
75639 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
75640 return 1;
75641 }
75642 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0);
75643 }
75644 }
75645 return 0;
75646 }
75647
@@ -76175,11 +75686,11 @@
75686 if( iCol>0 ){
75687 /* If an AS-name match is found, mark this ORDER BY column as being
75688 ** a copy of the iCol-th result-set column. The subsequent call to
75689 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
75690 ** copy of the iCol-th result-set expression. */
75691 pItem->u.x.iOrderByCol = (u16)iCol;
75692 continue;
75693 }
75694 }
75695 if( sqlite3ExprIsInteger(pE2, &iCol) ){
75696 /* The ORDER BY term is an integer constant. Again, set the column
@@ -76187,22 +75698,22 @@
75698 ** order-by term to a copy of the result-set expression */
75699 if( iCol<1 || iCol>0xffff ){
75700 resolveOutOfRangeError(pParse, zType, i+1, nResult);
75701 return 1;
75702 }
75703 pItem->u.x.iOrderByCol = (u16)iCol;
75704 continue;
75705 }
75706
75707 /* Otherwise, treat the ORDER BY term as an ordinary expression */
75708 pItem->u.x.iOrderByCol = 0;
75709 if( sqlite3ResolveExprNames(pNC, pE) ){
75710 return 1;
75711 }
75712 for(j=0; j<pSelect->pEList->nExpr; j++){
75713 if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
75714 pItem->u.x.iOrderByCol = j+1;
75715 }
75716 }
75717 }
75718 return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
75719 }
@@ -77477,12 +76988,11 @@
76988 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
76989 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
76990 pItem->sortOrder = pOldItem->sortOrder;
76991 pItem->done = 0;
76992 pItem->bSpanIsTab = pOldItem->bSpanIsTab;
76993 pItem->u = pOldItem->u;
 
76994 }
76995 return pNew;
76996 }
76997
76998 /*
@@ -77739,13 +77249,16 @@
77249 return WRC_Abort;
77250 }
77251
77252 switch( pExpr->op ){
77253 /* Consider functions to be constant if all their arguments are constant
77254 ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST
77255 ** flag. */
77256 case TK_FUNCTION:
77257 if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){
77258 return WRC_Continue;
77259 }
77260 /* Fall through */
77261 case TK_ID:
77262 case TK_COLUMN:
77263 case TK_AGG_FUNCTION:
77264 case TK_AGG_COLUMN:
@@ -78903,10 +78416,11 @@
78416 int inReg = target; /* Results stored in register inReg */
78417 int regFree1 = 0; /* If non-zero free this temporary register */
78418 int regFree2 = 0; /* If non-zero free this temporary register */
78419 int r1, r2, r3, r4; /* Various register numbers */
78420 sqlite3 *db = pParse->db; /* The database connection */
78421 Expr tempX; /* Temporary expression node */
78422
78423 assert( target>0 && target<=pParse->nMem );
78424 if( v==0 ){
78425 assert( pParse->db->mallocFailed );
78426 return 0;
@@ -79122,12 +78636,14 @@
78636 }else if( pLeft->op==TK_FLOAT ){
78637 assert( !ExprHasProperty(pExpr, EP_IntValue) );
78638 codeReal(v, pLeft->u.zToken, 1, target);
78639 #endif
78640 }else{
78641 tempX.op = TK_INTEGER;
78642 tempX.flags = EP_IntValue|EP_TokenOnly;
78643 tempX.u.iValue = 0;
78644 r1 = sqlite3ExprCodeTemp(pParse, &tempX, &regFree1);
78645 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree2);
78646 sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
78647 testcase( regFree2==0 );
78648 }
78649 inReg = target;
@@ -79168,11 +78684,10 @@
78684 }else{
78685 inReg = pInfo->aFunc[pExpr->iAgg].iMem;
78686 }
78687 break;
78688 }
 
78689 case TK_FUNCTION: {
78690 ExprList *pFarg; /* List of function arguments */
78691 int nFarg; /* Number of function arguments */
78692 FuncDef *pDef; /* The function definition object */
78693 int nId; /* Length of the function name in bytes */
@@ -79181,12 +78696,10 @@
78696 int i; /* Loop counter */
78697 u8 enc = ENC(db); /* The text encoding used by this database */
78698 CollSeq *pColl = 0; /* A collating sequence */
78699
78700 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
 
 
78701 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
78702 pFarg = 0;
78703 }else{
78704 pFarg = pExpr->x.pList;
78705 }
@@ -79226,12 +78739,25 @@
78739 assert( nFarg>=1 );
78740 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
78741 break;
78742 }
78743
78744 for(i=0; i<nFarg; i++){
78745 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
78746 constMask |= (1<<i);
78747 }
78748 if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
78749 pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
78750 }
78751 }
78752 if( pFarg ){
78753 if( constMask ){
78754 r1 = pParse->nMem+1;
78755 pParse->nMem += nFarg;
78756 }else{
78757 r1 = sqlite3GetTempRange(pParse, nFarg);
78758 }
78759
78760 /* For length() and typeof() functions with a column argument,
78761 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
78762 ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
78763 ** loading.
@@ -79242,18 +78768,19 @@
78768 assert( pFarg->a[0].pExpr!=0 );
78769 exprOp = pFarg->a[0].pExpr->op;
78770 if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
78771 assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
78772 assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
78773 testcase( pDef->funcFlags & OPFLAG_LENGTHARG );
78774 pFarg->a[0].pExpr->op2 =
78775 pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
78776 }
78777 }
78778
78779 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
78780 sqlite3ExprCodeExprList(pParse, pFarg, r1,
78781 SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
78782 sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */
78783 }else{
78784 r1 = 0;
78785 }
78786 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -79273,26 +78800,18 @@
78800 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
78801 }else if( nFarg>0 ){
78802 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
78803 }
78804 #endif
 
 
 
 
 
 
 
 
78805 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
78806 if( !pColl ) pColl = db->pDfltColl;
78807 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
78808 }
78809 sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
78810 (char*)pDef, P4_FUNCDEF);
78811 sqlite3VdbeChangeP5(v, (u8)nFarg);
78812 if( nFarg && constMask==0 ){
78813 sqlite3ReleaseTempRange(pParse, r1, nFarg);
78814 }
78815 break;
78816 }
78817 #ifndef SQLITE_OMIT_SUBQUERY
@@ -79439,11 +78958,10 @@
78958 int nExpr; /* 2x number of WHEN terms */
78959 int i; /* Loop counter */
78960 ExprList *pEList; /* List of WHEN terms */
78961 struct ExprList_item *aListelem; /* Array of WHEN terms */
78962 Expr opCompare; /* The X==Ei expression */
 
78963 Expr *pX; /* The X expression */
78964 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
78965 VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
78966
78967 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
@@ -79451,17 +78969,16 @@
78969 pEList = pExpr->x.pList;
78970 aListelem = pEList->a;
78971 nExpr = pEList->nExpr;
78972 endLabel = sqlite3VdbeMakeLabel(v);
78973 if( (pX = pExpr->pLeft)!=0 ){
78974 tempX = *pX;
78975 testcase( pX->op==TK_COLUMN );
78976 exprToRegister(&tempX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
 
78977 testcase( regFree1==0 );
78978 opCompare.op = TK_EQ;
78979 opCompare.pLeft = &tempX;
78980 pTest = &opCompare;
78981 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
78982 ** The value in regFree1 might get SCopy-ed into the file result.
78983 ** So make sure that the regFree1 register is not reused for other
78984 ** purposes and possibly overwritten. */
@@ -79477,11 +78994,10 @@
78994 }
78995 nextCase = sqlite3VdbeMakeLabel(v);
78996 testcase( pTest->op==TK_COLUMN );
78997 sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
78998 testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
 
78999 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
79000 sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
79001 sqlite3ExprCachePop(pParse, 1);
79002 sqlite3VdbeResolveLabel(v, nextCase);
79003 }
@@ -79527,28 +79043,75 @@
79043 }
79044 sqlite3ReleaseTempReg(pParse, regFree1);
79045 sqlite3ReleaseTempReg(pParse, regFree2);
79046 return inReg;
79047 }
79048
79049 /*
79050 ** Factor out the code of the given expression to initialization time.
79051 */
79052 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(
79053 Parse *pParse, /* Parsing context */
79054 Expr *pExpr, /* The expression to code when the VDBE initializes */
79055 int regDest, /* Store the value in this register */
79056 u8 reusable /* True if this expression is reusable */
79057 ){
79058 ExprList *p;
79059 assert( ConstFactorOk(pParse) );
79060 p = pParse->pConstExpr;
79061 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
79062 p = sqlite3ExprListAppend(pParse, p, pExpr);
79063 if( p ){
79064 struct ExprList_item *pItem = &p->a[p->nExpr-1];
79065 pItem->u.iConstExprReg = regDest;
79066 pItem->reusable = reusable;
79067 }
79068 pParse->pConstExpr = p;
79069 }
79070
79071 /*
79072 ** Generate code to evaluate an expression and store the results
79073 ** into a register. Return the register number where the results
79074 ** are stored.
79075 **
79076 ** If the register is a temporary register that can be deallocated,
79077 ** then write its number into *pReg. If the result register is not
79078 ** a temporary, then set *pReg to zero.
79079 **
79080 ** If pExpr is a constant, then this routine might generate this
79081 ** code to fill the register in the initialization section of the
79082 ** VDBE program, in order to factor it out of the evaluation loop.
79083 */
79084 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79085 int r2;
79086 pExpr = sqlite3ExprSkipCollate(pExpr);
79087 if( ConstFactorOk(pParse)
79088 && pExpr->op!=TK_REGISTER
79089 && sqlite3ExprIsConstantNotJoin(pExpr)
79090 ){
79091 ExprList *p = pParse->pConstExpr;
79092 int i;
79093 *pReg = 0;
79094 if( p ){
79095 struct ExprList_item *pItem;
79096 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
79097 if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
79098 return pItem->u.iConstExprReg;
79099 }
79100 }
79101 }
79102 r2 = ++pParse->nMem;
79103 sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
79104 }else{
79105 int r1 = sqlite3GetTempReg(pParse);
79106 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79107 if( r2==r1 ){
79108 *pReg = r1;
79109 }else{
79110 sqlite3ReleaseTempReg(pParse, r1);
79111 *pReg = 0;
79112 }
79113 }
79114 return r2;
79115 }
79116
79117 /*
@@ -79587,16 +79150,17 @@
79150 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79151 Vdbe *v = pParse->pVdbe;
79152 int inReg;
79153 inReg = sqlite3ExprCode(pParse, pExpr, target);
79154 assert( target>0 );
79155 /* The only place, other than this routine, where expressions can be
79156 ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79157 ** CASE operators. Neither ever calls this routine. And this routine
79158 ** is never called twice on the same expression. Hence it is impossible
79159 ** for the input to this routine to already be a register. Nevertheless,
79160 ** it seems prudent to keep the ALWAYS() in case the conditions above
79161 ** change with future modifications or enhancements. */
79162 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79163 int iMem;
79164 iMem = ++pParse->nMem;
79165 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79166 exprToRegister(pExpr, iMem);
@@ -79724,11 +79288,10 @@
79288 sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
79289 break;
79290 }
79291
79292 case TK_AGG_FUNCTION:
 
79293 case TK_FUNCTION: {
79294 ExprList *pFarg; /* List of function arguments */
79295 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79296 pFarg = 0;
79297 }else{
@@ -79874,169 +79437,46 @@
79437 }
79438 sqlite3ExplainPop(pOut);
79439 }
79440 }
79441 #endif /* SQLITE_DEBUG */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79442
79443 /*
79444 ** Generate code that pushes the value of every element of the given
79445 ** expression list into a sequence of registers beginning at target.
79446 **
79447 ** Return the number of elements evaluated.
79448 **
79449 ** The SQLITE_ECEL_DUP flag prevents the arguments from being
79450 ** filled using OP_SCopy. OP_Copy must be used instead.
79451 **
79452 ** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
79453 ** factored out into initialization code.
79454 */
79455 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
79456 Parse *pParse, /* Parsing context */
79457 ExprList *pList, /* The expression list to be coded */
79458 int target, /* Where to write results */
79459 u8 flags /* SQLITE_ECEL_* flags */
79460 ){
79461 struct ExprList_item *pItem;
79462 int i, n;
79463 u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
79464 assert( pList!=0 );
79465 assert( target>0 );
79466 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
79467 n = pList->nExpr;
79468 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
79469 for(pItem=pList->a, i=0; i<n; i++, pItem++){
79470 Expr *pExpr = pItem->pExpr;
79471 if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
79472 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
79473 }else{
79474 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
79475 if( inReg!=target+i ){
79476 sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i);
79477 }
79478 }
79479 }
79480 return n;
79481 }
79482
@@ -80386,44 +79826,46 @@
79826 ** this routine is used, it does not hurt to get an extra 2 - that
79827 ** just might result in some slightly slower code. But returning
79828 ** an incorrect 0 or 1 could lead to a malfunction.
79829 */
79830 SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
79831 u32 combinedFlags;
79832 if( pA==0 || pB==0 ){
79833 return pB==pA ? 0 : 2;
79834 }
79835 combinedFlags = pA->flags | pB->flags;
79836 if( combinedFlags & EP_IntValue ){
79837 if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
79838 return 0;
79839 }
79840 return 2;
79841 }
79842 if( pA->op!=pB->op ){
 
79843 if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB, iTab)<2 ){
79844 return 1;
79845 }
79846 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
79847 return 1;
79848 }
79849 return 2;
79850 }
79851 if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
 
 
 
 
 
 
 
 
 
 
 
 
79852 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
79853 return pA->op==TK_COLLATE ? 1 : 2;
79854 }
79855 }
79856 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
79857 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
79858 if( combinedFlags & EP_xIsSelect ) return 2;
79859 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
79860 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
79861 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
79862 if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
79863 if( pA->iColumn!=pB->iColumn ) return 2;
79864 if( pA->iTable!=pB->iTable
79865 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
79866 }
79867 }
79868 return 0;
79869 }
79870
79871 /*
@@ -83076,14 +82518,16 @@
82518 }
82519 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
82520 if( pTable==0 ){
82521 return 0;
82522 }
82523 if( argv[1]==0 ){
 
 
82524 pIndex = 0;
82525 }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
82526 pIndex = sqlite3PrimaryKeyIndex(pTable);
82527 }else{
82528 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
82529 }
82530 z = argv[2];
82531
82532 if( pIndex ){
82533 decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
@@ -84394,11 +83838,11 @@
83838 ** transaction on each used database and to verify the schema cookie
83839 ** on each used database.
83840 */
83841 if( pParse->cookieGoto>0 ){
83842 yDbMask mask;
83843 int iDb, i, addr;
83844 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
83845 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
83846 if( (mask & pParse->cookieMask)==0 ) continue;
83847 sqlite3VdbeUsesBtree(v, iDb);
83848 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
@@ -84408,18 +83852,15 @@
83852 iDb, pParse->cookieValue[iDb],
83853 db->aDb[iDb].pSchema->iGeneration);
83854 }
83855 }
83856 #ifndef SQLITE_OMIT_VIRTUALTABLE
83857 for(i=0; i<pParse->nVtabLock; i++){
83858 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
83859 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
83860 }
83861 pParse->nVtabLock = 0;
 
 
 
83862 #endif
83863
83864 /* Once all the cookies have been verified and transactions opened,
83865 ** obtain the required table-locks. This is a no-op unless the
83866 ** shared-cache feature is enabled.
@@ -84427,24 +83868,30 @@
83868 codeTableLocks(pParse);
83869
83870 /* Initialize any AUTOINCREMENT data structures required.
83871 */
83872 sqlite3AutoincrementBegin(pParse);
83873
83874 /* Code constant expressions that where factored out of inner loops */
83875 addr = pParse->cookieGoto;
83876 if( pParse->pConstExpr ){
83877 ExprList *pEL = pParse->pConstExpr;
83878 pParse->cookieGoto = 0;
83879 for(i=0; i<pEL->nExpr; i++){
83880 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
83881 }
83882 }
83883
83884 /* Finally, jump back to the beginning of the executable code. */
83885 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
83886 }
83887 }
83888
83889
83890 /* Get the VDBE program ready for execution
83891 */
83892 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
 
 
 
 
83893 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
83894 /* A minimum of one cursor is required if autoincrement is used
83895 * See ticket [a696379c1f08866] */
83896 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
83897 sqlite3VdbeMakeReady(v, pParse);
@@ -87031,11 +86478,11 @@
86478 Token *pName = 0; /* Unqualified name of the index to create */
86479 struct ExprList_item *pListItem; /* For looping over pList */
86480 const Column *pTabCol; /* A column in the table */
86481 int nExtra = 0; /* Space allocated for zExtra[] */
86482 int nExtraCol; /* Number of extra columns needed */
86483 char *zExtra = 0; /* Extra space after the Index object */
86484 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
86485
86486 assert( pParse->nErr==0 ); /* Never called with prior errors */
86487 if( db->mallocFailed || IN_DECLARE_VTAB ){
86488 goto exit_create_index;
@@ -88230,13 +87677,13 @@
87677 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
87678 errMsg.db = pParse->db;
87679 for(j=0; j<pIdx->nKeyCol; j++){
87680 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
87681 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
87682 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
87683 sqlite3StrAccumAppend(&errMsg, ".", 1);
87684 sqlite3StrAccumAppendAll(&errMsg, zCol);
87685 }
87686 zErr = sqlite3StrAccumFinish(&errMsg);
87687 sqlite3HaltConstraint(pParse,
87688 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
87689 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88424,12 +87871,13 @@
87871 }
87872 if( pKey ){
87873 assert( sqlite3KeyInfoIsWriteable(pKey) );
87874 for(i=0; i<nCol; i++){
87875 char *zColl = pIdx->azColl[i];
87876 assert( zColl!=0 );
87877 pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
87878 sqlite3LocateCollSeq(pParse, zColl);
87879 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
87880 }
87881 if( pParse->nErr ){
87882 sqlite3KeyInfoUnref(pKey);
87883 }else{
@@ -89148,24 +88596,38 @@
88596 Expr *pWhere /* The WHERE clause. May be null */
88597 ){
88598 Vdbe *v; /* The virtual database engine */
88599 Table *pTab; /* The table from which records will be deleted */
88600 const char *zDb; /* Name of database holding pTab */
 
88601 int i; /* Loop counter */
88602 WhereInfo *pWInfo; /* Information about the WHERE clause */
88603 Index *pIdx; /* For looping over indices of the table */
88604 int iTabCur; /* Cursor number for the table */
88605 int iDataCur; /* VDBE cursor for the canonical data source */
88606 int iIdxCur; /* Cursor number of the first index */
88607 int nIdx; /* Number of indices */
88608 sqlite3 *db; /* Main database structure */
88609 AuthContext sContext; /* Authorization context */
88610 NameContext sNC; /* Name context to resolve expressions in */
88611 int iDb; /* Database number */
88612 int memCnt = -1; /* Memory cell used for change counting */
88613 int rcauth; /* Value returned by authorization callback */
88614 int okOnePass; /* True for one-pass algorithm without the FIFO */
88615 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
88616 u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
88617 Index *pPk; /* The PRIMARY KEY index on the table */
88618 int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */
88619 i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
88620 int iKey; /* Memory cell holding key of row to be deleted */
88621 i16 nKey; /* Number of memory cells in the row key */
88622 int iEphCur = 0; /* Ephemeral table holding all primary key values */
88623 int iRowSet = 0; /* Register for rowset of rows to delete */
88624 int addrBypass = 0; /* Address of jump over the delete logic */
88625 int addrLoop = 0; /* Top of the delete loop */
88626 int addrDelete = 0; /* Jump directly to the delete logic */
88627 int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
88628
88629 #ifndef SQLITE_OMIT_TRIGGER
88630 int isView; /* True if attempting to delete from a view */
88631 Trigger *pTrigger; /* List of table triggers, if required */
88632 #endif
88633
@@ -89216,15 +88678,15 @@
88678 if( rcauth==SQLITE_DENY ){
88679 goto delete_from_cleanup;
88680 }
88681 assert(!isView || pTrigger);
88682
88683 /* Assign cursor numbers to the table and all its indices.
88684 */
88685 assert( pTabList->nSrc==1 );
88686 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
88687 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
88688 pParse->nTab++;
88689 }
88690
88691 /* Start the view context
88692 */
@@ -89286,132 +88748,162 @@
88748 assert( pIdx->pSchema==pTab->pSchema );
88749 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
88750 }
88751 }else
88752 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
88753 {
88754 if( HasRowid(pTab) ){
88755 /* For a rowid table, initialize the RowSet to an empty set */
88756 pPk = 0;
88757 nPk = 1;
88758 iRowSet = ++pParse->nMem;
88759 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
88760 }else{
88761 /* For a WITHOUT ROWID table, create an ephermeral table used to
88762 ** hold all primary keys for rows to be deleted. */
88763 pPk = sqlite3PrimaryKeyIndex(pTab);
88764 assert( pPk!=0 );
88765 nPk = pPk->nKeyCol;
88766 iPk = pParse->nMem+1;
88767 pParse->nMem += nPk;
88768 iEphCur = pParse->nTab++;
88769 addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk);
88770 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
88771 }
88772
88773 /* Construct a query to find the rowid or primary key for every row
88774 ** to be deleted, based on the WHERE clause.
88775 */
88776 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
88777 WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK,
88778 iTabCur+1);
88779 if( pWInfo==0 ) goto delete_from_cleanup;
88780 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
88781
88782 /* Keep track of the number of rows to be deleted */
88783 if( db->flags & SQLITE_CountRows ){
88784 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
88785 }
88786
88787 /* Extract the rowid or primary key for the current row */
88788 if( pPk ){
88789 for(i=0; i<nPk; i++){
88790 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
88791 pPk->aiColumn[i], iPk+i);
88792 }
88793 iKey = iPk;
88794 }else{
88795 iKey = pParse->nMem + 1;
88796 iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0);
88797 if( iKey>pParse->nMem ) pParse->nMem = iKey;
88798 }
88799
88800 if( okOnePass ){
88801 /* For ONEPASS, no need to store the rowid/primary-key. There is only
88802 ** one, so just keep it in its register(s) and fall through to the
88803 ** delete code.
88804 */
88805 nKey = nPk; /* OP_Found will use an unpacked key */
88806 aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
88807 if( aToOpen==0 ){
88808 sqlite3WhereEnd(pWInfo);
88809 goto delete_from_cleanup;
88810 }
88811 memset(aToOpen, 1, nIdx+1);
88812 aToOpen[nIdx+1] = 0;
88813 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
88814 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
88815 if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
88816 addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */
88817 }else if( pPk ){
88818 /* Construct a composite key for the row to be deleted and remember it */
88819 iKey = ++pParse->nMem;
88820 nKey = 0; /* Zero tells OP_Found to use a composite key */
88821 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
88822 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
88823 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
88824 }else{
88825 /* Get the rowid of the row to be deleted and remember it in the RowSet */
88826 nKey = 1; /* OP_Seek always uses a single rowid */
88827 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
88828 }
88829
88830 /* End of the WHERE loop */
88831 sqlite3WhereEnd(pWInfo);
88832 if( okOnePass ){
88833 /* Bypass the delete logic below if the WHERE loop found zero rows */
88834 addrBypass = sqlite3VdbeMakeLabel(v);
88835 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
88836 sqlite3VdbeJumpHere(v, addrDelete);
88837 }
88838
88839 /* Unless this is a view, open cursors for the table we are
88840 ** deleting from and all its indices. If this is a view, then the
88841 ** only effect this statement has is to fire the INSTEAD OF
88842 ** triggers.
88843 */
88844 if( !isView ){
88845 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen,
88846 &iDataCur, &iIdxCur);
88847 assert( pPk || iDataCur==iTabCur );
88848 assert( pPk || iIdxCur==iDataCur+1 );
88849 }
88850
88851 /* Set up a loop over the rowids/primary-keys that were found in the
88852 ** where-clause loop above.
88853 */
88854 if( okOnePass ){
88855 /* Just one row. Hence the top-of-loop is a no-op */
88856 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
88857 if( aToOpen[iDataCur-iTabCur] ){
88858 assert( pPk!=0 );
88859 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
88860 }
88861 }else if( pPk ){
88862 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
88863 sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
88864 assert( nKey==0 ); /* OP_Found will use a composite key */
88865 }else{
88866 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
88867 assert( nKey==1 );
88868 }
88869
88870 /* Delete the row */
88871 #ifndef SQLITE_OMIT_VIRTUALTABLE
88872 if( IsVirtual(pTab) ){
88873 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
88874 sqlite3VtabMakeWritable(pParse, pTab);
88875 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
88876 sqlite3VdbeChangeP5(v, OE_Abort);
88877 sqlite3MayAbort(pParse);
88878 }else
88879 #endif
88880 {
88881 int count = (pParse->nested==0); /* True to count changes */
88882 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
88883 iKey, nKey, count, OE_Default, okOnePass);
88884 }
88885
88886 /* End of the loop over all rowids/primary-keys. */
88887 if( okOnePass ){
88888 sqlite3VdbeResolveLabel(v, addrBypass);
88889 }else if( pPk ){
88890 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
88891 sqlite3VdbeJumpHere(v, addrLoop);
88892 }else{
88893 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
88894 sqlite3VdbeJumpHere(v, addrLoop);
88895 }
88896
88897 /* Close the cursors open on the table and its indexes. */
88898 if( !isView && !IsVirtual(pTab) ){
88899 if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
88900 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
88901 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
88902 }
88903 }
88904 } /* End non-truncate path */
88905
88906 /* Update the sqlite_sequence table by storing the content of the
88907 ** maximum rowid counter values recorded while inserting into
88908 ** autoincrement tables.
88909 */
@@ -89431,10 +88923,11 @@
88923
88924 delete_from_cleanup:
88925 sqlite3AuthContextPop(&sContext);
88926 sqlite3SrcListDelete(db, pTabList);
88927 sqlite3ExprDelete(db, pWhere);
88928 sqlite3DbFree(db, aToOpen);
88929 return;
88930 }
88931 /* Make sure "isView" and other macros defined above are undefined. Otherwise
88932 ** thely may interfere with compilation of other functions in this file
88933 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -89497,10 +88990,11 @@
88990 /* If there are any triggers to fire, allocate a range of registers to
88991 ** use for the old.* references in the triggers. */
88992 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
88993 u32 mask; /* Mask of OLD.* columns in use */
88994 int iCol; /* Iterator used while populating OLD.* */
88995 int addrStart; /* Start of BEFORE trigger programs */
88996
88997 /* TODO: Could use temporary registers here. Also could attempt to
88998 ** avoid copying the contents of the rowid register. */
88999 mask = sqlite3TriggerColmask(
89000 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
@@ -89517,19 +89011,23 @@
89011 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
89012 }
89013 }
89014
89015 /* Invoke BEFORE DELETE trigger programs. */
89016 addrStart = sqlite3VdbeCurrentAddr(v);
89017 sqlite3CodeRowTrigger(pParse, pTrigger,
89018 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
89019 );
89020
89021 /* If any BEFORE triggers were coded, then seek the cursor to the
89022 ** row to be deleted again. It may be that the BEFORE triggers moved
89023 ** the cursor or of already deleted the row that the cursor was
89024 ** pointing to.
89025 */
89026 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89027 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89028 }
89029
89030 /* Do FK processing. This call checks that any FK constraints that
89031 ** refer to this table (i.e. constraints attached to other tables)
89032 ** are not violated by deleting this row. */
89033 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -91193,15 +90691,15 @@
90691 nSep = sqlite3_value_bytes(argv[1]);
90692 }else{
90693 zSep = ",";
90694 nSep = 1;
90695 }
90696 if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
90697 }
90698 zVal = (char*)sqlite3_value_text(argv[0]);
90699 nVal = sqlite3_value_bytes(argv[0]);
90700 if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
90701 }
90702 }
90703 static void groupConcatFinalize(sqlite3_context *context){
90704 StrAccum *pAccum;
90705 pAccum = sqlite3_aggregate_context(context, 0);
@@ -91346,24 +90844,24 @@
90844 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
90845 FUNCTION(hex, 1, 0, 0, hexFunc ),
90846 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
90847 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
90848 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
90849 VFUNCTION(random, 0, 0, 0, randomFunc ),
90850 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
90851 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
90852 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
90853 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
90854 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
90855 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
90856 FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
90857 FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
90858 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
90859 FUNCTION(quote, 1, 0, 0, quoteFunc ),
90860 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
90861 VFUNCTION(changes, 0, 0, 0, changes ),
90862 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
90863 FUNCTION(replace, 3, 0, 0, replaceFunc ),
90864 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
90865 #ifdef SQLITE_SOUNDEX
90866 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
90867 #endif
@@ -91955,10 +91453,11 @@
91453 Vdbe *v = sqlite3GetVdbe(pParse);
91454
91455 assert( pIdx==0 || pIdx->pTable==pTab );
91456 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
91457 assert( pIdx!=0 || pFKey->nCol==1 );
91458 assert( pIdx!=0 || HasRowid(pTab) );
91459
91460 if( nIncr<0 ){
91461 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
91462 }
91463
@@ -92007,10 +91506,11 @@
91506 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
91507 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
91508 }else{
91509 Expr *pEq, *pAll = 0;
91510 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
91511 assert( pIdx!=0 );
91512 for(i=0; i<pPk->nKeyCol; i++){
91513 i16 iCol = pIdx->aiColumn[i];
91514 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
91515 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
91516 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
@@ -93585,11 +93085,11 @@
93085 }
93086
93087 /* If this is not a view, open the table and and all indices */
93088 if( !isView ){
93089 int nIdx;
93090 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1, 0,
93091 &iDataCur, &iIdxCur);
93092 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
93093 if( aRegIdx==0 ){
93094 goto insert_cleanup;
93095 }
@@ -94445,42 +93945,50 @@
93945 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
93946 Parse *pParse, /* Parsing context */
93947 Table *pTab, /* Table to be opened */
93948 int op, /* OP_OpenRead or OP_OpenWrite */
93949 int iBase, /* Use this for the table cursor, if there is one */
93950 u8 *aToOpen, /* If not NULL: boolean for each table and index */
93951 int *piDataCur, /* Write the database source cursor number here */
93952 int *piIdxCur /* Write the first index cursor number here */
93953 ){
93954 int i;
93955 int iDb;
93956 int iDataCur;
93957 Index *pIdx;
93958 Vdbe *v;
93959
93960 assert( op==OP_OpenRead || op==OP_OpenWrite );
93961 if( IsVirtual(pTab) ){
93962 assert( aToOpen==0 );
93963 *piDataCur = 0;
93964 *piIdxCur = 1;
93965 return 0;
93966 }
93967 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
93968 v = sqlite3GetVdbe(pParse);
93969 assert( v!=0 );
93970 if( iBase<0 ) iBase = pParse->nTab;
93971 iDataCur = iBase++;
93972 if( piDataCur ) *piDataCur = iDataCur;
93973 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
93974 sqlite3OpenTable(pParse, iDataCur, iDb, pTab, op);
93975 }else{
93976 sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
93977 }
93978 if( piIdxCur ) *piIdxCur = iBase;
93979 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
93980 int iIdxCur = iBase++;
93981 assert( pIdx->pSchema==pTab->pSchema );
93982 if( pIdx->autoIndex==2 && !HasRowid(pTab) && piDataCur ){
93983 *piDataCur = iIdxCur;
93984 }
93985 if( aToOpen==0 || aToOpen[i+1] ){
93986 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
93987 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
93988 VdbeComment((v, "%s", pIdx->zName));
93989 }
93990 }
93991 if( iBase>pParse->nTab ) pParse->nTab = iBase;
93992 return i;
93993 }
93994
@@ -96650,10 +96158,14 @@
96158 /* iArg: */ SQLITE_VdbeAddopTrace },
96159 { /* zName: */ "vdbe_debug",
96160 /* ePragTyp: */ PragTyp_FLAG,
96161 /* ePragFlag: */ 0,
96162 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
96163 { /* zName: */ "vdbe_eqp",
96164 /* ePragTyp: */ PragTyp_FLAG,
96165 /* ePragFlag: */ 0,
96166 /* iArg: */ SQLITE_VdbeEQP },
96167 { /* zName: */ "vdbe_listing",
96168 /* ePragTyp: */ PragTyp_FLAG,
96169 /* ePragFlag: */ 0,
96170 /* iArg: */ SQLITE_VdbeListing },
96171 { /* zName: */ "vdbe_trace",
@@ -96677,11 +96189,11 @@
96189 /* ePragTyp: */ PragTyp_FLAG,
96190 /* ePragFlag: */ 0,
96191 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
96192 #endif
96193 };
96194 /* Number of pragmas: 56 on by default, 69 total. */
96195 /* End of the automatically generated pragma table.
96196 ***************************************************************************/
96197
96198 /*
96199 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -98103,11 +97615,11 @@
97615 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
97616 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
97617 sqlite3VdbeJumpHere(v, addr);
97618 sqlite3ExprCacheClear(pParse);
97619 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
97620 1, 0, &iDataCur, &iIdxCur);
97621 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
97622 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
97623 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
97624 }
97625 pParse->nMem = MAX(pParse->nMem, 8+j);
@@ -99038,10 +98550,17 @@
98550 }
98551 assert( i>=0 && i<db->nDb );
98552 }
98553 return i;
98554 }
98555
98556 /*
98557 ** Free all memory allocations in the pParse object
98558 */
98559 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
98560 if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
98561 }
98562
98563 /*
98564 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
98565 */
98566 static int sqlite3Prepare(
@@ -99196,10 +98715,11 @@
98715 sqlite3DbFree(db, pT);
98716 }
98717
98718 end_prepare:
98719
98720 sqlite3ParserReset(pParse);
98721 sqlite3StackFree(db, pParse);
98722 rc = sqlite3ApiExit(db, rc);
98723 assert( (rc&db->errMask)==rc );
98724 return rc;
98725 }
@@ -99989,11 +99509,12 @@
99509 }else if( eDest!=SRT_Exists ){
99510 /* If the destination is an EXISTS(...) expression, the actual
99511 ** values returned by the SELECT are not required.
99512 */
99513 sqlite3ExprCacheClear(pParse);
99514 sqlite3ExprCodeExprList(pParse, pEList, regResult,
99515 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
99516 }
99517 nColumn = nResultCol;
99518
99519 /* If the DISTINCT keyword was present on the SELECT statement
99520 ** and this row has been seen before, then do not make this row
@@ -101762,20 +101283,20 @@
101283 */
101284 if( op!=TK_ALL ){
101285 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
101286 struct ExprList_item *pItem;
101287 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
101288 assert( pItem->u.x.iOrderByCol>0 );
101289 if( pItem->u.x.iOrderByCol==i ) break;
101290 }
101291 if( j==nOrderBy ){
101292 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
101293 if( pNew==0 ) return SQLITE_NOMEM;
101294 pNew->flags |= EP_IntValue;
101295 pNew->u.iValue = i;
101296 pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
101297 if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
101298 }
101299 }
101300 }
101301
101302 /* Compute the comparison permutation and keyinfo that is used with
@@ -101787,12 +101308,13 @@
101308 */
101309 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
101310 if( aPermute ){
101311 struct ExprList_item *pItem;
101312 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
101313 assert( pItem->u.x.iOrderByCol>0
101314 && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
101315 aPermute[i] = pItem->u.x.iOrderByCol - 1;
101316 }
101317 pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
101318 if( pKeyMerge ){
101319 for(i=0; i<nOrderBy; i++){
101320 CollSeq *pColl;
@@ -102368,11 +101890,11 @@
101890
101891 /* Restriction 18. */
101892 if( p->pOrderBy ){
101893 int ii;
101894 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
101895 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
101896 }
101897 }
101898 }
101899
101900 /***** If we reach this point, flattening is permitted. *****/
@@ -103274,11 +102796,11 @@
102796 ExprList *pList = pF->pExpr->x.pList;
102797 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
102798 if( pList ){
102799 nArg = pList->nExpr;
102800 regAgg = sqlite3GetTempRange(pParse, nArg);
102801 sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
102802 }else{
102803 nArg = 0;
102804 regAgg = 0;
102805 }
102806 if( pF->iDistinct>=0 ){
@@ -103775,14 +103297,14 @@
103297 if( pGroupBy ){
103298 int k; /* Loop counter */
103299 struct ExprList_item *pItem; /* For looping over expression in a list */
103300
103301 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
103302 pItem->u.x.iAlias = 0;
103303 }
103304 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
103305 pItem->u.x.iAlias = 0;
103306 }
103307 if( p->nSelectRow>100 ) p->nSelectRow = 100;
103308 }else{
103309 p->nSelectRow = 1;
103310 }
@@ -104060,15 +103582,16 @@
103582
103583 /* Search for the index that has the lowest scan cost.
103584 **
103585 ** (2011-04-15) Do not do a full scan of an unordered index.
103586 **
103587 ** (2013-10-03) Do not count the entries in a partial index.
103588 **
103589 ** In practice the KeyInfo structure will not be used. It is only
103590 ** passed to keep OP_OpenRead happy.
103591 */
103592 if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab);
103593 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
103594 if( pIdx->bUnordered==0
103595 && pIdx->szIdxRow<pTab->szTabRow
103596 && pIdx->pPartIdxWhere==0
103597 && (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
@@ -105428,10 +104951,11 @@
104951 sqlite3VdbeDelete(v);
104952 }
104953
104954 assert( !pSubParse->pAinc && !pSubParse->pZombieTab );
104955 assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
104956 sqlite3ParserReset(pSubParse);
104957 sqlite3StackFree(db, pSubParse);
104958
104959 return pPrg;
104960 }
104961
@@ -105742,22 +105266,23 @@
105266 WhereInfo *pWInfo; /* Information about the WHERE clause */
105267 Vdbe *v; /* The virtual database engine */
105268 Index *pIdx; /* For looping over indices */
105269 Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
105270 int nIdx; /* Number of indices that need updating */
105271 int iBaseCur; /* Base cursor number */
105272 int iDataCur; /* Cursor for the canonical data btree */
105273 int iIdxCur; /* Cursor for the first index */
105274 sqlite3 *db; /* The database structure */
105275 int *aRegIdx = 0; /* One register assigned to each index to be updated */
105276 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
105277 ** an expression for the i-th column of the table.
105278 ** aXRef[i]==-1 if the i-th column is not changed. */
105279 u8 *aToOpen; /* 1 for tables and indices to be opened */
105280 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105281 u8 chngRowid; /* Rowid changed in a normal table */
105282 u8 chngKey; /* Either chngPk or chngRowid */
105283 Expr *pRowidExpr = 0; /* Expression defining the new record number */
 
105284 AuthContext sContext; /* The authorization context */
105285 NameContext sNC; /* The name-context to resolve expressions in */
105286 int iDb; /* Database containing the table being updated */
105287 int okOnePass; /* True for one-pass algorithm without the FIFO */
105288 int hasFK; /* True if foreign key processing is required */
@@ -105817,29 +105342,37 @@
105342 goto update_cleanup;
105343 }
105344 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
105345 goto update_cleanup;
105346 }
 
 
 
105347
105348 /* Allocate a cursors for the main database table and for all indices.
105349 ** The index cursors might not be used, but if they are used they
105350 ** need to occur right after the database cursor. So go ahead and
105351 ** allocate enough space, just in case.
105352 */
105353 pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++;
105354 iIdxCur = iDataCur+1;
105355 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105356 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105357 if( pIdx->autoIndex==2 && pPk!=0 ){
105358 iDataCur = pParse->nTab;
105359 pTabList->a[0].iCursor = iDataCur;
105360 }
105361 pParse->nTab++;
105362 }
105363
105364 /* Allocate space for aXRef[], aRegIdx[], and aToOpen[].
105365 ** Initialize aXRef[] and aToOpen[] to their default values.
105366 */
105367 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 );
105368 if( aXRef==0 ) goto update_cleanup;
105369 aRegIdx = aXRef+pTab->nCol;
105370 aToOpen = (u8*)(aRegIdx+nIdx);
105371 memset(aToOpen, 1, nIdx+1);
105372 aToOpen[nIdx+1] = 0;
105373 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105374
105375 /* Initialize the name-context */
105376 memset(&sNC, 0, sizeof(sNC));
105377 sNC.pParse = pParse;
105378 sNC.pSrcList = pTabList;
@@ -105894,22 +105427,22 @@
105427 }
105428 assert( (chngRowid & chngPk)==0 );
105429 assert( chngRowid==0 || chngRowid==1 );
105430 assert( chngPk==0 || chngPk==1 );
105431 chngKey = chngRowid + chngPk;
105432
105433 /* The SET expressions are not actually used inside the WHERE loop.
105434 ** So reset the colUsed mask
105435 */
105436 pTabList->a[0].colUsed = 0;
105437
105438 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
105439
105440 /* There is one entry in the aRegIdx[] array for each index on the table
105441 ** being updated. Fill in aRegIdx[] with a register number that will hold
105442 ** the key for accessing each index.
 
105443 */
 
 
 
 
105444 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
105445 int reg;
105446 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
105447 reg = ++pParse->nMem;
105448 }else{
@@ -105919,10 +105452,11 @@
105452 reg = ++pParse->nMem;
105453 break;
105454 }
105455 }
105456 }
105457 if( reg==0 ) aToOpen[j+1] = 0;
105458 aRegIdx[j] = reg;
105459 }
105460
105461 /* Begin generating code. */
105462 v = sqlite3GetVdbe(pParse);
@@ -106042,46 +105576,34 @@
105576 ** Open every index that needs updating. Note that if any
105577 ** index could potentially invoke a REPLACE conflict resolution
105578 ** action, then we need to open all indices because we might need
105579 ** to be deleting some records.
105580 */
 
 
 
 
105581 if( onError==OE_Replace ){
105582 memset(aToOpen, 1, nIdx+1);
105583 }else{
 
105584 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
105585 if( pIdx->onError==OE_Replace ){
105586 memset(aToOpen, 1, nIdx+1);
105587 break;
105588 }
105589 }
105590 }
105591 if( okOnePass ){
105592 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
105593 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
105594 }
105595 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iBaseCur, aToOpen,
105596 0, 0);
 
 
 
 
 
 
 
 
 
 
 
105597 }
105598
105599 /* Top of the update loop */
105600 if( okOnePass ){
105601 if( aToOpen[iDataCur-iBaseCur] ){
105602 assert( pPk!=0 );
105603 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
105604 }
105605 labelContinue = labelBreak;
105606 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
105607 }else if( pPk ){
105608 labelContinue = sqlite3VdbeMakeLabel(v);
105609 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
@@ -106222,15 +105744,11 @@
105744 /* If changing the record number, delete the old record. */
105745 if( hasFK || chngKey || pPk!=0 ){
105746 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
105747 }
105748 if( bReplace || chngKey ){
105749 sqlite3VdbeJumpHere(v, j1);
 
 
 
 
105750 }
105751
105752 if( hasFK ){
105753 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
105754 }
@@ -106270,11 +105788,11 @@
105788 sqlite3VdbeResolveLabel(v, labelBreak);
105789
105790 /* Close all tables */
105791 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
105792 assert( aRegIdx );
105793 if( aToOpen[i+1] ){
105794 sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
105795 }
105796 }
105797 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
105798
@@ -106297,12 +105815,11 @@
105815 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
105816 }
105817
105818 update_cleanup:
105819 sqlite3AuthContextPop(&sContext);
105820 sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
 
105821 sqlite3SrcListDelete(db, pTabList);
105822 sqlite3ExprListDelete(db, pChanges);
105823 sqlite3ExprDelete(db, pWhere);
105824 return;
105825 }
@@ -107521,10 +107038,11 @@
107038
107039 if( pParse->pVdbe ){
107040 sqlite3VdbeFinalize(pParse->pVdbe);
107041 }
107042 sqlite3DeleteTable(db, pParse->pNewTable);
107043 sqlite3ParserReset(pParse);
107044 sqlite3StackFree(db, pParse);
107045 }
107046
107047 assert( (rc&0xff)==rc );
107048 rc = sqlite3ApiExit(db, rc);
@@ -107898,11 +107416,28 @@
107416 ** generating the code that loops through a table looking for applicable
107417 ** rows. Indices are selected and used to speed the search when doing
107418 ** so is applicable. Because this module is responsible for selecting
107419 ** indices, you might also think of this module as the "query optimizer".
107420 */
107421 /************** Include whereInt.h in the middle of where.c ******************/
107422 /************** Begin file whereInt.h ****************************************/
107423 /*
107424 ** 2013-11-12
107425 **
107426 ** The author disclaims copyright to this source code. In place of
107427 ** a legal notice, here is a blessing:
107428 **
107429 ** May you do good and not evil.
107430 ** May you find forgiveness for yourself and forgive others.
107431 ** May you share freely, never taking more than you give.
107432 **
107433 *************************************************************************
107434 **
107435 ** This file contains structure and macro definitions for the query
107436 ** planner logic in "where.c". These definitions are broken out into
107437 ** a separate source file for easier editing.
107438 */
107439
107440 /*
107441 ** Trace output macros
107442 */
107443 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
@@ -107950,10 +107485,11 @@
107485 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
107486 int iTabCur; /* The VDBE cursor used to access the table */
107487 int iIdxCur; /* The VDBE cursor used to access pIdx */
107488 int addrBrk; /* Jump here to break out of the loop */
107489 int addrNxt; /* Jump here to start the next IN combination */
107490 int addrSkip; /* Jump here for next iteration of skip-scan */
107491 int addrCont; /* Jump here to continue with the next loop cycle */
107492 int addrFirst; /* First instruction of interior of the loop */
107493 int addrBody; /* Beginning of the body of this loop */
107494 u8 iFrom; /* Which entry in the FROM clause */
107495 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
@@ -107998,11 +107534,12 @@
107534 LogEst rSetup; /* One-time setup cost (ex: create transient index) */
107535 LogEst rRun; /* Cost of running each loop */
107536 LogEst nOut; /* Estimated number of output rows */
107537 union {
107538 struct { /* Information for internal btree tables */
107539 u16 nEq; /* Number of equality constraints */
107540 u16 nSkip; /* Number of initial index columns to skip */
107541 Index *pIndex; /* Index used, or NULL */
107542 } btree;
107543 struct { /* Information for virtual tables */
107544 int idxNum; /* Index number */
107545 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -108339,10 +107876,14 @@
107876 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
107877 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
107878 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
107879 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
107880 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
107881 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
107882
107883 /************** End of whereInt.h ********************************************/
107884 /************** Continuing where we left off in where.c **********************/
107885
107886 /*
107887 ** Return the estimated number of output rows from a WHERE clause
107888 */
107889 SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
@@ -108990,13 +108531,10 @@
108531 }
108532 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
108533
108534 pRight = pList->a[0].pExpr;
108535 op = pRight->op;
 
 
 
108536 if( op==TK_VARIABLE ){
108537 Vdbe *pReprepare = pParse->pReprepare;
108538 int iCol = pRight->iColumn;
108539 pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_NONE);
108540 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
@@ -109859,10 +109397,11 @@
109397 }
109398 sqlite3DebugPrintf(" idxNum=%d\n", p->idxNum);
109399 sqlite3DebugPrintf(" idxStr=%s\n", p->idxStr);
109400 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
109401 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
109402 sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
109403 }
109404 #else
109405 #define TRACE_IDX_INPUTS(A)
109406 #define TRACE_IDX_OUTPUTS(A)
109407 #endif
@@ -110228,12 +109767,11 @@
109767 int res; /* Result of comparison operation */
109768
109769 #ifndef SQLITE_DEBUG
109770 UNUSED_PARAMETER( pParse );
109771 #endif
109772 assert( pRec!=0 );
 
109773 iCol = pRec->nField - 1;
109774 assert( pIdx->nSample>0 );
109775 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
109776 do{
109777 iTest = (iMin+i)/2;
@@ -110729,11 +110267,11 @@
110267 if( eType==IN_INDEX_ROWID ){
110268 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
110269 }else{
110270 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
110271 }
110272 pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
110273 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
110274 }else{
110275 pLevel->u.in.nIn = 0;
110276 }
110277 #endif
@@ -110742,11 +110280,11 @@
110280 return iReg;
110281 }
110282
110283 /*
110284 ** Generate code that will evaluate all == and IN constraints for an
110285 ** index scan.
110286 **
110287 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
110288 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
110289 ** The index has as many as three equality constraints, but in this
110290 ** example, the third "c" value is an inequality. So only two
@@ -110757,13 +110295,19 @@
110295 ** In the example above nEq==2. But this subroutine works for any value
110296 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
110297 ** The only thing it does is allocate the pLevel->iMem memory cell and
110298 ** compute the affinity string.
110299 **
110300 ** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
110301 ** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
110302 ** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
110303 ** occurs after the nEq quality constraints.
110304 **
110305 ** This routine allocates a range of nEq+nExtraReg memory cells and returns
110306 ** the index of the first memory cell in that range. The code that
110307 ** calls this routine will use that memory range to store keys for
110308 ** start and termination conditions of the loop.
110309 ** key value of the loop. If one or more IN operators appear, then
110310 ** this routine allocates an additional nEq memory cells for internal
110311 ** use.
110312 **
110313 ** Before returning, *pzAff is set to point to a buffer containing a
@@ -110786,11 +110330,12 @@
110330 WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
110331 int bRev, /* Reverse the order of IN operators */
110332 int nExtraReg, /* Number of extra registers to allocate */
110333 char **pzAff /* OUT: Set to point to affinity string */
110334 ){
110335 u16 nEq; /* The number of == or IN constraints to code */
110336 u16 nSkip; /* Number of left-most columns to skip */
110337 Vdbe *v = pParse->pVdbe; /* The vm under construction */
110338 Index *pIdx; /* The index being used for this loop */
110339 WhereTerm *pTerm; /* A single constraint term */
110340 WhereLoop *pLoop; /* The WhereLoop object */
110341 int j; /* Loop counter */
@@ -110800,10 +110345,11 @@
110345
110346 /* This module is only called on query plans that use an index. */
110347 pLoop = pLevel->pWLoop;
110348 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
110349 nEq = pLoop->u.btree.nEq;
110350 nSkip = pLoop->u.btree.nSkip;
110351 pIdx = pLoop->u.btree.pIndex;
110352 assert( pIdx!=0 );
110353
110354 /* Figure out how many memory cells we will need then allocate them.
110355 */
@@ -110813,19 +110359,34 @@
110359
110360 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
110361 if( !zAff ){
110362 pParse->db->mallocFailed = 1;
110363 }
110364
110365 if( nSkip ){
110366 int iIdxCur = pLevel->iIdxCur;
110367 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
110368 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
110369 j = sqlite3VdbeAddOp0(v, OP_Goto);
110370 pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
110371 iIdxCur, 0, regBase, nSkip);
110372 sqlite3VdbeJumpHere(v, j);
110373 for(j=0; j<nSkip; j++){
110374 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
110375 assert( pIdx->aiColumn[j]>=0 );
110376 VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
110377 }
110378 }
110379
110380 /* Evaluate the equality constraints
110381 */
110382 assert( zAff==0 || (int)strlen(zAff)>=nEq );
110383 for(j=nSkip; j<nEq; j++){
110384 int r1;
110385 pTerm = pLoop->aLTerm[j];
110386 assert( pTerm!=0 );
110387 /* The following testcase is true for indices with redundant columns.
110388 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
110389 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
110390 testcase( pTerm->wtFlags & TERM_VIRTUAL );
110391 r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
110392 if( r1!=regBase+j ){
@@ -110869,11 +110430,11 @@
110430 int iTerm, /* Index of this term. First is zero */
110431 const char *zColumn, /* Name of the column */
110432 const char *zOp /* Name of the operator */
110433 ){
110434 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110435 sqlite3StrAccumAppendAll(pStr, zColumn);
110436 sqlite3StrAccumAppend(pStr, zOp, 1);
110437 sqlite3StrAccumAppend(pStr, "?", 1);
110438 }
110439
110440 /*
@@ -110895,11 +110456,12 @@
110456 ** It is the responsibility of the caller to free the buffer when it is
110457 ** no longer required.
110458 */
110459 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
110460 Index *pIndex = pLoop->u.btree.pIndex;
110461 u16 nEq = pLoop->u.btree.nEq;
110462 u16 nSkip = pLoop->u.btree.nSkip;
110463 int i, j;
110464 Column *aCol = pTab->aCol;
110465 i16 *aiColumn = pIndex->aiColumn;
110466 StrAccum txt;
110467
@@ -110909,11 +110471,18 @@
110471 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
110472 txt.db = db;
110473 sqlite3StrAccumAppend(&txt, " (", 2);
110474 for(i=0; i<nEq; i++){
110475 char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
110476 if( i>=nSkip ){
110477 explainAppendTerm(&txt, i, z, "=");
110478 }else{
110479 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
110480 sqlite3StrAccumAppend(&txt, "ANY(", 4);
110481 sqlite3StrAccumAppendAll(&txt, z);
110482 sqlite3StrAccumAppend(&txt, ")", 1);
110483 }
110484 }
110485
110486 j = i;
110487 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
110488 char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -110939,11 +110508,14 @@
110508 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
110509 int iLevel, /* Value for "level" column of output */
110510 int iFrom, /* Value for "from" column of output */
110511 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
110512 ){
110513 #ifndef SQLITE_DEBUG
110514 if( pParse->explain==2 )
110515 #endif
110516 {
110517 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
110518 Vdbe *v = pParse->pVdbe; /* VM being constructed */
110519 sqlite3 *db = pParse->db; /* Database handle */
110520 char *zMsg; /* Text to add to EQP output */
110521 int iId = pParse->iSelectId; /* Select id (left-most output column) */
@@ -111045,11 +110617,11 @@
110617 iCur = pTabItem->iCursor;
110618 pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
110619 bRev = (pWInfo->revMask>>iLevel)&1;
110620 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
110621 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
110622 VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
110623
110624 /* Create labels for the "break" and "continue" instructions
110625 ** for the current loop. Jump to addrBrk to break out of a loop.
110626 ** Jump to cont to go immediately to the next iteration of the
110627 ** loop.
@@ -111272,12 +110844,12 @@
110844 static const u8 aEndOp[] = {
110845 OP_Noop, /* 0: (!end_constraints) */
110846 OP_IdxGE, /* 1: (end_constraints && !bRev) */
110847 OP_IdxLT /* 2: (end_constraints && bRev) */
110848 };
110849 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
110850 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
110851 int regBase; /* Base register holding constraint values */
110852 int r1; /* Temp register */
110853 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
110854 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
110855 int startEq; /* True if range start uses ==, >= or <= */
@@ -111287,14 +110859,15 @@
110859 Index *pIdx; /* The index we will be using */
110860 int iIdxCur; /* The VDBE cursor for the index */
110861 int nExtraReg = 0; /* Number of extra registers needed */
110862 int op; /* Instruction opcode */
110863 char *zStartAff; /* Affinity for start of range constraint */
110864 char cEndAff = 0; /* Affinity for end of range constraint */
110865
110866 pIdx = pLoop->u.btree.pIndex;
110867 iIdxCur = pLevel->iIdxCur;
110868 assert( nEq>=pLoop->u.btree.nSkip );
110869
110870 /* If this loop satisfies a sort order (pOrderBy) request that
110871 ** was passed to this function to implement a "SELECT min(x) ..."
110872 ** query, then the caller will only allow the loop to run for
110873 ** a single iteration. This means that the first row returned
@@ -111304,12 +110877,11 @@
110877 */
110878 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
110879 && (pWInfo->bOBSat!=0)
110880 && (pIdx->nKeyCol>nEq)
110881 ){
110882 assert( pLoop->u.btree.nSkip==0 );
 
110883 isMinQuery = 1;
110884 nExtraReg = 1;
110885 }
110886
110887 /* Find any inequality constraint terms for the start and end
@@ -111328,11 +110900,12 @@
110900 /* Generate code to evaluate all constraint terms using == or IN
110901 ** and store the values of those terms in an array of registers
110902 ** starting at regBase.
110903 */
110904 regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
110905 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
110906 if( zStartAff ) cEndAff = zStartAff[nEq];
110907 addrNxt = pLevel->addrNxt;
110908
110909 /* If we are doing a reverse order scan on an ascending index, or
110910 ** a forward order scan on a descending index, interchange the
110911 ** start and end terms (pRangeStart and pRangeEnd).
@@ -111398,27 +110971,19 @@
110971 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
110972 sqlite3ExprCode(pParse, pRight, regBase+nEq);
110973 if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
110974 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
110975 }
110976 if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
110977 && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
110978 ){
110979 codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
110980 }
 
 
 
 
 
 
 
110981 nConstraint++;
110982 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
110983 }
110984 sqlite3DbFree(db, zStartAff);
 
110985
110986 /* Top of the loop body */
110987 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
110988
110989 /* Check if the index cursor is past the end of the range. */
@@ -111436,12 +111001,17 @@
111001 ** If it is, jump to the next iteration of the loop.
111002 */
111003 r1 = sqlite3GetTempReg(pParse);
111004 testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111005 testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111006 if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111007 && (j = pIdx->aiColumn[nEq])>=0
111008 && pIdx->pTable->aCol[j].notNull==0
111009 && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111010 ){
111011 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111012 VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111013 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111014 }
111015 sqlite3ReleaseTempReg(pParse, r1);
111016
111017 /* Seek the table cursor, if required */
@@ -111752,11 +111322,11 @@
111322 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
111323 if( pAlt==0 ) continue;
111324 if( pAlt->wtFlags & (TERM_CODED) ) continue;
111325 testcase( pAlt->eOperator & WO_EQ );
111326 testcase( pAlt->eOperator & WO_IN );
111327 VdbeModuleComment((v, "begin transitive constraint"));
111328 pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
111329 if( pEAlt ){
111330 *pEAlt = *pAlt->pExpr;
111331 pEAlt->pLeft = pE->pLeft;
111332 sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL);
@@ -111852,10 +111422,11 @@
111422 int i;
111423 Vdbe *v = pWInfo->pParse->pVdbe;
111424 sqlite3ExplainBegin(v);
111425 for(i=0; i<p->nLTerm; i++){
111426 WhereTerm *pTerm = p->aLTerm[i];
111427 if( pTerm==0 ) continue;
111428 sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111429 sqlite3ExplainPush(v);
111430 whereExplainTerm(v, pTerm);
111431 sqlite3ExplainPop(v);
111432 sqlite3ExplainNL(v);
@@ -112135,10 +111706,11 @@
111706 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
111707 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
111708 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
111709 for(j=pLoop->nLTerm-1; j>=0; j--){
111710 pX = pLoop->aLTerm[j];
111711 if( pX==0 ) continue;
111712 if( pX==pTerm ) break;
111713 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
111714 }
111715 if( j<0 ) pLoop->nOut += pTerm->truthProb;
111716 }
@@ -112164,11 +111736,12 @@
111736 WhereTerm *pTerm; /* A WhereTerm under consideration */
111737 int opMask; /* Valid operators for constraints */
111738 WhereScan scan; /* Iterator for WHERE terms */
111739 Bitmask saved_prereq; /* Original value of pNew->prereq */
111740 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
111741 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
111742 u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
111743 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
111744 LogEst saved_nOut; /* Original value of pNew->nOut */
111745 int iCol; /* Index of the column in the table */
111746 int rc = SQLITE_OK; /* Return code */
111747 LogEst nRowEst; /* Estimated index selectivity */
@@ -112199,16 +111772,37 @@
111772 nRowEst = 0;
111773 }
111774 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
111775 opMask, pProbe);
111776 saved_nEq = pNew->u.btree.nEq;
111777 saved_nSkip = pNew->u.btree.nSkip;
111778 saved_nLTerm = pNew->nLTerm;
111779 saved_wsFlags = pNew->wsFlags;
111780 saved_prereq = pNew->prereq;
111781 saved_nOut = pNew->nOut;
111782 pNew->rSetup = 0;
111783 rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0]));
111784
111785 /* Consider using a skip-scan if there are no WHERE clause constraints
111786 ** available for the left-most terms of the index, and if the average
111787 ** number of repeats in the left-most terms is at least 18. The magic
111788 ** number 18 was found by experimentation to be the payoff point where
111789 ** skip-scan become faster than a full-scan.
111790 */
111791 if( pTerm==0
111792 && saved_nEq==saved_nSkip
111793 && saved_nEq+1<pProbe->nKeyCol
111794 && pProbe->aiRowEst[saved_nEq+1]>=18 /* TUNING: Minimum for skip-scan */
111795 ){
111796 LogEst nIter;
111797 pNew->u.btree.nEq++;
111798 pNew->u.btree.nSkip++;
111799 pNew->aLTerm[pNew->nLTerm++] = 0;
111800 pNew->wsFlags |= WHERE_SKIPSCAN;
111801 nIter = sqlite3LogEst(pProbe->aiRowEst[0]/pProbe->aiRowEst[saved_nEq+1]);
111802 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter);
111803 }
111804 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
111805 int nIn = 0;
111806 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
111807 int nRecValid = pBuilder->nRecValid;
111808 #endif
@@ -112240,12 +111834,14 @@
111834 }
111835 pNew->rRun += nIn;
111836 pNew->u.btree.nEq++;
111837 pNew->nOut = nRowEst + nInMul + nIn;
111838 }else if( pTerm->eOperator & (WO_EQ) ){
111839 assert(
111840 (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
111841 || nInMul==0
111842 );
111843 pNew->wsFlags |= WHERE_COLUMN_EQ;
111844 if( iCol<0
111845 || (pProbe->onError!=OE_None && nInMul==0
111846 && pNew->u.btree.nEq==pProbe->nKeyCol-1)
111847 ){
@@ -112322,10 +111918,11 @@
111918 pBuilder->nRecValid = nRecValid;
111919 #endif
111920 }
111921 pNew->prereq = saved_prereq;
111922 pNew->u.btree.nEq = saved_nEq;
111923 pNew->u.btree.nSkip = saved_nSkip;
111924 pNew->wsFlags = saved_wsFlags;
111925 pNew->nOut = saved_nOut;
111926 pNew->nLTerm = saved_nLTerm;
111927 return rc;
111928 }
@@ -112468,10 +112065,11 @@
112065 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
112066 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
112067 if( pTerm->prereqRight & pNew->maskSelf ) continue;
112068 if( termCanDriveIndex(pTerm, pSrc, 0) ){
112069 pNew->u.btree.nEq = 1;
112070 pNew->u.btree.nSkip = 0;
112071 pNew->u.btree.pIndex = 0;
112072 pNew->nLTerm = 1;
112073 pNew->aLTerm[0] = pTerm;
112074 /* TUNING: One-time cost for computing the automatic index is
112075 ** approximately 7*N*log2(N) where N is the number of rows in
@@ -112497,10 +112095,11 @@
112095 if( pProbe->pPartIdxWhere!=0
112096 && !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){
112097 continue; /* Partial index inappropriate for this query */
112098 }
112099 pNew->u.btree.nEq = 0;
112100 pNew->u.btree.nSkip = 0;
112101 pNew->nLTerm = 0;
112102 pNew->iSortIdx = 0;
112103 pNew->rSetup = 0;
112104 pNew->prereq = mExtra;
112105 pNew->nOut = rSize;
@@ -112582,11 +112181,12 @@
112181 /*
112182 ** Add all WhereLoop objects for a table of the join identified by
112183 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
112184 */
112185 static int whereLoopAddVirtual(
112186 WhereLoopBuilder *pBuilder, /* WHERE clause information */
112187 Bitmask mExtra
112188 ){
112189 WhereInfo *pWInfo; /* WHERE analysis context */
112190 Parse *pParse; /* The parsing context */
112191 WhereClause *pWC; /* The WHERE clause */
112192 struct SrcList_item *pSrc; /* The FROM clause term to search */
@@ -112668,14 +112268,15 @@
112268 pIdxInfo->idxStr = 0;
112269 pIdxInfo->idxNum = 0;
112270 pIdxInfo->needToFreeIdxStr = 0;
112271 pIdxInfo->orderByConsumed = 0;
112272 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
112273 pIdxInfo->estimatedRows = 25;
112274 rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112275 if( rc ) goto whereLoopAddVtab_exit;
112276 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112277 pNew->prereq = mExtra;
112278 mxTerm = -1;
112279 assert( pNew->nLSlot>=nConstraint );
112280 for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
112281 pNew->u.vtab.omitMask = 0;
112282 for(i=0; i<nConstraint; i++, pIdxCons++){
@@ -112727,12 +112328,11 @@
112328 pNew->u.vtab.idxStr = pIdxInfo->idxStr;
112329 pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0)
112330 && pIdxInfo->orderByConsumed);
112331 pNew->rSetup = 0;
112332 pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
112333 pNew->nOut = sqlite3LogEst(pIdxInfo->estimatedRows);
 
112334 whereLoopInsert(pBuilder, pNew);
112335 if( pNew->u.vtab.needFree ){
112336 sqlite3_free(pNew->u.vtab.idxStr);
112337 pNew->u.vtab.needFree = 0;
112338 }
@@ -112799,12 +112399,11 @@
112399 continue;
112400 }
112401 sCur.n = 0;
112402 #ifndef SQLITE_OMIT_VIRTUALTABLE
112403 if( IsVirtual(pItem->pTab) ){
112404 rc = whereLoopAddVirtual(&sSubBuild, mExtra);
 
112405 }else
112406 #endif
112407 {
112408 rc = whereLoopAddBtree(&sSubBuild, mExtra);
112409 }
@@ -112870,11 +112469,11 @@
112469 if( ((pItem->jointype|priorJoinType) & (JT_LEFT|JT_CROSS))!=0 ){
112470 mExtra = mPrior;
112471 }
112472 priorJoinType = pItem->jointype;
112473 if( IsVirtual(pItem->pTab) ){
112474 rc = whereLoopAddVirtual(pBuilder, mExtra);
112475 }else{
112476 rc = whereLoopAddBtree(pBuilder, mExtra);
112477 }
112478 if( rc==SQLITE_OK ){
112479 rc = whereLoopAddOr(pBuilder, mExtra);
@@ -113031,10 +112630,11 @@
112630 for(j=0; j<nColumn; j++){
112631 u8 bOnce; /* True to run the ORDER BY search loop */
112632
112633 /* Skip over == and IS NULL terms */
112634 if( j<pLoop->u.btree.nEq
112635 && pLoop->u.btree.nSkip==0
112636 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
112637 ){
112638 if( i & WO_ISNULL ){
112639 testcase( isOrderDistinct );
112640 isOrderDistinct = 0;
@@ -113456,10 +113056,11 @@
113056 if( pItem->zIndex ) return 0;
113057 iCur = pItem->iCursor;
113058 pWC = &pWInfo->sWC;
113059 pLoop = pBuilder->pNew;
113060 pLoop->wsFlags = 0;
113061 pLoop->u.btree.nSkip = 0;
113062 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
113063 if( pTerm ){
113064 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
113065 pLoop->aLTerm[0] = pTerm;
113066 pLoop->nLTerm = 1;
@@ -113684,11 +113285,10 @@
113285 /* Split the WHERE clause into separate subexpressions where each
113286 ** subexpression is separated by an AND operator.
113287 */
113288 initMaskSet(pMaskSet);
113289 whereClauseInit(&pWInfo->sWC, pWInfo);
 
113290 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
113291 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113292
113293 /* Special case: a WHERE clause that is constant. Evaluate the
113294 ** expression and either jump over all of the code or fall thru.
@@ -113999,10 +113599,11 @@
113599 notReady = codeOneLoopStart(pWInfo, ii, notReady);
113600 pWInfo->iContinue = pLevel->addrCont;
113601 }
113602
113603 /* Done. */
113604 VdbeModuleComment((v, "Begin WHERE-core"));
113605 return pWInfo;
113606
113607 /* Jump here if malloc fails */
113608 whereBeginError:
113609 if( pWInfo ){
@@ -114025,12 +113626,14 @@
113626 SrcList *pTabList = pWInfo->pTabList;
113627 sqlite3 *db = pParse->db;
113628
113629 /* Generate loop termination code.
113630 */
113631 VdbeModuleComment((v, "End WHERE-core"));
113632 sqlite3ExprCacheClear(pParse);
113633 for(i=pWInfo->nLevel-1; i>=0; i--){
113634 int addr;
113635 pLevel = &pWInfo->a[i];
113636 pLoop = pLevel->pWLoop;
113637 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
113638 if( pLevel->op!=OP_Noop ){
113639 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
@@ -114046,12 +113649,17 @@
113649 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
113650 }
113651 sqlite3DbFree(db, pLevel->u.in.aInLoop);
113652 }
113653 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
113654 if( pLevel->addrSkip ){
113655 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
113656 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
113657 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
113658 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
113659 }
113660 if( pLevel->iLeftJoin ){
 
113661 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
113662 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
113663 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
113664 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
113665 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
@@ -114064,11 +113672,11 @@
113672 }else{
113673 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
113674 }
113675 sqlite3VdbeJumpHere(v, addr);
113676 }
113677 VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
113678 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
113679 }
113680
113681 /* The "break" point is here, just past the end of the outer loop.
113682 ** Set it.
@@ -116923,16 +116531,11 @@
116531 spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
116532 }
116533 break;
116534 case 200: /* term ::= CTIME_KW */
116535 {
116536 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
 
 
 
 
 
116537 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
116538 }
116539 break;
116540 case 201: /* expr ::= expr AND expr */
116541 case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
@@ -119357,10 +118960,17 @@
118960 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
118961 if( szMmap>mxMmap) szMmap = mxMmap;
118962 sqlite3GlobalConfig.szMmap = szMmap;
118963 break;
118964 }
118965
118966 #if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC)
118967 case SQLITE_CONFIG_WIN32_HEAPSIZE: {
118968 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
118969 break;
118970 }
118971 #endif
118972
118973 default: {
118974 rc = SQLITE_ERROR;
118975 break;
118976 }
@@ -119424,11 +119034,12 @@
119034 }
119035 db->lookaside.pEnd = p;
119036 db->lookaside.bEnabled = 1;
119037 db->lookaside.bMalloced = pBuf==0 ?1:0;
119038 }else{
119039 db->lookaside.pStart = db;
119040 db->lookaside.pEnd = db;
119041 db->lookaside.bEnabled = 0;
119042 db->lookaside.bMalloced = 0;
119043 }
119044 return SQLITE_OK;
119045 }
@@ -119922,10 +119533,11 @@
119533 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
119534 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
119535 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
119536 case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
119537 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
119538 case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
119539 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
119540 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
119541 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
119542 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
119543 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -122132,10 +121744,23 @@
121744 *pzRet = sqlite3VdbeExplanation((Vdbe*)pStmt);
121745 break;
121746 }
121747 #endif
121748
121749 /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
121750 **
121751 ** Set or clear a flag that indicates that the database file is always well-
121752 ** formed and never corrupt. This flag is clear by default, indicating that
121753 ** database files might have arbitrary corruption. Setting the flag during
121754 ** testing causes certain assert() statements in the code to be activated
121755 ** that demonstrat invariants on well-formed database files.
121756 */
121757 case SQLITE_TESTCTRL_NEVER_CORRUPT: {
121758 sqlite3Config.neverCorrupt = va_arg(ap, int);
121759 break;
121760 }
121761
121762 }
121763 va_end(ap);
121764 #endif /* SQLITE_OMIT_BUILTIN_TEST */
121765 return rc;
121766 }
@@ -123649,10 +123274,14 @@
123274 char *aDoclist; /* Pointer to doclist buffer */
123275 int nDoclist; /* Size of aDoclist[] in bytes */
123276 };
123277
123278 SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
123279
123280 #define fts3GetVarint32(p, piVal) ( \
123281 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
123282 )
123283
123284 /* fts3.c */
123285 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
123286 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
123287 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
@@ -123757,36 +123386,63 @@
123386 q[-1] &= 0x7f; /* turn off high bit in final byte */
123387 assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
123388 return (int) (q - (unsigned char *)p);
123389 }
123390
123391 #define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
123392 v = (v & mask1) | ( (*ptr++) << shift ); \
123393 if( (v & mask2)==0 ){ var = v; return ret; }
123394 #define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
123395 v = (*ptr++); \
123396 if( (v & mask2)==0 ){ var = v; return ret; }
123397
123398 /*
123399 ** Read a 64-bit variable-length integer from memory starting at p[0].
123400 ** Return the number of bytes read, or 0 on error.
123401 ** The value is stored in *v.
123402 */
123403 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
123404 const char *pStart = p;
123405 u32 a;
123406 u64 b;
123407 int shift;
123408
123409 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
123410 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *v, 2);
123411 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *v, 3);
123412 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *v, 4);
123413 b = (a & 0x0FFFFFFF );
123414
123415 for(shift=28; shift<=63; shift+=7){
123416 u64 c = *p++;
123417 b += (c&0x7F) << shift;
123418 if( (c & 0x80)==0 ) break;
123419 }
123420 *v = b;
123421 return (int)(p - pStart);
123422 }
123423
123424 /*
123425 ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
123426 ** 32-bit integer before it is returned.
123427 */
123428 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
123429 u32 a;
123430
123431 #ifndef fts3GetVarint32
123432 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *pi, 1);
123433 #else
123434 a = (*p++);
123435 assert( a & 0x80 );
123436 #endif
123437
123438 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
123439 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
123440 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
123441 a = (a & 0x0FFFFFFF );
123442 *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
123443 return 5;
123444 }
123445
123446 /*
123447 ** Return the number of bytes required to encode v as a varint
123448 */
@@ -125142,14 +124798,14 @@
124798 int nBuffer; /* Total term size */
124799
124800 /* Load the next term on the node into zBuffer. Use realloc() to expand
124801 ** the size of zBuffer if required. */
124802 if( !isFirstTerm ){
124803 zCsr += fts3GetVarint32(zCsr, &nPrefix);
124804 }
124805 isFirstTerm = 0;
124806 zCsr += fts3GetVarint32(zCsr, &nSuffix);
124807
124808 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
124809 rc = FTS_CORRUPT_VTAB;
124810 goto finish_scan;
124811 }
@@ -125233,11 +124889,11 @@
124889 int rc; /* Return code */
124890 int iHeight; /* Height of this node in tree */
124891
124892 assert( piLeaf || piLeaf2 );
124893
124894 fts3GetVarint32(zNode, &iHeight);
124895 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
124896 assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
124897
124898 if( rc==SQLITE_OK && iHeight>1 ){
124899 char *zBlob = 0; /* Blob read from %_segments table */
@@ -125435,15 +125091,15 @@
125091
125092 while( *p1 || *p2 ){
125093 int iCol1; /* The current column index in pp1 */
125094 int iCol2; /* The current column index in pp2 */
125095
125096 if( *p1==POS_COLUMN ) fts3GetVarint32(&p1[1], &iCol1);
125097 else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
125098 else iCol1 = 0;
125099
125100 if( *p2==POS_COLUMN ) fts3GetVarint32(&p2[1], &iCol2);
125101 else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
125102 else iCol2 = 0;
125103
125104 if( iCol1==iCol2 ){
125105 sqlite3_int64 i1 = 0; /* Last position from pp1 */
@@ -125532,15 +125188,15 @@
125188 assert( isSaveLeft==0 || isExact==0 );
125189
125190 assert( p!=0 && *p1!=0 && *p2!=0 );
125191 if( *p1==POS_COLUMN ){
125192 p1++;
125193 p1 += fts3GetVarint32(p1, &iCol1);
125194 }
125195 if( *p2==POS_COLUMN ){
125196 p2++;
125197 p2 += fts3GetVarint32(p2, &iCol2);
125198 }
125199
125200 while( 1 ){
125201 if( iCol1==iCol2 ){
125202 char *pSave = p;
@@ -125586,13 +125242,13 @@
125242 fts3ColumnlistCopy(0, &p2);
125243 assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
125244 if( 0==*p1 || 0==*p2 ) break;
125245
125246 p1++;
125247 p1 += fts3GetVarint32(p1, &iCol1);
125248 p2++;
125249 p2 += fts3GetVarint32(p2, &iCol2);
125250 }
125251
125252 /* Advance pointer p1 or p2 (whichever corresponds to the smaller of
125253 ** iCol1 and iCol2) so that it points to either the 0x00 that marks the
125254 ** end of the position list, or the 0x01 that precedes the next
@@ -125600,16 +125256,16 @@
125256 */
125257 else if( iCol1<iCol2 ){
125258 fts3ColumnlistCopy(0, &p1);
125259 if( 0==*p1 ) break;
125260 p1++;
125261 p1 += fts3GetVarint32(p1, &iCol1);
125262 }else{
125263 fts3ColumnlistCopy(0, &p2);
125264 if( 0==*p2 ) break;
125265 p2++;
125266 p2 += fts3GetVarint32(p2, &iCol2);
125267 }
125268 }
125269
125270 fts3PoslistCopy(0, &p2);
125271 fts3PoslistCopy(0, &p1);
@@ -128772,11 +128428,11 @@
128428 */
128429 pExpr->aMI[iCol*3 + 1] += iCnt;
128430 pExpr->aMI[iCol*3 + 2] += (iCnt>0);
128431 if( *p==0x00 ) break;
128432 p++;
128433 p += fts3GetVarint32(p, &iCol);
128434 }
128435 }
128436
128437 fts3EvalUpdateCounts(pExpr->pLeft);
128438 fts3EvalUpdateCounts(pExpr->pRight);
@@ -129073,19 +128729,19 @@
128729 }
128730 if( pIter==0 ) return SQLITE_OK;
128731
128732 if( *pIter==0x01 ){
128733 pIter++;
128734 pIter += fts3GetVarint32(pIter, &iThis);
128735 }else{
128736 iThis = 0;
128737 }
128738 while( iThis<iCol ){
128739 fts3ColumnlistCopy(0, &pIter);
128740 if( *pIter==0x00 ) return 0;
128741 pIter++;
128742 pIter += fts3GetVarint32(pIter, &iThis);
128743 }
128744
128745 *ppOut = ((iCol==iThis)?pIter:0);
128746 return SQLITE_OK;
128747 }
@@ -134530,12 +134186,12 @@
134186 rc = fts3SegReaderRequire(pReader, pNext, FTS3_VARINT_MAX*2);
134187 if( rc!=SQLITE_OK ) return rc;
134188
134189 /* Because of the FTS3_NODE_PADDING bytes of padding, the following is
134190 ** safe (no risk of overread) even if the node data is corrupted. */
134191 pNext += fts3GetVarint32(pNext, &nPrefix);
134192 pNext += fts3GetVarint32(pNext, &nSuffix);
134193 if( nPrefix<0 || nSuffix<=0
134194 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
134195 ){
134196 return FTS_CORRUPT_VTAB;
134197 }
@@ -134554,11 +134210,11 @@
134210 if( rc!=SQLITE_OK ) return rc;
134211
134212 memcpy(&pReader->zTerm[nPrefix], pNext, nSuffix);
134213 pReader->nTerm = nPrefix+nSuffix;
134214 pNext += nSuffix;
134215 pNext += fts3GetVarint32(pNext, &pReader->nDoclist);
134216 pReader->aDoclist = pNext;
134217 pReader->pOffsetList = 0;
134218
134219 /* Check that the doclist does not appear to extend past the end of the
134220 ** b-tree node. And that the final byte of the doclist is 0x00. If either
@@ -135715,11 +135371,11 @@
135371 pList = p;
135372 if( nList==0 ){
135373 break;
135374 }
135375 p = &pList[1];
135376 p += fts3GetVarint32(p, &iCurrent);
135377 }
135378
135379 if( bZero && &pList[nList]!=pEnd ){
135380 memset(&pList[nList], 0, pEnd - &pList[nList]);
135381 }
@@ -136680,21 +136336,21 @@
136336 if( p->iOff>=p->nNode ){
136337 /* EOF */
136338 p->aNode = 0;
136339 }else{
136340 if( bFirst==0 ){
136341 p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136342 }
136343 p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136344
136345 blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
136346 if( rc==SQLITE_OK ){
136347 memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
136348 p->term.n = nPrefix+nSuffix;
136349 p->iOff += nSuffix;
136350 if( p->iChild==0 ){
136351 p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136352 p->aDoclist = &p->aNode[p->iOff];
136353 p->iOff += p->nDoclist;
136354 }
136355 }
136356 }
@@ -137742,11 +137398,11 @@
137398 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137399 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137400
137401 pHint->n = i;
137402 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
137403 i += fts3GetVarint32(&pHint->a[i], pnInput);
137404 if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
137405
137406 return SQLITE_OK;
137407 }
137408
@@ -138735,11 +138391,11 @@
138391 ** After it returns, *piPos contains the value of the next element of the
138392 ** list and *pp is advanced to the following varint.
138393 */
138394 static void fts3GetDeltaPosition(char **pp, int *piPos){
138395 int iVal;
138396 *pp += fts3GetVarint32(*pp, &iVal);
138397 *piPos += (iVal-2);
138398 }
138399
138400 /*
138401 ** Helper function for fts3ExprIterate() (see below).
@@ -141028,10 +140684,20 @@
140684 ** ever contain very many entries, so a fixed number of buckets is
140685 ** used.
140686 */
140687 #define HASHSIZE 128
140688
140689 /* The xBestIndex method of this virtual table requires an estimate of
140690 ** the number of rows in the virtual table to calculate the costs of
140691 ** various strategies. If possible, this estimate is loaded from the
140692 ** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
140693 ** Otherwise, if no sqlite_stat1 entry is available, use
140694 ** RTREE_DEFAULT_ROWEST.
140695 */
140696 #define RTREE_DEFAULT_ROWEST 1048576
140697 #define RTREE_MIN_ROWEST 100
140698
140699 /*
140700 ** An rtree virtual-table object.
140701 */
140702 struct Rtree {
140703 sqlite3_vtab base;
@@ -141042,10 +140708,11 @@
140708 int iDepth; /* Current depth of the r-tree structure */
140709 char *zDb; /* Name of database containing r-tree table */
140710 char *zName; /* Name of r-tree table */
140711 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
140712 int nBusy; /* Current number of users of this structure */
140713 i64 nRowEst; /* Estimated number of rows in this table */
140714
140715 /* List of nodes removed during a CondenseTree operation. List is
140716 ** linked together via the pointer normally used for hash chains -
140717 ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
140718 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
@@ -142233,10 +141900,23 @@
141900 }
141901
141902 rtreeRelease(pRtree);
141903 return rc;
141904 }
141905
141906 /*
141907 ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
141908 ** extension is currently being used by a version of SQLite too old to
141909 ** support estimatedRows. In that case this function is a no-op.
141910 */
141911 static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
141912 #if SQLITE_VERSION_NUMBER>=3008002
141913 if( sqlite3_libversion_number()>=3008002 ){
141914 pIdxInfo->estimatedRows = nRow;
141915 }
141916 #endif
141917 }
141918
141919 /*
141920 ** Rtree virtual table module xBestIndex method. There are three
141921 ** table scan strategies to choose from (in order from most to
141922 ** least desirable):
@@ -142269,17 +141949,18 @@
141949 ** The second of each pair of bytes identifies the coordinate column
141950 ** to which the constraint applies. The leftmost coordinate column
141951 ** is 'a', the second from the left 'b' etc.
141952 */
141953 static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
141954 Rtree *pRtree = (Rtree*)tab;
141955 int rc = SQLITE_OK;
141956 int ii;
141957 i64 nRow; /* Estimated rows returned by this scan */
141958
141959 int iIdx = 0;
141960 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
141961 memset(zIdxStr, 0, sizeof(zIdxStr));
 
141962
141963 assert( pIdxInfo->idxStr==0 );
141964 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
141965 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
141966
@@ -142295,13 +141976,15 @@
141976 pIdxInfo->aConstraintUsage[jj].omit = 1;
141977
141978 /* This strategy involves a two rowid lookups on an B-Tree structures
141979 ** and then a linear search of an R-Tree node. This should be
141980 ** considered almost as quick as a direct rowid lookup (for which
141981 ** sqlite uses an internal cost of 0.0). It is expected to return
141982 ** a single row.
141983 */
141984 pIdxInfo->estimatedCost = 30.0;
141985 setEstimatedRows(pIdxInfo, 1);
141986 return SQLITE_OK;
141987 }
141988
141989 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
141990 u8 op;
@@ -142326,12 +142009,15 @@
142009 pIdxInfo->idxNum = 2;
142010 pIdxInfo->needToFreeIdxStr = 1;
142011 if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
142012 return SQLITE_NOMEM;
142013 }
142014
142015 nRow = pRtree->nRowEst / (iIdx + 1);
142016 pIdxInfo->estimatedCost = (double)6.0 * (double)nRow;
142017 setEstimatedRows(pIdxInfo, nRow);
142018
142019 return rc;
142020 }
142021
142022 /*
142023 ** Return the N-dimensional volumn of the cell stored in *p.
@@ -143801,10 +143487,41 @@
143487 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
143488 sqlite3_free(zSql);
143489 }
143490 return rc;
143491 }
143492
143493 /*
143494 ** This function populates the pRtree->nRowEst variable with an estimate
143495 ** of the number of rows in the virtual table. If possible, this is based
143496 ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
143497 */
143498 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
143499 const char *zSql = "SELECT stat FROM sqlite_stat1 WHERE tbl= ? || '_rowid'";
143500 sqlite3_stmt *p;
143501 int rc;
143502 i64 nRow = 0;
143503
143504 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
143505 if( rc==SQLITE_OK ){
143506 sqlite3_bind_text(p, 1, pRtree->zName, -1, SQLITE_STATIC);
143507 if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
143508 rc = sqlite3_finalize(p);
143509 }else if( rc!=SQLITE_NOMEM ){
143510 rc = SQLITE_OK;
143511 }
143512
143513 if( rc==SQLITE_OK ){
143514 if( nRow==0 ){
143515 pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
143516 }else{
143517 pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
143518 }
143519 }
143520
143521 return rc;
143522 }
143523
143524 static sqlite3_module rtreeModule = {
143525 0, /* iVersion */
143526 rtreeCreate, /* xCreate - create a table */
143527 rtreeConnect, /* xConnect - connect to an existing table */
@@ -143887,10 +143604,11 @@
143604 appStmt[5] = &pRtree->pDeleteRowid;
143605 appStmt[6] = &pRtree->pReadParent;
143606 appStmt[7] = &pRtree->pWriteParent;
143607 appStmt[8] = &pRtree->pDeleteParent;
143608
143609 rc = rtreeQueryStat1(db, pRtree);
143610 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
143611 char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
143612 if( zSql ){
143613 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
143614 }else{
143615
+56 -25
--- 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.2"
111
-#define SQLITE_VERSION_NUMBER 3008002
112
-#define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
110
+#define SQLITE_VERSION "3.8.3"
111
+#define SQLITE_VERSION_NUMBER 3008003
112
+#define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -368,11 +368,11 @@
368368
** Restrictions:
369369
**
370370
** <ul>
371371
** <li> The application must insure that the 1st parameter to sqlite3_exec()
372372
** is a valid and open [database connection].
373
-** <li> The application must not close [database connection] specified by
373
+** <li> The application must not close the [database connection] specified by
374374
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
375375
** <li> The application must not modify the SQL statement text passed into
376376
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
377377
** </ul>
378378
*/
@@ -445,11 +445,11 @@
445445
** about errors. The extended result codes are enabled or disabled
446446
** on a per database connection basis using the
447447
** [sqlite3_extended_result_codes()] API.
448448
**
449449
** Some of the available extended result codes are listed here.
450
-** One may expect the number of extended result codes will be expand
450
+** One may expect the number of extended result codes will increase
451451
** over time. Software that uses extended result codes should expect
452452
** to see new result codes in future releases of SQLite.
453453
**
454454
** The SQLITE_OK result code will never be extended. It will always
455455
** be exactly zero.
@@ -489,10 +489,11 @@
489489
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490490
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491491
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492492
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493493
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
494
+#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
494495
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
495496
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
496497
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
497498
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
498499
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -556,11 +557,12 @@
556557
** information is written to disk in the same order as calls
557558
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
558559
** after reboot following a crash or power loss, the only bytes in a
559560
** file that were written at the application level might have changed
560561
** and that adjacent bytes, even bytes within the same sector are
561
-** guaranteed to be unchanged.
562
+** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
563
+** flag indicate that a file cannot be deleted when open.
562564
*/
563565
#define SQLITE_IOCAP_ATOMIC 0x00000001
564566
#define SQLITE_IOCAP_ATOMIC512 0x00000002
565567
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
566568
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -919,10 +921,16 @@
919921
** This file control is used by some VFS activity tracing [shims].
920922
** The argument is a zero-terminated string. Higher layers in the
921923
** SQLite stack may generate instances of this file control if
922924
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
923925
**
926
+** <li>[[SQLITE_FCNTL_HAS_MOVED]]
927
+** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
928
+** pointer to an integer and it writes a boolean into that integer depending
929
+** on whether or not the file has been renamed, moved, or deleted since it
930
+** was first opened.
931
+**
924932
** </ul>
925933
*/
926934
#define SQLITE_FCNTL_LOCKSTATE 1
927935
#define SQLITE_GET_LOCKPROXYFILE 2
928936
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -939,10 +947,11 @@
939947
#define SQLITE_FCNTL_PRAGMA 14
940948
#define SQLITE_FCNTL_BUSYHANDLER 15
941949
#define SQLITE_FCNTL_TEMPFILENAME 16
942950
#define SQLITE_FCNTL_MMAP_SIZE 18
943951
#define SQLITE_FCNTL_TRACE 19
952
+#define SQLITE_FCNTL_HAS_MOVED 20
944953
945954
/*
946955
** CAPI3REF: Mutex Handle
947956
**
948957
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1383,11 +1392,11 @@
13831392
** of 8. Some allocators round up to a larger multiple or to a power of 2.
13841393
** Every memory allocation request coming in through [sqlite3_malloc()]
13851394
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
13861395
** that causes the corresponding memory allocation to fail.
13871396
**
1388
-** The xInit method initializes the memory allocator. (For example,
1397
+** The xInit method initializes the memory allocator. For example,
13891398
** it might allocate any require mutexes or initialize internal data
13901399
** structures. The xShutdown method is invoked (indirectly) by
13911400
** [sqlite3_shutdown()] and should deallocate any resources acquired
13921401
** by xInit. The pAppData pointer is used as the only parameter to
13931402
** xInit and xShutdown.
@@ -1685,10 +1694,17 @@
16851694
** cannot be changed at run-time. Nor may the maximum allowed mmap size
16861695
** exceed the compile-time maximum mmap size set by the
16871696
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
16881697
** ^If either argument to this option is negative, then that argument is
16891698
** changed to its compile-time default.
1699
+**
1700
+** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1701
+** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1702
+** <dd>^This option is only available if SQLite is compiled for Windows
1703
+** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1704
+** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1705
+** that specifies the maximum size of the created heap.
16901706
** </dl>
16911707
*/
16921708
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
16931709
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
16941710
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1709,10 +1725,11 @@
17091725
#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
17101726
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
17111727
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
17121728
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
17131729
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1730
+#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
17141731
17151732
/*
17161733
** CAPI3REF: Database Connection Configuration Options
17171734
**
17181735
** These constants are the available integer configuration options that
@@ -3109,11 +3126,10 @@
31093126
** to the [sqlite3_bind_text | bindings] of that [parameter].
31103127
** ^The specific value of WHERE-clause [parameter] might influence the
31113128
** choice of query plan if the parameter is the left-hand side of a [LIKE]
31123129
** or [GLOB] operator or if the parameter is compared to an indexed column
31133130
** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3114
-** the
31153131
** </li>
31163132
** </ol>
31173133
*/
31183134
SQLITE_API int sqlite3_prepare(
31193135
sqlite3 *db, /* Database handle */
@@ -3771,23 +3787,23 @@
37713787
** <table border="1">
37723788
** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
37733789
**
37743790
** <tr><td> NULL <td> INTEGER <td> Result is 0
37753791
** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3776
-** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
3777
-** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
3792
+** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
3793
+** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
37783794
** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
37793795
** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
37803796
** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3781
-** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
3797
+** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
37823798
** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3783
-** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
3784
-** <tr><td> TEXT <td> INTEGER <td> Use atoi()
3785
-** <tr><td> TEXT <td> FLOAT <td> Use atof()
3799
+** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
3800
+** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
3801
+** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
37863802
** <tr><td> TEXT <td> BLOB <td> No change
3787
-** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
3788
-** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
3803
+** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
3804
+** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
37893805
** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
37903806
** </table>
37913807
** </blockquote>)^
37923808
**
37933809
** The table above makes reference to standard C library functions atoi()
@@ -3839,11 +3855,11 @@
38393855
**
38403856
** ^The pointers returned are valid until a type conversion occurs as
38413857
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
38423858
** [sqlite3_finalize()] is called. ^The memory space used to hold strings
38433859
** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3844
-** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3860
+** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
38453861
** [sqlite3_free()].
38463862
**
38473863
** ^(If a memory allocation error occurs during the evaluation of any
38483864
** of these routines, a default value is returned. The default value
38493865
** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4917,12 +4933,12 @@
49174933
/*
49184934
** CAPI3REF: Free Memory Used By A Database Connection
49194935
**
49204936
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
49214937
** memory as possible from database connection D. Unlike the
4922
-** [sqlite3_release_memory()] interface, this interface is effect even
4923
-** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4938
+** [sqlite3_release_memory()] interface, this interface is in effect even
4939
+** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
49244940
** omitted.
49254941
**
49264942
** See also: [sqlite3_release_memory()]
49274943
*/
49284944
SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -5293,14 +5309,26 @@
52935309
**
52945310
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
52955311
** the correct order to satisfy the ORDER BY clause so that no separate
52965312
** sorting step is required.
52975313
**
5298
-** ^The estimatedCost value is an estimate of the cost of doing the
5299
-** particular lookup. A full scan of a table with N entries should have
5300
-** a cost of N. A binary search of a table of N entries should have a
5301
-** cost of approximately log(N).
5314
+** ^The estimatedCost value is an estimate of the cost of a particular
5315
+** strategy. A cost of N indicates that the cost of the strategy is similar
5316
+** to a linear scan of an SQLite table with N rows. A cost of log(N)
5317
+** indicates that the expense of the operation is similar to that of a
5318
+** binary search on a unique indexed field of an SQLite table with N rows.
5319
+**
5320
+** ^The estimatedRows value is an estimate of the number of rows that
5321
+** will be returned by the strategy.
5322
+**
5323
+** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5324
+** structure for SQLite version 3.8.2. If a virtual table extension is
5325
+** used with an SQLite version earlier than 3.8.2, the results of attempting
5326
+** to read or write the estimatedRows field are undefined (but are likely
5327
+** to included crashing the application). The estimatedRows field should
5328
+** therefore only be used if [sqlite3_libversion_number()] returns a
5329
+** value greater than or equal to 3008002.
53025330
*/
53035331
struct sqlite3_index_info {
53045332
/* Inputs */
53055333
int nConstraint; /* Number of entries in aConstraint */
53065334
struct sqlite3_index_constraint {
@@ -5321,11 +5349,13 @@
53215349
} *aConstraintUsage;
53225350
int idxNum; /* Number used to identify the index */
53235351
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
53245352
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
53255353
int orderByConsumed; /* True if output is already ordered */
5326
- double estimatedCost; /* Estimated cost of using this index */
5354
+ double estimatedCost; /* Estimated cost of using this index */
5355
+ /* Fields below are only available in SQLite 3.8.2 and later */
5356
+ sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
53275357
};
53285358
53295359
/*
53305360
** CAPI3REF: Virtual Table Constraint Operator Codes
53315361
**
@@ -6051,11 +6081,12 @@
60516081
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
60526082
#define SQLITE_TESTCTRL_ISKEYWORD 16
60536083
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
60546084
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
60556085
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6056
-#define SQLITE_TESTCTRL_LAST 19
6086
+#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6087
+#define SQLITE_TESTCTRL_LAST 20
60576088
60586089
/*
60596090
** CAPI3REF: SQLite Runtime Status
60606091
**
60616092
** ^This interface is used to retrieve runtime status information
60626093
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -368,11 +368,11 @@
368 ** Restrictions:
369 **
370 ** <ul>
371 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
372 ** is a valid and open [database connection].
373 ** <li> The application must not close [database connection] specified by
374 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
375 ** <li> The application must not modify the SQL statement text passed into
376 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
377 ** </ul>
378 */
@@ -445,11 +445,11 @@
445 ** about errors. The extended result codes are enabled or disabled
446 ** on a per database connection basis using the
447 ** [sqlite3_extended_result_codes()] API.
448 **
449 ** Some of the available extended result codes are listed here.
450 ** One may expect the number of extended result codes will be expand
451 ** over time. Software that uses extended result codes should expect
452 ** to see new result codes in future releases of SQLite.
453 **
454 ** The SQLITE_OK result code will never be extended. It will always
455 ** be exactly zero.
@@ -489,10 +489,11 @@
489 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
 
494 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
495 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
496 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
497 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
498 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -556,11 +557,12 @@
556 ** information is written to disk in the same order as calls
557 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
558 ** after reboot following a crash or power loss, the only bytes in a
559 ** file that were written at the application level might have changed
560 ** and that adjacent bytes, even bytes within the same sector are
561 ** guaranteed to be unchanged.
 
562 */
563 #define SQLITE_IOCAP_ATOMIC 0x00000001
564 #define SQLITE_IOCAP_ATOMIC512 0x00000002
565 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
566 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -919,10 +921,16 @@
919 ** This file control is used by some VFS activity tracing [shims].
920 ** The argument is a zero-terminated string. Higher layers in the
921 ** SQLite stack may generate instances of this file control if
922 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
923 **
 
 
 
 
 
 
924 ** </ul>
925 */
926 #define SQLITE_FCNTL_LOCKSTATE 1
927 #define SQLITE_GET_LOCKPROXYFILE 2
928 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -939,10 +947,11 @@
939 #define SQLITE_FCNTL_PRAGMA 14
940 #define SQLITE_FCNTL_BUSYHANDLER 15
941 #define SQLITE_FCNTL_TEMPFILENAME 16
942 #define SQLITE_FCNTL_MMAP_SIZE 18
943 #define SQLITE_FCNTL_TRACE 19
 
944
945 /*
946 ** CAPI3REF: Mutex Handle
947 **
948 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1383,11 +1392,11 @@
1383 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1384 ** Every memory allocation request coming in through [sqlite3_malloc()]
1385 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1386 ** that causes the corresponding memory allocation to fail.
1387 **
1388 ** The xInit method initializes the memory allocator. (For example,
1389 ** it might allocate any require mutexes or initialize internal data
1390 ** structures. The xShutdown method is invoked (indirectly) by
1391 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1392 ** by xInit. The pAppData pointer is used as the only parameter to
1393 ** xInit and xShutdown.
@@ -1685,10 +1694,17 @@
1685 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1686 ** exceed the compile-time maximum mmap size set by the
1687 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1688 ** ^If either argument to this option is negative, then that argument is
1689 ** changed to its compile-time default.
 
 
 
 
 
 
 
1690 ** </dl>
1691 */
1692 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1693 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1694 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1709,10 +1725,11 @@
1709 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
1710 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1711 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1712 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1713 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
 
1714
1715 /*
1716 ** CAPI3REF: Database Connection Configuration Options
1717 **
1718 ** These constants are the available integer configuration options that
@@ -3109,11 +3126,10 @@
3109 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3110 ** ^The specific value of WHERE-clause [parameter] might influence the
3111 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3112 ** or [GLOB] operator or if the parameter is compared to an indexed column
3113 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3114 ** the
3115 ** </li>
3116 ** </ol>
3117 */
3118 SQLITE_API int sqlite3_prepare(
3119 sqlite3 *db, /* Database handle */
@@ -3771,23 +3787,23 @@
3771 ** <table border="1">
3772 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
3773 **
3774 ** <tr><td> NULL <td> INTEGER <td> Result is 0
3775 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3776 ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
3777 ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
3778 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
3779 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
3780 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3781 ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
3782 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3783 ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
3784 ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
3785 ** <tr><td> TEXT <td> FLOAT <td> Use atof()
3786 ** <tr><td> TEXT <td> BLOB <td> No change
3787 ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
3788 ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
3789 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
3790 ** </table>
3791 ** </blockquote>)^
3792 **
3793 ** The table above makes reference to standard C library functions atoi()
@@ -3839,11 +3855,11 @@
3839 **
3840 ** ^The pointers returned are valid until a type conversion occurs as
3841 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3842 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3843 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3844 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3845 ** [sqlite3_free()].
3846 **
3847 ** ^(If a memory allocation error occurs during the evaluation of any
3848 ** of these routines, a default value is returned. The default value
3849 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4917,12 +4933,12 @@
4917 /*
4918 ** CAPI3REF: Free Memory Used By A Database Connection
4919 **
4920 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4921 ** memory as possible from database connection D. Unlike the
4922 ** [sqlite3_release_memory()] interface, this interface is effect even
4923 ** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4924 ** omitted.
4925 **
4926 ** See also: [sqlite3_release_memory()]
4927 */
4928 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -5293,14 +5309,26 @@
5293 **
5294 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5295 ** the correct order to satisfy the ORDER BY clause so that no separate
5296 ** sorting step is required.
5297 **
5298 ** ^The estimatedCost value is an estimate of the cost of doing the
5299 ** particular lookup. A full scan of a table with N entries should have
5300 ** a cost of N. A binary search of a table of N entries should have a
5301 ** cost of approximately log(N).
 
 
 
 
 
 
 
 
 
 
 
 
5302 */
5303 struct sqlite3_index_info {
5304 /* Inputs */
5305 int nConstraint; /* Number of entries in aConstraint */
5306 struct sqlite3_index_constraint {
@@ -5321,11 +5349,13 @@
5321 } *aConstraintUsage;
5322 int idxNum; /* Number used to identify the index */
5323 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5324 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5325 int orderByConsumed; /* True if output is already ordered */
5326 double estimatedCost; /* Estimated cost of using this index */
 
 
5327 };
5328
5329 /*
5330 ** CAPI3REF: Virtual Table Constraint Operator Codes
5331 **
@@ -6051,11 +6081,12 @@
6051 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6052 #define SQLITE_TESTCTRL_ISKEYWORD 16
6053 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6054 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6055 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6056 #define SQLITE_TESTCTRL_LAST 19
 
6057
6058 /*
6059 ** CAPI3REF: SQLite Runtime Status
6060 **
6061 ** ^This interface is used to retrieve runtime status information
6062
--- 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"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -368,11 +368,11 @@
368 ** Restrictions:
369 **
370 ** <ul>
371 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
372 ** is a valid and open [database connection].
373 ** <li> The application must not close the [database connection] specified by
374 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
375 ** <li> The application must not modify the SQL statement text passed into
376 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
377 ** </ul>
378 */
@@ -445,11 +445,11 @@
445 ** about errors. The extended result codes are enabled or disabled
446 ** on a per database connection basis using the
447 ** [sqlite3_extended_result_codes()] API.
448 **
449 ** Some of the available extended result codes are listed here.
450 ** One may expect the number of extended result codes will increase
451 ** over time. Software that uses extended result codes should expect
452 ** to see new result codes in future releases of SQLite.
453 **
454 ** The SQLITE_OK result code will never be extended. It will always
455 ** be exactly zero.
@@ -489,10 +489,11 @@
489 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
494 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
495 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
496 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
497 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
498 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
499 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -556,11 +557,12 @@
557 ** information is written to disk in the same order as calls
558 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
559 ** after reboot following a crash or power loss, the only bytes in a
560 ** file that were written at the application level might have changed
561 ** and that adjacent bytes, even bytes within the same sector are
562 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
563 ** flag indicate that a file cannot be deleted when open.
564 */
565 #define SQLITE_IOCAP_ATOMIC 0x00000001
566 #define SQLITE_IOCAP_ATOMIC512 0x00000002
567 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
568 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -919,10 +921,16 @@
921 ** This file control is used by some VFS activity tracing [shims].
922 ** The argument is a zero-terminated string. Higher layers in the
923 ** SQLite stack may generate instances of this file control if
924 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
925 **
926 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
927 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
928 ** pointer to an integer and it writes a boolean into that integer depending
929 ** on whether or not the file has been renamed, moved, or deleted since it
930 ** was first opened.
931 **
932 ** </ul>
933 */
934 #define SQLITE_FCNTL_LOCKSTATE 1
935 #define SQLITE_GET_LOCKPROXYFILE 2
936 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -939,10 +947,11 @@
947 #define SQLITE_FCNTL_PRAGMA 14
948 #define SQLITE_FCNTL_BUSYHANDLER 15
949 #define SQLITE_FCNTL_TEMPFILENAME 16
950 #define SQLITE_FCNTL_MMAP_SIZE 18
951 #define SQLITE_FCNTL_TRACE 19
952 #define SQLITE_FCNTL_HAS_MOVED 20
953
954 /*
955 ** CAPI3REF: Mutex Handle
956 **
957 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -1383,11 +1392,11 @@
1392 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1393 ** Every memory allocation request coming in through [sqlite3_malloc()]
1394 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1395 ** that causes the corresponding memory allocation to fail.
1396 **
1397 ** The xInit method initializes the memory allocator. For example,
1398 ** it might allocate any require mutexes or initialize internal data
1399 ** structures. The xShutdown method is invoked (indirectly) by
1400 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1401 ** by xInit. The pAppData pointer is used as the only parameter to
1402 ** xInit and xShutdown.
@@ -1685,10 +1694,17 @@
1694 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1695 ** exceed the compile-time maximum mmap size set by the
1696 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1697 ** ^If either argument to this option is negative, then that argument is
1698 ** changed to its compile-time default.
1699 **
1700 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1701 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1702 ** <dd>^This option is only available if SQLite is compiled for Windows
1703 ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1704 ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1705 ** that specifies the maximum size of the created heap.
1706 ** </dl>
1707 */
1708 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1709 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1710 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1709,10 +1725,11 @@
1725 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
1726 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1727 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1728 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1729 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1730 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1731
1732 /*
1733 ** CAPI3REF: Database Connection Configuration Options
1734 **
1735 ** These constants are the available integer configuration options that
@@ -3109,11 +3126,10 @@
3126 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3127 ** ^The specific value of WHERE-clause [parameter] might influence the
3128 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3129 ** or [GLOB] operator or if the parameter is compared to an indexed column
3130 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
 
3131 ** </li>
3132 ** </ol>
3133 */
3134 SQLITE_API int sqlite3_prepare(
3135 sqlite3 *db, /* Database handle */
@@ -3771,23 +3787,23 @@
3787 ** <table border="1">
3788 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
3789 **
3790 ** <tr><td> NULL <td> INTEGER <td> Result is 0
3791 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3792 ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
3793 ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
3794 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
3795 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
3796 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3797 ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
3798 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3799 ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
3800 ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
3801 ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
3802 ** <tr><td> TEXT <td> BLOB <td> No change
3803 ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
3804 ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
3805 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
3806 ** </table>
3807 ** </blockquote>)^
3808 **
3809 ** The table above makes reference to standard C library functions atoi()
@@ -3839,11 +3855,11 @@
3855 **
3856 ** ^The pointers returned are valid until a type conversion occurs as
3857 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3858 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3859 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3860 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3861 ** [sqlite3_free()].
3862 **
3863 ** ^(If a memory allocation error occurs during the evaluation of any
3864 ** of these routines, a default value is returned. The default value
3865 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4917,12 +4933,12 @@
4933 /*
4934 ** CAPI3REF: Free Memory Used By A Database Connection
4935 **
4936 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4937 ** memory as possible from database connection D. Unlike the
4938 ** [sqlite3_release_memory()] interface, this interface is in effect even
4939 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4940 ** omitted.
4941 **
4942 ** See also: [sqlite3_release_memory()]
4943 */
4944 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -5293,14 +5309,26 @@
5309 **
5310 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5311 ** the correct order to satisfy the ORDER BY clause so that no separate
5312 ** sorting step is required.
5313 **
5314 ** ^The estimatedCost value is an estimate of the cost of a particular
5315 ** strategy. A cost of N indicates that the cost of the strategy is similar
5316 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
5317 ** indicates that the expense of the operation is similar to that of a
5318 ** binary search on a unique indexed field of an SQLite table with N rows.
5319 **
5320 ** ^The estimatedRows value is an estimate of the number of rows that
5321 ** will be returned by the strategy.
5322 **
5323 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5324 ** structure for SQLite version 3.8.2. If a virtual table extension is
5325 ** used with an SQLite version earlier than 3.8.2, the results of attempting
5326 ** to read or write the estimatedRows field are undefined (but are likely
5327 ** to included crashing the application). The estimatedRows field should
5328 ** therefore only be used if [sqlite3_libversion_number()] returns a
5329 ** value greater than or equal to 3008002.
5330 */
5331 struct sqlite3_index_info {
5332 /* Inputs */
5333 int nConstraint; /* Number of entries in aConstraint */
5334 struct sqlite3_index_constraint {
@@ -5321,11 +5349,13 @@
5349 } *aConstraintUsage;
5350 int idxNum; /* Number used to identify the index */
5351 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5352 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5353 int orderByConsumed; /* True if output is already ordered */
5354 double estimatedCost; /* Estimated cost of using this index */
5355 /* Fields below are only available in SQLite 3.8.2 and later */
5356 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
5357 };
5358
5359 /*
5360 ** CAPI3REF: Virtual Table Constraint Operator Codes
5361 **
@@ -6051,11 +6081,12 @@
6081 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6082 #define SQLITE_TESTCTRL_ISKEYWORD 16
6083 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6084 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6085 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6086 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6087 #define SQLITE_TESTCTRL_LAST 20
6088
6089 /*
6090 ** CAPI3REF: SQLite Runtime Status
6091 **
6092 ** ^This interface is used to retrieve runtime status information
6093
+30 -6
--- src/stat.c
+++ src/stat.c
@@ -55,10 +55,11 @@
5555
if( !g.perm.Read ){ login_needed(); return; }
5656
brief = P("brief")!=0;
5757
style_header("Repository Statistics");
5858
if( g.perm.Admin ){
5959
style_submenu_element("URLs", "URLs and Checkouts", "urllist");
60
+ style_submenu_element("Schema", "Repository Schema", "repo_schema");
6061
}
6162
@ <table class="label-value">
6263
@ <tr><th>Repository&nbsp;Size:</th><td>
6364
fsize = file_size(g.zRepositoryName);
6465
bigSizeName(sizeof(zBuf), zBuf, fsize);
@@ -122,12 +123,12 @@
122123
@ <tr><th>Project&nbsp;ID:</th><td>%h(db_get("project-code",""))</td></tr>
123124
@ <tr><th>Fossil&nbsp;Version:</th><td>
124125
@ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
125126
@ (%h(RELEASE_VERSION)) [compiled using %h(COMPILER_NAME)]
126127
@ </td></tr>
127
- @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(SQLITE_SOURCE_ID)
128
- @ [%.10s(&SQLITE_SOURCE_ID[20])] (%s(SQLITE_VERSION))</td></tr>
128
+ @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
129
+ @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))</td></tr>
129130
@ <tr><th>Repository Rebuilt:</th><td>
130131
@ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
131132
@ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
132133
@ <tr><th>Database&nbsp;Stats:</th><td>
133134
zDb = db_name("repository");
@@ -223,12 +224,12 @@
223224
colWidth, "fossil-version:",
224225
MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
225226
COMPILER_NAME);
226227
fossil_print("%*s%.19s [%.10s] (%s)\n",
227228
colWidth, "sqlite-version:",
228
- SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20],
229
- SQLITE_VERSION);
229
+ sqlite3_sourceid(), &sqlite3_sourceid()[20],
230
+ sqlite3_libversion());
230231
zDb = db_name("repository");
231232
fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
232233
"%s, %s mode\n",
233234
colWidth, "database-stats:",
234235
db_int(0, "PRAGMA %s.page_count", zDb),
@@ -236,12 +237,10 @@
236237
db_int(0, "PRAGMA %s.freelist_count", zDb),
237238
db_text(0, "PRAGMA %s.encoding", zDb),
238239
db_text(0, "PRAGMA %s.journal_mode", zDb));
239240
240241
}
241
-
242
-
243242
244243
/*
245244
** WEBPAGE: urllist
246245
**
247246
** Show ways in which this repository has been accessed
@@ -252,10 +251,11 @@
252251
login_check_credentials();
253252
if( !g.perm.Admin ){ login_needed(); return; }
254253
255254
style_header("URLs and Checkouts");
256255
style_submenu_element("Stat", "Repository Stats", "stat");
256
+ style_submenu_element("Schema", "Repository Schema", "repo_schema");
257257
@ <div class="section">URLs</div>
258258
@ <table border="0" width='100%%'>
259259
db_prepare(&q, "SELECT substr(name,9), datetime(mtime,'unixepoch')"
260260
" FROM config WHERE name GLOB 'baseurl:*' ORDER BY 2 DESC");
261261
cnt = 0;
@@ -284,5 +284,29 @@
284284
@ <tr><td>(none)</td>
285285
}
286286
@ </table>
287287
style_footer();
288288
}
289
+
290
+/*
291
+** WEBPAGE: repo_schema
292
+**
293
+** Show the repository schema
294
+*/
295
+void repo_schema_page(void){
296
+ Stmt q;
297
+ login_check_credentials();
298
+ if( !g.perm.Admin ){ login_needed(); return; }
299
+
300
+ style_header("Repository Schema");
301
+ style_submenu_element("Stat", "Repository Stats", "stat");
302
+ style_submenu_element("URLs", "URLs and Checkouts", "urllist");
303
+ db_prepare(&q, "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
304
+ db_name("repository"));
305
+ @ <pre>
306
+ while( db_step(&q)==SQLITE_ROW ){
307
+ @ %h(db_column_text(&q, 0));
308
+ }
309
+ @ </pre>
310
+ db_finalize(&q);
311
+ style_footer();
312
+}
289313
--- src/stat.c
+++ src/stat.c
@@ -55,10 +55,11 @@
55 if( !g.perm.Read ){ login_needed(); return; }
56 brief = P("brief")!=0;
57 style_header("Repository Statistics");
58 if( g.perm.Admin ){
59 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
 
60 }
61 @ <table class="label-value">
62 @ <tr><th>Repository&nbsp;Size:</th><td>
63 fsize = file_size(g.zRepositoryName);
64 bigSizeName(sizeof(zBuf), zBuf, fsize);
@@ -122,12 +123,12 @@
122 @ <tr><th>Project&nbsp;ID:</th><td>%h(db_get("project-code",""))</td></tr>
123 @ <tr><th>Fossil&nbsp;Version:</th><td>
124 @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
125 @ (%h(RELEASE_VERSION)) [compiled using %h(COMPILER_NAME)]
126 @ </td></tr>
127 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(SQLITE_SOURCE_ID)
128 @ [%.10s(&SQLITE_SOURCE_ID[20])] (%s(SQLITE_VERSION))</td></tr>
129 @ <tr><th>Repository Rebuilt:</th><td>
130 @ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
131 @ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
132 @ <tr><th>Database&nbsp;Stats:</th><td>
133 zDb = db_name("repository");
@@ -223,12 +224,12 @@
223 colWidth, "fossil-version:",
224 MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
225 COMPILER_NAME);
226 fossil_print("%*s%.19s [%.10s] (%s)\n",
227 colWidth, "sqlite-version:",
228 SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20],
229 SQLITE_VERSION);
230 zDb = db_name("repository");
231 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
232 "%s, %s mode\n",
233 colWidth, "database-stats:",
234 db_int(0, "PRAGMA %s.page_count", zDb),
@@ -236,12 +237,10 @@
236 db_int(0, "PRAGMA %s.freelist_count", zDb),
237 db_text(0, "PRAGMA %s.encoding", zDb),
238 db_text(0, "PRAGMA %s.journal_mode", zDb));
239
240 }
241
242
243
244 /*
245 ** WEBPAGE: urllist
246 **
247 ** Show ways in which this repository has been accessed
@@ -252,10 +251,11 @@
252 login_check_credentials();
253 if( !g.perm.Admin ){ login_needed(); return; }
254
255 style_header("URLs and Checkouts");
256 style_submenu_element("Stat", "Repository Stats", "stat");
 
257 @ <div class="section">URLs</div>
258 @ <table border="0" width='100%%'>
259 db_prepare(&q, "SELECT substr(name,9), datetime(mtime,'unixepoch')"
260 " FROM config WHERE name GLOB 'baseurl:*' ORDER BY 2 DESC");
261 cnt = 0;
@@ -284,5 +284,29 @@
284 @ <tr><td>(none)</td>
285 }
286 @ </table>
287 style_footer();
288 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
--- src/stat.c
+++ src/stat.c
@@ -55,10 +55,11 @@
55 if( !g.perm.Read ){ login_needed(); return; }
56 brief = P("brief")!=0;
57 style_header("Repository Statistics");
58 if( g.perm.Admin ){
59 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
60 style_submenu_element("Schema", "Repository Schema", "repo_schema");
61 }
62 @ <table class="label-value">
63 @ <tr><th>Repository&nbsp;Size:</th><td>
64 fsize = file_size(g.zRepositoryName);
65 bigSizeName(sizeof(zBuf), zBuf, fsize);
@@ -122,12 +123,12 @@
123 @ <tr><th>Project&nbsp;ID:</th><td>%h(db_get("project-code",""))</td></tr>
124 @ <tr><th>Fossil&nbsp;Version:</th><td>
125 @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
126 @ (%h(RELEASE_VERSION)) [compiled using %h(COMPILER_NAME)]
127 @ </td></tr>
128 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
129 @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))</td></tr>
130 @ <tr><th>Repository Rebuilt:</th><td>
131 @ %h(db_get_mtime("rebuilt","%Y-%m-%d %H:%M:%S","Never"))
132 @ By Fossil %h(db_get("rebuilt","Unknown"))</td></tr>
133 @ <tr><th>Database&nbsp;Stats:</th><td>
134 zDb = db_name("repository");
@@ -223,12 +224,12 @@
224 colWidth, "fossil-version:",
225 MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
226 COMPILER_NAME);
227 fossil_print("%*s%.19s [%.10s] (%s)\n",
228 colWidth, "sqlite-version:",
229 sqlite3_sourceid(), &sqlite3_sourceid()[20],
230 sqlite3_libversion());
231 zDb = db_name("repository");
232 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
233 "%s, %s mode\n",
234 colWidth, "database-stats:",
235 db_int(0, "PRAGMA %s.page_count", zDb),
@@ -236,12 +237,10 @@
237 db_int(0, "PRAGMA %s.freelist_count", zDb),
238 db_text(0, "PRAGMA %s.encoding", zDb),
239 db_text(0, "PRAGMA %s.journal_mode", zDb));
240
241 }
 
 
242
243 /*
244 ** WEBPAGE: urllist
245 **
246 ** Show ways in which this repository has been accessed
@@ -252,10 +251,11 @@
251 login_check_credentials();
252 if( !g.perm.Admin ){ login_needed(); return; }
253
254 style_header("URLs and Checkouts");
255 style_submenu_element("Stat", "Repository Stats", "stat");
256 style_submenu_element("Schema", "Repository Schema", "repo_schema");
257 @ <div class="section">URLs</div>
258 @ <table border="0" width='100%%'>
259 db_prepare(&q, "SELECT substr(name,9), datetime(mtime,'unixepoch')"
260 " FROM config WHERE name GLOB 'baseurl:*' ORDER BY 2 DESC");
261 cnt = 0;
@@ -284,5 +284,29 @@
284 @ <tr><td>(none)</td>
285 }
286 @ </table>
287 style_footer();
288 }
289
290 /*
291 ** WEBPAGE: repo_schema
292 **
293 ** Show the repository schema
294 */
295 void repo_schema_page(void){
296 Stmt q;
297 login_check_credentials();
298 if( !g.perm.Admin ){ login_needed(); return; }
299
300 style_header("Repository Schema");
301 style_submenu_element("Stat", "Repository Stats", "stat");
302 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
303 db_prepare(&q, "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
304 db_name("repository"));
305 @ <pre>
306 while( db_step(&q)==SQLITE_ROW ){
307 @ %h(db_column_text(&q, 0));
308 }
309 @ </pre>
310 db_finalize(&q);
311 style_footer();
312 }
313
+6 -6
--- src/style.c
+++ src/style.c
@@ -1114,18 +1114,18 @@
11141114
int i;
11151115
11161116
for (i=0;cssDefaultList[i].elementClass;i++){
11171117
if (cssDefaultList[i].elementClass[0]){
11181118
cgi_printf("/* %s */\n%s {\n%s\n}\n\n",
1119
- cssDefaultList[i].comment,
1120
- cssDefaultList[i].elementClass,
1121
- cssDefaultList[i].value
1122
- );
1119
+ cssDefaultList[i].comment,
1120
+ cssDefaultList[i].elementClass,
1121
+ cssDefaultList[i].value
1122
+ );
11231123
}else{
11241124
cgi_printf("%s",
1125
- cssDefaultList[i].value
1126
- );
1125
+ cssDefaultList[i].value
1126
+ );
11271127
}
11281128
}
11291129
}
11301130
11311131
/*
11321132
--- src/style.c
+++ src/style.c
@@ -1114,18 +1114,18 @@
1114 int i;
1115
1116 for (i=0;cssDefaultList[i].elementClass;i++){
1117 if (cssDefaultList[i].elementClass[0]){
1118 cgi_printf("/* %s */\n%s {\n%s\n}\n\n",
1119 cssDefaultList[i].comment,
1120 cssDefaultList[i].elementClass,
1121 cssDefaultList[i].value
1122 );
1123 }else{
1124 cgi_printf("%s",
1125 cssDefaultList[i].value
1126 );
1127 }
1128 }
1129 }
1130
1131 /*
1132
--- src/style.c
+++ src/style.c
@@ -1114,18 +1114,18 @@
1114 int i;
1115
1116 for (i=0;cssDefaultList[i].elementClass;i++){
1117 if (cssDefaultList[i].elementClass[0]){
1118 cgi_printf("/* %s */\n%s {\n%s\n}\n\n",
1119 cssDefaultList[i].comment,
1120 cssDefaultList[i].elementClass,
1121 cssDefaultList[i].value
1122 );
1123 }else{
1124 cgi_printf("%s",
1125 cssDefaultList[i].value
1126 );
1127 }
1128 }
1129 }
1130
1131 /*
1132
+43 -9
--- src/timeline.c
+++ src/timeline.c
@@ -111,10 +111,11 @@
111111
#define TIMELINE_DISJOINT 0x0010 /* Elements are not contiguous */
112112
#define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
113113
#define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
114114
#define TIMELINE_UCOLOR 0x0080 /* Background color by user */
115115
#define TIMELINE_FRENAMES 0x0100 /* Detail only file name changes */
116
+#define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
116117
#endif
117118
118119
/*
119120
** Hash a string and use the hash to determine a background color.
120121
*/
@@ -589,10 +590,11 @@
589590
){
590591
if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
591592
GraphRow *pRow;
592593
int i;
593594
char cSep;
595
+
594596
@ <script type="text/JavaScript">
595597
@ /* <![CDATA[ */
596598
@ var railPitch=%d(pGraph->iRailPitch);
597599
598600
/* the rowinfo[] array contains all the information needed to generate
@@ -850,11 +852,15 @@
850852
@ selRow = null;
851853
@ }else{
852854
if( fileDiff ){
853855
@ location.href="%R/fdiff?v1="+selRow.h+"&v2="+p.h+"&sbs=1";
854856
}else{
855
- @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=1";
857
+ if( db_get_boolean("show-version-diffs", 0)==0 ){
858
+ @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=0";
859
+ }else{
860
+ @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=1";
861
+ }
856862
}
857863
@ }
858864
@ }
859865
@ var lastId = "m"+rowinfo[rowinfo.length-1].id;
860866
@ var lastY = 0;
@@ -898,11 +904,10 @@
898904
/*
899905
** Return a pointer to a constant string that forms the basis
900906
** for a timeline query for the WWW interface.
901907
*/
902908
const char *timeline_query_for_www(void){
903
- static char *zBase = 0;
904909
static const char zBaseSql[] =
905910
@ SELECT
906911
@ blob.rid AS blobRid,
907912
@ uuid AS uuid,
908913
@ datetime(event.mtime,'localtime') AS timestamp,
@@ -918,14 +923,11 @@
918923
@ brief AS brief,
919924
@ event.mtime AS mtime
920925
@ FROM event CROSS JOIN blob
921926
@ WHERE blob.rid=event.objid
922927
;
923
- if( zBase==0 ){
924
- zBase = mprintf(zBaseSql, TAG_BRANCH, TAG_BRANCH);
925
- }
926
- return zBase;
928
+ return zBaseSql;
927929
}
928930
929931
/*
930932
** Generate a submenu element with a single parameter change.
931933
*/
@@ -1117,10 +1119,13 @@
11171119
}
11181120
if( P("brbg")!=0 ){
11191121
tmFlags |= TIMELINE_BRCOLOR;
11201122
url_add_parameter(&url, "brbg", 0);
11211123
}
1124
+ if( P("unhide")!=0 ){
1125
+ tmFlags |= TIMELINE_UNHIDE;
1126
+ }
11221127
if( P("ubg")!=0 ){
11231128
tmFlags |= TIMELINE_UCOLOR;
11241129
url_add_parameter(&url, "ubg", 0);
11251130
}
11261131
if( zUses!=0 ){
@@ -1151,10 +1156,15 @@
11511156
blob_append(&sql, "INSERT OR IGNORE INTO timeline ", -1);
11521157
blob_append(&sql, timeline_query_for_www(), -1);
11531158
if( P("fc")!=0 || P("v")!=0 || P("detail")!=0 ){
11541159
tmFlags |= TIMELINE_FCHANGES;
11551160
url_add_parameter(&url, "v", 0);
1161
+ }
1162
+ if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1163
+ blob_appendf(&sql, " AND NOT EXISTS(SELECT 1 FROM tagxref"
1164
+ " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)",
1165
+ TAG_HIDDEN);
11561166
}
11571167
if( !useDividers ) url_add_parameter(&url, "nd", 0);
11581168
if( ((from_rid && to_rid) || (me_rid && you_rid)) && g.perm.Read ){
11591169
/* If from= and to= are present, display all nodes on a path connecting
11601170
** the two */
@@ -1276,16 +1286,28 @@
12761286
blob_appendf(&sql,
12771287
" OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=cid"
12781288
" WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
12791289
tagid
12801290
);
1291
+ if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1292
+ blob_appendf(&sql,
1293
+ " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid"
1294
+ " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
1295
+ TAG_HIDDEN
1296
+ );
1297
+ }
12811298
if( P("mionly")==0 ){
12821299
blob_appendf(&sql,
12831300
" OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=pid"
12841301
" WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
12851302
tagid
12861303
);
1304
+ if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1305
+ blob_appendf(&sql, " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid"
1306
+ " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
1307
+ TAG_HIDDEN);
1308
+ }
12871309
}else{
12881310
url_add_parameter(&url, "mionly", "1");
12891311
}
12901312
}else{
12911313
url_add_parameter(&url, "t", zTagName);
@@ -1521,18 +1543,19 @@
15211543
int nEntry = 0;
15221544
char zPrevDate[20];
15231545
const char *zCurrentUuid = 0;
15241546
int fchngQueryInit = 0; /* True if fchngQuery is initialized */
15251547
Stmt fchngQuery; /* Query for file changes on check-ins */
1548
+ int rc;
15261549
15271550
zPrevDate[0] = 0;
15281551
if( g.localOpen ){
15291552
int rid = db_lget_int("checkout", 0);
15301553
zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
15311554
}
15321555
1533
- while( db_step(q)==SQLITE_ROW ){
1556
+ while( (rc=db_step(q))==SQLITE_ROW ){
15341557
int rid = db_column_int(q, 0);
15351558
const char *zId = db_column_text(q, 1);
15361559
const char *zDate = db_column_text(q, 2);
15371560
const char *zCom = db_column_text(q, 3);
15381561
int nChild = db_column_int(q, 4);
@@ -1611,10 +1634,18 @@
16111634
nLine++; /* record another line */
16121635
}
16131636
db_reset(&fchngQuery);
16141637
}
16151638
nEntry++; /* record another complete entry */
1639
+ }
1640
+ if( rc==SQLITE_DONE ){
1641
+ /* Did the underlying query actually have all entries? */
1642
+ if( nAbsLimit==0 ){
1643
+ fossil_print("+++ end of timeline (%d) +++\n", nEntry);
1644
+ }else{
1645
+ fossil_print("+++ no more data (%d) +++\n", nEntry);
1646
+ }
16161647
}
16171648
if( fchngQueryInit ) db_finalize(&fchngQuery);
16181649
}
16191650
16201651
/*
@@ -1752,11 +1783,12 @@
17521783
}else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
17531784
mode = 4;
17541785
}else if( strncmp(g.argv[2],"parents",k)==0 ){
17551786
mode = 4;
17561787
}else if(!zType && !zLimit){
1757
- usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit #? ?-t|--type TYPE? ?-W|--width WIDTH?");
1788
+ usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit #? ?-t|--type TYPE? "
1789
+ "?-W|--width WIDTH?");
17581790
}
17591791
if( '-' != *g.argv[3] ){
17601792
zOrigin = g.argv[3];
17611793
}else{
17621794
zOrigin = "now";
@@ -1813,11 +1845,13 @@
18131845
if( zType && (zType[0]!='a') ){
18141846
blob_appendf(&sql, " AND event.type=%Q ", zType);
18151847
}
18161848
blob_appendf(&sql, " ORDER BY event.mtime DESC");
18171849
if( iOffset>0 ){
1818
- blob_appendf(&sql, " LIMIT %d OFFSET %d", n>0?n+1:99999, iOffset);
1850
+ /* Don't handle LIMIT here, otherwise print_timeline()
1851
+ * will not determine the end-marker correctly! */
1852
+ blob_appendf(&sql, " LIMIT -1 OFFSET %d", iOffset);
18191853
}
18201854
db_prepare(&q, blob_str(&sql));
18211855
blob_reset(&sql);
18221856
print_timeline(&q, n, width, verboseFlag);
18231857
db_finalize(&q);
18241858
--- src/timeline.c
+++ src/timeline.c
@@ -111,10 +111,11 @@
111 #define TIMELINE_DISJOINT 0x0010 /* Elements are not contiguous */
112 #define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
113 #define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
114 #define TIMELINE_UCOLOR 0x0080 /* Background color by user */
115 #define TIMELINE_FRENAMES 0x0100 /* Detail only file name changes */
 
116 #endif
117
118 /*
119 ** Hash a string and use the hash to determine a background color.
120 */
@@ -589,10 +590,11 @@
589 ){
590 if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
591 GraphRow *pRow;
592 int i;
593 char cSep;
 
594 @ <script type="text/JavaScript">
595 @ /* <![CDATA[ */
596 @ var railPitch=%d(pGraph->iRailPitch);
597
598 /* the rowinfo[] array contains all the information needed to generate
@@ -850,11 +852,15 @@
850 @ selRow = null;
851 @ }else{
852 if( fileDiff ){
853 @ location.href="%R/fdiff?v1="+selRow.h+"&v2="+p.h+"&sbs=1";
854 }else{
855 @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=1";
 
 
 
 
856 }
857 @ }
858 @ }
859 @ var lastId = "m"+rowinfo[rowinfo.length-1].id;
860 @ var lastY = 0;
@@ -898,11 +904,10 @@
898 /*
899 ** Return a pointer to a constant string that forms the basis
900 ** for a timeline query for the WWW interface.
901 */
902 const char *timeline_query_for_www(void){
903 static char *zBase = 0;
904 static const char zBaseSql[] =
905 @ SELECT
906 @ blob.rid AS blobRid,
907 @ uuid AS uuid,
908 @ datetime(event.mtime,'localtime') AS timestamp,
@@ -918,14 +923,11 @@
918 @ brief AS brief,
919 @ event.mtime AS mtime
920 @ FROM event CROSS JOIN blob
921 @ WHERE blob.rid=event.objid
922 ;
923 if( zBase==0 ){
924 zBase = mprintf(zBaseSql, TAG_BRANCH, TAG_BRANCH);
925 }
926 return zBase;
927 }
928
929 /*
930 ** Generate a submenu element with a single parameter change.
931 */
@@ -1117,10 +1119,13 @@
1117 }
1118 if( P("brbg")!=0 ){
1119 tmFlags |= TIMELINE_BRCOLOR;
1120 url_add_parameter(&url, "brbg", 0);
1121 }
 
 
 
1122 if( P("ubg")!=0 ){
1123 tmFlags |= TIMELINE_UCOLOR;
1124 url_add_parameter(&url, "ubg", 0);
1125 }
1126 if( zUses!=0 ){
@@ -1151,10 +1156,15 @@
1151 blob_append(&sql, "INSERT OR IGNORE INTO timeline ", -1);
1152 blob_append(&sql, timeline_query_for_www(), -1);
1153 if( P("fc")!=0 || P("v")!=0 || P("detail")!=0 ){
1154 tmFlags |= TIMELINE_FCHANGES;
1155 url_add_parameter(&url, "v", 0);
 
 
 
 
 
1156 }
1157 if( !useDividers ) url_add_parameter(&url, "nd", 0);
1158 if( ((from_rid && to_rid) || (me_rid && you_rid)) && g.perm.Read ){
1159 /* If from= and to= are present, display all nodes on a path connecting
1160 ** the two */
@@ -1276,16 +1286,28 @@
1276 blob_appendf(&sql,
1277 " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=cid"
1278 " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
1279 tagid
1280 );
 
 
 
 
 
 
 
1281 if( P("mionly")==0 ){
1282 blob_appendf(&sql,
1283 " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=pid"
1284 " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
1285 tagid
1286 );
 
 
 
 
 
1287 }else{
1288 url_add_parameter(&url, "mionly", "1");
1289 }
1290 }else{
1291 url_add_parameter(&url, "t", zTagName);
@@ -1521,18 +1543,19 @@
1521 int nEntry = 0;
1522 char zPrevDate[20];
1523 const char *zCurrentUuid = 0;
1524 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1525 Stmt fchngQuery; /* Query for file changes on check-ins */
 
1526
1527 zPrevDate[0] = 0;
1528 if( g.localOpen ){
1529 int rid = db_lget_int("checkout", 0);
1530 zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1531 }
1532
1533 while( db_step(q)==SQLITE_ROW ){
1534 int rid = db_column_int(q, 0);
1535 const char *zId = db_column_text(q, 1);
1536 const char *zDate = db_column_text(q, 2);
1537 const char *zCom = db_column_text(q, 3);
1538 int nChild = db_column_int(q, 4);
@@ -1611,10 +1634,18 @@
1611 nLine++; /* record another line */
1612 }
1613 db_reset(&fchngQuery);
1614 }
1615 nEntry++; /* record another complete entry */
 
 
 
 
 
 
 
 
1616 }
1617 if( fchngQueryInit ) db_finalize(&fchngQuery);
1618 }
1619
1620 /*
@@ -1752,11 +1783,12 @@
1752 }else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
1753 mode = 4;
1754 }else if( strncmp(g.argv[2],"parents",k)==0 ){
1755 mode = 4;
1756 }else if(!zType && !zLimit){
1757 usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit #? ?-t|--type TYPE? ?-W|--width WIDTH?");
 
1758 }
1759 if( '-' != *g.argv[3] ){
1760 zOrigin = g.argv[3];
1761 }else{
1762 zOrigin = "now";
@@ -1813,11 +1845,13 @@
1813 if( zType && (zType[0]!='a') ){
1814 blob_appendf(&sql, " AND event.type=%Q ", zType);
1815 }
1816 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1817 if( iOffset>0 ){
1818 blob_appendf(&sql, " LIMIT %d OFFSET %d", n>0?n+1:99999, iOffset);
 
 
1819 }
1820 db_prepare(&q, blob_str(&sql));
1821 blob_reset(&sql);
1822 print_timeline(&q, n, width, verboseFlag);
1823 db_finalize(&q);
1824
--- src/timeline.c
+++ src/timeline.c
@@ -111,10 +111,11 @@
111 #define TIMELINE_DISJOINT 0x0010 /* Elements are not contiguous */
112 #define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
113 #define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
114 #define TIMELINE_UCOLOR 0x0080 /* Background color by user */
115 #define TIMELINE_FRENAMES 0x0100 /* Detail only file name changes */
116 #define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
117 #endif
118
119 /*
120 ** Hash a string and use the hash to determine a background color.
121 */
@@ -589,10 +590,11 @@
590 ){
591 if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
592 GraphRow *pRow;
593 int i;
594 char cSep;
595
596 @ <script type="text/JavaScript">
597 @ /* <![CDATA[ */
598 @ var railPitch=%d(pGraph->iRailPitch);
599
600 /* the rowinfo[] array contains all the information needed to generate
@@ -850,11 +852,15 @@
852 @ selRow = null;
853 @ }else{
854 if( fileDiff ){
855 @ location.href="%R/fdiff?v1="+selRow.h+"&v2="+p.h+"&sbs=1";
856 }else{
857 if( db_get_boolean("show-version-diffs", 0)==0 ){
858 @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=0";
859 }else{
860 @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=1";
861 }
862 }
863 @ }
864 @ }
865 @ var lastId = "m"+rowinfo[rowinfo.length-1].id;
866 @ var lastY = 0;
@@ -898,11 +904,10 @@
904 /*
905 ** Return a pointer to a constant string that forms the basis
906 ** for a timeline query for the WWW interface.
907 */
908 const char *timeline_query_for_www(void){
 
909 static const char zBaseSql[] =
910 @ SELECT
911 @ blob.rid AS blobRid,
912 @ uuid AS uuid,
913 @ datetime(event.mtime,'localtime') AS timestamp,
@@ -918,14 +923,11 @@
923 @ brief AS brief,
924 @ event.mtime AS mtime
925 @ FROM event CROSS JOIN blob
926 @ WHERE blob.rid=event.objid
927 ;
928 return zBaseSql;
 
 
 
929 }
930
931 /*
932 ** Generate a submenu element with a single parameter change.
933 */
@@ -1117,10 +1119,13 @@
1119 }
1120 if( P("brbg")!=0 ){
1121 tmFlags |= TIMELINE_BRCOLOR;
1122 url_add_parameter(&url, "brbg", 0);
1123 }
1124 if( P("unhide")!=0 ){
1125 tmFlags |= TIMELINE_UNHIDE;
1126 }
1127 if( P("ubg")!=0 ){
1128 tmFlags |= TIMELINE_UCOLOR;
1129 url_add_parameter(&url, "ubg", 0);
1130 }
1131 if( zUses!=0 ){
@@ -1151,10 +1156,15 @@
1156 blob_append(&sql, "INSERT OR IGNORE INTO timeline ", -1);
1157 blob_append(&sql, timeline_query_for_www(), -1);
1158 if( P("fc")!=0 || P("v")!=0 || P("detail")!=0 ){
1159 tmFlags |= TIMELINE_FCHANGES;
1160 url_add_parameter(&url, "v", 0);
1161 }
1162 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1163 blob_appendf(&sql, " AND NOT EXISTS(SELECT 1 FROM tagxref"
1164 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)",
1165 TAG_HIDDEN);
1166 }
1167 if( !useDividers ) url_add_parameter(&url, "nd", 0);
1168 if( ((from_rid && to_rid) || (me_rid && you_rid)) && g.perm.Read ){
1169 /* If from= and to= are present, display all nodes on a path connecting
1170 ** the two */
@@ -1276,16 +1286,28 @@
1286 blob_appendf(&sql,
1287 " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=cid"
1288 " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
1289 tagid
1290 );
1291 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1292 blob_appendf(&sql,
1293 " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid"
1294 " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)",
1295 TAG_HIDDEN
1296 );
1297 }
1298 if( P("mionly")==0 ){
1299 blob_appendf(&sql,
1300 " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=pid"
1301 " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
1302 tagid
1303 );
1304 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1305 blob_appendf(&sql, " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid"
1306 " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)",
1307 TAG_HIDDEN);
1308 }
1309 }else{
1310 url_add_parameter(&url, "mionly", "1");
1311 }
1312 }else{
1313 url_add_parameter(&url, "t", zTagName);
@@ -1521,18 +1543,19 @@
1543 int nEntry = 0;
1544 char zPrevDate[20];
1545 const char *zCurrentUuid = 0;
1546 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1547 Stmt fchngQuery; /* Query for file changes on check-ins */
1548 int rc;
1549
1550 zPrevDate[0] = 0;
1551 if( g.localOpen ){
1552 int rid = db_lget_int("checkout", 0);
1553 zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1554 }
1555
1556 while( (rc=db_step(q))==SQLITE_ROW ){
1557 int rid = db_column_int(q, 0);
1558 const char *zId = db_column_text(q, 1);
1559 const char *zDate = db_column_text(q, 2);
1560 const char *zCom = db_column_text(q, 3);
1561 int nChild = db_column_int(q, 4);
@@ -1611,10 +1634,18 @@
1634 nLine++; /* record another line */
1635 }
1636 db_reset(&fchngQuery);
1637 }
1638 nEntry++; /* record another complete entry */
1639 }
1640 if( rc==SQLITE_DONE ){
1641 /* Did the underlying query actually have all entries? */
1642 if( nAbsLimit==0 ){
1643 fossil_print("+++ end of timeline (%d) +++\n", nEntry);
1644 }else{
1645 fossil_print("+++ no more data (%d) +++\n", nEntry);
1646 }
1647 }
1648 if( fchngQueryInit ) db_finalize(&fchngQuery);
1649 }
1650
1651 /*
@@ -1752,11 +1783,12 @@
1783 }else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
1784 mode = 4;
1785 }else if( strncmp(g.argv[2],"parents",k)==0 ){
1786 mode = 4;
1787 }else if(!zType && !zLimit){
1788 usage("?WHEN? ?BASELINE|DATETIME? ?-n|--limit #? ?-t|--type TYPE? "
1789 "?-W|--width WIDTH?");
1790 }
1791 if( '-' != *g.argv[3] ){
1792 zOrigin = g.argv[3];
1793 }else{
1794 zOrigin = "now";
@@ -1813,11 +1845,13 @@
1845 if( zType && (zType[0]!='a') ){
1846 blob_appendf(&sql, " AND event.type=%Q ", zType);
1847 }
1848 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1849 if( iOffset>0 ){
1850 /* Don't handle LIMIT here, otherwise print_timeline()
1851 * will not determine the end-marker correctly! */
1852 blob_appendf(&sql, " LIMIT -1 OFFSET %d", iOffset);
1853 }
1854 db_prepare(&q, blob_str(&sql));
1855 blob_reset(&sql);
1856 print_timeline(&q, n, width, verboseFlag);
1857 db_finalize(&q);
1858
+6 -6
--- src/tkt.c
+++ src/tkt.c
@@ -1259,16 +1259,16 @@
12591259
const char *z;
12601260
z = pTicket->aField[i].zName;
12611261
blob_set(&val, pTicket->aField[i].zValue);
12621262
if( z[0]=='+' ){
12631263
fossil_print(" Append to ");
1264
- z++;
1265
- }else{
1266
- fossil_print(" Change ");
1267
- }
1268
- fossil_print("%h: ",z);
1269
- if( blob_size(&val)>50 || contains_newline(&val)) {
1264
+ z++;
1265
+ }else{
1266
+ fossil_print(" Change ");
1267
+ }
1268
+ fossil_print("%h: ",z);
1269
+ if( blob_size(&val)>50 || contains_newline(&val)) {
12701270
fossil_print("\n ",blob_str(&val));
12711271
comment_print(blob_str(&val),4,79);
12721272
}else{
12731273
fossil_print("%s\n",blob_str(&val));
12741274
}
12751275
--- src/tkt.c
+++ src/tkt.c
@@ -1259,16 +1259,16 @@
1259 const char *z;
1260 z = pTicket->aField[i].zName;
1261 blob_set(&val, pTicket->aField[i].zValue);
1262 if( z[0]=='+' ){
1263 fossil_print(" Append to ");
1264 z++;
1265 }else{
1266 fossil_print(" Change ");
1267 }
1268 fossil_print("%h: ",z);
1269 if( blob_size(&val)>50 || contains_newline(&val)) {
1270 fossil_print("\n ",blob_str(&val));
1271 comment_print(blob_str(&val),4,79);
1272 }else{
1273 fossil_print("%s\n",blob_str(&val));
1274 }
1275
--- src/tkt.c
+++ src/tkt.c
@@ -1259,16 +1259,16 @@
1259 const char *z;
1260 z = pTicket->aField[i].zName;
1261 blob_set(&val, pTicket->aField[i].zValue);
1262 if( z[0]=='+' ){
1263 fossil_print(" Append to ");
1264 z++;
1265 }else{
1266 fossil_print(" Change ");
1267 }
1268 fossil_print("%h: ",z);
1269 if( blob_size(&val)>50 || contains_newline(&val)) {
1270 fossil_print("\n ",blob_str(&val));
1271 comment_print(blob_str(&val),4,79);
1272 }else{
1273 fossil_print("%s\n",blob_str(&val));
1274 }
1275
+6 -6
--- src/tkt.c
+++ src/tkt.c
@@ -1259,16 +1259,16 @@
12591259
const char *z;
12601260
z = pTicket->aField[i].zName;
12611261
blob_set(&val, pTicket->aField[i].zValue);
12621262
if( z[0]=='+' ){
12631263
fossil_print(" Append to ");
1264
- z++;
1265
- }else{
1266
- fossil_print(" Change ");
1267
- }
1268
- fossil_print("%h: ",z);
1269
- if( blob_size(&val)>50 || contains_newline(&val)) {
1264
+ z++;
1265
+ }else{
1266
+ fossil_print(" Change ");
1267
+ }
1268
+ fossil_print("%h: ",z);
1269
+ if( blob_size(&val)>50 || contains_newline(&val)) {
12701270
fossil_print("\n ",blob_str(&val));
12711271
comment_print(blob_str(&val),4,79);
12721272
}else{
12731273
fossil_print("%s\n",blob_str(&val));
12741274
}
12751275
--- src/tkt.c
+++ src/tkt.c
@@ -1259,16 +1259,16 @@
1259 const char *z;
1260 z = pTicket->aField[i].zName;
1261 blob_set(&val, pTicket->aField[i].zValue);
1262 if( z[0]=='+' ){
1263 fossil_print(" Append to ");
1264 z++;
1265 }else{
1266 fossil_print(" Change ");
1267 }
1268 fossil_print("%h: ",z);
1269 if( blob_size(&val)>50 || contains_newline(&val)) {
1270 fossil_print("\n ",blob_str(&val));
1271 comment_print(blob_str(&val),4,79);
1272 }else{
1273 fossil_print("%s\n",blob_str(&val));
1274 }
1275
--- src/tkt.c
+++ src/tkt.c
@@ -1259,16 +1259,16 @@
1259 const char *z;
1260 z = pTicket->aField[i].zName;
1261 blob_set(&val, pTicket->aField[i].zValue);
1262 if( z[0]=='+' ){
1263 fossil_print(" Append to ");
1264 z++;
1265 }else{
1266 fossil_print(" Change ");
1267 }
1268 fossil_print("%h: ",z);
1269 if( blob_size(&val)>50 || contains_newline(&val)) {
1270 fossil_print("\n ",blob_str(&val));
1271 comment_print(blob_str(&val),4,79);
1272 }else{
1273 fossil_print("%s\n",blob_str(&val));
1274 }
1275
+7 -8
--- src/url.c
+++ src/url.c
@@ -18,14 +18,19 @@
1818
** This file contains code for parsing URLs that appear on the command-line
1919
*/
2020
#include "config.h"
2121
#include "url.h"
2222
#include <stdio.h>
23
+
2324
#ifdef _WIN32
2425
#include <io.h>
26
+#ifndef isatty
2527
#define isatty(d) _isatty(d)
28
+#endif
29
+#ifndef fileno
2630
#define fileno(s) _fileno(s)
31
+#endif
2732
#endif
2833
2934
#if INTERFACE
3035
/*
3136
** Flags for url_parse()
@@ -289,14 +294,11 @@
289294
**
290295
** ssh://userid@host:port/path?fossil=path/to/fossil.exe
291296
**
292297
*/
293298
void url_parse(const char *zUrl, unsigned int urlFlags){
294
- UrlData urlData;
295
- memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
296
- url_parse_local(zUrl, urlFlags, &urlData);
297
- memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
299
+ url_parse_local(zUrl, urlFlags, GLOBAL_URL());
298300
}
299301
300302
/*
301303
** COMMAND: test-urlparser
302304
**
@@ -520,14 +522,11 @@
520522
/*
521523
** Prompt the user for the password for g.urlUser. Store the result
522524
** in g.urlPasswd.
523525
*/
524526
void url_prompt_for_password(void){
525
- UrlData urlData;
526
- memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
527
- url_prompt_for_password_local(&urlData);
528
- memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
527
+ url_prompt_for_password_local(GLOBAL_URL());
529528
}
530529
531530
/*
532531
** Remember the URL and password if requested.
533532
*/
534533
--- src/url.c
+++ src/url.c
@@ -18,14 +18,19 @@
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
22 #include <stdio.h>
 
23 #ifdef _WIN32
24 #include <io.h>
 
25 #define isatty(d) _isatty(d)
 
 
26 #define fileno(s) _fileno(s)
 
27 #endif
28
29 #if INTERFACE
30 /*
31 ** Flags for url_parse()
@@ -289,14 +294,11 @@
289 **
290 ** ssh://userid@host:port/path?fossil=path/to/fossil.exe
291 **
292 */
293 void url_parse(const char *zUrl, unsigned int urlFlags){
294 UrlData urlData;
295 memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
296 url_parse_local(zUrl, urlFlags, &urlData);
297 memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
298 }
299
300 /*
301 ** COMMAND: test-urlparser
302 **
@@ -520,14 +522,11 @@
520 /*
521 ** Prompt the user for the password for g.urlUser. Store the result
522 ** in g.urlPasswd.
523 */
524 void url_prompt_for_password(void){
525 UrlData urlData;
526 memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
527 url_prompt_for_password_local(&urlData);
528 memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
529 }
530
531 /*
532 ** Remember the URL and password if requested.
533 */
534
--- src/url.c
+++ src/url.c
@@ -18,14 +18,19 @@
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
22 #include <stdio.h>
23
24 #ifdef _WIN32
25 #include <io.h>
26 #ifndef isatty
27 #define isatty(d) _isatty(d)
28 #endif
29 #ifndef fileno
30 #define fileno(s) _fileno(s)
31 #endif
32 #endif
33
34 #if INTERFACE
35 /*
36 ** Flags for url_parse()
@@ -289,14 +294,11 @@
294 **
295 ** ssh://userid@host:port/path?fossil=path/to/fossil.exe
296 **
297 */
298 void url_parse(const char *zUrl, unsigned int urlFlags){
299 url_parse_local(zUrl, urlFlags, GLOBAL_URL());
 
 
 
300 }
301
302 /*
303 ** COMMAND: test-urlparser
304 **
@@ -520,14 +522,11 @@
522 /*
523 ** Prompt the user for the password for g.urlUser. Store the result
524 ** in g.urlPasswd.
525 */
526 void url_prompt_for_password(void){
527 url_prompt_for_password_local(GLOBAL_URL());
 
 
 
528 }
529
530 /*
531 ** Remember the URL and password if requested.
532 */
533
+7 -8
--- src/url.c
+++ src/url.c
@@ -18,14 +18,19 @@
1818
** This file contains code for parsing URLs that appear on the command-line
1919
*/
2020
#include "config.h"
2121
#include "url.h"
2222
#include <stdio.h>
23
+
2324
#ifdef _WIN32
2425
#include <io.h>
26
+#ifndef isatty
2527
#define isatty(d) _isatty(d)
28
+#endif
29
+#ifndef fileno
2630
#define fileno(s) _fileno(s)
31
+#endif
2732
#endif
2833
2934
#if INTERFACE
3035
/*
3136
** Flags for url_parse()
@@ -289,14 +294,11 @@
289294
**
290295
** ssh://userid@host:port/path?fossil=path/to/fossil.exe
291296
**
292297
*/
293298
void url_parse(const char *zUrl, unsigned int urlFlags){
294
- UrlData urlData;
295
- memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
296
- url_parse_local(zUrl, urlFlags, &urlData);
297
- memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
299
+ url_parse_local(zUrl, urlFlags, GLOBAL_URL());
298300
}
299301
300302
/*
301303
** COMMAND: test-urlparser
302304
**
@@ -520,14 +522,11 @@
520522
/*
521523
** Prompt the user for the password for g.urlUser. Store the result
522524
** in g.urlPasswd.
523525
*/
524526
void url_prompt_for_password(void){
525
- UrlData urlData;
526
- memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
527
- url_prompt_for_password_local(&urlData);
528
- memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
527
+ url_prompt_for_password_local(GLOBAL_URL());
529528
}
530529
531530
/*
532531
** Remember the URL and password if requested.
533532
*/
534533
--- src/url.c
+++ src/url.c
@@ -18,14 +18,19 @@
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
22 #include <stdio.h>
 
23 #ifdef _WIN32
24 #include <io.h>
 
25 #define isatty(d) _isatty(d)
 
 
26 #define fileno(s) _fileno(s)
 
27 #endif
28
29 #if INTERFACE
30 /*
31 ** Flags for url_parse()
@@ -289,14 +294,11 @@
289 **
290 ** ssh://userid@host:port/path?fossil=path/to/fossil.exe
291 **
292 */
293 void url_parse(const char *zUrl, unsigned int urlFlags){
294 UrlData urlData;
295 memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
296 url_parse_local(zUrl, urlFlags, &urlData);
297 memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
298 }
299
300 /*
301 ** COMMAND: test-urlparser
302 **
@@ -520,14 +522,11 @@
520 /*
521 ** Prompt the user for the password for g.urlUser. Store the result
522 ** in g.urlPasswd.
523 */
524 void url_prompt_for_password(void){
525 UrlData urlData;
526 memcpy(&urlData, GLOBAL_URL(), sizeof(UrlData));
527 url_prompt_for_password_local(&urlData);
528 memcpy(GLOBAL_URL(), &urlData, sizeof(UrlData));
529 }
530
531 /*
532 ** Remember the URL and password if requested.
533 */
534
--- src/url.c
+++ src/url.c
@@ -18,14 +18,19 @@
18 ** This file contains code for parsing URLs that appear on the command-line
19 */
20 #include "config.h"
21 #include "url.h"
22 #include <stdio.h>
23
24 #ifdef _WIN32
25 #include <io.h>
26 #ifndef isatty
27 #define isatty(d) _isatty(d)
28 #endif
29 #ifndef fileno
30 #define fileno(s) _fileno(s)
31 #endif
32 #endif
33
34 #if INTERFACE
35 /*
36 ** Flags for url_parse()
@@ -289,14 +294,11 @@
294 **
295 ** ssh://userid@host:port/path?fossil=path/to/fossil.exe
296 **
297 */
298 void url_parse(const char *zUrl, unsigned int urlFlags){
299 url_parse_local(zUrl, urlFlags, GLOBAL_URL());
 
 
 
300 }
301
302 /*
303 ** COMMAND: test-urlparser
304 **
@@ -520,14 +522,11 @@
522 /*
523 ** Prompt the user for the password for g.urlUser. Store the result
524 ** in g.urlPasswd.
525 */
526 void url_prompt_for_password(void){
527 url_prompt_for_password_local(GLOBAL_URL());
 
 
 
528 }
529
530 /*
531 ** Remember the URL and password if requested.
532 */
533
+1 -1
--- src/wiki.c
+++ src/wiki.c
@@ -869,11 +869,11 @@
869869
style_header("Wiki Pages Found");
870870
@ <ul>
871871
db_prepare(&q,
872872
"SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'"
873873
" ORDER BY lower(tagname) /*sort*/" ,
874
- zTitle);
874
+ zTitle);
875875
while( db_step(&q)==SQLITE_ROW ){
876876
const char *zName = db_column_text(&q, 0);
877877
@ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
878878
}
879879
db_finalize(&q);
880880
--- src/wiki.c
+++ src/wiki.c
@@ -869,11 +869,11 @@
869 style_header("Wiki Pages Found");
870 @ <ul>
871 db_prepare(&q,
872 "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'"
873 " ORDER BY lower(tagname) /*sort*/" ,
874 zTitle);
875 while( db_step(&q)==SQLITE_ROW ){
876 const char *zName = db_column_text(&q, 0);
877 @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
878 }
879 db_finalize(&q);
880
--- src/wiki.c
+++ src/wiki.c
@@ -869,11 +869,11 @@
869 style_header("Wiki Pages Found");
870 @ <ul>
871 db_prepare(&q,
872 "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'"
873 " ORDER BY lower(tagname) /*sort*/" ,
874 zTitle);
875 while( db_step(&q)==SQLITE_ROW ){
876 const char *zName = db_column_text(&q, 0);
877 @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
878 }
879 db_finalize(&q);
880
+1 -1
--- src/wiki.c
+++ src/wiki.c
@@ -869,11 +869,11 @@
869869
style_header("Wiki Pages Found");
870870
@ <ul>
871871
db_prepare(&q,
872872
"SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'"
873873
" ORDER BY lower(tagname) /*sort*/" ,
874
- zTitle);
874
+ zTitle);
875875
while( db_step(&q)==SQLITE_ROW ){
876876
const char *zName = db_column_text(&q, 0);
877877
@ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
878878
}
879879
db_finalize(&q);
880880
--- src/wiki.c
+++ src/wiki.c
@@ -869,11 +869,11 @@
869 style_header("Wiki Pages Found");
870 @ <ul>
871 db_prepare(&q,
872 "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'"
873 " ORDER BY lower(tagname) /*sort*/" ,
874 zTitle);
875 while( db_step(&q)==SQLITE_ROW ){
876 const char *zName = db_column_text(&q, 0);
877 @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
878 }
879 db_finalize(&q);
880
--- src/wiki.c
+++ src/wiki.c
@@ -869,11 +869,11 @@
869 style_header("Wiki Pages Found");
870 @ <ul>
871 db_prepare(&q,
872 "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'"
873 " ORDER BY lower(tagname) /*sort*/" ,
874 zTitle);
875 while( db_step(&q)==SQLITE_ROW ){
876 const char *zName = db_column_text(&q, 0);
877 @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
878 }
879 db_finalize(&q);
880
+1
--- src/xfer.c
+++ src/xfer.c
@@ -1312,10 +1312,11 @@
13121312
zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
13131313
@ # timestamp %s(zNow)
13141314
free(zNow);
13151315
13161316
db_end_transaction(0);
1317
+ configure_rebuild();
13171318
}
13181319
13191320
/*
13201321
** COMMAND: test-xfer
13211322
**
13221323
--- src/xfer.c
+++ src/xfer.c
@@ -1312,10 +1312,11 @@
1312 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
1313 @ # timestamp %s(zNow)
1314 free(zNow);
1315
1316 db_end_transaction(0);
 
1317 }
1318
1319 /*
1320 ** COMMAND: test-xfer
1321 **
1322
--- src/xfer.c
+++ src/xfer.c
@@ -1312,10 +1312,11 @@
1312 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
1313 @ # timestamp %s(zNow)
1314 free(zNow);
1315
1316 db_end_transaction(0);
1317 configure_rebuild();
1318 }
1319
1320 /*
1321 ** COMMAND: test-xfer
1322 **
1323
+1
--- src/xfer.c
+++ src/xfer.c
@@ -1312,10 +1312,11 @@
13121312
zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
13131313
@ # timestamp %s(zNow)
13141314
free(zNow);
13151315
13161316
db_end_transaction(0);
1317
+ configure_rebuild();
13171318
}
13181319
13191320
/*
13201321
** COMMAND: test-xfer
13211322
**
13221323
--- src/xfer.c
+++ src/xfer.c
@@ -1312,10 +1312,11 @@
1312 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
1313 @ # timestamp %s(zNow)
1314 free(zNow);
1315
1316 db_end_transaction(0);
 
1317 }
1318
1319 /*
1320 ** COMMAND: test-xfer
1321 **
1322
--- src/xfer.c
+++ src/xfer.c
@@ -1312,10 +1312,11 @@
1312 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
1313 @ # timestamp %s(zNow)
1314 free(zNow);
1315
1316 db_end_transaction(0);
1317 configure_rebuild();
1318 }
1319
1320 /*
1321 ** COMMAND: test-xfer
1322 **
1323
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,17 +83,17 @@
8383
8484
# define the sqlite files, which need special flags on compile
8585
SQLITESRC=sqlite3.c
8686
ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
8787
SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88
-SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
88
+SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0
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 -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
94
+SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -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
@@ -83,17 +83,17 @@
83
84 # define the sqlite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
89
90 # define the sqlite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1
95
96 # define the th scripting files, which need special flags on compile
97 THSRC=th.c th_lang.c
98 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
99 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
100
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,17 +83,17 @@
83
84 # define the sqlite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0
89
90 # define the sqlite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -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
@@ -24,11 +24,13 @@
2424
CFLAGS = -o
2525
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
2626
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2727
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
2828
29
-SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
29
+SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0
30
+
31
+SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3032
3133
SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
3234
3335
OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
3436
@@ -66,14 +68,14 @@
6668
6769
version$E: $B\src\mkversion.c
6870
$(BCC) -o$@ $**
6971
7072
$(OBJDIR)\shell$O : $(SRCDIR)\shell.c
71
- $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
73
+ $(TCC) -o$@ -c $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) $**
7274
7375
$(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
74
- $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
76
+ $(TCC) -o$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
7577
7678
$(OBJDIR)\th$O : $(SRCDIR)\th.c
7779
$(TCC) -o$@ -c $**
7880
7981
$(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
8082
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,13 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
 
 
30
31 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
32
33 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
34
@@ -66,14 +68,14 @@
66
67 version$E: $B\src\mkversion.c
68 $(BCC) -o$@ $**
69
70 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
71 $(TCC) -o$@ -c -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen $(SQLITE_OPTIONS) $**
72
73 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
74 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
75
76 $(OBJDIR)\th$O : $(SRCDIR)\th.c
77 $(TCC) -o$@ -c $**
78
79 $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
80
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,13 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -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 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)\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
@@ -66,14 +68,14 @@
68
69 version$E: $B\src\mkversion.c
70 $(BCC) -o$@ $**
71
72 $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
73 $(TCC) -o$@ -c $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) $**
74
75 $(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
76 $(TCC) -o$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
77
78 $(OBJDIR)\th$O : $(SRCDIR)\th.c
79 $(TCC) -o$@ -c $**
80
81 $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
82
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -618,13 +618,15 @@
618618
619619
$(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
620620
ifdef USE_WINDOWS
621621
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
622622
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
623
+ $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
623624
else
624625
$(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
625626
$(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
627
+ $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
626628
endif
627629
$(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
628630
629631
install: $(OBJDIR) $(APPNAME)
630632
ifdef USE_WINDOWS
@@ -1683,21 +1685,38 @@
16831685
16841686
$(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
16851687
$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
16861688
16871689
$(OBJDIR)/zip.h: $(OBJDIR)/headers
1690
+
1691
+SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1692
+ -DSQLITE_THREADSAFE=0 \
1693
+ -DSQLITE_DEFAULT_FILE_FORMAT=4 \
1694
+ -DSQLITE_OMIT_DEPRECATED \
1695
+ -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
1696
+ -Dlocaltime=fossil_localtime \
1697
+ -DSQLITE_ENABLE_LOCKING_STYLE=0 \
1698
+ -D_HAVE_SQLITE_CONFIG_H \
1699
+ -DSQLITE_USE_MALLOC_H \
1700
+ -DSQLITE_USE_MSIZE
1701
+
1702
+SHELL_OPTIONS = -Dmain=sqlite3_shell \
1703
+ -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1704
+ -Dsqlite3_strglob=strglob \
1705
+ -Dgetenv=fossil_getenv \
1706
+ -Dfopen=fossil_fopen
16881707
16891708
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690
- $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1709
+ $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
16911710
16921711
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693
- $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1712
+ $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
16941713
16951714
$(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
16961715
16971716
$(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698
- $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1717
+ $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
16991718
17001719
$(OBJDIR)/th.o: $(SRCDIR)/th.c
17011720
$(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
17021721
17031722
$(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
17041723
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -618,13 +618,15 @@
618
619 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
620 ifdef USE_WINDOWS
621 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
622 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
 
623 else
624 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
625 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
 
626 endif
627 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
628
629 install: $(OBJDIR) $(APPNAME)
630 ifdef USE_WINDOWS
@@ -1683,21 +1685,38 @@
1683
1684 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1685 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1686
1687 $(OBJDIR)/zip.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1688
1689 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1691
1692 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1694
1695 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1696
1697 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698 $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1699
1700 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1701 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1702
1703 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1704
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -618,13 +618,15 @@
618
619 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
620 ifdef USE_WINDOWS
621 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
622 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
623 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
624 else
625 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
626 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
627 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
628 endif
629 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
630
631 install: $(OBJDIR) $(APPNAME)
632 ifdef USE_WINDOWS
@@ -1683,21 +1685,38 @@
1685
1686 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1687 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1688
1689 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1690
1691 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1692 -DSQLITE_THREADSAFE=0 \
1693 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
1694 -DSQLITE_OMIT_DEPRECATED \
1695 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
1696 -Dlocaltime=fossil_localtime \
1697 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
1698 -D_HAVE_SQLITE_CONFIG_H \
1699 -DSQLITE_USE_MALLOC_H \
1700 -DSQLITE_USE_MSIZE
1701
1702 SHELL_OPTIONS = -Dmain=sqlite3_shell \
1703 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1704 -Dsqlite3_strglob=strglob \
1705 -Dgetenv=fossil_getenv \
1706 -Dfopen=fossil_fopen
1707
1708 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1709 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1710
1711 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1712 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1713
1714 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1715
1716 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1717 $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1718
1719 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1720 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1721
1722 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1723
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -618,13 +618,15 @@
618618
619619
$(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
620620
ifdef USE_WINDOWS
621621
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
622622
$(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
623
+ $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
623624
else
624625
$(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
625626
$(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
627
+ $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
626628
endif
627629
$(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
628630
629631
install: $(OBJDIR) $(APPNAME)
630632
ifdef USE_WINDOWS
@@ -1683,21 +1685,38 @@
16831685
16841686
$(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
16851687
$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
16861688
16871689
$(OBJDIR)/zip.h: $(OBJDIR)/headers
1690
+
1691
+SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1692
+ -DSQLITE_THREADSAFE=0 \
1693
+ -DSQLITE_DEFAULT_FILE_FORMAT=4 \
1694
+ -DSQLITE_OMIT_DEPRECATED \
1695
+ -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
1696
+ -Dlocaltime=fossil_localtime \
1697
+ -DSQLITE_ENABLE_LOCKING_STYLE=0 \
1698
+ -D_HAVE_SQLITE_CONFIG_H \
1699
+ -DSQLITE_USE_MALLOC_H \
1700
+ -DSQLITE_USE_MSIZE
1701
+
1702
+SHELL_OPTIONS = -Dmain=sqlite3_shell \
1703
+ -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1704
+ -Dsqlite3_strglob=strglob \
1705
+ -Dgetenv=fossil_getenv \
1706
+ -Dfopen=fossil_fopen
16881707
16891708
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690
- $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1709
+ $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
16911710
16921711
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693
- $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1712
+ $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
16941713
16951714
$(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
16961715
16971716
$(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698
- $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1717
+ $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
16991718
17001719
$(OBJDIR)/th.o: $(SRCDIR)/th.c
17011720
$(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
17021721
17031722
$(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
17041723
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -618,13 +618,15 @@
618
619 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
620 ifdef USE_WINDOWS
621 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
622 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
 
623 else
624 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
625 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
 
626 endif
627 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
628
629 install: $(OBJDIR) $(APPNAME)
630 ifdef USE_WINDOWS
@@ -1683,21 +1685,38 @@
1683
1684 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1685 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1686
1687 $(OBJDIR)/zip.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1688
1689 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1691
1692 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1694
1695 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1696
1697 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1698 $(XTCC) -Dmain=sqlite3_shell -Dsqlite3_strglob=strglob -Dgetenv=fossil_getenv -Dfopen=fossil_fopen -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1699
1700 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1701 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1702
1703 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1704
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -618,13 +618,15 @@
618
619 $(OBJDIR)/fossil.o: $(SRCDIR)/../win/fossil.rc $(OBJDIR)/VERSION.h
620 ifdef USE_WINDOWS
621 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.rc) $(subst /,\,$(OBJDIR))
622 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.ico) $(subst /,\,$(OBJDIR))
623 $(CP) $(subst /,\,$(SRCDIR)\..\win\fossil.exe.manifest) $(subst /,\,$(OBJDIR))
624 else
625 $(CP) $(SRCDIR)/../win/fossil.rc $(OBJDIR)
626 $(CP) $(SRCDIR)/../win/fossil.ico $(OBJDIR)
627 $(CP) $(SRCDIR)/../win/fossil.exe.manifest $(OBJDIR)
628 endif
629 $(RCC) $(OBJDIR)/fossil.rc -o $(OBJDIR)/fossil.o
630
631 install: $(OBJDIR) $(APPNAME)
632 ifdef USE_WINDOWS
@@ -1683,21 +1685,38 @@
1685
1686 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1687 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1688
1689 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1690
1691 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1692 -DSQLITE_THREADSAFE=0 \
1693 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
1694 -DSQLITE_OMIT_DEPRECATED \
1695 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
1696 -Dlocaltime=fossil_localtime \
1697 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
1698 -D_HAVE_SQLITE_CONFIG_H \
1699 -DSQLITE_USE_MALLOC_H \
1700 -DSQLITE_USE_MSIZE
1701
1702 SHELL_OPTIONS = -Dmain=sqlite3_shell \
1703 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1704 -Dsqlite3_strglob=strglob \
1705 -Dgetenv=fossil_getenv \
1706 -Dfopen=fossil_fopen
1707
1708 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1709 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1710
1711 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1712 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1713
1714 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1715
1716 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1717 $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1718
1719 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1720 $(XTCC) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
1721
1722 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
1723
+11 -6
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -67,14 +67,20 @@
6767
!endif
6868
6969
SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
7070
/DSQLITE_THREADSAFE=0 \
7171
/DSQLITE_DEFAULT_FILE_FORMAT=4 \
72
- /DSQLITE_ENABLE_STAT3 \
72
+ /DSQLITE_OMIT_DEPRECATED \
73
+ /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
7374
/Dlocaltime=fossil_localtime \
74
- /DSQLITE_ENABLE_LOCKING_STYLE=0 \
75
- /DSQLITE_WIN32_NO_ANSI
75
+ /DSQLITE_ENABLE_LOCKING_STYLE=0
76
+
77
+SHELL_OPTIONS = /Dmain=sqlite3_shell \
78
+ /DSQLITE_OMIT_LOAD_EXTENSION=1 \
79
+ /Dsqlite3_strglob=strglob \
80
+ /Dgetenv=fossil_getenv \
81
+ /Dfopen=fossil_fopen
7682
7783
SRC = add_.c \
7884
allrepo_.c \
7985
attach_.c \
8086
bag_.c \
@@ -440,14 +446,14 @@
440446
441447
mkversion$E: $B\src\mkversion.c
442448
$(BCC) $**
443449
444450
$(OX)\shell$O : $(SRCDIR)\shell.c
445
- $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
451
+ $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
446452
447453
$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
448
- $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
454
+ $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
449455
450456
$(OX)\th$O : $(SRCDIR)\th.c
451457
$(TCC) /Fo$@ -c $**
452458
453459
$(OX)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -465,11 +471,10 @@
465471
-del $(OX)\*.obj
466472
-del *.obj
467473
-del *_.c
468474
-del *.h
469475
-del *.map
470
- -del *.manifest
471476
-del headers
472477
-del linkopts
473478
-del *.res
474479
475480
realclean: clean
476481
477482
ADDED win/fossil.exe.manifest
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -67,14 +67,20 @@
67 !endif
68
69 SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
70 /DSQLITE_THREADSAFE=0 \
71 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
72 /DSQLITE_ENABLE_STAT3 \
 
73 /Dlocaltime=fossil_localtime \
74 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
75 /DSQLITE_WIN32_NO_ANSI
 
 
 
 
 
76
77 SRC = add_.c \
78 allrepo_.c \
79 attach_.c \
80 bag_.c \
@@ -440,14 +446,14 @@
440
441 mkversion$E: $B\src\mkversion.c
442 $(BCC) $**
443
444 $(OX)\shell$O : $(SRCDIR)\shell.c
445 $(TCC) /Fo$@ /Dmain=sqlite3_shell /Dsqlite3_strglob=strglob /Dgetenv=fossil_getenv /Dfopen=fossil_fopen $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
446
447 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
448 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
449
450 $(OX)\th$O : $(SRCDIR)\th.c
451 $(TCC) /Fo$@ -c $**
452
453 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -465,11 +471,10 @@
465 -del $(OX)\*.obj
466 -del *.obj
467 -del *_.c
468 -del *.h
469 -del *.map
470 -del *.manifest
471 -del headers
472 -del linkopts
473 -del *.res
474
475 realclean: clean
476
477 DDED win/fossil.exe.manifest
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -67,14 +67,20 @@
67 !endif
68
69 SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
70 /DSQLITE_THREADSAFE=0 \
71 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
72 /DSQLITE_OMIT_DEPRECATED \
73 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
74 /Dlocaltime=fossil_localtime \
75 /DSQLITE_ENABLE_LOCKING_STYLE=0
76
77 SHELL_OPTIONS = /Dmain=sqlite3_shell \
78 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
79 /Dsqlite3_strglob=strglob \
80 /Dgetenv=fossil_getenv \
81 /Dfopen=fossil_fopen
82
83 SRC = add_.c \
84 allrepo_.c \
85 attach_.c \
86 bag_.c \
@@ -440,14 +446,14 @@
446
447 mkversion$E: $B\src\mkversion.c
448 $(BCC) $**
449
450 $(OX)\shell$O : $(SRCDIR)\shell.c
451 $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
452
453 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
454 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $**
455
456 $(OX)\th$O : $(SRCDIR)\th.c
457 $(TCC) /Fo$@ -c $**
458
459 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
@@ -465,11 +471,10 @@
471 -del $(OX)\*.obj
472 -del *.obj
473 -del *_.c
474 -del *.h
475 -del *.map
 
476 -del headers
477 -del linkopts
478 -del *.res
479
480 realclean: clean
481
482 DDED win/fossil.exe.manifest
--- a/win/fossil.exe.manifest
+++ b/win/fossil.exe.manifest
@@ -0,0 +1,38 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
3
+ xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
4
+ <assemblyIdentity version="1.0.0X860" processorArchitecture="*" name="fossil"
5
+ type="win32" />
6
+ <description>
7
+ Simple, high-reliability, distributed software configuration management system.
8
+ </description>
9
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
10
+ <security>
11
+ <requestedPrivileges>
12
+ <requestedExecutionLevel level="asInvoker" uiAccess="false" />
13
+ </requestedPrivileges>
14
+ </security>
15
+ </trustInfo>
16
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
17
+ <appli8.1 -->
18
+ <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
19
+ <!-- Windows 8 -->
20
+ <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
21
+ <!-- Windows 7 -->
22
+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
23
+ <!-- Windows Vista -->
24
+ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
25
+ </application>
26
+ </compatibility>
27
+ <asmv3:application>
28
+ <asmv3:windowsSettings
29
+ xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
30
+ <dpiAware>true</dpiAware>
31
+ </asmv3:windowsSettings>
32
+ </asmv3:application>
33
+ <dependency>
34
+ <dependentAssembly>
35
+ <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls"
36
+ version="6.0.0X86"
37
+ *"
38
+ publicKeyToken="6595b64144ccf1df" language="*" />
--- a/win/fossil.exe.manifest
+++ b/win/fossil.exe.manifest
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/win/fossil.exe.manifest
+++ b/win/fossil.exe.manifest
@@ -0,0 +1,38 @@
1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
3 xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
4 <assemblyIdentity version="1.0.0X860" processorArchitecture="*" name="fossil"
5 type="win32" />
6 <description>
7 Simple, high-reliability, distributed software configuration management system.
8 </description>
9 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
10 <security>
11 <requestedPrivileges>
12 <requestedExecutionLevel level="asInvoker" uiAccess="false" />
13 </requestedPrivileges>
14 </security>
15 </trustInfo>
16 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
17 <appli8.1 -->
18 <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
19 <!-- Windows 8 -->
20 <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
21 <!-- Windows 7 -->
22 <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
23 <!-- Windows Vista -->
24 <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
25 </application>
26 </compatibility>
27 <asmv3:application>
28 <asmv3:windowsSettings
29 xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
30 <dpiAware>true</dpiAware>
31 </asmv3:windowsSettings>
32 </asmv3:application>
33 <dependency>
34 <dependentAssembly>
35 <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls"
36 version="6.0.0X86"
37 *"
38 publicKeyToken="6595b64144ccf1df" language="*" />
--- win/fossil.rc
+++ win/fossil.rc
@@ -130,5 +130,19 @@
130130
BLOCK "VarFileInfo"
131131
BEGIN
132132
VALUE "Translation", 0x409, 0x4b0
133133
END
134134
END
135
+
136
+/*
137
+ * This embedded manifest is needed for Windows 8.1.
138
+ */
139
+
140
+#ifndef RT_MANIFEST
141
+#define RT_MANIFEST 24
142
+#endif
143
+
144
+#ifndef CREATEPROCESS_MANIFEST_RESOURCE_ID
145
+#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
146
+#endif
147
+
148
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "fossil.exe.manifest"
135149
--- win/fossil.rc
+++ win/fossil.rc
@@ -130,5 +130,19 @@
130 BLOCK "VarFileInfo"
131 BEGIN
132 VALUE "Translation", 0x409, 0x4b0
133 END
134 END
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
--- win/fossil.rc
+++ win/fossil.rc
@@ -130,5 +130,19 @@
130 BLOCK "VarFileInfo"
131 BEGIN
132 VALUE "Translation", 0x409, 0x4b0
133 END
134 END
135
136 /*
137 * This embedded manifest is needed for Windows 8.1.
138 */
139
140 #ifndef RT_MANIFEST
141 #define RT_MANIFEST 24
142 #endif
143
144 #ifndef CREATEPROCESS_MANIFEST_RESOURCE_ID
145 #define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
146 #endif
147
148 CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "fossil.exe.manifest"
149
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -116,6 +116,12 @@
116116
than what you actually did.
117117
118118
<blockquote>
119119
<i>Mike Meyer on the Fossil mailing list, 2011-10-04</i>
120120
</blockquote>
121
+
122
+<li>github is such a pale shadow of what fossil does.
123
+
124
+<blockquote>
125
+<i>dkf on the Tcl chatroom, 2013-12-06</i>
126
+</blockquote>
121127
</ol>
122128
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -116,6 +116,12 @@
116 than what you actually did.
117
118 <blockquote>
119 <i>Mike Meyer on the Fossil mailing list, 2011-10-04</i>
120 </blockquote>
 
 
 
 
 
 
121 </ol>
122
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -116,6 +116,12 @@
116 than what you actually did.
117
118 <blockquote>
119 <i>Mike Meyer on the Fossil mailing list, 2011-10-04</i>
120 </blockquote>
121
122 <li>github is such a pale shadow of what fossil does.
123
124 <blockquote>
125 <i>dkf on the Tcl chatroom, 2013-12-06</i>
126 </blockquote>
127 </ol>
128

Keyboard Shortcuts

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