Subject: | Allow /desc on tables in different schemas |
The attached patch allows /desc to work on tables in different schemas
by using the syntax
/desc schema.table
No way to escape the "." is provided, so this may break things if
somebody has a table with a dot in the name (but that would make sql
queries awkward, too).
As a side effect, this patch also fixes bug #15631.
Subject: | DBI-Shell-describe-schema.patch |
--- Shell.pm.orig 2003-10-03 04:21:00.000000000 +0200
+++ Shell.pm 2007-04-12 18:35:03.000000000 +0200
@@ -1376,6 +1376,11 @@
# desc_show_long: 1
# desc_show_remarks: 1
+ my $schema;
+ if ($tab =~ /^([^.]+)\.([^.]+)$/) {
+ $schema = $1;
+ $tab = $2;
+ }
my @names = ();
# Determine if the short or long display type is used
@@ -1406,13 +1411,13 @@
and $sh->{desc_show_remarks} == 1
and (not grep { m/REMARK/i } @names));
- my $sth = $dbh->column_info(undef, undef, $tab);
+ my $sth = $dbh->column_info(undef, $schema, $tab, '%');
if (ref $sth) {
# Only attempt the primary_key lookup if using the column_info call.
- my @key_column_names = $dbh->primary_key( undef, undef, $tab );
+ my @key_column_names = $dbh->primary_key( undef, $schema, $tab );
my %pk_cols;
# Convert the column names to lower case for matching
foreach my $idx (0 ..$#key_column_names) {
@@ -1504,6 +1509,7 @@
# This is the old method, if the driver doesn't support the DBI column_info
# meta data.
#
+ $tab = "$schema.$tab" if defined $schema;
my $sql = qq{select * from $tab where 1 = 0};
$sth = $dbh->prepare( $sql );
$sth->execute;