From a50da106f04f3dd6eb07655927f20f9afacb6c7f Mon Sep 17 00:00:00 2001
From: drh
Date: Tue, 8 Aug 2000 20:19:09 +0000
Subject: [PATCH] Add pattern matching to the .table command (CVS 129)
FossilOrigin-Name: 2b3511eca7e562ef2428cec2f7eeca1d26b6c1c8
---
manifest | 18 +++++++++---------
manifest.uuid | 2 +-
src/shell.c | 18 ++++++++++++++----
src/shell.tcl | 13 +++++++++++--
www/changes.tcl | 5 +++++
www/sqlite.tcl | 21 +++++++++++++++++++--
6 files changed, 59 insertions(+), 18 deletions(-)
diff --git a/manifest b/manifest
index 7b5d82a97c..c77194501e 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C :-)\s(CVS\s128)
-D 2000-08-04T14:56:25
+C Add\spattern\smatching\sto\sthe\s.table\scommand\s(CVS\s129)
+D 2000-08-08T20:19:09
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
F Makefile.in 670aa9413cb2cdcded23b328a9e255c845c41a1e
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
@@ -15,8 +15,8 @@ F src/insert.c f146f149ad2422a1dc3bfa7a1651a25940f98958
F src/main.c ba16b81890d962821bb90f0a4de9a29b0e495eb2
F src/parse.y 5d199034de5d29ebedb42c1c51f34db4df40cbe5
F src/select.c d382e96c2221d08367cc87976f2b574537c9de97
-F src/shell.c 2fd370838742afa068cfcdd05b667ff89bab25b6
-F src/shell.tcl ca52bb831e03e10480516e5e708c0c452914a219
+F src/shell.c cd560887be6fb9cfa477fce7ba60716139189271
+F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
F src/sqlite.h 82ae53028e27919250f886ff9d7c4927de81978a
F src/sqliteInt.h f6d1e139b3bfa4ceff2136684e19d76b53178ec0
F src/tclsqlite.c b1ae6abd50d8b0e2470cc49b5e1d03329a68dd75
@@ -60,16 +60,16 @@ F www/arch.fig 4e26e9dca3c49724fc8f554c695ddea9f2413156
F www/arch.png c4d908b79065a72e7dcf19317f36d1324c550e87
F www/arch.tcl 4f6a9afecc099a27bba17b4f8cc9561abc15dc40
F www/c_interface.tcl 29593cf77025bab137b7ba64b9459eb5eb6b4873
-F www/changes.tcl a8608ae834d6e6922f386a9341e84e74a521e847
+F www/changes.tcl 0dc473e0b4240c5711653dbe589fac77508a5c3f
F www/crosscompile.tcl 19734ce7f18b16ff2ed8479412abf8aca56e1dcc
F www/fileformat.tcl cfb7fba80b7275555281ba2f256c00734bcdd1c9
F www/index.tcl 421bcabc6839eb00698b75b169caa8a559454515
F www/lang.tcl 9192e114b19987e630a41e879585b87006eb84a1
F www/mingw.tcl fc5f4ba9d336b6e8c97347cc6496d6162461ef60
F www/opcode.tcl cb3a1abf8b7b9be9f3a228d097d6bf8b742c2b6f
-F www/sqlite.tcl 7c2ee68063fa59463f55d5bac1ffe3e50d8a817f
+F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
F www/vdbe.tcl bcbfc33bcdd0ebad95eab31286adb9e1bc289520
-P 695fd68eb6291bdcc04af0eec7c7cdd7ff10872b
-R ba994bd9837a407cb6abaac249529cc4
+P d53cccda4fa5d2f8287421e71488817eb4ca13eb
+R c2912166785333a778527e99f3e6b1d7
U drh
-Z 509708daad6c84350903dba5837a203b
+Z 6e010a7ae0b6272f5ce57bde940ce4a2
diff --git a/manifest.uuid b/manifest.uuid
index ab2ddab983..0728dee17d 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-d53cccda4fa5d2f8287421e71488817eb4ca13eb
\ No newline at end of file
+2b3511eca7e562ef2428cec2f7eeca1d26b6c1c8
\ No newline at end of file
diff --git a/src/shell.c b/src/shell.c
index 27e5d05b82..629d100838 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -24,7 +24,7 @@
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
-** $Id: shell.c,v 1.19 2000/08/02 13:47:42 drh Exp $
+** $Id: shell.c,v 1.20 2000/08/08 20:19:09 drh Exp $
*/
#include
#include
@@ -395,7 +395,7 @@ static char zHelp[] =
".output stdout Send output to the screen\n"
".schema ?TABLE? Show the CREATE statements\n"
".separator STRING Change separator string for \"list\" mode\n"
- ".tables List names all tables in the database\n"
+ ".tables ?PATTERN? List names of tables matching a pattern\n"
".timeout MS Try opening locked tables for MS milliseconds\n"
".width NUM NUM ... Set column widths for \"column\" mode\n"
;
@@ -574,11 +574,21 @@ static void do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
struct callback_data data;
char *zErrMsg = 0;
- static char zSql[] =
- "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
+ char zSql[1000];
memcpy(&data, p, sizeof(data));
data.showHeader = 0;
data.mode = MODE_List;
+ if( nArg==1 ){
+ sprintf(zSql,
+ "SELECT name FROM sqlite_master "
+ "WHERE type='table' "
+ "ORDER BY name");
+ }else{
+ sprintf(zSql,
+ "SELECT name FROM sqlite_master "
+ "WHERE type='table' AND name LIKE '%%%.100s%%' "
+ "ORDER BY name", azArg[1]);
+ }
sqlite_exec(db, zSql, callback, &data, &zErrMsg);
if( zErrMsg ){
fprintf(stderr,"Error: %s\n", zErrMsg);
diff --git a/src/shell.tcl b/src/shell.tcl
index d28cba6343..25aa9b0736 100644
--- a/src/shell.tcl
+++ b/src/shell.tcl
@@ -3,6 +3,8 @@
# A GUI shell for SQLite
#
+# The following code is slighly modified from the original. See comments
+# for the modifications...
############################################################################
# A console widget for Tcl/Tk. Invoke console:create with a window name,
# a prompt string, and a title to get a new top-level window that allows
@@ -277,8 +279,15 @@ proc console:Enter w {
} else {
set cmd $v(prior)\n$line
}
- if {[info complete $cmd]} {
- set rc [catch {uplevel #0 $cmd} res]
+##### Original
+# if {[info complete $cmd]} { }
+# set rc [catch {uplevel #0 $cmd} res]
+##### New
+ global DB
+ if {[$DB complete $cmd]} {
+ set CODE {}
+ set rc [catch {$DB eval $cmd RESULT $CODE}]
+##### End Of Changes
if {![winfo exists $w]} return
if {$rc} {
$w insert end $res\n err
diff --git a/www/changes.tcl b/www/changes.tcl
index d6060bdb7b..6fdbf29f59 100644
--- a/www/changes.tcl
+++ b/www/changes.tcl
@@ -17,6 +17,11 @@ proc chng {date desc} {
puts "
"
}
+chng {2000 Aug 8} {
+Added pattern matching to the ".table" command in the "sqlite"
+command shell.
+}
+
chng {2000 Aug 4} {
Documentation updates
Added "busy" and "timeout" methods to the Tcl interface
diff --git a/www/sqlite.tcl b/www/sqlite.tcl
index ed3bb31a71..48b00b113c 100644
--- a/www/sqlite.tcl
+++ b/www/sqlite.tcl
@@ -1,7 +1,7 @@
#
# Run this Tcl script to generate the sqlite.html file.
#
-set rcsid {$Id: sqlite.tcl,v 1.12 2000/08/04 13:49:03 drh Exp $}
+set rcsid {$Id: sqlite.tcl,v 1.13 2000/08/08 20:19:09 drh Exp $}
puts {
@@ -399,7 +399,24 @@ ORDER BY type DESC, name
The %s in the query above is replaced by the argument
-to ".schema", of course.
+to ".schema", of course. Notice that the argument to the ".schema"
+command appears to the right of an SQL LIKE operator. So you can
+use wildcards in the name of the table. For example, to get the
+schema for all tables whose names contain the character string
+"abc" you could enter:}
+
+Code {
+sqlite> (((.schema %abc%)))
+}
+
+puts {
+
+Along these same lines,
+the ".table" command also accepts a pattern as its first argument.
+If you give an argument to the .table command, a "%" is both
+appended and prepended and a LIKE clause is added to the query.
+This allows you to list only those tables that match a particular
+pattern.
Converting An Entire Database To An ASCII Text File