List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:January 13 2003 5:56pm
Subject:Re: Using tranzactions in Perl
View as plain text  
At 12:59 +0200 1/13/03, Octavian Rasnita wrote:
>Hi all,
>
>I've seen the following code in MySQL cookbook:
>
>  eval
>  {
>      # move some money from one person to the other
>      $dbh->do ("UPDATE money SET amt = amt - 6 WHERE name = 'Eve'");
>      $dbh->do ("UPDATE money SET amt = amt + 6 WHERE name = 'Ida'");
>      # all statements succeeded; commit transaction
>      $dbh->commit ( );
>  };
>
>  if ($@) # an error occurred
>  {
>      print "Transaction failed, rolling back. Error was:\n$@\n";
>      # roll back within eval to prevent rollback
>      # failure from terminating the script
>      eval { $dbh->rollback ( ); };
>  }
>
>---
>
>Well, I don't understand why I need to check if $@ is true or false.
>If there wasn't any error, and the program should not rollback, in fact it
>could give the rollback command because it won't produce any effect after
>the commit command was given.
>
>Am I wrong?


That's true, but don't you think it's a little confusing to write
code that issues a rollback back after a successful transaction?

It's also an additional statement that in that case is unnecessary
to issue, so what you suggest would be less efficient.

>
>
>Teddy,
>Teddy's Center: http://teddy.fcc.ro/
>Email: orasnita@stripped

Thread
Using tranzactions in PerlOctavian Rasnita13 Jan
  • Re: Using tranzactions in PerlPaul DuBois13 Jan