提交 4f5f59a4 编写于 作者: R Rafael Mendonça França

Merge pull request #11820 from vipulnsward/remove_s2b

Remove redundant `string_to_binary` from type-casting
......@@ -15,7 +15,6 @@ def quote(value, column = nil)
return "'#{quote_string(value)}'" unless column
case column.type
when :binary then "'#{quote_string(column.string_to_binary(value))}'"
when :integer then value.to_i.to_s
when :float then value.to_f.to_s
else
......
......@@ -16,9 +16,6 @@ class IndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths, :
# +columns+ attribute of said TableDefinition object, in order to be used
# for generating a number of table creation or table changing SQL statements.
class ColumnDefinition < Struct.new(:name, :type, :limit, :precision, :scale, :default, :null, :first, :after, :primary_key) #:nodoc:
def string_to_binary(value)
value
end
def primary_key?
primary_key || type.to_sym == :primary_key
......
......@@ -246,8 +246,8 @@ def error_number(exception) # :nodoc:
# QUOTING ==================================================
def quote(value, column = nil)
if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
s = column.class.string_to_binary(value).unpack("H*")[0]
if value.kind_of?(String) && column && column.type == :binary
s = value.unpack("H*")[0]
"x'#{s}'"
elsif value.kind_of?(BigDecimal)
value.to_s("F")
......
......@@ -119,17 +119,7 @@ def extract_default(default)
type_cast(default)
end
# Used to convert from Strings to BLOBs
def string_to_binary(value)
self.class.string_to_binary(value)
end
class << self
# Used to convert from Strings to BLOBs
def string_to_binary(value)
value
end
# Used to convert from BLOBs to Strings
def binary_to_string(value)
value
......
......@@ -226,8 +226,8 @@ def supports_explain?
# QUOTING ==================================================
def quote(value, column = nil)
if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
s = column.class.string_to_binary(value).unpack("H*")[0]
if value.kind_of?(String) && column && column.type == :binary
s = value.unpack("H*")[0]
"x'#{s}'"
else
super
......
......@@ -184,25 +184,6 @@ def test_quote_binary_without_string_to_binary
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:binary))
end
def test_quote_binary_with_string_to_binary
col = Class.new(FakeColumn) {
def string_to_binary(value)
'foo'
end
}.new(:binary)
assert_equal "'foo'", @quoter.quote('lo\l', col)
end
def test_quote_as_mb_chars_binary_column_with_string_to_binary
col = Class.new(FakeColumn) {
def string_to_binary(value)
'foo'
end
}.new(:binary)
string = ActiveSupport::Multibyte::Chars.new('lo\l')
assert_equal "'foo'", @quoter.quote(string, col)
end
def test_string_with_crazy_column
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:foo))
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册