I think I might have found a bug with the limit method when a range is 
passed in.

For the record, my test environment is using jdbc-sqlite3 (3.7.2.1) with 
jRuby 1.7.4

DB[:items].limit(10..20) # SELECT * FROM items LIMIT 11 OFFSET 10

Seems to me that the offset should be 9 here.  From my tests, it looks like 
this is a bug.  
I monkey patched the 3.48 version which passed all of my tests.  

In the example above, I expect to get rows 10 thru 20 inclusive starting at 
row 10 which is an offset of 9.
So if I wanted row 1 then the offset would be 0.  

The patch below is from the latest code.

Index: lib/sequel/dataset/query.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/sequel/dataset/query.rb (revision 
6542c3b6bcf0e8a1fb45a77e9a72d09188a2f0bf)
+++ lib/sequel/dataset/query.rb (revision )
@@ -515,7 +515,7 @@
       return from_self.limit(l, o) if @opts[:sql]
 
       if l.is_a?(Range)
-        o = l.first
+        o = l.first - 1
         l = l.last - l.first + (l.exclude_end? ? 0 : 1)
       end
       l = l.to_i if l.is_a?(String) && !l.is_a?(LiteralString)


Without the patch, I have to do something like the following to make it 
work.

filtered_dataset.limit(endRow - startRow + 1, startRow - 1)

I would have tested the patch and generated a pull request but I cant 
figure out how to run the internal tests.

Thanks,

Keith

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to