Fossil SCM

Updates the built-in SQLite sources to the latest 3.8.5 beta. In particular, this update includes the new ".system" and ".once" commands to the SQLite command-line utility accessed via the "fossil sql" command.

drh 2014-06-02 14:52 trunk
Commit 8bc47c1469ebe9361458e99a9fd20085028ac53f
3 files changed +232 -114 +30 -3 +8 -1
+232 -114
--- src/shell.c
+++ src/shell.c
@@ -444,12 +444,13 @@
444444
** state and mode information.
445445
*/
446446
struct callback_data {
447447
sqlite3 *db; /* The database */
448448
int echoOn; /* True to echo input commands */
449
- int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */
449
+ int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
450450
int statsOn; /* True to display memory stats before each finalize */
451
+ int outCount; /* Revert to stdout when reaching zero */
451452
int cnt; /* Number of records displayed so far */
452453
FILE *out; /* Write results here */
453454
FILE *traceOut; /* Output for sqlite3_trace() */
454455
int nErr; /* Number of errors seen */
455456
int mode; /* An output mode setting */
@@ -876,11 +877,12 @@
876877
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
877878
fprintf(p->out,"%sNULL",zSep);
878879
}else if( aiType && aiType[i]==SQLITE_TEXT ){
879880
if( zSep[0] ) fprintf(p->out,"%s",zSep);
880881
output_quoted_string(p->out, azArg[i]);
881
- }else if( aiType && (aiType[i]==SQLITE_INTEGER || aiType[i]==SQLITE_FLOAT) ){
882
+ }else if( aiType && (aiType[i]==SQLITE_INTEGER
883
+ || aiType[i]==SQLITE_FLOAT) ){
882884
fprintf(p->out,"%s%s",zSep, azArg[i]);
883885
}else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
884886
const void *pBlob = sqlite3_column_blob(p->pStmt, i);
885887
int nBlob = sqlite3_column_bytes(p->pStmt, i);
886888
if( zSep[0] ) fprintf(p->out,"%s",zSep);
@@ -1196,11 +1198,11 @@
11961198
int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
11971199
int iOp; /* Index of operation in p->aiIndent[] */
11981200
11991201
const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
12001202
"NextIfOpen", "PrevIfOpen", 0 };
1201
- const char *azYield[] = { "Yield", "SeekLt", "SeekGt", "RowSetRead", "Rewind", 0 };
1203
+ const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead", "Rewind", 0 };
12021204
const char *azGoto[] = { "Goto", 0 };
12031205
12041206
/* Try to figure out if this is really an EXPLAIN statement. If this
12051207
** cannot be verified, return early. */
12061208
zSql = sqlite3_sql(pSql);
@@ -1568,21 +1570,21 @@
15681570
/*
15691571
** Text of a help message
15701572
*/
15711573
static char zHelp[] =
15721574
".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1573
- ".bail ON|OFF Stop after hitting an error. Default OFF\n"
1575
+ ".bail on|off Stop after hitting an error. Default OFF\n"
15741576
".clone NEWDB Clone data into NEWDB from the existing database\n"
15751577
".databases List names and files of attached databases\n"
15761578
".dump ?TABLE? ... Dump the database in an SQL text format\n"
15771579
" If TABLE specified, only dump tables matching\n"
15781580
" LIKE pattern TABLE.\n"
1579
- ".echo ON|OFF Turn command echo on or off\n"
1581
+ ".echo on|off Turn command echo on or off\n"
15801582
".exit Exit this program\n"
1581
- ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n"
1583
+ ".explain ?on|off? Turn output mode suitable for EXPLAIN on or off.\n"
15821584
" With no args, it turns EXPLAIN on.\n"
1583
- ".headers ON|OFF Turn display of headers on or off\n"
1585
+ ".headers on|off Turn display of headers on or off\n"
15841586
".help Show this message\n"
15851587
".import FILE TABLE Import data from FILE into TABLE\n"
15861588
".indices ?TABLE? Show names of all indices\n"
15871589
" If TABLE specified, only show indices for tables\n"
15881590
" matching LIKE pattern TABLE.\n"
@@ -1601,13 +1603,13 @@
16011603
" line One value per line\n"
16021604
" list Values delimited by .separator string\n"
16031605
" tabs Tab-separated values\n"
16041606
" tcl TCL list elements\n"
16051607
".nullvalue STRING Use STRING in place of NULL values\n"
1608
+ ".once FILENAME Output for the next SQL command only to FILENAME\n"
16061609
".open ?FILENAME? Close existing database and reopen FILENAME\n"
1607
- ".output FILENAME Send output to FILENAME\n"
1608
- ".output stdout Send output to the screen\n"
1610
+ ".output ?FILENAME? Send output to FILENAME or stdout\n"
16091611
".print STRING... Print literal STRING\n"
16101612
".prompt MAIN CONTINUE Replace the standard prompts\n"
16111613
".quit Exit this program\n"
16121614
".read FILENAME Execute SQL in FILENAME\n"
16131615
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
@@ -1616,26 +1618,23 @@
16161618
" If TABLE specified, only show tables matching\n"
16171619
" LIKE pattern TABLE.\n"
16181620
".separator STRING Change separator used by output mode and .import\n"
16191621
".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
16201622
".show Show the current values for various settings\n"
1621
- ".stats ON|OFF Turn stats on or off\n"
1623
+ ".stats on|off Turn stats on or off\n"
16221624
".system CMD ARGS... Run CMD ARGS... in a system shell\n"
16231625
".tables ?TABLE? List names of tables\n"
16241626
" If TABLE specified, only list tables matching\n"
16251627
" LIKE pattern TABLE.\n"
16261628
".timeout MS Try opening locked tables for MS milliseconds\n"
1629
+ ".timer on|off Turn SQL timer on or off\n"
16271630
".trace FILE|off Output each SQL statement as it is run\n"
16281631
".vfsname ?AUX? Print the name of the VFS stack\n"
16291632
".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
16301633
" Negative values right-justify\n"
16311634
;
16321635
1633
-static char zTimerHelp[] =
1634
- ".timer ON|OFF Turn the CPU timer measurement on or off\n"
1635
-;
1636
-
16371636
/* Forward reference */
16381637
static int process_input(struct callback_data *p, FILE *in);
16391638
16401639
/*
16411640
** Make sure the database is open. If it is not, then open it. If
@@ -1673,10 +1672,11 @@
16731672
** \\ -> backslash
16741673
*/
16751674
static void resolve_backslashes(char *z){
16761675
int i, j;
16771676
char c;
1677
+ while( *z && *z!='\\' ) z++;
16781678
for(i=j=0; (c = z[i])!=0; i++, j++){
16791679
if( c=='\\' ){
16801680
c = z[++i];
16811681
if( c=='n' ){
16821682
c = '\n';
@@ -1698,11 +1698,11 @@
16981698
}
16991699
}
17001700
}
17011701
z[j] = c;
17021702
}
1703
- z[j] = 0;
1703
+ if( j<i ) z[j] = 0;
17041704
}
17051705
17061706
/*
17071707
** Return the value of a hexadecimal digit. Return -1 if the input
17081708
** is not a hex digit.
@@ -2141,10 +2141,23 @@
21412141
sqlite3_exec(newDb, "COMMIT;", 0, 0, 0);
21422142
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
21432143
}
21442144
sqlite3_close(newDb);
21452145
}
2146
+
2147
+/*
2148
+** Change the output file back to stdout
2149
+*/
2150
+static void output_reset(struct callback_data *p){
2151
+ if( p->outfile[0]=='|' ){
2152
+ pclose(p->out);
2153
+ }else{
2154
+ output_file_close(p->out);
2155
+ }
2156
+ p->outfile[0] = 0;
2157
+ p->out = stdout;
2158
+}
21462159
21472160
/*
21482161
** If an input line begins with "." then invoke this routine to
21492162
** process that line.
21502163
**
@@ -2240,26 +2253,36 @@
22402253
rc = 1;
22412254
}
22422255
sqlite3_close(pDest);
22432256
}else
22442257
2245
- if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 && nArg>1 && nArg<3 ){
2246
- bail_on_error = booleanValue(azArg[1]);
2258
+ if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
2259
+ if( nArg==2 ){
2260
+ bail_on_error = booleanValue(azArg[1]);
2261
+ }else{
2262
+ fprintf(stderr, "Usage: .bail on|off\n");
2263
+ rc = 1;
2264
+ }
22472265
}else
22482266
22492267
/* The undocumented ".breakpoint" command causes a call to the no-op
22502268
** routine named test_breakpoint().
22512269
*/
22522270
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
22532271
test_breakpoint();
22542272
}else
22552273
2256
- if( c=='c' && strncmp(azArg[0], "clone", n)==0 && nArg>1 && nArg<3 ){
2257
- tryToClone(p, azArg[1]);
2274
+ if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
2275
+ if( nArg==2 ){
2276
+ tryToClone(p, azArg[1]);
2277
+ }else{
2278
+ fprintf(stderr, "Usage: .clone FILENAME\n");
2279
+ rc = 1;
2280
+ }
22582281
}else
22592282
2260
- if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
2283
+ if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
22612284
struct callback_data data;
22622285
char *zErrMsg = 0;
22632286
open_db(p, 0);
22642287
memcpy(&data, p, sizeof(data));
22652288
data.showHeader = 1;
@@ -2274,15 +2297,20 @@
22742297
sqlite3_free(zErrMsg);
22752298
rc = 1;
22762299
}
22772300
}else
22782301
2279
- if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
2302
+ if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
22802303
open_db(p, 0);
22812304
/* When playing back a "dump", the content might appear in an order
22822305
** which causes immediate foreign key constraints to be violated.
22832306
** So disable foreign-key constraint enforcement to prevent problems. */
2307
+ if( nArg!=1 && nArg!=2 ){
2308
+ fprintf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
2309
+ rc = 1;
2310
+ goto meta_command_exit;
2311
+ }
22842312
fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
22852313
fprintf(p->out, "BEGIN TRANSACTION;\n");
22862314
p->writableSchema = 0;
22872315
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
22882316
p->nErr = 0;
@@ -2323,24 +2351,34 @@
23232351
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
23242352
sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
23252353
fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
23262354
}else
23272355
2328
- if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
2329
- p->echoOn = booleanValue(azArg[1]);
2356
+ if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
2357
+ if( nArg==2 ){
2358
+ p->echoOn = booleanValue(azArg[1]);
2359
+ }else{
2360
+ fprintf(stderr, "Usage: .echo on|off\n");
2361
+ rc = 1;
2362
+ }
23302363
}else
23312364
2332
- if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){
2333
- p->autoEQP = booleanValue(azArg[1]);
2365
+ if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
2366
+ if( nArg==2 ){
2367
+ p->autoEQP = booleanValue(azArg[1]);
2368
+ }else{
2369
+ fprintf(stderr, "Usage: .eqp on|off\n");
2370
+ rc = 1;
2371
+ }
23342372
}else
23352373
23362374
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
23372375
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
23382376
rc = 2;
23392377
}else
23402378
2341
- if( c=='e' && strncmp(azArg[0], "explain", n)==0 && nArg<3 ){
2379
+ if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
23422380
int val = nArg>=2 ? booleanValue(azArg[1]) : 1;
23432381
if(val == 1) {
23442382
if(!p->explainPrev.valid) {
23452383
p->explainPrev.valid = 1;
23462384
p->explainPrev.mode = p->mode;
@@ -2371,25 +2409,26 @@
23712409
p->showHeader = p->explainPrev.showHeader;
23722410
memcpy(p->colWidth,p->explainPrev.colWidth,sizeof(p->colWidth));
23732411
}
23742412
}else
23752413
2376
- if( c=='h' && (strncmp(azArg[0], "header", n)==0 ||
2377
- strncmp(azArg[0], "headers", n)==0) && nArg>1 && nArg<3 ){
2378
- p->showHeader = booleanValue(azArg[1]);
2414
+ if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
2415
+ if( nArg==2 ){
2416
+ p->showHeader = booleanValue(azArg[1]);
2417
+ }else{
2418
+ fprintf(stderr, "Usage: .headers on|off\n");
2419
+ rc = 1;
2420
+ }
23792421
}else
23802422
23812423
if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
2382
- fprintf(stderr,"%s",zHelp);
2383
- if( HAS_TIMER ){
2384
- fprintf(stderr,"%s",zTimerHelp);
2385
- }
2424
+ fprintf(p->out, "%s", zHelp);
23862425
}else
23872426
2388
- if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
2389
- char *zTable = azArg[2]; /* Insert data into this table */
2390
- char *zFile = azArg[1]; /* Name of file to extra content from */
2427
+ if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
2428
+ char *zTable; /* Insert data into this table */
2429
+ char *zFile; /* Name of file to extra content from */
23912430
sqlite3_stmt *pStmt = NULL; /* A statement */
23922431
int nCol; /* Number of columns in the table */
23932432
int nByte; /* Number of bytes in an SQL string */
23942433
int i, j; /* Loop counters */
23952434
int needCommit; /* True to COMMIT or ROLLBACK at end */
@@ -2396,10 +2435,16 @@
23962435
int nSep; /* Number of bytes in p->separator[] */
23972436
char *zSql; /* An SQL statement */
23982437
CSVReader sCsv; /* Reader context */
23992438
int (*xCloser)(FILE*); /* Procedure to close th3 connection */
24002439
2440
+ if( nArg!=3 ){
2441
+ fprintf(stderr, "Usage: .import FILE TABLE\n");
2442
+ goto meta_command_exit;
2443
+ }
2444
+ zFile = azArg[1];
2445
+ zTable = azArg[2];
24012446
seenInterrupt = 0;
24022447
memset(&sCsv, 0, sizeof(sCsv));
24032448
open_db(p, 0);
24042449
nSep = strlen30(p->separator);
24052450
if( nSep==0 ){
@@ -2534,11 +2579,11 @@
25342579
sqlite3_free(sCsv.z);
25352580
sqlite3_finalize(pStmt);
25362581
if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
25372582
}else
25382583
2539
- if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2584
+ if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
25402585
struct callback_data data;
25412586
char *zErrMsg = 0;
25422587
open_db(p, 0);
25432588
memcpy(&data, p, sizeof(data));
25442589
data.showHeader = 0;
@@ -2551,11 +2596,11 @@
25512596
"SELECT name FROM sqlite_temp_master "
25522597
"WHERE type='index' "
25532598
"ORDER BY 1",
25542599
callback, &data, &zErrMsg
25552600
);
2556
- }else{
2601
+ }else if( nArg==2 ){
25572602
zShellStatic = azArg[1];
25582603
rc = sqlite3_exec(p->db,
25592604
"SELECT name FROM sqlite_master "
25602605
"WHERE type='index' AND tbl_name LIKE shellstatic() "
25612606
"UNION ALL "
@@ -2563,10 +2608,14 @@
25632608
"WHERE type='index' AND tbl_name LIKE shellstatic() "
25642609
"ORDER BY 1",
25652610
callback, &data, &zErrMsg
25662611
);
25672612
zShellStatic = 0;
2613
+ }else{
2614
+ fprintf(stderr, "Usage: .indices ?LIKE-PATTERN?\n");
2615
+ rc = 1;
2616
+ goto meta_command_exit;
25682617
}
25692618
if( zErrMsg ){
25702619
fprintf(stderr,"Error: %s\n", zErrMsg);
25712620
sqlite3_free(zErrMsg);
25722621
rc = 1;
@@ -2598,13 +2647,18 @@
25982647
}
25992648
}else
26002649
#endif
26012650
26022651
#ifndef SQLITE_OMIT_LOAD_EXTENSION
2603
- if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){
2652
+ if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
26042653
const char *zFile, *zProc;
26052654
char *zErrMsg = 0;
2655
+ if( nArg<2 ){
2656
+ fprintf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
2657
+ rc = 1;
2658
+ goto meta_command_exit;
2659
+ }
26062660
zFile = azArg[1];
26072661
zProc = nArg>=3 ? azArg[2] : 0;
26082662
open_db(p, 0);
26092663
rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
26102664
if( rc!=SQLITE_OK ){
@@ -2613,66 +2667,62 @@
26132667
rc = 1;
26142668
}
26152669
}else
26162670
#endif
26172671
2618
- if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
2619
- const char *zFile = azArg[1];
2620
- output_file_close(p->pLog);
2621
- p->pLog = output_file_open(zFile);
2672
+ if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
2673
+ if( nArg!=2 ){
2674
+ fprintf(stderr, "Usage: .log FILENAME\n");
2675
+ rc = 1;
2676
+ }else{
2677
+ const char *zFile = azArg[1];
2678
+ output_file_close(p->pLog);
2679
+ p->pLog = output_file_open(zFile);
2680
+ }
26222681
}else
26232682
2624
- if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){
2625
- int n2 = strlen30(azArg[1]);
2626
- if( (n2==4 && strncmp(azArg[1],"line",n2)==0)
2627
- ||
2628
- (n2==5 && strncmp(azArg[1],"lines",n2)==0) ){
2683
+ if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
2684
+ const char *zMode = nArg>=2 ? azArg[1] : "";
2685
+ int n2 = (int)strlen(zMode);
2686
+ int c2 = zMode[0];
2687
+ if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
26292688
p->mode = MODE_Line;
2630
- }else if( (n2==6 && strncmp(azArg[1],"column",n2)==0)
2631
- ||
2632
- (n2==7 && strncmp(azArg[1],"columns",n2)==0) ){
2689
+ }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
26332690
p->mode = MODE_Column;
2634
- }else if( n2==4 && strncmp(azArg[1],"list",n2)==0 ){
2691
+ }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
26352692
p->mode = MODE_List;
2636
- }else if( n2==4 && strncmp(azArg[1],"html",n2)==0 ){
2693
+ }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
26372694
p->mode = MODE_Html;
2638
- }else if( n2==3 && strncmp(azArg[1],"tcl",n2)==0 ){
2695
+ }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
26392696
p->mode = MODE_Tcl;
26402697
sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
2641
- }else if( n2==3 && strncmp(azArg[1],"csv",n2)==0 ){
2698
+ }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
26422699
p->mode = MODE_Csv;
26432700
sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2644
- }else if( n2==4 && strncmp(azArg[1],"tabs",n2)==0 ){
2701
+ }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
26452702
p->mode = MODE_List;
26462703
sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
2647
- }else if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){
2704
+ }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
26482705
p->mode = MODE_Insert;
2649
- set_table_name(p, "table");
2706
+ set_table_name(p, nArg>=3 ? azArg[2] : "table");
26502707
}else {
26512708
fprintf(stderr,"Error: mode should be one of: "
26522709
"column csv html insert line list tabs tcl\n");
26532710
rc = 1;
26542711
}
26552712
}else
26562713
2657
- if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==3 ){
2658
- int n2 = strlen30(azArg[1]);
2659
- if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){
2660
- p->mode = MODE_Insert;
2661
- set_table_name(p, azArg[2]);
2662
- }else {
2663
- fprintf(stderr, "Error: invalid arguments: "
2664
- " \"%s\". Enter \".help\" for help\n", azArg[2]);
2714
+ if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2715
+ if( nArg==2 ){
2716
+ sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2717
+ "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2718
+ }else{
2719
+ fprintf(stderr, "Usage: .nullvalue STRING\n");
26652720
rc = 1;
26662721
}
26672722
}else
26682723
2669
- if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
2670
- sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2671
- "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2672
- }else
2673
-
26742724
if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
26752725
sqlite3 *savedDb = p->db;
26762726
const char *zSavedFilename = p->zDbFilename;
26772727
char *zNewFilename = 0;
26782728
p->db = 0;
@@ -2689,36 +2739,49 @@
26892739
p->db = savedDb;
26902740
p->zDbFilename = zSavedFilename;
26912741
}
26922742
}else
26932743
2694
- if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
2695
- if( p->outfile[0]=='|' ){
2696
- pclose(p->out);
2744
+ if( c=='o'
2745
+ && (strncmp(azArg[0], "output", n)==0 || strncmp(azArg[0], "once", n)==0)
2746
+ ){
2747
+ const char *zFile = nArg>=2 ? azArg[1] : "stdout";
2748
+ if( nArg>2 ){
2749
+ fprintf(stderr, "Usage: .%s FILE\n", azArg[0]);
2750
+ rc = 1;
2751
+ goto meta_command_exit;
2752
+ }
2753
+ if( n>1 && strncmp(azArg[0], "once", n)==0 ){
2754
+ if( nArg<2 ){
2755
+ fprintf(stderr, "Usage: .once FILE\n");
2756
+ rc = 1;
2757
+ goto meta_command_exit;
2758
+ }
2759
+ p->outCount = 2;
26972760
}else{
2698
- output_file_close(p->out);
2761
+ p->outCount = 0;
26992762
}
2700
- p->outfile[0] = 0;
2701
- if( azArg[1][0]=='|' ){
2702
- p->out = popen(&azArg[1][1], "w");
2763
+ output_reset(p);
2764
+ if( zFile[0]=='|' ){
2765
+ p->out = popen(zFile + 1, "w");
27032766
if( p->out==0 ){
2704
- fprintf(stderr,"Error: cannot open pipe \"%s\"\n", &azArg[1][1]);
2767
+ fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
27052768
p->out = stdout;
27062769
rc = 1;
27072770
}else{
2708
- sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
2771
+ sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
27092772
}
27102773
}else{
2711
- p->out = output_file_open(azArg[1]);
2774
+ p->out = output_file_open(zFile);
27122775
if( p->out==0 ){
2713
- if( strcmp(azArg[1],"off")!=0 ){
2714
- fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]);
2776
+ if( strcmp(zFile,"off")!=0 ){
2777
+ fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
27152778
}
27162779
p->out = stdout;
27172780
rc = 1;
27182781
} else {
2719
- sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
2782
+ sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
27202783
}
27212784
}
27222785
}else
27232786
27242787
if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
@@ -2728,47 +2791,57 @@
27282791
fprintf(p->out, "%s", azArg[i]);
27292792
}
27302793
fprintf(p->out, "\n");
27312794
}else
27322795
2733
- if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){
2796
+ if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
27342797
if( nArg >= 2) {
27352798
strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
27362799
}
27372800
if( nArg >= 3) {
27382801
strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
27392802
}
27402803
}else
27412804
2742
- if( c=='q' && strncmp(azArg[0], "quit", n)==0 && nArg==1 ){
2805
+ if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
27432806
rc = 2;
27442807
}else
27452808
2746
- if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 && nArg==2 ){
2747
- FILE *alt = fopen(azArg[1], "rb");
2809
+ if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
2810
+ FILE *alt;
2811
+ if( nArg!=2 ){
2812
+ fprintf(stderr, "Usage: .read FILE\n");
2813
+ rc = 1;
2814
+ goto meta_command_exit;
2815
+ }
2816
+ alt = fopen(azArg[1], "rb");
27482817
if( alt==0 ){
27492818
fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
27502819
rc = 1;
27512820
}else{
27522821
rc = process_input(p, alt);
27532822
fclose(alt);
27542823
}
27552824
}else
27562825
2757
- if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 && nArg>1 && nArg<4){
2826
+ if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
27582827
const char *zSrcFile;
27592828
const char *zDb;
27602829
sqlite3 *pSrc;
27612830
sqlite3_backup *pBackup;
27622831
int nTimeout = 0;
27632832
27642833
if( nArg==2 ){
27652834
zSrcFile = azArg[1];
27662835
zDb = "main";
2767
- }else{
2836
+ }else if( nArg==3 ){
27682837
zSrcFile = azArg[2];
27692838
zDb = azArg[1];
2839
+ }else{
2840
+ fprintf(stderr, "Usage: .restore ?DB? FILE\n");
2841
+ rc = 1;
2842
+ goto meta_command_exit;
27702843
}
27712844
rc = sqlite3_open(zSrcFile, &pSrc);
27722845
if( rc!=SQLITE_OK ){
27732846
fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
27742847
sqlite3_close(pSrc);
@@ -2799,18 +2872,18 @@
27992872
rc = 1;
28002873
}
28012874
sqlite3_close(pSrc);
28022875
}else
28032876
2804
- if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
2877
+ if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
28052878
struct callback_data data;
28062879
char *zErrMsg = 0;
28072880
open_db(p, 0);
28082881
memcpy(&data, p, sizeof(data));
28092882
data.showHeader = 0;
28102883
data.mode = MODE_Semi;
2811
- if( nArg>1 ){
2884
+ if( nArg==2 ){
28122885
int i;
28132886
for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
28142887
if( strcmp(azArg[1],"sqlite_master")==0 ){
28152888
char *new_argv[2], *new_colv[2];
28162889
new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -2850,20 +2923,24 @@
28502923
" AND type!='meta' AND sql NOTNULL "
28512924
"ORDER BY rowid",
28522925
callback, &data, &zErrMsg);
28532926
zShellStatic = 0;
28542927
}
2855
- }else{
2928
+ }else if( nArg==1 ){
28562929
rc = sqlite3_exec(p->db,
28572930
"SELECT sql FROM "
28582931
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
28592932
" FROM sqlite_master UNION ALL"
28602933
" SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
28612934
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
28622935
"ORDER BY rowid",
28632936
callback, &data, &zErrMsg
28642937
);
2938
+ }else{
2939
+ fprintf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
2940
+ rc = 1;
2941
+ goto meta_command_exit;
28652942
}
28662943
if( zErrMsg ){
28672944
fprintf(stderr,"Error: %s\n", zErrMsg);
28682945
sqlite3_free(zErrMsg);
28692946
rc = 1;
@@ -2889,38 +2966,53 @@
28892966
if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
28902967
int i; sqlite3_int64 v;
28912968
for(i=1; i<nArg; i++){
28922969
char zBuf[200];
28932970
v = integerValue(azArg[i]);
2894
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%s: %lld 0x%llx\n", azArg[i], v, v);
2971
+ sqlite3_snprintf(sizeof(zBuf),zBuf,"%s: %lld 0x%llx\n", azArg[i],v,v);
28952972
fprintf(p->out, "%s", zBuf);
28962973
}
28972974
}
28982975
}else
28992976
#endif
29002977
2901
- if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
2902
- sqlite3_snprintf(sizeof(p->separator), p->separator,
2903
- "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
2978
+ if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
2979
+ if( nArg==2 ){
2980
+ sqlite3_snprintf(sizeof(p->separator), p->separator,
2981
+ "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
2982
+ }else{
2983
+ fprintf(stderr, "Usage: .separator STRING\n");
2984
+ rc = 1;
2985
+ }
29042986
}else
29052987
29062988
if( c=='s'
29072989
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2908
- && nArg>=2
29092990
){
29102991
char *zCmd;
29112992
int i;
2912
- zCmd = sqlite3_mprintf("\"%s\"", azArg[1]);
2993
+ if( nArg<2 ){
2994
+ fprintf(stderr, "Usage: .system COMMAND\n");
2995
+ rc = 1;
2996
+ goto meta_command_exit;
2997
+ }
2998
+ zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
29132999
for(i=2; i<nArg; i++){
2914
- zCmd = sqlite3_mprintf("%z \"%s\"", zCmd, azArg[i]);
3000
+ zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
3001
+ zCmd, azArg[i]);
29153002
}
2916
- system(zCmd);
3003
+ (void)system(zCmd);
29173004
sqlite3_free(zCmd);
29183005
}else
29193006
2920
- if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
3007
+ if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
29213008
int i;
3009
+ if( nArg!=1 ){
3010
+ fprintf(stderr, "Usage: .show\n");
3011
+ rc = 1;
3012
+ goto meta_command_exit;
3013
+ }
29223014
fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
29233015
fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
29243016
fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
29253017
fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
29263018
fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
@@ -2938,15 +3030,20 @@
29383030
fprintf(p->out,"%d ",p->colWidth[i]);
29393031
}
29403032
fprintf(p->out,"\n");
29413033
}else
29423034
2943
- if( c=='s' && strncmp(azArg[0], "stats", n)==0 && nArg>1 && nArg<3 ){
2944
- p->statsOn = booleanValue(azArg[1]);
3035
+ if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
3036
+ if( nArg==2 ){
3037
+ p->statsOn = booleanValue(azArg[1]);
3038
+ }else{
3039
+ fprintf(stderr, "Usage: .stats on|off\n");
3040
+ rc = 1;
3041
+ }
29453042
}else
29463043
2947
- if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){
3044
+ if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
29483045
sqlite3_stmt *pStmt;
29493046
char **azResult;
29503047
int nRow, nAlloc;
29513048
char *zSql = 0;
29523049
int ii;
@@ -3148,24 +3245,36 @@
31483245
break;
31493246
}
31503247
}
31513248
}else
31523249
3153
- if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
3250
+ if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 ){
31543251
open_db(p, 0);
3155
- sqlite3_busy_timeout(p->db, (int)integerValue(azArg[1]));
3252
+ sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
31563253
}else
31573254
3158
- if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
3159
- && nArg==2
3160
- ){
3161
- enableTimer = booleanValue(azArg[1]);
3255
+ if( c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 ){
3256
+ if( nArg==2 ){
3257
+ enableTimer = booleanValue(azArg[1]);
3258
+ if( enableTimer && !HAS_TIMER ){
3259
+ fprintf(stderr, "Error: timer not available on this system.\n");
3260
+ enableTimer = 0;
3261
+ }
3262
+ }else{
3263
+ fprintf(stderr, "Usage: .timer on|off\n");
3264
+ rc = 1;
3265
+ }
31623266
}else
31633267
3164
- if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
3268
+ if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
31653269
open_db(p, 0);
31663270
output_file_close(p->traceOut);
3271
+ if( nArg!=2 ){
3272
+ fprintf(stderr, "Usage: .trace FILE|off\n");
3273
+ rc = 1;
3274
+ goto meta_command_exit;
3275
+ }
31673276
p->traceOut = output_file_open(azArg[1]);
31683277
#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
31693278
if( p->traceOut==0 ){
31703279
sqlite3_trace(p->db, 0, 0);
31713280
}else{
@@ -3192,15 +3301,15 @@
31923301
}else
31933302
31943303
#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
31953304
if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
31963305
extern int sqlite3WhereTrace;
3197
- sqlite3WhereTrace = booleanValue(azArg[1]);
3306
+ sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
31983307
}else
31993308
#endif
32003309
3201
- if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
3310
+ if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
32023311
int j;
32033312
assert( nArg<=ArraySize(azArg) );
32043313
for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
32053314
p->colWidth[j-1] = (int)integerValue(azArg[j]);
32063315
}
@@ -3210,10 +3319,15 @@
32103319
fprintf(stderr, "Error: unknown command or invalid arguments: "
32113320
" \"%s\". Enter \".help\" for help\n", azArg[0]);
32123321
rc = 1;
32133322
}
32143323
3324
+meta_command_exit:
3325
+ if( p->outCount ){
3326
+ p->outCount--;
3327
+ if( p->outCount==0 ) output_reset(p);
3328
+ }
32153329
return rc;
32163330
}
32173331
32183332
/*
32193333
** Return TRUE if a semicolon occurs anywhere in the first N characters
@@ -3377,10 +3491,14 @@
33773491
fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
33783492
}
33793493
errCnt++;
33803494
}
33813495
nSql = 0;
3496
+ if( p->outCount ){
3497
+ output_reset(p);
3498
+ p->outCount = 0;
3499
+ }
33823500
}else if( nSql && _all_whitespace(zSql) ){
33833501
if( p->echoOn ) printf("%s\n", zSql);
33843502
nSql = 0;
33853503
}
33863504
}
33873505
--- src/shell.c
+++ src/shell.c
@@ -444,12 +444,13 @@
444 ** state and mode information.
445 */
446 struct callback_data {
447 sqlite3 *db; /* The database */
448 int echoOn; /* True to echo input commands */
449 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */
450 int statsOn; /* True to display memory stats before each finalize */
 
451 int cnt; /* Number of records displayed so far */
452 FILE *out; /* Write results here */
453 FILE *traceOut; /* Output for sqlite3_trace() */
454 int nErr; /* Number of errors seen */
455 int mode; /* An output mode setting */
@@ -876,11 +877,12 @@
876 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
877 fprintf(p->out,"%sNULL",zSep);
878 }else if( aiType && aiType[i]==SQLITE_TEXT ){
879 if( zSep[0] ) fprintf(p->out,"%s",zSep);
880 output_quoted_string(p->out, azArg[i]);
881 }else if( aiType && (aiType[i]==SQLITE_INTEGER || aiType[i]==SQLITE_FLOAT) ){
 
882 fprintf(p->out,"%s%s",zSep, azArg[i]);
883 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
884 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
885 int nBlob = sqlite3_column_bytes(p->pStmt, i);
886 if( zSep[0] ) fprintf(p->out,"%s",zSep);
@@ -1196,11 +1198,11 @@
1196 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1197 int iOp; /* Index of operation in p->aiIndent[] */
1198
1199 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
1200 "NextIfOpen", "PrevIfOpen", 0 };
1201 const char *azYield[] = { "Yield", "SeekLt", "SeekGt", "RowSetRead", "Rewind", 0 };
1202 const char *azGoto[] = { "Goto", 0 };
1203
1204 /* Try to figure out if this is really an EXPLAIN statement. If this
1205 ** cannot be verified, return early. */
1206 zSql = sqlite3_sql(pSql);
@@ -1568,21 +1570,21 @@
1568 /*
1569 ** Text of a help message
1570 */
1571 static char zHelp[] =
1572 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1573 ".bail ON|OFF Stop after hitting an error. Default OFF\n"
1574 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1575 ".databases List names and files of attached databases\n"
1576 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1577 " If TABLE specified, only dump tables matching\n"
1578 " LIKE pattern TABLE.\n"
1579 ".echo ON|OFF Turn command echo on or off\n"
1580 ".exit Exit this program\n"
1581 ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n"
1582 " With no args, it turns EXPLAIN on.\n"
1583 ".headers ON|OFF Turn display of headers on or off\n"
1584 ".help Show this message\n"
1585 ".import FILE TABLE Import data from FILE into TABLE\n"
1586 ".indices ?TABLE? Show names of all indices\n"
1587 " If TABLE specified, only show indices for tables\n"
1588 " matching LIKE pattern TABLE.\n"
@@ -1601,13 +1603,13 @@
1601 " line One value per line\n"
1602 " list Values delimited by .separator string\n"
1603 " tabs Tab-separated values\n"
1604 " tcl TCL list elements\n"
1605 ".nullvalue STRING Use STRING in place of NULL values\n"
 
1606 ".open ?FILENAME? Close existing database and reopen FILENAME\n"
1607 ".output FILENAME Send output to FILENAME\n"
1608 ".output stdout Send output to the screen\n"
1609 ".print STRING... Print literal STRING\n"
1610 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1611 ".quit Exit this program\n"
1612 ".read FILENAME Execute SQL in FILENAME\n"
1613 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
@@ -1616,26 +1618,23 @@
1616 " If TABLE specified, only show tables matching\n"
1617 " LIKE pattern TABLE.\n"
1618 ".separator STRING Change separator used by output mode and .import\n"
1619 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1620 ".show Show the current values for various settings\n"
1621 ".stats ON|OFF Turn stats on or off\n"
1622 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1623 ".tables ?TABLE? List names of tables\n"
1624 " If TABLE specified, only list tables matching\n"
1625 " LIKE pattern TABLE.\n"
1626 ".timeout MS Try opening locked tables for MS milliseconds\n"
 
1627 ".trace FILE|off Output each SQL statement as it is run\n"
1628 ".vfsname ?AUX? Print the name of the VFS stack\n"
1629 ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
1630 " Negative values right-justify\n"
1631 ;
1632
1633 static char zTimerHelp[] =
1634 ".timer ON|OFF Turn the CPU timer measurement on or off\n"
1635 ;
1636
1637 /* Forward reference */
1638 static int process_input(struct callback_data *p, FILE *in);
1639
1640 /*
1641 ** Make sure the database is open. If it is not, then open it. If
@@ -1673,10 +1672,11 @@
1673 ** \\ -> backslash
1674 */
1675 static void resolve_backslashes(char *z){
1676 int i, j;
1677 char c;
 
1678 for(i=j=0; (c = z[i])!=0; i++, j++){
1679 if( c=='\\' ){
1680 c = z[++i];
1681 if( c=='n' ){
1682 c = '\n';
@@ -1698,11 +1698,11 @@
1698 }
1699 }
1700 }
1701 z[j] = c;
1702 }
1703 z[j] = 0;
1704 }
1705
1706 /*
1707 ** Return the value of a hexadecimal digit. Return -1 if the input
1708 ** is not a hex digit.
@@ -2141,10 +2141,23 @@
2141 sqlite3_exec(newDb, "COMMIT;", 0, 0, 0);
2142 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
2143 }
2144 sqlite3_close(newDb);
2145 }
 
 
 
 
 
 
 
 
 
 
 
 
 
2146
2147 /*
2148 ** If an input line begins with "." then invoke this routine to
2149 ** process that line.
2150 **
@@ -2240,26 +2253,36 @@
2240 rc = 1;
2241 }
2242 sqlite3_close(pDest);
2243 }else
2244
2245 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 && nArg>1 && nArg<3 ){
2246 bail_on_error = booleanValue(azArg[1]);
 
 
 
 
 
2247 }else
2248
2249 /* The undocumented ".breakpoint" command causes a call to the no-op
2250 ** routine named test_breakpoint().
2251 */
2252 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
2253 test_breakpoint();
2254 }else
2255
2256 if( c=='c' && strncmp(azArg[0], "clone", n)==0 && nArg>1 && nArg<3 ){
2257 tryToClone(p, azArg[1]);
 
 
 
 
 
2258 }else
2259
2260 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
2261 struct callback_data data;
2262 char *zErrMsg = 0;
2263 open_db(p, 0);
2264 memcpy(&data, p, sizeof(data));
2265 data.showHeader = 1;
@@ -2274,15 +2297,20 @@
2274 sqlite3_free(zErrMsg);
2275 rc = 1;
2276 }
2277 }else
2278
2279 if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
2280 open_db(p, 0);
2281 /* When playing back a "dump", the content might appear in an order
2282 ** which causes immediate foreign key constraints to be violated.
2283 ** So disable foreign-key constraint enforcement to prevent problems. */
 
 
 
 
 
2284 fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
2285 fprintf(p->out, "BEGIN TRANSACTION;\n");
2286 p->writableSchema = 0;
2287 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
2288 p->nErr = 0;
@@ -2323,24 +2351,34 @@
2323 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
2324 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
2325 fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
2326 }else
2327
2328 if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
2329 p->echoOn = booleanValue(azArg[1]);
 
 
 
 
 
2330 }else
2331
2332 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){
2333 p->autoEQP = booleanValue(azArg[1]);
 
 
 
 
 
2334 }else
2335
2336 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
2337 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2338 rc = 2;
2339 }else
2340
2341 if( c=='e' && strncmp(azArg[0], "explain", n)==0 && nArg<3 ){
2342 int val = nArg>=2 ? booleanValue(azArg[1]) : 1;
2343 if(val == 1) {
2344 if(!p->explainPrev.valid) {
2345 p->explainPrev.valid = 1;
2346 p->explainPrev.mode = p->mode;
@@ -2371,25 +2409,26 @@
2371 p->showHeader = p->explainPrev.showHeader;
2372 memcpy(p->colWidth,p->explainPrev.colWidth,sizeof(p->colWidth));
2373 }
2374 }else
2375
2376 if( c=='h' && (strncmp(azArg[0], "header", n)==0 ||
2377 strncmp(azArg[0], "headers", n)==0) && nArg>1 && nArg<3 ){
2378 p->showHeader = booleanValue(azArg[1]);
 
 
 
 
2379 }else
2380
2381 if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
2382 fprintf(stderr,"%s",zHelp);
2383 if( HAS_TIMER ){
2384 fprintf(stderr,"%s",zTimerHelp);
2385 }
2386 }else
2387
2388 if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
2389 char *zTable = azArg[2]; /* Insert data into this table */
2390 char *zFile = azArg[1]; /* Name of file to extra content from */
2391 sqlite3_stmt *pStmt = NULL; /* A statement */
2392 int nCol; /* Number of columns in the table */
2393 int nByte; /* Number of bytes in an SQL string */
2394 int i, j; /* Loop counters */
2395 int needCommit; /* True to COMMIT or ROLLBACK at end */
@@ -2396,10 +2435,16 @@
2396 int nSep; /* Number of bytes in p->separator[] */
2397 char *zSql; /* An SQL statement */
2398 CSVReader sCsv; /* Reader context */
2399 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2400
 
 
 
 
 
 
2401 seenInterrupt = 0;
2402 memset(&sCsv, 0, sizeof(sCsv));
2403 open_db(p, 0);
2404 nSep = strlen30(p->separator);
2405 if( nSep==0 ){
@@ -2534,11 +2579,11 @@
2534 sqlite3_free(sCsv.z);
2535 sqlite3_finalize(pStmt);
2536 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
2537 }else
2538
2539 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2540 struct callback_data data;
2541 char *zErrMsg = 0;
2542 open_db(p, 0);
2543 memcpy(&data, p, sizeof(data));
2544 data.showHeader = 0;
@@ -2551,11 +2596,11 @@
2551 "SELECT name FROM sqlite_temp_master "
2552 "WHERE type='index' "
2553 "ORDER BY 1",
2554 callback, &data, &zErrMsg
2555 );
2556 }else{
2557 zShellStatic = azArg[1];
2558 rc = sqlite3_exec(p->db,
2559 "SELECT name FROM sqlite_master "
2560 "WHERE type='index' AND tbl_name LIKE shellstatic() "
2561 "UNION ALL "
@@ -2563,10 +2608,14 @@
2563 "WHERE type='index' AND tbl_name LIKE shellstatic() "
2564 "ORDER BY 1",
2565 callback, &data, &zErrMsg
2566 );
2567 zShellStatic = 0;
 
 
 
 
2568 }
2569 if( zErrMsg ){
2570 fprintf(stderr,"Error: %s\n", zErrMsg);
2571 sqlite3_free(zErrMsg);
2572 rc = 1;
@@ -2598,13 +2647,18 @@
2598 }
2599 }else
2600 #endif
2601
2602 #ifndef SQLITE_OMIT_LOAD_EXTENSION
2603 if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){
2604 const char *zFile, *zProc;
2605 char *zErrMsg = 0;
 
 
 
 
 
2606 zFile = azArg[1];
2607 zProc = nArg>=3 ? azArg[2] : 0;
2608 open_db(p, 0);
2609 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
2610 if( rc!=SQLITE_OK ){
@@ -2613,66 +2667,62 @@
2613 rc = 1;
2614 }
2615 }else
2616 #endif
2617
2618 if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
2619 const char *zFile = azArg[1];
2620 output_file_close(p->pLog);
2621 p->pLog = output_file_open(zFile);
 
 
 
 
 
2622 }else
2623
2624 if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){
2625 int n2 = strlen30(azArg[1]);
2626 if( (n2==4 && strncmp(azArg[1],"line",n2)==0)
2627 ||
2628 (n2==5 && strncmp(azArg[1],"lines",n2)==0) ){
2629 p->mode = MODE_Line;
2630 }else if( (n2==6 && strncmp(azArg[1],"column",n2)==0)
2631 ||
2632 (n2==7 && strncmp(azArg[1],"columns",n2)==0) ){
2633 p->mode = MODE_Column;
2634 }else if( n2==4 && strncmp(azArg[1],"list",n2)==0 ){
2635 p->mode = MODE_List;
2636 }else if( n2==4 && strncmp(azArg[1],"html",n2)==0 ){
2637 p->mode = MODE_Html;
2638 }else if( n2==3 && strncmp(azArg[1],"tcl",n2)==0 ){
2639 p->mode = MODE_Tcl;
2640 sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
2641 }else if( n2==3 && strncmp(azArg[1],"csv",n2)==0 ){
2642 p->mode = MODE_Csv;
2643 sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2644 }else if( n2==4 && strncmp(azArg[1],"tabs",n2)==0 ){
2645 p->mode = MODE_List;
2646 sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
2647 }else if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){
2648 p->mode = MODE_Insert;
2649 set_table_name(p, "table");
2650 }else {
2651 fprintf(stderr,"Error: mode should be one of: "
2652 "column csv html insert line list tabs tcl\n");
2653 rc = 1;
2654 }
2655 }else
2656
2657 if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==3 ){
2658 int n2 = strlen30(azArg[1]);
2659 if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){
2660 p->mode = MODE_Insert;
2661 set_table_name(p, azArg[2]);
2662 }else {
2663 fprintf(stderr, "Error: invalid arguments: "
2664 " \"%s\". Enter \".help\" for help\n", azArg[2]);
2665 rc = 1;
2666 }
2667 }else
2668
2669 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
2670 sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2671 "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2672 }else
2673
2674 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
2675 sqlite3 *savedDb = p->db;
2676 const char *zSavedFilename = p->zDbFilename;
2677 char *zNewFilename = 0;
2678 p->db = 0;
@@ -2689,36 +2739,49 @@
2689 p->db = savedDb;
2690 p->zDbFilename = zSavedFilename;
2691 }
2692 }else
2693
2694 if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
2695 if( p->outfile[0]=='|' ){
2696 pclose(p->out);
 
 
 
 
 
 
 
 
 
 
 
 
 
2697 }else{
2698 output_file_close(p->out);
2699 }
2700 p->outfile[0] = 0;
2701 if( azArg[1][0]=='|' ){
2702 p->out = popen(&azArg[1][1], "w");
2703 if( p->out==0 ){
2704 fprintf(stderr,"Error: cannot open pipe \"%s\"\n", &azArg[1][1]);
2705 p->out = stdout;
2706 rc = 1;
2707 }else{
2708 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
2709 }
2710 }else{
2711 p->out = output_file_open(azArg[1]);
2712 if( p->out==0 ){
2713 if( strcmp(azArg[1],"off")!=0 ){
2714 fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]);
2715 }
2716 p->out = stdout;
2717 rc = 1;
2718 } else {
2719 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
2720 }
2721 }
2722 }else
2723
2724 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
@@ -2728,47 +2791,57 @@
2728 fprintf(p->out, "%s", azArg[i]);
2729 }
2730 fprintf(p->out, "\n");
2731 }else
2732
2733 if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){
2734 if( nArg >= 2) {
2735 strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
2736 }
2737 if( nArg >= 3) {
2738 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
2739 }
2740 }else
2741
2742 if( c=='q' && strncmp(azArg[0], "quit", n)==0 && nArg==1 ){
2743 rc = 2;
2744 }else
2745
2746 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 && nArg==2 ){
2747 FILE *alt = fopen(azArg[1], "rb");
 
 
 
 
 
 
2748 if( alt==0 ){
2749 fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
2750 rc = 1;
2751 }else{
2752 rc = process_input(p, alt);
2753 fclose(alt);
2754 }
2755 }else
2756
2757 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 && nArg>1 && nArg<4){
2758 const char *zSrcFile;
2759 const char *zDb;
2760 sqlite3 *pSrc;
2761 sqlite3_backup *pBackup;
2762 int nTimeout = 0;
2763
2764 if( nArg==2 ){
2765 zSrcFile = azArg[1];
2766 zDb = "main";
2767 }else{
2768 zSrcFile = azArg[2];
2769 zDb = azArg[1];
 
 
 
 
2770 }
2771 rc = sqlite3_open(zSrcFile, &pSrc);
2772 if( rc!=SQLITE_OK ){
2773 fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
2774 sqlite3_close(pSrc);
@@ -2799,18 +2872,18 @@
2799 rc = 1;
2800 }
2801 sqlite3_close(pSrc);
2802 }else
2803
2804 if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
2805 struct callback_data data;
2806 char *zErrMsg = 0;
2807 open_db(p, 0);
2808 memcpy(&data, p, sizeof(data));
2809 data.showHeader = 0;
2810 data.mode = MODE_Semi;
2811 if( nArg>1 ){
2812 int i;
2813 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
2814 if( strcmp(azArg[1],"sqlite_master")==0 ){
2815 char *new_argv[2], *new_colv[2];
2816 new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -2850,20 +2923,24 @@
2850 " AND type!='meta' AND sql NOTNULL "
2851 "ORDER BY rowid",
2852 callback, &data, &zErrMsg);
2853 zShellStatic = 0;
2854 }
2855 }else{
2856 rc = sqlite3_exec(p->db,
2857 "SELECT sql FROM "
2858 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
2859 " FROM sqlite_master UNION ALL"
2860 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
2861 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
2862 "ORDER BY rowid",
2863 callback, &data, &zErrMsg
2864 );
 
 
 
 
2865 }
2866 if( zErrMsg ){
2867 fprintf(stderr,"Error: %s\n", zErrMsg);
2868 sqlite3_free(zErrMsg);
2869 rc = 1;
@@ -2889,38 +2966,53 @@
2889 if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
2890 int i; sqlite3_int64 v;
2891 for(i=1; i<nArg; i++){
2892 char zBuf[200];
2893 v = integerValue(azArg[i]);
2894 sqlite3_snprintf(sizeof(zBuf), zBuf, "%s: %lld 0x%llx\n", azArg[i], v, v);
2895 fprintf(p->out, "%s", zBuf);
2896 }
2897 }
2898 }else
2899 #endif
2900
2901 if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
2902 sqlite3_snprintf(sizeof(p->separator), p->separator,
2903 "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
 
 
 
 
 
2904 }else
2905
2906 if( c=='s'
2907 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2908 && nArg>=2
2909 ){
2910 char *zCmd;
2911 int i;
2912 zCmd = sqlite3_mprintf("\"%s\"", azArg[1]);
 
 
 
 
 
2913 for(i=2; i<nArg; i++){
2914 zCmd = sqlite3_mprintf("%z \"%s\"", zCmd, azArg[i]);
 
2915 }
2916 system(zCmd);
2917 sqlite3_free(zCmd);
2918 }else
2919
2920 if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
2921 int i;
 
 
 
 
 
2922 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
2923 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
2924 fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
2925 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
2926 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
@@ -2938,15 +3030,20 @@
2938 fprintf(p->out,"%d ",p->colWidth[i]);
2939 }
2940 fprintf(p->out,"\n");
2941 }else
2942
2943 if( c=='s' && strncmp(azArg[0], "stats", n)==0 && nArg>1 && nArg<3 ){
2944 p->statsOn = booleanValue(azArg[1]);
 
 
 
 
 
2945 }else
2946
2947 if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){
2948 sqlite3_stmt *pStmt;
2949 char **azResult;
2950 int nRow, nAlloc;
2951 char *zSql = 0;
2952 int ii;
@@ -3148,24 +3245,36 @@
3148 break;
3149 }
3150 }
3151 }else
3152
3153 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
3154 open_db(p, 0);
3155 sqlite3_busy_timeout(p->db, (int)integerValue(azArg[1]));
3156 }else
3157
3158 if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
3159 && nArg==2
3160 ){
3161 enableTimer = booleanValue(azArg[1]);
 
 
 
 
 
 
 
3162 }else
3163
3164 if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
3165 open_db(p, 0);
3166 output_file_close(p->traceOut);
 
 
 
 
 
3167 p->traceOut = output_file_open(azArg[1]);
3168 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
3169 if( p->traceOut==0 ){
3170 sqlite3_trace(p->db, 0, 0);
3171 }else{
@@ -3192,15 +3301,15 @@
3192 }else
3193
3194 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
3195 if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
3196 extern int sqlite3WhereTrace;
3197 sqlite3WhereTrace = booleanValue(azArg[1]);
3198 }else
3199 #endif
3200
3201 if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
3202 int j;
3203 assert( nArg<=ArraySize(azArg) );
3204 for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
3205 p->colWidth[j-1] = (int)integerValue(azArg[j]);
3206 }
@@ -3210,10 +3319,15 @@
3210 fprintf(stderr, "Error: unknown command or invalid arguments: "
3211 " \"%s\". Enter \".help\" for help\n", azArg[0]);
3212 rc = 1;
3213 }
3214
 
 
 
 
 
3215 return rc;
3216 }
3217
3218 /*
3219 ** Return TRUE if a semicolon occurs anywhere in the first N characters
@@ -3377,10 +3491,14 @@
3377 fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
3378 }
3379 errCnt++;
3380 }
3381 nSql = 0;
 
 
 
 
3382 }else if( nSql && _all_whitespace(zSql) ){
3383 if( p->echoOn ) printf("%s\n", zSql);
3384 nSql = 0;
3385 }
3386 }
3387
--- src/shell.c
+++ src/shell.c
@@ -444,12 +444,13 @@
444 ** state and mode information.
445 */
446 struct callback_data {
447 sqlite3 *db; /* The database */
448 int echoOn; /* True to echo input commands */
449 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
450 int statsOn; /* True to display memory stats before each finalize */
451 int outCount; /* Revert to stdout when reaching zero */
452 int cnt; /* Number of records displayed so far */
453 FILE *out; /* Write results here */
454 FILE *traceOut; /* Output for sqlite3_trace() */
455 int nErr; /* Number of errors seen */
456 int mode; /* An output mode setting */
@@ -876,11 +877,12 @@
877 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
878 fprintf(p->out,"%sNULL",zSep);
879 }else if( aiType && aiType[i]==SQLITE_TEXT ){
880 if( zSep[0] ) fprintf(p->out,"%s",zSep);
881 output_quoted_string(p->out, azArg[i]);
882 }else if( aiType && (aiType[i]==SQLITE_INTEGER
883 || aiType[i]==SQLITE_FLOAT) ){
884 fprintf(p->out,"%s%s",zSep, azArg[i]);
885 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
886 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
887 int nBlob = sqlite3_column_bytes(p->pStmt, i);
888 if( zSep[0] ) fprintf(p->out,"%s",zSep);
@@ -1196,11 +1198,11 @@
1198 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1199 int iOp; /* Index of operation in p->aiIndent[] */
1200
1201 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
1202 "NextIfOpen", "PrevIfOpen", 0 };
1203 const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead", "Rewind", 0 };
1204 const char *azGoto[] = { "Goto", 0 };
1205
1206 /* Try to figure out if this is really an EXPLAIN statement. If this
1207 ** cannot be verified, return early. */
1208 zSql = sqlite3_sql(pSql);
@@ -1568,21 +1570,21 @@
1570 /*
1571 ** Text of a help message
1572 */
1573 static char zHelp[] =
1574 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1575 ".bail on|off Stop after hitting an error. Default OFF\n"
1576 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1577 ".databases List names and files of attached databases\n"
1578 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1579 " If TABLE specified, only dump tables matching\n"
1580 " LIKE pattern TABLE.\n"
1581 ".echo on|off Turn command echo on or off\n"
1582 ".exit Exit this program\n"
1583 ".explain ?on|off? Turn output mode suitable for EXPLAIN on or off.\n"
1584 " With no args, it turns EXPLAIN on.\n"
1585 ".headers on|off Turn display of headers on or off\n"
1586 ".help Show this message\n"
1587 ".import FILE TABLE Import data from FILE into TABLE\n"
1588 ".indices ?TABLE? Show names of all indices\n"
1589 " If TABLE specified, only show indices for tables\n"
1590 " matching LIKE pattern TABLE.\n"
@@ -1601,13 +1603,13 @@
1603 " line One value per line\n"
1604 " list Values delimited by .separator string\n"
1605 " tabs Tab-separated values\n"
1606 " tcl TCL list elements\n"
1607 ".nullvalue STRING Use STRING in place of NULL values\n"
1608 ".once FILENAME Output for the next SQL command only to FILENAME\n"
1609 ".open ?FILENAME? Close existing database and reopen FILENAME\n"
1610 ".output ?FILENAME? Send output to FILENAME or stdout\n"
 
1611 ".print STRING... Print literal STRING\n"
1612 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1613 ".quit Exit this program\n"
1614 ".read FILENAME Execute SQL in FILENAME\n"
1615 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
@@ -1616,26 +1618,23 @@
1618 " If TABLE specified, only show tables matching\n"
1619 " LIKE pattern TABLE.\n"
1620 ".separator STRING Change separator used by output mode and .import\n"
1621 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1622 ".show Show the current values for various settings\n"
1623 ".stats on|off Turn stats on or off\n"
1624 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1625 ".tables ?TABLE? List names of tables\n"
1626 " If TABLE specified, only list tables matching\n"
1627 " LIKE pattern TABLE.\n"
1628 ".timeout MS Try opening locked tables for MS milliseconds\n"
1629 ".timer on|off Turn SQL timer on or off\n"
1630 ".trace FILE|off Output each SQL statement as it is run\n"
1631 ".vfsname ?AUX? Print the name of the VFS stack\n"
1632 ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
1633 " Negative values right-justify\n"
1634 ;
1635
 
 
 
 
1636 /* Forward reference */
1637 static int process_input(struct callback_data *p, FILE *in);
1638
1639 /*
1640 ** Make sure the database is open. If it is not, then open it. If
@@ -1673,10 +1672,11 @@
1672 ** \\ -> backslash
1673 */
1674 static void resolve_backslashes(char *z){
1675 int i, j;
1676 char c;
1677 while( *z && *z!='\\' ) z++;
1678 for(i=j=0; (c = z[i])!=0; i++, j++){
1679 if( c=='\\' ){
1680 c = z[++i];
1681 if( c=='n' ){
1682 c = '\n';
@@ -1698,11 +1698,11 @@
1698 }
1699 }
1700 }
1701 z[j] = c;
1702 }
1703 if( j<i ) z[j] = 0;
1704 }
1705
1706 /*
1707 ** Return the value of a hexadecimal digit. Return -1 if the input
1708 ** is not a hex digit.
@@ -2141,10 +2141,23 @@
2141 sqlite3_exec(newDb, "COMMIT;", 0, 0, 0);
2142 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
2143 }
2144 sqlite3_close(newDb);
2145 }
2146
2147 /*
2148 ** Change the output file back to stdout
2149 */
2150 static void output_reset(struct callback_data *p){
2151 if( p->outfile[0]=='|' ){
2152 pclose(p->out);
2153 }else{
2154 output_file_close(p->out);
2155 }
2156 p->outfile[0] = 0;
2157 p->out = stdout;
2158 }
2159
2160 /*
2161 ** If an input line begins with "." then invoke this routine to
2162 ** process that line.
2163 **
@@ -2240,26 +2253,36 @@
2253 rc = 1;
2254 }
2255 sqlite3_close(pDest);
2256 }else
2257
2258 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
2259 if( nArg==2 ){
2260 bail_on_error = booleanValue(azArg[1]);
2261 }else{
2262 fprintf(stderr, "Usage: .bail on|off\n");
2263 rc = 1;
2264 }
2265 }else
2266
2267 /* The undocumented ".breakpoint" command causes a call to the no-op
2268 ** routine named test_breakpoint().
2269 */
2270 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
2271 test_breakpoint();
2272 }else
2273
2274 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
2275 if( nArg==2 ){
2276 tryToClone(p, azArg[1]);
2277 }else{
2278 fprintf(stderr, "Usage: .clone FILENAME\n");
2279 rc = 1;
2280 }
2281 }else
2282
2283 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
2284 struct callback_data data;
2285 char *zErrMsg = 0;
2286 open_db(p, 0);
2287 memcpy(&data, p, sizeof(data));
2288 data.showHeader = 1;
@@ -2274,15 +2297,20 @@
2297 sqlite3_free(zErrMsg);
2298 rc = 1;
2299 }
2300 }else
2301
2302 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
2303 open_db(p, 0);
2304 /* When playing back a "dump", the content might appear in an order
2305 ** which causes immediate foreign key constraints to be violated.
2306 ** So disable foreign-key constraint enforcement to prevent problems. */
2307 if( nArg!=1 && nArg!=2 ){
2308 fprintf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
2309 rc = 1;
2310 goto meta_command_exit;
2311 }
2312 fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
2313 fprintf(p->out, "BEGIN TRANSACTION;\n");
2314 p->writableSchema = 0;
2315 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
2316 p->nErr = 0;
@@ -2323,24 +2351,34 @@
2351 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
2352 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
2353 fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
2354 }else
2355
2356 if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
2357 if( nArg==2 ){
2358 p->echoOn = booleanValue(azArg[1]);
2359 }else{
2360 fprintf(stderr, "Usage: .echo on|off\n");
2361 rc = 1;
2362 }
2363 }else
2364
2365 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
2366 if( nArg==2 ){
2367 p->autoEQP = booleanValue(azArg[1]);
2368 }else{
2369 fprintf(stderr, "Usage: .eqp on|off\n");
2370 rc = 1;
2371 }
2372 }else
2373
2374 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
2375 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2376 rc = 2;
2377 }else
2378
2379 if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
2380 int val = nArg>=2 ? booleanValue(azArg[1]) : 1;
2381 if(val == 1) {
2382 if(!p->explainPrev.valid) {
2383 p->explainPrev.valid = 1;
2384 p->explainPrev.mode = p->mode;
@@ -2371,25 +2409,26 @@
2409 p->showHeader = p->explainPrev.showHeader;
2410 memcpy(p->colWidth,p->explainPrev.colWidth,sizeof(p->colWidth));
2411 }
2412 }else
2413
2414 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
2415 if( nArg==2 ){
2416 p->showHeader = booleanValue(azArg[1]);
2417 }else{
2418 fprintf(stderr, "Usage: .headers on|off\n");
2419 rc = 1;
2420 }
2421 }else
2422
2423 if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
2424 fprintf(p->out, "%s", zHelp);
 
 
 
2425 }else
2426
2427 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
2428 char *zTable; /* Insert data into this table */
2429 char *zFile; /* Name of file to extra content from */
2430 sqlite3_stmt *pStmt = NULL; /* A statement */
2431 int nCol; /* Number of columns in the table */
2432 int nByte; /* Number of bytes in an SQL string */
2433 int i, j; /* Loop counters */
2434 int needCommit; /* True to COMMIT or ROLLBACK at end */
@@ -2396,10 +2435,16 @@
2435 int nSep; /* Number of bytes in p->separator[] */
2436 char *zSql; /* An SQL statement */
2437 CSVReader sCsv; /* Reader context */
2438 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2439
2440 if( nArg!=3 ){
2441 fprintf(stderr, "Usage: .import FILE TABLE\n");
2442 goto meta_command_exit;
2443 }
2444 zFile = azArg[1];
2445 zTable = azArg[2];
2446 seenInterrupt = 0;
2447 memset(&sCsv, 0, sizeof(sCsv));
2448 open_db(p, 0);
2449 nSep = strlen30(p->separator);
2450 if( nSep==0 ){
@@ -2534,11 +2579,11 @@
2579 sqlite3_free(sCsv.z);
2580 sqlite3_finalize(pStmt);
2581 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
2582 }else
2583
2584 if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
2585 struct callback_data data;
2586 char *zErrMsg = 0;
2587 open_db(p, 0);
2588 memcpy(&data, p, sizeof(data));
2589 data.showHeader = 0;
@@ -2551,11 +2596,11 @@
2596 "SELECT name FROM sqlite_temp_master "
2597 "WHERE type='index' "
2598 "ORDER BY 1",
2599 callback, &data, &zErrMsg
2600 );
2601 }else if( nArg==2 ){
2602 zShellStatic = azArg[1];
2603 rc = sqlite3_exec(p->db,
2604 "SELECT name FROM sqlite_master "
2605 "WHERE type='index' AND tbl_name LIKE shellstatic() "
2606 "UNION ALL "
@@ -2563,10 +2608,14 @@
2608 "WHERE type='index' AND tbl_name LIKE shellstatic() "
2609 "ORDER BY 1",
2610 callback, &data, &zErrMsg
2611 );
2612 zShellStatic = 0;
2613 }else{
2614 fprintf(stderr, "Usage: .indices ?LIKE-PATTERN?\n");
2615 rc = 1;
2616 goto meta_command_exit;
2617 }
2618 if( zErrMsg ){
2619 fprintf(stderr,"Error: %s\n", zErrMsg);
2620 sqlite3_free(zErrMsg);
2621 rc = 1;
@@ -2598,13 +2647,18 @@
2647 }
2648 }else
2649 #endif
2650
2651 #ifndef SQLITE_OMIT_LOAD_EXTENSION
2652 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
2653 const char *zFile, *zProc;
2654 char *zErrMsg = 0;
2655 if( nArg<2 ){
2656 fprintf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
2657 rc = 1;
2658 goto meta_command_exit;
2659 }
2660 zFile = azArg[1];
2661 zProc = nArg>=3 ? azArg[2] : 0;
2662 open_db(p, 0);
2663 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
2664 if( rc!=SQLITE_OK ){
@@ -2613,66 +2667,62 @@
2667 rc = 1;
2668 }
2669 }else
2670 #endif
2671
2672 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
2673 if( nArg!=2 ){
2674 fprintf(stderr, "Usage: .log FILENAME\n");
2675 rc = 1;
2676 }else{
2677 const char *zFile = azArg[1];
2678 output_file_close(p->pLog);
2679 p->pLog = output_file_open(zFile);
2680 }
2681 }else
2682
2683 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
2684 const char *zMode = nArg>=2 ? azArg[1] : "";
2685 int n2 = (int)strlen(zMode);
2686 int c2 = zMode[0];
2687 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
2688 p->mode = MODE_Line;
2689 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
 
 
2690 p->mode = MODE_Column;
2691 }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
2692 p->mode = MODE_List;
2693 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
2694 p->mode = MODE_Html;
2695 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
2696 p->mode = MODE_Tcl;
2697 sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
2698 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
2699 p->mode = MODE_Csv;
2700 sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2701 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
2702 p->mode = MODE_List;
2703 sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
2704 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
2705 p->mode = MODE_Insert;
2706 set_table_name(p, nArg>=3 ? azArg[2] : "table");
2707 }else {
2708 fprintf(stderr,"Error: mode should be one of: "
2709 "column csv html insert line list tabs tcl\n");
2710 rc = 1;
2711 }
2712 }else
2713
2714 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2715 if( nArg==2 ){
2716 sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2717 "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2718 }else{
2719 fprintf(stderr, "Usage: .nullvalue STRING\n");
 
 
2720 rc = 1;
2721 }
2722 }else
2723
 
 
 
 
 
2724 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
2725 sqlite3 *savedDb = p->db;
2726 const char *zSavedFilename = p->zDbFilename;
2727 char *zNewFilename = 0;
2728 p->db = 0;
@@ -2689,36 +2739,49 @@
2739 p->db = savedDb;
2740 p->zDbFilename = zSavedFilename;
2741 }
2742 }else
2743
2744 if( c=='o'
2745 && (strncmp(azArg[0], "output", n)==0 || strncmp(azArg[0], "once", n)==0)
2746 ){
2747 const char *zFile = nArg>=2 ? azArg[1] : "stdout";
2748 if( nArg>2 ){
2749 fprintf(stderr, "Usage: .%s FILE\n", azArg[0]);
2750 rc = 1;
2751 goto meta_command_exit;
2752 }
2753 if( n>1 && strncmp(azArg[0], "once", n)==0 ){
2754 if( nArg<2 ){
2755 fprintf(stderr, "Usage: .once FILE\n");
2756 rc = 1;
2757 goto meta_command_exit;
2758 }
2759 p->outCount = 2;
2760 }else{
2761 p->outCount = 0;
2762 }
2763 output_reset(p);
2764 if( zFile[0]=='|' ){
2765 p->out = popen(zFile + 1, "w");
2766 if( p->out==0 ){
2767 fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
2768 p->out = stdout;
2769 rc = 1;
2770 }else{
2771 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2772 }
2773 }else{
2774 p->out = output_file_open(zFile);
2775 if( p->out==0 ){
2776 if( strcmp(zFile,"off")!=0 ){
2777 fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
2778 }
2779 p->out = stdout;
2780 rc = 1;
2781 } else {
2782 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2783 }
2784 }
2785 }else
2786
2787 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
@@ -2728,47 +2791,57 @@
2791 fprintf(p->out, "%s", azArg[i]);
2792 }
2793 fprintf(p->out, "\n");
2794 }else
2795
2796 if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
2797 if( nArg >= 2) {
2798 strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
2799 }
2800 if( nArg >= 3) {
2801 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
2802 }
2803 }else
2804
2805 if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
2806 rc = 2;
2807 }else
2808
2809 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
2810 FILE *alt;
2811 if( nArg!=2 ){
2812 fprintf(stderr, "Usage: .read FILE\n");
2813 rc = 1;
2814 goto meta_command_exit;
2815 }
2816 alt = fopen(azArg[1], "rb");
2817 if( alt==0 ){
2818 fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
2819 rc = 1;
2820 }else{
2821 rc = process_input(p, alt);
2822 fclose(alt);
2823 }
2824 }else
2825
2826 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
2827 const char *zSrcFile;
2828 const char *zDb;
2829 sqlite3 *pSrc;
2830 sqlite3_backup *pBackup;
2831 int nTimeout = 0;
2832
2833 if( nArg==2 ){
2834 zSrcFile = azArg[1];
2835 zDb = "main";
2836 }else if( nArg==3 ){
2837 zSrcFile = azArg[2];
2838 zDb = azArg[1];
2839 }else{
2840 fprintf(stderr, "Usage: .restore ?DB? FILE\n");
2841 rc = 1;
2842 goto meta_command_exit;
2843 }
2844 rc = sqlite3_open(zSrcFile, &pSrc);
2845 if( rc!=SQLITE_OK ){
2846 fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
2847 sqlite3_close(pSrc);
@@ -2799,18 +2872,18 @@
2872 rc = 1;
2873 }
2874 sqlite3_close(pSrc);
2875 }else
2876
2877 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
2878 struct callback_data data;
2879 char *zErrMsg = 0;
2880 open_db(p, 0);
2881 memcpy(&data, p, sizeof(data));
2882 data.showHeader = 0;
2883 data.mode = MODE_Semi;
2884 if( nArg==2 ){
2885 int i;
2886 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
2887 if( strcmp(azArg[1],"sqlite_master")==0 ){
2888 char *new_argv[2], *new_colv[2];
2889 new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -2850,20 +2923,24 @@
2923 " AND type!='meta' AND sql NOTNULL "
2924 "ORDER BY rowid",
2925 callback, &data, &zErrMsg);
2926 zShellStatic = 0;
2927 }
2928 }else if( nArg==1 ){
2929 rc = sqlite3_exec(p->db,
2930 "SELECT sql FROM "
2931 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
2932 " FROM sqlite_master UNION ALL"
2933 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
2934 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
2935 "ORDER BY rowid",
2936 callback, &data, &zErrMsg
2937 );
2938 }else{
2939 fprintf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
2940 rc = 1;
2941 goto meta_command_exit;
2942 }
2943 if( zErrMsg ){
2944 fprintf(stderr,"Error: %s\n", zErrMsg);
2945 sqlite3_free(zErrMsg);
2946 rc = 1;
@@ -2889,38 +2966,53 @@
2966 if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
2967 int i; sqlite3_int64 v;
2968 for(i=1; i<nArg; i++){
2969 char zBuf[200];
2970 v = integerValue(azArg[i]);
2971 sqlite3_snprintf(sizeof(zBuf),zBuf,"%s: %lld 0x%llx\n", azArg[i],v,v);
2972 fprintf(p->out, "%s", zBuf);
2973 }
2974 }
2975 }else
2976 #endif
2977
2978 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
2979 if( nArg==2 ){
2980 sqlite3_snprintf(sizeof(p->separator), p->separator,
2981 "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
2982 }else{
2983 fprintf(stderr, "Usage: .separator STRING\n");
2984 rc = 1;
2985 }
2986 }else
2987
2988 if( c=='s'
2989 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
 
2990 ){
2991 char *zCmd;
2992 int i;
2993 if( nArg<2 ){
2994 fprintf(stderr, "Usage: .system COMMAND\n");
2995 rc = 1;
2996 goto meta_command_exit;
2997 }
2998 zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
2999 for(i=2; i<nArg; i++){
3000 zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
3001 zCmd, azArg[i]);
3002 }
3003 (void)system(zCmd);
3004 sqlite3_free(zCmd);
3005 }else
3006
3007 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
3008 int i;
3009 if( nArg!=1 ){
3010 fprintf(stderr, "Usage: .show\n");
3011 rc = 1;
3012 goto meta_command_exit;
3013 }
3014 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
3015 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
3016 fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
3017 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
3018 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
@@ -2938,15 +3030,20 @@
3030 fprintf(p->out,"%d ",p->colWidth[i]);
3031 }
3032 fprintf(p->out,"\n");
3033 }else
3034
3035 if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
3036 if( nArg==2 ){
3037 p->statsOn = booleanValue(azArg[1]);
3038 }else{
3039 fprintf(stderr, "Usage: .stats on|off\n");
3040 rc = 1;
3041 }
3042 }else
3043
3044 if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
3045 sqlite3_stmt *pStmt;
3046 char **azResult;
3047 int nRow, nAlloc;
3048 char *zSql = 0;
3049 int ii;
@@ -3148,24 +3245,36 @@
3245 break;
3246 }
3247 }
3248 }else
3249
3250 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 ){
3251 open_db(p, 0);
3252 sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
3253 }else
3254
3255 if( c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 ){
3256 if( nArg==2 ){
3257 enableTimer = booleanValue(azArg[1]);
3258 if( enableTimer && !HAS_TIMER ){
3259 fprintf(stderr, "Error: timer not available on this system.\n");
3260 enableTimer = 0;
3261 }
3262 }else{
3263 fprintf(stderr, "Usage: .timer on|off\n");
3264 rc = 1;
3265 }
3266 }else
3267
3268 if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
3269 open_db(p, 0);
3270 output_file_close(p->traceOut);
3271 if( nArg!=2 ){
3272 fprintf(stderr, "Usage: .trace FILE|off\n");
3273 rc = 1;
3274 goto meta_command_exit;
3275 }
3276 p->traceOut = output_file_open(azArg[1]);
3277 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
3278 if( p->traceOut==0 ){
3279 sqlite3_trace(p->db, 0, 0);
3280 }else{
@@ -3192,15 +3301,15 @@
3301 }else
3302
3303 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
3304 if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
3305 extern int sqlite3WhereTrace;
3306 sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
3307 }else
3308 #endif
3309
3310 if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
3311 int j;
3312 assert( nArg<=ArraySize(azArg) );
3313 for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
3314 p->colWidth[j-1] = (int)integerValue(azArg[j]);
3315 }
@@ -3210,10 +3319,15 @@
3319 fprintf(stderr, "Error: unknown command or invalid arguments: "
3320 " \"%s\". Enter \".help\" for help\n", azArg[0]);
3321 rc = 1;
3322 }
3323
3324 meta_command_exit:
3325 if( p->outCount ){
3326 p->outCount--;
3327 if( p->outCount==0 ) output_reset(p);
3328 }
3329 return rc;
3330 }
3331
3332 /*
3333 ** Return TRUE if a semicolon occurs anywhere in the first N characters
@@ -3377,10 +3491,14 @@
3491 fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
3492 }
3493 errCnt++;
3494 }
3495 nSql = 0;
3496 if( p->outCount ){
3497 output_reset(p);
3498 p->outCount = 0;
3499 }
3500 }else if( nSql && _all_whitespace(zSql) ){
3501 if( p->echoOn ) printf("%s\n", zSql);
3502 nSql = 0;
3503 }
3504 }
3505
+30 -3
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222222
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223223
** [sqlite_version()] and [sqlite_source_id()].
224224
*/
225225
#define SQLITE_VERSION "3.8.5"
226226
#define SQLITE_VERSION_NUMBER 3008005
227
-#define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
227
+#define SQLITE_SOURCE_ID "2014-06-02 11:26:33 9f18b303cd1bc5779d82669884f802c7889b4947"
228228
229229
/*
230230
** CAPI3REF: Run-Time Library Version Numbers
231231
** KEYWORDS: sqlite3_version, sqlite3_sourceid
232232
**
@@ -1060,10 +1060,16 @@
10601060
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
10611061
** pointer to an integer and it writes a boolean into that integer depending
10621062
** on whether or not the file has been renamed, moved, or deleted since it
10631063
** was first opened.
10641064
**
1065
+** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
1066
+** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
1067
+** opcode causes the xFileControl method to swap the file handle with the one
1068
+** pointed to by the pArg argument. This capability is used during testing
1069
+** and only needs to be supported when SQLITE_TEST is defined.
1070
+**
10651071
** </ul>
10661072
*/
10671073
#define SQLITE_FCNTL_LOCKSTATE 1
10681074
#define SQLITE_GET_LOCKPROXYFILE 2
10691075
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -1083,10 +1089,11 @@
10831089
#define SQLITE_FCNTL_MMAP_SIZE 18
10841090
#define SQLITE_FCNTL_TRACE 19
10851091
#define SQLITE_FCNTL_HAS_MOVED 20
10861092
#define SQLITE_FCNTL_SYNC 21
10871093
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
1094
+#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
10881095
10891096
/*
10901097
** CAPI3REF: Mutex Handle
10911098
**
10921099
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -20986,10 +20993,11 @@
2098620993
zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
2098720994
}else{
2098820995
zNew = sqlite3_realloc(zOld, p->nAlloc);
2098920996
}
2099020997
if( zNew ){
20998
+ assert( p->zText!=0 || p->nChar==0 );
2099120999
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2099221000
p->zText = zNew;
2099321001
}else{
2099421002
sqlite3StrAccumReset(p);
2099521003
setStrAccumError(p, STRACCUM_NOMEM);
@@ -34539,12 +34547,20 @@
3453934547
** around problems caused by indexing and/or anti-virus software on
3454034548
** Windows systems.
3454134549
** If you are using this code as a model for alternative VFSes, do not
3454234550
** copy this retry logic. It is a hack intended for Windows only.
3454334551
*/
34552
+ lastErrno = osGetLastError();
3454434553
OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, result=%d\n",
3454534554
pFile->h, cnt, res));
34555
+ if( lastErrno==ERROR_INVALID_HANDLE ){
34556
+ pFile->lastErrno = lastErrno;
34557
+ rc = SQLITE_IOERR_LOCK;
34558
+ OSTRACE(("LOCK-FAIL file=%p, count=%d, rc=%s\n",
34559
+ pFile->h, cnt, sqlite3ErrName(rc)));
34560
+ return rc;
34561
+ }
3454634562
if( cnt ) sqlite3_win32_sleep(1);
3454734563
}
3454834564
gotPendingLock = res;
3454934565
if( !res ){
3455034566
lastErrno = osGetLastError();
@@ -34784,10 +34800,21 @@
3478434800
a[1] = winIoerrRetryDelay;
3478534801
}
3478634802
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
3478734803
return SQLITE_OK;
3478834804
}
34805
+#ifdef SQLITE_TEST
34806
+ case SQLITE_FCNTL_WIN32_SET_HANDLE: {
34807
+ LPHANDLE phFile = (LPHANDLE)pArg;
34808
+ HANDLE hOldFile = pFile->h;
34809
+ pFile->h = *phFile;
34810
+ *phFile = hOldFile;
34811
+ OSTRACE(("FCNTL oldFile=%p, newFile=%p, rc=SQLITE_OK\n",
34812
+ hOldFile, pFile->h));
34813
+ return SQLITE_OK;
34814
+ }
34815
+#endif
3478934816
case SQLITE_FCNTL_TEMPFILENAME: {
3479034817
char *zTFile = 0;
3479134818
int rc = winGetTempname(pFile->pVfs, &zTFile);
3479234819
if( rc==SQLITE_OK ){
3479334820
*(char**)pArg = zTFile;
@@ -115311,11 +115338,11 @@
115311115338
db = pParse->db;
115312115339
nLoop = pWInfo->nLevel;
115313115340
/* TUNING: For simple queries, only the best path is tracked.
115314115341
** For 2-way joins, the 5 best paths are followed.
115315115342
** For joins of 3 or more tables, track the 10 best paths */
115316
- mxChoice = (nLoop==1) ? 1 : (nLoop==2 ? 5 : 10);
115343
+ mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10);
115317115344
assert( nLoop<=pWInfo->pTabList->nSrc );
115318115345
WHERETRACE(0x002, ("---- begin solver\n"));
115319115346
115320115347
/* Allocate and initialize space for aTo and aFrom */
115321115348
ii = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2;
@@ -115341,11 +115368,11 @@
115341115368
** to sqlite3WhereBegin() was concerned about sorting */
115342115369
if( pWInfo->pOrderBy==0 || nRowEst==0 ){
115343115370
aFrom[0].isOrdered = 0;
115344115371
nOrderBy = 0;
115345115372
}else{
115346
- aFrom[0].isOrdered = -1;
115373
+ aFrom[0].isOrdered = nLoop>0 ? -1 : 1;
115347115374
nOrderBy = pWInfo->pOrderBy->nExpr;
115348115375
}
115349115376
115350115377
/* Compute successively longer WherePaths using the previous generation
115351115378
** of WherePaths as the basis for the next. Keep track of the mxChoice
115352115379
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.5"
226 #define SQLITE_VERSION_NUMBER 3008005
227 #define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -1060,10 +1060,16 @@
1060 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
1061 ** pointer to an integer and it writes a boolean into that integer depending
1062 ** on whether or not the file has been renamed, moved, or deleted since it
1063 ** was first opened.
1064 **
 
 
 
 
 
 
1065 ** </ul>
1066 */
1067 #define SQLITE_FCNTL_LOCKSTATE 1
1068 #define SQLITE_GET_LOCKPROXYFILE 2
1069 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -1083,10 +1089,11 @@
1083 #define SQLITE_FCNTL_MMAP_SIZE 18
1084 #define SQLITE_FCNTL_TRACE 19
1085 #define SQLITE_FCNTL_HAS_MOVED 20
1086 #define SQLITE_FCNTL_SYNC 21
1087 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
 
1088
1089 /*
1090 ** CAPI3REF: Mutex Handle
1091 **
1092 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -20986,10 +20993,11 @@
20986 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
20987 }else{
20988 zNew = sqlite3_realloc(zOld, p->nAlloc);
20989 }
20990 if( zNew ){
 
20991 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20992 p->zText = zNew;
20993 }else{
20994 sqlite3StrAccumReset(p);
20995 setStrAccumError(p, STRACCUM_NOMEM);
@@ -34539,12 +34547,20 @@
34539 ** around problems caused by indexing and/or anti-virus software on
34540 ** Windows systems.
34541 ** If you are using this code as a model for alternative VFSes, do not
34542 ** copy this retry logic. It is a hack intended for Windows only.
34543 */
 
34544 OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, result=%d\n",
34545 pFile->h, cnt, res));
 
 
 
 
 
 
 
34546 if( cnt ) sqlite3_win32_sleep(1);
34547 }
34548 gotPendingLock = res;
34549 if( !res ){
34550 lastErrno = osGetLastError();
@@ -34784,10 +34800,21 @@
34784 a[1] = winIoerrRetryDelay;
34785 }
34786 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34787 return SQLITE_OK;
34788 }
 
 
 
 
 
 
 
 
 
 
 
34789 case SQLITE_FCNTL_TEMPFILENAME: {
34790 char *zTFile = 0;
34791 int rc = winGetTempname(pFile->pVfs, &zTFile);
34792 if( rc==SQLITE_OK ){
34793 *(char**)pArg = zTFile;
@@ -115311,11 +115338,11 @@
115311 db = pParse->db;
115312 nLoop = pWInfo->nLevel;
115313 /* TUNING: For simple queries, only the best path is tracked.
115314 ** For 2-way joins, the 5 best paths are followed.
115315 ** For joins of 3 or more tables, track the 10 best paths */
115316 mxChoice = (nLoop==1) ? 1 : (nLoop==2 ? 5 : 10);
115317 assert( nLoop<=pWInfo->pTabList->nSrc );
115318 WHERETRACE(0x002, ("---- begin solver\n"));
115319
115320 /* Allocate and initialize space for aTo and aFrom */
115321 ii = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2;
@@ -115341,11 +115368,11 @@
115341 ** to sqlite3WhereBegin() was concerned about sorting */
115342 if( pWInfo->pOrderBy==0 || nRowEst==0 ){
115343 aFrom[0].isOrdered = 0;
115344 nOrderBy = 0;
115345 }else{
115346 aFrom[0].isOrdered = -1;
115347 nOrderBy = pWInfo->pOrderBy->nExpr;
115348 }
115349
115350 /* Compute successively longer WherePaths using the previous generation
115351 ** of WherePaths as the basis for the next. Keep track of the mxChoice
115352
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.5"
226 #define SQLITE_VERSION_NUMBER 3008005
227 #define SQLITE_SOURCE_ID "2014-06-02 11:26:33 9f18b303cd1bc5779d82669884f802c7889b4947"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -1060,10 +1060,16 @@
1060 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
1061 ** pointer to an integer and it writes a boolean into that integer depending
1062 ** on whether or not the file has been renamed, moved, or deleted since it
1063 ** was first opened.
1064 **
1065 ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
1066 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
1067 ** opcode causes the xFileControl method to swap the file handle with the one
1068 ** pointed to by the pArg argument. This capability is used during testing
1069 ** and only needs to be supported when SQLITE_TEST is defined.
1070 **
1071 ** </ul>
1072 */
1073 #define SQLITE_FCNTL_LOCKSTATE 1
1074 #define SQLITE_GET_LOCKPROXYFILE 2
1075 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -1083,10 +1089,11 @@
1089 #define SQLITE_FCNTL_MMAP_SIZE 18
1090 #define SQLITE_FCNTL_TRACE 19
1091 #define SQLITE_FCNTL_HAS_MOVED 20
1092 #define SQLITE_FCNTL_SYNC 21
1093 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1094 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1095
1096 /*
1097 ** CAPI3REF: Mutex Handle
1098 **
1099 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -20986,10 +20993,11 @@
20993 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
20994 }else{
20995 zNew = sqlite3_realloc(zOld, p->nAlloc);
20996 }
20997 if( zNew ){
20998 assert( p->zText!=0 || p->nChar==0 );
20999 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
21000 p->zText = zNew;
21001 }else{
21002 sqlite3StrAccumReset(p);
21003 setStrAccumError(p, STRACCUM_NOMEM);
@@ -34539,12 +34547,20 @@
34547 ** around problems caused by indexing and/or anti-virus software on
34548 ** Windows systems.
34549 ** If you are using this code as a model for alternative VFSes, do not
34550 ** copy this retry logic. It is a hack intended for Windows only.
34551 */
34552 lastErrno = osGetLastError();
34553 OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, result=%d\n",
34554 pFile->h, cnt, res));
34555 if( lastErrno==ERROR_INVALID_HANDLE ){
34556 pFile->lastErrno = lastErrno;
34557 rc = SQLITE_IOERR_LOCK;
34558 OSTRACE(("LOCK-FAIL file=%p, count=%d, rc=%s\n",
34559 pFile->h, cnt, sqlite3ErrName(rc)));
34560 return rc;
34561 }
34562 if( cnt ) sqlite3_win32_sleep(1);
34563 }
34564 gotPendingLock = res;
34565 if( !res ){
34566 lastErrno = osGetLastError();
@@ -34784,10 +34800,21 @@
34800 a[1] = winIoerrRetryDelay;
34801 }
34802 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34803 return SQLITE_OK;
34804 }
34805 #ifdef SQLITE_TEST
34806 case SQLITE_FCNTL_WIN32_SET_HANDLE: {
34807 LPHANDLE phFile = (LPHANDLE)pArg;
34808 HANDLE hOldFile = pFile->h;
34809 pFile->h = *phFile;
34810 *phFile = hOldFile;
34811 OSTRACE(("FCNTL oldFile=%p, newFile=%p, rc=SQLITE_OK\n",
34812 hOldFile, pFile->h));
34813 return SQLITE_OK;
34814 }
34815 #endif
34816 case SQLITE_FCNTL_TEMPFILENAME: {
34817 char *zTFile = 0;
34818 int rc = winGetTempname(pFile->pVfs, &zTFile);
34819 if( rc==SQLITE_OK ){
34820 *(char**)pArg = zTFile;
@@ -115311,11 +115338,11 @@
115338 db = pParse->db;
115339 nLoop = pWInfo->nLevel;
115340 /* TUNING: For simple queries, only the best path is tracked.
115341 ** For 2-way joins, the 5 best paths are followed.
115342 ** For joins of 3 or more tables, track the 10 best paths */
115343 mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10);
115344 assert( nLoop<=pWInfo->pTabList->nSrc );
115345 WHERETRACE(0x002, ("---- begin solver\n"));
115346
115347 /* Allocate and initialize space for aTo and aFrom */
115348 ii = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2;
@@ -115341,11 +115368,11 @@
115368 ** to sqlite3WhereBegin() was concerned about sorting */
115369 if( pWInfo->pOrderBy==0 || nRowEst==0 ){
115370 aFrom[0].isOrdered = 0;
115371 nOrderBy = 0;
115372 }else{
115373 aFrom[0].isOrdered = nLoop>0 ? -1 : 1;
115374 nOrderBy = pWInfo->pOrderBy->nExpr;
115375 }
115376
115377 /* Compute successively longer WherePaths using the previous generation
115378 ** of WherePaths as the basis for the next. Keep track of the mxChoice
115379
+8 -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.5"
111111
#define SQLITE_VERSION_NUMBER 3008005
112
-#define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
112
+#define SQLITE_SOURCE_ID "2014-06-02 11:26:33 9f18b303cd1bc5779d82669884f802c7889b4947"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -945,10 +945,16 @@
945945
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
946946
** pointer to an integer and it writes a boolean into that integer depending
947947
** on whether or not the file has been renamed, moved, or deleted since it
948948
** was first opened.
949949
**
950
+** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
951
+** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
952
+** opcode causes the xFileControl method to swap the file handle with the one
953
+** pointed to by the pArg argument. This capability is used during testing
954
+** and only needs to be supported when SQLITE_TEST is defined.
955
+**
950956
** </ul>
951957
*/
952958
#define SQLITE_FCNTL_LOCKSTATE 1
953959
#define SQLITE_GET_LOCKPROXYFILE 2
954960
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -968,10 +974,11 @@
968974
#define SQLITE_FCNTL_MMAP_SIZE 18
969975
#define SQLITE_FCNTL_TRACE 19
970976
#define SQLITE_FCNTL_HAS_MOVED 20
971977
#define SQLITE_FCNTL_SYNC 21
972978
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
979
+#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
973980
974981
/*
975982
** CAPI3REF: Mutex Handle
976983
**
977984
** The mutex module within SQLite defines [sqlite3_mutex] to be an
978985
--- 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.5"
111 #define SQLITE_VERSION_NUMBER 3008005
112 #define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -945,10 +945,16 @@
945 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
946 ** pointer to an integer and it writes a boolean into that integer depending
947 ** on whether or not the file has been renamed, moved, or deleted since it
948 ** was first opened.
949 **
 
 
 
 
 
 
950 ** </ul>
951 */
952 #define SQLITE_FCNTL_LOCKSTATE 1
953 #define SQLITE_GET_LOCKPROXYFILE 2
954 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -968,10 +974,11 @@
968 #define SQLITE_FCNTL_MMAP_SIZE 18
969 #define SQLITE_FCNTL_TRACE 19
970 #define SQLITE_FCNTL_HAS_MOVED 20
971 #define SQLITE_FCNTL_SYNC 21
972 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
 
973
974 /*
975 ** CAPI3REF: Mutex Handle
976 **
977 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
978
--- 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.5"
111 #define SQLITE_VERSION_NUMBER 3008005
112 #define SQLITE_SOURCE_ID "2014-06-02 11:26:33 9f18b303cd1bc5779d82669884f802c7889b4947"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -945,10 +945,16 @@
945 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
946 ** pointer to an integer and it writes a boolean into that integer depending
947 ** on whether or not the file has been renamed, moved, or deleted since it
948 ** was first opened.
949 **
950 ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
951 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
952 ** opcode causes the xFileControl method to swap the file handle with the one
953 ** pointed to by the pArg argument. This capability is used during testing
954 ** and only needs to be supported when SQLITE_TEST is defined.
955 **
956 ** </ul>
957 */
958 #define SQLITE_FCNTL_LOCKSTATE 1
959 #define SQLITE_GET_LOCKPROXYFILE 2
960 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -968,10 +974,11 @@
974 #define SQLITE_FCNTL_MMAP_SIZE 18
975 #define SQLITE_FCNTL_TRACE 19
976 #define SQLITE_FCNTL_HAS_MOVED 20
977 #define SQLITE_FCNTL_SYNC 21
978 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
979 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
980
981 /*
982 ** CAPI3REF: Mutex Handle
983 **
984 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
985

Keyboard Shortcuts

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