Subject: | DBD::DB2 can't bind under perl 5.16.0 |
When I have a "SUM(CASE WHEN COL = 'Y' THEN 100 ELSE 0 END)"
column *and* I have a variable for binding, DBD::DB2 is failing.
Here is my code, pared down a lot:
use 5.14.0;
use DBI;
my $dbh = DBI->connect('dbi:DB2:cbstats') or die "Can't connect: ",
$DBI::errstr;
say "Perl $^V, DBI $DBI::VERSION, DBD::DB2 $DBD::DB2::VERSION";
my $sql = <<SQL;
SELECT
SUM(CASE WHEN QUESTION = 'Y' THEN 100.00 ELSE 0 END) /
COUNT(*) AS PCT
FROM
CBSTATS.LOGS,
CBSTATS.USER
WHERE
FROM = NICK
AND
VISIBLE = ?
GROUP BY
FROM
HAVING COUNT(*) > 10
SQL
my $sth = $dbh->prepare($sql) or die "Can't prepare SQL: $dbh->
{errstr}";
my @param = ('Y');
$sth->execute(@param) or die "Can't execute: $dbh->{errstr}";
And here is the output using both Perl 5.14.2 and 5.16.0:
$ for x in 14.2 16.0; do perl5.$x db.pl; done
Perl v5.14.2, DBI 1.616, DBD::DB2 1.81
Perl v5.16.0, DBI 1.616, DBD::DB2 1.84
Can't bind unknown parameter marker ':p1' at db.pl line 29.
With 5.14.2, this all works. With 5.16.0, not so much.
Running Linux/amd64.