]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In the command-line shell in CSV move, put strings in C-style double-quotes.
authordrh <drh@noemail.net>
Thu, 7 Oct 2004 00:32:39 +0000 (00:32 +0000)
committerdrh <drh@noemail.net>
Thu, 7 Oct 2004 00:32:39 +0000 (00:32 +0000)
Ticket #911. (CVS 2009)

FossilOrigin-Name: 1376a0bb8d864de755c614b2ecce4342155fd09b

manifest
manifest.uuid
src/shell.c

index 9f4b85584c4efe4810b3b0b99659be2e1f3362a0..57cd6bf9b9b748feac4fc6766bec310e3c0f11b9 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\snaming\sconflict\sbetween\ssqlite.h\sand\ssqlite3.h.\s\sTicket\s#946.\s(CVS\s2007)
-D 2004-10-06T15:52:01
+C In\sthe\scommand-line\sshell\sin\sCSV\smove,\sput\sstrings\sin\sC-style\sdouble-quotes.\nTicket\s#911.\s(CVS\s2009)
+D 2004-10-07T00:32:40
 F Makefile.in 52c1cc106cad9148d4b7cb387b458e82dc86b339
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -60,7 +60,7 @@ F src/pragma.c 3134201e4d47be04b9fcd437e01eab682ad3a096
 F src/printf.c 7a92adc00b758cd5ce087dae80181a8bbdb70ed2
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
 F src/select.c de51ec24aef0d5370819dac6c2613460effac42c
-F src/shell.c bfd23e7293f468587c94f8375dfa969ce5dcd253
+F src/shell.c 2012beeea6b334c8e570e40107928036ce5bf895
 F src/sqlite.h.in 4f97b5907acfd2a5068cb0cec9d5178816734db7
 F src/sqliteInt.h 610f25a92c0ce5edf40d12087c643c310e1d7d05
 F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
@@ -251,7 +251,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P d790c84c5a889928d07f5394fffef0cbb8d5f214
-R b3cceebb7174bd299e79c0ff55d28308
+P 30370412630970a76aafb9715106911b716256db
+R a25f83fa122b7caf08059140bd1172c7
 U drh
-Z 97c46e1f9fc141789e84f32fa78ce4aa
+Z 9c5b634c11fd90503fe58c96320a51a7
index a52efb2e974fa13c6ab35cef3fed3e4a439e9f7d..75c11061bce9075eb32270644f0059fb38882650 100644 (file)
@@ -1 +1 @@
-30370412630970a76aafb9715106911b716256db
\ No newline at end of file
+1376a0bb8d864de755c614b2ecce4342155fd09b
\ No newline at end of file
index 0f2ae6251f329f2695cb52e88e8ffd431aff8b85..f9bb0b25c9e915b1ccf8ce22439d2f1f864f5ff1 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains code to implement the "sqlite" command line
 ** utility for accessing SQLite databases.
 **
-** $Id: shell.c,v 1.115 2004/10/06 14:39:07 drh Exp $
+** $Id: shell.c,v 1.116 2004/10/07 00:32:40 drh Exp $
 */
 #include <stdlib.h>
 #include <string.h>
@@ -242,7 +242,8 @@ struct callback_data {
 #define MODE_Html     4  /* Generate an XHTML table */
 #define MODE_Insert   5  /* Generate SQL "insert" statements */
 #define MODE_Tcl      6  /* Generate ANSI-C or TCL quoted elements */
-#define MODE_NUM_OF   7  /* The number of modes (not a mode itself) */
+#define MODE_Csv      7  /* Quote strings, numbers are plain */
+#define MODE_NUM_OF   8  /* The number of modes (not a mode itself) */
 
 char *modeDescr[MODE_NUM_OF] = {
   "line",
@@ -252,6 +253,7 @@ char *modeDescr[MODE_NUM_OF] = {
   "html",
   "insert",
   "tcl",
+  "csv",
 };
 
 /*
@@ -339,6 +341,25 @@ static void output_html_string(FILE *out, const char *z){
   }
 }
 
+/*
+** Output a single term of CSV.  Actually, p->separator is used for
+** the separator, which may or may not be a comma.  p->nullvalue is
+** the null value.  Strings are quoted using ANSI-C rules.  Numbers
+** appear outside of quotes.
+*/
+static void output_csv(struct callback_data *p, const char *z, int bSep){
+  if( z==0 ){
+    fprintf(p->out,"%s",p->nullvalue);
+  }else if( isNumber(z, 0) ){
+    fprintf(p->out,"%s",z);
+  }else{
+    output_c_string(p->out, z);
+  }
+  if( bSep ){
+    fprintf(p->out, p->separator);
+  }
+}
+
 /*
 ** This routine runs when the user presses Ctrl-C
 */
@@ -474,6 +495,20 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
       fprintf(p->out,"\n");
       break;
     }
+    case MODE_Csv: {
+      if( p->cnt++==0 && p->showHeader ){
+        for(i=0; i<nArg; i++){
+          output_csv(p, azCol[i], i<nArg-1);
+        }
+        fprintf(p->out,"\n");
+      }
+      if( azArg==0 ) break;
+      for(i=0; i<nArg; i++){
+        output_csv(p, azArg[i], i<nArg-1);
+      }
+      fprintf(p->out,"\n");
+      break;
+    }
     case MODE_Insert: {
       if( azArg==0 ) break;
       fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
@@ -1114,7 +1149,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
     }else if( strncmp(azArg[1],"tcl",n2)==0 ){
       p->mode = MODE_Tcl;
     }else if( strncmp(azArg[1],"csv",n2)==0 ){
-      p->mode = MODE_List;
+      p->mode = MODE_Csv;
       strcpy(p->separator, ",");
     }else if( strncmp(azArg[1],"tabs",n2)==0 ){
       p->mode = MODE_List;