diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-09-28 18:53:22 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-09-28 18:53:22 +0000 |
commit | fc83920383b5f839cd6badbc5c962be9383fe150 (patch) | |
tree | 6372da579fa303aa5f15cdd0908d8e9197e8435a /activerecord/lib/active_record | |
parent | 0d07152aab40da70ad87e0e652931812a80d7bcc (diff) | |
download | rails-fc83920383b5f839cd6badbc5c962be9383fe150.tar.gz rails-fc83920383b5f839cd6badbc5c962be9383fe150.tar.bz2 rails-fc83920383b5f839cd6badbc5c962be9383fe150.zip |
Fix transactions so that calling return while inside a transaction will not leave an open transaction on the connection.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2398 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 809424c078..febc702922 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -39,17 +39,20 @@ module ActiveRecord # Wrap a block in a transaction. Returns result of block. def transaction(start_db_transaction = true) + needs_commit = false begin if block_given? begin_db_transaction if start_db_transaction - result = yield - commit_db_transaction if start_db_transaction - result + needs_commit = start_db_transaction + yield end rescue Exception => database_transaction_rollback rollback_db_transaction if start_db_transaction + needs_commit = false raise end + ensure + commit_db_transaction if needs_commit end # Begins the transaction (and turns off auto-committing). @@ -81,4 +84,4 @@ module ActiveRecord end end end -end
\ No newline at end of file +end |