replace the ugly _column_info_broken method-flag with an eval on the dbh call/execute...
Brandon L. Black [Wed, 15 Mar 2006 13:51:11 +0000 (13:51 +0000)]
lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/DB2.pm

index 0da5731..afc8a66 100644 (file)
@@ -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;
 }
 
index 60a515b..a6e1452 100644 (file)
@@ -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) = @_;