diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-12-14 08:34:14 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2015-12-15 10:15:24 +0100 |
commit | af3dc42ee357a8f70148c9dc9572276a9824aeec (patch) | |
tree | 71e4a043ffe26af38effac2881ca1909987d17a7 /activerecord/test | |
parent | e12c2a6d11a9ebc28b85f34230b11fb654503726 (diff) | |
download | rails-af3dc42ee357a8f70148c9dc9572276a9824aeec.tar.gz rails-af3dc42ee357a8f70148c9dc9572276a9824aeec.tar.bz2 rails-af3dc42ee357a8f70148c9dc9572276a9824aeec.zip |
Use a bind param for `LIMIT` and `OFFSET`
We currently generate an unbounded number of prepared statements when
`limit` or `offset` are called with a dynamic argument. This changes
`LIMIT` and `OFFSET` to use bind params, eliminating the problem.
`Type::Value#hash` needed to be implemented, as it turns out we busted
the query cache if the type object used wasn't exactly the same object.
This drops support for passing an `Arel::Nodes::SqlLiteral` to `limit`.
Doing this relied on AR internals, and was never officially supported
usage.
Fixes #22250.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 6 |
2 files changed, 3 insertions, 9 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index b449280fb4..dc555caaff 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -147,12 +147,6 @@ class BasicsTest < ActiveRecord::TestCase end end - unless current_adapter?(:MysqlAdapter, :Mysql2Adapter) - def test_limit_should_allow_sql_literal - assert_equal 1, Topic.limit(Arel.sql('2-1')).to_a.length - end - end - def test_select_symbol topic_ids = Topic.select(:id).map(&:id).sort assert_equal Topic.pluck(:id).sort, topic_ids diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 91214da048..73f5312eba 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -434,9 +434,9 @@ class FinderTest < ActiveRecord::TestCase end def test_take_and_first_and_last_with_integer_should_use_sql_limit - assert_sql(/LIMIT 3|ROWNUM <= 3/) { Topic.take(3).entries } - assert_sql(/LIMIT 2|ROWNUM <= 2/) { Topic.first(2).entries } - assert_sql(/LIMIT 5|ROWNUM <= 5/) { Topic.last(5).entries } + assert_sql(/LIMIT|ROWNUM <=/) { Topic.take(3).entries } + assert_sql(/LIMIT|ROWNUM <=/) { Topic.first(2).entries } + assert_sql(/LIMIT|ROWNUM <=/) { Topic.last(5).entries } end def test_last_with_integer_and_order_should_keep_the_order |