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 [ Do, 03 März 2011 01:25 ] [ ID #2056121 ]

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" );
>
> Alfie
>
> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe: http://lists.mysql.com/perl?unsub=alfie [at] 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 [at] m .gmane.org
Alfie John [ Do, 03 März 2011 02:10 ] [ ID #2056122 ]
Datenbanken » gmane.comp.db.mysql.perl » Bind parameters for SET statements

Vorheriges Thema: Insert or update data in mysql using a perl script
Nächstes Thema: Perl script to insert data in mysql from Excel file