in reply to Perl DBI Mistaking a Number For a String

If any arguments are given, then execute will effectively call "bind_param" for each value before executing the statement. Values bound in this way are usually treated as SQL_VARCHAR types unless the driver can determine the correct type (which is rare), or unless bind_param (or bind_param_inout) has already been used to specify the type.


I suggest calling bind_param for each parameter and passing the correct bind type. Did you perhaps upgrade your MySQL or DBD::MySQL?
  • Comment on Re: Perl DBI Mistaking a Number For a String

Replies are listed 'Best First'.
Re^2: Perl DBI Mistaking a Number For a String
by {NULE} (Hermit) on Apr 21, 2005 at 14:03 UTC
    Hi again,

    I changed the code to use a bind_param and it seems to be working. This is what it looks like now:

    my $sh = $dbh->prepare("select * from records where date <= ? order by + date asc, time asc limit ?,10000") || die "Could not prepare select: " . $dbh->errstr; my $date = "2005-02-26"; my $n = 0; $sh->bind_param(1, $date, SQL_DATE); $sh->bind_param(2, $n, SQL_INTEGER); $sh->execute() || die "Could not execute select: " . $dbh->errstr;
    It still seems a little odd that the code broke in this manner. Never the less, I appreciate the quick reply as this was a production problem and I was stuck. :)

    Thanks,

Re^2: Perl DBI Mistaking a Number For a String
by {NULE} (Hermit) on Apr 21, 2005 at 13:51 UTC
    Thanks for the reply. MySQL certainly has not been updated, but DBD::MySQL may have been. I'm trying to reach my admin to find out if that's the case. I'll play with bind_param and see what I come up with.

    Thanks,