Add ".mode quote" to the command-line shell.

FossilOrigin-Name: c4f5fa78cd8207ce1e46e32e632b8f6ee86047e1
This commit is contained in:
drh 2016-10-21 17:39:30 +00:00
parent e24452edef
commit 41f5f6ec2c
3 changed files with 30 additions and 22 deletions

View File

@ -1,5 +1,5 @@
C Avoid\susing\sthe\s"direct\soverflow\sread"\soptimization\sto\sread\slarge\sblobs\sif\sthe\npager\slayer\shas\sa\swal\sfile\sopen\s-\seven\sif\sthe\sdatabase\sheader\sindicates\sthat\nthe\sdb\sis\snot\sa\swal\sdatabase. C Add\s".mode\squote"\sto\sthe\scommand-line\sshell.
D 2016-10-21T10:49:39.630 D 2016-10-21T17:39:30.026
F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f
@ -388,7 +388,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c ea3af83e2d0f245fef81ea4cf04cb730ce67f722 F src/select.c ea3af83e2d0f245fef81ea4cf04cb730ce67f722
F src/shell.c b80396d2fadce4681397707e30078bf416e1dec2 F src/shell.c f0e8b54c58a8a13cc046f5af6d72de7e0a118a2b
F src/sqlite.h.in 7ef021d74ac7d4004c784a16ad015508f171c4bf F src/sqlite.h.in 7ef021d74ac7d4004c784a16ad015508f171c4bf
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
@ -1527,7 +1527,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P b7d9727bff2e840af4b090872c991693e78e6076 P b54c15f11796a75683eec4b502a22ccb87d621c6
R 775b940b506452362a073212102869ea R cdb213453699e4a8a0bded009eb336d4
U dan U drh
Z 738379ab10ae31c6f3af66e5c08bf61c Z 3ba463b9129586b08f555ed8d54aa9f2

View File

@ -1 +1 @@
b54c15f11796a75683eec4b502a22ccb87d621c6 c4f5fa78cd8207ce1e46e32e632b8f6ee86047e1

View File

@ -668,11 +668,12 @@ struct ShellState {
#define MODE_Semi 3 /* Same as MODE_List but append ";" to each line */ #define MODE_Semi 3 /* Same as MODE_List but append ";" to each line */
#define MODE_Html 4 /* Generate an XHTML table */ #define MODE_Html 4 /* Generate an XHTML table */
#define MODE_Insert 5 /* Generate SQL "insert" statements */ #define MODE_Insert 5 /* Generate SQL "insert" statements */
#define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */ #define MODE_Quote 6 /* Quote values as for SQL */
#define MODE_Csv 7 /* Quote strings, numbers are plain */ #define MODE_Tcl 7 /* Generate ANSI-C or TCL quoted elements */
#define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */ #define MODE_Csv 8 /* Quote strings, numbers are plain */
#define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */ #define MODE_Explain 9 /* Like MODE_Column, but do not truncate data */
#define MODE_Pretty 10 /* Pretty-print schemas */ #define MODE_Ascii 10 /* Use ASCII unit and record separators (0x1F/0x1E) */
#define MODE_Pretty 11 /* Pretty-print schemas */
static const char *modeDescr[] = { static const char *modeDescr[] = {
"line", "line",
@ -681,6 +682,7 @@ static const char *modeDescr[] = {
"semi", "semi",
"html", "html",
"insert", "insert",
"quote",
"tcl", "tcl",
"csv", "csv",
"explain", "explain",
@ -1198,19 +1200,22 @@ static int shell_callback(
setTextMode(p->out, 1); setTextMode(p->out, 1);
break; break;
} }
case MODE_Quote:
case MODE_Insert: { case MODE_Insert: {
p->cnt++; p->cnt++;
if( azArg==0 ) break; if( azArg==0 ) break;
utf8_printf(p->out,"INSERT INTO %s",p->zDestTable); if( p->cMode==MODE_Insert ){
if( p->showHeader ){ utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
raw_printf(p->out,"("); if( p->showHeader ){
for(i=0; i<nArg; i++){ raw_printf(p->out,"(");
char *zSep = i>0 ? ",": ""; for(i=0; i<nArg; i++){
utf8_printf(p->out, "%s%s", zSep, azCol[i]); char *zSep = i>0 ? ",": "";
utf8_printf(p->out, "%s%s", zSep, azCol[i]);
}
raw_printf(p->out,")");
} }
raw_printf(p->out,")"); raw_printf(p->out," VALUES(");
} }
raw_printf(p->out," VALUES(");
for(i=0; i<nArg; i++){ for(i=0; i<nArg; i++){
char *zSep = i>0 ? ",": ""; char *zSep = i>0 ? ",": "";
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
@ -1233,7 +1238,7 @@ static int shell_callback(
output_quoted_string(p->out, azArg[i]); output_quoted_string(p->out, azArg[i]);
} }
} }
raw_printf(p->out,");\n"); raw_printf(p->out,p->cMode==MODE_Quote?"\n":");\n");
break; break;
} }
case MODE_Ascii: { case MODE_Ascii: {
@ -2177,6 +2182,7 @@ static char zHelp[] =
" insert SQL insert statements for TABLE\n" " insert SQL insert statements for TABLE\n"
" line One value per line\n" " line One value per line\n"
" list Values delimited by .separator strings\n" " list Values delimited by .separator strings\n"
" quote Escape answers as for SQL\n"
" tabs Tab-separated values\n" " tabs Tab-separated values\n"
" tcl TCL list elements\n" " tcl TCL list elements\n"
".nullvalue STRING Use STRING in place of NULL values\n" ".nullvalue STRING Use STRING in place of NULL values\n"
@ -3977,6 +3983,8 @@ static int do_meta_command(char *zLine, ShellState *p){
}else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){ }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
p->mode = MODE_Insert; p->mode = MODE_Insert;
set_table_name(p, nArg>=3 ? azArg[2] : "table"); set_table_name(p, nArg>=3 ? azArg[2] : "table");
}else if( c2=='q' && strncmp(azArg[1],"quote",n2)==0 ){
p->mode = MODE_Quote;
}else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){ }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
p->mode = MODE_Ascii; p->mode = MODE_Ascii;
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit); sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);