[Dbix-class] Autocommit => 0

Peter Rabbitson rabbit+dbic at rabbit.us
Mon Nov 26 19:22:47 GMT 2012


On Mon, Nov 26, 2012 at 10:02:48AM -0500, Len Jaffe wrote:
> On Mon, Nov 26, 2012 at 8:17 AM, Peter Rabbitson <rabbit+dbic at rabbit.us>wrote:
> 
> > On Mon, Nov 26, 2012 at 04:14:18PM +0400, Dmitry Belyavsky wrote:
> > > I prefer to set AutoCommit to 0 because it helps to avoid extra commits
> > > during debug just not writing the commit() function, whether I use
> > > DBIx::Class or plain DBI.
> >
> > The same effect can be achieved in a much saner way by wrapping the
> > entire debug session in a transaction and killing it right before the
> > block's end by throwing an exception or something. What you described is
> > a prime example of "erroneous use of AC = 0" :)
> >
> 
> So you're saying leave AutoCommit set, and if we need a multi-statement
> transaction, we should explicitly wrap those in a new TX?

Precisely. Not doing so usually leads to massive transactions, in which 
case a single unforseen error can abort the entire work done by a 
program, and leave your database out of sync with the rest of the world 
(it will roll back, the world won't).

It is of course possible to have good transaction discipline with AC = 
0, but it is much harder than with explicit txn begins.

Cheers



More information about the DBIx-Class mailing list