/ Check-in [c4f5fa78]
Login

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

Overview
Comment:Add ".mode quote" to the command-line shell.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c4f5fa78cd8207ce1e46e32e632b8f6ee86047e1
User & Date: drh 2016-10-21 17:39:30
Context
2016-10-22
01:22
In the sessions module, avoid recording a change if an UPDATE statement overwrites a column with REAL affinity containing an integer value with the same value. check-in: 5f3e6028 user: drh tags: trunk
2016-10-21
21:21
In the sessions module, avoid recording a change if an UPDATE statement overwrites a column with REAL affinity containing an integer value with the same value. Closed-Leaf check-in: b861328a user: dan tags: sessions-fix
17:45
Merge updates from trunk, and especially the ".mode quote" enhancement to the shell. check-in: 0c8a5b88 user: drh tags: est_count_pragma
17:39
Add ".mode quote" to the command-line shell. check-in: c4f5fa78 user: drh tags: trunk
10:49
Avoid using the "direct overflow read" optimization to read large blobs if the pager layer has a wal file open - even if the database header indicates that the db is not a wal database. check-in: b54c15f1 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

   664    664   */
   665    665   #define MODE_Line     0  /* One column per line.  Blank line between records */
   666    666   #define MODE_Column   1  /* One record per line in neat columns */
   667    667   #define MODE_List     2  /* One record per line with a separator */
   668    668   #define MODE_Semi     3  /* Same as MODE_List but append ";" to each line */
   669    669   #define MODE_Html     4  /* Generate an XHTML table */
   670    670   #define MODE_Insert   5  /* Generate SQL "insert" statements */
   671         -#define MODE_Tcl      6  /* Generate ANSI-C or TCL quoted elements */
   672         -#define MODE_Csv      7  /* Quote strings, numbers are plain */
   673         -#define MODE_Explain  8  /* Like MODE_Column, but do not truncate data */
   674         -#define MODE_Ascii    9  /* Use ASCII unit and record separators (0x1F/0x1E) */
   675         -#define MODE_Pretty  10  /* Pretty-print schemas */
          671  +#define MODE_Quote    6  /* Quote values as for SQL */
          672  +#define MODE_Tcl      7  /* Generate ANSI-C or TCL quoted elements */
          673  +#define MODE_Csv      8  /* Quote strings, numbers are plain */
          674  +#define MODE_Explain  9  /* Like MODE_Column, but do not truncate data */
          675  +#define MODE_Ascii   10  /* Use ASCII unit and record separators (0x1F/0x1E) */
          676  +#define MODE_Pretty  11  /* Pretty-print schemas */
   676    677   
   677    678   static const char *modeDescr[] = {
   678    679     "line",
   679    680     "column",
   680    681     "list",
   681    682     "semi",
   682    683     "html",
   683    684     "insert",
          685  +  "quote",
   684    686     "tcl",
   685    687     "csv",
   686    688     "explain",
   687    689     "ascii",
   688    690     "prettyprint",
   689    691   };
   690    692   
................................................................................
  1194   1196             output_csv(p, azArg[i], i<nArg-1);
  1195   1197           }
  1196   1198           utf8_printf(p->out, "%s", p->rowSeparator);
  1197   1199         }
  1198   1200         setTextMode(p->out, 1);
  1199   1201         break;
  1200   1202       }
         1203  +    case MODE_Quote:
  1201   1204       case MODE_Insert: {
  1202   1205         p->cnt++;
  1203   1206         if( azArg==0 ) break;
  1204         -      utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
  1205         -      if( p->showHeader ){
  1206         -        raw_printf(p->out,"(");
  1207         -        for(i=0; i<nArg; i++){
  1208         -          char *zSep = i>0 ? ",": "";
  1209         -          utf8_printf(p->out, "%s%s", zSep, azCol[i]);
         1207  +      if( p->cMode==MODE_Insert ){
         1208  +        utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
         1209  +        if( p->showHeader ){
         1210  +          raw_printf(p->out,"(");
         1211  +          for(i=0; i<nArg; i++){
         1212  +            char *zSep = i>0 ? ",": "";
         1213  +            utf8_printf(p->out, "%s%s", zSep, azCol[i]);
         1214  +          }
         1215  +          raw_printf(p->out,")");
  1210   1216           }
  1211         -        raw_printf(p->out,")");
         1217  +        raw_printf(p->out," VALUES(");
  1212   1218         }
  1213         -      raw_printf(p->out," VALUES(");
  1214   1219         for(i=0; i<nArg; i++){
  1215   1220           char *zSep = i>0 ? ",": "";
  1216   1221           if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
  1217   1222             utf8_printf(p->out,"%sNULL",zSep);
  1218   1223           }else if( aiType && aiType[i]==SQLITE_TEXT ){
  1219   1224             if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
  1220   1225             output_quoted_string(p->out, azArg[i]);
................................................................................
  1229   1234           }else if( isNumber(azArg[i], 0) ){
  1230   1235             utf8_printf(p->out,"%s%s",zSep, azArg[i]);
  1231   1236           }else{
  1232   1237             if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
  1233   1238             output_quoted_string(p->out, azArg[i]);
  1234   1239           }
  1235   1240         }
  1236         -      raw_printf(p->out,");\n");
         1241  +      raw_printf(p->out,p->cMode==MODE_Quote?"\n":");\n");
  1237   1242         break;
  1238   1243       }
  1239   1244       case MODE_Ascii: {
  1240   1245         if( p->cnt++==0 && p->showHeader ){
  1241   1246           for(i=0; i<nArg; i++){
  1242   1247             if( i>0 ) utf8_printf(p->out, "%s", p->colSeparator);
  1243   1248             utf8_printf(p->out,"%s",azCol[i] ? azCol[i] : "");
................................................................................
  2173   2178     "                         ascii    Columns/rows delimited by 0x1F and 0x1E\n"
  2174   2179     "                         csv      Comma-separated values\n"
  2175   2180     "                         column   Left-aligned columns.  (See .width)\n"
  2176   2181     "                         html     HTML <table> code\n"
  2177   2182     "                         insert   SQL insert statements for TABLE\n"
  2178   2183     "                         line     One value per line\n"
  2179   2184     "                         list     Values delimited by .separator strings\n"
         2185  +  "                         quote    Escape answers as for SQL\n"
  2180   2186     "                         tabs     Tab-separated values\n"
  2181   2187     "                         tcl      TCL list elements\n"
  2182   2188     ".nullvalue STRING      Use STRING in place of NULL values\n"
  2183   2189     ".once FILENAME         Output for the next SQL command only to FILENAME\n"
  2184   2190     ".open ?--new? ?FILE?   Close existing database and reopen FILE\n"
  2185   2191     "                         The --new starts with an empty file\n"
  2186   2192     ".output ?FILENAME?     Send output to FILENAME or stdout\n"
................................................................................
  3973   3979         sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
  3974   3980       }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
  3975   3981         p->mode = MODE_List;
  3976   3982         sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
  3977   3983       }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
  3978   3984         p->mode = MODE_Insert;
  3979   3985         set_table_name(p, nArg>=3 ? azArg[2] : "table");
         3986  +    }else if( c2=='q' && strncmp(azArg[1],"quote",n2)==0 ){
         3987  +      p->mode = MODE_Quote;
  3980   3988       }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
  3981   3989         p->mode = MODE_Ascii;
  3982   3990         sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
  3983   3991         sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
  3984   3992       }else {
  3985   3993         raw_printf(stderr, "Error: mode should be one of: "
  3986   3994            "ascii column csv html insert line list tabs tcl\n");