[Dbix-class] Problem with populate() and commits?

Louis Erickson lerickson at rdwarf.net
Fri May 15 18:48:11 GMT 2009

On Thu, 14 May 2009, Chris Cole wrote:


> Why does it work fine when I have Autocommit 'on', but get the following
> error with Autocommit 'off':

I'm surprised no one else has replied.  This bit me too when I first 
started with DBIC.  It seemed backwards to me at the time.

DBIx::Class assumes autocommit is on, and works strangely or not at all if 
it is off.

If you must have it off, say, to share a db handle with older code that 
requires it, you can usually finesse it to work but transactions will be 
hard. The one time I found myself in that situation, I discovered opening 
a second handle was easier.

You'll be best off with DBIC to leave autocommit on and use DBIC's 
transaction handling through txn_do instead.  It works well and handles 
some things the raw DBI one won't.

The DBIx::Class::Storage::DBI documentation 
explains this:

> DBIx::Class and AutoCommit
> DBIx::Class can do some wonderful magic with handling exceptions, 
> disconnections, and transactions when you use AutoCommit => 1 combined 
> with txn_do for transaction support.
> If you set AutoCommit => 0 in your connect info, then you are always in 
> an assumed transaction between commits, and you're telling us you'd like 
> to manage that manually. A lot of the magic protections offered by this 
> module will go away. We can't protect you from exceptions due to 
> database disconnects because we don't know anything about how to restart 
> your transactions. You're on your own for handling all sorts of 
> exceptional cases if you choose the AutoCommit => 0 path, just as you 
> would be with raw DBI.

Hope that explains it.  =)

Louis Erickson - lerickson at rdwarf.net - http://www.rdwarf.com/~wwonko/

Law of Probable Dispersal:
	Whatever it is that hits the fan will not be evenly

More information about the DBIx-Class mailing list