Permalink
Browse files

Fix use of limit with distinct on Microsoft SQL Server (Fixes #297)

Add a general test for limit and distinct which passes on all
tested adapters.
  • Loading branch information...
1 parent cda21c9 commit 582ef633e0191d5700b9c280ab1e46284ddb45e2 @jeremyevans committed Apr 27, 2010
Showing with 7 additions and 1 deletion.
  1. +2 −0 CHANGELOG
  2. +1 −1 lib/sequel/adapters/shared/mssql.rb
  3. +4 −0 spec/integration/dataset_test.rb
View
2 CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Fix use of limit with distinct on Microsoft SQL Server (jeremyevans) (#297)
+
* Correctly swallow errors when using :ignore_index_errors in Database#create_table when using unsupported indexes (jeremyevans) (#295)
* Fix returning autogenerated keys when using the 5.1.12 MySQL JDBC driver (viking)
View
2 lib/sequel/adapters/shared/mssql.rb
@@ -198,7 +198,7 @@ module DatasetMethods
COMMA_SEPARATOR = ', '.freeze
DELETE_CLAUSE_METHODS = Dataset.clause_methods(:delete, %w'with from output from2 where')
INSERT_CLAUSE_METHODS = Dataset.clause_methods(:insert, %w'with into columns output values')
- SELECT_CLAUSE_METHODS = Dataset.clause_methods(:select, %w'with limit distinct columns into from lock join where group having order compounds')
+ SELECT_CLAUSE_METHODS = Dataset.clause_methods(:select, %w'with distinct limit columns into from lock join where group having order compounds')
UPDATE_CLAUSE_METHODS = Dataset.clause_methods(:update, %w'with table set output from where')
NOLOCK = ' WITH (NOLOCK)'.freeze
UPDLOCK = ' WITH (UPDLOCK)'.freeze
View
4 spec/integration/dataset_test.rb
@@ -59,6 +59,10 @@
@ds.first.should == {:id=>1, :number=>10}
end
+ specify "should have distinct work with limit" do
+ @ds.limit(1).distinct.all.should == [{:id=>1, :number=>10}]
+ end
+
specify "should fetch correctly with a limit" do
@ds.order(:id).limit(2).all.should == [{:id=>1, :number=>10}]
@ds.insert(:number=>20)

0 comments on commit 582ef63

Please sign in to comment.