Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -176,7 +176,7 @@ class SQLServerAdapter < AbstractAdapter
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze

attr_reader :database_version, :database_year
attr_reader :database_version, :database_year, :spid

cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type,
:log_info_schema_queries, :enable_default_unicode_types, :auto_connect,
Expand Down Expand Up @@ -269,6 +269,7 @@ def reconnect!
end

def disconnect!
@spid = nil
case @connection_options[:mode]
when :dblib
@connection.close rescue nil
Expand Down Expand Up @@ -399,6 +400,7 @@ def connect
:encoding => encoding,
:azure => config[:azure]
}).tap do |client|
@spid = client.execute("SELECT @@spid").first.values.first
if config[:azure]
client.execute("SET ANSI_NULLS ON").do
client.execute("SET CURSOR_CLOSE_ON_COMMIT OFF").do
Expand Down
12 changes: 11 additions & 1 deletion test/cases/connection_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def setup
@connection = ActiveRecord::Base.connection
end


should 'affect rows' do
topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
updated = Topic.update(topic_data.keys, topic_data.values)
Expand Down Expand Up @@ -93,6 +92,17 @@ def setup
assert @connection.active?
end

if connection_mode_dblib?
should 'set spid on connect' do
assert @connection.spid.kind_of?(Fixnum)
end

should 'reset spid on disconnect!' do
@connection.disconnect!
assert @connection.spid.nil?
end
end

should 'be able to disconnect and reconnect at will' do
@connection.disconnect!
assert !@connection.active?
Expand Down