From: Brandon L. Black Date: Wed, 15 Mar 2006 13:51:11 +0000 (+0000) Subject: replace the ugly _column_info_broken method-flag with an eval on the dbh call/execute... X-Git-Tag: v0.06000~60^2~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bfe10d87f8b99fc852813e8311e9d9ec6aff1809;hp=3ec067db5de15b93b734ecb437c07a586e421bb5;p=dbsrgits%2FDBIx-Class.git replace the ugly _column_info_broken method-flag with an eval on the dbh call/execute instead --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 0da5731..afc8a66 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -521,43 +521,47 @@ Returns database type info for a given table columns. =cut -# override this in a subclass if your DBD ->can('column_info'), -# but the call itself is horribly broken. -sub _column_info_broken { 0 } - sub columns_info_for { my ($self, $table) = @_; - my %result; - if ( $self->dbh->can( 'column_info' ) && !$self->_column_info_broken){ - my $sth = $self->dbh->column_info( undef, undef, $table, '%' ); - $sth->execute(); - while ( my $info = $sth->fetchrow_hashref() ){ - my %column_info; - $column_info{data_type} = $info->{TYPE_NAME}; - $column_info{size} = $info->{COLUMN_SIZE}; - $column_info{is_nullable} = $info->{NULLABLE} ? 1 : 0; - $column_info{default_value} = $info->{COLUMN_DEF}; - $result{$info->{COLUMN_NAME}} = \%column_info; - } - } else { - my $sth = $self->dbh->prepare("SELECT * FROM $table WHERE 1=0"); - $sth->execute; - my @columns = @{$sth->{NAME_lc}}; - for my $i ( 0 .. $#columns ){ - my %column_info; - my $type_num = $sth->{TYPE}->[$i]; - my $type_name; - if(defined $type_num && $self->dbh->can('type_info')) { - my $type_info = $self->dbh->type_info($type_num); - $type_name = $type_info->{TYPE_NAME} if $type_info; + if ($self->dbh->can('column_info')) { + my %result; + my $old_raise_err = $self->dbh->{RaiseError}; + $self->dbh->{RaiseError} = 1; + eval { + my $sth = $self->dbh->column_info( undef, undef, $table, '%' ); + $sth->execute(); + while ( my $info = $sth->fetchrow_hashref() ){ + my %column_info; + $column_info{data_type} = $info->{TYPE_NAME}; + $column_info{size} = $info->{COLUMN_SIZE}; + $column_info{is_nullable} = $info->{NULLABLE} ? 1 : 0; + $column_info{default_value} = $info->{COLUMN_DEF}; + $result{$info->{COLUMN_NAME}} = \%column_info; } - $column_info{data_type} = $type_name ? $type_name : $type_num; - $column_info{size} = $sth->{PRECISION}->[$i]; - $column_info{is_nullable} = $sth->{NULLABLE}->[$i] ? 1 : 0; - $result{$columns[$i]} = \%column_info; + }; + $self->dbh->{RaiseError} = $old_raise_err; + return \%result if !$@; + } + + my %result; + my $sth = $self->dbh->prepare("SELECT * FROM $table WHERE 1=0"); + $sth->execute; + my @columns = @{$sth->{NAME_lc}}; + for my $i ( 0 .. $#columns ){ + my %column_info; + my $type_num = $sth->{TYPE}->[$i]; + my $type_name; + if(defined $type_num && $self->dbh->can('type_info')) { + my $type_info = $self->dbh->type_info($type_num); + $type_name = $type_info->{TYPE_NAME} if $type_info; } + $column_info{data_type} = $type_name ? $type_name : $type_num; + $column_info{size} = $sth->{PRECISION}->[$i]; + $column_info{is_nullable} = $sth->{NULLABLE}->[$i] ? 1 : 0; + $result{$columns[$i]} = \%column_info; } + return \%result; } diff --git a/lib/DBIx/Class/Storage/DBI/DB2.pm b/lib/DBIx/Class/Storage/DBI/DB2.pm index 60a515b..a6e1452 100644 --- a/lib/DBIx/Class/Storage/DBI/DB2.pm +++ b/lib/DBIx/Class/Storage/DBI/DB2.pm @@ -7,8 +7,6 @@ use base qw/DBIx::Class::Storage::DBI/; # __PACKAGE__->load_components(qw/PK::Auto/); -sub _column_info_broken { 1 } - sub last_insert_id { my ($self) = @_;