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.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to