提交 f037e4ac 编写于 作者: S Sean Griffin

Merge pull request #22787 from kamipo/fix_varbinary_with_default_empty_string

Fix varbinary with default ''
......@@ -31,8 +31,6 @@ def initialize(*)
def extract_default
if blob_or_text_column?
@default = null || strict ? nil : ''
elsif missing_default_forged_as_empty_string?(default)
@default = nil
end
end
......@@ -59,17 +57,6 @@ def auto_increment?
private
# MySQL misreports NOT NULL column default when none is given.
# We can't detect this for columns which may have a legitimate ''
# default (string) but we can for others (integer, datetime, boolean,
# and the rest).
#
# Test whether the column has default '', is not null, and is not
# a type allowing default ''.
def missing_default_forged_as_empty_string?(default)
type != :string && !null && default == ''
end
def assert_valid_default(default)
if blob_or_text_column? && default.present?
raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}"
......
......@@ -49,6 +49,16 @@ def test_should_set_default_for_mysql_binary_data_types
assert_equal "a", varbinary_column.default
end
def test_should_be_empty_string_default_for_mysql_binary_data_types
type = SqlTypeMetadata.new(type: :binary, sql_type: "binary(1)")
binary_column = AbstractMysqlAdapter::Column.new("title", "", type, false)
assert_equal "", binary_column.default
type = SqlTypeMetadata.new(type: :binary, sql_type: "varbinary")
varbinary_column = AbstractMysqlAdapter::Column.new("title", "", type, false)
assert_equal "", varbinary_column.default
end
def test_should_not_set_default_for_blob_and_text_data_types
assert_raise ArgumentError do
AbstractMysqlAdapter::Column.new("title", "a", SqlTypeMetadata.new(sql_type: "blob"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册