From 708b22b1e37e0093355911861c192a21f17a7fa6 Mon Sep 17 00:00:00 2001 From: drh <drh@noemail.net> Date: Sat, 11 Mar 2017 01:56:41 +0000 Subject: [PATCH] The output of the ".dump" command in the CLI quotes newline and carriage-return characters using "char(10)" and "char(13)". FossilOrigin-Name: 8b2954dd8376e2de985cf5dedeb6eec32c430505 --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/shell.c | 52 +++++++++++++++++++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 20f373b96b..a01f5a9680 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\snumber\sof\ssignificant\sdigits\sin\sfloating\spoint\sliterals\son\n".dump"\soutput\sfrom\sthe\sshell. -D 2017-03-11T00:46:57.350 +C The\soutput\sof\sthe\s".dump"\scommand\sin\sthe\sCLI\squotes\snewline\sand\scarriage-return\ncharacters\susing\s"char(10)"\sand\s"char(13)". +D 2017-03-11T01:56:41.692 F Makefile.in 2dae2a56457c2885425a480e1053de8096aff924 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 9020fa41eb91f657ae0cc44145d0a2f3af520860 @@ -399,7 +399,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c d12f3539f80db38b09015561b569e0eb1c4b6c5f -F src/shell.c df29706f8b19e3b6f695b4f64d6c6963348ca8a4 +F src/shell.c 353f3cebb938099577494326e2853010512e0625 F src/sqlite.h.in 4d0c08f8640c586564a7032b259c5f69bf397850 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1562,7 +1562,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b5bf2957677e8f2acd7426b302229a966de08fd9 -R a3ca39ff602fd356af0fc62171a8021d +P 7359fcacaadc349f520536311dcd1d0b5cea7673 +R 21dd742a2e245e17ea4fce05d92294e6 +T *branch * string-quoting-dump +T *sym-string-quoting-dump * +T -sym-trunk * U drh -Z 21429fdf284b465374d1bf63bafb22c0 +Z 185539d207724f873d847ed122ae7c58 diff --git a/manifest.uuid b/manifest.uuid index 61cc19af5e..db4edcf339 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7359fcacaadc349f520536311dcd1d0b5cea7673 \ No newline at end of file +8b2954dd8376e2de985cf5dedeb6eec32c430505 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 04f37809cc..602415f8c9 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1490,32 +1490,52 @@ static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){ /* ** 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. */ static void output_quoted_string(FILE *out, const char *z){ int i; - int nSingle = 0; + char c; setBinaryMode(out, 1); - for(i=0; z[i]; i++){ - if( z[i]=='\'' ) nSingle++; - } - if( nSingle==0 ){ + for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){} + if( c==0 ){ utf8_printf(out,"'%s'",z); }else{ - raw_printf(out,"'"); + int inQuote = 0; + int bStarted = 0; while( *z ){ - for(i=0; z[i] && z[i]!='\''; i++){} - if( i==0 ){ - raw_printf(out,"''"); - z++; - }else if( z[i]=='\'' ){ - utf8_printf(out,"%.*s''",i,z); - z += i+1; - }else{ - utf8_printf(out,"%s",z); + for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){} + if( c=='\'' ) i++; + if( i ){ + if( !inQuote ){ + if( bStarted ) raw_printf(out, "||"); + raw_printf(out, "'"); + inQuote = 1; + } + utf8_printf(out, "%.*s", i, z); + z += i; + bStarted = 1; + } + if( c=='\'' ){ + raw_printf(out, "'"); + continue; + } + if( inQuote ){ + raw_printf(out, "'"); + inQuote = 0; + } + if( c==0 ){ break; } + for(i=0; (c = z[i])=='\r' || c=='\n'; i++){ + if( bStarted ) raw_printf(out, "||"); + raw_printf(out, "char(%d)", c); + bStarted = 1; + } + z += i; } - raw_printf(out,"'"); + if( inQuote ) raw_printf(out, "'"); } setTextMode(out, 1); }