mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-06 15:49:35 +03:00
If errors are encountered while processing the ".dump" command in the
command-line shell, print error messages as comments in the output and ROLLBACK at the end rather than committing. Ticket [ee19e690ec9a5a2] FossilOrigin-Name: 8a8dcd6bd043d82dc04b6ad0614c64d20ace8e5f
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
||||
C Be\ssure\sto\sallocate\splenty\sof\sspace\sfor\serror\smessages\scoming\sout\sof\nsqlite3_load_extension(),\sso\sthat\sfilenames\sand\sprocedure\snames\sare\nnot\struncated.\s\sTicket\s[7d32c69b50f89d]
|
||||
D 2011-10-13T00:11:36.709
|
||||
C If\serrors\sare\sencountered\swhile\sprocessing\sthe\s".dump"\scommand\sin\sthe\ncommand-line\sshell,\sprint\serror\smessages\sas\scomments\sin\sthe\soutput\sand\nROLLBACK\sat\sthe\send\srather\sthan\scommitting.\nTicket\s[ee19e690ec9a5a2]
|
||||
D 2011-10-13T00:41:49.789
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in a162fe39e249b8ed4a65ee947c30152786cfe897
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@@ -180,7 +180,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
|
||||
F src/resolve.c 36368f44569208fa074e61f4dd0b6c4fb60ca2b4
|
||||
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
|
||||
F src/select.c 94b375306bfb4590fdfd76581ae663f57e94808f
|
||||
F src/shell.c a07ce148dc665e4283edf878d0fb52fed2018408
|
||||
F src/shell.c bef48bc4fa2e42535aee14c1e0ca34b0a43f27e4
|
||||
F src/sqlite.h.in 821027573c481e45ba276b078a3ae9ebaeb9bb92
|
||||
F src/sqlite3ext.h 1a1a4f784aa9c3b00edd287940197de52487cd93
|
||||
F src/sqliteInt.h 6f8e592fc28d16160d017684966b3528833a46c1
|
||||
@@ -966,7 +966,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5
|
||||
F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||
P d5b6b374c5225d21c386fb3d6507d3938296e759
|
||||
R ad241b5f1e2b5a40e8b22e9f2c8bb18c
|
||||
P af8bcdd951c31f69966942d67833da30f6b121bf
|
||||
R cf954ca8f3097f02bf28c5ed04310c31
|
||||
U drh
|
||||
Z 12a1fc6a3955002b8a71d507adebb052
|
||||
Z bdd04747fa59c02e0592ff23948f0dfa
|
||||
|
||||
@@ -1 +1 @@
|
||||
af8bcdd951c31f69966942d67833da30f6b121bf
|
||||
8a8dcd6bd043d82dc04b6ad0614c64d20ace8e5f
|
||||
63
src/shell.c
63
src/shell.c
@@ -407,6 +407,7 @@ struct callback_data {
|
||||
int statsOn; /* True to display memory stats before each finalize */
|
||||
int cnt; /* Number of records displayed so far */
|
||||
FILE *out; /* Write results here */
|
||||
int nErr; /* Number of errors seen */
|
||||
int mode; /* An output mode setting */
|
||||
int writableSchema; /* True if PRAGMA writable_schema=ON */
|
||||
int showHeader; /* True to show column names in List or Column mode */
|
||||
@@ -932,27 +933,33 @@ static char *appendText(char *zIn, char const *zAppend, char quote){
|
||||
** querying the SQLITE_MASTER table.
|
||||
*/
|
||||
static int run_table_dump_query(
|
||||
FILE *out, /* Send output here */
|
||||
sqlite3 *db, /* Database to query */
|
||||
struct callback_data *p, /* Query context */
|
||||
const char *zSelect, /* SELECT statement to extract content */
|
||||
const char *zFirstRow /* Print before first row, if not NULL */
|
||||
){
|
||||
sqlite3_stmt *pSelect;
|
||||
int rc;
|
||||
rc = sqlite3_prepare(db, zSelect, -1, &pSelect, 0);
|
||||
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));
|
||||
p->nErr++;
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3_step(pSelect);
|
||||
while( rc==SQLITE_ROW ){
|
||||
if( zFirstRow ){
|
||||
fprintf(out, "%s", zFirstRow);
|
||||
fprintf(p->out, "%s", zFirstRow);
|
||||
zFirstRow = 0;
|
||||
}
|
||||
fprintf(out, "%s;\n", sqlite3_column_text(pSelect, 0));
|
||||
fprintf(p->out, "%s;\n", sqlite3_column_text(pSelect, 0));
|
||||
rc = sqlite3_step(pSelect);
|
||||
}
|
||||
return sqlite3_finalize(pSelect);
|
||||
rc = sqlite3_finalize(pSelect);
|
||||
if( rc!=SQLITE_OK ){
|
||||
fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
|
||||
p->nErr++;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1278,10 +1285,10 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
zSelect = appendText(zSelect, "|| ')' FROM ", 0);
|
||||
zSelect = appendText(zSelect, zTable, '"');
|
||||
|
||||
rc = run_table_dump_query(p->out, p->db, zSelect, zPrepStmt);
|
||||
rc = run_table_dump_query(p, zSelect, zPrepStmt);
|
||||
if( rc==SQLITE_CORRUPT ){
|
||||
zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0);
|
||||
rc = run_table_dump_query(p->out, p->db, zSelect, 0);
|
||||
run_table_dump_query(p, zSelect, 0);
|
||||
}
|
||||
if( zSelect ) free(zSelect);
|
||||
}
|
||||
@@ -1297,19 +1304,30 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
*/
|
||||
static int run_schema_dump_query(
|
||||
struct callback_data *p,
|
||||
const char *zQuery,
|
||||
char **pzErrMsg
|
||||
const char *zQuery
|
||||
){
|
||||
int rc;
|
||||
rc = sqlite3_exec(p->db, zQuery, dump_callback, p, pzErrMsg);
|
||||
char *zErr = 0;
|
||||
rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr);
|
||||
if( rc==SQLITE_CORRUPT ){
|
||||
char *zQ2;
|
||||
int len = strlen30(zQuery);
|
||||
if( pzErrMsg ) sqlite3_free(*pzErrMsg);
|
||||
fprintf(p->out, "/****** CORRUPTION ERROR *******/\n");
|
||||
if( zErr ){
|
||||
fprintf(p->out, "/****** %s ******/\n", zErr);
|
||||
sqlite3_free(zErr);
|
||||
zErr = 0;
|
||||
}
|
||||
zQ2 = malloc( len+100 );
|
||||
if( zQ2==0 ) return rc;
|
||||
sqlite3_snprintf(sizeof(zQ2), zQ2, "%s ORDER BY rowid DESC", zQuery);
|
||||
rc = sqlite3_exec(p->db, zQ2, dump_callback, p, pzErrMsg);
|
||||
rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
|
||||
if( rc ){
|
||||
fprintf(p->out, "/****** ERROR: %s ******/\n", zErr);
|
||||
}else{
|
||||
rc = SQLITE_CORRUPT;
|
||||
}
|
||||
sqlite3_free(zErr);
|
||||
free(zQ2);
|
||||
}
|
||||
return rc;
|
||||
@@ -1555,7 +1573,6 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
}else
|
||||
|
||||
if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
|
||||
char *zErrMsg = 0;
|
||||
open_db(p);
|
||||
/* When playing back a "dump", the content might appear in an order
|
||||
** which causes immediate foreign key constraints to be violated.
|
||||
@@ -1564,16 +1581,17 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
fprintf(p->out, "BEGIN TRANSACTION;\n");
|
||||
p->writableSchema = 0;
|
||||
sqlite3_exec(p->db, "PRAGMA writable_schema=ON", 0, 0, 0);
|
||||
p->nErr = 0;
|
||||
if( nArg==1 ){
|
||||
run_schema_dump_query(p,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'", 0
|
||||
"WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'"
|
||||
);
|
||||
run_schema_dump_query(p,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE name=='sqlite_sequence'", 0
|
||||
"WHERE name=='sqlite_sequence'"
|
||||
);
|
||||
run_table_dump_query(p->out, p->db,
|
||||
run_table_dump_query(p,
|
||||
"SELECT sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
|
||||
);
|
||||
@@ -1584,8 +1602,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
run_schema_dump_query(p,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE tbl_name LIKE shellstatic() AND type=='table'"
|
||||
" AND sql NOT NULL", 0);
|
||||
run_table_dump_query(p->out, p->db,
|
||||
" AND sql NOT NULL");
|
||||
run_table_dump_query(p,
|
||||
"SELECT sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL"
|
||||
" AND type IN ('index','trigger','view')"
|
||||
@@ -1599,12 +1617,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
p->writableSchema = 0;
|
||||
}
|
||||
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF", 0, 0, 0);
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
}else{
|
||||
fprintf(p->out, "COMMIT;\n");
|
||||
}
|
||||
fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
|
||||
}else
|
||||
|
||||
if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
|
||||
|
||||
Reference in New Issue
Block a user