Fossil SCM

Update the built-in SQLite to include the latest changes, and especially the new auto-explain mode in the command-line shell.

drh 2016-02-09 20:16 trunk
Commit e00968a5a064861eac53d1cf697c36d8435a8ac7
3 files changed +93 -57 +12 -33 +1 -1
+93 -57
--- src/shell.c
+++ src/shell.c
@@ -590,10 +590,11 @@
590590
*/
591591
typedef struct ShellState ShellState;
592592
struct ShellState {
593593
sqlite3 *db; /* The database */
594594
int echoOn; /* True to echo input commands */
595
+ int autoExplain; /* Automatically turn on .explain mode */
595596
int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
596597
int statsOn; /* True to display memory stats before each finalize */
597598
int scanstatsOn; /* True to display scan stats before each finalize */
598599
int countChanges; /* True to display change counts */
599600
int backslashOn; /* Resolve C-style \x escapes in SQL input text */
@@ -601,10 +602,12 @@
601602
int cnt; /* Number of records displayed so far */
602603
FILE *out; /* Write results here */
603604
FILE *traceOut; /* Output for sqlite3_trace() */
604605
int nErr; /* Number of errors seen */
605606
int mode; /* An output mode setting */
607
+ int cMode; /* temporary output mode for the current query */
608
+ int normalMode; /* Output mode before ".explain on" */
606609
int writableSchema; /* True if PRAGMA writable_schema=ON */
607610
int showHeader; /* True to show column names in List or Column mode */
608611
unsigned shellFlgs; /* Various flags */
609612
char *zDestTable; /* Name of destination table when MODE_Insert */
610613
char colSeparator[20]; /* Column separator character for several modes */
@@ -611,11 +614,10 @@
611614
char rowSeparator[20]; /* Row separator character for MODE_Ascii */
612615
int colWidth[100]; /* Requested width of each column when in column mode*/
613616
int actualWidth[100]; /* Actual width of each column */
614617
char nullValue[20]; /* The text to print when a NULL comes back from
615618
** the database */
616
- SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
617619
char outfile[FILENAME_MAX]; /* Filename for *out */
618620
const char *zDbFilename; /* name of the database file */
619621
char *zFreeOnClose; /* Filename to free when closing */
620622
const char *zVfs; /* Name of VFS to use */
621623
sqlite3_stmt *pStmt; /* Current statement if any. */
@@ -880,11 +882,11 @@
880882
int *aiType /* Column types */
881883
){
882884
int i;
883885
ShellState *p = (ShellState*)pArg;
884886
885
- switch( p->mode ){
887
+ switch( p->cMode ){
886888
case MODE_Line: {
887889
int w = 5;
888890
if( azArg==0 ) break;
889891
for(i=0; i<nArg; i++){
890892
int len = strlen30(azCol[i] ? azCol[i] : "");
@@ -897,15 +899,28 @@
897899
}
898900
break;
899901
}
900902
case MODE_Explain:
901903
case MODE_Column: {
904
+ static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
905
+ const int *colWidth;
906
+ int showHdr;
907
+ char *rowSep;
908
+ if( p->cMode==MODE_Column ){
909
+ colWidth = p->colWidth;
910
+ showHdr = p->showHeader;
911
+ rowSep = p->rowSeparator;
912
+ }else{
913
+ colWidth = aExplainWidths;
914
+ showHdr = 1;
915
+ rowSep = "\n";
916
+ }
902917
if( p->cnt++==0 ){
903918
for(i=0; i<nArg; i++){
904919
int w, n;
905920
if( i<ArraySize(p->colWidth) ){
906
- w = p->colWidth[i];
921
+ w = colWidth[i];
907922
}else{
908923
w = 0;
909924
}
910925
if( w==0 ){
911926
w = strlen30(azCol[i] ? azCol[i] : "");
@@ -914,21 +929,21 @@
914929
if( w<n ) w = n;
915930
}
916931
if( i<ArraySize(p->actualWidth) ){
917932
p->actualWidth[i] = w;
918933
}
919
- if( p->showHeader ){
934
+ if( showHdr ){
920935
if( w<0 ){
921936
utf8_printf(p->out,"%*.*s%s",-w,-w,azCol[i],
922
- i==nArg-1 ? p->rowSeparator : " ");
937
+ i==nArg-1 ? rowSep : " ");
923938
}else{
924939
utf8_printf(p->out,"%-*.*s%s",w,w,azCol[i],
925
- i==nArg-1 ? p->rowSeparator : " ");
940
+ i==nArg-1 ? rowSep : " ");
926941
}
927942
}
928943
}
929
- if( p->showHeader ){
944
+ if( showHdr ){
930945
for(i=0; i<nArg; i++){
931946
int w;
932947
if( i<ArraySize(p->actualWidth) ){
933948
w = p->actualWidth[i];
934949
if( w<0 ) w = -w;
@@ -936,11 +951,11 @@
936951
w = 10;
937952
}
938953
utf8_printf(p->out,"%-*.*s%s",w,w,
939954
"----------------------------------------------------------"
940955
"----------------------------------------------------------",
941
- i==nArg-1 ? p->rowSeparator : " ");
956
+ i==nArg-1 ? rowSep : " ");
942957
}
943958
}
944959
}
945960
if( azArg==0 ) break;
946961
for(i=0; i<nArg; i++){
@@ -948,11 +963,11 @@
948963
if( i<ArraySize(p->actualWidth) ){
949964
w = p->actualWidth[i];
950965
}else{
951966
w = 10;
952967
}
953
- if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
968
+ if( p->cMode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
954969
w = strlen30(azArg[i]);
955970
}
956971
if( i==1 && p->aiIndent && p->pStmt ){
957972
if( p->iIndent<p->nIndent ){
958973
utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
@@ -960,15 +975,15 @@
960975
p->iIndent++;
961976
}
962977
if( w<0 ){
963978
utf8_printf(p->out,"%*.*s%s",-w,-w,
964979
azArg[i] ? azArg[i] : p->nullValue,
965
- i==nArg-1 ? p->rowSeparator : " ");
980
+ i==nArg-1 ? rowSep : " ");
966981
}else{
967982
utf8_printf(p->out,"%-*.*s%s",w,w,
968983
azArg[i] ? azArg[i] : p->nullValue,
969
- i==nArg-1 ? p->rowSeparator : " ");
984
+ i==nArg-1 ? rowSep : " ");
970985
}
971986
}
972987
break;
973988
}
974989
case MODE_Semi:
@@ -984,11 +999,11 @@
984999
char *z = azArg[i];
9851000
if( z==0 ) z = p->nullValue;
9861001
utf8_printf(p->out, "%s", z);
9871002
if( i<nArg-1 ){
9881003
utf8_printf(p->out, "%s", p->colSeparator);
989
- }else if( p->mode==MODE_Semi ){
1004
+ }else if( p->cMode==MODE_Semi ){
9901005
utf8_printf(p->out, ";%s", p->rowSeparator);
9911006
}else{
9921007
utf8_printf(p->out, "%s", p->rowSeparator);
9931008
}
9941009
}
@@ -1489,14 +1504,21 @@
14891504
"Rewind", 0 };
14901505
const char *azGoto[] = { "Goto", 0 };
14911506
14921507
/* Try to figure out if this is really an EXPLAIN statement. If this
14931508
** cannot be verified, return early. */
1509
+ if( sqlite3_column_count(pSql)!=8 ){
1510
+ p->cMode = p->mode;
1511
+ return;
1512
+ }
14941513
zSql = sqlite3_sql(pSql);
14951514
if( zSql==0 ) return;
14961515
for(z=zSql; *z==' ' || *z=='\t' || *z=='\n' || *z=='\f' || *z=='\r'; z++);
1497
- if( sqlite3_strnicmp(z, "explain", 7) ) return;
1516
+ if( sqlite3_strnicmp(z, "explain", 7) ){
1517
+ p->cMode = p->mode;
1518
+ return;
1519
+ }
14981520
14991521
for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
15001522
int i;
15011523
int iAddr = sqlite3_column_int(pSql, 0);
15021524
const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
@@ -1509,10 +1531,24 @@
15091531
int p2 = sqlite3_column_int(pSql, 3);
15101532
int p2op = (p2 + (iOp-iAddr));
15111533
15121534
/* Grow the p->aiIndent array as required */
15131535
if( iOp>=nAlloc ){
1536
+ if( iOp==0 ){
1537
+ /* Do further verfication that this is explain output. Abort if
1538
+ ** it is not */
1539
+ static const char *explainCols[] = {
1540
+ "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment" };
1541
+ int jj;
1542
+ for(jj=0; jj<ArraySize(explainCols); jj++){
1543
+ if( strcmp(sqlite3_column_name(pSql,jj),explainCols[jj])!=0 ){
1544
+ p->cMode = p->mode;
1545
+ sqlite3_reset(pSql);
1546
+ return;
1547
+ }
1548
+ }
1549
+ }
15141550
nAlloc += 100;
15151551
p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int));
15161552
abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int));
15171553
}
15181554
abYield[iOp] = str_in_array(zOp, azYield);
@@ -1612,14 +1648,24 @@
16121648
}
16131649
sqlite3_finalize(pExplain);
16141650
sqlite3_free(zEQP);
16151651
}
16161652
1617
- /* If the shell is currently in ".explain" mode, gather the extra
1618
- ** data required to add indents to the output.*/
1619
- if( pArg && pArg->mode==MODE_Explain ){
1620
- explain_data_prepare(pArg, pStmt);
1653
+ if( pArg ){
1654
+ pArg->cMode = pArg->mode;
1655
+ if( pArg->autoExplain
1656
+ && sqlite3_column_count(pStmt)==8
1657
+ && sqlite3_strlike("%EXPLAIN%", sqlite3_sql(pStmt),0)==0
1658
+ ){
1659
+ pArg->cMode = MODE_Explain;
1660
+ }
1661
+
1662
+ /* If the shell is currently in ".explain" mode, gather the extra
1663
+ ** data required to add indents to the output.*/
1664
+ if( pArg->cMode==MODE_Explain ){
1665
+ explain_data_prepare(pArg, pStmt);
1666
+ }
16211667
}
16221668
16231669
/* perform the first step. this will tell us if we
16241670
** have a result set or not and how wide it is.
16251671
*/
@@ -1645,11 +1691,11 @@
16451691
}
16461692
do{
16471693
/* extract the data and data types */
16481694
for(i=0; i<nCol; i++){
16491695
aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1650
- if( x==SQLITE_BLOB && pArg && pArg->mode==MODE_Insert ){
1696
+ if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
16511697
azVals[i] = "";
16521698
}else{
16531699
azVals[i] = (char*)sqlite3_column_text(pStmt, i);
16541700
}
16551701
if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
@@ -1865,12 +1911,11 @@
18651911
" If TABLE specified, only dump tables matching\n"
18661912
" LIKE pattern TABLE.\n"
18671913
".echo on|off Turn command echo on or off\n"
18681914
".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
18691915
".exit Exit this program\n"
1870
- ".explain ?on|off? Turn output mode suitable for EXPLAIN on or off.\n"
1871
- " With no args, it turns EXPLAIN on.\n"
1916
+ ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
18721917
".fullschema Show schema and the content of sqlite_stat tables\n"
18731918
".headers on|off Turn display of headers on or off\n"
18741919
".help Show this message\n"
18751920
".import FILE TABLE Import data from FILE into TABLE\n"
18761921
".indexes ?TABLE? Show names of all indexes\n"
@@ -2853,11 +2898,11 @@
28532898
ShellState data;
28542899
char *zErrMsg = 0;
28552900
open_db(p, 0);
28562901
memcpy(&data, p, sizeof(data));
28572902
data.showHeader = 1;
2858
- data.mode = MODE_Column;
2903
+ data.cMode = data.mode = MODE_Column;
28592904
data.colWidth[0] = 3;
28602905
data.colWidth[1] = 15;
28612906
data.colWidth[2] = 58;
28622907
data.cnt = 0;
28632908
sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
@@ -2948,41 +2993,28 @@
29482993
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
29492994
rc = 2;
29502995
}else
29512996
29522997
if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
2953
- int val = nArg>=2 ? booleanValue(azArg[1]) : 1;
2954
- if(val == 1) {
2955
- if(!p->normalMode.valid) {
2956
- p->normalMode.valid = 1;
2957
- p->normalMode.mode = p->mode;
2958
- p->normalMode.showHeader = p->showHeader;
2959
- memcpy(p->normalMode.colWidth,p->colWidth,sizeof(p->colWidth));
2960
- }
2961
- /* We could put this code under the !p->explainValid
2962
- ** condition so that it does not execute if we are already in
2963
- ** explain mode. However, always executing it allows us an easy
2964
- ** was to reset to explain mode in case the user previously
2965
- ** did an .explain followed by a .width, .mode or .header
2966
- ** command.
2967
- */
2998
+ int val = 1;
2999
+ if( nArg>=2 ){
3000
+ if( strcmp(azArg[1],"auto")==0 ){
3001
+ val = 99;
3002
+ }else{
3003
+ val = booleanValue(azArg[1]);
3004
+ }
3005
+ }
3006
+ if( val==1 && p->mode!=MODE_Explain ){
3007
+ p->normalMode = p->mode;
29683008
p->mode = MODE_Explain;
2969
- p->showHeader = 1;
2970
- memset(p->colWidth,0,sizeof(p->colWidth));
2971
- p->colWidth[0] = 4; /* addr */
2972
- p->colWidth[1] = 13; /* opcode */
2973
- p->colWidth[2] = 4; /* P1 */
2974
- p->colWidth[3] = 4; /* P2 */
2975
- p->colWidth[4] = 4; /* P3 */
2976
- p->colWidth[5] = 13; /* P4 */
2977
- p->colWidth[6] = 2; /* P5 */
2978
- p->colWidth[7] = 13; /* Comment */
2979
- }else if (p->normalMode.valid) {
2980
- p->normalMode.valid = 0;
2981
- p->mode = p->normalMode.mode;
2982
- p->showHeader = p->normalMode.showHeader;
2983
- memcpy(p->colWidth,p->normalMode.colWidth,sizeof(p->colWidth));
3009
+ p->autoExplain = 0;
3010
+ }else if( val==0 ){
3011
+ if( p->mode==MODE_Explain ) p->mode = p->normalMode;
3012
+ p->autoExplain = 0;
3013
+ }else if( val==99 ){
3014
+ if( p->mode==MODE_Explain ) p->mode = p->normalMode;
3015
+ p->autoExplain = 1;
29843016
}
29853017
}else
29863018
29873019
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
29883020
ShellState data;
@@ -2994,11 +3026,11 @@
29943026
goto meta_command_exit;
29953027
}
29963028
open_db(p, 0);
29973029
memcpy(&data, p, sizeof(data));
29983030
data.showHeader = 0;
2999
- data.mode = MODE_Semi;
3031
+ data.cMode = data.mode = MODE_Semi;
30003032
rc = sqlite3_exec(p->db,
30013033
"SELECT sql FROM"
30023034
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
30033035
" FROM sqlite_master UNION ALL"
30043036
" SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3019,11 +3051,11 @@
30193051
raw_printf(p->out, "/* No STAT tables available */\n");
30203052
}else{
30213053
raw_printf(p->out, "ANALYZE sqlite_master;\n");
30223054
sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
30233055
callback, &data, &zErrMsg);
3024
- data.mode = MODE_Insert;
3056
+ data.cMode = data.mode = MODE_Insert;
30253057
data.zDestTable = "sqlite_stat1";
30263058
shell_exec(p->db, "SELECT * FROM sqlite_stat1",
30273059
shell_callback, &data,&zErrMsg);
30283060
data.zDestTable = "sqlite_stat3";
30293061
shell_exec(p->db, "SELECT * FROM sqlite_stat3",
@@ -3251,11 +3283,11 @@
32513283
ShellState data;
32523284
char *zErrMsg = 0;
32533285
open_db(p, 0);
32543286
memcpy(&data, p, sizeof(data));
32553287
data.showHeader = 0;
3256
- data.mode = MODE_List;
3288
+ data.cMode = data.mode = MODE_List;
32573289
if( nArg==1 ){
32583290
rc = sqlite3_exec(p->db,
32593291
"SELECT name FROM sqlite_master "
32603292
"WHERE type='index' AND name NOT LIKE 'sqlite_%' "
32613293
"UNION ALL "
@@ -3437,10 +3469,11 @@
34373469
}else {
34383470
raw_printf(stderr, "Error: mode should be one of: "
34393471
"ascii column csv html insert line list tabs tcl\n");
34403472
rc = 1;
34413473
}
3474
+ p->cMode = p->mode;
34423475
}else
34433476
34443477
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
34453478
if( nArg==2 ){
34463479
sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
@@ -3626,11 +3659,11 @@
36263659
ShellState data;
36273660
char *zErrMsg = 0;
36283661
open_db(p, 0);
36293662
memcpy(&data, p, sizeof(data));
36303663
data.showHeader = 0;
3631
- data.mode = MODE_Semi;
3664
+ data.cMode = data.mode = MODE_Semi;
36323665
if( nArg==2 ){
36333666
int i;
36343667
for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
36353668
if( strcmp(azArg[1],"sqlite_master")==0 ){
36363669
char *new_argv[2], *new_colv[2];
@@ -3774,11 +3807,12 @@
37743807
rc = 1;
37753808
goto meta_command_exit;
37763809
}
37773810
utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
37783811
utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3779
- utf8_printf(p->out,"%9.9s: %s\n","explain",p->normalMode.valid?"on":"off");
3812
+ utf8_printf(p->out, "%12.12s: %s\n","explain",
3813
+ p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
37803814
utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
37813815
utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
37823816
utf8_printf(p->out, "%12.12s: ", "nullvalue");
37833817
output_c_string(p->out, p->nullValue);
37843818
raw_printf(p->out, "\n");
@@ -4573,11 +4607,12 @@
45734607
/*
45744608
** Initialize the state information in data
45754609
*/
45764610
static void main_init(ShellState *data) {
45774611
memset(data, 0, sizeof(*data));
4578
- data->mode = MODE_List;
4612
+ data->normalMode = data->cMode = data->mode = MODE_List;
4613
+ data->autoExplain = 1;
45794614
memcpy(data->colSeparator,SEP_Column, 2);
45804615
memcpy(data->rowSeparator,SEP_Row, 2);
45814616
data->showHeader = 0;
45824617
data->shellFlgs = SHFLG_Lookaside;
45834618
sqlite3_config(SQLITE_CONFIG_URI, 1);
@@ -4906,10 +4941,11 @@
49064941
}else{
49074942
utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
49084943
raw_printf(stderr,"Use -help for a list of options.\n");
49094944
return 1;
49104945
}
4946
+ data.cMode = data.mode;
49114947
}
49124948
49134949
if( !readStdin ){
49144950
/* Run all arguments that do not begin with '-' as if they were separate
49154951
** command-line inputs, except for the argToSkip argument which contains
49164952
--- src/shell.c
+++ src/shell.c
@@ -590,10 +590,11 @@
590 */
591 typedef struct ShellState ShellState;
592 struct ShellState {
593 sqlite3 *db; /* The database */
594 int echoOn; /* True to echo input commands */
 
595 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
596 int statsOn; /* True to display memory stats before each finalize */
597 int scanstatsOn; /* True to display scan stats before each finalize */
598 int countChanges; /* True to display change counts */
599 int backslashOn; /* Resolve C-style \x escapes in SQL input text */
@@ -601,10 +602,12 @@
601 int cnt; /* Number of records displayed so far */
602 FILE *out; /* Write results here */
603 FILE *traceOut; /* Output for sqlite3_trace() */
604 int nErr; /* Number of errors seen */
605 int mode; /* An output mode setting */
 
 
606 int writableSchema; /* True if PRAGMA writable_schema=ON */
607 int showHeader; /* True to show column names in List or Column mode */
608 unsigned shellFlgs; /* Various flags */
609 char *zDestTable; /* Name of destination table when MODE_Insert */
610 char colSeparator[20]; /* Column separator character for several modes */
@@ -611,11 +614,10 @@
611 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
612 int colWidth[100]; /* Requested width of each column when in column mode*/
613 int actualWidth[100]; /* Actual width of each column */
614 char nullValue[20]; /* The text to print when a NULL comes back from
615 ** the database */
616 SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
617 char outfile[FILENAME_MAX]; /* Filename for *out */
618 const char *zDbFilename; /* name of the database file */
619 char *zFreeOnClose; /* Filename to free when closing */
620 const char *zVfs; /* Name of VFS to use */
621 sqlite3_stmt *pStmt; /* Current statement if any. */
@@ -880,11 +882,11 @@
880 int *aiType /* Column types */
881 ){
882 int i;
883 ShellState *p = (ShellState*)pArg;
884
885 switch( p->mode ){
886 case MODE_Line: {
887 int w = 5;
888 if( azArg==0 ) break;
889 for(i=0; i<nArg; i++){
890 int len = strlen30(azCol[i] ? azCol[i] : "");
@@ -897,15 +899,28 @@
897 }
898 break;
899 }
900 case MODE_Explain:
901 case MODE_Column: {
 
 
 
 
 
 
 
 
 
 
 
 
 
902 if( p->cnt++==0 ){
903 for(i=0; i<nArg; i++){
904 int w, n;
905 if( i<ArraySize(p->colWidth) ){
906 w = p->colWidth[i];
907 }else{
908 w = 0;
909 }
910 if( w==0 ){
911 w = strlen30(azCol[i] ? azCol[i] : "");
@@ -914,21 +929,21 @@
914 if( w<n ) w = n;
915 }
916 if( i<ArraySize(p->actualWidth) ){
917 p->actualWidth[i] = w;
918 }
919 if( p->showHeader ){
920 if( w<0 ){
921 utf8_printf(p->out,"%*.*s%s",-w,-w,azCol[i],
922 i==nArg-1 ? p->rowSeparator : " ");
923 }else{
924 utf8_printf(p->out,"%-*.*s%s",w,w,azCol[i],
925 i==nArg-1 ? p->rowSeparator : " ");
926 }
927 }
928 }
929 if( p->showHeader ){
930 for(i=0; i<nArg; i++){
931 int w;
932 if( i<ArraySize(p->actualWidth) ){
933 w = p->actualWidth[i];
934 if( w<0 ) w = -w;
@@ -936,11 +951,11 @@
936 w = 10;
937 }
938 utf8_printf(p->out,"%-*.*s%s",w,w,
939 "----------------------------------------------------------"
940 "----------------------------------------------------------",
941 i==nArg-1 ? p->rowSeparator : " ");
942 }
943 }
944 }
945 if( azArg==0 ) break;
946 for(i=0; i<nArg; i++){
@@ -948,11 +963,11 @@
948 if( i<ArraySize(p->actualWidth) ){
949 w = p->actualWidth[i];
950 }else{
951 w = 10;
952 }
953 if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
954 w = strlen30(azArg[i]);
955 }
956 if( i==1 && p->aiIndent && p->pStmt ){
957 if( p->iIndent<p->nIndent ){
958 utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
@@ -960,15 +975,15 @@
960 p->iIndent++;
961 }
962 if( w<0 ){
963 utf8_printf(p->out,"%*.*s%s",-w,-w,
964 azArg[i] ? azArg[i] : p->nullValue,
965 i==nArg-1 ? p->rowSeparator : " ");
966 }else{
967 utf8_printf(p->out,"%-*.*s%s",w,w,
968 azArg[i] ? azArg[i] : p->nullValue,
969 i==nArg-1 ? p->rowSeparator : " ");
970 }
971 }
972 break;
973 }
974 case MODE_Semi:
@@ -984,11 +999,11 @@
984 char *z = azArg[i];
985 if( z==0 ) z = p->nullValue;
986 utf8_printf(p->out, "%s", z);
987 if( i<nArg-1 ){
988 utf8_printf(p->out, "%s", p->colSeparator);
989 }else if( p->mode==MODE_Semi ){
990 utf8_printf(p->out, ";%s", p->rowSeparator);
991 }else{
992 utf8_printf(p->out, "%s", p->rowSeparator);
993 }
994 }
@@ -1489,14 +1504,21 @@
1489 "Rewind", 0 };
1490 const char *azGoto[] = { "Goto", 0 };
1491
1492 /* Try to figure out if this is really an EXPLAIN statement. If this
1493 ** cannot be verified, return early. */
 
 
 
 
1494 zSql = sqlite3_sql(pSql);
1495 if( zSql==0 ) return;
1496 for(z=zSql; *z==' ' || *z=='\t' || *z=='\n' || *z=='\f' || *z=='\r'; z++);
1497 if( sqlite3_strnicmp(z, "explain", 7) ) return;
 
 
 
1498
1499 for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
1500 int i;
1501 int iAddr = sqlite3_column_int(pSql, 0);
1502 const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
@@ -1509,10 +1531,24 @@
1509 int p2 = sqlite3_column_int(pSql, 3);
1510 int p2op = (p2 + (iOp-iAddr));
1511
1512 /* Grow the p->aiIndent array as required */
1513 if( iOp>=nAlloc ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1514 nAlloc += 100;
1515 p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int));
1516 abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int));
1517 }
1518 abYield[iOp] = str_in_array(zOp, azYield);
@@ -1612,14 +1648,24 @@
1612 }
1613 sqlite3_finalize(pExplain);
1614 sqlite3_free(zEQP);
1615 }
1616
1617 /* If the shell is currently in ".explain" mode, gather the extra
1618 ** data required to add indents to the output.*/
1619 if( pArg && pArg->mode==MODE_Explain ){
1620 explain_data_prepare(pArg, pStmt);
 
 
 
 
 
 
 
 
 
 
1621 }
1622
1623 /* perform the first step. this will tell us if we
1624 ** have a result set or not and how wide it is.
1625 */
@@ -1645,11 +1691,11 @@
1645 }
1646 do{
1647 /* extract the data and data types */
1648 for(i=0; i<nCol; i++){
1649 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1650 if( x==SQLITE_BLOB && pArg && pArg->mode==MODE_Insert ){
1651 azVals[i] = "";
1652 }else{
1653 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1654 }
1655 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
@@ -1865,12 +1911,11 @@
1865 " If TABLE specified, only dump tables matching\n"
1866 " LIKE pattern TABLE.\n"
1867 ".echo on|off Turn command echo on or off\n"
1868 ".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
1869 ".exit Exit this program\n"
1870 ".explain ?on|off? Turn output mode suitable for EXPLAIN on or off.\n"
1871 " With no args, it turns EXPLAIN on.\n"
1872 ".fullschema Show schema and the content of sqlite_stat tables\n"
1873 ".headers on|off Turn display of headers on or off\n"
1874 ".help Show this message\n"
1875 ".import FILE TABLE Import data from FILE into TABLE\n"
1876 ".indexes ?TABLE? Show names of all indexes\n"
@@ -2853,11 +2898,11 @@
2853 ShellState data;
2854 char *zErrMsg = 0;
2855 open_db(p, 0);
2856 memcpy(&data, p, sizeof(data));
2857 data.showHeader = 1;
2858 data.mode = MODE_Column;
2859 data.colWidth[0] = 3;
2860 data.colWidth[1] = 15;
2861 data.colWidth[2] = 58;
2862 data.cnt = 0;
2863 sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
@@ -2948,41 +2993,28 @@
2948 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2949 rc = 2;
2950 }else
2951
2952 if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
2953 int val = nArg>=2 ? booleanValue(azArg[1]) : 1;
2954 if(val == 1) {
2955 if(!p->normalMode.valid) {
2956 p->normalMode.valid = 1;
2957 p->normalMode.mode = p->mode;
2958 p->normalMode.showHeader = p->showHeader;
2959 memcpy(p->normalMode.colWidth,p->colWidth,sizeof(p->colWidth));
2960 }
2961 /* We could put this code under the !p->explainValid
2962 ** condition so that it does not execute if we are already in
2963 ** explain mode. However, always executing it allows us an easy
2964 ** was to reset to explain mode in case the user previously
2965 ** did an .explain followed by a .width, .mode or .header
2966 ** command.
2967 */
2968 p->mode = MODE_Explain;
2969 p->showHeader = 1;
2970 memset(p->colWidth,0,sizeof(p->colWidth));
2971 p->colWidth[0] = 4; /* addr */
2972 p->colWidth[1] = 13; /* opcode */
2973 p->colWidth[2] = 4; /* P1 */
2974 p->colWidth[3] = 4; /* P2 */
2975 p->colWidth[4] = 4; /* P3 */
2976 p->colWidth[5] = 13; /* P4 */
2977 p->colWidth[6] = 2; /* P5 */
2978 p->colWidth[7] = 13; /* Comment */
2979 }else if (p->normalMode.valid) {
2980 p->normalMode.valid = 0;
2981 p->mode = p->normalMode.mode;
2982 p->showHeader = p->normalMode.showHeader;
2983 memcpy(p->colWidth,p->normalMode.colWidth,sizeof(p->colWidth));
2984 }
2985 }else
2986
2987 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
2988 ShellState data;
@@ -2994,11 +3026,11 @@
2994 goto meta_command_exit;
2995 }
2996 open_db(p, 0);
2997 memcpy(&data, p, sizeof(data));
2998 data.showHeader = 0;
2999 data.mode = MODE_Semi;
3000 rc = sqlite3_exec(p->db,
3001 "SELECT sql FROM"
3002 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
3003 " FROM sqlite_master UNION ALL"
3004 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3019,11 +3051,11 @@
3019 raw_printf(p->out, "/* No STAT tables available */\n");
3020 }else{
3021 raw_printf(p->out, "ANALYZE sqlite_master;\n");
3022 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
3023 callback, &data, &zErrMsg);
3024 data.mode = MODE_Insert;
3025 data.zDestTable = "sqlite_stat1";
3026 shell_exec(p->db, "SELECT * FROM sqlite_stat1",
3027 shell_callback, &data,&zErrMsg);
3028 data.zDestTable = "sqlite_stat3";
3029 shell_exec(p->db, "SELECT * FROM sqlite_stat3",
@@ -3251,11 +3283,11 @@
3251 ShellState data;
3252 char *zErrMsg = 0;
3253 open_db(p, 0);
3254 memcpy(&data, p, sizeof(data));
3255 data.showHeader = 0;
3256 data.mode = MODE_List;
3257 if( nArg==1 ){
3258 rc = sqlite3_exec(p->db,
3259 "SELECT name FROM sqlite_master "
3260 "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
3261 "UNION ALL "
@@ -3437,10 +3469,11 @@
3437 }else {
3438 raw_printf(stderr, "Error: mode should be one of: "
3439 "ascii column csv html insert line list tabs tcl\n");
3440 rc = 1;
3441 }
 
3442 }else
3443
3444 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
3445 if( nArg==2 ){
3446 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
@@ -3626,11 +3659,11 @@
3626 ShellState data;
3627 char *zErrMsg = 0;
3628 open_db(p, 0);
3629 memcpy(&data, p, sizeof(data));
3630 data.showHeader = 0;
3631 data.mode = MODE_Semi;
3632 if( nArg==2 ){
3633 int i;
3634 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
3635 if( strcmp(azArg[1],"sqlite_master")==0 ){
3636 char *new_argv[2], *new_colv[2];
@@ -3774,11 +3807,12 @@
3774 rc = 1;
3775 goto meta_command_exit;
3776 }
3777 utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3778 utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3779 utf8_printf(p->out,"%9.9s: %s\n","explain",p->normalMode.valid?"on":"off");
 
3780 utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3781 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
3782 utf8_printf(p->out, "%12.12s: ", "nullvalue");
3783 output_c_string(p->out, p->nullValue);
3784 raw_printf(p->out, "\n");
@@ -4573,11 +4607,12 @@
4573 /*
4574 ** Initialize the state information in data
4575 */
4576 static void main_init(ShellState *data) {
4577 memset(data, 0, sizeof(*data));
4578 data->mode = MODE_List;
 
4579 memcpy(data->colSeparator,SEP_Column, 2);
4580 memcpy(data->rowSeparator,SEP_Row, 2);
4581 data->showHeader = 0;
4582 data->shellFlgs = SHFLG_Lookaside;
4583 sqlite3_config(SQLITE_CONFIG_URI, 1);
@@ -4906,10 +4941,11 @@
4906 }else{
4907 utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
4908 raw_printf(stderr,"Use -help for a list of options.\n");
4909 return 1;
4910 }
 
4911 }
4912
4913 if( !readStdin ){
4914 /* Run all arguments that do not begin with '-' as if they were separate
4915 ** command-line inputs, except for the argToSkip argument which contains
4916
--- src/shell.c
+++ src/shell.c
@@ -590,10 +590,11 @@
590 */
591 typedef struct ShellState ShellState;
592 struct ShellState {
593 sqlite3 *db; /* The database */
594 int echoOn; /* True to echo input commands */
595 int autoExplain; /* Automatically turn on .explain mode */
596 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
597 int statsOn; /* True to display memory stats before each finalize */
598 int scanstatsOn; /* True to display scan stats before each finalize */
599 int countChanges; /* True to display change counts */
600 int backslashOn; /* Resolve C-style \x escapes in SQL input text */
@@ -601,10 +602,12 @@
602 int cnt; /* Number of records displayed so far */
603 FILE *out; /* Write results here */
604 FILE *traceOut; /* Output for sqlite3_trace() */
605 int nErr; /* Number of errors seen */
606 int mode; /* An output mode setting */
607 int cMode; /* temporary output mode for the current query */
608 int normalMode; /* Output mode before ".explain on" */
609 int writableSchema; /* True if PRAGMA writable_schema=ON */
610 int showHeader; /* True to show column names in List or Column mode */
611 unsigned shellFlgs; /* Various flags */
612 char *zDestTable; /* Name of destination table when MODE_Insert */
613 char colSeparator[20]; /* Column separator character for several modes */
@@ -611,11 +614,10 @@
614 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
615 int colWidth[100]; /* Requested width of each column when in column mode*/
616 int actualWidth[100]; /* Actual width of each column */
617 char nullValue[20]; /* The text to print when a NULL comes back from
618 ** the database */
 
619 char outfile[FILENAME_MAX]; /* Filename for *out */
620 const char *zDbFilename; /* name of the database file */
621 char *zFreeOnClose; /* Filename to free when closing */
622 const char *zVfs; /* Name of VFS to use */
623 sqlite3_stmt *pStmt; /* Current statement if any. */
@@ -880,11 +882,11 @@
882 int *aiType /* Column types */
883 ){
884 int i;
885 ShellState *p = (ShellState*)pArg;
886
887 switch( p->cMode ){
888 case MODE_Line: {
889 int w = 5;
890 if( azArg==0 ) break;
891 for(i=0; i<nArg; i++){
892 int len = strlen30(azCol[i] ? azCol[i] : "");
@@ -897,15 +899,28 @@
899 }
900 break;
901 }
902 case MODE_Explain:
903 case MODE_Column: {
904 static const int aExplainWidths[] = {4, 13, 4, 4, 4, 13, 2, 13};
905 const int *colWidth;
906 int showHdr;
907 char *rowSep;
908 if( p->cMode==MODE_Column ){
909 colWidth = p->colWidth;
910 showHdr = p->showHeader;
911 rowSep = p->rowSeparator;
912 }else{
913 colWidth = aExplainWidths;
914 showHdr = 1;
915 rowSep = "\n";
916 }
917 if( p->cnt++==0 ){
918 for(i=0; i<nArg; i++){
919 int w, n;
920 if( i<ArraySize(p->colWidth) ){
921 w = colWidth[i];
922 }else{
923 w = 0;
924 }
925 if( w==0 ){
926 w = strlen30(azCol[i] ? azCol[i] : "");
@@ -914,21 +929,21 @@
929 if( w<n ) w = n;
930 }
931 if( i<ArraySize(p->actualWidth) ){
932 p->actualWidth[i] = w;
933 }
934 if( showHdr ){
935 if( w<0 ){
936 utf8_printf(p->out,"%*.*s%s",-w,-w,azCol[i],
937 i==nArg-1 ? rowSep : " ");
938 }else{
939 utf8_printf(p->out,"%-*.*s%s",w,w,azCol[i],
940 i==nArg-1 ? rowSep : " ");
941 }
942 }
943 }
944 if( showHdr ){
945 for(i=0; i<nArg; i++){
946 int w;
947 if( i<ArraySize(p->actualWidth) ){
948 w = p->actualWidth[i];
949 if( w<0 ) w = -w;
@@ -936,11 +951,11 @@
951 w = 10;
952 }
953 utf8_printf(p->out,"%-*.*s%s",w,w,
954 "----------------------------------------------------------"
955 "----------------------------------------------------------",
956 i==nArg-1 ? rowSep : " ");
957 }
958 }
959 }
960 if( azArg==0 ) break;
961 for(i=0; i<nArg; i++){
@@ -948,11 +963,11 @@
963 if( i<ArraySize(p->actualWidth) ){
964 w = p->actualWidth[i];
965 }else{
966 w = 10;
967 }
968 if( p->cMode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
969 w = strlen30(azArg[i]);
970 }
971 if( i==1 && p->aiIndent && p->pStmt ){
972 if( p->iIndent<p->nIndent ){
973 utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
@@ -960,15 +975,15 @@
975 p->iIndent++;
976 }
977 if( w<0 ){
978 utf8_printf(p->out,"%*.*s%s",-w,-w,
979 azArg[i] ? azArg[i] : p->nullValue,
980 i==nArg-1 ? rowSep : " ");
981 }else{
982 utf8_printf(p->out,"%-*.*s%s",w,w,
983 azArg[i] ? azArg[i] : p->nullValue,
984 i==nArg-1 ? rowSep : " ");
985 }
986 }
987 break;
988 }
989 case MODE_Semi:
@@ -984,11 +999,11 @@
999 char *z = azArg[i];
1000 if( z==0 ) z = p->nullValue;
1001 utf8_printf(p->out, "%s", z);
1002 if( i<nArg-1 ){
1003 utf8_printf(p->out, "%s", p->colSeparator);
1004 }else if( p->cMode==MODE_Semi ){
1005 utf8_printf(p->out, ";%s", p->rowSeparator);
1006 }else{
1007 utf8_printf(p->out, "%s", p->rowSeparator);
1008 }
1009 }
@@ -1489,14 +1504,21 @@
1504 "Rewind", 0 };
1505 const char *azGoto[] = { "Goto", 0 };
1506
1507 /* Try to figure out if this is really an EXPLAIN statement. If this
1508 ** cannot be verified, return early. */
1509 if( sqlite3_column_count(pSql)!=8 ){
1510 p->cMode = p->mode;
1511 return;
1512 }
1513 zSql = sqlite3_sql(pSql);
1514 if( zSql==0 ) return;
1515 for(z=zSql; *z==' ' || *z=='\t' || *z=='\n' || *z=='\f' || *z=='\r'; z++);
1516 if( sqlite3_strnicmp(z, "explain", 7) ){
1517 p->cMode = p->mode;
1518 return;
1519 }
1520
1521 for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
1522 int i;
1523 int iAddr = sqlite3_column_int(pSql, 0);
1524 const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
@@ -1509,10 +1531,24 @@
1531 int p2 = sqlite3_column_int(pSql, 3);
1532 int p2op = (p2 + (iOp-iAddr));
1533
1534 /* Grow the p->aiIndent array as required */
1535 if( iOp>=nAlloc ){
1536 if( iOp==0 ){
1537 /* Do further verfication that this is explain output. Abort if
1538 ** it is not */
1539 static const char *explainCols[] = {
1540 "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment" };
1541 int jj;
1542 for(jj=0; jj<ArraySize(explainCols); jj++){
1543 if( strcmp(sqlite3_column_name(pSql,jj),explainCols[jj])!=0 ){
1544 p->cMode = p->mode;
1545 sqlite3_reset(pSql);
1546 return;
1547 }
1548 }
1549 }
1550 nAlloc += 100;
1551 p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int));
1552 abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int));
1553 }
1554 abYield[iOp] = str_in_array(zOp, azYield);
@@ -1612,14 +1648,24 @@
1648 }
1649 sqlite3_finalize(pExplain);
1650 sqlite3_free(zEQP);
1651 }
1652
1653 if( pArg ){
1654 pArg->cMode = pArg->mode;
1655 if( pArg->autoExplain
1656 && sqlite3_column_count(pStmt)==8
1657 && sqlite3_strlike("%EXPLAIN%", sqlite3_sql(pStmt),0)==0
1658 ){
1659 pArg->cMode = MODE_Explain;
1660 }
1661
1662 /* If the shell is currently in ".explain" mode, gather the extra
1663 ** data required to add indents to the output.*/
1664 if( pArg->cMode==MODE_Explain ){
1665 explain_data_prepare(pArg, pStmt);
1666 }
1667 }
1668
1669 /* perform the first step. this will tell us if we
1670 ** have a result set or not and how wide it is.
1671 */
@@ -1645,11 +1691,11 @@
1691 }
1692 do{
1693 /* extract the data and data types */
1694 for(i=0; i<nCol; i++){
1695 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1696 if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1697 azVals[i] = "";
1698 }else{
1699 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1700 }
1701 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
@@ -1865,12 +1911,11 @@
1911 " If TABLE specified, only dump tables matching\n"
1912 " LIKE pattern TABLE.\n"
1913 ".echo on|off Turn command echo on or off\n"
1914 ".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
1915 ".exit Exit this program\n"
1916 ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
 
1917 ".fullschema Show schema and the content of sqlite_stat tables\n"
1918 ".headers on|off Turn display of headers on or off\n"
1919 ".help Show this message\n"
1920 ".import FILE TABLE Import data from FILE into TABLE\n"
1921 ".indexes ?TABLE? Show names of all indexes\n"
@@ -2853,11 +2898,11 @@
2898 ShellState data;
2899 char *zErrMsg = 0;
2900 open_db(p, 0);
2901 memcpy(&data, p, sizeof(data));
2902 data.showHeader = 1;
2903 data.cMode = data.mode = MODE_Column;
2904 data.colWidth[0] = 3;
2905 data.colWidth[1] = 15;
2906 data.colWidth[2] = 58;
2907 data.cnt = 0;
2908 sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
@@ -2948,41 +2993,28 @@
2993 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2994 rc = 2;
2995 }else
2996
2997 if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
2998 int val = 1;
2999 if( nArg>=2 ){
3000 if( strcmp(azArg[1],"auto")==0 ){
3001 val = 99;
3002 }else{
3003 val = booleanValue(azArg[1]);
3004 }
3005 }
3006 if( val==1 && p->mode!=MODE_Explain ){
3007 p->normalMode = p->mode;
 
 
 
 
 
3008 p->mode = MODE_Explain;
3009 p->autoExplain = 0;
3010 }else if( val==0 ){
3011 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
3012 p->autoExplain = 0;
3013 }else if( val==99 ){
3014 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
3015 p->autoExplain = 1;
 
 
 
 
 
 
 
 
3016 }
3017 }else
3018
3019 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
3020 ShellState data;
@@ -2994,11 +3026,11 @@
3026 goto meta_command_exit;
3027 }
3028 open_db(p, 0);
3029 memcpy(&data, p, sizeof(data));
3030 data.showHeader = 0;
3031 data.cMode = data.mode = MODE_Semi;
3032 rc = sqlite3_exec(p->db,
3033 "SELECT sql FROM"
3034 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
3035 " FROM sqlite_master UNION ALL"
3036 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3019,11 +3051,11 @@
3051 raw_printf(p->out, "/* No STAT tables available */\n");
3052 }else{
3053 raw_printf(p->out, "ANALYZE sqlite_master;\n");
3054 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
3055 callback, &data, &zErrMsg);
3056 data.cMode = data.mode = MODE_Insert;
3057 data.zDestTable = "sqlite_stat1";
3058 shell_exec(p->db, "SELECT * FROM sqlite_stat1",
3059 shell_callback, &data,&zErrMsg);
3060 data.zDestTable = "sqlite_stat3";
3061 shell_exec(p->db, "SELECT * FROM sqlite_stat3",
@@ -3251,11 +3283,11 @@
3283 ShellState data;
3284 char *zErrMsg = 0;
3285 open_db(p, 0);
3286 memcpy(&data, p, sizeof(data));
3287 data.showHeader = 0;
3288 data.cMode = data.mode = MODE_List;
3289 if( nArg==1 ){
3290 rc = sqlite3_exec(p->db,
3291 "SELECT name FROM sqlite_master "
3292 "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
3293 "UNION ALL "
@@ -3437,10 +3469,11 @@
3469 }else {
3470 raw_printf(stderr, "Error: mode should be one of: "
3471 "ascii column csv html insert line list tabs tcl\n");
3472 rc = 1;
3473 }
3474 p->cMode = p->mode;
3475 }else
3476
3477 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
3478 if( nArg==2 ){
3479 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
@@ -3626,11 +3659,11 @@
3659 ShellState data;
3660 char *zErrMsg = 0;
3661 open_db(p, 0);
3662 memcpy(&data, p, sizeof(data));
3663 data.showHeader = 0;
3664 data.cMode = data.mode = MODE_Semi;
3665 if( nArg==2 ){
3666 int i;
3667 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
3668 if( strcmp(azArg[1],"sqlite_master")==0 ){
3669 char *new_argv[2], *new_colv[2];
@@ -3774,11 +3807,12 @@
3807 rc = 1;
3808 goto meta_command_exit;
3809 }
3810 utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3811 utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3812 utf8_printf(p->out, "%12.12s: %s\n","explain",
3813 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
3814 utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3815 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
3816 utf8_printf(p->out, "%12.12s: ", "nullvalue");
3817 output_c_string(p->out, p->nullValue);
3818 raw_printf(p->out, "\n");
@@ -4573,11 +4607,12 @@
4607 /*
4608 ** Initialize the state information in data
4609 */
4610 static void main_init(ShellState *data) {
4611 memset(data, 0, sizeof(*data));
4612 data->normalMode = data->cMode = data->mode = MODE_List;
4613 data->autoExplain = 1;
4614 memcpy(data->colSeparator,SEP_Column, 2);
4615 memcpy(data->rowSeparator,SEP_Row, 2);
4616 data->showHeader = 0;
4617 data->shellFlgs = SHFLG_Lookaside;
4618 sqlite3_config(SQLITE_CONFIG_URI, 1);
@@ -4906,10 +4941,11 @@
4941 }else{
4942 utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
4943 raw_printf(stderr,"Use -help for a list of options.\n");
4944 return 1;
4945 }
4946 data.cMode = data.mode;
4947 }
4948
4949 if( !readStdin ){
4950 /* Run all arguments that do not begin with '-' as if they were separate
4951 ** command-line inputs, except for the argToSkip argument which contains
4952
+12 -33
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -328,11 +328,11 @@
328328
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
329329
** [sqlite_version()] and [sqlite_source_id()].
330330
*/
331331
#define SQLITE_VERSION "3.11.0"
332332
#define SQLITE_VERSION_NUMBER 3011000
333
-#define SQLITE_SOURCE_ID "2016-02-09 02:12:20 ca72be8618e5d466d6f35819ca8bbd2b84269959"
333
+#define SQLITE_SOURCE_ID "2016-02-09 20:11:14 751915cb7e4981661a40dc5e4d029ab27434c2d9"
334334
335335
/*
336336
** CAPI3REF: Run-Time Library Version Numbers
337337
** KEYWORDS: sqlite3_version, sqlite3_sourceid
338338
**
@@ -14651,11 +14651,10 @@
1465114651
SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
1465214652
SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
1465314653
SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
1465414654
SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
1465514655
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
14656
-SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
1465714656
SQLITE_PRIVATE void sqlite3SchemaClear(void *);
1465814657
SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
1465914658
SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
1466014659
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
1466114660
SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
@@ -91282,37 +91281,10 @@
9128291281
sqlite3SrcListDelete(db, pSrc);
9128391282
sqlite3DbFree(db, zName);
9128491283
db->flags = savedDbFlags;
9128591284
}
9128691285
91287
-
91288
-/*
91289
-** Generate code to make sure the file format number is at least minFormat.
91290
-** The generated code will increase the file format number if necessary.
91291
-*/
91292
-SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){
91293
- Vdbe *v;
91294
- v = sqlite3GetVdbe(pParse);
91295
- /* The VDBE should have been allocated before this routine is called.
91296
- ** If that allocation failed, we would have quit before reaching this
91297
- ** point */
91298
- if( ALWAYS(v) ){
91299
- int r1 = sqlite3GetTempReg(pParse);
91300
- int r2 = sqlite3GetTempReg(pParse);
91301
- int addr1;
91302
- sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
91303
- sqlite3VdbeUsesBtree(v, iDb);
91304
- sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
91305
- addr1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
91306
- sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
91307
- sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, minFormat);
91308
- sqlite3VdbeJumpHere(v, addr1);
91309
- sqlite3ReleaseTempReg(pParse, r1);
91310
- sqlite3ReleaseTempReg(pParse, r2);
91311
- }
91312
-}
91313
-
9131491286
/*
9131591287
** This function is called after an "ALTER TABLE ... ADD" statement
9131691288
** has been parsed. Argument pColDef contains the text of the new
9131791289
** column definition.
9131891290
**
@@ -91327,13 +91299,15 @@
9132791299
const char *zTab; /* Table name */
9132891300
char *zCol; /* Null-terminated column definition */
9132991301
Column *pCol; /* The new column */
9133091302
Expr *pDflt; /* Default value for the new column */
9133191303
sqlite3 *db; /* The database connection; */
91304
+ Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */
9133291305
9133391306
db = pParse->db;
9133491307
if( pParse->nErr || db->mallocFailed ) return;
91308
+ assert( v!=0 );
9133591309
pNew = pParse->pNewTable;
9133691310
assert( pNew );
9133791311
9133891312
assert( sqlite3BtreeHoldsAllMutexes(db) );
9133991313
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -91419,15 +91393,20 @@
9141991393
);
9142091394
sqlite3DbFree(db, zCol);
9142191395
db->flags = savedDbFlags;
9142291396
}
9142391397
91424
- /* If the default value of the new column is NULL, then set the file
91398
+ /* If the default value of the new column is NULL, then the file
9142591399
** format to 2. If the default value of the new column is not NULL,
91426
- ** the file format becomes 3.
91400
+ ** the file format be 3. Back when this feature was first added
91401
+ ** in 2006, we went to the trouble to upgrade the file format to the
91402
+ ** minimum support values. But 10-years on, we can assume that all
91403
+ ** extent versions of SQLite support file-format 4, so we always and
91404
+ ** unconditionally upgrade to 4.
9142791405
*/
91428
- sqlite3MinimumFileFormat(pParse, iDb, pDflt ? 3 : 2);
91406
+ sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT,
91407
+ SQLITE_MAX_FILE_FORMAT);
9142991408
9143091409
/* Reload the schema of the modified table. */
9143191410
reloadTableSchema(pParse, pTab, pTab->zName);
9143291411
}
9143391412
@@ -184261,11 +184240,11 @@
184261184240
sqlite3_context *pCtx, /* Function call context */
184262184241
int nArg, /* Number of args */
184263184242
sqlite3_value **apVal /* Function arguments */
184264184243
){
184265184244
assert( nArg==0 );
184266
- sqlite3_result_text(pCtx, "fts5: 2016-02-08 20:45:37 6eab74c9ae57676044b5bc82fa14e92fd2448008", -1, SQLITE_TRANSIENT);
184245
+ sqlite3_result_text(pCtx, "fts5: 2016-02-09 18:28:20 51b6823f4c9376d549f572f5a33cac1e4c9783a2", -1, SQLITE_TRANSIENT);
184267184246
}
184268184247
184269184248
static int fts5Init(sqlite3 *db){
184270184249
static const sqlite3_module fts5Mod = {
184271184250
/* iVersion */ 2,
184272184251
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -328,11 +328,11 @@
328 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
329 ** [sqlite_version()] and [sqlite_source_id()].
330 */
331 #define SQLITE_VERSION "3.11.0"
332 #define SQLITE_VERSION_NUMBER 3011000
333 #define SQLITE_SOURCE_ID "2016-02-09 02:12:20 ca72be8618e5d466d6f35819ca8bbd2b84269959"
334
335 /*
336 ** CAPI3REF: Run-Time Library Version Numbers
337 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
338 **
@@ -14651,11 +14651,10 @@
14651 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
14652 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
14653 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
14654 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
14655 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
14656 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
14657 SQLITE_PRIVATE void sqlite3SchemaClear(void *);
14658 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
14659 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
14660 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
14661 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
@@ -91282,37 +91281,10 @@
91282 sqlite3SrcListDelete(db, pSrc);
91283 sqlite3DbFree(db, zName);
91284 db->flags = savedDbFlags;
91285 }
91286
91287
91288 /*
91289 ** Generate code to make sure the file format number is at least minFormat.
91290 ** The generated code will increase the file format number if necessary.
91291 */
91292 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){
91293 Vdbe *v;
91294 v = sqlite3GetVdbe(pParse);
91295 /* The VDBE should have been allocated before this routine is called.
91296 ** If that allocation failed, we would have quit before reaching this
91297 ** point */
91298 if( ALWAYS(v) ){
91299 int r1 = sqlite3GetTempReg(pParse);
91300 int r2 = sqlite3GetTempReg(pParse);
91301 int addr1;
91302 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
91303 sqlite3VdbeUsesBtree(v, iDb);
91304 sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
91305 addr1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
91306 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
91307 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, minFormat);
91308 sqlite3VdbeJumpHere(v, addr1);
91309 sqlite3ReleaseTempReg(pParse, r1);
91310 sqlite3ReleaseTempReg(pParse, r2);
91311 }
91312 }
91313
91314 /*
91315 ** This function is called after an "ALTER TABLE ... ADD" statement
91316 ** has been parsed. Argument pColDef contains the text of the new
91317 ** column definition.
91318 **
@@ -91327,13 +91299,15 @@
91327 const char *zTab; /* Table name */
91328 char *zCol; /* Null-terminated column definition */
91329 Column *pCol; /* The new column */
91330 Expr *pDflt; /* Default value for the new column */
91331 sqlite3 *db; /* The database connection; */
 
91332
91333 db = pParse->db;
91334 if( pParse->nErr || db->mallocFailed ) return;
 
91335 pNew = pParse->pNewTable;
91336 assert( pNew );
91337
91338 assert( sqlite3BtreeHoldsAllMutexes(db) );
91339 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -91419,15 +91393,20 @@
91419 );
91420 sqlite3DbFree(db, zCol);
91421 db->flags = savedDbFlags;
91422 }
91423
91424 /* If the default value of the new column is NULL, then set the file
91425 ** format to 2. If the default value of the new column is not NULL,
91426 ** the file format becomes 3.
 
 
 
 
91427 */
91428 sqlite3MinimumFileFormat(pParse, iDb, pDflt ? 3 : 2);
 
91429
91430 /* Reload the schema of the modified table. */
91431 reloadTableSchema(pParse, pTab, pTab->zName);
91432 }
91433
@@ -184261,11 +184240,11 @@
184261 sqlite3_context *pCtx, /* Function call context */
184262 int nArg, /* Number of args */
184263 sqlite3_value **apVal /* Function arguments */
184264 ){
184265 assert( nArg==0 );
184266 sqlite3_result_text(pCtx, "fts5: 2016-02-08 20:45:37 6eab74c9ae57676044b5bc82fa14e92fd2448008", -1, SQLITE_TRANSIENT);
184267 }
184268
184269 static int fts5Init(sqlite3 *db){
184270 static const sqlite3_module fts5Mod = {
184271 /* iVersion */ 2,
184272
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -328,11 +328,11 @@
328 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
329 ** [sqlite_version()] and [sqlite_source_id()].
330 */
331 #define SQLITE_VERSION "3.11.0"
332 #define SQLITE_VERSION_NUMBER 3011000
333 #define SQLITE_SOURCE_ID "2016-02-09 20:11:14 751915cb7e4981661a40dc5e4d029ab27434c2d9"
334
335 /*
336 ** CAPI3REF: Run-Time Library Version Numbers
337 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
338 **
@@ -14651,11 +14651,10 @@
14651 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
14652 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
14653 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
14654 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
14655 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
 
14656 SQLITE_PRIVATE void sqlite3SchemaClear(void *);
14657 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
14658 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
14659 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
14660 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
@@ -91282,37 +91281,10 @@
91281 sqlite3SrcListDelete(db, pSrc);
91282 sqlite3DbFree(db, zName);
91283 db->flags = savedDbFlags;
91284 }
91285
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91286 /*
91287 ** This function is called after an "ALTER TABLE ... ADD" statement
91288 ** has been parsed. Argument pColDef contains the text of the new
91289 ** column definition.
91290 **
@@ -91327,13 +91299,15 @@
91299 const char *zTab; /* Table name */
91300 char *zCol; /* Null-terminated column definition */
91301 Column *pCol; /* The new column */
91302 Expr *pDflt; /* Default value for the new column */
91303 sqlite3 *db; /* The database connection; */
91304 Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */
91305
91306 db = pParse->db;
91307 if( pParse->nErr || db->mallocFailed ) return;
91308 assert( v!=0 );
91309 pNew = pParse->pNewTable;
91310 assert( pNew );
91311
91312 assert( sqlite3BtreeHoldsAllMutexes(db) );
91313 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -91419,15 +91393,20 @@
91393 );
91394 sqlite3DbFree(db, zCol);
91395 db->flags = savedDbFlags;
91396 }
91397
91398 /* If the default value of the new column is NULL, then the file
91399 ** format to 2. If the default value of the new column is not NULL,
91400 ** the file format be 3. Back when this feature was first added
91401 ** in 2006, we went to the trouble to upgrade the file format to the
91402 ** minimum support values. But 10-years on, we can assume that all
91403 ** extent versions of SQLite support file-format 4, so we always and
91404 ** unconditionally upgrade to 4.
91405 */
91406 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT,
91407 SQLITE_MAX_FILE_FORMAT);
91408
91409 /* Reload the schema of the modified table. */
91410 reloadTableSchema(pParse, pTab, pTab->zName);
91411 }
91412
@@ -184261,11 +184240,11 @@
184240 sqlite3_context *pCtx, /* Function call context */
184241 int nArg, /* Number of args */
184242 sqlite3_value **apVal /* Function arguments */
184243 ){
184244 assert( nArg==0 );
184245 sqlite3_result_text(pCtx, "fts5: 2016-02-09 18:28:20 51b6823f4c9376d549f572f5a33cac1e4c9783a2", -1, SQLITE_TRANSIENT);
184246 }
184247
184248 static int fts5Init(sqlite3 *db){
184249 static const sqlite3_module fts5Mod = {
184250 /* iVersion */ 2,
184251
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.11.0"
115115
#define SQLITE_VERSION_NUMBER 3011000
116
-#define SQLITE_SOURCE_ID "2016-02-09 02:12:20 ca72be8618e5d466d6f35819ca8bbd2b84269959"
116
+#define SQLITE_SOURCE_ID "2016-02-09 20:11:14 751915cb7e4981661a40dc5e4d029ab27434c2d9"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
122122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.11.0"
115 #define SQLITE_VERSION_NUMBER 3011000
116 #define SQLITE_SOURCE_ID "2016-02-09 02:12:20 ca72be8618e5d466d6f35819ca8bbd2b84269959"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.11.0"
115 #define SQLITE_VERSION_NUMBER 3011000
116 #define SQLITE_SOURCE_ID "2016-02-09 20:11:14 751915cb7e4981661a40dc5e4d029ab27434c2d9"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122

Keyboard Shortcuts

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