Skip Menu |

This queue is for tickets about the DBD-Pg CPAN distribution.

Report information
The Basics
Id: 121419
Status: resolved
Priority: 0/
Queue: DBD-Pg

People
Owner: david [...] endpoint.com
Requestors: sftf-misc [...] mail.ru
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.6.0
Fixed in: (no value)



Subject: Placeholders are not recognized in plpgsql block
DBD-Pg-3.6.0 DBI-1.636 This is perl 5, version 24, subversion 0 (v5.24.0) built for MSWin32-x86-multi-thread-64int Windows Xp SP3 Next script fails with 'Statement has no placeholders to bind at E:\ph-bugreport.pl line 20.' ---------------------------------------------------------- #!/usr/bin/perl use strict; use DBI; my $dbh = DBI->connect('DBI:Pg:dbname=db_name;host=192.168.0.2;port=5432','user','passwd', {PrintError => 1, RaiseError => 0, AutoCommit => 0}); my $stmt = q( do language plpgsql $$ begin insert into msg_sended values (?); exception when unique_violation then update msg_sended set sended_tg=true where msg_id=?; end; $$; ); $dbh->{RaiseError} = 1; my $sth = $dbh->prepare($stmt); $sth->bind_param(1, 12345); $sth->bind_param(2, 12345); my $rows = $sth->execute(); $dbh->commit; --------------------------------------------------------- Without placeholders all works. $dbh->prepare($stmt,{pg_server_prepare => 1}) doesn't help.
Hi there, This is not a bug, since `DO` uses a string argument, so placeholders do no make sense in this case; they cannot be interpolated into normal strings as it is; e.g.: $ perl -MData::Dumper -MDBI -e'$dbh=DBI->connect(q{dbi:Pg:}); print Dumper($dbh->selectcol_arrayref(q{select $$?$$}))' $VAR1 = [ '?' ]; I did note that you can use placeholders to create the entire DO block; i.e.,: $ perl -MData::Dumper -MDBI -e'$dbh=DBI->connect(q{dbi:Pg:}); print Dumper($dbh->do(q{DO language plpgsql ?}, undef, q{begin raise notice $$hi$$; end}))' NOTICE: hi $VAR1 = '0E0'; So this sounds like we need to improve the documentation about placeholders and where they can be used. Since this is not a bug I will improve docs and close.