table_info is supposed to be the most portable eventually, it is currently experimental, and very few drivers implement it.
You guys should really investigate "Statement Handle Attributes" in the DBI pod. Even those depend on the underlying driver, but since they've been a part of DBI longer, they are more portable.
I recently started using DBD-SQLite,
and after converting my mysql-specific sql into equivalent ANSI92 DBD-SQLite compliant using code from Re: MySQL 2 SQLite, I came up with the following to dump some metadata about my database ;)
use DBI;
use Data::Dumper;
my $dbh = DBI->connect("dbi:SQLite:pod.wiki.sqlite.db") or die $DBD::e
+rr;
warn "database name is ", $dbh->{Name};
my $sth = $dbh->prepare("SELECT * FROM content limit 0");
warn $sth->execute;
for my $attr( qw[ NUM_OF_PARAMS NUM_OF_FIELDS
NAME NAME_hash TYPE PRECISION SCALE NULLABLE]){
eval { warn $attr, ' ', Dumper($sth->{$attr}); };
warn $attr,' is unavailable (', 1||$@, ')' if $@;
}
__END__
database name is pod.wiki.sqlite.db at dbi.table.info.pl line 5.
3 at dbi.table.info.pl line 7.
NUM_OF_PARAMS $VAR1 = 0;
NUM_OF_FIELDS $VAR1 = 5;
NAME $VAR1 = [
'name',
'version',
'text',
'modified',
'comment'
];
NAME_hash $VAR1 = {
'text' => 2,
'modified' => 3,
'comment' => 4,
'version' => 1,
'name' => 0
};
TYPE is unavailable (1) at dbi.table.info.pl line 11.
PRECISION is unavailable (1) at dbi.table.info.pl line 11.
SCALE is unavailable (1) at dbi.table.info.pl line 11.
NULLABLE is unavailable (1) at dbi.table.info.pl line 11.
update: ++ That is all true, but if you're looking for a list of tables, soon you'll be looking to describe those tables, and ... you get the point, yes? yes ;)
MJD says you
can't just make shit up and expect the computer to know what you mean, retardo!
I run a Win32 PPM
repository for perl 5.6x+5.8x. I take requests.
** The Third rule of perl club is a statement of fact: pod is sexy.
|
| [reply] [d/l] |
Statement handle attributes contain information on the structure of a table, he is looking for a list of tables, which isn't available in that manner, and which your sample code doesn't provide.
| [reply] |