I've ended up calling this procedure
in the loop before poll() - to run queued
commands from an array of hashes:
sub execSql {
eval {
my $dbh = DBI->connect_cached(DSN, DBUSER, DBPASS, {
private_key => __FILE__,
AutoCommit => 1,
PrintWarn => 1,
PrintError => 1,
RaiseError => 1,
FetchHashKeyName => 'NAME_lc',
pg_enable_utf8 => 1
});
if ($WaitSql && $dbh->pg_ready) {
$WaitSql = 0;
$dbh->pg_result();
}
if (!$WaitSql && @Sqls) {
$WaitSql = 1;
my $sql = shift @Sqls;
my $cmd = $sql->{CMD};
my $args = $sql->{ARGS};
my $sth = $dbh->prepare_cached($cmd,
{ pg_async => PG_ASYNC + PG_OLDQUERY_WAIT });
$sth->execute(@$args);
}
};
warn $@ if $@;
}