Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Apache::DBI , Transactions and Warnings ... Oh my!

by BMaximus (Chaplain)
on Feb 26, 2002 at 13:21 UTC ( [id://147549]=perlquestion: print w/replies, xml ) Need Help??

BMaximus has asked for the wisdom of the Perl Monks concerning the following question:

While working on my site tonight I put in some transactions just to play around with it. Now I have a mixed set of tables in my MySQL database. Some are regular MyISAM tables and some are InnoDB tables, which have the transaction abilities. Now when AutoCommit is set to 0 on the connection to the database. The transaction tables work great. However I come up with an error when a non-transaction table is worked on.
DBD::mysql::db rollback failed: Warning: Some non-transactional chang +ed tables couldn't be rolled back at /usr/lib/perl5/site_perl/5.6.1/A +pache/DBI.pm line 153.
now since Apache::DBI basically overloads DBI to create a connection pool. Here is the code around line 153 on Apache::DBI.
# The PerlCleanupHandler is supposed to initiate a rollback after the +script has finished if AutoCommit is off. # Note: the PerlCleanupHandler runs after the response has been sent t +o the client sub cleanup { my $prefix = "$$ Apache::DBI "; print STDERR "$prefix PerlCleanupHandler \n" if $Apache::DBI::DEBU +G > 1; my $dbh = $Connected{$Idx}; if ($Rollback{$Idx} and $dbh and $dbh->{Active} and !$dbh->{AutoCo +mmit} and eval {$dbh->rollback}) { print STDERR "$prefix PerlCleanupHandler rollback for $Idx \n" + if $Apache::DBI::DEBUG > 1; } delete $Rollback{$Idx}; 1; }

line 153 has eval {$dbh->rollback} which executes whenever AutoCommit is set to 0. Isn't DBI supposed to be told by MySQL whether the table is a transaction based table or not? I've gotten around the warning by setting $dbi->{AutoCommit} to 1 in the non-transaction section of the code that communicates with the DB. However I believe that this is a kludgy way of doing it and it should be handled in DBI somewhere/somehow. In any case, I thought MySQL sets AutoCommit according to the table being accesed by type. Could this be a bug in Apache::DBI or Apache::DBI breaking something on DBI?

BMaximus

Replies are listed 'Best First'.
Re: Apache::DBI , Transactions and Warnings ... Oh my!
by lachoy (Parson) on Feb 26, 2002 at 13:39 UTC

    How could DBI or MySQL even know whether the affected tables are transaction based? What if you mixed them up in your transaction?

    $dbh->do( "INSERT INTO nontrans VALUES ( 'hi' )" ); $dbh->do( "UPDATE trans SET name = 'hey' WHERE id = 4" ); $dbh->commit;

    How could either MySQL or DBI deal with this? It's probably a good idea to create two separate connections: one for transactions, one for non-transactions. And is it a good idea to even mix transaction and non-transactional tables in a database? This seems ripe for mistakes to me... but I haven't used transactions in MySQL before, so maybe this is recommended behavior?

    Chris
    M-x auto-bs-mode

Re: Apache::DBI , Transactions and Warnings ... Oh my!
by perrin (Chancellor) on Feb 26, 2002 at 15:58 UTC
    Apache::DBI does that in case your program crashes with some uncomitted changes active. It's a good thing. That warning can probably be turned off somehow at the MySQL level.
Re: Apache::DBI , Transactions and Warnings ... Oh my!
by zakzebrowski (Curate) on May 03, 2004 at 13:25 UTC
    Mysql on a non-transactional table can't rollback anything, so anytime it sees that issued on a non-rollback table, the transaction is lost and it always gives that warning. DBI was not designed explicitly for certain databases, so it's a feature I believe you have to live with (if you can't modify the mysql configuration which may have an option to turn the warning off... i don't thinks so though.)


    ----
    Zak - the office

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://147549]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-24 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found