Skip to content
Browse files

remove "AS count_table" alias from `paginate_by_sql` counter SQL

it's not supported by Oracle and not needed for other RDBMS
[#237 state:resolved]
  • Loading branch information...
1 parent 8c31282 commit 6dc60a9f6140b23220afaf0ced1c98e2072ba59a @mislav committed
Showing with 2 additions and 6 deletions.
  1. +0 −4 lib/will_paginate/finder.rb
  2. +2 −2 test/finder_test.rb
View
4 lib/will_paginate/finder.rb
@@ -140,10 +140,6 @@ def paginate_by_sql(sql, options)
unless pager.total_entries
count_query = original_query.sub /\bORDER\s+BY\s+[\w`,\s]+$/mi, ''
count_query = "SELECT COUNT(*) FROM (#{count_query})"
-
- unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase)
- count_query << ' AS count_table'
- end
# perform the count query
pager.total_entries = count_by_sql(count_query)
end
View
4 test/finder_test.rb
@@ -363,7 +363,7 @@ def test_should_use_scoped_finders_if_present
def test_paginate_by_sql
assert_respond_to Developer, :paginate_by_sql
Developer.expects(:find_by_sql).with(regexp_matches(/sql LIMIT 3(,| OFFSET) 3/)).returns([])
- Developer.expects(:count_by_sql).with('SELECT COUNT(*) FROM (sql) AS count_table').returns(0)
+ Developer.expects(:count_by_sql).with('SELECT COUNT(*) FROM (sql)').returns(0)
entries = Developer.paginate_by_sql 'sql', :page => 2, :per_page => 3
end
@@ -378,7 +378,7 @@ def test_paginate_by_sql_respects_total_entries_setting
def test_paginate_by_sql_strips_order_by_when_counting
Developer.expects(:find_by_sql).returns([])
- Developer.expects(:count_by_sql).with("SELECT COUNT(*) FROM (sql\n ) AS count_table").returns(0)
+ Developer.expects(:count_by_sql).with("SELECT COUNT(*) FROM (sql\n )").returns(0)
Developer.paginate_by_sql "sql\n ORDER\nby foo, bar, `baz` ASC", :page => 2
end

0 comments on commit 6dc60a9

Please sign in to comment.
Something went wrong with that request. Please try again.