diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/visitors/oracle.rb | 10 |
1 files changed, 9 insertions, 1 deletions
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 |