diff options
Diffstat (limited to 'lib/arel/visitors/oracle.rb')
-rw-r--r-- | lib/arel/visitors/oracle.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb index 875b0e5b6a..3b452836db 100644 --- a/lib/arel/visitors/oracle.rb +++ b/lib/arel/visitors/oracle.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Arel module Visitors class Oracle < Arel::Visitors::ToSql @@ -26,11 +27,22 @@ module Arel FROM (" collector = super(o, collector) - collector << ") raw_sql_ + + if offset.expr.is_a? Nodes::BindParam + offset_bind = nil + collector << ') raw_sql_ WHERE rownum <= (' + collector.add_bind(offset.expr) { |i| offset_bind = ":a#{i}" } + collector << ' + ' + collector.add_bind(limit) { |i| ":a#{i}" } + collector << ") ) WHERE raw_rnum_ > #{offset_bind}" + return collector + else + collector << ") raw_sql_ WHERE rownum <= #{offset.expr.to_i + limit} ) WHERE " - return visit(offset, collector) + return visit(offset, collector) + end end if o.limit @@ -125,7 +137,7 @@ module Arel array[i] << ',' << part else # to ensure that array[i] will be String and not Arel::Nodes::SqlLiteral - array[i] = '' << part + array[i] = part.to_s end i += 1 if array[i].count('(') == array[i].count(')') end |