Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15. Performing Transactions > Using Transactions in Ruby Programs - Pg. 642

} $dbh->{RaiseError} = $attr_ref->{RaiseError}; By using those two functions, our sample transaction can be simplified considerably: $ref = transaction_init ($dbh); 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 (); }; transaction_finish ($dbh, $ref, $@); In Perl DBI, an alternative to manipulating the AutoCommit attribute manually is to begin a transaction by invoking begin_work() . This method disables AutoCommit and causes it to be enabled again automatically when you invoke commit() or rollback() later. 15.5 Using Transactions in Ruby Programs Problem You want to perform a transaction in a Ruby DBI script.