Bind parameters for SET statements

Bind parameters for SET statements

am 03.03.2011 01:25:03 von Alfie John

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@m .gmane.org

Re: Bind parameters for SET statements

am 03.03.2011 02:10:26 von Alfie John

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/perl?unsub=alfie@h4c.kr
>

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