On Wed Sep 14 01:23:11 2011, jafd wrote:
Show quoted text>
> One might say that they do the same thing. I also thought so.
> In reality, the first one executes while the second one fails with:
>
> Cannot bind unknown placeholder ':status'
>
> I think this must be a bug in DBD::Pg.
Indeed. When parsing the placeholders, the code does strncmp which
matches left prefix of previously found placeholders.
Attached are patches against 1.49 (where I experienced the problem) and
against 2.99 (where the code is still the same), with test updates.
Please apply.
Jan
diff -ru DBD-Pg-2.99.9_2-orig/dbdimp.c DBD-Pg-2.99.9_2/dbdimp.c
--- DBD-Pg-2.99.9_2-orig/dbdimp.c 2011-06-20 16:37:15.000000000 -0400
+++ DBD-Pg-2.99.9_2/dbdimp.c 2011-11-02 09:45:26.000000000 -0400
@@ -1944,7 +1944,8 @@
sectionsize = currpos-sectionstop;
/* Have we seen this placeholder yet? */
for (xint=1,thisph=imp_sth->ph; NULL != thisph; thisph=thisph->nextph,xint++) {
- if (0==strncmp(thisph->fooname, statement-sectionsize, sectionsize)) {
+ if (0==strncmp(thisph->fooname, statement-sectionsize, sectionsize)
+ && thisph->fooname[sectionsize] == '\0') {
newseg->placeholder = xint;
newseg->ph = thisph;
break;
diff -ru DBD-Pg-2.99.9_2-orig/t/02attribs.t DBD-Pg-2.99.9_2/t/02attribs.t
--- DBD-Pg-2.99.9_2-orig/t/02attribs.t 2011-06-14 00:12:52.000000000 -0400
+++ DBD-Pg-2.99.9_2/t/02attribs.t 2011-11-02 09:43:19.000000000 -0400
@@ -18,7 +18,7 @@
if (! $dbh) {
plan skip_all => 'Connection to database failed, cannot continue testing';
}
-plan tests => 249;
+plan tests => 250;
isnt ($dbh, undef, 'Connect to database for handle attributes testing');
@@ -482,6 +482,10 @@
$sth = $dbh->prepare('SELECT 123 FROM pg_class WHERE relname=? AND reltuples=? and relpages=?');
is ($sth->{'NUM_OF_PARAMS'}, 3, $t);
+$t='Statement handle attribute "NUM_OF_PARAMS" works correctly with placeholders in reverse order';
+$sth = $dbh->prepare("select :p10 + :p1");
+is ($sth->{'NUM_OF_PARAMS'}, 2, $t);
+
$t='Statement handle attribute "NUM_OF_PARAMS" works correctly before execute with one placeholder';
$sth = $dbh->prepare('SELECT 123 AS "Sheep", CAST(id AS float) FROM dbd_pg_test WHERE id=?');
is ($sth->{'NUM_OF_PARAMS'}, 1, $t);
diff -ur DBD-Pg-1.49-orig/dbdimp.c DBD-Pg-1.49/dbdimp.c
--- DBD-Pg-1.49-orig/dbdimp.c 2006-05-03 22:11:14.000000000 -0400
+++ DBD-Pg-1.49/dbdimp.c 2011-11-02 09:38:28.000000000 -0400
@@ -1311,7 +1311,8 @@
sectionsize = currpos-sectionstop;
/* Have we seen this placeholder yet? */
for (xint=1,thisph=imp_sth->ph; NULL != thisph; thisph=thisph->nextph,xint++) {
- if (0==strncmp(thisph->fooname, statement-sectionsize, sectionsize)) {
+ if (0==strncmp(thisph->fooname, statement-sectionsize, sectionsize)
+ && thisph->fooname[sectionsize] == '\0') {
newseg->placeholder = xint;
newseg->ph = thisph;
break;
diff -ur DBD-Pg-1.49-orig/t/02attribs.t DBD-Pg-1.49/t/02attribs.t
--- DBD-Pg-1.49-orig/t/02attribs.t 2011-11-02 09:37:04.000000000 -0400
+++ DBD-Pg-1.49/t/02attribs.t 2011-11-02 09:37:30.000000000 -0400
@@ -8,7 +8,7 @@
$|=1;
if (defined $ENV{DBI_DSN}) {
- plan tests => 132;
+ plan tests => 133;
}
else {
plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the README file';
@@ -445,6 +445,11 @@
$sth->finish();
+$sth = $dbh->prepare("select :p10 + :p1");
+$attrib = $sth->{'NUM_OF_PARAMS'};
+is( $attrib, '2', 'Statement handle attribute "NUM_OF_PARAMS" works correctly with two placeholders');
+$sth->finish();
+
#
# Test of the statement handle attribute "CursorName"
#