Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: DBI $dbh->rollback() NOT rolling back???

by runrig (Abbot)
on Dec 20, 2010 at 16:42 UTC ( #878051=note: print w/ replies, xml ) Need Help??


in reply to DBI $dbh->rollback() NOT rolling back???

See the CREATE TABLE docs for MySQL. You need to tell MySQL that you want to use the InnoDB engine when you create the table. begin_work/commit/rollback silently do nothing otherwise. To convert the table, you can: ALTER TABLE t1 ENGINE=InnoDB;. Yeah, I was bitten by this also.


Comment on Re: DBI $dbh->rollback() NOT rolling back???
Download Code
Re^2: DBI $dbh->rollback() NOT rolling back???
by puterboy (Scribe) on Dec 20, 2010 at 19:12 UTC

    WOW - thanks!

    Why doesn't this signal an error in the same way that trying to rollback when you have AutoCommit set signals that the rollback is ineffective.

    i.e., why does the rollback command essentially fail silently? Theoretically, even if I create the database right, someone could change it and I would never know that my rollbacks stopped working? Also, I skimmed through lots of official manpages, docs, and examples of rollback but this 'fatal' error was not mentioned.

      You can have a mixture of MyISAM and InnoDB tables in your database, so transactions will only apply to the InnoDB tables. Don't call it "failure", call it a MySQL "feature" :-) (BTW, DBI has nothing to do with it).

      Update: I sense a misunderstanding of the relationship between DBI and the underlying database. DBI "knows" when you have the AutoCommit attribute set or not, so it can warn you when you do commits and rollbacks with AutoCommit unset. DBI doesn't "know" which of your MySQL tables are using the MyISAM or InnoDB engines on every SQL statement, so it can't warn you about that (the DBD::mysql library, with a bunch of extra work, might be made to do that, but it's really too much bother).

        Thanks for helping me understand the difference between the DBI and the SQL db level. You sensed correctly ;) And that explains I guess why it is not mentioned prominently if at all in the main DBI documentation.

        Though it would be helpful if it mentioned that rollback is database dependent (similar to how it mentions that using $sth->rows() before fetching all the rows may or may not work depending on the database)

Re^2: DBI $dbh->rollback() NOT rolling back???
by globularset (Initiate) on Mar 10, 2013 at 00:45 UTC
    Saved me from my hair pulling, thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://878051]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-11-27 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (180 votes), past polls