mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-05 04:30:38 +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]
|
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:11:36.709
|
D 2011-10-13T00:41:49.789
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in a162fe39e249b8ed4a65ee947c30152786cfe897
|
F Makefile.in a162fe39e249b8ed4a65ee947c30152786cfe897
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -180,7 +180,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
|
|||||||
F src/resolve.c 36368f44569208fa074e61f4dd0b6c4fb60ca2b4
|
F src/resolve.c 36368f44569208fa074e61f4dd0b6c4fb60ca2b4
|
||||||
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
|
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
|
||||||
F src/select.c 94b375306bfb4590fdfd76581ae663f57e94808f
|
F src/select.c 94b375306bfb4590fdfd76581ae663f57e94808f
|
||||||
F src/shell.c a07ce148dc665e4283edf878d0fb52fed2018408
|
F src/shell.c bef48bc4fa2e42535aee14c1e0ca34b0a43f27e4
|
||||||
F src/sqlite.h.in 821027573c481e45ba276b078a3ae9ebaeb9bb92
|
F src/sqlite.h.in 821027573c481e45ba276b078a3ae9ebaeb9bb92
|
||||||
F src/sqlite3ext.h 1a1a4f784aa9c3b00edd287940197de52487cd93
|
F src/sqlite3ext.h 1a1a4f784aa9c3b00edd287940197de52487cd93
|
||||||
F src/sqliteInt.h 6f8e592fc28d16160d017684966b3528833a46c1
|
F src/sqliteInt.h 6f8e592fc28d16160d017684966b3528833a46c1
|
||||||
@@ -966,7 +966,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5
|
|||||||
F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||||
P d5b6b374c5225d21c386fb3d6507d3938296e759
|
P af8bcdd951c31f69966942d67833da30f6b121bf
|
||||||
R ad241b5f1e2b5a40e8b22e9f2c8bb18c
|
R cf954ca8f3097f02bf28c5ed04310c31
|
||||||
U drh
|
U drh
|
||||||
Z 12a1fc6a3955002b8a71d507adebb052
|
Z bdd04747fa59c02e0592ff23948f0dfa
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
af8bcdd951c31f69966942d67833da30f6b121bf
|
8a8dcd6bd043d82dc04b6ad0614c64d20ace8e5f
|
||||||
67
src/shell.c
67
src/shell.c
@@ -407,6 +407,7 @@ struct callback_data {
|
|||||||
int statsOn; /* True to display memory stats before each finalize */
|
int statsOn; /* True to display memory stats before each finalize */
|
||||||
int cnt; /* Number of records displayed so far */
|
int cnt; /* Number of records displayed so far */
|
||||||
FILE *out; /* Write results here */
|
FILE *out; /* Write results here */
|
||||||
|
int nErr; /* Number of errors seen */
|
||||||
int mode; /* An output mode setting */
|
int mode; /* An output mode setting */
|
||||||
int writableSchema; /* True if PRAGMA writable_schema=ON */
|
int writableSchema; /* True if PRAGMA writable_schema=ON */
|
||||||
int showHeader; /* True to show column names in List or Column mode */
|
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.
|
** querying the SQLITE_MASTER table.
|
||||||
*/
|
*/
|
||||||
static int run_table_dump_query(
|
static int run_table_dump_query(
|
||||||
FILE *out, /* Send output here */
|
struct callback_data *p, /* Query context */
|
||||||
sqlite3 *db, /* Database to query */
|
const char *zSelect, /* SELECT statement to extract content */
|
||||||
const char *zSelect, /* SELECT statement to extract content */
|
const char *zFirstRow /* Print before first row, if not NULL */
|
||||||
const char *zFirstRow /* Print before first row, if not NULL */
|
|
||||||
){
|
){
|
||||||
sqlite3_stmt *pSelect;
|
sqlite3_stmt *pSelect;
|
||||||
int rc;
|
int rc;
|
||||||
rc = sqlite3_prepare(db, zSelect, -1, &pSelect, 0);
|
rc = sqlite3_prepare(p->db, zSelect, -1, &pSelect, 0);
|
||||||
if( rc!=SQLITE_OK || !pSelect ){
|
if( rc!=SQLITE_OK || !pSelect ){
|
||||||
|
fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
|
||||||
|
p->nErr++;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
rc = sqlite3_step(pSelect);
|
rc = sqlite3_step(pSelect);
|
||||||
while( rc==SQLITE_ROW ){
|
while( rc==SQLITE_ROW ){
|
||||||
if( zFirstRow ){
|
if( zFirstRow ){
|
||||||
fprintf(out, "%s", zFirstRow);
|
fprintf(p->out, "%s", zFirstRow);
|
||||||
zFirstRow = 0;
|
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);
|
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, "|| ')' FROM ", 0);
|
||||||
zSelect = appendText(zSelect, zTable, '"');
|
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 ){
|
if( rc==SQLITE_CORRUPT ){
|
||||||
zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0);
|
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);
|
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(
|
static int run_schema_dump_query(
|
||||||
struct callback_data *p,
|
struct callback_data *p,
|
||||||
const char *zQuery,
|
const char *zQuery
|
||||||
char **pzErrMsg
|
|
||||||
){
|
){
|
||||||
int rc;
|
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 ){
|
if( rc==SQLITE_CORRUPT ){
|
||||||
char *zQ2;
|
char *zQ2;
|
||||||
int len = strlen30(zQuery);
|
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 );
|
zQ2 = malloc( len+100 );
|
||||||
if( zQ2==0 ) return rc;
|
if( zQ2==0 ) return rc;
|
||||||
sqlite3_snprintf(sizeof(zQ2), zQ2, "%s ORDER BY rowid DESC", zQuery);
|
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);
|
free(zQ2);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
@@ -1555,7 +1573,6 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
|||||||
}else
|
}else
|
||||||
|
|
||||||
if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
|
if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
|
||||||
char *zErrMsg = 0;
|
|
||||||
open_db(p);
|
open_db(p);
|
||||||
/* When playing back a "dump", the content might appear in an order
|
/* When playing back a "dump", the content might appear in an order
|
||||||
** which causes immediate foreign key constraints to be violated.
|
** 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");
|
fprintf(p->out, "BEGIN TRANSACTION;\n");
|
||||||
p->writableSchema = 0;
|
p->writableSchema = 0;
|
||||||
sqlite3_exec(p->db, "PRAGMA writable_schema=ON", 0, 0, 0);
|
sqlite3_exec(p->db, "PRAGMA writable_schema=ON", 0, 0, 0);
|
||||||
|
p->nErr = 0;
|
||||||
if( nArg==1 ){
|
if( nArg==1 ){
|
||||||
run_schema_dump_query(p,
|
run_schema_dump_query(p,
|
||||||
"SELECT name, type, sql FROM sqlite_master "
|
"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,
|
run_schema_dump_query(p,
|
||||||
"SELECT name, type, sql FROM sqlite_master "
|
"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 "
|
"SELECT sql FROM sqlite_master "
|
||||||
"WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
|
"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,
|
run_schema_dump_query(p,
|
||||||
"SELECT name, type, sql FROM sqlite_master "
|
"SELECT name, type, sql FROM sqlite_master "
|
||||||
"WHERE tbl_name LIKE shellstatic() AND type=='table'"
|
"WHERE tbl_name LIKE shellstatic() AND type=='table'"
|
||||||
" AND sql NOT NULL", 0);
|
" AND sql NOT NULL");
|
||||||
run_table_dump_query(p->out, p->db,
|
run_table_dump_query(p,
|
||||||
"SELECT sql FROM sqlite_master "
|
"SELECT sql FROM sqlite_master "
|
||||||
"WHERE sql NOT NULL"
|
"WHERE sql NOT NULL"
|
||||||
" AND type IN ('index','trigger','view')"
|
" AND type IN ('index','trigger','view')"
|
||||||
@@ -1599,12 +1617,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
|||||||
p->writableSchema = 0;
|
p->writableSchema = 0;
|
||||||
}
|
}
|
||||||
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF", 0, 0, 0);
|
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF", 0, 0, 0);
|
||||||
if( zErrMsg ){
|
fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
|
||||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
|
||||||
sqlite3_free(zErrMsg);
|
|
||||||
}else{
|
|
||||||
fprintf(p->out, "COMMIT;\n");
|
|
||||||
}
|
|
||||||
}else
|
}else
|
||||||
|
|
||||||
if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
|
if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
|
||||||
|
|||||||
Reference in New Issue
Block a user