Is there are ready-to-use transaction wrapper for DBD:Pg?  I'm looking
for somehting which can be used like this:

    my $connect_args = [$data_source, $username, $auth, \%attr];
    transact $connect_args, sub {
      my ($dbh) = @_;
      $dbh->begin_work;
      ...
      $dbh->commit;
    };

The transact subroutine should abort the transaction if the passed sub
dies.  For certain exceptions, the sub should be called again to retry
the transaction.  The database handle should be cached.

This is somewhat PostgreSQL-specific because there are three cases:
permanent errors (such as SQL syntax errors, or non-SQL exceptions),
transient errors which will go away when the transaction is retried
within the same connection (such as serialization failures and certain
types of UNIQUE constraint violations), and errors which will likely go
away when the transaction is retried with a fresh connection (due to
server restart, for example).

This is not very difficult to write as such, but getting the error code
list right is a bit delicate.

-- 
Florian Weimer                <fwei...@bfk.de>
BFK edv-consulting GmbH       http://www.bfk.de/
Kriegsstraße 100              tel: +49-721-96201-1
D-76133 Karlsruhe             fax: +49-721-96201-99

Reply via email to