[Dbix-class] Re: ROLLBACK seems to be skipped on 0.08

Adam Sjøgren adsj at novozymes.com
Fri Nov 2 19:28:01 GMT 2007


On Thu, 1 Nov 2007 21:38:25 -0500, Brandon wrote:

> You can have the same multi-statement transactions with the same
> guarantees of serialization with or without AutoCommit at the DBI
> level.  At the DBI levels and below, all the way to your database,
> there is no difference between:

> $dbh->{AutoCommit} = 0;
> $dbh->do("INSERT ...");
> $dbh->do("DELETE ...");
> $dbh->commit;

> and:

> $dbh->{AutoCommit} = 1;
> $dbh->begin_work;
> $dbh->do("INSERT ...");
> $dbh->do("DELETE ...");
> $dbh->commit;

The thing I like about AutoCommit=0 is that if the lazy programmer
writes some code that modifies the database without considering how much
should be wrapped in a transaction (i.e. he does not ensure that a
commit is there), it doesn't work as he expects.

To me that is a nice way to ensure that I remember to consider
transactions for all the parts of the code that modifies/adds stuff.

Since txn_do arrived, I know I ought to use that for transactions, every
time I need them, but with AutoCommit=1 I lose the automatic kick in the
head if (when) I forget.


  Best regards,

    Adam

-- 
                                                          Adam Sjøgren
                                                    adsj at novozymes.com



More information about the DBIx-Class mailing list