Fossil SCM

merge trunk

jan.nijtmans 2015-05-07 19:28 sync-forkwarn merge
Commit c1416fd1339ffcc3a6304ffbfd77210e3131e275
D .fossil-settings/keep-glob
-4
--- a/.fossil-settings/keep-glob
+++ b/.fossil-settings/keep-glob
@@ -1,4 +0,0 @@
1
-compat/openssl*
2
-compat/tcl*
3
-ts
4
-aut
--- a/.fossil-settings/keep-glob
+++ b/.fossil-settings/keep-glob
@@ -1,4 +0,0 @@
1 compat/openssl*
2 compat/tcl*
3 ts
4 aut
--- a/.fossil-settings/keep-glob
+++ b/.fossil-settings/keep-glob
@@ -1,4 +0,0 @@
 
 
 
 
+2 -2
--- auto.def
+++ auto.def
@@ -51,12 +51,12 @@
5151
# if sqlite3_strglob() can be found as well. If we can find open() but
5252
# not strglob(), then the system SQLite is too old to link against
5353
# fossil.
5454
#
5555
if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
56
- if {![cc-check-function-in-lib sqlite3_strglob sqlite3 $extralibs]} {
57
- user-error "system sqlite3 too old (require >= 3.7.17)"
56
+ if {![cc-check-function-in-lib sqlite3_malloc64 sqlite3 $extralibs]} {
57
+ user-error "system sqlite3 too old (require >= 3.8.7)"
5858
}
5959
6060
# Success. Update symbols and return.
6161
#
6262
define USE_SYSTEM_SQLITE 1
6363
--- auto.def
+++ auto.def
@@ -51,12 +51,12 @@
51 # if sqlite3_strglob() can be found as well. If we can find open() but
52 # not strglob(), then the system SQLite is too old to link against
53 # fossil.
54 #
55 if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
56 if {![cc-check-function-in-lib sqlite3_strglob sqlite3 $extralibs]} {
57 user-error "system sqlite3 too old (require >= 3.7.17)"
58 }
59
60 # Success. Update symbols and return.
61 #
62 define USE_SYSTEM_SQLITE 1
63
--- auto.def
+++ auto.def
@@ -51,12 +51,12 @@
51 # if sqlite3_strglob() can be found as well. If we can find open() but
52 # not strglob(), then the system SQLite is too old to link against
53 # fossil.
54 #
55 if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
56 if {![cc-check-function-in-lib sqlite3_malloc64 sqlite3 $extralibs]} {
57 user-error "system sqlite3 too old (require >= 3.8.7)"
58 }
59
60 # Success. Update symbols and return.
61 #
62 define USE_SYSTEM_SQLITE 1
63
--- skins/eagle/header.txt
+++ skins/eagle/header.txt
@@ -123,10 +123,11 @@
123123
menulink /ticket Tickets
124124
}
125125
if {[anoncap j]} {
126126
menulink /wiki Wiki
127127
}
128
+menulink /sitemap More...
128129
if {[hascap s]} {
129130
menulink /setup Admin
130131
} elseif {[hascap a]} {
131132
menulink /setup_ulist Users
132133
}
133134
--- skins/eagle/header.txt
+++ skins/eagle/header.txt
@@ -123,10 +123,11 @@
123 menulink /ticket Tickets
124 }
125 if {[anoncap j]} {
126 menulink /wiki Wiki
127 }
 
128 if {[hascap s]} {
129 menulink /setup Admin
130 } elseif {[hascap a]} {
131 menulink /setup_ulist Users
132 }
133
--- skins/eagle/header.txt
+++ skins/eagle/header.txt
@@ -123,10 +123,11 @@
123 menulink /ticket Tickets
124 }
125 if {[anoncap j]} {
126 menulink /wiki Wiki
127 }
128 menulink /sitemap More...
129 if {[hascap s]} {
130 menulink /setup Admin
131 } elseif {[hascap a]} {
132 menulink /setup_ulist Users
133 }
134
+21 -21
--- src/checkin.c
+++ src/checkin.c
@@ -44,15 +44,15 @@
4444
Blob where;
4545
const char *zName;
4646
int i;
4747
4848
blob_zero(&where);
49
- for(i=2; i<g.argc; i++) {
49
+ for(i=2; i<g.argc; i++){
5050
Blob fname;
5151
file_tree_name(g.argv[i], &fname, 1);
5252
zName = blob_str(&fname);
53
- if( fossil_strcmp(zName, ".")==0 ) {
53
+ if( fossil_strcmp(zName, ".")==0 ){
5454
blob_reset(&where);
5555
break;
5656
}
5757
blob_append_sql(&where,
5858
" %s (pathname=%Q %s) "
@@ -290,11 +290,11 @@
290290
blob_zero(&where);
291291
for(i=2; i<g.argc; i++){
292292
Blob fname;
293293
file_tree_name(g.argv[i], &fname, 1);
294294
zName = blob_str(&fname);
295
- if( fossil_strcmp(zName, ".")==0 ) {
295
+ if( fossil_strcmp(zName, ".")==0 ){
296296
blob_reset(&where);
297297
break;
298298
}
299299
blob_append_sql(&where,
300300
" %s (pathname=%Q %s) "
@@ -403,11 +403,11 @@
403403
blob_zero(&where);
404404
for(i=2; i<g.argc; i++){
405405
Blob fname;
406406
file_tree_name(g.argv[i], &fname, 1);
407407
zName = blob_str(&fname);
408
- if( fossil_strcmp(zName, ".")==0 ) {
408
+ if( fossil_strcmp(zName, ".")==0 ){
409409
blob_reset(&where);
410410
break;
411411
}
412412
blob_append_sql(&where,
413413
" %s (pathname=%Q %s) "
@@ -595,11 +595,11 @@
595595
db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
596596
blob_zero(&rewrittenPathname);
597597
g.allowSymlinks = 1; /* Report on symbolic links */
598598
while( db_step(&q)==SQLITE_ROW ){
599599
zDisplayName = zPathname = db_column_text(&q, 0);
600
- if( cwdRelative ) {
600
+ if( cwdRelative ){
601601
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
602602
file_relative_name(zFullName, &rewrittenPathname, 0);
603603
free(zFullName);
604604
zDisplayName = blob_str(&rewrittenPathname);
605605
if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
@@ -626,20 +626,21 @@
626626
** cannot be undone. If one or more PATH arguments appear, then only
627627
** the files named, or files contained with directories named, will be
628628
** removed.
629629
**
630630
** Prompted are issued to confirm the removal of each file, unless
631
-** the --force or --verily flag is used or unless the file matches
632
-** glob pattern specified by the --clean option. No file that matches
633
-** glob patterns specified by --ignore or --keep will ever be deleted.
634
-** The default values for --clean, --ignore, and --keep are determined
635
-** by the (versionable) clean-glob, ignore-glob, and keep-glob settings.
631
+** the --force flag is used or unless the file matches glob pattern
632
+** specified by the --clean option. No file that matches glob patterns
633
+** specified by --ignore or --keep will ever be deleted. The default
634
+** values for --clean, --ignore, and --keep are determined by the
635
+** (versionable) clean-glob, ignore-glob, and keep-glob settings.
636636
** Files and subdirectories whose names begin with "." are automatically
637637
** ignored unless the --dotfiles option is used.
638638
**
639
-** The --verily option overrides all other options and settings and
640
-** deletes all unmanaged files and empty directories without prompting.
639
+** The --verily option ignores the keep-glob and ignore-glob settings
640
+** and turns on --force, --dotfiles, and --emptydirs. Use the --verily
641
+** option when you really want to clean up everything.
641642
**
642643
** Options:
643644
** --allckouts Check for empty directories within any checkouts
644645
** that may be nested within the current one. This
645646
** option should be used with great care because the
@@ -659,18 +660,19 @@
659660
** therefore, directories that contain only files
660661
** that were removed will be removed as well.
661662
** -f|--force Remove files without prompting.
662663
** -x|--verily Remove everything that is not a managed file or
663664
** the repository itself. Implies -f --emptydirs
664
-** --dotfiles --ignore '' --keep ''.
665
+** --dotfiles. Disregard keep-glob and ignore-glob.
665666
** --clean <CSG> Never prompt for files matching this
666667
** comma separated list of glob patterns.
667668
** --ignore <CSG> Ignore files matching patterns from the
668669
** comma separated list of glob patterns.
669670
** --keep <CSG> Keep files matching this comma separated
670671
** list of glob patterns.
671
-** -n|--dry-run If given, display instead of run actions.
672
+** -n|--dry-run Delete nothing, but display what would have been
673
+** deleted.
672674
** --temp Remove only Fossil-generated temporary files.
673675
** -v|--verbose Show all files as they are removed.
674676
**
675677
** See also: addremove, extras, status
676678
*/
@@ -703,12 +705,10 @@
703705
db_must_be_within_tree();
704706
if( find_option("verily","x",0)!=0 ){
705707
verilyFlag = allFileFlag = allDirFlag = 1;
706708
emptyDirsFlag = 1;
707709
scanFlags |= SCAN_ALL;
708
- zKeepFlag = 0;
709
- zIgnoreFlag = 0;
710710
zCleanFlag = 0;
711711
}
712712
if( zIgnoreFlag==0 && !verilyFlag ){
713713
zIgnoreFlag = db_get("ignore-glob", 0);
714714
}
@@ -761,11 +761,11 @@
761761
blob_reset(&ans);
762762
continue;
763763
}
764764
blob_reset(&ans);
765765
}
766
- if ( dryRunFlag || file_delete(zName)==0 ){
766
+ if( dryRunFlag || file_delete(zName)==0 ){
767767
if( verboseFlag || dryRunFlag ){
768768
fossil_print("Removed unmanaged file: %s\n", zName+nRoot);
769769
}
770770
}else if( verboseFlag ){
771771
fossil_print("Could not remove file: %s\n", zName+nRoot);
@@ -777,11 +777,11 @@
777777
Glob *pEmptyDirs = glob_create(db_get("empty-dirs", 0));
778778
Stmt q;
779779
Blob root;
780780
blob_init(&root, g.zLocalRoot, nRoot - 1);
781781
vfile_dir_scan(&root, blob_size(&root), scanFlags, pIgnore,
782
- pEmptyDirs, 0);
782
+ pEmptyDirs);
783783
blob_reset(&root);
784784
db_prepare(&q,
785785
"SELECT %Q || x FROM dscan_temp"
786786
" WHERE x NOT IN (%s) AND y = 0"
787787
" ORDER BY 1 DESC",
@@ -809,11 +809,11 @@
809809
blob_reset(&ans);
810810
continue;
811811
}
812812
blob_reset(&ans);
813813
}
814
- if ( dryRunFlag || file_rmdir(zName)==0 ){
814
+ if( dryRunFlag || file_rmdir(zName)==0 ){
815815
if( verboseFlag || dryRunFlag ){
816816
fossil_print("Removed unmanaged directory: %s\n", zName+nRoot);
817817
}
818818
}else if( verboseFlag ){
819819
fossil_print("Could not remove directory: %s\n", zName+nRoot);
@@ -948,11 +948,11 @@
948948
Blob prompt;
949949
#if defined(_WIN32) || defined(__CYGWIN__)
950950
int bomSize;
951951
const unsigned char *bom = get_utf8_bom(&bomSize);
952952
blob_init(&prompt, (const char *) bom, bomSize);
953
- if( zInit && zInit[0]) {
953
+ if( zInit && zInit[0]){
954954
blob_append(&prompt, zInit, -1);
955955
}
956956
#else
957957
blob_init(&prompt, zInit, -1);
958958
#endif
@@ -1489,11 +1489,11 @@
14891489
fossil_free(zOrig);
14901490
f = fossil_fopen(zFilename, "wb");
14911491
if( f==0 ){
14921492
fossil_warning("cannot open %s for writing", zFilename);
14931493
}else{
1494
- if( fUnicode ) {
1494
+ if( fUnicode ){
14951495
int bomSize;
14961496
const unsigned char *bom = get_utf8_bom(&bomSize);
14971497
fwrite(bom, 1, bomSize, f);
14981498
blob_to_utf8_no_bom(p, 0);
14991499
}else if( fHasInvalidUtf8 ){
15001500
--- src/checkin.c
+++ src/checkin.c
@@ -44,15 +44,15 @@
44 Blob where;
45 const char *zName;
46 int i;
47
48 blob_zero(&where);
49 for(i=2; i<g.argc; i++) {
50 Blob fname;
51 file_tree_name(g.argv[i], &fname, 1);
52 zName = blob_str(&fname);
53 if( fossil_strcmp(zName, ".")==0 ) {
54 blob_reset(&where);
55 break;
56 }
57 blob_append_sql(&where,
58 " %s (pathname=%Q %s) "
@@ -290,11 +290,11 @@
290 blob_zero(&where);
291 for(i=2; i<g.argc; i++){
292 Blob fname;
293 file_tree_name(g.argv[i], &fname, 1);
294 zName = blob_str(&fname);
295 if( fossil_strcmp(zName, ".")==0 ) {
296 blob_reset(&where);
297 break;
298 }
299 blob_append_sql(&where,
300 " %s (pathname=%Q %s) "
@@ -403,11 +403,11 @@
403 blob_zero(&where);
404 for(i=2; i<g.argc; i++){
405 Blob fname;
406 file_tree_name(g.argv[i], &fname, 1);
407 zName = blob_str(&fname);
408 if( fossil_strcmp(zName, ".")==0 ) {
409 blob_reset(&where);
410 break;
411 }
412 blob_append_sql(&where,
413 " %s (pathname=%Q %s) "
@@ -595,11 +595,11 @@
595 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
596 blob_zero(&rewrittenPathname);
597 g.allowSymlinks = 1; /* Report on symbolic links */
598 while( db_step(&q)==SQLITE_ROW ){
599 zDisplayName = zPathname = db_column_text(&q, 0);
600 if( cwdRelative ) {
601 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
602 file_relative_name(zFullName, &rewrittenPathname, 0);
603 free(zFullName);
604 zDisplayName = blob_str(&rewrittenPathname);
605 if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
@@ -626,20 +626,21 @@
626 ** cannot be undone. If one or more PATH arguments appear, then only
627 ** the files named, or files contained with directories named, will be
628 ** removed.
629 **
630 ** Prompted are issued to confirm the removal of each file, unless
631 ** the --force or --verily flag is used or unless the file matches
632 ** glob pattern specified by the --clean option. No file that matches
633 ** glob patterns specified by --ignore or --keep will ever be deleted.
634 ** The default values for --clean, --ignore, and --keep are determined
635 ** by the (versionable) clean-glob, ignore-glob, and keep-glob settings.
636 ** Files and subdirectories whose names begin with "." are automatically
637 ** ignored unless the --dotfiles option is used.
638 **
639 ** The --verily option overrides all other options and settings and
640 ** deletes all unmanaged files and empty directories without prompting.
 
641 **
642 ** Options:
643 ** --allckouts Check for empty directories within any checkouts
644 ** that may be nested within the current one. This
645 ** option should be used with great care because the
@@ -659,18 +660,19 @@
659 ** therefore, directories that contain only files
660 ** that were removed will be removed as well.
661 ** -f|--force Remove files without prompting.
662 ** -x|--verily Remove everything that is not a managed file or
663 ** the repository itself. Implies -f --emptydirs
664 ** --dotfiles --ignore '' --keep ''.
665 ** --clean <CSG> Never prompt for files matching this
666 ** comma separated list of glob patterns.
667 ** --ignore <CSG> Ignore files matching patterns from the
668 ** comma separated list of glob patterns.
669 ** --keep <CSG> Keep files matching this comma separated
670 ** list of glob patterns.
671 ** -n|--dry-run If given, display instead of run actions.
 
672 ** --temp Remove only Fossil-generated temporary files.
673 ** -v|--verbose Show all files as they are removed.
674 **
675 ** See also: addremove, extras, status
676 */
@@ -703,12 +705,10 @@
703 db_must_be_within_tree();
704 if( find_option("verily","x",0)!=0 ){
705 verilyFlag = allFileFlag = allDirFlag = 1;
706 emptyDirsFlag = 1;
707 scanFlags |= SCAN_ALL;
708 zKeepFlag = 0;
709 zIgnoreFlag = 0;
710 zCleanFlag = 0;
711 }
712 if( zIgnoreFlag==0 && !verilyFlag ){
713 zIgnoreFlag = db_get("ignore-glob", 0);
714 }
@@ -761,11 +761,11 @@
761 blob_reset(&ans);
762 continue;
763 }
764 blob_reset(&ans);
765 }
766 if ( dryRunFlag || file_delete(zName)==0 ){
767 if( verboseFlag || dryRunFlag ){
768 fossil_print("Removed unmanaged file: %s\n", zName+nRoot);
769 }
770 }else if( verboseFlag ){
771 fossil_print("Could not remove file: %s\n", zName+nRoot);
@@ -777,11 +777,11 @@
777 Glob *pEmptyDirs = glob_create(db_get("empty-dirs", 0));
778 Stmt q;
779 Blob root;
780 blob_init(&root, g.zLocalRoot, nRoot - 1);
781 vfile_dir_scan(&root, blob_size(&root), scanFlags, pIgnore,
782 pEmptyDirs, 0);
783 blob_reset(&root);
784 db_prepare(&q,
785 "SELECT %Q || x FROM dscan_temp"
786 " WHERE x NOT IN (%s) AND y = 0"
787 " ORDER BY 1 DESC",
@@ -809,11 +809,11 @@
809 blob_reset(&ans);
810 continue;
811 }
812 blob_reset(&ans);
813 }
814 if ( dryRunFlag || file_rmdir(zName)==0 ){
815 if( verboseFlag || dryRunFlag ){
816 fossil_print("Removed unmanaged directory: %s\n", zName+nRoot);
817 }
818 }else if( verboseFlag ){
819 fossil_print("Could not remove directory: %s\n", zName+nRoot);
@@ -948,11 +948,11 @@
948 Blob prompt;
949 #if defined(_WIN32) || defined(__CYGWIN__)
950 int bomSize;
951 const unsigned char *bom = get_utf8_bom(&bomSize);
952 blob_init(&prompt, (const char *) bom, bomSize);
953 if( zInit && zInit[0]) {
954 blob_append(&prompt, zInit, -1);
955 }
956 #else
957 blob_init(&prompt, zInit, -1);
958 #endif
@@ -1489,11 +1489,11 @@
1489 fossil_free(zOrig);
1490 f = fossil_fopen(zFilename, "wb");
1491 if( f==0 ){
1492 fossil_warning("cannot open %s for writing", zFilename);
1493 }else{
1494 if( fUnicode ) {
1495 int bomSize;
1496 const unsigned char *bom = get_utf8_bom(&bomSize);
1497 fwrite(bom, 1, bomSize, f);
1498 blob_to_utf8_no_bom(p, 0);
1499 }else if( fHasInvalidUtf8 ){
1500
--- src/checkin.c
+++ src/checkin.c
@@ -44,15 +44,15 @@
44 Blob where;
45 const char *zName;
46 int i;
47
48 blob_zero(&where);
49 for(i=2; i<g.argc; i++){
50 Blob fname;
51 file_tree_name(g.argv[i], &fname, 1);
52 zName = blob_str(&fname);
53 if( fossil_strcmp(zName, ".")==0 ){
54 blob_reset(&where);
55 break;
56 }
57 blob_append_sql(&where,
58 " %s (pathname=%Q %s) "
@@ -290,11 +290,11 @@
290 blob_zero(&where);
291 for(i=2; i<g.argc; i++){
292 Blob fname;
293 file_tree_name(g.argv[i], &fname, 1);
294 zName = blob_str(&fname);
295 if( fossil_strcmp(zName, ".")==0 ){
296 blob_reset(&where);
297 break;
298 }
299 blob_append_sql(&where,
300 " %s (pathname=%Q %s) "
@@ -403,11 +403,11 @@
403 blob_zero(&where);
404 for(i=2; i<g.argc; i++){
405 Blob fname;
406 file_tree_name(g.argv[i], &fname, 1);
407 zName = blob_str(&fname);
408 if( fossil_strcmp(zName, ".")==0 ){
409 blob_reset(&where);
410 break;
411 }
412 blob_append_sql(&where,
413 " %s (pathname=%Q %s) "
@@ -595,11 +595,11 @@
595 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
596 blob_zero(&rewrittenPathname);
597 g.allowSymlinks = 1; /* Report on symbolic links */
598 while( db_step(&q)==SQLITE_ROW ){
599 zDisplayName = zPathname = db_column_text(&q, 0);
600 if( cwdRelative ){
601 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
602 file_relative_name(zFullName, &rewrittenPathname, 0);
603 free(zFullName);
604 zDisplayName = blob_str(&rewrittenPathname);
605 if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
@@ -626,20 +626,21 @@
626 ** cannot be undone. If one or more PATH arguments appear, then only
627 ** the files named, or files contained with directories named, will be
628 ** removed.
629 **
630 ** Prompted are issued to confirm the removal of each file, unless
631 ** the --force flag is used or unless the file matches glob pattern
632 ** specified by the --clean option. No file that matches glob patterns
633 ** specified by --ignore or --keep will ever be deleted. The default
634 ** values for --clean, --ignore, and --keep are determined by the
635 ** (versionable) clean-glob, ignore-glob, and keep-glob settings.
636 ** Files and subdirectories whose names begin with "." are automatically
637 ** ignored unless the --dotfiles option is used.
638 **
639 ** The --verily option ignores the keep-glob and ignore-glob settings
640 ** and turns on --force, --dotfiles, and --emptydirs. Use the --verily
641 ** option when you really want to clean up everything.
642 **
643 ** Options:
644 ** --allckouts Check for empty directories within any checkouts
645 ** that may be nested within the current one. This
646 ** option should be used with great care because the
@@ -659,18 +660,19 @@
660 ** therefore, directories that contain only files
661 ** that were removed will be removed as well.
662 ** -f|--force Remove files without prompting.
663 ** -x|--verily Remove everything that is not a managed file or
664 ** the repository itself. Implies -f --emptydirs
665 ** --dotfiles. Disregard keep-glob and ignore-glob.
666 ** --clean <CSG> Never prompt for files matching this
667 ** comma separated list of glob patterns.
668 ** --ignore <CSG> Ignore files matching patterns from the
669 ** comma separated list of glob patterns.
670 ** --keep <CSG> Keep files matching this comma separated
671 ** list of glob patterns.
672 ** -n|--dry-run Delete nothing, but display what would have been
673 ** deleted.
674 ** --temp Remove only Fossil-generated temporary files.
675 ** -v|--verbose Show all files as they are removed.
676 **
677 ** See also: addremove, extras, status
678 */
@@ -703,12 +705,10 @@
705 db_must_be_within_tree();
706 if( find_option("verily","x",0)!=0 ){
707 verilyFlag = allFileFlag = allDirFlag = 1;
708 emptyDirsFlag = 1;
709 scanFlags |= SCAN_ALL;
 
 
710 zCleanFlag = 0;
711 }
712 if( zIgnoreFlag==0 && !verilyFlag ){
713 zIgnoreFlag = db_get("ignore-glob", 0);
714 }
@@ -761,11 +761,11 @@
761 blob_reset(&ans);
762 continue;
763 }
764 blob_reset(&ans);
765 }
766 if( dryRunFlag || file_delete(zName)==0 ){
767 if( verboseFlag || dryRunFlag ){
768 fossil_print("Removed unmanaged file: %s\n", zName+nRoot);
769 }
770 }else if( verboseFlag ){
771 fossil_print("Could not remove file: %s\n", zName+nRoot);
@@ -777,11 +777,11 @@
777 Glob *pEmptyDirs = glob_create(db_get("empty-dirs", 0));
778 Stmt q;
779 Blob root;
780 blob_init(&root, g.zLocalRoot, nRoot - 1);
781 vfile_dir_scan(&root, blob_size(&root), scanFlags, pIgnore,
782 pEmptyDirs);
783 blob_reset(&root);
784 db_prepare(&q,
785 "SELECT %Q || x FROM dscan_temp"
786 " WHERE x NOT IN (%s) AND y = 0"
787 " ORDER BY 1 DESC",
@@ -809,11 +809,11 @@
809 blob_reset(&ans);
810 continue;
811 }
812 blob_reset(&ans);
813 }
814 if( dryRunFlag || file_rmdir(zName)==0 ){
815 if( verboseFlag || dryRunFlag ){
816 fossil_print("Removed unmanaged directory: %s\n", zName+nRoot);
817 }
818 }else if( verboseFlag ){
819 fossil_print("Could not remove directory: %s\n", zName+nRoot);
@@ -948,11 +948,11 @@
948 Blob prompt;
949 #if defined(_WIN32) || defined(__CYGWIN__)
950 int bomSize;
951 const unsigned char *bom = get_utf8_bom(&bomSize);
952 blob_init(&prompt, (const char *) bom, bomSize);
953 if( zInit && zInit[0]){
954 blob_append(&prompt, zInit, -1);
955 }
956 #else
957 blob_init(&prompt, zInit, -1);
958 #endif
@@ -1489,11 +1489,11 @@
1489 fossil_free(zOrig);
1490 f = fossil_fopen(zFilename, "wb");
1491 if( f==0 ){
1492 fossil_warning("cannot open %s for writing", zFilename);
1493 }else{
1494 if( fUnicode ){
1495 int bomSize;
1496 const unsigned char *bom = get_utf8_bom(&bomSize);
1497 fwrite(bom, 1, bomSize, f);
1498 blob_to_utf8_no_bom(p, 0);
1499 }else if( fHasInvalidUtf8 ){
1500
+2 -2
--- src/db.c
+++ src/db.c
@@ -1887,11 +1887,11 @@
18871887
**
18881888
** Return the text of the string if it is found. Return NULL if not
18891889
** found.
18901890
**
18911891
** If the zNonVersionedSetting parameter is not NULL then it holds the
1892
-** non-versioned value for this setting. If both a versioned and ad
1892
+** non-versioned value for this setting. If both a versioned and a
18931893
** non-versioned value exist and are not equal, then a warning message
18941894
** might be generated.
18951895
*/
18961896
char *db_get_versioned(const char *zName, char *zNonVersionedSetting){
18971897
char *zVersionedSetting = 0;
@@ -1927,11 +1927,11 @@
19271927
Blob setting;
19281928
blob_zero(&setting);
19291929
if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){
19301930
blob_trim(&setting); /* Avoid non-obvious problems with line endings
19311931
** on boolean properties */
1932
- zVersionedSetting = strdup(blob_str(&setting));
1932
+ zVersionedSetting = fossil_strdup(blob_str(&setting));
19331933
}
19341934
blob_reset(&setting);
19351935
/* See if there's a no-warn flag */
19361936
blob_append(&versionedPathname, ".no-warn", -1);
19371937
if( file_size(blob_str(&versionedPathname))>=0 ){
19381938
--- src/db.c
+++ src/db.c
@@ -1887,11 +1887,11 @@
1887 **
1888 ** Return the text of the string if it is found. Return NULL if not
1889 ** found.
1890 **
1891 ** If the zNonVersionedSetting parameter is not NULL then it holds the
1892 ** non-versioned value for this setting. If both a versioned and ad
1893 ** non-versioned value exist and are not equal, then a warning message
1894 ** might be generated.
1895 */
1896 char *db_get_versioned(const char *zName, char *zNonVersionedSetting){
1897 char *zVersionedSetting = 0;
@@ -1927,11 +1927,11 @@
1927 Blob setting;
1928 blob_zero(&setting);
1929 if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){
1930 blob_trim(&setting); /* Avoid non-obvious problems with line endings
1931 ** on boolean properties */
1932 zVersionedSetting = strdup(blob_str(&setting));
1933 }
1934 blob_reset(&setting);
1935 /* See if there's a no-warn flag */
1936 blob_append(&versionedPathname, ".no-warn", -1);
1937 if( file_size(blob_str(&versionedPathname))>=0 ){
1938
--- src/db.c
+++ src/db.c
@@ -1887,11 +1887,11 @@
1887 **
1888 ** Return the text of the string if it is found. Return NULL if not
1889 ** found.
1890 **
1891 ** If the zNonVersionedSetting parameter is not NULL then it holds the
1892 ** non-versioned value for this setting. If both a versioned and a
1893 ** non-versioned value exist and are not equal, then a warning message
1894 ** might be generated.
1895 */
1896 char *db_get_versioned(const char *zName, char *zNonVersionedSetting){
1897 char *zVersionedSetting = 0;
@@ -1927,11 +1927,11 @@
1927 Blob setting;
1928 blob_zero(&setting);
1929 if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){
1930 blob_trim(&setting); /* Avoid non-obvious problems with line endings
1931 ** on boolean properties */
1932 zVersionedSetting = fossil_strdup(blob_str(&setting));
1933 }
1934 blob_reset(&setting);
1935 /* See if there's a no-warn flag */
1936 blob_append(&versionedPathname, ".no-warn", -1);
1937 if( file_size(blob_str(&versionedPathname))>=0 ){
1938
+3 -3
--- src/finfo.c
+++ src/finfo.c
@@ -261,12 +261,12 @@
261261
verify_all_options();
262262
263263
for(i=2; i<g.argc; i++){
264264
file_tree_name(g.argv[i], &fname, 1);
265265
blob_zero(&content);
266
- rc = historical_version_of_file(zRev, blob_str(&fname), &content, 0,0,0,0);
267
- if( rc==0 ){
266
+ rc = historical_version_of_file(zRev, blob_str(&fname), &content, 0,0,0,2);
267
+ if( rc==2 ){
268268
fossil_fatal("no such file: %s", g.argv[i]);
269269
}
270270
blob_write_to_file(&content, "-");
271271
blob_reset(&fname);
272272
blob_reset(&content);
@@ -509,11 +509,11 @@
509509
@ %z(href("%R/annotate?filename=%h&checkin=%s",z,zCkin))
510510
@ [annotate]</a>
511511
@ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
512512
@ [blame]</a>
513513
@ %z(href("%R/timeline?n=200&uf=%!S",zUuid))[check-ins&nbsp;using]</a>
514
- if( fpid ){
514
+ if( fpid>0 ){
515515
@ %z(href("%R/fdiff?sbs=1&v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
516516
}
517517
}
518518
if( fDebug & FINFO_DEBUG_MLINK ){
519519
int ii;
520520
--- src/finfo.c
+++ src/finfo.c
@@ -261,12 +261,12 @@
261 verify_all_options();
262
263 for(i=2; i<g.argc; i++){
264 file_tree_name(g.argv[i], &fname, 1);
265 blob_zero(&content);
266 rc = historical_version_of_file(zRev, blob_str(&fname), &content, 0,0,0,0);
267 if( rc==0 ){
268 fossil_fatal("no such file: %s", g.argv[i]);
269 }
270 blob_write_to_file(&content, "-");
271 blob_reset(&fname);
272 blob_reset(&content);
@@ -509,11 +509,11 @@
509 @ %z(href("%R/annotate?filename=%h&checkin=%s",z,zCkin))
510 @ [annotate]</a>
511 @ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
512 @ [blame]</a>
513 @ %z(href("%R/timeline?n=200&uf=%!S",zUuid))[check-ins&nbsp;using]</a>
514 if( fpid ){
515 @ %z(href("%R/fdiff?sbs=1&v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
516 }
517 }
518 if( fDebug & FINFO_DEBUG_MLINK ){
519 int ii;
520
--- src/finfo.c
+++ src/finfo.c
@@ -261,12 +261,12 @@
261 verify_all_options();
262
263 for(i=2; i<g.argc; i++){
264 file_tree_name(g.argv[i], &fname, 1);
265 blob_zero(&content);
266 rc = historical_version_of_file(zRev, blob_str(&fname), &content, 0,0,0,2);
267 if( rc==2 ){
268 fossil_fatal("no such file: %s", g.argv[i]);
269 }
270 blob_write_to_file(&content, "-");
271 blob_reset(&fname);
272 blob_reset(&content);
@@ -509,11 +509,11 @@
509 @ %z(href("%R/annotate?filename=%h&checkin=%s",z,zCkin))
510 @ [annotate]</a>
511 @ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
512 @ [blame]</a>
513 @ %z(href("%R/timeline?n=200&uf=%!S",zUuid))[check-ins&nbsp;using]</a>
514 if( fpid>0 ){
515 @ %z(href("%R/fdiff?sbs=1&v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
516 }
517 }
518 if( fDebug & FINFO_DEBUG_MLINK ){
519 int ii;
520
+2 -2
--- src/main.c
+++ src/main.c
@@ -590,12 +590,12 @@
590590
#endif
591591
{
592592
const char *zCmdName = "unknown";
593593
int idx;
594594
int rc;
595
- if( sqlite3_libversion_number()<3008003 ){
596
- fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.3",
595
+ if( sqlite3_libversion_number()<3008007 ){
596
+ fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.7",
597597
sqlite3_libversion());
598598
}
599599
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
600600
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
601601
memset(&g, 0, sizeof(g));
602602
--- src/main.c
+++ src/main.c
@@ -590,12 +590,12 @@
590 #endif
591 {
592 const char *zCmdName = "unknown";
593 int idx;
594 int rc;
595 if( sqlite3_libversion_number()<3008003 ){
596 fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.3",
597 sqlite3_libversion());
598 }
599 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
600 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
601 memset(&g, 0, sizeof(g));
602
--- src/main.c
+++ src/main.c
@@ -590,12 +590,12 @@
590 #endif
591 {
592 const char *zCmdName = "unknown";
593 int idx;
594 int rc;
595 if( sqlite3_libversion_number()<3008007 ){
596 fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.7",
597 sqlite3_libversion());
598 }
599 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
600 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
601 memset(&g, 0, sizeof(g));
602
+3 -3
--- src/manifest.c
+++ src/manifest.c
@@ -1344,10 +1344,11 @@
13441344
** A single mlink entry is added for every file that changed content,
13451345
** name, and/or permissions going from pid to cid.
13461346
**
13471347
** Deleted files have mlink.fid=0.
13481348
** Added files have mlink.pid=0.
1349
+** File added by merge have mlink.pid=-1
13491350
** Edited files have both mlink.pid!=0 and mlink.fid!=0
13501351
*/
13511352
static void add_mlink(
13521353
int pmid, Manifest *pParent, /* Parent check-in */
13531354
int mid, Manifest *pChild, /* The child check-in */
@@ -1801,14 +1802,13 @@
18011802
pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
18021803
add_mlink(pid, 0, rid, p, i==0);
18031804
if( i==0 ) parentid = pid;
18041805
}
18051806
if( p->nParent>1 ){
1806
- /* Remove incorrect MLINK create-file entries that arise when a
1807
- ** file is added by merge. */
1807
+ /* Change MLINK.PID from 0 to -1 for files that are added by merge. */
18081808
db_multi_exec(
1809
- "DELETE FROM mlink"
1809
+ "UPDATE mlink SET pid=-1"
18101810
" WHERE mid=%d"
18111811
" AND pid=0"
18121812
" AND fnid IN "
18131813
" (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
18141814
" HAVING count(*)<%d)",
18151815
--- src/manifest.c
+++ src/manifest.c
@@ -1344,10 +1344,11 @@
1344 ** A single mlink entry is added for every file that changed content,
1345 ** name, and/or permissions going from pid to cid.
1346 **
1347 ** Deleted files have mlink.fid=0.
1348 ** Added files have mlink.pid=0.
 
1349 ** Edited files have both mlink.pid!=0 and mlink.fid!=0
1350 */
1351 static void add_mlink(
1352 int pmid, Manifest *pParent, /* Parent check-in */
1353 int mid, Manifest *pChild, /* The child check-in */
@@ -1801,14 +1802,13 @@
1801 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1802 add_mlink(pid, 0, rid, p, i==0);
1803 if( i==0 ) parentid = pid;
1804 }
1805 if( p->nParent>1 ){
1806 /* Remove incorrect MLINK create-file entries that arise when a
1807 ** file is added by merge. */
1808 db_multi_exec(
1809 "DELETE FROM mlink"
1810 " WHERE mid=%d"
1811 " AND pid=0"
1812 " AND fnid IN "
1813 " (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
1814 " HAVING count(*)<%d)",
1815
--- src/manifest.c
+++ src/manifest.c
@@ -1344,10 +1344,11 @@
1344 ** A single mlink entry is added for every file that changed content,
1345 ** name, and/or permissions going from pid to cid.
1346 **
1347 ** Deleted files have mlink.fid=0.
1348 ** Added files have mlink.pid=0.
1349 ** File added by merge have mlink.pid=-1
1350 ** Edited files have both mlink.pid!=0 and mlink.fid!=0
1351 */
1352 static void add_mlink(
1353 int pmid, Manifest *pParent, /* Parent check-in */
1354 int mid, Manifest *pChild, /* The child check-in */
@@ -1801,14 +1802,13 @@
1802 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1803 add_mlink(pid, 0, rid, p, i==0);
1804 if( i==0 ) parentid = pid;
1805 }
1806 if( p->nParent>1 ){
1807 /* Change MLINK.PID from 0 to -1 for files that are added by merge. */
 
1808 db_multi_exec(
1809 "UPDATE mlink SET pid=-1"
1810 " WHERE mid=%d"
1811 " AND pid=0"
1812 " AND fnid IN "
1813 " (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
1814 " HAVING count(*)<%d)",
1815
+14 -10
--- src/report.c
+++ src/report.c
@@ -1083,11 +1083,11 @@
10831083
** then the output consists of lines of tab-separated fields instead of
10841084
** an HTML table.
10851085
*/
10861086
void rptview_page(void){
10871087
int count = 0;
1088
- int rn;
1088
+ int rn, rc;
10891089
char *zSql;
10901090
char *zTitle;
10911091
char *zOwner;
10921092
char *zClrKey;
10931093
int tabs;
@@ -1095,28 +1095,32 @@
10951095
char *zErr1 = 0;
10961096
char *zErr2 = 0;
10971097
10981098
login_check_credentials();
10991099
if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; }
1100
- rn = atoi(PD("rn","0"));
1101
- if( rn==0 ){
1102
- cgi_redirect("reportlist");
1103
- return;
1104
- }
11051100
tabs = P("tablist")!=0;
1106
- /* view_add_functions(tabs); */
11071101
db_prepare(&q,
1108
- "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
1109
- if( db_step(&q)!=SQLITE_ROW ){
1110
- cgi_redirect("reportlist");
1102
+ "SELECT title, sqlcode, owner, cols, rn FROM reportfmt WHERE rn=%d",
1103
+ atoi(PD("rn","0")));
1104
+ rc = db_step(&q);
1105
+ if( rc!=SQLITE_ROW ){
1106
+ db_finalize(&q);
1107
+ db_prepare(&q,
1108
+ "SELECT title, sqlcode, owner, cols, rn FROM reportfmt WHERE title GLOB %Q",
1109
+ P("title"));
1110
+ rc = db_step(&q);
1111
+ }
1112
+ if( rc!=SQLITE_ROW ){
11111113
db_finalize(&q);
1114
+ cgi_redirect("reportlist");
11121115
return;
11131116
}
11141117
zTitle = db_column_malloc(&q, 0);
11151118
zSql = db_column_malloc(&q, 1);
11161119
zOwner = db_column_malloc(&q, 2);
11171120
zClrKey = db_column_malloc(&q, 3);
1121
+ rn = db_column_int(&q,4);
11181122
db_finalize(&q);
11191123
11201124
if( P("order_by") ){
11211125
/*
11221126
** If the user wants to do a column sort, wrap the query into a sub
11231127
--- src/report.c
+++ src/report.c
@@ -1083,11 +1083,11 @@
1083 ** then the output consists of lines of tab-separated fields instead of
1084 ** an HTML table.
1085 */
1086 void rptview_page(void){
1087 int count = 0;
1088 int rn;
1089 char *zSql;
1090 char *zTitle;
1091 char *zOwner;
1092 char *zClrKey;
1093 int tabs;
@@ -1095,28 +1095,32 @@
1095 char *zErr1 = 0;
1096 char *zErr2 = 0;
1097
1098 login_check_credentials();
1099 if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; }
1100 rn = atoi(PD("rn","0"));
1101 if( rn==0 ){
1102 cgi_redirect("reportlist");
1103 return;
1104 }
1105 tabs = P("tablist")!=0;
1106 /* view_add_functions(tabs); */
1107 db_prepare(&q,
1108 "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
1109 if( db_step(&q)!=SQLITE_ROW ){
1110 cgi_redirect("reportlist");
 
 
 
 
 
 
 
 
1111 db_finalize(&q);
 
1112 return;
1113 }
1114 zTitle = db_column_malloc(&q, 0);
1115 zSql = db_column_malloc(&q, 1);
1116 zOwner = db_column_malloc(&q, 2);
1117 zClrKey = db_column_malloc(&q, 3);
 
1118 db_finalize(&q);
1119
1120 if( P("order_by") ){
1121 /*
1122 ** If the user wants to do a column sort, wrap the query into a sub
1123
--- src/report.c
+++ src/report.c
@@ -1083,11 +1083,11 @@
1083 ** then the output consists of lines of tab-separated fields instead of
1084 ** an HTML table.
1085 */
1086 void rptview_page(void){
1087 int count = 0;
1088 int rn, rc;
1089 char *zSql;
1090 char *zTitle;
1091 char *zOwner;
1092 char *zClrKey;
1093 int tabs;
@@ -1095,28 +1095,32 @@
1095 char *zErr1 = 0;
1096 char *zErr2 = 0;
1097
1098 login_check_credentials();
1099 if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; }
 
 
 
 
 
1100 tabs = P("tablist")!=0;
 
1101 db_prepare(&q,
1102 "SELECT title, sqlcode, owner, cols, rn FROM reportfmt WHERE rn=%d",
1103 atoi(PD("rn","0")));
1104 rc = db_step(&q);
1105 if( rc!=SQLITE_ROW ){
1106 db_finalize(&q);
1107 db_prepare(&q,
1108 "SELECT title, sqlcode, owner, cols, rn FROM reportfmt WHERE title GLOB %Q",
1109 P("title"));
1110 rc = db_step(&q);
1111 }
1112 if( rc!=SQLITE_ROW ){
1113 db_finalize(&q);
1114 cgi_redirect("reportlist");
1115 return;
1116 }
1117 zTitle = db_column_malloc(&q, 0);
1118 zSql = db_column_malloc(&q, 1);
1119 zOwner = db_column_malloc(&q, 2);
1120 zClrKey = db_column_malloc(&q, 3);
1121 rn = db_column_int(&q,4);
1122 db_finalize(&q);
1123
1124 if( P("order_by") ){
1125 /*
1126 ** If the user wants to do a column sort, wrap the query into a sub
1127
+14 -13
--- src/schema.c
+++ src/schema.c
@@ -249,22 +249,24 @@
249249
@ -- pid = Parent file ID.
250250
@ -- fnid = File Name ID.
251251
@ -- pfnid = Parent File Name ID.
252252
@ -- isaux = pmid IS AUXiliary parent, not primary parent
253253
@ --
254
-@ -- pid==0 if the file is added by check-in mid.
255
-@ -- fid==0 if the file is removed by check-in mid.
254
+@ -- pid==0 if the file is added by check-in mid.
255
+@ -- pid==(-1) if the file exists in a merge parents but not in the primary
256
+@ -- parent. In other words, if the file file was added by merge.
257
+@ -- fid==0 if the file is removed by check-in mid.
256258
@ --
257259
@ CREATE TABLE mlink(
258
-@ mid INTEGER REFERENCES plink(cid), -- Check-in that contains fid
259
-@ fid INTEGER REFERENCES blob, -- New file content. 0 if deleted
260
-@ pmid INTEGER REFERENCES plink(cid), -- Check-in that contains pid
261
-@ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
262
-@ fnid INTEGER REFERENCES filename, -- Name of the file
263
-@ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
264
-@ mperm INTEGER, -- File permissions. 1==exec
265
-@ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
260
+@ mid INTEGER, -- Check-in that contains fid
261
+@ fid INTEGER, -- New file content. 0 if deleted
262
+@ pmid INTEGER, -- Check-in that contains pid
263
+@ pid INTEGER, -- Prev file content. 0 if new. -1 merge
264
+@ fnid INTEGER REFERENCES filename, -- Name of the file
265
+@ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
266
+@ mperm INTEGER, -- File permissions. 1==exec
267
+@ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
266268
@ );
267269
@ CREATE INDEX mlink_i1 ON mlink(mid);
268270
@ CREATE INDEX mlink_i2 ON mlink(fnid);
269271
@ CREATE INDEX mlink_i3 ON mlink(fid);
270272
@ CREATE INDEX mlink_i4 ON mlink(pid);
@@ -367,10 +369,11 @@
367369
@ INSERT INTO tag VALUES(6, 'private'); -- TAG_PRIVATE
368370
@ INSERT INTO tag VALUES(7, 'cluster'); -- TAG_CLUSTER
369371
@ INSERT INTO tag VALUES(8, 'branch'); -- TAG_BRANCH
370372
@ INSERT INTO tag VALUES(9, 'closed'); -- TAG_CLOSED
371373
@ INSERT INTO tag VALUES(10,'parent'); -- TAG_PARENT
374
+@ INSERT INTO tag VALUES(11,'note'); -- TAG_NOTE
372375
@
373376
@ -- Assignments of tags to baselines. Note that we allow tags to
374377
@ -- have values assigned to them. So we are not really dealing with
375378
@ -- tags here. These are really properties. But we are going to
376379
@ -- keep calling them tags because in many cases the value is ignored.
@@ -466,13 +469,11 @@
466469
# define TAG_PRIVATE 6 /* Do not sync */
467470
# define TAG_CLUSTER 7 /* A cluster */
468471
# define TAG_BRANCH 8 /* Value is name of the current branch */
469472
# define TAG_CLOSED 9 /* Do not display this check-in as a leaf */
470473
# define TAG_PARENT 10 /* Change to parentage on a check-in */
471
-#endif
472
-#if EXPORT_INTERFACE
473
-# define MAX_INT_TAG 16 /* The largest pre-assigned tag id */
474
+# define TAG_NOTE 11 /* Extra text appended to a check-in comment */
474475
#endif
475476
476477
/*
477478
** The schema for the local FOSSIL database file found at the root
478479
** of every check-out. This database contains the complete state of
479480
--- src/schema.c
+++ src/schema.c
@@ -249,22 +249,24 @@
249 @ -- pid = Parent file ID.
250 @ -- fnid = File Name ID.
251 @ -- pfnid = Parent File Name ID.
252 @ -- isaux = pmid IS AUXiliary parent, not primary parent
253 @ --
254 @ -- pid==0 if the file is added by check-in mid.
255 @ -- fid==0 if the file is removed by check-in mid.
 
 
256 @ --
257 @ CREATE TABLE mlink(
258 @ mid INTEGER REFERENCES plink(cid), -- Check-in that contains fid
259 @ fid INTEGER REFERENCES blob, -- New file content. 0 if deleted
260 @ pmid INTEGER REFERENCES plink(cid), -- Check-in that contains pid
261 @ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
262 @ fnid INTEGER REFERENCES filename, -- Name of the file
263 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
264 @ mperm INTEGER, -- File permissions. 1==exec
265 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
266 @ );
267 @ CREATE INDEX mlink_i1 ON mlink(mid);
268 @ CREATE INDEX mlink_i2 ON mlink(fnid);
269 @ CREATE INDEX mlink_i3 ON mlink(fid);
270 @ CREATE INDEX mlink_i4 ON mlink(pid);
@@ -367,10 +369,11 @@
367 @ INSERT INTO tag VALUES(6, 'private'); -- TAG_PRIVATE
368 @ INSERT INTO tag VALUES(7, 'cluster'); -- TAG_CLUSTER
369 @ INSERT INTO tag VALUES(8, 'branch'); -- TAG_BRANCH
370 @ INSERT INTO tag VALUES(9, 'closed'); -- TAG_CLOSED
371 @ INSERT INTO tag VALUES(10,'parent'); -- TAG_PARENT
 
372 @
373 @ -- Assignments of tags to baselines. Note that we allow tags to
374 @ -- have values assigned to them. So we are not really dealing with
375 @ -- tags here. These are really properties. But we are going to
376 @ -- keep calling them tags because in many cases the value is ignored.
@@ -466,13 +469,11 @@
466 # define TAG_PRIVATE 6 /* Do not sync */
467 # define TAG_CLUSTER 7 /* A cluster */
468 # define TAG_BRANCH 8 /* Value is name of the current branch */
469 # define TAG_CLOSED 9 /* Do not display this check-in as a leaf */
470 # define TAG_PARENT 10 /* Change to parentage on a check-in */
471 #endif
472 #if EXPORT_INTERFACE
473 # define MAX_INT_TAG 16 /* The largest pre-assigned tag id */
474 #endif
475
476 /*
477 ** The schema for the local FOSSIL database file found at the root
478 ** of every check-out. This database contains the complete state of
479
--- src/schema.c
+++ src/schema.c
@@ -249,22 +249,24 @@
249 @ -- pid = Parent file ID.
250 @ -- fnid = File Name ID.
251 @ -- pfnid = Parent File Name ID.
252 @ -- isaux = pmid IS AUXiliary parent, not primary parent
253 @ --
254 @ -- pid==0 if the file is added by check-in mid.
255 @ -- pid==(-1) if the file exists in a merge parents but not in the primary
256 @ -- parent. In other words, if the file file was added by merge.
257 @ -- fid==0 if the file is removed by check-in mid.
258 @ --
259 @ CREATE TABLE mlink(
260 @ mid INTEGER, -- Check-in that contains fid
261 @ fid INTEGER, -- New file content. 0 if deleted
262 @ pmid INTEGER, -- Check-in that contains pid
263 @ pid INTEGER, -- Prev file content. 0 if new. -1 merge
264 @ fnid INTEGER REFERENCES filename, -- Name of the file
265 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
266 @ mperm INTEGER, -- File permissions. 1==exec
267 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
268 @ );
269 @ CREATE INDEX mlink_i1 ON mlink(mid);
270 @ CREATE INDEX mlink_i2 ON mlink(fnid);
271 @ CREATE INDEX mlink_i3 ON mlink(fid);
272 @ CREATE INDEX mlink_i4 ON mlink(pid);
@@ -367,10 +369,11 @@
369 @ INSERT INTO tag VALUES(6, 'private'); -- TAG_PRIVATE
370 @ INSERT INTO tag VALUES(7, 'cluster'); -- TAG_CLUSTER
371 @ INSERT INTO tag VALUES(8, 'branch'); -- TAG_BRANCH
372 @ INSERT INTO tag VALUES(9, 'closed'); -- TAG_CLOSED
373 @ INSERT INTO tag VALUES(10,'parent'); -- TAG_PARENT
374 @ INSERT INTO tag VALUES(11,'note'); -- TAG_NOTE
375 @
376 @ -- Assignments of tags to baselines. Note that we allow tags to
377 @ -- have values assigned to them. So we are not really dealing with
378 @ -- tags here. These are really properties. But we are going to
379 @ -- keep calling them tags because in many cases the value is ignored.
@@ -466,13 +469,11 @@
469 # define TAG_PRIVATE 6 /* Do not sync */
470 # define TAG_CLUSTER 7 /* A cluster */
471 # define TAG_BRANCH 8 /* Value is name of the current branch */
472 # define TAG_CLOSED 9 /* Do not display this check-in as a leaf */
473 # define TAG_PARENT 10 /* Change to parentage on a check-in */
474 # define TAG_NOTE 11 /* Extra text appended to a check-in comment */
 
 
475 #endif
476
477 /*
478 ** The schema for the local FOSSIL database file found at the root
479 ** of every check-out. This database contains the complete state of
480
+114 -15
--- src/shell.c
+++ src/shell.c
@@ -988,11 +988,20 @@
988988
break;
989989
}
990990
case MODE_Insert: {
991991
p->cnt++;
992992
if( azArg==0 ) break;
993
- fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
993
+ fprintf(p->out,"INSERT INTO %s",p->zDestTable);
994
+ if( p->showHeader ){
995
+ fprintf(p->out,"(");
996
+ for(i=0; i<nArg; i++){
997
+ char *zSep = i>0 ? ",": "";
998
+ fprintf(p->out, "%s%s", zSep, azCol[i]);
999
+ }
1000
+ fprintf(p->out,")");
1001
+ }
1002
+ fprintf(p->out," VALUES(");
9941003
for(i=0; i<nArg; i++){
9951004
char *zSep = i>0 ? ",": "";
9961005
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
9971006
fprintf(p->out,"%sNULL",zSep);
9981007
}else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1189,11 +1198,11 @@
11891198
*/
11901199
static char *save_err_msg(
11911200
sqlite3 *db /* Database to query */
11921201
){
11931202
int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
1194
- char *zErrMsg = sqlite3_malloc(nErrMsg);
1203
+ char *zErrMsg = sqlite3_malloc64(nErrMsg);
11951204
if( zErrMsg ){
11961205
memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
11971206
}
11981207
return zErrMsg;
11991208
}
@@ -1426,12 +1435,12 @@
14261435
int p2op = (p2 + (iOp-iAddr));
14271436
14281437
/* Grow the p->aiIndent array as required */
14291438
if( iOp>=nAlloc ){
14301439
nAlloc += 100;
1431
- p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int));
1432
- abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int));
1440
+ p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int));
1441
+ abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int));
14331442
}
14341443
abYield[iOp] = str_in_array(zOp, azYield);
14351444
p->aiIndent[iOp] = 0;
14361445
p->nIndent = iOp+1;
14371446
@@ -1544,11 +1553,11 @@
15441553
if( SQLITE_ROW == rc ){
15451554
/* if we have a callback... */
15461555
if( xCallback ){
15471556
/* allocate space for col name ptr, value ptr, and type */
15481557
int nCol = sqlite3_column_count(pStmt);
1549
- void *pData = sqlite3_malloc(3*nCol*sizeof(const char*) + 1);
1558
+ void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
15501559
if( !pData ){
15511560
rc = SQLITE_NOMEM;
15521561
}else{
15531562
char **azCols = (char **)pData; /* Names of result columns */
15541563
char **azVals = &azCols[nCol]; /* Results */
@@ -1770,10 +1779,11 @@
17701779
** Text of a help message
17711780
*/
17721781
static char zHelp[] =
17731782
".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
17741783
".bail on|off Stop after hitting an error. Default OFF\n"
1784
+ ".binary on|off Turn binary output on or off. Default OFF\n"
17751785
".clone NEWDB Clone data into NEWDB from the existing database\n"
17761786
".databases List names and files of attached databases\n"
17771787
".dbinfo ?DB? Show status information about the database\n"
17781788
".dump ?TABLE? ... Dump the database in an SQL text format\n"
17791789
" If TABLE specified, only dump tables matching\n"
@@ -1791,10 +1801,11 @@
17911801
" If TABLE specified, only show indexes for tables\n"
17921802
" matching LIKE pattern TABLE.\n"
17931803
#ifdef SQLITE_ENABLE_IOTRACE
17941804
".iotrace FILE Enable I/O diagnostic logging to FILE\n"
17951805
#endif
1806
+ ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n"
17961807
#ifndef SQLITE_OMIT_LOAD_EXTENSION
17971808
".load FILE ?ENTRY? Load an extension library\n"
17981809
#endif
17991810
".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
18001811
".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -1860,11 +1871,11 @@
18601871
in = fopen(zName, "rb");
18611872
if( in==0 ) return;
18621873
fseek(in, 0, SEEK_END);
18631874
nIn = ftell(in);
18641875
rewind(in);
1865
- pBuf = sqlite3_malloc( nIn );
1876
+ pBuf = sqlite3_malloc64( nIn );
18661877
if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
18671878
sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
18681879
}else{
18691880
sqlite3_free(pBuf);
18701881
}
@@ -1931,30 +1942,48 @@
19311942
}
19321943
19331944
/*
19341945
** Do C-language style dequoting.
19351946
**
1947
+** \a -> alarm
1948
+** \b -> backspace
19361949
** \t -> tab
19371950
** \n -> newline
1951
+** \v -> vertical tab
1952
+** \f -> form feed
19381953
** \r -> carriage return
1954
+** \s -> space
19391955
** \" -> "
1940
-** \NNN -> ascii character NNN in octal
1956
+** \' -> '
19411957
** \\ -> backslash
1958
+** \NNN -> ascii character NNN in octal
19421959
*/
19431960
static void resolve_backslashes(char *z){
19441961
int i, j;
19451962
char c;
19461963
while( *z && *z!='\\' ) z++;
19471964
for(i=j=0; (c = z[i])!=0; i++, j++){
19481965
if( c=='\\' && z[i+1]!=0 ){
19491966
c = z[++i];
1950
- if( c=='n' ){
1951
- c = '\n';
1967
+ if( c=='a' ){
1968
+ c = '\a';
1969
+ }else if( c=='b' ){
1970
+ c = '\b';
19521971
}else if( c=='t' ){
19531972
c = '\t';
1973
+ }else if( c=='n' ){
1974
+ c = '\n';
1975
+ }else if( c=='v' ){
1976
+ c = '\v';
1977
+ }else if( c=='f' ){
1978
+ c = '\f';
19541979
}else if( c=='r' ){
19551980
c = '\r';
1981
+ }else if( c=='"' ){
1982
+ c = '"';
1983
+ }else if( c=='\'' ){
1984
+ c = '\'';
19561985
}else if( c=='\\' ){
19571986
c = '\\';
19581987
}else if( c>='0' && c<='7' ){
19591988
c -= '0';
19601989
if( z[i+1]>='0' && z[i+1]<='7' ){
@@ -2120,11 +2149,11 @@
21202149
21212150
/* Append a single byte to z[] */
21222151
static void import_append_char(ImportCtx *p, int c){
21232152
if( p->n+1>=p->nAlloc ){
21242153
p->nAlloc += p->nAlloc + 100;
2125
- p->z = sqlite3_realloc(p->z, p->nAlloc);
2154
+ p->z = sqlite3_realloc64(p->z, p->nAlloc);
21262155
if( p->z==0 ){
21272156
fprintf(stderr, "out of memory\n");
21282157
exit(1);
21292158
}
21302159
}
@@ -2134,11 +2163,11 @@
21342163
/* Read a single field of CSV text. Compatible with rfc4180 and extended
21352164
** with the option of having a separator other than ",".
21362165
**
21372166
** + Input comes from p->in.
21382167
** + Store results in p->z of length p->n. Space to hold p->z comes
2139
-** from sqlite3_malloc().
2168
+** from sqlite3_malloc64().
21402169
** + Use p->cSep as the column separator. The default is ",".
21412170
** + Use p->rSep as the row separator. The default is "\n".
21422171
** + Keep track of the line number in p->nLine.
21432172
** + Store the character that terminates the field in p->cTerm. Store
21442173
** EOF on end-of-file.
@@ -2208,11 +2237,11 @@
22082237
22092238
/* Read a single field of ASCII delimited text.
22102239
**
22112240
** + Input comes from p->in.
22122241
** + Store results in p->z of length p->n. Space to hold p->z comes
2213
-** from sqlite3_malloc().
2242
+** from sqlite3_malloc64().
22142243
** + Use p->cSep as the column separator. The default is "\x1F".
22152244
** + Use p->rSep as the row separator. The default is "\x1E".
22162245
** + Keep track of the row number in p->nLine.
22172246
** + Store the character that terminates the field in p->cTerm. Store
22182247
** EOF on end-of-file.
@@ -2268,11 +2297,11 @@
22682297
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
22692298
zQuery);
22702299
goto end_data_xfer;
22712300
}
22722301
n = sqlite3_column_count(pQuery);
2273
- zInsert = sqlite3_malloc(200 + nTable + n*3);
2302
+ zInsert = sqlite3_malloc64(200 + nTable + n*3);
22742303
if( zInsert==0 ){
22752304
fprintf(stderr, "out of memory\n");
22762305
goto end_data_xfer;
22772306
}
22782307
sqlite3_snprintf(200+nTable,zInsert,
@@ -2683,10 +2712,23 @@
26832712
}else{
26842713
fprintf(stderr, "Usage: .bail on|off\n");
26852714
rc = 1;
26862715
}
26872716
}else
2717
+
2718
+ if( c=='b' && n>=3 && strncmp(azArg[0], "binary", n)==0 ){
2719
+ if( nArg==2 ){
2720
+ if( booleanValue(azArg[1]) ){
2721
+ setBinaryMode(p->out);
2722
+ }else{
2723
+ setTextMode(p->out);
2724
+ }
2725
+ }else{
2726
+ fprintf(stderr, "Usage: .binary on|off\n");
2727
+ rc = 1;
2728
+ }
2729
+ }else
26882730
26892731
/* The undocumented ".breakpoint" command causes a call to the no-op
26902732
** routine named test_breakpoint().
26912733
*/
26922734
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
@@ -3023,11 +3065,11 @@
30233065
}
30243066
nCol = sqlite3_column_count(pStmt);
30253067
sqlite3_finalize(pStmt);
30263068
pStmt = 0;
30273069
if( nCol==0 ) return 0; /* no columns, no error */
3028
- zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
3070
+ zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
30293071
if( zSql==0 ){
30303072
fprintf(stderr, "Error: out of memory\n");
30313073
xCloser(sCtx.in);
30323074
return 1;
30333075
}
@@ -3163,10 +3205,67 @@
31633205
sqlite3IoTrace = iotracePrintf;
31643206
}
31653207
}
31663208
}else
31673209
#endif
3210
+ if( c=='l' && n>=5 && strncmp(azArg[0], "limits", n)==0 ){
3211
+ static const struct {
3212
+ const char *zLimitName; /* Name of a limit */
3213
+ int limitCode; /* Integer code for that limit */
3214
+ } aLimit[] = {
3215
+ { "length", SQLITE_LIMIT_LENGTH },
3216
+ { "sql_length", SQLITE_LIMIT_SQL_LENGTH },
3217
+ { "column", SQLITE_LIMIT_COLUMN },
3218
+ { "expr_depth", SQLITE_LIMIT_EXPR_DEPTH },
3219
+ { "compound_select", SQLITE_LIMIT_COMPOUND_SELECT },
3220
+ { "vdbe_op", SQLITE_LIMIT_VDBE_OP },
3221
+ { "function_arg", SQLITE_LIMIT_FUNCTION_ARG },
3222
+ { "attached", SQLITE_LIMIT_ATTACHED },
3223
+ { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
3224
+ { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
3225
+ { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
3226
+ { "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
3227
+ };
3228
+ int i, n2;
3229
+ open_db(p, 0);
3230
+ if( nArg==1 ){
3231
+ for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){
3232
+ printf("%20s %d\n", aLimit[i].zLimitName,
3233
+ sqlite3_limit(p->db, aLimit[i].limitCode, -1));
3234
+ }
3235
+ }else if( nArg>3 ){
3236
+ fprintf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
3237
+ rc = 1;
3238
+ goto meta_command_exit;
3239
+ }else{
3240
+ int iLimit = -1;
3241
+ n2 = strlen30(azArg[1]);
3242
+ for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){
3243
+ if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
3244
+ if( iLimit<0 ){
3245
+ iLimit = i;
3246
+ }else{
3247
+ fprintf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
3248
+ rc = 1;
3249
+ goto meta_command_exit;
3250
+ }
3251
+ }
3252
+ }
3253
+ if( iLimit<0 ){
3254
+ fprintf(stderr, "unknown limit: \"%s\"\n"
3255
+ "enter \".limits\" with no arguments for a list.\n",
3256
+ azArg[1]);
3257
+ rc = 1;
3258
+ goto meta_command_exit;
3259
+ }
3260
+ if( nArg==3 ){
3261
+ sqlite3_limit(p->db, aLimit[iLimit].limitCode, integerValue(azArg[2]));
3262
+ }
3263
+ printf("%20s %d\n", aLimit[iLimit].zLimitName,
3264
+ sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
3265
+ }
3266
+ }else
31683267
31693268
#ifndef SQLITE_OMIT_LOAD_EXTENSION
31703269
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
31713270
const char *zFile, *zProc;
31723271
char *zErrMsg = 0;
@@ -3648,11 +3747,11 @@
36483747
}
36493748
while( sqlite3_step(pStmt)==SQLITE_ROW ){
36503749
if( nRow>=nAlloc ){
36513750
char **azNew;
36523751
int n2 = nAlloc*2 + 10;
3653
- azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2);
3752
+ azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2);
36543753
if( azNew==0 ){
36553754
fprintf(stderr, "Error: out of memory\n");
36563755
break;
36573756
}
36583757
nAlloc = n2;
36593758
--- src/shell.c
+++ src/shell.c
@@ -988,11 +988,20 @@
988 break;
989 }
990 case MODE_Insert: {
991 p->cnt++;
992 if( azArg==0 ) break;
993 fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
 
 
 
 
 
 
 
 
 
994 for(i=0; i<nArg; i++){
995 char *zSep = i>0 ? ",": "";
996 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
997 fprintf(p->out,"%sNULL",zSep);
998 }else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1189,11 +1198,11 @@
1189 */
1190 static char *save_err_msg(
1191 sqlite3 *db /* Database to query */
1192 ){
1193 int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
1194 char *zErrMsg = sqlite3_malloc(nErrMsg);
1195 if( zErrMsg ){
1196 memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
1197 }
1198 return zErrMsg;
1199 }
@@ -1426,12 +1435,12 @@
1426 int p2op = (p2 + (iOp-iAddr));
1427
1428 /* Grow the p->aiIndent array as required */
1429 if( iOp>=nAlloc ){
1430 nAlloc += 100;
1431 p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int));
1432 abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int));
1433 }
1434 abYield[iOp] = str_in_array(zOp, azYield);
1435 p->aiIndent[iOp] = 0;
1436 p->nIndent = iOp+1;
1437
@@ -1544,11 +1553,11 @@
1544 if( SQLITE_ROW == rc ){
1545 /* if we have a callback... */
1546 if( xCallback ){
1547 /* allocate space for col name ptr, value ptr, and type */
1548 int nCol = sqlite3_column_count(pStmt);
1549 void *pData = sqlite3_malloc(3*nCol*sizeof(const char*) + 1);
1550 if( !pData ){
1551 rc = SQLITE_NOMEM;
1552 }else{
1553 char **azCols = (char **)pData; /* Names of result columns */
1554 char **azVals = &azCols[nCol]; /* Results */
@@ -1770,10 +1779,11 @@
1770 ** Text of a help message
1771 */
1772 static char zHelp[] =
1773 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1774 ".bail on|off Stop after hitting an error. Default OFF\n"
 
1775 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1776 ".databases List names and files of attached databases\n"
1777 ".dbinfo ?DB? Show status information about the database\n"
1778 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1779 " If TABLE specified, only dump tables matching\n"
@@ -1791,10 +1801,11 @@
1791 " If TABLE specified, only show indexes for tables\n"
1792 " matching LIKE pattern TABLE.\n"
1793 #ifdef SQLITE_ENABLE_IOTRACE
1794 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
1795 #endif
 
1796 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1797 ".load FILE ?ENTRY? Load an extension library\n"
1798 #endif
1799 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1800 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -1860,11 +1871,11 @@
1860 in = fopen(zName, "rb");
1861 if( in==0 ) return;
1862 fseek(in, 0, SEEK_END);
1863 nIn = ftell(in);
1864 rewind(in);
1865 pBuf = sqlite3_malloc( nIn );
1866 if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1867 sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
1868 }else{
1869 sqlite3_free(pBuf);
1870 }
@@ -1931,30 +1942,48 @@
1931 }
1932
1933 /*
1934 ** Do C-language style dequoting.
1935 **
 
 
1936 ** \t -> tab
1937 ** \n -> newline
 
 
1938 ** \r -> carriage return
 
1939 ** \" -> "
1940 ** \NNN -> ascii character NNN in octal
1941 ** \\ -> backslash
 
1942 */
1943 static void resolve_backslashes(char *z){
1944 int i, j;
1945 char c;
1946 while( *z && *z!='\\' ) z++;
1947 for(i=j=0; (c = z[i])!=0; i++, j++){
1948 if( c=='\\' && z[i+1]!=0 ){
1949 c = z[++i];
1950 if( c=='n' ){
1951 c = '\n';
 
 
1952 }else if( c=='t' ){
1953 c = '\t';
 
 
 
 
 
 
1954 }else if( c=='r' ){
1955 c = '\r';
 
 
 
 
1956 }else if( c=='\\' ){
1957 c = '\\';
1958 }else if( c>='0' && c<='7' ){
1959 c -= '0';
1960 if( z[i+1]>='0' && z[i+1]<='7' ){
@@ -2120,11 +2149,11 @@
2120
2121 /* Append a single byte to z[] */
2122 static void import_append_char(ImportCtx *p, int c){
2123 if( p->n+1>=p->nAlloc ){
2124 p->nAlloc += p->nAlloc + 100;
2125 p->z = sqlite3_realloc(p->z, p->nAlloc);
2126 if( p->z==0 ){
2127 fprintf(stderr, "out of memory\n");
2128 exit(1);
2129 }
2130 }
@@ -2134,11 +2163,11 @@
2134 /* Read a single field of CSV text. Compatible with rfc4180 and extended
2135 ** with the option of having a separator other than ",".
2136 **
2137 ** + Input comes from p->in.
2138 ** + Store results in p->z of length p->n. Space to hold p->z comes
2139 ** from sqlite3_malloc().
2140 ** + Use p->cSep as the column separator. The default is ",".
2141 ** + Use p->rSep as the row separator. The default is "\n".
2142 ** + Keep track of the line number in p->nLine.
2143 ** + Store the character that terminates the field in p->cTerm. Store
2144 ** EOF on end-of-file.
@@ -2208,11 +2237,11 @@
2208
2209 /* Read a single field of ASCII delimited text.
2210 **
2211 ** + Input comes from p->in.
2212 ** + Store results in p->z of length p->n. Space to hold p->z comes
2213 ** from sqlite3_malloc().
2214 ** + Use p->cSep as the column separator. The default is "\x1F".
2215 ** + Use p->rSep as the row separator. The default is "\x1E".
2216 ** + Keep track of the row number in p->nLine.
2217 ** + Store the character that terminates the field in p->cTerm. Store
2218 ** EOF on end-of-file.
@@ -2268,11 +2297,11 @@
2268 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2269 zQuery);
2270 goto end_data_xfer;
2271 }
2272 n = sqlite3_column_count(pQuery);
2273 zInsert = sqlite3_malloc(200 + nTable + n*3);
2274 if( zInsert==0 ){
2275 fprintf(stderr, "out of memory\n");
2276 goto end_data_xfer;
2277 }
2278 sqlite3_snprintf(200+nTable,zInsert,
@@ -2683,10 +2712,23 @@
2683 }else{
2684 fprintf(stderr, "Usage: .bail on|off\n");
2685 rc = 1;
2686 }
2687 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
2688
2689 /* The undocumented ".breakpoint" command causes a call to the no-op
2690 ** routine named test_breakpoint().
2691 */
2692 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
@@ -3023,11 +3065,11 @@
3023 }
3024 nCol = sqlite3_column_count(pStmt);
3025 sqlite3_finalize(pStmt);
3026 pStmt = 0;
3027 if( nCol==0 ) return 0; /* no columns, no error */
3028 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
3029 if( zSql==0 ){
3030 fprintf(stderr, "Error: out of memory\n");
3031 xCloser(sCtx.in);
3032 return 1;
3033 }
@@ -3163,10 +3205,67 @@
3163 sqlite3IoTrace = iotracePrintf;
3164 }
3165 }
3166 }else
3167 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3168
3169 #ifndef SQLITE_OMIT_LOAD_EXTENSION
3170 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
3171 const char *zFile, *zProc;
3172 char *zErrMsg = 0;
@@ -3648,11 +3747,11 @@
3648 }
3649 while( sqlite3_step(pStmt)==SQLITE_ROW ){
3650 if( nRow>=nAlloc ){
3651 char **azNew;
3652 int n2 = nAlloc*2 + 10;
3653 azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2);
3654 if( azNew==0 ){
3655 fprintf(stderr, "Error: out of memory\n");
3656 break;
3657 }
3658 nAlloc = n2;
3659
--- src/shell.c
+++ src/shell.c
@@ -988,11 +988,20 @@
988 break;
989 }
990 case MODE_Insert: {
991 p->cnt++;
992 if( azArg==0 ) break;
993 fprintf(p->out,"INSERT INTO %s",p->zDestTable);
994 if( p->showHeader ){
995 fprintf(p->out,"(");
996 for(i=0; i<nArg; i++){
997 char *zSep = i>0 ? ",": "";
998 fprintf(p->out, "%s%s", zSep, azCol[i]);
999 }
1000 fprintf(p->out,")");
1001 }
1002 fprintf(p->out," VALUES(");
1003 for(i=0; i<nArg; i++){
1004 char *zSep = i>0 ? ",": "";
1005 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
1006 fprintf(p->out,"%sNULL",zSep);
1007 }else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1189,11 +1198,11 @@
1198 */
1199 static char *save_err_msg(
1200 sqlite3 *db /* Database to query */
1201 ){
1202 int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
1203 char *zErrMsg = sqlite3_malloc64(nErrMsg);
1204 if( zErrMsg ){
1205 memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
1206 }
1207 return zErrMsg;
1208 }
@@ -1426,12 +1435,12 @@
1435 int p2op = (p2 + (iOp-iAddr));
1436
1437 /* Grow the p->aiIndent array as required */
1438 if( iOp>=nAlloc ){
1439 nAlloc += 100;
1440 p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int));
1441 abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int));
1442 }
1443 abYield[iOp] = str_in_array(zOp, azYield);
1444 p->aiIndent[iOp] = 0;
1445 p->nIndent = iOp+1;
1446
@@ -1544,11 +1553,11 @@
1553 if( SQLITE_ROW == rc ){
1554 /* if we have a callback... */
1555 if( xCallback ){
1556 /* allocate space for col name ptr, value ptr, and type */
1557 int nCol = sqlite3_column_count(pStmt);
1558 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1559 if( !pData ){
1560 rc = SQLITE_NOMEM;
1561 }else{
1562 char **azCols = (char **)pData; /* Names of result columns */
1563 char **azVals = &azCols[nCol]; /* Results */
@@ -1770,10 +1779,11 @@
1779 ** Text of a help message
1780 */
1781 static char zHelp[] =
1782 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1783 ".bail on|off Stop after hitting an error. Default OFF\n"
1784 ".binary on|off Turn binary output on or off. Default OFF\n"
1785 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1786 ".databases List names and files of attached databases\n"
1787 ".dbinfo ?DB? Show status information about the database\n"
1788 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1789 " If TABLE specified, only dump tables matching\n"
@@ -1791,10 +1801,11 @@
1801 " If TABLE specified, only show indexes for tables\n"
1802 " matching LIKE pattern TABLE.\n"
1803 #ifdef SQLITE_ENABLE_IOTRACE
1804 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
1805 #endif
1806 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n"
1807 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1808 ".load FILE ?ENTRY? Load an extension library\n"
1809 #endif
1810 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1811 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -1860,11 +1871,11 @@
1871 in = fopen(zName, "rb");
1872 if( in==0 ) return;
1873 fseek(in, 0, SEEK_END);
1874 nIn = ftell(in);
1875 rewind(in);
1876 pBuf = sqlite3_malloc64( nIn );
1877 if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1878 sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
1879 }else{
1880 sqlite3_free(pBuf);
1881 }
@@ -1931,30 +1942,48 @@
1942 }
1943
1944 /*
1945 ** Do C-language style dequoting.
1946 **
1947 ** \a -> alarm
1948 ** \b -> backspace
1949 ** \t -> tab
1950 ** \n -> newline
1951 ** \v -> vertical tab
1952 ** \f -> form feed
1953 ** \r -> carriage return
1954 ** \s -> space
1955 ** \" -> "
1956 ** \' -> '
1957 ** \\ -> backslash
1958 ** \NNN -> ascii character NNN in octal
1959 */
1960 static void resolve_backslashes(char *z){
1961 int i, j;
1962 char c;
1963 while( *z && *z!='\\' ) z++;
1964 for(i=j=0; (c = z[i])!=0; i++, j++){
1965 if( c=='\\' && z[i+1]!=0 ){
1966 c = z[++i];
1967 if( c=='a' ){
1968 c = '\a';
1969 }else if( c=='b' ){
1970 c = '\b';
1971 }else if( c=='t' ){
1972 c = '\t';
1973 }else if( c=='n' ){
1974 c = '\n';
1975 }else if( c=='v' ){
1976 c = '\v';
1977 }else if( c=='f' ){
1978 c = '\f';
1979 }else if( c=='r' ){
1980 c = '\r';
1981 }else if( c=='"' ){
1982 c = '"';
1983 }else if( c=='\'' ){
1984 c = '\'';
1985 }else if( c=='\\' ){
1986 c = '\\';
1987 }else if( c>='0' && c<='7' ){
1988 c -= '0';
1989 if( z[i+1]>='0' && z[i+1]<='7' ){
@@ -2120,11 +2149,11 @@
2149
2150 /* Append a single byte to z[] */
2151 static void import_append_char(ImportCtx *p, int c){
2152 if( p->n+1>=p->nAlloc ){
2153 p->nAlloc += p->nAlloc + 100;
2154 p->z = sqlite3_realloc64(p->z, p->nAlloc);
2155 if( p->z==0 ){
2156 fprintf(stderr, "out of memory\n");
2157 exit(1);
2158 }
2159 }
@@ -2134,11 +2163,11 @@
2163 /* Read a single field of CSV text. Compatible with rfc4180 and extended
2164 ** with the option of having a separator other than ",".
2165 **
2166 ** + Input comes from p->in.
2167 ** + Store results in p->z of length p->n. Space to hold p->z comes
2168 ** from sqlite3_malloc64().
2169 ** + Use p->cSep as the column separator. The default is ",".
2170 ** + Use p->rSep as the row separator. The default is "\n".
2171 ** + Keep track of the line number in p->nLine.
2172 ** + Store the character that terminates the field in p->cTerm. Store
2173 ** EOF on end-of-file.
@@ -2208,11 +2237,11 @@
2237
2238 /* Read a single field of ASCII delimited text.
2239 **
2240 ** + Input comes from p->in.
2241 ** + Store results in p->z of length p->n. Space to hold p->z comes
2242 ** from sqlite3_malloc64().
2243 ** + Use p->cSep as the column separator. The default is "\x1F".
2244 ** + Use p->rSep as the row separator. The default is "\x1E".
2245 ** + Keep track of the row number in p->nLine.
2246 ** + Store the character that terminates the field in p->cTerm. Store
2247 ** EOF on end-of-file.
@@ -2268,11 +2297,11 @@
2297 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2298 zQuery);
2299 goto end_data_xfer;
2300 }
2301 n = sqlite3_column_count(pQuery);
2302 zInsert = sqlite3_malloc64(200 + nTable + n*3);
2303 if( zInsert==0 ){
2304 fprintf(stderr, "out of memory\n");
2305 goto end_data_xfer;
2306 }
2307 sqlite3_snprintf(200+nTable,zInsert,
@@ -2683,10 +2712,23 @@
2712 }else{
2713 fprintf(stderr, "Usage: .bail on|off\n");
2714 rc = 1;
2715 }
2716 }else
2717
2718 if( c=='b' && n>=3 && strncmp(azArg[0], "binary", n)==0 ){
2719 if( nArg==2 ){
2720 if( booleanValue(azArg[1]) ){
2721 setBinaryMode(p->out);
2722 }else{
2723 setTextMode(p->out);
2724 }
2725 }else{
2726 fprintf(stderr, "Usage: .binary on|off\n");
2727 rc = 1;
2728 }
2729 }else
2730
2731 /* The undocumented ".breakpoint" command causes a call to the no-op
2732 ** routine named test_breakpoint().
2733 */
2734 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
@@ -3023,11 +3065,11 @@
3065 }
3066 nCol = sqlite3_column_count(pStmt);
3067 sqlite3_finalize(pStmt);
3068 pStmt = 0;
3069 if( nCol==0 ) return 0; /* no columns, no error */
3070 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
3071 if( zSql==0 ){
3072 fprintf(stderr, "Error: out of memory\n");
3073 xCloser(sCtx.in);
3074 return 1;
3075 }
@@ -3163,10 +3205,67 @@
3205 sqlite3IoTrace = iotracePrintf;
3206 }
3207 }
3208 }else
3209 #endif
3210 if( c=='l' && n>=5 && strncmp(azArg[0], "limits", n)==0 ){
3211 static const struct {
3212 const char *zLimitName; /* Name of a limit */
3213 int limitCode; /* Integer code for that limit */
3214 } aLimit[] = {
3215 { "length", SQLITE_LIMIT_LENGTH },
3216 { "sql_length", SQLITE_LIMIT_SQL_LENGTH },
3217 { "column", SQLITE_LIMIT_COLUMN },
3218 { "expr_depth", SQLITE_LIMIT_EXPR_DEPTH },
3219 { "compound_select", SQLITE_LIMIT_COMPOUND_SELECT },
3220 { "vdbe_op", SQLITE_LIMIT_VDBE_OP },
3221 { "function_arg", SQLITE_LIMIT_FUNCTION_ARG },
3222 { "attached", SQLITE_LIMIT_ATTACHED },
3223 { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
3224 { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
3225 { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
3226 { "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
3227 };
3228 int i, n2;
3229 open_db(p, 0);
3230 if( nArg==1 ){
3231 for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){
3232 printf("%20s %d\n", aLimit[i].zLimitName,
3233 sqlite3_limit(p->db, aLimit[i].limitCode, -1));
3234 }
3235 }else if( nArg>3 ){
3236 fprintf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
3237 rc = 1;
3238 goto meta_command_exit;
3239 }else{
3240 int iLimit = -1;
3241 n2 = strlen30(azArg[1]);
3242 for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){
3243 if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
3244 if( iLimit<0 ){
3245 iLimit = i;
3246 }else{
3247 fprintf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
3248 rc = 1;
3249 goto meta_command_exit;
3250 }
3251 }
3252 }
3253 if( iLimit<0 ){
3254 fprintf(stderr, "unknown limit: \"%s\"\n"
3255 "enter \".limits\" with no arguments for a list.\n",
3256 azArg[1]);
3257 rc = 1;
3258 goto meta_command_exit;
3259 }
3260 if( nArg==3 ){
3261 sqlite3_limit(p->db, aLimit[iLimit].limitCode, integerValue(azArg[2]));
3262 }
3263 printf("%20s %d\n", aLimit[iLimit].zLimitName,
3264 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
3265 }
3266 }else
3267
3268 #ifndef SQLITE_OMIT_LOAD_EXTENSION
3269 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
3270 const char *zFile, *zProc;
3271 char *zErrMsg = 0;
@@ -3648,11 +3747,11 @@
3747 }
3748 while( sqlite3_step(pStmt)==SQLITE_ROW ){
3749 if( nRow>=nAlloc ){
3750 char **azNew;
3751 int n2 = nAlloc*2 + 10;
3752 azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2);
3753 if( azNew==0 ){
3754 fprintf(stderr, "Error: out of memory\n");
3755 break;
3756 }
3757 nAlloc = n2;
3758
+1934 -728
--- 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.9. By combining all the individual C code files into this
3
+** version 3.8.10. 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.
@@ -68,10 +68,11 @@
6868
#if defined(_MSC_VER)
6969
#pragma warning(disable : 4054)
7070
#pragma warning(disable : 4055)
7171
#pragma warning(disable : 4100)
7272
#pragma warning(disable : 4127)
73
+#pragma warning(disable : 4130)
7374
#pragma warning(disable : 4152)
7475
#pragma warning(disable : 4189)
7576
#pragma warning(disable : 4206)
7677
#pragma warning(disable : 4210)
7778
#pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
315316
**
316317
** See also: [sqlite3_libversion()],
317318
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318319
** [sqlite_version()] and [sqlite_source_id()].
319320
*/
320
-#define SQLITE_VERSION "3.8.9"
321
-#define SQLITE_VERSION_NUMBER 3008009
322
-#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
321
+#define SQLITE_VERSION "3.8.10"
322
+#define SQLITE_VERSION_NUMBER 3008010
323
+#define SQLITE_SOURCE_ID "2015-05-07 11:53:08 cf975957b9ae671f34bb65f049acf351e650d437"
323324
324325
/*
325326
** CAPI3REF: Run-Time Library Version Numbers
326327
** KEYWORDS: sqlite3_version, sqlite3_sourceid
327328
**
@@ -474,10 +475,11 @@
474475
# define double sqlite3_int64
475476
#endif
476477
477478
/*
478479
** CAPI3REF: Closing A Database Connection
480
+** DESTRUCTOR: sqlite3
479481
**
480482
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
481483
** for the [sqlite3] object.
482484
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
483485
** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
525527
*/
526528
typedef int (*sqlite3_callback)(void*,int,char**, char**);
527529
528530
/*
529531
** CAPI3REF: One-Step Query Execution Interface
532
+** METHOD: sqlite3
530533
**
531534
** The sqlite3_exec() interface is a convenience wrapper around
532535
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
533536
** that allows an application to run multiple statements of SQL
534537
** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
15821585
*/
15831586
SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
15841587
15851588
/*
15861589
** CAPI3REF: Configure database connections
1590
+** METHOD: sqlite3
15871591
**
15881592
** The sqlite3_db_config() interface is used to make configuration
15891593
** changes to a [database connection]. The interface is similar to
15901594
** [sqlite3_config()] except that the changes apply to a single
15911595
** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
20792083
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
20802084
20812085
20822086
/*
20832087
** CAPI3REF: Enable Or Disable Extended Result Codes
2088
+** METHOD: sqlite3
20842089
**
20852090
** ^The sqlite3_extended_result_codes() routine enables or disables the
20862091
** [extended result codes] feature of SQLite. ^The extended result
20872092
** codes are disabled by default for historical compatibility.
20882093
*/
20892094
SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
20902095
20912096
/*
20922097
** CAPI3REF: Last Insert Rowid
2098
+** METHOD: sqlite3
20932099
**
20942100
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
20952101
** has a unique 64-bit signed
20962102
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
20972103
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
21392145
*/
21402146
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
21412147
21422148
/*
21432149
** CAPI3REF: Count The Number Of Rows Modified
2150
+** METHOD: sqlite3
21442151
**
21452152
** ^This function returns the number of rows modified, inserted or
21462153
** deleted by the most recently completed INSERT, UPDATE or DELETE
21472154
** statement on the database connection specified by the only parameter.
21482155
** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
21912198
*/
21922199
SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
21932200
21942201
/*
21952202
** CAPI3REF: Total Number Of Rows Modified
2203
+** METHOD: sqlite3
21962204
**
21972205
** ^This function returns the total number of rows inserted, modified or
21982206
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
21992207
** since the database connection was opened, including those executed as
22002208
** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
22142222
*/
22152223
SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
22162224
22172225
/*
22182226
** CAPI3REF: Interrupt A Long-Running Query
2227
+** METHOD: sqlite3
22192228
**
22202229
** ^This function causes any pending database operation to abort and
22212230
** return at its earliest opportunity. This routine is typically
22222231
** called in response to a user action such as pressing "Cancel"
22232232
** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
22902299
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
22912300
22922301
/*
22932302
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
22942303
** KEYWORDS: {busy-handler callback} {busy handler}
2304
+** METHOD: sqlite3
22952305
**
22962306
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
22972307
** that might be invoked with argument P whenever
22982308
** an attempt is made to access a database table associated with
22992309
** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
23492359
*/
23502360
SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
23512361
23522362
/*
23532363
** CAPI3REF: Set A Busy Timeout
2364
+** METHOD: sqlite3
23542365
**
23552366
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
23562367
** for a specified amount of time when a table is locked. ^The handler
23572368
** will sleep multiple times until at least "ms" milliseconds of sleeping
23582369
** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
23712382
*/
23722383
SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
23732384
23742385
/*
23752386
** CAPI3REF: Convenience Routines For Running Queries
2387
+** METHOD: sqlite3
23762388
**
23772389
** This is a legacy interface that is preserved for backwards compatibility.
23782390
** Use of this interface is not recommended.
23792391
**
23802392
** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
27062718
*/
27072719
SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
27082720
27092721
/*
27102722
** CAPI3REF: Compile-Time Authorization Callbacks
2723
+** METHOD: sqlite3
27112724
**
27122725
** ^This routine registers an authorizer callback with a particular
27132726
** [database connection], supplied in the first argument.
27142727
** ^The authorizer callback is invoked as SQL statements are being compiled
27152728
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
28622875
#define SQLITE_COPY 0 /* No longer used */
28632876
#define SQLITE_RECURSIVE 33 /* NULL NULL */
28642877
28652878
/*
28662879
** CAPI3REF: Tracing And Profiling Functions
2880
+** METHOD: sqlite3
28672881
**
28682882
** These routines register callback functions that can be used for
28692883
** tracing and profiling the execution of SQL statements.
28702884
**
28712885
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
28942908
SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
28952909
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
28962910
28972911
/*
28982912
** CAPI3REF: Query Progress Callbacks
2913
+** METHOD: sqlite3
28992914
**
29002915
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
29012916
** function X to be invoked periodically during long running calls to
29022917
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
29032918
** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
29272942
*/
29282943
SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
29292944
29302945
/*
29312946
** CAPI3REF: Opening A New Database Connection
2947
+** CONSTRUCTOR: sqlite3
29322948
**
29332949
** ^These routines open an SQLite database file as specified by the
29342950
** filename argument. ^The filename argument is interpreted as UTF-8 for
29352951
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
29362952
** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
32123228
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
32133229
32143230
32153231
/*
32163232
** CAPI3REF: Error Codes And Messages
3233
+** METHOD: sqlite3
32173234
**
32183235
** ^If the most recent sqlite3_* API call associated with
32193236
** [database connection] D failed, then the sqlite3_errcode(D) interface
32203237
** returns the numeric [result code] or [extended result code] for that
32213238
** API call.
@@ -3257,37 +3274,38 @@
32573274
SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
32583275
SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
32593276
SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
32603277
32613278
/*
3262
-** CAPI3REF: SQL Statement Object
3279
+** CAPI3REF: Prepared Statement Object
32633280
** KEYWORDS: {prepared statement} {prepared statements}
32643281
**
3265
-** An instance of this object represents a single SQL statement.
3266
-** This object is variously known as a "prepared statement" or a
3267
-** "compiled SQL statement" or simply as a "statement".
3282
+** An instance of this object represents a single SQL statement that
3283
+** has been compiled into binary form and is ready to be evaluated.
32683284
**
3269
-** The life of a statement object goes something like this:
3285
+** Think of each SQL statement as a separate computer program. The
3286
+** original SQL text is source code. A prepared statement object
3287
+** is the compiled object code. All SQL must be converted into a
3288
+** prepared statement before it can be run.
3289
+**
3290
+** The life-cycle of a prepared statement object usually goes like this:
32703291
**
32713292
** <ol>
3272
-** <li> Create the object using [sqlite3_prepare_v2()] or a related
3273
-** function.
3274
-** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3293
+** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3294
+** <li> Bind values to [parameters] using the sqlite3_bind_*()
32753295
** interfaces.
32763296
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3277
-** <li> Reset the statement using [sqlite3_reset()] then go back
3297
+** <li> Reset the prepared statement using [sqlite3_reset()] then go back
32783298
** to step 2. Do this zero or more times.
32793299
** <li> Destroy the object using [sqlite3_finalize()].
32803300
** </ol>
3281
-**
3282
-** Refer to documentation on individual methods above for additional
3283
-** information.
32843301
*/
32853302
typedef struct sqlite3_stmt sqlite3_stmt;
32863303
32873304
/*
32883305
** CAPI3REF: Run-time Limits
3306
+** METHOD: sqlite3
32893307
**
32903308
** ^(This interface allows the size of various constructs to be limited
32913309
** on a connection by connection basis. The first parameter is the
32923310
** [database connection] whose limit is to be set or queried. The
32933311
** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
33953413
#define SQLITE_LIMIT_WORKER_THREADS 11
33963414
33973415
/*
33983416
** CAPI3REF: Compiling An SQL Statement
33993417
** KEYWORDS: {SQL statement compiler}
3418
+** METHOD: sqlite3
3419
+** CONSTRUCTOR: sqlite3_stmt
34003420
**
34013421
** To execute an SQL query, it must first be compiled into a byte-code
34023422
** program using one of these routines.
34033423
**
34043424
** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
35023522
const void **pzTail /* OUT: Pointer to unused portion of zSql */
35033523
);
35043524
35053525
/*
35063526
** CAPI3REF: Retrieving Statement SQL
3527
+** METHOD: sqlite3_stmt
35073528
**
35083529
** ^This interface can be used to retrieve a saved copy of the original
35093530
** SQL text used to create a [prepared statement] if that statement was
35103531
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
35113532
*/
35123533
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
35133534
35143535
/*
35153536
** CAPI3REF: Determine If An SQL Statement Writes The Database
3537
+** METHOD: sqlite3_stmt
35163538
**
35173539
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
35183540
** and only if the [prepared statement] X makes no direct changes to
35193541
** the content of the database file.
35203542
**
@@ -3542,10 +3564,11 @@
35423564
*/
35433565
SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
35443566
35453567
/*
35463568
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3569
+** METHOD: sqlite3_stmt
35473570
**
35483571
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
35493572
** [prepared statement] S has been stepped at least once using
35503573
** [sqlite3_step(S)] but has not run to completion and/or has not
35513574
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
36163639
36173640
/*
36183641
** CAPI3REF: Binding Values To Prepared Statements
36193642
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
36203643
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3644
+** METHOD: sqlite3_stmt
36213645
**
36223646
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
36233647
** literals may be replaced by a [parameter] that matches one of following
36243648
** templates:
36253649
**
@@ -3734,10 +3758,11 @@
37343758
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
37353759
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
37363760
37373761
/*
37383762
** CAPI3REF: Number Of SQL Parameters
3763
+** METHOD: sqlite3_stmt
37393764
**
37403765
** ^This routine can be used to find the number of [SQL parameters]
37413766
** in a [prepared statement]. SQL parameters are tokens of the
37423767
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
37433768
** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
37543779
*/
37553780
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
37563781
37573782
/*
37583783
** CAPI3REF: Name Of A Host Parameter
3784
+** METHOD: sqlite3_stmt
37593785
**
37603786
** ^The sqlite3_bind_parameter_name(P,N) interface returns
37613787
** the name of the N-th [SQL parameter] in the [prepared statement] P.
37623788
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
37633789
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
37813807
*/
37823808
SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
37833809
37843810
/*
37853811
** CAPI3REF: Index Of A Parameter With A Given Name
3812
+** METHOD: sqlite3_stmt
37863813
**
37873814
** ^Return the index of an SQL parameter given its name. ^The
37883815
** index value returned is suitable for use as the second
37893816
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
37903817
** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
37973824
*/
37983825
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
37993826
38003827
/*
38013828
** CAPI3REF: Reset All Bindings On A Prepared Statement
3829
+** METHOD: sqlite3_stmt
38023830
**
38033831
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
38043832
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
38053833
** ^Use this routine to reset all host parameters to NULL.
38063834
*/
38073835
SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
38083836
38093837
/*
38103838
** CAPI3REF: Number Of Columns In A Result Set
3839
+** METHOD: sqlite3_stmt
38113840
**
38123841
** ^Return the number of columns in the result set returned by the
38133842
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
38143843
** statement that does not return data (for example an [UPDATE]).
38153844
**
@@ -3817,10 +3846,11 @@
38173846
*/
38183847
SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
38193848
38203849
/*
38213850
** CAPI3REF: Column Names In A Result Set
3851
+** METHOD: sqlite3_stmt
38223852
**
38233853
** ^These routines return the name assigned to a particular column
38243854
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
38253855
** interface returns a pointer to a zero-terminated UTF-8 string
38263856
** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
38463876
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
38473877
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
38483878
38493879
/*
38503880
** CAPI3REF: Source Of Data In A Query Result
3881
+** METHOD: sqlite3_stmt
38513882
**
38523883
** ^These routines provide a means to determine the database, table, and
38533884
** table column that is the origin of a particular result column in
38543885
** [SELECT] statement.
38553886
** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
38983929
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
38993930
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
39003931
39013932
/*
39023933
** CAPI3REF: Declared Datatype Of A Query Result
3934
+** METHOD: sqlite3_stmt
39033935
**
39043936
** ^(The first parameter is a [prepared statement].
39053937
** If this statement is a [SELECT] statement and the Nth column of the
39063938
** returned result set of that [SELECT] is a table column (not an
39073939
** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
39303962
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
39313963
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
39323964
39333965
/*
39343966
** CAPI3REF: Evaluate An SQL Statement
3967
+** METHOD: sqlite3_stmt
39353968
**
39363969
** After a [prepared statement] has been prepared using either
39373970
** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
39383971
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
39393972
** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
40094042
*/
40104043
SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
40114044
40124045
/*
40134046
** CAPI3REF: Number of columns in a result set
4047
+** METHOD: sqlite3_stmt
40144048
**
40154049
** ^The sqlite3_data_count(P) interface returns the number of columns in the
40164050
** current row of the result set of [prepared statement] P.
40174051
** ^If prepared statement P does not have results ready to return
40184052
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
40624096
#define SQLITE3_TEXT 3
40634097
40644098
/*
40654099
** CAPI3REF: Result Values From A Query
40664100
** KEYWORDS: {column access functions}
4101
+** METHOD: sqlite3_stmt
40674102
**
40684103
** These routines form the "result set" interface.
40694104
**
40704105
** ^These routines return information about a single column of the current
40714106
** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
42344269
SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
42354270
SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
42364271
42374272
/*
42384273
** CAPI3REF: Destroy A Prepared Statement Object
4274
+** DESTRUCTOR: sqlite3_stmt
42394275
**
42404276
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
42414277
** ^If the most recent evaluation of the statement encountered no errors
42424278
** or if the statement is never been evaluated, then sqlite3_finalize() returns
42434279
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
42614297
*/
42624298
SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
42634299
42644300
/*
42654301
** CAPI3REF: Reset A Prepared Statement Object
4302
+** METHOD: sqlite3_stmt
42664303
**
42674304
** The sqlite3_reset() function is called to reset a [prepared statement]
42684305
** object back to its initial state, ready to be re-executed.
42694306
** ^Any SQL statement variables that had values bound to them using
42704307
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
42904327
/*
42914328
** CAPI3REF: Create Or Redefine SQL Functions
42924329
** KEYWORDS: {function creation routines}
42934330
** KEYWORDS: {application-defined SQL function}
42944331
** KEYWORDS: {application-defined SQL functions}
4332
+** METHOD: sqlite3
42954333
**
42964334
** ^These functions (collectively known as "function creation routines")
42974335
** are used to add SQL functions or aggregates or to redefine the behavior
42984336
** of existing SQL functions or aggregates. The only differences between
42994337
** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
44594497
void*,sqlite3_int64);
44604498
#endif
44614499
44624500
/*
44634501
** CAPI3REF: Obtaining SQL Function Parameter Values
4502
+** METHOD: sqlite3_value
44644503
**
44654504
** The C-language implementation of SQL functions and aggregates uses
44664505
** this set of interface routines to access the parameter values on
44674506
** the function or aggregate.
44684507
**
@@ -4517,10 +4556,11 @@
45174556
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
45184557
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
45194558
45204559
/*
45214560
** CAPI3REF: Obtain Aggregate Function Context
4561
+** METHOD: sqlite3_context
45224562
**
45234563
** Implementations of aggregate SQL functions use this
45244564
** routine to allocate memory for storing their state.
45254565
**
45264566
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
45614601
*/
45624602
SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
45634603
45644604
/*
45654605
** CAPI3REF: User Data For Functions
4606
+** METHOD: sqlite3_context
45664607
**
45674608
** ^The sqlite3_user_data() interface returns a copy of
45684609
** the pointer that was the pUserData parameter (the 5th parameter)
45694610
** of the [sqlite3_create_function()]
45704611
** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
45754616
*/
45764617
SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
45774618
45784619
/*
45794620
** CAPI3REF: Database Connection For Functions
4621
+** METHOD: sqlite3_context
45804622
**
45814623
** ^The sqlite3_context_db_handle() interface returns a copy of
45824624
** the pointer to the [database connection] (the 1st parameter)
45834625
** of the [sqlite3_create_function()]
45844626
** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
45864628
*/
45874629
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
45884630
45894631
/*
45904632
** CAPI3REF: Function Auxiliary Data
4633
+** METHOD: sqlite3_context
45914634
**
45924635
** These functions may be used by (non-aggregate) SQL functions to
45934636
** associate metadata with argument values. If the same value is passed to
45944637
** multiple invocations of the same SQL function during query execution, under
45954638
** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
46584701
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
46594702
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
46604703
46614704
/*
46624705
** CAPI3REF: Setting The Result Of An SQL Function
4706
+** METHOD: sqlite3_context
46634707
**
46644708
** These routines are used by the xFunc or xFinal callbacks that
46654709
** implement SQL functions and aggregates. See
46664710
** [sqlite3_create_function()] and [sqlite3_create_function16()]
46674711
** for additional information.
@@ -4793,10 +4837,11 @@
47934837
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
47944838
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
47954839
47964840
/*
47974841
** CAPI3REF: Define New Collating Sequences
4842
+** METHOD: sqlite3
47984843
**
47994844
** ^These functions add, remove, or modify a [collation] associated
48004845
** with the [database connection] specified as the first argument.
48014846
**
48024847
** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
48954940
int(*xCompare)(void*,int,const void*,int,const void*)
48964941
);
48974942
48984943
/*
48994944
** CAPI3REF: Collation Needed Callbacks
4945
+** METHOD: sqlite3
49004946
**
49014947
** ^To avoid having to register all collation sequences before a database
49024948
** can be used, a single callback function may be registered with the
49034949
** [database connection] to be invoked whenever an undefined collation
49044950
** sequence is required.
@@ -5102,10 +5148,11 @@
51025148
SQLITE_API char *sqlite3_data_directory;
51035149
51045150
/*
51055151
** CAPI3REF: Test For Auto-Commit Mode
51065152
** KEYWORDS: {autocommit mode}
5153
+** METHOD: sqlite3
51075154
**
51085155
** ^The sqlite3_get_autocommit() interface returns non-zero or
51095156
** zero if the given database connection is or is not in autocommit mode,
51105157
** respectively. ^Autocommit mode is on by default.
51115158
** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
51245171
*/
51255172
SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
51265173
51275174
/*
51285175
** CAPI3REF: Find The Database Handle Of A Prepared Statement
5176
+** METHOD: sqlite3_stmt
51295177
**
51305178
** ^The sqlite3_db_handle interface returns the [database connection] handle
51315179
** to which a [prepared statement] belongs. ^The [database connection]
51325180
** returned by sqlite3_db_handle is the same [database connection]
51335181
** that was the first argument
@@ -5136,10 +5184,11 @@
51365184
*/
51375185
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
51385186
51395187
/*
51405188
** CAPI3REF: Return The Filename For A Database Connection
5189
+** METHOD: sqlite3
51415190
**
51425191
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
51435192
** associated with database N of connection D. ^The main database file
51445193
** has the name "main". If there is no attached database N on the database
51455194
** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
51525201
*/
51535202
SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
51545203
51555204
/*
51565205
** CAPI3REF: Determine if a database is read-only
5206
+** METHOD: sqlite3
51575207
**
51585208
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
51595209
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
51605210
** the name of a database on connection D.
51615211
*/
51625212
SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
51635213
51645214
/*
51655215
** CAPI3REF: Find the next prepared statement
5216
+** METHOD: sqlite3
51665217
**
51675218
** ^This interface returns a pointer to the next [prepared statement] after
51685219
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
51695220
** then this interface returns a pointer to the first prepared statement
51705221
** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
51765227
*/
51775228
SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
51785229
51795230
/*
51805231
** CAPI3REF: Commit And Rollback Notification Callbacks
5232
+** METHOD: sqlite3
51815233
**
51825234
** ^The sqlite3_commit_hook() interface registers a callback
51835235
** function to be invoked whenever a transaction is [COMMIT | committed].
51845236
** ^Any callback set by a previous call to sqlite3_commit_hook()
51855237
** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
52255277
SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
52265278
SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
52275279
52285280
/*
52295281
** CAPI3REF: Data Change Notification Callbacks
5282
+** METHOD: sqlite3
52305283
**
52315284
** ^The sqlite3_update_hook() interface registers a callback function
52325285
** with the [database connection] identified by the first argument
52335286
** to be invoked whenever a row is updated, inserted or deleted in
52345287
** a rowid table.
@@ -5331,10 +5384,11 @@
53315384
*/
53325385
SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
53335386
53345387
/*
53355388
** CAPI3REF: Free Memory Used By A Database Connection
5389
+** METHOD: sqlite3
53365390
**
53375391
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
53385392
** memory as possible from database connection D. Unlike the
53395393
** [sqlite3_release_memory()] interface, this interface is in effect even
53405394
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
54085462
SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
54095463
54105464
54115465
/*
54125466
** CAPI3REF: Extract Metadata About A Column Of A Table
5467
+** METHOD: sqlite3
54135468
**
54145469
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
54155470
** information about column C of table T in database D
54165471
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
54175472
** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
54865541
int *pAutoinc /* OUTPUT: True if column is auto-increment */
54875542
);
54885543
54895544
/*
54905545
** CAPI3REF: Load An Extension
5546
+** METHOD: sqlite3
54915547
**
54925548
** ^This interface loads an SQLite extension library from the named file.
54935549
**
54945550
** ^The sqlite3_load_extension() interface attempts to load an
54955551
** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
55275583
char **pzErrMsg /* Put error message here if not 0 */
55285584
);
55295585
55305586
/*
55315587
** CAPI3REF: Enable Or Disable Extension Loading
5588
+** METHOD: sqlite3
55325589
**
55335590
** ^So as not to open security holes in older applications that are
55345591
** unprepared to deal with [extension loading], and as a means of disabling
55355592
** [extension loading] while evaluating user-entered SQL, the following API
55365593
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
57765833
#define SQLITE_INDEX_CONSTRAINT_GE 32
57775834
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
57785835
57795836
/*
57805837
** CAPI3REF: Register A Virtual Table Implementation
5838
+** METHOD: sqlite3
57815839
**
57825840
** ^These routines are used to register a new [virtual table module] name.
57835841
** ^Module names must be registered before
57845842
** creating a new [virtual table] using the module and before using a
57855843
** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
58725930
*/
58735931
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
58745932
58755933
/*
58765934
** CAPI3REF: Overload A Function For A Virtual Table
5935
+** METHOD: sqlite3
58775936
**
58785937
** ^(Virtual tables can provide alternative implementations of functions
58795938
** using the [xFindFunction] method of the [virtual table module].
58805939
** But global versions of those functions
58815940
** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
59145973
*/
59155974
typedef struct sqlite3_blob sqlite3_blob;
59165975
59175976
/*
59185977
** CAPI3REF: Open A BLOB For Incremental I/O
5978
+** METHOD: sqlite3
5979
+** CONSTRUCTOR: sqlite3_blob
59195980
**
59205981
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
59215982
** in row iRow, column zColumn, table zTable in database zDb;
59225983
** in other words, the same BLOB that would be selected by:
59235984
**
@@ -5995,10 +6056,11 @@
59956056
sqlite3_blob **ppBlob
59966057
);
59976058
59986059
/*
59996060
** CAPI3REF: Move a BLOB Handle to a New Row
6061
+** METHOD: sqlite3_blob
60006062
**
60016063
** ^This function is used to move an existing blob handle so that it points
60026064
** to a different row of the same database table. ^The new row is identified
60036065
** by the rowid value passed as the second argument. Only the row can be
60046066
** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
60196081
*/
60206082
SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
60216083
60226084
/*
60236085
** CAPI3REF: Close A BLOB Handle
6086
+** DESTRUCTOR: sqlite3_blob
60246087
**
60256088
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
60266089
** unconditionally. Even if this routine returns an error code, the
60276090
** handle is still closed.)^
60286091
**
@@ -6041,10 +6104,11 @@
60416104
*/
60426105
SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
60436106
60446107
/*
60456108
** CAPI3REF: Return The Size Of An Open BLOB
6109
+** METHOD: sqlite3_blob
60466110
**
60476111
** ^Returns the size in bytes of the BLOB accessible via the
60486112
** successfully opened [BLOB handle] in its only argument. ^The
60496113
** incremental blob I/O routines can only read or overwriting existing
60506114
** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
60566120
*/
60576121
SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
60586122
60596123
/*
60606124
** CAPI3REF: Read Data From A BLOB Incrementally
6125
+** METHOD: sqlite3_blob
60616126
**
60626127
** ^(This function is used to read data from an open [BLOB handle] into a
60636128
** caller-supplied buffer. N bytes of data are copied into buffer Z
60646129
** from the open BLOB, starting at offset iOffset.)^
60656130
**
@@ -6084,10 +6149,11 @@
60846149
*/
60856150
SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
60866151
60876152
/*
60886153
** CAPI3REF: Write Data Into A BLOB Incrementally
6154
+** METHOD: sqlite3_blob
60896155
**
60906156
** ^(This function is used to write data into an open [BLOB handle] from a
60916157
** caller-supplied buffer. N bytes of data are copied from the buffer Z
60926158
** into the open BLOB, starting at offset iOffset.)^
60936159
**
@@ -6411,10 +6477,11 @@
64116477
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
64126478
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
64136479
64146480
/*
64156481
** CAPI3REF: Retrieve the mutex for a database connection
6482
+** METHOD: sqlite3
64166483
**
64176484
** ^This interface returns a pointer the [sqlite3_mutex] object that
64186485
** serializes access to the [database connection] given in the argument
64196486
** when the [threading mode] is Serialized.
64206487
** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
64226489
*/
64236490
SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
64246491
64256492
/*
64266493
** CAPI3REF: Low-Level Control Of Database Files
6494
+** METHOD: sqlite3
64276495
**
64286496
** ^The [sqlite3_file_control()] interface makes a direct call to the
64296497
** xFileControl method for the [sqlite3_io_methods] object associated
64306498
** with a particular database identified by the second argument. ^The
64316499
** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
66386706
#define SQLITE_STATUS_SCRATCH_SIZE 8
66396707
#define SQLITE_STATUS_MALLOC_COUNT 9
66406708
66416709
/*
66426710
** CAPI3REF: Database Connection Status
6711
+** METHOD: sqlite3
66436712
**
66446713
** ^This interface is used to retrieve runtime status information
66456714
** about a single [database connection]. ^The first argument is the
66466715
** database connection object to be interrogated. ^The second argument
66476716
** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
67666835
#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
67676836
67686837
67696838
/*
67706839
** CAPI3REF: Prepared Statement Status
6840
+** METHOD: sqlite3_stmt
67716841
**
67726842
** ^(Each prepared statement maintains various
67736843
** [SQLITE_STMTSTATUS counters] that measure the number
67746844
** of times it has performed specific operations.)^ These counters can
67756845
** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
72697339
SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
72707340
SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
72717341
72727342
/*
72737343
** CAPI3REF: Unlock Notification
7344
+** METHOD: sqlite3
72747345
**
72757346
** ^When running in shared-cache mode, a database operation may fail with
72767347
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
72777348
** individual tables within the shared-cache cannot be obtained. See
72787349
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
74397510
*/
74407511
SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
74417512
74427513
/*
74437514
** CAPI3REF: Write-Ahead Log Commit Hook
7515
+** METHOD: sqlite3
74447516
**
74457517
** ^The [sqlite3_wal_hook()] function is used to register a callback that
74467518
** is invoked each time data is committed to a database in wal mode.
74477519
**
74487520
** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
74787550
void*
74797551
);
74807552
74817553
/*
74827554
** CAPI3REF: Configure an auto-checkpoint
7555
+** METHOD: sqlite3
74837556
**
74847557
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
74857558
** [sqlite3_wal_hook()] that causes any database on [database connection] D
74867559
** to automatically [checkpoint]
74877560
** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
75087581
*/
75097582
SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
75107583
75117584
/*
75127585
** CAPI3REF: Checkpoint a database
7586
+** METHOD: sqlite3
75137587
**
75147588
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
75157589
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
75167590
**
75177591
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
75297603
*/
75307604
SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
75317605
75327606
/*
75337607
** CAPI3REF: Checkpoint a database
7608
+** METHOD: sqlite3
75347609
**
75357610
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
75367611
** operation on database X of [database connection] D in mode M. Status
75377612
** information is written back into integers pointed to by L and C.)^
75387613
** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
77837858
#define SQLITE_SCANSTAT_EXPLAIN 4
77847859
#define SQLITE_SCANSTAT_SELECTID 5
77857860
77867861
/*
77877862
** CAPI3REF: Prepared Statement Scan Status
7863
+** METHOD: sqlite3_stmt
77887864
**
77897865
** This interface returns information about the predicted and measured
77907866
** performance for pStmt. Advanced applications can use this
77917867
** interface to compare the predicted and the measured performance and
77927868
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
78207896
void *pOut /* Result written here */
78217897
);
78227898
78237899
/*
78247900
** CAPI3REF: Zero Scan-Status Counters
7901
+** METHOD: sqlite3_stmt
78257902
**
78267903
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
78277904
**
78287905
** This API is only available if the library is built with pre-processor
78297906
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
84308507
#else
84318508
# define ALWAYS(X) (X)
84328509
# define NEVER(X) (X)
84338510
#endif
84348511
8512
+/*
8513
+** Declarations used for tracing the operating system interfaces.
8514
+*/
8515
+#if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
8516
+ (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8517
+ extern int sqlite3OSTrace;
8518
+# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
8519
+# define SQLITE_HAVE_OS_TRACE
8520
+#else
8521
+# define OSTRACE(X)
8522
+# undef SQLITE_HAVE_OS_TRACE
8523
+#endif
8524
+
8525
+/*
8526
+** Is the sqlite3ErrName() function needed in the build? Currently,
8527
+** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
8528
+** OSTRACE is enabled), and by several "test*.c" files (which are
8529
+** compiled using SQLITE_TEST).
8530
+*/
8531
+#if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \
8532
+ (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8533
+# define SQLITE_NEED_ERR_NAME
8534
+#else
8535
+# undef SQLITE_NEED_ERR_NAME
8536
+#endif
8537
+
84358538
/*
84368539
** Return true (non-zero) if the input is an integer that is too large
84378540
** to fit in 32-bits. This macro is used inside of various testcase()
84388541
** macros to verify that we have tested SQLite for large-file support.
84398542
*/
@@ -9841,37 +9944,36 @@
98419944
/* Properties such as "out2" or "jump" that are specified in
98429945
** comments following the "case" for each opcode in the vdbe.c
98439946
** are encoded into bitvectors as follows:
98449947
*/
98459948
#define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9846
-#define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
9847
-#define OPFLG_IN1 0x0004 /* in1: P1 is an input */
9848
-#define OPFLG_IN2 0x0008 /* in2: P2 is an input */
9849
-#define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9850
-#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9851
-#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9949
+#define OPFLG_IN1 0x0002 /* in1: P1 is an input */
9950
+#define OPFLG_IN2 0x0004 /* in2: P2 is an input */
9951
+#define OPFLG_IN3 0x0008 /* in3: P3 is an input */
9952
+#define OPFLG_OUT2 0x0010 /* out2: P2 is an output */
9953
+#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
98529954
#define OPFLG_INITIALIZER {\
98539955
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9854
-/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9855
-/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9856
-/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9857
-/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9858
-/* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\
9859
-/* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\
9860
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\
9861
-/* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\
9862
-/* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\
9863
-/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9864
-/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9865
-/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9866
-/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9867
-/* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9868
-/* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9869
-/* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9870
-/* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9956
+/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
9957
+/* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\
9958
+/* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\
9959
+/* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\
9960
+/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
9961
+/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\
9962
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\
9963
+/* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\
9964
+/* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
9965
+/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
9966
+/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
9967
+/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
9968
+/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
9969
+/* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\
9970
+/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9971
+/* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\
9972
+/* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\
98719973
/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9872
-/* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9974
+/* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,}
98739975
98749976
/************** End of opcodes.h *********************************************/
98759977
/************** Continuing where we left off in vdbe.h ***********************/
98769978
98779979
/*
@@ -9926,10 +10028,11 @@
992610028
#endif
992710029
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
992810030
992910031
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
993010032
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
10033
+SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
993110034
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
993210035
993310036
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
993410037
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
993510038
@@ -11063,10 +11166,11 @@
1106311166
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
1106411167
#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
1106511168
#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
1106611169
#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
1106711170
#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
11171
+#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
1106811172
1106911173
1107011174
/*
1107111175
** Bits of the sqlite3.dbOptFlags field that are used by the
1107211176
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
1139311497
int iSavepoint; /* Depth of the SAVEPOINT stack */
1139411498
VTable *pNext; /* Next in linked list (see above) */
1139511499
};
1139611500
1139711501
/*
11398
-** Each SQL table is represented in memory by an instance of the
11399
-** following structure.
11400
-**
11401
-** Table.zName is the name of the table. The case of the original
11402
-** CREATE TABLE statement is stored, but case is not significant for
11403
-** comparisons.
11404
-**
11405
-** Table.nCol is the number of columns in this table. Table.aCol is a
11406
-** pointer to an array of Column structures, one for each column.
11407
-**
11408
-** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
11409
-** the column that is that key. Otherwise Table.iPKey is negative. Note
11410
-** that the datatype of the PRIMARY KEY must be INTEGER for this field to
11411
-** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
11412
-** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
11413
-** is generated for each row of the table. TF_HasPrimaryKey is set if
11414
-** the table has any PRIMARY KEY, INTEGER or otherwise.
11415
-**
11416
-** Table.tnum is the page number for the root BTree page of the table in the
11417
-** database file. If Table.iDb is the index of the database table backend
11418
-** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
11419
-** holds temporary tables and indices. If TF_Ephemeral is set
11420
-** then the table is stored in a file that is automatically deleted
11421
-** when the VDBE cursor to the table is closed. In this case Table.tnum
11422
-** refers VDBE cursor number that holds the table open, not to the root
11423
-** page number. Transient tables are used to hold the results of a
11424
-** sub-query that appears instead of a real table name in the FROM clause
11425
-** of a SELECT statement.
11502
+** The schema for each SQL table and view is represented in memory
11503
+** by an instance of the following structure.
1142611504
*/
1142711505
struct Table {
1142811506
char *zName; /* Name of the table or view */
1142911507
Column *aCol; /* Information about each column */
1143011508
Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
1143211510
FKey *pFKey; /* Linked list of all foreign keys in this table */
1143311511
char *zColAff; /* String defining the affinity of each column */
1143411512
#ifndef SQLITE_OMIT_CHECK
1143511513
ExprList *pCheck; /* All CHECK constraints */
1143611514
#endif
11437
- LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11438
- int tnum; /* Root BTree node for this table (see note above) */
11439
- i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
11515
+ int tnum; /* Root BTree page for this table */
11516
+ i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1144011517
i16 nCol; /* Number of columns in this table */
1144111518
u16 nRef; /* Number of pointers to this Table */
11519
+ LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
1144211520
LogEst szTabRow; /* Estimated size of each table row in bytes */
1144311521
#ifdef SQLITE_ENABLE_COSTMULT
1144411522
LogEst costMult; /* Cost multiplier for using this table */
1144511523
#endif
1144611524
u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
1145811536
Table *pNextZombie; /* Next on the Parse.pZombieTab list */
1145911537
};
1146011538
1146111539
/*
1146211540
** Allowed values for Table.tabFlags.
11541
+**
11542
+** TF_OOOHidden applies to virtual tables that have hidden columns that are
11543
+** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
11544
+** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
11545
+** the TF_OOOHidden attribute would apply in this case. Such tables require
11546
+** special handling during INSERT processing.
1146311547
*/
1146411548
#define TF_Readonly 0x01 /* Read-only system table */
1146511549
#define TF_Ephemeral 0x02 /* An ephemeral table */
1146611550
#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
1146711551
#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
1146811552
#define TF_Virtual 0x10 /* Is a virtual table */
1146911553
#define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
11554
+#define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */
1147011555
1147111556
1147211557
/*
1147311558
** Test to see whether or not a table is a virtual table. This is
1147411559
** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
1222112306
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1222212307
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1222312308
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
1222412309
#define SF_Compound 0x0040 /* Part of a compound query */
1222512310
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
12226
-#define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12311
+#define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */
1222712312
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1222812313
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1222912314
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
1223012315
#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
1223112316
#define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
1260512690
*
1260612691
* (op == TK_INSERT)
1260712692
* orconf -> stores the ON CONFLICT algorithm
1260812693
* pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
1260912694
* this stores a pointer to the SELECT statement. Otherwise NULL.
12610
- * target -> A token holding the quoted name of the table to insert into.
12695
+ * zTarget -> Dequoted name of the table to insert into.
1261112696
* pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
1261212697
* this stores values to be inserted. Otherwise NULL.
1261312698
* pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
1261412699
* statement, then this stores the column-names to be
1261512700
* inserted into.
1261612701
*
1261712702
* (op == TK_DELETE)
12618
- * target -> A token holding the quoted name of the table to delete from.
12703
+ * zTarget -> Dequoted name of the table to delete from.
1261912704
* pWhere -> The WHERE clause of the DELETE statement if one is specified.
1262012705
* Otherwise NULL.
1262112706
*
1262212707
* (op == TK_UPDATE)
12623
- * target -> A token holding the quoted name of the table to update rows of.
12708
+ * zTarget -> Dequoted name of the table to update.
1262412709
* pWhere -> The WHERE clause of the UPDATE statement if one is specified.
1262512710
* Otherwise NULL.
1262612711
* pExprList -> A list of the columns to update and the expressions to update
1262712712
* them to. See sqlite3Update() documentation of "pChanges"
1262812713
* argument.
@@ -12630,12 +12715,12 @@
1263012715
*/
1263112716
struct TriggerStep {
1263212717
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
1263312718
u8 orconf; /* OE_Rollback etc. */
1263412719
Trigger *pTrig; /* The trigger that this step is a part of */
12635
- Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
12636
- Token target; /* Target table for DELETE, UPDATE, INSERT */
12720
+ Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
12721
+ char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
1263712722
Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
1263812723
ExprList *pExprList; /* SET clause for UPDATE. */
1263912724
IdList *pIdList; /* Column names for INSERT */
1264012725
TriggerStep *pNext; /* Next in the link-list */
1264112726
TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
1266412749
sqlite3 *db; /* Optional database for lookaside. Can be NULL */
1266512750
char *zBase; /* A base allocation. Not from malloc. */
1266612751
char *zText; /* The string collected so far */
1266712752
int nChar; /* Length of the string so far */
1266812753
int nAlloc; /* Amount of space allocated in zText */
12669
- int mxAlloc; /* Maximum allowed string length */
12670
- u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
12754
+ int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
1267112755
u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
1267212756
};
1267312757
#define STRACCUM_NOMEM 1
1267412758
#define STRACCUM_TOOBIG 2
1267512759
@@ -12982,11 +13066,11 @@
1298213066
SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
1298313067
SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
1298413068
SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
1298513069
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
1298613070
SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12987
-#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
13071
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
1298813072
SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
1298913073
#endif
1299013074
#if defined(SQLITE_TEST)
1299113075
SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
1299213076
#endif
@@ -13329,11 +13413,11 @@
1332913413
SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
1333013414
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
1333113415
SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
1333213416
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1333313417
13334
-#if defined(SQLITE_TEST)
13418
+#if defined(SQLITE_NEED_ERR_NAME)
1333513419
SQLITE_PRIVATE const char *sqlite3ErrName(int);
1333613420
#endif
1333713421
1333813422
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1333913423
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
1342313507
FuncDestructor *pDestructor
1342413508
);
1342513509
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1342613510
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1342713511
13428
-SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13512
+SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
1342913513
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
1343013514
SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
1343113515
SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
1343213516
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
1343313517
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -19807,20 +19891,10 @@
1980719891
*/
1980819892
#ifdef MEMORY_DEBUG
1980919893
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
1981019894
#endif
1981119895
19812
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19813
-# ifndef SQLITE_DEBUG_OS_TRACE
19814
-# define SQLITE_DEBUG_OS_TRACE 0
19815
-# endif
19816
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19817
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19818
-#else
19819
-# define OSTRACE(X)
19820
-#endif
19821
-
1982219896
/*
1982319897
** Macros for performance tracing. Normally turned off. Only works
1982419898
** on i486 hardware.
1982519899
*/
1982619900
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21475,11 @@
2140121475
2140221476
/*
2140321477
** Set the StrAccum object to an error mode.
2140421478
*/
2140521479
static void setStrAccumError(StrAccum *p, u8 eError){
21480
+ assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
2140621481
p->accError = eError;
2140721482
p->nAlloc = 0;
2140821483
}
2140921484
2141021485
/*
@@ -21515,11 +21590,10 @@
2151521590
case '0': flag_zeropad = 1; break;
2151621591
default: done = 1; break;
2151721592
}
2151821593
}while( !done && (c=(*++fmt))!=0 );
2151921594
/* Get the field width */
21520
- width = 0;
2152121595
if( c=='*' ){
2152221596
if( bArgList ){
2152321597
width = (int)getIntArg(pArgList);
2152421598
}else{
2152521599
width = va_arg(ap,int);
@@ -21539,11 +21613,10 @@
2153921613
width = wx & 0x7fffffff;
2154021614
}
2154121615
2154221616
/* Get the precision */
2154321617
if( c=='.' ){
21544
- precision = 0;
2154521618
c = *++fmt;
2154621619
if( c=='*' ){
2154721620
if( bArgList ){
2154821621
precision = (int)getIntArg(pArgList);
2154921622
}else{
@@ -22018,11 +22091,11 @@
2201822091
if( p->accError ){
2201922092
testcase(p->accError==STRACCUM_TOOBIG);
2202022093
testcase(p->accError==STRACCUM_NOMEM);
2202122094
return 0;
2202222095
}
22023
- if( !p->useMalloc ){
22096
+ if( p->mxAlloc==0 ){
2202422097
N = p->nAlloc - p->nChar - 1;
2202522098
setStrAccumError(p, STRACCUM_TOOBIG);
2202622099
return N;
2202722100
}else{
2202822101
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22111,14 @@
2203822111
setStrAccumError(p, STRACCUM_TOOBIG);
2203922112
return 0;
2204022113
}else{
2204122114
p->nAlloc = (int)szNew;
2204222115
}
22043
- if( p->useMalloc==1 ){
22116
+ if( p->db ){
2204422117
zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
2204522118
}else{
22046
- zNew = sqlite3_realloc(zOld, p->nAlloc);
22119
+ zNew = sqlite3_realloc64(zOld, p->nAlloc);
2204722120
}
2204822121
if( zNew ){
2204922122
assert( p->zText!=0 || p->nChar==0 );
2205022123
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2205122124
p->zText = zNew;
@@ -22089,11 +22162,11 @@
2208922162
/*
2209022163
** Append N bytes of text from z to the StrAccum object. Increase the
2209122164
** size of the memory allocation for StrAccum if necessary.
2209222165
*/
2209322166
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22094
- assert( z!=0 );
22167
+ assert( z!=0 || N==0 );
2209522168
assert( p->zText!=0 || p->nChar==0 || p->accError );
2209622169
assert( N>=0 );
2209722170
assert( p->accError==0 || p->nAlloc==0 );
2209822171
if( p->nChar+N >= p->nAlloc ){
2209922172
enlargeAndAppend(p,z,N);
@@ -22118,16 +22191,12 @@
2211822191
** pointer if any kind of error was encountered.
2211922192
*/
2212022193
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
2212122194
if( p->zText ){
2212222195
p->zText[p->nChar] = 0;
22123
- if( p->useMalloc && p->zText==p->zBase ){
22124
- if( p->useMalloc==1 ){
22125
- p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22126
- }else{
22127
- p->zText = sqlite3_malloc(p->nChar+1);
22128
- }
22196
+ if( p->mxAlloc>0 && p->zText==p->zBase ){
22197
+ p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
2212922198
if( p->zText ){
2213022199
memcpy(p->zText, p->zBase, p->nChar+1);
2213122200
}else{
2213222201
setStrAccumError(p, STRACCUM_NOMEM);
2213322202
}
@@ -22139,29 +22208,35 @@
2213922208
/*
2214022209
** Reset an StrAccum string. Reclaim all malloced memory.
2214122210
*/
2214222211
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
2214322212
if( p->zText!=p->zBase ){
22144
- if( p->useMalloc==1 ){
22145
- sqlite3DbFree(p->db, p->zText);
22146
- }else{
22147
- sqlite3_free(p->zText);
22148
- }
22213
+ sqlite3DbFree(p->db, p->zText);
2214922214
}
2215022215
p->zText = 0;
2215122216
}
2215222217
2215322218
/*
22154
-** Initialize a string accumulator
22219
+** Initialize a string accumulator.
22220
+**
22221
+** p: The accumulator to be initialized.
22222
+** db: Pointer to a database connection. May be NULL. Lookaside
22223
+** memory is used if not NULL. db->mallocFailed is set appropriately
22224
+** when not NULL.
22225
+** zBase: An initial buffer. May be NULL in which case the initial buffer
22226
+** is malloced.
22227
+** n: Size of zBase in bytes. If total space requirements never exceed
22228
+** n then no memory allocations ever occur.
22229
+** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
22230
+** allocations will ever occur.
2215522231
*/
22156
-SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
22232
+SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
2215722233
p->zText = p->zBase = zBase;
22158
- p->db = 0;
22234
+ p->db = db;
2215922235
p->nChar = 0;
2216022236
p->nAlloc = n;
2216122237
p->mxAlloc = mx;
22162
- p->useMalloc = 1;
2216322238
p->accError = 0;
2216422239
}
2216522240
2216622241
/*
2216722242
** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22245,12 @@
2217022245
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
2217122246
char *z;
2217222247
char zBase[SQLITE_PRINT_BUF_SIZE];
2217322248
StrAccum acc;
2217422249
assert( db!=0 );
22175
- sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
22250
+ sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
2217622251
db->aLimit[SQLITE_LIMIT_LENGTH]);
22177
- acc.db = db;
2217822252
sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
2217922253
z = sqlite3StrAccumFinish(&acc);
2218022254
if( acc.accError==STRACCUM_NOMEM ){
2218122255
db->mallocFailed = 1;
2218222256
}
@@ -22230,12 +22304,11 @@
2223022304
}
2223122305
#endif
2223222306
#ifndef SQLITE_OMIT_AUTOINIT
2223322307
if( sqlite3_initialize() ) return 0;
2223422308
#endif
22235
- sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
22236
- acc.useMalloc = 2;
22309
+ sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
2223722310
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2223822311
z = sqlite3StrAccumFinish(&acc);
2223922312
return z;
2224022313
}
2224122314
@@ -22276,12 +22349,11 @@
2227622349
(void)SQLITE_MISUSE_BKPT;
2227722350
if( zBuf ) zBuf[0] = 0;
2227822351
return zBuf;
2227922352
}
2228022353
#endif
22281
- sqlite3StrAccumInit(&acc, zBuf, n, 0);
22282
- acc.useMalloc = 0;
22354
+ sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
2228322355
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2228422356
return sqlite3StrAccumFinish(&acc);
2228522357
}
2228622358
SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
2228722359
char *z;
@@ -22303,12 +22375,11 @@
2230322375
*/
2230422376
static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
2230522377
StrAccum acc; /* String accumulator */
2230622378
char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
2230722379
22308
- sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
22309
- acc.useMalloc = 0;
22380
+ sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
2231022381
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2231122382
sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
2231222383
sqlite3StrAccumFinish(&acc));
2231322384
}
2231422385
@@ -22322,22 +22393,21 @@
2232222393
renderLogMsg(iErrCode, zFormat, ap);
2232322394
va_end(ap);
2232422395
}
2232522396
}
2232622397
22327
-#if defined(SQLITE_DEBUG)
22398
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
2232822399
/*
2232922400
** A version of printf() that understands %lld. Used for debugging.
2233022401
** The printf() built into some versions of windows does not understand %lld
2233122402
** and segfaults if you give it a long long int.
2233222403
*/
2233322404
SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
2233422405
va_list ap;
2233522406
StrAccum acc;
2233622407
char zBuf[500];
22337
- sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22338
- acc.useMalloc = 0;
22408
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2233922409
va_start(ap,zFormat);
2234022410
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2234122411
va_end(ap);
2234222412
sqlite3StrAccumFinish(&acc);
2234322413
fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22430,11 @@
2236022430
*/
2236122431
/* Add a new subitem to the tree. The moreToFollow flag indicates that this
2236222432
** is not the last item in the tree. */
2236322433
SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
2236422434
if( p==0 ){
22365
- p = sqlite3_malloc( sizeof(*p) );
22435
+ p = sqlite3_malloc64( sizeof(*p) );
2236622436
if( p==0 ) return 0;
2236722437
memset(p, 0, sizeof(*p));
2236822438
}else{
2236922439
p->iLevel++;
2237022440
}
@@ -22383,12 +22453,11 @@
2238322453
SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
2238422454
va_list ap;
2238522455
int i;
2238622456
StrAccum acc;
2238722457
char zBuf[500];
22388
- sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22389
- acc.useMalloc = 0;
22458
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2239022459
if( p ){
2239122460
for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
2239222461
sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
2239322462
}
2239422463
sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24076,11 @@
2400724076
}else{
2400824077
return 0;
2400924078
}
2401024079
}
2401124080
#endif
24081
+ while( zNum[0]=='0' ) zNum++;
2401224082
for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
2401324083
v = v*10 + c;
2401424084
}
2401524085
2401624086
/* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25331,21 @@
2526125331
#if SQLITE_ENABLE_LOCKING_STYLE
2526225332
# include <sys/ioctl.h>
2526325333
# include <sys/file.h>
2526425334
# include <sys/param.h>
2526525335
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
25336
+
25337
+#if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
25338
+ (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
25339
+# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
25340
+ && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
25341
+# define HAVE_GETHOSTUUID 1
25342
+# else
25343
+# warning "gethostuuid() is disabled."
25344
+# endif
25345
+#endif
25346
+
2526625347
2526725348
#if OS_VXWORKS
2526825349
/* # include <sys/ioctl.h> */
2526925350
# include <semaphore.h>
2527025351
# include <limits.h>
@@ -25457,20 +25538,10 @@
2545725538
*/
2545825539
#ifdef MEMORY_DEBUG
2545925540
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
2546025541
#endif
2546125542
25462
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25463
-# ifndef SQLITE_DEBUG_OS_TRACE
25464
-# define SQLITE_DEBUG_OS_TRACE 0
25465
-# endif
25466
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
25467
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
25468
-#else
25469
-# define OSTRACE(X)
25470
-#endif
25471
-
2547225543
/*
2547325544
** Macros for performance tracing. Normally turned off. Only works
2547425545
** on i486 hardware.
2547525546
*/
2547625547
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26080,11 @@
2600926080
return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
2601026081
}
2601126082
#endif
2601226083
2601326084
26014
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
26085
+#ifdef SQLITE_HAVE_OS_TRACE
2601526086
/*
2601626087
** Helper function for printing out trace information from debugging
2601726088
** binaries. This returns the string representation of the supplied
2601826089
** integer lock-type.
2601926090
*/
@@ -26272,11 +26343,11 @@
2627226343
struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
2627326344
int n; /* Length of zAbsoluteName string */
2627426345
2627526346
assert( zAbsoluteName[0]=='/' );
2627626347
n = (int)strlen(zAbsoluteName);
26277
- pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) );
26348
+ pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) );
2627826349
if( pNew==0 ) return 0;
2627926350
pNew->zCanonicalName = (char*)&pNew[1];
2628026351
memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
2628126352
n = vxworksSimplifyName(pNew->zCanonicalName, n);
2628226353
@@ -26676,11 +26747,11 @@
2667626747
pInode = inodeList;
2667726748
while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
2667826749
pInode = pInode->pNext;
2667926750
}
2668026751
if( pInode==0 ){
26681
- pInode = sqlite3_malloc( sizeof(*pInode) );
26752
+ pInode = sqlite3_malloc64( sizeof(*pInode) );
2668226753
if( pInode==0 ){
2668326754
return SQLITE_NOMEM;
2668426755
}
2668526756
memset(pInode, 0, sizeof(*pInode));
2668626757
memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29268,11 @@
2919729268
case SQLITE_FCNTL_VFSNAME: {
2919829269
*(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
2919929270
return SQLITE_OK;
2920029271
}
2920129272
case SQLITE_FCNTL_TEMPFILENAME: {
29202
- char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
29273
+ char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
2920329274
if( zTFile ){
2920429275
unixGetTempname(pFile->pVfs->mxPathname, zTFile);
2920529276
*(char**)pArg = zTFile;
2920629277
}
2920729278
return SQLITE_OK;
@@ -29638,11 +29709,11 @@
2963829709
unixInodeInfo *pInode; /* The inode of fd */
2963929710
char *zShmFilename; /* Name of the file used for SHM */
2964029711
int nShmFilename; /* Size of the SHM filename in bytes */
2964129712
2964229713
/* Allocate space for the new unixShm object. */
29643
- p = sqlite3_malloc( sizeof(*p) );
29714
+ p = sqlite3_malloc64( sizeof(*p) );
2964429715
if( p==0 ) return SQLITE_NOMEM;
2964529716
memset(p, 0, sizeof(*p));
2964629717
assert( pDbFd->pShm==0 );
2964729718
2964829719
/* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29740,11 @@
2966929740
#ifdef SQLITE_SHM_DIRECTORY
2967029741
nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
2967129742
#else
2967229743
nShmFilename = 6 + (int)strlen(zBasePath);
2967329744
#endif
29674
- pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29745
+ pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
2967529746
if( pShmNode==0 ){
2967629747
rc = SQLITE_NOMEM;
2967729748
goto shm_open_err;
2967829749
}
2967929750
memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29950,11 @@
2987929950
if( pMem==MAP_FAILED ){
2988029951
rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
2988129952
goto shmpage_out;
2988229953
}
2988329954
}else{
29884
- pMem = sqlite3_malloc(szRegion);
29955
+ pMem = sqlite3_malloc64(szRegion);
2988529956
if( pMem==0 ){
2988629957
rc = SQLITE_NOMEM;
2988729958
goto shmpage_out;
2988829959
}
2988929960
memset(pMem, 0, szRegion);
@@ -30716,11 +30787,11 @@
3071630787
else if( pLockingStyle == &afpIoMethods ){
3071730788
/* AFP locking uses the file path so it needs to be included in
3071830789
** the afpLockingContext.
3071930790
*/
3072030791
afpLockingContext *pCtx;
30721
- pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) );
30792
+ pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
3072230793
if( pCtx==0 ){
3072330794
rc = SQLITE_NOMEM;
3072430795
}else{
3072530796
/* NB: zFilename exists and remains valid until the file is closed
3072630797
** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30817,11 @@
3074630817
*/
3074730818
char *zLockFile;
3074830819
int nFilename;
3074930820
assert( zFilename!=0 );
3075030821
nFilename = (int)strlen(zFilename) + 6;
30751
- zLockFile = (char *)sqlite3_malloc(nFilename);
30822
+ zLockFile = (char *)sqlite3_malloc64(nFilename);
3075230823
if( zLockFile==0 ){
3075330824
rc = SQLITE_NOMEM;
3075430825
}else{
3075530826
sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
3075630827
}
@@ -31123,11 +31194,11 @@
3112331194
UnixUnusedFd *pUnused;
3112431195
pUnused = findReusableFd(zName, flags);
3112531196
if( pUnused ){
3112631197
fd = pUnused->fd;
3112731198
}else{
31128
- pUnused = sqlite3_malloc(sizeof(*pUnused));
31199
+ pUnused = sqlite3_malloc64(sizeof(*pUnused));
3112931200
if( !pUnused ){
3113031201
return SQLITE_NOMEM;
3113131202
}
3113231203
}
3113331204
p->pUnused = pUnused;
@@ -31503,11 +31574,11 @@
3150331574
** that we always use the same random number sequence. This makes the
3150431575
** tests repeatable.
3150531576
*/
3150631577
memset(zBuf, 0, nBuf);
3150731578
randomnessPid = osGetpid(0);
31508
-#if !defined(SQLITE_TEST)
31579
+#if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
3150931580
{
3151031581
int fd, got;
3151131582
fd = robust_open("/dev/urandom", O_RDONLY, 0);
3151231583
if( fd<0 ){
3151331584
time_t t;
@@ -31915,11 +31986,11 @@
3191531986
*/
3191631987
pUnused = findReusableFd(path, openFlags);
3191731988
if( pUnused ){
3191831989
fd = pUnused->fd;
3191931990
}else{
31920
- pUnused = sqlite3_malloc(sizeof(*pUnused));
31991
+ pUnused = sqlite3_malloc64(sizeof(*pUnused));
3192131992
if( !pUnused ){
3192231993
return SQLITE_NOMEM;
3192331994
}
3192431995
}
3192531996
if( fd<0 ){
@@ -31948,11 +32019,11 @@
3194832019
default:
3194932020
return SQLITE_CANTOPEN_BKPT;
3195032021
}
3195132022
}
3195232023
31953
- pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew));
32024
+ pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
3195432025
if( pNew==NULL ){
3195532026
rc = SQLITE_NOMEM;
3195632027
goto end_create_proxy;
3195732028
}
3195832029
memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32052,22 @@
3198132052
SQLITE_API int sqlite3_hostid_num = 0;
3198232053
#endif
3198332054
3198432055
#define PROXY_HOSTIDLEN 16 /* conch file host id length */
3198532056
32057
+#ifdef HAVE_GETHOSTUUID
3198632058
/* Not always defined in the headers as it ought to be */
3198732059
extern int gethostuuid(uuid_t id, const struct timespec *wait);
32060
+#endif
3198832061
3198932062
/* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
3199032063
** bytes of writable memory.
3199132064
*/
3199232065
static int proxyGetHostID(unsigned char *pHostID, int *pError){
3199332066
assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
3199432067
memset(pHostID, 0, PROXY_HOSTIDLEN);
31995
-# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31996
- (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
32068
+#ifdef HAVE_GETHOSTUUID
3199732069
{
3199832070
struct timespec timeout = {1, 0}; /* 1 sec timeout */
3199932071
if( gethostuuid(pHostID, &timeout) ){
3200032072
int err = errno;
3200132073
if( pError ){
@@ -32409,11 +32481,11 @@
3240932481
return rc;
3241032482
}
3241132483
3241232484
/*
3241332485
** Given the name of a database file, compute the name of its conch file.
32414
-** Store the conch filename in memory obtained from sqlite3_malloc().
32486
+** Store the conch filename in memory obtained from sqlite3_malloc64().
3241532487
** Make *pConchPath point to the new name. Return SQLITE_OK on success
3241632488
** or SQLITE_NOMEM if unable to obtain memory.
3241732489
**
3241832490
** The caller is responsible for ensuring that the allocated memory
3241932491
** space is eventually freed.
@@ -32425,11 +32497,11 @@
3242532497
int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
3242632498
char *conchPath; /* buffer in which to construct conch name */
3242732499
3242832500
/* Allocate space for the conch filename and initialize the name to
3242932501
** the name of the original database file. */
32430
- *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8);
32502
+ *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
3243132503
if( conchPath==0 ){
3243232504
return SQLITE_NOMEM;
3243332505
}
3243432506
memcpy(conchPath, dbPath, len+1);
3243532507
@@ -32541,11 +32613,11 @@
3254132613
}
3254232614
3254332615
OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
3254432616
(lockPath ? lockPath : ":auto:"), osGetpid(0)));
3254532617
32546
- pCtx = sqlite3_malloc( sizeof(*pCtx) );
32618
+ pCtx = sqlite3_malloc64( sizeof(*pCtx) );
3254732619
if( pCtx==0 ){
3254832620
return SQLITE_NOMEM;
3254932621
}
3255032622
memset(pCtx, 0, sizeof(*pCtx));
3255132623
@@ -32985,20 +33057,10 @@
3298533057
*/
3298633058
#ifdef MEMORY_DEBUG
3298733059
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
3298833060
#endif
3298933061
32990
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
32991
-# ifndef SQLITE_DEBUG_OS_TRACE
32992
-# define SQLITE_DEBUG_OS_TRACE 0
32993
-# endif
32994
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
32995
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
32996
-#else
32997
-# define OSTRACE(X)
32998
-#endif
32999
-
3300033062
/*
3300133063
** Macros for performance tracing. Normally turned off. Only works
3300233064
** on i486 hardware.
3300333065
*/
3300433066
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35960,11 @@
3589835960
** Used only when SQLITE_NO_SYNC is not defined.
3589935961
*/
3590035962
BOOL rc;
3590135963
#endif
3590235964
#if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35903
- (defined(SQLITE_TEST) && defined(SQLITE_DEBUG))
35965
+ defined(SQLITE_HAVE_OS_TRACE)
3590435966
/*
3590535967
** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
3590635968
** OSTRACE() macros.
3590735969
*/
3590835970
winFile *pFile = (winFile*)id;
@@ -36575,11 +36637,11 @@
3657536637
DWORD lastErrno; /* The Windows errno from the last I/O error */
3657636638
3657736639
int nRef; /* Number of winShm objects pointing to this */
3657836640
winShm *pFirst; /* All winShm objects pointing to this */
3657936641
winShmNode *pNext; /* Next in list of all winShmNode objects */
36580
-#ifdef SQLITE_DEBUG
36642
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3658136643
u8 nextShmId; /* Next available winShm.id value */
3658236644
#endif
3658336645
};
3658436646
3658536647
/*
@@ -36606,11 +36668,11 @@
3660636668
winShmNode *pShmNode; /* The underlying winShmNode object */
3660736669
winShm *pNext; /* Next winShm with the same winShmNode */
3660836670
u8 hasMutex; /* True if holding the winShmNode mutex */
3660936671
u16 sharedMask; /* Mask of shared locks held */
3661036672
u16 exclMask; /* Mask of exclusive locks held */
36611
-#ifdef SQLITE_DEBUG
36673
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3661236674
u8 id; /* Id of this connection with its winShmNode */
3661336675
#endif
3661436676
};
3661536677
3661636678
/*
@@ -36797,11 +36859,11 @@
3679736859
if( rc ) goto shm_open_err;
3679836860
}
3679936861
3680036862
/* Make the new connection a child of the winShmNode */
3680136863
p->pShmNode = pShmNode;
36802
-#ifdef SQLITE_DEBUG
36864
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3680336865
p->id = pShmNode->nextShmId++;
3680436866
#endif
3680536867
pShmNode->nRef++;
3680636868
pDbFd->pShm = p;
3680736869
winShmLeaveMutex();
@@ -37066,11 +37128,11 @@
3706637128
goto shmpage_out;
3706737129
}
3706837130
}
3706937131
3707037132
/* Map the requested memory region into this processes address space. */
37071
- apNew = (struct ShmRegion *)sqlite3_realloc(
37133
+ apNew = (struct ShmRegion *)sqlite3_realloc64(
3707237134
pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
3707337135
);
3707437136
if( !apNew ){
3707537137
rc = SQLITE_IOERR_NOMEM;
3707637138
goto shmpage_out;
@@ -38513,11 +38575,11 @@
3851338575
** Write up to nBuf bytes of randomness into zBuf.
3851438576
*/
3851538577
static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
3851638578
int n = 0;
3851738579
UNUSED_PARAMETER(pVfs);
38518
-#if defined(SQLITE_TEST)
38580
+#if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
3851938581
n = nBuf;
3852038582
memset(zBuf, 0, nBuf);
3852138583
#else
3852238584
if( sizeof(SYSTEMTIME)<=nBuf-n ){
3852338585
SYSTEMTIME x;
@@ -38547,11 +38609,10 @@
3854738609
LARGE_INTEGER i;
3854838610
osQueryPerformanceCounter(&i);
3854938611
memcpy(&zBuf[n], &i, sizeof(i));
3855038612
n += sizeof(i);
3855138613
}
38552
-#endif
3855338614
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
3855438615
if( sizeof(UUID)<=nBuf-n ){
3855538616
UUID id;
3855638617
memset(&id, 0, sizeof(UUID));
3855738618
osUuidCreate(&id);
@@ -38564,10 +38625,11 @@
3856438625
osUuidCreateSequential(&id);
3856538626
memcpy(zBuf, &id, sizeof(UUID));
3856638627
n += sizeof(UUID);
3856738628
}
3856838629
#endif
38630
+#endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
3856938631
return n;
3857038632
}
3857138633
3857238634
3857338635
/*
@@ -39118,11 +39180,11 @@
3911839180
3911939181
/* Allocate the Bitvec to be tested and a linear array of
3912039182
** bits to act as the reference */
3912139183
pBitvec = sqlite3BitvecCreate( sz );
3912239184
pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39123
- pTmpSpace = sqlite3_malloc(BITVEC_SZ);
39185
+ pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
3912439186
if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
3912539187
3912639188
/* NULL pBitvec tests */
3912739189
sqlite3BitvecSet(0, 1);
3912839190
sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44669,11 @@
4460744669
Pgno nTruncate, /* Database size after this commit */
4460844670
int isCommit /* True if this is a commit */
4460944671
){
4461044672
int rc; /* Return code */
4461144673
int nList; /* Number of pages in pList */
44612
-#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
4461344674
PgHdr *p; /* For looping over pages */
44614
-#endif
4461544675
4461644676
assert( pPager->pWal );
4461744677
assert( pList );
4461844678
#ifdef SQLITE_DEBUG
4461944679
/* Verify that the page list is in accending order */
@@ -44626,11 +44686,10 @@
4462644686
if( isCommit ){
4462744687
/* If a WAL transaction is being committed, there is no point in writing
4462844688
** any pages with page numbers greater than nTruncate into the WAL file.
4462944689
** They will never be read by any client. So remove them from the pDirty
4463044690
** list here. */
44631
- PgHdr *p;
4463244691
PgHdr **ppNext = &pList;
4463344692
nList = 0;
4463444693
for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
4463544694
if( p->pgno<=nTruncate ){
4463644695
ppNext = &p->pDirty;
@@ -44646,11 +44705,10 @@
4464644705
if( pList->pgno==1 ) pager_write_changecounter(pList);
4464744706
rc = sqlite3WalFrames(pPager->pWal,
4464844707
pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
4464944708
);
4465044709
if( rc==SQLITE_OK && pPager->pBackup ){
44651
- PgHdr *p;
4465244710
for(p=pList; p; p=p->pDirty){
4465344711
sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
4465444712
}
4465544713
}
4465644714
@@ -48577,10 +48635,12 @@
4857748635
}else if( state==PAGER_OPEN ){
4857848636
pager_unlock(pPager);
4857948637
}
4858048638
assert( state==pPager->eState );
4858148639
}
48640
+ }else if( eMode==PAGER_JOURNALMODE_OFF ){
48641
+ sqlite3OsClose(pPager->jfd);
4858248642
}
4858348643
}
4858448644
4858548645
/* Return the new journal mode */
4858648646
return (int)pPager->journalMode;
@@ -49359,11 +49419,11 @@
4935949419
4936049420
/* Enlarge the pWal->apWiData[] array if required */
4936149421
if( pWal->nWiData<=iPage ){
4936249422
int nByte = sizeof(u32*)*(iPage+1);
4936349423
volatile u32 **apNew;
49364
- apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte);
49424
+ apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
4936549425
if( !apNew ){
4936649426
*ppPage = 0;
4936749427
return SQLITE_NOMEM;
4936849428
}
4936949429
memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50044,11 @@
4998450044
goto finished;
4998550045
}
4998650046
4998750047
/* Malloc a buffer to read frames into. */
4998850048
szFrame = szPage + WAL_FRAME_HDRSIZE;
49989
- aFrame = (u8 *)sqlite3_malloc(szFrame);
50049
+ aFrame = (u8 *)sqlite3_malloc64(szFrame);
4999050050
if( !aFrame ){
4999150051
rc = SQLITE_NOMEM;
4999250052
goto recovery_error;
4999350053
}
4999450054
aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50437,21 @@
5037750437
/* Allocate space for the WalIterator object. */
5037850438
nSegment = walFramePage(iLast) + 1;
5037950439
nByte = sizeof(WalIterator)
5038050440
+ (nSegment-1)*sizeof(struct WalSegment)
5038150441
+ iLast*sizeof(ht_slot);
50382
- p = (WalIterator *)sqlite3_malloc(nByte);
50442
+ p = (WalIterator *)sqlite3_malloc64(nByte);
5038350443
if( !p ){
5038450444
return SQLITE_NOMEM;
5038550445
}
5038650446
memset(p, 0, nByte);
5038750447
p->nSegment = nSegment;
5038850448
5038950449
/* Allocate temporary space used by the merge-sort routine. This block
5039050450
** of memory will be freed before this function returns.
5039150451
*/
50392
- aTmp = (ht_slot *)sqlite3_malloc(
50452
+ aTmp = (ht_slot *)sqlite3_malloc64(
5039350453
sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
5039450454
);
5039550455
if( !aTmp ){
5039650456
rc = SQLITE_NOMEM;
5039750457
}
@@ -50567,10 +50627,18 @@
5056750627
** cannot be backfilled from the WAL.
5056850628
*/
5056950629
mxSafeFrame = pWal->hdr.mxFrame;
5057050630
mxPage = pWal->hdr.nPage;
5057150631
for(i=1; i<WAL_NREADER; i++){
50632
+ /* Thread-sanitizer reports that the following is an unsafe read,
50633
+ ** as some other thread may be in the process of updating the value
50634
+ ** of the aReadMark[] slot. The assumption here is that if that is
50635
+ ** happening, the other client may only be increasing the value,
50636
+ ** not decreasing it. So assuming either that either the "old" or
50637
+ ** "new" version of the value is read, and not some arbitrary value
50638
+ ** that would never be written by a real client, things are still
50639
+ ** safe. */
5057250640
u32 y = pInfo->aReadMark[i];
5057350641
if( mxSafeFrame>y ){
5057450642
assert( y<=pWal->hdr.mxFrame );
5057550643
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
5057650644
if( rc==SQLITE_OK ){
@@ -55407,11 +55475,11 @@
5540755475
}
5540855476
assert( nReserve>=0 && nReserve<=255 );
5540955477
if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
5541055478
((pageSize-1)&pageSize)==0 ){
5541155479
assert( (pageSize & 7)==0 );
55412
- assert( !pBt->pPage1 && !pBt->pCursor );
55480
+ assert( !pBt->pCursor );
5541355481
pBt->pageSize = (u32)pageSize;
5541455482
freeTempSpace(pBt);
5541555483
}
5541655484
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
5541755485
pBt->usableSize = pBt->pageSize - (u16)nReserve;
@@ -57429,17 +57497,22 @@
5742957497
*/
5743057498
static const void *fetchPayload(
5743157499
BtCursor *pCur, /* Cursor pointing to entry to read from */
5743257500
u32 *pAmt /* Write the number of available bytes here */
5743357501
){
57502
+ u32 amt;
5743457503
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
5743557504
assert( pCur->eState==CURSOR_VALID );
5743657505
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5743757506
assert( cursorHoldsMutex(pCur) );
5743857507
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
5743957508
assert( pCur->info.nSize>0 );
57440
- *pAmt = pCur->info.nLocal;
57509
+ assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
57510
+ assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
57511
+ amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
57512
+ if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
57513
+ *pAmt = amt;
5744157514
return (void*)pCur->info.pPayload;
5744257515
}
5744357516
5744457517
5744557518
/*
@@ -59713,11 +59786,10 @@
5971359786
if( iParentIdx==0 ){
5971459787
nxDiv = 0;
5971559788
}else if( iParentIdx==i ){
5971659789
nxDiv = i-2+bBulk;
5971759790
}else{
59718
- assert( bBulk==0 );
5971959791
nxDiv = iParentIdx-1;
5972059792
}
5972159793
i = 2-bBulk;
5972259794
}
5972359795
nOld = i+1;
@@ -61501,10 +61573,61 @@
6150161573
iPage = get4byte(pOvflData);
6150261574
sqlite3PagerUnref(pOvflPage);
6150361575
}
6150461576
}
6150561577
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
61578
+
61579
+/*
61580
+** An implementation of a min-heap.
61581
+**
61582
+** aHeap[0] is the number of elements on the heap. aHeap[1] is the
61583
+** root element. The daughter nodes of aHeap[N] are aHeap[N*2]
61584
+** and aHeap[N*2+1].
61585
+**
61586
+** The heap property is this: Every node is less than or equal to both
61587
+** of its daughter nodes. A consequence of the heap property is that the
61588
+** root node aHeap[1] is always the minimum value currently in the heap.
61589
+**
61590
+** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
61591
+** the heap, preserving the heap property. The btreeHeapPull() routine
61592
+** removes the root element from the heap (the minimum value in the heap)
61593
+** and then moves other nodes around as necessary to preserve the heap
61594
+** property.
61595
+**
61596
+** This heap is used for cell overlap and coverage testing. Each u32
61597
+** entry represents the span of a cell or freeblock on a btree page.
61598
+** The upper 16 bits are the index of the first byte of a range and the
61599
+** lower 16 bits are the index of the last byte of that range.
61600
+*/
61601
+static void btreeHeapInsert(u32 *aHeap, u32 x){
61602
+ u32 j, i = ++aHeap[0];
61603
+ aHeap[i] = x;
61604
+ while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
61605
+ x = aHeap[j];
61606
+ aHeap[j] = aHeap[i];
61607
+ aHeap[i] = x;
61608
+ i = j;
61609
+ }
61610
+}
61611
+static int btreeHeapPull(u32 *aHeap, u32 *pOut){
61612
+ u32 j, i, x;
61613
+ if( (x = aHeap[0])==0 ) return 0;
61614
+ *pOut = aHeap[1];
61615
+ aHeap[1] = aHeap[x];
61616
+ aHeap[x] = 0xffffffff;
61617
+ aHeap[0]--;
61618
+ i = 1;
61619
+ while( (j = i*2)<=aHeap[0] ){
61620
+ if( aHeap[j]>aHeap[j+1] ) j++;
61621
+ if( aHeap[i]<aHeap[j] ) break;
61622
+ x = aHeap[i];
61623
+ aHeap[i] = aHeap[j];
61624
+ aHeap[j] = x;
61625
+ i = j;
61626
+ }
61627
+ return 1;
61628
+}
6150661629
6150761630
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
6150861631
/*
6150961632
** Do various sanity checks on a single page of a tree. Return
6151061633
** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61657,12 @@
6153461657
int hdr, cellStart;
6153561658
int nCell;
6153661659
u8 *data;
6153761660
BtShared *pBt;
6153861661
int usableSize;
61539
- char *hit = 0;
61662
+ u32 *heap = 0;
61663
+ u32 x, prev = 0;
6154061664
i64 nMinKey = 0;
6154161665
i64 nMaxKey = 0;
6154261666
const char *saved_zPfx = pCheck->zPfx;
6154361667
int saved_v1 = pCheck->v1;
6154461668
int saved_v2 = pCheck->v2;
@@ -61679,19 +61803,19 @@
6167961803
6168061804
/* Check for complete coverage of the page
6168161805
*/
6168261806
data = pPage->aData;
6168361807
hdr = pPage->hdrOffset;
61684
- hit = sqlite3PageMalloc( pBt->pageSize );
61808
+ heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
6168561809
pCheck->zPfx = 0;
61686
- if( hit==0 ){
61810
+ if( heap==0 ){
6168761811
pCheck->mallocFailed = 1;
6168861812
}else{
6168961813
int contentOffset = get2byteNotZero(&data[hdr+5]);
6169061814
assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61691
- memset(hit+contentOffset, 0, usableSize-contentOffset);
61692
- memset(hit, 1, contentOffset);
61815
+ heap[0] = 0;
61816
+ btreeHeapInsert(heap, contentOffset-1);
6169361817
/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
6169461818
** number of cells on the page. */
6169561819
nCell = get2byte(&data[hdr+3]);
6169661820
/* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
6169761821
** immediately follows the b-tree page header. */
@@ -61699,20 +61823,19 @@
6169961823
/* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
6170061824
** integer offsets to the cell contents. */
6170161825
for(i=0; i<nCell; i++){
6170261826
int pc = get2byte(&data[cellStart+i*2]);
6170361827
u32 size = 65536;
61704
- int j;
6170561828
if( pc<=usableSize-4 ){
6170661829
size = cellSizePtr(pPage, &data[pc]);
6170761830
}
6170861831
if( (int)(pc+size-1)>=usableSize ){
6170961832
pCheck->zPfx = 0;
6171061833
checkAppendMsg(pCheck,
6171161834
"Corruption detected in cell %d on page %d",i,iPage);
6171261835
}else{
61713
- for(j=pc+size-1; j>=pc; j--) hit[j]++;
61836
+ btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
6171461837
}
6171561838
}
6171661839
/* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
6171761840
** is the offset of the first freeblock, or zero if there are no
6171861841
** freeblocks on the page. */
@@ -61720,11 +61843,11 @@
6172061843
while( i>0 ){
6172161844
int size, j;
6172261845
assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
6172361846
size = get2byte(&data[i+2]);
6172461847
assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61725
- for(j=i+size-1; j>=i; j--) hit[j]++;
61848
+ btreeHeapInsert(heap, (i<<16)|(i+size-1));
6172661849
/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
6172761850
** big-endian integer which is the offset in the b-tree page of the next
6172861851
** freeblock in the chain, or zero if the freeblock is the last on the
6172961852
** chain. */
6173061853
j = get2byte(&data[i]);
@@ -61732,31 +61855,37 @@
6173261855
** increasing offset. */
6173361856
assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
6173461857
assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
6173561858
i = j;
6173661859
}
61737
- for(i=cnt=0; i<usableSize; i++){
61738
- if( hit[i]==0 ){
61739
- cnt++;
61740
- }else if( hit[i]>1 ){
61860
+ cnt = 0;
61861
+ assert( heap[0]>0 );
61862
+ assert( (heap[1]>>16)==0 );
61863
+ btreeHeapPull(heap,&prev);
61864
+ while( btreeHeapPull(heap,&x) ){
61865
+ if( (prev&0xffff)+1>(x>>16) ){
6174161866
checkAppendMsg(pCheck,
61742
- "Multiple uses for byte %d of page %d", i, iPage);
61867
+ "Multiple uses for byte %u of page %d", x>>16, iPage);
6174361868
break;
61869
+ }else{
61870
+ cnt += (x>>16) - (prev&0xffff) - 1;
61871
+ prev = x;
6174461872
}
6174561873
}
61874
+ cnt += usableSize - (prev&0xffff) - 1;
6174661875
/* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
6174761876
** is stored in the fifth field of the b-tree page header.
6174861877
** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
6174961878
** number of fragmented free bytes within the cell content area.
6175061879
*/
61751
- if( cnt!=data[hdr+7] ){
61880
+ if( heap[0]==0 && cnt!=data[hdr+7] ){
6175261881
checkAppendMsg(pCheck,
6175361882
"Fragmentation of %d bytes reported as %d on page %d",
6175461883
cnt, data[hdr+7], iPage);
6175561884
}
6175661885
}
61757
- sqlite3PageFree(hit);
61886
+ sqlite3PageFree(heap);
6175861887
releasePage(pPage);
6175961888
6176061889
end_of_check:
6176161890
pCheck->zPfx = saved_zPfx;
6176261891
pCheck->v1 = saved_v1;
@@ -61816,12 +61945,11 @@
6181661945
sqlite3BtreeLeave(p);
6181761946
return 0;
6181861947
}
6181961948
i = PENDING_BYTE_PAGE(pBt);
6182061949
if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61821
- sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
61822
- sCheck.errMsg.useMalloc = 2;
61950
+ sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
6182361951
6182461952
/* Check the integrity of the freelist
6182561953
*/
6182661954
sCheck.zPfx = "Main freelist: ";
6182761955
checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63281,15 @@
6315363281
return SQLITE_NOMEM;
6315463282
}
6315563283
pMem->z[pMem->n] = 0;
6315663284
pMem->z[pMem->n+1] = 0;
6315763285
pMem->flags |= MEM_Term;
63286
+ }
63287
+ pMem->flags &= ~MEM_Ephem;
6315863288
#ifdef SQLITE_DEBUG
63159
- pMem->pScopyFrom = 0;
63289
+ pMem->pScopyFrom = 0;
6316063290
#endif
63161
- }
6316263291
6316363292
return SQLITE_OK;
6316463293
}
6316563294
6316663295
/*
@@ -64600,11 +64729,11 @@
6460064729
int i;
6460164730
int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
6460264731
Mem *aMem = pRec->aMem;
6460364732
sqlite3 *db = aMem[0].db;
6460464733
for(i=0; i<nCol; i++){
64605
- if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
64734
+ sqlite3VdbeMemRelease(&aMem[i]);
6460664735
}
6460764736
sqlite3KeyInfoUnref(pRec->pKeyInfo);
6460864737
sqlite3DbFree(db, pRec);
6460964738
}
6461064739
}
@@ -66436,18 +66565,35 @@
6643666565
pVtabCursor->pVtab->nRef--;
6643766566
pModule->xClose(pVtabCursor);
6643866567
}
6643966568
#endif
6644066569
}
66570
+
66571
+/*
66572
+** Close all cursors in the current frame.
66573
+*/
66574
+static void closeCursorsInFrame(Vdbe *p){
66575
+ if( p->apCsr ){
66576
+ int i;
66577
+ for(i=0; i<p->nCursor; i++){
66578
+ VdbeCursor *pC = p->apCsr[i];
66579
+ if( pC ){
66580
+ sqlite3VdbeFreeCursor(p, pC);
66581
+ p->apCsr[i] = 0;
66582
+ }
66583
+ }
66584
+ }
66585
+}
6644166586
6644266587
/*
6644366588
** Copy the values stored in the VdbeFrame structure to its Vdbe. This
6644466589
** is used, for example, when a trigger sub-program is halted to restore
6644566590
** control to the main program.
6644666591
*/
6644766592
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
6644866593
Vdbe *v = pFrame->v;
66594
+ closeCursorsInFrame(v);
6644966595
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
6645066596
v->anExec = pFrame->anExec;
6645166597
#endif
6645266598
v->aOnceFlag = pFrame->aOnceFlag;
6645366599
v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66624,11 @@
6647866624
sqlite3VdbeFrameRestore(pFrame);
6647966625
p->pFrame = 0;
6648066626
p->nFrame = 0;
6648166627
}
6648266628
assert( p->nFrame==0 );
66483
-
66484
- if( p->apCsr ){
66485
- int i;
66486
- for(i=0; i<p->nCursor; i++){
66487
- VdbeCursor *pC = p->apCsr[i];
66488
- if( pC ){
66489
- sqlite3VdbeFreeCursor(p, pC);
66490
- p->apCsr[i] = 0;
66491
- }
66492
- }
66493
- }
66629
+ closeCursorsInFrame(p);
6649466630
if( p->aMem ){
6649566631
releaseMemArray(&p->aMem[1], p->nMem);
6649666632
}
6649766633
while( p->pDelFrame ){
6649866634
VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68369,11 @@
6823368369
** If database corruption is discovered, set pPKey2->errCode to
6823468370
** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
6823568371
** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
6823668372
** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
6823768373
*/
68238
-static int vdbeRecordCompareWithSkip(
68374
+SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
6823968375
int nKey1, const void *pKey1, /* Left key */
6824068376
UnpackedRecord *pPKey2, /* Right key */
6824168377
int bSkip /* If true, skip the first field */
6824268378
){
6824368379
u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68555,11 @@
6841968555
}
6842068556
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
6842168557
int nKey1, const void *pKey1, /* Left key */
6842268558
UnpackedRecord *pPKey2 /* Right key */
6842368559
){
68424
- return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68560
+ return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
6842568561
}
6842668562
6842768563
6842868564
/*
6842968565
** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68643,11 @@
6850768643
}else if( v<lhs ){
6850868644
res = pPKey2->r2;
6850968645
}else if( pPKey2->nField>1 ){
6851068646
/* The first fields of the two keys are equal. Compare the trailing
6851168647
** fields. */
68512
- res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68648
+ res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6851368649
}else{
6851468650
/* The first fields of the two keys are equal and there are no trailing
6851568651
** fields. Return pPKey2->default_rc in this case. */
6851668652
res = pPKey2->default_rc;
6851768653
}
@@ -68555,11 +68691,11 @@
6855568691
6855668692
if( res==0 ){
6855768693
res = nStr - pPKey2->aMem[0].n;
6855868694
if( res==0 ){
6855968695
if( pPKey2->nField>1 ){
68560
- res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68696
+ res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6856168697
}else{
6856268698
res = pPKey2->default_rc;
6856368699
}
6856468700
}else if( res>0 ){
6856568701
res = pPKey2->r2;
@@ -70497,21 +70633,22 @@
7049770633
Mem *pVar; /* Value of a host parameter */
7049870634
StrAccum out; /* Accumulate the output here */
7049970635
char zBase[100]; /* Initial working space */
7050070636
7050170637
db = p->db;
70502
- sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
70638
+ sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
7050370639
db->aLimit[SQLITE_LIMIT_LENGTH]);
70504
- out.db = db;
7050570640
if( db->nVdbeExec>1 ){
7050670641
while( *zRawSql ){
7050770642
const char *zStart = zRawSql;
7050870643
while( *(zRawSql++)!='\n' && *zRawSql );
7050970644
sqlite3StrAccumAppend(&out, "-- ", 3);
7051070645
assert( (zRawSql - zStart) > 0 );
7051170646
sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
7051270647
}
70648
+ }else if( p->nVar==0 ){
70649
+ sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
7051370650
}else{
7051470651
while( zRawSql[0] ){
7051570652
n = findNextHostParameter(zRawSql, &nToken);
7051670653
assert( n>0 );
7051770654
sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70661,16 @@
7052470661
sqlite3GetInt32(&zRawSql[1], &idx);
7052570662
}else{
7052670663
idx = nextIndex;
7052770664
}
7052870665
}else{
70529
- assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
70666
+ assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
70667
+ zRawSql[0]=='@' || zRawSql[0]=='#' );
7053070668
testcase( zRawSql[0]==':' );
7053170669
testcase( zRawSql[0]=='$' );
7053270670
testcase( zRawSql[0]=='@' );
70671
+ testcase( zRawSql[0]=='#' );
7053370672
idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
7053470673
assert( idx>0 );
7053570674
}
7053670675
zRawSql += nToken;
7053770676
nextIndex = idx + 1;
@@ -71202,21 +71341,38 @@
7120271341
assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
7120371342
return 1;
7120471343
}
7120571344
#endif
7120671345
71346
+/*
71347
+** Return the register of pOp->p2 after first preparing it to be
71348
+** overwritten with an integer value.
71349
+*/
71350
+static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
71351
+ Mem *pOut;
71352
+ assert( pOp->p2>0 );
71353
+ assert( pOp->p2<=(p->nMem-p->nCursor) );
71354
+ pOut = &p->aMem[pOp->p2];
71355
+ memAboutToChange(p, pOut);
71356
+ if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71357
+ pOut->flags = MEM_Int;
71358
+ return pOut;
71359
+}
71360
+
7120771361
7120871362
/*
7120971363
** Execute as much of a VDBE program as we can.
7121071364
** This is the core of sqlite3_step().
7121171365
*/
7121271366
SQLITE_PRIVATE int sqlite3VdbeExec(
7121371367
Vdbe *p /* The VDBE */
7121471368
){
71215
- int pc=0; /* The program counter */
7121671369
Op *aOp = p->aOp; /* Copy of p->aOp */
71217
- Op *pOp; /* Current operation */
71370
+ Op *pOp = aOp; /* Current operation */
71371
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71372
+ Op *pOrigOp; /* Value of pOp at the top of the loop */
71373
+#endif
7121871374
int rc = SQLITE_OK; /* Value to return */
7121971375
sqlite3 *db = p->db; /* The database */
7122071376
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
7122171377
u8 encoding = ENC(db); /* The database encoding */
7122271378
int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71444,26 @@
7128871444
}
7128971445
if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
7129071446
}
7129171447
sqlite3EndBenignMalloc();
7129271448
#endif
71293
- for(pc=p->pc; rc==SQLITE_OK; pc++){
71294
- assert( pc>=0 && pc<p->nOp );
71449
+ for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){
71450
+ assert( pOp>=aOp && pOp<&aOp[p->nOp]);
7129571451
if( db->mallocFailed ) goto no_mem;
7129671452
#ifdef VDBE_PROFILE
7129771453
start = sqlite3Hwtime();
7129871454
#endif
7129971455
nVmStep++;
71300
- pOp = &aOp[pc];
7130171456
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71302
- if( p->anExec ) p->anExec[pc]++;
71457
+ if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
7130371458
#endif
7130471459
7130571460
/* Only allow tracing if SQLITE_DEBUG is defined.
7130671461
*/
7130771462
#ifdef SQLITE_DEBUG
7130871463
if( db->flags & SQLITE_VdbeTrace ){
71309
- sqlite3VdbePrintOp(stdout, pc, pOp);
71464
+ sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
7131071465
}
7131171466
#endif
7131271467
7131371468
7131471469
/* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71476,13 @@
7132171476
sqlite3_interrupt(db);
7132271477
}
7132371478
}
7132471479
#endif
7132571480
71326
- /* On any opcode with the "out2-prerelease" tag, free any
71327
- ** external allocations out of mem[p2] and set mem[p2] to be
71328
- ** an undefined integer. Opcodes will either fill in the integer
71329
- ** value or convert mem[p2] to a different type.
71330
- */
71331
- assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71332
- if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
71333
- assert( pOp->p2>0 );
71334
- assert( pOp->p2<=(p->nMem-p->nCursor) );
71335
- pOut = &aMem[pOp->p2];
71336
- memAboutToChange(p, pOut);
71337
- if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71338
- pOut->flags = MEM_Int;
71339
- }
71340
-
7134171481
/* Sanity checking on other operands */
7134271482
#ifdef SQLITE_DEBUG
71483
+ assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
7134371484
if( (pOp->opflags & OPFLG_IN1)!=0 ){
7134471485
assert( pOp->p1>0 );
7134571486
assert( pOp->p1<=(p->nMem-p->nCursor) );
7134671487
assert( memIsValid(&aMem[pOp->p1]) );
7134771488
assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71511,13 @@
7137071511
assert( pOp->p3>0 );
7137171512
assert( pOp->p3<=(p->nMem-p->nCursor) );
7137271513
memAboutToChange(p, &aMem[pOp->p3]);
7137371514
}
7137471515
#endif
71516
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71517
+ pOrigOp = pOp;
71518
+#endif
7137571519
7137671520
switch( pOp->opcode ){
7137771521
7137871522
/*****************************************************************************
7137971523
** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71537,11 @@
7139371537
** case statement is followed by a comment of the form "/# same as ... #/"
7139471538
** that comment is used to determine the particular value of the opcode.
7139571539
**
7139671540
** Other keywords in the comment that follows each case are used to
7139771541
** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71398
-** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See
71542
+** Keywords include: in1, in2, in3, out2, out3. See
7139971543
** the mkopcodeh.awk script for additional information.
7140071544
**
7140171545
** Documentation about VDBE opcodes is generated by scanning this file
7140271546
** for lines of that contain "Opcode:". That line and all subsequent
7140371547
** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71565,12 @@
7142171565
** is sometimes set to 1 instead of 0 as a hint to the command-line shell
7142271566
** that this Goto is the bottom of a loop and that the lines from P2 down
7142371567
** to the current line should be indented for EXPLAIN output.
7142471568
*/
7142571569
case OP_Goto: { /* jump */
71426
- pc = pOp->p2 - 1;
71570
+jump_to_p2_and_check_for_interrupt:
71571
+ pOp = &aOp[pOp->p2 - 1];
7142771572
7142871573
/* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
7142971574
** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
7143071575
** completion. Check to see if sqlite3_interrupt() has been called
7143171576
** or if the progress callback needs to be invoked.
@@ -71466,13 +71611,17 @@
7146671611
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
7146771612
pIn1 = &aMem[pOp->p1];
7146871613
assert( VdbeMemDynamic(pIn1)==0 );
7146971614
memAboutToChange(p, pIn1);
7147071615
pIn1->flags = MEM_Int;
71471
- pIn1->u.i = pc;
71616
+ pIn1->u.i = (int)(pOp-aOp);
7147271617
REGISTER_TRACE(pOp->p1, pIn1);
71473
- pc = pOp->p2 - 1;
71618
+
71619
+ /* Most jump operations do a goto to this spot in order to update
71620
+ ** the pOp pointer. */
71621
+jump_to_p2:
71622
+ pOp = &aOp[pOp->p2 - 1];
7147471623
break;
7147571624
}
7147671625
7147771626
/* Opcode: Return P1 * * * *
7147871627
**
@@ -71480,11 +71629,11 @@
7148071629
** the jump, register P1 becomes undefined.
7148171630
*/
7148271631
case OP_Return: { /* in1 */
7148371632
pIn1 = &aMem[pOp->p1];
7148471633
assert( pIn1->flags==MEM_Int );
71485
- pc = (int)pIn1->u.i;
71634
+ pOp = &aOp[pIn1->u.i];
7148671635
pIn1->flags = MEM_Undefined;
7148771636
break;
7148871637
}
7148971638
7149071639
/* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71653,11 @@
7150471653
assert( pOp->p3>=0 && pOp->p3<p->nOp );
7150571654
pOut = &aMem[pOp->p1];
7150671655
assert( !VdbeMemDynamic(pOut) );
7150771656
pOut->u.i = pOp->p3 - 1;
7150871657
pOut->flags = MEM_Int;
71509
- if( pOp->p2 ) pc = pOp->p2 - 1;
71658
+ if( pOp->p2 ) goto jump_to_p2;
7151071659
break;
7151171660
}
7151271661
7151371662
/* Opcode: EndCoroutine P1 * * * *
7151471663
**
@@ -71524,11 +71673,11 @@
7152471673
assert( pIn1->flags==MEM_Int );
7152571674
assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
7152671675
pCaller = &aOp[pIn1->u.i];
7152771676
assert( pCaller->opcode==OP_Yield );
7152871677
assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71529
- pc = pCaller->p2 - 1;
71678
+ pOp = &aOp[pCaller->p2 - 1];
7153071679
pIn1->flags = MEM_Undefined;
7153171680
break;
7153271681
}
7153371682
7153471683
/* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71697,13 @@
7154871697
int pcDest;
7154971698
pIn1 = &aMem[pOp->p1];
7155071699
assert( VdbeMemDynamic(pIn1)==0 );
7155171700
pIn1->flags = MEM_Int;
7155271701
pcDest = (int)pIn1->u.i;
71553
- pIn1->u.i = pc;
71702
+ pIn1->u.i = (int)(pOp - aOp);
7155471703
REGISTER_TRACE(pOp->p1, pIn1);
71555
- pc = pcDest;
71704
+ pOp = &aOp[pcDest];
7155671705
break;
7155771706
}
7155871707
7155971708
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
7156071709
** Synopsis: if r[P3]=null halt
@@ -71601,34 +71750,38 @@
7160171750
** is the same as executing Halt.
7160271751
*/
7160371752
case OP_Halt: {
7160471753
const char *zType;
7160571754
const char *zLogFmt;
71755
+ VdbeFrame *pFrame;
71756
+ int pcx;
7160671757
71758
+ pcx = (int)(pOp - aOp);
7160771759
if( pOp->p1==SQLITE_OK && p->pFrame ){
7160871760
/* Halt the sub-program. Return control to the parent frame. */
71609
- VdbeFrame *pFrame = p->pFrame;
71761
+ pFrame = p->pFrame;
7161071762
p->pFrame = pFrame->pParent;
7161171763
p->nFrame--;
7161271764
sqlite3VdbeSetChanges(db, p->nChange);
71613
- pc = sqlite3VdbeFrameRestore(pFrame);
71765
+ pcx = sqlite3VdbeFrameRestore(pFrame);
7161471766
lastRowid = db->lastRowid;
7161571767
if( pOp->p2==OE_Ignore ){
71616
- /* Instruction pc is the OP_Program that invoked the sub-program
71768
+ /* Instruction pcx is the OP_Program that invoked the sub-program
7161771769
** currently being halted. If the p2 instruction of this OP_Halt
7161871770
** instruction is set to OE_Ignore, then the sub-program is throwing
7161971771
** an IGNORE exception. In this case jump to the address specified
7162071772
** as the p2 of the calling OP_Program. */
71621
- pc = p->aOp[pc].p2-1;
71773
+ pcx = p->aOp[pcx].p2-1;
7162271774
}
7162371775
aOp = p->aOp;
7162471776
aMem = p->aMem;
71777
+ pOp = &aOp[pcx];
7162571778
break;
7162671779
}
7162771780
p->rc = pOp->p1;
7162871781
p->errorAction = (u8)pOp->p2;
71629
- p->pc = pc;
71782
+ p->pc = pcx;
7163071783
if( p->rc ){
7163171784
if( pOp->p5 ){
7163271785
static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
7163371786
"FOREIGN KEY" };
7163471787
assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71801,11 @@
7164871801
}else if( pOp->p4.z ){
7164971802
sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
7165071803
}else{
7165171804
sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
7165271805
}
71653
- sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
71806
+ sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
7165471807
}
7165571808
rc = sqlite3VdbeHalt(p);
7165671809
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
7165771810
if( rc==SQLITE_BUSY ){
7165871811
p->rc = rc = SQLITE_BUSY;
@@ -71667,11 +71820,12 @@
7166771820
/* Opcode: Integer P1 P2 * * *
7166871821
** Synopsis: r[P2]=P1
7166971822
**
7167071823
** The 32-bit integer value P1 is written into register P2.
7167171824
*/
71672
-case OP_Integer: { /* out2-prerelease */
71825
+case OP_Integer: { /* out2 */
71826
+ pOut = out2Prerelease(p, pOp);
7167371827
pOut->u.i = pOp->p1;
7167471828
break;
7167571829
}
7167671830
7167771831
/* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71832,12 @@
7167871832
** Synopsis: r[P2]=P4
7167971833
**
7168071834
** P4 is a pointer to a 64-bit integer value.
7168171835
** Write that value into register P2.
7168271836
*/
71683
-case OP_Int64: { /* out2-prerelease */
71837
+case OP_Int64: { /* out2 */
71838
+ pOut = out2Prerelease(p, pOp);
7168471839
assert( pOp->p4.pI64!=0 );
7168571840
pOut->u.i = *pOp->p4.pI64;
7168671841
break;
7168771842
}
7168871843
@@ -71691,11 +71846,12 @@
7169171846
** Synopsis: r[P2]=P4
7169271847
**
7169371848
** P4 is a pointer to a 64-bit floating point value.
7169471849
** Write that value into register P2.
7169571850
*/
71696
-case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
71851
+case OP_Real: { /* same as TK_FLOAT, out2 */
71852
+ pOut = out2Prerelease(p, pOp);
7169771853
pOut->flags = MEM_Real;
7169871854
assert( !sqlite3IsNaN(*pOp->p4.pReal) );
7169971855
pOut->u.r = *pOp->p4.pReal;
7170071856
break;
7170171857
}
@@ -71707,12 +71863,13 @@
7170771863
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
7170871864
** into a String opcode before it is executed for the first time. During
7170971865
** this transformation, the length of string P4 is computed and stored
7171071866
** as the P1 parameter.
7171171867
*/
71712
-case OP_String8: { /* same as TK_STRING, out2-prerelease */
71868
+case OP_String8: { /* same as TK_STRING, out2 */
7171371869
assert( pOp->p4.z!=0 );
71870
+ pOut = out2Prerelease(p, pOp);
7171471871
pOp->opcode = OP_String;
7171571872
pOp->p1 = sqlite3Strlen30(pOp->p4.z);
7171671873
7171771874
#ifndef SQLITE_OMIT_UTF16
7171871875
if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71902,13 @@
7174571902
** If P5!=0 and the content of register P3 is greater than zero, then
7174671903
** the datatype of the register P2 is converted to BLOB. The content is
7174771904
** the same sequence of bytes, it is merely interpreted as a BLOB instead
7174871905
** of a string, as if it had been CAST.
7174971906
*/
71750
-case OP_String: { /* out2-prerelease */
71907
+case OP_String: { /* out2 */
7175171908
assert( pOp->p4.z!=0 );
71909
+ pOut = out2Prerelease(p, pOp);
7175271910
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
7175371911
pOut->z = pOp->p4.z;
7175471912
pOut->n = pOp->p1;
7175571913
pOut->enc = encoding;
7175671914
UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71932,14 @@
7177471932
**
7177571933
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
7177671934
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
7177771935
** OP_Ne or OP_Eq.
7177871936
*/
71779
-case OP_Null: { /* out2-prerelease */
71937
+case OP_Null: { /* out2 */
7178071938
int cnt;
7178171939
u16 nullFlag;
71940
+ pOut = out2Prerelease(p, pOp);
7178271941
cnt = pOp->p3-pOp->p2;
7178371942
assert( pOp->p3<=(p->nMem-p->nCursor) );
7178471943
pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
7178571944
while( cnt>0 ){
7178671945
pOut++;
@@ -71811,12 +71970,13 @@
7181171970
** Synopsis: r[P2]=P4 (len=P1)
7181271971
**
7181371972
** P4 points to a blob of data P1 bytes long. Store this
7181471973
** blob in register P2.
7181571974
*/
71816
-case OP_Blob: { /* out2-prerelease */
71975
+case OP_Blob: { /* out2 */
7181771976
assert( pOp->p1 <= SQLITE_MAX_LENGTH );
71977
+ pOut = out2Prerelease(p, pOp);
7181871978
sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
7181971979
pOut->enc = encoding;
7182071980
UPDATE_MAX_BLOBSIZE(pOut);
7182171981
break;
7182271982
}
@@ -71827,19 +71987,20 @@
7182771987
** Transfer the values of bound parameter P1 into register P2
7182871988
**
7182971989
** If the parameter is named, then its name appears in P4.
7183071990
** The P4 value is used by sqlite3_bind_parameter_name().
7183171991
*/
71832
-case OP_Variable: { /* out2-prerelease */
71992
+case OP_Variable: { /* out2 */
7183371993
Mem *pVar; /* Value being transferred */
7183471994
7183571995
assert( pOp->p1>0 && pOp->p1<=p->nVar );
7183671996
assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
7183771997
pVar = &p->aVar[pOp->p1 - 1];
7183871998
if( sqlite3VdbeMemTooBig(pVar) ){
7183971999
goto too_big;
7184072000
}
72001
+ pOut = out2Prerelease(p, pOp);
7184172002
sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
7184272003
UPDATE_MAX_BLOBSIZE(pOut);
7184372004
break;
7184472005
}
7184572006
@@ -71870,14 +72031,15 @@
7187072031
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
7187172032
assert( memIsValid(pIn1) );
7187272033
memAboutToChange(p, pOut);
7187372034
sqlite3VdbeMemMove(pOut, pIn1);
7187472035
#ifdef SQLITE_DEBUG
71875
- if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
71876
- pOut->pScopyFrom += p1 - pOp->p2;
72036
+ if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
72037
+ pOut->pScopyFrom += pOp->p2 - p1;
7187772038
}
7187872039
#endif
72040
+ Deephemeralize(pOut);
7187972041
REGISTER_TRACE(p2++, pOut);
7188072042
pIn1++;
7188172043
pOut++;
7188272044
}while( --n );
7188372045
break;
@@ -72012,11 +72174,11 @@
7201272174
}
7201372175
if( db->mallocFailed ) goto no_mem;
7201472176
7201572177
/* Return SQLITE_ROW
7201672178
*/
72017
- p->pc = pc + 1;
72179
+ p->pc = (int)(pOp - aOp) + 1;
7201872180
rc = SQLITE_ROW;
7201972181
goto vdbe_return;
7202072182
}
7202172183
7202272184
/* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72420,11 @@
7225872420
REGISTER_TRACE(pOp->p2+i, pArg);
7225972421
}
7226072422
7226172423
assert( pOp->p4type==P4_FUNCDEF );
7226272424
ctx.pFunc = pOp->p4.pFunc;
72263
- ctx.iOp = pc;
72425
+ ctx.iOp = (int)(pOp - aOp);
7226472426
ctx.pVdbe = p;
7226572427
MemSetTypeFlag(ctx.pOut, MEM_Null);
7226672428
ctx.fErrorOrAux = 0;
7226772429
db->lastRowid = lastRowid;
7226872430
(*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72434,11 @@
7227272434
if( ctx.fErrorOrAux ){
7227372435
if( ctx.isError ){
7227472436
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
7227572437
rc = ctx.isError;
7227672438
}
72277
- sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
72439
+ sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1);
7227872440
}
7227972441
7228072442
/* Copy the result of the function into register P3 */
7228172443
sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
7228272444
if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72563,11 @@
7240172563
if( (pIn1->flags & MEM_Int)==0 ){
7240272564
if( pOp->p2==0 ){
7240372565
rc = SQLITE_MISMATCH;
7240472566
goto abort_due_to_error;
7240572567
}else{
72406
- pc = pOp->p2 - 1;
72407
- break;
72568
+ goto jump_to_p2;
7240872569
}
7240972570
}
7241072571
}
7241172572
MemSetTypeFlag(pIn1, MEM_Int);
7241272573
break;
@@ -72588,11 +72749,11 @@
7258872749
MemSetTypeFlag(pOut, MEM_Null);
7258972750
REGISTER_TRACE(pOp->p2, pOut);
7259072751
}else{
7259172752
VdbeBranchTaken(2,3);
7259272753
if( pOp->p5 & SQLITE_JUMPIFNULL ){
72593
- pc = pOp->p2-1;
72754
+ goto jump_to_p2;
7259472755
}
7259572756
}
7259672757
break;
7259772758
}
7259872759
}else{
@@ -72639,10 +72800,16 @@
7263972800
case OP_Lt: res = res<0; break;
7264072801
case OP_Le: res = res<=0; break;
7264172802
case OP_Gt: res = res>0; break;
7264272803
default: res = res>=0; break;
7264372804
}
72805
+
72806
+ /* Undo any changes made by applyAffinity() to the input registers. */
72807
+ assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72808
+ pIn1->flags = flags1;
72809
+ assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72810
+ pIn3->flags = flags3;
7264472811
7264572812
if( pOp->p5 & SQLITE_STOREP2 ){
7264672813
pOut = &aMem[pOp->p2];
7264772814
memAboutToChange(p, pOut);
7264872815
MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72816,13 @@
7264972816
pOut->u.i = res;
7265072817
REGISTER_TRACE(pOp->p2, pOut);
7265172818
}else{
7265272819
VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
7265372820
if( res ){
72654
- pc = pOp->p2-1;
72821
+ goto jump_to_p2;
7265572822
}
7265672823
}
72657
- /* Undo any changes made by applyAffinity() to the input registers. */
72658
- assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72659
- pIn1->flags = flags1;
72660
- assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72661
- pIn3->flags = flags3;
7266272824
break;
7266372825
}
7266472826
7266572827
/* Opcode: Permutation * * * P4 *
7266672828
**
@@ -72751,15 +72913,15 @@
7275172913
** in the most recent OP_Compare instruction the P1 vector was less than
7275272914
** equal to, or greater than the P2 vector, respectively.
7275372915
*/
7275472916
case OP_Jump: { /* jump */
7275572917
if( iCompare<0 ){
72756
- pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
72918
+ VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1];
7275772919
}else if( iCompare==0 ){
72758
- pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
72920
+ VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1];
7275972921
}else{
72760
- pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
72922
+ VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1];
7276172923
}
7276272924
break;
7276372925
}
7276472926
7276572927
/* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73027,11 @@
7286573027
*/
7286673028
case OP_Once: { /* jump */
7286773029
assert( pOp->p1<p->nOnceFlag );
7286873030
VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
7286973031
if( p->aOnceFlag[pOp->p1] ){
72870
- pc = pOp->p2-1;
73032
+ goto jump_to_p2;
7287173033
}else{
7287273034
p->aOnceFlag[pOp->p1] = 1;
7287373035
}
7287473036
break;
7287573037
}
@@ -72900,11 +73062,11 @@
7290073062
#endif
7290173063
if( pOp->opcode==OP_IfNot ) c = !c;
7290273064
}
7290373065
VdbeBranchTaken(c!=0, 2);
7290473066
if( c ){
72905
- pc = pOp->p2-1;
73067
+ goto jump_to_p2;
7290673068
}
7290773069
break;
7290873070
}
7290973071
7291073072
/* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73076,11 @@
7291473076
*/
7291573077
case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
7291673078
pIn1 = &aMem[pOp->p1];
7291773079
VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
7291873080
if( (pIn1->flags & MEM_Null)!=0 ){
72919
- pc = pOp->p2 - 1;
73081
+ goto jump_to_p2;
7292073082
}
7292173083
break;
7292273084
}
7292373085
7292473086
/* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73090,11 @@
7292873090
*/
7292973091
case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
7293073092
pIn1 = &aMem[pOp->p1];
7293173093
VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
7293273094
if( (pIn1->flags & MEM_Null)==0 ){
72933
- pc = pOp->p2 - 1;
73095
+ goto jump_to_p2;
7293473096
}
7293573097
break;
7293673098
}
7293773099
7293873100
/* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73304,11 @@
7314273304
rc = SQLITE_CORRUPT_BKPT;
7314373305
goto op_column_error;
7314473306
}
7314573307
}
7314673308
73147
- /* If after trying to extra new entries from the header, nHdrParsed is
73309
+ /* If after trying to extract new entries from the header, nHdrParsed is
7314873310
** still not up to p2, that means that the record has fewer than p2
7314973311
** columns. So the result will be either the default value or a NULL.
7315073312
*/
7315173313
if( pC->nHdrParsed<=p2 ){
7315273314
if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73428,11 @@
7326673428
u8 *zNewRecord; /* A buffer to hold the data for the new record */
7326773429
Mem *pRec; /* The new record */
7326873430
u64 nData; /* Number of bytes of data space */
7326973431
int nHdr; /* Number of bytes of header space */
7327073432
i64 nByte; /* Data space required for this record */
73271
- int nZero; /* Number of zero bytes at the end of the record */
73433
+ i64 nZero; /* Number of zero bytes at the end of the record */
7327273434
int nVarint; /* Number of bytes in a varint */
7327373435
u32 serial_type; /* Type field */
7327473436
Mem *pData0; /* First field to be combined into the record */
7327573437
Mem *pLast; /* Last field of the record */
7327673438
int nField; /* Number of fields in the record */
@@ -73358,11 +73520,11 @@
7335873520
nVarint = sqlite3VarintLen(nHdr);
7335973521
nHdr += nVarint;
7336073522
if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
7336173523
}
7336273524
nByte = nHdr+nData;
73363
- if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73525
+ if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
7336473526
goto too_big;
7336573527
}
7336673528
7336773529
/* Make sure the output register has a buffer large enough to store
7336873530
** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73571,19 @@
7340973571
**
7341073572
** Store the number of entries (an integer value) in the table or index
7341173573
** opened by cursor P1 in register P2
7341273574
*/
7341373575
#ifndef SQLITE_OMIT_BTREECOUNT
73414
-case OP_Count: { /* out2-prerelease */
73576
+case OP_Count: { /* out2 */
7341573577
i64 nEntry;
7341673578
BtCursor *pCrsr;
7341773579
7341873580
pCrsr = p->apCsr[pOp->p1]->pCursor;
7341973581
assert( pCrsr );
7342073582
nEntry = 0; /* Not needed. Only used to silence a warning. */
7342173583
rc = sqlite3BtreeCount(pCrsr, &nEntry);
73584
+ pOut = out2Prerelease(p, pOp);
7342273585
pOut->u.i = nEntry;
7342373586
break;
7342473587
}
7342573588
#endif
7342673589
@@ -73530,11 +73693,11 @@
7353073693
if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
7353173694
goto vdbe_return;
7353273695
}
7353373696
db->autoCommit = 1;
7353473697
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73535
- p->pc = pc;
73698
+ p->pc = (int)(pOp - aOp);
7353673699
db->autoCommit = 0;
7353773700
p->rc = rc = SQLITE_BUSY;
7353873701
goto vdbe_return;
7353973702
}
7354073703
db->isTransactionSavepoint = 0;
@@ -73589,11 +73752,11 @@
7358973752
}else{
7359073753
db->nDeferredCons = pSavepoint->nDeferredCons;
7359173754
db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
7359273755
}
7359373756
73594
- if( !isTransaction ){
73757
+ if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){
7359573758
rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
7359673759
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7359773760
}
7359873761
}
7359973762
}
@@ -73649,11 +73812,11 @@
7364973812
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
7365073813
goto vdbe_return;
7365173814
}else{
7365273815
db->autoCommit = (u8)desiredAutoCommit;
7365373816
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73654
- p->pc = pc;
73817
+ p->pc = (int)(pOp - aOp);
7365573818
db->autoCommit = (u8)(1-desiredAutoCommit);
7365673819
p->rc = rc = SQLITE_BUSY;
7365773820
goto vdbe_return;
7365873821
}
7365973822
}
@@ -73726,11 +73889,11 @@
7372673889
pBt = db->aDb[pOp->p1].pBt;
7372773890
7372873891
if( pBt ){
7372973892
rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
7373073893
if( rc==SQLITE_BUSY ){
73731
- p->pc = pc;
73894
+ p->pc = (int)(pOp - aOp);
7373273895
p->rc = rc = SQLITE_BUSY;
7373373896
goto vdbe_return;
7373473897
}
7373573898
if( rc!=SQLITE_OK ){
7373673899
goto abort_due_to_error;
@@ -73805,11 +73968,11 @@
7380573968
**
7380673969
** There must be a read-lock on the database (either a transaction
7380773970
** must be started or there must be an open cursor) before
7380873971
** executing this instruction.
7380973972
*/
73810
-case OP_ReadCookie: { /* out2-prerelease */
73973
+case OP_ReadCookie: { /* out2 */
7381173974
int iMeta;
7381273975
int iDb;
7381373976
int iCookie;
7381473977
7381573978
assert( p->bIsReader );
@@ -73819,10 +73982,11 @@
7381973982
assert( iDb>=0 && iDb<db->nDb );
7382073983
assert( db->aDb[iDb].pBt!=0 );
7382173984
assert( DbMaskTest(p->btreeMask, iDb) );
7382273985
7382373986
sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
73987
+ pOut = out2Prerelease(p, pOp);
7382473988
pOut->u.i = iMeta;
7382573989
break;
7382673990
}
7382773991
7382873992
/* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74304,11 @@
7414074304
VdbeCursor *pC;
7414174305
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7414274306
pC = p->apCsr[pOp->p1];
7414374307
assert( pC->pSorter );
7414474308
if( (pC->seqCount++)==0 ){
74145
- pc = pOp->p2 - 1;
74309
+ goto jump_to_p2;
7414674310
}
7414774311
break;
7414874312
}
7414974313
7415074314
/* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74481,11 @@
7431774481
** loss of information, then special processing is required... */
7431874482
if( (pIn3->flags & MEM_Int)==0 ){
7431974483
if( (pIn3->flags & MEM_Real)==0 ){
7432074484
/* If the P3 value cannot be converted into any kind of a number,
7432174485
** then the seek is not possible, so jump to P2 */
74322
- pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74486
+ VdbeBranchTaken(1,2); goto jump_to_p2;
7432374487
break;
7432474488
}
7432574489
7432674490
/* If the approximation iKey is larger than the actual real search
7432774491
** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74572,11 @@
7440874572
}
7440974573
}
7441074574
assert( pOp->p2>0 );
7441174575
VdbeBranchTaken(res!=0,2);
7441274576
if( res ){
74413
- pc = pOp->p2 - 1;
74577
+ goto jump_to_p2;
7441474578
}
7441574579
break;
7441674580
}
7441774581
7441874582
/* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74666,11 @@
7450274666
*/
7450374667
case OP_NoConflict: /* jump, in3 */
7450474668
case OP_NotFound: /* jump, in3 */
7450574669
case OP_Found: { /* jump, in3 */
7450674670
int alreadyExists;
74671
+ int takeJump;
7450774672
int ii;
7450874673
VdbeCursor *pC;
7450974674
int res;
7451074675
char *pFree;
7451174676
UnpackedRecord *pIdxKey;
@@ -74524,11 +74689,11 @@
7452474689
pC->seekOp = pOp->opcode;
7452574690
#endif
7452674691
pIn3 = &aMem[pOp->p3];
7452774692
assert( pC->pCursor!=0 );
7452874693
assert( pC->isTable==0 );
74529
- pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
74694
+ pFree = 0;
7453074695
if( pOp->p4.i>0 ){
7453174696
r.pKeyInfo = pC->pKeyInfo;
7453274697
r.nField = (u16)pOp->p4.i;
7453374698
r.aMem = pIn3;
7453474699
for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74712,24 @@
7454774712
assert( pIn3->flags & MEM_Blob );
7454874713
ExpandBlob(pIn3);
7454974714
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
7455074715
}
7455174716
pIdxKey->default_rc = 0;
74717
+ takeJump = 0;
7455274718
if( pOp->opcode==OP_NoConflict ){
7455374719
/* For the OP_NoConflict opcode, take the jump if any of the
7455474720
** input fields are NULL, since any key with a NULL will not
7455574721
** conflict */
7455674722
for(ii=0; ii<pIdxKey->nField; ii++){
7455774723
if( pIdxKey->aMem[ii].flags & MEM_Null ){
74558
- pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74724
+ takeJump = 1;
7455974725
break;
7456074726
}
7456174727
}
7456274728
}
7456374729
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74564
- if( pOp->p4.i==0 ){
74565
- sqlite3DbFree(db, pFree);
74566
- }
74730
+ sqlite3DbFree(db, pFree);
7456774731
if( rc!=SQLITE_OK ){
7456874732
break;
7456974733
}
7457074734
pC->seekResult = res;
7457174735
alreadyExists = (res==0);
@@ -74572,14 +74736,14 @@
7457274736
pC->nullRow = 1-alreadyExists;
7457374737
pC->deferredMoveto = 0;
7457474738
pC->cacheStatus = CACHE_STALE;
7457574739
if( pOp->opcode==OP_Found ){
7457674740
VdbeBranchTaken(alreadyExists!=0,2);
74577
- if( alreadyExists ) pc = pOp->p2 - 1;
74741
+ if( alreadyExists ) goto jump_to_p2;
7457874742
}else{
74579
- VdbeBranchTaken(alreadyExists==0,2);
74580
- if( !alreadyExists ) pc = pOp->p2 - 1;
74743
+ VdbeBranchTaken(takeJump||alreadyExists==0,2);
74744
+ if( takeJump || !alreadyExists ) goto jump_to_p2;
7458174745
}
7458274746
break;
7458374747
}
7458474748
7458574749
/* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74788,12 @@
7462474788
pC->movetoTarget = iKey; /* Used by OP_Delete */
7462574789
pC->nullRow = 0;
7462674790
pC->cacheStatus = CACHE_STALE;
7462774791
pC->deferredMoveto = 0;
7462874792
VdbeBranchTaken(res!=0,2);
74629
- if( res!=0 ){
74630
- pc = pOp->p2 - 1;
74631
- }
7463274793
pC->seekResult = res;
74794
+ if( res!=0 ) goto jump_to_p2;
7463374795
break;
7463474796
}
7463574797
7463674798
/* Opcode: Sequence P1 P2 * * *
7463774799
** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74801,14 @@
7463974801
** Find the next available sequence number for cursor P1.
7464074802
** Write the sequence number into register P2.
7464174803
** The sequence number on the cursor is incremented after this
7464274804
** instruction.
7464374805
*/
74644
-case OP_Sequence: { /* out2-prerelease */
74806
+case OP_Sequence: { /* out2 */
7464574807
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7464674808
assert( p->apCsr[pOp->p1]!=0 );
74809
+ pOut = out2Prerelease(p, pOp);
7464774810
pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
7464874811
break;
7464974812
}
7465074813
7465174814
@@ -74662,20 +74825,21 @@
7466274825
** allowed to be less than this value. When this value reaches its maximum,
7466374826
** an SQLITE_FULL error is generated. The P3 register is updated with the '
7466474827
** generated record number. This P3 mechanism is used to help implement the
7466574828
** AUTOINCREMENT feature.
7466674829
*/
74667
-case OP_NewRowid: { /* out2-prerelease */
74830
+case OP_NewRowid: { /* out2 */
7466874831
i64 v; /* The new rowid */
7466974832
VdbeCursor *pC; /* Cursor of table to get the new rowid */
7467074833
int res; /* Result of an sqlite3BtreeLast() */
7467174834
int cnt; /* Counter to limit the number of searches */
7467274835
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
7467374836
VdbeFrame *pFrame; /* Root frame of VDBE */
7467474837
7467574838
v = 0;
7467674839
res = 0;
74840
+ pOut = out2Prerelease(p, pOp);
7467774841
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7467874842
pC = p->apCsr[pOp->p1];
7467974843
assert( pC!=0 );
7468074844
if( NEVER(pC->pCursor==0) ){
7468174845
/* The zero initialization above is all that is needed */
@@ -74985,13 +75149,11 @@
7498575149
pIn3 = &aMem[pOp->p3];
7498675150
nKeyCol = pOp->p4.i;
7498775151
res = 0;
7498875152
rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
7498975153
VdbeBranchTaken(res!=0,2);
74990
- if( res ){
74991
- pc = pOp->p2-1;
74992
- }
75154
+ if( res ) goto jump_to_p2;
7499375155
break;
7499475156
};
7499575157
7499675158
/* Opcode: SorterData P1 P2 P3 * *
7499775159
** Synopsis: r[P2]=data
@@ -75116,16 +75278,17 @@
7511675278
**
7511775279
** P1 can be either an ordinary table or a virtual table. There used to
7511875280
** be a separate OP_VRowid opcode for use with virtual tables, but this
7511975281
** one opcode now works for both table types.
7512075282
*/
75121
-case OP_Rowid: { /* out2-prerelease */
75283
+case OP_Rowid: { /* out2 */
7512275284
VdbeCursor *pC;
7512375285
i64 v;
7512475286
sqlite3_vtab *pVtab;
7512575287
const sqlite3_module *pModule;
7512675288
75289
+ pOut = out2Prerelease(p, pOp);
7512775290
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7512875291
pC = p->apCsr[pOp->p1];
7512975292
assert( pC!=0 );
7513075293
assert( pC->pseudoTableReg==0 || pC->nullRow );
7513175294
if( pC->nullRow ){
@@ -75174,11 +75337,11 @@
7517475337
sqlite3BtreeClearCursor(pC->pCursor);
7517575338
}
7517675339
break;
7517775340
}
7517875341
75179
-/* Opcode: Last P1 P2 * * *
75342
+/* Opcode: Last P1 P2 P3 * *
7518075343
**
7518175344
** The next use of the Rowid or Column or Prev instruction for P1
7518275345
** will refer to the last entry in the database table or index.
7518375346
** If the table or index is empty and P2>0, then jump immediately to P2.
7518475347
** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75364,17 @@
7520175364
assert( pCrsr!=0 );
7520275365
rc = sqlite3BtreeLast(pCrsr, &res);
7520375366
pC->nullRow = (u8)res;
7520475367
pC->deferredMoveto = 0;
7520575368
pC->cacheStatus = CACHE_STALE;
75369
+ pC->seekResult = pOp->p3;
7520675370
#ifdef SQLITE_DEBUG
7520775371
pC->seekOp = OP_Last;
7520875372
#endif
7520975373
if( pOp->p2>0 ){
7521075374
VdbeBranchTaken(res!=0,2);
75211
- if( res ) pc = pOp->p2 - 1;
75375
+ if( res ) goto jump_to_p2;
7521275376
}
7521375377
break;
7521475378
}
7521575379
7521675380
@@ -75270,13 +75434,11 @@
7527075434
pC->cacheStatus = CACHE_STALE;
7527175435
}
7527275436
pC->nullRow = (u8)res;
7527375437
assert( pOp->p2>0 && pOp->p2<p->nOp );
7527475438
VdbeBranchTaken(res!=0,2);
75275
- if( res ){
75276
- pc = pOp->p2 - 1;
75277
- }
75439
+ if( res ) goto jump_to_p2;
7527875440
break;
7527975441
}
7528075442
7528175443
/* Opcode: Next P1 P2 P3 P4 P5
7528275444
**
@@ -75383,15 +75545,15 @@
7538375545
next_tail:
7538475546
pC->cacheStatus = CACHE_STALE;
7538575547
VdbeBranchTaken(res==0,2);
7538675548
if( res==0 ){
7538775549
pC->nullRow = 0;
75388
- pc = pOp->p2 - 1;
7538975550
p->aCounter[pOp->p5]++;
7539075551
#ifdef SQLITE_TEST
7539175552
sqlite3_search_count++;
7539275553
#endif
75554
+ goto jump_to_p2_and_check_for_interrupt;
7539375555
}else{
7539475556
pC->nullRow = 1;
7539575557
}
7539675558
goto check_for_interrupt;
7539775559
}
@@ -75495,15 +75657,16 @@
7549575657
** the end of the index key pointed to by cursor P1. This integer should be
7549675658
** the rowid of the table entry to which this index entry points.
7549775659
**
7549875660
** See also: Rowid, MakeRecord.
7549975661
*/
75500
-case OP_IdxRowid: { /* out2-prerelease */
75662
+case OP_IdxRowid: { /* out2 */
7550175663
BtCursor *pCrsr;
7550275664
VdbeCursor *pC;
7550375665
i64 rowid;
7550475666
75667
+ pOut = out2Prerelease(p, pOp);
7550575668
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7550675669
pC = p->apCsr[pOp->p1];
7550775670
assert( pC!=0 );
7550875671
pCrsr = pC->pCursor;
7550975672
assert( pCrsr!=0 );
@@ -75612,13 +75775,11 @@
7561275775
}else{
7561375776
assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
7561475777
res++;
7561575778
}
7561675779
VdbeBranchTaken(res>0,2);
75617
- if( res>0 ){
75618
- pc = pOp->p2 - 1 ;
75619
- }
75780
+ if( res>0 ) goto jump_to_p2;
7562075781
break;
7562175782
}
7562275783
7562375784
/* Opcode: Destroy P1 P2 P3 * *
7562475785
**
@@ -75638,15 +75799,16 @@
7563875799
** the last one in the database) then a zero is stored in register P2.
7563975800
** If AUTOVACUUM is disabled then a zero is stored in register P2.
7564075801
**
7564175802
** See also: Clear
7564275803
*/
75643
-case OP_Destroy: { /* out2-prerelease */
75804
+case OP_Destroy: { /* out2 */
7564475805
int iMoved;
7564575806
int iDb;
7564675807
7564775808
assert( p->readOnly==0 );
75809
+ pOut = out2Prerelease(p, pOp);
7564875810
pOut->flags = MEM_Null;
7564975811
if( db->nVdbeRead > db->nVDestroy+1 ){
7565075812
rc = SQLITE_LOCKED;
7565175813
p->errorAction = OE_Abort;
7565275814
}else{
@@ -75751,16 +75913,17 @@
7575175913
** P1>1. Write the root page number of the new table into
7575275914
** register P2.
7575375915
**
7575475916
** See documentation on OP_CreateTable for additional information.
7575575917
*/
75756
-case OP_CreateIndex: /* out2-prerelease */
75757
-case OP_CreateTable: { /* out2-prerelease */
75918
+case OP_CreateIndex: /* out2 */
75919
+case OP_CreateTable: { /* out2 */
7575875920
int pgno;
7575975921
int flags;
7576075922
Db *pDb;
7576175923
75924
+ pOut = out2Prerelease(p, pOp);
7576275925
pgno = 0;
7576375926
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7576475927
assert( DbMaskTest(p->btreeMask, pOp->p1) );
7576575928
assert( p->readOnly==0 );
7576675929
pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76145,16 @@
7598276145
if( (pIn1->flags & MEM_RowSet)==0
7598376146
|| sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
7598476147
){
7598576148
/* The boolean index is empty */
7598676149
sqlite3VdbeMemSetNull(pIn1);
75987
- pc = pOp->p2 - 1;
7598876150
VdbeBranchTaken(1,2);
76151
+ goto jump_to_p2_and_check_for_interrupt;
7598976152
}else{
7599076153
/* A value was pulled from the index */
75991
- sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7599276154
VdbeBranchTaken(0,2);
76155
+ sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7599376156
}
7599476157
goto check_for_interrupt;
7599576158
}
7599676159
7599776160
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76201,11 @@
7603876201
assert( pOp->p4type==P4_INT32 );
7603976202
assert( iSet==-1 || iSet>=0 );
7604076203
if( iSet ){
7604176204
exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
7604276205
VdbeBranchTaken(exists!=0,2);
76043
- if( exists ){
76044
- pc = pOp->p2 - 1;
76045
- break;
76046
- }
76206
+ if( exists ) goto jump_to_p2;
7604776207
}
7604876208
if( iSet>=0 ){
7604976209
sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
7605076210
}
7605176211
break;
@@ -76130,11 +76290,11 @@
7613076290
pRt->u.pFrame = pFrame;
7613176291
7613276292
pFrame->v = p;
7613376293
pFrame->nChildMem = nMem;
7613476294
pFrame->nChildCsr = pProgram->nCsr;
76135
- pFrame->pc = pc;
76295
+ pFrame->pc = (int)(pOp - aOp);
7613676296
pFrame->aMem = p->aMem;
7613776297
pFrame->nMem = p->nMem;
7613876298
pFrame->apCsr = p->apCsr;
7613976299
pFrame->nCursor = p->nCursor;
7614076300
pFrame->aOp = p->aOp;
@@ -76153,11 +76313,11 @@
7615376313
}
7615476314
}else{
7615576315
pFrame = pRt->u.pFrame;
7615676316
assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
7615776317
assert( pProgram->nCsr==pFrame->nChildCsr );
76158
- assert( pc==pFrame->pc );
76318
+ assert( (int)(pOp - aOp)==pFrame->pc );
7615976319
}
7616076320
7616176321
p->nFrame++;
7616276322
pFrame->pParent = p->pFrame;
7616376323
pFrame->lastRowid = lastRowid;
@@ -76174,11 +76334,11 @@
7617476334
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
7617576335
p->nOnceFlag = pProgram->nOnce;
7617676336
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
7617776337
p->anExec = 0;
7617876338
#endif
76179
- pc = -1;
76339
+ pOp = &aOp[-1];
7618076340
memset(p->aOnceFlag, 0, p->nOnceFlag);
7618176341
7618276342
break;
7618376343
}
7618476344
@@ -76192,13 +76352,14 @@
7619276352
**
7619376353
** The address of the cell in the parent frame is determined by adding
7619476354
** the value of the P1 argument to the value of the P1 argument to the
7619576355
** calling OP_Program instruction.
7619676356
*/
76197
-case OP_Param: { /* out2-prerelease */
76357
+case OP_Param: { /* out2 */
7619876358
VdbeFrame *pFrame;
7619976359
Mem *pIn;
76360
+ pOut = out2Prerelease(p, pOp);
7620076361
pFrame = p->pFrame;
7620176362
pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
7620276363
sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
7620376364
break;
7620476365
}
@@ -76238,14 +76399,14 @@
7623876399
** (immediate foreign key constraint violations).
7623976400
*/
7624076401
case OP_FkIfZero: { /* jump */
7624176402
if( pOp->p1 ){
7624276403
VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76243
- if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76404
+ if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
7624476405
}else{
7624576406
VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76246
- if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76407
+ if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
7624776408
}
7624876409
break;
7624976410
}
7625076411
#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
7625176412
@@ -76292,13 +76453,11 @@
7629276453
*/
7629376454
case OP_IfPos: { /* jump, in1 */
7629476455
pIn1 = &aMem[pOp->p1];
7629576456
assert( pIn1->flags&MEM_Int );
7629676457
VdbeBranchTaken( pIn1->u.i>0, 2);
76297
- if( pIn1->u.i>0 ){
76298
- pc = pOp->p2 - 1;
76299
- }
76458
+ if( pIn1->u.i>0 ) goto jump_to_p2;
7630076459
break;
7630176460
}
7630276461
7630376462
/* Opcode: IfNeg P1 P2 P3 * *
7630476463
** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76468,11 @@
7630976468
case OP_IfNeg: { /* jump, in1 */
7631076469
pIn1 = &aMem[pOp->p1];
7631176470
assert( pIn1->flags&MEM_Int );
7631276471
pIn1->u.i += pOp->p3;
7631376472
VdbeBranchTaken(pIn1->u.i<0, 2);
76314
- if( pIn1->u.i<0 ){
76315
- pc = pOp->p2 - 1;
76316
- }
76473
+ if( pIn1->u.i<0 ) goto jump_to_p2;
7631776474
break;
7631876475
}
7631976476
7632076477
/* Opcode: IfNotZero P1 P2 P3 * *
7632176478
** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76485,11 @@
7632876485
pIn1 = &aMem[pOp->p1];
7632976486
assert( pIn1->flags&MEM_Int );
7633076487
VdbeBranchTaken(pIn1->u.i<0, 2);
7633176488
if( pIn1->u.i ){
7633276489
pIn1->u.i += pOp->p3;
76333
- pc = pOp->p2 - 1;
76490
+ goto jump_to_p2;
7633476491
}
7633576492
break;
7633676493
}
7633776494
7633876495
/* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76501,11 @@
7634476501
case OP_DecrJumpZero: { /* jump, in1 */
7634576502
pIn1 = &aMem[pOp->p1];
7634676503
assert( pIn1->flags&MEM_Int );
7634776504
pIn1->u.i--;
7634876505
VdbeBranchTaken(pIn1->u.i==0, 2);
76349
- if( pIn1->u.i==0 ){
76350
- pc = pOp->p2 - 1;
76351
- }
76506
+ if( pIn1->u.i==0 ) goto jump_to_p2;
7635276507
break;
7635376508
}
7635476509
7635576510
7635676511
/* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76517,11 @@
7636276517
*/
7636376518
case OP_JumpZeroIncr: { /* jump, in1 */
7636476519
pIn1 = &aMem[pOp->p1];
7636576520
assert( pIn1->flags&MEM_Int );
7636676521
VdbeBranchTaken(pIn1->u.i==0, 2);
76367
- if( (pIn1->u.i++)==0 ){
76368
- pc = pOp->p2 - 1;
76369
- }
76522
+ if( (pIn1->u.i++)==0 ) goto jump_to_p2;
7637076523
break;
7637176524
}
7637276525
7637376526
/* Opcode: AggStep * P2 P3 P4 P5
7637476527
** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76559,11 @@
7640676559
pMem->n++;
7640776560
sqlite3VdbeMemInit(&t, db, MEM_Null);
7640876561
ctx.pOut = &t;
7640976562
ctx.isError = 0;
7641076563
ctx.pVdbe = p;
76411
- ctx.iOp = pc;
76564
+ ctx.iOp = (int)(pOp - aOp);
7641276565
ctx.skipFlag = 0;
7641376566
(ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
7641476567
if( ctx.isError ){
7641576568
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
7641676569
rc = ctx.isError;
@@ -76501,19 +76654,20 @@
7650176654
**
7650276655
** If changing into or out of WAL mode the procedure is more complicated.
7650376656
**
7650476657
** Write a string containing the final journal-mode to register P2.
7650576658
*/
76506
-case OP_JournalMode: { /* out2-prerelease */
76659
+case OP_JournalMode: { /* out2 */
7650776660
Btree *pBt; /* Btree to change journal mode of */
7650876661
Pager *pPager; /* Pager associated with pBt */
7650976662
int eNew; /* New journal mode */
7651076663
int eOld; /* The old journal mode */
7651176664
#ifndef SQLITE_OMIT_WAL
7651276665
const char *zFilename; /* Name of database file for pPager */
7651376666
#endif
7651476667
76668
+ pOut = out2Prerelease(p, pOp);
7651576669
eNew = pOp->p3;
7651676670
assert( eNew==PAGER_JOURNALMODE_DELETE
7651776671
|| eNew==PAGER_JOURNALMODE_TRUNCATE
7651876672
|| eNew==PAGER_JOURNALMODE_PERSIST
7651976673
|| eNew==PAGER_JOURNALMODE_OFF
@@ -76585,11 +76739,10 @@
7658576739
if( rc ){
7658676740
eNew = eOld;
7658776741
}
7658876742
eNew = sqlite3PagerSetJournalMode(pPager, eNew);
7658976743
76590
- pOut = &aMem[pOp->p2];
7659176744
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
7659276745
pOut->z = (char *)sqlite3JournalModename(eNew);
7659376746
pOut->n = sqlite3Strlen30(pOut->z);
7659476747
pOut->enc = SQLITE_UTF8;
7659576748
sqlite3VdbeChangeEncoding(pOut, encoding);
@@ -76626,12 +76779,12 @@
7662676779
assert( p->readOnly==0 );
7662776780
pBt = db->aDb[pOp->p1].pBt;
7662876781
rc = sqlite3BtreeIncrVacuum(pBt);
7662976782
VdbeBranchTaken(rc==SQLITE_DONE,2);
7663076783
if( rc==SQLITE_DONE ){
76631
- pc = pOp->p2 - 1;
7663276784
rc = SQLITE_OK;
76785
+ goto jump_to_p2;
7663376786
}
7663476787
break;
7663576788
}
7663676789
#endif
7663776790
@@ -76780,12 +76933,13 @@
7678076933
pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
7678176934
if( pCur ){
7678276935
pCur->pVtabCursor = pVtabCursor;
7678376936
pVtab->nRef++;
7678476937
}else{
76785
- db->mallocFailed = 1;
76938
+ assert( db->mallocFailed );
7678676939
pModule->xClose(pVtabCursor);
76940
+ goto no_mem;
7678776941
}
7678876942
}
7678976943
break;
7679076944
}
7679176945
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76991,23 @@
7683776991
assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
7683876992
nArg = (int)pArgc->u.i;
7683976993
iQuery = (int)pQuery->u.i;
7684076994
7684176995
/* Invoke the xFilter method */
76842
- {
76843
- res = 0;
76844
- apArg = p->apArg;
76845
- for(i = 0; i<nArg; i++){
76846
- apArg[i] = &pArgc[i+1];
76847
- }
76848
-
76849
- rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76850
- sqlite3VtabImportErrmsg(p, pVtab);
76851
- if( rc==SQLITE_OK ){
76852
- res = pModule->xEof(pVtabCursor);
76853
- }
76854
- VdbeBranchTaken(res!=0,2);
76855
- if( res ){
76856
- pc = pOp->p2 - 1;
76857
- }
76996
+ res = 0;
76997
+ apArg = p->apArg;
76998
+ for(i = 0; i<nArg; i++){
76999
+ apArg[i] = &pArgc[i+1];
77000
+ }
77001
+ rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
77002
+ sqlite3VtabImportErrmsg(p, pVtab);
77003
+ if( rc==SQLITE_OK ){
77004
+ res = pModule->xEof(pVtabCursor);
7685877005
}
7685977006
pCur->nullRow = 0;
76860
-
77007
+ VdbeBranchTaken(res!=0,2);
77008
+ if( res ) goto jump_to_p2;
7686177009
break;
7686277010
}
7686377011
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7686477012
7686577013
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77090,11 @@
7694277090
res = pModule->xEof(pCur->pVtabCursor);
7694377091
}
7694477092
VdbeBranchTaken(!res,2);
7694577093
if( !res ){
7694677094
/* If there is data, jump to P2 */
76947
- pc = pOp->p2 - 1;
77095
+ goto jump_to_p2_and_check_for_interrupt;
7694877096
}
7694977097
goto check_for_interrupt;
7695077098
}
7695177099
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7695277100
@@ -77065,11 +77213,12 @@
7706577213
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
7706677214
/* Opcode: Pagecount P1 P2 * * *
7706777215
**
7706877216
** Write the current number of pages in database P1 to memory cell P2.
7706977217
*/
77070
-case OP_Pagecount: { /* out2-prerelease */
77218
+case OP_Pagecount: { /* out2 */
77219
+ pOut = out2Prerelease(p, pOp);
7707177220
pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
7707277221
break;
7707377222
}
7707477223
#endif
7707577224
@@ -77081,14 +77230,15 @@
7708177230
** Do not let the maximum page count fall below the current page count and
7708277231
** do not change the maximum page count value if P3==0.
7708377232
**
7708477233
** Store the maximum page count after the change in register P2.
7708577234
*/
77086
-case OP_MaxPgcnt: { /* out2-prerelease */
77235
+case OP_MaxPgcnt: { /* out2 */
7708777236
unsigned int newMax;
7708877237
Btree *pBt;
7708977238
77239
+ pOut = out2Prerelease(p, pOp);
7709077240
pBt = db->aDb[pOp->p1].pBt;
7709177241
newMax = 0;
7709277242
if( pOp->p3 ){
7709377243
newMax = sqlite3BtreeLastPage(pBt);
7709477244
if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77263,10 @@
7711377263
*/
7711477264
case OP_Init: { /* jump */
7711577265
char *zTrace;
7711677266
char *z;
7711777267
77118
- if( pOp->p2 ){
77119
- pc = pOp->p2 - 1;
77120
- }
7712177268
#ifndef SQLITE_OMIT_TRACE
7712277269
if( db->xTrace
7712377270
&& !p->doingRerun
7712477271
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7712577272
){
@@ -77143,10 +77290,11 @@
7714377290
){
7714477291
sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
7714577292
}
7714677293
#endif /* SQLITE_DEBUG */
7714777294
#endif /* SQLITE_OMIT_TRACE */
77295
+ if( pOp->p2 ) goto jump_to_p2;
7714877296
break;
7714977297
}
7715077298
7715177299
7715277300
/* Opcode: Noop * * * * *
@@ -77174,31 +77322,31 @@
7717477322
}
7717577323
7717677324
#ifdef VDBE_PROFILE
7717777325
{
7717877326
u64 endTime = sqlite3Hwtime();
77179
- if( endTime>start ) pOp->cycles += endTime - start;
77180
- pOp->cnt++;
77327
+ if( endTime>start ) pOrigOp->cycles += endTime - start;
77328
+ pOrigOp->cnt++;
7718177329
}
7718277330
#endif
7718377331
7718477332
/* The following code adds nothing to the actual functionality
7718577333
** of the program. It is only here for testing and debugging.
7718677334
** On the other hand, it does burn CPU cycles every time through
7718777335
** the evaluator loop. So we can leave it out when NDEBUG is defined.
7718877336
*/
7718977337
#ifndef NDEBUG
77190
- assert( pc>=-1 && pc<p->nOp );
77338
+ assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
7719177339
7719277340
#ifdef SQLITE_DEBUG
7719377341
if( db->flags & SQLITE_VdbeTrace ){
7719477342
if( rc!=0 ) printf("rc=%d\n",rc);
77195
- if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
77196
- registerTrace(pOp->p2, &aMem[pOp->p2]);
77343
+ if( pOrigOp->opflags & (OPFLG_OUT2) ){
77344
+ registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
7719777345
}
77198
- if( pOp->opflags & OPFLG_OUT3 ){
77199
- registerTrace(pOp->p3, &aMem[pOp->p3]);
77346
+ if( pOrigOp->opflags & OPFLG_OUT3 ){
77347
+ registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
7720077348
}
7720177349
}
7720277350
#endif /* SQLITE_DEBUG */
7720377351
#endif /* NDEBUG */
7720477352
} /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77357,11 @@
7720977357
vdbe_error_halt:
7721077358
assert( rc );
7721177359
p->rc = rc;
7721277360
testcase( sqlite3GlobalConfig.xLog!=0 );
7721377361
sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77214
- pc, p->zSql, p->zErrMsg);
77362
+ (int)(pOp - aOp), p->zSql, p->zErrMsg);
7721577363
sqlite3VdbeHalt(p);
7721677364
if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
7721777365
rc = SQLITE_ERROR;
7721877366
if( resetSchemaOnFault>0 ){
7721977367
sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78183,23 @@
7803578183
**
7803678184
** In both cases, the effects of the main thread seeing (bDone==0) even
7803778185
** after the thread has finished are not dire. So we don't worry about
7803878186
** memory barriers and such here.
7803978187
*/
78188
+typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int);
7804078189
struct SortSubtask {
7804178190
SQLiteThread *pThread; /* Background thread, if any */
7804278191
int bDone; /* Set if thread is finished but not joined */
7804378192
VdbeSorter *pSorter; /* Sorter that owns this sub-task */
7804478193
UnpackedRecord *pUnpacked; /* Space to unpack a record */
7804578194
SorterList list; /* List for thread to write to a PMA */
7804678195
int nPMA; /* Number of PMAs currently in file */
78196
+ SorterCompare xCompare; /* Compare function to use */
7804778197
SorterFile file; /* Temp file for level-0 PMAs */
7804878198
SorterFile file2; /* Space for other PMAs */
7804978199
};
78200
+
7805078201
7805178202
/*
7805278203
** Main sorter structure. A single instance of this is allocated for each
7805378204
** sorter cursor created by the VDBE.
7805478205
**
@@ -78072,12 +78223,16 @@
7807278223
int nMemory; /* Size of list.aMemory allocation in bytes */
7807378224
u8 bUsePMA; /* True if one or more PMAs created */
7807478225
u8 bUseThreads; /* True to use background threads */
7807578226
u8 iPrev; /* Previous thread used to flush PMA */
7807678227
u8 nTask; /* Size of aTask[] array */
78228
+ u8 typeMask;
7807778229
SortSubtask aTask[1]; /* One or more subtasks */
7807878230
};
78231
+
78232
+#define SORTER_TYPE_INTEGER 0x01
78233
+#define SORTER_TYPE_TEXT 0x02
7807978234
7808078235
/*
7808178236
** An instance of the following object is used to read records out of a
7808278237
** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
7808378238
** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78641,165 @@
7848678641
rc = vdbePmaReaderNext(pReadr);
7848778642
}
7848878643
return rc;
7848978644
}
7849078645
78646
+/*
78647
+** A version of vdbeSorterCompare() that assumes that it has already been
78648
+** determined that the first field of key1 is equal to the first field of
78649
+** key2.
78650
+*/
78651
+static int vdbeSorterCompareTail(
78652
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78653
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78654
+ const void *pKey1, int nKey1, /* Left side of comparison */
78655
+ const void *pKey2, int nKey2 /* Right side of comparison */
78656
+){
78657
+ UnpackedRecord *r2 = pTask->pUnpacked;
78658
+ if( *pbKey2Cached==0 ){
78659
+ sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78660
+ *pbKey2Cached = 1;
78661
+ }
78662
+ return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
78663
+}
7849178664
7849278665
/*
7849378666
** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
7849478667
** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
7849578668
** used by the comparison. Return the result of the comparison.
7849678669
**
78497
-** Before returning, object (pTask->pUnpacked) is populated with the
78498
-** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it
78499
-** is assumed that the (pTask->pUnpacked) structure already contains the
78500
-** unpacked key to use as key2.
78670
+** If IN/OUT parameter *pbKey2Cached is true when this function is called,
78671
+** it is assumed that (pTask->pUnpacked) contains the unpacked version
78672
+** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
78673
+** version of key2 and *pbKey2Cached set to true before returning.
7850178674
**
7850278675
** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
7850378676
** to SQLITE_NOMEM.
7850478677
*/
7850578678
static int vdbeSorterCompare(
7850678679
SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78680
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
7850778681
const void *pKey1, int nKey1, /* Left side of comparison */
7850878682
const void *pKey2, int nKey2 /* Right side of comparison */
7850978683
){
7851078684
UnpackedRecord *r2 = pTask->pUnpacked;
78511
- if( pKey2 ){
78685
+ if( !*pbKey2Cached ){
7851278686
sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78687
+ *pbKey2Cached = 1;
7851378688
}
7851478689
return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
7851578690
}
78691
+
78692
+/*
78693
+** A specially optimized version of vdbeSorterCompare() that assumes that
78694
+** the first field of each key is a TEXT value and that the collation
78695
+** sequence to compare them with is BINARY.
78696
+*/
78697
+static int vdbeSorterCompareText(
78698
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78699
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78700
+ const void *pKey1, int nKey1, /* Left side of comparison */
78701
+ const void *pKey2, int nKey2 /* Right side of comparison */
78702
+){
78703
+ const u8 * const p1 = (const u8 * const)pKey1;
78704
+ const u8 * const p2 = (const u8 * const)pKey2;
78705
+ const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78706
+ const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78707
+
78708
+ int n1;
78709
+ int n2;
78710
+ int res;
78711
+
78712
+ getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2;
78713
+ getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2;
78714
+ res = memcmp(v1, v2, MIN(n1, n2));
78715
+ if( res==0 ){
78716
+ res = n1 - n2;
78717
+ }
78718
+
78719
+ if( res==0 ){
78720
+ if( pTask->pSorter->pKeyInfo->nField>1 ){
78721
+ res = vdbeSorterCompareTail(
78722
+ pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78723
+ );
78724
+ }
78725
+ }else{
78726
+ if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78727
+ res = res * -1;
78728
+ }
78729
+ }
78730
+
78731
+ return res;
78732
+}
78733
+
78734
+/*
78735
+** A specially optimized version of vdbeSorterCompare() that assumes that
78736
+** the first field of each key is an INTEGER value.
78737
+*/
78738
+static int vdbeSorterCompareInt(
78739
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78740
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78741
+ const void *pKey1, int nKey1, /* Left side of comparison */
78742
+ const void *pKey2, int nKey2 /* Right side of comparison */
78743
+){
78744
+ const u8 * const p1 = (const u8 * const)pKey1;
78745
+ const u8 * const p2 = (const u8 * const)pKey2;
78746
+ const int s1 = p1[1]; /* Left hand serial type */
78747
+ const int s2 = p2[1]; /* Right hand serial type */
78748
+ const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78749
+ const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78750
+ int res; /* Return value */
78751
+
78752
+ assert( (s1>0 && s1<7) || s1==8 || s1==9 );
78753
+ assert( (s2>0 && s2<7) || s2==8 || s2==9 );
78754
+
78755
+ if( s1>7 && s2>7 ){
78756
+ res = s1 - s2;
78757
+ }else{
78758
+ if( s1==s2 ){
78759
+ if( (*v1 ^ *v2) & 0x80 ){
78760
+ /* The two values have different signs */
78761
+ res = (*v1 & 0x80) ? -1 : +1;
78762
+ }else{
78763
+ /* The two values have the same sign. Compare using memcmp(). */
78764
+ static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
78765
+ int i;
78766
+ res = 0;
78767
+ for(i=0; i<aLen[s1]; i++){
78768
+ if( (res = v1[i] - v2[i]) ) break;
78769
+ }
78770
+ }
78771
+ }else{
78772
+ if( s2>7 ){
78773
+ res = +1;
78774
+ }else if( s1>7 ){
78775
+ res = -1;
78776
+ }else{
78777
+ res = s1 - s2;
78778
+ }
78779
+ assert( res!=0 );
78780
+
78781
+ if( res>0 ){
78782
+ if( *v1 & 0x80 ) res = -1;
78783
+ }else{
78784
+ if( *v2 & 0x80 ) res = +1;
78785
+ }
78786
+ }
78787
+ }
78788
+
78789
+ if( res==0 ){
78790
+ if( pTask->pSorter->pKeyInfo->nField>1 ){
78791
+ res = vdbeSorterCompareTail(
78792
+ pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78793
+ );
78794
+ }
78795
+ }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78796
+ res = res * -1;
78797
+ }
78798
+
78799
+ return res;
78800
+}
7851678801
7851778802
/*
7851878803
** Initialize the temporary index cursor just opened as a sorter cursor.
7851978804
**
7852078805
** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78864,17 @@
7857978864
rc = SQLITE_NOMEM;
7858078865
}else{
7858178866
pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
7858278867
memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
7858378868
pKeyInfo->db = 0;
78584
- if( nField && nWorker==0 ) pKeyInfo->nField = nField;
78869
+ if( nField && nWorker==0 ){
78870
+ pKeyInfo->nXField += (pKeyInfo->nField - nField);
78871
+ pKeyInfo->nField = nField;
78872
+ }
7858578873
pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
7858678874
pSorter->nTask = nWorker + 1;
78875
+ pSorter->iPrev = nWorker-1;
7858778876
pSorter->bUseThreads = (pSorter->nTask>1);
7858878877
pSorter->db = db;
7858978878
for(i=0; i<pSorter->nTask; i++){
7859078879
SortSubtask *pTask = &pSorter->aTask[i];
7859178880
pTask->pSorter = pSorter;
@@ -78607,10 +78896,16 @@
7860778896
pSorter->nMemory = pgsz;
7860878897
pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
7860978898
if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
7861078899
}
7861178900
}
78901
+
78902
+ if( (pKeyInfo->nField+pKeyInfo->nXField)<13
78903
+ && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
78904
+ ){
78905
+ pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
78906
+ }
7861278907
}
7861378908
7861478909
return rc;
7861578910
}
7861678911
#undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78926,28 @@
7863178926
** Free all resources owned by the object indicated by argument pTask. All
7863278927
** fields of *pTask are zeroed before returning.
7863378928
*/
7863478929
static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
7863578930
sqlite3DbFree(db, pTask->pUnpacked);
78636
- pTask->pUnpacked = 0;
7863778931
#if SQLITE_MAX_WORKER_THREADS>0
7863878932
/* pTask->list.aMemory can only be non-zero if it was handed memory
7863978933
** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
7864078934
if( pTask->list.aMemory ){
7864178935
sqlite3_free(pTask->list.aMemory);
78642
- pTask->list.aMemory = 0;
7864378936
}else
7864478937
#endif
7864578938
{
7864678939
assert( pTask->list.aMemory==0 );
7864778940
vdbeSorterRecordFree(0, pTask->list.pList);
7864878941
}
78649
- pTask->list.pList = 0;
7865078942
if( pTask->file.pFd ){
7865178943
sqlite3OsCloseFree(pTask->file.pFd);
78652
- pTask->file.pFd = 0;
78653
- pTask->file.iEof = 0;
7865478944
}
7865578945
if( pTask->file2.pFd ){
7865678946
sqlite3OsCloseFree(pTask->file2.pFd);
78657
- pTask->file2.pFd = 0;
78658
- pTask->file2.iEof = 0;
7865978947
}
78948
+ memset(pTask, 0, sizeof(SortSubtask));
7866078949
}
7866178950
7866278951
#ifdef SQLITE_DEBUG_SORTER_THREADS
7866378952
static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
7866478953
i64 t;
@@ -78834,10 +79123,11 @@
7883479123
vdbeMergeEngineFree(pSorter->pMerger);
7883579124
pSorter->pMerger = 0;
7883679125
for(i=0; i<pSorter->nTask; i++){
7883779126
SortSubtask *pTask = &pSorter->aTask[i];
7883879127
vdbeSortSubtaskCleanup(db, pTask);
79128
+ pTask->pSorter = pSorter;
7883979129
}
7884079130
if( pSorter->list.aMemory==0 ){
7884179131
vdbeSorterRecordFree(0, pSorter->list.pList);
7884279132
}
7884379133
pSorter->list.pList = 0;
@@ -78943,31 +79233,45 @@
7894379233
SorterRecord *p2, /* Second list to merge */
7894479234
SorterRecord **ppOut /* OUT: Head of merged list */
7894579235
){
7894679236
SorterRecord *pFinal = 0;
7894779237
SorterRecord **pp = &pFinal;
78948
- void *pVal2 = p2 ? SRVAL(p2) : 0;
79238
+ int bCached = 0;
7894979239
7895079240
while( p1 && p2 ){
7895179241
int res;
78952
- res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal);
79242
+ res = pTask->xCompare(
79243
+ pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
79244
+ );
79245
+
7895379246
if( res<=0 ){
7895479247
*pp = p1;
7895579248
pp = &p1->u.pNext;
7895679249
p1 = p1->u.pNext;
78957
- pVal2 = 0;
7895879250
}else{
7895979251
*pp = p2;
78960
- pp = &p2->u.pNext;
79252
+ pp = &p2->u.pNext;
7896179253
p2 = p2->u.pNext;
78962
- if( p2==0 ) break;
78963
- pVal2 = SRVAL(p2);
79254
+ bCached = 0;
7896479255
}
7896579256
}
7896679257
*pp = p1 ? p1 : p2;
7896779258
*ppOut = pFinal;
7896879259
}
79260
+
79261
+/*
79262
+** Return the SorterCompare function to compare values collected by the
79263
+** sorter object passed as the only argument.
79264
+*/
79265
+static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){
79266
+ if( p->typeMask==SORTER_TYPE_INTEGER ){
79267
+ return vdbeSorterCompareInt;
79268
+ }else if( p->typeMask==SORTER_TYPE_TEXT ){
79269
+ return vdbeSorterCompareText;
79270
+ }
79271
+ return vdbeSorterCompare;
79272
+}
7896979273
7897079274
/*
7897179275
** Sort the linked list of records headed at pTask->pList. Return
7897279276
** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
7897379277
** an error occurs.
@@ -78979,16 +79283,18 @@
7897979283
int rc;
7898079284
7898179285
rc = vdbeSortAllocUnpacked(pTask);
7898279286
if( rc!=SQLITE_OK ) return rc;
7898379287
79288
+ p = pList->pList;
79289
+ pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
79290
+
7898479291
aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
7898579292
if( !aSlot ){
7898679293
return SQLITE_NOMEM;
7898779294
}
7898879295
78989
- p = pList->pList;
7899079296
while( p ){
7899179297
SorterRecord *pNext;
7899279298
if( pList->aMemory ){
7899379299
if( (u8*)p==pList->aMemory ){
7899479300
pNext = 0;
@@ -79198,28 +79504,27 @@
7919879504
/* Update contents of aTree[] */
7919979505
if( rc==SQLITE_OK ){
7920079506
int i; /* Index of aTree[] to recalculate */
7920179507
PmaReader *pReadr1; /* First PmaReader to compare */
7920279508
PmaReader *pReadr2; /* Second PmaReader to compare */
79203
- u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */
79509
+ int bCached = 0;
7920479510
7920579511
/* Find the first two PmaReaders to compare. The one that was just
7920679512
** advanced (iPrev) and the one next to it in the array. */
7920779513
pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
7920879514
pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
79209
- pKey2 = pReadr2->aKey;
7921079515
7921179516
for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
7921279517
/* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
7921379518
int iRes;
7921479519
if( pReadr1->pFd==0 ){
7921579520
iRes = +1;
7921679521
}else if( pReadr2->pFd==0 ){
7921779522
iRes = -1;
7921879523
}else{
79219
- iRes = vdbeSorterCompare(pTask,
79220
- pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey
79524
+ iRes = pTask->xCompare(pTask, &bCached,
79525
+ pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
7922179526
);
7922279527
}
7922379528
7922479529
/* If pReadr1 contained the smaller value, set aTree[i] to its index.
7922579530
** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79542,13 @@
7923779542
** is sorted from oldest to newest, so pReadr1 contains older values
7923879543
** than pReadr2 iff (pReadr1<pReadr2). */
7923979544
if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
7924079545
pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
7924179546
pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79242
- pKey2 = pReadr2->aKey;
79547
+ bCached = 0;
7924379548
}else{
79244
- if( pReadr1->pFd ) pKey2 = 0;
79549
+ if( pReadr1->pFd ) bCached = 0;
7924579550
pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
7924679551
pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
7924779552
}
7924879553
}
7924979554
*pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79651,20 @@
7934679651
SorterRecord *pNew; /* New list element */
7934779652
7934879653
int bFlush; /* True to flush contents of memory to PMA */
7934979654
int nReq; /* Bytes of memory required */
7935079655
int nPMA; /* Bytes of PMA space required */
79656
+ int t; /* serial type of first record field */
79657
+
79658
+ getVarint32((const u8*)&pVal->z[1], t);
79659
+ if( t>0 && t<10 && t!=7 ){
79660
+ pSorter->typeMask &= SORTER_TYPE_INTEGER;
79661
+ }else if( t>10 && (t & 0x01) ){
79662
+ pSorter->typeMask &= SORTER_TYPE_TEXT;
79663
+ }else{
79664
+ pSorter->typeMask = 0;
79665
+ }
7935179666
7935279667
assert( pSorter );
7935379668
7935479669
/* Figure out whether or not the current contents of memory should be
7935579670
** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79926,16 @@
7961179926
if( p1->pFd==0 ){
7961279927
iRes = i2;
7961379928
}else if( p2->pFd==0 ){
7961479929
iRes = i1;
7961579930
}else{
79931
+ SortSubtask *pTask = pMerger->pTask;
79932
+ int bCached = 0;
7961679933
int res;
79617
- assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79618
- res = vdbeSorterCompare(
79619
- pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79934
+ assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79935
+ res = pTask->xCompare(
79936
+ pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey
7962079937
);
7962179938
if( res<=0 ){
7962279939
iRes = i1;
7962379940
}else{
7962479941
iRes = i2;
@@ -79638,15 +79955,16 @@
7963879955
*/
7963979956
#define INCRINIT_NORMAL 0
7964079957
#define INCRINIT_TASK 1
7964179958
#define INCRINIT_ROOT 2
7964279959
79643
-/* Forward reference.
79644
-** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each
79645
-** other (when building a merge tree).
79960
+/*
79961
+** Forward reference required as the vdbeIncrMergeInit() and
79962
+** vdbePmaReaderIncrInit() routines are called mutually recursively when
79963
+** building a merge tree.
7964679964
*/
79647
-static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode);
79965
+static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode);
7964879966
7964979967
/*
7965079968
** Initialize the MergeEngine object passed as the second argument. Once this
7965179969
** function returns, the first key of merged data may be read from the
7965279970
** MergeEngine object in the usual fashion.
@@ -79689,11 +80007,11 @@
7968980007
** the main thread to fill its buffer. So calling PmaReaderNext()
7969080008
** on this PmaReader before any of the multi-threaded PmaReaders takes
7969180009
** better advantage of multi-processor hardware. */
7969280010
rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
7969380011
}else{
79694
- rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
80012
+ rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
7969580013
}
7969680014
if( rc!=SQLITE_OK ) return rc;
7969780015
}
7969880016
7969980017
for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80019,19 @@
7970180019
}
7970280020
return pTask->pUnpacked->errCode;
7970380021
}
7970480022
7970580023
/*
79706
-** Initialize the IncrMerge field of a PmaReader.
79707
-**
79708
-** If the PmaReader passed as the first argument is not an incremental-reader
79709
-** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves
79710
-** to open and/or initialize the temp file related fields of the IncrMerge
80024
+** The PmaReader passed as the first argument is guaranteed to be an
80025
+** incremental-reader (pReadr->pIncr!=0). This function serves to open
80026
+** and/or initialize the temp file related fields of the IncrMerge
7971180027
** object at (pReadr->pIncr).
7971280028
**
7971380029
** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
79714
-** in the sub-tree headed by pReadr are also initialized. Data is then loaded
79715
-** into the buffers belonging to pReadr and it is set to
79716
-** point to the first key in its range.
80030
+** in the sub-tree headed by pReadr are also initialized. Data is then
80031
+** loaded into the buffers belonging to pReadr and it is set to point to
80032
+** the first key in its range.
7971780033
**
7971880034
** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
7971980035
** to be a multi-threaded PmaReader and this function is being called in a
7972080036
** background thread. In this case all PmaReaders in the sub-tree are
7972180037
** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80054,112 @@
7973880054
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
7973980055
*/
7974080056
static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
7974180057
int rc = SQLITE_OK;
7974280058
IncrMerger *pIncr = pReadr->pIncr;
80059
+ SortSubtask *pTask = pIncr->pTask;
80060
+ sqlite3 *db = pTask->pSorter->db;
7974380061
7974480062
/* eMode is always INCRINIT_NORMAL in single-threaded mode */
7974580063
assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
7974680064
79747
- if( pIncr ){
79748
- SortSubtask *pTask = pIncr->pTask;
79749
- sqlite3 *db = pTask->pSorter->db;
79750
-
79751
- rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
79752
-
79753
- /* Set up the required files for pIncr. A multi-theaded IncrMerge object
79754
- ** requires two temp files to itself, whereas a single-threaded object
79755
- ** only requires a region of pTask->file2. */
79756
- if( rc==SQLITE_OK ){
79757
- int mxSz = pIncr->mxSz;
79758
-#if SQLITE_MAX_WORKER_THREADS>0
79759
- if( pIncr->bUseThread ){
79760
- rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
79761
- if( rc==SQLITE_OK ){
79762
- rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
79763
- }
79764
- }else
79765
-#endif
79766
- /*if( !pIncr->bUseThread )*/{
79767
- if( pTask->file2.pFd==0 ){
79768
- assert( pTask->file2.iEof>0 );
79769
- rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
79770
- pTask->file2.iEof = 0;
79771
- }
79772
- if( rc==SQLITE_OK ){
79773
- pIncr->aFile[1].pFd = pTask->file2.pFd;
79774
- pIncr->iStartOff = pTask->file2.iEof;
79775
- pTask->file2.iEof += mxSz;
79776
- }
79777
- }
79778
- }
79779
-
79780
-#if SQLITE_MAX_WORKER_THREADS>0
79781
- if( rc==SQLITE_OK && pIncr->bUseThread ){
79782
- /* Use the current thread to populate aFile[1], even though this
79783
- ** PmaReader is multi-threaded. The reason being that this function
79784
- ** is already running in background thread pIncr->pTask->thread. */
79785
- assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
79786
- rc = vdbeIncrPopulate(pIncr);
79787
- }
79788
-#endif
79789
-
79790
- if( rc==SQLITE_OK
79791
- && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK)
79792
- ){
79793
- rc = vdbePmaReaderNext(pReadr);
79794
- }
79795
- }
80065
+ rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
80066
+
80067
+ /* Set up the required files for pIncr. A multi-theaded IncrMerge object
80068
+ ** requires two temp files to itself, whereas a single-threaded object
80069
+ ** only requires a region of pTask->file2. */
80070
+ if( rc==SQLITE_OK ){
80071
+ int mxSz = pIncr->mxSz;
80072
+#if SQLITE_MAX_WORKER_THREADS>0
80073
+ if( pIncr->bUseThread ){
80074
+ rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
80075
+ if( rc==SQLITE_OK ){
80076
+ rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
80077
+ }
80078
+ }else
80079
+#endif
80080
+ /*if( !pIncr->bUseThread )*/{
80081
+ if( pTask->file2.pFd==0 ){
80082
+ assert( pTask->file2.iEof>0 );
80083
+ rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
80084
+ pTask->file2.iEof = 0;
80085
+ }
80086
+ if( rc==SQLITE_OK ){
80087
+ pIncr->aFile[1].pFd = pTask->file2.pFd;
80088
+ pIncr->iStartOff = pTask->file2.iEof;
80089
+ pTask->file2.iEof += mxSz;
80090
+ }
80091
+ }
80092
+ }
80093
+
80094
+#if SQLITE_MAX_WORKER_THREADS>0
80095
+ if( rc==SQLITE_OK && pIncr->bUseThread ){
80096
+ /* Use the current thread to populate aFile[1], even though this
80097
+ ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
80098
+ ** then this function is already running in background thread
80099
+ ** pIncr->pTask->thread.
80100
+ **
80101
+ ** If this is the INCRINIT_ROOT object, then it is running in the
80102
+ ** main VDBE thread. But that is Ok, as that thread cannot return
80103
+ ** control to the VDBE or proceed with anything useful until the
80104
+ ** first results are ready from this merger object anyway.
80105
+ */
80106
+ assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
80107
+ rc = vdbeIncrPopulate(pIncr);
80108
+ }
80109
+#endif
80110
+
80111
+ if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
80112
+ rc = vdbePmaReaderNext(pReadr);
80113
+ }
80114
+
7979680115
return rc;
7979780116
}
7979880117
7979980118
#if SQLITE_MAX_WORKER_THREADS>0
7980080119
/*
7980180120
** The main routine for vdbePmaReaderIncrMergeInit() operations run in
7980280121
** background threads.
7980380122
*/
79804
-static void *vdbePmaReaderBgInit(void *pCtx){
80123
+static void *vdbePmaReaderBgIncrInit(void *pCtx){
7980580124
PmaReader *pReader = (PmaReader*)pCtx;
7980680125
void *pRet = SQLITE_INT_TO_PTR(
7980780126
vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
7980880127
);
7980980128
pReader->pIncr->pTask->bDone = 1;
7981080129
return pRet;
7981180130
}
80131
+#endif
7981280132
7981380133
/*
79814
-** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
79815
-** on the PmaReader object passed as the first argument.
79816
-**
79817
-** This call will initialize the various fields of the pReadr->pIncr
79818
-** structure and, if it is a multi-threaded IncrMerger, launch a
79819
-** background thread to populate aFile[1].
80134
+** If the PmaReader passed as the first argument is not an incremental-reader
80135
+** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
80136
+** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
80137
+** this routine to initialize the incremental merge.
80138
+**
80139
+** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
80140
+** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
80141
+** Or, if the IncrMerger is single threaded, the same function is called
80142
+** using the current thread.
7982080143
*/
79821
-static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){
79822
- void *pCtx = (void*)pReadr;
79823
- return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx);
80144
+static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){
80145
+ IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */
80146
+ int rc = SQLITE_OK; /* Return code */
80147
+ if( pIncr ){
80148
+#if SQLITE_MAX_WORKER_THREADS>0
80149
+ assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
80150
+ if( pIncr->bUseThread ){
80151
+ void *pCtx = (void*)pReadr;
80152
+ rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx);
80153
+ }else
80154
+#endif
80155
+ {
80156
+ rc = vdbePmaReaderIncrMergeInit(pReadr, eMode);
80157
+ }
80158
+ }
80159
+ return rc;
7982480160
}
79825
-#endif
7982680161
7982780162
/*
7982880163
** Allocate a new MergeEngine object to merge the contents of nPMA level-0
7982980164
** PMAs from pTask->file. If no error occurs, set *ppOut to point to
7983080165
** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80367,15 @@
8003280367
int rc; /* Return code */
8003380368
SortSubtask *pTask0 = &pSorter->aTask[0];
8003480369
MergeEngine *pMain = 0;
8003580370
#if SQLITE_MAX_WORKER_THREADS
8003680371
sqlite3 *db = pTask0->pSorter->db;
80372
+ int i;
80373
+ SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
80374
+ for(i=0; i<pSorter->nTask; i++){
80375
+ pSorter->aTask[i].xCompare = xCompare;
80376
+ }
8003780377
#endif
8003880378
8003980379
rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
8004080380
if( rc==SQLITE_OK ){
8004180381
#if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80400,25 @@
8006080400
vdbeIncrMergerSetThreads(pIncr);
8006180401
assert( pIncr->pTask!=pLast );
8006280402
}
8006380403
}
8006480404
for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
80405
+ /* Check that:
80406
+ **
80407
+ ** a) The incremental merge object is configured to use the
80408
+ ** right task, and
80409
+ ** b) If it is using task (nTask-1), it is configured to run
80410
+ ** in single-threaded mode. This is important, as the
80411
+ ** root merge (INCRINIT_ROOT) will be using the same task
80412
+ ** object.
80413
+ */
8006580414
PmaReader *p = &pMain->aReadr[iTask];
80066
- assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
80067
- if( p->pIncr ){
80068
- if( iTask==pSorter->nTask-1 ){
80069
- rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK);
80070
- }else{
80071
- rc = vdbePmaReaderBgIncrInit(p);
80072
- }
80073
- }
80415
+ assert( p->pIncr==0 || (
80416
+ (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */
80417
+ && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
80418
+ ));
80419
+ rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
8007480420
}
8007580421
}
8007680422
pMain = 0;
8007780423
}
8007880424
if( rc==SQLITE_OK ){
@@ -81023,11 +81369,11 @@
8102381369
** Should be transformed into:
8102481370
**
8102581371
** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
8102681372
**
8102781373
** The nSubquery parameter specifies how many levels of subquery the
81028
-** alias is removed from the original expression. The usually value is
81374
+** alias is removed from the original expression. The usual value is
8102981375
** zero but it might be more if the alias is contained within a subquery
8103081376
** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
8103181377
** structures must be increased by the nSubquery amount.
8103281378
*/
8103381379
static void resolveAlias(
@@ -81043,11 +81389,10 @@
8104381389
sqlite3 *db; /* The database connection */
8104481390
8104581391
assert( iCol>=0 && iCol<pEList->nExpr );
8104681392
pOrig = pEList->a[iCol].pExpr;
8104781393
assert( pOrig!=0 );
81048
- assert( pOrig->flags & EP_Resolved );
8104981394
db = pParse->db;
8105081395
pDup = sqlite3ExprDup(db, pOrig, 0);
8105181396
if( pDup==0 ) return;
8105281397
if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
8105381398
incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82282,15 @@
8193782282
pNew->flags |= EP_IntValue;
8193882283
pNew->u.iValue = iCol;
8193982284
if( pItem->pExpr==pE ){
8194082285
pItem->pExpr = pNew;
8194182286
}else{
81942
- assert( pItem->pExpr->op==TK_COLLATE );
81943
- assert( pItem->pExpr->pLeft==pE );
81944
- pItem->pExpr->pLeft = pNew;
82287
+ Expr *pParent = pItem->pExpr;
82288
+ assert( pParent->op==TK_COLLATE );
82289
+ while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
82290
+ assert( pParent->pLeft==pE );
82291
+ pParent->pLeft = pNew;
8194582292
}
8194682293
sqlite3ExprDelete(db, pE);
8194782294
pItem->u.x.iOrderByCol = (u16)iCol;
8194882295
pItem->done = 1;
8194982296
}else{
@@ -82139,11 +82486,11 @@
8213982486
** as if it were part of the sub-query, not the parent. This block
8214082487
** moves the pOrderBy down to the sub-query. It will be moved back
8214182488
** after the names have been resolved. */
8214282489
if( p->selFlags & SF_Converted ){
8214382490
Select *pSub = p->pSrc->a[0].pSelect;
82144
- assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82491
+ assert( p->pSrc->nSrc==1 && p->pOrderBy );
8214582492
assert( pSub->pPrior && pSub->pOrderBy==0 );
8214682493
pSub->pOrderBy = p->pOrderBy;
8214782494
p->pOrderBy = 0;
8214882495
}
8214982496
@@ -82241,12 +82588,19 @@
8224182588
8224282589
/* Process the ORDER BY clause for singleton SELECT statements.
8224382590
** The ORDER BY clause for compounds SELECT statements is handled
8224482591
** below, after all of the result-sets for all of the elements of
8224582592
** the compound have been resolved.
82593
+ **
82594
+ ** If there is an ORDER BY clause on a term of a compound-select other
82595
+ ** than the right-most term, then that is a syntax error. But the error
82596
+ ** is not detected until much later, and so we need to go ahead and
82597
+ ** resolve those symbols on the incorrect ORDER BY for consistency.
8224682598
*/
82247
- if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){
82599
+ if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
82600
+ && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
82601
+ ){
8224882602
return WRC_Abort;
8224982603
}
8225082604
if( db->mallocFailed ){
8225182605
return WRC_Abort;
8225282606
}
@@ -83694,11 +84048,12 @@
8369484048
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
8369584049
int i;
8369684050
u32 m = 0;
8369784051
if( pList ){
8369884052
for(i=0; i<pList->nExpr; i++){
83699
- m |= pList->a[i].pExpr->flags;
84053
+ Expr *pExpr = pList->a[i].pExpr;
84054
+ if( ALWAYS(pExpr) ) m |= pExpr->flags;
8370084055
}
8370184056
}
8370284057
return m;
8370384058
}
8370484059
@@ -84134,11 +84489,11 @@
8413484489
/* Check to see if an existing table or index can be used to
8413584490
** satisfy the query. This is preferable to generating a new
8413684491
** ephemeral table.
8413784492
*/
8413884493
p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84139
- if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
84494
+ if( pParse->nErr==0 && isCandidateForInOpt(p) ){
8414084495
sqlite3 *db = pParse->db; /* Database connection */
8414184496
Table *pTab; /* Table <table>. */
8414284497
Expr *pExpr; /* Expression <column> */
8414384498
i16 iCol; /* Index of column <column> */
8414484499
i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84814,11 @@
8445984814
}
8446084815
sqlite3ExprDelete(pParse->db, pSel->pLimit);
8446184816
pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
8446284817
&sqlite3IntTokens[1]);
8446384818
pSel->iLimit = 0;
84819
+ pSel->selFlags &= ~SF_MultiValue;
8446484820
if( sqlite3Select(pParse, pSel, &dest) ){
8446584821
return 0;
8446684822
}
8446784823
rReg = dest.iSDParm;
8446884824
ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86180,11 @@
8582486180
sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
8582586181
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
8582686182
break;
8582786183
}
8582886184
case TK_ID: {
85829
- sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
86185
+ sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
8583086186
break;
8583186187
}
8583286188
#ifndef SQLITE_OMIT_CAST
8583386189
case TK_CAST: {
8583486190
/* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86815,11 @@
8645986815
if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
8646086816
if( combinedFlags & EP_xIsSelect ) return 2;
8646186817
if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
8646286818
if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
8646386819
if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86464
- if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
86820
+ if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){
8646586821
if( pA->iColumn!=pB->iColumn ) return 2;
8646686822
if( pA->iTable!=pB->iTable
8646786823
&& (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
8646886824
}
8646986825
}
@@ -86991,10 +87347,11 @@
8699187347
do {
8699287348
z += n;
8699387349
n = sqlite3GetToken(z, &token);
8699487350
}while( token==TK_SPACE );
8699587351
87352
+ if( token==TK_ILLEGAL ) break;
8699687353
zParent = sqlite3DbStrNDup(db, (const char *)z, n);
8699787354
if( zParent==0 ) break;
8699887355
sqlite3Dequote(zParent);
8699987356
if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
8700087357
char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89574,21 @@
8921789574
pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8921889575
}
8921989576
z = argv[2];
8922089577
8922189578
if( pIndex ){
89579
+ tRowcnt *aiRowEst = 0;
8922289580
int nCol = pIndex->nKeyCol+1;
8922389581
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89224
- tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
89225
- sizeof(tRowcnt) * nCol
89226
- );
89227
- if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89228
-#else
89229
- tRowcnt * const aiRowEst = 0;
89582
+ /* Index.aiRowEst may already be set here if there are duplicate
89583
+ ** sqlite_stat1 entries for this index. In that case just clobber
89584
+ ** the old data with the new instead of allocating a new array. */
89585
+ if( pIndex->aiRowEst==0 ){
89586
+ pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol);
89587
+ if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89588
+ }
89589
+ aiRowEst = pIndex->aiRowEst;
8923089590
#endif
8923189591
pIndex->bUnordered = 0;
8923289592
decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
8923389593
if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
8923489594
}else{
@@ -89887,11 +90247,11 @@
8988790247
}
8988890248
8988990249
sqlite3BtreeClose(pDb->pBt);
8989090250
pDb->pBt = 0;
8989190251
pDb->pSchema = 0;
89892
- sqlite3ResetAllSchemasOfConnection(db);
90252
+ sqlite3CollapseDatabaseArray(db);
8989390253
return;
8989490254
8989590255
detach_error:
8989690256
sqlite3_result_error(context, zErr, -1);
8989790257
}
@@ -89921,11 +90281,10 @@
8992190281
if(
8992290282
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
8992390283
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
8992490284
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
8992590285
){
89926
- pParse->nErr++;
8992790286
goto attach_end;
8992890287
}
8992990288
8993090289
#ifndef SQLITE_OMIT_AUTHORIZATION
8993190290
if( pAuthArg ){
@@ -90580,13 +90939,15 @@
9058090939
sqlite3 *db;
9058190940
Vdbe *v;
9058290941
9058390942
assert( pParse->pToplevel==0 );
9058490943
db = pParse->db;
90585
- if( db->mallocFailed ) return;
9058690944
if( pParse->nested ) return;
90587
- if( pParse->nErr ) return;
90945
+ if( db->mallocFailed || pParse->nErr ){
90946
+ if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
90947
+ return;
90948
+ }
9058890949
9058990950
/* Begin by generating some termination code at the end of the
9059090951
** vdbe program
9059190952
*/
9059290953
v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91025,11 @@
9066491025
}
9066591026
9066691027
9066791028
/* Get the VDBE program ready for execution
9066891029
*/
90669
- if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
91030
+ if( v && pParse->nErr==0 && !db->mallocFailed ){
9067091031
assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
9067191032
/* A minimum of one cursor is required if autoincrement is used
9067291033
* See ticket [a696379c1f08866] */
9067391034
if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
9067491035
sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91560,16 @@
9119991560
sqlite3 *db = pParse->db;
9120091561
9120191562
if( ALWAYS(pName2!=0) && pName2->n>0 ){
9120291563
if( db->init.busy ) {
9120391564
sqlite3ErrorMsg(pParse, "corrupt database");
91204
- pParse->nErr++;
9120591565
return -1;
9120691566
}
9120791567
*pUnqual = pName2;
9120891568
iDb = sqlite3FindDb(db, pName1);
9120991569
if( iDb<0 ){
9121091570
sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
91211
- pParse->nErr++;
9121291571
return -1;
9121391572
}
9121491573
}else{
9121591574
assert( db->init.iDb==0 || db->init.busy );
9121691575
iDb = db->init.iDb;
@@ -91365,11 +91724,11 @@
9136591724
pTable = sqlite3FindTable(db, zName, zDb);
9136691725
if( pTable ){
9136791726
if( !noErr ){
9136891727
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
9136991728
}else{
91370
- assert( !db->init.busy );
91729
+ assert( !db->init.busy || CORRUPT_DB );
9137191730
sqlite3CodeVerifySchema(pParse, iDb);
9137291731
}
9137391732
goto begin_table_error;
9137491733
}
9137591734
if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92013,12 @@
9165492013
Column *pCol;
9165592014
9165692015
p = pParse->pNewTable;
9165792016
if( p==0 || NEVER(p->nCol<1) ) return;
9165892017
pCol = &p->aCol[p->nCol-1];
91659
- assert( pCol->zType==0 );
92018
+ assert( pCol->zType==0 || CORRUPT_DB );
92019
+ sqlite3DbFree(pParse->db, pCol->zType);
9166092020
pCol->zType = sqlite3NameFromToken(pParse->db, pType);
9166192021
pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
9166292022
}
9166392023
9166492024
/*
@@ -92888,10 +93248,11 @@
9288893248
if( db->mallocFailed ){
9288993249
goto exit_drop_table;
9289093250
}
9289193251
assert( pParse->nErr==0 );
9289293252
assert( pName->nSrc==1 );
93253
+ if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
9289393254
if( noErr ) db->suppressErr++;
9289493255
pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
9289593256
if( noErr ) db->suppressErr--;
9289693257
9289793258
if( pTab==0 ){
@@ -93201,11 +93562,12 @@
9320193562
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
9320293563
}else{
9320393564
addr2 = sqlite3VdbeCurrentAddr(v);
9320493565
}
9320593566
sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93206
- sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
93567
+ sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
93568
+ sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
9320793569
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
9320893570
sqlite3ReleaseTempReg(pParse, regRecord);
9320993571
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
9321093572
sqlite3VdbeJumpHere(v, addr1);
9321193573
@@ -93294,12 +93656,11 @@
9329493656
int nExtra = 0; /* Space allocated for zExtra[] */
9329593657
int nExtraCol; /* Number of extra columns needed */
9329693658
char *zExtra = 0; /* Extra space after the Index object */
9329793659
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
9329893660
93299
- assert( pParse->nErr==0 ); /* Never called with prior errors */
93300
- if( db->mallocFailed || IN_DECLARE_VTAB ){
93661
+ if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
9330193662
goto exit_create_index;
9330293663
}
9330393664
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
9330493665
goto exit_create_index;
9330593666
}
@@ -94214,11 +94575,10 @@
9421494575
** operator with A. This routine shifts that operator over to B.
9421594576
*/
9421694577
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
9421794578
if( p ){
9421894579
int i;
94219
- assert( p->a || p->nSrc==0 );
9422094580
for(i=p->nSrc-1; i>0; i--){
9422194581
p->a[i].jointype = p->a[i-1].jointype;
9422294582
}
9422394583
p->a[0].jointype = 0;
9422494584
}
@@ -94461,12 +94821,11 @@
9446194821
char *zErr;
9446294822
int j;
9446394823
StrAccum errMsg;
9446494824
Table *pTab = pIdx->pTable;
9446594825
94466
- sqlite3StrAccumInit(&errMsg, 0, 0, 200);
94467
- errMsg.db = pParse->db;
94826
+ sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
9446894827
for(j=0; j<pIdx->nKeyCol; j++){
9446994828
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
9447094829
if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
9447194830
sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
9447294831
sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96650,17 @@
9629196650
){
9629296651
PrintfArguments x;
9629396652
StrAccum str;
9629496653
const char *zFormat;
9629596654
int n;
96655
+ sqlite3 *db = sqlite3_context_db_handle(context);
9629696656
9629796657
if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
9629896658
x.nArg = argc-1;
9629996659
x.nUsed = 0;
9630096660
x.apArg = argv+1;
96301
- sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
96302
- str.db = sqlite3_context_db_handle(context);
96661
+ sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
9630396662
sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
9630496663
n = str.nChar;
9630596664
sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
9630696665
SQLITE_DYNAMIC);
9630796666
}
@@ -96447,11 +96806,11 @@
9644796806
sqlite3_result_double(context, r);
9644896807
}
9644996808
#endif
9645096809
9645196810
/*
96452
-** Allocate nByte bytes of space using sqlite3_malloc(). If the
96811
+** Allocate nByte bytes of space using sqlite3Malloc(). If the
9645396812
** allocation fails, call sqlite3_result_error_nomem() to notify
9645496813
** the database handle that malloc() has failed and return NULL.
9645596814
** If nByte is larger than the maximum string or blob length, then
9645696815
** raise an SQLITE_TOOBIG exception and return NULL.
9645796816
*/
@@ -97116,11 +97475,11 @@
9711697475
int argc,
9711797476
sqlite3_value **argv
9711897477
){
9711997478
unsigned char *z, *zOut;
9712097479
int i;
97121
- zOut = z = sqlite3_malloc( argc*4+1 );
97480
+ zOut = z = sqlite3_malloc64( argc*4+1 );
9712297481
if( z==0 ){
9712397482
sqlite3_result_error_nomem(context);
9712497483
return;
9712597484
}
9712697485
for(i=0; i<argc; i++){
@@ -97264,11 +97623,11 @@
9726497623
sqlite3_result_error_toobig(context);
9726597624
sqlite3_free(zOut);
9726697625
return;
9726797626
}
9726897627
zOld = zOut;
97269
- zOut = sqlite3_realloc(zOut, (int)nOut);
97628
+ zOut = sqlite3_realloc64(zOut, (int)nOut);
9727097629
if( zOut==0 ){
9727197630
sqlite3_result_error_nomem(context);
9727297631
sqlite3_free(zOld);
9727397632
return;
9727497633
}
@@ -97626,12 +97985,11 @@
9762697985
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
9762797986
pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
9762897987
9762997988
if( pAccum ){
9763097989
sqlite3 *db = sqlite3_context_db_handle(context);
97631
- int firstTerm = pAccum->useMalloc==0;
97632
- pAccum->useMalloc = 2;
97990
+ int firstTerm = pAccum->mxAlloc==0;
9763397991
pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
9763497992
if( !firstTerm ){
9763597993
if( argc==2 ){
9763697994
zSep = (char*)sqlite3_value_text(argv[1]);
9763797995
nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99405,12 @@
9904799405
int iFromCol; /* Idx of column in child table */
9904899406
Expr *pEq; /* tFromCol = OLD.tToCol */
9904999407
9905099408
iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
9905199409
assert( iFromCol>=0 );
99052
- tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid";
99410
+ assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
99411
+ tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName;
9905399412
tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
9905499413
9905599414
tToCol.n = sqlite3Strlen30(tToCol.z);
9905699415
tFromCol.n = sqlite3Strlen30(tFromCol.z);
9905799416
@@ -99059,14 +99418,14 @@
9905999418
** that the "OLD.zToCol" term is on the LHS of the = operator, so
9906099419
** that the affinity and collation sequence associated with the
9906199420
** parent table are used for the comparison. */
9906299421
pEq = sqlite3PExpr(pParse, TK_EQ,
9906399422
sqlite3PExpr(pParse, TK_DOT,
99064
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99065
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99423
+ sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99424
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
9906699425
, 0),
99067
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol)
99426
+ sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
9906899427
, 0);
9906999428
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
9907099429
9907199430
/* For ON UPDATE, construct the next term of the WHEN clause.
9907299431
** The final WHEN clause will be like this:
@@ -99074,27 +99433,27 @@
9907499433
** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
9907599434
*/
9907699435
if( pChanges ){
9907799436
pEq = sqlite3PExpr(pParse, TK_IS,
9907899437
sqlite3PExpr(pParse, TK_DOT,
99079
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99080
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99438
+ sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99439
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
9908199440
0),
9908299441
sqlite3PExpr(pParse, TK_DOT,
99083
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99084
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99442
+ sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99443
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
9908599444
0),
9908699445
0);
9908799446
pWhen = sqlite3ExprAnd(db, pWhen, pEq);
9908899447
}
9908999448
9909099449
if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
9909199450
Expr *pNew;
9909299451
if( action==OE_Cascade ){
9909399452
pNew = sqlite3PExpr(pParse, TK_DOT,
99094
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99095
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99453
+ sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99454
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
9909699455
, 0);
9909799456
}else if( action==OE_SetDflt ){
9909899457
Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
9909999458
if( pDflt ){
9910099459
pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99496,16 @@
9913799496
db->lookaside.bEnabled = 0;
9913899497
9913999498
pTrigger = (Trigger *)sqlite3DbMallocZero(db,
9914099499
sizeof(Trigger) + /* struct Trigger */
9914199500
sizeof(TriggerStep) + /* Single step in trigger program */
99142
- nFrom + 1 /* Space for pStep->target.z */
99501
+ nFrom + 1 /* Space for pStep->zTarget */
9914399502
);
9914499503
if( pTrigger ){
9914599504
pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99146
- pStep->target.z = (char *)&pStep[1];
99147
- pStep->target.n = nFrom;
99148
- memcpy((char *)pStep->target.z, zFrom, nFrom);
99505
+ pStep->zTarget = (char *)&pStep[1];
99506
+ memcpy((char *)pStep->zTarget, zFrom, nFrom);
9914999507
9915099508
pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
9915199509
pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
9915299510
pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
9915399511
if( pWhen ){
@@ -99608,24 +99966,27 @@
9960899966
);
9960999967
9961099968
/*
9961199969
** This routine is called to handle SQL of the following forms:
9961299970
**
99613
-** insert into TABLE (IDLIST) values(EXPRLIST)
99971
+** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
9961499972
** insert into TABLE (IDLIST) select
99973
+** insert into TABLE (IDLIST) default values
9961599974
**
9961699975
** The IDLIST following the table name is always optional. If omitted,
99617
-** then a list of all columns for the table is substituted. The IDLIST
99618
-** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
99976
+** then a list of all (non-hidden) columns for the table is substituted.
99977
+** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
99978
+** is omitted.
9961999979
**
99620
-** The pList parameter holds EXPRLIST in the first form of the INSERT
99621
-** statement above, and pSelect is NULL. For the second form, pList is
99622
-** NULL and pSelect is a pointer to the select statement used to generate
99623
-** data for the insert.
99980
+** For the pSelect parameter holds the values to be inserted for the
99981
+** first two forms shown above. A VALUES clause is really just short-hand
99982
+** for a SELECT statement that omits the FROM clause and everything else
99983
+** that follows. If the pSelect parameter is NULL, that means that the
99984
+** DEFAULT VALUES form of the INSERT statement is intended.
9962499985
**
9962599986
** The code generated follows one of four templates. For a simple
99626
-** insert with data coming from a VALUES clause, the code executes
99987
+** insert with data coming from a single-row VALUES clause, the code executes
9962799988
** once straight down through. Pseudo-code follows (we call this
9962899989
** the "1st template"):
9962999990
**
9963099991
** open write cursor to <table> and its indices
9963199992
** put VALUES clause expressions into registers
@@ -99728,11 +100089,11 @@
99728100089
int iDb; /* Index of database holding TABLE */
99729100090
Db *pDb; /* The database containing table being inserted into */
99730100091
u8 useTempTable = 0; /* Store SELECT results in intermediate table */
99731100092
u8 appendFlag = 0; /* True if the insert is likely to be an append */
99732100093
u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
99733
- u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
100094
+ u8 bIdListInOrder; /* True if IDLIST is in table order */
99734100095
ExprList *pList = 0; /* List of VALUES() to be inserted */
99735100096
99736100097
/* Register allocations */
99737100098
int regFromSelect = 0;/* Base register for data coming from SELECT */
99738100099
int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100114,12 @@
99753100114
if( pParse->nErr || db->mallocFailed ){
99754100115
goto insert_cleanup;
99755100116
}
99756100117
99757100118
/* If the Select object is really just a simple VALUES() list with a
99758
- ** single row values (the common case) then keep that one row of values
99759
- ** and go ahead and discard the Select object
100119
+ ** single row (the common case) then keep that one row of values
100120
+ ** and discard the other (unused) parts of the pSelect object
99760100121
*/
99761100122
if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
99762100123
pList = pSelect->pEList;
99763100124
pSelect->pEList = 0;
99764100125
sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100223,11 @@
99862100223
** the index into IDLIST of the primary key column. ipkColumn is
99863100224
** the index of the primary key as it appears in IDLIST, not as
99864100225
** is appears in the original table. (The index of the INTEGER
99865100226
** PRIMARY KEY in the original table is pTab->iPKey.)
99866100227
*/
100228
+ bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0;
99867100229
if( pColumn ){
99868100230
for(i=0; i<pColumn->nId; i++){
99869100231
pColumn->a[i].idx = -1;
99870100232
}
99871100233
for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100259,12 @@
99897100259
** is coming from a SELECT statement, then generate a co-routine that
99898100260
** produces a single row of the SELECT on each invocation. The
99899100261
** co-routine is the common header to the 3rd and 4th templates.
99900100262
*/
99901100263
if( pSelect ){
99902
- /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
100264
+ /* Data is coming from a SELECT or from a multi-row VALUES clause.
100265
+ ** Generate a co-routine to run the SELECT. */
99903100266
int regYield; /* Register holding co-routine entry-point */
99904100267
int addrTop; /* Top of the co-routine */
99905100268
int rc; /* Result code */
99906100269
99907100270
regYield = ++pParse->nMem;
@@ -99910,12 +100273,11 @@
99910100273
sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
99911100274
dest.iSdst = bIdListInOrder ? regData : 0;
99912100275
dest.nSdst = pTab->nCol;
99913100276
rc = sqlite3Select(pParse, pSelect, &dest);
99914100277
regFromSelect = dest.iSdst;
99915
- assert( pParse->nErr==0 || rc );
99916
- if( rc || db->mallocFailed ) goto insert_cleanup;
100278
+ if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
99917100279
sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
99918100280
sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
99919100281
assert( pSelect->pEList );
99920100282
nColumn = pSelect->pEList->nExpr;
99921100283
@@ -99959,12 +100321,12 @@
99959100321
sqlite3VdbeJumpHere(v, addrL);
99960100322
sqlite3ReleaseTempReg(pParse, regRec);
99961100323
sqlite3ReleaseTempReg(pParse, regTempRowid);
99962100324
}
99963100325
}else{
99964
- /* This is the case if the data for the INSERT is coming from a VALUES
99965
- ** clause
100326
+ /* This is the case if the data for the INSERT is coming from a
100327
+ ** single-row VALUES clause
99966100328
*/
99967100329
NameContext sNC;
99968100330
memset(&sNC, 0, sizeof(sNC));
99969100331
sNC.pParse = pParse;
99970100332
srcTab = -1;
@@ -101031,10 +101393,11 @@
101031101393
Table *pDest, /* The table we are inserting into */
101032101394
Select *pSelect, /* A SELECT statement to use as the data source */
101033101395
int onError, /* How to handle constraint errors */
101034101396
int iDbDest /* The database of pDest */
101035101397
){
101398
+ sqlite3 *db = pParse->db;
101036101399
ExprList *pEList; /* The result set of the SELECT */
101037101400
Table *pSrc; /* The table in the FROM clause of SELECT */
101038101401
Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101039101402
struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101040101403
int i; /* Loop counter */
@@ -101178,15 +101541,15 @@
101178101541
** But the main beneficiary of the transfer optimization is the VACUUM
101179101542
** command, and the VACUUM command disables foreign key constraints. So
101180101543
** the extra complication to make this rule less restrictive is probably
101181101544
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101182101545
*/
101183
- if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101546
+ if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101184101547
return 0;
101185101548
}
101186101549
#endif
101187
- if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
101550
+ if( (db->flags & SQLITE_CountRows)!=0 ){
101188101551
return 0; /* xfer opt does not play well with PRAGMA count_changes */
101189101552
}
101190101553
101191101554
/* If we get this far, it means that the xfer optimization is at
101192101555
** least a possibility, though it might only work if the destination
@@ -101193,28 +101556,32 @@
101193101556
** table (tab1) is initially empty.
101194101557
*/
101195101558
#ifdef SQLITE_TEST
101196101559
sqlite3_xferopt_count++;
101197101560
#endif
101198
- iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
101561
+ iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
101199101562
v = sqlite3GetVdbe(pParse);
101200101563
sqlite3CodeVerifySchema(pParse, iDbSrc);
101201101564
iSrc = pParse->nTab++;
101202101565
iDest = pParse->nTab++;
101203101566
regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101204101567
regData = sqlite3GetTempReg(pParse);
101205101568
regRowid = sqlite3GetTempReg(pParse);
101206101569
sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101207101570
assert( HasRowid(pDest) || destHasUniqueIdx );
101208
- if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101571
+ if( (db->flags & SQLITE_Vacuum)==0 && (
101572
+ (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101209101573
|| destHasUniqueIdx /* (2) */
101210101574
|| (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101211
- ){
101575
+ )){
101212101576
/* In some circumstances, we are able to run the xfer optimization
101213
- ** only if the destination table is initially empty. This code makes
101214
- ** that determination. Conditions under which the destination must
101215
- ** be empty:
101577
+ ** only if the destination table is initially empty. Unless the
101578
+ ** SQLITE_Vacuum flag is set, this block generates code to make
101579
+ ** that determination. If SQLITE_Vacuum is set, then the destination
101580
+ ** table is always empty.
101581
+ **
101582
+ ** Conditions under which the destination must be empty:
101216101583
**
101217101584
** (1) There is no INTEGER PRIMARY KEY but there are indices.
101218101585
** (If the destination is not initially empty, the rowid fields
101219101586
** of index entries might need to change.)
101220101587
**
@@ -101253,10 +101620,11 @@
101253101620
}else{
101254101621
sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101255101622
sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101256101623
}
101257101624
for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
101625
+ u8 useSeekResult = 0;
101258101626
for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101259101627
if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101260101628
}
101261101629
assert( pSrcIdx );
101262101630
sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101634,37 @@
101266101634
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101267101635
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101268101636
VdbeComment((v, "%s", pDestIdx->zName));
101269101637
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101270101638
sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
101639
+ if( db->flags & SQLITE_Vacuum ){
101640
+ /* This INSERT command is part of a VACUUM operation, which guarantees
101641
+ ** that the destination table is empty. If all indexed columns use
101642
+ ** collation sequence BINARY, then it can also be assumed that the
101643
+ ** index will be populated by inserting keys in strictly sorted
101644
+ ** order. In this case, instead of seeking within the b-tree as part
101645
+ ** of every OP_IdxInsert opcode, an OP_Last is added before the
101646
+ ** OP_IdxInsert to seek to the point within the b-tree where each key
101647
+ ** should be inserted. This is faster.
101648
+ **
101649
+ ** If any of the indexed columns use a collation sequence other than
101650
+ ** BINARY, this optimization is disabled. This is because the user
101651
+ ** might change the definition of a collation sequence and then run
101652
+ ** a VACUUM command. In that case keys may not be written in strictly
101653
+ ** sorted order. */
101654
+ for(i=0; i<pSrcIdx->nColumn; i++){
101655
+ char *zColl = pSrcIdx->azColl[i];
101656
+ assert( zColl!=0 );
101657
+ if( sqlite3_stricmp("BINARY", zColl) ) break;
101658
+ }
101659
+ if( i==pSrcIdx->nColumn ){
101660
+ useSeekResult = OPFLAG_USESEEKRESULT;
101661
+ sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
101662
+ }
101663
+ }
101271101664
sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
101665
+ sqlite3VdbeChangeP5(v, useSeekResult);
101272101666
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101273101667
sqlite3VdbeJumpHere(v, addr1);
101274101668
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101275101669
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101276101670
}
@@ -102385,11 +102779,11 @@
102385102779
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102386102780
char *zErrmsg = 0;
102387102781
const char *zEntry;
102388102782
char *zAltEntry = 0;
102389102783
void **aHandle;
102390
- int nMsg = 300 + sqlite3Strlen30(zFile);
102784
+ u64 nMsg = 300 + sqlite3Strlen30(zFile);
102391102785
int ii;
102392102786
102393102787
/* Shared library endings to try if zFile cannot be loaded as written */
102394102788
static const char *azEndings[] = {
102395102789
#if SQLITE_OS_WIN
@@ -102428,11 +102822,11 @@
102428102822
sqlite3_free(zAltFile);
102429102823
}
102430102824
#endif
102431102825
if( handle==0 ){
102432102826
if( pzErrMsg ){
102433
- *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102827
+ *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102434102828
if( zErrmsg ){
102435102829
sqlite3_snprintf(nMsg, zErrmsg,
102436102830
"unable to open shared library [%s]", zFile);
102437102831
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102438102832
}
@@ -102454,11 +102848,11 @@
102454102848
** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102455102849
*/
102456102850
if( xInit==0 && zProc==0 ){
102457102851
int iFile, iEntry, c;
102458102852
int ncFile = sqlite3Strlen30(zFile);
102459
- zAltEntry = sqlite3_malloc(ncFile+30);
102853
+ zAltEntry = sqlite3_malloc64(ncFile+30);
102460102854
if( zAltEntry==0 ){
102461102855
sqlite3OsDlClose(pVfs, handle);
102462102856
return SQLITE_NOMEM;
102463102857
}
102464102858
memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102870,11 @@
102476102870
sqlite3OsDlSym(pVfs, handle, zEntry);
102477102871
}
102478102872
if( xInit==0 ){
102479102873
if( pzErrMsg ){
102480102874
nMsg += sqlite3Strlen30(zEntry);
102481
- *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102875
+ *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102482102876
if( zErrmsg ){
102483102877
sqlite3_snprintf(nMsg, zErrmsg,
102484102878
"no entry point [%s] in shared library [%s]", zEntry, zFile);
102485102879
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102486102880
}
@@ -102575,11 +102969,11 @@
102575102969
** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102576102970
** mutex must be held while accessing this list.
102577102971
*/
102578102972
typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102579102973
static SQLITE_WSD struct sqlite3AutoExtList {
102580
- int nExt; /* Number of entries in aExt[] */
102974
+ u32 nExt; /* Number of entries in aExt[] */
102581102975
void (**aExt)(void); /* Pointers to the extension init functions */
102582102976
} sqlite3Autoext = { 0, 0 };
102583102977
102584102978
/* The "wsdAutoext" macro will resolve to the autoextension
102585102979
** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103002,23 @@
102608103002
if( rc ){
102609103003
return rc;
102610103004
}else
102611103005
#endif
102612103006
{
102613
- int i;
103007
+ u32 i;
102614103008
#if SQLITE_THREADSAFE
102615103009
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
102616103010
#endif
102617103011
wsdAutoextInit;
102618103012
sqlite3_mutex_enter(mutex);
102619103013
for(i=0; i<wsdAutoext.nExt; i++){
102620103014
if( wsdAutoext.aExt[i]==xInit ) break;
102621103015
}
102622103016
if( i==wsdAutoext.nExt ){
102623
- int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
103017
+ u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
102624103018
void (**aNew)(void);
102625
- aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
103019
+ aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
102626103020
if( aNew==0 ){
102627103021
rc = SQLITE_NOMEM;
102628103022
}else{
102629103023
wsdAutoext.aExt = aNew;
102630103024
wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103046,11 @@
102652103046
#endif
102653103047
int i;
102654103048
int n = 0;
102655103049
wsdAutoextInit;
102656103050
sqlite3_mutex_enter(mutex);
102657
- for(i=wsdAutoext.nExt-1; i>=0; i--){
103051
+ for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
102658103052
if( wsdAutoext.aExt[i]==xInit ){
102659103053
wsdAutoext.nExt--;
102660103054
wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
102661103055
n++;
102662103056
break;
@@ -102690,11 +103084,11 @@
102690103084
** Load all automatic extensions.
102691103085
**
102692103086
** If anything goes wrong, set an error in the database connection.
102693103087
*/
102694103088
SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
102695
- int i;
103089
+ u32 i;
102696103090
int go = 1;
102697103091
int rc;
102698103092
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102699103093
102700103094
wsdAutoextInit;
@@ -103354,19 +103748,19 @@
103354103748
/*
103355103749
** Generate code to return a single integer value.
103356103750
*/
103357103751
static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103358103752
Vdbe *v = sqlite3GetVdbe(pParse);
103359
- int mem = ++pParse->nMem;
103753
+ int nMem = ++pParse->nMem;
103360103754
i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103361103755
if( pI64 ){
103362103756
memcpy(pI64, &value, sizeof(value));
103363103757
}
103364
- sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
103758
+ sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
103365103759
sqlite3VdbeSetNumCols(v, 1);
103366103760
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103367
- sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103761
+ sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103368103762
}
103369103763
103370103764
103371103765
/*
103372103766
** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103921,15 @@
103527103921
aFcntl[3] = 0;
103528103922
db->busyHandler.nBusy = 0;
103529103923
rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103530103924
if( rc==SQLITE_OK ){
103531103925
if( aFcntl[0] ){
103532
- int mem = ++pParse->nMem;
103533
- sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
103926
+ int nMem = ++pParse->nMem;
103927
+ sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
103534103928
sqlite3VdbeSetNumCols(v, 1);
103535103929
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103536
- sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103930
+ sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103537103931
sqlite3_free(aFcntl[0]);
103538103932
}
103539103933
goto pragma_out;
103540103934
}
103541103935
if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104530,13 @@
104136104530
}else{
104137104531
if( !db->autoCommit ){
104138104532
sqlite3ErrorMsg(pParse,
104139104533
"Safety level may not be changed inside a transaction");
104140104534
}else{
104141
- pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
104535
+ int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
104536
+ if( iLevel==0 ) iLevel = 1;
104537
+ pDb->safety_level = iLevel;
104142104538
setAllPagerFlags(db);
104143104539
}
104144104540
}
104145104541
break;
104146104542
}
@@ -104231,11 +104627,11 @@
104231104627
if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104232104628
k = 0;
104233104629
}else if( pPk==0 ){
104234104630
k = 1;
104235104631
}else{
104236
- for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
104632
+ for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
104237104633
}
104238104634
sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104239104635
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104240104636
}
104241104637
}
@@ -105237,11 +105633,11 @@
105237105633
105238105634
assert( iDb>=0 && iDb<db->nDb );
105239105635
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105240105636
if( argv[1]==0 ){
105241105637
corruptSchema(pData, argv[0], 0);
105242
- }else if( argv[2] && argv[2][0] ){
105638
+ }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){
105243105639
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105244105640
** But because db->init.busy is set to 1, no VDBE code is generated
105245105641
** or executed. All the parser does is build the internal data
105246105642
** structures that describe the table, index, or view.
105247105643
*/
@@ -105268,12 +105664,12 @@
105268105664
corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105269105665
}
105270105666
}
105271105667
}
105272105668
sqlite3_finalize(pStmt);
105273
- }else if( argv[0]==0 ){
105274
- corruptSchema(pData, 0, 0);
105669
+ }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
105670
+ corruptSchema(pData, argv[0], 0);
105275105671
}else{
105276105672
/* If the SQL column is blank it means this is an index that
105277105673
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105278105674
** constraint for a CREATE TABLE. The index should have already
105279105675
** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106572,10 @@
106176106572
){
106177106573
Select *pNew;
106178106574
Select standin;
106179106575
sqlite3 *db = pParse->db;
106180106576
pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
106181
- assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
106182106577
if( pNew==0 ){
106183106578
assert( db->mallocFailed );
106184106579
pNew = &standin;
106185106580
memset(pNew, 0, sizeof(*pNew));
106186106581
}
@@ -106196,11 +106591,11 @@
106196106591
pNew->pOrderBy = pOrderBy;
106197106592
pNew->selFlags = selFlags;
106198106593
pNew->op = TK_SELECT;
106199106594
pNew->pLimit = pLimit;
106200106595
pNew->pOffset = pOffset;
106201
- assert( pOffset==0 || pLimit!=0 );
106596
+ assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
106202106597
pNew->addrOpenEphm[0] = -1;
106203106598
pNew->addrOpenEphm[1] = -1;
106204106599
if( db->mallocFailed ) {
106205106600
clearSelect(db, pNew, pNew!=&standin);
106206106601
pNew = 0;
@@ -107446,11 +107841,11 @@
107446107841
if( pS ){
107447107842
/* The "table" is actually a sub-select or a view in the FROM clause
107448107843
** of the SELECT statement. Return the declaration type and origin
107449107844
** data for the result-set column of the sub-select.
107450107845
*/
107451
- if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
107846
+ if( iCol>=0 && iCol<pS->pEList->nExpr ){
107452107847
/* If iCol is less than zero, then the expression requests the
107453107848
** rowid of the sub-select or view. This expression is legal (see
107454107849
** test case misc2.2.2) - it always evaluates to NULL.
107455107850
*/
107456107851
NameContext sNC;
@@ -107766,16 +108161,18 @@
107766108161
memset(&sNC, 0, sizeof(sNC));
107767108162
sNC.pSrcList = pSelect->pSrc;
107768108163
a = pSelect->pEList->a;
107769108164
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
107770108165
p = a[i].pExpr;
107771
- pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108166
+ if( pCol->zType==0 ){
108167
+ pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108168
+ }
107772108169
szAll += pCol->szEst;
107773108170
pCol->affinity = sqlite3ExprAffinity(p);
107774108171
if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
107775108172
pColl = sqlite3ExprCollSeq(pParse, p);
107776
- if( pColl ){
108173
+ if( pColl && pCol->zColl==0 ){
107777108174
pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
107778108175
}
107779108176
}
107780108177
pTab->szTabRow = sqlite3LogEst(szAll*4);
107781108178
}
@@ -108173,12 +108570,11 @@
108173108570
){
108174108571
Select *pPrior;
108175108572
int nExpr = p->pEList->nExpr;
108176108573
int nRow = 1;
108177108574
int rc = 0;
108178
- assert( p->pNext==0 );
108179
- assert( p->selFlags & SF_AllValues );
108575
+ assert( p->selFlags & SF_MultiValue );
108180108576
do{
108181108577
assert( p->selFlags & SF_Values );
108182108578
assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108183108579
assert( p->pLimit==0 );
108184108580
assert( p->pOffset==0 );
@@ -108283,11 +108679,11 @@
108283108679
dest.eDest = SRT_Table;
108284108680
}
108285108681
108286108682
/* Special handling for a compound-select that originates as a VALUES clause.
108287108683
*/
108288
- if( p->selFlags & SF_AllValues ){
108684
+ if( p->selFlags & SF_MultiValue ){
108289108685
rc = multiSelectValues(pParse, p, &dest);
108290108686
goto multi_select_end;
108291108687
}
108292108688
108293108689
/* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109064,11 @@
108668109064
** then there should be a single item on the stack. Write this
108669109065
** item into the set table with bogus data.
108670109066
*/
108671109067
case SRT_Set: {
108672109068
int r1;
108673
- assert( pIn->nSdst==1 );
109069
+ assert( pIn->nSdst==1 || pParse->nErr>0 );
108674109070
pDest->affSdst =
108675109071
sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
108676109072
r1 = sqlite3GetTempReg(pParse);
108677109073
sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
108678109074
sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109090,11 @@
108694109090
/* If this is a scalar select that is part of an expression, then
108695109091
** store the results in the appropriate memory cell and break out
108696109092
** of the scan loop.
108697109093
*/
108698109094
case SRT_Mem: {
108699
- assert( pIn->nSdst==1 );
109095
+ assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 );
108700109096
sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
108701109097
/* The LIMIT clause will jump out of the loop for us */
108702109098
break;
108703109099
}
108704109100
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109105,11 @@
108709109105
case SRT_Coroutine: {
108710109106
if( pDest->iSdst==0 ){
108711109107
pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
108712109108
pDest->nSdst = pIn->nSdst;
108713109109
}
108714
- sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
109110
+ sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
108715109111
sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108716109112
break;
108717109113
}
108718109114
108719109115
/* If none of the above, then the result destination must be
@@ -108925,12 +109321,14 @@
108925109321
*/
108926109322
aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
108927109323
if( aPermute ){
108928109324
struct ExprList_item *pItem;
108929109325
for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
108930
- assert( pItem->u.x.iOrderByCol>0
108931
- && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
109326
+ assert( pItem->u.x.iOrderByCol>0 );
109327
+ /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true
109328
+ ** but only for well-formed SELECT statements. */
109329
+ testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr );
108932109330
aPermute[i] = pItem->u.x.iOrderByCol - 1;
108933109331
}
108934109332
pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
108935109333
}else{
108936109334
pKeyMerge = 0;
@@ -109136,11 +109534,11 @@
109136109534
pPrior->pNext = p;
109137109535
109138109536
/*** TBD: Insert subroutine calls to close cursors on incomplete
109139109537
**** subqueries ****/
109140109538
explainComposite(pParse, p->op, iSub1, iSub2, 0);
109141
- return SQLITE_OK;
109539
+ return pParse->nErr!=0;
109142109540
}
109143109541
#endif
109144109542
109145109543
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109146109544
/* Forward Declarations */
@@ -109948,10 +110346,11 @@
109948110346
pNew->pGroupBy = 0;
109949110347
pNew->pHaving = 0;
109950110348
pNew->pOrderBy = 0;
109951110349
p->pPrior = 0;
109952110350
p->pNext = 0;
110351
+ p->pWith = 0;
109953110352
p->selFlags &= ~SF_Compound;
109954110353
assert( (p->selFlags & SF_Converted)==0 );
109955110354
p->selFlags |= SF_Converted;
109956110355
assert( pNew->pPrior!=0 );
109957110356
pNew->pPrior->pNext = pNew;
@@ -110486,11 +110885,11 @@
110486110885
if( pParse->hasCompound ){
110487110886
w.xSelectCallback = convertCompoundSelectToSubquery;
110488110887
sqlite3WalkSelect(&w, pSelect);
110489110888
}
110490110889
w.xSelectCallback = selectExpander;
110491
- if( (pSelect->selFlags & SF_AllValues)==0 ){
110890
+ if( (pSelect->selFlags & SF_MultiValue)==0 ){
110492110891
w.xSelectCallback2 = selectPopWith;
110493110892
}
110494110893
sqlite3WalkSelect(&w, pSelect);
110495110894
}
110496110895
@@ -110672,11 +111071,12 @@
110672111071
nArg = 0;
110673111072
regAgg = 0;
110674111073
}
110675111074
if( pF->iDistinct>=0 ){
110676111075
addrNext = sqlite3VdbeMakeLabel(v);
110677
- assert( nArg==1 );
111076
+ testcase( nArg==0 ); /* Error condition */
111077
+ testcase( nArg>1 ); /* Also an error */
110678111078
codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
110679111079
}
110680111080
if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
110681111081
CollSeq *pColl = 0;
110682111082
struct ExprList_item *pItem;
@@ -111547,14 +111947,13 @@
111547111947
111548111948
/* Jump here to skip this query
111549111949
*/
111550111950
sqlite3VdbeResolveLabel(v, iEnd);
111551111951
111552
- /* The SELECT was successfully coded. Set the return code to 0
111553
- ** to indicate no errors.
111554
- */
111555
- rc = 0;
111952
+ /* The SELECT has been coded. If there is an error in the Parse structure,
111953
+ ** set the return code to 1. Otherwise 0. */
111954
+ rc = (pParse->nErr>0);
111556111955
111557111956
/* Control jumps to here if an error is encountered above, or upon
111558111957
** successful coding of the SELECT.
111559111958
*/
111560111959
select_end:
@@ -111601,11 +112000,11 @@
111601112000
sqlite3TreeViewLine(pView, "FROM");
111602112001
for(i=0; i<p->pSrc->nSrc; i++){
111603112002
struct SrcList_item *pItem = &p->pSrc->a[i];
111604112003
StrAccum x;
111605112004
char zLine[100];
111606
- sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
112005
+ sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
111607112006
sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
111608112007
if( pItem->zDatabase ){
111609112008
sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
111610112009
}else if( pItem->zName ){
111611112010
sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112159,11 @@
111760112159
for(i=0; i<nCol; i++){
111761112160
if( argv[i]==0 ){
111762112161
z = 0;
111763112162
}else{
111764112163
int n = sqlite3Strlen30(argv[i])+1;
111765
- z = sqlite3_malloc( n );
112164
+ z = sqlite3_malloc64( n );
111766112165
if( z==0 ) goto malloc_failed;
111767112166
memcpy(z, argv[i], n);
111768112167
}
111769112168
p->azResult[p->nData++] = z;
111770112169
}
@@ -111809,11 +112208,11 @@
111809112208
res.nRow = 0;
111810112209
res.nColumn = 0;
111811112210
res.nData = 1;
111812112211
res.nAlloc = 20;
111813112212
res.rc = SQLITE_OK;
111814
- res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc );
112213
+ res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
111815112214
if( res.azResult==0 ){
111816112215
db->errCode = SQLITE_NOMEM;
111817112216
return SQLITE_NOMEM;
111818112217
}
111819112218
res.azResult[0] = 0;
@@ -111837,11 +112236,11 @@
111837112236
sqlite3_free_table(&res.azResult[1]);
111838112237
return rc;
111839112238
}
111840112239
if( res.nAlloc>res.nData ){
111841112240
char **azNew;
111842
- azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData );
112241
+ azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData );
111843112242
if( azNew==0 ){
111844112243
sqlite3_free_table(&res.azResult[1]);
111845112244
db->errCode = SQLITE_NOMEM;
111846112245
return SQLITE_NOMEM;
111847112246
}
@@ -112065,11 +112464,10 @@
112065112464
}
112066112465
112067112466
/* Do not create a trigger on a system table */
112068112467
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112069112468
sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
112070
- pParse->nErr++;
112071112469
goto trigger_cleanup;
112072112470
}
112073112471
112074112472
/* INSTEAD of triggers are only for views and views only support INSTEAD
112075112473
** of triggers.
@@ -112245,16 +112643,16 @@
112245112643
u8 op, /* Trigger opcode */
112246112644
Token *pName /* The target name */
112247112645
){
112248112646
TriggerStep *pTriggerStep;
112249112647
112250
- pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
112648
+ pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
112251112649
if( pTriggerStep ){
112252112650
char *z = (char*)&pTriggerStep[1];
112253112651
memcpy(z, pName->z, pName->n);
112254
- pTriggerStep->target.z = z;
112255
- pTriggerStep->target.n = pName->n;
112652
+ sqlite3Dequote(z);
112653
+ pTriggerStep->zTarget = z;
112256112654
pTriggerStep->op = op;
112257112655
}
112258112656
return pTriggerStep;
112259112657
}
112260112658
@@ -112533,11 +112931,11 @@
112533112931
}
112534112932
return (mask ? pList : 0);
112535112933
}
112536112934
112537112935
/*
112538
-** Convert the pStep->target token into a SrcList and return a pointer
112936
+** Convert the pStep->zTarget string into a SrcList and return a pointer
112539112937
** to that SrcList.
112540112938
**
112541112939
** This routine adds a specific database name, if needed, to the target when
112542112940
** forming the SrcList. This prevents a trigger in one database from
112543112941
** referring to a target in another database. An exception is when the
@@ -112546,21 +112944,21 @@
112546112944
*/
112547112945
static SrcList *targetSrcList(
112548112946
Parse *pParse, /* The parsing context */
112549112947
TriggerStep *pStep /* The trigger containing the target token */
112550112948
){
112949
+ sqlite3 *db = pParse->db;
112551112950
int iDb; /* Index of the database to use */
112552112951
SrcList *pSrc; /* SrcList to be returned */
112553112952
112554
- pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
112953
+ pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112555112954
if( pSrc ){
112556112955
assert( pSrc->nSrc>0 );
112557
- assert( pSrc->a!=0 );
112558
- iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
112956
+ pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
112957
+ iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
112559112958
if( iDb==0 || iDb>=2 ){
112560
- sqlite3 *db = pParse->db;
112561
- assert( iDb<pParse->db->nDb );
112959
+ assert( iDb<db->nDb );
112562112960
pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112563112961
}
112564112962
}
112565112963
return pSrc;
112566112964
}
@@ -112668,10 +113066,11 @@
112668113066
assert( pFrom->zErrMsg==0 || pFrom->nErr );
112669113067
assert( pTo->zErrMsg==0 || pTo->nErr );
112670113068
if( pTo->nErr==0 ){
112671113069
pTo->zErrMsg = pFrom->zErrMsg;
112672113070
pTo->nErr = pFrom->nErr;
113071
+ pTo->rc = pFrom->rc;
112673113072
}else{
112674113073
sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
112675113074
}
112676113075
}
112677113076
@@ -114018,17 +114417,21 @@
114018114417
114019114418
/* Loop through the tables in the main database. For each, do
114020114419
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114021114420
** the contents to the temporary database.
114022114421
*/
114422
+ assert( (db->flags & SQLITE_Vacuum)==0 );
114423
+ db->flags |= SQLITE_Vacuum;
114023114424
rc = execExecSql(db, pzErrMsg,
114024114425
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114025114426
"|| ' SELECT * FROM main.' || quote(name) || ';'"
114026114427
"FROM main.sqlite_master "
114027114428
"WHERE type = 'table' AND name!='sqlite_sequence' "
114028114429
" AND coalesce(rootpage,1)>0"
114029114430
);
114431
+ assert( (db->flags & SQLITE_Vacuum)!=0 );
114432
+ db->flags &= ~SQLITE_Vacuum;
114030114433
if( rc!=SQLITE_OK ) goto end_of_vacuum;
114031114434
114032114435
/* Copy over the sequence table
114033114436
*/
114034114437
rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114566,12 @@
114163114566
** are invoked only from within xCreate and xConnect methods.
114164114567
*/
114165114568
struct VtabCtx {
114166114569
VTable *pVTable; /* The virtual table being constructed */
114167114570
Table *pTab; /* The Table object to which the virtual table belongs */
114571
+ VtabCtx *pPrior; /* Parent context (if any) */
114572
+ int bDeclared; /* True after sqlite3_declare_vtab() is called */
114168114573
};
114169114574
114170114575
/*
114171114576
** The actual function that does the work of creating a new module.
114172114577
** This function implements the sqlite3_create_module() and
@@ -114609,11 +115014,11 @@
114609115014
Token *pArg = &pParse->sArg;
114610115015
if( pArg->z==0 ){
114611115016
pArg->z = p->z;
114612115017
pArg->n = p->n;
114613115018
}else{
114614
- assert(pArg->z < p->z);
115019
+ assert(pArg->z <= p->z);
114615115020
pArg->n = (int)(&p->z[p->n] - pArg->z);
114616115021
}
114617115022
}
114618115023
114619115024
/*
@@ -114626,19 +115031,31 @@
114626115031
Table *pTab,
114627115032
Module *pMod,
114628115033
int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
114629115034
char **pzErr
114630115035
){
114631
- VtabCtx sCtx, *pPriorCtx;
115036
+ VtabCtx sCtx;
114632115037
VTable *pVTable;
114633115038
int rc;
114634115039
const char *const*azArg = (const char *const*)pTab->azModuleArg;
114635115040
int nArg = pTab->nModuleArg;
114636115041
char *zErr = 0;
114637
- char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
115042
+ char *zModuleName;
114638115043
int iDb;
115044
+ VtabCtx *pCtx;
114639115045
115046
+ /* Check that the virtual-table is not already being initialized */
115047
+ for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
115048
+ if( pCtx->pTab==pTab ){
115049
+ *pzErr = sqlite3MPrintf(db,
115050
+ "vtable constructor called recursively: %s", pTab->zName
115051
+ );
115052
+ return SQLITE_LOCKED;
115053
+ }
115054
+ }
115055
+
115056
+ zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
114640115057
if( !zModuleName ){
114641115058
return SQLITE_NOMEM;
114642115059
}
114643115060
114644115061
pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115072,17 @@
114655115072
/* Invoke the virtual table constructor */
114656115073
assert( &db->pVtabCtx );
114657115074
assert( xConstruct );
114658115075
sCtx.pTab = pTab;
114659115076
sCtx.pVTable = pVTable;
114660
- pPriorCtx = db->pVtabCtx;
115077
+ sCtx.pPrior = db->pVtabCtx;
115078
+ sCtx.bDeclared = 0;
114661115079
db->pVtabCtx = &sCtx;
114662115080
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
114663
- db->pVtabCtx = pPriorCtx;
115081
+ db->pVtabCtx = sCtx.pPrior;
114664115082
if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
115083
+ assert( sCtx.pTab==pTab );
114665115084
114666115085
if( SQLITE_OK!=rc ){
114667115086
if( zErr==0 ){
114668115087
*pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
114669115088
}else {
@@ -114675,17 +115094,18 @@
114675115094
/* Justification of ALWAYS(): A correct vtab constructor must allocate
114676115095
** the sqlite3_vtab object if successful. */
114677115096
memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
114678115097
pVTable->pVtab->pModule = pMod->pModule;
114679115098
pVTable->nRef = 1;
114680
- if( sCtx.pTab ){
115099
+ if( sCtx.bDeclared==0 ){
114681115100
const char *zFormat = "vtable constructor did not declare schema: %s";
114682115101
*pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
114683115102
sqlite3VtabUnlock(pVTable);
114684115103
rc = SQLITE_ERROR;
114685115104
}else{
114686115105
int iCol;
115106
+ u8 oooHidden = 0;
114687115107
/* If everything went according to plan, link the new VTable structure
114688115108
** into the linked list headed by pTab->pVTable. Then loop through the
114689115109
** columns of the table to see if any of them contain the token "hidden".
114690115110
** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
114691115111
** the type string. */
@@ -114694,11 +115114,14 @@
114694115114
114695115115
for(iCol=0; iCol<pTab->nCol; iCol++){
114696115116
char *zType = pTab->aCol[iCol].zType;
114697115117
int nType;
114698115118
int i = 0;
114699
- if( !zType ) continue;
115119
+ if( !zType ){
115120
+ pTab->tabFlags |= oooHidden;
115121
+ continue;
115122
+ }
114700115123
nType = sqlite3Strlen30(zType);
114701115124
if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
114702115125
for(i=0; i<nType; i++){
114703115126
if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
114704115127
&& (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115140,13 @@
114717115140
if( zType[i]=='\0' && i>0 ){
114718115141
assert(zType[i-1]==' ');
114719115142
zType[i-1] = '\0';
114720115143
}
114721115144
pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
115145
+ oooHidden = TF_OOOHidden;
115146
+ }else{
115147
+ pTab->tabFlags |= oooHidden;
114722115148
}
114723115149
}
114724115150
}
114725115151
}
114726115152
@@ -114845,12 +115271,12 @@
114845115271
** This function is used to set the schema of a virtual table. It is only
114846115272
** valid to call this function from within the xCreate() or xConnect() of a
114847115273
** virtual table module.
114848115274
*/
114849115275
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
115276
+ VtabCtx *pCtx;
114850115277
Parse *pParse;
114851
-
114852115278
int rc = SQLITE_OK;
114853115279
Table *pTab;
114854115280
char *zErr = 0;
114855115281
114856115282
#ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115283,17 @@
114857115283
if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114858115284
return SQLITE_MISUSE_BKPT;
114859115285
}
114860115286
#endif
114861115287
sqlite3_mutex_enter(db->mutex);
114862
- if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
115288
+ pCtx = db->pVtabCtx;
115289
+ if( !pCtx || pCtx->bDeclared ){
114863115290
sqlite3Error(db, SQLITE_MISUSE);
114864115291
sqlite3_mutex_leave(db->mutex);
114865115292
return SQLITE_MISUSE_BKPT;
114866115293
}
115294
+ pTab = pCtx->pTab;
114867115295
assert( (pTab->tabFlags & TF_Virtual)!=0 );
114868115296
114869115297
pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
114870115298
if( pParse==0 ){
114871115299
rc = SQLITE_NOMEM;
@@ -114884,11 +115312,11 @@
114884115312
pTab->aCol = pParse->pNewTable->aCol;
114885115313
pTab->nCol = pParse->pNewTable->nCol;
114886115314
pParse->pNewTable->nCol = 0;
114887115315
pParse->pNewTable->aCol = 0;
114888115316
}
114889
- db->pVtabCtx->pTab = 0;
115317
+ pCtx->bDeclared = 1;
114890115318
}else{
114891115319
sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
114892115320
sqlite3DbFree(db, zErr);
114893115321
rc = SQLITE_ERROR;
114894115322
}
@@ -115078,11 +115506,11 @@
115078115506
*/
115079115507
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115080115508
int rc = SQLITE_OK;
115081115509
115082115510
assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115083
- assert( iSavepoint>=0 );
115511
+ assert( iSavepoint>=-1 );
115084115512
if( db->aVTrans ){
115085115513
int i;
115086115514
for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115087115515
VTable *pVTab = db->aVTrans[i];
115088115516
const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115624,11 @@
115196115624
assert( IsVirtual(pTab) );
115197115625
for(i=0; i<pToplevel->nVtabLock; i++){
115198115626
if( pTab==pToplevel->apVtabLock[i] ) return;
115199115627
}
115200115628
n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115201
- apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n);
115629
+ apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n);
115202115630
if( apVtabLock ){
115203115631
pToplevel->apVtabLock = apVtabLock;
115204115632
pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115205115633
}else{
115206115634
pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116423,18 @@
115995116423
** In the previous sentence and in the diagram, "slot[]" refers to
115996116424
** the WhereClause.a[] array. The slot[] array grows as needed to contain
115997116425
** all terms of the WHERE clause.
115998116426
*/
115999116427
static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
116428
+ Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
116000116429
pWC->op = op;
116001
- if( pExpr==0 ) return;
116002
- if( pExpr->op!=op ){
116430
+ if( pE2==0 ) return;
116431
+ if( pE2->op!=op ){
116003116432
whereClauseInsert(pWC, pExpr, 0);
116004116433
}else{
116005
- whereSplit(pWC, pExpr->pLeft, op);
116006
- whereSplit(pWC, pExpr->pRight, op);
116434
+ whereSplit(pWC, pE2->pLeft, op);
116435
+ whereSplit(pWC, pE2->pRight, op);
116007116436
}
116008116437
}
116009116438
116010116439
/*
116011116440
** Initialize a WhereMaskSet object
@@ -117272,11 +117701,11 @@
117272117701
if( p->op==TK_COLUMN
117273117702
&& p->iColumn==pIdx->aiColumn[iCol]
117274117703
&& p->iTable==iBase
117275117704
){
117276117705
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117277
- if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117706
+ if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117278117707
return i;
117279117708
}
117280117709
}
117281117710
}
117282117711
@@ -117546,11 +117975,11 @@
117546117975
if( (idxCols & cMask)==0 ){
117547117976
Expr *pX = pTerm->pExpr;
117548117977
idxCols |= cMask;
117549117978
pIdx->aiColumn[n] = pTerm->u.leftColumn;
117550117979
pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117551
- pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY";
117980
+ pIdx->azColl[n] = pColl ? pColl->zName : "BINARY";
117552117981
n++;
117553117982
}
117554117983
}
117555117984
}
117556117985
assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119271,11 @@
118842119271
118843119272
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
118844119273
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
118845119274
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
118846119275
118847
- sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118848
- str.db = db;
119276
+ sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118849119277
sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
118850119278
if( pItem->pSelect ){
118851119279
sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
118852119280
}else{
118853119281
sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120470,17 @@
120042120470
/*
120043120471
** Free a WhereInfo structure
120044120472
*/
120045120473
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120046120474
if( ALWAYS(pWInfo) ){
120475
+ int i;
120476
+ for(i=0; i<pWInfo->nLevel; i++){
120477
+ WhereLevel *pLevel = &pWInfo->a[i];
120478
+ if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
120479
+ sqlite3DbFree(db, pLevel->u.in.aInLoop);
120480
+ }
120481
+ }
120047120482
whereClauseClear(&pWInfo->sWC);
120048120483
while( pWInfo->pLoops ){
120049120484
WhereLoop *p = pWInfo->pLoops;
120050120485
pWInfo->pLoops = p->pNextLoop;
120051120486
whereLoopDelete(db, p);
@@ -120521,11 +120956,11 @@
120521120956
** changes "x IN (?)" into "x=?". */
120522120957
120523120958
}else if( eOp & (WO_EQ) ){
120524120959
pNew->wsFlags |= WHERE_COLUMN_EQ;
120525120960
if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120526
- if( iCol>=0 && !IsUniqueIndex(pProbe) ){
120961
+ if( iCol>=0 && pProbe->uniqNotNull==0 ){
120527120962
pNew->wsFlags |= WHERE_UNQ_WANTED;
120528120963
}else{
120529120964
pNew->wsFlags |= WHERE_ONEROW;
120530120965
}
120531120966
}
@@ -121981,11 +122416,11 @@
121981122416
pWInfo->nOBSat = pFrom->isOrdered;
121982122417
if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
121983122418
pWInfo->revMask = pFrom->revLoop;
121984122419
}
121985122420
if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
121986
- && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
122421
+ && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
121987122422
){
121988122423
Bitmask revMask = 0;
121989122424
int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
121990122425
pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
121991122426
);
@@ -122386,11 +122821,10 @@
122386122821
if( pParse->nErr || NEVER(db->mallocFailed) ){
122387122822
goto whereBeginError;
122388122823
}
122389122824
#ifdef WHERETRACE_ENABLED /* !=0 */
122390122825
if( sqlite3WhereTrace ){
122391
- int ii;
122392122826
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122393122827
if( pWInfo->nOBSat>0 ){
122394122828
sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122395122829
}
122396122830
switch( pWInfo->eDistinct ){
@@ -122639,11 +123073,10 @@
122639123073
VdbeCoverage(v);
122640123074
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
122641123075
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
122642123076
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
122643123077
}
122644
- sqlite3DbFree(db, pLevel->u.in.aInLoop);
122645123078
}
122646123079
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
122647123080
if( pLevel->addrSkip ){
122648123081
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
122649123082
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123283,32 @@
122850123283
/*
122851123284
** An instance of this structure holds the ATTACH key and the key type.
122852123285
*/
122853123286
struct AttachKey { int type; Token key; };
122854123287
123288
+
123289
+ /*
123290
+ ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
123291
+ ** all elements in the list. And make sure list length does not exceed
123292
+ ** SQLITE_LIMIT_COMPOUND_SELECT.
123293
+ */
123294
+ static void parserDoubleLinkSelect(Parse *pParse, Select *p){
123295
+ if( p->pPrior ){
123296
+ Select *pNext = 0, *pLoop;
123297
+ int mxSelect, cnt = 0;
123298
+ for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123299
+ pLoop->pNext = pNext;
123300
+ pLoop->selFlags |= SF_Compound;
123301
+ }
123302
+ if( (p->selFlags & SF_MultiValue)==0 &&
123303
+ (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
123304
+ cnt>mxSelect
123305
+ ){
123306
+ sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123307
+ }
123308
+ }
123309
+ }
122855123310
122856123311
/* This is a utility routine used to set the ExprSpan.zStart and
122857123312
** ExprSpan.zEnd values of pOut so that the span covers the complete
122858123313
** range of text beginning with pStart and going to the end of pEnd.
122859123314
*/
@@ -125167,31 +125622,14 @@
125167125622
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125168125623
}
125169125624
break;
125170125625
case 112: /* select ::= with selectnowith */
125171125626
{
125172
- Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
125627
+ Select *p = yymsp[0].minor.yy3;
125173125628
if( p ){
125174
- int cnt = 0, mxSelect;
125175125629
p->pWith = yymsp[-1].minor.yy59;
125176
- if( p->pPrior ){
125177
- u16 allValues = SF_Values;
125178
- pNext = 0;
125179
- for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
125180
- pLoop->pNext = pNext;
125181
- pLoop->selFlags |= SF_Compound;
125182
- allValues &= pLoop->selFlags;
125183
- }
125184
- if( allValues ){
125185
- p->selFlags |= SF_AllValues;
125186
- }else if(
125187
- (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
125188
- && cnt>mxSelect
125189
- ){
125190
- sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
125191
- }
125192
- }
125630
+ parserDoubleLinkSelect(pParse, p);
125193125631
}else{
125194125632
sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125195125633
}
125196125634
yygotominor.yy3 = p;
125197125635
}
@@ -125205,16 +125643,18 @@
125205125643
Select *pRhs = yymsp[0].minor.yy3;
125206125644
if( pRhs && pRhs->pPrior ){
125207125645
SrcList *pFrom;
125208125646
Token x;
125209125647
x.n = 0;
125648
+ parserDoubleLinkSelect(pParse, pRhs);
125210125649
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125211125650
pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125212125651
}
125213125652
if( pRhs ){
125214125653
pRhs->op = (u8)yymsp[-1].minor.yy328;
125215125654
pRhs->pPrior = yymsp[-2].minor.yy3;
125655
+ pRhs->selFlags &= ~SF_MultiValue;
125216125656
if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125217125657
}else{
125218125658
sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125219125659
}
125220125660
yygotominor.yy3 = pRhs;
@@ -125257,17 +125697,20 @@
125257125697
yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125258125698
}
125259125699
break;
125260125700
case 121: /* values ::= values COMMA LP exprlist RP */
125261125701
{
125262
- Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125702
+ Select *pRight, *pLeft = yymsp[-4].minor.yy3;
125703
+ pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
125704
+ if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
125263125705
if( pRight ){
125264125706
pRight->op = TK_ALL;
125265
- pRight->pPrior = yymsp[-4].minor.yy3;
125707
+ pLeft = yymsp[-4].minor.yy3;
125708
+ pRight->pPrior = pLeft;
125266125709
yygotominor.yy3 = pRight;
125267125710
}else{
125268
- yygotominor.yy3 = yymsp[-4].minor.yy3;
125711
+ yygotominor.yy3 = pLeft;
125269125712
}
125270125713
}
125271125714
break;
125272125715
case 122: /* distinct ::= DISTINCT */
125273125716
{yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127510,12 @@
127067127510
goto abort_parse;
127068127511
}
127069127512
break;
127070127513
}
127071127514
case TK_ILLEGAL: {
127072
- sqlite3DbFree(db, *pzErrMsg);
127073
- *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
127515
+ sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
127074127516
&pParse->sLastToken);
127075
- nErr++;
127076127517
goto abort_parse;
127077127518
}
127078127519
case TK_SEMI: {
127079127520
pParse->zTail = &zSql[i];
127080127521
/* Fall thru into the default case */
@@ -127088,16 +127529,19 @@
127088127529
break;
127089127530
}
127090127531
}
127091127532
}
127092127533
abort_parse:
127093
- if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
127534
+ assert( nErr==0 );
127535
+ if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127094127536
if( lastTokenParsed!=TK_SEMI ){
127095127537
sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127096127538
pParse->zTail = &zSql[i];
127097127539
}
127098
- sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127540
+ if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127541
+ sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127542
+ }
127099127543
}
127100127544
#ifdef YYTRACKMAXSTACKDEPTH
127101127545
sqlite3_mutex_enter(sqlite3MallocMutex());
127102127546
sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127103127547
sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127598,11 @@
127154127598
while( pParse->pZombieTab ){
127155127599
Table *p = pParse->pZombieTab;
127156127600
pParse->pZombieTab = p->pNextZombie;
127157127601
sqlite3DeleteTable(db, p);
127158127602
}
127159
- if( nErr>0 && pParse->rc==SQLITE_OK ){
127160
- pParse->rc = SQLITE_ERROR;
127161
- }
127603
+ assert( nErr==0 || pParse->rc!=SQLITE_OK );
127162127604
return nErr;
127163127605
}
127164127606
127165127607
/************** End of tokenize.c ********************************************/
127166127608
/************** Begin file complete.c ****************************************/
@@ -127432,11 +127874,11 @@
127432127874
** UTF-8.
127433127875
*/
127434127876
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127435127877
sqlite3_value *pVal;
127436127878
char const *zSql8;
127437
- int rc = SQLITE_NOMEM;
127879
+ int rc;
127438127880
127439127881
#ifndef SQLITE_OMIT_AUTOINIT
127440127882
rc = sqlite3_initialize();
127441127883
if( rc ) return rc;
127442127884
#endif
@@ -127598,10 +128040,22 @@
127598128040
** zero if and only if SQLite was compiled with mutexing code omitted due to
127599128041
** the SQLITE_THREADSAFE compile-time option being set to 0.
127600128042
*/
127601128043
SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
127602128044
128045
+/*
128046
+** When compiling the test fixture or with debugging enabled (on Win32),
128047
+** this variable being set to non-zero will cause OSTRACE macros to emit
128048
+** extra diagnostic information.
128049
+*/
128050
+#ifdef SQLITE_HAVE_OS_TRACE
128051
+# ifndef SQLITE_DEBUG_OS_TRACE
128052
+# define SQLITE_DEBUG_OS_TRACE 0
128053
+# endif
128054
+ int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
128055
+#endif
128056
+
127603128057
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
127604128058
/*
127605128059
** If the following function pointer is not NULL and if
127606128060
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
127607128061
** I/O active are written using this function. These messages
@@ -128737,11 +129191,11 @@
128737129191
128738129192
/*
128739129193
** Return a static string containing the name corresponding to the error code
128740129194
** specified in the argument.
128741129195
*/
128742
-#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST)
129196
+#if defined(SQLITE_NEED_ERR_NAME)
128743129197
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
128744129198
const char *zName = 0;
128745129199
int i, origRc = rc;
128746129200
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
128747129201
switch( rc ){
@@ -129962,18 +130416,18 @@
129962130416
){
129963130417
char *zOpt;
129964130418
int eState; /* Parser state when parsing URI */
129965130419
int iIn; /* Input character index */
129966130420
int iOut = 0; /* Output character index */
129967
- int nByte = nUri+2; /* Bytes of space to allocate */
130421
+ u64 nByte = nUri+2; /* Bytes of space to allocate */
129968130422
129969130423
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
129970130424
** method that there may be extra parameters following the file-name. */
129971130425
flags |= SQLITE_OPEN_URI;
129972130426
129973130427
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129974
- zFile = sqlite3_malloc(nByte);
130428
+ zFile = sqlite3_malloc64(nByte);
129975130429
if( !zFile ) return SQLITE_NOMEM;
129976130430
129977130431
iIn = 5;
129978130432
#ifdef SQLITE_ALLOW_URI_AUTHORITY
129979130433
if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130589,11 @@
130135130589
130136130590
zOpt = &zVal[nVal+1];
130137130591
}
130138130592
130139130593
}else{
130140
- zFile = sqlite3_malloc(nUri+2);
130594
+ zFile = sqlite3_malloc64(nUri+2);
130141130595
if( !zFile ) return SQLITE_NOMEM;
130142130596
memcpy(zFile, zUri, nUri);
130143130597
zFile[nUri] = '\0';
130144130598
zFile[nUri+1] = '\0';
130145130599
flags &= ~SQLITE_OPEN_URI;
@@ -130406,10 +130860,17 @@
130406130860
#ifdef SQLITE_ENABLE_RTREE
130407130861
if( !db->mallocFailed && rc==SQLITE_OK){
130408130862
rc = sqlite3RtreeInit(db);
130409130863
}
130410130864
#endif
130865
+
130866
+#ifdef SQLITE_ENABLE_DBSTAT_VTAB
130867
+ if( !db->mallocFailed && rc==SQLITE_OK){
130868
+ int sqlite3_dbstat_register(sqlite3*);
130869
+ rc = sqlite3_dbstat_register(db);
130870
+ }
130871
+#endif
130411130872
130412130873
/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
130413130874
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
130414130875
** mode. Doing nothing at all also makes NORMAL the default.
130415130876
*/
@@ -132344,10 +132805,15 @@
132344132805
** false.
132345132806
*/
132346132807
#ifdef SQLITE_COVERAGE_TEST
132347132808
# define ALWAYS(x) (1)
132348132809
# define NEVER(X) (0)
132810
+#elif defined(SQLITE_DEBUG)
132811
+# define ALWAYS(x) sqlite3Fts3Always((x)!=0)
132812
+# define NEVER(x) sqlite3Fts3Never((x)!=0)
132813
+SQLITE_PRIVATE int sqlite3Fts3Always(int b);
132814
+SQLITE_PRIVATE int sqlite3Fts3Never(int b);
132349132815
#else
132350132816
# define ALWAYS(x) (x)
132351132817
# define NEVER(x) (x)
132352132818
#endif
132353132819
@@ -132744,10 +133210,11 @@
132744133210
#define fts3GetVarint32(p, piVal) ( \
132745133211
(*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
132746133212
)
132747133213
132748133214
/* fts3.c */
133215
+SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
132749133216
SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
132750133217
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
132751133218
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
132752133219
SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
132753133220
SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133299,17 @@
132832133299
132833133300
static int fts3EvalNext(Fts3Cursor *pCsr);
132834133301
static int fts3EvalStart(Fts3Cursor *pCsr);
132835133302
static int fts3TermSegReaderCursor(
132836133303
Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
133304
+
133305
+#ifndef SQLITE_AMALGAMATION
133306
+# if defined(SQLITE_DEBUG)
133307
+SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
133308
+SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
133309
+# endif
133310
+#endif
132837133311
132838133312
/*
132839133313
** Write a 64-bit variable-length integer to memory starting at p[0].
132840133314
** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
132841133315
** The number of bytes written is returned.
@@ -132942,11 +133416,11 @@
132942133416
int iOut = 0; /* Index of next byte to write to output */
132943133417
132944133418
/* If the first byte was a '[', then the close-quote character is a ']' */
132945133419
if( quote=='[' ) quote = ']';
132946133420
132947
- while( ALWAYS(z[iIn]) ){
133421
+ while( z[iIn] ){
132948133422
if( z[iIn]==quote ){
132949133423
if( z[iIn+1]!=quote ) break;
132950133424
z[iOut++] = quote;
132951133425
iIn += 2;
132952133426
}else{
@@ -133020,10 +133494,21 @@
133020133494
p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133021133495
133022133496
sqlite3_free(p);
133023133497
return SQLITE_OK;
133024133498
}
133499
+
133500
+/*
133501
+** Write an error message into *pzErr
133502
+*/
133503
+SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){
133504
+ va_list ap;
133505
+ sqlite3_free(*pzErr);
133506
+ va_start(ap, zFormat);
133507
+ *pzErr = sqlite3_vmprintf(zFormat, ap);
133508
+ va_end(ap);
133509
+}
133025133510
133026133511
/*
133027133512
** Construct one or more SQL statements from the format string given
133028133513
** and then evaluate those statements. The success code is written
133029133514
** into *pRc.
@@ -133539,11 +134024,12 @@
133539134024
sqlite3 *db, /* Database handle */
133540134025
const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
133541134026
const char *zTbl, /* Name of content table */
133542134027
const char ***pazCol, /* OUT: Malloc'd array of column names */
133543134028
int *pnCol, /* OUT: Size of array *pazCol */
133544
- int *pnStr /* OUT: Bytes of string content */
134029
+ int *pnStr, /* OUT: Bytes of string content */
134030
+ char **pzErr /* OUT: error message */
133545134031
){
133546134032
int rc = SQLITE_OK; /* Return code */
133547134033
char *zSql; /* "SELECT *" statement on zTbl */
133548134034
sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
133549134035
@@ -133550,10 +134036,13 @@
133550134036
zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
133551134037
if( !zSql ){
133552134038
rc = SQLITE_NOMEM;
133553134039
}else{
133554134040
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
134041
+ if( rc!=SQLITE_OK ){
134042
+ sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
134043
+ }
133555134044
}
133556134045
sqlite3_free(zSql);
133557134046
133558134047
if( rc==SQLITE_OK ){
133559134048
const char **azCol; /* Output array */
@@ -133716,17 +134205,17 @@
133716134205
if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
133717134206
break;
133718134207
}
133719134208
}
133720134209
if( iOpt==SizeofArray(aFts4Opt) ){
133721
- *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z);
134210
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
133722134211
rc = SQLITE_ERROR;
133723134212
}else{
133724134213
switch( iOpt ){
133725134214
case 0: /* MATCHINFO */
133726134215
if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
133727
- *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal);
134216
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
133728134217
rc = SQLITE_ERROR;
133729134218
}
133730134219
bNoDocsize = 1;
133731134220
break;
133732134221
@@ -133750,11 +134239,11 @@
133750134239
133751134240
case 4: /* ORDER */
133752134241
if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
133753134242
&& (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
133754134243
){
133755
- *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
134244
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
133756134245
rc = SQLITE_ERROR;
133757134246
}
133758134247
bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
133759134248
break;
133760134249
@@ -133801,11 +134290,11 @@
133801134290
zCompress = 0;
133802134291
zUncompress = 0;
133803134292
if( nCol==0 ){
133804134293
sqlite3_free((void*)aCol);
133805134294
aCol = 0;
133806
- rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
134295
+ rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
133807134296
133808134297
/* If a languageid= option was specified, remove the language id
133809134298
** column from the aCol[] array. */
133810134299
if( rc==SQLITE_OK && zLanguageid ){
133811134300
int j;
@@ -133836,11 +134325,11 @@
133836134325
assert( pTokenizer );
133837134326
133838134327
rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
133839134328
if( rc==SQLITE_ERROR ){
133840134329
assert( zPrefix );
133841
- *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix);
134330
+ sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix);
133842134331
}
133843134332
if( rc!=SQLITE_OK ) goto fts3_init_out;
133844134333
133845134334
/* Allocate and populate the Fts3Table structure. */
133846134335
nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134407,19 @@
133918134407
}
133919134408
}
133920134409
}
133921134410
for(i=0; i<nNotindexed; i++){
133922134411
if( azNotindexed[i] ){
133923
- *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
134412
+ sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]);
133924134413
rc = SQLITE_ERROR;
133925134414
}
133926134415
}
133927134416
133928134417
if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
133929134418
char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
133930134419
rc = SQLITE_ERROR;
133931
- *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
134420
+ sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss);
133932134421
}
133933134422
p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
133934134423
p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
133935134424
if( rc!=SQLITE_OK ) goto fts3_init_out;
133936134425
@@ -135319,11 +135808,11 @@
135319135808
** Fts3SegReaderPending might segfault, as the data structures used by
135320135809
** fts4aux are not completely populated. So it's easiest to filter these
135321135810
** calls out here. */
135322135811
if( iLevel<0 && p->aIndex ){
135323135812
Fts3SegReader *pSeg = 0;
135324
- rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg);
135813
+ rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
135325135814
if( rc==SQLITE_OK && pSeg ){
135326135815
rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135327135816
}
135328135817
}
135329135818
@@ -135968,15 +136457,35 @@
135968136457
*/
135969136458
static void fts3ReversePoslist(char *pStart, char **ppPoslist){
135970136459
char *p = &(*ppPoslist)[-2];
135971136460
char c = 0;
135972136461
136462
+ /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
135973136463
while( p>pStart && (c=*p--)==0 );
136464
+
136465
+ /* Search backwards for a varint with value zero (the end of the previous
136466
+ ** poslist). This is an 0x00 byte preceded by some byte that does not
136467
+ ** have the 0x80 bit set. */
135974136468
while( p>pStart && (*p & 0x80) | c ){
135975136469
c = *p--;
135976136470
}
135977
- if( p>pStart ){ p = &p[2]; }
136471
+ assert( p==pStart || c==0 );
136472
+
136473
+ /* At this point p points to that preceding byte without the 0x80 bit
136474
+ ** set. So to find the start of the poslist, skip forward 2 bytes then
136475
+ ** over a varint.
136476
+ **
136477
+ ** Normally. The other case is that p==pStart and the poslist to return
136478
+ ** is the first in the doclist. In this case do not skip forward 2 bytes.
136479
+ ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
136480
+ ** is required for cases where the first byte of a doclist and the
136481
+ ** doclist is empty. For example, if the first docid is 10, a doclist
136482
+ ** that begins with:
136483
+ **
136484
+ ** 0x0A 0x00 <next docid delta varint>
136485
+ */
136486
+ if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
135978136487
while( *p++&0x80 );
135979136488
*ppPoslist = p;
135980136489
}
135981136490
135982136491
/*
@@ -136043,10 +136552,12 @@
136043136552
case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136044136553
case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136045136554
}
136046136555
if( !zEllipsis || !zEnd || !zStart ){
136047136556
sqlite3_result_error_nomem(pContext);
136557
+ }else if( nToken==0 ){
136558
+ sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
136048136559
}else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136049136560
sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136050136561
}
136051136562
}
136052136563
@@ -137104,16 +137615,18 @@
137104137615
Fts3Expr *pExpr, /* Expression to initialize phrases in */
137105137616
int *pRc /* IN/OUT: Error code */
137106137617
){
137107137618
if( pExpr && SQLITE_OK==*pRc ){
137108137619
if( pExpr->eType==FTSQUERY_PHRASE ){
137109
- int i;
137110137620
int nToken = pExpr->pPhrase->nToken;
137111
- for(i=0; i<nToken; i++){
137112
- if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137621
+ if( nToken ){
137622
+ int i;
137623
+ for(i=0; i<nToken; i++){
137624
+ if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137625
+ }
137626
+ pExpr->bDeferred = (i==nToken);
137113137627
}
137114
- pExpr->bDeferred = (i==nToken);
137115137628
*pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137116137629
}else{
137117137630
fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137118137631
fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137119137632
pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138785,12 @@
138272138785
if( rc!=SQLITE_OK ) return rc;
138273138786
138274138787
pIter = pPhrase->pOrPoslist;
138275138788
iDocid = pPhrase->iOrDocid;
138276138789
if( pCsr->bDesc==bDescDoclist ){
138277
- bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138790
+ bEof = !pPhrase->doclist.nAll ||
138791
+ (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138278138792
while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138279138793
sqlite3Fts3DoclistNext(
138280138794
bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138281138795
&pIter, &iDocid, &bEof
138282138796
);
@@ -138484,11 +138998,11 @@
138484138998
138485138999
*ppVtab = (sqlite3_vtab *)p;
138486139000
return SQLITE_OK;
138487139001
138488139002
bad_args:
138489
- *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor");
139003
+ sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor");
138490139004
return SQLITE_ERROR;
138491139005
}
138492139006
138493139007
/*
138494139008
** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140456,17 @@
139942140456
139943140457
if( rc!=SQLITE_OK ){
139944140458
sqlite3Fts3ExprFree(*ppExpr);
139945140459
*ppExpr = 0;
139946140460
if( rc==SQLITE_TOOBIG ){
139947
- *pzErr = sqlite3_mprintf(
140461
+ sqlite3Fts3ErrMsg(pzErr,
139948140462
"FTS expression tree is too large (maximum depth %d)",
139949140463
SQLITE_FTS3_MAX_EXPR_DEPTH
139950140464
);
139951140465
rc = SQLITE_ERROR;
139952140466
}else if( rc==SQLITE_ERROR ){
139953
- *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
140467
+ sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z);
139954140468
}
139955140469
}
139956140470
139957140471
return rc;
139958140472
}
@@ -141424,11 +141938,11 @@
141424141938
z[n] = '\0';
141425141939
sqlite3Fts3Dequote(z);
141426141940
141427141941
m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141428141942
if( !m ){
141429
- *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z);
141943
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
141430141944
rc = SQLITE_ERROR;
141431141945
}else{
141432141946
char const **aArg = 0;
141433141947
int iArg = 0;
141434141948
z = &z[n+1];
@@ -141447,11 +141961,11 @@
141447141961
z = &z[n+1];
141448141962
}
141449141963
rc = m->xCreate(iArg, aArg, ppTok);
141450141964
assert( rc!=SQLITE_OK || *ppTok );
141451141965
if( rc!=SQLITE_OK ){
141452
- *pzErr = sqlite3_mprintf("unknown tokenizer");
141966
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer");
141453141967
}else{
141454141968
(*ppTok)->pModule = m;
141455141969
}
141456141970
sqlite3_free((void *)aArg);
141457141971
}
@@ -141531,13 +142045,13 @@
141531142045
141532142046
pHash = (Fts3Hash *)sqlite3_user_data(context);
141533142047
p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
141534142048
141535142049
if( !p ){
141536
- char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
141537
- sqlite3_result_error(context, zErr, -1);
141538
- sqlite3_free(zErr);
142050
+ char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName);
142051
+ sqlite3_result_error(context, zErr2, -1);
142052
+ sqlite3_free(zErr2);
141539142053
return;
141540142054
}
141541142055
141542142056
pRet = Tcl_NewObj();
141543142057
Tcl_IncrRefCount(pRet);
@@ -142068,11 +142582,11 @@
142068142582
sqlite3_tokenizer_module *p;
142069142583
int nName = (int)strlen(zName);
142070142584
142071142585
p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142072142586
if( !p ){
142073
- *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
142587
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName);
142074142588
return SQLITE_ERROR;
142075142589
}
142076142590
142077142591
*pp = p;
142078142592
return SQLITE_OK;
@@ -142765,11 +143279,11 @@
142765143279
/* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
142766143280
/* 24 */ "",
142767143281
/* 25 */ "",
142768143282
142769143283
/* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
142770
-/* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'",
143284
+/* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'",
142771143285
142772143286
/* This statement is used to determine which level to read the input from
142773143287
** when performing an incremental merge. It returns the absolute level number
142774143288
** of the oldest level in the db that contains at least ? segments. Or,
142775143289
** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146397,12 @@
145883146397
sqlite3_stmt *pAllLangid = 0;
145884146398
145885146399
rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
145886146400
if( rc==SQLITE_OK ){
145887146401
int rc2;
145888
- sqlite3_bind_int(pAllLangid, 1, p->nIndex);
146402
+ sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
146403
+ sqlite3_bind_int(pAllLangid, 2, p->nIndex);
145889146404
while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
145890146405
int i;
145891146406
int iLangid = sqlite3_column_int(pAllLangid, 0);
145892146407
for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
145893146408
rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147730,11 @@
147215147730
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147216147731
147217147732
pHint->n = i;
147218147733
i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147219147734
i += fts3GetVarint32(&pHint->a[i], pnInput);
147220
- if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
147735
+ if( i!=nHint ) return FTS_CORRUPT_VTAB;
147221147736
147222147737
return SQLITE_OK;
147223147738
}
147224147739
147225147740
@@ -147583,11 +148098,12 @@
147583148098
147584148099
/* This block calculates the checksum according to the FTS index. */
147585148100
rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147586148101
if( rc==SQLITE_OK ){
147587148102
int rc2;
147588
- sqlite3_bind_int(pAllLangid, 1, p->nIndex);
148103
+ sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
148104
+ sqlite3_bind_int(pAllLangid, 2, p->nIndex);
147589148105
while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
147590148106
int iLangid = sqlite3_column_int(pAllLangid, 0);
147591148107
int i;
147592148108
for(i=0; i<p->nIndex; i++){
147593148109
cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148112,10 @@
147596148112
rc2 = sqlite3_reset(pAllLangid);
147597148113
if( rc==SQLITE_OK ) rc = rc2;
147598148114
}
147599148115
147600148116
/* This block calculates the checksum according to the %_content table */
147601
- rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147602148117
if( rc==SQLITE_OK ){
147603148118
sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
147604148119
sqlite3_stmt *pStmt = 0;
147605148120
char *zSql;
147606148121
@@ -147693,11 +148208,11 @@
147693148208
Fts3Table *p /* FTS3 table handle */
147694148209
){
147695148210
int rc;
147696148211
int bOk = 0;
147697148212
rc = fts3IntegrityCheck(p, &bOk);
147698
- if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB;
148213
+ if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
147699148214
return rc;
147700148215
}
147701148216
147702148217
/*
147703148218
** Handle a 'special' INSERT of the form:
@@ -148131,10 +148646,11 @@
148131148646
#define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148132148647
#define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148133148648
#define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148134148649
#define FTS3_MATCHINFO_LCS 's' /* nCol values */
148135148650
#define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
148651
+#define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */
148136148652
148137148653
/*
148138148654
** The default value for the second argument to matchinfo().
148139148655
*/
148140148656
#define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149428,55 @@
148912149428
}
148913149429
}
148914149430
148915149431
return rc;
148916149432
}
149433
+
149434
+/*
149435
+** fts3ExprIterate() callback used to gather information for the matchinfo
149436
+** directive 'y'.
149437
+*/
149438
+static int fts3ExprLHitsCb(
149439
+ Fts3Expr *pExpr, /* Phrase expression node */
149440
+ int iPhrase, /* Phrase number */
149441
+ void *pCtx /* Pointer to MatchInfo structure */
149442
+){
149443
+ MatchInfo *p = (MatchInfo *)pCtx;
149444
+ Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
149445
+ int rc = SQLITE_OK;
149446
+ int iStart = iPhrase * p->nCol;
149447
+ Fts3Expr *pEof; /* Ancestor node already at EOF */
149448
+
149449
+ /* This must be a phrase */
149450
+ assert( pExpr->pPhrase );
149451
+
149452
+ /* Initialize all output integers to zero. */
149453
+ memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
149454
+
149455
+ /* Check if this or any parent node is at EOF. If so, then all output
149456
+ ** values are zero. */
149457
+ for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
149458
+
149459
+ if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
149460
+ Fts3Phrase *pPhrase = pExpr->pPhrase;
149461
+ char *pIter = pPhrase->doclist.pList;
149462
+ int iCol = 0;
149463
+
149464
+ while( 1 ){
149465
+ int nHit = fts3ColumnlistCount(&pIter);
149466
+ if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
149467
+ p->aMatchinfo[iStart + iCol] = (u32)nHit;
149468
+ }
149469
+ assert( *pIter==0x00 || *pIter==0x01 );
149470
+ if( *pIter!=0x01 ) break;
149471
+ pIter++;
149472
+ pIter += fts3GetVarint32(pIter, &iCol);
149473
+ }
149474
+ }
149475
+
149476
+ return rc;
149477
+}
148917149478
148918149479
static int fts3MatchinfoCheck(
148919149480
Fts3Table *pTab,
148920149481
char cArg,
148921149482
char **pzErr
@@ -148925,14 +149486,15 @@
148925149486
|| (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
148926149487
|| (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
148927149488
|| (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
148928149489
|| (cArg==FTS3_MATCHINFO_LCS)
148929149490
|| (cArg==FTS3_MATCHINFO_HITS)
149491
+ || (cArg==FTS3_MATCHINFO_LHITS)
148930149492
){
148931149493
return SQLITE_OK;
148932149494
}
148933
- *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);
149495
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
148934149496
return SQLITE_ERROR;
148935149497
}
148936149498
148937149499
static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
148938149500
int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149509,14 @@
148947149509
case FTS3_MATCHINFO_AVGLENGTH:
148948149510
case FTS3_MATCHINFO_LENGTH:
148949149511
case FTS3_MATCHINFO_LCS:
148950149512
nVal = pInfo->nCol;
148951149513
break;
149514
+
149515
+ case FTS3_MATCHINFO_LHITS:
149516
+ nVal = pInfo->nCol * pInfo->nPhrase;
149517
+ break;
148952149518
148953149519
default:
148954149520
assert( cArg==FTS3_MATCHINFO_HITS );
148955149521
nVal = pInfo->nCol * pInfo->nPhrase * 3;
148956149522
break;
@@ -149201,10 +149767,14 @@
149201149767
rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149202149768
if( rc==SQLITE_OK ){
149203149769
rc = fts3MatchinfoLcs(pCsr, pInfo);
149204149770
}
149205149771
break;
149772
+
149773
+ case FTS3_MATCHINFO_LHITS:
149774
+ (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
149775
+ break;
149206149776
149207149777
default: {
149208149778
Fts3Expr *pExpr;
149209149779
assert( zArg[i]==FTS3_MATCHINFO_HITS );
149210149780
pExpr = pCsr->pExpr;
@@ -153214,15 +153784,23 @@
153214153784
** conflict-handling mode specified by the user.
153215153785
*/
153216153786
if( nData>1 ){
153217153787
int ii;
153218153788
153219
- /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
153220
- assert( nData==(pRtree->nDim*2 + 3) );
153789
+ /* Populate the cell.aCoord[] array. The first coordinate is azData[3].
153790
+ **
153791
+ ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
153792
+ ** with "column" that are interpreted as table constraints.
153793
+ ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
153794
+ ** This problem was discovered after years of use, so we silently ignore
153795
+ ** these kinds of misdeclared tables to avoid breaking any legacy.
153796
+ */
153797
+ assert( nData<=(pRtree->nDim*2 + 3) );
153798
+
153221153799
#ifndef SQLITE_RTREE_INT_ONLY
153222153800
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153223
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153801
+ for(ii=0; ii<nData-4; ii+=2){
153224153802
cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153225153803
cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153226153804
if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153227153805
rc = SQLITE_CONSTRAINT;
153228153806
goto constraint;
@@ -153229,11 +153807,11 @@
153229153807
}
153230153808
}
153231153809
}else
153232153810
#endif
153233153811
{
153234
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153812
+ for(ii=0; ii<nData-4; ii+=2){
153235153813
cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153236153814
cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153237153815
if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153238153816
rc = SQLITE_CONSTRAINT;
153239153817
goto constraint;
@@ -154629,5 +155207,633 @@
154629155207
154630155208
#endif /* defined(SQLITE_ENABLE_ICU) */
154631155209
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
154632155210
154633155211
/************** End of fts3_icu.c ********************************************/
155212
+/************** Begin file dbstat.c ******************************************/
155213
+/*
155214
+** 2010 July 12
155215
+**
155216
+** The author disclaims copyright to this source code. In place of
155217
+** a legal notice, here is a blessing:
155218
+**
155219
+** May you do good and not evil.
155220
+** May you find forgiveness for yourself and forgive others.
155221
+** May you share freely, never taking more than you give.
155222
+**
155223
+******************************************************************************
155224
+**
155225
+** This file contains an implementation of the "dbstat" virtual table.
155226
+**
155227
+** The dbstat virtual table is used to extract low-level formatting
155228
+** information from an SQLite database in order to implement the
155229
+** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
155230
+** for an example implementation.
155231
+*/
155232
+
155233
+#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
155234
+ && !defined(SQLITE_OMIT_VIRTUALTABLE)
155235
+
155236
+/*
155237
+** Page paths:
155238
+**
155239
+** The value of the 'path' column describes the path taken from the
155240
+** root-node of the b-tree structure to each page. The value of the
155241
+** root-node path is '/'.
155242
+**
155243
+** The value of the path for the left-most child page of the root of
155244
+** a b-tree is '/000/'. (Btrees store content ordered from left to right
155245
+** so the pages to the left have smaller keys than the pages to the right.)
155246
+** The next to left-most child of the root page is
155247
+** '/001', and so on, each sibling page identified by a 3-digit hex
155248
+** value. The children of the 451st left-most sibling have paths such
155249
+** as '/1c2/000/, '/1c2/001/' etc.
155250
+**
155251
+** Overflow pages are specified by appending a '+' character and a
155252
+** six-digit hexadecimal value to the path to the cell they are linked
155253
+** from. For example, the three overflow pages in a chain linked from
155254
+** the left-most cell of the 450th child of the root page are identified
155255
+** by the paths:
155256
+**
155257
+** '/1c2/000+000000' // First page in overflow chain
155258
+** '/1c2/000+000001' // Second page in overflow chain
155259
+** '/1c2/000+000002' // Third page in overflow chain
155260
+**
155261
+** If the paths are sorted using the BINARY collation sequence, then
155262
+** the overflow pages associated with a cell will appear earlier in the
155263
+** sort-order than its child page:
155264
+**
155265
+** '/1c2/000/' // Left-most child of 451st child of root
155266
+*/
155267
+#define VTAB_SCHEMA \
155268
+ "CREATE TABLE xx( " \
155269
+ " name STRING, /* Name of table or index */" \
155270
+ " path INTEGER, /* Path to page from root */" \
155271
+ " pageno INTEGER, /* Page number */" \
155272
+ " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \
155273
+ " ncell INTEGER, /* Cells on page (0 for overflow) */" \
155274
+ " payload INTEGER, /* Bytes of payload on this page */" \
155275
+ " unused INTEGER, /* Bytes of unused space on this page */" \
155276
+ " mx_payload INTEGER, /* Largest payload size of all cells */" \
155277
+ " pgoffset INTEGER, /* Offset of page in file */" \
155278
+ " pgsize INTEGER /* Size of the page */" \
155279
+ ");"
155280
+
155281
+
155282
+typedef struct StatTable StatTable;
155283
+typedef struct StatCursor StatCursor;
155284
+typedef struct StatPage StatPage;
155285
+typedef struct StatCell StatCell;
155286
+
155287
+struct StatCell {
155288
+ int nLocal; /* Bytes of local payload */
155289
+ u32 iChildPg; /* Child node (or 0 if this is a leaf) */
155290
+ int nOvfl; /* Entries in aOvfl[] */
155291
+ u32 *aOvfl; /* Array of overflow page numbers */
155292
+ int nLastOvfl; /* Bytes of payload on final overflow page */
155293
+ int iOvfl; /* Iterates through aOvfl[] */
155294
+};
155295
+
155296
+struct StatPage {
155297
+ u32 iPgno;
155298
+ DbPage *pPg;
155299
+ int iCell;
155300
+
155301
+ char *zPath; /* Path to this page */
155302
+
155303
+ /* Variables populated by statDecodePage(): */
155304
+ u8 flags; /* Copy of flags byte */
155305
+ int nCell; /* Number of cells on page */
155306
+ int nUnused; /* Number of unused bytes on page */
155307
+ StatCell *aCell; /* Array of parsed cells */
155308
+ u32 iRightChildPg; /* Right-child page number (or 0) */
155309
+ int nMxPayload; /* Largest payload of any cell on this page */
155310
+};
155311
+
155312
+struct StatCursor {
155313
+ sqlite3_vtab_cursor base;
155314
+ sqlite3_stmt *pStmt; /* Iterates through set of root pages */
155315
+ int isEof; /* After pStmt has returned SQLITE_DONE */
155316
+
155317
+ StatPage aPage[32];
155318
+ int iPage; /* Current entry in aPage[] */
155319
+
155320
+ /* Values to return. */
155321
+ char *zName; /* Value of 'name' column */
155322
+ char *zPath; /* Value of 'path' column */
155323
+ u32 iPageno; /* Value of 'pageno' column */
155324
+ char *zPagetype; /* Value of 'pagetype' column */
155325
+ int nCell; /* Value of 'ncell' column */
155326
+ int nPayload; /* Value of 'payload' column */
155327
+ int nUnused; /* Value of 'unused' column */
155328
+ int nMxPayload; /* Value of 'mx_payload' column */
155329
+ i64 iOffset; /* Value of 'pgOffset' column */
155330
+ int szPage; /* Value of 'pgSize' column */
155331
+};
155332
+
155333
+struct StatTable {
155334
+ sqlite3_vtab base;
155335
+ sqlite3 *db;
155336
+};
155337
+
155338
+#ifndef get2byte
155339
+# define get2byte(x) ((x)[0]<<8 | (x)[1])
155340
+#endif
155341
+
155342
+/*
155343
+** Connect to or create a statvfs virtual table.
155344
+*/
155345
+static int statConnect(
155346
+ sqlite3 *db,
155347
+ void *pAux,
155348
+ int argc, const char *const*argv,
155349
+ sqlite3_vtab **ppVtab,
155350
+ char **pzErr
155351
+){
155352
+ StatTable *pTab = 0;
155353
+ int rc = SQLITE_OK;
155354
+
155355
+ rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
155356
+ if( rc==SQLITE_OK ){
155357
+ pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
155358
+ if( pTab==0 ) rc = SQLITE_NOMEM;
155359
+ }
155360
+
155361
+ assert( rc==SQLITE_OK || pTab==0 );
155362
+ if( rc==SQLITE_OK ){
155363
+ memset(pTab, 0, sizeof(StatTable));
155364
+ pTab->db = db;
155365
+ }
155366
+
155367
+ *ppVtab = (sqlite3_vtab*)pTab;
155368
+ return rc;
155369
+}
155370
+
155371
+/*
155372
+** Disconnect from or destroy a statvfs virtual table.
155373
+*/
155374
+static int statDisconnect(sqlite3_vtab *pVtab){
155375
+ sqlite3_free(pVtab);
155376
+ return SQLITE_OK;
155377
+}
155378
+
155379
+/*
155380
+** There is no "best-index". This virtual table always does a linear
155381
+** scan of the binary VFS log file.
155382
+*/
155383
+static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
155384
+
155385
+ /* Records are always returned in ascending order of (name, path).
155386
+ ** If this will satisfy the client, set the orderByConsumed flag so that
155387
+ ** SQLite does not do an external sort.
155388
+ */
155389
+ if( ( pIdxInfo->nOrderBy==1
155390
+ && pIdxInfo->aOrderBy[0].iColumn==0
155391
+ && pIdxInfo->aOrderBy[0].desc==0
155392
+ ) ||
155393
+ ( pIdxInfo->nOrderBy==2
155394
+ && pIdxInfo->aOrderBy[0].iColumn==0
155395
+ && pIdxInfo->aOrderBy[0].desc==0
155396
+ && pIdxInfo->aOrderBy[1].iColumn==1
155397
+ && pIdxInfo->aOrderBy[1].desc==0
155398
+ )
155399
+ ){
155400
+ pIdxInfo->orderByConsumed = 1;
155401
+ }
155402
+
155403
+ pIdxInfo->estimatedCost = 10.0;
155404
+ return SQLITE_OK;
155405
+}
155406
+
155407
+/*
155408
+** Open a new statvfs cursor.
155409
+*/
155410
+static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
155411
+ StatTable *pTab = (StatTable *)pVTab;
155412
+ StatCursor *pCsr;
155413
+ int rc;
155414
+
155415
+ pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
155416
+ if( pCsr==0 ){
155417
+ rc = SQLITE_NOMEM;
155418
+ }else{
155419
+ memset(pCsr, 0, sizeof(StatCursor));
155420
+ pCsr->base.pVtab = pVTab;
155421
+
155422
+ rc = sqlite3_prepare_v2(pTab->db,
155423
+ "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
155424
+ " UNION ALL "
155425
+ "SELECT name, rootpage, type FROM sqlite_master WHERE rootpage!=0"
155426
+ " ORDER BY name", -1,
155427
+ &pCsr->pStmt, 0
155428
+ );
155429
+ if( rc!=SQLITE_OK ){
155430
+ sqlite3_free(pCsr);
155431
+ pCsr = 0;
155432
+ }
155433
+ }
155434
+
155435
+ *ppCursor = (sqlite3_vtab_cursor *)pCsr;
155436
+ return rc;
155437
+}
155438
+
155439
+static void statClearPage(StatPage *p){
155440
+ int i;
155441
+ if( p->aCell ){
155442
+ for(i=0; i<p->nCell; i++){
155443
+ sqlite3_free(p->aCell[i].aOvfl);
155444
+ }
155445
+ sqlite3_free(p->aCell);
155446
+ }
155447
+ sqlite3PagerUnref(p->pPg);
155448
+ sqlite3_free(p->zPath);
155449
+ memset(p, 0, sizeof(StatPage));
155450
+}
155451
+
155452
+static void statResetCsr(StatCursor *pCsr){
155453
+ int i;
155454
+ sqlite3_reset(pCsr->pStmt);
155455
+ for(i=0; i<ArraySize(pCsr->aPage); i++){
155456
+ statClearPage(&pCsr->aPage[i]);
155457
+ }
155458
+ pCsr->iPage = 0;
155459
+ sqlite3_free(pCsr->zPath);
155460
+ pCsr->zPath = 0;
155461
+}
155462
+
155463
+/*
155464
+** Close a statvfs cursor.
155465
+*/
155466
+static int statClose(sqlite3_vtab_cursor *pCursor){
155467
+ StatCursor *pCsr = (StatCursor *)pCursor;
155468
+ statResetCsr(pCsr);
155469
+ sqlite3_finalize(pCsr->pStmt);
155470
+ sqlite3_free(pCsr);
155471
+ return SQLITE_OK;
155472
+}
155473
+
155474
+static void getLocalPayload(
155475
+ int nUsable, /* Usable bytes per page */
155476
+ u8 flags, /* Page flags */
155477
+ int nTotal, /* Total record (payload) size */
155478
+ int *pnLocal /* OUT: Bytes stored locally */
155479
+){
155480
+ int nLocal;
155481
+ int nMinLocal;
155482
+ int nMaxLocal;
155483
+
155484
+ if( flags==0x0D ){ /* Table leaf node */
155485
+ nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155486
+ nMaxLocal = nUsable - 35;
155487
+ }else{ /* Index interior and leaf nodes */
155488
+ nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155489
+ nMaxLocal = (nUsable - 12) * 64 / 255 - 23;
155490
+ }
155491
+
155492
+ nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4);
155493
+ if( nLocal>nMaxLocal ) nLocal = nMinLocal;
155494
+ *pnLocal = nLocal;
155495
+}
155496
+
155497
+static int statDecodePage(Btree *pBt, StatPage *p){
155498
+ int nUnused;
155499
+ int iOff;
155500
+ int nHdr;
155501
+ int isLeaf;
155502
+ int szPage;
155503
+
155504
+ u8 *aData = sqlite3PagerGetData(p->pPg);
155505
+ u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
155506
+
155507
+ p->flags = aHdr[0];
155508
+ p->nCell = get2byte(&aHdr[3]);
155509
+ p->nMxPayload = 0;
155510
+
155511
+ isLeaf = (p->flags==0x0A || p->flags==0x0D);
155512
+ nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100;
155513
+
155514
+ nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell;
155515
+ nUnused += (int)aHdr[7];
155516
+ iOff = get2byte(&aHdr[1]);
155517
+ while( iOff ){
155518
+ nUnused += get2byte(&aData[iOff+2]);
155519
+ iOff = get2byte(&aData[iOff]);
155520
+ }
155521
+ p->nUnused = nUnused;
155522
+ p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
155523
+ szPage = sqlite3BtreeGetPageSize(pBt);
155524
+
155525
+ if( p->nCell ){
155526
+ int i; /* Used to iterate through cells */
155527
+ int nUsable; /* Usable bytes per page */
155528
+
155529
+ sqlite3BtreeEnter(pBt);
155530
+ nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt);
155531
+ sqlite3BtreeLeave(pBt);
155532
+ p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell));
155533
+ if( p->aCell==0 ) return SQLITE_NOMEM;
155534
+ memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
155535
+
155536
+ for(i=0; i<p->nCell; i++){
155537
+ StatCell *pCell = &p->aCell[i];
155538
+
155539
+ iOff = get2byte(&aData[nHdr+i*2]);
155540
+ if( !isLeaf ){
155541
+ pCell->iChildPg = sqlite3Get4byte(&aData[iOff]);
155542
+ iOff += 4;
155543
+ }
155544
+ if( p->flags==0x05 ){
155545
+ /* A table interior node. nPayload==0. */
155546
+ }else{
155547
+ u32 nPayload; /* Bytes of payload total (local+overflow) */
155548
+ int nLocal; /* Bytes of payload stored locally */
155549
+ iOff += getVarint32(&aData[iOff], nPayload);
155550
+ if( p->flags==0x0D ){
155551
+ u64 dummy;
155552
+ iOff += sqlite3GetVarint(&aData[iOff], &dummy);
155553
+ }
155554
+ if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload;
155555
+ getLocalPayload(nUsable, p->flags, nPayload, &nLocal);
155556
+ pCell->nLocal = nLocal;
155557
+ assert( nLocal>=0 );
155558
+ assert( nPayload>=(u32)nLocal );
155559
+ assert( nLocal<=(nUsable-35) );
155560
+ if( nPayload>(u32)nLocal ){
155561
+ int j;
155562
+ int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
155563
+ pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
155564
+ pCell->nOvfl = nOvfl;
155565
+ pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
155566
+ if( pCell->aOvfl==0 ) return SQLITE_NOMEM;
155567
+ pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
155568
+ for(j=1; j<nOvfl; j++){
155569
+ int rc;
155570
+ u32 iPrev = pCell->aOvfl[j-1];
155571
+ DbPage *pPg = 0;
155572
+ rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg);
155573
+ if( rc!=SQLITE_OK ){
155574
+ assert( pPg==0 );
155575
+ return rc;
155576
+ }
155577
+ pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
155578
+ sqlite3PagerUnref(pPg);
155579
+ }
155580
+ }
155581
+ }
155582
+ }
155583
+ }
155584
+
155585
+ return SQLITE_OK;
155586
+}
155587
+
155588
+/*
155589
+** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
155590
+** the current value of pCsr->iPageno.
155591
+*/
155592
+static void statSizeAndOffset(StatCursor *pCsr){
155593
+ StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab;
155594
+ Btree *pBt = pTab->db->aDb[0].pBt;
155595
+ Pager *pPager = sqlite3BtreePager(pBt);
155596
+ sqlite3_file *fd;
155597
+ sqlite3_int64 x[2];
155598
+
155599
+ /* The default page size and offset */
155600
+ pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
155601
+ pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1);
155602
+
155603
+ /* If connected to a ZIPVFS backend, override the page size and
155604
+ ** offset with actual values obtained from ZIPVFS.
155605
+ */
155606
+ fd = sqlite3PagerFile(pPager);
155607
+ x[0] = pCsr->iPageno;
155608
+ if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
155609
+ pCsr->iOffset = x[0];
155610
+ pCsr->szPage = (int)x[1];
155611
+ }
155612
+}
155613
+
155614
+/*
155615
+** Move a statvfs cursor to the next entry in the file.
155616
+*/
155617
+static int statNext(sqlite3_vtab_cursor *pCursor){
155618
+ int rc;
155619
+ int nPayload;
155620
+ StatCursor *pCsr = (StatCursor *)pCursor;
155621
+ StatTable *pTab = (StatTable *)pCursor->pVtab;
155622
+ Btree *pBt = pTab->db->aDb[0].pBt;
155623
+ Pager *pPager = sqlite3BtreePager(pBt);
155624
+
155625
+ sqlite3_free(pCsr->zPath);
155626
+ pCsr->zPath = 0;
155627
+
155628
+statNextRestart:
155629
+ if( pCsr->aPage[0].pPg==0 ){
155630
+ rc = sqlite3_step(pCsr->pStmt);
155631
+ if( rc==SQLITE_ROW ){
155632
+ int nPage;
155633
+ u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1);
155634
+ sqlite3PagerPagecount(pPager, &nPage);
155635
+ if( nPage==0 ){
155636
+ pCsr->isEof = 1;
155637
+ return sqlite3_reset(pCsr->pStmt);
155638
+ }
155639
+ rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
155640
+ pCsr->aPage[0].iPgno = iRoot;
155641
+ pCsr->aPage[0].iCell = 0;
155642
+ pCsr->aPage[0].zPath = sqlite3_mprintf("/");
155643
+ pCsr->iPage = 0;
155644
+ }else{
155645
+ pCsr->isEof = 1;
155646
+ return sqlite3_reset(pCsr->pStmt);
155647
+ }
155648
+ }else{
155649
+
155650
+ /* Page p itself has already been visited. */
155651
+ StatPage *p = &pCsr->aPage[pCsr->iPage];
155652
+
155653
+ while( p->iCell<p->nCell ){
155654
+ StatCell *pCell = &p->aCell[p->iCell];
155655
+ if( pCell->iOvfl<pCell->nOvfl ){
155656
+ int nUsable;
155657
+ sqlite3BtreeEnter(pBt);
155658
+ nUsable = sqlite3BtreeGetPageSize(pBt) -
155659
+ sqlite3BtreeGetReserveNoMutex(pBt);
155660
+ sqlite3BtreeLeave(pBt);
155661
+ pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155662
+ pCsr->iPageno = pCell->aOvfl[pCell->iOvfl];
155663
+ pCsr->zPagetype = "overflow";
155664
+ pCsr->nCell = 0;
155665
+ pCsr->nMxPayload = 0;
155666
+ pCsr->zPath = sqlite3_mprintf(
155667
+ "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl
155668
+ );
155669
+ if( pCell->iOvfl<pCell->nOvfl-1 ){
155670
+ pCsr->nUnused = 0;
155671
+ pCsr->nPayload = nUsable - 4;
155672
+ }else{
155673
+ pCsr->nPayload = pCell->nLastOvfl;
155674
+ pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
155675
+ }
155676
+ pCell->iOvfl++;
155677
+ statSizeAndOffset(pCsr);
155678
+ return SQLITE_OK;
155679
+ }
155680
+ if( p->iRightChildPg ) break;
155681
+ p->iCell++;
155682
+ }
155683
+
155684
+ if( !p->iRightChildPg || p->iCell>p->nCell ){
155685
+ statClearPage(p);
155686
+ if( pCsr->iPage==0 ) return statNext(pCursor);
155687
+ pCsr->iPage--;
155688
+ goto statNextRestart; /* Tail recursion */
155689
+ }
155690
+ pCsr->iPage++;
155691
+ assert( p==&pCsr->aPage[pCsr->iPage-1] );
155692
+
155693
+ if( p->iCell==p->nCell ){
155694
+ p[1].iPgno = p->iRightChildPg;
155695
+ }else{
155696
+ p[1].iPgno = p->aCell[p->iCell].iChildPg;
155697
+ }
155698
+ rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);
155699
+ p[1].iCell = 0;
155700
+ p[1].zPath = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
155701
+ p->iCell++;
155702
+ }
155703
+
155704
+
155705
+ /* Populate the StatCursor fields with the values to be returned
155706
+ ** by the xColumn() and xRowid() methods.
155707
+ */
155708
+ if( rc==SQLITE_OK ){
155709
+ int i;
155710
+ StatPage *p = &pCsr->aPage[pCsr->iPage];
155711
+ pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155712
+ pCsr->iPageno = p->iPgno;
155713
+
155714
+ rc = statDecodePage(pBt, p);
155715
+ if( rc==SQLITE_OK ){
155716
+ statSizeAndOffset(pCsr);
155717
+
155718
+ switch( p->flags ){
155719
+ case 0x05: /* table internal */
155720
+ case 0x02: /* index internal */
155721
+ pCsr->zPagetype = "internal";
155722
+ break;
155723
+ case 0x0D: /* table leaf */
155724
+ case 0x0A: /* index leaf */
155725
+ pCsr->zPagetype = "leaf";
155726
+ break;
155727
+ default:
155728
+ pCsr->zPagetype = "corrupted";
155729
+ break;
155730
+ }
155731
+ pCsr->nCell = p->nCell;
155732
+ pCsr->nUnused = p->nUnused;
155733
+ pCsr->nMxPayload = p->nMxPayload;
155734
+ pCsr->zPath = sqlite3_mprintf("%s", p->zPath);
155735
+ nPayload = 0;
155736
+ for(i=0; i<p->nCell; i++){
155737
+ nPayload += p->aCell[i].nLocal;
155738
+ }
155739
+ pCsr->nPayload = nPayload;
155740
+ }
155741
+ }
155742
+
155743
+ return rc;
155744
+}
155745
+
155746
+static int statEof(sqlite3_vtab_cursor *pCursor){
155747
+ StatCursor *pCsr = (StatCursor *)pCursor;
155748
+ return pCsr->isEof;
155749
+}
155750
+
155751
+static int statFilter(
155752
+ sqlite3_vtab_cursor *pCursor,
155753
+ int idxNum, const char *idxStr,
155754
+ int argc, sqlite3_value **argv
155755
+){
155756
+ StatCursor *pCsr = (StatCursor *)pCursor;
155757
+
155758
+ statResetCsr(pCsr);
155759
+ return statNext(pCursor);
155760
+}
155761
+
155762
+static int statColumn(
155763
+ sqlite3_vtab_cursor *pCursor,
155764
+ sqlite3_context *ctx,
155765
+ int i
155766
+){
155767
+ StatCursor *pCsr = (StatCursor *)pCursor;
155768
+ switch( i ){
155769
+ case 0: /* name */
155770
+ sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_STATIC);
155771
+ break;
155772
+ case 1: /* path */
155773
+ sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
155774
+ break;
155775
+ case 2: /* pageno */
155776
+ sqlite3_result_int64(ctx, pCsr->iPageno);
155777
+ break;
155778
+ case 3: /* pagetype */
155779
+ sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC);
155780
+ break;
155781
+ case 4: /* ncell */
155782
+ sqlite3_result_int(ctx, pCsr->nCell);
155783
+ break;
155784
+ case 5: /* payload */
155785
+ sqlite3_result_int(ctx, pCsr->nPayload);
155786
+ break;
155787
+ case 6: /* unused */
155788
+ sqlite3_result_int(ctx, pCsr->nUnused);
155789
+ break;
155790
+ case 7: /* mx_payload */
155791
+ sqlite3_result_int(ctx, pCsr->nMxPayload);
155792
+ break;
155793
+ case 8: /* pgoffset */
155794
+ sqlite3_result_int64(ctx, pCsr->iOffset);
155795
+ break;
155796
+ case 9: /* pgsize */
155797
+ sqlite3_result_int(ctx, pCsr->szPage);
155798
+ break;
155799
+ }
155800
+ return SQLITE_OK;
155801
+}
155802
+
155803
+static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
155804
+ StatCursor *pCsr = (StatCursor *)pCursor;
155805
+ *pRowid = pCsr->iPageno;
155806
+ return SQLITE_OK;
155807
+}
155808
+
155809
+/*
155810
+** Invoke this routine to register the "dbstat" virtual table module
155811
+*/
155812
+SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){
155813
+ static sqlite3_module dbstat_module = {
155814
+ 0, /* iVersion */
155815
+ statConnect, /* xCreate */
155816
+ statConnect, /* xConnect */
155817
+ statBestIndex, /* xBestIndex */
155818
+ statDisconnect, /* xDisconnect */
155819
+ statDisconnect, /* xDestroy */
155820
+ statOpen, /* xOpen - open a cursor */
155821
+ statClose, /* xClose - close a cursor */
155822
+ statFilter, /* xFilter - configure scan constraints */
155823
+ statNext, /* xNext - advance a cursor */
155824
+ statEof, /* xEof - check for end of scan */
155825
+ statColumn, /* xColumn - read data */
155826
+ statRowid, /* xRowid - read data */
155827
+ 0, /* xUpdate */
155828
+ 0, /* xBegin */
155829
+ 0, /* xSync */
155830
+ 0, /* xCommit */
155831
+ 0, /* xRollback */
155832
+ 0, /* xFindMethod */
155833
+ 0, /* xRename */
155834
+ };
155835
+ return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
155836
+}
155837
+#endif /* SQLITE_ENABLE_DBSTAT_VTAB */
155838
+
155839
+/************** End of dbstat.c **********************************************/
154634155840
--- 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.9. 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.
@@ -68,10 +68,11 @@
68 #if defined(_MSC_VER)
69 #pragma warning(disable : 4054)
70 #pragma warning(disable : 4055)
71 #pragma warning(disable : 4100)
72 #pragma warning(disable : 4127)
 
73 #pragma warning(disable : 4152)
74 #pragma warning(disable : 4189)
75 #pragma warning(disable : 4206)
76 #pragma warning(disable : 4210)
77 #pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
315 **
316 ** See also: [sqlite3_libversion()],
317 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318 ** [sqlite_version()] and [sqlite_source_id()].
319 */
320 #define SQLITE_VERSION "3.8.9"
321 #define SQLITE_VERSION_NUMBER 3008009
322 #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
323
324 /*
325 ** CAPI3REF: Run-Time Library Version Numbers
326 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
327 **
@@ -474,10 +475,11 @@
474 # define double sqlite3_int64
475 #endif
476
477 /*
478 ** CAPI3REF: Closing A Database Connection
 
479 **
480 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
481 ** for the [sqlite3] object.
482 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
483 ** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
525 */
526 typedef int (*sqlite3_callback)(void*,int,char**, char**);
527
528 /*
529 ** CAPI3REF: One-Step Query Execution Interface
 
530 **
531 ** The sqlite3_exec() interface is a convenience wrapper around
532 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
533 ** that allows an application to run multiple statements of SQL
534 ** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
1582 */
1583 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1584
1585 /*
1586 ** CAPI3REF: Configure database connections
 
1587 **
1588 ** The sqlite3_db_config() interface is used to make configuration
1589 ** changes to a [database connection]. The interface is similar to
1590 ** [sqlite3_config()] except that the changes apply to a single
1591 ** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
2079 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2080
2081
2082 /*
2083 ** CAPI3REF: Enable Or Disable Extended Result Codes
 
2084 **
2085 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2086 ** [extended result codes] feature of SQLite. ^The extended result
2087 ** codes are disabled by default for historical compatibility.
2088 */
2089 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
2090
2091 /*
2092 ** CAPI3REF: Last Insert Rowid
 
2093 **
2094 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2095 ** has a unique 64-bit signed
2096 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2097 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
2139 */
2140 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
2141
2142 /*
2143 ** CAPI3REF: Count The Number Of Rows Modified
 
2144 **
2145 ** ^This function returns the number of rows modified, inserted or
2146 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2147 ** statement on the database connection specified by the only parameter.
2148 ** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
2191 */
2192 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
2193
2194 /*
2195 ** CAPI3REF: Total Number Of Rows Modified
 
2196 **
2197 ** ^This function returns the total number of rows inserted, modified or
2198 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2199 ** since the database connection was opened, including those executed as
2200 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
2214 */
2215 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2216
2217 /*
2218 ** CAPI3REF: Interrupt A Long-Running Query
 
2219 **
2220 ** ^This function causes any pending database operation to abort and
2221 ** return at its earliest opportunity. This routine is typically
2222 ** called in response to a user action such as pressing "Cancel"
2223 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
2290 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2291
2292 /*
2293 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2294 ** KEYWORDS: {busy-handler callback} {busy handler}
 
2295 **
2296 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2297 ** that might be invoked with argument P whenever
2298 ** an attempt is made to access a database table associated with
2299 ** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
2349 */
2350 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2351
2352 /*
2353 ** CAPI3REF: Set A Busy Timeout
 
2354 **
2355 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2356 ** for a specified amount of time when a table is locked. ^The handler
2357 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2358 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
2371 */
2372 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2373
2374 /*
2375 ** CAPI3REF: Convenience Routines For Running Queries
 
2376 **
2377 ** This is a legacy interface that is preserved for backwards compatibility.
2378 ** Use of this interface is not recommended.
2379 **
2380 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
2706 */
2707 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2708
2709 /*
2710 ** CAPI3REF: Compile-Time Authorization Callbacks
 
2711 **
2712 ** ^This routine registers an authorizer callback with a particular
2713 ** [database connection], supplied in the first argument.
2714 ** ^The authorizer callback is invoked as SQL statements are being compiled
2715 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
2862 #define SQLITE_COPY 0 /* No longer used */
2863 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2864
2865 /*
2866 ** CAPI3REF: Tracing And Profiling Functions
 
2867 **
2868 ** These routines register callback functions that can be used for
2869 ** tracing and profiling the execution of SQL statements.
2870 **
2871 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
2894 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2895 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2896
2897 /*
2898 ** CAPI3REF: Query Progress Callbacks
 
2899 **
2900 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2901 ** function X to be invoked periodically during long running calls to
2902 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2903 ** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
2927 */
2928 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2929
2930 /*
2931 ** CAPI3REF: Opening A New Database Connection
 
2932 **
2933 ** ^These routines open an SQLite database file as specified by the
2934 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2935 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2936 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
3212 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3213
3214
3215 /*
3216 ** CAPI3REF: Error Codes And Messages
 
3217 **
3218 ** ^If the most recent sqlite3_* API call associated with
3219 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3220 ** returns the numeric [result code] or [extended result code] for that
3221 ** API call.
@@ -3257,37 +3274,38 @@
3257 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3258 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3259 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3260
3261 /*
3262 ** CAPI3REF: SQL Statement Object
3263 ** KEYWORDS: {prepared statement} {prepared statements}
3264 **
3265 ** An instance of this object represents a single SQL statement.
3266 ** This object is variously known as a "prepared statement" or a
3267 ** "compiled SQL statement" or simply as a "statement".
3268 **
3269 ** The life of a statement object goes something like this:
 
 
 
 
 
3270 **
3271 ** <ol>
3272 ** <li> Create the object using [sqlite3_prepare_v2()] or a related
3273 ** function.
3274 ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3275 ** interfaces.
3276 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3277 ** <li> Reset the statement using [sqlite3_reset()] then go back
3278 ** to step 2. Do this zero or more times.
3279 ** <li> Destroy the object using [sqlite3_finalize()].
3280 ** </ol>
3281 **
3282 ** Refer to documentation on individual methods above for additional
3283 ** information.
3284 */
3285 typedef struct sqlite3_stmt sqlite3_stmt;
3286
3287 /*
3288 ** CAPI3REF: Run-time Limits
 
3289 **
3290 ** ^(This interface allows the size of various constructs to be limited
3291 ** on a connection by connection basis. The first parameter is the
3292 ** [database connection] whose limit is to be set or queried. The
3293 ** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
3395 #define SQLITE_LIMIT_WORKER_THREADS 11
3396
3397 /*
3398 ** CAPI3REF: Compiling An SQL Statement
3399 ** KEYWORDS: {SQL statement compiler}
 
 
3400 **
3401 ** To execute an SQL query, it must first be compiled into a byte-code
3402 ** program using one of these routines.
3403 **
3404 ** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
3502 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3503 );
3504
3505 /*
3506 ** CAPI3REF: Retrieving Statement SQL
 
3507 **
3508 ** ^This interface can be used to retrieve a saved copy of the original
3509 ** SQL text used to create a [prepared statement] if that statement was
3510 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3511 */
3512 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3513
3514 /*
3515 ** CAPI3REF: Determine If An SQL Statement Writes The Database
 
3516 **
3517 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3518 ** and only if the [prepared statement] X makes no direct changes to
3519 ** the content of the database file.
3520 **
@@ -3542,10 +3564,11 @@
3542 */
3543 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3544
3545 /*
3546 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
 
3547 **
3548 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3549 ** [prepared statement] S has been stepped at least once using
3550 ** [sqlite3_step(S)] but has not run to completion and/or has not
3551 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
3616
3617 /*
3618 ** CAPI3REF: Binding Values To Prepared Statements
3619 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3620 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 
3621 **
3622 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3623 ** literals may be replaced by a [parameter] that matches one of following
3624 ** templates:
3625 **
@@ -3734,10 +3758,11 @@
3734 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3735 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3736
3737 /*
3738 ** CAPI3REF: Number Of SQL Parameters
 
3739 **
3740 ** ^This routine can be used to find the number of [SQL parameters]
3741 ** in a [prepared statement]. SQL parameters are tokens of the
3742 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3743 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
3754 */
3755 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3756
3757 /*
3758 ** CAPI3REF: Name Of A Host Parameter
 
3759 **
3760 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3761 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3762 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3763 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
3781 */
3782 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3783
3784 /*
3785 ** CAPI3REF: Index Of A Parameter With A Given Name
 
3786 **
3787 ** ^Return the index of an SQL parameter given its name. ^The
3788 ** index value returned is suitable for use as the second
3789 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3790 ** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
3797 */
3798 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3799
3800 /*
3801 ** CAPI3REF: Reset All Bindings On A Prepared Statement
 
3802 **
3803 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3804 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3805 ** ^Use this routine to reset all host parameters to NULL.
3806 */
3807 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3808
3809 /*
3810 ** CAPI3REF: Number Of Columns In A Result Set
 
3811 **
3812 ** ^Return the number of columns in the result set returned by the
3813 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3814 ** statement that does not return data (for example an [UPDATE]).
3815 **
@@ -3817,10 +3846,11 @@
3817 */
3818 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3819
3820 /*
3821 ** CAPI3REF: Column Names In A Result Set
 
3822 **
3823 ** ^These routines return the name assigned to a particular column
3824 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3825 ** interface returns a pointer to a zero-terminated UTF-8 string
3826 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
3846 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3847 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3848
3849 /*
3850 ** CAPI3REF: Source Of Data In A Query Result
 
3851 **
3852 ** ^These routines provide a means to determine the database, table, and
3853 ** table column that is the origin of a particular result column in
3854 ** [SELECT] statement.
3855 ** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
3898 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3899 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3900
3901 /*
3902 ** CAPI3REF: Declared Datatype Of A Query Result
 
3903 **
3904 ** ^(The first parameter is a [prepared statement].
3905 ** If this statement is a [SELECT] statement and the Nth column of the
3906 ** returned result set of that [SELECT] is a table column (not an
3907 ** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
3930 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3931 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3932
3933 /*
3934 ** CAPI3REF: Evaluate An SQL Statement
 
3935 **
3936 ** After a [prepared statement] has been prepared using either
3937 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3938 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3939 ** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
4009 */
4010 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
4011
4012 /*
4013 ** CAPI3REF: Number of columns in a result set
 
4014 **
4015 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4016 ** current row of the result set of [prepared statement] P.
4017 ** ^If prepared statement P does not have results ready to return
4018 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
4062 #define SQLITE3_TEXT 3
4063
4064 /*
4065 ** CAPI3REF: Result Values From A Query
4066 ** KEYWORDS: {column access functions}
 
4067 **
4068 ** These routines form the "result set" interface.
4069 **
4070 ** ^These routines return information about a single column of the current
4071 ** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
4234 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4235 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4236
4237 /*
4238 ** CAPI3REF: Destroy A Prepared Statement Object
 
4239 **
4240 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4241 ** ^If the most recent evaluation of the statement encountered no errors
4242 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4243 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
4261 */
4262 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4263
4264 /*
4265 ** CAPI3REF: Reset A Prepared Statement Object
 
4266 **
4267 ** The sqlite3_reset() function is called to reset a [prepared statement]
4268 ** object back to its initial state, ready to be re-executed.
4269 ** ^Any SQL statement variables that had values bound to them using
4270 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
4290 /*
4291 ** CAPI3REF: Create Or Redefine SQL Functions
4292 ** KEYWORDS: {function creation routines}
4293 ** KEYWORDS: {application-defined SQL function}
4294 ** KEYWORDS: {application-defined SQL functions}
 
4295 **
4296 ** ^These functions (collectively known as "function creation routines")
4297 ** are used to add SQL functions or aggregates or to redefine the behavior
4298 ** of existing SQL functions or aggregates. The only differences between
4299 ** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
4459 void*,sqlite3_int64);
4460 #endif
4461
4462 /*
4463 ** CAPI3REF: Obtaining SQL Function Parameter Values
 
4464 **
4465 ** The C-language implementation of SQL functions and aggregates uses
4466 ** this set of interface routines to access the parameter values on
4467 ** the function or aggregate.
4468 **
@@ -4517,10 +4556,11 @@
4517 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4518 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4519
4520 /*
4521 ** CAPI3REF: Obtain Aggregate Function Context
 
4522 **
4523 ** Implementations of aggregate SQL functions use this
4524 ** routine to allocate memory for storing their state.
4525 **
4526 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
4561 */
4562 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4563
4564 /*
4565 ** CAPI3REF: User Data For Functions
 
4566 **
4567 ** ^The sqlite3_user_data() interface returns a copy of
4568 ** the pointer that was the pUserData parameter (the 5th parameter)
4569 ** of the [sqlite3_create_function()]
4570 ** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
4575 */
4576 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4577
4578 /*
4579 ** CAPI3REF: Database Connection For Functions
 
4580 **
4581 ** ^The sqlite3_context_db_handle() interface returns a copy of
4582 ** the pointer to the [database connection] (the 1st parameter)
4583 ** of the [sqlite3_create_function()]
4584 ** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
4586 */
4587 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4588
4589 /*
4590 ** CAPI3REF: Function Auxiliary Data
 
4591 **
4592 ** These functions may be used by (non-aggregate) SQL functions to
4593 ** associate metadata with argument values. If the same value is passed to
4594 ** multiple invocations of the same SQL function during query execution, under
4595 ** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
4658 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4659 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4660
4661 /*
4662 ** CAPI3REF: Setting The Result Of An SQL Function
 
4663 **
4664 ** These routines are used by the xFunc or xFinal callbacks that
4665 ** implement SQL functions and aggregates. See
4666 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4667 ** for additional information.
@@ -4793,10 +4837,11 @@
4793 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4794 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4795
4796 /*
4797 ** CAPI3REF: Define New Collating Sequences
 
4798 **
4799 ** ^These functions add, remove, or modify a [collation] associated
4800 ** with the [database connection] specified as the first argument.
4801 **
4802 ** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
4895 int(*xCompare)(void*,int,const void*,int,const void*)
4896 );
4897
4898 /*
4899 ** CAPI3REF: Collation Needed Callbacks
 
4900 **
4901 ** ^To avoid having to register all collation sequences before a database
4902 ** can be used, a single callback function may be registered with the
4903 ** [database connection] to be invoked whenever an undefined collation
4904 ** sequence is required.
@@ -5102,10 +5148,11 @@
5102 SQLITE_API char *sqlite3_data_directory;
5103
5104 /*
5105 ** CAPI3REF: Test For Auto-Commit Mode
5106 ** KEYWORDS: {autocommit mode}
 
5107 **
5108 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5109 ** zero if the given database connection is or is not in autocommit mode,
5110 ** respectively. ^Autocommit mode is on by default.
5111 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
5124 */
5125 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
5126
5127 /*
5128 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 
5129 **
5130 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5131 ** to which a [prepared statement] belongs. ^The [database connection]
5132 ** returned by sqlite3_db_handle is the same [database connection]
5133 ** that was the first argument
@@ -5136,10 +5184,11 @@
5136 */
5137 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
5138
5139 /*
5140 ** CAPI3REF: Return The Filename For A Database Connection
 
5141 **
5142 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5143 ** associated with database N of connection D. ^The main database file
5144 ** has the name "main". If there is no attached database N on the database
5145 ** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
5152 */
5153 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5154
5155 /*
5156 ** CAPI3REF: Determine if a database is read-only
 
5157 **
5158 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5159 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5160 ** the name of a database on connection D.
5161 */
5162 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5163
5164 /*
5165 ** CAPI3REF: Find the next prepared statement
 
5166 **
5167 ** ^This interface returns a pointer to the next [prepared statement] after
5168 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5169 ** then this interface returns a pointer to the first prepared statement
5170 ** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
5176 */
5177 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5178
5179 /*
5180 ** CAPI3REF: Commit And Rollback Notification Callbacks
 
5181 **
5182 ** ^The sqlite3_commit_hook() interface registers a callback
5183 ** function to be invoked whenever a transaction is [COMMIT | committed].
5184 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5185 ** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
5225 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5226 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5227
5228 /*
5229 ** CAPI3REF: Data Change Notification Callbacks
 
5230 **
5231 ** ^The sqlite3_update_hook() interface registers a callback function
5232 ** with the [database connection] identified by the first argument
5233 ** to be invoked whenever a row is updated, inserted or deleted in
5234 ** a rowid table.
@@ -5331,10 +5384,11 @@
5331 */
5332 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5333
5334 /*
5335 ** CAPI3REF: Free Memory Used By A Database Connection
 
5336 **
5337 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5338 ** memory as possible from database connection D. Unlike the
5339 ** [sqlite3_release_memory()] interface, this interface is in effect even
5340 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
5408 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5409
5410
5411 /*
5412 ** CAPI3REF: Extract Metadata About A Column Of A Table
 
5413 **
5414 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5415 ** information about column C of table T in database D
5416 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5417 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
5486 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5487 );
5488
5489 /*
5490 ** CAPI3REF: Load An Extension
 
5491 **
5492 ** ^This interface loads an SQLite extension library from the named file.
5493 **
5494 ** ^The sqlite3_load_extension() interface attempts to load an
5495 ** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
5527 char **pzErrMsg /* Put error message here if not 0 */
5528 );
5529
5530 /*
5531 ** CAPI3REF: Enable Or Disable Extension Loading
 
5532 **
5533 ** ^So as not to open security holes in older applications that are
5534 ** unprepared to deal with [extension loading], and as a means of disabling
5535 ** [extension loading] while evaluating user-entered SQL, the following API
5536 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
5776 #define SQLITE_INDEX_CONSTRAINT_GE 32
5777 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5778
5779 /*
5780 ** CAPI3REF: Register A Virtual Table Implementation
 
5781 **
5782 ** ^These routines are used to register a new [virtual table module] name.
5783 ** ^Module names must be registered before
5784 ** creating a new [virtual table] using the module and before using a
5785 ** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
5872 */
5873 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5874
5875 /*
5876 ** CAPI3REF: Overload A Function For A Virtual Table
 
5877 **
5878 ** ^(Virtual tables can provide alternative implementations of functions
5879 ** using the [xFindFunction] method of the [virtual table module].
5880 ** But global versions of those functions
5881 ** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
5914 */
5915 typedef struct sqlite3_blob sqlite3_blob;
5916
5917 /*
5918 ** CAPI3REF: Open A BLOB For Incremental I/O
 
 
5919 **
5920 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5921 ** in row iRow, column zColumn, table zTable in database zDb;
5922 ** in other words, the same BLOB that would be selected by:
5923 **
@@ -5995,10 +6056,11 @@
5995 sqlite3_blob **ppBlob
5996 );
5997
5998 /*
5999 ** CAPI3REF: Move a BLOB Handle to a New Row
 
6000 **
6001 ** ^This function is used to move an existing blob handle so that it points
6002 ** to a different row of the same database table. ^The new row is identified
6003 ** by the rowid value passed as the second argument. Only the row can be
6004 ** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
6019 */
6020 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
6021
6022 /*
6023 ** CAPI3REF: Close A BLOB Handle
 
6024 **
6025 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
6026 ** unconditionally. Even if this routine returns an error code, the
6027 ** handle is still closed.)^
6028 **
@@ -6041,10 +6104,11 @@
6041 */
6042 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
6043
6044 /*
6045 ** CAPI3REF: Return The Size Of An Open BLOB
 
6046 **
6047 ** ^Returns the size in bytes of the BLOB accessible via the
6048 ** successfully opened [BLOB handle] in its only argument. ^The
6049 ** incremental blob I/O routines can only read or overwriting existing
6050 ** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
6056 */
6057 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
6058
6059 /*
6060 ** CAPI3REF: Read Data From A BLOB Incrementally
 
6061 **
6062 ** ^(This function is used to read data from an open [BLOB handle] into a
6063 ** caller-supplied buffer. N bytes of data are copied into buffer Z
6064 ** from the open BLOB, starting at offset iOffset.)^
6065 **
@@ -6084,10 +6149,11 @@
6084 */
6085 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
6086
6087 /*
6088 ** CAPI3REF: Write Data Into A BLOB Incrementally
 
6089 **
6090 ** ^(This function is used to write data into an open [BLOB handle] from a
6091 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
6092 ** into the open BLOB, starting at offset iOffset.)^
6093 **
@@ -6411,10 +6477,11 @@
6411 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6412 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6413
6414 /*
6415 ** CAPI3REF: Retrieve the mutex for a database connection
 
6416 **
6417 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6418 ** serializes access to the [database connection] given in the argument
6419 ** when the [threading mode] is Serialized.
6420 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
6422 */
6423 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6424
6425 /*
6426 ** CAPI3REF: Low-Level Control Of Database Files
 
6427 **
6428 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6429 ** xFileControl method for the [sqlite3_io_methods] object associated
6430 ** with a particular database identified by the second argument. ^The
6431 ** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
6638 #define SQLITE_STATUS_SCRATCH_SIZE 8
6639 #define SQLITE_STATUS_MALLOC_COUNT 9
6640
6641 /*
6642 ** CAPI3REF: Database Connection Status
 
6643 **
6644 ** ^This interface is used to retrieve runtime status information
6645 ** about a single [database connection]. ^The first argument is the
6646 ** database connection object to be interrogated. ^The second argument
6647 ** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
6766 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6767
6768
6769 /*
6770 ** CAPI3REF: Prepared Statement Status
 
6771 **
6772 ** ^(Each prepared statement maintains various
6773 ** [SQLITE_STMTSTATUS counters] that measure the number
6774 ** of times it has performed specific operations.)^ These counters can
6775 ** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
7269 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7270 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7271
7272 /*
7273 ** CAPI3REF: Unlock Notification
 
7274 **
7275 ** ^When running in shared-cache mode, a database operation may fail with
7276 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7277 ** individual tables within the shared-cache cannot be obtained. See
7278 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
7439 */
7440 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7441
7442 /*
7443 ** CAPI3REF: Write-Ahead Log Commit Hook
 
7444 **
7445 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7446 ** is invoked each time data is committed to a database in wal mode.
7447 **
7448 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
7478 void*
7479 );
7480
7481 /*
7482 ** CAPI3REF: Configure an auto-checkpoint
 
7483 **
7484 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7485 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7486 ** to automatically [checkpoint]
7487 ** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
7508 */
7509 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7510
7511 /*
7512 ** CAPI3REF: Checkpoint a database
 
7513 **
7514 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7515 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7516 **
7517 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
7529 */
7530 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7531
7532 /*
7533 ** CAPI3REF: Checkpoint a database
 
7534 **
7535 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7536 ** operation on database X of [database connection] D in mode M. Status
7537 ** information is written back into integers pointed to by L and C.)^
7538 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
7783 #define SQLITE_SCANSTAT_EXPLAIN 4
7784 #define SQLITE_SCANSTAT_SELECTID 5
7785
7786 /*
7787 ** CAPI3REF: Prepared Statement Scan Status
 
7788 **
7789 ** This interface returns information about the predicted and measured
7790 ** performance for pStmt. Advanced applications can use this
7791 ** interface to compare the predicted and the measured performance and
7792 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
7820 void *pOut /* Result written here */
7821 );
7822
7823 /*
7824 ** CAPI3REF: Zero Scan-Status Counters
 
7825 **
7826 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7827 **
7828 ** This API is only available if the library is built with pre-processor
7829 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
8430 #else
8431 # define ALWAYS(X) (X)
8432 # define NEVER(X) (X)
8433 #endif
8434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8435 /*
8436 ** Return true (non-zero) if the input is an integer that is too large
8437 ** to fit in 32-bits. This macro is used inside of various testcase()
8438 ** macros to verify that we have tested SQLite for large-file support.
8439 */
@@ -9841,37 +9944,36 @@
9841 /* Properties such as "out2" or "jump" that are specified in
9842 ** comments following the "case" for each opcode in the vdbe.c
9843 ** are encoded into bitvectors as follows:
9844 */
9845 #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9846 #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
9847 #define OPFLG_IN1 0x0004 /* in1: P1 is an input */
9848 #define OPFLG_IN2 0x0008 /* in2: P2 is an input */
9849 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9850 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9851 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9852 #define OPFLG_INITIALIZER {\
9853 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9854 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9855 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9856 /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9857 /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9858 /* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\
9859 /* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\
9860 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\
9861 /* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\
9862 /* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\
9863 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9864 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9865 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9866 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9867 /* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9868 /* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9869 /* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9870 /* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9871 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9872 /* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9873
9874 /************** End of opcodes.h *********************************************/
9875 /************** Continuing where we left off in vdbe.h ***********************/
9876
9877 /*
@@ -9926,10 +10028,11 @@
9926 #endif
9927 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
9928
9929 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9930 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
 
9931 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9932
9933 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
9934 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
9935
@@ -11063,10 +11166,11 @@
11063 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
11064 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
11065 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
11066 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
11067 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
 
11068
11069
11070 /*
11071 ** Bits of the sqlite3.dbOptFlags field that are used by the
11072 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
11393 int iSavepoint; /* Depth of the SAVEPOINT stack */
11394 VTable *pNext; /* Next in linked list (see above) */
11395 };
11396
11397 /*
11398 ** Each SQL table is represented in memory by an instance of the
11399 ** following structure.
11400 **
11401 ** Table.zName is the name of the table. The case of the original
11402 ** CREATE TABLE statement is stored, but case is not significant for
11403 ** comparisons.
11404 **
11405 ** Table.nCol is the number of columns in this table. Table.aCol is a
11406 ** pointer to an array of Column structures, one for each column.
11407 **
11408 ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
11409 ** the column that is that key. Otherwise Table.iPKey is negative. Note
11410 ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
11411 ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
11412 ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
11413 ** is generated for each row of the table. TF_HasPrimaryKey is set if
11414 ** the table has any PRIMARY KEY, INTEGER or otherwise.
11415 **
11416 ** Table.tnum is the page number for the root BTree page of the table in the
11417 ** database file. If Table.iDb is the index of the database table backend
11418 ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
11419 ** holds temporary tables and indices. If TF_Ephemeral is set
11420 ** then the table is stored in a file that is automatically deleted
11421 ** when the VDBE cursor to the table is closed. In this case Table.tnum
11422 ** refers VDBE cursor number that holds the table open, not to the root
11423 ** page number. Transient tables are used to hold the results of a
11424 ** sub-query that appears instead of a real table name in the FROM clause
11425 ** of a SELECT statement.
11426 */
11427 struct Table {
11428 char *zName; /* Name of the table or view */
11429 Column *aCol; /* Information about each column */
11430 Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
11432 FKey *pFKey; /* Linked list of all foreign keys in this table */
11433 char *zColAff; /* String defining the affinity of each column */
11434 #ifndef SQLITE_OMIT_CHECK
11435 ExprList *pCheck; /* All CHECK constraints */
11436 #endif
11437 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11438 int tnum; /* Root BTree node for this table (see note above) */
11439 i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
11440 i16 nCol; /* Number of columns in this table */
11441 u16 nRef; /* Number of pointers to this Table */
 
11442 LogEst szTabRow; /* Estimated size of each table row in bytes */
11443 #ifdef SQLITE_ENABLE_COSTMULT
11444 LogEst costMult; /* Cost multiplier for using this table */
11445 #endif
11446 u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
11458 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
11459 };
11460
11461 /*
11462 ** Allowed values for Table.tabFlags.
 
 
 
 
 
 
11463 */
11464 #define TF_Readonly 0x01 /* Read-only system table */
11465 #define TF_Ephemeral 0x02 /* An ephemeral table */
11466 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
11467 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
11468 #define TF_Virtual 0x10 /* Is a virtual table */
11469 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
 
11470
11471
11472 /*
11473 ** Test to see whether or not a table is a virtual table. This is
11474 ** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
12221 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12222 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12223 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12224 #define SF_Compound 0x0040 /* Part of a compound query */
12225 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12226 #define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12227 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12228 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12229 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12230 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12231 #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
12605 *
12606 * (op == TK_INSERT)
12607 * orconf -> stores the ON CONFLICT algorithm
12608 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
12609 * this stores a pointer to the SELECT statement. Otherwise NULL.
12610 * target -> A token holding the quoted name of the table to insert into.
12611 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
12612 * this stores values to be inserted. Otherwise NULL.
12613 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
12614 * statement, then this stores the column-names to be
12615 * inserted into.
12616 *
12617 * (op == TK_DELETE)
12618 * target -> A token holding the quoted name of the table to delete from.
12619 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
12620 * Otherwise NULL.
12621 *
12622 * (op == TK_UPDATE)
12623 * target -> A token holding the quoted name of the table to update rows of.
12624 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
12625 * Otherwise NULL.
12626 * pExprList -> A list of the columns to update and the expressions to update
12627 * them to. See sqlite3Update() documentation of "pChanges"
12628 * argument.
@@ -12630,12 +12715,12 @@
12630 */
12631 struct TriggerStep {
12632 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
12633 u8 orconf; /* OE_Rollback etc. */
12634 Trigger *pTrig; /* The trigger that this step is a part of */
12635 Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
12636 Token target; /* Target table for DELETE, UPDATE, INSERT */
12637 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
12638 ExprList *pExprList; /* SET clause for UPDATE. */
12639 IdList *pIdList; /* Column names for INSERT */
12640 TriggerStep *pNext; /* Next in the link-list */
12641 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
12664 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
12665 char *zBase; /* A base allocation. Not from malloc. */
12666 char *zText; /* The string collected so far */
12667 int nChar; /* Length of the string so far */
12668 int nAlloc; /* Amount of space allocated in zText */
12669 int mxAlloc; /* Maximum allowed string length */
12670 u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
12671 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
12672 };
12673 #define STRACCUM_NOMEM 1
12674 #define STRACCUM_TOOBIG 2
12675
@@ -12982,11 +13066,11 @@
12982 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
12983 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
12984 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
12985 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
12986 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12987 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
12988 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
12989 #endif
12990 #if defined(SQLITE_TEST)
12991 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
12992 #endif
@@ -13329,11 +13413,11 @@
13329 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
13330 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
13331 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
13332 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
13333
13334 #if defined(SQLITE_TEST)
13335 SQLITE_PRIVATE const char *sqlite3ErrName(int);
13336 #endif
13337
13338 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13339 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
13423 FuncDestructor *pDestructor
13424 );
13425 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
13426 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13427
13428 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13429 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13430 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13431 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
13432 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13433 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -19807,20 +19891,10 @@
19807 */
19808 #ifdef MEMORY_DEBUG
19809 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19810 #endif
19811
19812 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19813 # ifndef SQLITE_DEBUG_OS_TRACE
19814 # define SQLITE_DEBUG_OS_TRACE 0
19815 # endif
19816 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19817 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19818 #else
19819 # define OSTRACE(X)
19820 #endif
19821
19822 /*
19823 ** Macros for performance tracing. Normally turned off. Only works
19824 ** on i486 hardware.
19825 */
19826 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21475,11 @@
21401
21402 /*
21403 ** Set the StrAccum object to an error mode.
21404 */
21405 static void setStrAccumError(StrAccum *p, u8 eError){
 
21406 p->accError = eError;
21407 p->nAlloc = 0;
21408 }
21409
21410 /*
@@ -21515,11 +21590,10 @@
21515 case '0': flag_zeropad = 1; break;
21516 default: done = 1; break;
21517 }
21518 }while( !done && (c=(*++fmt))!=0 );
21519 /* Get the field width */
21520 width = 0;
21521 if( c=='*' ){
21522 if( bArgList ){
21523 width = (int)getIntArg(pArgList);
21524 }else{
21525 width = va_arg(ap,int);
@@ -21539,11 +21613,10 @@
21539 width = wx & 0x7fffffff;
21540 }
21541
21542 /* Get the precision */
21543 if( c=='.' ){
21544 precision = 0;
21545 c = *++fmt;
21546 if( c=='*' ){
21547 if( bArgList ){
21548 precision = (int)getIntArg(pArgList);
21549 }else{
@@ -22018,11 +22091,11 @@
22018 if( p->accError ){
22019 testcase(p->accError==STRACCUM_TOOBIG);
22020 testcase(p->accError==STRACCUM_NOMEM);
22021 return 0;
22022 }
22023 if( !p->useMalloc ){
22024 N = p->nAlloc - p->nChar - 1;
22025 setStrAccumError(p, STRACCUM_TOOBIG);
22026 return N;
22027 }else{
22028 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22111,14 @@
22038 setStrAccumError(p, STRACCUM_TOOBIG);
22039 return 0;
22040 }else{
22041 p->nAlloc = (int)szNew;
22042 }
22043 if( p->useMalloc==1 ){
22044 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22045 }else{
22046 zNew = sqlite3_realloc(zOld, p->nAlloc);
22047 }
22048 if( zNew ){
22049 assert( p->zText!=0 || p->nChar==0 );
22050 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
22051 p->zText = zNew;
@@ -22089,11 +22162,11 @@
22089 /*
22090 ** Append N bytes of text from z to the StrAccum object. Increase the
22091 ** size of the memory allocation for StrAccum if necessary.
22092 */
22093 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22094 assert( z!=0 );
22095 assert( p->zText!=0 || p->nChar==0 || p->accError );
22096 assert( N>=0 );
22097 assert( p->accError==0 || p->nAlloc==0 );
22098 if( p->nChar+N >= p->nAlloc ){
22099 enlargeAndAppend(p,z,N);
@@ -22118,16 +22191,12 @@
22118 ** pointer if any kind of error was encountered.
22119 */
22120 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
22121 if( p->zText ){
22122 p->zText[p->nChar] = 0;
22123 if( p->useMalloc && p->zText==p->zBase ){
22124 if( p->useMalloc==1 ){
22125 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22126 }else{
22127 p->zText = sqlite3_malloc(p->nChar+1);
22128 }
22129 if( p->zText ){
22130 memcpy(p->zText, p->zBase, p->nChar+1);
22131 }else{
22132 setStrAccumError(p, STRACCUM_NOMEM);
22133 }
@@ -22139,29 +22208,35 @@
22139 /*
22140 ** Reset an StrAccum string. Reclaim all malloced memory.
22141 */
22142 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
22143 if( p->zText!=p->zBase ){
22144 if( p->useMalloc==1 ){
22145 sqlite3DbFree(p->db, p->zText);
22146 }else{
22147 sqlite3_free(p->zText);
22148 }
22149 }
22150 p->zText = 0;
22151 }
22152
22153 /*
22154 ** Initialize a string accumulator
 
 
 
 
 
 
 
 
 
 
 
22155 */
22156 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
22157 p->zText = p->zBase = zBase;
22158 p->db = 0;
22159 p->nChar = 0;
22160 p->nAlloc = n;
22161 p->mxAlloc = mx;
22162 p->useMalloc = 1;
22163 p->accError = 0;
22164 }
22165
22166 /*
22167 ** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22245,12 @@
22170 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
22171 char *z;
22172 char zBase[SQLITE_PRINT_BUF_SIZE];
22173 StrAccum acc;
22174 assert( db!=0 );
22175 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
22176 db->aLimit[SQLITE_LIMIT_LENGTH]);
22177 acc.db = db;
22178 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
22179 z = sqlite3StrAccumFinish(&acc);
22180 if( acc.accError==STRACCUM_NOMEM ){
22181 db->mallocFailed = 1;
22182 }
@@ -22230,12 +22304,11 @@
22230 }
22231 #endif
22232 #ifndef SQLITE_OMIT_AUTOINIT
22233 if( sqlite3_initialize() ) return 0;
22234 #endif
22235 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
22236 acc.useMalloc = 2;
22237 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22238 z = sqlite3StrAccumFinish(&acc);
22239 return z;
22240 }
22241
@@ -22276,12 +22349,11 @@
22276 (void)SQLITE_MISUSE_BKPT;
22277 if( zBuf ) zBuf[0] = 0;
22278 return zBuf;
22279 }
22280 #endif
22281 sqlite3StrAccumInit(&acc, zBuf, n, 0);
22282 acc.useMalloc = 0;
22283 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22284 return sqlite3StrAccumFinish(&acc);
22285 }
22286 SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
22287 char *z;
@@ -22303,12 +22375,11 @@
22303 */
22304 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22305 StrAccum acc; /* String accumulator */
22306 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22307
22308 sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
22309 acc.useMalloc = 0;
22310 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22311 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
22312 sqlite3StrAccumFinish(&acc));
22313 }
22314
@@ -22322,22 +22393,21 @@
22322 renderLogMsg(iErrCode, zFormat, ap);
22323 va_end(ap);
22324 }
22325 }
22326
22327 #if defined(SQLITE_DEBUG)
22328 /*
22329 ** A version of printf() that understands %lld. Used for debugging.
22330 ** The printf() built into some versions of windows does not understand %lld
22331 ** and segfaults if you give it a long long int.
22332 */
22333 SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
22334 va_list ap;
22335 StrAccum acc;
22336 char zBuf[500];
22337 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22338 acc.useMalloc = 0;
22339 va_start(ap,zFormat);
22340 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22341 va_end(ap);
22342 sqlite3StrAccumFinish(&acc);
22343 fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22430,11 @@
22360 */
22361 /* Add a new subitem to the tree. The moreToFollow flag indicates that this
22362 ** is not the last item in the tree. */
22363 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
22364 if( p==0 ){
22365 p = sqlite3_malloc( sizeof(*p) );
22366 if( p==0 ) return 0;
22367 memset(p, 0, sizeof(*p));
22368 }else{
22369 p->iLevel++;
22370 }
@@ -22383,12 +22453,11 @@
22383 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
22384 va_list ap;
22385 int i;
22386 StrAccum acc;
22387 char zBuf[500];
22388 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22389 acc.useMalloc = 0;
22390 if( p ){
22391 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
22392 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
22393 }
22394 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24076,11 @@
24007 }else{
24008 return 0;
24009 }
24010 }
24011 #endif
 
24012 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
24013 v = v*10 + c;
24014 }
24015
24016 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25331,21 @@
25261 #if SQLITE_ENABLE_LOCKING_STYLE
25262 # include <sys/ioctl.h>
25263 # include <sys/file.h>
25264 # include <sys/param.h>
25265 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
 
 
 
 
 
 
 
 
 
 
 
25266
25267 #if OS_VXWORKS
25268 /* # include <sys/ioctl.h> */
25269 # include <semaphore.h>
25270 # include <limits.h>
@@ -25457,20 +25538,10 @@
25457 */
25458 #ifdef MEMORY_DEBUG
25459 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
25460 #endif
25461
25462 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25463 # ifndef SQLITE_DEBUG_OS_TRACE
25464 # define SQLITE_DEBUG_OS_TRACE 0
25465 # endif
25466 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
25467 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
25468 #else
25469 # define OSTRACE(X)
25470 #endif
25471
25472 /*
25473 ** Macros for performance tracing. Normally turned off. Only works
25474 ** on i486 hardware.
25475 */
25476 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26080,11 @@
26009 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26010 }
26011 #endif
26012
26013
26014 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
26015 /*
26016 ** Helper function for printing out trace information from debugging
26017 ** binaries. This returns the string representation of the supplied
26018 ** integer lock-type.
26019 */
@@ -26272,11 +26343,11 @@
26272 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
26273 int n; /* Length of zAbsoluteName string */
26274
26275 assert( zAbsoluteName[0]=='/' );
26276 n = (int)strlen(zAbsoluteName);
26277 pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) );
26278 if( pNew==0 ) return 0;
26279 pNew->zCanonicalName = (char*)&pNew[1];
26280 memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
26281 n = vxworksSimplifyName(pNew->zCanonicalName, n);
26282
@@ -26676,11 +26747,11 @@
26676 pInode = inodeList;
26677 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
26678 pInode = pInode->pNext;
26679 }
26680 if( pInode==0 ){
26681 pInode = sqlite3_malloc( sizeof(*pInode) );
26682 if( pInode==0 ){
26683 return SQLITE_NOMEM;
26684 }
26685 memset(pInode, 0, sizeof(*pInode));
26686 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29268,11 @@
29197 case SQLITE_FCNTL_VFSNAME: {
29198 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
29199 return SQLITE_OK;
29200 }
29201 case SQLITE_FCNTL_TEMPFILENAME: {
29202 char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
29203 if( zTFile ){
29204 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
29205 *(char**)pArg = zTFile;
29206 }
29207 return SQLITE_OK;
@@ -29638,11 +29709,11 @@
29638 unixInodeInfo *pInode; /* The inode of fd */
29639 char *zShmFilename; /* Name of the file used for SHM */
29640 int nShmFilename; /* Size of the SHM filename in bytes */
29641
29642 /* Allocate space for the new unixShm object. */
29643 p = sqlite3_malloc( sizeof(*p) );
29644 if( p==0 ) return SQLITE_NOMEM;
29645 memset(p, 0, sizeof(*p));
29646 assert( pDbFd->pShm==0 );
29647
29648 /* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29740,11 @@
29669 #ifdef SQLITE_SHM_DIRECTORY
29670 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29671 #else
29672 nShmFilename = 6 + (int)strlen(zBasePath);
29673 #endif
29674 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29675 if( pShmNode==0 ){
29676 rc = SQLITE_NOMEM;
29677 goto shm_open_err;
29678 }
29679 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29950,11 @@
29879 if( pMem==MAP_FAILED ){
29880 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
29881 goto shmpage_out;
29882 }
29883 }else{
29884 pMem = sqlite3_malloc(szRegion);
29885 if( pMem==0 ){
29886 rc = SQLITE_NOMEM;
29887 goto shmpage_out;
29888 }
29889 memset(pMem, 0, szRegion);
@@ -30716,11 +30787,11 @@
30716 else if( pLockingStyle == &afpIoMethods ){
30717 /* AFP locking uses the file path so it needs to be included in
30718 ** the afpLockingContext.
30719 */
30720 afpLockingContext *pCtx;
30721 pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) );
30722 if( pCtx==0 ){
30723 rc = SQLITE_NOMEM;
30724 }else{
30725 /* NB: zFilename exists and remains valid until the file is closed
30726 ** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30817,11 @@
30746 */
30747 char *zLockFile;
30748 int nFilename;
30749 assert( zFilename!=0 );
30750 nFilename = (int)strlen(zFilename) + 6;
30751 zLockFile = (char *)sqlite3_malloc(nFilename);
30752 if( zLockFile==0 ){
30753 rc = SQLITE_NOMEM;
30754 }else{
30755 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
30756 }
@@ -31123,11 +31194,11 @@
31123 UnixUnusedFd *pUnused;
31124 pUnused = findReusableFd(zName, flags);
31125 if( pUnused ){
31126 fd = pUnused->fd;
31127 }else{
31128 pUnused = sqlite3_malloc(sizeof(*pUnused));
31129 if( !pUnused ){
31130 return SQLITE_NOMEM;
31131 }
31132 }
31133 p->pUnused = pUnused;
@@ -31503,11 +31574,11 @@
31503 ** that we always use the same random number sequence. This makes the
31504 ** tests repeatable.
31505 */
31506 memset(zBuf, 0, nBuf);
31507 randomnessPid = osGetpid(0);
31508 #if !defined(SQLITE_TEST)
31509 {
31510 int fd, got;
31511 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31512 if( fd<0 ){
31513 time_t t;
@@ -31915,11 +31986,11 @@
31915 */
31916 pUnused = findReusableFd(path, openFlags);
31917 if( pUnused ){
31918 fd = pUnused->fd;
31919 }else{
31920 pUnused = sqlite3_malloc(sizeof(*pUnused));
31921 if( !pUnused ){
31922 return SQLITE_NOMEM;
31923 }
31924 }
31925 if( fd<0 ){
@@ -31948,11 +32019,11 @@
31948 default:
31949 return SQLITE_CANTOPEN_BKPT;
31950 }
31951 }
31952
31953 pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew));
31954 if( pNew==NULL ){
31955 rc = SQLITE_NOMEM;
31956 goto end_create_proxy;
31957 }
31958 memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32052,22 @@
31981 SQLITE_API int sqlite3_hostid_num = 0;
31982 #endif
31983
31984 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
31985
 
31986 /* Not always defined in the headers as it ought to be */
31987 extern int gethostuuid(uuid_t id, const struct timespec *wait);
 
31988
31989 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
31990 ** bytes of writable memory.
31991 */
31992 static int proxyGetHostID(unsigned char *pHostID, int *pError){
31993 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
31994 memset(pHostID, 0, PROXY_HOSTIDLEN);
31995 # if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31996 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
31997 {
31998 struct timespec timeout = {1, 0}; /* 1 sec timeout */
31999 if( gethostuuid(pHostID, &timeout) ){
32000 int err = errno;
32001 if( pError ){
@@ -32409,11 +32481,11 @@
32409 return rc;
32410 }
32411
32412 /*
32413 ** Given the name of a database file, compute the name of its conch file.
32414 ** Store the conch filename in memory obtained from sqlite3_malloc().
32415 ** Make *pConchPath point to the new name. Return SQLITE_OK on success
32416 ** or SQLITE_NOMEM if unable to obtain memory.
32417 **
32418 ** The caller is responsible for ensuring that the allocated memory
32419 ** space is eventually freed.
@@ -32425,11 +32497,11 @@
32425 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
32426 char *conchPath; /* buffer in which to construct conch name */
32427
32428 /* Allocate space for the conch filename and initialize the name to
32429 ** the name of the original database file. */
32430 *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8);
32431 if( conchPath==0 ){
32432 return SQLITE_NOMEM;
32433 }
32434 memcpy(conchPath, dbPath, len+1);
32435
@@ -32541,11 +32613,11 @@
32541 }
32542
32543 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32544 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
32545
32546 pCtx = sqlite3_malloc( sizeof(*pCtx) );
32547 if( pCtx==0 ){
32548 return SQLITE_NOMEM;
32549 }
32550 memset(pCtx, 0, sizeof(*pCtx));
32551
@@ -32985,20 +33057,10 @@
32985 */
32986 #ifdef MEMORY_DEBUG
32987 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
32988 #endif
32989
32990 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
32991 # ifndef SQLITE_DEBUG_OS_TRACE
32992 # define SQLITE_DEBUG_OS_TRACE 0
32993 # endif
32994 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
32995 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
32996 #else
32997 # define OSTRACE(X)
32998 #endif
32999
33000 /*
33001 ** Macros for performance tracing. Normally turned off. Only works
33002 ** on i486 hardware.
33003 */
33004 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35960,11 @@
35898 ** Used only when SQLITE_NO_SYNC is not defined.
35899 */
35900 BOOL rc;
35901 #endif
35902 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35903 (defined(SQLITE_TEST) && defined(SQLITE_DEBUG))
35904 /*
35905 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
35906 ** OSTRACE() macros.
35907 */
35908 winFile *pFile = (winFile*)id;
@@ -36575,11 +36637,11 @@
36575 DWORD lastErrno; /* The Windows errno from the last I/O error */
36576
36577 int nRef; /* Number of winShm objects pointing to this */
36578 winShm *pFirst; /* All winShm objects pointing to this */
36579 winShmNode *pNext; /* Next in list of all winShmNode objects */
36580 #ifdef SQLITE_DEBUG
36581 u8 nextShmId; /* Next available winShm.id value */
36582 #endif
36583 };
36584
36585 /*
@@ -36606,11 +36668,11 @@
36606 winShmNode *pShmNode; /* The underlying winShmNode object */
36607 winShm *pNext; /* Next winShm with the same winShmNode */
36608 u8 hasMutex; /* True if holding the winShmNode mutex */
36609 u16 sharedMask; /* Mask of shared locks held */
36610 u16 exclMask; /* Mask of exclusive locks held */
36611 #ifdef SQLITE_DEBUG
36612 u8 id; /* Id of this connection with its winShmNode */
36613 #endif
36614 };
36615
36616 /*
@@ -36797,11 +36859,11 @@
36797 if( rc ) goto shm_open_err;
36798 }
36799
36800 /* Make the new connection a child of the winShmNode */
36801 p->pShmNode = pShmNode;
36802 #ifdef SQLITE_DEBUG
36803 p->id = pShmNode->nextShmId++;
36804 #endif
36805 pShmNode->nRef++;
36806 pDbFd->pShm = p;
36807 winShmLeaveMutex();
@@ -37066,11 +37128,11 @@
37066 goto shmpage_out;
37067 }
37068 }
37069
37070 /* Map the requested memory region into this processes address space. */
37071 apNew = (struct ShmRegion *)sqlite3_realloc(
37072 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
37073 );
37074 if( !apNew ){
37075 rc = SQLITE_IOERR_NOMEM;
37076 goto shmpage_out;
@@ -38513,11 +38575,11 @@
38513 ** Write up to nBuf bytes of randomness into zBuf.
38514 */
38515 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
38516 int n = 0;
38517 UNUSED_PARAMETER(pVfs);
38518 #if defined(SQLITE_TEST)
38519 n = nBuf;
38520 memset(zBuf, 0, nBuf);
38521 #else
38522 if( sizeof(SYSTEMTIME)<=nBuf-n ){
38523 SYSTEMTIME x;
@@ -38547,11 +38609,10 @@
38547 LARGE_INTEGER i;
38548 osQueryPerformanceCounter(&i);
38549 memcpy(&zBuf[n], &i, sizeof(i));
38550 n += sizeof(i);
38551 }
38552 #endif
38553 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38554 if( sizeof(UUID)<=nBuf-n ){
38555 UUID id;
38556 memset(&id, 0, sizeof(UUID));
38557 osUuidCreate(&id);
@@ -38564,10 +38625,11 @@
38564 osUuidCreateSequential(&id);
38565 memcpy(zBuf, &id, sizeof(UUID));
38566 n += sizeof(UUID);
38567 }
38568 #endif
 
38569 return n;
38570 }
38571
38572
38573 /*
@@ -39118,11 +39180,11 @@
39118
39119 /* Allocate the Bitvec to be tested and a linear array of
39120 ** bits to act as the reference */
39121 pBitvec = sqlite3BitvecCreate( sz );
39122 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39123 pTmpSpace = sqlite3_malloc(BITVEC_SZ);
39124 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
39125
39126 /* NULL pBitvec tests */
39127 sqlite3BitvecSet(0, 1);
39128 sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44669,11 @@
44607 Pgno nTruncate, /* Database size after this commit */
44608 int isCommit /* True if this is a commit */
44609 ){
44610 int rc; /* Return code */
44611 int nList; /* Number of pages in pList */
44612 #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
44613 PgHdr *p; /* For looping over pages */
44614 #endif
44615
44616 assert( pPager->pWal );
44617 assert( pList );
44618 #ifdef SQLITE_DEBUG
44619 /* Verify that the page list is in accending order */
@@ -44626,11 +44686,10 @@
44626 if( isCommit ){
44627 /* If a WAL transaction is being committed, there is no point in writing
44628 ** any pages with page numbers greater than nTruncate into the WAL file.
44629 ** They will never be read by any client. So remove them from the pDirty
44630 ** list here. */
44631 PgHdr *p;
44632 PgHdr **ppNext = &pList;
44633 nList = 0;
44634 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
44635 if( p->pgno<=nTruncate ){
44636 ppNext = &p->pDirty;
@@ -44646,11 +44705,10 @@
44646 if( pList->pgno==1 ) pager_write_changecounter(pList);
44647 rc = sqlite3WalFrames(pPager->pWal,
44648 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
44649 );
44650 if( rc==SQLITE_OK && pPager->pBackup ){
44651 PgHdr *p;
44652 for(p=pList; p; p=p->pDirty){
44653 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
44654 }
44655 }
44656
@@ -48577,10 +48635,12 @@
48577 }else if( state==PAGER_OPEN ){
48578 pager_unlock(pPager);
48579 }
48580 assert( state==pPager->eState );
48581 }
 
 
48582 }
48583 }
48584
48585 /* Return the new journal mode */
48586 return (int)pPager->journalMode;
@@ -49359,11 +49419,11 @@
49359
49360 /* Enlarge the pWal->apWiData[] array if required */
49361 if( pWal->nWiData<=iPage ){
49362 int nByte = sizeof(u32*)*(iPage+1);
49363 volatile u32 **apNew;
49364 apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte);
49365 if( !apNew ){
49366 *ppPage = 0;
49367 return SQLITE_NOMEM;
49368 }
49369 memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50044,11 @@
49984 goto finished;
49985 }
49986
49987 /* Malloc a buffer to read frames into. */
49988 szFrame = szPage + WAL_FRAME_HDRSIZE;
49989 aFrame = (u8 *)sqlite3_malloc(szFrame);
49990 if( !aFrame ){
49991 rc = SQLITE_NOMEM;
49992 goto recovery_error;
49993 }
49994 aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50437,21 @@
50377 /* Allocate space for the WalIterator object. */
50378 nSegment = walFramePage(iLast) + 1;
50379 nByte = sizeof(WalIterator)
50380 + (nSegment-1)*sizeof(struct WalSegment)
50381 + iLast*sizeof(ht_slot);
50382 p = (WalIterator *)sqlite3_malloc(nByte);
50383 if( !p ){
50384 return SQLITE_NOMEM;
50385 }
50386 memset(p, 0, nByte);
50387 p->nSegment = nSegment;
50388
50389 /* Allocate temporary space used by the merge-sort routine. This block
50390 ** of memory will be freed before this function returns.
50391 */
50392 aTmp = (ht_slot *)sqlite3_malloc(
50393 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
50394 );
50395 if( !aTmp ){
50396 rc = SQLITE_NOMEM;
50397 }
@@ -50567,10 +50627,18 @@
50567 ** cannot be backfilled from the WAL.
50568 */
50569 mxSafeFrame = pWal->hdr.mxFrame;
50570 mxPage = pWal->hdr.nPage;
50571 for(i=1; i<WAL_NREADER; i++){
 
 
 
 
 
 
 
 
50572 u32 y = pInfo->aReadMark[i];
50573 if( mxSafeFrame>y ){
50574 assert( y<=pWal->hdr.mxFrame );
50575 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
50576 if( rc==SQLITE_OK ){
@@ -55407,11 +55475,11 @@
55407 }
55408 assert( nReserve>=0 && nReserve<=255 );
55409 if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
55410 ((pageSize-1)&pageSize)==0 ){
55411 assert( (pageSize & 7)==0 );
55412 assert( !pBt->pPage1 && !pBt->pCursor );
55413 pBt->pageSize = (u32)pageSize;
55414 freeTempSpace(pBt);
55415 }
55416 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
55417 pBt->usableSize = pBt->pageSize - (u16)nReserve;
@@ -57429,17 +57497,22 @@
57429 */
57430 static const void *fetchPayload(
57431 BtCursor *pCur, /* Cursor pointing to entry to read from */
57432 u32 *pAmt /* Write the number of available bytes here */
57433 ){
 
57434 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
57435 assert( pCur->eState==CURSOR_VALID );
57436 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57437 assert( cursorHoldsMutex(pCur) );
57438 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57439 assert( pCur->info.nSize>0 );
57440 *pAmt = pCur->info.nLocal;
 
 
 
 
57441 return (void*)pCur->info.pPayload;
57442 }
57443
57444
57445 /*
@@ -59713,11 +59786,10 @@
59713 if( iParentIdx==0 ){
59714 nxDiv = 0;
59715 }else if( iParentIdx==i ){
59716 nxDiv = i-2+bBulk;
59717 }else{
59718 assert( bBulk==0 );
59719 nxDiv = iParentIdx-1;
59720 }
59721 i = 2-bBulk;
59722 }
59723 nOld = i+1;
@@ -61501,10 +61573,61 @@
61501 iPage = get4byte(pOvflData);
61502 sqlite3PagerUnref(pOvflPage);
61503 }
61504 }
61505 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61506
61507 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
61508 /*
61509 ** Do various sanity checks on a single page of a tree. Return
61510 ** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61657,12 @@
61534 int hdr, cellStart;
61535 int nCell;
61536 u8 *data;
61537 BtShared *pBt;
61538 int usableSize;
61539 char *hit = 0;
 
61540 i64 nMinKey = 0;
61541 i64 nMaxKey = 0;
61542 const char *saved_zPfx = pCheck->zPfx;
61543 int saved_v1 = pCheck->v1;
61544 int saved_v2 = pCheck->v2;
@@ -61679,19 +61803,19 @@
61679
61680 /* Check for complete coverage of the page
61681 */
61682 data = pPage->aData;
61683 hdr = pPage->hdrOffset;
61684 hit = sqlite3PageMalloc( pBt->pageSize );
61685 pCheck->zPfx = 0;
61686 if( hit==0 ){
61687 pCheck->mallocFailed = 1;
61688 }else{
61689 int contentOffset = get2byteNotZero(&data[hdr+5]);
61690 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61691 memset(hit+contentOffset, 0, usableSize-contentOffset);
61692 memset(hit, 1, contentOffset);
61693 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61694 ** number of cells on the page. */
61695 nCell = get2byte(&data[hdr+3]);
61696 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61697 ** immediately follows the b-tree page header. */
@@ -61699,20 +61823,19 @@
61699 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61700 ** integer offsets to the cell contents. */
61701 for(i=0; i<nCell; i++){
61702 int pc = get2byte(&data[cellStart+i*2]);
61703 u32 size = 65536;
61704 int j;
61705 if( pc<=usableSize-4 ){
61706 size = cellSizePtr(pPage, &data[pc]);
61707 }
61708 if( (int)(pc+size-1)>=usableSize ){
61709 pCheck->zPfx = 0;
61710 checkAppendMsg(pCheck,
61711 "Corruption detected in cell %d on page %d",i,iPage);
61712 }else{
61713 for(j=pc+size-1; j>=pc; j--) hit[j]++;
61714 }
61715 }
61716 /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61717 ** is the offset of the first freeblock, or zero if there are no
61718 ** freeblocks on the page. */
@@ -61720,11 +61843,11 @@
61720 while( i>0 ){
61721 int size, j;
61722 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
61723 size = get2byte(&data[i+2]);
61724 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61725 for(j=i+size-1; j>=i; j--) hit[j]++;
61726 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61727 ** big-endian integer which is the offset in the b-tree page of the next
61728 ** freeblock in the chain, or zero if the freeblock is the last on the
61729 ** chain. */
61730 j = get2byte(&data[i]);
@@ -61732,31 +61855,37 @@
61732 ** increasing offset. */
61733 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
61734 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
61735 i = j;
61736 }
61737 for(i=cnt=0; i<usableSize; i++){
61738 if( hit[i]==0 ){
61739 cnt++;
61740 }else if( hit[i]>1 ){
 
 
61741 checkAppendMsg(pCheck,
61742 "Multiple uses for byte %d of page %d", i, iPage);
61743 break;
 
 
 
61744 }
61745 }
 
61746 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61747 ** is stored in the fifth field of the b-tree page header.
61748 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61749 ** number of fragmented free bytes within the cell content area.
61750 */
61751 if( cnt!=data[hdr+7] ){
61752 checkAppendMsg(pCheck,
61753 "Fragmentation of %d bytes reported as %d on page %d",
61754 cnt, data[hdr+7], iPage);
61755 }
61756 }
61757 sqlite3PageFree(hit);
61758 releasePage(pPage);
61759
61760 end_of_check:
61761 pCheck->zPfx = saved_zPfx;
61762 pCheck->v1 = saved_v1;
@@ -61816,12 +61945,11 @@
61816 sqlite3BtreeLeave(p);
61817 return 0;
61818 }
61819 i = PENDING_BYTE_PAGE(pBt);
61820 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61821 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
61822 sCheck.errMsg.useMalloc = 2;
61823
61824 /* Check the integrity of the freelist
61825 */
61826 sCheck.zPfx = "Main freelist: ";
61827 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63281,15 @@
63153 return SQLITE_NOMEM;
63154 }
63155 pMem->z[pMem->n] = 0;
63156 pMem->z[pMem->n+1] = 0;
63157 pMem->flags |= MEM_Term;
 
 
63158 #ifdef SQLITE_DEBUG
63159 pMem->pScopyFrom = 0;
63160 #endif
63161 }
63162
63163 return SQLITE_OK;
63164 }
63165
63166 /*
@@ -64600,11 +64729,11 @@
64600 int i;
64601 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
64602 Mem *aMem = pRec->aMem;
64603 sqlite3 *db = aMem[0].db;
64604 for(i=0; i<nCol; i++){
64605 if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
64606 }
64607 sqlite3KeyInfoUnref(pRec->pKeyInfo);
64608 sqlite3DbFree(db, pRec);
64609 }
64610 }
@@ -66436,18 +66565,35 @@
66436 pVtabCursor->pVtab->nRef--;
66437 pModule->xClose(pVtabCursor);
66438 }
66439 #endif
66440 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66441
66442 /*
66443 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
66444 ** is used, for example, when a trigger sub-program is halted to restore
66445 ** control to the main program.
66446 */
66447 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
66448 Vdbe *v = pFrame->v;
 
66449 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66450 v->anExec = pFrame->anExec;
66451 #endif
66452 v->aOnceFlag = pFrame->aOnceFlag;
66453 v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66624,11 @@
66478 sqlite3VdbeFrameRestore(pFrame);
66479 p->pFrame = 0;
66480 p->nFrame = 0;
66481 }
66482 assert( p->nFrame==0 );
66483
66484 if( p->apCsr ){
66485 int i;
66486 for(i=0; i<p->nCursor; i++){
66487 VdbeCursor *pC = p->apCsr[i];
66488 if( pC ){
66489 sqlite3VdbeFreeCursor(p, pC);
66490 p->apCsr[i] = 0;
66491 }
66492 }
66493 }
66494 if( p->aMem ){
66495 releaseMemArray(&p->aMem[1], p->nMem);
66496 }
66497 while( p->pDelFrame ){
66498 VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68369,11 @@
68233 ** If database corruption is discovered, set pPKey2->errCode to
68234 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
68235 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
68236 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
68237 */
68238 static int vdbeRecordCompareWithSkip(
68239 int nKey1, const void *pKey1, /* Left key */
68240 UnpackedRecord *pPKey2, /* Right key */
68241 int bSkip /* If true, skip the first field */
68242 ){
68243 u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68555,11 @@
68419 }
68420 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
68421 int nKey1, const void *pKey1, /* Left key */
68422 UnpackedRecord *pPKey2 /* Right key */
68423 ){
68424 return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68425 }
68426
68427
68428 /*
68429 ** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68643,11 @@
68507 }else if( v<lhs ){
68508 res = pPKey2->r2;
68509 }else if( pPKey2->nField>1 ){
68510 /* The first fields of the two keys are equal. Compare the trailing
68511 ** fields. */
68512 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68513 }else{
68514 /* The first fields of the two keys are equal and there are no trailing
68515 ** fields. Return pPKey2->default_rc in this case. */
68516 res = pPKey2->default_rc;
68517 }
@@ -68555,11 +68691,11 @@
68555
68556 if( res==0 ){
68557 res = nStr - pPKey2->aMem[0].n;
68558 if( res==0 ){
68559 if( pPKey2->nField>1 ){
68560 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68561 }else{
68562 res = pPKey2->default_rc;
68563 }
68564 }else if( res>0 ){
68565 res = pPKey2->r2;
@@ -70497,21 +70633,22 @@
70497 Mem *pVar; /* Value of a host parameter */
70498 StrAccum out; /* Accumulate the output here */
70499 char zBase[100]; /* Initial working space */
70500
70501 db = p->db;
70502 sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
70503 db->aLimit[SQLITE_LIMIT_LENGTH]);
70504 out.db = db;
70505 if( db->nVdbeExec>1 ){
70506 while( *zRawSql ){
70507 const char *zStart = zRawSql;
70508 while( *(zRawSql++)!='\n' && *zRawSql );
70509 sqlite3StrAccumAppend(&out, "-- ", 3);
70510 assert( (zRawSql - zStart) > 0 );
70511 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
70512 }
 
 
70513 }else{
70514 while( zRawSql[0] ){
70515 n = findNextHostParameter(zRawSql, &nToken);
70516 assert( n>0 );
70517 sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70661,16 @@
70524 sqlite3GetInt32(&zRawSql[1], &idx);
70525 }else{
70526 idx = nextIndex;
70527 }
70528 }else{
70529 assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
 
70530 testcase( zRawSql[0]==':' );
70531 testcase( zRawSql[0]=='$' );
70532 testcase( zRawSql[0]=='@' );
 
70533 idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
70534 assert( idx>0 );
70535 }
70536 zRawSql += nToken;
70537 nextIndex = idx + 1;
@@ -71202,21 +71341,38 @@
71202 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
71203 return 1;
71204 }
71205 #endif
71206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71207
71208 /*
71209 ** Execute as much of a VDBE program as we can.
71210 ** This is the core of sqlite3_step().
71211 */
71212 SQLITE_PRIVATE int sqlite3VdbeExec(
71213 Vdbe *p /* The VDBE */
71214 ){
71215 int pc=0; /* The program counter */
71216 Op *aOp = p->aOp; /* Copy of p->aOp */
71217 Op *pOp; /* Current operation */
 
 
 
71218 int rc = SQLITE_OK; /* Value to return */
71219 sqlite3 *db = p->db; /* The database */
71220 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
71221 u8 encoding = ENC(db); /* The database encoding */
71222 int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71444,26 @@
71288 }
71289 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
71290 }
71291 sqlite3EndBenignMalloc();
71292 #endif
71293 for(pc=p->pc; rc==SQLITE_OK; pc++){
71294 assert( pc>=0 && pc<p->nOp );
71295 if( db->mallocFailed ) goto no_mem;
71296 #ifdef VDBE_PROFILE
71297 start = sqlite3Hwtime();
71298 #endif
71299 nVmStep++;
71300 pOp = &aOp[pc];
71301 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71302 if( p->anExec ) p->anExec[pc]++;
71303 #endif
71304
71305 /* Only allow tracing if SQLITE_DEBUG is defined.
71306 */
71307 #ifdef SQLITE_DEBUG
71308 if( db->flags & SQLITE_VdbeTrace ){
71309 sqlite3VdbePrintOp(stdout, pc, pOp);
71310 }
71311 #endif
71312
71313
71314 /* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71476,13 @@
71321 sqlite3_interrupt(db);
71322 }
71323 }
71324 #endif
71325
71326 /* On any opcode with the "out2-prerelease" tag, free any
71327 ** external allocations out of mem[p2] and set mem[p2] to be
71328 ** an undefined integer. Opcodes will either fill in the integer
71329 ** value or convert mem[p2] to a different type.
71330 */
71331 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71332 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
71333 assert( pOp->p2>0 );
71334 assert( pOp->p2<=(p->nMem-p->nCursor) );
71335 pOut = &aMem[pOp->p2];
71336 memAboutToChange(p, pOut);
71337 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71338 pOut->flags = MEM_Int;
71339 }
71340
71341 /* Sanity checking on other operands */
71342 #ifdef SQLITE_DEBUG
 
71343 if( (pOp->opflags & OPFLG_IN1)!=0 ){
71344 assert( pOp->p1>0 );
71345 assert( pOp->p1<=(p->nMem-p->nCursor) );
71346 assert( memIsValid(&aMem[pOp->p1]) );
71347 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71511,13 @@
71370 assert( pOp->p3>0 );
71371 assert( pOp->p3<=(p->nMem-p->nCursor) );
71372 memAboutToChange(p, &aMem[pOp->p3]);
71373 }
71374 #endif
 
 
 
71375
71376 switch( pOp->opcode ){
71377
71378 /*****************************************************************************
71379 ** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71537,11 @@
71393 ** case statement is followed by a comment of the form "/# same as ... #/"
71394 ** that comment is used to determine the particular value of the opcode.
71395 **
71396 ** Other keywords in the comment that follows each case are used to
71397 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71398 ** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See
71399 ** the mkopcodeh.awk script for additional information.
71400 **
71401 ** Documentation about VDBE opcodes is generated by scanning this file
71402 ** for lines of that contain "Opcode:". That line and all subsequent
71403 ** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71565,12 @@
71421 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
71422 ** that this Goto is the bottom of a loop and that the lines from P2 down
71423 ** to the current line should be indented for EXPLAIN output.
71424 */
71425 case OP_Goto: { /* jump */
71426 pc = pOp->p2 - 1;
 
71427
71428 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
71429 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
71430 ** completion. Check to see if sqlite3_interrupt() has been called
71431 ** or if the progress callback needs to be invoked.
@@ -71466,13 +71611,17 @@
71466 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71467 pIn1 = &aMem[pOp->p1];
71468 assert( VdbeMemDynamic(pIn1)==0 );
71469 memAboutToChange(p, pIn1);
71470 pIn1->flags = MEM_Int;
71471 pIn1->u.i = pc;
71472 REGISTER_TRACE(pOp->p1, pIn1);
71473 pc = pOp->p2 - 1;
 
 
 
 
71474 break;
71475 }
71476
71477 /* Opcode: Return P1 * * * *
71478 **
@@ -71480,11 +71629,11 @@
71480 ** the jump, register P1 becomes undefined.
71481 */
71482 case OP_Return: { /* in1 */
71483 pIn1 = &aMem[pOp->p1];
71484 assert( pIn1->flags==MEM_Int );
71485 pc = (int)pIn1->u.i;
71486 pIn1->flags = MEM_Undefined;
71487 break;
71488 }
71489
71490 /* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71653,11 @@
71504 assert( pOp->p3>=0 && pOp->p3<p->nOp );
71505 pOut = &aMem[pOp->p1];
71506 assert( !VdbeMemDynamic(pOut) );
71507 pOut->u.i = pOp->p3 - 1;
71508 pOut->flags = MEM_Int;
71509 if( pOp->p2 ) pc = pOp->p2 - 1;
71510 break;
71511 }
71512
71513 /* Opcode: EndCoroutine P1 * * * *
71514 **
@@ -71524,11 +71673,11 @@
71524 assert( pIn1->flags==MEM_Int );
71525 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
71526 pCaller = &aOp[pIn1->u.i];
71527 assert( pCaller->opcode==OP_Yield );
71528 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71529 pc = pCaller->p2 - 1;
71530 pIn1->flags = MEM_Undefined;
71531 break;
71532 }
71533
71534 /* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71697,13 @@
71548 int pcDest;
71549 pIn1 = &aMem[pOp->p1];
71550 assert( VdbeMemDynamic(pIn1)==0 );
71551 pIn1->flags = MEM_Int;
71552 pcDest = (int)pIn1->u.i;
71553 pIn1->u.i = pc;
71554 REGISTER_TRACE(pOp->p1, pIn1);
71555 pc = pcDest;
71556 break;
71557 }
71558
71559 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
71560 ** Synopsis: if r[P3]=null halt
@@ -71601,34 +71750,38 @@
71601 ** is the same as executing Halt.
71602 */
71603 case OP_Halt: {
71604 const char *zType;
71605 const char *zLogFmt;
 
 
71606
 
71607 if( pOp->p1==SQLITE_OK && p->pFrame ){
71608 /* Halt the sub-program. Return control to the parent frame. */
71609 VdbeFrame *pFrame = p->pFrame;
71610 p->pFrame = pFrame->pParent;
71611 p->nFrame--;
71612 sqlite3VdbeSetChanges(db, p->nChange);
71613 pc = sqlite3VdbeFrameRestore(pFrame);
71614 lastRowid = db->lastRowid;
71615 if( pOp->p2==OE_Ignore ){
71616 /* Instruction pc is the OP_Program that invoked the sub-program
71617 ** currently being halted. If the p2 instruction of this OP_Halt
71618 ** instruction is set to OE_Ignore, then the sub-program is throwing
71619 ** an IGNORE exception. In this case jump to the address specified
71620 ** as the p2 of the calling OP_Program. */
71621 pc = p->aOp[pc].p2-1;
71622 }
71623 aOp = p->aOp;
71624 aMem = p->aMem;
 
71625 break;
71626 }
71627 p->rc = pOp->p1;
71628 p->errorAction = (u8)pOp->p2;
71629 p->pc = pc;
71630 if( p->rc ){
71631 if( pOp->p5 ){
71632 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
71633 "FOREIGN KEY" };
71634 assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71801,11 @@
71648 }else if( pOp->p4.z ){
71649 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
71650 }else{
71651 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
71652 }
71653 sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
71654 }
71655 rc = sqlite3VdbeHalt(p);
71656 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
71657 if( rc==SQLITE_BUSY ){
71658 p->rc = rc = SQLITE_BUSY;
@@ -71667,11 +71820,12 @@
71667 /* Opcode: Integer P1 P2 * * *
71668 ** Synopsis: r[P2]=P1
71669 **
71670 ** The 32-bit integer value P1 is written into register P2.
71671 */
71672 case OP_Integer: { /* out2-prerelease */
 
71673 pOut->u.i = pOp->p1;
71674 break;
71675 }
71676
71677 /* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71832,12 @@
71678 ** Synopsis: r[P2]=P4
71679 **
71680 ** P4 is a pointer to a 64-bit integer value.
71681 ** Write that value into register P2.
71682 */
71683 case OP_Int64: { /* out2-prerelease */
 
71684 assert( pOp->p4.pI64!=0 );
71685 pOut->u.i = *pOp->p4.pI64;
71686 break;
71687 }
71688
@@ -71691,11 +71846,12 @@
71691 ** Synopsis: r[P2]=P4
71692 **
71693 ** P4 is a pointer to a 64-bit floating point value.
71694 ** Write that value into register P2.
71695 */
71696 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
 
71697 pOut->flags = MEM_Real;
71698 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
71699 pOut->u.r = *pOp->p4.pReal;
71700 break;
71701 }
@@ -71707,12 +71863,13 @@
71707 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71708 ** into a String opcode before it is executed for the first time. During
71709 ** this transformation, the length of string P4 is computed and stored
71710 ** as the P1 parameter.
71711 */
71712 case OP_String8: { /* same as TK_STRING, out2-prerelease */
71713 assert( pOp->p4.z!=0 );
 
71714 pOp->opcode = OP_String;
71715 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
71716
71717 #ifndef SQLITE_OMIT_UTF16
71718 if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71902,13 @@
71745 ** If P5!=0 and the content of register P3 is greater than zero, then
71746 ** the datatype of the register P2 is converted to BLOB. The content is
71747 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
71748 ** of a string, as if it had been CAST.
71749 */
71750 case OP_String: { /* out2-prerelease */
71751 assert( pOp->p4.z!=0 );
 
71752 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71753 pOut->z = pOp->p4.z;
71754 pOut->n = pOp->p1;
71755 pOut->enc = encoding;
71756 UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71932,14 @@
71774 **
71775 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
71776 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
71777 ** OP_Ne or OP_Eq.
71778 */
71779 case OP_Null: { /* out2-prerelease */
71780 int cnt;
71781 u16 nullFlag;
 
71782 cnt = pOp->p3-pOp->p2;
71783 assert( pOp->p3<=(p->nMem-p->nCursor) );
71784 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
71785 while( cnt>0 ){
71786 pOut++;
@@ -71811,12 +71970,13 @@
71811 ** Synopsis: r[P2]=P4 (len=P1)
71812 **
71813 ** P4 points to a blob of data P1 bytes long. Store this
71814 ** blob in register P2.
71815 */
71816 case OP_Blob: { /* out2-prerelease */
71817 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
 
71818 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
71819 pOut->enc = encoding;
71820 UPDATE_MAX_BLOBSIZE(pOut);
71821 break;
71822 }
@@ -71827,19 +71987,20 @@
71827 ** Transfer the values of bound parameter P1 into register P2
71828 **
71829 ** If the parameter is named, then its name appears in P4.
71830 ** The P4 value is used by sqlite3_bind_parameter_name().
71831 */
71832 case OP_Variable: { /* out2-prerelease */
71833 Mem *pVar; /* Value being transferred */
71834
71835 assert( pOp->p1>0 && pOp->p1<=p->nVar );
71836 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
71837 pVar = &p->aVar[pOp->p1 - 1];
71838 if( sqlite3VdbeMemTooBig(pVar) ){
71839 goto too_big;
71840 }
 
71841 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
71842 UPDATE_MAX_BLOBSIZE(pOut);
71843 break;
71844 }
71845
@@ -71870,14 +72031,15 @@
71870 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
71871 assert( memIsValid(pIn1) );
71872 memAboutToChange(p, pOut);
71873 sqlite3VdbeMemMove(pOut, pIn1);
71874 #ifdef SQLITE_DEBUG
71875 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
71876 pOut->pScopyFrom += p1 - pOp->p2;
71877 }
71878 #endif
 
71879 REGISTER_TRACE(p2++, pOut);
71880 pIn1++;
71881 pOut++;
71882 }while( --n );
71883 break;
@@ -72012,11 +72174,11 @@
72012 }
72013 if( db->mallocFailed ) goto no_mem;
72014
72015 /* Return SQLITE_ROW
72016 */
72017 p->pc = pc + 1;
72018 rc = SQLITE_ROW;
72019 goto vdbe_return;
72020 }
72021
72022 /* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72420,11 @@
72258 REGISTER_TRACE(pOp->p2+i, pArg);
72259 }
72260
72261 assert( pOp->p4type==P4_FUNCDEF );
72262 ctx.pFunc = pOp->p4.pFunc;
72263 ctx.iOp = pc;
72264 ctx.pVdbe = p;
72265 MemSetTypeFlag(ctx.pOut, MEM_Null);
72266 ctx.fErrorOrAux = 0;
72267 db->lastRowid = lastRowid;
72268 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72434,11 @@
72272 if( ctx.fErrorOrAux ){
72273 if( ctx.isError ){
72274 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
72275 rc = ctx.isError;
72276 }
72277 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
72278 }
72279
72280 /* Copy the result of the function into register P3 */
72281 sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
72282 if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72563,11 @@
72401 if( (pIn1->flags & MEM_Int)==0 ){
72402 if( pOp->p2==0 ){
72403 rc = SQLITE_MISMATCH;
72404 goto abort_due_to_error;
72405 }else{
72406 pc = pOp->p2 - 1;
72407 break;
72408 }
72409 }
72410 }
72411 MemSetTypeFlag(pIn1, MEM_Int);
72412 break;
@@ -72588,11 +72749,11 @@
72588 MemSetTypeFlag(pOut, MEM_Null);
72589 REGISTER_TRACE(pOp->p2, pOut);
72590 }else{
72591 VdbeBranchTaken(2,3);
72592 if( pOp->p5 & SQLITE_JUMPIFNULL ){
72593 pc = pOp->p2-1;
72594 }
72595 }
72596 break;
72597 }
72598 }else{
@@ -72639,10 +72800,16 @@
72639 case OP_Lt: res = res<0; break;
72640 case OP_Le: res = res<=0; break;
72641 case OP_Gt: res = res>0; break;
72642 default: res = res>=0; break;
72643 }
 
 
 
 
 
 
72644
72645 if( pOp->p5 & SQLITE_STOREP2 ){
72646 pOut = &aMem[pOp->p2];
72647 memAboutToChange(p, pOut);
72648 MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72816,13 @@
72649 pOut->u.i = res;
72650 REGISTER_TRACE(pOp->p2, pOut);
72651 }else{
72652 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
72653 if( res ){
72654 pc = pOp->p2-1;
72655 }
72656 }
72657 /* Undo any changes made by applyAffinity() to the input registers. */
72658 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72659 pIn1->flags = flags1;
72660 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72661 pIn3->flags = flags3;
72662 break;
72663 }
72664
72665 /* Opcode: Permutation * * * P4 *
72666 **
@@ -72751,15 +72913,15 @@
72751 ** in the most recent OP_Compare instruction the P1 vector was less than
72752 ** equal to, or greater than the P2 vector, respectively.
72753 */
72754 case OP_Jump: { /* jump */
72755 if( iCompare<0 ){
72756 pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
72757 }else if( iCompare==0 ){
72758 pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
72759 }else{
72760 pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
72761 }
72762 break;
72763 }
72764
72765 /* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73027,11 @@
72865 */
72866 case OP_Once: { /* jump */
72867 assert( pOp->p1<p->nOnceFlag );
72868 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
72869 if( p->aOnceFlag[pOp->p1] ){
72870 pc = pOp->p2-1;
72871 }else{
72872 p->aOnceFlag[pOp->p1] = 1;
72873 }
72874 break;
72875 }
@@ -72900,11 +73062,11 @@
72900 #endif
72901 if( pOp->opcode==OP_IfNot ) c = !c;
72902 }
72903 VdbeBranchTaken(c!=0, 2);
72904 if( c ){
72905 pc = pOp->p2-1;
72906 }
72907 break;
72908 }
72909
72910 /* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73076,11 @@
72914 */
72915 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
72916 pIn1 = &aMem[pOp->p1];
72917 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
72918 if( (pIn1->flags & MEM_Null)!=0 ){
72919 pc = pOp->p2 - 1;
72920 }
72921 break;
72922 }
72923
72924 /* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73090,11 @@
72928 */
72929 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
72930 pIn1 = &aMem[pOp->p1];
72931 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
72932 if( (pIn1->flags & MEM_Null)==0 ){
72933 pc = pOp->p2 - 1;
72934 }
72935 break;
72936 }
72937
72938 /* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73304,11 @@
73142 rc = SQLITE_CORRUPT_BKPT;
73143 goto op_column_error;
73144 }
73145 }
73146
73147 /* If after trying to extra new entries from the header, nHdrParsed is
73148 ** still not up to p2, that means that the record has fewer than p2
73149 ** columns. So the result will be either the default value or a NULL.
73150 */
73151 if( pC->nHdrParsed<=p2 ){
73152 if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73428,11 @@
73266 u8 *zNewRecord; /* A buffer to hold the data for the new record */
73267 Mem *pRec; /* The new record */
73268 u64 nData; /* Number of bytes of data space */
73269 int nHdr; /* Number of bytes of header space */
73270 i64 nByte; /* Data space required for this record */
73271 int nZero; /* Number of zero bytes at the end of the record */
73272 int nVarint; /* Number of bytes in a varint */
73273 u32 serial_type; /* Type field */
73274 Mem *pData0; /* First field to be combined into the record */
73275 Mem *pLast; /* Last field of the record */
73276 int nField; /* Number of fields in the record */
@@ -73358,11 +73520,11 @@
73358 nVarint = sqlite3VarintLen(nHdr);
73359 nHdr += nVarint;
73360 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
73361 }
73362 nByte = nHdr+nData;
73363 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73364 goto too_big;
73365 }
73366
73367 /* Make sure the output register has a buffer large enough to store
73368 ** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73571,19 @@
73409 **
73410 ** Store the number of entries (an integer value) in the table or index
73411 ** opened by cursor P1 in register P2
73412 */
73413 #ifndef SQLITE_OMIT_BTREECOUNT
73414 case OP_Count: { /* out2-prerelease */
73415 i64 nEntry;
73416 BtCursor *pCrsr;
73417
73418 pCrsr = p->apCsr[pOp->p1]->pCursor;
73419 assert( pCrsr );
73420 nEntry = 0; /* Not needed. Only used to silence a warning. */
73421 rc = sqlite3BtreeCount(pCrsr, &nEntry);
 
73422 pOut->u.i = nEntry;
73423 break;
73424 }
73425 #endif
73426
@@ -73530,11 +73693,11 @@
73530 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73531 goto vdbe_return;
73532 }
73533 db->autoCommit = 1;
73534 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73535 p->pc = pc;
73536 db->autoCommit = 0;
73537 p->rc = rc = SQLITE_BUSY;
73538 goto vdbe_return;
73539 }
73540 db->isTransactionSavepoint = 0;
@@ -73589,11 +73752,11 @@
73589 }else{
73590 db->nDeferredCons = pSavepoint->nDeferredCons;
73591 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
73592 }
73593
73594 if( !isTransaction ){
73595 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
73596 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73597 }
73598 }
73599 }
@@ -73649,11 +73812,11 @@
73649 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73650 goto vdbe_return;
73651 }else{
73652 db->autoCommit = (u8)desiredAutoCommit;
73653 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73654 p->pc = pc;
73655 db->autoCommit = (u8)(1-desiredAutoCommit);
73656 p->rc = rc = SQLITE_BUSY;
73657 goto vdbe_return;
73658 }
73659 }
@@ -73726,11 +73889,11 @@
73726 pBt = db->aDb[pOp->p1].pBt;
73727
73728 if( pBt ){
73729 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
73730 if( rc==SQLITE_BUSY ){
73731 p->pc = pc;
73732 p->rc = rc = SQLITE_BUSY;
73733 goto vdbe_return;
73734 }
73735 if( rc!=SQLITE_OK ){
73736 goto abort_due_to_error;
@@ -73805,11 +73968,11 @@
73805 **
73806 ** There must be a read-lock on the database (either a transaction
73807 ** must be started or there must be an open cursor) before
73808 ** executing this instruction.
73809 */
73810 case OP_ReadCookie: { /* out2-prerelease */
73811 int iMeta;
73812 int iDb;
73813 int iCookie;
73814
73815 assert( p->bIsReader );
@@ -73819,10 +73982,11 @@
73819 assert( iDb>=0 && iDb<db->nDb );
73820 assert( db->aDb[iDb].pBt!=0 );
73821 assert( DbMaskTest(p->btreeMask, iDb) );
73822
73823 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
 
73824 pOut->u.i = iMeta;
73825 break;
73826 }
73827
73828 /* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74304,11 @@
74140 VdbeCursor *pC;
74141 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74142 pC = p->apCsr[pOp->p1];
74143 assert( pC->pSorter );
74144 if( (pC->seqCount++)==0 ){
74145 pc = pOp->p2 - 1;
74146 }
74147 break;
74148 }
74149
74150 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74481,11 @@
74317 ** loss of information, then special processing is required... */
74318 if( (pIn3->flags & MEM_Int)==0 ){
74319 if( (pIn3->flags & MEM_Real)==0 ){
74320 /* If the P3 value cannot be converted into any kind of a number,
74321 ** then the seek is not possible, so jump to P2 */
74322 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74323 break;
74324 }
74325
74326 /* If the approximation iKey is larger than the actual real search
74327 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74572,11 @@
74408 }
74409 }
74410 assert( pOp->p2>0 );
74411 VdbeBranchTaken(res!=0,2);
74412 if( res ){
74413 pc = pOp->p2 - 1;
74414 }
74415 break;
74416 }
74417
74418 /* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74666,11 @@
74502 */
74503 case OP_NoConflict: /* jump, in3 */
74504 case OP_NotFound: /* jump, in3 */
74505 case OP_Found: { /* jump, in3 */
74506 int alreadyExists;
 
74507 int ii;
74508 VdbeCursor *pC;
74509 int res;
74510 char *pFree;
74511 UnpackedRecord *pIdxKey;
@@ -74524,11 +74689,11 @@
74524 pC->seekOp = pOp->opcode;
74525 #endif
74526 pIn3 = &aMem[pOp->p3];
74527 assert( pC->pCursor!=0 );
74528 assert( pC->isTable==0 );
74529 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
74530 if( pOp->p4.i>0 ){
74531 r.pKeyInfo = pC->pKeyInfo;
74532 r.nField = (u16)pOp->p4.i;
74533 r.aMem = pIn3;
74534 for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74712,24 @@
74547 assert( pIn3->flags & MEM_Blob );
74548 ExpandBlob(pIn3);
74549 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
74550 }
74551 pIdxKey->default_rc = 0;
 
74552 if( pOp->opcode==OP_NoConflict ){
74553 /* For the OP_NoConflict opcode, take the jump if any of the
74554 ** input fields are NULL, since any key with a NULL will not
74555 ** conflict */
74556 for(ii=0; ii<pIdxKey->nField; ii++){
74557 if( pIdxKey->aMem[ii].flags & MEM_Null ){
74558 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74559 break;
74560 }
74561 }
74562 }
74563 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74564 if( pOp->p4.i==0 ){
74565 sqlite3DbFree(db, pFree);
74566 }
74567 if( rc!=SQLITE_OK ){
74568 break;
74569 }
74570 pC->seekResult = res;
74571 alreadyExists = (res==0);
@@ -74572,14 +74736,14 @@
74572 pC->nullRow = 1-alreadyExists;
74573 pC->deferredMoveto = 0;
74574 pC->cacheStatus = CACHE_STALE;
74575 if( pOp->opcode==OP_Found ){
74576 VdbeBranchTaken(alreadyExists!=0,2);
74577 if( alreadyExists ) pc = pOp->p2 - 1;
74578 }else{
74579 VdbeBranchTaken(alreadyExists==0,2);
74580 if( !alreadyExists ) pc = pOp->p2 - 1;
74581 }
74582 break;
74583 }
74584
74585 /* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74788,12 @@
74624 pC->movetoTarget = iKey; /* Used by OP_Delete */
74625 pC->nullRow = 0;
74626 pC->cacheStatus = CACHE_STALE;
74627 pC->deferredMoveto = 0;
74628 VdbeBranchTaken(res!=0,2);
74629 if( res!=0 ){
74630 pc = pOp->p2 - 1;
74631 }
74632 pC->seekResult = res;
 
74633 break;
74634 }
74635
74636 /* Opcode: Sequence P1 P2 * * *
74637 ** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74801,14 @@
74639 ** Find the next available sequence number for cursor P1.
74640 ** Write the sequence number into register P2.
74641 ** The sequence number on the cursor is incremented after this
74642 ** instruction.
74643 */
74644 case OP_Sequence: { /* out2-prerelease */
74645 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74646 assert( p->apCsr[pOp->p1]!=0 );
 
74647 pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
74648 break;
74649 }
74650
74651
@@ -74662,20 +74825,21 @@
74662 ** allowed to be less than this value. When this value reaches its maximum,
74663 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
74664 ** generated record number. This P3 mechanism is used to help implement the
74665 ** AUTOINCREMENT feature.
74666 */
74667 case OP_NewRowid: { /* out2-prerelease */
74668 i64 v; /* The new rowid */
74669 VdbeCursor *pC; /* Cursor of table to get the new rowid */
74670 int res; /* Result of an sqlite3BtreeLast() */
74671 int cnt; /* Counter to limit the number of searches */
74672 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
74673 VdbeFrame *pFrame; /* Root frame of VDBE */
74674
74675 v = 0;
74676 res = 0;
 
74677 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74678 pC = p->apCsr[pOp->p1];
74679 assert( pC!=0 );
74680 if( NEVER(pC->pCursor==0) ){
74681 /* The zero initialization above is all that is needed */
@@ -74985,13 +75149,11 @@
74985 pIn3 = &aMem[pOp->p3];
74986 nKeyCol = pOp->p4.i;
74987 res = 0;
74988 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
74989 VdbeBranchTaken(res!=0,2);
74990 if( res ){
74991 pc = pOp->p2-1;
74992 }
74993 break;
74994 };
74995
74996 /* Opcode: SorterData P1 P2 P3 * *
74997 ** Synopsis: r[P2]=data
@@ -75116,16 +75278,17 @@
75116 **
75117 ** P1 can be either an ordinary table or a virtual table. There used to
75118 ** be a separate OP_VRowid opcode for use with virtual tables, but this
75119 ** one opcode now works for both table types.
75120 */
75121 case OP_Rowid: { /* out2-prerelease */
75122 VdbeCursor *pC;
75123 i64 v;
75124 sqlite3_vtab *pVtab;
75125 const sqlite3_module *pModule;
75126
 
75127 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75128 pC = p->apCsr[pOp->p1];
75129 assert( pC!=0 );
75130 assert( pC->pseudoTableReg==0 || pC->nullRow );
75131 if( pC->nullRow ){
@@ -75174,11 +75337,11 @@
75174 sqlite3BtreeClearCursor(pC->pCursor);
75175 }
75176 break;
75177 }
75178
75179 /* Opcode: Last P1 P2 * * *
75180 **
75181 ** The next use of the Rowid or Column or Prev instruction for P1
75182 ** will refer to the last entry in the database table or index.
75183 ** If the table or index is empty and P2>0, then jump immediately to P2.
75184 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75364,17 @@
75201 assert( pCrsr!=0 );
75202 rc = sqlite3BtreeLast(pCrsr, &res);
75203 pC->nullRow = (u8)res;
75204 pC->deferredMoveto = 0;
75205 pC->cacheStatus = CACHE_STALE;
 
75206 #ifdef SQLITE_DEBUG
75207 pC->seekOp = OP_Last;
75208 #endif
75209 if( pOp->p2>0 ){
75210 VdbeBranchTaken(res!=0,2);
75211 if( res ) pc = pOp->p2 - 1;
75212 }
75213 break;
75214 }
75215
75216
@@ -75270,13 +75434,11 @@
75270 pC->cacheStatus = CACHE_STALE;
75271 }
75272 pC->nullRow = (u8)res;
75273 assert( pOp->p2>0 && pOp->p2<p->nOp );
75274 VdbeBranchTaken(res!=0,2);
75275 if( res ){
75276 pc = pOp->p2 - 1;
75277 }
75278 break;
75279 }
75280
75281 /* Opcode: Next P1 P2 P3 P4 P5
75282 **
@@ -75383,15 +75545,15 @@
75383 next_tail:
75384 pC->cacheStatus = CACHE_STALE;
75385 VdbeBranchTaken(res==0,2);
75386 if( res==0 ){
75387 pC->nullRow = 0;
75388 pc = pOp->p2 - 1;
75389 p->aCounter[pOp->p5]++;
75390 #ifdef SQLITE_TEST
75391 sqlite3_search_count++;
75392 #endif
 
75393 }else{
75394 pC->nullRow = 1;
75395 }
75396 goto check_for_interrupt;
75397 }
@@ -75495,15 +75657,16 @@
75495 ** the end of the index key pointed to by cursor P1. This integer should be
75496 ** the rowid of the table entry to which this index entry points.
75497 **
75498 ** See also: Rowid, MakeRecord.
75499 */
75500 case OP_IdxRowid: { /* out2-prerelease */
75501 BtCursor *pCrsr;
75502 VdbeCursor *pC;
75503 i64 rowid;
75504
 
75505 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75506 pC = p->apCsr[pOp->p1];
75507 assert( pC!=0 );
75508 pCrsr = pC->pCursor;
75509 assert( pCrsr!=0 );
@@ -75612,13 +75775,11 @@
75612 }else{
75613 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
75614 res++;
75615 }
75616 VdbeBranchTaken(res>0,2);
75617 if( res>0 ){
75618 pc = pOp->p2 - 1 ;
75619 }
75620 break;
75621 }
75622
75623 /* Opcode: Destroy P1 P2 P3 * *
75624 **
@@ -75638,15 +75799,16 @@
75638 ** the last one in the database) then a zero is stored in register P2.
75639 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
75640 **
75641 ** See also: Clear
75642 */
75643 case OP_Destroy: { /* out2-prerelease */
75644 int iMoved;
75645 int iDb;
75646
75647 assert( p->readOnly==0 );
 
75648 pOut->flags = MEM_Null;
75649 if( db->nVdbeRead > db->nVDestroy+1 ){
75650 rc = SQLITE_LOCKED;
75651 p->errorAction = OE_Abort;
75652 }else{
@@ -75751,16 +75913,17 @@
75751 ** P1>1. Write the root page number of the new table into
75752 ** register P2.
75753 **
75754 ** See documentation on OP_CreateTable for additional information.
75755 */
75756 case OP_CreateIndex: /* out2-prerelease */
75757 case OP_CreateTable: { /* out2-prerelease */
75758 int pgno;
75759 int flags;
75760 Db *pDb;
75761
 
75762 pgno = 0;
75763 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75764 assert( DbMaskTest(p->btreeMask, pOp->p1) );
75765 assert( p->readOnly==0 );
75766 pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76145,16 @@
75982 if( (pIn1->flags & MEM_RowSet)==0
75983 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
75984 ){
75985 /* The boolean index is empty */
75986 sqlite3VdbeMemSetNull(pIn1);
75987 pc = pOp->p2 - 1;
75988 VdbeBranchTaken(1,2);
 
75989 }else{
75990 /* A value was pulled from the index */
75991 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
75992 VdbeBranchTaken(0,2);
 
75993 }
75994 goto check_for_interrupt;
75995 }
75996
75997 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76201,11 @@
76038 assert( pOp->p4type==P4_INT32 );
76039 assert( iSet==-1 || iSet>=0 );
76040 if( iSet ){
76041 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
76042 VdbeBranchTaken(exists!=0,2);
76043 if( exists ){
76044 pc = pOp->p2 - 1;
76045 break;
76046 }
76047 }
76048 if( iSet>=0 ){
76049 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
76050 }
76051 break;
@@ -76130,11 +76290,11 @@
76130 pRt->u.pFrame = pFrame;
76131
76132 pFrame->v = p;
76133 pFrame->nChildMem = nMem;
76134 pFrame->nChildCsr = pProgram->nCsr;
76135 pFrame->pc = pc;
76136 pFrame->aMem = p->aMem;
76137 pFrame->nMem = p->nMem;
76138 pFrame->apCsr = p->apCsr;
76139 pFrame->nCursor = p->nCursor;
76140 pFrame->aOp = p->aOp;
@@ -76153,11 +76313,11 @@
76153 }
76154 }else{
76155 pFrame = pRt->u.pFrame;
76156 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
76157 assert( pProgram->nCsr==pFrame->nChildCsr );
76158 assert( pc==pFrame->pc );
76159 }
76160
76161 p->nFrame++;
76162 pFrame->pParent = p->pFrame;
76163 pFrame->lastRowid = lastRowid;
@@ -76174,11 +76334,11 @@
76174 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
76175 p->nOnceFlag = pProgram->nOnce;
76176 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
76177 p->anExec = 0;
76178 #endif
76179 pc = -1;
76180 memset(p->aOnceFlag, 0, p->nOnceFlag);
76181
76182 break;
76183 }
76184
@@ -76192,13 +76352,14 @@
76192 **
76193 ** The address of the cell in the parent frame is determined by adding
76194 ** the value of the P1 argument to the value of the P1 argument to the
76195 ** calling OP_Program instruction.
76196 */
76197 case OP_Param: { /* out2-prerelease */
76198 VdbeFrame *pFrame;
76199 Mem *pIn;
 
76200 pFrame = p->pFrame;
76201 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
76202 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
76203 break;
76204 }
@@ -76238,14 +76399,14 @@
76238 ** (immediate foreign key constraint violations).
76239 */
76240 case OP_FkIfZero: { /* jump */
76241 if( pOp->p1 ){
76242 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76243 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76244 }else{
76245 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76246 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76247 }
76248 break;
76249 }
76250 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
76251
@@ -76292,13 +76453,11 @@
76292 */
76293 case OP_IfPos: { /* jump, in1 */
76294 pIn1 = &aMem[pOp->p1];
76295 assert( pIn1->flags&MEM_Int );
76296 VdbeBranchTaken( pIn1->u.i>0, 2);
76297 if( pIn1->u.i>0 ){
76298 pc = pOp->p2 - 1;
76299 }
76300 break;
76301 }
76302
76303 /* Opcode: IfNeg P1 P2 P3 * *
76304 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76468,11 @@
76309 case OP_IfNeg: { /* jump, in1 */
76310 pIn1 = &aMem[pOp->p1];
76311 assert( pIn1->flags&MEM_Int );
76312 pIn1->u.i += pOp->p3;
76313 VdbeBranchTaken(pIn1->u.i<0, 2);
76314 if( pIn1->u.i<0 ){
76315 pc = pOp->p2 - 1;
76316 }
76317 break;
76318 }
76319
76320 /* Opcode: IfNotZero P1 P2 P3 * *
76321 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76485,11 @@
76328 pIn1 = &aMem[pOp->p1];
76329 assert( pIn1->flags&MEM_Int );
76330 VdbeBranchTaken(pIn1->u.i<0, 2);
76331 if( pIn1->u.i ){
76332 pIn1->u.i += pOp->p3;
76333 pc = pOp->p2 - 1;
76334 }
76335 break;
76336 }
76337
76338 /* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76501,11 @@
76344 case OP_DecrJumpZero: { /* jump, in1 */
76345 pIn1 = &aMem[pOp->p1];
76346 assert( pIn1->flags&MEM_Int );
76347 pIn1->u.i--;
76348 VdbeBranchTaken(pIn1->u.i==0, 2);
76349 if( pIn1->u.i==0 ){
76350 pc = pOp->p2 - 1;
76351 }
76352 break;
76353 }
76354
76355
76356 /* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76517,11 @@
76362 */
76363 case OP_JumpZeroIncr: { /* jump, in1 */
76364 pIn1 = &aMem[pOp->p1];
76365 assert( pIn1->flags&MEM_Int );
76366 VdbeBranchTaken(pIn1->u.i==0, 2);
76367 if( (pIn1->u.i++)==0 ){
76368 pc = pOp->p2 - 1;
76369 }
76370 break;
76371 }
76372
76373 /* Opcode: AggStep * P2 P3 P4 P5
76374 ** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76559,11 @@
76406 pMem->n++;
76407 sqlite3VdbeMemInit(&t, db, MEM_Null);
76408 ctx.pOut = &t;
76409 ctx.isError = 0;
76410 ctx.pVdbe = p;
76411 ctx.iOp = pc;
76412 ctx.skipFlag = 0;
76413 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
76414 if( ctx.isError ){
76415 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
76416 rc = ctx.isError;
@@ -76501,19 +76654,20 @@
76501 **
76502 ** If changing into or out of WAL mode the procedure is more complicated.
76503 **
76504 ** Write a string containing the final journal-mode to register P2.
76505 */
76506 case OP_JournalMode: { /* out2-prerelease */
76507 Btree *pBt; /* Btree to change journal mode of */
76508 Pager *pPager; /* Pager associated with pBt */
76509 int eNew; /* New journal mode */
76510 int eOld; /* The old journal mode */
76511 #ifndef SQLITE_OMIT_WAL
76512 const char *zFilename; /* Name of database file for pPager */
76513 #endif
76514
 
76515 eNew = pOp->p3;
76516 assert( eNew==PAGER_JOURNALMODE_DELETE
76517 || eNew==PAGER_JOURNALMODE_TRUNCATE
76518 || eNew==PAGER_JOURNALMODE_PERSIST
76519 || eNew==PAGER_JOURNALMODE_OFF
@@ -76585,11 +76739,10 @@
76585 if( rc ){
76586 eNew = eOld;
76587 }
76588 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
76589
76590 pOut = &aMem[pOp->p2];
76591 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
76592 pOut->z = (char *)sqlite3JournalModename(eNew);
76593 pOut->n = sqlite3Strlen30(pOut->z);
76594 pOut->enc = SQLITE_UTF8;
76595 sqlite3VdbeChangeEncoding(pOut, encoding);
@@ -76626,12 +76779,12 @@
76626 assert( p->readOnly==0 );
76627 pBt = db->aDb[pOp->p1].pBt;
76628 rc = sqlite3BtreeIncrVacuum(pBt);
76629 VdbeBranchTaken(rc==SQLITE_DONE,2);
76630 if( rc==SQLITE_DONE ){
76631 pc = pOp->p2 - 1;
76632 rc = SQLITE_OK;
 
76633 }
76634 break;
76635 }
76636 #endif
76637
@@ -76780,12 +76933,13 @@
76780 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76781 if( pCur ){
76782 pCur->pVtabCursor = pVtabCursor;
76783 pVtab->nRef++;
76784 }else{
76785 db->mallocFailed = 1;
76786 pModule->xClose(pVtabCursor);
 
76787 }
76788 }
76789 break;
76790 }
76791 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76991,23 @@
76837 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
76838 nArg = (int)pArgc->u.i;
76839 iQuery = (int)pQuery->u.i;
76840
76841 /* Invoke the xFilter method */
76842 {
76843 res = 0;
76844 apArg = p->apArg;
76845 for(i = 0; i<nArg; i++){
76846 apArg[i] = &pArgc[i+1];
76847 }
76848
76849 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76850 sqlite3VtabImportErrmsg(p, pVtab);
76851 if( rc==SQLITE_OK ){
76852 res = pModule->xEof(pVtabCursor);
76853 }
76854 VdbeBranchTaken(res!=0,2);
76855 if( res ){
76856 pc = pOp->p2 - 1;
76857 }
76858 }
76859 pCur->nullRow = 0;
76860
 
76861 break;
76862 }
76863 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76864
76865 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77090,11 @@
76942 res = pModule->xEof(pCur->pVtabCursor);
76943 }
76944 VdbeBranchTaken(!res,2);
76945 if( !res ){
76946 /* If there is data, jump to P2 */
76947 pc = pOp->p2 - 1;
76948 }
76949 goto check_for_interrupt;
76950 }
76951 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76952
@@ -77065,11 +77213,12 @@
77065 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
77066 /* Opcode: Pagecount P1 P2 * * *
77067 **
77068 ** Write the current number of pages in database P1 to memory cell P2.
77069 */
77070 case OP_Pagecount: { /* out2-prerelease */
 
77071 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
77072 break;
77073 }
77074 #endif
77075
@@ -77081,14 +77230,15 @@
77081 ** Do not let the maximum page count fall below the current page count and
77082 ** do not change the maximum page count value if P3==0.
77083 **
77084 ** Store the maximum page count after the change in register P2.
77085 */
77086 case OP_MaxPgcnt: { /* out2-prerelease */
77087 unsigned int newMax;
77088 Btree *pBt;
77089
 
77090 pBt = db->aDb[pOp->p1].pBt;
77091 newMax = 0;
77092 if( pOp->p3 ){
77093 newMax = sqlite3BtreeLastPage(pBt);
77094 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77263,10 @@
77113 */
77114 case OP_Init: { /* jump */
77115 char *zTrace;
77116 char *z;
77117
77118 if( pOp->p2 ){
77119 pc = pOp->p2 - 1;
77120 }
77121 #ifndef SQLITE_OMIT_TRACE
77122 if( db->xTrace
77123 && !p->doingRerun
77124 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
77125 ){
@@ -77143,10 +77290,11 @@
77143 ){
77144 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
77145 }
77146 #endif /* SQLITE_DEBUG */
77147 #endif /* SQLITE_OMIT_TRACE */
 
77148 break;
77149 }
77150
77151
77152 /* Opcode: Noop * * * * *
@@ -77174,31 +77322,31 @@
77174 }
77175
77176 #ifdef VDBE_PROFILE
77177 {
77178 u64 endTime = sqlite3Hwtime();
77179 if( endTime>start ) pOp->cycles += endTime - start;
77180 pOp->cnt++;
77181 }
77182 #endif
77183
77184 /* The following code adds nothing to the actual functionality
77185 ** of the program. It is only here for testing and debugging.
77186 ** On the other hand, it does burn CPU cycles every time through
77187 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
77188 */
77189 #ifndef NDEBUG
77190 assert( pc>=-1 && pc<p->nOp );
77191
77192 #ifdef SQLITE_DEBUG
77193 if( db->flags & SQLITE_VdbeTrace ){
77194 if( rc!=0 ) printf("rc=%d\n",rc);
77195 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
77196 registerTrace(pOp->p2, &aMem[pOp->p2]);
77197 }
77198 if( pOp->opflags & OPFLG_OUT3 ){
77199 registerTrace(pOp->p3, &aMem[pOp->p3]);
77200 }
77201 }
77202 #endif /* SQLITE_DEBUG */
77203 #endif /* NDEBUG */
77204 } /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77357,11 @@
77209 vdbe_error_halt:
77210 assert( rc );
77211 p->rc = rc;
77212 testcase( sqlite3GlobalConfig.xLog!=0 );
77213 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77214 pc, p->zSql, p->zErrMsg);
77215 sqlite3VdbeHalt(p);
77216 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
77217 rc = SQLITE_ERROR;
77218 if( resetSchemaOnFault>0 ){
77219 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78183,23 @@
78035 **
78036 ** In both cases, the effects of the main thread seeing (bDone==0) even
78037 ** after the thread has finished are not dire. So we don't worry about
78038 ** memory barriers and such here.
78039 */
 
78040 struct SortSubtask {
78041 SQLiteThread *pThread; /* Background thread, if any */
78042 int bDone; /* Set if thread is finished but not joined */
78043 VdbeSorter *pSorter; /* Sorter that owns this sub-task */
78044 UnpackedRecord *pUnpacked; /* Space to unpack a record */
78045 SorterList list; /* List for thread to write to a PMA */
78046 int nPMA; /* Number of PMAs currently in file */
 
78047 SorterFile file; /* Temp file for level-0 PMAs */
78048 SorterFile file2; /* Space for other PMAs */
78049 };
 
78050
78051 /*
78052 ** Main sorter structure. A single instance of this is allocated for each
78053 ** sorter cursor created by the VDBE.
78054 **
@@ -78072,12 +78223,16 @@
78072 int nMemory; /* Size of list.aMemory allocation in bytes */
78073 u8 bUsePMA; /* True if one or more PMAs created */
78074 u8 bUseThreads; /* True to use background threads */
78075 u8 iPrev; /* Previous thread used to flush PMA */
78076 u8 nTask; /* Size of aTask[] array */
 
78077 SortSubtask aTask[1]; /* One or more subtasks */
78078 };
 
 
 
78079
78080 /*
78081 ** An instance of the following object is used to read records out of a
78082 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
78083 ** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78641,165 @@
78486 rc = vdbePmaReaderNext(pReadr);
78487 }
78488 return rc;
78489 }
78490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78491
78492 /*
78493 ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
78494 ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
78495 ** used by the comparison. Return the result of the comparison.
78496 **
78497 ** Before returning, object (pTask->pUnpacked) is populated with the
78498 ** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it
78499 ** is assumed that the (pTask->pUnpacked) structure already contains the
78500 ** unpacked key to use as key2.
78501 **
78502 ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
78503 ** to SQLITE_NOMEM.
78504 */
78505 static int vdbeSorterCompare(
78506 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
 
78507 const void *pKey1, int nKey1, /* Left side of comparison */
78508 const void *pKey2, int nKey2 /* Right side of comparison */
78509 ){
78510 UnpackedRecord *r2 = pTask->pUnpacked;
78511 if( pKey2 ){
78512 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
 
78513 }
78514 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
78515 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78516
78517 /*
78518 ** Initialize the temporary index cursor just opened as a sorter cursor.
78519 **
78520 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78864,17 @@
78579 rc = SQLITE_NOMEM;
78580 }else{
78581 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
78582 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
78583 pKeyInfo->db = 0;
78584 if( nField && nWorker==0 ) pKeyInfo->nField = nField;
 
 
 
78585 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
78586 pSorter->nTask = nWorker + 1;
 
78587 pSorter->bUseThreads = (pSorter->nTask>1);
78588 pSorter->db = db;
78589 for(i=0; i<pSorter->nTask; i++){
78590 SortSubtask *pTask = &pSorter->aTask[i];
78591 pTask->pSorter = pSorter;
@@ -78607,10 +78896,16 @@
78607 pSorter->nMemory = pgsz;
78608 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
78609 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
78610 }
78611 }
 
 
 
 
 
 
78612 }
78613
78614 return rc;
78615 }
78616 #undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78926,28 @@
78631 ** Free all resources owned by the object indicated by argument pTask. All
78632 ** fields of *pTask are zeroed before returning.
78633 */
78634 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
78635 sqlite3DbFree(db, pTask->pUnpacked);
78636 pTask->pUnpacked = 0;
78637 #if SQLITE_MAX_WORKER_THREADS>0
78638 /* pTask->list.aMemory can only be non-zero if it was handed memory
78639 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
78640 if( pTask->list.aMemory ){
78641 sqlite3_free(pTask->list.aMemory);
78642 pTask->list.aMemory = 0;
78643 }else
78644 #endif
78645 {
78646 assert( pTask->list.aMemory==0 );
78647 vdbeSorterRecordFree(0, pTask->list.pList);
78648 }
78649 pTask->list.pList = 0;
78650 if( pTask->file.pFd ){
78651 sqlite3OsCloseFree(pTask->file.pFd);
78652 pTask->file.pFd = 0;
78653 pTask->file.iEof = 0;
78654 }
78655 if( pTask->file2.pFd ){
78656 sqlite3OsCloseFree(pTask->file2.pFd);
78657 pTask->file2.pFd = 0;
78658 pTask->file2.iEof = 0;
78659 }
 
78660 }
78661
78662 #ifdef SQLITE_DEBUG_SORTER_THREADS
78663 static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
78664 i64 t;
@@ -78834,10 +79123,11 @@
78834 vdbeMergeEngineFree(pSorter->pMerger);
78835 pSorter->pMerger = 0;
78836 for(i=0; i<pSorter->nTask; i++){
78837 SortSubtask *pTask = &pSorter->aTask[i];
78838 vdbeSortSubtaskCleanup(db, pTask);
 
78839 }
78840 if( pSorter->list.aMemory==0 ){
78841 vdbeSorterRecordFree(0, pSorter->list.pList);
78842 }
78843 pSorter->list.pList = 0;
@@ -78943,31 +79233,45 @@
78943 SorterRecord *p2, /* Second list to merge */
78944 SorterRecord **ppOut /* OUT: Head of merged list */
78945 ){
78946 SorterRecord *pFinal = 0;
78947 SorterRecord **pp = &pFinal;
78948 void *pVal2 = p2 ? SRVAL(p2) : 0;
78949
78950 while( p1 && p2 ){
78951 int res;
78952 res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal);
 
 
 
78953 if( res<=0 ){
78954 *pp = p1;
78955 pp = &p1->u.pNext;
78956 p1 = p1->u.pNext;
78957 pVal2 = 0;
78958 }else{
78959 *pp = p2;
78960 pp = &p2->u.pNext;
78961 p2 = p2->u.pNext;
78962 if( p2==0 ) break;
78963 pVal2 = SRVAL(p2);
78964 }
78965 }
78966 *pp = p1 ? p1 : p2;
78967 *ppOut = pFinal;
78968 }
 
 
 
 
 
 
 
 
 
 
 
 
 
78969
78970 /*
78971 ** Sort the linked list of records headed at pTask->pList. Return
78972 ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
78973 ** an error occurs.
@@ -78979,16 +79283,18 @@
78979 int rc;
78980
78981 rc = vdbeSortAllocUnpacked(pTask);
78982 if( rc!=SQLITE_OK ) return rc;
78983
 
 
 
78984 aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
78985 if( !aSlot ){
78986 return SQLITE_NOMEM;
78987 }
78988
78989 p = pList->pList;
78990 while( p ){
78991 SorterRecord *pNext;
78992 if( pList->aMemory ){
78993 if( (u8*)p==pList->aMemory ){
78994 pNext = 0;
@@ -79198,28 +79504,27 @@
79198 /* Update contents of aTree[] */
79199 if( rc==SQLITE_OK ){
79200 int i; /* Index of aTree[] to recalculate */
79201 PmaReader *pReadr1; /* First PmaReader to compare */
79202 PmaReader *pReadr2; /* Second PmaReader to compare */
79203 u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */
79204
79205 /* Find the first two PmaReaders to compare. The one that was just
79206 ** advanced (iPrev) and the one next to it in the array. */
79207 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
79208 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
79209 pKey2 = pReadr2->aKey;
79210
79211 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
79212 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
79213 int iRes;
79214 if( pReadr1->pFd==0 ){
79215 iRes = +1;
79216 }else if( pReadr2->pFd==0 ){
79217 iRes = -1;
79218 }else{
79219 iRes = vdbeSorterCompare(pTask,
79220 pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey
79221 );
79222 }
79223
79224 /* If pReadr1 contained the smaller value, set aTree[i] to its index.
79225 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79542,13 @@
79237 ** is sorted from oldest to newest, so pReadr1 contains older values
79238 ** than pReadr2 iff (pReadr1<pReadr2). */
79239 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
79240 pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
79241 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79242 pKey2 = pReadr2->aKey;
79243 }else{
79244 if( pReadr1->pFd ) pKey2 = 0;
79245 pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
79246 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79247 }
79248 }
79249 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79651,20 @@
79346 SorterRecord *pNew; /* New list element */
79347
79348 int bFlush; /* True to flush contents of memory to PMA */
79349 int nReq; /* Bytes of memory required */
79350 int nPMA; /* Bytes of PMA space required */
 
 
 
 
 
 
 
 
 
 
79351
79352 assert( pSorter );
79353
79354 /* Figure out whether or not the current contents of memory should be
79355 ** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79926,16 @@
79611 if( p1->pFd==0 ){
79612 iRes = i2;
79613 }else if( p2->pFd==0 ){
79614 iRes = i1;
79615 }else{
 
 
79616 int res;
79617 assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79618 res = vdbeSorterCompare(
79619 pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79620 );
79621 if( res<=0 ){
79622 iRes = i1;
79623 }else{
79624 iRes = i2;
@@ -79638,15 +79955,16 @@
79638 */
79639 #define INCRINIT_NORMAL 0
79640 #define INCRINIT_TASK 1
79641 #define INCRINIT_ROOT 2
79642
79643 /* Forward reference.
79644 ** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each
79645 ** other (when building a merge tree).
 
79646 */
79647 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode);
79648
79649 /*
79650 ** Initialize the MergeEngine object passed as the second argument. Once this
79651 ** function returns, the first key of merged data may be read from the
79652 ** MergeEngine object in the usual fashion.
@@ -79689,11 +80007,11 @@
79689 ** the main thread to fill its buffer. So calling PmaReaderNext()
79690 ** on this PmaReader before any of the multi-threaded PmaReaders takes
79691 ** better advantage of multi-processor hardware. */
79692 rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
79693 }else{
79694 rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
79695 }
79696 if( rc!=SQLITE_OK ) return rc;
79697 }
79698
79699 for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80019,19 @@
79701 }
79702 return pTask->pUnpacked->errCode;
79703 }
79704
79705 /*
79706 ** Initialize the IncrMerge field of a PmaReader.
79707 **
79708 ** If the PmaReader passed as the first argument is not an incremental-reader
79709 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves
79710 ** to open and/or initialize the temp file related fields of the IncrMerge
79711 ** object at (pReadr->pIncr).
79712 **
79713 ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
79714 ** in the sub-tree headed by pReadr are also initialized. Data is then loaded
79715 ** into the buffers belonging to pReadr and it is set to
79716 ** point to the first key in its range.
79717 **
79718 ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
79719 ** to be a multi-threaded PmaReader and this function is being called in a
79720 ** background thread. In this case all PmaReaders in the sub-tree are
79721 ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80054,112 @@
79738 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
79739 */
79740 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
79741 int rc = SQLITE_OK;
79742 IncrMerger *pIncr = pReadr->pIncr;
 
 
79743
79744 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
79745 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
79746
79747 if( pIncr ){
79748 SortSubtask *pTask = pIncr->pTask;
79749 sqlite3 *db = pTask->pSorter->db;
79750
79751 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
79752
79753 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
79754 ** requires two temp files to itself, whereas a single-threaded object
79755 ** only requires a region of pTask->file2. */
79756 if( rc==SQLITE_OK ){
79757 int mxSz = pIncr->mxSz;
79758 #if SQLITE_MAX_WORKER_THREADS>0
79759 if( pIncr->bUseThread ){
79760 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
79761 if( rc==SQLITE_OK ){
79762 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
79763 }
79764 }else
79765 #endif
79766 /*if( !pIncr->bUseThread )*/{
79767 if( pTask->file2.pFd==0 ){
79768 assert( pTask->file2.iEof>0 );
79769 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
79770 pTask->file2.iEof = 0;
79771 }
79772 if( rc==SQLITE_OK ){
79773 pIncr->aFile[1].pFd = pTask->file2.pFd;
79774 pIncr->iStartOff = pTask->file2.iEof;
79775 pTask->file2.iEof += mxSz;
79776 }
79777 }
79778 }
79779
79780 #if SQLITE_MAX_WORKER_THREADS>0
79781 if( rc==SQLITE_OK && pIncr->bUseThread ){
79782 /* Use the current thread to populate aFile[1], even though this
79783 ** PmaReader is multi-threaded. The reason being that this function
79784 ** is already running in background thread pIncr->pTask->thread. */
79785 assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
79786 rc = vdbeIncrPopulate(pIncr);
79787 }
79788 #endif
79789
79790 if( rc==SQLITE_OK
79791 && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK)
79792 ){
79793 rc = vdbePmaReaderNext(pReadr);
79794 }
79795 }
 
79796 return rc;
79797 }
79798
79799 #if SQLITE_MAX_WORKER_THREADS>0
79800 /*
79801 ** The main routine for vdbePmaReaderIncrMergeInit() operations run in
79802 ** background threads.
79803 */
79804 static void *vdbePmaReaderBgInit(void *pCtx){
79805 PmaReader *pReader = (PmaReader*)pCtx;
79806 void *pRet = SQLITE_INT_TO_PTR(
79807 vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
79808 );
79809 pReader->pIncr->pTask->bDone = 1;
79810 return pRet;
79811 }
 
79812
79813 /*
79814 ** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
79815 ** on the PmaReader object passed as the first argument.
79816 **
79817 ** This call will initialize the various fields of the pReadr->pIncr
79818 ** structure and, if it is a multi-threaded IncrMerger, launch a
79819 ** background thread to populate aFile[1].
 
 
 
79820 */
79821 static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){
79822 void *pCtx = (void*)pReadr;
79823 return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx);
 
 
 
 
 
 
 
 
 
 
 
 
 
79824 }
79825 #endif
79826
79827 /*
79828 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
79829 ** PMAs from pTask->file. If no error occurs, set *ppOut to point to
79830 ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80367,15 @@
80032 int rc; /* Return code */
80033 SortSubtask *pTask0 = &pSorter->aTask[0];
80034 MergeEngine *pMain = 0;
80035 #if SQLITE_MAX_WORKER_THREADS
80036 sqlite3 *db = pTask0->pSorter->db;
 
 
 
 
 
80037 #endif
80038
80039 rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
80040 if( rc==SQLITE_OK ){
80041 #if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80400,25 @@
80060 vdbeIncrMergerSetThreads(pIncr);
80061 assert( pIncr->pTask!=pLast );
80062 }
80063 }
80064 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
 
 
 
 
 
 
 
 
 
80065 PmaReader *p = &pMain->aReadr[iTask];
80066 assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
80067 if( p->pIncr ){
80068 if( iTask==pSorter->nTask-1 ){
80069 rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK);
80070 }else{
80071 rc = vdbePmaReaderBgIncrInit(p);
80072 }
80073 }
80074 }
80075 }
80076 pMain = 0;
80077 }
80078 if( rc==SQLITE_OK ){
@@ -81023,11 +81369,11 @@
81023 ** Should be transformed into:
81024 **
81025 ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
81026 **
81027 ** The nSubquery parameter specifies how many levels of subquery the
81028 ** alias is removed from the original expression. The usually value is
81029 ** zero but it might be more if the alias is contained within a subquery
81030 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
81031 ** structures must be increased by the nSubquery amount.
81032 */
81033 static void resolveAlias(
@@ -81043,11 +81389,10 @@
81043 sqlite3 *db; /* The database connection */
81044
81045 assert( iCol>=0 && iCol<pEList->nExpr );
81046 pOrig = pEList->a[iCol].pExpr;
81047 assert( pOrig!=0 );
81048 assert( pOrig->flags & EP_Resolved );
81049 db = pParse->db;
81050 pDup = sqlite3ExprDup(db, pOrig, 0);
81051 if( pDup==0 ) return;
81052 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
81053 incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82282,15 @@
81937 pNew->flags |= EP_IntValue;
81938 pNew->u.iValue = iCol;
81939 if( pItem->pExpr==pE ){
81940 pItem->pExpr = pNew;
81941 }else{
81942 assert( pItem->pExpr->op==TK_COLLATE );
81943 assert( pItem->pExpr->pLeft==pE );
81944 pItem->pExpr->pLeft = pNew;
 
 
81945 }
81946 sqlite3ExprDelete(db, pE);
81947 pItem->u.x.iOrderByCol = (u16)iCol;
81948 pItem->done = 1;
81949 }else{
@@ -82139,11 +82486,11 @@
82139 ** as if it were part of the sub-query, not the parent. This block
82140 ** moves the pOrderBy down to the sub-query. It will be moved back
82141 ** after the names have been resolved. */
82142 if( p->selFlags & SF_Converted ){
82143 Select *pSub = p->pSrc->a[0].pSelect;
82144 assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82145 assert( pSub->pPrior && pSub->pOrderBy==0 );
82146 pSub->pOrderBy = p->pOrderBy;
82147 p->pOrderBy = 0;
82148 }
82149
@@ -82241,12 +82588,19 @@
82241
82242 /* Process the ORDER BY clause for singleton SELECT statements.
82243 ** The ORDER BY clause for compounds SELECT statements is handled
82244 ** below, after all of the result-sets for all of the elements of
82245 ** the compound have been resolved.
 
 
 
 
 
82246 */
82247 if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){
 
 
82248 return WRC_Abort;
82249 }
82250 if( db->mallocFailed ){
82251 return WRC_Abort;
82252 }
@@ -83694,11 +84048,12 @@
83694 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
83695 int i;
83696 u32 m = 0;
83697 if( pList ){
83698 for(i=0; i<pList->nExpr; i++){
83699 m |= pList->a[i].pExpr->flags;
 
83700 }
83701 }
83702 return m;
83703 }
83704
@@ -84134,11 +84489,11 @@
84134 /* Check to see if an existing table or index can be used to
84135 ** satisfy the query. This is preferable to generating a new
84136 ** ephemeral table.
84137 */
84138 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84139 if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
84140 sqlite3 *db = pParse->db; /* Database connection */
84141 Table *pTab; /* Table <table>. */
84142 Expr *pExpr; /* Expression <column> */
84143 i16 iCol; /* Index of column <column> */
84144 i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84814,11 @@
84459 }
84460 sqlite3ExprDelete(pParse->db, pSel->pLimit);
84461 pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
84462 &sqlite3IntTokens[1]);
84463 pSel->iLimit = 0;
 
84464 if( sqlite3Select(pParse, pSel, &dest) ){
84465 return 0;
84466 }
84467 rReg = dest.iSDParm;
84468 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86180,11 @@
85824 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
85825 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
85826 break;
85827 }
85828 case TK_ID: {
85829 sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
85830 break;
85831 }
85832 #ifndef SQLITE_OMIT_CAST
85833 case TK_CAST: {
85834 /* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86815,11 @@
86459 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
86460 if( combinedFlags & EP_xIsSelect ) return 2;
86461 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
86462 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
86463 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86464 if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
86465 if( pA->iColumn!=pB->iColumn ) return 2;
86466 if( pA->iTable!=pB->iTable
86467 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
86468 }
86469 }
@@ -86991,10 +87347,11 @@
86991 do {
86992 z += n;
86993 n = sqlite3GetToken(z, &token);
86994 }while( token==TK_SPACE );
86995
 
86996 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
86997 if( zParent==0 ) break;
86998 sqlite3Dequote(zParent);
86999 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
87000 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89574,21 @@
89217 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
89218 }
89219 z = argv[2];
89220
89221 if( pIndex ){
 
89222 int nCol = pIndex->nKeyCol+1;
89223 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89224 tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
89225 sizeof(tRowcnt) * nCol
89226 );
89227 if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89228 #else
89229 tRowcnt * const aiRowEst = 0;
 
 
89230 #endif
89231 pIndex->bUnordered = 0;
89232 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
89233 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
89234 }else{
@@ -89887,11 +90247,11 @@
89887 }
89888
89889 sqlite3BtreeClose(pDb->pBt);
89890 pDb->pBt = 0;
89891 pDb->pSchema = 0;
89892 sqlite3ResetAllSchemasOfConnection(db);
89893 return;
89894
89895 detach_error:
89896 sqlite3_result_error(context, zErr, -1);
89897 }
@@ -89921,11 +90281,10 @@
89921 if(
89922 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
89923 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
89924 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
89925 ){
89926 pParse->nErr++;
89927 goto attach_end;
89928 }
89929
89930 #ifndef SQLITE_OMIT_AUTHORIZATION
89931 if( pAuthArg ){
@@ -90580,13 +90939,15 @@
90580 sqlite3 *db;
90581 Vdbe *v;
90582
90583 assert( pParse->pToplevel==0 );
90584 db = pParse->db;
90585 if( db->mallocFailed ) return;
90586 if( pParse->nested ) return;
90587 if( pParse->nErr ) return;
 
 
 
90588
90589 /* Begin by generating some termination code at the end of the
90590 ** vdbe program
90591 */
90592 v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91025,11 @@
90664 }
90665
90666
90667 /* Get the VDBE program ready for execution
90668 */
90669 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
90670 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
90671 /* A minimum of one cursor is required if autoincrement is used
90672 * See ticket [a696379c1f08866] */
90673 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
90674 sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91560,16 @@
91199 sqlite3 *db = pParse->db;
91200
91201 if( ALWAYS(pName2!=0) && pName2->n>0 ){
91202 if( db->init.busy ) {
91203 sqlite3ErrorMsg(pParse, "corrupt database");
91204 pParse->nErr++;
91205 return -1;
91206 }
91207 *pUnqual = pName2;
91208 iDb = sqlite3FindDb(db, pName1);
91209 if( iDb<0 ){
91210 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
91211 pParse->nErr++;
91212 return -1;
91213 }
91214 }else{
91215 assert( db->init.iDb==0 || db->init.busy );
91216 iDb = db->init.iDb;
@@ -91365,11 +91724,11 @@
91365 pTable = sqlite3FindTable(db, zName, zDb);
91366 if( pTable ){
91367 if( !noErr ){
91368 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
91369 }else{
91370 assert( !db->init.busy );
91371 sqlite3CodeVerifySchema(pParse, iDb);
91372 }
91373 goto begin_table_error;
91374 }
91375 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92013,12 @@
91654 Column *pCol;
91655
91656 p = pParse->pNewTable;
91657 if( p==0 || NEVER(p->nCol<1) ) return;
91658 pCol = &p->aCol[p->nCol-1];
91659 assert( pCol->zType==0 );
 
91660 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
91661 pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
91662 }
91663
91664 /*
@@ -92888,10 +93248,11 @@
92888 if( db->mallocFailed ){
92889 goto exit_drop_table;
92890 }
92891 assert( pParse->nErr==0 );
92892 assert( pName->nSrc==1 );
 
92893 if( noErr ) db->suppressErr++;
92894 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
92895 if( noErr ) db->suppressErr--;
92896
92897 if( pTab==0 ){
@@ -93201,11 +93562,12 @@
93201 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
93202 }else{
93203 addr2 = sqlite3VdbeCurrentAddr(v);
93204 }
93205 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93206 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
 
93207 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
93208 sqlite3ReleaseTempReg(pParse, regRecord);
93209 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
93210 sqlite3VdbeJumpHere(v, addr1);
93211
@@ -93294,12 +93656,11 @@
93294 int nExtra = 0; /* Space allocated for zExtra[] */
93295 int nExtraCol; /* Number of extra columns needed */
93296 char *zExtra = 0; /* Extra space after the Index object */
93297 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
93298
93299 assert( pParse->nErr==0 ); /* Never called with prior errors */
93300 if( db->mallocFailed || IN_DECLARE_VTAB ){
93301 goto exit_create_index;
93302 }
93303 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
93304 goto exit_create_index;
93305 }
@@ -94214,11 +94575,10 @@
94214 ** operator with A. This routine shifts that operator over to B.
94215 */
94216 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
94217 if( p ){
94218 int i;
94219 assert( p->a || p->nSrc==0 );
94220 for(i=p->nSrc-1; i>0; i--){
94221 p->a[i].jointype = p->a[i-1].jointype;
94222 }
94223 p->a[0].jointype = 0;
94224 }
@@ -94461,12 +94821,11 @@
94461 char *zErr;
94462 int j;
94463 StrAccum errMsg;
94464 Table *pTab = pIdx->pTable;
94465
94466 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
94467 errMsg.db = pParse->db;
94468 for(j=0; j<pIdx->nKeyCol; j++){
94469 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
94470 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
94471 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
94472 sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96650,17 @@
96291 ){
96292 PrintfArguments x;
96293 StrAccum str;
96294 const char *zFormat;
96295 int n;
 
96296
96297 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
96298 x.nArg = argc-1;
96299 x.nUsed = 0;
96300 x.apArg = argv+1;
96301 sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
96302 str.db = sqlite3_context_db_handle(context);
96303 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
96304 n = str.nChar;
96305 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
96306 SQLITE_DYNAMIC);
96307 }
@@ -96447,11 +96806,11 @@
96447 sqlite3_result_double(context, r);
96448 }
96449 #endif
96450
96451 /*
96452 ** Allocate nByte bytes of space using sqlite3_malloc(). If the
96453 ** allocation fails, call sqlite3_result_error_nomem() to notify
96454 ** the database handle that malloc() has failed and return NULL.
96455 ** If nByte is larger than the maximum string or blob length, then
96456 ** raise an SQLITE_TOOBIG exception and return NULL.
96457 */
@@ -97116,11 +97475,11 @@
97116 int argc,
97117 sqlite3_value **argv
97118 ){
97119 unsigned char *z, *zOut;
97120 int i;
97121 zOut = z = sqlite3_malloc( argc*4+1 );
97122 if( z==0 ){
97123 sqlite3_result_error_nomem(context);
97124 return;
97125 }
97126 for(i=0; i<argc; i++){
@@ -97264,11 +97623,11 @@
97264 sqlite3_result_error_toobig(context);
97265 sqlite3_free(zOut);
97266 return;
97267 }
97268 zOld = zOut;
97269 zOut = sqlite3_realloc(zOut, (int)nOut);
97270 if( zOut==0 ){
97271 sqlite3_result_error_nomem(context);
97272 sqlite3_free(zOld);
97273 return;
97274 }
@@ -97626,12 +97985,11 @@
97626 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
97627 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
97628
97629 if( pAccum ){
97630 sqlite3 *db = sqlite3_context_db_handle(context);
97631 int firstTerm = pAccum->useMalloc==0;
97632 pAccum->useMalloc = 2;
97633 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
97634 if( !firstTerm ){
97635 if( argc==2 ){
97636 zSep = (char*)sqlite3_value_text(argv[1]);
97637 nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99405,12 @@
99047 int iFromCol; /* Idx of column in child table */
99048 Expr *pEq; /* tFromCol = OLD.tToCol */
99049
99050 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
99051 assert( iFromCol>=0 );
99052 tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid";
 
99053 tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
99054
99055 tToCol.n = sqlite3Strlen30(tToCol.z);
99056 tFromCol.n = sqlite3Strlen30(tFromCol.z);
99057
@@ -99059,14 +99418,14 @@
99059 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
99060 ** that the affinity and collation sequence associated with the
99061 ** parent table are used for the comparison. */
99062 pEq = sqlite3PExpr(pParse, TK_EQ,
99063 sqlite3PExpr(pParse, TK_DOT,
99064 sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99065 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99066 , 0),
99067 sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol)
99068 , 0);
99069 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
99070
99071 /* For ON UPDATE, construct the next term of the WHEN clause.
99072 ** The final WHEN clause will be like this:
@@ -99074,27 +99433,27 @@
99074 ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
99075 */
99076 if( pChanges ){
99077 pEq = sqlite3PExpr(pParse, TK_IS,
99078 sqlite3PExpr(pParse, TK_DOT,
99079 sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99080 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99081 0),
99082 sqlite3PExpr(pParse, TK_DOT,
99083 sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99084 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99085 0),
99086 0);
99087 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
99088 }
99089
99090 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
99091 Expr *pNew;
99092 if( action==OE_Cascade ){
99093 pNew = sqlite3PExpr(pParse, TK_DOT,
99094 sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99095 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99096 , 0);
99097 }else if( action==OE_SetDflt ){
99098 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
99099 if( pDflt ){
99100 pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99496,16 @@
99137 db->lookaside.bEnabled = 0;
99138
99139 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
99140 sizeof(Trigger) + /* struct Trigger */
99141 sizeof(TriggerStep) + /* Single step in trigger program */
99142 nFrom + 1 /* Space for pStep->target.z */
99143 );
99144 if( pTrigger ){
99145 pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99146 pStep->target.z = (char *)&pStep[1];
99147 pStep->target.n = nFrom;
99148 memcpy((char *)pStep->target.z, zFrom, nFrom);
99149
99150 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99151 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
99152 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99153 if( pWhen ){
@@ -99608,24 +99966,27 @@
99608 );
99609
99610 /*
99611 ** This routine is called to handle SQL of the following forms:
99612 **
99613 ** insert into TABLE (IDLIST) values(EXPRLIST)
99614 ** insert into TABLE (IDLIST) select
 
99615 **
99616 ** The IDLIST following the table name is always optional. If omitted,
99617 ** then a list of all columns for the table is substituted. The IDLIST
99618 ** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
 
99619 **
99620 ** The pList parameter holds EXPRLIST in the first form of the INSERT
99621 ** statement above, and pSelect is NULL. For the second form, pList is
99622 ** NULL and pSelect is a pointer to the select statement used to generate
99623 ** data for the insert.
 
99624 **
99625 ** The code generated follows one of four templates. For a simple
99626 ** insert with data coming from a VALUES clause, the code executes
99627 ** once straight down through. Pseudo-code follows (we call this
99628 ** the "1st template"):
99629 **
99630 ** open write cursor to <table> and its indices
99631 ** put VALUES clause expressions into registers
@@ -99728,11 +100089,11 @@
99728 int iDb; /* Index of database holding TABLE */
99729 Db *pDb; /* The database containing table being inserted into */
99730 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
99731 u8 appendFlag = 0; /* True if the insert is likely to be an append */
99732 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
99733 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
99734 ExprList *pList = 0; /* List of VALUES() to be inserted */
99735
99736 /* Register allocations */
99737 int regFromSelect = 0;/* Base register for data coming from SELECT */
99738 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100114,12 @@
99753 if( pParse->nErr || db->mallocFailed ){
99754 goto insert_cleanup;
99755 }
99756
99757 /* If the Select object is really just a simple VALUES() list with a
99758 ** single row values (the common case) then keep that one row of values
99759 ** and go ahead and discard the Select object
99760 */
99761 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
99762 pList = pSelect->pEList;
99763 pSelect->pEList = 0;
99764 sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100223,11 @@
99862 ** the index into IDLIST of the primary key column. ipkColumn is
99863 ** the index of the primary key as it appears in IDLIST, not as
99864 ** is appears in the original table. (The index of the INTEGER
99865 ** PRIMARY KEY in the original table is pTab->iPKey.)
99866 */
 
99867 if( pColumn ){
99868 for(i=0; i<pColumn->nId; i++){
99869 pColumn->a[i].idx = -1;
99870 }
99871 for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100259,12 @@
99897 ** is coming from a SELECT statement, then generate a co-routine that
99898 ** produces a single row of the SELECT on each invocation. The
99899 ** co-routine is the common header to the 3rd and 4th templates.
99900 */
99901 if( pSelect ){
99902 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
 
99903 int regYield; /* Register holding co-routine entry-point */
99904 int addrTop; /* Top of the co-routine */
99905 int rc; /* Result code */
99906
99907 regYield = ++pParse->nMem;
@@ -99910,12 +100273,11 @@
99910 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
99911 dest.iSdst = bIdListInOrder ? regData : 0;
99912 dest.nSdst = pTab->nCol;
99913 rc = sqlite3Select(pParse, pSelect, &dest);
99914 regFromSelect = dest.iSdst;
99915 assert( pParse->nErr==0 || rc );
99916 if( rc || db->mallocFailed ) goto insert_cleanup;
99917 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
99918 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
99919 assert( pSelect->pEList );
99920 nColumn = pSelect->pEList->nExpr;
99921
@@ -99959,12 +100321,12 @@
99959 sqlite3VdbeJumpHere(v, addrL);
99960 sqlite3ReleaseTempReg(pParse, regRec);
99961 sqlite3ReleaseTempReg(pParse, regTempRowid);
99962 }
99963 }else{
99964 /* This is the case if the data for the INSERT is coming from a VALUES
99965 ** clause
99966 */
99967 NameContext sNC;
99968 memset(&sNC, 0, sizeof(sNC));
99969 sNC.pParse = pParse;
99970 srcTab = -1;
@@ -101031,10 +101393,11 @@
101031 Table *pDest, /* The table we are inserting into */
101032 Select *pSelect, /* A SELECT statement to use as the data source */
101033 int onError, /* How to handle constraint errors */
101034 int iDbDest /* The database of pDest */
101035 ){
 
101036 ExprList *pEList; /* The result set of the SELECT */
101037 Table *pSrc; /* The table in the FROM clause of SELECT */
101038 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101039 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101040 int i; /* Loop counter */
@@ -101178,15 +101541,15 @@
101178 ** But the main beneficiary of the transfer optimization is the VACUUM
101179 ** command, and the VACUUM command disables foreign key constraints. So
101180 ** the extra complication to make this rule less restrictive is probably
101181 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101182 */
101183 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101184 return 0;
101185 }
101186 #endif
101187 if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
101188 return 0; /* xfer opt does not play well with PRAGMA count_changes */
101189 }
101190
101191 /* If we get this far, it means that the xfer optimization is at
101192 ** least a possibility, though it might only work if the destination
@@ -101193,28 +101556,32 @@
101193 ** table (tab1) is initially empty.
101194 */
101195 #ifdef SQLITE_TEST
101196 sqlite3_xferopt_count++;
101197 #endif
101198 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
101199 v = sqlite3GetVdbe(pParse);
101200 sqlite3CodeVerifySchema(pParse, iDbSrc);
101201 iSrc = pParse->nTab++;
101202 iDest = pParse->nTab++;
101203 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101204 regData = sqlite3GetTempReg(pParse);
101205 regRowid = sqlite3GetTempReg(pParse);
101206 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101207 assert( HasRowid(pDest) || destHasUniqueIdx );
101208 if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
 
101209 || destHasUniqueIdx /* (2) */
101210 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101211 ){
101212 /* In some circumstances, we are able to run the xfer optimization
101213 ** only if the destination table is initially empty. This code makes
101214 ** that determination. Conditions under which the destination must
101215 ** be empty:
 
 
 
101216 **
101217 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
101218 ** (If the destination is not initially empty, the rowid fields
101219 ** of index entries might need to change.)
101220 **
@@ -101253,10 +101620,11 @@
101253 }else{
101254 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101255 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101256 }
101257 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
 
101258 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101259 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101260 }
101261 assert( pSrcIdx );
101262 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101634,37 @@
101266 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101267 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101268 VdbeComment((v, "%s", pDestIdx->zName));
101269 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101270 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101271 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
 
101272 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101273 sqlite3VdbeJumpHere(v, addr1);
101274 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101275 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101276 }
@@ -102385,11 +102779,11 @@
102385 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102386 char *zErrmsg = 0;
102387 const char *zEntry;
102388 char *zAltEntry = 0;
102389 void **aHandle;
102390 int nMsg = 300 + sqlite3Strlen30(zFile);
102391 int ii;
102392
102393 /* Shared library endings to try if zFile cannot be loaded as written */
102394 static const char *azEndings[] = {
102395 #if SQLITE_OS_WIN
@@ -102428,11 +102822,11 @@
102428 sqlite3_free(zAltFile);
102429 }
102430 #endif
102431 if( handle==0 ){
102432 if( pzErrMsg ){
102433 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102434 if( zErrmsg ){
102435 sqlite3_snprintf(nMsg, zErrmsg,
102436 "unable to open shared library [%s]", zFile);
102437 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102438 }
@@ -102454,11 +102848,11 @@
102454 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102455 */
102456 if( xInit==0 && zProc==0 ){
102457 int iFile, iEntry, c;
102458 int ncFile = sqlite3Strlen30(zFile);
102459 zAltEntry = sqlite3_malloc(ncFile+30);
102460 if( zAltEntry==0 ){
102461 sqlite3OsDlClose(pVfs, handle);
102462 return SQLITE_NOMEM;
102463 }
102464 memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102870,11 @@
102476 sqlite3OsDlSym(pVfs, handle, zEntry);
102477 }
102478 if( xInit==0 ){
102479 if( pzErrMsg ){
102480 nMsg += sqlite3Strlen30(zEntry);
102481 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102482 if( zErrmsg ){
102483 sqlite3_snprintf(nMsg, zErrmsg,
102484 "no entry point [%s] in shared library [%s]", zEntry, zFile);
102485 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102486 }
@@ -102575,11 +102969,11 @@
102575 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102576 ** mutex must be held while accessing this list.
102577 */
102578 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102579 static SQLITE_WSD struct sqlite3AutoExtList {
102580 int nExt; /* Number of entries in aExt[] */
102581 void (**aExt)(void); /* Pointers to the extension init functions */
102582 } sqlite3Autoext = { 0, 0 };
102583
102584 /* The "wsdAutoext" macro will resolve to the autoextension
102585 ** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103002,23 @@
102608 if( rc ){
102609 return rc;
102610 }else
102611 #endif
102612 {
102613 int i;
102614 #if SQLITE_THREADSAFE
102615 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
102616 #endif
102617 wsdAutoextInit;
102618 sqlite3_mutex_enter(mutex);
102619 for(i=0; i<wsdAutoext.nExt; i++){
102620 if( wsdAutoext.aExt[i]==xInit ) break;
102621 }
102622 if( i==wsdAutoext.nExt ){
102623 int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
102624 void (**aNew)(void);
102625 aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
102626 if( aNew==0 ){
102627 rc = SQLITE_NOMEM;
102628 }else{
102629 wsdAutoext.aExt = aNew;
102630 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103046,11 @@
102652 #endif
102653 int i;
102654 int n = 0;
102655 wsdAutoextInit;
102656 sqlite3_mutex_enter(mutex);
102657 for(i=wsdAutoext.nExt-1; i>=0; i--){
102658 if( wsdAutoext.aExt[i]==xInit ){
102659 wsdAutoext.nExt--;
102660 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
102661 n++;
102662 break;
@@ -102690,11 +103084,11 @@
102690 ** Load all automatic extensions.
102691 **
102692 ** If anything goes wrong, set an error in the database connection.
102693 */
102694 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
102695 int i;
102696 int go = 1;
102697 int rc;
102698 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102699
102700 wsdAutoextInit;
@@ -103354,19 +103748,19 @@
103354 /*
103355 ** Generate code to return a single integer value.
103356 */
103357 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103358 Vdbe *v = sqlite3GetVdbe(pParse);
103359 int mem = ++pParse->nMem;
103360 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103361 if( pI64 ){
103362 memcpy(pI64, &value, sizeof(value));
103363 }
103364 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
103365 sqlite3VdbeSetNumCols(v, 1);
103366 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103367 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103368 }
103369
103370
103371 /*
103372 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103921,15 @@
103527 aFcntl[3] = 0;
103528 db->busyHandler.nBusy = 0;
103529 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103530 if( rc==SQLITE_OK ){
103531 if( aFcntl[0] ){
103532 int mem = ++pParse->nMem;
103533 sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
103534 sqlite3VdbeSetNumCols(v, 1);
103535 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103536 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103537 sqlite3_free(aFcntl[0]);
103538 }
103539 goto pragma_out;
103540 }
103541 if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104530,13 @@
104136 }else{
104137 if( !db->autoCommit ){
104138 sqlite3ErrorMsg(pParse,
104139 "Safety level may not be changed inside a transaction");
104140 }else{
104141 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
 
 
104142 setAllPagerFlags(db);
104143 }
104144 }
104145 break;
104146 }
@@ -104231,11 +104627,11 @@
104231 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104232 k = 0;
104233 }else if( pPk==0 ){
104234 k = 1;
104235 }else{
104236 for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
104237 }
104238 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104239 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104240 }
104241 }
@@ -105237,11 +105633,11 @@
105237
105238 assert( iDb>=0 && iDb<db->nDb );
105239 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105240 if( argv[1]==0 ){
105241 corruptSchema(pData, argv[0], 0);
105242 }else if( argv[2] && argv[2][0] ){
105243 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105244 ** But because db->init.busy is set to 1, no VDBE code is generated
105245 ** or executed. All the parser does is build the internal data
105246 ** structures that describe the table, index, or view.
105247 */
@@ -105268,12 +105664,12 @@
105268 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105269 }
105270 }
105271 }
105272 sqlite3_finalize(pStmt);
105273 }else if( argv[0]==0 ){
105274 corruptSchema(pData, 0, 0);
105275 }else{
105276 /* If the SQL column is blank it means this is an index that
105277 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105278 ** constraint for a CREATE TABLE. The index should have already
105279 ** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106572,10 @@
106176 ){
106177 Select *pNew;
106178 Select standin;
106179 sqlite3 *db = pParse->db;
106180 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
106181 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
106182 if( pNew==0 ){
106183 assert( db->mallocFailed );
106184 pNew = &standin;
106185 memset(pNew, 0, sizeof(*pNew));
106186 }
@@ -106196,11 +106591,11 @@
106196 pNew->pOrderBy = pOrderBy;
106197 pNew->selFlags = selFlags;
106198 pNew->op = TK_SELECT;
106199 pNew->pLimit = pLimit;
106200 pNew->pOffset = pOffset;
106201 assert( pOffset==0 || pLimit!=0 );
106202 pNew->addrOpenEphm[0] = -1;
106203 pNew->addrOpenEphm[1] = -1;
106204 if( db->mallocFailed ) {
106205 clearSelect(db, pNew, pNew!=&standin);
106206 pNew = 0;
@@ -107446,11 +107841,11 @@
107446 if( pS ){
107447 /* The "table" is actually a sub-select or a view in the FROM clause
107448 ** of the SELECT statement. Return the declaration type and origin
107449 ** data for the result-set column of the sub-select.
107450 */
107451 if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
107452 /* If iCol is less than zero, then the expression requests the
107453 ** rowid of the sub-select or view. This expression is legal (see
107454 ** test case misc2.2.2) - it always evaluates to NULL.
107455 */
107456 NameContext sNC;
@@ -107766,16 +108161,18 @@
107766 memset(&sNC, 0, sizeof(sNC));
107767 sNC.pSrcList = pSelect->pSrc;
107768 a = pSelect->pEList->a;
107769 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
107770 p = a[i].pExpr;
107771 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
 
 
107772 szAll += pCol->szEst;
107773 pCol->affinity = sqlite3ExprAffinity(p);
107774 if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
107775 pColl = sqlite3ExprCollSeq(pParse, p);
107776 if( pColl ){
107777 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
107778 }
107779 }
107780 pTab->szTabRow = sqlite3LogEst(szAll*4);
107781 }
@@ -108173,12 +108570,11 @@
108173 ){
108174 Select *pPrior;
108175 int nExpr = p->pEList->nExpr;
108176 int nRow = 1;
108177 int rc = 0;
108178 assert( p->pNext==0 );
108179 assert( p->selFlags & SF_AllValues );
108180 do{
108181 assert( p->selFlags & SF_Values );
108182 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108183 assert( p->pLimit==0 );
108184 assert( p->pOffset==0 );
@@ -108283,11 +108679,11 @@
108283 dest.eDest = SRT_Table;
108284 }
108285
108286 /* Special handling for a compound-select that originates as a VALUES clause.
108287 */
108288 if( p->selFlags & SF_AllValues ){
108289 rc = multiSelectValues(pParse, p, &dest);
108290 goto multi_select_end;
108291 }
108292
108293 /* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109064,11 @@
108668 ** then there should be a single item on the stack. Write this
108669 ** item into the set table with bogus data.
108670 */
108671 case SRT_Set: {
108672 int r1;
108673 assert( pIn->nSdst==1 );
108674 pDest->affSdst =
108675 sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
108676 r1 = sqlite3GetTempReg(pParse);
108677 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
108678 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109090,11 @@
108694 /* If this is a scalar select that is part of an expression, then
108695 ** store the results in the appropriate memory cell and break out
108696 ** of the scan loop.
108697 */
108698 case SRT_Mem: {
108699 assert( pIn->nSdst==1 );
108700 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
108701 /* The LIMIT clause will jump out of the loop for us */
108702 break;
108703 }
108704 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109105,11 @@
108709 case SRT_Coroutine: {
108710 if( pDest->iSdst==0 ){
108711 pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
108712 pDest->nSdst = pIn->nSdst;
108713 }
108714 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
108715 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108716 break;
108717 }
108718
108719 /* If none of the above, then the result destination must be
@@ -108925,12 +109321,14 @@
108925 */
108926 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
108927 if( aPermute ){
108928 struct ExprList_item *pItem;
108929 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
108930 assert( pItem->u.x.iOrderByCol>0
108931 && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
 
 
108932 aPermute[i] = pItem->u.x.iOrderByCol - 1;
108933 }
108934 pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
108935 }else{
108936 pKeyMerge = 0;
@@ -109136,11 +109534,11 @@
109136 pPrior->pNext = p;
109137
109138 /*** TBD: Insert subroutine calls to close cursors on incomplete
109139 **** subqueries ****/
109140 explainComposite(pParse, p->op, iSub1, iSub2, 0);
109141 return SQLITE_OK;
109142 }
109143 #endif
109144
109145 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109146 /* Forward Declarations */
@@ -109948,10 +110346,11 @@
109948 pNew->pGroupBy = 0;
109949 pNew->pHaving = 0;
109950 pNew->pOrderBy = 0;
109951 p->pPrior = 0;
109952 p->pNext = 0;
 
109953 p->selFlags &= ~SF_Compound;
109954 assert( (p->selFlags & SF_Converted)==0 );
109955 p->selFlags |= SF_Converted;
109956 assert( pNew->pPrior!=0 );
109957 pNew->pPrior->pNext = pNew;
@@ -110486,11 +110885,11 @@
110486 if( pParse->hasCompound ){
110487 w.xSelectCallback = convertCompoundSelectToSubquery;
110488 sqlite3WalkSelect(&w, pSelect);
110489 }
110490 w.xSelectCallback = selectExpander;
110491 if( (pSelect->selFlags & SF_AllValues)==0 ){
110492 w.xSelectCallback2 = selectPopWith;
110493 }
110494 sqlite3WalkSelect(&w, pSelect);
110495 }
110496
@@ -110672,11 +111071,12 @@
110672 nArg = 0;
110673 regAgg = 0;
110674 }
110675 if( pF->iDistinct>=0 ){
110676 addrNext = sqlite3VdbeMakeLabel(v);
110677 assert( nArg==1 );
 
110678 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
110679 }
110680 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
110681 CollSeq *pColl = 0;
110682 struct ExprList_item *pItem;
@@ -111547,14 +111947,13 @@
111547
111548 /* Jump here to skip this query
111549 */
111550 sqlite3VdbeResolveLabel(v, iEnd);
111551
111552 /* The SELECT was successfully coded. Set the return code to 0
111553 ** to indicate no errors.
111554 */
111555 rc = 0;
111556
111557 /* Control jumps to here if an error is encountered above, or upon
111558 ** successful coding of the SELECT.
111559 */
111560 select_end:
@@ -111601,11 +112000,11 @@
111601 sqlite3TreeViewLine(pView, "FROM");
111602 for(i=0; i<p->pSrc->nSrc; i++){
111603 struct SrcList_item *pItem = &p->pSrc->a[i];
111604 StrAccum x;
111605 char zLine[100];
111606 sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
111607 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
111608 if( pItem->zDatabase ){
111609 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
111610 }else if( pItem->zName ){
111611 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112159,11 @@
111760 for(i=0; i<nCol; i++){
111761 if( argv[i]==0 ){
111762 z = 0;
111763 }else{
111764 int n = sqlite3Strlen30(argv[i])+1;
111765 z = sqlite3_malloc( n );
111766 if( z==0 ) goto malloc_failed;
111767 memcpy(z, argv[i], n);
111768 }
111769 p->azResult[p->nData++] = z;
111770 }
@@ -111809,11 +112208,11 @@
111809 res.nRow = 0;
111810 res.nColumn = 0;
111811 res.nData = 1;
111812 res.nAlloc = 20;
111813 res.rc = SQLITE_OK;
111814 res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc );
111815 if( res.azResult==0 ){
111816 db->errCode = SQLITE_NOMEM;
111817 return SQLITE_NOMEM;
111818 }
111819 res.azResult[0] = 0;
@@ -111837,11 +112236,11 @@
111837 sqlite3_free_table(&res.azResult[1]);
111838 return rc;
111839 }
111840 if( res.nAlloc>res.nData ){
111841 char **azNew;
111842 azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData );
111843 if( azNew==0 ){
111844 sqlite3_free_table(&res.azResult[1]);
111845 db->errCode = SQLITE_NOMEM;
111846 return SQLITE_NOMEM;
111847 }
@@ -112065,11 +112464,10 @@
112065 }
112066
112067 /* Do not create a trigger on a system table */
112068 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112069 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
112070 pParse->nErr++;
112071 goto trigger_cleanup;
112072 }
112073
112074 /* INSTEAD of triggers are only for views and views only support INSTEAD
112075 ** of triggers.
@@ -112245,16 +112643,16 @@
112245 u8 op, /* Trigger opcode */
112246 Token *pName /* The target name */
112247 ){
112248 TriggerStep *pTriggerStep;
112249
112250 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
112251 if( pTriggerStep ){
112252 char *z = (char*)&pTriggerStep[1];
112253 memcpy(z, pName->z, pName->n);
112254 pTriggerStep->target.z = z;
112255 pTriggerStep->target.n = pName->n;
112256 pTriggerStep->op = op;
112257 }
112258 return pTriggerStep;
112259 }
112260
@@ -112533,11 +112931,11 @@
112533 }
112534 return (mask ? pList : 0);
112535 }
112536
112537 /*
112538 ** Convert the pStep->target token into a SrcList and return a pointer
112539 ** to that SrcList.
112540 **
112541 ** This routine adds a specific database name, if needed, to the target when
112542 ** forming the SrcList. This prevents a trigger in one database from
112543 ** referring to a target in another database. An exception is when the
@@ -112546,21 +112944,21 @@
112546 */
112547 static SrcList *targetSrcList(
112548 Parse *pParse, /* The parsing context */
112549 TriggerStep *pStep /* The trigger containing the target token */
112550 ){
 
112551 int iDb; /* Index of the database to use */
112552 SrcList *pSrc; /* SrcList to be returned */
112553
112554 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
112555 if( pSrc ){
112556 assert( pSrc->nSrc>0 );
112557 assert( pSrc->a!=0 );
112558 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
112559 if( iDb==0 || iDb>=2 ){
112560 sqlite3 *db = pParse->db;
112561 assert( iDb<pParse->db->nDb );
112562 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112563 }
112564 }
112565 return pSrc;
112566 }
@@ -112668,10 +113066,11 @@
112668 assert( pFrom->zErrMsg==0 || pFrom->nErr );
112669 assert( pTo->zErrMsg==0 || pTo->nErr );
112670 if( pTo->nErr==0 ){
112671 pTo->zErrMsg = pFrom->zErrMsg;
112672 pTo->nErr = pFrom->nErr;
 
112673 }else{
112674 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
112675 }
112676 }
112677
@@ -114018,17 +114417,21 @@
114018
114019 /* Loop through the tables in the main database. For each, do
114020 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114021 ** the contents to the temporary database.
114022 */
 
 
114023 rc = execExecSql(db, pzErrMsg,
114024 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114025 "|| ' SELECT * FROM main.' || quote(name) || ';'"
114026 "FROM main.sqlite_master "
114027 "WHERE type = 'table' AND name!='sqlite_sequence' "
114028 " AND coalesce(rootpage,1)>0"
114029 );
 
 
114030 if( rc!=SQLITE_OK ) goto end_of_vacuum;
114031
114032 /* Copy over the sequence table
114033 */
114034 rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114566,12 @@
114163 ** are invoked only from within xCreate and xConnect methods.
114164 */
114165 struct VtabCtx {
114166 VTable *pVTable; /* The virtual table being constructed */
114167 Table *pTab; /* The Table object to which the virtual table belongs */
 
 
114168 };
114169
114170 /*
114171 ** The actual function that does the work of creating a new module.
114172 ** This function implements the sqlite3_create_module() and
@@ -114609,11 +115014,11 @@
114609 Token *pArg = &pParse->sArg;
114610 if( pArg->z==0 ){
114611 pArg->z = p->z;
114612 pArg->n = p->n;
114613 }else{
114614 assert(pArg->z < p->z);
114615 pArg->n = (int)(&p->z[p->n] - pArg->z);
114616 }
114617 }
114618
114619 /*
@@ -114626,19 +115031,31 @@
114626 Table *pTab,
114627 Module *pMod,
114628 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
114629 char **pzErr
114630 ){
114631 VtabCtx sCtx, *pPriorCtx;
114632 VTable *pVTable;
114633 int rc;
114634 const char *const*azArg = (const char *const*)pTab->azModuleArg;
114635 int nArg = pTab->nModuleArg;
114636 char *zErr = 0;
114637 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
114638 int iDb;
 
114639
 
 
 
 
 
 
 
 
 
 
 
114640 if( !zModuleName ){
114641 return SQLITE_NOMEM;
114642 }
114643
114644 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115072,17 @@
114655 /* Invoke the virtual table constructor */
114656 assert( &db->pVtabCtx );
114657 assert( xConstruct );
114658 sCtx.pTab = pTab;
114659 sCtx.pVTable = pVTable;
114660 pPriorCtx = db->pVtabCtx;
 
114661 db->pVtabCtx = &sCtx;
114662 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
114663 db->pVtabCtx = pPriorCtx;
114664 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
 
114665
114666 if( SQLITE_OK!=rc ){
114667 if( zErr==0 ){
114668 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
114669 }else {
@@ -114675,17 +115094,18 @@
114675 /* Justification of ALWAYS(): A correct vtab constructor must allocate
114676 ** the sqlite3_vtab object if successful. */
114677 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
114678 pVTable->pVtab->pModule = pMod->pModule;
114679 pVTable->nRef = 1;
114680 if( sCtx.pTab ){
114681 const char *zFormat = "vtable constructor did not declare schema: %s";
114682 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
114683 sqlite3VtabUnlock(pVTable);
114684 rc = SQLITE_ERROR;
114685 }else{
114686 int iCol;
 
114687 /* If everything went according to plan, link the new VTable structure
114688 ** into the linked list headed by pTab->pVTable. Then loop through the
114689 ** columns of the table to see if any of them contain the token "hidden".
114690 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
114691 ** the type string. */
@@ -114694,11 +115114,14 @@
114694
114695 for(iCol=0; iCol<pTab->nCol; iCol++){
114696 char *zType = pTab->aCol[iCol].zType;
114697 int nType;
114698 int i = 0;
114699 if( !zType ) continue;
 
 
 
114700 nType = sqlite3Strlen30(zType);
114701 if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
114702 for(i=0; i<nType; i++){
114703 if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
114704 && (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115140,13 @@
114717 if( zType[i]=='\0' && i>0 ){
114718 assert(zType[i-1]==' ');
114719 zType[i-1] = '\0';
114720 }
114721 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
 
 
 
114722 }
114723 }
114724 }
114725 }
114726
@@ -114845,12 +115271,12 @@
114845 ** This function is used to set the schema of a virtual table. It is only
114846 ** valid to call this function from within the xCreate() or xConnect() of a
114847 ** virtual table module.
114848 */
114849 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
 
114850 Parse *pParse;
114851
114852 int rc = SQLITE_OK;
114853 Table *pTab;
114854 char *zErr = 0;
114855
114856 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115283,17 @@
114857 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114858 return SQLITE_MISUSE_BKPT;
114859 }
114860 #endif
114861 sqlite3_mutex_enter(db->mutex);
114862 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
 
114863 sqlite3Error(db, SQLITE_MISUSE);
114864 sqlite3_mutex_leave(db->mutex);
114865 return SQLITE_MISUSE_BKPT;
114866 }
 
114867 assert( (pTab->tabFlags & TF_Virtual)!=0 );
114868
114869 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
114870 if( pParse==0 ){
114871 rc = SQLITE_NOMEM;
@@ -114884,11 +115312,11 @@
114884 pTab->aCol = pParse->pNewTable->aCol;
114885 pTab->nCol = pParse->pNewTable->nCol;
114886 pParse->pNewTable->nCol = 0;
114887 pParse->pNewTable->aCol = 0;
114888 }
114889 db->pVtabCtx->pTab = 0;
114890 }else{
114891 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
114892 sqlite3DbFree(db, zErr);
114893 rc = SQLITE_ERROR;
114894 }
@@ -115078,11 +115506,11 @@
115078 */
115079 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115080 int rc = SQLITE_OK;
115081
115082 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115083 assert( iSavepoint>=0 );
115084 if( db->aVTrans ){
115085 int i;
115086 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115087 VTable *pVTab = db->aVTrans[i];
115088 const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115624,11 @@
115196 assert( IsVirtual(pTab) );
115197 for(i=0; i<pToplevel->nVtabLock; i++){
115198 if( pTab==pToplevel->apVtabLock[i] ) return;
115199 }
115200 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115201 apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n);
115202 if( apVtabLock ){
115203 pToplevel->apVtabLock = apVtabLock;
115204 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115205 }else{
115206 pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116423,18 @@
115995 ** In the previous sentence and in the diagram, "slot[]" refers to
115996 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
115997 ** all terms of the WHERE clause.
115998 */
115999 static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
 
116000 pWC->op = op;
116001 if( pExpr==0 ) return;
116002 if( pExpr->op!=op ){
116003 whereClauseInsert(pWC, pExpr, 0);
116004 }else{
116005 whereSplit(pWC, pExpr->pLeft, op);
116006 whereSplit(pWC, pExpr->pRight, op);
116007 }
116008 }
116009
116010 /*
116011 ** Initialize a WhereMaskSet object
@@ -117272,11 +117701,11 @@
117272 if( p->op==TK_COLUMN
117273 && p->iColumn==pIdx->aiColumn[iCol]
117274 && p->iTable==iBase
117275 ){
117276 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117277 if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117278 return i;
117279 }
117280 }
117281 }
117282
@@ -117546,11 +117975,11 @@
117546 if( (idxCols & cMask)==0 ){
117547 Expr *pX = pTerm->pExpr;
117548 idxCols |= cMask;
117549 pIdx->aiColumn[n] = pTerm->u.leftColumn;
117550 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117551 pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY";
117552 n++;
117553 }
117554 }
117555 }
117556 assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119271,11 @@
118842
118843 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
118844 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
118845 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
118846
118847 sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118848 str.db = db;
118849 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
118850 if( pItem->pSelect ){
118851 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
118852 }else{
118853 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120470,17 @@
120042 /*
120043 ** Free a WhereInfo structure
120044 */
120045 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120046 if( ALWAYS(pWInfo) ){
 
 
 
 
 
 
 
120047 whereClauseClear(&pWInfo->sWC);
120048 while( pWInfo->pLoops ){
120049 WhereLoop *p = pWInfo->pLoops;
120050 pWInfo->pLoops = p->pNextLoop;
120051 whereLoopDelete(db, p);
@@ -120521,11 +120956,11 @@
120521 ** changes "x IN (?)" into "x=?". */
120522
120523 }else if( eOp & (WO_EQ) ){
120524 pNew->wsFlags |= WHERE_COLUMN_EQ;
120525 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120526 if( iCol>=0 && !IsUniqueIndex(pProbe) ){
120527 pNew->wsFlags |= WHERE_UNQ_WANTED;
120528 }else{
120529 pNew->wsFlags |= WHERE_ONEROW;
120530 }
120531 }
@@ -121981,11 +122416,11 @@
121981 pWInfo->nOBSat = pFrom->isOrdered;
121982 if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
121983 pWInfo->revMask = pFrom->revLoop;
121984 }
121985 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
121986 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
121987 ){
121988 Bitmask revMask = 0;
121989 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
121990 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
121991 );
@@ -122386,11 +122821,10 @@
122386 if( pParse->nErr || NEVER(db->mallocFailed) ){
122387 goto whereBeginError;
122388 }
122389 #ifdef WHERETRACE_ENABLED /* !=0 */
122390 if( sqlite3WhereTrace ){
122391 int ii;
122392 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122393 if( pWInfo->nOBSat>0 ){
122394 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122395 }
122396 switch( pWInfo->eDistinct ){
@@ -122639,11 +123073,10 @@
122639 VdbeCoverage(v);
122640 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
122641 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
122642 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
122643 }
122644 sqlite3DbFree(db, pLevel->u.in.aInLoop);
122645 }
122646 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
122647 if( pLevel->addrSkip ){
122648 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
122649 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123283,32 @@
122850 /*
122851 ** An instance of this structure holds the ATTACH key and the key type.
122852 */
122853 struct AttachKey { int type; Token key; };
122854
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122855
122856 /* This is a utility routine used to set the ExprSpan.zStart and
122857 ** ExprSpan.zEnd values of pOut so that the span covers the complete
122858 ** range of text beginning with pStart and going to the end of pEnd.
122859 */
@@ -125167,31 +125622,14 @@
125167 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125168 }
125169 break;
125170 case 112: /* select ::= with selectnowith */
125171 {
125172 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
125173 if( p ){
125174 int cnt = 0, mxSelect;
125175 p->pWith = yymsp[-1].minor.yy59;
125176 if( p->pPrior ){
125177 u16 allValues = SF_Values;
125178 pNext = 0;
125179 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
125180 pLoop->pNext = pNext;
125181 pLoop->selFlags |= SF_Compound;
125182 allValues &= pLoop->selFlags;
125183 }
125184 if( allValues ){
125185 p->selFlags |= SF_AllValues;
125186 }else if(
125187 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
125188 && cnt>mxSelect
125189 ){
125190 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
125191 }
125192 }
125193 }else{
125194 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125195 }
125196 yygotominor.yy3 = p;
125197 }
@@ -125205,16 +125643,18 @@
125205 Select *pRhs = yymsp[0].minor.yy3;
125206 if( pRhs && pRhs->pPrior ){
125207 SrcList *pFrom;
125208 Token x;
125209 x.n = 0;
 
125210 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125211 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125212 }
125213 if( pRhs ){
125214 pRhs->op = (u8)yymsp[-1].minor.yy328;
125215 pRhs->pPrior = yymsp[-2].minor.yy3;
 
125216 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125217 }else{
125218 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125219 }
125220 yygotominor.yy3 = pRhs;
@@ -125257,17 +125697,20 @@
125257 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125258 }
125259 break;
125260 case 121: /* values ::= values COMMA LP exprlist RP */
125261 {
125262 Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
 
 
125263 if( pRight ){
125264 pRight->op = TK_ALL;
125265 pRight->pPrior = yymsp[-4].minor.yy3;
 
125266 yygotominor.yy3 = pRight;
125267 }else{
125268 yygotominor.yy3 = yymsp[-4].minor.yy3;
125269 }
125270 }
125271 break;
125272 case 122: /* distinct ::= DISTINCT */
125273 {yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127510,12 @@
127067 goto abort_parse;
127068 }
127069 break;
127070 }
127071 case TK_ILLEGAL: {
127072 sqlite3DbFree(db, *pzErrMsg);
127073 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
127074 &pParse->sLastToken);
127075 nErr++;
127076 goto abort_parse;
127077 }
127078 case TK_SEMI: {
127079 pParse->zTail = &zSql[i];
127080 /* Fall thru into the default case */
@@ -127088,16 +127529,19 @@
127088 break;
127089 }
127090 }
127091 }
127092 abort_parse:
127093 if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
 
127094 if( lastTokenParsed!=TK_SEMI ){
127095 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127096 pParse->zTail = &zSql[i];
127097 }
127098 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
 
 
127099 }
127100 #ifdef YYTRACKMAXSTACKDEPTH
127101 sqlite3_mutex_enter(sqlite3MallocMutex());
127102 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127103 sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127598,11 @@
127154 while( pParse->pZombieTab ){
127155 Table *p = pParse->pZombieTab;
127156 pParse->pZombieTab = p->pNextZombie;
127157 sqlite3DeleteTable(db, p);
127158 }
127159 if( nErr>0 && pParse->rc==SQLITE_OK ){
127160 pParse->rc = SQLITE_ERROR;
127161 }
127162 return nErr;
127163 }
127164
127165 /************** End of tokenize.c ********************************************/
127166 /************** Begin file complete.c ****************************************/
@@ -127432,11 +127874,11 @@
127432 ** UTF-8.
127433 */
127434 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127435 sqlite3_value *pVal;
127436 char const *zSql8;
127437 int rc = SQLITE_NOMEM;
127438
127439 #ifndef SQLITE_OMIT_AUTOINIT
127440 rc = sqlite3_initialize();
127441 if( rc ) return rc;
127442 #endif
@@ -127598,10 +128040,22 @@
127598 ** zero if and only if SQLite was compiled with mutexing code omitted due to
127599 ** the SQLITE_THREADSAFE compile-time option being set to 0.
127600 */
127601 SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
127602
 
 
 
 
 
 
 
 
 
 
 
 
127603 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
127604 /*
127605 ** If the following function pointer is not NULL and if
127606 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
127607 ** I/O active are written using this function. These messages
@@ -128737,11 +129191,11 @@
128737
128738 /*
128739 ** Return a static string containing the name corresponding to the error code
128740 ** specified in the argument.
128741 */
128742 #if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST)
128743 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
128744 const char *zName = 0;
128745 int i, origRc = rc;
128746 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
128747 switch( rc ){
@@ -129962,18 +130416,18 @@
129962 ){
129963 char *zOpt;
129964 int eState; /* Parser state when parsing URI */
129965 int iIn; /* Input character index */
129966 int iOut = 0; /* Output character index */
129967 int nByte = nUri+2; /* Bytes of space to allocate */
129968
129969 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
129970 ** method that there may be extra parameters following the file-name. */
129971 flags |= SQLITE_OPEN_URI;
129972
129973 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129974 zFile = sqlite3_malloc(nByte);
129975 if( !zFile ) return SQLITE_NOMEM;
129976
129977 iIn = 5;
129978 #ifdef SQLITE_ALLOW_URI_AUTHORITY
129979 if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130589,11 @@
130135
130136 zOpt = &zVal[nVal+1];
130137 }
130138
130139 }else{
130140 zFile = sqlite3_malloc(nUri+2);
130141 if( !zFile ) return SQLITE_NOMEM;
130142 memcpy(zFile, zUri, nUri);
130143 zFile[nUri] = '\0';
130144 zFile[nUri+1] = '\0';
130145 flags &= ~SQLITE_OPEN_URI;
@@ -130406,10 +130860,17 @@
130406 #ifdef SQLITE_ENABLE_RTREE
130407 if( !db->mallocFailed && rc==SQLITE_OK){
130408 rc = sqlite3RtreeInit(db);
130409 }
130410 #endif
 
 
 
 
 
 
 
130411
130412 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
130413 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
130414 ** mode. Doing nothing at all also makes NORMAL the default.
130415 */
@@ -132344,10 +132805,15 @@
132344 ** false.
132345 */
132346 #ifdef SQLITE_COVERAGE_TEST
132347 # define ALWAYS(x) (1)
132348 # define NEVER(X) (0)
 
 
 
 
 
132349 #else
132350 # define ALWAYS(x) (x)
132351 # define NEVER(x) (x)
132352 #endif
132353
@@ -132744,10 +133210,11 @@
132744 #define fts3GetVarint32(p, piVal) ( \
132745 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
132746 )
132747
132748 /* fts3.c */
 
132749 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
132750 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
132751 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
132752 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
132753 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133299,17 @@
132832
132833 static int fts3EvalNext(Fts3Cursor *pCsr);
132834 static int fts3EvalStart(Fts3Cursor *pCsr);
132835 static int fts3TermSegReaderCursor(
132836 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
 
 
 
 
 
 
 
132837
132838 /*
132839 ** Write a 64-bit variable-length integer to memory starting at p[0].
132840 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
132841 ** The number of bytes written is returned.
@@ -132942,11 +133416,11 @@
132942 int iOut = 0; /* Index of next byte to write to output */
132943
132944 /* If the first byte was a '[', then the close-quote character is a ']' */
132945 if( quote=='[' ) quote = ']';
132946
132947 while( ALWAYS(z[iIn]) ){
132948 if( z[iIn]==quote ){
132949 if( z[iIn+1]!=quote ) break;
132950 z[iOut++] = quote;
132951 iIn += 2;
132952 }else{
@@ -133020,10 +133494,21 @@
133020 p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133021
133022 sqlite3_free(p);
133023 return SQLITE_OK;
133024 }
 
 
 
 
 
 
 
 
 
 
 
133025
133026 /*
133027 ** Construct one or more SQL statements from the format string given
133028 ** and then evaluate those statements. The success code is written
133029 ** into *pRc.
@@ -133539,11 +134024,12 @@
133539 sqlite3 *db, /* Database handle */
133540 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
133541 const char *zTbl, /* Name of content table */
133542 const char ***pazCol, /* OUT: Malloc'd array of column names */
133543 int *pnCol, /* OUT: Size of array *pazCol */
133544 int *pnStr /* OUT: Bytes of string content */
 
133545 ){
133546 int rc = SQLITE_OK; /* Return code */
133547 char *zSql; /* "SELECT *" statement on zTbl */
133548 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
133549
@@ -133550,10 +134036,13 @@
133550 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
133551 if( !zSql ){
133552 rc = SQLITE_NOMEM;
133553 }else{
133554 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
 
 
 
133555 }
133556 sqlite3_free(zSql);
133557
133558 if( rc==SQLITE_OK ){
133559 const char **azCol; /* Output array */
@@ -133716,17 +134205,17 @@
133716 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
133717 break;
133718 }
133719 }
133720 if( iOpt==SizeofArray(aFts4Opt) ){
133721 *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z);
133722 rc = SQLITE_ERROR;
133723 }else{
133724 switch( iOpt ){
133725 case 0: /* MATCHINFO */
133726 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
133727 *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal);
133728 rc = SQLITE_ERROR;
133729 }
133730 bNoDocsize = 1;
133731 break;
133732
@@ -133750,11 +134239,11 @@
133750
133751 case 4: /* ORDER */
133752 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
133753 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
133754 ){
133755 *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
133756 rc = SQLITE_ERROR;
133757 }
133758 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
133759 break;
133760
@@ -133801,11 +134290,11 @@
133801 zCompress = 0;
133802 zUncompress = 0;
133803 if( nCol==0 ){
133804 sqlite3_free((void*)aCol);
133805 aCol = 0;
133806 rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
133807
133808 /* If a languageid= option was specified, remove the language id
133809 ** column from the aCol[] array. */
133810 if( rc==SQLITE_OK && zLanguageid ){
133811 int j;
@@ -133836,11 +134325,11 @@
133836 assert( pTokenizer );
133837
133838 rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
133839 if( rc==SQLITE_ERROR ){
133840 assert( zPrefix );
133841 *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix);
133842 }
133843 if( rc!=SQLITE_OK ) goto fts3_init_out;
133844
133845 /* Allocate and populate the Fts3Table structure. */
133846 nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134407,19 @@
133918 }
133919 }
133920 }
133921 for(i=0; i<nNotindexed; i++){
133922 if( azNotindexed[i] ){
133923 *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
133924 rc = SQLITE_ERROR;
133925 }
133926 }
133927
133928 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
133929 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
133930 rc = SQLITE_ERROR;
133931 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
133932 }
133933 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
133934 p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
133935 if( rc!=SQLITE_OK ) goto fts3_init_out;
133936
@@ -135319,11 +135808,11 @@
135319 ** Fts3SegReaderPending might segfault, as the data structures used by
135320 ** fts4aux are not completely populated. So it's easiest to filter these
135321 ** calls out here. */
135322 if( iLevel<0 && p->aIndex ){
135323 Fts3SegReader *pSeg = 0;
135324 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg);
135325 if( rc==SQLITE_OK && pSeg ){
135326 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135327 }
135328 }
135329
@@ -135968,15 +136457,35 @@
135968 */
135969 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
135970 char *p = &(*ppPoslist)[-2];
135971 char c = 0;
135972
 
135973 while( p>pStart && (c=*p--)==0 );
 
 
 
 
135974 while( p>pStart && (*p & 0x80) | c ){
135975 c = *p--;
135976 }
135977 if( p>pStart ){ p = &p[2]; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135978 while( *p++&0x80 );
135979 *ppPoslist = p;
135980 }
135981
135982 /*
@@ -136043,10 +136552,12 @@
136043 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136044 case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136045 }
136046 if( !zEllipsis || !zEnd || !zStart ){
136047 sqlite3_result_error_nomem(pContext);
 
 
136048 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136049 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136050 }
136051 }
136052
@@ -137104,16 +137615,18 @@
137104 Fts3Expr *pExpr, /* Expression to initialize phrases in */
137105 int *pRc /* IN/OUT: Error code */
137106 ){
137107 if( pExpr && SQLITE_OK==*pRc ){
137108 if( pExpr->eType==FTSQUERY_PHRASE ){
137109 int i;
137110 int nToken = pExpr->pPhrase->nToken;
137111 for(i=0; i<nToken; i++){
137112 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
 
 
 
 
137113 }
137114 pExpr->bDeferred = (i==nToken);
137115 *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137116 }else{
137117 fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137118 fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137119 pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138785,12 @@
138272 if( rc!=SQLITE_OK ) return rc;
138273
138274 pIter = pPhrase->pOrPoslist;
138275 iDocid = pPhrase->iOrDocid;
138276 if( pCsr->bDesc==bDescDoclist ){
138277 bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
 
138278 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138279 sqlite3Fts3DoclistNext(
138280 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138281 &pIter, &iDocid, &bEof
138282 );
@@ -138484,11 +138998,11 @@
138484
138485 *ppVtab = (sqlite3_vtab *)p;
138486 return SQLITE_OK;
138487
138488 bad_args:
138489 *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor");
138490 return SQLITE_ERROR;
138491 }
138492
138493 /*
138494 ** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140456,17 @@
139942
139943 if( rc!=SQLITE_OK ){
139944 sqlite3Fts3ExprFree(*ppExpr);
139945 *ppExpr = 0;
139946 if( rc==SQLITE_TOOBIG ){
139947 *pzErr = sqlite3_mprintf(
139948 "FTS expression tree is too large (maximum depth %d)",
139949 SQLITE_FTS3_MAX_EXPR_DEPTH
139950 );
139951 rc = SQLITE_ERROR;
139952 }else if( rc==SQLITE_ERROR ){
139953 *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
139954 }
139955 }
139956
139957 return rc;
139958 }
@@ -141424,11 +141938,11 @@
141424 z[n] = '\0';
141425 sqlite3Fts3Dequote(z);
141426
141427 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141428 if( !m ){
141429 *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z);
141430 rc = SQLITE_ERROR;
141431 }else{
141432 char const **aArg = 0;
141433 int iArg = 0;
141434 z = &z[n+1];
@@ -141447,11 +141961,11 @@
141447 z = &z[n+1];
141448 }
141449 rc = m->xCreate(iArg, aArg, ppTok);
141450 assert( rc!=SQLITE_OK || *ppTok );
141451 if( rc!=SQLITE_OK ){
141452 *pzErr = sqlite3_mprintf("unknown tokenizer");
141453 }else{
141454 (*ppTok)->pModule = m;
141455 }
141456 sqlite3_free((void *)aArg);
141457 }
@@ -141531,13 +142045,13 @@
141531
141532 pHash = (Fts3Hash *)sqlite3_user_data(context);
141533 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
141534
141535 if( !p ){
141536 char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
141537 sqlite3_result_error(context, zErr, -1);
141538 sqlite3_free(zErr);
141539 return;
141540 }
141541
141542 pRet = Tcl_NewObj();
141543 Tcl_IncrRefCount(pRet);
@@ -142068,11 +142582,11 @@
142068 sqlite3_tokenizer_module *p;
142069 int nName = (int)strlen(zName);
142070
142071 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142072 if( !p ){
142073 *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
142074 return SQLITE_ERROR;
142075 }
142076
142077 *pp = p;
142078 return SQLITE_OK;
@@ -142765,11 +143279,11 @@
142765 /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
142766 /* 24 */ "",
142767 /* 25 */ "",
142768
142769 /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
142770 /* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'",
142771
142772 /* This statement is used to determine which level to read the input from
142773 ** when performing an incremental merge. It returns the absolute level number
142774 ** of the oldest level in the db that contains at least ? segments. Or,
142775 ** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146397,12 @@
145883 sqlite3_stmt *pAllLangid = 0;
145884
145885 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
145886 if( rc==SQLITE_OK ){
145887 int rc2;
145888 sqlite3_bind_int(pAllLangid, 1, p->nIndex);
 
145889 while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
145890 int i;
145891 int iLangid = sqlite3_column_int(pAllLangid, 0);
145892 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
145893 rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147730,11 @@
147215 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147216
147217 pHint->n = i;
147218 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147219 i += fts3GetVarint32(&pHint->a[i], pnInput);
147220 if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
147221
147222 return SQLITE_OK;
147223 }
147224
147225
@@ -147583,11 +148098,12 @@
147583
147584 /* This block calculates the checksum according to the FTS index. */
147585 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147586 if( rc==SQLITE_OK ){
147587 int rc2;
147588 sqlite3_bind_int(pAllLangid, 1, p->nIndex);
 
147589 while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
147590 int iLangid = sqlite3_column_int(pAllLangid, 0);
147591 int i;
147592 for(i=0; i<p->nIndex; i++){
147593 cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148112,10 @@
147596 rc2 = sqlite3_reset(pAllLangid);
147597 if( rc==SQLITE_OK ) rc = rc2;
147598 }
147599
147600 /* This block calculates the checksum according to the %_content table */
147601 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147602 if( rc==SQLITE_OK ){
147603 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
147604 sqlite3_stmt *pStmt = 0;
147605 char *zSql;
147606
@@ -147693,11 +148208,11 @@
147693 Fts3Table *p /* FTS3 table handle */
147694 ){
147695 int rc;
147696 int bOk = 0;
147697 rc = fts3IntegrityCheck(p, &bOk);
147698 if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB;
147699 return rc;
147700 }
147701
147702 /*
147703 ** Handle a 'special' INSERT of the form:
@@ -148131,10 +148646,11 @@
148131 #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148132 #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148133 #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148134 #define FTS3_MATCHINFO_LCS 's' /* nCol values */
148135 #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
 
148136
148137 /*
148138 ** The default value for the second argument to matchinfo().
148139 */
148140 #define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149428,55 @@
148912 }
148913 }
148914
148915 return rc;
148916 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148917
148918 static int fts3MatchinfoCheck(
148919 Fts3Table *pTab,
148920 char cArg,
148921 char **pzErr
@@ -148925,14 +149486,15 @@
148925 || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
148926 || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
148927 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
148928 || (cArg==FTS3_MATCHINFO_LCS)
148929 || (cArg==FTS3_MATCHINFO_HITS)
 
148930 ){
148931 return SQLITE_OK;
148932 }
148933 *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);
148934 return SQLITE_ERROR;
148935 }
148936
148937 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
148938 int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149509,14 @@
148947 case FTS3_MATCHINFO_AVGLENGTH:
148948 case FTS3_MATCHINFO_LENGTH:
148949 case FTS3_MATCHINFO_LCS:
148950 nVal = pInfo->nCol;
148951 break;
 
 
 
 
148952
148953 default:
148954 assert( cArg==FTS3_MATCHINFO_HITS );
148955 nVal = pInfo->nCol * pInfo->nPhrase * 3;
148956 break;
@@ -149201,10 +149767,14 @@
149201 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149202 if( rc==SQLITE_OK ){
149203 rc = fts3MatchinfoLcs(pCsr, pInfo);
149204 }
149205 break;
 
 
 
 
149206
149207 default: {
149208 Fts3Expr *pExpr;
149209 assert( zArg[i]==FTS3_MATCHINFO_HITS );
149210 pExpr = pCsr->pExpr;
@@ -153214,15 +153784,23 @@
153214 ** conflict-handling mode specified by the user.
153215 */
153216 if( nData>1 ){
153217 int ii;
153218
153219 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
153220 assert( nData==(pRtree->nDim*2 + 3) );
 
 
 
 
 
 
 
 
153221 #ifndef SQLITE_RTREE_INT_ONLY
153222 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153223 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153224 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153225 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153226 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153227 rc = SQLITE_CONSTRAINT;
153228 goto constraint;
@@ -153229,11 +153807,11 @@
153229 }
153230 }
153231 }else
153232 #endif
153233 {
153234 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153235 cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153236 cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153237 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153238 rc = SQLITE_CONSTRAINT;
153239 goto constraint;
@@ -154629,5 +155207,633 @@
154629
154630 #endif /* defined(SQLITE_ENABLE_ICU) */
154631 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
154632
154633 /************** End of fts3_icu.c ********************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154634
--- 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.10. 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.
@@ -68,10 +68,11 @@
68 #if defined(_MSC_VER)
69 #pragma warning(disable : 4054)
70 #pragma warning(disable : 4055)
71 #pragma warning(disable : 4100)
72 #pragma warning(disable : 4127)
73 #pragma warning(disable : 4130)
74 #pragma warning(disable : 4152)
75 #pragma warning(disable : 4189)
76 #pragma warning(disable : 4206)
77 #pragma warning(disable : 4210)
78 #pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
316 **
317 ** See also: [sqlite3_libversion()],
318 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
319 ** [sqlite_version()] and [sqlite_source_id()].
320 */
321 #define SQLITE_VERSION "3.8.10"
322 #define SQLITE_VERSION_NUMBER 3008010
323 #define SQLITE_SOURCE_ID "2015-05-07 11:53:08 cf975957b9ae671f34bb65f049acf351e650d437"
324
325 /*
326 ** CAPI3REF: Run-Time Library Version Numbers
327 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
328 **
@@ -474,10 +475,11 @@
475 # define double sqlite3_int64
476 #endif
477
478 /*
479 ** CAPI3REF: Closing A Database Connection
480 ** DESTRUCTOR: sqlite3
481 **
482 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
483 ** for the [sqlite3] object.
484 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
485 ** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
527 */
528 typedef int (*sqlite3_callback)(void*,int,char**, char**);
529
530 /*
531 ** CAPI3REF: One-Step Query Execution Interface
532 ** METHOD: sqlite3
533 **
534 ** The sqlite3_exec() interface is a convenience wrapper around
535 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
536 ** that allows an application to run multiple statements of SQL
537 ** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
1585 */
1586 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1587
1588 /*
1589 ** CAPI3REF: Configure database connections
1590 ** METHOD: sqlite3
1591 **
1592 ** The sqlite3_db_config() interface is used to make configuration
1593 ** changes to a [database connection]. The interface is similar to
1594 ** [sqlite3_config()] except that the changes apply to a single
1595 ** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
2083 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2084
2085
2086 /*
2087 ** CAPI3REF: Enable Or Disable Extended Result Codes
2088 ** METHOD: sqlite3
2089 **
2090 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2091 ** [extended result codes] feature of SQLite. ^The extended result
2092 ** codes are disabled by default for historical compatibility.
2093 */
2094 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
2095
2096 /*
2097 ** CAPI3REF: Last Insert Rowid
2098 ** METHOD: sqlite3
2099 **
2100 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2101 ** has a unique 64-bit signed
2102 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2103 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
2145 */
2146 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
2147
2148 /*
2149 ** CAPI3REF: Count The Number Of Rows Modified
2150 ** METHOD: sqlite3
2151 **
2152 ** ^This function returns the number of rows modified, inserted or
2153 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2154 ** statement on the database connection specified by the only parameter.
2155 ** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
2198 */
2199 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
2200
2201 /*
2202 ** CAPI3REF: Total Number Of Rows Modified
2203 ** METHOD: sqlite3
2204 **
2205 ** ^This function returns the total number of rows inserted, modified or
2206 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2207 ** since the database connection was opened, including those executed as
2208 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
2222 */
2223 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2224
2225 /*
2226 ** CAPI3REF: Interrupt A Long-Running Query
2227 ** METHOD: sqlite3
2228 **
2229 ** ^This function causes any pending database operation to abort and
2230 ** return at its earliest opportunity. This routine is typically
2231 ** called in response to a user action such as pressing "Cancel"
2232 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
2299 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2300
2301 /*
2302 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2303 ** KEYWORDS: {busy-handler callback} {busy handler}
2304 ** METHOD: sqlite3
2305 **
2306 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2307 ** that might be invoked with argument P whenever
2308 ** an attempt is made to access a database table associated with
2309 ** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
2359 */
2360 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2361
2362 /*
2363 ** CAPI3REF: Set A Busy Timeout
2364 ** METHOD: sqlite3
2365 **
2366 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2367 ** for a specified amount of time when a table is locked. ^The handler
2368 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2369 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
2382 */
2383 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2384
2385 /*
2386 ** CAPI3REF: Convenience Routines For Running Queries
2387 ** METHOD: sqlite3
2388 **
2389 ** This is a legacy interface that is preserved for backwards compatibility.
2390 ** Use of this interface is not recommended.
2391 **
2392 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
2718 */
2719 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2720
2721 /*
2722 ** CAPI3REF: Compile-Time Authorization Callbacks
2723 ** METHOD: sqlite3
2724 **
2725 ** ^This routine registers an authorizer callback with a particular
2726 ** [database connection], supplied in the first argument.
2727 ** ^The authorizer callback is invoked as SQL statements are being compiled
2728 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
2875 #define SQLITE_COPY 0 /* No longer used */
2876 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2877
2878 /*
2879 ** CAPI3REF: Tracing And Profiling Functions
2880 ** METHOD: sqlite3
2881 **
2882 ** These routines register callback functions that can be used for
2883 ** tracing and profiling the execution of SQL statements.
2884 **
2885 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
2908 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2909 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2910
2911 /*
2912 ** CAPI3REF: Query Progress Callbacks
2913 ** METHOD: sqlite3
2914 **
2915 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2916 ** function X to be invoked periodically during long running calls to
2917 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2918 ** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
2942 */
2943 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2944
2945 /*
2946 ** CAPI3REF: Opening A New Database Connection
2947 ** CONSTRUCTOR: sqlite3
2948 **
2949 ** ^These routines open an SQLite database file as specified by the
2950 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2951 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2952 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
3228 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3229
3230
3231 /*
3232 ** CAPI3REF: Error Codes And Messages
3233 ** METHOD: sqlite3
3234 **
3235 ** ^If the most recent sqlite3_* API call associated with
3236 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3237 ** returns the numeric [result code] or [extended result code] for that
3238 ** API call.
@@ -3257,37 +3274,38 @@
3274 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3275 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3276 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3277
3278 /*
3279 ** CAPI3REF: Prepared Statement Object
3280 ** KEYWORDS: {prepared statement} {prepared statements}
3281 **
3282 ** An instance of this object represents a single SQL statement that
3283 ** has been compiled into binary form and is ready to be evaluated.
 
3284 **
3285 ** Think of each SQL statement as a separate computer program. The
3286 ** original SQL text is source code. A prepared statement object
3287 ** is the compiled object code. All SQL must be converted into a
3288 ** prepared statement before it can be run.
3289 **
3290 ** The life-cycle of a prepared statement object usually goes like this:
3291 **
3292 ** <ol>
3293 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3294 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
 
3295 ** interfaces.
3296 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3297 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3298 ** to step 2. Do this zero or more times.
3299 ** <li> Destroy the object using [sqlite3_finalize()].
3300 ** </ol>
 
 
 
3301 */
3302 typedef struct sqlite3_stmt sqlite3_stmt;
3303
3304 /*
3305 ** CAPI3REF: Run-time Limits
3306 ** METHOD: sqlite3
3307 **
3308 ** ^(This interface allows the size of various constructs to be limited
3309 ** on a connection by connection basis. The first parameter is the
3310 ** [database connection] whose limit is to be set or queried. The
3311 ** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
3413 #define SQLITE_LIMIT_WORKER_THREADS 11
3414
3415 /*
3416 ** CAPI3REF: Compiling An SQL Statement
3417 ** KEYWORDS: {SQL statement compiler}
3418 ** METHOD: sqlite3
3419 ** CONSTRUCTOR: sqlite3_stmt
3420 **
3421 ** To execute an SQL query, it must first be compiled into a byte-code
3422 ** program using one of these routines.
3423 **
3424 ** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
3522 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3523 );
3524
3525 /*
3526 ** CAPI3REF: Retrieving Statement SQL
3527 ** METHOD: sqlite3_stmt
3528 **
3529 ** ^This interface can be used to retrieve a saved copy of the original
3530 ** SQL text used to create a [prepared statement] if that statement was
3531 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3532 */
3533 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3534
3535 /*
3536 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3537 ** METHOD: sqlite3_stmt
3538 **
3539 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3540 ** and only if the [prepared statement] X makes no direct changes to
3541 ** the content of the database file.
3542 **
@@ -3542,10 +3564,11 @@
3564 */
3565 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3566
3567 /*
3568 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3569 ** METHOD: sqlite3_stmt
3570 **
3571 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3572 ** [prepared statement] S has been stepped at least once using
3573 ** [sqlite3_step(S)] but has not run to completion and/or has not
3574 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
3639
3640 /*
3641 ** CAPI3REF: Binding Values To Prepared Statements
3642 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3643 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3644 ** METHOD: sqlite3_stmt
3645 **
3646 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3647 ** literals may be replaced by a [parameter] that matches one of following
3648 ** templates:
3649 **
@@ -3734,10 +3758,11 @@
3758 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3759 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3760
3761 /*
3762 ** CAPI3REF: Number Of SQL Parameters
3763 ** METHOD: sqlite3_stmt
3764 **
3765 ** ^This routine can be used to find the number of [SQL parameters]
3766 ** in a [prepared statement]. SQL parameters are tokens of the
3767 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3768 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
3779 */
3780 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3781
3782 /*
3783 ** CAPI3REF: Name Of A Host Parameter
3784 ** METHOD: sqlite3_stmt
3785 **
3786 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3787 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3788 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3789 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
3807 */
3808 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3809
3810 /*
3811 ** CAPI3REF: Index Of A Parameter With A Given Name
3812 ** METHOD: sqlite3_stmt
3813 **
3814 ** ^Return the index of an SQL parameter given its name. ^The
3815 ** index value returned is suitable for use as the second
3816 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3817 ** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
3824 */
3825 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3826
3827 /*
3828 ** CAPI3REF: Reset All Bindings On A Prepared Statement
3829 ** METHOD: sqlite3_stmt
3830 **
3831 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3832 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3833 ** ^Use this routine to reset all host parameters to NULL.
3834 */
3835 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3836
3837 /*
3838 ** CAPI3REF: Number Of Columns In A Result Set
3839 ** METHOD: sqlite3_stmt
3840 **
3841 ** ^Return the number of columns in the result set returned by the
3842 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3843 ** statement that does not return data (for example an [UPDATE]).
3844 **
@@ -3817,10 +3846,11 @@
3846 */
3847 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3848
3849 /*
3850 ** CAPI3REF: Column Names In A Result Set
3851 ** METHOD: sqlite3_stmt
3852 **
3853 ** ^These routines return the name assigned to a particular column
3854 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3855 ** interface returns a pointer to a zero-terminated UTF-8 string
3856 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
3876 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3877 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3878
3879 /*
3880 ** CAPI3REF: Source Of Data In A Query Result
3881 ** METHOD: sqlite3_stmt
3882 **
3883 ** ^These routines provide a means to determine the database, table, and
3884 ** table column that is the origin of a particular result column in
3885 ** [SELECT] statement.
3886 ** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
3929 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3930 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3931
3932 /*
3933 ** CAPI3REF: Declared Datatype Of A Query Result
3934 ** METHOD: sqlite3_stmt
3935 **
3936 ** ^(The first parameter is a [prepared statement].
3937 ** If this statement is a [SELECT] statement and the Nth column of the
3938 ** returned result set of that [SELECT] is a table column (not an
3939 ** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
3962 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3963 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3964
3965 /*
3966 ** CAPI3REF: Evaluate An SQL Statement
3967 ** METHOD: sqlite3_stmt
3968 **
3969 ** After a [prepared statement] has been prepared using either
3970 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3971 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3972 ** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
4042 */
4043 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
4044
4045 /*
4046 ** CAPI3REF: Number of columns in a result set
4047 ** METHOD: sqlite3_stmt
4048 **
4049 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4050 ** current row of the result set of [prepared statement] P.
4051 ** ^If prepared statement P does not have results ready to return
4052 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
4096 #define SQLITE3_TEXT 3
4097
4098 /*
4099 ** CAPI3REF: Result Values From A Query
4100 ** KEYWORDS: {column access functions}
4101 ** METHOD: sqlite3_stmt
4102 **
4103 ** These routines form the "result set" interface.
4104 **
4105 ** ^These routines return information about a single column of the current
4106 ** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
4269 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4270 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4271
4272 /*
4273 ** CAPI3REF: Destroy A Prepared Statement Object
4274 ** DESTRUCTOR: sqlite3_stmt
4275 **
4276 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4277 ** ^If the most recent evaluation of the statement encountered no errors
4278 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4279 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
4297 */
4298 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4299
4300 /*
4301 ** CAPI3REF: Reset A Prepared Statement Object
4302 ** METHOD: sqlite3_stmt
4303 **
4304 ** The sqlite3_reset() function is called to reset a [prepared statement]
4305 ** object back to its initial state, ready to be re-executed.
4306 ** ^Any SQL statement variables that had values bound to them using
4307 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
4327 /*
4328 ** CAPI3REF: Create Or Redefine SQL Functions
4329 ** KEYWORDS: {function creation routines}
4330 ** KEYWORDS: {application-defined SQL function}
4331 ** KEYWORDS: {application-defined SQL functions}
4332 ** METHOD: sqlite3
4333 **
4334 ** ^These functions (collectively known as "function creation routines")
4335 ** are used to add SQL functions or aggregates or to redefine the behavior
4336 ** of existing SQL functions or aggregates. The only differences between
4337 ** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
4497 void*,sqlite3_int64);
4498 #endif
4499
4500 /*
4501 ** CAPI3REF: Obtaining SQL Function Parameter Values
4502 ** METHOD: sqlite3_value
4503 **
4504 ** The C-language implementation of SQL functions and aggregates uses
4505 ** this set of interface routines to access the parameter values on
4506 ** the function or aggregate.
4507 **
@@ -4517,10 +4556,11 @@
4556 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4557 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4558
4559 /*
4560 ** CAPI3REF: Obtain Aggregate Function Context
4561 ** METHOD: sqlite3_context
4562 **
4563 ** Implementations of aggregate SQL functions use this
4564 ** routine to allocate memory for storing their state.
4565 **
4566 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
4601 */
4602 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4603
4604 /*
4605 ** CAPI3REF: User Data For Functions
4606 ** METHOD: sqlite3_context
4607 **
4608 ** ^The sqlite3_user_data() interface returns a copy of
4609 ** the pointer that was the pUserData parameter (the 5th parameter)
4610 ** of the [sqlite3_create_function()]
4611 ** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
4616 */
4617 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4618
4619 /*
4620 ** CAPI3REF: Database Connection For Functions
4621 ** METHOD: sqlite3_context
4622 **
4623 ** ^The sqlite3_context_db_handle() interface returns a copy of
4624 ** the pointer to the [database connection] (the 1st parameter)
4625 ** of the [sqlite3_create_function()]
4626 ** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
4628 */
4629 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4630
4631 /*
4632 ** CAPI3REF: Function Auxiliary Data
4633 ** METHOD: sqlite3_context
4634 **
4635 ** These functions may be used by (non-aggregate) SQL functions to
4636 ** associate metadata with argument values. If the same value is passed to
4637 ** multiple invocations of the same SQL function during query execution, under
4638 ** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
4701 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4702 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4703
4704 /*
4705 ** CAPI3REF: Setting The Result Of An SQL Function
4706 ** METHOD: sqlite3_context
4707 **
4708 ** These routines are used by the xFunc or xFinal callbacks that
4709 ** implement SQL functions and aggregates. See
4710 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4711 ** for additional information.
@@ -4793,10 +4837,11 @@
4837 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4838 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4839
4840 /*
4841 ** CAPI3REF: Define New Collating Sequences
4842 ** METHOD: sqlite3
4843 **
4844 ** ^These functions add, remove, or modify a [collation] associated
4845 ** with the [database connection] specified as the first argument.
4846 **
4847 ** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
4940 int(*xCompare)(void*,int,const void*,int,const void*)
4941 );
4942
4943 /*
4944 ** CAPI3REF: Collation Needed Callbacks
4945 ** METHOD: sqlite3
4946 **
4947 ** ^To avoid having to register all collation sequences before a database
4948 ** can be used, a single callback function may be registered with the
4949 ** [database connection] to be invoked whenever an undefined collation
4950 ** sequence is required.
@@ -5102,10 +5148,11 @@
5148 SQLITE_API char *sqlite3_data_directory;
5149
5150 /*
5151 ** CAPI3REF: Test For Auto-Commit Mode
5152 ** KEYWORDS: {autocommit mode}
5153 ** METHOD: sqlite3
5154 **
5155 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5156 ** zero if the given database connection is or is not in autocommit mode,
5157 ** respectively. ^Autocommit mode is on by default.
5158 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
5171 */
5172 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
5173
5174 /*
5175 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
5176 ** METHOD: sqlite3_stmt
5177 **
5178 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5179 ** to which a [prepared statement] belongs. ^The [database connection]
5180 ** returned by sqlite3_db_handle is the same [database connection]
5181 ** that was the first argument
@@ -5136,10 +5184,11 @@
5184 */
5185 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
5186
5187 /*
5188 ** CAPI3REF: Return The Filename For A Database Connection
5189 ** METHOD: sqlite3
5190 **
5191 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5192 ** associated with database N of connection D. ^The main database file
5193 ** has the name "main". If there is no attached database N on the database
5194 ** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
5201 */
5202 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5203
5204 /*
5205 ** CAPI3REF: Determine if a database is read-only
5206 ** METHOD: sqlite3
5207 **
5208 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5209 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5210 ** the name of a database on connection D.
5211 */
5212 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5213
5214 /*
5215 ** CAPI3REF: Find the next prepared statement
5216 ** METHOD: sqlite3
5217 **
5218 ** ^This interface returns a pointer to the next [prepared statement] after
5219 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5220 ** then this interface returns a pointer to the first prepared statement
5221 ** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
5227 */
5228 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5229
5230 /*
5231 ** CAPI3REF: Commit And Rollback Notification Callbacks
5232 ** METHOD: sqlite3
5233 **
5234 ** ^The sqlite3_commit_hook() interface registers a callback
5235 ** function to be invoked whenever a transaction is [COMMIT | committed].
5236 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5237 ** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
5277 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5278 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5279
5280 /*
5281 ** CAPI3REF: Data Change Notification Callbacks
5282 ** METHOD: sqlite3
5283 **
5284 ** ^The sqlite3_update_hook() interface registers a callback function
5285 ** with the [database connection] identified by the first argument
5286 ** to be invoked whenever a row is updated, inserted or deleted in
5287 ** a rowid table.
@@ -5331,10 +5384,11 @@
5384 */
5385 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5386
5387 /*
5388 ** CAPI3REF: Free Memory Used By A Database Connection
5389 ** METHOD: sqlite3
5390 **
5391 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5392 ** memory as possible from database connection D. Unlike the
5393 ** [sqlite3_release_memory()] interface, this interface is in effect even
5394 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
5462 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5463
5464
5465 /*
5466 ** CAPI3REF: Extract Metadata About A Column Of A Table
5467 ** METHOD: sqlite3
5468 **
5469 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5470 ** information about column C of table T in database D
5471 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5472 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
5541 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5542 );
5543
5544 /*
5545 ** CAPI3REF: Load An Extension
5546 ** METHOD: sqlite3
5547 **
5548 ** ^This interface loads an SQLite extension library from the named file.
5549 **
5550 ** ^The sqlite3_load_extension() interface attempts to load an
5551 ** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
5583 char **pzErrMsg /* Put error message here if not 0 */
5584 );
5585
5586 /*
5587 ** CAPI3REF: Enable Or Disable Extension Loading
5588 ** METHOD: sqlite3
5589 **
5590 ** ^So as not to open security holes in older applications that are
5591 ** unprepared to deal with [extension loading], and as a means of disabling
5592 ** [extension loading] while evaluating user-entered SQL, the following API
5593 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
5833 #define SQLITE_INDEX_CONSTRAINT_GE 32
5834 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5835
5836 /*
5837 ** CAPI3REF: Register A Virtual Table Implementation
5838 ** METHOD: sqlite3
5839 **
5840 ** ^These routines are used to register a new [virtual table module] name.
5841 ** ^Module names must be registered before
5842 ** creating a new [virtual table] using the module and before using a
5843 ** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
5930 */
5931 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5932
5933 /*
5934 ** CAPI3REF: Overload A Function For A Virtual Table
5935 ** METHOD: sqlite3
5936 **
5937 ** ^(Virtual tables can provide alternative implementations of functions
5938 ** using the [xFindFunction] method of the [virtual table module].
5939 ** But global versions of those functions
5940 ** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
5973 */
5974 typedef struct sqlite3_blob sqlite3_blob;
5975
5976 /*
5977 ** CAPI3REF: Open A BLOB For Incremental I/O
5978 ** METHOD: sqlite3
5979 ** CONSTRUCTOR: sqlite3_blob
5980 **
5981 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5982 ** in row iRow, column zColumn, table zTable in database zDb;
5983 ** in other words, the same BLOB that would be selected by:
5984 **
@@ -5995,10 +6056,11 @@
6056 sqlite3_blob **ppBlob
6057 );
6058
6059 /*
6060 ** CAPI3REF: Move a BLOB Handle to a New Row
6061 ** METHOD: sqlite3_blob
6062 **
6063 ** ^This function is used to move an existing blob handle so that it points
6064 ** to a different row of the same database table. ^The new row is identified
6065 ** by the rowid value passed as the second argument. Only the row can be
6066 ** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
6081 */
6082 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
6083
6084 /*
6085 ** CAPI3REF: Close A BLOB Handle
6086 ** DESTRUCTOR: sqlite3_blob
6087 **
6088 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
6089 ** unconditionally. Even if this routine returns an error code, the
6090 ** handle is still closed.)^
6091 **
@@ -6041,10 +6104,11 @@
6104 */
6105 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
6106
6107 /*
6108 ** CAPI3REF: Return The Size Of An Open BLOB
6109 ** METHOD: sqlite3_blob
6110 **
6111 ** ^Returns the size in bytes of the BLOB accessible via the
6112 ** successfully opened [BLOB handle] in its only argument. ^The
6113 ** incremental blob I/O routines can only read or overwriting existing
6114 ** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
6120 */
6121 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
6122
6123 /*
6124 ** CAPI3REF: Read Data From A BLOB Incrementally
6125 ** METHOD: sqlite3_blob
6126 **
6127 ** ^(This function is used to read data from an open [BLOB handle] into a
6128 ** caller-supplied buffer. N bytes of data are copied into buffer Z
6129 ** from the open BLOB, starting at offset iOffset.)^
6130 **
@@ -6084,10 +6149,11 @@
6149 */
6150 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
6151
6152 /*
6153 ** CAPI3REF: Write Data Into A BLOB Incrementally
6154 ** METHOD: sqlite3_blob
6155 **
6156 ** ^(This function is used to write data into an open [BLOB handle] from a
6157 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
6158 ** into the open BLOB, starting at offset iOffset.)^
6159 **
@@ -6411,10 +6477,11 @@
6477 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6478 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6479
6480 /*
6481 ** CAPI3REF: Retrieve the mutex for a database connection
6482 ** METHOD: sqlite3
6483 **
6484 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6485 ** serializes access to the [database connection] given in the argument
6486 ** when the [threading mode] is Serialized.
6487 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
6489 */
6490 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6491
6492 /*
6493 ** CAPI3REF: Low-Level Control Of Database Files
6494 ** METHOD: sqlite3
6495 **
6496 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6497 ** xFileControl method for the [sqlite3_io_methods] object associated
6498 ** with a particular database identified by the second argument. ^The
6499 ** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
6706 #define SQLITE_STATUS_SCRATCH_SIZE 8
6707 #define SQLITE_STATUS_MALLOC_COUNT 9
6708
6709 /*
6710 ** CAPI3REF: Database Connection Status
6711 ** METHOD: sqlite3
6712 **
6713 ** ^This interface is used to retrieve runtime status information
6714 ** about a single [database connection]. ^The first argument is the
6715 ** database connection object to be interrogated. ^The second argument
6716 ** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
6835 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6836
6837
6838 /*
6839 ** CAPI3REF: Prepared Statement Status
6840 ** METHOD: sqlite3_stmt
6841 **
6842 ** ^(Each prepared statement maintains various
6843 ** [SQLITE_STMTSTATUS counters] that measure the number
6844 ** of times it has performed specific operations.)^ These counters can
6845 ** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
7339 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7340 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7341
7342 /*
7343 ** CAPI3REF: Unlock Notification
7344 ** METHOD: sqlite3
7345 **
7346 ** ^When running in shared-cache mode, a database operation may fail with
7347 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7348 ** individual tables within the shared-cache cannot be obtained. See
7349 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
7510 */
7511 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7512
7513 /*
7514 ** CAPI3REF: Write-Ahead Log Commit Hook
7515 ** METHOD: sqlite3
7516 **
7517 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7518 ** is invoked each time data is committed to a database in wal mode.
7519 **
7520 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
7550 void*
7551 );
7552
7553 /*
7554 ** CAPI3REF: Configure an auto-checkpoint
7555 ** METHOD: sqlite3
7556 **
7557 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7558 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7559 ** to automatically [checkpoint]
7560 ** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
7581 */
7582 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7583
7584 /*
7585 ** CAPI3REF: Checkpoint a database
7586 ** METHOD: sqlite3
7587 **
7588 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7589 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7590 **
7591 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
7603 */
7604 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7605
7606 /*
7607 ** CAPI3REF: Checkpoint a database
7608 ** METHOD: sqlite3
7609 **
7610 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7611 ** operation on database X of [database connection] D in mode M. Status
7612 ** information is written back into integers pointed to by L and C.)^
7613 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
7858 #define SQLITE_SCANSTAT_EXPLAIN 4
7859 #define SQLITE_SCANSTAT_SELECTID 5
7860
7861 /*
7862 ** CAPI3REF: Prepared Statement Scan Status
7863 ** METHOD: sqlite3_stmt
7864 **
7865 ** This interface returns information about the predicted and measured
7866 ** performance for pStmt. Advanced applications can use this
7867 ** interface to compare the predicted and the measured performance and
7868 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
7896 void *pOut /* Result written here */
7897 );
7898
7899 /*
7900 ** CAPI3REF: Zero Scan-Status Counters
7901 ** METHOD: sqlite3_stmt
7902 **
7903 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7904 **
7905 ** This API is only available if the library is built with pre-processor
7906 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
8507 #else
8508 # define ALWAYS(X) (X)
8509 # define NEVER(X) (X)
8510 #endif
8511
8512 /*
8513 ** Declarations used for tracing the operating system interfaces.
8514 */
8515 #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
8516 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8517 extern int sqlite3OSTrace;
8518 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
8519 # define SQLITE_HAVE_OS_TRACE
8520 #else
8521 # define OSTRACE(X)
8522 # undef SQLITE_HAVE_OS_TRACE
8523 #endif
8524
8525 /*
8526 ** Is the sqlite3ErrName() function needed in the build? Currently,
8527 ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
8528 ** OSTRACE is enabled), and by several "test*.c" files (which are
8529 ** compiled using SQLITE_TEST).
8530 */
8531 #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \
8532 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8533 # define SQLITE_NEED_ERR_NAME
8534 #else
8535 # undef SQLITE_NEED_ERR_NAME
8536 #endif
8537
8538 /*
8539 ** Return true (non-zero) if the input is an integer that is too large
8540 ** to fit in 32-bits. This macro is used inside of various testcase()
8541 ** macros to verify that we have tested SQLite for large-file support.
8542 */
@@ -9841,37 +9944,36 @@
9944 /* Properties such as "out2" or "jump" that are specified in
9945 ** comments following the "case" for each opcode in the vdbe.c
9946 ** are encoded into bitvectors as follows:
9947 */
9948 #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9949 #define OPFLG_IN1 0x0002 /* in1: P1 is an input */
9950 #define OPFLG_IN2 0x0004 /* in2: P2 is an input */
9951 #define OPFLG_IN3 0x0008 /* in3: P3 is an input */
9952 #define OPFLG_OUT2 0x0010 /* out2: P2 is an output */
9953 #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
 
9954 #define OPFLG_INITIALIZER {\
9955 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9956 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
9957 /* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\
9958 /* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\
9959 /* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\
9960 /* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
9961 /* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\
9962 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\
9963 /* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\
9964 /* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
9965 /* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
9966 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
9967 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
9968 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
9969 /* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\
9970 /* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9971 /* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\
9972 /* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\
9973 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9974 /* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,}
9975
9976 /************** End of opcodes.h *********************************************/
9977 /************** Continuing where we left off in vdbe.h ***********************/
9978
9979 /*
@@ -9926,10 +10028,11 @@
10028 #endif
10029 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
10030
10031 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
10032 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
10033 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
10034 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
10035
10036 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
10037 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
10038
@@ -11063,10 +11166,11 @@
11166 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
11167 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
11168 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
11169 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
11170 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
11171 #define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
11172
11173
11174 /*
11175 ** Bits of the sqlite3.dbOptFlags field that are used by the
11176 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
11497 int iSavepoint; /* Depth of the SAVEPOINT stack */
11498 VTable *pNext; /* Next in linked list (see above) */
11499 };
11500
11501 /*
11502 ** The schema for each SQL table and view is represented in memory
11503 ** by an instance of the following structure.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11504 */
11505 struct Table {
11506 char *zName; /* Name of the table or view */
11507 Column *aCol; /* Information about each column */
11508 Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
11510 FKey *pFKey; /* Linked list of all foreign keys in this table */
11511 char *zColAff; /* String defining the affinity of each column */
11512 #ifndef SQLITE_OMIT_CHECK
11513 ExprList *pCheck; /* All CHECK constraints */
11514 #endif
11515 int tnum; /* Root BTree page for this table */
11516 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
 
11517 i16 nCol; /* Number of columns in this table */
11518 u16 nRef; /* Number of pointers to this Table */
11519 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11520 LogEst szTabRow; /* Estimated size of each table row in bytes */
11521 #ifdef SQLITE_ENABLE_COSTMULT
11522 LogEst costMult; /* Cost multiplier for using this table */
11523 #endif
11524 u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
11536 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
11537 };
11538
11539 /*
11540 ** Allowed values for Table.tabFlags.
11541 **
11542 ** TF_OOOHidden applies to virtual tables that have hidden columns that are
11543 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
11544 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
11545 ** the TF_OOOHidden attribute would apply in this case. Such tables require
11546 ** special handling during INSERT processing.
11547 */
11548 #define TF_Readonly 0x01 /* Read-only system table */
11549 #define TF_Ephemeral 0x02 /* An ephemeral table */
11550 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
11551 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
11552 #define TF_Virtual 0x10 /* Is a virtual table */
11553 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
11554 #define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */
11555
11556
11557 /*
11558 ** Test to see whether or not a table is a virtual table. This is
11559 ** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
12306 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12307 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12308 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12309 #define SF_Compound 0x0040 /* Part of a compound query */
12310 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12311 #define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */
12312 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12313 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12314 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12315 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12316 #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
12690 *
12691 * (op == TK_INSERT)
12692 * orconf -> stores the ON CONFLICT algorithm
12693 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
12694 * this stores a pointer to the SELECT statement. Otherwise NULL.
12695 * zTarget -> Dequoted name of the table to insert into.
12696 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
12697 * this stores values to be inserted. Otherwise NULL.
12698 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
12699 * statement, then this stores the column-names to be
12700 * inserted into.
12701 *
12702 * (op == TK_DELETE)
12703 * zTarget -> Dequoted name of the table to delete from.
12704 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
12705 * Otherwise NULL.
12706 *
12707 * (op == TK_UPDATE)
12708 * zTarget -> Dequoted name of the table to update.
12709 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
12710 * Otherwise NULL.
12711 * pExprList -> A list of the columns to update and the expressions to update
12712 * them to. See sqlite3Update() documentation of "pChanges"
12713 * argument.
@@ -12630,12 +12715,12 @@
12715 */
12716 struct TriggerStep {
12717 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
12718 u8 orconf; /* OE_Rollback etc. */
12719 Trigger *pTrig; /* The trigger that this step is a part of */
12720 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
12721 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
12722 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
12723 ExprList *pExprList; /* SET clause for UPDATE. */
12724 IdList *pIdList; /* Column names for INSERT */
12725 TriggerStep *pNext; /* Next in the link-list */
12726 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
12749 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
12750 char *zBase; /* A base allocation. Not from malloc. */
12751 char *zText; /* The string collected so far */
12752 int nChar; /* Length of the string so far */
12753 int nAlloc; /* Amount of space allocated in zText */
12754 int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
 
12755 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
12756 };
12757 #define STRACCUM_NOMEM 1
12758 #define STRACCUM_TOOBIG 2
12759
@@ -12982,11 +13066,11 @@
13066 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
13067 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
13068 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
13069 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
13070 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
13071 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
13072 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
13073 #endif
13074 #if defined(SQLITE_TEST)
13075 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
13076 #endif
@@ -13329,11 +13413,11 @@
13413 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
13414 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
13415 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
13416 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
13417
13418 #if defined(SQLITE_NEED_ERR_NAME)
13419 SQLITE_PRIVATE const char *sqlite3ErrName(int);
13420 #endif
13421
13422 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13423 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
13507 FuncDestructor *pDestructor
13508 );
13509 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
13510 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13511
13512 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
13513 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13514 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13515 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
13516 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13517 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -19807,20 +19891,10 @@
19891 */
19892 #ifdef MEMORY_DEBUG
19893 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19894 #endif
19895
 
 
 
 
 
 
 
 
 
 
19896 /*
19897 ** Macros for performance tracing. Normally turned off. Only works
19898 ** on i486 hardware.
19899 */
19900 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21475,11 @@
21475
21476 /*
21477 ** Set the StrAccum object to an error mode.
21478 */
21479 static void setStrAccumError(StrAccum *p, u8 eError){
21480 assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
21481 p->accError = eError;
21482 p->nAlloc = 0;
21483 }
21484
21485 /*
@@ -21515,11 +21590,10 @@
21590 case '0': flag_zeropad = 1; break;
21591 default: done = 1; break;
21592 }
21593 }while( !done && (c=(*++fmt))!=0 );
21594 /* Get the field width */
 
21595 if( c=='*' ){
21596 if( bArgList ){
21597 width = (int)getIntArg(pArgList);
21598 }else{
21599 width = va_arg(ap,int);
@@ -21539,11 +21613,10 @@
21613 width = wx & 0x7fffffff;
21614 }
21615
21616 /* Get the precision */
21617 if( c=='.' ){
 
21618 c = *++fmt;
21619 if( c=='*' ){
21620 if( bArgList ){
21621 precision = (int)getIntArg(pArgList);
21622 }else{
@@ -22018,11 +22091,11 @@
22091 if( p->accError ){
22092 testcase(p->accError==STRACCUM_TOOBIG);
22093 testcase(p->accError==STRACCUM_NOMEM);
22094 return 0;
22095 }
22096 if( p->mxAlloc==0 ){
22097 N = p->nAlloc - p->nChar - 1;
22098 setStrAccumError(p, STRACCUM_TOOBIG);
22099 return N;
22100 }else{
22101 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22111,14 @@
22111 setStrAccumError(p, STRACCUM_TOOBIG);
22112 return 0;
22113 }else{
22114 p->nAlloc = (int)szNew;
22115 }
22116 if( p->db ){
22117 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22118 }else{
22119 zNew = sqlite3_realloc64(zOld, p->nAlloc);
22120 }
22121 if( zNew ){
22122 assert( p->zText!=0 || p->nChar==0 );
22123 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
22124 p->zText = zNew;
@@ -22089,11 +22162,11 @@
22162 /*
22163 ** Append N bytes of text from z to the StrAccum object. Increase the
22164 ** size of the memory allocation for StrAccum if necessary.
22165 */
22166 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22167 assert( z!=0 || N==0 );
22168 assert( p->zText!=0 || p->nChar==0 || p->accError );
22169 assert( N>=0 );
22170 assert( p->accError==0 || p->nAlloc==0 );
22171 if( p->nChar+N >= p->nAlloc ){
22172 enlargeAndAppend(p,z,N);
@@ -22118,16 +22191,12 @@
22191 ** pointer if any kind of error was encountered.
22192 */
22193 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
22194 if( p->zText ){
22195 p->zText[p->nChar] = 0;
22196 if( p->mxAlloc>0 && p->zText==p->zBase ){
22197 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 
 
 
 
22198 if( p->zText ){
22199 memcpy(p->zText, p->zBase, p->nChar+1);
22200 }else{
22201 setStrAccumError(p, STRACCUM_NOMEM);
22202 }
@@ -22139,29 +22208,35 @@
22208 /*
22209 ** Reset an StrAccum string. Reclaim all malloced memory.
22210 */
22211 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
22212 if( p->zText!=p->zBase ){
22213 sqlite3DbFree(p->db, p->zText);
 
 
 
 
22214 }
22215 p->zText = 0;
22216 }
22217
22218 /*
22219 ** Initialize a string accumulator.
22220 **
22221 ** p: The accumulator to be initialized.
22222 ** db: Pointer to a database connection. May be NULL. Lookaside
22223 ** memory is used if not NULL. db->mallocFailed is set appropriately
22224 ** when not NULL.
22225 ** zBase: An initial buffer. May be NULL in which case the initial buffer
22226 ** is malloced.
22227 ** n: Size of zBase in bytes. If total space requirements never exceed
22228 ** n then no memory allocations ever occur.
22229 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
22230 ** allocations will ever occur.
22231 */
22232 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
22233 p->zText = p->zBase = zBase;
22234 p->db = db;
22235 p->nChar = 0;
22236 p->nAlloc = n;
22237 p->mxAlloc = mx;
 
22238 p->accError = 0;
22239 }
22240
22241 /*
22242 ** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22245,12 @@
22245 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
22246 char *z;
22247 char zBase[SQLITE_PRINT_BUF_SIZE];
22248 StrAccum acc;
22249 assert( db!=0 );
22250 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
22251 db->aLimit[SQLITE_LIMIT_LENGTH]);
 
22252 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
22253 z = sqlite3StrAccumFinish(&acc);
22254 if( acc.accError==STRACCUM_NOMEM ){
22255 db->mallocFailed = 1;
22256 }
@@ -22230,12 +22304,11 @@
22304 }
22305 #endif
22306 #ifndef SQLITE_OMIT_AUTOINIT
22307 if( sqlite3_initialize() ) return 0;
22308 #endif
22309 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
 
22310 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22311 z = sqlite3StrAccumFinish(&acc);
22312 return z;
22313 }
22314
@@ -22276,12 +22349,11 @@
22349 (void)SQLITE_MISUSE_BKPT;
22350 if( zBuf ) zBuf[0] = 0;
22351 return zBuf;
22352 }
22353 #endif
22354 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
 
22355 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22356 return sqlite3StrAccumFinish(&acc);
22357 }
22358 SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
22359 char *z;
@@ -22303,12 +22375,11 @@
22375 */
22376 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22377 StrAccum acc; /* String accumulator */
22378 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22379
22380 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
 
22381 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22382 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
22383 sqlite3StrAccumFinish(&acc));
22384 }
22385
@@ -22322,22 +22393,21 @@
22393 renderLogMsg(iErrCode, zFormat, ap);
22394 va_end(ap);
22395 }
22396 }
22397
22398 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
22399 /*
22400 ** A version of printf() that understands %lld. Used for debugging.
22401 ** The printf() built into some versions of windows does not understand %lld
22402 ** and segfaults if you give it a long long int.
22403 */
22404 SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
22405 va_list ap;
22406 StrAccum acc;
22407 char zBuf[500];
22408 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
 
22409 va_start(ap,zFormat);
22410 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22411 va_end(ap);
22412 sqlite3StrAccumFinish(&acc);
22413 fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22430,11 @@
22430 */
22431 /* Add a new subitem to the tree. The moreToFollow flag indicates that this
22432 ** is not the last item in the tree. */
22433 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
22434 if( p==0 ){
22435 p = sqlite3_malloc64( sizeof(*p) );
22436 if( p==0 ) return 0;
22437 memset(p, 0, sizeof(*p));
22438 }else{
22439 p->iLevel++;
22440 }
@@ -22383,12 +22453,11 @@
22453 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
22454 va_list ap;
22455 int i;
22456 StrAccum acc;
22457 char zBuf[500];
22458 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
 
22459 if( p ){
22460 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
22461 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
22462 }
22463 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24076,11 @@
24076 }else{
24077 return 0;
24078 }
24079 }
24080 #endif
24081 while( zNum[0]=='0' ) zNum++;
24082 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
24083 v = v*10 + c;
24084 }
24085
24086 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25331,21 @@
25331 #if SQLITE_ENABLE_LOCKING_STYLE
25332 # include <sys/ioctl.h>
25333 # include <sys/file.h>
25334 # include <sys/param.h>
25335 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
25336
25337 #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
25338 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
25339 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
25340 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
25341 # define HAVE_GETHOSTUUID 1
25342 # else
25343 # warning "gethostuuid() is disabled."
25344 # endif
25345 #endif
25346
25347
25348 #if OS_VXWORKS
25349 /* # include <sys/ioctl.h> */
25350 # include <semaphore.h>
25351 # include <limits.h>
@@ -25457,20 +25538,10 @@
25538 */
25539 #ifdef MEMORY_DEBUG
25540 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
25541 #endif
25542
 
 
 
 
 
 
 
 
 
 
25543 /*
25544 ** Macros for performance tracing. Normally turned off. Only works
25545 ** on i486 hardware.
25546 */
25547 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26080,11 @@
26080 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26081 }
26082 #endif
26083
26084
26085 #ifdef SQLITE_HAVE_OS_TRACE
26086 /*
26087 ** Helper function for printing out trace information from debugging
26088 ** binaries. This returns the string representation of the supplied
26089 ** integer lock-type.
26090 */
@@ -26272,11 +26343,11 @@
26343 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
26344 int n; /* Length of zAbsoluteName string */
26345
26346 assert( zAbsoluteName[0]=='/' );
26347 n = (int)strlen(zAbsoluteName);
26348 pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) );
26349 if( pNew==0 ) return 0;
26350 pNew->zCanonicalName = (char*)&pNew[1];
26351 memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
26352 n = vxworksSimplifyName(pNew->zCanonicalName, n);
26353
@@ -26676,11 +26747,11 @@
26747 pInode = inodeList;
26748 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
26749 pInode = pInode->pNext;
26750 }
26751 if( pInode==0 ){
26752 pInode = sqlite3_malloc64( sizeof(*pInode) );
26753 if( pInode==0 ){
26754 return SQLITE_NOMEM;
26755 }
26756 memset(pInode, 0, sizeof(*pInode));
26757 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29268,11 @@
29268 case SQLITE_FCNTL_VFSNAME: {
29269 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
29270 return SQLITE_OK;
29271 }
29272 case SQLITE_FCNTL_TEMPFILENAME: {
29273 char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
29274 if( zTFile ){
29275 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
29276 *(char**)pArg = zTFile;
29277 }
29278 return SQLITE_OK;
@@ -29638,11 +29709,11 @@
29709 unixInodeInfo *pInode; /* The inode of fd */
29710 char *zShmFilename; /* Name of the file used for SHM */
29711 int nShmFilename; /* Size of the SHM filename in bytes */
29712
29713 /* Allocate space for the new unixShm object. */
29714 p = sqlite3_malloc64( sizeof(*p) );
29715 if( p==0 ) return SQLITE_NOMEM;
29716 memset(p, 0, sizeof(*p));
29717 assert( pDbFd->pShm==0 );
29718
29719 /* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29740,11 @@
29740 #ifdef SQLITE_SHM_DIRECTORY
29741 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29742 #else
29743 nShmFilename = 6 + (int)strlen(zBasePath);
29744 #endif
29745 pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
29746 if( pShmNode==0 ){
29747 rc = SQLITE_NOMEM;
29748 goto shm_open_err;
29749 }
29750 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29950,11 @@
29950 if( pMem==MAP_FAILED ){
29951 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
29952 goto shmpage_out;
29953 }
29954 }else{
29955 pMem = sqlite3_malloc64(szRegion);
29956 if( pMem==0 ){
29957 rc = SQLITE_NOMEM;
29958 goto shmpage_out;
29959 }
29960 memset(pMem, 0, szRegion);
@@ -30716,11 +30787,11 @@
30787 else if( pLockingStyle == &afpIoMethods ){
30788 /* AFP locking uses the file path so it needs to be included in
30789 ** the afpLockingContext.
30790 */
30791 afpLockingContext *pCtx;
30792 pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
30793 if( pCtx==0 ){
30794 rc = SQLITE_NOMEM;
30795 }else{
30796 /* NB: zFilename exists and remains valid until the file is closed
30797 ** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30817,11 @@
30817 */
30818 char *zLockFile;
30819 int nFilename;
30820 assert( zFilename!=0 );
30821 nFilename = (int)strlen(zFilename) + 6;
30822 zLockFile = (char *)sqlite3_malloc64(nFilename);
30823 if( zLockFile==0 ){
30824 rc = SQLITE_NOMEM;
30825 }else{
30826 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
30827 }
@@ -31123,11 +31194,11 @@
31194 UnixUnusedFd *pUnused;
31195 pUnused = findReusableFd(zName, flags);
31196 if( pUnused ){
31197 fd = pUnused->fd;
31198 }else{
31199 pUnused = sqlite3_malloc64(sizeof(*pUnused));
31200 if( !pUnused ){
31201 return SQLITE_NOMEM;
31202 }
31203 }
31204 p->pUnused = pUnused;
@@ -31503,11 +31574,11 @@
31574 ** that we always use the same random number sequence. This makes the
31575 ** tests repeatable.
31576 */
31577 memset(zBuf, 0, nBuf);
31578 randomnessPid = osGetpid(0);
31579 #if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
31580 {
31581 int fd, got;
31582 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31583 if( fd<0 ){
31584 time_t t;
@@ -31915,11 +31986,11 @@
31986 */
31987 pUnused = findReusableFd(path, openFlags);
31988 if( pUnused ){
31989 fd = pUnused->fd;
31990 }else{
31991 pUnused = sqlite3_malloc64(sizeof(*pUnused));
31992 if( !pUnused ){
31993 return SQLITE_NOMEM;
31994 }
31995 }
31996 if( fd<0 ){
@@ -31948,11 +32019,11 @@
32019 default:
32020 return SQLITE_CANTOPEN_BKPT;
32021 }
32022 }
32023
32024 pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
32025 if( pNew==NULL ){
32026 rc = SQLITE_NOMEM;
32027 goto end_create_proxy;
32028 }
32029 memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32052,22 @@
32052 SQLITE_API int sqlite3_hostid_num = 0;
32053 #endif
32054
32055 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
32056
32057 #ifdef HAVE_GETHOSTUUID
32058 /* Not always defined in the headers as it ought to be */
32059 extern int gethostuuid(uuid_t id, const struct timespec *wait);
32060 #endif
32061
32062 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
32063 ** bytes of writable memory.
32064 */
32065 static int proxyGetHostID(unsigned char *pHostID, int *pError){
32066 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
32067 memset(pHostID, 0, PROXY_HOSTIDLEN);
32068 #ifdef HAVE_GETHOSTUUID
 
32069 {
32070 struct timespec timeout = {1, 0}; /* 1 sec timeout */
32071 if( gethostuuid(pHostID, &timeout) ){
32072 int err = errno;
32073 if( pError ){
@@ -32409,11 +32481,11 @@
32481 return rc;
32482 }
32483
32484 /*
32485 ** Given the name of a database file, compute the name of its conch file.
32486 ** Store the conch filename in memory obtained from sqlite3_malloc64().
32487 ** Make *pConchPath point to the new name. Return SQLITE_OK on success
32488 ** or SQLITE_NOMEM if unable to obtain memory.
32489 **
32490 ** The caller is responsible for ensuring that the allocated memory
32491 ** space is eventually freed.
@@ -32425,11 +32497,11 @@
32497 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
32498 char *conchPath; /* buffer in which to construct conch name */
32499
32500 /* Allocate space for the conch filename and initialize the name to
32501 ** the name of the original database file. */
32502 *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
32503 if( conchPath==0 ){
32504 return SQLITE_NOMEM;
32505 }
32506 memcpy(conchPath, dbPath, len+1);
32507
@@ -32541,11 +32613,11 @@
32613 }
32614
32615 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32616 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
32617
32618 pCtx = sqlite3_malloc64( sizeof(*pCtx) );
32619 if( pCtx==0 ){
32620 return SQLITE_NOMEM;
32621 }
32622 memset(pCtx, 0, sizeof(*pCtx));
32623
@@ -32985,20 +33057,10 @@
33057 */
33058 #ifdef MEMORY_DEBUG
33059 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
33060 #endif
33061
 
 
 
 
 
 
 
 
 
 
33062 /*
33063 ** Macros for performance tracing. Normally turned off. Only works
33064 ** on i486 hardware.
33065 */
33066 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35960,11 @@
35960 ** Used only when SQLITE_NO_SYNC is not defined.
35961 */
35962 BOOL rc;
35963 #endif
35964 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35965 defined(SQLITE_HAVE_OS_TRACE)
35966 /*
35967 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
35968 ** OSTRACE() macros.
35969 */
35970 winFile *pFile = (winFile*)id;
@@ -36575,11 +36637,11 @@
36637 DWORD lastErrno; /* The Windows errno from the last I/O error */
36638
36639 int nRef; /* Number of winShm objects pointing to this */
36640 winShm *pFirst; /* All winShm objects pointing to this */
36641 winShmNode *pNext; /* Next in list of all winShmNode objects */
36642 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36643 u8 nextShmId; /* Next available winShm.id value */
36644 #endif
36645 };
36646
36647 /*
@@ -36606,11 +36668,11 @@
36668 winShmNode *pShmNode; /* The underlying winShmNode object */
36669 winShm *pNext; /* Next winShm with the same winShmNode */
36670 u8 hasMutex; /* True if holding the winShmNode mutex */
36671 u16 sharedMask; /* Mask of shared locks held */
36672 u16 exclMask; /* Mask of exclusive locks held */
36673 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36674 u8 id; /* Id of this connection with its winShmNode */
36675 #endif
36676 };
36677
36678 /*
@@ -36797,11 +36859,11 @@
36859 if( rc ) goto shm_open_err;
36860 }
36861
36862 /* Make the new connection a child of the winShmNode */
36863 p->pShmNode = pShmNode;
36864 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36865 p->id = pShmNode->nextShmId++;
36866 #endif
36867 pShmNode->nRef++;
36868 pDbFd->pShm = p;
36869 winShmLeaveMutex();
@@ -37066,11 +37128,11 @@
37128 goto shmpage_out;
37129 }
37130 }
37131
37132 /* Map the requested memory region into this processes address space. */
37133 apNew = (struct ShmRegion *)sqlite3_realloc64(
37134 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
37135 );
37136 if( !apNew ){
37137 rc = SQLITE_IOERR_NOMEM;
37138 goto shmpage_out;
@@ -38513,11 +38575,11 @@
38575 ** Write up to nBuf bytes of randomness into zBuf.
38576 */
38577 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
38578 int n = 0;
38579 UNUSED_PARAMETER(pVfs);
38580 #if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
38581 n = nBuf;
38582 memset(zBuf, 0, nBuf);
38583 #else
38584 if( sizeof(SYSTEMTIME)<=nBuf-n ){
38585 SYSTEMTIME x;
@@ -38547,11 +38609,10 @@
38609 LARGE_INTEGER i;
38610 osQueryPerformanceCounter(&i);
38611 memcpy(&zBuf[n], &i, sizeof(i));
38612 n += sizeof(i);
38613 }
 
38614 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38615 if( sizeof(UUID)<=nBuf-n ){
38616 UUID id;
38617 memset(&id, 0, sizeof(UUID));
38618 osUuidCreate(&id);
@@ -38564,10 +38625,11 @@
38625 osUuidCreateSequential(&id);
38626 memcpy(zBuf, &id, sizeof(UUID));
38627 n += sizeof(UUID);
38628 }
38629 #endif
38630 #endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
38631 return n;
38632 }
38633
38634
38635 /*
@@ -39118,11 +39180,11 @@
39180
39181 /* Allocate the Bitvec to be tested and a linear array of
39182 ** bits to act as the reference */
39183 pBitvec = sqlite3BitvecCreate( sz );
39184 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39185 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
39186 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
39187
39188 /* NULL pBitvec tests */
39189 sqlite3BitvecSet(0, 1);
39190 sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44669,11 @@
44669 Pgno nTruncate, /* Database size after this commit */
44670 int isCommit /* True if this is a commit */
44671 ){
44672 int rc; /* Return code */
44673 int nList; /* Number of pages in pList */
 
44674 PgHdr *p; /* For looping over pages */
 
44675
44676 assert( pPager->pWal );
44677 assert( pList );
44678 #ifdef SQLITE_DEBUG
44679 /* Verify that the page list is in accending order */
@@ -44626,11 +44686,10 @@
44686 if( isCommit ){
44687 /* If a WAL transaction is being committed, there is no point in writing
44688 ** any pages with page numbers greater than nTruncate into the WAL file.
44689 ** They will never be read by any client. So remove them from the pDirty
44690 ** list here. */
 
44691 PgHdr **ppNext = &pList;
44692 nList = 0;
44693 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
44694 if( p->pgno<=nTruncate ){
44695 ppNext = &p->pDirty;
@@ -44646,11 +44705,10 @@
44705 if( pList->pgno==1 ) pager_write_changecounter(pList);
44706 rc = sqlite3WalFrames(pPager->pWal,
44707 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
44708 );
44709 if( rc==SQLITE_OK && pPager->pBackup ){
 
44710 for(p=pList; p; p=p->pDirty){
44711 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
44712 }
44713 }
44714
@@ -48577,10 +48635,12 @@
48635 }else if( state==PAGER_OPEN ){
48636 pager_unlock(pPager);
48637 }
48638 assert( state==pPager->eState );
48639 }
48640 }else if( eMode==PAGER_JOURNALMODE_OFF ){
48641 sqlite3OsClose(pPager->jfd);
48642 }
48643 }
48644
48645 /* Return the new journal mode */
48646 return (int)pPager->journalMode;
@@ -49359,11 +49419,11 @@
49419
49420 /* Enlarge the pWal->apWiData[] array if required */
49421 if( pWal->nWiData<=iPage ){
49422 int nByte = sizeof(u32*)*(iPage+1);
49423 volatile u32 **apNew;
49424 apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
49425 if( !apNew ){
49426 *ppPage = 0;
49427 return SQLITE_NOMEM;
49428 }
49429 memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50044,11 @@
50044 goto finished;
50045 }
50046
50047 /* Malloc a buffer to read frames into. */
50048 szFrame = szPage + WAL_FRAME_HDRSIZE;
50049 aFrame = (u8 *)sqlite3_malloc64(szFrame);
50050 if( !aFrame ){
50051 rc = SQLITE_NOMEM;
50052 goto recovery_error;
50053 }
50054 aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50437,21 @@
50437 /* Allocate space for the WalIterator object. */
50438 nSegment = walFramePage(iLast) + 1;
50439 nByte = sizeof(WalIterator)
50440 + (nSegment-1)*sizeof(struct WalSegment)
50441 + iLast*sizeof(ht_slot);
50442 p = (WalIterator *)sqlite3_malloc64(nByte);
50443 if( !p ){
50444 return SQLITE_NOMEM;
50445 }
50446 memset(p, 0, nByte);
50447 p->nSegment = nSegment;
50448
50449 /* Allocate temporary space used by the merge-sort routine. This block
50450 ** of memory will be freed before this function returns.
50451 */
50452 aTmp = (ht_slot *)sqlite3_malloc64(
50453 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
50454 );
50455 if( !aTmp ){
50456 rc = SQLITE_NOMEM;
50457 }
@@ -50567,10 +50627,18 @@
50627 ** cannot be backfilled from the WAL.
50628 */
50629 mxSafeFrame = pWal->hdr.mxFrame;
50630 mxPage = pWal->hdr.nPage;
50631 for(i=1; i<WAL_NREADER; i++){
50632 /* Thread-sanitizer reports that the following is an unsafe read,
50633 ** as some other thread may be in the process of updating the value
50634 ** of the aReadMark[] slot. The assumption here is that if that is
50635 ** happening, the other client may only be increasing the value,
50636 ** not decreasing it. So assuming either that either the "old" or
50637 ** "new" version of the value is read, and not some arbitrary value
50638 ** that would never be written by a real client, things are still
50639 ** safe. */
50640 u32 y = pInfo->aReadMark[i];
50641 if( mxSafeFrame>y ){
50642 assert( y<=pWal->hdr.mxFrame );
50643 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
50644 if( rc==SQLITE_OK ){
@@ -55407,11 +55475,11 @@
55475 }
55476 assert( nReserve>=0 && nReserve<=255 );
55477 if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
55478 ((pageSize-1)&pageSize)==0 ){
55479 assert( (pageSize & 7)==0 );
55480 assert( !pBt->pCursor );
55481 pBt->pageSize = (u32)pageSize;
55482 freeTempSpace(pBt);
55483 }
55484 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
55485 pBt->usableSize = pBt->pageSize - (u16)nReserve;
@@ -57429,17 +57497,22 @@
57497 */
57498 static const void *fetchPayload(
57499 BtCursor *pCur, /* Cursor pointing to entry to read from */
57500 u32 *pAmt /* Write the number of available bytes here */
57501 ){
57502 u32 amt;
57503 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
57504 assert( pCur->eState==CURSOR_VALID );
57505 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57506 assert( cursorHoldsMutex(pCur) );
57507 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57508 assert( pCur->info.nSize>0 );
57509 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
57510 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
57511 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
57512 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
57513 *pAmt = amt;
57514 return (void*)pCur->info.pPayload;
57515 }
57516
57517
57518 /*
@@ -59713,11 +59786,10 @@
59786 if( iParentIdx==0 ){
59787 nxDiv = 0;
59788 }else if( iParentIdx==i ){
59789 nxDiv = i-2+bBulk;
59790 }else{
 
59791 nxDiv = iParentIdx-1;
59792 }
59793 i = 2-bBulk;
59794 }
59795 nOld = i+1;
@@ -61501,10 +61573,61 @@
61573 iPage = get4byte(pOvflData);
61574 sqlite3PagerUnref(pOvflPage);
61575 }
61576 }
61577 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
61578
61579 /*
61580 ** An implementation of a min-heap.
61581 **
61582 ** aHeap[0] is the number of elements on the heap. aHeap[1] is the
61583 ** root element. The daughter nodes of aHeap[N] are aHeap[N*2]
61584 ** and aHeap[N*2+1].
61585 **
61586 ** The heap property is this: Every node is less than or equal to both
61587 ** of its daughter nodes. A consequence of the heap property is that the
61588 ** root node aHeap[1] is always the minimum value currently in the heap.
61589 **
61590 ** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
61591 ** the heap, preserving the heap property. The btreeHeapPull() routine
61592 ** removes the root element from the heap (the minimum value in the heap)
61593 ** and then moves other nodes around as necessary to preserve the heap
61594 ** property.
61595 **
61596 ** This heap is used for cell overlap and coverage testing. Each u32
61597 ** entry represents the span of a cell or freeblock on a btree page.
61598 ** The upper 16 bits are the index of the first byte of a range and the
61599 ** lower 16 bits are the index of the last byte of that range.
61600 */
61601 static void btreeHeapInsert(u32 *aHeap, u32 x){
61602 u32 j, i = ++aHeap[0];
61603 aHeap[i] = x;
61604 while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
61605 x = aHeap[j];
61606 aHeap[j] = aHeap[i];
61607 aHeap[i] = x;
61608 i = j;
61609 }
61610 }
61611 static int btreeHeapPull(u32 *aHeap, u32 *pOut){
61612 u32 j, i, x;
61613 if( (x = aHeap[0])==0 ) return 0;
61614 *pOut = aHeap[1];
61615 aHeap[1] = aHeap[x];
61616 aHeap[x] = 0xffffffff;
61617 aHeap[0]--;
61618 i = 1;
61619 while( (j = i*2)<=aHeap[0] ){
61620 if( aHeap[j]>aHeap[j+1] ) j++;
61621 if( aHeap[i]<aHeap[j] ) break;
61622 x = aHeap[i];
61623 aHeap[i] = aHeap[j];
61624 aHeap[j] = x;
61625 i = j;
61626 }
61627 return 1;
61628 }
61629
61630 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
61631 /*
61632 ** Do various sanity checks on a single page of a tree. Return
61633 ** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61657,12 @@
61657 int hdr, cellStart;
61658 int nCell;
61659 u8 *data;
61660 BtShared *pBt;
61661 int usableSize;
61662 u32 *heap = 0;
61663 u32 x, prev = 0;
61664 i64 nMinKey = 0;
61665 i64 nMaxKey = 0;
61666 const char *saved_zPfx = pCheck->zPfx;
61667 int saved_v1 = pCheck->v1;
61668 int saved_v2 = pCheck->v2;
@@ -61679,19 +61803,19 @@
61803
61804 /* Check for complete coverage of the page
61805 */
61806 data = pPage->aData;
61807 hdr = pPage->hdrOffset;
61808 heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
61809 pCheck->zPfx = 0;
61810 if( heap==0 ){
61811 pCheck->mallocFailed = 1;
61812 }else{
61813 int contentOffset = get2byteNotZero(&data[hdr+5]);
61814 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61815 heap[0] = 0;
61816 btreeHeapInsert(heap, contentOffset-1);
61817 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61818 ** number of cells on the page. */
61819 nCell = get2byte(&data[hdr+3]);
61820 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61821 ** immediately follows the b-tree page header. */
@@ -61699,20 +61823,19 @@
61823 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61824 ** integer offsets to the cell contents. */
61825 for(i=0; i<nCell; i++){
61826 int pc = get2byte(&data[cellStart+i*2]);
61827 u32 size = 65536;
 
61828 if( pc<=usableSize-4 ){
61829 size = cellSizePtr(pPage, &data[pc]);
61830 }
61831 if( (int)(pc+size-1)>=usableSize ){
61832 pCheck->zPfx = 0;
61833 checkAppendMsg(pCheck,
61834 "Corruption detected in cell %d on page %d",i,iPage);
61835 }else{
61836 btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
61837 }
61838 }
61839 /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61840 ** is the offset of the first freeblock, or zero if there are no
61841 ** freeblocks on the page. */
@@ -61720,11 +61843,11 @@
61843 while( i>0 ){
61844 int size, j;
61845 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
61846 size = get2byte(&data[i+2]);
61847 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61848 btreeHeapInsert(heap, (i<<16)|(i+size-1));
61849 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61850 ** big-endian integer which is the offset in the b-tree page of the next
61851 ** freeblock in the chain, or zero if the freeblock is the last on the
61852 ** chain. */
61853 j = get2byte(&data[i]);
@@ -61732,31 +61855,37 @@
61855 ** increasing offset. */
61856 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
61857 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
61858 i = j;
61859 }
61860 cnt = 0;
61861 assert( heap[0]>0 );
61862 assert( (heap[1]>>16)==0 );
61863 btreeHeapPull(heap,&prev);
61864 while( btreeHeapPull(heap,&x) ){
61865 if( (prev&0xffff)+1>(x>>16) ){
61866 checkAppendMsg(pCheck,
61867 "Multiple uses for byte %u of page %d", x>>16, iPage);
61868 break;
61869 }else{
61870 cnt += (x>>16) - (prev&0xffff) - 1;
61871 prev = x;
61872 }
61873 }
61874 cnt += usableSize - (prev&0xffff) - 1;
61875 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61876 ** is stored in the fifth field of the b-tree page header.
61877 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61878 ** number of fragmented free bytes within the cell content area.
61879 */
61880 if( heap[0]==0 && cnt!=data[hdr+7] ){
61881 checkAppendMsg(pCheck,
61882 "Fragmentation of %d bytes reported as %d on page %d",
61883 cnt, data[hdr+7], iPage);
61884 }
61885 }
61886 sqlite3PageFree(heap);
61887 releasePage(pPage);
61888
61889 end_of_check:
61890 pCheck->zPfx = saved_zPfx;
61891 pCheck->v1 = saved_v1;
@@ -61816,12 +61945,11 @@
61945 sqlite3BtreeLeave(p);
61946 return 0;
61947 }
61948 i = PENDING_BYTE_PAGE(pBt);
61949 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61950 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
 
61951
61952 /* Check the integrity of the freelist
61953 */
61954 sCheck.zPfx = "Main freelist: ";
61955 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63281,15 @@
63281 return SQLITE_NOMEM;
63282 }
63283 pMem->z[pMem->n] = 0;
63284 pMem->z[pMem->n+1] = 0;
63285 pMem->flags |= MEM_Term;
63286 }
63287 pMem->flags &= ~MEM_Ephem;
63288 #ifdef SQLITE_DEBUG
63289 pMem->pScopyFrom = 0;
63290 #endif
 
63291
63292 return SQLITE_OK;
63293 }
63294
63295 /*
@@ -64600,11 +64729,11 @@
64729 int i;
64730 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
64731 Mem *aMem = pRec->aMem;
64732 sqlite3 *db = aMem[0].db;
64733 for(i=0; i<nCol; i++){
64734 sqlite3VdbeMemRelease(&aMem[i]);
64735 }
64736 sqlite3KeyInfoUnref(pRec->pKeyInfo);
64737 sqlite3DbFree(db, pRec);
64738 }
64739 }
@@ -66436,18 +66565,35 @@
66565 pVtabCursor->pVtab->nRef--;
66566 pModule->xClose(pVtabCursor);
66567 }
66568 #endif
66569 }
66570
66571 /*
66572 ** Close all cursors in the current frame.
66573 */
66574 static void closeCursorsInFrame(Vdbe *p){
66575 if( p->apCsr ){
66576 int i;
66577 for(i=0; i<p->nCursor; i++){
66578 VdbeCursor *pC = p->apCsr[i];
66579 if( pC ){
66580 sqlite3VdbeFreeCursor(p, pC);
66581 p->apCsr[i] = 0;
66582 }
66583 }
66584 }
66585 }
66586
66587 /*
66588 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
66589 ** is used, for example, when a trigger sub-program is halted to restore
66590 ** control to the main program.
66591 */
66592 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
66593 Vdbe *v = pFrame->v;
66594 closeCursorsInFrame(v);
66595 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66596 v->anExec = pFrame->anExec;
66597 #endif
66598 v->aOnceFlag = pFrame->aOnceFlag;
66599 v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66624,11 @@
66624 sqlite3VdbeFrameRestore(pFrame);
66625 p->pFrame = 0;
66626 p->nFrame = 0;
66627 }
66628 assert( p->nFrame==0 );
66629 closeCursorsInFrame(p);
 
 
 
 
 
 
 
 
 
 
66630 if( p->aMem ){
66631 releaseMemArray(&p->aMem[1], p->nMem);
66632 }
66633 while( p->pDelFrame ){
66634 VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68369,11 @@
68369 ** If database corruption is discovered, set pPKey2->errCode to
68370 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
68371 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
68372 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
68373 */
68374 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
68375 int nKey1, const void *pKey1, /* Left key */
68376 UnpackedRecord *pPKey2, /* Right key */
68377 int bSkip /* If true, skip the first field */
68378 ){
68379 u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68555,11 @@
68555 }
68556 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
68557 int nKey1, const void *pKey1, /* Left key */
68558 UnpackedRecord *pPKey2 /* Right key */
68559 ){
68560 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68561 }
68562
68563
68564 /*
68565 ** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68643,11 @@
68643 }else if( v<lhs ){
68644 res = pPKey2->r2;
68645 }else if( pPKey2->nField>1 ){
68646 /* The first fields of the two keys are equal. Compare the trailing
68647 ** fields. */
68648 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68649 }else{
68650 /* The first fields of the two keys are equal and there are no trailing
68651 ** fields. Return pPKey2->default_rc in this case. */
68652 res = pPKey2->default_rc;
68653 }
@@ -68555,11 +68691,11 @@
68691
68692 if( res==0 ){
68693 res = nStr - pPKey2->aMem[0].n;
68694 if( res==0 ){
68695 if( pPKey2->nField>1 ){
68696 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68697 }else{
68698 res = pPKey2->default_rc;
68699 }
68700 }else if( res>0 ){
68701 res = pPKey2->r2;
@@ -70497,21 +70633,22 @@
70633 Mem *pVar; /* Value of a host parameter */
70634 StrAccum out; /* Accumulate the output here */
70635 char zBase[100]; /* Initial working space */
70636
70637 db = p->db;
70638 sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
70639 db->aLimit[SQLITE_LIMIT_LENGTH]);
 
70640 if( db->nVdbeExec>1 ){
70641 while( *zRawSql ){
70642 const char *zStart = zRawSql;
70643 while( *(zRawSql++)!='\n' && *zRawSql );
70644 sqlite3StrAccumAppend(&out, "-- ", 3);
70645 assert( (zRawSql - zStart) > 0 );
70646 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
70647 }
70648 }else if( p->nVar==0 ){
70649 sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
70650 }else{
70651 while( zRawSql[0] ){
70652 n = findNextHostParameter(zRawSql, &nToken);
70653 assert( n>0 );
70654 sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70661,16 @@
70661 sqlite3GetInt32(&zRawSql[1], &idx);
70662 }else{
70663 idx = nextIndex;
70664 }
70665 }else{
70666 assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
70667 zRawSql[0]=='@' || zRawSql[0]=='#' );
70668 testcase( zRawSql[0]==':' );
70669 testcase( zRawSql[0]=='$' );
70670 testcase( zRawSql[0]=='@' );
70671 testcase( zRawSql[0]=='#' );
70672 idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
70673 assert( idx>0 );
70674 }
70675 zRawSql += nToken;
70676 nextIndex = idx + 1;
@@ -71202,21 +71341,38 @@
71341 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
71342 return 1;
71343 }
71344 #endif
71345
71346 /*
71347 ** Return the register of pOp->p2 after first preparing it to be
71348 ** overwritten with an integer value.
71349 */
71350 static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
71351 Mem *pOut;
71352 assert( pOp->p2>0 );
71353 assert( pOp->p2<=(p->nMem-p->nCursor) );
71354 pOut = &p->aMem[pOp->p2];
71355 memAboutToChange(p, pOut);
71356 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71357 pOut->flags = MEM_Int;
71358 return pOut;
71359 }
71360
71361
71362 /*
71363 ** Execute as much of a VDBE program as we can.
71364 ** This is the core of sqlite3_step().
71365 */
71366 SQLITE_PRIVATE int sqlite3VdbeExec(
71367 Vdbe *p /* The VDBE */
71368 ){
 
71369 Op *aOp = p->aOp; /* Copy of p->aOp */
71370 Op *pOp = aOp; /* Current operation */
71371 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71372 Op *pOrigOp; /* Value of pOp at the top of the loop */
71373 #endif
71374 int rc = SQLITE_OK; /* Value to return */
71375 sqlite3 *db = p->db; /* The database */
71376 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
71377 u8 encoding = ENC(db); /* The database encoding */
71378 int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71444,26 @@
71444 }
71445 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
71446 }
71447 sqlite3EndBenignMalloc();
71448 #endif
71449 for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){
71450 assert( pOp>=aOp && pOp<&aOp[p->nOp]);
71451 if( db->mallocFailed ) goto no_mem;
71452 #ifdef VDBE_PROFILE
71453 start = sqlite3Hwtime();
71454 #endif
71455 nVmStep++;
 
71456 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71457 if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
71458 #endif
71459
71460 /* Only allow tracing if SQLITE_DEBUG is defined.
71461 */
71462 #ifdef SQLITE_DEBUG
71463 if( db->flags & SQLITE_VdbeTrace ){
71464 sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
71465 }
71466 #endif
71467
71468
71469 /* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71476,13 @@
71476 sqlite3_interrupt(db);
71477 }
71478 }
71479 #endif
71480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71481 /* Sanity checking on other operands */
71482 #ifdef SQLITE_DEBUG
71483 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71484 if( (pOp->opflags & OPFLG_IN1)!=0 ){
71485 assert( pOp->p1>0 );
71486 assert( pOp->p1<=(p->nMem-p->nCursor) );
71487 assert( memIsValid(&aMem[pOp->p1]) );
71488 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71511,13 @@
71511 assert( pOp->p3>0 );
71512 assert( pOp->p3<=(p->nMem-p->nCursor) );
71513 memAboutToChange(p, &aMem[pOp->p3]);
71514 }
71515 #endif
71516 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71517 pOrigOp = pOp;
71518 #endif
71519
71520 switch( pOp->opcode ){
71521
71522 /*****************************************************************************
71523 ** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71537,11 @@
71537 ** case statement is followed by a comment of the form "/# same as ... #/"
71538 ** that comment is used to determine the particular value of the opcode.
71539 **
71540 ** Other keywords in the comment that follows each case are used to
71541 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71542 ** Keywords include: in1, in2, in3, out2, out3. See
71543 ** the mkopcodeh.awk script for additional information.
71544 **
71545 ** Documentation about VDBE opcodes is generated by scanning this file
71546 ** for lines of that contain "Opcode:". That line and all subsequent
71547 ** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71565,12 @@
71565 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
71566 ** that this Goto is the bottom of a loop and that the lines from P2 down
71567 ** to the current line should be indented for EXPLAIN output.
71568 */
71569 case OP_Goto: { /* jump */
71570 jump_to_p2_and_check_for_interrupt:
71571 pOp = &aOp[pOp->p2 - 1];
71572
71573 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
71574 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
71575 ** completion. Check to see if sqlite3_interrupt() has been called
71576 ** or if the progress callback needs to be invoked.
@@ -71466,13 +71611,17 @@
71611 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71612 pIn1 = &aMem[pOp->p1];
71613 assert( VdbeMemDynamic(pIn1)==0 );
71614 memAboutToChange(p, pIn1);
71615 pIn1->flags = MEM_Int;
71616 pIn1->u.i = (int)(pOp-aOp);
71617 REGISTER_TRACE(pOp->p1, pIn1);
71618
71619 /* Most jump operations do a goto to this spot in order to update
71620 ** the pOp pointer. */
71621 jump_to_p2:
71622 pOp = &aOp[pOp->p2 - 1];
71623 break;
71624 }
71625
71626 /* Opcode: Return P1 * * * *
71627 **
@@ -71480,11 +71629,11 @@
71629 ** the jump, register P1 becomes undefined.
71630 */
71631 case OP_Return: { /* in1 */
71632 pIn1 = &aMem[pOp->p1];
71633 assert( pIn1->flags==MEM_Int );
71634 pOp = &aOp[pIn1->u.i];
71635 pIn1->flags = MEM_Undefined;
71636 break;
71637 }
71638
71639 /* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71653,11 @@
71653 assert( pOp->p3>=0 && pOp->p3<p->nOp );
71654 pOut = &aMem[pOp->p1];
71655 assert( !VdbeMemDynamic(pOut) );
71656 pOut->u.i = pOp->p3 - 1;
71657 pOut->flags = MEM_Int;
71658 if( pOp->p2 ) goto jump_to_p2;
71659 break;
71660 }
71661
71662 /* Opcode: EndCoroutine P1 * * * *
71663 **
@@ -71524,11 +71673,11 @@
71673 assert( pIn1->flags==MEM_Int );
71674 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
71675 pCaller = &aOp[pIn1->u.i];
71676 assert( pCaller->opcode==OP_Yield );
71677 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71678 pOp = &aOp[pCaller->p2 - 1];
71679 pIn1->flags = MEM_Undefined;
71680 break;
71681 }
71682
71683 /* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71697,13 @@
71697 int pcDest;
71698 pIn1 = &aMem[pOp->p1];
71699 assert( VdbeMemDynamic(pIn1)==0 );
71700 pIn1->flags = MEM_Int;
71701 pcDest = (int)pIn1->u.i;
71702 pIn1->u.i = (int)(pOp - aOp);
71703 REGISTER_TRACE(pOp->p1, pIn1);
71704 pOp = &aOp[pcDest];
71705 break;
71706 }
71707
71708 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
71709 ** Synopsis: if r[P3]=null halt
@@ -71601,34 +71750,38 @@
71750 ** is the same as executing Halt.
71751 */
71752 case OP_Halt: {
71753 const char *zType;
71754 const char *zLogFmt;
71755 VdbeFrame *pFrame;
71756 int pcx;
71757
71758 pcx = (int)(pOp - aOp);
71759 if( pOp->p1==SQLITE_OK && p->pFrame ){
71760 /* Halt the sub-program. Return control to the parent frame. */
71761 pFrame = p->pFrame;
71762 p->pFrame = pFrame->pParent;
71763 p->nFrame--;
71764 sqlite3VdbeSetChanges(db, p->nChange);
71765 pcx = sqlite3VdbeFrameRestore(pFrame);
71766 lastRowid = db->lastRowid;
71767 if( pOp->p2==OE_Ignore ){
71768 /* Instruction pcx is the OP_Program that invoked the sub-program
71769 ** currently being halted. If the p2 instruction of this OP_Halt
71770 ** instruction is set to OE_Ignore, then the sub-program is throwing
71771 ** an IGNORE exception. In this case jump to the address specified
71772 ** as the p2 of the calling OP_Program. */
71773 pcx = p->aOp[pcx].p2-1;
71774 }
71775 aOp = p->aOp;
71776 aMem = p->aMem;
71777 pOp = &aOp[pcx];
71778 break;
71779 }
71780 p->rc = pOp->p1;
71781 p->errorAction = (u8)pOp->p2;
71782 p->pc = pcx;
71783 if( p->rc ){
71784 if( pOp->p5 ){
71785 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
71786 "FOREIGN KEY" };
71787 assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71801,11 @@
71801 }else if( pOp->p4.z ){
71802 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
71803 }else{
71804 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
71805 }
71806 sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
71807 }
71808 rc = sqlite3VdbeHalt(p);
71809 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
71810 if( rc==SQLITE_BUSY ){
71811 p->rc = rc = SQLITE_BUSY;
@@ -71667,11 +71820,12 @@
71820 /* Opcode: Integer P1 P2 * * *
71821 ** Synopsis: r[P2]=P1
71822 **
71823 ** The 32-bit integer value P1 is written into register P2.
71824 */
71825 case OP_Integer: { /* out2 */
71826 pOut = out2Prerelease(p, pOp);
71827 pOut->u.i = pOp->p1;
71828 break;
71829 }
71830
71831 /* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71832,12 @@
71832 ** Synopsis: r[P2]=P4
71833 **
71834 ** P4 is a pointer to a 64-bit integer value.
71835 ** Write that value into register P2.
71836 */
71837 case OP_Int64: { /* out2 */
71838 pOut = out2Prerelease(p, pOp);
71839 assert( pOp->p4.pI64!=0 );
71840 pOut->u.i = *pOp->p4.pI64;
71841 break;
71842 }
71843
@@ -71691,11 +71846,12 @@
71846 ** Synopsis: r[P2]=P4
71847 **
71848 ** P4 is a pointer to a 64-bit floating point value.
71849 ** Write that value into register P2.
71850 */
71851 case OP_Real: { /* same as TK_FLOAT, out2 */
71852 pOut = out2Prerelease(p, pOp);
71853 pOut->flags = MEM_Real;
71854 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
71855 pOut->u.r = *pOp->p4.pReal;
71856 break;
71857 }
@@ -71707,12 +71863,13 @@
71863 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71864 ** into a String opcode before it is executed for the first time. During
71865 ** this transformation, the length of string P4 is computed and stored
71866 ** as the P1 parameter.
71867 */
71868 case OP_String8: { /* same as TK_STRING, out2 */
71869 assert( pOp->p4.z!=0 );
71870 pOut = out2Prerelease(p, pOp);
71871 pOp->opcode = OP_String;
71872 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
71873
71874 #ifndef SQLITE_OMIT_UTF16
71875 if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71902,13 @@
71902 ** If P5!=0 and the content of register P3 is greater than zero, then
71903 ** the datatype of the register P2 is converted to BLOB. The content is
71904 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
71905 ** of a string, as if it had been CAST.
71906 */
71907 case OP_String: { /* out2 */
71908 assert( pOp->p4.z!=0 );
71909 pOut = out2Prerelease(p, pOp);
71910 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71911 pOut->z = pOp->p4.z;
71912 pOut->n = pOp->p1;
71913 pOut->enc = encoding;
71914 UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71932,14 @@
71932 **
71933 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
71934 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
71935 ** OP_Ne or OP_Eq.
71936 */
71937 case OP_Null: { /* out2 */
71938 int cnt;
71939 u16 nullFlag;
71940 pOut = out2Prerelease(p, pOp);
71941 cnt = pOp->p3-pOp->p2;
71942 assert( pOp->p3<=(p->nMem-p->nCursor) );
71943 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
71944 while( cnt>0 ){
71945 pOut++;
@@ -71811,12 +71970,13 @@
71970 ** Synopsis: r[P2]=P4 (len=P1)
71971 **
71972 ** P4 points to a blob of data P1 bytes long. Store this
71973 ** blob in register P2.
71974 */
71975 case OP_Blob: { /* out2 */
71976 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
71977 pOut = out2Prerelease(p, pOp);
71978 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
71979 pOut->enc = encoding;
71980 UPDATE_MAX_BLOBSIZE(pOut);
71981 break;
71982 }
@@ -71827,19 +71987,20 @@
71987 ** Transfer the values of bound parameter P1 into register P2
71988 **
71989 ** If the parameter is named, then its name appears in P4.
71990 ** The P4 value is used by sqlite3_bind_parameter_name().
71991 */
71992 case OP_Variable: { /* out2 */
71993 Mem *pVar; /* Value being transferred */
71994
71995 assert( pOp->p1>0 && pOp->p1<=p->nVar );
71996 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
71997 pVar = &p->aVar[pOp->p1 - 1];
71998 if( sqlite3VdbeMemTooBig(pVar) ){
71999 goto too_big;
72000 }
72001 pOut = out2Prerelease(p, pOp);
72002 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
72003 UPDATE_MAX_BLOBSIZE(pOut);
72004 break;
72005 }
72006
@@ -71870,14 +72031,15 @@
72031 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
72032 assert( memIsValid(pIn1) );
72033 memAboutToChange(p, pOut);
72034 sqlite3VdbeMemMove(pOut, pIn1);
72035 #ifdef SQLITE_DEBUG
72036 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
72037 pOut->pScopyFrom += pOp->p2 - p1;
72038 }
72039 #endif
72040 Deephemeralize(pOut);
72041 REGISTER_TRACE(p2++, pOut);
72042 pIn1++;
72043 pOut++;
72044 }while( --n );
72045 break;
@@ -72012,11 +72174,11 @@
72174 }
72175 if( db->mallocFailed ) goto no_mem;
72176
72177 /* Return SQLITE_ROW
72178 */
72179 p->pc = (int)(pOp - aOp) + 1;
72180 rc = SQLITE_ROW;
72181 goto vdbe_return;
72182 }
72183
72184 /* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72420,11 @@
72420 REGISTER_TRACE(pOp->p2+i, pArg);
72421 }
72422
72423 assert( pOp->p4type==P4_FUNCDEF );
72424 ctx.pFunc = pOp->p4.pFunc;
72425 ctx.iOp = (int)(pOp - aOp);
72426 ctx.pVdbe = p;
72427 MemSetTypeFlag(ctx.pOut, MEM_Null);
72428 ctx.fErrorOrAux = 0;
72429 db->lastRowid = lastRowid;
72430 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72434,11 @@
72434 if( ctx.fErrorOrAux ){
72435 if( ctx.isError ){
72436 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
72437 rc = ctx.isError;
72438 }
72439 sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1);
72440 }
72441
72442 /* Copy the result of the function into register P3 */
72443 sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
72444 if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72563,11 @@
72563 if( (pIn1->flags & MEM_Int)==0 ){
72564 if( pOp->p2==0 ){
72565 rc = SQLITE_MISMATCH;
72566 goto abort_due_to_error;
72567 }else{
72568 goto jump_to_p2;
 
72569 }
72570 }
72571 }
72572 MemSetTypeFlag(pIn1, MEM_Int);
72573 break;
@@ -72588,11 +72749,11 @@
72749 MemSetTypeFlag(pOut, MEM_Null);
72750 REGISTER_TRACE(pOp->p2, pOut);
72751 }else{
72752 VdbeBranchTaken(2,3);
72753 if( pOp->p5 & SQLITE_JUMPIFNULL ){
72754 goto jump_to_p2;
72755 }
72756 }
72757 break;
72758 }
72759 }else{
@@ -72639,10 +72800,16 @@
72800 case OP_Lt: res = res<0; break;
72801 case OP_Le: res = res<=0; break;
72802 case OP_Gt: res = res>0; break;
72803 default: res = res>=0; break;
72804 }
72805
72806 /* Undo any changes made by applyAffinity() to the input registers. */
72807 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72808 pIn1->flags = flags1;
72809 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72810 pIn3->flags = flags3;
72811
72812 if( pOp->p5 & SQLITE_STOREP2 ){
72813 pOut = &aMem[pOp->p2];
72814 memAboutToChange(p, pOut);
72815 MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72816,13 @@
72816 pOut->u.i = res;
72817 REGISTER_TRACE(pOp->p2, pOut);
72818 }else{
72819 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
72820 if( res ){
72821 goto jump_to_p2;
72822 }
72823 }
 
 
 
 
 
72824 break;
72825 }
72826
72827 /* Opcode: Permutation * * * P4 *
72828 **
@@ -72751,15 +72913,15 @@
72913 ** in the most recent OP_Compare instruction the P1 vector was less than
72914 ** equal to, or greater than the P2 vector, respectively.
72915 */
72916 case OP_Jump: { /* jump */
72917 if( iCompare<0 ){
72918 VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1];
72919 }else if( iCompare==0 ){
72920 VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1];
72921 }else{
72922 VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1];
72923 }
72924 break;
72925 }
72926
72927 /* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73027,11 @@
73027 */
73028 case OP_Once: { /* jump */
73029 assert( pOp->p1<p->nOnceFlag );
73030 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
73031 if( p->aOnceFlag[pOp->p1] ){
73032 goto jump_to_p2;
73033 }else{
73034 p->aOnceFlag[pOp->p1] = 1;
73035 }
73036 break;
73037 }
@@ -72900,11 +73062,11 @@
73062 #endif
73063 if( pOp->opcode==OP_IfNot ) c = !c;
73064 }
73065 VdbeBranchTaken(c!=0, 2);
73066 if( c ){
73067 goto jump_to_p2;
73068 }
73069 break;
73070 }
73071
73072 /* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73076,11 @@
73076 */
73077 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
73078 pIn1 = &aMem[pOp->p1];
73079 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
73080 if( (pIn1->flags & MEM_Null)!=0 ){
73081 goto jump_to_p2;
73082 }
73083 break;
73084 }
73085
73086 /* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73090,11 @@
73090 */
73091 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
73092 pIn1 = &aMem[pOp->p1];
73093 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
73094 if( (pIn1->flags & MEM_Null)==0 ){
73095 goto jump_to_p2;
73096 }
73097 break;
73098 }
73099
73100 /* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73304,11 @@
73304 rc = SQLITE_CORRUPT_BKPT;
73305 goto op_column_error;
73306 }
73307 }
73308
73309 /* If after trying to extract new entries from the header, nHdrParsed is
73310 ** still not up to p2, that means that the record has fewer than p2
73311 ** columns. So the result will be either the default value or a NULL.
73312 */
73313 if( pC->nHdrParsed<=p2 ){
73314 if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73428,11 @@
73428 u8 *zNewRecord; /* A buffer to hold the data for the new record */
73429 Mem *pRec; /* The new record */
73430 u64 nData; /* Number of bytes of data space */
73431 int nHdr; /* Number of bytes of header space */
73432 i64 nByte; /* Data space required for this record */
73433 i64 nZero; /* Number of zero bytes at the end of the record */
73434 int nVarint; /* Number of bytes in a varint */
73435 u32 serial_type; /* Type field */
73436 Mem *pData0; /* First field to be combined into the record */
73437 Mem *pLast; /* Last field of the record */
73438 int nField; /* Number of fields in the record */
@@ -73358,11 +73520,11 @@
73520 nVarint = sqlite3VarintLen(nHdr);
73521 nHdr += nVarint;
73522 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
73523 }
73524 nByte = nHdr+nData;
73525 if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73526 goto too_big;
73527 }
73528
73529 /* Make sure the output register has a buffer large enough to store
73530 ** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73571,19 @@
73571 **
73572 ** Store the number of entries (an integer value) in the table or index
73573 ** opened by cursor P1 in register P2
73574 */
73575 #ifndef SQLITE_OMIT_BTREECOUNT
73576 case OP_Count: { /* out2 */
73577 i64 nEntry;
73578 BtCursor *pCrsr;
73579
73580 pCrsr = p->apCsr[pOp->p1]->pCursor;
73581 assert( pCrsr );
73582 nEntry = 0; /* Not needed. Only used to silence a warning. */
73583 rc = sqlite3BtreeCount(pCrsr, &nEntry);
73584 pOut = out2Prerelease(p, pOp);
73585 pOut->u.i = nEntry;
73586 break;
73587 }
73588 #endif
73589
@@ -73530,11 +73693,11 @@
73693 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73694 goto vdbe_return;
73695 }
73696 db->autoCommit = 1;
73697 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73698 p->pc = (int)(pOp - aOp);
73699 db->autoCommit = 0;
73700 p->rc = rc = SQLITE_BUSY;
73701 goto vdbe_return;
73702 }
73703 db->isTransactionSavepoint = 0;
@@ -73589,11 +73752,11 @@
73752 }else{
73753 db->nDeferredCons = pSavepoint->nDeferredCons;
73754 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
73755 }
73756
73757 if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){
73758 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
73759 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73760 }
73761 }
73762 }
@@ -73649,11 +73812,11 @@
73812 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73813 goto vdbe_return;
73814 }else{
73815 db->autoCommit = (u8)desiredAutoCommit;
73816 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73817 p->pc = (int)(pOp - aOp);
73818 db->autoCommit = (u8)(1-desiredAutoCommit);
73819 p->rc = rc = SQLITE_BUSY;
73820 goto vdbe_return;
73821 }
73822 }
@@ -73726,11 +73889,11 @@
73889 pBt = db->aDb[pOp->p1].pBt;
73890
73891 if( pBt ){
73892 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
73893 if( rc==SQLITE_BUSY ){
73894 p->pc = (int)(pOp - aOp);
73895 p->rc = rc = SQLITE_BUSY;
73896 goto vdbe_return;
73897 }
73898 if( rc!=SQLITE_OK ){
73899 goto abort_due_to_error;
@@ -73805,11 +73968,11 @@
73968 **
73969 ** There must be a read-lock on the database (either a transaction
73970 ** must be started or there must be an open cursor) before
73971 ** executing this instruction.
73972 */
73973 case OP_ReadCookie: { /* out2 */
73974 int iMeta;
73975 int iDb;
73976 int iCookie;
73977
73978 assert( p->bIsReader );
@@ -73819,10 +73982,11 @@
73982 assert( iDb>=0 && iDb<db->nDb );
73983 assert( db->aDb[iDb].pBt!=0 );
73984 assert( DbMaskTest(p->btreeMask, iDb) );
73985
73986 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
73987 pOut = out2Prerelease(p, pOp);
73988 pOut->u.i = iMeta;
73989 break;
73990 }
73991
73992 /* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74304,11 @@
74304 VdbeCursor *pC;
74305 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74306 pC = p->apCsr[pOp->p1];
74307 assert( pC->pSorter );
74308 if( (pC->seqCount++)==0 ){
74309 goto jump_to_p2;
74310 }
74311 break;
74312 }
74313
74314 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74481,11 @@
74481 ** loss of information, then special processing is required... */
74482 if( (pIn3->flags & MEM_Int)==0 ){
74483 if( (pIn3->flags & MEM_Real)==0 ){
74484 /* If the P3 value cannot be converted into any kind of a number,
74485 ** then the seek is not possible, so jump to P2 */
74486 VdbeBranchTaken(1,2); goto jump_to_p2;
74487 break;
74488 }
74489
74490 /* If the approximation iKey is larger than the actual real search
74491 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74572,11 @@
74572 }
74573 }
74574 assert( pOp->p2>0 );
74575 VdbeBranchTaken(res!=0,2);
74576 if( res ){
74577 goto jump_to_p2;
74578 }
74579 break;
74580 }
74581
74582 /* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74666,11 @@
74666 */
74667 case OP_NoConflict: /* jump, in3 */
74668 case OP_NotFound: /* jump, in3 */
74669 case OP_Found: { /* jump, in3 */
74670 int alreadyExists;
74671 int takeJump;
74672 int ii;
74673 VdbeCursor *pC;
74674 int res;
74675 char *pFree;
74676 UnpackedRecord *pIdxKey;
@@ -74524,11 +74689,11 @@
74689 pC->seekOp = pOp->opcode;
74690 #endif
74691 pIn3 = &aMem[pOp->p3];
74692 assert( pC->pCursor!=0 );
74693 assert( pC->isTable==0 );
74694 pFree = 0;
74695 if( pOp->p4.i>0 ){
74696 r.pKeyInfo = pC->pKeyInfo;
74697 r.nField = (u16)pOp->p4.i;
74698 r.aMem = pIn3;
74699 for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74712,24 @@
74712 assert( pIn3->flags & MEM_Blob );
74713 ExpandBlob(pIn3);
74714 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
74715 }
74716 pIdxKey->default_rc = 0;
74717 takeJump = 0;
74718 if( pOp->opcode==OP_NoConflict ){
74719 /* For the OP_NoConflict opcode, take the jump if any of the
74720 ** input fields are NULL, since any key with a NULL will not
74721 ** conflict */
74722 for(ii=0; ii<pIdxKey->nField; ii++){
74723 if( pIdxKey->aMem[ii].flags & MEM_Null ){
74724 takeJump = 1;
74725 break;
74726 }
74727 }
74728 }
74729 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74730 sqlite3DbFree(db, pFree);
 
 
74731 if( rc!=SQLITE_OK ){
74732 break;
74733 }
74734 pC->seekResult = res;
74735 alreadyExists = (res==0);
@@ -74572,14 +74736,14 @@
74736 pC->nullRow = 1-alreadyExists;
74737 pC->deferredMoveto = 0;
74738 pC->cacheStatus = CACHE_STALE;
74739 if( pOp->opcode==OP_Found ){
74740 VdbeBranchTaken(alreadyExists!=0,2);
74741 if( alreadyExists ) goto jump_to_p2;
74742 }else{
74743 VdbeBranchTaken(takeJump||alreadyExists==0,2);
74744 if( takeJump || !alreadyExists ) goto jump_to_p2;
74745 }
74746 break;
74747 }
74748
74749 /* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74788,12 @@
74788 pC->movetoTarget = iKey; /* Used by OP_Delete */
74789 pC->nullRow = 0;
74790 pC->cacheStatus = CACHE_STALE;
74791 pC->deferredMoveto = 0;
74792 VdbeBranchTaken(res!=0,2);
 
 
 
74793 pC->seekResult = res;
74794 if( res!=0 ) goto jump_to_p2;
74795 break;
74796 }
74797
74798 /* Opcode: Sequence P1 P2 * * *
74799 ** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74801,14 @@
74801 ** Find the next available sequence number for cursor P1.
74802 ** Write the sequence number into register P2.
74803 ** The sequence number on the cursor is incremented after this
74804 ** instruction.
74805 */
74806 case OP_Sequence: { /* out2 */
74807 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74808 assert( p->apCsr[pOp->p1]!=0 );
74809 pOut = out2Prerelease(p, pOp);
74810 pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
74811 break;
74812 }
74813
74814
@@ -74662,20 +74825,21 @@
74825 ** allowed to be less than this value. When this value reaches its maximum,
74826 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
74827 ** generated record number. This P3 mechanism is used to help implement the
74828 ** AUTOINCREMENT feature.
74829 */
74830 case OP_NewRowid: { /* out2 */
74831 i64 v; /* The new rowid */
74832 VdbeCursor *pC; /* Cursor of table to get the new rowid */
74833 int res; /* Result of an sqlite3BtreeLast() */
74834 int cnt; /* Counter to limit the number of searches */
74835 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
74836 VdbeFrame *pFrame; /* Root frame of VDBE */
74837
74838 v = 0;
74839 res = 0;
74840 pOut = out2Prerelease(p, pOp);
74841 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74842 pC = p->apCsr[pOp->p1];
74843 assert( pC!=0 );
74844 if( NEVER(pC->pCursor==0) ){
74845 /* The zero initialization above is all that is needed */
@@ -74985,13 +75149,11 @@
75149 pIn3 = &aMem[pOp->p3];
75150 nKeyCol = pOp->p4.i;
75151 res = 0;
75152 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
75153 VdbeBranchTaken(res!=0,2);
75154 if( res ) goto jump_to_p2;
 
 
75155 break;
75156 };
75157
75158 /* Opcode: SorterData P1 P2 P3 * *
75159 ** Synopsis: r[P2]=data
@@ -75116,16 +75278,17 @@
75278 **
75279 ** P1 can be either an ordinary table or a virtual table. There used to
75280 ** be a separate OP_VRowid opcode for use with virtual tables, but this
75281 ** one opcode now works for both table types.
75282 */
75283 case OP_Rowid: { /* out2 */
75284 VdbeCursor *pC;
75285 i64 v;
75286 sqlite3_vtab *pVtab;
75287 const sqlite3_module *pModule;
75288
75289 pOut = out2Prerelease(p, pOp);
75290 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75291 pC = p->apCsr[pOp->p1];
75292 assert( pC!=0 );
75293 assert( pC->pseudoTableReg==0 || pC->nullRow );
75294 if( pC->nullRow ){
@@ -75174,11 +75337,11 @@
75337 sqlite3BtreeClearCursor(pC->pCursor);
75338 }
75339 break;
75340 }
75341
75342 /* Opcode: Last P1 P2 P3 * *
75343 **
75344 ** The next use of the Rowid or Column or Prev instruction for P1
75345 ** will refer to the last entry in the database table or index.
75346 ** If the table or index is empty and P2>0, then jump immediately to P2.
75347 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75364,17 @@
75364 assert( pCrsr!=0 );
75365 rc = sqlite3BtreeLast(pCrsr, &res);
75366 pC->nullRow = (u8)res;
75367 pC->deferredMoveto = 0;
75368 pC->cacheStatus = CACHE_STALE;
75369 pC->seekResult = pOp->p3;
75370 #ifdef SQLITE_DEBUG
75371 pC->seekOp = OP_Last;
75372 #endif
75373 if( pOp->p2>0 ){
75374 VdbeBranchTaken(res!=0,2);
75375 if( res ) goto jump_to_p2;
75376 }
75377 break;
75378 }
75379
75380
@@ -75270,13 +75434,11 @@
75434 pC->cacheStatus = CACHE_STALE;
75435 }
75436 pC->nullRow = (u8)res;
75437 assert( pOp->p2>0 && pOp->p2<p->nOp );
75438 VdbeBranchTaken(res!=0,2);
75439 if( res ) goto jump_to_p2;
 
 
75440 break;
75441 }
75442
75443 /* Opcode: Next P1 P2 P3 P4 P5
75444 **
@@ -75383,15 +75545,15 @@
75545 next_tail:
75546 pC->cacheStatus = CACHE_STALE;
75547 VdbeBranchTaken(res==0,2);
75548 if( res==0 ){
75549 pC->nullRow = 0;
 
75550 p->aCounter[pOp->p5]++;
75551 #ifdef SQLITE_TEST
75552 sqlite3_search_count++;
75553 #endif
75554 goto jump_to_p2_and_check_for_interrupt;
75555 }else{
75556 pC->nullRow = 1;
75557 }
75558 goto check_for_interrupt;
75559 }
@@ -75495,15 +75657,16 @@
75657 ** the end of the index key pointed to by cursor P1. This integer should be
75658 ** the rowid of the table entry to which this index entry points.
75659 **
75660 ** See also: Rowid, MakeRecord.
75661 */
75662 case OP_IdxRowid: { /* out2 */
75663 BtCursor *pCrsr;
75664 VdbeCursor *pC;
75665 i64 rowid;
75666
75667 pOut = out2Prerelease(p, pOp);
75668 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75669 pC = p->apCsr[pOp->p1];
75670 assert( pC!=0 );
75671 pCrsr = pC->pCursor;
75672 assert( pCrsr!=0 );
@@ -75612,13 +75775,11 @@
75775 }else{
75776 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
75777 res++;
75778 }
75779 VdbeBranchTaken(res>0,2);
75780 if( res>0 ) goto jump_to_p2;
 
 
75781 break;
75782 }
75783
75784 /* Opcode: Destroy P1 P2 P3 * *
75785 **
@@ -75638,15 +75799,16 @@
75799 ** the last one in the database) then a zero is stored in register P2.
75800 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
75801 **
75802 ** See also: Clear
75803 */
75804 case OP_Destroy: { /* out2 */
75805 int iMoved;
75806 int iDb;
75807
75808 assert( p->readOnly==0 );
75809 pOut = out2Prerelease(p, pOp);
75810 pOut->flags = MEM_Null;
75811 if( db->nVdbeRead > db->nVDestroy+1 ){
75812 rc = SQLITE_LOCKED;
75813 p->errorAction = OE_Abort;
75814 }else{
@@ -75751,16 +75913,17 @@
75913 ** P1>1. Write the root page number of the new table into
75914 ** register P2.
75915 **
75916 ** See documentation on OP_CreateTable for additional information.
75917 */
75918 case OP_CreateIndex: /* out2 */
75919 case OP_CreateTable: { /* out2 */
75920 int pgno;
75921 int flags;
75922 Db *pDb;
75923
75924 pOut = out2Prerelease(p, pOp);
75925 pgno = 0;
75926 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75927 assert( DbMaskTest(p->btreeMask, pOp->p1) );
75928 assert( p->readOnly==0 );
75929 pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76145,16 @@
76145 if( (pIn1->flags & MEM_RowSet)==0
76146 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
76147 ){
76148 /* The boolean index is empty */
76149 sqlite3VdbeMemSetNull(pIn1);
 
76150 VdbeBranchTaken(1,2);
76151 goto jump_to_p2_and_check_for_interrupt;
76152 }else{
76153 /* A value was pulled from the index */
 
76154 VdbeBranchTaken(0,2);
76155 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
76156 }
76157 goto check_for_interrupt;
76158 }
76159
76160 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76201,11 @@
76201 assert( pOp->p4type==P4_INT32 );
76202 assert( iSet==-1 || iSet>=0 );
76203 if( iSet ){
76204 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
76205 VdbeBranchTaken(exists!=0,2);
76206 if( exists ) goto jump_to_p2;
 
 
 
76207 }
76208 if( iSet>=0 ){
76209 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
76210 }
76211 break;
@@ -76130,11 +76290,11 @@
76290 pRt->u.pFrame = pFrame;
76291
76292 pFrame->v = p;
76293 pFrame->nChildMem = nMem;
76294 pFrame->nChildCsr = pProgram->nCsr;
76295 pFrame->pc = (int)(pOp - aOp);
76296 pFrame->aMem = p->aMem;
76297 pFrame->nMem = p->nMem;
76298 pFrame->apCsr = p->apCsr;
76299 pFrame->nCursor = p->nCursor;
76300 pFrame->aOp = p->aOp;
@@ -76153,11 +76313,11 @@
76313 }
76314 }else{
76315 pFrame = pRt->u.pFrame;
76316 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
76317 assert( pProgram->nCsr==pFrame->nChildCsr );
76318 assert( (int)(pOp - aOp)==pFrame->pc );
76319 }
76320
76321 p->nFrame++;
76322 pFrame->pParent = p->pFrame;
76323 pFrame->lastRowid = lastRowid;
@@ -76174,11 +76334,11 @@
76334 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
76335 p->nOnceFlag = pProgram->nOnce;
76336 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
76337 p->anExec = 0;
76338 #endif
76339 pOp = &aOp[-1];
76340 memset(p->aOnceFlag, 0, p->nOnceFlag);
76341
76342 break;
76343 }
76344
@@ -76192,13 +76352,14 @@
76352 **
76353 ** The address of the cell in the parent frame is determined by adding
76354 ** the value of the P1 argument to the value of the P1 argument to the
76355 ** calling OP_Program instruction.
76356 */
76357 case OP_Param: { /* out2 */
76358 VdbeFrame *pFrame;
76359 Mem *pIn;
76360 pOut = out2Prerelease(p, pOp);
76361 pFrame = p->pFrame;
76362 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
76363 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
76364 break;
76365 }
@@ -76238,14 +76399,14 @@
76399 ** (immediate foreign key constraint violations).
76400 */
76401 case OP_FkIfZero: { /* jump */
76402 if( pOp->p1 ){
76403 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76404 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
76405 }else{
76406 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76407 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
76408 }
76409 break;
76410 }
76411 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
76412
@@ -76292,13 +76453,11 @@
76453 */
76454 case OP_IfPos: { /* jump, in1 */
76455 pIn1 = &aMem[pOp->p1];
76456 assert( pIn1->flags&MEM_Int );
76457 VdbeBranchTaken( pIn1->u.i>0, 2);
76458 if( pIn1->u.i>0 ) goto jump_to_p2;
 
 
76459 break;
76460 }
76461
76462 /* Opcode: IfNeg P1 P2 P3 * *
76463 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76468,11 @@
76468 case OP_IfNeg: { /* jump, in1 */
76469 pIn1 = &aMem[pOp->p1];
76470 assert( pIn1->flags&MEM_Int );
76471 pIn1->u.i += pOp->p3;
76472 VdbeBranchTaken(pIn1->u.i<0, 2);
76473 if( pIn1->u.i<0 ) goto jump_to_p2;
 
 
76474 break;
76475 }
76476
76477 /* Opcode: IfNotZero P1 P2 P3 * *
76478 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76485,11 @@
76485 pIn1 = &aMem[pOp->p1];
76486 assert( pIn1->flags&MEM_Int );
76487 VdbeBranchTaken(pIn1->u.i<0, 2);
76488 if( pIn1->u.i ){
76489 pIn1->u.i += pOp->p3;
76490 goto jump_to_p2;
76491 }
76492 break;
76493 }
76494
76495 /* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76501,11 @@
76501 case OP_DecrJumpZero: { /* jump, in1 */
76502 pIn1 = &aMem[pOp->p1];
76503 assert( pIn1->flags&MEM_Int );
76504 pIn1->u.i--;
76505 VdbeBranchTaken(pIn1->u.i==0, 2);
76506 if( pIn1->u.i==0 ) goto jump_to_p2;
 
 
76507 break;
76508 }
76509
76510
76511 /* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76517,11 @@
76517 */
76518 case OP_JumpZeroIncr: { /* jump, in1 */
76519 pIn1 = &aMem[pOp->p1];
76520 assert( pIn1->flags&MEM_Int );
76521 VdbeBranchTaken(pIn1->u.i==0, 2);
76522 if( (pIn1->u.i++)==0 ) goto jump_to_p2;
 
 
76523 break;
76524 }
76525
76526 /* Opcode: AggStep * P2 P3 P4 P5
76527 ** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76559,11 @@
76559 pMem->n++;
76560 sqlite3VdbeMemInit(&t, db, MEM_Null);
76561 ctx.pOut = &t;
76562 ctx.isError = 0;
76563 ctx.pVdbe = p;
76564 ctx.iOp = (int)(pOp - aOp);
76565 ctx.skipFlag = 0;
76566 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
76567 if( ctx.isError ){
76568 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
76569 rc = ctx.isError;
@@ -76501,19 +76654,20 @@
76654 **
76655 ** If changing into or out of WAL mode the procedure is more complicated.
76656 **
76657 ** Write a string containing the final journal-mode to register P2.
76658 */
76659 case OP_JournalMode: { /* out2 */
76660 Btree *pBt; /* Btree to change journal mode of */
76661 Pager *pPager; /* Pager associated with pBt */
76662 int eNew; /* New journal mode */
76663 int eOld; /* The old journal mode */
76664 #ifndef SQLITE_OMIT_WAL
76665 const char *zFilename; /* Name of database file for pPager */
76666 #endif
76667
76668 pOut = out2Prerelease(p, pOp);
76669 eNew = pOp->p3;
76670 assert( eNew==PAGER_JOURNALMODE_DELETE
76671 || eNew==PAGER_JOURNALMODE_TRUNCATE
76672 || eNew==PAGER_JOURNALMODE_PERSIST
76673 || eNew==PAGER_JOURNALMODE_OFF
@@ -76585,11 +76739,10 @@
76739 if( rc ){
76740 eNew = eOld;
76741 }
76742 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
76743
 
76744 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
76745 pOut->z = (char *)sqlite3JournalModename(eNew);
76746 pOut->n = sqlite3Strlen30(pOut->z);
76747 pOut->enc = SQLITE_UTF8;
76748 sqlite3VdbeChangeEncoding(pOut, encoding);
@@ -76626,12 +76779,12 @@
76779 assert( p->readOnly==0 );
76780 pBt = db->aDb[pOp->p1].pBt;
76781 rc = sqlite3BtreeIncrVacuum(pBt);
76782 VdbeBranchTaken(rc==SQLITE_DONE,2);
76783 if( rc==SQLITE_DONE ){
 
76784 rc = SQLITE_OK;
76785 goto jump_to_p2;
76786 }
76787 break;
76788 }
76789 #endif
76790
@@ -76780,12 +76933,13 @@
76933 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76934 if( pCur ){
76935 pCur->pVtabCursor = pVtabCursor;
76936 pVtab->nRef++;
76937 }else{
76938 assert( db->mallocFailed );
76939 pModule->xClose(pVtabCursor);
76940 goto no_mem;
76941 }
76942 }
76943 break;
76944 }
76945 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76991,23 @@
76991 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
76992 nArg = (int)pArgc->u.i;
76993 iQuery = (int)pQuery->u.i;
76994
76995 /* Invoke the xFilter method */
76996 res = 0;
76997 apArg = p->apArg;
76998 for(i = 0; i<nArg; i++){
76999 apArg[i] = &pArgc[i+1];
77000 }
77001 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
77002 sqlite3VtabImportErrmsg(p, pVtab);
77003 if( rc==SQLITE_OK ){
77004 res = pModule->xEof(pVtabCursor);
 
 
 
 
 
 
 
77005 }
77006 pCur->nullRow = 0;
77007 VdbeBranchTaken(res!=0,2);
77008 if( res ) goto jump_to_p2;
77009 break;
77010 }
77011 #endif /* SQLITE_OMIT_VIRTUALTABLE */
77012
77013 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77090,11 @@
77090 res = pModule->xEof(pCur->pVtabCursor);
77091 }
77092 VdbeBranchTaken(!res,2);
77093 if( !res ){
77094 /* If there is data, jump to P2 */
77095 goto jump_to_p2_and_check_for_interrupt;
77096 }
77097 goto check_for_interrupt;
77098 }
77099 #endif /* SQLITE_OMIT_VIRTUALTABLE */
77100
@@ -77065,11 +77213,12 @@
77213 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
77214 /* Opcode: Pagecount P1 P2 * * *
77215 **
77216 ** Write the current number of pages in database P1 to memory cell P2.
77217 */
77218 case OP_Pagecount: { /* out2 */
77219 pOut = out2Prerelease(p, pOp);
77220 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
77221 break;
77222 }
77223 #endif
77224
@@ -77081,14 +77230,15 @@
77230 ** Do not let the maximum page count fall below the current page count and
77231 ** do not change the maximum page count value if P3==0.
77232 **
77233 ** Store the maximum page count after the change in register P2.
77234 */
77235 case OP_MaxPgcnt: { /* out2 */
77236 unsigned int newMax;
77237 Btree *pBt;
77238
77239 pOut = out2Prerelease(p, pOp);
77240 pBt = db->aDb[pOp->p1].pBt;
77241 newMax = 0;
77242 if( pOp->p3 ){
77243 newMax = sqlite3BtreeLastPage(pBt);
77244 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77263,10 @@
77263 */
77264 case OP_Init: { /* jump */
77265 char *zTrace;
77266 char *z;
77267
 
 
 
77268 #ifndef SQLITE_OMIT_TRACE
77269 if( db->xTrace
77270 && !p->doingRerun
77271 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
77272 ){
@@ -77143,10 +77290,11 @@
77290 ){
77291 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
77292 }
77293 #endif /* SQLITE_DEBUG */
77294 #endif /* SQLITE_OMIT_TRACE */
77295 if( pOp->p2 ) goto jump_to_p2;
77296 break;
77297 }
77298
77299
77300 /* Opcode: Noop * * * * *
@@ -77174,31 +77322,31 @@
77322 }
77323
77324 #ifdef VDBE_PROFILE
77325 {
77326 u64 endTime = sqlite3Hwtime();
77327 if( endTime>start ) pOrigOp->cycles += endTime - start;
77328 pOrigOp->cnt++;
77329 }
77330 #endif
77331
77332 /* The following code adds nothing to the actual functionality
77333 ** of the program. It is only here for testing and debugging.
77334 ** On the other hand, it does burn CPU cycles every time through
77335 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
77336 */
77337 #ifndef NDEBUG
77338 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
77339
77340 #ifdef SQLITE_DEBUG
77341 if( db->flags & SQLITE_VdbeTrace ){
77342 if( rc!=0 ) printf("rc=%d\n",rc);
77343 if( pOrigOp->opflags & (OPFLG_OUT2) ){
77344 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
77345 }
77346 if( pOrigOp->opflags & OPFLG_OUT3 ){
77347 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
77348 }
77349 }
77350 #endif /* SQLITE_DEBUG */
77351 #endif /* NDEBUG */
77352 } /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77357,11 @@
77357 vdbe_error_halt:
77358 assert( rc );
77359 p->rc = rc;
77360 testcase( sqlite3GlobalConfig.xLog!=0 );
77361 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77362 (int)(pOp - aOp), p->zSql, p->zErrMsg);
77363 sqlite3VdbeHalt(p);
77364 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
77365 rc = SQLITE_ERROR;
77366 if( resetSchemaOnFault>0 ){
77367 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78183,23 @@
78183 **
78184 ** In both cases, the effects of the main thread seeing (bDone==0) even
78185 ** after the thread has finished are not dire. So we don't worry about
78186 ** memory barriers and such here.
78187 */
78188 typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int);
78189 struct SortSubtask {
78190 SQLiteThread *pThread; /* Background thread, if any */
78191 int bDone; /* Set if thread is finished but not joined */
78192 VdbeSorter *pSorter; /* Sorter that owns this sub-task */
78193 UnpackedRecord *pUnpacked; /* Space to unpack a record */
78194 SorterList list; /* List for thread to write to a PMA */
78195 int nPMA; /* Number of PMAs currently in file */
78196 SorterCompare xCompare; /* Compare function to use */
78197 SorterFile file; /* Temp file for level-0 PMAs */
78198 SorterFile file2; /* Space for other PMAs */
78199 };
78200
78201
78202 /*
78203 ** Main sorter structure. A single instance of this is allocated for each
78204 ** sorter cursor created by the VDBE.
78205 **
@@ -78072,12 +78223,16 @@
78223 int nMemory; /* Size of list.aMemory allocation in bytes */
78224 u8 bUsePMA; /* True if one or more PMAs created */
78225 u8 bUseThreads; /* True to use background threads */
78226 u8 iPrev; /* Previous thread used to flush PMA */
78227 u8 nTask; /* Size of aTask[] array */
78228 u8 typeMask;
78229 SortSubtask aTask[1]; /* One or more subtasks */
78230 };
78231
78232 #define SORTER_TYPE_INTEGER 0x01
78233 #define SORTER_TYPE_TEXT 0x02
78234
78235 /*
78236 ** An instance of the following object is used to read records out of a
78237 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
78238 ** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78641,165 @@
78641 rc = vdbePmaReaderNext(pReadr);
78642 }
78643 return rc;
78644 }
78645
78646 /*
78647 ** A version of vdbeSorterCompare() that assumes that it has already been
78648 ** determined that the first field of key1 is equal to the first field of
78649 ** key2.
78650 */
78651 static int vdbeSorterCompareTail(
78652 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78653 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78654 const void *pKey1, int nKey1, /* Left side of comparison */
78655 const void *pKey2, int nKey2 /* Right side of comparison */
78656 ){
78657 UnpackedRecord *r2 = pTask->pUnpacked;
78658 if( *pbKey2Cached==0 ){
78659 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78660 *pbKey2Cached = 1;
78661 }
78662 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
78663 }
78664
78665 /*
78666 ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
78667 ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
78668 ** used by the comparison. Return the result of the comparison.
78669 **
78670 ** If IN/OUT parameter *pbKey2Cached is true when this function is called,
78671 ** it is assumed that (pTask->pUnpacked) contains the unpacked version
78672 ** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
78673 ** version of key2 and *pbKey2Cached set to true before returning.
78674 **
78675 ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
78676 ** to SQLITE_NOMEM.
78677 */
78678 static int vdbeSorterCompare(
78679 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78680 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78681 const void *pKey1, int nKey1, /* Left side of comparison */
78682 const void *pKey2, int nKey2 /* Right side of comparison */
78683 ){
78684 UnpackedRecord *r2 = pTask->pUnpacked;
78685 if( !*pbKey2Cached ){
78686 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78687 *pbKey2Cached = 1;
78688 }
78689 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
78690 }
78691
78692 /*
78693 ** A specially optimized version of vdbeSorterCompare() that assumes that
78694 ** the first field of each key is a TEXT value and that the collation
78695 ** sequence to compare them with is BINARY.
78696 */
78697 static int vdbeSorterCompareText(
78698 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78699 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78700 const void *pKey1, int nKey1, /* Left side of comparison */
78701 const void *pKey2, int nKey2 /* Right side of comparison */
78702 ){
78703 const u8 * const p1 = (const u8 * const)pKey1;
78704 const u8 * const p2 = (const u8 * const)pKey2;
78705 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78706 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78707
78708 int n1;
78709 int n2;
78710 int res;
78711
78712 getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2;
78713 getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2;
78714 res = memcmp(v1, v2, MIN(n1, n2));
78715 if( res==0 ){
78716 res = n1 - n2;
78717 }
78718
78719 if( res==0 ){
78720 if( pTask->pSorter->pKeyInfo->nField>1 ){
78721 res = vdbeSorterCompareTail(
78722 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78723 );
78724 }
78725 }else{
78726 if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78727 res = res * -1;
78728 }
78729 }
78730
78731 return res;
78732 }
78733
78734 /*
78735 ** A specially optimized version of vdbeSorterCompare() that assumes that
78736 ** the first field of each key is an INTEGER value.
78737 */
78738 static int vdbeSorterCompareInt(
78739 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78740 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78741 const void *pKey1, int nKey1, /* Left side of comparison */
78742 const void *pKey2, int nKey2 /* Right side of comparison */
78743 ){
78744 const u8 * const p1 = (const u8 * const)pKey1;
78745 const u8 * const p2 = (const u8 * const)pKey2;
78746 const int s1 = p1[1]; /* Left hand serial type */
78747 const int s2 = p2[1]; /* Right hand serial type */
78748 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78749 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78750 int res; /* Return value */
78751
78752 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
78753 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
78754
78755 if( s1>7 && s2>7 ){
78756 res = s1 - s2;
78757 }else{
78758 if( s1==s2 ){
78759 if( (*v1 ^ *v2) & 0x80 ){
78760 /* The two values have different signs */
78761 res = (*v1 & 0x80) ? -1 : +1;
78762 }else{
78763 /* The two values have the same sign. Compare using memcmp(). */
78764 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
78765 int i;
78766 res = 0;
78767 for(i=0; i<aLen[s1]; i++){
78768 if( (res = v1[i] - v2[i]) ) break;
78769 }
78770 }
78771 }else{
78772 if( s2>7 ){
78773 res = +1;
78774 }else if( s1>7 ){
78775 res = -1;
78776 }else{
78777 res = s1 - s2;
78778 }
78779 assert( res!=0 );
78780
78781 if( res>0 ){
78782 if( *v1 & 0x80 ) res = -1;
78783 }else{
78784 if( *v2 & 0x80 ) res = +1;
78785 }
78786 }
78787 }
78788
78789 if( res==0 ){
78790 if( pTask->pSorter->pKeyInfo->nField>1 ){
78791 res = vdbeSorterCompareTail(
78792 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78793 );
78794 }
78795 }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78796 res = res * -1;
78797 }
78798
78799 return res;
78800 }
78801
78802 /*
78803 ** Initialize the temporary index cursor just opened as a sorter cursor.
78804 **
78805 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78864,17 @@
78864 rc = SQLITE_NOMEM;
78865 }else{
78866 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
78867 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
78868 pKeyInfo->db = 0;
78869 if( nField && nWorker==0 ){
78870 pKeyInfo->nXField += (pKeyInfo->nField - nField);
78871 pKeyInfo->nField = nField;
78872 }
78873 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
78874 pSorter->nTask = nWorker + 1;
78875 pSorter->iPrev = nWorker-1;
78876 pSorter->bUseThreads = (pSorter->nTask>1);
78877 pSorter->db = db;
78878 for(i=0; i<pSorter->nTask; i++){
78879 SortSubtask *pTask = &pSorter->aTask[i];
78880 pTask->pSorter = pSorter;
@@ -78607,10 +78896,16 @@
78896 pSorter->nMemory = pgsz;
78897 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
78898 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
78899 }
78900 }
78901
78902 if( (pKeyInfo->nField+pKeyInfo->nXField)<13
78903 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
78904 ){
78905 pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
78906 }
78907 }
78908
78909 return rc;
78910 }
78911 #undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78926,28 @@
78926 ** Free all resources owned by the object indicated by argument pTask. All
78927 ** fields of *pTask are zeroed before returning.
78928 */
78929 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
78930 sqlite3DbFree(db, pTask->pUnpacked);
 
78931 #if SQLITE_MAX_WORKER_THREADS>0
78932 /* pTask->list.aMemory can only be non-zero if it was handed memory
78933 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
78934 if( pTask->list.aMemory ){
78935 sqlite3_free(pTask->list.aMemory);
 
78936 }else
78937 #endif
78938 {
78939 assert( pTask->list.aMemory==0 );
78940 vdbeSorterRecordFree(0, pTask->list.pList);
78941 }
 
78942 if( pTask->file.pFd ){
78943 sqlite3OsCloseFree(pTask->file.pFd);
 
 
78944 }
78945 if( pTask->file2.pFd ){
78946 sqlite3OsCloseFree(pTask->file2.pFd);
 
 
78947 }
78948 memset(pTask, 0, sizeof(SortSubtask));
78949 }
78950
78951 #ifdef SQLITE_DEBUG_SORTER_THREADS
78952 static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
78953 i64 t;
@@ -78834,10 +79123,11 @@
79123 vdbeMergeEngineFree(pSorter->pMerger);
79124 pSorter->pMerger = 0;
79125 for(i=0; i<pSorter->nTask; i++){
79126 SortSubtask *pTask = &pSorter->aTask[i];
79127 vdbeSortSubtaskCleanup(db, pTask);
79128 pTask->pSorter = pSorter;
79129 }
79130 if( pSorter->list.aMemory==0 ){
79131 vdbeSorterRecordFree(0, pSorter->list.pList);
79132 }
79133 pSorter->list.pList = 0;
@@ -78943,31 +79233,45 @@
79233 SorterRecord *p2, /* Second list to merge */
79234 SorterRecord **ppOut /* OUT: Head of merged list */
79235 ){
79236 SorterRecord *pFinal = 0;
79237 SorterRecord **pp = &pFinal;
79238 int bCached = 0;
79239
79240 while( p1 && p2 ){
79241 int res;
79242 res = pTask->xCompare(
79243 pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
79244 );
79245
79246 if( res<=0 ){
79247 *pp = p1;
79248 pp = &p1->u.pNext;
79249 p1 = p1->u.pNext;
 
79250 }else{
79251 *pp = p2;
79252 pp = &p2->u.pNext;
79253 p2 = p2->u.pNext;
79254 bCached = 0;
 
79255 }
79256 }
79257 *pp = p1 ? p1 : p2;
79258 *ppOut = pFinal;
79259 }
79260
79261 /*
79262 ** Return the SorterCompare function to compare values collected by the
79263 ** sorter object passed as the only argument.
79264 */
79265 static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){
79266 if( p->typeMask==SORTER_TYPE_INTEGER ){
79267 return vdbeSorterCompareInt;
79268 }else if( p->typeMask==SORTER_TYPE_TEXT ){
79269 return vdbeSorterCompareText;
79270 }
79271 return vdbeSorterCompare;
79272 }
79273
79274 /*
79275 ** Sort the linked list of records headed at pTask->pList. Return
79276 ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
79277 ** an error occurs.
@@ -78979,16 +79283,18 @@
79283 int rc;
79284
79285 rc = vdbeSortAllocUnpacked(pTask);
79286 if( rc!=SQLITE_OK ) return rc;
79287
79288 p = pList->pList;
79289 pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
79290
79291 aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
79292 if( !aSlot ){
79293 return SQLITE_NOMEM;
79294 }
79295
 
79296 while( p ){
79297 SorterRecord *pNext;
79298 if( pList->aMemory ){
79299 if( (u8*)p==pList->aMemory ){
79300 pNext = 0;
@@ -79198,28 +79504,27 @@
79504 /* Update contents of aTree[] */
79505 if( rc==SQLITE_OK ){
79506 int i; /* Index of aTree[] to recalculate */
79507 PmaReader *pReadr1; /* First PmaReader to compare */
79508 PmaReader *pReadr2; /* Second PmaReader to compare */
79509 int bCached = 0;
79510
79511 /* Find the first two PmaReaders to compare. The one that was just
79512 ** advanced (iPrev) and the one next to it in the array. */
79513 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
79514 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
 
79515
79516 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
79517 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
79518 int iRes;
79519 if( pReadr1->pFd==0 ){
79520 iRes = +1;
79521 }else if( pReadr2->pFd==0 ){
79522 iRes = -1;
79523 }else{
79524 iRes = pTask->xCompare(pTask, &bCached,
79525 pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
79526 );
79527 }
79528
79529 /* If pReadr1 contained the smaller value, set aTree[i] to its index.
79530 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79542,13 @@
79542 ** is sorted from oldest to newest, so pReadr1 contains older values
79543 ** than pReadr2 iff (pReadr1<pReadr2). */
79544 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
79545 pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
79546 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79547 bCached = 0;
79548 }else{
79549 if( pReadr1->pFd ) bCached = 0;
79550 pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
79551 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79552 }
79553 }
79554 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79651,20 @@
79651 SorterRecord *pNew; /* New list element */
79652
79653 int bFlush; /* True to flush contents of memory to PMA */
79654 int nReq; /* Bytes of memory required */
79655 int nPMA; /* Bytes of PMA space required */
79656 int t; /* serial type of first record field */
79657
79658 getVarint32((const u8*)&pVal->z[1], t);
79659 if( t>0 && t<10 && t!=7 ){
79660 pSorter->typeMask &= SORTER_TYPE_INTEGER;
79661 }else if( t>10 && (t & 0x01) ){
79662 pSorter->typeMask &= SORTER_TYPE_TEXT;
79663 }else{
79664 pSorter->typeMask = 0;
79665 }
79666
79667 assert( pSorter );
79668
79669 /* Figure out whether or not the current contents of memory should be
79670 ** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79926,16 @@
79926 if( p1->pFd==0 ){
79927 iRes = i2;
79928 }else if( p2->pFd==0 ){
79929 iRes = i1;
79930 }else{
79931 SortSubtask *pTask = pMerger->pTask;
79932 int bCached = 0;
79933 int res;
79934 assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79935 res = pTask->xCompare(
79936 pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79937 );
79938 if( res<=0 ){
79939 iRes = i1;
79940 }else{
79941 iRes = i2;
@@ -79638,15 +79955,16 @@
79955 */
79956 #define INCRINIT_NORMAL 0
79957 #define INCRINIT_TASK 1
79958 #define INCRINIT_ROOT 2
79959
79960 /*
79961 ** Forward reference required as the vdbeIncrMergeInit() and
79962 ** vdbePmaReaderIncrInit() routines are called mutually recursively when
79963 ** building a merge tree.
79964 */
79965 static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode);
79966
79967 /*
79968 ** Initialize the MergeEngine object passed as the second argument. Once this
79969 ** function returns, the first key of merged data may be read from the
79970 ** MergeEngine object in the usual fashion.
@@ -79689,11 +80007,11 @@
80007 ** the main thread to fill its buffer. So calling PmaReaderNext()
80008 ** on this PmaReader before any of the multi-threaded PmaReaders takes
80009 ** better advantage of multi-processor hardware. */
80010 rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
80011 }else{
80012 rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
80013 }
80014 if( rc!=SQLITE_OK ) return rc;
80015 }
80016
80017 for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80019,19 @@
80019 }
80020 return pTask->pUnpacked->errCode;
80021 }
80022
80023 /*
80024 ** The PmaReader passed as the first argument is guaranteed to be an
80025 ** incremental-reader (pReadr->pIncr!=0). This function serves to open
80026 ** and/or initialize the temp file related fields of the IncrMerge
 
 
80027 ** object at (pReadr->pIncr).
80028 **
80029 ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
80030 ** in the sub-tree headed by pReadr are also initialized. Data is then
80031 ** loaded into the buffers belonging to pReadr and it is set to point to
80032 ** the first key in its range.
80033 **
80034 ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
80035 ** to be a multi-threaded PmaReader and this function is being called in a
80036 ** background thread. In this case all PmaReaders in the sub-tree are
80037 ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80054,112 @@
80054 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
80055 */
80056 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
80057 int rc = SQLITE_OK;
80058 IncrMerger *pIncr = pReadr->pIncr;
80059 SortSubtask *pTask = pIncr->pTask;
80060 sqlite3 *db = pTask->pSorter->db;
80061
80062 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
80063 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
80064
80065 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
80066
80067 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
80068 ** requires two temp files to itself, whereas a single-threaded object
80069 ** only requires a region of pTask->file2. */
80070 if( rc==SQLITE_OK ){
80071 int mxSz = pIncr->mxSz;
80072 #if SQLITE_MAX_WORKER_THREADS>0
80073 if( pIncr->bUseThread ){
80074 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
80075 if( rc==SQLITE_OK ){
80076 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
80077 }
80078 }else
80079 #endif
80080 /*if( !pIncr->bUseThread )*/{
80081 if( pTask->file2.pFd==0 ){
80082 assert( pTask->file2.iEof>0 );
80083 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
80084 pTask->file2.iEof = 0;
80085 }
80086 if( rc==SQLITE_OK ){
80087 pIncr->aFile[1].pFd = pTask->file2.pFd;
80088 pIncr->iStartOff = pTask->file2.iEof;
80089 pTask->file2.iEof += mxSz;
80090 }
80091 }
80092 }
80093
80094 #if SQLITE_MAX_WORKER_THREADS>0
80095 if( rc==SQLITE_OK && pIncr->bUseThread ){
80096 /* Use the current thread to populate aFile[1], even though this
80097 ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
80098 ** then this function is already running in background thread
80099 ** pIncr->pTask->thread.
80100 **
80101 ** If this is the INCRINIT_ROOT object, then it is running in the
80102 ** main VDBE thread. But that is Ok, as that thread cannot return
80103 ** control to the VDBE or proceed with anything useful until the
80104 ** first results are ready from this merger object anyway.
80105 */
80106 assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
80107 rc = vdbeIncrPopulate(pIncr);
80108 }
80109 #endif
80110
80111 if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
80112 rc = vdbePmaReaderNext(pReadr);
80113 }
80114
80115 return rc;
80116 }
80117
80118 #if SQLITE_MAX_WORKER_THREADS>0
80119 /*
80120 ** The main routine for vdbePmaReaderIncrMergeInit() operations run in
80121 ** background threads.
80122 */
80123 static void *vdbePmaReaderBgIncrInit(void *pCtx){
80124 PmaReader *pReader = (PmaReader*)pCtx;
80125 void *pRet = SQLITE_INT_TO_PTR(
80126 vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
80127 );
80128 pReader->pIncr->pTask->bDone = 1;
80129 return pRet;
80130 }
80131 #endif
80132
80133 /*
80134 ** If the PmaReader passed as the first argument is not an incremental-reader
80135 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
80136 ** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
80137 ** this routine to initialize the incremental merge.
80138 **
80139 ** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
80140 ** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
80141 ** Or, if the IncrMerger is single threaded, the same function is called
80142 ** using the current thread.
80143 */
80144 static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){
80145 IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */
80146 int rc = SQLITE_OK; /* Return code */
80147 if( pIncr ){
80148 #if SQLITE_MAX_WORKER_THREADS>0
80149 assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
80150 if( pIncr->bUseThread ){
80151 void *pCtx = (void*)pReadr;
80152 rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx);
80153 }else
80154 #endif
80155 {
80156 rc = vdbePmaReaderIncrMergeInit(pReadr, eMode);
80157 }
80158 }
80159 return rc;
80160 }
 
80161
80162 /*
80163 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
80164 ** PMAs from pTask->file. If no error occurs, set *ppOut to point to
80165 ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80367,15 @@
80367 int rc; /* Return code */
80368 SortSubtask *pTask0 = &pSorter->aTask[0];
80369 MergeEngine *pMain = 0;
80370 #if SQLITE_MAX_WORKER_THREADS
80371 sqlite3 *db = pTask0->pSorter->db;
80372 int i;
80373 SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
80374 for(i=0; i<pSorter->nTask; i++){
80375 pSorter->aTask[i].xCompare = xCompare;
80376 }
80377 #endif
80378
80379 rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
80380 if( rc==SQLITE_OK ){
80381 #if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80400,25 @@
80400 vdbeIncrMergerSetThreads(pIncr);
80401 assert( pIncr->pTask!=pLast );
80402 }
80403 }
80404 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
80405 /* Check that:
80406 **
80407 ** a) The incremental merge object is configured to use the
80408 ** right task, and
80409 ** b) If it is using task (nTask-1), it is configured to run
80410 ** in single-threaded mode. This is important, as the
80411 ** root merge (INCRINIT_ROOT) will be using the same task
80412 ** object.
80413 */
80414 PmaReader *p = &pMain->aReadr[iTask];
80415 assert( p->pIncr==0 || (
80416 (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */
80417 && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
80418 ));
80419 rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
 
 
 
80420 }
80421 }
80422 pMain = 0;
80423 }
80424 if( rc==SQLITE_OK ){
@@ -81023,11 +81369,11 @@
81369 ** Should be transformed into:
81370 **
81371 ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
81372 **
81373 ** The nSubquery parameter specifies how many levels of subquery the
81374 ** alias is removed from the original expression. The usual value is
81375 ** zero but it might be more if the alias is contained within a subquery
81376 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
81377 ** structures must be increased by the nSubquery amount.
81378 */
81379 static void resolveAlias(
@@ -81043,11 +81389,10 @@
81389 sqlite3 *db; /* The database connection */
81390
81391 assert( iCol>=0 && iCol<pEList->nExpr );
81392 pOrig = pEList->a[iCol].pExpr;
81393 assert( pOrig!=0 );
 
81394 db = pParse->db;
81395 pDup = sqlite3ExprDup(db, pOrig, 0);
81396 if( pDup==0 ) return;
81397 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
81398 incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82282,15 @@
82282 pNew->flags |= EP_IntValue;
82283 pNew->u.iValue = iCol;
82284 if( pItem->pExpr==pE ){
82285 pItem->pExpr = pNew;
82286 }else{
82287 Expr *pParent = pItem->pExpr;
82288 assert( pParent->op==TK_COLLATE );
82289 while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
82290 assert( pParent->pLeft==pE );
82291 pParent->pLeft = pNew;
82292 }
82293 sqlite3ExprDelete(db, pE);
82294 pItem->u.x.iOrderByCol = (u16)iCol;
82295 pItem->done = 1;
82296 }else{
@@ -82139,11 +82486,11 @@
82486 ** as if it were part of the sub-query, not the parent. This block
82487 ** moves the pOrderBy down to the sub-query. It will be moved back
82488 ** after the names have been resolved. */
82489 if( p->selFlags & SF_Converted ){
82490 Select *pSub = p->pSrc->a[0].pSelect;
82491 assert( p->pSrc->nSrc==1 && p->pOrderBy );
82492 assert( pSub->pPrior && pSub->pOrderBy==0 );
82493 pSub->pOrderBy = p->pOrderBy;
82494 p->pOrderBy = 0;
82495 }
82496
@@ -82241,12 +82588,19 @@
82588
82589 /* Process the ORDER BY clause for singleton SELECT statements.
82590 ** The ORDER BY clause for compounds SELECT statements is handled
82591 ** below, after all of the result-sets for all of the elements of
82592 ** the compound have been resolved.
82593 **
82594 ** If there is an ORDER BY clause on a term of a compound-select other
82595 ** than the right-most term, then that is a syntax error. But the error
82596 ** is not detected until much later, and so we need to go ahead and
82597 ** resolve those symbols on the incorrect ORDER BY for consistency.
82598 */
82599 if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
82600 && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
82601 ){
82602 return WRC_Abort;
82603 }
82604 if( db->mallocFailed ){
82605 return WRC_Abort;
82606 }
@@ -83694,11 +84048,12 @@
84048 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
84049 int i;
84050 u32 m = 0;
84051 if( pList ){
84052 for(i=0; i<pList->nExpr; i++){
84053 Expr *pExpr = pList->a[i].pExpr;
84054 if( ALWAYS(pExpr) ) m |= pExpr->flags;
84055 }
84056 }
84057 return m;
84058 }
84059
@@ -84134,11 +84489,11 @@
84489 /* Check to see if an existing table or index can be used to
84490 ** satisfy the query. This is preferable to generating a new
84491 ** ephemeral table.
84492 */
84493 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84494 if( pParse->nErr==0 && isCandidateForInOpt(p) ){
84495 sqlite3 *db = pParse->db; /* Database connection */
84496 Table *pTab; /* Table <table>. */
84497 Expr *pExpr; /* Expression <column> */
84498 i16 iCol; /* Index of column <column> */
84499 i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84814,11 @@
84814 }
84815 sqlite3ExprDelete(pParse->db, pSel->pLimit);
84816 pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
84817 &sqlite3IntTokens[1]);
84818 pSel->iLimit = 0;
84819 pSel->selFlags &= ~SF_MultiValue;
84820 if( sqlite3Select(pParse, pSel, &dest) ){
84821 return 0;
84822 }
84823 rReg = dest.iSDParm;
84824 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86180,11 @@
86180 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
86181 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
86182 break;
86183 }
86184 case TK_ID: {
86185 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
86186 break;
86187 }
86188 #ifndef SQLITE_OMIT_CAST
86189 case TK_CAST: {
86190 /* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86815,11 @@
86815 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
86816 if( combinedFlags & EP_xIsSelect ) return 2;
86817 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
86818 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
86819 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86820 if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){
86821 if( pA->iColumn!=pB->iColumn ) return 2;
86822 if( pA->iTable!=pB->iTable
86823 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
86824 }
86825 }
@@ -86991,10 +87347,11 @@
87347 do {
87348 z += n;
87349 n = sqlite3GetToken(z, &token);
87350 }while( token==TK_SPACE );
87351
87352 if( token==TK_ILLEGAL ) break;
87353 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
87354 if( zParent==0 ) break;
87355 sqlite3Dequote(zParent);
87356 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
87357 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89574,21 @@
89574 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
89575 }
89576 z = argv[2];
89577
89578 if( pIndex ){
89579 tRowcnt *aiRowEst = 0;
89580 int nCol = pIndex->nKeyCol+1;
89581 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89582 /* Index.aiRowEst may already be set here if there are duplicate
89583 ** sqlite_stat1 entries for this index. In that case just clobber
89584 ** the old data with the new instead of allocating a new array. */
89585 if( pIndex->aiRowEst==0 ){
89586 pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol);
89587 if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89588 }
89589 aiRowEst = pIndex->aiRowEst;
89590 #endif
89591 pIndex->bUnordered = 0;
89592 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
89593 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
89594 }else{
@@ -89887,11 +90247,11 @@
90247 }
90248
90249 sqlite3BtreeClose(pDb->pBt);
90250 pDb->pBt = 0;
90251 pDb->pSchema = 0;
90252 sqlite3CollapseDatabaseArray(db);
90253 return;
90254
90255 detach_error:
90256 sqlite3_result_error(context, zErr, -1);
90257 }
@@ -89921,11 +90281,10 @@
90281 if(
90282 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
90283 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
90284 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
90285 ){
 
90286 goto attach_end;
90287 }
90288
90289 #ifndef SQLITE_OMIT_AUTHORIZATION
90290 if( pAuthArg ){
@@ -90580,13 +90939,15 @@
90939 sqlite3 *db;
90940 Vdbe *v;
90941
90942 assert( pParse->pToplevel==0 );
90943 db = pParse->db;
 
90944 if( pParse->nested ) return;
90945 if( db->mallocFailed || pParse->nErr ){
90946 if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
90947 return;
90948 }
90949
90950 /* Begin by generating some termination code at the end of the
90951 ** vdbe program
90952 */
90953 v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91025,11 @@
91025 }
91026
91027
91028 /* Get the VDBE program ready for execution
91029 */
91030 if( v && pParse->nErr==0 && !db->mallocFailed ){
91031 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
91032 /* A minimum of one cursor is required if autoincrement is used
91033 * See ticket [a696379c1f08866] */
91034 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
91035 sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91560,16 @@
91560 sqlite3 *db = pParse->db;
91561
91562 if( ALWAYS(pName2!=0) && pName2->n>0 ){
91563 if( db->init.busy ) {
91564 sqlite3ErrorMsg(pParse, "corrupt database");
 
91565 return -1;
91566 }
91567 *pUnqual = pName2;
91568 iDb = sqlite3FindDb(db, pName1);
91569 if( iDb<0 ){
91570 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
 
91571 return -1;
91572 }
91573 }else{
91574 assert( db->init.iDb==0 || db->init.busy );
91575 iDb = db->init.iDb;
@@ -91365,11 +91724,11 @@
91724 pTable = sqlite3FindTable(db, zName, zDb);
91725 if( pTable ){
91726 if( !noErr ){
91727 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
91728 }else{
91729 assert( !db->init.busy || CORRUPT_DB );
91730 sqlite3CodeVerifySchema(pParse, iDb);
91731 }
91732 goto begin_table_error;
91733 }
91734 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92013,12 @@
92013 Column *pCol;
92014
92015 p = pParse->pNewTable;
92016 if( p==0 || NEVER(p->nCol<1) ) return;
92017 pCol = &p->aCol[p->nCol-1];
92018 assert( pCol->zType==0 || CORRUPT_DB );
92019 sqlite3DbFree(pParse->db, pCol->zType);
92020 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
92021 pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
92022 }
92023
92024 /*
@@ -92888,10 +93248,11 @@
93248 if( db->mallocFailed ){
93249 goto exit_drop_table;
93250 }
93251 assert( pParse->nErr==0 );
93252 assert( pName->nSrc==1 );
93253 if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
93254 if( noErr ) db->suppressErr++;
93255 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
93256 if( noErr ) db->suppressErr--;
93257
93258 if( pTab==0 ){
@@ -93201,11 +93562,12 @@
93562 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
93563 }else{
93564 addr2 = sqlite3VdbeCurrentAddr(v);
93565 }
93566 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93567 sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
93568 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
93569 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
93570 sqlite3ReleaseTempReg(pParse, regRecord);
93571 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
93572 sqlite3VdbeJumpHere(v, addr1);
93573
@@ -93294,12 +93656,11 @@
93656 int nExtra = 0; /* Space allocated for zExtra[] */
93657 int nExtraCol; /* Number of extra columns needed */
93658 char *zExtra = 0; /* Extra space after the Index object */
93659 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
93660
93661 if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
 
93662 goto exit_create_index;
93663 }
93664 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
93665 goto exit_create_index;
93666 }
@@ -94214,11 +94575,10 @@
94575 ** operator with A. This routine shifts that operator over to B.
94576 */
94577 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
94578 if( p ){
94579 int i;
 
94580 for(i=p->nSrc-1; i>0; i--){
94581 p->a[i].jointype = p->a[i-1].jointype;
94582 }
94583 p->a[0].jointype = 0;
94584 }
@@ -94461,12 +94821,11 @@
94821 char *zErr;
94822 int j;
94823 StrAccum errMsg;
94824 Table *pTab = pIdx->pTable;
94825
94826 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
 
94827 for(j=0; j<pIdx->nKeyCol; j++){
94828 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
94829 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
94830 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
94831 sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96650,17 @@
96650 ){
96651 PrintfArguments x;
96652 StrAccum str;
96653 const char *zFormat;
96654 int n;
96655 sqlite3 *db = sqlite3_context_db_handle(context);
96656
96657 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
96658 x.nArg = argc-1;
96659 x.nUsed = 0;
96660 x.apArg = argv+1;
96661 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
 
96662 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
96663 n = str.nChar;
96664 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
96665 SQLITE_DYNAMIC);
96666 }
@@ -96447,11 +96806,11 @@
96806 sqlite3_result_double(context, r);
96807 }
96808 #endif
96809
96810 /*
96811 ** Allocate nByte bytes of space using sqlite3Malloc(). If the
96812 ** allocation fails, call sqlite3_result_error_nomem() to notify
96813 ** the database handle that malloc() has failed and return NULL.
96814 ** If nByte is larger than the maximum string or blob length, then
96815 ** raise an SQLITE_TOOBIG exception and return NULL.
96816 */
@@ -97116,11 +97475,11 @@
97475 int argc,
97476 sqlite3_value **argv
97477 ){
97478 unsigned char *z, *zOut;
97479 int i;
97480 zOut = z = sqlite3_malloc64( argc*4+1 );
97481 if( z==0 ){
97482 sqlite3_result_error_nomem(context);
97483 return;
97484 }
97485 for(i=0; i<argc; i++){
@@ -97264,11 +97623,11 @@
97623 sqlite3_result_error_toobig(context);
97624 sqlite3_free(zOut);
97625 return;
97626 }
97627 zOld = zOut;
97628 zOut = sqlite3_realloc64(zOut, (int)nOut);
97629 if( zOut==0 ){
97630 sqlite3_result_error_nomem(context);
97631 sqlite3_free(zOld);
97632 return;
97633 }
@@ -97626,12 +97985,11 @@
97985 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
97986 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
97987
97988 if( pAccum ){
97989 sqlite3 *db = sqlite3_context_db_handle(context);
97990 int firstTerm = pAccum->mxAlloc==0;
 
97991 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
97992 if( !firstTerm ){
97993 if( argc==2 ){
97994 zSep = (char*)sqlite3_value_text(argv[1]);
97995 nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99405,12 @@
99405 int iFromCol; /* Idx of column in child table */
99406 Expr *pEq; /* tFromCol = OLD.tToCol */
99407
99408 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
99409 assert( iFromCol>=0 );
99410 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
99411 tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName;
99412 tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
99413
99414 tToCol.n = sqlite3Strlen30(tToCol.z);
99415 tFromCol.n = sqlite3Strlen30(tFromCol.z);
99416
@@ -99059,14 +99418,14 @@
99418 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
99419 ** that the affinity and collation sequence associated with the
99420 ** parent table are used for the comparison. */
99421 pEq = sqlite3PExpr(pParse, TK_EQ,
99422 sqlite3PExpr(pParse, TK_DOT,
99423 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99424 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
99425 , 0),
99426 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
99427 , 0);
99428 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
99429
99430 /* For ON UPDATE, construct the next term of the WHEN clause.
99431 ** The final WHEN clause will be like this:
@@ -99074,27 +99433,27 @@
99433 ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
99434 */
99435 if( pChanges ){
99436 pEq = sqlite3PExpr(pParse, TK_IS,
99437 sqlite3PExpr(pParse, TK_DOT,
99438 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99439 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
99440 0),
99441 sqlite3PExpr(pParse, TK_DOT,
99442 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99443 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
99444 0),
99445 0);
99446 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
99447 }
99448
99449 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
99450 Expr *pNew;
99451 if( action==OE_Cascade ){
99452 pNew = sqlite3PExpr(pParse, TK_DOT,
99453 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99454 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
99455 , 0);
99456 }else if( action==OE_SetDflt ){
99457 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
99458 if( pDflt ){
99459 pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99496,16 @@
99496 db->lookaside.bEnabled = 0;
99497
99498 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
99499 sizeof(Trigger) + /* struct Trigger */
99500 sizeof(TriggerStep) + /* Single step in trigger program */
99501 nFrom + 1 /* Space for pStep->zTarget */
99502 );
99503 if( pTrigger ){
99504 pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99505 pStep->zTarget = (char *)&pStep[1];
99506 memcpy((char *)pStep->zTarget, zFrom, nFrom);
 
99507
99508 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99509 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
99510 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99511 if( pWhen ){
@@ -99608,24 +99966,27 @@
99966 );
99967
99968 /*
99969 ** This routine is called to handle SQL of the following forms:
99970 **
99971 ** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
99972 ** insert into TABLE (IDLIST) select
99973 ** insert into TABLE (IDLIST) default values
99974 **
99975 ** The IDLIST following the table name is always optional. If omitted,
99976 ** then a list of all (non-hidden) columns for the table is substituted.
99977 ** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
99978 ** is omitted.
99979 **
99980 ** For the pSelect parameter holds the values to be inserted for the
99981 ** first two forms shown above. A VALUES clause is really just short-hand
99982 ** for a SELECT statement that omits the FROM clause and everything else
99983 ** that follows. If the pSelect parameter is NULL, that means that the
99984 ** DEFAULT VALUES form of the INSERT statement is intended.
99985 **
99986 ** The code generated follows one of four templates. For a simple
99987 ** insert with data coming from a single-row VALUES clause, the code executes
99988 ** once straight down through. Pseudo-code follows (we call this
99989 ** the "1st template"):
99990 **
99991 ** open write cursor to <table> and its indices
99992 ** put VALUES clause expressions into registers
@@ -99728,11 +100089,11 @@
100089 int iDb; /* Index of database holding TABLE */
100090 Db *pDb; /* The database containing table being inserted into */
100091 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
100092 u8 appendFlag = 0; /* True if the insert is likely to be an append */
100093 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
100094 u8 bIdListInOrder; /* True if IDLIST is in table order */
100095 ExprList *pList = 0; /* List of VALUES() to be inserted */
100096
100097 /* Register allocations */
100098 int regFromSelect = 0;/* Base register for data coming from SELECT */
100099 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100114,12 @@
100114 if( pParse->nErr || db->mallocFailed ){
100115 goto insert_cleanup;
100116 }
100117
100118 /* If the Select object is really just a simple VALUES() list with a
100119 ** single row (the common case) then keep that one row of values
100120 ** and discard the other (unused) parts of the pSelect object
100121 */
100122 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
100123 pList = pSelect->pEList;
100124 pSelect->pEList = 0;
100125 sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100223,11 @@
100223 ** the index into IDLIST of the primary key column. ipkColumn is
100224 ** the index of the primary key as it appears in IDLIST, not as
100225 ** is appears in the original table. (The index of the INTEGER
100226 ** PRIMARY KEY in the original table is pTab->iPKey.)
100227 */
100228 bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0;
100229 if( pColumn ){
100230 for(i=0; i<pColumn->nId; i++){
100231 pColumn->a[i].idx = -1;
100232 }
100233 for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100259,12 @@
100259 ** is coming from a SELECT statement, then generate a co-routine that
100260 ** produces a single row of the SELECT on each invocation. The
100261 ** co-routine is the common header to the 3rd and 4th templates.
100262 */
100263 if( pSelect ){
100264 /* Data is coming from a SELECT or from a multi-row VALUES clause.
100265 ** Generate a co-routine to run the SELECT. */
100266 int regYield; /* Register holding co-routine entry-point */
100267 int addrTop; /* Top of the co-routine */
100268 int rc; /* Result code */
100269
100270 regYield = ++pParse->nMem;
@@ -99910,12 +100273,11 @@
100273 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
100274 dest.iSdst = bIdListInOrder ? regData : 0;
100275 dest.nSdst = pTab->nCol;
100276 rc = sqlite3Select(pParse, pSelect, &dest);
100277 regFromSelect = dest.iSdst;
100278 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
 
100279 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
100280 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
100281 assert( pSelect->pEList );
100282 nColumn = pSelect->pEList->nExpr;
100283
@@ -99959,12 +100321,12 @@
100321 sqlite3VdbeJumpHere(v, addrL);
100322 sqlite3ReleaseTempReg(pParse, regRec);
100323 sqlite3ReleaseTempReg(pParse, regTempRowid);
100324 }
100325 }else{
100326 /* This is the case if the data for the INSERT is coming from a
100327 ** single-row VALUES clause
100328 */
100329 NameContext sNC;
100330 memset(&sNC, 0, sizeof(sNC));
100331 sNC.pParse = pParse;
100332 srcTab = -1;
@@ -101031,10 +101393,11 @@
101393 Table *pDest, /* The table we are inserting into */
101394 Select *pSelect, /* A SELECT statement to use as the data source */
101395 int onError, /* How to handle constraint errors */
101396 int iDbDest /* The database of pDest */
101397 ){
101398 sqlite3 *db = pParse->db;
101399 ExprList *pEList; /* The result set of the SELECT */
101400 Table *pSrc; /* The table in the FROM clause of SELECT */
101401 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101402 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101403 int i; /* Loop counter */
@@ -101178,15 +101541,15 @@
101541 ** But the main beneficiary of the transfer optimization is the VACUUM
101542 ** command, and the VACUUM command disables foreign key constraints. So
101543 ** the extra complication to make this rule less restrictive is probably
101544 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101545 */
101546 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101547 return 0;
101548 }
101549 #endif
101550 if( (db->flags & SQLITE_CountRows)!=0 ){
101551 return 0; /* xfer opt does not play well with PRAGMA count_changes */
101552 }
101553
101554 /* If we get this far, it means that the xfer optimization is at
101555 ** least a possibility, though it might only work if the destination
@@ -101193,28 +101556,32 @@
101556 ** table (tab1) is initially empty.
101557 */
101558 #ifdef SQLITE_TEST
101559 sqlite3_xferopt_count++;
101560 #endif
101561 iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
101562 v = sqlite3GetVdbe(pParse);
101563 sqlite3CodeVerifySchema(pParse, iDbSrc);
101564 iSrc = pParse->nTab++;
101565 iDest = pParse->nTab++;
101566 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101567 regData = sqlite3GetTempReg(pParse);
101568 regRowid = sqlite3GetTempReg(pParse);
101569 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101570 assert( HasRowid(pDest) || destHasUniqueIdx );
101571 if( (db->flags & SQLITE_Vacuum)==0 && (
101572 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101573 || destHasUniqueIdx /* (2) */
101574 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101575 )){
101576 /* In some circumstances, we are able to run the xfer optimization
101577 ** only if the destination table is initially empty. Unless the
101578 ** SQLITE_Vacuum flag is set, this block generates code to make
101579 ** that determination. If SQLITE_Vacuum is set, then the destination
101580 ** table is always empty.
101581 **
101582 ** Conditions under which the destination must be empty:
101583 **
101584 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
101585 ** (If the destination is not initially empty, the rowid fields
101586 ** of index entries might need to change.)
101587 **
@@ -101253,10 +101620,11 @@
101620 }else{
101621 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101622 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101623 }
101624 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
101625 u8 useSeekResult = 0;
101626 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101627 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101628 }
101629 assert( pSrcIdx );
101630 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101634,37 @@
101634 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101635 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101636 VdbeComment((v, "%s", pDestIdx->zName));
101637 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101638 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
101639 if( db->flags & SQLITE_Vacuum ){
101640 /* This INSERT command is part of a VACUUM operation, which guarantees
101641 ** that the destination table is empty. If all indexed columns use
101642 ** collation sequence BINARY, then it can also be assumed that the
101643 ** index will be populated by inserting keys in strictly sorted
101644 ** order. In this case, instead of seeking within the b-tree as part
101645 ** of every OP_IdxInsert opcode, an OP_Last is added before the
101646 ** OP_IdxInsert to seek to the point within the b-tree where each key
101647 ** should be inserted. This is faster.
101648 **
101649 ** If any of the indexed columns use a collation sequence other than
101650 ** BINARY, this optimization is disabled. This is because the user
101651 ** might change the definition of a collation sequence and then run
101652 ** a VACUUM command. In that case keys may not be written in strictly
101653 ** sorted order. */
101654 for(i=0; i<pSrcIdx->nColumn; i++){
101655 char *zColl = pSrcIdx->azColl[i];
101656 assert( zColl!=0 );
101657 if( sqlite3_stricmp("BINARY", zColl) ) break;
101658 }
101659 if( i==pSrcIdx->nColumn ){
101660 useSeekResult = OPFLAG_USESEEKRESULT;
101661 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
101662 }
101663 }
101664 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
101665 sqlite3VdbeChangeP5(v, useSeekResult);
101666 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101667 sqlite3VdbeJumpHere(v, addr1);
101668 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101669 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101670 }
@@ -102385,11 +102779,11 @@
102779 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102780 char *zErrmsg = 0;
102781 const char *zEntry;
102782 char *zAltEntry = 0;
102783 void **aHandle;
102784 u64 nMsg = 300 + sqlite3Strlen30(zFile);
102785 int ii;
102786
102787 /* Shared library endings to try if zFile cannot be loaded as written */
102788 static const char *azEndings[] = {
102789 #if SQLITE_OS_WIN
@@ -102428,11 +102822,11 @@
102822 sqlite3_free(zAltFile);
102823 }
102824 #endif
102825 if( handle==0 ){
102826 if( pzErrMsg ){
102827 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102828 if( zErrmsg ){
102829 sqlite3_snprintf(nMsg, zErrmsg,
102830 "unable to open shared library [%s]", zFile);
102831 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102832 }
@@ -102454,11 +102848,11 @@
102848 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102849 */
102850 if( xInit==0 && zProc==0 ){
102851 int iFile, iEntry, c;
102852 int ncFile = sqlite3Strlen30(zFile);
102853 zAltEntry = sqlite3_malloc64(ncFile+30);
102854 if( zAltEntry==0 ){
102855 sqlite3OsDlClose(pVfs, handle);
102856 return SQLITE_NOMEM;
102857 }
102858 memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102870,11 @@
102870 sqlite3OsDlSym(pVfs, handle, zEntry);
102871 }
102872 if( xInit==0 ){
102873 if( pzErrMsg ){
102874 nMsg += sqlite3Strlen30(zEntry);
102875 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102876 if( zErrmsg ){
102877 sqlite3_snprintf(nMsg, zErrmsg,
102878 "no entry point [%s] in shared library [%s]", zEntry, zFile);
102879 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102880 }
@@ -102575,11 +102969,11 @@
102969 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102970 ** mutex must be held while accessing this list.
102971 */
102972 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102973 static SQLITE_WSD struct sqlite3AutoExtList {
102974 u32 nExt; /* Number of entries in aExt[] */
102975 void (**aExt)(void); /* Pointers to the extension init functions */
102976 } sqlite3Autoext = { 0, 0 };
102977
102978 /* The "wsdAutoext" macro will resolve to the autoextension
102979 ** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103002,23 @@
103002 if( rc ){
103003 return rc;
103004 }else
103005 #endif
103006 {
103007 u32 i;
103008 #if SQLITE_THREADSAFE
103009 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
103010 #endif
103011 wsdAutoextInit;
103012 sqlite3_mutex_enter(mutex);
103013 for(i=0; i<wsdAutoext.nExt; i++){
103014 if( wsdAutoext.aExt[i]==xInit ) break;
103015 }
103016 if( i==wsdAutoext.nExt ){
103017 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
103018 void (**aNew)(void);
103019 aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
103020 if( aNew==0 ){
103021 rc = SQLITE_NOMEM;
103022 }else{
103023 wsdAutoext.aExt = aNew;
103024 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103046,11 @@
103046 #endif
103047 int i;
103048 int n = 0;
103049 wsdAutoextInit;
103050 sqlite3_mutex_enter(mutex);
103051 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
103052 if( wsdAutoext.aExt[i]==xInit ){
103053 wsdAutoext.nExt--;
103054 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
103055 n++;
103056 break;
@@ -102690,11 +103084,11 @@
103084 ** Load all automatic extensions.
103085 **
103086 ** If anything goes wrong, set an error in the database connection.
103087 */
103088 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
103089 u32 i;
103090 int go = 1;
103091 int rc;
103092 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
103093
103094 wsdAutoextInit;
@@ -103354,19 +103748,19 @@
103748 /*
103749 ** Generate code to return a single integer value.
103750 */
103751 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103752 Vdbe *v = sqlite3GetVdbe(pParse);
103753 int nMem = ++pParse->nMem;
103754 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103755 if( pI64 ){
103756 memcpy(pI64, &value, sizeof(value));
103757 }
103758 sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
103759 sqlite3VdbeSetNumCols(v, 1);
103760 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103761 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103762 }
103763
103764
103765 /*
103766 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103921,15 @@
103921 aFcntl[3] = 0;
103922 db->busyHandler.nBusy = 0;
103923 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103924 if( rc==SQLITE_OK ){
103925 if( aFcntl[0] ){
103926 int nMem = ++pParse->nMem;
103927 sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
103928 sqlite3VdbeSetNumCols(v, 1);
103929 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103930 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103931 sqlite3_free(aFcntl[0]);
103932 }
103933 goto pragma_out;
103934 }
103935 if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104530,13 @@
104530 }else{
104531 if( !db->autoCommit ){
104532 sqlite3ErrorMsg(pParse,
104533 "Safety level may not be changed inside a transaction");
104534 }else{
104535 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
104536 if( iLevel==0 ) iLevel = 1;
104537 pDb->safety_level = iLevel;
104538 setAllPagerFlags(db);
104539 }
104540 }
104541 break;
104542 }
@@ -104231,11 +104627,11 @@
104627 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104628 k = 0;
104629 }else if( pPk==0 ){
104630 k = 1;
104631 }else{
104632 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
104633 }
104634 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104635 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104636 }
104637 }
@@ -105237,11 +105633,11 @@
105633
105634 assert( iDb>=0 && iDb<db->nDb );
105635 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105636 if( argv[1]==0 ){
105637 corruptSchema(pData, argv[0], 0);
105638 }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){
105639 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105640 ** But because db->init.busy is set to 1, no VDBE code is generated
105641 ** or executed. All the parser does is build the internal data
105642 ** structures that describe the table, index, or view.
105643 */
@@ -105268,12 +105664,12 @@
105664 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105665 }
105666 }
105667 }
105668 sqlite3_finalize(pStmt);
105669 }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
105670 corruptSchema(pData, argv[0], 0);
105671 }else{
105672 /* If the SQL column is blank it means this is an index that
105673 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105674 ** constraint for a CREATE TABLE. The index should have already
105675 ** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106572,10 @@
106572 ){
106573 Select *pNew;
106574 Select standin;
106575 sqlite3 *db = pParse->db;
106576 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
 
106577 if( pNew==0 ){
106578 assert( db->mallocFailed );
106579 pNew = &standin;
106580 memset(pNew, 0, sizeof(*pNew));
106581 }
@@ -106196,11 +106591,11 @@
106591 pNew->pOrderBy = pOrderBy;
106592 pNew->selFlags = selFlags;
106593 pNew->op = TK_SELECT;
106594 pNew->pLimit = pLimit;
106595 pNew->pOffset = pOffset;
106596 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
106597 pNew->addrOpenEphm[0] = -1;
106598 pNew->addrOpenEphm[1] = -1;
106599 if( db->mallocFailed ) {
106600 clearSelect(db, pNew, pNew!=&standin);
106601 pNew = 0;
@@ -107446,11 +107841,11 @@
107841 if( pS ){
107842 /* The "table" is actually a sub-select or a view in the FROM clause
107843 ** of the SELECT statement. Return the declaration type and origin
107844 ** data for the result-set column of the sub-select.
107845 */
107846 if( iCol>=0 && iCol<pS->pEList->nExpr ){
107847 /* If iCol is less than zero, then the expression requests the
107848 ** rowid of the sub-select or view. This expression is legal (see
107849 ** test case misc2.2.2) - it always evaluates to NULL.
107850 */
107851 NameContext sNC;
@@ -107766,16 +108161,18 @@
108161 memset(&sNC, 0, sizeof(sNC));
108162 sNC.pSrcList = pSelect->pSrc;
108163 a = pSelect->pEList->a;
108164 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
108165 p = a[i].pExpr;
108166 if( pCol->zType==0 ){
108167 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108168 }
108169 szAll += pCol->szEst;
108170 pCol->affinity = sqlite3ExprAffinity(p);
108171 if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
108172 pColl = sqlite3ExprCollSeq(pParse, p);
108173 if( pColl && pCol->zColl==0 ){
108174 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
108175 }
108176 }
108177 pTab->szTabRow = sqlite3LogEst(szAll*4);
108178 }
@@ -108173,12 +108570,11 @@
108570 ){
108571 Select *pPrior;
108572 int nExpr = p->pEList->nExpr;
108573 int nRow = 1;
108574 int rc = 0;
108575 assert( p->selFlags & SF_MultiValue );
 
108576 do{
108577 assert( p->selFlags & SF_Values );
108578 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108579 assert( p->pLimit==0 );
108580 assert( p->pOffset==0 );
@@ -108283,11 +108679,11 @@
108679 dest.eDest = SRT_Table;
108680 }
108681
108682 /* Special handling for a compound-select that originates as a VALUES clause.
108683 */
108684 if( p->selFlags & SF_MultiValue ){
108685 rc = multiSelectValues(pParse, p, &dest);
108686 goto multi_select_end;
108687 }
108688
108689 /* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109064,11 @@
109064 ** then there should be a single item on the stack. Write this
109065 ** item into the set table with bogus data.
109066 */
109067 case SRT_Set: {
109068 int r1;
109069 assert( pIn->nSdst==1 || pParse->nErr>0 );
109070 pDest->affSdst =
109071 sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
109072 r1 = sqlite3GetTempReg(pParse);
109073 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
109074 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109090,11 @@
109090 /* If this is a scalar select that is part of an expression, then
109091 ** store the results in the appropriate memory cell and break out
109092 ** of the scan loop.
109093 */
109094 case SRT_Mem: {
109095 assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 );
109096 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
109097 /* The LIMIT clause will jump out of the loop for us */
109098 break;
109099 }
109100 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109105,11 @@
109105 case SRT_Coroutine: {
109106 if( pDest->iSdst==0 ){
109107 pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
109108 pDest->nSdst = pIn->nSdst;
109109 }
109110 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
109111 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
109112 break;
109113 }
109114
109115 /* If none of the above, then the result destination must be
@@ -108925,12 +109321,14 @@
109321 */
109322 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
109323 if( aPermute ){
109324 struct ExprList_item *pItem;
109325 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
109326 assert( pItem->u.x.iOrderByCol>0 );
109327 /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true
109328 ** but only for well-formed SELECT statements. */
109329 testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr );
109330 aPermute[i] = pItem->u.x.iOrderByCol - 1;
109331 }
109332 pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
109333 }else{
109334 pKeyMerge = 0;
@@ -109136,11 +109534,11 @@
109534 pPrior->pNext = p;
109535
109536 /*** TBD: Insert subroutine calls to close cursors on incomplete
109537 **** subqueries ****/
109538 explainComposite(pParse, p->op, iSub1, iSub2, 0);
109539 return pParse->nErr!=0;
109540 }
109541 #endif
109542
109543 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109544 /* Forward Declarations */
@@ -109948,10 +110346,11 @@
110346 pNew->pGroupBy = 0;
110347 pNew->pHaving = 0;
110348 pNew->pOrderBy = 0;
110349 p->pPrior = 0;
110350 p->pNext = 0;
110351 p->pWith = 0;
110352 p->selFlags &= ~SF_Compound;
110353 assert( (p->selFlags & SF_Converted)==0 );
110354 p->selFlags |= SF_Converted;
110355 assert( pNew->pPrior!=0 );
110356 pNew->pPrior->pNext = pNew;
@@ -110486,11 +110885,11 @@
110885 if( pParse->hasCompound ){
110886 w.xSelectCallback = convertCompoundSelectToSubquery;
110887 sqlite3WalkSelect(&w, pSelect);
110888 }
110889 w.xSelectCallback = selectExpander;
110890 if( (pSelect->selFlags & SF_MultiValue)==0 ){
110891 w.xSelectCallback2 = selectPopWith;
110892 }
110893 sqlite3WalkSelect(&w, pSelect);
110894 }
110895
@@ -110672,11 +111071,12 @@
111071 nArg = 0;
111072 regAgg = 0;
111073 }
111074 if( pF->iDistinct>=0 ){
111075 addrNext = sqlite3VdbeMakeLabel(v);
111076 testcase( nArg==0 ); /* Error condition */
111077 testcase( nArg>1 ); /* Also an error */
111078 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
111079 }
111080 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
111081 CollSeq *pColl = 0;
111082 struct ExprList_item *pItem;
@@ -111547,14 +111947,13 @@
111947
111948 /* Jump here to skip this query
111949 */
111950 sqlite3VdbeResolveLabel(v, iEnd);
111951
111952 /* The SELECT has been coded. If there is an error in the Parse structure,
111953 ** set the return code to 1. Otherwise 0. */
111954 rc = (pParse->nErr>0);
 
111955
111956 /* Control jumps to here if an error is encountered above, or upon
111957 ** successful coding of the SELECT.
111958 */
111959 select_end:
@@ -111601,11 +112000,11 @@
112000 sqlite3TreeViewLine(pView, "FROM");
112001 for(i=0; i<p->pSrc->nSrc; i++){
112002 struct SrcList_item *pItem = &p->pSrc->a[i];
112003 StrAccum x;
112004 char zLine[100];
112005 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
112006 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
112007 if( pItem->zDatabase ){
112008 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
112009 }else if( pItem->zName ){
112010 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112159,11 @@
112159 for(i=0; i<nCol; i++){
112160 if( argv[i]==0 ){
112161 z = 0;
112162 }else{
112163 int n = sqlite3Strlen30(argv[i])+1;
112164 z = sqlite3_malloc64( n );
112165 if( z==0 ) goto malloc_failed;
112166 memcpy(z, argv[i], n);
112167 }
112168 p->azResult[p->nData++] = z;
112169 }
@@ -111809,11 +112208,11 @@
112208 res.nRow = 0;
112209 res.nColumn = 0;
112210 res.nData = 1;
112211 res.nAlloc = 20;
112212 res.rc = SQLITE_OK;
112213 res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
112214 if( res.azResult==0 ){
112215 db->errCode = SQLITE_NOMEM;
112216 return SQLITE_NOMEM;
112217 }
112218 res.azResult[0] = 0;
@@ -111837,11 +112236,11 @@
112236 sqlite3_free_table(&res.azResult[1]);
112237 return rc;
112238 }
112239 if( res.nAlloc>res.nData ){
112240 char **azNew;
112241 azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData );
112242 if( azNew==0 ){
112243 sqlite3_free_table(&res.azResult[1]);
112244 db->errCode = SQLITE_NOMEM;
112245 return SQLITE_NOMEM;
112246 }
@@ -112065,11 +112464,10 @@
112464 }
112465
112466 /* Do not create a trigger on a system table */
112467 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112468 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
 
112469 goto trigger_cleanup;
112470 }
112471
112472 /* INSTEAD of triggers are only for views and views only support INSTEAD
112473 ** of triggers.
@@ -112245,16 +112643,16 @@
112643 u8 op, /* Trigger opcode */
112644 Token *pName /* The target name */
112645 ){
112646 TriggerStep *pTriggerStep;
112647
112648 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
112649 if( pTriggerStep ){
112650 char *z = (char*)&pTriggerStep[1];
112651 memcpy(z, pName->z, pName->n);
112652 sqlite3Dequote(z);
112653 pTriggerStep->zTarget = z;
112654 pTriggerStep->op = op;
112655 }
112656 return pTriggerStep;
112657 }
112658
@@ -112533,11 +112931,11 @@
112931 }
112932 return (mask ? pList : 0);
112933 }
112934
112935 /*
112936 ** Convert the pStep->zTarget string into a SrcList and return a pointer
112937 ** to that SrcList.
112938 **
112939 ** This routine adds a specific database name, if needed, to the target when
112940 ** forming the SrcList. This prevents a trigger in one database from
112941 ** referring to a target in another database. An exception is when the
@@ -112546,21 +112944,21 @@
112944 */
112945 static SrcList *targetSrcList(
112946 Parse *pParse, /* The parsing context */
112947 TriggerStep *pStep /* The trigger containing the target token */
112948 ){
112949 sqlite3 *db = pParse->db;
112950 int iDb; /* Index of the database to use */
112951 SrcList *pSrc; /* SrcList to be returned */
112952
112953 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112954 if( pSrc ){
112955 assert( pSrc->nSrc>0 );
112956 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
112957 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
112958 if( iDb==0 || iDb>=2 ){
112959 assert( iDb<db->nDb );
 
112960 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112961 }
112962 }
112963 return pSrc;
112964 }
@@ -112668,10 +113066,11 @@
113066 assert( pFrom->zErrMsg==0 || pFrom->nErr );
113067 assert( pTo->zErrMsg==0 || pTo->nErr );
113068 if( pTo->nErr==0 ){
113069 pTo->zErrMsg = pFrom->zErrMsg;
113070 pTo->nErr = pFrom->nErr;
113071 pTo->rc = pFrom->rc;
113072 }else{
113073 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
113074 }
113075 }
113076
@@ -114018,17 +114417,21 @@
114417
114418 /* Loop through the tables in the main database. For each, do
114419 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114420 ** the contents to the temporary database.
114421 */
114422 assert( (db->flags & SQLITE_Vacuum)==0 );
114423 db->flags |= SQLITE_Vacuum;
114424 rc = execExecSql(db, pzErrMsg,
114425 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114426 "|| ' SELECT * FROM main.' || quote(name) || ';'"
114427 "FROM main.sqlite_master "
114428 "WHERE type = 'table' AND name!='sqlite_sequence' "
114429 " AND coalesce(rootpage,1)>0"
114430 );
114431 assert( (db->flags & SQLITE_Vacuum)!=0 );
114432 db->flags &= ~SQLITE_Vacuum;
114433 if( rc!=SQLITE_OK ) goto end_of_vacuum;
114434
114435 /* Copy over the sequence table
114436 */
114437 rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114566,12 @@
114566 ** are invoked only from within xCreate and xConnect methods.
114567 */
114568 struct VtabCtx {
114569 VTable *pVTable; /* The virtual table being constructed */
114570 Table *pTab; /* The Table object to which the virtual table belongs */
114571 VtabCtx *pPrior; /* Parent context (if any) */
114572 int bDeclared; /* True after sqlite3_declare_vtab() is called */
114573 };
114574
114575 /*
114576 ** The actual function that does the work of creating a new module.
114577 ** This function implements the sqlite3_create_module() and
@@ -114609,11 +115014,11 @@
115014 Token *pArg = &pParse->sArg;
115015 if( pArg->z==0 ){
115016 pArg->z = p->z;
115017 pArg->n = p->n;
115018 }else{
115019 assert(pArg->z <= p->z);
115020 pArg->n = (int)(&p->z[p->n] - pArg->z);
115021 }
115022 }
115023
115024 /*
@@ -114626,19 +115031,31 @@
115031 Table *pTab,
115032 Module *pMod,
115033 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
115034 char **pzErr
115035 ){
115036 VtabCtx sCtx;
115037 VTable *pVTable;
115038 int rc;
115039 const char *const*azArg = (const char *const*)pTab->azModuleArg;
115040 int nArg = pTab->nModuleArg;
115041 char *zErr = 0;
115042 char *zModuleName;
115043 int iDb;
115044 VtabCtx *pCtx;
115045
115046 /* Check that the virtual-table is not already being initialized */
115047 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
115048 if( pCtx->pTab==pTab ){
115049 *pzErr = sqlite3MPrintf(db,
115050 "vtable constructor called recursively: %s", pTab->zName
115051 );
115052 return SQLITE_LOCKED;
115053 }
115054 }
115055
115056 zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
115057 if( !zModuleName ){
115058 return SQLITE_NOMEM;
115059 }
115060
115061 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115072,17 @@
115072 /* Invoke the virtual table constructor */
115073 assert( &db->pVtabCtx );
115074 assert( xConstruct );
115075 sCtx.pTab = pTab;
115076 sCtx.pVTable = pVTable;
115077 sCtx.pPrior = db->pVtabCtx;
115078 sCtx.bDeclared = 0;
115079 db->pVtabCtx = &sCtx;
115080 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
115081 db->pVtabCtx = sCtx.pPrior;
115082 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
115083 assert( sCtx.pTab==pTab );
115084
115085 if( SQLITE_OK!=rc ){
115086 if( zErr==0 ){
115087 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
115088 }else {
@@ -114675,17 +115094,18 @@
115094 /* Justification of ALWAYS(): A correct vtab constructor must allocate
115095 ** the sqlite3_vtab object if successful. */
115096 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
115097 pVTable->pVtab->pModule = pMod->pModule;
115098 pVTable->nRef = 1;
115099 if( sCtx.bDeclared==0 ){
115100 const char *zFormat = "vtable constructor did not declare schema: %s";
115101 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
115102 sqlite3VtabUnlock(pVTable);
115103 rc = SQLITE_ERROR;
115104 }else{
115105 int iCol;
115106 u8 oooHidden = 0;
115107 /* If everything went according to plan, link the new VTable structure
115108 ** into the linked list headed by pTab->pVTable. Then loop through the
115109 ** columns of the table to see if any of them contain the token "hidden".
115110 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
115111 ** the type string. */
@@ -114694,11 +115114,14 @@
115114
115115 for(iCol=0; iCol<pTab->nCol; iCol++){
115116 char *zType = pTab->aCol[iCol].zType;
115117 int nType;
115118 int i = 0;
115119 if( !zType ){
115120 pTab->tabFlags |= oooHidden;
115121 continue;
115122 }
115123 nType = sqlite3Strlen30(zType);
115124 if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
115125 for(i=0; i<nType; i++){
115126 if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
115127 && (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115140,13 @@
115140 if( zType[i]=='\0' && i>0 ){
115141 assert(zType[i-1]==' ');
115142 zType[i-1] = '\0';
115143 }
115144 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
115145 oooHidden = TF_OOOHidden;
115146 }else{
115147 pTab->tabFlags |= oooHidden;
115148 }
115149 }
115150 }
115151 }
115152
@@ -114845,12 +115271,12 @@
115271 ** This function is used to set the schema of a virtual table. It is only
115272 ** valid to call this function from within the xCreate() or xConnect() of a
115273 ** virtual table module.
115274 */
115275 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
115276 VtabCtx *pCtx;
115277 Parse *pParse;
 
115278 int rc = SQLITE_OK;
115279 Table *pTab;
115280 char *zErr = 0;
115281
115282 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115283,17 @@
115283 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
115284 return SQLITE_MISUSE_BKPT;
115285 }
115286 #endif
115287 sqlite3_mutex_enter(db->mutex);
115288 pCtx = db->pVtabCtx;
115289 if( !pCtx || pCtx->bDeclared ){
115290 sqlite3Error(db, SQLITE_MISUSE);
115291 sqlite3_mutex_leave(db->mutex);
115292 return SQLITE_MISUSE_BKPT;
115293 }
115294 pTab = pCtx->pTab;
115295 assert( (pTab->tabFlags & TF_Virtual)!=0 );
115296
115297 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
115298 if( pParse==0 ){
115299 rc = SQLITE_NOMEM;
@@ -114884,11 +115312,11 @@
115312 pTab->aCol = pParse->pNewTable->aCol;
115313 pTab->nCol = pParse->pNewTable->nCol;
115314 pParse->pNewTable->nCol = 0;
115315 pParse->pNewTable->aCol = 0;
115316 }
115317 pCtx->bDeclared = 1;
115318 }else{
115319 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
115320 sqlite3DbFree(db, zErr);
115321 rc = SQLITE_ERROR;
115322 }
@@ -115078,11 +115506,11 @@
115506 */
115507 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115508 int rc = SQLITE_OK;
115509
115510 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115511 assert( iSavepoint>=-1 );
115512 if( db->aVTrans ){
115513 int i;
115514 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115515 VTable *pVTab = db->aVTrans[i];
115516 const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115624,11 @@
115624 assert( IsVirtual(pTab) );
115625 for(i=0; i<pToplevel->nVtabLock; i++){
115626 if( pTab==pToplevel->apVtabLock[i] ) return;
115627 }
115628 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115629 apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n);
115630 if( apVtabLock ){
115631 pToplevel->apVtabLock = apVtabLock;
115632 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115633 }else{
115634 pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116423,18 @@
116423 ** In the previous sentence and in the diagram, "slot[]" refers to
116424 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
116425 ** all terms of the WHERE clause.
116426 */
116427 static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
116428 Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
116429 pWC->op = op;
116430 if( pE2==0 ) return;
116431 if( pE2->op!=op ){
116432 whereClauseInsert(pWC, pExpr, 0);
116433 }else{
116434 whereSplit(pWC, pE2->pLeft, op);
116435 whereSplit(pWC, pE2->pRight, op);
116436 }
116437 }
116438
116439 /*
116440 ** Initialize a WhereMaskSet object
@@ -117272,11 +117701,11 @@
117701 if( p->op==TK_COLUMN
117702 && p->iColumn==pIdx->aiColumn[iCol]
117703 && p->iTable==iBase
117704 ){
117705 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117706 if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117707 return i;
117708 }
117709 }
117710 }
117711
@@ -117546,11 +117975,11 @@
117975 if( (idxCols & cMask)==0 ){
117976 Expr *pX = pTerm->pExpr;
117977 idxCols |= cMask;
117978 pIdx->aiColumn[n] = pTerm->u.leftColumn;
117979 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117980 pIdx->azColl[n] = pColl ? pColl->zName : "BINARY";
117981 n++;
117982 }
117983 }
117984 }
117985 assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119271,11 @@
119271
119272 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
119273 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
119274 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
119275
119276 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
 
119277 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
119278 if( pItem->pSelect ){
119279 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
119280 }else{
119281 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120470,17 @@
120470 /*
120471 ** Free a WhereInfo structure
120472 */
120473 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120474 if( ALWAYS(pWInfo) ){
120475 int i;
120476 for(i=0; i<pWInfo->nLevel; i++){
120477 WhereLevel *pLevel = &pWInfo->a[i];
120478 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
120479 sqlite3DbFree(db, pLevel->u.in.aInLoop);
120480 }
120481 }
120482 whereClauseClear(&pWInfo->sWC);
120483 while( pWInfo->pLoops ){
120484 WhereLoop *p = pWInfo->pLoops;
120485 pWInfo->pLoops = p->pNextLoop;
120486 whereLoopDelete(db, p);
@@ -120521,11 +120956,11 @@
120956 ** changes "x IN (?)" into "x=?". */
120957
120958 }else if( eOp & (WO_EQ) ){
120959 pNew->wsFlags |= WHERE_COLUMN_EQ;
120960 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120961 if( iCol>=0 && pProbe->uniqNotNull==0 ){
120962 pNew->wsFlags |= WHERE_UNQ_WANTED;
120963 }else{
120964 pNew->wsFlags |= WHERE_ONEROW;
120965 }
120966 }
@@ -121981,11 +122416,11 @@
122416 pWInfo->nOBSat = pFrom->isOrdered;
122417 if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
122418 pWInfo->revMask = pFrom->revLoop;
122419 }
122420 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
122421 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
122422 ){
122423 Bitmask revMask = 0;
122424 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
122425 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
122426 );
@@ -122386,11 +122821,10 @@
122821 if( pParse->nErr || NEVER(db->mallocFailed) ){
122822 goto whereBeginError;
122823 }
122824 #ifdef WHERETRACE_ENABLED /* !=0 */
122825 if( sqlite3WhereTrace ){
 
122826 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122827 if( pWInfo->nOBSat>0 ){
122828 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122829 }
122830 switch( pWInfo->eDistinct ){
@@ -122639,11 +123073,10 @@
123073 VdbeCoverage(v);
123074 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
123075 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
123076 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
123077 }
 
123078 }
123079 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
123080 if( pLevel->addrSkip ){
123081 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
123082 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123283,32 @@
123283 /*
123284 ** An instance of this structure holds the ATTACH key and the key type.
123285 */
123286 struct AttachKey { int type; Token key; };
123287
123288
123289 /*
123290 ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
123291 ** all elements in the list. And make sure list length does not exceed
123292 ** SQLITE_LIMIT_COMPOUND_SELECT.
123293 */
123294 static void parserDoubleLinkSelect(Parse *pParse, Select *p){
123295 if( p->pPrior ){
123296 Select *pNext = 0, *pLoop;
123297 int mxSelect, cnt = 0;
123298 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123299 pLoop->pNext = pNext;
123300 pLoop->selFlags |= SF_Compound;
123301 }
123302 if( (p->selFlags & SF_MultiValue)==0 &&
123303 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
123304 cnt>mxSelect
123305 ){
123306 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123307 }
123308 }
123309 }
123310
123311 /* This is a utility routine used to set the ExprSpan.zStart and
123312 ** ExprSpan.zEnd values of pOut so that the span covers the complete
123313 ** range of text beginning with pStart and going to the end of pEnd.
123314 */
@@ -125167,31 +125622,14 @@
125622 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125623 }
125624 break;
125625 case 112: /* select ::= with selectnowith */
125626 {
125627 Select *p = yymsp[0].minor.yy3;
125628 if( p ){
 
125629 p->pWith = yymsp[-1].minor.yy59;
125630 parserDoubleLinkSelect(pParse, p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125631 }else{
125632 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125633 }
125634 yygotominor.yy3 = p;
125635 }
@@ -125205,16 +125643,18 @@
125643 Select *pRhs = yymsp[0].minor.yy3;
125644 if( pRhs && pRhs->pPrior ){
125645 SrcList *pFrom;
125646 Token x;
125647 x.n = 0;
125648 parserDoubleLinkSelect(pParse, pRhs);
125649 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125650 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125651 }
125652 if( pRhs ){
125653 pRhs->op = (u8)yymsp[-1].minor.yy328;
125654 pRhs->pPrior = yymsp[-2].minor.yy3;
125655 pRhs->selFlags &= ~SF_MultiValue;
125656 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125657 }else{
125658 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125659 }
125660 yygotominor.yy3 = pRhs;
@@ -125257,17 +125697,20 @@
125697 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125698 }
125699 break;
125700 case 121: /* values ::= values COMMA LP exprlist RP */
125701 {
125702 Select *pRight, *pLeft = yymsp[-4].minor.yy3;
125703 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
125704 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
125705 if( pRight ){
125706 pRight->op = TK_ALL;
125707 pLeft = yymsp[-4].minor.yy3;
125708 pRight->pPrior = pLeft;
125709 yygotominor.yy3 = pRight;
125710 }else{
125711 yygotominor.yy3 = pLeft;
125712 }
125713 }
125714 break;
125715 case 122: /* distinct ::= DISTINCT */
125716 {yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127510,12 @@
127510 goto abort_parse;
127511 }
127512 break;
127513 }
127514 case TK_ILLEGAL: {
127515 sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
 
127516 &pParse->sLastToken);
 
127517 goto abort_parse;
127518 }
127519 case TK_SEMI: {
127520 pParse->zTail = &zSql[i];
127521 /* Fall thru into the default case */
@@ -127088,16 +127529,19 @@
127529 break;
127530 }
127531 }
127532 }
127533 abort_parse:
127534 assert( nErr==0 );
127535 if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127536 if( lastTokenParsed!=TK_SEMI ){
127537 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127538 pParse->zTail = &zSql[i];
127539 }
127540 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127541 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127542 }
127543 }
127544 #ifdef YYTRACKMAXSTACKDEPTH
127545 sqlite3_mutex_enter(sqlite3MallocMutex());
127546 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127547 sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127598,11 @@
127598 while( pParse->pZombieTab ){
127599 Table *p = pParse->pZombieTab;
127600 pParse->pZombieTab = p->pNextZombie;
127601 sqlite3DeleteTable(db, p);
127602 }
127603 assert( nErr==0 || pParse->rc!=SQLITE_OK );
 
 
127604 return nErr;
127605 }
127606
127607 /************** End of tokenize.c ********************************************/
127608 /************** Begin file complete.c ****************************************/
@@ -127432,11 +127874,11 @@
127874 ** UTF-8.
127875 */
127876 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127877 sqlite3_value *pVal;
127878 char const *zSql8;
127879 int rc;
127880
127881 #ifndef SQLITE_OMIT_AUTOINIT
127882 rc = sqlite3_initialize();
127883 if( rc ) return rc;
127884 #endif
@@ -127598,10 +128040,22 @@
128040 ** zero if and only if SQLite was compiled with mutexing code omitted due to
128041 ** the SQLITE_THREADSAFE compile-time option being set to 0.
128042 */
128043 SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
128044
128045 /*
128046 ** When compiling the test fixture or with debugging enabled (on Win32),
128047 ** this variable being set to non-zero will cause OSTRACE macros to emit
128048 ** extra diagnostic information.
128049 */
128050 #ifdef SQLITE_HAVE_OS_TRACE
128051 # ifndef SQLITE_DEBUG_OS_TRACE
128052 # define SQLITE_DEBUG_OS_TRACE 0
128053 # endif
128054 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
128055 #endif
128056
128057 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
128058 /*
128059 ** If the following function pointer is not NULL and if
128060 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
128061 ** I/O active are written using this function. These messages
@@ -128737,11 +129191,11 @@
129191
129192 /*
129193 ** Return a static string containing the name corresponding to the error code
129194 ** specified in the argument.
129195 */
129196 #if defined(SQLITE_NEED_ERR_NAME)
129197 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
129198 const char *zName = 0;
129199 int i, origRc = rc;
129200 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
129201 switch( rc ){
@@ -129962,18 +130416,18 @@
130416 ){
130417 char *zOpt;
130418 int eState; /* Parser state when parsing URI */
130419 int iIn; /* Input character index */
130420 int iOut = 0; /* Output character index */
130421 u64 nByte = nUri+2; /* Bytes of space to allocate */
130422
130423 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
130424 ** method that there may be extra parameters following the file-name. */
130425 flags |= SQLITE_OPEN_URI;
130426
130427 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
130428 zFile = sqlite3_malloc64(nByte);
130429 if( !zFile ) return SQLITE_NOMEM;
130430
130431 iIn = 5;
130432 #ifdef SQLITE_ALLOW_URI_AUTHORITY
130433 if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130589,11 @@
130589
130590 zOpt = &zVal[nVal+1];
130591 }
130592
130593 }else{
130594 zFile = sqlite3_malloc64(nUri+2);
130595 if( !zFile ) return SQLITE_NOMEM;
130596 memcpy(zFile, zUri, nUri);
130597 zFile[nUri] = '\0';
130598 zFile[nUri+1] = '\0';
130599 flags &= ~SQLITE_OPEN_URI;
@@ -130406,10 +130860,17 @@
130860 #ifdef SQLITE_ENABLE_RTREE
130861 if( !db->mallocFailed && rc==SQLITE_OK){
130862 rc = sqlite3RtreeInit(db);
130863 }
130864 #endif
130865
130866 #ifdef SQLITE_ENABLE_DBSTAT_VTAB
130867 if( !db->mallocFailed && rc==SQLITE_OK){
130868 int sqlite3_dbstat_register(sqlite3*);
130869 rc = sqlite3_dbstat_register(db);
130870 }
130871 #endif
130872
130873 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
130874 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
130875 ** mode. Doing nothing at all also makes NORMAL the default.
130876 */
@@ -132344,10 +132805,15 @@
132805 ** false.
132806 */
132807 #ifdef SQLITE_COVERAGE_TEST
132808 # define ALWAYS(x) (1)
132809 # define NEVER(X) (0)
132810 #elif defined(SQLITE_DEBUG)
132811 # define ALWAYS(x) sqlite3Fts3Always((x)!=0)
132812 # define NEVER(x) sqlite3Fts3Never((x)!=0)
132813 SQLITE_PRIVATE int sqlite3Fts3Always(int b);
132814 SQLITE_PRIVATE int sqlite3Fts3Never(int b);
132815 #else
132816 # define ALWAYS(x) (x)
132817 # define NEVER(x) (x)
132818 #endif
132819
@@ -132744,10 +133210,11 @@
133210 #define fts3GetVarint32(p, piVal) ( \
133211 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
133212 )
133213
133214 /* fts3.c */
133215 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
133216 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
133217 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
133218 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
133219 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
133220 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133299,17 @@
133299
133300 static int fts3EvalNext(Fts3Cursor *pCsr);
133301 static int fts3EvalStart(Fts3Cursor *pCsr);
133302 static int fts3TermSegReaderCursor(
133303 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
133304
133305 #ifndef SQLITE_AMALGAMATION
133306 # if defined(SQLITE_DEBUG)
133307 SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
133308 SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
133309 # endif
133310 #endif
133311
133312 /*
133313 ** Write a 64-bit variable-length integer to memory starting at p[0].
133314 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
133315 ** The number of bytes written is returned.
@@ -132942,11 +133416,11 @@
133416 int iOut = 0; /* Index of next byte to write to output */
133417
133418 /* If the first byte was a '[', then the close-quote character is a ']' */
133419 if( quote=='[' ) quote = ']';
133420
133421 while( z[iIn] ){
133422 if( z[iIn]==quote ){
133423 if( z[iIn+1]!=quote ) break;
133424 z[iOut++] = quote;
133425 iIn += 2;
133426 }else{
@@ -133020,10 +133494,21 @@
133494 p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133495
133496 sqlite3_free(p);
133497 return SQLITE_OK;
133498 }
133499
133500 /*
133501 ** Write an error message into *pzErr
133502 */
133503 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){
133504 va_list ap;
133505 sqlite3_free(*pzErr);
133506 va_start(ap, zFormat);
133507 *pzErr = sqlite3_vmprintf(zFormat, ap);
133508 va_end(ap);
133509 }
133510
133511 /*
133512 ** Construct one or more SQL statements from the format string given
133513 ** and then evaluate those statements. The success code is written
133514 ** into *pRc.
@@ -133539,11 +134024,12 @@
134024 sqlite3 *db, /* Database handle */
134025 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
134026 const char *zTbl, /* Name of content table */
134027 const char ***pazCol, /* OUT: Malloc'd array of column names */
134028 int *pnCol, /* OUT: Size of array *pazCol */
134029 int *pnStr, /* OUT: Bytes of string content */
134030 char **pzErr /* OUT: error message */
134031 ){
134032 int rc = SQLITE_OK; /* Return code */
134033 char *zSql; /* "SELECT *" statement on zTbl */
134034 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
134035
@@ -133550,10 +134036,13 @@
134036 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
134037 if( !zSql ){
134038 rc = SQLITE_NOMEM;
134039 }else{
134040 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
134041 if( rc!=SQLITE_OK ){
134042 sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
134043 }
134044 }
134045 sqlite3_free(zSql);
134046
134047 if( rc==SQLITE_OK ){
134048 const char **azCol; /* Output array */
@@ -133716,17 +134205,17 @@
134205 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
134206 break;
134207 }
134208 }
134209 if( iOpt==SizeofArray(aFts4Opt) ){
134210 sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
134211 rc = SQLITE_ERROR;
134212 }else{
134213 switch( iOpt ){
134214 case 0: /* MATCHINFO */
134215 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
134216 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
134217 rc = SQLITE_ERROR;
134218 }
134219 bNoDocsize = 1;
134220 break;
134221
@@ -133750,11 +134239,11 @@
134239
134240 case 4: /* ORDER */
134241 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
134242 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
134243 ){
134244 sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
134245 rc = SQLITE_ERROR;
134246 }
134247 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
134248 break;
134249
@@ -133801,11 +134290,11 @@
134290 zCompress = 0;
134291 zUncompress = 0;
134292 if( nCol==0 ){
134293 sqlite3_free((void*)aCol);
134294 aCol = 0;
134295 rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
134296
134297 /* If a languageid= option was specified, remove the language id
134298 ** column from the aCol[] array. */
134299 if( rc==SQLITE_OK && zLanguageid ){
134300 int j;
@@ -133836,11 +134325,11 @@
134325 assert( pTokenizer );
134326
134327 rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
134328 if( rc==SQLITE_ERROR ){
134329 assert( zPrefix );
134330 sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix);
134331 }
134332 if( rc!=SQLITE_OK ) goto fts3_init_out;
134333
134334 /* Allocate and populate the Fts3Table structure. */
134335 nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134407,19 @@
134407 }
134408 }
134409 }
134410 for(i=0; i<nNotindexed; i++){
134411 if( azNotindexed[i] ){
134412 sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]);
134413 rc = SQLITE_ERROR;
134414 }
134415 }
134416
134417 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
134418 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
134419 rc = SQLITE_ERROR;
134420 sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss);
134421 }
134422 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
134423 p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
134424 if( rc!=SQLITE_OK ) goto fts3_init_out;
134425
@@ -135319,11 +135808,11 @@
135808 ** Fts3SegReaderPending might segfault, as the data structures used by
135809 ** fts4aux are not completely populated. So it's easiest to filter these
135810 ** calls out here. */
135811 if( iLevel<0 && p->aIndex ){
135812 Fts3SegReader *pSeg = 0;
135813 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
135814 if( rc==SQLITE_OK && pSeg ){
135815 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135816 }
135817 }
135818
@@ -135968,15 +136457,35 @@
136457 */
136458 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
136459 char *p = &(*ppPoslist)[-2];
136460 char c = 0;
136461
136462 /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
136463 while( p>pStart && (c=*p--)==0 );
136464
136465 /* Search backwards for a varint with value zero (the end of the previous
136466 ** poslist). This is an 0x00 byte preceded by some byte that does not
136467 ** have the 0x80 bit set. */
136468 while( p>pStart && (*p & 0x80) | c ){
136469 c = *p--;
136470 }
136471 assert( p==pStart || c==0 );
136472
136473 /* At this point p points to that preceding byte without the 0x80 bit
136474 ** set. So to find the start of the poslist, skip forward 2 bytes then
136475 ** over a varint.
136476 **
136477 ** Normally. The other case is that p==pStart and the poslist to return
136478 ** is the first in the doclist. In this case do not skip forward 2 bytes.
136479 ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
136480 ** is required for cases where the first byte of a doclist and the
136481 ** doclist is empty. For example, if the first docid is 10, a doclist
136482 ** that begins with:
136483 **
136484 ** 0x0A 0x00 <next docid delta varint>
136485 */
136486 if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
136487 while( *p++&0x80 );
136488 *ppPoslist = p;
136489 }
136490
136491 /*
@@ -136043,10 +136552,12 @@
136552 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136553 case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136554 }
136555 if( !zEllipsis || !zEnd || !zStart ){
136556 sqlite3_result_error_nomem(pContext);
136557 }else if( nToken==0 ){
136558 sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
136559 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136560 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136561 }
136562 }
136563
@@ -137104,16 +137615,18 @@
137615 Fts3Expr *pExpr, /* Expression to initialize phrases in */
137616 int *pRc /* IN/OUT: Error code */
137617 ){
137618 if( pExpr && SQLITE_OK==*pRc ){
137619 if( pExpr->eType==FTSQUERY_PHRASE ){
 
137620 int nToken = pExpr->pPhrase->nToken;
137621 if( nToken ){
137622 int i;
137623 for(i=0; i<nToken; i++){
137624 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137625 }
137626 pExpr->bDeferred = (i==nToken);
137627 }
 
137628 *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137629 }else{
137630 fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137631 fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137632 pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138785,12 @@
138785 if( rc!=SQLITE_OK ) return rc;
138786
138787 pIter = pPhrase->pOrPoslist;
138788 iDocid = pPhrase->iOrDocid;
138789 if( pCsr->bDesc==bDescDoclist ){
138790 bEof = !pPhrase->doclist.nAll ||
138791 (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138792 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138793 sqlite3Fts3DoclistNext(
138794 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138795 &pIter, &iDocid, &bEof
138796 );
@@ -138484,11 +138998,11 @@
138998
138999 *ppVtab = (sqlite3_vtab *)p;
139000 return SQLITE_OK;
139001
139002 bad_args:
139003 sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor");
139004 return SQLITE_ERROR;
139005 }
139006
139007 /*
139008 ** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140456,17 @@
140456
140457 if( rc!=SQLITE_OK ){
140458 sqlite3Fts3ExprFree(*ppExpr);
140459 *ppExpr = 0;
140460 if( rc==SQLITE_TOOBIG ){
140461 sqlite3Fts3ErrMsg(pzErr,
140462 "FTS expression tree is too large (maximum depth %d)",
140463 SQLITE_FTS3_MAX_EXPR_DEPTH
140464 );
140465 rc = SQLITE_ERROR;
140466 }else if( rc==SQLITE_ERROR ){
140467 sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z);
140468 }
140469 }
140470
140471 return rc;
140472 }
@@ -141424,11 +141938,11 @@
141938 z[n] = '\0';
141939 sqlite3Fts3Dequote(z);
141940
141941 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141942 if( !m ){
141943 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
141944 rc = SQLITE_ERROR;
141945 }else{
141946 char const **aArg = 0;
141947 int iArg = 0;
141948 z = &z[n+1];
@@ -141447,11 +141961,11 @@
141961 z = &z[n+1];
141962 }
141963 rc = m->xCreate(iArg, aArg, ppTok);
141964 assert( rc!=SQLITE_OK || *ppTok );
141965 if( rc!=SQLITE_OK ){
141966 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer");
141967 }else{
141968 (*ppTok)->pModule = m;
141969 }
141970 sqlite3_free((void *)aArg);
141971 }
@@ -141531,13 +142045,13 @@
142045
142046 pHash = (Fts3Hash *)sqlite3_user_data(context);
142047 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142048
142049 if( !p ){
142050 char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName);
142051 sqlite3_result_error(context, zErr2, -1);
142052 sqlite3_free(zErr2);
142053 return;
142054 }
142055
142056 pRet = Tcl_NewObj();
142057 Tcl_IncrRefCount(pRet);
@@ -142068,11 +142582,11 @@
142582 sqlite3_tokenizer_module *p;
142583 int nName = (int)strlen(zName);
142584
142585 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142586 if( !p ){
142587 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName);
142588 return SQLITE_ERROR;
142589 }
142590
142591 *pp = p;
142592 return SQLITE_OK;
@@ -142765,11 +143279,11 @@
143279 /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
143280 /* 24 */ "",
143281 /* 25 */ "",
143282
143283 /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
143284 /* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'",
143285
143286 /* This statement is used to determine which level to read the input from
143287 ** when performing an incremental merge. It returns the absolute level number
143288 ** of the oldest level in the db that contains at least ? segments. Or,
143289 ** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146397,12 @@
146397 sqlite3_stmt *pAllLangid = 0;
146398
146399 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
146400 if( rc==SQLITE_OK ){
146401 int rc2;
146402 sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
146403 sqlite3_bind_int(pAllLangid, 2, p->nIndex);
146404 while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
146405 int i;
146406 int iLangid = sqlite3_column_int(pAllLangid, 0);
146407 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
146408 rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147730,11 @@
147730 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147731
147732 pHint->n = i;
147733 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147734 i += fts3GetVarint32(&pHint->a[i], pnInput);
147735 if( i!=nHint ) return FTS_CORRUPT_VTAB;
147736
147737 return SQLITE_OK;
147738 }
147739
147740
@@ -147583,11 +148098,12 @@
148098
148099 /* This block calculates the checksum according to the FTS index. */
148100 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
148101 if( rc==SQLITE_OK ){
148102 int rc2;
148103 sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
148104 sqlite3_bind_int(pAllLangid, 2, p->nIndex);
148105 while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
148106 int iLangid = sqlite3_column_int(pAllLangid, 0);
148107 int i;
148108 for(i=0; i<p->nIndex; i++){
148109 cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148112,10 @@
148112 rc2 = sqlite3_reset(pAllLangid);
148113 if( rc==SQLITE_OK ) rc = rc2;
148114 }
148115
148116 /* This block calculates the checksum according to the %_content table */
 
148117 if( rc==SQLITE_OK ){
148118 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
148119 sqlite3_stmt *pStmt = 0;
148120 char *zSql;
148121
@@ -147693,11 +148208,11 @@
148208 Fts3Table *p /* FTS3 table handle */
148209 ){
148210 int rc;
148211 int bOk = 0;
148212 rc = fts3IntegrityCheck(p, &bOk);
148213 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
148214 return rc;
148215 }
148216
148217 /*
148218 ** Handle a 'special' INSERT of the form:
@@ -148131,10 +148646,11 @@
148646 #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148647 #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148648 #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148649 #define FTS3_MATCHINFO_LCS 's' /* nCol values */
148650 #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
148651 #define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */
148652
148653 /*
148654 ** The default value for the second argument to matchinfo().
148655 */
148656 #define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149428,55 @@
149428 }
149429 }
149430
149431 return rc;
149432 }
149433
149434 /*
149435 ** fts3ExprIterate() callback used to gather information for the matchinfo
149436 ** directive 'y'.
149437 */
149438 static int fts3ExprLHitsCb(
149439 Fts3Expr *pExpr, /* Phrase expression node */
149440 int iPhrase, /* Phrase number */
149441 void *pCtx /* Pointer to MatchInfo structure */
149442 ){
149443 MatchInfo *p = (MatchInfo *)pCtx;
149444 Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
149445 int rc = SQLITE_OK;
149446 int iStart = iPhrase * p->nCol;
149447 Fts3Expr *pEof; /* Ancestor node already at EOF */
149448
149449 /* This must be a phrase */
149450 assert( pExpr->pPhrase );
149451
149452 /* Initialize all output integers to zero. */
149453 memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
149454
149455 /* Check if this or any parent node is at EOF. If so, then all output
149456 ** values are zero. */
149457 for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
149458
149459 if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
149460 Fts3Phrase *pPhrase = pExpr->pPhrase;
149461 char *pIter = pPhrase->doclist.pList;
149462 int iCol = 0;
149463
149464 while( 1 ){
149465 int nHit = fts3ColumnlistCount(&pIter);
149466 if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
149467 p->aMatchinfo[iStart + iCol] = (u32)nHit;
149468 }
149469 assert( *pIter==0x00 || *pIter==0x01 );
149470 if( *pIter!=0x01 ) break;
149471 pIter++;
149472 pIter += fts3GetVarint32(pIter, &iCol);
149473 }
149474 }
149475
149476 return rc;
149477 }
149478
149479 static int fts3MatchinfoCheck(
149480 Fts3Table *pTab,
149481 char cArg,
149482 char **pzErr
@@ -148925,14 +149486,15 @@
149486 || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
149487 || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
149488 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
149489 || (cArg==FTS3_MATCHINFO_LCS)
149490 || (cArg==FTS3_MATCHINFO_HITS)
149491 || (cArg==FTS3_MATCHINFO_LHITS)
149492 ){
149493 return SQLITE_OK;
149494 }
149495 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
149496 return SQLITE_ERROR;
149497 }
149498
149499 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
149500 int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149509,14 @@
149509 case FTS3_MATCHINFO_AVGLENGTH:
149510 case FTS3_MATCHINFO_LENGTH:
149511 case FTS3_MATCHINFO_LCS:
149512 nVal = pInfo->nCol;
149513 break;
149514
149515 case FTS3_MATCHINFO_LHITS:
149516 nVal = pInfo->nCol * pInfo->nPhrase;
149517 break;
149518
149519 default:
149520 assert( cArg==FTS3_MATCHINFO_HITS );
149521 nVal = pInfo->nCol * pInfo->nPhrase * 3;
149522 break;
@@ -149201,10 +149767,14 @@
149767 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149768 if( rc==SQLITE_OK ){
149769 rc = fts3MatchinfoLcs(pCsr, pInfo);
149770 }
149771 break;
149772
149773 case FTS3_MATCHINFO_LHITS:
149774 (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
149775 break;
149776
149777 default: {
149778 Fts3Expr *pExpr;
149779 assert( zArg[i]==FTS3_MATCHINFO_HITS );
149780 pExpr = pCsr->pExpr;
@@ -153214,15 +153784,23 @@
153784 ** conflict-handling mode specified by the user.
153785 */
153786 if( nData>1 ){
153787 int ii;
153788
153789 /* Populate the cell.aCoord[] array. The first coordinate is azData[3].
153790 **
153791 ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
153792 ** with "column" that are interpreted as table constraints.
153793 ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
153794 ** This problem was discovered after years of use, so we silently ignore
153795 ** these kinds of misdeclared tables to avoid breaking any legacy.
153796 */
153797 assert( nData<=(pRtree->nDim*2 + 3) );
153798
153799 #ifndef SQLITE_RTREE_INT_ONLY
153800 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153801 for(ii=0; ii<nData-4; ii+=2){
153802 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153803 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153804 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153805 rc = SQLITE_CONSTRAINT;
153806 goto constraint;
@@ -153229,11 +153807,11 @@
153807 }
153808 }
153809 }else
153810 #endif
153811 {
153812 for(ii=0; ii<nData-4; ii+=2){
153813 cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153814 cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153815 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153816 rc = SQLITE_CONSTRAINT;
153817 goto constraint;
@@ -154629,5 +155207,633 @@
155207
155208 #endif /* defined(SQLITE_ENABLE_ICU) */
155209 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
155210
155211 /************** End of fts3_icu.c ********************************************/
155212 /************** Begin file dbstat.c ******************************************/
155213 /*
155214 ** 2010 July 12
155215 **
155216 ** The author disclaims copyright to this source code. In place of
155217 ** a legal notice, here is a blessing:
155218 **
155219 ** May you do good and not evil.
155220 ** May you find forgiveness for yourself and forgive others.
155221 ** May you share freely, never taking more than you give.
155222 **
155223 ******************************************************************************
155224 **
155225 ** This file contains an implementation of the "dbstat" virtual table.
155226 **
155227 ** The dbstat virtual table is used to extract low-level formatting
155228 ** information from an SQLite database in order to implement the
155229 ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
155230 ** for an example implementation.
155231 */
155232
155233 #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
155234 && !defined(SQLITE_OMIT_VIRTUALTABLE)
155235
155236 /*
155237 ** Page paths:
155238 **
155239 ** The value of the 'path' column describes the path taken from the
155240 ** root-node of the b-tree structure to each page. The value of the
155241 ** root-node path is '/'.
155242 **
155243 ** The value of the path for the left-most child page of the root of
155244 ** a b-tree is '/000/'. (Btrees store content ordered from left to right
155245 ** so the pages to the left have smaller keys than the pages to the right.)
155246 ** The next to left-most child of the root page is
155247 ** '/001', and so on, each sibling page identified by a 3-digit hex
155248 ** value. The children of the 451st left-most sibling have paths such
155249 ** as '/1c2/000/, '/1c2/001/' etc.
155250 **
155251 ** Overflow pages are specified by appending a '+' character and a
155252 ** six-digit hexadecimal value to the path to the cell they are linked
155253 ** from. For example, the three overflow pages in a chain linked from
155254 ** the left-most cell of the 450th child of the root page are identified
155255 ** by the paths:
155256 **
155257 ** '/1c2/000+000000' // First page in overflow chain
155258 ** '/1c2/000+000001' // Second page in overflow chain
155259 ** '/1c2/000+000002' // Third page in overflow chain
155260 **
155261 ** If the paths are sorted using the BINARY collation sequence, then
155262 ** the overflow pages associated with a cell will appear earlier in the
155263 ** sort-order than its child page:
155264 **
155265 ** '/1c2/000/' // Left-most child of 451st child of root
155266 */
155267 #define VTAB_SCHEMA \
155268 "CREATE TABLE xx( " \
155269 " name STRING, /* Name of table or index */" \
155270 " path INTEGER, /* Path to page from root */" \
155271 " pageno INTEGER, /* Page number */" \
155272 " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \
155273 " ncell INTEGER, /* Cells on page (0 for overflow) */" \
155274 " payload INTEGER, /* Bytes of payload on this page */" \
155275 " unused INTEGER, /* Bytes of unused space on this page */" \
155276 " mx_payload INTEGER, /* Largest payload size of all cells */" \
155277 " pgoffset INTEGER, /* Offset of page in file */" \
155278 " pgsize INTEGER /* Size of the page */" \
155279 ");"
155280
155281
155282 typedef struct StatTable StatTable;
155283 typedef struct StatCursor StatCursor;
155284 typedef struct StatPage StatPage;
155285 typedef struct StatCell StatCell;
155286
155287 struct StatCell {
155288 int nLocal; /* Bytes of local payload */
155289 u32 iChildPg; /* Child node (or 0 if this is a leaf) */
155290 int nOvfl; /* Entries in aOvfl[] */
155291 u32 *aOvfl; /* Array of overflow page numbers */
155292 int nLastOvfl; /* Bytes of payload on final overflow page */
155293 int iOvfl; /* Iterates through aOvfl[] */
155294 };
155295
155296 struct StatPage {
155297 u32 iPgno;
155298 DbPage *pPg;
155299 int iCell;
155300
155301 char *zPath; /* Path to this page */
155302
155303 /* Variables populated by statDecodePage(): */
155304 u8 flags; /* Copy of flags byte */
155305 int nCell; /* Number of cells on page */
155306 int nUnused; /* Number of unused bytes on page */
155307 StatCell *aCell; /* Array of parsed cells */
155308 u32 iRightChildPg; /* Right-child page number (or 0) */
155309 int nMxPayload; /* Largest payload of any cell on this page */
155310 };
155311
155312 struct StatCursor {
155313 sqlite3_vtab_cursor base;
155314 sqlite3_stmt *pStmt; /* Iterates through set of root pages */
155315 int isEof; /* After pStmt has returned SQLITE_DONE */
155316
155317 StatPage aPage[32];
155318 int iPage; /* Current entry in aPage[] */
155319
155320 /* Values to return. */
155321 char *zName; /* Value of 'name' column */
155322 char *zPath; /* Value of 'path' column */
155323 u32 iPageno; /* Value of 'pageno' column */
155324 char *zPagetype; /* Value of 'pagetype' column */
155325 int nCell; /* Value of 'ncell' column */
155326 int nPayload; /* Value of 'payload' column */
155327 int nUnused; /* Value of 'unused' column */
155328 int nMxPayload; /* Value of 'mx_payload' column */
155329 i64 iOffset; /* Value of 'pgOffset' column */
155330 int szPage; /* Value of 'pgSize' column */
155331 };
155332
155333 struct StatTable {
155334 sqlite3_vtab base;
155335 sqlite3 *db;
155336 };
155337
155338 #ifndef get2byte
155339 # define get2byte(x) ((x)[0]<<8 | (x)[1])
155340 #endif
155341
155342 /*
155343 ** Connect to or create a statvfs virtual table.
155344 */
155345 static int statConnect(
155346 sqlite3 *db,
155347 void *pAux,
155348 int argc, const char *const*argv,
155349 sqlite3_vtab **ppVtab,
155350 char **pzErr
155351 ){
155352 StatTable *pTab = 0;
155353 int rc = SQLITE_OK;
155354
155355 rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
155356 if( rc==SQLITE_OK ){
155357 pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
155358 if( pTab==0 ) rc = SQLITE_NOMEM;
155359 }
155360
155361 assert( rc==SQLITE_OK || pTab==0 );
155362 if( rc==SQLITE_OK ){
155363 memset(pTab, 0, sizeof(StatTable));
155364 pTab->db = db;
155365 }
155366
155367 *ppVtab = (sqlite3_vtab*)pTab;
155368 return rc;
155369 }
155370
155371 /*
155372 ** Disconnect from or destroy a statvfs virtual table.
155373 */
155374 static int statDisconnect(sqlite3_vtab *pVtab){
155375 sqlite3_free(pVtab);
155376 return SQLITE_OK;
155377 }
155378
155379 /*
155380 ** There is no "best-index". This virtual table always does a linear
155381 ** scan of the binary VFS log file.
155382 */
155383 static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
155384
155385 /* Records are always returned in ascending order of (name, path).
155386 ** If this will satisfy the client, set the orderByConsumed flag so that
155387 ** SQLite does not do an external sort.
155388 */
155389 if( ( pIdxInfo->nOrderBy==1
155390 && pIdxInfo->aOrderBy[0].iColumn==0
155391 && pIdxInfo->aOrderBy[0].desc==0
155392 ) ||
155393 ( pIdxInfo->nOrderBy==2
155394 && pIdxInfo->aOrderBy[0].iColumn==0
155395 && pIdxInfo->aOrderBy[0].desc==0
155396 && pIdxInfo->aOrderBy[1].iColumn==1
155397 && pIdxInfo->aOrderBy[1].desc==0
155398 )
155399 ){
155400 pIdxInfo->orderByConsumed = 1;
155401 }
155402
155403 pIdxInfo->estimatedCost = 10.0;
155404 return SQLITE_OK;
155405 }
155406
155407 /*
155408 ** Open a new statvfs cursor.
155409 */
155410 static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
155411 StatTable *pTab = (StatTable *)pVTab;
155412 StatCursor *pCsr;
155413 int rc;
155414
155415 pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
155416 if( pCsr==0 ){
155417 rc = SQLITE_NOMEM;
155418 }else{
155419 memset(pCsr, 0, sizeof(StatCursor));
155420 pCsr->base.pVtab = pVTab;
155421
155422 rc = sqlite3_prepare_v2(pTab->db,
155423 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
155424 " UNION ALL "
155425 "SELECT name, rootpage, type FROM sqlite_master WHERE rootpage!=0"
155426 " ORDER BY name", -1,
155427 &pCsr->pStmt, 0
155428 );
155429 if( rc!=SQLITE_OK ){
155430 sqlite3_free(pCsr);
155431 pCsr = 0;
155432 }
155433 }
155434
155435 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
155436 return rc;
155437 }
155438
155439 static void statClearPage(StatPage *p){
155440 int i;
155441 if( p->aCell ){
155442 for(i=0; i<p->nCell; i++){
155443 sqlite3_free(p->aCell[i].aOvfl);
155444 }
155445 sqlite3_free(p->aCell);
155446 }
155447 sqlite3PagerUnref(p->pPg);
155448 sqlite3_free(p->zPath);
155449 memset(p, 0, sizeof(StatPage));
155450 }
155451
155452 static void statResetCsr(StatCursor *pCsr){
155453 int i;
155454 sqlite3_reset(pCsr->pStmt);
155455 for(i=0; i<ArraySize(pCsr->aPage); i++){
155456 statClearPage(&pCsr->aPage[i]);
155457 }
155458 pCsr->iPage = 0;
155459 sqlite3_free(pCsr->zPath);
155460 pCsr->zPath = 0;
155461 }
155462
155463 /*
155464 ** Close a statvfs cursor.
155465 */
155466 static int statClose(sqlite3_vtab_cursor *pCursor){
155467 StatCursor *pCsr = (StatCursor *)pCursor;
155468 statResetCsr(pCsr);
155469 sqlite3_finalize(pCsr->pStmt);
155470 sqlite3_free(pCsr);
155471 return SQLITE_OK;
155472 }
155473
155474 static void getLocalPayload(
155475 int nUsable, /* Usable bytes per page */
155476 u8 flags, /* Page flags */
155477 int nTotal, /* Total record (payload) size */
155478 int *pnLocal /* OUT: Bytes stored locally */
155479 ){
155480 int nLocal;
155481 int nMinLocal;
155482 int nMaxLocal;
155483
155484 if( flags==0x0D ){ /* Table leaf node */
155485 nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155486 nMaxLocal = nUsable - 35;
155487 }else{ /* Index interior and leaf nodes */
155488 nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155489 nMaxLocal = (nUsable - 12) * 64 / 255 - 23;
155490 }
155491
155492 nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4);
155493 if( nLocal>nMaxLocal ) nLocal = nMinLocal;
155494 *pnLocal = nLocal;
155495 }
155496
155497 static int statDecodePage(Btree *pBt, StatPage *p){
155498 int nUnused;
155499 int iOff;
155500 int nHdr;
155501 int isLeaf;
155502 int szPage;
155503
155504 u8 *aData = sqlite3PagerGetData(p->pPg);
155505 u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
155506
155507 p->flags = aHdr[0];
155508 p->nCell = get2byte(&aHdr[3]);
155509 p->nMxPayload = 0;
155510
155511 isLeaf = (p->flags==0x0A || p->flags==0x0D);
155512 nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100;
155513
155514 nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell;
155515 nUnused += (int)aHdr[7];
155516 iOff = get2byte(&aHdr[1]);
155517 while( iOff ){
155518 nUnused += get2byte(&aData[iOff+2]);
155519 iOff = get2byte(&aData[iOff]);
155520 }
155521 p->nUnused = nUnused;
155522 p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
155523 szPage = sqlite3BtreeGetPageSize(pBt);
155524
155525 if( p->nCell ){
155526 int i; /* Used to iterate through cells */
155527 int nUsable; /* Usable bytes per page */
155528
155529 sqlite3BtreeEnter(pBt);
155530 nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt);
155531 sqlite3BtreeLeave(pBt);
155532 p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell));
155533 if( p->aCell==0 ) return SQLITE_NOMEM;
155534 memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
155535
155536 for(i=0; i<p->nCell; i++){
155537 StatCell *pCell = &p->aCell[i];
155538
155539 iOff = get2byte(&aData[nHdr+i*2]);
155540 if( !isLeaf ){
155541 pCell->iChildPg = sqlite3Get4byte(&aData[iOff]);
155542 iOff += 4;
155543 }
155544 if( p->flags==0x05 ){
155545 /* A table interior node. nPayload==0. */
155546 }else{
155547 u32 nPayload; /* Bytes of payload total (local+overflow) */
155548 int nLocal; /* Bytes of payload stored locally */
155549 iOff += getVarint32(&aData[iOff], nPayload);
155550 if( p->flags==0x0D ){
155551 u64 dummy;
155552 iOff += sqlite3GetVarint(&aData[iOff], &dummy);
155553 }
155554 if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload;
155555 getLocalPayload(nUsable, p->flags, nPayload, &nLocal);
155556 pCell->nLocal = nLocal;
155557 assert( nLocal>=0 );
155558 assert( nPayload>=(u32)nLocal );
155559 assert( nLocal<=(nUsable-35) );
155560 if( nPayload>(u32)nLocal ){
155561 int j;
155562 int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
155563 pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
155564 pCell->nOvfl = nOvfl;
155565 pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
155566 if( pCell->aOvfl==0 ) return SQLITE_NOMEM;
155567 pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
155568 for(j=1; j<nOvfl; j++){
155569 int rc;
155570 u32 iPrev = pCell->aOvfl[j-1];
155571 DbPage *pPg = 0;
155572 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg);
155573 if( rc!=SQLITE_OK ){
155574 assert( pPg==0 );
155575 return rc;
155576 }
155577 pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
155578 sqlite3PagerUnref(pPg);
155579 }
155580 }
155581 }
155582 }
155583 }
155584
155585 return SQLITE_OK;
155586 }
155587
155588 /*
155589 ** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
155590 ** the current value of pCsr->iPageno.
155591 */
155592 static void statSizeAndOffset(StatCursor *pCsr){
155593 StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab;
155594 Btree *pBt = pTab->db->aDb[0].pBt;
155595 Pager *pPager = sqlite3BtreePager(pBt);
155596 sqlite3_file *fd;
155597 sqlite3_int64 x[2];
155598
155599 /* The default page size and offset */
155600 pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
155601 pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1);
155602
155603 /* If connected to a ZIPVFS backend, override the page size and
155604 ** offset with actual values obtained from ZIPVFS.
155605 */
155606 fd = sqlite3PagerFile(pPager);
155607 x[0] = pCsr->iPageno;
155608 if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
155609 pCsr->iOffset = x[0];
155610 pCsr->szPage = (int)x[1];
155611 }
155612 }
155613
155614 /*
155615 ** Move a statvfs cursor to the next entry in the file.
155616 */
155617 static int statNext(sqlite3_vtab_cursor *pCursor){
155618 int rc;
155619 int nPayload;
155620 StatCursor *pCsr = (StatCursor *)pCursor;
155621 StatTable *pTab = (StatTable *)pCursor->pVtab;
155622 Btree *pBt = pTab->db->aDb[0].pBt;
155623 Pager *pPager = sqlite3BtreePager(pBt);
155624
155625 sqlite3_free(pCsr->zPath);
155626 pCsr->zPath = 0;
155627
155628 statNextRestart:
155629 if( pCsr->aPage[0].pPg==0 ){
155630 rc = sqlite3_step(pCsr->pStmt);
155631 if( rc==SQLITE_ROW ){
155632 int nPage;
155633 u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1);
155634 sqlite3PagerPagecount(pPager, &nPage);
155635 if( nPage==0 ){
155636 pCsr->isEof = 1;
155637 return sqlite3_reset(pCsr->pStmt);
155638 }
155639 rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
155640 pCsr->aPage[0].iPgno = iRoot;
155641 pCsr->aPage[0].iCell = 0;
155642 pCsr->aPage[0].zPath = sqlite3_mprintf("/");
155643 pCsr->iPage = 0;
155644 }else{
155645 pCsr->isEof = 1;
155646 return sqlite3_reset(pCsr->pStmt);
155647 }
155648 }else{
155649
155650 /* Page p itself has already been visited. */
155651 StatPage *p = &pCsr->aPage[pCsr->iPage];
155652
155653 while( p->iCell<p->nCell ){
155654 StatCell *pCell = &p->aCell[p->iCell];
155655 if( pCell->iOvfl<pCell->nOvfl ){
155656 int nUsable;
155657 sqlite3BtreeEnter(pBt);
155658 nUsable = sqlite3BtreeGetPageSize(pBt) -
155659 sqlite3BtreeGetReserveNoMutex(pBt);
155660 sqlite3BtreeLeave(pBt);
155661 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155662 pCsr->iPageno = pCell->aOvfl[pCell->iOvfl];
155663 pCsr->zPagetype = "overflow";
155664 pCsr->nCell = 0;
155665 pCsr->nMxPayload = 0;
155666 pCsr->zPath = sqlite3_mprintf(
155667 "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl
155668 );
155669 if( pCell->iOvfl<pCell->nOvfl-1 ){
155670 pCsr->nUnused = 0;
155671 pCsr->nPayload = nUsable - 4;
155672 }else{
155673 pCsr->nPayload = pCell->nLastOvfl;
155674 pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
155675 }
155676 pCell->iOvfl++;
155677 statSizeAndOffset(pCsr);
155678 return SQLITE_OK;
155679 }
155680 if( p->iRightChildPg ) break;
155681 p->iCell++;
155682 }
155683
155684 if( !p->iRightChildPg || p->iCell>p->nCell ){
155685 statClearPage(p);
155686 if( pCsr->iPage==0 ) return statNext(pCursor);
155687 pCsr->iPage--;
155688 goto statNextRestart; /* Tail recursion */
155689 }
155690 pCsr->iPage++;
155691 assert( p==&pCsr->aPage[pCsr->iPage-1] );
155692
155693 if( p->iCell==p->nCell ){
155694 p[1].iPgno = p->iRightChildPg;
155695 }else{
155696 p[1].iPgno = p->aCell[p->iCell].iChildPg;
155697 }
155698 rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);
155699 p[1].iCell = 0;
155700 p[1].zPath = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
155701 p->iCell++;
155702 }
155703
155704
155705 /* Populate the StatCursor fields with the values to be returned
155706 ** by the xColumn() and xRowid() methods.
155707 */
155708 if( rc==SQLITE_OK ){
155709 int i;
155710 StatPage *p = &pCsr->aPage[pCsr->iPage];
155711 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155712 pCsr->iPageno = p->iPgno;
155713
155714 rc = statDecodePage(pBt, p);
155715 if( rc==SQLITE_OK ){
155716 statSizeAndOffset(pCsr);
155717
155718 switch( p->flags ){
155719 case 0x05: /* table internal */
155720 case 0x02: /* index internal */
155721 pCsr->zPagetype = "internal";
155722 break;
155723 case 0x0D: /* table leaf */
155724 case 0x0A: /* index leaf */
155725 pCsr->zPagetype = "leaf";
155726 break;
155727 default:
155728 pCsr->zPagetype = "corrupted";
155729 break;
155730 }
155731 pCsr->nCell = p->nCell;
155732 pCsr->nUnused = p->nUnused;
155733 pCsr->nMxPayload = p->nMxPayload;
155734 pCsr->zPath = sqlite3_mprintf("%s", p->zPath);
155735 nPayload = 0;
155736 for(i=0; i<p->nCell; i++){
155737 nPayload += p->aCell[i].nLocal;
155738 }
155739 pCsr->nPayload = nPayload;
155740 }
155741 }
155742
155743 return rc;
155744 }
155745
155746 static int statEof(sqlite3_vtab_cursor *pCursor){
155747 StatCursor *pCsr = (StatCursor *)pCursor;
155748 return pCsr->isEof;
155749 }
155750
155751 static int statFilter(
155752 sqlite3_vtab_cursor *pCursor,
155753 int idxNum, const char *idxStr,
155754 int argc, sqlite3_value **argv
155755 ){
155756 StatCursor *pCsr = (StatCursor *)pCursor;
155757
155758 statResetCsr(pCsr);
155759 return statNext(pCursor);
155760 }
155761
155762 static int statColumn(
155763 sqlite3_vtab_cursor *pCursor,
155764 sqlite3_context *ctx,
155765 int i
155766 ){
155767 StatCursor *pCsr = (StatCursor *)pCursor;
155768 switch( i ){
155769 case 0: /* name */
155770 sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_STATIC);
155771 break;
155772 case 1: /* path */
155773 sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
155774 break;
155775 case 2: /* pageno */
155776 sqlite3_result_int64(ctx, pCsr->iPageno);
155777 break;
155778 case 3: /* pagetype */
155779 sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC);
155780 break;
155781 case 4: /* ncell */
155782 sqlite3_result_int(ctx, pCsr->nCell);
155783 break;
155784 case 5: /* payload */
155785 sqlite3_result_int(ctx, pCsr->nPayload);
155786 break;
155787 case 6: /* unused */
155788 sqlite3_result_int(ctx, pCsr->nUnused);
155789 break;
155790 case 7: /* mx_payload */
155791 sqlite3_result_int(ctx, pCsr->nMxPayload);
155792 break;
155793 case 8: /* pgoffset */
155794 sqlite3_result_int64(ctx, pCsr->iOffset);
155795 break;
155796 case 9: /* pgsize */
155797 sqlite3_result_int(ctx, pCsr->szPage);
155798 break;
155799 }
155800 return SQLITE_OK;
155801 }
155802
155803 static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
155804 StatCursor *pCsr = (StatCursor *)pCursor;
155805 *pRowid = pCsr->iPageno;
155806 return SQLITE_OK;
155807 }
155808
155809 /*
155810 ** Invoke this routine to register the "dbstat" virtual table module
155811 */
155812 SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){
155813 static sqlite3_module dbstat_module = {
155814 0, /* iVersion */
155815 statConnect, /* xCreate */
155816 statConnect, /* xConnect */
155817 statBestIndex, /* xBestIndex */
155818 statDisconnect, /* xDisconnect */
155819 statDisconnect, /* xDestroy */
155820 statOpen, /* xOpen - open a cursor */
155821 statClose, /* xClose - close a cursor */
155822 statFilter, /* xFilter - configure scan constraints */
155823 statNext, /* xNext - advance a cursor */
155824 statEof, /* xEof - check for end of scan */
155825 statColumn, /* xColumn - read data */
155826 statRowid, /* xRowid - read data */
155827 0, /* xUpdate */
155828 0, /* xBegin */
155829 0, /* xSync */
155830 0, /* xCommit */
155831 0, /* xRollback */
155832 0, /* xFindMethod */
155833 0, /* xRename */
155834 };
155835 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
155836 }
155837 #endif /* SQLITE_ENABLE_DBSTAT_VTAB */
155838
155839 /************** End of dbstat.c **********************************************/
155840
+91 -15
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109109
**
110110
** See also: [sqlite3_libversion()],
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114
-#define SQLITE_VERSION "3.8.9"
115
-#define SQLITE_VERSION_NUMBER 3008009
116
-#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
114
+#define SQLITE_VERSION "3.8.10"
115
+#define SQLITE_VERSION_NUMBER 3008010
116
+#define SQLITE_SOURCE_ID "2015-05-07 11:53:08 cf975957b9ae671f34bb65f049acf351e650d437"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -268,10 +268,11 @@
268268
# define double sqlite3_int64
269269
#endif
270270
271271
/*
272272
** CAPI3REF: Closing A Database Connection
273
+** DESTRUCTOR: sqlite3
273274
**
274275
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
275276
** for the [sqlite3] object.
276277
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
277278
** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
319320
*/
320321
typedef int (*sqlite3_callback)(void*,int,char**, char**);
321322
322323
/*
323324
** CAPI3REF: One-Step Query Execution Interface
325
+** METHOD: sqlite3
324326
**
325327
** The sqlite3_exec() interface is a convenience wrapper around
326328
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
327329
** that allows an application to run multiple statements of SQL
328330
** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
13761378
*/
13771379
SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
13781380
13791381
/*
13801382
** CAPI3REF: Configure database connections
1383
+** METHOD: sqlite3
13811384
**
13821385
** The sqlite3_db_config() interface is used to make configuration
13831386
** changes to a [database connection]. The interface is similar to
13841387
** [sqlite3_config()] except that the changes apply to a single
13851388
** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
18731876
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
18741877
18751878
18761879
/*
18771880
** CAPI3REF: Enable Or Disable Extended Result Codes
1881
+** METHOD: sqlite3
18781882
**
18791883
** ^The sqlite3_extended_result_codes() routine enables or disables the
18801884
** [extended result codes] feature of SQLite. ^The extended result
18811885
** codes are disabled by default for historical compatibility.
18821886
*/
18831887
SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
18841888
18851889
/*
18861890
** CAPI3REF: Last Insert Rowid
1891
+** METHOD: sqlite3
18871892
**
18881893
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
18891894
** has a unique 64-bit signed
18901895
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
18911896
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
19331938
*/
19341939
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
19351940
19361941
/*
19371942
** CAPI3REF: Count The Number Of Rows Modified
1943
+** METHOD: sqlite3
19381944
**
19391945
** ^This function returns the number of rows modified, inserted or
19401946
** deleted by the most recently completed INSERT, UPDATE or DELETE
19411947
** statement on the database connection specified by the only parameter.
19421948
** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
19851991
*/
19861992
SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
19871993
19881994
/*
19891995
** CAPI3REF: Total Number Of Rows Modified
1996
+** METHOD: sqlite3
19901997
**
19911998
** ^This function returns the total number of rows inserted, modified or
19921999
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
19932000
** since the database connection was opened, including those executed as
19942001
** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
20082015
*/
20092016
SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
20102017
20112018
/*
20122019
** CAPI3REF: Interrupt A Long-Running Query
2020
+** METHOD: sqlite3
20132021
**
20142022
** ^This function causes any pending database operation to abort and
20152023
** return at its earliest opportunity. This routine is typically
20162024
** called in response to a user action such as pressing "Cancel"
20172025
** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
20842092
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
20852093
20862094
/*
20872095
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
20882096
** KEYWORDS: {busy-handler callback} {busy handler}
2097
+** METHOD: sqlite3
20892098
**
20902099
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
20912100
** that might be invoked with argument P whenever
20922101
** an attempt is made to access a database table associated with
20932102
** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
21432152
*/
21442153
SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
21452154
21462155
/*
21472156
** CAPI3REF: Set A Busy Timeout
2157
+** METHOD: sqlite3
21482158
**
21492159
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
21502160
** for a specified amount of time when a table is locked. ^The handler
21512161
** will sleep multiple times until at least "ms" milliseconds of sleeping
21522162
** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
21652175
*/
21662176
SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
21672177
21682178
/*
21692179
** CAPI3REF: Convenience Routines For Running Queries
2180
+** METHOD: sqlite3
21702181
**
21712182
** This is a legacy interface that is preserved for backwards compatibility.
21722183
** Use of this interface is not recommended.
21732184
**
21742185
** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
25002511
*/
25012512
SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
25022513
25032514
/*
25042515
** CAPI3REF: Compile-Time Authorization Callbacks
2516
+** METHOD: sqlite3
25052517
**
25062518
** ^This routine registers an authorizer callback with a particular
25072519
** [database connection], supplied in the first argument.
25082520
** ^The authorizer callback is invoked as SQL statements are being compiled
25092521
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
26562668
#define SQLITE_COPY 0 /* No longer used */
26572669
#define SQLITE_RECURSIVE 33 /* NULL NULL */
26582670
26592671
/*
26602672
** CAPI3REF: Tracing And Profiling Functions
2673
+** METHOD: sqlite3
26612674
**
26622675
** These routines register callback functions that can be used for
26632676
** tracing and profiling the execution of SQL statements.
26642677
**
26652678
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
26882701
SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
26892702
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
26902703
26912704
/*
26922705
** CAPI3REF: Query Progress Callbacks
2706
+** METHOD: sqlite3
26932707
**
26942708
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
26952709
** function X to be invoked periodically during long running calls to
26962710
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
26972711
** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
27212735
*/
27222736
SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
27232737
27242738
/*
27252739
** CAPI3REF: Opening A New Database Connection
2740
+** CONSTRUCTOR: sqlite3
27262741
**
27272742
** ^These routines open an SQLite database file as specified by the
27282743
** filename argument. ^The filename argument is interpreted as UTF-8 for
27292744
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
27302745
** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
30063021
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
30073022
30083023
30093024
/*
30103025
** CAPI3REF: Error Codes And Messages
3026
+** METHOD: sqlite3
30113027
**
30123028
** ^If the most recent sqlite3_* API call associated with
30133029
** [database connection] D failed, then the sqlite3_errcode(D) interface
30143030
** returns the numeric [result code] or [extended result code] for that
30153031
** API call.
@@ -3051,37 +3067,38 @@
30513067
SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
30523068
SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
30533069
SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
30543070
30553071
/*
3056
-** CAPI3REF: SQL Statement Object
3072
+** CAPI3REF: Prepared Statement Object
30573073
** KEYWORDS: {prepared statement} {prepared statements}
30583074
**
3059
-** An instance of this object represents a single SQL statement.
3060
-** This object is variously known as a "prepared statement" or a
3061
-** "compiled SQL statement" or simply as a "statement".
3075
+** An instance of this object represents a single SQL statement that
3076
+** has been compiled into binary form and is ready to be evaluated.
30623077
**
3063
-** The life of a statement object goes something like this:
3078
+** Think of each SQL statement as a separate computer program. The
3079
+** original SQL text is source code. A prepared statement object
3080
+** is the compiled object code. All SQL must be converted into a
3081
+** prepared statement before it can be run.
3082
+**
3083
+** The life-cycle of a prepared statement object usually goes like this:
30643084
**
30653085
** <ol>
3066
-** <li> Create the object using [sqlite3_prepare_v2()] or a related
3067
-** function.
3068
-** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3086
+** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3087
+** <li> Bind values to [parameters] using the sqlite3_bind_*()
30693088
** interfaces.
30703089
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3071
-** <li> Reset the statement using [sqlite3_reset()] then go back
3090
+** <li> Reset the prepared statement using [sqlite3_reset()] then go back
30723091
** to step 2. Do this zero or more times.
30733092
** <li> Destroy the object using [sqlite3_finalize()].
30743093
** </ol>
3075
-**
3076
-** Refer to documentation on individual methods above for additional
3077
-** information.
30783094
*/
30793095
typedef struct sqlite3_stmt sqlite3_stmt;
30803096
30813097
/*
30823098
** CAPI3REF: Run-time Limits
3099
+** METHOD: sqlite3
30833100
**
30843101
** ^(This interface allows the size of various constructs to be limited
30853102
** on a connection by connection basis. The first parameter is the
30863103
** [database connection] whose limit is to be set or queried. The
30873104
** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
31893206
#define SQLITE_LIMIT_WORKER_THREADS 11
31903207
31913208
/*
31923209
** CAPI3REF: Compiling An SQL Statement
31933210
** KEYWORDS: {SQL statement compiler}
3211
+** METHOD: sqlite3
3212
+** CONSTRUCTOR: sqlite3_stmt
31943213
**
31953214
** To execute an SQL query, it must first be compiled into a byte-code
31963215
** program using one of these routines.
31973216
**
31983217
** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
32963315
const void **pzTail /* OUT: Pointer to unused portion of zSql */
32973316
);
32983317
32993318
/*
33003319
** CAPI3REF: Retrieving Statement SQL
3320
+** METHOD: sqlite3_stmt
33013321
**
33023322
** ^This interface can be used to retrieve a saved copy of the original
33033323
** SQL text used to create a [prepared statement] if that statement was
33043324
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
33053325
*/
33063326
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
33073327
33083328
/*
33093329
** CAPI3REF: Determine If An SQL Statement Writes The Database
3330
+** METHOD: sqlite3_stmt
33103331
**
33113332
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
33123333
** and only if the [prepared statement] X makes no direct changes to
33133334
** the content of the database file.
33143335
**
@@ -3336,10 +3357,11 @@
33363357
*/
33373358
SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
33383359
33393360
/*
33403361
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3362
+** METHOD: sqlite3_stmt
33413363
**
33423364
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
33433365
** [prepared statement] S has been stepped at least once using
33443366
** [sqlite3_step(S)] but has not run to completion and/or has not
33453367
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
34103432
34113433
/*
34123434
** CAPI3REF: Binding Values To Prepared Statements
34133435
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
34143436
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3437
+** METHOD: sqlite3_stmt
34153438
**
34163439
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
34173440
** literals may be replaced by a [parameter] that matches one of following
34183441
** templates:
34193442
**
@@ -3528,10 +3551,11 @@
35283551
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
35293552
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
35303553
35313554
/*
35323555
** CAPI3REF: Number Of SQL Parameters
3556
+** METHOD: sqlite3_stmt
35333557
**
35343558
** ^This routine can be used to find the number of [SQL parameters]
35353559
** in a [prepared statement]. SQL parameters are tokens of the
35363560
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
35373561
** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
35483572
*/
35493573
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
35503574
35513575
/*
35523576
** CAPI3REF: Name Of A Host Parameter
3577
+** METHOD: sqlite3_stmt
35533578
**
35543579
** ^The sqlite3_bind_parameter_name(P,N) interface returns
35553580
** the name of the N-th [SQL parameter] in the [prepared statement] P.
35563581
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
35573582
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
35753600
*/
35763601
SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
35773602
35783603
/*
35793604
** CAPI3REF: Index Of A Parameter With A Given Name
3605
+** METHOD: sqlite3_stmt
35803606
**
35813607
** ^Return the index of an SQL parameter given its name. ^The
35823608
** index value returned is suitable for use as the second
35833609
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
35843610
** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
35913617
*/
35923618
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
35933619
35943620
/*
35953621
** CAPI3REF: Reset All Bindings On A Prepared Statement
3622
+** METHOD: sqlite3_stmt
35963623
**
35973624
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
35983625
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
35993626
** ^Use this routine to reset all host parameters to NULL.
36003627
*/
36013628
SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
36023629
36033630
/*
36043631
** CAPI3REF: Number Of Columns In A Result Set
3632
+** METHOD: sqlite3_stmt
36053633
**
36063634
** ^Return the number of columns in the result set returned by the
36073635
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
36083636
** statement that does not return data (for example an [UPDATE]).
36093637
**
@@ -3611,10 +3639,11 @@
36113639
*/
36123640
SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
36133641
36143642
/*
36153643
** CAPI3REF: Column Names In A Result Set
3644
+** METHOD: sqlite3_stmt
36163645
**
36173646
** ^These routines return the name assigned to a particular column
36183647
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
36193648
** interface returns a pointer to a zero-terminated UTF-8 string
36203649
** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
36403669
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
36413670
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
36423671
36433672
/*
36443673
** CAPI3REF: Source Of Data In A Query Result
3674
+** METHOD: sqlite3_stmt
36453675
**
36463676
** ^These routines provide a means to determine the database, table, and
36473677
** table column that is the origin of a particular result column in
36483678
** [SELECT] statement.
36493679
** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
36923722
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
36933723
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
36943724
36953725
/*
36963726
** CAPI3REF: Declared Datatype Of A Query Result
3727
+** METHOD: sqlite3_stmt
36973728
**
36983729
** ^(The first parameter is a [prepared statement].
36993730
** If this statement is a [SELECT] statement and the Nth column of the
37003731
** returned result set of that [SELECT] is a table column (not an
37013732
** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
37243755
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
37253756
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
37263757
37273758
/*
37283759
** CAPI3REF: Evaluate An SQL Statement
3760
+** METHOD: sqlite3_stmt
37293761
**
37303762
** After a [prepared statement] has been prepared using either
37313763
** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
37323764
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
37333765
** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
38033835
*/
38043836
SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
38053837
38063838
/*
38073839
** CAPI3REF: Number of columns in a result set
3840
+** METHOD: sqlite3_stmt
38083841
**
38093842
** ^The sqlite3_data_count(P) interface returns the number of columns in the
38103843
** current row of the result set of [prepared statement] P.
38113844
** ^If prepared statement P does not have results ready to return
38123845
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
38563889
#define SQLITE3_TEXT 3
38573890
38583891
/*
38593892
** CAPI3REF: Result Values From A Query
38603893
** KEYWORDS: {column access functions}
3894
+** METHOD: sqlite3_stmt
38613895
**
38623896
** These routines form the "result set" interface.
38633897
**
38643898
** ^These routines return information about a single column of the current
38653899
** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
40284062
SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
40294063
SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
40304064
40314065
/*
40324066
** CAPI3REF: Destroy A Prepared Statement Object
4067
+** DESTRUCTOR: sqlite3_stmt
40334068
**
40344069
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
40354070
** ^If the most recent evaluation of the statement encountered no errors
40364071
** or if the statement is never been evaluated, then sqlite3_finalize() returns
40374072
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
40554090
*/
40564091
SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
40574092
40584093
/*
40594094
** CAPI3REF: Reset A Prepared Statement Object
4095
+** METHOD: sqlite3_stmt
40604096
**
40614097
** The sqlite3_reset() function is called to reset a [prepared statement]
40624098
** object back to its initial state, ready to be re-executed.
40634099
** ^Any SQL statement variables that had values bound to them using
40644100
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
40844120
/*
40854121
** CAPI3REF: Create Or Redefine SQL Functions
40864122
** KEYWORDS: {function creation routines}
40874123
** KEYWORDS: {application-defined SQL function}
40884124
** KEYWORDS: {application-defined SQL functions}
4125
+** METHOD: sqlite3
40894126
**
40904127
** ^These functions (collectively known as "function creation routines")
40914128
** are used to add SQL functions or aggregates or to redefine the behavior
40924129
** of existing SQL functions or aggregates. The only differences between
40934130
** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
42534290
void*,sqlite3_int64);
42544291
#endif
42554292
42564293
/*
42574294
** CAPI3REF: Obtaining SQL Function Parameter Values
4295
+** METHOD: sqlite3_value
42584296
**
42594297
** The C-language implementation of SQL functions and aggregates uses
42604298
** this set of interface routines to access the parameter values on
42614299
** the function or aggregate.
42624300
**
@@ -4311,10 +4349,11 @@
43114349
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
43124350
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
43134351
43144352
/*
43154353
** CAPI3REF: Obtain Aggregate Function Context
4354
+** METHOD: sqlite3_context
43164355
**
43174356
** Implementations of aggregate SQL functions use this
43184357
** routine to allocate memory for storing their state.
43194358
**
43204359
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
43554394
*/
43564395
SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
43574396
43584397
/*
43594398
** CAPI3REF: User Data For Functions
4399
+** METHOD: sqlite3_context
43604400
**
43614401
** ^The sqlite3_user_data() interface returns a copy of
43624402
** the pointer that was the pUserData parameter (the 5th parameter)
43634403
** of the [sqlite3_create_function()]
43644404
** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
43694409
*/
43704410
SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
43714411
43724412
/*
43734413
** CAPI3REF: Database Connection For Functions
4414
+** METHOD: sqlite3_context
43744415
**
43754416
** ^The sqlite3_context_db_handle() interface returns a copy of
43764417
** the pointer to the [database connection] (the 1st parameter)
43774418
** of the [sqlite3_create_function()]
43784419
** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
43804421
*/
43814422
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
43824423
43834424
/*
43844425
** CAPI3REF: Function Auxiliary Data
4426
+** METHOD: sqlite3_context
43854427
**
43864428
** These functions may be used by (non-aggregate) SQL functions to
43874429
** associate metadata with argument values. If the same value is passed to
43884430
** multiple invocations of the same SQL function during query execution, under
43894431
** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
44524494
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
44534495
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
44544496
44554497
/*
44564498
** CAPI3REF: Setting The Result Of An SQL Function
4499
+** METHOD: sqlite3_context
44574500
**
44584501
** These routines are used by the xFunc or xFinal callbacks that
44594502
** implement SQL functions and aggregates. See
44604503
** [sqlite3_create_function()] and [sqlite3_create_function16()]
44614504
** for additional information.
@@ -4587,10 +4630,11 @@
45874630
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
45884631
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
45894632
45904633
/*
45914634
** CAPI3REF: Define New Collating Sequences
4635
+** METHOD: sqlite3
45924636
**
45934637
** ^These functions add, remove, or modify a [collation] associated
45944638
** with the [database connection] specified as the first argument.
45954639
**
45964640
** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
46894733
int(*xCompare)(void*,int,const void*,int,const void*)
46904734
);
46914735
46924736
/*
46934737
** CAPI3REF: Collation Needed Callbacks
4738
+** METHOD: sqlite3
46944739
**
46954740
** ^To avoid having to register all collation sequences before a database
46964741
** can be used, a single callback function may be registered with the
46974742
** [database connection] to be invoked whenever an undefined collation
46984743
** sequence is required.
@@ -4896,10 +4941,11 @@
48964941
SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
48974942
48984943
/*
48994944
** CAPI3REF: Test For Auto-Commit Mode
49004945
** KEYWORDS: {autocommit mode}
4946
+** METHOD: sqlite3
49014947
**
49024948
** ^The sqlite3_get_autocommit() interface returns non-zero or
49034949
** zero if the given database connection is or is not in autocommit mode,
49044950
** respectively. ^Autocommit mode is on by default.
49054951
** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
49184964
*/
49194965
SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
49204966
49214967
/*
49224968
** CAPI3REF: Find The Database Handle Of A Prepared Statement
4969
+** METHOD: sqlite3_stmt
49234970
**
49244971
** ^The sqlite3_db_handle interface returns the [database connection] handle
49254972
** to which a [prepared statement] belongs. ^The [database connection]
49264973
** returned by sqlite3_db_handle is the same [database connection]
49274974
** that was the first argument
@@ -4930,10 +4977,11 @@
49304977
*/
49314978
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
49324979
49334980
/*
49344981
** CAPI3REF: Return The Filename For A Database Connection
4982
+** METHOD: sqlite3
49354983
**
49364984
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
49374985
** associated with database N of connection D. ^The main database file
49384986
** has the name "main". If there is no attached database N on the database
49394987
** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
49464994
*/
49474995
SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
49484996
49494997
/*
49504998
** CAPI3REF: Determine if a database is read-only
4999
+** METHOD: sqlite3
49515000
**
49525001
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
49535002
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
49545003
** the name of a database on connection D.
49555004
*/
49565005
SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
49575006
49585007
/*
49595008
** CAPI3REF: Find the next prepared statement
5009
+** METHOD: sqlite3
49605010
**
49615011
** ^This interface returns a pointer to the next [prepared statement] after
49625012
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
49635013
** then this interface returns a pointer to the first prepared statement
49645014
** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
49705020
*/
49715021
SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
49725022
49735023
/*
49745024
** CAPI3REF: Commit And Rollback Notification Callbacks
5025
+** METHOD: sqlite3
49755026
**
49765027
** ^The sqlite3_commit_hook() interface registers a callback
49775028
** function to be invoked whenever a transaction is [COMMIT | committed].
49785029
** ^Any callback set by a previous call to sqlite3_commit_hook()
49795030
** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
50195070
SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
50205071
SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
50215072
50225073
/*
50235074
** CAPI3REF: Data Change Notification Callbacks
5075
+** METHOD: sqlite3
50245076
**
50255077
** ^The sqlite3_update_hook() interface registers a callback function
50265078
** with the [database connection] identified by the first argument
50275079
** to be invoked whenever a row is updated, inserted or deleted in
50285080
** a rowid table.
@@ -5125,10 +5177,11 @@
51255177
*/
51265178
SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
51275179
51285180
/*
51295181
** CAPI3REF: Free Memory Used By A Database Connection
5182
+** METHOD: sqlite3
51305183
**
51315184
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
51325185
** memory as possible from database connection D. Unlike the
51335186
** [sqlite3_release_memory()] interface, this interface is in effect even
51345187
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
52025255
SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
52035256
52045257
52055258
/*
52065259
** CAPI3REF: Extract Metadata About A Column Of A Table
5260
+** METHOD: sqlite3
52075261
**
52085262
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
52095263
** information about column C of table T in database D
52105264
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
52115265
** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
52805334
int *pAutoinc /* OUTPUT: True if column is auto-increment */
52815335
);
52825336
52835337
/*
52845338
** CAPI3REF: Load An Extension
5339
+** METHOD: sqlite3
52855340
**
52865341
** ^This interface loads an SQLite extension library from the named file.
52875342
**
52885343
** ^The sqlite3_load_extension() interface attempts to load an
52895344
** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
53215376
char **pzErrMsg /* Put error message here if not 0 */
53225377
);
53235378
53245379
/*
53255380
** CAPI3REF: Enable Or Disable Extension Loading
5381
+** METHOD: sqlite3
53265382
**
53275383
** ^So as not to open security holes in older applications that are
53285384
** unprepared to deal with [extension loading], and as a means of disabling
53295385
** [extension loading] while evaluating user-entered SQL, the following API
53305386
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
55705626
#define SQLITE_INDEX_CONSTRAINT_GE 32
55715627
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
55725628
55735629
/*
55745630
** CAPI3REF: Register A Virtual Table Implementation
5631
+** METHOD: sqlite3
55755632
**
55765633
** ^These routines are used to register a new [virtual table module] name.
55775634
** ^Module names must be registered before
55785635
** creating a new [virtual table] using the module and before using a
55795636
** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
56665723
*/
56675724
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
56685725
56695726
/*
56705727
** CAPI3REF: Overload A Function For A Virtual Table
5728
+** METHOD: sqlite3
56715729
**
56725730
** ^(Virtual tables can provide alternative implementations of functions
56735731
** using the [xFindFunction] method of the [virtual table module].
56745732
** But global versions of those functions
56755733
** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
57085766
*/
57095767
typedef struct sqlite3_blob sqlite3_blob;
57105768
57115769
/*
57125770
** CAPI3REF: Open A BLOB For Incremental I/O
5771
+** METHOD: sqlite3
5772
+** CONSTRUCTOR: sqlite3_blob
57135773
**
57145774
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
57155775
** in row iRow, column zColumn, table zTable in database zDb;
57165776
** in other words, the same BLOB that would be selected by:
57175777
**
@@ -5789,10 +5849,11 @@
57895849
sqlite3_blob **ppBlob
57905850
);
57915851
57925852
/*
57935853
** CAPI3REF: Move a BLOB Handle to a New Row
5854
+** METHOD: sqlite3_blob
57945855
**
57955856
** ^This function is used to move an existing blob handle so that it points
57965857
** to a different row of the same database table. ^The new row is identified
57975858
** by the rowid value passed as the second argument. Only the row can be
57985859
** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
58135874
*/
58145875
SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
58155876
58165877
/*
58175878
** CAPI3REF: Close A BLOB Handle
5879
+** DESTRUCTOR: sqlite3_blob
58185880
**
58195881
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
58205882
** unconditionally. Even if this routine returns an error code, the
58215883
** handle is still closed.)^
58225884
**
@@ -5835,10 +5897,11 @@
58355897
*/
58365898
SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
58375899
58385900
/*
58395901
** CAPI3REF: Return The Size Of An Open BLOB
5902
+** METHOD: sqlite3_blob
58405903
**
58415904
** ^Returns the size in bytes of the BLOB accessible via the
58425905
** successfully opened [BLOB handle] in its only argument. ^The
58435906
** incremental blob I/O routines can only read or overwriting existing
58445907
** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
58505913
*/
58515914
SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
58525915
58535916
/*
58545917
** CAPI3REF: Read Data From A BLOB Incrementally
5918
+** METHOD: sqlite3_blob
58555919
**
58565920
** ^(This function is used to read data from an open [BLOB handle] into a
58575921
** caller-supplied buffer. N bytes of data are copied into buffer Z
58585922
** from the open BLOB, starting at offset iOffset.)^
58595923
**
@@ -5878,10 +5942,11 @@
58785942
*/
58795943
SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
58805944
58815945
/*
58825946
** CAPI3REF: Write Data Into A BLOB Incrementally
5947
+** METHOD: sqlite3_blob
58835948
**
58845949
** ^(This function is used to write data into an open [BLOB handle] from a
58855950
** caller-supplied buffer. N bytes of data are copied from the buffer Z
58865951
** into the open BLOB, starting at offset iOffset.)^
58875952
**
@@ -6205,10 +6270,11 @@
62056270
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
62066271
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
62076272
62086273
/*
62096274
** CAPI3REF: Retrieve the mutex for a database connection
6275
+** METHOD: sqlite3
62106276
**
62116277
** ^This interface returns a pointer the [sqlite3_mutex] object that
62126278
** serializes access to the [database connection] given in the argument
62136279
** when the [threading mode] is Serialized.
62146280
** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
62166282
*/
62176283
SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
62186284
62196285
/*
62206286
** CAPI3REF: Low-Level Control Of Database Files
6287
+** METHOD: sqlite3
62216288
**
62226289
** ^The [sqlite3_file_control()] interface makes a direct call to the
62236290
** xFileControl method for the [sqlite3_io_methods] object associated
62246291
** with a particular database identified by the second argument. ^The
62256292
** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
64326499
#define SQLITE_STATUS_SCRATCH_SIZE 8
64336500
#define SQLITE_STATUS_MALLOC_COUNT 9
64346501
64356502
/*
64366503
** CAPI3REF: Database Connection Status
6504
+** METHOD: sqlite3
64376505
**
64386506
** ^This interface is used to retrieve runtime status information
64396507
** about a single [database connection]. ^The first argument is the
64406508
** database connection object to be interrogated. ^The second argument
64416509
** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
65606628
#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
65616629
65626630
65636631
/*
65646632
** CAPI3REF: Prepared Statement Status
6633
+** METHOD: sqlite3_stmt
65656634
**
65666635
** ^(Each prepared statement maintains various
65676636
** [SQLITE_STMTSTATUS counters] that measure the number
65686637
** of times it has performed specific operations.)^ These counters can
65696638
** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
70637132
SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
70647133
SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
70657134
70667135
/*
70677136
** CAPI3REF: Unlock Notification
7137
+** METHOD: sqlite3
70687138
**
70697139
** ^When running in shared-cache mode, a database operation may fail with
70707140
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
70717141
** individual tables within the shared-cache cannot be obtained. See
70727142
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
72337303
*/
72347304
SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
72357305
72367306
/*
72377307
** CAPI3REF: Write-Ahead Log Commit Hook
7308
+** METHOD: sqlite3
72387309
**
72397310
** ^The [sqlite3_wal_hook()] function is used to register a callback that
72407311
** is invoked each time data is committed to a database in wal mode.
72417312
**
72427313
** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
72727343
void*
72737344
);
72747345
72757346
/*
72767347
** CAPI3REF: Configure an auto-checkpoint
7348
+** METHOD: sqlite3
72777349
**
72787350
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
72797351
** [sqlite3_wal_hook()] that causes any database on [database connection] D
72807352
** to automatically [checkpoint]
72817353
** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
73027374
*/
73037375
SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
73047376
73057377
/*
73067378
** CAPI3REF: Checkpoint a database
7379
+** METHOD: sqlite3
73077380
**
73087381
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
73097382
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
73107383
**
73117384
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
73237396
*/
73247397
SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
73257398
73267399
/*
73277400
** CAPI3REF: Checkpoint a database
7401
+** METHOD: sqlite3
73287402
**
73297403
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
73307404
** operation on database X of [database connection] D in mode M. Status
73317405
** information is written back into integers pointed to by L and C.)^
73327406
** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
75777651
#define SQLITE_SCANSTAT_EXPLAIN 4
75787652
#define SQLITE_SCANSTAT_SELECTID 5
75797653
75807654
/*
75817655
** CAPI3REF: Prepared Statement Scan Status
7656
+** METHOD: sqlite3_stmt
75827657
**
75837658
** This interface returns information about the predicted and measured
75847659
** performance for pStmt. Advanced applications can use this
75857660
** interface to compare the predicted and the measured performance and
75867661
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
76147689
void *pOut /* Result written here */
76157690
);
76167691
76177692
/*
76187693
** CAPI3REF: Zero Scan-Status Counters
7694
+** METHOD: sqlite3_stmt
76197695
**
76207696
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
76217697
**
76227698
** This API is only available if the library is built with pre-processor
76237699
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
76247700
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.9"
115 #define SQLITE_VERSION_NUMBER 3008009
116 #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -268,10 +268,11 @@
268 # define double sqlite3_int64
269 #endif
270
271 /*
272 ** CAPI3REF: Closing A Database Connection
 
273 **
274 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
275 ** for the [sqlite3] object.
276 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
277 ** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
319 */
320 typedef int (*sqlite3_callback)(void*,int,char**, char**);
321
322 /*
323 ** CAPI3REF: One-Step Query Execution Interface
 
324 **
325 ** The sqlite3_exec() interface is a convenience wrapper around
326 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
327 ** that allows an application to run multiple statements of SQL
328 ** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
1376 */
1377 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1378
1379 /*
1380 ** CAPI3REF: Configure database connections
 
1381 **
1382 ** The sqlite3_db_config() interface is used to make configuration
1383 ** changes to a [database connection]. The interface is similar to
1384 ** [sqlite3_config()] except that the changes apply to a single
1385 ** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
1873 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1874
1875
1876 /*
1877 ** CAPI3REF: Enable Or Disable Extended Result Codes
 
1878 **
1879 ** ^The sqlite3_extended_result_codes() routine enables or disables the
1880 ** [extended result codes] feature of SQLite. ^The extended result
1881 ** codes are disabled by default for historical compatibility.
1882 */
1883 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
1884
1885 /*
1886 ** CAPI3REF: Last Insert Rowid
 
1887 **
1888 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1889 ** has a unique 64-bit signed
1890 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1891 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
1933 */
1934 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
1935
1936 /*
1937 ** CAPI3REF: Count The Number Of Rows Modified
 
1938 **
1939 ** ^This function returns the number of rows modified, inserted or
1940 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1941 ** statement on the database connection specified by the only parameter.
1942 ** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
1985 */
1986 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
1987
1988 /*
1989 ** CAPI3REF: Total Number Of Rows Modified
 
1990 **
1991 ** ^This function returns the total number of rows inserted, modified or
1992 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
1993 ** since the database connection was opened, including those executed as
1994 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
2008 */
2009 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2010
2011 /*
2012 ** CAPI3REF: Interrupt A Long-Running Query
 
2013 **
2014 ** ^This function causes any pending database operation to abort and
2015 ** return at its earliest opportunity. This routine is typically
2016 ** called in response to a user action such as pressing "Cancel"
2017 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
2084 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2085
2086 /*
2087 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2088 ** KEYWORDS: {busy-handler callback} {busy handler}
 
2089 **
2090 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2091 ** that might be invoked with argument P whenever
2092 ** an attempt is made to access a database table associated with
2093 ** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
2143 */
2144 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2145
2146 /*
2147 ** CAPI3REF: Set A Busy Timeout
 
2148 **
2149 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2150 ** for a specified amount of time when a table is locked. ^The handler
2151 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2152 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
2165 */
2166 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2167
2168 /*
2169 ** CAPI3REF: Convenience Routines For Running Queries
 
2170 **
2171 ** This is a legacy interface that is preserved for backwards compatibility.
2172 ** Use of this interface is not recommended.
2173 **
2174 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
2500 */
2501 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2502
2503 /*
2504 ** CAPI3REF: Compile-Time Authorization Callbacks
 
2505 **
2506 ** ^This routine registers an authorizer callback with a particular
2507 ** [database connection], supplied in the first argument.
2508 ** ^The authorizer callback is invoked as SQL statements are being compiled
2509 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
2656 #define SQLITE_COPY 0 /* No longer used */
2657 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2658
2659 /*
2660 ** CAPI3REF: Tracing And Profiling Functions
 
2661 **
2662 ** These routines register callback functions that can be used for
2663 ** tracing and profiling the execution of SQL statements.
2664 **
2665 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
2688 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2689 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2690
2691 /*
2692 ** CAPI3REF: Query Progress Callbacks
 
2693 **
2694 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2695 ** function X to be invoked periodically during long running calls to
2696 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2697 ** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
2721 */
2722 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2723
2724 /*
2725 ** CAPI3REF: Opening A New Database Connection
 
2726 **
2727 ** ^These routines open an SQLite database file as specified by the
2728 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2729 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2730 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
3006 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3007
3008
3009 /*
3010 ** CAPI3REF: Error Codes And Messages
 
3011 **
3012 ** ^If the most recent sqlite3_* API call associated with
3013 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3014 ** returns the numeric [result code] or [extended result code] for that
3015 ** API call.
@@ -3051,37 +3067,38 @@
3051 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3052 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3053 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3054
3055 /*
3056 ** CAPI3REF: SQL Statement Object
3057 ** KEYWORDS: {prepared statement} {prepared statements}
3058 **
3059 ** An instance of this object represents a single SQL statement.
3060 ** This object is variously known as a "prepared statement" or a
3061 ** "compiled SQL statement" or simply as a "statement".
3062 **
3063 ** The life of a statement object goes something like this:
 
 
 
 
 
3064 **
3065 ** <ol>
3066 ** <li> Create the object using [sqlite3_prepare_v2()] or a related
3067 ** function.
3068 ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3069 ** interfaces.
3070 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3071 ** <li> Reset the statement using [sqlite3_reset()] then go back
3072 ** to step 2. Do this zero or more times.
3073 ** <li> Destroy the object using [sqlite3_finalize()].
3074 ** </ol>
3075 **
3076 ** Refer to documentation on individual methods above for additional
3077 ** information.
3078 */
3079 typedef struct sqlite3_stmt sqlite3_stmt;
3080
3081 /*
3082 ** CAPI3REF: Run-time Limits
 
3083 **
3084 ** ^(This interface allows the size of various constructs to be limited
3085 ** on a connection by connection basis. The first parameter is the
3086 ** [database connection] whose limit is to be set or queried. The
3087 ** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
3189 #define SQLITE_LIMIT_WORKER_THREADS 11
3190
3191 /*
3192 ** CAPI3REF: Compiling An SQL Statement
3193 ** KEYWORDS: {SQL statement compiler}
 
 
3194 **
3195 ** To execute an SQL query, it must first be compiled into a byte-code
3196 ** program using one of these routines.
3197 **
3198 ** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
3296 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3297 );
3298
3299 /*
3300 ** CAPI3REF: Retrieving Statement SQL
 
3301 **
3302 ** ^This interface can be used to retrieve a saved copy of the original
3303 ** SQL text used to create a [prepared statement] if that statement was
3304 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3305 */
3306 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3307
3308 /*
3309 ** CAPI3REF: Determine If An SQL Statement Writes The Database
 
3310 **
3311 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3312 ** and only if the [prepared statement] X makes no direct changes to
3313 ** the content of the database file.
3314 **
@@ -3336,10 +3357,11 @@
3336 */
3337 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3338
3339 /*
3340 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
 
3341 **
3342 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3343 ** [prepared statement] S has been stepped at least once using
3344 ** [sqlite3_step(S)] but has not run to completion and/or has not
3345 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
3410
3411 /*
3412 ** CAPI3REF: Binding Values To Prepared Statements
3413 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3414 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 
3415 **
3416 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3417 ** literals may be replaced by a [parameter] that matches one of following
3418 ** templates:
3419 **
@@ -3528,10 +3551,11 @@
3528 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3529 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3530
3531 /*
3532 ** CAPI3REF: Number Of SQL Parameters
 
3533 **
3534 ** ^This routine can be used to find the number of [SQL parameters]
3535 ** in a [prepared statement]. SQL parameters are tokens of the
3536 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3537 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
3548 */
3549 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3550
3551 /*
3552 ** CAPI3REF: Name Of A Host Parameter
 
3553 **
3554 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3555 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3556 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3557 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
3575 */
3576 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3577
3578 /*
3579 ** CAPI3REF: Index Of A Parameter With A Given Name
 
3580 **
3581 ** ^Return the index of an SQL parameter given its name. ^The
3582 ** index value returned is suitable for use as the second
3583 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3584 ** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
3591 */
3592 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3593
3594 /*
3595 ** CAPI3REF: Reset All Bindings On A Prepared Statement
 
3596 **
3597 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3598 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3599 ** ^Use this routine to reset all host parameters to NULL.
3600 */
3601 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3602
3603 /*
3604 ** CAPI3REF: Number Of Columns In A Result Set
 
3605 **
3606 ** ^Return the number of columns in the result set returned by the
3607 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3608 ** statement that does not return data (for example an [UPDATE]).
3609 **
@@ -3611,10 +3639,11 @@
3611 */
3612 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3613
3614 /*
3615 ** CAPI3REF: Column Names In A Result Set
 
3616 **
3617 ** ^These routines return the name assigned to a particular column
3618 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3619 ** interface returns a pointer to a zero-terminated UTF-8 string
3620 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
3640 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3641 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3642
3643 /*
3644 ** CAPI3REF: Source Of Data In A Query Result
 
3645 **
3646 ** ^These routines provide a means to determine the database, table, and
3647 ** table column that is the origin of a particular result column in
3648 ** [SELECT] statement.
3649 ** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
3692 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3693 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3694
3695 /*
3696 ** CAPI3REF: Declared Datatype Of A Query Result
 
3697 **
3698 ** ^(The first parameter is a [prepared statement].
3699 ** If this statement is a [SELECT] statement and the Nth column of the
3700 ** returned result set of that [SELECT] is a table column (not an
3701 ** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
3724 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3725 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3726
3727 /*
3728 ** CAPI3REF: Evaluate An SQL Statement
 
3729 **
3730 ** After a [prepared statement] has been prepared using either
3731 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3732 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3733 ** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
3803 */
3804 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
3805
3806 /*
3807 ** CAPI3REF: Number of columns in a result set
 
3808 **
3809 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3810 ** current row of the result set of [prepared statement] P.
3811 ** ^If prepared statement P does not have results ready to return
3812 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
3856 #define SQLITE3_TEXT 3
3857
3858 /*
3859 ** CAPI3REF: Result Values From A Query
3860 ** KEYWORDS: {column access functions}
 
3861 **
3862 ** These routines form the "result set" interface.
3863 **
3864 ** ^These routines return information about a single column of the current
3865 ** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
4028 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4029 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4030
4031 /*
4032 ** CAPI3REF: Destroy A Prepared Statement Object
 
4033 **
4034 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4035 ** ^If the most recent evaluation of the statement encountered no errors
4036 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4037 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
4055 */
4056 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4057
4058 /*
4059 ** CAPI3REF: Reset A Prepared Statement Object
 
4060 **
4061 ** The sqlite3_reset() function is called to reset a [prepared statement]
4062 ** object back to its initial state, ready to be re-executed.
4063 ** ^Any SQL statement variables that had values bound to them using
4064 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
4084 /*
4085 ** CAPI3REF: Create Or Redefine SQL Functions
4086 ** KEYWORDS: {function creation routines}
4087 ** KEYWORDS: {application-defined SQL function}
4088 ** KEYWORDS: {application-defined SQL functions}
 
4089 **
4090 ** ^These functions (collectively known as "function creation routines")
4091 ** are used to add SQL functions or aggregates or to redefine the behavior
4092 ** of existing SQL functions or aggregates. The only differences between
4093 ** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
4253 void*,sqlite3_int64);
4254 #endif
4255
4256 /*
4257 ** CAPI3REF: Obtaining SQL Function Parameter Values
 
4258 **
4259 ** The C-language implementation of SQL functions and aggregates uses
4260 ** this set of interface routines to access the parameter values on
4261 ** the function or aggregate.
4262 **
@@ -4311,10 +4349,11 @@
4311 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4312 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4313
4314 /*
4315 ** CAPI3REF: Obtain Aggregate Function Context
 
4316 **
4317 ** Implementations of aggregate SQL functions use this
4318 ** routine to allocate memory for storing their state.
4319 **
4320 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
4355 */
4356 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4357
4358 /*
4359 ** CAPI3REF: User Data For Functions
 
4360 **
4361 ** ^The sqlite3_user_data() interface returns a copy of
4362 ** the pointer that was the pUserData parameter (the 5th parameter)
4363 ** of the [sqlite3_create_function()]
4364 ** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
4369 */
4370 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4371
4372 /*
4373 ** CAPI3REF: Database Connection For Functions
 
4374 **
4375 ** ^The sqlite3_context_db_handle() interface returns a copy of
4376 ** the pointer to the [database connection] (the 1st parameter)
4377 ** of the [sqlite3_create_function()]
4378 ** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
4380 */
4381 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4382
4383 /*
4384 ** CAPI3REF: Function Auxiliary Data
 
4385 **
4386 ** These functions may be used by (non-aggregate) SQL functions to
4387 ** associate metadata with argument values. If the same value is passed to
4388 ** multiple invocations of the same SQL function during query execution, under
4389 ** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
4452 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4453 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4454
4455 /*
4456 ** CAPI3REF: Setting The Result Of An SQL Function
 
4457 **
4458 ** These routines are used by the xFunc or xFinal callbacks that
4459 ** implement SQL functions and aggregates. See
4460 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4461 ** for additional information.
@@ -4587,10 +4630,11 @@
4587 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4588 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4589
4590 /*
4591 ** CAPI3REF: Define New Collating Sequences
 
4592 **
4593 ** ^These functions add, remove, or modify a [collation] associated
4594 ** with the [database connection] specified as the first argument.
4595 **
4596 ** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
4689 int(*xCompare)(void*,int,const void*,int,const void*)
4690 );
4691
4692 /*
4693 ** CAPI3REF: Collation Needed Callbacks
 
4694 **
4695 ** ^To avoid having to register all collation sequences before a database
4696 ** can be used, a single callback function may be registered with the
4697 ** [database connection] to be invoked whenever an undefined collation
4698 ** sequence is required.
@@ -4896,10 +4941,11 @@
4896 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
4897
4898 /*
4899 ** CAPI3REF: Test For Auto-Commit Mode
4900 ** KEYWORDS: {autocommit mode}
 
4901 **
4902 ** ^The sqlite3_get_autocommit() interface returns non-zero or
4903 ** zero if the given database connection is or is not in autocommit mode,
4904 ** respectively. ^Autocommit mode is on by default.
4905 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
4918 */
4919 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
4920
4921 /*
4922 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 
4923 **
4924 ** ^The sqlite3_db_handle interface returns the [database connection] handle
4925 ** to which a [prepared statement] belongs. ^The [database connection]
4926 ** returned by sqlite3_db_handle is the same [database connection]
4927 ** that was the first argument
@@ -4930,10 +4977,11 @@
4930 */
4931 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
4932
4933 /*
4934 ** CAPI3REF: Return The Filename For A Database Connection
 
4935 **
4936 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
4937 ** associated with database N of connection D. ^The main database file
4938 ** has the name "main". If there is no attached database N on the database
4939 ** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
4946 */
4947 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4948
4949 /*
4950 ** CAPI3REF: Determine if a database is read-only
 
4951 **
4952 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
4953 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
4954 ** the name of a database on connection D.
4955 */
4956 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
4957
4958 /*
4959 ** CAPI3REF: Find the next prepared statement
 
4960 **
4961 ** ^This interface returns a pointer to the next [prepared statement] after
4962 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
4963 ** then this interface returns a pointer to the first prepared statement
4964 ** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
4970 */
4971 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
4972
4973 /*
4974 ** CAPI3REF: Commit And Rollback Notification Callbacks
 
4975 **
4976 ** ^The sqlite3_commit_hook() interface registers a callback
4977 ** function to be invoked whenever a transaction is [COMMIT | committed].
4978 ** ^Any callback set by a previous call to sqlite3_commit_hook()
4979 ** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
5019 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5020 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5021
5022 /*
5023 ** CAPI3REF: Data Change Notification Callbacks
 
5024 **
5025 ** ^The sqlite3_update_hook() interface registers a callback function
5026 ** with the [database connection] identified by the first argument
5027 ** to be invoked whenever a row is updated, inserted or deleted in
5028 ** a rowid table.
@@ -5125,10 +5177,11 @@
5125 */
5126 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5127
5128 /*
5129 ** CAPI3REF: Free Memory Used By A Database Connection
 
5130 **
5131 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5132 ** memory as possible from database connection D. Unlike the
5133 ** [sqlite3_release_memory()] interface, this interface is in effect even
5134 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
5202 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5203
5204
5205 /*
5206 ** CAPI3REF: Extract Metadata About A Column Of A Table
 
5207 **
5208 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5209 ** information about column C of table T in database D
5210 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5211 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
5280 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5281 );
5282
5283 /*
5284 ** CAPI3REF: Load An Extension
 
5285 **
5286 ** ^This interface loads an SQLite extension library from the named file.
5287 **
5288 ** ^The sqlite3_load_extension() interface attempts to load an
5289 ** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
5321 char **pzErrMsg /* Put error message here if not 0 */
5322 );
5323
5324 /*
5325 ** CAPI3REF: Enable Or Disable Extension Loading
 
5326 **
5327 ** ^So as not to open security holes in older applications that are
5328 ** unprepared to deal with [extension loading], and as a means of disabling
5329 ** [extension loading] while evaluating user-entered SQL, the following API
5330 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
5570 #define SQLITE_INDEX_CONSTRAINT_GE 32
5571 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5572
5573 /*
5574 ** CAPI3REF: Register A Virtual Table Implementation
 
5575 **
5576 ** ^These routines are used to register a new [virtual table module] name.
5577 ** ^Module names must be registered before
5578 ** creating a new [virtual table] using the module and before using a
5579 ** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
5666 */
5667 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5668
5669 /*
5670 ** CAPI3REF: Overload A Function For A Virtual Table
 
5671 **
5672 ** ^(Virtual tables can provide alternative implementations of functions
5673 ** using the [xFindFunction] method of the [virtual table module].
5674 ** But global versions of those functions
5675 ** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
5708 */
5709 typedef struct sqlite3_blob sqlite3_blob;
5710
5711 /*
5712 ** CAPI3REF: Open A BLOB For Incremental I/O
 
 
5713 **
5714 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5715 ** in row iRow, column zColumn, table zTable in database zDb;
5716 ** in other words, the same BLOB that would be selected by:
5717 **
@@ -5789,10 +5849,11 @@
5789 sqlite3_blob **ppBlob
5790 );
5791
5792 /*
5793 ** CAPI3REF: Move a BLOB Handle to a New Row
 
5794 **
5795 ** ^This function is used to move an existing blob handle so that it points
5796 ** to a different row of the same database table. ^The new row is identified
5797 ** by the rowid value passed as the second argument. Only the row can be
5798 ** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
5813 */
5814 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5815
5816 /*
5817 ** CAPI3REF: Close A BLOB Handle
 
5818 **
5819 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5820 ** unconditionally. Even if this routine returns an error code, the
5821 ** handle is still closed.)^
5822 **
@@ -5835,10 +5897,11 @@
5835 */
5836 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
5837
5838 /*
5839 ** CAPI3REF: Return The Size Of An Open BLOB
 
5840 **
5841 ** ^Returns the size in bytes of the BLOB accessible via the
5842 ** successfully opened [BLOB handle] in its only argument. ^The
5843 ** incremental blob I/O routines can only read or overwriting existing
5844 ** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
5850 */
5851 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
5852
5853 /*
5854 ** CAPI3REF: Read Data From A BLOB Incrementally
 
5855 **
5856 ** ^(This function is used to read data from an open [BLOB handle] into a
5857 ** caller-supplied buffer. N bytes of data are copied into buffer Z
5858 ** from the open BLOB, starting at offset iOffset.)^
5859 **
@@ -5878,10 +5942,11 @@
5878 */
5879 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5880
5881 /*
5882 ** CAPI3REF: Write Data Into A BLOB Incrementally
 
5883 **
5884 ** ^(This function is used to write data into an open [BLOB handle] from a
5885 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5886 ** into the open BLOB, starting at offset iOffset.)^
5887 **
@@ -6205,10 +6270,11 @@
6205 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6206 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6207
6208 /*
6209 ** CAPI3REF: Retrieve the mutex for a database connection
 
6210 **
6211 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6212 ** serializes access to the [database connection] given in the argument
6213 ** when the [threading mode] is Serialized.
6214 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
6216 */
6217 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6218
6219 /*
6220 ** CAPI3REF: Low-Level Control Of Database Files
 
6221 **
6222 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6223 ** xFileControl method for the [sqlite3_io_methods] object associated
6224 ** with a particular database identified by the second argument. ^The
6225 ** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
6432 #define SQLITE_STATUS_SCRATCH_SIZE 8
6433 #define SQLITE_STATUS_MALLOC_COUNT 9
6434
6435 /*
6436 ** CAPI3REF: Database Connection Status
 
6437 **
6438 ** ^This interface is used to retrieve runtime status information
6439 ** about a single [database connection]. ^The first argument is the
6440 ** database connection object to be interrogated. ^The second argument
6441 ** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
6560 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6561
6562
6563 /*
6564 ** CAPI3REF: Prepared Statement Status
 
6565 **
6566 ** ^(Each prepared statement maintains various
6567 ** [SQLITE_STMTSTATUS counters] that measure the number
6568 ** of times it has performed specific operations.)^ These counters can
6569 ** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
7063 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7064 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7065
7066 /*
7067 ** CAPI3REF: Unlock Notification
 
7068 **
7069 ** ^When running in shared-cache mode, a database operation may fail with
7070 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7071 ** individual tables within the shared-cache cannot be obtained. See
7072 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
7233 */
7234 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7235
7236 /*
7237 ** CAPI3REF: Write-Ahead Log Commit Hook
 
7238 **
7239 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7240 ** is invoked each time data is committed to a database in wal mode.
7241 **
7242 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
7272 void*
7273 );
7274
7275 /*
7276 ** CAPI3REF: Configure an auto-checkpoint
 
7277 **
7278 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7279 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7280 ** to automatically [checkpoint]
7281 ** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
7302 */
7303 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7304
7305 /*
7306 ** CAPI3REF: Checkpoint a database
 
7307 **
7308 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7309 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7310 **
7311 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
7323 */
7324 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7325
7326 /*
7327 ** CAPI3REF: Checkpoint a database
 
7328 **
7329 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7330 ** operation on database X of [database connection] D in mode M. Status
7331 ** information is written back into integers pointed to by L and C.)^
7332 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
7577 #define SQLITE_SCANSTAT_EXPLAIN 4
7578 #define SQLITE_SCANSTAT_SELECTID 5
7579
7580 /*
7581 ** CAPI3REF: Prepared Statement Scan Status
 
7582 **
7583 ** This interface returns information about the predicted and measured
7584 ** performance for pStmt. Advanced applications can use this
7585 ** interface to compare the predicted and the measured performance and
7586 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
7614 void *pOut /* Result written here */
7615 );
7616
7617 /*
7618 ** CAPI3REF: Zero Scan-Status Counters
 
7619 **
7620 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7621 **
7622 ** This API is only available if the library is built with pre-processor
7623 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7624
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.10"
115 #define SQLITE_VERSION_NUMBER 3008010
116 #define SQLITE_SOURCE_ID "2015-05-07 11:53:08 cf975957b9ae671f34bb65f049acf351e650d437"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -268,10 +268,11 @@
268 # define double sqlite3_int64
269 #endif
270
271 /*
272 ** CAPI3REF: Closing A Database Connection
273 ** DESTRUCTOR: sqlite3
274 **
275 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
276 ** for the [sqlite3] object.
277 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
278 ** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
320 */
321 typedef int (*sqlite3_callback)(void*,int,char**, char**);
322
323 /*
324 ** CAPI3REF: One-Step Query Execution Interface
325 ** METHOD: sqlite3
326 **
327 ** The sqlite3_exec() interface is a convenience wrapper around
328 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
329 ** that allows an application to run multiple statements of SQL
330 ** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
1378 */
1379 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1380
1381 /*
1382 ** CAPI3REF: Configure database connections
1383 ** METHOD: sqlite3
1384 **
1385 ** The sqlite3_db_config() interface is used to make configuration
1386 ** changes to a [database connection]. The interface is similar to
1387 ** [sqlite3_config()] except that the changes apply to a single
1388 ** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
1876 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1877
1878
1879 /*
1880 ** CAPI3REF: Enable Or Disable Extended Result Codes
1881 ** METHOD: sqlite3
1882 **
1883 ** ^The sqlite3_extended_result_codes() routine enables or disables the
1884 ** [extended result codes] feature of SQLite. ^The extended result
1885 ** codes are disabled by default for historical compatibility.
1886 */
1887 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
1888
1889 /*
1890 ** CAPI3REF: Last Insert Rowid
1891 ** METHOD: sqlite3
1892 **
1893 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1894 ** has a unique 64-bit signed
1895 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1896 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
1938 */
1939 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
1940
1941 /*
1942 ** CAPI3REF: Count The Number Of Rows Modified
1943 ** METHOD: sqlite3
1944 **
1945 ** ^This function returns the number of rows modified, inserted or
1946 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1947 ** statement on the database connection specified by the only parameter.
1948 ** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
1991 */
1992 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
1993
1994 /*
1995 ** CAPI3REF: Total Number Of Rows Modified
1996 ** METHOD: sqlite3
1997 **
1998 ** ^This function returns the total number of rows inserted, modified or
1999 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2000 ** since the database connection was opened, including those executed as
2001 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
2015 */
2016 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2017
2018 /*
2019 ** CAPI3REF: Interrupt A Long-Running Query
2020 ** METHOD: sqlite3
2021 **
2022 ** ^This function causes any pending database operation to abort and
2023 ** return at its earliest opportunity. This routine is typically
2024 ** called in response to a user action such as pressing "Cancel"
2025 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
2092 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2093
2094 /*
2095 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2096 ** KEYWORDS: {busy-handler callback} {busy handler}
2097 ** METHOD: sqlite3
2098 **
2099 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2100 ** that might be invoked with argument P whenever
2101 ** an attempt is made to access a database table associated with
2102 ** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
2152 */
2153 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2154
2155 /*
2156 ** CAPI3REF: Set A Busy Timeout
2157 ** METHOD: sqlite3
2158 **
2159 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2160 ** for a specified amount of time when a table is locked. ^The handler
2161 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2162 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
2175 */
2176 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2177
2178 /*
2179 ** CAPI3REF: Convenience Routines For Running Queries
2180 ** METHOD: sqlite3
2181 **
2182 ** This is a legacy interface that is preserved for backwards compatibility.
2183 ** Use of this interface is not recommended.
2184 **
2185 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
2511 */
2512 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2513
2514 /*
2515 ** CAPI3REF: Compile-Time Authorization Callbacks
2516 ** METHOD: sqlite3
2517 **
2518 ** ^This routine registers an authorizer callback with a particular
2519 ** [database connection], supplied in the first argument.
2520 ** ^The authorizer callback is invoked as SQL statements are being compiled
2521 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
2668 #define SQLITE_COPY 0 /* No longer used */
2669 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2670
2671 /*
2672 ** CAPI3REF: Tracing And Profiling Functions
2673 ** METHOD: sqlite3
2674 **
2675 ** These routines register callback functions that can be used for
2676 ** tracing and profiling the execution of SQL statements.
2677 **
2678 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
2701 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2702 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2703
2704 /*
2705 ** CAPI3REF: Query Progress Callbacks
2706 ** METHOD: sqlite3
2707 **
2708 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2709 ** function X to be invoked periodically during long running calls to
2710 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2711 ** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
2735 */
2736 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2737
2738 /*
2739 ** CAPI3REF: Opening A New Database Connection
2740 ** CONSTRUCTOR: sqlite3
2741 **
2742 ** ^These routines open an SQLite database file as specified by the
2743 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2744 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2745 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
3021 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3022
3023
3024 /*
3025 ** CAPI3REF: Error Codes And Messages
3026 ** METHOD: sqlite3
3027 **
3028 ** ^If the most recent sqlite3_* API call associated with
3029 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3030 ** returns the numeric [result code] or [extended result code] for that
3031 ** API call.
@@ -3051,37 +3067,38 @@
3067 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3068 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3069 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3070
3071 /*
3072 ** CAPI3REF: Prepared Statement Object
3073 ** KEYWORDS: {prepared statement} {prepared statements}
3074 **
3075 ** An instance of this object represents a single SQL statement that
3076 ** has been compiled into binary form and is ready to be evaluated.
 
3077 **
3078 ** Think of each SQL statement as a separate computer program. The
3079 ** original SQL text is source code. A prepared statement object
3080 ** is the compiled object code. All SQL must be converted into a
3081 ** prepared statement before it can be run.
3082 **
3083 ** The life-cycle of a prepared statement object usually goes like this:
3084 **
3085 ** <ol>
3086 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3087 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
 
3088 ** interfaces.
3089 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3090 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3091 ** to step 2. Do this zero or more times.
3092 ** <li> Destroy the object using [sqlite3_finalize()].
3093 ** </ol>
 
 
 
3094 */
3095 typedef struct sqlite3_stmt sqlite3_stmt;
3096
3097 /*
3098 ** CAPI3REF: Run-time Limits
3099 ** METHOD: sqlite3
3100 **
3101 ** ^(This interface allows the size of various constructs to be limited
3102 ** on a connection by connection basis. The first parameter is the
3103 ** [database connection] whose limit is to be set or queried. The
3104 ** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
3206 #define SQLITE_LIMIT_WORKER_THREADS 11
3207
3208 /*
3209 ** CAPI3REF: Compiling An SQL Statement
3210 ** KEYWORDS: {SQL statement compiler}
3211 ** METHOD: sqlite3
3212 ** CONSTRUCTOR: sqlite3_stmt
3213 **
3214 ** To execute an SQL query, it must first be compiled into a byte-code
3215 ** program using one of these routines.
3216 **
3217 ** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
3315 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3316 );
3317
3318 /*
3319 ** CAPI3REF: Retrieving Statement SQL
3320 ** METHOD: sqlite3_stmt
3321 **
3322 ** ^This interface can be used to retrieve a saved copy of the original
3323 ** SQL text used to create a [prepared statement] if that statement was
3324 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3325 */
3326 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3327
3328 /*
3329 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3330 ** METHOD: sqlite3_stmt
3331 **
3332 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3333 ** and only if the [prepared statement] X makes no direct changes to
3334 ** the content of the database file.
3335 **
@@ -3336,10 +3357,11 @@
3357 */
3358 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3359
3360 /*
3361 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3362 ** METHOD: sqlite3_stmt
3363 **
3364 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3365 ** [prepared statement] S has been stepped at least once using
3366 ** [sqlite3_step(S)] but has not run to completion and/or has not
3367 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
3432
3433 /*
3434 ** CAPI3REF: Binding Values To Prepared Statements
3435 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3436 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3437 ** METHOD: sqlite3_stmt
3438 **
3439 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3440 ** literals may be replaced by a [parameter] that matches one of following
3441 ** templates:
3442 **
@@ -3528,10 +3551,11 @@
3551 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3552 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3553
3554 /*
3555 ** CAPI3REF: Number Of SQL Parameters
3556 ** METHOD: sqlite3_stmt
3557 **
3558 ** ^This routine can be used to find the number of [SQL parameters]
3559 ** in a [prepared statement]. SQL parameters are tokens of the
3560 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3561 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
3572 */
3573 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3574
3575 /*
3576 ** CAPI3REF: Name Of A Host Parameter
3577 ** METHOD: sqlite3_stmt
3578 **
3579 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3580 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3581 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3582 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
3600 */
3601 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3602
3603 /*
3604 ** CAPI3REF: Index Of A Parameter With A Given Name
3605 ** METHOD: sqlite3_stmt
3606 **
3607 ** ^Return the index of an SQL parameter given its name. ^The
3608 ** index value returned is suitable for use as the second
3609 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3610 ** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
3617 */
3618 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3619
3620 /*
3621 ** CAPI3REF: Reset All Bindings On A Prepared Statement
3622 ** METHOD: sqlite3_stmt
3623 **
3624 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3625 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3626 ** ^Use this routine to reset all host parameters to NULL.
3627 */
3628 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3629
3630 /*
3631 ** CAPI3REF: Number Of Columns In A Result Set
3632 ** METHOD: sqlite3_stmt
3633 **
3634 ** ^Return the number of columns in the result set returned by the
3635 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3636 ** statement that does not return data (for example an [UPDATE]).
3637 **
@@ -3611,10 +3639,11 @@
3639 */
3640 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3641
3642 /*
3643 ** CAPI3REF: Column Names In A Result Set
3644 ** METHOD: sqlite3_stmt
3645 **
3646 ** ^These routines return the name assigned to a particular column
3647 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3648 ** interface returns a pointer to a zero-terminated UTF-8 string
3649 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
3669 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3670 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3671
3672 /*
3673 ** CAPI3REF: Source Of Data In A Query Result
3674 ** METHOD: sqlite3_stmt
3675 **
3676 ** ^These routines provide a means to determine the database, table, and
3677 ** table column that is the origin of a particular result column in
3678 ** [SELECT] statement.
3679 ** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
3722 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3723 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3724
3725 /*
3726 ** CAPI3REF: Declared Datatype Of A Query Result
3727 ** METHOD: sqlite3_stmt
3728 **
3729 ** ^(The first parameter is a [prepared statement].
3730 ** If this statement is a [SELECT] statement and the Nth column of the
3731 ** returned result set of that [SELECT] is a table column (not an
3732 ** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
3755 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3756 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3757
3758 /*
3759 ** CAPI3REF: Evaluate An SQL Statement
3760 ** METHOD: sqlite3_stmt
3761 **
3762 ** After a [prepared statement] has been prepared using either
3763 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3764 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3765 ** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
3835 */
3836 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
3837
3838 /*
3839 ** CAPI3REF: Number of columns in a result set
3840 ** METHOD: sqlite3_stmt
3841 **
3842 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3843 ** current row of the result set of [prepared statement] P.
3844 ** ^If prepared statement P does not have results ready to return
3845 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
3889 #define SQLITE3_TEXT 3
3890
3891 /*
3892 ** CAPI3REF: Result Values From A Query
3893 ** KEYWORDS: {column access functions}
3894 ** METHOD: sqlite3_stmt
3895 **
3896 ** These routines form the "result set" interface.
3897 **
3898 ** ^These routines return information about a single column of the current
3899 ** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
4062 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4063 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4064
4065 /*
4066 ** CAPI3REF: Destroy A Prepared Statement Object
4067 ** DESTRUCTOR: sqlite3_stmt
4068 **
4069 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4070 ** ^If the most recent evaluation of the statement encountered no errors
4071 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4072 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
4090 */
4091 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4092
4093 /*
4094 ** CAPI3REF: Reset A Prepared Statement Object
4095 ** METHOD: sqlite3_stmt
4096 **
4097 ** The sqlite3_reset() function is called to reset a [prepared statement]
4098 ** object back to its initial state, ready to be re-executed.
4099 ** ^Any SQL statement variables that had values bound to them using
4100 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
4120 /*
4121 ** CAPI3REF: Create Or Redefine SQL Functions
4122 ** KEYWORDS: {function creation routines}
4123 ** KEYWORDS: {application-defined SQL function}
4124 ** KEYWORDS: {application-defined SQL functions}
4125 ** METHOD: sqlite3
4126 **
4127 ** ^These functions (collectively known as "function creation routines")
4128 ** are used to add SQL functions or aggregates or to redefine the behavior
4129 ** of existing SQL functions or aggregates. The only differences between
4130 ** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
4290 void*,sqlite3_int64);
4291 #endif
4292
4293 /*
4294 ** CAPI3REF: Obtaining SQL Function Parameter Values
4295 ** METHOD: sqlite3_value
4296 **
4297 ** The C-language implementation of SQL functions and aggregates uses
4298 ** this set of interface routines to access the parameter values on
4299 ** the function or aggregate.
4300 **
@@ -4311,10 +4349,11 @@
4349 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4350 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4351
4352 /*
4353 ** CAPI3REF: Obtain Aggregate Function Context
4354 ** METHOD: sqlite3_context
4355 **
4356 ** Implementations of aggregate SQL functions use this
4357 ** routine to allocate memory for storing their state.
4358 **
4359 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
4394 */
4395 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4396
4397 /*
4398 ** CAPI3REF: User Data For Functions
4399 ** METHOD: sqlite3_context
4400 **
4401 ** ^The sqlite3_user_data() interface returns a copy of
4402 ** the pointer that was the pUserData parameter (the 5th parameter)
4403 ** of the [sqlite3_create_function()]
4404 ** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
4409 */
4410 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4411
4412 /*
4413 ** CAPI3REF: Database Connection For Functions
4414 ** METHOD: sqlite3_context
4415 **
4416 ** ^The sqlite3_context_db_handle() interface returns a copy of
4417 ** the pointer to the [database connection] (the 1st parameter)
4418 ** of the [sqlite3_create_function()]
4419 ** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
4421 */
4422 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4423
4424 /*
4425 ** CAPI3REF: Function Auxiliary Data
4426 ** METHOD: sqlite3_context
4427 **
4428 ** These functions may be used by (non-aggregate) SQL functions to
4429 ** associate metadata with argument values. If the same value is passed to
4430 ** multiple invocations of the same SQL function during query execution, under
4431 ** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
4494 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4495 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4496
4497 /*
4498 ** CAPI3REF: Setting The Result Of An SQL Function
4499 ** METHOD: sqlite3_context
4500 **
4501 ** These routines are used by the xFunc or xFinal callbacks that
4502 ** implement SQL functions and aggregates. See
4503 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4504 ** for additional information.
@@ -4587,10 +4630,11 @@
4630 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4631 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4632
4633 /*
4634 ** CAPI3REF: Define New Collating Sequences
4635 ** METHOD: sqlite3
4636 **
4637 ** ^These functions add, remove, or modify a [collation] associated
4638 ** with the [database connection] specified as the first argument.
4639 **
4640 ** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
4733 int(*xCompare)(void*,int,const void*,int,const void*)
4734 );
4735
4736 /*
4737 ** CAPI3REF: Collation Needed Callbacks
4738 ** METHOD: sqlite3
4739 **
4740 ** ^To avoid having to register all collation sequences before a database
4741 ** can be used, a single callback function may be registered with the
4742 ** [database connection] to be invoked whenever an undefined collation
4743 ** sequence is required.
@@ -4896,10 +4941,11 @@
4941 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
4942
4943 /*
4944 ** CAPI3REF: Test For Auto-Commit Mode
4945 ** KEYWORDS: {autocommit mode}
4946 ** METHOD: sqlite3
4947 **
4948 ** ^The sqlite3_get_autocommit() interface returns non-zero or
4949 ** zero if the given database connection is or is not in autocommit mode,
4950 ** respectively. ^Autocommit mode is on by default.
4951 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
4964 */
4965 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
4966
4967 /*
4968 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
4969 ** METHOD: sqlite3_stmt
4970 **
4971 ** ^The sqlite3_db_handle interface returns the [database connection] handle
4972 ** to which a [prepared statement] belongs. ^The [database connection]
4973 ** returned by sqlite3_db_handle is the same [database connection]
4974 ** that was the first argument
@@ -4930,10 +4977,11 @@
4977 */
4978 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
4979
4980 /*
4981 ** CAPI3REF: Return The Filename For A Database Connection
4982 ** METHOD: sqlite3
4983 **
4984 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
4985 ** associated with database N of connection D. ^The main database file
4986 ** has the name "main". If there is no attached database N on the database
4987 ** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
4994 */
4995 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4996
4997 /*
4998 ** CAPI3REF: Determine if a database is read-only
4999 ** METHOD: sqlite3
5000 **
5001 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5002 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5003 ** the name of a database on connection D.
5004 */
5005 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5006
5007 /*
5008 ** CAPI3REF: Find the next prepared statement
5009 ** METHOD: sqlite3
5010 **
5011 ** ^This interface returns a pointer to the next [prepared statement] after
5012 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5013 ** then this interface returns a pointer to the first prepared statement
5014 ** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
5020 */
5021 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5022
5023 /*
5024 ** CAPI3REF: Commit And Rollback Notification Callbacks
5025 ** METHOD: sqlite3
5026 **
5027 ** ^The sqlite3_commit_hook() interface registers a callback
5028 ** function to be invoked whenever a transaction is [COMMIT | committed].
5029 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5030 ** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
5070 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5071 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5072
5073 /*
5074 ** CAPI3REF: Data Change Notification Callbacks
5075 ** METHOD: sqlite3
5076 **
5077 ** ^The sqlite3_update_hook() interface registers a callback function
5078 ** with the [database connection] identified by the first argument
5079 ** to be invoked whenever a row is updated, inserted or deleted in
5080 ** a rowid table.
@@ -5125,10 +5177,11 @@
5177 */
5178 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5179
5180 /*
5181 ** CAPI3REF: Free Memory Used By A Database Connection
5182 ** METHOD: sqlite3
5183 **
5184 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5185 ** memory as possible from database connection D. Unlike the
5186 ** [sqlite3_release_memory()] interface, this interface is in effect even
5187 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
5255 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5256
5257
5258 /*
5259 ** CAPI3REF: Extract Metadata About A Column Of A Table
5260 ** METHOD: sqlite3
5261 **
5262 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5263 ** information about column C of table T in database D
5264 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5265 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
5334 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5335 );
5336
5337 /*
5338 ** CAPI3REF: Load An Extension
5339 ** METHOD: sqlite3
5340 **
5341 ** ^This interface loads an SQLite extension library from the named file.
5342 **
5343 ** ^The sqlite3_load_extension() interface attempts to load an
5344 ** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
5376 char **pzErrMsg /* Put error message here if not 0 */
5377 );
5378
5379 /*
5380 ** CAPI3REF: Enable Or Disable Extension Loading
5381 ** METHOD: sqlite3
5382 **
5383 ** ^So as not to open security holes in older applications that are
5384 ** unprepared to deal with [extension loading], and as a means of disabling
5385 ** [extension loading] while evaluating user-entered SQL, the following API
5386 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
5626 #define SQLITE_INDEX_CONSTRAINT_GE 32
5627 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5628
5629 /*
5630 ** CAPI3REF: Register A Virtual Table Implementation
5631 ** METHOD: sqlite3
5632 **
5633 ** ^These routines are used to register a new [virtual table module] name.
5634 ** ^Module names must be registered before
5635 ** creating a new [virtual table] using the module and before using a
5636 ** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
5723 */
5724 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5725
5726 /*
5727 ** CAPI3REF: Overload A Function For A Virtual Table
5728 ** METHOD: sqlite3
5729 **
5730 ** ^(Virtual tables can provide alternative implementations of functions
5731 ** using the [xFindFunction] method of the [virtual table module].
5732 ** But global versions of those functions
5733 ** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
5766 */
5767 typedef struct sqlite3_blob sqlite3_blob;
5768
5769 /*
5770 ** CAPI3REF: Open A BLOB For Incremental I/O
5771 ** METHOD: sqlite3
5772 ** CONSTRUCTOR: sqlite3_blob
5773 **
5774 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5775 ** in row iRow, column zColumn, table zTable in database zDb;
5776 ** in other words, the same BLOB that would be selected by:
5777 **
@@ -5789,10 +5849,11 @@
5849 sqlite3_blob **ppBlob
5850 );
5851
5852 /*
5853 ** CAPI3REF: Move a BLOB Handle to a New Row
5854 ** METHOD: sqlite3_blob
5855 **
5856 ** ^This function is used to move an existing blob handle so that it points
5857 ** to a different row of the same database table. ^The new row is identified
5858 ** by the rowid value passed as the second argument. Only the row can be
5859 ** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
5874 */
5875 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5876
5877 /*
5878 ** CAPI3REF: Close A BLOB Handle
5879 ** DESTRUCTOR: sqlite3_blob
5880 **
5881 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5882 ** unconditionally. Even if this routine returns an error code, the
5883 ** handle is still closed.)^
5884 **
@@ -5835,10 +5897,11 @@
5897 */
5898 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
5899
5900 /*
5901 ** CAPI3REF: Return The Size Of An Open BLOB
5902 ** METHOD: sqlite3_blob
5903 **
5904 ** ^Returns the size in bytes of the BLOB accessible via the
5905 ** successfully opened [BLOB handle] in its only argument. ^The
5906 ** incremental blob I/O routines can only read or overwriting existing
5907 ** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
5913 */
5914 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
5915
5916 /*
5917 ** CAPI3REF: Read Data From A BLOB Incrementally
5918 ** METHOD: sqlite3_blob
5919 **
5920 ** ^(This function is used to read data from an open [BLOB handle] into a
5921 ** caller-supplied buffer. N bytes of data are copied into buffer Z
5922 ** from the open BLOB, starting at offset iOffset.)^
5923 **
@@ -5878,10 +5942,11 @@
5942 */
5943 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5944
5945 /*
5946 ** CAPI3REF: Write Data Into A BLOB Incrementally
5947 ** METHOD: sqlite3_blob
5948 **
5949 ** ^(This function is used to write data into an open [BLOB handle] from a
5950 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5951 ** into the open BLOB, starting at offset iOffset.)^
5952 **
@@ -6205,10 +6270,11 @@
6270 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6271 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6272
6273 /*
6274 ** CAPI3REF: Retrieve the mutex for a database connection
6275 ** METHOD: sqlite3
6276 **
6277 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6278 ** serializes access to the [database connection] given in the argument
6279 ** when the [threading mode] is Serialized.
6280 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
6282 */
6283 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6284
6285 /*
6286 ** CAPI3REF: Low-Level Control Of Database Files
6287 ** METHOD: sqlite3
6288 **
6289 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6290 ** xFileControl method for the [sqlite3_io_methods] object associated
6291 ** with a particular database identified by the second argument. ^The
6292 ** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
6499 #define SQLITE_STATUS_SCRATCH_SIZE 8
6500 #define SQLITE_STATUS_MALLOC_COUNT 9
6501
6502 /*
6503 ** CAPI3REF: Database Connection Status
6504 ** METHOD: sqlite3
6505 **
6506 ** ^This interface is used to retrieve runtime status information
6507 ** about a single [database connection]. ^The first argument is the
6508 ** database connection object to be interrogated. ^The second argument
6509 ** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
6628 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6629
6630
6631 /*
6632 ** CAPI3REF: Prepared Statement Status
6633 ** METHOD: sqlite3_stmt
6634 **
6635 ** ^(Each prepared statement maintains various
6636 ** [SQLITE_STMTSTATUS counters] that measure the number
6637 ** of times it has performed specific operations.)^ These counters can
6638 ** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
7132 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7133 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7134
7135 /*
7136 ** CAPI3REF: Unlock Notification
7137 ** METHOD: sqlite3
7138 **
7139 ** ^When running in shared-cache mode, a database operation may fail with
7140 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7141 ** individual tables within the shared-cache cannot be obtained. See
7142 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
7303 */
7304 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7305
7306 /*
7307 ** CAPI3REF: Write-Ahead Log Commit Hook
7308 ** METHOD: sqlite3
7309 **
7310 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7311 ** is invoked each time data is committed to a database in wal mode.
7312 **
7313 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
7343 void*
7344 );
7345
7346 /*
7347 ** CAPI3REF: Configure an auto-checkpoint
7348 ** METHOD: sqlite3
7349 **
7350 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7351 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7352 ** to automatically [checkpoint]
7353 ** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
7374 */
7375 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7376
7377 /*
7378 ** CAPI3REF: Checkpoint a database
7379 ** METHOD: sqlite3
7380 **
7381 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7382 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7383 **
7384 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
7396 */
7397 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7398
7399 /*
7400 ** CAPI3REF: Checkpoint a database
7401 ** METHOD: sqlite3
7402 **
7403 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7404 ** operation on database X of [database connection] D in mode M. Status
7405 ** information is written back into integers pointed to by L and C.)^
7406 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
7651 #define SQLITE_SCANSTAT_EXPLAIN 4
7652 #define SQLITE_SCANSTAT_SELECTID 5
7653
7654 /*
7655 ** CAPI3REF: Prepared Statement Scan Status
7656 ** METHOD: sqlite3_stmt
7657 **
7658 ** This interface returns information about the predicted and measured
7659 ** performance for pStmt. Advanced applications can use this
7660 ** interface to compare the predicted and the measured performance and
7661 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
7689 void *pOut /* Result written here */
7690 );
7691
7692 /*
7693 ** CAPI3REF: Zero Scan-Status Counters
7694 ** METHOD: sqlite3_stmt
7695 **
7696 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7697 **
7698 ** This API is only available if the library is built with pre-processor
7699 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7700
+11 -5
--- src/timeline.c
+++ src/timeline.c
@@ -499,11 +499,11 @@
499499
&& zType[0]=='c' && g.perm.Hyperlink
500500
){
501501
int inUl = 0;
502502
if( !fchngQueryInit ){
503503
db_prepare(&fchngQuery,
504
- "SELECT (pid==0) AS isnew,"
504
+ "SELECT pid,"
505505
" fid,"
506506
" (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
507507
" (SELECT uuid FROM blob WHERE rid=fid),"
508508
" (SELECT uuid FROM blob WHERE rid=pid),"
509509
" (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
@@ -517,11 +517,12 @@
517517
fchngQueryInit = 1;
518518
}
519519
db_bind_int(&fchngQuery, ":mid", rid);
520520
while( db_step(&fchngQuery)==SQLITE_ROW ){
521521
const char *zFilename = db_column_text(&fchngQuery, 2);
522
- int isNew = db_column_int(&fchngQuery, 0);
522
+ int isNew = db_column_int(&fchngQuery, 0)<=0;
523
+ int isMergeNew = db_column_int(&fchngQuery, 0)<0;
523524
int fid = db_column_int(&fchngQuery, 1);
524525
int isDel = fid==0;
525526
const char *zOldName = db_column_text(&fchngQuery, 5);
526527
const char *zOld = db_column_text(&fchngQuery, 4);
527528
const char *zNew = db_column_text(&fchngQuery, 3);
@@ -546,12 +547,17 @@
546547
zA = href("%R/artifact/%!S",fid?zNew:zOld);
547548
if( content_is_private(fid) ){
548549
zUnpub = UNPUB_TAG;
549550
}
550551
if( isNew ){
551
- @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub) (new file) &nbsp;
552
- @ %z(href("%R/artifact/%!S",zNew))[view]</a></li>
552
+ @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub)
553
+ if( isMergeNew ){
554
+ @ (added by merge)
555
+ }else{
556
+ @ (new file)
557
+ }
558
+ @ &nbsp; %z(href("%R/artifact/%!S",zNew))[view]</a></li>
553559
}else if( isDel ){
554560
@ <li> %s(zA)%h(zFilename)</a> (deleted)</li>
555561
}else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
556562
@ <li> %h(zOldName) &rarr; %s(zA)%h(zFilename)</a>%s(zId)
557563
@ %s(zUnpub) %z(href("%R/artifact/%!S",zNew))[view]</a></li>
@@ -1873,11 +1879,11 @@
18731879
fossil_free(zFree);
18741880
18751881
if(verboseFlag){
18761882
if( !fchngQueryInit ){
18771883
db_prepare(&fchngQuery,
1878
- "SELECT (pid==0) AS isnew,"
1884
+ "SELECT (pid<=0) AS isnew,"
18791885
" (fid==0) AS isdel,"
18801886
" (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
18811887
" (SELECT uuid FROM blob WHERE rid=fid),"
18821888
" (SELECT uuid FROM blob WHERE rid=pid)"
18831889
" FROM mlink"
18841890
--- src/timeline.c
+++ src/timeline.c
@@ -499,11 +499,11 @@
499 && zType[0]=='c' && g.perm.Hyperlink
500 ){
501 int inUl = 0;
502 if( !fchngQueryInit ){
503 db_prepare(&fchngQuery,
504 "SELECT (pid==0) AS isnew,"
505 " fid,"
506 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
507 " (SELECT uuid FROM blob WHERE rid=fid),"
508 " (SELECT uuid FROM blob WHERE rid=pid),"
509 " (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
@@ -517,11 +517,12 @@
517 fchngQueryInit = 1;
518 }
519 db_bind_int(&fchngQuery, ":mid", rid);
520 while( db_step(&fchngQuery)==SQLITE_ROW ){
521 const char *zFilename = db_column_text(&fchngQuery, 2);
522 int isNew = db_column_int(&fchngQuery, 0);
 
523 int fid = db_column_int(&fchngQuery, 1);
524 int isDel = fid==0;
525 const char *zOldName = db_column_text(&fchngQuery, 5);
526 const char *zOld = db_column_text(&fchngQuery, 4);
527 const char *zNew = db_column_text(&fchngQuery, 3);
@@ -546,12 +547,17 @@
546 zA = href("%R/artifact/%!S",fid?zNew:zOld);
547 if( content_is_private(fid) ){
548 zUnpub = UNPUB_TAG;
549 }
550 if( isNew ){
551 @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub) (new file) &nbsp;
552 @ %z(href("%R/artifact/%!S",zNew))[view]</a></li>
 
 
 
 
 
553 }else if( isDel ){
554 @ <li> %s(zA)%h(zFilename)</a> (deleted)</li>
555 }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
556 @ <li> %h(zOldName) &rarr; %s(zA)%h(zFilename)</a>%s(zId)
557 @ %s(zUnpub) %z(href("%R/artifact/%!S",zNew))[view]</a></li>
@@ -1873,11 +1879,11 @@
1873 fossil_free(zFree);
1874
1875 if(verboseFlag){
1876 if( !fchngQueryInit ){
1877 db_prepare(&fchngQuery,
1878 "SELECT (pid==0) AS isnew,"
1879 " (fid==0) AS isdel,"
1880 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
1881 " (SELECT uuid FROM blob WHERE rid=fid),"
1882 " (SELECT uuid FROM blob WHERE rid=pid)"
1883 " FROM mlink"
1884
--- src/timeline.c
+++ src/timeline.c
@@ -499,11 +499,11 @@
499 && zType[0]=='c' && g.perm.Hyperlink
500 ){
501 int inUl = 0;
502 if( !fchngQueryInit ){
503 db_prepare(&fchngQuery,
504 "SELECT pid,"
505 " fid,"
506 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
507 " (SELECT uuid FROM blob WHERE rid=fid),"
508 " (SELECT uuid FROM blob WHERE rid=pid),"
509 " (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
@@ -517,11 +517,12 @@
517 fchngQueryInit = 1;
518 }
519 db_bind_int(&fchngQuery, ":mid", rid);
520 while( db_step(&fchngQuery)==SQLITE_ROW ){
521 const char *zFilename = db_column_text(&fchngQuery, 2);
522 int isNew = db_column_int(&fchngQuery, 0)<=0;
523 int isMergeNew = db_column_int(&fchngQuery, 0)<0;
524 int fid = db_column_int(&fchngQuery, 1);
525 int isDel = fid==0;
526 const char *zOldName = db_column_text(&fchngQuery, 5);
527 const char *zOld = db_column_text(&fchngQuery, 4);
528 const char *zNew = db_column_text(&fchngQuery, 3);
@@ -546,12 +547,17 @@
547 zA = href("%R/artifact/%!S",fid?zNew:zOld);
548 if( content_is_private(fid) ){
549 zUnpub = UNPUB_TAG;
550 }
551 if( isNew ){
552 @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub)
553 if( isMergeNew ){
554 @ (added by merge)
555 }else{
556 @ (new file)
557 }
558 @ &nbsp; %z(href("%R/artifact/%!S",zNew))[view]</a></li>
559 }else if( isDel ){
560 @ <li> %s(zA)%h(zFilename)</a> (deleted)</li>
561 }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
562 @ <li> %h(zOldName) &rarr; %s(zA)%h(zFilename)</a>%s(zId)
563 @ %s(zUnpub) %z(href("%R/artifact/%!S",zNew))[view]</a></li>
@@ -1873,11 +1879,11 @@
1879 fossil_free(zFree);
1880
1881 if(verboseFlag){
1882 if( !fchngQueryInit ){
1883 db_prepare(&fchngQuery,
1884 "SELECT (pid<=0) AS isnew,"
1885 " (fid==0) AS isdel,"
1886 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
1887 " (SELECT uuid FROM blob WHERE rid=fid),"
1888 " (SELECT uuid FROM blob WHERE rid=pid)"
1889 " FROM mlink"
1890
+1 -1
--- src/update.c
+++ src/update.c
@@ -650,11 +650,11 @@
650650
const char *file, /* Full treename of the file */
651651
Blob *content, /* Put the content here */
652652
int *pIsLink, /* Set to true if file is link. */
653653
int *pIsExe, /* Set to true if file is executable */
654654
int *pIsBin, /* Set to true if file is binary */
655
- int errCode /* Error code if file not found. Panic if 0. */
655
+ int errCode /* Error code if file not found. Panic if <= 0. */
656656
){
657657
Manifest *pManifest;
658658
ManifestFile *pFile;
659659
int rid=0;
660660
661661
--- src/update.c
+++ src/update.c
@@ -650,11 +650,11 @@
650 const char *file, /* Full treename of the file */
651 Blob *content, /* Put the content here */
652 int *pIsLink, /* Set to true if file is link. */
653 int *pIsExe, /* Set to true if file is executable */
654 int *pIsBin, /* Set to true if file is binary */
655 int errCode /* Error code if file not found. Panic if 0. */
656 ){
657 Manifest *pManifest;
658 ManifestFile *pFile;
659 int rid=0;
660
661
--- src/update.c
+++ src/update.c
@@ -650,11 +650,11 @@
650 const char *file, /* Full treename of the file */
651 Blob *content, /* Put the content here */
652 int *pIsLink, /* Set to true if file is link. */
653 int *pIsExe, /* Set to true if file is executable */
654 int *pIsBin, /* Set to true if file is binary */
655 int errCode /* Error code if file not found. Panic if <= 0. */
656 ){
657 Manifest *pManifest;
658 ManifestFile *pFile;
659 int rid=0;
660
661
+4 -7
--- src/vfile.c
+++ src/vfile.c
@@ -546,12 +546,11 @@
546546
int vfile_dir_scan(
547547
Blob *pPath, /* Base directory to be scanned */
548548
int nPrefix, /* Number of bytes in base directory name */
549549
unsigned scanFlags, /* Zero or more SCAN_xxx flags */
550550
Glob *pIgnore1, /* Do not add directories that match this GLOB */
551
- Glob *pIgnore2, /* Omit directories matching this GLOB too */
552
- Glob *pIgnore3 /* Omit directories matching this GLOB too */
551
+ Glob *pIgnore2 /* Omit directories matching this GLOB too */
553552
){
554553
int result = 0;
555554
DIR *d;
556555
int origSize;
557556
struct dirent *pEntry;
@@ -560,15 +559,14 @@
560559
static Stmt upd;
561560
static int depth = 0;
562561
void *zNative;
563562
564563
origSize = blob_size(pPath);
565
- if( pIgnore1 || pIgnore2 || pIgnore3 ){
564
+ if( pIgnore1 || pIgnore2 ){
566565
blob_appendf(pPath, "/");
567566
if( glob_match(pIgnore1, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
568567
if( glob_match(pIgnore2, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
569
- if( glob_match(pIgnore3, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
570568
blob_resize(pPath, origSize);
571569
}
572570
if( skipAll ) return result;
573571
574572
if( depth==0 ){
@@ -604,12 +602,11 @@
604602
zOrigPath = mprintf("%s", blob_str(pPath));
605603
zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
606604
blob_appendf(pPath, "/%s", zUtf8);
607605
zPath = blob_str(pPath);
608606
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
609
- glob_match(pIgnore2, &zPath[nPrefix+1]) ||
610
- glob_match(pIgnore3, &zPath[nPrefix+1]) ){
607
+ glob_match(pIgnore2, &zPath[nPrefix+1]) ){
611608
/* do nothing */
612609
#ifdef _DIRENT_HAVE_D_TYPE
613610
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
614611
? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
615612
#else
@@ -616,11 +613,11 @@
616613
}else if( file_wd_isdir(zPath)==1 ){
617614
#endif
618615
if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
619616
char *zSavePath = mprintf("%s", zPath);
620617
int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
621
- pIgnore2, pIgnore3);
618
+ pIgnore2);
622619
db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
623620
db_bind_int(&ins, ":count", count);
624621
db_step(&ins);
625622
db_reset(&ins);
626623
fossil_free(zSavePath);
627624
--- src/vfile.c
+++ src/vfile.c
@@ -546,12 +546,11 @@
546 int vfile_dir_scan(
547 Blob *pPath, /* Base directory to be scanned */
548 int nPrefix, /* Number of bytes in base directory name */
549 unsigned scanFlags, /* Zero or more SCAN_xxx flags */
550 Glob *pIgnore1, /* Do not add directories that match this GLOB */
551 Glob *pIgnore2, /* Omit directories matching this GLOB too */
552 Glob *pIgnore3 /* Omit directories matching this GLOB too */
553 ){
554 int result = 0;
555 DIR *d;
556 int origSize;
557 struct dirent *pEntry;
@@ -560,15 +559,14 @@
560 static Stmt upd;
561 static int depth = 0;
562 void *zNative;
563
564 origSize = blob_size(pPath);
565 if( pIgnore1 || pIgnore2 || pIgnore3 ){
566 blob_appendf(pPath, "/");
567 if( glob_match(pIgnore1, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
568 if( glob_match(pIgnore2, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
569 if( glob_match(pIgnore3, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
570 blob_resize(pPath, origSize);
571 }
572 if( skipAll ) return result;
573
574 if( depth==0 ){
@@ -604,12 +602,11 @@
604 zOrigPath = mprintf("%s", blob_str(pPath));
605 zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
606 blob_appendf(pPath, "/%s", zUtf8);
607 zPath = blob_str(pPath);
608 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
609 glob_match(pIgnore2, &zPath[nPrefix+1]) ||
610 glob_match(pIgnore3, &zPath[nPrefix+1]) ){
611 /* do nothing */
612 #ifdef _DIRENT_HAVE_D_TYPE
613 }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
614 ? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
615 #else
@@ -616,11 +613,11 @@
616 }else if( file_wd_isdir(zPath)==1 ){
617 #endif
618 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
619 char *zSavePath = mprintf("%s", zPath);
620 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
621 pIgnore2, pIgnore3);
622 db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
623 db_bind_int(&ins, ":count", count);
624 db_step(&ins);
625 db_reset(&ins);
626 fossil_free(zSavePath);
627
--- src/vfile.c
+++ src/vfile.c
@@ -546,12 +546,11 @@
546 int vfile_dir_scan(
547 Blob *pPath, /* Base directory to be scanned */
548 int nPrefix, /* Number of bytes in base directory name */
549 unsigned scanFlags, /* Zero or more SCAN_xxx flags */
550 Glob *pIgnore1, /* Do not add directories that match this GLOB */
551 Glob *pIgnore2 /* Omit directories matching this GLOB too */
 
552 ){
553 int result = 0;
554 DIR *d;
555 int origSize;
556 struct dirent *pEntry;
@@ -560,15 +559,14 @@
559 static Stmt upd;
560 static int depth = 0;
561 void *zNative;
562
563 origSize = blob_size(pPath);
564 if( pIgnore1 || pIgnore2 ){
565 blob_appendf(pPath, "/");
566 if( glob_match(pIgnore1, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
567 if( glob_match(pIgnore2, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
 
568 blob_resize(pPath, origSize);
569 }
570 if( skipAll ) return result;
571
572 if( depth==0 ){
@@ -604,12 +602,11 @@
602 zOrigPath = mprintf("%s", blob_str(pPath));
603 zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
604 blob_appendf(pPath, "/%s", zUtf8);
605 zPath = blob_str(pPath);
606 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
607 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
 
608 /* do nothing */
609 #ifdef _DIRENT_HAVE_D_TYPE
610 }else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
611 ? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
612 #else
@@ -616,11 +613,11 @@
613 }else if( file_wd_isdir(zPath)==1 ){
614 #endif
615 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
616 char *zSavePath = mprintf("%s", zPath);
617 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
618 pIgnore2);
619 db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
620 db_bind_int(&ins, ":count", count);
621 db_step(&ins);
622 db_reset(&ins);
623 fossil_free(zSavePath);
624
--- test/release-checklist.wiki
+++ test/release-checklist.wiki
@@ -3,11 +3,11 @@
33
This file describes the testing procedures for Fossil prior to an
44
official release.
55
66
<ol>
77
<li><p>
8
-From a private directory (not the source tree) run
8
+From a private directory (not the source tree) run
99
"<b>tclsh $SRC/test/tester.tcl $FOSSIL</b>" where $FOSSIL is the
1010
name of the executable under test and $SRC is the source tree.
1111
Verify that there are no errors.
1212
1313
<li><p>
1414
--- test/release-checklist.wiki
+++ test/release-checklist.wiki
@@ -3,11 +3,11 @@
3 This file describes the testing procedures for Fossil prior to an
4 official release.
5
6 <ol>
7 <li><p>
8 From a private directory (not the source tree) run
9 "<b>tclsh $SRC/test/tester.tcl $FOSSIL</b>" where $FOSSIL is the
10 name of the executable under test and $SRC is the source tree.
11 Verify that there are no errors.
12
13 <li><p>
14
--- test/release-checklist.wiki
+++ test/release-checklist.wiki
@@ -3,11 +3,11 @@
3 This file describes the testing procedures for Fossil prior to an
4 official release.
5
6 <ol>
7 <li><p>
8 From a private directory (not the source tree) run
9 "<b>tclsh $SRC/test/tester.tcl $FOSSIL</b>" where $FOSSIL is the
10 name of the executable under test and $SRC is the source tree.
11 Verify that there are no errors.
12
13 <li><p>
14
+2 -2
--- test/th1.test
+++ test/th1.test
@@ -42,16 +42,16 @@
4242
test th1-setting-4 {$RESULT eq {TH_ERROR: no value for setting "abc"}}
4343
4444
###############################################################################
4545
4646
fossil test-th-eval --open-config "setting autosync"
47
-test th1-setting-5 {$RESULT eq 0 || $RESULT eq 1}
47
+test th1-setting-5 {$RESULT eq 0 || $RESULT eq 1 || $RESULT eq "on"}
4848
4949
###############################################################################
5050
5151
fossil test-th-eval --open-config "setting -strict autosync"
52
-test th1-setting-6 {$RESULT eq 0 || $RESULT eq 1}
52
+test th1-setting-6 {$RESULT eq 0 || $RESULT eq 1 || $RESULT eq "on"}
5353
5454
###############################################################################
5555
5656
fossil test-th-eval --open-config "setting --"
5757
test th1-setting-7 {$RESULT eq \
5858
--- test/th1.test
+++ test/th1.test
@@ -42,16 +42,16 @@
42 test th1-setting-4 {$RESULT eq {TH_ERROR: no value for setting "abc"}}
43
44 ###############################################################################
45
46 fossil test-th-eval --open-config "setting autosync"
47 test th1-setting-5 {$RESULT eq 0 || $RESULT eq 1}
48
49 ###############################################################################
50
51 fossil test-th-eval --open-config "setting -strict autosync"
52 test th1-setting-6 {$RESULT eq 0 || $RESULT eq 1}
53
54 ###############################################################################
55
56 fossil test-th-eval --open-config "setting --"
57 test th1-setting-7 {$RESULT eq \
58
--- test/th1.test
+++ test/th1.test
@@ -42,16 +42,16 @@
42 test th1-setting-4 {$RESULT eq {TH_ERROR: no value for setting "abc"}}
43
44 ###############################################################################
45
46 fossil test-th-eval --open-config "setting autosync"
47 test th1-setting-5 {$RESULT eq 0 || $RESULT eq 1 || $RESULT eq "on"}
48
49 ###############################################################################
50
51 fossil test-th-eval --open-config "setting -strict autosync"
52 test th1-setting-6 {$RESULT eq 0 || $RESULT eq 1 || $RESULT eq "on"}
53
54 ###############################################################################
55
56 fossil test-th-eval --open-config "setting --"
57 test th1-setting-7 {$RESULT eq \
58

Keyboard Shortcuts

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