From: dan Date: Tue, 25 May 2021 11:39:14 +0000 (+0000) Subject: Enhance the shell tool ".dump PATTERN" command so that it dumps the contents of shado... X-Git-Tag: version-3.36.0~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=78a9d7551c7f709eef0804bd00caee1c06ff11d0;p=thirdparty%2Fsqlite.git 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 --- diff --git a/manifest b/manifest index e79b0171d7..8908399948 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sthe\sin-memory\sjournal\scode\sthat\scould\soccasionally\slead\sto\sa\ssegfault\swhen\sa\ssub-transaction\sthat\smodified\szero\spages\swas\scommitted. -D 2021-05-24T14:35:19.500 +C Enhance\sthe\sshell\stool\s".dump\sPATTERN"\scommand\sso\sthat\sit\sdumps\sthe\scontents\sof\sshadow\stables\swhen\sa\svirtual\stable\sis\sidentified\sby\sthe\sPATTERN. +D 2021-05-25T11:39:14.912 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -544,7 +544,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 40e216d9a72e52841a9c8e0aec7d367bade8e2df17b804653b539b20c1ab5660 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 531612539a0058b6e953a5b5497d9a2066f483089764002d9f2745dd7600d6f7 -F src/shell.c.in 1b32ba2918ede13b68df47c7b92b72ba0d06e68d384e78bb9d7456527271d400 +F src/shell.c.in 2a2b06d463933ee3a5bb0242d5d2200ca36769493fd6f4d939a0574113f3d6d8 F src/sqlite.h.in 5c950066775ca9efdaa49077c05d38d0bef6418f3bd07d2dce0210f1d2f3c326 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 61b38c073d5e1e96a3d45271b257aef27d0d13da2bea5347692ae579475cd95e @@ -1915,7 +1915,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7aca8d52c16c2192d9c1ff03a976c482a60365cef8d2474b540ff4c84e8737b4 -R 063cf7670c70a45b325de4faeffc140b +P 17960165f5840cab45b7a8bb02779ebfb321c68f33ec6da9ab14063ccd134fa4 +R 566b3231aafb0b1c4d92f8d47e61c4a9 U dan -Z 2105d14c8908ec3b52c696f7307f25a5 +Z b40b0f8d44019306141de12b3f25d01c diff --git a/manifest.uuid b/manifest.uuid index 103e3f204f..a459b9cd7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -17960165f5840cab45b7a8bb02779ebfb321c68f33ec6da9ab14063ccd134fa4 \ No newline at end of file +b0bc5ab9ceec496ac260ccfd53b51a2b53a81576fbe04c97b99f6705b063c59f \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 462cd717ba..517e12cb5a 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