[Dbix-class] Options to avoid "Issuing rollback() for database..." (aka. AutoCommit and DBIx (again))

Erik Wasser erik.wasser at iquer.net
Mon May 5 09:02:59 BST 2008


Hello list,

maybe I'm under the weather so please forgive me. I've trouble with 
getting the concept of AutoCommit (of the DBI) in combination with 
DBIx::Class::Schema->txn_do().

I've read the long posting "Re: Transactions and AutoCommit" from "Josef 
Karthauser from the archive of the mailing list 
(http://lists.scsys.co.uk/pipermail/dbix-class/2007-January/003440.html).

I'm familiar with the concept with the AutoCommit feature of databases 
so that's is not the problem. I quite not sure what does this mean for 
the coding practice with the DBIx classes.

The problem is (to get more specific) that I'm getting a "Issuing 
rollback() for database handle being DESTROY'd without explicit 
disconnect()" warning at the end of my code. That tells me that there 
is one ongoing transaction at the end of the program.

So here's is some (pseudo)code:

------------------------------------------------------------------------

# You can use any kind of schema (I'm not using any special methods
# or overloading stuff). Neither the kind of database does matter.
my $schema = TestDatabase->connect(
   "dbi:SQLite:dbname=database.sqllite", "", "",
   { PrintError => 1, RaiseError => 1, AutoCommit => 0 }
);

my @all;

eval {
   @all = $schema->txn_do(sub {
      $schema->resultset('Persons')->search( { id => 9999 } )->all;
   });
};
if ($@)
{
   warn $@;
}

------------------------------------------------------------------------

I set AutoCommit=>1 because I do some non-DBIx accessing and that saves 
me some '$dbh->begin_work()' calls.

So what are my options here to avoid the warning "Issuing rollback() for 
database..." at the end of the program? I figured out two ways on my 
own but I need a second opinion for my solutions:

a) I added an explicit "$scheme->commit()" call in the eval {} construct 
like this:

eval {
   @all = $schema->txn_do($code);
   $schema->txn_commit();
};

b) I turn the AutoCommit feature to Off and change my "legacy" code to 
work with that feature.

And refering to the "Another Important Note" paragraph in "perldoc 
DBIC::SQL::Abstract" (DBIC can do some wonderful magic with handling 
exceptions... just as you would be with raw DBI) I would say that this 
could be more specific. B-) The following examples in the man page are 
not really helpful for this issue.

Maybe somebody can explain the difference between this:

# with AutoCommit => 0
$schema->txn_do($coderef);
$schema->txn_commit();

...and this...

# with AutoCommit => 1
$schema->txn_do($coderef);

If I get the picture I also volunteer for extending the man page 
of 'DBIC::SQL::Abstract' to get the things more 'straight'.

Thanks for reading and greetings

-- 
So long... Fuzz



More information about the DBIx-Class mailing list