Skip to content

Commit

Permalink
remove "AS count_table" alias from paginate_by_sql counter SQL
Browse files Browse the repository at this point in the history
it's not supported by Oracle and not needed for other RDBMS
[mislav#237 state:resolved]
  • Loading branch information
mislav committed May 20, 2009
1 parent 8c31282 commit 6dc60a9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
4 changes: 0 additions & 4 deletions lib/will_paginate/finder.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/finder_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6dc60a9

Please sign in to comment.