Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    7878        when :string    then value 
    7979        when :integer   then value == true || value == false ? value == true ? 1 : 0 : value.to_i 
    8080        when :float     then value.to_f 
    81         when :datetime  then cast_to_datetime(value) 
     81        when :datetime  then cast_to_time(value) 
    8282        when :timestamp then cast_to_time(value) 
    8383        when :time      then cast_to_time(value) 
    84         when :date      then cast_to_datetime(value) 
     84        when :date      then cast_to_date(value) 
    8585        when :boolean   then value == true or (value =~ /^t(rue)?$/i) == 0 or value.to_s == '1' 
    8686        else value 
    8787        end 
     
    9696        Time.send(Base.default_timezone, *time_array) rescue nil 
    9797      end 
    9898 
    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) 
    109101      end 
    110102 
    111103      # These methods will only allow the adapter to insert binary data with a length of 7K or less