aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors/oracle.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-24 10:09:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-24 10:09:21 -0700
commitf63badf42738c4a553e84e3d121786000c67c623 (patch)
treef5094cb2a931c89977fa3dd6953b4c66aeb49bc9 /lib/arel/visitors/oracle.rb
parent487df1771ded1fb065a53ebe9d1a5a9c119478e3 (diff)
downloadrails-f63badf42738c4a553e84e3d121786000c67c623.tar.gz
rails-f63badf42738c4a553e84e3d121786000c67c623.tar.bz2
rails-f63badf42738c4a553e84e3d121786000c67c623.zip
creating a subquery when there is an order and a limit
Diffstat (limited to 'lib/arel/visitors/oracle.rb')
-rw-r--r--lib/arel/visitors/oracle.rb10
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