Skip to content

Commit

Permalink
Savepoint queries should be internally executed so that they don't cl…
Browse files Browse the repository at this point in the history
…ear the query cache
  • Loading branch information
aidanharan committed Oct 7, 2023
1 parent ca76dc0 commit 90604da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,6 @@ def exec_rollback_db_transaction
execute "IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION", "TRANSACTION"
end

include Savepoints

def create_savepoint(name = current_savepoint_name)
execute "SAVE TRANSACTION #{name}", "TRANSACTION"
end

def exec_rollback_to_savepoint(name = current_savepoint_name)
execute "ROLLBACK TRANSACTION #{name}", "TRANSACTION"
end

def release_savepoint(name = current_savepoint_name)
end

def case_sensitive_comparison(attribute, value)
column = column_for_attribute(attribute)

Expand Down
24 changes: 24 additions & 0 deletions lib/active_record/connection_adapters/sqlserver/savepoints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module ActiveRecord
module ConnectionAdapters
module SQLServer
module Savepoints
def current_savepoint_name
current_transaction.savepoint_name
end

def create_savepoint(name = current_savepoint_name)
internal_execute("SAVE TRANSACTION #{name}", "TRANSACTION")
end

def exec_rollback_to_savepoint(name = current_savepoint_name)
internal_execute("ROLLBACK TRANSACTION #{name}", "TRANSACTION")
end

def release_savepoint(_name)
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require "active_record/connection_adapters/sqlserver/database_limits"
require "active_record/connection_adapters/sqlserver/database_statements"
require "active_record/connection_adapters/sqlserver/database_tasks"
require "active_record/connection_adapters/sqlserver/savepoints"
require "active_record/connection_adapters/sqlserver/transaction"
require "active_record/connection_adapters/sqlserver/errors"
require "active_record/connection_adapters/sqlserver/schema_creation"
Expand All @@ -40,7 +41,8 @@ class SQLServerAdapter < AbstractAdapter
SQLServer::Showplan,
SQLServer::SchemaStatements,
SQLServer::DatabaseLimits,
SQLServer::DatabaseTasks
SQLServer::DatabaseTasks,
SQLServer::Savepoints

ADAPTER_NAME = "SQLServer".freeze

Expand Down

0 comments on commit 90604da

Please sign in to comment.