Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly retrieve the SQL Server database version #1313

Merged
merged 5 commits into from
Mar 20, 2025
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@

- [#1273](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1273) TinyTDS v3+ is now required.

#### Fixed

- [#1313](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1313) Correctly retrieve the SQL Server database version.

Please check [8-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/8-0-stable/CHANGELOG.md) for previous changes.
7 changes: 2 additions & 5 deletions lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,16 @@ def initialize_dateformatter
end

def version_year
@version_year ||= begin
@version_year ||=
if /vNext/.match?(sqlserver_version)
2016
else
/SQL Server (\d+)/.match(sqlserver_version).to_a.last.to_s.to_i
end
rescue
2016
end
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
end

private
Expand Down
8 changes: 8 additions & 0 deletions test/cases/helper_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
require "support/query_assertions"
require "mocha/minitest"

Minitest.after_run do
puts "\n\n"
puts "=" * 80
puts ActiveRecord::Base.lease_connection.send(:sqlserver_version)
puts "\nSQL Server Version Year: #{ActiveRecord::Base.lease_connection.get_database_version}"
puts "=" * 80
end

module ActiveSupport
class TestCase < ::Minitest::Test
include ARTest::SQLServer::CoerceableTest
Expand Down