diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 19:16:33 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 19:16:33 -0700 |
commit | 3ec26142a9f9f036bc3f763adac8fa38048d0a76 (patch) | |
tree | d46a2eb27747abe60274184c7e3fa7d39cc69f69 /lib/arel/visitors | |
parent | b2fb1d3381027176505e8709acd22295fb57597a (diff) | |
download | rails-3ec26142a9f9f036bc3f763adac8fa38048d0a76.tar.gz rails-3ec26142a9f9f036bc3f763adac8fa38048d0a76.tar.bz2 rails-3ec26142a9f9f036bc3f763adac8fa38048d0a76.zip |
oracle tests passing
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/oracle.rb | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb index 0cd0179931..2cdbafadad 100644 --- a/lib/arel/visitors/oracle.rb +++ b/lib/arel/visitors/oracle.rb @@ -3,7 +3,7 @@ module Arel class Oracle < Arel::Visitors::ToSql private - def visit_Arel_Nodes_SelectStatement o + def visit_Arel_Nodes_SelectStatement o, collector o = order_hacks(o) # if need to select first records without ORDER BY and GROUP BY and without DISTINCT @@ -20,49 +20,58 @@ module Arel limit = o.limit.expr.to_i offset = o.offset o.offset = nil - sql = super(o) - return <<-eosql + collector << " SELECT * FROM ( SELECT raw_sql_.*, rownum raw_rnum_ - FROM (#{sql}) raw_sql_ + FROM (" + + collector = super(o, collector) + collector << ") raw_sql_ WHERE rownum <= #{offset.expr.to_i + limit} ) - WHERE #{visit offset} - eosql + WHERE " + return visit(offset, collector) end if o.limit o = o.dup limit = o.limit.expr - return "SELECT * FROM (#{super(o)}) WHERE ROWNUM <= #{visit limit}" + collector << "SELECT * FROM (" + collector = super(o, collector) + collector << ") WHERE ROWNUM <= " + return visit limit, collector end if o.offset o = o.dup offset = o.offset o.offset = nil - sql = super(o) - return <<-eosql - SELECT * FROM ( + collector << "SELECT * FROM ( SELECT raw_sql_.*, rownum raw_rnum_ - FROM (#{sql}) raw_sql_ + FROM (" + collector = super(o, collector) + collector << ") raw_sql_ ) - WHERE #{visit offset} - eosql + WHERE " + return visit offset, collector end super end - def visit_Arel_Nodes_Limit o + def visit_Arel_Nodes_Limit o, collector + collector end - def visit_Arel_Nodes_Offset o - "raw_rnum_ > #{visit o.expr}" + def visit_Arel_Nodes_Offset o, collector + collector << "raw_rnum_ > " + visit o.expr, collector end - def visit_Arel_Nodes_Except o - "( #{visit o.left } MINUS #{visit o.right} )" + def visit_Arel_Nodes_Except o, collector + collector << "( " + collector = infix_value o, collector, " MINUS " + collector << " )" end def visit_Arel_Nodes_UpdateStatement o @@ -91,7 +100,7 @@ module Arel # # orders = o.orders.map { |x| visit x }.join(', ').split(',') orders = o.orders.map do |x| - string = visit x + string = visit(x, Arel::Collectors::SQLString.new).value if string.include?(',') split_order_string(string) else |