Skip to content

Commit

Permalink
Allow AbstractAdapter to detect sqlserver connection
Browse files Browse the repository at this point in the history
Allow AbstractAdapter to detect sqlserver connection
  • Loading branch information
aovertus committed Oct 11, 2023
1 parent d1a3b1d commit 324850a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module ActiveRecord
module ConnectionAdapters
module SQLServer
module CoreExt
module AbstractAdapter
def sqlserver?
false
end
end
end
end
end
end

ActiveSupport.on_load(:active_record) do
mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::AbstractAdapter
ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(mod)
end
10 changes: 4 additions & 6 deletions lib/active_record/connection_adapters/sqlserver/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
module ActiveRecord
module ConnectionAdapters
module SQLServerTransaction
private
delegate :sqlserver?, to: :connection, prefix: true

def sqlserver?
connection.respond_to?(:sqlserver?) && connection.sqlserver?
end
private

def current_isolation_level
return unless sqlserver?
return unless connection_sqlserver?

level = connection.user_options_isolation_level
# When READ_COMMITTED_SNAPSHOT is set to ON,
Expand Down Expand Up @@ -50,7 +48,7 @@ def rollback
private

def reset_starting_isolation_level
if sqlserver? && starting_isolation_level
if connection_sqlserver? && starting_isolation_level
connection.set_transaction_isolation_level(starting_isolation_level)
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require "active_record/connection_adapters/sqlserver/core_ext/attribute_methods"
require "active_record/connection_adapters/sqlserver/core_ext/finder_methods"
require "active_record/connection_adapters/sqlserver/core_ext/preloader"
require "active_record/connection_adapters/sqlserver/core_ext/abstract_adapter"
require "active_record/connection_adapters/sqlserver/version"
require "active_record/connection_adapters/sqlserver/type"
require "active_record/connection_adapters/sqlserver/database_limits"
Expand Down Expand Up @@ -100,7 +101,7 @@ def initialize(...)
super

@config[:tds_version] = "7.3" unless @config[:tds_version]
@config[:appname] = rails_application_name unless @config[:appname]
@config[:appname] = self.class.rails_application_name unless @config[:appname]
@config[:login_timeout] = @config[:login_timeout].present? ? @config[:login_timeout].to_i : nil
@config[:timeout] = @config[:timeout].present? ? @config[:timeout].to_i / 1000 : nil
@config[:encoding] = @config[:encoding].present? ? @config[:encoding] : nil
Expand Down

0 comments on commit 324850a

Please sign in to comment.