public
Fork of jeremyevans/sequel
Description: Sequel: The Database Toolkit for Ruby
Homepage: http://sequel.rubyforge.org
Clone URL: git://github.com/divoxx/sequel.git
Search Repo:
Use COUNT_FROM_SELF_OPTS to implement count w/ limit

Change implementation to use COUNT_FROM_SELF_OPTS and from_self method
to implement count of dataset w/ limit defined
divoxx (author)
Thu Jun 26 11:39:09 -0700 2008
commit  70b17cc5234739dc137519d01c6058c1f3c702dc
tree    8507dd650c4941f62ebf3502bc8acf1e5bc019e6
parent  c4f4f75ba91fcaf1e9eda863a3aa66e23b9dc5cc
...
6
7
8
9
 
10
11
12
...
59
60
61
62
63
64
65
66
67
68
 
69
70
71
...
6
7
8
 
9
10
11
12
...
59
60
61
 
 
 
 
 
 
 
62
63
64
65
0
@@ -6,7 +6,7 @@ module Sequel
0
     COLUMN_REF_RE1 = /\A([\w ]+)__([\w ]+)___([\w ]+)\z/.freeze
0
     COLUMN_REF_RE2 = /\A([\w ]+)___([\w ]+)\z/.freeze
0
     COLUMN_REF_RE3 = /\A([\w ]+)__([\w ]+)\z/.freeze
0
- COUNT_FROM_SELF_OPTS = [:distinct, :group, :sql]
0
+ COUNT_FROM_SELF_OPTS = [:distinct, :group, :sql, :limit]
0
     DATE_FORMAT = "DATE '%Y-%m-%d'".freeze
0
     N_ARITY_OPERATORS = ::Sequel::SQL::ComplexExpression::N_ARITY_OPERATORS
0
     NULL = "NULL".freeze
0
@@ -59,13 +59,7 @@ module Sequel
0
 
0
     # Returns the number of records in the dataset.
0
     def count
0
- count = options_overlap(COUNT_FROM_SELF_OPTS) ? from_self.count : single_value(STOCK_COUNT_OPTS).to_i
0
-
0
- if limit = opts[:limit]
0
- count = limit if count > limit
0
- end
0
-
0
- count
0
+ options_overlap(COUNT_FROM_SELF_OPTS) ? from_self.count : single_value(STOCK_COUNT_OPTS).to_i
0
     end
0
     alias_method :size, :count
0
 
...
1152
1153
1154
1155
1156
1157
 
 
1158
1159
1160
...
1152
1153
1154
 
 
 
1155
1156
1157
1158
1159
0
@@ -1152,9 +1152,8 @@ context "Dataset#count" do
0
   end
0
 
0
   specify "should return limit if count is greater than it" do
0
- ds = @dataset.limit(5)
0
- ds.should_receive(:single_value).and_return("10")
0
- ds.count.should be(5)
0
+ @dataset.limit(5).count.should == 1
0
+ @c.sql.should == "SELECT COUNT(*) FROM (SELECT * FROM test LIMIT 5) t1 LIMIT 1"
0
   end
0
 end
0
 

Comments

    No one has commented yet.