Fossil SCM

merge trunk

jan.nijtmans 2015-08-21 09:15 cleanX merge
Commit 0ab66b742c58672d9d44c81a94614deea7339339
--- a/.fossil-settings/clean-glob
+++ b/.fossil-settings/clean-glob
@@ -0,0 +1,14 @@
1
+*.a
2
+*.lib
3
+*.manifest
4
+*.o
5
+bld/*
6
+w.a
7
+*.lib
8
+*.manifest
9
+*.o
10
+*.obj
11
+*.pdb
12
+*.res
13
+Makefile
14
+aut
--- a/.fossil-settings/clean-glob
+++ b/.fossil-settings/clean-glob
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/.fossil-settings/clean-glob
+++ b/.fossil-settings/clean-glob
@@ -0,0 +1,14 @@
1 *.a
2 *.lib
3 *.manifest
4 *.o
5 bld/*
6 w.a
7 *.lib
8 *.manifest
9 *.o
10 *.obj
11 *.pdb
12 *.res
13 Makefile
14 aut

No diff available

--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,22 +1,5 @@
11
compat/openssl*
22
compat/tcl*
3
-*.a
4
-*.lib
5
-*.manifest
6
-*.o
7
-*.obj
8
-*.pdb
9
-*.res
10
-Makefile
11
-bld/*
12
-wbld/*
13
-win/*.c
14
-win/*.h
15
-win/*.exe
16
-win/headers
17
-win/linkopts
18
-autoconfig.h
19
-config.log
203
fossil
214
fossil.exe
225
win/fossil.exe
236
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,22 +1,5 @@
1 compat/openssl*
2 compat/tcl*
3 *.a
4 *.lib
5 *.manifest
6 *.o
7 *.obj
8 *.pdb
9 *.res
10 Makefile
11 bld/*
12 wbld/*
13 win/*.c
14 win/*.h
15 win/*.exe
16 win/headers
17 win/linkopts
18 autoconfig.h
19 config.log
20 fossil
21 fossil.exe
22 win/fossil.exe
23
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,22 +1,5 @@
1 compat/openssl*
2 compat/tcl*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3 fossil
4 fossil.exe
5 win/fossil.exe
6
+1
--- src/blob.c
+++ src/blob.c
@@ -271,10 +271,11 @@
271271
272272
/*
273273
** Append text or data to the end of a blob.
274274
*/
275275
void blob_append(Blob *pBlob, const char *aData, int nData){
276
+ assert( aData!=0 || nData==0 );
276277
blob_is_init(pBlob);
277278
if( nData<0 ) nData = strlen(aData);
278279
if( nData==0 ) return;
279280
if( pBlob->nUsed + nData >= pBlob->nAlloc ){
280281
pBlob->xRealloc(pBlob, pBlob->nUsed + nData + pBlob->nAlloc + 100);
281282
--- src/blob.c
+++ src/blob.c
@@ -271,10 +271,11 @@
271
272 /*
273 ** Append text or data to the end of a blob.
274 */
275 void blob_append(Blob *pBlob, const char *aData, int nData){
 
276 blob_is_init(pBlob);
277 if( nData<0 ) nData = strlen(aData);
278 if( nData==0 ) return;
279 if( pBlob->nUsed + nData >= pBlob->nAlloc ){
280 pBlob->xRealloc(pBlob, pBlob->nUsed + nData + pBlob->nAlloc + 100);
281
--- src/blob.c
+++ src/blob.c
@@ -271,10 +271,11 @@
271
272 /*
273 ** Append text or data to the end of a blob.
274 */
275 void blob_append(Blob *pBlob, const char *aData, int nData){
276 assert( aData!=0 || nData==0 );
277 blob_is_init(pBlob);
278 if( nData<0 ) nData = strlen(aData);
279 if( nData==0 ) return;
280 if( pBlob->nUsed + nData >= pBlob->nAlloc ){
281 pBlob->xRealloc(pBlob, pBlob->nUsed + nData + pBlob->nAlloc + 100);
282
+1 -1
--- src/cgi.c
+++ src/cgi.c
@@ -1050,11 +1050,11 @@
10501050
10511051
/* If no match is found and the name begins with an upper-case
10521052
** letter, then check to see if there is an environment variable
10531053
** with the given name.
10541054
*/
1055
- if( fossil_isupper(zName[0]) ){
1055
+ if( zName && fossil_isupper(zName[0]) ){
10561056
const char *zValue = fossil_getenv(zName);
10571057
if( zValue ){
10581058
cgi_set_parameter_nocopy(zName, zValue, 0);
10591059
CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
10601060
return zValue;
10611061
--- src/cgi.c
+++ src/cgi.c
@@ -1050,11 +1050,11 @@
1050
1051 /* If no match is found and the name begins with an upper-case
1052 ** letter, then check to see if there is an environment variable
1053 ** with the given name.
1054 */
1055 if( fossil_isupper(zName[0]) ){
1056 const char *zValue = fossil_getenv(zName);
1057 if( zValue ){
1058 cgi_set_parameter_nocopy(zName, zValue, 0);
1059 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
1060 return zValue;
1061
--- src/cgi.c
+++ src/cgi.c
@@ -1050,11 +1050,11 @@
1050
1051 /* If no match is found and the name begins with an upper-case
1052 ** letter, then check to see if there is an environment variable
1053 ** with the given name.
1054 */
1055 if( zName && fossil_isupper(zName[0]) ){
1056 const char *zValue = fossil_getenv(zName);
1057 if( zValue ){
1058 cgi_set_parameter_nocopy(zName, zValue, 0);
1059 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
1060 return zValue;
1061
+12 -10
--- src/checkin.c
+++ src/checkin.c
@@ -642,14 +642,14 @@
642642
** values for --clean, --ignore, and --keep are determined by the
643643
** (versionable) clean-glob, ignore-glob, and keep-glob settings.
644644
** Files and subdirectories whose names begin with "." are automatically
645645
** ignored unless the --dotfiles option is used.
646646
**
647
-** The --verily option ignores the ignore-glob setting and turns on
648
-**--dotfiles, and --emptydirs. Use the --verily option when you
649
-** really want to clean up everything. Extreme care should be
650
-** exercised when using the --verily option.
647
+** The --verily option ignores the keep-glob and ignore-glob settings
648
+** and turns on --dotfiles, and --emptydirs. Use the --verily
649
+** option when you really want to clean up everything. Extreme care
650
+** should be exercised when using the --verily option.
651651
**
652652
** Options:
653653
** --allckouts Check for empty directories within any checkouts
654654
** that may be nested within the current one. This
655655
** option should be used with great care because the
@@ -672,13 +672,14 @@
672672
** therefore, directories that contain only files
673673
** that were removed will be removed as well.
674674
** -f|--force Remove files without prompting.
675675
** -x|--verily WARNING: Removes everything that is not a managed
676676
** file or the repository itself. This option
677
-** implies the -emptydirs and --dotfiles options.
678
-** Furthermore, it completely disregards the ignore-glob.
679
-** setting. However, it does honor the --ignore and --keep
677
+** implies the --emptydirs, --dotfiles, and
678
+** --disable-undo options. Furthermore, it completely
679
+** disregards the keep-glob and ignore-glob settings.
680
+** However, it does honor the --ignore and --keep
680681
** options.
681682
** --clean <CSG> WARNING: Never prompt to delete any files matching
682683
** this comma separated list of glob patterns. Also,
683684
** deletions of any files matching this pattern list
684685
** cannot be undone.
@@ -731,17 +732,18 @@
731732
zCleanFlag = find_option("clean",0,1);
732733
db_must_be_within_tree();
733734
if( find_option("verily","x",0)!=0 ){
734735
verilyFlag = 1;
735736
emptyDirsFlag = 1;
737
+ disableUndo = 1;
736738
scanFlags |= SCAN_ALL;
737739
zCleanFlag = 0;
738740
}
739741
if( zIgnoreFlag==0 ){
740742
zIgnoreFlag = db_get("ignore-glob", 0);
741743
}
742
- if( zKeepFlag==0 ){
744
+ if( zKeepFlag==0 && !verilyFlag ){
743745
zKeepFlag = db_get("keep-glob", 0);
744746
}
745747
if( zCleanFlag==0 && !verilyFlag ){
746748
zCleanFlag = db_get("clean-glob", 0);
747749
}
@@ -769,11 +771,11 @@
769771
}
770772
db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
771773
while( db_step(&q)==SQLITE_ROW ){
772774
const char *zName = db_column_text(&q, 0);
773775
if( glob_match(pKeep, zName+nRoot) ){
774
- if( verboseFlag || verilyFlag ){
776
+ if( verboseFlag ){
775777
fossil_print("KEPT file \"%s\" not removed (due to --keep"
776778
" or \"keep-glob\")\n", zName+nRoot);
777779
}
778780
continue;
779781
}
@@ -833,11 +835,11 @@
833835
g.zLocalRoot, fossil_all_reserved_names(0)
834836
);
835837
while( db_step(&q)==SQLITE_ROW ){
836838
const char *zName = db_column_text(&q, 0);
837839
if( glob_match(pKeep, zName+nRoot) ){
838
- if( verboseFlag || verilyFlag ){
840
+ if( verboseFlag ){
839841
fossil_print("KEPT directory \"%s\" not removed (due to --keep"
840842
" or \"keep-glob\")\n", zName+nRoot);
841843
}
842844
continue;
843845
}
844846
--- src/checkin.c
+++ src/checkin.c
@@ -642,14 +642,14 @@
642 ** values for --clean, --ignore, and --keep are determined by the
643 ** (versionable) clean-glob, ignore-glob, and keep-glob settings.
644 ** Files and subdirectories whose names begin with "." are automatically
645 ** ignored unless the --dotfiles option is used.
646 **
647 ** The --verily option ignores the ignore-glob setting and turns on
648 **--dotfiles, and --emptydirs. Use the --verily option when you
649 ** really want to clean up everything. Extreme care should be
650 ** exercised when using the --verily option.
651 **
652 ** Options:
653 ** --allckouts Check for empty directories within any checkouts
654 ** that may be nested within the current one. This
655 ** option should be used with great care because the
@@ -672,13 +672,14 @@
672 ** therefore, directories that contain only files
673 ** that were removed will be removed as well.
674 ** -f|--force Remove files without prompting.
675 ** -x|--verily WARNING: Removes everything that is not a managed
676 ** file or the repository itself. This option
677 ** implies the -emptydirs and --dotfiles options.
678 ** Furthermore, it completely disregards the ignore-glob.
679 ** setting. However, it does honor the --ignore and --keep
 
680 ** options.
681 ** --clean <CSG> WARNING: Never prompt to delete any files matching
682 ** this comma separated list of glob patterns. Also,
683 ** deletions of any files matching this pattern list
684 ** cannot be undone.
@@ -731,17 +732,18 @@
731 zCleanFlag = find_option("clean",0,1);
732 db_must_be_within_tree();
733 if( find_option("verily","x",0)!=0 ){
734 verilyFlag = 1;
735 emptyDirsFlag = 1;
 
736 scanFlags |= SCAN_ALL;
737 zCleanFlag = 0;
738 }
739 if( zIgnoreFlag==0 ){
740 zIgnoreFlag = db_get("ignore-glob", 0);
741 }
742 if( zKeepFlag==0 ){
743 zKeepFlag = db_get("keep-glob", 0);
744 }
745 if( zCleanFlag==0 && !verilyFlag ){
746 zCleanFlag = db_get("clean-glob", 0);
747 }
@@ -769,11 +771,11 @@
769 }
770 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
771 while( db_step(&q)==SQLITE_ROW ){
772 const char *zName = db_column_text(&q, 0);
773 if( glob_match(pKeep, zName+nRoot) ){
774 if( verboseFlag || verilyFlag ){
775 fossil_print("KEPT file \"%s\" not removed (due to --keep"
776 " or \"keep-glob\")\n", zName+nRoot);
777 }
778 continue;
779 }
@@ -833,11 +835,11 @@
833 g.zLocalRoot, fossil_all_reserved_names(0)
834 );
835 while( db_step(&q)==SQLITE_ROW ){
836 const char *zName = db_column_text(&q, 0);
837 if( glob_match(pKeep, zName+nRoot) ){
838 if( verboseFlag || verilyFlag ){
839 fossil_print("KEPT directory \"%s\" not removed (due to --keep"
840 " or \"keep-glob\")\n", zName+nRoot);
841 }
842 continue;
843 }
844
--- src/checkin.c
+++ src/checkin.c
@@ -642,14 +642,14 @@
642 ** values for --clean, --ignore, and --keep are determined by the
643 ** (versionable) clean-glob, ignore-glob, and keep-glob settings.
644 ** Files and subdirectories whose names begin with "." are automatically
645 ** ignored unless the --dotfiles option is used.
646 **
647 ** The --verily option ignores the keep-glob and ignore-glob settings
648 ** and turns on --dotfiles, and --emptydirs. Use the --verily
649 ** option when you really want to clean up everything. Extreme care
650 ** should be exercised when using the --verily option.
651 **
652 ** Options:
653 ** --allckouts Check for empty directories within any checkouts
654 ** that may be nested within the current one. This
655 ** option should be used with great care because the
@@ -672,13 +672,14 @@
672 ** therefore, directories that contain only files
673 ** that were removed will be removed as well.
674 ** -f|--force Remove files without prompting.
675 ** -x|--verily WARNING: Removes everything that is not a managed
676 ** file or the repository itself. This option
677 ** implies the --emptydirs, --dotfiles, and
678 ** --disable-undo options. Furthermore, it completely
679 ** disregards the keep-glob and ignore-glob settings.
680 ** However, it does honor the --ignore and --keep
681 ** options.
682 ** --clean <CSG> WARNING: Never prompt to delete any files matching
683 ** this comma separated list of glob patterns. Also,
684 ** deletions of any files matching this pattern list
685 ** cannot be undone.
@@ -731,17 +732,18 @@
732 zCleanFlag = find_option("clean",0,1);
733 db_must_be_within_tree();
734 if( find_option("verily","x",0)!=0 ){
735 verilyFlag = 1;
736 emptyDirsFlag = 1;
737 disableUndo = 1;
738 scanFlags |= SCAN_ALL;
739 zCleanFlag = 0;
740 }
741 if( zIgnoreFlag==0 ){
742 zIgnoreFlag = db_get("ignore-glob", 0);
743 }
744 if( zKeepFlag==0 && !verilyFlag ){
745 zKeepFlag = db_get("keep-glob", 0);
746 }
747 if( zCleanFlag==0 && !verilyFlag ){
748 zCleanFlag = db_get("clean-glob", 0);
749 }
@@ -769,11 +771,11 @@
771 }
772 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
773 while( db_step(&q)==SQLITE_ROW ){
774 const char *zName = db_column_text(&q, 0);
775 if( glob_match(pKeep, zName+nRoot) ){
776 if( verboseFlag ){
777 fossil_print("KEPT file \"%s\" not removed (due to --keep"
778 " or \"keep-glob\")\n", zName+nRoot);
779 }
780 continue;
781 }
@@ -833,11 +835,11 @@
835 g.zLocalRoot, fossil_all_reserved_names(0)
836 );
837 while( db_step(&q)==SQLITE_ROW ){
838 const char *zName = db_column_text(&q, 0);
839 if( glob_match(pKeep, zName+nRoot) ){
840 if( verboseFlag ){
841 fossil_print("KEPT directory \"%s\" not removed (due to --keep"
842 " or \"keep-glob\")\n", zName+nRoot);
843 }
844 continue;
845 }
846
+12 -10
--- src/checkin.c
+++ src/checkin.c
@@ -642,14 +642,14 @@
642642
** values for --clean, --ignore, and --keep are determined by the
643643
** (versionable) clean-glob, ignore-glob, and keep-glob settings.
644644
** Files and subdirectories whose names begin with "." are automatically
645645
** ignored unless the --dotfiles option is used.
646646
**
647
-** The --verily option ignores the ignore-glob setting and turns on
648
-**--dotfiles, and --emptydirs. Use the --verily option when you
649
-** really want to clean up everything. Extreme care should be
650
-** exercised when using the --verily option.
647
+** The --verily option ignores the keep-glob and ignore-glob settings
648
+** and turns on --dotfiles, and --emptydirs. Use the --verily
649
+** option when you really want to clean up everything. Extreme care
650
+** should be exercised when using the --verily option.
651651
**
652652
** Options:
653653
** --allckouts Check for empty directories within any checkouts
654654
** that may be nested within the current one. This
655655
** option should be used with great care because the
@@ -672,13 +672,14 @@
672672
** therefore, directories that contain only files
673673
** that were removed will be removed as well.
674674
** -f|--force Remove files without prompting.
675675
** -x|--verily WARNING: Removes everything that is not a managed
676676
** file or the repository itself. This option
677
-** implies the -emptydirs and --dotfiles options.
678
-** Furthermore, it completely disregards the ignore-glob.
679
-** setting. However, it does honor the --ignore and --keep
677
+** implies the --emptydirs, --dotfiles, and
678
+** --disable-undo options. Furthermore, it completely
679
+** disregards the keep-glob and ignore-glob settings.
680
+** However, it does honor the --ignore and --keep
680681
** options.
681682
** --clean <CSG> WARNING: Never prompt to delete any files matching
682683
** this comma separated list of glob patterns. Also,
683684
** deletions of any files matching this pattern list
684685
** cannot be undone.
@@ -731,17 +732,18 @@
731732
zCleanFlag = find_option("clean",0,1);
732733
db_must_be_within_tree();
733734
if( find_option("verily","x",0)!=0 ){
734735
verilyFlag = 1;
735736
emptyDirsFlag = 1;
737
+ disableUndo = 1;
736738
scanFlags |= SCAN_ALL;
737739
zCleanFlag = 0;
738740
}
739741
if( zIgnoreFlag==0 ){
740742
zIgnoreFlag = db_get("ignore-glob", 0);
741743
}
742
- if( zKeepFlag==0 ){
744
+ if( zKeepFlag==0 && !verilyFlag ){
743745
zKeepFlag = db_get("keep-glob", 0);
744746
}
745747
if( zCleanFlag==0 && !verilyFlag ){
746748
zCleanFlag = db_get("clean-glob", 0);
747749
}
@@ -769,11 +771,11 @@
769771
}
770772
db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
771773
while( db_step(&q)==SQLITE_ROW ){
772774
const char *zName = db_column_text(&q, 0);
773775
if( glob_match(pKeep, zName+nRoot) ){
774
- if( verboseFlag || verilyFlag ){
776
+ if( verboseFlag ){
775777
fossil_print("KEPT file \"%s\" not removed (due to --keep"
776778
" or \"keep-glob\")\n", zName+nRoot);
777779
}
778780
continue;
779781
}
@@ -833,11 +835,11 @@
833835
g.zLocalRoot, fossil_all_reserved_names(0)
834836
);
835837
while( db_step(&q)==SQLITE_ROW ){
836838
const char *zName = db_column_text(&q, 0);
837839
if( glob_match(pKeep, zName+nRoot) ){
838
- if( verboseFlag || verilyFlag ){
840
+ if( verboseFlag ){
839841
fossil_print("KEPT directory \"%s\" not removed (due to --keep"
840842
" or \"keep-glob\")\n", zName+nRoot);
841843
}
842844
continue;
843845
}
844846
--- src/checkin.c
+++ src/checkin.c
@@ -642,14 +642,14 @@
642 ** values for --clean, --ignore, and --keep are determined by the
643 ** (versionable) clean-glob, ignore-glob, and keep-glob settings.
644 ** Files and subdirectories whose names begin with "." are automatically
645 ** ignored unless the --dotfiles option is used.
646 **
647 ** The --verily option ignores the ignore-glob setting and turns on
648 **--dotfiles, and --emptydirs. Use the --verily option when you
649 ** really want to clean up everything. Extreme care should be
650 ** exercised when using the --verily option.
651 **
652 ** Options:
653 ** --allckouts Check for empty directories within any checkouts
654 ** that may be nested within the current one. This
655 ** option should be used with great care because the
@@ -672,13 +672,14 @@
672 ** therefore, directories that contain only files
673 ** that were removed will be removed as well.
674 ** -f|--force Remove files without prompting.
675 ** -x|--verily WARNING: Removes everything that is not a managed
676 ** file or the repository itself. This option
677 ** implies the -emptydirs and --dotfiles options.
678 ** Furthermore, it completely disregards the ignore-glob.
679 ** setting. However, it does honor the --ignore and --keep
 
680 ** options.
681 ** --clean <CSG> WARNING: Never prompt to delete any files matching
682 ** this comma separated list of glob patterns. Also,
683 ** deletions of any files matching this pattern list
684 ** cannot be undone.
@@ -731,17 +732,18 @@
731 zCleanFlag = find_option("clean",0,1);
732 db_must_be_within_tree();
733 if( find_option("verily","x",0)!=0 ){
734 verilyFlag = 1;
735 emptyDirsFlag = 1;
 
736 scanFlags |= SCAN_ALL;
737 zCleanFlag = 0;
738 }
739 if( zIgnoreFlag==0 ){
740 zIgnoreFlag = db_get("ignore-glob", 0);
741 }
742 if( zKeepFlag==0 ){
743 zKeepFlag = db_get("keep-glob", 0);
744 }
745 if( zCleanFlag==0 && !verilyFlag ){
746 zCleanFlag = db_get("clean-glob", 0);
747 }
@@ -769,11 +771,11 @@
769 }
770 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
771 while( db_step(&q)==SQLITE_ROW ){
772 const char *zName = db_column_text(&q, 0);
773 if( glob_match(pKeep, zName+nRoot) ){
774 if( verboseFlag || verilyFlag ){
775 fossil_print("KEPT file \"%s\" not removed (due to --keep"
776 " or \"keep-glob\")\n", zName+nRoot);
777 }
778 continue;
779 }
@@ -833,11 +835,11 @@
833 g.zLocalRoot, fossil_all_reserved_names(0)
834 );
835 while( db_step(&q)==SQLITE_ROW ){
836 const char *zName = db_column_text(&q, 0);
837 if( glob_match(pKeep, zName+nRoot) ){
838 if( verboseFlag || verilyFlag ){
839 fossil_print("KEPT directory \"%s\" not removed (due to --keep"
840 " or \"keep-glob\")\n", zName+nRoot);
841 }
842 continue;
843 }
844
--- src/checkin.c
+++ src/checkin.c
@@ -642,14 +642,14 @@
642 ** values for --clean, --ignore, and --keep are determined by the
643 ** (versionable) clean-glob, ignore-glob, and keep-glob settings.
644 ** Files and subdirectories whose names begin with "." are automatically
645 ** ignored unless the --dotfiles option is used.
646 **
647 ** The --verily option ignores the keep-glob and ignore-glob settings
648 ** and turns on --dotfiles, and --emptydirs. Use the --verily
649 ** option when you really want to clean up everything. Extreme care
650 ** should be exercised when using the --verily option.
651 **
652 ** Options:
653 ** --allckouts Check for empty directories within any checkouts
654 ** that may be nested within the current one. This
655 ** option should be used with great care because the
@@ -672,13 +672,14 @@
672 ** therefore, directories that contain only files
673 ** that were removed will be removed as well.
674 ** -f|--force Remove files without prompting.
675 ** -x|--verily WARNING: Removes everything that is not a managed
676 ** file or the repository itself. This option
677 ** implies the --emptydirs, --dotfiles, and
678 ** --disable-undo options. Furthermore, it completely
679 ** disregards the keep-glob and ignore-glob settings.
680 ** However, it does honor the --ignore and --keep
681 ** options.
682 ** --clean <CSG> WARNING: Never prompt to delete any files matching
683 ** this comma separated list of glob patterns. Also,
684 ** deletions of any files matching this pattern list
685 ** cannot be undone.
@@ -731,17 +732,18 @@
732 zCleanFlag = find_option("clean",0,1);
733 db_must_be_within_tree();
734 if( find_option("verily","x",0)!=0 ){
735 verilyFlag = 1;
736 emptyDirsFlag = 1;
737 disableUndo = 1;
738 scanFlags |= SCAN_ALL;
739 zCleanFlag = 0;
740 }
741 if( zIgnoreFlag==0 ){
742 zIgnoreFlag = db_get("ignore-glob", 0);
743 }
744 if( zKeepFlag==0 && !verilyFlag ){
745 zKeepFlag = db_get("keep-glob", 0);
746 }
747 if( zCleanFlag==0 && !verilyFlag ){
748 zCleanFlag = db_get("clean-glob", 0);
749 }
@@ -769,11 +771,11 @@
771 }
772 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
773 while( db_step(&q)==SQLITE_ROW ){
774 const char *zName = db_column_text(&q, 0);
775 if( glob_match(pKeep, zName+nRoot) ){
776 if( verboseFlag ){
777 fossil_print("KEPT file \"%s\" not removed (due to --keep"
778 " or \"keep-glob\")\n", zName+nRoot);
779 }
780 continue;
781 }
@@ -833,11 +835,11 @@
835 g.zLocalRoot, fossil_all_reserved_names(0)
836 );
837 while( db_step(&q)==SQLITE_ROW ){
838 const char *zName = db_column_text(&q, 0);
839 if( glob_match(pKeep, zName+nRoot) ){
840 if( verboseFlag ){
841 fossil_print("KEPT directory \"%s\" not removed (due to --keep"
842 " or \"keep-glob\")\n", zName+nRoot);
843 }
844 continue;
845 }
846
+4 -3
--- src/db.c
+++ src/db.c
@@ -1974,12 +1974,13 @@
19741974
** the user about the conflict */
19751975
fossil_warning(
19761976
"setting %s has both versioned and non-versioned values: using "
19771977
"versioned value from file .fossil-settings/%s (to silence this "
19781978
"warning, either create an empty file named "
1979
- ".fossil-settings/%s.no-warn or delete the non-versioned setting "
1980
- " with \"fossil unset %s\")", zName, zName, zName, zName
1979
+ ".fossil-settings/%s.no-warn in the check-out root, "
1980
+ "or delete the non-versioned setting "
1981
+ "with \"fossil unset %s\")", zName, zName, zName, zName
19811982
);
19821983
}
19831984
/* Prefer the versioned setting */
19841985
return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
19851986
}
@@ -2462,11 +2463,11 @@
24622463
** The "settings" command with no arguments lists all properties and their
24632464
** values. With just a property name it shows the value of that property.
24642465
** With a value argument it changes the property for the current repository.
24652466
**
24662467
** Settings marked as versionable are overridden by the contents of the
2467
-** file named .fossil-settings/PROPERTY in the checked out files, if that
2468
+** file named .fossil-settings/PROPERTY in the check-out root, if that
24682469
** file exists.
24692470
**
24702471
** The "unset" command clears a property setting.
24712472
**
24722473
**
24732474
--- src/db.c
+++ src/db.c
@@ -1974,12 +1974,13 @@
1974 ** the user about the conflict */
1975 fossil_warning(
1976 "setting %s has both versioned and non-versioned values: using "
1977 "versioned value from file .fossil-settings/%s (to silence this "
1978 "warning, either create an empty file named "
1979 ".fossil-settings/%s.no-warn or delete the non-versioned setting "
1980 " with \"fossil unset %s\")", zName, zName, zName, zName
 
1981 );
1982 }
1983 /* Prefer the versioned setting */
1984 return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
1985 }
@@ -2462,11 +2463,11 @@
2462 ** The "settings" command with no arguments lists all properties and their
2463 ** values. With just a property name it shows the value of that property.
2464 ** With a value argument it changes the property for the current repository.
2465 **
2466 ** Settings marked as versionable are overridden by the contents of the
2467 ** file named .fossil-settings/PROPERTY in the checked out files, if that
2468 ** file exists.
2469 **
2470 ** The "unset" command clears a property setting.
2471 **
2472 **
2473
--- src/db.c
+++ src/db.c
@@ -1974,12 +1974,13 @@
1974 ** the user about the conflict */
1975 fossil_warning(
1976 "setting %s has both versioned and non-versioned values: using "
1977 "versioned value from file .fossil-settings/%s (to silence this "
1978 "warning, either create an empty file named "
1979 ".fossil-settings/%s.no-warn in the check-out root, "
1980 "or delete the non-versioned setting "
1981 "with \"fossil unset %s\")", zName, zName, zName, zName
1982 );
1983 }
1984 /* Prefer the versioned setting */
1985 return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
1986 }
@@ -2462,11 +2463,11 @@
2463 ** The "settings" command with no arguments lists all properties and their
2464 ** values. With just a property name it shows the value of that property.
2465 ** With a value argument it changes the property for the current repository.
2466 **
2467 ** Settings marked as versionable are overridden by the contents of the
2468 ** file named .fossil-settings/PROPERTY in the check-out root, if that
2469 ** file exists.
2470 **
2471 ** The "unset" command clears a property setting.
2472 **
2473 **
2474
+61
--- src/delta.c
+++ src/delta.c
@@ -589,10 +589,71 @@
589589
/* ERROR: generated size does not match predicted size */
590590
return -1;
591591
}
592592
return total;
593593
}
594
+ default: {
595
+ /* ERROR: unknown delta operator */
596
+ return -1;
597
+ }
598
+ }
599
+ }
600
+ /* ERROR: unterminated delta */
601
+ return -1;
602
+}
603
+
604
+/*
605
+** Analyze a delta. Figure out the total number of bytes copied from
606
+** source to target, and the total number of bytes inserted by the delta,
607
+** and return both numbers.
608
+*/
609
+int delta_analyze(
610
+ const char *zDelta, /* Delta to apply to the pattern */
611
+ int lenDelta, /* Length of the delta */
612
+ int *pnCopy, /* OUT: Number of bytes copied */
613
+ int *pnInsert /* OUT: Number of bytes inserted */
614
+){
615
+ unsigned int nInsert = 0;
616
+ unsigned int nCopy = 0;
617
+
618
+ (void)getInt(&zDelta, &lenDelta);
619
+ if( *zDelta!='\n' ){
620
+ /* ERROR: size integer not terminated by "\n" */
621
+ return -1;
622
+ }
623
+ zDelta++; lenDelta--;
624
+ while( *zDelta && lenDelta>0 ){
625
+ unsigned int cnt, ofst;
626
+ cnt = getInt(&zDelta, &lenDelta);
627
+ switch( zDelta[0] ){
628
+ case '@': {
629
+ zDelta++; lenDelta--;
630
+ ofst = getInt(&zDelta, &lenDelta);
631
+ if( lenDelta>0 && zDelta[0]!=',' ){
632
+ /* ERROR: copy command not terminated by ',' */
633
+ return -1;
634
+ }
635
+ zDelta++; lenDelta--;
636
+ nCopy += cnt;
637
+ break;
638
+ }
639
+ case ':': {
640
+ zDelta++; lenDelta--;
641
+ nInsert += cnt;
642
+ if( cnt>lenDelta ){
643
+ /* ERROR: insert count exceeds size of delta */
644
+ return -1;
645
+ }
646
+ zDelta += cnt;
647
+ lenDelta -= cnt;
648
+ break;
649
+ }
650
+ case ';': {
651
+ *pnCopy = nCopy;
652
+ *pnInsert = nInsert;
653
+ return 0;
654
+ }
594655
default: {
595656
/* ERROR: unknown delta operator */
596657
return -1;
597658
}
598659
}
599660
--- src/delta.c
+++ src/delta.c
@@ -589,10 +589,71 @@
589 /* ERROR: generated size does not match predicted size */
590 return -1;
591 }
592 return total;
593 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
594 default: {
595 /* ERROR: unknown delta operator */
596 return -1;
597 }
598 }
599
--- src/delta.c
+++ src/delta.c
@@ -589,10 +589,71 @@
589 /* ERROR: generated size does not match predicted size */
590 return -1;
591 }
592 return total;
593 }
594 default: {
595 /* ERROR: unknown delta operator */
596 return -1;
597 }
598 }
599 }
600 /* ERROR: unterminated delta */
601 return -1;
602 }
603
604 /*
605 ** Analyze a delta. Figure out the total number of bytes copied from
606 ** source to target, and the total number of bytes inserted by the delta,
607 ** and return both numbers.
608 */
609 int delta_analyze(
610 const char *zDelta, /* Delta to apply to the pattern */
611 int lenDelta, /* Length of the delta */
612 int *pnCopy, /* OUT: Number of bytes copied */
613 int *pnInsert /* OUT: Number of bytes inserted */
614 ){
615 unsigned int nInsert = 0;
616 unsigned int nCopy = 0;
617
618 (void)getInt(&zDelta, &lenDelta);
619 if( *zDelta!='\n' ){
620 /* ERROR: size integer not terminated by "\n" */
621 return -1;
622 }
623 zDelta++; lenDelta--;
624 while( *zDelta && lenDelta>0 ){
625 unsigned int cnt, ofst;
626 cnt = getInt(&zDelta, &lenDelta);
627 switch( zDelta[0] ){
628 case '@': {
629 zDelta++; lenDelta--;
630 ofst = getInt(&zDelta, &lenDelta);
631 if( lenDelta>0 && zDelta[0]!=',' ){
632 /* ERROR: copy command not terminated by ',' */
633 return -1;
634 }
635 zDelta++; lenDelta--;
636 nCopy += cnt;
637 break;
638 }
639 case ':': {
640 zDelta++; lenDelta--;
641 nInsert += cnt;
642 if( cnt>lenDelta ){
643 /* ERROR: insert count exceeds size of delta */
644 return -1;
645 }
646 zDelta += cnt;
647 lenDelta -= cnt;
648 break;
649 }
650 case ';': {
651 *pnCopy = nCopy;
652 *pnInsert = nInsert;
653 return 0;
654 }
655 default: {
656 /* ERROR: unknown delta operator */
657 return -1;
658 }
659 }
660
+47 -4
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -43,12 +43,14 @@
4343
}
4444
4545
/*
4646
** COMMAND: test-delta-create
4747
**
48
-** Given two input files, create and output a delta that carries
49
-** the first file into the second.
48
+** Usage: %fossil test-delta-create FILE1 FILE2 DELTA
49
+**
50
+** Create and output a delta that carries FILE1 into FILE2.
51
+** Store the result in DELTA.
5052
*/
5153
void delta_create_cmd(void){
5254
Blob orig, target, delta;
5355
if( g.argc!=5 ){
5456
usage("ORIGIN TARGET DELTA");
@@ -65,10 +67,47 @@
6567
}
6668
blob_reset(&orig);
6769
blob_reset(&target);
6870
blob_reset(&delta);
6971
}
72
+
73
+/*
74
+** COMMAND: test-delta-analyze
75
+**
76
+** Usage: %fossil test-delta-analyze FILE1 FILE2
77
+**
78
+** Create and a delta that carries FILE1 into FILE2. Print the
79
+** number bytes copied and the number of bytes inserted.
80
+*/
81
+void delta_analyze_cmd(void){
82
+ Blob orig, target, delta;
83
+ int nCopy = 0;
84
+ int nInsert = 0;
85
+ int sz1, sz2;
86
+ if( g.argc!=4 ){
87
+ usage("ORIGIN TARGET");
88
+ }
89
+ if( blob_read_from_file(&orig, g.argv[2])<0 ){
90
+ fossil_fatal("cannot read %s\n", g.argv[2]);
91
+ }
92
+ if( blob_read_from_file(&target, g.argv[3])<0 ){
93
+ fossil_fatal("cannot read %s\n", g.argv[3]);
94
+ }
95
+ blob_delta_create(&orig, &target, &delta);
96
+ delta_analyze(blob_buffer(&delta), blob_size(&delta), &nCopy, &nInsert);
97
+ sz1 = blob_size(&orig);
98
+ sz2 = blob_size(&target);
99
+ blob_reset(&orig);
100
+ blob_reset(&target);
101
+ blob_reset(&delta);
102
+ fossil_print("original size: %8d\n", sz1);
103
+ fossil_print("bytes copied: %8d (%.1f%% of target)\n",
104
+ nCopy, (100.0*nCopy)/sz2);
105
+ fossil_print("bytes inserted: %8d (%.1f%% of target)\n",
106
+ nInsert, (100.0*nInsert)/sz2);
107
+ fossil_print("final size: %8d\n", sz2);
108
+}
70109
71110
/*
72111
** Apply the delta in pDelta to the original file pOriginal to generate
73112
** the target file pTarget. The pTarget blob is initialized by this
74113
** routine.
@@ -102,12 +141,13 @@
102141
}
103142
104143
/*
105144
** COMMAND: test-delta-apply
106145
**
107
-** Given an input files and a delta, apply the delta to the input file
108
-** and write the result.
146
+** Usage: %fossil test-delta-apply FILE1 DELTA
147
+**
148
+** Apply DELTA to FILE1 and output the result.
109149
*/
110150
void delta_apply_cmd(void){
111151
Blob orig, target, delta;
112152
if( g.argc!=5 ){
113153
usage("ORIGIN DELTA TARGET");
@@ -124,13 +164,16 @@
124164
}
125165
blob_reset(&orig);
126166
blob_reset(&target);
127167
blob_reset(&delta);
128168
}
169
+
129170
130171
/*
131172
** COMMAND: test-delta
173
+**
174
+** Usage: %fossil test-delta FILE1 FILE2
132175
**
133176
** Read two files named on the command-line. Create and apply deltas
134177
** going in both directions. Verify that the original files are
135178
** correctly recovered.
136179
*/
137180
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -43,12 +43,14 @@
43 }
44
45 /*
46 ** COMMAND: test-delta-create
47 **
48 ** Given two input files, create and output a delta that carries
49 ** the first file into the second.
 
 
50 */
51 void delta_create_cmd(void){
52 Blob orig, target, delta;
53 if( g.argc!=5 ){
54 usage("ORIGIN TARGET DELTA");
@@ -65,10 +67,47 @@
65 }
66 blob_reset(&orig);
67 blob_reset(&target);
68 blob_reset(&delta);
69 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71 /*
72 ** Apply the delta in pDelta to the original file pOriginal to generate
73 ** the target file pTarget. The pTarget blob is initialized by this
74 ** routine.
@@ -102,12 +141,13 @@
102 }
103
104 /*
105 ** COMMAND: test-delta-apply
106 **
107 ** Given an input files and a delta, apply the delta to the input file
108 ** and write the result.
 
109 */
110 void delta_apply_cmd(void){
111 Blob orig, target, delta;
112 if( g.argc!=5 ){
113 usage("ORIGIN DELTA TARGET");
@@ -124,13 +164,16 @@
124 }
125 blob_reset(&orig);
126 blob_reset(&target);
127 blob_reset(&delta);
128 }
 
129
130 /*
131 ** COMMAND: test-delta
 
 
132 **
133 ** Read two files named on the command-line. Create and apply deltas
134 ** going in both directions. Verify that the original files are
135 ** correctly recovered.
136 */
137
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -43,12 +43,14 @@
43 }
44
45 /*
46 ** COMMAND: test-delta-create
47 **
48 ** Usage: %fossil test-delta-create FILE1 FILE2 DELTA
49 **
50 ** Create and output a delta that carries FILE1 into FILE2.
51 ** Store the result in DELTA.
52 */
53 void delta_create_cmd(void){
54 Blob orig, target, delta;
55 if( g.argc!=5 ){
56 usage("ORIGIN TARGET DELTA");
@@ -65,10 +67,47 @@
67 }
68 blob_reset(&orig);
69 blob_reset(&target);
70 blob_reset(&delta);
71 }
72
73 /*
74 ** COMMAND: test-delta-analyze
75 **
76 ** Usage: %fossil test-delta-analyze FILE1 FILE2
77 **
78 ** Create and a delta that carries FILE1 into FILE2. Print the
79 ** number bytes copied and the number of bytes inserted.
80 */
81 void delta_analyze_cmd(void){
82 Blob orig, target, delta;
83 int nCopy = 0;
84 int nInsert = 0;
85 int sz1, sz2;
86 if( g.argc!=4 ){
87 usage("ORIGIN TARGET");
88 }
89 if( blob_read_from_file(&orig, g.argv[2])<0 ){
90 fossil_fatal("cannot read %s\n", g.argv[2]);
91 }
92 if( blob_read_from_file(&target, g.argv[3])<0 ){
93 fossil_fatal("cannot read %s\n", g.argv[3]);
94 }
95 blob_delta_create(&orig, &target, &delta);
96 delta_analyze(blob_buffer(&delta), blob_size(&delta), &nCopy, &nInsert);
97 sz1 = blob_size(&orig);
98 sz2 = blob_size(&target);
99 blob_reset(&orig);
100 blob_reset(&target);
101 blob_reset(&delta);
102 fossil_print("original size: %8d\n", sz1);
103 fossil_print("bytes copied: %8d (%.1f%% of target)\n",
104 nCopy, (100.0*nCopy)/sz2);
105 fossil_print("bytes inserted: %8d (%.1f%% of target)\n",
106 nInsert, (100.0*nInsert)/sz2);
107 fossil_print("final size: %8d\n", sz2);
108 }
109
110 /*
111 ** Apply the delta in pDelta to the original file pOriginal to generate
112 ** the target file pTarget. The pTarget blob is initialized by this
113 ** routine.
@@ -102,12 +141,13 @@
141 }
142
143 /*
144 ** COMMAND: test-delta-apply
145 **
146 ** Usage: %fossil test-delta-apply FILE1 DELTA
147 **
148 ** Apply DELTA to FILE1 and output the result.
149 */
150 void delta_apply_cmd(void){
151 Blob orig, target, delta;
152 if( g.argc!=5 ){
153 usage("ORIGIN DELTA TARGET");
@@ -124,13 +164,16 @@
164 }
165 blob_reset(&orig);
166 blob_reset(&target);
167 blob_reset(&delta);
168 }
169
170
171 /*
172 ** COMMAND: test-delta
173 **
174 ** Usage: %fossil test-delta FILE1 FILE2
175 **
176 ** Read two files named on the command-line. Create and apply deltas
177 ** going in both directions. Verify that the original files are
178 ** correctly recovered.
179 */
180
+4 -3
--- src/doc.c
+++ src/doc.c
@@ -523,11 +523,11 @@
523523
** it gets checked in.
524524
**
525525
** The file extension is used to decide how to render the file.
526526
**
527527
** If FILE ends in "/" then names "FILE/index.html", "FILE/index.wiki",
528
-** and "FILE/index.md" are in that order. If none of those are found,
528
+** and "FILE/index.md" are tried in that order. If none of those are found,
529529
** then FILE is completely replaced by "404.md" and tried. If that is
530530
** not found, then a default 404 screen is generated.
531531
*/
532532
void doc_page(void){
533533
const char *zName; /* Argument to the /doc page */
@@ -547,14 +547,15 @@
547547
login_check_credentials();
548548
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
549549
blob_init(&title, 0, 0);
550550
db_begin_transaction();
551551
while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){
552
- zName = PD("name", "tip/index.wiki");
552
+ zName = P("name");
553
+ if( zName==0 || zName[0]==0 ) zName = "tip/index.wiki";
553554
for(i=0; zName[i] && zName[i]!='/'; i++){}
554555
zCheckin = mprintf("%.*s", i, zName);
555
- if( fossil_strcmp(zCheckin,"ckout")==0 && db_open_local(0)==0 ){
556
+ if( fossil_strcmp(zCheckin,"ckout")==0 && g.localOpen==0 ){
556557
zCheckin = "tip";
557558
}
558559
if( nMiss==ArraySize(azSuffix) ){
559560
zName = "404.md";
560561
}else if( zName[i]==0 ){
561562
--- src/doc.c
+++ src/doc.c
@@ -523,11 +523,11 @@
523 ** it gets checked in.
524 **
525 ** The file extension is used to decide how to render the file.
526 **
527 ** If FILE ends in "/" then names "FILE/index.html", "FILE/index.wiki",
528 ** and "FILE/index.md" are in that order. If none of those are found,
529 ** then FILE is completely replaced by "404.md" and tried. If that is
530 ** not found, then a default 404 screen is generated.
531 */
532 void doc_page(void){
533 const char *zName; /* Argument to the /doc page */
@@ -547,14 +547,15 @@
547 login_check_credentials();
548 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
549 blob_init(&title, 0, 0);
550 db_begin_transaction();
551 while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){
552 zName = PD("name", "tip/index.wiki");
 
553 for(i=0; zName[i] && zName[i]!='/'; i++){}
554 zCheckin = mprintf("%.*s", i, zName);
555 if( fossil_strcmp(zCheckin,"ckout")==0 && db_open_local(0)==0 ){
556 zCheckin = "tip";
557 }
558 if( nMiss==ArraySize(azSuffix) ){
559 zName = "404.md";
560 }else if( zName[i]==0 ){
561
--- src/doc.c
+++ src/doc.c
@@ -523,11 +523,11 @@
523 ** it gets checked in.
524 **
525 ** The file extension is used to decide how to render the file.
526 **
527 ** If FILE ends in "/" then names "FILE/index.html", "FILE/index.wiki",
528 ** and "FILE/index.md" are tried in that order. If none of those are found,
529 ** then FILE is completely replaced by "404.md" and tried. If that is
530 ** not found, then a default 404 screen is generated.
531 */
532 void doc_page(void){
533 const char *zName; /* Argument to the /doc page */
@@ -547,14 +547,15 @@
547 login_check_credentials();
548 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
549 blob_init(&title, 0, 0);
550 db_begin_transaction();
551 while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){
552 zName = P("name");
553 if( zName==0 || zName[0]==0 ) zName = "tip/index.wiki";
554 for(i=0; zName[i] && zName[i]!='/'; i++){}
555 zCheckin = mprintf("%.*s", i, zName);
556 if( fossil_strcmp(zCheckin,"ckout")==0 && g.localOpen==0 ){
557 zCheckin = "tip";
558 }
559 if( nMiss==ArraySize(azSuffix) ){
560 zName = "404.md";
561 }else if( zName[i]==0 ){
562
+5 -4
--- src/foci.c
+++ src/foci.c
@@ -167,17 +167,18 @@
167167
){
168168
FociCursor *pCur = (FociCursor *)pCursor;
169169
manifest_destroy(pCur->pMan);
170170
if( idxNum ){
171171
pCur->pMan = manifest_get(sqlite3_value_int(argv[0]), CFTYPE_MANIFEST, 0);
172
- pCur->iFile = 0;
173
- manifest_file_rewind(pCur->pMan);
174
- pCur->pFile = manifest_file_next(pCur->pMan, 0);
172
+ if( pCur->pMan ){
173
+ manifest_file_rewind(pCur->pMan);
174
+ pCur->pFile = manifest_file_next(pCur->pMan, 0);
175
+ }
175176
}else{
176177
pCur->pMan = 0;
177
- pCur->iFile = 0;
178178
}
179
+ pCur->iFile = 0;
179180
return SQLITE_OK;
180181
}
181182
182183
static int fociColumn(
183184
sqlite3_vtab_cursor *pCursor,
184185
--- src/foci.c
+++ src/foci.c
@@ -167,17 +167,18 @@
167 ){
168 FociCursor *pCur = (FociCursor *)pCursor;
169 manifest_destroy(pCur->pMan);
170 if( idxNum ){
171 pCur->pMan = manifest_get(sqlite3_value_int(argv[0]), CFTYPE_MANIFEST, 0);
172 pCur->iFile = 0;
173 manifest_file_rewind(pCur->pMan);
174 pCur->pFile = manifest_file_next(pCur->pMan, 0);
 
175 }else{
176 pCur->pMan = 0;
177 pCur->iFile = 0;
178 }
 
179 return SQLITE_OK;
180 }
181
182 static int fociColumn(
183 sqlite3_vtab_cursor *pCursor,
184
--- src/foci.c
+++ src/foci.c
@@ -167,17 +167,18 @@
167 ){
168 FociCursor *pCur = (FociCursor *)pCursor;
169 manifest_destroy(pCur->pMan);
170 if( idxNum ){
171 pCur->pMan = manifest_get(sqlite3_value_int(argv[0]), CFTYPE_MANIFEST, 0);
172 if( pCur->pMan ){
173 manifest_file_rewind(pCur->pMan);
174 pCur->pFile = manifest_file_next(pCur->pMan, 0);
175 }
176 }else{
177 pCur->pMan = 0;
 
178 }
179 pCur->iFile = 0;
180 return SQLITE_OK;
181 }
182
183 static int fociColumn(
184 sqlite3_vtab_cursor *pCursor,
185
+345 -80
--- src/info.c
+++ src/info.c
@@ -1886,11 +1886,11 @@
18861886
}
18871887
if( descOnly ){
18881888
style_submenu_element("Content", "Content", "%R/artifact/%s", zUuid);
18891889
}else{
18901890
style_submenu_element("Line Numbers", "Line Numbers",
1891
- "%R/info/%s%s",zUuid,
1891
+ "%R/artifact/%s%s",zUuid,
18921892
((zLn&&*zLn) ? "" : "?txt=1&ln=0"));
18931893
@ <hr />
18941894
content_get(rid, &content);
18951895
if( renderAsWiki ){
18961896
wiki_render_by_mimetype(&content, zMime);
@@ -2276,10 +2276,133 @@
22762276
}
22772277
while( fossil_isspace(zB[0]) ) zB++;
22782278
while( fossil_isspace(zA[0]) ) zA++;
22792279
return zA[0]==0 && zB[0]==0;
22802280
}
2281
+
2282
+/*
2283
+** The following methods operate on the newtags temporary table
2284
+** that is used to collect various changes to be added to a control
2285
+** artifact for a check-in edit.
2286
+*/
2287
+static void init_newtags(void){
2288
+ db_multi_exec("CREATE TEMP TABLE newtags(tag UNIQUE, prefix, value)");
2289
+}
2290
+
2291
+static void change_special(
2292
+ const char *zName, /* Name of the special tag */
2293
+ const char *zOp, /* Operation prefix (e.g. +,-,*) */
2294
+ const char *zValue /* Value of the tag */
2295
+){
2296
+ db_multi_exec("REPLACE INTO newtags VALUES(%Q,'%q',%Q)", zName, zOp, zValue);
2297
+}
2298
+
2299
+static void change_sym_tag(const char *zTag, const char *zOp){
2300
+ db_multi_exec("REPLACE INTO newtags VALUES('sym-%q',%Q,NULL)", zTag, zOp);
2301
+}
2302
+
2303
+static void cancel_special(const char *zTag){
2304
+ change_special(zTag,"-",0);
2305
+}
2306
+
2307
+static void add_color(const char *zNewColor, int fPropagateColor){
2308
+ change_special("bgcolor",fPropagateColor ? "*" : "+", zNewColor);
2309
+}
2310
+
2311
+static void cancel_color(void){
2312
+ change_special("bgcolor","-",0);
2313
+}
2314
+
2315
+static void add_comment(const char *zNewComment){
2316
+ change_special("comment","+",zNewComment);
2317
+}
2318
+
2319
+static void add_date(const char *zNewDate){
2320
+ change_special("date","+",zNewDate);
2321
+}
2322
+
2323
+static void add_user(const char *zNewUser){
2324
+ change_special("user","+",zNewUser);
2325
+}
2326
+
2327
+static void add_tag(const char *zNewTag){
2328
+ change_sym_tag(zNewTag,"+");
2329
+}
2330
+
2331
+static void cancel_tag(int rid, const char *zCancelTag){
2332
+ if( db_exists("SELECT 1 FROM tagxref, tag"
2333
+ " WHERE tagxref.rid=%d AND tagtype>0"
2334
+ " AND tagxref.tagid=tag.tagid AND tagname='sym-%q'",
2335
+ rid, zCancelTag)
2336
+ ) change_sym_tag(zCancelTag,"-");
2337
+}
2338
+
2339
+static void hide_branch(void){
2340
+ change_special("hidden","*",0);
2341
+}
2342
+
2343
+static void close_leaf(int rid){
2344
+ change_special("closed",is_a_leaf(rid)?"+":"*",0);
2345
+}
2346
+
2347
+static void change_branch(int rid, const char *zNewBranch){
2348
+ db_multi_exec(
2349
+ "REPLACE INTO newtags "
2350
+ " SELECT tagname, '-', NULL FROM tagxref, tag"
2351
+ " WHERE tagxref.rid=%d AND tagtype==2"
2352
+ " AND tagname GLOB 'sym-*'"
2353
+ " AND tag.tagid=tagxref.tagid",
2354
+ rid
2355
+ );
2356
+ change_special("branch","*",zNewBranch);
2357
+ change_sym_tag(zNewBranch,"*");
2358
+}
2359
+
2360
+/*
2361
+** The apply_newtags method is called after all newtags have been added
2362
+** and the control artifact is completed and then written to the DB.
2363
+*/
2364
+static void apply_newtags(Blob *ctrl, int rid, const char *zUuid){
2365
+ Stmt q;
2366
+ int nChng = 0;
2367
+
2368
+ db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
2369
+ " ORDER BY prefix || tag");
2370
+ while( db_step(&q)==SQLITE_ROW ){
2371
+ const char *zTag = db_column_text(&q, 0);
2372
+ const char *zPrefix = db_column_text(&q, 1);
2373
+ const char *zValue = db_column_text(&q, 2);
2374
+ nChng++;
2375
+ if( zValue ){
2376
+ blob_appendf(ctrl, "T %s%F %s %F\n", zPrefix, zTag, zUuid, zValue);
2377
+ }else{
2378
+ blob_appendf(ctrl, "T %s%F %s\n", zPrefix, zTag, zUuid);
2379
+ }
2380
+ }
2381
+ db_finalize(&q);
2382
+ if( nChng>0 ){
2383
+ int nrid;
2384
+ Blob cksum;
2385
+ blob_appendf(ctrl, "U %F\n", login_name());
2386
+ md5sum_blob(ctrl, &cksum);
2387
+ blob_appendf(ctrl, "Z %b\n", &cksum);
2388
+ db_begin_transaction();
2389
+ g.markPrivate = content_is_private(rid);
2390
+ nrid = content_put(ctrl);
2391
+ manifest_crosslink(nrid, ctrl, MC_PERMIT_HOOKS);
2392
+ assert( blob_is_reset(ctrl) );
2393
+ db_end_transaction(0);
2394
+ }
2395
+}
2396
+
2397
+/*
2398
+** This method checks that the date can be parsed.
2399
+** Returns 1 if datetime() can validate, 0 otherwise.
2400
+*/
2401
+int is_datetime(const char* zDate){
2402
+ return db_int(0, "SELECT datetime(%Q) NOT NULL", zDate);
2403
+}
22812404
22822405
/*
22832406
** WEBPAGE: ci_edit
22842407
** URL: /ci_edit?r=RID&c=NEWCOMMENT&u=NEWUSER
22852408
**
@@ -2354,42 +2477,24 @@
23542477
zCloseFlag = P("close") ? " checked" : "";
23552478
zHideFlag = P("hide") ? " checked" : "";
23562479
if( P("apply") ){
23572480
Blob ctrl;
23582481
char *zNow;
2359
- int nChng = 0;
23602482
23612483
login_verify_csrf_secret();
23622484
blob_zero(&ctrl);
23632485
zNow = date_in_standard_format(zChngTime ? zChngTime : "now");
23642486
blob_appendf(&ctrl, "D %s\n", zNow);
2365
- db_multi_exec("CREATE TEMP TABLE newtags(tag UNIQUE, prefix, value)");
2487
+ init_newtags();
23662488
if( zNewColor[0]
23672489
&& (fPropagateColor!=fNewPropagateColor
23682490
|| fossil_strcmp(zColor,zNewColor)!=0)
2369
- ){
2370
- char *zPrefix = "+";
2371
- if( fNewPropagateColor ){
2372
- zPrefix = "*";
2373
- }
2374
- db_multi_exec("REPLACE INTO newtags VALUES('bgcolor',%Q,%Q)",
2375
- zPrefix, zNewColor);
2376
- }
2377
- if( zNewColor[0]==0 && zColor[0]!=0 ){
2378
- db_multi_exec("REPLACE INTO newtags VALUES('bgcolor','-',NULL)");
2379
- }
2380
- if( comment_compare(zComment,zNewComment)==0 ){
2381
- db_multi_exec("REPLACE INTO newtags VALUES('comment','+',%Q)",
2382
- zNewComment);
2383
- }
2384
- if( fossil_strcmp(zDate,zNewDate)!=0 ){
2385
- db_multi_exec("REPLACE INTO newtags VALUES('date','+',%Q)",
2386
- zNewDate);
2387
- }
2388
- if( fossil_strcmp(zUser,zNewUser)!=0 ){
2389
- db_multi_exec("REPLACE INTO newtags VALUES('user','+',%Q)", zNewUser);
2390
- }
2491
+ ) add_color(zNewColor,fNewPropagateColor);
2492
+ if( zNewColor[0]==0 && zColor[0]!=0 ) cancel_color();
2493
+ if( comment_compare(zComment,zNewComment)==0 ) add_comment(zNewComment);
2494
+ if( fossil_strcmp(zDate,zNewDate)!=0 ) add_date(zNewDate);
2495
+ if( fossil_strcmp(zUser,zNewUser)!=0 ) add_user(zNewUser);
23912496
db_prepare(&q,
23922497
"SELECT tag.tagid, tagname FROM tagxref, tag"
23932498
" WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid",
23942499
rid
23952500
);
@@ -2396,65 +2501,18 @@
23962501
while( db_step(&q)==SQLITE_ROW ){
23972502
int tagid = db_column_int(&q, 0);
23982503
const char *zTag = db_column_text(&q, 1);
23992504
char zLabel[30];
24002505
sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
2401
- if( P(zLabel) ){
2402
- db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2403
- }
2404
- }
2405
- db_finalize(&q);
2406
- if( zHideFlag[0] ){
2407
- db_multi_exec("REPLACE INTO newtags VALUES('hidden','*',NULL)");
2408
- }
2409
- if( zCloseFlag[0] ){
2410
- db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2411
- is_a_leaf(rid)?"+":"*");
2412
- }
2413
- if( zNewTagFlag[0] && zNewTag[0] ){
2414
- db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
2415
- }
2416
- if( zNewBrFlag[0] && zNewBranch[0] ){
2417
- db_multi_exec(
2418
- "REPLACE INTO newtags "
2419
- " SELECT tagname, '-', NULL FROM tagxref, tag"
2420
- " WHERE tagxref.rid=%d AND tagtype==2"
2421
- " AND tagname GLOB 'sym-*'"
2422
- " AND tag.tagid=tagxref.tagid",
2423
- rid
2424
- );
2425
- db_multi_exec("REPLACE INTO newtags VALUES('branch','*',%Q)", zNewBranch);
2426
- db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','*',NULL)",
2427
- zNewBranch);
2428
- }
2429
- db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
2430
- " ORDER BY prefix || tag");
2431
- while( db_step(&q)==SQLITE_ROW ){
2432
- const char *zTag = db_column_text(&q, 0);
2433
- const char *zPrefix = db_column_text(&q, 1);
2434
- const char *zValue = db_column_text(&q, 2);
2435
- nChng++;
2436
- if( zValue ){
2437
- blob_appendf(&ctrl, "T %s%F %s %F\n", zPrefix, zTag, zUuid, zValue);
2438
- }else{
2439
- blob_appendf(&ctrl, "T %s%F %s\n", zPrefix, zTag, zUuid);
2440
- }
2441
- }
2442
- db_finalize(&q);
2443
- if( nChng>0 ){
2444
- int nrid;
2445
- Blob cksum;
2446
- blob_appendf(&ctrl, "U %F\n", login_name());
2447
- md5sum_blob(&ctrl, &cksum);
2448
- blob_appendf(&ctrl, "Z %b\n", &cksum);
2449
- db_begin_transaction();
2450
- g.markPrivate = content_is_private(rid);
2451
- nrid = content_put(&ctrl);
2452
- manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
2453
- assert( blob_is_reset(&ctrl) );
2454
- db_end_transaction(0);
2455
- }
2506
+ if( P(zLabel) ) cancel_special(zTag);
2507
+ }
2508
+ db_finalize(&q);
2509
+ if( zHideFlag[0] ) hide_branch();
2510
+ if( zCloseFlag[0] ) close_leaf(rid);
2511
+ if( zNewTagFlag[0] && zNewTag[0] ) add_tag(zNewTag);
2512
+ if( zNewBrFlag[0] && zNewBranch[0] ) change_branch(rid,zNewBranch);
2513
+ apply_newtags(&ctrl, rid, zUuid);
24562514
cgi_redirectf("ci?name=%s", zUuid);
24572515
}
24582516
blob_zero(&comment);
24592517
blob_append(&comment, zNewComment, -1);
24602518
zUuid[10] = 0;
@@ -2652,5 +2710,212 @@
26522710
@ </td></tr>
26532711
@ </table>
26542712
@ </div></form>
26552713
style_footer();
26562714
}
2715
+
2716
+/*
2717
+** Prepare an ammended commit comment. Let the user modify it using the
2718
+** editor specified in the global_config table or either
2719
+** the VISUAL or EDITOR environment variable.
2720
+**
2721
+** Store the final commit comment in pComment. pComment is assumed
2722
+** to be uninitialized - any prior content is overwritten.
2723
+**
2724
+** Use zInit to initialize the check-in comment so that the user does
2725
+** not have to retype.
2726
+*/
2727
+static void prepare_amend_comment(
2728
+ Blob *pComment,
2729
+ const char *zInit,
2730
+ const char *zUuid
2731
+){
2732
+ Blob prompt;
2733
+#if defined(_WIN32) || defined(__CYGWIN__)
2734
+ int bomSize;
2735
+ const unsigned char *bom = get_utf8_bom(&bomSize);
2736
+ blob_init(&prompt, (const char *) bom, bomSize);
2737
+ if( zInit && zInit[0]){
2738
+ blob_append(&prompt, zInit, -1);
2739
+ }
2740
+#else
2741
+ blob_init(&prompt, zInit, -1);
2742
+#endif
2743
+ blob_append(&prompt, "\n# Enter a new comment for check-in ", -1);
2744
+ if( zUuid && zUuid[0] ){
2745
+ blob_append(&prompt, zUuid, -1);
2746
+ }
2747
+ blob_append(&prompt, ".\n# Lines beginning with a # are ignored.\n", -1);
2748
+ prompt_for_user_comment(pComment, &prompt);
2749
+ blob_reset(&prompt);
2750
+}
2751
+
2752
+#define AMEND_USAGE_STMT "UUID OPTION ?OPTION ...?"
2753
+/*
2754
+** COMMAND: amend
2755
+**
2756
+** Usage: %fossil amend UUID OPTION ?OPTION ...?
2757
+**
2758
+** Amend the tags on check-in UUID to change how it displays in the timeline.
2759
+**
2760
+** Options:
2761
+**
2762
+** --author USER Make USER the author for check-in
2763
+** -m|--comment COMMENT Make COMMENT the check-in comment
2764
+** -M|--message-file FILE Read the amended comment from FILE
2765
+** --edit-comment Launch editor to revise comment
2766
+** --date DATE Make DATE the check-in time
2767
+** --bgcolor COLOR Apply COLOR to this check-in
2768
+** --branchcolor COLOR Apply and propagate COLOR to the branch
2769
+** --tag TAG Add new TAG to this check-in
2770
+** --cancel TAG Cancel TAG from this check-in
2771
+** --branch NAME Make this check-in the start of branch NAME
2772
+** --hide Hide branch starting from this check-in
2773
+** --close Mark this "leaf" as closed
2774
+*/
2775
+void ci_amend_cmd(void){
2776
+ int rid;
2777
+ const char *zComment; /* Current comment on the check-in */
2778
+ const char *zNewComment; /* Revised check-in comment */
2779
+ const char *zComFile; /* Filename from which to read comment */
2780
+ const char *zUser; /* Current user for the check-in */
2781
+ const char *zNewUser; /* Revised user */
2782
+ const char *zDate; /* Current date of the check-in */
2783
+ const char *zNewDate; /* Revised check-in date */
2784
+ const char *zColor;
2785
+ const char *zNewColor;
2786
+ const char *zNewBrColor;
2787
+ const char *zNewBranch;
2788
+ const char **pzNewTags = 0;
2789
+ const char **pzCancelTags = 0;
2790
+ int fClose; /* True if leaf should be closed */
2791
+ int fHide; /* True if branch should be hidden */
2792
+ int fPropagateColor; /* True if color propagates before amend */
2793
+ int fNewPropagateColor = 0; /* True if color propagates after amend */
2794
+ int fHasHidden = 0; /* True if hidden tag already set */
2795
+ int fHasClosed = 0; /* True if closed tag already set */
2796
+ int fEditComment; /* True if editor to be used for comment */
2797
+ const char *zChngTime; /* The change time on the control artifact */
2798
+ const char *zUuid;
2799
+ Blob ctrl;
2800
+ Blob comment;
2801
+ char *zNow;
2802
+ int nTags, nCancels;
2803
+ int i;
2804
+ Stmt q;
2805
+
2806
+ if( g.argc==3 ) usage(AMEND_USAGE_STMT);
2807
+ fEditComment = find_option("edit-comment",0,0)!=0;
2808
+ zNewComment = find_option("comment","m",1);
2809
+ zComFile = find_option("message-file","M",1);
2810
+ zNewBranch = find_option("branch",0,1);
2811
+ zNewColor = find_option("bgcolor",0,1);
2812
+ zNewBrColor = find_option("branchcolor",0,1);
2813
+ if( zNewBrColor ){
2814
+ zNewColor = zNewBrColor;
2815
+ fNewPropagateColor = 1;
2816
+ }
2817
+ zNewDate = find_option("date",0,1);
2818
+ zNewUser = find_option("author",0,1);
2819
+ pzNewTags = find_repeatable_option("tag",0,&nTags);
2820
+ pzCancelTags = find_repeatable_option("cancel",0,&nCancels);
2821
+ fClose = find_option("close",0,0)!=0;
2822
+ fHide = find_option("hide",0,0)!=0;
2823
+ zChngTime = find_option("chngtime",0,1);
2824
+ db_find_and_open_repository(0,0);
2825
+ user_select();
2826
+ verify_all_options();
2827
+ if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
2828
+ rid = name_to_typed_rid(g.argv[2], "ci");
2829
+ if( rid==0 && !is_a_version(rid) ) fossil_fatal("no such check-in");
2830
+ zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
2831
+ if( zUuid==0 ) fossil_fatal("Unable to find UUID");
2832
+ zComment = db_text(0, "SELECT coalesce(ecomment,comment)"
2833
+ " FROM event WHERE objid=%d", rid);
2834
+ zUser = db_text(0, "SELECT coalesce(euser,user)"
2835
+ " FROM event WHERE objid=%d", rid);
2836
+ zDate = db_text(0, "SELECT datetime(mtime)"
2837
+ " FROM event WHERE objid=%d", rid);
2838
+ zColor = db_text("", "SELECT bgcolor"
2839
+ " FROM event WHERE objid=%d", rid);
2840
+ fPropagateColor = db_int(0, "SELECT tagtype FROM tagxref"
2841
+ " WHERE rid=%d AND tagid=%d",
2842
+ rid, TAG_BGCOLOR)==2;
2843
+ fNewPropagateColor = zNewColor && zNewColor[0]
2844
+ ? fNewPropagateColor : fPropagateColor;
2845
+ db_prepare(&q,
2846
+ "SELECT tag.tagid FROM tagxref, tag"
2847
+ " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid",
2848
+ rid
2849
+ );
2850
+ while( db_step(&q)==SQLITE_ROW ){
2851
+ int tagid = db_column_int(&q, 0);
2852
+
2853
+ if( tagid == TAG_CLOSED ){
2854
+ fHasClosed = 1;
2855
+ }else if( tagid==TAG_HIDDEN ){
2856
+ fHasHidden = 1;
2857
+ }else{
2858
+ continue;
2859
+ }
2860
+ }
2861
+ db_finalize(&q);
2862
+ blob_zero(&ctrl);
2863
+ zNow = date_in_standard_format(zChngTime && zChngTime[0] ? zChngTime : "now");
2864
+ blob_appendf(&ctrl, "D %s\n", zNow);
2865
+ init_newtags();
2866
+ if( zNewColor && zNewColor[0]
2867
+ && (fPropagateColor!=fNewPropagateColor
2868
+ || fossil_strcmp(zColor,zNewColor)!=0)
2869
+ ){
2870
+ add_color(
2871
+ mprintf("%s%s", (zNewColor[0]!='#' &&
2872
+ validate16(zNewColor,strlen(zNewColor)) &&
2873
+ (strlen(zNewColor)==6 || strlen(zNewColor)==3)) ? "#" : "",
2874
+ zNewColor
2875
+ ),
2876
+ fNewPropagateColor
2877
+ );
2878
+ }
2879
+ if( (zNewColor!=0 && zNewColor[0]==0) && (zColor && zColor[0] ) ){
2880
+ cancel_color();
2881
+ }
2882
+ if( fEditComment ){
2883
+ prepare_amend_comment(&comment, zComment, zUuid);
2884
+ zNewComment = blob_str(&comment);
2885
+ }else if( zComFile ){
2886
+ blob_zero(&comment);
2887
+ blob_read_from_file(&comment, zComFile);
2888
+ blob_to_utf8_no_bom(&comment, 1);
2889
+ zNewComment = blob_str(&comment);
2890
+ }
2891
+ if( zNewComment && zNewComment[0]
2892
+ && comment_compare(zComment,zNewComment)==0 ) add_comment(zNewComment);
2893
+ if( zNewDate && zNewDate[0] && fossil_strcmp(zDate,zNewDate)!=0 ){
2894
+ if( is_datetime(zNewDate) ){
2895
+ add_date(zNewDate);
2896
+ }else{
2897
+ fossil_fatal("Unsupported date format, use YYYY-MM-DD HH:MM:SS");
2898
+ }
2899
+ }
2900
+ if( zNewUser && zNewUser[0] && fossil_strcmp(zUser,zNewUser)!=0 ){
2901
+ add_user(zNewUser);
2902
+ }
2903
+ if( pzNewTags!=0 ){
2904
+ for(i=0; i<nTags; i++){
2905
+ if( pzNewTags[i] && pzNewTags[i][0] ) add_tag(pzNewTags[i]);
2906
+ }
2907
+ fossil_free(pzNewTags);
2908
+ }
2909
+ if( pzCancelTags!=0 ){
2910
+ for(i=0; i<nCancels; i++){
2911
+ if( pzCancelTags[i] && pzCancelTags[i][0] )
2912
+ cancel_tag(rid,pzCancelTags[i]);
2913
+ }
2914
+ fossil_free(pzCancelTags);
2915
+ }
2916
+ if( fHide && !fHasHidden ) hide_branch();
2917
+ if( fClose && !fHasClosed ) close_leaf(rid);
2918
+ if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
2919
+ apply_newtags(&ctrl, rid, zUuid);
2920
+ show_common_info(rid, "uuid:", 1, 0);
2921
+}
26572922
--- src/info.c
+++ src/info.c
@@ -1886,11 +1886,11 @@
1886 }
1887 if( descOnly ){
1888 style_submenu_element("Content", "Content", "%R/artifact/%s", zUuid);
1889 }else{
1890 style_submenu_element("Line Numbers", "Line Numbers",
1891 "%R/info/%s%s",zUuid,
1892 ((zLn&&*zLn) ? "" : "?txt=1&ln=0"));
1893 @ <hr />
1894 content_get(rid, &content);
1895 if( renderAsWiki ){
1896 wiki_render_by_mimetype(&content, zMime);
@@ -2276,10 +2276,133 @@
2276 }
2277 while( fossil_isspace(zB[0]) ) zB++;
2278 while( fossil_isspace(zA[0]) ) zA++;
2279 return zA[0]==0 && zB[0]==0;
2280 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2281
2282 /*
2283 ** WEBPAGE: ci_edit
2284 ** URL: /ci_edit?r=RID&c=NEWCOMMENT&u=NEWUSER
2285 **
@@ -2354,42 +2477,24 @@
2354 zCloseFlag = P("close") ? " checked" : "";
2355 zHideFlag = P("hide") ? " checked" : "";
2356 if( P("apply") ){
2357 Blob ctrl;
2358 char *zNow;
2359 int nChng = 0;
2360
2361 login_verify_csrf_secret();
2362 blob_zero(&ctrl);
2363 zNow = date_in_standard_format(zChngTime ? zChngTime : "now");
2364 blob_appendf(&ctrl, "D %s\n", zNow);
2365 db_multi_exec("CREATE TEMP TABLE newtags(tag UNIQUE, prefix, value)");
2366 if( zNewColor[0]
2367 && (fPropagateColor!=fNewPropagateColor
2368 || fossil_strcmp(zColor,zNewColor)!=0)
2369 ){
2370 char *zPrefix = "+";
2371 if( fNewPropagateColor ){
2372 zPrefix = "*";
2373 }
2374 db_multi_exec("REPLACE INTO newtags VALUES('bgcolor',%Q,%Q)",
2375 zPrefix, zNewColor);
2376 }
2377 if( zNewColor[0]==0 && zColor[0]!=0 ){
2378 db_multi_exec("REPLACE INTO newtags VALUES('bgcolor','-',NULL)");
2379 }
2380 if( comment_compare(zComment,zNewComment)==0 ){
2381 db_multi_exec("REPLACE INTO newtags VALUES('comment','+',%Q)",
2382 zNewComment);
2383 }
2384 if( fossil_strcmp(zDate,zNewDate)!=0 ){
2385 db_multi_exec("REPLACE INTO newtags VALUES('date','+',%Q)",
2386 zNewDate);
2387 }
2388 if( fossil_strcmp(zUser,zNewUser)!=0 ){
2389 db_multi_exec("REPLACE INTO newtags VALUES('user','+',%Q)", zNewUser);
2390 }
2391 db_prepare(&q,
2392 "SELECT tag.tagid, tagname FROM tagxref, tag"
2393 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid",
2394 rid
2395 );
@@ -2396,65 +2501,18 @@
2396 while( db_step(&q)==SQLITE_ROW ){
2397 int tagid = db_column_int(&q, 0);
2398 const char *zTag = db_column_text(&q, 1);
2399 char zLabel[30];
2400 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
2401 if( P(zLabel) ){
2402 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2403 }
2404 }
2405 db_finalize(&q);
2406 if( zHideFlag[0] ){
2407 db_multi_exec("REPLACE INTO newtags VALUES('hidden','*',NULL)");
2408 }
2409 if( zCloseFlag[0] ){
2410 db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2411 is_a_leaf(rid)?"+":"*");
2412 }
2413 if( zNewTagFlag[0] && zNewTag[0] ){
2414 db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
2415 }
2416 if( zNewBrFlag[0] && zNewBranch[0] ){
2417 db_multi_exec(
2418 "REPLACE INTO newtags "
2419 " SELECT tagname, '-', NULL FROM tagxref, tag"
2420 " WHERE tagxref.rid=%d AND tagtype==2"
2421 " AND tagname GLOB 'sym-*'"
2422 " AND tag.tagid=tagxref.tagid",
2423 rid
2424 );
2425 db_multi_exec("REPLACE INTO newtags VALUES('branch','*',%Q)", zNewBranch);
2426 db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','*',NULL)",
2427 zNewBranch);
2428 }
2429 db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
2430 " ORDER BY prefix || tag");
2431 while( db_step(&q)==SQLITE_ROW ){
2432 const char *zTag = db_column_text(&q, 0);
2433 const char *zPrefix = db_column_text(&q, 1);
2434 const char *zValue = db_column_text(&q, 2);
2435 nChng++;
2436 if( zValue ){
2437 blob_appendf(&ctrl, "T %s%F %s %F\n", zPrefix, zTag, zUuid, zValue);
2438 }else{
2439 blob_appendf(&ctrl, "T %s%F %s\n", zPrefix, zTag, zUuid);
2440 }
2441 }
2442 db_finalize(&q);
2443 if( nChng>0 ){
2444 int nrid;
2445 Blob cksum;
2446 blob_appendf(&ctrl, "U %F\n", login_name());
2447 md5sum_blob(&ctrl, &cksum);
2448 blob_appendf(&ctrl, "Z %b\n", &cksum);
2449 db_begin_transaction();
2450 g.markPrivate = content_is_private(rid);
2451 nrid = content_put(&ctrl);
2452 manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
2453 assert( blob_is_reset(&ctrl) );
2454 db_end_transaction(0);
2455 }
2456 cgi_redirectf("ci?name=%s", zUuid);
2457 }
2458 blob_zero(&comment);
2459 blob_append(&comment, zNewComment, -1);
2460 zUuid[10] = 0;
@@ -2652,5 +2710,212 @@
2652 @ </td></tr>
2653 @ </table>
2654 @ </div></form>
2655 style_footer();
2656 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2657
--- src/info.c
+++ src/info.c
@@ -1886,11 +1886,11 @@
1886 }
1887 if( descOnly ){
1888 style_submenu_element("Content", "Content", "%R/artifact/%s", zUuid);
1889 }else{
1890 style_submenu_element("Line Numbers", "Line Numbers",
1891 "%R/artifact/%s%s",zUuid,
1892 ((zLn&&*zLn) ? "" : "?txt=1&ln=0"));
1893 @ <hr />
1894 content_get(rid, &content);
1895 if( renderAsWiki ){
1896 wiki_render_by_mimetype(&content, zMime);
@@ -2276,10 +2276,133 @@
2276 }
2277 while( fossil_isspace(zB[0]) ) zB++;
2278 while( fossil_isspace(zA[0]) ) zA++;
2279 return zA[0]==0 && zB[0]==0;
2280 }
2281
2282 /*
2283 ** The following methods operate on the newtags temporary table
2284 ** that is used to collect various changes to be added to a control
2285 ** artifact for a check-in edit.
2286 */
2287 static void init_newtags(void){
2288 db_multi_exec("CREATE TEMP TABLE newtags(tag UNIQUE, prefix, value)");
2289 }
2290
2291 static void change_special(
2292 const char *zName, /* Name of the special tag */
2293 const char *zOp, /* Operation prefix (e.g. +,-,*) */
2294 const char *zValue /* Value of the tag */
2295 ){
2296 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'%q',%Q)", zName, zOp, zValue);
2297 }
2298
2299 static void change_sym_tag(const char *zTag, const char *zOp){
2300 db_multi_exec("REPLACE INTO newtags VALUES('sym-%q',%Q,NULL)", zTag, zOp);
2301 }
2302
2303 static void cancel_special(const char *zTag){
2304 change_special(zTag,"-",0);
2305 }
2306
2307 static void add_color(const char *zNewColor, int fPropagateColor){
2308 change_special("bgcolor",fPropagateColor ? "*" : "+", zNewColor);
2309 }
2310
2311 static void cancel_color(void){
2312 change_special("bgcolor","-",0);
2313 }
2314
2315 static void add_comment(const char *zNewComment){
2316 change_special("comment","+",zNewComment);
2317 }
2318
2319 static void add_date(const char *zNewDate){
2320 change_special("date","+",zNewDate);
2321 }
2322
2323 static void add_user(const char *zNewUser){
2324 change_special("user","+",zNewUser);
2325 }
2326
2327 static void add_tag(const char *zNewTag){
2328 change_sym_tag(zNewTag,"+");
2329 }
2330
2331 static void cancel_tag(int rid, const char *zCancelTag){
2332 if( db_exists("SELECT 1 FROM tagxref, tag"
2333 " WHERE tagxref.rid=%d AND tagtype>0"
2334 " AND tagxref.tagid=tag.tagid AND tagname='sym-%q'",
2335 rid, zCancelTag)
2336 ) change_sym_tag(zCancelTag,"-");
2337 }
2338
2339 static void hide_branch(void){
2340 change_special("hidden","*",0);
2341 }
2342
2343 static void close_leaf(int rid){
2344 change_special("closed",is_a_leaf(rid)?"+":"*",0);
2345 }
2346
2347 static void change_branch(int rid, const char *zNewBranch){
2348 db_multi_exec(
2349 "REPLACE INTO newtags "
2350 " SELECT tagname, '-', NULL FROM tagxref, tag"
2351 " WHERE tagxref.rid=%d AND tagtype==2"
2352 " AND tagname GLOB 'sym-*'"
2353 " AND tag.tagid=tagxref.tagid",
2354 rid
2355 );
2356 change_special("branch","*",zNewBranch);
2357 change_sym_tag(zNewBranch,"*");
2358 }
2359
2360 /*
2361 ** The apply_newtags method is called after all newtags have been added
2362 ** and the control artifact is completed and then written to the DB.
2363 */
2364 static void apply_newtags(Blob *ctrl, int rid, const char *zUuid){
2365 Stmt q;
2366 int nChng = 0;
2367
2368 db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
2369 " ORDER BY prefix || tag");
2370 while( db_step(&q)==SQLITE_ROW ){
2371 const char *zTag = db_column_text(&q, 0);
2372 const char *zPrefix = db_column_text(&q, 1);
2373 const char *zValue = db_column_text(&q, 2);
2374 nChng++;
2375 if( zValue ){
2376 blob_appendf(ctrl, "T %s%F %s %F\n", zPrefix, zTag, zUuid, zValue);
2377 }else{
2378 blob_appendf(ctrl, "T %s%F %s\n", zPrefix, zTag, zUuid);
2379 }
2380 }
2381 db_finalize(&q);
2382 if( nChng>0 ){
2383 int nrid;
2384 Blob cksum;
2385 blob_appendf(ctrl, "U %F\n", login_name());
2386 md5sum_blob(ctrl, &cksum);
2387 blob_appendf(ctrl, "Z %b\n", &cksum);
2388 db_begin_transaction();
2389 g.markPrivate = content_is_private(rid);
2390 nrid = content_put(ctrl);
2391 manifest_crosslink(nrid, ctrl, MC_PERMIT_HOOKS);
2392 assert( blob_is_reset(ctrl) );
2393 db_end_transaction(0);
2394 }
2395 }
2396
2397 /*
2398 ** This method checks that the date can be parsed.
2399 ** Returns 1 if datetime() can validate, 0 otherwise.
2400 */
2401 int is_datetime(const char* zDate){
2402 return db_int(0, "SELECT datetime(%Q) NOT NULL", zDate);
2403 }
2404
2405 /*
2406 ** WEBPAGE: ci_edit
2407 ** URL: /ci_edit?r=RID&c=NEWCOMMENT&u=NEWUSER
2408 **
@@ -2354,42 +2477,24 @@
2477 zCloseFlag = P("close") ? " checked" : "";
2478 zHideFlag = P("hide") ? " checked" : "";
2479 if( P("apply") ){
2480 Blob ctrl;
2481 char *zNow;
 
2482
2483 login_verify_csrf_secret();
2484 blob_zero(&ctrl);
2485 zNow = date_in_standard_format(zChngTime ? zChngTime : "now");
2486 blob_appendf(&ctrl, "D %s\n", zNow);
2487 init_newtags();
2488 if( zNewColor[0]
2489 && (fPropagateColor!=fNewPropagateColor
2490 || fossil_strcmp(zColor,zNewColor)!=0)
2491 ) add_color(zNewColor,fNewPropagateColor);
2492 if( zNewColor[0]==0 && zColor[0]!=0 ) cancel_color();
2493 if( comment_compare(zComment,zNewComment)==0 ) add_comment(zNewComment);
2494 if( fossil_strcmp(zDate,zNewDate)!=0 ) add_date(zNewDate);
2495 if( fossil_strcmp(zUser,zNewUser)!=0 ) add_user(zNewUser);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2496 db_prepare(&q,
2497 "SELECT tag.tagid, tagname FROM tagxref, tag"
2498 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid",
2499 rid
2500 );
@@ -2396,65 +2501,18 @@
2501 while( db_step(&q)==SQLITE_ROW ){
2502 int tagid = db_column_int(&q, 0);
2503 const char *zTag = db_column_text(&q, 1);
2504 char zLabel[30];
2505 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
2506 if( P(zLabel) ) cancel_special(zTag);
2507 }
2508 db_finalize(&q);
2509 if( zHideFlag[0] ) hide_branch();
2510 if( zCloseFlag[0] ) close_leaf(rid);
2511 if( zNewTagFlag[0] && zNewTag[0] ) add_tag(zNewTag);
2512 if( zNewBrFlag[0] && zNewBranch[0] ) change_branch(rid,zNewBranch);
2513 apply_newtags(&ctrl, rid, zUuid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2514 cgi_redirectf("ci?name=%s", zUuid);
2515 }
2516 blob_zero(&comment);
2517 blob_append(&comment, zNewComment, -1);
2518 zUuid[10] = 0;
@@ -2652,5 +2710,212 @@
2710 @ </td></tr>
2711 @ </table>
2712 @ </div></form>
2713 style_footer();
2714 }
2715
2716 /*
2717 ** Prepare an ammended commit comment. Let the user modify it using the
2718 ** editor specified in the global_config table or either
2719 ** the VISUAL or EDITOR environment variable.
2720 **
2721 ** Store the final commit comment in pComment. pComment is assumed
2722 ** to be uninitialized - any prior content is overwritten.
2723 **
2724 ** Use zInit to initialize the check-in comment so that the user does
2725 ** not have to retype.
2726 */
2727 static void prepare_amend_comment(
2728 Blob *pComment,
2729 const char *zInit,
2730 const char *zUuid
2731 ){
2732 Blob prompt;
2733 #if defined(_WIN32) || defined(__CYGWIN__)
2734 int bomSize;
2735 const unsigned char *bom = get_utf8_bom(&bomSize);
2736 blob_init(&prompt, (const char *) bom, bomSize);
2737 if( zInit && zInit[0]){
2738 blob_append(&prompt, zInit, -1);
2739 }
2740 #else
2741 blob_init(&prompt, zInit, -1);
2742 #endif
2743 blob_append(&prompt, "\n# Enter a new comment for check-in ", -1);
2744 if( zUuid && zUuid[0] ){
2745 blob_append(&prompt, zUuid, -1);
2746 }
2747 blob_append(&prompt, ".\n# Lines beginning with a # are ignored.\n", -1);
2748 prompt_for_user_comment(pComment, &prompt);
2749 blob_reset(&prompt);
2750 }
2751
2752 #define AMEND_USAGE_STMT "UUID OPTION ?OPTION ...?"
2753 /*
2754 ** COMMAND: amend
2755 **
2756 ** Usage: %fossil amend UUID OPTION ?OPTION ...?
2757 **
2758 ** Amend the tags on check-in UUID to change how it displays in the timeline.
2759 **
2760 ** Options:
2761 **
2762 ** --author USER Make USER the author for check-in
2763 ** -m|--comment COMMENT Make COMMENT the check-in comment
2764 ** -M|--message-file FILE Read the amended comment from FILE
2765 ** --edit-comment Launch editor to revise comment
2766 ** --date DATE Make DATE the check-in time
2767 ** --bgcolor COLOR Apply COLOR to this check-in
2768 ** --branchcolor COLOR Apply and propagate COLOR to the branch
2769 ** --tag TAG Add new TAG to this check-in
2770 ** --cancel TAG Cancel TAG from this check-in
2771 ** --branch NAME Make this check-in the start of branch NAME
2772 ** --hide Hide branch starting from this check-in
2773 ** --close Mark this "leaf" as closed
2774 */
2775 void ci_amend_cmd(void){
2776 int rid;
2777 const char *zComment; /* Current comment on the check-in */
2778 const char *zNewComment; /* Revised check-in comment */
2779 const char *zComFile; /* Filename from which to read comment */
2780 const char *zUser; /* Current user for the check-in */
2781 const char *zNewUser; /* Revised user */
2782 const char *zDate; /* Current date of the check-in */
2783 const char *zNewDate; /* Revised check-in date */
2784 const char *zColor;
2785 const char *zNewColor;
2786 const char *zNewBrColor;
2787 const char *zNewBranch;
2788 const char **pzNewTags = 0;
2789 const char **pzCancelTags = 0;
2790 int fClose; /* True if leaf should be closed */
2791 int fHide; /* True if branch should be hidden */
2792 int fPropagateColor; /* True if color propagates before amend */
2793 int fNewPropagateColor = 0; /* True if color propagates after amend */
2794 int fHasHidden = 0; /* True if hidden tag already set */
2795 int fHasClosed = 0; /* True if closed tag already set */
2796 int fEditComment; /* True if editor to be used for comment */
2797 const char *zChngTime; /* The change time on the control artifact */
2798 const char *zUuid;
2799 Blob ctrl;
2800 Blob comment;
2801 char *zNow;
2802 int nTags, nCancels;
2803 int i;
2804 Stmt q;
2805
2806 if( g.argc==3 ) usage(AMEND_USAGE_STMT);
2807 fEditComment = find_option("edit-comment",0,0)!=0;
2808 zNewComment = find_option("comment","m",1);
2809 zComFile = find_option("message-file","M",1);
2810 zNewBranch = find_option("branch",0,1);
2811 zNewColor = find_option("bgcolor",0,1);
2812 zNewBrColor = find_option("branchcolor",0,1);
2813 if( zNewBrColor ){
2814 zNewColor = zNewBrColor;
2815 fNewPropagateColor = 1;
2816 }
2817 zNewDate = find_option("date",0,1);
2818 zNewUser = find_option("author",0,1);
2819 pzNewTags = find_repeatable_option("tag",0,&nTags);
2820 pzCancelTags = find_repeatable_option("cancel",0,&nCancels);
2821 fClose = find_option("close",0,0)!=0;
2822 fHide = find_option("hide",0,0)!=0;
2823 zChngTime = find_option("chngtime",0,1);
2824 db_find_and_open_repository(0,0);
2825 user_select();
2826 verify_all_options();
2827 if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
2828 rid = name_to_typed_rid(g.argv[2], "ci");
2829 if( rid==0 && !is_a_version(rid) ) fossil_fatal("no such check-in");
2830 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
2831 if( zUuid==0 ) fossil_fatal("Unable to find UUID");
2832 zComment = db_text(0, "SELECT coalesce(ecomment,comment)"
2833 " FROM event WHERE objid=%d", rid);
2834 zUser = db_text(0, "SELECT coalesce(euser,user)"
2835 " FROM event WHERE objid=%d", rid);
2836 zDate = db_text(0, "SELECT datetime(mtime)"
2837 " FROM event WHERE objid=%d", rid);
2838 zColor = db_text("", "SELECT bgcolor"
2839 " FROM event WHERE objid=%d", rid);
2840 fPropagateColor = db_int(0, "SELECT tagtype FROM tagxref"
2841 " WHERE rid=%d AND tagid=%d",
2842 rid, TAG_BGCOLOR)==2;
2843 fNewPropagateColor = zNewColor && zNewColor[0]
2844 ? fNewPropagateColor : fPropagateColor;
2845 db_prepare(&q,
2846 "SELECT tag.tagid FROM tagxref, tag"
2847 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid",
2848 rid
2849 );
2850 while( db_step(&q)==SQLITE_ROW ){
2851 int tagid = db_column_int(&q, 0);
2852
2853 if( tagid == TAG_CLOSED ){
2854 fHasClosed = 1;
2855 }else if( tagid==TAG_HIDDEN ){
2856 fHasHidden = 1;
2857 }else{
2858 continue;
2859 }
2860 }
2861 db_finalize(&q);
2862 blob_zero(&ctrl);
2863 zNow = date_in_standard_format(zChngTime && zChngTime[0] ? zChngTime : "now");
2864 blob_appendf(&ctrl, "D %s\n", zNow);
2865 init_newtags();
2866 if( zNewColor && zNewColor[0]
2867 && (fPropagateColor!=fNewPropagateColor
2868 || fossil_strcmp(zColor,zNewColor)!=0)
2869 ){
2870 add_color(
2871 mprintf("%s%s", (zNewColor[0]!='#' &&
2872 validate16(zNewColor,strlen(zNewColor)) &&
2873 (strlen(zNewColor)==6 || strlen(zNewColor)==3)) ? "#" : "",
2874 zNewColor
2875 ),
2876 fNewPropagateColor
2877 );
2878 }
2879 if( (zNewColor!=0 && zNewColor[0]==0) && (zColor && zColor[0] ) ){
2880 cancel_color();
2881 }
2882 if( fEditComment ){
2883 prepare_amend_comment(&comment, zComment, zUuid);
2884 zNewComment = blob_str(&comment);
2885 }else if( zComFile ){
2886 blob_zero(&comment);
2887 blob_read_from_file(&comment, zComFile);
2888 blob_to_utf8_no_bom(&comment, 1);
2889 zNewComment = blob_str(&comment);
2890 }
2891 if( zNewComment && zNewComment[0]
2892 && comment_compare(zComment,zNewComment)==0 ) add_comment(zNewComment);
2893 if( zNewDate && zNewDate[0] && fossil_strcmp(zDate,zNewDate)!=0 ){
2894 if( is_datetime(zNewDate) ){
2895 add_date(zNewDate);
2896 }else{
2897 fossil_fatal("Unsupported date format, use YYYY-MM-DD HH:MM:SS");
2898 }
2899 }
2900 if( zNewUser && zNewUser[0] && fossil_strcmp(zUser,zNewUser)!=0 ){
2901 add_user(zNewUser);
2902 }
2903 if( pzNewTags!=0 ){
2904 for(i=0; i<nTags; i++){
2905 if( pzNewTags[i] && pzNewTags[i][0] ) add_tag(pzNewTags[i]);
2906 }
2907 fossil_free(pzNewTags);
2908 }
2909 if( pzCancelTags!=0 ){
2910 for(i=0; i<nCancels; i++){
2911 if( pzCancelTags[i] && pzCancelTags[i][0] )
2912 cancel_tag(rid,pzCancelTags[i]);
2913 }
2914 fossil_free(pzCancelTags);
2915 }
2916 if( fHide && !fHasHidden ) hide_branch();
2917 if( fClose && !fHasClosed ) close_leaf(rid);
2918 if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
2919 apply_newtags(&ctrl, rid, zUuid);
2920 show_common_info(rid, "uuid:", 1, 0);
2921 }
2922
+7 -7
--- src/linenoise.c
+++ src/linenoise.c
@@ -176,24 +176,24 @@
176176
static void refreshLine(struct linenoiseState *l);
177177
178178
/* Debugging macro. */
179179
#if 0
180180
FILE *lndebug_fp = NULL;
181
-#define lndebug(...) \
181
+#define lndebug(fmt, arg1) \
182182
do { \
183183
if (lndebug_fp == NULL) { \
184184
lndebug_fp = fopen("/tmp/lndebug.txt","a"); \
185185
fprintf(lndebug_fp, \
186186
"[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
187187
(int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
188188
(int)l->maxrows,old_rows); \
189189
} \
190
- fprintf(lndebug_fp, ", " __VA_ARGS__); \
190
+ fprintf(lndebug_fp, ", " fmt, arg1); \
191191
fflush(lndebug_fp); \
192192
} while (0)
193193
#else
194
-#define lndebug(fmt, ...)
194
+#define lndebug(fmt, arg1)
195195
#endif
196196
197197
/* ======================= Low level terminal handling ====================== */
198198
199199
/* Set if to use or not the multi line mode. */
@@ -526,17 +526,17 @@
526526
abAppend(&ab,seq,strlen(seq));
527527
}
528528
529529
/* Now for every row clear it, go up. */
530530
for (j = 0; j < old_rows-1; j++) {
531
- lndebug("clear+up");
531
+ lndebug("clear+up", 0);
532532
snprintf(seq,64,"\r\x1b[0K\x1b[1A");
533533
abAppend(&ab,seq,strlen(seq));
534534
}
535535
536536
/* Clean the top line. */
537
- lndebug("clear");
537
+ lndebug("clear", 0);
538538
snprintf(seq,64,"\r\x1b[0K");
539539
abAppend(&ab,seq,strlen(seq));
540540
541541
/* Write the prompt and the current buffer content */
542542
abAppend(&ab,l->prompt,strlen(l->prompt));
@@ -546,11 +546,11 @@
546546
* emit a newline and move the prompt to the first column. */
547547
if (l->pos &&
548548
l->pos == l->len &&
549549
(l->pos+plen) % l->cols == 0)
550550
{
551
- lndebug("<newline>");
551
+ lndebug("<newline>", 0);
552552
abAppend(&ab,"\n",1);
553553
snprintf(seq,64,"\r");
554554
abAppend(&ab,seq,strlen(seq));
555555
rows++;
556556
if (rows > (int)l->maxrows) l->maxrows = rows;
@@ -574,11 +574,11 @@
574574
snprintf(seq,64,"\r\x1b[%dC", col);
575575
else
576576
snprintf(seq,64,"\r");
577577
abAppend(&ab,seq,strlen(seq));
578578
579
- lndebug("\n");
579
+ lndebug("\n", 0);
580580
l->oldpos = l->pos;
581581
582582
if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
583583
abFree(&ab);
584584
}
585585
--- src/linenoise.c
+++ src/linenoise.c
@@ -176,24 +176,24 @@
176 static void refreshLine(struct linenoiseState *l);
177
178 /* Debugging macro. */
179 #if 0
180 FILE *lndebug_fp = NULL;
181 #define lndebug(...) \
182 do { \
183 if (lndebug_fp == NULL) { \
184 lndebug_fp = fopen("/tmp/lndebug.txt","a"); \
185 fprintf(lndebug_fp, \
186 "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
187 (int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
188 (int)l->maxrows,old_rows); \
189 } \
190 fprintf(lndebug_fp, ", " __VA_ARGS__); \
191 fflush(lndebug_fp); \
192 } while (0)
193 #else
194 #define lndebug(fmt, ...)
195 #endif
196
197 /* ======================= Low level terminal handling ====================== */
198
199 /* Set if to use or not the multi line mode. */
@@ -526,17 +526,17 @@
526 abAppend(&ab,seq,strlen(seq));
527 }
528
529 /* Now for every row clear it, go up. */
530 for (j = 0; j < old_rows-1; j++) {
531 lndebug("clear+up");
532 snprintf(seq,64,"\r\x1b[0K\x1b[1A");
533 abAppend(&ab,seq,strlen(seq));
534 }
535
536 /* Clean the top line. */
537 lndebug("clear");
538 snprintf(seq,64,"\r\x1b[0K");
539 abAppend(&ab,seq,strlen(seq));
540
541 /* Write the prompt and the current buffer content */
542 abAppend(&ab,l->prompt,strlen(l->prompt));
@@ -546,11 +546,11 @@
546 * emit a newline and move the prompt to the first column. */
547 if (l->pos &&
548 l->pos == l->len &&
549 (l->pos+plen) % l->cols == 0)
550 {
551 lndebug("<newline>");
552 abAppend(&ab,"\n",1);
553 snprintf(seq,64,"\r");
554 abAppend(&ab,seq,strlen(seq));
555 rows++;
556 if (rows > (int)l->maxrows) l->maxrows = rows;
@@ -574,11 +574,11 @@
574 snprintf(seq,64,"\r\x1b[%dC", col);
575 else
576 snprintf(seq,64,"\r");
577 abAppend(&ab,seq,strlen(seq));
578
579 lndebug("\n");
580 l->oldpos = l->pos;
581
582 if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
583 abFree(&ab);
584 }
585
--- src/linenoise.c
+++ src/linenoise.c
@@ -176,24 +176,24 @@
176 static void refreshLine(struct linenoiseState *l);
177
178 /* Debugging macro. */
179 #if 0
180 FILE *lndebug_fp = NULL;
181 #define lndebug(fmt, arg1) \
182 do { \
183 if (lndebug_fp == NULL) { \
184 lndebug_fp = fopen("/tmp/lndebug.txt","a"); \
185 fprintf(lndebug_fp, \
186 "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
187 (int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
188 (int)l->maxrows,old_rows); \
189 } \
190 fprintf(lndebug_fp, ", " fmt, arg1); \
191 fflush(lndebug_fp); \
192 } while (0)
193 #else
194 #define lndebug(fmt, arg1)
195 #endif
196
197 /* ======================= Low level terminal handling ====================== */
198
199 /* Set if to use or not the multi line mode. */
@@ -526,17 +526,17 @@
526 abAppend(&ab,seq,strlen(seq));
527 }
528
529 /* Now for every row clear it, go up. */
530 for (j = 0; j < old_rows-1; j++) {
531 lndebug("clear+up", 0);
532 snprintf(seq,64,"\r\x1b[0K\x1b[1A");
533 abAppend(&ab,seq,strlen(seq));
534 }
535
536 /* Clean the top line. */
537 lndebug("clear", 0);
538 snprintf(seq,64,"\r\x1b[0K");
539 abAppend(&ab,seq,strlen(seq));
540
541 /* Write the prompt and the current buffer content */
542 abAppend(&ab,l->prompt,strlen(l->prompt));
@@ -546,11 +546,11 @@
546 * emit a newline and move the prompt to the first column. */
547 if (l->pos &&
548 l->pos == l->len &&
549 (l->pos+plen) % l->cols == 0)
550 {
551 lndebug("<newline>", 0);
552 abAppend(&ab,"\n",1);
553 snprintf(seq,64,"\r");
554 abAppend(&ab,seq,strlen(seq));
555 rows++;
556 if (rows > (int)l->maxrows) l->maxrows = rows;
@@ -574,11 +574,11 @@
574 snprintf(seq,64,"\r\x1b[%dC", col);
575 else
576 snprintf(seq,64,"\r");
577 abAppend(&ab,seq,strlen(seq));
578
579 lndebug("\n", 0);
580 l->oldpos = l->pos;
581
582 if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
583 abFree(&ab);
584 }
585
+34
--- src/main.c
+++ src/main.c
@@ -876,10 +876,44 @@
876876
break;
877877
}
878878
}
879879
return zReturn;
880880
}
881
+
882
+/*
883
+** Look for multiple occurrences of a command-line option with the
884
+** corresponding argument.
885
+**
886
+** Return a malloc allocated array of pointers to the arguments.
887
+**
888
+** pnUsedArgs is used to store the number of matched arguments.
889
+**
890
+** Caller is responsible to free allocated memory.
891
+*/
892
+const char **find_repeatable_option(
893
+ const char *zLong,
894
+ const char *zShort,
895
+ int *pnUsedArgs
896
+){
897
+ const char *zOption;
898
+ const char **pzArgs = 0;
899
+ int nAllocArgs = 0;
900
+ int nUsedArgs = 0;
901
+
902
+ while( (zOption = find_option(zLong, zShort, 1))!=0 ){
903
+ if( pzArgs==0 && nAllocArgs==0 ){
904
+ nAllocArgs = 1;
905
+ pzArgs = fossil_malloc( nAllocArgs*sizeof(pzArgs[0]) );
906
+ }else if( nAllocArgs<=nUsedArgs ){
907
+ nAllocArgs = nAllocArgs*2;
908
+ pzArgs = fossil_realloc( pzArgs, nAllocArgs*sizeof(pzArgs[0]) );
909
+ }
910
+ pzArgs[nUsedArgs++] = zOption;
911
+ }
912
+ *pnUsedArgs = nUsedArgs;
913
+ return pzArgs;
914
+}
881915
882916
/*
883917
** Look for a repository command-line option. If present, [re-]cache it in
884918
** the global state and return the new pointer, freeing any previous value.
885919
** If absent and there is no cached value, return NULL.
886920
--- src/main.c
+++ src/main.c
@@ -876,10 +876,44 @@
876 break;
877 }
878 }
879 return zReturn;
880 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
881
882 /*
883 ** Look for a repository command-line option. If present, [re-]cache it in
884 ** the global state and return the new pointer, freeing any previous value.
885 ** If absent and there is no cached value, return NULL.
886
--- src/main.c
+++ src/main.c
@@ -876,10 +876,44 @@
876 break;
877 }
878 }
879 return zReturn;
880 }
881
882 /*
883 ** Look for multiple occurrences of a command-line option with the
884 ** corresponding argument.
885 **
886 ** Return a malloc allocated array of pointers to the arguments.
887 **
888 ** pnUsedArgs is used to store the number of matched arguments.
889 **
890 ** Caller is responsible to free allocated memory.
891 */
892 const char **find_repeatable_option(
893 const char *zLong,
894 const char *zShort,
895 int *pnUsedArgs
896 ){
897 const char *zOption;
898 const char **pzArgs = 0;
899 int nAllocArgs = 0;
900 int nUsedArgs = 0;
901
902 while( (zOption = find_option(zLong, zShort, 1))!=0 ){
903 if( pzArgs==0 && nAllocArgs==0 ){
904 nAllocArgs = 1;
905 pzArgs = fossil_malloc( nAllocArgs*sizeof(pzArgs[0]) );
906 }else if( nAllocArgs<=nUsedArgs ){
907 nAllocArgs = nAllocArgs*2;
908 pzArgs = fossil_realloc( pzArgs, nAllocArgs*sizeof(pzArgs[0]) );
909 }
910 pzArgs[nUsedArgs++] = zOption;
911 }
912 *pnUsedArgs = nUsedArgs;
913 return pzArgs;
914 }
915
916 /*
917 ** Look for a repository command-line option. If present, [re-]cache it in
918 ** the global state and return the new pointer, freeing any previous value.
919 ** If absent and there is no cached value, return NULL.
920
+5 -5
--- src/merge.c
+++ src/merge.c
@@ -592,11 +592,11 @@
592592
}
593593
if( islinkv || islinkm /* || file_wd_islink(zFullPath) */ ){
594594
fossil_print("***** Cannot merge symlink %s\n", zName);
595595
nConflict++;
596596
}else{
597
- undo_save(zName);
597
+ if( !dryRunFlag ) undo_save(zName);
598598
zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
599599
content_get(ridp, &p);
600600
content_get(ridm, &m);
601601
if( isBinary ){
602602
rc = -1;
@@ -643,11 +643,11 @@
643643
fossil_print("DELETE %s\n", zName);
644644
if( chnged ){
645645
fossil_warning("WARNING: local edits lost for %s\n", zName);
646646
nConflict++;
647647
}
648
- undo_save(zName);
648
+ if( !dryRunFlag ) undo_save(zName);
649649
db_multi_exec(
650650
"UPDATE vfile SET deleted=1 WHERE id=%d", idv
651651
);
652652
if( !dryRunFlag ){
653653
char *zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
@@ -669,12 +669,12 @@
669669
while( db_step(&q)==SQLITE_ROW ){
670670
int idv = db_column_int(&q, 0);
671671
const char *zOldName = db_column_text(&q, 1);
672672
const char *zNewName = db_column_text(&q, 2);
673673
fossil_print("RENAME %s -> %s\n", zOldName, zNewName);
674
- undo_save(zOldName);
675
- undo_save(zNewName);
674
+ if( !dryRunFlag ) undo_save(zOldName);
675
+ if( !dryRunFlag ) undo_save(zNewName);
676676
db_multi_exec(
677677
"UPDATE vfile SET pathname=%Q, origname=coalesce(origname,pathname)"
678678
" WHERE id=%d AND vid=%d", zNewName, idv, vid
679679
);
680680
if( !dryRunFlag ){
@@ -726,8 +726,8 @@
726726
}else if( integrateFlag ){
727727
db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(-4,%d)",mid);
728728
}else{
729729
db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(0,%d)", mid);
730730
}
731
- undo_finish();
731
+ if( !dryRunFlag ) undo_finish();
732732
db_end_transaction(dryRunFlag);
733733
}
734734
--- src/merge.c
+++ src/merge.c
@@ -592,11 +592,11 @@
592 }
593 if( islinkv || islinkm /* || file_wd_islink(zFullPath) */ ){
594 fossil_print("***** Cannot merge symlink %s\n", zName);
595 nConflict++;
596 }else{
597 undo_save(zName);
598 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
599 content_get(ridp, &p);
600 content_get(ridm, &m);
601 if( isBinary ){
602 rc = -1;
@@ -643,11 +643,11 @@
643 fossil_print("DELETE %s\n", zName);
644 if( chnged ){
645 fossil_warning("WARNING: local edits lost for %s\n", zName);
646 nConflict++;
647 }
648 undo_save(zName);
649 db_multi_exec(
650 "UPDATE vfile SET deleted=1 WHERE id=%d", idv
651 );
652 if( !dryRunFlag ){
653 char *zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
@@ -669,12 +669,12 @@
669 while( db_step(&q)==SQLITE_ROW ){
670 int idv = db_column_int(&q, 0);
671 const char *zOldName = db_column_text(&q, 1);
672 const char *zNewName = db_column_text(&q, 2);
673 fossil_print("RENAME %s -> %s\n", zOldName, zNewName);
674 undo_save(zOldName);
675 undo_save(zNewName);
676 db_multi_exec(
677 "UPDATE vfile SET pathname=%Q, origname=coalesce(origname,pathname)"
678 " WHERE id=%d AND vid=%d", zNewName, idv, vid
679 );
680 if( !dryRunFlag ){
@@ -726,8 +726,8 @@
726 }else if( integrateFlag ){
727 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(-4,%d)",mid);
728 }else{
729 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(0,%d)", mid);
730 }
731 undo_finish();
732 db_end_transaction(dryRunFlag);
733 }
734
--- src/merge.c
+++ src/merge.c
@@ -592,11 +592,11 @@
592 }
593 if( islinkv || islinkm /* || file_wd_islink(zFullPath) */ ){
594 fossil_print("***** Cannot merge symlink %s\n", zName);
595 nConflict++;
596 }else{
597 if( !dryRunFlag ) undo_save(zName);
598 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
599 content_get(ridp, &p);
600 content_get(ridm, &m);
601 if( isBinary ){
602 rc = -1;
@@ -643,11 +643,11 @@
643 fossil_print("DELETE %s\n", zName);
644 if( chnged ){
645 fossil_warning("WARNING: local edits lost for %s\n", zName);
646 nConflict++;
647 }
648 if( !dryRunFlag ) undo_save(zName);
649 db_multi_exec(
650 "UPDATE vfile SET deleted=1 WHERE id=%d", idv
651 );
652 if( !dryRunFlag ){
653 char *zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
@@ -669,12 +669,12 @@
669 while( db_step(&q)==SQLITE_ROW ){
670 int idv = db_column_int(&q, 0);
671 const char *zOldName = db_column_text(&q, 1);
672 const char *zNewName = db_column_text(&q, 2);
673 fossil_print("RENAME %s -> %s\n", zOldName, zNewName);
674 if( !dryRunFlag ) undo_save(zOldName);
675 if( !dryRunFlag ) undo_save(zNewName);
676 db_multi_exec(
677 "UPDATE vfile SET pathname=%Q, origname=coalesce(origname,pathname)"
678 " WHERE id=%d AND vid=%d", zNewName, idv, vid
679 );
680 if( !dryRunFlag ){
@@ -726,8 +726,8 @@
726 }else if( integrateFlag ){
727 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(-4,%d)",mid);
728 }else{
729 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(0,%d)", mid);
730 }
731 if( !dryRunFlag ) undo_finish();
732 db_end_transaction(dryRunFlag);
733 }
734
+2 -1
--- src/setup.c
+++ src/setup.c
@@ -1472,11 +1472,12 @@
14721472
}
14731473
}
14741474
@ </td></tr></table>
14751475
@ </div></form>
14761476
@ <p>Settings marked with (v) are 'versionable' and will be overridden
1477
- @ by the contents of files named <tt>.fossil-settings/PROPERTY</tt>.
1477
+ @ by the contents of files named <tt>.fossil-settings/PROPERTY</tt>
1478
+ @ in the check-out root.
14781479
@ If such a file is present, the corresponding field above is not
14791480
@ editable.</p><hr /><p>
14801481
@ These settings work in the same way, as the <kbd>set</kbd>
14811482
@ commandline:<br />
14821483
@ </p><pre>%s(zHelp_setting_cmd)</pre>
14831484
--- src/setup.c
+++ src/setup.c
@@ -1472,11 +1472,12 @@
1472 }
1473 }
1474 @ </td></tr></table>
1475 @ </div></form>
1476 @ <p>Settings marked with (v) are 'versionable' and will be overridden
1477 @ by the contents of files named <tt>.fossil-settings/PROPERTY</tt>.
 
1478 @ If such a file is present, the corresponding field above is not
1479 @ editable.</p><hr /><p>
1480 @ These settings work in the same way, as the <kbd>set</kbd>
1481 @ commandline:<br />
1482 @ </p><pre>%s(zHelp_setting_cmd)</pre>
1483
--- src/setup.c
+++ src/setup.c
@@ -1472,11 +1472,12 @@
1472 }
1473 }
1474 @ </td></tr></table>
1475 @ </div></form>
1476 @ <p>Settings marked with (v) are 'versionable' and will be overridden
1477 @ by the contents of files named <tt>.fossil-settings/PROPERTY</tt>
1478 @ in the check-out root.
1479 @ If such a file is present, the corresponding field above is not
1480 @ editable.</p><hr /><p>
1481 @ These settings work in the same way, as the <kbd>set</kbd>
1482 @ commandline:<br />
1483 @ </p><pre>%s(zHelp_setting_cmd)</pre>
1484
--- src/shell.c
+++ src/shell.c
@@ -1316,10 +1316,12 @@
13161316
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
13171317
fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
13181318
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
13191319
fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
13201320
}
1321
+
1322
+ /* Do not remove this machine readable comment: extra-stats-output-here */
13211323
13221324
return 0;
13231325
}
13241326
13251327
/*
13261328
--- src/shell.c
+++ src/shell.c
@@ -1316,10 +1316,12 @@
1316 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1317 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1318 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1319 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1320 }
 
 
1321
1322 return 0;
1323 }
1324
1325 /*
1326
--- src/shell.c
+++ src/shell.c
@@ -1316,10 +1316,12 @@
1316 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1317 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1318 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1319 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1320 }
1321
1322 /* Do not remove this machine readable comment: extra-stats-output-here */
1323
1324 return 0;
1325 }
1326
1327 /*
1328
+1308 -1062
--- 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.11. By combining all the individual C code files into this
3
+** version 3.8.11.1. 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.
@@ -323,13 +323,13 @@
323323
**
324324
** See also: [sqlite3_libversion()],
325325
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326326
** [sqlite_version()] and [sqlite_source_id()].
327327
*/
328
-#define SQLITE_VERSION "3.8.11"
328
+#define SQLITE_VERSION "3.8.11.1"
329329
#define SQLITE_VERSION_NUMBER 3008011
330
-#define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
330
+#define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
331331
332332
/*
333333
** CAPI3REF: Run-Time Library Version Numbers
334334
** KEYWORDS: sqlite3_version, sqlite3_sourceid
335335
**
@@ -1179,13 +1179,13 @@
11791179
**
11801180
** <li>[[SQLITE_FCNTL_ZIPVFS]]
11811181
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
11821182
** VFS should return SQLITE_NOTFOUND for this opcode.
11831183
**
1184
-** <li>[[SQLITE_FCNTL_OTA]]
1185
-** The [SQLITE_FCNTL_OTA] opcode is implemented by the special VFS used by
1186
-** the OTA extension only. All other VFS should return SQLITE_NOTFOUND for
1184
+** <li>[[SQLITE_FCNTL_RBU]]
1185
+** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1186
+** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
11871187
** this opcode.
11881188
** </ul>
11891189
*/
11901190
#define SQLITE_FCNTL_LOCKSTATE 1
11911191
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -1209,11 +1209,11 @@
12091209
#define SQLITE_FCNTL_SYNC 21
12101210
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
12111211
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
12121212
#define SQLITE_FCNTL_WAL_BLOCK 24
12131213
#define SQLITE_FCNTL_ZIPVFS 25
1214
-#define SQLITE_FCNTL_OTA 26
1214
+#define SQLITE_FCNTL_RBU 26
12151215
12161216
/* deprecated names */
12171217
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
12181218
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
12191219
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3774,10 +3774,11 @@
37743774
SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
37753775
SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
37763776
void(*)(void*), unsigned char encoding);
37773777
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
37783778
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3779
+SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
37793780
37803781
/*
37813782
** CAPI3REF: Number Of SQL Parameters
37823783
** METHOD: sqlite3_stmt
37833784
**
@@ -4746,13 +4747,13 @@
47464747
** ^The sqlite3_result_blob() interface sets the result from
47474748
** an application-defined function to be the BLOB whose content is pointed
47484749
** to by the second parameter and which is N bytes long where N is the
47494750
** third parameter.
47504751
**
4751
-** ^The sqlite3_result_zeroblob() interfaces set the result of
4752
-** the application-defined function to be a BLOB containing all zero
4753
-** bytes and N bytes in size, where N is the value of the 2nd parameter.
4752
+** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
4753
+** interfaces set the result of the application-defined function to be
4754
+** a BLOB containing all zero bytes and N bytes in size.
47544755
**
47554756
** ^The sqlite3_result_double() interface sets the result from
47564757
** an application-defined function to be a floating point value specified
47574758
** by its 2nd argument.
47584759
**
@@ -4863,10 +4864,11 @@
48634864
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
48644865
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
48654866
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
48664867
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
48674868
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4869
+SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
48684870
48694871
/*
48704872
** CAPI3REF: Define New Collating Sequences
48714873
** METHOD: sqlite3
48724874
**
@@ -8362,13 +8364,17 @@
83628364
/*
83638365
** Make sure that the compiler intrinsics we desire are enabled when
83648366
** compiling with an appropriate version of MSVC.
83658367
*/
83668368
#if defined(_MSC_VER) && _MSC_VER>=1300
8367
-# include <intrin.h>
8368
-# pragma intrinsic(_byteswap_ushort)
8369
-# pragma intrinsic(_byteswap_ulong)
8369
+# if !defined(_WIN32_WCE)
8370
+# include <intrin.h>
8371
+# pragma intrinsic(_byteswap_ushort)
8372
+# pragma intrinsic(_byteswap_ulong)
8373
+# else
8374
+# include <cmnintrin.h>
8375
+# endif
83708376
#endif
83718377
83728378
/*
83738379
** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
83748380
** 0 means mutexes are permanently disable and the library is never
@@ -9189,11 +9195,13 @@
91899195
#endif
91909196
#ifndef SQLITE_MAX_MMAP_SIZE
91919197
# if defined(__linux__) \
91929198
|| defined(_WIN32) \
91939199
|| (defined(__APPLE__) && defined(__MACH__)) \
9194
- || defined(__sun)
9200
+ || defined(__sun) \
9201
+ || defined(__FreeBSD__) \
9202
+ || defined(__DragonFly__)
91959203
# define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
91969204
# else
91979205
# define SQLITE_MAX_MMAP_SIZE 0
91989206
# endif
91999207
# define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */
@@ -13883,10 +13891,11 @@
1388313891
**
1388413892
*************************************************************************
1388513893
**
1388613894
** This file contains definitions of global variables and constants.
1388713895
*/
13896
+/* #include "sqliteInt.h" */
1388813897
1388913898
/* An array to map all upper-case characters into their corresponding
1389013899
** lower-case character.
1389113900
**
1389213901
** SQLite only considers US-ASCII (or EBCDIC) characters. We do not
@@ -14122,10 +14131,11 @@
1412214131
*/
1412314132
#ifndef SQLITE_OMIT_WSD
1412414133
SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
1412514134
#endif
1412614135
14136
+/* #include "opcodes.h" */
1412714137
/*
1412814138
** Properties of opcodes. The OPFLG_INITIALIZER macro is
1412914139
** created by mkopcodeh.awk during compilation. Data is obtained
1413014140
** from the comments following the "case OP_xxxx:" statements in
1413114141
** the vdbe.c file.
@@ -14150,10 +14160,11 @@
1415014160
** SQLite was built with.
1415114161
*/
1415214162
1415314163
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
1415414164
14165
+/* #include "sqliteInt.h" */
1415514166
1415614167
/*
1415714168
** An array of names of all compile-time options. This array should
1415814169
** be sorted A-Z.
1415914170
**
@@ -14579,10 +14590,11 @@
1457914590
*************************************************************************
1458014591
**
1458114592
** This module implements the sqlite3_status() interface and related
1458214593
** functionality.
1458314594
*/
14595
+/* #include "sqliteInt.h" */
1458414596
/************** Include vdbeInt.h in the middle of status.c ******************/
1458514597
/************** Begin file vdbeInt.h *****************************************/
1458614598
/*
1458714599
** 2003 September 6
1458814600
**
@@ -15462,10 +15474,11 @@
1546215474
** Astronomical Algorithms, 2nd Edition, 1998
1546315475
** ISBM 0-943396-61-1
1546415476
** Willmann-Bell, Inc
1546515477
** Richmond, Virginia (USA)
1546615478
*/
15479
+/* #include "sqliteInt.h" */
1546715480
/* #include <stdlib.h> */
1546815481
/* #include <assert.h> */
1546915482
#include <time.h>
1547015483
1547115484
#ifndef SQLITE_OMIT_DATETIME_FUNCS
@@ -15773,11 +15786,11 @@
1577315786
Z = (int)((p->iJD + 43200000)/86400000);
1577415787
A = (int)((Z - 1867216.25)/36524.25);
1577515788
A = Z + 1 + A - (A/4);
1577615789
B = A + 1524;
1577715790
C = (int)((B - 122.1)/365.25);
15778
- D = (36525*C)/100;
15791
+ D = (36525*(C&32767))/100;
1577915792
E = (int)((B-D)/30.6001);
1578015793
X1 = (int)(30.6001*E);
1578115794
p->D = B - D - X1;
1578215795
p->M = E<14 ? E-1 : E-13;
1578315796
p->Y = p->M>2 ? C - 4716 : C - 4715;
@@ -16574,10 +16587,11 @@
1657416587
**
1657516588
** This file contains OS interface code that is common to all
1657616589
** architectures.
1657716590
*/
1657816591
#define _SQLITE_OS_C_ 1
16592
+/* #include "sqliteInt.h" */
1657916593
#undef _SQLITE_OS_C_
1658016594
1658116595
/*
1658216596
** The default SQLite sqlite3_vfs implementations do not allocate
1658316597
** memory (actually, os_unix.c allocates a small amount of memory
@@ -16980,10 +16994,11 @@
1698016994
** is completely recoverable simply by not carrying out the resize. The
1698116995
** hash table will continue to function normally. So a malloc failure
1698216996
** during a hash table resize is a benign fault.
1698316997
*/
1698416998
16999
+/* #include "sqliteInt.h" */
1698517000
1698617001
#ifndef SQLITE_OMIT_BUILTIN_TEST
1698717002
1698817003
/*
1698917004
** Global variables.
@@ -17061,10 +17076,11 @@
1706117076
** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented
1706217077
** here always fail. SQLite will not operate with these drivers. These
1706317078
** are merely placeholders. Real drivers must be substituted using
1706417079
** sqlite3_config() before SQLite will operate.
1706517080
*/
17081
+/* #include "sqliteInt.h" */
1706617082
1706717083
/*
1706817084
** This version of the memory allocator is the default. It is
1706917085
** used when no other memory allocator is specified using compile-time
1707017086
** macros.
@@ -17147,10 +17163,11 @@
1714717163
** SQLITE_WITHOUT_MSIZE Set this symbol to disable the use of
1714817164
** _msize() on windows systems. This might
1714917165
** be necessary when compiling for Delphi,
1715017166
** for example.
1715117167
*/
17168
+/* #include "sqliteInt.h" */
1715217169
1715317170
/*
1715417171
** This version of the memory allocator is the default. It is
1715517172
** used when no other memory allocator is specified using compile-time
1715617173
** macros.
@@ -17422,10 +17439,11 @@
1742217439
** leaks and memory usage errors.
1742317440
**
1742417441
** This file contains implementations of the low-level memory allocation
1742517442
** routines specified in the sqlite3_mem_methods object.
1742617443
*/
17444
+/* #include "sqliteInt.h" */
1742717445
1742817446
/*
1742917447
** This version of the memory allocator is used only if the
1743017448
** SQLITE_MEMDEBUG macro is defined
1743117449
*/
@@ -17956,10 +17974,11 @@
1795617974
** be changed.
1795717975
**
1795817976
** This version of the memory allocation subsystem is included
1795917977
** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
1796017978
*/
17979
+/* #include "sqliteInt.h" */
1796117980
1796217981
/*
1796317982
** This version of the memory allocator is only built into the library
1796417983
** SQLITE_ENABLE_MEMSYS3 is defined. Defining this symbol does not
1796517984
** mean that the library will use a memory-pool by default, just that
@@ -18670,10 +18689,11 @@
1867018689
** N >= M*(1 + log2(n)/2) - n + 1
1867118690
**
1867218691
** The sqlite3_status() logic tracks the maximum values of n and M so
1867318692
** that an application can, at any time, verify this constraint.
1867418693
*/
18694
+/* #include "sqliteInt.h" */
1867518695
1867618696
/*
1867718697
** This version of the memory allocator is used only when
1867818698
** SQLITE_ENABLE_MEMSYS5 is defined.
1867918699
*/
@@ -19213,10 +19233,11 @@
1921319233
*************************************************************************
1921419234
** This file contains the C functions that implement mutexes.
1921519235
**
1921619236
** This file contains code that is common across all mutex implementations.
1921719237
*/
19238
+/* #include "sqliteInt.h" */
1921819239
1921919240
#if defined(SQLITE_DEBUG) && !defined(SQLITE_MUTEX_OMIT)
1922019241
/*
1922119242
** For debugging purposes, record when the mutex subsystem is initialized
1922219243
** and uninitialized so that we can assert() if there is an attempt to
@@ -19386,10 +19407,11 @@
1938619407
**
1938719408
** If compiled with SQLITE_DEBUG, then additional logic is inserted
1938819409
** that does error checking on mutexes to make sure they are being
1938919410
** called correctly.
1939019411
*/
19412
+/* #include "sqliteInt.h" */
1939119413
1939219414
#ifndef SQLITE_MUTEX_OMIT
1939319415
1939419416
#ifndef SQLITE_DEBUG
1939519417
/*
@@ -19589,10 +19611,11 @@
1958919611
** May you share freely, never taking more than you give.
1959019612
**
1959119613
*************************************************************************
1959219614
** This file contains the C functions that implement mutexes for pthreads
1959319615
*/
19616
+/* #include "sqliteInt.h" */
1959419617
1959519618
/*
1959619619
** The code in this file is only used if we are compiling threadsafe
1959719620
** under unix with pthreads.
1959819621
**
@@ -19963,10 +19986,11 @@
1996319986
** May you share freely, never taking more than you give.
1996419987
**
1996519988
*************************************************************************
1996619989
** This file contains the C functions that implement mutexes for Win32.
1996719990
*/
19991
+/* #include "sqliteInt.h" */
1996819992
1996919993
#if SQLITE_OS_WIN
1997019994
/*
1997119995
** Include code that is common to all os_*.c files
1997219996
*/
@@ -20638,10 +20662,11 @@
2063820662
**
2063920663
*************************************************************************
2064020664
**
2064120665
** Memory allocation functions used throughout sqlite.
2064220666
*/
20667
+/* #include "sqliteInt.h" */
2064320668
/* #include <stdarg.h> */
2064420669
2064520670
/*
2064620671
** Attempt to release up to n bytes of non-essential memory currently
2064720672
** held by SQLite. An example of non-essential memory is memory used to
@@ -21449,10 +21474,11 @@
2144921474
** This file contains code for a set of "printf"-like routines. These
2145021475
** routines format strings much like the printf() from the standard C
2145121476
** library, though the implementation here has enhancements to support
2145221477
** SQLite.
2145321478
*/
21479
+/* #include "sqliteInt.h" */
2145421480
2145521481
/*
2145621482
** Conversion types fall into various categories as defined by the
2145721483
** following enumeration.
2145821484
*/
@@ -22451,10 +22477,15 @@
2245122477
** stack space on small-stack systems when logging is disabled.
2245222478
**
2245322479
** sqlite3_log() must render into a static buffer. It cannot dynamically
2245422480
** allocate memory because it might be called while the memory allocator
2245522481
** mutex is held.
22482
+**
22483
+** sqlite3VXPrintf() might ask for *temporary* memory allocations for
22484
+** certain format characters (%q) or for very large precisions or widths.
22485
+** Care must be taken that any sqlite3_log() calls that occur while the
22486
+** memory mutex is held do not use these mechanisms.
2245622487
*/
2245722488
static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
2245822489
StrAccum acc; /* String accumulator */
2245922490
char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
2246022491
@@ -22526,10 +22557,11 @@
2252622557
** analysis.
2252722558
**
2252822559
** The interfaces in this file is only available when compiling
2252922560
** with SQLITE_DEBUG.
2253022561
*/
22562
+/* #include "sqliteInt.h" */
2253122563
#ifdef SQLITE_DEBUG
2253222564
2253322565
/*
2253422566
** Add a new subitem to the tree. The moreToFollow flag indicates that this
2253522567
** is not the last item in the tree.
@@ -22957,10 +22989,11 @@
2295722989
** generator (PRNG) for SQLite.
2295822990
**
2295922991
** Random numbers are used by some of the database backends in order
2296022992
** to generate random integer keys for tables or random filenames.
2296122993
*/
22994
+/* #include "sqliteInt.h" */
2296222995
2296322996
2296422997
/* All threads share a single random number generator.
2296522998
** This structure is the current state of the generator.
2296622999
*/
@@ -23103,11 +23136,13 @@
2310323136
** single threaded systems. Nothing in SQLite requires multiple threads.
2310423137
** This interface exists so that applications that want to take advantage
2310523138
** of multiple cores can do so, while also allowing applications to stay
2310623139
** single-threaded if desired.
2310723140
*/
23141
+/* #include "sqliteInt.h" */
2310823142
#if SQLITE_OS_WIN
23143
+/* # include "os_win.h" */
2310923144
#endif
2311023145
2311123146
#if SQLITE_MAX_WORKER_THREADS>0
2311223147
2311323148
/********************************* Unix Pthreads ****************************/
@@ -23377,11 +23412,13 @@
2337723412
** BOM or Byte Order Mark:
2337823413
** 0xff 0xfe little-endian utf-16 follows
2337923414
** 0xfe 0xff big-endian utf-16 follows
2338023415
**
2338123416
*/
23417
+/* #include "sqliteInt.h" */
2338223418
/* #include <assert.h> */
23419
+/* #include "vdbeInt.h" */
2338323420
2338423421
#ifndef SQLITE_AMALGAMATION
2338523422
/*
2338623423
** The following constant value is used by the SQLITE_BIGENDIAN and
2338723424
** SQLITE_LITTLEENDIAN macros.
@@ -23890,10 +23927,11 @@
2389023927
**
2389123928
** This file contains functions for allocating memory, comparing
2389223929
** strings, and stuff like that.
2389323930
**
2389423931
*/
23932
+/* #include "sqliteInt.h" */
2389523933
/* #include <stdarg.h> */
2389623934
#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
2389723935
# include <math.h>
2389823936
#endif
2389923937
@@ -25286,10 +25324,11 @@
2528625324
**
2528725325
*************************************************************************
2528825326
** This is the implementation of generic hash-tables
2528925327
** used in SQLite.
2529025328
*/
25329
+/* #include "sqliteInt.h" */
2529125330
/* #include <assert.h> */
2529225331
2529325332
/* Turn bulk memory into a hash table object by initializing the
2529425333
** fields of the Hash structure.
2529525334
**
@@ -25763,10 +25802,11 @@
2576325802
** * sqlite3_vfs method implementations.
2576425803
** * Locking primitives for the proxy uber-locking-method. (MacOSX only)
2576525804
** * Definitions of sqlite3_vfs objects for all locking methods
2576625805
** plus implementations of sqlite3_os_init() and sqlite3_os_end().
2576725806
*/
25807
+/* #include "sqliteInt.h" */
2576825808
#if SQLITE_OS_UNIX /* This file is used on unix only */
2576925809
2577025810
/*
2577125811
** There are various methods for file locking used for concurrency
2577225812
** control:
@@ -33497,10 +33537,11 @@
3349733537
**
3349833538
******************************************************************************
3349933539
**
3350033540
** This file contains code that is specific to Windows.
3350133541
*/
33542
+/* #include "sqliteInt.h" */
3350233543
#if SQLITE_OS_WIN /* This file is used for Windows only */
3350333544
3350433545
/*
3350533546
** Include code that is common to all os_*.c files
3350633547
*/
@@ -33705,10 +33746,11 @@
3370533746
/************** Continuing where we left off in os_win.c *********************/
3370633747
3370733748
/*
3370833749
** Include the header file for the Windows VFS.
3370933750
*/
33751
+/* #include "os_win.h" */
3371033752
3371133753
/*
3371233754
** Compiling and using WAL mode requires several APIs that are only
3371333755
** available in Windows platforms based on the NT kernel.
3371433756
*/
@@ -39358,10 +39400,11 @@
3935839400
** sometimes grow into tens of thousands or larger. The size of the
3935939401
** Bitvec object is the number of pages in the database file at the
3936039402
** start of a transaction, and is thus usually less than a few thousand,
3936139403
** but can be as large as 2 billion for a really big database.
3936239404
*/
39405
+/* #include "sqliteInt.h" */
3936339406
3936439407
/* Size of the Bitvec structure in bytes. */
3936539408
#define BITVEC_SZ 512
3936639409
3936739410
/* Round the union size down to the nearest pointer boundary, since that's how
@@ -39747,10 +39790,11 @@
3974739790
** May you share freely, never taking more than you give.
3974839791
**
3974939792
*************************************************************************
3975039793
** This file implements that page cache.
3975139794
*/
39795
+/* #include "sqliteInt.h" */
3975239796
3975339797
/*
3975439798
** A complete page cache is an instance of this structure.
3975539799
*/
3975639800
struct PCache {
@@ -40488,10 +40532,11 @@
4048840532
**
4048940533
** Earlier versions of SQLite used only methods (1) and (2). But experiments
4049040534
** show that method (3) with N==100 provides about a 5% performance boost for
4049140535
** common workloads.
4049240536
*/
40537
+/* #include "sqliteInt.h" */
4049340538
4049440539
typedef struct PCache1 PCache1;
4049540540
typedef struct PgHdr1 PgHdr1;
4049640541
typedef struct PgFreeslot PgFreeslot;
4049740542
typedef struct PGroup PGroup;
@@ -40598,10 +40643,11 @@
4059840643
** fixed at sqlite3_initialize() time and do not require mutex protection.
4059940644
** The nFreeSlot and pFree values do require mutex protection.
4060040645
*/
4060140646
int isInit; /* True if initialized */
4060240647
int separateCache; /* Use a new PGroup for each PCache */
40648
+ int nInitPage; /* Initial bulk allocation size */
4060340649
int szSlot; /* Size of each free slot */
4060440650
int nSlot; /* The number of pcache slots */
4060540651
int nReserve; /* Try to keep nFreeSlot above this */
4060640652
void *pStart, *pEnd; /* Bounds of global page cache memory */
4060740653
/* Above requires no mutex. Use mutex below for variable that follow. */
@@ -40665,10 +40711,47 @@
4066540711
pBuf = (void*)&((char*)pBuf)[sz];
4066640712
}
4066740713
pcache1.pEnd = pBuf;
4066840714
}
4066940715
}
40716
+
40717
+/*
40718
+** Try to initialize the pCache->pFree and pCache->pBulk fields. Return
40719
+** true if pCache->pFree ends up containing one or more free pages.
40720
+*/
40721
+static int pcache1InitBulk(PCache1 *pCache){
40722
+ i64 szBulk;
40723
+ char *zBulk;
40724
+ if( pcache1.nInitPage==0 ) return 0;
40725
+ /* Do not bother with a bulk allocation if the cache size very small */
40726
+ if( pCache->nMax<3 ) return 0;
40727
+ sqlite3BeginBenignMalloc();
40728
+ if( pcache1.nInitPage>0 ){
40729
+ szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
40730
+ }else{
40731
+ szBulk = -1024 * (i64)pcache1.nInitPage;
40732
+ }
40733
+ if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
40734
+ szBulk = pCache->szAlloc*pCache->nMax;
40735
+ }
40736
+ zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
40737
+ sqlite3EndBenignMalloc();
40738
+ if( zBulk ){
40739
+ int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
40740
+ int i;
40741
+ for(i=0; i<nBulk; i++){
40742
+ PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
40743
+ pX->page.pBuf = zBulk;
40744
+ pX->page.pExtra = &pX[1];
40745
+ pX->isBulkLocal = 1;
40746
+ pX->pNext = pCache->pFree;
40747
+ pCache->pFree = pX;
40748
+ zBulk += pCache->szAlloc;
40749
+ }
40750
+ }
40751
+ return pCache->pFree!=0;
40752
+}
4067040753
4067140754
/*
4067240755
** Malloc function used within this file to allocate space from the buffer
4067340756
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
4067440757
** such buffer exists or there is no space left in it, this function falls
@@ -40766,11 +40849,11 @@
4076640849
static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
4076740850
PgHdr1 *p = 0;
4076840851
void *pPg;
4076940852
4077040853
assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40771
- if( pCache->pFree ){
40854
+ if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
4077240855
p = pCache->pFree;
4077340856
pCache->pFree = p->pNext;
4077440857
p->pNext = 0;
4077540858
}else{
4077640859
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
@@ -40970,18 +41053,23 @@
4097041053
4097141054
/*
4097241055
** If there are currently more than nMaxPage pages allocated, try
4097341056
** to recycle pages to reduce the number allocated to nMaxPage.
4097441057
*/
40975
-static void pcache1EnforceMaxPage(PGroup *pGroup){
41058
+static void pcache1EnforceMaxPage(PCache1 *pCache){
41059
+ PGroup *pGroup = pCache->pGroup;
4097641060
assert( sqlite3_mutex_held(pGroup->mutex) );
4097741061
while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
4097841062
PgHdr1 *p = pGroup->pLruTail;
4097941063
assert( p->pCache->pGroup==pGroup );
4098041064
assert( p->isPinned==0 );
4098141065
pcache1PinPage(p);
4098241066
pcache1RemoveFromHash(p, 1);
41067
+ }
41068
+ if( pCache->nPage==0 && pCache->pBulk ){
41069
+ sqlite3_free(pCache->pBulk);
41070
+ pCache->pBulk = pCache->pFree = 0;
4098341071
}
4098441072
}
4098541073
4098641074
/*
4098741075
** Discard all pages from cache pCache with a page number (key value)
@@ -41054,10 +41142,18 @@
4105441142
if( sqlite3GlobalConfig.bCoreMutex ){
4105541143
pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
4105641144
pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
4105741145
}
4105841146
#endif
41147
+ if( pcache1.separateCache
41148
+ && sqlite3GlobalConfig.nPage!=0
41149
+ && sqlite3GlobalConfig.pPage==0
41150
+ ){
41151
+ pcache1.nInitPage = sqlite3GlobalConfig.nPage;
41152
+ }else{
41153
+ pcache1.nInitPage = 0;
41154
+ }
4105941155
pcache1.grp.mxPinned = 10;
4106041156
pcache1.isInit = 1;
4106141157
return SQLITE_OK;
4106241158
}
4106341159
@@ -41108,40 +41204,10 @@
4110841204
pCache->nMin = 10;
4110941205
pGroup->nMinPage += pCache->nMin;
4111041206
pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
4111141207
}
4111241208
pcache1LeaveMutex(pGroup);
41113
- /* Try to initialize the local bulk pagecache line allocation if using
41114
- ** separate caches and if nPage!=0 */
41115
- if( pcache1.separateCache
41116
- && sqlite3GlobalConfig.nPage!=0
41117
- && sqlite3GlobalConfig.pPage==0
41118
- ){
41119
- int szBulk;
41120
- char *zBulk;
41121
- sqlite3BeginBenignMalloc();
41122
- if( sqlite3GlobalConfig.nPage>0 ){
41123
- szBulk = pCache->szAlloc * sqlite3GlobalConfig.nPage;
41124
- }else{
41125
- szBulk = -1024*sqlite3GlobalConfig.nPage;
41126
- }
41127
- zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
41128
- sqlite3EndBenignMalloc();
41129
- if( zBulk ){
41130
- int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
41131
- int i;
41132
- for(i=0; i<nBulk; i++){
41133
- PgHdr1 *pX = (PgHdr1*)&zBulk[szPage];
41134
- pX->page.pBuf = zBulk;
41135
- pX->page.pExtra = &pX[1];
41136
- pX->isBulkLocal = 1;
41137
- pX->pNext = pCache->pFree;
41138
- pCache->pFree = pX;
41139
- zBulk += pCache->szAlloc;
41140
- }
41141
- }
41142
- }
4114341209
if( pCache->nHash==0 ){
4114441210
pcache1Destroy((sqlite3_pcache*)pCache);
4114541211
pCache = 0;
4114641212
}
4114741213
}
@@ -41160,11 +41226,11 @@
4116041226
pcache1EnterMutex(pGroup);
4116141227
pGroup->nMaxPage += (nMax - pCache->nMax);
4116241228
pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
4116341229
pCache->nMax = nMax;
4116441230
pCache->n90pct = pCache->nMax*9/10;
41165
- pcache1EnforceMaxPage(pGroup);
41231
+ pcache1EnforceMaxPage(pCache);
4116641232
pcache1LeaveMutex(pGroup);
4116741233
}
4116841234
}
4116941235
4117041236
/*
@@ -41178,11 +41244,11 @@
4117841244
PGroup *pGroup = pCache->pGroup;
4117941245
int savedMaxPage;
4118041246
pcache1EnterMutex(pGroup);
4118141247
savedMaxPage = pGroup->nMaxPage;
4118241248
pGroup->nMaxPage = 0;
41183
- pcache1EnforceMaxPage(pGroup);
41249
+ pcache1EnforceMaxPage(pCache);
4118441250
pGroup->nMaxPage = savedMaxPage;
4118541251
pcache1LeaveMutex(pGroup);
4118641252
}
4118741253
}
4118841254
@@ -41515,11 +41581,11 @@
4151541581
assert( pGroup->nMaxPage >= pCache->nMax );
4151641582
pGroup->nMaxPage -= pCache->nMax;
4151741583
assert( pGroup->nMinPage >= pCache->nMin );
4151841584
pGroup->nMinPage -= pCache->nMin;
4151941585
pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41520
- pcache1EnforceMaxPage(pGroup);
41586
+ pcache1EnforceMaxPage(pCache);
4152141587
pcache1LeaveMutex(pGroup);
4152241588
sqlite3_free(pCache->pBulk);
4152341589
sqlite3_free(pCache->apHash);
4152441590
sqlite3_free(pCache);
4152541591
}
@@ -41679,10 +41745,11 @@
4167941745
** primitives are constant time. The cost of DESTROY is O(N).
4168041746
**
4168141747
** There is an added cost of O(N) when switching between TEST and
4168241748
** SMALLEST primitives.
4168341749
*/
41750
+/* #include "sqliteInt.h" */
4168441751
4168541752
4168641753
/*
4168741754
** Target size for allocation chunks.
4168841755
*/
@@ -42148,10 +42215,11 @@
4214842215
** locking to prevent two processes from writing the same database
4214942216
** file simultaneously, or one process from reading the database while
4215042217
** another is writing.
4215142218
*/
4215242219
#ifndef SQLITE_OMIT_DISKIO
42220
+/* #include "sqliteInt.h" */
4215342221
/************** Include wal.h in the middle of pager.c ***********************/
4215442222
/************** Begin file wal.h *********************************************/
4215542223
/*
4215642224
** 2010 February 1
4215742225
**
@@ -42169,10 +42237,11 @@
4216942237
*/
4217042238
4217142239
#ifndef _WAL_H_
4217242240
#define _WAL_H_
4217342241
42242
+/* #include "sqliteInt.h" */
4217442243
4217542244
/* Additional values that can be added to the sync_flags argument of
4217642245
** sqlite3WalFrames():
4217742246
*/
4217842247
#define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */
@@ -49783,10 +49852,11 @@
4978349852
** that correspond to frames greater than the new K value are removed
4978449853
** from the hash table at this point.
4978549854
*/
4978649855
#ifndef SQLITE_OMIT_WAL
4978749856
49857
+/* #include "wal.h" */
4978849858
4978949859
/*
4979049860
** Trace output macros
4979149861
*/
4979249862
#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
@@ -50188,13 +50258,13 @@
5018850258
5018950259
assert( pWal->writeLock );
5019050260
pWal->hdr.isInit = 1;
5019150261
pWal->hdr.iVersion = WALINDEX_MAX_VERSION;
5019250262
walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
50193
- memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr));
50263
+ memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
5019450264
walShmBarrier(pWal);
50195
- memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr));
50265
+ memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
5019650266
}
5019750267
5019850268
/*
5019950269
** This function encodes a single frame header and writes it to a buffer
5020050270
** supplied by the caller. A frame-header is made up of a series of
@@ -50492,17 +50562,17 @@
5049250562
#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
5049350563
/* Verify that the every entry in the mapping region is still reachable
5049450564
** via the hash table even after the cleanup.
5049550565
*/
5049650566
if( iLimit ){
50497
- int i; /* Loop counter */
50567
+ int j; /* Loop counter */
5049850568
int iKey; /* Hash key */
50499
- for(i=1; i<=iLimit; i++){
50500
- for(iKey=walHash(aPgno[i]); aHash[iKey]; iKey=walNextHash(iKey)){
50501
- if( aHash[iKey]==i ) break;
50569
+ for(j=1; j<=iLimit; j++){
50570
+ for(iKey=walHash(aPgno[j]); aHash[iKey]; iKey=walNextHash(iKey)){
50571
+ if( aHash[iKey]==j ) break;
5050250572
}
50503
- assert( aHash[iKey]==i );
50573
+ assert( aHash[iKey]==j );
5050450574
}
5050550575
}
5050650576
#endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
5050750577
}
5050850578
@@ -51000,11 +51070,11 @@
5100051070
5100151071
const int nList = *pnList; /* Size of input list */
5100251072
int nMerge = 0; /* Number of elements in list aMerge */
5100351073
ht_slot *aMerge = 0; /* List to be merged */
5100451074
int iList; /* Index into input list */
51005
- int iSub = 0; /* Index into aSub array */
51075
+ u32 iSub = 0; /* Index into aSub array */
5100651076
struct Sublist aSub[13]; /* Array of sub-lists */
5100751077
5100851078
memset(aSub, 0, sizeof(aSub));
5100951079
assert( nList<=HASHTABLE_NPAGE && nList>0 );
5101051080
assert( HASHTABLE_NPAGE==(1<<(ArraySize(aSub)-1)) );
@@ -51011,11 +51081,13 @@
5101151081
5101251082
for(iList=0; iList<nList; iList++){
5101351083
nMerge = 1;
5101451084
aMerge = &aList[iList];
5101551085
for(iSub=0; iList & (1<<iSub); iSub++){
51016
- struct Sublist *p = &aSub[iSub];
51086
+ struct Sublist *p;
51087
+ assert( iSub<ArraySize(aSub) );
51088
+ p = &aSub[iSub];
5101751089
assert( p->aList && p->nList<=(1<<iSub) );
5101851090
assert( p->aList==&aList[iList&~((2<<iSub)-1)] );
5101951091
walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
5102051092
}
5102151093
aSub[iSub].aList = aMerge;
@@ -51022,11 +51094,13 @@
5102251094
aSub[iSub].nList = nMerge;
5102351095
}
5102451096
5102551097
for(iSub++; iSub<ArraySize(aSub); iSub++){
5102651098
if( nList & (1<<iSub) ){
51027
- struct Sublist *p = &aSub[iSub];
51099
+ struct Sublist *p;
51100
+ assert( iSub<ArraySize(aSub) );
51101
+ p = &aSub[iSub];
5102851102
assert( p->nList<=(1<<iSub) );
5102951103
assert( p->aList==&aList[nList&~((2<<iSub)-1)] );
5103051104
walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
5103151105
}
5103251106
}
@@ -52933,10 +53007,11 @@
5293353007
** SIZE DESCRIPTION
5293453008
** 4 Page number of next trunk page
5293553009
** 4 Number of leaf pointers on this page
5293653010
** * zero or more pages numbers of leaves
5293753011
*/
53012
+/* #include "sqliteInt.h" */
5293853013
5293953014
5294053015
/* The following value is the maximum cell size assuming a maximum page
5294153016
** size give above.
5294253017
*/
@@ -53730,10 +53805,11 @@
5373053805
*************************************************************************
5373153806
** This file implements an external (disk-based) database using BTrees.
5373253807
** See the header comment on "btreeInt.h" for additional information.
5373353808
** Including a description of file format and an overview of operation.
5373453809
*/
53810
+/* #include "btreeInt.h" */
5373553811
5373653812
/*
5373753813
** The header string that appears at the beginning of every
5373853814
** SQLite database.
5373953815
*/
@@ -62675,11 +62751,11 @@
6267562751
u32 *heap = 0; /* Min-heap used for checking cell coverage */
6267662752
u32 x, prev = 0; /* Next and previous entry on the min-heap */
6267762753
const char *saved_zPfx = pCheck->zPfx;
6267862754
int saved_v1 = pCheck->v1;
6267962755
int saved_v2 = pCheck->v2;
62680
- u8 savedIsInit;
62756
+ u8 savedIsInit = 0;
6268162757
6268262758
/* Check that the page exists
6268362759
*/
6268462760
pBt = pCheck->pBt;
6268562761
usableSize = pBt->usableSize;
@@ -63311,10 +63387,12 @@
6331163387
**
6331263388
*************************************************************************
6331363389
** This file contains the implementation of the sqlite3_backup_XXX()
6331463390
** API functions and the related features.
6331563391
*/
63392
+/* #include "sqliteInt.h" */
63393
+/* #include "btreeInt.h" */
6331663394
6331763395
/*
6331863396
** Structure allocated for each backup operation.
6331963397
*/
6332063398
struct sqlite3_backup {
@@ -64109,10 +64187,12 @@
6410964187
** This file contains code use to manipulate "Mem" structure. A "Mem"
6411064188
** stores a single value in the VDBE. Mem is an opaque structure visible
6411164189
** only within the VDBE. Interface routines refer to a Mem using the
6411264190
** name sqlite_value
6411364191
*/
64192
+/* #include "sqliteInt.h" */
64193
+/* #include "vdbeInt.h" */
6411464194
6411564195
#ifdef SQLITE_DEBUG
6411664196
/*
6411764197
** Check invariants on a Mem object.
6411864198
**
@@ -65826,10 +65906,12 @@
6582665906
**
6582765907
*************************************************************************
6582865908
** This file contains code used for creating, destroying, and populating
6582965909
** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)
6583065910
*/
65911
+/* #include "sqliteInt.h" */
65912
+/* #include "vdbeInt.h" */
6583165913
6583265914
/*
6583365915
** Create a new virtual database engine.
6583465916
*/
6583565917
SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){
@@ -70074,10 +70156,12 @@
7007470156
*************************************************************************
7007570157
**
7007670158
** This file contains code use to implement APIs that are part of the
7007770159
** VDBE.
7007870160
*/
70161
+/* #include "sqliteInt.h" */
70162
+/* #include "vdbeInt.h" */
7007970163
7008070164
#ifndef SQLITE_OMIT_DEPRECATED
7008170165
/*
7008270166
** Return TRUE (non-zero) of the statement supplied as an argument needs
7008370167
** to be recompiled. A statement needs to be recompiled whenever the
@@ -70112,10 +70196,35 @@
7011270196
}else{
7011370197
return vdbeSafety(p);
7011470198
}
7011570199
}
7011670200
70201
+#ifndef SQLITE_OMIT_TRACE
70202
+/*
70203
+** Invoke the profile callback. This routine is only called if we already
70204
+** know that the profile callback is defined and needs to be invoked.
70205
+*/
70206
+static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){
70207
+ sqlite3_int64 iNow;
70208
+ assert( p->startTime>0 );
70209
+ assert( db->xProfile!=0 );
70210
+ assert( db->init.busy==0 );
70211
+ assert( p->zSql!=0 );
70212
+ sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
70213
+ db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
70214
+ p->startTime = 0;
70215
+}
70216
+/*
70217
+** The checkProfileCallback(DB,P) macro checks to see if a profile callback
70218
+** is needed, and it invokes the callback if it is needed.
70219
+*/
70220
+# define checkProfileCallback(DB,P) \
70221
+ if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
70222
+#else
70223
+# define checkProfileCallback(DB,P) /*no-op*/
70224
+#endif
70225
+
7011770226
/*
7011870227
** The following routine destroys a virtual machine that is created by
7011970228
** the sqlite3_compile() routine. The integer returned is an SQLITE_
7012070229
** success/failure code that describes the result of executing the virtual
7012170230
** machine.
@@ -70132,10 +70241,11 @@
7013270241
}else{
7013370242
Vdbe *v = (Vdbe*)pStmt;
7013470243
sqlite3 *db = v->db;
7013570244
if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
7013670245
sqlite3_mutex_enter(db->mutex);
70246
+ checkProfileCallback(db, v);
7013770247
rc = sqlite3VdbeFinalize(v);
7013870248
rc = sqlite3ApiExit(db, rc);
7013970249
sqlite3LeaveMutexAndCloseZombie(db);
7014070250
}
7014170251
return rc;
@@ -70153,16 +70263,18 @@
7015370263
int rc;
7015470264
if( pStmt==0 ){
7015570265
rc = SQLITE_OK;
7015670266
}else{
7015770267
Vdbe *v = (Vdbe*)pStmt;
70158
- sqlite3_mutex_enter(v->db->mutex);
70268
+ sqlite3 *db = v->db;
70269
+ sqlite3_mutex_enter(db->mutex);
70270
+ checkProfileCallback(db, v);
7015970271
rc = sqlite3VdbeReset(v);
7016070272
sqlite3VdbeRewind(v);
70161
- assert( (rc & (v->db->errMask))==rc );
70162
- rc = sqlite3ApiExit(v->db, rc);
70163
- sqlite3_mutex_leave(v->db->mutex);
70273
+ assert( (rc & (db->errMask))==rc );
70274
+ rc = sqlite3ApiExit(db, rc);
70275
+ sqlite3_mutex_leave(db->mutex);
7016470276
}
7016570277
return rc;
7016670278
}
7016770279
7016870280
/*
@@ -70193,11 +70305,14 @@
7019370305
** structure.
7019470306
*/
7019570307
SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value *pVal){
7019670308
Mem *p = (Mem*)pVal;
7019770309
if( p->flags & (MEM_Blob|MEM_Str) ){
70198
- sqlite3VdbeMemExpandBlob(p);
70310
+ if( sqlite3VdbeMemExpandBlob(p)!=SQLITE_OK ){
70311
+ assert( p->flags==MEM_Null && p->z==0 );
70312
+ return 0;
70313
+ }
7019970314
p->flags |= MEM_Blob;
7020070315
return p->n ? p->z : 0;
7020170316
}else{
7020270317
return sqlite3_value_text(pVal);
7020370318
}
@@ -70454,10 +70569,19 @@
7045470569
sqlite3VdbeMemCopy(pCtx->pOut, pValue);
7045570570
}
7045670571
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
7045770572
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
7045870573
sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
70574
+}
70575
+SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
70576
+ Mem *pOut = pCtx->pOut;
70577
+ assert( sqlite3_mutex_held(pOut->db->mutex) );
70578
+ if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
70579
+ return SQLITE_TOOBIG;
70580
+ }
70581
+ sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
70582
+ return SQLITE_OK;
7045970583
}
7046070584
SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
7046170585
pCtx->isError = errCode;
7046270586
pCtx->fErrorOrAux = 1;
7046370587
#ifdef SQLITE_DEBUG
@@ -70508,10 +70632,11 @@
7050870632
}
7050970633
}
7051070634
#endif
7051170635
return rc;
7051270636
}
70637
+
7051370638
7051470639
/*
7051570640
** Execute the statement pStmt, either until a row of data is ready, the
7051670641
** statement is completely executed or an error occurs.
7051770642
**
@@ -70577,12 +70702,14 @@
7057770702
assert( db->nVdbeWrite>0 || db->autoCommit==0
7057870703
|| (db->nDeferredCons==0 && db->nDeferredImmCons==0)
7057970704
);
7058070705
7058170706
#ifndef SQLITE_OMIT_TRACE
70582
- if( db->xProfile && !db->init.busy ){
70707
+ if( db->xProfile && !db->init.busy && p->zSql ){
7058370708
sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
70709
+ }else{
70710
+ assert( p->startTime==0 );
7058470711
}
7058570712
#endif
7058670713
7058770714
db->nVdbeActive++;
7058870715
if( p->readOnly==0 ) db->nVdbeWrite++;
@@ -70602,17 +70729,12 @@
7060270729
rc = sqlite3VdbeExec(p);
7060370730
db->nVdbeExec--;
7060470731
}
7060570732
7060670733
#ifndef SQLITE_OMIT_TRACE
70607
- /* Invoke the profile callback if there is one
70608
- */
70609
- if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
70610
- sqlite3_int64 iNow;
70611
- sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
70612
- db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
70613
- }
70734
+ /* If the statement completed successfully, invoke the profile callback */
70735
+ if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
7061470736
#endif
7061570737
7061670738
if( rc==SQLITE_DONE ){
7061770739
assert( p->rc==SQLITE_OK );
7061870740
p->rc = doWalCallbacks(db);
@@ -71436,10 +71558,24 @@
7143671558
sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
7143771559
sqlite3_mutex_leave(p->db->mutex);
7143871560
}
7143971561
return rc;
7144071562
}
71563
+SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt, int i, sqlite3_uint64 n){
71564
+ int rc;
71565
+ Vdbe *p = (Vdbe *)pStmt;
71566
+ sqlite3_mutex_enter(p->db->mutex);
71567
+ if( n>(u64)p->db->aLimit[SQLITE_LIMIT_LENGTH] ){
71568
+ rc = SQLITE_TOOBIG;
71569
+ }else{
71570
+ assert( (n & 0x7FFFFFFF)==n );
71571
+ rc = sqlite3_bind_zeroblob(pStmt, i, n);
71572
+ }
71573
+ rc = sqlite3ApiExit(p->db, rc);
71574
+ sqlite3_mutex_leave(p->db->mutex);
71575
+ return rc;
71576
+}
7144171577
7144271578
/*
7144371579
** Return the number of wildcards that can be potentially bound to.
7144471580
** This routine is added to support DBD::SQLite.
7144571581
*/
@@ -71685,10 +71821,12 @@
7168571821
** This file contains code used to insert the values of host parameters
7168671822
** (aka "wildcards") into the SQL text output by sqlite3_trace().
7168771823
**
7168871824
** The Vdbe parse-tree explainer is also found here.
7168971825
*/
71826
+/* #include "sqliteInt.h" */
71827
+/* #include "vdbeInt.h" */
7169071828
7169171829
#ifndef SQLITE_OMIT_TRACE
7169271830
7169371831
/*
7169471832
** zSql is a zero-terminated string of UTF-8 SQL text. Return the number of
@@ -71877,10 +72015,12 @@
7187772015
** documentation, headers files, or other derived files. The formatting
7187872016
** of the code in this file is, therefore, important. See other comments
7187972017
** in this file for details. If in doubt, do not deviate from existing
7188072018
** commenting and indentation practices when changing or adding code.
7188172019
*/
72020
+/* #include "sqliteInt.h" */
72021
+/* #include "vdbeInt.h" */
7188272022
7188372023
/*
7188472024
** Invoke this macro on memory cells just prior to changing the
7188572025
** value of the cell. This macro verifies that shallow copies are
7188672026
** not misused. A shallow copy of a string or blob just copies a
@@ -74648,11 +74788,11 @@
7464874788
assert( memIsValid(pRec) );
7464974789
pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format);
7465074790
len = sqlite3VdbeSerialTypeLen(serial_type);
7465174791
if( pRec->flags & MEM_Zero ){
7465274792
if( nData ){
74653
- sqlite3VdbeMemExpandBlob(pRec);
74793
+ if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem;
7465474794
}else{
7465574795
nZero += pRec->u.nZero;
7465674796
len -= pRec->u.nZero;
7465774797
}
7465874798
}
@@ -78635,10 +78775,12 @@
7863578775
*************************************************************************
7863678776
**
7863778777
** This file contains code used to implement incremental BLOB I/O.
7863878778
*/
7863978779
78780
+/* #include "sqliteInt.h" */
78781
+/* #include "vdbeInt.h" */
7864078782
7864178783
#ifndef SQLITE_OMIT_INCRBLOB
7864278784
7864378785
/*
7864478786
** Valid sqlite3_blob* handles point to Incrblob structures.
@@ -79233,10 +79375,12 @@
7923379375
** than one background thread may be created. Specifically, there may be
7923479376
** one background thread for each temporary file on disk, and one background
7923579377
** thread to merge the output of each of the others to a single PMA for
7923679378
** the main thread to read from.
7923779379
*/
79380
+/* #include "sqliteInt.h" */
79381
+/* #include "vdbeInt.h" */
7923879382
7923979383
/*
7924079384
** If SQLITE_DEBUG_SORTER_THREADS is defined, this module outputs various
7924179385
** messages to stderr that may be helpful in understanding the performance
7924279386
** characteristics of the sorter in multi-threaded mode.
@@ -81849,10 +81993,11 @@
8184981993
** 1) The in-memory representation grows too large for the allocated
8185081994
** buffer, or
8185181995
** 2) The sqlite3JournalCreate() function is called.
8185281996
*/
8185381997
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
81998
+/* #include "sqliteInt.h" */
8185481999
8185582000
8185682001
/*
8185782002
** A JournalFile object is a subclass of sqlite3_file used by
8185882003
** as an open file handle for journal files.
@@ -82096,10 +82241,11 @@
8209682241
**
8209782242
** This file contains code use to implement an in-memory rollback journal.
8209882243
** The in-memory rollback journal is used to journal transactions for
8209982244
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
8210082245
*/
82246
+/* #include "sqliteInt.h" */
8210182247
8210282248
/* Forward references to internal structures */
8210382249
typedef struct MemJournal MemJournal;
8210482250
typedef struct FilePoint FilePoint;
8210582251
typedef struct FileChunk FileChunk;
@@ -82351,10 +82497,11 @@
8235182497
**
8235282498
*************************************************************************
8235382499
** This file contains routines used for walking the parser tree for
8235482500
** an SQL statement.
8235582501
*/
82502
+/* #include "sqliteInt.h" */
8235682503
/* #include <stdlib.h> */
8235782504
/* #include <string.h> */
8235882505
8235982506
8236082507
/*
@@ -82509,10 +82656,11 @@
8250982656
**
8251082657
** This file contains routines used for walking the parser tree and
8251182658
** resolve all identifiers by associating them with a particular
8251282659
** table and column.
8251382660
*/
82661
+/* #include "sqliteInt.h" */
8251482662
/* #include <stdlib.h> */
8251582663
/* #include <string.h> */
8251682664
8251782665
/*
8251882666
** Walk the expression tree pExpr and increase the aggregate function
@@ -84021,10 +84169,11 @@
8402184169
**
8402284170
*************************************************************************
8402384171
** This file contains routines used for analyzing expressions and
8402484172
** for generating VDBE code that evaluates expressions in SQLite.
8402584173
*/
84174
+/* #include "sqliteInt.h" */
8402684175
8402784176
/*
8402884177
** Return the 'affinity' of the expression pExpr if any.
8402984178
**
8403084179
** If pExpr is a column, a reference to a column via an 'AS' alias,
@@ -88183,10 +88332,11 @@
8818388332
**
8818488333
*************************************************************************
8818588334
** This file contains C code routines that used to generate VDBE code
8818688335
** that implements the ALTER TABLE command.
8818788336
*/
88337
+/* #include "sqliteInt.h" */
8818888338
8818988339
/*
8819088340
** The code in this file only exists if we are not omitting the
8819188341
** ALTER TABLE logic from the build.
8819288342
*/
@@ -89145,10 +89295,11 @@
8914589295
** sqlite_stat4.sample. The nEq, nLt, and nDLt entries of sqlite_stat3
8914689296
** all contain just a single integer which is the same as the first
8914789297
** integer in the equivalent columns in sqlite_stat4.
8914889298
*/
8914989299
#ifndef SQLITE_OMIT_ANALYZE
89300
+/* #include "sqliteInt.h" */
8915089301
8915189302
#if defined(SQLITE_ENABLE_STAT4)
8915289303
# define IsStat4 1
8915389304
# define IsStat3 0
8915489305
#elif defined(SQLITE_ENABLE_STAT3)
@@ -90910,10 +91061,11 @@
9091091061
** May you share freely, never taking more than you give.
9091191062
**
9091291063
*************************************************************************
9091391064
** This file contains code used to implement the ATTACH and DETACH commands.
9091491065
*/
91066
+/* #include "sqliteInt.h" */
9091591067
9091691068
#ifndef SQLITE_OMIT_ATTACH
9091791069
/*
9091891070
** Resolve an expression that was part of an ATTACH or DETACH statement. This
9091991071
** is slightly different from resolving a normal SQL expression, because simple
@@ -91499,10 +91651,11 @@
9149991651
** This file contains code used to implement the sqlite3_set_authorizer()
9150091652
** API. This facility is an optional feature of the library. Embedded
9150191653
** systems that do not need this facility may omit it by recompiling
9150291654
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
9150391655
*/
91656
+/* #include "sqliteInt.h" */
9150491657
9150591658
/*
9150691659
** All of the code in this file may be omitted by defining a single
9150791660
** macro.
9150891661
*/
@@ -91769,10 +91922,11 @@
9176991922
** creating ID lists
9177091923
** BEGIN TRANSACTION
9177191924
** COMMIT
9177291925
** ROLLBACK
9177391926
*/
91927
+/* #include "sqliteInt.h" */
9177491928
9177591929
/*
9177691930
** This routine is called when a new SQL statement is beginning to
9177791931
** be parsed. Initialize the pParse structure as needed.
9177891932
*/
@@ -96089,10 +96243,11 @@
9608996243
**
9609096244
** This file contains functions used to access the internal hash tables
9609196245
** of user defined functions and collation sequences.
9609296246
*/
9609396247
96248
+/* #include "sqliteInt.h" */
9609496249
9609596250
/*
9609696251
** Invoke the 'collation needed' callback to request a collation sequence
9609796252
** in the encoding enc of name zName, length nName.
9609896253
*/
@@ -96566,10 +96721,11 @@
9656696721
**
9656796722
*************************************************************************
9656896723
** This file contains C code routines that are called by the parser
9656996724
** in order to generate code for DELETE FROM statements.
9657096725
*/
96726
+/* #include "sqliteInt.h" */
9657196727
9657296728
/*
9657396729
** While a SrcList can in general represent multiple tables and subqueries
9657496730
** (as in the FROM clause of a SELECT statement) in this case it contains
9657596731
** the name of a single table, as one might find in an INSERT, DELETE,
@@ -97408,12 +97564,14 @@
9740897564
*************************************************************************
9740997565
** This file contains the C-language implementations for many of the SQL
9741097566
** functions of SQLite. (Some function, and in particular the date and
9741197567
** time functions, are implemented separately.)
9741297568
*/
97569
+/* #include "sqliteInt.h" */
9741397570
/* #include <stdlib.h> */
9741497571
/* #include <assert.h> */
97572
+/* #include "vdbeInt.h" */
9741597573
9741697574
/*
9741797575
** Return the collating function associated with a function.
9741897576
*/
9741997577
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
@@ -98515,20 +98673,18 @@
9851598673
sqlite3_context *context,
9851698674
int argc,
9851798675
sqlite3_value **argv
9851898676
){
9851998677
i64 n;
98520
- sqlite3 *db = sqlite3_context_db_handle(context);
98678
+ int rc;
9852198679
assert( argc==1 );
9852298680
UNUSED_PARAMETER(argc);
9852398681
n = sqlite3_value_int64(argv[0]);
98524
- testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
98525
- testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
98526
- if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
98527
- sqlite3_result_error_toobig(context);
98528
- }else{
98529
- sqlite3_result_zeroblob(context, (int)n); /* IMP: R-00293-64994 */
98682
+ if( n<0 ) n = 0;
98683
+ rc = sqlite3_result_zeroblob64(context, n); /* IMP: R-00293-64994 */
98684
+ if( rc ){
98685
+ sqlite3_result_error_code(context, rc);
9853098686
}
9853198687
}
9853298688
9853398689
/*
9853498690
** The replace() function. Three arguments are all strings: call
@@ -99205,10 +99361,11 @@
9920599361
**
9920699362
*************************************************************************
9920799363
** This file contains code used by the compiler to add foreign key
9920899364
** support to compiled SQL statements.
9920999365
*/
99366
+/* #include "sqliteInt.h" */
9921099367
9921199368
#ifndef SQLITE_OMIT_FOREIGN_KEY
9921299369
#ifndef SQLITE_OMIT_TRIGGER
9921399370
9921499371
/*
@@ -100609,10 +100766,11 @@
100609100766
**
100610100767
*************************************************************************
100611100768
** This file contains C code routines that are called by the parser
100612100769
** to handle INSERT statements in SQLite.
100613100770
*/
100771
+/* #include "sqliteInt.h" */
100614100772
100615100773
/*
100616100774
** Generate code that will
100617100775
**
100618100776
** (1) acquire a lock for table pTab then
@@ -102592,11 +102750,11 @@
102592102750
}else{
102593102751
sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
102594102752
sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
102595102753
}
102596102754
for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
102597
- u8 useSeekResult = 0;
102755
+ u8 idxInsFlags = 0;
102598102756
for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
102599102757
if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
102600102758
}
102601102759
assert( pSrcIdx );
102602102760
sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -102627,16 +102785,19 @@
102627102785
char *zColl = pSrcIdx->azColl[i];
102628102786
assert( zColl!=0 );
102629102787
if( sqlite3_stricmp("BINARY", zColl) ) break;
102630102788
}
102631102789
if( i==pSrcIdx->nColumn ){
102632
- useSeekResult = OPFLAG_USESEEKRESULT;
102790
+ idxInsFlags = OPFLAG_USESEEKRESULT;
102633102791
sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
102634102792
}
102793
+ }
102794
+ if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
102795
+ idxInsFlags |= OPFLAG_NCHANGE;
102635102796
}
102636102797
sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
102637
- sqlite3VdbeChangeP5(v, useSeekResult);
102798
+ sqlite3VdbeChangeP5(v, idxInsFlags);
102638102799
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
102639102800
sqlite3VdbeJumpHere(v, addr1);
102640102801
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
102641102802
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
102642102803
}
@@ -102671,10 +102832,11 @@
102671102832
** implement the programmer interface to the library. Routines in
102672102833
** other files are for internal use by SQLite and should not be
102673102834
** accessed by users of the library.
102674102835
*/
102675102836
102837
+/* #include "sqliteInt.h" */
102676102838
102677102839
/*
102678102840
** Execute SQL code. Return one of the SQLITE_ success/failure
102679102841
** codes. Also write an error message into memory obtained from
102680102842
** malloc() and make *pzErrMsg point to that message.
@@ -102839,10 +103001,11 @@
102839103001
** as extensions by SQLite should #include this file instead of
102840103002
** sqlite3.h.
102841103003
*/
102842103004
#ifndef _SQLITE3EXT_H_
102843103005
#define _SQLITE3EXT_H_
103006
+/* #include "sqlite3.h" */
102844103007
102845103008
typedef struct sqlite3_api_routines sqlite3_api_routines;
102846103009
102847103010
/*
102848103011
** The following structure holds pointers to all of the SQLite API
@@ -103091,10 +103254,12 @@
103091103254
void(*)(void*), unsigned char);
103092103255
int (*strglob)(const char*,const char*);
103093103256
/* Version 3.8.11 and later */
103094103257
sqlite3_value *(*value_dup)(const sqlite3_value*);
103095103258
void (*value_free)(sqlite3_value*);
103259
+ int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
103260
+ int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
103096103261
};
103097103262
103098103263
/*
103099103264
** The following macros redefine the API routines so that they are
103100103265
** redirected through the global sqlite3_api structure.
@@ -103324,10 +103489,12 @@
103324103489
#define sqlite3_result_text64 sqlite3_api->result_text64
103325103490
#define sqlite3_strglob sqlite3_api->strglob
103326103491
/* Version 3.8.11 and later */
103327103492
#define sqlite3_value_dup sqlite3_api->value_dup
103328103493
#define sqlite3_value_free sqlite3_api->value_free
103494
+#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
103495
+#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
103329103496
#endif /* SQLITE_CORE */
103330103497
103331103498
#ifndef SQLITE_CORE
103332103499
/* This case when the file really is being compiled as a loadable
103333103500
** extension */
@@ -103345,10 +103512,11 @@
103345103512
103346103513
#endif /* _SQLITE3EXT_H_ */
103347103514
103348103515
/************** End of sqlite3ext.h ******************************************/
103349103516
/************** Continuing where we left off in loadext.c ********************/
103517
+/* #include "sqliteInt.h" */
103350103518
/* #include <string.h> */
103351103519
103352103520
#ifndef SQLITE_OMIT_LOAD_EXTENSION
103353103521
103354103522
/*
@@ -103732,11 +103900,13 @@
103732103900
sqlite3_result_blob64,
103733103901
sqlite3_result_text64,
103734103902
sqlite3_strglob,
103735103903
/* Version 3.8.11 and later */
103736103904
(sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
103737
- sqlite3_value_free
103905
+ sqlite3_value_free,
103906
+ sqlite3_result_zeroblob64,
103907
+ sqlite3_bind_zeroblob64
103738103908
};
103739103909
103740103910
/*
103741103911
** Attempt to load an SQLite extension library contained in the file
103742103912
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -104114,10 +104284,11 @@
104114104284
** May you share freely, never taking more than you give.
104115104285
**
104116104286
*************************************************************************
104117104287
** This file contains code used to implement the PRAGMA command.
104118104288
*/
104289
+/* #include "sqliteInt.h" */
104119104290
104120104291
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
104121104292
# if defined(__APPLE__)
104122104293
# define SQLITE_ENABLE_LOCKING_STYLE 1
104123104294
# else
@@ -104220,11 +104391,11 @@
104220104391
/* ePragFlag: */ 0,
104221104392
/* iArg: */ 0 },
104222104393
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
104223104394
{ /* zName: */ "cache_size",
104224104395
/* ePragTyp: */ PragTyp_CACHE_SIZE,
104225
- /* ePragFlag: */ PragFlag_NeedSchema,
104396
+ /* ePragFlag: */ 0,
104226104397
/* iArg: */ 0 },
104227104398
#endif
104228104399
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
104229104400
{ /* zName: */ "cache_spill",
104230104401
/* ePragTyp: */ PragTyp_FLAG,
@@ -105290,15 +105461,17 @@
105290105461
** of memory.
105291105462
*/
105292105463
case PragTyp_CACHE_SIZE: {
105293105464
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
105294105465
if( !zRight ){
105466
+ if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105295105467
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
105296105468
}else{
105297105469
int size = sqlite3Atoi(zRight);
105298105470
pDb->pSchema->cache_size = size;
105299105471
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
105472
+ if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105300105473
}
105301105474
break;
105302105475
}
105303105476
105304105477
/*
@@ -106565,10 +106738,11 @@
106565106738
*************************************************************************
106566106739
** This file contains the implementation of the sqlite3_prepare()
106567106740
** interface, and routines that contribute to loading the database schema
106568106741
** from disk.
106569106742
*/
106743
+/* #include "sqliteInt.h" */
106570106744
106571106745
/*
106572106746
** Fill the InitData structure with an error message that indicates
106573106747
** that the database is corrupt.
106574106748
*/
@@ -107459,10 +107633,11 @@
107459107633
**
107460107634
*************************************************************************
107461107635
** This file contains C code routines that are called by the parser
107462107636
** to handle SELECT statements in SQLite.
107463107637
*/
107638
+/* #include "sqliteInt.h" */
107464107639
107465107640
/*
107466107641
** Trace output macros
107467107642
*/
107468107643
#if SELECTTRACE_ENABLED
@@ -108528,11 +108703,10 @@
108528108703
}
108529108704
}
108530108705
return pInfo;
108531108706
}
108532108707
108533
-#ifndef SQLITE_OMIT_COMPOUND_SELECT
108534108708
/*
108535108709
** Name of the connection operator, used for error messages.
108536108710
*/
108537108711
static const char *selectOpName(int id){
108538108712
char *z;
@@ -108542,11 +108716,10 @@
108542108716
case TK_EXCEPT: z = "EXCEPT"; break;
108543108717
default: z = "UNION"; break;
108544108718
}
108545108719
return z;
108546108720
}
108547
-#endif /* SQLITE_OMIT_COMPOUND_SELECT */
108548108721
108549108722
#ifndef SQLITE_OMIT_EXPLAIN
108550108723
/*
108551108724
** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
108552108725
** is a no-op. Otherwise, it adds a single row of output to the EQP result,
@@ -109545,23 +109718,10 @@
109545109718
Parse *pParse, /* Parsing context */
109546109719
Select *p, /* The right-most of SELECTs to be coded */
109547109720
SelectDest *pDest /* What to do with query results */
109548109721
);
109549109722
109550
-/*
109551
-** Error message for when two or more terms of a compound select have different
109552
-** size result sets.
109553
-*/
109554
-SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){
109555
- if( p->selFlags & SF_Values ){
109556
- sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
109557
- }else{
109558
- sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
109559
- " do not have the same number of result columns", selectOpName(p->op));
109560
- }
109561
-}
109562
-
109563109723
/*
109564109724
** Handle the special case of a compound-select that originates from a
109565109725
** VALUES clause. By handling this as a special case, we avoid deep
109566109726
** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
109567109727
** on a VALUES clause.
@@ -109983,10 +110143,23 @@
109983110143
pDest->nSdst = dest.nSdst;
109984110144
sqlite3SelectDelete(db, pDelete);
109985110145
return rc;
109986110146
}
109987110147
#endif /* SQLITE_OMIT_COMPOUND_SELECT */
110148
+
110149
+/*
110150
+** Error message for when two or more terms of a compound select have different
110151
+** size result sets.
110152
+*/
110153
+SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){
110154
+ if( p->selFlags & SF_Values ){
110155
+ sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
110156
+ }else{
110157
+ sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
110158
+ " do not have the same number of result columns", selectOpName(p->op));
110159
+ }
110160
+}
109988110161
109989110162
/*
109990110163
** Code an output subroutine for a coroutine implementation of a
109991110164
** SELECT statment.
109992110165
**
@@ -113077,10 +113250,11 @@
113077113250
** interface routine of sqlite3_exec().
113078113251
**
113079113252
** These routines are in a separate files so that they will not be linked
113080113253
** if they are not used.
113081113254
*/
113255
+/* #include "sqliteInt.h" */
113082113256
/* #include <stdlib.h> */
113083113257
/* #include <string.h> */
113084113258
113085113259
#ifndef SQLITE_OMIT_GET_TABLE
113086113260
@@ -113273,10 +113447,11 @@
113273113447
** May you share freely, never taking more than you give.
113274113448
**
113275113449
*************************************************************************
113276113450
** This file contains the implementation for TRIGGERs
113277113451
*/
113452
+/* #include "sqliteInt.h" */
113278113453
113279113454
#ifndef SQLITE_OMIT_TRIGGER
113280113455
/*
113281113456
** Delete a linked list of TriggerStep structures.
113282113457
*/
@@ -114396,10 +114571,11 @@
114396114571
**
114397114572
*************************************************************************
114398114573
** This file contains C code routines that are called by the parser
114399114574
** to handle UPDATE statements.
114400114575
*/
114576
+/* #include "sqliteInt.h" */
114401114577
114402114578
#ifndef SQLITE_OMIT_VIRTUALTABLE
114403114579
/* Forward declaration */
114404114580
static void updateVirtualTable(
114405114581
Parse *pParse, /* The parsing context */
@@ -115172,10 +115348,12 @@
115172115348
** This file contains code used to implement the VACUUM command.
115173115349
**
115174115350
** Most of the code in this file may be omitted by defining the
115175115351
** SQLITE_OMIT_VACUUM macro.
115176115352
*/
115353
+/* #include "sqliteInt.h" */
115354
+/* #include "vdbeInt.h" */
115177115355
115178115356
#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
115179115357
/*
115180115358
** Finalize a prepared statement. If there was an error, store the
115181115359
** text of the error message in *pzErrMsg. Return the result code.
@@ -115544,10 +115722,11 @@
115544115722
**
115545115723
*************************************************************************
115546115724
** This file contains code used to help implement virtual tables.
115547115725
*/
115548115726
#ifndef SQLITE_OMIT_VIRTUALTABLE
115727
+/* #include "sqliteInt.h" */
115549115728
115550115729
/*
115551115730
** Before a virtual table xCreate() or xConnect() method is invoked, the
115552115731
** sqlite3.pVtabCtx member variable is set to point to an instance of
115553115732
** this struct allocated on the stack. It is used by the implementation of
@@ -116702,10 +116881,11 @@
116702116881
** This file was split off from where.c on 2015-06-06 in order to reduce the
116703116882
** size of where.c and make it easier to edit. This file contains the routines
116704116883
** that actually generate the bulk of the WHERE loop code. The original where.c
116705116884
** file retains the code that does query planning and analysis.
116706116885
*/
116886
+/* #include "sqliteInt.h" */
116707116887
/************** Include whereInt.h in the middle of wherecode.c **************/
116708116888
/************** Begin file whereInt.h ****************************************/
116709116889
/*
116710116890
** 2013-11-12
116711116891
**
@@ -118513,11 +118693,15 @@
118513118693
118514118694
/* Read the PK into an array of temp registers. */
118515118695
r = sqlite3GetTempRange(pParse, nPk);
118516118696
for(iPk=0; iPk<nPk; iPk++){
118517118697
int iCol = pPk->aiColumn[iPk];
118518
- sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur, r+iPk, 0);
118698
+ int rx;
118699
+ rx = sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur,r+iPk,0);
118700
+ if( rx!=r+iPk ){
118701
+ sqlite3VdbeAddOp2(v, OP_SCopy, rx, r+iPk);
118702
+ }
118519118703
}
118520118704
118521118705
/* Check if the temp table already contains this key. If so,
118522118706
** the row has already been included in the result set and
118523118707
** can be ignored (by jumping past the Gosub below). Otherwise,
@@ -118737,10 +118921,12 @@
118737118921
**
118738118922
** This file was originally part of where.c but was split out to improve
118739118923
** readability and editabiliity. This file contains utility routines for
118740118924
** analyzing Expr objects in the WHERE clause.
118741118925
*/
118926
+/* #include "sqliteInt.h" */
118927
+/* #include "whereInt.h" */
118742118928
118743118929
/* Forward declarations */
118744118930
static void exprAnalyze(SrcList*, WhereClause*, int);
118745118931
118746118932
/*
@@ -119987,10 +120173,12 @@
119987120173
** generating the code that loops through a table looking for applicable
119988120174
** rows. Indices are selected and used to speed the search when doing
119989120175
** so is applicable. Because this module is responsible for selecting
119990120176
** indices, you might also think of this module as the "query optimizer".
119991120177
*/
120178
+/* #include "sqliteInt.h" */
120179
+/* #include "whereInt.h" */
119992120180
119993120181
/* Forward declaration of methods */
119994120182
static int whereLoopResize(sqlite3*, WhereLoop*, int);
119995120183
119996120184
/* Test variable that can be set to enable WHERE tracing */
@@ -124486,10 +124674,11 @@
124486124674
*/
124487124675
/* First off, code is included that follows the "include" declaration
124488124676
** in the input grammar file. */
124489124677
/* #include <stdio.h> */
124490124678
124679
+/* #include "sqliteInt.h" */
124491124680
124492124681
/*
124493124682
** Disable all error recovery processing in the parser push-down
124494124683
** automaton.
124495124684
*/
@@ -128071,10 +128260,11 @@
128071128260
**
128072128261
** This file contains C code that splits an SQL input string up into
128073128262
** individual tokens and sends those tokens one-by-one over to the
128074128263
** parser for analysis.
128075128264
*/
128265
+/* #include "sqliteInt.h" */
128076128266
/* #include <stdlib.h> */
128077128267
128078128268
/*
128079128269
** The charMap() macro maps alphabetic characters into their
128080128270
** lower-case ASCII equivalent. On ASCII machines, this is just
@@ -128880,10 +129070,11 @@
128880129070
** This file contains C code that implements the sqlite3_complete() API.
128881129071
** This code used to be part of the tokenizer.c source file. But by
128882129072
** separating it out, the code will be automatically omitted from
128883129073
** static links that do not use it.
128884129074
*/
129075
+/* #include "sqliteInt.h" */
128885129076
#ifndef SQLITE_OMIT_COMPLETE
128886129077
128887129078
/*
128888129079
** This is defined in tokenize.c. We just have to import the definition.
128889129080
*/
@@ -129170,10 +129361,11 @@
129170129361
** Main file for the SQLite library. The routines in this file
129171129362
** implement the programmer interface to the library. Routines in
129172129363
** other files are for internal use by SQLite and should not be
129173129364
** accessed by users of the library.
129174129365
*/
129366
+/* #include "sqliteInt.h" */
129175129367
129176129368
#ifdef SQLITE_ENABLE_FTS3
129177129369
/************** Include fts3.h in the middle of main.c ***********************/
129178129370
/************** Begin file fts3.h ********************************************/
129179129371
/*
@@ -129189,10 +129381,11 @@
129189129381
******************************************************************************
129190129382
**
129191129383
** This header file is used by programs that want to link against the
129192129384
** FTS3 library. All it does is declare the sqlite3Fts3Init() interface.
129193129385
*/
129386
+/* #include "sqlite3.h" */
129194129387
129195129388
#if 0
129196129389
extern "C" {
129197129390
#endif /* __cplusplus */
129198129391
@@ -129221,10 +129414,11 @@
129221129414
******************************************************************************
129222129415
**
129223129416
** This header file is used by programs that want to link against the
129224129417
** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
129225129418
*/
129419
+/* #include "sqlite3.h" */
129226129420
129227129421
#if 0
129228129422
extern "C" {
129229129423
#endif /* __cplusplus */
129230129424
@@ -129253,10 +129447,11 @@
129253129447
******************************************************************************
129254129448
**
129255129449
** This header file is used by programs that want to link against the
129256129450
** ICU extension. All it does is declare the sqlite3IcuInit() interface.
129257129451
*/
129452
+/* #include "sqlite3.h" */
129258129453
129259129454
#if 0
129260129455
extern "C" {
129261129456
#endif /* __cplusplus */
129262129457
@@ -129885,10 +130080,11 @@
129885130080
** space for the lookaside memory is obtained from sqlite3_malloc().
129886130081
** If pStart is not NULL then it is sz*cnt bytes of memory to use for
129887130082
** the lookaside memory.
129888130083
*/
129889130084
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
130085
+#ifndef SQLITE_OMIT_LOOKASIDE
129890130086
void *pStart;
129891130087
if( db->lookaside.nOut ){
129892130088
return SQLITE_BUSY;
129893130089
}
129894130090
/* Free any existing lookaside buffer for this handle before
@@ -129935,10 +130131,11 @@
129935130131
db->lookaside.pStart = db;
129936130132
db->lookaside.pEnd = db;
129937130133
db->lookaside.bEnabled = 0;
129938130134
db->lookaside.bMalloced = 0;
129939130135
}
130136
+#endif /* SQLITE_OMIT_LOOKASIDE */
129940130137
return SQLITE_OK;
129941130138
}
129942130139
129943130140
/*
129944130141
** Return the mutex associated with a database connection.
@@ -133045,10 +133242,12 @@
133045133242
*************************************************************************
133046133243
**
133047133244
** This file contains the implementation of the sqlite3_unlock_notify()
133048133245
** API method and its associated functionality.
133049133246
*/
133247
+/* #include "sqliteInt.h" */
133248
+/* #include "btreeInt.h" */
133050133249
133051133250
/* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */
133052133251
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
133053133252
133054133253
/*
@@ -133688,13 +133887,15 @@
133688133887
133689133888
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
133690133889
133691133890
/* If not building as part of the core, include sqlite3ext.h. */
133692133891
#ifndef SQLITE_CORE
133892
+/* # include "sqlite3ext.h" */
133693133893
SQLITE_EXTENSION_INIT3
133694133894
#endif
133695133895
133896
+/* #include "sqlite3.h" */
133696133897
/************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
133697133898
/************** Begin file fts3_tokenizer.h **********************************/
133698133899
/*
133699133900
** 2006 July 10
133700133901
**
@@ -133719,10 +133920,11 @@
133719133920
133720133921
/* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time.
133721133922
** If tokenizers are to be allowed to call sqlite3_*() functions, then
133722133923
** we will need a way to register the API consistently.
133723133924
*/
133925
+/* #include "sqlite3.h" */
133724133926
133725133927
/*
133726133928
** Structures used by the tokenizer interface. When a new tokenizer
133727133929
** implementation is registered, the caller provides a pointer to
133728133930
** an sqlite3_tokenizer_module containing pointers to the callback
@@ -134559,11 +134761,13 @@
134559134761
/* #include <stddef.h> */
134560134762
/* #include <stdio.h> */
134561134763
/* #include <string.h> */
134562134764
/* #include <stdarg.h> */
134563134765
134766
+/* #include "fts3.h" */
134564134767
#ifndef SQLITE_CORE
134768
+/* # include "sqlite3ext.h" */
134565134769
SQLITE_EXTENSION_INIT1
134566134770
#endif
134567134771
134568134772
static int fts3EvalNext(Fts3Cursor *pCsr);
134569134773
static int fts3EvalStart(Fts3Cursor *pCsr);
@@ -138486,11 +138690,10 @@
138486138690
** tokens or prefix tokens that cannot use a prefix-index. */
138487138691
int bHaveIncr = 0;
138488138692
int bIncrOk = (bOptOk
138489138693
&& pCsr->bDesc==pTab->bDescIdx
138490138694
&& p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
138491
- && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
138492138695
#ifdef SQLITE_TEST
138493138696
&& pTab->bNoIncrDoclist==0
138494138697
#endif
138495138698
);
138496138699
for(i=0; bIncrOk==1 && i<p->nToken; i++){
@@ -138606,10 +138809,11 @@
138606138809
if( p==0 ){
138607138810
p = aDoclist;
138608138811
p += sqlite3Fts3GetVarint(p, piDocid);
138609138812
}else{
138610138813
fts3PoslistCopy(0, &p);
138814
+ while( p<&aDoclist[nDoclist] && *p==0 ) p++;
138611138815
if( p>=&aDoclist[nDoclist] ){
138612138816
*pbEof = 1;
138613138817
}else{
138614138818
sqlite3_int64 iVar;
138615138819
p += sqlite3Fts3GetVarint(p, &iVar);
@@ -140012,14 +140216,14 @@
140012140216
pIter = pPhrase->doclist.pList;
140013140217
if( iDocid!=pCsr->iPrevId || pExpr->bEof ){
140014140218
int rc = SQLITE_OK;
140015140219
int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */
140016140220
int bOr = 0;
140017
- u8 bEof = 0;
140018140221
u8 bTreeEof = 0;
140019140222
Fts3Expr *p; /* Used to iterate from pExpr to root */
140020140223
Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */
140224
+ int bMatch;
140021140225
140022140226
/* Check if this phrase descends from an OR expression node. If not,
140023140227
** return NULL. Otherwise, the entry that corresponds to docid
140024140228
** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
140025140229
** tree that the node is part of has been marked as EOF, but the node
@@ -140049,35 +140253,51 @@
140049140253
fts3EvalNextRow(pCsr, pNear, &rc);
140050140254
}
140051140255
}
140052140256
if( rc!=SQLITE_OK ) return rc;
140053140257
140054
- pIter = pPhrase->pOrPoslist;
140055
- iDocid = pPhrase->iOrDocid;
140056
- if( pCsr->bDesc==bDescDoclist ){
140057
- bEof = !pPhrase->doclist.nAll ||
140058
- (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
140059
- while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
140060
- sqlite3Fts3DoclistNext(
140061
- bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
140062
- &pIter, &iDocid, &bEof
140063
- );
140064
- }
140065
- }else{
140066
- bEof = !pPhrase->doclist.nAll || (pIter && pIter<=pPhrase->doclist.aAll);
140067
- while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
140068
- int dummy;
140069
- sqlite3Fts3DoclistPrev(
140070
- bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
140071
- &pIter, &iDocid, &dummy, &bEof
140072
- );
140073
- }
140074
- }
140075
- pPhrase->pOrPoslist = pIter;
140076
- pPhrase->iOrDocid = iDocid;
140077
-
140078
- if( bEof || iDocid!=pCsr->iPrevId ) pIter = 0;
140258
+ bMatch = 1;
140259
+ for(p=pNear; p; p=p->pLeft){
140260
+ u8 bEof = 0;
140261
+ Fts3Expr *pTest = p;
140262
+ Fts3Phrase *pPh;
140263
+ assert( pTest->eType==FTSQUERY_NEAR || pTest->eType==FTSQUERY_PHRASE );
140264
+ if( pTest->eType==FTSQUERY_NEAR ) pTest = pTest->pRight;
140265
+ assert( pTest->eType==FTSQUERY_PHRASE );
140266
+ pPh = pTest->pPhrase;
140267
+
140268
+ pIter = pPh->pOrPoslist;
140269
+ iDocid = pPh->iOrDocid;
140270
+ if( pCsr->bDesc==bDescDoclist ){
140271
+ bEof = !pPh->doclist.nAll ||
140272
+ (pIter >= (pPh->doclist.aAll + pPh->doclist.nAll));
140273
+ while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
140274
+ sqlite3Fts3DoclistNext(
140275
+ bDescDoclist, pPh->doclist.aAll, pPh->doclist.nAll,
140276
+ &pIter, &iDocid, &bEof
140277
+ );
140278
+ }
140279
+ }else{
140280
+ bEof = !pPh->doclist.nAll || (pIter && pIter<=pPh->doclist.aAll);
140281
+ while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
140282
+ int dummy;
140283
+ sqlite3Fts3DoclistPrev(
140284
+ bDescDoclist, pPh->doclist.aAll, pPh->doclist.nAll,
140285
+ &pIter, &iDocid, &dummy, &bEof
140286
+ );
140287
+ }
140288
+ }
140289
+ pPh->pOrPoslist = pIter;
140290
+ pPh->iOrDocid = iDocid;
140291
+ if( bEof || iDocid!=pCsr->iPrevId ) bMatch = 0;
140292
+ }
140293
+
140294
+ if( bMatch ){
140295
+ pIter = pPhrase->pOrPoslist;
140296
+ }else{
140297
+ pIter = 0;
140298
+ }
140079140299
}
140080140300
if( pIter==0 ) return SQLITE_OK;
140081140301
140082140302
if( *pIter==0x01 ){
140083140303
pIter++;
@@ -140161,10 +140381,11 @@
140161140381
** May you share freely, never taking more than you give.
140162140382
**
140163140383
******************************************************************************
140164140384
**
140165140385
*/
140386
+/* #include "fts3Int.h" */
140166140387
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
140167140388
140168140389
/* #include <string.h> */
140169140390
/* #include <assert.h> */
140170140391
@@ -140717,10 +140938,11 @@
140717140938
** This module contains code that implements a parser for fts3 query strings
140718140939
** (the right-hand argument to the MATCH operator). Because the supported
140719140940
** syntax is relatively simple, the whole tokenizer/parser system is
140720140941
** hand-coded.
140721140942
*/
140943
+/* #include "fts3Int.h" */
140722140944
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
140723140945
140724140946
/*
140725140947
** By default, this module parses the legacy syntax that has been
140726140948
** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS
@@ -142010,16 +142232,18 @@
142010142232
** (in which case SQLITE_CORE is not defined), or
142011142233
**
142012142234
** * The FTS3 module is being built into the core of
142013142235
** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
142014142236
*/
142237
+/* #include "fts3Int.h" */
142015142238
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
142016142239
142017142240
/* #include <assert.h> */
142018142241
/* #include <stdlib.h> */
142019142242
/* #include <string.h> */
142020142243
142244
+/* #include "fts3_hash.h" */
142021142245
142022142246
/*
142023142247
** Malloc and Free functions
142024142248
*/
142025142249
static void *fts3HashMalloc(int n){
@@ -142393,17 +142617,19 @@
142393142617
** (in which case SQLITE_CORE is not defined), or
142394142618
**
142395142619
** * The FTS3 module is being built into the core of
142396142620
** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
142397142621
*/
142622
+/* #include "fts3Int.h" */
142398142623
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
142399142624
142400142625
/* #include <assert.h> */
142401142626
/* #include <stdlib.h> */
142402142627
/* #include <stdio.h> */
142403142628
/* #include <string.h> */
142404142629
142630
+/* #include "fts3_tokenizer.h" */
142405142631
142406142632
/*
142407142633
** Class derived from sqlite3_tokenizer
142408142634
*/
142409142635
typedef struct porter_tokenizer {
@@ -143057,10 +143283,11 @@
143057143283
** (in which case SQLITE_CORE is not defined), or
143058143284
**
143059143285
** * The FTS3 module is being built into the core of
143060143286
** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
143061143287
*/
143288
+/* #include "fts3Int.h" */
143062143289
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143063143290
143064143291
/* #include <assert.h> */
143065143292
/* #include <string.h> */
143066143293
@@ -143552,17 +143779,19 @@
143552143779
** (in which case SQLITE_CORE is not defined), or
143553143780
**
143554143781
** * The FTS3 module is being built into the core of
143555143782
** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
143556143783
*/
143784
+/* #include "fts3Int.h" */
143557143785
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143558143786
143559143787
/* #include <assert.h> */
143560143788
/* #include <stdlib.h> */
143561143789
/* #include <stdio.h> */
143562143790
/* #include <string.h> */
143563143791
143792
+/* #include "fts3_tokenizer.h" */
143564143793
143565143794
typedef struct simple_tokenizer {
143566143795
sqlite3_tokenizer base;
143567143796
char delim[128]; /* flag ASCII delimiters */
143568143797
} simple_tokenizer;
@@ -143803,10 +144032,11 @@
143803144032
** end: Byte offset of the byte immediately following the end of the
143804144033
** token within the input string.
143805144034
** pos: Token offset of token within input.
143806144035
**
143807144036
*/
144037
+/* #include "fts3Int.h" */
143808144038
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143809144039
143810144040
/* #include <string.h> */
143811144041
/* #include <assert.h> */
143812144042
@@ -144238,10 +144468,11 @@
144238144468
** tables. It also contains code to merge FTS3 b-tree segments. Some
144239144469
** of the sub-routines used to merge segments are also used by the query
144240144470
** code in fts3.c.
144241144471
*/
144242144472
144473
+/* #include "fts3Int.h" */
144243144474
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
144244144475
144245144476
/* #include <string.h> */
144246144477
/* #include <assert.h> */
144247144478
/* #include <stdlib.h> */
@@ -149898,10 +150129,11 @@
149898150129
** May you share freely, never taking more than you give.
149899150130
**
149900150131
******************************************************************************
149901150132
*/
149902150133
150134
+/* #include "fts3Int.h" */
149903150135
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
149904150136
149905150137
/* #include <string.h> */
149906150138
/* #include <assert.h> */
149907150139
@@ -151610,17 +151842,19 @@
151610151842
** Implementation of the "unicode" full-text-search tokenizer.
151611151843
*/
151612151844
151613151845
#ifndef SQLITE_DISABLE_FTS3_UNICODE
151614151846
151847
+/* #include "fts3Int.h" */
151615151848
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
151616151849
151617151850
/* #include <assert.h> */
151618151851
/* #include <stdlib.h> */
151619151852
/* #include <stdio.h> */
151620151853
/* #include <string.h> */
151621151854
151855
+/* #include "fts3_tokenizer.h" */
151622151856
151623151857
/*
151624151858
** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
151625151859
** from the sqlite3 source file utf.c. If this file is compiled as part
151626151860
** of the amalgamation, they are not required.
@@ -152412,12 +152646,14 @@
152412152646
*/
152413152647
152414152648
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
152415152649
152416152650
#ifndef SQLITE_CORE
152651
+/* #include "sqlite3ext.h" */
152417152652
SQLITE_EXTENSION_INIT1
152418152653
#else
152654
+/* #include "sqlite3.h" */
152419152655
#endif
152420152656
152421152657
/* #include <string.h> */
152422152658
/* #include <assert.h> */
152423152659
/* #include <stdio.h> */
@@ -155909,12 +156145,14 @@
155909156145
#include <unicode/ucol.h>
155910156146
155911156147
/* #include <assert.h> */
155912156148
155913156149
#ifndef SQLITE_CORE
156150
+/* #include "sqlite3ext.h" */
155914156151
SQLITE_EXTENSION_INIT1
155915156152
#else
156153
+/* #include "sqlite3.h" */
155916156154
#endif
155917156155
155918156156
/*
155919156157
** Maximum length (in bytes) of the pattern in a LIKE or GLOB
155920156158
** operator.
@@ -156386,15 +156624,17 @@
156386156624
** May you share freely, never taking more than you give.
156387156625
**
156388156626
*************************************************************************
156389156627
** This file implements a tokenizer for fts3 based on the ICU library.
156390156628
*/
156629
+/* #include "fts3Int.h" */
156391156630
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
156392156631
#ifdef SQLITE_ENABLE_ICU
156393156632
156394156633
/* #include <assert.h> */
156395156634
/* #include <string.h> */
156635
+/* #include "fts3_tokenizer.h" */
156396156636
156397156637
#include <unicode/ubrk.h>
156398156638
/* #include <unicode/ucol.h> */
156399156639
/* #include <unicode/ustring.h> */
156400156640
#include <unicode/utf16.h>
@@ -156635,11 +156875,11 @@
156635156875
156636156876
#endif /* defined(SQLITE_ENABLE_ICU) */
156637156877
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
156638156878
156639156879
/************** End of fts3_icu.c ********************************************/
156640
-/************** Begin file sqlite3ota.c **************************************/
156880
+/************** Begin file sqlite3rbu.c **************************************/
156641156881
/*
156642156882
** 2014 August 30
156643156883
**
156644156884
** The author disclaims copyright to this source code. In place of
156645156885
** a legal notice, here is a blessing:
@@ -156651,15 +156891,15 @@
156651156891
*************************************************************************
156652156892
**
156653156893
**
156654156894
** OVERVIEW
156655156895
**
156656
-** The OTA extension requires that the OTA update be packaged as an
156896
+** The RBU extension requires that the RBU update be packaged as an
156657156897
** SQLite database. The tables it expects to find are described in
156658
-** sqlite3ota.h. Essentially, for each table xyz in the target database
156898
+** sqlite3rbu.h. Essentially, for each table xyz in the target database
156659156899
** that the user wishes to write to, a corresponding data_xyz table is
156660
-** created in the OTA database and populated with one row for each row to
156900
+** created in the RBU database and populated with one row for each row to
156661156901
** update, insert or delete from the target table.
156662156902
**
156663156903
** The update proceeds in three stages:
156664156904
**
156665156905
** 1) The database is updated. The modified database pages are written
@@ -156667,70 +156907,74 @@
156667156907
** that it is named "<database>-oal" instead of "<database>-wal".
156668156908
** Because regular SQLite clients do not look for file named
156669156909
** "<database>-oal", they go on using the original database in
156670156910
** rollback mode while the *-oal file is being generated.
156671156911
**
156672
-** During this stage OTA does not update the database by writing
156912
+** During this stage RBU does not update the database by writing
156673156913
** directly to the target tables. Instead it creates "imposter"
156674156914
** tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses
156675156915
** to update each b-tree individually. All updates required by each
156676156916
** b-tree are completed before moving on to the next, and all
156677156917
** updates are done in sorted key order.
156678156918
**
156679156919
** 2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
156680
-** location using a call to rename(2). Before doing this the OTA
156920
+** location using a call to rename(2). Before doing this the RBU
156681156921
** module takes an EXCLUSIVE lock on the database file, ensuring
156682156922
** that there are no other active readers.
156683156923
**
156684156924
** Once the EXCLUSIVE lock is released, any other database readers
156685156925
** detect the new *-wal file and read the database in wal mode. At
156686156926
** this point they see the new version of the database - including
156687
-** the updates made as part of the OTA update.
156927
+** the updates made as part of the RBU update.
156688156928
**
156689156929
** 3) The new *-wal file is checkpointed. This proceeds in the same way
156690156930
** as a regular database checkpoint, except that a single frame is
156691
-** checkpointed each time sqlite3ota_step() is called. If the OTA
156931
+** checkpointed each time sqlite3rbu_step() is called. If the RBU
156692156932
** handle is closed before the entire *-wal file is checkpointed,
156693
-** the checkpoint progress is saved in the OTA database and the
156694
-** checkpoint can be resumed by another OTA client at some point in
156933
+** the checkpoint progress is saved in the RBU database and the
156934
+** checkpoint can be resumed by another RBU client at some point in
156695156935
** the future.
156696156936
**
156697156937
** POTENTIAL PROBLEMS
156698156938
**
156699
-** The rename() call might not be portable. And OTA is not currently
156939
+** The rename() call might not be portable. And RBU is not currently
156700156940
** syncing the directory after renaming the file.
156701156941
**
156702156942
** When state is saved, any commit to the *-oal file and the commit to
156703
-** the OTA update database are not atomic. So if the power fails at the
156943
+** the RBU update database are not atomic. So if the power fails at the
156704156944
** wrong moment they might get out of sync. As the main database will be
156705
-** committed before the OTA update database this will likely either just
156945
+** committed before the RBU update database this will likely either just
156706156946
** pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
156707156947
** constraint violations).
156708156948
**
156709
-** If some client does modify the target database mid OTA update, or some
156710
-** other error occurs, the OTA extension will keep throwing errors. It's
156949
+** If some client does modify the target database mid RBU update, or some
156950
+** other error occurs, the RBU extension will keep throwing errors. It's
156711156951
** not really clear how to get out of this state. The system could just
156712
-** by delete the OTA update database and *-oal file and have the device
156952
+** by delete the RBU update database and *-oal file and have the device
156713156953
** download the update again and start over.
156714156954
**
156715156955
** At present, for an UPDATE, both the new.* and old.* records are
156716
-** collected in the ota_xyz table. And for both UPDATEs and DELETEs all
156956
+** collected in the rbu_xyz table. And for both UPDATEs and DELETEs all
156717156957
** fields are collected. This means we're probably writing a lot more
156718
-** data to disk when saving the state of an ongoing update to the OTA
156958
+** data to disk when saving the state of an ongoing update to the RBU
156719156959
** update database than is strictly necessary.
156720156960
**
156721156961
*/
156722156962
156723156963
/* #include <assert.h> */
156724156964
/* #include <string.h> */
156725156965
/* #include <stdio.h> */
156726
-/* #include <unistd.h> */
156727156966
156967
+#if !defined(_WIN32)
156968
+/* # include <unistd.h> */
156969
+#endif
156728156970
156729
-#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA)
156730
-/************** Include sqlite3ota.h in the middle of sqlite3ota.c ***********/
156731
-/************** Begin file sqlite3ota.h **************************************/
156971
+/* #include "sqlite3.h" */
156972
+
156973
+#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
156974
+/************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
156975
+/************** Begin file sqlite3rbu.h **************************************/
156732156976
/*
156733156977
** 2014 August 30
156734156978
**
156735156979
** The author disclaims copyright to this source code. In place of
156736156980
** a legal notice, here is a blessing:
@@ -156739,11 +156983,11 @@
156739156983
** May you find forgiveness for yourself and forgive others.
156740156984
** May you share freely, never taking more than you give.
156741156985
**
156742156986
*************************************************************************
156743156987
**
156744
-** This file contains the public interface for the OTA extension.
156988
+** This file contains the public interface for the RBU extension.
156745156989
*/
156746156990
156747156991
/*
156748156992
** SUMMARY
156749156993
**
@@ -156776,18 +157020,18 @@
156776157020
** mobile device that is frequently rebooted. Even after the writer process
156777157021
** has committed one or more sub-transactions, other database clients continue
156778157022
** to read from the original database snapshot. In other words, partially
156779157023
** applied transactions are not visible to other clients.
156780157024
**
156781
-** "OTA" stands for "Over The Air" update. As in a large database update
157025
+** "RBU" stands for "Resumable Bulk Update". As in a large database update
156782157026
** transmitted via a wireless network to a mobile device. A transaction
156783
-** applied using this extension is hence refered to as an "OTA update".
157027
+** applied using this extension is hence refered to as an "RBU update".
156784157028
**
156785157029
**
156786157030
** LIMITATIONS
156787157031
**
156788
-** An "OTA update" transaction is subject to the following limitations:
157032
+** An "RBU update" transaction is subject to the following limitations:
156789157033
**
156790157034
** * The transaction must consist of INSERT, UPDATE and DELETE operations
156791157035
** only.
156792157036
**
156793157037
** * INSERT statements may not use any default values.
@@ -156808,430 +157052,430 @@
156808157052
** * No constraint handling mode except for "OR ROLLBACK" is supported.
156809157053
**
156810157054
**
156811157055
** PREPARATION
156812157056
**
156813
-** An "OTA update" is stored as a separate SQLite database. A database
156814
-** containing an OTA update is an "OTA database". For each table in the
156815
-** target database to be updated, the OTA database should contain a table
157057
+** An "RBU update" is stored as a separate SQLite database. A database
157058
+** containing an RBU update is an "RBU database". For each table in the
157059
+** target database to be updated, the RBU database should contain a table
156816157060
** named "data_<target name>" containing the same set of columns as the
156817
-** target table, and one more - "ota_control". The data_% table should
157061
+** target table, and one more - "rbu_control". The data_% table should
156818157062
** have no PRIMARY KEY or UNIQUE constraints, but each column should have
156819157063
** the same type as the corresponding column in the target database.
156820
-** The "ota_control" column should have no type at all. For example, if
157064
+** The "rbu_control" column should have no type at all. For example, if
156821157065
** the target database contains:
156822157066
**
156823157067
** CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE);
156824157068
**
156825
-** Then the OTA database should contain:
157069
+** Then the RBU database should contain:
156826157070
**
156827
-** CREATE TABLE data_t1(a INTEGER, b TEXT, c, ota_control);
157071
+** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
156828157072
**
156829157073
** The order of the columns in the data_% table does not matter.
156830157074
**
156831157075
** If the target database table is a virtual table or a table that has no
156832157076
** PRIMARY KEY declaration, the data_% table must also contain a column
156833
-** named "ota_rowid". This column is mapped to the tables implicit primary
157077
+** named "rbu_rowid". This column is mapped to the tables implicit primary
156834157078
** key column - "rowid". Virtual tables for which the "rowid" column does
156835
-** not function like a primary key value cannot be updated using OTA. For
157079
+** not function like a primary key value cannot be updated using RBU. For
156836157080
** example, if the target db contains either of the following:
156837157081
**
156838157082
** CREATE VIRTUAL TABLE x1 USING fts3(a, b);
156839157083
** CREATE TABLE x1(a, b)
156840157084
**
156841
-** then the OTA database should contain:
157085
+** then the RBU database should contain:
156842157086
**
156843
-** CREATE TABLE data_x1(a, b, ota_rowid, ota_control);
157087
+** CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control);
156844157088
**
156845157089
** All non-hidden columns (i.e. all columns matched by "SELECT *") of the
156846157090
** target table must be present in the input table. For virtual tables,
156847
-** hidden columns are optional - they are updated by OTA if present in
157091
+** hidden columns are optional - they are updated by RBU if present in
156848157092
** the input table, or not otherwise. For example, to write to an fts4
156849157093
** table with a hidden languageid column such as:
156850157094
**
156851157095
** CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid');
156852157096
**
156853157097
** Either of the following input table schemas may be used:
156854157098
**
156855
-** CREATE TABLE data_ft1(a, b, langid, ota_rowid, ota_control);
156856
-** CREATE TABLE data_ft1(a, b, ota_rowid, ota_control);
157099
+** CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control);
157100
+** CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control);
156857157101
**
156858
-** For each row to INSERT into the target database as part of the OTA
157102
+** For each row to INSERT into the target database as part of the RBU
156859157103
** update, the corresponding data_% table should contain a single record
156860
-** with the "ota_control" column set to contain integer value 0. The
157104
+** with the "rbu_control" column set to contain integer value 0. The
156861157105
** other columns should be set to the values that make up the new record
156862157106
** to insert.
156863157107
**
156864157108
** If the target database table has an INTEGER PRIMARY KEY, it is not
156865157109
** possible to insert a NULL value into the IPK column. Attempting to
156866157110
** do so results in an SQLITE_MISMATCH error.
156867157111
**
156868
-** For each row to DELETE from the target database as part of the OTA
157112
+** For each row to DELETE from the target database as part of the RBU
156869157113
** update, the corresponding data_% table should contain a single record
156870
-** with the "ota_control" column set to contain integer value 1. The
157114
+** with the "rbu_control" column set to contain integer value 1. The
156871157115
** real primary key values of the row to delete should be stored in the
156872157116
** corresponding columns of the data_% table. The values stored in the
156873157117
** other columns are not used.
156874157118
**
156875
-** For each row to UPDATE from the target database as part of the OTA
157119
+** For each row to UPDATE from the target database as part of the RBU
156876157120
** update, the corresponding data_% table should contain a single record
156877
-** with the "ota_control" column set to contain a value of type text.
157121
+** with the "rbu_control" column set to contain a value of type text.
156878157122
** The real primary key values identifying the row to update should be
156879157123
** stored in the corresponding columns of the data_% table row, as should
156880157124
** the new values of all columns being update. The text value in the
156881
-** "ota_control" column must contain the same number of characters as
157125
+** "rbu_control" column must contain the same number of characters as
156882157126
** there are columns in the target database table, and must consist entirely
156883157127
** of 'x' and '.' characters (or in some special cases 'd' - see below). For
156884157128
** each column that is being updated, the corresponding character is set to
156885157129
** 'x'. For those that remain as they are, the corresponding character of the
156886
-** ota_control value should be set to '.'. For example, given the tables
157130
+** rbu_control value should be set to '.'. For example, given the tables
156887157131
** above, the update statement:
156888157132
**
156889157133
** UPDATE t1 SET c = 'usa' WHERE a = 4;
156890157134
**
156891157135
** is represented by the data_t1 row created by:
156892157136
**
156893
-** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..x');
157137
+** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..x');
156894157138
**
156895
-** Instead of an 'x' character, characters of the ota_control value specified
157139
+** Instead of an 'x' character, characters of the rbu_control value specified
156896157140
** for UPDATEs may also be set to 'd'. In this case, instead of updating the
156897157141
** target table with the value stored in the corresponding data_% column, the
156898
-** user-defined SQL function "ota_delta()" is invoked and the result stored in
156899
-** the target table column. ota_delta() is invoked with two arguments - the
157142
+** user-defined SQL function "rbu_delta()" is invoked and the result stored in
157143
+** the target table column. rbu_delta() is invoked with two arguments - the
156900157144
** original value currently stored in the target table column and the
156901157145
** value specified in the data_xxx table.
156902157146
**
156903157147
** For example, this row:
156904157148
**
156905
-** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..d');
157149
+** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
156906157150
**
156907157151
** is similar to an UPDATE statement such as:
156908157152
**
156909
-** UPDATE t1 SET c = ota_delta(c, 'usa') WHERE a = 4;
157153
+** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
156910157154
**
156911157155
** If the target database table is a virtual table or a table with no PRIMARY
156912
-** KEY, the ota_control value should not include a character corresponding
156913
-** to the ota_rowid value. For example, this:
157156
+** KEY, the rbu_control value should not include a character corresponding
157157
+** to the rbu_rowid value. For example, this:
156914157158
**
156915
-** INSERT INTO data_ft1(a, b, ota_rowid, ota_control)
157159
+** INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control)
156916157160
** VALUES(NULL, 'usa', 12, '.x');
156917157161
**
156918157162
** causes a result similar to:
156919157163
**
156920157164
** UPDATE ft1 SET b = 'usa' WHERE rowid = 12;
156921157165
**
156922157166
** The data_xxx tables themselves should have no PRIMARY KEY declarations.
156923
-** However, OTA is more efficient if reading the rows in from each data_xxx
157167
+** However, RBU is more efficient if reading the rows in from each data_xxx
156924157168
** table in "rowid" order is roughly the same as reading them sorted by
156925157169
** the PRIMARY KEY of the corresponding target database table. In other
156926157170
** words, rows should be sorted using the destination table PRIMARY KEY
156927157171
** fields before they are inserted into the data_xxx tables.
156928157172
**
156929157173
** USAGE
156930157174
**
156931
-** The API declared below allows an application to apply an OTA update
157175
+** The API declared below allows an application to apply an RBU update
156932157176
** stored on disk to an existing target database. Essentially, the
156933157177
** application:
156934157178
**
156935
-** 1) Opens an OTA handle using the sqlite3ota_open() function.
157179
+** 1) Opens an RBU handle using the sqlite3rbu_open() function.
156936157180
**
156937157181
** 2) Registers any required virtual table modules with the database
156938
-** handle returned by sqlite3ota_db(). Also, if required, register
156939
-** the ota_delta() implementation.
157182
+** handle returned by sqlite3rbu_db(). Also, if required, register
157183
+** the rbu_delta() implementation.
156940157184
**
156941
-** 3) Calls the sqlite3ota_step() function one or more times on
156942
-** the new handle. Each call to sqlite3ota_step() performs a single
157185
+** 3) Calls the sqlite3rbu_step() function one or more times on
157186
+** the new handle. Each call to sqlite3rbu_step() performs a single
156943157187
** b-tree operation, so thousands of calls may be required to apply
156944157188
** a complete update.
156945157189
**
156946
-** 4) Calls sqlite3ota_close() to close the OTA update handle. If
156947
-** sqlite3ota_step() has been called enough times to completely
156948
-** apply the update to the target database, then the OTA database
156949
-** is marked as fully applied. Otherwise, the state of the OTA
156950
-** update application is saved in the OTA database for later
157190
+** 4) Calls sqlite3rbu_close() to close the RBU update handle. If
157191
+** sqlite3rbu_step() has been called enough times to completely
157192
+** apply the update to the target database, then the RBU database
157193
+** is marked as fully applied. Otherwise, the state of the RBU
157194
+** update application is saved in the RBU database for later
156951157195
** resumption.
156952157196
**
156953157197
** See comments below for more detail on APIs.
156954157198
**
156955157199
** If an update is only partially applied to the target database by the
156956
-** time sqlite3ota_close() is called, various state information is saved
156957
-** within the OTA database. This allows subsequent processes to automatically
156958
-** resume the OTA update from where it left off.
157200
+** time sqlite3rbu_close() is called, various state information is saved
157201
+** within the RBU database. This allows subsequent processes to automatically
157202
+** resume the RBU update from where it left off.
156959157203
**
156960
-** To remove all OTA extension state information, returning an OTA database
157204
+** To remove all RBU extension state information, returning an RBU database
156961157205
** to its original contents, it is sufficient to drop all tables that begin
156962
-** with the prefix "ota_"
157206
+** with the prefix "rbu_"
156963157207
**
156964157208
** DATABASE LOCKING
156965157209
**
156966
-** An OTA update may not be applied to a database in WAL mode. Attempting
157210
+** An RBU update may not be applied to a database in WAL mode. Attempting
156967157211
** to do so is an error (SQLITE_ERROR).
156968157212
**
156969
-** While an OTA handle is open, a SHARED lock may be held on the target
157213
+** While an RBU handle is open, a SHARED lock may be held on the target
156970157214
** database file. This means it is possible for other clients to read the
156971157215
** database, but not to write it.
156972157216
**
156973
-** If an OTA update is started and then suspended before it is completed,
157217
+** If an RBU update is started and then suspended before it is completed,
156974157218
** then an external client writes to the database, then attempting to resume
156975
-** the suspended OTA update is also an error (SQLITE_BUSY).
157219
+** the suspended RBU update is also an error (SQLITE_BUSY).
156976157220
*/
156977157221
156978
-#ifndef _SQLITE3OTA_H
156979
-#define _SQLITE3OTA_H
157222
+#ifndef _SQLITE3RBU_H
157223
+#define _SQLITE3RBU_H
156980157224
157225
+/* #include "sqlite3.h" ** Required for error code definitions ** */
156981157226
156982
-typedef struct sqlite3ota sqlite3ota;
157227
+typedef struct sqlite3rbu sqlite3rbu;
156983157228
156984157229
/*
156985
-** Open an OTA handle.
157230
+** Open an RBU handle.
156986157231
**
156987
-** Argument zTarget is the path to the target database. Argument zOta is
156988
-** the path to the OTA database. Each call to this function must be matched
156989
-** by a call to sqlite3ota_close(). When opening the databases, OTA passes
157232
+** Argument zTarget is the path to the target database. Argument zRbu is
157233
+** the path to the RBU database. Each call to this function must be matched
157234
+** by a call to sqlite3rbu_close(). When opening the databases, RBU passes
156990157235
** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget
156991
-** or zOta begin with "file:", it will be interpreted as an SQLite
157236
+** or zRbu begin with "file:", it will be interpreted as an SQLite
156992157237
** database URI, not a regular file name.
156993157238
**
156994
-** If the zState argument is passed a NULL value, the OTA extension stores
157239
+** If the zState argument is passed a NULL value, the RBU extension stores
156995157240
** the current state of the update (how many rows have been updated, which
156996
-** indexes are yet to be updated etc.) within the OTA database itself. This
156997
-** can be convenient, as it means that the OTA application does not need to
157241
+** indexes are yet to be updated etc.) within the RBU database itself. This
157242
+** can be convenient, as it means that the RBU application does not need to
156998157243
** organize removing a separate state file after the update is concluded.
156999157244
** Or, if zState is non-NULL, it must be a path to a database file in which
157000
-** the OTA extension can store the state of the update.
157245
+** the RBU extension can store the state of the update.
157001157246
**
157002
-** When resuming an OTA update, the zState argument must be passed the same
157003
-** value as when the OTA update was started.
157247
+** When resuming an RBU update, the zState argument must be passed the same
157248
+** value as when the RBU update was started.
157004157249
**
157005
-** Once the OTA update is finished, the OTA extension does not
157250
+** Once the RBU update is finished, the RBU extension does not
157006157251
** automatically remove any zState database file, even if it created it.
157007157252
**
157008
-** By default, OTA uses the default VFS to access the files on disk. To
157253
+** By default, RBU uses the default VFS to access the files on disk. To
157009157254
** use a VFS other than the default, an SQLite "file:" URI containing a
157010157255
** "vfs=..." option may be passed as the zTarget option.
157011157256
**
157012
-** IMPORTANT NOTE FOR ZIPVFS USERS: The OTA extension works with all of
157257
+** IMPORTANT NOTE FOR ZIPVFS USERS: The RBU extension works with all of
157013157258
** SQLite's built-in VFSs, including the multiplexor VFS. However it does
157014157259
** not work out of the box with zipvfs. Refer to the comment describing
157015
-** the zipvfs_create_vfs() API below for details on using OTA with zipvfs.
157260
+** the zipvfs_create_vfs() API below for details on using RBU with zipvfs.
157016157261
*/
157017
-SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open(
157262
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
157018157263
const char *zTarget,
157019
- const char *zOta,
157264
+ const char *zRbu,
157020157265
const char *zState
157021157266
);
157022157267
157023157268
/*
157024
-** Internally, each OTA connection uses a separate SQLite database
157025
-** connection to access the target and ota update databases. This
157269
+** Internally, each RBU connection uses a separate SQLite database
157270
+** connection to access the target and rbu update databases. This
157026157271
** API allows the application direct access to these database handles.
157027157272
**
157028
-** The first argument passed to this function must be a valid, open, OTA
157273
+** The first argument passed to this function must be a valid, open, RBU
157029157274
** handle. The second argument should be passed zero to access the target
157030
-** database handle, or non-zero to access the ota update database handle.
157275
+** database handle, or non-zero to access the rbu update database handle.
157031157276
** Accessing the underlying database handles may be useful in the
157032157277
** following scenarios:
157033157278
**
157034157279
** * If any target tables are virtual tables, it may be necessary to
157035157280
** call sqlite3_create_module() on the target database handle to
157036157281
** register the required virtual table implementations.
157037157282
**
157038
-** * If the data_xxx tables in the OTA source database are virtual
157283
+** * If the data_xxx tables in the RBU source database are virtual
157039157284
** tables, the application may need to call sqlite3_create_module() on
157040
-** the ota update db handle to any required virtual table
157285
+** the rbu update db handle to any required virtual table
157041157286
** implementations.
157042157287
**
157043
-** * If the application uses the "ota_delta()" feature described above,
157288
+** * If the application uses the "rbu_delta()" feature described above,
157044157289
** it must use sqlite3_create_function() or similar to register the
157045
-** ota_delta() implementation with the target database handle.
157290
+** rbu_delta() implementation with the target database handle.
157046157291
**
157047
-** If an error has occurred, either while opening or stepping the OTA object,
157292
+** If an error has occurred, either while opening or stepping the RBU object,
157048157293
** this function may return NULL. The error code and message may be collected
157049
-** when sqlite3ota_close() is called.
157294
+** when sqlite3rbu_close() is called.
157050157295
*/
157051
-SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota*, int bOta);
157296
+SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu*, int bRbu);
157052157297
157053157298
/*
157054
-** Do some work towards applying the OTA update to the target db.
157299
+** Do some work towards applying the RBU update to the target db.
157055157300
**
157056157301
** Return SQLITE_DONE if the update has been completely applied, or
157057157302
** SQLITE_OK if no error occurs but there remains work to do to apply
157058
-** the OTA update. If an error does occur, some other error code is
157303
+** the RBU update. If an error does occur, some other error code is
157059157304
** returned.
157060157305
**
157061
-** Once a call to sqlite3ota_step() has returned a value other than
157062
-** SQLITE_OK, all subsequent calls on the same OTA handle are no-ops
157306
+** Once a call to sqlite3rbu_step() has returned a value other than
157307
+** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
157063157308
** that immediately return the same value.
157064157309
*/
157065
-SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *pOta);
157310
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu);
157066157311
157067157312
/*
157068
-** Close an OTA handle.
157313
+** Close an RBU handle.
157069157314
**
157070
-** If the OTA update has been completely applied, mark the OTA database
157315
+** If the RBU update has been completely applied, mark the RBU database
157071157316
** as fully applied. Otherwise, assuming no error has occurred, save the
157072
-** current state of the OTA update appliation to the OTA database.
157317
+** current state of the RBU update appliation to the RBU database.
157073157318
**
157074
-** If an error has already occurred as part of an sqlite3ota_step()
157075
-** or sqlite3ota_open() call, or if one occurs within this function, an
157319
+** If an error has already occurred as part of an sqlite3rbu_step()
157320
+** or sqlite3rbu_open() call, or if one occurs within this function, an
157076157321
** SQLite error code is returned. Additionally, *pzErrmsg may be set to
157077157322
** point to a buffer containing a utf-8 formatted English language error
157078157323
** message. It is the responsibility of the caller to eventually free any
157079157324
** such buffer using sqlite3_free().
157080157325
**
157081157326
** Otherwise, if no error occurs, this function returns SQLITE_OK if the
157082157327
** update has been partially applied, or SQLITE_DONE if it has been
157083157328
** completely applied.
157084157329
*/
157085
-SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *pOta, char **pzErrmsg);
157330
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *pRbu, char **pzErrmsg);
157086157331
157087157332
/*
157088157333
** Return the total number of key-value operations (inserts, deletes or
157089157334
** updates) that have been performed on the target database since the
157090
-** current OTA update was started.
157335
+** current RBU update was started.
157091157336
*/
157092
-SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta);
157337
+SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu);
157093157338
157094157339
/*
157095
-** Create an OTA VFS named zName that accesses the underlying file-system
157340
+** Create an RBU VFS named zName that accesses the underlying file-system
157096157341
** via existing VFS zParent. Or, if the zParent parameter is passed NULL,
157097
-** then the new OTA VFS uses the default system VFS to access the file-system.
157342
+** then the new RBU VFS uses the default system VFS to access the file-system.
157098157343
** The new object is registered as a non-default VFS with SQLite before
157099157344
** returning.
157100157345
**
157101
-** Part of the OTA implementation uses a custom VFS object. Usually, this
157102
-** object is created and deleted automatically by OTA.
157346
+** Part of the RBU implementation uses a custom VFS object. Usually, this
157347
+** object is created and deleted automatically by RBU.
157103157348
**
157104157349
** The exception is for applications that also use zipvfs. In this case,
157105
-** the custom VFS must be explicitly created by the user before the OTA
157106
-** handle is opened. The OTA VFS should be installed so that the zipvfs
157107
-** VFS uses the OTA VFS, which in turn uses any other VFS layers in use
157350
+** the custom VFS must be explicitly created by the user before the RBU
157351
+** handle is opened. The RBU VFS should be installed so that the zipvfs
157352
+** VFS uses the RBU VFS, which in turn uses any other VFS layers in use
157108157353
** (for example multiplexor) to access the file-system. For example,
157109
-** to assemble an OTA enabled VFS stack that uses both zipvfs and
157354
+** to assemble an RBU enabled VFS stack that uses both zipvfs and
157110157355
** multiplexor (error checking omitted):
157111157356
**
157112157357
** // Create a VFS named "multiplex" (not the default).
157113157358
** sqlite3_multiplex_initialize(0, 0);
157114157359
**
157115
-** // Create an ota VFS named "ota" that uses multiplexor. If the
157116
-** // second argument were replaced with NULL, the "ota" VFS would
157360
+** // Create an rbu VFS named "rbu" that uses multiplexor. If the
157361
+** // second argument were replaced with NULL, the "rbu" VFS would
157117157362
** // access the file-system via the system default VFS, bypassing the
157118157363
** // multiplexor.
157119
-** sqlite3ota_create_vfs("ota", "multiplex");
157364
+** sqlite3rbu_create_vfs("rbu", "multiplex");
157120157365
**
157121
-** // Create a zipvfs VFS named "zipvfs" that uses ota.
157122
-** zipvfs_create_vfs_v3("zipvfs", "ota", 0, xCompressorAlgorithmDetector);
157366
+** // Create a zipvfs VFS named "zipvfs" that uses rbu.
157367
+** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector);
157123157368
**
157124157369
** // Make zipvfs the default VFS.
157125157370
** sqlite3_vfs_register(sqlite3_vfs_find("zipvfs"), 1);
157126157371
**
157127
-** Because the default VFS created above includes a OTA functionality, it
157128
-** may be used by OTA clients. Attempting to use OTA with a zipvfs VFS stack
157129
-** that does not include the OTA layer results in an error.
157372
+** Because the default VFS created above includes a RBU functionality, it
157373
+** may be used by RBU clients. Attempting to use RBU with a zipvfs VFS stack
157374
+** that does not include the RBU layer results in an error.
157130157375
**
157131
-** The overhead of adding the "ota" VFS to the system is negligible for
157132
-** non-OTA users. There is no harm in an application accessing the
157133
-** file-system via "ota" all the time, even if it only uses OTA functionality
157376
+** The overhead of adding the "rbu" VFS to the system is negligible for
157377
+** non-RBU users. There is no harm in an application accessing the
157378
+** file-system via "rbu" all the time, even if it only uses RBU functionality
157134157379
** occasionally.
157135157380
*/
157136
-SQLITE_API int SQLITE_STDCALL sqlite3ota_create_vfs(const char *zName, const char *zParent);
157381
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_create_vfs(const char *zName, const char *zParent);
157137157382
157138157383
/*
157139
-** Deregister and destroy an OTA vfs created by an earlier call to
157140
-** sqlite3ota_create_vfs().
157384
+** Deregister and destroy an RBU vfs created by an earlier call to
157385
+** sqlite3rbu_create_vfs().
157141157386
**
157142157387
** VFS objects are not reference counted. If a VFS object is destroyed
157143157388
** before all database handles that use it have been closed, the results
157144157389
** are undefined.
157145157390
*/
157146
-SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName);
157391
+SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName);
157147157392
157148
-#endif /* _SQLITE3OTA_H */
157393
+#endif /* _SQLITE3RBU_H */
157149157394
157150
-
157151
-/************** End of sqlite3ota.h ******************************************/
157152
-/************** Continuing where we left off in sqlite3ota.c *****************/
157395
+/************** End of sqlite3rbu.h ******************************************/
157396
+/************** Continuing where we left off in sqlite3rbu.c *****************/
157153157397
157154157398
/* Maximum number of prepared UPDATE statements held by this module */
157155
-#define SQLITE_OTA_UPDATE_CACHESIZE 16
157399
+#define SQLITE_RBU_UPDATE_CACHESIZE 16
157156157400
157157157401
/*
157158157402
** Swap two objects of type TYPE.
157159157403
*/
157160157404
#if !defined(SQLITE_AMALGAMATION)
157161157405
# define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
157162157406
#endif
157163157407
157164157408
/*
157165
-** The ota_state table is used to save the state of a partially applied
157409
+** The rbu_state table is used to save the state of a partially applied
157166157410
** update so that it can be resumed later. The table consists of integer
157167157411
** keys mapped to values as follows:
157168157412
**
157169
-** OTA_STATE_STAGE:
157413
+** RBU_STATE_STAGE:
157170157414
** May be set to integer values 1, 2, 4 or 5. As follows:
157171
-** 1: the *-ota file is currently under construction.
157172
-** 2: the *-ota file has been constructed, but not yet moved
157415
+** 1: the *-rbu file is currently under construction.
157416
+** 2: the *-rbu file has been constructed, but not yet moved
157173157417
** to the *-wal path.
157174157418
** 4: the checkpoint is underway.
157175
-** 5: the ota update has been checkpointed.
157419
+** 5: the rbu update has been checkpointed.
157176157420
**
157177
-** OTA_STATE_TBL:
157421
+** RBU_STATE_TBL:
157178157422
** Only valid if STAGE==1. The target database name of the table
157179157423
** currently being written.
157180157424
**
157181
-** OTA_STATE_IDX:
157425
+** RBU_STATE_IDX:
157182157426
** Only valid if STAGE==1. The target database name of the index
157183157427
** currently being written, or NULL if the main table is currently being
157184157428
** updated.
157185157429
**
157186
-** OTA_STATE_ROW:
157430
+** RBU_STATE_ROW:
157187157431
** Only valid if STAGE==1. Number of rows already processed for the current
157188157432
** table/index.
157189157433
**
157190
-** OTA_STATE_PROGRESS:
157191
-** Total number of sqlite3ota_step() calls made so far as part of this
157192
-** ota update.
157434
+** RBU_STATE_PROGRESS:
157435
+** Trbul number of sqlite3rbu_step() calls made so far as part of this
157436
+** rbu update.
157193157437
**
157194
-** OTA_STATE_CKPT:
157438
+** RBU_STATE_CKPT:
157195157439
** Valid if STAGE==4. The 64-bit checksum associated with the wal-index
157196157440
** header created by recovering the *-wal file. This is used to detect
157197157441
** cases when another client appends frames to the *-wal file in the
157198157442
** middle of an incremental checkpoint (an incremental checkpoint cannot
157199157443
** be continued if this happens).
157200157444
**
157201
-** OTA_STATE_COOKIE:
157445
+** RBU_STATE_COOKIE:
157202157446
** Valid if STAGE==1. The current change-counter cookie value in the
157203157447
** target db file.
157204157448
**
157205
-** OTA_STATE_OALSZ:
157449
+** RBU_STATE_OALSZ:
157206157450
** Valid if STAGE==1. The size in bytes of the *-oal file.
157207157451
*/
157208
-#define OTA_STATE_STAGE 1
157209
-#define OTA_STATE_TBL 2
157210
-#define OTA_STATE_IDX 3
157211
-#define OTA_STATE_ROW 4
157212
-#define OTA_STATE_PROGRESS 5
157213
-#define OTA_STATE_CKPT 6
157214
-#define OTA_STATE_COOKIE 7
157215
-#define OTA_STATE_OALSZ 8
157216
-
157217
-#define OTA_STAGE_OAL 1
157218
-#define OTA_STAGE_MOVE 2
157219
-#define OTA_STAGE_CAPTURE 3
157220
-#define OTA_STAGE_CKPT 4
157221
-#define OTA_STAGE_DONE 5
157222
-
157223
-
157224
-#define OTA_CREATE_STATE \
157225
- "CREATE TABLE IF NOT EXISTS %s.ota_state(k INTEGER PRIMARY KEY, v)"
157226
-
157227
-typedef struct OtaFrame OtaFrame;
157228
-typedef struct OtaObjIter OtaObjIter;
157229
-typedef struct OtaState OtaState;
157230
-typedef struct ota_vfs ota_vfs;
157231
-typedef struct ota_file ota_file;
157232
-typedef struct OtaUpdateStmt OtaUpdateStmt;
157452
+#define RBU_STATE_STAGE 1
157453
+#define RBU_STATE_TBL 2
157454
+#define RBU_STATE_IDX 3
157455
+#define RBU_STATE_ROW 4
157456
+#define RBU_STATE_PROGRESS 5
157457
+#define RBU_STATE_CKPT 6
157458
+#define RBU_STATE_COOKIE 7
157459
+#define RBU_STATE_OALSZ 8
157460
+
157461
+#define RBU_STAGE_OAL 1
157462
+#define RBU_STAGE_MOVE 2
157463
+#define RBU_STAGE_CAPTURE 3
157464
+#define RBU_STAGE_CKPT 4
157465
+#define RBU_STAGE_DONE 5
157466
+
157467
+
157468
+#define RBU_CREATE_STATE \
157469
+ "CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)"
157470
+
157471
+typedef struct RbuFrame RbuFrame;
157472
+typedef struct RbuObjIter RbuObjIter;
157473
+typedef struct RbuState RbuState;
157474
+typedef struct rbu_vfs rbu_vfs;
157475
+typedef struct rbu_file rbu_file;
157476
+typedef struct RbuUpdateStmt RbuUpdateStmt;
157233157477
157234157478
#if !defined(SQLITE_AMALGAMATION)
157235157479
typedef unsigned int u32;
157236157480
typedef unsigned char u8;
157237157481
typedef sqlite3_int64 i64;
@@ -157245,13 +157489,13 @@
157245157489
#define WAL_LOCK_WRITE 0
157246157490
#define WAL_LOCK_CKPT 1
157247157491
#define WAL_LOCK_READ0 3
157248157492
157249157493
/*
157250
-** A structure to store values read from the ota_state table in memory.
157494
+** A structure to store values read from the rbu_state table in memory.
157251157495
*/
157252
-struct OtaState {
157496
+struct RbuState {
157253157497
int eStage;
157254157498
char *zTbl;
157255157499
char *zIdx;
157256157500
i64 iWalCksum;
157257157501
int nRow;
@@ -157258,14 +157502,14 @@
157258157502
i64 nProgress;
157259157503
u32 iCookie;
157260157504
i64 iOalSz;
157261157505
};
157262157506
157263
-struct OtaUpdateStmt {
157507
+struct RbuUpdateStmt {
157264157508
char *zMask; /* Copy of update mask used with pUpdate */
157265157509
sqlite3_stmt *pUpdate; /* Last update statement (or NULL) */
157266
- OtaUpdateStmt *pNext;
157510
+ RbuUpdateStmt *pNext;
157267157511
};
157268157512
157269157513
/*
157270157514
** An iterator of this type is used to iterate through all objects in
157271157515
** the target database that require updating. For each such table, the
@@ -157280,131 +157524,131 @@
157280157524
** it points to an array of flags nTblCol elements in size. The flag is
157281157525
** set for each column that is either a part of the PK or a part of an
157282157526
** index. Or clear otherwise.
157283157527
**
157284157528
*/
157285
-struct OtaObjIter {
157529
+struct RbuObjIter {
157286157530
sqlite3_stmt *pTblIter; /* Iterate through tables */
157287157531
sqlite3_stmt *pIdxIter; /* Index iterator */
157288157532
int nTblCol; /* Size of azTblCol[] array */
157289157533
char **azTblCol; /* Array of unquoted target column names */
157290157534
char **azTblType; /* Array of target column types */
157291157535
int *aiSrcOrder; /* src table col -> target table col */
157292157536
u8 *abTblPk; /* Array of flags, set on target PK columns */
157293157537
u8 *abNotNull; /* Array of flags, set on NOT NULL columns */
157294157538
u8 *abIndexed; /* Array of flags, set on indexed & PK cols */
157295
- int eType; /* Table type - an OTA_PK_XXX value */
157539
+ int eType; /* Table type - an RBU_PK_XXX value */
157296157540
157297157541
/* Output variables. zTbl==0 implies EOF. */
157298157542
int bCleanup; /* True in "cleanup" state */
157299157543
const char *zTbl; /* Name of target db table */
157300157544
const char *zIdx; /* Name of target db index (or null) */
157301157545
int iTnum; /* Root page of current object */
157302157546
int iPkTnum; /* If eType==EXTERNAL, root of PK index */
157303157547
int bUnique; /* Current index is unique */
157304157548
157305
- /* Statements created by otaObjIterPrepareAll() */
157549
+ /* Statements created by rbuObjIterPrepareAll() */
157306157550
int nCol; /* Number of columns in current object */
157307157551
sqlite3_stmt *pSelect; /* Source data */
157308157552
sqlite3_stmt *pInsert; /* Statement for INSERT operations */
157309157553
sqlite3_stmt *pDelete; /* Statement for DELETE ops */
157310
- sqlite3_stmt *pTmpInsert; /* Insert into ota_tmp_$zTbl */
157554
+ sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zTbl */
157311157555
157312157556
/* Last UPDATE used (for PK b-tree updates only), or NULL. */
157313
- OtaUpdateStmt *pOtaUpdate;
157557
+ RbuUpdateStmt *pRbuUpdate;
157314157558
};
157315157559
157316157560
/*
157317
-** Values for OtaObjIter.eType
157561
+** Values for RbuObjIter.eType
157318157562
**
157319157563
** 0: Table does not exist (error)
157320157564
** 1: Table has an implicit rowid.
157321157565
** 2: Table has an explicit IPK column.
157322157566
** 3: Table has an external PK index.
157323157567
** 4: Table is WITHOUT ROWID.
157324157568
** 5: Table is a virtual table.
157325157569
*/
157326
-#define OTA_PK_NOTABLE 0
157327
-#define OTA_PK_NONE 1
157328
-#define OTA_PK_IPK 2
157329
-#define OTA_PK_EXTERNAL 3
157330
-#define OTA_PK_WITHOUT_ROWID 4
157331
-#define OTA_PK_VTAB 5
157570
+#define RBU_PK_NOTABLE 0
157571
+#define RBU_PK_NONE 1
157572
+#define RBU_PK_IPK 2
157573
+#define RBU_PK_EXTERNAL 3
157574
+#define RBU_PK_WITHOUT_ROWID 4
157575
+#define RBU_PK_VTAB 5
157332157576
157333157577
157334157578
/*
157335
-** Within the OTA_STAGE_OAL stage, each call to sqlite3ota_step() performs
157579
+** Within the RBU_STAGE_OAL stage, each call to sqlite3rbu_step() performs
157336157580
** one of the following operations.
157337157581
*/
157338
-#define OTA_INSERT 1 /* Insert on a main table b-tree */
157339
-#define OTA_DELETE 2 /* Delete a row from a main table b-tree */
157340
-#define OTA_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */
157341
-#define OTA_IDX_INSERT 4 /* Insert on an aux. index b-tree */
157342
-#define OTA_UPDATE 5 /* Update a row in a main table b-tree */
157582
+#define RBU_INSERT 1 /* Insert on a main table b-tree */
157583
+#define RBU_DELETE 2 /* Delete a row from a main table b-tree */
157584
+#define RBU_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */
157585
+#define RBU_IDX_INSERT 4 /* Insert on an aux. index b-tree */
157586
+#define RBU_UPDATE 5 /* Update a row in a main table b-tree */
157343157587
157344157588
157345157589
/*
157346157590
** A single step of an incremental checkpoint - frame iWalFrame of the wal
157347157591
** file should be copied to page iDbPage of the database file.
157348157592
*/
157349
-struct OtaFrame {
157593
+struct RbuFrame {
157350157594
u32 iDbPage;
157351157595
u32 iWalFrame;
157352157596
};
157353157597
157354157598
/*
157355
-** OTA handle.
157599
+** RBU handle.
157356157600
*/
157357
-struct sqlite3ota {
157358
- int eStage; /* Value of OTA_STATE_STAGE field */
157601
+struct sqlite3rbu {
157602
+ int eStage; /* Value of RBU_STATE_STAGE field */
157359157603
sqlite3 *dbMain; /* target database handle */
157360
- sqlite3 *dbOta; /* ota database handle */
157604
+ sqlite3 *dbRbu; /* rbu database handle */
157361157605
char *zTarget; /* Path to target db */
157362
- char *zOta; /* Path to ota db */
157363
- char *zState; /* Path to state db (or NULL if zOta) */
157606
+ char *zRbu; /* Path to rbu db */
157607
+ char *zState; /* Path to state db (or NULL if zRbu) */
157364157608
char zStateDb[5]; /* Db name for state ("stat" or "main") */
157365
- int rc; /* Value returned by last ota_step() call */
157609
+ int rc; /* Value returned by last rbu_step() call */
157366157610
char *zErrmsg; /* Error message if rc!=SQLITE_OK */
157367157611
int nStep; /* Rows processed for current object */
157368157612
int nProgress; /* Rows processed for all objects */
157369
- OtaObjIter objiter; /* Iterator for skipping through tbl/idx */
157370
- const char *zVfsName; /* Name of automatically created ota vfs */
157371
- ota_file *pTargetFd; /* File handle open on target db */
157613
+ RbuObjIter objiter; /* Iterator for skipping through tbl/idx */
157614
+ const char *zVfsName; /* Name of automatically created rbu vfs */
157615
+ rbu_file *pTargetFd; /* File handle open on target db */
157372157616
i64 iOalSz;
157373157617
157374157618
/* The following state variables are used as part of the incremental
157375
- ** checkpoint stage (eStage==OTA_STAGE_CKPT). See comments surrounding
157376
- ** function otaSetupCheckpoint() for details. */
157619
+ ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding
157620
+ ** function rbuSetupCheckpoint() for details. */
157377157621
u32 iMaxFrame; /* Largest iWalFrame value in aFrame[] */
157378157622
u32 mLock;
157379157623
int nFrame; /* Entries in aFrame[] array */
157380157624
int nFrameAlloc; /* Allocated size of aFrame[] array */
157381
- OtaFrame *aFrame;
157625
+ RbuFrame *aFrame;
157382157626
int pgsz;
157383157627
u8 *aBuf;
157384157628
i64 iWalCksum;
157385157629
};
157386157630
157387157631
/*
157388
-** An ota VFS is implemented using an instance of this structure.
157632
+** An rbu VFS is implemented using an instance of this structure.
157389157633
*/
157390
-struct ota_vfs {
157391
- sqlite3_vfs base; /* ota VFS shim methods */
157634
+struct rbu_vfs {
157635
+ sqlite3_vfs base; /* rbu VFS shim methods */
157392157636
sqlite3_vfs *pRealVfs; /* Underlying VFS */
157393157637
sqlite3_mutex *mutex; /* Mutex to protect pMain */
157394
- ota_file *pMain; /* Linked list of main db files */
157638
+ rbu_file *pMain; /* Linked list of main db files */
157395157639
};
157396157640
157397157641
/*
157398
-** Each file opened by an ota VFS is represented by an instance of
157642
+** Each file opened by an rbu VFS is represented by an instance of
157399157643
** the following structure.
157400157644
*/
157401
-struct ota_file {
157645
+struct rbu_file {
157402157646
sqlite3_file base; /* sqlite3_file methods */
157403157647
sqlite3_file *pReal; /* Underlying file handle */
157404
- ota_vfs *pOtaVfs; /* Pointer to the ota_vfs object */
157405
- sqlite3ota *pOta; /* Pointer to ota object (ota target only) */
157648
+ rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */
157649
+ sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
157406157650
157407157651
int openFlags; /* Flags this file was opened with */
157408157652
u32 iCookie; /* Cookie value for main db files */
157409157653
u8 iWriteVer; /* "write-version" value for main db files */
157410157654
@@ -157411,12 +157655,12 @@
157411157655
int nShm; /* Number of entries in apShm[] array */
157412157656
char **apShm; /* Array of mmap'd *-shm regions */
157413157657
char *zDel; /* Delete this when closing file */
157414157658
157415157659
const char *zWal; /* Wal filename for this main db file */
157416
- ota_file *pWalFd; /* Wal file descriptor for this main db */
157417
- ota_file *pMainNext; /* Next MAIN_DB file */
157660
+ rbu_file *pWalFd; /* Wal file descriptor for this main db */
157661
+ rbu_file *pMainNext; /* Next MAIN_DB file */
157418157662
};
157419157663
157420157664
157421157665
/*
157422157666
** Prepare the SQL statement in buffer zSql against database handle db.
@@ -157490,14 +157734,14 @@
157490157734
}
157491157735
return rc;
157492157736
}
157493157737
157494157738
/*
157495
-** Free the OtaObjIter.azTblCol[] and OtaObjIter.abTblPk[] arrays allocated
157496
-** by an earlier call to otaObjIterCacheTableInfo().
157739
+** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated
157740
+** by an earlier call to rbuObjIterCacheTableInfo().
157497157741
*/
157498
-static void otaObjIterFreeCols(OtaObjIter *pIter){
157742
+static void rbuObjIterFreeCols(RbuObjIter *pIter){
157499157743
int i;
157500157744
for(i=0; i<pIter->nTblCol; i++){
157501157745
sqlite3_free(pIter->azTblCol[i]);
157502157746
sqlite3_free(pIter->azTblType[i]);
157503157747
}
@@ -157513,72 +157757,72 @@
157513157757
157514157758
/*
157515157759
** Finalize all statements and free all allocations that are specific to
157516157760
** the current object (table/index pair).
157517157761
*/
157518
-static void otaObjIterClearStatements(OtaObjIter *pIter){
157519
- OtaUpdateStmt *pUp;
157762
+static void rbuObjIterClearStatements(RbuObjIter *pIter){
157763
+ RbuUpdateStmt *pUp;
157520157764
157521157765
sqlite3_finalize(pIter->pSelect);
157522157766
sqlite3_finalize(pIter->pInsert);
157523157767
sqlite3_finalize(pIter->pDelete);
157524157768
sqlite3_finalize(pIter->pTmpInsert);
157525
- pUp = pIter->pOtaUpdate;
157769
+ pUp = pIter->pRbuUpdate;
157526157770
while( pUp ){
157527
- OtaUpdateStmt *pTmp = pUp->pNext;
157771
+ RbuUpdateStmt *pTmp = pUp->pNext;
157528157772
sqlite3_finalize(pUp->pUpdate);
157529157773
sqlite3_free(pUp);
157530157774
pUp = pTmp;
157531157775
}
157532157776
157533157777
pIter->pSelect = 0;
157534157778
pIter->pInsert = 0;
157535157779
pIter->pDelete = 0;
157536
- pIter->pOtaUpdate = 0;
157780
+ pIter->pRbuUpdate = 0;
157537157781
pIter->pTmpInsert = 0;
157538157782
pIter->nCol = 0;
157539157783
}
157540157784
157541157785
/*
157542157786
** Clean up any resources allocated as part of the iterator object passed
157543157787
** as the only argument.
157544157788
*/
157545
-static void otaObjIterFinalize(OtaObjIter *pIter){
157546
- otaObjIterClearStatements(pIter);
157789
+static void rbuObjIterFinalize(RbuObjIter *pIter){
157790
+ rbuObjIterClearStatements(pIter);
157547157791
sqlite3_finalize(pIter->pTblIter);
157548157792
sqlite3_finalize(pIter->pIdxIter);
157549
- otaObjIterFreeCols(pIter);
157550
- memset(pIter, 0, sizeof(OtaObjIter));
157793
+ rbuObjIterFreeCols(pIter);
157794
+ memset(pIter, 0, sizeof(RbuObjIter));
157551157795
}
157552157796
157553157797
/*
157554157798
** Advance the iterator to the next position.
157555157799
**
157556157800
** If no error occurs, SQLITE_OK is returned and the iterator is left
157557157801
** pointing to the next entry. Otherwise, an error code and message is
157558
-** left in the OTA handle passed as the first argument. A copy of the
157802
+** left in the RBU handle passed as the first argument. A copy of the
157559157803
** error code is returned.
157560157804
*/
157561
-static int otaObjIterNext(sqlite3ota *p, OtaObjIter *pIter){
157805
+static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){
157562157806
int rc = p->rc;
157563157807
if( rc==SQLITE_OK ){
157564157808
157565157809
/* Free any SQLite statements used while processing the previous object */
157566
- otaObjIterClearStatements(pIter);
157810
+ rbuObjIterClearStatements(pIter);
157567157811
if( pIter->zIdx==0 ){
157568157812
rc = sqlite3_exec(p->dbMain,
157569
- "DROP TRIGGER IF EXISTS temp.ota_insert_tr;"
157570
- "DROP TRIGGER IF EXISTS temp.ota_update1_tr;"
157571
- "DROP TRIGGER IF EXISTS temp.ota_update2_tr;"
157572
- "DROP TRIGGER IF EXISTS temp.ota_delete_tr;"
157813
+ "DROP TRIGGER IF EXISTS temp.rbu_insert_tr;"
157814
+ "DROP TRIGGER IF EXISTS temp.rbu_update1_tr;"
157815
+ "DROP TRIGGER IF EXISTS temp.rbu_update2_tr;"
157816
+ "DROP TRIGGER IF EXISTS temp.rbu_delete_tr;"
157573157817
, 0, 0, &p->zErrmsg
157574157818
);
157575157819
}
157576157820
157577157821
if( rc==SQLITE_OK ){
157578157822
if( pIter->bCleanup ){
157579
- otaObjIterFreeCols(pIter);
157823
+ rbuObjIterFreeCols(pIter);
157580157824
pIter->bCleanup = 0;
157581157825
rc = sqlite3_step(pIter->pTblIter);
157582157826
if( rc!=SQLITE_ROW ){
157583157827
rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
157584157828
pIter->zTbl = 0;
@@ -157607,11 +157851,11 @@
157607157851
}
157608157852
}
157609157853
}
157610157854
157611157855
if( rc!=SQLITE_OK ){
157612
- otaObjIterFinalize(pIter);
157856
+ rbuObjIterFinalize(pIter);
157613157857
p->rc = rc;
157614157858
}
157615157859
return rc;
157616157860
}
157617157861
@@ -157618,20 +157862,20 @@
157618157862
/*
157619157863
** Initialize the iterator structure passed as the second argument.
157620157864
**
157621157865
** If no error occurs, SQLITE_OK is returned and the iterator is left
157622157866
** pointing to the first entry. Otherwise, an error code and message is
157623
-** left in the OTA handle passed as the first argument. A copy of the
157867
+** left in the RBU handle passed as the first argument. A copy of the
157624157868
** error code is returned.
157625157869
*/
157626
-static int otaObjIterFirst(sqlite3ota *p, OtaObjIter *pIter){
157870
+static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
157627157871
int rc;
157628
- memset(pIter, 0, sizeof(OtaObjIter));
157872
+ memset(pIter, 0, sizeof(RbuObjIter));
157629157873
157630
- rc = prepareAndCollectError(p->dbOta, &pIter->pTblIter, &p->zErrmsg,
157874
+ rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
157631157875
"SELECT substr(name, 6) FROM sqlite_master "
157632
- "WHERE type='table' AND name LIKE 'data_%'"
157876
+ "WHERE type IN ('table', 'view') AND name LIKE 'data_%'"
157633157877
);
157634157878
157635157879
if( rc==SQLITE_OK ){
157636157880
rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
157637157881
"SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
@@ -157640,23 +157884,23 @@
157640157884
);
157641157885
}
157642157886
157643157887
pIter->bCleanup = 1;
157644157888
p->rc = rc;
157645
- return otaObjIterNext(p, pIter);
157889
+ return rbuObjIterNext(p, pIter);
157646157890
}
157647157891
157648157892
/*
157649157893
** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs,
157650
-** an error code is stored in the OTA handle passed as the first argument.
157894
+** an error code is stored in the RBU handle passed as the first argument.
157651157895
**
157652157896
** If an error has already occurred (p->rc is already set to something other
157653157897
** than SQLITE_OK), then this function returns NULL without modifying the
157654157898
** stored error code. In this case it still calls sqlite3_free() on any
157655157899
** printf() parameters associated with %z conversions.
157656157900
*/
157657
-static char *otaMPrintf(sqlite3ota *p, const char *zFmt, ...){
157901
+static char *rbuMPrintf(sqlite3rbu *p, const char *zFmt, ...){
157658157902
char *zSql = 0;
157659157903
va_list ap;
157660157904
va_start(ap, zFmt);
157661157905
zSql = sqlite3_vmprintf(zFmt, ap);
157662157906
if( p->rc==SQLITE_OK ){
@@ -157671,20 +157915,21 @@
157671157915
157672157916
/*
157673157917
** Argument zFmt is a sqlite3_mprintf() style format string. The trailing
157674157918
** arguments are the usual subsitution values. This function performs
157675157919
** the printf() style substitutions and executes the result as an SQL
157676
-** statement on the OTA handles database.
157920
+** statement on the RBU handles database.
157677157921
**
157678157922
** If an error occurs, an error code and error message is stored in the
157679
-** OTA handle. If an error has already occurred when this function is
157923
+** RBU handle. If an error has already occurred when this function is
157680157924
** called, it is a no-op.
157681157925
*/
157682
-static int otaMPrintfExec(sqlite3ota *p, sqlite3 *db, const char *zFmt, ...){
157926
+static int rbuMPrintfExec(sqlite3rbu *p, sqlite3 *db, const char *zFmt, ...){
157683157927
va_list ap;
157928
+ char *zSql;
157684157929
va_start(ap, zFmt);
157685
- char *zSql = sqlite3_vmprintf(zFmt, ap);
157930
+ zSql = sqlite3_vmprintf(zFmt, ap);
157686157931
if( p->rc==SQLITE_OK ){
157687157932
if( zSql==0 ){
157688157933
p->rc = SQLITE_NOMEM;
157689157934
}else{
157690157935
p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
@@ -157698,16 +157943,16 @@
157698157943
/*
157699157944
** Attempt to allocate and return a pointer to a zeroed block of nByte
157700157945
** bytes.
157701157946
**
157702157947
** If an error (i.e. an OOM condition) occurs, return NULL and leave an
157703
-** error code in the ota handle passed as the first argument. Or, if an
157948
+** error code in the rbu handle passed as the first argument. Or, if an
157704157949
** error has already occurred when this function is called, return NULL
157705157950
** immediately without attempting the allocation or modifying the stored
157706157951
** error code.
157707157952
*/
157708
-static void *otaMalloc(sqlite3ota *p, int nByte){
157953
+static void *rbuMalloc(sqlite3rbu *p, int nByte){
157709157954
void *pRet = 0;
157710157955
if( p->rc==SQLITE_OK ){
157711157956
assert( nByte>0 );
157712157957
pRet = sqlite3_malloc(nByte);
157713157958
if( pRet==0 ){
@@ -157721,17 +157966,17 @@
157721157966
157722157967
157723157968
/*
157724157969
** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
157725157970
** there is room for at least nCol elements. If an OOM occurs, store an
157726
-** error code in the OTA handle passed as the first argument.
157971
+** error code in the RBU handle passed as the first argument.
157727157972
*/
157728
-static void otaAllocateIterArrays(sqlite3ota *p, OtaObjIter *pIter, int nCol){
157973
+static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
157729157974
int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
157730157975
char **azNew;
157731157976
157732
- azNew = (char**)otaMalloc(p, nByte);
157977
+ azNew = (char**)rbuMalloc(p, nByte);
157733157978
if( azNew ){
157734157979
pIter->azTblCol = azNew;
157735157980
pIter->azTblType = &azNew[nCol];
157736157981
pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
157737157982
pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol];
@@ -157748,11 +157993,11 @@
157748157993
**
157749157994
** If an OOM condition is encountered when attempting to allocate memory,
157750157995
** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
157751157996
** if the allocation succeeds, (*pRc) is left unchanged.
157752157997
*/
157753
-static char *otaStrndup(const char *zStr, int *pRc){
157998
+static char *rbuStrndup(const char *zStr, int *pRc){
157754157999
char *zRet = 0;
157755158000
157756158001
assert( *pRc==SQLITE_OK );
157757158002
if( zStr ){
157758158003
int nCopy = strlen(zStr) + 1;
@@ -157769,14 +158014,14 @@
157769158014
157770158015
/*
157771158016
** Finalize the statement passed as the second argument.
157772158017
**
157773158018
** If the sqlite3_finalize() call indicates that an error occurs, and the
157774
-** ota handle error code is not already set, set the error code and error
158019
+** rbu handle error code is not already set, set the error code and error
157775158020
** message accordingly.
157776158021
*/
157777
-static void otaFinalize(sqlite3ota *p, sqlite3_stmt *pStmt){
158022
+static void rbuFinalize(sqlite3rbu *p, sqlite3_stmt *pStmt){
157778158023
sqlite3 *db = sqlite3_db_handle(pStmt);
157779158024
int rc = sqlite3_finalize(pStmt);
157780158025
if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){
157781158026
p->rc = rc;
157782158027
p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
@@ -157787,16 +158032,16 @@
157787158032
**
157788158033
** peType is of type (int*), a pointer to an output parameter of type
157789158034
** (int). This call sets the output parameter as follows, depending
157790158035
** on the type of the table specified by parameters dbName and zTbl.
157791158036
**
157792
-** OTA_PK_NOTABLE: No such table.
157793
-** OTA_PK_NONE: Table has an implicit rowid.
157794
-** OTA_PK_IPK: Table has an explicit IPK column.
157795
-** OTA_PK_EXTERNAL: Table has an external PK index.
157796
-** OTA_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
157797
-** OTA_PK_VTAB: Table is a virtual table.
158037
+** RBU_PK_NOTABLE: No such table.
158038
+** RBU_PK_NONE: Table has an implicit rowid.
158039
+** RBU_PK_IPK: Table has an explicit IPK column.
158040
+** RBU_PK_EXTERNAL: Table has an external PK index.
158041
+** RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
158042
+** RBU_PK_VTAB: Table is a virtual table.
157798158043
**
157799158044
** Argument *piPk is also of type (int*), and also points to an output
157800158045
** parameter. Unless the table has an external primary key index
157801158046
** (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
157802158047
** if the table does have an external primary key index, then *piPk
@@ -157804,28 +158049,28 @@
157804158049
** returning.
157805158050
**
157806158051
** ALGORITHM:
157807158052
**
157808158053
** if( no entry exists in sqlite_master ){
157809
-** return OTA_PK_NOTABLE
158054
+** return RBU_PK_NOTABLE
157810158055
** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
157811
-** return OTA_PK_VTAB
158056
+** return RBU_PK_VTAB
157812158057
** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
157813158058
** if( the index that is the pk exists in sqlite_master ){
157814158059
** *piPK = rootpage of that index.
157815
-** return OTA_PK_EXTERNAL
158060
+** return RBU_PK_EXTERNAL
157816158061
** }else{
157817
-** return OTA_PK_WITHOUT_ROWID
158062
+** return RBU_PK_WITHOUT_ROWID
157818158063
** }
157819158064
** }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
157820
-** return OTA_PK_IPK
158065
+** return RBU_PK_IPK
157821158066
** }else{
157822
-** return OTA_PK_NONE
158067
+** return RBU_PK_NONE
157823158068
** }
157824158069
*/
157825
-static void otaTableType(
157826
- sqlite3ota *p,
158070
+static void rbuTableType(
158071
+ sqlite3rbu *p,
157827158072
const char *zTab,
157828158073
int *peType,
157829158074
int *piTnum,
157830158075
int *piPk
157831158076
){
@@ -157835,11 +158080,11 @@
157835158080
** 2) SELECT count(*) FROM sqlite_master where name=%Q
157836158081
** 3) PRAGMA table_info = ?
157837158082
*/
157838158083
sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
157839158084
157840
- *peType = OTA_PK_NOTABLE;
158085
+ *peType = RBU_PK_NOTABLE;
157841158086
*piPk = 0;
157842158087
157843158088
assert( p->rc==SQLITE_OK );
157844158089
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
157845158090
sqlite3_mprintf(
@@ -157847,22 +158092,22 @@
157847158092
" FROM sqlite_master"
157848158093
" WHERE name=%Q", zTab
157849158094
));
157850158095
if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
157851158096
/* Either an error, or no such table. */
157852
- goto otaTableType_end;
158097
+ goto rbuTableType_end;
157853158098
}
157854158099
if( sqlite3_column_int(aStmt[0], 0) ){
157855
- *peType = OTA_PK_VTAB; /* virtual table */
157856
- goto otaTableType_end;
158100
+ *peType = RBU_PK_VTAB; /* virtual table */
158101
+ goto rbuTableType_end;
157857158102
}
157858158103
*piTnum = sqlite3_column_int(aStmt[0], 1);
157859158104
157860158105
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[1], &p->zErrmsg,
157861158106
sqlite3_mprintf("PRAGMA index_list=%Q",zTab)
157862158107
);
157863
- if( p->rc ) goto otaTableType_end;
158108
+ if( p->rc ) goto rbuTableType_end;
157864158109
while( sqlite3_step(aStmt[1])==SQLITE_ROW ){
157865158110
const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
157866158111
const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
157867158112
if( zOrig && zIdx && zOrig[0]=='p' ){
157868158113
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg,
@@ -157870,45 +158115,45 @@
157870158115
"SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx
157871158116
));
157872158117
if( p->rc==SQLITE_OK ){
157873158118
if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
157874158119
*piPk = sqlite3_column_int(aStmt[2], 0);
157875
- *peType = OTA_PK_EXTERNAL;
158120
+ *peType = RBU_PK_EXTERNAL;
157876158121
}else{
157877
- *peType = OTA_PK_WITHOUT_ROWID;
158122
+ *peType = RBU_PK_WITHOUT_ROWID;
157878158123
}
157879158124
}
157880
- goto otaTableType_end;
158125
+ goto rbuTableType_end;
157881158126
}
157882158127
}
157883158128
157884158129
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[3], &p->zErrmsg,
157885158130
sqlite3_mprintf("PRAGMA table_info=%Q",zTab)
157886158131
);
157887158132
if( p->rc==SQLITE_OK ){
157888158133
while( sqlite3_step(aStmt[3])==SQLITE_ROW ){
157889158134
if( sqlite3_column_int(aStmt[3],5)>0 ){
157890
- *peType = OTA_PK_IPK; /* explicit IPK column */
157891
- goto otaTableType_end;
158135
+ *peType = RBU_PK_IPK; /* explicit IPK column */
158136
+ goto rbuTableType_end;
157892158137
}
157893158138
}
157894
- *peType = OTA_PK_NONE;
158139
+ *peType = RBU_PK_NONE;
157895158140
}
157896158141
157897
-otaTableType_end: {
158142
+rbuTableType_end: {
157898158143
int i;
157899158144
for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
157900
- otaFinalize(p, aStmt[i]);
158145
+ rbuFinalize(p, aStmt[i]);
157901158146
}
157902158147
}
157903158148
}
157904158149
157905158150
/*
157906
-** This is a helper function for otaObjIterCacheTableInfo(). It populates
158151
+** This is a helper function for rbuObjIterCacheTableInfo(). It populates
157907158152
** the pIter->abIndexed[] array.
157908158153
*/
157909
-static void otaObjIterCacheIndexedCols(sqlite3ota *p, OtaObjIter *pIter){
158154
+static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){
157910158155
sqlite3_stmt *pList = 0;
157911158156
int bIndex = 0;
157912158157
157913158158
if( p->rc==SQLITE_OK ){
157914158159
memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol);
@@ -157926,15 +158171,15 @@
157926158171
);
157927158172
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
157928158173
int iCid = sqlite3_column_int(pXInfo, 1);
157929158174
if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
157930158175
}
157931
- otaFinalize(p, pXInfo);
158176
+ rbuFinalize(p, pXInfo);
157932158177
bIndex = 1;
157933158178
}
157934158179
157935
- otaFinalize(p, pList);
158180
+ rbuFinalize(p, pList);
157936158181
if( bIndex==0 ) pIter->abIndexed = 0;
157937158182
}
157938158183
157939158184
157940158185
/*
@@ -157942,67 +158187,67 @@
157942158187
** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
157943158188
** the table (not index) that the iterator currently points to.
157944158189
**
157945158190
** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
157946158191
** an error does occur, an error code and error message are also left in
157947
-** the OTA handle.
158192
+** the RBU handle.
157948158193
*/
157949
-static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){
158194
+static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){
157950158195
if( pIter->azTblCol==0 ){
157951158196
sqlite3_stmt *pStmt = 0;
157952158197
int nCol = 0;
157953158198
int i; /* for() loop iterator variable */
157954
- int bOtaRowid = 0; /* If input table has column "ota_rowid" */
158199
+ int bRbuRowid = 0; /* If input table has column "rbu_rowid" */
157955158200
int iOrder = 0;
157956158201
int iTnum = 0;
157957158202
157958158203
/* Figure out the type of table this step will deal with. */
157959158204
assert( pIter->eType==0 );
157960
- otaTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
157961
- if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_NOTABLE ){
158205
+ rbuTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
158206
+ if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_NOTABLE ){
157962158207
p->rc = SQLITE_ERROR;
157963158208
p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl);
157964158209
}
157965158210
if( p->rc ) return p->rc;
157966158211
if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
157967158212
157968
- assert( pIter->eType==OTA_PK_NONE || pIter->eType==OTA_PK_IPK
157969
- || pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_WITHOUT_ROWID
157970
- || pIter->eType==OTA_PK_VTAB
158213
+ assert( pIter->eType==RBU_PK_NONE || pIter->eType==RBU_PK_IPK
158214
+ || pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_WITHOUT_ROWID
158215
+ || pIter->eType==RBU_PK_VTAB
157971158216
);
157972158217
157973158218
/* Populate the azTblCol[] and nTblCol variables based on the columns
157974158219
** of the input table. Ignore any input table columns that begin with
157975
- ** "ota_". */
157976
- p->rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg,
158220
+ ** "rbu_". */
158221
+ p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
157977158222
sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl)
157978158223
);
157979158224
if( p->rc==SQLITE_OK ){
157980158225
nCol = sqlite3_column_count(pStmt);
157981
- otaAllocateIterArrays(p, pIter, nCol);
158226
+ rbuAllocateIterArrays(p, pIter, nCol);
157982158227
}
157983158228
for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
157984158229
const char *zName = (const char*)sqlite3_column_name(pStmt, i);
157985
- if( sqlite3_strnicmp("ota_", zName, 4) ){
157986
- char *zCopy = otaStrndup(zName, &p->rc);
158230
+ if( sqlite3_strnicmp("rbu_", zName, 4) ){
158231
+ char *zCopy = rbuStrndup(zName, &p->rc);
157987158232
pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol;
157988158233
pIter->azTblCol[pIter->nTblCol++] = zCopy;
157989158234
}
157990
- else if( 0==sqlite3_stricmp("ota_rowid", zName) ){
157991
- bOtaRowid = 1;
158235
+ else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){
158236
+ bRbuRowid = 1;
157992158237
}
157993158238
}
157994158239
sqlite3_finalize(pStmt);
157995158240
pStmt = 0;
157996158241
157997158242
if( p->rc==SQLITE_OK
157998
- && bOtaRowid!=(pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE)
158243
+ && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
157999158244
){
158000158245
p->rc = SQLITE_ERROR;
158001158246
p->zErrmsg = sqlite3_mprintf(
158002
- "table data_%q %s ota_rowid column", pIter->zTbl,
158003
- (bOtaRowid ? "may not have" : "requires")
158247
+ "table data_%q %s rbu_rowid column", pIter->zTbl,
158248
+ (bRbuRowid ? "may not have" : "requires")
158004158249
);
158005158250
}
158006158251
158007158252
/* Check that all non-HIDDEN columns in the destination table are also
158008158253
** present in the input table. Populate the abTblPk[], azTblType[] and
@@ -158031,20 +158276,20 @@
158031158276
if( i!=iOrder ){
158032158277
SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]);
158033158278
SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]);
158034158279
}
158035158280
158036
- pIter->azTblType[iOrder] = otaStrndup(zType, &p->rc);
158281
+ pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc);
158037158282
pIter->abTblPk[iOrder] = (iPk!=0);
158038158283
pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
158039158284
iOrder++;
158040158285
}
158041158286
}
158042158287
158043
- otaFinalize(p, pStmt);
158044
- otaObjIterCacheIndexedCols(p, pIter);
158045
- assert( pIter->eType!=OTA_PK_VTAB || pIter->abIndexed==0 );
158288
+ rbuFinalize(p, pStmt);
158289
+ rbuObjIterCacheIndexedCols(p, pIter);
158290
+ assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
158046158291
}
158047158292
158048158293
return p->rc;
158049158294
}
158050158295
@@ -158051,29 +158296,29 @@
158051158296
/*
158052158297
** This function constructs and returns a pointer to a nul-terminated
158053158298
** string containing some SQL clause or list based on one or more of the
158054158299
** column names currently stored in the pIter->azTblCol[] array.
158055158300
*/
158056
-static char *otaObjIterGetCollist(
158057
- sqlite3ota *p, /* OTA object */
158058
- OtaObjIter *pIter /* Object iterator for column names */
158301
+static char *rbuObjIterGetCollist(
158302
+ sqlite3rbu *p, /* RBU object */
158303
+ RbuObjIter *pIter /* Object iterator for column names */
158059158304
){
158060158305
char *zList = 0;
158061158306
const char *zSep = "";
158062158307
int i;
158063158308
for(i=0; i<pIter->nTblCol; i++){
158064158309
const char *z = pIter->azTblCol[i];
158065
- zList = otaMPrintf(p, "%z%s\"%w\"", zList, zSep, z);
158310
+ zList = rbuMPrintf(p, "%z%s\"%w\"", zList, zSep, z);
158066158311
zSep = ", ";
158067158312
}
158068158313
return zList;
158069158314
}
158070158315
158071158316
/*
158072158317
** This function is used to create a SELECT list (the list of SQL
158073158318
** expressions that follows a SELECT keyword) for a SELECT statement
158074
-** used to read from an data_xxx or ota_tmp_xxx table while updating the
158319
+** used to read from an data_xxx or rbu_tmp_xxx table while updating the
158075158320
** index object currently indicated by the iterator object passed as the
158076158321
** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used
158077158322
** to obtain the required information.
158078158323
**
158079158324
** If the index is of the following form:
@@ -158090,17 +158335,17 @@
158090158335
**
158091158336
** pzImposterCols: ...
158092158337
** pzImposterPk: ...
158093158338
** pzWhere: ...
158094158339
*/
158095
-static char *otaObjIterGetIndexCols(
158096
- sqlite3ota *p, /* OTA object */
158097
- OtaObjIter *pIter, /* Object iterator for column names */
158340
+static char *rbuObjIterGetIndexCols(
158341
+ sqlite3rbu *p, /* RBU object */
158342
+ RbuObjIter *pIter, /* Object iterator for column names */
158098158343
char **pzImposterCols, /* OUT: Columns for imposter table */
158099158344
char **pzImposterPk, /* OUT: Imposter PK clause */
158100158345
char **pzWhere, /* OUT: WHERE clause */
158101
- int *pnBind /* OUT: Total number of columns */
158346
+ int *pnBind /* OUT: Trbul number of columns */
158102158347
){
158103158348
int rc = p->rc; /* Error code */
158104158349
int rc2; /* sqlite3_finalize() return code */
158105158350
char *zRet = 0; /* String to return */
158106158351
char *zImpCols = 0; /* String to return via *pzImposterCols */
@@ -158125,18 +158370,18 @@
158125158370
const char *zCol;
158126158371
const char *zType;
158127158372
158128158373
if( iCid<0 ){
158129158374
/* An integer primary key. If the table has an explicit IPK, use
158130
- ** its name. Otherwise, use "ota_rowid". */
158131
- if( pIter->eType==OTA_PK_IPK ){
158375
+ ** its name. Otherwise, use "rbu_rowid". */
158376
+ if( pIter->eType==RBU_PK_IPK ){
158132158377
int i;
158133158378
for(i=0; pIter->abTblPk[i]==0; i++);
158134158379
assert( i<pIter->nTblCol );
158135158380
zCol = pIter->azTblCol[i];
158136158381
}else{
158137
- zCol = "ota_rowid";
158382
+ zCol = "rbu_rowid";
158138158383
}
158139158384
zType = "INTEGER";
158140158385
}else{
158141158386
zCol = pIter->azTblCol[iCid];
158142158387
zType = pIter->azTblType[iCid];
@@ -158143,19 +158388,19 @@
158143158388
}
158144158389
158145158390
zRet = sqlite3_mprintf("%z%s\"%w\" COLLATE %Q", zRet, zCom, zCol, zCollate);
158146158391
if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
158147158392
const char *zOrder = (bDesc ? " DESC" : "");
158148
- zImpPK = sqlite3_mprintf("%z%s\"ota_imp_%d%w\"%s",
158393
+ zImpPK = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\"%s",
158149158394
zImpPK, zCom, nBind, zCol, zOrder
158150158395
);
158151158396
}
158152
- zImpCols = sqlite3_mprintf("%z%s\"ota_imp_%d%w\" %s COLLATE %Q",
158397
+ zImpCols = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\" %s COLLATE %Q",
158153158398
zImpCols, zCom, nBind, zCol, zType, zCollate
158154158399
);
158155158400
zWhere = sqlite3_mprintf(
158156
- "%z%s\"ota_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol
158401
+ "%z%s\"rbu_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol
158157158402
);
158158158403
if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM;
158159158404
zCom = ", ";
158160158405
zAnd = " AND ";
158161158406
nBind++;
@@ -158189,16 +158434,16 @@
158189158434
**
158190158435
** "old.a, old.b, old.b"
158191158436
**
158192158437
** With the column names escaped.
158193158438
**
158194
-** For tables with implicit rowids - OTA_PK_EXTERNAL and OTA_PK_NONE, append
158439
+** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append
158195158440
** the text ", old._rowid_" to the returned value.
158196158441
*/
158197
-static char *otaObjIterGetOldlist(
158198
- sqlite3ota *p,
158199
- OtaObjIter *pIter,
158442
+static char *rbuObjIterGetOldlist(
158443
+ sqlite3rbu *p,
158444
+ RbuObjIter *pIter,
158200158445
const char *zObj
158201158446
){
158202158447
char *zList = 0;
158203158448
if( p->rc==SQLITE_OK && pIter->abIndexed ){
158204158449
const char *zS = "";
@@ -158216,12 +158461,12 @@
158216158461
break;
158217158462
}
158218158463
}
158219158464
158220158465
/* For a table with implicit rowids, append "old._rowid_" to the list. */
158221
- if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158222
- zList = otaMPrintf(p, "%z, %s._rowid_", zList, zObj);
158466
+ if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158467
+ zList = rbuMPrintf(p, "%z, %s._rowid_", zList, zObj);
158223158468
}
158224158469
}
158225158470
return zList;
158226158471
}
158227158472
@@ -158233,37 +158478,37 @@
158233158478
**
158234158479
** Return the string:
158235158480
**
158236158481
** "b = ?1 AND c = ?2"
158237158482
*/
158238
-static char *otaObjIterGetWhere(
158239
- sqlite3ota *p,
158240
- OtaObjIter *pIter
158483
+static char *rbuObjIterGetWhere(
158484
+ sqlite3rbu *p,
158485
+ RbuObjIter *pIter
158241158486
){
158242158487
char *zList = 0;
158243
- if( pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE ){
158244
- zList = otaMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
158245
- }else if( pIter->eType==OTA_PK_EXTERNAL ){
158488
+ if( pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE ){
158489
+ zList = rbuMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
158490
+ }else if( pIter->eType==RBU_PK_EXTERNAL ){
158246158491
const char *zSep = "";
158247158492
int i;
158248158493
for(i=0; i<pIter->nTblCol; i++){
158249158494
if( pIter->abTblPk[i] ){
158250
- zList = otaMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1);
158495
+ zList = rbuMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1);
158251158496
zSep = " AND ";
158252158497
}
158253158498
}
158254
- zList = otaMPrintf(p,
158255
- "_rowid_ = (SELECT id FROM ota_imposter2 WHERE %z)", zList
158499
+ zList = rbuMPrintf(p,
158500
+ "_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)", zList
158256158501
);
158257158502
158258158503
}else{
158259158504
const char *zSep = "";
158260158505
int i;
158261158506
for(i=0; i<pIter->nTblCol; i++){
158262158507
if( pIter->abTblPk[i] ){
158263158508
const char *zCol = pIter->azTblCol[i];
158264
- zList = otaMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1);
158509
+ zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1);
158265158510
zSep = " AND ";
158266158511
}
158267158512
}
158268158513
}
158269158514
return zList;
@@ -158270,60 +158515,60 @@
158270158515
}
158271158516
158272158517
/*
158273158518
** The SELECT statement iterating through the keys for the current object
158274158519
** (p->objiter.pSelect) currently points to a valid row. However, there
158275
-** is something wrong with the ota_control value in the ota_control value
158520
+** is something wrong with the rbu_control value in the rbu_control value
158276158521
** stored in the (p->nCol+1)'th column. Set the error code and error message
158277
-** of the OTA handle to something reflecting this.
158522
+** of the RBU handle to something reflecting this.
158278158523
*/
158279
-static void otaBadControlError(sqlite3ota *p){
158524
+static void rbuBadControlError(sqlite3rbu *p){
158280158525
p->rc = SQLITE_ERROR;
158281
- p->zErrmsg = sqlite3_mprintf("invalid ota_control value");
158526
+ p->zErrmsg = sqlite3_mprintf("invalid rbu_control value");
158282158527
}
158283158528
158284158529
158285158530
/*
158286158531
** Return a nul-terminated string containing the comma separated list of
158287158532
** assignments that should be included following the "SET" keyword of
158288158533
** an UPDATE statement used to update the table object that the iterator
158289
-** passed as the second argument currently points to if the ota_control
158534
+** passed as the second argument currently points to if the rbu_control
158290158535
** column of the data_xxx table entry is set to zMask.
158291158536
**
158292158537
** The memory for the returned string is obtained from sqlite3_malloc().
158293158538
** It is the responsibility of the caller to eventually free it using
158294158539
** sqlite3_free().
158295158540
**
158296158541
** If an OOM error is encountered when allocating space for the new
158297
-** string, an error code is left in the ota handle passed as the first
158542
+** string, an error code is left in the rbu handle passed as the first
158298158543
** argument and NULL is returned. Or, if an error has already occurred
158299158544
** when this function is called, NULL is returned immediately, without
158300158545
** attempting the allocation or modifying the stored error code.
158301158546
*/
158302
-static char *otaObjIterGetSetlist(
158303
- sqlite3ota *p,
158304
- OtaObjIter *pIter,
158547
+static char *rbuObjIterGetSetlist(
158548
+ sqlite3rbu *p,
158549
+ RbuObjIter *pIter,
158305158550
const char *zMask
158306158551
){
158307158552
char *zList = 0;
158308158553
if( p->rc==SQLITE_OK ){
158309158554
int i;
158310158555
158311158556
if( strlen(zMask)!=pIter->nTblCol ){
158312
- otaBadControlError(p);
158557
+ rbuBadControlError(p);
158313158558
}else{
158314158559
const char *zSep = "";
158315158560
for(i=0; i<pIter->nTblCol; i++){
158316158561
char c = zMask[pIter->aiSrcOrder[i]];
158317158562
if( c=='x' ){
158318
- zList = otaMPrintf(p, "%z%s\"%w\"=?%d",
158563
+ zList = rbuMPrintf(p, "%z%s\"%w\"=?%d",
158319158564
zList, zSep, pIter->azTblCol[i], i+1
158320158565
);
158321158566
zSep = ", ";
158322158567
}
158323158568
if( c=='d' ){
158324
- zList = otaMPrintf(p, "%z%s\"%w\"=ota_delta(\"%w\", ?%d)",
158569
+ zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)",
158325158570
zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
158326158571
);
158327158572
zSep = ", ";
158328158573
}
158329158574
}
@@ -158340,20 +158585,20 @@
158340158585
** The memory for the returned string is obtained from sqlite3_malloc().
158341158586
** It is the responsibility of the caller to eventually free it using
158342158587
** sqlite3_free().
158343158588
**
158344158589
** If an OOM error is encountered when allocating space for the new
158345
-** string, an error code is left in the ota handle passed as the first
158590
+** string, an error code is left in the rbu handle passed as the first
158346158591
** argument and NULL is returned. Or, if an error has already occurred
158347158592
** when this function is called, NULL is returned immediately, without
158348158593
** attempting the allocation or modifying the stored error code.
158349158594
*/
158350
-static char *otaObjIterGetBindlist(sqlite3ota *p, int nBind){
158595
+static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
158351158596
char *zRet = 0;
158352158597
int nByte = nBind*2 + 1;
158353158598
158354
- zRet = (char*)otaMalloc(p, nByte);
158599
+ zRet = (char*)rbuMalloc(p, nByte);
158355158600
if( zRet ){
158356158601
int i;
158357158602
for(i=0; i<nBind; i++){
158358158603
zRet[i*2] = '?';
158359158604
zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
@@ -158362,21 +158607,21 @@
158362158607
return zRet;
158363158608
}
158364158609
158365158610
/*
158366158611
** The iterator currently points to a table (not index) of type
158367
-** OTA_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
158612
+** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
158368158613
** declaration for the corresponding imposter table. For example,
158369158614
** if the iterator points to a table created as:
158370158615
**
158371158616
** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
158372158617
**
158373158618
** this function returns:
158374158619
**
158375158620
** PRIMARY KEY("b", "a" DESC)
158376158621
*/
158377
-static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){
158622
+static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){
158378158623
char *z = 0;
158379158624
assert( pIter->zIdx==0 );
158380158625
if( p->rc==SQLITE_OK ){
158381158626
const char *zSep = "PRIMARY KEY(";
158382158627
sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
@@ -158395,23 +158640,23 @@
158395158640
);
158396158641
}
158397158642
break;
158398158643
}
158399158644
}
158400
- otaFinalize(p, pXList);
158645
+ rbuFinalize(p, pXList);
158401158646
158402158647
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158403158648
if( sqlite3_column_int(pXInfo, 5) ){
158404158649
/* int iCid = sqlite3_column_int(pXInfo, 0); */
158405158650
const char *zCol = (const char*)sqlite3_column_text(pXInfo, 2);
158406158651
const char *zDesc = sqlite3_column_int(pXInfo, 3) ? " DESC" : "";
158407
- z = otaMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc);
158652
+ z = rbuMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc);
158408158653
zSep = ", ";
158409158654
}
158410158655
}
158411
- z = otaMPrintf(p, "%z)", z);
158412
- otaFinalize(p, pXInfo);
158656
+ z = rbuMPrintf(p, "%z)", z);
158657
+ rbuFinalize(p, pXInfo);
158413158658
}
158414158659
return z;
158415158660
}
158416158661
158417158662
/*
@@ -158420,23 +158665,23 @@
158420158665
** iterator passed as the second argument does not currently point to
158421158666
** a table (not index) with an external primary key, this function is a
158422158667
** no-op.
158423158668
**
158424158669
** Assuming the iterator does point to a table with an external PK, this
158425
-** function creates a WITHOUT ROWID imposter table named "ota_imposter2"
158670
+** function creates a WITHOUT ROWID imposter table named "rbu_imposter2"
158426158671
** used to access that PK index. For example, if the target table is
158427158672
** declared as follows:
158428158673
**
158429158674
** CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
158430158675
**
158431158676
** then the imposter table schema is:
158432158677
**
158433
-** CREATE TABLE ota_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
158678
+** CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
158434158679
**
158435158680
*/
158436
-static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){
158437
- if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_EXTERNAL ){
158681
+static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){
158682
+ if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_EXTERNAL ){
158438158683
int tnum = pIter->iPkTnum; /* Root page of PK index */
158439158684
sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */
158440158685
const char *zIdx = 0; /* Name of PK index */
158441158686
sqlite3_stmt *pXInfo = 0; /* PRAGMA main.index_xinfo = $zIdx */
158442158687
const char *zComma = "";
@@ -158458,31 +158703,31 @@
158458158703
if( zIdx ){
158459158704
p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
158460158705
sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
158461158706
);
158462158707
}
158463
- otaFinalize(p, pQuery);
158708
+ rbuFinalize(p, pQuery);
158464158709
158465158710
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158466158711
int bKey = sqlite3_column_int(pXInfo, 5);
158467158712
if( bKey ){
158468158713
int iCid = sqlite3_column_int(pXInfo, 1);
158469158714
int bDesc = sqlite3_column_int(pXInfo, 3);
158470158715
const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
158471
- zCols = otaMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma,
158716
+ zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma,
158472158717
iCid, pIter->azTblType[iCid], zCollate
158473158718
);
158474
- zPk = otaMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":"");
158719
+ zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":"");
158475158720
zComma = ", ";
158476158721
}
158477158722
}
158478
- zCols = otaMPrintf(p, "%z, id INTEGER", zCols);
158479
- otaFinalize(p, pXInfo);
158723
+ zCols = rbuMPrintf(p, "%z, id INTEGER", zCols);
158724
+ rbuFinalize(p, pXInfo);
158480158725
158481158726
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158482
- otaMPrintfExec(p, p->dbMain,
158483
- "CREATE TABLE ota_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID",
158727
+ rbuMPrintfExec(p, p->dbMain,
158728
+ "CREATE TABLE rbu_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID",
158484158729
zCols, zPk
158485158730
);
158486158731
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158487158732
}
158488158733
}
@@ -158489,28 +158734,28 @@
158489158734
158490158735
/*
158491158736
** If an error has already occurred when this function is called, it
158492158737
** immediately returns zero (without doing any work). Or, if an error
158493158738
** occurs during the execution of this function, it sets the error code
158494
-** in the sqlite3ota object indicated by the first argument and returns
158739
+** in the sqlite3rbu object indicated by the first argument and returns
158495158740
** zero.
158496158741
**
158497158742
** The iterator passed as the second argument is guaranteed to point to
158498158743
** a table (not an index) when this function is called. This function
158499158744
** attempts to create any imposter table required to write to the main
158500158745
** table b-tree of the table before returning. Non-zero is returned if
158501158746
** an imposter table are created, or zero otherwise.
158502158747
**
158503
-** An imposter table is required in all cases except OTA_PK_VTAB. Only
158748
+** An imposter table is required in all cases except RBU_PK_VTAB. Only
158504158749
** virtual tables are written to directly. The imposter table has the
158505158750
** same schema as the actual target table (less any UNIQUE constraints).
158506158751
** More precisely, the "same schema" means the same columns, types,
158507158752
** collation sequences. For tables that do not have an external PRIMARY
158508158753
** KEY, it also means the same PRIMARY KEY declaration.
158509158754
*/
158510
-static void otaCreateImposterTable(sqlite3ota *p, OtaObjIter *pIter){
158511
- if( p->rc==SQLITE_OK && pIter->eType!=OTA_PK_VTAB ){
158755
+static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){
158756
+ if( p->rc==SQLITE_OK && pIter->eType!=RBU_PK_VTAB ){
158512158757
int tnum = pIter->iTnum;
158513158758
const char *zComma = "";
158514158759
char *zSql = 0;
158515158760
int iCol;
158516158761
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
@@ -158522,73 +158767,73 @@
158522158767
158523158768
p->rc = sqlite3_table_column_metadata(
158524158769
p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
158525158770
);
158526158771
158527
- if( pIter->eType==OTA_PK_IPK && pIter->abTblPk[iCol] ){
158772
+ if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
158528158773
/* If the target table column is an "INTEGER PRIMARY KEY", add
158529158774
** "PRIMARY KEY" to the imposter table column declaration. */
158530158775
zPk = "PRIMARY KEY ";
158531158776
}
158532
- zSql = otaMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s",
158777
+ zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s",
158533158778
zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
158534158779
(pIter->abNotNull[iCol] ? " NOT NULL" : "")
158535158780
);
158536158781
zComma = ", ";
158537158782
}
158538158783
158539
- if( pIter->eType==OTA_PK_WITHOUT_ROWID ){
158540
- char *zPk = otaWithoutRowidPK(p, pIter);
158784
+ if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
158785
+ char *zPk = rbuWithoutRowidPK(p, pIter);
158541158786
if( zPk ){
158542
- zSql = otaMPrintf(p, "%z, %z", zSql, zPk);
158787
+ zSql = rbuMPrintf(p, "%z, %z", zSql, zPk);
158543158788
}
158544158789
}
158545158790
158546158791
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158547
- otaMPrintfExec(p, p->dbMain, "CREATE TABLE \"ota_imp_%w\"(%z)%s",
158792
+ rbuMPrintfExec(p, p->dbMain, "CREATE TABLE \"rbu_imp_%w\"(%z)%s",
158548158793
pIter->zTbl, zSql,
158549
- (pIter->eType==OTA_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
158794
+ (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
158550158795
);
158551158796
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158552158797
}
158553158798
}
158554158799
158555158800
/*
158556
-** Prepare a statement used to insert rows into the "ota_tmp_xxx" table.
158801
+** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table.
158557158802
** Specifically a statement of the form:
158558158803
**
158559
-** INSERT INTO ota_tmp_xxx VALUES(?, ?, ? ...);
158804
+** INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...);
158560158805
**
158561158806
** The number of bound variables is equal to the number of columns in
158562
-** the target table, plus one (for the ota_control column), plus one more
158563
-** (for the ota_rowid column) if the target table is an implicit IPK or
158807
+** the target table, plus one (for the rbu_control column), plus one more
158808
+** (for the rbu_rowid column) if the target table is an implicit IPK or
158564158809
** virtual table.
158565158810
*/
158566
-static void otaObjIterPrepareTmpInsert(
158567
- sqlite3ota *p,
158568
- OtaObjIter *pIter,
158811
+static void rbuObjIterPrepareTmpInsert(
158812
+ sqlite3rbu *p,
158813
+ RbuObjIter *pIter,
158569158814
const char *zCollist,
158570
- const char *zOtaRowid
158815
+ const char *zRbuRowid
158571158816
){
158572
- int bOtaRowid = (pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE);
158573
- char *zBind = otaObjIterGetBindlist(p, pIter->nTblCol + 1 + bOtaRowid);
158817
+ int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE);
158818
+ char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid);
158574158819
if( zBind ){
158575158820
assert( pIter->pTmpInsert==0 );
158576158821
p->rc = prepareFreeAndCollectError(
158577
- p->dbOta, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
158578
- "INSERT INTO %s.'ota_tmp_%q'(ota_control,%s%s) VALUES(%z)",
158579
- p->zStateDb, pIter->zTbl, zCollist, zOtaRowid, zBind
158822
+ p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
158823
+ "INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)",
158824
+ p->zStateDb, pIter->zTbl, zCollist, zRbuRowid, zBind
158580158825
));
158581158826
}
158582158827
}
158583158828
158584
-static void otaTmpInsertFunc(
158829
+static void rbuTmpInsertFunc(
158585158830
sqlite3_context *pCtx,
158586158831
int nVal,
158587158832
sqlite3_value **apVal
158588158833
){
158589
- sqlite3ota *p = sqlite3_user_data(pCtx);
158834
+ sqlite3rbu *p = sqlite3_user_data(pCtx);
158590158835
int rc = SQLITE_OK;
158591158836
int i;
158592158837
158593158838
for(i=0; rc==SQLITE_OK && i<nVal; i++){
158594158839
rc = sqlite3_bind_value(p->objiter.pTmpInsert, i+1, apVal[i]);
@@ -158606,17 +158851,17 @@
158606158851
/*
158607158852
** Ensure that the SQLite statement handles required to update the
158608158853
** target database object currently indicated by the iterator passed
158609158854
** as the second argument are available.
158610158855
*/
158611
-static int otaObjIterPrepareAll(
158612
- sqlite3ota *p,
158613
- OtaObjIter *pIter,
158856
+static int rbuObjIterPrepareAll(
158857
+ sqlite3rbu *p,
158858
+ RbuObjIter *pIter,
158614158859
int nOffset /* Add "LIMIT -1 OFFSET $nOffset" to SELECT */
158615158860
){
158616158861
assert( pIter->bCleanup==0 );
158617
- if( pIter->pSelect==0 && otaObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
158862
+ if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
158618158863
const int tnum = pIter->iTnum;
158619158864
char *zCollist = 0; /* List of indexed columns */
158620158865
char **pz = &p->zErrmsg;
158621158866
const char *zIdx = pIter->zIdx;
158622158867
char *zLimit = 0;
@@ -158632,104 +158877,104 @@
158632158877
char *zImposterPK = 0; /* Primary key declaration for imposter */
158633158878
char *zWhere = 0; /* WHERE clause on PK columns */
158634158879
char *zBind = 0;
158635158880
int nBind = 0;
158636158881
158637
- assert( pIter->eType!=OTA_PK_VTAB );
158638
- zCollist = otaObjIterGetIndexCols(
158882
+ assert( pIter->eType!=RBU_PK_VTAB );
158883
+ zCollist = rbuObjIterGetIndexCols(
158639158884
p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
158640158885
);
158641
- zBind = otaObjIterGetBindlist(p, nBind);
158886
+ zBind = rbuObjIterGetBindlist(p, nBind);
158642158887
158643158888
/* Create the imposter table used to write to this index. */
158644158889
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
158645158890
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
158646
- otaMPrintfExec(p, p->dbMain,
158647
- "CREATE TABLE \"ota_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID",
158891
+ rbuMPrintfExec(p, p->dbMain,
158892
+ "CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID",
158648158893
zTbl, zImposterCols, zImposterPK
158649158894
);
158650158895
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158651158896
158652158897
/* Create the statement to insert index entries */
158653158898
pIter->nCol = nBind;
158654158899
if( p->rc==SQLITE_OK ){
158655158900
p->rc = prepareFreeAndCollectError(
158656158901
p->dbMain, &pIter->pInsert, &p->zErrmsg,
158657
- sqlite3_mprintf("INSERT INTO \"ota_imp_%w\" VALUES(%s)", zTbl, zBind)
158902
+ sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
158658158903
);
158659158904
}
158660158905
158661158906
/* And to delete index entries */
158662158907
if( p->rc==SQLITE_OK ){
158663158908
p->rc = prepareFreeAndCollectError(
158664158909
p->dbMain, &pIter->pDelete, &p->zErrmsg,
158665
- sqlite3_mprintf("DELETE FROM \"ota_imp_%w\" WHERE %s", zTbl, zWhere)
158910
+ sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
158666158911
);
158667158912
}
158668158913
158669158914
/* Create the SELECT statement to read keys in sorted order */
158670158915
if( p->rc==SQLITE_OK ){
158671158916
char *zSql;
158672
- if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158917
+ if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158673158918
zSql = sqlite3_mprintf(
158674
- "SELECT %s, ota_control FROM %s.'ota_tmp_%q' ORDER BY %s%s",
158919
+ "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
158675158920
zCollist, p->zStateDb, pIter->zTbl,
158676158921
zCollist, zLimit
158677158922
);
158678158923
}else{
158679158924
zSql = sqlite3_mprintf(
158680
- "SELECT %s, ota_control FROM 'data_%q' "
158681
- "WHERE typeof(ota_control)='integer' AND ota_control!=1 "
158925
+ "SELECT %s, rbu_control FROM 'data_%q' "
158926
+ "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
158682158927
"UNION ALL "
158683
- "SELECT %s, ota_control FROM %s.'ota_tmp_%q' "
158928
+ "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
158684158929
"ORDER BY %s%s",
158685158930
zCollist, pIter->zTbl,
158686158931
zCollist, p->zStateDb, pIter->zTbl,
158687158932
zCollist, zLimit
158688158933
);
158689158934
}
158690
- p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz, zSql);
158935
+ p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
158691158936
}
158692158937
158693158938
sqlite3_free(zImposterCols);
158694158939
sqlite3_free(zImposterPK);
158695158940
sqlite3_free(zWhere);
158696158941
sqlite3_free(zBind);
158697158942
}else{
158698
- int bOtaRowid = (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE);
158943
+ int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
158699158944
const char *zTbl = pIter->zTbl; /* Table this step applies to */
158700158945
const char *zWrite; /* Imposter table name */
158701158946
158702
- char *zBindings = otaObjIterGetBindlist(p, pIter->nTblCol + bOtaRowid);
158703
- char *zWhere = otaObjIterGetWhere(p, pIter);
158704
- char *zOldlist = otaObjIterGetOldlist(p, pIter, "old");
158705
- char *zNewlist = otaObjIterGetOldlist(p, pIter, "new");
158947
+ char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
158948
+ char *zWhere = rbuObjIterGetWhere(p, pIter);
158949
+ char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old");
158950
+ char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
158706158951
158707
- zCollist = otaObjIterGetCollist(p, pIter);
158952
+ zCollist = rbuObjIterGetCollist(p, pIter);
158708158953
pIter->nCol = pIter->nTblCol;
158709158954
158710158955
/* Create the SELECT statement to read keys from data_xxx */
158711158956
if( p->rc==SQLITE_OK ){
158712
- p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz,
158957
+ p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
158713158958
sqlite3_mprintf(
158714
- "SELECT %s, ota_control%s FROM 'data_%q'%s",
158715
- zCollist, (bOtaRowid ? ", ota_rowid" : ""), zTbl, zLimit
158959
+ "SELECT %s, rbu_control%s FROM 'data_%q'%s",
158960
+ zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit
158716158961
)
158717158962
);
158718158963
}
158719158964
158720158965
/* Create the imposter table or tables (if required). */
158721
- otaCreateImposterTable(p, pIter);
158722
- otaCreateImposterTable2(p, pIter);
158723
- zWrite = (pIter->eType==OTA_PK_VTAB ? "" : "ota_imp_");
158966
+ rbuCreateImposterTable(p, pIter);
158967
+ rbuCreateImposterTable2(p, pIter);
158968
+ zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
158724158969
158725158970
/* Create the INSERT statement to write to the target PK b-tree */
158726158971
if( p->rc==SQLITE_OK ){
158727158972
p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz,
158728158973
sqlite3_mprintf(
158729158974
"INSERT INTO \"%s%w\"(%s%s) VALUES(%s)",
158730
- zWrite, zTbl, zCollist, (bOtaRowid ? ", _rowid_" : ""), zBindings
158975
+ zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
158731158976
)
158732158977
);
158733158978
}
158734158979
158735158980
/* Create the DELETE statement to write to the target PK b-tree */
@@ -158740,55 +158985,55 @@
158740158985
)
158741158986
);
158742158987
}
158743158988
158744158989
if( pIter->abIndexed ){
158745
- const char *zOtaRowid = "";
158746
- if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158747
- zOtaRowid = ", ota_rowid";
158990
+ const char *zRbuRowid = "";
158991
+ if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158992
+ zRbuRowid = ", rbu_rowid";
158748158993
}
158749158994
158750
- /* Create the ota_tmp_xxx table and the triggers to populate it. */
158751
- otaMPrintfExec(p, p->dbOta,
158752
- "CREATE TABLE IF NOT EXISTS %s.'ota_tmp_%q' AS "
158995
+ /* Create the rbu_tmp_xxx table and the triggers to populate it. */
158996
+ rbuMPrintfExec(p, p->dbRbu,
158997
+ "CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS "
158753158998
"SELECT *%s FROM 'data_%q' WHERE 0;"
158754158999
, p->zStateDb
158755
- , zTbl, (pIter->eType==OTA_PK_EXTERNAL ? ", 0 AS ota_rowid" : "")
159000
+ , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
158756159001
, zTbl
158757159002
);
158758159003
158759
- otaMPrintfExec(p, p->dbMain,
158760
- "CREATE TEMP TRIGGER ota_delete_tr BEFORE DELETE ON \"%s%w\" "
159004
+ rbuMPrintfExec(p, p->dbMain,
159005
+ "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" "
158761159006
"BEGIN "
158762
- " SELECT ota_tmp_insert(2, %s);"
159007
+ " SELECT rbu_tmp_insert(2, %s);"
158763159008
"END;"
158764159009
158765
- "CREATE TEMP TRIGGER ota_update1_tr BEFORE UPDATE ON \"%s%w\" "
159010
+ "CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" "
158766159011
"BEGIN "
158767
- " SELECT ota_tmp_insert(2, %s);"
159012
+ " SELECT rbu_tmp_insert(2, %s);"
158768159013
"END;"
158769159014
158770
- "CREATE TEMP TRIGGER ota_update2_tr AFTER UPDATE ON \"%s%w\" "
159015
+ "CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" "
158771159016
"BEGIN "
158772
- " SELECT ota_tmp_insert(3, %s);"
159017
+ " SELECT rbu_tmp_insert(3, %s);"
158773159018
"END;",
158774159019
zWrite, zTbl, zOldlist,
158775159020
zWrite, zTbl, zOldlist,
158776159021
zWrite, zTbl, zNewlist
158777159022
);
158778159023
158779
- if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158780
- otaMPrintfExec(p, p->dbMain,
158781
- "CREATE TEMP TRIGGER ota_insert_tr AFTER INSERT ON \"%s%w\" "
159024
+ if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
159025
+ rbuMPrintfExec(p, p->dbMain,
159026
+ "CREATE TEMP TRIGGER rbu_insert_tr AFTER INSERT ON \"%s%w\" "
158782159027
"BEGIN "
158783
- " SELECT ota_tmp_insert(0, %s);"
159028
+ " SELECT rbu_tmp_insert(0, %s);"
158784159029
"END;",
158785159030
zWrite, zTbl, zNewlist
158786159031
);
158787159032
}
158788159033
158789
- otaObjIterPrepareTmpInsert(p, pIter, zCollist, zOtaRowid);
159034
+ rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
158790159035
}
158791159036
158792159037
sqlite3_free(zWhere);
158793159038
sqlite3_free(zOldlist);
158794159039
sqlite3_free(zNewlist);
@@ -158803,68 +159048,68 @@
158803159048
158804159049
/*
158805159050
** Set output variable *ppStmt to point to an UPDATE statement that may
158806159051
** be used to update the imposter table for the main table b-tree of the
158807159052
** table object that pIter currently points to, assuming that the
158808
-** ota_control column of the data_xyz table contains zMask.
159053
+** rbu_control column of the data_xyz table contains zMask.
158809159054
**
158810159055
** If the zMask string does not specify any columns to update, then this
158811159056
** is not an error. Output variable *ppStmt is set to NULL in this case.
158812159057
*/
158813
-static int otaGetUpdateStmt(
158814
- sqlite3ota *p, /* OTA handle */
158815
- OtaObjIter *pIter, /* Object iterator */
158816
- const char *zMask, /* ota_control value ('x.x.') */
159058
+static int rbuGetUpdateStmt(
159059
+ sqlite3rbu *p, /* RBU handle */
159060
+ RbuObjIter *pIter, /* Object iterator */
159061
+ const char *zMask, /* rbu_control value ('x.x.') */
158817159062
sqlite3_stmt **ppStmt /* OUT: UPDATE statement handle */
158818159063
){
158819
- OtaUpdateStmt **pp;
158820
- OtaUpdateStmt *pUp = 0;
159064
+ RbuUpdateStmt **pp;
159065
+ RbuUpdateStmt *pUp = 0;
158821159066
int nUp = 0;
158822159067
158823159068
/* In case an error occurs */
158824159069
*ppStmt = 0;
158825159070
158826159071
/* Search for an existing statement. If one is found, shift it to the front
158827159072
** of the LRU queue and return immediately. Otherwise, leave nUp pointing
158828159073
** to the number of statements currently in the cache and pUp to the
158829159074
** last object in the list. */
158830
- for(pp=&pIter->pOtaUpdate; *pp; pp=&((*pp)->pNext)){
159075
+ for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){
158831159076
pUp = *pp;
158832159077
if( strcmp(pUp->zMask, zMask)==0 ){
158833159078
*pp = pUp->pNext;
158834
- pUp->pNext = pIter->pOtaUpdate;
158835
- pIter->pOtaUpdate = pUp;
159079
+ pUp->pNext = pIter->pRbuUpdate;
159080
+ pIter->pRbuUpdate = pUp;
158836159081
*ppStmt = pUp->pUpdate;
158837159082
return SQLITE_OK;
158838159083
}
158839159084
nUp++;
158840159085
}
158841159086
assert( pUp==0 || pUp->pNext==0 );
158842159087
158843
- if( nUp>=SQLITE_OTA_UPDATE_CACHESIZE ){
158844
- for(pp=&pIter->pOtaUpdate; *pp!=pUp; pp=&((*pp)->pNext));
159088
+ if( nUp>=SQLITE_RBU_UPDATE_CACHESIZE ){
159089
+ for(pp=&pIter->pRbuUpdate; *pp!=pUp; pp=&((*pp)->pNext));
158845159090
*pp = 0;
158846159091
sqlite3_finalize(pUp->pUpdate);
158847159092
pUp->pUpdate = 0;
158848159093
}else{
158849
- pUp = (OtaUpdateStmt*)otaMalloc(p, sizeof(OtaUpdateStmt)+pIter->nTblCol+1);
159094
+ pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1);
158850159095
}
158851159096
158852159097
if( pUp ){
158853
- char *zWhere = otaObjIterGetWhere(p, pIter);
158854
- char *zSet = otaObjIterGetSetlist(p, pIter, zMask);
159098
+ char *zWhere = rbuObjIterGetWhere(p, pIter);
159099
+ char *zSet = rbuObjIterGetSetlist(p, pIter, zMask);
158855159100
char *zUpdate = 0;
158856159101
158857159102
pUp->zMask = (char*)&pUp[1];
158858159103
memcpy(pUp->zMask, zMask, pIter->nTblCol);
158859
- pUp->pNext = pIter->pOtaUpdate;
158860
- pIter->pOtaUpdate = pUp;
159104
+ pUp->pNext = pIter->pRbuUpdate;
159105
+ pIter->pRbuUpdate = pUp;
158861159106
158862159107
if( zSet ){
158863159108
const char *zPrefix = "";
158864159109
158865
- if( pIter->eType!=OTA_PK_VTAB ) zPrefix = "ota_imp_";
159110
+ if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_";
158866159111
zUpdate = sqlite3_mprintf("UPDATE \"%s%w\" SET %s WHERE %s",
158867159112
zPrefix, pIter->zTbl, zSet, zWhere
158868159113
);
158869159114
p->rc = prepareFreeAndCollectError(
158870159115
p->dbMain, &pUp->pUpdate, &p->zErrmsg, zUpdate
@@ -158876,11 +159121,11 @@
158876159121
}
158877159122
158878159123
return p->rc;
158879159124
}
158880159125
158881
-static sqlite3 *otaOpenDbhandle(sqlite3ota *p, const char *zName){
159126
+static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){
158882159127
sqlite3 *db = 0;
158883159128
if( p->rc==SQLITE_OK ){
158884159129
const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
158885159130
p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
158886159131
if( p->rc ){
@@ -158891,51 +159136,51 @@
158891159136
}
158892159137
return db;
158893159138
}
158894159139
158895159140
/*
158896
-** Open the database handle and attach the OTA database as "ota". If an
158897
-** error occurs, leave an error code and message in the OTA handle.
159141
+** Open the database handle and attach the RBU database as "rbu". If an
159142
+** error occurs, leave an error code and message in the RBU handle.
158898159143
*/
158899
-static void otaOpenDatabase(sqlite3ota *p){
159144
+static void rbuOpenDatabase(sqlite3rbu *p){
158900159145
assert( p->rc==SQLITE_OK );
158901
- assert( p->dbMain==0 && p->dbOta==0 );
159146
+ assert( p->dbMain==0 && p->dbRbu==0 );
158902159147
158903159148
p->eStage = 0;
158904
- p->dbMain = otaOpenDbhandle(p, p->zTarget);
158905
- p->dbOta = otaOpenDbhandle(p, p->zOta);
159149
+ p->dbMain = rbuOpenDbhandle(p, p->zTarget);
159150
+ p->dbRbu = rbuOpenDbhandle(p, p->zRbu);
158906159151
158907
- /* If using separate OTA and state databases, attach the state database to
158908
- ** the OTA db handle now. */
159152
+ /* If using separate RBU and state databases, attach the state database to
159153
+ ** the RBU db handle now. */
158909159154
if( p->zState ){
158910
- otaMPrintfExec(p, p->dbOta, "ATTACH %Q AS stat", p->zState);
159155
+ rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
158911159156
memcpy(p->zStateDb, "stat", 4);
158912159157
}else{
158913159158
memcpy(p->zStateDb, "main", 4);
158914159159
}
158915159160
158916159161
if( p->rc==SQLITE_OK ){
158917159162
p->rc = sqlite3_create_function(p->dbMain,
158918
- "ota_tmp_insert", -1, SQLITE_UTF8, (void*)p, otaTmpInsertFunc, 0, 0
159163
+ "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
158919159164
);
158920159165
}
158921159166
158922159167
if( p->rc==SQLITE_OK ){
158923
- p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p);
159168
+ p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
158924159169
}
158925
- otaMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
159170
+ rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
158926159171
158927
- /* Mark the database file just opened as an OTA target database. If
158928
- ** this call returns SQLITE_NOTFOUND, then the OTA vfs is not in use.
159172
+ /* Mark the database file just opened as an RBU target database. If
159173
+ ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
158929159174
** This is an error. */
158930159175
if( p->rc==SQLITE_OK ){
158931
- p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p);
159176
+ p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
158932159177
}
158933159178
158934159179
if( p->rc==SQLITE_NOTFOUND ){
158935159180
p->rc = SQLITE_ERROR;
158936
- p->zErrmsg = sqlite3_mprintf("ota vfs not found");
159181
+ p->zErrmsg = sqlite3_mprintf("rbu vfs not found");
158937159182
}
158938159183
}
158939159184
158940159185
/*
158941159186
** This routine is a copy of the sqlite3FileSuffix3() routine from the core.
@@ -158955,11 +159200,11 @@
158955159200
** test.db-journal => test.nal
158956159201
** test.db-wal => test.wal
158957159202
** test.db-shm => test.shm
158958159203
** test.db-mj7f3319fa => test.9fa
158959159204
*/
158960
-static void otaFileSuffix3(const char *zBase, char *z){
159205
+static void rbuFileSuffix3(const char *zBase, char *z){
158961159206
#ifdef SQLITE_ENABLE_8_3_NAMES
158962159207
#if SQLITE_ENABLE_8_3_NAMES<2
158963159208
if( sqlite3_uri_boolean(zBase, "8_3_names", 0) )
158964159209
#endif
158965159210
{
@@ -158976,11 +159221,11 @@
158976159221
** as a 64-bit integer.
158977159222
**
158978159223
** The checksum is store in the first page of xShmMap memory as an 8-byte
158979159224
** blob starting at byte offset 40.
158980159225
*/
158981
-static i64 otaShmChecksum(sqlite3ota *p){
159226
+static i64 rbuShmChecksum(sqlite3rbu *p){
158982159227
i64 iRet = 0;
158983159228
if( p->rc==SQLITE_OK ){
158984159229
sqlite3_file *pDb = p->pTargetFd->pReal;
158985159230
u32 volatile *ptr;
158986159231
p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
@@ -158993,23 +159238,23 @@
158993159238
158994159239
/*
158995159240
** This function is called as part of initializing or reinitializing an
158996159241
** incremental checkpoint.
158997159242
**
158998
-** It populates the sqlite3ota.aFrame[] array with the set of
159243
+** It populates the sqlite3rbu.aFrame[] array with the set of
158999159244
** (wal frame -> db page) copy operations required to checkpoint the
159000159245
** current wal file, and obtains the set of shm locks required to safely
159001159246
** perform the copy operations directly on the file-system.
159002159247
**
159003159248
** If argument pState is not NULL, then the incremental checkpoint is
159004159249
** being resumed. In this case, if the checksum of the wal-index-header
159005
-** following recovery is not the same as the checksum saved in the OtaState
159006
-** object, then the ota handle is set to DONE state. This occurs if some
159250
+** following recovery is not the same as the checksum saved in the RbuState
159251
+** object, then the rbu handle is set to DONE state. This occurs if some
159007159252
** other client appends a transaction to the wal file in the middle of
159008159253
** an incremental checkpoint.
159009159254
*/
159010
-static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){
159255
+static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){
159011159256
159012159257
/* If pState is NULL, then the wal file may not have been opened and
159013159258
** recovered. Running a read-statement here to ensure that doing so
159014159259
** does not interfere with the "capture" process below. */
159015159260
if( pState==0 ){
@@ -159018,20 +159263,20 @@
159018159263
p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0);
159019159264
}
159020159265
}
159021159266
159022159267
/* Assuming no error has occurred, run a "restart" checkpoint with the
159023
- ** sqlite3ota.eStage variable set to CAPTURE. This turns on the following
159024
- ** special behaviour in the ota VFS:
159268
+ ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
159269
+ ** special behaviour in the rbu VFS:
159025159270
**
159026159271
** * If the exclusive shm WRITER or READ0 lock cannot be obtained,
159027159272
** the checkpoint fails with SQLITE_BUSY (normally SQLite would
159028159273
** proceed with running a passive checkpoint instead of failing).
159029159274
**
159030159275
** * Attempts to read from the *-wal file or write to the database file
159031159276
** do not perform any IO. Instead, the frame/page combinations that
159032
- ** would be read/written are recorded in the sqlite3ota.aFrame[]
159277
+ ** would be read/written are recorded in the sqlite3rbu.aFrame[]
159033159278
** array.
159034159279
**
159035159280
** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
159036159281
** READ0 and CHECKPOINT locks taken as part of the checkpoint are
159037159282
** no-ops. These locks will not be released until the connection
@@ -159047,76 +159292,76 @@
159047159292
** data from the wal file into the database file according to the
159048159293
** contents of aFrame[].
159049159294
*/
159050159295
if( p->rc==SQLITE_OK ){
159051159296
int rc2;
159052
- p->eStage = OTA_STAGE_CAPTURE;
159297
+ p->eStage = RBU_STAGE_CAPTURE;
159053159298
rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
159054159299
if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
159055159300
}
159056159301
159057159302
if( p->rc==SQLITE_OK ){
159058
- p->eStage = OTA_STAGE_CKPT;
159303
+ p->eStage = RBU_STAGE_CKPT;
159059159304
p->nStep = (pState ? pState->nRow : 0);
159060
- p->aBuf = otaMalloc(p, p->pgsz);
159061
- p->iWalCksum = otaShmChecksum(p);
159305
+ p->aBuf = rbuMalloc(p, p->pgsz);
159306
+ p->iWalCksum = rbuShmChecksum(p);
159062159307
}
159063159308
159064159309
if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
159065159310
p->rc = SQLITE_DONE;
159066
- p->eStage = OTA_STAGE_DONE;
159311
+ p->eStage = RBU_STAGE_DONE;
159067159312
}
159068159313
}
159069159314
159070159315
/*
159071159316
** Called when iAmt bytes are read from offset iOff of the wal file while
159072
-** the ota object is in capture mode. Record the frame number of the frame
159317
+** the rbu object is in capture mode. Record the frame number of the frame
159073159318
** being read in the aFrame[] array.
159074159319
*/
159075
-static int otaCaptureWalRead(sqlite3ota *pOta, i64 iOff, int iAmt){
159320
+static int rbuCaptureWalRead(sqlite3rbu *pRbu, i64 iOff, int iAmt){
159076159321
const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0);
159077159322
u32 iFrame;
159078159323
159079
- if( pOta->mLock!=mReq ){
159080
- pOta->rc = SQLITE_BUSY;
159324
+ if( pRbu->mLock!=mReq ){
159325
+ pRbu->rc = SQLITE_BUSY;
159081159326
return SQLITE_INTERNAL;
159082159327
}
159083159328
159084
- pOta->pgsz = iAmt;
159085
- if( pOta->nFrame==pOta->nFrameAlloc ){
159086
- int nNew = (pOta->nFrameAlloc ? pOta->nFrameAlloc : 64) * 2;
159087
- OtaFrame *aNew;
159088
- aNew = (OtaFrame*)sqlite3_realloc(pOta->aFrame, nNew * sizeof(OtaFrame));
159329
+ pRbu->pgsz = iAmt;
159330
+ if( pRbu->nFrame==pRbu->nFrameAlloc ){
159331
+ int nNew = (pRbu->nFrameAlloc ? pRbu->nFrameAlloc : 64) * 2;
159332
+ RbuFrame *aNew;
159333
+ aNew = (RbuFrame*)sqlite3_realloc(pRbu->aFrame, nNew * sizeof(RbuFrame));
159089159334
if( aNew==0 ) return SQLITE_NOMEM;
159090
- pOta->aFrame = aNew;
159091
- pOta->nFrameAlloc = nNew;
159335
+ pRbu->aFrame = aNew;
159336
+ pRbu->nFrameAlloc = nNew;
159092159337
}
159093159338
159094159339
iFrame = (u32)((iOff-32) / (i64)(iAmt+24)) + 1;
159095
- if( pOta->iMaxFrame<iFrame ) pOta->iMaxFrame = iFrame;
159096
- pOta->aFrame[pOta->nFrame].iWalFrame = iFrame;
159097
- pOta->aFrame[pOta->nFrame].iDbPage = 0;
159098
- pOta->nFrame++;
159340
+ if( pRbu->iMaxFrame<iFrame ) pRbu->iMaxFrame = iFrame;
159341
+ pRbu->aFrame[pRbu->nFrame].iWalFrame = iFrame;
159342
+ pRbu->aFrame[pRbu->nFrame].iDbPage = 0;
159343
+ pRbu->nFrame++;
159099159344
return SQLITE_OK;
159100159345
}
159101159346
159102159347
/*
159103159348
** Called when a page of data is written to offset iOff of the database
159104
-** file while the ota handle is in capture mode. Record the page number
159349
+** file while the rbu handle is in capture mode. Record the page number
159105159350
** of the page being written in the aFrame[] array.
159106159351
*/
159107
-static int otaCaptureDbWrite(sqlite3ota *pOta, i64 iOff){
159108
- pOta->aFrame[pOta->nFrame-1].iDbPage = (u32)(iOff / pOta->pgsz) + 1;
159352
+static int rbuCaptureDbWrite(sqlite3rbu *pRbu, i64 iOff){
159353
+ pRbu->aFrame[pRbu->nFrame-1].iDbPage = (u32)(iOff / pRbu->pgsz) + 1;
159109159354
return SQLITE_OK;
159110159355
}
159111159356
159112159357
/*
159113159358
** This is called as part of an incremental checkpoint operation. Copy
159114159359
** a single frame of data from the wal file into the database file, as
159115
-** indicated by the OtaFrame object.
159360
+** indicated by the RbuFrame object.
159116159361
*/
159117
-static void otaCheckpointFrame(sqlite3ota *p, OtaFrame *pFrame){
159362
+static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){
159118159363
sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal;
159119159364
sqlite3_file *pDb = p->pTargetFd->pReal;
159120159365
i64 iOff;
159121159366
159122159367
assert( p->rc==SQLITE_OK );
@@ -159130,33 +159375,33 @@
159130159375
159131159376
159132159377
/*
159133159378
** Take an EXCLUSIVE lock on the database file.
159134159379
*/
159135
-static void otaLockDatabase(sqlite3ota *p){
159380
+static void rbuLockDatabase(sqlite3rbu *p){
159136159381
sqlite3_file *pReal = p->pTargetFd->pReal;
159137159382
assert( p->rc==SQLITE_OK );
159138159383
p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED);
159139159384
if( p->rc==SQLITE_OK ){
159140159385
p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE);
159141159386
}
159142159387
}
159143159388
159144159389
/*
159145
-** The OTA handle is currently in OTA_STAGE_OAL state, with a SHARED lock
159390
+** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock
159146159391
** on the database file. This proc moves the *-oal file to the *-wal path,
159147159392
** then reopens the database file (this time in vanilla, non-oal, WAL mode).
159148
-** If an error occurs, leave an error code and error message in the ota
159393
+** If an error occurs, leave an error code and error message in the rbu
159149159394
** handle.
159150159395
*/
159151
-static void otaMoveOalFile(sqlite3ota *p){
159396
+static void rbuMoveOalFile(sqlite3rbu *p){
159152159397
const char *zBase = sqlite3_db_filename(p->dbMain, "main");
159153159398
159154159399
char *zWal = sqlite3_mprintf("%s-wal", zBase);
159155159400
char *zOal = sqlite3_mprintf("%s-oal", zBase);
159156159401
159157
- assert( p->eStage==OTA_STAGE_MOVE );
159402
+ assert( p->eStage==RBU_STAGE_MOVE );
159158159403
assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159159159404
if( zWal==0 || zOal==0 ){
159160159405
p->rc = SQLITE_NOMEM;
159161159406
}else{
159162159407
/* Move the *-oal file to *-wal. At this point connection p->db is
@@ -159164,25 +159409,25 @@
159164159409
** in WAL mode). So no other connection may be writing the db.
159165159410
**
159166159411
** In order to ensure that there are no database readers, an EXCLUSIVE
159167159412
** lock is obtained here before the *-oal is moved to *-wal.
159168159413
*/
159169
- otaLockDatabase(p);
159414
+ rbuLockDatabase(p);
159170159415
if( p->rc==SQLITE_OK ){
159171
- otaFileSuffix3(zBase, zWal);
159172
- otaFileSuffix3(zBase, zOal);
159416
+ rbuFileSuffix3(zBase, zWal);
159417
+ rbuFileSuffix3(zBase, zOal);
159173159418
159174159419
/* Re-open the databases. */
159175
- otaObjIterFinalize(&p->objiter);
159420
+ rbuObjIterFinalize(&p->objiter);
159176159421
sqlite3_close(p->dbMain);
159177
- sqlite3_close(p->dbOta);
159422
+ sqlite3_close(p->dbRbu);
159178159423
p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
159179159424
if( p->rc==SQLITE_OK ){
159180159425
p->dbMain = 0;
159181
- p->dbOta = 0;
159182
- otaOpenDatabase(p);
159183
- otaSetupCheckpoint(p, 0);
159426
+ p->dbRbu = 0;
159427
+ rbuOpenDatabase(p);
159428
+ rbuSetupCheckpoint(p, 0);
159184159429
}
159185159430
}
159186159431
}
159187159432
159188159433
sqlite3_free(zWal);
@@ -159193,36 +159438,36 @@
159193159438
** The SELECT statement iterating through the keys for the current object
159194159439
** (p->objiter.pSelect) currently points to a valid row. This function
159195159440
** determines the type of operation requested by this row and returns
159196159441
** one of the following values to indicate the result:
159197159442
**
159198
-** * OTA_INSERT
159199
-** * OTA_DELETE
159200
-** * OTA_IDX_DELETE
159201
-** * OTA_UPDATE
159443
+** * RBU_INSERT
159444
+** * RBU_DELETE
159445
+** * RBU_IDX_DELETE
159446
+** * RBU_UPDATE
159202159447
**
159203
-** If OTA_UPDATE is returned, then output variable *pzMask is set to
159448
+** If RBU_UPDATE is returned, then output variable *pzMask is set to
159204159449
** point to the text value indicating the columns to update.
159205159450
**
159206
-** If the ota_control field contains an invalid value, an error code and
159207
-** message are left in the OTA handle and zero returned.
159451
+** If the rbu_control field contains an invalid value, an error code and
159452
+** message are left in the RBU handle and zero returned.
159208159453
*/
159209
-static int otaStepType(sqlite3ota *p, const char **pzMask){
159210
- int iCol = p->objiter.nCol; /* Index of ota_control column */
159454
+static int rbuStepType(sqlite3rbu *p, const char **pzMask){
159455
+ int iCol = p->objiter.nCol; /* Index of rbu_control column */
159211159456
int res = 0; /* Return value */
159212159457
159213159458
switch( sqlite3_column_type(p->objiter.pSelect, iCol) ){
159214159459
case SQLITE_INTEGER: {
159215159460
int iVal = sqlite3_column_int(p->objiter.pSelect, iCol);
159216159461
if( iVal==0 ){
159217
- res = OTA_INSERT;
159462
+ res = RBU_INSERT;
159218159463
}else if( iVal==1 ){
159219
- res = OTA_DELETE;
159464
+ res = RBU_DELETE;
159220159465
}else if( iVal==2 ){
159221
- res = OTA_IDX_DELETE;
159466
+ res = RBU_IDX_DELETE;
159222159467
}else if( iVal==3 ){
159223
- res = OTA_IDX_INSERT;
159468
+ res = RBU_IDX_INSERT;
159224159469
}
159225159470
break;
159226159471
}
159227159472
159228159473
case SQLITE_TEXT: {
@@ -159230,21 +159475,21 @@
159230159475
if( z==0 ){
159231159476
p->rc = SQLITE_NOMEM;
159232159477
}else{
159233159478
*pzMask = (const char*)z;
159234159479
}
159235
- res = OTA_UPDATE;
159480
+ res = RBU_UPDATE;
159236159481
159237159482
break;
159238159483
}
159239159484
159240159485
default:
159241159486
break;
159242159487
}
159243159488
159244159489
if( res==0 ){
159245
- otaBadControlError(p);
159490
+ rbuBadControlError(p);
159246159491
}
159247159492
return res;
159248159493
}
159249159494
159250159495
#ifdef SQLITE_DEBUG
@@ -159258,82 +159503,82 @@
159258159503
#else
159259159504
# define assertColumnName(x,y,z)
159260159505
#endif
159261159506
159262159507
/*
159263
-** This function does the work for an sqlite3ota_step() call.
159508
+** This function does the work for an sqlite3rbu_step() call.
159264159509
**
159265159510
** The object-iterator (p->objiter) currently points to a valid object,
159266159511
** and the input cursor (p->objiter.pSelect) currently points to a valid
159267159512
** input row. Perform whatever processing is required and return.
159268159513
**
159269159514
** If no error occurs, SQLITE_OK is returned. Otherwise, an error code
159270
-** and message is left in the OTA handle and a copy of the error code
159515
+** and message is left in the RBU handle and a copy of the error code
159271159516
** returned.
159272159517
*/
159273
-static int otaStep(sqlite3ota *p){
159274
- OtaObjIter *pIter = &p->objiter;
159518
+static int rbuStep(sqlite3rbu *p){
159519
+ RbuObjIter *pIter = &p->objiter;
159275159520
const char *zMask = 0;
159276159521
int i;
159277
- int eType = otaStepType(p, &zMask);
159522
+ int eType = rbuStepType(p, &zMask);
159278159523
159279159524
if( eType ){
159280
- assert( eType!=OTA_UPDATE || pIter->zIdx==0 );
159525
+ assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
159281159526
159282
- if( pIter->zIdx==0 && eType==OTA_IDX_DELETE ){
159283
- otaBadControlError(p);
159527
+ if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){
159528
+ rbuBadControlError(p);
159284159529
}
159285159530
else if(
159286
- eType==OTA_INSERT
159287
- || eType==OTA_DELETE
159288
- || eType==OTA_IDX_DELETE
159289
- || eType==OTA_IDX_INSERT
159531
+ eType==RBU_INSERT
159532
+ || eType==RBU_DELETE
159533
+ || eType==RBU_IDX_DELETE
159534
+ || eType==RBU_IDX_INSERT
159290159535
){
159291159536
sqlite3_value *pVal;
159292159537
sqlite3_stmt *pWriter;
159293159538
159294
- assert( eType!=OTA_UPDATE );
159295
- assert( eType!=OTA_DELETE || pIter->zIdx==0 );
159539
+ assert( eType!=RBU_UPDATE );
159540
+ assert( eType!=RBU_DELETE || pIter->zIdx==0 );
159296159541
159297
- if( eType==OTA_IDX_DELETE || eType==OTA_DELETE ){
159542
+ if( eType==RBU_IDX_DELETE || eType==RBU_DELETE ){
159298159543
pWriter = pIter->pDelete;
159299159544
}else{
159300159545
pWriter = pIter->pInsert;
159301159546
}
159302159547
159303159548
for(i=0; i<pIter->nCol; i++){
159304159549
/* If this is an INSERT into a table b-tree and the table has an
159305159550
** explicit INTEGER PRIMARY KEY, check that this is not an attempt
159306159551
** to write a NULL into the IPK column. That is not permitted. */
159307
- if( eType==OTA_INSERT
159308
- && pIter->zIdx==0 && pIter->eType==OTA_PK_IPK && pIter->abTblPk[i]
159552
+ if( eType==RBU_INSERT
159553
+ && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
159309159554
&& sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL
159310159555
){
159311159556
p->rc = SQLITE_MISMATCH;
159312159557
p->zErrmsg = sqlite3_mprintf("datatype mismatch");
159313159558
goto step_out;
159314159559
}
159315159560
159316
- if( eType==OTA_DELETE && pIter->abTblPk[i]==0 ){
159561
+ if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
159317159562
continue;
159318159563
}
159319159564
159320159565
pVal = sqlite3_column_value(pIter->pSelect, i);
159321159566
p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
159322159567
if( p->rc ) goto step_out;
159323159568
}
159324159569
if( pIter->zIdx==0
159325
- && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE)
159570
+ && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
159326159571
){
159327159572
/* For a virtual table, or a table with no primary key, the
159328159573
** SELECT statement is:
159329159574
**
159330
- ** SELECT <cols>, ota_control, ota_rowid FROM ....
159575
+ ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
159331159576
**
159332159577
** Hence column_value(pIter->nCol+1).
159333159578
*/
159334
- assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid");
159579
+ assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
159335159580
pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159336159581
p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
159337159582
}
159338159583
if( p->rc==SQLITE_OK ){
159339159584
sqlite3_step(pWriter);
@@ -159340,25 +159585,25 @@
159340159585
p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
159341159586
}
159342159587
}else{
159343159588
sqlite3_value *pVal;
159344159589
sqlite3_stmt *pUpdate = 0;
159345
- assert( eType==OTA_UPDATE );
159346
- otaGetUpdateStmt(p, pIter, zMask, &pUpdate);
159590
+ assert( eType==RBU_UPDATE );
159591
+ rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
159347159592
if( pUpdate ){
159348159593
for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
159349159594
char c = zMask[pIter->aiSrcOrder[i]];
159350159595
pVal = sqlite3_column_value(pIter->pSelect, i);
159351159596
if( pIter->abTblPk[i] || c=='x' || c=='d' ){
159352159597
p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
159353159598
}
159354159599
}
159355159600
if( p->rc==SQLITE_OK
159356
- && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE)
159601
+ && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
159357159602
){
159358
- /* Bind the ota_rowid value to column _rowid_ */
159359
- assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid");
159603
+ /* Bind the rbu_rowid value to column _rowid_ */
159604
+ assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
159360159605
pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159361159606
p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal);
159362159607
}
159363159608
if( p->rc==SQLITE_OK ){
159364159609
sqlite3_step(pUpdate);
@@ -159373,11 +159618,11 @@
159373159618
}
159374159619
159375159620
/*
159376159621
** Increment the schema cookie of the main database opened by p->dbMain.
159377159622
*/
159378
-static void otaIncrSchemaCookie(sqlite3ota *p){
159623
+static void rbuIncrSchemaCookie(sqlite3rbu *p){
159379159624
if( p->rc==SQLITE_OK ){
159380159625
int iCookie = 1000000;
159381159626
sqlite3_stmt *pStmt;
159382159627
159383159628
p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
@@ -159390,49 +159635,49 @@
159390159635
** statement reads is page 1, which is guaranteed to be in the cache.
159391159636
** And no memory allocations are required. */
159392159637
if( SQLITE_ROW==sqlite3_step(pStmt) ){
159393159638
iCookie = sqlite3_column_int(pStmt, 0);
159394159639
}
159395
- otaFinalize(p, pStmt);
159640
+ rbuFinalize(p, pStmt);
159396159641
}
159397159642
if( p->rc==SQLITE_OK ){
159398
- otaMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1);
159643
+ rbuMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1);
159399159644
}
159400159645
}
159401159646
}
159402159647
159403159648
/*
159404
-** Update the contents of the ota_state table within the ota database. The
159405
-** value stored in the OTA_STATE_STAGE column is eStage. All other values
159406
-** are determined by inspecting the ota handle passed as the first argument.
159649
+** Update the contents of the rbu_state table within the rbu database. The
159650
+** value stored in the RBU_STATE_STAGE column is eStage. All other values
159651
+** are determined by inspecting the rbu handle passed as the first argument.
159407159652
*/
159408
-static void otaSaveState(sqlite3ota *p, int eStage){
159653
+static void rbuSaveState(sqlite3rbu *p, int eStage){
159409159654
if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
159410159655
sqlite3_stmt *pInsert = 0;
159411159656
int rc;
159412159657
159413159658
assert( p->zErrmsg==0 );
159414
- rc = prepareFreeAndCollectError(p->dbOta, &pInsert, &p->zErrmsg,
159659
+ rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
159415159660
sqlite3_mprintf(
159416
- "INSERT OR REPLACE INTO %s.ota_state(k, v) VALUES "
159661
+ "INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES "
159417159662
"(%d, %d), "
159418159663
"(%d, %Q), "
159419159664
"(%d, %Q), "
159420159665
"(%d, %d), "
159421159666
"(%d, %d), "
159422159667
"(%d, %lld), "
159423159668
"(%d, %lld), "
159424159669
"(%d, %lld) ",
159425159670
p->zStateDb,
159426
- OTA_STATE_STAGE, eStage,
159427
- OTA_STATE_TBL, p->objiter.zTbl,
159428
- OTA_STATE_IDX, p->objiter.zIdx,
159429
- OTA_STATE_ROW, p->nStep,
159430
- OTA_STATE_PROGRESS, p->nProgress,
159431
- OTA_STATE_CKPT, p->iWalCksum,
159432
- OTA_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
159433
- OTA_STATE_OALSZ, p->iOalSz
159671
+ RBU_STATE_STAGE, eStage,
159672
+ RBU_STATE_TBL, p->objiter.zTbl,
159673
+ RBU_STATE_IDX, p->objiter.zIdx,
159674
+ RBU_STATE_ROW, p->nStep,
159675
+ RBU_STATE_PROGRESS, p->nProgress,
159676
+ RBU_STATE_CKPT, p->iWalCksum,
159677
+ RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
159678
+ RBU_STATE_OALSZ, p->iOalSz
159434159679
)
159435159680
);
159436159681
assert( pInsert==0 || rc==SQLITE_OK );
159437159682
159438159683
if( rc==SQLITE_OK ){
@@ -159443,71 +159688,71 @@
159443159688
}
159444159689
}
159445159690
159446159691
159447159692
/*
159448
-** Step the OTA object.
159693
+** Step the RBU object.
159449159694
*/
159450
-SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *p){
159695
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
159451159696
if( p ){
159452159697
switch( p->eStage ){
159453
- case OTA_STAGE_OAL: {
159454
- OtaObjIter *pIter = &p->objiter;
159698
+ case RBU_STAGE_OAL: {
159699
+ RbuObjIter *pIter = &p->objiter;
159455159700
while( p->rc==SQLITE_OK && pIter->zTbl ){
159456159701
159457159702
if( pIter->bCleanup ){
159458
- /* Clean up the ota_tmp_xxx table for the previous table. It
159703
+ /* Clean up the rbu_tmp_xxx table for the previous table. It
159459159704
** cannot be dropped as there are currently active SQL statements.
159460159705
** But the contents can be deleted. */
159461159706
if( pIter->abIndexed ){
159462
- otaMPrintfExec(p, p->dbOta,
159463
- "DELETE FROM %s.'ota_tmp_%q'", p->zStateDb, pIter->zTbl
159707
+ rbuMPrintfExec(p, p->dbRbu,
159708
+ "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zTbl
159464159709
);
159465159710
}
159466159711
}else{
159467
- otaObjIterPrepareAll(p, pIter, 0);
159712
+ rbuObjIterPrepareAll(p, pIter, 0);
159468159713
159469159714
/* Advance to the next row to process. */
159470159715
if( p->rc==SQLITE_OK ){
159471159716
int rc = sqlite3_step(pIter->pSelect);
159472159717
if( rc==SQLITE_ROW ){
159473159718
p->nProgress++;
159474159719
p->nStep++;
159475
- return otaStep(p);
159720
+ return rbuStep(p);
159476159721
}
159477159722
p->rc = sqlite3_reset(pIter->pSelect);
159478159723
p->nStep = 0;
159479159724
}
159480159725
}
159481159726
159482
- otaObjIterNext(p, pIter);
159727
+ rbuObjIterNext(p, pIter);
159483159728
}
159484159729
159485159730
if( p->rc==SQLITE_OK ){
159486159731
assert( pIter->zTbl==0 );
159487
- otaSaveState(p, OTA_STAGE_MOVE);
159488
- otaIncrSchemaCookie(p);
159732
+ rbuSaveState(p, RBU_STAGE_MOVE);
159733
+ rbuIncrSchemaCookie(p);
159489159734
if( p->rc==SQLITE_OK ){
159490159735
p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
159491159736
}
159492159737
if( p->rc==SQLITE_OK ){
159493
- p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg);
159494
- }
159495
- p->eStage = OTA_STAGE_MOVE;
159496
- }
159497
- break;
159498
- }
159499
-
159500
- case OTA_STAGE_MOVE: {
159738
+ p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
159739
+ }
159740
+ p->eStage = RBU_STAGE_MOVE;
159741
+ }
159742
+ break;
159743
+ }
159744
+
159745
+ case RBU_STAGE_MOVE: {
159501159746
if( p->rc==SQLITE_OK ){
159502
- otaMoveOalFile(p);
159747
+ rbuMoveOalFile(p);
159503159748
p->nProgress++;
159504159749
}
159505159750
break;
159506159751
}
159507159752
159508
- case OTA_STAGE_CKPT: {
159753
+ case RBU_STAGE_CKPT: {
159509159754
if( p->rc==SQLITE_OK ){
159510159755
if( p->nStep>=p->nFrame ){
159511159756
sqlite3_file *pDb = p->pTargetFd->pReal;
159512159757
159513159758
/* Sync the db file */
@@ -159521,16 +159766,16 @@
159521159766
((u32 volatile*)ptr)[24] = p->iMaxFrame;
159522159767
}
159523159768
}
159524159769
159525159770
if( p->rc==SQLITE_OK ){
159526
- p->eStage = OTA_STAGE_DONE;
159771
+ p->eStage = RBU_STAGE_DONE;
159527159772
p->rc = SQLITE_DONE;
159528159773
}
159529159774
}else{
159530
- OtaFrame *pFrame = &p->aFrame[p->nStep];
159531
- otaCheckpointFrame(p, pFrame);
159775
+ RbuFrame *pFrame = &p->aFrame[p->nStep];
159776
+ rbuCheckpointFrame(p, pFrame);
159532159777
p->nStep++;
159533159778
}
159534159779
p->nProgress++;
159535159780
}
159536159781
break;
@@ -159544,78 +159789,78 @@
159544159789
return SQLITE_NOMEM;
159545159790
}
159546159791
}
159547159792
159548159793
/*
159549
-** Free an OtaState object allocated by otaLoadState().
159794
+** Free an RbuState object allocated by rbuLoadState().
159550159795
*/
159551
-static void otaFreeState(OtaState *p){
159796
+static void rbuFreeState(RbuState *p){
159552159797
if( p ){
159553159798
sqlite3_free(p->zTbl);
159554159799
sqlite3_free(p->zIdx);
159555159800
sqlite3_free(p);
159556159801
}
159557159802
}
159558159803
159559159804
/*
159560
-** Allocate an OtaState object and load the contents of the ota_state
159805
+** Allocate an RbuState object and load the contents of the rbu_state
159561159806
** table into it. Return a pointer to the new object. It is the
159562159807
** responsibility of the caller to eventually free the object using
159563159808
** sqlite3_free().
159564159809
**
159565
-** If an error occurs, leave an error code and message in the ota handle
159810
+** If an error occurs, leave an error code and message in the rbu handle
159566159811
** and return NULL.
159567159812
*/
159568
-static OtaState *otaLoadState(sqlite3ota *p){
159569
- OtaState *pRet = 0;
159813
+static RbuState *rbuLoadState(sqlite3rbu *p){
159814
+ RbuState *pRet = 0;
159570159815
sqlite3_stmt *pStmt = 0;
159571159816
int rc;
159572159817
int rc2;
159573159818
159574
- pRet = (OtaState*)otaMalloc(p, sizeof(OtaState));
159819
+ pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
159575159820
if( pRet==0 ) return 0;
159576159821
159577
- rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg,
159578
- sqlite3_mprintf("SELECT k, v FROM %s.ota_state", p->zStateDb)
159822
+ rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
159823
+ sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
159579159824
);
159580159825
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
159581159826
switch( sqlite3_column_int(pStmt, 0) ){
159582
- case OTA_STATE_STAGE:
159827
+ case RBU_STATE_STAGE:
159583159828
pRet->eStage = sqlite3_column_int(pStmt, 1);
159584
- if( pRet->eStage!=OTA_STAGE_OAL
159585
- && pRet->eStage!=OTA_STAGE_MOVE
159586
- && pRet->eStage!=OTA_STAGE_CKPT
159829
+ if( pRet->eStage!=RBU_STAGE_OAL
159830
+ && pRet->eStage!=RBU_STAGE_MOVE
159831
+ && pRet->eStage!=RBU_STAGE_CKPT
159587159832
){
159588159833
p->rc = SQLITE_CORRUPT;
159589159834
}
159590159835
break;
159591159836
159592
- case OTA_STATE_TBL:
159593
- pRet->zTbl = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159837
+ case RBU_STATE_TBL:
159838
+ pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159594159839
break;
159595159840
159596
- case OTA_STATE_IDX:
159597
- pRet->zIdx = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159841
+ case RBU_STATE_IDX:
159842
+ pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159598159843
break;
159599159844
159600
- case OTA_STATE_ROW:
159845
+ case RBU_STATE_ROW:
159601159846
pRet->nRow = sqlite3_column_int(pStmt, 1);
159602159847
break;
159603159848
159604
- case OTA_STATE_PROGRESS:
159849
+ case RBU_STATE_PROGRESS:
159605159850
pRet->nProgress = sqlite3_column_int64(pStmt, 1);
159606159851
break;
159607159852
159608
- case OTA_STATE_CKPT:
159853
+ case RBU_STATE_CKPT:
159609159854
pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
159610159855
break;
159611159856
159612
- case OTA_STATE_COOKIE:
159857
+ case RBU_STATE_COOKIE:
159613159858
pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
159614159859
break;
159615159860
159616
- case OTA_STATE_OALSZ:
159861
+ case RBU_STATE_OALSZ:
159617159862
pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
159618159863
break;
159619159864
159620159865
default:
159621159866
rc = SQLITE_CORRUPT;
@@ -159632,142 +159877,142 @@
159632159877
/*
159633159878
** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
159634159879
** otherwise. Either or both argument may be NULL. Two NULL values are
159635159880
** considered equal, and NULL is considered distinct from all other values.
159636159881
*/
159637
-static int otaStrCompare(const char *z1, const char *z2){
159882
+static int rbuStrCompare(const char *z1, const char *z2){
159638159883
if( z1==0 && z2==0 ) return 0;
159639159884
if( z1==0 || z2==0 ) return 1;
159640159885
return (sqlite3_stricmp(z1, z2)!=0);
159641159886
}
159642159887
159643159888
/*
159644
-** This function is called as part of sqlite3ota_open() when initializing
159645
-** an ota handle in OAL stage. If the ota update has not started (i.e.
159646
-** the ota_state table was empty) it is a no-op. Otherwise, it arranges
159647
-** things so that the next call to sqlite3ota_step() continues on from
159648
-** where the previous ota handle left off.
159889
+** This function is called as part of sqlite3rbu_open() when initializing
159890
+** an rbu handle in OAL stage. If the rbu update has not started (i.e.
159891
+** the rbu_state table was empty) it is a no-op. Otherwise, it arranges
159892
+** things so that the next call to sqlite3rbu_step() continues on from
159893
+** where the previous rbu handle left off.
159649159894
**
159650159895
** If an error occurs, an error code and error message are left in the
159651
-** ota handle passed as the first argument.
159896
+** rbu handle passed as the first argument.
159652159897
*/
159653
-static void otaSetupOal(sqlite3ota *p, OtaState *pState){
159898
+static void rbuSetupOal(sqlite3rbu *p, RbuState *pState){
159654159899
assert( p->rc==SQLITE_OK );
159655159900
if( pState->zTbl ){
159656
- OtaObjIter *pIter = &p->objiter;
159901
+ RbuObjIter *pIter = &p->objiter;
159657159902
int rc = SQLITE_OK;
159658159903
159659159904
while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup
159660
- || otaStrCompare(pIter->zIdx, pState->zIdx)
159661
- || otaStrCompare(pIter->zTbl, pState->zTbl)
159905
+ || rbuStrCompare(pIter->zIdx, pState->zIdx)
159906
+ || rbuStrCompare(pIter->zTbl, pState->zTbl)
159662159907
)){
159663
- rc = otaObjIterNext(p, pIter);
159908
+ rc = rbuObjIterNext(p, pIter);
159664159909
}
159665159910
159666159911
if( rc==SQLITE_OK && !pIter->zTbl ){
159667159912
rc = SQLITE_ERROR;
159668
- p->zErrmsg = sqlite3_mprintf("ota_state mismatch error");
159913
+ p->zErrmsg = sqlite3_mprintf("rbu_state mismatch error");
159669159914
}
159670159915
159671159916
if( rc==SQLITE_OK ){
159672159917
p->nStep = pState->nRow;
159673
- rc = otaObjIterPrepareAll(p, &p->objiter, p->nStep);
159918
+ rc = rbuObjIterPrepareAll(p, &p->objiter, p->nStep);
159674159919
}
159675159920
159676159921
p->rc = rc;
159677159922
}
159678159923
}
159679159924
159680159925
/*
159681159926
** If there is a "*-oal" file in the file-system corresponding to the
159682159927
** target database in the file-system, delete it. If an error occurs,
159683
-** leave an error code and error message in the ota handle.
159928
+** leave an error code and error message in the rbu handle.
159684159929
*/
159685
-static void otaDeleteOalFile(sqlite3ota *p){
159930
+static void rbuDeleteOalFile(sqlite3rbu *p){
159686159931
char *zOal = sqlite3_mprintf("%s-oal", p->zTarget);
159687159932
assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159688159933
unlink(zOal);
159689159934
sqlite3_free(zOal);
159690159935
}
159691159936
159692159937
/*
159693
-** Allocate a private ota VFS for the ota handle passed as the only
159694
-** argument. This VFS will be used unless the call to sqlite3ota_open()
159938
+** Allocate a private rbu VFS for the rbu handle passed as the only
159939
+** argument. This VFS will be used unless the call to sqlite3rbu_open()
159695159940
** specified a URI with a vfs=? option in place of a target database
159696159941
** file name.
159697159942
*/
159698
-static void otaCreateVfs(sqlite3ota *p){
159943
+static void rbuCreateVfs(sqlite3rbu *p){
159699159944
int rnd;
159700159945
char zRnd[64];
159701159946
159702159947
assert( p->rc==SQLITE_OK );
159703159948
sqlite3_randomness(sizeof(int), (void*)&rnd);
159704
- sprintf(zRnd, "ota_vfs_%d", rnd);
159705
- p->rc = sqlite3ota_create_vfs(zRnd, 0);
159949
+ sqlite3_snprintf(sizeof(zRnd), zRnd, "rbu_vfs_%d", rnd);
159950
+ p->rc = sqlite3rbu_create_vfs(zRnd, 0);
159706159951
if( p->rc==SQLITE_OK ){
159707159952
sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd);
159708159953
assert( pVfs );
159709159954
p->zVfsName = pVfs->zName;
159710159955
}
159711159956
}
159712159957
159713159958
/*
159714
-** Destroy the private VFS created for the ota handle passed as the only
159715
-** argument by an earlier call to otaCreateVfs().
159959
+** Destroy the private VFS created for the rbu handle passed as the only
159960
+** argument by an earlier call to rbuCreateVfs().
159716159961
*/
159717
-static void otaDeleteVfs(sqlite3ota *p){
159962
+static void rbuDeleteVfs(sqlite3rbu *p){
159718159963
if( p->zVfsName ){
159719
- sqlite3ota_destroy_vfs(p->zVfsName);
159964
+ sqlite3rbu_destroy_vfs(p->zVfsName);
159720159965
p->zVfsName = 0;
159721159966
}
159722159967
}
159723159968
159724159969
/*
159725
-** Open and return a new OTA handle.
159970
+** Open and return a new RBU handle.
159726159971
*/
159727
-SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open(
159972
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
159728159973
const char *zTarget,
159729
- const char *zOta,
159974
+ const char *zRbu,
159730159975
const char *zState
159731159976
){
159732
- sqlite3ota *p;
159977
+ sqlite3rbu *p;
159733159978
int nTarget = strlen(zTarget);
159734
- int nOta = strlen(zOta);
159979
+ int nRbu = strlen(zRbu);
159735159980
int nState = zState ? strlen(zState) : 0;
159736159981
159737
- p = (sqlite3ota*)sqlite3_malloc(sizeof(sqlite3ota)+nTarget+1+nOta+1+nState+1);
159982
+ p = (sqlite3rbu*)sqlite3_malloc(sizeof(sqlite3rbu)+nTarget+1+nRbu+1+nState+1);
159738159983
if( p ){
159739
- OtaState *pState = 0;
159984
+ RbuState *pState = 0;
159740159985
159741159986
/* Create the custom VFS. */
159742
- memset(p, 0, sizeof(sqlite3ota));
159743
- otaCreateVfs(p);
159987
+ memset(p, 0, sizeof(sqlite3rbu));
159988
+ rbuCreateVfs(p);
159744159989
159745159990
/* Open the target database */
159746159991
if( p->rc==SQLITE_OK ){
159747159992
p->zTarget = (char*)&p[1];
159748159993
memcpy(p->zTarget, zTarget, nTarget+1);
159749
- p->zOta = &p->zTarget[nTarget+1];
159750
- memcpy(p->zOta, zOta, nOta+1);
159994
+ p->zRbu = &p->zTarget[nTarget+1];
159995
+ memcpy(p->zRbu, zRbu, nRbu+1);
159751159996
if( zState ){
159752
- p->zState = &p->zOta[nOta+1];
159997
+ p->zState = &p->zRbu[nRbu+1];
159753159998
memcpy(p->zState, zState, nState+1);
159754159999
}
159755
- otaOpenDatabase(p);
160000
+ rbuOpenDatabase(p);
159756160001
}
159757160002
159758
- /* If it has not already been created, create the ota_state table */
159759
- otaMPrintfExec(p, p->dbOta, OTA_CREATE_STATE, p->zStateDb);
160003
+ /* If it has not already been created, create the rbu_state table */
160004
+ rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
159760160005
159761160006
if( p->rc==SQLITE_OK ){
159762
- pState = otaLoadState(p);
160007
+ pState = rbuLoadState(p);
159763160008
assert( pState || p->rc!=SQLITE_OK );
159764160009
if( p->rc==SQLITE_OK ){
159765160010
159766160011
if( pState->eStage==0 ){
159767
- otaDeleteOalFile(p);
159768
- p->eStage = OTA_STAGE_OAL;
160012
+ rbuDeleteOalFile(p);
160013
+ p->eStage = RBU_STAGE_OAL;
159769160014
}else{
159770160015
p->eStage = pState->eStage;
159771160016
}
159772160017
p->nProgress = pState->nProgress;
159773160018
p->iOalSz = pState->iOalSz;
@@ -159774,97 +160019,97 @@
159774160019
}
159775160020
}
159776160021
assert( p->rc!=SQLITE_OK || p->eStage!=0 );
159777160022
159778160023
if( p->rc==SQLITE_OK && p->pTargetFd->pWalFd ){
159779
- if( p->eStage==OTA_STAGE_OAL ){
160024
+ if( p->eStage==RBU_STAGE_OAL ){
159780160025
p->rc = SQLITE_ERROR;
159781160026
p->zErrmsg = sqlite3_mprintf("cannot update wal mode database");
159782
- }else if( p->eStage==OTA_STAGE_MOVE ){
159783
- p->eStage = OTA_STAGE_CKPT;
160027
+ }else if( p->eStage==RBU_STAGE_MOVE ){
160028
+ p->eStage = RBU_STAGE_CKPT;
159784160029
p->nStep = 0;
159785160030
}
159786160031
}
159787160032
159788160033
if( p->rc==SQLITE_OK
159789
- && (p->eStage==OTA_STAGE_OAL || p->eStage==OTA_STAGE_MOVE)
160034
+ && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
159790160035
&& pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
159791160036
){
159792160037
/* At this point (pTargetFd->iCookie) contains the value of the
159793160038
** change-counter cookie (the thing that gets incremented when a
159794160039
** transaction is committed in rollback mode) currently stored on
159795160040
** page 1 of the database file. */
159796160041
p->rc = SQLITE_BUSY;
159797
- p->zErrmsg = sqlite3_mprintf("database modified during ota update");
160042
+ p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
159798160043
}
159799160044
159800160045
if( p->rc==SQLITE_OK ){
159801
- if( p->eStage==OTA_STAGE_OAL ){
160046
+ if( p->eStage==RBU_STAGE_OAL ){
159802160047
159803160048
/* Open transactions both databases. The *-oal file is opened or
159804160049
** created at this point. */
159805160050
p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
159806160051
if( p->rc==SQLITE_OK ){
159807
- p->rc = sqlite3_exec(p->dbOta, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160052
+ p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
159808160053
}
159809160054
159810160055
/* Point the object iterator at the first object */
159811160056
if( p->rc==SQLITE_OK ){
159812
- p->rc = otaObjIterFirst(p, &p->objiter);
160057
+ p->rc = rbuObjIterFirst(p, &p->objiter);
159813160058
}
159814160059
159815
- /* If the OTA database contains no data_xxx tables, declare the OTA
160060
+ /* If the RBU database contains no data_xxx tables, declare the RBU
159816160061
** update finished. */
159817160062
if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
159818160063
p->rc = SQLITE_DONE;
159819160064
}
159820160065
159821160066
if( p->rc==SQLITE_OK ){
159822
- otaSetupOal(p, pState);
160067
+ rbuSetupOal(p, pState);
159823160068
}
159824160069
159825
- }else if( p->eStage==OTA_STAGE_MOVE ){
160070
+ }else if( p->eStage==RBU_STAGE_MOVE ){
159826160071
/* no-op */
159827
- }else if( p->eStage==OTA_STAGE_CKPT ){
159828
- otaSetupCheckpoint(p, pState);
159829
- }else if( p->eStage==OTA_STAGE_DONE ){
160072
+ }else if( p->eStage==RBU_STAGE_CKPT ){
160073
+ rbuSetupCheckpoint(p, pState);
160074
+ }else if( p->eStage==RBU_STAGE_DONE ){
159830160075
p->rc = SQLITE_DONE;
159831160076
}else{
159832160077
p->rc = SQLITE_CORRUPT;
159833160078
}
159834160079
}
159835160080
159836
- otaFreeState(pState);
160081
+ rbuFreeState(pState);
159837160082
}
159838160083
159839160084
return p;
159840160085
}
159841160086
159842160087
159843160088
/*
159844
-** Return the database handle used by pOta.
160089
+** Return the database handle used by pRbu.
159845160090
*/
159846
-SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota *pOta, int bOta){
160091
+SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
159847160092
sqlite3 *db = 0;
159848
- if( pOta ){
159849
- db = (bOta ? pOta->dbOta : pOta->dbMain);
160093
+ if( pRbu ){
160094
+ db = (bRbu ? pRbu->dbRbu : pRbu->dbMain);
159850160095
}
159851160096
return db;
159852160097
}
159853160098
159854160099
159855160100
/*
159856
-** If the error code currently stored in the OTA handle is SQLITE_CONSTRAINT,
160101
+** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT,
159857160102
** then edit any error message string so as to remove all occurrences of
159858
-** the pattern "ota_imp_[0-9]*".
160103
+** the pattern "rbu_imp_[0-9]*".
159859160104
*/
159860
-static void otaEditErrmsg(sqlite3ota *p){
160105
+static void rbuEditErrmsg(sqlite3rbu *p){
159861160106
if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
159862160107
int i;
159863160108
int nErrmsg = strlen(p->zErrmsg);
159864160109
for(i=0; i<(nErrmsg-8); i++){
159865
- if( memcmp(&p->zErrmsg[i], "ota_imp_", 8)==0 ){
160110
+ if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
159866160111
int nDel = 8;
159867160112
while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
159868160113
memmove(&p->zErrmsg[i], &p->zErrmsg[i+nDel], nErrmsg + 1 - i - nDel);
159869160114
nErrmsg -= nDel;
159870160115
}
@@ -159871,38 +160116,38 @@
159871160116
}
159872160117
}
159873160118
}
159874160119
159875160120
/*
159876
-** Close the OTA handle.
160121
+** Close the RBU handle.
159877160122
*/
159878
-SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *p, char **pzErrmsg){
160123
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){
159879160124
int rc;
159880160125
if( p ){
159881160126
159882160127
/* Commit the transaction to the *-oal file. */
159883
- if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){
160128
+ if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
159884160129
p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
159885160130
}
159886160131
159887
- otaSaveState(p, p->eStage);
160132
+ rbuSaveState(p, p->eStage);
159888160133
159889
- if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){
159890
- p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg);
160134
+ if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
160135
+ p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
159891160136
}
159892160137
159893160138
/* Close any open statement handles. */
159894
- otaObjIterFinalize(&p->objiter);
160139
+ rbuObjIterFinalize(&p->objiter);
159895160140
159896160141
/* Close the open database handle and VFS object. */
159897160142
sqlite3_close(p->dbMain);
159898
- sqlite3_close(p->dbOta);
159899
- otaDeleteVfs(p);
160143
+ sqlite3_close(p->dbRbu);
160144
+ rbuDeleteVfs(p);
159900160145
sqlite3_free(p->aBuf);
159901160146
sqlite3_free(p->aFrame);
159902160147
159903
- otaEditErrmsg(p);
160148
+ rbuEditErrmsg(p);
159904160149
rc = p->rc;
159905160150
*pzErrmsg = p->zErrmsg;
159906160151
sqlite3_free(p);
159907160152
}else{
159908160153
rc = SQLITE_NOMEM;
@@ -159912,65 +160157,65 @@
159912160157
}
159913160158
159914160159
/*
159915160160
** Return the total number of key-value operations (inserts, deletes or
159916160161
** updates) that have been performed on the target database since the
159917
-** current OTA update was started.
160162
+** current RBU update was started.
159918160163
*/
159919
-SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta){
159920
- return pOta->nProgress;
160164
+SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){
160165
+ return pRbu->nProgress;
159921160166
}
159922160167
159923160168
/**************************************************************************
159924
-** Beginning of OTA VFS shim methods. The VFS shim modifies the behaviour
160169
+** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
159925160170
** of a standard VFS in the following ways:
159926160171
**
159927160172
** 1. Whenever the first page of a main database file is read or
159928160173
** written, the value of the change-counter cookie is stored in
159929
-** ota_file.iCookie. Similarly, the value of the "write-version"
159930
-** database header field is stored in ota_file.iWriteVer. This ensures
160174
+** rbu_file.iCookie. Similarly, the value of the "write-version"
160175
+** database header field is stored in rbu_file.iWriteVer. This ensures
159931160176
** that the values are always trustworthy within an open transaction.
159932160177
**
159933
-** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (ota_file.pWalFd)
160178
+** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (rbu_file.pWalFd)
159934160179
** member variable of the associated database file descriptor is set
159935160180
** to point to the new file. A mutex protected linked list of all main
159936
-** db fds opened using a particular OTA VFS is maintained at
159937
-** ota_vfs.pMain to facilitate this.
160181
+** db fds opened using a particular RBU VFS is maintained at
160182
+** rbu_vfs.pMain to facilitate this.
159938160183
**
159939
-** 3. Using a new file-control "SQLITE_FCNTL_OTA", a main db ota_file
159940
-** object can be marked as the target database of an OTA update. This
160184
+** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file
160185
+** object can be marked as the target database of an RBU update. This
159941160186
** turns on the following extra special behaviour:
159942160187
**
159943160188
** 3a. If xAccess() is called to check if there exists a *-wal file
159944
-** associated with an OTA target database currently in OTA_STAGE_OAL
160189
+** associated with an RBU target database currently in RBU_STAGE_OAL
159945160190
** stage (preparing the *-oal file), the following special handling
159946160191
** applies:
159947160192
**
159948
-** * if the *-wal file does exist, return SQLITE_CANTOPEN. An OTA
160193
+** * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU
159949160194
** target database may not be in wal mode already.
159950160195
**
159951160196
** * if the *-wal file does not exist, set the output parameter to
159952160197
** non-zero (to tell SQLite that it does exist) anyway.
159953160198
**
159954160199
** Then, when xOpen() is called to open the *-wal file associated with
159955
-** the OTA target in OTA_STAGE_OAL stage, instead of opening the *-wal
159956
-** file, the ota vfs opens the corresponding *-oal file instead.
160200
+** the RBU target in RBU_STAGE_OAL stage, instead of opening the *-wal
160201
+** file, the rbu vfs opens the corresponding *-oal file instead.
159957160202
**
159958160203
** 3b. The *-shm pages returned by xShmMap() for a target db file in
159959
-** OTA_STAGE_OAL mode are actually stored in heap memory. This is to
160204
+** RBU_STAGE_OAL mode are actually stored in heap memory. This is to
159960160205
** avoid creating a *-shm file on disk. Additionally, xShmLock() calls
159961
-** are no-ops on target database files in OTA_STAGE_OAL mode. This is
160206
+** are no-ops on target database files in RBU_STAGE_OAL mode. This is
159962160207
** because assert() statements in some VFS implementations fail if
159963160208
** xShmLock() is called before xShmMap().
159964160209
**
159965160210
** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
159966
-** mode except OTA_STAGE_DONE (all work completed and checkpointed), it
159967
-** fails with an SQLITE_BUSY error. This is to stop OTA connections
160211
+** mode except RBU_STAGE_DONE (all work completed and checkpointed), it
160212
+** fails with an SQLITE_BUSY error. This is to stop RBU connections
159968160213
** from automatically checkpointing a *-wal (or *-oal) file from within
159969160214
** sqlite3_close().
159970160215
**
159971
-** 3d. In OTA_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
160216
+** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
159972160217
** all xWrite() calls on the target database file perform no IO.
159973160218
** Instead the frame and page numbers that would be read and written
159974160219
** are recorded. Additionally, successful attempts to obtain exclusive
159975160220
** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
159976160221
** database file are recorded. xShmLock() calls to unlock the same
@@ -159977,28 +160222,28 @@
159977160222
** locks are no-ops (so that once obtained, these locks are never
159978160223
** relinquished). Finally, calls to xSync() on the target database
159979160224
** file fail with SQLITE_INTERNAL errors.
159980160225
*/
159981160226
159982
-static void otaUnlockShm(ota_file *p){
159983
- if( p->pOta ){
160227
+static void rbuUnlockShm(rbu_file *p){
160228
+ if( p->pRbu ){
159984160229
int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock;
159985160230
int i;
159986160231
for(i=0; i<SQLITE_SHM_NLOCK;i++){
159987
- if( (1<<i) & p->pOta->mLock ){
160232
+ if( (1<<i) & p->pRbu->mLock ){
159988160233
xShmLock(p->pReal, i, 1, SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE);
159989160234
}
159990160235
}
159991
- p->pOta->mLock = 0;
160236
+ p->pRbu->mLock = 0;
159992160237
}
159993160238
}
159994160239
159995160240
/*
159996
-** Close an ota file.
160241
+** Close an rbu file.
159997160242
*/
159998
-static int otaVfsClose(sqlite3_file *pFile){
159999
- ota_file *p = (ota_file*)pFile;
160243
+static int rbuVfsClose(sqlite3_file *pFile){
160244
+ rbu_file *p = (rbu_file*)pFile;
160000160245
int rc;
160001160246
int i;
160002160247
160003160248
/* Free the contents of the apShm[] array. And the array itself. */
160004160249
for(i=0; i<p->nShm; i++){
@@ -160007,16 +160252,16 @@
160007160252
sqlite3_free(p->apShm);
160008160253
p->apShm = 0;
160009160254
sqlite3_free(p->zDel);
160010160255
160011160256
if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160012
- ota_file **pp;
160013
- sqlite3_mutex_enter(p->pOtaVfs->mutex);
160014
- for(pp=&p->pOtaVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext));
160257
+ rbu_file **pp;
160258
+ sqlite3_mutex_enter(p->pRbuVfs->mutex);
160259
+ for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext));
160015160260
*pp = p->pMainNext;
160016
- sqlite3_mutex_leave(p->pOtaVfs->mutex);
160017
- otaUnlockShm(p);
160261
+ sqlite3_mutex_leave(p->pRbuVfs->mutex);
160262
+ rbuUnlockShm(p);
160018160263
p->pReal->pMethods->xShmUnmap(p->pReal, 0);
160019160264
}
160020160265
160021160266
/* Close the underlying file handle */
160022160267
rc = p->pReal->pMethods->xClose(p->pReal);
@@ -160026,37 +160271,37 @@
160026160271
160027160272
/*
160028160273
** Read and return an unsigned 32-bit big-endian integer from the buffer
160029160274
** passed as the only argument.
160030160275
*/
160031
-static u32 otaGetU32(u8 *aBuf){
160276
+static u32 rbuGetU32(u8 *aBuf){
160032160277
return ((u32)aBuf[0] << 24)
160033160278
+ ((u32)aBuf[1] << 16)
160034160279
+ ((u32)aBuf[2] << 8)
160035160280
+ ((u32)aBuf[3]);
160036160281
}
160037160282
160038160283
/*
160039
-** Read data from an otaVfs-file.
160284
+** Read data from an rbuVfs-file.
160040160285
*/
160041
-static int otaVfsRead(
160286
+static int rbuVfsRead(
160042160287
sqlite3_file *pFile,
160043160288
void *zBuf,
160044160289
int iAmt,
160045160290
sqlite_int64 iOfst
160046160291
){
160047
- ota_file *p = (ota_file*)pFile;
160048
- sqlite3ota *pOta = p->pOta;
160292
+ rbu_file *p = (rbu_file*)pFile;
160293
+ sqlite3rbu *pRbu = p->pRbu;
160049160294
int rc;
160050160295
160051
- if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){
160296
+ if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
160052160297
assert( p->openFlags & SQLITE_OPEN_WAL );
160053
- rc = otaCaptureWalRead(p->pOta, iOfst, iAmt);
160298
+ rc = rbuCaptureWalRead(p->pRbu, iOfst, iAmt);
160054160299
}else{
160055
- if( pOta && pOta->eStage==OTA_STAGE_OAL
160300
+ if( pRbu && pRbu->eStage==RBU_STAGE_OAL
160056160301
&& (p->openFlags & SQLITE_OPEN_WAL)
160057
- && iOfst>=pOta->iOalSz
160302
+ && iOfst>=pRbu->iOalSz
160058160303
){
160059160304
rc = SQLITE_OK;
160060160305
memset(zBuf, 0, iAmt);
160061160306
}else{
160062160307
rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
@@ -160063,92 +160308,92 @@
160063160308
}
160064160309
if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160065160310
/* These look like magic numbers. But they are stable, as they are part
160066160311
** of the definition of the SQLite file format, which may not change. */
160067160312
u8 *pBuf = (u8*)zBuf;
160068
- p->iCookie = otaGetU32(&pBuf[24]);
160313
+ p->iCookie = rbuGetU32(&pBuf[24]);
160069160314
p->iWriteVer = pBuf[19];
160070160315
}
160071160316
}
160072160317
return rc;
160073160318
}
160074160319
160075160320
/*
160076
-** Write data to an otaVfs-file.
160321
+** Write data to an rbuVfs-file.
160077160322
*/
160078
-static int otaVfsWrite(
160323
+static int rbuVfsWrite(
160079160324
sqlite3_file *pFile,
160080160325
const void *zBuf,
160081160326
int iAmt,
160082160327
sqlite_int64 iOfst
160083160328
){
160084
- ota_file *p = (ota_file*)pFile;
160085
- sqlite3ota *pOta = p->pOta;
160329
+ rbu_file *p = (rbu_file*)pFile;
160330
+ sqlite3rbu *pRbu = p->pRbu;
160086160331
int rc;
160087160332
160088
- if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){
160333
+ if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
160089160334
assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
160090
- rc = otaCaptureDbWrite(p->pOta, iOfst);
160335
+ rc = rbuCaptureDbWrite(p->pRbu, iOfst);
160091160336
}else{
160092
- if( pOta && pOta->eStage==OTA_STAGE_OAL
160337
+ if( pRbu && pRbu->eStage==RBU_STAGE_OAL
160093160338
&& (p->openFlags & SQLITE_OPEN_WAL)
160094
- && iOfst>=pOta->iOalSz
160339
+ && iOfst>=pRbu->iOalSz
160095160340
){
160096
- pOta->iOalSz = iAmt + iOfst;
160341
+ pRbu->iOalSz = iAmt + iOfst;
160097160342
}
160098160343
rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
160099160344
if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160100160345
/* These look like magic numbers. But they are stable, as they are part
160101160346
** of the definition of the SQLite file format, which may not change. */
160102160347
u8 *pBuf = (u8*)zBuf;
160103
- p->iCookie = otaGetU32(&pBuf[24]);
160348
+ p->iCookie = rbuGetU32(&pBuf[24]);
160104160349
p->iWriteVer = pBuf[19];
160105160350
}
160106160351
}
160107160352
return rc;
160108160353
}
160109160354
160110160355
/*
160111
-** Truncate an otaVfs-file.
160356
+** Truncate an rbuVfs-file.
160112160357
*/
160113
-static int otaVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
160114
- ota_file *p = (ota_file*)pFile;
160358
+static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
160359
+ rbu_file *p = (rbu_file*)pFile;
160115160360
return p->pReal->pMethods->xTruncate(p->pReal, size);
160116160361
}
160117160362
160118160363
/*
160119
-** Sync an otaVfs-file.
160364
+** Sync an rbuVfs-file.
160120160365
*/
160121
-static int otaVfsSync(sqlite3_file *pFile, int flags){
160122
- ota_file *p = (ota_file *)pFile;
160123
- if( p->pOta && p->pOta->eStage==OTA_STAGE_CAPTURE ){
160366
+static int rbuVfsSync(sqlite3_file *pFile, int flags){
160367
+ rbu_file *p = (rbu_file *)pFile;
160368
+ if( p->pRbu && p->pRbu->eStage==RBU_STAGE_CAPTURE ){
160124160369
if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160125160370
return SQLITE_INTERNAL;
160126160371
}
160127160372
return SQLITE_OK;
160128160373
}
160129160374
return p->pReal->pMethods->xSync(p->pReal, flags);
160130160375
}
160131160376
160132160377
/*
160133
-** Return the current file-size of an otaVfs-file.
160378
+** Return the current file-size of an rbuVfs-file.
160134160379
*/
160135
-static int otaVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
160136
- ota_file *p = (ota_file *)pFile;
160380
+static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
160381
+ rbu_file *p = (rbu_file *)pFile;
160137160382
return p->pReal->pMethods->xFileSize(p->pReal, pSize);
160138160383
}
160139160384
160140160385
/*
160141
-** Lock an otaVfs-file.
160386
+** Lock an rbuVfs-file.
160142160387
*/
160143
-static int otaVfsLock(sqlite3_file *pFile, int eLock){
160144
- ota_file *p = (ota_file*)pFile;
160145
- sqlite3ota *pOta = p->pOta;
160388
+static int rbuVfsLock(sqlite3_file *pFile, int eLock){
160389
+ rbu_file *p = (rbu_file*)pFile;
160390
+ sqlite3rbu *pRbu = p->pRbu;
160146160391
int rc = SQLITE_OK;
160147160392
160148160393
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160149
- if( pOta && eLock==SQLITE_LOCK_EXCLUSIVE && pOta->eStage!=OTA_STAGE_DONE ){
160394
+ if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){
160150160395
/* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
160151160396
** prevents it from checkpointing the database from sqlite3_close(). */
160152160397
rc = SQLITE_BUSY;
160153160398
}else{
160154160399
rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -160156,122 +160401,122 @@
160156160401
160157160402
return rc;
160158160403
}
160159160404
160160160405
/*
160161
-** Unlock an otaVfs-file.
160406
+** Unlock an rbuVfs-file.
160162160407
*/
160163
-static int otaVfsUnlock(sqlite3_file *pFile, int eLock){
160164
- ota_file *p = (ota_file *)pFile;
160408
+static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){
160409
+ rbu_file *p = (rbu_file *)pFile;
160165160410
return p->pReal->pMethods->xUnlock(p->pReal, eLock);
160166160411
}
160167160412
160168160413
/*
160169
-** Check if another file-handle holds a RESERVED lock on an otaVfs-file.
160414
+** Check if another file-handle holds a RESERVED lock on an rbuVfs-file.
160170160415
*/
160171
-static int otaVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
160172
- ota_file *p = (ota_file *)pFile;
160416
+static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
160417
+ rbu_file *p = (rbu_file *)pFile;
160173160418
return p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut);
160174160419
}
160175160420
160176160421
/*
160177
-** File control method. For custom operations on an otaVfs-file.
160422
+** File control method. For custom operations on an rbuVfs-file.
160178160423
*/
160179
-static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
160180
- ota_file *p = (ota_file *)pFile;
160424
+static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
160425
+ rbu_file *p = (rbu_file *)pFile;
160181160426
int (*xControl)(sqlite3_file*,int,void*) = p->pReal->pMethods->xFileControl;
160182160427
int rc;
160183160428
160184160429
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB)
160185160430
|| p->openFlags & (SQLITE_OPEN_TRANSIENT_DB|SQLITE_OPEN_TEMP_JOURNAL)
160186160431
);
160187
- if( op==SQLITE_FCNTL_OTA ){
160188
- sqlite3ota *pOta = (sqlite3ota*)pArg;
160432
+ if( op==SQLITE_FCNTL_RBU ){
160433
+ sqlite3rbu *pRbu = (sqlite3rbu*)pArg;
160189160434
160190
- /* First try to find another OTA vfs lower down in the vfs stack. If
160435
+ /* First try to find another RBU vfs lower down in the vfs stack. If
160191160436
** one is found, this vfs will operate in pass-through mode. The lower
160192
- ** level vfs will do the special OTA handling. */
160437
+ ** level vfs will do the special RBU handling. */
160193160438
rc = xControl(p->pReal, op, pArg);
160194160439
160195160440
if( rc==SQLITE_NOTFOUND ){
160196160441
/* Now search for a zipvfs instance lower down in the VFS stack. If
160197160442
** one is found, this is an error. */
160198160443
void *dummy = 0;
160199160444
rc = xControl(p->pReal, SQLITE_FCNTL_ZIPVFS, &dummy);
160200160445
if( rc==SQLITE_OK ){
160201160446
rc = SQLITE_ERROR;
160202
- pOta->zErrmsg = sqlite3_mprintf("ota/zipvfs setup error");
160447
+ pRbu->zErrmsg = sqlite3_mprintf("rbu/zipvfs setup error");
160203160448
}else if( rc==SQLITE_NOTFOUND ){
160204
- pOta->pTargetFd = p;
160205
- p->pOta = pOta;
160206
- if( p->pWalFd ) p->pWalFd->pOta = pOta;
160449
+ pRbu->pTargetFd = p;
160450
+ p->pRbu = pRbu;
160451
+ if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
160207160452
rc = SQLITE_OK;
160208160453
}
160209160454
}
160210160455
return rc;
160211160456
}
160212160457
160213160458
rc = xControl(p->pReal, op, pArg);
160214160459
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
160215
- ota_vfs *pOtaVfs = p->pOtaVfs;
160460
+ rbu_vfs *pRbuVfs = p->pRbuVfs;
160216160461
char *zIn = *(char**)pArg;
160217
- char *zOut = sqlite3_mprintf("ota(%s)/%z", pOtaVfs->base.zName, zIn);
160462
+ char *zOut = sqlite3_mprintf("rbu(%s)/%z", pRbuVfs->base.zName, zIn);
160218160463
*(char**)pArg = zOut;
160219160464
if( zOut==0 ) rc = SQLITE_NOMEM;
160220160465
}
160221160466
160222160467
return rc;
160223160468
}
160224160469
160225160470
/*
160226
-** Return the sector-size in bytes for an otaVfs-file.
160471
+** Return the sector-size in bytes for an rbuVfs-file.
160227160472
*/
160228
-static int otaVfsSectorSize(sqlite3_file *pFile){
160229
- ota_file *p = (ota_file *)pFile;
160473
+static int rbuVfsSectorSize(sqlite3_file *pFile){
160474
+ rbu_file *p = (rbu_file *)pFile;
160230160475
return p->pReal->pMethods->xSectorSize(p->pReal);
160231160476
}
160232160477
160233160478
/*
160234
-** Return the device characteristic flags supported by an otaVfs-file.
160479
+** Return the device characteristic flags supported by an rbuVfs-file.
160235160480
*/
160236
-static int otaVfsDeviceCharacteristics(sqlite3_file *pFile){
160237
- ota_file *p = (ota_file *)pFile;
160481
+static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){
160482
+ rbu_file *p = (rbu_file *)pFile;
160238160483
return p->pReal->pMethods->xDeviceCharacteristics(p->pReal);
160239160484
}
160240160485
160241160486
/*
160242160487
** Take or release a shared-memory lock.
160243160488
*/
160244
-static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
160245
- ota_file *p = (ota_file*)pFile;
160246
- sqlite3ota *pOta = p->pOta;
160489
+static int rbuVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
160490
+ rbu_file *p = (rbu_file*)pFile;
160491
+ sqlite3rbu *pRbu = p->pRbu;
160247160492
int rc = SQLITE_OK;
160248160493
160249160494
#ifdef SQLITE_AMALGAMATION
160250160495
assert( WAL_CKPT_LOCK==1 );
160251160496
#endif
160252160497
160253160498
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160254
- if( pOta && (pOta->eStage==OTA_STAGE_OAL || pOta->eStage==OTA_STAGE_MOVE) ){
160499
+ if( pRbu && (pRbu->eStage==RBU_STAGE_OAL || pRbu->eStage==RBU_STAGE_MOVE) ){
160255160500
/* Magic number 1 is the WAL_CKPT_LOCK lock. Preventing SQLite from
160256160501
** taking this lock also prevents any checkpoints from occurring.
160257160502
** todo: really, it's not clear why this might occur, as
160258160503
** wal_autocheckpoint ought to be turned off. */
160259160504
if( ofst==WAL_LOCK_CKPT && n==1 ) rc = SQLITE_BUSY;
160260160505
}else{
160261160506
int bCapture = 0;
160262160507
if( n==1 && (flags & SQLITE_SHM_EXCLUSIVE)
160263
- && pOta && pOta->eStage==OTA_STAGE_CAPTURE
160508
+ && pRbu && pRbu->eStage==RBU_STAGE_CAPTURE
160264160509
&& (ofst==WAL_LOCK_WRITE || ofst==WAL_LOCK_CKPT || ofst==WAL_LOCK_READ0)
160265160510
){
160266160511
bCapture = 1;
160267160512
}
160268160513
160269160514
if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){
160270160515
rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags);
160271160516
if( bCapture && rc==SQLITE_OK ){
160272
- pOta->mLock |= (1 << ofst);
160517
+ pRbu->mLock |= (1 << ofst);
160273160518
}
160274160519
}
160275160520
}
160276160521
160277160522
return rc;
@@ -160278,26 +160523,26 @@
160278160523
}
160279160524
160280160525
/*
160281160526
** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
160282160527
*/
160283
-static int otaVfsShmMap(
160528
+static int rbuVfsShmMap(
160284160529
sqlite3_file *pFile,
160285160530
int iRegion,
160286160531
int szRegion,
160287160532
int isWrite,
160288160533
void volatile **pp
160289160534
){
160290
- ota_file *p = (ota_file*)pFile;
160535
+ rbu_file *p = (rbu_file*)pFile;
160291160536
int rc = SQLITE_OK;
160292
- int eStage = (p->pOta ? p->pOta->eStage : 0);
160537
+ int eStage = (p->pRbu ? p->pRbu->eStage : 0);
160293160538
160294
- /* If not in OTA_STAGE_OAL, allow this call to pass through. Or, if this
160295
- ** ota is in the OTA_STAGE_OAL state, use heap memory for *-shm space
160539
+ /* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this
160540
+ ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
160296160541
** instead of a file on disk. */
160297160542
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160298
- if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){
160543
+ if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
160299160544
if( iRegion<=p->nShm ){
160300160545
int nByte = (iRegion+1) * sizeof(char*);
160301160546
char **apNew = (char**)sqlite3_realloc(p->apShm, nByte);
160302160547
if( apNew==0 ){
160303160548
rc = SQLITE_NOMEM;
@@ -160332,29 +160577,29 @@
160332160577
}
160333160578
160334160579
/*
160335160580
** Memory barrier.
160336160581
*/
160337
-static void otaVfsShmBarrier(sqlite3_file *pFile){
160338
- ota_file *p = (ota_file *)pFile;
160582
+static void rbuVfsShmBarrier(sqlite3_file *pFile){
160583
+ rbu_file *p = (rbu_file *)pFile;
160339160584
p->pReal->pMethods->xShmBarrier(p->pReal);
160340160585
}
160341160586
160342160587
/*
160343160588
** The xShmUnmap method.
160344160589
*/
160345
-static int otaVfsShmUnmap(sqlite3_file *pFile, int delFlag){
160346
- ota_file *p = (ota_file*)pFile;
160590
+static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){
160591
+ rbu_file *p = (rbu_file*)pFile;
160347160592
int rc = SQLITE_OK;
160348
- int eStage = (p->pOta ? p->pOta->eStage : 0);
160593
+ int eStage = (p->pRbu ? p->pRbu->eStage : 0);
160349160594
160350160595
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160351
- if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){
160596
+ if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
160352160597
/* no-op */
160353160598
}else{
160354160599
/* Release the checkpointer and writer locks */
160355
- otaUnlockShm(p);
160600
+ rbuUnlockShm(p);
160356160601
rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
160357160602
}
160358160603
return rc;
160359160604
}
160360160605
@@ -160362,56 +160607,56 @@
160362160607
** Given that zWal points to a buffer containing a wal file name passed to
160363160608
** either the xOpen() or xAccess() VFS method, return a pointer to the
160364160609
** file-handle opened by the same database connection on the corresponding
160365160610
** database file.
160366160611
*/
160367
-static ota_file *otaFindMaindb(ota_vfs *pOtaVfs, const char *zWal){
160368
- ota_file *pDb;
160369
- sqlite3_mutex_enter(pOtaVfs->mutex);
160370
- for(pDb=pOtaVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext);
160371
- sqlite3_mutex_leave(pOtaVfs->mutex);
160612
+static rbu_file *rbuFindMaindb(rbu_vfs *pRbuVfs, const char *zWal){
160613
+ rbu_file *pDb;
160614
+ sqlite3_mutex_enter(pRbuVfs->mutex);
160615
+ for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext);
160616
+ sqlite3_mutex_leave(pRbuVfs->mutex);
160372160617
return pDb;
160373160618
}
160374160619
160375160620
/*
160376
-** Open an ota file handle.
160621
+** Open an rbu file handle.
160377160622
*/
160378
-static int otaVfsOpen(
160623
+static int rbuVfsOpen(
160379160624
sqlite3_vfs *pVfs,
160380160625
const char *zName,
160381160626
sqlite3_file *pFile,
160382160627
int flags,
160383160628
int *pOutFlags
160384160629
){
160385
- static sqlite3_io_methods otavfs_io_methods = {
160630
+ static sqlite3_io_methods rbuvfs_io_methods = {
160386160631
2, /* iVersion */
160387
- otaVfsClose, /* xClose */
160388
- otaVfsRead, /* xRead */
160389
- otaVfsWrite, /* xWrite */
160390
- otaVfsTruncate, /* xTruncate */
160391
- otaVfsSync, /* xSync */
160392
- otaVfsFileSize, /* xFileSize */
160393
- otaVfsLock, /* xLock */
160394
- otaVfsUnlock, /* xUnlock */
160395
- otaVfsCheckReservedLock, /* xCheckReservedLock */
160396
- otaVfsFileControl, /* xFileControl */
160397
- otaVfsSectorSize, /* xSectorSize */
160398
- otaVfsDeviceCharacteristics, /* xDeviceCharacteristics */
160399
- otaVfsShmMap, /* xShmMap */
160400
- otaVfsShmLock, /* xShmLock */
160401
- otaVfsShmBarrier, /* xShmBarrier */
160402
- otaVfsShmUnmap /* xShmUnmap */
160632
+ rbuVfsClose, /* xClose */
160633
+ rbuVfsRead, /* xRead */
160634
+ rbuVfsWrite, /* xWrite */
160635
+ rbuVfsTruncate, /* xTruncate */
160636
+ rbuVfsSync, /* xSync */
160637
+ rbuVfsFileSize, /* xFileSize */
160638
+ rbuVfsLock, /* xLock */
160639
+ rbuVfsUnlock, /* xUnlock */
160640
+ rbuVfsCheckReservedLock, /* xCheckReservedLock */
160641
+ rbuVfsFileControl, /* xFileControl */
160642
+ rbuVfsSectorSize, /* xSectorSize */
160643
+ rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
160644
+ rbuVfsShmMap, /* xShmMap */
160645
+ rbuVfsShmLock, /* xShmLock */
160646
+ rbuVfsShmBarrier, /* xShmBarrier */
160647
+ rbuVfsShmUnmap /* xShmUnmap */
160403160648
};
160404
- ota_vfs *pOtaVfs = (ota_vfs*)pVfs;
160405
- sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs;
160406
- ota_file *pFd = (ota_file *)pFile;
160649
+ rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
160650
+ sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
160651
+ rbu_file *pFd = (rbu_file *)pFile;
160407160652
int rc = SQLITE_OK;
160408160653
const char *zOpen = zName;
160409160654
160410
- memset(pFd, 0, sizeof(ota_file));
160655
+ memset(pFd, 0, sizeof(rbu_file));
160411160656
pFd->pReal = (sqlite3_file*)&pFd[1];
160412
- pFd->pOtaVfs = pOtaVfs;
160657
+ pFd->pRbuVfs = pRbuVfs;
160413160658
pFd->openFlags = flags;
160414160659
if( zName ){
160415160660
if( flags & SQLITE_OPEN_MAIN_DB ){
160416160661
/* A main database has just been opened. The following block sets
160417160662
** (pFd->zWal) to point to a buffer owned by SQLite that contains
@@ -160435,13 +160680,13 @@
160435160680
}
160436160681
z += (n + 8 + 1);
160437160682
pFd->zWal = z;
160438160683
}
160439160684
else if( flags & SQLITE_OPEN_WAL ){
160440
- ota_file *pDb = otaFindMaindb(pOtaVfs, zName);
160685
+ rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
160441160686
if( pDb ){
160442
- if( pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){
160687
+ if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
160443160688
/* This call is to open a *-wal file. Intead, open the *-oal. This
160444160689
** code ensures that the string passed to xOpen() is terminated by a
160445160690
** pair of '\0' bytes in case the VFS attempts to extract a URI
160446160691
** parameter from it. */
160447160692
int nCopy = strlen(zName);
@@ -160453,11 +160698,11 @@
160453160698
zCopy[nCopy+1] = '\0';
160454160699
zOpen = (const char*)(pFd->zDel = zCopy);
160455160700
}else{
160456160701
rc = SQLITE_NOMEM;
160457160702
}
160458
- pFd->pOta = pDb->pOta;
160703
+ pFd->pRbu = pDb->pRbu;
160459160704
}
160460160705
pDb->pWalFd = pFd;
160461160706
}
160462160707
}
160463160708
}
@@ -160467,16 +160712,16 @@
160467160712
}
160468160713
if( pFd->pReal->pMethods ){
160469160714
/* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
160470160715
** pointer and, if the file is a main database file, link it into the
160471160716
** mutex protected linked list of all such files. */
160472
- pFile->pMethods = &otavfs_io_methods;
160717
+ pFile->pMethods = &rbuvfs_io_methods;
160473160718
if( flags & SQLITE_OPEN_MAIN_DB ){
160474
- sqlite3_mutex_enter(pOtaVfs->mutex);
160475
- pFd->pMainNext = pOtaVfs->pMain;
160476
- pOtaVfs->pMain = pFd;
160477
- sqlite3_mutex_leave(pOtaVfs->mutex);
160719
+ sqlite3_mutex_enter(pRbuVfs->mutex);
160720
+ pFd->pMainNext = pRbuVfs->pMain;
160721
+ pRbuVfs->pMain = pFd;
160722
+ sqlite3_mutex_leave(pRbuVfs->mutex);
160478160723
}
160479160724
}else{
160480160725
sqlite3_free(pFd->zDel);
160481160726
}
160482160727
@@ -160484,48 +160729,48 @@
160484160729
}
160485160730
160486160731
/*
160487160732
** Delete the file located at zPath.
160488160733
*/
160489
-static int otaVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
160490
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160734
+static int rbuVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
160735
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160491160736
return pRealVfs->xDelete(pRealVfs, zPath, dirSync);
160492160737
}
160493160738
160494160739
/*
160495160740
** Test for access permissions. Return true if the requested permission
160496160741
** is available, or false otherwise.
160497160742
*/
160498
-static int otaVfsAccess(
160743
+static int rbuVfsAccess(
160499160744
sqlite3_vfs *pVfs,
160500160745
const char *zPath,
160501160746
int flags,
160502160747
int *pResOut
160503160748
){
160504
- ota_vfs *pOtaVfs = (ota_vfs*)pVfs;
160505
- sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs;
160749
+ rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
160750
+ sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
160506160751
int rc;
160507160752
160508160753
rc = pRealVfs->xAccess(pRealVfs, zPath, flags, pResOut);
160509160754
160510
- /* If this call is to check if a *-wal file associated with an OTA target
160511
- ** database connection exists, and the OTA update is in OTA_STAGE_OAL,
160755
+ /* If this call is to check if a *-wal file associated with an RBU target
160756
+ ** database connection exists, and the RBU update is in RBU_STAGE_OAL,
160512160757
** the following special handling is activated:
160513160758
**
160514160759
** a) if the *-wal file does exist, return SQLITE_CANTOPEN. This
160515
- ** ensures that the OTA extension never tries to update a database
160760
+ ** ensures that the RBU extension never tries to update a database
160516160761
** in wal mode, even if the first page of the database file has
160517160762
** been damaged.
160518160763
**
160519160764
** b) if the *-wal file does not exist, claim that it does anyway,
160520160765
** causing SQLite to call xOpen() to open it. This call will also
160521
- ** be intercepted (see the otaVfsOpen() function) and the *-oal
160766
+ ** be intercepted (see the rbuVfsOpen() function) and the *-oal
160522160767
** file opened instead.
160523160768
*/
160524160769
if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){
160525
- ota_file *pDb = otaFindMaindb(pOtaVfs, zPath);
160526
- if( pDb && pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){
160770
+ rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath);
160771
+ if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
160527160772
if( *pResOut ){
160528160773
rc = SQLITE_CANTOPEN;
160529160774
}else{
160530160775
*pResOut = 1;
160531160776
}
@@ -160538,151 +160783,151 @@
160538160783
/*
160539160784
** Populate buffer zOut with the full canonical pathname corresponding
160540160785
** to the pathname in zPath. zOut is guaranteed to point to a buffer
160541160786
** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
160542160787
*/
160543
-static int otaVfsFullPathname(
160788
+static int rbuVfsFullPathname(
160544160789
sqlite3_vfs *pVfs,
160545160790
const char *zPath,
160546160791
int nOut,
160547160792
char *zOut
160548160793
){
160549
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160794
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160550160795
return pRealVfs->xFullPathname(pRealVfs, zPath, nOut, zOut);
160551160796
}
160552160797
160553160798
#ifndef SQLITE_OMIT_LOAD_EXTENSION
160554160799
/*
160555160800
** Open the dynamic library located at zPath and return a handle.
160556160801
*/
160557
-static void *otaVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
160558
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160802
+static void *rbuVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
160803
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160559160804
return pRealVfs->xDlOpen(pRealVfs, zPath);
160560160805
}
160561160806
160562160807
/*
160563160808
** Populate the buffer zErrMsg (size nByte bytes) with a human readable
160564160809
** utf-8 string describing the most recent error encountered associated
160565160810
** with dynamic libraries.
160566160811
*/
160567
-static void otaVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
160568
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160812
+static void rbuVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
160813
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160569160814
pRealVfs->xDlError(pRealVfs, nByte, zErrMsg);
160570160815
}
160571160816
160572160817
/*
160573160818
** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
160574160819
*/
160575
-static void (*otaVfsDlSym(
160820
+static void (*rbuVfsDlSym(
160576160821
sqlite3_vfs *pVfs,
160577160822
void *pArg,
160578160823
const char *zSym
160579160824
))(void){
160580
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160825
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160581160826
return pRealVfs->xDlSym(pRealVfs, pArg, zSym);
160582160827
}
160583160828
160584160829
/*
160585160830
** Close the dynamic library handle pHandle.
160586160831
*/
160587
-static void otaVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
160588
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160589
- return pRealVfs->xDlClose(pRealVfs, pHandle);
160832
+static void rbuVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
160833
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160834
+ pRealVfs->xDlClose(pRealVfs, pHandle);
160590160835
}
160591160836
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
160592160837
160593160838
/*
160594160839
** Populate the buffer pointed to by zBufOut with nByte bytes of
160595160840
** random data.
160596160841
*/
160597
-static int otaVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
160598
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160842
+static int rbuVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
160843
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160599160844
return pRealVfs->xRandomness(pRealVfs, nByte, zBufOut);
160600160845
}
160601160846
160602160847
/*
160603160848
** Sleep for nMicro microseconds. Return the number of microseconds
160604160849
** actually slept.
160605160850
*/
160606
-static int otaVfsSleep(sqlite3_vfs *pVfs, int nMicro){
160607
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160851
+static int rbuVfsSleep(sqlite3_vfs *pVfs, int nMicro){
160852
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160608160853
return pRealVfs->xSleep(pRealVfs, nMicro);
160609160854
}
160610160855
160611160856
/*
160612160857
** Return the current time as a Julian Day number in *pTimeOut.
160613160858
*/
160614
-static int otaVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
160615
- sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160859
+static int rbuVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
160860
+ sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160616160861
return pRealVfs->xCurrentTime(pRealVfs, pTimeOut);
160617160862
}
160618160863
160619160864
/*
160620160865
** No-op.
160621160866
*/
160622
-static int otaVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){
160867
+static int rbuVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){
160623160868
return 0;
160624160869
}
160625160870
160626160871
/*
160627
-** Deregister and destroy an OTA vfs created by an earlier call to
160628
-** sqlite3ota_create_vfs().
160872
+** Deregister and destroy an RBU vfs created by an earlier call to
160873
+** sqlite3rbu_create_vfs().
160629160874
*/
160630
-SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName){
160875
+SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName){
160631160876
sqlite3_vfs *pVfs = sqlite3_vfs_find(zName);
160632
- if( pVfs && pVfs->xOpen==otaVfsOpen ){
160633
- sqlite3_mutex_free(((ota_vfs*)pVfs)->mutex);
160877
+ if( pVfs && pVfs->xOpen==rbuVfsOpen ){
160878
+ sqlite3_mutex_free(((rbu_vfs*)pVfs)->mutex);
160634160879
sqlite3_vfs_unregister(pVfs);
160635160880
sqlite3_free(pVfs);
160636160881
}
160637160882
}
160638160883
160639160884
/*
160640
-** Create an OTA VFS named zName that accesses the underlying file-system
160885
+** Create an RBU VFS named zName that accesses the underlying file-system
160641160886
** via existing VFS zParent. The new object is registered as a non-default
160642160887
** VFS with SQLite before returning.
160643160888
*/
160644
-SQLITE_API int SQLITE_STDCALL sqlite3ota_create_vfs(const char *zName, const char *zParent){
160889
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_create_vfs(const char *zName, const char *zParent){
160645160890
160646160891
/* Template for VFS */
160647160892
static sqlite3_vfs vfs_template = {
160648160893
1, /* iVersion */
160649160894
0, /* szOsFile */
160650160895
0, /* mxPathname */
160651160896
0, /* pNext */
160652160897
0, /* zName */
160653160898
0, /* pAppData */
160654
- otaVfsOpen, /* xOpen */
160655
- otaVfsDelete, /* xDelete */
160656
- otaVfsAccess, /* xAccess */
160657
- otaVfsFullPathname, /* xFullPathname */
160899
+ rbuVfsOpen, /* xOpen */
160900
+ rbuVfsDelete, /* xDelete */
160901
+ rbuVfsAccess, /* xAccess */
160902
+ rbuVfsFullPathname, /* xFullPathname */
160658160903
160659160904
#ifndef SQLITE_OMIT_LOAD_EXTENSION
160660
- otaVfsDlOpen, /* xDlOpen */
160661
- otaVfsDlError, /* xDlError */
160662
- otaVfsDlSym, /* xDlSym */
160663
- otaVfsDlClose, /* xDlClose */
160905
+ rbuVfsDlOpen, /* xDlOpen */
160906
+ rbuVfsDlError, /* xDlError */
160907
+ rbuVfsDlSym, /* xDlSym */
160908
+ rbuVfsDlClose, /* xDlClose */
160664160909
#else
160665160910
0, 0, 0, 0,
160666160911
#endif
160667160912
160668
- otaVfsRandomness, /* xRandomness */
160669
- otaVfsSleep, /* xSleep */
160670
- otaVfsCurrentTime, /* xCurrentTime */
160671
- otaVfsGetLastError, /* xGetLastError */
160913
+ rbuVfsRandomness, /* xRandomness */
160914
+ rbuVfsSleep, /* xSleep */
160915
+ rbuVfsCurrentTime, /* xCurrentTime */
160916
+ rbuVfsGetLastError, /* xGetLastError */
160672160917
0, /* xCurrentTimeInt64 (version 2) */
160673160918
0, 0, 0 /* Unimplemented version 3 methods */
160674160919
};
160675160920
160676
- ota_vfs *pNew = 0; /* Newly allocated VFS */
160921
+ rbu_vfs *pNew = 0; /* Newly allocated VFS */
160677160922
int nName;
160678160923
int rc = SQLITE_OK;
160679160924
160680160925
int nByte;
160681160926
nName = strlen(zName);
160682
- nByte = sizeof(ota_vfs) + nName + 1;
160683
- pNew = (ota_vfs*)sqlite3_malloc(nByte);
160927
+ nByte = sizeof(rbu_vfs) + nName + 1;
160928
+ pNew = (rbu_vfs*)sqlite3_malloc(nByte);
160684160929
if( pNew==0 ){
160685160930
rc = SQLITE_NOMEM;
160686160931
}else{
160687160932
sqlite3_vfs *pParent; /* Parent VFS */
160688160933
memset(pNew, 0, nByte);
@@ -160691,11 +160936,11 @@
160691160936
rc = SQLITE_NOTFOUND;
160692160937
}else{
160693160938
char *zSpace;
160694160939
memcpy(&pNew->base, &vfs_template, sizeof(sqlite3_vfs));
160695160940
pNew->base.mxPathname = pParent->mxPathname;
160696
- pNew->base.szOsFile = sizeof(ota_file) + pParent->szOsFile;
160941
+ pNew->base.szOsFile = sizeof(rbu_file) + pParent->szOsFile;
160697160942
pNew->pRealVfs = pParent;
160698160943
pNew->base.zName = (const char*)(zSpace = (char*)&pNew[1]);
160699160944
memcpy(zSpace, zName, nName);
160700160945
160701160946
/* Allocate the mutex and register the new VFS (not as the default) */
@@ -160717,13 +160962,13 @@
160717160962
}
160718160963
160719160964
160720160965
/**************************************************************************/
160721160966
160722
-#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */
160967
+#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */
160723160968
160724
-/************** End of sqlite3ota.c ******************************************/
160969
+/************** End of sqlite3rbu.c ******************************************/
160725160970
/************** Begin file dbstat.c ******************************************/
160726160971
/*
160727160972
** 2010 July 12
160728160973
**
160729160974
** The author disclaims copyright to this source code. In place of
@@ -160741,10 +160986,11 @@
160741160986
** information from an SQLite database in order to implement the
160742160987
** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
160743160988
** for an example implementation.
160744160989
*/
160745160990
160991
+/* #include "sqliteInt.h" ** Requires access to internal data structures ** */
160746160992
#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
160747160993
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
160748160994
160749160995
/*
160750160996
** Page paths:
160751160997
--- 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.11. 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.
@@ -323,13 +323,13 @@
323 **
324 ** See also: [sqlite3_libversion()],
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.11"
329 #define SQLITE_VERSION_NUMBER 3008011
330 #define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -1179,13 +1179,13 @@
1179 **
1180 ** <li>[[SQLITE_FCNTL_ZIPVFS]]
1181 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
1182 ** VFS should return SQLITE_NOTFOUND for this opcode.
1183 **
1184 ** <li>[[SQLITE_FCNTL_OTA]]
1185 ** The [SQLITE_FCNTL_OTA] opcode is implemented by the special VFS used by
1186 ** the OTA extension only. All other VFS should return SQLITE_NOTFOUND for
1187 ** this opcode.
1188 ** </ul>
1189 */
1190 #define SQLITE_FCNTL_LOCKSTATE 1
1191 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -1209,11 +1209,11 @@
1209 #define SQLITE_FCNTL_SYNC 21
1210 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1211 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1212 #define SQLITE_FCNTL_WAL_BLOCK 24
1213 #define SQLITE_FCNTL_ZIPVFS 25
1214 #define SQLITE_FCNTL_OTA 26
1215
1216 /* deprecated names */
1217 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1218 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1219 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3774,10 +3774,11 @@
3774 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3775 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3776 void(*)(void*), unsigned char encoding);
3777 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3778 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
 
3779
3780 /*
3781 ** CAPI3REF: Number Of SQL Parameters
3782 ** METHOD: sqlite3_stmt
3783 **
@@ -4746,13 +4747,13 @@
4746 ** ^The sqlite3_result_blob() interface sets the result from
4747 ** an application-defined function to be the BLOB whose content is pointed
4748 ** to by the second parameter and which is N bytes long where N is the
4749 ** third parameter.
4750 **
4751 ** ^The sqlite3_result_zeroblob() interfaces set the result of
4752 ** the application-defined function to be a BLOB containing all zero
4753 ** bytes and N bytes in size, where N is the value of the 2nd parameter.
4754 **
4755 ** ^The sqlite3_result_double() interface sets the result from
4756 ** an application-defined function to be a floating point value specified
4757 ** by its 2nd argument.
4758 **
@@ -4863,10 +4864,11 @@
4863 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4864 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4865 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4866 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4867 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
 
4868
4869 /*
4870 ** CAPI3REF: Define New Collating Sequences
4871 ** METHOD: sqlite3
4872 **
@@ -8362,13 +8364,17 @@
8362 /*
8363 ** Make sure that the compiler intrinsics we desire are enabled when
8364 ** compiling with an appropriate version of MSVC.
8365 */
8366 #if defined(_MSC_VER) && _MSC_VER>=1300
8367 # include <intrin.h>
8368 # pragma intrinsic(_byteswap_ushort)
8369 # pragma intrinsic(_byteswap_ulong)
 
 
 
 
8370 #endif
8371
8372 /*
8373 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
8374 ** 0 means mutexes are permanently disable and the library is never
@@ -9189,11 +9195,13 @@
9189 #endif
9190 #ifndef SQLITE_MAX_MMAP_SIZE
9191 # if defined(__linux__) \
9192 || defined(_WIN32) \
9193 || (defined(__APPLE__) && defined(__MACH__)) \
9194 || defined(__sun)
 
 
9195 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
9196 # else
9197 # define SQLITE_MAX_MMAP_SIZE 0
9198 # endif
9199 # define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */
@@ -13883,10 +13891,11 @@
13883 **
13884 *************************************************************************
13885 **
13886 ** This file contains definitions of global variables and constants.
13887 */
 
13888
13889 /* An array to map all upper-case characters into their corresponding
13890 ** lower-case character.
13891 **
13892 ** SQLite only considers US-ASCII (or EBCDIC) characters. We do not
@@ -14122,10 +14131,11 @@
14122 */
14123 #ifndef SQLITE_OMIT_WSD
14124 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
14125 #endif
14126
 
14127 /*
14128 ** Properties of opcodes. The OPFLG_INITIALIZER macro is
14129 ** created by mkopcodeh.awk during compilation. Data is obtained
14130 ** from the comments following the "case OP_xxxx:" statements in
14131 ** the vdbe.c file.
@@ -14150,10 +14160,11 @@
14150 ** SQLite was built with.
14151 */
14152
14153 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
14154
 
14155
14156 /*
14157 ** An array of names of all compile-time options. This array should
14158 ** be sorted A-Z.
14159 **
@@ -14579,10 +14590,11 @@
14579 *************************************************************************
14580 **
14581 ** This module implements the sqlite3_status() interface and related
14582 ** functionality.
14583 */
 
14584 /************** Include vdbeInt.h in the middle of status.c ******************/
14585 /************** Begin file vdbeInt.h *****************************************/
14586 /*
14587 ** 2003 September 6
14588 **
@@ -15462,10 +15474,11 @@
15462 ** Astronomical Algorithms, 2nd Edition, 1998
15463 ** ISBM 0-943396-61-1
15464 ** Willmann-Bell, Inc
15465 ** Richmond, Virginia (USA)
15466 */
 
15467 /* #include <stdlib.h> */
15468 /* #include <assert.h> */
15469 #include <time.h>
15470
15471 #ifndef SQLITE_OMIT_DATETIME_FUNCS
@@ -15773,11 +15786,11 @@
15773 Z = (int)((p->iJD + 43200000)/86400000);
15774 A = (int)((Z - 1867216.25)/36524.25);
15775 A = Z + 1 + A - (A/4);
15776 B = A + 1524;
15777 C = (int)((B - 122.1)/365.25);
15778 D = (36525*C)/100;
15779 E = (int)((B-D)/30.6001);
15780 X1 = (int)(30.6001*E);
15781 p->D = B - D - X1;
15782 p->M = E<14 ? E-1 : E-13;
15783 p->Y = p->M>2 ? C - 4716 : C - 4715;
@@ -16574,10 +16587,11 @@
16574 **
16575 ** This file contains OS interface code that is common to all
16576 ** architectures.
16577 */
16578 #define _SQLITE_OS_C_ 1
 
16579 #undef _SQLITE_OS_C_
16580
16581 /*
16582 ** The default SQLite sqlite3_vfs implementations do not allocate
16583 ** memory (actually, os_unix.c allocates a small amount of memory
@@ -16980,10 +16994,11 @@
16980 ** is completely recoverable simply by not carrying out the resize. The
16981 ** hash table will continue to function normally. So a malloc failure
16982 ** during a hash table resize is a benign fault.
16983 */
16984
 
16985
16986 #ifndef SQLITE_OMIT_BUILTIN_TEST
16987
16988 /*
16989 ** Global variables.
@@ -17061,10 +17076,11 @@
17061 ** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented
17062 ** here always fail. SQLite will not operate with these drivers. These
17063 ** are merely placeholders. Real drivers must be substituted using
17064 ** sqlite3_config() before SQLite will operate.
17065 */
 
17066
17067 /*
17068 ** This version of the memory allocator is the default. It is
17069 ** used when no other memory allocator is specified using compile-time
17070 ** macros.
@@ -17147,10 +17163,11 @@
17147 ** SQLITE_WITHOUT_MSIZE Set this symbol to disable the use of
17148 ** _msize() on windows systems. This might
17149 ** be necessary when compiling for Delphi,
17150 ** for example.
17151 */
 
17152
17153 /*
17154 ** This version of the memory allocator is the default. It is
17155 ** used when no other memory allocator is specified using compile-time
17156 ** macros.
@@ -17422,10 +17439,11 @@
17422 ** leaks and memory usage errors.
17423 **
17424 ** This file contains implementations of the low-level memory allocation
17425 ** routines specified in the sqlite3_mem_methods object.
17426 */
 
17427
17428 /*
17429 ** This version of the memory allocator is used only if the
17430 ** SQLITE_MEMDEBUG macro is defined
17431 */
@@ -17956,10 +17974,11 @@
17956 ** be changed.
17957 **
17958 ** This version of the memory allocation subsystem is included
17959 ** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
17960 */
 
17961
17962 /*
17963 ** This version of the memory allocator is only built into the library
17964 ** SQLITE_ENABLE_MEMSYS3 is defined. Defining this symbol does not
17965 ** mean that the library will use a memory-pool by default, just that
@@ -18670,10 +18689,11 @@
18670 ** N >= M*(1 + log2(n)/2) - n + 1
18671 **
18672 ** The sqlite3_status() logic tracks the maximum values of n and M so
18673 ** that an application can, at any time, verify this constraint.
18674 */
 
18675
18676 /*
18677 ** This version of the memory allocator is used only when
18678 ** SQLITE_ENABLE_MEMSYS5 is defined.
18679 */
@@ -19213,10 +19233,11 @@
19213 *************************************************************************
19214 ** This file contains the C functions that implement mutexes.
19215 **
19216 ** This file contains code that is common across all mutex implementations.
19217 */
 
19218
19219 #if defined(SQLITE_DEBUG) && !defined(SQLITE_MUTEX_OMIT)
19220 /*
19221 ** For debugging purposes, record when the mutex subsystem is initialized
19222 ** and uninitialized so that we can assert() if there is an attempt to
@@ -19386,10 +19407,11 @@
19386 **
19387 ** If compiled with SQLITE_DEBUG, then additional logic is inserted
19388 ** that does error checking on mutexes to make sure they are being
19389 ** called correctly.
19390 */
 
19391
19392 #ifndef SQLITE_MUTEX_OMIT
19393
19394 #ifndef SQLITE_DEBUG
19395 /*
@@ -19589,10 +19611,11 @@
19589 ** May you share freely, never taking more than you give.
19590 **
19591 *************************************************************************
19592 ** This file contains the C functions that implement mutexes for pthreads
19593 */
 
19594
19595 /*
19596 ** The code in this file is only used if we are compiling threadsafe
19597 ** under unix with pthreads.
19598 **
@@ -19963,10 +19986,11 @@
19963 ** May you share freely, never taking more than you give.
19964 **
19965 *************************************************************************
19966 ** This file contains the C functions that implement mutexes for Win32.
19967 */
 
19968
19969 #if SQLITE_OS_WIN
19970 /*
19971 ** Include code that is common to all os_*.c files
19972 */
@@ -20638,10 +20662,11 @@
20638 **
20639 *************************************************************************
20640 **
20641 ** Memory allocation functions used throughout sqlite.
20642 */
 
20643 /* #include <stdarg.h> */
20644
20645 /*
20646 ** Attempt to release up to n bytes of non-essential memory currently
20647 ** held by SQLite. An example of non-essential memory is memory used to
@@ -21449,10 +21474,11 @@
21449 ** This file contains code for a set of "printf"-like routines. These
21450 ** routines format strings much like the printf() from the standard C
21451 ** library, though the implementation here has enhancements to support
21452 ** SQLite.
21453 */
 
21454
21455 /*
21456 ** Conversion types fall into various categories as defined by the
21457 ** following enumeration.
21458 */
@@ -22451,10 +22477,15 @@
22451 ** stack space on small-stack systems when logging is disabled.
22452 **
22453 ** sqlite3_log() must render into a static buffer. It cannot dynamically
22454 ** allocate memory because it might be called while the memory allocator
22455 ** mutex is held.
 
 
 
 
 
22456 */
22457 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22458 StrAccum acc; /* String accumulator */
22459 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22460
@@ -22526,10 +22557,11 @@
22526 ** analysis.
22527 **
22528 ** The interfaces in this file is only available when compiling
22529 ** with SQLITE_DEBUG.
22530 */
 
22531 #ifdef SQLITE_DEBUG
22532
22533 /*
22534 ** Add a new subitem to the tree. The moreToFollow flag indicates that this
22535 ** is not the last item in the tree.
@@ -22957,10 +22989,11 @@
22957 ** generator (PRNG) for SQLite.
22958 **
22959 ** Random numbers are used by some of the database backends in order
22960 ** to generate random integer keys for tables or random filenames.
22961 */
 
22962
22963
22964 /* All threads share a single random number generator.
22965 ** This structure is the current state of the generator.
22966 */
@@ -23103,11 +23136,13 @@
23103 ** single threaded systems. Nothing in SQLite requires multiple threads.
23104 ** This interface exists so that applications that want to take advantage
23105 ** of multiple cores can do so, while also allowing applications to stay
23106 ** single-threaded if desired.
23107 */
 
23108 #if SQLITE_OS_WIN
 
23109 #endif
23110
23111 #if SQLITE_MAX_WORKER_THREADS>0
23112
23113 /********************************* Unix Pthreads ****************************/
@@ -23377,11 +23412,13 @@
23377 ** BOM or Byte Order Mark:
23378 ** 0xff 0xfe little-endian utf-16 follows
23379 ** 0xfe 0xff big-endian utf-16 follows
23380 **
23381 */
 
23382 /* #include <assert.h> */
 
23383
23384 #ifndef SQLITE_AMALGAMATION
23385 /*
23386 ** The following constant value is used by the SQLITE_BIGENDIAN and
23387 ** SQLITE_LITTLEENDIAN macros.
@@ -23890,10 +23927,11 @@
23890 **
23891 ** This file contains functions for allocating memory, comparing
23892 ** strings, and stuff like that.
23893 **
23894 */
 
23895 /* #include <stdarg.h> */
23896 #if HAVE_ISNAN || SQLITE_HAVE_ISNAN
23897 # include <math.h>
23898 #endif
23899
@@ -25286,10 +25324,11 @@
25286 **
25287 *************************************************************************
25288 ** This is the implementation of generic hash-tables
25289 ** used in SQLite.
25290 */
 
25291 /* #include <assert.h> */
25292
25293 /* Turn bulk memory into a hash table object by initializing the
25294 ** fields of the Hash structure.
25295 **
@@ -25763,10 +25802,11 @@
25763 ** * sqlite3_vfs method implementations.
25764 ** * Locking primitives for the proxy uber-locking-method. (MacOSX only)
25765 ** * Definitions of sqlite3_vfs objects for all locking methods
25766 ** plus implementations of sqlite3_os_init() and sqlite3_os_end().
25767 */
 
25768 #if SQLITE_OS_UNIX /* This file is used on unix only */
25769
25770 /*
25771 ** There are various methods for file locking used for concurrency
25772 ** control:
@@ -33497,10 +33537,11 @@
33497 **
33498 ******************************************************************************
33499 **
33500 ** This file contains code that is specific to Windows.
33501 */
 
33502 #if SQLITE_OS_WIN /* This file is used for Windows only */
33503
33504 /*
33505 ** Include code that is common to all os_*.c files
33506 */
@@ -33705,10 +33746,11 @@
33705 /************** Continuing where we left off in os_win.c *********************/
33706
33707 /*
33708 ** Include the header file for the Windows VFS.
33709 */
 
33710
33711 /*
33712 ** Compiling and using WAL mode requires several APIs that are only
33713 ** available in Windows platforms based on the NT kernel.
33714 */
@@ -39358,10 +39400,11 @@
39358 ** sometimes grow into tens of thousands or larger. The size of the
39359 ** Bitvec object is the number of pages in the database file at the
39360 ** start of a transaction, and is thus usually less than a few thousand,
39361 ** but can be as large as 2 billion for a really big database.
39362 */
 
39363
39364 /* Size of the Bitvec structure in bytes. */
39365 #define BITVEC_SZ 512
39366
39367 /* Round the union size down to the nearest pointer boundary, since that's how
@@ -39747,10 +39790,11 @@
39747 ** May you share freely, never taking more than you give.
39748 **
39749 *************************************************************************
39750 ** This file implements that page cache.
39751 */
 
39752
39753 /*
39754 ** A complete page cache is an instance of this structure.
39755 */
39756 struct PCache {
@@ -40488,10 +40532,11 @@
40488 **
40489 ** Earlier versions of SQLite used only methods (1) and (2). But experiments
40490 ** show that method (3) with N==100 provides about a 5% performance boost for
40491 ** common workloads.
40492 */
 
40493
40494 typedef struct PCache1 PCache1;
40495 typedef struct PgHdr1 PgHdr1;
40496 typedef struct PgFreeslot PgFreeslot;
40497 typedef struct PGroup PGroup;
@@ -40598,10 +40643,11 @@
40598 ** fixed at sqlite3_initialize() time and do not require mutex protection.
40599 ** The nFreeSlot and pFree values do require mutex protection.
40600 */
40601 int isInit; /* True if initialized */
40602 int separateCache; /* Use a new PGroup for each PCache */
 
40603 int szSlot; /* Size of each free slot */
40604 int nSlot; /* The number of pcache slots */
40605 int nReserve; /* Try to keep nFreeSlot above this */
40606 void *pStart, *pEnd; /* Bounds of global page cache memory */
40607 /* Above requires no mutex. Use mutex below for variable that follow. */
@@ -40665,10 +40711,47 @@
40665 pBuf = (void*)&((char*)pBuf)[sz];
40666 }
40667 pcache1.pEnd = pBuf;
40668 }
40669 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40670
40671 /*
40672 ** Malloc function used within this file to allocate space from the buffer
40673 ** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
40674 ** such buffer exists or there is no space left in it, this function falls
@@ -40766,11 +40849,11 @@
40766 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
40767 PgHdr1 *p = 0;
40768 void *pPg;
40769
40770 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40771 if( pCache->pFree ){
40772 p = pCache->pFree;
40773 pCache->pFree = p->pNext;
40774 p->pNext = 0;
40775 }else{
40776 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
@@ -40970,18 +41053,23 @@
40970
40971 /*
40972 ** If there are currently more than nMaxPage pages allocated, try
40973 ** to recycle pages to reduce the number allocated to nMaxPage.
40974 */
40975 static void pcache1EnforceMaxPage(PGroup *pGroup){
 
40976 assert( sqlite3_mutex_held(pGroup->mutex) );
40977 while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
40978 PgHdr1 *p = pGroup->pLruTail;
40979 assert( p->pCache->pGroup==pGroup );
40980 assert( p->isPinned==0 );
40981 pcache1PinPage(p);
40982 pcache1RemoveFromHash(p, 1);
 
 
 
 
40983 }
40984 }
40985
40986 /*
40987 ** Discard all pages from cache pCache with a page number (key value)
@@ -41054,10 +41142,18 @@
41054 if( sqlite3GlobalConfig.bCoreMutex ){
41055 pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
41056 pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
41057 }
41058 #endif
 
 
 
 
 
 
 
 
41059 pcache1.grp.mxPinned = 10;
41060 pcache1.isInit = 1;
41061 return SQLITE_OK;
41062 }
41063
@@ -41108,40 +41204,10 @@
41108 pCache->nMin = 10;
41109 pGroup->nMinPage += pCache->nMin;
41110 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41111 }
41112 pcache1LeaveMutex(pGroup);
41113 /* Try to initialize the local bulk pagecache line allocation if using
41114 ** separate caches and if nPage!=0 */
41115 if( pcache1.separateCache
41116 && sqlite3GlobalConfig.nPage!=0
41117 && sqlite3GlobalConfig.pPage==0
41118 ){
41119 int szBulk;
41120 char *zBulk;
41121 sqlite3BeginBenignMalloc();
41122 if( sqlite3GlobalConfig.nPage>0 ){
41123 szBulk = pCache->szAlloc * sqlite3GlobalConfig.nPage;
41124 }else{
41125 szBulk = -1024*sqlite3GlobalConfig.nPage;
41126 }
41127 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
41128 sqlite3EndBenignMalloc();
41129 if( zBulk ){
41130 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
41131 int i;
41132 for(i=0; i<nBulk; i++){
41133 PgHdr1 *pX = (PgHdr1*)&zBulk[szPage];
41134 pX->page.pBuf = zBulk;
41135 pX->page.pExtra = &pX[1];
41136 pX->isBulkLocal = 1;
41137 pX->pNext = pCache->pFree;
41138 pCache->pFree = pX;
41139 zBulk += pCache->szAlloc;
41140 }
41141 }
41142 }
41143 if( pCache->nHash==0 ){
41144 pcache1Destroy((sqlite3_pcache*)pCache);
41145 pCache = 0;
41146 }
41147 }
@@ -41160,11 +41226,11 @@
41160 pcache1EnterMutex(pGroup);
41161 pGroup->nMaxPage += (nMax - pCache->nMax);
41162 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41163 pCache->nMax = nMax;
41164 pCache->n90pct = pCache->nMax*9/10;
41165 pcache1EnforceMaxPage(pGroup);
41166 pcache1LeaveMutex(pGroup);
41167 }
41168 }
41169
41170 /*
@@ -41178,11 +41244,11 @@
41178 PGroup *pGroup = pCache->pGroup;
41179 int savedMaxPage;
41180 pcache1EnterMutex(pGroup);
41181 savedMaxPage = pGroup->nMaxPage;
41182 pGroup->nMaxPage = 0;
41183 pcache1EnforceMaxPage(pGroup);
41184 pGroup->nMaxPage = savedMaxPage;
41185 pcache1LeaveMutex(pGroup);
41186 }
41187 }
41188
@@ -41515,11 +41581,11 @@
41515 assert( pGroup->nMaxPage >= pCache->nMax );
41516 pGroup->nMaxPage -= pCache->nMax;
41517 assert( pGroup->nMinPage >= pCache->nMin );
41518 pGroup->nMinPage -= pCache->nMin;
41519 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41520 pcache1EnforceMaxPage(pGroup);
41521 pcache1LeaveMutex(pGroup);
41522 sqlite3_free(pCache->pBulk);
41523 sqlite3_free(pCache->apHash);
41524 sqlite3_free(pCache);
41525 }
@@ -41679,10 +41745,11 @@
41679 ** primitives are constant time. The cost of DESTROY is O(N).
41680 **
41681 ** There is an added cost of O(N) when switching between TEST and
41682 ** SMALLEST primitives.
41683 */
 
41684
41685
41686 /*
41687 ** Target size for allocation chunks.
41688 */
@@ -42148,10 +42215,11 @@
42148 ** locking to prevent two processes from writing the same database
42149 ** file simultaneously, or one process from reading the database while
42150 ** another is writing.
42151 */
42152 #ifndef SQLITE_OMIT_DISKIO
 
42153 /************** Include wal.h in the middle of pager.c ***********************/
42154 /************** Begin file wal.h *********************************************/
42155 /*
42156 ** 2010 February 1
42157 **
@@ -42169,10 +42237,11 @@
42169 */
42170
42171 #ifndef _WAL_H_
42172 #define _WAL_H_
42173
 
42174
42175 /* Additional values that can be added to the sync_flags argument of
42176 ** sqlite3WalFrames():
42177 */
42178 #define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */
@@ -49783,10 +49852,11 @@
49783 ** that correspond to frames greater than the new K value are removed
49784 ** from the hash table at this point.
49785 */
49786 #ifndef SQLITE_OMIT_WAL
49787
 
49788
49789 /*
49790 ** Trace output macros
49791 */
49792 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
@@ -50188,13 +50258,13 @@
50188
50189 assert( pWal->writeLock );
50190 pWal->hdr.isInit = 1;
50191 pWal->hdr.iVersion = WALINDEX_MAX_VERSION;
50192 walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
50193 memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr));
50194 walShmBarrier(pWal);
50195 memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr));
50196 }
50197
50198 /*
50199 ** This function encodes a single frame header and writes it to a buffer
50200 ** supplied by the caller. A frame-header is made up of a series of
@@ -50492,17 +50562,17 @@
50492 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
50493 /* Verify that the every entry in the mapping region is still reachable
50494 ** via the hash table even after the cleanup.
50495 */
50496 if( iLimit ){
50497 int i; /* Loop counter */
50498 int iKey; /* Hash key */
50499 for(i=1; i<=iLimit; i++){
50500 for(iKey=walHash(aPgno[i]); aHash[iKey]; iKey=walNextHash(iKey)){
50501 if( aHash[iKey]==i ) break;
50502 }
50503 assert( aHash[iKey]==i );
50504 }
50505 }
50506 #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
50507 }
50508
@@ -51000,11 +51070,11 @@
51000
51001 const int nList = *pnList; /* Size of input list */
51002 int nMerge = 0; /* Number of elements in list aMerge */
51003 ht_slot *aMerge = 0; /* List to be merged */
51004 int iList; /* Index into input list */
51005 int iSub = 0; /* Index into aSub array */
51006 struct Sublist aSub[13]; /* Array of sub-lists */
51007
51008 memset(aSub, 0, sizeof(aSub));
51009 assert( nList<=HASHTABLE_NPAGE && nList>0 );
51010 assert( HASHTABLE_NPAGE==(1<<(ArraySize(aSub)-1)) );
@@ -51011,11 +51081,13 @@
51011
51012 for(iList=0; iList<nList; iList++){
51013 nMerge = 1;
51014 aMerge = &aList[iList];
51015 for(iSub=0; iList & (1<<iSub); iSub++){
51016 struct Sublist *p = &aSub[iSub];
 
 
51017 assert( p->aList && p->nList<=(1<<iSub) );
51018 assert( p->aList==&aList[iList&~((2<<iSub)-1)] );
51019 walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
51020 }
51021 aSub[iSub].aList = aMerge;
@@ -51022,11 +51094,13 @@
51022 aSub[iSub].nList = nMerge;
51023 }
51024
51025 for(iSub++; iSub<ArraySize(aSub); iSub++){
51026 if( nList & (1<<iSub) ){
51027 struct Sublist *p = &aSub[iSub];
 
 
51028 assert( p->nList<=(1<<iSub) );
51029 assert( p->aList==&aList[nList&~((2<<iSub)-1)] );
51030 walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
51031 }
51032 }
@@ -52933,10 +53007,11 @@
52933 ** SIZE DESCRIPTION
52934 ** 4 Page number of next trunk page
52935 ** 4 Number of leaf pointers on this page
52936 ** * zero or more pages numbers of leaves
52937 */
 
52938
52939
52940 /* The following value is the maximum cell size assuming a maximum page
52941 ** size give above.
52942 */
@@ -53730,10 +53805,11 @@
53730 *************************************************************************
53731 ** This file implements an external (disk-based) database using BTrees.
53732 ** See the header comment on "btreeInt.h" for additional information.
53733 ** Including a description of file format and an overview of operation.
53734 */
 
53735
53736 /*
53737 ** The header string that appears at the beginning of every
53738 ** SQLite database.
53739 */
@@ -62675,11 +62751,11 @@
62675 u32 *heap = 0; /* Min-heap used for checking cell coverage */
62676 u32 x, prev = 0; /* Next and previous entry on the min-heap */
62677 const char *saved_zPfx = pCheck->zPfx;
62678 int saved_v1 = pCheck->v1;
62679 int saved_v2 = pCheck->v2;
62680 u8 savedIsInit;
62681
62682 /* Check that the page exists
62683 */
62684 pBt = pCheck->pBt;
62685 usableSize = pBt->usableSize;
@@ -63311,10 +63387,12 @@
63311 **
63312 *************************************************************************
63313 ** This file contains the implementation of the sqlite3_backup_XXX()
63314 ** API functions and the related features.
63315 */
 
 
63316
63317 /*
63318 ** Structure allocated for each backup operation.
63319 */
63320 struct sqlite3_backup {
@@ -64109,10 +64187,12 @@
64109 ** This file contains code use to manipulate "Mem" structure. A "Mem"
64110 ** stores a single value in the VDBE. Mem is an opaque structure visible
64111 ** only within the VDBE. Interface routines refer to a Mem using the
64112 ** name sqlite_value
64113 */
 
 
64114
64115 #ifdef SQLITE_DEBUG
64116 /*
64117 ** Check invariants on a Mem object.
64118 **
@@ -65826,10 +65906,12 @@
65826 **
65827 *************************************************************************
65828 ** This file contains code used for creating, destroying, and populating
65829 ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)
65830 */
 
 
65831
65832 /*
65833 ** Create a new virtual database engine.
65834 */
65835 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){
@@ -70074,10 +70156,12 @@
70074 *************************************************************************
70075 **
70076 ** This file contains code use to implement APIs that are part of the
70077 ** VDBE.
70078 */
 
 
70079
70080 #ifndef SQLITE_OMIT_DEPRECATED
70081 /*
70082 ** Return TRUE (non-zero) of the statement supplied as an argument needs
70083 ** to be recompiled. A statement needs to be recompiled whenever the
@@ -70112,10 +70196,35 @@
70112 }else{
70113 return vdbeSafety(p);
70114 }
70115 }
70116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70117 /*
70118 ** The following routine destroys a virtual machine that is created by
70119 ** the sqlite3_compile() routine. The integer returned is an SQLITE_
70120 ** success/failure code that describes the result of executing the virtual
70121 ** machine.
@@ -70132,10 +70241,11 @@
70132 }else{
70133 Vdbe *v = (Vdbe*)pStmt;
70134 sqlite3 *db = v->db;
70135 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
70136 sqlite3_mutex_enter(db->mutex);
 
70137 rc = sqlite3VdbeFinalize(v);
70138 rc = sqlite3ApiExit(db, rc);
70139 sqlite3LeaveMutexAndCloseZombie(db);
70140 }
70141 return rc;
@@ -70153,16 +70263,18 @@
70153 int rc;
70154 if( pStmt==0 ){
70155 rc = SQLITE_OK;
70156 }else{
70157 Vdbe *v = (Vdbe*)pStmt;
70158 sqlite3_mutex_enter(v->db->mutex);
 
 
70159 rc = sqlite3VdbeReset(v);
70160 sqlite3VdbeRewind(v);
70161 assert( (rc & (v->db->errMask))==rc );
70162 rc = sqlite3ApiExit(v->db, rc);
70163 sqlite3_mutex_leave(v->db->mutex);
70164 }
70165 return rc;
70166 }
70167
70168 /*
@@ -70193,11 +70305,14 @@
70193 ** structure.
70194 */
70195 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value *pVal){
70196 Mem *p = (Mem*)pVal;
70197 if( p->flags & (MEM_Blob|MEM_Str) ){
70198 sqlite3VdbeMemExpandBlob(p);
 
 
 
70199 p->flags |= MEM_Blob;
70200 return p->n ? p->z : 0;
70201 }else{
70202 return sqlite3_value_text(pVal);
70203 }
@@ -70454,10 +70569,19 @@
70454 sqlite3VdbeMemCopy(pCtx->pOut, pValue);
70455 }
70456 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
70457 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
70458 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
 
 
 
 
 
 
 
 
 
70459 }
70460 SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
70461 pCtx->isError = errCode;
70462 pCtx->fErrorOrAux = 1;
70463 #ifdef SQLITE_DEBUG
@@ -70508,10 +70632,11 @@
70508 }
70509 }
70510 #endif
70511 return rc;
70512 }
 
70513
70514 /*
70515 ** Execute the statement pStmt, either until a row of data is ready, the
70516 ** statement is completely executed or an error occurs.
70517 **
@@ -70577,12 +70702,14 @@
70577 assert( db->nVdbeWrite>0 || db->autoCommit==0
70578 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
70579 );
70580
70581 #ifndef SQLITE_OMIT_TRACE
70582 if( db->xProfile && !db->init.busy ){
70583 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
 
 
70584 }
70585 #endif
70586
70587 db->nVdbeActive++;
70588 if( p->readOnly==0 ) db->nVdbeWrite++;
@@ -70602,17 +70729,12 @@
70602 rc = sqlite3VdbeExec(p);
70603 db->nVdbeExec--;
70604 }
70605
70606 #ifndef SQLITE_OMIT_TRACE
70607 /* Invoke the profile callback if there is one
70608 */
70609 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
70610 sqlite3_int64 iNow;
70611 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
70612 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
70613 }
70614 #endif
70615
70616 if( rc==SQLITE_DONE ){
70617 assert( p->rc==SQLITE_OK );
70618 p->rc = doWalCallbacks(db);
@@ -71436,10 +71558,24 @@
71436 sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
71437 sqlite3_mutex_leave(p->db->mutex);
71438 }
71439 return rc;
71440 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71441
71442 /*
71443 ** Return the number of wildcards that can be potentially bound to.
71444 ** This routine is added to support DBD::SQLite.
71445 */
@@ -71685,10 +71821,12 @@
71685 ** This file contains code used to insert the values of host parameters
71686 ** (aka "wildcards") into the SQL text output by sqlite3_trace().
71687 **
71688 ** The Vdbe parse-tree explainer is also found here.
71689 */
 
 
71690
71691 #ifndef SQLITE_OMIT_TRACE
71692
71693 /*
71694 ** zSql is a zero-terminated string of UTF-8 SQL text. Return the number of
@@ -71877,10 +72015,12 @@
71877 ** documentation, headers files, or other derived files. The formatting
71878 ** of the code in this file is, therefore, important. See other comments
71879 ** in this file for details. If in doubt, do not deviate from existing
71880 ** commenting and indentation practices when changing or adding code.
71881 */
 
 
71882
71883 /*
71884 ** Invoke this macro on memory cells just prior to changing the
71885 ** value of the cell. This macro verifies that shallow copies are
71886 ** not misused. A shallow copy of a string or blob just copies a
@@ -74648,11 +74788,11 @@
74648 assert( memIsValid(pRec) );
74649 pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format);
74650 len = sqlite3VdbeSerialTypeLen(serial_type);
74651 if( pRec->flags & MEM_Zero ){
74652 if( nData ){
74653 sqlite3VdbeMemExpandBlob(pRec);
74654 }else{
74655 nZero += pRec->u.nZero;
74656 len -= pRec->u.nZero;
74657 }
74658 }
@@ -78635,10 +78775,12 @@
78635 *************************************************************************
78636 **
78637 ** This file contains code used to implement incremental BLOB I/O.
78638 */
78639
 
 
78640
78641 #ifndef SQLITE_OMIT_INCRBLOB
78642
78643 /*
78644 ** Valid sqlite3_blob* handles point to Incrblob structures.
@@ -79233,10 +79375,12 @@
79233 ** than one background thread may be created. Specifically, there may be
79234 ** one background thread for each temporary file on disk, and one background
79235 ** thread to merge the output of each of the others to a single PMA for
79236 ** the main thread to read from.
79237 */
 
 
79238
79239 /*
79240 ** If SQLITE_DEBUG_SORTER_THREADS is defined, this module outputs various
79241 ** messages to stderr that may be helpful in understanding the performance
79242 ** characteristics of the sorter in multi-threaded mode.
@@ -81849,10 +81993,11 @@
81849 ** 1) The in-memory representation grows too large for the allocated
81850 ** buffer, or
81851 ** 2) The sqlite3JournalCreate() function is called.
81852 */
81853 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
 
81854
81855
81856 /*
81857 ** A JournalFile object is a subclass of sqlite3_file used by
81858 ** as an open file handle for journal files.
@@ -82096,10 +82241,11 @@
82096 **
82097 ** This file contains code use to implement an in-memory rollback journal.
82098 ** The in-memory rollback journal is used to journal transactions for
82099 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
82100 */
 
82101
82102 /* Forward references to internal structures */
82103 typedef struct MemJournal MemJournal;
82104 typedef struct FilePoint FilePoint;
82105 typedef struct FileChunk FileChunk;
@@ -82351,10 +82497,11 @@
82351 **
82352 *************************************************************************
82353 ** This file contains routines used for walking the parser tree for
82354 ** an SQL statement.
82355 */
 
82356 /* #include <stdlib.h> */
82357 /* #include <string.h> */
82358
82359
82360 /*
@@ -82509,10 +82656,11 @@
82509 **
82510 ** This file contains routines used for walking the parser tree and
82511 ** resolve all identifiers by associating them with a particular
82512 ** table and column.
82513 */
 
82514 /* #include <stdlib.h> */
82515 /* #include <string.h> */
82516
82517 /*
82518 ** Walk the expression tree pExpr and increase the aggregate function
@@ -84021,10 +84169,11 @@
84021 **
84022 *************************************************************************
84023 ** This file contains routines used for analyzing expressions and
84024 ** for generating VDBE code that evaluates expressions in SQLite.
84025 */
 
84026
84027 /*
84028 ** Return the 'affinity' of the expression pExpr if any.
84029 **
84030 ** If pExpr is a column, a reference to a column via an 'AS' alias,
@@ -88183,10 +88332,11 @@
88183 **
88184 *************************************************************************
88185 ** This file contains C code routines that used to generate VDBE code
88186 ** that implements the ALTER TABLE command.
88187 */
 
88188
88189 /*
88190 ** The code in this file only exists if we are not omitting the
88191 ** ALTER TABLE logic from the build.
88192 */
@@ -89145,10 +89295,11 @@
89145 ** sqlite_stat4.sample. The nEq, nLt, and nDLt entries of sqlite_stat3
89146 ** all contain just a single integer which is the same as the first
89147 ** integer in the equivalent columns in sqlite_stat4.
89148 */
89149 #ifndef SQLITE_OMIT_ANALYZE
 
89150
89151 #if defined(SQLITE_ENABLE_STAT4)
89152 # define IsStat4 1
89153 # define IsStat3 0
89154 #elif defined(SQLITE_ENABLE_STAT3)
@@ -90910,10 +91061,11 @@
90910 ** May you share freely, never taking more than you give.
90911 **
90912 *************************************************************************
90913 ** This file contains code used to implement the ATTACH and DETACH commands.
90914 */
 
90915
90916 #ifndef SQLITE_OMIT_ATTACH
90917 /*
90918 ** Resolve an expression that was part of an ATTACH or DETACH statement. This
90919 ** is slightly different from resolving a normal SQL expression, because simple
@@ -91499,10 +91651,11 @@
91499 ** This file contains code used to implement the sqlite3_set_authorizer()
91500 ** API. This facility is an optional feature of the library. Embedded
91501 ** systems that do not need this facility may omit it by recompiling
91502 ** the library with -DSQLITE_OMIT_AUTHORIZATION=1
91503 */
 
91504
91505 /*
91506 ** All of the code in this file may be omitted by defining a single
91507 ** macro.
91508 */
@@ -91769,10 +91922,11 @@
91769 ** creating ID lists
91770 ** BEGIN TRANSACTION
91771 ** COMMIT
91772 ** ROLLBACK
91773 */
 
91774
91775 /*
91776 ** This routine is called when a new SQL statement is beginning to
91777 ** be parsed. Initialize the pParse structure as needed.
91778 */
@@ -96089,10 +96243,11 @@
96089 **
96090 ** This file contains functions used to access the internal hash tables
96091 ** of user defined functions and collation sequences.
96092 */
96093
 
96094
96095 /*
96096 ** Invoke the 'collation needed' callback to request a collation sequence
96097 ** in the encoding enc of name zName, length nName.
96098 */
@@ -96566,10 +96721,11 @@
96566 **
96567 *************************************************************************
96568 ** This file contains C code routines that are called by the parser
96569 ** in order to generate code for DELETE FROM statements.
96570 */
 
96571
96572 /*
96573 ** While a SrcList can in general represent multiple tables and subqueries
96574 ** (as in the FROM clause of a SELECT statement) in this case it contains
96575 ** the name of a single table, as one might find in an INSERT, DELETE,
@@ -97408,12 +97564,14 @@
97408 *************************************************************************
97409 ** This file contains the C-language implementations for many of the SQL
97410 ** functions of SQLite. (Some function, and in particular the date and
97411 ** time functions, are implemented separately.)
97412 */
 
97413 /* #include <stdlib.h> */
97414 /* #include <assert.h> */
 
97415
97416 /*
97417 ** Return the collating function associated with a function.
97418 */
97419 static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
@@ -98515,20 +98673,18 @@
98515 sqlite3_context *context,
98516 int argc,
98517 sqlite3_value **argv
98518 ){
98519 i64 n;
98520 sqlite3 *db = sqlite3_context_db_handle(context);
98521 assert( argc==1 );
98522 UNUSED_PARAMETER(argc);
98523 n = sqlite3_value_int64(argv[0]);
98524 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
98525 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
98526 if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
98527 sqlite3_result_error_toobig(context);
98528 }else{
98529 sqlite3_result_zeroblob(context, (int)n); /* IMP: R-00293-64994 */
98530 }
98531 }
98532
98533 /*
98534 ** The replace() function. Three arguments are all strings: call
@@ -99205,10 +99361,11 @@
99205 **
99206 *************************************************************************
99207 ** This file contains code used by the compiler to add foreign key
99208 ** support to compiled SQL statements.
99209 */
 
99210
99211 #ifndef SQLITE_OMIT_FOREIGN_KEY
99212 #ifndef SQLITE_OMIT_TRIGGER
99213
99214 /*
@@ -100609,10 +100766,11 @@
100609 **
100610 *************************************************************************
100611 ** This file contains C code routines that are called by the parser
100612 ** to handle INSERT statements in SQLite.
100613 */
 
100614
100615 /*
100616 ** Generate code that will
100617 **
100618 ** (1) acquire a lock for table pTab then
@@ -102592,11 +102750,11 @@
102592 }else{
102593 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
102594 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
102595 }
102596 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
102597 u8 useSeekResult = 0;
102598 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
102599 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
102600 }
102601 assert( pSrcIdx );
102602 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -102627,16 +102785,19 @@
102627 char *zColl = pSrcIdx->azColl[i];
102628 assert( zColl!=0 );
102629 if( sqlite3_stricmp("BINARY", zColl) ) break;
102630 }
102631 if( i==pSrcIdx->nColumn ){
102632 useSeekResult = OPFLAG_USESEEKRESULT;
102633 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
102634 }
 
 
 
102635 }
102636 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
102637 sqlite3VdbeChangeP5(v, useSeekResult);
102638 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
102639 sqlite3VdbeJumpHere(v, addr1);
102640 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
102641 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
102642 }
@@ -102671,10 +102832,11 @@
102671 ** implement the programmer interface to the library. Routines in
102672 ** other files are for internal use by SQLite and should not be
102673 ** accessed by users of the library.
102674 */
102675
 
102676
102677 /*
102678 ** Execute SQL code. Return one of the SQLITE_ success/failure
102679 ** codes. Also write an error message into memory obtained from
102680 ** malloc() and make *pzErrMsg point to that message.
@@ -102839,10 +103001,11 @@
102839 ** as extensions by SQLite should #include this file instead of
102840 ** sqlite3.h.
102841 */
102842 #ifndef _SQLITE3EXT_H_
102843 #define _SQLITE3EXT_H_
 
102844
102845 typedef struct sqlite3_api_routines sqlite3_api_routines;
102846
102847 /*
102848 ** The following structure holds pointers to all of the SQLite API
@@ -103091,10 +103254,12 @@
103091 void(*)(void*), unsigned char);
103092 int (*strglob)(const char*,const char*);
103093 /* Version 3.8.11 and later */
103094 sqlite3_value *(*value_dup)(const sqlite3_value*);
103095 void (*value_free)(sqlite3_value*);
 
 
103096 };
103097
103098 /*
103099 ** The following macros redefine the API routines so that they are
103100 ** redirected through the global sqlite3_api structure.
@@ -103324,10 +103489,12 @@
103324 #define sqlite3_result_text64 sqlite3_api->result_text64
103325 #define sqlite3_strglob sqlite3_api->strglob
103326 /* Version 3.8.11 and later */
103327 #define sqlite3_value_dup sqlite3_api->value_dup
103328 #define sqlite3_value_free sqlite3_api->value_free
 
 
103329 #endif /* SQLITE_CORE */
103330
103331 #ifndef SQLITE_CORE
103332 /* This case when the file really is being compiled as a loadable
103333 ** extension */
@@ -103345,10 +103512,11 @@
103345
103346 #endif /* _SQLITE3EXT_H_ */
103347
103348 /************** End of sqlite3ext.h ******************************************/
103349 /************** Continuing where we left off in loadext.c ********************/
 
103350 /* #include <string.h> */
103351
103352 #ifndef SQLITE_OMIT_LOAD_EXTENSION
103353
103354 /*
@@ -103732,11 +103900,13 @@
103732 sqlite3_result_blob64,
103733 sqlite3_result_text64,
103734 sqlite3_strglob,
103735 /* Version 3.8.11 and later */
103736 (sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
103737 sqlite3_value_free
 
 
103738 };
103739
103740 /*
103741 ** Attempt to load an SQLite extension library contained in the file
103742 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -104114,10 +104284,11 @@
104114 ** May you share freely, never taking more than you give.
104115 **
104116 *************************************************************************
104117 ** This file contains code used to implement the PRAGMA command.
104118 */
 
104119
104120 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
104121 # if defined(__APPLE__)
104122 # define SQLITE_ENABLE_LOCKING_STYLE 1
104123 # else
@@ -104220,11 +104391,11 @@
104220 /* ePragFlag: */ 0,
104221 /* iArg: */ 0 },
104222 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
104223 { /* zName: */ "cache_size",
104224 /* ePragTyp: */ PragTyp_CACHE_SIZE,
104225 /* ePragFlag: */ PragFlag_NeedSchema,
104226 /* iArg: */ 0 },
104227 #endif
104228 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
104229 { /* zName: */ "cache_spill",
104230 /* ePragTyp: */ PragTyp_FLAG,
@@ -105290,15 +105461,17 @@
105290 ** of memory.
105291 */
105292 case PragTyp_CACHE_SIZE: {
105293 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
105294 if( !zRight ){
 
105295 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
105296 }else{
105297 int size = sqlite3Atoi(zRight);
105298 pDb->pSchema->cache_size = size;
105299 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
 
105300 }
105301 break;
105302 }
105303
105304 /*
@@ -106565,10 +106738,11 @@
106565 *************************************************************************
106566 ** This file contains the implementation of the sqlite3_prepare()
106567 ** interface, and routines that contribute to loading the database schema
106568 ** from disk.
106569 */
 
106570
106571 /*
106572 ** Fill the InitData structure with an error message that indicates
106573 ** that the database is corrupt.
106574 */
@@ -107459,10 +107633,11 @@
107459 **
107460 *************************************************************************
107461 ** This file contains C code routines that are called by the parser
107462 ** to handle SELECT statements in SQLite.
107463 */
 
107464
107465 /*
107466 ** Trace output macros
107467 */
107468 #if SELECTTRACE_ENABLED
@@ -108528,11 +108703,10 @@
108528 }
108529 }
108530 return pInfo;
108531 }
108532
108533 #ifndef SQLITE_OMIT_COMPOUND_SELECT
108534 /*
108535 ** Name of the connection operator, used for error messages.
108536 */
108537 static const char *selectOpName(int id){
108538 char *z;
@@ -108542,11 +108716,10 @@
108542 case TK_EXCEPT: z = "EXCEPT"; break;
108543 default: z = "UNION"; break;
108544 }
108545 return z;
108546 }
108547 #endif /* SQLITE_OMIT_COMPOUND_SELECT */
108548
108549 #ifndef SQLITE_OMIT_EXPLAIN
108550 /*
108551 ** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
108552 ** is a no-op. Otherwise, it adds a single row of output to the EQP result,
@@ -109545,23 +109718,10 @@
109545 Parse *pParse, /* Parsing context */
109546 Select *p, /* The right-most of SELECTs to be coded */
109547 SelectDest *pDest /* What to do with query results */
109548 );
109549
109550 /*
109551 ** Error message for when two or more terms of a compound select have different
109552 ** size result sets.
109553 */
109554 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){
109555 if( p->selFlags & SF_Values ){
109556 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
109557 }else{
109558 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
109559 " do not have the same number of result columns", selectOpName(p->op));
109560 }
109561 }
109562
109563 /*
109564 ** Handle the special case of a compound-select that originates from a
109565 ** VALUES clause. By handling this as a special case, we avoid deep
109566 ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
109567 ** on a VALUES clause.
@@ -109983,10 +110143,23 @@
109983 pDest->nSdst = dest.nSdst;
109984 sqlite3SelectDelete(db, pDelete);
109985 return rc;
109986 }
109987 #endif /* SQLITE_OMIT_COMPOUND_SELECT */
 
 
 
 
 
 
 
 
 
 
 
 
 
109988
109989 /*
109990 ** Code an output subroutine for a coroutine implementation of a
109991 ** SELECT statment.
109992 **
@@ -113077,10 +113250,11 @@
113077 ** interface routine of sqlite3_exec().
113078 **
113079 ** These routines are in a separate files so that they will not be linked
113080 ** if they are not used.
113081 */
 
113082 /* #include <stdlib.h> */
113083 /* #include <string.h> */
113084
113085 #ifndef SQLITE_OMIT_GET_TABLE
113086
@@ -113273,10 +113447,11 @@
113273 ** May you share freely, never taking more than you give.
113274 **
113275 *************************************************************************
113276 ** This file contains the implementation for TRIGGERs
113277 */
 
113278
113279 #ifndef SQLITE_OMIT_TRIGGER
113280 /*
113281 ** Delete a linked list of TriggerStep structures.
113282 */
@@ -114396,10 +114571,11 @@
114396 **
114397 *************************************************************************
114398 ** This file contains C code routines that are called by the parser
114399 ** to handle UPDATE statements.
114400 */
 
114401
114402 #ifndef SQLITE_OMIT_VIRTUALTABLE
114403 /* Forward declaration */
114404 static void updateVirtualTable(
114405 Parse *pParse, /* The parsing context */
@@ -115172,10 +115348,12 @@
115172 ** This file contains code used to implement the VACUUM command.
115173 **
115174 ** Most of the code in this file may be omitted by defining the
115175 ** SQLITE_OMIT_VACUUM macro.
115176 */
 
 
115177
115178 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
115179 /*
115180 ** Finalize a prepared statement. If there was an error, store the
115181 ** text of the error message in *pzErrMsg. Return the result code.
@@ -115544,10 +115722,11 @@
115544 **
115545 *************************************************************************
115546 ** This file contains code used to help implement virtual tables.
115547 */
115548 #ifndef SQLITE_OMIT_VIRTUALTABLE
 
115549
115550 /*
115551 ** Before a virtual table xCreate() or xConnect() method is invoked, the
115552 ** sqlite3.pVtabCtx member variable is set to point to an instance of
115553 ** this struct allocated on the stack. It is used by the implementation of
@@ -116702,10 +116881,11 @@
116702 ** This file was split off from where.c on 2015-06-06 in order to reduce the
116703 ** size of where.c and make it easier to edit. This file contains the routines
116704 ** that actually generate the bulk of the WHERE loop code. The original where.c
116705 ** file retains the code that does query planning and analysis.
116706 */
 
116707 /************** Include whereInt.h in the middle of wherecode.c **************/
116708 /************** Begin file whereInt.h ****************************************/
116709 /*
116710 ** 2013-11-12
116711 **
@@ -118513,11 +118693,15 @@
118513
118514 /* Read the PK into an array of temp registers. */
118515 r = sqlite3GetTempRange(pParse, nPk);
118516 for(iPk=0; iPk<nPk; iPk++){
118517 int iCol = pPk->aiColumn[iPk];
118518 sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur, r+iPk, 0);
 
 
 
 
118519 }
118520
118521 /* Check if the temp table already contains this key. If so,
118522 ** the row has already been included in the result set and
118523 ** can be ignored (by jumping past the Gosub below). Otherwise,
@@ -118737,10 +118921,12 @@
118737 **
118738 ** This file was originally part of where.c but was split out to improve
118739 ** readability and editabiliity. This file contains utility routines for
118740 ** analyzing Expr objects in the WHERE clause.
118741 */
 
 
118742
118743 /* Forward declarations */
118744 static void exprAnalyze(SrcList*, WhereClause*, int);
118745
118746 /*
@@ -119987,10 +120173,12 @@
119987 ** generating the code that loops through a table looking for applicable
119988 ** rows. Indices are selected and used to speed the search when doing
119989 ** so is applicable. Because this module is responsible for selecting
119990 ** indices, you might also think of this module as the "query optimizer".
119991 */
 
 
119992
119993 /* Forward declaration of methods */
119994 static int whereLoopResize(sqlite3*, WhereLoop*, int);
119995
119996 /* Test variable that can be set to enable WHERE tracing */
@@ -124486,10 +124674,11 @@
124486 */
124487 /* First off, code is included that follows the "include" declaration
124488 ** in the input grammar file. */
124489 /* #include <stdio.h> */
124490
 
124491
124492 /*
124493 ** Disable all error recovery processing in the parser push-down
124494 ** automaton.
124495 */
@@ -128071,10 +128260,11 @@
128071 **
128072 ** This file contains C code that splits an SQL input string up into
128073 ** individual tokens and sends those tokens one-by-one over to the
128074 ** parser for analysis.
128075 */
 
128076 /* #include <stdlib.h> */
128077
128078 /*
128079 ** The charMap() macro maps alphabetic characters into their
128080 ** lower-case ASCII equivalent. On ASCII machines, this is just
@@ -128880,10 +129070,11 @@
128880 ** This file contains C code that implements the sqlite3_complete() API.
128881 ** This code used to be part of the tokenizer.c source file. But by
128882 ** separating it out, the code will be automatically omitted from
128883 ** static links that do not use it.
128884 */
 
128885 #ifndef SQLITE_OMIT_COMPLETE
128886
128887 /*
128888 ** This is defined in tokenize.c. We just have to import the definition.
128889 */
@@ -129170,10 +129361,11 @@
129170 ** Main file for the SQLite library. The routines in this file
129171 ** implement the programmer interface to the library. Routines in
129172 ** other files are for internal use by SQLite and should not be
129173 ** accessed by users of the library.
129174 */
 
129175
129176 #ifdef SQLITE_ENABLE_FTS3
129177 /************** Include fts3.h in the middle of main.c ***********************/
129178 /************** Begin file fts3.h ********************************************/
129179 /*
@@ -129189,10 +129381,11 @@
129189 ******************************************************************************
129190 **
129191 ** This header file is used by programs that want to link against the
129192 ** FTS3 library. All it does is declare the sqlite3Fts3Init() interface.
129193 */
 
129194
129195 #if 0
129196 extern "C" {
129197 #endif /* __cplusplus */
129198
@@ -129221,10 +129414,11 @@
129221 ******************************************************************************
129222 **
129223 ** This header file is used by programs that want to link against the
129224 ** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
129225 */
 
129226
129227 #if 0
129228 extern "C" {
129229 #endif /* __cplusplus */
129230
@@ -129253,10 +129447,11 @@
129253 ******************************************************************************
129254 **
129255 ** This header file is used by programs that want to link against the
129256 ** ICU extension. All it does is declare the sqlite3IcuInit() interface.
129257 */
 
129258
129259 #if 0
129260 extern "C" {
129261 #endif /* __cplusplus */
129262
@@ -129885,10 +130080,11 @@
129885 ** space for the lookaside memory is obtained from sqlite3_malloc().
129886 ** If pStart is not NULL then it is sz*cnt bytes of memory to use for
129887 ** the lookaside memory.
129888 */
129889 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
 
129890 void *pStart;
129891 if( db->lookaside.nOut ){
129892 return SQLITE_BUSY;
129893 }
129894 /* Free any existing lookaside buffer for this handle before
@@ -129935,10 +130131,11 @@
129935 db->lookaside.pStart = db;
129936 db->lookaside.pEnd = db;
129937 db->lookaside.bEnabled = 0;
129938 db->lookaside.bMalloced = 0;
129939 }
 
129940 return SQLITE_OK;
129941 }
129942
129943 /*
129944 ** Return the mutex associated with a database connection.
@@ -133045,10 +133242,12 @@
133045 *************************************************************************
133046 **
133047 ** This file contains the implementation of the sqlite3_unlock_notify()
133048 ** API method and its associated functionality.
133049 */
 
 
133050
133051 /* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */
133052 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
133053
133054 /*
@@ -133688,13 +133887,15 @@
133688
133689 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
133690
133691 /* If not building as part of the core, include sqlite3ext.h. */
133692 #ifndef SQLITE_CORE
 
133693 SQLITE_EXTENSION_INIT3
133694 #endif
133695
 
133696 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
133697 /************** Begin file fts3_tokenizer.h **********************************/
133698 /*
133699 ** 2006 July 10
133700 **
@@ -133719,10 +133920,11 @@
133719
133720 /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time.
133721 ** If tokenizers are to be allowed to call sqlite3_*() functions, then
133722 ** we will need a way to register the API consistently.
133723 */
 
133724
133725 /*
133726 ** Structures used by the tokenizer interface. When a new tokenizer
133727 ** implementation is registered, the caller provides a pointer to
133728 ** an sqlite3_tokenizer_module containing pointers to the callback
@@ -134559,11 +134761,13 @@
134559 /* #include <stddef.h> */
134560 /* #include <stdio.h> */
134561 /* #include <string.h> */
134562 /* #include <stdarg.h> */
134563
 
134564 #ifndef SQLITE_CORE
 
134565 SQLITE_EXTENSION_INIT1
134566 #endif
134567
134568 static int fts3EvalNext(Fts3Cursor *pCsr);
134569 static int fts3EvalStart(Fts3Cursor *pCsr);
@@ -138486,11 +138690,10 @@
138486 ** tokens or prefix tokens that cannot use a prefix-index. */
138487 int bHaveIncr = 0;
138488 int bIncrOk = (bOptOk
138489 && pCsr->bDesc==pTab->bDescIdx
138490 && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
138491 && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
138492 #ifdef SQLITE_TEST
138493 && pTab->bNoIncrDoclist==0
138494 #endif
138495 );
138496 for(i=0; bIncrOk==1 && i<p->nToken; i++){
@@ -138606,10 +138809,11 @@
138606 if( p==0 ){
138607 p = aDoclist;
138608 p += sqlite3Fts3GetVarint(p, piDocid);
138609 }else{
138610 fts3PoslistCopy(0, &p);
 
138611 if( p>=&aDoclist[nDoclist] ){
138612 *pbEof = 1;
138613 }else{
138614 sqlite3_int64 iVar;
138615 p += sqlite3Fts3GetVarint(p, &iVar);
@@ -140012,14 +140216,14 @@
140012 pIter = pPhrase->doclist.pList;
140013 if( iDocid!=pCsr->iPrevId || pExpr->bEof ){
140014 int rc = SQLITE_OK;
140015 int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */
140016 int bOr = 0;
140017 u8 bEof = 0;
140018 u8 bTreeEof = 0;
140019 Fts3Expr *p; /* Used to iterate from pExpr to root */
140020 Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */
 
140021
140022 /* Check if this phrase descends from an OR expression node. If not,
140023 ** return NULL. Otherwise, the entry that corresponds to docid
140024 ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
140025 ** tree that the node is part of has been marked as EOF, but the node
@@ -140049,35 +140253,51 @@
140049 fts3EvalNextRow(pCsr, pNear, &rc);
140050 }
140051 }
140052 if( rc!=SQLITE_OK ) return rc;
140053
140054 pIter = pPhrase->pOrPoslist;
140055 iDocid = pPhrase->iOrDocid;
140056 if( pCsr->bDesc==bDescDoclist ){
140057 bEof = !pPhrase->doclist.nAll ||
140058 (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
140059 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
140060 sqlite3Fts3DoclistNext(
140061 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
140062 &pIter, &iDocid, &bEof
140063 );
140064 }
140065 }else{
140066 bEof = !pPhrase->doclist.nAll || (pIter && pIter<=pPhrase->doclist.aAll);
140067 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
140068 int dummy;
140069 sqlite3Fts3DoclistPrev(
140070 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
140071 &pIter, &iDocid, &dummy, &bEof
140072 );
140073 }
140074 }
140075 pPhrase->pOrPoslist = pIter;
140076 pPhrase->iOrDocid = iDocid;
140077
140078 if( bEof || iDocid!=pCsr->iPrevId ) pIter = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140079 }
140080 if( pIter==0 ) return SQLITE_OK;
140081
140082 if( *pIter==0x01 ){
140083 pIter++;
@@ -140161,10 +140381,11 @@
140161 ** May you share freely, never taking more than you give.
140162 **
140163 ******************************************************************************
140164 **
140165 */
 
140166 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
140167
140168 /* #include <string.h> */
140169 /* #include <assert.h> */
140170
@@ -140717,10 +140938,11 @@
140717 ** This module contains code that implements a parser for fts3 query strings
140718 ** (the right-hand argument to the MATCH operator). Because the supported
140719 ** syntax is relatively simple, the whole tokenizer/parser system is
140720 ** hand-coded.
140721 */
 
140722 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
140723
140724 /*
140725 ** By default, this module parses the legacy syntax that has been
140726 ** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS
@@ -142010,16 +142232,18 @@
142010 ** (in which case SQLITE_CORE is not defined), or
142011 **
142012 ** * The FTS3 module is being built into the core of
142013 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
142014 */
 
142015 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
142016
142017 /* #include <assert.h> */
142018 /* #include <stdlib.h> */
142019 /* #include <string.h> */
142020
 
142021
142022 /*
142023 ** Malloc and Free functions
142024 */
142025 static void *fts3HashMalloc(int n){
@@ -142393,17 +142617,19 @@
142393 ** (in which case SQLITE_CORE is not defined), or
142394 **
142395 ** * The FTS3 module is being built into the core of
142396 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
142397 */
 
142398 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
142399
142400 /* #include <assert.h> */
142401 /* #include <stdlib.h> */
142402 /* #include <stdio.h> */
142403 /* #include <string.h> */
142404
 
142405
142406 /*
142407 ** Class derived from sqlite3_tokenizer
142408 */
142409 typedef struct porter_tokenizer {
@@ -143057,10 +143283,11 @@
143057 ** (in which case SQLITE_CORE is not defined), or
143058 **
143059 ** * The FTS3 module is being built into the core of
143060 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
143061 */
 
143062 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143063
143064 /* #include <assert.h> */
143065 /* #include <string.h> */
143066
@@ -143552,17 +143779,19 @@
143552 ** (in which case SQLITE_CORE is not defined), or
143553 **
143554 ** * The FTS3 module is being built into the core of
143555 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
143556 */
 
143557 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143558
143559 /* #include <assert.h> */
143560 /* #include <stdlib.h> */
143561 /* #include <stdio.h> */
143562 /* #include <string.h> */
143563
 
143564
143565 typedef struct simple_tokenizer {
143566 sqlite3_tokenizer base;
143567 char delim[128]; /* flag ASCII delimiters */
143568 } simple_tokenizer;
@@ -143803,10 +144032,11 @@
143803 ** end: Byte offset of the byte immediately following the end of the
143804 ** token within the input string.
143805 ** pos: Token offset of token within input.
143806 **
143807 */
 
143808 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143809
143810 /* #include <string.h> */
143811 /* #include <assert.h> */
143812
@@ -144238,10 +144468,11 @@
144238 ** tables. It also contains code to merge FTS3 b-tree segments. Some
144239 ** of the sub-routines used to merge segments are also used by the query
144240 ** code in fts3.c.
144241 */
144242
 
144243 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
144244
144245 /* #include <string.h> */
144246 /* #include <assert.h> */
144247 /* #include <stdlib.h> */
@@ -149898,10 +150129,11 @@
149898 ** May you share freely, never taking more than you give.
149899 **
149900 ******************************************************************************
149901 */
149902
 
149903 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
149904
149905 /* #include <string.h> */
149906 /* #include <assert.h> */
149907
@@ -151610,17 +151842,19 @@
151610 ** Implementation of the "unicode" full-text-search tokenizer.
151611 */
151612
151613 #ifndef SQLITE_DISABLE_FTS3_UNICODE
151614
 
151615 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
151616
151617 /* #include <assert.h> */
151618 /* #include <stdlib.h> */
151619 /* #include <stdio.h> */
151620 /* #include <string.h> */
151621
 
151622
151623 /*
151624 ** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
151625 ** from the sqlite3 source file utf.c. If this file is compiled as part
151626 ** of the amalgamation, they are not required.
@@ -152412,12 +152646,14 @@
152412 */
152413
152414 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
152415
152416 #ifndef SQLITE_CORE
 
152417 SQLITE_EXTENSION_INIT1
152418 #else
 
152419 #endif
152420
152421 /* #include <string.h> */
152422 /* #include <assert.h> */
152423 /* #include <stdio.h> */
@@ -155909,12 +156145,14 @@
155909 #include <unicode/ucol.h>
155910
155911 /* #include <assert.h> */
155912
155913 #ifndef SQLITE_CORE
 
155914 SQLITE_EXTENSION_INIT1
155915 #else
 
155916 #endif
155917
155918 /*
155919 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
155920 ** operator.
@@ -156386,15 +156624,17 @@
156386 ** May you share freely, never taking more than you give.
156387 **
156388 *************************************************************************
156389 ** This file implements a tokenizer for fts3 based on the ICU library.
156390 */
 
156391 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
156392 #ifdef SQLITE_ENABLE_ICU
156393
156394 /* #include <assert.h> */
156395 /* #include <string.h> */
 
156396
156397 #include <unicode/ubrk.h>
156398 /* #include <unicode/ucol.h> */
156399 /* #include <unicode/ustring.h> */
156400 #include <unicode/utf16.h>
@@ -156635,11 +156875,11 @@
156635
156636 #endif /* defined(SQLITE_ENABLE_ICU) */
156637 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
156638
156639 /************** End of fts3_icu.c ********************************************/
156640 /************** Begin file sqlite3ota.c **************************************/
156641 /*
156642 ** 2014 August 30
156643 **
156644 ** The author disclaims copyright to this source code. In place of
156645 ** a legal notice, here is a blessing:
@@ -156651,15 +156891,15 @@
156651 *************************************************************************
156652 **
156653 **
156654 ** OVERVIEW
156655 **
156656 ** The OTA extension requires that the OTA update be packaged as an
156657 ** SQLite database. The tables it expects to find are described in
156658 ** sqlite3ota.h. Essentially, for each table xyz in the target database
156659 ** that the user wishes to write to, a corresponding data_xyz table is
156660 ** created in the OTA database and populated with one row for each row to
156661 ** update, insert or delete from the target table.
156662 **
156663 ** The update proceeds in three stages:
156664 **
156665 ** 1) The database is updated. The modified database pages are written
@@ -156667,70 +156907,74 @@
156667 ** that it is named "<database>-oal" instead of "<database>-wal".
156668 ** Because regular SQLite clients do not look for file named
156669 ** "<database>-oal", they go on using the original database in
156670 ** rollback mode while the *-oal file is being generated.
156671 **
156672 ** During this stage OTA does not update the database by writing
156673 ** directly to the target tables. Instead it creates "imposter"
156674 ** tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses
156675 ** to update each b-tree individually. All updates required by each
156676 ** b-tree are completed before moving on to the next, and all
156677 ** updates are done in sorted key order.
156678 **
156679 ** 2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
156680 ** location using a call to rename(2). Before doing this the OTA
156681 ** module takes an EXCLUSIVE lock on the database file, ensuring
156682 ** that there are no other active readers.
156683 **
156684 ** Once the EXCLUSIVE lock is released, any other database readers
156685 ** detect the new *-wal file and read the database in wal mode. At
156686 ** this point they see the new version of the database - including
156687 ** the updates made as part of the OTA update.
156688 **
156689 ** 3) The new *-wal file is checkpointed. This proceeds in the same way
156690 ** as a regular database checkpoint, except that a single frame is
156691 ** checkpointed each time sqlite3ota_step() is called. If the OTA
156692 ** handle is closed before the entire *-wal file is checkpointed,
156693 ** the checkpoint progress is saved in the OTA database and the
156694 ** checkpoint can be resumed by another OTA client at some point in
156695 ** the future.
156696 **
156697 ** POTENTIAL PROBLEMS
156698 **
156699 ** The rename() call might not be portable. And OTA is not currently
156700 ** syncing the directory after renaming the file.
156701 **
156702 ** When state is saved, any commit to the *-oal file and the commit to
156703 ** the OTA update database are not atomic. So if the power fails at the
156704 ** wrong moment they might get out of sync. As the main database will be
156705 ** committed before the OTA update database this will likely either just
156706 ** pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
156707 ** constraint violations).
156708 **
156709 ** If some client does modify the target database mid OTA update, or some
156710 ** other error occurs, the OTA extension will keep throwing errors. It's
156711 ** not really clear how to get out of this state. The system could just
156712 ** by delete the OTA update database and *-oal file and have the device
156713 ** download the update again and start over.
156714 **
156715 ** At present, for an UPDATE, both the new.* and old.* records are
156716 ** collected in the ota_xyz table. And for both UPDATEs and DELETEs all
156717 ** fields are collected. This means we're probably writing a lot more
156718 ** data to disk when saving the state of an ongoing update to the OTA
156719 ** update database than is strictly necessary.
156720 **
156721 */
156722
156723 /* #include <assert.h> */
156724 /* #include <string.h> */
156725 /* #include <stdio.h> */
156726 /* #include <unistd.h> */
156727
 
 
 
156728
156729 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA)
156730 /************** Include sqlite3ota.h in the middle of sqlite3ota.c ***********/
156731 /************** Begin file sqlite3ota.h **************************************/
 
 
156732 /*
156733 ** 2014 August 30
156734 **
156735 ** The author disclaims copyright to this source code. In place of
156736 ** a legal notice, here is a blessing:
@@ -156739,11 +156983,11 @@
156739 ** May you find forgiveness for yourself and forgive others.
156740 ** May you share freely, never taking more than you give.
156741 **
156742 *************************************************************************
156743 **
156744 ** This file contains the public interface for the OTA extension.
156745 */
156746
156747 /*
156748 ** SUMMARY
156749 **
@@ -156776,18 +157020,18 @@
156776 ** mobile device that is frequently rebooted. Even after the writer process
156777 ** has committed one or more sub-transactions, other database clients continue
156778 ** to read from the original database snapshot. In other words, partially
156779 ** applied transactions are not visible to other clients.
156780 **
156781 ** "OTA" stands for "Over The Air" update. As in a large database update
156782 ** transmitted via a wireless network to a mobile device. A transaction
156783 ** applied using this extension is hence refered to as an "OTA update".
156784 **
156785 **
156786 ** LIMITATIONS
156787 **
156788 ** An "OTA update" transaction is subject to the following limitations:
156789 **
156790 ** * The transaction must consist of INSERT, UPDATE and DELETE operations
156791 ** only.
156792 **
156793 ** * INSERT statements may not use any default values.
@@ -156808,430 +157052,430 @@
156808 ** * No constraint handling mode except for "OR ROLLBACK" is supported.
156809 **
156810 **
156811 ** PREPARATION
156812 **
156813 ** An "OTA update" is stored as a separate SQLite database. A database
156814 ** containing an OTA update is an "OTA database". For each table in the
156815 ** target database to be updated, the OTA database should contain a table
156816 ** named "data_<target name>" containing the same set of columns as the
156817 ** target table, and one more - "ota_control". The data_% table should
156818 ** have no PRIMARY KEY or UNIQUE constraints, but each column should have
156819 ** the same type as the corresponding column in the target database.
156820 ** The "ota_control" column should have no type at all. For example, if
156821 ** the target database contains:
156822 **
156823 ** CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE);
156824 **
156825 ** Then the OTA database should contain:
156826 **
156827 ** CREATE TABLE data_t1(a INTEGER, b TEXT, c, ota_control);
156828 **
156829 ** The order of the columns in the data_% table does not matter.
156830 **
156831 ** If the target database table is a virtual table or a table that has no
156832 ** PRIMARY KEY declaration, the data_% table must also contain a column
156833 ** named "ota_rowid". This column is mapped to the tables implicit primary
156834 ** key column - "rowid". Virtual tables for which the "rowid" column does
156835 ** not function like a primary key value cannot be updated using OTA. For
156836 ** example, if the target db contains either of the following:
156837 **
156838 ** CREATE VIRTUAL TABLE x1 USING fts3(a, b);
156839 ** CREATE TABLE x1(a, b)
156840 **
156841 ** then the OTA database should contain:
156842 **
156843 ** CREATE TABLE data_x1(a, b, ota_rowid, ota_control);
156844 **
156845 ** All non-hidden columns (i.e. all columns matched by "SELECT *") of the
156846 ** target table must be present in the input table. For virtual tables,
156847 ** hidden columns are optional - they are updated by OTA if present in
156848 ** the input table, or not otherwise. For example, to write to an fts4
156849 ** table with a hidden languageid column such as:
156850 **
156851 ** CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid');
156852 **
156853 ** Either of the following input table schemas may be used:
156854 **
156855 ** CREATE TABLE data_ft1(a, b, langid, ota_rowid, ota_control);
156856 ** CREATE TABLE data_ft1(a, b, ota_rowid, ota_control);
156857 **
156858 ** For each row to INSERT into the target database as part of the OTA
156859 ** update, the corresponding data_% table should contain a single record
156860 ** with the "ota_control" column set to contain integer value 0. The
156861 ** other columns should be set to the values that make up the new record
156862 ** to insert.
156863 **
156864 ** If the target database table has an INTEGER PRIMARY KEY, it is not
156865 ** possible to insert a NULL value into the IPK column. Attempting to
156866 ** do so results in an SQLITE_MISMATCH error.
156867 **
156868 ** For each row to DELETE from the target database as part of the OTA
156869 ** update, the corresponding data_% table should contain a single record
156870 ** with the "ota_control" column set to contain integer value 1. The
156871 ** real primary key values of the row to delete should be stored in the
156872 ** corresponding columns of the data_% table. The values stored in the
156873 ** other columns are not used.
156874 **
156875 ** For each row to UPDATE from the target database as part of the OTA
156876 ** update, the corresponding data_% table should contain a single record
156877 ** with the "ota_control" column set to contain a value of type text.
156878 ** The real primary key values identifying the row to update should be
156879 ** stored in the corresponding columns of the data_% table row, as should
156880 ** the new values of all columns being update. The text value in the
156881 ** "ota_control" column must contain the same number of characters as
156882 ** there are columns in the target database table, and must consist entirely
156883 ** of 'x' and '.' characters (or in some special cases 'd' - see below). For
156884 ** each column that is being updated, the corresponding character is set to
156885 ** 'x'. For those that remain as they are, the corresponding character of the
156886 ** ota_control value should be set to '.'. For example, given the tables
156887 ** above, the update statement:
156888 **
156889 ** UPDATE t1 SET c = 'usa' WHERE a = 4;
156890 **
156891 ** is represented by the data_t1 row created by:
156892 **
156893 ** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..x');
156894 **
156895 ** Instead of an 'x' character, characters of the ota_control value specified
156896 ** for UPDATEs may also be set to 'd'. In this case, instead of updating the
156897 ** target table with the value stored in the corresponding data_% column, the
156898 ** user-defined SQL function "ota_delta()" is invoked and the result stored in
156899 ** the target table column. ota_delta() is invoked with two arguments - the
156900 ** original value currently stored in the target table column and the
156901 ** value specified in the data_xxx table.
156902 **
156903 ** For example, this row:
156904 **
156905 ** INSERT INTO data_t1(a, b, c, ota_control) VALUES(4, NULL, 'usa', '..d');
156906 **
156907 ** is similar to an UPDATE statement such as:
156908 **
156909 ** UPDATE t1 SET c = ota_delta(c, 'usa') WHERE a = 4;
156910 **
156911 ** If the target database table is a virtual table or a table with no PRIMARY
156912 ** KEY, the ota_control value should not include a character corresponding
156913 ** to the ota_rowid value. For example, this:
156914 **
156915 ** INSERT INTO data_ft1(a, b, ota_rowid, ota_control)
156916 ** VALUES(NULL, 'usa', 12, '.x');
156917 **
156918 ** causes a result similar to:
156919 **
156920 ** UPDATE ft1 SET b = 'usa' WHERE rowid = 12;
156921 **
156922 ** The data_xxx tables themselves should have no PRIMARY KEY declarations.
156923 ** However, OTA is more efficient if reading the rows in from each data_xxx
156924 ** table in "rowid" order is roughly the same as reading them sorted by
156925 ** the PRIMARY KEY of the corresponding target database table. In other
156926 ** words, rows should be sorted using the destination table PRIMARY KEY
156927 ** fields before they are inserted into the data_xxx tables.
156928 **
156929 ** USAGE
156930 **
156931 ** The API declared below allows an application to apply an OTA update
156932 ** stored on disk to an existing target database. Essentially, the
156933 ** application:
156934 **
156935 ** 1) Opens an OTA handle using the sqlite3ota_open() function.
156936 **
156937 ** 2) Registers any required virtual table modules with the database
156938 ** handle returned by sqlite3ota_db(). Also, if required, register
156939 ** the ota_delta() implementation.
156940 **
156941 ** 3) Calls the sqlite3ota_step() function one or more times on
156942 ** the new handle. Each call to sqlite3ota_step() performs a single
156943 ** b-tree operation, so thousands of calls may be required to apply
156944 ** a complete update.
156945 **
156946 ** 4) Calls sqlite3ota_close() to close the OTA update handle. If
156947 ** sqlite3ota_step() has been called enough times to completely
156948 ** apply the update to the target database, then the OTA database
156949 ** is marked as fully applied. Otherwise, the state of the OTA
156950 ** update application is saved in the OTA database for later
156951 ** resumption.
156952 **
156953 ** See comments below for more detail on APIs.
156954 **
156955 ** If an update is only partially applied to the target database by the
156956 ** time sqlite3ota_close() is called, various state information is saved
156957 ** within the OTA database. This allows subsequent processes to automatically
156958 ** resume the OTA update from where it left off.
156959 **
156960 ** To remove all OTA extension state information, returning an OTA database
156961 ** to its original contents, it is sufficient to drop all tables that begin
156962 ** with the prefix "ota_"
156963 **
156964 ** DATABASE LOCKING
156965 **
156966 ** An OTA update may not be applied to a database in WAL mode. Attempting
156967 ** to do so is an error (SQLITE_ERROR).
156968 **
156969 ** While an OTA handle is open, a SHARED lock may be held on the target
156970 ** database file. This means it is possible for other clients to read the
156971 ** database, but not to write it.
156972 **
156973 ** If an OTA update is started and then suspended before it is completed,
156974 ** then an external client writes to the database, then attempting to resume
156975 ** the suspended OTA update is also an error (SQLITE_BUSY).
156976 */
156977
156978 #ifndef _SQLITE3OTA_H
156979 #define _SQLITE3OTA_H
156980
 
156981
156982 typedef struct sqlite3ota sqlite3ota;
156983
156984 /*
156985 ** Open an OTA handle.
156986 **
156987 ** Argument zTarget is the path to the target database. Argument zOta is
156988 ** the path to the OTA database. Each call to this function must be matched
156989 ** by a call to sqlite3ota_close(). When opening the databases, OTA passes
156990 ** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget
156991 ** or zOta begin with "file:", it will be interpreted as an SQLite
156992 ** database URI, not a regular file name.
156993 **
156994 ** If the zState argument is passed a NULL value, the OTA extension stores
156995 ** the current state of the update (how many rows have been updated, which
156996 ** indexes are yet to be updated etc.) within the OTA database itself. This
156997 ** can be convenient, as it means that the OTA application does not need to
156998 ** organize removing a separate state file after the update is concluded.
156999 ** Or, if zState is non-NULL, it must be a path to a database file in which
157000 ** the OTA extension can store the state of the update.
157001 **
157002 ** When resuming an OTA update, the zState argument must be passed the same
157003 ** value as when the OTA update was started.
157004 **
157005 ** Once the OTA update is finished, the OTA extension does not
157006 ** automatically remove any zState database file, even if it created it.
157007 **
157008 ** By default, OTA uses the default VFS to access the files on disk. To
157009 ** use a VFS other than the default, an SQLite "file:" URI containing a
157010 ** "vfs=..." option may be passed as the zTarget option.
157011 **
157012 ** IMPORTANT NOTE FOR ZIPVFS USERS: The OTA extension works with all of
157013 ** SQLite's built-in VFSs, including the multiplexor VFS. However it does
157014 ** not work out of the box with zipvfs. Refer to the comment describing
157015 ** the zipvfs_create_vfs() API below for details on using OTA with zipvfs.
157016 */
157017 SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open(
157018 const char *zTarget,
157019 const char *zOta,
157020 const char *zState
157021 );
157022
157023 /*
157024 ** Internally, each OTA connection uses a separate SQLite database
157025 ** connection to access the target and ota update databases. This
157026 ** API allows the application direct access to these database handles.
157027 **
157028 ** The first argument passed to this function must be a valid, open, OTA
157029 ** handle. The second argument should be passed zero to access the target
157030 ** database handle, or non-zero to access the ota update database handle.
157031 ** Accessing the underlying database handles may be useful in the
157032 ** following scenarios:
157033 **
157034 ** * If any target tables are virtual tables, it may be necessary to
157035 ** call sqlite3_create_module() on the target database handle to
157036 ** register the required virtual table implementations.
157037 **
157038 ** * If the data_xxx tables in the OTA source database are virtual
157039 ** tables, the application may need to call sqlite3_create_module() on
157040 ** the ota update db handle to any required virtual table
157041 ** implementations.
157042 **
157043 ** * If the application uses the "ota_delta()" feature described above,
157044 ** it must use sqlite3_create_function() or similar to register the
157045 ** ota_delta() implementation with the target database handle.
157046 **
157047 ** If an error has occurred, either while opening or stepping the OTA object,
157048 ** this function may return NULL. The error code and message may be collected
157049 ** when sqlite3ota_close() is called.
157050 */
157051 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota*, int bOta);
157052
157053 /*
157054 ** Do some work towards applying the OTA update to the target db.
157055 **
157056 ** Return SQLITE_DONE if the update has been completely applied, or
157057 ** SQLITE_OK if no error occurs but there remains work to do to apply
157058 ** the OTA update. If an error does occur, some other error code is
157059 ** returned.
157060 **
157061 ** Once a call to sqlite3ota_step() has returned a value other than
157062 ** SQLITE_OK, all subsequent calls on the same OTA handle are no-ops
157063 ** that immediately return the same value.
157064 */
157065 SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *pOta);
157066
157067 /*
157068 ** Close an OTA handle.
157069 **
157070 ** If the OTA update has been completely applied, mark the OTA database
157071 ** as fully applied. Otherwise, assuming no error has occurred, save the
157072 ** current state of the OTA update appliation to the OTA database.
157073 **
157074 ** If an error has already occurred as part of an sqlite3ota_step()
157075 ** or sqlite3ota_open() call, or if one occurs within this function, an
157076 ** SQLite error code is returned. Additionally, *pzErrmsg may be set to
157077 ** point to a buffer containing a utf-8 formatted English language error
157078 ** message. It is the responsibility of the caller to eventually free any
157079 ** such buffer using sqlite3_free().
157080 **
157081 ** Otherwise, if no error occurs, this function returns SQLITE_OK if the
157082 ** update has been partially applied, or SQLITE_DONE if it has been
157083 ** completely applied.
157084 */
157085 SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *pOta, char **pzErrmsg);
157086
157087 /*
157088 ** Return the total number of key-value operations (inserts, deletes or
157089 ** updates) that have been performed on the target database since the
157090 ** current OTA update was started.
157091 */
157092 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta);
157093
157094 /*
157095 ** Create an OTA VFS named zName that accesses the underlying file-system
157096 ** via existing VFS zParent. Or, if the zParent parameter is passed NULL,
157097 ** then the new OTA VFS uses the default system VFS to access the file-system.
157098 ** The new object is registered as a non-default VFS with SQLite before
157099 ** returning.
157100 **
157101 ** Part of the OTA implementation uses a custom VFS object. Usually, this
157102 ** object is created and deleted automatically by OTA.
157103 **
157104 ** The exception is for applications that also use zipvfs. In this case,
157105 ** the custom VFS must be explicitly created by the user before the OTA
157106 ** handle is opened. The OTA VFS should be installed so that the zipvfs
157107 ** VFS uses the OTA VFS, which in turn uses any other VFS layers in use
157108 ** (for example multiplexor) to access the file-system. For example,
157109 ** to assemble an OTA enabled VFS stack that uses both zipvfs and
157110 ** multiplexor (error checking omitted):
157111 **
157112 ** // Create a VFS named "multiplex" (not the default).
157113 ** sqlite3_multiplex_initialize(0, 0);
157114 **
157115 ** // Create an ota VFS named "ota" that uses multiplexor. If the
157116 ** // second argument were replaced with NULL, the "ota" VFS would
157117 ** // access the file-system via the system default VFS, bypassing the
157118 ** // multiplexor.
157119 ** sqlite3ota_create_vfs("ota", "multiplex");
157120 **
157121 ** // Create a zipvfs VFS named "zipvfs" that uses ota.
157122 ** zipvfs_create_vfs_v3("zipvfs", "ota", 0, xCompressorAlgorithmDetector);
157123 **
157124 ** // Make zipvfs the default VFS.
157125 ** sqlite3_vfs_register(sqlite3_vfs_find("zipvfs"), 1);
157126 **
157127 ** Because the default VFS created above includes a OTA functionality, it
157128 ** may be used by OTA clients. Attempting to use OTA with a zipvfs VFS stack
157129 ** that does not include the OTA layer results in an error.
157130 **
157131 ** The overhead of adding the "ota" VFS to the system is negligible for
157132 ** non-OTA users. There is no harm in an application accessing the
157133 ** file-system via "ota" all the time, even if it only uses OTA functionality
157134 ** occasionally.
157135 */
157136 SQLITE_API int SQLITE_STDCALL sqlite3ota_create_vfs(const char *zName, const char *zParent);
157137
157138 /*
157139 ** Deregister and destroy an OTA vfs created by an earlier call to
157140 ** sqlite3ota_create_vfs().
157141 **
157142 ** VFS objects are not reference counted. If a VFS object is destroyed
157143 ** before all database handles that use it have been closed, the results
157144 ** are undefined.
157145 */
157146 SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName);
157147
157148 #endif /* _SQLITE3OTA_H */
157149
157150
157151 /************** End of sqlite3ota.h ******************************************/
157152 /************** Continuing where we left off in sqlite3ota.c *****************/
157153
157154 /* Maximum number of prepared UPDATE statements held by this module */
157155 #define SQLITE_OTA_UPDATE_CACHESIZE 16
157156
157157 /*
157158 ** Swap two objects of type TYPE.
157159 */
157160 #if !defined(SQLITE_AMALGAMATION)
157161 # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
157162 #endif
157163
157164 /*
157165 ** The ota_state table is used to save the state of a partially applied
157166 ** update so that it can be resumed later. The table consists of integer
157167 ** keys mapped to values as follows:
157168 **
157169 ** OTA_STATE_STAGE:
157170 ** May be set to integer values 1, 2, 4 or 5. As follows:
157171 ** 1: the *-ota file is currently under construction.
157172 ** 2: the *-ota file has been constructed, but not yet moved
157173 ** to the *-wal path.
157174 ** 4: the checkpoint is underway.
157175 ** 5: the ota update has been checkpointed.
157176 **
157177 ** OTA_STATE_TBL:
157178 ** Only valid if STAGE==1. The target database name of the table
157179 ** currently being written.
157180 **
157181 ** OTA_STATE_IDX:
157182 ** Only valid if STAGE==1. The target database name of the index
157183 ** currently being written, or NULL if the main table is currently being
157184 ** updated.
157185 **
157186 ** OTA_STATE_ROW:
157187 ** Only valid if STAGE==1. Number of rows already processed for the current
157188 ** table/index.
157189 **
157190 ** OTA_STATE_PROGRESS:
157191 ** Total number of sqlite3ota_step() calls made so far as part of this
157192 ** ota update.
157193 **
157194 ** OTA_STATE_CKPT:
157195 ** Valid if STAGE==4. The 64-bit checksum associated with the wal-index
157196 ** header created by recovering the *-wal file. This is used to detect
157197 ** cases when another client appends frames to the *-wal file in the
157198 ** middle of an incremental checkpoint (an incremental checkpoint cannot
157199 ** be continued if this happens).
157200 **
157201 ** OTA_STATE_COOKIE:
157202 ** Valid if STAGE==1. The current change-counter cookie value in the
157203 ** target db file.
157204 **
157205 ** OTA_STATE_OALSZ:
157206 ** Valid if STAGE==1. The size in bytes of the *-oal file.
157207 */
157208 #define OTA_STATE_STAGE 1
157209 #define OTA_STATE_TBL 2
157210 #define OTA_STATE_IDX 3
157211 #define OTA_STATE_ROW 4
157212 #define OTA_STATE_PROGRESS 5
157213 #define OTA_STATE_CKPT 6
157214 #define OTA_STATE_COOKIE 7
157215 #define OTA_STATE_OALSZ 8
157216
157217 #define OTA_STAGE_OAL 1
157218 #define OTA_STAGE_MOVE 2
157219 #define OTA_STAGE_CAPTURE 3
157220 #define OTA_STAGE_CKPT 4
157221 #define OTA_STAGE_DONE 5
157222
157223
157224 #define OTA_CREATE_STATE \
157225 "CREATE TABLE IF NOT EXISTS %s.ota_state(k INTEGER PRIMARY KEY, v)"
157226
157227 typedef struct OtaFrame OtaFrame;
157228 typedef struct OtaObjIter OtaObjIter;
157229 typedef struct OtaState OtaState;
157230 typedef struct ota_vfs ota_vfs;
157231 typedef struct ota_file ota_file;
157232 typedef struct OtaUpdateStmt OtaUpdateStmt;
157233
157234 #if !defined(SQLITE_AMALGAMATION)
157235 typedef unsigned int u32;
157236 typedef unsigned char u8;
157237 typedef sqlite3_int64 i64;
@@ -157245,13 +157489,13 @@
157245 #define WAL_LOCK_WRITE 0
157246 #define WAL_LOCK_CKPT 1
157247 #define WAL_LOCK_READ0 3
157248
157249 /*
157250 ** A structure to store values read from the ota_state table in memory.
157251 */
157252 struct OtaState {
157253 int eStage;
157254 char *zTbl;
157255 char *zIdx;
157256 i64 iWalCksum;
157257 int nRow;
@@ -157258,14 +157502,14 @@
157258 i64 nProgress;
157259 u32 iCookie;
157260 i64 iOalSz;
157261 };
157262
157263 struct OtaUpdateStmt {
157264 char *zMask; /* Copy of update mask used with pUpdate */
157265 sqlite3_stmt *pUpdate; /* Last update statement (or NULL) */
157266 OtaUpdateStmt *pNext;
157267 };
157268
157269 /*
157270 ** An iterator of this type is used to iterate through all objects in
157271 ** the target database that require updating. For each such table, the
@@ -157280,131 +157524,131 @@
157280 ** it points to an array of flags nTblCol elements in size. The flag is
157281 ** set for each column that is either a part of the PK or a part of an
157282 ** index. Or clear otherwise.
157283 **
157284 */
157285 struct OtaObjIter {
157286 sqlite3_stmt *pTblIter; /* Iterate through tables */
157287 sqlite3_stmt *pIdxIter; /* Index iterator */
157288 int nTblCol; /* Size of azTblCol[] array */
157289 char **azTblCol; /* Array of unquoted target column names */
157290 char **azTblType; /* Array of target column types */
157291 int *aiSrcOrder; /* src table col -> target table col */
157292 u8 *abTblPk; /* Array of flags, set on target PK columns */
157293 u8 *abNotNull; /* Array of flags, set on NOT NULL columns */
157294 u8 *abIndexed; /* Array of flags, set on indexed & PK cols */
157295 int eType; /* Table type - an OTA_PK_XXX value */
157296
157297 /* Output variables. zTbl==0 implies EOF. */
157298 int bCleanup; /* True in "cleanup" state */
157299 const char *zTbl; /* Name of target db table */
157300 const char *zIdx; /* Name of target db index (or null) */
157301 int iTnum; /* Root page of current object */
157302 int iPkTnum; /* If eType==EXTERNAL, root of PK index */
157303 int bUnique; /* Current index is unique */
157304
157305 /* Statements created by otaObjIterPrepareAll() */
157306 int nCol; /* Number of columns in current object */
157307 sqlite3_stmt *pSelect; /* Source data */
157308 sqlite3_stmt *pInsert; /* Statement for INSERT operations */
157309 sqlite3_stmt *pDelete; /* Statement for DELETE ops */
157310 sqlite3_stmt *pTmpInsert; /* Insert into ota_tmp_$zTbl */
157311
157312 /* Last UPDATE used (for PK b-tree updates only), or NULL. */
157313 OtaUpdateStmt *pOtaUpdate;
157314 };
157315
157316 /*
157317 ** Values for OtaObjIter.eType
157318 **
157319 ** 0: Table does not exist (error)
157320 ** 1: Table has an implicit rowid.
157321 ** 2: Table has an explicit IPK column.
157322 ** 3: Table has an external PK index.
157323 ** 4: Table is WITHOUT ROWID.
157324 ** 5: Table is a virtual table.
157325 */
157326 #define OTA_PK_NOTABLE 0
157327 #define OTA_PK_NONE 1
157328 #define OTA_PK_IPK 2
157329 #define OTA_PK_EXTERNAL 3
157330 #define OTA_PK_WITHOUT_ROWID 4
157331 #define OTA_PK_VTAB 5
157332
157333
157334 /*
157335 ** Within the OTA_STAGE_OAL stage, each call to sqlite3ota_step() performs
157336 ** one of the following operations.
157337 */
157338 #define OTA_INSERT 1 /* Insert on a main table b-tree */
157339 #define OTA_DELETE 2 /* Delete a row from a main table b-tree */
157340 #define OTA_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */
157341 #define OTA_IDX_INSERT 4 /* Insert on an aux. index b-tree */
157342 #define OTA_UPDATE 5 /* Update a row in a main table b-tree */
157343
157344
157345 /*
157346 ** A single step of an incremental checkpoint - frame iWalFrame of the wal
157347 ** file should be copied to page iDbPage of the database file.
157348 */
157349 struct OtaFrame {
157350 u32 iDbPage;
157351 u32 iWalFrame;
157352 };
157353
157354 /*
157355 ** OTA handle.
157356 */
157357 struct sqlite3ota {
157358 int eStage; /* Value of OTA_STATE_STAGE field */
157359 sqlite3 *dbMain; /* target database handle */
157360 sqlite3 *dbOta; /* ota database handle */
157361 char *zTarget; /* Path to target db */
157362 char *zOta; /* Path to ota db */
157363 char *zState; /* Path to state db (or NULL if zOta) */
157364 char zStateDb[5]; /* Db name for state ("stat" or "main") */
157365 int rc; /* Value returned by last ota_step() call */
157366 char *zErrmsg; /* Error message if rc!=SQLITE_OK */
157367 int nStep; /* Rows processed for current object */
157368 int nProgress; /* Rows processed for all objects */
157369 OtaObjIter objiter; /* Iterator for skipping through tbl/idx */
157370 const char *zVfsName; /* Name of automatically created ota vfs */
157371 ota_file *pTargetFd; /* File handle open on target db */
157372 i64 iOalSz;
157373
157374 /* The following state variables are used as part of the incremental
157375 ** checkpoint stage (eStage==OTA_STAGE_CKPT). See comments surrounding
157376 ** function otaSetupCheckpoint() for details. */
157377 u32 iMaxFrame; /* Largest iWalFrame value in aFrame[] */
157378 u32 mLock;
157379 int nFrame; /* Entries in aFrame[] array */
157380 int nFrameAlloc; /* Allocated size of aFrame[] array */
157381 OtaFrame *aFrame;
157382 int pgsz;
157383 u8 *aBuf;
157384 i64 iWalCksum;
157385 };
157386
157387 /*
157388 ** An ota VFS is implemented using an instance of this structure.
157389 */
157390 struct ota_vfs {
157391 sqlite3_vfs base; /* ota VFS shim methods */
157392 sqlite3_vfs *pRealVfs; /* Underlying VFS */
157393 sqlite3_mutex *mutex; /* Mutex to protect pMain */
157394 ota_file *pMain; /* Linked list of main db files */
157395 };
157396
157397 /*
157398 ** Each file opened by an ota VFS is represented by an instance of
157399 ** the following structure.
157400 */
157401 struct ota_file {
157402 sqlite3_file base; /* sqlite3_file methods */
157403 sqlite3_file *pReal; /* Underlying file handle */
157404 ota_vfs *pOtaVfs; /* Pointer to the ota_vfs object */
157405 sqlite3ota *pOta; /* Pointer to ota object (ota target only) */
157406
157407 int openFlags; /* Flags this file was opened with */
157408 u32 iCookie; /* Cookie value for main db files */
157409 u8 iWriteVer; /* "write-version" value for main db files */
157410
@@ -157411,12 +157655,12 @@
157411 int nShm; /* Number of entries in apShm[] array */
157412 char **apShm; /* Array of mmap'd *-shm regions */
157413 char *zDel; /* Delete this when closing file */
157414
157415 const char *zWal; /* Wal filename for this main db file */
157416 ota_file *pWalFd; /* Wal file descriptor for this main db */
157417 ota_file *pMainNext; /* Next MAIN_DB file */
157418 };
157419
157420
157421 /*
157422 ** Prepare the SQL statement in buffer zSql against database handle db.
@@ -157490,14 +157734,14 @@
157490 }
157491 return rc;
157492 }
157493
157494 /*
157495 ** Free the OtaObjIter.azTblCol[] and OtaObjIter.abTblPk[] arrays allocated
157496 ** by an earlier call to otaObjIterCacheTableInfo().
157497 */
157498 static void otaObjIterFreeCols(OtaObjIter *pIter){
157499 int i;
157500 for(i=0; i<pIter->nTblCol; i++){
157501 sqlite3_free(pIter->azTblCol[i]);
157502 sqlite3_free(pIter->azTblType[i]);
157503 }
@@ -157513,72 +157757,72 @@
157513
157514 /*
157515 ** Finalize all statements and free all allocations that are specific to
157516 ** the current object (table/index pair).
157517 */
157518 static void otaObjIterClearStatements(OtaObjIter *pIter){
157519 OtaUpdateStmt *pUp;
157520
157521 sqlite3_finalize(pIter->pSelect);
157522 sqlite3_finalize(pIter->pInsert);
157523 sqlite3_finalize(pIter->pDelete);
157524 sqlite3_finalize(pIter->pTmpInsert);
157525 pUp = pIter->pOtaUpdate;
157526 while( pUp ){
157527 OtaUpdateStmt *pTmp = pUp->pNext;
157528 sqlite3_finalize(pUp->pUpdate);
157529 sqlite3_free(pUp);
157530 pUp = pTmp;
157531 }
157532
157533 pIter->pSelect = 0;
157534 pIter->pInsert = 0;
157535 pIter->pDelete = 0;
157536 pIter->pOtaUpdate = 0;
157537 pIter->pTmpInsert = 0;
157538 pIter->nCol = 0;
157539 }
157540
157541 /*
157542 ** Clean up any resources allocated as part of the iterator object passed
157543 ** as the only argument.
157544 */
157545 static void otaObjIterFinalize(OtaObjIter *pIter){
157546 otaObjIterClearStatements(pIter);
157547 sqlite3_finalize(pIter->pTblIter);
157548 sqlite3_finalize(pIter->pIdxIter);
157549 otaObjIterFreeCols(pIter);
157550 memset(pIter, 0, sizeof(OtaObjIter));
157551 }
157552
157553 /*
157554 ** Advance the iterator to the next position.
157555 **
157556 ** If no error occurs, SQLITE_OK is returned and the iterator is left
157557 ** pointing to the next entry. Otherwise, an error code and message is
157558 ** left in the OTA handle passed as the first argument. A copy of the
157559 ** error code is returned.
157560 */
157561 static int otaObjIterNext(sqlite3ota *p, OtaObjIter *pIter){
157562 int rc = p->rc;
157563 if( rc==SQLITE_OK ){
157564
157565 /* Free any SQLite statements used while processing the previous object */
157566 otaObjIterClearStatements(pIter);
157567 if( pIter->zIdx==0 ){
157568 rc = sqlite3_exec(p->dbMain,
157569 "DROP TRIGGER IF EXISTS temp.ota_insert_tr;"
157570 "DROP TRIGGER IF EXISTS temp.ota_update1_tr;"
157571 "DROP TRIGGER IF EXISTS temp.ota_update2_tr;"
157572 "DROP TRIGGER IF EXISTS temp.ota_delete_tr;"
157573 , 0, 0, &p->zErrmsg
157574 );
157575 }
157576
157577 if( rc==SQLITE_OK ){
157578 if( pIter->bCleanup ){
157579 otaObjIterFreeCols(pIter);
157580 pIter->bCleanup = 0;
157581 rc = sqlite3_step(pIter->pTblIter);
157582 if( rc!=SQLITE_ROW ){
157583 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
157584 pIter->zTbl = 0;
@@ -157607,11 +157851,11 @@
157607 }
157608 }
157609 }
157610
157611 if( rc!=SQLITE_OK ){
157612 otaObjIterFinalize(pIter);
157613 p->rc = rc;
157614 }
157615 return rc;
157616 }
157617
@@ -157618,20 +157862,20 @@
157618 /*
157619 ** Initialize the iterator structure passed as the second argument.
157620 **
157621 ** If no error occurs, SQLITE_OK is returned and the iterator is left
157622 ** pointing to the first entry. Otherwise, an error code and message is
157623 ** left in the OTA handle passed as the first argument. A copy of the
157624 ** error code is returned.
157625 */
157626 static int otaObjIterFirst(sqlite3ota *p, OtaObjIter *pIter){
157627 int rc;
157628 memset(pIter, 0, sizeof(OtaObjIter));
157629
157630 rc = prepareAndCollectError(p->dbOta, &pIter->pTblIter, &p->zErrmsg,
157631 "SELECT substr(name, 6) FROM sqlite_master "
157632 "WHERE type='table' AND name LIKE 'data_%'"
157633 );
157634
157635 if( rc==SQLITE_OK ){
157636 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
157637 "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
@@ -157640,23 +157884,23 @@
157640 );
157641 }
157642
157643 pIter->bCleanup = 1;
157644 p->rc = rc;
157645 return otaObjIterNext(p, pIter);
157646 }
157647
157648 /*
157649 ** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs,
157650 ** an error code is stored in the OTA handle passed as the first argument.
157651 **
157652 ** If an error has already occurred (p->rc is already set to something other
157653 ** than SQLITE_OK), then this function returns NULL without modifying the
157654 ** stored error code. In this case it still calls sqlite3_free() on any
157655 ** printf() parameters associated with %z conversions.
157656 */
157657 static char *otaMPrintf(sqlite3ota *p, const char *zFmt, ...){
157658 char *zSql = 0;
157659 va_list ap;
157660 va_start(ap, zFmt);
157661 zSql = sqlite3_vmprintf(zFmt, ap);
157662 if( p->rc==SQLITE_OK ){
@@ -157671,20 +157915,21 @@
157671
157672 /*
157673 ** Argument zFmt is a sqlite3_mprintf() style format string. The trailing
157674 ** arguments are the usual subsitution values. This function performs
157675 ** the printf() style substitutions and executes the result as an SQL
157676 ** statement on the OTA handles database.
157677 **
157678 ** If an error occurs, an error code and error message is stored in the
157679 ** OTA handle. If an error has already occurred when this function is
157680 ** called, it is a no-op.
157681 */
157682 static int otaMPrintfExec(sqlite3ota *p, sqlite3 *db, const char *zFmt, ...){
157683 va_list ap;
 
157684 va_start(ap, zFmt);
157685 char *zSql = sqlite3_vmprintf(zFmt, ap);
157686 if( p->rc==SQLITE_OK ){
157687 if( zSql==0 ){
157688 p->rc = SQLITE_NOMEM;
157689 }else{
157690 p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
@@ -157698,16 +157943,16 @@
157698 /*
157699 ** Attempt to allocate and return a pointer to a zeroed block of nByte
157700 ** bytes.
157701 **
157702 ** If an error (i.e. an OOM condition) occurs, return NULL and leave an
157703 ** error code in the ota handle passed as the first argument. Or, if an
157704 ** error has already occurred when this function is called, return NULL
157705 ** immediately without attempting the allocation or modifying the stored
157706 ** error code.
157707 */
157708 static void *otaMalloc(sqlite3ota *p, int nByte){
157709 void *pRet = 0;
157710 if( p->rc==SQLITE_OK ){
157711 assert( nByte>0 );
157712 pRet = sqlite3_malloc(nByte);
157713 if( pRet==0 ){
@@ -157721,17 +157966,17 @@
157721
157722
157723 /*
157724 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
157725 ** there is room for at least nCol elements. If an OOM occurs, store an
157726 ** error code in the OTA handle passed as the first argument.
157727 */
157728 static void otaAllocateIterArrays(sqlite3ota *p, OtaObjIter *pIter, int nCol){
157729 int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
157730 char **azNew;
157731
157732 azNew = (char**)otaMalloc(p, nByte);
157733 if( azNew ){
157734 pIter->azTblCol = azNew;
157735 pIter->azTblType = &azNew[nCol];
157736 pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
157737 pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol];
@@ -157748,11 +157993,11 @@
157748 **
157749 ** If an OOM condition is encountered when attempting to allocate memory,
157750 ** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
157751 ** if the allocation succeeds, (*pRc) is left unchanged.
157752 */
157753 static char *otaStrndup(const char *zStr, int *pRc){
157754 char *zRet = 0;
157755
157756 assert( *pRc==SQLITE_OK );
157757 if( zStr ){
157758 int nCopy = strlen(zStr) + 1;
@@ -157769,14 +158014,14 @@
157769
157770 /*
157771 ** Finalize the statement passed as the second argument.
157772 **
157773 ** If the sqlite3_finalize() call indicates that an error occurs, and the
157774 ** ota handle error code is not already set, set the error code and error
157775 ** message accordingly.
157776 */
157777 static void otaFinalize(sqlite3ota *p, sqlite3_stmt *pStmt){
157778 sqlite3 *db = sqlite3_db_handle(pStmt);
157779 int rc = sqlite3_finalize(pStmt);
157780 if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){
157781 p->rc = rc;
157782 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
@@ -157787,16 +158032,16 @@
157787 **
157788 ** peType is of type (int*), a pointer to an output parameter of type
157789 ** (int). This call sets the output parameter as follows, depending
157790 ** on the type of the table specified by parameters dbName and zTbl.
157791 **
157792 ** OTA_PK_NOTABLE: No such table.
157793 ** OTA_PK_NONE: Table has an implicit rowid.
157794 ** OTA_PK_IPK: Table has an explicit IPK column.
157795 ** OTA_PK_EXTERNAL: Table has an external PK index.
157796 ** OTA_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
157797 ** OTA_PK_VTAB: Table is a virtual table.
157798 **
157799 ** Argument *piPk is also of type (int*), and also points to an output
157800 ** parameter. Unless the table has an external primary key index
157801 ** (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
157802 ** if the table does have an external primary key index, then *piPk
@@ -157804,28 +158049,28 @@
157804 ** returning.
157805 **
157806 ** ALGORITHM:
157807 **
157808 ** if( no entry exists in sqlite_master ){
157809 ** return OTA_PK_NOTABLE
157810 ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
157811 ** return OTA_PK_VTAB
157812 ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
157813 ** if( the index that is the pk exists in sqlite_master ){
157814 ** *piPK = rootpage of that index.
157815 ** return OTA_PK_EXTERNAL
157816 ** }else{
157817 ** return OTA_PK_WITHOUT_ROWID
157818 ** }
157819 ** }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
157820 ** return OTA_PK_IPK
157821 ** }else{
157822 ** return OTA_PK_NONE
157823 ** }
157824 */
157825 static void otaTableType(
157826 sqlite3ota *p,
157827 const char *zTab,
157828 int *peType,
157829 int *piTnum,
157830 int *piPk
157831 ){
@@ -157835,11 +158080,11 @@
157835 ** 2) SELECT count(*) FROM sqlite_master where name=%Q
157836 ** 3) PRAGMA table_info = ?
157837 */
157838 sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
157839
157840 *peType = OTA_PK_NOTABLE;
157841 *piPk = 0;
157842
157843 assert( p->rc==SQLITE_OK );
157844 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
157845 sqlite3_mprintf(
@@ -157847,22 +158092,22 @@
157847 " FROM sqlite_master"
157848 " WHERE name=%Q", zTab
157849 ));
157850 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
157851 /* Either an error, or no such table. */
157852 goto otaTableType_end;
157853 }
157854 if( sqlite3_column_int(aStmt[0], 0) ){
157855 *peType = OTA_PK_VTAB; /* virtual table */
157856 goto otaTableType_end;
157857 }
157858 *piTnum = sqlite3_column_int(aStmt[0], 1);
157859
157860 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[1], &p->zErrmsg,
157861 sqlite3_mprintf("PRAGMA index_list=%Q",zTab)
157862 );
157863 if( p->rc ) goto otaTableType_end;
157864 while( sqlite3_step(aStmt[1])==SQLITE_ROW ){
157865 const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
157866 const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
157867 if( zOrig && zIdx && zOrig[0]=='p' ){
157868 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg,
@@ -157870,45 +158115,45 @@
157870 "SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx
157871 ));
157872 if( p->rc==SQLITE_OK ){
157873 if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
157874 *piPk = sqlite3_column_int(aStmt[2], 0);
157875 *peType = OTA_PK_EXTERNAL;
157876 }else{
157877 *peType = OTA_PK_WITHOUT_ROWID;
157878 }
157879 }
157880 goto otaTableType_end;
157881 }
157882 }
157883
157884 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[3], &p->zErrmsg,
157885 sqlite3_mprintf("PRAGMA table_info=%Q",zTab)
157886 );
157887 if( p->rc==SQLITE_OK ){
157888 while( sqlite3_step(aStmt[3])==SQLITE_ROW ){
157889 if( sqlite3_column_int(aStmt[3],5)>0 ){
157890 *peType = OTA_PK_IPK; /* explicit IPK column */
157891 goto otaTableType_end;
157892 }
157893 }
157894 *peType = OTA_PK_NONE;
157895 }
157896
157897 otaTableType_end: {
157898 int i;
157899 for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
157900 otaFinalize(p, aStmt[i]);
157901 }
157902 }
157903 }
157904
157905 /*
157906 ** This is a helper function for otaObjIterCacheTableInfo(). It populates
157907 ** the pIter->abIndexed[] array.
157908 */
157909 static void otaObjIterCacheIndexedCols(sqlite3ota *p, OtaObjIter *pIter){
157910 sqlite3_stmt *pList = 0;
157911 int bIndex = 0;
157912
157913 if( p->rc==SQLITE_OK ){
157914 memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol);
@@ -157926,15 +158171,15 @@
157926 );
157927 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
157928 int iCid = sqlite3_column_int(pXInfo, 1);
157929 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
157930 }
157931 otaFinalize(p, pXInfo);
157932 bIndex = 1;
157933 }
157934
157935 otaFinalize(p, pList);
157936 if( bIndex==0 ) pIter->abIndexed = 0;
157937 }
157938
157939
157940 /*
@@ -157942,67 +158187,67 @@
157942 ** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
157943 ** the table (not index) that the iterator currently points to.
157944 **
157945 ** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
157946 ** an error does occur, an error code and error message are also left in
157947 ** the OTA handle.
157948 */
157949 static int otaObjIterCacheTableInfo(sqlite3ota *p, OtaObjIter *pIter){
157950 if( pIter->azTblCol==0 ){
157951 sqlite3_stmt *pStmt = 0;
157952 int nCol = 0;
157953 int i; /* for() loop iterator variable */
157954 int bOtaRowid = 0; /* If input table has column "ota_rowid" */
157955 int iOrder = 0;
157956 int iTnum = 0;
157957
157958 /* Figure out the type of table this step will deal with. */
157959 assert( pIter->eType==0 );
157960 otaTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
157961 if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_NOTABLE ){
157962 p->rc = SQLITE_ERROR;
157963 p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl);
157964 }
157965 if( p->rc ) return p->rc;
157966 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
157967
157968 assert( pIter->eType==OTA_PK_NONE || pIter->eType==OTA_PK_IPK
157969 || pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_WITHOUT_ROWID
157970 || pIter->eType==OTA_PK_VTAB
157971 );
157972
157973 /* Populate the azTblCol[] and nTblCol variables based on the columns
157974 ** of the input table. Ignore any input table columns that begin with
157975 ** "ota_". */
157976 p->rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg,
157977 sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl)
157978 );
157979 if( p->rc==SQLITE_OK ){
157980 nCol = sqlite3_column_count(pStmt);
157981 otaAllocateIterArrays(p, pIter, nCol);
157982 }
157983 for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
157984 const char *zName = (const char*)sqlite3_column_name(pStmt, i);
157985 if( sqlite3_strnicmp("ota_", zName, 4) ){
157986 char *zCopy = otaStrndup(zName, &p->rc);
157987 pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol;
157988 pIter->azTblCol[pIter->nTblCol++] = zCopy;
157989 }
157990 else if( 0==sqlite3_stricmp("ota_rowid", zName) ){
157991 bOtaRowid = 1;
157992 }
157993 }
157994 sqlite3_finalize(pStmt);
157995 pStmt = 0;
157996
157997 if( p->rc==SQLITE_OK
157998 && bOtaRowid!=(pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE)
157999 ){
158000 p->rc = SQLITE_ERROR;
158001 p->zErrmsg = sqlite3_mprintf(
158002 "table data_%q %s ota_rowid column", pIter->zTbl,
158003 (bOtaRowid ? "may not have" : "requires")
158004 );
158005 }
158006
158007 /* Check that all non-HIDDEN columns in the destination table are also
158008 ** present in the input table. Populate the abTblPk[], azTblType[] and
@@ -158031,20 +158276,20 @@
158031 if( i!=iOrder ){
158032 SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]);
158033 SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]);
158034 }
158035
158036 pIter->azTblType[iOrder] = otaStrndup(zType, &p->rc);
158037 pIter->abTblPk[iOrder] = (iPk!=0);
158038 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
158039 iOrder++;
158040 }
158041 }
158042
158043 otaFinalize(p, pStmt);
158044 otaObjIterCacheIndexedCols(p, pIter);
158045 assert( pIter->eType!=OTA_PK_VTAB || pIter->abIndexed==0 );
158046 }
158047
158048 return p->rc;
158049 }
158050
@@ -158051,29 +158296,29 @@
158051 /*
158052 ** This function constructs and returns a pointer to a nul-terminated
158053 ** string containing some SQL clause or list based on one or more of the
158054 ** column names currently stored in the pIter->azTblCol[] array.
158055 */
158056 static char *otaObjIterGetCollist(
158057 sqlite3ota *p, /* OTA object */
158058 OtaObjIter *pIter /* Object iterator for column names */
158059 ){
158060 char *zList = 0;
158061 const char *zSep = "";
158062 int i;
158063 for(i=0; i<pIter->nTblCol; i++){
158064 const char *z = pIter->azTblCol[i];
158065 zList = otaMPrintf(p, "%z%s\"%w\"", zList, zSep, z);
158066 zSep = ", ";
158067 }
158068 return zList;
158069 }
158070
158071 /*
158072 ** This function is used to create a SELECT list (the list of SQL
158073 ** expressions that follows a SELECT keyword) for a SELECT statement
158074 ** used to read from an data_xxx or ota_tmp_xxx table while updating the
158075 ** index object currently indicated by the iterator object passed as the
158076 ** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used
158077 ** to obtain the required information.
158078 **
158079 ** If the index is of the following form:
@@ -158090,17 +158335,17 @@
158090 **
158091 ** pzImposterCols: ...
158092 ** pzImposterPk: ...
158093 ** pzWhere: ...
158094 */
158095 static char *otaObjIterGetIndexCols(
158096 sqlite3ota *p, /* OTA object */
158097 OtaObjIter *pIter, /* Object iterator for column names */
158098 char **pzImposterCols, /* OUT: Columns for imposter table */
158099 char **pzImposterPk, /* OUT: Imposter PK clause */
158100 char **pzWhere, /* OUT: WHERE clause */
158101 int *pnBind /* OUT: Total number of columns */
158102 ){
158103 int rc = p->rc; /* Error code */
158104 int rc2; /* sqlite3_finalize() return code */
158105 char *zRet = 0; /* String to return */
158106 char *zImpCols = 0; /* String to return via *pzImposterCols */
@@ -158125,18 +158370,18 @@
158125 const char *zCol;
158126 const char *zType;
158127
158128 if( iCid<0 ){
158129 /* An integer primary key. If the table has an explicit IPK, use
158130 ** its name. Otherwise, use "ota_rowid". */
158131 if( pIter->eType==OTA_PK_IPK ){
158132 int i;
158133 for(i=0; pIter->abTblPk[i]==0; i++);
158134 assert( i<pIter->nTblCol );
158135 zCol = pIter->azTblCol[i];
158136 }else{
158137 zCol = "ota_rowid";
158138 }
158139 zType = "INTEGER";
158140 }else{
158141 zCol = pIter->azTblCol[iCid];
158142 zType = pIter->azTblType[iCid];
@@ -158143,19 +158388,19 @@
158143 }
158144
158145 zRet = sqlite3_mprintf("%z%s\"%w\" COLLATE %Q", zRet, zCom, zCol, zCollate);
158146 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
158147 const char *zOrder = (bDesc ? " DESC" : "");
158148 zImpPK = sqlite3_mprintf("%z%s\"ota_imp_%d%w\"%s",
158149 zImpPK, zCom, nBind, zCol, zOrder
158150 );
158151 }
158152 zImpCols = sqlite3_mprintf("%z%s\"ota_imp_%d%w\" %s COLLATE %Q",
158153 zImpCols, zCom, nBind, zCol, zType, zCollate
158154 );
158155 zWhere = sqlite3_mprintf(
158156 "%z%s\"ota_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol
158157 );
158158 if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM;
158159 zCom = ", ";
158160 zAnd = " AND ";
158161 nBind++;
@@ -158189,16 +158434,16 @@
158189 **
158190 ** "old.a, old.b, old.b"
158191 **
158192 ** With the column names escaped.
158193 **
158194 ** For tables with implicit rowids - OTA_PK_EXTERNAL and OTA_PK_NONE, append
158195 ** the text ", old._rowid_" to the returned value.
158196 */
158197 static char *otaObjIterGetOldlist(
158198 sqlite3ota *p,
158199 OtaObjIter *pIter,
158200 const char *zObj
158201 ){
158202 char *zList = 0;
158203 if( p->rc==SQLITE_OK && pIter->abIndexed ){
158204 const char *zS = "";
@@ -158216,12 +158461,12 @@
158216 break;
158217 }
158218 }
158219
158220 /* For a table with implicit rowids, append "old._rowid_" to the list. */
158221 if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158222 zList = otaMPrintf(p, "%z, %s._rowid_", zList, zObj);
158223 }
158224 }
158225 return zList;
158226 }
158227
@@ -158233,37 +158478,37 @@
158233 **
158234 ** Return the string:
158235 **
158236 ** "b = ?1 AND c = ?2"
158237 */
158238 static char *otaObjIterGetWhere(
158239 sqlite3ota *p,
158240 OtaObjIter *pIter
158241 ){
158242 char *zList = 0;
158243 if( pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE ){
158244 zList = otaMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
158245 }else if( pIter->eType==OTA_PK_EXTERNAL ){
158246 const char *zSep = "";
158247 int i;
158248 for(i=0; i<pIter->nTblCol; i++){
158249 if( pIter->abTblPk[i] ){
158250 zList = otaMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1);
158251 zSep = " AND ";
158252 }
158253 }
158254 zList = otaMPrintf(p,
158255 "_rowid_ = (SELECT id FROM ota_imposter2 WHERE %z)", zList
158256 );
158257
158258 }else{
158259 const char *zSep = "";
158260 int i;
158261 for(i=0; i<pIter->nTblCol; i++){
158262 if( pIter->abTblPk[i] ){
158263 const char *zCol = pIter->azTblCol[i];
158264 zList = otaMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1);
158265 zSep = " AND ";
158266 }
158267 }
158268 }
158269 return zList;
@@ -158270,60 +158515,60 @@
158270 }
158271
158272 /*
158273 ** The SELECT statement iterating through the keys for the current object
158274 ** (p->objiter.pSelect) currently points to a valid row. However, there
158275 ** is something wrong with the ota_control value in the ota_control value
158276 ** stored in the (p->nCol+1)'th column. Set the error code and error message
158277 ** of the OTA handle to something reflecting this.
158278 */
158279 static void otaBadControlError(sqlite3ota *p){
158280 p->rc = SQLITE_ERROR;
158281 p->zErrmsg = sqlite3_mprintf("invalid ota_control value");
158282 }
158283
158284
158285 /*
158286 ** Return a nul-terminated string containing the comma separated list of
158287 ** assignments that should be included following the "SET" keyword of
158288 ** an UPDATE statement used to update the table object that the iterator
158289 ** passed as the second argument currently points to if the ota_control
158290 ** column of the data_xxx table entry is set to zMask.
158291 **
158292 ** The memory for the returned string is obtained from sqlite3_malloc().
158293 ** It is the responsibility of the caller to eventually free it using
158294 ** sqlite3_free().
158295 **
158296 ** If an OOM error is encountered when allocating space for the new
158297 ** string, an error code is left in the ota handle passed as the first
158298 ** argument and NULL is returned. Or, if an error has already occurred
158299 ** when this function is called, NULL is returned immediately, without
158300 ** attempting the allocation or modifying the stored error code.
158301 */
158302 static char *otaObjIterGetSetlist(
158303 sqlite3ota *p,
158304 OtaObjIter *pIter,
158305 const char *zMask
158306 ){
158307 char *zList = 0;
158308 if( p->rc==SQLITE_OK ){
158309 int i;
158310
158311 if( strlen(zMask)!=pIter->nTblCol ){
158312 otaBadControlError(p);
158313 }else{
158314 const char *zSep = "";
158315 for(i=0; i<pIter->nTblCol; i++){
158316 char c = zMask[pIter->aiSrcOrder[i]];
158317 if( c=='x' ){
158318 zList = otaMPrintf(p, "%z%s\"%w\"=?%d",
158319 zList, zSep, pIter->azTblCol[i], i+1
158320 );
158321 zSep = ", ";
158322 }
158323 if( c=='d' ){
158324 zList = otaMPrintf(p, "%z%s\"%w\"=ota_delta(\"%w\", ?%d)",
158325 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
158326 );
158327 zSep = ", ";
158328 }
158329 }
@@ -158340,20 +158585,20 @@
158340 ** The memory for the returned string is obtained from sqlite3_malloc().
158341 ** It is the responsibility of the caller to eventually free it using
158342 ** sqlite3_free().
158343 **
158344 ** If an OOM error is encountered when allocating space for the new
158345 ** string, an error code is left in the ota handle passed as the first
158346 ** argument and NULL is returned. Or, if an error has already occurred
158347 ** when this function is called, NULL is returned immediately, without
158348 ** attempting the allocation or modifying the stored error code.
158349 */
158350 static char *otaObjIterGetBindlist(sqlite3ota *p, int nBind){
158351 char *zRet = 0;
158352 int nByte = nBind*2 + 1;
158353
158354 zRet = (char*)otaMalloc(p, nByte);
158355 if( zRet ){
158356 int i;
158357 for(i=0; i<nBind; i++){
158358 zRet[i*2] = '?';
158359 zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
@@ -158362,21 +158607,21 @@
158362 return zRet;
158363 }
158364
158365 /*
158366 ** The iterator currently points to a table (not index) of type
158367 ** OTA_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
158368 ** declaration for the corresponding imposter table. For example,
158369 ** if the iterator points to a table created as:
158370 **
158371 ** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
158372 **
158373 ** this function returns:
158374 **
158375 ** PRIMARY KEY("b", "a" DESC)
158376 */
158377 static char *otaWithoutRowidPK(sqlite3ota *p, OtaObjIter *pIter){
158378 char *z = 0;
158379 assert( pIter->zIdx==0 );
158380 if( p->rc==SQLITE_OK ){
158381 const char *zSep = "PRIMARY KEY(";
158382 sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
@@ -158395,23 +158640,23 @@
158395 );
158396 }
158397 break;
158398 }
158399 }
158400 otaFinalize(p, pXList);
158401
158402 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158403 if( sqlite3_column_int(pXInfo, 5) ){
158404 /* int iCid = sqlite3_column_int(pXInfo, 0); */
158405 const char *zCol = (const char*)sqlite3_column_text(pXInfo, 2);
158406 const char *zDesc = sqlite3_column_int(pXInfo, 3) ? " DESC" : "";
158407 z = otaMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc);
158408 zSep = ", ";
158409 }
158410 }
158411 z = otaMPrintf(p, "%z)", z);
158412 otaFinalize(p, pXInfo);
158413 }
158414 return z;
158415 }
158416
158417 /*
@@ -158420,23 +158665,23 @@
158420 ** iterator passed as the second argument does not currently point to
158421 ** a table (not index) with an external primary key, this function is a
158422 ** no-op.
158423 **
158424 ** Assuming the iterator does point to a table with an external PK, this
158425 ** function creates a WITHOUT ROWID imposter table named "ota_imposter2"
158426 ** used to access that PK index. For example, if the target table is
158427 ** declared as follows:
158428 **
158429 ** CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
158430 **
158431 ** then the imposter table schema is:
158432 **
158433 ** CREATE TABLE ota_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
158434 **
158435 */
158436 static void otaCreateImposterTable2(sqlite3ota *p, OtaObjIter *pIter){
158437 if( p->rc==SQLITE_OK && pIter->eType==OTA_PK_EXTERNAL ){
158438 int tnum = pIter->iPkTnum; /* Root page of PK index */
158439 sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */
158440 const char *zIdx = 0; /* Name of PK index */
158441 sqlite3_stmt *pXInfo = 0; /* PRAGMA main.index_xinfo = $zIdx */
158442 const char *zComma = "";
@@ -158458,31 +158703,31 @@
158458 if( zIdx ){
158459 p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
158460 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
158461 );
158462 }
158463 otaFinalize(p, pQuery);
158464
158465 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158466 int bKey = sqlite3_column_int(pXInfo, 5);
158467 if( bKey ){
158468 int iCid = sqlite3_column_int(pXInfo, 1);
158469 int bDesc = sqlite3_column_int(pXInfo, 3);
158470 const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
158471 zCols = otaMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma,
158472 iCid, pIter->azTblType[iCid], zCollate
158473 );
158474 zPk = otaMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":"");
158475 zComma = ", ";
158476 }
158477 }
158478 zCols = otaMPrintf(p, "%z, id INTEGER", zCols);
158479 otaFinalize(p, pXInfo);
158480
158481 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158482 otaMPrintfExec(p, p->dbMain,
158483 "CREATE TABLE ota_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID",
158484 zCols, zPk
158485 );
158486 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158487 }
158488 }
@@ -158489,28 +158734,28 @@
158489
158490 /*
158491 ** If an error has already occurred when this function is called, it
158492 ** immediately returns zero (without doing any work). Or, if an error
158493 ** occurs during the execution of this function, it sets the error code
158494 ** in the sqlite3ota object indicated by the first argument and returns
158495 ** zero.
158496 **
158497 ** The iterator passed as the second argument is guaranteed to point to
158498 ** a table (not an index) when this function is called. This function
158499 ** attempts to create any imposter table required to write to the main
158500 ** table b-tree of the table before returning. Non-zero is returned if
158501 ** an imposter table are created, or zero otherwise.
158502 **
158503 ** An imposter table is required in all cases except OTA_PK_VTAB. Only
158504 ** virtual tables are written to directly. The imposter table has the
158505 ** same schema as the actual target table (less any UNIQUE constraints).
158506 ** More precisely, the "same schema" means the same columns, types,
158507 ** collation sequences. For tables that do not have an external PRIMARY
158508 ** KEY, it also means the same PRIMARY KEY declaration.
158509 */
158510 static void otaCreateImposterTable(sqlite3ota *p, OtaObjIter *pIter){
158511 if( p->rc==SQLITE_OK && pIter->eType!=OTA_PK_VTAB ){
158512 int tnum = pIter->iTnum;
158513 const char *zComma = "";
158514 char *zSql = 0;
158515 int iCol;
158516 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
@@ -158522,73 +158767,73 @@
158522
158523 p->rc = sqlite3_table_column_metadata(
158524 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
158525 );
158526
158527 if( pIter->eType==OTA_PK_IPK && pIter->abTblPk[iCol] ){
158528 /* If the target table column is an "INTEGER PRIMARY KEY", add
158529 ** "PRIMARY KEY" to the imposter table column declaration. */
158530 zPk = "PRIMARY KEY ";
158531 }
158532 zSql = otaMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s",
158533 zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
158534 (pIter->abNotNull[iCol] ? " NOT NULL" : "")
158535 );
158536 zComma = ", ";
158537 }
158538
158539 if( pIter->eType==OTA_PK_WITHOUT_ROWID ){
158540 char *zPk = otaWithoutRowidPK(p, pIter);
158541 if( zPk ){
158542 zSql = otaMPrintf(p, "%z, %z", zSql, zPk);
158543 }
158544 }
158545
158546 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158547 otaMPrintfExec(p, p->dbMain, "CREATE TABLE \"ota_imp_%w\"(%z)%s",
158548 pIter->zTbl, zSql,
158549 (pIter->eType==OTA_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
158550 );
158551 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158552 }
158553 }
158554
158555 /*
158556 ** Prepare a statement used to insert rows into the "ota_tmp_xxx" table.
158557 ** Specifically a statement of the form:
158558 **
158559 ** INSERT INTO ota_tmp_xxx VALUES(?, ?, ? ...);
158560 **
158561 ** The number of bound variables is equal to the number of columns in
158562 ** the target table, plus one (for the ota_control column), plus one more
158563 ** (for the ota_rowid column) if the target table is an implicit IPK or
158564 ** virtual table.
158565 */
158566 static void otaObjIterPrepareTmpInsert(
158567 sqlite3ota *p,
158568 OtaObjIter *pIter,
158569 const char *zCollist,
158570 const char *zOtaRowid
158571 ){
158572 int bOtaRowid = (pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE);
158573 char *zBind = otaObjIterGetBindlist(p, pIter->nTblCol + 1 + bOtaRowid);
158574 if( zBind ){
158575 assert( pIter->pTmpInsert==0 );
158576 p->rc = prepareFreeAndCollectError(
158577 p->dbOta, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
158578 "INSERT INTO %s.'ota_tmp_%q'(ota_control,%s%s) VALUES(%z)",
158579 p->zStateDb, pIter->zTbl, zCollist, zOtaRowid, zBind
158580 ));
158581 }
158582 }
158583
158584 static void otaTmpInsertFunc(
158585 sqlite3_context *pCtx,
158586 int nVal,
158587 sqlite3_value **apVal
158588 ){
158589 sqlite3ota *p = sqlite3_user_data(pCtx);
158590 int rc = SQLITE_OK;
158591 int i;
158592
158593 for(i=0; rc==SQLITE_OK && i<nVal; i++){
158594 rc = sqlite3_bind_value(p->objiter.pTmpInsert, i+1, apVal[i]);
@@ -158606,17 +158851,17 @@
158606 /*
158607 ** Ensure that the SQLite statement handles required to update the
158608 ** target database object currently indicated by the iterator passed
158609 ** as the second argument are available.
158610 */
158611 static int otaObjIterPrepareAll(
158612 sqlite3ota *p,
158613 OtaObjIter *pIter,
158614 int nOffset /* Add "LIMIT -1 OFFSET $nOffset" to SELECT */
158615 ){
158616 assert( pIter->bCleanup==0 );
158617 if( pIter->pSelect==0 && otaObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
158618 const int tnum = pIter->iTnum;
158619 char *zCollist = 0; /* List of indexed columns */
158620 char **pz = &p->zErrmsg;
158621 const char *zIdx = pIter->zIdx;
158622 char *zLimit = 0;
@@ -158632,104 +158877,104 @@
158632 char *zImposterPK = 0; /* Primary key declaration for imposter */
158633 char *zWhere = 0; /* WHERE clause on PK columns */
158634 char *zBind = 0;
158635 int nBind = 0;
158636
158637 assert( pIter->eType!=OTA_PK_VTAB );
158638 zCollist = otaObjIterGetIndexCols(
158639 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
158640 );
158641 zBind = otaObjIterGetBindlist(p, nBind);
158642
158643 /* Create the imposter table used to write to this index. */
158644 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
158645 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
158646 otaMPrintfExec(p, p->dbMain,
158647 "CREATE TABLE \"ota_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID",
158648 zTbl, zImposterCols, zImposterPK
158649 );
158650 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158651
158652 /* Create the statement to insert index entries */
158653 pIter->nCol = nBind;
158654 if( p->rc==SQLITE_OK ){
158655 p->rc = prepareFreeAndCollectError(
158656 p->dbMain, &pIter->pInsert, &p->zErrmsg,
158657 sqlite3_mprintf("INSERT INTO \"ota_imp_%w\" VALUES(%s)", zTbl, zBind)
158658 );
158659 }
158660
158661 /* And to delete index entries */
158662 if( p->rc==SQLITE_OK ){
158663 p->rc = prepareFreeAndCollectError(
158664 p->dbMain, &pIter->pDelete, &p->zErrmsg,
158665 sqlite3_mprintf("DELETE FROM \"ota_imp_%w\" WHERE %s", zTbl, zWhere)
158666 );
158667 }
158668
158669 /* Create the SELECT statement to read keys in sorted order */
158670 if( p->rc==SQLITE_OK ){
158671 char *zSql;
158672 if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158673 zSql = sqlite3_mprintf(
158674 "SELECT %s, ota_control FROM %s.'ota_tmp_%q' ORDER BY %s%s",
158675 zCollist, p->zStateDb, pIter->zTbl,
158676 zCollist, zLimit
158677 );
158678 }else{
158679 zSql = sqlite3_mprintf(
158680 "SELECT %s, ota_control FROM 'data_%q' "
158681 "WHERE typeof(ota_control)='integer' AND ota_control!=1 "
158682 "UNION ALL "
158683 "SELECT %s, ota_control FROM %s.'ota_tmp_%q' "
158684 "ORDER BY %s%s",
158685 zCollist, pIter->zTbl,
158686 zCollist, p->zStateDb, pIter->zTbl,
158687 zCollist, zLimit
158688 );
158689 }
158690 p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz, zSql);
158691 }
158692
158693 sqlite3_free(zImposterCols);
158694 sqlite3_free(zImposterPK);
158695 sqlite3_free(zWhere);
158696 sqlite3_free(zBind);
158697 }else{
158698 int bOtaRowid = (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE);
158699 const char *zTbl = pIter->zTbl; /* Table this step applies to */
158700 const char *zWrite; /* Imposter table name */
158701
158702 char *zBindings = otaObjIterGetBindlist(p, pIter->nTblCol + bOtaRowid);
158703 char *zWhere = otaObjIterGetWhere(p, pIter);
158704 char *zOldlist = otaObjIterGetOldlist(p, pIter, "old");
158705 char *zNewlist = otaObjIterGetOldlist(p, pIter, "new");
158706
158707 zCollist = otaObjIterGetCollist(p, pIter);
158708 pIter->nCol = pIter->nTblCol;
158709
158710 /* Create the SELECT statement to read keys from data_xxx */
158711 if( p->rc==SQLITE_OK ){
158712 p->rc = prepareFreeAndCollectError(p->dbOta, &pIter->pSelect, pz,
158713 sqlite3_mprintf(
158714 "SELECT %s, ota_control%s FROM 'data_%q'%s",
158715 zCollist, (bOtaRowid ? ", ota_rowid" : ""), zTbl, zLimit
158716 )
158717 );
158718 }
158719
158720 /* Create the imposter table or tables (if required). */
158721 otaCreateImposterTable(p, pIter);
158722 otaCreateImposterTable2(p, pIter);
158723 zWrite = (pIter->eType==OTA_PK_VTAB ? "" : "ota_imp_");
158724
158725 /* Create the INSERT statement to write to the target PK b-tree */
158726 if( p->rc==SQLITE_OK ){
158727 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz,
158728 sqlite3_mprintf(
158729 "INSERT INTO \"%s%w\"(%s%s) VALUES(%s)",
158730 zWrite, zTbl, zCollist, (bOtaRowid ? ", _rowid_" : ""), zBindings
158731 )
158732 );
158733 }
158734
158735 /* Create the DELETE statement to write to the target PK b-tree */
@@ -158740,55 +158985,55 @@
158740 )
158741 );
158742 }
158743
158744 if( pIter->abIndexed ){
158745 const char *zOtaRowid = "";
158746 if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158747 zOtaRowid = ", ota_rowid";
158748 }
158749
158750 /* Create the ota_tmp_xxx table and the triggers to populate it. */
158751 otaMPrintfExec(p, p->dbOta,
158752 "CREATE TABLE IF NOT EXISTS %s.'ota_tmp_%q' AS "
158753 "SELECT *%s FROM 'data_%q' WHERE 0;"
158754 , p->zStateDb
158755 , zTbl, (pIter->eType==OTA_PK_EXTERNAL ? ", 0 AS ota_rowid" : "")
158756 , zTbl
158757 );
158758
158759 otaMPrintfExec(p, p->dbMain,
158760 "CREATE TEMP TRIGGER ota_delete_tr BEFORE DELETE ON \"%s%w\" "
158761 "BEGIN "
158762 " SELECT ota_tmp_insert(2, %s);"
158763 "END;"
158764
158765 "CREATE TEMP TRIGGER ota_update1_tr BEFORE UPDATE ON \"%s%w\" "
158766 "BEGIN "
158767 " SELECT ota_tmp_insert(2, %s);"
158768 "END;"
158769
158770 "CREATE TEMP TRIGGER ota_update2_tr AFTER UPDATE ON \"%s%w\" "
158771 "BEGIN "
158772 " SELECT ota_tmp_insert(3, %s);"
158773 "END;",
158774 zWrite, zTbl, zOldlist,
158775 zWrite, zTbl, zOldlist,
158776 zWrite, zTbl, zNewlist
158777 );
158778
158779 if( pIter->eType==OTA_PK_EXTERNAL || pIter->eType==OTA_PK_NONE ){
158780 otaMPrintfExec(p, p->dbMain,
158781 "CREATE TEMP TRIGGER ota_insert_tr AFTER INSERT ON \"%s%w\" "
158782 "BEGIN "
158783 " SELECT ota_tmp_insert(0, %s);"
158784 "END;",
158785 zWrite, zTbl, zNewlist
158786 );
158787 }
158788
158789 otaObjIterPrepareTmpInsert(p, pIter, zCollist, zOtaRowid);
158790 }
158791
158792 sqlite3_free(zWhere);
158793 sqlite3_free(zOldlist);
158794 sqlite3_free(zNewlist);
@@ -158803,68 +159048,68 @@
158803
158804 /*
158805 ** Set output variable *ppStmt to point to an UPDATE statement that may
158806 ** be used to update the imposter table for the main table b-tree of the
158807 ** table object that pIter currently points to, assuming that the
158808 ** ota_control column of the data_xyz table contains zMask.
158809 **
158810 ** If the zMask string does not specify any columns to update, then this
158811 ** is not an error. Output variable *ppStmt is set to NULL in this case.
158812 */
158813 static int otaGetUpdateStmt(
158814 sqlite3ota *p, /* OTA handle */
158815 OtaObjIter *pIter, /* Object iterator */
158816 const char *zMask, /* ota_control value ('x.x.') */
158817 sqlite3_stmt **ppStmt /* OUT: UPDATE statement handle */
158818 ){
158819 OtaUpdateStmt **pp;
158820 OtaUpdateStmt *pUp = 0;
158821 int nUp = 0;
158822
158823 /* In case an error occurs */
158824 *ppStmt = 0;
158825
158826 /* Search for an existing statement. If one is found, shift it to the front
158827 ** of the LRU queue and return immediately. Otherwise, leave nUp pointing
158828 ** to the number of statements currently in the cache and pUp to the
158829 ** last object in the list. */
158830 for(pp=&pIter->pOtaUpdate; *pp; pp=&((*pp)->pNext)){
158831 pUp = *pp;
158832 if( strcmp(pUp->zMask, zMask)==0 ){
158833 *pp = pUp->pNext;
158834 pUp->pNext = pIter->pOtaUpdate;
158835 pIter->pOtaUpdate = pUp;
158836 *ppStmt = pUp->pUpdate;
158837 return SQLITE_OK;
158838 }
158839 nUp++;
158840 }
158841 assert( pUp==0 || pUp->pNext==0 );
158842
158843 if( nUp>=SQLITE_OTA_UPDATE_CACHESIZE ){
158844 for(pp=&pIter->pOtaUpdate; *pp!=pUp; pp=&((*pp)->pNext));
158845 *pp = 0;
158846 sqlite3_finalize(pUp->pUpdate);
158847 pUp->pUpdate = 0;
158848 }else{
158849 pUp = (OtaUpdateStmt*)otaMalloc(p, sizeof(OtaUpdateStmt)+pIter->nTblCol+1);
158850 }
158851
158852 if( pUp ){
158853 char *zWhere = otaObjIterGetWhere(p, pIter);
158854 char *zSet = otaObjIterGetSetlist(p, pIter, zMask);
158855 char *zUpdate = 0;
158856
158857 pUp->zMask = (char*)&pUp[1];
158858 memcpy(pUp->zMask, zMask, pIter->nTblCol);
158859 pUp->pNext = pIter->pOtaUpdate;
158860 pIter->pOtaUpdate = pUp;
158861
158862 if( zSet ){
158863 const char *zPrefix = "";
158864
158865 if( pIter->eType!=OTA_PK_VTAB ) zPrefix = "ota_imp_";
158866 zUpdate = sqlite3_mprintf("UPDATE \"%s%w\" SET %s WHERE %s",
158867 zPrefix, pIter->zTbl, zSet, zWhere
158868 );
158869 p->rc = prepareFreeAndCollectError(
158870 p->dbMain, &pUp->pUpdate, &p->zErrmsg, zUpdate
@@ -158876,11 +159121,11 @@
158876 }
158877
158878 return p->rc;
158879 }
158880
158881 static sqlite3 *otaOpenDbhandle(sqlite3ota *p, const char *zName){
158882 sqlite3 *db = 0;
158883 if( p->rc==SQLITE_OK ){
158884 const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
158885 p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
158886 if( p->rc ){
@@ -158891,51 +159136,51 @@
158891 }
158892 return db;
158893 }
158894
158895 /*
158896 ** Open the database handle and attach the OTA database as "ota". If an
158897 ** error occurs, leave an error code and message in the OTA handle.
158898 */
158899 static void otaOpenDatabase(sqlite3ota *p){
158900 assert( p->rc==SQLITE_OK );
158901 assert( p->dbMain==0 && p->dbOta==0 );
158902
158903 p->eStage = 0;
158904 p->dbMain = otaOpenDbhandle(p, p->zTarget);
158905 p->dbOta = otaOpenDbhandle(p, p->zOta);
158906
158907 /* If using separate OTA and state databases, attach the state database to
158908 ** the OTA db handle now. */
158909 if( p->zState ){
158910 otaMPrintfExec(p, p->dbOta, "ATTACH %Q AS stat", p->zState);
158911 memcpy(p->zStateDb, "stat", 4);
158912 }else{
158913 memcpy(p->zStateDb, "main", 4);
158914 }
158915
158916 if( p->rc==SQLITE_OK ){
158917 p->rc = sqlite3_create_function(p->dbMain,
158918 "ota_tmp_insert", -1, SQLITE_UTF8, (void*)p, otaTmpInsertFunc, 0, 0
158919 );
158920 }
158921
158922 if( p->rc==SQLITE_OK ){
158923 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p);
158924 }
158925 otaMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
158926
158927 /* Mark the database file just opened as an OTA target database. If
158928 ** this call returns SQLITE_NOTFOUND, then the OTA vfs is not in use.
158929 ** This is an error. */
158930 if( p->rc==SQLITE_OK ){
158931 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_OTA, (void*)p);
158932 }
158933
158934 if( p->rc==SQLITE_NOTFOUND ){
158935 p->rc = SQLITE_ERROR;
158936 p->zErrmsg = sqlite3_mprintf("ota vfs not found");
158937 }
158938 }
158939
158940 /*
158941 ** This routine is a copy of the sqlite3FileSuffix3() routine from the core.
@@ -158955,11 +159200,11 @@
158955 ** test.db-journal => test.nal
158956 ** test.db-wal => test.wal
158957 ** test.db-shm => test.shm
158958 ** test.db-mj7f3319fa => test.9fa
158959 */
158960 static void otaFileSuffix3(const char *zBase, char *z){
158961 #ifdef SQLITE_ENABLE_8_3_NAMES
158962 #if SQLITE_ENABLE_8_3_NAMES<2
158963 if( sqlite3_uri_boolean(zBase, "8_3_names", 0) )
158964 #endif
158965 {
@@ -158976,11 +159221,11 @@
158976 ** as a 64-bit integer.
158977 **
158978 ** The checksum is store in the first page of xShmMap memory as an 8-byte
158979 ** blob starting at byte offset 40.
158980 */
158981 static i64 otaShmChecksum(sqlite3ota *p){
158982 i64 iRet = 0;
158983 if( p->rc==SQLITE_OK ){
158984 sqlite3_file *pDb = p->pTargetFd->pReal;
158985 u32 volatile *ptr;
158986 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
@@ -158993,23 +159238,23 @@
158993
158994 /*
158995 ** This function is called as part of initializing or reinitializing an
158996 ** incremental checkpoint.
158997 **
158998 ** It populates the sqlite3ota.aFrame[] array with the set of
158999 ** (wal frame -> db page) copy operations required to checkpoint the
159000 ** current wal file, and obtains the set of shm locks required to safely
159001 ** perform the copy operations directly on the file-system.
159002 **
159003 ** If argument pState is not NULL, then the incremental checkpoint is
159004 ** being resumed. In this case, if the checksum of the wal-index-header
159005 ** following recovery is not the same as the checksum saved in the OtaState
159006 ** object, then the ota handle is set to DONE state. This occurs if some
159007 ** other client appends a transaction to the wal file in the middle of
159008 ** an incremental checkpoint.
159009 */
159010 static void otaSetupCheckpoint(sqlite3ota *p, OtaState *pState){
159011
159012 /* If pState is NULL, then the wal file may not have been opened and
159013 ** recovered. Running a read-statement here to ensure that doing so
159014 ** does not interfere with the "capture" process below. */
159015 if( pState==0 ){
@@ -159018,20 +159263,20 @@
159018 p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0);
159019 }
159020 }
159021
159022 /* Assuming no error has occurred, run a "restart" checkpoint with the
159023 ** sqlite3ota.eStage variable set to CAPTURE. This turns on the following
159024 ** special behaviour in the ota VFS:
159025 **
159026 ** * If the exclusive shm WRITER or READ0 lock cannot be obtained,
159027 ** the checkpoint fails with SQLITE_BUSY (normally SQLite would
159028 ** proceed with running a passive checkpoint instead of failing).
159029 **
159030 ** * Attempts to read from the *-wal file or write to the database file
159031 ** do not perform any IO. Instead, the frame/page combinations that
159032 ** would be read/written are recorded in the sqlite3ota.aFrame[]
159033 ** array.
159034 **
159035 ** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
159036 ** READ0 and CHECKPOINT locks taken as part of the checkpoint are
159037 ** no-ops. These locks will not be released until the connection
@@ -159047,76 +159292,76 @@
159047 ** data from the wal file into the database file according to the
159048 ** contents of aFrame[].
159049 */
159050 if( p->rc==SQLITE_OK ){
159051 int rc2;
159052 p->eStage = OTA_STAGE_CAPTURE;
159053 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
159054 if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
159055 }
159056
159057 if( p->rc==SQLITE_OK ){
159058 p->eStage = OTA_STAGE_CKPT;
159059 p->nStep = (pState ? pState->nRow : 0);
159060 p->aBuf = otaMalloc(p, p->pgsz);
159061 p->iWalCksum = otaShmChecksum(p);
159062 }
159063
159064 if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
159065 p->rc = SQLITE_DONE;
159066 p->eStage = OTA_STAGE_DONE;
159067 }
159068 }
159069
159070 /*
159071 ** Called when iAmt bytes are read from offset iOff of the wal file while
159072 ** the ota object is in capture mode. Record the frame number of the frame
159073 ** being read in the aFrame[] array.
159074 */
159075 static int otaCaptureWalRead(sqlite3ota *pOta, i64 iOff, int iAmt){
159076 const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0);
159077 u32 iFrame;
159078
159079 if( pOta->mLock!=mReq ){
159080 pOta->rc = SQLITE_BUSY;
159081 return SQLITE_INTERNAL;
159082 }
159083
159084 pOta->pgsz = iAmt;
159085 if( pOta->nFrame==pOta->nFrameAlloc ){
159086 int nNew = (pOta->nFrameAlloc ? pOta->nFrameAlloc : 64) * 2;
159087 OtaFrame *aNew;
159088 aNew = (OtaFrame*)sqlite3_realloc(pOta->aFrame, nNew * sizeof(OtaFrame));
159089 if( aNew==0 ) return SQLITE_NOMEM;
159090 pOta->aFrame = aNew;
159091 pOta->nFrameAlloc = nNew;
159092 }
159093
159094 iFrame = (u32)((iOff-32) / (i64)(iAmt+24)) + 1;
159095 if( pOta->iMaxFrame<iFrame ) pOta->iMaxFrame = iFrame;
159096 pOta->aFrame[pOta->nFrame].iWalFrame = iFrame;
159097 pOta->aFrame[pOta->nFrame].iDbPage = 0;
159098 pOta->nFrame++;
159099 return SQLITE_OK;
159100 }
159101
159102 /*
159103 ** Called when a page of data is written to offset iOff of the database
159104 ** file while the ota handle is in capture mode. Record the page number
159105 ** of the page being written in the aFrame[] array.
159106 */
159107 static int otaCaptureDbWrite(sqlite3ota *pOta, i64 iOff){
159108 pOta->aFrame[pOta->nFrame-1].iDbPage = (u32)(iOff / pOta->pgsz) + 1;
159109 return SQLITE_OK;
159110 }
159111
159112 /*
159113 ** This is called as part of an incremental checkpoint operation. Copy
159114 ** a single frame of data from the wal file into the database file, as
159115 ** indicated by the OtaFrame object.
159116 */
159117 static void otaCheckpointFrame(sqlite3ota *p, OtaFrame *pFrame){
159118 sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal;
159119 sqlite3_file *pDb = p->pTargetFd->pReal;
159120 i64 iOff;
159121
159122 assert( p->rc==SQLITE_OK );
@@ -159130,33 +159375,33 @@
159130
159131
159132 /*
159133 ** Take an EXCLUSIVE lock on the database file.
159134 */
159135 static void otaLockDatabase(sqlite3ota *p){
159136 sqlite3_file *pReal = p->pTargetFd->pReal;
159137 assert( p->rc==SQLITE_OK );
159138 p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED);
159139 if( p->rc==SQLITE_OK ){
159140 p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE);
159141 }
159142 }
159143
159144 /*
159145 ** The OTA handle is currently in OTA_STAGE_OAL state, with a SHARED lock
159146 ** on the database file. This proc moves the *-oal file to the *-wal path,
159147 ** then reopens the database file (this time in vanilla, non-oal, WAL mode).
159148 ** If an error occurs, leave an error code and error message in the ota
159149 ** handle.
159150 */
159151 static void otaMoveOalFile(sqlite3ota *p){
159152 const char *zBase = sqlite3_db_filename(p->dbMain, "main");
159153
159154 char *zWal = sqlite3_mprintf("%s-wal", zBase);
159155 char *zOal = sqlite3_mprintf("%s-oal", zBase);
159156
159157 assert( p->eStage==OTA_STAGE_MOVE );
159158 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159159 if( zWal==0 || zOal==0 ){
159160 p->rc = SQLITE_NOMEM;
159161 }else{
159162 /* Move the *-oal file to *-wal. At this point connection p->db is
@@ -159164,25 +159409,25 @@
159164 ** in WAL mode). So no other connection may be writing the db.
159165 **
159166 ** In order to ensure that there are no database readers, an EXCLUSIVE
159167 ** lock is obtained here before the *-oal is moved to *-wal.
159168 */
159169 otaLockDatabase(p);
159170 if( p->rc==SQLITE_OK ){
159171 otaFileSuffix3(zBase, zWal);
159172 otaFileSuffix3(zBase, zOal);
159173
159174 /* Re-open the databases. */
159175 otaObjIterFinalize(&p->objiter);
159176 sqlite3_close(p->dbMain);
159177 sqlite3_close(p->dbOta);
159178 p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
159179 if( p->rc==SQLITE_OK ){
159180 p->dbMain = 0;
159181 p->dbOta = 0;
159182 otaOpenDatabase(p);
159183 otaSetupCheckpoint(p, 0);
159184 }
159185 }
159186 }
159187
159188 sqlite3_free(zWal);
@@ -159193,36 +159438,36 @@
159193 ** The SELECT statement iterating through the keys for the current object
159194 ** (p->objiter.pSelect) currently points to a valid row. This function
159195 ** determines the type of operation requested by this row and returns
159196 ** one of the following values to indicate the result:
159197 **
159198 ** * OTA_INSERT
159199 ** * OTA_DELETE
159200 ** * OTA_IDX_DELETE
159201 ** * OTA_UPDATE
159202 **
159203 ** If OTA_UPDATE is returned, then output variable *pzMask is set to
159204 ** point to the text value indicating the columns to update.
159205 **
159206 ** If the ota_control field contains an invalid value, an error code and
159207 ** message are left in the OTA handle and zero returned.
159208 */
159209 static int otaStepType(sqlite3ota *p, const char **pzMask){
159210 int iCol = p->objiter.nCol; /* Index of ota_control column */
159211 int res = 0; /* Return value */
159212
159213 switch( sqlite3_column_type(p->objiter.pSelect, iCol) ){
159214 case SQLITE_INTEGER: {
159215 int iVal = sqlite3_column_int(p->objiter.pSelect, iCol);
159216 if( iVal==0 ){
159217 res = OTA_INSERT;
159218 }else if( iVal==1 ){
159219 res = OTA_DELETE;
159220 }else if( iVal==2 ){
159221 res = OTA_IDX_DELETE;
159222 }else if( iVal==3 ){
159223 res = OTA_IDX_INSERT;
159224 }
159225 break;
159226 }
159227
159228 case SQLITE_TEXT: {
@@ -159230,21 +159475,21 @@
159230 if( z==0 ){
159231 p->rc = SQLITE_NOMEM;
159232 }else{
159233 *pzMask = (const char*)z;
159234 }
159235 res = OTA_UPDATE;
159236
159237 break;
159238 }
159239
159240 default:
159241 break;
159242 }
159243
159244 if( res==0 ){
159245 otaBadControlError(p);
159246 }
159247 return res;
159248 }
159249
159250 #ifdef SQLITE_DEBUG
@@ -159258,82 +159503,82 @@
159258 #else
159259 # define assertColumnName(x,y,z)
159260 #endif
159261
159262 /*
159263 ** This function does the work for an sqlite3ota_step() call.
159264 **
159265 ** The object-iterator (p->objiter) currently points to a valid object,
159266 ** and the input cursor (p->objiter.pSelect) currently points to a valid
159267 ** input row. Perform whatever processing is required and return.
159268 **
159269 ** If no error occurs, SQLITE_OK is returned. Otherwise, an error code
159270 ** and message is left in the OTA handle and a copy of the error code
159271 ** returned.
159272 */
159273 static int otaStep(sqlite3ota *p){
159274 OtaObjIter *pIter = &p->objiter;
159275 const char *zMask = 0;
159276 int i;
159277 int eType = otaStepType(p, &zMask);
159278
159279 if( eType ){
159280 assert( eType!=OTA_UPDATE || pIter->zIdx==0 );
159281
159282 if( pIter->zIdx==0 && eType==OTA_IDX_DELETE ){
159283 otaBadControlError(p);
159284 }
159285 else if(
159286 eType==OTA_INSERT
159287 || eType==OTA_DELETE
159288 || eType==OTA_IDX_DELETE
159289 || eType==OTA_IDX_INSERT
159290 ){
159291 sqlite3_value *pVal;
159292 sqlite3_stmt *pWriter;
159293
159294 assert( eType!=OTA_UPDATE );
159295 assert( eType!=OTA_DELETE || pIter->zIdx==0 );
159296
159297 if( eType==OTA_IDX_DELETE || eType==OTA_DELETE ){
159298 pWriter = pIter->pDelete;
159299 }else{
159300 pWriter = pIter->pInsert;
159301 }
159302
159303 for(i=0; i<pIter->nCol; i++){
159304 /* If this is an INSERT into a table b-tree and the table has an
159305 ** explicit INTEGER PRIMARY KEY, check that this is not an attempt
159306 ** to write a NULL into the IPK column. That is not permitted. */
159307 if( eType==OTA_INSERT
159308 && pIter->zIdx==0 && pIter->eType==OTA_PK_IPK && pIter->abTblPk[i]
159309 && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL
159310 ){
159311 p->rc = SQLITE_MISMATCH;
159312 p->zErrmsg = sqlite3_mprintf("datatype mismatch");
159313 goto step_out;
159314 }
159315
159316 if( eType==OTA_DELETE && pIter->abTblPk[i]==0 ){
159317 continue;
159318 }
159319
159320 pVal = sqlite3_column_value(pIter->pSelect, i);
159321 p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
159322 if( p->rc ) goto step_out;
159323 }
159324 if( pIter->zIdx==0
159325 && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE)
159326 ){
159327 /* For a virtual table, or a table with no primary key, the
159328 ** SELECT statement is:
159329 **
159330 ** SELECT <cols>, ota_control, ota_rowid FROM ....
159331 **
159332 ** Hence column_value(pIter->nCol+1).
159333 */
159334 assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid");
159335 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159336 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
159337 }
159338 if( p->rc==SQLITE_OK ){
159339 sqlite3_step(pWriter);
@@ -159340,25 +159585,25 @@
159340 p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
159341 }
159342 }else{
159343 sqlite3_value *pVal;
159344 sqlite3_stmt *pUpdate = 0;
159345 assert( eType==OTA_UPDATE );
159346 otaGetUpdateStmt(p, pIter, zMask, &pUpdate);
159347 if( pUpdate ){
159348 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
159349 char c = zMask[pIter->aiSrcOrder[i]];
159350 pVal = sqlite3_column_value(pIter->pSelect, i);
159351 if( pIter->abTblPk[i] || c=='x' || c=='d' ){
159352 p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
159353 }
159354 }
159355 if( p->rc==SQLITE_OK
159356 && (pIter->eType==OTA_PK_VTAB || pIter->eType==OTA_PK_NONE)
159357 ){
159358 /* Bind the ota_rowid value to column _rowid_ */
159359 assertColumnName(pIter->pSelect, pIter->nCol+1, "ota_rowid");
159360 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159361 p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal);
159362 }
159363 if( p->rc==SQLITE_OK ){
159364 sqlite3_step(pUpdate);
@@ -159373,11 +159618,11 @@
159373 }
159374
159375 /*
159376 ** Increment the schema cookie of the main database opened by p->dbMain.
159377 */
159378 static void otaIncrSchemaCookie(sqlite3ota *p){
159379 if( p->rc==SQLITE_OK ){
159380 int iCookie = 1000000;
159381 sqlite3_stmt *pStmt;
159382
159383 p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
@@ -159390,49 +159635,49 @@
159390 ** statement reads is page 1, which is guaranteed to be in the cache.
159391 ** And no memory allocations are required. */
159392 if( SQLITE_ROW==sqlite3_step(pStmt) ){
159393 iCookie = sqlite3_column_int(pStmt, 0);
159394 }
159395 otaFinalize(p, pStmt);
159396 }
159397 if( p->rc==SQLITE_OK ){
159398 otaMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1);
159399 }
159400 }
159401 }
159402
159403 /*
159404 ** Update the contents of the ota_state table within the ota database. The
159405 ** value stored in the OTA_STATE_STAGE column is eStage. All other values
159406 ** are determined by inspecting the ota handle passed as the first argument.
159407 */
159408 static void otaSaveState(sqlite3ota *p, int eStage){
159409 if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
159410 sqlite3_stmt *pInsert = 0;
159411 int rc;
159412
159413 assert( p->zErrmsg==0 );
159414 rc = prepareFreeAndCollectError(p->dbOta, &pInsert, &p->zErrmsg,
159415 sqlite3_mprintf(
159416 "INSERT OR REPLACE INTO %s.ota_state(k, v) VALUES "
159417 "(%d, %d), "
159418 "(%d, %Q), "
159419 "(%d, %Q), "
159420 "(%d, %d), "
159421 "(%d, %d), "
159422 "(%d, %lld), "
159423 "(%d, %lld), "
159424 "(%d, %lld) ",
159425 p->zStateDb,
159426 OTA_STATE_STAGE, eStage,
159427 OTA_STATE_TBL, p->objiter.zTbl,
159428 OTA_STATE_IDX, p->objiter.zIdx,
159429 OTA_STATE_ROW, p->nStep,
159430 OTA_STATE_PROGRESS, p->nProgress,
159431 OTA_STATE_CKPT, p->iWalCksum,
159432 OTA_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
159433 OTA_STATE_OALSZ, p->iOalSz
159434 )
159435 );
159436 assert( pInsert==0 || rc==SQLITE_OK );
159437
159438 if( rc==SQLITE_OK ){
@@ -159443,71 +159688,71 @@
159443 }
159444 }
159445
159446
159447 /*
159448 ** Step the OTA object.
159449 */
159450 SQLITE_API int SQLITE_STDCALL sqlite3ota_step(sqlite3ota *p){
159451 if( p ){
159452 switch( p->eStage ){
159453 case OTA_STAGE_OAL: {
159454 OtaObjIter *pIter = &p->objiter;
159455 while( p->rc==SQLITE_OK && pIter->zTbl ){
159456
159457 if( pIter->bCleanup ){
159458 /* Clean up the ota_tmp_xxx table for the previous table. It
159459 ** cannot be dropped as there are currently active SQL statements.
159460 ** But the contents can be deleted. */
159461 if( pIter->abIndexed ){
159462 otaMPrintfExec(p, p->dbOta,
159463 "DELETE FROM %s.'ota_tmp_%q'", p->zStateDb, pIter->zTbl
159464 );
159465 }
159466 }else{
159467 otaObjIterPrepareAll(p, pIter, 0);
159468
159469 /* Advance to the next row to process. */
159470 if( p->rc==SQLITE_OK ){
159471 int rc = sqlite3_step(pIter->pSelect);
159472 if( rc==SQLITE_ROW ){
159473 p->nProgress++;
159474 p->nStep++;
159475 return otaStep(p);
159476 }
159477 p->rc = sqlite3_reset(pIter->pSelect);
159478 p->nStep = 0;
159479 }
159480 }
159481
159482 otaObjIterNext(p, pIter);
159483 }
159484
159485 if( p->rc==SQLITE_OK ){
159486 assert( pIter->zTbl==0 );
159487 otaSaveState(p, OTA_STAGE_MOVE);
159488 otaIncrSchemaCookie(p);
159489 if( p->rc==SQLITE_OK ){
159490 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
159491 }
159492 if( p->rc==SQLITE_OK ){
159493 p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg);
159494 }
159495 p->eStage = OTA_STAGE_MOVE;
159496 }
159497 break;
159498 }
159499
159500 case OTA_STAGE_MOVE: {
159501 if( p->rc==SQLITE_OK ){
159502 otaMoveOalFile(p);
159503 p->nProgress++;
159504 }
159505 break;
159506 }
159507
159508 case OTA_STAGE_CKPT: {
159509 if( p->rc==SQLITE_OK ){
159510 if( p->nStep>=p->nFrame ){
159511 sqlite3_file *pDb = p->pTargetFd->pReal;
159512
159513 /* Sync the db file */
@@ -159521,16 +159766,16 @@
159521 ((u32 volatile*)ptr)[24] = p->iMaxFrame;
159522 }
159523 }
159524
159525 if( p->rc==SQLITE_OK ){
159526 p->eStage = OTA_STAGE_DONE;
159527 p->rc = SQLITE_DONE;
159528 }
159529 }else{
159530 OtaFrame *pFrame = &p->aFrame[p->nStep];
159531 otaCheckpointFrame(p, pFrame);
159532 p->nStep++;
159533 }
159534 p->nProgress++;
159535 }
159536 break;
@@ -159544,78 +159789,78 @@
159544 return SQLITE_NOMEM;
159545 }
159546 }
159547
159548 /*
159549 ** Free an OtaState object allocated by otaLoadState().
159550 */
159551 static void otaFreeState(OtaState *p){
159552 if( p ){
159553 sqlite3_free(p->zTbl);
159554 sqlite3_free(p->zIdx);
159555 sqlite3_free(p);
159556 }
159557 }
159558
159559 /*
159560 ** Allocate an OtaState object and load the contents of the ota_state
159561 ** table into it. Return a pointer to the new object. It is the
159562 ** responsibility of the caller to eventually free the object using
159563 ** sqlite3_free().
159564 **
159565 ** If an error occurs, leave an error code and message in the ota handle
159566 ** and return NULL.
159567 */
159568 static OtaState *otaLoadState(sqlite3ota *p){
159569 OtaState *pRet = 0;
159570 sqlite3_stmt *pStmt = 0;
159571 int rc;
159572 int rc2;
159573
159574 pRet = (OtaState*)otaMalloc(p, sizeof(OtaState));
159575 if( pRet==0 ) return 0;
159576
159577 rc = prepareFreeAndCollectError(p->dbOta, &pStmt, &p->zErrmsg,
159578 sqlite3_mprintf("SELECT k, v FROM %s.ota_state", p->zStateDb)
159579 );
159580 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
159581 switch( sqlite3_column_int(pStmt, 0) ){
159582 case OTA_STATE_STAGE:
159583 pRet->eStage = sqlite3_column_int(pStmt, 1);
159584 if( pRet->eStage!=OTA_STAGE_OAL
159585 && pRet->eStage!=OTA_STAGE_MOVE
159586 && pRet->eStage!=OTA_STAGE_CKPT
159587 ){
159588 p->rc = SQLITE_CORRUPT;
159589 }
159590 break;
159591
159592 case OTA_STATE_TBL:
159593 pRet->zTbl = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159594 break;
159595
159596 case OTA_STATE_IDX:
159597 pRet->zIdx = otaStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159598 break;
159599
159600 case OTA_STATE_ROW:
159601 pRet->nRow = sqlite3_column_int(pStmt, 1);
159602 break;
159603
159604 case OTA_STATE_PROGRESS:
159605 pRet->nProgress = sqlite3_column_int64(pStmt, 1);
159606 break;
159607
159608 case OTA_STATE_CKPT:
159609 pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
159610 break;
159611
159612 case OTA_STATE_COOKIE:
159613 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
159614 break;
159615
159616 case OTA_STATE_OALSZ:
159617 pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
159618 break;
159619
159620 default:
159621 rc = SQLITE_CORRUPT;
@@ -159632,142 +159877,142 @@
159632 /*
159633 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
159634 ** otherwise. Either or both argument may be NULL. Two NULL values are
159635 ** considered equal, and NULL is considered distinct from all other values.
159636 */
159637 static int otaStrCompare(const char *z1, const char *z2){
159638 if( z1==0 && z2==0 ) return 0;
159639 if( z1==0 || z2==0 ) return 1;
159640 return (sqlite3_stricmp(z1, z2)!=0);
159641 }
159642
159643 /*
159644 ** This function is called as part of sqlite3ota_open() when initializing
159645 ** an ota handle in OAL stage. If the ota update has not started (i.e.
159646 ** the ota_state table was empty) it is a no-op. Otherwise, it arranges
159647 ** things so that the next call to sqlite3ota_step() continues on from
159648 ** where the previous ota handle left off.
159649 **
159650 ** If an error occurs, an error code and error message are left in the
159651 ** ota handle passed as the first argument.
159652 */
159653 static void otaSetupOal(sqlite3ota *p, OtaState *pState){
159654 assert( p->rc==SQLITE_OK );
159655 if( pState->zTbl ){
159656 OtaObjIter *pIter = &p->objiter;
159657 int rc = SQLITE_OK;
159658
159659 while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup
159660 || otaStrCompare(pIter->zIdx, pState->zIdx)
159661 || otaStrCompare(pIter->zTbl, pState->zTbl)
159662 )){
159663 rc = otaObjIterNext(p, pIter);
159664 }
159665
159666 if( rc==SQLITE_OK && !pIter->zTbl ){
159667 rc = SQLITE_ERROR;
159668 p->zErrmsg = sqlite3_mprintf("ota_state mismatch error");
159669 }
159670
159671 if( rc==SQLITE_OK ){
159672 p->nStep = pState->nRow;
159673 rc = otaObjIterPrepareAll(p, &p->objiter, p->nStep);
159674 }
159675
159676 p->rc = rc;
159677 }
159678 }
159679
159680 /*
159681 ** If there is a "*-oal" file in the file-system corresponding to the
159682 ** target database in the file-system, delete it. If an error occurs,
159683 ** leave an error code and error message in the ota handle.
159684 */
159685 static void otaDeleteOalFile(sqlite3ota *p){
159686 char *zOal = sqlite3_mprintf("%s-oal", p->zTarget);
159687 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159688 unlink(zOal);
159689 sqlite3_free(zOal);
159690 }
159691
159692 /*
159693 ** Allocate a private ota VFS for the ota handle passed as the only
159694 ** argument. This VFS will be used unless the call to sqlite3ota_open()
159695 ** specified a URI with a vfs=? option in place of a target database
159696 ** file name.
159697 */
159698 static void otaCreateVfs(sqlite3ota *p){
159699 int rnd;
159700 char zRnd[64];
159701
159702 assert( p->rc==SQLITE_OK );
159703 sqlite3_randomness(sizeof(int), (void*)&rnd);
159704 sprintf(zRnd, "ota_vfs_%d", rnd);
159705 p->rc = sqlite3ota_create_vfs(zRnd, 0);
159706 if( p->rc==SQLITE_OK ){
159707 sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd);
159708 assert( pVfs );
159709 p->zVfsName = pVfs->zName;
159710 }
159711 }
159712
159713 /*
159714 ** Destroy the private VFS created for the ota handle passed as the only
159715 ** argument by an earlier call to otaCreateVfs().
159716 */
159717 static void otaDeleteVfs(sqlite3ota *p){
159718 if( p->zVfsName ){
159719 sqlite3ota_destroy_vfs(p->zVfsName);
159720 p->zVfsName = 0;
159721 }
159722 }
159723
159724 /*
159725 ** Open and return a new OTA handle.
159726 */
159727 SQLITE_API sqlite3ota *SQLITE_STDCALL sqlite3ota_open(
159728 const char *zTarget,
159729 const char *zOta,
159730 const char *zState
159731 ){
159732 sqlite3ota *p;
159733 int nTarget = strlen(zTarget);
159734 int nOta = strlen(zOta);
159735 int nState = zState ? strlen(zState) : 0;
159736
159737 p = (sqlite3ota*)sqlite3_malloc(sizeof(sqlite3ota)+nTarget+1+nOta+1+nState+1);
159738 if( p ){
159739 OtaState *pState = 0;
159740
159741 /* Create the custom VFS. */
159742 memset(p, 0, sizeof(sqlite3ota));
159743 otaCreateVfs(p);
159744
159745 /* Open the target database */
159746 if( p->rc==SQLITE_OK ){
159747 p->zTarget = (char*)&p[1];
159748 memcpy(p->zTarget, zTarget, nTarget+1);
159749 p->zOta = &p->zTarget[nTarget+1];
159750 memcpy(p->zOta, zOta, nOta+1);
159751 if( zState ){
159752 p->zState = &p->zOta[nOta+1];
159753 memcpy(p->zState, zState, nState+1);
159754 }
159755 otaOpenDatabase(p);
159756 }
159757
159758 /* If it has not already been created, create the ota_state table */
159759 otaMPrintfExec(p, p->dbOta, OTA_CREATE_STATE, p->zStateDb);
159760
159761 if( p->rc==SQLITE_OK ){
159762 pState = otaLoadState(p);
159763 assert( pState || p->rc!=SQLITE_OK );
159764 if( p->rc==SQLITE_OK ){
159765
159766 if( pState->eStage==0 ){
159767 otaDeleteOalFile(p);
159768 p->eStage = OTA_STAGE_OAL;
159769 }else{
159770 p->eStage = pState->eStage;
159771 }
159772 p->nProgress = pState->nProgress;
159773 p->iOalSz = pState->iOalSz;
@@ -159774,97 +160019,97 @@
159774 }
159775 }
159776 assert( p->rc!=SQLITE_OK || p->eStage!=0 );
159777
159778 if( p->rc==SQLITE_OK && p->pTargetFd->pWalFd ){
159779 if( p->eStage==OTA_STAGE_OAL ){
159780 p->rc = SQLITE_ERROR;
159781 p->zErrmsg = sqlite3_mprintf("cannot update wal mode database");
159782 }else if( p->eStage==OTA_STAGE_MOVE ){
159783 p->eStage = OTA_STAGE_CKPT;
159784 p->nStep = 0;
159785 }
159786 }
159787
159788 if( p->rc==SQLITE_OK
159789 && (p->eStage==OTA_STAGE_OAL || p->eStage==OTA_STAGE_MOVE)
159790 && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
159791 ){
159792 /* At this point (pTargetFd->iCookie) contains the value of the
159793 ** change-counter cookie (the thing that gets incremented when a
159794 ** transaction is committed in rollback mode) currently stored on
159795 ** page 1 of the database file. */
159796 p->rc = SQLITE_BUSY;
159797 p->zErrmsg = sqlite3_mprintf("database modified during ota update");
159798 }
159799
159800 if( p->rc==SQLITE_OK ){
159801 if( p->eStage==OTA_STAGE_OAL ){
159802
159803 /* Open transactions both databases. The *-oal file is opened or
159804 ** created at this point. */
159805 p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
159806 if( p->rc==SQLITE_OK ){
159807 p->rc = sqlite3_exec(p->dbOta, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
159808 }
159809
159810 /* Point the object iterator at the first object */
159811 if( p->rc==SQLITE_OK ){
159812 p->rc = otaObjIterFirst(p, &p->objiter);
159813 }
159814
159815 /* If the OTA database contains no data_xxx tables, declare the OTA
159816 ** update finished. */
159817 if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
159818 p->rc = SQLITE_DONE;
159819 }
159820
159821 if( p->rc==SQLITE_OK ){
159822 otaSetupOal(p, pState);
159823 }
159824
159825 }else if( p->eStage==OTA_STAGE_MOVE ){
159826 /* no-op */
159827 }else if( p->eStage==OTA_STAGE_CKPT ){
159828 otaSetupCheckpoint(p, pState);
159829 }else if( p->eStage==OTA_STAGE_DONE ){
159830 p->rc = SQLITE_DONE;
159831 }else{
159832 p->rc = SQLITE_CORRUPT;
159833 }
159834 }
159835
159836 otaFreeState(pState);
159837 }
159838
159839 return p;
159840 }
159841
159842
159843 /*
159844 ** Return the database handle used by pOta.
159845 */
159846 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3ota_db(sqlite3ota *pOta, int bOta){
159847 sqlite3 *db = 0;
159848 if( pOta ){
159849 db = (bOta ? pOta->dbOta : pOta->dbMain);
159850 }
159851 return db;
159852 }
159853
159854
159855 /*
159856 ** If the error code currently stored in the OTA handle is SQLITE_CONSTRAINT,
159857 ** then edit any error message string so as to remove all occurrences of
159858 ** the pattern "ota_imp_[0-9]*".
159859 */
159860 static void otaEditErrmsg(sqlite3ota *p){
159861 if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
159862 int i;
159863 int nErrmsg = strlen(p->zErrmsg);
159864 for(i=0; i<(nErrmsg-8); i++){
159865 if( memcmp(&p->zErrmsg[i], "ota_imp_", 8)==0 ){
159866 int nDel = 8;
159867 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
159868 memmove(&p->zErrmsg[i], &p->zErrmsg[i+nDel], nErrmsg + 1 - i - nDel);
159869 nErrmsg -= nDel;
159870 }
@@ -159871,38 +160116,38 @@
159871 }
159872 }
159873 }
159874
159875 /*
159876 ** Close the OTA handle.
159877 */
159878 SQLITE_API int SQLITE_STDCALL sqlite3ota_close(sqlite3ota *p, char **pzErrmsg){
159879 int rc;
159880 if( p ){
159881
159882 /* Commit the transaction to the *-oal file. */
159883 if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){
159884 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
159885 }
159886
159887 otaSaveState(p, p->eStage);
159888
159889 if( p->rc==SQLITE_OK && p->eStage==OTA_STAGE_OAL ){
159890 p->rc = sqlite3_exec(p->dbOta, "COMMIT", 0, 0, &p->zErrmsg);
159891 }
159892
159893 /* Close any open statement handles. */
159894 otaObjIterFinalize(&p->objiter);
159895
159896 /* Close the open database handle and VFS object. */
159897 sqlite3_close(p->dbMain);
159898 sqlite3_close(p->dbOta);
159899 otaDeleteVfs(p);
159900 sqlite3_free(p->aBuf);
159901 sqlite3_free(p->aFrame);
159902
159903 otaEditErrmsg(p);
159904 rc = p->rc;
159905 *pzErrmsg = p->zErrmsg;
159906 sqlite3_free(p);
159907 }else{
159908 rc = SQLITE_NOMEM;
@@ -159912,65 +160157,65 @@
159912 }
159913
159914 /*
159915 ** Return the total number of key-value operations (inserts, deletes or
159916 ** updates) that have been performed on the target database since the
159917 ** current OTA update was started.
159918 */
159919 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3ota_progress(sqlite3ota *pOta){
159920 return pOta->nProgress;
159921 }
159922
159923 /**************************************************************************
159924 ** Beginning of OTA VFS shim methods. The VFS shim modifies the behaviour
159925 ** of a standard VFS in the following ways:
159926 **
159927 ** 1. Whenever the first page of a main database file is read or
159928 ** written, the value of the change-counter cookie is stored in
159929 ** ota_file.iCookie. Similarly, the value of the "write-version"
159930 ** database header field is stored in ota_file.iWriteVer. This ensures
159931 ** that the values are always trustworthy within an open transaction.
159932 **
159933 ** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (ota_file.pWalFd)
159934 ** member variable of the associated database file descriptor is set
159935 ** to point to the new file. A mutex protected linked list of all main
159936 ** db fds opened using a particular OTA VFS is maintained at
159937 ** ota_vfs.pMain to facilitate this.
159938 **
159939 ** 3. Using a new file-control "SQLITE_FCNTL_OTA", a main db ota_file
159940 ** object can be marked as the target database of an OTA update. This
159941 ** turns on the following extra special behaviour:
159942 **
159943 ** 3a. If xAccess() is called to check if there exists a *-wal file
159944 ** associated with an OTA target database currently in OTA_STAGE_OAL
159945 ** stage (preparing the *-oal file), the following special handling
159946 ** applies:
159947 **
159948 ** * if the *-wal file does exist, return SQLITE_CANTOPEN. An OTA
159949 ** target database may not be in wal mode already.
159950 **
159951 ** * if the *-wal file does not exist, set the output parameter to
159952 ** non-zero (to tell SQLite that it does exist) anyway.
159953 **
159954 ** Then, when xOpen() is called to open the *-wal file associated with
159955 ** the OTA target in OTA_STAGE_OAL stage, instead of opening the *-wal
159956 ** file, the ota vfs opens the corresponding *-oal file instead.
159957 **
159958 ** 3b. The *-shm pages returned by xShmMap() for a target db file in
159959 ** OTA_STAGE_OAL mode are actually stored in heap memory. This is to
159960 ** avoid creating a *-shm file on disk. Additionally, xShmLock() calls
159961 ** are no-ops on target database files in OTA_STAGE_OAL mode. This is
159962 ** because assert() statements in some VFS implementations fail if
159963 ** xShmLock() is called before xShmMap().
159964 **
159965 ** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
159966 ** mode except OTA_STAGE_DONE (all work completed and checkpointed), it
159967 ** fails with an SQLITE_BUSY error. This is to stop OTA connections
159968 ** from automatically checkpointing a *-wal (or *-oal) file from within
159969 ** sqlite3_close().
159970 **
159971 ** 3d. In OTA_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
159972 ** all xWrite() calls on the target database file perform no IO.
159973 ** Instead the frame and page numbers that would be read and written
159974 ** are recorded. Additionally, successful attempts to obtain exclusive
159975 ** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
159976 ** database file are recorded. xShmLock() calls to unlock the same
@@ -159977,28 +160222,28 @@
159977 ** locks are no-ops (so that once obtained, these locks are never
159978 ** relinquished). Finally, calls to xSync() on the target database
159979 ** file fail with SQLITE_INTERNAL errors.
159980 */
159981
159982 static void otaUnlockShm(ota_file *p){
159983 if( p->pOta ){
159984 int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock;
159985 int i;
159986 for(i=0; i<SQLITE_SHM_NLOCK;i++){
159987 if( (1<<i) & p->pOta->mLock ){
159988 xShmLock(p->pReal, i, 1, SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE);
159989 }
159990 }
159991 p->pOta->mLock = 0;
159992 }
159993 }
159994
159995 /*
159996 ** Close an ota file.
159997 */
159998 static int otaVfsClose(sqlite3_file *pFile){
159999 ota_file *p = (ota_file*)pFile;
160000 int rc;
160001 int i;
160002
160003 /* Free the contents of the apShm[] array. And the array itself. */
160004 for(i=0; i<p->nShm; i++){
@@ -160007,16 +160252,16 @@
160007 sqlite3_free(p->apShm);
160008 p->apShm = 0;
160009 sqlite3_free(p->zDel);
160010
160011 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160012 ota_file **pp;
160013 sqlite3_mutex_enter(p->pOtaVfs->mutex);
160014 for(pp=&p->pOtaVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext));
160015 *pp = p->pMainNext;
160016 sqlite3_mutex_leave(p->pOtaVfs->mutex);
160017 otaUnlockShm(p);
160018 p->pReal->pMethods->xShmUnmap(p->pReal, 0);
160019 }
160020
160021 /* Close the underlying file handle */
160022 rc = p->pReal->pMethods->xClose(p->pReal);
@@ -160026,37 +160271,37 @@
160026
160027 /*
160028 ** Read and return an unsigned 32-bit big-endian integer from the buffer
160029 ** passed as the only argument.
160030 */
160031 static u32 otaGetU32(u8 *aBuf){
160032 return ((u32)aBuf[0] << 24)
160033 + ((u32)aBuf[1] << 16)
160034 + ((u32)aBuf[2] << 8)
160035 + ((u32)aBuf[3]);
160036 }
160037
160038 /*
160039 ** Read data from an otaVfs-file.
160040 */
160041 static int otaVfsRead(
160042 sqlite3_file *pFile,
160043 void *zBuf,
160044 int iAmt,
160045 sqlite_int64 iOfst
160046 ){
160047 ota_file *p = (ota_file*)pFile;
160048 sqlite3ota *pOta = p->pOta;
160049 int rc;
160050
160051 if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){
160052 assert( p->openFlags & SQLITE_OPEN_WAL );
160053 rc = otaCaptureWalRead(p->pOta, iOfst, iAmt);
160054 }else{
160055 if( pOta && pOta->eStage==OTA_STAGE_OAL
160056 && (p->openFlags & SQLITE_OPEN_WAL)
160057 && iOfst>=pOta->iOalSz
160058 ){
160059 rc = SQLITE_OK;
160060 memset(zBuf, 0, iAmt);
160061 }else{
160062 rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
@@ -160063,92 +160308,92 @@
160063 }
160064 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160065 /* These look like magic numbers. But they are stable, as they are part
160066 ** of the definition of the SQLite file format, which may not change. */
160067 u8 *pBuf = (u8*)zBuf;
160068 p->iCookie = otaGetU32(&pBuf[24]);
160069 p->iWriteVer = pBuf[19];
160070 }
160071 }
160072 return rc;
160073 }
160074
160075 /*
160076 ** Write data to an otaVfs-file.
160077 */
160078 static int otaVfsWrite(
160079 sqlite3_file *pFile,
160080 const void *zBuf,
160081 int iAmt,
160082 sqlite_int64 iOfst
160083 ){
160084 ota_file *p = (ota_file*)pFile;
160085 sqlite3ota *pOta = p->pOta;
160086 int rc;
160087
160088 if( pOta && pOta->eStage==OTA_STAGE_CAPTURE ){
160089 assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
160090 rc = otaCaptureDbWrite(p->pOta, iOfst);
160091 }else{
160092 if( pOta && pOta->eStage==OTA_STAGE_OAL
160093 && (p->openFlags & SQLITE_OPEN_WAL)
160094 && iOfst>=pOta->iOalSz
160095 ){
160096 pOta->iOalSz = iAmt + iOfst;
160097 }
160098 rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
160099 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160100 /* These look like magic numbers. But they are stable, as they are part
160101 ** of the definition of the SQLite file format, which may not change. */
160102 u8 *pBuf = (u8*)zBuf;
160103 p->iCookie = otaGetU32(&pBuf[24]);
160104 p->iWriteVer = pBuf[19];
160105 }
160106 }
160107 return rc;
160108 }
160109
160110 /*
160111 ** Truncate an otaVfs-file.
160112 */
160113 static int otaVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
160114 ota_file *p = (ota_file*)pFile;
160115 return p->pReal->pMethods->xTruncate(p->pReal, size);
160116 }
160117
160118 /*
160119 ** Sync an otaVfs-file.
160120 */
160121 static int otaVfsSync(sqlite3_file *pFile, int flags){
160122 ota_file *p = (ota_file *)pFile;
160123 if( p->pOta && p->pOta->eStage==OTA_STAGE_CAPTURE ){
160124 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160125 return SQLITE_INTERNAL;
160126 }
160127 return SQLITE_OK;
160128 }
160129 return p->pReal->pMethods->xSync(p->pReal, flags);
160130 }
160131
160132 /*
160133 ** Return the current file-size of an otaVfs-file.
160134 */
160135 static int otaVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
160136 ota_file *p = (ota_file *)pFile;
160137 return p->pReal->pMethods->xFileSize(p->pReal, pSize);
160138 }
160139
160140 /*
160141 ** Lock an otaVfs-file.
160142 */
160143 static int otaVfsLock(sqlite3_file *pFile, int eLock){
160144 ota_file *p = (ota_file*)pFile;
160145 sqlite3ota *pOta = p->pOta;
160146 int rc = SQLITE_OK;
160147
160148 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160149 if( pOta && eLock==SQLITE_LOCK_EXCLUSIVE && pOta->eStage!=OTA_STAGE_DONE ){
160150 /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
160151 ** prevents it from checkpointing the database from sqlite3_close(). */
160152 rc = SQLITE_BUSY;
160153 }else{
160154 rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -160156,122 +160401,122 @@
160156
160157 return rc;
160158 }
160159
160160 /*
160161 ** Unlock an otaVfs-file.
160162 */
160163 static int otaVfsUnlock(sqlite3_file *pFile, int eLock){
160164 ota_file *p = (ota_file *)pFile;
160165 return p->pReal->pMethods->xUnlock(p->pReal, eLock);
160166 }
160167
160168 /*
160169 ** Check if another file-handle holds a RESERVED lock on an otaVfs-file.
160170 */
160171 static int otaVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
160172 ota_file *p = (ota_file *)pFile;
160173 return p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut);
160174 }
160175
160176 /*
160177 ** File control method. For custom operations on an otaVfs-file.
160178 */
160179 static int otaVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
160180 ota_file *p = (ota_file *)pFile;
160181 int (*xControl)(sqlite3_file*,int,void*) = p->pReal->pMethods->xFileControl;
160182 int rc;
160183
160184 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB)
160185 || p->openFlags & (SQLITE_OPEN_TRANSIENT_DB|SQLITE_OPEN_TEMP_JOURNAL)
160186 );
160187 if( op==SQLITE_FCNTL_OTA ){
160188 sqlite3ota *pOta = (sqlite3ota*)pArg;
160189
160190 /* First try to find another OTA vfs lower down in the vfs stack. If
160191 ** one is found, this vfs will operate in pass-through mode. The lower
160192 ** level vfs will do the special OTA handling. */
160193 rc = xControl(p->pReal, op, pArg);
160194
160195 if( rc==SQLITE_NOTFOUND ){
160196 /* Now search for a zipvfs instance lower down in the VFS stack. If
160197 ** one is found, this is an error. */
160198 void *dummy = 0;
160199 rc = xControl(p->pReal, SQLITE_FCNTL_ZIPVFS, &dummy);
160200 if( rc==SQLITE_OK ){
160201 rc = SQLITE_ERROR;
160202 pOta->zErrmsg = sqlite3_mprintf("ota/zipvfs setup error");
160203 }else if( rc==SQLITE_NOTFOUND ){
160204 pOta->pTargetFd = p;
160205 p->pOta = pOta;
160206 if( p->pWalFd ) p->pWalFd->pOta = pOta;
160207 rc = SQLITE_OK;
160208 }
160209 }
160210 return rc;
160211 }
160212
160213 rc = xControl(p->pReal, op, pArg);
160214 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
160215 ota_vfs *pOtaVfs = p->pOtaVfs;
160216 char *zIn = *(char**)pArg;
160217 char *zOut = sqlite3_mprintf("ota(%s)/%z", pOtaVfs->base.zName, zIn);
160218 *(char**)pArg = zOut;
160219 if( zOut==0 ) rc = SQLITE_NOMEM;
160220 }
160221
160222 return rc;
160223 }
160224
160225 /*
160226 ** Return the sector-size in bytes for an otaVfs-file.
160227 */
160228 static int otaVfsSectorSize(sqlite3_file *pFile){
160229 ota_file *p = (ota_file *)pFile;
160230 return p->pReal->pMethods->xSectorSize(p->pReal);
160231 }
160232
160233 /*
160234 ** Return the device characteristic flags supported by an otaVfs-file.
160235 */
160236 static int otaVfsDeviceCharacteristics(sqlite3_file *pFile){
160237 ota_file *p = (ota_file *)pFile;
160238 return p->pReal->pMethods->xDeviceCharacteristics(p->pReal);
160239 }
160240
160241 /*
160242 ** Take or release a shared-memory lock.
160243 */
160244 static int otaVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
160245 ota_file *p = (ota_file*)pFile;
160246 sqlite3ota *pOta = p->pOta;
160247 int rc = SQLITE_OK;
160248
160249 #ifdef SQLITE_AMALGAMATION
160250 assert( WAL_CKPT_LOCK==1 );
160251 #endif
160252
160253 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160254 if( pOta && (pOta->eStage==OTA_STAGE_OAL || pOta->eStage==OTA_STAGE_MOVE) ){
160255 /* Magic number 1 is the WAL_CKPT_LOCK lock. Preventing SQLite from
160256 ** taking this lock also prevents any checkpoints from occurring.
160257 ** todo: really, it's not clear why this might occur, as
160258 ** wal_autocheckpoint ought to be turned off. */
160259 if( ofst==WAL_LOCK_CKPT && n==1 ) rc = SQLITE_BUSY;
160260 }else{
160261 int bCapture = 0;
160262 if( n==1 && (flags & SQLITE_SHM_EXCLUSIVE)
160263 && pOta && pOta->eStage==OTA_STAGE_CAPTURE
160264 && (ofst==WAL_LOCK_WRITE || ofst==WAL_LOCK_CKPT || ofst==WAL_LOCK_READ0)
160265 ){
160266 bCapture = 1;
160267 }
160268
160269 if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){
160270 rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags);
160271 if( bCapture && rc==SQLITE_OK ){
160272 pOta->mLock |= (1 << ofst);
160273 }
160274 }
160275 }
160276
160277 return rc;
@@ -160278,26 +160523,26 @@
160278 }
160279
160280 /*
160281 ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
160282 */
160283 static int otaVfsShmMap(
160284 sqlite3_file *pFile,
160285 int iRegion,
160286 int szRegion,
160287 int isWrite,
160288 void volatile **pp
160289 ){
160290 ota_file *p = (ota_file*)pFile;
160291 int rc = SQLITE_OK;
160292 int eStage = (p->pOta ? p->pOta->eStage : 0);
160293
160294 /* If not in OTA_STAGE_OAL, allow this call to pass through. Or, if this
160295 ** ota is in the OTA_STAGE_OAL state, use heap memory for *-shm space
160296 ** instead of a file on disk. */
160297 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160298 if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){
160299 if( iRegion<=p->nShm ){
160300 int nByte = (iRegion+1) * sizeof(char*);
160301 char **apNew = (char**)sqlite3_realloc(p->apShm, nByte);
160302 if( apNew==0 ){
160303 rc = SQLITE_NOMEM;
@@ -160332,29 +160577,29 @@
160332 }
160333
160334 /*
160335 ** Memory barrier.
160336 */
160337 static void otaVfsShmBarrier(sqlite3_file *pFile){
160338 ota_file *p = (ota_file *)pFile;
160339 p->pReal->pMethods->xShmBarrier(p->pReal);
160340 }
160341
160342 /*
160343 ** The xShmUnmap method.
160344 */
160345 static int otaVfsShmUnmap(sqlite3_file *pFile, int delFlag){
160346 ota_file *p = (ota_file*)pFile;
160347 int rc = SQLITE_OK;
160348 int eStage = (p->pOta ? p->pOta->eStage : 0);
160349
160350 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160351 if( eStage==OTA_STAGE_OAL || eStage==OTA_STAGE_MOVE ){
160352 /* no-op */
160353 }else{
160354 /* Release the checkpointer and writer locks */
160355 otaUnlockShm(p);
160356 rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
160357 }
160358 return rc;
160359 }
160360
@@ -160362,56 +160607,56 @@
160362 ** Given that zWal points to a buffer containing a wal file name passed to
160363 ** either the xOpen() or xAccess() VFS method, return a pointer to the
160364 ** file-handle opened by the same database connection on the corresponding
160365 ** database file.
160366 */
160367 static ota_file *otaFindMaindb(ota_vfs *pOtaVfs, const char *zWal){
160368 ota_file *pDb;
160369 sqlite3_mutex_enter(pOtaVfs->mutex);
160370 for(pDb=pOtaVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext);
160371 sqlite3_mutex_leave(pOtaVfs->mutex);
160372 return pDb;
160373 }
160374
160375 /*
160376 ** Open an ota file handle.
160377 */
160378 static int otaVfsOpen(
160379 sqlite3_vfs *pVfs,
160380 const char *zName,
160381 sqlite3_file *pFile,
160382 int flags,
160383 int *pOutFlags
160384 ){
160385 static sqlite3_io_methods otavfs_io_methods = {
160386 2, /* iVersion */
160387 otaVfsClose, /* xClose */
160388 otaVfsRead, /* xRead */
160389 otaVfsWrite, /* xWrite */
160390 otaVfsTruncate, /* xTruncate */
160391 otaVfsSync, /* xSync */
160392 otaVfsFileSize, /* xFileSize */
160393 otaVfsLock, /* xLock */
160394 otaVfsUnlock, /* xUnlock */
160395 otaVfsCheckReservedLock, /* xCheckReservedLock */
160396 otaVfsFileControl, /* xFileControl */
160397 otaVfsSectorSize, /* xSectorSize */
160398 otaVfsDeviceCharacteristics, /* xDeviceCharacteristics */
160399 otaVfsShmMap, /* xShmMap */
160400 otaVfsShmLock, /* xShmLock */
160401 otaVfsShmBarrier, /* xShmBarrier */
160402 otaVfsShmUnmap /* xShmUnmap */
160403 };
160404 ota_vfs *pOtaVfs = (ota_vfs*)pVfs;
160405 sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs;
160406 ota_file *pFd = (ota_file *)pFile;
160407 int rc = SQLITE_OK;
160408 const char *zOpen = zName;
160409
160410 memset(pFd, 0, sizeof(ota_file));
160411 pFd->pReal = (sqlite3_file*)&pFd[1];
160412 pFd->pOtaVfs = pOtaVfs;
160413 pFd->openFlags = flags;
160414 if( zName ){
160415 if( flags & SQLITE_OPEN_MAIN_DB ){
160416 /* A main database has just been opened. The following block sets
160417 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
@@ -160435,13 +160680,13 @@
160435 }
160436 z += (n + 8 + 1);
160437 pFd->zWal = z;
160438 }
160439 else if( flags & SQLITE_OPEN_WAL ){
160440 ota_file *pDb = otaFindMaindb(pOtaVfs, zName);
160441 if( pDb ){
160442 if( pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){
160443 /* This call is to open a *-wal file. Intead, open the *-oal. This
160444 ** code ensures that the string passed to xOpen() is terminated by a
160445 ** pair of '\0' bytes in case the VFS attempts to extract a URI
160446 ** parameter from it. */
160447 int nCopy = strlen(zName);
@@ -160453,11 +160698,11 @@
160453 zCopy[nCopy+1] = '\0';
160454 zOpen = (const char*)(pFd->zDel = zCopy);
160455 }else{
160456 rc = SQLITE_NOMEM;
160457 }
160458 pFd->pOta = pDb->pOta;
160459 }
160460 pDb->pWalFd = pFd;
160461 }
160462 }
160463 }
@@ -160467,16 +160712,16 @@
160467 }
160468 if( pFd->pReal->pMethods ){
160469 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
160470 ** pointer and, if the file is a main database file, link it into the
160471 ** mutex protected linked list of all such files. */
160472 pFile->pMethods = &otavfs_io_methods;
160473 if( flags & SQLITE_OPEN_MAIN_DB ){
160474 sqlite3_mutex_enter(pOtaVfs->mutex);
160475 pFd->pMainNext = pOtaVfs->pMain;
160476 pOtaVfs->pMain = pFd;
160477 sqlite3_mutex_leave(pOtaVfs->mutex);
160478 }
160479 }else{
160480 sqlite3_free(pFd->zDel);
160481 }
160482
@@ -160484,48 +160729,48 @@
160484 }
160485
160486 /*
160487 ** Delete the file located at zPath.
160488 */
160489 static int otaVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
160490 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160491 return pRealVfs->xDelete(pRealVfs, zPath, dirSync);
160492 }
160493
160494 /*
160495 ** Test for access permissions. Return true if the requested permission
160496 ** is available, or false otherwise.
160497 */
160498 static int otaVfsAccess(
160499 sqlite3_vfs *pVfs,
160500 const char *zPath,
160501 int flags,
160502 int *pResOut
160503 ){
160504 ota_vfs *pOtaVfs = (ota_vfs*)pVfs;
160505 sqlite3_vfs *pRealVfs = pOtaVfs->pRealVfs;
160506 int rc;
160507
160508 rc = pRealVfs->xAccess(pRealVfs, zPath, flags, pResOut);
160509
160510 /* If this call is to check if a *-wal file associated with an OTA target
160511 ** database connection exists, and the OTA update is in OTA_STAGE_OAL,
160512 ** the following special handling is activated:
160513 **
160514 ** a) if the *-wal file does exist, return SQLITE_CANTOPEN. This
160515 ** ensures that the OTA extension never tries to update a database
160516 ** in wal mode, even if the first page of the database file has
160517 ** been damaged.
160518 **
160519 ** b) if the *-wal file does not exist, claim that it does anyway,
160520 ** causing SQLite to call xOpen() to open it. This call will also
160521 ** be intercepted (see the otaVfsOpen() function) and the *-oal
160522 ** file opened instead.
160523 */
160524 if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){
160525 ota_file *pDb = otaFindMaindb(pOtaVfs, zPath);
160526 if( pDb && pDb->pOta && pDb->pOta->eStage==OTA_STAGE_OAL ){
160527 if( *pResOut ){
160528 rc = SQLITE_CANTOPEN;
160529 }else{
160530 *pResOut = 1;
160531 }
@@ -160538,151 +160783,151 @@
160538 /*
160539 ** Populate buffer zOut with the full canonical pathname corresponding
160540 ** to the pathname in zPath. zOut is guaranteed to point to a buffer
160541 ** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
160542 */
160543 static int otaVfsFullPathname(
160544 sqlite3_vfs *pVfs,
160545 const char *zPath,
160546 int nOut,
160547 char *zOut
160548 ){
160549 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160550 return pRealVfs->xFullPathname(pRealVfs, zPath, nOut, zOut);
160551 }
160552
160553 #ifndef SQLITE_OMIT_LOAD_EXTENSION
160554 /*
160555 ** Open the dynamic library located at zPath and return a handle.
160556 */
160557 static void *otaVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
160558 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160559 return pRealVfs->xDlOpen(pRealVfs, zPath);
160560 }
160561
160562 /*
160563 ** Populate the buffer zErrMsg (size nByte bytes) with a human readable
160564 ** utf-8 string describing the most recent error encountered associated
160565 ** with dynamic libraries.
160566 */
160567 static void otaVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
160568 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160569 pRealVfs->xDlError(pRealVfs, nByte, zErrMsg);
160570 }
160571
160572 /*
160573 ** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
160574 */
160575 static void (*otaVfsDlSym(
160576 sqlite3_vfs *pVfs,
160577 void *pArg,
160578 const char *zSym
160579 ))(void){
160580 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160581 return pRealVfs->xDlSym(pRealVfs, pArg, zSym);
160582 }
160583
160584 /*
160585 ** Close the dynamic library handle pHandle.
160586 */
160587 static void otaVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
160588 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160589 return pRealVfs->xDlClose(pRealVfs, pHandle);
160590 }
160591 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
160592
160593 /*
160594 ** Populate the buffer pointed to by zBufOut with nByte bytes of
160595 ** random data.
160596 */
160597 static int otaVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
160598 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160599 return pRealVfs->xRandomness(pRealVfs, nByte, zBufOut);
160600 }
160601
160602 /*
160603 ** Sleep for nMicro microseconds. Return the number of microseconds
160604 ** actually slept.
160605 */
160606 static int otaVfsSleep(sqlite3_vfs *pVfs, int nMicro){
160607 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160608 return pRealVfs->xSleep(pRealVfs, nMicro);
160609 }
160610
160611 /*
160612 ** Return the current time as a Julian Day number in *pTimeOut.
160613 */
160614 static int otaVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
160615 sqlite3_vfs *pRealVfs = ((ota_vfs*)pVfs)->pRealVfs;
160616 return pRealVfs->xCurrentTime(pRealVfs, pTimeOut);
160617 }
160618
160619 /*
160620 ** No-op.
160621 */
160622 static int otaVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){
160623 return 0;
160624 }
160625
160626 /*
160627 ** Deregister and destroy an OTA vfs created by an earlier call to
160628 ** sqlite3ota_create_vfs().
160629 */
160630 SQLITE_API void SQLITE_STDCALL sqlite3ota_destroy_vfs(const char *zName){
160631 sqlite3_vfs *pVfs = sqlite3_vfs_find(zName);
160632 if( pVfs && pVfs->xOpen==otaVfsOpen ){
160633 sqlite3_mutex_free(((ota_vfs*)pVfs)->mutex);
160634 sqlite3_vfs_unregister(pVfs);
160635 sqlite3_free(pVfs);
160636 }
160637 }
160638
160639 /*
160640 ** Create an OTA VFS named zName that accesses the underlying file-system
160641 ** via existing VFS zParent. The new object is registered as a non-default
160642 ** VFS with SQLite before returning.
160643 */
160644 SQLITE_API int SQLITE_STDCALL sqlite3ota_create_vfs(const char *zName, const char *zParent){
160645
160646 /* Template for VFS */
160647 static sqlite3_vfs vfs_template = {
160648 1, /* iVersion */
160649 0, /* szOsFile */
160650 0, /* mxPathname */
160651 0, /* pNext */
160652 0, /* zName */
160653 0, /* pAppData */
160654 otaVfsOpen, /* xOpen */
160655 otaVfsDelete, /* xDelete */
160656 otaVfsAccess, /* xAccess */
160657 otaVfsFullPathname, /* xFullPathname */
160658
160659 #ifndef SQLITE_OMIT_LOAD_EXTENSION
160660 otaVfsDlOpen, /* xDlOpen */
160661 otaVfsDlError, /* xDlError */
160662 otaVfsDlSym, /* xDlSym */
160663 otaVfsDlClose, /* xDlClose */
160664 #else
160665 0, 0, 0, 0,
160666 #endif
160667
160668 otaVfsRandomness, /* xRandomness */
160669 otaVfsSleep, /* xSleep */
160670 otaVfsCurrentTime, /* xCurrentTime */
160671 otaVfsGetLastError, /* xGetLastError */
160672 0, /* xCurrentTimeInt64 (version 2) */
160673 0, 0, 0 /* Unimplemented version 3 methods */
160674 };
160675
160676 ota_vfs *pNew = 0; /* Newly allocated VFS */
160677 int nName;
160678 int rc = SQLITE_OK;
160679
160680 int nByte;
160681 nName = strlen(zName);
160682 nByte = sizeof(ota_vfs) + nName + 1;
160683 pNew = (ota_vfs*)sqlite3_malloc(nByte);
160684 if( pNew==0 ){
160685 rc = SQLITE_NOMEM;
160686 }else{
160687 sqlite3_vfs *pParent; /* Parent VFS */
160688 memset(pNew, 0, nByte);
@@ -160691,11 +160936,11 @@
160691 rc = SQLITE_NOTFOUND;
160692 }else{
160693 char *zSpace;
160694 memcpy(&pNew->base, &vfs_template, sizeof(sqlite3_vfs));
160695 pNew->base.mxPathname = pParent->mxPathname;
160696 pNew->base.szOsFile = sizeof(ota_file) + pParent->szOsFile;
160697 pNew->pRealVfs = pParent;
160698 pNew->base.zName = (const char*)(zSpace = (char*)&pNew[1]);
160699 memcpy(zSpace, zName, nName);
160700
160701 /* Allocate the mutex and register the new VFS (not as the default) */
@@ -160717,13 +160962,13 @@
160717 }
160718
160719
160720 /**************************************************************************/
160721
160722 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_OTA) */
160723
160724 /************** End of sqlite3ota.c ******************************************/
160725 /************** Begin file dbstat.c ******************************************/
160726 /*
160727 ** 2010 July 12
160728 **
160729 ** The author disclaims copyright to this source code. In place of
@@ -160741,10 +160986,11 @@
160741 ** information from an SQLite database in order to implement the
160742 ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
160743 ** for an example implementation.
160744 */
160745
 
160746 #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
160747 && !defined(SQLITE_OMIT_VIRTUALTABLE)
160748
160749 /*
160750 ** Page paths:
160751
--- 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.11.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -323,13 +323,13 @@
323 **
324 ** See also: [sqlite3_libversion()],
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.11.1"
329 #define SQLITE_VERSION_NUMBER 3008011
330 #define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -1179,13 +1179,13 @@
1179 **
1180 ** <li>[[SQLITE_FCNTL_ZIPVFS]]
1181 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
1182 ** VFS should return SQLITE_NOTFOUND for this opcode.
1183 **
1184 ** <li>[[SQLITE_FCNTL_RBU]]
1185 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1186 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
1187 ** this opcode.
1188 ** </ul>
1189 */
1190 #define SQLITE_FCNTL_LOCKSTATE 1
1191 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -1209,11 +1209,11 @@
1209 #define SQLITE_FCNTL_SYNC 21
1210 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1211 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1212 #define SQLITE_FCNTL_WAL_BLOCK 24
1213 #define SQLITE_FCNTL_ZIPVFS 25
1214 #define SQLITE_FCNTL_RBU 26
1215
1216 /* deprecated names */
1217 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1218 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1219 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3774,10 +3774,11 @@
3774 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3775 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3776 void(*)(void*), unsigned char encoding);
3777 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3778 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3779 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
3780
3781 /*
3782 ** CAPI3REF: Number Of SQL Parameters
3783 ** METHOD: sqlite3_stmt
3784 **
@@ -4746,13 +4747,13 @@
4747 ** ^The sqlite3_result_blob() interface sets the result from
4748 ** an application-defined function to be the BLOB whose content is pointed
4749 ** to by the second parameter and which is N bytes long where N is the
4750 ** third parameter.
4751 **
4752 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
4753 ** interfaces set the result of the application-defined function to be
4754 ** a BLOB containing all zero bytes and N bytes in size.
4755 **
4756 ** ^The sqlite3_result_double() interface sets the result from
4757 ** an application-defined function to be a floating point value specified
4758 ** by its 2nd argument.
4759 **
@@ -4863,10 +4864,11 @@
4864 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4865 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4866 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4867 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4868 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4869 SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
4870
4871 /*
4872 ** CAPI3REF: Define New Collating Sequences
4873 ** METHOD: sqlite3
4874 **
@@ -8362,13 +8364,17 @@
8364 /*
8365 ** Make sure that the compiler intrinsics we desire are enabled when
8366 ** compiling with an appropriate version of MSVC.
8367 */
8368 #if defined(_MSC_VER) && _MSC_VER>=1300
8369 # if !defined(_WIN32_WCE)
8370 # include <intrin.h>
8371 # pragma intrinsic(_byteswap_ushort)
8372 # pragma intrinsic(_byteswap_ulong)
8373 # else
8374 # include <cmnintrin.h>
8375 # endif
8376 #endif
8377
8378 /*
8379 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
8380 ** 0 means mutexes are permanently disable and the library is never
@@ -9189,11 +9195,13 @@
9195 #endif
9196 #ifndef SQLITE_MAX_MMAP_SIZE
9197 # if defined(__linux__) \
9198 || defined(_WIN32) \
9199 || (defined(__APPLE__) && defined(__MACH__)) \
9200 || defined(__sun) \
9201 || defined(__FreeBSD__) \
9202 || defined(__DragonFly__)
9203 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
9204 # else
9205 # define SQLITE_MAX_MMAP_SIZE 0
9206 # endif
9207 # define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */
@@ -13883,10 +13891,11 @@
13891 **
13892 *************************************************************************
13893 **
13894 ** This file contains definitions of global variables and constants.
13895 */
13896 /* #include "sqliteInt.h" */
13897
13898 /* An array to map all upper-case characters into their corresponding
13899 ** lower-case character.
13900 **
13901 ** SQLite only considers US-ASCII (or EBCDIC) characters. We do not
@@ -14122,10 +14131,11 @@
14131 */
14132 #ifndef SQLITE_OMIT_WSD
14133 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
14134 #endif
14135
14136 /* #include "opcodes.h" */
14137 /*
14138 ** Properties of opcodes. The OPFLG_INITIALIZER macro is
14139 ** created by mkopcodeh.awk during compilation. Data is obtained
14140 ** from the comments following the "case OP_xxxx:" statements in
14141 ** the vdbe.c file.
@@ -14150,10 +14160,11 @@
14160 ** SQLite was built with.
14161 */
14162
14163 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
14164
14165 /* #include "sqliteInt.h" */
14166
14167 /*
14168 ** An array of names of all compile-time options. This array should
14169 ** be sorted A-Z.
14170 **
@@ -14579,10 +14590,11 @@
14590 *************************************************************************
14591 **
14592 ** This module implements the sqlite3_status() interface and related
14593 ** functionality.
14594 */
14595 /* #include "sqliteInt.h" */
14596 /************** Include vdbeInt.h in the middle of status.c ******************/
14597 /************** Begin file vdbeInt.h *****************************************/
14598 /*
14599 ** 2003 September 6
14600 **
@@ -15462,10 +15474,11 @@
15474 ** Astronomical Algorithms, 2nd Edition, 1998
15475 ** ISBM 0-943396-61-1
15476 ** Willmann-Bell, Inc
15477 ** Richmond, Virginia (USA)
15478 */
15479 /* #include "sqliteInt.h" */
15480 /* #include <stdlib.h> */
15481 /* #include <assert.h> */
15482 #include <time.h>
15483
15484 #ifndef SQLITE_OMIT_DATETIME_FUNCS
@@ -15773,11 +15786,11 @@
15786 Z = (int)((p->iJD + 43200000)/86400000);
15787 A = (int)((Z - 1867216.25)/36524.25);
15788 A = Z + 1 + A - (A/4);
15789 B = A + 1524;
15790 C = (int)((B - 122.1)/365.25);
15791 D = (36525*(C&32767))/100;
15792 E = (int)((B-D)/30.6001);
15793 X1 = (int)(30.6001*E);
15794 p->D = B - D - X1;
15795 p->M = E<14 ? E-1 : E-13;
15796 p->Y = p->M>2 ? C - 4716 : C - 4715;
@@ -16574,10 +16587,11 @@
16587 **
16588 ** This file contains OS interface code that is common to all
16589 ** architectures.
16590 */
16591 #define _SQLITE_OS_C_ 1
16592 /* #include "sqliteInt.h" */
16593 #undef _SQLITE_OS_C_
16594
16595 /*
16596 ** The default SQLite sqlite3_vfs implementations do not allocate
16597 ** memory (actually, os_unix.c allocates a small amount of memory
@@ -16980,10 +16994,11 @@
16994 ** is completely recoverable simply by not carrying out the resize. The
16995 ** hash table will continue to function normally. So a malloc failure
16996 ** during a hash table resize is a benign fault.
16997 */
16998
16999 /* #include "sqliteInt.h" */
17000
17001 #ifndef SQLITE_OMIT_BUILTIN_TEST
17002
17003 /*
17004 ** Global variables.
@@ -17061,10 +17076,11 @@
17076 ** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented
17077 ** here always fail. SQLite will not operate with these drivers. These
17078 ** are merely placeholders. Real drivers must be substituted using
17079 ** sqlite3_config() before SQLite will operate.
17080 */
17081 /* #include "sqliteInt.h" */
17082
17083 /*
17084 ** This version of the memory allocator is the default. It is
17085 ** used when no other memory allocator is specified using compile-time
17086 ** macros.
@@ -17147,10 +17163,11 @@
17163 ** SQLITE_WITHOUT_MSIZE Set this symbol to disable the use of
17164 ** _msize() on windows systems. This might
17165 ** be necessary when compiling for Delphi,
17166 ** for example.
17167 */
17168 /* #include "sqliteInt.h" */
17169
17170 /*
17171 ** This version of the memory allocator is the default. It is
17172 ** used when no other memory allocator is specified using compile-time
17173 ** macros.
@@ -17422,10 +17439,11 @@
17439 ** leaks and memory usage errors.
17440 **
17441 ** This file contains implementations of the low-level memory allocation
17442 ** routines specified in the sqlite3_mem_methods object.
17443 */
17444 /* #include "sqliteInt.h" */
17445
17446 /*
17447 ** This version of the memory allocator is used only if the
17448 ** SQLITE_MEMDEBUG macro is defined
17449 */
@@ -17956,10 +17974,11 @@
17974 ** be changed.
17975 **
17976 ** This version of the memory allocation subsystem is included
17977 ** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
17978 */
17979 /* #include "sqliteInt.h" */
17980
17981 /*
17982 ** This version of the memory allocator is only built into the library
17983 ** SQLITE_ENABLE_MEMSYS3 is defined. Defining this symbol does not
17984 ** mean that the library will use a memory-pool by default, just that
@@ -18670,10 +18689,11 @@
18689 ** N >= M*(1 + log2(n)/2) - n + 1
18690 **
18691 ** The sqlite3_status() logic tracks the maximum values of n and M so
18692 ** that an application can, at any time, verify this constraint.
18693 */
18694 /* #include "sqliteInt.h" */
18695
18696 /*
18697 ** This version of the memory allocator is used only when
18698 ** SQLITE_ENABLE_MEMSYS5 is defined.
18699 */
@@ -19213,10 +19233,11 @@
19233 *************************************************************************
19234 ** This file contains the C functions that implement mutexes.
19235 **
19236 ** This file contains code that is common across all mutex implementations.
19237 */
19238 /* #include "sqliteInt.h" */
19239
19240 #if defined(SQLITE_DEBUG) && !defined(SQLITE_MUTEX_OMIT)
19241 /*
19242 ** For debugging purposes, record when the mutex subsystem is initialized
19243 ** and uninitialized so that we can assert() if there is an attempt to
@@ -19386,10 +19407,11 @@
19407 **
19408 ** If compiled with SQLITE_DEBUG, then additional logic is inserted
19409 ** that does error checking on mutexes to make sure they are being
19410 ** called correctly.
19411 */
19412 /* #include "sqliteInt.h" */
19413
19414 #ifndef SQLITE_MUTEX_OMIT
19415
19416 #ifndef SQLITE_DEBUG
19417 /*
@@ -19589,10 +19611,11 @@
19611 ** May you share freely, never taking more than you give.
19612 **
19613 *************************************************************************
19614 ** This file contains the C functions that implement mutexes for pthreads
19615 */
19616 /* #include "sqliteInt.h" */
19617
19618 /*
19619 ** The code in this file is only used if we are compiling threadsafe
19620 ** under unix with pthreads.
19621 **
@@ -19963,10 +19986,11 @@
19986 ** May you share freely, never taking more than you give.
19987 **
19988 *************************************************************************
19989 ** This file contains the C functions that implement mutexes for Win32.
19990 */
19991 /* #include "sqliteInt.h" */
19992
19993 #if SQLITE_OS_WIN
19994 /*
19995 ** Include code that is common to all os_*.c files
19996 */
@@ -20638,10 +20662,11 @@
20662 **
20663 *************************************************************************
20664 **
20665 ** Memory allocation functions used throughout sqlite.
20666 */
20667 /* #include "sqliteInt.h" */
20668 /* #include <stdarg.h> */
20669
20670 /*
20671 ** Attempt to release up to n bytes of non-essential memory currently
20672 ** held by SQLite. An example of non-essential memory is memory used to
@@ -21449,10 +21474,11 @@
21474 ** This file contains code for a set of "printf"-like routines. These
21475 ** routines format strings much like the printf() from the standard C
21476 ** library, though the implementation here has enhancements to support
21477 ** SQLite.
21478 */
21479 /* #include "sqliteInt.h" */
21480
21481 /*
21482 ** Conversion types fall into various categories as defined by the
21483 ** following enumeration.
21484 */
@@ -22451,10 +22477,15 @@
22477 ** stack space on small-stack systems when logging is disabled.
22478 **
22479 ** sqlite3_log() must render into a static buffer. It cannot dynamically
22480 ** allocate memory because it might be called while the memory allocator
22481 ** mutex is held.
22482 **
22483 ** sqlite3VXPrintf() might ask for *temporary* memory allocations for
22484 ** certain format characters (%q) or for very large precisions or widths.
22485 ** Care must be taken that any sqlite3_log() calls that occur while the
22486 ** memory mutex is held do not use these mechanisms.
22487 */
22488 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22489 StrAccum acc; /* String accumulator */
22490 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22491
@@ -22526,10 +22557,11 @@
22557 ** analysis.
22558 **
22559 ** The interfaces in this file is only available when compiling
22560 ** with SQLITE_DEBUG.
22561 */
22562 /* #include "sqliteInt.h" */
22563 #ifdef SQLITE_DEBUG
22564
22565 /*
22566 ** Add a new subitem to the tree. The moreToFollow flag indicates that this
22567 ** is not the last item in the tree.
@@ -22957,10 +22989,11 @@
22989 ** generator (PRNG) for SQLite.
22990 **
22991 ** Random numbers are used by some of the database backends in order
22992 ** to generate random integer keys for tables or random filenames.
22993 */
22994 /* #include "sqliteInt.h" */
22995
22996
22997 /* All threads share a single random number generator.
22998 ** This structure is the current state of the generator.
22999 */
@@ -23103,11 +23136,13 @@
23136 ** single threaded systems. Nothing in SQLite requires multiple threads.
23137 ** This interface exists so that applications that want to take advantage
23138 ** of multiple cores can do so, while also allowing applications to stay
23139 ** single-threaded if desired.
23140 */
23141 /* #include "sqliteInt.h" */
23142 #if SQLITE_OS_WIN
23143 /* # include "os_win.h" */
23144 #endif
23145
23146 #if SQLITE_MAX_WORKER_THREADS>0
23147
23148 /********************************* Unix Pthreads ****************************/
@@ -23377,11 +23412,13 @@
23412 ** BOM or Byte Order Mark:
23413 ** 0xff 0xfe little-endian utf-16 follows
23414 ** 0xfe 0xff big-endian utf-16 follows
23415 **
23416 */
23417 /* #include "sqliteInt.h" */
23418 /* #include <assert.h> */
23419 /* #include "vdbeInt.h" */
23420
23421 #ifndef SQLITE_AMALGAMATION
23422 /*
23423 ** The following constant value is used by the SQLITE_BIGENDIAN and
23424 ** SQLITE_LITTLEENDIAN macros.
@@ -23890,10 +23927,11 @@
23927 **
23928 ** This file contains functions for allocating memory, comparing
23929 ** strings, and stuff like that.
23930 **
23931 */
23932 /* #include "sqliteInt.h" */
23933 /* #include <stdarg.h> */
23934 #if HAVE_ISNAN || SQLITE_HAVE_ISNAN
23935 # include <math.h>
23936 #endif
23937
@@ -25286,10 +25324,11 @@
25324 **
25325 *************************************************************************
25326 ** This is the implementation of generic hash-tables
25327 ** used in SQLite.
25328 */
25329 /* #include "sqliteInt.h" */
25330 /* #include <assert.h> */
25331
25332 /* Turn bulk memory into a hash table object by initializing the
25333 ** fields of the Hash structure.
25334 **
@@ -25763,10 +25802,11 @@
25802 ** * sqlite3_vfs method implementations.
25803 ** * Locking primitives for the proxy uber-locking-method. (MacOSX only)
25804 ** * Definitions of sqlite3_vfs objects for all locking methods
25805 ** plus implementations of sqlite3_os_init() and sqlite3_os_end().
25806 */
25807 /* #include "sqliteInt.h" */
25808 #if SQLITE_OS_UNIX /* This file is used on unix only */
25809
25810 /*
25811 ** There are various methods for file locking used for concurrency
25812 ** control:
@@ -33497,10 +33537,11 @@
33537 **
33538 ******************************************************************************
33539 **
33540 ** This file contains code that is specific to Windows.
33541 */
33542 /* #include "sqliteInt.h" */
33543 #if SQLITE_OS_WIN /* This file is used for Windows only */
33544
33545 /*
33546 ** Include code that is common to all os_*.c files
33547 */
@@ -33705,10 +33746,11 @@
33746 /************** Continuing where we left off in os_win.c *********************/
33747
33748 /*
33749 ** Include the header file for the Windows VFS.
33750 */
33751 /* #include "os_win.h" */
33752
33753 /*
33754 ** Compiling and using WAL mode requires several APIs that are only
33755 ** available in Windows platforms based on the NT kernel.
33756 */
@@ -39358,10 +39400,11 @@
39400 ** sometimes grow into tens of thousands or larger. The size of the
39401 ** Bitvec object is the number of pages in the database file at the
39402 ** start of a transaction, and is thus usually less than a few thousand,
39403 ** but can be as large as 2 billion for a really big database.
39404 */
39405 /* #include "sqliteInt.h" */
39406
39407 /* Size of the Bitvec structure in bytes. */
39408 #define BITVEC_SZ 512
39409
39410 /* Round the union size down to the nearest pointer boundary, since that's how
@@ -39747,10 +39790,11 @@
39790 ** May you share freely, never taking more than you give.
39791 **
39792 *************************************************************************
39793 ** This file implements that page cache.
39794 */
39795 /* #include "sqliteInt.h" */
39796
39797 /*
39798 ** A complete page cache is an instance of this structure.
39799 */
39800 struct PCache {
@@ -40488,10 +40532,11 @@
40532 **
40533 ** Earlier versions of SQLite used only methods (1) and (2). But experiments
40534 ** show that method (3) with N==100 provides about a 5% performance boost for
40535 ** common workloads.
40536 */
40537 /* #include "sqliteInt.h" */
40538
40539 typedef struct PCache1 PCache1;
40540 typedef struct PgHdr1 PgHdr1;
40541 typedef struct PgFreeslot PgFreeslot;
40542 typedef struct PGroup PGroup;
@@ -40598,10 +40643,11 @@
40643 ** fixed at sqlite3_initialize() time and do not require mutex protection.
40644 ** The nFreeSlot and pFree values do require mutex protection.
40645 */
40646 int isInit; /* True if initialized */
40647 int separateCache; /* Use a new PGroup for each PCache */
40648 int nInitPage; /* Initial bulk allocation size */
40649 int szSlot; /* Size of each free slot */
40650 int nSlot; /* The number of pcache slots */
40651 int nReserve; /* Try to keep nFreeSlot above this */
40652 void *pStart, *pEnd; /* Bounds of global page cache memory */
40653 /* Above requires no mutex. Use mutex below for variable that follow. */
@@ -40665,10 +40711,47 @@
40711 pBuf = (void*)&((char*)pBuf)[sz];
40712 }
40713 pcache1.pEnd = pBuf;
40714 }
40715 }
40716
40717 /*
40718 ** Try to initialize the pCache->pFree and pCache->pBulk fields. Return
40719 ** true if pCache->pFree ends up containing one or more free pages.
40720 */
40721 static int pcache1InitBulk(PCache1 *pCache){
40722 i64 szBulk;
40723 char *zBulk;
40724 if( pcache1.nInitPage==0 ) return 0;
40725 /* Do not bother with a bulk allocation if the cache size very small */
40726 if( pCache->nMax<3 ) return 0;
40727 sqlite3BeginBenignMalloc();
40728 if( pcache1.nInitPage>0 ){
40729 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
40730 }else{
40731 szBulk = -1024 * (i64)pcache1.nInitPage;
40732 }
40733 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
40734 szBulk = pCache->szAlloc*pCache->nMax;
40735 }
40736 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
40737 sqlite3EndBenignMalloc();
40738 if( zBulk ){
40739 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
40740 int i;
40741 for(i=0; i<nBulk; i++){
40742 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
40743 pX->page.pBuf = zBulk;
40744 pX->page.pExtra = &pX[1];
40745 pX->isBulkLocal = 1;
40746 pX->pNext = pCache->pFree;
40747 pCache->pFree = pX;
40748 zBulk += pCache->szAlloc;
40749 }
40750 }
40751 return pCache->pFree!=0;
40752 }
40753
40754 /*
40755 ** Malloc function used within this file to allocate space from the buffer
40756 ** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
40757 ** such buffer exists or there is no space left in it, this function falls
@@ -40766,11 +40849,11 @@
40849 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
40850 PgHdr1 *p = 0;
40851 void *pPg;
40852
40853 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40854 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
40855 p = pCache->pFree;
40856 pCache->pFree = p->pNext;
40857 p->pNext = 0;
40858 }else{
40859 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
@@ -40970,18 +41053,23 @@
41053
41054 /*
41055 ** If there are currently more than nMaxPage pages allocated, try
41056 ** to recycle pages to reduce the number allocated to nMaxPage.
41057 */
41058 static void pcache1EnforceMaxPage(PCache1 *pCache){
41059 PGroup *pGroup = pCache->pGroup;
41060 assert( sqlite3_mutex_held(pGroup->mutex) );
41061 while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
41062 PgHdr1 *p = pGroup->pLruTail;
41063 assert( p->pCache->pGroup==pGroup );
41064 assert( p->isPinned==0 );
41065 pcache1PinPage(p);
41066 pcache1RemoveFromHash(p, 1);
41067 }
41068 if( pCache->nPage==0 && pCache->pBulk ){
41069 sqlite3_free(pCache->pBulk);
41070 pCache->pBulk = pCache->pFree = 0;
41071 }
41072 }
41073
41074 /*
41075 ** Discard all pages from cache pCache with a page number (key value)
@@ -41054,10 +41142,18 @@
41142 if( sqlite3GlobalConfig.bCoreMutex ){
41143 pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
41144 pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
41145 }
41146 #endif
41147 if( pcache1.separateCache
41148 && sqlite3GlobalConfig.nPage!=0
41149 && sqlite3GlobalConfig.pPage==0
41150 ){
41151 pcache1.nInitPage = sqlite3GlobalConfig.nPage;
41152 }else{
41153 pcache1.nInitPage = 0;
41154 }
41155 pcache1.grp.mxPinned = 10;
41156 pcache1.isInit = 1;
41157 return SQLITE_OK;
41158 }
41159
@@ -41108,40 +41204,10 @@
41204 pCache->nMin = 10;
41205 pGroup->nMinPage += pCache->nMin;
41206 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41207 }
41208 pcache1LeaveMutex(pGroup);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41209 if( pCache->nHash==0 ){
41210 pcache1Destroy((sqlite3_pcache*)pCache);
41211 pCache = 0;
41212 }
41213 }
@@ -41160,11 +41226,11 @@
41226 pcache1EnterMutex(pGroup);
41227 pGroup->nMaxPage += (nMax - pCache->nMax);
41228 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41229 pCache->nMax = nMax;
41230 pCache->n90pct = pCache->nMax*9/10;
41231 pcache1EnforceMaxPage(pCache);
41232 pcache1LeaveMutex(pGroup);
41233 }
41234 }
41235
41236 /*
@@ -41178,11 +41244,11 @@
41244 PGroup *pGroup = pCache->pGroup;
41245 int savedMaxPage;
41246 pcache1EnterMutex(pGroup);
41247 savedMaxPage = pGroup->nMaxPage;
41248 pGroup->nMaxPage = 0;
41249 pcache1EnforceMaxPage(pCache);
41250 pGroup->nMaxPage = savedMaxPage;
41251 pcache1LeaveMutex(pGroup);
41252 }
41253 }
41254
@@ -41515,11 +41581,11 @@
41581 assert( pGroup->nMaxPage >= pCache->nMax );
41582 pGroup->nMaxPage -= pCache->nMax;
41583 assert( pGroup->nMinPage >= pCache->nMin );
41584 pGroup->nMinPage -= pCache->nMin;
41585 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41586 pcache1EnforceMaxPage(pCache);
41587 pcache1LeaveMutex(pGroup);
41588 sqlite3_free(pCache->pBulk);
41589 sqlite3_free(pCache->apHash);
41590 sqlite3_free(pCache);
41591 }
@@ -41679,10 +41745,11 @@
41745 ** primitives are constant time. The cost of DESTROY is O(N).
41746 **
41747 ** There is an added cost of O(N) when switching between TEST and
41748 ** SMALLEST primitives.
41749 */
41750 /* #include "sqliteInt.h" */
41751
41752
41753 /*
41754 ** Target size for allocation chunks.
41755 */
@@ -42148,10 +42215,11 @@
42215 ** locking to prevent two processes from writing the same database
42216 ** file simultaneously, or one process from reading the database while
42217 ** another is writing.
42218 */
42219 #ifndef SQLITE_OMIT_DISKIO
42220 /* #include "sqliteInt.h" */
42221 /************** Include wal.h in the middle of pager.c ***********************/
42222 /************** Begin file wal.h *********************************************/
42223 /*
42224 ** 2010 February 1
42225 **
@@ -42169,10 +42237,11 @@
42237 */
42238
42239 #ifndef _WAL_H_
42240 #define _WAL_H_
42241
42242 /* #include "sqliteInt.h" */
42243
42244 /* Additional values that can be added to the sync_flags argument of
42245 ** sqlite3WalFrames():
42246 */
42247 #define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */
@@ -49783,10 +49852,11 @@
49852 ** that correspond to frames greater than the new K value are removed
49853 ** from the hash table at this point.
49854 */
49855 #ifndef SQLITE_OMIT_WAL
49856
49857 /* #include "wal.h" */
49858
49859 /*
49860 ** Trace output macros
49861 */
49862 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
@@ -50188,13 +50258,13 @@
50258
50259 assert( pWal->writeLock );
50260 pWal->hdr.isInit = 1;
50261 pWal->hdr.iVersion = WALINDEX_MAX_VERSION;
50262 walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
50263 memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
50264 walShmBarrier(pWal);
50265 memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
50266 }
50267
50268 /*
50269 ** This function encodes a single frame header and writes it to a buffer
50270 ** supplied by the caller. A frame-header is made up of a series of
@@ -50492,17 +50562,17 @@
50562 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
50563 /* Verify that the every entry in the mapping region is still reachable
50564 ** via the hash table even after the cleanup.
50565 */
50566 if( iLimit ){
50567 int j; /* Loop counter */
50568 int iKey; /* Hash key */
50569 for(j=1; j<=iLimit; j++){
50570 for(iKey=walHash(aPgno[j]); aHash[iKey]; iKey=walNextHash(iKey)){
50571 if( aHash[iKey]==j ) break;
50572 }
50573 assert( aHash[iKey]==j );
50574 }
50575 }
50576 #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
50577 }
50578
@@ -51000,11 +51070,11 @@
51070
51071 const int nList = *pnList; /* Size of input list */
51072 int nMerge = 0; /* Number of elements in list aMerge */
51073 ht_slot *aMerge = 0; /* List to be merged */
51074 int iList; /* Index into input list */
51075 u32 iSub = 0; /* Index into aSub array */
51076 struct Sublist aSub[13]; /* Array of sub-lists */
51077
51078 memset(aSub, 0, sizeof(aSub));
51079 assert( nList<=HASHTABLE_NPAGE && nList>0 );
51080 assert( HASHTABLE_NPAGE==(1<<(ArraySize(aSub)-1)) );
@@ -51011,11 +51081,13 @@
51081
51082 for(iList=0; iList<nList; iList++){
51083 nMerge = 1;
51084 aMerge = &aList[iList];
51085 for(iSub=0; iList & (1<<iSub); iSub++){
51086 struct Sublist *p;
51087 assert( iSub<ArraySize(aSub) );
51088 p = &aSub[iSub];
51089 assert( p->aList && p->nList<=(1<<iSub) );
51090 assert( p->aList==&aList[iList&~((2<<iSub)-1)] );
51091 walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
51092 }
51093 aSub[iSub].aList = aMerge;
@@ -51022,11 +51094,13 @@
51094 aSub[iSub].nList = nMerge;
51095 }
51096
51097 for(iSub++; iSub<ArraySize(aSub); iSub++){
51098 if( nList & (1<<iSub) ){
51099 struct Sublist *p;
51100 assert( iSub<ArraySize(aSub) );
51101 p = &aSub[iSub];
51102 assert( p->nList<=(1<<iSub) );
51103 assert( p->aList==&aList[nList&~((2<<iSub)-1)] );
51104 walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
51105 }
51106 }
@@ -52933,10 +53007,11 @@
53007 ** SIZE DESCRIPTION
53008 ** 4 Page number of next trunk page
53009 ** 4 Number of leaf pointers on this page
53010 ** * zero or more pages numbers of leaves
53011 */
53012 /* #include "sqliteInt.h" */
53013
53014
53015 /* The following value is the maximum cell size assuming a maximum page
53016 ** size give above.
53017 */
@@ -53730,10 +53805,11 @@
53805 *************************************************************************
53806 ** This file implements an external (disk-based) database using BTrees.
53807 ** See the header comment on "btreeInt.h" for additional information.
53808 ** Including a description of file format and an overview of operation.
53809 */
53810 /* #include "btreeInt.h" */
53811
53812 /*
53813 ** The header string that appears at the beginning of every
53814 ** SQLite database.
53815 */
@@ -62675,11 +62751,11 @@
62751 u32 *heap = 0; /* Min-heap used for checking cell coverage */
62752 u32 x, prev = 0; /* Next and previous entry on the min-heap */
62753 const char *saved_zPfx = pCheck->zPfx;
62754 int saved_v1 = pCheck->v1;
62755 int saved_v2 = pCheck->v2;
62756 u8 savedIsInit = 0;
62757
62758 /* Check that the page exists
62759 */
62760 pBt = pCheck->pBt;
62761 usableSize = pBt->usableSize;
@@ -63311,10 +63387,12 @@
63387 **
63388 *************************************************************************
63389 ** This file contains the implementation of the sqlite3_backup_XXX()
63390 ** API functions and the related features.
63391 */
63392 /* #include "sqliteInt.h" */
63393 /* #include "btreeInt.h" */
63394
63395 /*
63396 ** Structure allocated for each backup operation.
63397 */
63398 struct sqlite3_backup {
@@ -64109,10 +64187,12 @@
64187 ** This file contains code use to manipulate "Mem" structure. A "Mem"
64188 ** stores a single value in the VDBE. Mem is an opaque structure visible
64189 ** only within the VDBE. Interface routines refer to a Mem using the
64190 ** name sqlite_value
64191 */
64192 /* #include "sqliteInt.h" */
64193 /* #include "vdbeInt.h" */
64194
64195 #ifdef SQLITE_DEBUG
64196 /*
64197 ** Check invariants on a Mem object.
64198 **
@@ -65826,10 +65906,12 @@
65906 **
65907 *************************************************************************
65908 ** This file contains code used for creating, destroying, and populating
65909 ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)
65910 */
65911 /* #include "sqliteInt.h" */
65912 /* #include "vdbeInt.h" */
65913
65914 /*
65915 ** Create a new virtual database engine.
65916 */
65917 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){
@@ -70074,10 +70156,12 @@
70156 *************************************************************************
70157 **
70158 ** This file contains code use to implement APIs that are part of the
70159 ** VDBE.
70160 */
70161 /* #include "sqliteInt.h" */
70162 /* #include "vdbeInt.h" */
70163
70164 #ifndef SQLITE_OMIT_DEPRECATED
70165 /*
70166 ** Return TRUE (non-zero) of the statement supplied as an argument needs
70167 ** to be recompiled. A statement needs to be recompiled whenever the
@@ -70112,10 +70196,35 @@
70196 }else{
70197 return vdbeSafety(p);
70198 }
70199 }
70200
70201 #ifndef SQLITE_OMIT_TRACE
70202 /*
70203 ** Invoke the profile callback. This routine is only called if we already
70204 ** know that the profile callback is defined and needs to be invoked.
70205 */
70206 static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){
70207 sqlite3_int64 iNow;
70208 assert( p->startTime>0 );
70209 assert( db->xProfile!=0 );
70210 assert( db->init.busy==0 );
70211 assert( p->zSql!=0 );
70212 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
70213 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
70214 p->startTime = 0;
70215 }
70216 /*
70217 ** The checkProfileCallback(DB,P) macro checks to see if a profile callback
70218 ** is needed, and it invokes the callback if it is needed.
70219 */
70220 # define checkProfileCallback(DB,P) \
70221 if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
70222 #else
70223 # define checkProfileCallback(DB,P) /*no-op*/
70224 #endif
70225
70226 /*
70227 ** The following routine destroys a virtual machine that is created by
70228 ** the sqlite3_compile() routine. The integer returned is an SQLITE_
70229 ** success/failure code that describes the result of executing the virtual
70230 ** machine.
@@ -70132,10 +70241,11 @@
70241 }else{
70242 Vdbe *v = (Vdbe*)pStmt;
70243 sqlite3 *db = v->db;
70244 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
70245 sqlite3_mutex_enter(db->mutex);
70246 checkProfileCallback(db, v);
70247 rc = sqlite3VdbeFinalize(v);
70248 rc = sqlite3ApiExit(db, rc);
70249 sqlite3LeaveMutexAndCloseZombie(db);
70250 }
70251 return rc;
@@ -70153,16 +70263,18 @@
70263 int rc;
70264 if( pStmt==0 ){
70265 rc = SQLITE_OK;
70266 }else{
70267 Vdbe *v = (Vdbe*)pStmt;
70268 sqlite3 *db = v->db;
70269 sqlite3_mutex_enter(db->mutex);
70270 checkProfileCallback(db, v);
70271 rc = sqlite3VdbeReset(v);
70272 sqlite3VdbeRewind(v);
70273 assert( (rc & (db->errMask))==rc );
70274 rc = sqlite3ApiExit(db, rc);
70275 sqlite3_mutex_leave(db->mutex);
70276 }
70277 return rc;
70278 }
70279
70280 /*
@@ -70193,11 +70305,14 @@
70305 ** structure.
70306 */
70307 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value *pVal){
70308 Mem *p = (Mem*)pVal;
70309 if( p->flags & (MEM_Blob|MEM_Str) ){
70310 if( sqlite3VdbeMemExpandBlob(p)!=SQLITE_OK ){
70311 assert( p->flags==MEM_Null && p->z==0 );
70312 return 0;
70313 }
70314 p->flags |= MEM_Blob;
70315 return p->n ? p->z : 0;
70316 }else{
70317 return sqlite3_value_text(pVal);
70318 }
@@ -70454,10 +70569,19 @@
70569 sqlite3VdbeMemCopy(pCtx->pOut, pValue);
70570 }
70571 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
70572 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
70573 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
70574 }
70575 SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
70576 Mem *pOut = pCtx->pOut;
70577 assert( sqlite3_mutex_held(pOut->db->mutex) );
70578 if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
70579 return SQLITE_TOOBIG;
70580 }
70581 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
70582 return SQLITE_OK;
70583 }
70584 SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
70585 pCtx->isError = errCode;
70586 pCtx->fErrorOrAux = 1;
70587 #ifdef SQLITE_DEBUG
@@ -70508,10 +70632,11 @@
70632 }
70633 }
70634 #endif
70635 return rc;
70636 }
70637
70638
70639 /*
70640 ** Execute the statement pStmt, either until a row of data is ready, the
70641 ** statement is completely executed or an error occurs.
70642 **
@@ -70577,12 +70702,14 @@
70702 assert( db->nVdbeWrite>0 || db->autoCommit==0
70703 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
70704 );
70705
70706 #ifndef SQLITE_OMIT_TRACE
70707 if( db->xProfile && !db->init.busy && p->zSql ){
70708 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
70709 }else{
70710 assert( p->startTime==0 );
70711 }
70712 #endif
70713
70714 db->nVdbeActive++;
70715 if( p->readOnly==0 ) db->nVdbeWrite++;
@@ -70602,17 +70729,12 @@
70729 rc = sqlite3VdbeExec(p);
70730 db->nVdbeExec--;
70731 }
70732
70733 #ifndef SQLITE_OMIT_TRACE
70734 /* If the statement completed successfully, invoke the profile callback */
70735 if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
 
 
 
 
 
70736 #endif
70737
70738 if( rc==SQLITE_DONE ){
70739 assert( p->rc==SQLITE_OK );
70740 p->rc = doWalCallbacks(db);
@@ -71436,10 +71558,24 @@
71558 sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
71559 sqlite3_mutex_leave(p->db->mutex);
71560 }
71561 return rc;
71562 }
71563 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt, int i, sqlite3_uint64 n){
71564 int rc;
71565 Vdbe *p = (Vdbe *)pStmt;
71566 sqlite3_mutex_enter(p->db->mutex);
71567 if( n>(u64)p->db->aLimit[SQLITE_LIMIT_LENGTH] ){
71568 rc = SQLITE_TOOBIG;
71569 }else{
71570 assert( (n & 0x7FFFFFFF)==n );
71571 rc = sqlite3_bind_zeroblob(pStmt, i, n);
71572 }
71573 rc = sqlite3ApiExit(p->db, rc);
71574 sqlite3_mutex_leave(p->db->mutex);
71575 return rc;
71576 }
71577
71578 /*
71579 ** Return the number of wildcards that can be potentially bound to.
71580 ** This routine is added to support DBD::SQLite.
71581 */
@@ -71685,10 +71821,12 @@
71821 ** This file contains code used to insert the values of host parameters
71822 ** (aka "wildcards") into the SQL text output by sqlite3_trace().
71823 **
71824 ** The Vdbe parse-tree explainer is also found here.
71825 */
71826 /* #include "sqliteInt.h" */
71827 /* #include "vdbeInt.h" */
71828
71829 #ifndef SQLITE_OMIT_TRACE
71830
71831 /*
71832 ** zSql is a zero-terminated string of UTF-8 SQL text. Return the number of
@@ -71877,10 +72015,12 @@
72015 ** documentation, headers files, or other derived files. The formatting
72016 ** of the code in this file is, therefore, important. See other comments
72017 ** in this file for details. If in doubt, do not deviate from existing
72018 ** commenting and indentation practices when changing or adding code.
72019 */
72020 /* #include "sqliteInt.h" */
72021 /* #include "vdbeInt.h" */
72022
72023 /*
72024 ** Invoke this macro on memory cells just prior to changing the
72025 ** value of the cell. This macro verifies that shallow copies are
72026 ** not misused. A shallow copy of a string or blob just copies a
@@ -74648,11 +74788,11 @@
74788 assert( memIsValid(pRec) );
74789 pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format);
74790 len = sqlite3VdbeSerialTypeLen(serial_type);
74791 if( pRec->flags & MEM_Zero ){
74792 if( nData ){
74793 if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem;
74794 }else{
74795 nZero += pRec->u.nZero;
74796 len -= pRec->u.nZero;
74797 }
74798 }
@@ -78635,10 +78775,12 @@
78775 *************************************************************************
78776 **
78777 ** This file contains code used to implement incremental BLOB I/O.
78778 */
78779
78780 /* #include "sqliteInt.h" */
78781 /* #include "vdbeInt.h" */
78782
78783 #ifndef SQLITE_OMIT_INCRBLOB
78784
78785 /*
78786 ** Valid sqlite3_blob* handles point to Incrblob structures.
@@ -79233,10 +79375,12 @@
79375 ** than one background thread may be created. Specifically, there may be
79376 ** one background thread for each temporary file on disk, and one background
79377 ** thread to merge the output of each of the others to a single PMA for
79378 ** the main thread to read from.
79379 */
79380 /* #include "sqliteInt.h" */
79381 /* #include "vdbeInt.h" */
79382
79383 /*
79384 ** If SQLITE_DEBUG_SORTER_THREADS is defined, this module outputs various
79385 ** messages to stderr that may be helpful in understanding the performance
79386 ** characteristics of the sorter in multi-threaded mode.
@@ -81849,10 +81993,11 @@
81993 ** 1) The in-memory representation grows too large for the allocated
81994 ** buffer, or
81995 ** 2) The sqlite3JournalCreate() function is called.
81996 */
81997 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
81998 /* #include "sqliteInt.h" */
81999
82000
82001 /*
82002 ** A JournalFile object is a subclass of sqlite3_file used by
82003 ** as an open file handle for journal files.
@@ -82096,10 +82241,11 @@
82241 **
82242 ** This file contains code use to implement an in-memory rollback journal.
82243 ** The in-memory rollback journal is used to journal transactions for
82244 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
82245 */
82246 /* #include "sqliteInt.h" */
82247
82248 /* Forward references to internal structures */
82249 typedef struct MemJournal MemJournal;
82250 typedef struct FilePoint FilePoint;
82251 typedef struct FileChunk FileChunk;
@@ -82351,10 +82497,11 @@
82497 **
82498 *************************************************************************
82499 ** This file contains routines used for walking the parser tree for
82500 ** an SQL statement.
82501 */
82502 /* #include "sqliteInt.h" */
82503 /* #include <stdlib.h> */
82504 /* #include <string.h> */
82505
82506
82507 /*
@@ -82509,10 +82656,11 @@
82656 **
82657 ** This file contains routines used for walking the parser tree and
82658 ** resolve all identifiers by associating them with a particular
82659 ** table and column.
82660 */
82661 /* #include "sqliteInt.h" */
82662 /* #include <stdlib.h> */
82663 /* #include <string.h> */
82664
82665 /*
82666 ** Walk the expression tree pExpr and increase the aggregate function
@@ -84021,10 +84169,11 @@
84169 **
84170 *************************************************************************
84171 ** This file contains routines used for analyzing expressions and
84172 ** for generating VDBE code that evaluates expressions in SQLite.
84173 */
84174 /* #include "sqliteInt.h" */
84175
84176 /*
84177 ** Return the 'affinity' of the expression pExpr if any.
84178 **
84179 ** If pExpr is a column, a reference to a column via an 'AS' alias,
@@ -88183,10 +88332,11 @@
88332 **
88333 *************************************************************************
88334 ** This file contains C code routines that used to generate VDBE code
88335 ** that implements the ALTER TABLE command.
88336 */
88337 /* #include "sqliteInt.h" */
88338
88339 /*
88340 ** The code in this file only exists if we are not omitting the
88341 ** ALTER TABLE logic from the build.
88342 */
@@ -89145,10 +89295,11 @@
89295 ** sqlite_stat4.sample. The nEq, nLt, and nDLt entries of sqlite_stat3
89296 ** all contain just a single integer which is the same as the first
89297 ** integer in the equivalent columns in sqlite_stat4.
89298 */
89299 #ifndef SQLITE_OMIT_ANALYZE
89300 /* #include "sqliteInt.h" */
89301
89302 #if defined(SQLITE_ENABLE_STAT4)
89303 # define IsStat4 1
89304 # define IsStat3 0
89305 #elif defined(SQLITE_ENABLE_STAT3)
@@ -90910,10 +91061,11 @@
91061 ** May you share freely, never taking more than you give.
91062 **
91063 *************************************************************************
91064 ** This file contains code used to implement the ATTACH and DETACH commands.
91065 */
91066 /* #include "sqliteInt.h" */
91067
91068 #ifndef SQLITE_OMIT_ATTACH
91069 /*
91070 ** Resolve an expression that was part of an ATTACH or DETACH statement. This
91071 ** is slightly different from resolving a normal SQL expression, because simple
@@ -91499,10 +91651,11 @@
91651 ** This file contains code used to implement the sqlite3_set_authorizer()
91652 ** API. This facility is an optional feature of the library. Embedded
91653 ** systems that do not need this facility may omit it by recompiling
91654 ** the library with -DSQLITE_OMIT_AUTHORIZATION=1
91655 */
91656 /* #include "sqliteInt.h" */
91657
91658 /*
91659 ** All of the code in this file may be omitted by defining a single
91660 ** macro.
91661 */
@@ -91769,10 +91922,11 @@
91922 ** creating ID lists
91923 ** BEGIN TRANSACTION
91924 ** COMMIT
91925 ** ROLLBACK
91926 */
91927 /* #include "sqliteInt.h" */
91928
91929 /*
91930 ** This routine is called when a new SQL statement is beginning to
91931 ** be parsed. Initialize the pParse structure as needed.
91932 */
@@ -96089,10 +96243,11 @@
96243 **
96244 ** This file contains functions used to access the internal hash tables
96245 ** of user defined functions and collation sequences.
96246 */
96247
96248 /* #include "sqliteInt.h" */
96249
96250 /*
96251 ** Invoke the 'collation needed' callback to request a collation sequence
96252 ** in the encoding enc of name zName, length nName.
96253 */
@@ -96566,10 +96721,11 @@
96721 **
96722 *************************************************************************
96723 ** This file contains C code routines that are called by the parser
96724 ** in order to generate code for DELETE FROM statements.
96725 */
96726 /* #include "sqliteInt.h" */
96727
96728 /*
96729 ** While a SrcList can in general represent multiple tables and subqueries
96730 ** (as in the FROM clause of a SELECT statement) in this case it contains
96731 ** the name of a single table, as one might find in an INSERT, DELETE,
@@ -97408,12 +97564,14 @@
97564 *************************************************************************
97565 ** This file contains the C-language implementations for many of the SQL
97566 ** functions of SQLite. (Some function, and in particular the date and
97567 ** time functions, are implemented separately.)
97568 */
97569 /* #include "sqliteInt.h" */
97570 /* #include <stdlib.h> */
97571 /* #include <assert.h> */
97572 /* #include "vdbeInt.h" */
97573
97574 /*
97575 ** Return the collating function associated with a function.
97576 */
97577 static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
@@ -98515,20 +98673,18 @@
98673 sqlite3_context *context,
98674 int argc,
98675 sqlite3_value **argv
98676 ){
98677 i64 n;
98678 int rc;
98679 assert( argc==1 );
98680 UNUSED_PARAMETER(argc);
98681 n = sqlite3_value_int64(argv[0]);
98682 if( n<0 ) n = 0;
98683 rc = sqlite3_result_zeroblob64(context, n); /* IMP: R-00293-64994 */
98684 if( rc ){
98685 sqlite3_result_error_code(context, rc);
 
 
98686 }
98687 }
98688
98689 /*
98690 ** The replace() function. Three arguments are all strings: call
@@ -99205,10 +99361,11 @@
99361 **
99362 *************************************************************************
99363 ** This file contains code used by the compiler to add foreign key
99364 ** support to compiled SQL statements.
99365 */
99366 /* #include "sqliteInt.h" */
99367
99368 #ifndef SQLITE_OMIT_FOREIGN_KEY
99369 #ifndef SQLITE_OMIT_TRIGGER
99370
99371 /*
@@ -100609,10 +100766,11 @@
100766 **
100767 *************************************************************************
100768 ** This file contains C code routines that are called by the parser
100769 ** to handle INSERT statements in SQLite.
100770 */
100771 /* #include "sqliteInt.h" */
100772
100773 /*
100774 ** Generate code that will
100775 **
100776 ** (1) acquire a lock for table pTab then
@@ -102592,11 +102750,11 @@
102750 }else{
102751 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
102752 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
102753 }
102754 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
102755 u8 idxInsFlags = 0;
102756 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
102757 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
102758 }
102759 assert( pSrcIdx );
102760 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -102627,16 +102785,19 @@
102785 char *zColl = pSrcIdx->azColl[i];
102786 assert( zColl!=0 );
102787 if( sqlite3_stricmp("BINARY", zColl) ) break;
102788 }
102789 if( i==pSrcIdx->nColumn ){
102790 idxInsFlags = OPFLAG_USESEEKRESULT;
102791 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
102792 }
102793 }
102794 if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
102795 idxInsFlags |= OPFLAG_NCHANGE;
102796 }
102797 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
102798 sqlite3VdbeChangeP5(v, idxInsFlags);
102799 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
102800 sqlite3VdbeJumpHere(v, addr1);
102801 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
102802 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
102803 }
@@ -102671,10 +102832,11 @@
102832 ** implement the programmer interface to the library. Routines in
102833 ** other files are for internal use by SQLite and should not be
102834 ** accessed by users of the library.
102835 */
102836
102837 /* #include "sqliteInt.h" */
102838
102839 /*
102840 ** Execute SQL code. Return one of the SQLITE_ success/failure
102841 ** codes. Also write an error message into memory obtained from
102842 ** malloc() and make *pzErrMsg point to that message.
@@ -102839,10 +103001,11 @@
103001 ** as extensions by SQLite should #include this file instead of
103002 ** sqlite3.h.
103003 */
103004 #ifndef _SQLITE3EXT_H_
103005 #define _SQLITE3EXT_H_
103006 /* #include "sqlite3.h" */
103007
103008 typedef struct sqlite3_api_routines sqlite3_api_routines;
103009
103010 /*
103011 ** The following structure holds pointers to all of the SQLite API
@@ -103091,10 +103254,12 @@
103254 void(*)(void*), unsigned char);
103255 int (*strglob)(const char*,const char*);
103256 /* Version 3.8.11 and later */
103257 sqlite3_value *(*value_dup)(const sqlite3_value*);
103258 void (*value_free)(sqlite3_value*);
103259 int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
103260 int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
103261 };
103262
103263 /*
103264 ** The following macros redefine the API routines so that they are
103265 ** redirected through the global sqlite3_api structure.
@@ -103324,10 +103489,12 @@
103489 #define sqlite3_result_text64 sqlite3_api->result_text64
103490 #define sqlite3_strglob sqlite3_api->strglob
103491 /* Version 3.8.11 and later */
103492 #define sqlite3_value_dup sqlite3_api->value_dup
103493 #define sqlite3_value_free sqlite3_api->value_free
103494 #define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
103495 #define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
103496 #endif /* SQLITE_CORE */
103497
103498 #ifndef SQLITE_CORE
103499 /* This case when the file really is being compiled as a loadable
103500 ** extension */
@@ -103345,10 +103512,11 @@
103512
103513 #endif /* _SQLITE3EXT_H_ */
103514
103515 /************** End of sqlite3ext.h ******************************************/
103516 /************** Continuing where we left off in loadext.c ********************/
103517 /* #include "sqliteInt.h" */
103518 /* #include <string.h> */
103519
103520 #ifndef SQLITE_OMIT_LOAD_EXTENSION
103521
103522 /*
@@ -103732,11 +103900,13 @@
103900 sqlite3_result_blob64,
103901 sqlite3_result_text64,
103902 sqlite3_strglob,
103903 /* Version 3.8.11 and later */
103904 (sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
103905 sqlite3_value_free,
103906 sqlite3_result_zeroblob64,
103907 sqlite3_bind_zeroblob64
103908 };
103909
103910 /*
103911 ** Attempt to load an SQLite extension library contained in the file
103912 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -104114,10 +104284,11 @@
104284 ** May you share freely, never taking more than you give.
104285 **
104286 *************************************************************************
104287 ** This file contains code used to implement the PRAGMA command.
104288 */
104289 /* #include "sqliteInt.h" */
104290
104291 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
104292 # if defined(__APPLE__)
104293 # define SQLITE_ENABLE_LOCKING_STYLE 1
104294 # else
@@ -104220,11 +104391,11 @@
104391 /* ePragFlag: */ 0,
104392 /* iArg: */ 0 },
104393 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
104394 { /* zName: */ "cache_size",
104395 /* ePragTyp: */ PragTyp_CACHE_SIZE,
104396 /* ePragFlag: */ 0,
104397 /* iArg: */ 0 },
104398 #endif
104399 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
104400 { /* zName: */ "cache_spill",
104401 /* ePragTyp: */ PragTyp_FLAG,
@@ -105290,15 +105461,17 @@
105461 ** of memory.
105462 */
105463 case PragTyp_CACHE_SIZE: {
105464 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
105465 if( !zRight ){
105466 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105467 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
105468 }else{
105469 int size = sqlite3Atoi(zRight);
105470 pDb->pSchema->cache_size = size;
105471 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
105472 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105473 }
105474 break;
105475 }
105476
105477 /*
@@ -106565,10 +106738,11 @@
106738 *************************************************************************
106739 ** This file contains the implementation of the sqlite3_prepare()
106740 ** interface, and routines that contribute to loading the database schema
106741 ** from disk.
106742 */
106743 /* #include "sqliteInt.h" */
106744
106745 /*
106746 ** Fill the InitData structure with an error message that indicates
106747 ** that the database is corrupt.
106748 */
@@ -107459,10 +107633,11 @@
107633 **
107634 *************************************************************************
107635 ** This file contains C code routines that are called by the parser
107636 ** to handle SELECT statements in SQLite.
107637 */
107638 /* #include "sqliteInt.h" */
107639
107640 /*
107641 ** Trace output macros
107642 */
107643 #if SELECTTRACE_ENABLED
@@ -108528,11 +108703,10 @@
108703 }
108704 }
108705 return pInfo;
108706 }
108707
 
108708 /*
108709 ** Name of the connection operator, used for error messages.
108710 */
108711 static const char *selectOpName(int id){
108712 char *z;
@@ -108542,11 +108716,10 @@
108716 case TK_EXCEPT: z = "EXCEPT"; break;
108717 default: z = "UNION"; break;
108718 }
108719 return z;
108720 }
 
108721
108722 #ifndef SQLITE_OMIT_EXPLAIN
108723 /*
108724 ** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
108725 ** is a no-op. Otherwise, it adds a single row of output to the EQP result,
@@ -109545,23 +109718,10 @@
109718 Parse *pParse, /* Parsing context */
109719 Select *p, /* The right-most of SELECTs to be coded */
109720 SelectDest *pDest /* What to do with query results */
109721 );
109722
 
 
 
 
 
 
 
 
 
 
 
 
 
109723 /*
109724 ** Handle the special case of a compound-select that originates from a
109725 ** VALUES clause. By handling this as a special case, we avoid deep
109726 ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
109727 ** on a VALUES clause.
@@ -109983,10 +110143,23 @@
110143 pDest->nSdst = dest.nSdst;
110144 sqlite3SelectDelete(db, pDelete);
110145 return rc;
110146 }
110147 #endif /* SQLITE_OMIT_COMPOUND_SELECT */
110148
110149 /*
110150 ** Error message for when two or more terms of a compound select have different
110151 ** size result sets.
110152 */
110153 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){
110154 if( p->selFlags & SF_Values ){
110155 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
110156 }else{
110157 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
110158 " do not have the same number of result columns", selectOpName(p->op));
110159 }
110160 }
110161
110162 /*
110163 ** Code an output subroutine for a coroutine implementation of a
110164 ** SELECT statment.
110165 **
@@ -113077,10 +113250,11 @@
113250 ** interface routine of sqlite3_exec().
113251 **
113252 ** These routines are in a separate files so that they will not be linked
113253 ** if they are not used.
113254 */
113255 /* #include "sqliteInt.h" */
113256 /* #include <stdlib.h> */
113257 /* #include <string.h> */
113258
113259 #ifndef SQLITE_OMIT_GET_TABLE
113260
@@ -113273,10 +113447,11 @@
113447 ** May you share freely, never taking more than you give.
113448 **
113449 *************************************************************************
113450 ** This file contains the implementation for TRIGGERs
113451 */
113452 /* #include "sqliteInt.h" */
113453
113454 #ifndef SQLITE_OMIT_TRIGGER
113455 /*
113456 ** Delete a linked list of TriggerStep structures.
113457 */
@@ -114396,10 +114571,11 @@
114571 **
114572 *************************************************************************
114573 ** This file contains C code routines that are called by the parser
114574 ** to handle UPDATE statements.
114575 */
114576 /* #include "sqliteInt.h" */
114577
114578 #ifndef SQLITE_OMIT_VIRTUALTABLE
114579 /* Forward declaration */
114580 static void updateVirtualTable(
114581 Parse *pParse, /* The parsing context */
@@ -115172,10 +115348,12 @@
115348 ** This file contains code used to implement the VACUUM command.
115349 **
115350 ** Most of the code in this file may be omitted by defining the
115351 ** SQLITE_OMIT_VACUUM macro.
115352 */
115353 /* #include "sqliteInt.h" */
115354 /* #include "vdbeInt.h" */
115355
115356 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
115357 /*
115358 ** Finalize a prepared statement. If there was an error, store the
115359 ** text of the error message in *pzErrMsg. Return the result code.
@@ -115544,10 +115722,11 @@
115722 **
115723 *************************************************************************
115724 ** This file contains code used to help implement virtual tables.
115725 */
115726 #ifndef SQLITE_OMIT_VIRTUALTABLE
115727 /* #include "sqliteInt.h" */
115728
115729 /*
115730 ** Before a virtual table xCreate() or xConnect() method is invoked, the
115731 ** sqlite3.pVtabCtx member variable is set to point to an instance of
115732 ** this struct allocated on the stack. It is used by the implementation of
@@ -116702,10 +116881,11 @@
116881 ** This file was split off from where.c on 2015-06-06 in order to reduce the
116882 ** size of where.c and make it easier to edit. This file contains the routines
116883 ** that actually generate the bulk of the WHERE loop code. The original where.c
116884 ** file retains the code that does query planning and analysis.
116885 */
116886 /* #include "sqliteInt.h" */
116887 /************** Include whereInt.h in the middle of wherecode.c **************/
116888 /************** Begin file whereInt.h ****************************************/
116889 /*
116890 ** 2013-11-12
116891 **
@@ -118513,11 +118693,15 @@
118693
118694 /* Read the PK into an array of temp registers. */
118695 r = sqlite3GetTempRange(pParse, nPk);
118696 for(iPk=0; iPk<nPk; iPk++){
118697 int iCol = pPk->aiColumn[iPk];
118698 int rx;
118699 rx = sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur,r+iPk,0);
118700 if( rx!=r+iPk ){
118701 sqlite3VdbeAddOp2(v, OP_SCopy, rx, r+iPk);
118702 }
118703 }
118704
118705 /* Check if the temp table already contains this key. If so,
118706 ** the row has already been included in the result set and
118707 ** can be ignored (by jumping past the Gosub below). Otherwise,
@@ -118737,10 +118921,12 @@
118921 **
118922 ** This file was originally part of where.c but was split out to improve
118923 ** readability and editabiliity. This file contains utility routines for
118924 ** analyzing Expr objects in the WHERE clause.
118925 */
118926 /* #include "sqliteInt.h" */
118927 /* #include "whereInt.h" */
118928
118929 /* Forward declarations */
118930 static void exprAnalyze(SrcList*, WhereClause*, int);
118931
118932 /*
@@ -119987,10 +120173,12 @@
120173 ** generating the code that loops through a table looking for applicable
120174 ** rows. Indices are selected and used to speed the search when doing
120175 ** so is applicable. Because this module is responsible for selecting
120176 ** indices, you might also think of this module as the "query optimizer".
120177 */
120178 /* #include "sqliteInt.h" */
120179 /* #include "whereInt.h" */
120180
120181 /* Forward declaration of methods */
120182 static int whereLoopResize(sqlite3*, WhereLoop*, int);
120183
120184 /* Test variable that can be set to enable WHERE tracing */
@@ -124486,10 +124674,11 @@
124674 */
124675 /* First off, code is included that follows the "include" declaration
124676 ** in the input grammar file. */
124677 /* #include <stdio.h> */
124678
124679 /* #include "sqliteInt.h" */
124680
124681 /*
124682 ** Disable all error recovery processing in the parser push-down
124683 ** automaton.
124684 */
@@ -128071,10 +128260,11 @@
128260 **
128261 ** This file contains C code that splits an SQL input string up into
128262 ** individual tokens and sends those tokens one-by-one over to the
128263 ** parser for analysis.
128264 */
128265 /* #include "sqliteInt.h" */
128266 /* #include <stdlib.h> */
128267
128268 /*
128269 ** The charMap() macro maps alphabetic characters into their
128270 ** lower-case ASCII equivalent. On ASCII machines, this is just
@@ -128880,10 +129070,11 @@
129070 ** This file contains C code that implements the sqlite3_complete() API.
129071 ** This code used to be part of the tokenizer.c source file. But by
129072 ** separating it out, the code will be automatically omitted from
129073 ** static links that do not use it.
129074 */
129075 /* #include "sqliteInt.h" */
129076 #ifndef SQLITE_OMIT_COMPLETE
129077
129078 /*
129079 ** This is defined in tokenize.c. We just have to import the definition.
129080 */
@@ -129170,10 +129361,11 @@
129361 ** Main file for the SQLite library. The routines in this file
129362 ** implement the programmer interface to the library. Routines in
129363 ** other files are for internal use by SQLite and should not be
129364 ** accessed by users of the library.
129365 */
129366 /* #include "sqliteInt.h" */
129367
129368 #ifdef SQLITE_ENABLE_FTS3
129369 /************** Include fts3.h in the middle of main.c ***********************/
129370 /************** Begin file fts3.h ********************************************/
129371 /*
@@ -129189,10 +129381,11 @@
129381 ******************************************************************************
129382 **
129383 ** This header file is used by programs that want to link against the
129384 ** FTS3 library. All it does is declare the sqlite3Fts3Init() interface.
129385 */
129386 /* #include "sqlite3.h" */
129387
129388 #if 0
129389 extern "C" {
129390 #endif /* __cplusplus */
129391
@@ -129221,10 +129414,11 @@
129414 ******************************************************************************
129415 **
129416 ** This header file is used by programs that want to link against the
129417 ** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
129418 */
129419 /* #include "sqlite3.h" */
129420
129421 #if 0
129422 extern "C" {
129423 #endif /* __cplusplus */
129424
@@ -129253,10 +129447,11 @@
129447 ******************************************************************************
129448 **
129449 ** This header file is used by programs that want to link against the
129450 ** ICU extension. All it does is declare the sqlite3IcuInit() interface.
129451 */
129452 /* #include "sqlite3.h" */
129453
129454 #if 0
129455 extern "C" {
129456 #endif /* __cplusplus */
129457
@@ -129885,10 +130080,11 @@
130080 ** space for the lookaside memory is obtained from sqlite3_malloc().
130081 ** If pStart is not NULL then it is sz*cnt bytes of memory to use for
130082 ** the lookaside memory.
130083 */
130084 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
130085 #ifndef SQLITE_OMIT_LOOKASIDE
130086 void *pStart;
130087 if( db->lookaside.nOut ){
130088 return SQLITE_BUSY;
130089 }
130090 /* Free any existing lookaside buffer for this handle before
@@ -129935,10 +130131,11 @@
130131 db->lookaside.pStart = db;
130132 db->lookaside.pEnd = db;
130133 db->lookaside.bEnabled = 0;
130134 db->lookaside.bMalloced = 0;
130135 }
130136 #endif /* SQLITE_OMIT_LOOKASIDE */
130137 return SQLITE_OK;
130138 }
130139
130140 /*
130141 ** Return the mutex associated with a database connection.
@@ -133045,10 +133242,12 @@
133242 *************************************************************************
133243 **
133244 ** This file contains the implementation of the sqlite3_unlock_notify()
133245 ** API method and its associated functionality.
133246 */
133247 /* #include "sqliteInt.h" */
133248 /* #include "btreeInt.h" */
133249
133250 /* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */
133251 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
133252
133253 /*
@@ -133688,13 +133887,15 @@
133887
133888 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
133889
133890 /* If not building as part of the core, include sqlite3ext.h. */
133891 #ifndef SQLITE_CORE
133892 /* # include "sqlite3ext.h" */
133893 SQLITE_EXTENSION_INIT3
133894 #endif
133895
133896 /* #include "sqlite3.h" */
133897 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
133898 /************** Begin file fts3_tokenizer.h **********************************/
133899 /*
133900 ** 2006 July 10
133901 **
@@ -133719,10 +133920,11 @@
133920
133921 /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time.
133922 ** If tokenizers are to be allowed to call sqlite3_*() functions, then
133923 ** we will need a way to register the API consistently.
133924 */
133925 /* #include "sqlite3.h" */
133926
133927 /*
133928 ** Structures used by the tokenizer interface. When a new tokenizer
133929 ** implementation is registered, the caller provides a pointer to
133930 ** an sqlite3_tokenizer_module containing pointers to the callback
@@ -134559,11 +134761,13 @@
134761 /* #include <stddef.h> */
134762 /* #include <stdio.h> */
134763 /* #include <string.h> */
134764 /* #include <stdarg.h> */
134765
134766 /* #include "fts3.h" */
134767 #ifndef SQLITE_CORE
134768 /* # include "sqlite3ext.h" */
134769 SQLITE_EXTENSION_INIT1
134770 #endif
134771
134772 static int fts3EvalNext(Fts3Cursor *pCsr);
134773 static int fts3EvalStart(Fts3Cursor *pCsr);
@@ -138486,11 +138690,10 @@
138690 ** tokens or prefix tokens that cannot use a prefix-index. */
138691 int bHaveIncr = 0;
138692 int bIncrOk = (bOptOk
138693 && pCsr->bDesc==pTab->bDescIdx
138694 && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
 
138695 #ifdef SQLITE_TEST
138696 && pTab->bNoIncrDoclist==0
138697 #endif
138698 );
138699 for(i=0; bIncrOk==1 && i<p->nToken; i++){
@@ -138606,10 +138809,11 @@
138809 if( p==0 ){
138810 p = aDoclist;
138811 p += sqlite3Fts3GetVarint(p, piDocid);
138812 }else{
138813 fts3PoslistCopy(0, &p);
138814 while( p<&aDoclist[nDoclist] && *p==0 ) p++;
138815 if( p>=&aDoclist[nDoclist] ){
138816 *pbEof = 1;
138817 }else{
138818 sqlite3_int64 iVar;
138819 p += sqlite3Fts3GetVarint(p, &iVar);
@@ -140012,14 +140216,14 @@
140216 pIter = pPhrase->doclist.pList;
140217 if( iDocid!=pCsr->iPrevId || pExpr->bEof ){
140218 int rc = SQLITE_OK;
140219 int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */
140220 int bOr = 0;
 
140221 u8 bTreeEof = 0;
140222 Fts3Expr *p; /* Used to iterate from pExpr to root */
140223 Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */
140224 int bMatch;
140225
140226 /* Check if this phrase descends from an OR expression node. If not,
140227 ** return NULL. Otherwise, the entry that corresponds to docid
140228 ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
140229 ** tree that the node is part of has been marked as EOF, but the node
@@ -140049,35 +140253,51 @@
140253 fts3EvalNextRow(pCsr, pNear, &rc);
140254 }
140255 }
140256 if( rc!=SQLITE_OK ) return rc;
140257
140258 bMatch = 1;
140259 for(p=pNear; p; p=p->pLeft){
140260 u8 bEof = 0;
140261 Fts3Expr *pTest = p;
140262 Fts3Phrase *pPh;
140263 assert( pTest->eType==FTSQUERY_NEAR || pTest->eType==FTSQUERY_PHRASE );
140264 if( pTest->eType==FTSQUERY_NEAR ) pTest = pTest->pRight;
140265 assert( pTest->eType==FTSQUERY_PHRASE );
140266 pPh = pTest->pPhrase;
140267
140268 pIter = pPh->pOrPoslist;
140269 iDocid = pPh->iOrDocid;
140270 if( pCsr->bDesc==bDescDoclist ){
140271 bEof = !pPh->doclist.nAll ||
140272 (pIter >= (pPh->doclist.aAll + pPh->doclist.nAll));
140273 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
140274 sqlite3Fts3DoclistNext(
140275 bDescDoclist, pPh->doclist.aAll, pPh->doclist.nAll,
140276 &pIter, &iDocid, &bEof
140277 );
140278 }
140279 }else{
140280 bEof = !pPh->doclist.nAll || (pIter && pIter<=pPh->doclist.aAll);
140281 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
140282 int dummy;
140283 sqlite3Fts3DoclistPrev(
140284 bDescDoclist, pPh->doclist.aAll, pPh->doclist.nAll,
140285 &pIter, &iDocid, &dummy, &bEof
140286 );
140287 }
140288 }
140289 pPh->pOrPoslist = pIter;
140290 pPh->iOrDocid = iDocid;
140291 if( bEof || iDocid!=pCsr->iPrevId ) bMatch = 0;
140292 }
140293
140294 if( bMatch ){
140295 pIter = pPhrase->pOrPoslist;
140296 }else{
140297 pIter = 0;
140298 }
140299 }
140300 if( pIter==0 ) return SQLITE_OK;
140301
140302 if( *pIter==0x01 ){
140303 pIter++;
@@ -140161,10 +140381,11 @@
140381 ** May you share freely, never taking more than you give.
140382 **
140383 ******************************************************************************
140384 **
140385 */
140386 /* #include "fts3Int.h" */
140387 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
140388
140389 /* #include <string.h> */
140390 /* #include <assert.h> */
140391
@@ -140717,10 +140938,11 @@
140938 ** This module contains code that implements a parser for fts3 query strings
140939 ** (the right-hand argument to the MATCH operator). Because the supported
140940 ** syntax is relatively simple, the whole tokenizer/parser system is
140941 ** hand-coded.
140942 */
140943 /* #include "fts3Int.h" */
140944 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
140945
140946 /*
140947 ** By default, this module parses the legacy syntax that has been
140948 ** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS
@@ -142010,16 +142232,18 @@
142232 ** (in which case SQLITE_CORE is not defined), or
142233 **
142234 ** * The FTS3 module is being built into the core of
142235 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
142236 */
142237 /* #include "fts3Int.h" */
142238 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
142239
142240 /* #include <assert.h> */
142241 /* #include <stdlib.h> */
142242 /* #include <string.h> */
142243
142244 /* #include "fts3_hash.h" */
142245
142246 /*
142247 ** Malloc and Free functions
142248 */
142249 static void *fts3HashMalloc(int n){
@@ -142393,17 +142617,19 @@
142617 ** (in which case SQLITE_CORE is not defined), or
142618 **
142619 ** * The FTS3 module is being built into the core of
142620 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
142621 */
142622 /* #include "fts3Int.h" */
142623 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
142624
142625 /* #include <assert.h> */
142626 /* #include <stdlib.h> */
142627 /* #include <stdio.h> */
142628 /* #include <string.h> */
142629
142630 /* #include "fts3_tokenizer.h" */
142631
142632 /*
142633 ** Class derived from sqlite3_tokenizer
142634 */
142635 typedef struct porter_tokenizer {
@@ -143057,10 +143283,11 @@
143283 ** (in which case SQLITE_CORE is not defined), or
143284 **
143285 ** * The FTS3 module is being built into the core of
143286 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
143287 */
143288 /* #include "fts3Int.h" */
143289 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143290
143291 /* #include <assert.h> */
143292 /* #include <string.h> */
143293
@@ -143552,17 +143779,19 @@
143779 ** (in which case SQLITE_CORE is not defined), or
143780 **
143781 ** * The FTS3 module is being built into the core of
143782 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
143783 */
143784 /* #include "fts3Int.h" */
143785 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143786
143787 /* #include <assert.h> */
143788 /* #include <stdlib.h> */
143789 /* #include <stdio.h> */
143790 /* #include <string.h> */
143791
143792 /* #include "fts3_tokenizer.h" */
143793
143794 typedef struct simple_tokenizer {
143795 sqlite3_tokenizer base;
143796 char delim[128]; /* flag ASCII delimiters */
143797 } simple_tokenizer;
@@ -143803,10 +144032,11 @@
144032 ** end: Byte offset of the byte immediately following the end of the
144033 ** token within the input string.
144034 ** pos: Token offset of token within input.
144035 **
144036 */
144037 /* #include "fts3Int.h" */
144038 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
144039
144040 /* #include <string.h> */
144041 /* #include <assert.h> */
144042
@@ -144238,10 +144468,11 @@
144468 ** tables. It also contains code to merge FTS3 b-tree segments. Some
144469 ** of the sub-routines used to merge segments are also used by the query
144470 ** code in fts3.c.
144471 */
144472
144473 /* #include "fts3Int.h" */
144474 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
144475
144476 /* #include <string.h> */
144477 /* #include <assert.h> */
144478 /* #include <stdlib.h> */
@@ -149898,10 +150129,11 @@
150129 ** May you share freely, never taking more than you give.
150130 **
150131 ******************************************************************************
150132 */
150133
150134 /* #include "fts3Int.h" */
150135 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
150136
150137 /* #include <string.h> */
150138 /* #include <assert.h> */
150139
@@ -151610,17 +151842,19 @@
151842 ** Implementation of the "unicode" full-text-search tokenizer.
151843 */
151844
151845 #ifndef SQLITE_DISABLE_FTS3_UNICODE
151846
151847 /* #include "fts3Int.h" */
151848 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
151849
151850 /* #include <assert.h> */
151851 /* #include <stdlib.h> */
151852 /* #include <stdio.h> */
151853 /* #include <string.h> */
151854
151855 /* #include "fts3_tokenizer.h" */
151856
151857 /*
151858 ** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
151859 ** from the sqlite3 source file utf.c. If this file is compiled as part
151860 ** of the amalgamation, they are not required.
@@ -152412,12 +152646,14 @@
152646 */
152647
152648 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
152649
152650 #ifndef SQLITE_CORE
152651 /* #include "sqlite3ext.h" */
152652 SQLITE_EXTENSION_INIT1
152653 #else
152654 /* #include "sqlite3.h" */
152655 #endif
152656
152657 /* #include <string.h> */
152658 /* #include <assert.h> */
152659 /* #include <stdio.h> */
@@ -155909,12 +156145,14 @@
156145 #include <unicode/ucol.h>
156146
156147 /* #include <assert.h> */
156148
156149 #ifndef SQLITE_CORE
156150 /* #include "sqlite3ext.h" */
156151 SQLITE_EXTENSION_INIT1
156152 #else
156153 /* #include "sqlite3.h" */
156154 #endif
156155
156156 /*
156157 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
156158 ** operator.
@@ -156386,15 +156624,17 @@
156624 ** May you share freely, never taking more than you give.
156625 **
156626 *************************************************************************
156627 ** This file implements a tokenizer for fts3 based on the ICU library.
156628 */
156629 /* #include "fts3Int.h" */
156630 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
156631 #ifdef SQLITE_ENABLE_ICU
156632
156633 /* #include <assert.h> */
156634 /* #include <string.h> */
156635 /* #include "fts3_tokenizer.h" */
156636
156637 #include <unicode/ubrk.h>
156638 /* #include <unicode/ucol.h> */
156639 /* #include <unicode/ustring.h> */
156640 #include <unicode/utf16.h>
@@ -156635,11 +156875,11 @@
156875
156876 #endif /* defined(SQLITE_ENABLE_ICU) */
156877 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
156878
156879 /************** End of fts3_icu.c ********************************************/
156880 /************** Begin file sqlite3rbu.c **************************************/
156881 /*
156882 ** 2014 August 30
156883 **
156884 ** The author disclaims copyright to this source code. In place of
156885 ** a legal notice, here is a blessing:
@@ -156651,15 +156891,15 @@
156891 *************************************************************************
156892 **
156893 **
156894 ** OVERVIEW
156895 **
156896 ** The RBU extension requires that the RBU update be packaged as an
156897 ** SQLite database. The tables it expects to find are described in
156898 ** sqlite3rbu.h. Essentially, for each table xyz in the target database
156899 ** that the user wishes to write to, a corresponding data_xyz table is
156900 ** created in the RBU database and populated with one row for each row to
156901 ** update, insert or delete from the target table.
156902 **
156903 ** The update proceeds in three stages:
156904 **
156905 ** 1) The database is updated. The modified database pages are written
@@ -156667,70 +156907,74 @@
156907 ** that it is named "<database>-oal" instead of "<database>-wal".
156908 ** Because regular SQLite clients do not look for file named
156909 ** "<database>-oal", they go on using the original database in
156910 ** rollback mode while the *-oal file is being generated.
156911 **
156912 ** During this stage RBU does not update the database by writing
156913 ** directly to the target tables. Instead it creates "imposter"
156914 ** tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses
156915 ** to update each b-tree individually. All updates required by each
156916 ** b-tree are completed before moving on to the next, and all
156917 ** updates are done in sorted key order.
156918 **
156919 ** 2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
156920 ** location using a call to rename(2). Before doing this the RBU
156921 ** module takes an EXCLUSIVE lock on the database file, ensuring
156922 ** that there are no other active readers.
156923 **
156924 ** Once the EXCLUSIVE lock is released, any other database readers
156925 ** detect the new *-wal file and read the database in wal mode. At
156926 ** this point they see the new version of the database - including
156927 ** the updates made as part of the RBU update.
156928 **
156929 ** 3) The new *-wal file is checkpointed. This proceeds in the same way
156930 ** as a regular database checkpoint, except that a single frame is
156931 ** checkpointed each time sqlite3rbu_step() is called. If the RBU
156932 ** handle is closed before the entire *-wal file is checkpointed,
156933 ** the checkpoint progress is saved in the RBU database and the
156934 ** checkpoint can be resumed by another RBU client at some point in
156935 ** the future.
156936 **
156937 ** POTENTIAL PROBLEMS
156938 **
156939 ** The rename() call might not be portable. And RBU is not currently
156940 ** syncing the directory after renaming the file.
156941 **
156942 ** When state is saved, any commit to the *-oal file and the commit to
156943 ** the RBU update database are not atomic. So if the power fails at the
156944 ** wrong moment they might get out of sync. As the main database will be
156945 ** committed before the RBU update database this will likely either just
156946 ** pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
156947 ** constraint violations).
156948 **
156949 ** If some client does modify the target database mid RBU update, or some
156950 ** other error occurs, the RBU extension will keep throwing errors. It's
156951 ** not really clear how to get out of this state. The system could just
156952 ** by delete the RBU update database and *-oal file and have the device
156953 ** download the update again and start over.
156954 **
156955 ** At present, for an UPDATE, both the new.* and old.* records are
156956 ** collected in the rbu_xyz table. And for both UPDATEs and DELETEs all
156957 ** fields are collected. This means we're probably writing a lot more
156958 ** data to disk when saving the state of an ongoing update to the RBU
156959 ** update database than is strictly necessary.
156960 **
156961 */
156962
156963 /* #include <assert.h> */
156964 /* #include <string.h> */
156965 /* #include <stdio.h> */
 
156966
156967 #if !defined(_WIN32)
156968 /* # include <unistd.h> */
156969 #endif
156970
156971 /* #include "sqlite3.h" */
156972
156973 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
156974 /************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
156975 /************** Begin file sqlite3rbu.h **************************************/
156976 /*
156977 ** 2014 August 30
156978 **
156979 ** The author disclaims copyright to this source code. In place of
156980 ** a legal notice, here is a blessing:
@@ -156739,11 +156983,11 @@
156983 ** May you find forgiveness for yourself and forgive others.
156984 ** May you share freely, never taking more than you give.
156985 **
156986 *************************************************************************
156987 **
156988 ** This file contains the public interface for the RBU extension.
156989 */
156990
156991 /*
156992 ** SUMMARY
156993 **
@@ -156776,18 +157020,18 @@
157020 ** mobile device that is frequently rebooted. Even after the writer process
157021 ** has committed one or more sub-transactions, other database clients continue
157022 ** to read from the original database snapshot. In other words, partially
157023 ** applied transactions are not visible to other clients.
157024 **
157025 ** "RBU" stands for "Resumable Bulk Update". As in a large database update
157026 ** transmitted via a wireless network to a mobile device. A transaction
157027 ** applied using this extension is hence refered to as an "RBU update".
157028 **
157029 **
157030 ** LIMITATIONS
157031 **
157032 ** An "RBU update" transaction is subject to the following limitations:
157033 **
157034 ** * The transaction must consist of INSERT, UPDATE and DELETE operations
157035 ** only.
157036 **
157037 ** * INSERT statements may not use any default values.
@@ -156808,430 +157052,430 @@
157052 ** * No constraint handling mode except for "OR ROLLBACK" is supported.
157053 **
157054 **
157055 ** PREPARATION
157056 **
157057 ** An "RBU update" is stored as a separate SQLite database. A database
157058 ** containing an RBU update is an "RBU database". For each table in the
157059 ** target database to be updated, the RBU database should contain a table
157060 ** named "data_<target name>" containing the same set of columns as the
157061 ** target table, and one more - "rbu_control". The data_% table should
157062 ** have no PRIMARY KEY or UNIQUE constraints, but each column should have
157063 ** the same type as the corresponding column in the target database.
157064 ** The "rbu_control" column should have no type at all. For example, if
157065 ** the target database contains:
157066 **
157067 ** CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE);
157068 **
157069 ** Then the RBU database should contain:
157070 **
157071 ** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
157072 **
157073 ** The order of the columns in the data_% table does not matter.
157074 **
157075 ** If the target database table is a virtual table or a table that has no
157076 ** PRIMARY KEY declaration, the data_% table must also contain a column
157077 ** named "rbu_rowid". This column is mapped to the tables implicit primary
157078 ** key column - "rowid". Virtual tables for which the "rowid" column does
157079 ** not function like a primary key value cannot be updated using RBU. For
157080 ** example, if the target db contains either of the following:
157081 **
157082 ** CREATE VIRTUAL TABLE x1 USING fts3(a, b);
157083 ** CREATE TABLE x1(a, b)
157084 **
157085 ** then the RBU database should contain:
157086 **
157087 ** CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control);
157088 **
157089 ** All non-hidden columns (i.e. all columns matched by "SELECT *") of the
157090 ** target table must be present in the input table. For virtual tables,
157091 ** hidden columns are optional - they are updated by RBU if present in
157092 ** the input table, or not otherwise. For example, to write to an fts4
157093 ** table with a hidden languageid column such as:
157094 **
157095 ** CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid');
157096 **
157097 ** Either of the following input table schemas may be used:
157098 **
157099 ** CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control);
157100 ** CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control);
157101 **
157102 ** For each row to INSERT into the target database as part of the RBU
157103 ** update, the corresponding data_% table should contain a single record
157104 ** with the "rbu_control" column set to contain integer value 0. The
157105 ** other columns should be set to the values that make up the new record
157106 ** to insert.
157107 **
157108 ** If the target database table has an INTEGER PRIMARY KEY, it is not
157109 ** possible to insert a NULL value into the IPK column. Attempting to
157110 ** do so results in an SQLITE_MISMATCH error.
157111 **
157112 ** For each row to DELETE from the target database as part of the RBU
157113 ** update, the corresponding data_% table should contain a single record
157114 ** with the "rbu_control" column set to contain integer value 1. The
157115 ** real primary key values of the row to delete should be stored in the
157116 ** corresponding columns of the data_% table. The values stored in the
157117 ** other columns are not used.
157118 **
157119 ** For each row to UPDATE from the target database as part of the RBU
157120 ** update, the corresponding data_% table should contain a single record
157121 ** with the "rbu_control" column set to contain a value of type text.
157122 ** The real primary key values identifying the row to update should be
157123 ** stored in the corresponding columns of the data_% table row, as should
157124 ** the new values of all columns being update. The text value in the
157125 ** "rbu_control" column must contain the same number of characters as
157126 ** there are columns in the target database table, and must consist entirely
157127 ** of 'x' and '.' characters (or in some special cases 'd' - see below). For
157128 ** each column that is being updated, the corresponding character is set to
157129 ** 'x'. For those that remain as they are, the corresponding character of the
157130 ** rbu_control value should be set to '.'. For example, given the tables
157131 ** above, the update statement:
157132 **
157133 ** UPDATE t1 SET c = 'usa' WHERE a = 4;
157134 **
157135 ** is represented by the data_t1 row created by:
157136 **
157137 ** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..x');
157138 **
157139 ** Instead of an 'x' character, characters of the rbu_control value specified
157140 ** for UPDATEs may also be set to 'd'. In this case, instead of updating the
157141 ** target table with the value stored in the corresponding data_% column, the
157142 ** user-defined SQL function "rbu_delta()" is invoked and the result stored in
157143 ** the target table column. rbu_delta() is invoked with two arguments - the
157144 ** original value currently stored in the target table column and the
157145 ** value specified in the data_xxx table.
157146 **
157147 ** For example, this row:
157148 **
157149 ** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
157150 **
157151 ** is similar to an UPDATE statement such as:
157152 **
157153 ** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
157154 **
157155 ** If the target database table is a virtual table or a table with no PRIMARY
157156 ** KEY, the rbu_control value should not include a character corresponding
157157 ** to the rbu_rowid value. For example, this:
157158 **
157159 ** INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control)
157160 ** VALUES(NULL, 'usa', 12, '.x');
157161 **
157162 ** causes a result similar to:
157163 **
157164 ** UPDATE ft1 SET b = 'usa' WHERE rowid = 12;
157165 **
157166 ** The data_xxx tables themselves should have no PRIMARY KEY declarations.
157167 ** However, RBU is more efficient if reading the rows in from each data_xxx
157168 ** table in "rowid" order is roughly the same as reading them sorted by
157169 ** the PRIMARY KEY of the corresponding target database table. In other
157170 ** words, rows should be sorted using the destination table PRIMARY KEY
157171 ** fields before they are inserted into the data_xxx tables.
157172 **
157173 ** USAGE
157174 **
157175 ** The API declared below allows an application to apply an RBU update
157176 ** stored on disk to an existing target database. Essentially, the
157177 ** application:
157178 **
157179 ** 1) Opens an RBU handle using the sqlite3rbu_open() function.
157180 **
157181 ** 2) Registers any required virtual table modules with the database
157182 ** handle returned by sqlite3rbu_db(). Also, if required, register
157183 ** the rbu_delta() implementation.
157184 **
157185 ** 3) Calls the sqlite3rbu_step() function one or more times on
157186 ** the new handle. Each call to sqlite3rbu_step() performs a single
157187 ** b-tree operation, so thousands of calls may be required to apply
157188 ** a complete update.
157189 **
157190 ** 4) Calls sqlite3rbu_close() to close the RBU update handle. If
157191 ** sqlite3rbu_step() has been called enough times to completely
157192 ** apply the update to the target database, then the RBU database
157193 ** is marked as fully applied. Otherwise, the state of the RBU
157194 ** update application is saved in the RBU database for later
157195 ** resumption.
157196 **
157197 ** See comments below for more detail on APIs.
157198 **
157199 ** If an update is only partially applied to the target database by the
157200 ** time sqlite3rbu_close() is called, various state information is saved
157201 ** within the RBU database. This allows subsequent processes to automatically
157202 ** resume the RBU update from where it left off.
157203 **
157204 ** To remove all RBU extension state information, returning an RBU database
157205 ** to its original contents, it is sufficient to drop all tables that begin
157206 ** with the prefix "rbu_"
157207 **
157208 ** DATABASE LOCKING
157209 **
157210 ** An RBU update may not be applied to a database in WAL mode. Attempting
157211 ** to do so is an error (SQLITE_ERROR).
157212 **
157213 ** While an RBU handle is open, a SHARED lock may be held on the target
157214 ** database file. This means it is possible for other clients to read the
157215 ** database, but not to write it.
157216 **
157217 ** If an RBU update is started and then suspended before it is completed,
157218 ** then an external client writes to the database, then attempting to resume
157219 ** the suspended RBU update is also an error (SQLITE_BUSY).
157220 */
157221
157222 #ifndef _SQLITE3RBU_H
157223 #define _SQLITE3RBU_H
157224
157225 /* #include "sqlite3.h" ** Required for error code definitions ** */
157226
157227 typedef struct sqlite3rbu sqlite3rbu;
157228
157229 /*
157230 ** Open an RBU handle.
157231 **
157232 ** Argument zTarget is the path to the target database. Argument zRbu is
157233 ** the path to the RBU database. Each call to this function must be matched
157234 ** by a call to sqlite3rbu_close(). When opening the databases, RBU passes
157235 ** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget
157236 ** or zRbu begin with "file:", it will be interpreted as an SQLite
157237 ** database URI, not a regular file name.
157238 **
157239 ** If the zState argument is passed a NULL value, the RBU extension stores
157240 ** the current state of the update (how many rows have been updated, which
157241 ** indexes are yet to be updated etc.) within the RBU database itself. This
157242 ** can be convenient, as it means that the RBU application does not need to
157243 ** organize removing a separate state file after the update is concluded.
157244 ** Or, if zState is non-NULL, it must be a path to a database file in which
157245 ** the RBU extension can store the state of the update.
157246 **
157247 ** When resuming an RBU update, the zState argument must be passed the same
157248 ** value as when the RBU update was started.
157249 **
157250 ** Once the RBU update is finished, the RBU extension does not
157251 ** automatically remove any zState database file, even if it created it.
157252 **
157253 ** By default, RBU uses the default VFS to access the files on disk. To
157254 ** use a VFS other than the default, an SQLite "file:" URI containing a
157255 ** "vfs=..." option may be passed as the zTarget option.
157256 **
157257 ** IMPORTANT NOTE FOR ZIPVFS USERS: The RBU extension works with all of
157258 ** SQLite's built-in VFSs, including the multiplexor VFS. However it does
157259 ** not work out of the box with zipvfs. Refer to the comment describing
157260 ** the zipvfs_create_vfs() API below for details on using RBU with zipvfs.
157261 */
157262 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
157263 const char *zTarget,
157264 const char *zRbu,
157265 const char *zState
157266 );
157267
157268 /*
157269 ** Internally, each RBU connection uses a separate SQLite database
157270 ** connection to access the target and rbu update databases. This
157271 ** API allows the application direct access to these database handles.
157272 **
157273 ** The first argument passed to this function must be a valid, open, RBU
157274 ** handle. The second argument should be passed zero to access the target
157275 ** database handle, or non-zero to access the rbu update database handle.
157276 ** Accessing the underlying database handles may be useful in the
157277 ** following scenarios:
157278 **
157279 ** * If any target tables are virtual tables, it may be necessary to
157280 ** call sqlite3_create_module() on the target database handle to
157281 ** register the required virtual table implementations.
157282 **
157283 ** * If the data_xxx tables in the RBU source database are virtual
157284 ** tables, the application may need to call sqlite3_create_module() on
157285 ** the rbu update db handle to any required virtual table
157286 ** implementations.
157287 **
157288 ** * If the application uses the "rbu_delta()" feature described above,
157289 ** it must use sqlite3_create_function() or similar to register the
157290 ** rbu_delta() implementation with the target database handle.
157291 **
157292 ** If an error has occurred, either while opening or stepping the RBU object,
157293 ** this function may return NULL. The error code and message may be collected
157294 ** when sqlite3rbu_close() is called.
157295 */
157296 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu*, int bRbu);
157297
157298 /*
157299 ** Do some work towards applying the RBU update to the target db.
157300 **
157301 ** Return SQLITE_DONE if the update has been completely applied, or
157302 ** SQLITE_OK if no error occurs but there remains work to do to apply
157303 ** the RBU update. If an error does occur, some other error code is
157304 ** returned.
157305 **
157306 ** Once a call to sqlite3rbu_step() has returned a value other than
157307 ** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
157308 ** that immediately return the same value.
157309 */
157310 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu);
157311
157312 /*
157313 ** Close an RBU handle.
157314 **
157315 ** If the RBU update has been completely applied, mark the RBU database
157316 ** as fully applied. Otherwise, assuming no error has occurred, save the
157317 ** current state of the RBU update appliation to the RBU database.
157318 **
157319 ** If an error has already occurred as part of an sqlite3rbu_step()
157320 ** or sqlite3rbu_open() call, or if one occurs within this function, an
157321 ** SQLite error code is returned. Additionally, *pzErrmsg may be set to
157322 ** point to a buffer containing a utf-8 formatted English language error
157323 ** message. It is the responsibility of the caller to eventually free any
157324 ** such buffer using sqlite3_free().
157325 **
157326 ** Otherwise, if no error occurs, this function returns SQLITE_OK if the
157327 ** update has been partially applied, or SQLITE_DONE if it has been
157328 ** completely applied.
157329 */
157330 SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *pRbu, char **pzErrmsg);
157331
157332 /*
157333 ** Return the total number of key-value operations (inserts, deletes or
157334 ** updates) that have been performed on the target database since the
157335 ** current RBU update was started.
157336 */
157337 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu);
157338
157339 /*
157340 ** Create an RBU VFS named zName that accesses the underlying file-system
157341 ** via existing VFS zParent. Or, if the zParent parameter is passed NULL,
157342 ** then the new RBU VFS uses the default system VFS to access the file-system.
157343 ** The new object is registered as a non-default VFS with SQLite before
157344 ** returning.
157345 **
157346 ** Part of the RBU implementation uses a custom VFS object. Usually, this
157347 ** object is created and deleted automatically by RBU.
157348 **
157349 ** The exception is for applications that also use zipvfs. In this case,
157350 ** the custom VFS must be explicitly created by the user before the RBU
157351 ** handle is opened. The RBU VFS should be installed so that the zipvfs
157352 ** VFS uses the RBU VFS, which in turn uses any other VFS layers in use
157353 ** (for example multiplexor) to access the file-system. For example,
157354 ** to assemble an RBU enabled VFS stack that uses both zipvfs and
157355 ** multiplexor (error checking omitted):
157356 **
157357 ** // Create a VFS named "multiplex" (not the default).
157358 ** sqlite3_multiplex_initialize(0, 0);
157359 **
157360 ** // Create an rbu VFS named "rbu" that uses multiplexor. If the
157361 ** // second argument were replaced with NULL, the "rbu" VFS would
157362 ** // access the file-system via the system default VFS, bypassing the
157363 ** // multiplexor.
157364 ** sqlite3rbu_create_vfs("rbu", "multiplex");
157365 **
157366 ** // Create a zipvfs VFS named "zipvfs" that uses rbu.
157367 ** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector);
157368 **
157369 ** // Make zipvfs the default VFS.
157370 ** sqlite3_vfs_register(sqlite3_vfs_find("zipvfs"), 1);
157371 **
157372 ** Because the default VFS created above includes a RBU functionality, it
157373 ** may be used by RBU clients. Attempting to use RBU with a zipvfs VFS stack
157374 ** that does not include the RBU layer results in an error.
157375 **
157376 ** The overhead of adding the "rbu" VFS to the system is negligible for
157377 ** non-RBU users. There is no harm in an application accessing the
157378 ** file-system via "rbu" all the time, even if it only uses RBU functionality
157379 ** occasionally.
157380 */
157381 SQLITE_API int SQLITE_STDCALL sqlite3rbu_create_vfs(const char *zName, const char *zParent);
157382
157383 /*
157384 ** Deregister and destroy an RBU vfs created by an earlier call to
157385 ** sqlite3rbu_create_vfs().
157386 **
157387 ** VFS objects are not reference counted. If a VFS object is destroyed
157388 ** before all database handles that use it have been closed, the results
157389 ** are undefined.
157390 */
157391 SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName);
157392
157393 #endif /* _SQLITE3RBU_H */
157394
157395 /************** End of sqlite3rbu.h ******************************************/
157396 /************** Continuing where we left off in sqlite3rbu.c *****************/
 
157397
157398 /* Maximum number of prepared UPDATE statements held by this module */
157399 #define SQLITE_RBU_UPDATE_CACHESIZE 16
157400
157401 /*
157402 ** Swap two objects of type TYPE.
157403 */
157404 #if !defined(SQLITE_AMALGAMATION)
157405 # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
157406 #endif
157407
157408 /*
157409 ** The rbu_state table is used to save the state of a partially applied
157410 ** update so that it can be resumed later. The table consists of integer
157411 ** keys mapped to values as follows:
157412 **
157413 ** RBU_STATE_STAGE:
157414 ** May be set to integer values 1, 2, 4 or 5. As follows:
157415 ** 1: the *-rbu file is currently under construction.
157416 ** 2: the *-rbu file has been constructed, but not yet moved
157417 ** to the *-wal path.
157418 ** 4: the checkpoint is underway.
157419 ** 5: the rbu update has been checkpointed.
157420 **
157421 ** RBU_STATE_TBL:
157422 ** Only valid if STAGE==1. The target database name of the table
157423 ** currently being written.
157424 **
157425 ** RBU_STATE_IDX:
157426 ** Only valid if STAGE==1. The target database name of the index
157427 ** currently being written, or NULL if the main table is currently being
157428 ** updated.
157429 **
157430 ** RBU_STATE_ROW:
157431 ** Only valid if STAGE==1. Number of rows already processed for the current
157432 ** table/index.
157433 **
157434 ** RBU_STATE_PROGRESS:
157435 ** Trbul number of sqlite3rbu_step() calls made so far as part of this
157436 ** rbu update.
157437 **
157438 ** RBU_STATE_CKPT:
157439 ** Valid if STAGE==4. The 64-bit checksum associated with the wal-index
157440 ** header created by recovering the *-wal file. This is used to detect
157441 ** cases when another client appends frames to the *-wal file in the
157442 ** middle of an incremental checkpoint (an incremental checkpoint cannot
157443 ** be continued if this happens).
157444 **
157445 ** RBU_STATE_COOKIE:
157446 ** Valid if STAGE==1. The current change-counter cookie value in the
157447 ** target db file.
157448 **
157449 ** RBU_STATE_OALSZ:
157450 ** Valid if STAGE==1. The size in bytes of the *-oal file.
157451 */
157452 #define RBU_STATE_STAGE 1
157453 #define RBU_STATE_TBL 2
157454 #define RBU_STATE_IDX 3
157455 #define RBU_STATE_ROW 4
157456 #define RBU_STATE_PROGRESS 5
157457 #define RBU_STATE_CKPT 6
157458 #define RBU_STATE_COOKIE 7
157459 #define RBU_STATE_OALSZ 8
157460
157461 #define RBU_STAGE_OAL 1
157462 #define RBU_STAGE_MOVE 2
157463 #define RBU_STAGE_CAPTURE 3
157464 #define RBU_STAGE_CKPT 4
157465 #define RBU_STAGE_DONE 5
157466
157467
157468 #define RBU_CREATE_STATE \
157469 "CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)"
157470
157471 typedef struct RbuFrame RbuFrame;
157472 typedef struct RbuObjIter RbuObjIter;
157473 typedef struct RbuState RbuState;
157474 typedef struct rbu_vfs rbu_vfs;
157475 typedef struct rbu_file rbu_file;
157476 typedef struct RbuUpdateStmt RbuUpdateStmt;
157477
157478 #if !defined(SQLITE_AMALGAMATION)
157479 typedef unsigned int u32;
157480 typedef unsigned char u8;
157481 typedef sqlite3_int64 i64;
@@ -157245,13 +157489,13 @@
157489 #define WAL_LOCK_WRITE 0
157490 #define WAL_LOCK_CKPT 1
157491 #define WAL_LOCK_READ0 3
157492
157493 /*
157494 ** A structure to store values read from the rbu_state table in memory.
157495 */
157496 struct RbuState {
157497 int eStage;
157498 char *zTbl;
157499 char *zIdx;
157500 i64 iWalCksum;
157501 int nRow;
@@ -157258,14 +157502,14 @@
157502 i64 nProgress;
157503 u32 iCookie;
157504 i64 iOalSz;
157505 };
157506
157507 struct RbuUpdateStmt {
157508 char *zMask; /* Copy of update mask used with pUpdate */
157509 sqlite3_stmt *pUpdate; /* Last update statement (or NULL) */
157510 RbuUpdateStmt *pNext;
157511 };
157512
157513 /*
157514 ** An iterator of this type is used to iterate through all objects in
157515 ** the target database that require updating. For each such table, the
@@ -157280,131 +157524,131 @@
157524 ** it points to an array of flags nTblCol elements in size. The flag is
157525 ** set for each column that is either a part of the PK or a part of an
157526 ** index. Or clear otherwise.
157527 **
157528 */
157529 struct RbuObjIter {
157530 sqlite3_stmt *pTblIter; /* Iterate through tables */
157531 sqlite3_stmt *pIdxIter; /* Index iterator */
157532 int nTblCol; /* Size of azTblCol[] array */
157533 char **azTblCol; /* Array of unquoted target column names */
157534 char **azTblType; /* Array of target column types */
157535 int *aiSrcOrder; /* src table col -> target table col */
157536 u8 *abTblPk; /* Array of flags, set on target PK columns */
157537 u8 *abNotNull; /* Array of flags, set on NOT NULL columns */
157538 u8 *abIndexed; /* Array of flags, set on indexed & PK cols */
157539 int eType; /* Table type - an RBU_PK_XXX value */
157540
157541 /* Output variables. zTbl==0 implies EOF. */
157542 int bCleanup; /* True in "cleanup" state */
157543 const char *zTbl; /* Name of target db table */
157544 const char *zIdx; /* Name of target db index (or null) */
157545 int iTnum; /* Root page of current object */
157546 int iPkTnum; /* If eType==EXTERNAL, root of PK index */
157547 int bUnique; /* Current index is unique */
157548
157549 /* Statements created by rbuObjIterPrepareAll() */
157550 int nCol; /* Number of columns in current object */
157551 sqlite3_stmt *pSelect; /* Source data */
157552 sqlite3_stmt *pInsert; /* Statement for INSERT operations */
157553 sqlite3_stmt *pDelete; /* Statement for DELETE ops */
157554 sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zTbl */
157555
157556 /* Last UPDATE used (for PK b-tree updates only), or NULL. */
157557 RbuUpdateStmt *pRbuUpdate;
157558 };
157559
157560 /*
157561 ** Values for RbuObjIter.eType
157562 **
157563 ** 0: Table does not exist (error)
157564 ** 1: Table has an implicit rowid.
157565 ** 2: Table has an explicit IPK column.
157566 ** 3: Table has an external PK index.
157567 ** 4: Table is WITHOUT ROWID.
157568 ** 5: Table is a virtual table.
157569 */
157570 #define RBU_PK_NOTABLE 0
157571 #define RBU_PK_NONE 1
157572 #define RBU_PK_IPK 2
157573 #define RBU_PK_EXTERNAL 3
157574 #define RBU_PK_WITHOUT_ROWID 4
157575 #define RBU_PK_VTAB 5
157576
157577
157578 /*
157579 ** Within the RBU_STAGE_OAL stage, each call to sqlite3rbu_step() performs
157580 ** one of the following operations.
157581 */
157582 #define RBU_INSERT 1 /* Insert on a main table b-tree */
157583 #define RBU_DELETE 2 /* Delete a row from a main table b-tree */
157584 #define RBU_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */
157585 #define RBU_IDX_INSERT 4 /* Insert on an aux. index b-tree */
157586 #define RBU_UPDATE 5 /* Update a row in a main table b-tree */
157587
157588
157589 /*
157590 ** A single step of an incremental checkpoint - frame iWalFrame of the wal
157591 ** file should be copied to page iDbPage of the database file.
157592 */
157593 struct RbuFrame {
157594 u32 iDbPage;
157595 u32 iWalFrame;
157596 };
157597
157598 /*
157599 ** RBU handle.
157600 */
157601 struct sqlite3rbu {
157602 int eStage; /* Value of RBU_STATE_STAGE field */
157603 sqlite3 *dbMain; /* target database handle */
157604 sqlite3 *dbRbu; /* rbu database handle */
157605 char *zTarget; /* Path to target db */
157606 char *zRbu; /* Path to rbu db */
157607 char *zState; /* Path to state db (or NULL if zRbu) */
157608 char zStateDb[5]; /* Db name for state ("stat" or "main") */
157609 int rc; /* Value returned by last rbu_step() call */
157610 char *zErrmsg; /* Error message if rc!=SQLITE_OK */
157611 int nStep; /* Rows processed for current object */
157612 int nProgress; /* Rows processed for all objects */
157613 RbuObjIter objiter; /* Iterator for skipping through tbl/idx */
157614 const char *zVfsName; /* Name of automatically created rbu vfs */
157615 rbu_file *pTargetFd; /* File handle open on target db */
157616 i64 iOalSz;
157617
157618 /* The following state variables are used as part of the incremental
157619 ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding
157620 ** function rbuSetupCheckpoint() for details. */
157621 u32 iMaxFrame; /* Largest iWalFrame value in aFrame[] */
157622 u32 mLock;
157623 int nFrame; /* Entries in aFrame[] array */
157624 int nFrameAlloc; /* Allocated size of aFrame[] array */
157625 RbuFrame *aFrame;
157626 int pgsz;
157627 u8 *aBuf;
157628 i64 iWalCksum;
157629 };
157630
157631 /*
157632 ** An rbu VFS is implemented using an instance of this structure.
157633 */
157634 struct rbu_vfs {
157635 sqlite3_vfs base; /* rbu VFS shim methods */
157636 sqlite3_vfs *pRealVfs; /* Underlying VFS */
157637 sqlite3_mutex *mutex; /* Mutex to protect pMain */
157638 rbu_file *pMain; /* Linked list of main db files */
157639 };
157640
157641 /*
157642 ** Each file opened by an rbu VFS is represented by an instance of
157643 ** the following structure.
157644 */
157645 struct rbu_file {
157646 sqlite3_file base; /* sqlite3_file methods */
157647 sqlite3_file *pReal; /* Underlying file handle */
157648 rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */
157649 sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
157650
157651 int openFlags; /* Flags this file was opened with */
157652 u32 iCookie; /* Cookie value for main db files */
157653 u8 iWriteVer; /* "write-version" value for main db files */
157654
@@ -157411,12 +157655,12 @@
157655 int nShm; /* Number of entries in apShm[] array */
157656 char **apShm; /* Array of mmap'd *-shm regions */
157657 char *zDel; /* Delete this when closing file */
157658
157659 const char *zWal; /* Wal filename for this main db file */
157660 rbu_file *pWalFd; /* Wal file descriptor for this main db */
157661 rbu_file *pMainNext; /* Next MAIN_DB file */
157662 };
157663
157664
157665 /*
157666 ** Prepare the SQL statement in buffer zSql against database handle db.
@@ -157490,14 +157734,14 @@
157734 }
157735 return rc;
157736 }
157737
157738 /*
157739 ** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated
157740 ** by an earlier call to rbuObjIterCacheTableInfo().
157741 */
157742 static void rbuObjIterFreeCols(RbuObjIter *pIter){
157743 int i;
157744 for(i=0; i<pIter->nTblCol; i++){
157745 sqlite3_free(pIter->azTblCol[i]);
157746 sqlite3_free(pIter->azTblType[i]);
157747 }
@@ -157513,72 +157757,72 @@
157757
157758 /*
157759 ** Finalize all statements and free all allocations that are specific to
157760 ** the current object (table/index pair).
157761 */
157762 static void rbuObjIterClearStatements(RbuObjIter *pIter){
157763 RbuUpdateStmt *pUp;
157764
157765 sqlite3_finalize(pIter->pSelect);
157766 sqlite3_finalize(pIter->pInsert);
157767 sqlite3_finalize(pIter->pDelete);
157768 sqlite3_finalize(pIter->pTmpInsert);
157769 pUp = pIter->pRbuUpdate;
157770 while( pUp ){
157771 RbuUpdateStmt *pTmp = pUp->pNext;
157772 sqlite3_finalize(pUp->pUpdate);
157773 sqlite3_free(pUp);
157774 pUp = pTmp;
157775 }
157776
157777 pIter->pSelect = 0;
157778 pIter->pInsert = 0;
157779 pIter->pDelete = 0;
157780 pIter->pRbuUpdate = 0;
157781 pIter->pTmpInsert = 0;
157782 pIter->nCol = 0;
157783 }
157784
157785 /*
157786 ** Clean up any resources allocated as part of the iterator object passed
157787 ** as the only argument.
157788 */
157789 static void rbuObjIterFinalize(RbuObjIter *pIter){
157790 rbuObjIterClearStatements(pIter);
157791 sqlite3_finalize(pIter->pTblIter);
157792 sqlite3_finalize(pIter->pIdxIter);
157793 rbuObjIterFreeCols(pIter);
157794 memset(pIter, 0, sizeof(RbuObjIter));
157795 }
157796
157797 /*
157798 ** Advance the iterator to the next position.
157799 **
157800 ** If no error occurs, SQLITE_OK is returned and the iterator is left
157801 ** pointing to the next entry. Otherwise, an error code and message is
157802 ** left in the RBU handle passed as the first argument. A copy of the
157803 ** error code is returned.
157804 */
157805 static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){
157806 int rc = p->rc;
157807 if( rc==SQLITE_OK ){
157808
157809 /* Free any SQLite statements used while processing the previous object */
157810 rbuObjIterClearStatements(pIter);
157811 if( pIter->zIdx==0 ){
157812 rc = sqlite3_exec(p->dbMain,
157813 "DROP TRIGGER IF EXISTS temp.rbu_insert_tr;"
157814 "DROP TRIGGER IF EXISTS temp.rbu_update1_tr;"
157815 "DROP TRIGGER IF EXISTS temp.rbu_update2_tr;"
157816 "DROP TRIGGER IF EXISTS temp.rbu_delete_tr;"
157817 , 0, 0, &p->zErrmsg
157818 );
157819 }
157820
157821 if( rc==SQLITE_OK ){
157822 if( pIter->bCleanup ){
157823 rbuObjIterFreeCols(pIter);
157824 pIter->bCleanup = 0;
157825 rc = sqlite3_step(pIter->pTblIter);
157826 if( rc!=SQLITE_ROW ){
157827 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
157828 pIter->zTbl = 0;
@@ -157607,11 +157851,11 @@
157851 }
157852 }
157853 }
157854
157855 if( rc!=SQLITE_OK ){
157856 rbuObjIterFinalize(pIter);
157857 p->rc = rc;
157858 }
157859 return rc;
157860 }
157861
@@ -157618,20 +157862,20 @@
157862 /*
157863 ** Initialize the iterator structure passed as the second argument.
157864 **
157865 ** If no error occurs, SQLITE_OK is returned and the iterator is left
157866 ** pointing to the first entry. Otherwise, an error code and message is
157867 ** left in the RBU handle passed as the first argument. A copy of the
157868 ** error code is returned.
157869 */
157870 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
157871 int rc;
157872 memset(pIter, 0, sizeof(RbuObjIter));
157873
157874 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
157875 "SELECT substr(name, 6) FROM sqlite_master "
157876 "WHERE type IN ('table', 'view') AND name LIKE 'data_%'"
157877 );
157878
157879 if( rc==SQLITE_OK ){
157880 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
157881 "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
@@ -157640,23 +157884,23 @@
157884 );
157885 }
157886
157887 pIter->bCleanup = 1;
157888 p->rc = rc;
157889 return rbuObjIterNext(p, pIter);
157890 }
157891
157892 /*
157893 ** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs,
157894 ** an error code is stored in the RBU handle passed as the first argument.
157895 **
157896 ** If an error has already occurred (p->rc is already set to something other
157897 ** than SQLITE_OK), then this function returns NULL without modifying the
157898 ** stored error code. In this case it still calls sqlite3_free() on any
157899 ** printf() parameters associated with %z conversions.
157900 */
157901 static char *rbuMPrintf(sqlite3rbu *p, const char *zFmt, ...){
157902 char *zSql = 0;
157903 va_list ap;
157904 va_start(ap, zFmt);
157905 zSql = sqlite3_vmprintf(zFmt, ap);
157906 if( p->rc==SQLITE_OK ){
@@ -157671,20 +157915,21 @@
157915
157916 /*
157917 ** Argument zFmt is a sqlite3_mprintf() style format string. The trailing
157918 ** arguments are the usual subsitution values. This function performs
157919 ** the printf() style substitutions and executes the result as an SQL
157920 ** statement on the RBU handles database.
157921 **
157922 ** If an error occurs, an error code and error message is stored in the
157923 ** RBU handle. If an error has already occurred when this function is
157924 ** called, it is a no-op.
157925 */
157926 static int rbuMPrintfExec(sqlite3rbu *p, sqlite3 *db, const char *zFmt, ...){
157927 va_list ap;
157928 char *zSql;
157929 va_start(ap, zFmt);
157930 zSql = sqlite3_vmprintf(zFmt, ap);
157931 if( p->rc==SQLITE_OK ){
157932 if( zSql==0 ){
157933 p->rc = SQLITE_NOMEM;
157934 }else{
157935 p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
@@ -157698,16 +157943,16 @@
157943 /*
157944 ** Attempt to allocate and return a pointer to a zeroed block of nByte
157945 ** bytes.
157946 **
157947 ** If an error (i.e. an OOM condition) occurs, return NULL and leave an
157948 ** error code in the rbu handle passed as the first argument. Or, if an
157949 ** error has already occurred when this function is called, return NULL
157950 ** immediately without attempting the allocation or modifying the stored
157951 ** error code.
157952 */
157953 static void *rbuMalloc(sqlite3rbu *p, int nByte){
157954 void *pRet = 0;
157955 if( p->rc==SQLITE_OK ){
157956 assert( nByte>0 );
157957 pRet = sqlite3_malloc(nByte);
157958 if( pRet==0 ){
@@ -157721,17 +157966,17 @@
157966
157967
157968 /*
157969 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
157970 ** there is room for at least nCol elements. If an OOM occurs, store an
157971 ** error code in the RBU handle passed as the first argument.
157972 */
157973 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
157974 int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
157975 char **azNew;
157976
157977 azNew = (char**)rbuMalloc(p, nByte);
157978 if( azNew ){
157979 pIter->azTblCol = azNew;
157980 pIter->azTblType = &azNew[nCol];
157981 pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
157982 pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol];
@@ -157748,11 +157993,11 @@
157993 **
157994 ** If an OOM condition is encountered when attempting to allocate memory,
157995 ** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
157996 ** if the allocation succeeds, (*pRc) is left unchanged.
157997 */
157998 static char *rbuStrndup(const char *zStr, int *pRc){
157999 char *zRet = 0;
158000
158001 assert( *pRc==SQLITE_OK );
158002 if( zStr ){
158003 int nCopy = strlen(zStr) + 1;
@@ -157769,14 +158014,14 @@
158014
158015 /*
158016 ** Finalize the statement passed as the second argument.
158017 **
158018 ** If the sqlite3_finalize() call indicates that an error occurs, and the
158019 ** rbu handle error code is not already set, set the error code and error
158020 ** message accordingly.
158021 */
158022 static void rbuFinalize(sqlite3rbu *p, sqlite3_stmt *pStmt){
158023 sqlite3 *db = sqlite3_db_handle(pStmt);
158024 int rc = sqlite3_finalize(pStmt);
158025 if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){
158026 p->rc = rc;
158027 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
@@ -157787,16 +158032,16 @@
158032 **
158033 ** peType is of type (int*), a pointer to an output parameter of type
158034 ** (int). This call sets the output parameter as follows, depending
158035 ** on the type of the table specified by parameters dbName and zTbl.
158036 **
158037 ** RBU_PK_NOTABLE: No such table.
158038 ** RBU_PK_NONE: Table has an implicit rowid.
158039 ** RBU_PK_IPK: Table has an explicit IPK column.
158040 ** RBU_PK_EXTERNAL: Table has an external PK index.
158041 ** RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
158042 ** RBU_PK_VTAB: Table is a virtual table.
158043 **
158044 ** Argument *piPk is also of type (int*), and also points to an output
158045 ** parameter. Unless the table has an external primary key index
158046 ** (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
158047 ** if the table does have an external primary key index, then *piPk
@@ -157804,28 +158049,28 @@
158049 ** returning.
158050 **
158051 ** ALGORITHM:
158052 **
158053 ** if( no entry exists in sqlite_master ){
158054 ** return RBU_PK_NOTABLE
158055 ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
158056 ** return RBU_PK_VTAB
158057 ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
158058 ** if( the index that is the pk exists in sqlite_master ){
158059 ** *piPK = rootpage of that index.
158060 ** return RBU_PK_EXTERNAL
158061 ** }else{
158062 ** return RBU_PK_WITHOUT_ROWID
158063 ** }
158064 ** }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
158065 ** return RBU_PK_IPK
158066 ** }else{
158067 ** return RBU_PK_NONE
158068 ** }
158069 */
158070 static void rbuTableType(
158071 sqlite3rbu *p,
158072 const char *zTab,
158073 int *peType,
158074 int *piTnum,
158075 int *piPk
158076 ){
@@ -157835,11 +158080,11 @@
158080 ** 2) SELECT count(*) FROM sqlite_master where name=%Q
158081 ** 3) PRAGMA table_info = ?
158082 */
158083 sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
158084
158085 *peType = RBU_PK_NOTABLE;
158086 *piPk = 0;
158087
158088 assert( p->rc==SQLITE_OK );
158089 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
158090 sqlite3_mprintf(
@@ -157847,22 +158092,22 @@
158092 " FROM sqlite_master"
158093 " WHERE name=%Q", zTab
158094 ));
158095 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
158096 /* Either an error, or no such table. */
158097 goto rbuTableType_end;
158098 }
158099 if( sqlite3_column_int(aStmt[0], 0) ){
158100 *peType = RBU_PK_VTAB; /* virtual table */
158101 goto rbuTableType_end;
158102 }
158103 *piTnum = sqlite3_column_int(aStmt[0], 1);
158104
158105 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[1], &p->zErrmsg,
158106 sqlite3_mprintf("PRAGMA index_list=%Q",zTab)
158107 );
158108 if( p->rc ) goto rbuTableType_end;
158109 while( sqlite3_step(aStmt[1])==SQLITE_ROW ){
158110 const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
158111 const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
158112 if( zOrig && zIdx && zOrig[0]=='p' ){
158113 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg,
@@ -157870,45 +158115,45 @@
158115 "SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx
158116 ));
158117 if( p->rc==SQLITE_OK ){
158118 if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
158119 *piPk = sqlite3_column_int(aStmt[2], 0);
158120 *peType = RBU_PK_EXTERNAL;
158121 }else{
158122 *peType = RBU_PK_WITHOUT_ROWID;
158123 }
158124 }
158125 goto rbuTableType_end;
158126 }
158127 }
158128
158129 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[3], &p->zErrmsg,
158130 sqlite3_mprintf("PRAGMA table_info=%Q",zTab)
158131 );
158132 if( p->rc==SQLITE_OK ){
158133 while( sqlite3_step(aStmt[3])==SQLITE_ROW ){
158134 if( sqlite3_column_int(aStmt[3],5)>0 ){
158135 *peType = RBU_PK_IPK; /* explicit IPK column */
158136 goto rbuTableType_end;
158137 }
158138 }
158139 *peType = RBU_PK_NONE;
158140 }
158141
158142 rbuTableType_end: {
158143 int i;
158144 for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
158145 rbuFinalize(p, aStmt[i]);
158146 }
158147 }
158148 }
158149
158150 /*
158151 ** This is a helper function for rbuObjIterCacheTableInfo(). It populates
158152 ** the pIter->abIndexed[] array.
158153 */
158154 static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){
158155 sqlite3_stmt *pList = 0;
158156 int bIndex = 0;
158157
158158 if( p->rc==SQLITE_OK ){
158159 memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol);
@@ -157926,15 +158171,15 @@
158171 );
158172 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158173 int iCid = sqlite3_column_int(pXInfo, 1);
158174 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
158175 }
158176 rbuFinalize(p, pXInfo);
158177 bIndex = 1;
158178 }
158179
158180 rbuFinalize(p, pList);
158181 if( bIndex==0 ) pIter->abIndexed = 0;
158182 }
158183
158184
158185 /*
@@ -157942,67 +158187,67 @@
158187 ** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
158188 ** the table (not index) that the iterator currently points to.
158189 **
158190 ** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
158191 ** an error does occur, an error code and error message are also left in
158192 ** the RBU handle.
158193 */
158194 static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){
158195 if( pIter->azTblCol==0 ){
158196 sqlite3_stmt *pStmt = 0;
158197 int nCol = 0;
158198 int i; /* for() loop iterator variable */
158199 int bRbuRowid = 0; /* If input table has column "rbu_rowid" */
158200 int iOrder = 0;
158201 int iTnum = 0;
158202
158203 /* Figure out the type of table this step will deal with. */
158204 assert( pIter->eType==0 );
158205 rbuTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
158206 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_NOTABLE ){
158207 p->rc = SQLITE_ERROR;
158208 p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl);
158209 }
158210 if( p->rc ) return p->rc;
158211 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
158212
158213 assert( pIter->eType==RBU_PK_NONE || pIter->eType==RBU_PK_IPK
158214 || pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_WITHOUT_ROWID
158215 || pIter->eType==RBU_PK_VTAB
158216 );
158217
158218 /* Populate the azTblCol[] and nTblCol variables based on the columns
158219 ** of the input table. Ignore any input table columns that begin with
158220 ** "rbu_". */
158221 p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
158222 sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl)
158223 );
158224 if( p->rc==SQLITE_OK ){
158225 nCol = sqlite3_column_count(pStmt);
158226 rbuAllocateIterArrays(p, pIter, nCol);
158227 }
158228 for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
158229 const char *zName = (const char*)sqlite3_column_name(pStmt, i);
158230 if( sqlite3_strnicmp("rbu_", zName, 4) ){
158231 char *zCopy = rbuStrndup(zName, &p->rc);
158232 pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol;
158233 pIter->azTblCol[pIter->nTblCol++] = zCopy;
158234 }
158235 else if( 0==sqlite3_stricmp("rbu_rowid", zName) ){
158236 bRbuRowid = 1;
158237 }
158238 }
158239 sqlite3_finalize(pStmt);
158240 pStmt = 0;
158241
158242 if( p->rc==SQLITE_OK
158243 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
158244 ){
158245 p->rc = SQLITE_ERROR;
158246 p->zErrmsg = sqlite3_mprintf(
158247 "table data_%q %s rbu_rowid column", pIter->zTbl,
158248 (bRbuRowid ? "may not have" : "requires")
158249 );
158250 }
158251
158252 /* Check that all non-HIDDEN columns in the destination table are also
158253 ** present in the input table. Populate the abTblPk[], azTblType[] and
@@ -158031,20 +158276,20 @@
158276 if( i!=iOrder ){
158277 SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]);
158278 SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]);
158279 }
158280
158281 pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc);
158282 pIter->abTblPk[iOrder] = (iPk!=0);
158283 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
158284 iOrder++;
158285 }
158286 }
158287
158288 rbuFinalize(p, pStmt);
158289 rbuObjIterCacheIndexedCols(p, pIter);
158290 assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
158291 }
158292
158293 return p->rc;
158294 }
158295
@@ -158051,29 +158296,29 @@
158296 /*
158297 ** This function constructs and returns a pointer to a nul-terminated
158298 ** string containing some SQL clause or list based on one or more of the
158299 ** column names currently stored in the pIter->azTblCol[] array.
158300 */
158301 static char *rbuObjIterGetCollist(
158302 sqlite3rbu *p, /* RBU object */
158303 RbuObjIter *pIter /* Object iterator for column names */
158304 ){
158305 char *zList = 0;
158306 const char *zSep = "";
158307 int i;
158308 for(i=0; i<pIter->nTblCol; i++){
158309 const char *z = pIter->azTblCol[i];
158310 zList = rbuMPrintf(p, "%z%s\"%w\"", zList, zSep, z);
158311 zSep = ", ";
158312 }
158313 return zList;
158314 }
158315
158316 /*
158317 ** This function is used to create a SELECT list (the list of SQL
158318 ** expressions that follows a SELECT keyword) for a SELECT statement
158319 ** used to read from an data_xxx or rbu_tmp_xxx table while updating the
158320 ** index object currently indicated by the iterator object passed as the
158321 ** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used
158322 ** to obtain the required information.
158323 **
158324 ** If the index is of the following form:
@@ -158090,17 +158335,17 @@
158335 **
158336 ** pzImposterCols: ...
158337 ** pzImposterPk: ...
158338 ** pzWhere: ...
158339 */
158340 static char *rbuObjIterGetIndexCols(
158341 sqlite3rbu *p, /* RBU object */
158342 RbuObjIter *pIter, /* Object iterator for column names */
158343 char **pzImposterCols, /* OUT: Columns for imposter table */
158344 char **pzImposterPk, /* OUT: Imposter PK clause */
158345 char **pzWhere, /* OUT: WHERE clause */
158346 int *pnBind /* OUT: Trbul number of columns */
158347 ){
158348 int rc = p->rc; /* Error code */
158349 int rc2; /* sqlite3_finalize() return code */
158350 char *zRet = 0; /* String to return */
158351 char *zImpCols = 0; /* String to return via *pzImposterCols */
@@ -158125,18 +158370,18 @@
158370 const char *zCol;
158371 const char *zType;
158372
158373 if( iCid<0 ){
158374 /* An integer primary key. If the table has an explicit IPK, use
158375 ** its name. Otherwise, use "rbu_rowid". */
158376 if( pIter->eType==RBU_PK_IPK ){
158377 int i;
158378 for(i=0; pIter->abTblPk[i]==0; i++);
158379 assert( i<pIter->nTblCol );
158380 zCol = pIter->azTblCol[i];
158381 }else{
158382 zCol = "rbu_rowid";
158383 }
158384 zType = "INTEGER";
158385 }else{
158386 zCol = pIter->azTblCol[iCid];
158387 zType = pIter->azTblType[iCid];
@@ -158143,19 +158388,19 @@
158388 }
158389
158390 zRet = sqlite3_mprintf("%z%s\"%w\" COLLATE %Q", zRet, zCom, zCol, zCollate);
158391 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
158392 const char *zOrder = (bDesc ? " DESC" : "");
158393 zImpPK = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\"%s",
158394 zImpPK, zCom, nBind, zCol, zOrder
158395 );
158396 }
158397 zImpCols = sqlite3_mprintf("%z%s\"rbu_imp_%d%w\" %s COLLATE %Q",
158398 zImpCols, zCom, nBind, zCol, zType, zCollate
158399 );
158400 zWhere = sqlite3_mprintf(
158401 "%z%s\"rbu_imp_%d%w\" IS ?", zWhere, zAnd, nBind, zCol
158402 );
158403 if( zRet==0 || zImpPK==0 || zImpCols==0 || zWhere==0 ) rc = SQLITE_NOMEM;
158404 zCom = ", ";
158405 zAnd = " AND ";
158406 nBind++;
@@ -158189,16 +158434,16 @@
158434 **
158435 ** "old.a, old.b, old.b"
158436 **
158437 ** With the column names escaped.
158438 **
158439 ** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append
158440 ** the text ", old._rowid_" to the returned value.
158441 */
158442 static char *rbuObjIterGetOldlist(
158443 sqlite3rbu *p,
158444 RbuObjIter *pIter,
158445 const char *zObj
158446 ){
158447 char *zList = 0;
158448 if( p->rc==SQLITE_OK && pIter->abIndexed ){
158449 const char *zS = "";
@@ -158216,12 +158461,12 @@
158461 break;
158462 }
158463 }
158464
158465 /* For a table with implicit rowids, append "old._rowid_" to the list. */
158466 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158467 zList = rbuMPrintf(p, "%z, %s._rowid_", zList, zObj);
158468 }
158469 }
158470 return zList;
158471 }
158472
@@ -158233,37 +158478,37 @@
158478 **
158479 ** Return the string:
158480 **
158481 ** "b = ?1 AND c = ?2"
158482 */
158483 static char *rbuObjIterGetWhere(
158484 sqlite3rbu *p,
158485 RbuObjIter *pIter
158486 ){
158487 char *zList = 0;
158488 if( pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE ){
158489 zList = rbuMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
158490 }else if( pIter->eType==RBU_PK_EXTERNAL ){
158491 const char *zSep = "";
158492 int i;
158493 for(i=0; i<pIter->nTblCol; i++){
158494 if( pIter->abTblPk[i] ){
158495 zList = rbuMPrintf(p, "%z%sc%d=?%d", zList, zSep, i, i+1);
158496 zSep = " AND ";
158497 }
158498 }
158499 zList = rbuMPrintf(p,
158500 "_rowid_ = (SELECT id FROM rbu_imposter2 WHERE %z)", zList
158501 );
158502
158503 }else{
158504 const char *zSep = "";
158505 int i;
158506 for(i=0; i<pIter->nTblCol; i++){
158507 if( pIter->abTblPk[i] ){
158508 const char *zCol = pIter->azTblCol[i];
158509 zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", zList, zSep, zCol, i+1);
158510 zSep = " AND ";
158511 }
158512 }
158513 }
158514 return zList;
@@ -158270,60 +158515,60 @@
158515 }
158516
158517 /*
158518 ** The SELECT statement iterating through the keys for the current object
158519 ** (p->objiter.pSelect) currently points to a valid row. However, there
158520 ** is something wrong with the rbu_control value in the rbu_control value
158521 ** stored in the (p->nCol+1)'th column. Set the error code and error message
158522 ** of the RBU handle to something reflecting this.
158523 */
158524 static void rbuBadControlError(sqlite3rbu *p){
158525 p->rc = SQLITE_ERROR;
158526 p->zErrmsg = sqlite3_mprintf("invalid rbu_control value");
158527 }
158528
158529
158530 /*
158531 ** Return a nul-terminated string containing the comma separated list of
158532 ** assignments that should be included following the "SET" keyword of
158533 ** an UPDATE statement used to update the table object that the iterator
158534 ** passed as the second argument currently points to if the rbu_control
158535 ** column of the data_xxx table entry is set to zMask.
158536 **
158537 ** The memory for the returned string is obtained from sqlite3_malloc().
158538 ** It is the responsibility of the caller to eventually free it using
158539 ** sqlite3_free().
158540 **
158541 ** If an OOM error is encountered when allocating space for the new
158542 ** string, an error code is left in the rbu handle passed as the first
158543 ** argument and NULL is returned. Or, if an error has already occurred
158544 ** when this function is called, NULL is returned immediately, without
158545 ** attempting the allocation or modifying the stored error code.
158546 */
158547 static char *rbuObjIterGetSetlist(
158548 sqlite3rbu *p,
158549 RbuObjIter *pIter,
158550 const char *zMask
158551 ){
158552 char *zList = 0;
158553 if( p->rc==SQLITE_OK ){
158554 int i;
158555
158556 if( strlen(zMask)!=pIter->nTblCol ){
158557 rbuBadControlError(p);
158558 }else{
158559 const char *zSep = "";
158560 for(i=0; i<pIter->nTblCol; i++){
158561 char c = zMask[pIter->aiSrcOrder[i]];
158562 if( c=='x' ){
158563 zList = rbuMPrintf(p, "%z%s\"%w\"=?%d",
158564 zList, zSep, pIter->azTblCol[i], i+1
158565 );
158566 zSep = ", ";
158567 }
158568 if( c=='d' ){
158569 zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)",
158570 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
158571 );
158572 zSep = ", ";
158573 }
158574 }
@@ -158340,20 +158585,20 @@
158585 ** The memory for the returned string is obtained from sqlite3_malloc().
158586 ** It is the responsibility of the caller to eventually free it using
158587 ** sqlite3_free().
158588 **
158589 ** If an OOM error is encountered when allocating space for the new
158590 ** string, an error code is left in the rbu handle passed as the first
158591 ** argument and NULL is returned. Or, if an error has already occurred
158592 ** when this function is called, NULL is returned immediately, without
158593 ** attempting the allocation or modifying the stored error code.
158594 */
158595 static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
158596 char *zRet = 0;
158597 int nByte = nBind*2 + 1;
158598
158599 zRet = (char*)rbuMalloc(p, nByte);
158600 if( zRet ){
158601 int i;
158602 for(i=0; i<nBind; i++){
158603 zRet[i*2] = '?';
158604 zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
@@ -158362,21 +158607,21 @@
158607 return zRet;
158608 }
158609
158610 /*
158611 ** The iterator currently points to a table (not index) of type
158612 ** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
158613 ** declaration for the corresponding imposter table. For example,
158614 ** if the iterator points to a table created as:
158615 **
158616 ** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
158617 **
158618 ** this function returns:
158619 **
158620 ** PRIMARY KEY("b", "a" DESC)
158621 */
158622 static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){
158623 char *z = 0;
158624 assert( pIter->zIdx==0 );
158625 if( p->rc==SQLITE_OK ){
158626 const char *zSep = "PRIMARY KEY(";
158627 sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
@@ -158395,23 +158640,23 @@
158640 );
158641 }
158642 break;
158643 }
158644 }
158645 rbuFinalize(p, pXList);
158646
158647 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158648 if( sqlite3_column_int(pXInfo, 5) ){
158649 /* int iCid = sqlite3_column_int(pXInfo, 0); */
158650 const char *zCol = (const char*)sqlite3_column_text(pXInfo, 2);
158651 const char *zDesc = sqlite3_column_int(pXInfo, 3) ? " DESC" : "";
158652 z = rbuMPrintf(p, "%z%s\"%w\"%s", z, zSep, zCol, zDesc);
158653 zSep = ", ";
158654 }
158655 }
158656 z = rbuMPrintf(p, "%z)", z);
158657 rbuFinalize(p, pXInfo);
158658 }
158659 return z;
158660 }
158661
158662 /*
@@ -158420,23 +158665,23 @@
158665 ** iterator passed as the second argument does not currently point to
158666 ** a table (not index) with an external primary key, this function is a
158667 ** no-op.
158668 **
158669 ** Assuming the iterator does point to a table with an external PK, this
158670 ** function creates a WITHOUT ROWID imposter table named "rbu_imposter2"
158671 ** used to access that PK index. For example, if the target table is
158672 ** declared as follows:
158673 **
158674 ** CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
158675 **
158676 ** then the imposter table schema is:
158677 **
158678 ** CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
158679 **
158680 */
158681 static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){
158682 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_EXTERNAL ){
158683 int tnum = pIter->iPkTnum; /* Root page of PK index */
158684 sqlite3_stmt *pQuery = 0; /* SELECT name ... WHERE rootpage = $tnum */
158685 const char *zIdx = 0; /* Name of PK index */
158686 sqlite3_stmt *pXInfo = 0; /* PRAGMA main.index_xinfo = $zIdx */
158687 const char *zComma = "";
@@ -158458,31 +158703,31 @@
158703 if( zIdx ){
158704 p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
158705 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
158706 );
158707 }
158708 rbuFinalize(p, pQuery);
158709
158710 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
158711 int bKey = sqlite3_column_int(pXInfo, 5);
158712 if( bKey ){
158713 int iCid = sqlite3_column_int(pXInfo, 1);
158714 int bDesc = sqlite3_column_int(pXInfo, 3);
158715 const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
158716 zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma,
158717 iCid, pIter->azTblType[iCid], zCollate
158718 );
158719 zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":"");
158720 zComma = ", ";
158721 }
158722 }
158723 zCols = rbuMPrintf(p, "%z, id INTEGER", zCols);
158724 rbuFinalize(p, pXInfo);
158725
158726 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158727 rbuMPrintfExec(p, p->dbMain,
158728 "CREATE TABLE rbu_imposter2(%z, PRIMARY KEY(%z)) WITHOUT ROWID",
158729 zCols, zPk
158730 );
158731 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158732 }
158733 }
@@ -158489,28 +158734,28 @@
158734
158735 /*
158736 ** If an error has already occurred when this function is called, it
158737 ** immediately returns zero (without doing any work). Or, if an error
158738 ** occurs during the execution of this function, it sets the error code
158739 ** in the sqlite3rbu object indicated by the first argument and returns
158740 ** zero.
158741 **
158742 ** The iterator passed as the second argument is guaranteed to point to
158743 ** a table (not an index) when this function is called. This function
158744 ** attempts to create any imposter table required to write to the main
158745 ** table b-tree of the table before returning. Non-zero is returned if
158746 ** an imposter table are created, or zero otherwise.
158747 **
158748 ** An imposter table is required in all cases except RBU_PK_VTAB. Only
158749 ** virtual tables are written to directly. The imposter table has the
158750 ** same schema as the actual target table (less any UNIQUE constraints).
158751 ** More precisely, the "same schema" means the same columns, types,
158752 ** collation sequences. For tables that do not have an external PRIMARY
158753 ** KEY, it also means the same PRIMARY KEY declaration.
158754 */
158755 static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){
158756 if( p->rc==SQLITE_OK && pIter->eType!=RBU_PK_VTAB ){
158757 int tnum = pIter->iTnum;
158758 const char *zComma = "";
158759 char *zSql = 0;
158760 int iCol;
158761 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
@@ -158522,73 +158767,73 @@
158767
158768 p->rc = sqlite3_table_column_metadata(
158769 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
158770 );
158771
158772 if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
158773 /* If the target table column is an "INTEGER PRIMARY KEY", add
158774 ** "PRIMARY KEY" to the imposter table column declaration. */
158775 zPk = "PRIMARY KEY ";
158776 }
158777 zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s",
158778 zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
158779 (pIter->abNotNull[iCol] ? " NOT NULL" : "")
158780 );
158781 zComma = ", ";
158782 }
158783
158784 if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
158785 char *zPk = rbuWithoutRowidPK(p, pIter);
158786 if( zPk ){
158787 zSql = rbuMPrintf(p, "%z, %z", zSql, zPk);
158788 }
158789 }
158790
158791 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1, tnum);
158792 rbuMPrintfExec(p, p->dbMain, "CREATE TABLE \"rbu_imp_%w\"(%z)%s",
158793 pIter->zTbl, zSql,
158794 (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
158795 );
158796 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158797 }
158798 }
158799
158800 /*
158801 ** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table.
158802 ** Specifically a statement of the form:
158803 **
158804 ** INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...);
158805 **
158806 ** The number of bound variables is equal to the number of columns in
158807 ** the target table, plus one (for the rbu_control column), plus one more
158808 ** (for the rbu_rowid column) if the target table is an implicit IPK or
158809 ** virtual table.
158810 */
158811 static void rbuObjIterPrepareTmpInsert(
158812 sqlite3rbu *p,
158813 RbuObjIter *pIter,
158814 const char *zCollist,
158815 const char *zRbuRowid
158816 ){
158817 int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE);
158818 char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid);
158819 if( zBind ){
158820 assert( pIter->pTmpInsert==0 );
158821 p->rc = prepareFreeAndCollectError(
158822 p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
158823 "INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)",
158824 p->zStateDb, pIter->zTbl, zCollist, zRbuRowid, zBind
158825 ));
158826 }
158827 }
158828
158829 static void rbuTmpInsertFunc(
158830 sqlite3_context *pCtx,
158831 int nVal,
158832 sqlite3_value **apVal
158833 ){
158834 sqlite3rbu *p = sqlite3_user_data(pCtx);
158835 int rc = SQLITE_OK;
158836 int i;
158837
158838 for(i=0; rc==SQLITE_OK && i<nVal; i++){
158839 rc = sqlite3_bind_value(p->objiter.pTmpInsert, i+1, apVal[i]);
@@ -158606,17 +158851,17 @@
158851 /*
158852 ** Ensure that the SQLite statement handles required to update the
158853 ** target database object currently indicated by the iterator passed
158854 ** as the second argument are available.
158855 */
158856 static int rbuObjIterPrepareAll(
158857 sqlite3rbu *p,
158858 RbuObjIter *pIter,
158859 int nOffset /* Add "LIMIT -1 OFFSET $nOffset" to SELECT */
158860 ){
158861 assert( pIter->bCleanup==0 );
158862 if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
158863 const int tnum = pIter->iTnum;
158864 char *zCollist = 0; /* List of indexed columns */
158865 char **pz = &p->zErrmsg;
158866 const char *zIdx = pIter->zIdx;
158867 char *zLimit = 0;
@@ -158632,104 +158877,104 @@
158877 char *zImposterPK = 0; /* Primary key declaration for imposter */
158878 char *zWhere = 0; /* WHERE clause on PK columns */
158879 char *zBind = 0;
158880 int nBind = 0;
158881
158882 assert( pIter->eType!=RBU_PK_VTAB );
158883 zCollist = rbuObjIterGetIndexCols(
158884 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
158885 );
158886 zBind = rbuObjIterGetBindlist(p, nBind);
158887
158888 /* Create the imposter table used to write to this index. */
158889 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
158890 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
158891 rbuMPrintfExec(p, p->dbMain,
158892 "CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID",
158893 zTbl, zImposterCols, zImposterPK
158894 );
158895 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 0);
158896
158897 /* Create the statement to insert index entries */
158898 pIter->nCol = nBind;
158899 if( p->rc==SQLITE_OK ){
158900 p->rc = prepareFreeAndCollectError(
158901 p->dbMain, &pIter->pInsert, &p->zErrmsg,
158902 sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
158903 );
158904 }
158905
158906 /* And to delete index entries */
158907 if( p->rc==SQLITE_OK ){
158908 p->rc = prepareFreeAndCollectError(
158909 p->dbMain, &pIter->pDelete, &p->zErrmsg,
158910 sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
158911 );
158912 }
158913
158914 /* Create the SELECT statement to read keys in sorted order */
158915 if( p->rc==SQLITE_OK ){
158916 char *zSql;
158917 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158918 zSql = sqlite3_mprintf(
158919 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
158920 zCollist, p->zStateDb, pIter->zTbl,
158921 zCollist, zLimit
158922 );
158923 }else{
158924 zSql = sqlite3_mprintf(
158925 "SELECT %s, rbu_control FROM 'data_%q' "
158926 "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
158927 "UNION ALL "
158928 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
158929 "ORDER BY %s%s",
158930 zCollist, pIter->zTbl,
158931 zCollist, p->zStateDb, pIter->zTbl,
158932 zCollist, zLimit
158933 );
158934 }
158935 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
158936 }
158937
158938 sqlite3_free(zImposterCols);
158939 sqlite3_free(zImposterPK);
158940 sqlite3_free(zWhere);
158941 sqlite3_free(zBind);
158942 }else{
158943 int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
158944 const char *zTbl = pIter->zTbl; /* Table this step applies to */
158945 const char *zWrite; /* Imposter table name */
158946
158947 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
158948 char *zWhere = rbuObjIterGetWhere(p, pIter);
158949 char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old");
158950 char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
158951
158952 zCollist = rbuObjIterGetCollist(p, pIter);
158953 pIter->nCol = pIter->nTblCol;
158954
158955 /* Create the SELECT statement to read keys from data_xxx */
158956 if( p->rc==SQLITE_OK ){
158957 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
158958 sqlite3_mprintf(
158959 "SELECT %s, rbu_control%s FROM 'data_%q'%s",
158960 zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit
158961 )
158962 );
158963 }
158964
158965 /* Create the imposter table or tables (if required). */
158966 rbuCreateImposterTable(p, pIter);
158967 rbuCreateImposterTable2(p, pIter);
158968 zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
158969
158970 /* Create the INSERT statement to write to the target PK b-tree */
158971 if( p->rc==SQLITE_OK ){
158972 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz,
158973 sqlite3_mprintf(
158974 "INSERT INTO \"%s%w\"(%s%s) VALUES(%s)",
158975 zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
158976 )
158977 );
158978 }
158979
158980 /* Create the DELETE statement to write to the target PK b-tree */
@@ -158740,55 +158985,55 @@
158985 )
158986 );
158987 }
158988
158989 if( pIter->abIndexed ){
158990 const char *zRbuRowid = "";
158991 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158992 zRbuRowid = ", rbu_rowid";
158993 }
158994
158995 /* Create the rbu_tmp_xxx table and the triggers to populate it. */
158996 rbuMPrintfExec(p, p->dbRbu,
158997 "CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS "
158998 "SELECT *%s FROM 'data_%q' WHERE 0;"
158999 , p->zStateDb
159000 , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
159001 , zTbl
159002 );
159003
159004 rbuMPrintfExec(p, p->dbMain,
159005 "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" "
159006 "BEGIN "
159007 " SELECT rbu_tmp_insert(2, %s);"
159008 "END;"
159009
159010 "CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" "
159011 "BEGIN "
159012 " SELECT rbu_tmp_insert(2, %s);"
159013 "END;"
159014
159015 "CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" "
159016 "BEGIN "
159017 " SELECT rbu_tmp_insert(3, %s);"
159018 "END;",
159019 zWrite, zTbl, zOldlist,
159020 zWrite, zTbl, zOldlist,
159021 zWrite, zTbl, zNewlist
159022 );
159023
159024 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
159025 rbuMPrintfExec(p, p->dbMain,
159026 "CREATE TEMP TRIGGER rbu_insert_tr AFTER INSERT ON \"%s%w\" "
159027 "BEGIN "
159028 " SELECT rbu_tmp_insert(0, %s);"
159029 "END;",
159030 zWrite, zTbl, zNewlist
159031 );
159032 }
159033
159034 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
159035 }
159036
159037 sqlite3_free(zWhere);
159038 sqlite3_free(zOldlist);
159039 sqlite3_free(zNewlist);
@@ -158803,68 +159048,68 @@
159048
159049 /*
159050 ** Set output variable *ppStmt to point to an UPDATE statement that may
159051 ** be used to update the imposter table for the main table b-tree of the
159052 ** table object that pIter currently points to, assuming that the
159053 ** rbu_control column of the data_xyz table contains zMask.
159054 **
159055 ** If the zMask string does not specify any columns to update, then this
159056 ** is not an error. Output variable *ppStmt is set to NULL in this case.
159057 */
159058 static int rbuGetUpdateStmt(
159059 sqlite3rbu *p, /* RBU handle */
159060 RbuObjIter *pIter, /* Object iterator */
159061 const char *zMask, /* rbu_control value ('x.x.') */
159062 sqlite3_stmt **ppStmt /* OUT: UPDATE statement handle */
159063 ){
159064 RbuUpdateStmt **pp;
159065 RbuUpdateStmt *pUp = 0;
159066 int nUp = 0;
159067
159068 /* In case an error occurs */
159069 *ppStmt = 0;
159070
159071 /* Search for an existing statement. If one is found, shift it to the front
159072 ** of the LRU queue and return immediately. Otherwise, leave nUp pointing
159073 ** to the number of statements currently in the cache and pUp to the
159074 ** last object in the list. */
159075 for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){
159076 pUp = *pp;
159077 if( strcmp(pUp->zMask, zMask)==0 ){
159078 *pp = pUp->pNext;
159079 pUp->pNext = pIter->pRbuUpdate;
159080 pIter->pRbuUpdate = pUp;
159081 *ppStmt = pUp->pUpdate;
159082 return SQLITE_OK;
159083 }
159084 nUp++;
159085 }
159086 assert( pUp==0 || pUp->pNext==0 );
159087
159088 if( nUp>=SQLITE_RBU_UPDATE_CACHESIZE ){
159089 for(pp=&pIter->pRbuUpdate; *pp!=pUp; pp=&((*pp)->pNext));
159090 *pp = 0;
159091 sqlite3_finalize(pUp->pUpdate);
159092 pUp->pUpdate = 0;
159093 }else{
159094 pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1);
159095 }
159096
159097 if( pUp ){
159098 char *zWhere = rbuObjIterGetWhere(p, pIter);
159099 char *zSet = rbuObjIterGetSetlist(p, pIter, zMask);
159100 char *zUpdate = 0;
159101
159102 pUp->zMask = (char*)&pUp[1];
159103 memcpy(pUp->zMask, zMask, pIter->nTblCol);
159104 pUp->pNext = pIter->pRbuUpdate;
159105 pIter->pRbuUpdate = pUp;
159106
159107 if( zSet ){
159108 const char *zPrefix = "";
159109
159110 if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_";
159111 zUpdate = sqlite3_mprintf("UPDATE \"%s%w\" SET %s WHERE %s",
159112 zPrefix, pIter->zTbl, zSet, zWhere
159113 );
159114 p->rc = prepareFreeAndCollectError(
159115 p->dbMain, &pUp->pUpdate, &p->zErrmsg, zUpdate
@@ -158876,11 +159121,11 @@
159121 }
159122
159123 return p->rc;
159124 }
159125
159126 static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){
159127 sqlite3 *db = 0;
159128 if( p->rc==SQLITE_OK ){
159129 const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
159130 p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
159131 if( p->rc ){
@@ -158891,51 +159136,51 @@
159136 }
159137 return db;
159138 }
159139
159140 /*
159141 ** Open the database handle and attach the RBU database as "rbu". If an
159142 ** error occurs, leave an error code and message in the RBU handle.
159143 */
159144 static void rbuOpenDatabase(sqlite3rbu *p){
159145 assert( p->rc==SQLITE_OK );
159146 assert( p->dbMain==0 && p->dbRbu==0 );
159147
159148 p->eStage = 0;
159149 p->dbMain = rbuOpenDbhandle(p, p->zTarget);
159150 p->dbRbu = rbuOpenDbhandle(p, p->zRbu);
159151
159152 /* If using separate RBU and state databases, attach the state database to
159153 ** the RBU db handle now. */
159154 if( p->zState ){
159155 rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
159156 memcpy(p->zStateDb, "stat", 4);
159157 }else{
159158 memcpy(p->zStateDb, "main", 4);
159159 }
159160
159161 if( p->rc==SQLITE_OK ){
159162 p->rc = sqlite3_create_function(p->dbMain,
159163 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
159164 );
159165 }
159166
159167 if( p->rc==SQLITE_OK ){
159168 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
159169 }
159170 rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
159171
159172 /* Mark the database file just opened as an RBU target database. If
159173 ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
159174 ** This is an error. */
159175 if( p->rc==SQLITE_OK ){
159176 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
159177 }
159178
159179 if( p->rc==SQLITE_NOTFOUND ){
159180 p->rc = SQLITE_ERROR;
159181 p->zErrmsg = sqlite3_mprintf("rbu vfs not found");
159182 }
159183 }
159184
159185 /*
159186 ** This routine is a copy of the sqlite3FileSuffix3() routine from the core.
@@ -158955,11 +159200,11 @@
159200 ** test.db-journal => test.nal
159201 ** test.db-wal => test.wal
159202 ** test.db-shm => test.shm
159203 ** test.db-mj7f3319fa => test.9fa
159204 */
159205 static void rbuFileSuffix3(const char *zBase, char *z){
159206 #ifdef SQLITE_ENABLE_8_3_NAMES
159207 #if SQLITE_ENABLE_8_3_NAMES<2
159208 if( sqlite3_uri_boolean(zBase, "8_3_names", 0) )
159209 #endif
159210 {
@@ -158976,11 +159221,11 @@
159221 ** as a 64-bit integer.
159222 **
159223 ** The checksum is store in the first page of xShmMap memory as an 8-byte
159224 ** blob starting at byte offset 40.
159225 */
159226 static i64 rbuShmChecksum(sqlite3rbu *p){
159227 i64 iRet = 0;
159228 if( p->rc==SQLITE_OK ){
159229 sqlite3_file *pDb = p->pTargetFd->pReal;
159230 u32 volatile *ptr;
159231 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
@@ -158993,23 +159238,23 @@
159238
159239 /*
159240 ** This function is called as part of initializing or reinitializing an
159241 ** incremental checkpoint.
159242 **
159243 ** It populates the sqlite3rbu.aFrame[] array with the set of
159244 ** (wal frame -> db page) copy operations required to checkpoint the
159245 ** current wal file, and obtains the set of shm locks required to safely
159246 ** perform the copy operations directly on the file-system.
159247 **
159248 ** If argument pState is not NULL, then the incremental checkpoint is
159249 ** being resumed. In this case, if the checksum of the wal-index-header
159250 ** following recovery is not the same as the checksum saved in the RbuState
159251 ** object, then the rbu handle is set to DONE state. This occurs if some
159252 ** other client appends a transaction to the wal file in the middle of
159253 ** an incremental checkpoint.
159254 */
159255 static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){
159256
159257 /* If pState is NULL, then the wal file may not have been opened and
159258 ** recovered. Running a read-statement here to ensure that doing so
159259 ** does not interfere with the "capture" process below. */
159260 if( pState==0 ){
@@ -159018,20 +159263,20 @@
159263 p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0);
159264 }
159265 }
159266
159267 /* Assuming no error has occurred, run a "restart" checkpoint with the
159268 ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
159269 ** special behaviour in the rbu VFS:
159270 **
159271 ** * If the exclusive shm WRITER or READ0 lock cannot be obtained,
159272 ** the checkpoint fails with SQLITE_BUSY (normally SQLite would
159273 ** proceed with running a passive checkpoint instead of failing).
159274 **
159275 ** * Attempts to read from the *-wal file or write to the database file
159276 ** do not perform any IO. Instead, the frame/page combinations that
159277 ** would be read/written are recorded in the sqlite3rbu.aFrame[]
159278 ** array.
159279 **
159280 ** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
159281 ** READ0 and CHECKPOINT locks taken as part of the checkpoint are
159282 ** no-ops. These locks will not be released until the connection
@@ -159047,76 +159292,76 @@
159292 ** data from the wal file into the database file according to the
159293 ** contents of aFrame[].
159294 */
159295 if( p->rc==SQLITE_OK ){
159296 int rc2;
159297 p->eStage = RBU_STAGE_CAPTURE;
159298 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
159299 if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
159300 }
159301
159302 if( p->rc==SQLITE_OK ){
159303 p->eStage = RBU_STAGE_CKPT;
159304 p->nStep = (pState ? pState->nRow : 0);
159305 p->aBuf = rbuMalloc(p, p->pgsz);
159306 p->iWalCksum = rbuShmChecksum(p);
159307 }
159308
159309 if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
159310 p->rc = SQLITE_DONE;
159311 p->eStage = RBU_STAGE_DONE;
159312 }
159313 }
159314
159315 /*
159316 ** Called when iAmt bytes are read from offset iOff of the wal file while
159317 ** the rbu object is in capture mode. Record the frame number of the frame
159318 ** being read in the aFrame[] array.
159319 */
159320 static int rbuCaptureWalRead(sqlite3rbu *pRbu, i64 iOff, int iAmt){
159321 const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0);
159322 u32 iFrame;
159323
159324 if( pRbu->mLock!=mReq ){
159325 pRbu->rc = SQLITE_BUSY;
159326 return SQLITE_INTERNAL;
159327 }
159328
159329 pRbu->pgsz = iAmt;
159330 if( pRbu->nFrame==pRbu->nFrameAlloc ){
159331 int nNew = (pRbu->nFrameAlloc ? pRbu->nFrameAlloc : 64) * 2;
159332 RbuFrame *aNew;
159333 aNew = (RbuFrame*)sqlite3_realloc(pRbu->aFrame, nNew * sizeof(RbuFrame));
159334 if( aNew==0 ) return SQLITE_NOMEM;
159335 pRbu->aFrame = aNew;
159336 pRbu->nFrameAlloc = nNew;
159337 }
159338
159339 iFrame = (u32)((iOff-32) / (i64)(iAmt+24)) + 1;
159340 if( pRbu->iMaxFrame<iFrame ) pRbu->iMaxFrame = iFrame;
159341 pRbu->aFrame[pRbu->nFrame].iWalFrame = iFrame;
159342 pRbu->aFrame[pRbu->nFrame].iDbPage = 0;
159343 pRbu->nFrame++;
159344 return SQLITE_OK;
159345 }
159346
159347 /*
159348 ** Called when a page of data is written to offset iOff of the database
159349 ** file while the rbu handle is in capture mode. Record the page number
159350 ** of the page being written in the aFrame[] array.
159351 */
159352 static int rbuCaptureDbWrite(sqlite3rbu *pRbu, i64 iOff){
159353 pRbu->aFrame[pRbu->nFrame-1].iDbPage = (u32)(iOff / pRbu->pgsz) + 1;
159354 return SQLITE_OK;
159355 }
159356
159357 /*
159358 ** This is called as part of an incremental checkpoint operation. Copy
159359 ** a single frame of data from the wal file into the database file, as
159360 ** indicated by the RbuFrame object.
159361 */
159362 static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){
159363 sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal;
159364 sqlite3_file *pDb = p->pTargetFd->pReal;
159365 i64 iOff;
159366
159367 assert( p->rc==SQLITE_OK );
@@ -159130,33 +159375,33 @@
159375
159376
159377 /*
159378 ** Take an EXCLUSIVE lock on the database file.
159379 */
159380 static void rbuLockDatabase(sqlite3rbu *p){
159381 sqlite3_file *pReal = p->pTargetFd->pReal;
159382 assert( p->rc==SQLITE_OK );
159383 p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED);
159384 if( p->rc==SQLITE_OK ){
159385 p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE);
159386 }
159387 }
159388
159389 /*
159390 ** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock
159391 ** on the database file. This proc moves the *-oal file to the *-wal path,
159392 ** then reopens the database file (this time in vanilla, non-oal, WAL mode).
159393 ** If an error occurs, leave an error code and error message in the rbu
159394 ** handle.
159395 */
159396 static void rbuMoveOalFile(sqlite3rbu *p){
159397 const char *zBase = sqlite3_db_filename(p->dbMain, "main");
159398
159399 char *zWal = sqlite3_mprintf("%s-wal", zBase);
159400 char *zOal = sqlite3_mprintf("%s-oal", zBase);
159401
159402 assert( p->eStage==RBU_STAGE_MOVE );
159403 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159404 if( zWal==0 || zOal==0 ){
159405 p->rc = SQLITE_NOMEM;
159406 }else{
159407 /* Move the *-oal file to *-wal. At this point connection p->db is
@@ -159164,25 +159409,25 @@
159409 ** in WAL mode). So no other connection may be writing the db.
159410 **
159411 ** In order to ensure that there are no database readers, an EXCLUSIVE
159412 ** lock is obtained here before the *-oal is moved to *-wal.
159413 */
159414 rbuLockDatabase(p);
159415 if( p->rc==SQLITE_OK ){
159416 rbuFileSuffix3(zBase, zWal);
159417 rbuFileSuffix3(zBase, zOal);
159418
159419 /* Re-open the databases. */
159420 rbuObjIterFinalize(&p->objiter);
159421 sqlite3_close(p->dbMain);
159422 sqlite3_close(p->dbRbu);
159423 p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
159424 if( p->rc==SQLITE_OK ){
159425 p->dbMain = 0;
159426 p->dbRbu = 0;
159427 rbuOpenDatabase(p);
159428 rbuSetupCheckpoint(p, 0);
159429 }
159430 }
159431 }
159432
159433 sqlite3_free(zWal);
@@ -159193,36 +159438,36 @@
159438 ** The SELECT statement iterating through the keys for the current object
159439 ** (p->objiter.pSelect) currently points to a valid row. This function
159440 ** determines the type of operation requested by this row and returns
159441 ** one of the following values to indicate the result:
159442 **
159443 ** * RBU_INSERT
159444 ** * RBU_DELETE
159445 ** * RBU_IDX_DELETE
159446 ** * RBU_UPDATE
159447 **
159448 ** If RBU_UPDATE is returned, then output variable *pzMask is set to
159449 ** point to the text value indicating the columns to update.
159450 **
159451 ** If the rbu_control field contains an invalid value, an error code and
159452 ** message are left in the RBU handle and zero returned.
159453 */
159454 static int rbuStepType(sqlite3rbu *p, const char **pzMask){
159455 int iCol = p->objiter.nCol; /* Index of rbu_control column */
159456 int res = 0; /* Return value */
159457
159458 switch( sqlite3_column_type(p->objiter.pSelect, iCol) ){
159459 case SQLITE_INTEGER: {
159460 int iVal = sqlite3_column_int(p->objiter.pSelect, iCol);
159461 if( iVal==0 ){
159462 res = RBU_INSERT;
159463 }else if( iVal==1 ){
159464 res = RBU_DELETE;
159465 }else if( iVal==2 ){
159466 res = RBU_IDX_DELETE;
159467 }else if( iVal==3 ){
159468 res = RBU_IDX_INSERT;
159469 }
159470 break;
159471 }
159472
159473 case SQLITE_TEXT: {
@@ -159230,21 +159475,21 @@
159475 if( z==0 ){
159476 p->rc = SQLITE_NOMEM;
159477 }else{
159478 *pzMask = (const char*)z;
159479 }
159480 res = RBU_UPDATE;
159481
159482 break;
159483 }
159484
159485 default:
159486 break;
159487 }
159488
159489 if( res==0 ){
159490 rbuBadControlError(p);
159491 }
159492 return res;
159493 }
159494
159495 #ifdef SQLITE_DEBUG
@@ -159258,82 +159503,82 @@
159503 #else
159504 # define assertColumnName(x,y,z)
159505 #endif
159506
159507 /*
159508 ** This function does the work for an sqlite3rbu_step() call.
159509 **
159510 ** The object-iterator (p->objiter) currently points to a valid object,
159511 ** and the input cursor (p->objiter.pSelect) currently points to a valid
159512 ** input row. Perform whatever processing is required and return.
159513 **
159514 ** If no error occurs, SQLITE_OK is returned. Otherwise, an error code
159515 ** and message is left in the RBU handle and a copy of the error code
159516 ** returned.
159517 */
159518 static int rbuStep(sqlite3rbu *p){
159519 RbuObjIter *pIter = &p->objiter;
159520 const char *zMask = 0;
159521 int i;
159522 int eType = rbuStepType(p, &zMask);
159523
159524 if( eType ){
159525 assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
159526
159527 if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){
159528 rbuBadControlError(p);
159529 }
159530 else if(
159531 eType==RBU_INSERT
159532 || eType==RBU_DELETE
159533 || eType==RBU_IDX_DELETE
159534 || eType==RBU_IDX_INSERT
159535 ){
159536 sqlite3_value *pVal;
159537 sqlite3_stmt *pWriter;
159538
159539 assert( eType!=RBU_UPDATE );
159540 assert( eType!=RBU_DELETE || pIter->zIdx==0 );
159541
159542 if( eType==RBU_IDX_DELETE || eType==RBU_DELETE ){
159543 pWriter = pIter->pDelete;
159544 }else{
159545 pWriter = pIter->pInsert;
159546 }
159547
159548 for(i=0; i<pIter->nCol; i++){
159549 /* If this is an INSERT into a table b-tree and the table has an
159550 ** explicit INTEGER PRIMARY KEY, check that this is not an attempt
159551 ** to write a NULL into the IPK column. That is not permitted. */
159552 if( eType==RBU_INSERT
159553 && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
159554 && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL
159555 ){
159556 p->rc = SQLITE_MISMATCH;
159557 p->zErrmsg = sqlite3_mprintf("datatype mismatch");
159558 goto step_out;
159559 }
159560
159561 if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
159562 continue;
159563 }
159564
159565 pVal = sqlite3_column_value(pIter->pSelect, i);
159566 p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
159567 if( p->rc ) goto step_out;
159568 }
159569 if( pIter->zIdx==0
159570 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
159571 ){
159572 /* For a virtual table, or a table with no primary key, the
159573 ** SELECT statement is:
159574 **
159575 ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
159576 **
159577 ** Hence column_value(pIter->nCol+1).
159578 */
159579 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
159580 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159581 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
159582 }
159583 if( p->rc==SQLITE_OK ){
159584 sqlite3_step(pWriter);
@@ -159340,25 +159585,25 @@
159585 p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
159586 }
159587 }else{
159588 sqlite3_value *pVal;
159589 sqlite3_stmt *pUpdate = 0;
159590 assert( eType==RBU_UPDATE );
159591 rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
159592 if( pUpdate ){
159593 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
159594 char c = zMask[pIter->aiSrcOrder[i]];
159595 pVal = sqlite3_column_value(pIter->pSelect, i);
159596 if( pIter->abTblPk[i] || c=='x' || c=='d' ){
159597 p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
159598 }
159599 }
159600 if( p->rc==SQLITE_OK
159601 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
159602 ){
159603 /* Bind the rbu_rowid value to column _rowid_ */
159604 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
159605 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
159606 p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal);
159607 }
159608 if( p->rc==SQLITE_OK ){
159609 sqlite3_step(pUpdate);
@@ -159373,11 +159618,11 @@
159618 }
159619
159620 /*
159621 ** Increment the schema cookie of the main database opened by p->dbMain.
159622 */
159623 static void rbuIncrSchemaCookie(sqlite3rbu *p){
159624 if( p->rc==SQLITE_OK ){
159625 int iCookie = 1000000;
159626 sqlite3_stmt *pStmt;
159627
159628 p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
@@ -159390,49 +159635,49 @@
159635 ** statement reads is page 1, which is guaranteed to be in the cache.
159636 ** And no memory allocations are required. */
159637 if( SQLITE_ROW==sqlite3_step(pStmt) ){
159638 iCookie = sqlite3_column_int(pStmt, 0);
159639 }
159640 rbuFinalize(p, pStmt);
159641 }
159642 if( p->rc==SQLITE_OK ){
159643 rbuMPrintfExec(p, p->dbMain, "PRAGMA schema_version = %d", iCookie+1);
159644 }
159645 }
159646 }
159647
159648 /*
159649 ** Update the contents of the rbu_state table within the rbu database. The
159650 ** value stored in the RBU_STATE_STAGE column is eStage. All other values
159651 ** are determined by inspecting the rbu handle passed as the first argument.
159652 */
159653 static void rbuSaveState(sqlite3rbu *p, int eStage){
159654 if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
159655 sqlite3_stmt *pInsert = 0;
159656 int rc;
159657
159658 assert( p->zErrmsg==0 );
159659 rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
159660 sqlite3_mprintf(
159661 "INSERT OR REPLACE INTO %s.rbu_state(k, v) VALUES "
159662 "(%d, %d), "
159663 "(%d, %Q), "
159664 "(%d, %Q), "
159665 "(%d, %d), "
159666 "(%d, %d), "
159667 "(%d, %lld), "
159668 "(%d, %lld), "
159669 "(%d, %lld) ",
159670 p->zStateDb,
159671 RBU_STATE_STAGE, eStage,
159672 RBU_STATE_TBL, p->objiter.zTbl,
159673 RBU_STATE_IDX, p->objiter.zIdx,
159674 RBU_STATE_ROW, p->nStep,
159675 RBU_STATE_PROGRESS, p->nProgress,
159676 RBU_STATE_CKPT, p->iWalCksum,
159677 RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
159678 RBU_STATE_OALSZ, p->iOalSz
159679 )
159680 );
159681 assert( pInsert==0 || rc==SQLITE_OK );
159682
159683 if( rc==SQLITE_OK ){
@@ -159443,71 +159688,71 @@
159688 }
159689 }
159690
159691
159692 /*
159693 ** Step the RBU object.
159694 */
159695 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
159696 if( p ){
159697 switch( p->eStage ){
159698 case RBU_STAGE_OAL: {
159699 RbuObjIter *pIter = &p->objiter;
159700 while( p->rc==SQLITE_OK && pIter->zTbl ){
159701
159702 if( pIter->bCleanup ){
159703 /* Clean up the rbu_tmp_xxx table for the previous table. It
159704 ** cannot be dropped as there are currently active SQL statements.
159705 ** But the contents can be deleted. */
159706 if( pIter->abIndexed ){
159707 rbuMPrintfExec(p, p->dbRbu,
159708 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zTbl
159709 );
159710 }
159711 }else{
159712 rbuObjIterPrepareAll(p, pIter, 0);
159713
159714 /* Advance to the next row to process. */
159715 if( p->rc==SQLITE_OK ){
159716 int rc = sqlite3_step(pIter->pSelect);
159717 if( rc==SQLITE_ROW ){
159718 p->nProgress++;
159719 p->nStep++;
159720 return rbuStep(p);
159721 }
159722 p->rc = sqlite3_reset(pIter->pSelect);
159723 p->nStep = 0;
159724 }
159725 }
159726
159727 rbuObjIterNext(p, pIter);
159728 }
159729
159730 if( p->rc==SQLITE_OK ){
159731 assert( pIter->zTbl==0 );
159732 rbuSaveState(p, RBU_STAGE_MOVE);
159733 rbuIncrSchemaCookie(p);
159734 if( p->rc==SQLITE_OK ){
159735 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
159736 }
159737 if( p->rc==SQLITE_OK ){
159738 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
159739 }
159740 p->eStage = RBU_STAGE_MOVE;
159741 }
159742 break;
159743 }
159744
159745 case RBU_STAGE_MOVE: {
159746 if( p->rc==SQLITE_OK ){
159747 rbuMoveOalFile(p);
159748 p->nProgress++;
159749 }
159750 break;
159751 }
159752
159753 case RBU_STAGE_CKPT: {
159754 if( p->rc==SQLITE_OK ){
159755 if( p->nStep>=p->nFrame ){
159756 sqlite3_file *pDb = p->pTargetFd->pReal;
159757
159758 /* Sync the db file */
@@ -159521,16 +159766,16 @@
159766 ((u32 volatile*)ptr)[24] = p->iMaxFrame;
159767 }
159768 }
159769
159770 if( p->rc==SQLITE_OK ){
159771 p->eStage = RBU_STAGE_DONE;
159772 p->rc = SQLITE_DONE;
159773 }
159774 }else{
159775 RbuFrame *pFrame = &p->aFrame[p->nStep];
159776 rbuCheckpointFrame(p, pFrame);
159777 p->nStep++;
159778 }
159779 p->nProgress++;
159780 }
159781 break;
@@ -159544,78 +159789,78 @@
159789 return SQLITE_NOMEM;
159790 }
159791 }
159792
159793 /*
159794 ** Free an RbuState object allocated by rbuLoadState().
159795 */
159796 static void rbuFreeState(RbuState *p){
159797 if( p ){
159798 sqlite3_free(p->zTbl);
159799 sqlite3_free(p->zIdx);
159800 sqlite3_free(p);
159801 }
159802 }
159803
159804 /*
159805 ** Allocate an RbuState object and load the contents of the rbu_state
159806 ** table into it. Return a pointer to the new object. It is the
159807 ** responsibility of the caller to eventually free the object using
159808 ** sqlite3_free().
159809 **
159810 ** If an error occurs, leave an error code and message in the rbu handle
159811 ** and return NULL.
159812 */
159813 static RbuState *rbuLoadState(sqlite3rbu *p){
159814 RbuState *pRet = 0;
159815 sqlite3_stmt *pStmt = 0;
159816 int rc;
159817 int rc2;
159818
159819 pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
159820 if( pRet==0 ) return 0;
159821
159822 rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
159823 sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
159824 );
159825 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
159826 switch( sqlite3_column_int(pStmt, 0) ){
159827 case RBU_STATE_STAGE:
159828 pRet->eStage = sqlite3_column_int(pStmt, 1);
159829 if( pRet->eStage!=RBU_STAGE_OAL
159830 && pRet->eStage!=RBU_STAGE_MOVE
159831 && pRet->eStage!=RBU_STAGE_CKPT
159832 ){
159833 p->rc = SQLITE_CORRUPT;
159834 }
159835 break;
159836
159837 case RBU_STATE_TBL:
159838 pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159839 break;
159840
159841 case RBU_STATE_IDX:
159842 pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
159843 break;
159844
159845 case RBU_STATE_ROW:
159846 pRet->nRow = sqlite3_column_int(pStmt, 1);
159847 break;
159848
159849 case RBU_STATE_PROGRESS:
159850 pRet->nProgress = sqlite3_column_int64(pStmt, 1);
159851 break;
159852
159853 case RBU_STATE_CKPT:
159854 pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
159855 break;
159856
159857 case RBU_STATE_COOKIE:
159858 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
159859 break;
159860
159861 case RBU_STATE_OALSZ:
159862 pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
159863 break;
159864
159865 default:
159866 rc = SQLITE_CORRUPT;
@@ -159632,142 +159877,142 @@
159877 /*
159878 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
159879 ** otherwise. Either or both argument may be NULL. Two NULL values are
159880 ** considered equal, and NULL is considered distinct from all other values.
159881 */
159882 static int rbuStrCompare(const char *z1, const char *z2){
159883 if( z1==0 && z2==0 ) return 0;
159884 if( z1==0 || z2==0 ) return 1;
159885 return (sqlite3_stricmp(z1, z2)!=0);
159886 }
159887
159888 /*
159889 ** This function is called as part of sqlite3rbu_open() when initializing
159890 ** an rbu handle in OAL stage. If the rbu update has not started (i.e.
159891 ** the rbu_state table was empty) it is a no-op. Otherwise, it arranges
159892 ** things so that the next call to sqlite3rbu_step() continues on from
159893 ** where the previous rbu handle left off.
159894 **
159895 ** If an error occurs, an error code and error message are left in the
159896 ** rbu handle passed as the first argument.
159897 */
159898 static void rbuSetupOal(sqlite3rbu *p, RbuState *pState){
159899 assert( p->rc==SQLITE_OK );
159900 if( pState->zTbl ){
159901 RbuObjIter *pIter = &p->objiter;
159902 int rc = SQLITE_OK;
159903
159904 while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup
159905 || rbuStrCompare(pIter->zIdx, pState->zIdx)
159906 || rbuStrCompare(pIter->zTbl, pState->zTbl)
159907 )){
159908 rc = rbuObjIterNext(p, pIter);
159909 }
159910
159911 if( rc==SQLITE_OK && !pIter->zTbl ){
159912 rc = SQLITE_ERROR;
159913 p->zErrmsg = sqlite3_mprintf("rbu_state mismatch error");
159914 }
159915
159916 if( rc==SQLITE_OK ){
159917 p->nStep = pState->nRow;
159918 rc = rbuObjIterPrepareAll(p, &p->objiter, p->nStep);
159919 }
159920
159921 p->rc = rc;
159922 }
159923 }
159924
159925 /*
159926 ** If there is a "*-oal" file in the file-system corresponding to the
159927 ** target database in the file-system, delete it. If an error occurs,
159928 ** leave an error code and error message in the rbu handle.
159929 */
159930 static void rbuDeleteOalFile(sqlite3rbu *p){
159931 char *zOal = sqlite3_mprintf("%s-oal", p->zTarget);
159932 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159933 unlink(zOal);
159934 sqlite3_free(zOal);
159935 }
159936
159937 /*
159938 ** Allocate a private rbu VFS for the rbu handle passed as the only
159939 ** argument. This VFS will be used unless the call to sqlite3rbu_open()
159940 ** specified a URI with a vfs=? option in place of a target database
159941 ** file name.
159942 */
159943 static void rbuCreateVfs(sqlite3rbu *p){
159944 int rnd;
159945 char zRnd[64];
159946
159947 assert( p->rc==SQLITE_OK );
159948 sqlite3_randomness(sizeof(int), (void*)&rnd);
159949 sqlite3_snprintf(sizeof(zRnd), zRnd, "rbu_vfs_%d", rnd);
159950 p->rc = sqlite3rbu_create_vfs(zRnd, 0);
159951 if( p->rc==SQLITE_OK ){
159952 sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd);
159953 assert( pVfs );
159954 p->zVfsName = pVfs->zName;
159955 }
159956 }
159957
159958 /*
159959 ** Destroy the private VFS created for the rbu handle passed as the only
159960 ** argument by an earlier call to rbuCreateVfs().
159961 */
159962 static void rbuDeleteVfs(sqlite3rbu *p){
159963 if( p->zVfsName ){
159964 sqlite3rbu_destroy_vfs(p->zVfsName);
159965 p->zVfsName = 0;
159966 }
159967 }
159968
159969 /*
159970 ** Open and return a new RBU handle.
159971 */
159972 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
159973 const char *zTarget,
159974 const char *zRbu,
159975 const char *zState
159976 ){
159977 sqlite3rbu *p;
159978 int nTarget = strlen(zTarget);
159979 int nRbu = strlen(zRbu);
159980 int nState = zState ? strlen(zState) : 0;
159981
159982 p = (sqlite3rbu*)sqlite3_malloc(sizeof(sqlite3rbu)+nTarget+1+nRbu+1+nState+1);
159983 if( p ){
159984 RbuState *pState = 0;
159985
159986 /* Create the custom VFS. */
159987 memset(p, 0, sizeof(sqlite3rbu));
159988 rbuCreateVfs(p);
159989
159990 /* Open the target database */
159991 if( p->rc==SQLITE_OK ){
159992 p->zTarget = (char*)&p[1];
159993 memcpy(p->zTarget, zTarget, nTarget+1);
159994 p->zRbu = &p->zTarget[nTarget+1];
159995 memcpy(p->zRbu, zRbu, nRbu+1);
159996 if( zState ){
159997 p->zState = &p->zRbu[nRbu+1];
159998 memcpy(p->zState, zState, nState+1);
159999 }
160000 rbuOpenDatabase(p);
160001 }
160002
160003 /* If it has not already been created, create the rbu_state table */
160004 rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
160005
160006 if( p->rc==SQLITE_OK ){
160007 pState = rbuLoadState(p);
160008 assert( pState || p->rc!=SQLITE_OK );
160009 if( p->rc==SQLITE_OK ){
160010
160011 if( pState->eStage==0 ){
160012 rbuDeleteOalFile(p);
160013 p->eStage = RBU_STAGE_OAL;
160014 }else{
160015 p->eStage = pState->eStage;
160016 }
160017 p->nProgress = pState->nProgress;
160018 p->iOalSz = pState->iOalSz;
@@ -159774,97 +160019,97 @@
160019 }
160020 }
160021 assert( p->rc!=SQLITE_OK || p->eStage!=0 );
160022
160023 if( p->rc==SQLITE_OK && p->pTargetFd->pWalFd ){
160024 if( p->eStage==RBU_STAGE_OAL ){
160025 p->rc = SQLITE_ERROR;
160026 p->zErrmsg = sqlite3_mprintf("cannot update wal mode database");
160027 }else if( p->eStage==RBU_STAGE_MOVE ){
160028 p->eStage = RBU_STAGE_CKPT;
160029 p->nStep = 0;
160030 }
160031 }
160032
160033 if( p->rc==SQLITE_OK
160034 && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
160035 && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
160036 ){
160037 /* At this point (pTargetFd->iCookie) contains the value of the
160038 ** change-counter cookie (the thing that gets incremented when a
160039 ** transaction is committed in rollback mode) currently stored on
160040 ** page 1 of the database file. */
160041 p->rc = SQLITE_BUSY;
160042 p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
160043 }
160044
160045 if( p->rc==SQLITE_OK ){
160046 if( p->eStage==RBU_STAGE_OAL ){
160047
160048 /* Open transactions both databases. The *-oal file is opened or
160049 ** created at this point. */
160050 p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160051 if( p->rc==SQLITE_OK ){
160052 p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160053 }
160054
160055 /* Point the object iterator at the first object */
160056 if( p->rc==SQLITE_OK ){
160057 p->rc = rbuObjIterFirst(p, &p->objiter);
160058 }
160059
160060 /* If the RBU database contains no data_xxx tables, declare the RBU
160061 ** update finished. */
160062 if( p->rc==SQLITE_OK && p->objiter.zTbl==0 ){
160063 p->rc = SQLITE_DONE;
160064 }
160065
160066 if( p->rc==SQLITE_OK ){
160067 rbuSetupOal(p, pState);
160068 }
160069
160070 }else if( p->eStage==RBU_STAGE_MOVE ){
160071 /* no-op */
160072 }else if( p->eStage==RBU_STAGE_CKPT ){
160073 rbuSetupCheckpoint(p, pState);
160074 }else if( p->eStage==RBU_STAGE_DONE ){
160075 p->rc = SQLITE_DONE;
160076 }else{
160077 p->rc = SQLITE_CORRUPT;
160078 }
160079 }
160080
160081 rbuFreeState(pState);
160082 }
160083
160084 return p;
160085 }
160086
160087
160088 /*
160089 ** Return the database handle used by pRbu.
160090 */
160091 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
160092 sqlite3 *db = 0;
160093 if( pRbu ){
160094 db = (bRbu ? pRbu->dbRbu : pRbu->dbMain);
160095 }
160096 return db;
160097 }
160098
160099
160100 /*
160101 ** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT,
160102 ** then edit any error message string so as to remove all occurrences of
160103 ** the pattern "rbu_imp_[0-9]*".
160104 */
160105 static void rbuEditErrmsg(sqlite3rbu *p){
160106 if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
160107 int i;
160108 int nErrmsg = strlen(p->zErrmsg);
160109 for(i=0; i<(nErrmsg-8); i++){
160110 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
160111 int nDel = 8;
160112 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
160113 memmove(&p->zErrmsg[i], &p->zErrmsg[i+nDel], nErrmsg + 1 - i - nDel);
160114 nErrmsg -= nDel;
160115 }
@@ -159871,38 +160116,38 @@
160116 }
160117 }
160118 }
160119
160120 /*
160121 ** Close the RBU handle.
160122 */
160123 SQLITE_API int SQLITE_STDCALL sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){
160124 int rc;
160125 if( p ){
160126
160127 /* Commit the transaction to the *-oal file. */
160128 if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
160129 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
160130 }
160131
160132 rbuSaveState(p, p->eStage);
160133
160134 if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
160135 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
160136 }
160137
160138 /* Close any open statement handles. */
160139 rbuObjIterFinalize(&p->objiter);
160140
160141 /* Close the open database handle and VFS object. */
160142 sqlite3_close(p->dbMain);
160143 sqlite3_close(p->dbRbu);
160144 rbuDeleteVfs(p);
160145 sqlite3_free(p->aBuf);
160146 sqlite3_free(p->aFrame);
160147
160148 rbuEditErrmsg(p);
160149 rc = p->rc;
160150 *pzErrmsg = p->zErrmsg;
160151 sqlite3_free(p);
160152 }else{
160153 rc = SQLITE_NOMEM;
@@ -159912,65 +160157,65 @@
160157 }
160158
160159 /*
160160 ** Return the total number of key-value operations (inserts, deletes or
160161 ** updates) that have been performed on the target database since the
160162 ** current RBU update was started.
160163 */
160164 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){
160165 return pRbu->nProgress;
160166 }
160167
160168 /**************************************************************************
160169 ** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
160170 ** of a standard VFS in the following ways:
160171 **
160172 ** 1. Whenever the first page of a main database file is read or
160173 ** written, the value of the change-counter cookie is stored in
160174 ** rbu_file.iCookie. Similarly, the value of the "write-version"
160175 ** database header field is stored in rbu_file.iWriteVer. This ensures
160176 ** that the values are always trustworthy within an open transaction.
160177 **
160178 ** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (rbu_file.pWalFd)
160179 ** member variable of the associated database file descriptor is set
160180 ** to point to the new file. A mutex protected linked list of all main
160181 ** db fds opened using a particular RBU VFS is maintained at
160182 ** rbu_vfs.pMain to facilitate this.
160183 **
160184 ** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file
160185 ** object can be marked as the target database of an RBU update. This
160186 ** turns on the following extra special behaviour:
160187 **
160188 ** 3a. If xAccess() is called to check if there exists a *-wal file
160189 ** associated with an RBU target database currently in RBU_STAGE_OAL
160190 ** stage (preparing the *-oal file), the following special handling
160191 ** applies:
160192 **
160193 ** * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU
160194 ** target database may not be in wal mode already.
160195 **
160196 ** * if the *-wal file does not exist, set the output parameter to
160197 ** non-zero (to tell SQLite that it does exist) anyway.
160198 **
160199 ** Then, when xOpen() is called to open the *-wal file associated with
160200 ** the RBU target in RBU_STAGE_OAL stage, instead of opening the *-wal
160201 ** file, the rbu vfs opens the corresponding *-oal file instead.
160202 **
160203 ** 3b. The *-shm pages returned by xShmMap() for a target db file in
160204 ** RBU_STAGE_OAL mode are actually stored in heap memory. This is to
160205 ** avoid creating a *-shm file on disk. Additionally, xShmLock() calls
160206 ** are no-ops on target database files in RBU_STAGE_OAL mode. This is
160207 ** because assert() statements in some VFS implementations fail if
160208 ** xShmLock() is called before xShmMap().
160209 **
160210 ** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
160211 ** mode except RBU_STAGE_DONE (all work completed and checkpointed), it
160212 ** fails with an SQLITE_BUSY error. This is to stop RBU connections
160213 ** from automatically checkpointing a *-wal (or *-oal) file from within
160214 ** sqlite3_close().
160215 **
160216 ** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
160217 ** all xWrite() calls on the target database file perform no IO.
160218 ** Instead the frame and page numbers that would be read and written
160219 ** are recorded. Additionally, successful attempts to obtain exclusive
160220 ** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
160221 ** database file are recorded. xShmLock() calls to unlock the same
@@ -159977,28 +160222,28 @@
160222 ** locks are no-ops (so that once obtained, these locks are never
160223 ** relinquished). Finally, calls to xSync() on the target database
160224 ** file fail with SQLITE_INTERNAL errors.
160225 */
160226
160227 static void rbuUnlockShm(rbu_file *p){
160228 if( p->pRbu ){
160229 int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock;
160230 int i;
160231 for(i=0; i<SQLITE_SHM_NLOCK;i++){
160232 if( (1<<i) & p->pRbu->mLock ){
160233 xShmLock(p->pReal, i, 1, SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE);
160234 }
160235 }
160236 p->pRbu->mLock = 0;
160237 }
160238 }
160239
160240 /*
160241 ** Close an rbu file.
160242 */
160243 static int rbuVfsClose(sqlite3_file *pFile){
160244 rbu_file *p = (rbu_file*)pFile;
160245 int rc;
160246 int i;
160247
160248 /* Free the contents of the apShm[] array. And the array itself. */
160249 for(i=0; i<p->nShm; i++){
@@ -160007,16 +160252,16 @@
160252 sqlite3_free(p->apShm);
160253 p->apShm = 0;
160254 sqlite3_free(p->zDel);
160255
160256 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160257 rbu_file **pp;
160258 sqlite3_mutex_enter(p->pRbuVfs->mutex);
160259 for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext));
160260 *pp = p->pMainNext;
160261 sqlite3_mutex_leave(p->pRbuVfs->mutex);
160262 rbuUnlockShm(p);
160263 p->pReal->pMethods->xShmUnmap(p->pReal, 0);
160264 }
160265
160266 /* Close the underlying file handle */
160267 rc = p->pReal->pMethods->xClose(p->pReal);
@@ -160026,37 +160271,37 @@
160271
160272 /*
160273 ** Read and return an unsigned 32-bit big-endian integer from the buffer
160274 ** passed as the only argument.
160275 */
160276 static u32 rbuGetU32(u8 *aBuf){
160277 return ((u32)aBuf[0] << 24)
160278 + ((u32)aBuf[1] << 16)
160279 + ((u32)aBuf[2] << 8)
160280 + ((u32)aBuf[3]);
160281 }
160282
160283 /*
160284 ** Read data from an rbuVfs-file.
160285 */
160286 static int rbuVfsRead(
160287 sqlite3_file *pFile,
160288 void *zBuf,
160289 int iAmt,
160290 sqlite_int64 iOfst
160291 ){
160292 rbu_file *p = (rbu_file*)pFile;
160293 sqlite3rbu *pRbu = p->pRbu;
160294 int rc;
160295
160296 if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
160297 assert( p->openFlags & SQLITE_OPEN_WAL );
160298 rc = rbuCaptureWalRead(p->pRbu, iOfst, iAmt);
160299 }else{
160300 if( pRbu && pRbu->eStage==RBU_STAGE_OAL
160301 && (p->openFlags & SQLITE_OPEN_WAL)
160302 && iOfst>=pRbu->iOalSz
160303 ){
160304 rc = SQLITE_OK;
160305 memset(zBuf, 0, iAmt);
160306 }else{
160307 rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
@@ -160063,92 +160308,92 @@
160308 }
160309 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160310 /* These look like magic numbers. But they are stable, as they are part
160311 ** of the definition of the SQLite file format, which may not change. */
160312 u8 *pBuf = (u8*)zBuf;
160313 p->iCookie = rbuGetU32(&pBuf[24]);
160314 p->iWriteVer = pBuf[19];
160315 }
160316 }
160317 return rc;
160318 }
160319
160320 /*
160321 ** Write data to an rbuVfs-file.
160322 */
160323 static int rbuVfsWrite(
160324 sqlite3_file *pFile,
160325 const void *zBuf,
160326 int iAmt,
160327 sqlite_int64 iOfst
160328 ){
160329 rbu_file *p = (rbu_file*)pFile;
160330 sqlite3rbu *pRbu = p->pRbu;
160331 int rc;
160332
160333 if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
160334 assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
160335 rc = rbuCaptureDbWrite(p->pRbu, iOfst);
160336 }else{
160337 if( pRbu && pRbu->eStage==RBU_STAGE_OAL
160338 && (p->openFlags & SQLITE_OPEN_WAL)
160339 && iOfst>=pRbu->iOalSz
160340 ){
160341 pRbu->iOalSz = iAmt + iOfst;
160342 }
160343 rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
160344 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
160345 /* These look like magic numbers. But they are stable, as they are part
160346 ** of the definition of the SQLite file format, which may not change. */
160347 u8 *pBuf = (u8*)zBuf;
160348 p->iCookie = rbuGetU32(&pBuf[24]);
160349 p->iWriteVer = pBuf[19];
160350 }
160351 }
160352 return rc;
160353 }
160354
160355 /*
160356 ** Truncate an rbuVfs-file.
160357 */
160358 static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
160359 rbu_file *p = (rbu_file*)pFile;
160360 return p->pReal->pMethods->xTruncate(p->pReal, size);
160361 }
160362
160363 /*
160364 ** Sync an rbuVfs-file.
160365 */
160366 static int rbuVfsSync(sqlite3_file *pFile, int flags){
160367 rbu_file *p = (rbu_file *)pFile;
160368 if( p->pRbu && p->pRbu->eStage==RBU_STAGE_CAPTURE ){
160369 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
160370 return SQLITE_INTERNAL;
160371 }
160372 return SQLITE_OK;
160373 }
160374 return p->pReal->pMethods->xSync(p->pReal, flags);
160375 }
160376
160377 /*
160378 ** Return the current file-size of an rbuVfs-file.
160379 */
160380 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
160381 rbu_file *p = (rbu_file *)pFile;
160382 return p->pReal->pMethods->xFileSize(p->pReal, pSize);
160383 }
160384
160385 /*
160386 ** Lock an rbuVfs-file.
160387 */
160388 static int rbuVfsLock(sqlite3_file *pFile, int eLock){
160389 rbu_file *p = (rbu_file*)pFile;
160390 sqlite3rbu *pRbu = p->pRbu;
160391 int rc = SQLITE_OK;
160392
160393 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160394 if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){
160395 /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
160396 ** prevents it from checkpointing the database from sqlite3_close(). */
160397 rc = SQLITE_BUSY;
160398 }else{
160399 rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -160156,122 +160401,122 @@
160401
160402 return rc;
160403 }
160404
160405 /*
160406 ** Unlock an rbuVfs-file.
160407 */
160408 static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){
160409 rbu_file *p = (rbu_file *)pFile;
160410 return p->pReal->pMethods->xUnlock(p->pReal, eLock);
160411 }
160412
160413 /*
160414 ** Check if another file-handle holds a RESERVED lock on an rbuVfs-file.
160415 */
160416 static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
160417 rbu_file *p = (rbu_file *)pFile;
160418 return p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut);
160419 }
160420
160421 /*
160422 ** File control method. For custom operations on an rbuVfs-file.
160423 */
160424 static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
160425 rbu_file *p = (rbu_file *)pFile;
160426 int (*xControl)(sqlite3_file*,int,void*) = p->pReal->pMethods->xFileControl;
160427 int rc;
160428
160429 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB)
160430 || p->openFlags & (SQLITE_OPEN_TRANSIENT_DB|SQLITE_OPEN_TEMP_JOURNAL)
160431 );
160432 if( op==SQLITE_FCNTL_RBU ){
160433 sqlite3rbu *pRbu = (sqlite3rbu*)pArg;
160434
160435 /* First try to find another RBU vfs lower down in the vfs stack. If
160436 ** one is found, this vfs will operate in pass-through mode. The lower
160437 ** level vfs will do the special RBU handling. */
160438 rc = xControl(p->pReal, op, pArg);
160439
160440 if( rc==SQLITE_NOTFOUND ){
160441 /* Now search for a zipvfs instance lower down in the VFS stack. If
160442 ** one is found, this is an error. */
160443 void *dummy = 0;
160444 rc = xControl(p->pReal, SQLITE_FCNTL_ZIPVFS, &dummy);
160445 if( rc==SQLITE_OK ){
160446 rc = SQLITE_ERROR;
160447 pRbu->zErrmsg = sqlite3_mprintf("rbu/zipvfs setup error");
160448 }else if( rc==SQLITE_NOTFOUND ){
160449 pRbu->pTargetFd = p;
160450 p->pRbu = pRbu;
160451 if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
160452 rc = SQLITE_OK;
160453 }
160454 }
160455 return rc;
160456 }
160457
160458 rc = xControl(p->pReal, op, pArg);
160459 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
160460 rbu_vfs *pRbuVfs = p->pRbuVfs;
160461 char *zIn = *(char**)pArg;
160462 char *zOut = sqlite3_mprintf("rbu(%s)/%z", pRbuVfs->base.zName, zIn);
160463 *(char**)pArg = zOut;
160464 if( zOut==0 ) rc = SQLITE_NOMEM;
160465 }
160466
160467 return rc;
160468 }
160469
160470 /*
160471 ** Return the sector-size in bytes for an rbuVfs-file.
160472 */
160473 static int rbuVfsSectorSize(sqlite3_file *pFile){
160474 rbu_file *p = (rbu_file *)pFile;
160475 return p->pReal->pMethods->xSectorSize(p->pReal);
160476 }
160477
160478 /*
160479 ** Return the device characteristic flags supported by an rbuVfs-file.
160480 */
160481 static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){
160482 rbu_file *p = (rbu_file *)pFile;
160483 return p->pReal->pMethods->xDeviceCharacteristics(p->pReal);
160484 }
160485
160486 /*
160487 ** Take or release a shared-memory lock.
160488 */
160489 static int rbuVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
160490 rbu_file *p = (rbu_file*)pFile;
160491 sqlite3rbu *pRbu = p->pRbu;
160492 int rc = SQLITE_OK;
160493
160494 #ifdef SQLITE_AMALGAMATION
160495 assert( WAL_CKPT_LOCK==1 );
160496 #endif
160497
160498 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160499 if( pRbu && (pRbu->eStage==RBU_STAGE_OAL || pRbu->eStage==RBU_STAGE_MOVE) ){
160500 /* Magic number 1 is the WAL_CKPT_LOCK lock. Preventing SQLite from
160501 ** taking this lock also prevents any checkpoints from occurring.
160502 ** todo: really, it's not clear why this might occur, as
160503 ** wal_autocheckpoint ought to be turned off. */
160504 if( ofst==WAL_LOCK_CKPT && n==1 ) rc = SQLITE_BUSY;
160505 }else{
160506 int bCapture = 0;
160507 if( n==1 && (flags & SQLITE_SHM_EXCLUSIVE)
160508 && pRbu && pRbu->eStage==RBU_STAGE_CAPTURE
160509 && (ofst==WAL_LOCK_WRITE || ofst==WAL_LOCK_CKPT || ofst==WAL_LOCK_READ0)
160510 ){
160511 bCapture = 1;
160512 }
160513
160514 if( bCapture==0 || 0==(flags & SQLITE_SHM_UNLOCK) ){
160515 rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags);
160516 if( bCapture && rc==SQLITE_OK ){
160517 pRbu->mLock |= (1 << ofst);
160518 }
160519 }
160520 }
160521
160522 return rc;
@@ -160278,26 +160523,26 @@
160523 }
160524
160525 /*
160526 ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
160527 */
160528 static int rbuVfsShmMap(
160529 sqlite3_file *pFile,
160530 int iRegion,
160531 int szRegion,
160532 int isWrite,
160533 void volatile **pp
160534 ){
160535 rbu_file *p = (rbu_file*)pFile;
160536 int rc = SQLITE_OK;
160537 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
160538
160539 /* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this
160540 ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
160541 ** instead of a file on disk. */
160542 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160543 if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
160544 if( iRegion<=p->nShm ){
160545 int nByte = (iRegion+1) * sizeof(char*);
160546 char **apNew = (char**)sqlite3_realloc(p->apShm, nByte);
160547 if( apNew==0 ){
160548 rc = SQLITE_NOMEM;
@@ -160332,29 +160577,29 @@
160577 }
160578
160579 /*
160580 ** Memory barrier.
160581 */
160582 static void rbuVfsShmBarrier(sqlite3_file *pFile){
160583 rbu_file *p = (rbu_file *)pFile;
160584 p->pReal->pMethods->xShmBarrier(p->pReal);
160585 }
160586
160587 /*
160588 ** The xShmUnmap method.
160589 */
160590 static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){
160591 rbu_file *p = (rbu_file*)pFile;
160592 int rc = SQLITE_OK;
160593 int eStage = (p->pRbu ? p->pRbu->eStage : 0);
160594
160595 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
160596 if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
160597 /* no-op */
160598 }else{
160599 /* Release the checkpointer and writer locks */
160600 rbuUnlockShm(p);
160601 rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
160602 }
160603 return rc;
160604 }
160605
@@ -160362,56 +160607,56 @@
160607 ** Given that zWal points to a buffer containing a wal file name passed to
160608 ** either the xOpen() or xAccess() VFS method, return a pointer to the
160609 ** file-handle opened by the same database connection on the corresponding
160610 ** database file.
160611 */
160612 static rbu_file *rbuFindMaindb(rbu_vfs *pRbuVfs, const char *zWal){
160613 rbu_file *pDb;
160614 sqlite3_mutex_enter(pRbuVfs->mutex);
160615 for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext);
160616 sqlite3_mutex_leave(pRbuVfs->mutex);
160617 return pDb;
160618 }
160619
160620 /*
160621 ** Open an rbu file handle.
160622 */
160623 static int rbuVfsOpen(
160624 sqlite3_vfs *pVfs,
160625 const char *zName,
160626 sqlite3_file *pFile,
160627 int flags,
160628 int *pOutFlags
160629 ){
160630 static sqlite3_io_methods rbuvfs_io_methods = {
160631 2, /* iVersion */
160632 rbuVfsClose, /* xClose */
160633 rbuVfsRead, /* xRead */
160634 rbuVfsWrite, /* xWrite */
160635 rbuVfsTruncate, /* xTruncate */
160636 rbuVfsSync, /* xSync */
160637 rbuVfsFileSize, /* xFileSize */
160638 rbuVfsLock, /* xLock */
160639 rbuVfsUnlock, /* xUnlock */
160640 rbuVfsCheckReservedLock, /* xCheckReservedLock */
160641 rbuVfsFileControl, /* xFileControl */
160642 rbuVfsSectorSize, /* xSectorSize */
160643 rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
160644 rbuVfsShmMap, /* xShmMap */
160645 rbuVfsShmLock, /* xShmLock */
160646 rbuVfsShmBarrier, /* xShmBarrier */
160647 rbuVfsShmUnmap /* xShmUnmap */
160648 };
160649 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
160650 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
160651 rbu_file *pFd = (rbu_file *)pFile;
160652 int rc = SQLITE_OK;
160653 const char *zOpen = zName;
160654
160655 memset(pFd, 0, sizeof(rbu_file));
160656 pFd->pReal = (sqlite3_file*)&pFd[1];
160657 pFd->pRbuVfs = pRbuVfs;
160658 pFd->openFlags = flags;
160659 if( zName ){
160660 if( flags & SQLITE_OPEN_MAIN_DB ){
160661 /* A main database has just been opened. The following block sets
160662 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
@@ -160435,13 +160680,13 @@
160680 }
160681 z += (n + 8 + 1);
160682 pFd->zWal = z;
160683 }
160684 else if( flags & SQLITE_OPEN_WAL ){
160685 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
160686 if( pDb ){
160687 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
160688 /* This call is to open a *-wal file. Intead, open the *-oal. This
160689 ** code ensures that the string passed to xOpen() is terminated by a
160690 ** pair of '\0' bytes in case the VFS attempts to extract a URI
160691 ** parameter from it. */
160692 int nCopy = strlen(zName);
@@ -160453,11 +160698,11 @@
160698 zCopy[nCopy+1] = '\0';
160699 zOpen = (const char*)(pFd->zDel = zCopy);
160700 }else{
160701 rc = SQLITE_NOMEM;
160702 }
160703 pFd->pRbu = pDb->pRbu;
160704 }
160705 pDb->pWalFd = pFd;
160706 }
160707 }
160708 }
@@ -160467,16 +160712,16 @@
160712 }
160713 if( pFd->pReal->pMethods ){
160714 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
160715 ** pointer and, if the file is a main database file, link it into the
160716 ** mutex protected linked list of all such files. */
160717 pFile->pMethods = &rbuvfs_io_methods;
160718 if( flags & SQLITE_OPEN_MAIN_DB ){
160719 sqlite3_mutex_enter(pRbuVfs->mutex);
160720 pFd->pMainNext = pRbuVfs->pMain;
160721 pRbuVfs->pMain = pFd;
160722 sqlite3_mutex_leave(pRbuVfs->mutex);
160723 }
160724 }else{
160725 sqlite3_free(pFd->zDel);
160726 }
160727
@@ -160484,48 +160729,48 @@
160729 }
160730
160731 /*
160732 ** Delete the file located at zPath.
160733 */
160734 static int rbuVfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
160735 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160736 return pRealVfs->xDelete(pRealVfs, zPath, dirSync);
160737 }
160738
160739 /*
160740 ** Test for access permissions. Return true if the requested permission
160741 ** is available, or false otherwise.
160742 */
160743 static int rbuVfsAccess(
160744 sqlite3_vfs *pVfs,
160745 const char *zPath,
160746 int flags,
160747 int *pResOut
160748 ){
160749 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
160750 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
160751 int rc;
160752
160753 rc = pRealVfs->xAccess(pRealVfs, zPath, flags, pResOut);
160754
160755 /* If this call is to check if a *-wal file associated with an RBU target
160756 ** database connection exists, and the RBU update is in RBU_STAGE_OAL,
160757 ** the following special handling is activated:
160758 **
160759 ** a) if the *-wal file does exist, return SQLITE_CANTOPEN. This
160760 ** ensures that the RBU extension never tries to update a database
160761 ** in wal mode, even if the first page of the database file has
160762 ** been damaged.
160763 **
160764 ** b) if the *-wal file does not exist, claim that it does anyway,
160765 ** causing SQLite to call xOpen() to open it. This call will also
160766 ** be intercepted (see the rbuVfsOpen() function) and the *-oal
160767 ** file opened instead.
160768 */
160769 if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){
160770 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath);
160771 if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
160772 if( *pResOut ){
160773 rc = SQLITE_CANTOPEN;
160774 }else{
160775 *pResOut = 1;
160776 }
@@ -160538,151 +160783,151 @@
160783 /*
160784 ** Populate buffer zOut with the full canonical pathname corresponding
160785 ** to the pathname in zPath. zOut is guaranteed to point to a buffer
160786 ** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
160787 */
160788 static int rbuVfsFullPathname(
160789 sqlite3_vfs *pVfs,
160790 const char *zPath,
160791 int nOut,
160792 char *zOut
160793 ){
160794 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160795 return pRealVfs->xFullPathname(pRealVfs, zPath, nOut, zOut);
160796 }
160797
160798 #ifndef SQLITE_OMIT_LOAD_EXTENSION
160799 /*
160800 ** Open the dynamic library located at zPath and return a handle.
160801 */
160802 static void *rbuVfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
160803 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160804 return pRealVfs->xDlOpen(pRealVfs, zPath);
160805 }
160806
160807 /*
160808 ** Populate the buffer zErrMsg (size nByte bytes) with a human readable
160809 ** utf-8 string describing the most recent error encountered associated
160810 ** with dynamic libraries.
160811 */
160812 static void rbuVfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
160813 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160814 pRealVfs->xDlError(pRealVfs, nByte, zErrMsg);
160815 }
160816
160817 /*
160818 ** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
160819 */
160820 static void (*rbuVfsDlSym(
160821 sqlite3_vfs *pVfs,
160822 void *pArg,
160823 const char *zSym
160824 ))(void){
160825 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160826 return pRealVfs->xDlSym(pRealVfs, pArg, zSym);
160827 }
160828
160829 /*
160830 ** Close the dynamic library handle pHandle.
160831 */
160832 static void rbuVfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
160833 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160834 pRealVfs->xDlClose(pRealVfs, pHandle);
160835 }
160836 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
160837
160838 /*
160839 ** Populate the buffer pointed to by zBufOut with nByte bytes of
160840 ** random data.
160841 */
160842 static int rbuVfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
160843 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160844 return pRealVfs->xRandomness(pRealVfs, nByte, zBufOut);
160845 }
160846
160847 /*
160848 ** Sleep for nMicro microseconds. Return the number of microseconds
160849 ** actually slept.
160850 */
160851 static int rbuVfsSleep(sqlite3_vfs *pVfs, int nMicro){
160852 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160853 return pRealVfs->xSleep(pRealVfs, nMicro);
160854 }
160855
160856 /*
160857 ** Return the current time as a Julian Day number in *pTimeOut.
160858 */
160859 static int rbuVfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
160860 sqlite3_vfs *pRealVfs = ((rbu_vfs*)pVfs)->pRealVfs;
160861 return pRealVfs->xCurrentTime(pRealVfs, pTimeOut);
160862 }
160863
160864 /*
160865 ** No-op.
160866 */
160867 static int rbuVfsGetLastError(sqlite3_vfs *pVfs, int a, char *b){
160868 return 0;
160869 }
160870
160871 /*
160872 ** Deregister and destroy an RBU vfs created by an earlier call to
160873 ** sqlite3rbu_create_vfs().
160874 */
160875 SQLITE_API void SQLITE_STDCALL sqlite3rbu_destroy_vfs(const char *zName){
160876 sqlite3_vfs *pVfs = sqlite3_vfs_find(zName);
160877 if( pVfs && pVfs->xOpen==rbuVfsOpen ){
160878 sqlite3_mutex_free(((rbu_vfs*)pVfs)->mutex);
160879 sqlite3_vfs_unregister(pVfs);
160880 sqlite3_free(pVfs);
160881 }
160882 }
160883
160884 /*
160885 ** Create an RBU VFS named zName that accesses the underlying file-system
160886 ** via existing VFS zParent. The new object is registered as a non-default
160887 ** VFS with SQLite before returning.
160888 */
160889 SQLITE_API int SQLITE_STDCALL sqlite3rbu_create_vfs(const char *zName, const char *zParent){
160890
160891 /* Template for VFS */
160892 static sqlite3_vfs vfs_template = {
160893 1, /* iVersion */
160894 0, /* szOsFile */
160895 0, /* mxPathname */
160896 0, /* pNext */
160897 0, /* zName */
160898 0, /* pAppData */
160899 rbuVfsOpen, /* xOpen */
160900 rbuVfsDelete, /* xDelete */
160901 rbuVfsAccess, /* xAccess */
160902 rbuVfsFullPathname, /* xFullPathname */
160903
160904 #ifndef SQLITE_OMIT_LOAD_EXTENSION
160905 rbuVfsDlOpen, /* xDlOpen */
160906 rbuVfsDlError, /* xDlError */
160907 rbuVfsDlSym, /* xDlSym */
160908 rbuVfsDlClose, /* xDlClose */
160909 #else
160910 0, 0, 0, 0,
160911 #endif
160912
160913 rbuVfsRandomness, /* xRandomness */
160914 rbuVfsSleep, /* xSleep */
160915 rbuVfsCurrentTime, /* xCurrentTime */
160916 rbuVfsGetLastError, /* xGetLastError */
160917 0, /* xCurrentTimeInt64 (version 2) */
160918 0, 0, 0 /* Unimplemented version 3 methods */
160919 };
160920
160921 rbu_vfs *pNew = 0; /* Newly allocated VFS */
160922 int nName;
160923 int rc = SQLITE_OK;
160924
160925 int nByte;
160926 nName = strlen(zName);
160927 nByte = sizeof(rbu_vfs) + nName + 1;
160928 pNew = (rbu_vfs*)sqlite3_malloc(nByte);
160929 if( pNew==0 ){
160930 rc = SQLITE_NOMEM;
160931 }else{
160932 sqlite3_vfs *pParent; /* Parent VFS */
160933 memset(pNew, 0, nByte);
@@ -160691,11 +160936,11 @@
160936 rc = SQLITE_NOTFOUND;
160937 }else{
160938 char *zSpace;
160939 memcpy(&pNew->base, &vfs_template, sizeof(sqlite3_vfs));
160940 pNew->base.mxPathname = pParent->mxPathname;
160941 pNew->base.szOsFile = sizeof(rbu_file) + pParent->szOsFile;
160942 pNew->pRealVfs = pParent;
160943 pNew->base.zName = (const char*)(zSpace = (char*)&pNew[1]);
160944 memcpy(zSpace, zName, nName);
160945
160946 /* Allocate the mutex and register the new VFS (not as the default) */
@@ -160717,13 +160962,13 @@
160962 }
160963
160964
160965 /**************************************************************************/
160966
160967 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */
160968
160969 /************** End of sqlite3rbu.c ******************************************/
160970 /************** Begin file dbstat.c ******************************************/
160971 /*
160972 ** 2010 July 12
160973 **
160974 ** The author disclaims copyright to this source code. In place of
@@ -160741,10 +160986,11 @@
160986 ** information from an SQLite database in order to implement the
160987 ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
160988 ** for an example implementation.
160989 */
160990
160991 /* #include "sqliteInt.h" ** Requires access to internal data structures ** */
160992 #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
160993 && !defined(SQLITE_OMIT_VIRTUALTABLE)
160994
160995 /*
160996 ** Page paths:
160997
+11 -9
--- 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.11"
114
+#define SQLITE_VERSION "3.8.11.1"
115115
#define SQLITE_VERSION_NUMBER 3008011
116
-#define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
116
+#define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -965,13 +965,13 @@
965965
**
966966
** <li>[[SQLITE_FCNTL_ZIPVFS]]
967967
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
968968
** VFS should return SQLITE_NOTFOUND for this opcode.
969969
**
970
-** <li>[[SQLITE_FCNTL_OTA]]
971
-** The [SQLITE_FCNTL_OTA] opcode is implemented by the special VFS used by
972
-** the OTA extension only. All other VFS should return SQLITE_NOTFOUND for
970
+** <li>[[SQLITE_FCNTL_RBU]]
971
+** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
972
+** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
973973
** this opcode.
974974
** </ul>
975975
*/
976976
#define SQLITE_FCNTL_LOCKSTATE 1
977977
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -995,11 +995,11 @@
995995
#define SQLITE_FCNTL_SYNC 21
996996
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
997997
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
998998
#define SQLITE_FCNTL_WAL_BLOCK 24
999999
#define SQLITE_FCNTL_ZIPVFS 25
1000
-#define SQLITE_FCNTL_OTA 26
1000
+#define SQLITE_FCNTL_RBU 26
10011001
10021002
/* deprecated names */
10031003
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
10041004
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
10051005
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3560,10 +3560,11 @@
35603560
SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
35613561
SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
35623562
void(*)(void*), unsigned char encoding);
35633563
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
35643564
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3565
+SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
35653566
35663567
/*
35673568
** CAPI3REF: Number Of SQL Parameters
35683569
** METHOD: sqlite3_stmt
35693570
**
@@ -4532,13 +4533,13 @@
45324533
** ^The sqlite3_result_blob() interface sets the result from
45334534
** an application-defined function to be the BLOB whose content is pointed
45344535
** to by the second parameter and which is N bytes long where N is the
45354536
** third parameter.
45364537
**
4537
-** ^The sqlite3_result_zeroblob() interfaces set the result of
4538
-** the application-defined function to be a BLOB containing all zero
4539
-** bytes and N bytes in size, where N is the value of the 2nd parameter.
4538
+** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
4539
+** interfaces set the result of the application-defined function to be
4540
+** a BLOB containing all zero bytes and N bytes in size.
45404541
**
45414542
** ^The sqlite3_result_double() interface sets the result from
45424543
** an application-defined function to be a floating point value specified
45434544
** by its 2nd argument.
45444545
**
@@ -4649,10 +4650,11 @@
46494650
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
46504651
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
46514652
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
46524653
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
46534654
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4655
+SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
46544656
46554657
/*
46564658
** CAPI3REF: Define New Collating Sequences
46574659
** METHOD: sqlite3
46584660
**
46594661
--- 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.11"
115 #define SQLITE_VERSION_NUMBER 3008011
116 #define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -965,13 +965,13 @@
965 **
966 ** <li>[[SQLITE_FCNTL_ZIPVFS]]
967 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
968 ** VFS should return SQLITE_NOTFOUND for this opcode.
969 **
970 ** <li>[[SQLITE_FCNTL_OTA]]
971 ** The [SQLITE_FCNTL_OTA] opcode is implemented by the special VFS used by
972 ** the OTA extension only. All other VFS should return SQLITE_NOTFOUND for
973 ** this opcode.
974 ** </ul>
975 */
976 #define SQLITE_FCNTL_LOCKSTATE 1
977 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -995,11 +995,11 @@
995 #define SQLITE_FCNTL_SYNC 21
996 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
997 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
998 #define SQLITE_FCNTL_WAL_BLOCK 24
999 #define SQLITE_FCNTL_ZIPVFS 25
1000 #define SQLITE_FCNTL_OTA 26
1001
1002 /* deprecated names */
1003 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1004 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1005 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3560,10 +3560,11 @@
3560 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3561 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3562 void(*)(void*), unsigned char encoding);
3563 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3564 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
 
3565
3566 /*
3567 ** CAPI3REF: Number Of SQL Parameters
3568 ** METHOD: sqlite3_stmt
3569 **
@@ -4532,13 +4533,13 @@
4532 ** ^The sqlite3_result_blob() interface sets the result from
4533 ** an application-defined function to be the BLOB whose content is pointed
4534 ** to by the second parameter and which is N bytes long where N is the
4535 ** third parameter.
4536 **
4537 ** ^The sqlite3_result_zeroblob() interfaces set the result of
4538 ** the application-defined function to be a BLOB containing all zero
4539 ** bytes and N bytes in size, where N is the value of the 2nd parameter.
4540 **
4541 ** ^The sqlite3_result_double() interface sets the result from
4542 ** an application-defined function to be a floating point value specified
4543 ** by its 2nd argument.
4544 **
@@ -4649,10 +4650,11 @@
4649 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4650 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4651 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4652 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4653 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
 
4654
4655 /*
4656 ** CAPI3REF: Define New Collating Sequences
4657 ** METHOD: sqlite3
4658 **
4659
--- 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.11.1"
115 #define SQLITE_VERSION_NUMBER 3008011
116 #define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -965,13 +965,13 @@
965 **
966 ** <li>[[SQLITE_FCNTL_ZIPVFS]]
967 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
968 ** VFS should return SQLITE_NOTFOUND for this opcode.
969 **
970 ** <li>[[SQLITE_FCNTL_RBU]]
971 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
972 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
973 ** this opcode.
974 ** </ul>
975 */
976 #define SQLITE_FCNTL_LOCKSTATE 1
977 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -995,11 +995,11 @@
995 #define SQLITE_FCNTL_SYNC 21
996 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
997 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
998 #define SQLITE_FCNTL_WAL_BLOCK 24
999 #define SQLITE_FCNTL_ZIPVFS 25
1000 #define SQLITE_FCNTL_RBU 26
1001
1002 /* deprecated names */
1003 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1004 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1005 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3560,10 +3560,11 @@
3560 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3561 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3562 void(*)(void*), unsigned char encoding);
3563 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3564 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3565 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
3566
3567 /*
3568 ** CAPI3REF: Number Of SQL Parameters
3569 ** METHOD: sqlite3_stmt
3570 **
@@ -4532,13 +4533,13 @@
4533 ** ^The sqlite3_result_blob() interface sets the result from
4534 ** an application-defined function to be the BLOB whose content is pointed
4535 ** to by the second parameter and which is N bytes long where N is the
4536 ** third parameter.
4537 **
4538 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
4539 ** interfaces set the result of the application-defined function to be
4540 ** a BLOB containing all zero bytes and N bytes in size.
4541 **
4542 ** ^The sqlite3_result_double() interface sets the result from
4543 ** an application-defined function to be a floating point value specified
4544 ** by its 2nd argument.
4545 **
@@ -4649,10 +4650,11 @@
4650 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4651 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4652 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4653 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4654 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4655 SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
4656
4657 /*
4658 ** CAPI3REF: Define New Collating Sequences
4659 ** METHOD: sqlite3
4660 **
4661
--- src/stash.c
+++ src/stash.c
@@ -503,10 +503,11 @@
503503
while( db_step(&q)==SQLITE_ROW ){
504504
newArgv[i++] = mprintf("%s%s", g.zLocalRoot, db_column_text(&q, 0));
505505
}
506506
db_finalize(&q);
507507
newArgv[0] = g.argv[0];
508
+ newArgv[1] = 0;
508509
g.argv = newArgv;
509510
g.argc = nFile+2;
510511
if( nFile==0 ) return;
511512
}
512513
g.argv[1] = "revert";
513514
--- src/stash.c
+++ src/stash.c
@@ -503,10 +503,11 @@
503 while( db_step(&q)==SQLITE_ROW ){
504 newArgv[i++] = mprintf("%s%s", g.zLocalRoot, db_column_text(&q, 0));
505 }
506 db_finalize(&q);
507 newArgv[0] = g.argv[0];
 
508 g.argv = newArgv;
509 g.argc = nFile+2;
510 if( nFile==0 ) return;
511 }
512 g.argv[1] = "revert";
513
--- src/stash.c
+++ src/stash.c
@@ -503,10 +503,11 @@
503 while( db_step(&q)==SQLITE_ROW ){
504 newArgv[i++] = mprintf("%s%s", g.zLocalRoot, db_column_text(&q, 0));
505 }
506 db_finalize(&q);
507 newArgv[0] = g.argv[0];
508 newArgv[1] = 0;
509 g.argv = newArgv;
510 g.argc = nFile+2;
511 if( nFile==0 ) return;
512 }
513 g.argv[1] = "revert";
514
+12 -11
--- src/statrep.c
+++ src/statrep.c
@@ -462,20 +462,20 @@
462462
row colors */
463463
int nMaxEvents = 1; /* max number of events for
464464
all rows. */
465465
Blob userFilter = empty_blob; /* Optional user=johndoe query string */
466466
static const char *const daysOfWeek[] = {
467
- "Monday", "Tuesday", "Wednesday", "Thursday",
468
- "Friday", "Saturday", "Sunday"
467
+ "Sunday", "Monday", "Tuesday", "Wednesday",
468
+ "Thursday", "Friday", "Saturday"
469469
};
470470
471471
stats_report_init_view();
472472
if( zUserName ){
473473
blob_appendf(&userFilter, "user=%s", zUserName);
474474
}
475475
db_prepare(&query,
476
- "SELECT cast(mtime %% 7 AS INTEGER) dow,"
476
+ "SELECT cast(strftime('%%w', mtime) AS INTEGER) dow,"
477477
" COUNT(*) AS eventCount"
478478
" FROM v_reports"
479479
" WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
480480
" GROUP BY dow ORDER BY dow", zUserName);
481481
@ <h1>Timeline Events (%h(stats_report_label_for_type())) by Day of the Week
@@ -484,21 +484,22 @@
484484
}
485485
@ </h1>
486486
db_multi_exec(
487487
"CREATE TEMP TABLE piechart(amt,label);"
488488
"INSERT INTO piechart"
489
- " SELECT count(*), cast(mtime %% 7 AS INT) FROM v_reports"
489
+ " SELECT count(*), cast(strftime('%%w', mtime) AS INT) FROM v_reports"
490490
" WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
491491
" GROUP BY 2 ORDER BY 2;"
492492
"UPDATE piechart SET label = CASE label"
493
- " WHEN 0 THEN 'Monday'"
494
- " WHEN 1 THEN 'Tuesday'"
495
- " WHEN 2 THEN 'Wednesday'"
496
- " WHEN 3 THEN 'Thursday'"
497
- " WHEN 4 THEN 'Friday'"
498
- " WHEN 5 THEN 'Saturday'"
499
- " ELSE 'Sunday' END;", zUserName
493
+ " WHEN 0 THEN 'Sunday'"
494
+ " WHEN 1 THEN 'Monday'"
495
+ " WHEN 2 THEN 'Tuesday'"
496
+ " WHEN 3 THEN 'Wednesday'"
497
+ " WHEN 4 THEN 'Thursday'"
498
+ " WHEN 5 THEN 'Friday'"
499
+ " WHEN 6 THEN 'Saturday'"
500
+ " ELSE 'ERROR' END;", zUserName
500501
);
501502
if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
502503
@ <center><svg width=700 height=400>
503504
piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
504505
@ </svg></centre><hr/>
505506
--- src/statrep.c
+++ src/statrep.c
@@ -462,20 +462,20 @@
462 row colors */
463 int nMaxEvents = 1; /* max number of events for
464 all rows. */
465 Blob userFilter = empty_blob; /* Optional user=johndoe query string */
466 static const char *const daysOfWeek[] = {
467 "Monday", "Tuesday", "Wednesday", "Thursday",
468 "Friday", "Saturday", "Sunday"
469 };
470
471 stats_report_init_view();
472 if( zUserName ){
473 blob_appendf(&userFilter, "user=%s", zUserName);
474 }
475 db_prepare(&query,
476 "SELECT cast(mtime %% 7 AS INTEGER) dow,"
477 " COUNT(*) AS eventCount"
478 " FROM v_reports"
479 " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
480 " GROUP BY dow ORDER BY dow", zUserName);
481 @ <h1>Timeline Events (%h(stats_report_label_for_type())) by Day of the Week
@@ -484,21 +484,22 @@
484 }
485 @ </h1>
486 db_multi_exec(
487 "CREATE TEMP TABLE piechart(amt,label);"
488 "INSERT INTO piechart"
489 " SELECT count(*), cast(mtime %% 7 AS INT) FROM v_reports"
490 " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
491 " GROUP BY 2 ORDER BY 2;"
492 "UPDATE piechart SET label = CASE label"
493 " WHEN 0 THEN 'Monday'"
494 " WHEN 1 THEN 'Tuesday'"
495 " WHEN 2 THEN 'Wednesday'"
496 " WHEN 3 THEN 'Thursday'"
497 " WHEN 4 THEN 'Friday'"
498 " WHEN 5 THEN 'Saturday'"
499 " ELSE 'Sunday' END;", zUserName
 
500 );
501 if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
502 @ <center><svg width=700 height=400>
503 piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
504 @ </svg></centre><hr/>
505
--- src/statrep.c
+++ src/statrep.c
@@ -462,20 +462,20 @@
462 row colors */
463 int nMaxEvents = 1; /* max number of events for
464 all rows. */
465 Blob userFilter = empty_blob; /* Optional user=johndoe query string */
466 static const char *const daysOfWeek[] = {
467 "Sunday", "Monday", "Tuesday", "Wednesday",
468 "Thursday", "Friday", "Saturday"
469 };
470
471 stats_report_init_view();
472 if( zUserName ){
473 blob_appendf(&userFilter, "user=%s", zUserName);
474 }
475 db_prepare(&query,
476 "SELECT cast(strftime('%%w', mtime) AS INTEGER) dow,"
477 " COUNT(*) AS eventCount"
478 " FROM v_reports"
479 " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
480 " GROUP BY dow ORDER BY dow", zUserName);
481 @ <h1>Timeline Events (%h(stats_report_label_for_type())) by Day of the Week
@@ -484,21 +484,22 @@
484 }
485 @ </h1>
486 db_multi_exec(
487 "CREATE TEMP TABLE piechart(amt,label);"
488 "INSERT INTO piechart"
489 " SELECT count(*), cast(strftime('%%w', mtime) AS INT) FROM v_reports"
490 " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
491 " GROUP BY 2 ORDER BY 2;"
492 "UPDATE piechart SET label = CASE label"
493 " WHEN 0 THEN 'Sunday'"
494 " WHEN 1 THEN 'Monday'"
495 " WHEN 2 THEN 'Tuesday'"
496 " WHEN 3 THEN 'Wednesday'"
497 " WHEN 4 THEN 'Thursday'"
498 " WHEN 5 THEN 'Friday'"
499 " WHEN 6 THEN 'Saturday'"
500 " ELSE 'ERROR' END;", zUserName
501 );
502 if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
503 @ <center><svg width=700 height=400>
504 piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
505 @ </svg></centre><hr/>
506
+31 -12
--- src/th_lang.c
+++ src/th_lang.c
@@ -722,27 +722,46 @@
722722
** string is CLASS STRING
723723
*/
724724
static int string_is_command(
725725
Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
726726
){
727
- int i;
728
- int iRes = 1;
729727
if( argc!=4 ){
730728
return Th_WrongNumArgs(interp, "string is class string");
731729
}
732
- if( argl[2]!=5 || 0!=memcmp(argv[2], "alnum", 5) ){
733
- Th_ErrorMessage(interp, "Expected alnum, got: ", argv[2], argl[2]);
730
+ if( argl[2]==5 && 0==memcmp(argv[2], "alnum", 5) ){
731
+ int i;
732
+ int iRes = 1;
733
+
734
+ for(i=0; i<argl[3]; i++){
735
+ if( !th_isalnum(argv[3][i]) ){
736
+ iRes = 0;
737
+ }
738
+ }
739
+
740
+ return Th_SetResultInt(interp, iRes);
741
+ }else if( argl[2]==6 && 0==memcmp(argv[2], "double", 6) ){
742
+ double fVal;
743
+ if( Th_ToDouble(interp, argv[3], argl[3], &fVal)==TH_OK ){
744
+ return Th_SetResultInt(interp, 1);
745
+ }
746
+ return Th_SetResultInt(interp, 0);
747
+ }else if( argl[2]==7 && 0==memcmp(argv[2], "integer", 7) ){
748
+ int iVal;
749
+ if( Th_ToInt(interp, argv[3], argl[3], &iVal)==TH_OK ){
750
+ return Th_SetResultInt(interp, 1);
751
+ }
752
+ return Th_SetResultInt(interp, 0);
753
+ }else if( argl[2]==4 && 0==memcmp(argv[2], "list", 4) ){
754
+ if( Th_SplitList(interp, argv[3], argl[3], 0, 0, 0)==TH_OK ){
755
+ return Th_SetResultInt(interp, 1);
756
+ }
757
+ return Th_SetResultInt(interp, 0);
758
+ }else{
759
+ Th_ErrorMessage(interp,
760
+ "Expected alnum, double, integer, or list, got:", argv[2], argl[2]);
734761
return TH_ERROR;
735762
}
736
-
737
- for(i=0; i<argl[3]; i++){
738
- if( !th_isalnum(argv[3][i]) ){
739
- iRes = 0;
740
- }
741
- }
742
-
743
- return Th_SetResultInt(interp, iRes);
744763
}
745764
746765
/*
747766
** TH Syntax:
748767
**
749768
--- src/th_lang.c
+++ src/th_lang.c
@@ -722,27 +722,46 @@
722 ** string is CLASS STRING
723 */
724 static int string_is_command(
725 Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
726 ){
727 int i;
728 int iRes = 1;
729 if( argc!=4 ){
730 return Th_WrongNumArgs(interp, "string is class string");
731 }
732 if( argl[2]!=5 || 0!=memcmp(argv[2], "alnum", 5) ){
733 Th_ErrorMessage(interp, "Expected alnum, got: ", argv[2], argl[2]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734 return TH_ERROR;
735 }
736
737 for(i=0; i<argl[3]; i++){
738 if( !th_isalnum(argv[3][i]) ){
739 iRes = 0;
740 }
741 }
742
743 return Th_SetResultInt(interp, iRes);
744 }
745
746 /*
747 ** TH Syntax:
748 **
749
--- src/th_lang.c
+++ src/th_lang.c
@@ -722,27 +722,46 @@
722 ** string is CLASS STRING
723 */
724 static int string_is_command(
725 Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
726 ){
 
 
727 if( argc!=4 ){
728 return Th_WrongNumArgs(interp, "string is class string");
729 }
730 if( argl[2]==5 && 0==memcmp(argv[2], "alnum", 5) ){
731 int i;
732 int iRes = 1;
733
734 for(i=0; i<argl[3]; i++){
735 if( !th_isalnum(argv[3][i]) ){
736 iRes = 0;
737 }
738 }
739
740 return Th_SetResultInt(interp, iRes);
741 }else if( argl[2]==6 && 0==memcmp(argv[2], "double", 6) ){
742 double fVal;
743 if( Th_ToDouble(interp, argv[3], argl[3], &fVal)==TH_OK ){
744 return Th_SetResultInt(interp, 1);
745 }
746 return Th_SetResultInt(interp, 0);
747 }else if( argl[2]==7 && 0==memcmp(argv[2], "integer", 7) ){
748 int iVal;
749 if( Th_ToInt(interp, argv[3], argl[3], &iVal)==TH_OK ){
750 return Th_SetResultInt(interp, 1);
751 }
752 return Th_SetResultInt(interp, 0);
753 }else if( argl[2]==4 && 0==memcmp(argv[2], "list", 4) ){
754 if( Th_SplitList(interp, argv[3], argl[3], 0, 0, 0)==TH_OK ){
755 return Th_SetResultInt(interp, 1);
756 }
757 return Th_SetResultInt(interp, 0);
758 }else{
759 Th_ErrorMessage(interp,
760 "Expected alnum, double, integer, or list, got:", argv[2], argl[2]);
761 return TH_ERROR;
762 }
 
 
 
 
 
 
 
 
763 }
764
765 /*
766 ** TH Syntax:
767 **
768
--- src/th_main.c
+++ src/th_main.c
@@ -337,10 +337,40 @@
337337
return Th_WrongNumArgs(interp, "puts STRING");
338338
}
339339
sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
340340
return TH_OK;
341341
}
342
+
343
+/*
344
+** TH1 command: markdown STRING
345
+**
346
+** Renders the input string as markdown. The result is a two-element list.
347
+** The first element is the text-only title string. The second element
348
+** contains the body, rendered as HTML.
349
+*/
350
+static int markdownCmd(
351
+ Th_Interp *interp,
352
+ void *p,
353
+ int argc,
354
+ const char **argv,
355
+ int *argl
356
+){
357
+ Blob src, title, body;
358
+ char *zValue = 0;
359
+ int nValue = 0;
360
+ if( argc!=2 ){
361
+ return Th_WrongNumArgs(interp, "markdown STRING");
362
+ }
363
+ blob_zero(&src);
364
+ blob_init(&src, (char*)argv[1], argl[1]);
365
+ blob_zero(&title); blob_zero(&body);
366
+ markdown_to_html(&src, &title, &body);
367
+ Th_ListAppend(interp, &zValue, &nValue, blob_str(&title), blob_size(&title));
368
+ Th_ListAppend(interp, &zValue, &nValue, blob_str(&body), blob_size(&body));
369
+ Th_SetResult(interp, zValue, nValue);
370
+ return TH_OK;
371
+}
342372
343373
/*
344374
** TH1 command: decorate STRING
345375
** TH1 command: wiki STRING
346376
**
@@ -1613,10 +1643,11 @@
16131643
{"hasfeature", hasfeatureCmd, 0},
16141644
{"html", putsCmd, (void*)&aFlags[0]},
16151645
{"htmlize", htmlizeCmd, 0},
16161646
{"http", httpCmd, 0},
16171647
{"linecount", linecntCmd, 0},
1648
+ {"markdown", markdownCmd, 0},
16181649
{"puts", putsCmd, (void*)&aFlags[1]},
16191650
{"query", queryCmd, 0},
16201651
{"randhex", randhexCmd, 0},
16211652
{"regexp", regexpCmd, 0},
16221653
{"reinitialize", reinitializeCmd, 0},
16231654
--- src/th_main.c
+++ src/th_main.c
@@ -337,10 +337,40 @@
337 return Th_WrongNumArgs(interp, "puts STRING");
338 }
339 sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
340 return TH_OK;
341 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
343 /*
344 ** TH1 command: decorate STRING
345 ** TH1 command: wiki STRING
346 **
@@ -1613,10 +1643,11 @@
1613 {"hasfeature", hasfeatureCmd, 0},
1614 {"html", putsCmd, (void*)&aFlags[0]},
1615 {"htmlize", htmlizeCmd, 0},
1616 {"http", httpCmd, 0},
1617 {"linecount", linecntCmd, 0},
 
1618 {"puts", putsCmd, (void*)&aFlags[1]},
1619 {"query", queryCmd, 0},
1620 {"randhex", randhexCmd, 0},
1621 {"regexp", regexpCmd, 0},
1622 {"reinitialize", reinitializeCmd, 0},
1623
--- src/th_main.c
+++ src/th_main.c
@@ -337,10 +337,40 @@
337 return Th_WrongNumArgs(interp, "puts STRING");
338 }
339 sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
340 return TH_OK;
341 }
342
343 /*
344 ** TH1 command: markdown STRING
345 **
346 ** Renders the input string as markdown. The result is a two-element list.
347 ** The first element is the text-only title string. The second element
348 ** contains the body, rendered as HTML.
349 */
350 static int markdownCmd(
351 Th_Interp *interp,
352 void *p,
353 int argc,
354 const char **argv,
355 int *argl
356 ){
357 Blob src, title, body;
358 char *zValue = 0;
359 int nValue = 0;
360 if( argc!=2 ){
361 return Th_WrongNumArgs(interp, "markdown STRING");
362 }
363 blob_zero(&src);
364 blob_init(&src, (char*)argv[1], argl[1]);
365 blob_zero(&title); blob_zero(&body);
366 markdown_to_html(&src, &title, &body);
367 Th_ListAppend(interp, &zValue, &nValue, blob_str(&title), blob_size(&title));
368 Th_ListAppend(interp, &zValue, &nValue, blob_str(&body), blob_size(&body));
369 Th_SetResult(interp, zValue, nValue);
370 return TH_OK;
371 }
372
373 /*
374 ** TH1 command: decorate STRING
375 ** TH1 command: wiki STRING
376 **
@@ -1613,10 +1643,11 @@
1643 {"hasfeature", hasfeatureCmd, 0},
1644 {"html", putsCmd, (void*)&aFlags[0]},
1645 {"htmlize", htmlizeCmd, 0},
1646 {"http", httpCmd, 0},
1647 {"linecount", linecntCmd, 0},
1648 {"markdown", markdownCmd, 0},
1649 {"puts", putsCmd, (void*)&aFlags[1]},
1650 {"query", queryCmd, 0},
1651 {"randhex", randhexCmd, 0},
1652 {"regexp", regexpCmd, 0},
1653 {"reinitialize", reinitializeCmd, 0},
1654
+13 -4
--- src/undo.c
+++ src/undo.c
@@ -24,12 +24,13 @@
2424
/*
2525
** Possible return values from the undo_maybe_save() routine.
2626
*/
2727
#define UNDO_NONE (0) /* Placeholder only used to initialize vars. */
2828
#define UNDO_SAVED_OK (1) /* The specified file was saved succesfully. */
29
-#define UNDO_INACTIVE (2) /* File not saved, subsystem is not active. */
30
-#define UNDO_TOOBIG (3) /* File not saved, it exceeded a size limit. */
29
+#define UNDO_DISABLED (2) /* File not saved, subsystem is disabled. */
30
+#define UNDO_INACTIVE (3) /* File not saved, subsystem is not active. */
31
+#define UNDO_TOOBIG (4) /* File not saved, it exceeded a size limit. */
3132
#endif
3233
3334
/*
3435
** Undo the change to the file zPathname. zPathname is the pathname
3536
** of the file relative to the root of the repository. If redoFlag is
@@ -74,13 +75,13 @@
7475
if( old_exists ){
7576
db_ephemeral_blob(&q, 0, &new);
7677
}
7778
if( old_exists ){
7879
if( new_exists ){
79
- fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
80
+ fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
8081
}else{
81
- fossil_print("NEW %s\n", zPathname);
82
+ fossil_print("NEW %s\n", zPathname);
8283
}
8384
if( new_exists && (new_link || old_link) ){
8485
file_delete(zFullname);
8586
}
8687
if( old_link ){
@@ -269,10 +270,11 @@
269270
** Save the current content of the file zPathname so that it
270271
** will be undoable. The name is relative to the root of the
271272
** tree.
272273
*/
273274
void undo_save(const char *zPathname){
275
+ if( undoDisable ) return;
274276
if( undo_maybe_save(zPathname, -1)!=UNDO_SAVED_OK ){
275277
fossil_panic("failed to save undo information for path: %s",
276278
zPathname);
277279
}
278280
}
@@ -291,10 +293,15 @@
291293
**
292294
** The return value of this function will always be one of the
293295
** following codes:
294296
**
295297
** UNDO_SAVED_OK: The specified file was saved succesfully.
298
+**
299
+** UNDO_DISABLED: The specified file was NOT saved, because the
300
+** "undo subsystem" is disabled. This error may
301
+** indicate that a call to undo_disable() was
302
+** issued.
296303
**
297304
** UNDO_INACTIVE: The specified file was NOT saved, because the
298305
** "undo subsystem" is not active. This error
299306
** may indicate that a call to undo_begin() is
300307
** missing.
@@ -308,10 +315,11 @@
308315
int undo_maybe_save(const char *zPathname, i64 limit){
309316
char *zFullname;
310317
i64 size;
311318
int result;
312319
320
+ if( undoDisable ) return UNDO_DISABLED;
313321
if( !undoActive ) return UNDO_INACTIVE;
314322
zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
315323
size = file_wd_size(zFullname);
316324
if( limit<0 || size<=limit ){
317325
int existsFlag = (size>=0);
@@ -355,10 +363,11 @@
355363
static char zRc[32];
356364
357365
switch( rc ){
358366
case UNDO_NONE: return "undo is disabled for this operation";
359367
case UNDO_SAVED_OK: return "the save operation was successful";
368
+ case UNDO_DISABLED: return "the undo subsystem is disabled";
360369
case UNDO_INACTIVE: return "the undo subsystem is inactive";
361370
case UNDO_TOOBIG: return "the file is too big";
362371
default: {
363372
sqlite3_snprintf(sizeof(zRc), zRc, "of error code %d", rc);
364373
}
365374
--- src/undo.c
+++ src/undo.c
@@ -24,12 +24,13 @@
24 /*
25 ** Possible return values from the undo_maybe_save() routine.
26 */
27 #define UNDO_NONE (0) /* Placeholder only used to initialize vars. */
28 #define UNDO_SAVED_OK (1) /* The specified file was saved succesfully. */
29 #define UNDO_INACTIVE (2) /* File not saved, subsystem is not active. */
30 #define UNDO_TOOBIG (3) /* File not saved, it exceeded a size limit. */
 
31 #endif
32
33 /*
34 ** Undo the change to the file zPathname. zPathname is the pathname
35 ** of the file relative to the root of the repository. If redoFlag is
@@ -74,13 +75,13 @@
74 if( old_exists ){
75 db_ephemeral_blob(&q, 0, &new);
76 }
77 if( old_exists ){
78 if( new_exists ){
79 fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
80 }else{
81 fossil_print("NEW %s\n", zPathname);
82 }
83 if( new_exists && (new_link || old_link) ){
84 file_delete(zFullname);
85 }
86 if( old_link ){
@@ -269,10 +270,11 @@
269 ** Save the current content of the file zPathname so that it
270 ** will be undoable. The name is relative to the root of the
271 ** tree.
272 */
273 void undo_save(const char *zPathname){
 
274 if( undo_maybe_save(zPathname, -1)!=UNDO_SAVED_OK ){
275 fossil_panic("failed to save undo information for path: %s",
276 zPathname);
277 }
278 }
@@ -291,10 +293,15 @@
291 **
292 ** The return value of this function will always be one of the
293 ** following codes:
294 **
295 ** UNDO_SAVED_OK: The specified file was saved succesfully.
 
 
 
 
 
296 **
297 ** UNDO_INACTIVE: The specified file was NOT saved, because the
298 ** "undo subsystem" is not active. This error
299 ** may indicate that a call to undo_begin() is
300 ** missing.
@@ -308,10 +315,11 @@
308 int undo_maybe_save(const char *zPathname, i64 limit){
309 char *zFullname;
310 i64 size;
311 int result;
312
 
313 if( !undoActive ) return UNDO_INACTIVE;
314 zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
315 size = file_wd_size(zFullname);
316 if( limit<0 || size<=limit ){
317 int existsFlag = (size>=0);
@@ -355,10 +363,11 @@
355 static char zRc[32];
356
357 switch( rc ){
358 case UNDO_NONE: return "undo is disabled for this operation";
359 case UNDO_SAVED_OK: return "the save operation was successful";
 
360 case UNDO_INACTIVE: return "the undo subsystem is inactive";
361 case UNDO_TOOBIG: return "the file is too big";
362 default: {
363 sqlite3_snprintf(sizeof(zRc), zRc, "of error code %d", rc);
364 }
365
--- src/undo.c
+++ src/undo.c
@@ -24,12 +24,13 @@
24 /*
25 ** Possible return values from the undo_maybe_save() routine.
26 */
27 #define UNDO_NONE (0) /* Placeholder only used to initialize vars. */
28 #define UNDO_SAVED_OK (1) /* The specified file was saved succesfully. */
29 #define UNDO_DISABLED (2) /* File not saved, subsystem is disabled. */
30 #define UNDO_INACTIVE (3) /* File not saved, subsystem is not active. */
31 #define UNDO_TOOBIG (4) /* File not saved, it exceeded a size limit. */
32 #endif
33
34 /*
35 ** Undo the change to the file zPathname. zPathname is the pathname
36 ** of the file relative to the root of the repository. If redoFlag is
@@ -74,13 +75,13 @@
75 if( old_exists ){
76 db_ephemeral_blob(&q, 0, &new);
77 }
78 if( old_exists ){
79 if( new_exists ){
80 fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
81 }else{
82 fossil_print("NEW %s\n", zPathname);
83 }
84 if( new_exists && (new_link || old_link) ){
85 file_delete(zFullname);
86 }
87 if( old_link ){
@@ -269,10 +270,11 @@
270 ** Save the current content of the file zPathname so that it
271 ** will be undoable. The name is relative to the root of the
272 ** tree.
273 */
274 void undo_save(const char *zPathname){
275 if( undoDisable ) return;
276 if( undo_maybe_save(zPathname, -1)!=UNDO_SAVED_OK ){
277 fossil_panic("failed to save undo information for path: %s",
278 zPathname);
279 }
280 }
@@ -291,10 +293,15 @@
293 **
294 ** The return value of this function will always be one of the
295 ** following codes:
296 **
297 ** UNDO_SAVED_OK: The specified file was saved succesfully.
298 **
299 ** UNDO_DISABLED: The specified file was NOT saved, because the
300 ** "undo subsystem" is disabled. This error may
301 ** indicate that a call to undo_disable() was
302 ** issued.
303 **
304 ** UNDO_INACTIVE: The specified file was NOT saved, because the
305 ** "undo subsystem" is not active. This error
306 ** may indicate that a call to undo_begin() is
307 ** missing.
@@ -308,10 +315,11 @@
315 int undo_maybe_save(const char *zPathname, i64 limit){
316 char *zFullname;
317 i64 size;
318 int result;
319
320 if( undoDisable ) return UNDO_DISABLED;
321 if( !undoActive ) return UNDO_INACTIVE;
322 zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
323 size = file_wd_size(zFullname);
324 if( limit<0 || size<=limit ){
325 int existsFlag = (size>=0);
@@ -355,10 +363,11 @@
363 static char zRc[32];
364
365 switch( rc ){
366 case UNDO_NONE: return "undo is disabled for this operation";
367 case UNDO_SAVED_OK: return "the save operation was successful";
368 case UNDO_DISABLED: return "the undo subsystem is disabled";
369 case UNDO_INACTIVE: return "the undo subsystem is inactive";
370 case UNDO_TOOBIG: return "the file is too big";
371 default: {
372 sqlite3_snprintf(sizeof(zRc), zRc, "of error code %d", rc);
373 }
374
+9 -8
--- src/update.c
+++ src/update.c
@@ -424,26 +424,26 @@
424424
fossil_print("ADD %s - overwrites an unmanaged file\n", zName);
425425
nOverwrite++;
426426
}else{
427427
fossil_print("ADD %s\n", zName);
428428
}
429
- undo_save(zName);
429
+ if( !dryRunFlag && !internalUpdate ) undo_save(zName);
430430
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
431431
}else if( idt>0 && idv>0 && ridt!=ridv && (chnged==0 || deleted) ){
432432
/* The file is unedited. Change it to the target version */
433
- undo_save(zName);
434433
if( deleted ){
435434
fossil_print("UPDATE %s - change to unmanaged file\n", zName);
436435
}else{
437436
fossil_print("UPDATE %s\n", zName);
438437
}
438
+ if( !dryRunFlag && !internalUpdate ) undo_save(zName);
439439
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
440440
}else if( idt>0 && idv>0 && !deleted && file_wd_size(zFullPath)<0 ){
441441
/* The file missing from the local check-out. Restore it to the
442442
** version that appears in the target. */
443443
fossil_print("UPDATE %s\n", zName);
444
- undo_save(zName);
444
+ if( !dryRunFlag && !internalUpdate ) undo_save(zName);
445445
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
446446
}else if( idt==0 && idv>0 ){
447447
if( ridv==0 ){
448448
/* Added in current checkout. Continue to hold the file as
449449
** as an addition */
@@ -454,11 +454,11 @@
454454
fossil_print("CONFLICT %s - edited locally but deleted by update\n",
455455
zName);
456456
nConflict++;
457457
}else{
458458
fossil_print("REMOVE %s\n", zName);
459
- undo_save(zName);
459
+ if( !dryRunFlag && !internalUpdate ) undo_save(zName);
460460
if( !dryRunFlag ) file_delete(zFullPath);
461461
}
462462
}else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
463463
/* Merge the changes in the current tree into the target version */
464464
Blob r, t, v;
@@ -471,11 +471,11 @@
471471
if( islinkv || islinkt /* || file_wd_islink(zFullPath) */ ){
472472
fossil_print("***** Cannot merge symlink %s\n", zNewName);
473473
nConflict++;
474474
}else{
475475
unsigned mergeFlags = dryRunFlag ? MERGE_DRYRUN : 0;
476
- undo_save(zName);
476
+ if( !dryRunFlag && !internalUpdate ) undo_save(zName);
477477
content_get(ridt, &t);
478478
content_get(ridv, &v);
479479
rc = merge_3way(&v, zFullPath, &t, &r, mergeFlags);
480480
if( rc>=0 ){
481481
if( !dryRunFlag ){
@@ -738,10 +738,11 @@
738738
739739
if( g.argc>2 ){
740740
for(i=2; i<g.argc; i++){
741741
Blob fname;
742742
zFile = mprintf("%/", g.argv[i]);
743
+ blob_zero(&fname);
743744
file_tree_name(zFile, &fname, 0, 1);
744745
db_multi_exec(
745746
"REPLACE INTO torevert VALUES(%B);"
746747
"INSERT OR IGNORE INTO torevert"
747748
" SELECT pathname"
@@ -784,15 +785,15 @@
784785
errCode = historical_version_of_file(zRevision, zFile, &record,
785786
&isLink, &isExe, 0, 2);
786787
if( errCode==2 ){
787788
if( db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q OR origname=%Q",
788789
zFile, zFile)==0 ){
789
- fossil_print("UNMANAGE: %s\n", zFile);
790
+ fossil_print("UNMANAGE %s\n", zFile);
790791
}else{
791792
undo_save(zFile);
792793
file_delete(zFull);
793
- fossil_print("DELETE: %s\n", zFile);
794
+ fossil_print("DELETE %s\n", zFile);
794795
}
795796
db_multi_exec(
796797
"UPDATE OR REPLACE vfile"
797798
" SET pathname=origname, origname=NULL"
798799
" WHERE pathname=%Q AND origname!=pathname;"
@@ -809,11 +810,11 @@
809810
symlink_create(blob_str(&record), zFull);
810811
}else{
811812
blob_write_to_file(&record, zFull);
812813
}
813814
file_wd_setexe(zFull, isExe);
814
- fossil_print("REVERTED: %s\n", zFile);
815
+ fossil_print("REVERT %s\n", zFile);
815816
mtime = file_wd_mtime(zFull);
816817
db_multi_exec(
817818
"UPDATE vfile"
818819
" SET mtime=%lld, chnged=0, deleted=0, isexe=%d, islink=%d,mrid=rid"
819820
" WHERE pathname=%Q OR origname=%Q",
820821
821822
ADDED test/amend.test
--- src/update.c
+++ src/update.c
@@ -424,26 +424,26 @@
424 fossil_print("ADD %s - overwrites an unmanaged file\n", zName);
425 nOverwrite++;
426 }else{
427 fossil_print("ADD %s\n", zName);
428 }
429 undo_save(zName);
430 if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
431 }else if( idt>0 && idv>0 && ridt!=ridv && (chnged==0 || deleted) ){
432 /* The file is unedited. Change it to the target version */
433 undo_save(zName);
434 if( deleted ){
435 fossil_print("UPDATE %s - change to unmanaged file\n", zName);
436 }else{
437 fossil_print("UPDATE %s\n", zName);
438 }
 
439 if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
440 }else if( idt>0 && idv>0 && !deleted && file_wd_size(zFullPath)<0 ){
441 /* The file missing from the local check-out. Restore it to the
442 ** version that appears in the target. */
443 fossil_print("UPDATE %s\n", zName);
444 undo_save(zName);
445 if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
446 }else if( idt==0 && idv>0 ){
447 if( ridv==0 ){
448 /* Added in current checkout. Continue to hold the file as
449 ** as an addition */
@@ -454,11 +454,11 @@
454 fossil_print("CONFLICT %s - edited locally but deleted by update\n",
455 zName);
456 nConflict++;
457 }else{
458 fossil_print("REMOVE %s\n", zName);
459 undo_save(zName);
460 if( !dryRunFlag ) file_delete(zFullPath);
461 }
462 }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
463 /* Merge the changes in the current tree into the target version */
464 Blob r, t, v;
@@ -471,11 +471,11 @@
471 if( islinkv || islinkt /* || file_wd_islink(zFullPath) */ ){
472 fossil_print("***** Cannot merge symlink %s\n", zNewName);
473 nConflict++;
474 }else{
475 unsigned mergeFlags = dryRunFlag ? MERGE_DRYRUN : 0;
476 undo_save(zName);
477 content_get(ridt, &t);
478 content_get(ridv, &v);
479 rc = merge_3way(&v, zFullPath, &t, &r, mergeFlags);
480 if( rc>=0 ){
481 if( !dryRunFlag ){
@@ -738,10 +738,11 @@
738
739 if( g.argc>2 ){
740 for(i=2; i<g.argc; i++){
741 Blob fname;
742 zFile = mprintf("%/", g.argv[i]);
 
743 file_tree_name(zFile, &fname, 0, 1);
744 db_multi_exec(
745 "REPLACE INTO torevert VALUES(%B);"
746 "INSERT OR IGNORE INTO torevert"
747 " SELECT pathname"
@@ -784,15 +785,15 @@
784 errCode = historical_version_of_file(zRevision, zFile, &record,
785 &isLink, &isExe, 0, 2);
786 if( errCode==2 ){
787 if( db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q OR origname=%Q",
788 zFile, zFile)==0 ){
789 fossil_print("UNMANAGE: %s\n", zFile);
790 }else{
791 undo_save(zFile);
792 file_delete(zFull);
793 fossil_print("DELETE: %s\n", zFile);
794 }
795 db_multi_exec(
796 "UPDATE OR REPLACE vfile"
797 " SET pathname=origname, origname=NULL"
798 " WHERE pathname=%Q AND origname!=pathname;"
@@ -809,11 +810,11 @@
809 symlink_create(blob_str(&record), zFull);
810 }else{
811 blob_write_to_file(&record, zFull);
812 }
813 file_wd_setexe(zFull, isExe);
814 fossil_print("REVERTED: %s\n", zFile);
815 mtime = file_wd_mtime(zFull);
816 db_multi_exec(
817 "UPDATE vfile"
818 " SET mtime=%lld, chnged=0, deleted=0, isexe=%d, islink=%d,mrid=rid"
819 " WHERE pathname=%Q OR origname=%Q",
820
821 DDED test/amend.test
--- src/update.c
+++ src/update.c
@@ -424,26 +424,26 @@
424 fossil_print("ADD %s - overwrites an unmanaged file\n", zName);
425 nOverwrite++;
426 }else{
427 fossil_print("ADD %s\n", zName);
428 }
429 if( !dryRunFlag && !internalUpdate ) undo_save(zName);
430 if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
431 }else if( idt>0 && idv>0 && ridt!=ridv && (chnged==0 || deleted) ){
432 /* The file is unedited. Change it to the target version */
 
433 if( deleted ){
434 fossil_print("UPDATE %s - change to unmanaged file\n", zName);
435 }else{
436 fossil_print("UPDATE %s\n", zName);
437 }
438 if( !dryRunFlag && !internalUpdate ) undo_save(zName);
439 if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
440 }else if( idt>0 && idv>0 && !deleted && file_wd_size(zFullPath)<0 ){
441 /* The file missing from the local check-out. Restore it to the
442 ** version that appears in the target. */
443 fossil_print("UPDATE %s\n", zName);
444 if( !dryRunFlag && !internalUpdate ) undo_save(zName);
445 if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
446 }else if( idt==0 && idv>0 ){
447 if( ridv==0 ){
448 /* Added in current checkout. Continue to hold the file as
449 ** as an addition */
@@ -454,11 +454,11 @@
454 fossil_print("CONFLICT %s - edited locally but deleted by update\n",
455 zName);
456 nConflict++;
457 }else{
458 fossil_print("REMOVE %s\n", zName);
459 if( !dryRunFlag && !internalUpdate ) undo_save(zName);
460 if( !dryRunFlag ) file_delete(zFullPath);
461 }
462 }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
463 /* Merge the changes in the current tree into the target version */
464 Blob r, t, v;
@@ -471,11 +471,11 @@
471 if( islinkv || islinkt /* || file_wd_islink(zFullPath) */ ){
472 fossil_print("***** Cannot merge symlink %s\n", zNewName);
473 nConflict++;
474 }else{
475 unsigned mergeFlags = dryRunFlag ? MERGE_DRYRUN : 0;
476 if( !dryRunFlag && !internalUpdate ) undo_save(zName);
477 content_get(ridt, &t);
478 content_get(ridv, &v);
479 rc = merge_3way(&v, zFullPath, &t, &r, mergeFlags);
480 if( rc>=0 ){
481 if( !dryRunFlag ){
@@ -738,10 +738,11 @@
738
739 if( g.argc>2 ){
740 for(i=2; i<g.argc; i++){
741 Blob fname;
742 zFile = mprintf("%/", g.argv[i]);
743 blob_zero(&fname);
744 file_tree_name(zFile, &fname, 0, 1);
745 db_multi_exec(
746 "REPLACE INTO torevert VALUES(%B);"
747 "INSERT OR IGNORE INTO torevert"
748 " SELECT pathname"
@@ -784,15 +785,15 @@
785 errCode = historical_version_of_file(zRevision, zFile, &record,
786 &isLink, &isExe, 0, 2);
787 if( errCode==2 ){
788 if( db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q OR origname=%Q",
789 zFile, zFile)==0 ){
790 fossil_print("UNMANAGE %s\n", zFile);
791 }else{
792 undo_save(zFile);
793 file_delete(zFull);
794 fossil_print("DELETE %s\n", zFile);
795 }
796 db_multi_exec(
797 "UPDATE OR REPLACE vfile"
798 " SET pathname=origname, origname=NULL"
799 " WHERE pathname=%Q AND origname!=pathname;"
@@ -809,11 +810,11 @@
810 symlink_create(blob_str(&record), zFull);
811 }else{
812 blob_write_to_file(&record, zFull);
813 }
814 file_wd_setexe(zFull, isExe);
815 fossil_print("REVERT %s\n", zFile);
816 mtime = file_wd_mtime(zFull);
817 db_multi_exec(
818 "UPDATE vfile"
819 " SET mtime=%lld, chnged=0, deleted=0, isexe=%d, islink=%d,mrid=rid"
820 " WHERE pathname=%Q OR origname=%Q",
821
822 DDED test/amend.test
--- a/test/amend.test
+++ b/test/amend.test
@@ -0,0 +1,44 @@
1
+software; you caed
2
+
3
+ returnreturnRichard Hipp
4
+#
5
+# This program is free software; you can redistribute it and/or
6
+# modify it under the terms of the Simplified BSD License (also
7
+# known as the "2-Clause Lishort_uuid {uuid {len 10}} {
8
+ string range $uuid 0 $len-1
9
+}
10
+
11
+proc d Hipp
12
+#
13
+# This program#
14
+# Copyright (c) 2015 D. Richard Hipp
15
+#
16
+# This program is free software; you can redistribute it and/or
17
+# modify it under the terms of the Simplified BSD License (also
18
+# known as the "2-Clause Li#
19
+# Copyright (c) 2015 D. Richard Hipp
20
+#
21
+# This program is free software; you caed
22
+
23
+ return#
24
+# Copyright (c) 2015 D. Richard Hipp
25
+#
26
+# This program is free software; you can redistribute it and/or
27
+# modify it under the terms of the Simplified BSD License (also
28
+# repo_init string range $uuid 0 $len-1
29
+}
30
+
31
+proc d Hipp
32
+#
33
+# This program#
34
+# Copyright (c) 2015 D. Richard Hipp
35
+#
36
+# This program is free software; you can redistribute it and/or
37
+# modify it under the terms of the Simplified BSD License (also
38
+# known as the "2-Clause Li#
39
+# Copyright (c) 2015 D. Richard Hipp
40
+#
41
+# This program is free software; you caed
42
+
43
+ return
44
+ 2.$sc leafset env(EDITOR)unset env(EDITOR)
--- a/test/amend.test
+++ b/test/amend.test
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/amend.test
+++ b/test/amend.test
@@ -0,0 +1,44 @@
1 software; you caed
2
3 returnreturnRichard Hipp
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the Simplified BSD License (also
7 # known as the "2-Clause Lishort_uuid {uuid {len 10}} {
8 string range $uuid 0 $len-1
9 }
10
11 proc d Hipp
12 #
13 # This program#
14 # Copyright (c) 2015 D. Richard Hipp
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the Simplified BSD License (also
18 # known as the "2-Clause Li#
19 # Copyright (c) 2015 D. Richard Hipp
20 #
21 # This program is free software; you caed
22
23 return#
24 # Copyright (c) 2015 D. Richard Hipp
25 #
26 # This program is free software; you can redistribute it and/or
27 # modify it under the terms of the Simplified BSD License (also
28 # repo_init string range $uuid 0 $len-1
29 }
30
31 proc d Hipp
32 #
33 # This program#
34 # Copyright (c) 2015 D. Richard Hipp
35 #
36 # This program is free software; you can redistribute it and/or
37 # modify it under the terms of the Simplified BSD License (also
38 # known as the "2-Clause Li#
39 # Copyright (c) 2015 D. Richard Hipp
40 #
41 # This program is free software; you caed
42
43 return
44 2.$sc leafset env(EDITOR)unset env(EDITOR)
--- test/merge5.test
+++ test/merge5.test
@@ -37,11 +37,10 @@
3737
test merge5-$testid 1
3838
}
3939
}
4040
4141
catch {exec $::fossilexe info} res
42
-puts res=$res
4342
if {![regexp {use --repository} $res]} {
4443
puts stderr "Cannot run this test within an open checkout"
4544
return
4645
}
4746
#
4847
--- test/merge5.test
+++ test/merge5.test
@@ -37,11 +37,10 @@
37 test merge5-$testid 1
38 }
39 }
40
41 catch {exec $::fossilexe info} res
42 puts res=$res
43 if {![regexp {use --repository} $res]} {
44 puts stderr "Cannot run this test within an open checkout"
45 return
46 }
47 #
48
--- test/merge5.test
+++ test/merge5.test
@@ -37,11 +37,10 @@
37 test merge5-$testid 1
38 }
39 }
40
41 catch {exec $::fossilexe info} res
 
42 if {![regexp {use --repository} $res]} {
43 puts stderr "Cannot run this test within an open checkout"
44 return
45 }
46 #
47
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -2,11 +2,10 @@
22
# Tests for merging with renames
33
#
44
#
55
66
catch {exec $::fossilexe info} res
7
-puts res=$res
87
if {![regexp {use --repository} $res]} {
98
puts stderr "Cannot run this test within an open checkout"
109
return
1110
}
1211
1312
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -2,11 +2,10 @@
2 # Tests for merging with renames
3 #
4 #
5
6 catch {exec $::fossilexe info} res
7 puts res=$res
8 if {![regexp {use --repository} $res]} {
9 puts stderr "Cannot run this test within an open checkout"
10 return
11 }
12
13
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -2,11 +2,10 @@
2 # Tests for merging with renames
3 #
4 #
5
6 catch {exec $::fossilexe info} res
 
7 if {![regexp {use --repository} $res]} {
8 puts stderr "Cannot run this test within an open checkout"
9 return
10 }
11
12
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -17,11 +17,10 @@
1717
#
1818
# MV / RM Commands
1919
#
2020
2121
catch {exec $::fossilexe info} res
22
-puts res=$res
2322
if {![regexp {use --repository} $res]} {
2423
puts stderr "Cannot run this test within an open checkout"
2524
return
2625
}
2726
2827
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -17,11 +17,10 @@
17 #
18 # MV / RM Commands
19 #
20
21 catch {exec $::fossilexe info} res
22 puts res=$res
23 if {![regexp {use --repository} $res]} {
24 puts stderr "Cannot run this test within an open checkout"
25 return
26 }
27
28
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -17,11 +17,10 @@
17 #
18 # MV / RM Commands
19 #
20
21 catch {exec $::fossilexe info} res
 
22 if {![regexp {use --repository} $res]} {
23 puts stderr "Cannot run this test within an open checkout"
24 return
25 }
26
27
--- test/revert.test
+++ test/revert.test
@@ -38,11 +38,10 @@
3838
3939
fossil undo
4040
}
4141
4242
catch {exec $::fossilexe info} res
43
-puts res=$res
4443
if {![regexp {use --repository} $res]} {
4544
puts stderr "Cannot run this test within an open checkout"
4645
return
4746
}
4847
4948
--- test/revert.test
+++ test/revert.test
@@ -38,11 +38,10 @@
38
39 fossil undo
40 }
41
42 catch {exec $::fossilexe info} res
43 puts res=$res
44 if {![regexp {use --repository} $res]} {
45 puts stderr "Cannot run this test within an open checkout"
46 return
47 }
48
49
--- test/revert.test
+++ test/revert.test
@@ -38,11 +38,10 @@
38
39 fossil undo
40 }
41
42 catch {exec $::fossilexe info} res
 
43 if {![regexp {use --repository} $res]} {
44 puts stderr "Cannot run this test within an open checkout"
45 return
46 }
47
48
+235 -2
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,14 @@
1616
############################################################################
1717
#
1818
# TH1 Commands
1919
#
2020
21
+set dir [file dirname [info script]]
22
+
23
+###############################################################################
24
+
2125
fossil test-th-eval --open-config "setting th1-hooks"
2226
set th1Hooks [expr {$RESULT eq "1"}]
2327
2428
###############################################################################
2529
@@ -859,12 +863,12 @@
859863
#
860864
fossil test-th-eval "info commands"
861865
test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
862866
enable_output uplevel http expr glob_match utime styleFooter catch if\
863867
tclReady searchable reinitialize combobox lindex query html anoncap randhex\
864
-llength for set break regexp styleHeader puts return checkout decorate\
865
-artifact trace wiki proc hascap globalState continue getParameter\
868
+llength for set break regexp markdown styleHeader puts return checkout\
869
+decorate artifact trace wiki proc hascap globalState continue getParameter\
866870
hasfeature setting lsearch breakpoint upvar render repository string unset\
867871
setParameter list error info rename anycap httpize}}
868872
869873
###############################################################################
870874
@@ -1012,5 +1016,234 @@
10121016
10131017
###############################################################################
10141018
10151019
fossil test-th-eval {list [glob_match {a[bd]c} abc] [glob_match abc {a[bd]c}]}
10161020
test th1-glob-match-13 {$RESULT eq "1 0"}
1021
+
1022
+###############################################################################
1023
+
1024
+fossil test-th-eval {string is}
1025
+test th1-string-is-1 {$RESULT eq \
1026
+{TH_ERROR: wrong # args: should be "string is class string"}}
1027
+
1028
+###############################################################################
1029
+
1030
+fossil test-th-eval {string is something}
1031
+test th1-string-is-2 {$RESULT eq \
1032
+{TH_ERROR: wrong # args: should be "string is class string"}}
1033
+
1034
+###############################################################################
1035
+
1036
+fossil test-th-eval {string is not something else}
1037
+test th1-string-is-3 {$RESULT eq \
1038
+{TH_ERROR: wrong # args: should be "string is class string"}}
1039
+
1040
+###############################################################################
1041
+
1042
+fossil test-th-eval {string is other 123}
1043
+test th1-string-is-4 {$RESULT eq \
1044
+"TH_ERROR: Expected alnum, double, integer, or list, got: other"}
1045
+
1046
+###############################################################################
1047
+
1048
+fossil test-th-eval {string is alnum 123}
1049
+test th1-string-is-5 {$RESULT eq "1"}
1050
+
1051
+###############################################################################
1052
+
1053
+fossil test-th-eval {string is alnum abc}
1054
+test th1-string-is-6 {$RESULT eq "1"}
1055
+
1056
+###############################################################################
1057
+
1058
+fossil test-th-eval {string is alnum 123abc}
1059
+test th1-string-is-7 {$RESULT eq "1"}
1060
+
1061
+###############################################################################
1062
+
1063
+fossil test-th-eval {string is alnum abc123}
1064
+test th1-string-is-8 {$RESULT eq "1"}
1065
+
1066
+###############################################################################
1067
+
1068
+fossil test-th-eval {string is alnum _abc123}
1069
+test th1-string-is-9 {$RESULT eq "0"}
1070
+
1071
+###############################################################################
1072
+
1073
+fossil test-th-eval {string is alnum abc.123}
1074
+test th1-string-is-10 {$RESULT eq "0"}
1075
+
1076
+###############################################################################
1077
+
1078
+fossil test-th-eval {string is alnum abc123_}
1079
+test th1-string-is-11 {$RESULT eq "0"}
1080
+
1081
+###############################################################################
1082
+
1083
+fossil test-th-eval {string is list ""}
1084
+test th1-string-is-12 {$RESULT eq "1"}
1085
+
1086
+###############################################################################
1087
+
1088
+fossil test-th-eval {string is list 1}
1089
+test th1-string-is-13 {$RESULT eq "1"}
1090
+
1091
+###############################################################################
1092
+
1093
+fossil test-th-eval {string is list "1 2 3"}
1094
+test th1-string-is-14 {$RESULT eq "1"}
1095
+
1096
+###############################################################################
1097
+
1098
+fossil test-th-eval {string is list "\{"}
1099
+test th1-string-is-15 {$RESULT eq "0"}
1100
+
1101
+###############################################################################
1102
+
1103
+fossil test-th-eval {string is list "1 2 3 \{"}
1104
+test th1-string-is-16 {$RESULT eq "0"}
1105
+
1106
+###############################################################################
1107
+
1108
+fossil test-th-eval {string is list "1 2 3 \{\}"}
1109
+test th1-string-is-17 {$RESULT eq "1"}
1110
+
1111
+###############################################################################
1112
+
1113
+fossil test-th-eval {string is list "1 2 3 \{\{\}"}
1114
+test th1-string-is-18 {$RESULT eq "0"}
1115
+
1116
+###############################################################################
1117
+
1118
+fossil test-th-eval {string is double 123}
1119
+test th1-string-is-19 {$RESULT eq "1"}
1120
+
1121
+###############################################################################
1122
+
1123
+fossil test-th-eval {string is double 123.456}
1124
+test th1-string-is-20 {$RESULT eq "1"}
1125
+
1126
+###############################################################################
1127
+
1128
+fossil test-th-eval {string is double 123abc}
1129
+test th1-string-is-21 {$RESULT eq "0"}
1130
+
1131
+###############################################################################
1132
+
1133
+fossil test-th-eval {string is double 123_456}
1134
+test th1-string-is-22 {$RESULT eq "0"}
1135
+
1136
+###############################################################################
1137
+
1138
+fossil test-th-eval {string is integer 123}
1139
+test th1-string-is-23 {$RESULT eq "1"}
1140
+
1141
+###############################################################################
1142
+
1143
+fossil test-th-eval {string is integer 123.456}
1144
+test th1-string-is-24 {$RESULT eq "0"}
1145
+
1146
+###############################################################################
1147
+
1148
+fossil test-th-eval {string is integer 123abc}
1149
+test th1-string-is-25 {$RESULT eq "0"}
1150
+
1151
+###############################################################################
1152
+
1153
+fossil test-th-eval {string is integer 0b11001001}
1154
+test th1-string-is-26 {$RESULT eq "1"}
1155
+
1156
+###############################################################################
1157
+
1158
+fossil test-th-eval {string is integer 0b11001002}
1159
+test th1-string-is-27 {$RESULT eq "0"}
1160
+
1161
+###############################################################################
1162
+
1163
+fossil test-th-eval {string is integer 0o777}
1164
+test th1-string-is-28 {$RESULT eq "1"}
1165
+
1166
+###############################################################################
1167
+
1168
+fossil test-th-eval {string is integer 0o778}
1169
+test th1-string-is-29 {$RESULT eq "0"}
1170
+
1171
+###############################################################################
1172
+
1173
+fossil test-th-eval {string is integer 0xC0DEF00D}
1174
+test th1-string-is-30 {$RESULT eq "1"}
1175
+
1176
+###############################################################################
1177
+
1178
+fossil test-th-eval {string is integer 0xC0DEF00Z}
1179
+test th1-string-is-31 {$RESULT eq "0"}
1180
+
1181
+###############################################################################
1182
+
1183
+fossil test-th-eval {markdown}
1184
+test th1-markdown-1 {$RESULT eq \
1185
+{TH_ERROR: wrong # args: should be "markdown STRING"}}
1186
+
1187
+###############################################################################
1188
+
1189
+fossil test-th-eval {markdown one two}
1190
+test th1-markdown-2 {$RESULT eq \
1191
+{TH_ERROR: wrong # args: should be "markdown STRING"}}
1192
+
1193
+###############################################################################
1194
+
1195
+fossil test-th-eval {markdown "*This is a test.*"}
1196
+test th1-markdown-3 {[normalize_result] eq {{} {<div class="markdown">
1197
+
1198
+<p><em>This is a test.</em></p>
1199
+
1200
+</div>
1201
+}}}
1202
+
1203
+###############################################################################
1204
+
1205
+fossil test-th-eval {markdown "Test1\n=====\n*This is a test.*"}
1206
+test th1-markdown-4 {[normalize_result] eq {Test1 {<div class="markdown">
1207
+
1208
+<h1>Test1</h1>
1209
+<p><em>This is a test.</em></p>
1210
+
1211
+</div>
1212
+}}}
1213
+
1214
+###############################################################################
1215
+
1216
+set markdown [read_file [file join $dir markdown-test1.md]]
1217
+fossil test-th-eval [string map \
1218
+ [list %markdown% $markdown] {markdown {%markdown%}}]
1219
+test th1-markdown-5 {[normalize_result] eq \
1220
+{{Markdown Formatter Test Document} {<div class="markdown">
1221
+
1222
+<h1>Markdown Formatter Test Document</h1>
1223
+<p>This document is designed to test the markdown formatter.</p>
1224
+
1225
+<ul>
1226
+<li>A bullet item.
1227
+
1228
+<ul>
1229
+<li>A subitem</li>
1230
+</ul></li>
1231
+<li>Second bullet</li>
1232
+</ul>
1233
+
1234
+<p>More text</p>
1235
+
1236
+<ol>
1237
+<li>Enumeration
1238
+1.1. Subitem 1
1239
+1.2. Subitem 2</li>
1240
+<li>Second enumeration.</li>
1241
+</ol>
1242
+
1243
+<p>Another paragraph.</p>
1244
+
1245
+<h2>Other Features</h2>
1246
+<p>Text can show <em>emphasis</em> or <em>emphasis</em> or <strong>strong emphassis</strong>.</p>
1247
+
1248
+</div>
1249
+}}}
10171250
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,14 @@
16 ############################################################################
17 #
18 # TH1 Commands
19 #
20
 
 
 
 
21 fossil test-th-eval --open-config "setting th1-hooks"
22 set th1Hooks [expr {$RESULT eq "1"}]
23
24 ###############################################################################
25
@@ -859,12 +863,12 @@
859 #
860 fossil test-th-eval "info commands"
861 test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
862 enable_output uplevel http expr glob_match utime styleFooter catch if\
863 tclReady searchable reinitialize combobox lindex query html anoncap randhex\
864 llength for set break regexp styleHeader puts return checkout decorate\
865 artifact trace wiki proc hascap globalState continue getParameter\
866 hasfeature setting lsearch breakpoint upvar render repository string unset\
867 setParameter list error info rename anycap httpize}}
868
869 ###############################################################################
870
@@ -1012,5 +1016,234 @@
1012
1013 ###############################################################################
1014
1015 fossil test-th-eval {list [glob_match {a[bd]c} abc] [glob_match abc {a[bd]c}]}
1016 test th1-glob-match-13 {$RESULT eq "1 0"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,14 @@
16 ############################################################################
17 #
18 # TH1 Commands
19 #
20
21 set dir [file dirname [info script]]
22
23 ###############################################################################
24
25 fossil test-th-eval --open-config "setting th1-hooks"
26 set th1Hooks [expr {$RESULT eq "1"}]
27
28 ###############################################################################
29
@@ -859,12 +863,12 @@
863 #
864 fossil test-th-eval "info commands"
865 test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
866 enable_output uplevel http expr glob_match utime styleFooter catch if\
867 tclReady searchable reinitialize combobox lindex query html anoncap randhex\
868 llength for set break regexp markdown styleHeader puts return checkout\
869 decorate artifact trace wiki proc hascap globalState continue getParameter\
870 hasfeature setting lsearch breakpoint upvar render repository string unset\
871 setParameter list error info rename anycap httpize}}
872
873 ###############################################################################
874
@@ -1012,5 +1016,234 @@
1016
1017 ###############################################################################
1018
1019 fossil test-th-eval {list [glob_match {a[bd]c} abc] [glob_match abc {a[bd]c}]}
1020 test th1-glob-match-13 {$RESULT eq "1 0"}
1021
1022 ###############################################################################
1023
1024 fossil test-th-eval {string is}
1025 test th1-string-is-1 {$RESULT eq \
1026 {TH_ERROR: wrong # args: should be "string is class string"}}
1027
1028 ###############################################################################
1029
1030 fossil test-th-eval {string is something}
1031 test th1-string-is-2 {$RESULT eq \
1032 {TH_ERROR: wrong # args: should be "string is class string"}}
1033
1034 ###############################################################################
1035
1036 fossil test-th-eval {string is not something else}
1037 test th1-string-is-3 {$RESULT eq \
1038 {TH_ERROR: wrong # args: should be "string is class string"}}
1039
1040 ###############################################################################
1041
1042 fossil test-th-eval {string is other 123}
1043 test th1-string-is-4 {$RESULT eq \
1044 "TH_ERROR: Expected alnum, double, integer, or list, got: other"}
1045
1046 ###############################################################################
1047
1048 fossil test-th-eval {string is alnum 123}
1049 test th1-string-is-5 {$RESULT eq "1"}
1050
1051 ###############################################################################
1052
1053 fossil test-th-eval {string is alnum abc}
1054 test th1-string-is-6 {$RESULT eq "1"}
1055
1056 ###############################################################################
1057
1058 fossil test-th-eval {string is alnum 123abc}
1059 test th1-string-is-7 {$RESULT eq "1"}
1060
1061 ###############################################################################
1062
1063 fossil test-th-eval {string is alnum abc123}
1064 test th1-string-is-8 {$RESULT eq "1"}
1065
1066 ###############################################################################
1067
1068 fossil test-th-eval {string is alnum _abc123}
1069 test th1-string-is-9 {$RESULT eq "0"}
1070
1071 ###############################################################################
1072
1073 fossil test-th-eval {string is alnum abc.123}
1074 test th1-string-is-10 {$RESULT eq "0"}
1075
1076 ###############################################################################
1077
1078 fossil test-th-eval {string is alnum abc123_}
1079 test th1-string-is-11 {$RESULT eq "0"}
1080
1081 ###############################################################################
1082
1083 fossil test-th-eval {string is list ""}
1084 test th1-string-is-12 {$RESULT eq "1"}
1085
1086 ###############################################################################
1087
1088 fossil test-th-eval {string is list 1}
1089 test th1-string-is-13 {$RESULT eq "1"}
1090
1091 ###############################################################################
1092
1093 fossil test-th-eval {string is list "1 2 3"}
1094 test th1-string-is-14 {$RESULT eq "1"}
1095
1096 ###############################################################################
1097
1098 fossil test-th-eval {string is list "\{"}
1099 test th1-string-is-15 {$RESULT eq "0"}
1100
1101 ###############################################################################
1102
1103 fossil test-th-eval {string is list "1 2 3 \{"}
1104 test th1-string-is-16 {$RESULT eq "0"}
1105
1106 ###############################################################################
1107
1108 fossil test-th-eval {string is list "1 2 3 \{\}"}
1109 test th1-string-is-17 {$RESULT eq "1"}
1110
1111 ###############################################################################
1112
1113 fossil test-th-eval {string is list "1 2 3 \{\{\}"}
1114 test th1-string-is-18 {$RESULT eq "0"}
1115
1116 ###############################################################################
1117
1118 fossil test-th-eval {string is double 123}
1119 test th1-string-is-19 {$RESULT eq "1"}
1120
1121 ###############################################################################
1122
1123 fossil test-th-eval {string is double 123.456}
1124 test th1-string-is-20 {$RESULT eq "1"}
1125
1126 ###############################################################################
1127
1128 fossil test-th-eval {string is double 123abc}
1129 test th1-string-is-21 {$RESULT eq "0"}
1130
1131 ###############################################################################
1132
1133 fossil test-th-eval {string is double 123_456}
1134 test th1-string-is-22 {$RESULT eq "0"}
1135
1136 ###############################################################################
1137
1138 fossil test-th-eval {string is integer 123}
1139 test th1-string-is-23 {$RESULT eq "1"}
1140
1141 ###############################################################################
1142
1143 fossil test-th-eval {string is integer 123.456}
1144 test th1-string-is-24 {$RESULT eq "0"}
1145
1146 ###############################################################################
1147
1148 fossil test-th-eval {string is integer 123abc}
1149 test th1-string-is-25 {$RESULT eq "0"}
1150
1151 ###############################################################################
1152
1153 fossil test-th-eval {string is integer 0b11001001}
1154 test th1-string-is-26 {$RESULT eq "1"}
1155
1156 ###############################################################################
1157
1158 fossil test-th-eval {string is integer 0b11001002}
1159 test th1-string-is-27 {$RESULT eq "0"}
1160
1161 ###############################################################################
1162
1163 fossil test-th-eval {string is integer 0o777}
1164 test th1-string-is-28 {$RESULT eq "1"}
1165
1166 ###############################################################################
1167
1168 fossil test-th-eval {string is integer 0o778}
1169 test th1-string-is-29 {$RESULT eq "0"}
1170
1171 ###############################################################################
1172
1173 fossil test-th-eval {string is integer 0xC0DEF00D}
1174 test th1-string-is-30 {$RESULT eq "1"}
1175
1176 ###############################################################################
1177
1178 fossil test-th-eval {string is integer 0xC0DEF00Z}
1179 test th1-string-is-31 {$RESULT eq "0"}
1180
1181 ###############################################################################
1182
1183 fossil test-th-eval {markdown}
1184 test th1-markdown-1 {$RESULT eq \
1185 {TH_ERROR: wrong # args: should be "markdown STRING"}}
1186
1187 ###############################################################################
1188
1189 fossil test-th-eval {markdown one two}
1190 test th1-markdown-2 {$RESULT eq \
1191 {TH_ERROR: wrong # args: should be "markdown STRING"}}
1192
1193 ###############################################################################
1194
1195 fossil test-th-eval {markdown "*This is a test.*"}
1196 test th1-markdown-3 {[normalize_result] eq {{} {<div class="markdown">
1197
1198 <p><em>This is a test.</em></p>
1199
1200 </div>
1201 }}}
1202
1203 ###############################################################################
1204
1205 fossil test-th-eval {markdown "Test1\n=====\n*This is a test.*"}
1206 test th1-markdown-4 {[normalize_result] eq {Test1 {<div class="markdown">
1207
1208 <h1>Test1</h1>
1209 <p><em>This is a test.</em></p>
1210
1211 </div>
1212 }}}
1213
1214 ###############################################################################
1215
1216 set markdown [read_file [file join $dir markdown-test1.md]]
1217 fossil test-th-eval [string map \
1218 [list %markdown% $markdown] {markdown {%markdown%}}]
1219 test th1-markdown-5 {[normalize_result] eq \
1220 {{Markdown Formatter Test Document} {<div class="markdown">
1221
1222 <h1>Markdown Formatter Test Document</h1>
1223 <p>This document is designed to test the markdown formatter.</p>
1224
1225 <ul>
1226 <li>A bullet item.
1227
1228 <ul>
1229 <li>A subitem</li>
1230 </ul></li>
1231 <li>Second bullet</li>
1232 </ul>
1233
1234 <p>More text</p>
1235
1236 <ol>
1237 <li>Enumeration
1238 1.1. Subitem 1
1239 1.2. Subitem 2</li>
1240 <li>Second enumeration.</li>
1241 </ol>
1242
1243 <p>Another paragraph.</p>
1244
1245 <h2>Other Features</h2>
1246 <p>Text can show <em>emphasis</em> or <em>emphasis</em> or <strong>strong emphassis</strong>.</p>
1247
1248 </div>
1249 }}}
1250
+15 -5
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,15 +1,25 @@
11
<title>Change Log</title>
22
33
<h2>Changes for Version 1.34 (2015-??-??)</h2>
4
- * Fix --hard option to mv/rm to enable them to work properly with certain
5
- relative paths.
6
- * Add minimal 'lsearch' command to TH1. Only exact case-sensitive matching
7
- is supported.
8
- * Add 'glob_match' command to TH1.
4
+
5
+ * Fix --hard option to [/help?cmd=mv|fossil mv] and [/help?cmd=rm|fossil rm]
6
+ to enable them to work properly with certain relative paths.
7
+ * Make the [/help?cmd=clean|fossil clean] command undoable for files less
8
+ than 10MiB.
9
+ * Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
10
+ case-sensitive matching is supported.
11
+ * Add the <nowiki>[glob_match]</nowiki> and <nowiki>[markdown]</nowiki>
12
+ commands to TH1.
13
+ * Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
14
+ the Tcl integration subsystem.
15
+ * Add 'double', 'integer', and 'list' classes to the
16
+ <nowiki>[string is]</nowiki> command in TH1.
917
* Update internal Unicode character tables, used in regular expression
1018
handling, from version 7.0 to 8.0.
19
+ * Add the new [/help?cmd=amend|amend] command which is used to modify
20
+ tags of a "check-in".
1121
1222
<h2>Changes for Version 1.33 (2015-05-23)</h2>
1323
* Improved fork detection on [/help?cmd=update|fossil update],
1424
[/help?cmd=status|fossil status] and related commands.
1525
* Change the default skin to what used to be called "San Francisco Modern".
1626
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,15 +1,25 @@
1 <title>Change Log</title>
2
3 <h2>Changes for Version 1.34 (2015-??-??)</h2>
4 * Fix --hard option to mv/rm to enable them to work properly with certain
5 relative paths.
6 * Add minimal 'lsearch' command to TH1. Only exact case-sensitive matching
7 is supported.
8 * Add 'glob_match' command to TH1.
 
 
 
 
 
 
 
 
9 * Update internal Unicode character tables, used in regular expression
10 handling, from version 7.0 to 8.0.
 
 
11
12 <h2>Changes for Version 1.33 (2015-05-23)</h2>
13 * Improved fork detection on [/help?cmd=update|fossil update],
14 [/help?cmd=status|fossil status] and related commands.
15 * Change the default skin to what used to be called "San Francisco Modern".
16
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,15 +1,25 @@
1 <title>Change Log</title>
2
3 <h2>Changes for Version 1.34 (2015-??-??)</h2>
4
5 * Fix --hard option to [/help?cmd=mv|fossil mv] and [/help?cmd=rm|fossil rm]
6 to enable them to work properly with certain relative paths.
7 * Make the [/help?cmd=clean|fossil clean] command undoable for files less
8 than 10MiB.
9 * Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
10 case-sensitive matching is supported.
11 * Add the <nowiki>[glob_match]</nowiki> and <nowiki>[markdown]</nowiki>
12 commands to TH1.
13 * Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
14 the Tcl integration subsystem.
15 * Add 'double', 'integer', and 'list' classes to the
16 <nowiki>[string is]</nowiki> command in TH1.
17 * Update internal Unicode character tables, used in regular expression
18 handling, from version 7.0 to 8.0.
19 * Add the new [/help?cmd=amend|amend] command which is used to modify
20 tags of a "check-in".
21
22 <h2>Changes for Version 1.33 (2015-05-23)</h2>
23 * Improved fork detection on [/help?cmd=update|fossil update],
24 [/help?cmd=status|fossil status] and related commands.
25 * Change the default skin to what used to be called "San Francisco Modern".
26
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -15,10 +15,11 @@
1515
<ul>
1616
<li> <b>tip</b>
1717
<li> <b>current</b>
1818
<li> <b>next</b>
1919
<li> <b>previous</b> or <b>prev</b>
20
+<li> <b>ckout</b> for embedded docs
2021
</ul>
2122
</ul>
2223
</td></tr>
2324
</table>
2425
Many Fossil [/help|commands] and [./webui.wiki | web-interface] URLs accept
@@ -216,10 +217,16 @@
216217
If the command is being run from a working check-out (not against a bare
217218
repository) then a few extra tags apply. The "current" tag means the
218219
current check-out. The "next" tag means the youngest child of the
219220
current check-out. And the "previous" or "prev" tag means the primary
220221
(non-merge) parent of the current check-out.
222
+
223
+For embedded documentation, the tag "ckout" means the version as present in
224
+the local source tree on disk, provided that the web server is started using
225
+"fossil ui" or "fossil server" from within the source tree. This tag can be
226
+used to preview local changes to documentation before committing them. It does
227
+not apply to CLI commands.
221228
222229
<h2>Additional Examples</h2>
223230
224231
To view the changes in the most recent check-in prior to the version currently
225232
checked out:
226233
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -15,10 +15,11 @@
15 <ul>
16 <li> <b>tip</b>
17 <li> <b>current</b>
18 <li> <b>next</b>
19 <li> <b>previous</b> or <b>prev</b>
 
20 </ul>
21 </ul>
22 </td></tr>
23 </table>
24 Many Fossil [/help|commands] and [./webui.wiki | web-interface] URLs accept
@@ -216,10 +217,16 @@
216 If the command is being run from a working check-out (not against a bare
217 repository) then a few extra tags apply. The "current" tag means the
218 current check-out. The "next" tag means the youngest child of the
219 current check-out. And the "previous" or "prev" tag means the primary
220 (non-merge) parent of the current check-out.
 
 
 
 
 
 
221
222 <h2>Additional Examples</h2>
223
224 To view the changes in the most recent check-in prior to the version currently
225 checked out:
226
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -15,10 +15,11 @@
15 <ul>
16 <li> <b>tip</b>
17 <li> <b>current</b>
18 <li> <b>next</b>
19 <li> <b>previous</b> or <b>prev</b>
20 <li> <b>ckout</b> for embedded docs
21 </ul>
22 </ul>
23 </td></tr>
24 </table>
25 Many Fossil [/help|commands] and [./webui.wiki | web-interface] URLs accept
@@ -216,10 +217,16 @@
217 If the command is being run from a working check-out (not against a bare
218 repository) then a few extra tags apply. The "current" tag means the
219 current check-out. The "next" tag means the youngest child of the
220 current check-out. And the "previous" or "prev" tag means the primary
221 (non-merge) parent of the current check-out.
222
223 For embedded documentation, the tag "ckout" means the version as present in
224 the local source tree on disk, provided that the web server is started using
225 "fossil ui" or "fossil server" from within the source tree. This tag can be
226 used to preview local changes to documentation before committing them. It does
227 not apply to CLI commands.
228
229 <h2>Additional Examples</h2>
230
231 To view the changes in the most recent check-in prior to the version currently
232 checked out:
233
--- www/server.wiki
+++ www/server.wiki
@@ -179,10 +179,14 @@
179179
script itself must be executable for the user under which it will run (which often differs
180180
from the one running the web server - consult your site's documentation or administrator).</li>
181181
<li>The repository file AND the directory containing it must be writable by the same account
182182
which executes the Fossil binary (again, this might differ from the WWW user). The directory
183183
needs to be writable so that sqlite can write its journal files.</li>
184
+<li>Fossil must be able to create temporary files, the default directory
185
+for which depends on the OS. When the CGI process is operating within
186
+a chroot, ensure that this directory exists and is readable/writeable
187
+by the user who executes the Fossil binary.</li>
184188
</ul>
185189
</p>
186190
187191
<p>
188192
Once the script is set up correctly, and assuming your server is also set
189193
--- www/server.wiki
+++ www/server.wiki
@@ -179,10 +179,14 @@
179 script itself must be executable for the user under which it will run (which often differs
180 from the one running the web server - consult your site's documentation or administrator).</li>
181 <li>The repository file AND the directory containing it must be writable by the same account
182 which executes the Fossil binary (again, this might differ from the WWW user). The directory
183 needs to be writable so that sqlite can write its journal files.</li>
 
 
 
 
184 </ul>
185 </p>
186
187 <p>
188 Once the script is set up correctly, and assuming your server is also set
189
--- www/server.wiki
+++ www/server.wiki
@@ -179,10 +179,14 @@
179 script itself must be executable for the user under which it will run (which often differs
180 from the one running the web server - consult your site's documentation or administrator).</li>
181 <li>The repository file AND the directory containing it must be writable by the same account
182 which executes the Fossil binary (again, this might differ from the WWW user). The directory
183 needs to be writable so that sqlite can write its journal files.</li>
184 <li>Fossil must be able to create temporary files, the default directory
185 for which depends on the OS. When the CGI process is operating within
186 a chroot, ensure that this directory exists and is readable/writeable
187 by the user who executes the Fossil binary.</li>
188 </ul>
189 </p>
190
191 <p>
192 Once the script is set up correctly, and assuming your server is also set
193
--- www/settings.wiki
+++ www/settings.wiki
@@ -42,12 +42,13 @@
4242
with the <tt>extras</tt> command.
4343
4444
Because these options can change over time, and the inconvenience of
4545
replicating changes, these settings are "versionable". As well as being
4646
able to be set using the <tt>settings</tt> command or the web interface,
47
-you can created versioned files in the <tt>.fossil-settings</tt>
48
-directory named with the setting name. The contents of the file is the
47
+you can create versioned files in the <tt>.fossil-settings</tt>
48
+subdirectory of the check-out root, named with the setting name.
49
+The contents of the file is the
4950
value of the setting, and these files are checked in, committed, merged,
5051
and so on, as with any other file.
5152
5253
Where a setting is a list of values, such as <tt>ignore-glob</tt>, you
5354
can use a newline as a separator as well as a comma.
5455
--- www/settings.wiki
+++ www/settings.wiki
@@ -42,12 +42,13 @@
42 with the <tt>extras</tt> command.
43
44 Because these options can change over time, and the inconvenience of
45 replicating changes, these settings are "versionable". As well as being
46 able to be set using the <tt>settings</tt> command or the web interface,
47 you can created versioned files in the <tt>.fossil-settings</tt>
48 directory named with the setting name. The contents of the file is the
 
49 value of the setting, and these files are checked in, committed, merged,
50 and so on, as with any other file.
51
52 Where a setting is a list of values, such as <tt>ignore-glob</tt>, you
53 can use a newline as a separator as well as a comma.
54
--- www/settings.wiki
+++ www/settings.wiki
@@ -42,12 +42,13 @@
42 with the <tt>extras</tt> command.
43
44 Because these options can change over time, and the inconvenience of
45 replicating changes, these settings are "versionable". As well as being
46 able to be set using the <tt>settings</tt> command or the web interface,
47 you can create versioned files in the <tt>.fossil-settings</tt>
48 subdirectory of the check-out root, named with the setting name.
49 The contents of the file is the
50 value of the setting, and these files are checked in, committed, merged,
51 and so on, as with any other file.
52
53 Where a setting is a list of values, such as <tt>ignore-glob</tt>, you
54 can use a newline as a separator as well as a comma.
55
+12 -1
--- www/th1.md
+++ www/th1.md
@@ -113,11 +113,12 @@
113113
* unset VARNAME
114114
* uplevel ?LEVEL? SCRIPT
115115
* upvar ?FRAME? OTHERVAR MYVAR ?OTHERVAR MYVAR?
116116
117117
All of the above commands works as in the original Tcl. Refer to the
118
-Tcl documentation for details.
118
+<a href="https://www.tcl.tk/man/tcl/contents.htm">Tcl documentation</a>
119
+for details.
119120
120121
TH1 Extended Commands
121122
---------------------
122123
123124
There are many new commands added to TH1 and used to access the special
@@ -139,10 +140,11 @@
139140
* html
140141
* htmlize
141142
* http
142143
* httpize
143144
* linecount
145
+ * markdown
144146
* puts
145147
* query
146148
* randhex
147149
* regexp
148150
* reinitialize
@@ -350,10 +352,19 @@
350352
351353
* linecount STRING MAX MIN
352354
353355
Returns one more than the number of \n characters in STRING. But
354356
never returns less than MIN or more than MAX.
357
+
358
+<a name="markdown"></a>TH1 markdown Command
359
+---------------------------------------------
360
+
361
+ * markdown STRING
362
+
363
+Renders the input string as markdown. The result is a two-element list.
364
+The first element contains the body, rendered as HTML. The second element
365
+is the text-only title string.
355366
356367
<a name="puts"></a>TH1 puts Command
357368
-----------------------------------
358369
359370
* puts STRING
360371
--- www/th1.md
+++ www/th1.md
@@ -113,11 +113,12 @@
113 * unset VARNAME
114 * uplevel ?LEVEL? SCRIPT
115 * upvar ?FRAME? OTHERVAR MYVAR ?OTHERVAR MYVAR?
116
117 All of the above commands works as in the original Tcl. Refer to the
118 Tcl documentation for details.
 
119
120 TH1 Extended Commands
121 ---------------------
122
123 There are many new commands added to TH1 and used to access the special
@@ -139,10 +140,11 @@
139 * html
140 * htmlize
141 * http
142 * httpize
143 * linecount
 
144 * puts
145 * query
146 * randhex
147 * regexp
148 * reinitialize
@@ -350,10 +352,19 @@
350
351 * linecount STRING MAX MIN
352
353 Returns one more than the number of \n characters in STRING. But
354 never returns less than MIN or more than MAX.
 
 
 
 
 
 
 
 
 
355
356 <a name="puts"></a>TH1 puts Command
357 -----------------------------------
358
359 * puts STRING
360
--- www/th1.md
+++ www/th1.md
@@ -113,11 +113,12 @@
113 * unset VARNAME
114 * uplevel ?LEVEL? SCRIPT
115 * upvar ?FRAME? OTHERVAR MYVAR ?OTHERVAR MYVAR?
116
117 All of the above commands works as in the original Tcl. Refer to the
118 <a href="https://www.tcl.tk/man/tcl/contents.htm">Tcl documentation</a>
119 for details.
120
121 TH1 Extended Commands
122 ---------------------
123
124 There are many new commands added to TH1 and used to access the special
@@ -139,10 +140,11 @@
140 * html
141 * htmlize
142 * http
143 * httpize
144 * linecount
145 * markdown
146 * puts
147 * query
148 * randhex
149 * regexp
150 * reinitialize
@@ -350,10 +352,19 @@
352
353 * linecount STRING MAX MIN
354
355 Returns one more than the number of \n characters in STRING. But
356 never returns less than MIN or more than MAX.
357
358 <a name="markdown"></a>TH1 markdown Command
359 ---------------------------------------------
360
361 * markdown STRING
362
363 Renders the input string as markdown. The result is a two-element list.
364 The first element contains the body, rendered as HTML. The second element
365 is the text-only title string.
366
367 <a name="puts"></a>TH1 puts Command
368 -----------------------------------
369
370 * puts STRING
371
+1 -1
--- www/webui.wiki
+++ www/webui.wiki
@@ -61,11 +61,11 @@
6161
<b>fossil ui</b>
6262
6363
The latter case is a very useful short-cut when you are working on a
6464
Fossil project and you want to quickly do some work with the web interface.
6565
Notice that Fossil automatically finds an unused TCP port to run the
66
-server own and automatically points your web browser to the correct
66
+server on and automatically points your web browser to the correct
6767
URL. So there is never any fumbling around trying to find an open
6868
port or to type arcane strings into your browser URL entry box.
6969
The interface just pops right up, ready to run.
7070
7171
The Fossil web interface is also very easy to setup and run on a
7272
--- www/webui.wiki
+++ www/webui.wiki
@@ -61,11 +61,11 @@
61 <b>fossil ui</b>
62
63 The latter case is a very useful short-cut when you are working on a
64 Fossil project and you want to quickly do some work with the web interface.
65 Notice that Fossil automatically finds an unused TCP port to run the
66 server own and automatically points your web browser to the correct
67 URL. So there is never any fumbling around trying to find an open
68 port or to type arcane strings into your browser URL entry box.
69 The interface just pops right up, ready to run.
70
71 The Fossil web interface is also very easy to setup and run on a
72
--- www/webui.wiki
+++ www/webui.wiki
@@ -61,11 +61,11 @@
61 <b>fossil ui</b>
62
63 The latter case is a very useful short-cut when you are working on a
64 Fossil project and you want to quickly do some work with the web interface.
65 Notice that Fossil automatically finds an unused TCP port to run the
66 server on and automatically points your web browser to the correct
67 URL. So there is never any fumbling around trying to find an open
68 port or to type arcane strings into your browser URL entry box.
69 The interface just pops right up, ready to run.
70
71 The Fossil web interface is also very easy to setup and run on a
72

Keyboard Shortcuts

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