aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan <Dan Kennedy>2021-05-25 11:39:14 +0000
committerdan <Dan Kennedy>2021-05-25 11:39:14 +0000
commit78a9d7551c7f709eef0804bd00caee1c06ff11d0 (patch)
tree791a29f0486f0ee6e1d4bf77c35979d08f260965 /src
parentc00727ab583ea47f6962aa33dfc84f2d3723dc04 (diff)
downloadsqlite-78a9d7551c7f709eef0804bd00caee1c06ff11d0.tar.gz
sqlite-78a9d7551c7f709eef0804bd00caee1c06ff11d0.zip
Enhance the shell tool ".dump PATTERN" command so that it dumps the contents of shadow tables when a virtual table is identified by the PATTERN.
FossilOrigin-Name: b0bc5ab9ceec496ac260ccfd53b51a2b53a81576fbe04c97b99f6705b063c59f
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index 462cd717b..517e12cb5 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -7739,11 +7739,26 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_free(zLike);
goto meta_command_exit;
}
- }else if( zLike ){
- zLike = sqlite3_mprintf("%z OR name LIKE %Q ESCAPE '\\'",
- zLike, azArg[i]);
}else{
- zLike = sqlite3_mprintf("name LIKE %Q ESCAPE '\\'", azArg[i]);
+ /* azArg[i] contains a LIKE pattern. This ".dump" request should
+ ** only dump data for tables for which either the table name matches
+ ** the LIKE pattern, or the table appears to be a shadow table of
+ ** a virtual table for which the name matches the LIKE pattern.
+ */
+ char *zExpr = sqlite3_mprintf(
+ "name LIKE %Q ESCAPE '\\' OR EXISTS ("
+ " SELECT 1 FROM sqlite_schema WHERE "
+ " name LIKE %Q ESCAPE '\\' AND"
+ " sql LIKE 'CREATE VIRTUAL TABLE%%' AND"
+ " substr(o.name, 1, length(name)+1) == (name||'_')"
+ ")", azArg[i], azArg[i]
+ );
+
+ if( zLike ){
+ zLike = sqlite3_mprintf("%z OR %z", zLike, zExpr);
+ }else{
+ zLike = zExpr;
+ }
}
}
@@ -7765,7 +7780,7 @@ static int do_meta_command(char *zLine, ShellState *p){
p->nErr = 0;
if( zLike==0 ) zLike = sqlite3_mprintf("true");
zSql = sqlite3_mprintf(
- "SELECT name, type, sql FROM sqlite_schema "
+ "SELECT name, type, sql FROM sqlite_schema AS o "
"WHERE (%s) AND type=='table'"
" AND sql NOT NULL"
" ORDER BY tbl_name='sqlite_sequence', rowid",
@@ -7775,7 +7790,7 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_free(zSql);
if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
zSql = sqlite3_mprintf(
- "SELECT sql FROM sqlite_schema "
+ "SELECT sql FROM sqlite_schema AS o "
"WHERE (%s) AND sql NOT NULL"
" AND type IN ('index','trigger','view')",
zLike