Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change the savepoint interface to allow passing the name.

  • Loading branch information...
commit 032998ad7460c59916b8268467251d78c6cd18b7 1 parent 47a19eb
@senny senny authored
View
5 activerecord/CHANGELOG.md
@@ -1,3 +1,8 @@
+* `create_savepoint`, `rollback_to_savepoint` and `release_savepoint` accept
+ a savepoint name.
+
+ *Yves Senn*
+
* Make `next_migration_number` accessible for third party generators.
*Yves Senn*
View
6 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -395,13 +395,13 @@ def open_transactions
@transaction.number
end
- def create_savepoint
+ def create_savepoint(name = nil)
end
- def rollback_to_savepoint
+ def rollback_to_savepoint(name = nil)
end
- def release_savepoint
+ def release_savepoint(name = nil)
end
def case_sensitive_modifier(node)
View
12 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -340,16 +340,16 @@ def rollback_db_transaction #:nodoc:
# Transactions aren't supported
end
- def create_savepoint
- execute("SAVEPOINT #{current_savepoint_name}")
+ def create_savepoint(name = current_savepoint_name)
+ execute("SAVEPOINT #{name}")
end
- def rollback_to_savepoint
- execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
+ def rollback_to_savepoint(name = current_savepoint_name)
+ execute("ROLLBACK TO SAVEPOINT #{name}")
end
- def release_savepoint
- execute("RELEASE SAVEPOINT #{current_savepoint_name}")
+ def release_savepoint(name = current_savepoint_name)
+ execute("RELEASE SAVEPOINT #{name}")
end
# In the simple case, MySQL allows us to place JOINs directly into the UPDATE
View
12 activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
@@ -219,16 +219,16 @@ def rollback_db_transaction
execute "ROLLBACK"
end
- def create_savepoint
- execute("SAVEPOINT #{current_savepoint_name}")
+ def create_savepoint(name = current_savepoint_name)
+ execute("SAVEPOINT #{name}")
end
- def rollback_to_savepoint
- execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
+ def rollback_to_savepoint(name = current_savepoint_name)
+ execute("ROLLBACK TO SAVEPOINT #{name}")
end
- def release_savepoint
- execute("RELEASE SAVEPOINT #{current_savepoint_name}")
+ def release_savepoint(name = current_savepoint_name)
+ execute("RELEASE SAVEPOINT #{name}")
end
end
end
View
12 activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -351,16 +351,16 @@ def select_rows(sql, name = nil)
exec_query(sql, name).rows
end
- def create_savepoint
- execute("SAVEPOINT #{current_savepoint_name}")
+ def create_savepoint(name = current_savepoint_name)
+ execute("SAVEPOINT #{name}")
end
- def rollback_to_savepoint
- execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
+ def rollback_to_savepoint(name = current_savepoint_name)
+ execute("ROLLBACK TO SAVEPOINT #{name}")
end
- def release_savepoint
- execute("RELEASE SAVEPOINT #{current_savepoint_name}")
+ def release_savepoint(name = current_savepoint_name)
+ execute("RELEASE SAVEPOINT #{name}")
end
def begin_db_transaction #:nodoc:
View
30 activerecord/test/cases/transactions_test.rb
@@ -375,6 +375,36 @@ def test_many_savepoints
assert_equal "Three", @three
end if Topic.connection.supports_savepoints?
+ def test_using_named_savepoints
+ Topic.transaction do
+ @first.approved = true
+ @first.save!
+ Topic.connection.create_savepoint("first")
+
+ @first.approved = false
+ @first.save!
+ Topic.connection.rollback_to_savepoint("first")
+ assert @first.reload.approved?
+
+ @first.approved = false
+ @first.save!
+ Topic.connection.release_savepoint("first")
+ assert_not @first.reload.approved?
+ end
+ end if Topic.connection.supports_savepoints?
+
+ def test_releasing_named_savepoints
+ Topic.transaction do
+ Topic.connection.create_savepoint("another")
+ Topic.connection.release_savepoint("another")
+
+ # The savepoint is now gone and we can't remove it again.
+ assert_raises(ActiveRecord::StatementInvalid) do
+ Topic.connection.release_savepoint("another")
+ end
+ end
+ end
+
def test_rollback_when_commit_raises
Topic.connection.expects(:begin_db_transaction)
Topic.connection.expects(:commit_db_transaction).raises('OH NOES')
Please sign in to comment.
Something went wrong with that request. Please try again.