]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the ".echo on" dot-command of the shell so that it echos comments in
authordrh <drh@noemail.net>
Sat, 21 Dec 2013 15:46:06 +0000 (15:46 +0000)
committerdrh <drh@noemail.net>
Sat, 21 Dec 2013 15:46:06 +0000 (15:46 +0000)
addition to SQL statements and dot-commands.  Add the --explain option
to speedtest1 so that the output can be piped into the command-line shell
to show nicely-formated VDBE code for the entire test.

FossilOrigin-Name: 96397263f94256e284aae9506de1fc48fea89193

manifest
manifest.uuid
src/shell.c
test/shell2.test
test/speedtest1.c

index 54ee0ed6bb4ae90734514bcfbadd243800153882..d556779ff4421b2851dc8df6f2b70de171564367 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sa\scase\sto\sspeedtest1.c\sthat\sdemonstrates\sthe\sneed\sto\sfactor\sOP_Column\noperators\sout\sof\sinner\sloops.
-D 2013-12-21T00:04:37.543
+C Fix\sthe\s".echo\son"\sdot-command\sof\sthe\sshell\sso\sthat\sit\sechos\scomments\sin\naddition\sto\sSQL\sstatements\sand\sdot-commands.\s\sAdd\sthe\s--explain\soption\nto\sspeedtest1\sso\sthat\sthe\soutput\scan\sbe\spiped\sinto\sthe\scommand-line\sshell\nto\sshow\snicely-formated\sVDBE\scode\sfor\sthe\sentire\stest.
+D 2013-12-21T15:46:06.562
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -220,7 +220,7 @@ F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68
 F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
 F src/select.c 819bb090c9a348d17f69f136cad2bfa9ee9cbb41
-F src/shell.c 18924f6ccfa70da98bf9e388bab512c0fd1e792e
+F src/shell.c a3541193d5fce37e91dad8ef46a9505aa7c9b344
 F src/sqlite.h.in 4ef56464aeaa3785a2c5ca37fb3a0fb229d68b2e
 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
@@ -802,7 +802,7 @@ F test/sharedA.test 0cdf1a76dfa00e6beee66af5b534b1e8df2720f5
 F test/shared_err.test 0079c05c97d88cfa03989b7c20a8b266983087aa
 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
 F test/shell1.test e7c0b9ebda25d5e78f0a3ea0dc4e31bb6d8098c0
-F test/shell2.test e1d3790f064e50b2f973502f45750012667486df
+F test/shell2.test c57da3a381c099b02c813ba156298d5c2f5c93a3
 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29
 F test/shell4.test aa4eef8118b412d1a01477a53426ece169ea86a9
 F test/shell5.test cee83b4385f842fec1f2a0bec9ea811f35386edf
@@ -822,7 +822,7 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523
 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715
 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa
 F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b
-F test/speedtest1.c 60d9ebc64c036ee7803cc5323ef5204686312f5b
+F test/speedtest1.c 0fb5502e0879e18991e7ecc791b41ba1c7fa74e8
 F test/spellfix.test 8c40b169b104086d8795781f670ba3c786d6d8be
 F test/sqllimits1.test b1aae27cc98eceb845e7f7adf918561256e31298
 F test/stat.test 76fd746b85459e812a0193410fb599f0531f22de
@@ -1147,7 +1147,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P d93ae6833a7fca0672caf902a7b48846e54242cd
-R 1bba9a023d69c9c6d571dcfd3bfe83d6
+P 69a17336fdf4ae891e815914be8942f7222230c2
+R f8c33eb19f28c61795b29a236555d23d
 U drh
-Z 60543214dfc95183844c1868498ec509
+Z 526508e712c84b42d21bbec0b02b9c9e
index d06af4fa2615fb13abe2a123f477c131c0884d68..b9cf9f2e0b8b33c4dd41697e144293a99d25eef5 100644 (file)
@@ -1 +1 @@
-69a17336fdf4ae891e815914be8942f7222230c2
\ No newline at end of file
+96397263f94256e284aae9506de1fc48fea89193
\ No newline at end of file
index 7826fdf204bdb1390fd5f0e2fe34add00eab4b5b..00cff6a8e5e43456aceac74bc0888f3d6d479758 100644 (file)
@@ -3038,7 +3038,10 @@ static int process_input(struct callback_data *p, FILE *in){
       seenInterrupt = 0;
     }
     lineno++;
-    if( nSql==0 && _all_whitespace(zLine) ) continue;
+    if( nSql==0 && _all_whitespace(zLine) ){
+      if( p->echoOn ) printf("%s\n", zLine);
+      continue;
+    }
     if( zLine && zLine[0]=='.' && nSql==0 ){
       if( p->echoOn ) printf("%s\n", zLine);
       rc = do_meta_command(zLine, p);
@@ -3100,6 +3103,7 @@ static int process_input(struct callback_data *p, FILE *in){
       }
       nSql = 0;
     }else if( nSql && _all_whitespace(zSql) ){
+      if( p->echoOn ) printf("%s\n", zSql);
       nSql = 0;
     }
   }
index f02d788415e91804aa541b2a081608e0e670f423..def574c76c16d82c405aaead3e9a3adbe2505f42 100644 (file)
@@ -155,7 +155,8 @@ SELECT * FROM foo1;
 2
 SELECT * FROM foo2;
 1
-2}}
+2
+}}
 
 # Test with echo on and headers on using dot command and 
 # multiple commands per line.
@@ -192,6 +193,7 @@ a
 SELECT * FROM foo2;
 b
 1
-2}}
+2
+}}
 
 finish_test
index 6137720ee0b127c779c50d3b00b6ca7f4b55ff5d..57d21b26c43ab351d95319c9633b3453714f9642 100644 (file)
@@ -9,6 +9,7 @@ static const char zHelp[] =
   "  --autovacuum        Enable AUTOVACUUM mode\n"
   "  --cachesize N       Set the cache size to N\n" 
   "  --exclusive         Enable locking_mode=EXCLUSIVE\n"
+  "  --explain           Like --sqlonly but with added EXPLAIN keywords\n"
   "  --heap SZ MIN       Memory allocator uses SZ bytes & min allocation MIN\n"
   "  --incrvacuum        Enable incremenatal vacuum mode\n"
   "  --journalmode M     Set the journal_mode to MODE\n"
@@ -49,6 +50,7 @@ static struct Global {
   int bWithoutRowid;         /* True for --without-rowid */
   int bReprepare;            /* True to reprepare the SQL on each rerun */
   int bSqlOnly;              /* True to print the SQL once only */
+  int bExplain;              /* Print SQL with EXPLAIN prefix */
   int szTest;                /* Scale factor for test iterations */
   const char *zWR;           /* Might be WITHOUT ROWID */
   const char *zNN;           /* Might be NOT NULL */
@@ -290,6 +292,22 @@ void speedtest1_final(void){
   }
 }
 
+/* Print an SQL statement to standard output */
+static void printSql(const char *zSql){
+  int n = (int)strlen(zSql);
+  while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
+  if( g.bExplain ) printf("EXPLAIN ");
+  printf("%.*s;\n", n, zSql);
+  if( g.bExplain
+   && (sqlite3_strglob("CREATE *", zSql)
+     || sqlite3_strglob("DROP *", zSql)
+     || sqlite3_strglob("ALTER *", zSql)
+      )
+  ){
+    printf("%.*s;\n", n, zSql);
+  }
+}
+
 /* Run SQL */
 void speedtest1_exec(const char *zFormat, ...){
   va_list ap;
@@ -298,9 +316,7 @@ void speedtest1_exec(const char *zFormat, ...){
   zSql = sqlite3_vmprintf(zFormat, ap);
   va_end(ap);
   if( g.bSqlOnly ){
-    int n = (int)strlen(zSql);
-    while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
-    printf("%.*s;\n", n, zSql);
+    printSql(zSql);
   }else{
     char *zErrMsg = 0;
     int rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
@@ -318,9 +334,7 @@ void speedtest1_prepare(const char *zFormat, ...){
   zSql = sqlite3_vmprintf(zFormat, ap);
   va_end(ap);
   if( g.bSqlOnly ){
-    int n = (int)strlen(zSql);
-    while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
-    printf("%.*s;\n", n, zSql);
+    printSql(zSql);
   }else{
     int rc;
     if( g.pStmt ) sqlite3_finalize(g.pStmt);
@@ -497,15 +511,13 @@ void testset_main(void){
 
 
   speedtest1_begin_test(150, "CREATE INDEX five times");
-  speedtest1_exec(
-      "BEGIN;\n"
-      "CREATE UNIQUE INDEX t1b ON t1(b);\n"
-      "CREATE INDEX t1c ON t1(c);\n"
-      "CREATE UNIQUE INDEX t2b ON t2(b);\n"
-      "CREATE INDEX t2c ON t2(c DESC);\n"
-      "CREATE INDEX t3bc ON t3(b,c);\n"
-      "COMMIT;\n"
-  );
+  speedtest1_exec("BEGIN;");
+  speedtest1_exec("CREATE UNIQUE INDEX t1b ON t1(b);");
+  speedtest1_exec("CREATE INDEX t1c ON t1(c);");
+  speedtest1_exec("CREATE UNIQUE INDEX t2b ON t2(b);");
+  speedtest1_exec("CREATE INDEX t2c ON t2(c DESC);");
+  speedtest1_exec("CREATE INDEX t3bc ON t3(b,c);");
+  speedtest1_exec("COMMIT;");
   speedtest1_end_test();
 
 
@@ -579,10 +591,8 @@ void testset_main(void){
 
   n = sz;
   speedtest1_begin_test(190, "DELETE and REFILL one table", n);
-  speedtest1_exec(
-    "DELETE FROM t2;"
-    "INSERT INTO t2 SELECT * FROM t1;"
-  );
+  speedtest1_exec("DELETE FROM t2;");
+  speedtest1_exec("INSERT INTO t2 SELECT * FROM t1;");
   speedtest1_end_test();
 
 
@@ -678,10 +688,10 @@ void testset_main(void){
 
   speedtest1_begin_test(300, "Refill a %d-row table using (b&1)==(a&1)", sz);
   speedtest1_exec("DELETE FROM t2;");
-  speedtest1_exec(
-     "INSERT INTO t2(a,b,c) SELECT a,b,c FROM t1 WHERE (b&1)==(a&1);"
-     "INSERT INTO t2(a,b,c) SELECT a,b,c FROM t1 WHERE (b&1)<>(a&1);"
-  );
+  speedtest1_exec("INSERT INTO t2(a,b,c)\n"
+                  " SELECT a,b,c FROM t1  WHERE (b&1)==(a&1);");
+  speedtest1_exec("INSERT INTO t2(a,b,c)\n"
+                  " SELECT a,b,c FROM t1  WHERE (b&1)<>(a&1);");
   speedtest1_end_test();
 
 
@@ -786,6 +796,9 @@ int main(int argc, char **argv){
         cacheSize = integerValue(argv[i]);
       }else if( strcmp(z,"exclusive")==0 ){
         doExclusive = 1;
+      }else if( strcmp(z,"explain")==0 ){
+        g.bSqlOnly = 1;
+        g.bExplain = 1;
       }else if( strcmp(z,"heap")==0 ){
         if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
         nHeap = integerValue(argv[i+1]);
@@ -925,6 +938,7 @@ int main(int argc, char **argv){
     speedtest1_exec("PRAGMA journal_mode=%s", zJMode);
   }
 
+  if( g.bExplain ) printf(".explain\n.echo on\n");
   if( strcmp(zTSet,"main")==0 ){
     testset_main();
   }else if( strcmp(zTSet,"debug1")==0 ){