]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Set binary mode for output on Windows when writing a quoted string that
authordrh <drh@noemail.net>
Sun, 18 Jan 2015 20:30:23 +0000 (20:30 +0000)
committerdrh <drh@noemail.net>
Sun, 18 Jan 2015 20:30:23 +0000 (20:30 +0000)
might contain newline characters.

FossilOrigin-Name: 7096e6c06d9a3e48d3f0d134f5f3275dde796be2

manifest
manifest.uuid
src/shell.c

index d122701d5e7371c2d1bdde22e2edf295c4aa7be8..12bc387dc3f3d1ef09daf67d493596d5d8262ce2 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Set\sthe\scommand-line\sshell\sstdin\sto\sbinary\smode\son\swindows.
-D 2015-01-18T01:50:54.333
+C Set\sbinary\smode\sfor\soutput\son\sWindows\swhen\swriting\sa\squoted\sstring\sthat\nmight\scontain\snewline\scharacters.
+D 2015-01-18T20:30:23.778
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -230,7 +230,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada
 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
 F src/select.c e4c38c75e36f28aed80a69a725d888751bfd53df
-F src/shell.c 96c40c85467552025d81505310efcf3679303d3a
+F src/shell.c 4958f393be95eaf223dd51f7eb799f6c5e800060
 F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada
 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
 F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
@@ -1236,7 +1236,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P ceac571f53bdbc02616b21a4404cb1250030dea8
-R af1132932e63d89318ed108ce444bb3a
+P 80541e8b94b713e8f9e588ae047ffc5ae804ef1c
+R 8c7ae3a28cebe6c4cd8f1efeb860b8e0
 U drh
-Z 8c65f5a7bb0fabe2bc52b8a9296117bf
+Z d712af0bd91c24c0e42eda8fb9513bd5
index 2997f19ca01f7cb7ad19d360566ba262fc566896..d19793c1f545bf39e9c2f6509d7ad677f7c9ecbb 100644 (file)
@@ -1 +1 @@
-80541e8b94b713e8f9e588ae047ffc5ae804ef1c
\ No newline at end of file
+7096e6c06d9a3e48d3f0d134f5f3275dde796be2
\ No newline at end of file
index 9e23734ae787155f8fd425fdcea293c8766b2607..5643e4f242cbc4a0ea5a280488e4937786877deb 100644 (file)
@@ -106,6 +106,26 @@ extern int pclose(FILE*);
 #define IsDigit(X)  isdigit((unsigned char)X)
 #define ToLower(X)  (char)tolower((unsigned char)X)
 
+/* On Windows, we normally run with output mode of TEXT so that \n characters
+** are automatically translated into \r\n.  However, this behavior needs
+** to be disabled in some cases (ex: when generating CSV output and when
+** rendering quoted strings that contain \n characters).  The following
+** routines take care of that.
+*/
+#if defined(_WIN32) || defined(WIN32)
+static setBinaryMode(FILE *out){
+  fflush(out);
+  _setmode(_fileno(out), _O_BINARY);
+}
+static setTextMode(FILE *out){
+  fflush(out);
+  _setmode(_fileno(out), _O_TEXT);
+}
+#else
+# define setBinaryMode(X)
+# define setTextMode(X)
+#endif
+
 
 /* True if the timer is enabled */
 static int enableTimer = 0;
@@ -584,6 +604,7 @@ static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
 static void output_quoted_string(FILE *out, const char *z){
   int i;
   int nSingle = 0;
+  setBinaryMode(out);
   for(i=0; z[i]; i++){
     if( z[i]=='\'' ) nSingle++;
   }
@@ -606,6 +627,7 @@ static void output_quoted_string(FILE *out, const char *z){
     }
     fprintf(out,"'");
   }
+  setTextMode(out);
 }
 
 /*
@@ -908,10 +930,7 @@ static int shell_callback(
       break;
     }
     case MODE_Csv: {
-#if defined(WIN32) || defined(_WIN32)
-      fflush(p->out);
-      _setmode(_fileno(p->out), _O_BINARY);
-#endif
+      setBinaryMode(p->out);
       if( p->cnt++==0 && p->showHeader ){
         for(i=0; i<nArg; i++){
           output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
@@ -924,10 +943,7 @@ static int shell_callback(
         }
         fprintf(p->out, "%s", p->rowSeparator);
       }
-#if defined(WIN32) || defined(_WIN32)
-      fflush(p->out);
-      _setmode(_fileno(p->out), _O_TEXT);
-#endif
+      setTextMode(p->out);
       break;
     }
     case MODE_Insert: {
@@ -4176,9 +4192,7 @@ int main(int argc, char **argv){
     exit(1);
   }
 #endif
-#if defined(WIN32) || defined(_WIN32)
-  _setmode(0, _O_BINARY);
-#endif
+  setBinaryMode(stdin);
   Argv0 = argv[0];
   main_init(&data);
   stdin_is_interactive = isatty(0);