Skip to content

Commit 19949a7

Browse files
committed
Making sure that smalldatetime types are OK to use. Also fixed a bug in the #view_information method that checks to see if a view definition is equal to 4000 chars, meaning that it is most likely truncated and needs to use the backup method of sp_helptext to get it's view definition.
1 parent e319916 commit 19949a7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ def view_information(table_name)
485485
@sqlserver_view_information_cache[table_name] ||= begin
486486
view_info = info_schema_query { select_one("SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = '#{table_name}'") }
487487
if view_info
488-
view_info['VIEW_DEFINITION'] ||= info_schema_query { select_values("EXEC sp_helptext #{table_name}").join }
488+
if view_info['VIEW_DEFINITION'].blank? || view_info['VIEW_DEFINITION'].length == 4000
489+
view_info['VIEW_DEFINITION'] = info_schema_query { select_values("EXEC sp_helptext #{table_name}").join }
490+
end
489491
end
490492
view_info
491493
end

test/cases/column_test_sqlserver.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def setup
158158
@date = SqlServerChronic.columns_hash['date']
159159
@time = SqlServerChronic.columns_hash['time']
160160
@datetime = SqlServerChronic.columns_hash['datetime']
161+
@smalldatetime = SqlServerChronic.columns_hash['smalldatetime']
161162
end
162163

163164
should 'have correct simplified type for uncast datetime' do
@@ -176,6 +177,23 @@ def setup
176177
assert_equal nil, @datetime.limit
177178
end
178179

180+
context 'For smalldatetime types' do
181+
182+
should 'have created that type using rails migrations' do
183+
assert_equal 'smalldatetime', @smalldatetime.sql_type
184+
end
185+
186+
should 'be able to insert column without truncation warnings or the like' do
187+
SqlServerChronic.create! :smalldatetime => Time.now
188+
end
189+
190+
should 'be able to update column without truncation warnings or the like' do
191+
ssc = SqlServerChronic.create! :smalldatetime => 2.days.ago
192+
ssc.update_attributes! :smalldatetime => Time.now
193+
end
194+
195+
end
196+
179197
context 'which have coerced types' do
180198

181199
setup do

test/schema/sqlserver_specific_schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
t.column :time, :time
2626
t.column :datetime, :datetime
2727
t.column :timestamp, :timestamp
28+
t.column :smalldatetime, :smalldatetime
2829
end
2930

3031
create_table(:fk_test_has_fks, :force => true) { |t| t.column(:fk_id, :integer, :null => false) }

0 commit comments

Comments
 (0)