提交 8996fc30 编写于 作者: R Rafael Mendonça França

Merge pull request #15802 from sgrif/sg-column-quoting

Don't use column object for type casting in `quoting`
......@@ -14,8 +14,8 @@ def quote(value, column = nil)
# value. Is this really the only case? Are we missing tests for other types?
# We should have a real column object passed (or nil) here, and check for that
# instead
if column.respond_to?(:type_cast_for_database)
value = column.type_cast_for_database(value)
if column.respond_to?(:cast_type)
value = column.cast_type.type_cast_for_database(value)
end
_quote(value)
......@@ -34,8 +34,8 @@ def type_cast(value, column)
# value. Is this really the only case? Are we missing tests for other types?
# We should have a real column object passed (or nil) here, and check for that
# instead
if column.respond_to?(:type_cast_for_database)
value = column.type_cast_for_database(value)
if column.respond_to?(:cast_type)
value = column.cast_type.type_cast_for_database(value)
end
_type_cast(value)
......
......@@ -179,8 +179,8 @@ def _type_cast(value)
end
def array_column(column)
if column.array && !column.respond_to?(:type_cast_for_database)
OID::Array.new(AdapterProxyType.new(column, self))
if column.array && !column.respond_to?(:cast_type)
Column.new('', nil, OID::Array.new(AdapterProxyType.new(column, self)))
else
column
end
......
......@@ -93,12 +93,10 @@ def test_quote_nil
def test_quote_true
assert_equal @quoter.quoted_true, @quoter.quote(true, nil)
assert_equal '1', @quoter.quote(true, Type::Integer.new)
end
def test_quote_false
assert_equal @quoter.quoted_false, @quoter.quote(false, nil)
assert_equal '0', @quoter.quote(false, Type::Integer.new)
end
def test_quote_float
......@@ -157,25 +155,6 @@ def test_quote_as_mb_chars_no_column
assert_equal "'lo\\\\l'", @quoter.quote(string, nil)
end
def test_quote_string_int_column
assert_equal "1", @quoter.quote('1', Type::Integer.new)
assert_equal "1", @quoter.quote('1.2', Type::Integer.new)
end
def test_quote_string_float_column
assert_equal "1.0", @quoter.quote('1', Type::Float.new)
assert_equal "1.2", @quoter.quote('1.2', Type::Float.new)
end
def test_quote_as_mb_chars_binary_column
string = ActiveSupport::Multibyte::Chars.new('lo\l')
assert_equal "'lo\\\\l'", @quoter.quote(string, Type::Binary.new)
end
def test_quote_binary_without_string_to_binary
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', Type::Binary.new)
end
def test_string_with_crazy_column
assert_equal "'lo\\\\l'", @quoter.quote('lo\l')
end
......@@ -183,10 +162,6 @@ def test_string_with_crazy_column
def test_quote_duration
assert_equal "1800", @quoter.quote(30.minutes)
end
def test_quote_duration_int_column
assert_equal "7200", @quoter.quote(2.hours, Type::Integer.new)
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册