提交 521ca37c 编写于 作者: J Jamis Buck

be like a duck. Let's not rely on explicit classes, so we can pass proxy...

be like a duck. Let's not rely on explicit classes, so we can pass proxy objects around and have them interpreted correctly by ActiveRecord's serialization routines


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5953 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 5314960d
......@@ -24,9 +24,14 @@ def quote(value, column = nil)
when Float, Fixnum, Bignum then value.to_s
# BigDecimals need to be output in a non-normalized form and quoted.
when BigDecimal then value.to_s('F')
when Date then "'#{value.to_s}'"
when Time, DateTime then "'#{quoted_date(value)}'"
else "'#{quote_string(value.to_yaml)}'"
else
if value.acts_like?(:date)
"'#{value.to_s}'"
elsif value.acts_like?(:time)
"'#{quoted_date(value)}'"
else
"'#{quote_string(value.to_yaml)}'"
end
end
end
......
......@@ -375,31 +375,33 @@ def quote(value, column = nil)
(column && column.type == :integer ? '0' : quoted_false)
when Float, Fixnum, Bignum, BigDecimal
value.to_s
when Time, Date, DateTime
if column
case column.type
when :date
else
if value.acts_like?(:time) || value.acts_like?(:date)
if column
case column.type
when :date
"DATE '#{value.strftime("%Y-%m-%d")}'"
when :time
"TIME '#{value.strftime("%H:%M:%S")}'"
when :timestamp
"TIMESTAMP '#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
else
raise NotImplementedError, "Unknown column type!"
end # case
else # Column wasn't passed in, so try to guess the right type
if value.acts_like?(:date)
"DATE '#{value.strftime("%Y-%m-%d")}'"
when :time
"TIME '#{value.strftime("%H:%M:%S")}'"
when :timestamp
"TIMESTAMP '#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
else
raise NotImplementedError, "Unknown column type!"
end # case
else # Column wasn't passed in, so try to guess the right type
if value.kind_of? Date
"DATE '#{value.strftime("%Y-%m-%d")}'"
else
if [:hour, :min, :sec].all? {|part| value.send(:part).zero? }
"TIME '#{value.strftime("%H:%M:%S")}'"
else
"TIMESTAMP '#{quoted_date(value)}'"
end
end
end #if column
else
"'#{quote_string(value.to_yaml)}'"
if [:hour, :min, :sec].all? {|part| value.send(:part).zero? }
"TIME '#{value.strftime("%H:%M:%S")}'"
else
"TIMESTAMP '#{quoted_date(value)}'"
end
end
end #if column
else
"'#{quote_string(value.to_yaml)}'"
end
end #case
end
else
......
......@@ -347,9 +347,14 @@ def quote(value, column = nil)
case value
when TrueClass then '1'
when FalseClass then '0'
when Time, DateTime then "'#{value.strftime("%Y%m%d %H:%M:%S")}'"
when Date then "'#{value.strftime("%Y%m%d")}'"
else super
else
if value.acts_like?(:time)
"'#{value.strftime("%Y%m%d %H:%M:%S")}'"
elsif value.acts_like?(:date)
"'#{value.strftime("%Y%m%d")}'"
else
super
end
end
end
......
......@@ -292,8 +292,12 @@ def quote(value, column = nil)
when TrueClass then '1'
when FalseClass then '0'
when Float, Fixnum, Bignum then force_numeric?(column) ? value.to_s : "'#{value.to_s}'"
when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
else super
else
if value.acts_like?(:time)
"'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
else
super
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册