Fossil SCM

Update the built-in SQLite to the latest 3.8.8 beta.

drh 2015-01-11 00:06 trunk
Commit 5c8f33d6a829dfaa61a69501074b885c1aaf2059
3 files changed +252 -129 +255 -191 +13 -5
+252 -129
--- src/shell.c
+++ src/shell.c
@@ -46,21 +46,20 @@
4646
# endif
4747
# include <unistd.h>
4848
# include <sys/types.h>
4949
#endif
5050
51
-#if defined(HAVE_READLINE) && HAVE_READLINE!=0
51
+#if HAVE_READLINE
5252
# include <readline/readline.h>
5353
# include <readline/history.h>
54
-#else
55
-# undef HAVE_READLINE
5654
#endif
57
-#if defined(HAVE_EDITLINE) && !defined(HAVE_READLINE)
55
+#if HAVE_EDITLINE
56
+# undef HAVE_READLINE
5857
# define HAVE_READLINE 1
5958
# include <editline/readline.h>
6059
#endif
61
-#if !defined(HAVE_READLINE)
60
+#if !HAVE_READLINE
6261
# define add_history(X)
6362
# define read_history(X)
6463
# define write_history(X)
6564
# define stifle_history(X)
6665
#endif
@@ -423,11 +422,11 @@
423422
char *zResult;
424423
if( in!=0 ){
425424
zResult = local_getline(zPrior, in);
426425
}else{
427426
zPrompt = isContinuation ? continuePrompt : mainPrompt;
428
-#if defined(HAVE_READLINE)
427
+#if HAVE_READLINE
429428
free(zPrior);
430429
zResult = readline(zPrompt);
431430
if( zResult && *zResult ) add_history(zResult);
432431
#else
433432
printf("%s", zPrompt);
@@ -469,15 +468,15 @@
469468
int mode; /* An output mode setting */
470469
int writableSchema; /* True if PRAGMA writable_schema=ON */
471470
int showHeader; /* True to show column names in List or Column mode */
472471
unsigned shellFlgs; /* Various flags */
473472
char *zDestTable; /* Name of destination table when MODE_Insert */
474
- char separator[20]; /* Separator character for MODE_List */
475
- char newline[20]; /* Record separator in MODE_Csv */
473
+ char colSeparator[20]; /* Column separator character for several modes */
474
+ char rowSeparator[20]; /* Row separator character for MODE_Ascii */
476475
int colWidth[100]; /* Requested width of each column when in column mode*/
477476
int actualWidth[100]; /* Actual width of each column */
478
- char nullvalue[20]; /* The text to print when a NULL comes back from
477
+ char nullValue[20]; /* The text to print when a NULL comes back from
479478
** the database */
480479
SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
481480
char outfile[FILENAME_MAX]; /* Filename for *out */
482481
const char *zDbFilename; /* name of the database file */
483482
char *zFreeOnClose; /* Filename to free when closing */
@@ -506,10 +505,11 @@
506505
#define MODE_Html 4 /* Generate an XHTML table */
507506
#define MODE_Insert 5 /* Generate SQL "insert" statements */
508507
#define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
509508
#define MODE_Csv 7 /* Quote strings, numbers are plain */
510509
#define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
510
+#define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
511511
512512
static const char *modeDescr[] = {
513513
"line",
514514
"column",
515515
"list",
@@ -517,12 +517,26 @@
517517
"html",
518518
"insert",
519519
"tcl",
520520
"csv",
521521
"explain",
522
+ "ascii",
522523
};
523524
525
+/*
526
+** These are the column/row/line separators used by the various
527
+** import/export modes.
528
+*/
529
+#define SEP_Column "|"
530
+#define SEP_Row "\n"
531
+#define SEP_Tab "\t"
532
+#define SEP_Space " "
533
+#define SEP_Comma ","
534
+#define SEP_CrLf "\r\n"
535
+#define SEP_Unit "\x1F"
536
+#define SEP_Record "\x1E"
537
+
524538
/*
525539
** Number of elements in an array
526540
*/
527541
#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
528542
@@ -675,26 +689,26 @@
675689
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
676690
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
677691
};
678692
679693
/*
680
-** Output a single term of CSV. Actually, p->separator is used for
681
-** the separator, which may or may not be a comma. p->nullvalue is
694
+** Output a single term of CSV. Actually, p->colSeparator is used for
695
+** the separator, which may or may not be a comma. p->nullValue is
682696
** the null value. Strings are quoted if necessary. The separator
683697
** is only issued if bSep is true.
684698
*/
685699
static void output_csv(ShellState *p, const char *z, int bSep){
686700
FILE *out = p->out;
687701
if( z==0 ){
688
- fprintf(out,"%s",p->nullvalue);
702
+ fprintf(out,"%s",p->nullValue);
689703
}else{
690704
int i;
691
- int nSep = strlen30(p->separator);
705
+ int nSep = strlen30(p->colSeparator);
692706
for(i=0; z[i]; i++){
693707
if( needCsvQuote[((unsigned char*)z)[i]]
694
- || (z[i]==p->separator[0] &&
695
- (nSep==1 || memcmp(z, p->separator, nSep)==0)) ){
708
+ || (z[i]==p->colSeparator[0] &&
709
+ (nSep==1 || memcmp(z, p->colSeparator, nSep)==0)) ){
696710
i = 0;
697711
break;
698712
}
699713
}
700714
if( i==0 ){
@@ -707,11 +721,11 @@
707721
}else{
708722
fprintf(out, "%s", z);
709723
}
710724
}
711725
if( bSep ){
712
- fprintf(p->out, "%s", p->separator);
726
+ fprintf(p->out, "%s", p->colSeparator);
713727
}
714728
}
715729
716730
#ifdef SIGINT
717731
/*
@@ -745,14 +759,14 @@
745759
if( azArg==0 ) break;
746760
for(i=0; i<nArg; i++){
747761
int len = strlen30(azCol[i] ? azCol[i] : "");
748762
if( len>w ) w = len;
749763
}
750
- if( p->cnt++>0 ) fprintf(p->out,"\n");
764
+ if( p->cnt++>0 ) fprintf(p->out, "%s", p->rowSeparator);
751765
for(i=0; i<nArg; i++){
752
- fprintf(p->out,"%*s = %s\n", w, azCol[i],
753
- azArg[i] ? azArg[i] : p->nullvalue);
766
+ fprintf(p->out,"%*s = %s%s", w, azCol[i],
767
+ azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator);
754768
}
755769
break;
756770
}
757771
case MODE_Explain:
758772
case MODE_Column: {
@@ -765,21 +779,23 @@
765779
w = 0;
766780
}
767781
if( w==0 ){
768782
w = strlen30(azCol[i] ? azCol[i] : "");
769783
if( w<10 ) w = 10;
770
- n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue);
784
+ n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullValue);
771785
if( w<n ) w = n;
772786
}
773787
if( i<ArraySize(p->actualWidth) ){
774788
p->actualWidth[i] = w;
775789
}
776790
if( p->showHeader ){
777791
if( w<0 ){
778
- fprintf(p->out,"%*.*s%s",-w,-w,azCol[i], i==nArg-1 ? "\n": " ");
792
+ fprintf(p->out,"%*.*s%s",-w,-w,azCol[i],
793
+ i==nArg-1 ? p->rowSeparator : " ");
779794
}else{
780
- fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " ");
795
+ fprintf(p->out,"%-*.*s%s",w,w,azCol[i],
796
+ i==nArg-1 ? p->rowSeparator : " ");
781797
}
782798
}
783799
}
784800
if( p->showHeader ){
785801
for(i=0; i<nArg; i++){
@@ -790,11 +806,11 @@
790806
}else{
791807
w = 10;
792808
}
793809
fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
794810
"----------------------------------------------------------",
795
- i==nArg-1 ? "\n": " ");
811
+ i==nArg-1 ? p->rowSeparator : " ");
796812
}
797813
}
798814
}
799815
if( azArg==0 ) break;
800816
for(i=0; i<nArg; i++){
@@ -813,36 +829,39 @@
813829
}
814830
p->iIndent++;
815831
}
816832
if( w<0 ){
817833
fprintf(p->out,"%*.*s%s",-w,-w,
818
- azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
834
+ azArg[i] ? azArg[i] : p->nullValue,
835
+ i==nArg-1 ? p->rowSeparator : " ");
819836
}else{
820837
fprintf(p->out,"%-*.*s%s",w,w,
821
- azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
838
+ azArg[i] ? azArg[i] : p->nullValue,
839
+ i==nArg-1 ? p->rowSeparator : " ");
822840
}
823841
}
824842
break;
825843
}
826844
case MODE_Semi:
827845
case MODE_List: {
828846
if( p->cnt++==0 && p->showHeader ){
829847
for(i=0; i<nArg; i++){
830
- fprintf(p->out,"%s%s",azCol[i], i==nArg-1 ? "\n" : p->separator);
848
+ fprintf(p->out,"%s%s",azCol[i],
849
+ i==nArg-1 ? p->rowSeparator : p->colSeparator);
831850
}
832851
}
833852
if( azArg==0 ) break;
834853
for(i=0; i<nArg; i++){
835854
char *z = azArg[i];
836
- if( z==0 ) z = p->nullvalue;
855
+ if( z==0 ) z = p->nullValue;
837856
fprintf(p->out, "%s", z);
838857
if( i<nArg-1 ){
839
- fprintf(p->out, "%s", p->separator);
858
+ fprintf(p->out, "%s", p->colSeparator);
840859
}else if( p->mode==MODE_Semi ){
841
- fprintf(p->out, ";\n");
860
+ fprintf(p->out, ";%s", p->rowSeparator);
842861
}else{
843
- fprintf(p->out, "\n");
862
+ fprintf(p->out, "%s", p->rowSeparator);
844863
}
845864
}
846865
break;
847866
}
848867
case MODE_Html: {
@@ -857,30 +876,30 @@
857876
}
858877
if( azArg==0 ) break;
859878
fprintf(p->out,"<TR>");
860879
for(i=0; i<nArg; i++){
861880
fprintf(p->out,"<TD>");
862
- output_html_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
881
+ output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
863882
fprintf(p->out,"</TD>\n");
864883
}
865884
fprintf(p->out,"</TR>\n");
866885
break;
867886
}
868887
case MODE_Tcl: {
869888
if( p->cnt++==0 && p->showHeader ){
870889
for(i=0; i<nArg; i++){
871890
output_c_string(p->out,azCol[i] ? azCol[i] : "");
872
- if(i<nArg-1) fprintf(p->out, "%s", p->separator);
891
+ if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
873892
}
874
- fprintf(p->out,"\n");
893
+ fprintf(p->out, "%s", p->rowSeparator);
875894
}
876895
if( azArg==0 ) break;
877896
for(i=0; i<nArg; i++){
878
- output_c_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
879
- if(i<nArg-1) fprintf(p->out, "%s", p->separator);
897
+ output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
898
+ if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
880899
}
881
- fprintf(p->out,"\n");
900
+ fprintf(p->out, "%s", p->rowSeparator);
882901
break;
883902
}
884903
case MODE_Csv: {
885904
#if defined(WIN32) || defined(_WIN32)
886905
fflush(p->out);
@@ -888,17 +907,17 @@
888907
#endif
889908
if( p->cnt++==0 && p->showHeader ){
890909
for(i=0; i<nArg; i++){
891910
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
892911
}
893
- fprintf(p->out,"%s",p->newline);
912
+ fprintf(p->out, "%s", p->rowSeparator);
894913
}
895914
if( nArg>0 ){
896915
for(i=0; i<nArg; i++){
897916
output_csv(p, azArg[i], i<nArg-1);
898917
}
899
- fprintf(p->out,"%s",p->newline);
918
+ fprintf(p->out, "%s", p->rowSeparator);
900919
}
901920
#if defined(WIN32) || defined(_WIN32)
902921
fflush(p->out);
903922
_setmode(_fileno(p->out), _O_TEXT);
904923
#endif
@@ -930,10 +949,26 @@
930949
output_quoted_string(p->out, azArg[i]);
931950
}
932951
}
933952
fprintf(p->out,");\n");
934953
break;
954
+ }
955
+ case MODE_Ascii: {
956
+ if( p->cnt++==0 && p->showHeader ){
957
+ for(i=0; i<nArg; i++){
958
+ if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
959
+ fprintf(p->out,"%s",azCol[i] ? azCol[i] : "");
960
+ }
961
+ fprintf(p->out, "%s", p->rowSeparator);
962
+ }
963
+ if( azArg==0 ) break;
964
+ for(i=0; i<nArg; i++){
965
+ if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
966
+ fprintf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue);
967
+ }
968
+ fprintf(p->out, "%s", p->rowSeparator);
969
+ break;
935970
}
936971
}
937972
return 0;
938973
}
939974
@@ -1696,16 +1731,17 @@
16961731
#ifndef SQLITE_OMIT_LOAD_EXTENSION
16971732
".load FILE ?ENTRY? Load an extension library\n"
16981733
#endif
16991734
".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
17001735
".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
1736
+ " ascii Columns/rows delimited by 0x1F and 0x1E\n"
17011737
" csv Comma-separated values\n"
17021738
" column Left-aligned columns. (See .width)\n"
17031739
" html HTML <table> code\n"
17041740
" insert SQL insert statements for TABLE\n"
17051741
" line One value per line\n"
1706
- " list Values delimited by .separator string\n"
1742
+ " list Values delimited by .separator strings\n"
17071743
" tabs Tab-separated values\n"
17081744
" tcl TCL list elements\n"
17091745
".nullvalue STRING Use STRING in place of NULL values\n"
17101746
".once FILENAME Output for the next SQL command only to FILENAME\n"
17111747
".open ?FILENAME? Close existing database and reopen FILENAME\n"
@@ -1718,12 +1754,12 @@
17181754
".save FILE Write in-memory database into FILE\n"
17191755
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
17201756
".schema ?TABLE? Show the CREATE statements\n"
17211757
" If TABLE specified, only show tables matching\n"
17221758
" LIKE pattern TABLE.\n"
1723
- ".separator STRING ?NL? Change separator used by output mode and .import\n"
1724
- " NL is the end-of-line mark for CSV\n"
1759
+ ".separator COL ?ROW? Change the column separator and optionally the row\n"
1760
+ " separator for both the output mode and .import\n"
17251761
".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
17261762
".show Show the current values for various settings\n"
17271763
".stats on|off Turn stats on or off\n"
17281764
".system CMD ARGS... Run CMD ARGS... in a system shell\n"
17291765
".tables ?TABLE? List names of tables\n"
@@ -2000,26 +2036,27 @@
20002036
static int nCall = 0;
20012037
nCall++;
20022038
}
20032039
20042040
/*
2005
-** An object used to read a CSV file
2041
+** An object used to read a CSV and other files for import.
20062042
*/
2007
-typedef struct CSVReader CSVReader;
2008
-struct CSVReader {
2043
+typedef struct ImportCtx ImportCtx;
2044
+struct ImportCtx {
20092045
const char *zFile; /* Name of the input file */
20102046
FILE *in; /* Read the CSV text from this input stream */
20112047
char *z; /* Accumulated text for a field */
20122048
int n; /* Number of bytes in z */
20132049
int nAlloc; /* Space allocated for z[] */
20142050
int nLine; /* Current line number */
20152051
int cTerm; /* Character that terminated the most recent field */
2016
- int cSeparator; /* The separator character. (Usually ",") */
2052
+ int cColSep; /* The column separator character. (Usually ",") */
2053
+ int cRowSep; /* The row separator character. (Usually "\n") */
20172054
};
20182055
20192056
/* Append a single byte to z[] */
2020
-static void csv_append_char(CSVReader *p, int c){
2057
+static void import_append_char(ImportCtx *p, int c){
20212058
if( p->n+1>=p->nAlloc ){
20222059
p->nAlloc += p->nAlloc + 100;
20232060
p->z = sqlite3_realloc(p->z, p->nAlloc);
20242061
if( p->z==0 ){
20252062
fprintf(stderr, "out of memory\n");
@@ -2033,41 +2070,44 @@
20332070
** with the option of having a separator other than ",".
20342071
**
20352072
** + Input comes from p->in.
20362073
** + Store results in p->z of length p->n. Space to hold p->z comes
20372074
** from sqlite3_malloc().
2038
-** + Use p->cSep as the separator. The default is ",".
2075
+** + Use p->cSep as the column separator. The default is ",".
2076
+** + Use p->rSep as the row separator. The default is "\n".
20392077
** + Keep track of the line number in p->nLine.
20402078
** + Store the character that terminates the field in p->cTerm. Store
20412079
** EOF on end-of-file.
20422080
** + Report syntax errors on stderr
20432081
*/
2044
-static char *csv_read_one_field(CSVReader *p){
2045
- int c, pc, ppc;
2046
- int cSep = p->cSeparator;
2082
+static char *csv_read_one_field(ImportCtx *p){
2083
+ int c;
2084
+ int cSep = p->cColSep;
2085
+ int rSep = p->cRowSep;
20472086
p->n = 0;
20482087
c = fgetc(p->in);
20492088
if( c==EOF || seenInterrupt ){
20502089
p->cTerm = EOF;
20512090
return 0;
20522091
}
20532092
if( c=='"' ){
2093
+ int pc, ppc;
20542094
int startLine = p->nLine;
20552095
int cQuote = c;
20562096
pc = ppc = 0;
20572097
while( 1 ){
20582098
c = fgetc(p->in);
2059
- if( c=='\n' ) p->nLine++;
2099
+ if( c==rSep ) p->nLine++;
20602100
if( c==cQuote ){
20612101
if( pc==cQuote ){
20622102
pc = 0;
20632103
continue;
20642104
}
20652105
}
20662106
if( (c==cSep && pc==cQuote)
2067
- || (c=='\n' && pc==cQuote)
2068
- || (c=='\n' && pc=='\r' && ppc==cQuote)
2107
+ || (c==rSep && pc==cQuote)
2108
+ || (c==rSep && pc=='\r' && ppc==cQuote)
20692109
|| (c==EOF && pc==cQuote)
20702110
){
20712111
do{ p->n--; }while( p->z[p->n]!=cQuote );
20722112
p->cTerm = c;
20732113
break;
@@ -2077,31 +2117,65 @@
20772117
p->zFile, p->nLine, cQuote);
20782118
}
20792119
if( c==EOF ){
20802120
fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
20812121
p->zFile, startLine, cQuote);
2082
- p->cTerm = EOF;
2122
+ p->cTerm = c;
20832123
break;
20842124
}
2085
- csv_append_char(p, c);
2125
+ import_append_char(p, c);
20862126
ppc = pc;
20872127
pc = c;
20882128
}
20892129
}else{
2090
- while( c!=EOF && c!=cSep && c!='\n' ){
2091
- csv_append_char(p, c);
2130
+ while( c!=EOF && c!=cSep && c!=rSep ){
2131
+ import_append_char(p, c);
20922132
c = fgetc(p->in);
20932133
}
2094
- if( c=='\n' ){
2134
+ if( c==rSep ){
20952135
p->nLine++;
20962136
if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
20972137
}
20982138
p->cTerm = c;
20992139
}
21002140
if( p->z ) p->z[p->n] = 0;
21012141
return p->z;
21022142
}
2143
+
2144
+/* Read a single field of ASCII delimited text.
2145
+**
2146
+** + Input comes from p->in.
2147
+** + Store results in p->z of length p->n. Space to hold p->z comes
2148
+** from sqlite3_malloc().
2149
+** + Use p->cSep as the column separator. The default is "\x1F".
2150
+** + Use p->rSep as the row separator. The default is "\x1E".
2151
+** + Keep track of the row number in p->nLine.
2152
+** + Store the character that terminates the field in p->cTerm. Store
2153
+** EOF on end-of-file.
2154
+** + Report syntax errors on stderr
2155
+*/
2156
+static char *ascii_read_one_field(ImportCtx *p){
2157
+ int c;
2158
+ int cSep = p->cColSep;
2159
+ int rSep = p->cRowSep;
2160
+ p->n = 0;
2161
+ c = fgetc(p->in);
2162
+ if( c==EOF || seenInterrupt ){
2163
+ p->cTerm = EOF;
2164
+ return 0;
2165
+ }
2166
+ while( c!=EOF && c!=cSep && c!=rSep ){
2167
+ import_append_char(p, c);
2168
+ c = fgetc(p->in);
2169
+ }
2170
+ if( c==rSep ){
2171
+ p->nLine++;
2172
+ }
2173
+ p->cTerm = c;
2174
+ if( p->z ) p->z[p->n] = 0;
2175
+ return p->z;
2176
+}
21032177
21042178
/*
21052179
** Try to transfer data for table zTable. If an error is seen while
21062180
** moving forward, try to go backwards. The backwards movement won't
21072181
** work for WITHOUT ROWID tables.
@@ -2653,100 +2727,125 @@
26532727
sqlite3_stmt *pStmt = NULL; /* A statement */
26542728
int nCol; /* Number of columns in the table */
26552729
int nByte; /* Number of bytes in an SQL string */
26562730
int i, j; /* Loop counters */
26572731
int needCommit; /* True to COMMIT or ROLLBACK at end */
2658
- int nSep; /* Number of bytes in p->separator[] */
2732
+ int nSep; /* Number of bytes in p->colSeparator[] */
26592733
char *zSql; /* An SQL statement */
2660
- CSVReader sCsv; /* Reader context */
2734
+ ImportCtx sCtx; /* Reader context */
2735
+ char *(*xRead)(ImportCtx*); /* Procedure to read one value */
26612736
int (*xCloser)(FILE*); /* Procedure to close th3 connection */
26622737
26632738
if( nArg!=3 ){
26642739
fprintf(stderr, "Usage: .import FILE TABLE\n");
26652740
goto meta_command_exit;
26662741
}
26672742
zFile = azArg[1];
26682743
zTable = azArg[2];
26692744
seenInterrupt = 0;
2670
- memset(&sCsv, 0, sizeof(sCsv));
2745
+ memset(&sCtx, 0, sizeof(sCtx));
26712746
open_db(p, 0);
2672
- nSep = strlen30(p->separator);
2747
+ nSep = strlen30(p->colSeparator);
2748
+ if( nSep==0 ){
2749
+ fprintf(stderr, "Error: non-null column separator required for import\n");
2750
+ return 1;
2751
+ }
2752
+ if( nSep>1 ){
2753
+ fprintf(stderr, "Error: multi-character column separators not allowed"
2754
+ " for import\n");
2755
+ return 1;
2756
+ }
2757
+ nSep = strlen30(p->rowSeparator);
26732758
if( nSep==0 ){
2674
- fprintf(stderr, "Error: non-null separator required for import\n");
2759
+ fprintf(stderr, "Error: non-null row separator required for import\n");
26752760
return 1;
2761
+ }
2762
+ if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
2763
+ /* When importing CSV (only), if the row separator is set to the
2764
+ ** default output row separator, change it to the default input
2765
+ ** row separator. This avoids having to maintain different input
2766
+ ** and output row separators. */
2767
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
2768
+ nSep = strlen30(p->rowSeparator);
26762769
}
26772770
if( nSep>1 ){
2678
- fprintf(stderr, "Error: multi-character separators not allowed"
2771
+ fprintf(stderr, "Error: multi-character row separators not allowed"
26792772
" for import\n");
26802773
return 1;
26812774
}
2682
- sCsv.zFile = zFile;
2683
- sCsv.nLine = 1;
2684
- if( sCsv.zFile[0]=='|' ){
2685
- sCsv.in = popen(sCsv.zFile+1, "r");
2686
- sCsv.zFile = "<pipe>";
2775
+ sCtx.zFile = zFile;
2776
+ sCtx.nLine = 1;
2777
+ if( sCtx.zFile[0]=='|' ){
2778
+ sCtx.in = popen(sCtx.zFile+1, "r");
2779
+ sCtx.zFile = "<pipe>";
26872780
xCloser = pclose;
26882781
}else{
2689
- sCsv.in = fopen(sCsv.zFile, "rb");
2782
+ sCtx.in = fopen(sCtx.zFile, "rb");
26902783
xCloser = fclose;
26912784
}
2692
- if( sCsv.in==0 ){
2785
+ if( p->mode==MODE_Ascii ){
2786
+ xRead = ascii_read_one_field;
2787
+ }else{
2788
+ xRead = csv_read_one_field;
2789
+ }
2790
+ if( sCtx.in==0 ){
26932791
fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
26942792
return 1;
26952793
}
2696
- sCsv.cSeparator = p->separator[0];
2794
+ sCtx.cColSep = p->colSeparator[0];
2795
+ sCtx.cRowSep = p->rowSeparator[0];
26972796
zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
26982797
if( zSql==0 ){
26992798
fprintf(stderr, "Error: out of memory\n");
2700
- xCloser(sCsv.in);
2799
+ xCloser(sCtx.in);
27012800
return 1;
27022801
}
27032802
nByte = strlen30(zSql);
27042803
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2705
- csv_append_char(&sCsv, 0); /* To ensure sCsv.z is allocated */
2804
+ import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
27062805
if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
27072806
char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
27082807
char cSep = '(';
2709
- while( csv_read_one_field(&sCsv) ){
2710
- zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2808
+ while( xRead(&sCtx) ){
2809
+ zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z);
27112810
cSep = ',';
2712
- if( sCsv.cTerm!=sCsv.cSeparator ) break;
2811
+ if( sCtx.cTerm!=sCtx.cColSep ) break;
27132812
}
27142813
if( cSep=='(' ){
27152814
sqlite3_free(zCreate);
2716
- sqlite3_free(sCsv.z);
2717
- xCloser(sCsv.in);
2718
- fprintf(stderr,"%s: empty file\n", sCsv.zFile);
2815
+ sqlite3_free(sCtx.z);
2816
+ xCloser(sCtx.in);
2817
+ fprintf(stderr,"%s: empty file\n", sCtx.zFile);
27192818
return 1;
27202819
}
27212820
zCreate = sqlite3_mprintf("%z\n)", zCreate);
27222821
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
27232822
sqlite3_free(zCreate);
27242823
if( rc ){
27252824
fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
27262825
sqlite3_errmsg(db));
2727
- sqlite3_free(sCsv.z);
2728
- xCloser(sCsv.in);
2826
+ sqlite3_free(sCtx.z);
2827
+ xCloser(sCtx.in);
27292828
return 1;
27302829
}
27312830
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27322831
}
27332832
sqlite3_free(zSql);
27342833
if( rc ){
27352834
if (pStmt) sqlite3_finalize(pStmt);
27362835
fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2737
- xCloser(sCsv.in);
2836
+ xCloser(sCtx.in);
27382837
return 1;
27392838
}
27402839
nCol = sqlite3_column_count(pStmt);
27412840
sqlite3_finalize(pStmt);
27422841
pStmt = 0;
27432842
if( nCol==0 ) return 0; /* no columns, no error */
27442843
zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
27452844
if( zSql==0 ){
27462845
fprintf(stderr, "Error: out of memory\n");
2747
- xCloser(sCsv.in);
2846
+ xCloser(sCtx.in);
27482847
return 1;
27492848
}
27502849
sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
27512850
j = strlen30(zSql);
27522851
for(i=1; i<nCol; i++){
@@ -2758,50 +2857,60 @@
27582857
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27592858
sqlite3_free(zSql);
27602859
if( rc ){
27612860
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
27622861
if (pStmt) sqlite3_finalize(pStmt);
2763
- xCloser(sCsv.in);
2862
+ xCloser(sCtx.in);
27642863
return 1;
27652864
}
27662865
needCommit = sqlite3_get_autocommit(db);
27672866
if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
27682867
do{
2769
- int startLine = sCsv.nLine;
2868
+ int startLine = sCtx.nLine;
27702869
for(i=0; i<nCol; i++){
2771
- char *z = csv_read_one_field(&sCsv);
2870
+ char *z = xRead(&sCtx);
2871
+ /*
2872
+ ** Did we reach end-of-file before finding any columns?
2873
+ ** If so, stop instead of NULL filling the remaining columns.
2874
+ */
27722875
if( z==0 && i==0 ) break;
2876
+ /*
2877
+ ** Did we reach end-of-file OR end-of-line before finding any
2878
+ ** columns in ASCII mode? If so, stop instead of NULL filling
2879
+ ** the remaining columns.
2880
+ */
2881
+ if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
27732882
sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2774
- if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2883
+ if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
27752884
fprintf(stderr, "%s:%d: expected %d columns but found %d - "
27762885
"filling the rest with NULL\n",
2777
- sCsv.zFile, startLine, nCol, i+1);
2886
+ sCtx.zFile, startLine, nCol, i+1);
27782887
i++;
27792888
while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
27802889
}
27812890
}
2782
- if( sCsv.cTerm==sCsv.cSeparator ){
2891
+ if( sCtx.cTerm==sCtx.cColSep ){
27832892
do{
2784
- csv_read_one_field(&sCsv);
2893
+ xRead(&sCtx);
27852894
i++;
2786
- }while( sCsv.cTerm==sCsv.cSeparator );
2895
+ }while( sCtx.cTerm==sCtx.cColSep );
27872896
fprintf(stderr, "%s:%d: expected %d columns but found %d - "
27882897
"extras ignored\n",
2789
- sCsv.zFile, startLine, nCol, i);
2898
+ sCtx.zFile, startLine, nCol, i);
27902899
}
27912900
if( i>=nCol ){
27922901
sqlite3_step(pStmt);
27932902
rc = sqlite3_reset(pStmt);
27942903
if( rc!=SQLITE_OK ){
2795
- fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2904
+ fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
27962905
sqlite3_errmsg(db));
27972906
}
27982907
}
2799
- }while( sCsv.cTerm!=EOF );
2908
+ }while( sCtx.cTerm!=EOF );
28002909
2801
- xCloser(sCsv.in);
2802
- sqlite3_free(sCsv.z);
2910
+ xCloser(sCtx.in);
2911
+ sqlite3_free(sCtx.z);
28032912
sqlite3_finalize(pStmt);
28042913
if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
28052914
}else
28062915
28072916
if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
@@ -2915,32 +3024,36 @@
29153024
p->mode = MODE_List;
29163025
}else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
29173026
p->mode = MODE_Html;
29183027
}else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
29193028
p->mode = MODE_Tcl;
2920
- sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
3029
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
29213030
}else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
29223031
p->mode = MODE_Csv;
2923
- sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2924
- sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n");
3032
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
3033
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
29253034
}else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
29263035
p->mode = MODE_List;
2927
- sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
3036
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
29283037
}else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
29293038
p->mode = MODE_Insert;
29303039
set_table_name(p, nArg>=3 ? azArg[2] : "table");
3040
+ }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
3041
+ p->mode = MODE_Ascii;
3042
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
3043
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
29313044
}else {
29323045
fprintf(stderr,"Error: mode should be one of: "
2933
- "column csv html insert line list tabs tcl\n");
3046
+ "ascii column csv html insert line list tabs tcl\n");
29343047
rc = 1;
29353048
}
29363049
}else
29373050
29383051
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
29393052
if( nArg==2 ){
2940
- sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2941
- "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
3053
+ sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
3054
+ "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
29423055
}else{
29433056
fprintf(stderr, "Usage: .nullvalue STRING\n");
29443057
rc = 1;
29453058
}
29463059
}else
@@ -3221,18 +3334,20 @@
32213334
}else
32223335
#endif
32233336
32243337
if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
32253338
if( nArg<2 || nArg>3 ){
3226
- fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n");
3339
+ fprintf(stderr, "Usage: .separator COL ?ROW?\n");
32273340
rc = 1;
32283341
}
32293342
if( nArg>=2 ){
3230
- sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]);
3343
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator,
3344
+ "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
32313345
}
32323346
if( nArg>=3 ){
3233
- sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]);
3347
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator,
3348
+ "%.*s", (int)ArraySize(p->rowSeparator)-1, azArg[2]);
32343349
}
32353350
}else
32363351
32373352
if( c=='s'
32383353
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
@@ -3259,27 +3374,28 @@
32593374
if( nArg!=1 ){
32603375
fprintf(stderr, "Usage: .show\n");
32613376
rc = 1;
32623377
goto meta_command_exit;
32633378
}
3264
- fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
3265
- fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
3379
+ fprintf(p->out,"%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3380
+ fprintf(p->out,"%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
32663381
fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3267
- fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
3268
- fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
3269
- fprintf(p->out,"%9.9s: ", "nullvalue");
3270
- output_c_string(p->out, p->nullvalue);
3382
+ fprintf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3383
+ fprintf(p->out,"%12.12s: %s\n","mode", modeDescr[p->mode]);
3384
+ fprintf(p->out,"%12.12s: ", "nullvalue");
3385
+ output_c_string(p->out, p->nullValue);
32713386
fprintf(p->out, "\n");
3272
- fprintf(p->out,"%9.9s: %s\n","output",
3387
+ fprintf(p->out,"%12.12s: %s\n","output",
32733388
strlen30(p->outfile) ? p->outfile : "stdout");
3274
- fprintf(p->out,"%9.9s: ", "separator");
3275
- output_c_string(p->out, p->separator);
3276
- fprintf(p->out," ");
3277
- output_c_string(p->out, p->newline);
3389
+ fprintf(p->out,"%12.12s: ", "colseparator");
3390
+ output_c_string(p->out, p->colSeparator);
3391
+ fprintf(p->out, "\n");
3392
+ fprintf(p->out,"%12.12s: ", "rowseparator");
3393
+ output_c_string(p->out, p->rowSeparator);
32783394
fprintf(p->out, "\n");
3279
- fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
3280
- fprintf(p->out,"%9.9s: ","width");
3395
+ fprintf(p->out,"%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3396
+ fprintf(p->out,"%12.12s: ","width");
32813397
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
32823398
fprintf(p->out,"%d ",p->colWidth[i]);
32833399
}
32843400
fprintf(p->out,"\n");
32853401
}else
@@ -3936,10 +4052,11 @@
39364052
39374053
/*
39384054
** Show available command line options
39394055
*/
39404056
static const char zOptions[] =
4057
+ " -ascii set output mode to 'ascii'\n"
39414058
" -bail stop after hitting an error\n"
39424059
" -batch force batch I/O\n"
39434060
" -column set output mode to 'column'\n"
39444061
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
39454062
" -csv set output mode to 'csv'\n"
@@ -3957,15 +4074,15 @@
39574074
" -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
39584075
" -mmap N default mmap size set to N\n"
39594076
#ifdef SQLITE_ENABLE_MULTIPLEX
39604077
" -multiplex enable the multiplexor VFS\n"
39614078
#endif
3962
- " -newline SEP set newline character(s) for CSV\n"
4079
+ " -newline SEP set output row separator. Default: '\\n'\n"
39634080
" -nullvalue TEXT set text string for NULL values. Default ''\n"
39644081
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
39654082
" -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
3966
- " -separator SEP set output field separator. Default: '|'\n"
4083
+ " -separator SEP set output column separator. Default: '|'\n"
39674084
" -stats print memory stats before each finalize\n"
39684085
" -version show SQLite version\n"
39694086
" -vfs NAME use NAME as the default VFS\n"
39704087
#ifdef SQLITE_ENABLE_VFSTRACE
39714088
" -vfstrace enable tracing of all VFS calls\n"
@@ -3988,12 +4105,12 @@
39884105
** Initialize the state information in data
39894106
*/
39904107
static void main_init(ShellState *data) {
39914108
memset(data, 0, sizeof(*data));
39924109
data->mode = MODE_List;
3993
- memcpy(data->separator,"|", 2);
3994
- memcpy(data->newline,"\r\n", 3);
4110
+ memcpy(data->colSeparator,SEP_Column, 2);
4111
+ memcpy(data->rowSeparator,SEP_Row, 2);
39954112
data->showHeader = 0;
39964113
data->shellFlgs = SHFLG_Lookaside;
39974114
sqlite3_config(SQLITE_CONFIG_URI, 1);
39984115
sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
39994116
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
@@ -4228,19 +4345,25 @@
42284345
data.mode = MODE_Line;
42294346
}else if( strcmp(z,"-column")==0 ){
42304347
data.mode = MODE_Column;
42314348
}else if( strcmp(z,"-csv")==0 ){
42324349
data.mode = MODE_Csv;
4233
- memcpy(data.separator,",",2);
4350
+ memcpy(data.colSeparator,",",2);
4351
+ }else if( strcmp(z,"-ascii")==0 ){
4352
+ data.mode = MODE_Ascii;
4353
+ sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
4354
+ SEP_Unit);
4355
+ sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
4356
+ SEP_Record);
42344357
}else if( strcmp(z,"-separator")==0 ){
4235
- sqlite3_snprintf(sizeof(data.separator), data.separator,
4358
+ sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
42364359
"%s",cmdline_option_value(argc,argv,++i));
42374360
}else if( strcmp(z,"-newline")==0 ){
4238
- sqlite3_snprintf(sizeof(data.newline), data.newline,
4361
+ sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
42394362
"%s",cmdline_option_value(argc,argv,++i));
42404363
}else if( strcmp(z,"-nullvalue")==0 ){
4241
- sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
4364
+ sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
42424365
"%s",cmdline_option_value(argc,argv,++i));
42434366
}else if( strcmp(z,"-header")==0 ){
42444367
data.showHeader = 1;
42454368
}else if( strcmp(z,"-noheader")==0 ){
42464369
data.showHeader = 0;
@@ -4356,11 +4479,11 @@
43564479
nHistory = strlen30(zHome) + 20;
43574480
if( (zHistory = malloc(nHistory))!=0 ){
43584481
sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
43594482
}
43604483
}
4361
-#if defined(HAVE_READLINE)
4484
+#if HAVE_READLINE
43624485
if( zHistory ) read_history(zHistory);
43634486
#endif
43644487
rc = process_input(&data, 0);
43654488
if( zHistory ){
43664489
stifle_history(100);
43674490
--- src/shell.c
+++ src/shell.c
@@ -46,21 +46,20 @@
46 # endif
47 # include <unistd.h>
48 # include <sys/types.h>
49 #endif
50
51 #if defined(HAVE_READLINE) && HAVE_READLINE!=0
52 # include <readline/readline.h>
53 # include <readline/history.h>
54 #else
55 # undef HAVE_READLINE
56 #endif
57 #if defined(HAVE_EDITLINE) && !defined(HAVE_READLINE)
 
58 # define HAVE_READLINE 1
59 # include <editline/readline.h>
60 #endif
61 #if !defined(HAVE_READLINE)
62 # define add_history(X)
63 # define read_history(X)
64 # define write_history(X)
65 # define stifle_history(X)
66 #endif
@@ -423,11 +422,11 @@
423 char *zResult;
424 if( in!=0 ){
425 zResult = local_getline(zPrior, in);
426 }else{
427 zPrompt = isContinuation ? continuePrompt : mainPrompt;
428 #if defined(HAVE_READLINE)
429 free(zPrior);
430 zResult = readline(zPrompt);
431 if( zResult && *zResult ) add_history(zResult);
432 #else
433 printf("%s", zPrompt);
@@ -469,15 +468,15 @@
469 int mode; /* An output mode setting */
470 int writableSchema; /* True if PRAGMA writable_schema=ON */
471 int showHeader; /* True to show column names in List or Column mode */
472 unsigned shellFlgs; /* Various flags */
473 char *zDestTable; /* Name of destination table when MODE_Insert */
474 char separator[20]; /* Separator character for MODE_List */
475 char newline[20]; /* Record separator in MODE_Csv */
476 int colWidth[100]; /* Requested width of each column when in column mode*/
477 int actualWidth[100]; /* Actual width of each column */
478 char nullvalue[20]; /* The text to print when a NULL comes back from
479 ** the database */
480 SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
481 char outfile[FILENAME_MAX]; /* Filename for *out */
482 const char *zDbFilename; /* name of the database file */
483 char *zFreeOnClose; /* Filename to free when closing */
@@ -506,10 +505,11 @@
506 #define MODE_Html 4 /* Generate an XHTML table */
507 #define MODE_Insert 5 /* Generate SQL "insert" statements */
508 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
509 #define MODE_Csv 7 /* Quote strings, numbers are plain */
510 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
 
511
512 static const char *modeDescr[] = {
513 "line",
514 "column",
515 "list",
@@ -517,12 +517,26 @@
517 "html",
518 "insert",
519 "tcl",
520 "csv",
521 "explain",
 
522 };
523
 
 
 
 
 
 
 
 
 
 
 
 
 
524 /*
525 ** Number of elements in an array
526 */
527 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
528
@@ -675,26 +689,26 @@
675 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
676 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
677 };
678
679 /*
680 ** Output a single term of CSV. Actually, p->separator is used for
681 ** the separator, which may or may not be a comma. p->nullvalue is
682 ** the null value. Strings are quoted if necessary. The separator
683 ** is only issued if bSep is true.
684 */
685 static void output_csv(ShellState *p, const char *z, int bSep){
686 FILE *out = p->out;
687 if( z==0 ){
688 fprintf(out,"%s",p->nullvalue);
689 }else{
690 int i;
691 int nSep = strlen30(p->separator);
692 for(i=0; z[i]; i++){
693 if( needCsvQuote[((unsigned char*)z)[i]]
694 || (z[i]==p->separator[0] &&
695 (nSep==1 || memcmp(z, p->separator, nSep)==0)) ){
696 i = 0;
697 break;
698 }
699 }
700 if( i==0 ){
@@ -707,11 +721,11 @@
707 }else{
708 fprintf(out, "%s", z);
709 }
710 }
711 if( bSep ){
712 fprintf(p->out, "%s", p->separator);
713 }
714 }
715
716 #ifdef SIGINT
717 /*
@@ -745,14 +759,14 @@
745 if( azArg==0 ) break;
746 for(i=0; i<nArg; i++){
747 int len = strlen30(azCol[i] ? azCol[i] : "");
748 if( len>w ) w = len;
749 }
750 if( p->cnt++>0 ) fprintf(p->out,"\n");
751 for(i=0; i<nArg; i++){
752 fprintf(p->out,"%*s = %s\n", w, azCol[i],
753 azArg[i] ? azArg[i] : p->nullvalue);
754 }
755 break;
756 }
757 case MODE_Explain:
758 case MODE_Column: {
@@ -765,21 +779,23 @@
765 w = 0;
766 }
767 if( w==0 ){
768 w = strlen30(azCol[i] ? azCol[i] : "");
769 if( w<10 ) w = 10;
770 n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue);
771 if( w<n ) w = n;
772 }
773 if( i<ArraySize(p->actualWidth) ){
774 p->actualWidth[i] = w;
775 }
776 if( p->showHeader ){
777 if( w<0 ){
778 fprintf(p->out,"%*.*s%s",-w,-w,azCol[i], i==nArg-1 ? "\n": " ");
 
779 }else{
780 fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " ");
 
781 }
782 }
783 }
784 if( p->showHeader ){
785 for(i=0; i<nArg; i++){
@@ -790,11 +806,11 @@
790 }else{
791 w = 10;
792 }
793 fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
794 "----------------------------------------------------------",
795 i==nArg-1 ? "\n": " ");
796 }
797 }
798 }
799 if( azArg==0 ) break;
800 for(i=0; i<nArg; i++){
@@ -813,36 +829,39 @@
813 }
814 p->iIndent++;
815 }
816 if( w<0 ){
817 fprintf(p->out,"%*.*s%s",-w,-w,
818 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
 
819 }else{
820 fprintf(p->out,"%-*.*s%s",w,w,
821 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
 
822 }
823 }
824 break;
825 }
826 case MODE_Semi:
827 case MODE_List: {
828 if( p->cnt++==0 && p->showHeader ){
829 for(i=0; i<nArg; i++){
830 fprintf(p->out,"%s%s",azCol[i], i==nArg-1 ? "\n" : p->separator);
 
831 }
832 }
833 if( azArg==0 ) break;
834 for(i=0; i<nArg; i++){
835 char *z = azArg[i];
836 if( z==0 ) z = p->nullvalue;
837 fprintf(p->out, "%s", z);
838 if( i<nArg-1 ){
839 fprintf(p->out, "%s", p->separator);
840 }else if( p->mode==MODE_Semi ){
841 fprintf(p->out, ";\n");
842 }else{
843 fprintf(p->out, "\n");
844 }
845 }
846 break;
847 }
848 case MODE_Html: {
@@ -857,30 +876,30 @@
857 }
858 if( azArg==0 ) break;
859 fprintf(p->out,"<TR>");
860 for(i=0; i<nArg; i++){
861 fprintf(p->out,"<TD>");
862 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
863 fprintf(p->out,"</TD>\n");
864 }
865 fprintf(p->out,"</TR>\n");
866 break;
867 }
868 case MODE_Tcl: {
869 if( p->cnt++==0 && p->showHeader ){
870 for(i=0; i<nArg; i++){
871 output_c_string(p->out,azCol[i] ? azCol[i] : "");
872 if(i<nArg-1) fprintf(p->out, "%s", p->separator);
873 }
874 fprintf(p->out,"\n");
875 }
876 if( azArg==0 ) break;
877 for(i=0; i<nArg; i++){
878 output_c_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
879 if(i<nArg-1) fprintf(p->out, "%s", p->separator);
880 }
881 fprintf(p->out,"\n");
882 break;
883 }
884 case MODE_Csv: {
885 #if defined(WIN32) || defined(_WIN32)
886 fflush(p->out);
@@ -888,17 +907,17 @@
888 #endif
889 if( p->cnt++==0 && p->showHeader ){
890 for(i=0; i<nArg; i++){
891 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
892 }
893 fprintf(p->out,"%s",p->newline);
894 }
895 if( nArg>0 ){
896 for(i=0; i<nArg; i++){
897 output_csv(p, azArg[i], i<nArg-1);
898 }
899 fprintf(p->out,"%s",p->newline);
900 }
901 #if defined(WIN32) || defined(_WIN32)
902 fflush(p->out);
903 _setmode(_fileno(p->out), _O_TEXT);
904 #endif
@@ -930,10 +949,26 @@
930 output_quoted_string(p->out, azArg[i]);
931 }
932 }
933 fprintf(p->out,");\n");
934 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
935 }
936 }
937 return 0;
938 }
939
@@ -1696,16 +1731,17 @@
1696 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1697 ".load FILE ?ENTRY? Load an extension library\n"
1698 #endif
1699 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1700 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
 
1701 " csv Comma-separated values\n"
1702 " column Left-aligned columns. (See .width)\n"
1703 " html HTML <table> code\n"
1704 " insert SQL insert statements for TABLE\n"
1705 " line One value per line\n"
1706 " list Values delimited by .separator string\n"
1707 " tabs Tab-separated values\n"
1708 " tcl TCL list elements\n"
1709 ".nullvalue STRING Use STRING in place of NULL values\n"
1710 ".once FILENAME Output for the next SQL command only to FILENAME\n"
1711 ".open ?FILENAME? Close existing database and reopen FILENAME\n"
@@ -1718,12 +1754,12 @@
1718 ".save FILE Write in-memory database into FILE\n"
1719 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
1720 ".schema ?TABLE? Show the CREATE statements\n"
1721 " If TABLE specified, only show tables matching\n"
1722 " LIKE pattern TABLE.\n"
1723 ".separator STRING ?NL? Change separator used by output mode and .import\n"
1724 " NL is the end-of-line mark for CSV\n"
1725 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1726 ".show Show the current values for various settings\n"
1727 ".stats on|off Turn stats on or off\n"
1728 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1729 ".tables ?TABLE? List names of tables\n"
@@ -2000,26 +2036,27 @@
2000 static int nCall = 0;
2001 nCall++;
2002 }
2003
2004 /*
2005 ** An object used to read a CSV file
2006 */
2007 typedef struct CSVReader CSVReader;
2008 struct CSVReader {
2009 const char *zFile; /* Name of the input file */
2010 FILE *in; /* Read the CSV text from this input stream */
2011 char *z; /* Accumulated text for a field */
2012 int n; /* Number of bytes in z */
2013 int nAlloc; /* Space allocated for z[] */
2014 int nLine; /* Current line number */
2015 int cTerm; /* Character that terminated the most recent field */
2016 int cSeparator; /* The separator character. (Usually ",") */
 
2017 };
2018
2019 /* Append a single byte to z[] */
2020 static void csv_append_char(CSVReader *p, int c){
2021 if( p->n+1>=p->nAlloc ){
2022 p->nAlloc += p->nAlloc + 100;
2023 p->z = sqlite3_realloc(p->z, p->nAlloc);
2024 if( p->z==0 ){
2025 fprintf(stderr, "out of memory\n");
@@ -2033,41 +2070,44 @@
2033 ** with the option of having a separator other than ",".
2034 **
2035 ** + Input comes from p->in.
2036 ** + Store results in p->z of length p->n. Space to hold p->z comes
2037 ** from sqlite3_malloc().
2038 ** + Use p->cSep as the separator. The default is ",".
 
2039 ** + Keep track of the line number in p->nLine.
2040 ** + Store the character that terminates the field in p->cTerm. Store
2041 ** EOF on end-of-file.
2042 ** + Report syntax errors on stderr
2043 */
2044 static char *csv_read_one_field(CSVReader *p){
2045 int c, pc, ppc;
2046 int cSep = p->cSeparator;
 
2047 p->n = 0;
2048 c = fgetc(p->in);
2049 if( c==EOF || seenInterrupt ){
2050 p->cTerm = EOF;
2051 return 0;
2052 }
2053 if( c=='"' ){
 
2054 int startLine = p->nLine;
2055 int cQuote = c;
2056 pc = ppc = 0;
2057 while( 1 ){
2058 c = fgetc(p->in);
2059 if( c=='\n' ) p->nLine++;
2060 if( c==cQuote ){
2061 if( pc==cQuote ){
2062 pc = 0;
2063 continue;
2064 }
2065 }
2066 if( (c==cSep && pc==cQuote)
2067 || (c=='\n' && pc==cQuote)
2068 || (c=='\n' && pc=='\r' && ppc==cQuote)
2069 || (c==EOF && pc==cQuote)
2070 ){
2071 do{ p->n--; }while( p->z[p->n]!=cQuote );
2072 p->cTerm = c;
2073 break;
@@ -2077,31 +2117,65 @@
2077 p->zFile, p->nLine, cQuote);
2078 }
2079 if( c==EOF ){
2080 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
2081 p->zFile, startLine, cQuote);
2082 p->cTerm = EOF;
2083 break;
2084 }
2085 csv_append_char(p, c);
2086 ppc = pc;
2087 pc = c;
2088 }
2089 }else{
2090 while( c!=EOF && c!=cSep && c!='\n' ){
2091 csv_append_char(p, c);
2092 c = fgetc(p->in);
2093 }
2094 if( c=='\n' ){
2095 p->nLine++;
2096 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
2097 }
2098 p->cTerm = c;
2099 }
2100 if( p->z ) p->z[p->n] = 0;
2101 return p->z;
2102 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2103
2104 /*
2105 ** Try to transfer data for table zTable. If an error is seen while
2106 ** moving forward, try to go backwards. The backwards movement won't
2107 ** work for WITHOUT ROWID tables.
@@ -2653,100 +2727,125 @@
2653 sqlite3_stmt *pStmt = NULL; /* A statement */
2654 int nCol; /* Number of columns in the table */
2655 int nByte; /* Number of bytes in an SQL string */
2656 int i, j; /* Loop counters */
2657 int needCommit; /* True to COMMIT or ROLLBACK at end */
2658 int nSep; /* Number of bytes in p->separator[] */
2659 char *zSql; /* An SQL statement */
2660 CSVReader sCsv; /* Reader context */
 
2661 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2662
2663 if( nArg!=3 ){
2664 fprintf(stderr, "Usage: .import FILE TABLE\n");
2665 goto meta_command_exit;
2666 }
2667 zFile = azArg[1];
2668 zTable = azArg[2];
2669 seenInterrupt = 0;
2670 memset(&sCsv, 0, sizeof(sCsv));
2671 open_db(p, 0);
2672 nSep = strlen30(p->separator);
 
 
 
 
 
 
 
 
 
 
2673 if( nSep==0 ){
2674 fprintf(stderr, "Error: non-null separator required for import\n");
2675 return 1;
 
 
 
 
 
 
 
 
2676 }
2677 if( nSep>1 ){
2678 fprintf(stderr, "Error: multi-character separators not allowed"
2679 " for import\n");
2680 return 1;
2681 }
2682 sCsv.zFile = zFile;
2683 sCsv.nLine = 1;
2684 if( sCsv.zFile[0]=='|' ){
2685 sCsv.in = popen(sCsv.zFile+1, "r");
2686 sCsv.zFile = "<pipe>";
2687 xCloser = pclose;
2688 }else{
2689 sCsv.in = fopen(sCsv.zFile, "rb");
2690 xCloser = fclose;
2691 }
2692 if( sCsv.in==0 ){
 
 
 
 
 
2693 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2694 return 1;
2695 }
2696 sCsv.cSeparator = p->separator[0];
 
2697 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
2698 if( zSql==0 ){
2699 fprintf(stderr, "Error: out of memory\n");
2700 xCloser(sCsv.in);
2701 return 1;
2702 }
2703 nByte = strlen30(zSql);
2704 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2705 csv_append_char(&sCsv, 0); /* To ensure sCsv.z is allocated */
2706 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2707 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2708 char cSep = '(';
2709 while( csv_read_one_field(&sCsv) ){
2710 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2711 cSep = ',';
2712 if( sCsv.cTerm!=sCsv.cSeparator ) break;
2713 }
2714 if( cSep=='(' ){
2715 sqlite3_free(zCreate);
2716 sqlite3_free(sCsv.z);
2717 xCloser(sCsv.in);
2718 fprintf(stderr,"%s: empty file\n", sCsv.zFile);
2719 return 1;
2720 }
2721 zCreate = sqlite3_mprintf("%z\n)", zCreate);
2722 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2723 sqlite3_free(zCreate);
2724 if( rc ){
2725 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2726 sqlite3_errmsg(db));
2727 sqlite3_free(sCsv.z);
2728 xCloser(sCsv.in);
2729 return 1;
2730 }
2731 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2732 }
2733 sqlite3_free(zSql);
2734 if( rc ){
2735 if (pStmt) sqlite3_finalize(pStmt);
2736 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2737 xCloser(sCsv.in);
2738 return 1;
2739 }
2740 nCol = sqlite3_column_count(pStmt);
2741 sqlite3_finalize(pStmt);
2742 pStmt = 0;
2743 if( nCol==0 ) return 0; /* no columns, no error */
2744 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
2745 if( zSql==0 ){
2746 fprintf(stderr, "Error: out of memory\n");
2747 xCloser(sCsv.in);
2748 return 1;
2749 }
2750 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
2751 j = strlen30(zSql);
2752 for(i=1; i<nCol; i++){
@@ -2758,50 +2857,60 @@
2758 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2759 sqlite3_free(zSql);
2760 if( rc ){
2761 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2762 if (pStmt) sqlite3_finalize(pStmt);
2763 xCloser(sCsv.in);
2764 return 1;
2765 }
2766 needCommit = sqlite3_get_autocommit(db);
2767 if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
2768 do{
2769 int startLine = sCsv.nLine;
2770 for(i=0; i<nCol; i++){
2771 char *z = csv_read_one_field(&sCsv);
 
 
 
 
2772 if( z==0 && i==0 ) break;
 
 
 
 
 
 
2773 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2774 if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2775 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2776 "filling the rest with NULL\n",
2777 sCsv.zFile, startLine, nCol, i+1);
2778 i++;
2779 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2780 }
2781 }
2782 if( sCsv.cTerm==sCsv.cSeparator ){
2783 do{
2784 csv_read_one_field(&sCsv);
2785 i++;
2786 }while( sCsv.cTerm==sCsv.cSeparator );
2787 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2788 "extras ignored\n",
2789 sCsv.zFile, startLine, nCol, i);
2790 }
2791 if( i>=nCol ){
2792 sqlite3_step(pStmt);
2793 rc = sqlite3_reset(pStmt);
2794 if( rc!=SQLITE_OK ){
2795 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2796 sqlite3_errmsg(db));
2797 }
2798 }
2799 }while( sCsv.cTerm!=EOF );
2800
2801 xCloser(sCsv.in);
2802 sqlite3_free(sCsv.z);
2803 sqlite3_finalize(pStmt);
2804 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
2805 }else
2806
2807 if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
@@ -2915,32 +3024,36 @@
2915 p->mode = MODE_List;
2916 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
2917 p->mode = MODE_Html;
2918 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
2919 p->mode = MODE_Tcl;
2920 sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
2921 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
2922 p->mode = MODE_Csv;
2923 sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2924 sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n");
2925 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
2926 p->mode = MODE_List;
2927 sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
2928 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
2929 p->mode = MODE_Insert;
2930 set_table_name(p, nArg>=3 ? azArg[2] : "table");
 
 
 
 
2931 }else {
2932 fprintf(stderr,"Error: mode should be one of: "
2933 "column csv html insert line list tabs tcl\n");
2934 rc = 1;
2935 }
2936 }else
2937
2938 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2939 if( nArg==2 ){
2940 sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2941 "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2942 }else{
2943 fprintf(stderr, "Usage: .nullvalue STRING\n");
2944 rc = 1;
2945 }
2946 }else
@@ -3221,18 +3334,20 @@
3221 }else
3222 #endif
3223
3224 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3225 if( nArg<2 || nArg>3 ){
3226 fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n");
3227 rc = 1;
3228 }
3229 if( nArg>=2 ){
3230 sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]);
 
3231 }
3232 if( nArg>=3 ){
3233 sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]);
 
3234 }
3235 }else
3236
3237 if( c=='s'
3238 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
@@ -3259,27 +3374,28 @@
3259 if( nArg!=1 ){
3260 fprintf(stderr, "Usage: .show\n");
3261 rc = 1;
3262 goto meta_command_exit;
3263 }
3264 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
3265 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
3266 fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3267 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
3268 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
3269 fprintf(p->out,"%9.9s: ", "nullvalue");
3270 output_c_string(p->out, p->nullvalue);
3271 fprintf(p->out, "\n");
3272 fprintf(p->out,"%9.9s: %s\n","output",
3273 strlen30(p->outfile) ? p->outfile : "stdout");
3274 fprintf(p->out,"%9.9s: ", "separator");
3275 output_c_string(p->out, p->separator);
3276 fprintf(p->out," ");
3277 output_c_string(p->out, p->newline);
 
3278 fprintf(p->out, "\n");
3279 fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
3280 fprintf(p->out,"%9.9s: ","width");
3281 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3282 fprintf(p->out,"%d ",p->colWidth[i]);
3283 }
3284 fprintf(p->out,"\n");
3285 }else
@@ -3936,10 +4052,11 @@
3936
3937 /*
3938 ** Show available command line options
3939 */
3940 static const char zOptions[] =
 
3941 " -bail stop after hitting an error\n"
3942 " -batch force batch I/O\n"
3943 " -column set output mode to 'column'\n"
3944 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
3945 " -csv set output mode to 'csv'\n"
@@ -3957,15 +4074,15 @@
3957 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
3958 " -mmap N default mmap size set to N\n"
3959 #ifdef SQLITE_ENABLE_MULTIPLEX
3960 " -multiplex enable the multiplexor VFS\n"
3961 #endif
3962 " -newline SEP set newline character(s) for CSV\n"
3963 " -nullvalue TEXT set text string for NULL values. Default ''\n"
3964 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
3965 " -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
3966 " -separator SEP set output field separator. Default: '|'\n"
3967 " -stats print memory stats before each finalize\n"
3968 " -version show SQLite version\n"
3969 " -vfs NAME use NAME as the default VFS\n"
3970 #ifdef SQLITE_ENABLE_VFSTRACE
3971 " -vfstrace enable tracing of all VFS calls\n"
@@ -3988,12 +4105,12 @@
3988 ** Initialize the state information in data
3989 */
3990 static void main_init(ShellState *data) {
3991 memset(data, 0, sizeof(*data));
3992 data->mode = MODE_List;
3993 memcpy(data->separator,"|", 2);
3994 memcpy(data->newline,"\r\n", 3);
3995 data->showHeader = 0;
3996 data->shellFlgs = SHFLG_Lookaside;
3997 sqlite3_config(SQLITE_CONFIG_URI, 1);
3998 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
3999 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
@@ -4228,19 +4345,25 @@
4228 data.mode = MODE_Line;
4229 }else if( strcmp(z,"-column")==0 ){
4230 data.mode = MODE_Column;
4231 }else if( strcmp(z,"-csv")==0 ){
4232 data.mode = MODE_Csv;
4233 memcpy(data.separator,",",2);
 
 
 
 
 
 
4234 }else if( strcmp(z,"-separator")==0 ){
4235 sqlite3_snprintf(sizeof(data.separator), data.separator,
4236 "%s",cmdline_option_value(argc,argv,++i));
4237 }else if( strcmp(z,"-newline")==0 ){
4238 sqlite3_snprintf(sizeof(data.newline), data.newline,
4239 "%s",cmdline_option_value(argc,argv,++i));
4240 }else if( strcmp(z,"-nullvalue")==0 ){
4241 sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
4242 "%s",cmdline_option_value(argc,argv,++i));
4243 }else if( strcmp(z,"-header")==0 ){
4244 data.showHeader = 1;
4245 }else if( strcmp(z,"-noheader")==0 ){
4246 data.showHeader = 0;
@@ -4356,11 +4479,11 @@
4356 nHistory = strlen30(zHome) + 20;
4357 if( (zHistory = malloc(nHistory))!=0 ){
4358 sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
4359 }
4360 }
4361 #if defined(HAVE_READLINE)
4362 if( zHistory ) read_history(zHistory);
4363 #endif
4364 rc = process_input(&data, 0);
4365 if( zHistory ){
4366 stifle_history(100);
4367
--- src/shell.c
+++ src/shell.c
@@ -46,21 +46,20 @@
46 # endif
47 # include <unistd.h>
48 # include <sys/types.h>
49 #endif
50
51 #if HAVE_READLINE
52 # include <readline/readline.h>
53 # include <readline/history.h>
 
 
54 #endif
55 #if HAVE_EDITLINE
56 # undef HAVE_READLINE
57 # define HAVE_READLINE 1
58 # include <editline/readline.h>
59 #endif
60 #if !HAVE_READLINE
61 # define add_history(X)
62 # define read_history(X)
63 # define write_history(X)
64 # define stifle_history(X)
65 #endif
@@ -423,11 +422,11 @@
422 char *zResult;
423 if( in!=0 ){
424 zResult = local_getline(zPrior, in);
425 }else{
426 zPrompt = isContinuation ? continuePrompt : mainPrompt;
427 #if HAVE_READLINE
428 free(zPrior);
429 zResult = readline(zPrompt);
430 if( zResult && *zResult ) add_history(zResult);
431 #else
432 printf("%s", zPrompt);
@@ -469,15 +468,15 @@
468 int mode; /* An output mode setting */
469 int writableSchema; /* True if PRAGMA writable_schema=ON */
470 int showHeader; /* True to show column names in List or Column mode */
471 unsigned shellFlgs; /* Various flags */
472 char *zDestTable; /* Name of destination table when MODE_Insert */
473 char colSeparator[20]; /* Column separator character for several modes */
474 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
475 int colWidth[100]; /* Requested width of each column when in column mode*/
476 int actualWidth[100]; /* Actual width of each column */
477 char nullValue[20]; /* The text to print when a NULL comes back from
478 ** the database */
479 SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
480 char outfile[FILENAME_MAX]; /* Filename for *out */
481 const char *zDbFilename; /* name of the database file */
482 char *zFreeOnClose; /* Filename to free when closing */
@@ -506,10 +505,11 @@
505 #define MODE_Html 4 /* Generate an XHTML table */
506 #define MODE_Insert 5 /* Generate SQL "insert" statements */
507 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
508 #define MODE_Csv 7 /* Quote strings, numbers are plain */
509 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
510 #define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
511
512 static const char *modeDescr[] = {
513 "line",
514 "column",
515 "list",
@@ -517,12 +517,26 @@
517 "html",
518 "insert",
519 "tcl",
520 "csv",
521 "explain",
522 "ascii",
523 };
524
525 /*
526 ** These are the column/row/line separators used by the various
527 ** import/export modes.
528 */
529 #define SEP_Column "|"
530 #define SEP_Row "\n"
531 #define SEP_Tab "\t"
532 #define SEP_Space " "
533 #define SEP_Comma ","
534 #define SEP_CrLf "\r\n"
535 #define SEP_Unit "\x1F"
536 #define SEP_Record "\x1E"
537
538 /*
539 ** Number of elements in an array
540 */
541 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
542
@@ -675,26 +689,26 @@
689 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
690 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
691 };
692
693 /*
694 ** Output a single term of CSV. Actually, p->colSeparator is used for
695 ** the separator, which may or may not be a comma. p->nullValue is
696 ** the null value. Strings are quoted if necessary. The separator
697 ** is only issued if bSep is true.
698 */
699 static void output_csv(ShellState *p, const char *z, int bSep){
700 FILE *out = p->out;
701 if( z==0 ){
702 fprintf(out,"%s",p->nullValue);
703 }else{
704 int i;
705 int nSep = strlen30(p->colSeparator);
706 for(i=0; z[i]; i++){
707 if( needCsvQuote[((unsigned char*)z)[i]]
708 || (z[i]==p->colSeparator[0] &&
709 (nSep==1 || memcmp(z, p->colSeparator, nSep)==0)) ){
710 i = 0;
711 break;
712 }
713 }
714 if( i==0 ){
@@ -707,11 +721,11 @@
721 }else{
722 fprintf(out, "%s", z);
723 }
724 }
725 if( bSep ){
726 fprintf(p->out, "%s", p->colSeparator);
727 }
728 }
729
730 #ifdef SIGINT
731 /*
@@ -745,14 +759,14 @@
759 if( azArg==0 ) break;
760 for(i=0; i<nArg; i++){
761 int len = strlen30(azCol[i] ? azCol[i] : "");
762 if( len>w ) w = len;
763 }
764 if( p->cnt++>0 ) fprintf(p->out, "%s", p->rowSeparator);
765 for(i=0; i<nArg; i++){
766 fprintf(p->out,"%*s = %s%s", w, azCol[i],
767 azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator);
768 }
769 break;
770 }
771 case MODE_Explain:
772 case MODE_Column: {
@@ -765,21 +779,23 @@
779 w = 0;
780 }
781 if( w==0 ){
782 w = strlen30(azCol[i] ? azCol[i] : "");
783 if( w<10 ) w = 10;
784 n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullValue);
785 if( w<n ) w = n;
786 }
787 if( i<ArraySize(p->actualWidth) ){
788 p->actualWidth[i] = w;
789 }
790 if( p->showHeader ){
791 if( w<0 ){
792 fprintf(p->out,"%*.*s%s",-w,-w,azCol[i],
793 i==nArg-1 ? p->rowSeparator : " ");
794 }else{
795 fprintf(p->out,"%-*.*s%s",w,w,azCol[i],
796 i==nArg-1 ? p->rowSeparator : " ");
797 }
798 }
799 }
800 if( p->showHeader ){
801 for(i=0; i<nArg; i++){
@@ -790,11 +806,11 @@
806 }else{
807 w = 10;
808 }
809 fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
810 "----------------------------------------------------------",
811 i==nArg-1 ? p->rowSeparator : " ");
812 }
813 }
814 }
815 if( azArg==0 ) break;
816 for(i=0; i<nArg; i++){
@@ -813,36 +829,39 @@
829 }
830 p->iIndent++;
831 }
832 if( w<0 ){
833 fprintf(p->out,"%*.*s%s",-w,-w,
834 azArg[i] ? azArg[i] : p->nullValue,
835 i==nArg-1 ? p->rowSeparator : " ");
836 }else{
837 fprintf(p->out,"%-*.*s%s",w,w,
838 azArg[i] ? azArg[i] : p->nullValue,
839 i==nArg-1 ? p->rowSeparator : " ");
840 }
841 }
842 break;
843 }
844 case MODE_Semi:
845 case MODE_List: {
846 if( p->cnt++==0 && p->showHeader ){
847 for(i=0; i<nArg; i++){
848 fprintf(p->out,"%s%s",azCol[i],
849 i==nArg-1 ? p->rowSeparator : p->colSeparator);
850 }
851 }
852 if( azArg==0 ) break;
853 for(i=0; i<nArg; i++){
854 char *z = azArg[i];
855 if( z==0 ) z = p->nullValue;
856 fprintf(p->out, "%s", z);
857 if( i<nArg-1 ){
858 fprintf(p->out, "%s", p->colSeparator);
859 }else if( p->mode==MODE_Semi ){
860 fprintf(p->out, ";%s", p->rowSeparator);
861 }else{
862 fprintf(p->out, "%s", p->rowSeparator);
863 }
864 }
865 break;
866 }
867 case MODE_Html: {
@@ -857,30 +876,30 @@
876 }
877 if( azArg==0 ) break;
878 fprintf(p->out,"<TR>");
879 for(i=0; i<nArg; i++){
880 fprintf(p->out,"<TD>");
881 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
882 fprintf(p->out,"</TD>\n");
883 }
884 fprintf(p->out,"</TR>\n");
885 break;
886 }
887 case MODE_Tcl: {
888 if( p->cnt++==0 && p->showHeader ){
889 for(i=0; i<nArg; i++){
890 output_c_string(p->out,azCol[i] ? azCol[i] : "");
891 if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
892 }
893 fprintf(p->out, "%s", p->rowSeparator);
894 }
895 if( azArg==0 ) break;
896 for(i=0; i<nArg; i++){
897 output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
898 if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
899 }
900 fprintf(p->out, "%s", p->rowSeparator);
901 break;
902 }
903 case MODE_Csv: {
904 #if defined(WIN32) || defined(_WIN32)
905 fflush(p->out);
@@ -888,17 +907,17 @@
907 #endif
908 if( p->cnt++==0 && p->showHeader ){
909 for(i=0; i<nArg; i++){
910 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
911 }
912 fprintf(p->out, "%s", p->rowSeparator);
913 }
914 if( nArg>0 ){
915 for(i=0; i<nArg; i++){
916 output_csv(p, azArg[i], i<nArg-1);
917 }
918 fprintf(p->out, "%s", p->rowSeparator);
919 }
920 #if defined(WIN32) || defined(_WIN32)
921 fflush(p->out);
922 _setmode(_fileno(p->out), _O_TEXT);
923 #endif
@@ -930,10 +949,26 @@
949 output_quoted_string(p->out, azArg[i]);
950 }
951 }
952 fprintf(p->out,");\n");
953 break;
954 }
955 case MODE_Ascii: {
956 if( p->cnt++==0 && p->showHeader ){
957 for(i=0; i<nArg; i++){
958 if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
959 fprintf(p->out,"%s",azCol[i] ? azCol[i] : "");
960 }
961 fprintf(p->out, "%s", p->rowSeparator);
962 }
963 if( azArg==0 ) break;
964 for(i=0; i<nArg; i++){
965 if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
966 fprintf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue);
967 }
968 fprintf(p->out, "%s", p->rowSeparator);
969 break;
970 }
971 }
972 return 0;
973 }
974
@@ -1696,16 +1731,17 @@
1731 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1732 ".load FILE ?ENTRY? Load an extension library\n"
1733 #endif
1734 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1735 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
1736 " ascii Columns/rows delimited by 0x1F and 0x1E\n"
1737 " csv Comma-separated values\n"
1738 " column Left-aligned columns. (See .width)\n"
1739 " html HTML <table> code\n"
1740 " insert SQL insert statements for TABLE\n"
1741 " line One value per line\n"
1742 " list Values delimited by .separator strings\n"
1743 " tabs Tab-separated values\n"
1744 " tcl TCL list elements\n"
1745 ".nullvalue STRING Use STRING in place of NULL values\n"
1746 ".once FILENAME Output for the next SQL command only to FILENAME\n"
1747 ".open ?FILENAME? Close existing database and reopen FILENAME\n"
@@ -1718,12 +1754,12 @@
1754 ".save FILE Write in-memory database into FILE\n"
1755 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
1756 ".schema ?TABLE? Show the CREATE statements\n"
1757 " If TABLE specified, only show tables matching\n"
1758 " LIKE pattern TABLE.\n"
1759 ".separator COL ?ROW? Change the column separator and optionally the row\n"
1760 " separator for both the output mode and .import\n"
1761 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1762 ".show Show the current values for various settings\n"
1763 ".stats on|off Turn stats on or off\n"
1764 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1765 ".tables ?TABLE? List names of tables\n"
@@ -2000,26 +2036,27 @@
2036 static int nCall = 0;
2037 nCall++;
2038 }
2039
2040 /*
2041 ** An object used to read a CSV and other files for import.
2042 */
2043 typedef struct ImportCtx ImportCtx;
2044 struct ImportCtx {
2045 const char *zFile; /* Name of the input file */
2046 FILE *in; /* Read the CSV text from this input stream */
2047 char *z; /* Accumulated text for a field */
2048 int n; /* Number of bytes in z */
2049 int nAlloc; /* Space allocated for z[] */
2050 int nLine; /* Current line number */
2051 int cTerm; /* Character that terminated the most recent field */
2052 int cColSep; /* The column separator character. (Usually ",") */
2053 int cRowSep; /* The row separator character. (Usually "\n") */
2054 };
2055
2056 /* Append a single byte to z[] */
2057 static void import_append_char(ImportCtx *p, int c){
2058 if( p->n+1>=p->nAlloc ){
2059 p->nAlloc += p->nAlloc + 100;
2060 p->z = sqlite3_realloc(p->z, p->nAlloc);
2061 if( p->z==0 ){
2062 fprintf(stderr, "out of memory\n");
@@ -2033,41 +2070,44 @@
2070 ** with the option of having a separator other than ",".
2071 **
2072 ** + Input comes from p->in.
2073 ** + Store results in p->z of length p->n. Space to hold p->z comes
2074 ** from sqlite3_malloc().
2075 ** + Use p->cSep as the column separator. The default is ",".
2076 ** + Use p->rSep as the row separator. The default is "\n".
2077 ** + Keep track of the line number in p->nLine.
2078 ** + Store the character that terminates the field in p->cTerm. Store
2079 ** EOF on end-of-file.
2080 ** + Report syntax errors on stderr
2081 */
2082 static char *csv_read_one_field(ImportCtx *p){
2083 int c;
2084 int cSep = p->cColSep;
2085 int rSep = p->cRowSep;
2086 p->n = 0;
2087 c = fgetc(p->in);
2088 if( c==EOF || seenInterrupt ){
2089 p->cTerm = EOF;
2090 return 0;
2091 }
2092 if( c=='"' ){
2093 int pc, ppc;
2094 int startLine = p->nLine;
2095 int cQuote = c;
2096 pc = ppc = 0;
2097 while( 1 ){
2098 c = fgetc(p->in);
2099 if( c==rSep ) p->nLine++;
2100 if( c==cQuote ){
2101 if( pc==cQuote ){
2102 pc = 0;
2103 continue;
2104 }
2105 }
2106 if( (c==cSep && pc==cQuote)
2107 || (c==rSep && pc==cQuote)
2108 || (c==rSep && pc=='\r' && ppc==cQuote)
2109 || (c==EOF && pc==cQuote)
2110 ){
2111 do{ p->n--; }while( p->z[p->n]!=cQuote );
2112 p->cTerm = c;
2113 break;
@@ -2077,31 +2117,65 @@
2117 p->zFile, p->nLine, cQuote);
2118 }
2119 if( c==EOF ){
2120 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
2121 p->zFile, startLine, cQuote);
2122 p->cTerm = c;
2123 break;
2124 }
2125 import_append_char(p, c);
2126 ppc = pc;
2127 pc = c;
2128 }
2129 }else{
2130 while( c!=EOF && c!=cSep && c!=rSep ){
2131 import_append_char(p, c);
2132 c = fgetc(p->in);
2133 }
2134 if( c==rSep ){
2135 p->nLine++;
2136 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
2137 }
2138 p->cTerm = c;
2139 }
2140 if( p->z ) p->z[p->n] = 0;
2141 return p->z;
2142 }
2143
2144 /* Read a single field of ASCII delimited text.
2145 **
2146 ** + Input comes from p->in.
2147 ** + Store results in p->z of length p->n. Space to hold p->z comes
2148 ** from sqlite3_malloc().
2149 ** + Use p->cSep as the column separator. The default is "\x1F".
2150 ** + Use p->rSep as the row separator. The default is "\x1E".
2151 ** + Keep track of the row number in p->nLine.
2152 ** + Store the character that terminates the field in p->cTerm. Store
2153 ** EOF on end-of-file.
2154 ** + Report syntax errors on stderr
2155 */
2156 static char *ascii_read_one_field(ImportCtx *p){
2157 int c;
2158 int cSep = p->cColSep;
2159 int rSep = p->cRowSep;
2160 p->n = 0;
2161 c = fgetc(p->in);
2162 if( c==EOF || seenInterrupt ){
2163 p->cTerm = EOF;
2164 return 0;
2165 }
2166 while( c!=EOF && c!=cSep && c!=rSep ){
2167 import_append_char(p, c);
2168 c = fgetc(p->in);
2169 }
2170 if( c==rSep ){
2171 p->nLine++;
2172 }
2173 p->cTerm = c;
2174 if( p->z ) p->z[p->n] = 0;
2175 return p->z;
2176 }
2177
2178 /*
2179 ** Try to transfer data for table zTable. If an error is seen while
2180 ** moving forward, try to go backwards. The backwards movement won't
2181 ** work for WITHOUT ROWID tables.
@@ -2653,100 +2727,125 @@
2727 sqlite3_stmt *pStmt = NULL; /* A statement */
2728 int nCol; /* Number of columns in the table */
2729 int nByte; /* Number of bytes in an SQL string */
2730 int i, j; /* Loop counters */
2731 int needCommit; /* True to COMMIT or ROLLBACK at end */
2732 int nSep; /* Number of bytes in p->colSeparator[] */
2733 char *zSql; /* An SQL statement */
2734 ImportCtx sCtx; /* Reader context */
2735 char *(*xRead)(ImportCtx*); /* Procedure to read one value */
2736 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2737
2738 if( nArg!=3 ){
2739 fprintf(stderr, "Usage: .import FILE TABLE\n");
2740 goto meta_command_exit;
2741 }
2742 zFile = azArg[1];
2743 zTable = azArg[2];
2744 seenInterrupt = 0;
2745 memset(&sCtx, 0, sizeof(sCtx));
2746 open_db(p, 0);
2747 nSep = strlen30(p->colSeparator);
2748 if( nSep==0 ){
2749 fprintf(stderr, "Error: non-null column separator required for import\n");
2750 return 1;
2751 }
2752 if( nSep>1 ){
2753 fprintf(stderr, "Error: multi-character column separators not allowed"
2754 " for import\n");
2755 return 1;
2756 }
2757 nSep = strlen30(p->rowSeparator);
2758 if( nSep==0 ){
2759 fprintf(stderr, "Error: non-null row separator required for import\n");
2760 return 1;
2761 }
2762 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
2763 /* When importing CSV (only), if the row separator is set to the
2764 ** default output row separator, change it to the default input
2765 ** row separator. This avoids having to maintain different input
2766 ** and output row separators. */
2767 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
2768 nSep = strlen30(p->rowSeparator);
2769 }
2770 if( nSep>1 ){
2771 fprintf(stderr, "Error: multi-character row separators not allowed"
2772 " for import\n");
2773 return 1;
2774 }
2775 sCtx.zFile = zFile;
2776 sCtx.nLine = 1;
2777 if( sCtx.zFile[0]=='|' ){
2778 sCtx.in = popen(sCtx.zFile+1, "r");
2779 sCtx.zFile = "<pipe>";
2780 xCloser = pclose;
2781 }else{
2782 sCtx.in = fopen(sCtx.zFile, "rb");
2783 xCloser = fclose;
2784 }
2785 if( p->mode==MODE_Ascii ){
2786 xRead = ascii_read_one_field;
2787 }else{
2788 xRead = csv_read_one_field;
2789 }
2790 if( sCtx.in==0 ){
2791 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2792 return 1;
2793 }
2794 sCtx.cColSep = p->colSeparator[0];
2795 sCtx.cRowSep = p->rowSeparator[0];
2796 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
2797 if( zSql==0 ){
2798 fprintf(stderr, "Error: out of memory\n");
2799 xCloser(sCtx.in);
2800 return 1;
2801 }
2802 nByte = strlen30(zSql);
2803 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2804 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
2805 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2806 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2807 char cSep = '(';
2808 while( xRead(&sCtx) ){
2809 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z);
2810 cSep = ',';
2811 if( sCtx.cTerm!=sCtx.cColSep ) break;
2812 }
2813 if( cSep=='(' ){
2814 sqlite3_free(zCreate);
2815 sqlite3_free(sCtx.z);
2816 xCloser(sCtx.in);
2817 fprintf(stderr,"%s: empty file\n", sCtx.zFile);
2818 return 1;
2819 }
2820 zCreate = sqlite3_mprintf("%z\n)", zCreate);
2821 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2822 sqlite3_free(zCreate);
2823 if( rc ){
2824 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2825 sqlite3_errmsg(db));
2826 sqlite3_free(sCtx.z);
2827 xCloser(sCtx.in);
2828 return 1;
2829 }
2830 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2831 }
2832 sqlite3_free(zSql);
2833 if( rc ){
2834 if (pStmt) sqlite3_finalize(pStmt);
2835 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2836 xCloser(sCtx.in);
2837 return 1;
2838 }
2839 nCol = sqlite3_column_count(pStmt);
2840 sqlite3_finalize(pStmt);
2841 pStmt = 0;
2842 if( nCol==0 ) return 0; /* no columns, no error */
2843 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
2844 if( zSql==0 ){
2845 fprintf(stderr, "Error: out of memory\n");
2846 xCloser(sCtx.in);
2847 return 1;
2848 }
2849 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
2850 j = strlen30(zSql);
2851 for(i=1; i<nCol; i++){
@@ -2758,50 +2857,60 @@
2857 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2858 sqlite3_free(zSql);
2859 if( rc ){
2860 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2861 if (pStmt) sqlite3_finalize(pStmt);
2862 xCloser(sCtx.in);
2863 return 1;
2864 }
2865 needCommit = sqlite3_get_autocommit(db);
2866 if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
2867 do{
2868 int startLine = sCtx.nLine;
2869 for(i=0; i<nCol; i++){
2870 char *z = xRead(&sCtx);
2871 /*
2872 ** Did we reach end-of-file before finding any columns?
2873 ** If so, stop instead of NULL filling the remaining columns.
2874 */
2875 if( z==0 && i==0 ) break;
2876 /*
2877 ** Did we reach end-of-file OR end-of-line before finding any
2878 ** columns in ASCII mode? If so, stop instead of NULL filling
2879 ** the remaining columns.
2880 */
2881 if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
2882 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2883 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
2884 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2885 "filling the rest with NULL\n",
2886 sCtx.zFile, startLine, nCol, i+1);
2887 i++;
2888 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2889 }
2890 }
2891 if( sCtx.cTerm==sCtx.cColSep ){
2892 do{
2893 xRead(&sCtx);
2894 i++;
2895 }while( sCtx.cTerm==sCtx.cColSep );
2896 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2897 "extras ignored\n",
2898 sCtx.zFile, startLine, nCol, i);
2899 }
2900 if( i>=nCol ){
2901 sqlite3_step(pStmt);
2902 rc = sqlite3_reset(pStmt);
2903 if( rc!=SQLITE_OK ){
2904 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
2905 sqlite3_errmsg(db));
2906 }
2907 }
2908 }while( sCtx.cTerm!=EOF );
2909
2910 xCloser(sCtx.in);
2911 sqlite3_free(sCtx.z);
2912 sqlite3_finalize(pStmt);
2913 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
2914 }else
2915
2916 if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
@@ -2915,32 +3024,36 @@
3024 p->mode = MODE_List;
3025 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
3026 p->mode = MODE_Html;
3027 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
3028 p->mode = MODE_Tcl;
3029 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
3030 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
3031 p->mode = MODE_Csv;
3032 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
3033 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
3034 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
3035 p->mode = MODE_List;
3036 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
3037 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
3038 p->mode = MODE_Insert;
3039 set_table_name(p, nArg>=3 ? azArg[2] : "table");
3040 }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
3041 p->mode = MODE_Ascii;
3042 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
3043 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
3044 }else {
3045 fprintf(stderr,"Error: mode should be one of: "
3046 "ascii column csv html insert line list tabs tcl\n");
3047 rc = 1;
3048 }
3049 }else
3050
3051 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
3052 if( nArg==2 ){
3053 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
3054 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
3055 }else{
3056 fprintf(stderr, "Usage: .nullvalue STRING\n");
3057 rc = 1;
3058 }
3059 }else
@@ -3221,18 +3334,20 @@
3334 }else
3335 #endif
3336
3337 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3338 if( nArg<2 || nArg>3 ){
3339 fprintf(stderr, "Usage: .separator COL ?ROW?\n");
3340 rc = 1;
3341 }
3342 if( nArg>=2 ){
3343 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator,
3344 "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
3345 }
3346 if( nArg>=3 ){
3347 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator,
3348 "%.*s", (int)ArraySize(p->rowSeparator)-1, azArg[2]);
3349 }
3350 }else
3351
3352 if( c=='s'
3353 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
@@ -3259,27 +3374,28 @@
3374 if( nArg!=1 ){
3375 fprintf(stderr, "Usage: .show\n");
3376 rc = 1;
3377 goto meta_command_exit;
3378 }
3379 fprintf(p->out,"%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3380 fprintf(p->out,"%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3381 fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3382 fprintf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3383 fprintf(p->out,"%12.12s: %s\n","mode", modeDescr[p->mode]);
3384 fprintf(p->out,"%12.12s: ", "nullvalue");
3385 output_c_string(p->out, p->nullValue);
3386 fprintf(p->out, "\n");
3387 fprintf(p->out,"%12.12s: %s\n","output",
3388 strlen30(p->outfile) ? p->outfile : "stdout");
3389 fprintf(p->out,"%12.12s: ", "colseparator");
3390 output_c_string(p->out, p->colSeparator);
3391 fprintf(p->out, "\n");
3392 fprintf(p->out,"%12.12s: ", "rowseparator");
3393 output_c_string(p->out, p->rowSeparator);
3394 fprintf(p->out, "\n");
3395 fprintf(p->out,"%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3396 fprintf(p->out,"%12.12s: ","width");
3397 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3398 fprintf(p->out,"%d ",p->colWidth[i]);
3399 }
3400 fprintf(p->out,"\n");
3401 }else
@@ -3936,10 +4052,11 @@
4052
4053 /*
4054 ** Show available command line options
4055 */
4056 static const char zOptions[] =
4057 " -ascii set output mode to 'ascii'\n"
4058 " -bail stop after hitting an error\n"
4059 " -batch force batch I/O\n"
4060 " -column set output mode to 'column'\n"
4061 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
4062 " -csv set output mode to 'csv'\n"
@@ -3957,15 +4074,15 @@
4074 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
4075 " -mmap N default mmap size set to N\n"
4076 #ifdef SQLITE_ENABLE_MULTIPLEX
4077 " -multiplex enable the multiplexor VFS\n"
4078 #endif
4079 " -newline SEP set output row separator. Default: '\\n'\n"
4080 " -nullvalue TEXT set text string for NULL values. Default ''\n"
4081 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
4082 " -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
4083 " -separator SEP set output column separator. Default: '|'\n"
4084 " -stats print memory stats before each finalize\n"
4085 " -version show SQLite version\n"
4086 " -vfs NAME use NAME as the default VFS\n"
4087 #ifdef SQLITE_ENABLE_VFSTRACE
4088 " -vfstrace enable tracing of all VFS calls\n"
@@ -3988,12 +4105,12 @@
4105 ** Initialize the state information in data
4106 */
4107 static void main_init(ShellState *data) {
4108 memset(data, 0, sizeof(*data));
4109 data->mode = MODE_List;
4110 memcpy(data->colSeparator,SEP_Column, 2);
4111 memcpy(data->rowSeparator,SEP_Row, 2);
4112 data->showHeader = 0;
4113 data->shellFlgs = SHFLG_Lookaside;
4114 sqlite3_config(SQLITE_CONFIG_URI, 1);
4115 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
4116 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
@@ -4228,19 +4345,25 @@
4345 data.mode = MODE_Line;
4346 }else if( strcmp(z,"-column")==0 ){
4347 data.mode = MODE_Column;
4348 }else if( strcmp(z,"-csv")==0 ){
4349 data.mode = MODE_Csv;
4350 memcpy(data.colSeparator,",",2);
4351 }else if( strcmp(z,"-ascii")==0 ){
4352 data.mode = MODE_Ascii;
4353 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
4354 SEP_Unit);
4355 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
4356 SEP_Record);
4357 }else if( strcmp(z,"-separator")==0 ){
4358 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
4359 "%s",cmdline_option_value(argc,argv,++i));
4360 }else if( strcmp(z,"-newline")==0 ){
4361 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
4362 "%s",cmdline_option_value(argc,argv,++i));
4363 }else if( strcmp(z,"-nullvalue")==0 ){
4364 sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
4365 "%s",cmdline_option_value(argc,argv,++i));
4366 }else if( strcmp(z,"-header")==0 ){
4367 data.showHeader = 1;
4368 }else if( strcmp(z,"-noheader")==0 ){
4369 data.showHeader = 0;
@@ -4356,11 +4479,11 @@
4479 nHistory = strlen30(zHome) + 20;
4480 if( (zHistory = malloc(nHistory))!=0 ){
4481 sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
4482 }
4483 }
4484 #if HAVE_READLINE
4485 if( zHistory ) read_history(zHistory);
4486 #endif
4487 rc = process_input(&data, 0);
4488 if( zHistory ){
4489 stifle_history(100);
4490
+255 -191
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232232
** [sqlite_version()] and [sqlite_source_id()].
233233
*/
234234
#define SQLITE_VERSION "3.8.8"
235235
#define SQLITE_VERSION_NUMBER 3008008
236
-#define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
236
+#define SQLITE_SOURCE_ID "2015-01-10 18:22:06 46f3aba2692d74c29ab5c1f24a6daac600fd6af8"
237237
238238
/*
239239
** CAPI3REF: Run-Time Library Version Numbers
240240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241241
**
@@ -7613,10 +7613,14 @@
76137613
**
76147614
** The following constants can be used for the T parameter to the
76157615
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
76167616
** different metric for sqlite3_stmt_scanstatus() to return.
76177617
**
7618
+** When the value returned to V is a string, space to hold that string is
7619
+** managed by the prepared statement S and will be automatically freed when
7620
+** S is finalized.
7621
+**
76187622
** <dl>
76197623
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
76207624
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
76217625
** set to the total number of times that the X-th loop has run.</dd>
76227626
**
@@ -7658,11 +7662,18 @@
76587662
#define SQLITE_SCANSTAT_SELECTID 5
76597663
76607664
/*
76617665
** CAPI3REF: Prepared Statement Scan Status
76627666
**
7663
-** Return status data for a single loop within query pStmt.
7667
+** This interface returns information about the predicted and measured
7668
+** performance for pStmt. Advanced applications can use this
7669
+** interface to compare the predicted and the measured performance and
7670
+** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7671
+**
7672
+** Since this interface is expected to be rarely used, it is only
7673
+** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7674
+** compile-time option.
76647675
**
76657676
** The "iScanStatusOp" parameter determines which status information to return.
76667677
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
76677678
** of this interface is undefined.
76687679
** ^The requested measurement is written into a variable pointed to by
@@ -7676,13 +7687,10 @@
76767687
** ^Statistics might not be available for all loops in all statements. ^In cases
76777688
** where there exist loops with no available statistics, this function behaves
76787689
** as if the loop did not exist - it returns non-zero and leave the variable
76797690
** that pOut points to unchanged.
76807691
**
7681
-** This API is only available if the library is built with pre-processor
7682
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7683
-**
76847692
** See also: [sqlite3_stmt_scanstatus_reset()]
76857693
*/
76867694
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
76877695
sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
76887696
int idx, /* Index of loop to report on */
@@ -12054,11 +12062,11 @@
1205412062
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1205512063
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1205612064
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
1205712065
#define SF_Compound 0x0040 /* Part of a compound query */
1205812066
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
12059
- /* 0x0100 NOT USED */
12067
+#define SF_AllValues 0x0100 /* All terms of compound are VALUES */
1206012068
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1206112069
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1206212070
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
1206312071
#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
1206412072
@@ -12682,11 +12690,11 @@
1268212690
** FTS4 is really an extension for FTS3. It is enabled using the
1268312691
** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
1268412692
** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
1268512693
*/
1268612694
#if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12687
-# define SQLITE_ENABLE_FTS3
12695
+# define SQLITE_ENABLE_FTS3 1
1268812696
#endif
1268912697
1269012698
/*
1269112699
** The ctype.h header is needed for non-ASCII systems. It is also
1269212700
** needed by FTS3 when FTS3 is included in the amalgamation.
@@ -13824,355 +13832,355 @@
1382413832
/* These macros are provided to "stringify" the value of the define
1382513833
** for those options in which the value is meaningful. */
1382613834
#define CTIMEOPT_VAL_(opt) #opt
1382713835
#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
1382813836
13829
-#ifdef SQLITE_32BIT_ROWID
13837
+#if SQLITE_32BIT_ROWID
1383013838
"32BIT_ROWID",
1383113839
#endif
13832
-#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
13840
+#if SQLITE_4_BYTE_ALIGNED_MALLOC
1383313841
"4_BYTE_ALIGNED_MALLOC",
1383413842
#endif
13835
-#ifdef SQLITE_CASE_SENSITIVE_LIKE
13843
+#if SQLITE_CASE_SENSITIVE_LIKE
1383613844
"CASE_SENSITIVE_LIKE",
1383713845
#endif
13838
-#ifdef SQLITE_CHECK_PAGES
13846
+#if SQLITE_CHECK_PAGES
1383913847
"CHECK_PAGES",
1384013848
#endif
13841
-#ifdef SQLITE_COVERAGE_TEST
13849
+#if SQLITE_COVERAGE_TEST
1384213850
"COVERAGE_TEST",
1384313851
#endif
13844
-#ifdef SQLITE_DEBUG
13852
+#if SQLITE_DEBUG
1384513853
"DEBUG",
1384613854
#endif
13847
-#ifdef SQLITE_DEFAULT_LOCKING_MODE
13855
+#if SQLITE_DEFAULT_LOCKING_MODE
1384813856
"DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
1384913857
#endif
1385013858
#if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
1385113859
"DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
1385213860
#endif
13853
-#ifdef SQLITE_DISABLE_DIRSYNC
13861
+#if SQLITE_DISABLE_DIRSYNC
1385413862
"DISABLE_DIRSYNC",
1385513863
#endif
13856
-#ifdef SQLITE_DISABLE_LFS
13864
+#if SQLITE_DISABLE_LFS
1385713865
"DISABLE_LFS",
1385813866
#endif
13859
-#ifdef SQLITE_ENABLE_API_ARMOR
13867
+#if SQLITE_ENABLE_API_ARMOR
1386013868
"ENABLE_API_ARMOR",
1386113869
#endif
13862
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
13870
+#if SQLITE_ENABLE_ATOMIC_WRITE
1386313871
"ENABLE_ATOMIC_WRITE",
1386413872
#endif
13865
-#ifdef SQLITE_ENABLE_CEROD
13873
+#if SQLITE_ENABLE_CEROD
1386613874
"ENABLE_CEROD",
1386713875
#endif
13868
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
13876
+#if SQLITE_ENABLE_COLUMN_METADATA
1386913877
"ENABLE_COLUMN_METADATA",
1387013878
#endif
13871
-#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
13879
+#if SQLITE_ENABLE_EXPENSIVE_ASSERT
1387213880
"ENABLE_EXPENSIVE_ASSERT",
1387313881
#endif
13874
-#ifdef SQLITE_ENABLE_FTS1
13882
+#if SQLITE_ENABLE_FTS1
1387513883
"ENABLE_FTS1",
1387613884
#endif
13877
-#ifdef SQLITE_ENABLE_FTS2
13885
+#if SQLITE_ENABLE_FTS2
1387813886
"ENABLE_FTS2",
1387913887
#endif
13880
-#ifdef SQLITE_ENABLE_FTS3
13888
+#if SQLITE_ENABLE_FTS3
1388113889
"ENABLE_FTS3",
1388213890
#endif
13883
-#ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
13891
+#if SQLITE_ENABLE_FTS3_PARENTHESIS
1388413892
"ENABLE_FTS3_PARENTHESIS",
1388513893
#endif
13886
-#ifdef SQLITE_ENABLE_FTS4
13894
+#if SQLITE_ENABLE_FTS4
1388713895
"ENABLE_FTS4",
1388813896
#endif
13889
-#ifdef SQLITE_ENABLE_ICU
13897
+#if SQLITE_ENABLE_ICU
1389013898
"ENABLE_ICU",
1389113899
#endif
13892
-#ifdef SQLITE_ENABLE_IOTRACE
13900
+#if SQLITE_ENABLE_IOTRACE
1389313901
"ENABLE_IOTRACE",
1389413902
#endif
13895
-#ifdef SQLITE_ENABLE_LOAD_EXTENSION
13903
+#if SQLITE_ENABLE_LOAD_EXTENSION
1389613904
"ENABLE_LOAD_EXTENSION",
1389713905
#endif
13898
-#ifdef SQLITE_ENABLE_LOCKING_STYLE
13906
+#if SQLITE_ENABLE_LOCKING_STYLE
1389913907
"ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
1390013908
#endif
13901
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
13909
+#if SQLITE_ENABLE_MEMORY_MANAGEMENT
1390213910
"ENABLE_MEMORY_MANAGEMENT",
1390313911
#endif
13904
-#ifdef SQLITE_ENABLE_MEMSYS3
13912
+#if SQLITE_ENABLE_MEMSYS3
1390513913
"ENABLE_MEMSYS3",
1390613914
#endif
13907
-#ifdef SQLITE_ENABLE_MEMSYS5
13915
+#if SQLITE_ENABLE_MEMSYS5
1390813916
"ENABLE_MEMSYS5",
1390913917
#endif
13910
-#ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK
13918
+#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
1391113919
"ENABLE_OVERSIZE_CELL_CHECK",
1391213920
#endif
13913
-#ifdef SQLITE_ENABLE_RTREE
13921
+#if SQLITE_ENABLE_RTREE
1391413922
"ENABLE_RTREE",
1391513923
#endif
1391613924
#if defined(SQLITE_ENABLE_STAT4)
1391713925
"ENABLE_STAT4",
1391813926
#elif defined(SQLITE_ENABLE_STAT3)
1391913927
"ENABLE_STAT3",
1392013928
#endif
13921
-#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
13929
+#if SQLITE_ENABLE_UNLOCK_NOTIFY
1392213930
"ENABLE_UNLOCK_NOTIFY",
1392313931
#endif
13924
-#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
13932
+#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
1392513933
"ENABLE_UPDATE_DELETE_LIMIT",
1392613934
#endif
13927
-#ifdef SQLITE_HAS_CODEC
13935
+#if SQLITE_HAS_CODEC
1392813936
"HAS_CODEC",
1392913937
#endif
13930
-#ifdef SQLITE_HAVE_ISNAN
13938
+#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
1393113939
"HAVE_ISNAN",
1393213940
#endif
13933
-#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
13941
+#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
1393413942
"HOMEGROWN_RECURSIVE_MUTEX",
1393513943
#endif
13936
-#ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS
13944
+#if SQLITE_IGNORE_AFP_LOCK_ERRORS
1393713945
"IGNORE_AFP_LOCK_ERRORS",
1393813946
#endif
13939
-#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
13947
+#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
1394013948
"IGNORE_FLOCK_LOCK_ERRORS",
1394113949
#endif
1394213950
#ifdef SQLITE_INT64_TYPE
1394313951
"INT64_TYPE",
1394413952
#endif
13945
-#ifdef SQLITE_LOCK_TRACE
13953
+#if SQLITE_LOCK_TRACE
1394613954
"LOCK_TRACE",
1394713955
#endif
1394813956
#if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc)
1394913957
"MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
1395013958
#endif
1395113959
#ifdef SQLITE_MAX_SCHEMA_RETRY
1395213960
"MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
1395313961
#endif
13954
-#ifdef SQLITE_MEMDEBUG
13962
+#if SQLITE_MEMDEBUG
1395513963
"MEMDEBUG",
1395613964
#endif
13957
-#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
13965
+#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
1395813966
"MIXED_ENDIAN_64BIT_FLOAT",
1395913967
#endif
13960
-#ifdef SQLITE_NO_SYNC
13968
+#if SQLITE_NO_SYNC
1396113969
"NO_SYNC",
1396213970
#endif
13963
-#ifdef SQLITE_OMIT_ALTERTABLE
13971
+#if SQLITE_OMIT_ALTERTABLE
1396413972
"OMIT_ALTERTABLE",
1396513973
#endif
13966
-#ifdef SQLITE_OMIT_ANALYZE
13974
+#if SQLITE_OMIT_ANALYZE
1396713975
"OMIT_ANALYZE",
1396813976
#endif
13969
-#ifdef SQLITE_OMIT_ATTACH
13977
+#if SQLITE_OMIT_ATTACH
1397013978
"OMIT_ATTACH",
1397113979
#endif
13972
-#ifdef SQLITE_OMIT_AUTHORIZATION
13980
+#if SQLITE_OMIT_AUTHORIZATION
1397313981
"OMIT_AUTHORIZATION",
1397413982
#endif
13975
-#ifdef SQLITE_OMIT_AUTOINCREMENT
13983
+#if SQLITE_OMIT_AUTOINCREMENT
1397613984
"OMIT_AUTOINCREMENT",
1397713985
#endif
13978
-#ifdef SQLITE_OMIT_AUTOINIT
13986
+#if SQLITE_OMIT_AUTOINIT
1397913987
"OMIT_AUTOINIT",
1398013988
#endif
13981
-#ifdef SQLITE_OMIT_AUTOMATIC_INDEX
13989
+#if SQLITE_OMIT_AUTOMATIC_INDEX
1398213990
"OMIT_AUTOMATIC_INDEX",
1398313991
#endif
13984
-#ifdef SQLITE_OMIT_AUTORESET
13992
+#if SQLITE_OMIT_AUTORESET
1398513993
"OMIT_AUTORESET",
1398613994
#endif
13987
-#ifdef SQLITE_OMIT_AUTOVACUUM
13995
+#if SQLITE_OMIT_AUTOVACUUM
1398813996
"OMIT_AUTOVACUUM",
1398913997
#endif
13990
-#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
13998
+#if SQLITE_OMIT_BETWEEN_OPTIMIZATION
1399113999
"OMIT_BETWEEN_OPTIMIZATION",
1399214000
#endif
13993
-#ifdef SQLITE_OMIT_BLOB_LITERAL
14001
+#if SQLITE_OMIT_BLOB_LITERAL
1399414002
"OMIT_BLOB_LITERAL",
1399514003
#endif
13996
-#ifdef SQLITE_OMIT_BTREECOUNT
14004
+#if SQLITE_OMIT_BTREECOUNT
1399714005
"OMIT_BTREECOUNT",
1399814006
#endif
13999
-#ifdef SQLITE_OMIT_BUILTIN_TEST
14007
+#if SQLITE_OMIT_BUILTIN_TEST
1400014008
"OMIT_BUILTIN_TEST",
1400114009
#endif
14002
-#ifdef SQLITE_OMIT_CAST
14010
+#if SQLITE_OMIT_CAST
1400314011
"OMIT_CAST",
1400414012
#endif
14005
-#ifdef SQLITE_OMIT_CHECK
14013
+#if SQLITE_OMIT_CHECK
1400614014
"OMIT_CHECK",
1400714015
#endif
14008
-#ifdef SQLITE_OMIT_COMPLETE
14016
+#if SQLITE_OMIT_COMPLETE
1400914017
"OMIT_COMPLETE",
1401014018
#endif
14011
-#ifdef SQLITE_OMIT_COMPOUND_SELECT
14019
+#if SQLITE_OMIT_COMPOUND_SELECT
1401214020
"OMIT_COMPOUND_SELECT",
1401314021
#endif
14014
-#ifdef SQLITE_OMIT_CTE
14022
+#if SQLITE_OMIT_CTE
1401514023
"OMIT_CTE",
1401614024
#endif
14017
-#ifdef SQLITE_OMIT_DATETIME_FUNCS
14025
+#if SQLITE_OMIT_DATETIME_FUNCS
1401814026
"OMIT_DATETIME_FUNCS",
1401914027
#endif
14020
-#ifdef SQLITE_OMIT_DECLTYPE
14028
+#if SQLITE_OMIT_DECLTYPE
1402114029
"OMIT_DECLTYPE",
1402214030
#endif
14023
-#ifdef SQLITE_OMIT_DEPRECATED
14031
+#if SQLITE_OMIT_DEPRECATED
1402414032
"OMIT_DEPRECATED",
1402514033
#endif
14026
-#ifdef SQLITE_OMIT_DISKIO
14034
+#if SQLITE_OMIT_DISKIO
1402714035
"OMIT_DISKIO",
1402814036
#endif
14029
-#ifdef SQLITE_OMIT_EXPLAIN
14037
+#if SQLITE_OMIT_EXPLAIN
1403014038
"OMIT_EXPLAIN",
1403114039
#endif
14032
-#ifdef SQLITE_OMIT_FLAG_PRAGMAS
14040
+#if SQLITE_OMIT_FLAG_PRAGMAS
1403314041
"OMIT_FLAG_PRAGMAS",
1403414042
#endif
14035
-#ifdef SQLITE_OMIT_FLOATING_POINT
14043
+#if SQLITE_OMIT_FLOATING_POINT
1403614044
"OMIT_FLOATING_POINT",
1403714045
#endif
14038
-#ifdef SQLITE_OMIT_FOREIGN_KEY
14046
+#if SQLITE_OMIT_FOREIGN_KEY
1403914047
"OMIT_FOREIGN_KEY",
1404014048
#endif
14041
-#ifdef SQLITE_OMIT_GET_TABLE
14049
+#if SQLITE_OMIT_GET_TABLE
1404214050
"OMIT_GET_TABLE",
1404314051
#endif
14044
-#ifdef SQLITE_OMIT_INCRBLOB
14052
+#if SQLITE_OMIT_INCRBLOB
1404514053
"OMIT_INCRBLOB",
1404614054
#endif
14047
-#ifdef SQLITE_OMIT_INTEGRITY_CHECK
14055
+#if SQLITE_OMIT_INTEGRITY_CHECK
1404814056
"OMIT_INTEGRITY_CHECK",
1404914057
#endif
14050
-#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
14058
+#if SQLITE_OMIT_LIKE_OPTIMIZATION
1405114059
"OMIT_LIKE_OPTIMIZATION",
1405214060
#endif
14053
-#ifdef SQLITE_OMIT_LOAD_EXTENSION
14061
+#if SQLITE_OMIT_LOAD_EXTENSION
1405414062
"OMIT_LOAD_EXTENSION",
1405514063
#endif
14056
-#ifdef SQLITE_OMIT_LOCALTIME
14064
+#if SQLITE_OMIT_LOCALTIME
1405714065
"OMIT_LOCALTIME",
1405814066
#endif
14059
-#ifdef SQLITE_OMIT_LOOKASIDE
14067
+#if SQLITE_OMIT_LOOKASIDE
1406014068
"OMIT_LOOKASIDE",
1406114069
#endif
14062
-#ifdef SQLITE_OMIT_MEMORYDB
14070
+#if SQLITE_OMIT_MEMORYDB
1406314071
"OMIT_MEMORYDB",
1406414072
#endif
14065
-#ifdef SQLITE_OMIT_OR_OPTIMIZATION
14073
+#if SQLITE_OMIT_OR_OPTIMIZATION
1406614074
"OMIT_OR_OPTIMIZATION",
1406714075
#endif
14068
-#ifdef SQLITE_OMIT_PAGER_PRAGMAS
14076
+#if SQLITE_OMIT_PAGER_PRAGMAS
1406914077
"OMIT_PAGER_PRAGMAS",
1407014078
#endif
14071
-#ifdef SQLITE_OMIT_PRAGMA
14079
+#if SQLITE_OMIT_PRAGMA
1407214080
"OMIT_PRAGMA",
1407314081
#endif
14074
-#ifdef SQLITE_OMIT_PROGRESS_CALLBACK
14082
+#if SQLITE_OMIT_PROGRESS_CALLBACK
1407514083
"OMIT_PROGRESS_CALLBACK",
1407614084
#endif
14077
-#ifdef SQLITE_OMIT_QUICKBALANCE
14085
+#if SQLITE_OMIT_QUICKBALANCE
1407814086
"OMIT_QUICKBALANCE",
1407914087
#endif
14080
-#ifdef SQLITE_OMIT_REINDEX
14088
+#if SQLITE_OMIT_REINDEX
1408114089
"OMIT_REINDEX",
1408214090
#endif
14083
-#ifdef SQLITE_OMIT_SCHEMA_PRAGMAS
14091
+#if SQLITE_OMIT_SCHEMA_PRAGMAS
1408414092
"OMIT_SCHEMA_PRAGMAS",
1408514093
#endif
14086
-#ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
14094
+#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
1408714095
"OMIT_SCHEMA_VERSION_PRAGMAS",
1408814096
#endif
14089
-#ifdef SQLITE_OMIT_SHARED_CACHE
14097
+#if SQLITE_OMIT_SHARED_CACHE
1409014098
"OMIT_SHARED_CACHE",
1409114099
#endif
14092
-#ifdef SQLITE_OMIT_SUBQUERY
14100
+#if SQLITE_OMIT_SUBQUERY
1409314101
"OMIT_SUBQUERY",
1409414102
#endif
14095
-#ifdef SQLITE_OMIT_TCL_VARIABLE
14103
+#if SQLITE_OMIT_TCL_VARIABLE
1409614104
"OMIT_TCL_VARIABLE",
1409714105
#endif
14098
-#ifdef SQLITE_OMIT_TEMPDB
14106
+#if SQLITE_OMIT_TEMPDB
1409914107
"OMIT_TEMPDB",
1410014108
#endif
14101
-#ifdef SQLITE_OMIT_TRACE
14109
+#if SQLITE_OMIT_TRACE
1410214110
"OMIT_TRACE",
1410314111
#endif
14104
-#ifdef SQLITE_OMIT_TRIGGER
14112
+#if SQLITE_OMIT_TRIGGER
1410514113
"OMIT_TRIGGER",
1410614114
#endif
14107
-#ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
14115
+#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
1410814116
"OMIT_TRUNCATE_OPTIMIZATION",
1410914117
#endif
14110
-#ifdef SQLITE_OMIT_UTF16
14118
+#if SQLITE_OMIT_UTF16
1411114119
"OMIT_UTF16",
1411214120
#endif
14113
-#ifdef SQLITE_OMIT_VACUUM
14121
+#if SQLITE_OMIT_VACUUM
1411414122
"OMIT_VACUUM",
1411514123
#endif
14116
-#ifdef SQLITE_OMIT_VIEW
14124
+#if SQLITE_OMIT_VIEW
1411714125
"OMIT_VIEW",
1411814126
#endif
14119
-#ifdef SQLITE_OMIT_VIRTUALTABLE
14127
+#if SQLITE_OMIT_VIRTUALTABLE
1412014128
"OMIT_VIRTUALTABLE",
1412114129
#endif
14122
-#ifdef SQLITE_OMIT_WAL
14130
+#if SQLITE_OMIT_WAL
1412314131
"OMIT_WAL",
1412414132
#endif
14125
-#ifdef SQLITE_OMIT_WSD
14133
+#if SQLITE_OMIT_WSD
1412614134
"OMIT_WSD",
1412714135
#endif
14128
-#ifdef SQLITE_OMIT_XFER_OPT
14136
+#if SQLITE_OMIT_XFER_OPT
1412914137
"OMIT_XFER_OPT",
1413014138
#endif
14131
-#ifdef SQLITE_PERFORMANCE_TRACE
14139
+#if SQLITE_PERFORMANCE_TRACE
1413214140
"PERFORMANCE_TRACE",
1413314141
#endif
14134
-#ifdef SQLITE_PROXY_DEBUG
14142
+#if SQLITE_PROXY_DEBUG
1413514143
"PROXY_DEBUG",
1413614144
#endif
14137
-#ifdef SQLITE_RTREE_INT_ONLY
14145
+#if SQLITE_RTREE_INT_ONLY
1413814146
"RTREE_INT_ONLY",
1413914147
#endif
14140
-#ifdef SQLITE_SECURE_DELETE
14148
+#if SQLITE_SECURE_DELETE
1414114149
"SECURE_DELETE",
1414214150
#endif
14143
-#ifdef SQLITE_SMALL_STACK
14151
+#if SQLITE_SMALL_STACK
1414414152
"SMALL_STACK",
1414514153
#endif
14146
-#ifdef SQLITE_SOUNDEX
14154
+#if SQLITE_SOUNDEX
1414714155
"SOUNDEX",
1414814156
#endif
14149
-#ifdef SQLITE_SYSTEM_MALLOC
14157
+#if SQLITE_SYSTEM_MALLOC
1415014158
"SYSTEM_MALLOC",
1415114159
#endif
14152
-#ifdef SQLITE_TCL
14160
+#if SQLITE_TCL
1415314161
"TCL",
1415414162
#endif
1415514163
#if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
1415614164
"TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
1415714165
#endif
14158
-#ifdef SQLITE_TEST
14166
+#if SQLITE_TEST
1415914167
"TEST",
1416014168
#endif
1416114169
#if defined(SQLITE_THREADSAFE)
1416214170
"THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
1416314171
#endif
14164
-#ifdef SQLITE_USE_ALLOCA
14172
+#if SQLITE_USE_ALLOCA
1416514173
"USE_ALLOCA",
1416614174
#endif
14167
-#ifdef SQLITE_USER_AUTHENTICATION
14175
+#if SQLITE_USER_AUTHENTICATION
1416814176
"USER_AUTHENTICATION",
1416914177
#endif
14170
-#ifdef SQLITE_WIN32_MALLOC
14178
+#if SQLITE_WIN32_MALLOC
1417114179
"WIN32_MALLOC",
1417214180
#endif
14173
-#ifdef SQLITE_ZERO_MALLOC
14181
+#if SQLITE_ZERO_MALLOC
1417414182
"ZERO_MALLOC"
1417514183
#endif
1417614184
};
1417714185
1417814186
/*
@@ -14183,11 +14191,11 @@
1418314191
** is not required for a match.
1418414192
*/
1418514193
SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
1418614194
int i, n;
1418714195
14188
-#ifdef SQLITE_ENABLE_API_ARMOR
14196
+#if SQLITE_ENABLE_API_ARMOR
1418914197
if( zOptName==0 ){
1419014198
(void)SQLITE_MISUSE_BKPT;
1419114199
return 0;
1419214200
}
1419314201
#endif
@@ -15411,12 +15419,13 @@
1541115419
**
1541215420
** If the user has not indicated to use localtime_r() or localtime_s()
1541315421
** already, check for an MSVC build environment that provides
1541415422
** localtime_s().
1541515423
*/
15416
-#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
15417
- defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
15424
+#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S \
15425
+ && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
15426
+#undef HAVE_LOCALTIME_S
1541815427
#define HAVE_LOCALTIME_S 1
1541915428
#endif
1542015429
1542115430
#ifndef SQLITE_OMIT_LOCALTIME
1542215431
/*
@@ -15432,12 +15441,11 @@
1543215441
** library function localtime_r() is used to assist in the calculation of
1543315442
** local time.
1543415443
*/
1543515444
static int osLocaltime(time_t *t, struct tm *pTm){
1543615445
int rc;
15437
-#if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \
15438
- && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S)
15446
+#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
1543915447
struct tm *pX;
1544015448
#if SQLITE_THREADSAFE>0
1544115449
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
1544215450
#endif
1544315451
sqlite3_mutex_enter(mutex);
@@ -15450,11 +15458,11 @@
1545015458
rc = pX==0;
1545115459
#else
1545215460
#ifndef SQLITE_OMIT_BUILTIN_TEST
1545315461
if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
1545415462
#endif
15455
-#if defined(HAVE_LOCALTIME_R) && HAVE_LOCALTIME_R
15463
+#if HAVE_LOCALTIME_R
1545615464
rc = localtime_r(t, pTm)==0;
1545715465
#else
1545815466
rc = localtime_s(pTm, t);
1545915467
#endif /* HAVE_LOCALTIME_R */
1546015468
#endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */
@@ -15894,12 +15902,14 @@
1589415902
DateTime x;
1589515903
u64 n;
1589615904
size_t i,j;
1589715905
char *z;
1589815906
sqlite3 *db;
15899
- const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
15907
+ const char *zFmt;
1590015908
char zBuf[100];
15909
+ if( argc==0 ) return;
15910
+ zFmt = (const char*)sqlite3_value_text(argv[0]);
1590115911
if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
1590215912
db = sqlite3_context_db_handle(context);
1590315913
for(i=0, n=1; zFmt[i]; i++, n++){
1590415914
if( zFmt[i]=='%' ){
1590515915
switch( zFmt[i+1] ){
@@ -16089,11 +16099,11 @@
1608916099
UNUSED_PARAMETER(argv);
1609016100
1609116101
iT = sqlite3StmtCurrentTime(context);
1609216102
if( iT<=0 ) return;
1609316103
t = iT/1000 - 10000*(sqlite3_int64)21086676;
16094
-#ifdef HAVE_GMTIME_R
16104
+#if HAVE_GMTIME_R
1609516105
pTm = gmtime_r(&t, &sNow);
1609616106
#else
1609716107
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
1609816108
pTm = gmtime(&t);
1609916109
if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
@@ -16763,13 +16773,13 @@
1676316773
1676416774
/*
1676516775
** The malloc.h header file is needed for malloc_usable_size() function
1676616776
** on some systems (e.g. Linux).
1676716777
*/
16768
-#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
16769
-# define SQLITE_USE_MALLOC_H
16770
-# define SQLITE_USE_MALLOC_USABLE_SIZE
16778
+#if HAVE_MALLOC_H && HAVE_MALLOC_USABLE_SIZE
16779
+# define SQLITE_USE_MALLOC_H 1
16780
+# define SQLITE_USE_MALLOC_USABLE_SIZE 1
1677116781
/*
1677216782
** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
1677316783
** use of _msize() is automatic, but can be disabled by compiling with
1677416784
** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
1677516785
** the malloc.h header file.
@@ -21004,21 +21014,10 @@
2100421014
** This file contains code for a set of "printf"-like routines. These
2100521015
** routines format strings much like the printf() from the standard C
2100621016
** library, though the implementation here has enhancements to support
2100721017
** SQLlite.
2100821018
*/
21009
-
21010
-/*
21011
-** If the strchrnul() library function is available, then set
21012
-** HAVE_STRCHRNUL. If that routine is not available, this module
21013
-** will supply its own. The built-in version is slower than
21014
-** the glibc version so the glibc version is definitely preferred.
21015
-*/
21016
-#if !defined(HAVE_STRCHRNUL)
21017
-# define HAVE_STRCHRNUL 0
21018
-#endif
21019
-
2102021019
2102121020
/*
2102221021
** Conversion types fall into various categories as defined by the
2102321022
** following enumeration.
2102421023
*/
@@ -22313,10 +22312,12 @@
2231322312
** single threaded systems. Nothing in SQLite requires multiple threads.
2231422313
** This interface exists so that applications that want to take advantage
2231522314
** of multiple cores can do so, while also allowing applications to stay
2231622315
** single-threaded if desired.
2231722316
*/
22317
+#if SQLITE_OS_WIN
22318
+#endif
2231822319
2231922320
#if SQLITE_MAX_WORKER_THREADS>0
2232022321
2232122322
/********************************* Unix Pthreads ****************************/
2232222323
#if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
@@ -23099,11 +23100,11 @@
2309923100
** This file contains functions for allocating memory, comparing
2310023101
** strings, and stuff like that.
2310123102
**
2310223103
*/
2310323104
/* #include <stdarg.h> */
23104
-#ifdef SQLITE_HAVE_ISNAN
23105
+#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
2310523106
# include <math.h>
2310623107
#endif
2310723108
2310823109
/*
2310923110
** Routine needed to support the testcase() macro.
@@ -23140,11 +23141,11 @@
2314023141
** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
2314123142
** Otherwise, we have our own implementation that works on most systems.
2314223143
*/
2314323144
SQLITE_PRIVATE int sqlite3IsNaN(double x){
2314423145
int rc; /* The value return */
23145
-#if !defined(SQLITE_HAVE_ISNAN)
23146
+#if !SQLITE_HAVE_ISNAN && !HAVE_ISNAN
2314623147
/*
2314723148
** Systems that support the isnan() library function should probably
2314823149
** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have
2314923150
** found that many systems do not have a working isnan() function so
2315023151
** this implementation is provided as an alternative.
@@ -23170,13 +23171,13 @@
2317023171
# error SQLite will not work correctly with the -ffast-math option of GCC.
2317123172
#endif
2317223173
volatile double y = x;
2317323174
volatile double z = y;
2317423175
rc = (y!=z);
23175
-#else /* if defined(SQLITE_HAVE_ISNAN) */
23176
+#else /* if HAVE_ISNAN */
2317623177
rc = isnan(x);
23177
-#endif /* SQLITE_HAVE_ISNAN */
23178
+#endif /* HAVE_ISNAN */
2317823179
testcase( rc );
2317923180
return rc;
2318023181
}
2318123182
#endif /* SQLITE_OMIT_FLOATING_POINT */
2318223183
@@ -28493,13 +28494,13 @@
2849328494
2849428495
/*
2849528496
** We do not trust systems to provide a working fdatasync(). Some do.
2849628497
** Others do no. To be safe, we will stick with the (slightly slower)
2849728498
** fsync(). If you know that your system does support fdatasync() correctly,
28498
-** then simply compile with -Dfdatasync=fdatasync
28499
+** then simply compile with -Dfdatasync=fdatasync or -DHAVE_FDATASYNC
2849928500
*/
28500
-#if !defined(fdatasync)
28501
+#if !defined(fdatasync) && !HAVE_FDATASYNC
2850128502
# define fdatasync fsync
2850228503
#endif
2850328504
2850428505
/*
2850528506
** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
@@ -28824,22 +28825,23 @@
2882428825
** at offset (nSize-1), to set the size of the file correctly.
2882528826
** This is a similar technique to that used by glibc on systems
2882628827
** that do not have a real fallocate() call.
2882728828
*/
2882828829
int nBlk = buf.st_blksize; /* File-system block size */
28830
+ int nWrite = 0; /* Number of bytes written by seekAndWrite */
2882928831
i64 iWrite; /* Next offset to write to */
2883028832
2883128833
iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
2883228834
assert( iWrite>=buf.st_size );
2883328835
assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
2883428836
assert( ((iWrite+1)%nBlk)==0 );
2883528837
for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
28836
- int nWrite = seekAndWrite(pFile, iWrite, "", 1);
28838
+ nWrite = seekAndWrite(pFile, iWrite, "", 1);
2883728839
if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
2883828840
}
28839
- if( nSize%nBlk ){
28840
- int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
28841
+ if( nWrite==0 || (nSize%nBlk) ){
28842
+ nWrite = seekAndWrite(pFile, nSize-1, "", 1);
2884128843
if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
2884228844
}
2884328845
#endif
2884428846
}
2884528847
}
@@ -38849,22 +38851,10 @@
3884938851
void *pStress; /* Argument to xStress */
3885038852
sqlite3_pcache *pCache; /* Pluggable cache module */
3885138853
PgHdr *pPage1; /* Reference to page 1 */
3885238854
};
3885338855
38854
-/*
38855
-** Some of the assert() macros in this code are too expensive to run
38856
-** even during normal debugging. Use them only rarely on long-running
38857
-** tests. Enable the expensive asserts using the
38858
-** -DSQLITE_ENABLE_EXPENSIVE_ASSERT=1 compile-time option.
38859
-*/
38860
-#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
38861
-# define expensive_assert(X) assert(X)
38862
-#else
38863
-# define expensive_assert(X)
38864
-#endif
38865
-
3886638856
/********************************** Linked List Management ********************/
3886738857
3886838858
/* Allowed values for second argument to pcacheManageDirtyList() */
3886938859
#define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
3887038860
#define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
@@ -82230,11 +82220,11 @@
8223082220
Expr *pLeft, /* Left operand */
8223182221
Expr *pRight, /* Right operand */
8223282222
const Token *pToken /* Argument token */
8223382223
){
8223482224
Expr *p;
82235
- if( op==TK_AND && pLeft && pRight ){
82225
+ if( op==TK_AND && pLeft && pRight && pParse->nErr==0 ){
8223682226
/* Take advantage of short-circuit false optimization for AND */
8223782227
p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
8223882228
}else{
8223982229
p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
8224082230
sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
@@ -85784,14 +85774,15 @@
8578485774
** NEVER() will need to be removed. */
8578585775
if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
8578685776
int i;
8578785777
struct SrcCount *p = pWalker->u.pSrcCount;
8578885778
SrcList *pSrc = p->pSrc;
85789
- for(i=0; i<pSrc->nSrc; i++){
85779
+ int nSrc = pSrc ? pSrc->nSrc : 0;
85780
+ for(i=0; i<nSrc; i++){
8579085781
if( pExpr->iTable==pSrc->a[i].iCursor ) break;
8579185782
}
85792
- if( i<pSrc->nSrc ){
85783
+ if( i<nSrc ){
8579385784
p->nThis++;
8579485785
}else{
8579585786
p->nOther++;
8579685787
}
8579785788
}
@@ -105271,24 +105262,29 @@
105271105262
u8 sortFlags; /* Zero or more SORTFLAG_* bits */
105272105263
};
105273105264
#define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
105274105265
105275105266
/*
105276
-** Delete all the content of a Select structure but do not deallocate
105277
-** the select structure itself.
105267
+** Delete all the content of a Select structure. Deallocate the structure
105268
+** itself only if bFree is true.
105278105269
*/
105279
-static void clearSelect(sqlite3 *db, Select *p){
105280
- sqlite3ExprListDelete(db, p->pEList);
105281
- sqlite3SrcListDelete(db, p->pSrc);
105282
- sqlite3ExprDelete(db, p->pWhere);
105283
- sqlite3ExprListDelete(db, p->pGroupBy);
105284
- sqlite3ExprDelete(db, p->pHaving);
105285
- sqlite3ExprListDelete(db, p->pOrderBy);
105286
- sqlite3SelectDelete(db, p->pPrior);
105287
- sqlite3ExprDelete(db, p->pLimit);
105288
- sqlite3ExprDelete(db, p->pOffset);
105289
- sqlite3WithDelete(db, p->pWith);
105270
+static void clearSelect(sqlite3 *db, Select *p, int bFree){
105271
+ while( p ){
105272
+ Select *pPrior = p->pPrior;
105273
+ sqlite3ExprListDelete(db, p->pEList);
105274
+ sqlite3SrcListDelete(db, p->pSrc);
105275
+ sqlite3ExprDelete(db, p->pWhere);
105276
+ sqlite3ExprListDelete(db, p->pGroupBy);
105277
+ sqlite3ExprDelete(db, p->pHaving);
105278
+ sqlite3ExprListDelete(db, p->pOrderBy);
105279
+ sqlite3ExprDelete(db, p->pLimit);
105280
+ sqlite3ExprDelete(db, p->pOffset);
105281
+ sqlite3WithDelete(db, p->pWith);
105282
+ if( bFree ) sqlite3DbFree(db, p);
105283
+ p = pPrior;
105284
+ bFree = 1;
105285
+ }
105290105286
}
105291105287
105292105288
/*
105293105289
** Initialize a SelectDest structure.
105294105290
*/
@@ -105343,12 +105339,11 @@
105343105339
pNew->pOffset = pOffset;
105344105340
assert( pOffset==0 || pLimit!=0 );
105345105341
pNew->addrOpenEphm[0] = -1;
105346105342
pNew->addrOpenEphm[1] = -1;
105347105343
if( db->mallocFailed ) {
105348
- clearSelect(db, pNew);
105349
- if( pNew!=&standin ) sqlite3DbFree(db, pNew);
105344
+ clearSelect(db, pNew, pNew!=&standin);
105350105345
pNew = 0;
105351105346
}else{
105352105347
assert( pNew->pSrc!=0 || pParse->nErr>0 );
105353105348
}
105354105349
assert( pNew!=&standin );
@@ -105369,14 +105364,11 @@
105369105364
105370105365
/*
105371105366
** Delete the given Select structure and all of its substructures.
105372105367
*/
105373105368
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
105374
- if( p ){
105375
- clearSelect(db, p);
105376
- sqlite3DbFree(db, p);
105377
- }
105369
+ clearSelect(db, p, 1);
105378105370
}
105379105371
105380105372
/*
105381105373
** Return a pointer to the right-most SELECT statement in a compound.
105382105374
*/
@@ -107288,10 +107280,70 @@
107288107280
Parse *pParse, /* Parsing context */
107289107281
Select *p, /* The right-most of SELECTs to be coded */
107290107282
SelectDest *pDest /* What to do with query results */
107291107283
);
107292107284
107285
+/*
107286
+** Error message for when two or more terms of a compound select have different
107287
+** size result sets.
107288
+*/
107289
+static void selectWrongNumTermsError(Parse *pParse, Select *p){
107290
+ if( p->selFlags & SF_Values ){
107291
+ sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107292
+ }else{
107293
+ sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107294
+ " do not have the same number of result columns", selectOpName(p->op));
107295
+ }
107296
+}
107297
+
107298
+/*
107299
+** Handle the special case of a compound-select that originates from a
107300
+** VALUES clause. By handling this as a special case, we avoid deep
107301
+** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
107302
+** on a VALUES clause.
107303
+**
107304
+** Because the Select object originates from a VALUES clause:
107305
+** (1) It has no LIMIT or OFFSET
107306
+** (2) All terms are UNION ALL
107307
+** (3) There is no ORDER BY clause
107308
+*/
107309
+static int multiSelectValues(
107310
+ Parse *pParse, /* Parsing context */
107311
+ Select *p, /* The right-most of SELECTs to be coded */
107312
+ SelectDest *pDest /* What to do with query results */
107313
+){
107314
+ Select *pPrior;
107315
+ int nExpr = p->pEList->nExpr;
107316
+ int nRow = 1;
107317
+ int rc = 0;
107318
+ assert( p->pNext==0 );
107319
+ assert( p->selFlags & SF_AllValues );
107320
+ do{
107321
+ assert( p->selFlags & SF_Values );
107322
+ assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
107323
+ assert( p->pLimit==0 );
107324
+ assert( p->pOffset==0 );
107325
+ if( p->pEList->nExpr!=nExpr ){
107326
+ selectWrongNumTermsError(pParse, p);
107327
+ return 1;
107328
+ }
107329
+ if( p->pPrior==0 ) break;
107330
+ assert( p->pPrior->pNext==p );
107331
+ p = p->pPrior;
107332
+ nRow++;
107333
+ }while(1);
107334
+ while( p ){
107335
+ pPrior = p->pPrior;
107336
+ p->pPrior = 0;
107337
+ rc = sqlite3Select(pParse, p, pDest);
107338
+ p->pPrior = pPrior;
107339
+ if( rc ) break;
107340
+ p->nSelectRow = nRow;
107341
+ p = p->pNext;
107342
+ }
107343
+ return rc;
107344
+}
107293107345
107294107346
/*
107295107347
** This routine is called to process a compound query form from
107296107348
** two or more separate queries using UNION, UNION ALL, EXCEPT, or
107297107349
** INTERSECT
@@ -107368,22 +107420,24 @@
107368107420
assert( p->pEList );
107369107421
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr);
107370107422
sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
107371107423
dest.eDest = SRT_Table;
107372107424
}
107425
+
107426
+ /* Special handling for a compound-select that originates as a VALUES clause.
107427
+ */
107428
+ if( p->selFlags & SF_AllValues ){
107429
+ rc = multiSelectValues(pParse, p, &dest);
107430
+ goto multi_select_end;
107431
+ }
107373107432
107374107433
/* Make sure all SELECTs in the statement have the same number of elements
107375107434
** in their result sets.
107376107435
*/
107377107436
assert( p->pEList && pPrior->pEList );
107378107437
if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
107379
- if( p->selFlags & SF_Values ){
107380
- sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107381
- }else{
107382
- sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107383
- " do not have the same number of result columns", selectOpName(p->op));
107384
- }
107438
+ selectWrongNumTermsError(pParse, p);
107385107439
rc = 1;
107386107440
goto multi_select_end;
107387107441
}
107388107442
107389107443
#ifndef SQLITE_OMIT_CTE
@@ -109265,11 +109319,13 @@
109265109319
if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
109266109320
return WRC_Prune;
109267109321
}
109268109322
pTabList = p->pSrc;
109269109323
pEList = p->pEList;
109270
- sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
109324
+ if( pWalker->xSelectCallback2==selectPopWith ){
109325
+ sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
109326
+ }
109271109327
109272109328
/* Make sure cursor numbers have been assigned to all entries in
109273109329
** the FROM clause of the SELECT statement.
109274109330
*/
109275109331
sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -109556,11 +109612,13 @@
109556109612
if( pParse->hasCompound ){
109557109613
w.xSelectCallback = convertCompoundSelectToSubquery;
109558109614
sqlite3WalkSelect(&w, pSelect);
109559109615
}
109560109616
w.xSelectCallback = selectExpander;
109561
- w.xSelectCallback2 = selectPopWith;
109617
+ if( (pSelect->selFlags & SF_AllValues)==0 ){
109618
+ w.xSelectCallback2 = selectPopWith;
109619
+ }
109562109620
sqlite3WalkSelect(&w, pSelect);
109563109621
}
109564109622
109565109623
109566109624
#ifndef SQLITE_OMIT_SUBQUERY
@@ -123884,17 +123942,23 @@
123884123942
Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
123885123943
if( p ){
123886123944
int cnt = 0, mxSelect;
123887123945
p->pWith = yymsp[-1].minor.yy59;
123888123946
if( p->pPrior ){
123947
+ u16 allValues = SF_Values;
123889123948
pNext = 0;
123890123949
for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123891123950
pLoop->pNext = pNext;
123892123951
pLoop->selFlags |= SF_Compound;
123952
+ allValues &= pLoop->selFlags;
123893123953
}
123894
- mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
123895
- if( mxSelect && cnt>mxSelect ){
123954
+ if( allValues ){
123955
+ p->selFlags |= SF_AllValues;
123956
+ }else if(
123957
+ (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
123958
+ && cnt>mxSelect
123959
+ ){
123896123960
sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123897123961
}
123898123962
}
123899123963
}else{
123900123964
sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
@@ -127600,11 +127664,11 @@
127600127664
*/
127601127665
static int sqliteDefaultBusyCallback(
127602127666
void *ptr, /* Database connection */
127603127667
int count /* Number of times table has been busy */
127604127668
){
127605
-#if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP)
127669
+#if SQLITE_OS_WIN || HAVE_USLEEP
127606127670
static const u8 delays[] =
127607127671
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
127608127672
static const u8 totals[] =
127609127673
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
127610127674
# define NDELAY ArraySize(delays)
127611127675
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.8"
235 #define SQLITE_VERSION_NUMBER 3008008
236 #define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -7613,10 +7613,14 @@
7613 **
7614 ** The following constants can be used for the T parameter to the
7615 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7616 ** different metric for sqlite3_stmt_scanstatus() to return.
7617 **
 
 
 
 
7618 ** <dl>
7619 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7620 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7621 ** set to the total number of times that the X-th loop has run.</dd>
7622 **
@@ -7658,11 +7662,18 @@
7658 #define SQLITE_SCANSTAT_SELECTID 5
7659
7660 /*
7661 ** CAPI3REF: Prepared Statement Scan Status
7662 **
7663 ** Return status data for a single loop within query pStmt.
 
 
 
 
 
 
 
7664 **
7665 ** The "iScanStatusOp" parameter determines which status information to return.
7666 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7667 ** of this interface is undefined.
7668 ** ^The requested measurement is written into a variable pointed to by
@@ -7676,13 +7687,10 @@
7676 ** ^Statistics might not be available for all loops in all statements. ^In cases
7677 ** where there exist loops with no available statistics, this function behaves
7678 ** as if the loop did not exist - it returns non-zero and leave the variable
7679 ** that pOut points to unchanged.
7680 **
7681 ** This API is only available if the library is built with pre-processor
7682 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7683 **
7684 ** See also: [sqlite3_stmt_scanstatus_reset()]
7685 */
7686 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7687 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7688 int idx, /* Index of loop to report on */
@@ -12054,11 +12062,11 @@
12054 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12055 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12056 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12057 #define SF_Compound 0x0040 /* Part of a compound query */
12058 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12059 /* 0x0100 NOT USED */
12060 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12061 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12062 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12063 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12064
@@ -12682,11 +12690,11 @@
12682 ** FTS4 is really an extension for FTS3. It is enabled using the
12683 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
12684 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
12685 */
12686 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12687 # define SQLITE_ENABLE_FTS3
12688 #endif
12689
12690 /*
12691 ** The ctype.h header is needed for non-ASCII systems. It is also
12692 ** needed by FTS3 when FTS3 is included in the amalgamation.
@@ -13824,355 +13832,355 @@
13824 /* These macros are provided to "stringify" the value of the define
13825 ** for those options in which the value is meaningful. */
13826 #define CTIMEOPT_VAL_(opt) #opt
13827 #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
13828
13829 #ifdef SQLITE_32BIT_ROWID
13830 "32BIT_ROWID",
13831 #endif
13832 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
13833 "4_BYTE_ALIGNED_MALLOC",
13834 #endif
13835 #ifdef SQLITE_CASE_SENSITIVE_LIKE
13836 "CASE_SENSITIVE_LIKE",
13837 #endif
13838 #ifdef SQLITE_CHECK_PAGES
13839 "CHECK_PAGES",
13840 #endif
13841 #ifdef SQLITE_COVERAGE_TEST
13842 "COVERAGE_TEST",
13843 #endif
13844 #ifdef SQLITE_DEBUG
13845 "DEBUG",
13846 #endif
13847 #ifdef SQLITE_DEFAULT_LOCKING_MODE
13848 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
13849 #endif
13850 #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
13851 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
13852 #endif
13853 #ifdef SQLITE_DISABLE_DIRSYNC
13854 "DISABLE_DIRSYNC",
13855 #endif
13856 #ifdef SQLITE_DISABLE_LFS
13857 "DISABLE_LFS",
13858 #endif
13859 #ifdef SQLITE_ENABLE_API_ARMOR
13860 "ENABLE_API_ARMOR",
13861 #endif
13862 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
13863 "ENABLE_ATOMIC_WRITE",
13864 #endif
13865 #ifdef SQLITE_ENABLE_CEROD
13866 "ENABLE_CEROD",
13867 #endif
13868 #ifdef SQLITE_ENABLE_COLUMN_METADATA
13869 "ENABLE_COLUMN_METADATA",
13870 #endif
13871 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
13872 "ENABLE_EXPENSIVE_ASSERT",
13873 #endif
13874 #ifdef SQLITE_ENABLE_FTS1
13875 "ENABLE_FTS1",
13876 #endif
13877 #ifdef SQLITE_ENABLE_FTS2
13878 "ENABLE_FTS2",
13879 #endif
13880 #ifdef SQLITE_ENABLE_FTS3
13881 "ENABLE_FTS3",
13882 #endif
13883 #ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
13884 "ENABLE_FTS3_PARENTHESIS",
13885 #endif
13886 #ifdef SQLITE_ENABLE_FTS4
13887 "ENABLE_FTS4",
13888 #endif
13889 #ifdef SQLITE_ENABLE_ICU
13890 "ENABLE_ICU",
13891 #endif
13892 #ifdef SQLITE_ENABLE_IOTRACE
13893 "ENABLE_IOTRACE",
13894 #endif
13895 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
13896 "ENABLE_LOAD_EXTENSION",
13897 #endif
13898 #ifdef SQLITE_ENABLE_LOCKING_STYLE
13899 "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
13900 #endif
13901 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
13902 "ENABLE_MEMORY_MANAGEMENT",
13903 #endif
13904 #ifdef SQLITE_ENABLE_MEMSYS3
13905 "ENABLE_MEMSYS3",
13906 #endif
13907 #ifdef SQLITE_ENABLE_MEMSYS5
13908 "ENABLE_MEMSYS5",
13909 #endif
13910 #ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK
13911 "ENABLE_OVERSIZE_CELL_CHECK",
13912 #endif
13913 #ifdef SQLITE_ENABLE_RTREE
13914 "ENABLE_RTREE",
13915 #endif
13916 #if defined(SQLITE_ENABLE_STAT4)
13917 "ENABLE_STAT4",
13918 #elif defined(SQLITE_ENABLE_STAT3)
13919 "ENABLE_STAT3",
13920 #endif
13921 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
13922 "ENABLE_UNLOCK_NOTIFY",
13923 #endif
13924 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
13925 "ENABLE_UPDATE_DELETE_LIMIT",
13926 #endif
13927 #ifdef SQLITE_HAS_CODEC
13928 "HAS_CODEC",
13929 #endif
13930 #ifdef SQLITE_HAVE_ISNAN
13931 "HAVE_ISNAN",
13932 #endif
13933 #ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
13934 "HOMEGROWN_RECURSIVE_MUTEX",
13935 #endif
13936 #ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS
13937 "IGNORE_AFP_LOCK_ERRORS",
13938 #endif
13939 #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
13940 "IGNORE_FLOCK_LOCK_ERRORS",
13941 #endif
13942 #ifdef SQLITE_INT64_TYPE
13943 "INT64_TYPE",
13944 #endif
13945 #ifdef SQLITE_LOCK_TRACE
13946 "LOCK_TRACE",
13947 #endif
13948 #if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc)
13949 "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
13950 #endif
13951 #ifdef SQLITE_MAX_SCHEMA_RETRY
13952 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
13953 #endif
13954 #ifdef SQLITE_MEMDEBUG
13955 "MEMDEBUG",
13956 #endif
13957 #ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
13958 "MIXED_ENDIAN_64BIT_FLOAT",
13959 #endif
13960 #ifdef SQLITE_NO_SYNC
13961 "NO_SYNC",
13962 #endif
13963 #ifdef SQLITE_OMIT_ALTERTABLE
13964 "OMIT_ALTERTABLE",
13965 #endif
13966 #ifdef SQLITE_OMIT_ANALYZE
13967 "OMIT_ANALYZE",
13968 #endif
13969 #ifdef SQLITE_OMIT_ATTACH
13970 "OMIT_ATTACH",
13971 #endif
13972 #ifdef SQLITE_OMIT_AUTHORIZATION
13973 "OMIT_AUTHORIZATION",
13974 #endif
13975 #ifdef SQLITE_OMIT_AUTOINCREMENT
13976 "OMIT_AUTOINCREMENT",
13977 #endif
13978 #ifdef SQLITE_OMIT_AUTOINIT
13979 "OMIT_AUTOINIT",
13980 #endif
13981 #ifdef SQLITE_OMIT_AUTOMATIC_INDEX
13982 "OMIT_AUTOMATIC_INDEX",
13983 #endif
13984 #ifdef SQLITE_OMIT_AUTORESET
13985 "OMIT_AUTORESET",
13986 #endif
13987 #ifdef SQLITE_OMIT_AUTOVACUUM
13988 "OMIT_AUTOVACUUM",
13989 #endif
13990 #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
13991 "OMIT_BETWEEN_OPTIMIZATION",
13992 #endif
13993 #ifdef SQLITE_OMIT_BLOB_LITERAL
13994 "OMIT_BLOB_LITERAL",
13995 #endif
13996 #ifdef SQLITE_OMIT_BTREECOUNT
13997 "OMIT_BTREECOUNT",
13998 #endif
13999 #ifdef SQLITE_OMIT_BUILTIN_TEST
14000 "OMIT_BUILTIN_TEST",
14001 #endif
14002 #ifdef SQLITE_OMIT_CAST
14003 "OMIT_CAST",
14004 #endif
14005 #ifdef SQLITE_OMIT_CHECK
14006 "OMIT_CHECK",
14007 #endif
14008 #ifdef SQLITE_OMIT_COMPLETE
14009 "OMIT_COMPLETE",
14010 #endif
14011 #ifdef SQLITE_OMIT_COMPOUND_SELECT
14012 "OMIT_COMPOUND_SELECT",
14013 #endif
14014 #ifdef SQLITE_OMIT_CTE
14015 "OMIT_CTE",
14016 #endif
14017 #ifdef SQLITE_OMIT_DATETIME_FUNCS
14018 "OMIT_DATETIME_FUNCS",
14019 #endif
14020 #ifdef SQLITE_OMIT_DECLTYPE
14021 "OMIT_DECLTYPE",
14022 #endif
14023 #ifdef SQLITE_OMIT_DEPRECATED
14024 "OMIT_DEPRECATED",
14025 #endif
14026 #ifdef SQLITE_OMIT_DISKIO
14027 "OMIT_DISKIO",
14028 #endif
14029 #ifdef SQLITE_OMIT_EXPLAIN
14030 "OMIT_EXPLAIN",
14031 #endif
14032 #ifdef SQLITE_OMIT_FLAG_PRAGMAS
14033 "OMIT_FLAG_PRAGMAS",
14034 #endif
14035 #ifdef SQLITE_OMIT_FLOATING_POINT
14036 "OMIT_FLOATING_POINT",
14037 #endif
14038 #ifdef SQLITE_OMIT_FOREIGN_KEY
14039 "OMIT_FOREIGN_KEY",
14040 #endif
14041 #ifdef SQLITE_OMIT_GET_TABLE
14042 "OMIT_GET_TABLE",
14043 #endif
14044 #ifdef SQLITE_OMIT_INCRBLOB
14045 "OMIT_INCRBLOB",
14046 #endif
14047 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
14048 "OMIT_INTEGRITY_CHECK",
14049 #endif
14050 #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
14051 "OMIT_LIKE_OPTIMIZATION",
14052 #endif
14053 #ifdef SQLITE_OMIT_LOAD_EXTENSION
14054 "OMIT_LOAD_EXTENSION",
14055 #endif
14056 #ifdef SQLITE_OMIT_LOCALTIME
14057 "OMIT_LOCALTIME",
14058 #endif
14059 #ifdef SQLITE_OMIT_LOOKASIDE
14060 "OMIT_LOOKASIDE",
14061 #endif
14062 #ifdef SQLITE_OMIT_MEMORYDB
14063 "OMIT_MEMORYDB",
14064 #endif
14065 #ifdef SQLITE_OMIT_OR_OPTIMIZATION
14066 "OMIT_OR_OPTIMIZATION",
14067 #endif
14068 #ifdef SQLITE_OMIT_PAGER_PRAGMAS
14069 "OMIT_PAGER_PRAGMAS",
14070 #endif
14071 #ifdef SQLITE_OMIT_PRAGMA
14072 "OMIT_PRAGMA",
14073 #endif
14074 #ifdef SQLITE_OMIT_PROGRESS_CALLBACK
14075 "OMIT_PROGRESS_CALLBACK",
14076 #endif
14077 #ifdef SQLITE_OMIT_QUICKBALANCE
14078 "OMIT_QUICKBALANCE",
14079 #endif
14080 #ifdef SQLITE_OMIT_REINDEX
14081 "OMIT_REINDEX",
14082 #endif
14083 #ifdef SQLITE_OMIT_SCHEMA_PRAGMAS
14084 "OMIT_SCHEMA_PRAGMAS",
14085 #endif
14086 #ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
14087 "OMIT_SCHEMA_VERSION_PRAGMAS",
14088 #endif
14089 #ifdef SQLITE_OMIT_SHARED_CACHE
14090 "OMIT_SHARED_CACHE",
14091 #endif
14092 #ifdef SQLITE_OMIT_SUBQUERY
14093 "OMIT_SUBQUERY",
14094 #endif
14095 #ifdef SQLITE_OMIT_TCL_VARIABLE
14096 "OMIT_TCL_VARIABLE",
14097 #endif
14098 #ifdef SQLITE_OMIT_TEMPDB
14099 "OMIT_TEMPDB",
14100 #endif
14101 #ifdef SQLITE_OMIT_TRACE
14102 "OMIT_TRACE",
14103 #endif
14104 #ifdef SQLITE_OMIT_TRIGGER
14105 "OMIT_TRIGGER",
14106 #endif
14107 #ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
14108 "OMIT_TRUNCATE_OPTIMIZATION",
14109 #endif
14110 #ifdef SQLITE_OMIT_UTF16
14111 "OMIT_UTF16",
14112 #endif
14113 #ifdef SQLITE_OMIT_VACUUM
14114 "OMIT_VACUUM",
14115 #endif
14116 #ifdef SQLITE_OMIT_VIEW
14117 "OMIT_VIEW",
14118 #endif
14119 #ifdef SQLITE_OMIT_VIRTUALTABLE
14120 "OMIT_VIRTUALTABLE",
14121 #endif
14122 #ifdef SQLITE_OMIT_WAL
14123 "OMIT_WAL",
14124 #endif
14125 #ifdef SQLITE_OMIT_WSD
14126 "OMIT_WSD",
14127 #endif
14128 #ifdef SQLITE_OMIT_XFER_OPT
14129 "OMIT_XFER_OPT",
14130 #endif
14131 #ifdef SQLITE_PERFORMANCE_TRACE
14132 "PERFORMANCE_TRACE",
14133 #endif
14134 #ifdef SQLITE_PROXY_DEBUG
14135 "PROXY_DEBUG",
14136 #endif
14137 #ifdef SQLITE_RTREE_INT_ONLY
14138 "RTREE_INT_ONLY",
14139 #endif
14140 #ifdef SQLITE_SECURE_DELETE
14141 "SECURE_DELETE",
14142 #endif
14143 #ifdef SQLITE_SMALL_STACK
14144 "SMALL_STACK",
14145 #endif
14146 #ifdef SQLITE_SOUNDEX
14147 "SOUNDEX",
14148 #endif
14149 #ifdef SQLITE_SYSTEM_MALLOC
14150 "SYSTEM_MALLOC",
14151 #endif
14152 #ifdef SQLITE_TCL
14153 "TCL",
14154 #endif
14155 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
14156 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
14157 #endif
14158 #ifdef SQLITE_TEST
14159 "TEST",
14160 #endif
14161 #if defined(SQLITE_THREADSAFE)
14162 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
14163 #endif
14164 #ifdef SQLITE_USE_ALLOCA
14165 "USE_ALLOCA",
14166 #endif
14167 #ifdef SQLITE_USER_AUTHENTICATION
14168 "USER_AUTHENTICATION",
14169 #endif
14170 #ifdef SQLITE_WIN32_MALLOC
14171 "WIN32_MALLOC",
14172 #endif
14173 #ifdef SQLITE_ZERO_MALLOC
14174 "ZERO_MALLOC"
14175 #endif
14176 };
14177
14178 /*
@@ -14183,11 +14191,11 @@
14183 ** is not required for a match.
14184 */
14185 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
14186 int i, n;
14187
14188 #ifdef SQLITE_ENABLE_API_ARMOR
14189 if( zOptName==0 ){
14190 (void)SQLITE_MISUSE_BKPT;
14191 return 0;
14192 }
14193 #endif
@@ -15411,12 +15419,13 @@
15411 **
15412 ** If the user has not indicated to use localtime_r() or localtime_s()
15413 ** already, check for an MSVC build environment that provides
15414 ** localtime_s().
15415 */
15416 #if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
15417 defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
 
15418 #define HAVE_LOCALTIME_S 1
15419 #endif
15420
15421 #ifndef SQLITE_OMIT_LOCALTIME
15422 /*
@@ -15432,12 +15441,11 @@
15432 ** library function localtime_r() is used to assist in the calculation of
15433 ** local time.
15434 */
15435 static int osLocaltime(time_t *t, struct tm *pTm){
15436 int rc;
15437 #if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \
15438 && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S)
15439 struct tm *pX;
15440 #if SQLITE_THREADSAFE>0
15441 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
15442 #endif
15443 sqlite3_mutex_enter(mutex);
@@ -15450,11 +15458,11 @@
15450 rc = pX==0;
15451 #else
15452 #ifndef SQLITE_OMIT_BUILTIN_TEST
15453 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
15454 #endif
15455 #if defined(HAVE_LOCALTIME_R) && HAVE_LOCALTIME_R
15456 rc = localtime_r(t, pTm)==0;
15457 #else
15458 rc = localtime_s(pTm, t);
15459 #endif /* HAVE_LOCALTIME_R */
15460 #endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */
@@ -15894,12 +15902,14 @@
15894 DateTime x;
15895 u64 n;
15896 size_t i,j;
15897 char *z;
15898 sqlite3 *db;
15899 const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
15900 char zBuf[100];
 
 
15901 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
15902 db = sqlite3_context_db_handle(context);
15903 for(i=0, n=1; zFmt[i]; i++, n++){
15904 if( zFmt[i]=='%' ){
15905 switch( zFmt[i+1] ){
@@ -16089,11 +16099,11 @@
16089 UNUSED_PARAMETER(argv);
16090
16091 iT = sqlite3StmtCurrentTime(context);
16092 if( iT<=0 ) return;
16093 t = iT/1000 - 10000*(sqlite3_int64)21086676;
16094 #ifdef HAVE_GMTIME_R
16095 pTm = gmtime_r(&t, &sNow);
16096 #else
16097 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
16098 pTm = gmtime(&t);
16099 if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
@@ -16763,13 +16773,13 @@
16763
16764 /*
16765 ** The malloc.h header file is needed for malloc_usable_size() function
16766 ** on some systems (e.g. Linux).
16767 */
16768 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
16769 # define SQLITE_USE_MALLOC_H
16770 # define SQLITE_USE_MALLOC_USABLE_SIZE
16771 /*
16772 ** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
16773 ** use of _msize() is automatic, but can be disabled by compiling with
16774 ** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
16775 ** the malloc.h header file.
@@ -21004,21 +21014,10 @@
21004 ** This file contains code for a set of "printf"-like routines. These
21005 ** routines format strings much like the printf() from the standard C
21006 ** library, though the implementation here has enhancements to support
21007 ** SQLlite.
21008 */
21009
21010 /*
21011 ** If the strchrnul() library function is available, then set
21012 ** HAVE_STRCHRNUL. If that routine is not available, this module
21013 ** will supply its own. The built-in version is slower than
21014 ** the glibc version so the glibc version is definitely preferred.
21015 */
21016 #if !defined(HAVE_STRCHRNUL)
21017 # define HAVE_STRCHRNUL 0
21018 #endif
21019
21020
21021 /*
21022 ** Conversion types fall into various categories as defined by the
21023 ** following enumeration.
21024 */
@@ -22313,10 +22312,12 @@
22313 ** single threaded systems. Nothing in SQLite requires multiple threads.
22314 ** This interface exists so that applications that want to take advantage
22315 ** of multiple cores can do so, while also allowing applications to stay
22316 ** single-threaded if desired.
22317 */
 
 
22318
22319 #if SQLITE_MAX_WORKER_THREADS>0
22320
22321 /********************************* Unix Pthreads ****************************/
22322 #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
@@ -23099,11 +23100,11 @@
23099 ** This file contains functions for allocating memory, comparing
23100 ** strings, and stuff like that.
23101 **
23102 */
23103 /* #include <stdarg.h> */
23104 #ifdef SQLITE_HAVE_ISNAN
23105 # include <math.h>
23106 #endif
23107
23108 /*
23109 ** Routine needed to support the testcase() macro.
@@ -23140,11 +23141,11 @@
23140 ** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
23141 ** Otherwise, we have our own implementation that works on most systems.
23142 */
23143 SQLITE_PRIVATE int sqlite3IsNaN(double x){
23144 int rc; /* The value return */
23145 #if !defined(SQLITE_HAVE_ISNAN)
23146 /*
23147 ** Systems that support the isnan() library function should probably
23148 ** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have
23149 ** found that many systems do not have a working isnan() function so
23150 ** this implementation is provided as an alternative.
@@ -23170,13 +23171,13 @@
23170 # error SQLite will not work correctly with the -ffast-math option of GCC.
23171 #endif
23172 volatile double y = x;
23173 volatile double z = y;
23174 rc = (y!=z);
23175 #else /* if defined(SQLITE_HAVE_ISNAN) */
23176 rc = isnan(x);
23177 #endif /* SQLITE_HAVE_ISNAN */
23178 testcase( rc );
23179 return rc;
23180 }
23181 #endif /* SQLITE_OMIT_FLOATING_POINT */
23182
@@ -28493,13 +28494,13 @@
28493
28494 /*
28495 ** We do not trust systems to provide a working fdatasync(). Some do.
28496 ** Others do no. To be safe, we will stick with the (slightly slower)
28497 ** fsync(). If you know that your system does support fdatasync() correctly,
28498 ** then simply compile with -Dfdatasync=fdatasync
28499 */
28500 #if !defined(fdatasync)
28501 # define fdatasync fsync
28502 #endif
28503
28504 /*
28505 ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
@@ -28824,22 +28825,23 @@
28824 ** at offset (nSize-1), to set the size of the file correctly.
28825 ** This is a similar technique to that used by glibc on systems
28826 ** that do not have a real fallocate() call.
28827 */
28828 int nBlk = buf.st_blksize; /* File-system block size */
 
28829 i64 iWrite; /* Next offset to write to */
28830
28831 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28832 assert( iWrite>=buf.st_size );
28833 assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
28834 assert( ((iWrite+1)%nBlk)==0 );
28835 for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
28836 int nWrite = seekAndWrite(pFile, iWrite, "", 1);
28837 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28838 }
28839 if( nSize%nBlk ){
28840 int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
28841 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28842 }
28843 #endif
28844 }
28845 }
@@ -38849,22 +38851,10 @@
38849 void *pStress; /* Argument to xStress */
38850 sqlite3_pcache *pCache; /* Pluggable cache module */
38851 PgHdr *pPage1; /* Reference to page 1 */
38852 };
38853
38854 /*
38855 ** Some of the assert() macros in this code are too expensive to run
38856 ** even during normal debugging. Use them only rarely on long-running
38857 ** tests. Enable the expensive asserts using the
38858 ** -DSQLITE_ENABLE_EXPENSIVE_ASSERT=1 compile-time option.
38859 */
38860 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
38861 # define expensive_assert(X) assert(X)
38862 #else
38863 # define expensive_assert(X)
38864 #endif
38865
38866 /********************************** Linked List Management ********************/
38867
38868 /* Allowed values for second argument to pcacheManageDirtyList() */
38869 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
38870 #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
@@ -82230,11 +82220,11 @@
82230 Expr *pLeft, /* Left operand */
82231 Expr *pRight, /* Right operand */
82232 const Token *pToken /* Argument token */
82233 ){
82234 Expr *p;
82235 if( op==TK_AND && pLeft && pRight ){
82236 /* Take advantage of short-circuit false optimization for AND */
82237 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
82238 }else{
82239 p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
82240 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
@@ -85784,14 +85774,15 @@
85784 ** NEVER() will need to be removed. */
85785 if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
85786 int i;
85787 struct SrcCount *p = pWalker->u.pSrcCount;
85788 SrcList *pSrc = p->pSrc;
85789 for(i=0; i<pSrc->nSrc; i++){
 
85790 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
85791 }
85792 if( i<pSrc->nSrc ){
85793 p->nThis++;
85794 }else{
85795 p->nOther++;
85796 }
85797 }
@@ -105271,24 +105262,29 @@
105271 u8 sortFlags; /* Zero or more SORTFLAG_* bits */
105272 };
105273 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
105274
105275 /*
105276 ** Delete all the content of a Select structure but do not deallocate
105277 ** the select structure itself.
105278 */
105279 static void clearSelect(sqlite3 *db, Select *p){
105280 sqlite3ExprListDelete(db, p->pEList);
105281 sqlite3SrcListDelete(db, p->pSrc);
105282 sqlite3ExprDelete(db, p->pWhere);
105283 sqlite3ExprListDelete(db, p->pGroupBy);
105284 sqlite3ExprDelete(db, p->pHaving);
105285 sqlite3ExprListDelete(db, p->pOrderBy);
105286 sqlite3SelectDelete(db, p->pPrior);
105287 sqlite3ExprDelete(db, p->pLimit);
105288 sqlite3ExprDelete(db, p->pOffset);
105289 sqlite3WithDelete(db, p->pWith);
 
 
 
 
 
105290 }
105291
105292 /*
105293 ** Initialize a SelectDest structure.
105294 */
@@ -105343,12 +105339,11 @@
105343 pNew->pOffset = pOffset;
105344 assert( pOffset==0 || pLimit!=0 );
105345 pNew->addrOpenEphm[0] = -1;
105346 pNew->addrOpenEphm[1] = -1;
105347 if( db->mallocFailed ) {
105348 clearSelect(db, pNew);
105349 if( pNew!=&standin ) sqlite3DbFree(db, pNew);
105350 pNew = 0;
105351 }else{
105352 assert( pNew->pSrc!=0 || pParse->nErr>0 );
105353 }
105354 assert( pNew!=&standin );
@@ -105369,14 +105364,11 @@
105369
105370 /*
105371 ** Delete the given Select structure and all of its substructures.
105372 */
105373 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
105374 if( p ){
105375 clearSelect(db, p);
105376 sqlite3DbFree(db, p);
105377 }
105378 }
105379
105380 /*
105381 ** Return a pointer to the right-most SELECT statement in a compound.
105382 */
@@ -107288,10 +107280,70 @@
107288 Parse *pParse, /* Parsing context */
107289 Select *p, /* The right-most of SELECTs to be coded */
107290 SelectDest *pDest /* What to do with query results */
107291 );
107292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107293
107294 /*
107295 ** This routine is called to process a compound query form from
107296 ** two or more separate queries using UNION, UNION ALL, EXCEPT, or
107297 ** INTERSECT
@@ -107368,22 +107420,24 @@
107368 assert( p->pEList );
107369 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr);
107370 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
107371 dest.eDest = SRT_Table;
107372 }
 
 
 
 
 
 
 
107373
107374 /* Make sure all SELECTs in the statement have the same number of elements
107375 ** in their result sets.
107376 */
107377 assert( p->pEList && pPrior->pEList );
107378 if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
107379 if( p->selFlags & SF_Values ){
107380 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107381 }else{
107382 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107383 " do not have the same number of result columns", selectOpName(p->op));
107384 }
107385 rc = 1;
107386 goto multi_select_end;
107387 }
107388
107389 #ifndef SQLITE_OMIT_CTE
@@ -109265,11 +109319,13 @@
109265 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
109266 return WRC_Prune;
109267 }
109268 pTabList = p->pSrc;
109269 pEList = p->pEList;
109270 sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
 
 
109271
109272 /* Make sure cursor numbers have been assigned to all entries in
109273 ** the FROM clause of the SELECT statement.
109274 */
109275 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -109556,11 +109612,13 @@
109556 if( pParse->hasCompound ){
109557 w.xSelectCallback = convertCompoundSelectToSubquery;
109558 sqlite3WalkSelect(&w, pSelect);
109559 }
109560 w.xSelectCallback = selectExpander;
109561 w.xSelectCallback2 = selectPopWith;
 
 
109562 sqlite3WalkSelect(&w, pSelect);
109563 }
109564
109565
109566 #ifndef SQLITE_OMIT_SUBQUERY
@@ -123884,17 +123942,23 @@
123884 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
123885 if( p ){
123886 int cnt = 0, mxSelect;
123887 p->pWith = yymsp[-1].minor.yy59;
123888 if( p->pPrior ){
 
123889 pNext = 0;
123890 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123891 pLoop->pNext = pNext;
123892 pLoop->selFlags |= SF_Compound;
 
123893 }
123894 mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
123895 if( mxSelect && cnt>mxSelect ){
 
 
 
 
123896 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123897 }
123898 }
123899 }else{
123900 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
@@ -127600,11 +127664,11 @@
127600 */
127601 static int sqliteDefaultBusyCallback(
127602 void *ptr, /* Database connection */
127603 int count /* Number of times table has been busy */
127604 ){
127605 #if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP)
127606 static const u8 delays[] =
127607 { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
127608 static const u8 totals[] =
127609 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
127610 # define NDELAY ArraySize(delays)
127611
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.8"
235 #define SQLITE_VERSION_NUMBER 3008008
236 #define SQLITE_SOURCE_ID "2015-01-10 18:22:06 46f3aba2692d74c29ab5c1f24a6daac600fd6af8"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -7613,10 +7613,14 @@
7613 **
7614 ** The following constants can be used for the T parameter to the
7615 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7616 ** different metric for sqlite3_stmt_scanstatus() to return.
7617 **
7618 ** When the value returned to V is a string, space to hold that string is
7619 ** managed by the prepared statement S and will be automatically freed when
7620 ** S is finalized.
7621 **
7622 ** <dl>
7623 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7624 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7625 ** set to the total number of times that the X-th loop has run.</dd>
7626 **
@@ -7658,11 +7662,18 @@
7662 #define SQLITE_SCANSTAT_SELECTID 5
7663
7664 /*
7665 ** CAPI3REF: Prepared Statement Scan Status
7666 **
7667 ** This interface returns information about the predicted and measured
7668 ** performance for pStmt. Advanced applications can use this
7669 ** interface to compare the predicted and the measured performance and
7670 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7671 **
7672 ** Since this interface is expected to be rarely used, it is only
7673 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7674 ** compile-time option.
7675 **
7676 ** The "iScanStatusOp" parameter determines which status information to return.
7677 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7678 ** of this interface is undefined.
7679 ** ^The requested measurement is written into a variable pointed to by
@@ -7676,13 +7687,10 @@
7687 ** ^Statistics might not be available for all loops in all statements. ^In cases
7688 ** where there exist loops with no available statistics, this function behaves
7689 ** as if the loop did not exist - it returns non-zero and leave the variable
7690 ** that pOut points to unchanged.
7691 **
 
 
 
7692 ** See also: [sqlite3_stmt_scanstatus_reset()]
7693 */
7694 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7695 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7696 int idx, /* Index of loop to report on */
@@ -12054,11 +12062,11 @@
12062 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12063 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12064 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12065 #define SF_Compound 0x0040 /* Part of a compound query */
12066 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12067 #define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12068 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12069 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12070 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12071 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12072
@@ -12682,11 +12690,11 @@
12690 ** FTS4 is really an extension for FTS3. It is enabled using the
12691 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
12692 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
12693 */
12694 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12695 # define SQLITE_ENABLE_FTS3 1
12696 #endif
12697
12698 /*
12699 ** The ctype.h header is needed for non-ASCII systems. It is also
12700 ** needed by FTS3 when FTS3 is included in the amalgamation.
@@ -13824,355 +13832,355 @@
13832 /* These macros are provided to "stringify" the value of the define
13833 ** for those options in which the value is meaningful. */
13834 #define CTIMEOPT_VAL_(opt) #opt
13835 #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
13836
13837 #if SQLITE_32BIT_ROWID
13838 "32BIT_ROWID",
13839 #endif
13840 #if SQLITE_4_BYTE_ALIGNED_MALLOC
13841 "4_BYTE_ALIGNED_MALLOC",
13842 #endif
13843 #if SQLITE_CASE_SENSITIVE_LIKE
13844 "CASE_SENSITIVE_LIKE",
13845 #endif
13846 #if SQLITE_CHECK_PAGES
13847 "CHECK_PAGES",
13848 #endif
13849 #if SQLITE_COVERAGE_TEST
13850 "COVERAGE_TEST",
13851 #endif
13852 #if SQLITE_DEBUG
13853 "DEBUG",
13854 #endif
13855 #if SQLITE_DEFAULT_LOCKING_MODE
13856 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
13857 #endif
13858 #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
13859 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
13860 #endif
13861 #if SQLITE_DISABLE_DIRSYNC
13862 "DISABLE_DIRSYNC",
13863 #endif
13864 #if SQLITE_DISABLE_LFS
13865 "DISABLE_LFS",
13866 #endif
13867 #if SQLITE_ENABLE_API_ARMOR
13868 "ENABLE_API_ARMOR",
13869 #endif
13870 #if SQLITE_ENABLE_ATOMIC_WRITE
13871 "ENABLE_ATOMIC_WRITE",
13872 #endif
13873 #if SQLITE_ENABLE_CEROD
13874 "ENABLE_CEROD",
13875 #endif
13876 #if SQLITE_ENABLE_COLUMN_METADATA
13877 "ENABLE_COLUMN_METADATA",
13878 #endif
13879 #if SQLITE_ENABLE_EXPENSIVE_ASSERT
13880 "ENABLE_EXPENSIVE_ASSERT",
13881 #endif
13882 #if SQLITE_ENABLE_FTS1
13883 "ENABLE_FTS1",
13884 #endif
13885 #if SQLITE_ENABLE_FTS2
13886 "ENABLE_FTS2",
13887 #endif
13888 #if SQLITE_ENABLE_FTS3
13889 "ENABLE_FTS3",
13890 #endif
13891 #if SQLITE_ENABLE_FTS3_PARENTHESIS
13892 "ENABLE_FTS3_PARENTHESIS",
13893 #endif
13894 #if SQLITE_ENABLE_FTS4
13895 "ENABLE_FTS4",
13896 #endif
13897 #if SQLITE_ENABLE_ICU
13898 "ENABLE_ICU",
13899 #endif
13900 #if SQLITE_ENABLE_IOTRACE
13901 "ENABLE_IOTRACE",
13902 #endif
13903 #if SQLITE_ENABLE_LOAD_EXTENSION
13904 "ENABLE_LOAD_EXTENSION",
13905 #endif
13906 #if SQLITE_ENABLE_LOCKING_STYLE
13907 "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
13908 #endif
13909 #if SQLITE_ENABLE_MEMORY_MANAGEMENT
13910 "ENABLE_MEMORY_MANAGEMENT",
13911 #endif
13912 #if SQLITE_ENABLE_MEMSYS3
13913 "ENABLE_MEMSYS3",
13914 #endif
13915 #if SQLITE_ENABLE_MEMSYS5
13916 "ENABLE_MEMSYS5",
13917 #endif
13918 #if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
13919 "ENABLE_OVERSIZE_CELL_CHECK",
13920 #endif
13921 #if SQLITE_ENABLE_RTREE
13922 "ENABLE_RTREE",
13923 #endif
13924 #if defined(SQLITE_ENABLE_STAT4)
13925 "ENABLE_STAT4",
13926 #elif defined(SQLITE_ENABLE_STAT3)
13927 "ENABLE_STAT3",
13928 #endif
13929 #if SQLITE_ENABLE_UNLOCK_NOTIFY
13930 "ENABLE_UNLOCK_NOTIFY",
13931 #endif
13932 #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
13933 "ENABLE_UPDATE_DELETE_LIMIT",
13934 #endif
13935 #if SQLITE_HAS_CODEC
13936 "HAS_CODEC",
13937 #endif
13938 #if HAVE_ISNAN || SQLITE_HAVE_ISNAN
13939 "HAVE_ISNAN",
13940 #endif
13941 #if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
13942 "HOMEGROWN_RECURSIVE_MUTEX",
13943 #endif
13944 #if SQLITE_IGNORE_AFP_LOCK_ERRORS
13945 "IGNORE_AFP_LOCK_ERRORS",
13946 #endif
13947 #if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
13948 "IGNORE_FLOCK_LOCK_ERRORS",
13949 #endif
13950 #ifdef SQLITE_INT64_TYPE
13951 "INT64_TYPE",
13952 #endif
13953 #if SQLITE_LOCK_TRACE
13954 "LOCK_TRACE",
13955 #endif
13956 #if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc)
13957 "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
13958 #endif
13959 #ifdef SQLITE_MAX_SCHEMA_RETRY
13960 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
13961 #endif
13962 #if SQLITE_MEMDEBUG
13963 "MEMDEBUG",
13964 #endif
13965 #if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
13966 "MIXED_ENDIAN_64BIT_FLOAT",
13967 #endif
13968 #if SQLITE_NO_SYNC
13969 "NO_SYNC",
13970 #endif
13971 #if SQLITE_OMIT_ALTERTABLE
13972 "OMIT_ALTERTABLE",
13973 #endif
13974 #if SQLITE_OMIT_ANALYZE
13975 "OMIT_ANALYZE",
13976 #endif
13977 #if SQLITE_OMIT_ATTACH
13978 "OMIT_ATTACH",
13979 #endif
13980 #if SQLITE_OMIT_AUTHORIZATION
13981 "OMIT_AUTHORIZATION",
13982 #endif
13983 #if SQLITE_OMIT_AUTOINCREMENT
13984 "OMIT_AUTOINCREMENT",
13985 #endif
13986 #if SQLITE_OMIT_AUTOINIT
13987 "OMIT_AUTOINIT",
13988 #endif
13989 #if SQLITE_OMIT_AUTOMATIC_INDEX
13990 "OMIT_AUTOMATIC_INDEX",
13991 #endif
13992 #if SQLITE_OMIT_AUTORESET
13993 "OMIT_AUTORESET",
13994 #endif
13995 #if SQLITE_OMIT_AUTOVACUUM
13996 "OMIT_AUTOVACUUM",
13997 #endif
13998 #if SQLITE_OMIT_BETWEEN_OPTIMIZATION
13999 "OMIT_BETWEEN_OPTIMIZATION",
14000 #endif
14001 #if SQLITE_OMIT_BLOB_LITERAL
14002 "OMIT_BLOB_LITERAL",
14003 #endif
14004 #if SQLITE_OMIT_BTREECOUNT
14005 "OMIT_BTREECOUNT",
14006 #endif
14007 #if SQLITE_OMIT_BUILTIN_TEST
14008 "OMIT_BUILTIN_TEST",
14009 #endif
14010 #if SQLITE_OMIT_CAST
14011 "OMIT_CAST",
14012 #endif
14013 #if SQLITE_OMIT_CHECK
14014 "OMIT_CHECK",
14015 #endif
14016 #if SQLITE_OMIT_COMPLETE
14017 "OMIT_COMPLETE",
14018 #endif
14019 #if SQLITE_OMIT_COMPOUND_SELECT
14020 "OMIT_COMPOUND_SELECT",
14021 #endif
14022 #if SQLITE_OMIT_CTE
14023 "OMIT_CTE",
14024 #endif
14025 #if SQLITE_OMIT_DATETIME_FUNCS
14026 "OMIT_DATETIME_FUNCS",
14027 #endif
14028 #if SQLITE_OMIT_DECLTYPE
14029 "OMIT_DECLTYPE",
14030 #endif
14031 #if SQLITE_OMIT_DEPRECATED
14032 "OMIT_DEPRECATED",
14033 #endif
14034 #if SQLITE_OMIT_DISKIO
14035 "OMIT_DISKIO",
14036 #endif
14037 #if SQLITE_OMIT_EXPLAIN
14038 "OMIT_EXPLAIN",
14039 #endif
14040 #if SQLITE_OMIT_FLAG_PRAGMAS
14041 "OMIT_FLAG_PRAGMAS",
14042 #endif
14043 #if SQLITE_OMIT_FLOATING_POINT
14044 "OMIT_FLOATING_POINT",
14045 #endif
14046 #if SQLITE_OMIT_FOREIGN_KEY
14047 "OMIT_FOREIGN_KEY",
14048 #endif
14049 #if SQLITE_OMIT_GET_TABLE
14050 "OMIT_GET_TABLE",
14051 #endif
14052 #if SQLITE_OMIT_INCRBLOB
14053 "OMIT_INCRBLOB",
14054 #endif
14055 #if SQLITE_OMIT_INTEGRITY_CHECK
14056 "OMIT_INTEGRITY_CHECK",
14057 #endif
14058 #if SQLITE_OMIT_LIKE_OPTIMIZATION
14059 "OMIT_LIKE_OPTIMIZATION",
14060 #endif
14061 #if SQLITE_OMIT_LOAD_EXTENSION
14062 "OMIT_LOAD_EXTENSION",
14063 #endif
14064 #if SQLITE_OMIT_LOCALTIME
14065 "OMIT_LOCALTIME",
14066 #endif
14067 #if SQLITE_OMIT_LOOKASIDE
14068 "OMIT_LOOKASIDE",
14069 #endif
14070 #if SQLITE_OMIT_MEMORYDB
14071 "OMIT_MEMORYDB",
14072 #endif
14073 #if SQLITE_OMIT_OR_OPTIMIZATION
14074 "OMIT_OR_OPTIMIZATION",
14075 #endif
14076 #if SQLITE_OMIT_PAGER_PRAGMAS
14077 "OMIT_PAGER_PRAGMAS",
14078 #endif
14079 #if SQLITE_OMIT_PRAGMA
14080 "OMIT_PRAGMA",
14081 #endif
14082 #if SQLITE_OMIT_PROGRESS_CALLBACK
14083 "OMIT_PROGRESS_CALLBACK",
14084 #endif
14085 #if SQLITE_OMIT_QUICKBALANCE
14086 "OMIT_QUICKBALANCE",
14087 #endif
14088 #if SQLITE_OMIT_REINDEX
14089 "OMIT_REINDEX",
14090 #endif
14091 #if SQLITE_OMIT_SCHEMA_PRAGMAS
14092 "OMIT_SCHEMA_PRAGMAS",
14093 #endif
14094 #if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
14095 "OMIT_SCHEMA_VERSION_PRAGMAS",
14096 #endif
14097 #if SQLITE_OMIT_SHARED_CACHE
14098 "OMIT_SHARED_CACHE",
14099 #endif
14100 #if SQLITE_OMIT_SUBQUERY
14101 "OMIT_SUBQUERY",
14102 #endif
14103 #if SQLITE_OMIT_TCL_VARIABLE
14104 "OMIT_TCL_VARIABLE",
14105 #endif
14106 #if SQLITE_OMIT_TEMPDB
14107 "OMIT_TEMPDB",
14108 #endif
14109 #if SQLITE_OMIT_TRACE
14110 "OMIT_TRACE",
14111 #endif
14112 #if SQLITE_OMIT_TRIGGER
14113 "OMIT_TRIGGER",
14114 #endif
14115 #if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
14116 "OMIT_TRUNCATE_OPTIMIZATION",
14117 #endif
14118 #if SQLITE_OMIT_UTF16
14119 "OMIT_UTF16",
14120 #endif
14121 #if SQLITE_OMIT_VACUUM
14122 "OMIT_VACUUM",
14123 #endif
14124 #if SQLITE_OMIT_VIEW
14125 "OMIT_VIEW",
14126 #endif
14127 #if SQLITE_OMIT_VIRTUALTABLE
14128 "OMIT_VIRTUALTABLE",
14129 #endif
14130 #if SQLITE_OMIT_WAL
14131 "OMIT_WAL",
14132 #endif
14133 #if SQLITE_OMIT_WSD
14134 "OMIT_WSD",
14135 #endif
14136 #if SQLITE_OMIT_XFER_OPT
14137 "OMIT_XFER_OPT",
14138 #endif
14139 #if SQLITE_PERFORMANCE_TRACE
14140 "PERFORMANCE_TRACE",
14141 #endif
14142 #if SQLITE_PROXY_DEBUG
14143 "PROXY_DEBUG",
14144 #endif
14145 #if SQLITE_RTREE_INT_ONLY
14146 "RTREE_INT_ONLY",
14147 #endif
14148 #if SQLITE_SECURE_DELETE
14149 "SECURE_DELETE",
14150 #endif
14151 #if SQLITE_SMALL_STACK
14152 "SMALL_STACK",
14153 #endif
14154 #if SQLITE_SOUNDEX
14155 "SOUNDEX",
14156 #endif
14157 #if SQLITE_SYSTEM_MALLOC
14158 "SYSTEM_MALLOC",
14159 #endif
14160 #if SQLITE_TCL
14161 "TCL",
14162 #endif
14163 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
14164 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
14165 #endif
14166 #if SQLITE_TEST
14167 "TEST",
14168 #endif
14169 #if defined(SQLITE_THREADSAFE)
14170 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
14171 #endif
14172 #if SQLITE_USE_ALLOCA
14173 "USE_ALLOCA",
14174 #endif
14175 #if SQLITE_USER_AUTHENTICATION
14176 "USER_AUTHENTICATION",
14177 #endif
14178 #if SQLITE_WIN32_MALLOC
14179 "WIN32_MALLOC",
14180 #endif
14181 #if SQLITE_ZERO_MALLOC
14182 "ZERO_MALLOC"
14183 #endif
14184 };
14185
14186 /*
@@ -14183,11 +14191,11 @@
14191 ** is not required for a match.
14192 */
14193 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
14194 int i, n;
14195
14196 #if SQLITE_ENABLE_API_ARMOR
14197 if( zOptName==0 ){
14198 (void)SQLITE_MISUSE_BKPT;
14199 return 0;
14200 }
14201 #endif
@@ -15411,12 +15419,13 @@
15419 **
15420 ** If the user has not indicated to use localtime_r() or localtime_s()
15421 ** already, check for an MSVC build environment that provides
15422 ** localtime_s().
15423 */
15424 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S \
15425 && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
15426 #undef HAVE_LOCALTIME_S
15427 #define HAVE_LOCALTIME_S 1
15428 #endif
15429
15430 #ifndef SQLITE_OMIT_LOCALTIME
15431 /*
@@ -15432,12 +15441,11 @@
15441 ** library function localtime_r() is used to assist in the calculation of
15442 ** local time.
15443 */
15444 static int osLocaltime(time_t *t, struct tm *pTm){
15445 int rc;
15446 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
 
15447 struct tm *pX;
15448 #if SQLITE_THREADSAFE>0
15449 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
15450 #endif
15451 sqlite3_mutex_enter(mutex);
@@ -15450,11 +15458,11 @@
15458 rc = pX==0;
15459 #else
15460 #ifndef SQLITE_OMIT_BUILTIN_TEST
15461 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
15462 #endif
15463 #if HAVE_LOCALTIME_R
15464 rc = localtime_r(t, pTm)==0;
15465 #else
15466 rc = localtime_s(pTm, t);
15467 #endif /* HAVE_LOCALTIME_R */
15468 #endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */
@@ -15894,12 +15902,14 @@
15902 DateTime x;
15903 u64 n;
15904 size_t i,j;
15905 char *z;
15906 sqlite3 *db;
15907 const char *zFmt;
15908 char zBuf[100];
15909 if( argc==0 ) return;
15910 zFmt = (const char*)sqlite3_value_text(argv[0]);
15911 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
15912 db = sqlite3_context_db_handle(context);
15913 for(i=0, n=1; zFmt[i]; i++, n++){
15914 if( zFmt[i]=='%' ){
15915 switch( zFmt[i+1] ){
@@ -16089,11 +16099,11 @@
16099 UNUSED_PARAMETER(argv);
16100
16101 iT = sqlite3StmtCurrentTime(context);
16102 if( iT<=0 ) return;
16103 t = iT/1000 - 10000*(sqlite3_int64)21086676;
16104 #if HAVE_GMTIME_R
16105 pTm = gmtime_r(&t, &sNow);
16106 #else
16107 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
16108 pTm = gmtime(&t);
16109 if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
@@ -16763,13 +16773,13 @@
16773
16774 /*
16775 ** The malloc.h header file is needed for malloc_usable_size() function
16776 ** on some systems (e.g. Linux).
16777 */
16778 #if HAVE_MALLOC_H && HAVE_MALLOC_USABLE_SIZE
16779 # define SQLITE_USE_MALLOC_H 1
16780 # define SQLITE_USE_MALLOC_USABLE_SIZE 1
16781 /*
16782 ** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
16783 ** use of _msize() is automatic, but can be disabled by compiling with
16784 ** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
16785 ** the malloc.h header file.
@@ -21004,21 +21014,10 @@
21014 ** This file contains code for a set of "printf"-like routines. These
21015 ** routines format strings much like the printf() from the standard C
21016 ** library, though the implementation here has enhancements to support
21017 ** SQLlite.
21018 */
 
 
 
 
 
 
 
 
 
 
 
21019
21020 /*
21021 ** Conversion types fall into various categories as defined by the
21022 ** following enumeration.
21023 */
@@ -22313,10 +22312,12 @@
22312 ** single threaded systems. Nothing in SQLite requires multiple threads.
22313 ** This interface exists so that applications that want to take advantage
22314 ** of multiple cores can do so, while also allowing applications to stay
22315 ** single-threaded if desired.
22316 */
22317 #if SQLITE_OS_WIN
22318 #endif
22319
22320 #if SQLITE_MAX_WORKER_THREADS>0
22321
22322 /********************************* Unix Pthreads ****************************/
22323 #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
@@ -23099,11 +23100,11 @@
23100 ** This file contains functions for allocating memory, comparing
23101 ** strings, and stuff like that.
23102 **
23103 */
23104 /* #include <stdarg.h> */
23105 #if HAVE_ISNAN || SQLITE_HAVE_ISNAN
23106 # include <math.h>
23107 #endif
23108
23109 /*
23110 ** Routine needed to support the testcase() macro.
@@ -23140,11 +23141,11 @@
23141 ** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
23142 ** Otherwise, we have our own implementation that works on most systems.
23143 */
23144 SQLITE_PRIVATE int sqlite3IsNaN(double x){
23145 int rc; /* The value return */
23146 #if !SQLITE_HAVE_ISNAN && !HAVE_ISNAN
23147 /*
23148 ** Systems that support the isnan() library function should probably
23149 ** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have
23150 ** found that many systems do not have a working isnan() function so
23151 ** this implementation is provided as an alternative.
@@ -23170,13 +23171,13 @@
23171 # error SQLite will not work correctly with the -ffast-math option of GCC.
23172 #endif
23173 volatile double y = x;
23174 volatile double z = y;
23175 rc = (y!=z);
23176 #else /* if HAVE_ISNAN */
23177 rc = isnan(x);
23178 #endif /* HAVE_ISNAN */
23179 testcase( rc );
23180 return rc;
23181 }
23182 #endif /* SQLITE_OMIT_FLOATING_POINT */
23183
@@ -28493,13 +28494,13 @@
28494
28495 /*
28496 ** We do not trust systems to provide a working fdatasync(). Some do.
28497 ** Others do no. To be safe, we will stick with the (slightly slower)
28498 ** fsync(). If you know that your system does support fdatasync() correctly,
28499 ** then simply compile with -Dfdatasync=fdatasync or -DHAVE_FDATASYNC
28500 */
28501 #if !defined(fdatasync) && !HAVE_FDATASYNC
28502 # define fdatasync fsync
28503 #endif
28504
28505 /*
28506 ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
@@ -28824,22 +28825,23 @@
28825 ** at offset (nSize-1), to set the size of the file correctly.
28826 ** This is a similar technique to that used by glibc on systems
28827 ** that do not have a real fallocate() call.
28828 */
28829 int nBlk = buf.st_blksize; /* File-system block size */
28830 int nWrite = 0; /* Number of bytes written by seekAndWrite */
28831 i64 iWrite; /* Next offset to write to */
28832
28833 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28834 assert( iWrite>=buf.st_size );
28835 assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
28836 assert( ((iWrite+1)%nBlk)==0 );
28837 for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
28838 nWrite = seekAndWrite(pFile, iWrite, "", 1);
28839 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28840 }
28841 if( nWrite==0 || (nSize%nBlk) ){
28842 nWrite = seekAndWrite(pFile, nSize-1, "", 1);
28843 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28844 }
28845 #endif
28846 }
28847 }
@@ -38849,22 +38851,10 @@
38851 void *pStress; /* Argument to xStress */
38852 sqlite3_pcache *pCache; /* Pluggable cache module */
38853 PgHdr *pPage1; /* Reference to page 1 */
38854 };
38855
 
 
 
 
 
 
 
 
 
 
 
 
38856 /********************************** Linked List Management ********************/
38857
38858 /* Allowed values for second argument to pcacheManageDirtyList() */
38859 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
38860 #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
@@ -82230,11 +82220,11 @@
82220 Expr *pLeft, /* Left operand */
82221 Expr *pRight, /* Right operand */
82222 const Token *pToken /* Argument token */
82223 ){
82224 Expr *p;
82225 if( op==TK_AND && pLeft && pRight && pParse->nErr==0 ){
82226 /* Take advantage of short-circuit false optimization for AND */
82227 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
82228 }else{
82229 p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
82230 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
@@ -85784,14 +85774,15 @@
85774 ** NEVER() will need to be removed. */
85775 if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
85776 int i;
85777 struct SrcCount *p = pWalker->u.pSrcCount;
85778 SrcList *pSrc = p->pSrc;
85779 int nSrc = pSrc ? pSrc->nSrc : 0;
85780 for(i=0; i<nSrc; i++){
85781 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
85782 }
85783 if( i<nSrc ){
85784 p->nThis++;
85785 }else{
85786 p->nOther++;
85787 }
85788 }
@@ -105271,24 +105262,29 @@
105262 u8 sortFlags; /* Zero or more SORTFLAG_* bits */
105263 };
105264 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
105265
105266 /*
105267 ** Delete all the content of a Select structure. Deallocate the structure
105268 ** itself only if bFree is true.
105269 */
105270 static void clearSelect(sqlite3 *db, Select *p, int bFree){
105271 while( p ){
105272 Select *pPrior = p->pPrior;
105273 sqlite3ExprListDelete(db, p->pEList);
105274 sqlite3SrcListDelete(db, p->pSrc);
105275 sqlite3ExprDelete(db, p->pWhere);
105276 sqlite3ExprListDelete(db, p->pGroupBy);
105277 sqlite3ExprDelete(db, p->pHaving);
105278 sqlite3ExprListDelete(db, p->pOrderBy);
105279 sqlite3ExprDelete(db, p->pLimit);
105280 sqlite3ExprDelete(db, p->pOffset);
105281 sqlite3WithDelete(db, p->pWith);
105282 if( bFree ) sqlite3DbFree(db, p);
105283 p = pPrior;
105284 bFree = 1;
105285 }
105286 }
105287
105288 /*
105289 ** Initialize a SelectDest structure.
105290 */
@@ -105343,12 +105339,11 @@
105339 pNew->pOffset = pOffset;
105340 assert( pOffset==0 || pLimit!=0 );
105341 pNew->addrOpenEphm[0] = -1;
105342 pNew->addrOpenEphm[1] = -1;
105343 if( db->mallocFailed ) {
105344 clearSelect(db, pNew, pNew!=&standin);
 
105345 pNew = 0;
105346 }else{
105347 assert( pNew->pSrc!=0 || pParse->nErr>0 );
105348 }
105349 assert( pNew!=&standin );
@@ -105369,14 +105364,11 @@
105364
105365 /*
105366 ** Delete the given Select structure and all of its substructures.
105367 */
105368 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
105369 clearSelect(db, p, 1);
 
 
 
105370 }
105371
105372 /*
105373 ** Return a pointer to the right-most SELECT statement in a compound.
105374 */
@@ -107288,10 +107280,70 @@
107280 Parse *pParse, /* Parsing context */
107281 Select *p, /* The right-most of SELECTs to be coded */
107282 SelectDest *pDest /* What to do with query results */
107283 );
107284
107285 /*
107286 ** Error message for when two or more terms of a compound select have different
107287 ** size result sets.
107288 */
107289 static void selectWrongNumTermsError(Parse *pParse, Select *p){
107290 if( p->selFlags & SF_Values ){
107291 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107292 }else{
107293 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107294 " do not have the same number of result columns", selectOpName(p->op));
107295 }
107296 }
107297
107298 /*
107299 ** Handle the special case of a compound-select that originates from a
107300 ** VALUES clause. By handling this as a special case, we avoid deep
107301 ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
107302 ** on a VALUES clause.
107303 **
107304 ** Because the Select object originates from a VALUES clause:
107305 ** (1) It has no LIMIT or OFFSET
107306 ** (2) All terms are UNION ALL
107307 ** (3) There is no ORDER BY clause
107308 */
107309 static int multiSelectValues(
107310 Parse *pParse, /* Parsing context */
107311 Select *p, /* The right-most of SELECTs to be coded */
107312 SelectDest *pDest /* What to do with query results */
107313 ){
107314 Select *pPrior;
107315 int nExpr = p->pEList->nExpr;
107316 int nRow = 1;
107317 int rc = 0;
107318 assert( p->pNext==0 );
107319 assert( p->selFlags & SF_AllValues );
107320 do{
107321 assert( p->selFlags & SF_Values );
107322 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
107323 assert( p->pLimit==0 );
107324 assert( p->pOffset==0 );
107325 if( p->pEList->nExpr!=nExpr ){
107326 selectWrongNumTermsError(pParse, p);
107327 return 1;
107328 }
107329 if( p->pPrior==0 ) break;
107330 assert( p->pPrior->pNext==p );
107331 p = p->pPrior;
107332 nRow++;
107333 }while(1);
107334 while( p ){
107335 pPrior = p->pPrior;
107336 p->pPrior = 0;
107337 rc = sqlite3Select(pParse, p, pDest);
107338 p->pPrior = pPrior;
107339 if( rc ) break;
107340 p->nSelectRow = nRow;
107341 p = p->pNext;
107342 }
107343 return rc;
107344 }
107345
107346 /*
107347 ** This routine is called to process a compound query form from
107348 ** two or more separate queries using UNION, UNION ALL, EXCEPT, or
107349 ** INTERSECT
@@ -107368,22 +107420,24 @@
107420 assert( p->pEList );
107421 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr);
107422 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
107423 dest.eDest = SRT_Table;
107424 }
107425
107426 /* Special handling for a compound-select that originates as a VALUES clause.
107427 */
107428 if( p->selFlags & SF_AllValues ){
107429 rc = multiSelectValues(pParse, p, &dest);
107430 goto multi_select_end;
107431 }
107432
107433 /* Make sure all SELECTs in the statement have the same number of elements
107434 ** in their result sets.
107435 */
107436 assert( p->pEList && pPrior->pEList );
107437 if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
107438 selectWrongNumTermsError(pParse, p);
 
 
 
 
 
107439 rc = 1;
107440 goto multi_select_end;
107441 }
107442
107443 #ifndef SQLITE_OMIT_CTE
@@ -109265,11 +109319,13 @@
109319 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
109320 return WRC_Prune;
109321 }
109322 pTabList = p->pSrc;
109323 pEList = p->pEList;
109324 if( pWalker->xSelectCallback2==selectPopWith ){
109325 sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
109326 }
109327
109328 /* Make sure cursor numbers have been assigned to all entries in
109329 ** the FROM clause of the SELECT statement.
109330 */
109331 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -109556,11 +109612,13 @@
109612 if( pParse->hasCompound ){
109613 w.xSelectCallback = convertCompoundSelectToSubquery;
109614 sqlite3WalkSelect(&w, pSelect);
109615 }
109616 w.xSelectCallback = selectExpander;
109617 if( (pSelect->selFlags & SF_AllValues)==0 ){
109618 w.xSelectCallback2 = selectPopWith;
109619 }
109620 sqlite3WalkSelect(&w, pSelect);
109621 }
109622
109623
109624 #ifndef SQLITE_OMIT_SUBQUERY
@@ -123884,17 +123942,23 @@
123942 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
123943 if( p ){
123944 int cnt = 0, mxSelect;
123945 p->pWith = yymsp[-1].minor.yy59;
123946 if( p->pPrior ){
123947 u16 allValues = SF_Values;
123948 pNext = 0;
123949 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123950 pLoop->pNext = pNext;
123951 pLoop->selFlags |= SF_Compound;
123952 allValues &= pLoop->selFlags;
123953 }
123954 if( allValues ){
123955 p->selFlags |= SF_AllValues;
123956 }else if(
123957 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
123958 && cnt>mxSelect
123959 ){
123960 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123961 }
123962 }
123963 }else{
123964 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
@@ -127600,11 +127664,11 @@
127664 */
127665 static int sqliteDefaultBusyCallback(
127666 void *ptr, /* Database connection */
127667 int count /* Number of times table has been busy */
127668 ){
127669 #if SQLITE_OS_WIN || HAVE_USLEEP
127670 static const u8 delays[] =
127671 { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
127672 static const u8 totals[] =
127673 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
127674 # define NDELAY ArraySize(delays)
127675
+13 -5
--- 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.8"
111111
#define SQLITE_VERSION_NUMBER 3008008
112
-#define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
112
+#define SQLITE_SOURCE_ID "2015-01-10 18:22:06 46f3aba2692d74c29ab5c1f24a6daac600fd6af8"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -7489,10 +7489,14 @@
74897489
**
74907490
** The following constants can be used for the T parameter to the
74917491
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
74927492
** different metric for sqlite3_stmt_scanstatus() to return.
74937493
**
7494
+** When the value returned to V is a string, space to hold that string is
7495
+** managed by the prepared statement S and will be automatically freed when
7496
+** S is finalized.
7497
+**
74947498
** <dl>
74957499
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
74967500
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
74977501
** set to the total number of times that the X-th loop has run.</dd>
74987502
**
@@ -7534,11 +7538,18 @@
75347538
#define SQLITE_SCANSTAT_SELECTID 5
75357539
75367540
/*
75377541
** CAPI3REF: Prepared Statement Scan Status
75387542
**
7539
-** Return status data for a single loop within query pStmt.
7543
+** This interface returns information about the predicted and measured
7544
+** performance for pStmt. Advanced applications can use this
7545
+** interface to compare the predicted and the measured performance and
7546
+** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7547
+**
7548
+** Since this interface is expected to be rarely used, it is only
7549
+** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7550
+** compile-time option.
75407551
**
75417552
** The "iScanStatusOp" parameter determines which status information to return.
75427553
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
75437554
** of this interface is undefined.
75447555
** ^The requested measurement is written into a variable pointed to by
@@ -7552,13 +7563,10 @@
75527563
** ^Statistics might not be available for all loops in all statements. ^In cases
75537564
** where there exist loops with no available statistics, this function behaves
75547565
** as if the loop did not exist - it returns non-zero and leave the variable
75557566
** that pOut points to unchanged.
75567567
**
7557
-** This API is only available if the library is built with pre-processor
7558
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7559
-**
75607568
** See also: [sqlite3_stmt_scanstatus_reset()]
75617569
*/
75627570
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
75637571
sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
75647572
int idx, /* Index of loop to report on */
75657573
--- 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.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2015-01-03 18:59:17 23d4c07eb81db5a5c6beb56b5820f0b6501f1fb6"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -7489,10 +7489,14 @@
7489 **
7490 ** The following constants can be used for the T parameter to the
7491 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7492 ** different metric for sqlite3_stmt_scanstatus() to return.
7493 **
 
 
 
 
7494 ** <dl>
7495 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7496 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7497 ** set to the total number of times that the X-th loop has run.</dd>
7498 **
@@ -7534,11 +7538,18 @@
7534 #define SQLITE_SCANSTAT_SELECTID 5
7535
7536 /*
7537 ** CAPI3REF: Prepared Statement Scan Status
7538 **
7539 ** Return status data for a single loop within query pStmt.
 
 
 
 
 
 
 
7540 **
7541 ** The "iScanStatusOp" parameter determines which status information to return.
7542 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7543 ** of this interface is undefined.
7544 ** ^The requested measurement is written into a variable pointed to by
@@ -7552,13 +7563,10 @@
7552 ** ^Statistics might not be available for all loops in all statements. ^In cases
7553 ** where there exist loops with no available statistics, this function behaves
7554 ** as if the loop did not exist - it returns non-zero and leave the variable
7555 ** that pOut points to unchanged.
7556 **
7557 ** This API is only available if the library is built with pre-processor
7558 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7559 **
7560 ** See also: [sqlite3_stmt_scanstatus_reset()]
7561 */
7562 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7563 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7564 int idx, /* Index of loop to report on */
7565
--- 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.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2015-01-10 18:22:06 46f3aba2692d74c29ab5c1f24a6daac600fd6af8"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -7489,10 +7489,14 @@
7489 **
7490 ** The following constants can be used for the T parameter to the
7491 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7492 ** different metric for sqlite3_stmt_scanstatus() to return.
7493 **
7494 ** When the value returned to V is a string, space to hold that string is
7495 ** managed by the prepared statement S and will be automatically freed when
7496 ** S is finalized.
7497 **
7498 ** <dl>
7499 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7500 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7501 ** set to the total number of times that the X-th loop has run.</dd>
7502 **
@@ -7534,11 +7538,18 @@
7538 #define SQLITE_SCANSTAT_SELECTID 5
7539
7540 /*
7541 ** CAPI3REF: Prepared Statement Scan Status
7542 **
7543 ** This interface returns information about the predicted and measured
7544 ** performance for pStmt. Advanced applications can use this
7545 ** interface to compare the predicted and the measured performance and
7546 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7547 **
7548 ** Since this interface is expected to be rarely used, it is only
7549 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7550 ** compile-time option.
7551 **
7552 ** The "iScanStatusOp" parameter determines which status information to return.
7553 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7554 ** of this interface is undefined.
7555 ** ^The requested measurement is written into a variable pointed to by
@@ -7552,13 +7563,10 @@
7563 ** ^Statistics might not be available for all loops in all statements. ^In cases
7564 ** where there exist loops with no available statistics, this function behaves
7565 ** as if the loop did not exist - it returns non-zero and leave the variable
7566 ** that pOut points to unchanged.
7567 **
 
 
 
7568 ** See also: [sqlite3_stmt_scanstatus_reset()]
7569 */
7570 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7571 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7572 int idx, /* Index of loop to report on */
7573

Keyboard Shortcuts

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