[DBD::Pg 4/4] Add test for escaped colon-style placeholders, e.g. foobar[1 \\:3]
[email protected] Tue, 6 Jan 2015 16:56:22 +0000
| Newsgroups | perl.dbd.pg.changes |
|---|---|
| Message-ID | <[email protected]> |
Committed by Greg Sabino Mullane <[email protected]> Subject: [DBD::Pg 4/4] Add test for escaped colon-style placeholders, e.g. foobar[1 \\:3] --- t/12placeholders.t | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/t/12placeholders.t b/t/12placeholders.t index ea4d9a6..548cd19 100644 --- a/t/12placeholders.t +++ b/t/12placeholders.t @@ -17,7 +17,7 @@ my $dbh = connect_database(); if (! $dbh) { plan skip_all => 'Connection to database failed, cannot continue testing'; } -plan tests => 254; +plan tests => 256; my $t='Connect to database for placeholder testing'; isnt ($dbh, undef, $t); @@ -408,7 +408,7 @@ for my $line (split /\n\n+/ => $testdata) { $dbh->do('DELETE FROM dbd_pg_test_geom'); eval { $qresult = $dbh->quote($input, {pg_type => $typemap{$type}}); }; if ($@) { - if ($quoted !~ /ERROR: .+/) { + if ($quoted !~ /ERROR: (.+)/) { ## no critic fail ("$t error: $@"); } else { @@ -878,6 +878,27 @@ eval { like($@, qr{execute}, $t); $sth->finish(); +## The space before the colon is significant here +$SQL = qq{SELECT testarray [1 :5] FROM dbd_pg_test WHERE pname = :foo}; +$sth = $dbh->prepare($SQL); +eval { + $sth->bind_param(':foo', 'abc'); + $count = $sth->execute(); +}; +like($@, qr{execute}, $t); +$sth->finish(); + +$t = q{Placeholder escaping works for colons}; +$dbh->{pg_placeholder_escaped} = 1; +$SQL = qq{SELECT testarray [1 \\:5] FROM dbd_pg_test WHERE pname = :foo}; +$sth = $dbh->prepare($SQL); +eval { + $sth->bind_param(':foo', 'abc'); + $count = $sth->execute(); +}; +is($@, '', $t); +$sth->finish(); + ## Begin custom type testing -- 1.8.4