提交 4b2e16ed 编写于 作者: A Aaron Patterson

all columns respond to string_to_binary, so no need to check respond_to?

上级 5b5ae01f
......@@ -14,8 +14,8 @@ def quote(value, column = nil)
value = value.to_s
return "'#{quote_string(value)}'" unless column
if column.type == :binary && column.class.respond_to?(:string_to_binary)
"'#{quote_string(column.class.string_to_binary(value))}'" # ' (for ruby-mode)
if column.type == :binary
"'#{quote_string(column.string_to_binary(value))}'" # ' (for ruby-mode)
elsif [:integer, :float].include?(column.type)
(column.type == :integer ? value.to_i : value.to_f).to_s
else
......
......@@ -114,6 +114,11 @@ 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)
......@@ -268,6 +273,10 @@ class IndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths) #
# for generating a number of table creation or table changing SQL statements.
class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :precision, :scale, :default, :null) #:nodoc:
def string_to_binary(value)
value
end
def sql_type
base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
end
......
......@@ -3,7 +3,12 @@
module ActiveRecord
module ConnectionAdapters
class QuotingTest < ActiveRecord::TestCase
class FakeColumn < Struct.new(:type)
class FakeColumn < ActiveRecord::ConnectionAdapters::Column
attr_accessor :type
def initialize type
@type = type
end
end
def setup
......@@ -190,7 +195,7 @@ def test_quote_binary_without_string_to_binary
def test_quote_binary_with_string_to_binary
col = Class.new(FakeColumn) {
def self.string_to_binary(value)
def string_to_binary(value)
'foo'
end
}.new(:binary)
......@@ -199,7 +204,7 @@ def self.string_to_binary(value)
def test_quote_as_mb_chars_binary_column_with_string_to_binary
col = Class.new(FakeColumn) {
def self.string_to_binary(value)
def string_to_binary(value)
'foo'
end
}.new(:binary)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册