提交 5837de53 编写于 作者: J Jeremy Daer

Merge pull request #20645 from kamipo/fix_mysql_set_type_bug

Fix undesired type lookup with `SET` in MySQL
......@@ -814,7 +814,6 @@ def initialize_type_map(m) # :nodoc:
register_integer_type m, %r(^tinyint)i, limit: 1
m.alias_type %r(tinyint\(1\))i, 'boolean' if emulate_booleans
m.alias_type %r(set)i, 'varchar'
m.alias_type %r(year)i, 'integer'
m.alias_type %r(bit)i, 'binary'
......@@ -823,6 +822,12 @@ def initialize_type_map(m) # :nodoc:
.split(',').map{|enum| enum.strip.length - 2}.max
MysqlString.new(limit: limit)
end
m.register_type(%r(^set)i) do |sql_type|
limit = sql_type[/^set\((.+)\)/i, 1]
.split(',').map{|set| set.strip.length - 1}.sum - 1
MysqlString.new(limit: limit)
end
end
def register_integer_type(mapping, key, options) # :nodoc:
......
......@@ -22,6 +22,10 @@ def test_string_types
assert_lookup_type :string, "SET('one', 'two', 'three')"
end
def test_set_type_with_value_matching_other_type
assert_lookup_type :string, "SET('unicode', '8bit', 'none', 'time')"
end
def test_enum_type_with_value_matching_other_type
assert_lookup_type :string, "ENUM('unicode', '8bit', 'none')"
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册