X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI.pm;h=1e3f4233a21252d9ec5a096d3d42f8e4571b46af;hb=a82f1dd456e802874a36f012a10c5a7cfc8d2024;hp=7e99a81328a65296d904ddf7df845dcfda038d1b;hpb=0f8448322561029d7265adc51484136b2433ad28;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index 7e99a81..1e3f423 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -9,7 +9,7 @@ use List::MoreUtils 'any'; use namespace::clean; use DBIx::Class::Schema::Loader::Table (); -our $VERSION = '0.07014'; +our $VERSION = '0.07017'; __PACKAGE__->mk_group_accessors('simple', qw/ _disable_pk_detection @@ -323,32 +323,52 @@ sub _table_uniq_info { sub _table_comment { my ($self, $table) = @_; + my $dbh = $self->dbh; my $comments_table = $table->clone; $comments_table->name($self->table_comments_table); - my ($comment) = try { $self->dbh->selectrow_array(<<"EOF") }; + my ($comment) = + (exists $self->_tables->{$comments_table->sql_name} || undef) + && try { $dbh->selectrow_array(<<"EOF") }; SELECT comment_text FROM @{[ $comments_table->sql_name ]} -WHERE table_name = @{[ $self->dbh->quote($table->name) ]} +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}; + } + return $comment; } sub _column_comment { my ($self, $table, $column_number, $column_name) = @_; + my $dbh = $self->dbh; my $comments_table = $table->clone; $comments_table->name($self->column_comments_table); - my ($comment) = try { $self->dbh->selectrow_array(<<"EOF") }; + my ($comment) = + (exists $self->_tables->{$comments_table->sql_name} || undef) + && try { $dbh->selectrow_array(<<"EOF") }; SELECT comment_text FROM @{[ $comments_table->sql_name ]} -WHERE table_name = @{[ $self->dbh->quote($table->name) ]} -AND column_name = @{[ $self->dbh->quote($column_name) ]} +WHERE table_name = @{[ $dbh->quote($table->name) ]} +AND column_name = @{[ $dbh->quote($column_name) ]} EOF - + + # Failback: try the REMARKS column on column_info + if (!$comment && $dbh->can('column_info')) { + my $sth = $self->_dbh_column_info( $dbh, undef, $table->schema, $table->name, $column_name ); + my $info = $sth->fetchrow_hashref(); + $comment = $info->{REMARKS}; + } + return $comment; } @@ -516,6 +536,13 @@ sub _dbh_type_info_type_name { # do not use this, override _columns_info_for instead sub _extra_column_info {} +# override to mask warnings if needed +sub _dbh_table_info { + my ($self, $dbh) = (shift, shift); + + return $dbh->table_info(@_); +} + # override to mask warnings if needed (see mysql) sub _dbh_column_info { my ($self, $dbh) = (shift, shift);