Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make Dataset#count use a subselect when the dataset has an offset wit…

…hout a limit (Fixed #587)

Dataset#count already used a subselect if there was a limit on
the dataset, but it didn't previously consider the offset without
limit case.
  • Loading branch information...
commit 1be7fcd890305ed561ae63970487941a7b67f27f 1 parent 3b54f02
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Make Dataset#count use a subselect when the dataset has an offset without a limit (jeremyevans) (#587)
+
* Dump deferrable status of unique indexes on PostgreSQL (radford) (#583)
* Support :deferrable constraints on PostgreSQL (radford) (#583)
View
2  lib/sequel/dataset/sql.rb
@@ -206,7 +206,7 @@ def self.clause_methods(type, clauses)
COMMA_SEPARATOR = COMMA
CONDITION_FALSE = '(1 = 0)'.freeze
CONDITION_TRUE = '(1 = 1)'.freeze
- COUNT_FROM_SELF_OPTS = [:distinct, :group, :sql, :limit, :compounds]
+ COUNT_FROM_SELF_OPTS = [:distinct, :group, :sql, :limit, :offset, :compounds]
COUNT_OF_ALL_AS_COUNT = SQL::Function.new(:count, WILDCARD).as(:count)
DATASET_ALIAS_BASE_NAME = 't'.freeze
DEFAULT = LiteralString.new('DEFAULT').freeze
View
5 spec/core/dataset_spec.rb
@@ -1885,6 +1885,11 @@ def d.to_s; "adsf" end
@db.sqls.should == ["SELECT COUNT(*) AS count FROM (SELECT * FROM test LIMIT 5) AS t1 LIMIT 1"]
end
+ specify "should work correctly with offsets" do
+ @dataset.limit(nil, 5).count.should == 1
+ @db.sqls.should == ["SELECT COUNT(*) AS count FROM (SELECT * FROM test OFFSET 5) AS t1 LIMIT 1"]
+ end
+
it "should work on a graphed_dataset" do
@dataset.should_receive(:columns).twice.and_return([:a])
@dataset.graph(@dataset, [:a], :table_alias=>:test2).count.should == 1
Please sign in to comment.
Something went wrong with that request. Please try again.