Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#219 select(limit=n) - limit keyword is not recognized

closed-fixed
Oleg Broytman
General (126)
5
2007-04-17
2007-04-12
kumar mcmillan
No

0.8.1 release

here is a failing test case :(

from sqlobject import *
def test():
c = connectionForURI('sqlite:/:memory:')
class Foo(SQLObject):
bar = 1
Foo.createTable(connection=c)
f = Foo(connection=c)
f = Foo(connection=c)
assert Foo.select(connection=c).count() == 2
assert Foo.select(connection=c, limit=1).count() == 1

if __name__ == '__main__':
test()

Discussion

1 2 > >> (Page 1 of 2)
  • kumar mcmillan
    kumar mcmillan
    2007-04-12

    failing test to reproduce limit bug

     
    Attachments
  • kumar mcmillan
    kumar mcmillan
    2007-04-12

    Logged In: YES
    user_id=540473
    Originator: YES

    tested in SQLObject-0.10dev_r2521-py2.4.egg ... still broken

     
  • Oleg Broytman
    Oleg Broytman
    2007-04-16

    Logged In: YES
    user_id=4799
    Originator: NO

    Using both COUNT() and LIMIT is meaningless. LIMIT limits the number of rows returned by SELECT, but SELECT COUNT() returns exactly 1 (one) row, so what are you limiting?

    If you want to limit what SELECT * returns and later count it - use few separate queries, or a complex query with subqueries.

     
  • Oleg Broytman
    Oleg Broytman
    2007-04-16

    • status: open --> closed-invalid
     
  • kumar mcmillan
    kumar mcmillan
    2007-04-16

    a better failing test to reproduce limit bug

     
    Attachments
  • kumar mcmillan
    kumar mcmillan
    2007-04-16

    Logged In: YES
    user_id=540473
    Originator: YES

    sorry, bad example. The bug is not with count(), it is with sql reproduction of the entire select. It is not including the limit=limit part of the query. Here is a better test, still failing.

    from sqlobject import *
    def test():
    c = connectionForURI('sqlite:/:memory:')
    class Foo(SQLObject):
    bar = StringCol()
    Foo.createTable(connection=c)
    f = Foo(bar='bar', connection=c)
    f = Foo(bar='foo', connection=c)
    rs = Foo.select(connection=c)
    assert len(list(rs)) == 2
    rs = Foo.select(connection=c, limit=1)
    print rs
    assert len(list(rs)) == 1

    if __name__ == '__main__':
    test()
    print "OK"

    File Added: test_sresults.py

     
  • kumar mcmillan
    kumar mcmillan
    2007-04-16

    • status: closed-invalid --> open-invalid
     
  • Oleg Broytman
    Oleg Broytman
    2007-04-16

    • assigned_to: nobody --> phd
    • status: open-invalid --> open-later
     
  • Oleg Broytman
    Oleg Broytman
    2007-04-16

    Logged In: YES
    user_id=4799
    Originator: NO

    Yes, that's a long-standing bug in SelectResults. Meanwhile you can use .select()[:1] or .select().limit(1).

     
  • Oleg Broytman
    Oleg Broytman
    2007-04-17

    • status: open-later --> closed-fixed
     
1 2 > >> (Page 1 of 2)