Subject: | memory management error using question mark operator |
Date: | Wed, 03 Jan 2018 16:42:20 +0000 |
To: | bug-DBD-Pg [...] rt.cpan.org |
From: | Ryley Breiddal <ryleyb [...] gmail.com> |
I filed this on github (https://github.com/bucardo/dbdpg/issues/33)
already, but since CPAN seems to be more active, here is the report:
I have code that uses bind parameters and the ? operator for a JSONB field.
I get a variety of different errors, each time I run my test script.
Test Script:
use strict;
use DBI;
use DBD::Pg;
my $connect_info = {
dsn => 'dbi:Pg:dbname=xxx host=localhost port=5432',
user => 'username',
password => 'password'
};
my $qry = q{
select count(*)
from tablename
where
col1 = $1 and
jsonb_col \? 'key' and
1 = $2
};
for (my $i=0;$i<50;$i++){
print STDERR "iteration $i...";
my $dbh =
DBI->connect($connect_info->{dsn},$connect_info->{user},$connect_info->{password});
my $sqlh = $dbh->prepare($qry) || warn "Can't prepare SQL statement:
$DBI::errstr\n";
$sqlh->bind_param('$1',10000);
$sqlh->bind_param('$2',1);
$sqlh->execute() || warn "Cant execute SQL statement: $DBI::errstr\n";
$sqlh->finish();
$dbh->disconnect();
print STDERR "done \n";
}
Example output:
iteration 0...done
iteration 1...Statement has no placeholders to bind at test-dbd-pg.pl line
25.
*** Error in `perl': double free or corruption (fasttop):
0x0000000001cb2480 ***
Aborted
Another run:
iteration 0...done
iteration 1...DBD::Pg::st execute failed: ERROR: invalid byte sequence for
encoding "UTF8": 0xcf 0x03 at test-dbd-pg.pl line 28.
Cant execute SQL statement: ERROR: invalid byte sequence for encoding
"UTF8": 0xcf 0x03
done
... (repeated 48 more times)
If I take out the bind params or only have one of them, it works fine.
If I replace "jsonb_col \? 'key' " in the where clause with "
jsonb_typeof(jsonb_col->'key') is not null" it works fine.
System info:
-Postgresql 9.6.1
-DBD::Pg 3.7.0
-DBI 1.637
Other than those, I believe stock Debian Jessie.
Regards,
Ryley