Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

paginate_by_sql and Oracle - the offset value results in repeating rows #247

Open
tamersalama opened this Issue · 1 comment

1 participant

Tamer Salama
Tamer Salama

With per_page set to 10; First page will retrieve 1~10, Second page will retrieve 10~20 (instead of 11 to 20).

This results in repeating edge rows between pages.

Rails 3.2.0
will_paginate 3.0.3
activerecord-oracle_enhanced-adapter 1.4.0

Tamer Salama

I monkey-patched the gem and changed the paginate_by_sql to add 1 to the offset

        def paginate_by_sql(sql, options)
         ...

          if oracle
            # Changed the offset adding 1
            query = <<-SQL
              SELECT * FROM (
                SELECT rownum rnum, a.* FROM (#{query}) a
                WHERE rownum <= #{pager.offset + pager.per_page}
              ) WHERE rnum >= #{pager.offset+1}
            SQL
          else
            ...
          end
          ...
        end

instead of

        def paginate_by_sql(sql, options)
         ...

          if oracle
            query = <<-SQL
              SELECT * FROM (
                SELECT rownum rnum, a.* FROM (#{query}) a
                WHERE rownum <= #{pager.offset + pager.per_page}
              ) WHERE rnum >= #{pager.offset}
            SQL
          else
            ...
          end
          ...
        end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.