SQLite

Check-in [68f6dc7a]
Login

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

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 68f6dc7af1013f296a11db14c007cc13cc3fe56832848bfed835ed8f74dcc676
User & Date: drh 2017-03-13 18:24:06
Context
2017-03-13
22:10
Add the dbdump.c extension that implements functionality similar to the ".dump" command of the CLI, though in a separate library. (check-in: 2b9980a2 user: drh tags: trunk)
19:26
Infrastructure for an extension C-library to implement sqlite3_db_dump() and a corresponding "dbdump" command-line utility - both of which do the same work as the ".dump" command of the CLI. (check-in: 74c5ace4 user: drh tags: dbdump)
18:31
Merge all recent changes from trunk. (check-in: 3d04b2cd user: drh tags: apple-osx)
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)
17:37
Fix the sqlite3TreeViewSelect() routine so that it works with a null pointer to the Select object. (check-in: 9034cf7e 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)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/shell.c.

1486
1487
1488
1489
1490
1491
1492



1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504

1505

1506
1507


1508
1509
1510

1511
1512




1513


1514



1515
1516




1517


1518
1519
1520
1521
1522
1523
1524
1525
  raw_printf(out,"X'");
  for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
  raw_printf(out,"'");
}

/*
** Output the given string as a quoted string using SQL quoting conventions.



*/
static void output_quoted_string(FILE *out, const char *z){
  int i;
  int nSingle = 0;
  setBinaryMode(out, 1);
  for(i=0; z[i]; i++){
    if( z[i]=='\'' ) nSingle++;
  }
  if( nSingle==0 ){
    utf8_printf(out,"'%s'",z);
  }else{
    raw_printf(out,"'");

    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);



        break;
      }




    }


    raw_printf(out,"'");
  }
  setTextMode(out, 1);
}

/*
** Output the given string as a quoted according to C or TCL quoting rules.
*/







>
>
>



|

|
<
<
|


|
>

>
|
|
>
>
|
<
|
>
|
|
>
>
>
>
|
>
>
|
>
>
>


>
>
>
>
|
>
>
|







1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501


1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513

1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
  raw_printf(out,"X'");
  for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
  raw_printf(out,"'");
}

/*
** 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;
  char c;
  setBinaryMode(out, 1);
  for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}


  if( c==0 ){
    utf8_printf(out,"'%s'",z);
  }else{
    int inQuote = 0;
    int bStarted = 0;
    while( *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;
    }
    if( inQuote ) raw_printf(out, "'");
  }
  setTextMode(out, 1);
}

/*
** Output the given string as a quoted according to C or TCL quoting rules.
*/