[Dbix-class] Manual Transaction Handling for Sybase ?

Tim Bunce Tim.Bunce at pobox.com
Wed Jul 8 22:49:49 GMT 2009


On Wed, Jul 08, 2009 at 09:18:01PM +0200, Robert Heinzmann wrote:
> Hello, 
> 
> I'm using DBIx::Class and I want to implement manual transactions. 
> 
> Connection is set to "AutoCommit => 0". I issue manual 
> 
> ----
> txn_begin()
> 
> Insert
> Update
> Select 
> 
> txn_commit() / txn_rollback()
> ----
> 
> However no Transaction takes place. DBIC Trace shows no BEGIN or COMMIT
> / ROLLBACK.

I ran into exactly this problem recently (with PostgreSQL)
and was equally surprised.

> sub _populate_dbh {
> 
>   # Always set the transaction depth on connect, since
>   #  there is no transaction in progress by definition
>   $self->{transaction_depth} = $self->_dbh_autocommit ? 0 : 1;

That's the key line. Essentially a txn_begin has been done for you.

> For me this means with AutoCommit => 0 I cant do any transactions at all
> ... 
> 
> Looks like a bug ? 

The "DBIC Way" is to use AutoCommit => 1 and enable transactions only
"when needed". (I'm guessing that comes from a "web service" viewpoint.)

BTW, be wary of txn_do() as it'll re-execute the code if the code throws
an except and the dbh is disconnected. That might cause unwanted
side-effects. See the note in the docs re idempotent actions.

I'm supposed to be working on a patch to enable the caller to control
(ie disable) that auromatic retry behaviour.

Tim.



More information about the DBIx-Class mailing list