]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In the command-line shell, fix the .imposter command so that it works
authordrh <drh@noemail.net>
Thu, 3 Nov 2016 13:12:28 +0000 (13:12 +0000)
committerdrh <drh@noemail.net>
Thu, 3 Nov 2016 13:12:28 +0000 (13:12 +0000)
with indexes on expressions.  Fix the ".mode quote" mode so that it works
with ".headers ON".

FossilOrigin-Name: ba9873da94d21873ff76f16a5332fc0092d83f70

manifest
manifest.uuid
src/shell.c

index e87531c36192bc2c95ff6c3284ca4667421b0f3b..3767dfc065444cb81e17661813bdec655282262a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\s".imposter"\scommand\sto\sthe\scommand-line\sshell.
-D 2016-11-03T13:01:38.992
+C In\sthe\scommand-line\sshell,\sfix\sthe\s.imposter\scommand\sso\sthat\sit\sworks\nwith\sindexes\son\sexpressions.\s\sFix\sthe\s".mode\squote"\smode\sso\sthat\sit\sworks\nwith\s".headers\sON".
+D 2016-11-03T13:12:28.436
 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc e0217f2d35a0448abbe4b066132ae20136e8b408
@@ -388,7 +388,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
 F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
 F src/select.c ea3af83e2d0f245fef81ea4cf04cb730ce67f722
-F src/shell.c 859c497e9f83a5326f43c1a0e078acc52952b275
+F src/shell.c 63e54cfa1c7ec5b70a4c9a86502bc10280c3d5a3
 F src/sqlite.h.in 97e9b0f952306677db82b055147ed1d99cb7ba66
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
@@ -1529,7 +1529,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 ad08753a8bbf073ec4af9c3a5783ed664244d954
-R 4bccfcf3c4fd102e5db9ad5f3fdf53dc
+P be3ec8fdcf1541017ca9375df07645db2a9a3f5a
+R 492f3194b55f82acdeed3f831384acda
 U drh
-Z 3d1bd5abf50601149224220b1d9418d0
+Z cf1e2d863175ee56efe47dbfd06f83ec
index c6fc1185b00790013eb72b032a98b960d79e86c6..9e5798c1007f5a3d12fec40af3b6f537de68d2e1 100644 (file)
@@ -1 +1 @@
-be3ec8fdcf1541017ca9375df07645db2a9a3f5a
\ No newline at end of file
+ba9873da94d21873ff76f16a5332fc0092d83f70
\ No newline at end of file
index 374755fcc5477bb47b1ac84587ebc064fbe1f2cf..6a7bee142d94b74a22d350def9f0829a94645af7 100644 (file)
@@ -1202,7 +1202,6 @@ static int shell_callback(
     }
     case MODE_Quote:
     case MODE_Insert: {
-      p->cnt++;
       if( azArg==0 ) break;
       if( p->cMode==MODE_Insert ){
         utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
@@ -1215,7 +1214,14 @@ static int shell_callback(
           raw_printf(p->out,")");
         }
         raw_printf(p->out," VALUES(");
+      }else if( p->cnt==0 && p->showHeader ){
+        for(i=0; i<nArg; i++){
+          if( i>0 ) utf8_printf(p->out, ",");
+          output_quoted_string(p->out, azCol[i]);
+        }
+        utf8_printf(p->out,"\n");
       }
+      p->cnt++;
       for(i=0; i<nArg; i++){
         char *zSep = i>0 ? ",": "";
         if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
@@ -3855,6 +3861,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     char *zCollist = 0;
     sqlite3_stmt *pStmt;
     int tnum = 0;
+    int i;
     if( nArg!=3 ){
       utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n");
       rc = 1;
@@ -3877,9 +3884,19 @@ static int do_meta_command(char *zLine, ShellState *p){
     zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
     rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
     sqlite3_free(zSql);
+    i = 0;
     while( sqlite3_step(pStmt)==SQLITE_ROW ){
+      char zLabel[20];
       const char *zCol = (const char*)sqlite3_column_text(pStmt,2);
-      if( zCol==0 ) zCol = "_ROWID_";
+      i++;
+      if( zCol==0 ){
+        if( sqlite3_column_int(pStmt,1)==-1 ){
+          zCol = "_ROWID_";
+        }else{
+          sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
+          zCol = zLabel;
+        }
+      }
       if( zCollist==0 ){
         zCollist = sqlite3_mprintf("\"%w\"", zCol);
       }else{