Skip to content
Closed
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## v7.1.11
## Unreleased

#### Fixed

Correctly retrieve the SQL Server database version.

#### Fixed

Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def version_year
end

def sqlserver_version
@sqlserver_version ||= _raw_select("SELECT @@version", @raw_connection).first.first.to_s
@sqlserver_version ||= execute("SELECT @@version", "SCHEMA").rows.first.first.to_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK execute("SELECT @@version", "SCHEMA") will just return the number of rows affected as an integer. It won't return rows of data. I think the fix for 7.1 will be different than what is in main.

end

private
Expand Down
10 changes: 10 additions & 0 deletions test/cases/adapter_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
end
end

it 'test proper connection before fetching sqlserver_version'
connection.disconnect!

assert_nothing_raised do
version = connection.sqlserver_version
assert version.is_a?(String)
assert version.length > 0
end
end

describe "with different language" do
before do
@default_language = connection.user_options_language
Expand Down
Loading