Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Rails 3 support for Oracle database in paginate_by_sql #96

Closed
wants to merge 1 commit into from

3 participants

@davesmylie

Small patch to support oracle database - this doesn't support the offset/limit keywords directly so must be faked with some extra sql.

Previously add_limits! handled this for you, but this has been removed in rails3.

Dave Smylie Oracle doesn't support the OFFSET and LIMIT keywords. Previously this…
… was handled here by the rails add_limit! method

but this was removed in rails3. Faking it for oracle with some additional queries.
117c45a
@quarklemotion

I had the same problem with will_paginate and rails3 with Oracle 10g and made a local monkey patch that does the exact technique you are using, the nested query rownum-based paging. From my research, this is the most recommended paging technique in Oracle. I am using this same technique on a large Java application as well and have not run into any performance issues, etc. I hope this gets merged in soon.

@mislav
Owner

Merge in c0e61aa

@mislav mislav closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2011
  1. Oracle doesn't support the OFFSET and LIMIT keywords. Previously this…

    Dave Smylie authored
    … was handled here by the rails add_limit! method
    
    but this was removed in rails3. Faking it for oracle with some additional queries.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 2 deletions.
  1. +10 −2 lib/will_paginate/finders/active_record.rb
View
12 lib/will_paginate/finders/active_record.rb
@@ -56,8 +56,16 @@ def paginate_by_sql(sql, options)
WillPaginate::Collection.create(*wp_parse_options(options)) do |pager|
query = sanitize_sql(sql.dup)
original_query = query.dup
- # add limit, offset
- query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
+
+ # add limit, offset. Oracle doesn't support LIMIT/OFFSET. This should be taken care of by Arel but
+ # for now, just manually add them in here.
+ if self.connection.adapter_name =~ /^(oracle|oci$)/i
+ query = "SELECT * FROM (SELECT raw_sql_.*, rownum raw_rnum_ FROM (#{query}) raw_sql_ WHERE " +
+ " rownum <= #{pager.offset + pager.per_page }) WHERE raw_rnum_ > #{pager.offset}"
+ else
+ query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
+ end
+
# perfom the find
pager.replace find_by_sql(query)
Something went wrong with that request. Please try again.