Update the .dump command of the command-line shell so that it (1) avoids
putting the semicolon of a DDL statement on the same line as a comment, (2) avoids long expression, even when dumping a table with many columns, and (3) avoids unnecessary quoting of the table name. This fixes tickets [c04a8b8a4f] and [232637c465]. Shell change only; no changes to the SQLite core. FossilOrigin-Name: e6eea8d50d6c307e3e34891758ed4912d368580b
This commit is contained in:
parent
8395b7b6cb
commit
b21a8e4834
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Remove\sa\scouple\sof\sunnecessary\snonterminals\sfrom\sthe\sgrammar.
|
||||
D 2012-01-28T19:44:22.866
|
||||
C Update\sthe\s.dump\scommand\sof\sthe\scommand-line\sshell\sso\sthat\sit\s(1)\savoids\nputting\sthe\ssemicolon\sof\sa\sDDL\sstatement\son\sthe\ssame\sline\sas\sa\scomment,\n(2)\savoids\slong\sexpression,\seven\swhen\sdumping\sa\stable\swith\smany\scolumns,\sand\n(3)\savoids\sunnecessary\squoting\sof\sthe\stable\sname.\s\sThis\sfixes\stickets\n[c04a8b8a4f]\sand\s[232637c465].\s\s\nShell\schange\sonly;\sno\schanges\sto\sthe\sSQLite\score.
|
||||
D 2012-01-28T21:08:51.203
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 3f79a373e57c3b92dabf76f40b065e719d31ac34
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -181,7 +181,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
|
||||
F src/resolve.c 3d3e80a98f203ac6b9329e9621e29eda85ddfd40
|
||||
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
|
||||
F src/select.c 1ad267692ab09afe05092eddcb5aba96b796afe1
|
||||
F src/shell.c f492df9fc2de27e4700ecbaa948729fc47af88d7
|
||||
F src/shell.c 60d147c2411dd2d79a5151cfb9a068de87c7babe
|
||||
F src/sqlite.h.in 53516617d2945a411d028674d7fa20dd394b9ec0
|
||||
F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
|
||||
F src/sqliteInt.h 005e7da944fdb8c2b7883ebb345caf3835c1e162
|
||||
@ -988,7 +988,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
|
||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||
P 230983e86a897caa91a487ef2d4c1c7fb7c79f10
|
||||
R b7872693d49b83267a43c45a2cca2f46
|
||||
P 2b2a7d8d736d1e72f847f443b9957e41da6149c9
|
||||
R 5a7483ac490fc4e2695fc3318a7874ef
|
||||
U drh
|
||||
Z ab25b505b5ce6d1df5ddeff0b153564c
|
||||
Z e85ab90d7cc64a88d5a03e912d2818dd
|
||||
|
@ -1 +1 @@
|
||||
2b2a7d8d736d1e72f847f443b9957e41da6149c9
|
||||
e6eea8d50d6c307e3e34891758ed4912d368580b
|
38
src/shell.c
38
src/shell.c
@ -937,11 +937,14 @@ static char *appendText(char *zIn, char const *zAppend, char quote){
|
||||
|
||||
|
||||
/*
|
||||
** Execute a query statement that has a single result column. Print
|
||||
** that result column on a line by itself with a semicolon terminator.
|
||||
** Execute a query statement that will generate SQL output. Print
|
||||
** the result columns, comma-separated, on a line and then add a
|
||||
** semicolon terminator to the end of that line.
|
||||
**
|
||||
** This is used, for example, to show the schema of the database by
|
||||
** querying the SQLITE_MASTER table.
|
||||
** If the number of columns is 1 and that column contains text "--"
|
||||
** then write the semicolon on a separate line. That way, if a
|
||||
** "--" comment occurs at the end of the statement, the comment
|
||||
** won't consume the semicolon terminator.
|
||||
*/
|
||||
static int run_table_dump_query(
|
||||
struct callback_data *p, /* Query context */
|
||||
@ -950,6 +953,9 @@ static int run_table_dump_query(
|
||||
){
|
||||
sqlite3_stmt *pSelect;
|
||||
int rc;
|
||||
int nResult;
|
||||
int i;
|
||||
const char *z;
|
||||
rc = sqlite3_prepare(p->db, zSelect, -1, &pSelect, 0);
|
||||
if( rc!=SQLITE_OK || !pSelect ){
|
||||
fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
|
||||
@ -957,12 +963,24 @@ static int run_table_dump_query(
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3_step(pSelect);
|
||||
nResult = sqlite3_column_count(pSelect);
|
||||
while( rc==SQLITE_ROW ){
|
||||
if( zFirstRow ){
|
||||
fprintf(p->out, "%s", zFirstRow);
|
||||
zFirstRow = 0;
|
||||
}
|
||||
fprintf(p->out, "%s;\n", sqlite3_column_text(pSelect, 0));
|
||||
z = (const char*)sqlite3_column_text(pSelect, 0);
|
||||
fprintf(p->out, "%s", z);
|
||||
for(i=1; i<nResult; i++){
|
||||
fprintf(p->out, ",%s", sqlite3_column_text(pSelect, i));
|
||||
}
|
||||
if( z==0 ) z = "";
|
||||
while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
|
||||
if( z[0] ){
|
||||
fprintf(p->out, "\n;\n");
|
||||
}else{
|
||||
fprintf(p->out, ";\n");
|
||||
}
|
||||
rc = sqlite3_step(pSelect);
|
||||
}
|
||||
rc = sqlite3_finalize(pSelect);
|
||||
@ -1269,6 +1287,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
char *zTableInfo = 0;
|
||||
char *zTmp = 0;
|
||||
int nRow = 0;
|
||||
int kk;
|
||||
|
||||
zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0);
|
||||
zTableInfo = appendText(zTableInfo, zTable, '"');
|
||||
@ -1281,7 +1300,12 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
}
|
||||
|
||||
zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0);
|
||||
zTmp = appendText(zTmp, zTable, '"');
|
||||
if( !isalpha(zTable[0]) ){
|
||||
kk = 0;
|
||||
}else{
|
||||
for(kk=1; isalnum(zTable[kk]); kk++){}
|
||||
}
|
||||
zTmp = appendText(zTmp, zTable, zTable[kk] ? '"' : 0);
|
||||
if( zTmp ){
|
||||
zSelect = appendText(zSelect, zTmp, '\'');
|
||||
}
|
||||
@ -1293,7 +1317,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
zSelect = appendText(zSelect, zText, '"');
|
||||
rc = sqlite3_step(pTableInfo);
|
||||
if( rc==SQLITE_ROW ){
|
||||
zSelect = appendText(zSelect, ") || ',' || ", 0);
|
||||
zSelect = appendText(zSelect, "), ", 0);
|
||||
}else{
|
||||
zSelect = appendText(zSelect, ") ", 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user