Skip to content

Commit 0d34b79

Browse files
committed
Start to support 2011 code named "Denali".
1 parent 08e95a6 commit 0d34b79

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
* master *
33

4+
* Start to support 2011 code named "Denali".
5+
46
* Limit and Offset can take SqlLiteral objects now.
57

68

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class SQLServerAdapter < AbstractAdapter
165165

166166
ADAPTER_NAME = 'SQLServer'.freeze
167167
VERSION = '3.0.9'.freeze
168-
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
169-
SUPPORTED_VERSIONS = [2005,2008].freeze
168+
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
169+
SUPPORTED_VERSIONS = [2005,2008,2011].freeze
170170

171171
attr_reader :database_version, :database_year,
172172
:connection_supports_native_types
@@ -180,11 +180,16 @@ def initialize(logger,config)
180180
connect
181181
super(@connection, logger)
182182
@database_version = info_schema_query { select_value('SELECT @@version') }
183-
@database_year = DATABASE_VERSION_REGEXP.match(@database_version)[1].to_i rescue 0
183+
@database_year = begin
184+
year = DATABASE_VERSION_REGEXP.match(@database_version)[1]
185+
year == "Denali" ? 2011 : year.to_i
186+
rescue
187+
0
188+
end
184189
initialize_sqlserver_caches
185190
use_database
186191
unless SUPPORTED_VERSIONS.include?(@database_year)
187-
raise NotImplementedError, "Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported."
192+
raise NotImplementedError, "Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported. We got back #{@database_version}."
188193
end
189194
end
190195

@@ -285,6 +290,10 @@ def sqlserver_2008?
285290
@database_year == 2008
286291
end
287292

293+
def sqlserver_2011?
294+
@database_year == 2011
295+
end
296+
288297
def version
289298
self.class::VERSION
290299
end

test/cases/adapter_test_sqlserver.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def setup
5959
@supported_version = ActiveRecord::ConnectionAdapters::SQLServerAdapter::SUPPORTED_VERSIONS
6060
@sqlserver_2005_string = "Microsoft SQL Server 2005 - 9.00.3215.00 (Intel X86)"
6161
@sqlserver_2008_string = "Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)"
62+
@sqlserver_2011_string1 = %|Microsoft SQL Server "Denali" (CTP1) - 11.0.1103.9 (Intel X86) Sep 24 2010 22:02:43 Copyright (c) Microsoft Corporation Enterprise Evaluation Edition on Windows NT 6.0 (Build 6002: Service Pack 2)|
6263
end
6364

6465
should 'return a string from #database_version that matches class regexp' do
@@ -70,6 +71,10 @@ def setup
7071
assert_contains @supported_version, @connection.database_year
7172
end
7273

74+
should 'return a code name if year not available' do
75+
assert_equal "Denali", @version_regexp.match(@sqlserver_2011_string1)[1]
76+
end
77+
7378
end
7479

7580
context 'for #unqualify_table_name and #unqualify_db_name' do

0 commit comments

Comments
 (0)