Changeset 6074
- Timestamp:
- 01/28/07 15:45:06 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (modified) (3 diffs)
- trunk/activerecord/test/fixtures/db_definitions/mysql.sql (modified) (1 diff)
- trunk/activerecord/test/migration_test.rb (modified) (2 diffs)
- trunk/activerecord/test/schema_dumper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6073 r6074 1 1 *SVN* 2 3 * MySQL: blob and text columns may not have defaults in 5.x. Update fixtures schema for strict mode. #6695 [Dan Kubb] 2 4 3 5 * update_all can take a Hash argument. sanitize_sql splits into two methods for conditions and assignment since NULL values and delimiters are handled differently. #6583, #7365 [sandofsky, Assaf] trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
r6064 r6074 86 86 module ConnectionAdapters 87 87 class MysqlColumn < Column #:nodoc: 88 TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:binary, :string, :text]) 88 TYPES_DISALLOWING_DEFAULT = Set.new([:binary, :text]) 89 TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:string]) 89 90 90 91 def initialize(name, default, sql_type = nil, null = true) 91 92 @original_default = default 92 93 super 93 @default = nil if missing_default_forged_as_empty_string?94 @default = nil if no_default_allowed? || missing_default_forged_as_empty_string? 94 95 end 95 96 … … 103 104 # MySQL misreports NOT NULL column default when none is given. 104 105 # We can't detect this for columns which may have a legitimate '' 105 # default (string , text, binary) but we can for others (integer,106 # datetime, boolean,and the rest).106 # default (string) but we can for others (integer, datetime, boolean, 107 # and the rest). 107 108 # 108 109 # Test whether the column has default '', is not null, and is not … … 110 111 def missing_default_forged_as_empty_string? 111 112 !null && @original_default == '' && !TYPES_ALLOWING_EMPTY_STRING_DEFAULT.include?(type) 113 end 114 115 # MySQL 5.0 does not allow text and binary columns to have defaults 116 def no_default_allowed? 117 TYPES_DISALLOWING_DEFAULT.include?(type) 112 118 end 113 119 end trunk/activerecord/test/fixtures/db_definitions/mysql.sql
r5749 r6074 177 177 CREATE TABLE `tasks` ( 178 178 `id` int(11) NOT NULL auto_increment, 179 `starting` datetime NOT NULL default ' 0000-00-0000:00:00',180 `ending` datetime NOT NULL default ' 0000-00-0000:00:00',179 `starting` datetime NOT NULL default '1000-01-01 00:00:00', 180 `ending` datetime NOT NULL default '1000-01-01 00:00:00', 181 181 PRIMARY KEY (`id`) 182 182 ) TYPE=InnoDB; trunk/activerecord/test/migration_test.rb
r5937 r6074 693 693 assert_nothing_raised { 694 694 Person.connection.create_table :binary_testings do |t| 695 t.column "data", :binary, : default => "", :null => false695 t.column "data", :binary, :null => false 696 696 end 697 697 } … … 703 703 assert_equal "empty_blob()", data_column.default 704 704 else 705 assert_ equal "",data_column.default705 assert_nil data_column.default 706 706 end 707 707 trunk/activerecord/test/schema_dumper_test.rb
r5520 r6074 90 90 end 91 91 92 if current_adapter?(:MysqlAdapter) 93 def test_schema_dump_should_not_add_default_value_for_mysql_text_field 94 output = standard_dump 95 assert_match %r{t.column "body",\s+:text,\s+:null => false$}, output 96 end 97 end 98 92 99 def test_schema_dump_includes_decimal_options 93 100 stream = StringIO.new