[Catalyst] How safe are database transactions?

Xavier Robin robin0 at etu.unige.ch
Thu Jan 4 09:45:49 GMT 2007


Hello all,

I'm sorry if it is the wrong list, but I thought it was more a 
Catalyst-specific issue than a DBIx::Class one, as it is about the way 
Catalyst uses DBIx::Class.

I would like to use transactions in Catalyst.

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;
}

I could do it by testing that all data will be able to fit into the database 
and then insert everything, but it is basically doing it twice, and I would 
like to avoid that.

But is it safe?
I mean, my application died once before the rollback and everything went 
wrong. I think this is because Catalyst connects only once, so all the work 
is done under the same connexion. I will be more careful from now, but could 
it still happen that some data of another user is being lost if he sends a 
command at the same time? Or is it safe?

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

Greetings,
Xavier



More information about the Catalyst mailing list