From f63badf42738c4a553e84e3d121786000c67c623 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 24 Sep 2010 10:09:21 -0700 Subject: creating a subquery when there is an order and a limit --- lib/arel/visitors/oracle.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/arel/visitors/oracle.rb') diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb index 840a7a9ace..afea683080 100644 --- a/lib/arel/visitors/oracle.rb +++ b/lib/arel/visitors/oracle.rb @@ -2,12 +2,20 @@ module Arel module Visitors class Oracle < Arel::Visitors::ToSql def visit_Arel_Nodes_SelectStatement o - if o.limit + if o.limit && o.orders.empty? o.cores.last.wheres.push Nodes::LessThanOrEqual.new( Nodes::SqlLiteral.new('ROWNUM'), o.limit ) o.limit = nil + return super end + + if o.limit && !o.orders.empty? + limit = o.limit + o.limit = nil + return "SELECT * FROM (#{super}) WHERE ROWNUM <= #{limit}" + end + super end end -- cgit v1.2.3