Subject: | forking confuses server side prepared statements |
When using server side prepare statements and forking a child process, even if the child process is marked with an 'InactiveDestroy' flag, the parent process immediately hits an error when it attempts to reuse a pre-prepared statement. See attached file to reproduce problem.
#! /usr/local/bin/perl -wT
use strict;
use DBI();
MAIN: {
$ENV{'DBI_DSN'} ||= 'dbi:Pg:dbname=template1';
$ENV{'DBI_USER'} ||= 'postgres';
$ENV{'DBI_PASS'} ||= '';
my ($dbh) = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS}, {RaiseError => 1, PrintError => 0, AutoCommit => 0});
# $dbh->{pg_server_prepare} = 0;
my ($sql) = qq[SELECT * FROM pg_tables WHERE tablename LIKE ?];
my ($sth) = $dbh->prepare($sql);
$sth->execute('foo');
$sth->finish();
my ($pid);
if ($pid = fork()) {
waitpid($pid, 0);
unless ($? == 0) {
die("Child failed to execute successfully\n");
}
} elsif (defined $pid) {
$dbh->{'InactiveDestroy'} = 1;
exit(0);
} else {
die("Failed to fork:$!\n");
}
$sth->execute('foo');
$sth->finish();
$dbh->disconnect();
}