]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the CLI so that the ".open --hexdb" command works even if it is contained
authordrh <drh@noemail.net>
Thu, 13 Dec 2018 18:30:01 +0000 (18:30 +0000)
committerdrh <drh@noemail.net>
Thu, 13 Dec 2018 18:30:01 +0000 (18:30 +0000)
in a subscript that is read using ".read".

FossilOrigin-Name: 67a87399b8ad8f1ce3052ee3159906f5c6df3d7b5691b3acac856bd2f1c82088

manifest
manifest.uuid
src/shell.c.in

index 127fdbd6ec25b609731f884e0db2cc823c95be24..a0f3a016d02fd111799e2adeb4dc4613b0bd013b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\s"dbtotxt"\sutility\sprogram\sand\sthe\sability\sto\sread\s"dbtotxt"\soutput\nas\sa\sdeserialized\sinput\sdatabase\sin\sthe\sCLI,\susing\sthe\s--hexdb\soption\sto\nthe\s".open"\scommand.
-D 2018-12-13T15:06:26.121
+C Fix\sthe\sCLI\sso\sthat\sthe\s".open\s--hexdb"\scommand\sworks\seven\sif\sit\sis\scontained\nin\sa\ssubscript\sthat\sis\sread\susing\s".read".
+D 2018-12-13T18:30:01.890
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 2f1b61ac62689ca4e9cbff9fdb359578ea37ddd9252355ec0b7b9700ad56fe90
@@ -508,7 +508,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c abd65c518c198400193c6319a70c0d722fa30a35be89dc898917ff6489edf017
 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
 F src/select.c 8c7317d5ee920516a56b8b4ca79fbfca70a1f8b52d67e884c808ea3a016c04e3
-F src/shell.c.in 6c06ff4077ab38b30a307c058ecc650e958bfdb6da1c255ebbd8779447e0cae9
+F src/shell.c.in b998c6d78bc886e900780abf8ef89fc33c0884058ee6583ff466e52a273872e6
 F src/sqlite.h.in 92fd656c26cc76de9fa8c5bf1a473066e3b5c6da345a447679f0f44de1aa4edd
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683
@@ -1786,7 +1786,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P eac9c0c49650b008951318a2225b932709a0a8dffbb01ed57684c40357b2e25c
-R 4375ea249bc2f1867ed511e156cfaedb
+P e3bf1d3ea5f748c5142c2403813fdace5aedc1fc68f0dcd5eae40a2fe763fedb
+R a7af747c108542ed7a9f41235cf0fca7
 U drh
-Z 5d7eea8bc66404385fe54bd1e1b7369f
+Z c11351b3fcf7b9c9d8ba68269cb05836
index 4226c789846cfe3ebf24dc6ceac218cf750e481b..66a335cd85bf942cbd3ce62628843d28be5bf9ca 100644 (file)
@@ -1 +1 @@
-e3bf1d3ea5f748c5142c2403813fdace5aedc1fc68f0dcd5eae40a2fe763fedb
\ No newline at end of file
+67a87399b8ad8f1ce3052ee3159906f5c6df3d7b5691b3acac856bd2f1c82088
\ No newline at end of file
index 70cbfe9eb9c6877d2cabd7037365591614bb9590..b1988e5a29731d653db772feb70862168e194289 100644 (file)
@@ -1011,6 +1011,7 @@ struct ShellState {
   unsigned mEqpLines;    /* Mask of veritical lines in the EQP output graph */
   int outCount;          /* Revert to stdout when reaching zero */
   int cnt;               /* Number of records displayed so far */
+  FILE *in;              /* Read commands from this stream */
   FILE *out;             /* Write results here */
   FILE *traceOut;        /* Output for sqlite3_trace() */
   int nErr;              /* Number of errors seen */
@@ -3595,7 +3596,7 @@ static int showHelp(FILE *out, const char *zPattern){
 }
 
 /* Forward reference */
-static int process_input(ShellState *p, FILE *in);
+static int process_input(ShellState *p);
 
 /*
 ** Read the content of file zName into memory obtained from sqlite3_malloc64()
@@ -3749,7 +3750,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){
       return 0;
     }
   }else{
-    in = stdin;
+    in = p->in;
   }
   *pnData = 0;
   if( fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error;
@@ -3789,14 +3790,14 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){
     }
   }
   *pnData = n;
-  if( in!=stdin ) fclose(in);
+  if( in!=p->in ) fclose(in);
   return a;
 
 readHexDb_error:
   if( in!=stdin ){
     fclose(in);
   }else{
-    while( fgets(zLine, sizeof(zLine), in)!=0 ){
+    while( fgets(zLine, sizeof(zLine), p->in)!=0 ){
       if(strncmp(zLine, "| end ", 6)==0 ) break;
     }
   }
@@ -6970,20 +6971,21 @@ static int do_meta_command(char *zLine, ShellState *p){
   }else
 
   if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
-    FILE *alt;
+    FILE *inSaved = p->in;
     if( nArg!=2 ){
       raw_printf(stderr, "Usage: .read FILE\n");
       rc = 1;
       goto meta_command_exit;
     }
-    alt = fopen(azArg[1], "rb");
-    if( alt==0 ){
+    p->in = fopen(azArg[1], "rb");
+    if( p->in==0 ){
       utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
       rc = 1;
     }else{
-      rc = process_input(p, alt);
-      fclose(alt);
+      rc = process_input(p);
+      fclose(p->in);
     }
+    p->in = inSaved;
   }else
 
   if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
@@ -8324,7 +8326,7 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
 **
 ** Return the number of errors.
 */
-static int process_input(ShellState *p, FILE *in){
+static int process_input(ShellState *p){
   char *zLine = 0;          /* A single input line */
   char *zSql = 0;           /* Accumulated SQL text */
   int nLine;                /* Length of current line */
@@ -8336,16 +8338,16 @@ static int process_input(ShellState *p, FILE *in){
   int lineno = 0;           /* Current line number */
   int startline = 0;        /* Line number for start of current input */
 
-  while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){
+  while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
     fflush(p->out);
-    zLine = one_input_line(in, zLine, nSql>0);
+    zLine = one_input_line(p->in, zLine, nSql>0);
     if( zLine==0 ){
       /* End of input */
-      if( in==0 && stdin_is_interactive ) printf("\n");
+      if( p->in==0 && stdin_is_interactive ) printf("\n");
       break;
     }
     if( seenInterrupt ){
-      if( in!=0 ) break;
+      if( p->in!=0 ) break;
       seenInterrupt = 0;
     }
     lineno++;
@@ -8389,7 +8391,7 @@ static int process_input(ShellState *p, FILE *in){
     }
     if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
                 && sqlite3_complete(zSql) ){
-      errCnt += runOneSqlLine(p, zSql, in, startline);
+      errCnt += runOneSqlLine(p, zSql, p->in, startline);
       nSql = 0;
       if( p->outCount ){
         output_reset(p);
@@ -8403,7 +8405,7 @@ static int process_input(ShellState *p, FILE *in){
     }
   }
   if( nSql && !_all_whitespace(zSql) ){
-    errCnt += runOneSqlLine(p, zSql, in, startline);
+    errCnt += runOneSqlLine(p, zSql, p->in, startline);
   }
   free(zSql);
   free(zLine);
@@ -8492,7 +8494,7 @@ static void process_sqliterc(
   char *home_dir = NULL;
   const char *sqliterc = sqliterc_override;
   char *zBuf = 0;
-  FILE *in = NULL;
+  FILE *inSaved = p->in;
 
   if (sqliterc == NULL) {
     home_dir = find_home_dir(0);
@@ -8504,14 +8506,15 @@ static void process_sqliterc(
     zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
     sqliterc = zBuf;
   }
-  in = fopen(sqliterc,"rb");
-  if( in ){
+  p->in = fopen(sqliterc,"rb");
+  if( p->in ){
     if( stdin_is_interactive ){
       utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc);
     }
-    process_input(p,in);
-    fclose(in);
+    process_input(p);
+    fclose(p->in);
   }
+  p->in = inSaved;
   sqlite3_free(zBuf);
 }
 
@@ -9123,14 +9126,16 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
 #elif HAVE_LINENOISE
       linenoiseSetCompletionCallback(linenoise_completion);
 #endif
-      rc = process_input(&data, 0);
+      data.in = 0;
+      rc = process_input(&data);
       if( zHistory ){
         shell_stifle_history(2000);
         shell_write_history(zHistory);
         free(zHistory);
       }
     }else{
-      rc = process_input(&data, stdin);
+      data.in = stdin;
+      rc = process_input(&data);
     }
   }
   set_table_name(&data, 0);