Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tamersalama opened this issue Jun 22, 2012 · 1 comment

Comments

@tamersalama
Copy link

With per_page set to 10; First page will retrieve 110, Second page will retrieve 1020 (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

@tamersalama
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant