Ticket #5940: readonly_timestamp_columns_for_sqlserver.diff
| File readonly_timestamp_columns_for_sqlserver.diff, 6.0 kB (added by tomafro, 1 year ago) |
|---|
-
activerecord/test/adapter_test_sqlserver.rb
old new 4 4 require 'fixtures/task' 5 5 6 6 class SqlServerAdapterTest < Test::Unit::TestCase 7 class TableWith RealColumn < ActiveRecord::Base; end7 class TableWithSqlserverSpecificColumn < ActiveRecord::Base; end 8 8 9 9 fixtures :posts, :tasks 10 10 … … 17 17 end 18 18 19 19 def test_real_column_has_float_type 20 assert_equal :float, TableWith RealColumn.columns_hash["real_number"].type20 assert_equal :float, TableWithSqlserverSpecificColumn.columns_hash["real_number"].type 21 21 end 22 23 def test_timestamp_column_has_timestamp_type 24 assert_equal :timestamp, TableWithSqlserverSpecificColumn.columns_hash["timestamp"].type 25 end 22 26 27 def test_create_record_with_timestamp_column 28 record = TableWithSqlserverSpecificColumn.create(:real_number => 1.2345) 29 assert_nil record.timestamp 30 loaded = TableWithSqlserverSpecificColumn.find(record.id) 31 assert_not_nil loaded.timestamp 32 end 33 34 def test_update_record_with_timestamp_column 35 record = TableWithSqlserverSpecificColumn.create!(:real_number => 1.2345) 36 loaded = TableWithSqlserverSpecificColumn.find(record.id) 37 loaded.timestamp = "rubbish" 38 loaded.real_number = 2.345 39 loaded.save! 40 loaded.reload 41 assert_not_nil loaded.timestamp 42 assert_not_equal "rubbish", loaded.timestamp 43 end 44 23 45 # SQL Server 2000 has a bug where some unambiguous date formats are not 24 46 # correctly identified if the session language is set to german 25 47 def test_date_insertion_when_language_is_german … … 68 90 assert_all_statements_used_are_closed do 69 91 @connection.active? 70 92 end 71 end 93 end 72 94 73 95 def assert_all_statements_used_are_closed(&block) 74 96 existing_handles = [] -
activerecord/test/fixtures/db_definitions/schema.rb
old new 71 71 72 72 # For sqlserver 2000+, ensure real columns can be used 73 73 if adapter_name.starts_with?("SQLServer") 74 create_table :table_with_ real_columns, :force => true do |t|74 create_table :table_with_sqlserver_specific_columns, :force => true do |t| 75 75 t.column :real_number, :real 76 t.column :timestamp, :timestamp 76 77 end 77 78 end 78 79 end -
activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
old new 23 23 24 24 @primary = nil 25 25 end 26 27 # Is this column read-only? Some databases (such as SQL Server) provide 28 # read only data types. This method can be overridden by subclasses 29 # to indicate the column is readonly 30 31 def readonly? 32 false 33 end 26 34 27 35 def text? 28 36 [:string, :text].include? type -
activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
old new 72 72 else super 73 73 end 74 74 end 75 76 def readonly? 77 case type 78 when :timestamp then true 79 else super 80 end 81 end 75 82 83 def type_cast_code(var_name) 84 case type 85 when :timestamp then nil 86 else super 87 end 88 end 89 76 90 def type_cast(value) 77 91 return nil if value.nil? 78 92 case type 79 93 when :datetime then cast_to_datetime(value) 80 when :timestamp then cast_to_time(value)94 when :timestamp then value 81 95 when :time then cast_to_time(value) 82 96 when :date then cast_to_datetime(value) 83 97 when :boolean then value == true or (value =~ /^t(rue)?$/i) == 0 or value.to_s == '1' … … 110 124 value 111 125 end 112 126 127 def self.string_to_timestamp(value) 128 value 129 end 130 113 131 # TODO: Find less hack way to convert DateTime objects into Times 114 132 115 133 def self.string_to_time(value) … … 203 221 :float => { :name => "float", :limit => 8 }, 204 222 :decimal => { :name => "decimal" }, 205 223 :datetime => { :name => "datetime" }, 206 :timestamp => { :name => " datetime" },224 :timestamp => { :name => "timestamp" }, 207 225 :time => { :name => "datetime" }, 208 226 :date => { :name => "datetime" }, 209 227 :binary => { :name => "image"}, … … 600 618 end 601 619 sql 602 620 end 621 622 def options_include_default?(options) 623 options[:column].type == :timestamp ? false : super 624 end 603 625 604 626 end #class SQLServerAdapter < AbstractAdapter 605 627 end #module ConnectionAdapters -
activerecord/lib/active_record/base.rb
old new 2202 2202 # an SQL statement. 2203 2203 def attributes_with_quotes(include_primary_key = true) 2204 2204 attributes.inject({}) do |quoted, (name, value)| 2205 if column = column_for_attribute(name) 2205 column = column_for_attribute(name) 2206 if column && !column.readonly? 2206 2207 quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary 2207 2208 end 2208 2209 quoted