Skip to content

Commit cbf4ff5

Browse files
committed
Add 2008 support in raw form.
1 parent d4f58d4 commit cbf4ff5

File tree

8 files changed

+25
-14
lines changed

8 files changed

+25
-14
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class SQLServerAdapter < AbstractAdapter
181181
ADAPTER_NAME = 'SQLServer'.freeze
182182
VERSION = '2.2.17'.freeze
183183
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
184-
SUPPORTED_VERSIONS = [2000,2005].freeze
184+
SUPPORTED_VERSIONS = [2000,2005,2008].freeze
185185
LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
186186

187187
LOST_CONNECTION_EXCEPTIONS = [DBI::DatabaseError, DBI::InterfaceError]
@@ -250,6 +250,10 @@ def sqlserver_2005?
250250
database_year == 2005
251251
end
252252

253+
def sqlserver_2008?
254+
database_year == 2008
255+
end
256+
253257
def version
254258
self.class::VERSION
255259
end
@@ -276,7 +280,7 @@ def native_text_database_type
276280
end
277281

278282
def native_binary_database_type
279-
@@native_binary_database_type || (sqlserver_2005? ? 'varbinary(max)' : 'image')
283+
@@native_binary_database_type || ((sqlserver_2005? || sqlserver_2008?) ? 'varbinary(max)' : 'image')
280284
end
281285

282286
# QUOTING ==================================================#

test/cases/adapter_test_sqlserver.rb

Lines changed: 6 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_2000_string = "Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)"
6161
@sqlserver_2005_string = "Microsoft SQL Server 2005 - 9.00.3215.00 (Intel X86)"
62+
@sqlserver_2008_string = "Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)"
6263
end
6364

6465
should 'return a string from #database_version that matches class regexp' do
@@ -80,6 +81,11 @@ def setup
8081
assert @connection.sqlserver_2005?
8182
end
8283

84+
should 'return true to #sqlserver_2008?' do
85+
@connection.stubs(:database_version).returns(@sqlserver_2008_string)
86+
assert @connection.sqlserver_2008?
87+
end
88+
8389
end
8490

8591
context 'for #unqualify_table_name and #unqualify_db_name' do

test/cases/column_test_sqlserver.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def setup
6666
should 'have correct simplified types' do
6767
assert_equal :string, @char.type
6868
assert_equal :string, @char10.type
69-
if sqlserver_2005?
69+
if sqlserver_2005? || sqlserver_2008?
7070
assert_equal :text, @varcharmax.type, @varcharmax.inspect
7171
assert_equal :text, @varcharmax10.type, @varcharmax10.inspect
7272
end
@@ -75,7 +75,7 @@ def setup
7575
should 'have correct #sql_type per schema definition' do
7676
assert_equal 'char(1)', @char.sql_type, 'Specifing a char type with no limit is 1 by SQL Server standards.'
7777
assert_equal 'char(10)', @char10.sql_type, @char10.inspect
78-
if sqlserver_2005?
78+
if sqlserver_2005? || sqlserver_2008?
7979
assert_equal 'varchar(max)', @varcharmax.sql_type, 'A -1 limit should be converted to max (max) type.'
8080
assert_equal 'varchar(max)', @varcharmax10.sql_type, 'A -1 limit should be converted to max (max) type.'
8181
end
@@ -84,7 +84,7 @@ def setup
8484
should 'have correct #limit per schema definition' do
8585
assert_equal 1, @char.limit
8686
assert_equal 10, @char10.limit
87-
if sqlserver_2005?
87+
if sqlserver_2005? || sqlserver_2008?
8888
assert_equal nil, @varcharmax.limit, 'Limits on max types are moot and we should let rails know that.'
8989
assert_equal nil, @varcharmax10.limit, 'Limits on max types are moot and we should let rails know that.'
9090
end
@@ -119,7 +119,7 @@ def setup
119119
assert_equal :text, @ntext10.type
120120
assert_equal :string, @nchar10.type
121121
assert_equal :string, @nvarchar100.type
122-
if sqlserver_2005?
122+
if sqlserver_2005? || sqlserver_2008?
123123
assert_equal :text, @nvarcharmax.type, @nvarcharmax.inspect
124124
assert_equal :text, @nvarcharmax10.type, @nvarcharmax10.inspect
125125
end
@@ -132,7 +132,7 @@ def setup
132132
assert_equal 'ntext', @ntext10.sql_type, 'Even a next with a limit of 10 specified will mean nothing.'
133133
assert_equal 'nchar(10)', @nchar10.sql_type, 'An nchar with a limit of 10 needs to have it show up here.'
134134
assert_equal 'nvarchar(100)', @nvarchar100.sql_type, 'An nvarchar with a specified limit of 100 needs to show it.'
135-
if sqlserver_2005?
135+
if sqlserver_2005? || sqlserver_2008?
136136
assert_equal 'nvarchar(max)', @nvarcharmax.sql_type, 'A -1 limit should be converted to max (max) type.'
137137
assert_equal 'nvarchar(max)', @nvarcharmax10.sql_type, 'A -1 limit should be converted to max (max) type.'
138138
end
@@ -144,7 +144,7 @@ def setup
144144
assert_equal nil, @ntext.limit, 'An ntext column limit is moot, it is a fixed variable length'
145145
assert_equal 10, @nchar10.limit
146146
assert_equal 100, @nvarchar100.limit
147-
if sqlserver_2005?
147+
if sqlserver_2005? || sqlserver_2008?
148148
assert_equal nil, @nvarcharmax.limit, 'Limits on max types are moot and we should let rails know that.'
149149
assert_equal nil, @nvarcharmax10.limit, 'Limits on max types are moot and we should let rails know that.'
150150
end

test/cases/execute_procedure_test_sqlserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def setup
2323
should 'quote bind vars correctly' do
2424
assert_sql(/EXEC sp_tables '%sql_server%', NULL, NULL, NULL, 1/) do
2525
@klass.execute_procedure :sp_tables, '%sql_server%', nil, nil, nil, true
26-
end if sqlserver_2005?
26+
end if sqlserver_2005? || sqlserver_2008?
2727
assert_sql(/EXEC sp_tables '%sql_server%', NULL, NULL, NULL/) do
2828
@klass.execute_procedure :sp_tables, '%sql_server%', nil, nil, nil
2929
end if sqlserver_2000?

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SchemaDumperTestSqlserver < ActiveRecord::TestCase
4141
table_dump('sql_server_strings') do |output|
4242
assert_match %r{t.text.*varchar_max}, output
4343
end
44-
end
44+
end if sqlserver_2005? || sqlserver_2008?
4545

4646
end
4747

test/cases/sqlserver_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class TestCase < ActiveSupport::TestCase
9696
class << self
9797
def sqlserver_2000? ; ActiveRecord::Base.connection.sqlserver_2000? ; end
9898
def sqlserver_2005? ; ActiveRecord::Base.connection.sqlserver_2005? ; end
99+
def sqlserver_2008? ; ActiveRecord::Base.connection.sqlserver_2008? ; end
99100
def active_record_2_point_2? ; ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 2 ; end
100101
def active_record_2_point_3? ; ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 3 ; end
101102
def ruby_19? ; RUBY_VERSION >= '1.9' ; end
@@ -112,6 +113,7 @@ def assert_sql(*patterns_to_match)
112113
end
113114
def sqlserver_2000? ; self.class.sqlserver_2000? ; end
114115
def sqlserver_2005? ; self.class.sqlserver_2005? ; end
116+
def sqlserver_2008? ; self.class.sqlserver_2008? ; end
115117
def active_record_2_point_2? ; self.class.active_record_2_point_2? ; end
116118
def active_record_2_point_3? ; self.class.active_record_2_point_3? ; end
117119
def ruby_19? ; self.class.ruby_19? ; end

test/cases/unicode_test_sqlserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class UnicodeTestSqlserver < ActiveRecord::TestCase
1414
test_string = 'Ken Collins'
1515
assert nvarcharmax_data = SqlServerUnicode.create!(:nvarchar_max => test_string)
1616
assert_equal test_string, SqlServerUnicode.find(nvarcharmax_data.id).nvarchar_max
17-
end if sqlserver_2005?
17+
end if sqlserver_2005? || sqlserver_2008?
1818

1919
should 'enforce default nchar_10 limit of 10' do
2020
assert_raise(ActiveRecord::StatementInvalid) { SqlServerUnicode.create!(:nchar => '01234567891') }

test/schema/sqlserver_specific_schema.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
create_table :table_with_real_columns, :force => true do |t|
44
t.column :real_number, :real
5-
# t.column :varchar_max, :varchar_max if ActiveRecord::Base.connection.sqlserver_2005?
65
end
76

87
create_table :defaults, :force => true do |t|
@@ -44,7 +43,7 @@
4443
t.column :ntext_10, :ntext, :limit => 10
4544
t.column :nchar_10, :nchar, :limit => 10
4645
t.column :nvarchar_100, :nvarchar, :limit => 100
47-
if ActiveRecord::Base.connection.sqlserver_2005?
46+
if ActiveRecord::Base.connection.sqlserver_2005? || ActiveRecord::Base.connection.sqlserver_2008?
4847
t.column :nvarchar_max, :nvarchar_max
4948
t.column :nvarchar_max_10, :nvarchar_max, :limit => 10
5049
end
@@ -53,7 +52,7 @@
5352
create_table :sql_server_strings, :force => true do |t|
5453
t.column :char, :char
5554
t.column :char_10, :char, :limit => 10
56-
if ActiveRecord::Base.connection.sqlserver_2005?
55+
if ActiveRecord::Base.connection.sqlserver_2005? || ActiveRecord::Base.connection.sqlserver_2008?
5756
t.column :varchar_max, :varchar_max
5857
t.column :varchar_max_10, :varchar_max, :limit => 10
5958
end

0 commit comments

Comments
 (0)