Ticket #3430: change_type_casting_for_datetime_and_date_columns.patch
| File change_type_casting_for_datetime_and_date_columns.patch, 1.6 kB (added by mixonic@synitech.com, 2 years ago) |
|---|
-
lib/active_record/connection_adapters/sqlserver_adapter.rb
old new 78 78 when :string then value 79 79 when :integer then value == true || value == false ? value == true ? 1 : 0 : value.to_i 80 80 when :float then value.to_f 81 when :datetime then cast_to_ datetime(value)81 when :datetime then cast_to_time(value) 82 82 when :timestamp then cast_to_time(value) 83 83 when :time then cast_to_time(value) 84 when :date then cast_to_date time(value)84 when :date then cast_to_date(value) 85 85 when :boolean then value == true or (value =~ /^t(rue)?$/i) == 0 or value.to_s == '1' 86 86 else value 87 87 end … … 96 96 Time.send(Base.default_timezone, *time_array) rescue nil 97 97 end 98 98 99 def cast_to_datetime(value) 100 if value.is_a?(Time) 101 if value.year != 0 and value.month != 0 and value.day != 0 102 return value 103 else 104 return Time.mktime(2000, 1, 1, value.hour, value.min, value.sec) rescue nil 105 end 106 end 107 return cast_to_time(value) if value.is_a?(Date) or value.is_a?(String) rescue nil 108 value 99 def cast_to_date(value) 100 Date.new cast_to_time(value) 109 101 end 110 102 111 103 # These methods will only allow the adapter to insert binary data with a length of 7K or less