Subject: | using named bind parameter more than once fails on execute (2.19.1 REGRESSION) |
Date: | Mon, 12 Mar 2012 14:48:01 +0100 |
To: | bug-DBD-Pg [...] rt.cpan.org |
From: | Bernhard Reutner-Fischer <rep.dot.nop [...] gmail.com> |
Hi,
With 2.19.1, binding two occurances of a named bind_param fails.
This used to work fine with 2.18.1.
$ cat x.pl ;echo "---8<---";perl ./x.pl
#!/usr/bin/env perl
use warnings;
use strict;
use DBI;
my $dbh = DBI->connect('dbi:Pg:dbname=mydb', '', '');
my $sth = $dbh->prepare('
select 1 where 1 = :foo and 0 < :foo
');
$sth->bind_param(':foo', 1);
$sth->execute;
my $rows = $sth->rows;
print "ROWS [$rows]\n";
$sth->finish;
$dbh->disconnect;
---8<---
2.19.1:
DBD::Pg::st execute failed: execute called with an unbound placeholder at x.pl line 11.
2.18.1: works fine:
ROWS [1]
Using unnamed placeholders (like $1) of course works fine.
Something like this in the testsuite might be handy to prevent future regressions:
$ git diff t/12placeholders.t | cat
diff --git a/t/12placeholders.t b/t/12placeholders.t
index 0fdd3b5..9460eaf 100644
--- a/t/12placeholders.t
+++ b/t/12placeholders.t
@@ -65,6 +65,16 @@ eval {
};
like ($@, qr{when 0 are needed}, $t);
+# in 2.19.1 we counted named bind params wrongly:
+# Each bind_param satisfies one OR MORE occurances in the SQL string!
+$t='Execute with two identical placeholders works';
+$sql = 'SELECT 1 WHERE 1 = :foo AND 0 < :foo';
+$sth = $dbh->prepare($sql);
+$sth->bind_param(':foo', '1');
+$sth->execute();
+($retr) = $sth->fetchrow_array();
+is ($retr, '1', $t);
+
$t='Execute with ? placeholder works';
$sql = 'SELECT pname FROM dbd_pg_test WHERE pname = ?';
$sth = $dbh->prepare($sql);
TIA and cheers,