bucardo / dbdpg

Perl Postgres driver DBD::Pg aka dbdpg
48 stars 36 forks source link

Placeholders must begin with ':' when using the ":foo" style #38

Closed dk closed 5 years ago

dk commented 6 years ago

Legacy code using ":foo" style selects fails with this error. The code is as follows:

$dbh->selectall_array('SELECT now where 1 = :id', {}, $id);

Since the call is issued as

    sv_setiv(idx, i);
    if (!dbd_bind_ph(sth, imp_sth, idx, value, 0, Nullsv, FALSE, 0)) {

with idx being the third parameter with the integer, and the third parameter is supposed to be a ":foo" string inside dbd_bind_ph, I can't find a way how this supposed to be working.

ilmari commented 5 years ago

When using named placeholders, you must bind them by name using bind_param:

my $sth = $dbh->prepare('SELECT now() where 1 = :id');
$sth->bind_param(':id', $id);
$sth->execute;
$sth->fetchrow_array; # '2019-03-30 22:20:44.600588+00'
dk commented 5 years ago

thank you!