use DBI qw(:sql_types);
Tim Bunce wrote:
On Wed, Jul 16, 2003 at 01:35:23AM -0500, Christopher L. Everett wrote:
  
I've been using an alpha version of column_info that Tim Bunce
sent the Class::DBI list ages ago in connection with some code
to extend Class::DBI.  AFAICS, it's precisely what's in the
latest version of DBD::mysql.  I got it to work without any
finding bugs except it couldn't handle tablenames that included
the database name, like 'foo.bar', which I naturally fixed.
    

I don't think there's a bug. Looks like you were calling it the wrong way:
my $sth = $dbh->column_info(undef, undef, 'physemp.account', '%');
    

Should be

  my $sth = $dbh->column_info(undef, 'physemp', 'account', '%');

Tim.

OK, with the current CPAN release of DBD::mysql my program:

<code>
#!/usr/bin/perl

use strict;
use My::DBI;

my $dbh = My::DBI->connect('physemp');
my $sth = $dbh->column_info(undef, 'physemp', 'account', '%');
</code>

will output

#perl test.pl
Undefined subroutine &DBD::mysql::db::SQL_VARCHAR called at /usr/local/lib/perl/5.8.0/DBD/mysql.pm line 337.

going into the source for DBD::mysql, I see line 7

use DBI ();

which I think ought to maybe be

use DBI qw(:sql_types);

but that didn't fix the problem.  However, going to line 337
which originally reads

       $info->{DATA_TYPE} = SQL_VARCHAR();

and patching it to say

       $info->{DATA_TYPE} = DBI::SQL_VARCHAR();

and then repeating that for all the SQL_.*() subroutine calls in
column_info does work, at least on initial inspection.  Just for
grins and giggles (I don't think this is how you'd want to fix it)
I included a patch.

HTH
--- mysql.pm
+++ mysql.pm
@@ -334,9 +334,9 @@
         my @type_attr = split / /, $3||'';
         #warn "$type: $basetype [EMAIL PROTECTED] [EMAIL PROTECTED]";
 
-        $info->{DATA_TYPE} = SQL_VARCHAR();
+        $info->{DATA_TYPE} = DBI::SQL_VARCHAR();
         if ($basetype =~ /char|text|blob/) {
-            $info->{DATA_TYPE} = SQL_CHAR() if $basetype eq 'char';
+            $info->{DATA_TYPE} = DBI::SQL_CHAR() if $basetype eq 'char';
             if ($type_params[0]) {
                 $info->{COLUMN_SIZE} = $type_params[0];
             }
@@ -359,29 +359,29 @@
             $info->{"mysql_values"} = [EMAIL PROTECTED];
         }
         elsif ($basetype =~ /int/) {
-            $info->{DATA_TYPE} = SQL_INTEGER();
+            $info->{DATA_TYPE} = DBI::SQL_INTEGER();
             $info->{NUM_PREC_RADIX} = 10;
             $info->{COLUMN_SIZE} = $type_params[0];
         }
         elsif ($basetype =~ /decimal/) {
-            $info->{DATA_TYPE} = SQL_DECIMAL();
+            $info->{DATA_TYPE} = DBI::SQL_DECIMAL();
             $info->{NUM_PREC_RADIX} = 10;
             $info->{COLUMN_SIZE}    = $type_params[0];
             $info->{DECIMAL_DIGITS} = $type_params[1];
         }
         elsif ($basetype =~ /float|double/) {
-            $info->{DATA_TYPE} = ($basetype eq 'float') ? SQL_FLOAT() : SQL_DOUBLE();
+            $info->{DATA_TYPE} = ($basetype eq 'float') ? DBI::SQL_FLOAT() : 
DBI::SQL_DOUBLE();
             $info->{NUM_PREC_RADIX} = 2;
             $info->{COLUMN_SIZE} = ($basetype eq 'float') ? 32 : 64;
         }
         elsif ($basetype =~ /date|time/) { # date/datetime/time/timestamp
             if ($basetype eq 'time' or $basetype eq 'date') {
-                $info->{DATA_TYPE}   = ($basetype eq 'time') ? SQL_TYPE_TIME() : 
SQL_TYPE_DATE();
+                $info->{DATA_TYPE}   = ($basetype eq 'time') ? DBI::SQL_TYPE_TIME() : 
DBI::SQL_TYPE_DATE();
                 $info->{COLUMN_SIZE} = ($basetype eq 'time') ? 8 : 10;
             }
             else { # datetime/timestamp
-                $info->{DATA_TYPE}     = SQL_TYPE_TIMESTAMP();
-                $info->{SQL_DATA_TYPE} = SQL_DATETIME();
+                $info->{DATA_TYPE}     = DBI::SQL_TYPE_TIMESTAMP();
+                $info->{SQL_DATA_TYPE} = DBI::SQL_DATETIME();
                 $info->{SQL_DATETIME_SUB} = $info->{DATA_TYPE} - 
($info->{SQL_DATA_TYPE} * 10);
                 $info->{COLUMN_SIZE}   = ($basetype eq 'datetime') ? 19 : 
$type_params[0] || 14;
             }

Reply via email to