Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial checkin of 2008 support

  • Loading branch information...
commit d5ef69ee850b1441c92380dfe3806d6fa1a95011 1 parent e319916
Zak & Chad authored
View
18 lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -152,10 +152,10 @@ class SQLServerAdapter < AbstractAdapter
ADAPTER_NAME = 'SQLServer'.freeze
VERSION = '2.2.13'.freeze
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
- SUPPORTED_VERSIONS = [2000,2005].freeze
+ SUPPORTED_VERSIONS = [2000, 2005, 2008].freeze
LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
- cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type,
+ cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type, :native_date_database_type,
:log_info_schema_queries, :enable_default_unicode_types
class << self
@@ -209,6 +209,10 @@ def sqlserver_2005?
database_year == 2005
end
+ def sqlserver_2008?
+ database_year == 2008
+ end
+
def version
self.class::VERSION
end
@@ -223,7 +227,7 @@ def native_string_database_type
def native_text_database_type
@@native_text_database_type ||
- if sqlserver_2005?
+ if sqlserver_2005? || sqlserver_2008?
enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)'
else
enable_default_unicode_types ? 'ntext' : 'text'
@@ -231,7 +235,11 @@ def native_text_database_type
end
def native_binary_database_type
- @@native_binary_database_type || (sqlserver_2005? ? 'varbinary(max)' : 'image')
+ @@native_binary_database_type || ((sqlserver_2005? || sqlserver_2008?) ? 'varbinary(max)' : 'image')
+ end
+
+ def native_date_database_type
+ @@native_date_database_type || (sqlserver_2008? ? 'date' : 'datetime')
end
# QUOTING ==================================================#
@@ -452,7 +460,7 @@ def native_database_types
:datetime => { :name => "datetime" },
:timestamp => { :name => "datetime" },
:time => { :name => "datetime" },
- :date => { :name => "datetime" },
+ :date => { :name => native_date_database_type },
:binary => { :name => native_binary_database_type },
:boolean => { :name => "bit"},
# These are custom types that may move somewhere else for good schema_dumper.rb hacking to output them.
View
8 test/cases/adapter_test_sqlserver.rb
@@ -284,6 +284,7 @@ def setup
should 'truncate 3001 usec to just 003 in the DB cast back to 3000' do
@time.stubs(:usec).returns(3001)
saved = SqlServerChronic.create!(:datetime => @time).reload
+
assert_equal '003', saved.datetime_before_type_cast.split('.')[1]
assert_equal 3000, saved.datetime.usec
end
@@ -554,8 +555,11 @@ def setup
end
should 'using alternate view defintion still be able to find real default' do
- assert_equal 'null', StringDefaultsBigView.new.pretend_null,
- StringDefaultsBigView.columns_hash['pretend_null'].inspect
+ if sqlserver_2008?
+ assert_equal nil, StringDefaultsBigView.new.pretend_null, StringDefaultsBigView.columns_hash['pretend_null'].inspect
+ else
+ assert_equal 'null', StringDefaultsBigView.new.pretend_null, StringDefaultsBigView.columns_hash['pretend_null'].inspect
+ end
end
end
View
3  test/cases/sqlserver_helper.rb
@@ -25,6 +25,7 @@ class StringDefaultsBigView < ActiveRecord::Base ; self.table_name = 'string_def
class SqlServerUnicode < ActiveRecord::Base ; end
class SqlServerString < ActiveRecord::Base ; end
class SqlServerChronic < ActiveRecord::Base
+ # Disable next line only in 2008 models
coerce_sqlserver_date :date
coerce_sqlserver_time :time
default_timezone = :utc
@@ -94,6 +95,7 @@ class TestCase < ActiveSupport::TestCase
class << self
def sqlserver_2000? ; ActiveRecord::Base.connection.sqlserver_2000? ; end
def sqlserver_2005? ; ActiveRecord::Base.connection.sqlserver_2005? ; end
+ def sqlserver_2008? ; ActiveRecord::Base.connection.sqlserver_2008? ; end
end
def assert_sql(*patterns_to_match)
$queries_executed = []
@@ -107,6 +109,7 @@ def assert_sql(*patterns_to_match)
end
def sqlserver_2000? ; self.class.sqlserver_2000? ; end
def sqlserver_2005? ; self.class.sqlserver_2005? ; end
+ def sqlserver_2008? ; self.class.sqlserver_2008? ; end
end
end
View
8 test/connections/native_sqlserver_odbc/connection.rb
@@ -8,16 +8,12 @@
'arunit' => {
:adapter => 'sqlserver',
:mode => 'ODBC',
- :host => 'localhost',
- :username => 'rails',
- :dsn => 'activerecord_unittest'
+ :dsn => 'DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=172.16.132.128;DATABASE=activerecord_unittest;Port=1433;uid=rails;pwd=;'
},
'arunit2' => {
:adapter => 'sqlserver',
:mode => 'ODBC',
- :host => 'localhost',
- :username => 'rails',
- :dsn => 'activerecord_unittest2'
+ :dsn => 'DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=172.16.132.128;DATABASE=activerecord_unittest2;Port=1433;uid=rails;pwd=;'
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.