[Catalyst] How safe are database transactions?

Kay Sindre Bærulfsen berulfsen at gmail.com
Thu Jan 4 11:34:07 GMT 2007


On 1/4/07, Xavier Robin <robin0 at etu.unige.ch> wrote:
[...]
>
> my $transaction = $c->model('MyAppDB')->storage;
> $transaction->txn_begin;
> eval {
>     # Do some insertions with $c->model('MyAppDB::Table')->create()
> };
> if ($@) {
>     $transaction->txn_rollback;
> }
> else {
>     $transaction->txn_commit;
> }
>

Fist of all, put your $transaction->txn_commit inside your eval{},
because the commit can fail too.

> Note: I'm connecting to a PostgreSQL database with Autocommit on.

As long as you/DBIx::Class sends a BEGIN, your should be okey.


-- 
Kay Bærulfsen



More information about the Catalyst mailing list