Skip to content

Instantly share code, notes, and snippets.

@rootatdarkstar
Last active September 29, 2016 12:35
Show Gist options
  • Save rootatdarkstar/91f12bb72a21313a5024a9c0c6a5629d to your computer and use it in GitHub Desktop.
Save rootatdarkstar/91f12bb72a21313a5024a9c0c6a5629d to your computer and use it in GitHub Desktop.
if o.limit && o.offset
o = o.dup
limit = o.limit.expr
offset = o.offset
o.offset = nil
collector << "
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM ("
collector = super(o, collector)
collector << ") raw_sql_
WHERE rownum <= ("
collector = collector.add_bind(offset.expr) { |i| ":a#{i}" }
@limit_placeholder = nil
collector << " + "
collector = collector.add_bind(limit) { |i| @limit_placeholder = ":a#{i}" }
collector << ")
)
WHERE "
collector << "raw_rnum_ > #{@limit_placeholder}"
return collector
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment