Re: data_type() not working

[prev] [thread] [next] [Date index for 2005/06/07]

From: Tim Bunce
Subject: Re: data_type() not working
Date: 21:24 on 07 Jun 2005
On Tue, Jun 07, 2005 at 04:15:16PM -0400, Perrin Harkins wrote:
> I'm having problems specifying data types.  I'm adding LIMIT clauses for
> some queries, using MySQL-specific syntax, and DBI needs to be told that
> these are numeric.  I use the following call in my Class::DBI base
> class:
> 
> __PACKAGE__->data_type(
>     '__LIMIT'  => DBI::SQL_INTEGER(),
>     '__OFFSET' => DBI::SQL_INTEGER(),
> );
> 
> When I send in a query with a __LIMIT column and value, I get this
> error:
> 
> DBD::mysql::st bind_param failed: Binding non-numeric field 1, value
> undef as a numeric! [for Statement "SELECT person_id
> FROM   person
> WHERE  1=1  ORDER BY first_name LIMIT ?, ?
> "] at /home/perrin/projects/arcos/lib/Class/DBI.pm line 658.
> 
> And line 658 is the $sth->bind_param call here:
> 
> sub _bind_param {
> 	my ($class, $sth, $keys) = @_;
> 	my $datatype = $class->__data_type or return;
> 	for my $i (0 .. $#$keys) {
> 		if (my $type = $datatype->{ $keys->[$i] }) {
> 			$sth->bind_param($i + 1, undef, $type);
> 		}
> 	}
> }
> 
> It does indeed call it with undef, but this same technique is used in
> Class::DBI::Sweet and seems to work.  Does anyone have a suggestion?
> I'm using MySQL 4.1.12, DBI 1.48, and DBD-mysql 2.9007.

I think DBD::mysql has recently got more strict in sanity checking that
bind_param with a numeric type actually has a numeric value.

I'd guess that they didn't allow for NULL (undef) in their code.
Binding an undef should bind NULL regardless of the type.

Report it as a DBD::mysql bug.

Tim.

data_type() not working
Perrin Harkins 20:15 on 07 Jun 2005

Re: data_type() not working
Tim Bunce 21:24 on 07 Jun 2005

Re: data_type() not working
Perrin Harkins 21:30 on 07 Jun 2005

Generated at 16:38 on 28 Jul 2005 by mariachi v0.52