Re: Bind parameters for SET statements

Alfie John <[email protected]> Thu, 3 Mar 2011 12:10:26 +1100
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
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" );
> 
> Alfie
> 
> -- 
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe:    http://lists.mysql.com/[email protected]
> 

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]