aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors/oracle.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-24 10:24:31 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-24 10:24:31 -0700
commit58d82b23a102ca1eb5510b8c49bc097b402a332d (patch)
treefda2bba5863637d996cb0754aed767bd400397cd /lib/arel/visitors/oracle.rb
parentf63badf42738c4a553e84e3d121786000c67c623 (diff)
downloadrails-58d82b23a102ca1eb5510b8c49bc097b402a332d.tar.gz
rails-58d82b23a102ca1eb5510b8c49bc097b402a332d.tar.bz2
rails-58d82b23a102ca1eb5510b8c49bc097b402a332d.zip
dealing with limits and offsets
Diffstat (limited to 'lib/arel/visitors/oracle.rb')
-rw-r--r--lib/arel/visitors/oracle.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb
index afea683080..c3af68cc36 100644
--- a/lib/arel/visitors/oracle.rb
+++ b/lib/arel/visitors/oracle.rb
@@ -1,8 +1,10 @@
module Arel
module Visitors
class Oracle < Arel::Visitors::ToSql
+ private
+
def visit_Arel_Nodes_SelectStatement o
- if o.limit && o.orders.empty?
+ if o.limit && o.orders.empty? && !o.offset
o.cores.last.wheres.push Nodes::LessThanOrEqual.new(
Nodes::SqlLiteral.new('ROWNUM'), o.limit
)
@@ -10,6 +12,22 @@ module Arel
return super
end
+ if o.limit && o.offset
+ limit = o.limit.to_i
+ offset = o.offset
+ o.limit = nil
+ o.offset = nil
+ sql = super
+ return <<-eosql
+ SELECT * FROM (
+ SELECT raw_sql_.*, rownum raw_rnum_
+ FROM (#{sql}) raw_sql_
+ WHERE rownum <= #{offset.value.to_i + limit}
+ )
+ WHERE #{visit offset}
+ eosql
+ end
+
if o.limit && !o.orders.empty?
limit = o.limit
o.limit = nil
@@ -18,6 +36,10 @@ module Arel
super
end
+
+ def visit_Arel_Nodes_Offset o
+ "raw_rnum_ > #{visit o.value}"
+ end
end
end
end