Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 25569
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: pierrick_trash [...] le-gall.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 4.003
Fixed in: 4.001



Subject: table_info returns no table
$ perl -e 'use DBI; DBI->installed_versions()' Perl : 5.008007 (i486-linux-gnu-thread-multi) OS : linux (2.6.10) DBI : 1.52 DBD::mysql : 4.003 Show quoted text
mysql> select version();
+-------------------------------+ | version() | +-------------------------------+ | 5.0.22-Debian_0ubuntu6.06-log | +-------------------------------+ Using DBD::mysql 4.003, table_info returns no table in the following script. 3.0008 or 4.001 works perfectly. #!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect( sprintf( 'DBI:mysql:database=%s;host=%s;port=%s', 'talend', 'localhost', '3306', ), 'root', 'conway', { } ) or die "can't connect to database"; my $sth; my $query; # We need the table list to know if drop or "create if not exists" is # relevant my $schema = '%'; my $catalog = undef; my $tabsth = $dbh->table_info($catalog, $schema); my @tables = (); while (my $entity = $tabsth->fetchrow_hashref()) { if ($entity->{TABLE_TYPE} eq 'TABLE') { push @tables, lc $entity->{TABLE_NAME}; } } print "===\n"; print "existing tables:\n"; print join("\n", map {" - ".$_} @tables), "\n"; print "===\n";
Hi! This actually works per the DBI spec-- the perldoc for DBI: "If the value of $schema is ’%’ and $catalog and $table are empty strings, the result set contains a list of schema names." So, if you want a list of all schemas and their tables, simply leave the schema name blank.