List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 25 2001 12:42pm
Subject:Re: transactions
View as plain text  
At 3:40 PM +0400 6/25/01, Ilya Martynov wrote:
>  > Hello All,
>>  I'm current working on project, converting a flatfile system, to use MySQL,
>>  which supports transactions w/Innobase tables. My questions is, as 
>>I'm sure many
>>  have coded using transaction w/Perl and DBI. I understand that there as some
>>  draw backs to using transactions when not necessary, but very 
>>beneficial, when
>>  needed. What are some good guide lines or "rule of thumb" to following when
>>  using transactions type tables?
>
>This is from 'man DBI'. I don't think I can add anything to it:

There was some discussion on the DBI list recently on this topic that
indicated that under some conditions having PrintError enabled could
result in the transaction being committed when an error occurred.  I
haven't observed that to happen myself, but to avoid the problem,
it may be prudent to add this to the two lines preceding the eval:

$dbh->{PrintError} = 0;


>
>        The recommended way to implement robust transactions in
>        Perl applications is to use `RaiseError' and
>        `eval { ... }' (which is very fast, unlike `eval "..."').
>        For example:
>
>          $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
>          }
>
>--
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>| 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/)                          |
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


-- 
Paul DuBois, paul@stripped
Thread
transactionsMike<mickalo>Blezien23 Jun
  • Re: transactionsIlya Martynov25 Jun
    • Re: transactionsPaul DuBois25 Jun
      • Re: transactionsMike<mickalo>Blezien25 Jun
    • can I force SELECT to use a specified INDEX?Jaime Teng25 Jun
  • Re: transactionsDaniel Ã…kerud25 Jun