activerecord-sqlserver-adapter 2.3.6 → 2.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG
CHANGED
@@ -109,6 +109,11 @@ module ActiveRecord
|
|
109
109
|
(@table_klass && @table_klass < ActiveRecord::Base) ? @table_klass : nil
|
110
110
|
end
|
111
111
|
|
112
|
+
def database_year
|
113
|
+
@sqlserver_options[:database_year]
|
114
|
+
end
|
115
|
+
|
116
|
+
|
112
117
|
private
|
113
118
|
|
114
119
|
def extract_limit(sql_type)
|
@@ -140,7 +145,9 @@ module ActiveRecord
|
|
140
145
|
end
|
141
146
|
|
142
147
|
def simplified_datetime
|
143
|
-
if
|
148
|
+
if database_year >= 2008
|
149
|
+
:datetime
|
150
|
+
elsif table_klass && table_klass.coerced_sqlserver_date_columns.include?(name)
|
144
151
|
:date
|
145
152
|
elsif table_klass && table_klass.coerced_sqlserver_time_columns.include?(name)
|
146
153
|
:time
|
@@ -163,7 +170,7 @@ module ActiveRecord
|
|
163
170
|
class SQLServerAdapter < AbstractAdapter
|
164
171
|
|
165
172
|
ADAPTER_NAME = 'SQLServer'.freeze
|
166
|
-
VERSION = '2.3.
|
173
|
+
VERSION = '2.3.7'.freeze
|
167
174
|
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
|
168
175
|
SUPPORTED_VERSIONS = [2000,2005,2008].freeze
|
169
176
|
LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
|
@@ -265,10 +272,19 @@ module ActiveRecord
|
|
265
272
|
end
|
266
273
|
end
|
267
274
|
|
275
|
+
def native_time_database_type
|
276
|
+
sqlserver_2008? ? 'time' : 'datetime'
|
277
|
+
end
|
278
|
+
|
279
|
+
def native_date_database_type
|
280
|
+
sqlserver_2008? ? 'date' : 'datetime'
|
281
|
+
end
|
282
|
+
|
268
283
|
def native_binary_database_type
|
269
284
|
@@native_binary_database_type || ((sqlserver_2005? || sqlserver_2008?) ? 'varbinary(max)' : 'image')
|
270
285
|
end
|
271
286
|
|
287
|
+
|
272
288
|
# QUOTING ==================================================#
|
273
289
|
|
274
290
|
def quote(value, column = nil)
|
@@ -533,8 +549,8 @@ module ActiveRecord
|
|
533
549
|
:decimal => { :name => "decimal" },
|
534
550
|
:datetime => { :name => "datetime" },
|
535
551
|
:timestamp => { :name => "datetime" },
|
536
|
-
:time => { :name =>
|
537
|
-
:date => { :name =>
|
552
|
+
:time => { :name => native_time_database_type },
|
553
|
+
:date => { :name => native_date_database_type },
|
538
554
|
:binary => { :name => native_binary_database_type },
|
539
555
|
:boolean => { :name => "bit"},
|
540
556
|
# These are custom types that may move somewhere else for good schema_dumper.rb hacking to output them.
|
@@ -606,7 +622,7 @@ module ActiveRecord
|
|
606
622
|
return [] if table_name.blank?
|
607
623
|
cache_key = unqualify_table_name(table_name)
|
608
624
|
@sqlserver_columns_cache[cache_key] ||= column_definitions(table_name).collect do |ci|
|
609
|
-
sqlserver_options = ci.except(:name,:default_value,:type,:null)
|
625
|
+
sqlserver_options = ci.except(:name,:default_value,:type,:null).merge(:database_year=>database_year)
|
610
626
|
SQLServerColumn.new ci[:name], ci[:default_value], ci[:type], ci[:null], sqlserver_options
|
611
627
|
end
|
612
628
|
end
|
@@ -167,10 +167,15 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
|
|
167
167
|
assert_equal :datetime, @datetime.type
|
168
168
|
end
|
169
169
|
|
170
|
-
should '
|
171
|
-
assert_equal 'datetime', @date.sql_type
|
172
|
-
assert_equal 'datetime', @time.sql_type
|
170
|
+
should 'use correct #sql_type for different sql server versions' do
|
173
171
|
assert_equal 'datetime', @datetime.sql_type
|
172
|
+
if sqlserver_2000? || sqlserver_2005?
|
173
|
+
assert_equal 'datetime', @date.sql_type
|
174
|
+
assert_equal 'datetime', @time.sql_type
|
175
|
+
else
|
176
|
+
assert_equal 'date', @date.sql_type
|
177
|
+
assert_equal 'time', @time.sql_type
|
178
|
+
end
|
174
179
|
end
|
175
180
|
|
176
181
|
should 'all be have nil #limit' do
|
@@ -206,7 +211,7 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
|
|
206
211
|
end
|
207
212
|
|
208
213
|
should 'have an inheritable attribute ' do
|
209
|
-
assert SqlServerChronic.coerced_sqlserver_date_columns.include?('date')
|
214
|
+
assert SqlServerChronic.coerced_sqlserver_date_columns.include?('date') unless sqlserver_2008?
|
210
215
|
end
|
211
216
|
|
212
217
|
should 'have column and objects cast to date' do
|