List:General Discussion« Previous MessageNext Message »
From:Ilya Martynov Date:June 19 2001 11:14am
Subject:Re: begin and commit w/ perl
View as plain text  
r> When begining and commiting a transaction using perl and DBI, does the
r> commit need to come from the same statement handle as the begin or does it
r> just need to be from the same database connection handle?

If you are using DBI for transactions you should have something like:

         $dbh->{AutoCommit} = 0;  # enable transactions, if possible
         $dbh->{RaiseError} = 1;
         eval {
             foo(...)        # do lots of work here
             bar(...)        # including inserts
             baz(...)        # and updates
             $dbh->commit;   # commit the changes if we get this far
         };
         if ($@) {
             warn "Transaction aborted because $@";
             $dbh->rollback; # undo the incomplete changes
             # add other application on-error-clean-up code here
         }

Sample have been taken right from 'perldoc DBI'. Read section
'Transaction' there for more info.

P.S. Be sure that you have latest version of Msql-Mysql-modules
(version 1.2216). Previous versions does not support transactions.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Thread
begin and commit w/ perlryc19 Jun
  • Re: begin and commit w/ perlIlya Martynov19 Jun