Fossil SCM

Upgrade the built-in SQLite to the latest 3.8.6 alpha from upstream.

drh 2014-07-24 15:46 trunk
Commit f39d8a3d24a2d07b75348751ce5d2531ae34bc5d
3 files changed +104 -12 +453 -259 +45 -13
+104 -12
--- src/shell.c
+++ src/shell.c
@@ -62,10 +62,11 @@
6262
# define stifle_history(X)
6363
#endif
6464
6565
#if defined(_WIN32) || defined(WIN32)
6666
# include <io.h>
67
+# include <fcntl.h>
6768
#define isatty(h) _isatty(h)
6869
#ifndef access
6970
# define access(f,m) _access((f),(m))
7071
#endif
7172
#undef popen
@@ -456,10 +457,11 @@
456457
int mode; /* An output mode setting */
457458
int writableSchema; /* True if PRAGMA writable_schema=ON */
458459
int showHeader; /* True to show column names in List or Column mode */
459460
char *zDestTable; /* Name of destination table when MODE_Insert */
460461
char separator[20]; /* Separator character for MODE_List */
462
+ char newline[20]; /* Record separator in MODE_Csv */
461463
int colWidth[100]; /* Requested width of each column when in column mode*/
462464
int actualWidth[100]; /* Actual width of each column */
463465
char nullvalue[20]; /* The text to print when a NULL comes back from
464466
** the database */
465467
struct previous_mode_data explainPrev;
@@ -657,11 +659,12 @@
657659
};
658660
659661
/*
660662
** Output a single term of CSV. Actually, p->separator is used for
661663
** the separator, which may or may not be a comma. p->nullvalue is
662
-** the null value. Strings are quoted if necessary.
664
+** the null value. Strings are quoted if necessary. The separator
665
+** is only issued if bSep is true.
663666
*/
664667
static void output_csv(struct callback_data *p, const char *z, int bSep){
665668
FILE *out = p->out;
666669
if( z==0 ){
667670
fprintf(out,"%s",p->nullvalue);
@@ -853,21 +856,30 @@
853856
}
854857
fprintf(p->out,"\n");
855858
break;
856859
}
857860
case MODE_Csv: {
861
+#if defined(WIN32) || defined(_WIN32)
862
+ fflush(p->out);
863
+ _setmode(_fileno(p->out), _O_BINARY);
864
+#endif
858865
if( p->cnt++==0 && p->showHeader ){
859866
for(i=0; i<nArg; i++){
860867
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
861868
}
862
- fprintf(p->out,"\n");
869
+ fprintf(p->out,"%s",p->newline);
863870
}
864
- if( azArg==0 ) break;
865
- for(i=0; i<nArg; i++){
866
- output_csv(p, azArg[i], i<nArg-1);
871
+ if( azArg>0 ){
872
+ for(i=0; i<nArg; i++){
873
+ output_csv(p, azArg[i], i<nArg-1);
874
+ }
875
+ fprintf(p->out,"%s",p->newline);
867876
}
868
- fprintf(p->out,"\n");
877
+#if defined(WIN32) || defined(_WIN32)
878
+ fflush(p->out);
879
+ _setmode(_fileno(p->out), _O_TEXT);
880
+#endif
869881
break;
870882
}
871883
case MODE_Insert: {
872884
p->cnt++;
873885
if( azArg==0 ) break;
@@ -1617,11 +1629,12 @@
16171629
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
16181630
".save FILE Write in-memory database into FILE\n"
16191631
".schema ?TABLE? Show the CREATE statements\n"
16201632
" If TABLE specified, only show tables matching\n"
16211633
" LIKE pattern TABLE.\n"
1622
- ".separator STRING Change separator used by output mode and .import\n"
1634
+ ".separator STRING ?NL? Change separator used by output mode and .import\n"
1635
+ " NL is the end-of-line mark for CSV\n"
16231636
".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
16241637
".show Show the current values for various settings\n"
16251638
".stats on|off Turn stats on or off\n"
16261639
".system CMD ARGS... Run CMD ARGS... in a system shell\n"
16271640
".tables ?TABLE? List names of tables\n"
@@ -1635,10 +1648,73 @@
16351648
" Negative values right-justify\n"
16361649
;
16371650
16381651
/* Forward reference */
16391652
static int process_input(struct callback_data *p, FILE *in);
1653
+/*
1654
+** Implementation of the "readfile(X)" SQL function. The entire content
1655
+** of the file named X is read and returned as a BLOB. NULL is returned
1656
+** if the file does not exist or is unreadable.
1657
+*/
1658
+static void readfileFunc(
1659
+ sqlite3_context *context,
1660
+ int argc,
1661
+ sqlite3_value **argv
1662
+){
1663
+ const char *zName;
1664
+ FILE *in;
1665
+ long nIn;
1666
+ void *pBuf;
1667
+
1668
+ zName = (const char*)sqlite3_value_text(argv[0]);
1669
+ if( zName==0 ) return;
1670
+ in = fopen(zName, "rb");
1671
+ if( in==0 ) return;
1672
+ fseek(in, 0, SEEK_END);
1673
+ nIn = ftell(in);
1674
+ rewind(in);
1675
+ pBuf = sqlite3_malloc( nIn );
1676
+ if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1677
+ sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
1678
+ }else{
1679
+ sqlite3_free(pBuf);
1680
+ }
1681
+ fclose(in);
1682
+}
1683
+
1684
+/*
1685
+** Implementation of the "writefile(X,Y)" SQL function. The argument Y
1686
+** is written into file X. The number of bytes written is returned. Or
1687
+** NULL is returned if something goes wrong, such as being unable to open
1688
+** file X for writing.
1689
+*/
1690
+static void writefileFunc(
1691
+ sqlite3_context *context,
1692
+ int argc,
1693
+ sqlite3_value **argv
1694
+){
1695
+ FILE *out;
1696
+ const char *z;
1697
+ int n;
1698
+ sqlite3_int64 rc;
1699
+ const char *zFile;
1700
+
1701
+ zFile = (const char*)sqlite3_value_text(argv[0]);
1702
+ if( zFile==0 ) return;
1703
+ out = fopen(zFile, "wb");
1704
+ if( out==0 ) return;
1705
+ z = (const char*)sqlite3_value_blob(argv[1]);
1706
+ if( z==0 ){
1707
+ n = 0;
1708
+ rc = 0;
1709
+ }else{
1710
+ n = sqlite3_value_bytes(argv[1]);
1711
+ rc = fwrite(z, 1, n, out);
1712
+ }
1713
+ fclose(out);
1714
+ sqlite3_result_int64(context, rc);
1715
+}
16401716
16411717
/*
16421718
** Make sure the database is open. If it is not, then open it. If
16431719
** the database fails to open, print an error message and exit.
16441720
*/
@@ -1658,10 +1734,14 @@
16581734
exit(1);
16591735
}
16601736
#ifndef SQLITE_OMIT_LOAD_EXTENSION
16611737
sqlite3_enable_load_extension(p->db, 1);
16621738
#endif
1739
+ sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
1740
+ readfileFunc, 0, 0);
1741
+ sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
1742
+ writefileFunc, 0, 0);
16631743
}
16641744
}
16651745
16661746
/*
16671747
** Do C-language style dequoting.
@@ -2749,10 +2829,11 @@
27492829
p->mode = MODE_Tcl;
27502830
sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
27512831
}else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
27522832
p->mode = MODE_Csv;
27532833
sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2834
+ sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n");
27542835
}else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
27552836
p->mode = MODE_List;
27562837
sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
27572838
}else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
27582839
p->mode = MODE_Insert;
@@ -3027,17 +3108,20 @@
30273108
}
30283109
}else
30293110
#endif
30303111
30313112
if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3032
- if( nArg==2 ){
3033
- sqlite3_snprintf(sizeof(p->separator), p->separator,
3034
- "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
3035
- }else{
3036
- fprintf(stderr, "Usage: .separator STRING\n");
3113
+ if( nArg<2 || nArg>3 ){
3114
+ fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n");
30373115
rc = 1;
30383116
}
3117
+ if( nArg>=2 ){
3118
+ sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]);
3119
+ }
3120
+ if( nArg>=3 ){
3121
+ sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]);
3122
+ }
30393123
}else
30403124
30413125
if( c=='s'
30423126
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
30433127
){
@@ -3074,10 +3158,12 @@
30743158
fprintf(p->out, "\n");
30753159
fprintf(p->out,"%9.9s: %s\n","output",
30763160
strlen30(p->outfile) ? p->outfile : "stdout");
30773161
fprintf(p->out,"%9.9s: ", "separator");
30783162
output_c_string(p->out, p->separator);
3163
+ fprintf(p->out," ");
3164
+ output_c_string(p->out, p->newline);
30793165
fprintf(p->out, "\n");
30803166
fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
30813167
fprintf(p->out,"%9.9s: ","width");
30823168
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
30833169
fprintf(p->out,"%d ",p->colWidth[i]);
@@ -3690,10 +3776,11 @@
36903776
" -list set output mode to 'list'\n"
36913777
" -mmap N default mmap size set to N\n"
36923778
#ifdef SQLITE_ENABLE_MULTIPLEX
36933779
" -multiplex enable the multiplexor VFS\n"
36943780
#endif
3781
+ " -newline SEP set newline character(s) for CSV\n"
36953782
" -nullvalue TEXT set text string for NULL values. Default ''\n"
36963783
" -separator SEP set output field separator. Default: '|'\n"
36973784
" -stats print memory stats before each finalize\n"
36983785
" -version show SQLite version\n"
36993786
" -vfs NAME use NAME as the default VFS\n"
@@ -3719,10 +3806,11 @@
37193806
*/
37203807
static void main_init(struct callback_data *data) {
37213808
memset(data, 0, sizeof(*data));
37223809
data->mode = MODE_List;
37233810
memcpy(data->separator,"|", 2);
3811
+ memcpy(data->newline,"\r\n", 3);
37243812
data->showHeader = 0;
37253813
sqlite3_config(SQLITE_CONFIG_URI, 1);
37263814
sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
37273815
sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
37283816
sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
@@ -3811,10 +3899,11 @@
38113899
return 1;
38123900
}
38133901
if( z[1]=='-' ) z++;
38143902
if( strcmp(z,"-separator")==0
38153903
|| strcmp(z,"-nullvalue")==0
3904
+ || strcmp(z,"-newline")==0
38163905
|| strcmp(z,"-cmd")==0
38173906
){
38183907
(void)cmdline_option_value(argc, argv, ++i);
38193908
}else if( strcmp(z,"-init")==0 ){
38203909
zInitFile = cmdline_option_value(argc, argv, ++i);
@@ -3920,10 +4009,13 @@
39204009
data.mode = MODE_Csv;
39214010
memcpy(data.separator,",",2);
39224011
}else if( strcmp(z,"-separator")==0 ){
39234012
sqlite3_snprintf(sizeof(data.separator), data.separator,
39244013
"%s",cmdline_option_value(argc,argv,++i));
4014
+ }else if( strcmp(z,"-newline")==0 ){
4015
+ sqlite3_snprintf(sizeof(data.newline), data.newline,
4016
+ "%s",cmdline_option_value(argc,argv,++i));
39254017
}else if( strcmp(z,"-nullvalue")==0 ){
39264018
sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
39274019
"%s",cmdline_option_value(argc,argv,++i));
39284020
}else if( strcmp(z,"-header")==0 ){
39294021
data.showHeader = 1;
39304022
--- src/shell.c
+++ src/shell.c
@@ -62,10 +62,11 @@
62 # define stifle_history(X)
63 #endif
64
65 #if defined(_WIN32) || defined(WIN32)
66 # include <io.h>
 
67 #define isatty(h) _isatty(h)
68 #ifndef access
69 # define access(f,m) _access((f),(m))
70 #endif
71 #undef popen
@@ -456,10 +457,11 @@
456 int mode; /* An output mode setting */
457 int writableSchema; /* True if PRAGMA writable_schema=ON */
458 int showHeader; /* True to show column names in List or Column mode */
459 char *zDestTable; /* Name of destination table when MODE_Insert */
460 char separator[20]; /* Separator character for MODE_List */
 
461 int colWidth[100]; /* Requested width of each column when in column mode*/
462 int actualWidth[100]; /* Actual width of each column */
463 char nullvalue[20]; /* The text to print when a NULL comes back from
464 ** the database */
465 struct previous_mode_data explainPrev;
@@ -657,11 +659,12 @@
657 };
658
659 /*
660 ** Output a single term of CSV. Actually, p->separator is used for
661 ** the separator, which may or may not be a comma. p->nullvalue is
662 ** the null value. Strings are quoted if necessary.
 
663 */
664 static void output_csv(struct callback_data *p, const char *z, int bSep){
665 FILE *out = p->out;
666 if( z==0 ){
667 fprintf(out,"%s",p->nullvalue);
@@ -853,21 +856,30 @@
853 }
854 fprintf(p->out,"\n");
855 break;
856 }
857 case MODE_Csv: {
 
 
 
 
858 if( p->cnt++==0 && p->showHeader ){
859 for(i=0; i<nArg; i++){
860 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
861 }
862 fprintf(p->out,"\n");
863 }
864 if( azArg==0 ) break;
865 for(i=0; i<nArg; i++){
866 output_csv(p, azArg[i], i<nArg-1);
 
 
867 }
868 fprintf(p->out,"\n");
 
 
 
869 break;
870 }
871 case MODE_Insert: {
872 p->cnt++;
873 if( azArg==0 ) break;
@@ -1617,11 +1629,12 @@
1617 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1618 ".save FILE Write in-memory database into FILE\n"
1619 ".schema ?TABLE? Show the CREATE statements\n"
1620 " If TABLE specified, only show tables matching\n"
1621 " LIKE pattern TABLE.\n"
1622 ".separator STRING Change separator used by output mode and .import\n"
 
1623 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1624 ".show Show the current values for various settings\n"
1625 ".stats on|off Turn stats on or off\n"
1626 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1627 ".tables ?TABLE? List names of tables\n"
@@ -1635,10 +1648,73 @@
1635 " Negative values right-justify\n"
1636 ;
1637
1638 /* Forward reference */
1639 static int process_input(struct callback_data *p, FILE *in);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1640
1641 /*
1642 ** Make sure the database is open. If it is not, then open it. If
1643 ** the database fails to open, print an error message and exit.
1644 */
@@ -1658,10 +1734,14 @@
1658 exit(1);
1659 }
1660 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1661 sqlite3_enable_load_extension(p->db, 1);
1662 #endif
 
 
 
 
1663 }
1664 }
1665
1666 /*
1667 ** Do C-language style dequoting.
@@ -2749,10 +2829,11 @@
2749 p->mode = MODE_Tcl;
2750 sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
2751 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
2752 p->mode = MODE_Csv;
2753 sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
 
2754 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
2755 p->mode = MODE_List;
2756 sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
2757 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
2758 p->mode = MODE_Insert;
@@ -3027,17 +3108,20 @@
3027 }
3028 }else
3029 #endif
3030
3031 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3032 if( nArg==2 ){
3033 sqlite3_snprintf(sizeof(p->separator), p->separator,
3034 "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
3035 }else{
3036 fprintf(stderr, "Usage: .separator STRING\n");
3037 rc = 1;
3038 }
 
 
 
 
 
 
3039 }else
3040
3041 if( c=='s'
3042 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
3043 ){
@@ -3074,10 +3158,12 @@
3074 fprintf(p->out, "\n");
3075 fprintf(p->out,"%9.9s: %s\n","output",
3076 strlen30(p->outfile) ? p->outfile : "stdout");
3077 fprintf(p->out,"%9.9s: ", "separator");
3078 output_c_string(p->out, p->separator);
 
 
3079 fprintf(p->out, "\n");
3080 fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
3081 fprintf(p->out,"%9.9s: ","width");
3082 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3083 fprintf(p->out,"%d ",p->colWidth[i]);
@@ -3690,10 +3776,11 @@
3690 " -list set output mode to 'list'\n"
3691 " -mmap N default mmap size set to N\n"
3692 #ifdef SQLITE_ENABLE_MULTIPLEX
3693 " -multiplex enable the multiplexor VFS\n"
3694 #endif
 
3695 " -nullvalue TEXT set text string for NULL values. Default ''\n"
3696 " -separator SEP set output field separator. Default: '|'\n"
3697 " -stats print memory stats before each finalize\n"
3698 " -version show SQLite version\n"
3699 " -vfs NAME use NAME as the default VFS\n"
@@ -3719,10 +3806,11 @@
3719 */
3720 static void main_init(struct callback_data *data) {
3721 memset(data, 0, sizeof(*data));
3722 data->mode = MODE_List;
3723 memcpy(data->separator,"|", 2);
 
3724 data->showHeader = 0;
3725 sqlite3_config(SQLITE_CONFIG_URI, 1);
3726 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
3727 sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
3728 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
@@ -3811,10 +3899,11 @@
3811 return 1;
3812 }
3813 if( z[1]=='-' ) z++;
3814 if( strcmp(z,"-separator")==0
3815 || strcmp(z,"-nullvalue")==0
 
3816 || strcmp(z,"-cmd")==0
3817 ){
3818 (void)cmdline_option_value(argc, argv, ++i);
3819 }else if( strcmp(z,"-init")==0 ){
3820 zInitFile = cmdline_option_value(argc, argv, ++i);
@@ -3920,10 +4009,13 @@
3920 data.mode = MODE_Csv;
3921 memcpy(data.separator,",",2);
3922 }else if( strcmp(z,"-separator")==0 ){
3923 sqlite3_snprintf(sizeof(data.separator), data.separator,
3924 "%s",cmdline_option_value(argc,argv,++i));
 
 
 
3925 }else if( strcmp(z,"-nullvalue")==0 ){
3926 sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
3927 "%s",cmdline_option_value(argc,argv,++i));
3928 }else if( strcmp(z,"-header")==0 ){
3929 data.showHeader = 1;
3930
--- src/shell.c
+++ src/shell.c
@@ -62,10 +62,11 @@
62 # define stifle_history(X)
63 #endif
64
65 #if defined(_WIN32) || defined(WIN32)
66 # include <io.h>
67 # include <fcntl.h>
68 #define isatty(h) _isatty(h)
69 #ifndef access
70 # define access(f,m) _access((f),(m))
71 #endif
72 #undef popen
@@ -456,10 +457,11 @@
457 int mode; /* An output mode setting */
458 int writableSchema; /* True if PRAGMA writable_schema=ON */
459 int showHeader; /* True to show column names in List or Column mode */
460 char *zDestTable; /* Name of destination table when MODE_Insert */
461 char separator[20]; /* Separator character for MODE_List */
462 char newline[20]; /* Record separator in MODE_Csv */
463 int colWidth[100]; /* Requested width of each column when in column mode*/
464 int actualWidth[100]; /* Actual width of each column */
465 char nullvalue[20]; /* The text to print when a NULL comes back from
466 ** the database */
467 struct previous_mode_data explainPrev;
@@ -657,11 +659,12 @@
659 };
660
661 /*
662 ** Output a single term of CSV. Actually, p->separator is used for
663 ** the separator, which may or may not be a comma. p->nullvalue is
664 ** the null value. Strings are quoted if necessary. The separator
665 ** is only issued if bSep is true.
666 */
667 static void output_csv(struct callback_data *p, const char *z, int bSep){
668 FILE *out = p->out;
669 if( z==0 ){
670 fprintf(out,"%s",p->nullvalue);
@@ -853,21 +856,30 @@
856 }
857 fprintf(p->out,"\n");
858 break;
859 }
860 case MODE_Csv: {
861 #if defined(WIN32) || defined(_WIN32)
862 fflush(p->out);
863 _setmode(_fileno(p->out), _O_BINARY);
864 #endif
865 if( p->cnt++==0 && p->showHeader ){
866 for(i=0; i<nArg; i++){
867 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
868 }
869 fprintf(p->out,"%s",p->newline);
870 }
871 if( azArg>0 ){
872 for(i=0; i<nArg; i++){
873 output_csv(p, azArg[i], i<nArg-1);
874 }
875 fprintf(p->out,"%s",p->newline);
876 }
877 #if defined(WIN32) || defined(_WIN32)
878 fflush(p->out);
879 _setmode(_fileno(p->out), _O_TEXT);
880 #endif
881 break;
882 }
883 case MODE_Insert: {
884 p->cnt++;
885 if( azArg==0 ) break;
@@ -1617,11 +1629,12 @@
1629 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1630 ".save FILE Write in-memory database into FILE\n"
1631 ".schema ?TABLE? Show the CREATE statements\n"
1632 " If TABLE specified, only show tables matching\n"
1633 " LIKE pattern TABLE.\n"
1634 ".separator STRING ?NL? Change separator used by output mode and .import\n"
1635 " NL is the end-of-line mark for CSV\n"
1636 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1637 ".show Show the current values for various settings\n"
1638 ".stats on|off Turn stats on or off\n"
1639 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1640 ".tables ?TABLE? List names of tables\n"
@@ -1635,10 +1648,73 @@
1648 " Negative values right-justify\n"
1649 ;
1650
1651 /* Forward reference */
1652 static int process_input(struct callback_data *p, FILE *in);
1653 /*
1654 ** Implementation of the "readfile(X)" SQL function. The entire content
1655 ** of the file named X is read and returned as a BLOB. NULL is returned
1656 ** if the file does not exist or is unreadable.
1657 */
1658 static void readfileFunc(
1659 sqlite3_context *context,
1660 int argc,
1661 sqlite3_value **argv
1662 ){
1663 const char *zName;
1664 FILE *in;
1665 long nIn;
1666 void *pBuf;
1667
1668 zName = (const char*)sqlite3_value_text(argv[0]);
1669 if( zName==0 ) return;
1670 in = fopen(zName, "rb");
1671 if( in==0 ) return;
1672 fseek(in, 0, SEEK_END);
1673 nIn = ftell(in);
1674 rewind(in);
1675 pBuf = sqlite3_malloc( nIn );
1676 if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1677 sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
1678 }else{
1679 sqlite3_free(pBuf);
1680 }
1681 fclose(in);
1682 }
1683
1684 /*
1685 ** Implementation of the "writefile(X,Y)" SQL function. The argument Y
1686 ** is written into file X. The number of bytes written is returned. Or
1687 ** NULL is returned if something goes wrong, such as being unable to open
1688 ** file X for writing.
1689 */
1690 static void writefileFunc(
1691 sqlite3_context *context,
1692 int argc,
1693 sqlite3_value **argv
1694 ){
1695 FILE *out;
1696 const char *z;
1697 int n;
1698 sqlite3_int64 rc;
1699 const char *zFile;
1700
1701 zFile = (const char*)sqlite3_value_text(argv[0]);
1702 if( zFile==0 ) return;
1703 out = fopen(zFile, "wb");
1704 if( out==0 ) return;
1705 z = (const char*)sqlite3_value_blob(argv[1]);
1706 if( z==0 ){
1707 n = 0;
1708 rc = 0;
1709 }else{
1710 n = sqlite3_value_bytes(argv[1]);
1711 rc = fwrite(z, 1, n, out);
1712 }
1713 fclose(out);
1714 sqlite3_result_int64(context, rc);
1715 }
1716
1717 /*
1718 ** Make sure the database is open. If it is not, then open it. If
1719 ** the database fails to open, print an error message and exit.
1720 */
@@ -1658,10 +1734,14 @@
1734 exit(1);
1735 }
1736 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1737 sqlite3_enable_load_extension(p->db, 1);
1738 #endif
1739 sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
1740 readfileFunc, 0, 0);
1741 sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
1742 writefileFunc, 0, 0);
1743 }
1744 }
1745
1746 /*
1747 ** Do C-language style dequoting.
@@ -2749,10 +2829,11 @@
2829 p->mode = MODE_Tcl;
2830 sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
2831 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
2832 p->mode = MODE_Csv;
2833 sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2834 sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n");
2835 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
2836 p->mode = MODE_List;
2837 sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
2838 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
2839 p->mode = MODE_Insert;
@@ -3027,17 +3108,20 @@
3108 }
3109 }else
3110 #endif
3111
3112 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3113 if( nArg<2 || nArg>3 ){
3114 fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n");
 
 
 
3115 rc = 1;
3116 }
3117 if( nArg>=2 ){
3118 sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]);
3119 }
3120 if( nArg>=3 ){
3121 sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]);
3122 }
3123 }else
3124
3125 if( c=='s'
3126 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
3127 ){
@@ -3074,10 +3158,12 @@
3158 fprintf(p->out, "\n");
3159 fprintf(p->out,"%9.9s: %s\n","output",
3160 strlen30(p->outfile) ? p->outfile : "stdout");
3161 fprintf(p->out,"%9.9s: ", "separator");
3162 output_c_string(p->out, p->separator);
3163 fprintf(p->out," ");
3164 output_c_string(p->out, p->newline);
3165 fprintf(p->out, "\n");
3166 fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
3167 fprintf(p->out,"%9.9s: ","width");
3168 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3169 fprintf(p->out,"%d ",p->colWidth[i]);
@@ -3690,10 +3776,11 @@
3776 " -list set output mode to 'list'\n"
3777 " -mmap N default mmap size set to N\n"
3778 #ifdef SQLITE_ENABLE_MULTIPLEX
3779 " -multiplex enable the multiplexor VFS\n"
3780 #endif
3781 " -newline SEP set newline character(s) for CSV\n"
3782 " -nullvalue TEXT set text string for NULL values. Default ''\n"
3783 " -separator SEP set output field separator. Default: '|'\n"
3784 " -stats print memory stats before each finalize\n"
3785 " -version show SQLite version\n"
3786 " -vfs NAME use NAME as the default VFS\n"
@@ -3719,10 +3806,11 @@
3806 */
3807 static void main_init(struct callback_data *data) {
3808 memset(data, 0, sizeof(*data));
3809 data->mode = MODE_List;
3810 memcpy(data->separator,"|", 2);
3811 memcpy(data->newline,"\r\n", 3);
3812 data->showHeader = 0;
3813 sqlite3_config(SQLITE_CONFIG_URI, 1);
3814 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
3815 sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
3816 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
@@ -3811,10 +3899,11 @@
3899 return 1;
3900 }
3901 if( z[1]=='-' ) z++;
3902 if( strcmp(z,"-separator")==0
3903 || strcmp(z,"-nullvalue")==0
3904 || strcmp(z,"-newline")==0
3905 || strcmp(z,"-cmd")==0
3906 ){
3907 (void)cmdline_option_value(argc, argv, ++i);
3908 }else if( strcmp(z,"-init")==0 ){
3909 zInitFile = cmdline_option_value(argc, argv, ++i);
@@ -3920,10 +4009,13 @@
4009 data.mode = MODE_Csv;
4010 memcpy(data.separator,",",2);
4011 }else if( strcmp(z,"-separator")==0 ){
4012 sqlite3_snprintf(sizeof(data.separator), data.separator,
4013 "%s",cmdline_option_value(argc,argv,++i));
4014 }else if( strcmp(z,"-newline")==0 ){
4015 sqlite3_snprintf(sizeof(data.newline), data.newline,
4016 "%s",cmdline_option_value(argc,argv,++i));
4017 }else if( strcmp(z,"-nullvalue")==0 ){
4018 sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
4019 "%s",cmdline_option_value(argc,argv,++i));
4020 }else if( strcmp(z,"-header")==0 ){
4021 data.showHeader = 1;
4022
+453 -259
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222222
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223223
** [sqlite_version()] and [sqlite_source_id()].
224224
*/
225225
#define SQLITE_VERSION "3.8.6"
226226
#define SQLITE_VERSION_NUMBER 3008006
227
-#define SQLITE_SOURCE_ID "2014-07-01 11:54:02 21981e35062cc6b30e9576786cbf55265a7a4d41"
227
+#define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
228228
229229
/*
230230
** CAPI3REF: Run-Time Library Version Numbers
231231
** KEYWORDS: sqlite3_version, sqlite3_sourceid
232232
**
@@ -2150,31 +2150,37 @@
21502150
SQLITE_API int sqlite3_complete16(const void *sql);
21512151
21522152
/*
21532153
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
21542154
**
2155
-** ^This routine sets a callback function that might be invoked whenever
2156
-** an attempt is made to open a database table that another thread
2157
-** or process has locked.
2155
+** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2156
+** that might be invoked with argument P whenever
2157
+** an attempt is made to access a database table associated with
2158
+** [database connection] D when another thread
2159
+** or process has the table locked.
2160
+** The sqlite3_busy_handler() interface is used to implement
2161
+** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
21582162
**
21592163
** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
21602164
** is returned immediately upon encountering the lock. ^If the busy callback
21612165
** is not NULL, then the callback might be invoked with two arguments.
21622166
**
21632167
** ^The first argument to the busy handler is a copy of the void* pointer which
21642168
** is the third argument to sqlite3_busy_handler(). ^The second argument to
21652169
** the busy handler callback is the number of times that the busy handler has
2166
-** been invoked for this locking event. ^If the
2170
+** been invoked for the same locking event. ^If the
21672171
** busy callback returns 0, then no additional attempts are made to
2168
-** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
2172
+** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned
2173
+** to the application.
21692174
** ^If the callback returns non-zero, then another attempt
2170
-** is made to open the database for reading and the cycle repeats.
2175
+** is made to access the database and the cycle repeats.
21712176
**
21722177
** The presence of a busy handler does not guarantee that it will be invoked
21732178
** when there is lock contention. ^If SQLite determines that invoking the busy
21742179
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2175
-** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
2180
+** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the
2181
+** busy handler.
21762182
** Consider a scenario where one process is holding a read lock that
21772183
** it is trying to promote to a reserved lock and
21782184
** a second process is holding a reserved lock that it is trying
21792185
** to promote to an exclusive lock. The first process cannot proceed
21802186
** because it is blocked by the second and the second process cannot
@@ -2202,14 +2208,16 @@
22022208
** this is important.
22032209
**
22042210
** ^(There can only be a single busy handler defined for each
22052211
** [database connection]. Setting a new busy handler clears any
22062212
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
2207
-** will also set or clear the busy handler.
2213
+** or evaluating [PRAGMA busy_timeout=N] will change the
2214
+** busy handler and thus clear any previously set busy handler.
22082215
**
22092216
** The busy callback should not take any actions which modify the
2210
-** database connection that invoked the busy handler. Any such actions
2217
+** database connection that invoked the busy handler. In other words,
2218
+** the busy handler is not reentrant. Any such actions
22112219
** result in undefined behavior.
22122220
**
22132221
** A busy handler must not close the database connection
22142222
** or [prepared statement] that invoked the busy handler.
22152223
*/
@@ -2230,10 +2238,12 @@
22302238
**
22312239
** ^(There can only be a single busy handler for a particular
22322240
** [database connection] any any given moment. If another busy handler
22332241
** was defined (using [sqlite3_busy_handler()]) prior to calling
22342242
** this routine, that other busy handler is cleared.)^
2243
+**
2244
+** See also: [PRAGMA busy_timeout]
22352245
*/
22362246
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
22372247
22382248
/*
22392249
** CAPI3REF: Convenience Routines For Running Queries
@@ -4818,10 +4828,17 @@
48184828
** the name of a folder (a.k.a. directory), then all temporary files
48194829
** created by SQLite when using a built-in [sqlite3_vfs | VFS]
48204830
** will be placed in that directory.)^ ^If this variable
48214831
** is a NULL pointer, then SQLite performs a search for an appropriate
48224832
** temporary file directory.
4833
+**
4834
+** Applications are strongly discouraged from using this global variable.
4835
+** It is required to set a temporary folder on Windows Runtime (WinRT).
4836
+** But for all other platforms, it is highly recommended that applications
4837
+** neither read nor write this variable. This global variable is a relic
4838
+** that exists for backwards compatibility of legacy applications and should
4839
+** be avoided in new projects.
48234840
**
48244841
** It is not safe to read or modify this variable in more than one
48254842
** thread at a time. It is not safe to read or modify this variable
48264843
** if a [database connection] is being used at the same time in a separate
48274844
** thread.
@@ -4837,10 +4854,15 @@
48374854
** [sqlite3_malloc] and the pragma may attempt to free that memory
48384855
** using [sqlite3_free].
48394856
** Hence, if this variable is modified directly, either it should be
48404857
** made NULL or made to point to memory obtained from [sqlite3_malloc]
48414858
** or else the use of the [temp_store_directory pragma] should be avoided.
4859
+** Except when requested by the [temp_store_directory pragma], SQLite
4860
+** does not free the memory that sqlite3_temp_directory points to. If
4861
+** the application wants that memory to be freed, it must do
4862
+** so itself, taking care to only do so after all [database connection]
4863
+** objects have been destroyed.
48424864
**
48434865
** <b>Note to Windows Runtime users:</b> The temporary directory must be set
48444866
** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
48454867
** features that require the use of temporary files may fail. Here is an
48464868
** example of how to do this using C++ with the Windows Runtime:
@@ -7256,10 +7278,13 @@
72567278
** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
72577279
** configured by this function.
72587280
**
72597281
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
72607282
** from SQL.
7283
+**
7284
+** ^Checkpoints initiated by this mechanism are
7285
+** [sqlite3_wal_checkpoint_v2|PASSIVE].
72617286
**
72627287
** ^Every new [database connection] defaults to having the auto-checkpoint
72637288
** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
72647289
** pages. The use of this interface
72657290
** is only necessary if the default setting is found to be suboptimal
@@ -7273,10 +7298,14 @@
72737298
** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
72747299
** on [database connection] D to be [checkpointed]. ^If X is NULL or an
72757300
** empty string, then a checkpoint is run on all databases of
72767301
** connection D. ^If the database connection D is not in
72777302
** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7303
+** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7304
+** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7305
+** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7306
+** or RESET checkpoint.
72787307
**
72797308
** ^The [wal_checkpoint pragma] can be used to invoke this interface
72807309
** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
72817310
** [wal_autocheckpoint pragma] can be used to cause this interface to be
72827311
** run whenever the WAL reaches a certain size threshold.
@@ -7295,22 +7324,25 @@
72957324
** <dl>
72967325
** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
72977326
** Checkpoint as many frames as possible without waiting for any database
72987327
** readers or writers to finish. Sync the db file if all frames in the log
72997328
** are checkpointed. This mode is the same as calling
7300
-** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked.
7329
+** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7330
+** is never invoked.
73017331
**
73027332
** <dt>SQLITE_CHECKPOINT_FULL<dd>
7303
-** This mode blocks (calls the busy-handler callback) until there is no
7333
+** This mode blocks (it invokes the
7334
+** [sqlite3_busy_handler|busy-handler callback]) until there is no
73047335
** database writer and all readers are reading from the most recent database
73057336
** snapshot. It then checkpoints all frames in the log file and syncs the
73067337
** database file. This call blocks database writers while it is running,
73077338
** but not database readers.
73087339
**
73097340
** <dt>SQLITE_CHECKPOINT_RESTART<dd>
73107341
** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7311
-** checkpointing the log file it blocks (calls the busy-handler callback)
7342
+** checkpointing the log file it blocks (calls the
7343
+** [sqlite3_busy_handler|busy-handler callback])
73127344
** until all readers are reading from the database file only. This ensures
73137345
** that the next client to write to the database file restarts the log file
73147346
** from the beginning. This call blocks database writers while it is running,
73157347
** but not database readers.
73167348
** </dl>
@@ -9285,43 +9317,43 @@
92859317
#define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */
92869318
#define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
92879319
#define OP_Count 49 /* synopsis: r[P2]=count() */
92889320
#define OP_ReadCookie 50
92899321
#define OP_SetCookie 51
9290
-#define OP_OpenRead 52 /* synopsis: root=P2 iDb=P3 */
9291
-#define OP_OpenWrite 53 /* synopsis: root=P2 iDb=P3 */
9292
-#define OP_OpenAutoindex 54 /* synopsis: nColumn=P2 */
9293
-#define OP_OpenEphemeral 55 /* synopsis: nColumn=P2 */
9294
-#define OP_SorterOpen 56
9295
-#define OP_OpenPseudo 57 /* synopsis: P3 columns in r[P2] */
9296
-#define OP_Close 58
9297
-#define OP_SeekLT 59
9298
-#define OP_SeekLE 60
9299
-#define OP_SeekGE 61
9300
-#define OP_SeekGT 62
9301
-#define OP_Seek 63 /* synopsis: intkey=r[P2] */
9302
-#define OP_NoConflict 64 /* synopsis: key=r[P3@P4] */
9303
-#define OP_NotFound 65 /* synopsis: key=r[P3@P4] */
9304
-#define OP_Found 66 /* synopsis: key=r[P3@P4] */
9305
-#define OP_NotExists 67 /* synopsis: intkey=r[P3] */
9306
-#define OP_Sequence 68 /* synopsis: r[P2]=cursor[P1].ctr++ */
9307
-#define OP_NewRowid 69 /* synopsis: r[P2]=rowid */
9308
-#define OP_Insert 70 /* synopsis: intkey=r[P3] data=r[P2] */
9322
+#define OP_ReopenIdx 52 /* synopsis: root=P2 iDb=P3 */
9323
+#define OP_OpenRead 53 /* synopsis: root=P2 iDb=P3 */
9324
+#define OP_OpenWrite 54 /* synopsis: root=P2 iDb=P3 */
9325
+#define OP_OpenAutoindex 55 /* synopsis: nColumn=P2 */
9326
+#define OP_OpenEphemeral 56 /* synopsis: nColumn=P2 */
9327
+#define OP_SorterOpen 57
9328
+#define OP_OpenPseudo 58 /* synopsis: P3 columns in r[P2] */
9329
+#define OP_Close 59
9330
+#define OP_SeekLT 60
9331
+#define OP_SeekLE 61
9332
+#define OP_SeekGE 62
9333
+#define OP_SeekGT 63
9334
+#define OP_Seek 64 /* synopsis: intkey=r[P2] */
9335
+#define OP_NoConflict 65 /* synopsis: key=r[P3@P4] */
9336
+#define OP_NotFound 66 /* synopsis: key=r[P3@P4] */
9337
+#define OP_Found 67 /* synopsis: key=r[P3@P4] */
9338
+#define OP_NotExists 68 /* synopsis: intkey=r[P3] */
9339
+#define OP_Sequence 69 /* synopsis: r[P2]=cursor[P1].ctr++ */
9340
+#define OP_NewRowid 70 /* synopsis: r[P2]=rowid */
93099341
#define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
93109342
#define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9311
-#define OP_InsertInt 73 /* synopsis: intkey=P3 data=r[P2] */
9312
-#define OP_Delete 74
9313
-#define OP_ResetCount 75
9343
+#define OP_Insert 73 /* synopsis: intkey=r[P3] data=r[P2] */
9344
+#define OP_InsertInt 74 /* synopsis: intkey=P3 data=r[P2] */
9345
+#define OP_Delete 75
93149346
#define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
93159347
#define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
93169348
#define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
93179349
#define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
93189350
#define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
93199351
#define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
93209352
#define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
93219353
#define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9322
-#define OP_SorterCompare 84 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9354
+#define OP_ResetCount 84
93239355
#define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
93249356
#define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
93259357
#define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
93269358
#define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
93279359
#define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9328,73 +9360,74 @@
93289360
#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
93299361
#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
93309362
#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
93319363
#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
93329364
#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9333
-#define OP_SorterData 95 /* synopsis: r[P2]=data */
9365
+#define OP_SorterCompare 95 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
93349366
#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
93359367
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9336
-#define OP_RowKey 98 /* synopsis: r[P2]=key */
9337
-#define OP_RowData 99 /* synopsis: r[P2]=data */
9338
-#define OP_Rowid 100 /* synopsis: r[P2]=rowid */
9339
-#define OP_NullRow 101
9340
-#define OP_Last 102
9341
-#define OP_SorterSort 103
9342
-#define OP_Sort 104
9343
-#define OP_Rewind 105
9344
-#define OP_SorterInsert 106
9345
-#define OP_IdxInsert 107 /* synopsis: key=r[P2] */
9346
-#define OP_IdxDelete 108 /* synopsis: key=r[P2@P3] */
9347
-#define OP_IdxRowid 109 /* synopsis: r[P2]=rowid */
9348
-#define OP_IdxLE 110 /* synopsis: key=r[P3@P4] */
9349
-#define OP_IdxGT 111 /* synopsis: key=r[P3@P4] */
9350
-#define OP_IdxLT 112 /* synopsis: key=r[P3@P4] */
9351
-#define OP_IdxGE 113 /* synopsis: key=r[P3@P4] */
9352
-#define OP_Destroy 114
9353
-#define OP_Clear 115
9354
-#define OP_ResetSorter 116
9355
-#define OP_CreateIndex 117 /* synopsis: r[P2]=root iDb=P1 */
9356
-#define OP_CreateTable 118 /* synopsis: r[P2]=root iDb=P1 */
9357
-#define OP_ParseSchema 119
9358
-#define OP_LoadAnalysis 120
9359
-#define OP_DropTable 121
9360
-#define OP_DropIndex 122
9361
-#define OP_DropTrigger 123
9362
-#define OP_IntegrityCk 124
9363
-#define OP_RowSetAdd 125 /* synopsis: rowset(P1)=r[P2] */
9364
-#define OP_RowSetRead 126 /* synopsis: r[P3]=rowset(P1) */
9365
-#define OP_RowSetTest 127 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9366
-#define OP_Program 128
9367
-#define OP_Param 129
9368
-#define OP_FkCounter 130 /* synopsis: fkctr[P1]+=P2 */
9369
-#define OP_FkIfZero 131 /* synopsis: if fkctr[P1]==0 goto P2 */
9370
-#define OP_MemMax 132 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9368
+#define OP_SorterData 98 /* synopsis: r[P2]=data */
9369
+#define OP_RowKey 99 /* synopsis: r[P2]=key */
9370
+#define OP_RowData 100 /* synopsis: r[P2]=data */
9371
+#define OP_Rowid 101 /* synopsis: r[P2]=rowid */
9372
+#define OP_NullRow 102
9373
+#define OP_Last 103
9374
+#define OP_SorterSort 104
9375
+#define OP_Sort 105
9376
+#define OP_Rewind 106
9377
+#define OP_SorterInsert 107
9378
+#define OP_IdxInsert 108 /* synopsis: key=r[P2] */
9379
+#define OP_IdxDelete 109 /* synopsis: key=r[P2@P3] */
9380
+#define OP_IdxRowid 110 /* synopsis: r[P2]=rowid */
9381
+#define OP_IdxLE 111 /* synopsis: key=r[P3@P4] */
9382
+#define OP_IdxGT 112 /* synopsis: key=r[P3@P4] */
9383
+#define OP_IdxLT 113 /* synopsis: key=r[P3@P4] */
9384
+#define OP_IdxGE 114 /* synopsis: key=r[P3@P4] */
9385
+#define OP_Destroy 115
9386
+#define OP_Clear 116
9387
+#define OP_ResetSorter 117
9388
+#define OP_CreateIndex 118 /* synopsis: r[P2]=root iDb=P1 */
9389
+#define OP_CreateTable 119 /* synopsis: r[P2]=root iDb=P1 */
9390
+#define OP_ParseSchema 120
9391
+#define OP_LoadAnalysis 121
9392
+#define OP_DropTable 122
9393
+#define OP_DropIndex 123
9394
+#define OP_DropTrigger 124
9395
+#define OP_IntegrityCk 125
9396
+#define OP_RowSetAdd 126 /* synopsis: rowset(P1)=r[P2] */
9397
+#define OP_RowSetRead 127 /* synopsis: r[P3]=rowset(P1) */
9398
+#define OP_RowSetTest 128 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9399
+#define OP_Program 129
9400
+#define OP_Param 130
9401
+#define OP_FkCounter 131 /* synopsis: fkctr[P1]+=P2 */
9402
+#define OP_FkIfZero 132 /* synopsis: if fkctr[P1]==0 goto P2 */
93719403
#define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9372
-#define OP_IfPos 134 /* synopsis: if r[P1]>0 goto P2 */
9373
-#define OP_IfNeg 135 /* synopsis: if r[P1]<0 goto P2 */
9374
-#define OP_IfZero 136 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9375
-#define OP_AggFinal 137 /* synopsis: accum=r[P1] N=P2 */
9376
-#define OP_IncrVacuum 138
9377
-#define OP_Expire 139
9378
-#define OP_TableLock 140 /* synopsis: iDb=P1 root=P2 write=P3 */
9379
-#define OP_VBegin 141
9380
-#define OP_VCreate 142
9404
+#define OP_MemMax 134 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9405
+#define OP_IfPos 135 /* synopsis: if r[P1]>0 goto P2 */
9406
+#define OP_IfNeg 136 /* synopsis: if r[P1]<0 goto P2 */
9407
+#define OP_IfZero 137 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9408
+#define OP_AggFinal 138 /* synopsis: accum=r[P1] N=P2 */
9409
+#define OP_IncrVacuum 139
9410
+#define OP_Expire 140
9411
+#define OP_TableLock 141 /* synopsis: iDb=P1 root=P2 write=P3 */
9412
+#define OP_VBegin 142
93819413
#define OP_ToText 143 /* same as TK_TO_TEXT */
93829414
#define OP_ToBlob 144 /* same as TK_TO_BLOB */
93839415
#define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
93849416
#define OP_ToInt 146 /* same as TK_TO_INT */
93859417
#define OP_ToReal 147 /* same as TK_TO_REAL */
9386
-#define OP_VDestroy 148
9387
-#define OP_VOpen 149
9388
-#define OP_VColumn 150 /* synopsis: r[P3]=vcolumn(P2) */
9389
-#define OP_VNext 151
9390
-#define OP_VRename 152
9391
-#define OP_Pagecount 153
9392
-#define OP_MaxPgcnt 154
9393
-#define OP_Init 155 /* synopsis: Start at P2 */
9394
-#define OP_Noop 156
9395
-#define OP_Explain 157
9418
+#define OP_VCreate 148
9419
+#define OP_VDestroy 149
9420
+#define OP_VOpen 150
9421
+#define OP_VColumn 151 /* synopsis: r[P3]=vcolumn(P2) */
9422
+#define OP_VNext 152
9423
+#define OP_VRename 153
9424
+#define OP_Pagecount 154
9425
+#define OP_MaxPgcnt 155
9426
+#define OP_Init 156 /* synopsis: Start at P2 */
9427
+#define OP_Noop 157
9428
+#define OP_Explain 158
93969429
93979430
93989431
/* Properties such as "out2" or "jump" that are specified in
93999432
** comments following the "case" for each opcode in the vdbe.c
94009433
** are encoded into bitvectors as follows:
@@ -9412,23 +9445,23 @@
94129445
/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
94139446
/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
94149447
/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
94159448
/* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\
94169449
/* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\
9417
-/* 56 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
9418
-/* 64 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c,\
9450
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\
9451
+/* 64 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x4c,\
94199452
/* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
94209453
/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
94219454
/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9422
-/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
9423
-/* 104 */ 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01,\
9424
-/* 112 */ 0x01, 0x01, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00,\
9425
-/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45, 0x15,\
9426
-/* 128 */ 0x01, 0x02, 0x00, 0x01, 0x08, 0x02, 0x05, 0x05,\
9427
-/* 136 */ 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04,\
9428
-/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x01,\
9429
-/* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9455
+/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
9456
+/* 104 */ 0x01, 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01,\
9457
+/* 112 */ 0x01, 0x01, 0x01, 0x02, 0x00, 0x00, 0x02, 0x02,\
9458
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
9459
+/* 128 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x02, 0x08, 0x05,\
9460
+/* 136 */ 0x05, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04,\
9461
+/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00,\
9462
+/* 152 */ 0x01, 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
94309463
94319464
/************** End of opcodes.h *********************************************/
94329465
/************** Continuing where we left off in vdbe.h ***********************/
94339466
94349467
/*
@@ -10932,10 +10965,13 @@
1093210965
int tnum; /* Root BTree node for this table (see note above) */
1093310966
i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
1093410967
i16 nCol; /* Number of columns in this table */
1093510968
u16 nRef; /* Number of pointers to this Table */
1093610969
LogEst szTabRow; /* Estimated size of each table row in bytes */
10970
+#ifdef SQLITE_ENABLE_COSTMULT
10971
+ LogEst costMult; /* Cost multiplier for using this table */
10972
+#endif
1093710973
u8 tabFlags; /* Mask of TF_* values */
1093810974
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
1093910975
#ifndef SQLITE_OMIT_ALTERTABLE
1094010976
int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
1094110977
#endif
@@ -11591,10 +11627,11 @@
1159111627
#define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
1159211628
#define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
1159311629
#define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
1159411630
#define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
1159511631
#define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
11632
+#define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
1159611633
1159711634
/* Allowed return values from sqlite3WhereIsDistinct()
1159811635
*/
1159911636
#define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
1160011637
#define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -11847,13 +11884,23 @@
1184711884
1184811885
/*
1184911886
** The yDbMask datatype for the bitmask of all attached databases.
1185011887
*/
1185111888
#if SQLITE_MAX_ATTACHED>30
11852
- typedef sqlite3_uint64 yDbMask;
11889
+ typedef unsigned char yDbMask[(SQLITE_MAX_ATTACHED+9)/8];
11890
+# define DbMaskTest(M,I) (((M)[(I)/8]&(1<<((I)&7)))!=0)
11891
+# define DbMaskZero(M) memset((M),0,sizeof(M))
11892
+# define DbMaskSet(M,I) (M)[(I)/8]|=(1<<((I)&7))
11893
+# define DbMaskAllZero(M) sqlite3DbMaskAllZero(M)
11894
+# define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0)
1185311895
#else
1185411896
typedef unsigned int yDbMask;
11897
+# define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
11898
+# define DbMaskZero(M) (M)=0
11899
+# define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I))
11900
+# define DbMaskAllZero(M) (M)==0
11901
+# define DbMaskNonZero(M) (M)!=0
1185511902
#endif
1185611903
1185711904
/*
1185811905
** An SQL parser context. A copy of this structure is passed through
1185911906
** the parser and down into all the parser action routine in order to
@@ -12522,10 +12569,13 @@
1252212569
SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
1252312570
#else
1252412571
# define sqlite3ViewGetColumnNames(A,B) 0
1252512572
#endif
1252612573
12574
+#if SQLITE_MAX_ATTACHED>30
12575
+SQLITE_PRIVATE int sqlite3DbMaskAllZero(yDbMask);
12576
+#endif
1252712577
SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
1252812578
SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
1252912579
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
1253012580
#ifndef SQLITE_OMIT_AUTOINCREMENT
1253112581
SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
@@ -12772,10 +12822,11 @@
1277212822
SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
1277312823
SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
1277412824
SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
1277512825
SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
1277612826
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
12827
+SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
1277712828
SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
1277812829
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
1277912830
SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
1278012831
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1278112832
@@ -13884,10 +13935,11 @@
1388413935
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1388513936
Bool isEphemeral:1; /* True for an ephemeral table */
1388613937
Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
1388713938
Bool isTable:1; /* True if a table requiring integer keys */
1388813939
Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13940
+ Pgno pgnoRoot; /* Root page of the open btree cursor */
1388913941
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1389013942
i64 seqCount; /* Sequence counter */
1389113943
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1389213944
i64 lastRowid; /* Rowid being deleted by OP_Delete */
1389313945
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -22422,13 +22474,13 @@
2242222474
testcase( c==(+1) );
2242322475
}
2242422476
return c;
2242522477
}
2242622478
22427
-
2242822479
/*
22429
-** Convert zNum to a 64-bit signed integer.
22480
+** Convert zNum to a 64-bit signed integer. zNum must be decimal. This
22481
+** routine does *not* accept hexadecimal notation.
2243022482
**
2243122483
** If the zNum value is representable as a 64-bit twos-complement
2243222484
** integer, then write that value into *pNum and return 0.
2243322485
**
2243422486
** If zNum is exactly 9223372036854775808, return 2. This special
@@ -22511,14 +22563,48 @@
2251122563
assert( u-1==LARGEST_INT64 );
2251222564
return neg ? 0 : 2;
2251322565
}
2251422566
}
2251522567
}
22568
+
22569
+/*
22570
+** Transform a UTF-8 integer literal, in either decimal or hexadecimal,
22571
+** into a 64-bit signed integer. This routine accepts hexadecimal literals,
22572
+** whereas sqlite3Atoi64() does not.
22573
+**
22574
+** Returns:
22575
+**
22576
+** 0 Successful transformation. Fits in a 64-bit signed integer.
22577
+** 1 Integer too large for a 64-bit signed integer or is malformed
22578
+** 2 Special case of 9223372036854775808
22579
+*/
22580
+SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
22581
+#ifndef SQLITE_OMIT_HEX_INTEGER
22582
+ if( z[0]=='0'
22583
+ && (z[1]=='x' || z[1]=='X')
22584
+ && sqlite3Isxdigit(z[2])
22585
+ ){
22586
+ u64 u = 0;
22587
+ int i, k;
22588
+ for(i=2; z[i]=='0'; i++){}
22589
+ for(k=i; sqlite3Isxdigit(z[k]); k++){
22590
+ u = u*16 + sqlite3HexToInt(z[k]);
22591
+ }
22592
+ memcpy(pOut, &u, 8);
22593
+ return (z[k]==0 && k-i<=16) ? 0 : 1;
22594
+ }else
22595
+#endif /* SQLITE_OMIT_HEX_INTEGER */
22596
+ {
22597
+ return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
22598
+ }
22599
+}
2251622600
2251722601
/*
2251822602
** If zNum represents an integer that will fit in 32-bits, then set
2251922603
** *pValue to that integer and return true. Otherwise return false.
22604
+**
22605
+** This routine accepts both decimal and hexadecimal notation for integers.
2252022606
**
2252122607
** Any non-numeric characters that following zNum are ignored.
2252222608
** This is different from sqlite3Atoi64() which requires the
2252322609
** input number to be zero-terminated.
2252422610
*/
@@ -22530,11 +22616,29 @@
2253022616
neg = 1;
2253122617
zNum++;
2253222618
}else if( zNum[0]=='+' ){
2253322619
zNum++;
2253422620
}
22535
- while( zNum[0]=='0' ) zNum++;
22621
+#ifndef SQLITE_OMIT_HEX_INTEGER
22622
+ else if( zNum[0]=='0'
22623
+ && (zNum[1]=='x' || zNum[1]=='X')
22624
+ && sqlite3Isxdigit(zNum[2])
22625
+ ){
22626
+ u32 u = 0;
22627
+ zNum += 2;
22628
+ while( zNum[0]=='0' ) zNum++;
22629
+ for(i=0; sqlite3Isxdigit(zNum[i]) && i<8; i++){
22630
+ u = u*16 + sqlite3HexToInt(zNum[i]);
22631
+ }
22632
+ if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){
22633
+ memcpy(pValue, &u, 4);
22634
+ return 1;
22635
+ }else{
22636
+ return 0;
22637
+ }
22638
+ }
22639
+#endif
2253622640
for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
2253722641
v = v*10 + c;
2253822642
}
2253922643
2254022644
/* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -23606,43 +23710,43 @@
2360623710
/* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
2360723711
/* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
2360823712
/* 49 */ "Count" OpHelp("r[P2]=count()"),
2360923713
/* 50 */ "ReadCookie" OpHelp(""),
2361023714
/* 51 */ "SetCookie" OpHelp(""),
23611
- /* 52 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23612
- /* 53 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23613
- /* 54 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23614
- /* 55 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23615
- /* 56 */ "SorterOpen" OpHelp(""),
23616
- /* 57 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23617
- /* 58 */ "Close" OpHelp(""),
23618
- /* 59 */ "SeekLT" OpHelp(""),
23619
- /* 60 */ "SeekLE" OpHelp(""),
23620
- /* 61 */ "SeekGE" OpHelp(""),
23621
- /* 62 */ "SeekGT" OpHelp(""),
23622
- /* 63 */ "Seek" OpHelp("intkey=r[P2]"),
23623
- /* 64 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23624
- /* 65 */ "NotFound" OpHelp("key=r[P3@P4]"),
23625
- /* 66 */ "Found" OpHelp("key=r[P3@P4]"),
23626
- /* 67 */ "NotExists" OpHelp("intkey=r[P3]"),
23627
- /* 68 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
23628
- /* 69 */ "NewRowid" OpHelp("r[P2]=rowid"),
23629
- /* 70 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23715
+ /* 52 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
23716
+ /* 53 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23717
+ /* 54 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23718
+ /* 55 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23719
+ /* 56 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23720
+ /* 57 */ "SorterOpen" OpHelp(""),
23721
+ /* 58 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23722
+ /* 59 */ "Close" OpHelp(""),
23723
+ /* 60 */ "SeekLT" OpHelp(""),
23724
+ /* 61 */ "SeekLE" OpHelp(""),
23725
+ /* 62 */ "SeekGE" OpHelp(""),
23726
+ /* 63 */ "SeekGT" OpHelp(""),
23727
+ /* 64 */ "Seek" OpHelp("intkey=r[P2]"),
23728
+ /* 65 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23729
+ /* 66 */ "NotFound" OpHelp("key=r[P3@P4]"),
23730
+ /* 67 */ "Found" OpHelp("key=r[P3@P4]"),
23731
+ /* 68 */ "NotExists" OpHelp("intkey=r[P3]"),
23732
+ /* 69 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
23733
+ /* 70 */ "NewRowid" OpHelp("r[P2]=rowid"),
2363023734
/* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
2363123735
/* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23632
- /* 73 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23633
- /* 74 */ "Delete" OpHelp(""),
23634
- /* 75 */ "ResetCount" OpHelp(""),
23736
+ /* 73 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23737
+ /* 74 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23738
+ /* 75 */ "Delete" OpHelp(""),
2363523739
/* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
2363623740
/* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
2363723741
/* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
2363823742
/* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
2363923743
/* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
2364023744
/* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
2364123745
/* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
2364223746
/* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23643
- /* 84 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23747
+ /* 84 */ "ResetCount" OpHelp(""),
2364423748
/* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
2364523749
/* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
2364623750
/* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
2364723751
/* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
2364823752
/* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23649,73 +23753,74 @@
2364923753
/* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2365023754
/* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
2365123755
/* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
2365223756
/* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2365323757
/* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23654
- /* 95 */ "SorterData" OpHelp("r[P2]=data"),
23758
+ /* 95 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
2365523759
/* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2365623760
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
23657
- /* 98 */ "RowKey" OpHelp("r[P2]=key"),
23658
- /* 99 */ "RowData" OpHelp("r[P2]=data"),
23659
- /* 100 */ "Rowid" OpHelp("r[P2]=rowid"),
23660
- /* 101 */ "NullRow" OpHelp(""),
23661
- /* 102 */ "Last" OpHelp(""),
23662
- /* 103 */ "SorterSort" OpHelp(""),
23663
- /* 104 */ "Sort" OpHelp(""),
23664
- /* 105 */ "Rewind" OpHelp(""),
23665
- /* 106 */ "SorterInsert" OpHelp(""),
23666
- /* 107 */ "IdxInsert" OpHelp("key=r[P2]"),
23667
- /* 108 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23668
- /* 109 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23669
- /* 110 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23670
- /* 111 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23671
- /* 112 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23672
- /* 113 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23673
- /* 114 */ "Destroy" OpHelp(""),
23674
- /* 115 */ "Clear" OpHelp(""),
23675
- /* 116 */ "ResetSorter" OpHelp(""),
23676
- /* 117 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23677
- /* 118 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23678
- /* 119 */ "ParseSchema" OpHelp(""),
23679
- /* 120 */ "LoadAnalysis" OpHelp(""),
23680
- /* 121 */ "DropTable" OpHelp(""),
23681
- /* 122 */ "DropIndex" OpHelp(""),
23682
- /* 123 */ "DropTrigger" OpHelp(""),
23683
- /* 124 */ "IntegrityCk" OpHelp(""),
23684
- /* 125 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23685
- /* 126 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23686
- /* 127 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23687
- /* 128 */ "Program" OpHelp(""),
23688
- /* 129 */ "Param" OpHelp(""),
23689
- /* 130 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23690
- /* 131 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23691
- /* 132 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23761
+ /* 98 */ "SorterData" OpHelp("r[P2]=data"),
23762
+ /* 99 */ "RowKey" OpHelp("r[P2]=key"),
23763
+ /* 100 */ "RowData" OpHelp("r[P2]=data"),
23764
+ /* 101 */ "Rowid" OpHelp("r[P2]=rowid"),
23765
+ /* 102 */ "NullRow" OpHelp(""),
23766
+ /* 103 */ "Last" OpHelp(""),
23767
+ /* 104 */ "SorterSort" OpHelp(""),
23768
+ /* 105 */ "Sort" OpHelp(""),
23769
+ /* 106 */ "Rewind" OpHelp(""),
23770
+ /* 107 */ "SorterInsert" OpHelp(""),
23771
+ /* 108 */ "IdxInsert" OpHelp("key=r[P2]"),
23772
+ /* 109 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23773
+ /* 110 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23774
+ /* 111 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23775
+ /* 112 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23776
+ /* 113 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23777
+ /* 114 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23778
+ /* 115 */ "Destroy" OpHelp(""),
23779
+ /* 116 */ "Clear" OpHelp(""),
23780
+ /* 117 */ "ResetSorter" OpHelp(""),
23781
+ /* 118 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23782
+ /* 119 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23783
+ /* 120 */ "ParseSchema" OpHelp(""),
23784
+ /* 121 */ "LoadAnalysis" OpHelp(""),
23785
+ /* 122 */ "DropTable" OpHelp(""),
23786
+ /* 123 */ "DropIndex" OpHelp(""),
23787
+ /* 124 */ "DropTrigger" OpHelp(""),
23788
+ /* 125 */ "IntegrityCk" OpHelp(""),
23789
+ /* 126 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23790
+ /* 127 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23791
+ /* 128 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23792
+ /* 129 */ "Program" OpHelp(""),
23793
+ /* 130 */ "Param" OpHelp(""),
23794
+ /* 131 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23795
+ /* 132 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
2369223796
/* 133 */ "Real" OpHelp("r[P2]=P4"),
23693
- /* 134 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23694
- /* 135 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23695
- /* 136 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23696
- /* 137 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23697
- /* 138 */ "IncrVacuum" OpHelp(""),
23698
- /* 139 */ "Expire" OpHelp(""),
23699
- /* 140 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23700
- /* 141 */ "VBegin" OpHelp(""),
23701
- /* 142 */ "VCreate" OpHelp(""),
23797
+ /* 134 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23798
+ /* 135 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23799
+ /* 136 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23800
+ /* 137 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23801
+ /* 138 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23802
+ /* 139 */ "IncrVacuum" OpHelp(""),
23803
+ /* 140 */ "Expire" OpHelp(""),
23804
+ /* 141 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23805
+ /* 142 */ "VBegin" OpHelp(""),
2370223806
/* 143 */ "ToText" OpHelp(""),
2370323807
/* 144 */ "ToBlob" OpHelp(""),
2370423808
/* 145 */ "ToNumeric" OpHelp(""),
2370523809
/* 146 */ "ToInt" OpHelp(""),
2370623810
/* 147 */ "ToReal" OpHelp(""),
23707
- /* 148 */ "VDestroy" OpHelp(""),
23708
- /* 149 */ "VOpen" OpHelp(""),
23709
- /* 150 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23710
- /* 151 */ "VNext" OpHelp(""),
23711
- /* 152 */ "VRename" OpHelp(""),
23712
- /* 153 */ "Pagecount" OpHelp(""),
23713
- /* 154 */ "MaxPgcnt" OpHelp(""),
23714
- /* 155 */ "Init" OpHelp("Start at P2"),
23715
- /* 156 */ "Noop" OpHelp(""),
23716
- /* 157 */ "Explain" OpHelp(""),
23811
+ /* 148 */ "VCreate" OpHelp(""),
23812
+ /* 149 */ "VDestroy" OpHelp(""),
23813
+ /* 150 */ "VOpen" OpHelp(""),
23814
+ /* 151 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23815
+ /* 152 */ "VNext" OpHelp(""),
23816
+ /* 153 */ "VRename" OpHelp(""),
23817
+ /* 154 */ "Pagecount" OpHelp(""),
23818
+ /* 155 */ "MaxPgcnt" OpHelp(""),
23819
+ /* 156 */ "Init" OpHelp("Start at P2"),
23820
+ /* 157 */ "Noop" OpHelp(""),
23821
+ /* 158 */ "Explain" OpHelp(""),
2371723822
};
2371823823
return azName[i];
2371923824
}
2372023825
#endif
2372123826
@@ -62343,11 +62448,11 @@
6234362448
}
6234462449
sqlite3DbFree(p->db, pParse->aLabel);
6234562450
pParse->aLabel = 0;
6234662451
pParse->nLabel = 0;
6234762452
*pMaxFuncArgs = nMaxArgs;
62348
- assert( p->bIsReader!=0 || p->btreeMask==0 );
62453
+ assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
6234962454
}
6235062455
6235162456
/*
6235262457
** Return the address of the next instruction to be inserted.
6235362458
*/
@@ -62370,11 +62475,11 @@
6237062475
SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe *p, int *pnOp, int *pnMaxArg){
6237162476
VdbeOp *aOp = p->aOp;
6237262477
assert( aOp && !p->db->mallocFailed );
6237362478
6237462479
/* Check that sqlite3VdbeUsesBtree() was not called on this VM */
62375
- assert( p->btreeMask==0 );
62480
+ assert( DbMaskAllZero(p->btreeMask) );
6237662481
6237762482
resolveP2Values(p, pnMaxArg);
6237862483
*pnOp = p->nOp;
6237962484
p->aOp = 0;
6238062485
return aOp;
@@ -62955,13 +63060,13 @@
6295563060
** p->btreeMask of databases that will require a lock.
6295663061
*/
6295763062
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
6295863063
assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
6295963064
assert( i<(int)sizeof(p->btreeMask)*8 );
62960
- p->btreeMask |= ((yDbMask)1)<<i;
63065
+ DbMaskSet(p->btreeMask, i);
6296163066
if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
62962
- p->lockMask |= ((yDbMask)1)<<i;
63067
+ DbMaskSet(p->lockMask, i);
6296363068
}
6296463069
}
6296563070
6296663071
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
6296763072
/*
@@ -62985,20 +63090,19 @@
6298563090
** this routine is N*N. But as N is rarely more than 1, this should not
6298663091
** be a problem.
6298763092
*/
6298863093
SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){
6298963094
int i;
62990
- yDbMask mask;
6299163095
sqlite3 *db;
6299263096
Db *aDb;
6299363097
int nDb;
62994
- if( p->lockMask==0 ) return; /* The common case */
63098
+ if( DbMaskAllZero(p->lockMask) ) return; /* The common case */
6299563099
db = p->db;
6299663100
aDb = db->aDb;
6299763101
nDb = db->nDb;
62998
- for(i=0, mask=1; i<nDb; i++, mask += mask){
62999
- if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
63102
+ for(i=0; i<nDb; i++){
63103
+ if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
6300063104
sqlite3BtreeEnter(aDb[i].pBt);
6300163105
}
6300263106
}
6300363107
}
6300463108
#endif
@@ -63007,20 +63111,19 @@
6300763111
/*
6300863112
** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
6300963113
*/
6301063114
SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){
6301163115
int i;
63012
- yDbMask mask;
6301363116
sqlite3 *db;
6301463117
Db *aDb;
6301563118
int nDb;
63016
- if( p->lockMask==0 ) return; /* The common case */
63119
+ if( DbMaskAllZero(p->lockMask) ) return; /* The common case */
6301763120
db = p->db;
6301863121
aDb = db->aDb;
6301963122
nDb = db->nDb;
63020
- for(i=0, mask=1; i<nDb; i++, mask += mask){
63021
- if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
63123
+ for(i=0; i<nDb; i++){
63124
+ if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
6302263125
sqlite3BtreeLeave(aDb[i].pBt);
6302363126
}
6302463127
}
6302563128
}
6302663129
#endif
@@ -63987,11 +64090,11 @@
6398764090
int cnt = 0;
6398864091
int nWrite = 0;
6398964092
int nRead = 0;
6399064093
p = db->pVdbe;
6399164094
while( p ){
63992
- if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){
64095
+ if( sqlite3_stmt_busy((sqlite3_stmt*)p) ){
6399364096
cnt++;
6399464097
if( p->readOnly==0 ) nWrite++;
6399564098
if( p->bIsReader ) nRead++;
6399664099
}
6399764100
p = p->pNext;
@@ -67184,11 +67287,11 @@
6718467287
/*
6718567288
** Return true if the prepared statement is in need of being reset.
6718667289
*/
6718767290
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
6718867291
Vdbe *v = (Vdbe*)pStmt;
67189
- return v!=0 && v->pc>0 && v->magic==VDBE_MAGIC_RUN;
67292
+ return v!=0 && v->pc>=0 && v->magic==VDBE_MAGIC_RUN;
6719067293
}
6719167294
6719267295
/*
6719367296
** Return a pointer to the next prepared statement after pStmt associated
6719467297
** with database connection pDb. If pStmt is NULL, return the first
@@ -70641,11 +70744,11 @@
7064170744
int iGen;
7064270745
7064370746
assert( p->bIsReader );
7064470747
assert( p->readOnly==0 || pOp->p2==0 );
7064570748
assert( pOp->p1>=0 && pOp->p1<db->nDb );
70646
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70749
+ assert( DbMaskTest(p->btreeMask, pOp->p1) );
7064770750
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
7064870751
rc = SQLITE_READONLY;
7064970752
goto abort_due_to_error;
7065070753
}
7065170754
pBt = db->aDb[pOp->p1].pBt;
@@ -70736,11 +70839,11 @@
7073670839
iDb = pOp->p1;
7073770840
iCookie = pOp->p3;
7073870841
assert( pOp->p3<SQLITE_N_BTREE_META );
7073970842
assert( iDb>=0 && iDb<db->nDb );
7074070843
assert( db->aDb[iDb].pBt!=0 );
70741
- assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
70844
+ assert( DbMaskTest(p->btreeMask, iDb) );
7074270845
7074370846
sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
7074470847
pOut->u.i = iMeta;
7074570848
break;
7074670849
}
@@ -70757,11 +70860,11 @@
7075770860
*/
7075870861
case OP_SetCookie: { /* in3 */
7075970862
Db *pDb;
7076070863
assert( pOp->p2<SQLITE_N_BTREE_META );
7076170864
assert( pOp->p1>=0 && pOp->p1<db->nDb );
70762
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70865
+ assert( DbMaskTest(p->btreeMask, pOp->p1) );
7076370866
assert( p->readOnly==0 );
7076470867
pDb = &db->aDb[pOp->p1];
7076570868
assert( pDb->pBt!=0 );
7076670869
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
7076770870
pIn3 = &aMem[pOp->p3];
@@ -70812,11 +70915,25 @@
7081270915
** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
7081370916
** structure, then said structure defines the content and collating
7081470917
** sequence of the index being opened. Otherwise, if P4 is an integer
7081570918
** value, it is set to the number of columns in the table.
7081670919
**
70817
-** See also OpenWrite.
70920
+** See also: OpenWrite, ReopenIdx
70921
+*/
70922
+/* Opcode: ReopenIdx P1 P2 P3 P4 P5
70923
+** Synopsis: root=P2 iDb=P3
70924
+**
70925
+** The ReopenIdx opcode works exactly like ReadOpen except that it first
70926
+** checks to see if the cursor on P1 is already open with a root page
70927
+** number of P2 and if it is this opcode becomes a no-op. In other words,
70928
+** if the cursor is already open, do not reopen it.
70929
+**
70930
+** The ReopenIdx opcode may only be used with P5==0 and with P4 being
70931
+** a P4_KEYINFO object. Furthermore, the P3 value must be the same as
70932
+** every other ReopenIdx or OpenRead for the same cursor number.
70933
+**
70934
+** See the OpenRead opcode documentation for additional information.
7081870935
*/
7081970936
/* Opcode: OpenWrite P1 P2 P3 P4 P5
7082070937
** Synopsis: root=P2 iDb=P3
7082170938
**
7082270939
** Open a read/write cursor named P1 on the table or index whose root
@@ -70834,10 +70951,23 @@
7083470951
** in read/write mode. For a given table, there can be one or more read-only
7083570952
** cursors or a single read/write cursor but not both.
7083670953
**
7083770954
** See also OpenRead.
7083870955
*/
70956
+case OP_ReopenIdx: {
70957
+ VdbeCursor *pCur;
70958
+
70959
+ assert( pOp->p5==0 );
70960
+ assert( pOp->p4type==P4_KEYINFO );
70961
+ pCur = p->apCsr[pOp->p1];
70962
+ if( pCur && pCur->pgnoRoot==pOp->p2 ){
70963
+ assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
70964
+ break;
70965
+ }
70966
+ /* If the cursor is not currently open or is open on a different
70967
+ ** index, then fall through into OP_OpenRead to force a reopen */
70968
+}
7083970969
case OP_OpenRead:
7084070970
case OP_OpenWrite: {
7084170971
int nField;
7084270972
KeyInfo *pKeyInfo;
7084370973
int p2;
@@ -70848,11 +70978,12 @@
7084870978
Db *pDb;
7084970979
7085070980
assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
7085170981
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
7085270982
assert( p->bIsReader );
70853
- assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
70983
+ assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
70984
+ || p->readOnly==0 );
7085470985
7085570986
if( p->expired ){
7085670987
rc = SQLITE_ABORT;
7085770988
break;
7085870989
}
@@ -70860,11 +70991,11 @@
7086070991
nField = 0;
7086170992
pKeyInfo = 0;
7086270993
p2 = pOp->p2;
7086370994
iDb = pOp->p3;
7086470995
assert( iDb>=0 && iDb<db->nDb );
70865
- assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
70996
+ assert( DbMaskTest(p->btreeMask, iDb) );
7086670997
pDb = &db->aDb[iDb];
7086770998
pX = pDb->pBt;
7086870999
assert( pX!=0 );
7086971000
if( pOp->opcode==OP_OpenWrite ){
7087071001
wrFlag = 1;
@@ -70905,10 +71036,11 @@
7090571036
testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
7090671037
pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
7090771038
if( pCur==0 ) goto no_mem;
7090871039
pCur->nullRow = 1;
7090971040
pCur->isOrdered = 1;
71041
+ pCur->pgnoRoot = p2;
7091071042
rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
7091171043
pCur->pKeyInfo = pKeyInfo;
7091271044
assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
7091371045
sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
7091471046
@@ -72451,11 +72583,11 @@
7245172583
rc = SQLITE_LOCKED;
7245272584
p->errorAction = OE_Abort;
7245372585
}else{
7245472586
iDb = pOp->p3;
7245572587
assert( iCnt==1 );
72456
- assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
72588
+ assert( DbMaskTest(p->btreeMask, iDb) );
7245772589
iMoved = 0; /* Not needed. Only to silence a warning. */
7245872590
rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
7245972591
pOut->flags = MEM_Int;
7246072592
pOut->u.i = iMoved;
7246172593
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -72491,11 +72623,11 @@
7249172623
case OP_Clear: {
7249272624
int nChange;
7249372625
7249472626
nChange = 0;
7249572627
assert( p->readOnly==0 );
72496
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
72628
+ assert( DbMaskTest(p->btreeMask, pOp->p2) );
7249772629
rc = sqlite3BtreeClearTable(
7249872630
db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
7249972631
);
7250072632
if( pOp->p3 ){
7250172633
p->nChange += nChange;
@@ -72561,11 +72693,11 @@
7256172693
int flags;
7256272694
Db *pDb;
7256372695
7256472696
pgno = 0;
7256572697
assert( pOp->p1>=0 && pOp->p1<db->nDb );
72566
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72698
+ assert( DbMaskTest(p->btreeMask, pOp->p1) );
7256772699
assert( p->readOnly==0 );
7256872700
pDb = &db->aDb[pOp->p1];
7256972701
assert( pDb->pBt!=0 );
7257072702
if( pOp->opcode==OP_CreateTable ){
7257172703
/* flags = BTREE_INTKEY; */
@@ -72726,11 +72858,11 @@
7272672858
for(j=0; j<nRoot; j++){
7272772859
aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
7272872860
}
7272972861
aRoot[j] = 0;
7273072862
assert( pOp->p5<db->nDb );
72731
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
72863
+ assert( DbMaskTest(p->btreeMask, pOp->p5) );
7273272864
z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
7273372865
(int)pnErr->u.i, &nErr);
7273472866
sqlite3DbFree(db, aRoot);
7273572867
pnErr->u.i -= nErr;
7273672868
sqlite3VdbeMemSetNull(pIn1);
@@ -73386,11 +73518,11 @@
7338673518
*/
7338773519
case OP_IncrVacuum: { /* jump */
7338873520
Btree *pBt;
7338973521
7339073522
assert( pOp->p1>=0 && pOp->p1<db->nDb );
73391
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
73523
+ assert( DbMaskTest(p->btreeMask, pOp->p1) );
7339273524
assert( p->readOnly==0 );
7339373525
pBt = db->aDb[pOp->p1].pBt;
7339473526
rc = sqlite3BtreeIncrVacuum(pBt);
7339573527
VdbeBranchTaken(rc==SQLITE_DONE,2);
7339673528
if( rc==SQLITE_DONE ){
@@ -73401,16 +73533,17 @@
7340173533
}
7340273534
#endif
7340373535
7340473536
/* Opcode: Expire P1 * * * *
7340573537
**
73406
-** Cause precompiled statements to become expired. An expired statement
73407
-** fails with an error code of SQLITE_SCHEMA if it is ever executed
73408
-** (via sqlite3_step()).
73538
+** Cause precompiled statements to expire. When an expired statement
73539
+** is executed using sqlite3_step() it will either automatically
73540
+** reprepare itself (if it was originally created using sqlite3_prepare_v2())
73541
+** or it will fail with SQLITE_SCHEMA.
7340973542
**
7341073543
** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
73411
-** then only the currently executing statement is affected.
73544
+** then only the currently executing statement is expired.
7341273545
*/
7341373546
case OP_Expire: {
7341473547
if( !pOp->p1 ){
7341573548
sqlite3ExpirePreparedStatements(db);
7341673549
}else{
@@ -73438,11 +73571,11 @@
7343873571
case OP_TableLock: {
7343973572
u8 isWriteLock = (u8)pOp->p3;
7344073573
if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
7344173574
int p1 = pOp->p1;
7344273575
assert( p1>=0 && p1<db->nDb );
73443
- assert( (p->btreeMask & (((yDbMask)1)<<p1))!=0 );
73576
+ assert( DbMaskTest(p->btreeMask, p1) );
7344473577
assert( isWriteLock==0 || isWriteLock==1 );
7344573578
rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
7344673579
if( (rc&0xFF)==SQLITE_LOCKED ){
7344773580
const char *z = pOp->p4.z;
7344873581
sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
@@ -73888,11 +74021,11 @@
7388874021
#ifdef SQLITE_USE_FCNTL_TRACE
7388974022
zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
7389074023
if( zTrace ){
7389174024
int i;
7389274025
for(i=0; i<db->nDb; i++){
73893
- if( (MASKBIT(i) & p->btreeMask)==0 ) continue;
74026
+ if( DbMaskTest(p->btreeMask, i)==0 ) continue;
7389474027
sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
7389574028
}
7389674029
}
7389774030
#endif /* SQLITE_USE_FCNTL_TRACE */
7389874031
#ifdef SQLITE_DEBUG
@@ -79792,21 +79925,28 @@
7979279925
}else{
7979379926
int c;
7979479927
i64 value;
7979579928
const char *z = pExpr->u.zToken;
7979679929
assert( z!=0 );
79797
- c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
79930
+ c = sqlite3DecOrHexToI64(z, &value);
7979879931
if( c==0 || (c==2 && negFlag) ){
7979979932
char *zV;
7980079933
if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
7980179934
zV = dup8bytes(v, (char*)&value);
7980279935
sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
7980379936
}else{
7980479937
#ifdef SQLITE_OMIT_FLOATING_POINT
7980579938
sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
7980679939
#else
79807
- codeReal(v, z, negFlag, iMem);
79940
+#ifndef SQLITE_OMIT_HEX_INTEGER
79941
+ if( sqlite3_strnicmp(z,"0x",2)==0 ){
79942
+ sqlite3ErrorMsg(pParse, "hex literal too big: %s", z);
79943
+ }else
79944
+#endif
79945
+ {
79946
+ codeReal(v, z, negFlag, iMem);
79947
+ }
7980879948
#endif
7980979949
}
7981079950
}
7981179951
}
7981279952
@@ -83913,20 +84053,20 @@
8391384053
** ...
8391484054
** regChng = N
8391584055
** goto chng_addr_N
8391684056
*/
8391784057
addrNextRow = sqlite3VdbeCurrentAddr(v);
83918
- for(i=0; i<nCol; i++){
84058
+ for(i=0; i<nCol-1; i++){
8391984059
char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
8392084060
sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
8392184061
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
8392284062
aGotoChng[i] =
8392384063
sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
8392484064
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
8392584065
VdbeCoverage(v);
8392684066
}
83927
- sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
84067
+ sqlite3VdbeAddOp2(v, OP_Integer, nCol-1, regChng);
8392884068
aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
8392984069
8393084070
/*
8393184071
** chng_addr_0:
8393284072
** regPrev(0) = idx(0)
@@ -83933,11 +84073,11 @@
8393384073
** chng_addr_1:
8393484074
** regPrev(1) = idx(1)
8393584075
** ...
8393684076
*/
8393784077
sqlite3VdbeJumpHere(v, addrGotoChng0);
83938
- for(i=0; i<nCol; i++){
84078
+ for(i=0; i<nCol-1; i++){
8393984079
sqlite3VdbeJumpHere(v, aGotoChng[i]);
8394084080
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
8394184081
}
8394284082
8394384083
/*
@@ -84124,10 +84264,11 @@
8412484264
int i;
8412584265
char *z, *zDb;
8412684266
Table *pTab;
8412784267
Index *pIdx;
8412884268
Token *pTableName;
84269
+ Vdbe *v;
8412984270
8413084271
/* Read the database schema. If an error occurs, leave an error message
8413184272
** and code in pParse and return NULL. */
8413284273
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
8413384274
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
@@ -84171,10 +84312,12 @@
8417184312
}
8417284313
sqlite3DbFree(db, z);
8417384314
}
8417484315
}
8417584316
}
84317
+ v = sqlite3GetVdbe(pParse);
84318
+ if( v ) sqlite3VdbeAddOp0(v, OP_Expire);
8417684319
}
8417784320
8417884321
/*
8417984322
** Used to pass information from the analyzer reader through to the
8418084323
** callback routine.
@@ -84229,18 +84372,23 @@
8422984372
#ifndef SQLITE_ENABLE_STAT3_OR_STAT4
8423084373
assert( pIndex!=0 );
8423184374
#else
8423284375
if( pIndex )
8423384376
#endif
84234
- {
84235
- if( strcmp(z, "unordered")==0 ){
84377
+ while( z[0] ){
84378
+ if( sqlite3_strglob("unordered*", z)==0 ){
8423684379
pIndex->bUnordered = 1;
8423784380
}else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
84238
- int v32 = 0;
84239
- sqlite3GetInt32(z+3, &v32);
84240
- pIndex->szIdxRow = sqlite3LogEst(v32);
84381
+ pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3));
8424184382
}
84383
+#ifdef SQLITE_ENABLE_COSTMULT
84384
+ else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
84385
+ pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9));
84386
+ }
84387
+#endif
84388
+ while( z[0]!=0 && z[0]!=' ' ) z++;
84389
+ while( z[0]==' ' ) z++;
8424284390
}
8424384391
}
8424484392
8424584393
/*
8424684394
** This callback is invoked once for each index when reading the
@@ -84277,15 +84425,19 @@
8427784425
pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8427884426
}
8427984427
z = argv[2];
8428084428
8428184429
if( pIndex ){
84430
+ pIndex->bUnordered = 0;
8428284431
decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
8428384432
if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
8428484433
}else{
8428584434
Index fakeIdx;
8428684435
fakeIdx.szIdxRow = pTable->szTabRow;
84436
+#ifdef SQLITE_ENABLE_COSTMULT
84437
+ fakeIdx.pTable = pTable;
84438
+#endif
8428784439
decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
8428884440
pTable->szTabRow = fakeIdx.szIdxRow;
8428984441
}
8429084442
8429184443
return 0;
@@ -85557,10 +85709,23 @@
8555785709
}
8555885710
#else
8555985711
#define codeTableLocks(x)
8556085712
#endif
8556185713
85714
+/*
85715
+** Return TRUE if the given yDbMask object is empty - if it contains no
85716
+** 1 bits. This routine is used by the DbMaskAllZero() and DbMaskNotZero()
85717
+** macros when SQLITE_MAX_ATTACHED is greater than 30.
85718
+*/
85719
+#if SQLITE_MAX_ATTACHED>30
85720
+SQLITE_PRIVATE int sqlite3DbMaskAllZero(yDbMask m){
85721
+ int i;
85722
+ for(i=0; i<sizeof(yDbMask); i++) if( m[i] ) return 0;
85723
+ return 1;
85724
+}
85725
+#endif
85726
+
8556285727
/*
8556385728
** This routine is called after a single SQL statement has been
8556485729
** parsed and a VDBE program to execute that statement has been
8556585730
** prepared. This routine puts the finishing touches on the
8556685731
** VDBE program and resets the pParse structure for the next
@@ -85593,22 +85758,23 @@
8559385758
** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
8559485759
** set for each database that is used. Generate code to start a
8559585760
** transaction on each used database and to verify the schema cookie
8559685761
** on each used database.
8559785762
*/
85598
- if( db->mallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){
85599
- yDbMask mask;
85763
+ if( db->mallocFailed==0
85764
+ && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
85765
+ ){
8560085766
int iDb, i;
8560185767
assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
8560285768
sqlite3VdbeJumpHere(v, 0);
85603
- for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
85604
- if( (mask & pParse->cookieMask)==0 ) continue;
85769
+ for(iDb=0; iDb<db->nDb; iDb++){
85770
+ if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
8560585771
sqlite3VdbeUsesBtree(v, iDb);
8560685772
sqlite3VdbeAddOp4Int(v,
8560785773
OP_Transaction, /* Opcode */
8560885774
iDb, /* P1 */
85609
- (mask & pParse->writeMask)!=0, /* P2 */
85775
+ DbMaskTest(pParse->writeMask,iDb), /* P2 */
8561085776
pParse->cookieValue[iDb], /* P3 */
8561185777
db->aDb[iDb].pSchema->iGeneration /* P4 */
8561285778
);
8561385779
if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
8561485780
}
@@ -85660,11 +85826,11 @@
8566085826
}
8566185827
pParse->nTab = 0;
8566285828
pParse->nMem = 0;
8566385829
pParse->nSet = 0;
8566485830
pParse->nVar = 0;
85665
- pParse->cookieMask = 0;
85831
+ DbMaskZero(pParse->cookieMask);
8566685832
}
8566785833
8566885834
/*
8566985835
** Run the parser and code generator recursively in order to generate
8567085836
** code for the SQL statement given onto the end of the pParse context
@@ -89287,19 +89453,17 @@
8928789453
** later, by sqlite3FinishCoding().
8928889454
*/
8928989455
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
8929089456
Parse *pToplevel = sqlite3ParseToplevel(pParse);
8929189457
sqlite3 *db = pToplevel->db;
89292
- yDbMask mask;
8929389458
8929489459
assert( iDb>=0 && iDb<db->nDb );
8929589460
assert( db->aDb[iDb].pBt!=0 || iDb==1 );
8929689461
assert( iDb<SQLITE_MAX_ATTACHED+2 );
8929789462
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
89298
- mask = ((yDbMask)1)<<iDb;
89299
- if( (pToplevel->cookieMask & mask)==0 ){
89300
- pToplevel->cookieMask |= mask;
89463
+ if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
89464
+ DbMaskSet(pToplevel->cookieMask, iDb);
8930189465
pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
8930289466
if( !OMIT_TEMPDB && iDb==1 ){
8930389467
sqlite3OpenTempDatabase(pToplevel);
8930489468
}
8930589469
}
@@ -89334,11 +89498,11 @@
8933489498
** necessary to undo a write and the checkpoint should not be set.
8933589499
*/
8933689500
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
8933789501
Parse *pToplevel = sqlite3ParseToplevel(pParse);
8933889502
sqlite3CodeVerifySchema(pParse, iDb);
89339
- pToplevel->writeMask |= ((yDbMask)1)<<iDb;
89503
+ DbMaskSet(pToplevel->writeMask, iDb);
8934089504
pToplevel->isMultiWrite |= setStatement;
8934189505
}
8934289506
8934389507
/*
8934489508
** Indicate that the statement currently under construction might write
@@ -98590,11 +98754,11 @@
9859098754
*/
9859198755
case PragTyp_JOURNAL_SIZE_LIMIT: {
9859298756
Pager *pPager = sqlite3BtreePager(pDb->pBt);
9859398757
i64 iLimit = -2;
9859498758
if( zRight ){
98595
- sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8);
98759
+ sqlite3DecOrHexToI64(zRight, &iLimit);
9859698760
if( iLimit<-1 ) iLimit = -1;
9859798761
}
9859898762
iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
9859998763
returnSingleInt(pParse, "journal_size_limit", iLimit);
9860098764
break;
@@ -98718,11 +98882,11 @@
9871898882
sqlite3_int64 sz;
9871998883
#if SQLITE_MAX_MMAP_SIZE>0
9872098884
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9872198885
if( zRight ){
9872298886
int ii;
98723
- sqlite3Atoi64(zRight, &sz, sqlite3Strlen30(zRight), SQLITE_UTF8);
98887
+ sqlite3DecOrHexToI64(zRight, &sz);
9872498888
if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
9872598889
if( pId2->n==0 ) db->szMmap = sz;
9872698890
for(ii=db->nDb-1; ii>=0; ii--){
9872798891
if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
9872898892
sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
@@ -99761,11 +99925,11 @@
9976199925
** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
9976299926
** use -1.
9976399927
*/
9976499928
case PragTyp_SOFT_HEAP_LIMIT: {
9976599929
sqlite3_int64 N;
99766
- if( zRight && sqlite3Atoi64(zRight, &N, 1000000, SQLITE_UTF8)==SQLITE_OK ){
99930
+ if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
9976799931
sqlite3_soft_heap_limit64(N);
9976899932
}
9976999933
returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
9977099934
break;
9977199935
}
@@ -113609,10 +113773,11 @@
113609113773
int regRowid = 0; /* Register holding rowid */
113610113774
int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
113611113775
int iRetInit; /* Address of regReturn init */
113612113776
int untestedTerms = 0; /* Some terms not completely tested */
113613113777
int ii; /* Loop counter */
113778
+ u16 wctrlFlags; /* Flags for sub-WHERE clause */
113614113779
Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
113615113780
Table *pTab = pTabItem->pTab;
113616113781
113617113782
pTerm = pLoop->aLTerm[0];
113618113783
assert( pTerm!=0 );
@@ -113704,10 +113869,12 @@
113704113869
113705113870
/* Run a separate WHERE clause for each term of the OR clause. After
113706113871
** eliminating duplicates from other WHERE clauses, the action for each
113707113872
** sub-WHERE clause is to to invoke the main loop body as a subroutine.
113708113873
*/
113874
+ wctrlFlags = WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
113875
+ WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY;
113709113876
for(ii=0; ii<pOrWc->nTerm; ii++){
113710113877
WhereTerm *pOrTerm = &pOrWc->a[ii];
113711113878
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
113712113879
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
113713113880
Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -113716,12 +113883,11 @@
113716113883
pAndExpr->pLeft = pOrExpr;
113717113884
pOrExpr = pAndExpr;
113718113885
}
113719113886
/* Loop through table entries that match term pOrTerm. */
113720113887
pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
113721
- WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
113722
- WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur);
113888
+ wctrlFlags, iCovCur);
113723113889
assert( pSubWInfo || pParse->nErr || db->mallocFailed );
113724113890
if( pSubWInfo ){
113725113891
WhereLoop *pSubLoop;
113726113892
explainOneScan(
113727113893
pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
@@ -113808,10 +113974,11 @@
113808113974
&& (ii==0 || pSubLoop->u.btree.pIndex==pCov)
113809113975
&& (HasRowid(pTab) || !IsPrimaryKeyIndex(pSubLoop->u.btree.pIndex))
113810113976
){
113811113977
assert( pSubWInfo->a[0].iIdxCur==iCovCur );
113812113978
pCov = pSubLoop->u.btree.pIndex;
113979
+ wctrlFlags |= WHERE_REOPEN_IDX;
113813113980
}else{
113814113981
pCov = 0;
113815113982
}
113816113983
113817113984
/* Finish the loop through table entries that match term pOrTerm. */
@@ -114414,10 +114581,20 @@
114414114581
pLoop->nOut += (pTerm->truthProb<=0 ? pTerm->truthProb : -1);
114415114582
}
114416114583
}
114417114584
}
114418114585
114586
+/*
114587
+** Adjust the cost C by the costMult facter T. This only occurs if
114588
+** compiled with -DSQLITE_ENABLE_COSTMULT
114589
+*/
114590
+#ifdef SQLITE_ENABLE_COSTMULT
114591
+# define ApplyCostMultiplier(C,T) C += T
114592
+#else
114593
+# define ApplyCostMultiplier(C,T)
114594
+#endif
114595
+
114419114596
/*
114420114597
** We have so far matched pBuilder->pNew->u.btree.nEq terms of the
114421114598
** index pIndex. Try to match one more.
114422114599
**
114423114600
** When this function is called, pBuilder->pNew->nOut contains the
@@ -114610,11 +114787,10 @@
114610114787
testcase( eOp & WO_ISNULL );
114611114788
rc = whereEqualScanEst(pParse, pBuilder, pExpr->pRight, &nOut);
114612114789
}else{
114613114790
rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut);
114614114791
}
114615
- assert( rc!=SQLITE_OK || nOut>0 );
114616114792
if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
114617114793
if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */
114618114794
if( nOut ){
114619114795
pNew->nOut = sqlite3LogEst(nOut);
114620114796
if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut;
@@ -114642,10 +114818,11 @@
114642114818
rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
114643114819
pNew->rRun = sqlite3LogEstAdd(rLogSize, rCostIdx);
114644114820
if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){
114645114821
pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut + 16);
114646114822
}
114823
+ ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult);
114647114824
114648114825
nOutUnadjusted = pNew->nOut;
114649114826
pNew->rRun += nInMul + nIn;
114650114827
pNew->nOut += nInMul + nIn;
114651114828
whereLoopOutputAdjust(pBuilder->pWC, pNew);
@@ -114761,10 +114938,18 @@
114761114938
** cost = nSeek * (log(nRow) + (K+3.0) * nVisit) // non-covering index
114762114939
**
114763114940
** Normally, nSeek is 1. nSeek values greater than 1 come about if the
114764114941
** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
114765114942
** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
114943
+**
114944
+** The estimated values (nRow, nVisit, nSeek) often contain a large amount
114945
+** of uncertainty. For this reason, scoring is designed to pick plans that
114946
+** "do the least harm" if the estimates are inaccurate. For example, a
114947
+** log(nRow) factor is omitted from a non-covering index scan in order to
114948
+** bias the scoring in favor of using an index, since the worst-case
114949
+** performance of using an index is far better than the worst-case performance
114950
+** of a full table scan.
114766114951
*/
114767114952
static int whereLoopAddBtree(
114768114953
WhereLoopBuilder *pBuilder, /* WHERE clause information */
114769114954
Bitmask mExtra /* Extra prerequesites for using this table */
114770114955
){
@@ -114848,10 +115033,11 @@
114848115033
pNew->aLTerm[0] = pTerm;
114849115034
/* TUNING: One-time cost for computing the automatic index is
114850115035
** approximately 7*N*log2(N) where N is the number of rows in
114851115036
** the table being indexed. */
114852115037
pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
115038
+ ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
114853115039
/* TUNING: Each index lookup yields 20 rows in the table. This
114854115040
** is more than the usual guess of 10 rows, since we have no way
114855115041
** of knowning how selective the index will ultimately be. It would
114856115042
** not be unreasonable to make this value much larger. */
114857115043
pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
@@ -114889,10 +115075,11 @@
114889115075
114890115076
/* Full table scan */
114891115077
pNew->iSortIdx = b ? iSortIdx : 0;
114892115078
/* TUNING: Cost of full table scan is (N*3.0). */
114893115079
pNew->rRun = rSize + 16;
115080
+ ApplyCostMultiplier(pNew->rRun, pTab->costMult);
114894115081
whereLoopOutputAdjust(pWC, pNew);
114895115082
rc = whereLoopInsert(pBuilder, pNew);
114896115083
pNew->nOut = rSize;
114897115084
if( rc ) break;
114898115085
}else{
@@ -114924,11 +115111,11 @@
114924115111
** also add the cost of visiting table rows (N*3.0). */
114925115112
pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow;
114926115113
if( m!=0 ){
114927115114
pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16);
114928115115
}
114929
-
115116
+ ApplyCostMultiplier(pNew->rRun, pTab->costMult);
114930115117
whereLoopOutputAdjust(pWC, pNew);
114931115118
rc = whereLoopInsert(pBuilder, pNew);
114932115119
pNew->nOut = rSize;
114933115120
if( rc ) break;
114934115121
}
@@ -116399,10 +116586,11 @@
116399116586
}
116400116587
op = OP_OpenWrite;
116401116588
pWInfo->aiCurOnePass[1] = iIndexCur;
116402116589
}else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){
116403116590
iIndexCur = iIdxCur;
116591
+ if( wctrlFlags & WHERE_REOPEN_IDX ) op = OP_ReopenIdx;
116404116592
}else{
116405116593
iIndexCur = pParse->nTab++;
116406116594
}
116407116595
pLevel->iIdxCur = iIndexCur;
116408116596
assert( pIx->pSchema==pTab->pSchema );
@@ -120723,10 +120911,16 @@
120723120911
testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
120724120912
testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
120725120913
testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
120726120914
testcase( z[0]=='9' );
120727120915
*tokenType = TK_INTEGER;
120916
+#ifndef SQLITE_OMIT_HEX_INTEGER
120917
+ if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
120918
+ for(i=3; sqlite3Isxdigit(z[i]); i++){}
120919
+ return i;
120920
+ }
120921
+#endif
120728120922
for(i=0; sqlite3Isdigit(z[i]); i++){}
120729120923
#ifndef SQLITE_OMIT_FLOATING_POINT
120730120924
if( z[i]=='.' ){
120731120925
i++;
120732120926
while( sqlite3Isdigit(z[i]) ){ i++; }
@@ -123444,12 +123638,12 @@
123444123638
# error SQLITE_MAX_VDBE_OP must be at least 40
123445123639
#endif
123446123640
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
123447123641
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
123448123642
#endif
123449
-#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>62
123450
-# error SQLITE_MAX_ATTACHED must be between 0 and 62
123643
+#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
123644
+# error SQLITE_MAX_ATTACHED must be between 0 and 125
123451123645
#endif
123452123646
#if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
123453123647
# error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
123454123648
#endif
123455123649
#if SQLITE_MAX_COLUMN>32767
@@ -124752,11 +124946,11 @@
124752124946
const char *zParam, /* URI parameter sought */
124753124947
sqlite3_int64 bDflt /* return if parameter is missing */
124754124948
){
124755124949
const char *z = sqlite3_uri_parameter(zFilename, zParam);
124756124950
sqlite3_int64 v;
124757
- if( z && sqlite3Atoi64(z, &v, sqlite3Strlen30(z), SQLITE_UTF8)==SQLITE_OK ){
124951
+ if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){
124758124952
bDflt = v;
124759124953
}
124760124954
return bDflt;
124761124955
}
124762124956
@@ -126283,11 +126477,11 @@
126283126477
126284126478
/* fts3_tokenize_vtab.c */
126285126479
SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *);
126286126480
126287126481
/* fts3_unicode2.c (functions generated by parsing unicode text files) */
126288
-#ifdef SQLITE_ENABLE_FTS4_UNICODE61
126482
+#ifndef SQLITE_DISABLE_FTS3_UNICODE
126289126483
SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int);
126290126484
SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int);
126291126485
SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
126292126486
#endif
126293126487
@@ -129753,11 +129947,11 @@
129753129947
** to by the argument to point to the "simple" tokenizer implementation.
129754129948
** And so on.
129755129949
*/
129756129950
SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129757129951
SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129758
-#ifdef SQLITE_ENABLE_FTS4_UNICODE61
129952
+#ifndef SQLITE_DISABLE_FTS3_UNICODE
129759129953
SQLITE_PRIVATE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const**ppModule);
129760129954
#endif
129761129955
#ifdef SQLITE_ENABLE_ICU
129762129956
SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129763129957
#endif
@@ -129771,20 +129965,20 @@
129771129965
SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
129772129966
int rc = SQLITE_OK;
129773129967
Fts3Hash *pHash = 0;
129774129968
const sqlite3_tokenizer_module *pSimple = 0;
129775129969
const sqlite3_tokenizer_module *pPorter = 0;
129776
-#ifdef SQLITE_ENABLE_FTS4_UNICODE61
129970
+#ifndef SQLITE_DISABLE_FTS3_UNICODE
129777129971
const sqlite3_tokenizer_module *pUnicode = 0;
129778129972
#endif
129779129973
129780129974
#ifdef SQLITE_ENABLE_ICU
129781129975
const sqlite3_tokenizer_module *pIcu = 0;
129782129976
sqlite3Fts3IcuTokenizerModule(&pIcu);
129783129977
#endif
129784129978
129785
-#ifdef SQLITE_ENABLE_FTS4_UNICODE61
129979
+#ifndef SQLITE_DISABLE_FTS3_UNICODE
129786129980
sqlite3Fts3UnicodeTokenizer(&pUnicode);
129787129981
#endif
129788129982
129789129983
#ifdef SQLITE_TEST
129790129984
rc = sqlite3Fts3InitTerm(db);
@@ -129808,11 +130002,11 @@
129808130002
/* Load the built-in tokenizers into the hash table */
129809130003
if( rc==SQLITE_OK ){
129810130004
if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
129811130005
|| sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
129812130006
129813
-#ifdef SQLITE_ENABLE_FTS4_UNICODE61
130007
+#ifndef SQLITE_DISABLE_FTS3_UNICODE
129814130008
|| sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode)
129815130009
#endif
129816130010
#ifdef SQLITE_ENABLE_ICU
129817130011
|| (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
129818130012
#endif
@@ -143068,11 +143262,11 @@
143068143262
******************************************************************************
143069143263
**
143070143264
** Implementation of the "unicode" full-text-search tokenizer.
143071143265
*/
143072143266
143073
-#ifdef SQLITE_ENABLE_FTS4_UNICODE61
143267
+#ifndef SQLITE_DISABLE_FTS3_UNICODE
143074143268
143075143269
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143076143270
143077143271
/* #include <assert.h> */
143078143272
/* #include <stdlib.h> */
@@ -143284,11 +143478,11 @@
143284143478
memset(pNew, 0, sizeof(unicode_tokenizer));
143285143479
pNew->bRemoveDiacritic = 1;
143286143480
143287143481
for(i=0; rc==SQLITE_OK && i<nArg; i++){
143288143482
const char *z = azArg[i];
143289
- int n = strlen(z);
143483
+ int n = (int)strlen(z);
143290143484
143291143485
if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){
143292143486
pNew->bRemoveDiacritic = 1;
143293143487
}
143294143488
else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){
@@ -143416,15 +143610,15 @@
143416143610
}while( unicodeIsAlnum(p, iCode)
143417143611
|| sqlite3FtsUnicodeIsdiacritic(iCode)
143418143612
);
143419143613
143420143614
/* Set the output variables and return. */
143421
- pCsr->iOff = (z - pCsr->aInput);
143615
+ pCsr->iOff = (int)(z - pCsr->aInput);
143422143616
*paToken = pCsr->zToken;
143423
- *pnToken = zOut - pCsr->zToken;
143424
- *piStart = (zStart - pCsr->aInput);
143425
- *piEnd = (zEnd - pCsr->aInput);
143617
+ *pnToken = (int)(zOut - pCsr->zToken);
143618
+ *piStart = (int)(zStart - pCsr->aInput);
143619
+ *piEnd = (int)(zEnd - pCsr->aInput);
143426143620
*piPos = pCsr->iToken++;
143427143621
return SQLITE_OK;
143428143622
}
143429143623
143430143624
/*
@@ -143443,11 +143637,11 @@
143443143637
};
143444143638
*ppModule = &module;
143445143639
}
143446143640
143447143641
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
143448
-#endif /* ifndef SQLITE_ENABLE_FTS4_UNICODE61 */
143642
+#endif /* ifndef SQLITE_DISABLE_FTS3_UNICODE */
143449143643
143450143644
/************** End of fts3_unicode.c ****************************************/
143451143645
/************** Begin file fts3_unicode2.c ***********************************/
143452143646
/*
143453143647
** 2012 May 25
@@ -143464,11 +143658,11 @@
143464143658
143465143659
/*
143466143660
** DO NOT EDIT THIS MACHINE GENERATED FILE.
143467143661
*/
143468143662
143469
-#if defined(SQLITE_ENABLE_FTS4_UNICODE61)
143663
+#ifndef SQLITE_DISABLE_FTS3_UNICODE
143470143664
#if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
143471143665
143472143666
/* #include <assert.h> */
143473143667
143474143668
/*
@@ -143811,11 +144005,11 @@
143811144005
}
143812144006
143813144007
return ret;
143814144008
}
143815144009
#endif /* defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) */
143816
-#endif /* !defined(SQLITE_ENABLE_FTS4_UNICODE61) */
144010
+#endif /* !defined(SQLITE_DISABLE_FTS3_UNICODE) */
143817144011
143818144012
/************** End of fts3_unicode2.c ***************************************/
143819144013
/************** Begin file rtree.c *******************************************/
143820144014
/*
143821144015
** 2001 September 15
143822144016
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.6"
226 #define SQLITE_VERSION_NUMBER 3008006
227 #define SQLITE_SOURCE_ID "2014-07-01 11:54:02 21981e35062cc6b30e9576786cbf55265a7a4d41"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -2150,31 +2150,37 @@
2150 SQLITE_API int sqlite3_complete16(const void *sql);
2151
2152 /*
2153 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2154 **
2155 ** ^This routine sets a callback function that might be invoked whenever
2156 ** an attempt is made to open a database table that another thread
2157 ** or process has locked.
 
 
 
 
2158 **
2159 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2160 ** is returned immediately upon encountering the lock. ^If the busy callback
2161 ** is not NULL, then the callback might be invoked with two arguments.
2162 **
2163 ** ^The first argument to the busy handler is a copy of the void* pointer which
2164 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2165 ** the busy handler callback is the number of times that the busy handler has
2166 ** been invoked for this locking event. ^If the
2167 ** busy callback returns 0, then no additional attempts are made to
2168 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
 
2169 ** ^If the callback returns non-zero, then another attempt
2170 ** is made to open the database for reading and the cycle repeats.
2171 **
2172 ** The presence of a busy handler does not guarantee that it will be invoked
2173 ** when there is lock contention. ^If SQLite determines that invoking the busy
2174 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2175 ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
 
2176 ** Consider a scenario where one process is holding a read lock that
2177 ** it is trying to promote to a reserved lock and
2178 ** a second process is holding a reserved lock that it is trying
2179 ** to promote to an exclusive lock. The first process cannot proceed
2180 ** because it is blocked by the second and the second process cannot
@@ -2202,14 +2208,16 @@
2202 ** this is important.
2203 **
2204 ** ^(There can only be a single busy handler defined for each
2205 ** [database connection]. Setting a new busy handler clears any
2206 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
2207 ** will also set or clear the busy handler.
 
2208 **
2209 ** The busy callback should not take any actions which modify the
2210 ** database connection that invoked the busy handler. Any such actions
 
2211 ** result in undefined behavior.
2212 **
2213 ** A busy handler must not close the database connection
2214 ** or [prepared statement] that invoked the busy handler.
2215 */
@@ -2230,10 +2238,12 @@
2230 **
2231 ** ^(There can only be a single busy handler for a particular
2232 ** [database connection] any any given moment. If another busy handler
2233 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2234 ** this routine, that other busy handler is cleared.)^
 
 
2235 */
2236 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2237
2238 /*
2239 ** CAPI3REF: Convenience Routines For Running Queries
@@ -4818,10 +4828,17 @@
4818 ** the name of a folder (a.k.a. directory), then all temporary files
4819 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
4820 ** will be placed in that directory.)^ ^If this variable
4821 ** is a NULL pointer, then SQLite performs a search for an appropriate
4822 ** temporary file directory.
 
 
 
 
 
 
 
4823 **
4824 ** It is not safe to read or modify this variable in more than one
4825 ** thread at a time. It is not safe to read or modify this variable
4826 ** if a [database connection] is being used at the same time in a separate
4827 ** thread.
@@ -4837,10 +4854,15 @@
4837 ** [sqlite3_malloc] and the pragma may attempt to free that memory
4838 ** using [sqlite3_free].
4839 ** Hence, if this variable is modified directly, either it should be
4840 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4841 ** or else the use of the [temp_store_directory pragma] should be avoided.
 
 
 
 
 
4842 **
4843 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
4844 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
4845 ** features that require the use of temporary files may fail. Here is an
4846 ** example of how to do this using C++ with the Windows Runtime:
@@ -7256,10 +7278,13 @@
7256 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
7257 ** configured by this function.
7258 **
7259 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
7260 ** from SQL.
 
 
 
7261 **
7262 ** ^Every new [database connection] defaults to having the auto-checkpoint
7263 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
7264 ** pages. The use of this interface
7265 ** is only necessary if the default setting is found to be suboptimal
@@ -7273,10 +7298,14 @@
7273 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7274 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7275 ** empty string, then a checkpoint is run on all databases of
7276 ** connection D. ^If the database connection D is not in
7277 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
 
 
 
 
7278 **
7279 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
7280 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7281 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
7282 ** run whenever the WAL reaches a certain size threshold.
@@ -7295,22 +7324,25 @@
7295 ** <dl>
7296 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7297 ** Checkpoint as many frames as possible without waiting for any database
7298 ** readers or writers to finish. Sync the db file if all frames in the log
7299 ** are checkpointed. This mode is the same as calling
7300 ** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked.
 
7301 **
7302 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7303 ** This mode blocks (calls the busy-handler callback) until there is no
 
7304 ** database writer and all readers are reading from the most recent database
7305 ** snapshot. It then checkpoints all frames in the log file and syncs the
7306 ** database file. This call blocks database writers while it is running,
7307 ** but not database readers.
7308 **
7309 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7310 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7311 ** checkpointing the log file it blocks (calls the busy-handler callback)
 
7312 ** until all readers are reading from the database file only. This ensures
7313 ** that the next client to write to the database file restarts the log file
7314 ** from the beginning. This call blocks database writers while it is running,
7315 ** but not database readers.
7316 ** </dl>
@@ -9285,43 +9317,43 @@
9285 #define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */
9286 #define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9287 #define OP_Count 49 /* synopsis: r[P2]=count() */
9288 #define OP_ReadCookie 50
9289 #define OP_SetCookie 51
9290 #define OP_OpenRead 52 /* synopsis: root=P2 iDb=P3 */
9291 #define OP_OpenWrite 53 /* synopsis: root=P2 iDb=P3 */
9292 #define OP_OpenAutoindex 54 /* synopsis: nColumn=P2 */
9293 #define OP_OpenEphemeral 55 /* synopsis: nColumn=P2 */
9294 #define OP_SorterOpen 56
9295 #define OP_OpenPseudo 57 /* synopsis: P3 columns in r[P2] */
9296 #define OP_Close 58
9297 #define OP_SeekLT 59
9298 #define OP_SeekLE 60
9299 #define OP_SeekGE 61
9300 #define OP_SeekGT 62
9301 #define OP_Seek 63 /* synopsis: intkey=r[P2] */
9302 #define OP_NoConflict 64 /* synopsis: key=r[P3@P4] */
9303 #define OP_NotFound 65 /* synopsis: key=r[P3@P4] */
9304 #define OP_Found 66 /* synopsis: key=r[P3@P4] */
9305 #define OP_NotExists 67 /* synopsis: intkey=r[P3] */
9306 #define OP_Sequence 68 /* synopsis: r[P2]=cursor[P1].ctr++ */
9307 #define OP_NewRowid 69 /* synopsis: r[P2]=rowid */
9308 #define OP_Insert 70 /* synopsis: intkey=r[P3] data=r[P2] */
9309 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9310 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9311 #define OP_InsertInt 73 /* synopsis: intkey=P3 data=r[P2] */
9312 #define OP_Delete 74
9313 #define OP_ResetCount 75
9314 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9315 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9316 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9317 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9318 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9319 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9320 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9321 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9322 #define OP_SorterCompare 84 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9323 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9324 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9325 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9326 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9327 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9328,73 +9360,74 @@
9328 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9329 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9330 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9331 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9332 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9333 #define OP_SorterData 95 /* synopsis: r[P2]=data */
9334 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9335 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9336 #define OP_RowKey 98 /* synopsis: r[P2]=key */
9337 #define OP_RowData 99 /* synopsis: r[P2]=data */
9338 #define OP_Rowid 100 /* synopsis: r[P2]=rowid */
9339 #define OP_NullRow 101
9340 #define OP_Last 102
9341 #define OP_SorterSort 103
9342 #define OP_Sort 104
9343 #define OP_Rewind 105
9344 #define OP_SorterInsert 106
9345 #define OP_IdxInsert 107 /* synopsis: key=r[P2] */
9346 #define OP_IdxDelete 108 /* synopsis: key=r[P2@P3] */
9347 #define OP_IdxRowid 109 /* synopsis: r[P2]=rowid */
9348 #define OP_IdxLE 110 /* synopsis: key=r[P3@P4] */
9349 #define OP_IdxGT 111 /* synopsis: key=r[P3@P4] */
9350 #define OP_IdxLT 112 /* synopsis: key=r[P3@P4] */
9351 #define OP_IdxGE 113 /* synopsis: key=r[P3@P4] */
9352 #define OP_Destroy 114
9353 #define OP_Clear 115
9354 #define OP_ResetSorter 116
9355 #define OP_CreateIndex 117 /* synopsis: r[P2]=root iDb=P1 */
9356 #define OP_CreateTable 118 /* synopsis: r[P2]=root iDb=P1 */
9357 #define OP_ParseSchema 119
9358 #define OP_LoadAnalysis 120
9359 #define OP_DropTable 121
9360 #define OP_DropIndex 122
9361 #define OP_DropTrigger 123
9362 #define OP_IntegrityCk 124
9363 #define OP_RowSetAdd 125 /* synopsis: rowset(P1)=r[P2] */
9364 #define OP_RowSetRead 126 /* synopsis: r[P3]=rowset(P1) */
9365 #define OP_RowSetTest 127 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9366 #define OP_Program 128
9367 #define OP_Param 129
9368 #define OP_FkCounter 130 /* synopsis: fkctr[P1]+=P2 */
9369 #define OP_FkIfZero 131 /* synopsis: if fkctr[P1]==0 goto P2 */
9370 #define OP_MemMax 132 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9371 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9372 #define OP_IfPos 134 /* synopsis: if r[P1]>0 goto P2 */
9373 #define OP_IfNeg 135 /* synopsis: if r[P1]<0 goto P2 */
9374 #define OP_IfZero 136 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9375 #define OP_AggFinal 137 /* synopsis: accum=r[P1] N=P2 */
9376 #define OP_IncrVacuum 138
9377 #define OP_Expire 139
9378 #define OP_TableLock 140 /* synopsis: iDb=P1 root=P2 write=P3 */
9379 #define OP_VBegin 141
9380 #define OP_VCreate 142
9381 #define OP_ToText 143 /* same as TK_TO_TEXT */
9382 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9383 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9384 #define OP_ToInt 146 /* same as TK_TO_INT */
9385 #define OP_ToReal 147 /* same as TK_TO_REAL */
9386 #define OP_VDestroy 148
9387 #define OP_VOpen 149
9388 #define OP_VColumn 150 /* synopsis: r[P3]=vcolumn(P2) */
9389 #define OP_VNext 151
9390 #define OP_VRename 152
9391 #define OP_Pagecount 153
9392 #define OP_MaxPgcnt 154
9393 #define OP_Init 155 /* synopsis: Start at P2 */
9394 #define OP_Noop 156
9395 #define OP_Explain 157
 
9396
9397
9398 /* Properties such as "out2" or "jump" that are specified in
9399 ** comments following the "case" for each opcode in the vdbe.c
9400 ** are encoded into bitvectors as follows:
@@ -9412,23 +9445,23 @@
9412 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9413 /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9414 /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9415 /* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\
9416 /* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\
9417 /* 56 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
9418 /* 64 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c,\
9419 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9420 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9421 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9422 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
9423 /* 104 */ 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01,\
9424 /* 112 */ 0x01, 0x01, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00,\
9425 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45, 0x15,\
9426 /* 128 */ 0x01, 0x02, 0x00, 0x01, 0x08, 0x02, 0x05, 0x05,\
9427 /* 136 */ 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04,\
9428 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x01,\
9429 /* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9430
9431 /************** End of opcodes.h *********************************************/
9432 /************** Continuing where we left off in vdbe.h ***********************/
9433
9434 /*
@@ -10932,10 +10965,13 @@
10932 int tnum; /* Root BTree node for this table (see note above) */
10933 i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
10934 i16 nCol; /* Number of columns in this table */
10935 u16 nRef; /* Number of pointers to this Table */
10936 LogEst szTabRow; /* Estimated size of each table row in bytes */
 
 
 
10937 u8 tabFlags; /* Mask of TF_* values */
10938 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
10939 #ifndef SQLITE_OMIT_ALTERTABLE
10940 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
10941 #endif
@@ -11591,10 +11627,11 @@
11591 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11592 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11593 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11594 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
11595 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
 
11596
11597 /* Allowed return values from sqlite3WhereIsDistinct()
11598 */
11599 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
11600 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -11847,13 +11884,23 @@
11847
11848 /*
11849 ** The yDbMask datatype for the bitmask of all attached databases.
11850 */
11851 #if SQLITE_MAX_ATTACHED>30
11852 typedef sqlite3_uint64 yDbMask;
 
 
 
 
 
11853 #else
11854 typedef unsigned int yDbMask;
 
 
 
 
 
11855 #endif
11856
11857 /*
11858 ** An SQL parser context. A copy of this structure is passed through
11859 ** the parser and down into all the parser action routine in order to
@@ -12522,10 +12569,13 @@
12522 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
12523 #else
12524 # define sqlite3ViewGetColumnNames(A,B) 0
12525 #endif
12526
 
 
 
12527 SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
12528 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
12529 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
12530 #ifndef SQLITE_OMIT_AUTOINCREMENT
12531 SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
@@ -12772,10 +12822,11 @@
12772 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
12773 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
12774 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
12775 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
12776 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
 
12777 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
12778 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
12779 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
12780 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
12781
@@ -13884,10 +13935,11 @@
13884 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13885 Bool isEphemeral:1; /* True for an ephemeral table */
13886 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13887 Bool isTable:1; /* True if a table requiring integer keys */
13888 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
 
13889 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13890 i64 seqCount; /* Sequence counter */
13891 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13892 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13893 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -22422,13 +22474,13 @@
22422 testcase( c==(+1) );
22423 }
22424 return c;
22425 }
22426
22427
22428 /*
22429 ** Convert zNum to a 64-bit signed integer.
 
22430 **
22431 ** If the zNum value is representable as a 64-bit twos-complement
22432 ** integer, then write that value into *pNum and return 0.
22433 **
22434 ** If zNum is exactly 9223372036854775808, return 2. This special
@@ -22511,14 +22563,48 @@
22511 assert( u-1==LARGEST_INT64 );
22512 return neg ? 0 : 2;
22513 }
22514 }
22515 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22516
22517 /*
22518 ** If zNum represents an integer that will fit in 32-bits, then set
22519 ** *pValue to that integer and return true. Otherwise return false.
 
 
22520 **
22521 ** Any non-numeric characters that following zNum are ignored.
22522 ** This is different from sqlite3Atoi64() which requires the
22523 ** input number to be zero-terminated.
22524 */
@@ -22530,11 +22616,29 @@
22530 neg = 1;
22531 zNum++;
22532 }else if( zNum[0]=='+' ){
22533 zNum++;
22534 }
22535 while( zNum[0]=='0' ) zNum++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22536 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
22537 v = v*10 + c;
22538 }
22539
22540 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -23606,43 +23710,43 @@
23606 /* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23607 /* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23608 /* 49 */ "Count" OpHelp("r[P2]=count()"),
23609 /* 50 */ "ReadCookie" OpHelp(""),
23610 /* 51 */ "SetCookie" OpHelp(""),
23611 /* 52 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23612 /* 53 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23613 /* 54 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23614 /* 55 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23615 /* 56 */ "SorterOpen" OpHelp(""),
23616 /* 57 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23617 /* 58 */ "Close" OpHelp(""),
23618 /* 59 */ "SeekLT" OpHelp(""),
23619 /* 60 */ "SeekLE" OpHelp(""),
23620 /* 61 */ "SeekGE" OpHelp(""),
23621 /* 62 */ "SeekGT" OpHelp(""),
23622 /* 63 */ "Seek" OpHelp("intkey=r[P2]"),
23623 /* 64 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23624 /* 65 */ "NotFound" OpHelp("key=r[P3@P4]"),
23625 /* 66 */ "Found" OpHelp("key=r[P3@P4]"),
23626 /* 67 */ "NotExists" OpHelp("intkey=r[P3]"),
23627 /* 68 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
23628 /* 69 */ "NewRowid" OpHelp("r[P2]=rowid"),
23629 /* 70 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23630 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23631 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23632 /* 73 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23633 /* 74 */ "Delete" OpHelp(""),
23634 /* 75 */ "ResetCount" OpHelp(""),
23635 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23636 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23637 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23638 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23639 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23640 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23641 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23642 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23643 /* 84 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23644 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23645 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23646 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23647 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23648 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23649,73 +23753,74 @@
23649 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23650 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23651 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23652 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23653 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23654 /* 95 */ "SorterData" OpHelp("r[P2]=data"),
23655 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23656 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23657 /* 98 */ "RowKey" OpHelp("r[P2]=key"),
23658 /* 99 */ "RowData" OpHelp("r[P2]=data"),
23659 /* 100 */ "Rowid" OpHelp("r[P2]=rowid"),
23660 /* 101 */ "NullRow" OpHelp(""),
23661 /* 102 */ "Last" OpHelp(""),
23662 /* 103 */ "SorterSort" OpHelp(""),
23663 /* 104 */ "Sort" OpHelp(""),
23664 /* 105 */ "Rewind" OpHelp(""),
23665 /* 106 */ "SorterInsert" OpHelp(""),
23666 /* 107 */ "IdxInsert" OpHelp("key=r[P2]"),
23667 /* 108 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23668 /* 109 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23669 /* 110 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23670 /* 111 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23671 /* 112 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23672 /* 113 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23673 /* 114 */ "Destroy" OpHelp(""),
23674 /* 115 */ "Clear" OpHelp(""),
23675 /* 116 */ "ResetSorter" OpHelp(""),
23676 /* 117 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23677 /* 118 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23678 /* 119 */ "ParseSchema" OpHelp(""),
23679 /* 120 */ "LoadAnalysis" OpHelp(""),
23680 /* 121 */ "DropTable" OpHelp(""),
23681 /* 122 */ "DropIndex" OpHelp(""),
23682 /* 123 */ "DropTrigger" OpHelp(""),
23683 /* 124 */ "IntegrityCk" OpHelp(""),
23684 /* 125 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23685 /* 126 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23686 /* 127 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23687 /* 128 */ "Program" OpHelp(""),
23688 /* 129 */ "Param" OpHelp(""),
23689 /* 130 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23690 /* 131 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23691 /* 132 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23692 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23693 /* 134 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23694 /* 135 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23695 /* 136 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23696 /* 137 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23697 /* 138 */ "IncrVacuum" OpHelp(""),
23698 /* 139 */ "Expire" OpHelp(""),
23699 /* 140 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23700 /* 141 */ "VBegin" OpHelp(""),
23701 /* 142 */ "VCreate" OpHelp(""),
23702 /* 143 */ "ToText" OpHelp(""),
23703 /* 144 */ "ToBlob" OpHelp(""),
23704 /* 145 */ "ToNumeric" OpHelp(""),
23705 /* 146 */ "ToInt" OpHelp(""),
23706 /* 147 */ "ToReal" OpHelp(""),
23707 /* 148 */ "VDestroy" OpHelp(""),
23708 /* 149 */ "VOpen" OpHelp(""),
23709 /* 150 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23710 /* 151 */ "VNext" OpHelp(""),
23711 /* 152 */ "VRename" OpHelp(""),
23712 /* 153 */ "Pagecount" OpHelp(""),
23713 /* 154 */ "MaxPgcnt" OpHelp(""),
23714 /* 155 */ "Init" OpHelp("Start at P2"),
23715 /* 156 */ "Noop" OpHelp(""),
23716 /* 157 */ "Explain" OpHelp(""),
 
23717 };
23718 return azName[i];
23719 }
23720 #endif
23721
@@ -62343,11 +62448,11 @@
62343 }
62344 sqlite3DbFree(p->db, pParse->aLabel);
62345 pParse->aLabel = 0;
62346 pParse->nLabel = 0;
62347 *pMaxFuncArgs = nMaxArgs;
62348 assert( p->bIsReader!=0 || p->btreeMask==0 );
62349 }
62350
62351 /*
62352 ** Return the address of the next instruction to be inserted.
62353 */
@@ -62370,11 +62475,11 @@
62370 SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe *p, int *pnOp, int *pnMaxArg){
62371 VdbeOp *aOp = p->aOp;
62372 assert( aOp && !p->db->mallocFailed );
62373
62374 /* Check that sqlite3VdbeUsesBtree() was not called on this VM */
62375 assert( p->btreeMask==0 );
62376
62377 resolveP2Values(p, pnMaxArg);
62378 *pnOp = p->nOp;
62379 p->aOp = 0;
62380 return aOp;
@@ -62955,13 +63060,13 @@
62955 ** p->btreeMask of databases that will require a lock.
62956 */
62957 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
62958 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
62959 assert( i<(int)sizeof(p->btreeMask)*8 );
62960 p->btreeMask |= ((yDbMask)1)<<i;
62961 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
62962 p->lockMask |= ((yDbMask)1)<<i;
62963 }
62964 }
62965
62966 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
62967 /*
@@ -62985,20 +63090,19 @@
62985 ** this routine is N*N. But as N is rarely more than 1, this should not
62986 ** be a problem.
62987 */
62988 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){
62989 int i;
62990 yDbMask mask;
62991 sqlite3 *db;
62992 Db *aDb;
62993 int nDb;
62994 if( p->lockMask==0 ) return; /* The common case */
62995 db = p->db;
62996 aDb = db->aDb;
62997 nDb = db->nDb;
62998 for(i=0, mask=1; i<nDb; i++, mask += mask){
62999 if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
63000 sqlite3BtreeEnter(aDb[i].pBt);
63001 }
63002 }
63003 }
63004 #endif
@@ -63007,20 +63111,19 @@
63007 /*
63008 ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
63009 */
63010 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){
63011 int i;
63012 yDbMask mask;
63013 sqlite3 *db;
63014 Db *aDb;
63015 int nDb;
63016 if( p->lockMask==0 ) return; /* The common case */
63017 db = p->db;
63018 aDb = db->aDb;
63019 nDb = db->nDb;
63020 for(i=0, mask=1; i<nDb; i++, mask += mask){
63021 if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
63022 sqlite3BtreeLeave(aDb[i].pBt);
63023 }
63024 }
63025 }
63026 #endif
@@ -63987,11 +64090,11 @@
63987 int cnt = 0;
63988 int nWrite = 0;
63989 int nRead = 0;
63990 p = db->pVdbe;
63991 while( p ){
63992 if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){
63993 cnt++;
63994 if( p->readOnly==0 ) nWrite++;
63995 if( p->bIsReader ) nRead++;
63996 }
63997 p = p->pNext;
@@ -67184,11 +67287,11 @@
67184 /*
67185 ** Return true if the prepared statement is in need of being reset.
67186 */
67187 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
67188 Vdbe *v = (Vdbe*)pStmt;
67189 return v!=0 && v->pc>0 && v->magic==VDBE_MAGIC_RUN;
67190 }
67191
67192 /*
67193 ** Return a pointer to the next prepared statement after pStmt associated
67194 ** with database connection pDb. If pStmt is NULL, return the first
@@ -70641,11 +70744,11 @@
70641 int iGen;
70642
70643 assert( p->bIsReader );
70644 assert( p->readOnly==0 || pOp->p2==0 );
70645 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70646 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70647 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
70648 rc = SQLITE_READONLY;
70649 goto abort_due_to_error;
70650 }
70651 pBt = db->aDb[pOp->p1].pBt;
@@ -70736,11 +70839,11 @@
70736 iDb = pOp->p1;
70737 iCookie = pOp->p3;
70738 assert( pOp->p3<SQLITE_N_BTREE_META );
70739 assert( iDb>=0 && iDb<db->nDb );
70740 assert( db->aDb[iDb].pBt!=0 );
70741 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
70742
70743 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
70744 pOut->u.i = iMeta;
70745 break;
70746 }
@@ -70757,11 +70860,11 @@
70757 */
70758 case OP_SetCookie: { /* in3 */
70759 Db *pDb;
70760 assert( pOp->p2<SQLITE_N_BTREE_META );
70761 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70762 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70763 assert( p->readOnly==0 );
70764 pDb = &db->aDb[pOp->p1];
70765 assert( pDb->pBt!=0 );
70766 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
70767 pIn3 = &aMem[pOp->p3];
@@ -70812,11 +70915,25 @@
70812 ** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
70813 ** structure, then said structure defines the content and collating
70814 ** sequence of the index being opened. Otherwise, if P4 is an integer
70815 ** value, it is set to the number of columns in the table.
70816 **
70817 ** See also OpenWrite.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70818 */
70819 /* Opcode: OpenWrite P1 P2 P3 P4 P5
70820 ** Synopsis: root=P2 iDb=P3
70821 **
70822 ** Open a read/write cursor named P1 on the table or index whose root
@@ -70834,10 +70951,23 @@
70834 ** in read/write mode. For a given table, there can be one or more read-only
70835 ** cursors or a single read/write cursor but not both.
70836 **
70837 ** See also OpenRead.
70838 */
 
 
 
 
 
 
 
 
 
 
 
 
 
70839 case OP_OpenRead:
70840 case OP_OpenWrite: {
70841 int nField;
70842 KeyInfo *pKeyInfo;
70843 int p2;
@@ -70848,11 +70978,12 @@
70848 Db *pDb;
70849
70850 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
70851 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
70852 assert( p->bIsReader );
70853 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
 
70854
70855 if( p->expired ){
70856 rc = SQLITE_ABORT;
70857 break;
70858 }
@@ -70860,11 +70991,11 @@
70860 nField = 0;
70861 pKeyInfo = 0;
70862 p2 = pOp->p2;
70863 iDb = pOp->p3;
70864 assert( iDb>=0 && iDb<db->nDb );
70865 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
70866 pDb = &db->aDb[iDb];
70867 pX = pDb->pBt;
70868 assert( pX!=0 );
70869 if( pOp->opcode==OP_OpenWrite ){
70870 wrFlag = 1;
@@ -70905,10 +71036,11 @@
70905 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
70906 pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
70907 if( pCur==0 ) goto no_mem;
70908 pCur->nullRow = 1;
70909 pCur->isOrdered = 1;
 
70910 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
70911 pCur->pKeyInfo = pKeyInfo;
70912 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
70913 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
70914
@@ -72451,11 +72583,11 @@
72451 rc = SQLITE_LOCKED;
72452 p->errorAction = OE_Abort;
72453 }else{
72454 iDb = pOp->p3;
72455 assert( iCnt==1 );
72456 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
72457 iMoved = 0; /* Not needed. Only to silence a warning. */
72458 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
72459 pOut->flags = MEM_Int;
72460 pOut->u.i = iMoved;
72461 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -72491,11 +72623,11 @@
72491 case OP_Clear: {
72492 int nChange;
72493
72494 nChange = 0;
72495 assert( p->readOnly==0 );
72496 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
72497 rc = sqlite3BtreeClearTable(
72498 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
72499 );
72500 if( pOp->p3 ){
72501 p->nChange += nChange;
@@ -72561,11 +72693,11 @@
72561 int flags;
72562 Db *pDb;
72563
72564 pgno = 0;
72565 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72566 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72567 assert( p->readOnly==0 );
72568 pDb = &db->aDb[pOp->p1];
72569 assert( pDb->pBt!=0 );
72570 if( pOp->opcode==OP_CreateTable ){
72571 /* flags = BTREE_INTKEY; */
@@ -72726,11 +72858,11 @@
72726 for(j=0; j<nRoot; j++){
72727 aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
72728 }
72729 aRoot[j] = 0;
72730 assert( pOp->p5<db->nDb );
72731 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
72732 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
72733 (int)pnErr->u.i, &nErr);
72734 sqlite3DbFree(db, aRoot);
72735 pnErr->u.i -= nErr;
72736 sqlite3VdbeMemSetNull(pIn1);
@@ -73386,11 +73518,11 @@
73386 */
73387 case OP_IncrVacuum: { /* jump */
73388 Btree *pBt;
73389
73390 assert( pOp->p1>=0 && pOp->p1<db->nDb );
73391 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
73392 assert( p->readOnly==0 );
73393 pBt = db->aDb[pOp->p1].pBt;
73394 rc = sqlite3BtreeIncrVacuum(pBt);
73395 VdbeBranchTaken(rc==SQLITE_DONE,2);
73396 if( rc==SQLITE_DONE ){
@@ -73401,16 +73533,17 @@
73401 }
73402 #endif
73403
73404 /* Opcode: Expire P1 * * * *
73405 **
73406 ** Cause precompiled statements to become expired. An expired statement
73407 ** fails with an error code of SQLITE_SCHEMA if it is ever executed
73408 ** (via sqlite3_step()).
 
73409 **
73410 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
73411 ** then only the currently executing statement is affected.
73412 */
73413 case OP_Expire: {
73414 if( !pOp->p1 ){
73415 sqlite3ExpirePreparedStatements(db);
73416 }else{
@@ -73438,11 +73571,11 @@
73438 case OP_TableLock: {
73439 u8 isWriteLock = (u8)pOp->p3;
73440 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
73441 int p1 = pOp->p1;
73442 assert( p1>=0 && p1<db->nDb );
73443 assert( (p->btreeMask & (((yDbMask)1)<<p1))!=0 );
73444 assert( isWriteLock==0 || isWriteLock==1 );
73445 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
73446 if( (rc&0xFF)==SQLITE_LOCKED ){
73447 const char *z = pOp->p4.z;
73448 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
@@ -73888,11 +74021,11 @@
73888 #ifdef SQLITE_USE_FCNTL_TRACE
73889 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
73890 if( zTrace ){
73891 int i;
73892 for(i=0; i<db->nDb; i++){
73893 if( (MASKBIT(i) & p->btreeMask)==0 ) continue;
73894 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
73895 }
73896 }
73897 #endif /* SQLITE_USE_FCNTL_TRACE */
73898 #ifdef SQLITE_DEBUG
@@ -79792,21 +79925,28 @@
79792 }else{
79793 int c;
79794 i64 value;
79795 const char *z = pExpr->u.zToken;
79796 assert( z!=0 );
79797 c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
79798 if( c==0 || (c==2 && negFlag) ){
79799 char *zV;
79800 if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
79801 zV = dup8bytes(v, (char*)&value);
79802 sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
79803 }else{
79804 #ifdef SQLITE_OMIT_FLOATING_POINT
79805 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
79806 #else
79807 codeReal(v, z, negFlag, iMem);
 
 
 
 
 
 
 
79808 #endif
79809 }
79810 }
79811 }
79812
@@ -83913,20 +84053,20 @@
83913 ** ...
83914 ** regChng = N
83915 ** goto chng_addr_N
83916 */
83917 addrNextRow = sqlite3VdbeCurrentAddr(v);
83918 for(i=0; i<nCol; i++){
83919 char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
83920 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
83921 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
83922 aGotoChng[i] =
83923 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
83924 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
83925 VdbeCoverage(v);
83926 }
83927 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
83928 aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
83929
83930 /*
83931 ** chng_addr_0:
83932 ** regPrev(0) = idx(0)
@@ -83933,11 +84073,11 @@
83933 ** chng_addr_1:
83934 ** regPrev(1) = idx(1)
83935 ** ...
83936 */
83937 sqlite3VdbeJumpHere(v, addrGotoChng0);
83938 for(i=0; i<nCol; i++){
83939 sqlite3VdbeJumpHere(v, aGotoChng[i]);
83940 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
83941 }
83942
83943 /*
@@ -84124,10 +84264,11 @@
84124 int i;
84125 char *z, *zDb;
84126 Table *pTab;
84127 Index *pIdx;
84128 Token *pTableName;
 
84129
84130 /* Read the database schema. If an error occurs, leave an error message
84131 ** and code in pParse and return NULL. */
84132 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
84133 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
@@ -84171,10 +84312,12 @@
84171 }
84172 sqlite3DbFree(db, z);
84173 }
84174 }
84175 }
 
 
84176 }
84177
84178 /*
84179 ** Used to pass information from the analyzer reader through to the
84180 ** callback routine.
@@ -84229,18 +84372,23 @@
84229 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
84230 assert( pIndex!=0 );
84231 #else
84232 if( pIndex )
84233 #endif
84234 {
84235 if( strcmp(z, "unordered")==0 ){
84236 pIndex->bUnordered = 1;
84237 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
84238 int v32 = 0;
84239 sqlite3GetInt32(z+3, &v32);
84240 pIndex->szIdxRow = sqlite3LogEst(v32);
84241 }
 
 
 
 
 
 
 
84242 }
84243 }
84244
84245 /*
84246 ** This callback is invoked once for each index when reading the
@@ -84277,15 +84425,19 @@
84277 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
84278 }
84279 z = argv[2];
84280
84281 if( pIndex ){
 
84282 decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
84283 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
84284 }else{
84285 Index fakeIdx;
84286 fakeIdx.szIdxRow = pTable->szTabRow;
 
 
 
84287 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
84288 pTable->szTabRow = fakeIdx.szIdxRow;
84289 }
84290
84291 return 0;
@@ -85557,10 +85709,23 @@
85557 }
85558 #else
85559 #define codeTableLocks(x)
85560 #endif
85561
 
 
 
 
 
 
 
 
 
 
 
 
 
85562 /*
85563 ** This routine is called after a single SQL statement has been
85564 ** parsed and a VDBE program to execute that statement has been
85565 ** prepared. This routine puts the finishing touches on the
85566 ** VDBE program and resets the pParse structure for the next
@@ -85593,22 +85758,23 @@
85593 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
85594 ** set for each database that is used. Generate code to start a
85595 ** transaction on each used database and to verify the schema cookie
85596 ** on each used database.
85597 */
85598 if( db->mallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){
85599 yDbMask mask;
 
85600 int iDb, i;
85601 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
85602 sqlite3VdbeJumpHere(v, 0);
85603 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
85604 if( (mask & pParse->cookieMask)==0 ) continue;
85605 sqlite3VdbeUsesBtree(v, iDb);
85606 sqlite3VdbeAddOp4Int(v,
85607 OP_Transaction, /* Opcode */
85608 iDb, /* P1 */
85609 (mask & pParse->writeMask)!=0, /* P2 */
85610 pParse->cookieValue[iDb], /* P3 */
85611 db->aDb[iDb].pSchema->iGeneration /* P4 */
85612 );
85613 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
85614 }
@@ -85660,11 +85826,11 @@
85660 }
85661 pParse->nTab = 0;
85662 pParse->nMem = 0;
85663 pParse->nSet = 0;
85664 pParse->nVar = 0;
85665 pParse->cookieMask = 0;
85666 }
85667
85668 /*
85669 ** Run the parser and code generator recursively in order to generate
85670 ** code for the SQL statement given onto the end of the pParse context
@@ -89287,19 +89453,17 @@
89287 ** later, by sqlite3FinishCoding().
89288 */
89289 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
89290 Parse *pToplevel = sqlite3ParseToplevel(pParse);
89291 sqlite3 *db = pToplevel->db;
89292 yDbMask mask;
89293
89294 assert( iDb>=0 && iDb<db->nDb );
89295 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
89296 assert( iDb<SQLITE_MAX_ATTACHED+2 );
89297 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
89298 mask = ((yDbMask)1)<<iDb;
89299 if( (pToplevel->cookieMask & mask)==0 ){
89300 pToplevel->cookieMask |= mask;
89301 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
89302 if( !OMIT_TEMPDB && iDb==1 ){
89303 sqlite3OpenTempDatabase(pToplevel);
89304 }
89305 }
@@ -89334,11 +89498,11 @@
89334 ** necessary to undo a write and the checkpoint should not be set.
89335 */
89336 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
89337 Parse *pToplevel = sqlite3ParseToplevel(pParse);
89338 sqlite3CodeVerifySchema(pParse, iDb);
89339 pToplevel->writeMask |= ((yDbMask)1)<<iDb;
89340 pToplevel->isMultiWrite |= setStatement;
89341 }
89342
89343 /*
89344 ** Indicate that the statement currently under construction might write
@@ -98590,11 +98754,11 @@
98590 */
98591 case PragTyp_JOURNAL_SIZE_LIMIT: {
98592 Pager *pPager = sqlite3BtreePager(pDb->pBt);
98593 i64 iLimit = -2;
98594 if( zRight ){
98595 sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8);
98596 if( iLimit<-1 ) iLimit = -1;
98597 }
98598 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
98599 returnSingleInt(pParse, "journal_size_limit", iLimit);
98600 break;
@@ -98718,11 +98882,11 @@
98718 sqlite3_int64 sz;
98719 #if SQLITE_MAX_MMAP_SIZE>0
98720 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98721 if( zRight ){
98722 int ii;
98723 sqlite3Atoi64(zRight, &sz, sqlite3Strlen30(zRight), SQLITE_UTF8);
98724 if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
98725 if( pId2->n==0 ) db->szMmap = sz;
98726 for(ii=db->nDb-1; ii>=0; ii--){
98727 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
98728 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
@@ -99761,11 +99925,11 @@
99761 ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
99762 ** use -1.
99763 */
99764 case PragTyp_SOFT_HEAP_LIMIT: {
99765 sqlite3_int64 N;
99766 if( zRight && sqlite3Atoi64(zRight, &N, 1000000, SQLITE_UTF8)==SQLITE_OK ){
99767 sqlite3_soft_heap_limit64(N);
99768 }
99769 returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
99770 break;
99771 }
@@ -113609,10 +113773,11 @@
113609 int regRowid = 0; /* Register holding rowid */
113610 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
113611 int iRetInit; /* Address of regReturn init */
113612 int untestedTerms = 0; /* Some terms not completely tested */
113613 int ii; /* Loop counter */
 
113614 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
113615 Table *pTab = pTabItem->pTab;
113616
113617 pTerm = pLoop->aLTerm[0];
113618 assert( pTerm!=0 );
@@ -113704,10 +113869,12 @@
113704
113705 /* Run a separate WHERE clause for each term of the OR clause. After
113706 ** eliminating duplicates from other WHERE clauses, the action for each
113707 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
113708 */
 
 
113709 for(ii=0; ii<pOrWc->nTerm; ii++){
113710 WhereTerm *pOrTerm = &pOrWc->a[ii];
113711 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
113712 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
113713 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -113716,12 +113883,11 @@
113716 pAndExpr->pLeft = pOrExpr;
113717 pOrExpr = pAndExpr;
113718 }
113719 /* Loop through table entries that match term pOrTerm. */
113720 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
113721 WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
113722 WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur);
113723 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
113724 if( pSubWInfo ){
113725 WhereLoop *pSubLoop;
113726 explainOneScan(
113727 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
@@ -113808,10 +113974,11 @@
113808 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
113809 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pSubLoop->u.btree.pIndex))
113810 ){
113811 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
113812 pCov = pSubLoop->u.btree.pIndex;
 
113813 }else{
113814 pCov = 0;
113815 }
113816
113817 /* Finish the loop through table entries that match term pOrTerm. */
@@ -114414,10 +114581,20 @@
114414 pLoop->nOut += (pTerm->truthProb<=0 ? pTerm->truthProb : -1);
114415 }
114416 }
114417 }
114418
 
 
 
 
 
 
 
 
 
 
114419 /*
114420 ** We have so far matched pBuilder->pNew->u.btree.nEq terms of the
114421 ** index pIndex. Try to match one more.
114422 **
114423 ** When this function is called, pBuilder->pNew->nOut contains the
@@ -114610,11 +114787,10 @@
114610 testcase( eOp & WO_ISNULL );
114611 rc = whereEqualScanEst(pParse, pBuilder, pExpr->pRight, &nOut);
114612 }else{
114613 rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut);
114614 }
114615 assert( rc!=SQLITE_OK || nOut>0 );
114616 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
114617 if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */
114618 if( nOut ){
114619 pNew->nOut = sqlite3LogEst(nOut);
114620 if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut;
@@ -114642,10 +114818,11 @@
114642 rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
114643 pNew->rRun = sqlite3LogEstAdd(rLogSize, rCostIdx);
114644 if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){
114645 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut + 16);
114646 }
 
114647
114648 nOutUnadjusted = pNew->nOut;
114649 pNew->rRun += nInMul + nIn;
114650 pNew->nOut += nInMul + nIn;
114651 whereLoopOutputAdjust(pBuilder->pWC, pNew);
@@ -114761,10 +114938,18 @@
114761 ** cost = nSeek * (log(nRow) + (K+3.0) * nVisit) // non-covering index
114762 **
114763 ** Normally, nSeek is 1. nSeek values greater than 1 come about if the
114764 ** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
114765 ** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
 
 
 
 
 
 
 
 
114766 */
114767 static int whereLoopAddBtree(
114768 WhereLoopBuilder *pBuilder, /* WHERE clause information */
114769 Bitmask mExtra /* Extra prerequesites for using this table */
114770 ){
@@ -114848,10 +115033,11 @@
114848 pNew->aLTerm[0] = pTerm;
114849 /* TUNING: One-time cost for computing the automatic index is
114850 ** approximately 7*N*log2(N) where N is the number of rows in
114851 ** the table being indexed. */
114852 pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
 
114853 /* TUNING: Each index lookup yields 20 rows in the table. This
114854 ** is more than the usual guess of 10 rows, since we have no way
114855 ** of knowning how selective the index will ultimately be. It would
114856 ** not be unreasonable to make this value much larger. */
114857 pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
@@ -114889,10 +115075,11 @@
114889
114890 /* Full table scan */
114891 pNew->iSortIdx = b ? iSortIdx : 0;
114892 /* TUNING: Cost of full table scan is (N*3.0). */
114893 pNew->rRun = rSize + 16;
 
114894 whereLoopOutputAdjust(pWC, pNew);
114895 rc = whereLoopInsert(pBuilder, pNew);
114896 pNew->nOut = rSize;
114897 if( rc ) break;
114898 }else{
@@ -114924,11 +115111,11 @@
114924 ** also add the cost of visiting table rows (N*3.0). */
114925 pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow;
114926 if( m!=0 ){
114927 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16);
114928 }
114929
114930 whereLoopOutputAdjust(pWC, pNew);
114931 rc = whereLoopInsert(pBuilder, pNew);
114932 pNew->nOut = rSize;
114933 if( rc ) break;
114934 }
@@ -116399,10 +116586,11 @@
116399 }
116400 op = OP_OpenWrite;
116401 pWInfo->aiCurOnePass[1] = iIndexCur;
116402 }else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){
116403 iIndexCur = iIdxCur;
 
116404 }else{
116405 iIndexCur = pParse->nTab++;
116406 }
116407 pLevel->iIdxCur = iIndexCur;
116408 assert( pIx->pSchema==pTab->pSchema );
@@ -120723,10 +120911,16 @@
120723 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
120724 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
120725 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
120726 testcase( z[0]=='9' );
120727 *tokenType = TK_INTEGER;
 
 
 
 
 
 
120728 for(i=0; sqlite3Isdigit(z[i]); i++){}
120729 #ifndef SQLITE_OMIT_FLOATING_POINT
120730 if( z[i]=='.' ){
120731 i++;
120732 while( sqlite3Isdigit(z[i]) ){ i++; }
@@ -123444,12 +123638,12 @@
123444 # error SQLITE_MAX_VDBE_OP must be at least 40
123445 #endif
123446 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
123447 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
123448 #endif
123449 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>62
123450 # error SQLITE_MAX_ATTACHED must be between 0 and 62
123451 #endif
123452 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
123453 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
123454 #endif
123455 #if SQLITE_MAX_COLUMN>32767
@@ -124752,11 +124946,11 @@
124752 const char *zParam, /* URI parameter sought */
124753 sqlite3_int64 bDflt /* return if parameter is missing */
124754 ){
124755 const char *z = sqlite3_uri_parameter(zFilename, zParam);
124756 sqlite3_int64 v;
124757 if( z && sqlite3Atoi64(z, &v, sqlite3Strlen30(z), SQLITE_UTF8)==SQLITE_OK ){
124758 bDflt = v;
124759 }
124760 return bDflt;
124761 }
124762
@@ -126283,11 +126477,11 @@
126283
126284 /* fts3_tokenize_vtab.c */
126285 SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *);
126286
126287 /* fts3_unicode2.c (functions generated by parsing unicode text files) */
126288 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
126289 SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int);
126290 SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int);
126291 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
126292 #endif
126293
@@ -129753,11 +129947,11 @@
129753 ** to by the argument to point to the "simple" tokenizer implementation.
129754 ** And so on.
129755 */
129756 SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129757 SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129758 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
129759 SQLITE_PRIVATE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const**ppModule);
129760 #endif
129761 #ifdef SQLITE_ENABLE_ICU
129762 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129763 #endif
@@ -129771,20 +129965,20 @@
129771 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
129772 int rc = SQLITE_OK;
129773 Fts3Hash *pHash = 0;
129774 const sqlite3_tokenizer_module *pSimple = 0;
129775 const sqlite3_tokenizer_module *pPorter = 0;
129776 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
129777 const sqlite3_tokenizer_module *pUnicode = 0;
129778 #endif
129779
129780 #ifdef SQLITE_ENABLE_ICU
129781 const sqlite3_tokenizer_module *pIcu = 0;
129782 sqlite3Fts3IcuTokenizerModule(&pIcu);
129783 #endif
129784
129785 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
129786 sqlite3Fts3UnicodeTokenizer(&pUnicode);
129787 #endif
129788
129789 #ifdef SQLITE_TEST
129790 rc = sqlite3Fts3InitTerm(db);
@@ -129808,11 +130002,11 @@
129808 /* Load the built-in tokenizers into the hash table */
129809 if( rc==SQLITE_OK ){
129810 if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
129811 || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
129812
129813 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
129814 || sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode)
129815 #endif
129816 #ifdef SQLITE_ENABLE_ICU
129817 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
129818 #endif
@@ -143068,11 +143262,11 @@
143068 ******************************************************************************
143069 **
143070 ** Implementation of the "unicode" full-text-search tokenizer.
143071 */
143072
143073 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
143074
143075 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143076
143077 /* #include <assert.h> */
143078 /* #include <stdlib.h> */
@@ -143284,11 +143478,11 @@
143284 memset(pNew, 0, sizeof(unicode_tokenizer));
143285 pNew->bRemoveDiacritic = 1;
143286
143287 for(i=0; rc==SQLITE_OK && i<nArg; i++){
143288 const char *z = azArg[i];
143289 int n = strlen(z);
143290
143291 if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){
143292 pNew->bRemoveDiacritic = 1;
143293 }
143294 else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){
@@ -143416,15 +143610,15 @@
143416 }while( unicodeIsAlnum(p, iCode)
143417 || sqlite3FtsUnicodeIsdiacritic(iCode)
143418 );
143419
143420 /* Set the output variables and return. */
143421 pCsr->iOff = (z - pCsr->aInput);
143422 *paToken = pCsr->zToken;
143423 *pnToken = zOut - pCsr->zToken;
143424 *piStart = (zStart - pCsr->aInput);
143425 *piEnd = (zEnd - pCsr->aInput);
143426 *piPos = pCsr->iToken++;
143427 return SQLITE_OK;
143428 }
143429
143430 /*
@@ -143443,11 +143637,11 @@
143443 };
143444 *ppModule = &module;
143445 }
143446
143447 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
143448 #endif /* ifndef SQLITE_ENABLE_FTS4_UNICODE61 */
143449
143450 /************** End of fts3_unicode.c ****************************************/
143451 /************** Begin file fts3_unicode2.c ***********************************/
143452 /*
143453 ** 2012 May 25
@@ -143464,11 +143658,11 @@
143464
143465 /*
143466 ** DO NOT EDIT THIS MACHINE GENERATED FILE.
143467 */
143468
143469 #if defined(SQLITE_ENABLE_FTS4_UNICODE61)
143470 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
143471
143472 /* #include <assert.h> */
143473
143474 /*
@@ -143811,11 +144005,11 @@
143811 }
143812
143813 return ret;
143814 }
143815 #endif /* defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) */
143816 #endif /* !defined(SQLITE_ENABLE_FTS4_UNICODE61) */
143817
143818 /************** End of fts3_unicode2.c ***************************************/
143819 /************** Begin file rtree.c *******************************************/
143820 /*
143821 ** 2001 September 15
143822
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.6"
226 #define SQLITE_VERSION_NUMBER 3008006
227 #define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -2150,31 +2150,37 @@
2150 SQLITE_API int sqlite3_complete16(const void *sql);
2151
2152 /*
2153 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2154 **
2155 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2156 ** that might be invoked with argument P whenever
2157 ** an attempt is made to access a database table associated with
2158 ** [database connection] D when another thread
2159 ** or process has the table locked.
2160 ** The sqlite3_busy_handler() interface is used to implement
2161 ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
2162 **
2163 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2164 ** is returned immediately upon encountering the lock. ^If the busy callback
2165 ** is not NULL, then the callback might be invoked with two arguments.
2166 **
2167 ** ^The first argument to the busy handler is a copy of the void* pointer which
2168 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2169 ** the busy handler callback is the number of times that the busy handler has
2170 ** been invoked for the same locking event. ^If the
2171 ** busy callback returns 0, then no additional attempts are made to
2172 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned
2173 ** to the application.
2174 ** ^If the callback returns non-zero, then another attempt
2175 ** is made to access the database and the cycle repeats.
2176 **
2177 ** The presence of a busy handler does not guarantee that it will be invoked
2178 ** when there is lock contention. ^If SQLite determines that invoking the busy
2179 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2180 ** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the
2181 ** busy handler.
2182 ** Consider a scenario where one process is holding a read lock that
2183 ** it is trying to promote to a reserved lock and
2184 ** a second process is holding a reserved lock that it is trying
2185 ** to promote to an exclusive lock. The first process cannot proceed
2186 ** because it is blocked by the second and the second process cannot
@@ -2202,14 +2208,16 @@
2208 ** this is important.
2209 **
2210 ** ^(There can only be a single busy handler defined for each
2211 ** [database connection]. Setting a new busy handler clears any
2212 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
2213 ** or evaluating [PRAGMA busy_timeout=N] will change the
2214 ** busy handler and thus clear any previously set busy handler.
2215 **
2216 ** The busy callback should not take any actions which modify the
2217 ** database connection that invoked the busy handler. In other words,
2218 ** the busy handler is not reentrant. Any such actions
2219 ** result in undefined behavior.
2220 **
2221 ** A busy handler must not close the database connection
2222 ** or [prepared statement] that invoked the busy handler.
2223 */
@@ -2230,10 +2238,12 @@
2238 **
2239 ** ^(There can only be a single busy handler for a particular
2240 ** [database connection] any any given moment. If another busy handler
2241 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2242 ** this routine, that other busy handler is cleared.)^
2243 **
2244 ** See also: [PRAGMA busy_timeout]
2245 */
2246 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2247
2248 /*
2249 ** CAPI3REF: Convenience Routines For Running Queries
@@ -4818,10 +4828,17 @@
4828 ** the name of a folder (a.k.a. directory), then all temporary files
4829 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
4830 ** will be placed in that directory.)^ ^If this variable
4831 ** is a NULL pointer, then SQLite performs a search for an appropriate
4832 ** temporary file directory.
4833 **
4834 ** Applications are strongly discouraged from using this global variable.
4835 ** It is required to set a temporary folder on Windows Runtime (WinRT).
4836 ** But for all other platforms, it is highly recommended that applications
4837 ** neither read nor write this variable. This global variable is a relic
4838 ** that exists for backwards compatibility of legacy applications and should
4839 ** be avoided in new projects.
4840 **
4841 ** It is not safe to read or modify this variable in more than one
4842 ** thread at a time. It is not safe to read or modify this variable
4843 ** if a [database connection] is being used at the same time in a separate
4844 ** thread.
@@ -4837,10 +4854,15 @@
4854 ** [sqlite3_malloc] and the pragma may attempt to free that memory
4855 ** using [sqlite3_free].
4856 ** Hence, if this variable is modified directly, either it should be
4857 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4858 ** or else the use of the [temp_store_directory pragma] should be avoided.
4859 ** Except when requested by the [temp_store_directory pragma], SQLite
4860 ** does not free the memory that sqlite3_temp_directory points to. If
4861 ** the application wants that memory to be freed, it must do
4862 ** so itself, taking care to only do so after all [database connection]
4863 ** objects have been destroyed.
4864 **
4865 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
4866 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
4867 ** features that require the use of temporary files may fail. Here is an
4868 ** example of how to do this using C++ with the Windows Runtime:
@@ -7256,10 +7278,13 @@
7278 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
7279 ** configured by this function.
7280 **
7281 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
7282 ** from SQL.
7283 **
7284 ** ^Checkpoints initiated by this mechanism are
7285 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
7286 **
7287 ** ^Every new [database connection] defaults to having the auto-checkpoint
7288 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
7289 ** pages. The use of this interface
7290 ** is only necessary if the default setting is found to be suboptimal
@@ -7273,10 +7298,14 @@
7298 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7299 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7300 ** empty string, then a checkpoint is run on all databases of
7301 ** connection D. ^If the database connection D is not in
7302 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7303 ** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7304 ** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7305 ** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7306 ** or RESET checkpoint.
7307 **
7308 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
7309 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7310 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
7311 ** run whenever the WAL reaches a certain size threshold.
@@ -7295,22 +7324,25 @@
7324 ** <dl>
7325 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7326 ** Checkpoint as many frames as possible without waiting for any database
7327 ** readers or writers to finish. Sync the db file if all frames in the log
7328 ** are checkpointed. This mode is the same as calling
7329 ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7330 ** is never invoked.
7331 **
7332 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7333 ** This mode blocks (it invokes the
7334 ** [sqlite3_busy_handler|busy-handler callback]) until there is no
7335 ** database writer and all readers are reading from the most recent database
7336 ** snapshot. It then checkpoints all frames in the log file and syncs the
7337 ** database file. This call blocks database writers while it is running,
7338 ** but not database readers.
7339 **
7340 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7341 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7342 ** checkpointing the log file it blocks (calls the
7343 ** [sqlite3_busy_handler|busy-handler callback])
7344 ** until all readers are reading from the database file only. This ensures
7345 ** that the next client to write to the database file restarts the log file
7346 ** from the beginning. This call blocks database writers while it is running,
7347 ** but not database readers.
7348 ** </dl>
@@ -9285,43 +9317,43 @@
9317 #define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */
9318 #define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9319 #define OP_Count 49 /* synopsis: r[P2]=count() */
9320 #define OP_ReadCookie 50
9321 #define OP_SetCookie 51
9322 #define OP_ReopenIdx 52 /* synopsis: root=P2 iDb=P3 */
9323 #define OP_OpenRead 53 /* synopsis: root=P2 iDb=P3 */
9324 #define OP_OpenWrite 54 /* synopsis: root=P2 iDb=P3 */
9325 #define OP_OpenAutoindex 55 /* synopsis: nColumn=P2 */
9326 #define OP_OpenEphemeral 56 /* synopsis: nColumn=P2 */
9327 #define OP_SorterOpen 57
9328 #define OP_OpenPseudo 58 /* synopsis: P3 columns in r[P2] */
9329 #define OP_Close 59
9330 #define OP_SeekLT 60
9331 #define OP_SeekLE 61
9332 #define OP_SeekGE 62
9333 #define OP_SeekGT 63
9334 #define OP_Seek 64 /* synopsis: intkey=r[P2] */
9335 #define OP_NoConflict 65 /* synopsis: key=r[P3@P4] */
9336 #define OP_NotFound 66 /* synopsis: key=r[P3@P4] */
9337 #define OP_Found 67 /* synopsis: key=r[P3@P4] */
9338 #define OP_NotExists 68 /* synopsis: intkey=r[P3] */
9339 #define OP_Sequence 69 /* synopsis: r[P2]=cursor[P1].ctr++ */
9340 #define OP_NewRowid 70 /* synopsis: r[P2]=rowid */
9341 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9342 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9343 #define OP_Insert 73 /* synopsis: intkey=r[P3] data=r[P2] */
9344 #define OP_InsertInt 74 /* synopsis: intkey=P3 data=r[P2] */
9345 #define OP_Delete 75
9346 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9347 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9348 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9349 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9350 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9351 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9352 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9353 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9354 #define OP_ResetCount 84
9355 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9356 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9357 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9358 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9359 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9328,73 +9360,74 @@
9360 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9361 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9362 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9363 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9364 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9365 #define OP_SorterCompare 95 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9366 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9367 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9368 #define OP_SorterData 98 /* synopsis: r[P2]=data */
9369 #define OP_RowKey 99 /* synopsis: r[P2]=key */
9370 #define OP_RowData 100 /* synopsis: r[P2]=data */
9371 #define OP_Rowid 101 /* synopsis: r[P2]=rowid */
9372 #define OP_NullRow 102
9373 #define OP_Last 103
9374 #define OP_SorterSort 104
9375 #define OP_Sort 105
9376 #define OP_Rewind 106
9377 #define OP_SorterInsert 107
9378 #define OP_IdxInsert 108 /* synopsis: key=r[P2] */
9379 #define OP_IdxDelete 109 /* synopsis: key=r[P2@P3] */
9380 #define OP_IdxRowid 110 /* synopsis: r[P2]=rowid */
9381 #define OP_IdxLE 111 /* synopsis: key=r[P3@P4] */
9382 #define OP_IdxGT 112 /* synopsis: key=r[P3@P4] */
9383 #define OP_IdxLT 113 /* synopsis: key=r[P3@P4] */
9384 #define OP_IdxGE 114 /* synopsis: key=r[P3@P4] */
9385 #define OP_Destroy 115
9386 #define OP_Clear 116
9387 #define OP_ResetSorter 117
9388 #define OP_CreateIndex 118 /* synopsis: r[P2]=root iDb=P1 */
9389 #define OP_CreateTable 119 /* synopsis: r[P2]=root iDb=P1 */
9390 #define OP_ParseSchema 120
9391 #define OP_LoadAnalysis 121
9392 #define OP_DropTable 122
9393 #define OP_DropIndex 123
9394 #define OP_DropTrigger 124
9395 #define OP_IntegrityCk 125
9396 #define OP_RowSetAdd 126 /* synopsis: rowset(P1)=r[P2] */
9397 #define OP_RowSetRead 127 /* synopsis: r[P3]=rowset(P1) */
9398 #define OP_RowSetTest 128 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9399 #define OP_Program 129
9400 #define OP_Param 130
9401 #define OP_FkCounter 131 /* synopsis: fkctr[P1]+=P2 */
9402 #define OP_FkIfZero 132 /* synopsis: if fkctr[P1]==0 goto P2 */
9403 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9404 #define OP_MemMax 134 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9405 #define OP_IfPos 135 /* synopsis: if r[P1]>0 goto P2 */
9406 #define OP_IfNeg 136 /* synopsis: if r[P1]<0 goto P2 */
9407 #define OP_IfZero 137 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9408 #define OP_AggFinal 138 /* synopsis: accum=r[P1] N=P2 */
9409 #define OP_IncrVacuum 139
9410 #define OP_Expire 140
9411 #define OP_TableLock 141 /* synopsis: iDb=P1 root=P2 write=P3 */
9412 #define OP_VBegin 142
9413 #define OP_ToText 143 /* same as TK_TO_TEXT */
9414 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9415 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9416 #define OP_ToInt 146 /* same as TK_TO_INT */
9417 #define OP_ToReal 147 /* same as TK_TO_REAL */
9418 #define OP_VCreate 148
9419 #define OP_VDestroy 149
9420 #define OP_VOpen 150
9421 #define OP_VColumn 151 /* synopsis: r[P3]=vcolumn(P2) */
9422 #define OP_VNext 152
9423 #define OP_VRename 153
9424 #define OP_Pagecount 154
9425 #define OP_MaxPgcnt 155
9426 #define OP_Init 156 /* synopsis: Start at P2 */
9427 #define OP_Noop 157
9428 #define OP_Explain 158
9429
9430
9431 /* Properties such as "out2" or "jump" that are specified in
9432 ** comments following the "case" for each opcode in the vdbe.c
9433 ** are encoded into bitvectors as follows:
@@ -9412,23 +9445,23 @@
9445 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9446 /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9447 /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9448 /* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\
9449 /* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\
9450 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\
9451 /* 64 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x4c,\
9452 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9453 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9454 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9455 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
9456 /* 104 */ 0x01, 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01,\
9457 /* 112 */ 0x01, 0x01, 0x01, 0x02, 0x00, 0x00, 0x02, 0x02,\
9458 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
9459 /* 128 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x02, 0x08, 0x05,\
9460 /* 136 */ 0x05, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04,\
9461 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00,\
9462 /* 152 */ 0x01, 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9463
9464 /************** End of opcodes.h *********************************************/
9465 /************** Continuing where we left off in vdbe.h ***********************/
9466
9467 /*
@@ -10932,10 +10965,13 @@
10965 int tnum; /* Root BTree node for this table (see note above) */
10966 i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
10967 i16 nCol; /* Number of columns in this table */
10968 u16 nRef; /* Number of pointers to this Table */
10969 LogEst szTabRow; /* Estimated size of each table row in bytes */
10970 #ifdef SQLITE_ENABLE_COSTMULT
10971 LogEst costMult; /* Cost multiplier for using this table */
10972 #endif
10973 u8 tabFlags; /* Mask of TF_* values */
10974 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
10975 #ifndef SQLITE_OMIT_ALTERTABLE
10976 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
10977 #endif
@@ -11591,10 +11627,11 @@
11627 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11628 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11629 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11630 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
11631 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
11632 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
11633
11634 /* Allowed return values from sqlite3WhereIsDistinct()
11635 */
11636 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
11637 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -11847,13 +11884,23 @@
11884
11885 /*
11886 ** The yDbMask datatype for the bitmask of all attached databases.
11887 */
11888 #if SQLITE_MAX_ATTACHED>30
11889 typedef unsigned char yDbMask[(SQLITE_MAX_ATTACHED+9)/8];
11890 # define DbMaskTest(M,I) (((M)[(I)/8]&(1<<((I)&7)))!=0)
11891 # define DbMaskZero(M) memset((M),0,sizeof(M))
11892 # define DbMaskSet(M,I) (M)[(I)/8]|=(1<<((I)&7))
11893 # define DbMaskAllZero(M) sqlite3DbMaskAllZero(M)
11894 # define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0)
11895 #else
11896 typedef unsigned int yDbMask;
11897 # define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
11898 # define DbMaskZero(M) (M)=0
11899 # define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I))
11900 # define DbMaskAllZero(M) (M)==0
11901 # define DbMaskNonZero(M) (M)!=0
11902 #endif
11903
11904 /*
11905 ** An SQL parser context. A copy of this structure is passed through
11906 ** the parser and down into all the parser action routine in order to
@@ -12522,10 +12569,13 @@
12569 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
12570 #else
12571 # define sqlite3ViewGetColumnNames(A,B) 0
12572 #endif
12573
12574 #if SQLITE_MAX_ATTACHED>30
12575 SQLITE_PRIVATE int sqlite3DbMaskAllZero(yDbMask);
12576 #endif
12577 SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
12578 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
12579 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
12580 #ifndef SQLITE_OMIT_AUTOINCREMENT
12581 SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
@@ -12772,10 +12822,11 @@
12822 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
12823 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
12824 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
12825 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
12826 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
12827 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
12828 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
12829 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
12830 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
12831 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
12832
@@ -13884,10 +13935,11 @@
13935 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13936 Bool isEphemeral:1; /* True for an ephemeral table */
13937 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13938 Bool isTable:1; /* True if a table requiring integer keys */
13939 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13940 Pgno pgnoRoot; /* Root page of the open btree cursor */
13941 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13942 i64 seqCount; /* Sequence counter */
13943 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13944 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13945 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -22422,13 +22474,13 @@
22474 testcase( c==(+1) );
22475 }
22476 return c;
22477 }
22478
 
22479 /*
22480 ** Convert zNum to a 64-bit signed integer. zNum must be decimal. This
22481 ** routine does *not* accept hexadecimal notation.
22482 **
22483 ** If the zNum value is representable as a 64-bit twos-complement
22484 ** integer, then write that value into *pNum and return 0.
22485 **
22486 ** If zNum is exactly 9223372036854775808, return 2. This special
@@ -22511,14 +22563,48 @@
22563 assert( u-1==LARGEST_INT64 );
22564 return neg ? 0 : 2;
22565 }
22566 }
22567 }
22568
22569 /*
22570 ** Transform a UTF-8 integer literal, in either decimal or hexadecimal,
22571 ** into a 64-bit signed integer. This routine accepts hexadecimal literals,
22572 ** whereas sqlite3Atoi64() does not.
22573 **
22574 ** Returns:
22575 **
22576 ** 0 Successful transformation. Fits in a 64-bit signed integer.
22577 ** 1 Integer too large for a 64-bit signed integer or is malformed
22578 ** 2 Special case of 9223372036854775808
22579 */
22580 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
22581 #ifndef SQLITE_OMIT_HEX_INTEGER
22582 if( z[0]=='0'
22583 && (z[1]=='x' || z[1]=='X')
22584 && sqlite3Isxdigit(z[2])
22585 ){
22586 u64 u = 0;
22587 int i, k;
22588 for(i=2; z[i]=='0'; i++){}
22589 for(k=i; sqlite3Isxdigit(z[k]); k++){
22590 u = u*16 + sqlite3HexToInt(z[k]);
22591 }
22592 memcpy(pOut, &u, 8);
22593 return (z[k]==0 && k-i<=16) ? 0 : 1;
22594 }else
22595 #endif /* SQLITE_OMIT_HEX_INTEGER */
22596 {
22597 return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
22598 }
22599 }
22600
22601 /*
22602 ** If zNum represents an integer that will fit in 32-bits, then set
22603 ** *pValue to that integer and return true. Otherwise return false.
22604 **
22605 ** This routine accepts both decimal and hexadecimal notation for integers.
22606 **
22607 ** Any non-numeric characters that following zNum are ignored.
22608 ** This is different from sqlite3Atoi64() which requires the
22609 ** input number to be zero-terminated.
22610 */
@@ -22530,11 +22616,29 @@
22616 neg = 1;
22617 zNum++;
22618 }else if( zNum[0]=='+' ){
22619 zNum++;
22620 }
22621 #ifndef SQLITE_OMIT_HEX_INTEGER
22622 else if( zNum[0]=='0'
22623 && (zNum[1]=='x' || zNum[1]=='X')
22624 && sqlite3Isxdigit(zNum[2])
22625 ){
22626 u32 u = 0;
22627 zNum += 2;
22628 while( zNum[0]=='0' ) zNum++;
22629 for(i=0; sqlite3Isxdigit(zNum[i]) && i<8; i++){
22630 u = u*16 + sqlite3HexToInt(zNum[i]);
22631 }
22632 if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){
22633 memcpy(pValue, &u, 4);
22634 return 1;
22635 }else{
22636 return 0;
22637 }
22638 }
22639 #endif
22640 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
22641 v = v*10 + c;
22642 }
22643
22644 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -23606,43 +23710,43 @@
23710 /* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23711 /* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23712 /* 49 */ "Count" OpHelp("r[P2]=count()"),
23713 /* 50 */ "ReadCookie" OpHelp(""),
23714 /* 51 */ "SetCookie" OpHelp(""),
23715 /* 52 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
23716 /* 53 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23717 /* 54 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23718 /* 55 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23719 /* 56 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23720 /* 57 */ "SorterOpen" OpHelp(""),
23721 /* 58 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23722 /* 59 */ "Close" OpHelp(""),
23723 /* 60 */ "SeekLT" OpHelp(""),
23724 /* 61 */ "SeekLE" OpHelp(""),
23725 /* 62 */ "SeekGE" OpHelp(""),
23726 /* 63 */ "SeekGT" OpHelp(""),
23727 /* 64 */ "Seek" OpHelp("intkey=r[P2]"),
23728 /* 65 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23729 /* 66 */ "NotFound" OpHelp("key=r[P3@P4]"),
23730 /* 67 */ "Found" OpHelp("key=r[P3@P4]"),
23731 /* 68 */ "NotExists" OpHelp("intkey=r[P3]"),
23732 /* 69 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
23733 /* 70 */ "NewRowid" OpHelp("r[P2]=rowid"),
23734 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23735 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23736 /* 73 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23737 /* 74 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23738 /* 75 */ "Delete" OpHelp(""),
23739 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23740 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23741 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23742 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23743 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23744 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23745 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23746 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23747 /* 84 */ "ResetCount" OpHelp(""),
23748 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23749 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23750 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23751 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23752 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23649,73 +23753,74 @@
23753 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23754 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23755 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23756 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23757 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23758 /* 95 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23759 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23760 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23761 /* 98 */ "SorterData" OpHelp("r[P2]=data"),
23762 /* 99 */ "RowKey" OpHelp("r[P2]=key"),
23763 /* 100 */ "RowData" OpHelp("r[P2]=data"),
23764 /* 101 */ "Rowid" OpHelp("r[P2]=rowid"),
23765 /* 102 */ "NullRow" OpHelp(""),
23766 /* 103 */ "Last" OpHelp(""),
23767 /* 104 */ "SorterSort" OpHelp(""),
23768 /* 105 */ "Sort" OpHelp(""),
23769 /* 106 */ "Rewind" OpHelp(""),
23770 /* 107 */ "SorterInsert" OpHelp(""),
23771 /* 108 */ "IdxInsert" OpHelp("key=r[P2]"),
23772 /* 109 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23773 /* 110 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23774 /* 111 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23775 /* 112 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23776 /* 113 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23777 /* 114 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23778 /* 115 */ "Destroy" OpHelp(""),
23779 /* 116 */ "Clear" OpHelp(""),
23780 /* 117 */ "ResetSorter" OpHelp(""),
23781 /* 118 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23782 /* 119 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23783 /* 120 */ "ParseSchema" OpHelp(""),
23784 /* 121 */ "LoadAnalysis" OpHelp(""),
23785 /* 122 */ "DropTable" OpHelp(""),
23786 /* 123 */ "DropIndex" OpHelp(""),
23787 /* 124 */ "DropTrigger" OpHelp(""),
23788 /* 125 */ "IntegrityCk" OpHelp(""),
23789 /* 126 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23790 /* 127 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23791 /* 128 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23792 /* 129 */ "Program" OpHelp(""),
23793 /* 130 */ "Param" OpHelp(""),
23794 /* 131 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23795 /* 132 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23796 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23797 /* 134 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23798 /* 135 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23799 /* 136 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23800 /* 137 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23801 /* 138 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23802 /* 139 */ "IncrVacuum" OpHelp(""),
23803 /* 140 */ "Expire" OpHelp(""),
23804 /* 141 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23805 /* 142 */ "VBegin" OpHelp(""),
23806 /* 143 */ "ToText" OpHelp(""),
23807 /* 144 */ "ToBlob" OpHelp(""),
23808 /* 145 */ "ToNumeric" OpHelp(""),
23809 /* 146 */ "ToInt" OpHelp(""),
23810 /* 147 */ "ToReal" OpHelp(""),
23811 /* 148 */ "VCreate" OpHelp(""),
23812 /* 149 */ "VDestroy" OpHelp(""),
23813 /* 150 */ "VOpen" OpHelp(""),
23814 /* 151 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23815 /* 152 */ "VNext" OpHelp(""),
23816 /* 153 */ "VRename" OpHelp(""),
23817 /* 154 */ "Pagecount" OpHelp(""),
23818 /* 155 */ "MaxPgcnt" OpHelp(""),
23819 /* 156 */ "Init" OpHelp("Start at P2"),
23820 /* 157 */ "Noop" OpHelp(""),
23821 /* 158 */ "Explain" OpHelp(""),
23822 };
23823 return azName[i];
23824 }
23825 #endif
23826
@@ -62343,11 +62448,11 @@
62448 }
62449 sqlite3DbFree(p->db, pParse->aLabel);
62450 pParse->aLabel = 0;
62451 pParse->nLabel = 0;
62452 *pMaxFuncArgs = nMaxArgs;
62453 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
62454 }
62455
62456 /*
62457 ** Return the address of the next instruction to be inserted.
62458 */
@@ -62370,11 +62475,11 @@
62475 SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe *p, int *pnOp, int *pnMaxArg){
62476 VdbeOp *aOp = p->aOp;
62477 assert( aOp && !p->db->mallocFailed );
62478
62479 /* Check that sqlite3VdbeUsesBtree() was not called on this VM */
62480 assert( DbMaskAllZero(p->btreeMask) );
62481
62482 resolveP2Values(p, pnMaxArg);
62483 *pnOp = p->nOp;
62484 p->aOp = 0;
62485 return aOp;
@@ -62955,13 +63060,13 @@
63060 ** p->btreeMask of databases that will require a lock.
63061 */
63062 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
63063 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
63064 assert( i<(int)sizeof(p->btreeMask)*8 );
63065 DbMaskSet(p->btreeMask, i);
63066 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
63067 DbMaskSet(p->lockMask, i);
63068 }
63069 }
63070
63071 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
63072 /*
@@ -62985,20 +63090,19 @@
63090 ** this routine is N*N. But as N is rarely more than 1, this should not
63091 ** be a problem.
63092 */
63093 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){
63094 int i;
 
63095 sqlite3 *db;
63096 Db *aDb;
63097 int nDb;
63098 if( DbMaskAllZero(p->lockMask) ) return; /* The common case */
63099 db = p->db;
63100 aDb = db->aDb;
63101 nDb = db->nDb;
63102 for(i=0; i<nDb; i++){
63103 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
63104 sqlite3BtreeEnter(aDb[i].pBt);
63105 }
63106 }
63107 }
63108 #endif
@@ -63007,20 +63111,19 @@
63111 /*
63112 ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
63113 */
63114 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){
63115 int i;
 
63116 sqlite3 *db;
63117 Db *aDb;
63118 int nDb;
63119 if( DbMaskAllZero(p->lockMask) ) return; /* The common case */
63120 db = p->db;
63121 aDb = db->aDb;
63122 nDb = db->nDb;
63123 for(i=0; i<nDb; i++){
63124 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
63125 sqlite3BtreeLeave(aDb[i].pBt);
63126 }
63127 }
63128 }
63129 #endif
@@ -63987,11 +64090,11 @@
64090 int cnt = 0;
64091 int nWrite = 0;
64092 int nRead = 0;
64093 p = db->pVdbe;
64094 while( p ){
64095 if( sqlite3_stmt_busy((sqlite3_stmt*)p) ){
64096 cnt++;
64097 if( p->readOnly==0 ) nWrite++;
64098 if( p->bIsReader ) nRead++;
64099 }
64100 p = p->pNext;
@@ -67184,11 +67287,11 @@
67287 /*
67288 ** Return true if the prepared statement is in need of being reset.
67289 */
67290 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
67291 Vdbe *v = (Vdbe*)pStmt;
67292 return v!=0 && v->pc>=0 && v->magic==VDBE_MAGIC_RUN;
67293 }
67294
67295 /*
67296 ** Return a pointer to the next prepared statement after pStmt associated
67297 ** with database connection pDb. If pStmt is NULL, return the first
@@ -70641,11 +70744,11 @@
70744 int iGen;
70745
70746 assert( p->bIsReader );
70747 assert( p->readOnly==0 || pOp->p2==0 );
70748 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70749 assert( DbMaskTest(p->btreeMask, pOp->p1) );
70750 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
70751 rc = SQLITE_READONLY;
70752 goto abort_due_to_error;
70753 }
70754 pBt = db->aDb[pOp->p1].pBt;
@@ -70736,11 +70839,11 @@
70839 iDb = pOp->p1;
70840 iCookie = pOp->p3;
70841 assert( pOp->p3<SQLITE_N_BTREE_META );
70842 assert( iDb>=0 && iDb<db->nDb );
70843 assert( db->aDb[iDb].pBt!=0 );
70844 assert( DbMaskTest(p->btreeMask, iDb) );
70845
70846 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
70847 pOut->u.i = iMeta;
70848 break;
70849 }
@@ -70757,11 +70860,11 @@
70860 */
70861 case OP_SetCookie: { /* in3 */
70862 Db *pDb;
70863 assert( pOp->p2<SQLITE_N_BTREE_META );
70864 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70865 assert( DbMaskTest(p->btreeMask, pOp->p1) );
70866 assert( p->readOnly==0 );
70867 pDb = &db->aDb[pOp->p1];
70868 assert( pDb->pBt!=0 );
70869 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
70870 pIn3 = &aMem[pOp->p3];
@@ -70812,11 +70915,25 @@
70915 ** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
70916 ** structure, then said structure defines the content and collating
70917 ** sequence of the index being opened. Otherwise, if P4 is an integer
70918 ** value, it is set to the number of columns in the table.
70919 **
70920 ** See also: OpenWrite, ReopenIdx
70921 */
70922 /* Opcode: ReopenIdx P1 P2 P3 P4 P5
70923 ** Synopsis: root=P2 iDb=P3
70924 **
70925 ** The ReopenIdx opcode works exactly like ReadOpen except that it first
70926 ** checks to see if the cursor on P1 is already open with a root page
70927 ** number of P2 and if it is this opcode becomes a no-op. In other words,
70928 ** if the cursor is already open, do not reopen it.
70929 **
70930 ** The ReopenIdx opcode may only be used with P5==0 and with P4 being
70931 ** a P4_KEYINFO object. Furthermore, the P3 value must be the same as
70932 ** every other ReopenIdx or OpenRead for the same cursor number.
70933 **
70934 ** See the OpenRead opcode documentation for additional information.
70935 */
70936 /* Opcode: OpenWrite P1 P2 P3 P4 P5
70937 ** Synopsis: root=P2 iDb=P3
70938 **
70939 ** Open a read/write cursor named P1 on the table or index whose root
@@ -70834,10 +70951,23 @@
70951 ** in read/write mode. For a given table, there can be one or more read-only
70952 ** cursors or a single read/write cursor but not both.
70953 **
70954 ** See also OpenRead.
70955 */
70956 case OP_ReopenIdx: {
70957 VdbeCursor *pCur;
70958
70959 assert( pOp->p5==0 );
70960 assert( pOp->p4type==P4_KEYINFO );
70961 pCur = p->apCsr[pOp->p1];
70962 if( pCur && pCur->pgnoRoot==pOp->p2 ){
70963 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
70964 break;
70965 }
70966 /* If the cursor is not currently open or is open on a different
70967 ** index, then fall through into OP_OpenRead to force a reopen */
70968 }
70969 case OP_OpenRead:
70970 case OP_OpenWrite: {
70971 int nField;
70972 KeyInfo *pKeyInfo;
70973 int p2;
@@ -70848,11 +70978,12 @@
70978 Db *pDb;
70979
70980 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
70981 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
70982 assert( p->bIsReader );
70983 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
70984 || p->readOnly==0 );
70985
70986 if( p->expired ){
70987 rc = SQLITE_ABORT;
70988 break;
70989 }
@@ -70860,11 +70991,11 @@
70991 nField = 0;
70992 pKeyInfo = 0;
70993 p2 = pOp->p2;
70994 iDb = pOp->p3;
70995 assert( iDb>=0 && iDb<db->nDb );
70996 assert( DbMaskTest(p->btreeMask, iDb) );
70997 pDb = &db->aDb[iDb];
70998 pX = pDb->pBt;
70999 assert( pX!=0 );
71000 if( pOp->opcode==OP_OpenWrite ){
71001 wrFlag = 1;
@@ -70905,10 +71036,11 @@
71036 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
71037 pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
71038 if( pCur==0 ) goto no_mem;
71039 pCur->nullRow = 1;
71040 pCur->isOrdered = 1;
71041 pCur->pgnoRoot = p2;
71042 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
71043 pCur->pKeyInfo = pKeyInfo;
71044 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
71045 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
71046
@@ -72451,11 +72583,11 @@
72583 rc = SQLITE_LOCKED;
72584 p->errorAction = OE_Abort;
72585 }else{
72586 iDb = pOp->p3;
72587 assert( iCnt==1 );
72588 assert( DbMaskTest(p->btreeMask, iDb) );
72589 iMoved = 0; /* Not needed. Only to silence a warning. */
72590 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
72591 pOut->flags = MEM_Int;
72592 pOut->u.i = iMoved;
72593 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -72491,11 +72623,11 @@
72623 case OP_Clear: {
72624 int nChange;
72625
72626 nChange = 0;
72627 assert( p->readOnly==0 );
72628 assert( DbMaskTest(p->btreeMask, pOp->p2) );
72629 rc = sqlite3BtreeClearTable(
72630 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
72631 );
72632 if( pOp->p3 ){
72633 p->nChange += nChange;
@@ -72561,11 +72693,11 @@
72693 int flags;
72694 Db *pDb;
72695
72696 pgno = 0;
72697 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72698 assert( DbMaskTest(p->btreeMask, pOp->p1) );
72699 assert( p->readOnly==0 );
72700 pDb = &db->aDb[pOp->p1];
72701 assert( pDb->pBt!=0 );
72702 if( pOp->opcode==OP_CreateTable ){
72703 /* flags = BTREE_INTKEY; */
@@ -72726,11 +72858,11 @@
72858 for(j=0; j<nRoot; j++){
72859 aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
72860 }
72861 aRoot[j] = 0;
72862 assert( pOp->p5<db->nDb );
72863 assert( DbMaskTest(p->btreeMask, pOp->p5) );
72864 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
72865 (int)pnErr->u.i, &nErr);
72866 sqlite3DbFree(db, aRoot);
72867 pnErr->u.i -= nErr;
72868 sqlite3VdbeMemSetNull(pIn1);
@@ -73386,11 +73518,11 @@
73518 */
73519 case OP_IncrVacuum: { /* jump */
73520 Btree *pBt;
73521
73522 assert( pOp->p1>=0 && pOp->p1<db->nDb );
73523 assert( DbMaskTest(p->btreeMask, pOp->p1) );
73524 assert( p->readOnly==0 );
73525 pBt = db->aDb[pOp->p1].pBt;
73526 rc = sqlite3BtreeIncrVacuum(pBt);
73527 VdbeBranchTaken(rc==SQLITE_DONE,2);
73528 if( rc==SQLITE_DONE ){
@@ -73401,16 +73533,17 @@
73533 }
73534 #endif
73535
73536 /* Opcode: Expire P1 * * * *
73537 **
73538 ** Cause precompiled statements to expire. When an expired statement
73539 ** is executed using sqlite3_step() it will either automatically
73540 ** reprepare itself (if it was originally created using sqlite3_prepare_v2())
73541 ** or it will fail with SQLITE_SCHEMA.
73542 **
73543 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
73544 ** then only the currently executing statement is expired.
73545 */
73546 case OP_Expire: {
73547 if( !pOp->p1 ){
73548 sqlite3ExpirePreparedStatements(db);
73549 }else{
@@ -73438,11 +73571,11 @@
73571 case OP_TableLock: {
73572 u8 isWriteLock = (u8)pOp->p3;
73573 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
73574 int p1 = pOp->p1;
73575 assert( p1>=0 && p1<db->nDb );
73576 assert( DbMaskTest(p->btreeMask, p1) );
73577 assert( isWriteLock==0 || isWriteLock==1 );
73578 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
73579 if( (rc&0xFF)==SQLITE_LOCKED ){
73580 const char *z = pOp->p4.z;
73581 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
@@ -73888,11 +74021,11 @@
74021 #ifdef SQLITE_USE_FCNTL_TRACE
74022 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
74023 if( zTrace ){
74024 int i;
74025 for(i=0; i<db->nDb; i++){
74026 if( DbMaskTest(p->btreeMask, i)==0 ) continue;
74027 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
74028 }
74029 }
74030 #endif /* SQLITE_USE_FCNTL_TRACE */
74031 #ifdef SQLITE_DEBUG
@@ -79792,21 +79925,28 @@
79925 }else{
79926 int c;
79927 i64 value;
79928 const char *z = pExpr->u.zToken;
79929 assert( z!=0 );
79930 c = sqlite3DecOrHexToI64(z, &value);
79931 if( c==0 || (c==2 && negFlag) ){
79932 char *zV;
79933 if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
79934 zV = dup8bytes(v, (char*)&value);
79935 sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
79936 }else{
79937 #ifdef SQLITE_OMIT_FLOATING_POINT
79938 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
79939 #else
79940 #ifndef SQLITE_OMIT_HEX_INTEGER
79941 if( sqlite3_strnicmp(z,"0x",2)==0 ){
79942 sqlite3ErrorMsg(pParse, "hex literal too big: %s", z);
79943 }else
79944 #endif
79945 {
79946 codeReal(v, z, negFlag, iMem);
79947 }
79948 #endif
79949 }
79950 }
79951 }
79952
@@ -83913,20 +84053,20 @@
84053 ** ...
84054 ** regChng = N
84055 ** goto chng_addr_N
84056 */
84057 addrNextRow = sqlite3VdbeCurrentAddr(v);
84058 for(i=0; i<nCol-1; i++){
84059 char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
84060 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
84061 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
84062 aGotoChng[i] =
84063 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
84064 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
84065 VdbeCoverage(v);
84066 }
84067 sqlite3VdbeAddOp2(v, OP_Integer, nCol-1, regChng);
84068 aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
84069
84070 /*
84071 ** chng_addr_0:
84072 ** regPrev(0) = idx(0)
@@ -83933,11 +84073,11 @@
84073 ** chng_addr_1:
84074 ** regPrev(1) = idx(1)
84075 ** ...
84076 */
84077 sqlite3VdbeJumpHere(v, addrGotoChng0);
84078 for(i=0; i<nCol-1; i++){
84079 sqlite3VdbeJumpHere(v, aGotoChng[i]);
84080 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
84081 }
84082
84083 /*
@@ -84124,10 +84264,11 @@
84264 int i;
84265 char *z, *zDb;
84266 Table *pTab;
84267 Index *pIdx;
84268 Token *pTableName;
84269 Vdbe *v;
84270
84271 /* Read the database schema. If an error occurs, leave an error message
84272 ** and code in pParse and return NULL. */
84273 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
84274 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
@@ -84171,10 +84312,12 @@
84312 }
84313 sqlite3DbFree(db, z);
84314 }
84315 }
84316 }
84317 v = sqlite3GetVdbe(pParse);
84318 if( v ) sqlite3VdbeAddOp0(v, OP_Expire);
84319 }
84320
84321 /*
84322 ** Used to pass information from the analyzer reader through to the
84323 ** callback routine.
@@ -84229,18 +84372,23 @@
84372 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
84373 assert( pIndex!=0 );
84374 #else
84375 if( pIndex )
84376 #endif
84377 while( z[0] ){
84378 if( sqlite3_strglob("unordered*", z)==0 ){
84379 pIndex->bUnordered = 1;
84380 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
84381 pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3));
 
 
84382 }
84383 #ifdef SQLITE_ENABLE_COSTMULT
84384 else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
84385 pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9));
84386 }
84387 #endif
84388 while( z[0]!=0 && z[0]!=' ' ) z++;
84389 while( z[0]==' ' ) z++;
84390 }
84391 }
84392
84393 /*
84394 ** This callback is invoked once for each index when reading the
@@ -84277,15 +84425,19 @@
84425 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
84426 }
84427 z = argv[2];
84428
84429 if( pIndex ){
84430 pIndex->bUnordered = 0;
84431 decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
84432 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
84433 }else{
84434 Index fakeIdx;
84435 fakeIdx.szIdxRow = pTable->szTabRow;
84436 #ifdef SQLITE_ENABLE_COSTMULT
84437 fakeIdx.pTable = pTable;
84438 #endif
84439 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
84440 pTable->szTabRow = fakeIdx.szIdxRow;
84441 }
84442
84443 return 0;
@@ -85557,10 +85709,23 @@
85709 }
85710 #else
85711 #define codeTableLocks(x)
85712 #endif
85713
85714 /*
85715 ** Return TRUE if the given yDbMask object is empty - if it contains no
85716 ** 1 bits. This routine is used by the DbMaskAllZero() and DbMaskNotZero()
85717 ** macros when SQLITE_MAX_ATTACHED is greater than 30.
85718 */
85719 #if SQLITE_MAX_ATTACHED>30
85720 SQLITE_PRIVATE int sqlite3DbMaskAllZero(yDbMask m){
85721 int i;
85722 for(i=0; i<sizeof(yDbMask); i++) if( m[i] ) return 0;
85723 return 1;
85724 }
85725 #endif
85726
85727 /*
85728 ** This routine is called after a single SQL statement has been
85729 ** parsed and a VDBE program to execute that statement has been
85730 ** prepared. This routine puts the finishing touches on the
85731 ** VDBE program and resets the pParse structure for the next
@@ -85593,22 +85758,23 @@
85758 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
85759 ** set for each database that is used. Generate code to start a
85760 ** transaction on each used database and to verify the schema cookie
85761 ** on each used database.
85762 */
85763 if( db->mallocFailed==0
85764 && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
85765 ){
85766 int iDb, i;
85767 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
85768 sqlite3VdbeJumpHere(v, 0);
85769 for(iDb=0; iDb<db->nDb; iDb++){
85770 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
85771 sqlite3VdbeUsesBtree(v, iDb);
85772 sqlite3VdbeAddOp4Int(v,
85773 OP_Transaction, /* Opcode */
85774 iDb, /* P1 */
85775 DbMaskTest(pParse->writeMask,iDb), /* P2 */
85776 pParse->cookieValue[iDb], /* P3 */
85777 db->aDb[iDb].pSchema->iGeneration /* P4 */
85778 );
85779 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
85780 }
@@ -85660,11 +85826,11 @@
85826 }
85827 pParse->nTab = 0;
85828 pParse->nMem = 0;
85829 pParse->nSet = 0;
85830 pParse->nVar = 0;
85831 DbMaskZero(pParse->cookieMask);
85832 }
85833
85834 /*
85835 ** Run the parser and code generator recursively in order to generate
85836 ** code for the SQL statement given onto the end of the pParse context
@@ -89287,19 +89453,17 @@
89453 ** later, by sqlite3FinishCoding().
89454 */
89455 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
89456 Parse *pToplevel = sqlite3ParseToplevel(pParse);
89457 sqlite3 *db = pToplevel->db;
 
89458
89459 assert( iDb>=0 && iDb<db->nDb );
89460 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
89461 assert( iDb<SQLITE_MAX_ATTACHED+2 );
89462 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
89463 if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
89464 DbMaskSet(pToplevel->cookieMask, iDb);
 
89465 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
89466 if( !OMIT_TEMPDB && iDb==1 ){
89467 sqlite3OpenTempDatabase(pToplevel);
89468 }
89469 }
@@ -89334,11 +89498,11 @@
89498 ** necessary to undo a write and the checkpoint should not be set.
89499 */
89500 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
89501 Parse *pToplevel = sqlite3ParseToplevel(pParse);
89502 sqlite3CodeVerifySchema(pParse, iDb);
89503 DbMaskSet(pToplevel->writeMask, iDb);
89504 pToplevel->isMultiWrite |= setStatement;
89505 }
89506
89507 /*
89508 ** Indicate that the statement currently under construction might write
@@ -98590,11 +98754,11 @@
98754 */
98755 case PragTyp_JOURNAL_SIZE_LIMIT: {
98756 Pager *pPager = sqlite3BtreePager(pDb->pBt);
98757 i64 iLimit = -2;
98758 if( zRight ){
98759 sqlite3DecOrHexToI64(zRight, &iLimit);
98760 if( iLimit<-1 ) iLimit = -1;
98761 }
98762 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
98763 returnSingleInt(pParse, "journal_size_limit", iLimit);
98764 break;
@@ -98718,11 +98882,11 @@
98882 sqlite3_int64 sz;
98883 #if SQLITE_MAX_MMAP_SIZE>0
98884 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98885 if( zRight ){
98886 int ii;
98887 sqlite3DecOrHexToI64(zRight, &sz);
98888 if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
98889 if( pId2->n==0 ) db->szMmap = sz;
98890 for(ii=db->nDb-1; ii>=0; ii--){
98891 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
98892 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
@@ -99761,11 +99925,11 @@
99925 ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
99926 ** use -1.
99927 */
99928 case PragTyp_SOFT_HEAP_LIMIT: {
99929 sqlite3_int64 N;
99930 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
99931 sqlite3_soft_heap_limit64(N);
99932 }
99933 returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
99934 break;
99935 }
@@ -113609,10 +113773,11 @@
113773 int regRowid = 0; /* Register holding rowid */
113774 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
113775 int iRetInit; /* Address of regReturn init */
113776 int untestedTerms = 0; /* Some terms not completely tested */
113777 int ii; /* Loop counter */
113778 u16 wctrlFlags; /* Flags for sub-WHERE clause */
113779 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
113780 Table *pTab = pTabItem->pTab;
113781
113782 pTerm = pLoop->aLTerm[0];
113783 assert( pTerm!=0 );
@@ -113704,10 +113869,12 @@
113869
113870 /* Run a separate WHERE clause for each term of the OR clause. After
113871 ** eliminating duplicates from other WHERE clauses, the action for each
113872 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
113873 */
113874 wctrlFlags = WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
113875 WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY;
113876 for(ii=0; ii<pOrWc->nTerm; ii++){
113877 WhereTerm *pOrTerm = &pOrWc->a[ii];
113878 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
113879 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
113880 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -113716,12 +113883,11 @@
113883 pAndExpr->pLeft = pOrExpr;
113884 pOrExpr = pAndExpr;
113885 }
113886 /* Loop through table entries that match term pOrTerm. */
113887 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
113888 wctrlFlags, iCovCur);
 
113889 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
113890 if( pSubWInfo ){
113891 WhereLoop *pSubLoop;
113892 explainOneScan(
113893 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
@@ -113808,10 +113974,11 @@
113974 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
113975 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pSubLoop->u.btree.pIndex))
113976 ){
113977 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
113978 pCov = pSubLoop->u.btree.pIndex;
113979 wctrlFlags |= WHERE_REOPEN_IDX;
113980 }else{
113981 pCov = 0;
113982 }
113983
113984 /* Finish the loop through table entries that match term pOrTerm. */
@@ -114414,10 +114581,20 @@
114581 pLoop->nOut += (pTerm->truthProb<=0 ? pTerm->truthProb : -1);
114582 }
114583 }
114584 }
114585
114586 /*
114587 ** Adjust the cost C by the costMult facter T. This only occurs if
114588 ** compiled with -DSQLITE_ENABLE_COSTMULT
114589 */
114590 #ifdef SQLITE_ENABLE_COSTMULT
114591 # define ApplyCostMultiplier(C,T) C += T
114592 #else
114593 # define ApplyCostMultiplier(C,T)
114594 #endif
114595
114596 /*
114597 ** We have so far matched pBuilder->pNew->u.btree.nEq terms of the
114598 ** index pIndex. Try to match one more.
114599 **
114600 ** When this function is called, pBuilder->pNew->nOut contains the
@@ -114610,11 +114787,10 @@
114787 testcase( eOp & WO_ISNULL );
114788 rc = whereEqualScanEst(pParse, pBuilder, pExpr->pRight, &nOut);
114789 }else{
114790 rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut);
114791 }
 
114792 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
114793 if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */
114794 if( nOut ){
114795 pNew->nOut = sqlite3LogEst(nOut);
114796 if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut;
@@ -114642,10 +114818,11 @@
114818 rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
114819 pNew->rRun = sqlite3LogEstAdd(rLogSize, rCostIdx);
114820 if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){
114821 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut + 16);
114822 }
114823 ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult);
114824
114825 nOutUnadjusted = pNew->nOut;
114826 pNew->rRun += nInMul + nIn;
114827 pNew->nOut += nInMul + nIn;
114828 whereLoopOutputAdjust(pBuilder->pWC, pNew);
@@ -114761,10 +114938,18 @@
114938 ** cost = nSeek * (log(nRow) + (K+3.0) * nVisit) // non-covering index
114939 **
114940 ** Normally, nSeek is 1. nSeek values greater than 1 come about if the
114941 ** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
114942 ** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
114943 **
114944 ** The estimated values (nRow, nVisit, nSeek) often contain a large amount
114945 ** of uncertainty. For this reason, scoring is designed to pick plans that
114946 ** "do the least harm" if the estimates are inaccurate. For example, a
114947 ** log(nRow) factor is omitted from a non-covering index scan in order to
114948 ** bias the scoring in favor of using an index, since the worst-case
114949 ** performance of using an index is far better than the worst-case performance
114950 ** of a full table scan.
114951 */
114952 static int whereLoopAddBtree(
114953 WhereLoopBuilder *pBuilder, /* WHERE clause information */
114954 Bitmask mExtra /* Extra prerequesites for using this table */
114955 ){
@@ -114848,10 +115033,11 @@
115033 pNew->aLTerm[0] = pTerm;
115034 /* TUNING: One-time cost for computing the automatic index is
115035 ** approximately 7*N*log2(N) where N is the number of rows in
115036 ** the table being indexed. */
115037 pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
115038 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
115039 /* TUNING: Each index lookup yields 20 rows in the table. This
115040 ** is more than the usual guess of 10 rows, since we have no way
115041 ** of knowning how selective the index will ultimately be. It would
115042 ** not be unreasonable to make this value much larger. */
115043 pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
@@ -114889,10 +115075,11 @@
115075
115076 /* Full table scan */
115077 pNew->iSortIdx = b ? iSortIdx : 0;
115078 /* TUNING: Cost of full table scan is (N*3.0). */
115079 pNew->rRun = rSize + 16;
115080 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
115081 whereLoopOutputAdjust(pWC, pNew);
115082 rc = whereLoopInsert(pBuilder, pNew);
115083 pNew->nOut = rSize;
115084 if( rc ) break;
115085 }else{
@@ -114924,11 +115111,11 @@
115111 ** also add the cost of visiting table rows (N*3.0). */
115112 pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow;
115113 if( m!=0 ){
115114 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16);
115115 }
115116 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
115117 whereLoopOutputAdjust(pWC, pNew);
115118 rc = whereLoopInsert(pBuilder, pNew);
115119 pNew->nOut = rSize;
115120 if( rc ) break;
115121 }
@@ -116399,10 +116586,11 @@
116586 }
116587 op = OP_OpenWrite;
116588 pWInfo->aiCurOnePass[1] = iIndexCur;
116589 }else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){
116590 iIndexCur = iIdxCur;
116591 if( wctrlFlags & WHERE_REOPEN_IDX ) op = OP_ReopenIdx;
116592 }else{
116593 iIndexCur = pParse->nTab++;
116594 }
116595 pLevel->iIdxCur = iIndexCur;
116596 assert( pIx->pSchema==pTab->pSchema );
@@ -120723,10 +120911,16 @@
120911 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
120912 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
120913 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
120914 testcase( z[0]=='9' );
120915 *tokenType = TK_INTEGER;
120916 #ifndef SQLITE_OMIT_HEX_INTEGER
120917 if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
120918 for(i=3; sqlite3Isxdigit(z[i]); i++){}
120919 return i;
120920 }
120921 #endif
120922 for(i=0; sqlite3Isdigit(z[i]); i++){}
120923 #ifndef SQLITE_OMIT_FLOATING_POINT
120924 if( z[i]=='.' ){
120925 i++;
120926 while( sqlite3Isdigit(z[i]) ){ i++; }
@@ -123444,12 +123638,12 @@
123638 # error SQLITE_MAX_VDBE_OP must be at least 40
123639 #endif
123640 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
123641 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
123642 #endif
123643 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
123644 # error SQLITE_MAX_ATTACHED must be between 0 and 125
123645 #endif
123646 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
123647 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
123648 #endif
123649 #if SQLITE_MAX_COLUMN>32767
@@ -124752,11 +124946,11 @@
124946 const char *zParam, /* URI parameter sought */
124947 sqlite3_int64 bDflt /* return if parameter is missing */
124948 ){
124949 const char *z = sqlite3_uri_parameter(zFilename, zParam);
124950 sqlite3_int64 v;
124951 if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){
124952 bDflt = v;
124953 }
124954 return bDflt;
124955 }
124956
@@ -126283,11 +126477,11 @@
126477
126478 /* fts3_tokenize_vtab.c */
126479 SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *);
126480
126481 /* fts3_unicode2.c (functions generated by parsing unicode text files) */
126482 #ifndef SQLITE_DISABLE_FTS3_UNICODE
126483 SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int);
126484 SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int);
126485 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
126486 #endif
126487
@@ -129753,11 +129947,11 @@
129947 ** to by the argument to point to the "simple" tokenizer implementation.
129948 ** And so on.
129949 */
129950 SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129951 SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129952 #ifndef SQLITE_DISABLE_FTS3_UNICODE
129953 SQLITE_PRIVATE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const**ppModule);
129954 #endif
129955 #ifdef SQLITE_ENABLE_ICU
129956 SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
129957 #endif
@@ -129771,20 +129965,20 @@
129965 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
129966 int rc = SQLITE_OK;
129967 Fts3Hash *pHash = 0;
129968 const sqlite3_tokenizer_module *pSimple = 0;
129969 const sqlite3_tokenizer_module *pPorter = 0;
129970 #ifndef SQLITE_DISABLE_FTS3_UNICODE
129971 const sqlite3_tokenizer_module *pUnicode = 0;
129972 #endif
129973
129974 #ifdef SQLITE_ENABLE_ICU
129975 const sqlite3_tokenizer_module *pIcu = 0;
129976 sqlite3Fts3IcuTokenizerModule(&pIcu);
129977 #endif
129978
129979 #ifndef SQLITE_DISABLE_FTS3_UNICODE
129980 sqlite3Fts3UnicodeTokenizer(&pUnicode);
129981 #endif
129982
129983 #ifdef SQLITE_TEST
129984 rc = sqlite3Fts3InitTerm(db);
@@ -129808,11 +130002,11 @@
130002 /* Load the built-in tokenizers into the hash table */
130003 if( rc==SQLITE_OK ){
130004 if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
130005 || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
130006
130007 #ifndef SQLITE_DISABLE_FTS3_UNICODE
130008 || sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode)
130009 #endif
130010 #ifdef SQLITE_ENABLE_ICU
130011 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
130012 #endif
@@ -143068,11 +143262,11 @@
143262 ******************************************************************************
143263 **
143264 ** Implementation of the "unicode" full-text-search tokenizer.
143265 */
143266
143267 #ifndef SQLITE_DISABLE_FTS3_UNICODE
143268
143269 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
143270
143271 /* #include <assert.h> */
143272 /* #include <stdlib.h> */
@@ -143284,11 +143478,11 @@
143478 memset(pNew, 0, sizeof(unicode_tokenizer));
143479 pNew->bRemoveDiacritic = 1;
143480
143481 for(i=0; rc==SQLITE_OK && i<nArg; i++){
143482 const char *z = azArg[i];
143483 int n = (int)strlen(z);
143484
143485 if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){
143486 pNew->bRemoveDiacritic = 1;
143487 }
143488 else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){
@@ -143416,15 +143610,15 @@
143610 }while( unicodeIsAlnum(p, iCode)
143611 || sqlite3FtsUnicodeIsdiacritic(iCode)
143612 );
143613
143614 /* Set the output variables and return. */
143615 pCsr->iOff = (int)(z - pCsr->aInput);
143616 *paToken = pCsr->zToken;
143617 *pnToken = (int)(zOut - pCsr->zToken);
143618 *piStart = (int)(zStart - pCsr->aInput);
143619 *piEnd = (int)(zEnd - pCsr->aInput);
143620 *piPos = pCsr->iToken++;
143621 return SQLITE_OK;
143622 }
143623
143624 /*
@@ -143443,11 +143637,11 @@
143637 };
143638 *ppModule = &module;
143639 }
143640
143641 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
143642 #endif /* ifndef SQLITE_DISABLE_FTS3_UNICODE */
143643
143644 /************** End of fts3_unicode.c ****************************************/
143645 /************** Begin file fts3_unicode2.c ***********************************/
143646 /*
143647 ** 2012 May 25
@@ -143464,11 +143658,11 @@
143658
143659 /*
143660 ** DO NOT EDIT THIS MACHINE GENERATED FILE.
143661 */
143662
143663 #ifndef SQLITE_DISABLE_FTS3_UNICODE
143664 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
143665
143666 /* #include <assert.h> */
143667
143668 /*
@@ -143811,11 +144005,11 @@
144005 }
144006
144007 return ret;
144008 }
144009 #endif /* defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) */
144010 #endif /* !defined(SQLITE_DISABLE_FTS3_UNICODE) */
144011
144012 /************** End of fts3_unicode2.c ***************************************/
144013 /************** Begin file rtree.c *******************************************/
144014 /*
144015 ** 2001 September 15
144016
+45 -13
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.6"
111111
#define SQLITE_VERSION_NUMBER 3008006
112
-#define SQLITE_SOURCE_ID "2014-07-01 11:54:02 21981e35062cc6b30e9576786cbf55265a7a4d41"
112
+#define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2035,31 +2035,37 @@
20352035
SQLITE_API int sqlite3_complete16(const void *sql);
20362036
20372037
/*
20382038
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
20392039
**
2040
-** ^This routine sets a callback function that might be invoked whenever
2041
-** an attempt is made to open a database table that another thread
2042
-** or process has locked.
2040
+** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2041
+** that might be invoked with argument P whenever
2042
+** an attempt is made to access a database table associated with
2043
+** [database connection] D when another thread
2044
+** or process has the table locked.
2045
+** The sqlite3_busy_handler() interface is used to implement
2046
+** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
20432047
**
20442048
** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
20452049
** is returned immediately upon encountering the lock. ^If the busy callback
20462050
** is not NULL, then the callback might be invoked with two arguments.
20472051
**
20482052
** ^The first argument to the busy handler is a copy of the void* pointer which
20492053
** is the third argument to sqlite3_busy_handler(). ^The second argument to
20502054
** the busy handler callback is the number of times that the busy handler has
2051
-** been invoked for this locking event. ^If the
2055
+** been invoked for the same locking event. ^If the
20522056
** busy callback returns 0, then no additional attempts are made to
2053
-** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
2057
+** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned
2058
+** to the application.
20542059
** ^If the callback returns non-zero, then another attempt
2055
-** is made to open the database for reading and the cycle repeats.
2060
+** is made to access the database and the cycle repeats.
20562061
**
20572062
** The presence of a busy handler does not guarantee that it will be invoked
20582063
** when there is lock contention. ^If SQLite determines that invoking the busy
20592064
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2060
-** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
2065
+** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the
2066
+** busy handler.
20612067
** Consider a scenario where one process is holding a read lock that
20622068
** it is trying to promote to a reserved lock and
20632069
** a second process is holding a reserved lock that it is trying
20642070
** to promote to an exclusive lock. The first process cannot proceed
20652071
** because it is blocked by the second and the second process cannot
@@ -2087,14 +2093,16 @@
20872093
** this is important.
20882094
**
20892095
** ^(There can only be a single busy handler defined for each
20902096
** [database connection]. Setting a new busy handler clears any
20912097
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
2092
-** will also set or clear the busy handler.
2098
+** or evaluating [PRAGMA busy_timeout=N] will change the
2099
+** busy handler and thus clear any previously set busy handler.
20932100
**
20942101
** The busy callback should not take any actions which modify the
2095
-** database connection that invoked the busy handler. Any such actions
2102
+** database connection that invoked the busy handler. In other words,
2103
+** the busy handler is not reentrant. Any such actions
20962104
** result in undefined behavior.
20972105
**
20982106
** A busy handler must not close the database connection
20992107
** or [prepared statement] that invoked the busy handler.
21002108
*/
@@ -2115,10 +2123,12 @@
21152123
**
21162124
** ^(There can only be a single busy handler for a particular
21172125
** [database connection] any any given moment. If another busy handler
21182126
** was defined (using [sqlite3_busy_handler()]) prior to calling
21192127
** this routine, that other busy handler is cleared.)^
2128
+**
2129
+** See also: [PRAGMA busy_timeout]
21202130
*/
21212131
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
21222132
21232133
/*
21242134
** CAPI3REF: Convenience Routines For Running Queries
@@ -4703,10 +4713,17 @@
47034713
** the name of a folder (a.k.a. directory), then all temporary files
47044714
** created by SQLite when using a built-in [sqlite3_vfs | VFS]
47054715
** will be placed in that directory.)^ ^If this variable
47064716
** is a NULL pointer, then SQLite performs a search for an appropriate
47074717
** temporary file directory.
4718
+**
4719
+** Applications are strongly discouraged from using this global variable.
4720
+** It is required to set a temporary folder on Windows Runtime (WinRT).
4721
+** But for all other platforms, it is highly recommended that applications
4722
+** neither read nor write this variable. This global variable is a relic
4723
+** that exists for backwards compatibility of legacy applications and should
4724
+** be avoided in new projects.
47084725
**
47094726
** It is not safe to read or modify this variable in more than one
47104727
** thread at a time. It is not safe to read or modify this variable
47114728
** if a [database connection] is being used at the same time in a separate
47124729
** thread.
@@ -4722,10 +4739,15 @@
47224739
** [sqlite3_malloc] and the pragma may attempt to free that memory
47234740
** using [sqlite3_free].
47244741
** Hence, if this variable is modified directly, either it should be
47254742
** made NULL or made to point to memory obtained from [sqlite3_malloc]
47264743
** or else the use of the [temp_store_directory pragma] should be avoided.
4744
+** Except when requested by the [temp_store_directory pragma], SQLite
4745
+** does not free the memory that sqlite3_temp_directory points to. If
4746
+** the application wants that memory to be freed, it must do
4747
+** so itself, taking care to only do so after all [database connection]
4748
+** objects have been destroyed.
47274749
**
47284750
** <b>Note to Windows Runtime users:</b> The temporary directory must be set
47294751
** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
47304752
** features that require the use of temporary files may fail. Here is an
47314753
** example of how to do this using C++ with the Windows Runtime:
@@ -7141,10 +7163,13 @@
71417163
** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
71427164
** configured by this function.
71437165
**
71447166
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
71457167
** from SQL.
7168
+**
7169
+** ^Checkpoints initiated by this mechanism are
7170
+** [sqlite3_wal_checkpoint_v2|PASSIVE].
71467171
**
71477172
** ^Every new [database connection] defaults to having the auto-checkpoint
71487173
** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
71497174
** pages. The use of this interface
71507175
** is only necessary if the default setting is found to be suboptimal
@@ -7158,10 +7183,14 @@
71587183
** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
71597184
** on [database connection] D to be [checkpointed]. ^If X is NULL or an
71607185
** empty string, then a checkpoint is run on all databases of
71617186
** connection D. ^If the database connection D is not in
71627187
** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7188
+** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7189
+** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7190
+** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7191
+** or RESET checkpoint.
71637192
**
71647193
** ^The [wal_checkpoint pragma] can be used to invoke this interface
71657194
** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
71667195
** [wal_autocheckpoint pragma] can be used to cause this interface to be
71677196
** run whenever the WAL reaches a certain size threshold.
@@ -7180,22 +7209,25 @@
71807209
** <dl>
71817210
** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
71827211
** Checkpoint as many frames as possible without waiting for any database
71837212
** readers or writers to finish. Sync the db file if all frames in the log
71847213
** are checkpointed. This mode is the same as calling
7185
-** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked.
7214
+** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7215
+** is never invoked.
71867216
**
71877217
** <dt>SQLITE_CHECKPOINT_FULL<dd>
7188
-** This mode blocks (calls the busy-handler callback) until there is no
7218
+** This mode blocks (it invokes the
7219
+** [sqlite3_busy_handler|busy-handler callback]) until there is no
71897220
** database writer and all readers are reading from the most recent database
71907221
** snapshot. It then checkpoints all frames in the log file and syncs the
71917222
** database file. This call blocks database writers while it is running,
71927223
** but not database readers.
71937224
**
71947225
** <dt>SQLITE_CHECKPOINT_RESTART<dd>
71957226
** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7196
-** checkpointing the log file it blocks (calls the busy-handler callback)
7227
+** checkpointing the log file it blocks (calls the
7228
+** [sqlite3_busy_handler|busy-handler callback])
71977229
** until all readers are reading from the database file only. This ensures
71987230
** that the next client to write to the database file restarts the log file
71997231
** from the beginning. This call blocks database writers while it is running,
72007232
** but not database readers.
72017233
** </dl>
72027234
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.6"
111 #define SQLITE_VERSION_NUMBER 3008006
112 #define SQLITE_SOURCE_ID "2014-07-01 11:54:02 21981e35062cc6b30e9576786cbf55265a7a4d41"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2035,31 +2035,37 @@
2035 SQLITE_API int sqlite3_complete16(const void *sql);
2036
2037 /*
2038 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2039 **
2040 ** ^This routine sets a callback function that might be invoked whenever
2041 ** an attempt is made to open a database table that another thread
2042 ** or process has locked.
 
 
 
 
2043 **
2044 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2045 ** is returned immediately upon encountering the lock. ^If the busy callback
2046 ** is not NULL, then the callback might be invoked with two arguments.
2047 **
2048 ** ^The first argument to the busy handler is a copy of the void* pointer which
2049 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2050 ** the busy handler callback is the number of times that the busy handler has
2051 ** been invoked for this locking event. ^If the
2052 ** busy callback returns 0, then no additional attempts are made to
2053 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
 
2054 ** ^If the callback returns non-zero, then another attempt
2055 ** is made to open the database for reading and the cycle repeats.
2056 **
2057 ** The presence of a busy handler does not guarantee that it will be invoked
2058 ** when there is lock contention. ^If SQLite determines that invoking the busy
2059 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2060 ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
 
2061 ** Consider a scenario where one process is holding a read lock that
2062 ** it is trying to promote to a reserved lock and
2063 ** a second process is holding a reserved lock that it is trying
2064 ** to promote to an exclusive lock. The first process cannot proceed
2065 ** because it is blocked by the second and the second process cannot
@@ -2087,14 +2093,16 @@
2087 ** this is important.
2088 **
2089 ** ^(There can only be a single busy handler defined for each
2090 ** [database connection]. Setting a new busy handler clears any
2091 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
2092 ** will also set or clear the busy handler.
 
2093 **
2094 ** The busy callback should not take any actions which modify the
2095 ** database connection that invoked the busy handler. Any such actions
 
2096 ** result in undefined behavior.
2097 **
2098 ** A busy handler must not close the database connection
2099 ** or [prepared statement] that invoked the busy handler.
2100 */
@@ -2115,10 +2123,12 @@
2115 **
2116 ** ^(There can only be a single busy handler for a particular
2117 ** [database connection] any any given moment. If another busy handler
2118 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2119 ** this routine, that other busy handler is cleared.)^
 
 
2120 */
2121 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2122
2123 /*
2124 ** CAPI3REF: Convenience Routines For Running Queries
@@ -4703,10 +4713,17 @@
4703 ** the name of a folder (a.k.a. directory), then all temporary files
4704 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
4705 ** will be placed in that directory.)^ ^If this variable
4706 ** is a NULL pointer, then SQLite performs a search for an appropriate
4707 ** temporary file directory.
 
 
 
 
 
 
 
4708 **
4709 ** It is not safe to read or modify this variable in more than one
4710 ** thread at a time. It is not safe to read or modify this variable
4711 ** if a [database connection] is being used at the same time in a separate
4712 ** thread.
@@ -4722,10 +4739,15 @@
4722 ** [sqlite3_malloc] and the pragma may attempt to free that memory
4723 ** using [sqlite3_free].
4724 ** Hence, if this variable is modified directly, either it should be
4725 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4726 ** or else the use of the [temp_store_directory pragma] should be avoided.
 
 
 
 
 
4727 **
4728 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
4729 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
4730 ** features that require the use of temporary files may fail. Here is an
4731 ** example of how to do this using C++ with the Windows Runtime:
@@ -7141,10 +7163,13 @@
7141 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
7142 ** configured by this function.
7143 **
7144 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
7145 ** from SQL.
 
 
 
7146 **
7147 ** ^Every new [database connection] defaults to having the auto-checkpoint
7148 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
7149 ** pages. The use of this interface
7150 ** is only necessary if the default setting is found to be suboptimal
@@ -7158,10 +7183,14 @@
7158 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7159 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7160 ** empty string, then a checkpoint is run on all databases of
7161 ** connection D. ^If the database connection D is not in
7162 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
 
 
 
 
7163 **
7164 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
7165 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7166 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
7167 ** run whenever the WAL reaches a certain size threshold.
@@ -7180,22 +7209,25 @@
7180 ** <dl>
7181 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7182 ** Checkpoint as many frames as possible without waiting for any database
7183 ** readers or writers to finish. Sync the db file if all frames in the log
7184 ** are checkpointed. This mode is the same as calling
7185 ** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked.
 
7186 **
7187 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7188 ** This mode blocks (calls the busy-handler callback) until there is no
 
7189 ** database writer and all readers are reading from the most recent database
7190 ** snapshot. It then checkpoints all frames in the log file and syncs the
7191 ** database file. This call blocks database writers while it is running,
7192 ** but not database readers.
7193 **
7194 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7195 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7196 ** checkpointing the log file it blocks (calls the busy-handler callback)
 
7197 ** until all readers are reading from the database file only. This ensures
7198 ** that the next client to write to the database file restarts the log file
7199 ** from the beginning. This call blocks database writers while it is running,
7200 ** but not database readers.
7201 ** </dl>
7202
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.6"
111 #define SQLITE_VERSION_NUMBER 3008006
112 #define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2035,31 +2035,37 @@
2035 SQLITE_API int sqlite3_complete16(const void *sql);
2036
2037 /*
2038 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2039 **
2040 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2041 ** that might be invoked with argument P whenever
2042 ** an attempt is made to access a database table associated with
2043 ** [database connection] D when another thread
2044 ** or process has the table locked.
2045 ** The sqlite3_busy_handler() interface is used to implement
2046 ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
2047 **
2048 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2049 ** is returned immediately upon encountering the lock. ^If the busy callback
2050 ** is not NULL, then the callback might be invoked with two arguments.
2051 **
2052 ** ^The first argument to the busy handler is a copy of the void* pointer which
2053 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2054 ** the busy handler callback is the number of times that the busy handler has
2055 ** been invoked for the same locking event. ^If the
2056 ** busy callback returns 0, then no additional attempts are made to
2057 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned
2058 ** to the application.
2059 ** ^If the callback returns non-zero, then another attempt
2060 ** is made to access the database and the cycle repeats.
2061 **
2062 ** The presence of a busy handler does not guarantee that it will be invoked
2063 ** when there is lock contention. ^If SQLite determines that invoking the busy
2064 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2065 ** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the
2066 ** busy handler.
2067 ** Consider a scenario where one process is holding a read lock that
2068 ** it is trying to promote to a reserved lock and
2069 ** a second process is holding a reserved lock that it is trying
2070 ** to promote to an exclusive lock. The first process cannot proceed
2071 ** because it is blocked by the second and the second process cannot
@@ -2087,14 +2093,16 @@
2093 ** this is important.
2094 **
2095 ** ^(There can only be a single busy handler defined for each
2096 ** [database connection]. Setting a new busy handler clears any
2097 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
2098 ** or evaluating [PRAGMA busy_timeout=N] will change the
2099 ** busy handler and thus clear any previously set busy handler.
2100 **
2101 ** The busy callback should not take any actions which modify the
2102 ** database connection that invoked the busy handler. In other words,
2103 ** the busy handler is not reentrant. Any such actions
2104 ** result in undefined behavior.
2105 **
2106 ** A busy handler must not close the database connection
2107 ** or [prepared statement] that invoked the busy handler.
2108 */
@@ -2115,10 +2123,12 @@
2123 **
2124 ** ^(There can only be a single busy handler for a particular
2125 ** [database connection] any any given moment. If another busy handler
2126 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2127 ** this routine, that other busy handler is cleared.)^
2128 **
2129 ** See also: [PRAGMA busy_timeout]
2130 */
2131 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2132
2133 /*
2134 ** CAPI3REF: Convenience Routines For Running Queries
@@ -4703,10 +4713,17 @@
4713 ** the name of a folder (a.k.a. directory), then all temporary files
4714 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
4715 ** will be placed in that directory.)^ ^If this variable
4716 ** is a NULL pointer, then SQLite performs a search for an appropriate
4717 ** temporary file directory.
4718 **
4719 ** Applications are strongly discouraged from using this global variable.
4720 ** It is required to set a temporary folder on Windows Runtime (WinRT).
4721 ** But for all other platforms, it is highly recommended that applications
4722 ** neither read nor write this variable. This global variable is a relic
4723 ** that exists for backwards compatibility of legacy applications and should
4724 ** be avoided in new projects.
4725 **
4726 ** It is not safe to read or modify this variable in more than one
4727 ** thread at a time. It is not safe to read or modify this variable
4728 ** if a [database connection] is being used at the same time in a separate
4729 ** thread.
@@ -4722,10 +4739,15 @@
4739 ** [sqlite3_malloc] and the pragma may attempt to free that memory
4740 ** using [sqlite3_free].
4741 ** Hence, if this variable is modified directly, either it should be
4742 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4743 ** or else the use of the [temp_store_directory pragma] should be avoided.
4744 ** Except when requested by the [temp_store_directory pragma], SQLite
4745 ** does not free the memory that sqlite3_temp_directory points to. If
4746 ** the application wants that memory to be freed, it must do
4747 ** so itself, taking care to only do so after all [database connection]
4748 ** objects have been destroyed.
4749 **
4750 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
4751 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
4752 ** features that require the use of temporary files may fail. Here is an
4753 ** example of how to do this using C++ with the Windows Runtime:
@@ -7141,10 +7163,13 @@
7163 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
7164 ** configured by this function.
7165 **
7166 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
7167 ** from SQL.
7168 **
7169 ** ^Checkpoints initiated by this mechanism are
7170 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
7171 **
7172 ** ^Every new [database connection] defaults to having the auto-checkpoint
7173 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
7174 ** pages. The use of this interface
7175 ** is only necessary if the default setting is found to be suboptimal
@@ -7158,10 +7183,14 @@
7183 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7184 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7185 ** empty string, then a checkpoint is run on all databases of
7186 ** connection D. ^If the database connection D is not in
7187 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7188 ** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7189 ** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7190 ** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7191 ** or RESET checkpoint.
7192 **
7193 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
7194 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7195 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
7196 ** run whenever the WAL reaches a certain size threshold.
@@ -7180,22 +7209,25 @@
7209 ** <dl>
7210 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7211 ** Checkpoint as many frames as possible without waiting for any database
7212 ** readers or writers to finish. Sync the db file if all frames in the log
7213 ** are checkpointed. This mode is the same as calling
7214 ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7215 ** is never invoked.
7216 **
7217 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7218 ** This mode blocks (it invokes the
7219 ** [sqlite3_busy_handler|busy-handler callback]) until there is no
7220 ** database writer and all readers are reading from the most recent database
7221 ** snapshot. It then checkpoints all frames in the log file and syncs the
7222 ** database file. This call blocks database writers while it is running,
7223 ** but not database readers.
7224 **
7225 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7226 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7227 ** checkpointing the log file it blocks (calls the
7228 ** [sqlite3_busy_handler|busy-handler callback])
7229 ** until all readers are reading from the database file only. This ensures
7230 ** that the next client to write to the database file restarts the log file
7231 ** from the beginning. This call blocks database writers while it is running,
7232 ** but not database readers.
7233 ** </dl>
7234

Keyboard Shortcuts

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