mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove redundant string_to_binary
from type-casting
This commit is contained in:
parent
0053b2a1c4
commit
5ef02de131
6 changed files with 4 additions and 37 deletions
|
@ -15,7 +15,6 @@ module ActiveRecord
|
||||||
return "'#{quote_string(value)}'" unless column
|
return "'#{quote_string(value)}'" unless column
|
||||||
|
|
||||||
case column.type
|
case column.type
|
||||||
when :binary then "'#{quote_string(column.string_to_binary(value))}'"
|
|
||||||
when :integer then value.to_i.to_s
|
when :integer then value.to_i.to_s
|
||||||
when :float then value.to_f.to_s
|
when :float then value.to_f.to_s
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,9 +16,6 @@ module ActiveRecord
|
||||||
# +columns+ attribute of said TableDefinition object, in order to be used
|
# +columns+ attribute of said TableDefinition object, in order to be used
|
||||||
# for generating a number of table creation or table changing SQL statements.
|
# 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:
|
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?
|
def primary_key?
|
||||||
primary_key || type.to_sym == :primary_key
|
primary_key || type.to_sym == :primary_key
|
||||||
|
|
|
@ -246,8 +246,8 @@ module ActiveRecord
|
||||||
# QUOTING ==================================================
|
# QUOTING ==================================================
|
||||||
|
|
||||||
def quote(value, column = nil)
|
def quote(value, column = nil)
|
||||||
if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
|
if value.kind_of?(String) && column && column.type == :binary
|
||||||
s = column.class.string_to_binary(value).unpack("H*")[0]
|
s = value.unpack("H*")[0]
|
||||||
"x'#{s}'"
|
"x'#{s}'"
|
||||||
elsif value.kind_of?(BigDecimal)
|
elsif value.kind_of?(BigDecimal)
|
||||||
value.to_s("F")
|
value.to_s("F")
|
||||||
|
|
|
@ -119,17 +119,7 @@ module ActiveRecord
|
||||||
type_cast(default)
|
type_cast(default)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Used to convert from Strings to BLOBs
|
|
||||||
def string_to_binary(value)
|
|
||||||
self.class.string_to_binary(value)
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# Used to convert from Strings to BLOBs
|
|
||||||
def string_to_binary(value)
|
|
||||||
value
|
|
||||||
end
|
|
||||||
|
|
||||||
# Used to convert from BLOBs to Strings
|
# Used to convert from BLOBs to Strings
|
||||||
def binary_to_string(value)
|
def binary_to_string(value)
|
||||||
value
|
value
|
||||||
|
|
|
@ -226,8 +226,8 @@ module ActiveRecord
|
||||||
# QUOTING ==================================================
|
# QUOTING ==================================================
|
||||||
|
|
||||||
def quote(value, column = nil)
|
def quote(value, column = nil)
|
||||||
if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
|
if value.kind_of?(String) && column && column.type == :binary
|
||||||
s = column.class.string_to_binary(value).unpack("H*")[0]
|
s = value.unpack("H*")[0]
|
||||||
"x'#{s}'"
|
"x'#{s}'"
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
|
|
@ -184,25 +184,6 @@ module ActiveRecord
|
||||||
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:binary))
|
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:binary))
|
||||||
end
|
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
|
def test_string_with_crazy_column
|
||||||
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:foo))
|
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:foo))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue