Skip to content

Fix pagination on SQL Server 2000 with GROUP clause (Fix #367) #369

Closed
wants to merge 2 commits into from

2 participants

@pschambacher

The pagination condition was added before the ORDER condition.
If there is a GROUP BY clause, the pagination was in the GROUP BY
instead of the WHERE clause. New approach is extracting each clause and
build a new proper query.

@pschambacher pschambacher Fix #367 pagination not working with group on SQLSERVER 2000.
The pagination condition was added before the ORDER condition.
If there is a GROUP BY clause, the pagination was in the GROUP BY
instead of the WHERE clause. New approach is extraction each clause and
build a new proper query.
4bed7eb
@kares
JRuby Team member
kares commented Apr 9, 2013

fix is on master as 8e85d2f but the newly added test fails for me on 2012 :

Error: test_limit_with_group_by(MSSQLLimitOffsetTest)
  ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: Column 'long_ships.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.: SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY long_ships.id) AS _row_num, [long_ships].* FROM [long_ships]  GROUP BY name) AS t WHERE t._row_num BETWEEN 1 AND 2
arjdbc/jdbc/RubyJdbcConnection.java:439:in `execute_query_raw'
/home/kares/workspace/github/activerecord-jdbc-adapter/lib/arjdbc/jdbc/adapter.rb:283:in `exec_query_raw'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `log'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:19:in `instrument'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/kares/workspace/github/activerecord-jdbc-adapter/lib/arjdbc/jdbc/adapter.rb:282:in `exec_query_raw'
/home/kares/workspace/github/activerecord-jdbc-adapter/lib/arjdbc/jdbc/adapter.rb:301:in `select'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/querying.rb:38:in `find_by_sql'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/explain.rb:41:in `logging_query_plan'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/querying.rb:37:in `find_by_sql'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/relation.rb:171:in `exec_queries'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/relation.rb:160:in `to_a'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/explain.rb:41:in `logging_query_plan'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/relation.rb:159:in `to_a'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:159:in `all'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:105:in `find'
/opt/local/rvm/gems/jruby-1.7.3@jdbc/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:101:in `find'
/home/kares/workspace/github/activerecord-jdbc-adapter/test/db/mssql/limit_offset_test.rb:177:in `test_limit_with_group_by'
     174:       LongShip.create!(:name => name)
     175:     end
     176: 
  => 177:     ships = LongShip.group(:name).find(:all, :limit => 2)

could you please look at it if the failure occurs at your side as well ?
might be caused by refactorings done since you updated master ...

@pschambacher

Oh yeah I forgot once again that SQL Server doesn't know how to deal with this ... I'll fix this !

@pschambacher

Sorry about that.

Is there a documentation somewhere how to configure your computer and database to run the tests ?
This way I would be able to run them locally (at least for MSSQL2000 and 2005)

@kares
JRuby Team member
kares commented Apr 9, 2013

not really but if you go through the tests you'll find out, this should be sufficient to read to get started :
https://github.com/jruby/activerecord-jdbc-adapter/blob/master/test/db/mssql.rb

@kares kares closed this May 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.