mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-03 16:53:36 +03:00
In the CLI in the ".dump" command, do not attempt to clear the sqlite_sequence
table until the first row of content of that table is seen. Ticket #3867 (CVS 6664) FossilOrigin-Name: bedd5ad1942021ef2b3defde3ff3e8aead86137e
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C In\sthe\sCLI,\salways\s"dump"\sthe\ssqlite_sequence\stable\slast.\s\sTicket\s#3867\s(CVS\s6663)
|
C In\sthe\sCLI\sin\sthe\s".dump"\scommand,\sdo\snot\sattempt\sto\sclear\sthe\ssqlite_sequence\ntable\suntil\sthe\sfirst\srow\sof\scontent\sof\sthat\stable\sis\sseen.\s\sTicket\s#3867\s(CVS\s6664)
|
||||||
D 2009-05-21T14:51:03
|
D 2009-05-21T15:15:01
|
||||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||||
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
|
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
|
||||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||||
@@ -159,7 +159,7 @@ F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
|
|||||||
F src/resolve.c 2ce8f8bc8a0c913cbaec3fb3da2be113ea1fa5af
|
F src/resolve.c 2ce8f8bc8a0c913cbaec3fb3da2be113ea1fa5af
|
||||||
F src/rowset.c 14d12b5e81b5907b87d511f6f4219805f96a4b55
|
F src/rowset.c 14d12b5e81b5907b87d511f6f4219805f96a4b55
|
||||||
F src/select.c 88e654ab5b183e4fdb084680b66b5bfa6f214dc5
|
F src/select.c 88e654ab5b183e4fdb084680b66b5bfa6f214dc5
|
||||||
F src/shell.c 7d20ab57cac411a4798335ede7d8d292cb2d2d4c
|
F src/shell.c 7eacd0bdaa887931f5ff205c9defc3e8df95a2dd
|
||||||
F src/sqlite.h.in 0c459a45c1047be24c6a58646e8be4d001a3a28a
|
F src/sqlite.h.in 0c459a45c1047be24c6a58646e8be4d001a3a28a
|
||||||
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
||||||
F src/sqliteInt.h b4cc76a99bc82894703528376067c743eb27184c
|
F src/sqliteInt.h b4cc76a99bc82894703528376067c743eb27184c
|
||||||
@@ -729,7 +729,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
|||||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||||
P e4d1b117c90dca341bfa74291c7dfc2afca38cc6
|
P a0028d4808275cb1d020d56344d90b2a04603f4d
|
||||||
R 15bc7524b83192070e8332740e3dd7dd
|
R a6c6ee687310ceffc123f04a82263b69
|
||||||
U drh
|
U drh
|
||||||
Z 80201cfb6f117152d032ea15d9f61e5f
|
Z 3221b6689b30d8e2afed14ae03e93796
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
a0028d4808275cb1d020d56344d90b2a04603f4d
|
bedd5ad1942021ef2b3defde3ff3e8aead86137e
|
||||||
32
src/shell.c
32
src/shell.c
@@ -12,7 +12,7 @@
|
|||||||
** This file contains code to implement the "sqlite" command line
|
** This file contains code to implement the "sqlite" command line
|
||||||
** utility for accessing SQLite databases.
|
** utility for accessing SQLite databases.
|
||||||
**
|
**
|
||||||
** $Id: shell.c,v 1.208 2009/05/21 14:51:03 drh Exp $
|
** $Id: shell.c,v 1.209 2009/05/21 15:15:01 drh Exp $
|
||||||
*/
|
*/
|
||||||
#if defined(_WIN32) || defined(WIN32)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
/* This needs to come before any includes for MSVC compiler */
|
/* This needs to come before any includes for MSVC compiler */
|
||||||
@@ -1644,7 +1644,12 @@ static char *appendText(char *zIn, char const *zAppend, char quote){
|
|||||||
** This is used, for example, to show the schema of the database by
|
** This is used, for example, to show the schema of the database by
|
||||||
** querying the SQLITE_MASTER table.
|
** querying the SQLITE_MASTER table.
|
||||||
*/
|
*/
|
||||||
static int run_table_dump_query(FILE *out, sqlite3 *db, const char *zSelect){
|
static int run_table_dump_query(
|
||||||
|
FILE *out, /* Send output here */
|
||||||
|
sqlite3 *db, /* Database to query */
|
||||||
|
const char *zSelect, /* SELECT statement to extract content */
|
||||||
|
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(db, zSelect, -1, &pSelect, 0);
|
||||||
@@ -1653,6 +1658,10 @@ static int run_table_dump_query(FILE *out, sqlite3 *db, const char *zSelect){
|
|||||||
}
|
}
|
||||||
rc = sqlite3_step(pSelect);
|
rc = sqlite3_step(pSelect);
|
||||||
while( rc==SQLITE_ROW ){
|
while( rc==SQLITE_ROW ){
|
||||||
|
if( zFirstRow ){
|
||||||
|
fprintf(out, "%s", zFirstRow);
|
||||||
|
zFirstRow = 0;
|
||||||
|
}
|
||||||
fprintf(out, "%s;\n", sqlite3_column_text(pSelect, 0));
|
fprintf(out, "%s;\n", sqlite3_column_text(pSelect, 0));
|
||||||
rc = sqlite3_step(pSelect);
|
rc = sqlite3_step(pSelect);
|
||||||
}
|
}
|
||||||
@@ -1671,6 +1680,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
|||||||
const char *zTable;
|
const char *zTable;
|
||||||
const char *zType;
|
const char *zType;
|
||||||
const char *zSql;
|
const char *zSql;
|
||||||
|
const char *zPrepStmt = 0;
|
||||||
struct callback_data *p = (struct callback_data *)pArg;
|
struct callback_data *p = (struct callback_data *)pArg;
|
||||||
|
|
||||||
UNUSED_PARAMETER(azCol);
|
UNUSED_PARAMETER(azCol);
|
||||||
@@ -1680,7 +1690,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
|||||||
zSql = azArg[2];
|
zSql = azArg[2];
|
||||||
|
|
||||||
if( strcmp(zTable, "sqlite_sequence")==0 ){
|
if( strcmp(zTable, "sqlite_sequence")==0 ){
|
||||||
fprintf(p->out, "DELETE FROM sqlite_sequence;\n");
|
zPrepStmt = "DELETE FROM sqlite_sequence;\n";
|
||||||
}else if( strcmp(zTable, "sqlite_stat1")==0 ){
|
}else if( strcmp(zTable, "sqlite_stat1")==0 ){
|
||||||
fprintf(p->out, "ANALYZE sqlite_master;\n");
|
fprintf(p->out, "ANALYZE sqlite_master;\n");
|
||||||
}else if( strncmp(zTable, "sqlite_", 7)==0 ){
|
}else if( strncmp(zTable, "sqlite_", 7)==0 ){
|
||||||
@@ -1707,13 +1717,14 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
|||||||
char *zSelect = 0;
|
char *zSelect = 0;
|
||||||
char *zTableInfo = 0;
|
char *zTableInfo = 0;
|
||||||
char *zTmp = 0;
|
char *zTmp = 0;
|
||||||
|
int nRow = 0;
|
||||||
|
|
||||||
zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0);
|
zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0);
|
||||||
zTableInfo = appendText(zTableInfo, zTable, '"');
|
zTableInfo = appendText(zTableInfo, zTable, '"');
|
||||||
zTableInfo = appendText(zTableInfo, ");", 0);
|
zTableInfo = appendText(zTableInfo, ");", 0);
|
||||||
|
|
||||||
rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0);
|
rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0);
|
||||||
if( zTableInfo ) free(zTableInfo);
|
free(zTableInfo);
|
||||||
if( rc!=SQLITE_OK || !pTableInfo ){
|
if( rc!=SQLITE_OK || !pTableInfo ){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1735,19 +1746,20 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
|||||||
}else{
|
}else{
|
||||||
zSelect = appendText(zSelect, ") ", 0);
|
zSelect = appendText(zSelect, ") ", 0);
|
||||||
}
|
}
|
||||||
|
nRow++;
|
||||||
}
|
}
|
||||||
rc = sqlite3_finalize(pTableInfo);
|
rc = sqlite3_finalize(pTableInfo);
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK || nRow==0 ){
|
||||||
if( zSelect ) free(zSelect);
|
free(zSelect);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
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);
|
rc = run_table_dump_query(p->out, p->db, 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);
|
rc = run_table_dump_query(p->out, p->db, zSelect, 0);
|
||||||
}
|
}
|
||||||
if( zSelect ) free(zSelect);
|
if( zSelect ) free(zSelect);
|
||||||
}
|
}
|
||||||
@@ -2088,7 +2100,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
|||||||
);
|
);
|
||||||
run_table_dump_query(p->out, p->db,
|
run_table_dump_query(p->out, p->db,
|
||||||
"SELECT sql FROM sqlite_master "
|
"SELECT sql FROM sqlite_master "
|
||||||
"WHERE sql NOT NULL AND type IN ('index','trigger','view')"
|
"WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
|
||||||
);
|
);
|
||||||
}else{
|
}else{
|
||||||
int i;
|
int i;
|
||||||
@@ -2102,7 +2114,7 @@ static int do_meta_command(char *zLine, struct callback_data *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')"
|
||||||
" AND tbl_name LIKE shellstatic()"
|
" AND tbl_name LIKE shellstatic()", 0
|
||||||
);
|
);
|
||||||
zShellStatic = 0;
|
zShellStatic = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user