Skip to content

Instantly share code, notes, and snippets.

@roooodcastro
Last active October 6, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roooodcastro/7afe4f2877f0ec1681d350def8406902 to your computer and use it in GitHub Desktop.
Save roooodcastro/7afe4f2877f0ec1681d350def8406902 to your computer and use it in GitHub Desktop.
Fixes Arel's pagination issue for Oracle https://github.com/rails/arel/issues/438
if o.limit && o.offset
o = o.dup
limit = o.limit.expr
offset = o.offset
o.offset = nil
offset_bind = nil
collector << "
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM ("
collector = super(o, collector)
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
end
@roooodcastro
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment