mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-06 15:49:35 +03:00
In the command-line shell in CSV move, put strings in C-style double-quotes.
Ticket #911. (CVS 2009) FossilOrigin-Name: 1376a0bb8d864de755c614b2ecce4342155fd09b
This commit is contained in:
41
src/shell.c
41
src/shell.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user