提交 962604f4 编写于 作者: J Jon Leighton

Merge pull request #9686 from strzalek/cast_number_to_string_in_pg

Cast number to string in Postgres
......@@ -51,9 +51,12 @@ def quote(value, column = nil) #:nodoc:
super
end
when Numeric
return super unless column.sql_type == 'money'
# Not truly string input, so doesn't require (or allow) escape string syntax.
"'#{value}'"
if column.sql_type == 'money' || [:string, :text].include?(column.type)
# Not truly string input, so doesn't require (or allow) escape string syntax.
"'#{value}'"
else
super
end
when String
case column.sql_type
when 'bytea' then "'#{escape_bytea(value)}'"
......
......@@ -44,6 +44,14 @@ def test_quote_float_infinity
c = Column.new(nil, 1, 'float')
assert_equal "'Infinity'", @conn.quote(infinity, c)
end
def test_quote_cast_numeric
fixnum = 666
c = Column.new(nil, nil, 'string')
assert_equal "'666'", @conn.quote(fixnum, c)
c = Column.new(nil, nil, 'text')
assert_equal "'666'", @conn.quote(fixnum, c)
end
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册