mirror of https://github.com/rails/rails
Handle quoting of Rational numbers for MySQL
This commit is contained in:
parent
f9a1671c18
commit
f572e0ea1c
|
@ -1,3 +1,7 @@
|
|||
* Fix quoting of `ActiveSupport::Duration` and `Rational` numbers in the MySQL adapter.
|
||||
|
||||
*Kevin McPhillips*
|
||||
|
||||
* Allow column name with COLLATE (e.g., title COLLATE "C") as safe SQL string
|
||||
|
||||
*Shugo Maeda*
|
||||
|
|
|
@ -8,6 +8,8 @@ module ActiveRecord
|
|||
module Quoting # :nodoc:
|
||||
def quote_bound_value(value)
|
||||
case value
|
||||
when Rational
|
||||
quote(value.to_f.to_s)
|
||||
when Numeric, ActiveSupport::Duration
|
||||
quote(value.to_s)
|
||||
when BigDecimal
|
||||
|
|
|
@ -72,6 +72,11 @@ module ActiveRecord
|
|||
assert_equal 0, count
|
||||
end
|
||||
|
||||
def test_where_with_rational_for_string_column_using_bind_parameters
|
||||
count = Post.where("title = ?", Rational(0)).count
|
||||
assert_equal 0, count
|
||||
end
|
||||
|
||||
def test_where_with_duration_for_string_column_using_bind_parameters
|
||||
count = Post.where("title = ?", 0.seconds).count
|
||||
assert_equal 0, count
|
||||
|
|
|
@ -16,6 +16,10 @@ class Mysql2QuotingTest < ActiveRecord::Mysql2TestCase
|
|||
assert_equal "'4.2'", @conn.quote_bound_value(BigDecimal("4.2"))
|
||||
end
|
||||
|
||||
def test_quote_bound_rational
|
||||
assert_equal "'0.75'", @conn.quote_bound_value(Rational(3, 4))
|
||||
end
|
||||
|
||||
def test_quote_bound_duration
|
||||
assert_equal "'42'", @conn.quote_bound_value(42.seconds)
|
||||
end
|
||||
|
|
|
@ -37,6 +37,12 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def test_where_with_rational_for_string_column_using_bind_parameters
|
||||
assert_raises ActiveRecord::StatementInvalid do
|
||||
Post.where("title = ?", Rational(0)).count
|
||||
end
|
||||
end
|
||||
|
||||
def test_where_with_duration_for_string_column_using_bind_parameters
|
||||
assert_raises ActiveRecord::StatementInvalid do
|
||||
Post.where("title = ?", 0.seconds).count
|
||||
|
|
|
@ -33,6 +33,11 @@ module ActiveRecord
|
|||
assert_equal 0, count
|
||||
end
|
||||
|
||||
def test_where_with_rational_for_string_column_using_bind_parameters
|
||||
count = Post.where("title = ?", Rational(0)).count
|
||||
assert_equal 0, count
|
||||
end
|
||||
|
||||
def test_where_with_duration_for_string_column_using_bind_parameters
|
||||
count = Post.where("title = ?", 0.seconds).count
|
||||
assert_equal 0, count
|
||||
|
|
|
@ -336,6 +336,11 @@ module ActiveRecord
|
|||
assert_equal 0, count
|
||||
end
|
||||
|
||||
def test_where_with_rational_for_string_column
|
||||
count = Post.where(title: Rational(0)).count
|
||||
assert_equal 0, count
|
||||
end
|
||||
|
||||
def test_where_with_duration_for_string_column
|
||||
count = Post.where(title: 0.seconds).count
|
||||
assert_equal 0, count
|
||||
|
|
Loading…
Reference in New Issue