I've been using an alpha version of column_info that Tim Bunce
sent the Class::DBI list ages ago in connection with some code
to extend Class::DBI.  AFAICS, it's precisely what's in the
latest version of DBD::mysql.  I got it to work without any
finding bugs except it couldn't handle tablenames that included
the database name, like 'foo.bar', which I naturally fixed.

But when I updated my development box recently to DBI v1.37
and DBD::mysql v2.90002 (I think), it broke badly. 

Here is a short program that illustrates the problem:

<code>
#/usr/bin/perl

use strict;
use DBI;

my $dbh = DBI->connect('dbi:mysql:connect2', username', 'password');
my $sth = $dbh->column_info(undef, undef, 'physemp.account', '%');
</code>

results in an error message:

DBD::mysql::db column_info failed: column_info doesn't support
table wildcard at /usr/local/lib/site_perl/My/Class/DBI.pm line
190.

Going into the DBD::mysql source, I see where the error happens,
so I patched (see attached) the source to allow table names like
'physemp.account'.  Now I get error messages that say:

DBD::mysql::db column_info failed: Incorrect table name
'physemp.account' at test.pl line 7.

When I go look for where that error gets generated, I have no
clue where it is, "# grep -r "Incorrect table name" /usr/*"
gives no results at all.

Even more mystifying is that I put a print statement just
before column_info returns, and it prints out just fine.
WTH's going on here? 

Since I write code like

<code>
use DBI;

my $dbh = DBI->connect('dbi:mysql:connect2', username', 'password');
my $results = $dbh->selectall_arrayref('select * from physemp.account',
                                       {Columns => {}});
</code>

all day long, I'd expect my little program to work perfectly.

I can fix this problem given some clue, or I can deal with
fixing my production code to work around this.  I'd rather do
the former, since one upon a time this technique did work.

Thanks.
--- mysql.pm
+++ mysql.pm
@@ -282,7 +282,7 @@
 sub column_info {
     my ($dbh, $catalog, $schema, $table, $column) = @_;
     return $dbh->set_err(1, "column_info doesn't support table wildcard")
-       if $table !~ /^\w+$/;
+       if $table !~ /^(\w+\.)?\w+$/;
     return $dbh->set_err(1, "column_info doesn't support column selection")
        if $column ne "%";
 

Reply via email to