Attached is a small patch for column_info().
$TypeName was set before the test

  $ti->{COLUMN_SIZE} >= $ColSize;

Thus, if no type has a large enough COLUMN_SIZE (hypothetical
case), $TypeName may contain a wrong type name.
Now, $TypeName remains undefined in this case.


Steffen
*** DBD-ADO-2.4_04-orig/lib/DBD/ADO.pm  Tue Apr 09 04:51:22 2002
--- ADO.pm      Wed Apr 10 21:12:54 2002
***************
*** 1057,1083 ****
                                if $lastError;
  
                while ( ! $RecSet->{EOF} ) {
-                       my @Fields;
                        my $AdoType    = $RecSet->Fields('DATA_TYPE'   )->{Value};
                        my $ColFlags   = $RecSet->Fields('COLUMN_FLAGS')->{Value};
                        my $IsLong     = ( $ColFlags & $ado_consts->{adFldLong } ) ? 1 
: 0;
                        my $IsFixed    = ( $ColFlags & $ado_consts->{adFldFixed} ) ? 1 
: 0;
                        my @SqlType    = DBD::ADO::db::convert_ado_to_odbc( $dbh, 
$AdoType, $IsFixed, $IsLong );
- #                     my $TypeInfo   = $dbh->type_info( $SqlType[0] );
- #                     my $TypeName   = $TypeInfo ? $TypeInfo->{TYPE_NAME} : undef;
-                       my $TypeName;
                        my $IsNullable = $RecSet->Fields('IS_NULLABLE')->{Value} ? 
'YES' : 'NO';
                        my $ColSize    = $RecSet->Fields('NUMERIC_PRECISION'       
)->{Value}
                                      || 
$RecSet->Fields('CHARACTER_MAXIMUM_LENGTH')->{Value}
                                                                                || 0;  
# Default value to stop warnings ???
                        my $ado_tis    = DBD::ADO::db::_ado_get_type_info_for( $dbh, 
$AdoType, $IsFixed, $IsLong );
! #                     print '***', $AdoType, $IsFixed, $IsLong, ' => ', $ColSize, 
$RecSet->Fields('COLUMN_NAME')->{Value};
!                       for my $ti ( sort { $a->{COLUMN_SIZE} <=> $b->{COLUMN_SIZE} } 
@$ado_tis )
!                       {
                                $TypeName = $ti->{TYPE_NAME};
! #                             print '***', $AdoType, $IsFixed, $IsLong, ' => ', 
$ti->{TYPE_NAME}, $ti->{COLUMN_SIZE}, $ColSize, 
$RecSet->Fields('COLUMN_NAME')->{Value};
!                               last if $ti->{COLUMN_SIZE} >= $ColSize;
                        }
                        $Fields[ 0] = $RecSet->Fields('TABLE_CATALOG'           
)->{Value}; # TABLE_CAT
                        $Fields[ 1] = $RecSet->Fields('TABLE_SCHEMA'            
)->{Value}; # TABLE_SCHEM
                        $Fields[ 2] = $RecSet->Fields('TABLE_NAME'              
)->{Value}; # TABLE_NAME
--- 1057,1085 ----
                                if $lastError;
  
                while ( ! $RecSet->{EOF} ) {
                        my $AdoType    = $RecSet->Fields('DATA_TYPE'   )->{Value};
                        my $ColFlags   = $RecSet->Fields('COLUMN_FLAGS')->{Value};
                        my $IsLong     = ( $ColFlags & $ado_consts->{adFldLong } ) ? 1 
: 0;
                        my $IsFixed    = ( $ColFlags & $ado_consts->{adFldFixed} ) ? 1 
: 0;
                        my @SqlType    = DBD::ADO::db::convert_ado_to_odbc( $dbh, 
$AdoType, $IsFixed, $IsLong );
                        my $IsNullable = $RecSet->Fields('IS_NULLABLE')->{Value} ? 
'YES' : 'NO';
                        my $ColSize    = $RecSet->Fields('NUMERIC_PRECISION'       
)->{Value}
                                      || 
$RecSet->Fields('CHARACTER_MAXIMUM_LENGTH')->{Value}
                                                                                || 0;  
# Default value to stop warnings ???
+                       my $TypeName;
                        my $ado_tis    = DBD::ADO::db::_ado_get_type_info_for( $dbh, 
$AdoType, $IsFixed, $IsLong );
!                       $dbh->trace_msg('  *** ' . 
$RecSet->Fields('COLUMN_NAME')->{Value} . "($ColSize): $AdoType, $IsFixed, $IsLong\n", 
3 );
!                       # find the first type which has a large enough COLUMN_SIZE:
!                       for my $ti ( sort { $a->{COLUMN_SIZE} <=> $b->{COLUMN_SIZE} } 
@$ado_tis ) {
!                               $dbh->trace_msg("    * => 
$ti->{TYPE_NAME}($ti->{COLUMN_SIZE})\n", 3 );
!                               if ( $ti->{COLUMN_SIZE} >= $ColSize ) {
                                $TypeName = $ti->{TYPE_NAME};
!                                       last ;
                        }
+                       }
+                       # unless $TypeName: Standard SQL type name???
+ 
+                       my @Fields;
                        $Fields[ 0] = $RecSet->Fields('TABLE_CATALOG'           
)->{Value}; # TABLE_CAT
                        $Fields[ 1] = $RecSet->Fields('TABLE_SCHEMA'            
)->{Value}; # TABLE_SCHEM
                        $Fields[ 2] = $RecSet->Fields('TABLE_NAME'              
)->{Value}; # TABLE_NAME

Reply via email to