/ Check-in [8b2954dd]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The output of the ".dump" command in the CLI quotes newline and carriage-return characters using "char(10)" and "char(13)".
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | string-quoting-dump
Files: files | file ages | folders
SHA1: 8b2954dd8376e2de985cf5dedeb6eec32c430505
User & Date: drh 2017-03-11 01:56:41
Context
2017-03-13
18:24
In the output of the ".dump" command in the CLI, quote newline and carriage-return characters using the char() function, so that they do not get eaten by end-of-line processing logic in the OS or in other command-line utilities and/or libraries. check-in: 68f6dc7a user: drh tags: trunk
2017-03-11
01:56
The output of the ".dump" command in the CLI quotes newline and carriage-return characters using "char(10)" and "char(13)". Closed-Leaf check-in: 8b2954dd user: drh tags: string-quoting-dump
00:46
Increase the number of significant digits in floating point literals on ".dump" output from the shell. check-in: 7359fcac user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

  1486   1486     raw_printf(out,"X'");
  1487   1487     for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
  1488   1488     raw_printf(out,"'");
  1489   1489   }
  1490   1490   
  1491   1491   /*
  1492   1492   ** Output the given string as a quoted string using SQL quoting conventions.
         1493  +**
         1494  +** The "\n" and "\r" characters are converted to char(10) and char(13)
         1495  +** to prevent them from being transformed by end-of-line translators.
  1493   1496   */
  1494   1497   static void output_quoted_string(FILE *out, const char *z){
  1495   1498     int i;
  1496         -  int nSingle = 0;
         1499  +  char c;
  1497   1500     setBinaryMode(out, 1);
  1498         -  for(i=0; z[i]; i++){
  1499         -    if( z[i]=='\'' ) nSingle++;
  1500         -  }
  1501         -  if( nSingle==0 ){
         1501  +  for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
         1502  +  if( c==0 ){
  1502   1503       utf8_printf(out,"'%s'",z);
  1503   1504     }else{
  1504         -    raw_printf(out,"'");
         1505  +    int inQuote = 0;
         1506  +    int bStarted = 0;
  1505   1507       while( *z ){
  1506         -      for(i=0; z[i] && z[i]!='\''; i++){}
  1507         -      if( i==0 ){
  1508         -        raw_printf(out,"''");
  1509         -        z++;
  1510         -      }else if( z[i]=='\'' ){
  1511         -        utf8_printf(out,"%.*s''",i,z);
  1512         -        z += i+1;
  1513         -      }else{
  1514         -        utf8_printf(out,"%s",z);
         1508  +      for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){}
         1509  +      if( c=='\'' ) i++;
         1510  +      if( i ){
         1511  +        if( !inQuote ){
         1512  +          if( bStarted ) raw_printf(out, "||");
         1513  +          raw_printf(out, "'");
         1514  +          inQuote = 1;
         1515  +        }
         1516  +        utf8_printf(out, "%.*s", i, z);
         1517  +        z += i;
         1518  +        bStarted = 1;
         1519  +      }
         1520  +      if( c=='\'' ){
         1521  +        raw_printf(out, "'");
         1522  +        continue;
         1523  +      }
         1524  +      if( inQuote ){
         1525  +        raw_printf(out, "'");
         1526  +        inQuote = 0;
         1527  +      }
         1528  +      if( c==0 ){
  1515   1529           break;
  1516   1530         }
         1531  +      for(i=0; (c = z[i])=='\r' || c=='\n'; i++){
         1532  +        if( bStarted ) raw_printf(out, "||");
         1533  +        raw_printf(out, "char(%d)", c);
         1534  +        bStarted = 1;
         1535  +      }
         1536  +      z += i;
  1517   1537       }
  1518         -    raw_printf(out,"'");
         1538  +    if( inQuote ) raw_printf(out, "'");
  1519   1539     }
  1520   1540     setTextMode(out, 1);
  1521   1541   }
  1522   1542   
  1523   1543   /*
  1524   1544   ** Output the given string as a quoted according to C or TCL quoting rules.
  1525   1545   */