aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors/oracle.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-24 11:17:17 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-24 11:17:17 -0700
commitf381da2738ec8c2aac3c34fead32688ea7b08d74 (patch)
tree4eaa7d8bff4d42dfe37af6fa0eff50dc49f3d3d1 /lib/arel/visitors/oracle.rb
parent58d82b23a102ca1eb5510b8c49bc097b402a332d (diff)
downloadrails-f381da2738ec8c2aac3c34fead32688ea7b08d74.tar.gz
rails-f381da2738ec8c2aac3c34fead32688ea7b08d74.tar.bz2
rails-f381da2738ec8c2aac3c34fead32688ea7b08d74.zip
adding more oracle hacks
Diffstat (limited to 'lib/arel/visitors/oracle.rb')
-rw-r--r--lib/arel/visitors/oracle.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb
index c3af68cc36..46a3ad4c78 100644
--- a/lib/arel/visitors/oracle.rb
+++ b/lib/arel/visitors/oracle.rb
@@ -4,6 +4,8 @@ module Arel
private
def visit_Arel_Nodes_SelectStatement o
+ order_hacks(o)
+
if o.limit && o.orders.empty? && !o.offset
o.cores.last.wheres.push Nodes::LessThanOrEqual.new(
Nodes::SqlLiteral.new('ROWNUM'), o.limit
@@ -40,6 +42,23 @@ module Arel
def visit_Arel_Nodes_Offset o
"raw_rnum_ > #{visit o.value}"
end
+
+ ###
+ # Hacks for the order clauses specific to Oracle
+ def order_hacks o
+ return if o.orders.empty?
+ return unless o.cores.any? do |core|
+ core.projections.any? do |projection|
+ /DISTINCT.*FIRST_VALUE/ === projection
+ end
+ end
+ orders = o.orders
+ o.orders = []
+ orders.each_with_index do |order, i|
+ o.orders <<
+ Nodes::SqlLiteral.new("alias_#{i}__ #{'DESC' if /\bdesc$/i === order}")
+ end
+ end
end
end
end