From 8e9297fb795584f53c31f04f6b702962a10cb5b7 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2020 12:50:13 +0000 Subject: [PATCH 1/3] 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 --- manifest | 14 +++++----- manifest.uuid | 2 +- src/shell.c.in | 68 ++++++++++++++++++------------------------------ test/shell1.test | 9 ++++--- 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/manifest b/manifest index ef3e2aac8c..da8607f852 100644 --- a/manifest +++ b/manifest @@ -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]. -D 2020-03-21T23:10:38.823 +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-25T12:50:13.948 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -532,7 +532,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 903a70c48d0f72fdd657b225d499cf99ec01d575cf3fbc8196b43562045319ac F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 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/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 9c5269260409eb3275324ccace6a13a96f4ad330c708415f70ca6097901ff4ee @@ -1333,7 +1333,7 @@ F test/sharedA.test 49d87ec54ab640fbbc3786ee3c01de94aaa482a3a9f834ad3fe92770eb69 F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test 43e12c7d4ff65f041803ad24a93fd3818deb2cb83e721810f27d0fde61d64a13 +F test/shell1.test 1796b7f76d09ffd2b2dc0ff5ad89428e9892f237d4f4e33ef2278f064a2d94a4 F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b F test/shell3.test ac8c2b744014c3e9a0e26bfd829ab65f00923dc1a91ffd044863e9423cc91494 F test/shell4.test 1c6aef11daaa2d6830acaba3ac9cbec93fbc1c3d5530743a637f39b3987d08ce @@ -1860,7 +1860,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 8a5c539b77aa174c048a504d211c56902075f9b42b654e1f8cc5767739e5fcc9 -R 480ea7ba1b66f997fe626bc516b1544b +P 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525 +R 3d4d5bc7aeb5d456d8c0a7166a26bb4e U drh -Z 1f463b1edcb75b2ef80d4761df1603b9 +Z ff19b393b7175126a56d85ef88b57634 diff --git a/manifest.uuid b/manifest.uuid index 9559b864a1..1ad3e7cfac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525 \ No newline at end of file +45fba3d7055f90f67005ca740687f060a2311db40c8f6a161bfea0424e6ebf6d \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 728a4d051d..365823eb56 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2358,8 +2358,7 @@ static void set_table_name(ShellState *p, const char *zName){ */ static int run_table_dump_query( ShellState *p, /* Query context */ - const char *zSelect, /* SELECT statement to extract content */ - const char *zFirstRow /* Print before first row, if not NULL */ + const char *zSelect /* SELECT statement to extract content */ ){ sqlite3_stmt *pSelect; int rc; @@ -2376,10 +2375,6 @@ static int run_table_dump_query( rc = sqlite3_step(pSelect); nResult = sqlite3_column_count(pSelect); while( rc==SQLITE_ROW ){ - if( zFirstRow ){ - utf8_printf(p->out, "%s", zFirstRow); - zFirstRow = 0; - } z = (const char*)sqlite3_column_text(pSelect, 0); utf8_printf(p->out, "%s", z); for(i=1; ishowHeader; int savedShellFlags = p->shellFlgs; @@ -7306,12 +7303,9 @@ static int do_meta_command(char *zLine, ShellState *p){ goto meta_command_exit; } }else if( zLike ){ - raw_printf(stderr, "Usage: .dump ?--preserve-rowids? " - "?--newlines? ?LIKE-PATTERN?\n"); - rc = 1; - goto meta_command_exit; + zLike = sqlite3_mprintf("%z OR name LIKE %Q", zLike, azArg[i]); }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. */ sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0); p->nErr = 0; - if( zLike==0 ){ - run_schema_dump_query(p, - "SELECT name, type, sql FROM sqlite_master " - "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'" - ); - run_schema_dump_query(p, - "SELECT name, type, sql FROM sqlite_master " - "WHERE name=='sqlite_sequence'" - ); - run_table_dump_query(p, - "SELECT sql FROM sqlite_master " - "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0 - ); - }else{ - char *zSql; - zSql = sqlite3_mprintf( - "SELECT name, type, sql FROM sqlite_master " - "WHERE tbl_name LIKE %Q AND type=='table'" - " AND sql NOT NULL", 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( zLike==0 ) zLike = sqlite3_mprintf("true"); + zSql = sqlite3_mprintf( + "SELECT name, type, sql FROM sqlite_master " + "WHERE (%s) AND type=='table'" + " AND sql NOT NULL" + " ORDER BY tbl_name='sqlite_sequence', rowid", + zLike + ); + run_schema_dump_query(p,zSql); + sqlite3_free(zSql); + zSql = sqlite3_mprintf( + "SELECT sql FROM sqlite_master " + "WHERE (%s) AND sql NOT NULL" + " AND type IN ('index','trigger','view')", + zLike + ); + run_table_dump_query(p, zSql); + sqlite3_free(zSql); + sqlite3_free(zLike); if( p->writableSchema ){ raw_printf(p->out, "PRAGMA writable_schema=OFF;\n"); p->writableSchema = 0; diff --git a/test/shell1.test b/test/shell1.test index 9273adeeb8..bbe2ad765e 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -297,10 +297,11 @@ do_test shell1-3.4.2 { list [regexp {BEGIN TRANSACTION;} $res] \ [regexp {COMMIT;} $res] } {1 1} -do_test shell1-3.4.3 { - # too many arguments - catchcmd "test.db" ".dump FOO BAD" -} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}} +# The .dump command now accepts multiple arguments +#do_test shell1-3.4.3 { +# # too many arguments +# catchcmd "test.db" ".dump FOO BAD" +#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}} # .echo ON|OFF Turn command echo on or off do_test shell1-3.5.1 { From cdbb28154eeb8d790562e1e32fb2df71abef0e37 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2020 20:31:45 +0000 Subject: [PATCH 2/3] For the LIKE pattern in the .dump command of the CLI, accept backslash as an escape character. FossilOrigin-Name: 029ceea612f5c7a1420939d8a772eefcc6f9550d24d57b52ae1729ea9d85fae9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index da8607f852..5692ceeaac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -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-25T12:50:13.948 +C For\sthe\sLIKE\spattern\sin\sthe\s.dump\scommand\sof\sthe\sCLI,\saccept\sbackslash\sas\nan\sescape\scharacter. +D 2020-03-25T20:31:45.467 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -532,7 +532,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 903a70c48d0f72fdd657b225d499cf99ec01d575cf3fbc8196b43562045319ac F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 6908c059e4289149f88bfd641305b96ee34e500855fcd580ff8df1bd0885191a -F src/shell.c.in 10093b8f88cfdce124c99f382a26a922210315cc537ef0f8e2d811fc5aa7a3b2 +F src/shell.c.in 7bb9005bf876c4e1210257a63fa49b556f4eddf59f94b6eb310fcb5096bec0e9 F src/sqlite.h.in 802957feeb249ede54f8dfe99b72aa19e70a0b7737969c46e625dc2f9f2d42b0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 9c5269260409eb3275324ccace6a13a96f4ad330c708415f70ca6097901ff4ee @@ -1860,7 +1860,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 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525 -R 3d4d5bc7aeb5d456d8c0a7166a26bb4e +P 45fba3d7055f90f67005ca740687f060a2311db40c8f6a161bfea0424e6ebf6d +R 0cb6c5ae4650de0954aa86cff220a90e U drh -Z ff19b393b7175126a56d85ef88b57634 +Z 736254bd9dd4359a40d3e390ba1aa98f diff --git a/manifest.uuid b/manifest.uuid index 1ad3e7cfac..8ff4a5b692 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -45fba3d7055f90f67005ca740687f060a2311db40c8f6a161bfea0424e6ebf6d \ No newline at end of file +029ceea612f5c7a1420939d8a772eefcc6f9550d24d57b52ae1729ea9d85fae9 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 365823eb56..54b779dcb1 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7303,9 +7303,10 @@ static int do_meta_command(char *zLine, ShellState *p){ goto meta_command_exit; } }else if( zLike ){ - zLike = sqlite3_mprintf("%z OR name LIKE %Q", zLike, azArg[i]); + zLike = sqlite3_mprintf("%z OR name LIKE %Q ESCAPE '\\'", + zLike, azArg[i]); }else{ - zLike = sqlite3_mprintf("name LIKE %Q", azArg[i]); + zLike = sqlite3_mprintf("name LIKE %Q ESCAPE '\\'", azArg[i]); } } From 95b395901a3b34c9b26b42da80ead52d02f0e54a Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Mar 2020 00:29:50 +0000 Subject: [PATCH 3/3] Reinstate the optimization that converts "x IN (y)" into "x==y". FossilOrigin-Name: 27936e6884e77093533719c7955a17f051cfb359872e51a6d1481152e6256443 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 12 +++--------- src/parse.y | 3 ++- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 5692ceeaac..2e5f6a4e1e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sthe\sLIKE\spattern\sin\sthe\s.dump\scommand\sof\sthe\sCLI,\saccept\sbackslash\sas\nan\sescape\scharacter. -D 2020-03-25T20:31:45.467 +C Reinstate\sthe\soptimization\sthat\sconverts\s"x\sIN\s(y)"\sinto\s"x==y". +D 2020-03-26T00:29:50.482 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -483,7 +483,7 @@ F src/date.c 6c408fdd2e9ddf6e8431aba76315a2d061bea2cec8fbb75e25d7c1ba08274712 F src/dbpage.c 8a01e865bf8bc6d7b1844b4314443a6436c07c3efe1d488ed89e81719047833a F src/dbstat.c 793deaf88a0904f88285d93d6713c636d55ede0ffd9f08d10f4ea825531d367f F src/delete.c 11000121c4281c0bce4e41db29addfaea0038eaa127ece02557c9207bc3e541d -F src/expr.c ed718ee2206166c9c2fc4fe89eadb1f369318aeb8645e06033566b387970fb9a +F src/expr.c 226293a02bd8376db5981a52a2163a5022c52d69878cb64a5821529743f51162 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 4b575423b0a5d4898b1a7868ce985cf1a8ad91c741c9abbb108ff02536d20f41 F src/func.c f3dcdc0e95509864767c1f0991b19360f969e44177f4e058fd51da9a6154f47e @@ -520,7 +520,7 @@ F src/os_win.c 035a813cbd17f355bdcad7ab894af214a9c13a1db8aeac902365350b98cd45a7 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c a71ffd145f55e28cbdc1bdabb5e6bef063da428a6c0de3c3a36e9a0c41d4c8c0 F src/pager.h 3b33619a90180e0874c7eca31d6f6ceb464d9322c6fb4e9a7bbb318c8a17bdb3 -F src/parse.y 8575183809cf30f8c9d1fbea65ca34d1de78b659792bc7c42681e01fc596b520 +F src/parse.y c8eff38606f443d5ba245263fa7abc05e4116d95656e050c4b78e9bfbf931add F src/pcache.c 385ff064bca69789d199a98e2169445dc16e4291fa807babd61d4890c3b34177 F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c 6596e10baf3d8f84cc1585d226cf1ab26564a5f5caf85a15757a281ff977d51a @@ -1860,7 +1860,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 45fba3d7055f90f67005ca740687f060a2311db40c8f6a161bfea0424e6ebf6d -R 0cb6c5ae4650de0954aa86cff220a90e +P 029ceea612f5c7a1420939d8a772eefcc6f9550d24d57b52ae1729ea9d85fae9 +R 3705b23e9f0d2aa8bb1acee008cd53c5 U drh -Z 736254bd9dd4359a40d3e390ba1aa98f +Z f21f043fe82b450709b51f4ab8aebfa6 diff --git a/manifest.uuid b/manifest.uuid index 8ff4a5b692..6d29acdcbb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -029ceea612f5c7a1420939d8a772eefcc6f9550d24d57b52ae1729ea9d85fae9 \ No newline at end of file +27936e6884e77093533719c7955a17f051cfb359872e51a6d1481152e6256443 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 8587f5ec78..e588897370 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2941,6 +2941,8 @@ void sqlite3CodeRhsOfIN( affinity = sqlite3ExprAffinity(pLeft); if( affinity<=SQLITE_AFF_NONE ){ affinity = SQLITE_AFF_BLOB; + }else if( affinity==SQLITE_AFF_REAL ){ + affinity = SQLITE_AFF_NUMERIC; } if( pKeyInfo ){ assert( sqlite3KeyInfoIsWriteable(pKeyInfo) ); @@ -3250,21 +3252,13 @@ static void sqlite3ExprCodeIN( int r2, regToFree; int regCkNull = 0; int ii; - int bLhsReal; /* True if the LHS of the IN has REAL affinity */ assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); if( destIfNull!=destIfFalse ){ regCkNull = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull); } - bLhsReal = sqlite3ExprAffinity(pExpr->pLeft)==SQLITE_AFF_REAL; for(ii=0; iinExpr; ii++){ - if( bLhsReal ){ - r2 = regToFree = sqlite3GetTempReg(pParse); - sqlite3ExprCode(pParse, pList->a[ii].pExpr, r2); - sqlite3VdbeAddOp4(v, OP_Affinity, r2, 1, 0, "E", P4_STATIC); - }else{ - r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, ®ToFree); - } + r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, ®ToFree); if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){ sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull); } diff --git a/src/parse.y b/src/parse.y index c321daf195..09731eb99c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1194,10 +1194,11 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] { */ sqlite3ExprUnmapAndDelete(pParse, A); A = sqlite3Expr(pParse->db, TK_INTEGER, N ? "1" : "0"); - }else if( 0 && Y->nExpr==1 && sqlite3ExprIsConstant(Y->a[0].pExpr) ){ + }else if( Y->nExpr==1 && sqlite3ExprIsConstant(Y->a[0].pExpr) ){ Expr *pRHS = Y->a[0].pExpr; Y->a[0].pExpr = 0; sqlite3ExprListDelete(pParse->db, Y); + pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); A = sqlite3PExpr(pParse, TK_EQ, A, pRHS); if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0); }else{