From b511c409ad81b82715e54fed91255223aec8cd64 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sat, 24 Sep 2011 02:51:10 +0200 Subject: [PATCH] sql: fixed bug #34034: sql: --list-databases --- src/sql | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/sql b/src/sql index 131376d8..91bb84b2 100755 --- a/src/sql +++ b/src/sql @@ -82,13 +82,24 @@ HTML output. Turn on HTML tabular output. Show the list of running queries. +=item B<--show-databases> + +=item B<--showdbs> + +=item B<--list-databases> + +=item B<--listdbs> + +List the databases (table spaces) in the database. + + =item B<--show-tables> =item B<--list-tables> =item B<--table-list> -List the tables in the database +List the tables in the database. =item B<--noheaders> @@ -493,6 +504,10 @@ if(defined $::opt_tablelist) { unshift @ARGV, tablelist($database_driver,%dburl); } +if(defined $::opt_dblist) { + unshift @ARGV, dblist($database_driver,%dburl); +} + if(defined $::opt_dbsize) { unshift @ARGV, dbsize($database_driver,%dburl); } @@ -556,6 +571,11 @@ sub parse_options { "show-processlist|proclist|listproc" => \$::opt_processlist, "show-tables|showtables|listtables|list-tables|tablelist|table-list" => \$::opt_tablelist, + "dblist|". + "listdb|listdbs|list-db|list-dbs|list-database|". + "list-databases|listdatabases|listdatabase|showdb|". + "showdbs|show-db|show-dbs|show-database|show-databases|". + "showdatabases|showdatabase" => \$::opt_dblist, "db-size|dbsize" => \$::opt_dbsize, "table-size|tablesize" => \$::opt_tablesize, "noheaders|no-headers|n" => \$::opt_n, @@ -767,6 +787,25 @@ sub tablelist { } } +# Return the code for 'show databases' in the chosen database dialect +sub dblist { + my $dbdriver = shift; + my %dburl = @_; + my %statement = + ("mysql" => "show databases;", + "postgresql" => ("SELECT datname FROM pg_database ". + "WHERE datname NOT IN ('template0','template1','postgres') ". + "ORDER BY datname ASC;"), + "oracle" => ("select * from user_tablespaces;"), + ); + if($statement{$dbdriver}) { + return $statement{$dbdriver}; + } else { + print STDERR "dblist is not implemented for $dbdriver\n"; + exit 1; + } +} + # Return the code for 'show database size' in the chosen database dialect sub dbsize { my $dbdriver = shift;