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

Dear Monks,

I've been trying to turn off AutoCommit without succes so far
Here is what I did:
$dbh = DBI->connect($dbc, $root, $passwd, {AutoCommit => 0, PrintError + => 0}) ; print "status=".$dbh->{AutoCommit}."\n" ;
But the result is:
status=1
Any suggestions to set AutoCommit to zero ??

Thanks in advance
Luca

Replies are listed 'Best First'.
Re: turning off Autocommit (MySql)
by tirwhan (Abbot) on Nov 11, 2005 at 12:19 UTC

    From perldoc DBD::mysql:

    o Switching AutoCommit mode from on to off or vice versa may fail. +You should always check for errors, when changing AutoCommit mode. T +he suggested way of doing so is using the DBI flag RaiseError. If yo +u don't like RaiseError, you have to use code like the following: $dbh->{'AutoCommit'} = 0; if ($dbh->{'AutoCommit'}) { # An error occurred! }

    I'd suggest you set RaiseError and see whether there's an error message which gives you a clue on what's happening.


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
      Code snippet:
      $dbh = DBI->connect($dbc, $root, $passwd, {AutoCommit => 0, RaiseError + => 1}) ; $dbh->{'AutoCommit'} $dbh->{'AutoCommit'} = 0; if ($dbh->{'AutoCommit'}) { print "An error occurred!\n" ; } print "status=".$dbh->{'AutoCommit'}."\n" ;
      Output is:status=
      And it didn't rollback the creation of a database....
      How can I check if this options is enabled by MySql (version is 4.1.14) ?

      Luca

        Your output looks fine, AutoCommit is turned off (otherwise you'd get "An error occurred" output as well as a 1). I don't think database creations can be rolled back though. If alone for the fact that transaction support in MySQL depends on the table type of the database (InnoDB supports transactions, MyISAM doesn't). Try issuing insert/select statements and rolling them back explicitly (or just disconnect without commit) and see what happens.


        Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
Re: turning off Autocommit (MySql)
by borisz (Canon) on Nov 11, 2005 at 12:15 UTC
    $dbh->{AutoCommit} = 0;
    But maybe your database did not support transactions.
    Boris
Re: turning off Autocommit (MySql)
by jimbus (Friar) on Nov 11, 2005 at 13:22 UTC
    Check the MySQL docs, as I recall, MySQL doesn't support rollbacks and everything is auto-commited. It's been a while since I've read up on this, but I think thats one of the big attractions for 5.0
    Never moon a werewolf!