]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the quoting mechanism for ".dump" so that it is not applied for the
authordrh <drh@noemail.net>
Sat, 8 Apr 2017 13:42:55 +0000 (13:42 +0000)
committerdrh <drh@noemail.net>
Sat, 8 Apr 2017 13:42:55 +0000 (13:42 +0000)
".mode quote" output.

FossilOrigin-Name: 78c1e90305d48917d9423d8e50a7dfd15ec27aa93cb421610062229c7ede13a6

manifest
manifest.uuid
src/shell.c

index 847f11c3350b3e20ccb237d76bf4556b4c917c50..999a8ca810a53155b2c0df85089c3b903370065c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Have\sfts5\sclose\sany\sopen\sblob-handle\swhen\sa\snew\ssavepoint\sis\sopened.\sThis\nensures\sthat\sfts5\sdoes\snot\sprevent\sDROP\sTABLE\sstatements\s(which\salways\sopen\sa\nsavepoint)\sfrom\ssucceeding.
-D 2017-04-08T09:12:20.282
+C Fix\sthe\squoting\smechanism\sfor\s".dump"\sso\sthat\sit\sis\snot\sapplied\sfor\sthe\n".mode\squote"\soutput.
+D 2017-04-08T13:42:55.616
 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc a4c0613a18663bda56d8cf76079ab6590a7c3602e54befb4bbdef76bcaa38b6a
@@ -402,7 +402,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
 F src/select.c afcf31d8ed7c890328a31d3f350467ccd273af345b24562382b398d6d9cd0664
-F src/shell.c 13512de3e9862c1c2df0b034b1f54810e0b885fcf25475b7c61b7e7ef0a28d33
+F src/shell.c 70f4957b988572315e97c56941fdc81fd35907fee36b7b2e7be5ec4c7e9d065d
 F src/sqlite.h.in ab77e511620eebbd4ed7e4f52fae697b6870dda66c945acd2d3066f99c98e17e
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 58fd0676d3111d02e62e5a35992a7d3da5d3f88753acc174f2d37b774fbbdd28
@@ -1570,7 +1570,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 1cdae2db3c54970a1811e597065724578408c84d49d75b8fe25d56281ddc2e94
-R 70601a411a243bcad4990e39c82ee1af
-U dan
-Z dfa6c73936264c9fbb94dc8123013fe7
+P a921ada89050ce1d162fd1b0056939573635e2cec7ac0c2a99ae924b3ae593f7
+R 82737b36216e366238632e12de53d03d
+U drh
+Z 97234581d28b10577d1d04c415271f72
index 9f89285dde86c6ae531a1a6bdbb82a7e4b9585c5..e318e00b25accaf706dfee75c19784ddd410b0e2 100644 (file)
@@ -1 +1 @@
-a921ada89050ce1d162fd1b0056939573635e2cec7ac0c2a99ae924b3ae593f7
\ No newline at end of file
+78c1e90305d48917d9423d8e50a7dfd15ec27aa93cb421610062229c7ede13a6
\ No newline at end of file
index 9ddd11706d4a399b09b137037f3074f346035854..8341d828c1fef80a660a5cedf50a1b4fd771263c 100644 (file)
@@ -1512,10 +1512,48 @@ static const char *unused_string(
 /*
 ** Output the given string as a quoted string using SQL quoting conventions.
 **
-** The "\n" and "\r" characters are converted to char(10) and char(13)
-** to prevent them from being transformed by end-of-line translators.
+** See also: output_quoted_escaped_string()
 */
 static void output_quoted_string(FILE *out, const char *z){
+  int i;
+  char c;
+  setBinaryMode(out, 1);
+  for(i=0; (c = z[i])!=0 && c!='\''; i++){}
+  if( c==0 ){
+    utf8_printf(out,"'%s'",z);
+  }else{
+    raw_printf(out, "'");
+    while( *z ){
+      for(i=0; (c = z[i])!=0 && c!='\''; i++){}
+      if( c=='\'' ) i++;
+      if( i ){
+        utf8_printf(out, "%.*s", i, z);
+        z += i;
+      }
+      if( c=='\'' ){
+        raw_printf(out, "'");
+        continue;
+      }
+      if( c==0 ){
+        break;
+      }
+      z++;
+    }
+    raw_printf(out, "'");
+  }
+  setTextMode(out, 1);
+}
+
+/*
+** Output the given string as a quoted string using SQL quoting conventions.
+** Additionallly , escape the "\n" and "\r" characters so that they do not
+** get corrupted by end-of-line translation facilities in some operating
+** systems.
+**
+** This is like output_quoted_string() but with the addition of the \r\n
+** escape mechanism.
+*/
+static void output_quoted_escaped_string(FILE *out, const char *z){
   int i;
   char c;
   setBinaryMode(out, 1);
@@ -2031,27 +2069,53 @@ static int shell_callback(
       setTextMode(p->out, 1);
       break;
     }
-    case MODE_Quote:
     case MODE_Insert: {
       if( azArg==0 ) break;
-      if( p->cMode==MODE_Insert ){
-        utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
-        if( p->showHeader ){
-          raw_printf(p->out,"(");
-          for(i=0; i<nArg; i++){
-            if( i>0 ) raw_printf(p->out, ",");
-            if( quoteChar(azCol[i]) ){
-              char *z = sqlite3_mprintf("\"%w\"", azCol[i]);
-              utf8_printf(p->out, "%s", z);
-              sqlite3_free(z);
-            }else{
-              raw_printf(p->out, "%s", azCol[i]);
-            }
+      utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
+      if( p->showHeader ){
+        raw_printf(p->out,"(");
+        for(i=0; i<nArg; i++){
+          if( i>0 ) raw_printf(p->out, ",");
+          if( quoteChar(azCol[i]) ){
+            char *z = sqlite3_mprintf("\"%w\"", azCol[i]);
+            utf8_printf(p->out, "%s", z);
+            sqlite3_free(z);
+          }else{
+            raw_printf(p->out, "%s", azCol[i]);
           }
-          raw_printf(p->out,")");
         }
-        raw_printf(p->out," VALUES(");
-      }else if( p->cnt==0 && p->showHeader ){
+        raw_printf(p->out,")");
+      }
+      p->cnt++;
+      for(i=0; i<nArg; i++){
+        raw_printf(p->out, i>0 ? "," : " VALUES(");
+        if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
+          utf8_printf(p->out,"NULL");
+        }else if( aiType && aiType[i]==SQLITE_TEXT ){
+          output_quoted_escaped_string(p->out, azArg[i]);
+        }else if( aiType && aiType[i]==SQLITE_INTEGER ){
+          utf8_printf(p->out,"%s", azArg[i]);
+        }else if( aiType && aiType[i]==SQLITE_FLOAT ){
+          char z[50];
+          double r = sqlite3_column_double(p->pStmt, i);
+          sqlite3_snprintf(50,z,"%!.20g", r);
+          raw_printf(p->out, "%s", z);
+        }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
+          const void *pBlob = sqlite3_column_blob(p->pStmt, i);
+          int nBlob = sqlite3_column_bytes(p->pStmt, i);
+          output_hex_blob(p->out, pBlob, nBlob);
+        }else if( isNumber(azArg[i], 0) ){
+          utf8_printf(p->out,"%s", azArg[i]);
+        }else{
+          output_quoted_escaped_string(p->out, azArg[i]);
+        }
+      }
+      raw_printf(p->out,");\n");
+      break;
+    }
+    case MODE_Quote: {
+      if( azArg==0 ) break;
+      if( p->cnt==0 && p->showHeader ){
         for(i=0; i<nArg; i++){
           if( i>0 ) raw_printf(p->out, ",");
           output_quoted_string(p->out, azCol[i]);
@@ -2060,32 +2124,29 @@ static int shell_callback(
       }
       p->cnt++;
       for(i=0; i<nArg; i++){
-        char *zSep = i>0 ? ",": "";
+        if( i>0 ) raw_printf(p->out, ",");
         if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
-          utf8_printf(p->out,"%sNULL",zSep);
+          utf8_printf(p->out,"NULL");
         }else if( aiType && aiType[i]==SQLITE_TEXT ){
-          if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
           output_quoted_string(p->out, azArg[i]);
         }else if( aiType && aiType[i]==SQLITE_INTEGER ){
-          utf8_printf(p->out,"%s%s",zSep, azArg[i]);
+          utf8_printf(p->out,"%s", azArg[i]);
         }else if( aiType && aiType[i]==SQLITE_FLOAT ){
           char z[50];
           double r = sqlite3_column_double(p->pStmt, i);
           sqlite3_snprintf(50,z,"%!.20g", r);
-          raw_printf(p->out, "%s%s", zSep, z);
+          raw_printf(p->out, "%s", z);
         }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
           const void *pBlob = sqlite3_column_blob(p->pStmt, i);
           int nBlob = sqlite3_column_bytes(p->pStmt, i);
-          if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
           output_hex_blob(p->out, pBlob, nBlob);
         }else if( isNumber(azArg[i], 0) ){
-          utf8_printf(p->out,"%s%s",zSep, azArg[i]);
+          utf8_printf(p->out,"%s", azArg[i]);
         }else{
-          if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
           output_quoted_string(p->out, azArg[i]);
         }
       }
-      raw_printf(p->out,p->cMode==MODE_Quote?"\n":");\n");
+      raw_printf(p->out,"\n");
       break;
     }
     case MODE_Ascii: {