]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the ".recover" output in the shell to use double-quotes around table
authordrh <drh@noemail.net>
Tue, 6 Aug 2019 20:26:17 +0000 (20:26 +0000)
committerdrh <drh@noemail.net>
Tue, 6 Aug 2019 20:26:17 +0000 (20:26 +0000)
and column identifiers.

FossilOrigin-Name: 846d2d2d2f7fd2e4178c70bc2b92f18941a7972fe88c0129035b7a253ed21785

manifest
manifest.uuid
src/shell.c.in

index bd21295943b812b409f4305f6a38507fe5f81319..fa965410934ea511211264d62aecca986c837b7e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\s"PRAGMA\sforeign_keys=OFF;"\sto\sthe\sstart\sof\sthe\sscript\soutput\sby\s".recover",\sjust\sas\sis\sdone\sfor\s".dump".
-D 2019-08-06T18:40:36.681
+C Enhance\sthe\s".recover"\soutput\sin\sthe\sshell\sto\suse\sdouble-quotes\saround\stable\nand\scolumn\sidentifiers.
+D 2019-08-06T20:26:17.504
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -524,7 +524,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 3ed5a3de18b455366771a89241283fef16508a7f681af546296e95e81458efeb
 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
 F src/select.c db06006136ec50868ce6f6fe17e8dfad21b58c089f9372d29c1a79283445907f
-F src/shell.c.in 486dbf00639caefff49157ff0fb495ece63b5d3446226530a4d12da4523a85d7
+F src/shell.c.in 97714cd5e177b6d53fac83c74becf4b19fe0aa8f1a4ed6a4fa1eede4bafb96f7
 F src/sqlite.h.in dfe86c132b5085e00cf0539c78510b75e60d740191804c9848e8bb7aa850fff5
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 9ecc93b8493bd20c0c07d52e2ac0ed8bab9b549c7f7955b59869597b650dd8b5
@@ -1838,7 +1838,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 9c8c1092a8ce80e114fcfe8ce780332a6f269b8c87df226242b582d2d825c393
-R 57f54a483ad45f70950f478d347477c2
-U dan
-Z 611328cc84a1359679c9e0fa05abc352
+P bfc29e62eff0ed00c153e18a27815f7e3ba316f46871e9645b84ab1e6709a392
+R 10086bf66980a741a6f6a6c27d24c72b
+U drh
+Z 2822779ed58d184aa4feb3102735adde
index e0b22fe4d1afc2759ba4562015965d8f08eec7c6..a8ffcdbce29f0a9cd02ca91a7bcf7ead362ad34c 100644 (file)
@@ -1 +1 @@
-bfc29e62eff0ed00c153e18a27815f7e3ba316f46871e9645b84ab1e6709a392
\ No newline at end of file
+846d2d2d2f7fd2e4178c70bc2b92f18941a7972fe88c0129035b7a253ed21785
\ No newline at end of file
index 4c625e5700efe4ba0324670c0e16116fc172c80a..916b11283b38893bd4ae83b1653a4d1fb1e81d53 100644 (file)
@@ -3977,6 +3977,22 @@ static void shellInt32(
   }
 }
 
+/*
+** Scalar function "shell_idquote(X)" returns string X quoted as an identifier,
+** using "..." with internal double-quote characters doubled.
+*/
+static void shellIdQuote(
+  sqlite3_context *context, 
+  int argc, 
+  sqlite3_value **argv
+){
+  const char *zName = (const char*)sqlite3_value_text(argv[0]);
+  if( zName ){
+    char *z = sqlite3_mprintf("\"%w\"", zName);
+    sqlite3_result_text(context, z, -1, sqlite3_free);
+  }
+}
+
 /*
 ** Scalar function "shell_escape_crnl" used by the .recover command.
 ** The argument passed to this function is the output of built-in
@@ -4153,6 +4169,8 @@ static void open_db(ShellState *p, int openFlags){
                             shellEscapeCrnl, 0, 0);
     sqlite3_create_function(p->db, "shell_int32", 2, SQLITE_UTF8, 0,
                             shellInt32, 0, 0);
+    sqlite3_create_function(p->db, "shell_idquote", 1, SQLITE_UTF8, 0,
+                            shellIdQuote, 0, 0);
 #ifndef SQLITE_NOHAVE_SYSTEM
     sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0,
                             editFunc, 0, 0);
@@ -6330,6 +6348,10 @@ static RecoverTable *recoverNewTable(
     sqlite3_stmt *pStmt = 0;
     
     rc = sqlite3_open("", &dbtmp);
+    if( rc==SQLITE_OK ){
+      sqlite3_create_function(dbtmp, "shell_idquote", 1, SQLITE_UTF8, 0,
+                              shellIdQuote, 0, 0);
+    }
     if( rc==SQLITE_OK ){
       rc = sqlite3_exec(dbtmp, "PRAGMA writable_schema = on", 0, 0, 0);
     }
@@ -6386,18 +6408,18 @@ static RecoverTable *recoverNewTable(
         }
       }
 
-      pTab->zQuoted = shellMPrintf(&rc, "%Q", zName);
+      pTab->zQuoted = shellMPrintf(&rc, "\"%w\"", zName);
       pTab->azlCol = (char**)shellMalloc(&rc, sizeof(char*) * (nSqlCol+1));
       pTab->nCol = nSqlCol;
 
       if( bIntkey ){
-        pTab->azlCol[0] = shellMPrintf(&rc, "%Q", zPk);
+        pTab->azlCol[0] = shellMPrintf(&rc, "\"%w\"", zPk);
       }else{
         pTab->azlCol[0] = shellMPrintf(&rc, "");
       }
       i = 1;
       shellPreparePrintf(dbtmp, &rc, &pStmt, 
-          "SELECT %Q || group_concat(quote(name), ', ') "
+          "SELECT %Q || group_concat(shell_idquote(name), ', ') "
           "  FILTER (WHERE cid!=%d) OVER (ORDER BY %s cid) "
           "FROM pragma_table_info(%Q)", 
           bIntkey ? ", " : "", pTab->iPk, 
@@ -6511,7 +6533,7 @@ static RecoverTable *recoverOrphanTable(
 
     pTab = (RecoverTable*)shellMalloc(pRc, sizeof(RecoverTable));
     if( pTab ){
-      pTab->zQuoted = shellMPrintf(pRc, "%Q", zTab);
+      pTab->zQuoted = shellMPrintf(pRc, "\"%w\"", zTab);
       pTab->nCol = nCol;
       pTab->iPk = -2;
       if( nCol>0 ){
@@ -6775,7 +6797,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
       if( pTab==0 ) break;
     }
 
-    if( 0==sqlite3_stricmp(pTab->zQuoted, "'sqlite_sequence'") ){
+    if( 0==sqlite3_stricmp(pTab->zQuoted, "\"sqlite_sequence\"") ){
       raw_printf(pState->out, "DELETE FROM sqlite_sequence;\n");
     }
     sqlite3_bind_int(pPages, 1, iRoot);