1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Enhance the ".dump" command in the CLI so that it accepts multiple LIKE

pattern arguments and shows the union of all matching tables.

FossilOrigin-Name: 45fba3d7055f90f67005ca740687f060a2311db40c8f6a161bfea0424e6ebf6d
This commit is contained in:
drh
2020-03-25 12:50:13 +00:00
parent 74a07986ce
commit 8e9297fb79
4 changed files with 39 additions and 54 deletions

View File

@ -1,5 +1,5 @@
C Fix\sto\sthe\srecomputation\sof\sthe\scolUsed\sfield\sadded\sby\scheck-in\n[a9bb71ba708ba722].\s\sThis\sfixes\sticket\s[5829597ac43811e3]. C Enhance\sthe\s".dump"\scommand\sin\sthe\sCLI\sso\sthat\sit\saccepts\smultiple\sLIKE\npattern\sarguments\sand\sshows\sthe\sunion\sof\sall\smatching\stables.
D 2020-03-21T23:10:38.823 D 2020-03-25T12:50:13.948
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -532,7 +532,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 903a70c48d0f72fdd657b225d499cf99ec01d575cf3fbc8196b43562045319ac F src/resolve.c 903a70c48d0f72fdd657b225d499cf99ec01d575cf3fbc8196b43562045319ac
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c 6908c059e4289149f88bfd641305b96ee34e500855fcd580ff8df1bd0885191a F src/select.c 6908c059e4289149f88bfd641305b96ee34e500855fcd580ff8df1bd0885191a
F src/shell.c.in f76590931c0cbbfef347f44f81ade6b335f80c46bc6e59b8b6114383a8df30e0 F src/shell.c.in 10093b8f88cfdce124c99f382a26a922210315cc537ef0f8e2d811fc5aa7a3b2
F src/sqlite.h.in 802957feeb249ede54f8dfe99b72aa19e70a0b7737969c46e625dc2f9f2d42b0 F src/sqlite.h.in 802957feeb249ede54f8dfe99b72aa19e70a0b7737969c46e625dc2f9f2d42b0
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 9c5269260409eb3275324ccace6a13a96f4ad330c708415f70ca6097901ff4ee F src/sqlite3ext.h 9c5269260409eb3275324ccace6a13a96f4ad330c708415f70ca6097901ff4ee
@ -1333,7 +1333,7 @@ F test/sharedA.test 49d87ec54ab640fbbc3786ee3c01de94aaa482a3a9f834ad3fe92770eb69
F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e
F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939 F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939
F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
F test/shell1.test 43e12c7d4ff65f041803ad24a93fd3818deb2cb83e721810f27d0fde61d64a13 F test/shell1.test 1796b7f76d09ffd2b2dc0ff5ad89428e9892f237d4f4e33ef2278f064a2d94a4
F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b
F test/shell3.test ac8c2b744014c3e9a0e26bfd829ab65f00923dc1a91ffd044863e9423cc91494 F test/shell3.test ac8c2b744014c3e9a0e26bfd829ab65f00923dc1a91ffd044863e9423cc91494
F test/shell4.test 1c6aef11daaa2d6830acaba3ac9cbec93fbc1c3d5530743a637f39b3987d08ce F test/shell4.test 1c6aef11daaa2d6830acaba3ac9cbec93fbc1c3d5530743a637f39b3987d08ce
@ -1860,7 +1860,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 8a5c539b77aa174c048a504d211c56902075f9b42b654e1f8cc5767739e5fcc9 P 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525
R 480ea7ba1b66f997fe626bc516b1544b R 3d4d5bc7aeb5d456d8c0a7166a26bb4e
U drh U drh
Z 1f463b1edcb75b2ef80d4761df1603b9 Z ff19b393b7175126a56d85ef88b57634

View File

@ -1 +1 @@
5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525 45fba3d7055f90f67005ca740687f060a2311db40c8f6a161bfea0424e6ebf6d

View File

@ -2358,8 +2358,7 @@ static void set_table_name(ShellState *p, const char *zName){
*/ */
static int run_table_dump_query( static int run_table_dump_query(
ShellState *p, /* Query context */ ShellState *p, /* Query context */
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 */
){ ){
sqlite3_stmt *pSelect; sqlite3_stmt *pSelect;
int rc; int rc;
@ -2376,10 +2375,6 @@ static int run_table_dump_query(
rc = sqlite3_step(pSelect); rc = sqlite3_step(pSelect);
nResult = sqlite3_column_count(pSelect); nResult = sqlite3_column_count(pSelect);
while( rc==SQLITE_ROW ){ while( rc==SQLITE_ROW ){
if( zFirstRow ){
utf8_printf(p->out, "%s", zFirstRow);
zFirstRow = 0;
}
z = (const char*)sqlite3_column_text(pSelect, 0); z = (const char*)sqlite3_column_text(pSelect, 0);
utf8_printf(p->out, "%s", z); utf8_printf(p->out, "%s", z);
for(i=1; i<nResult; i++){ for(i=1; i<nResult; i++){
@ -3552,11 +3547,12 @@ static const char *(azHelp[]) = {
".databases List names and files of attached databases", ".databases List names and files of attached databases",
".dbconfig ?op? ?val? List or change sqlite3_db_config() options", ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
".dbinfo ?DB? Show status information about the database", ".dbinfo ?DB? Show status information about the database",
".dump ?TABLE? ... Render all database content as SQL", ".dump ?TABLE? Render database content as SQL",
" Options:", " Options:",
" --preserve-rowids Include ROWID values in the output", " --preserve-rowids Include ROWID values in the output",
" --newlines Allow unescaped newline characters in output", " --newlines Allow unescaped newline characters in output",
" TABLE is a LIKE pattern for the tables to dump", " TABLE is a LIKE pattern for the tables to dump",
" Additional LIKE patterns can be given in subsequent arguments",
".echo on|off Turn command echo on or off", ".echo on|off Turn command echo on or off",
".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN", ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
" Other Modes:", " Other Modes:",
@ -7278,7 +7274,8 @@ static int do_meta_command(char *zLine, ShellState *p){
#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */ #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){ if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
const char *zLike = 0; char *zLike = 0;
char *zSql;
int i; int i;
int savedShowHeader = p->showHeader; int savedShowHeader = p->showHeader;
int savedShellFlags = p->shellFlgs; int savedShellFlags = p->shellFlgs;
@ -7306,12 +7303,9 @@ static int do_meta_command(char *zLine, ShellState *p){
goto meta_command_exit; goto meta_command_exit;
} }
}else if( zLike ){ }else if( zLike ){
raw_printf(stderr, "Usage: .dump ?--preserve-rowids? " zLike = sqlite3_mprintf("%z OR name LIKE %Q", zLike, azArg[i]);
"?--newlines? ?LIKE-PATTERN?\n");
rc = 1;
goto meta_command_exit;
}else{ }else{
zLike = azArg[i]; zLike = sqlite3_mprintf("name LIKE %Q", azArg[i]);
} }
} }
@ -7329,35 +7323,25 @@ static int do_meta_command(char *zLine, ShellState *p){
** corrupt. */ ** corrupt. */
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0); sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
p->nErr = 0; p->nErr = 0;
if( zLike==0 ){ if( zLike==0 ) zLike = sqlite3_mprintf("true");
run_schema_dump_query(p, zSql = sqlite3_mprintf(
"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'" "WHERE (%s) AND type=='table'"
); " AND sql NOT NULL"
run_schema_dump_query(p, " ORDER BY tbl_name='sqlite_sequence', rowid",
"SELECT name, type, sql FROM sqlite_master " zLike
"WHERE name=='sqlite_sequence'" );
); run_schema_dump_query(p,zSql);
run_table_dump_query(p, sqlite3_free(zSql);
"SELECT sql FROM sqlite_master " zSql = sqlite3_mprintf(
"WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0 "SELECT sql FROM sqlite_master "
); "WHERE (%s) AND sql NOT NULL"
}else{ " AND type IN ('index','trigger','view')",
char *zSql; zLike
zSql = sqlite3_mprintf( );
"SELECT name, type, sql FROM sqlite_master " run_table_dump_query(p, zSql);
"WHERE tbl_name LIKE %Q AND type=='table'" sqlite3_free(zSql);
" AND sql NOT NULL", zLike); sqlite3_free(zLike);
run_schema_dump_query(p,zSql);
sqlite3_free(zSql);
zSql = sqlite3_mprintf(
"SELECT sql FROM sqlite_master "
"WHERE sql NOT NULL"
" AND type IN ('index','trigger','view')"
" AND tbl_name LIKE %Q", zLike);
run_table_dump_query(p, zSql, 0);
sqlite3_free(zSql);
}
if( p->writableSchema ){ if( p->writableSchema ){
raw_printf(p->out, "PRAGMA writable_schema=OFF;\n"); raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
p->writableSchema = 0; p->writableSchema = 0;

View File

@ -297,10 +297,11 @@ do_test shell1-3.4.2 {
list [regexp {BEGIN TRANSACTION;} $res] \ list [regexp {BEGIN TRANSACTION;} $res] \
[regexp {COMMIT;} $res] [regexp {COMMIT;} $res]
} {1 1} } {1 1}
do_test shell1-3.4.3 { # The .dump command now accepts multiple arguments
# too many arguments #do_test shell1-3.4.3 {
catchcmd "test.db" ".dump FOO BAD" # # too many arguments
} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}} # catchcmd "test.db" ".dump FOO BAD"
#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}}
# .echo ON|OFF Turn command echo on or off # .echo ON|OFF Turn command echo on or off
do_test shell1-3.5.1 { do_test shell1-3.5.1 {