-C Make\ssure\sthe\sdatabase\sconnection\sis\sopen\sprior\sto\srunning\sthe\s".sha3sum"\ncommand.
-D 2017-03-08T18:06:20.965
+C Begin\smoving\sseparate\sboolean\svariables\sin\sthe\sShellState\sobject\sof\sthe\sCLI\ninto\sthe\sshellFlgs\sbitmask.
+D 2017-03-09T13:50:49.349
F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2
F src/resolve.c 3e518b962d932a997fae373366880fc028c75706
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c d12f3539f80db38b09015561b569e0eb1c4b6c5f
-F src/shell.c 1160c054a483d15213ceb70fdbc383b07eebdf78
+F src/shell.c 397e51c3eeb3a9dc21667a0a384eb14403cc5eea
F src/sqlite.h.in 4d0c08f8640c586564a7032b259c5f69bf397850
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 30f878832820ce7ccc4627c4f0f98fbe82f8b0f6
-R 15b9925a544b33052292bf7b7cba23e6
+P 2ea300fb8f7c497f3f092dc91f4305d8431c27d9
+R 193fb708e3eeb9be14d6692d9fad8ed4
U drh
-Z d079eee20e78bccc69196e077d629480
+Z 6ea8a21fbd5a369fc4273386c415b1f4
typedef struct ShellState ShellState;
struct ShellState {
sqlite3 *db; /* The database */
- int echoOn; /* True to echo input commands */
int autoExplain; /* Automatically turn on .explain mode */
int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
int statsOn; /* True to display memory stats before each finalize */
int scanstatsOn; /* True to display scan stats before each finalize */
- int countChanges; /* True to display change counts */
- int backslashOn; /* Resolve C-style \x escapes in SQL input text */
int outCount; /* Revert to stdout when reaching zero */
- int preserveRowid; /* Preserver ROWID values on a ".dump" command */
int cnt; /* Number of records displayed so far */
FILE *out; /* Write results here */
FILE *traceOut; /* Output for sqlite3_trace() */
/*
** These are the allowed shellFlgs values
*/
-#define SHFLG_Scratch 0x00001 /* The --scratch option is used */
-#define SHFLG_Pagecache 0x00002 /* The --pagecache option is used */
-#define SHFLG_Lookaside 0x00004 /* Lookaside memory is used */
+#define SHFLG_Scratch 0x00000001 /* The --scratch option is used */
+#define SHFLG_Pagecache 0x00000002 /* The --pagecache option is used */
+#define SHFLG_Lookaside 0x00000004 /* Lookaside memory is used */
+#define SHFLG_Backslash 0x00000008 /* The --backslash option is used */
+#define SHFLG_PreserveRowid 0x00000010 /* .dump preserves rowid values */
+#define SHFLG_CountChanges 0x00000020 /* .changes setting */
+#define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
+
+/*
+** Macros for testing and setting shellFlgs
+*/
+#define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
+#define ShellSetFlag(P,X) ((P)->shellFlgs|=(X))
+#define ShellClearFlag(P,X) ((P)->shellFlgs&=(~(X)))
/*
** These are the allowed modes.
}
/* echo the sql statement if echo on */
- if( pArg && pArg->echoOn ){
+ if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
}
int nAlloc = 0;
int nPK = 0; /* Number of PRIMARY KEY columns seen */
int isIPK = 0; /* True if one PRIMARY KEY column of type INTEGER */
- int preserveRowid = p->preserveRowid;
+ int preserveRowid = ShellHasFlag(p, SHFLG_PreserveRowid);
int rc;
zSql = sqlite3_mprintf("PRAGMA table_info=%Q", zTab);
** Interpret zArg as either an integer or a boolean value. Return 1 or 0
** for TRUE and FALSE. Return the integer value if appropriate.
*/
-static int booleanValue(char *zArg){
+static int booleanValue(const char *zArg){
int i;
if( zArg[0]=='0' && zArg[1]=='x' ){
for(i=2; hexDigitValue(zArg[i])>=0; i++){}
return 0;
}
+/*
+** Set or clear a shell flag according to a boolean value.
+*/
+static void setOrClearFlag(ShellState *p, unsigned mFlag, const char *zArg){
+ if( booleanValue(zArg) ){
+ ShellSetFlag(p, mFlag);
+ }else{
+ ShellClearFlag(p, mFlag);
+ }
+}
+
/*
** Close an output file, assuming it is not stderr or stdout
*/
if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
if( nArg==2 ){
- p->countChanges = booleanValue(azArg[1]);
+ setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
}else{
raw_printf(stderr, "Usage: .changes on|off\n");
rc = 1;
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
const char *zLike = 0;
int i;
- p->preserveRowid = 0;
+ ShellClearFlag(p, SHFLG_PreserveRowid);
for(i=1; i<nArg; i++){
if( azArg[i][0]=='-' ){
const char *z = azArg[i]+1;
if( z[0]=='-' ) z++;
if( strcmp(z,"preserve-rowids")==0 ){
- p->preserveRowid = 1;
+ ShellSetFlag(p, SHFLG_PreserveRowid);
}else
{
raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
if( nArg==2 ){
- p->echoOn = booleanValue(azArg[1]);
+ setOrClearFlag(p, SHFLG_Echo, azArg[1]);
}else{
raw_printf(stderr, "Usage: .echo on|off\n");
rc = 1;
rc = 1;
goto meta_command_exit;
}
- utf8_printf(p->out, "%12.12s: %s\n","echo", azBool[p->echoOn!=0]);
+ utf8_printf(p->out, "%12.12s: %s\n","echo",
+ azBool[ShellHasFlag(p, SHFLG_Echo)]);
utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
utf8_printf(p->out, "%12.12s: %s\n","explain",
p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
char *zErrMsg = 0;
open_db(p, 0);
- if( p->backslashOn ) resolve_backslashes(zSql);
+ if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
BEGIN_TIMER;
rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
END_TIMER;
utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
}
return 1;
- }else if( p->countChanges ){
+ }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
raw_printf(p->out, "changes: %3d total_changes: %d\n",
sqlite3_changes(p->db), sqlite3_total_changes(p->db));
}
}
lineno++;
if( nSql==0 && _all_whitespace(zLine) ){
- if( p->echoOn ) printf("%s\n", zLine);
+ if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
continue;
}
if( zLine && zLine[0]=='.' && nSql==0 ){
- if( p->echoOn ) printf("%s\n", zLine);
+ if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
rc = do_meta_command(zLine, p);
if( rc==2 ){ /* exit requested */
break;
p->outCount = 0;
}
}else if( nSql && _all_whitespace(zSql) ){
- if( p->echoOn ) printf("%s\n", zSql);
+ if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
nSql = 0;
}
}
}else if( strcmp(z,"-noheader")==0 ){
data.showHeader = 0;
}else if( strcmp(z,"-echo")==0 ){
- data.echoOn = 1;
+ ShellSetFlag(&data, SHFLG_Echo);
}else if( strcmp(z,"-eqp")==0 ){
data.autoEQP = 1;
}else if( strcmp(z,"-eqpfull")==0 ){
** prior to sending the SQL into SQLite. Useful for injecting
** crazy bytes in the middle of SQL statements for testing and debugging.
*/
- data.backslashOn = 1;
+ ShellSetFlag(&data, SHFLG_Backslash);
}else if( strcmp(z,"-bail")==0 ){
bail_on_error = 1;
}else if( strcmp(z,"-version")==0 ){