diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/visitors/oracle.rb | 19 |
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 |