will_paginate icon indicating copy to clipboard operation
will_paginate copied to clipboard

paginate_by_sql and Oracle - the offset value results in repeating rows

Open tamersalama opened this issue 12 years ago • 1 comments

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

tamersalama avatar Jun 22 '12 16:06 tamersalama

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

tamersalama avatar Jun 22 '12 17:06 tamersalama