Alfie John | 3 Mar 2011 01:25
Picon
Favicon

Bind parameters for SET statements

Hi,

Not sure if this is a DBD::mysql or a plain DBI problem but thought I
would start here.

It seems that the following code is broken:

  $dbh->do( 'SET TIMESTAMP=?', undef, $timestamp );

This fails with:

  Incorrect argument type to variable 'timestamp'

Yet the following works:

  $dbh->do( "SET TIMESTAMP=$timestamp" );

Alfie

--

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules <at> m.gmane.org

Alfie John | 3 Mar 2011 02:10
Picon
Favicon

Re: Bind parameters for SET statements

On Thu, Mar 03, 2011 at 11:25:03AM +1100, Alfie John wrote:
> It seems that the following code is broken:
> 
>   $dbh->do( 'SET TIMESTAMP=?', undef, $timestamp );
> 
> This fails with:
> 
>   Incorrect argument type to variable 'timestamp'

On further investigation, we've found that DBI is sending the timestamp
over the wire as a string hence the incorrect argument type.

Although not ideal, We have the following work arounds:

  $dbh->do( "SET TIMESTAMP=cast( ? AS UNSIGNED INTEGER )", undef, $timestamp );

And

  use DBI qw{ :sql_types };
  ...
  my $sth = $dbh->prepare( "SET TIMESTAMP=?" );
  $sth->bind_param( 1, $timestamp, { TYPE => SQL_INTEGER } );
  $sth->execute();

Alfie

> 
> Yet the following works:
> 
>   $dbh->do( "SET TIMESTAMP=$timestamp" );
(Continue reading)


Gmane