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

Re: DBI AutoCommit clarification

by gmax (Abbot)
on Sep 18, 2003 at 17:49 UTC ( #292471=note: print w/replies, xml ) Need Help??


in reply to DBI AutoCommit clarification

What the book says exactly is (pag. 159) :

Connect to the database with transactions and error handling enabled.

What this comment means is that, having AutoCommit disabled, you can use transactions, where you use begin, commit, or rollback.

When Autocommit is on, instead, every statement is automatically committed, and therefore transactions are disabled, i.e. you can't rollback.

_ _ _ _ (_|| | |(_|>< _|

Replies are listed 'Best First'.
Re: Re: DBI AutoCommit clarification
by mpeppler (Vicar) on Sep 18, 2003 at 17:57 UTC
    When Autocommit is on, instead, every statement is automatically committed, and therefore transactions are disabled, i.e. you can't rollback.
    This is mostly correct. However, with MS-SQL and Sybase (and possibly others) you can still use transactions by explicitly issuing BEGIN TRAN requests in do() and/or prepare() requests.

    Michael

      And then there is always the $dbh->begin_work() method, but I don't know how many drivers support it at this time; I know that neither DBD::mysql nor DBD::Pg support it right now. Oracle?

      The nice thing about  $dbh->begin_work() over local($dbh->{AutoCommit}) = 0; is that $dbh->begin_work() will not automatically commit on exiting scope which could be a bad thing if you missed catching an exception or forgot to rollback in the exception handler.

        If you check the DBI sources, begin_work() is nothing more than $dbh->{AutoCommit} = 0;...

        The nice thing about $dbh->begin_work() over local($dbh->{AutoCommit}) = 0; is that $dbh->begin_work() will not automatically commit on exiting scope...
        That's a good point. My first reaction was that no driver should do that, but then I looked at my sources and realized that DBD::Sybase does indeed commit silently when AutoCommit is turned back on. I'm not sure that I like that behavior - I should probably issue a message about un-committed work at that point - if you have AutoCommit turned off you should really be forced to explicitly commit or rollback any changes, and just flipping AutoCommit back on isn't the same thing.

        Michael

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2022-12-06 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?