Subject: | Bind values rely on Perl's automatic numeric/string scalar conversion |
Mac OS X 10.2, Perl 5.6.0, DBD::Pg 1.22, DBI 1.45
Bind values appear to rely upon Perl's automatic numeric/string scalar conversion in order to determine whether or not to quote.
This bug was discussed on
http://aspn.activestate.com/ASPN/Mail/Message/perl-DBI-dev/1607287
my $dbh = DBI->connect(...); #connect to Postgres; no errors with SQLite
my $scalar = "abc";
warn "scalar is greater than zero (and now considered numeric)" if $scalar > 0;
warn "dbh->quote(scalar) works ok: " . $dbh->quote($scalar);
warn "but bind values do not:" . $dbh->selectrow_array(
"SELECT 1 WHERE 1=?",
undef,
($scalar)
);
Using a numeric operator on the scalar makes Perl auto-convert it to a number; this is interpreted by the magic in Pg.xs as rendering the scalar ineligible for quoting.
One solution is to bind those variables that must be text but might have been numberified with "$varname", thereby stringifying them in the eyes of Perl.