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

Fix paginate_by_sql for MSSQL adapter #289

Closed
wants to merge 2 commits into from

Conversation

denniskis
Copy link

paginate_by_sql adds LIMIT option which is not working with MSSQL.

LIMIT option is not working with MSSQL.
Fix mssql support for paginate_by_sql
@viegasfh
Copy link

viegasfh commented May 5, 2013

Same holds true for Firebird SQL. I modifed active_record.rb as follows:

      oracle = self.connection.adapter_name =~ /^(oracle|oci$)/i
      firebird = self.connection.adapter_name == 'Rubyfb'

      # add limit, offset
      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
      elsif firebird
        query << " ROWS #{pager.offset+1} TO #{pager.per_page+pager.offset}"
      else
        query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
      end

This will work with Rubyfb driver or Firebird, and it only supports Firebird 2.0+

@tflanitzer
Copy link

The problem reported by denniskis still exists after 2 years. Merging this into a near future release would be highly appreciated.

@mislav mislav closed this in f63844a Oct 22, 2019
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

Successfully merging this pull request may close these issues.

3 participants