DECIMAL col type bug in DBD::mysql w/mysql 5

Ray Zimmerman <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
I believe I have discovered a bug (I'm guessing it's in DBD::mysql).  
When connecting to mysql 5, it returns the type of a decimal column  
as SQL_VARCHAR, as opposed to SQL_DECIMAL returned when the mysql  
server is version 4.1.

The details of my setup:

	Mac OS X Tiger 10.4.3
	perl 5.8.6
	DBI 1.47
	DBD::mysql 3.0002 (and 3.0002_04) (built with mysql-5.0.16 libraries)
	mysql 5.0.16
	mysql 4.1.15

The script below demonstrates the bug, outputing ...

    value   12  SQL_VARCHAR

... when connecting to a mysql 5.0.16 server on localhost, vs ...

    value    3  SQL_DECIMAL

... when connecting to a mysql 4.1.15 server on localhost.

Ray Zimmerman
Director, Laboratory for Experimental Economics and Decision Research
428-B Phillips Hall, Cornell University, Ithaca, NY 14853
phone:  (607) 255-9645

-------------------------------------

#!/usr/bin/perl -w
use DBI;

## get DBI type map
my %map;
foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) {
	$map{&{"DBI::$_"}} = $_;
}

my $dbh = DBI->connect('DBI:mysql:test', 'test');
my $table = 'mysql5bug';
my $drop   = "DROP TABLE IF EXISTS $table";
my $create = "CREATE TABLE $table (value decimal(5,2));";
my $select = "SELECT * FROM $table WHERE 1 = 0";

## create table and get column types
$dbh->do($drop)		or die $dbh->errstr;
$dbh->do($create)	or die $dbh->errstr;
my $sth = $dbh->prepare( $select );
my $rv = $sth->execute;
my $fields = $sth->{NAME};
my $types  = $sth->{TYPE};

## print out column types
foreach (0..$#$fields) {
	printf("%8s  %3d  %s\n", $fields->[$_], $types->[$_], $map{$types-> 
[$_]});
}

## cleanup
$dbh->do($drop)		or die $dbh->errstr;
$sth->finish;
$dbh->disconnect;

1;


-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.