Fossil SCM

Update to the latest SQLite 3.8.0 beta in order to test SQLite.

drh 2013-08-19 11:22 trunk
Commit 48445291c06ccda96196eb7cd79fef7068c24c96
3 files changed +69 -77 +133 -81 +1 -1
+69 -77
--- src/shell.c
+++ src/shell.c
@@ -51,11 +51,10 @@
5151
#if defined(HAVE_READLINE) && HAVE_READLINE==1
5252
# include <readline/readline.h>
5353
# include <readline/history.h>
5454
#endif
5555
#if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1)
56
-# define readline(p) local_getline(p,stdin,0)
5756
# define add_history(X)
5857
# define read_history(X)
5958
# define write_history(X)
6059
# define stifle_history(X)
6160
#endif
@@ -335,27 +334,17 @@
335334
** This routine reads a line of text from FILE in, stores
336335
** the text in memory obtained from malloc() and returns a pointer
337336
** to the text. NULL is returned at end of file, or if malloc()
338337
** fails.
339338
**
340
-** The interface is like "readline" but no command-line editing
341
-** is done.
339
+** If zLine is not NULL then it is a malloced buffer returned from
340
+** a previous call to this routine that may be reused.
342341
*/
343
-static char *local_getline(char *zPrompt, FILE *in, int csvFlag){
344
- char *zLine;
345
- int nLine;
346
- int n;
347
- int inQuote = 0;
348
-
349
- if( zPrompt && *zPrompt ){
350
- printf("%s",zPrompt);
351
- fflush(stdout);
352
- }
353
- nLine = 100;
354
- zLine = malloc( nLine );
355
- if( zLine==0 ) return 0;
356
- n = 0;
342
+static char *local_getline(char *zLine, FILE *in){
343
+ int nLine = zLine==0 ? 0 : 100;
344
+ int n = 0;
345
+
357346
while( 1 ){
358347
if( n+100>nLine ){
359348
nLine = nLine*2 + 100;
360349
zLine = realloc(zLine, nLine);
361350
if( zLine==0 ) return 0;
@@ -366,46 +355,52 @@
366355
return 0;
367356
}
368357
zLine[n] = 0;
369358
break;
370359
}
371
- while( zLine[n] ){
372
- if( zLine[n]=='"' ) inQuote = !inQuote;
373
- n++;
374
- }
375
- if( n>0 && zLine[n-1]=='\n' && (!inQuote || !csvFlag) ){
360
+ while( zLine[n] ) n++;
361
+ if( n>0 && zLine[n-1]=='\n' ){
376362
n--;
377363
if( n>0 && zLine[n-1]=='\r' ) n--;
378364
zLine[n] = 0;
379365
break;
380366
}
381367
}
382
- zLine = realloc( zLine, n+1 );
383368
return zLine;
384369
}
385370
386371
/*
387372
** Retrieve a single line of input text.
388373
**
389
-** zPrior is a string of prior text retrieved. If not the empty
390
-** string, then issue a continuation prompt.
374
+** If in==0 then read from standard input and prompt before each line.
375
+** If isContinuation is true, then a continuation prompt is appropriate.
376
+** If isContinuation is zero, then the main prompt should be used.
377
+**
378
+** If zPrior is not NULL then it is a buffer from a prior call to this
379
+** routine that can be reused.
380
+**
381
+** The result is stored in space obtained from malloc() and must either
382
+** be freed by the caller or else passed back into this routine via the
383
+** zPrior argument for reuse.
391384
*/
392
-static char *one_input_line(const char *zPrior, FILE *in){
385
+static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
393386
char *zPrompt;
394387
char *zResult;
395388
if( in!=0 ){
396
- return local_getline(0, in, 0);
397
- }
398
- if( zPrior && zPrior[0] ){
399
- zPrompt = continuePrompt;
389
+ zResult = local_getline(zPrior, in);
400390
}else{
401
- zPrompt = mainPrompt;
402
- }
403
- zResult = readline(zPrompt);
391
+ zPrompt = isContinuation ? continuePrompt : mainPrompt;
404392
#if defined(HAVE_READLINE) && HAVE_READLINE==1
405
- if( zResult && *zResult ) add_history(zResult);
393
+ free(zPrior);
394
+ zResult = readline(zPrompt);
395
+ if( zResult && *zResult ) add_history(zResult);
396
+#else
397
+ printf("%s", zPrompt);
398
+ fflush(stdout);
399
+ zResult = local_getline(zPrior, stdin);
406400
#endif
401
+ }
407402
return zResult;
408403
}
409404
410405
struct previous_mode_data {
411406
int valid; /* Is there legit data in here? */
@@ -1993,10 +1988,11 @@
19931988
char *zFile = azArg[1]; /* Name of file to extra content from */
19941989
sqlite3_stmt *pStmt = NULL; /* A statement */
19951990
int nCol; /* Number of columns in the table */
19961991
int nByte; /* Number of bytes in an SQL string */
19971992
int i, j; /* Loop counters */
1993
+ int needCommit; /* True to COMMIT or ROLLBACK at end */
19981994
int nSep; /* Number of bytes in p->separator[] */
19991995
char *zSql; /* An SQL statement */
20001996
CSVReader sCsv; /* Reader context */
20011997
int (*xCloser)(FILE*); /* Procedure to close th3 connection */
20021998
@@ -2094,10 +2090,12 @@
20942090
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
20952091
if (pStmt) sqlite3_finalize(pStmt);
20962092
xCloser(sCsv.in);
20972093
return 1;
20982094
}
2095
+ needCommit = sqlite3_get_autocommit(db);
2096
+ if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
20992097
do{
21002098
int startLine = sCsv.nLine;
21012099
for(i=0; i<nCol; i++){
21022100
char *z = csv_read_one_field(&sCsv);
21032101
if( z==0 && i==0 ) break;
@@ -2130,11 +2128,11 @@
21302128
}while( sCsv.cTerm!=EOF );
21312129
21322130
xCloser(sCsv.in);
21332131
sqlite3_free(sCsv.z);
21342132
sqlite3_finalize(pStmt);
2135
- sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
2133
+ if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
21362134
}else
21372135
21382136
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
21392137
struct callback_data data;
21402138
char *zErrMsg = 0;
@@ -2779,11 +2777,11 @@
27792777
27802778
/*
27812779
** Return TRUE if a semicolon occurs anywhere in the first N characters
27822780
** of string z[].
27832781
*/
2784
-static int _contains_semicolon(const char *z, int N){
2782
+static int line_contains_semicolon(const char *z, int N){
27852783
int i;
27862784
for(i=0; i<N; i++){ if( z[i]==';' ) return 1; }
27872785
return 0;
27882786
}
27892787
@@ -2814,11 +2812,11 @@
28142812
/*
28152813
** Return TRUE if the line typed in is an SQL command terminator other
28162814
** than a semi-colon. The SQL Server style "go" command is understood
28172815
** as is the Oracle "/".
28182816
*/
2819
-static int _is_command_terminator(const char *zLine){
2817
+static int line_is_command_terminator(const char *zLine){
28202818
while( IsSpace(zLine[0]) ){ zLine++; };
28212819
if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ){
28222820
return 1; /* Oracle */
28232821
}
28242822
if( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o'
@@ -2830,11 +2828,11 @@
28302828
28312829
/*
28322830
** Return true if zSql is a complete SQL statement. Return false if it
28332831
** ends in the middle of a string literal or C-style comment.
28342832
*/
2835
-static int _is_complete(char *zSql, int nSql){
2833
+static int line_is_complete(char *zSql, int nSql){
28362834
int rc;
28372835
if( zSql==0 ) return 1;
28382836
zSql[nSql] = ';';
28392837
zSql[nSql+1] = 0;
28402838
rc = sqlite3_complete(zSql);
@@ -2850,24 +2848,25 @@
28502848
** cause this routine to exit immediately, unless input is interactive.
28512849
**
28522850
** Return the number of errors.
28532851
*/
28542852
static int process_input(struct callback_data *p, FILE *in){
2855
- char *zLine = 0;
2856
- char *zSql = 0;
2857
- int nSql = 0;
2858
- int nSqlPrior = 0;
2859
- char *zErrMsg;
2860
- int rc;
2861
- int errCnt = 0;
2862
- int lineno = 0;
2863
- int startline = 0;
2853
+ char *zLine = 0; /* A single input line */
2854
+ char *zSql = 0; /* Accumulated SQL text */
2855
+ int nLine; /* Length of current line */
2856
+ int nSql = 0; /* Bytes of zSql[] used */
2857
+ int nAlloc = 0; /* Allocated zSql[] space */
2858
+ int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
2859
+ char *zErrMsg; /* Error message returned */
2860
+ int rc; /* Error code */
2861
+ int errCnt = 0; /* Number of errors seen */
2862
+ int lineno = 0; /* Current line number */
2863
+ int startline = 0; /* Line number for start of current input */
28642864
28652865
while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){
28662866
fflush(p->out);
2867
- free(zLine);
2868
- zLine = one_input_line(zSql, in);
2867
+ zLine = one_input_line(in, zLine, nSql>0);
28692868
if( zLine==0 ){
28702869
/* End of input */
28712870
if( stdin_is_interactive ) printf("\n");
28722871
break;
28732872
}
@@ -2874,11 +2873,11 @@
28742873
if( seenInterrupt ){
28752874
if( in!=0 ) break;
28762875
seenInterrupt = 0;
28772876
}
28782877
lineno++;
2879
- if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
2878
+ if( nSql==0 && _all_whitespace(zLine) ) continue;
28802879
if( zLine && zLine[0]=='.' && nSql==0 ){
28812880
if( p->echoOn ) printf("%s\n", zLine);
28822881
rc = do_meta_command(zLine, p);
28832882
if( rc==2 ){ /* exit requested */
28842883
break;
@@ -2885,39 +2884,36 @@
28852884
}else if( rc ){
28862885
errCnt++;
28872886
}
28882887
continue;
28892888
}
2890
- if( _is_command_terminator(zLine) && _is_complete(zSql, nSql) ){
2889
+ if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
28912890
memcpy(zLine,";",2);
2891
+ }
2892
+ nLine = strlen30(zLine);
2893
+ if( nSql+nLine+2>=nAlloc ){
2894
+ nAlloc = nSql+nLine+100;
2895
+ zSql = realloc(zSql, nAlloc);
2896
+ if( zSql==0 ){
2897
+ fprintf(stderr, "Error: out of memory\n");
2898
+ exit(1);
2899
+ }
28922900
}
28932901
nSqlPrior = nSql;
2894
- if( zSql==0 ){
2902
+ if( nSql==0 ){
28952903
int i;
28962904
for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
2897
- if( zLine[i]!=0 ){
2898
- nSql = strlen30(zLine);
2899
- zSql = malloc( nSql+3 );
2900
- if( zSql==0 ){
2901
- fprintf(stderr, "Error: out of memory\n");
2902
- exit(1);
2903
- }
2904
- memcpy(zSql, zLine, nSql+1);
2905
- startline = lineno;
2906
- }
2905
+ assert( nAlloc>0 && zSql!=0 );
2906
+ memcpy(zSql, zLine+i, nLine+1-i);
2907
+ startline = lineno;
2908
+ nSql = nLine-i;
29072909
}else{
2908
- int len = strlen30(zLine);
2909
- zSql = realloc( zSql, nSql + len + 4 );
2910
- if( zSql==0 ){
2911
- fprintf(stderr,"Error: out of memory\n");
2912
- exit(1);
2913
- }
29142910
zSql[nSql++] = '\n';
2915
- memcpy(&zSql[nSql], zLine, len+1);
2916
- nSql += len;
2911
+ memcpy(zSql+nSql, zLine, nLine+1);
2912
+ nSql += nLine;
29172913
}
2918
- if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
2914
+ if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
29192915
&& sqlite3_complete(zSql) ){
29202916
p->cnt = 0;
29212917
open_db(p);
29222918
BEGIN_TIMER;
29232919
rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
@@ -2937,20 +2933,16 @@
29372933
}else{
29382934
fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
29392935
}
29402936
errCnt++;
29412937
}
2942
- free(zSql);
2943
- zSql = 0;
29442938
nSql = 0;
2945
- }else if( zSql && _all_whitespace(zSql) ){
2946
- free(zSql);
2947
- zSql = 0;
2939
+ }else if( nSql && _all_whitespace(zSql) ){
29482940
nSql = 0;
29492941
}
29502942
}
2951
- if( zSql ){
2943
+ if( nSql ){
29522944
if( !_all_whitespace(zSql) ){
29532945
fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
29542946
}
29552947
free(zSql);
29562948
}
29572949
--- src/shell.c
+++ src/shell.c
@@ -51,11 +51,10 @@
51 #if defined(HAVE_READLINE) && HAVE_READLINE==1
52 # include <readline/readline.h>
53 # include <readline/history.h>
54 #endif
55 #if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1)
56 # define readline(p) local_getline(p,stdin,0)
57 # define add_history(X)
58 # define read_history(X)
59 # define write_history(X)
60 # define stifle_history(X)
61 #endif
@@ -335,27 +334,17 @@
335 ** This routine reads a line of text from FILE in, stores
336 ** the text in memory obtained from malloc() and returns a pointer
337 ** to the text. NULL is returned at end of file, or if malloc()
338 ** fails.
339 **
340 ** The interface is like "readline" but no command-line editing
341 ** is done.
342 */
343 static char *local_getline(char *zPrompt, FILE *in, int csvFlag){
344 char *zLine;
345 int nLine;
346 int n;
347 int inQuote = 0;
348
349 if( zPrompt && *zPrompt ){
350 printf("%s",zPrompt);
351 fflush(stdout);
352 }
353 nLine = 100;
354 zLine = malloc( nLine );
355 if( zLine==0 ) return 0;
356 n = 0;
357 while( 1 ){
358 if( n+100>nLine ){
359 nLine = nLine*2 + 100;
360 zLine = realloc(zLine, nLine);
361 if( zLine==0 ) return 0;
@@ -366,46 +355,52 @@
366 return 0;
367 }
368 zLine[n] = 0;
369 break;
370 }
371 while( zLine[n] ){
372 if( zLine[n]=='"' ) inQuote = !inQuote;
373 n++;
374 }
375 if( n>0 && zLine[n-1]=='\n' && (!inQuote || !csvFlag) ){
376 n--;
377 if( n>0 && zLine[n-1]=='\r' ) n--;
378 zLine[n] = 0;
379 break;
380 }
381 }
382 zLine = realloc( zLine, n+1 );
383 return zLine;
384 }
385
386 /*
387 ** Retrieve a single line of input text.
388 **
389 ** zPrior is a string of prior text retrieved. If not the empty
390 ** string, then issue a continuation prompt.
 
 
 
 
 
 
 
 
391 */
392 static char *one_input_line(const char *zPrior, FILE *in){
393 char *zPrompt;
394 char *zResult;
395 if( in!=0 ){
396 return local_getline(0, in, 0);
397 }
398 if( zPrior && zPrior[0] ){
399 zPrompt = continuePrompt;
400 }else{
401 zPrompt = mainPrompt;
402 }
403 zResult = readline(zPrompt);
404 #if defined(HAVE_READLINE) && HAVE_READLINE==1
405 if( zResult && *zResult ) add_history(zResult);
 
 
 
 
 
 
406 #endif
 
407 return zResult;
408 }
409
410 struct previous_mode_data {
411 int valid; /* Is there legit data in here? */
@@ -1993,10 +1988,11 @@
1993 char *zFile = azArg[1]; /* Name of file to extra content from */
1994 sqlite3_stmt *pStmt = NULL; /* A statement */
1995 int nCol; /* Number of columns in the table */
1996 int nByte; /* Number of bytes in an SQL string */
1997 int i, j; /* Loop counters */
 
1998 int nSep; /* Number of bytes in p->separator[] */
1999 char *zSql; /* An SQL statement */
2000 CSVReader sCsv; /* Reader context */
2001 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2002
@@ -2094,10 +2090,12 @@
2094 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2095 if (pStmt) sqlite3_finalize(pStmt);
2096 xCloser(sCsv.in);
2097 return 1;
2098 }
 
 
2099 do{
2100 int startLine = sCsv.nLine;
2101 for(i=0; i<nCol; i++){
2102 char *z = csv_read_one_field(&sCsv);
2103 if( z==0 && i==0 ) break;
@@ -2130,11 +2128,11 @@
2130 }while( sCsv.cTerm!=EOF );
2131
2132 xCloser(sCsv.in);
2133 sqlite3_free(sCsv.z);
2134 sqlite3_finalize(pStmt);
2135 sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
2136 }else
2137
2138 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2139 struct callback_data data;
2140 char *zErrMsg = 0;
@@ -2779,11 +2777,11 @@
2779
2780 /*
2781 ** Return TRUE if a semicolon occurs anywhere in the first N characters
2782 ** of string z[].
2783 */
2784 static int _contains_semicolon(const char *z, int N){
2785 int i;
2786 for(i=0; i<N; i++){ if( z[i]==';' ) return 1; }
2787 return 0;
2788 }
2789
@@ -2814,11 +2812,11 @@
2814 /*
2815 ** Return TRUE if the line typed in is an SQL command terminator other
2816 ** than a semi-colon. The SQL Server style "go" command is understood
2817 ** as is the Oracle "/".
2818 */
2819 static int _is_command_terminator(const char *zLine){
2820 while( IsSpace(zLine[0]) ){ zLine++; };
2821 if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ){
2822 return 1; /* Oracle */
2823 }
2824 if( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o'
@@ -2830,11 +2828,11 @@
2830
2831 /*
2832 ** Return true if zSql is a complete SQL statement. Return false if it
2833 ** ends in the middle of a string literal or C-style comment.
2834 */
2835 static int _is_complete(char *zSql, int nSql){
2836 int rc;
2837 if( zSql==0 ) return 1;
2838 zSql[nSql] = ';';
2839 zSql[nSql+1] = 0;
2840 rc = sqlite3_complete(zSql);
@@ -2850,24 +2848,25 @@
2850 ** cause this routine to exit immediately, unless input is interactive.
2851 **
2852 ** Return the number of errors.
2853 */
2854 static int process_input(struct callback_data *p, FILE *in){
2855 char *zLine = 0;
2856 char *zSql = 0;
2857 int nSql = 0;
2858 int nSqlPrior = 0;
2859 char *zErrMsg;
2860 int rc;
2861 int errCnt = 0;
2862 int lineno = 0;
2863 int startline = 0;
 
 
2864
2865 while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){
2866 fflush(p->out);
2867 free(zLine);
2868 zLine = one_input_line(zSql, in);
2869 if( zLine==0 ){
2870 /* End of input */
2871 if( stdin_is_interactive ) printf("\n");
2872 break;
2873 }
@@ -2874,11 +2873,11 @@
2874 if( seenInterrupt ){
2875 if( in!=0 ) break;
2876 seenInterrupt = 0;
2877 }
2878 lineno++;
2879 if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
2880 if( zLine && zLine[0]=='.' && nSql==0 ){
2881 if( p->echoOn ) printf("%s\n", zLine);
2882 rc = do_meta_command(zLine, p);
2883 if( rc==2 ){ /* exit requested */
2884 break;
@@ -2885,39 +2884,36 @@
2885 }else if( rc ){
2886 errCnt++;
2887 }
2888 continue;
2889 }
2890 if( _is_command_terminator(zLine) && _is_complete(zSql, nSql) ){
2891 memcpy(zLine,";",2);
 
 
 
 
 
 
 
 
 
2892 }
2893 nSqlPrior = nSql;
2894 if( zSql==0 ){
2895 int i;
2896 for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
2897 if( zLine[i]!=0 ){
2898 nSql = strlen30(zLine);
2899 zSql = malloc( nSql+3 );
2900 if( zSql==0 ){
2901 fprintf(stderr, "Error: out of memory\n");
2902 exit(1);
2903 }
2904 memcpy(zSql, zLine, nSql+1);
2905 startline = lineno;
2906 }
2907 }else{
2908 int len = strlen30(zLine);
2909 zSql = realloc( zSql, nSql + len + 4 );
2910 if( zSql==0 ){
2911 fprintf(stderr,"Error: out of memory\n");
2912 exit(1);
2913 }
2914 zSql[nSql++] = '\n';
2915 memcpy(&zSql[nSql], zLine, len+1);
2916 nSql += len;
2917 }
2918 if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
2919 && sqlite3_complete(zSql) ){
2920 p->cnt = 0;
2921 open_db(p);
2922 BEGIN_TIMER;
2923 rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
@@ -2937,20 +2933,16 @@
2937 }else{
2938 fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
2939 }
2940 errCnt++;
2941 }
2942 free(zSql);
2943 zSql = 0;
2944 nSql = 0;
2945 }else if( zSql && _all_whitespace(zSql) ){
2946 free(zSql);
2947 zSql = 0;
2948 nSql = 0;
2949 }
2950 }
2951 if( zSql ){
2952 if( !_all_whitespace(zSql) ){
2953 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
2954 }
2955 free(zSql);
2956 }
2957
--- src/shell.c
+++ src/shell.c
@@ -51,11 +51,10 @@
51 #if defined(HAVE_READLINE) && HAVE_READLINE==1
52 # include <readline/readline.h>
53 # include <readline/history.h>
54 #endif
55 #if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1)
 
56 # define add_history(X)
57 # define read_history(X)
58 # define write_history(X)
59 # define stifle_history(X)
60 #endif
@@ -335,27 +334,17 @@
334 ** This routine reads a line of text from FILE in, stores
335 ** the text in memory obtained from malloc() and returns a pointer
336 ** to the text. NULL is returned at end of file, or if malloc()
337 ** fails.
338 **
339 ** If zLine is not NULL then it is a malloced buffer returned from
340 ** a previous call to this routine that may be reused.
341 */
342 static char *local_getline(char *zLine, FILE *in){
343 int nLine = zLine==0 ? 0 : 100;
344 int n = 0;
345
 
 
 
 
 
 
 
 
 
 
346 while( 1 ){
347 if( n+100>nLine ){
348 nLine = nLine*2 + 100;
349 zLine = realloc(zLine, nLine);
350 if( zLine==0 ) return 0;
@@ -366,46 +355,52 @@
355 return 0;
356 }
357 zLine[n] = 0;
358 break;
359 }
360 while( zLine[n] ) n++;
361 if( n>0 && zLine[n-1]=='\n' ){
 
 
 
362 n--;
363 if( n>0 && zLine[n-1]=='\r' ) n--;
364 zLine[n] = 0;
365 break;
366 }
367 }
 
368 return zLine;
369 }
370
371 /*
372 ** Retrieve a single line of input text.
373 **
374 ** If in==0 then read from standard input and prompt before each line.
375 ** If isContinuation is true, then a continuation prompt is appropriate.
376 ** If isContinuation is zero, then the main prompt should be used.
377 **
378 ** If zPrior is not NULL then it is a buffer from a prior call to this
379 ** routine that can be reused.
380 **
381 ** The result is stored in space obtained from malloc() and must either
382 ** be freed by the caller or else passed back into this routine via the
383 ** zPrior argument for reuse.
384 */
385 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
386 char *zPrompt;
387 char *zResult;
388 if( in!=0 ){
389 zResult = local_getline(zPrior, in);
 
 
 
390 }else{
391 zPrompt = isContinuation ? continuePrompt : mainPrompt;
 
 
392 #if defined(HAVE_READLINE) && HAVE_READLINE==1
393 free(zPrior);
394 zResult = readline(zPrompt);
395 if( zResult && *zResult ) add_history(zResult);
396 #else
397 printf("%s", zPrompt);
398 fflush(stdout);
399 zResult = local_getline(zPrior, stdin);
400 #endif
401 }
402 return zResult;
403 }
404
405 struct previous_mode_data {
406 int valid; /* Is there legit data in here? */
@@ -1993,10 +1988,11 @@
1988 char *zFile = azArg[1]; /* Name of file to extra content from */
1989 sqlite3_stmt *pStmt = NULL; /* A statement */
1990 int nCol; /* Number of columns in the table */
1991 int nByte; /* Number of bytes in an SQL string */
1992 int i, j; /* Loop counters */
1993 int needCommit; /* True to COMMIT or ROLLBACK at end */
1994 int nSep; /* Number of bytes in p->separator[] */
1995 char *zSql; /* An SQL statement */
1996 CSVReader sCsv; /* Reader context */
1997 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
1998
@@ -2094,10 +2090,12 @@
2090 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2091 if (pStmt) sqlite3_finalize(pStmt);
2092 xCloser(sCsv.in);
2093 return 1;
2094 }
2095 needCommit = sqlite3_get_autocommit(db);
2096 if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
2097 do{
2098 int startLine = sCsv.nLine;
2099 for(i=0; i<nCol; i++){
2100 char *z = csv_read_one_field(&sCsv);
2101 if( z==0 && i==0 ) break;
@@ -2130,11 +2128,11 @@
2128 }while( sCsv.cTerm!=EOF );
2129
2130 xCloser(sCsv.in);
2131 sqlite3_free(sCsv.z);
2132 sqlite3_finalize(pStmt);
2133 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
2134 }else
2135
2136 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2137 struct callback_data data;
2138 char *zErrMsg = 0;
@@ -2779,11 +2777,11 @@
2777
2778 /*
2779 ** Return TRUE if a semicolon occurs anywhere in the first N characters
2780 ** of string z[].
2781 */
2782 static int line_contains_semicolon(const char *z, int N){
2783 int i;
2784 for(i=0; i<N; i++){ if( z[i]==';' ) return 1; }
2785 return 0;
2786 }
2787
@@ -2814,11 +2812,11 @@
2812 /*
2813 ** Return TRUE if the line typed in is an SQL command terminator other
2814 ** than a semi-colon. The SQL Server style "go" command is understood
2815 ** as is the Oracle "/".
2816 */
2817 static int line_is_command_terminator(const char *zLine){
2818 while( IsSpace(zLine[0]) ){ zLine++; };
2819 if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ){
2820 return 1; /* Oracle */
2821 }
2822 if( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o'
@@ -2830,11 +2828,11 @@
2828
2829 /*
2830 ** Return true if zSql is a complete SQL statement. Return false if it
2831 ** ends in the middle of a string literal or C-style comment.
2832 */
2833 static int line_is_complete(char *zSql, int nSql){
2834 int rc;
2835 if( zSql==0 ) return 1;
2836 zSql[nSql] = ';';
2837 zSql[nSql+1] = 0;
2838 rc = sqlite3_complete(zSql);
@@ -2850,24 +2848,25 @@
2848 ** cause this routine to exit immediately, unless input is interactive.
2849 **
2850 ** Return the number of errors.
2851 */
2852 static int process_input(struct callback_data *p, FILE *in){
2853 char *zLine = 0; /* A single input line */
2854 char *zSql = 0; /* Accumulated SQL text */
2855 int nLine; /* Length of current line */
2856 int nSql = 0; /* Bytes of zSql[] used */
2857 int nAlloc = 0; /* Allocated zSql[] space */
2858 int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
2859 char *zErrMsg; /* Error message returned */
2860 int rc; /* Error code */
2861 int errCnt = 0; /* Number of errors seen */
2862 int lineno = 0; /* Current line number */
2863 int startline = 0; /* Line number for start of current input */
2864
2865 while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){
2866 fflush(p->out);
2867 zLine = one_input_line(in, zLine, nSql>0);
 
2868 if( zLine==0 ){
2869 /* End of input */
2870 if( stdin_is_interactive ) printf("\n");
2871 break;
2872 }
@@ -2874,11 +2873,11 @@
2873 if( seenInterrupt ){
2874 if( in!=0 ) break;
2875 seenInterrupt = 0;
2876 }
2877 lineno++;
2878 if( nSql==0 && _all_whitespace(zLine) ) continue;
2879 if( zLine && zLine[0]=='.' && nSql==0 ){
2880 if( p->echoOn ) printf("%s\n", zLine);
2881 rc = do_meta_command(zLine, p);
2882 if( rc==2 ){ /* exit requested */
2883 break;
@@ -2885,39 +2884,36 @@
2884 }else if( rc ){
2885 errCnt++;
2886 }
2887 continue;
2888 }
2889 if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
2890 memcpy(zLine,";",2);
2891 }
2892 nLine = strlen30(zLine);
2893 if( nSql+nLine+2>=nAlloc ){
2894 nAlloc = nSql+nLine+100;
2895 zSql = realloc(zSql, nAlloc);
2896 if( zSql==0 ){
2897 fprintf(stderr, "Error: out of memory\n");
2898 exit(1);
2899 }
2900 }
2901 nSqlPrior = nSql;
2902 if( nSql==0 ){
2903 int i;
2904 for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
2905 assert( nAlloc>0 && zSql!=0 );
2906 memcpy(zSql, zLine+i, nLine+1-i);
2907 startline = lineno;
2908 nSql = nLine-i;
 
 
 
 
 
 
2909 }else{
 
 
 
 
 
 
2910 zSql[nSql++] = '\n';
2911 memcpy(zSql+nSql, zLine, nLine+1);
2912 nSql += nLine;
2913 }
2914 if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
2915 && sqlite3_complete(zSql) ){
2916 p->cnt = 0;
2917 open_db(p);
2918 BEGIN_TIMER;
2919 rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
@@ -2937,20 +2933,16 @@
2933 }else{
2934 fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
2935 }
2936 errCnt++;
2937 }
 
 
2938 nSql = 0;
2939 }else if( nSql && _all_whitespace(zSql) ){
 
 
2940 nSql = 0;
2941 }
2942 }
2943 if( nSql ){
2944 if( !_all_whitespace(zSql) ){
2945 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
2946 }
2947 free(zSql);
2948 }
2949
+133 -81
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656656
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657657
** [sqlite_version()] and [sqlite_source_id()].
658658
*/
659659
#define SQLITE_VERSION "3.8.0"
660660
#define SQLITE_VERSION_NUMBER 3008000
661
-#define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
661
+#define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a"
662662
663663
/*
664664
** CAPI3REF: Run-Time Library Version Numbers
665665
** KEYWORDS: sqlite3_version, sqlite3_sourceid
666666
**
@@ -8587,11 +8587,11 @@
85878587
#define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */
85888588
85898589
SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
85908590
SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
85918591
SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
8592
-SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int);
8592
+SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned);
85938593
SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
85948594
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
85958595
SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
85968596
SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
85978597
SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
@@ -9291,10 +9291,22 @@
92919291
** Flags that make up the mask passed to sqlite3PagerAcquire().
92929292
*/
92939293
#define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */
92949294
#define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */
92959295
9296
+/*
9297
+** Flags for sqlite3PagerSetFlags()
9298
+*/
9299
+#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
9300
+#define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
9301
+#define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
9302
+#define PAGER_SYNCHRONOUS_MASK 0x03 /* Mask for three values above */
9303
+#define PAGER_FULLFSYNC 0x04 /* PRAGMA fullfsync=ON */
9304
+#define PAGER_CKPT_FULLFSYNC 0x08 /* PRAGMA checkpoint_fullfsync=ON */
9305
+#define PAGER_CACHESPILL 0x10 /* PRAGMA cache_spill=ON */
9306
+#define PAGER_FLAGS_MASK 0x1c /* All above except SYNCHRONOUS */
9307
+
92969308
/*
92979309
** The remainder of this file contains the declarations of the functions
92989310
** that make up the Pager sub-system API. See source code comments for
92999311
** a detailed description of each routine.
93009312
*/
@@ -9317,11 +9329,11 @@
93179329
SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
93189330
SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
93199331
SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
93209332
SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
93219333
SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
9322
-SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int,int);
9334
+SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned);
93239335
SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
93249336
SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
93259337
SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
93269338
SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
93279339
SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
@@ -10180,36 +10192,37 @@
1018010192
/*
1018110193
** Possible values for the sqlite3.flags.
1018210194
*/
1018310195
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
1018410196
#define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
10185
-#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
10186
-#define SQLITE_ShortColNames 0x00000008 /* Show short columns names */
10187
-#define SQLITE_CountRows 0x00000010 /* Count rows changed by INSERT, */
10197
+#define SQLITE_FullFSync 0x00000004 /* Use full fsync on the backend */
10198
+#define SQLITE_CkptFullFSync 0x00000008 /* Use full fsync for checkpoint */
10199
+#define SQLITE_CacheSpill 0x00000010 /* OK to spill pager cache */
10200
+#define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */
10201
+#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
10202
+#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
1018810203
/* DELETE, or UPDATE and return */
1018910204
/* the count using a callback. */
10190
-#define SQLITE_NullCallback 0x00000020 /* Invoke the callback once if the */
10205
+#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
1019110206
/* result set is empty */
10192
-#define SQLITE_SqlTrace 0x00000040 /* Debug print SQL as it executes */
10193
-#define SQLITE_VdbeListing 0x00000080 /* Debug listings of VDBE programs */
10194
-#define SQLITE_WriteSchema 0x00000100 /* OK to update SQLITE_MASTER */
10195
-#define SQLITE_VdbeAddopTrace 0x00000200 /* Trace sqlite3VdbeAddOp() calls */
10196
-#define SQLITE_IgnoreChecks 0x00000400 /* Do not enforce check constraints */
10197
-#define SQLITE_ReadUncommitted 0x0000800 /* For shared-cache mode */
10198
-#define SQLITE_LegacyFileFmt 0x00001000 /* Create new databases in format 1 */
10199
-#define SQLITE_FullFSync 0x00002000 /* Use full fsync on the backend */
10200
-#define SQLITE_CkptFullFSync 0x00004000 /* Use full fsync for checkpoint */
10201
-#define SQLITE_RecoveryMode 0x00008000 /* Ignore schema errors */
10202
-#define SQLITE_ReverseOrder 0x00010000 /* Reverse unordered SELECTs */
10203
-#define SQLITE_RecTriggers 0x00020000 /* Enable recursive triggers */
10204
-#define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */
10205
-#define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */
10206
-#define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */
10207
-#define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */
10208
-#define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */
10209
-#define SQLITE_DeferFKs 0x00800000 /* Defer all FK constraints */
10210
-#define SQLITE_QueryOnly 0x01000000 /* Disable database changes */
10207
+#define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */
10208
+#define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */
10209
+#define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */
10210
+#define SQLITE_VdbeAddopTrace 0x00001000 /* Trace sqlite3VdbeAddOp() calls */
10211
+#define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */
10212
+#define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */
10213
+#define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */
10214
+#define SQLITE_RecoveryMode 0x00010000 /* Ignore schema errors */
10215
+#define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */
10216
+#define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
10217
+#define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
10218
+#define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
10219
+#define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
10220
+#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
10221
+#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
10222
+#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
10223
+#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
1021110224
1021210225
1021310226
/*
1021410227
** Bits of the sqlite3.dbOptFlags field that are used by the
1021510228
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -38794,10 +38807,17 @@
3879438807
#ifndef SQLITE_OMIT_WAL
3879538808
u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */
3879638809
#endif
3879738810
};
3879838811
38812
+/*
38813
+** Bits of the Pager.doNotSpill flag. See further description below.
38814
+*/
38815
+#define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
38816
+#define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
38817
+#define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
38818
+
3879938819
/*
3880038820
** A open page cache is an instance of struct Pager. A description of
3880138821
** some of the more important member variables follows:
3880238822
**
3880338823
** eState
@@ -38860,23 +38880,25 @@
3886038880
** The flag is cleared as soon as the journal file is finalized (either
3886138881
** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
3886238882
** journal file from being successfully finalized, the setMaster flag
3886338883
** is cleared anyway (and the pager will move to ERROR state).
3886438884
**
38865
-** doNotSpill, doNotSyncSpill
38866
-**
38867
-** These two boolean variables control the behavior of cache-spills
38868
-** (calls made by the pcache module to the pagerStress() routine to
38869
-** write cached data to the file-system in order to free up memory).
38870
-**
38871
-** When doNotSpill is non-zero, writing to the database from pagerStress()
38872
-** is disabled altogether. This is done in a very obscure case that
38885
+** doNotSpill
38886
+**
38887
+** This variables control the behavior of cache-spills (calls made by
38888
+** the pcache module to the pagerStress() routine to write cached data
38889
+** to the file-system in order to free up memory).
38890
+**
38891
+** When bits SPILLFLAG_OFF or SPILLFLAG_ROLLBACK of doNotSpill are set,
38892
+** writing to the database from pagerStress() is disabled altogether.
38893
+** The SPILLFLAG_ROLLBACK case is done in a very obscure case that
3887338894
** comes up during savepoint rollback that requires the pcache module
3887438895
** to allocate a new page to prevent the journal file from being written
38875
-** while it is being traversed by code in pager_playback().
38896
+** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF
38897
+** case is a user preference.
3887638898
**
38877
-** If doNotSyncSpill is non-zero, writing to the database from pagerStress()
38899
+** If the SPILLFLAG_NOSYNC bit is set, writing to the database from pagerStress()
3887838900
** is permitted, but syncing the journal file is not. This flag is set
3887938901
** by sqlite3PagerWrite() when the file-system sector-size is larger than
3888038902
** the database page-size in order to prevent a journal sync from happening
3888138903
** in between the journalling of two pages on the same sector.
3888238904
**
@@ -38976,11 +38998,10 @@
3897638998
u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */
3897738999
u8 eLock; /* Current lock held on database file */
3897839000
u8 changeCountDone; /* Set after incrementing the change-counter */
3897939001
u8 setMaster; /* True if a m-j name has been written to jrnl */
3898039002
u8 doNotSpill; /* Do not spill the cache when non-zero */
38981
- u8 doNotSyncSpill; /* Do not do a spill that requires jrnl sync */
3898239003
u8 subjInMemory; /* True to use in-memory sub-journals */
3898339004
Pgno dbSize; /* Number of pages in the database */
3898439005
Pgno dbOrigSize; /* dbSize before the current transaction */
3898539006
Pgno dbFileSize; /* Number of pages in the database file */
3898639007
Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
@@ -40636,15 +40657,15 @@
4063640657
** the data just read from the sub-journal. Mark the page as dirty
4063740658
** and if the pager requires a journal-sync, then mark the page as
4063840659
** requiring a journal-sync before it is written.
4063940660
*/
4064040661
assert( isSavepnt );
40641
- assert( pPager->doNotSpill==0 );
40642
- pPager->doNotSpill++;
40662
+ assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 );
40663
+ pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
4064340664
rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1);
40644
- assert( pPager->doNotSpill==1 );
40645
- pPager->doNotSpill--;
40665
+ assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
40666
+ pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
4064640667
if( rc!=SQLITE_OK ) return rc;
4064740668
pPg->flags &= ~PGHDR_NEED_READ;
4064840669
sqlite3PcacheMakeDirty(pPg);
4064940670
}
4065040671
if( pPg ){
@@ -41745,13 +41766,16 @@
4174541766
SQLITE_PRIVATE void sqlite3PagerShrink(Pager *pPager){
4174641767
sqlite3PcacheShrink(pPager->pPCache);
4174741768
}
4174841769
4174941770
/*
41750
-** Adjust the robustness of the database to damage due to OS crashes
41751
-** or power failures by changing the number of syncs()s when writing
41752
-** the rollback journal. There are three levels:
41771
+** Adjust settings of the pager to those specified in the pgFlags parameter.
41772
+**
41773
+** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness
41774
+** of the database to damage due to OS crashes or power failures by
41775
+** changing the number of syncs()s when writing the journals.
41776
+** There are three levels:
4175341777
**
4175441778
** OFF sqlite3OsSync() is never called. This is the default
4175541779
** for temporary and transient files.
4175641780
**
4175741781
** NORMAL The journal is synced once before writes begin on the
@@ -41788,26 +41812,25 @@
4178841812
**
4178941813
** Numeric values associated with these states are OFF==1, NORMAL=2,
4179041814
** and FULL=3.
4179141815
*/
4179241816
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
41793
-SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(
41817
+SQLITE_PRIVATE void sqlite3PagerSetFlags(
4179441818
Pager *pPager, /* The pager to set safety level for */
41795
- int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */
41796
- int bFullFsync, /* PRAGMA fullfsync */
41797
- int bCkptFullFsync /* PRAGMA checkpoint_fullfsync */
41819
+ unsigned pgFlags /* Various flags */
4179841820
){
41821
+ unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK;
4179941822
assert( level>=1 && level<=3 );
4180041823
pPager->noSync = (level==1 || pPager->tempFile) ?1:0;
4180141824
pPager->fullSync = (level==3 && !pPager->tempFile) ?1:0;
4180241825
if( pPager->noSync ){
4180341826
pPager->syncFlags = 0;
4180441827
pPager->ckptSyncFlags = 0;
41805
- }else if( bFullFsync ){
41828
+ }else if( pgFlags & PAGER_FULLFSYNC ){
4180641829
pPager->syncFlags = SQLITE_SYNC_FULL;
4180741830
pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
41808
- }else if( bCkptFullFsync ){
41831
+ }else if( pgFlags & PAGER_CKPT_FULLFSYNC ){
4180941832
pPager->syncFlags = SQLITE_SYNC_NORMAL;
4181041833
pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
4181141834
}else{
4181241835
pPager->syncFlags = SQLITE_SYNC_NORMAL;
4181341836
pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL;
@@ -41814,10 +41837,15 @@
4181441837
}
4181541838
pPager->walSyncFlags = pPager->syncFlags;
4181641839
if( pPager->fullSync ){
4181741840
pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS;
4181841841
}
41842
+ if( pgFlags & PAGER_CACHESPILL ){
41843
+ pPager->doNotSpill &= ~SPILLFLAG_OFF;
41844
+ }else{
41845
+ pPager->doNotSpill |= SPILLFLAG_OFF;
41846
+ }
4181941847
}
4182041848
#endif
4182141849
4182241850
/*
4182341851
** The following global variable is incremented whenever the library
@@ -42714,28 +42742,34 @@
4271442742
int rc = SQLITE_OK;
4271542743
4271642744
assert( pPg->pPager==pPager );
4271742745
assert( pPg->flags&PGHDR_DIRTY );
4271842746
42719
- /* The doNotSyncSpill flag is set during times when doing a sync of
42747
+ /* The doNotSpill NOSYNC bit is set during times when doing a sync of
4272042748
** journal (and adding a new header) is not allowed. This occurs
4272142749
** during calls to sqlite3PagerWrite() while trying to journal multiple
4272242750
** pages belonging to the same sector.
4272342751
**
42724
- ** The doNotSpill flag inhibits all cache spilling regardless of whether
42725
- ** or not a sync is required. This is set during a rollback.
42752
+ ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
42753
+ ** regardless of whether or not a sync is required. This is set during
42754
+ ** a rollback or by user request, respectively.
4272642755
**
4272742756
** Spilling is also prohibited when in an error state since that could
4272842757
** lead to database corruption. In the current implementaton it
4272942758
** is impossible for sqlite3PcacheFetch() to be called with createFlag==1
4273042759
** while in the error state, hence it is impossible for this routine to
4273142760
** be called in the error state. Nevertheless, we include a NEVER()
4273242761
** test for the error state as a safeguard against future changes.
4273342762
*/
4273442763
if( NEVER(pPager->errCode) ) return SQLITE_OK;
42735
- if( pPager->doNotSpill ) return SQLITE_OK;
42736
- if( pPager->doNotSyncSpill && (pPg->flags & PGHDR_NEED_SYNC)!=0 ){
42764
+ testcase( pPager->doNotSpill & SPILLFLAG_ROLLBACK );
42765
+ testcase( pPager->doNotSpill & SPILLFLAG_OFF );
42766
+ testcase( pPager->doNotSpill & SPILLFLAG_NOSYNC );
42767
+ if( pPager->doNotSpill
42768
+ && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0
42769
+ || (pPg->flags & PGHDR_NEED_SYNC)!=0)
42770
+ ){
4273742771
return SQLITE_OK;
4273842772
}
4273942773
4274042774
pPg->pDirty = 0;
4274142775
if( pagerUseWal(pPager) ){
@@ -44085,17 +44119,17 @@
4408544119
Pgno pg1; /* First page of the sector pPg is located on. */
4408644120
int nPage = 0; /* Number of pages starting at pg1 to journal */
4408744121
int ii; /* Loop counter */
4408844122
int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
4408944123
44090
- /* Set the doNotSyncSpill flag to 1. This is because we cannot allow
44124
+ /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
4409144125
** a journal header to be written between the pages journaled by
4409244126
** this function.
4409344127
*/
4409444128
assert( !MEMDB );
44095
- assert( pPager->doNotSyncSpill==0 );
44096
- pPager->doNotSyncSpill++;
44129
+ assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 );
44130
+ pPager->doNotSpill |= SPILLFLAG_NOSYNC;
4409744131
4409844132
/* This trick assumes that both the page-size and sector-size are
4409944133
** an integer power of 2. It sets variable pg1 to the identifier
4410044134
** of the first page of the sector pPg is located on.
4410144135
*/
@@ -44150,12 +44184,12 @@
4415044184
sqlite3PagerUnref(pPage);
4415144185
}
4415244186
}
4415344187
}
4415444188
44155
- assert( pPager->doNotSyncSpill==1 );
44156
- pPager->doNotSyncSpill--;
44189
+ assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
44190
+ pPager->doNotSpill &= ~SPILLFLAG_NOSYNC;
4415744191
}else{
4415844192
rc = pager_write(pDbPage);
4415944193
}
4416044194
return rc;
4416144195
}
@@ -51727,21 +51761,18 @@
5172751761
** there is a high probability of damage) Level 2 is the default. There
5172851762
** is a very low but non-zero probability of damage. Level 3 reduces the
5172951763
** probability of damage to near zero but with a write performance reduction.
5173051764
*/
5173151765
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
51732
-SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(
51766
+SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(
5173351767
Btree *p, /* The btree to set the safety level on */
51734
- int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */
51735
- int fullSync, /* PRAGMA fullfsync. */
51736
- int ckptFullSync /* PRAGMA checkpoint_fullfync */
51768
+ unsigned pgFlags /* Various PAGER_* flags */
5173751769
){
5173851770
BtShared *pBt = p->pBt;
5173951771
assert( sqlite3_mutex_held(p->db->mutex) );
51740
- assert( level>=1 && level<=3 );
5174151772
sqlite3BtreeEnter(p);
51742
- sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync, ckptFullSync);
51773
+ sqlite3PagerSetFlags(pBt->pPager, pgFlags);
5174351774
sqlite3BtreeLeave(p);
5174451775
return SQLITE_OK;
5174551776
}
5174651777
#endif
5174751778
@@ -71760,10 +71791,11 @@
7176071791
/* This is the only way out of this procedure. We have to
7176171792
** release the mutexes on btrees that were acquired at the
7176271793
** top. */
7176371794
vdbe_return:
7176471795
db->lastRowid = lastRowid;
71796
+ testcase( nVmStep>0 );
7176571797
p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
7176671798
sqlite3VdbeLeave(p);
7176771799
return rc;
7176871800
7176971801
/* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
@@ -81769,10 +81801,11 @@
8176981801
}
8177081802
pPager = sqlite3BtreePager(aNew->pBt);
8177181803
sqlite3PagerLockingMode(pPager, db->dfltLockMode);
8177281804
sqlite3BtreeSecureDelete(aNew->pBt,
8177381805
sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
81806
+ sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
8177481807
}
8177581808
aNew->safety_level = 3;
8177681809
aNew->zName = sqlite3DbStrDup(db, zName);
8177781810
if( rc==SQLITE_OK && aNew->zName==0 ){
8177881811
rc = SQLITE_NOMEM;
@@ -85289,11 +85322,11 @@
8528985322
8529085323
/* Gather the complete text of the CREATE INDEX statement into
8529185324
** the zStmt variable
8529285325
*/
8529385326
if( pStart ){
85294
- int n = (pParse->sLastToken.z - pName->z) + pParse->sLastToken.n;
85327
+ int n = (int)(pParse->sLastToken.z - pName->z) + pParse->sLastToken.n;
8529585328
if( pName->z[n-1]==';' ) n--;
8529685329
/* A named index with an explicit CREATE INDEX statement */
8529785330
zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
8529885331
onError==OE_None ? "" : " UNIQUE", n, pName->z);
8529985332
}else{
@@ -93834,10 +93867,38 @@
9383493867
sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
9383593868
sqlite3VdbeSetNumCols(v, 1);
9383693869
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
9383793870
sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
9383893871
}
93872
+
93873
+
93874
+/*
93875
+** Set the safety_level and pager flags for pager iDb. Or if iDb<0
93876
+** set these values for all pagers.
93877
+*/
93878
+#ifndef SQLITE_OMIT_PAGER_PRAGMAS
93879
+static void setAllPagerFlags(sqlite3 *db){
93880
+ if( db->autoCommit ){
93881
+ Db *pDb = db->aDb;
93882
+ int n = db->nDb;
93883
+ assert( SQLITE_FullFSync==PAGER_FULLFSYNC );
93884
+ assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC );
93885
+ assert( SQLITE_CacheSpill==PAGER_CACHESPILL );
93886
+ assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL)
93887
+ == PAGER_FLAGS_MASK );
93888
+ assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level );
93889
+ while( (n--) > 0 ){
93890
+ if( pDb->pBt ){
93891
+ sqlite3BtreeSetPagerFlags(pDb->pBt,
93892
+ pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) );
93893
+ }
93894
+ pDb++;
93895
+ }
93896
+ }
93897
+}
93898
+#endif
93899
+
9383993900
9384093901
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
9384193902
/*
9384293903
** Check to see if zRight and zLeft refer to a pragma that queries
9384393904
** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
@@ -93853,10 +93914,11 @@
9385393914
{ "count_changes", SQLITE_CountRows },
9385493915
{ "empty_result_callbacks", SQLITE_NullCallback },
9385593916
{ "legacy_file_format", SQLITE_LegacyFileFmt },
9385693917
{ "fullfsync", SQLITE_FullFSync },
9385793918
{ "checkpoint_fullfsync", SQLITE_CkptFullFSync },
93919
+ { "cache_spill", SQLITE_CacheSpill },
9385893920
{ "reverse_unordered_selects", SQLITE_ReverseOrder },
9385993921
{ "query_only", SQLITE_QueryOnly },
9386093922
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
9386193923
{ "automatic_index", SQLITE_AutoIndex },
9386293924
#endif
@@ -94643,19 +94705,19 @@
9464394705
if( !db->autoCommit ){
9464494706
sqlite3ErrorMsg(pParse,
9464594707
"Safety level may not be changed inside a transaction");
9464694708
}else{
9464794709
pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
94710
+ setAllPagerFlags(db);
9464894711
}
9464994712
}
9465094713
}else
9465194714
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
9465294715
9465394716
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
9465494717
if( flagPragma(pParse, zLeft, zRight) ){
94655
- /* The flagPragma() subroutine also generates any necessary code
94656
- ** there is nothing more to do here */
94718
+ setAllPagerFlags(db);
9465794719
}else
9465894720
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
9465994721
9466094722
#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
9466194723
/*
@@ -95482,21 +95544,10 @@
9548295544
#endif
9548395545
9548495546
9548595547
{/* Empty ELSE clause */}
9548695548
95487
- /*
95488
- ** Reset the safety level, in case the fullfsync flag or synchronous
95489
- ** setting changed.
95490
- */
95491
-#ifndef SQLITE_OMIT_PAGER_PRAGMAS
95492
- if( db->autoCommit ){
95493
- sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
95494
- (db->flags&SQLITE_FullFSync)!=0,
95495
- (db->flags&SQLITE_CkptFullFSync)!=0);
95496
- }
95497
-#endif
9549895549
pragma_out:
9549995550
sqlite3DbFree(db, zLeft);
9550095551
sqlite3DbFree(db, zRight);
9550195552
}
9550295553
@@ -109541,10 +109592,11 @@
109541109592
109542109593
pWC = pBuilder->pWC;
109543109594
if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
109544109595
pWCEnd = pWC->a + pWC->nTerm;
109545109596
pNew = pBuilder->pNew;
109597
+ memset(&sSum, 0, sizeof(sSum));
109546109598
109547109599
for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
109548109600
if( (pTerm->eOperator & WO_OR)!=0
109549109601
&& (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
109550109602
){
@@ -117967,11 +118019,11 @@
117967118019
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
117968118020
db->autoCommit = 1;
117969118021
db->nextAutovac = -1;
117970118022
db->szMmap = sqlite3GlobalConfig.szMmap;
117971118023
db->nextPagesize = 0;
117972
- db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
118024
+ db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
117973118025
#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117974118026
| SQLITE_AutoIndex
117975118027
#endif
117976118028
#if SQLITE_DEFAULT_FILE_FORMAT<4
117977118029
| SQLITE_LegacyFileFmt
117978118030
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.0"
660 #define SQLITE_VERSION_NUMBER 3008000
661 #define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -8587,11 +8587,11 @@
8587 #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */
8588
8589 SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
8590 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
8591 SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
8592 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int);
8593 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
8594 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
8595 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
8596 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
8597 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
@@ -9291,10 +9291,22 @@
9291 ** Flags that make up the mask passed to sqlite3PagerAcquire().
9292 */
9293 #define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */
9294 #define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */
9295
 
 
 
 
 
 
 
 
 
 
 
 
9296 /*
9297 ** The remainder of this file contains the declarations of the functions
9298 ** that make up the Pager sub-system API. See source code comments for
9299 ** a detailed description of each routine.
9300 */
@@ -9317,11 +9329,11 @@
9317 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
9318 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
9319 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
9320 SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
9321 SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
9322 SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int,int);
9323 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
9324 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
9325 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
9326 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
9327 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
@@ -10180,36 +10192,37 @@
10180 /*
10181 ** Possible values for the sqlite3.flags.
10182 */
10183 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
10184 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
10185 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
10186 #define SQLITE_ShortColNames 0x00000008 /* Show short columns names */
10187 #define SQLITE_CountRows 0x00000010 /* Count rows changed by INSERT, */
 
 
 
10188 /* DELETE, or UPDATE and return */
10189 /* the count using a callback. */
10190 #define SQLITE_NullCallback 0x00000020 /* Invoke the callback once if the */
10191 /* result set is empty */
10192 #define SQLITE_SqlTrace 0x00000040 /* Debug print SQL as it executes */
10193 #define SQLITE_VdbeListing 0x00000080 /* Debug listings of VDBE programs */
10194 #define SQLITE_WriteSchema 0x00000100 /* OK to update SQLITE_MASTER */
10195 #define SQLITE_VdbeAddopTrace 0x00000200 /* Trace sqlite3VdbeAddOp() calls */
10196 #define SQLITE_IgnoreChecks 0x00000400 /* Do not enforce check constraints */
10197 #define SQLITE_ReadUncommitted 0x0000800 /* For shared-cache mode */
10198 #define SQLITE_LegacyFileFmt 0x00001000 /* Create new databases in format 1 */
10199 #define SQLITE_FullFSync 0x00002000 /* Use full fsync on the backend */
10200 #define SQLITE_CkptFullFSync 0x00004000 /* Use full fsync for checkpoint */
10201 #define SQLITE_RecoveryMode 0x00008000 /* Ignore schema errors */
10202 #define SQLITE_ReverseOrder 0x00010000 /* Reverse unordered SELECTs */
10203 #define SQLITE_RecTriggers 0x00020000 /* Enable recursive triggers */
10204 #define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */
10205 #define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */
10206 #define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */
10207 #define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */
10208 #define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */
10209 #define SQLITE_DeferFKs 0x00800000 /* Defer all FK constraints */
10210 #define SQLITE_QueryOnly 0x01000000 /* Disable database changes */
10211
10212
10213 /*
10214 ** Bits of the sqlite3.dbOptFlags field that are used by the
10215 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -38794,10 +38807,17 @@
38794 #ifndef SQLITE_OMIT_WAL
38795 u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */
38796 #endif
38797 };
38798
 
 
 
 
 
 
 
38799 /*
38800 ** A open page cache is an instance of struct Pager. A description of
38801 ** some of the more important member variables follows:
38802 **
38803 ** eState
@@ -38860,23 +38880,25 @@
38860 ** The flag is cleared as soon as the journal file is finalized (either
38861 ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
38862 ** journal file from being successfully finalized, the setMaster flag
38863 ** is cleared anyway (and the pager will move to ERROR state).
38864 **
38865 ** doNotSpill, doNotSyncSpill
38866 **
38867 ** These two boolean variables control the behavior of cache-spills
38868 ** (calls made by the pcache module to the pagerStress() routine to
38869 ** write cached data to the file-system in order to free up memory).
38870 **
38871 ** When doNotSpill is non-zero, writing to the database from pagerStress()
38872 ** is disabled altogether. This is done in a very obscure case that
 
38873 ** comes up during savepoint rollback that requires the pcache module
38874 ** to allocate a new page to prevent the journal file from being written
38875 ** while it is being traversed by code in pager_playback().
 
38876 **
38877 ** If doNotSyncSpill is non-zero, writing to the database from pagerStress()
38878 ** is permitted, but syncing the journal file is not. This flag is set
38879 ** by sqlite3PagerWrite() when the file-system sector-size is larger than
38880 ** the database page-size in order to prevent a journal sync from happening
38881 ** in between the journalling of two pages on the same sector.
38882 **
@@ -38976,11 +38998,10 @@
38976 u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */
38977 u8 eLock; /* Current lock held on database file */
38978 u8 changeCountDone; /* Set after incrementing the change-counter */
38979 u8 setMaster; /* True if a m-j name has been written to jrnl */
38980 u8 doNotSpill; /* Do not spill the cache when non-zero */
38981 u8 doNotSyncSpill; /* Do not do a spill that requires jrnl sync */
38982 u8 subjInMemory; /* True to use in-memory sub-journals */
38983 Pgno dbSize; /* Number of pages in the database */
38984 Pgno dbOrigSize; /* dbSize before the current transaction */
38985 Pgno dbFileSize; /* Number of pages in the database file */
38986 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
@@ -40636,15 +40657,15 @@
40636 ** the data just read from the sub-journal. Mark the page as dirty
40637 ** and if the pager requires a journal-sync, then mark the page as
40638 ** requiring a journal-sync before it is written.
40639 */
40640 assert( isSavepnt );
40641 assert( pPager->doNotSpill==0 );
40642 pPager->doNotSpill++;
40643 rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1);
40644 assert( pPager->doNotSpill==1 );
40645 pPager->doNotSpill--;
40646 if( rc!=SQLITE_OK ) return rc;
40647 pPg->flags &= ~PGHDR_NEED_READ;
40648 sqlite3PcacheMakeDirty(pPg);
40649 }
40650 if( pPg ){
@@ -41745,13 +41766,16 @@
41745 SQLITE_PRIVATE void sqlite3PagerShrink(Pager *pPager){
41746 sqlite3PcacheShrink(pPager->pPCache);
41747 }
41748
41749 /*
41750 ** Adjust the robustness of the database to damage due to OS crashes
41751 ** or power failures by changing the number of syncs()s when writing
41752 ** the rollback journal. There are three levels:
 
 
 
41753 **
41754 ** OFF sqlite3OsSync() is never called. This is the default
41755 ** for temporary and transient files.
41756 **
41757 ** NORMAL The journal is synced once before writes begin on the
@@ -41788,26 +41812,25 @@
41788 **
41789 ** Numeric values associated with these states are OFF==1, NORMAL=2,
41790 ** and FULL=3.
41791 */
41792 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
41793 SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(
41794 Pager *pPager, /* The pager to set safety level for */
41795 int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */
41796 int bFullFsync, /* PRAGMA fullfsync */
41797 int bCkptFullFsync /* PRAGMA checkpoint_fullfsync */
41798 ){
 
41799 assert( level>=1 && level<=3 );
41800 pPager->noSync = (level==1 || pPager->tempFile) ?1:0;
41801 pPager->fullSync = (level==3 && !pPager->tempFile) ?1:0;
41802 if( pPager->noSync ){
41803 pPager->syncFlags = 0;
41804 pPager->ckptSyncFlags = 0;
41805 }else if( bFullFsync ){
41806 pPager->syncFlags = SQLITE_SYNC_FULL;
41807 pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
41808 }else if( bCkptFullFsync ){
41809 pPager->syncFlags = SQLITE_SYNC_NORMAL;
41810 pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
41811 }else{
41812 pPager->syncFlags = SQLITE_SYNC_NORMAL;
41813 pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL;
@@ -41814,10 +41837,15 @@
41814 }
41815 pPager->walSyncFlags = pPager->syncFlags;
41816 if( pPager->fullSync ){
41817 pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS;
41818 }
 
 
 
 
 
41819 }
41820 #endif
41821
41822 /*
41823 ** The following global variable is incremented whenever the library
@@ -42714,28 +42742,34 @@
42714 int rc = SQLITE_OK;
42715
42716 assert( pPg->pPager==pPager );
42717 assert( pPg->flags&PGHDR_DIRTY );
42718
42719 /* The doNotSyncSpill flag is set during times when doing a sync of
42720 ** journal (and adding a new header) is not allowed. This occurs
42721 ** during calls to sqlite3PagerWrite() while trying to journal multiple
42722 ** pages belonging to the same sector.
42723 **
42724 ** The doNotSpill flag inhibits all cache spilling regardless of whether
42725 ** or not a sync is required. This is set during a rollback.
 
42726 **
42727 ** Spilling is also prohibited when in an error state since that could
42728 ** lead to database corruption. In the current implementaton it
42729 ** is impossible for sqlite3PcacheFetch() to be called with createFlag==1
42730 ** while in the error state, hence it is impossible for this routine to
42731 ** be called in the error state. Nevertheless, we include a NEVER()
42732 ** test for the error state as a safeguard against future changes.
42733 */
42734 if( NEVER(pPager->errCode) ) return SQLITE_OK;
42735 if( pPager->doNotSpill ) return SQLITE_OK;
42736 if( pPager->doNotSyncSpill && (pPg->flags & PGHDR_NEED_SYNC)!=0 ){
 
 
 
 
 
42737 return SQLITE_OK;
42738 }
42739
42740 pPg->pDirty = 0;
42741 if( pagerUseWal(pPager) ){
@@ -44085,17 +44119,17 @@
44085 Pgno pg1; /* First page of the sector pPg is located on. */
44086 int nPage = 0; /* Number of pages starting at pg1 to journal */
44087 int ii; /* Loop counter */
44088 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
44089
44090 /* Set the doNotSyncSpill flag to 1. This is because we cannot allow
44091 ** a journal header to be written between the pages journaled by
44092 ** this function.
44093 */
44094 assert( !MEMDB );
44095 assert( pPager->doNotSyncSpill==0 );
44096 pPager->doNotSyncSpill++;
44097
44098 /* This trick assumes that both the page-size and sector-size are
44099 ** an integer power of 2. It sets variable pg1 to the identifier
44100 ** of the first page of the sector pPg is located on.
44101 */
@@ -44150,12 +44184,12 @@
44150 sqlite3PagerUnref(pPage);
44151 }
44152 }
44153 }
44154
44155 assert( pPager->doNotSyncSpill==1 );
44156 pPager->doNotSyncSpill--;
44157 }else{
44158 rc = pager_write(pDbPage);
44159 }
44160 return rc;
44161 }
@@ -51727,21 +51761,18 @@
51727 ** there is a high probability of damage) Level 2 is the default. There
51728 ** is a very low but non-zero probability of damage. Level 3 reduces the
51729 ** probability of damage to near zero but with a write performance reduction.
51730 */
51731 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
51732 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(
51733 Btree *p, /* The btree to set the safety level on */
51734 int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */
51735 int fullSync, /* PRAGMA fullfsync. */
51736 int ckptFullSync /* PRAGMA checkpoint_fullfync */
51737 ){
51738 BtShared *pBt = p->pBt;
51739 assert( sqlite3_mutex_held(p->db->mutex) );
51740 assert( level>=1 && level<=3 );
51741 sqlite3BtreeEnter(p);
51742 sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync, ckptFullSync);
51743 sqlite3BtreeLeave(p);
51744 return SQLITE_OK;
51745 }
51746 #endif
51747
@@ -71760,10 +71791,11 @@
71760 /* This is the only way out of this procedure. We have to
71761 ** release the mutexes on btrees that were acquired at the
71762 ** top. */
71763 vdbe_return:
71764 db->lastRowid = lastRowid;
 
71765 p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
71766 sqlite3VdbeLeave(p);
71767 return rc;
71768
71769 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
@@ -81769,10 +81801,11 @@
81769 }
81770 pPager = sqlite3BtreePager(aNew->pBt);
81771 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
81772 sqlite3BtreeSecureDelete(aNew->pBt,
81773 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
 
81774 }
81775 aNew->safety_level = 3;
81776 aNew->zName = sqlite3DbStrDup(db, zName);
81777 if( rc==SQLITE_OK && aNew->zName==0 ){
81778 rc = SQLITE_NOMEM;
@@ -85289,11 +85322,11 @@
85289
85290 /* Gather the complete text of the CREATE INDEX statement into
85291 ** the zStmt variable
85292 */
85293 if( pStart ){
85294 int n = (pParse->sLastToken.z - pName->z) + pParse->sLastToken.n;
85295 if( pName->z[n-1]==';' ) n--;
85296 /* A named index with an explicit CREATE INDEX statement */
85297 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
85298 onError==OE_None ? "" : " UNIQUE", n, pName->z);
85299 }else{
@@ -93834,10 +93867,38 @@
93834 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
93835 sqlite3VdbeSetNumCols(v, 1);
93836 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
93837 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
93838 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93839
93840 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
93841 /*
93842 ** Check to see if zRight and zLeft refer to a pragma that queries
93843 ** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
@@ -93853,10 +93914,11 @@
93853 { "count_changes", SQLITE_CountRows },
93854 { "empty_result_callbacks", SQLITE_NullCallback },
93855 { "legacy_file_format", SQLITE_LegacyFileFmt },
93856 { "fullfsync", SQLITE_FullFSync },
93857 { "checkpoint_fullfsync", SQLITE_CkptFullFSync },
 
93858 { "reverse_unordered_selects", SQLITE_ReverseOrder },
93859 { "query_only", SQLITE_QueryOnly },
93860 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
93861 { "automatic_index", SQLITE_AutoIndex },
93862 #endif
@@ -94643,19 +94705,19 @@
94643 if( !db->autoCommit ){
94644 sqlite3ErrorMsg(pParse,
94645 "Safety level may not be changed inside a transaction");
94646 }else{
94647 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
 
94648 }
94649 }
94650 }else
94651 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
94652
94653 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
94654 if( flagPragma(pParse, zLeft, zRight) ){
94655 /* The flagPragma() subroutine also generates any necessary code
94656 ** there is nothing more to do here */
94657 }else
94658 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
94659
94660 #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
94661 /*
@@ -95482,21 +95544,10 @@
95482 #endif
95483
95484
95485 {/* Empty ELSE clause */}
95486
95487 /*
95488 ** Reset the safety level, in case the fullfsync flag or synchronous
95489 ** setting changed.
95490 */
95491 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
95492 if( db->autoCommit ){
95493 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
95494 (db->flags&SQLITE_FullFSync)!=0,
95495 (db->flags&SQLITE_CkptFullFSync)!=0);
95496 }
95497 #endif
95498 pragma_out:
95499 sqlite3DbFree(db, zLeft);
95500 sqlite3DbFree(db, zRight);
95501 }
95502
@@ -109541,10 +109592,11 @@
109541
109542 pWC = pBuilder->pWC;
109543 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
109544 pWCEnd = pWC->a + pWC->nTerm;
109545 pNew = pBuilder->pNew;
 
109546
109547 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
109548 if( (pTerm->eOperator & WO_OR)!=0
109549 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
109550 ){
@@ -117967,11 +118019,11 @@
117967 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
117968 db->autoCommit = 1;
117969 db->nextAutovac = -1;
117970 db->szMmap = sqlite3GlobalConfig.szMmap;
117971 db->nextPagesize = 0;
117972 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117973 #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117974 | SQLITE_AutoIndex
117975 #endif
117976 #if SQLITE_DEFAULT_FILE_FORMAT<4
117977 | SQLITE_LegacyFileFmt
117978
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.0"
660 #define SQLITE_VERSION_NUMBER 3008000
661 #define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -8587,11 +8587,11 @@
8587 #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */
8588
8589 SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
8590 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
8591 SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
8592 SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned);
8593 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
8594 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
8595 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
8596 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
8597 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
@@ -9291,10 +9291,22 @@
9291 ** Flags that make up the mask passed to sqlite3PagerAcquire().
9292 */
9293 #define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */
9294 #define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */
9295
9296 /*
9297 ** Flags for sqlite3PagerSetFlags()
9298 */
9299 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
9300 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
9301 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
9302 #define PAGER_SYNCHRONOUS_MASK 0x03 /* Mask for three values above */
9303 #define PAGER_FULLFSYNC 0x04 /* PRAGMA fullfsync=ON */
9304 #define PAGER_CKPT_FULLFSYNC 0x08 /* PRAGMA checkpoint_fullfsync=ON */
9305 #define PAGER_CACHESPILL 0x10 /* PRAGMA cache_spill=ON */
9306 #define PAGER_FLAGS_MASK 0x1c /* All above except SYNCHRONOUS */
9307
9308 /*
9309 ** The remainder of this file contains the declarations of the functions
9310 ** that make up the Pager sub-system API. See source code comments for
9311 ** a detailed description of each routine.
9312 */
@@ -9317,11 +9329,11 @@
9329 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
9330 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
9331 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
9332 SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
9333 SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
9334 SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned);
9335 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
9336 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
9337 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
9338 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
9339 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
@@ -10180,36 +10192,37 @@
10192 /*
10193 ** Possible values for the sqlite3.flags.
10194 */
10195 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
10196 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
10197 #define SQLITE_FullFSync 0x00000004 /* Use full fsync on the backend */
10198 #define SQLITE_CkptFullFSync 0x00000008 /* Use full fsync for checkpoint */
10199 #define SQLITE_CacheSpill 0x00000010 /* OK to spill pager cache */
10200 #define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */
10201 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
10202 #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
10203 /* DELETE, or UPDATE and return */
10204 /* the count using a callback. */
10205 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
10206 /* result set is empty */
10207 #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */
10208 #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */
10209 #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */
10210 #define SQLITE_VdbeAddopTrace 0x00001000 /* Trace sqlite3VdbeAddOp() calls */
10211 #define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */
10212 #define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */
10213 #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */
10214 #define SQLITE_RecoveryMode 0x00010000 /* Ignore schema errors */
10215 #define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */
10216 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
10217 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
10218 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
10219 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
10220 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
10221 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
10222 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
10223 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
 
 
10224
10225
10226 /*
10227 ** Bits of the sqlite3.dbOptFlags field that are used by the
10228 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -38794,10 +38807,17 @@
38807 #ifndef SQLITE_OMIT_WAL
38808 u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */
38809 #endif
38810 };
38811
38812 /*
38813 ** Bits of the Pager.doNotSpill flag. See further description below.
38814 */
38815 #define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
38816 #define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
38817 #define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
38818
38819 /*
38820 ** A open page cache is an instance of struct Pager. A description of
38821 ** some of the more important member variables follows:
38822 **
38823 ** eState
@@ -38860,23 +38880,25 @@
38880 ** The flag is cleared as soon as the journal file is finalized (either
38881 ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
38882 ** journal file from being successfully finalized, the setMaster flag
38883 ** is cleared anyway (and the pager will move to ERROR state).
38884 **
38885 ** doNotSpill
38886 **
38887 ** This variables control the behavior of cache-spills (calls made by
38888 ** the pcache module to the pagerStress() routine to write cached data
38889 ** to the file-system in order to free up memory).
38890 **
38891 ** When bits SPILLFLAG_OFF or SPILLFLAG_ROLLBACK of doNotSpill are set,
38892 ** writing to the database from pagerStress() is disabled altogether.
38893 ** The SPILLFLAG_ROLLBACK case is done in a very obscure case that
38894 ** comes up during savepoint rollback that requires the pcache module
38895 ** to allocate a new page to prevent the journal file from being written
38896 ** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF
38897 ** case is a user preference.
38898 **
38899 ** If the SPILLFLAG_NOSYNC bit is set, writing to the database from pagerStress()
38900 ** is permitted, but syncing the journal file is not. This flag is set
38901 ** by sqlite3PagerWrite() when the file-system sector-size is larger than
38902 ** the database page-size in order to prevent a journal sync from happening
38903 ** in between the journalling of two pages on the same sector.
38904 **
@@ -38976,11 +38998,10 @@
38998 u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */
38999 u8 eLock; /* Current lock held on database file */
39000 u8 changeCountDone; /* Set after incrementing the change-counter */
39001 u8 setMaster; /* True if a m-j name has been written to jrnl */
39002 u8 doNotSpill; /* Do not spill the cache when non-zero */
 
39003 u8 subjInMemory; /* True to use in-memory sub-journals */
39004 Pgno dbSize; /* Number of pages in the database */
39005 Pgno dbOrigSize; /* dbSize before the current transaction */
39006 Pgno dbFileSize; /* Number of pages in the database file */
39007 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
@@ -40636,15 +40657,15 @@
40657 ** the data just read from the sub-journal. Mark the page as dirty
40658 ** and if the pager requires a journal-sync, then mark the page as
40659 ** requiring a journal-sync before it is written.
40660 */
40661 assert( isSavepnt );
40662 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 );
40663 pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
40664 rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1);
40665 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
40666 pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
40667 if( rc!=SQLITE_OK ) return rc;
40668 pPg->flags &= ~PGHDR_NEED_READ;
40669 sqlite3PcacheMakeDirty(pPg);
40670 }
40671 if( pPg ){
@@ -41745,13 +41766,16 @@
41766 SQLITE_PRIVATE void sqlite3PagerShrink(Pager *pPager){
41767 sqlite3PcacheShrink(pPager->pPCache);
41768 }
41769
41770 /*
41771 ** Adjust settings of the pager to those specified in the pgFlags parameter.
41772 **
41773 ** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness
41774 ** of the database to damage due to OS crashes or power failures by
41775 ** changing the number of syncs()s when writing the journals.
41776 ** There are three levels:
41777 **
41778 ** OFF sqlite3OsSync() is never called. This is the default
41779 ** for temporary and transient files.
41780 **
41781 ** NORMAL The journal is synced once before writes begin on the
@@ -41788,26 +41812,25 @@
41812 **
41813 ** Numeric values associated with these states are OFF==1, NORMAL=2,
41814 ** and FULL=3.
41815 */
41816 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
41817 SQLITE_PRIVATE void sqlite3PagerSetFlags(
41818 Pager *pPager, /* The pager to set safety level for */
41819 unsigned pgFlags /* Various flags */
 
 
41820 ){
41821 unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK;
41822 assert( level>=1 && level<=3 );
41823 pPager->noSync = (level==1 || pPager->tempFile) ?1:0;
41824 pPager->fullSync = (level==3 && !pPager->tempFile) ?1:0;
41825 if( pPager->noSync ){
41826 pPager->syncFlags = 0;
41827 pPager->ckptSyncFlags = 0;
41828 }else if( pgFlags & PAGER_FULLFSYNC ){
41829 pPager->syncFlags = SQLITE_SYNC_FULL;
41830 pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
41831 }else if( pgFlags & PAGER_CKPT_FULLFSYNC ){
41832 pPager->syncFlags = SQLITE_SYNC_NORMAL;
41833 pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
41834 }else{
41835 pPager->syncFlags = SQLITE_SYNC_NORMAL;
41836 pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL;
@@ -41814,10 +41837,15 @@
41837 }
41838 pPager->walSyncFlags = pPager->syncFlags;
41839 if( pPager->fullSync ){
41840 pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS;
41841 }
41842 if( pgFlags & PAGER_CACHESPILL ){
41843 pPager->doNotSpill &= ~SPILLFLAG_OFF;
41844 }else{
41845 pPager->doNotSpill |= SPILLFLAG_OFF;
41846 }
41847 }
41848 #endif
41849
41850 /*
41851 ** The following global variable is incremented whenever the library
@@ -42714,28 +42742,34 @@
42742 int rc = SQLITE_OK;
42743
42744 assert( pPg->pPager==pPager );
42745 assert( pPg->flags&PGHDR_DIRTY );
42746
42747 /* The doNotSpill NOSYNC bit is set during times when doing a sync of
42748 ** journal (and adding a new header) is not allowed. This occurs
42749 ** during calls to sqlite3PagerWrite() while trying to journal multiple
42750 ** pages belonging to the same sector.
42751 **
42752 ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
42753 ** regardless of whether or not a sync is required. This is set during
42754 ** a rollback or by user request, respectively.
42755 **
42756 ** Spilling is also prohibited when in an error state since that could
42757 ** lead to database corruption. In the current implementaton it
42758 ** is impossible for sqlite3PcacheFetch() to be called with createFlag==1
42759 ** while in the error state, hence it is impossible for this routine to
42760 ** be called in the error state. Nevertheless, we include a NEVER()
42761 ** test for the error state as a safeguard against future changes.
42762 */
42763 if( NEVER(pPager->errCode) ) return SQLITE_OK;
42764 testcase( pPager->doNotSpill & SPILLFLAG_ROLLBACK );
42765 testcase( pPager->doNotSpill & SPILLFLAG_OFF );
42766 testcase( pPager->doNotSpill & SPILLFLAG_NOSYNC );
42767 if( pPager->doNotSpill
42768 && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0
42769 || (pPg->flags & PGHDR_NEED_SYNC)!=0)
42770 ){
42771 return SQLITE_OK;
42772 }
42773
42774 pPg->pDirty = 0;
42775 if( pagerUseWal(pPager) ){
@@ -44085,17 +44119,17 @@
44119 Pgno pg1; /* First page of the sector pPg is located on. */
44120 int nPage = 0; /* Number of pages starting at pg1 to journal */
44121 int ii; /* Loop counter */
44122 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
44123
44124 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
44125 ** a journal header to be written between the pages journaled by
44126 ** this function.
44127 */
44128 assert( !MEMDB );
44129 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 );
44130 pPager->doNotSpill |= SPILLFLAG_NOSYNC;
44131
44132 /* This trick assumes that both the page-size and sector-size are
44133 ** an integer power of 2. It sets variable pg1 to the identifier
44134 ** of the first page of the sector pPg is located on.
44135 */
@@ -44150,12 +44184,12 @@
44184 sqlite3PagerUnref(pPage);
44185 }
44186 }
44187 }
44188
44189 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
44190 pPager->doNotSpill &= ~SPILLFLAG_NOSYNC;
44191 }else{
44192 rc = pager_write(pDbPage);
44193 }
44194 return rc;
44195 }
@@ -51727,21 +51761,18 @@
51761 ** there is a high probability of damage) Level 2 is the default. There
51762 ** is a very low but non-zero probability of damage. Level 3 reduces the
51763 ** probability of damage to near zero but with a write performance reduction.
51764 */
51765 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
51766 SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(
51767 Btree *p, /* The btree to set the safety level on */
51768 unsigned pgFlags /* Various PAGER_* flags */
 
 
51769 ){
51770 BtShared *pBt = p->pBt;
51771 assert( sqlite3_mutex_held(p->db->mutex) );
 
51772 sqlite3BtreeEnter(p);
51773 sqlite3PagerSetFlags(pBt->pPager, pgFlags);
51774 sqlite3BtreeLeave(p);
51775 return SQLITE_OK;
51776 }
51777 #endif
51778
@@ -71760,10 +71791,11 @@
71791 /* This is the only way out of this procedure. We have to
71792 ** release the mutexes on btrees that were acquired at the
71793 ** top. */
71794 vdbe_return:
71795 db->lastRowid = lastRowid;
71796 testcase( nVmStep>0 );
71797 p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
71798 sqlite3VdbeLeave(p);
71799 return rc;
71800
71801 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
@@ -81769,10 +81801,11 @@
81801 }
81802 pPager = sqlite3BtreePager(aNew->pBt);
81803 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
81804 sqlite3BtreeSecureDelete(aNew->pBt,
81805 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
81806 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
81807 }
81808 aNew->safety_level = 3;
81809 aNew->zName = sqlite3DbStrDup(db, zName);
81810 if( rc==SQLITE_OK && aNew->zName==0 ){
81811 rc = SQLITE_NOMEM;
@@ -85289,11 +85322,11 @@
85322
85323 /* Gather the complete text of the CREATE INDEX statement into
85324 ** the zStmt variable
85325 */
85326 if( pStart ){
85327 int n = (int)(pParse->sLastToken.z - pName->z) + pParse->sLastToken.n;
85328 if( pName->z[n-1]==';' ) n--;
85329 /* A named index with an explicit CREATE INDEX statement */
85330 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
85331 onError==OE_None ? "" : " UNIQUE", n, pName->z);
85332 }else{
@@ -93834,10 +93867,38 @@
93867 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
93868 sqlite3VdbeSetNumCols(v, 1);
93869 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
93870 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
93871 }
93872
93873
93874 /*
93875 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
93876 ** set these values for all pagers.
93877 */
93878 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
93879 static void setAllPagerFlags(sqlite3 *db){
93880 if( db->autoCommit ){
93881 Db *pDb = db->aDb;
93882 int n = db->nDb;
93883 assert( SQLITE_FullFSync==PAGER_FULLFSYNC );
93884 assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC );
93885 assert( SQLITE_CacheSpill==PAGER_CACHESPILL );
93886 assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL)
93887 == PAGER_FLAGS_MASK );
93888 assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level );
93889 while( (n--) > 0 ){
93890 if( pDb->pBt ){
93891 sqlite3BtreeSetPagerFlags(pDb->pBt,
93892 pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) );
93893 }
93894 pDb++;
93895 }
93896 }
93897 }
93898 #endif
93899
93900
93901 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
93902 /*
93903 ** Check to see if zRight and zLeft refer to a pragma that queries
93904 ** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
@@ -93853,10 +93914,11 @@
93914 { "count_changes", SQLITE_CountRows },
93915 { "empty_result_callbacks", SQLITE_NullCallback },
93916 { "legacy_file_format", SQLITE_LegacyFileFmt },
93917 { "fullfsync", SQLITE_FullFSync },
93918 { "checkpoint_fullfsync", SQLITE_CkptFullFSync },
93919 { "cache_spill", SQLITE_CacheSpill },
93920 { "reverse_unordered_selects", SQLITE_ReverseOrder },
93921 { "query_only", SQLITE_QueryOnly },
93922 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
93923 { "automatic_index", SQLITE_AutoIndex },
93924 #endif
@@ -94643,19 +94705,19 @@
94705 if( !db->autoCommit ){
94706 sqlite3ErrorMsg(pParse,
94707 "Safety level may not be changed inside a transaction");
94708 }else{
94709 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
94710 setAllPagerFlags(db);
94711 }
94712 }
94713 }else
94714 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
94715
94716 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
94717 if( flagPragma(pParse, zLeft, zRight) ){
94718 setAllPagerFlags(db);
 
94719 }else
94720 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
94721
94722 #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
94723 /*
@@ -95482,21 +95544,10 @@
95544 #endif
95545
95546
95547 {/* Empty ELSE clause */}
95548
 
 
 
 
 
 
 
 
 
 
 
95549 pragma_out:
95550 sqlite3DbFree(db, zLeft);
95551 sqlite3DbFree(db, zRight);
95552 }
95553
@@ -109541,10 +109592,11 @@
109592
109593 pWC = pBuilder->pWC;
109594 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
109595 pWCEnd = pWC->a + pWC->nTerm;
109596 pNew = pBuilder->pNew;
109597 memset(&sSum, 0, sizeof(sSum));
109598
109599 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
109600 if( (pTerm->eOperator & WO_OR)!=0
109601 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
109602 ){
@@ -117967,11 +118019,11 @@
118019 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
118020 db->autoCommit = 1;
118021 db->nextAutovac = -1;
118022 db->szMmap = sqlite3GlobalConfig.szMmap;
118023 db->nextPagesize = 0;
118024 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
118025 #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
118026 | SQLITE_AutoIndex
118027 #endif
118028 #if SQLITE_DEFAULT_FILE_FORMAT<4
118029 | SQLITE_LegacyFileFmt
118030
+1 -1
--- 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.0"
111111
#define SQLITE_VERSION_NUMBER 3008000
112
-#define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
112
+#define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- 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.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- 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.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

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