From: Aaron Crane Date: Sun, 29 Sep 2013 13:11:06 +0000 (+0100) Subject: Push table-equality checks into _dbh_table_info X-Git-Tag: 0.07036_04~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=68c6c83f83086611e0c992dbcd09e3a77e0fd7ff;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Push table-equality checks into _dbh_table_info Some DBDs don't support table_info. Even in those that do, we may need to iterate over the table_info data to find the entry that exactly matches the table we want. --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index d054351..71fd3d6 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -372,10 +372,9 @@ WHERE table_name = @{[ $dbh->quote($table->name) ]} EOF # Failback: try the REMARKS column on table_info - if (!$comment && $dbh->can('table_info')) { - my $sth = $self->_dbh_table_info( $dbh, undef, $table->schema, $table->name ); - my $info = $sth->fetchrow_hashref(); - $comment = $info->{REMARKS}; + if (!$comment) { + my $info = $self->_dbh_table_info( $dbh, $table ); + $comment = $info->{REMARKS} if $info; } return $comment; @@ -632,9 +631,23 @@ sub _extra_column_info {} # override to mask warnings if needed sub _dbh_table_info { - my ($self, $dbh) = (shift, shift); + my ($self, $dbh, $table) = (shift, shift, shift); + + return undef if !$dbh->can('table_info'); + my $sth = $dbh->table_info(undef, $table->schema, $table->name); + while (my $info = $sth->fetchrow_hashref) { + next if !$self->_table_info_matches($table, $info); + return $info; + } + return undef; +} + +sub _table_info_matches { + my ($self, $table, $info) = @_; - return $dbh->table_info(@_); + no warnings 'uninitialized'; + return $info->{TABLE_SCHEM} eq $table->schema + && $info->{TABLE_NAME} eq $table->name; } # override to mask warnings if needed (see mysql) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index 23adaf5..7bb4eaf 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -251,6 +251,15 @@ sub _tables_list { return $self->_filter_tables(\@tables, $opts); } +sub _table_info_matches { + my ($self, $table, $info) = @_; + + my $table_schema = $table->schema; + $table_schema = 'main' if !defined $table_schema; + return $info->{TABLE_SCHEM} eq $table_schema + && $info->{TABLE_NAME} eq $table->name; +} + =head1 SEE ALSO L, L,