I have a list of products (much less than 1000) that the users can select
or unselect--I supposed I could only select on the unselected items.
If it's above 80 or so sqlite throws <class 'sqlite3.OperationalError'>
parser stack overflow, see code below:
db.define_table("product")
query = []
for i in xrange(90):
query.append(db.product.id == i)
query = reduce(lambda a,b:a|b,query)
db(query).select()
However, the suggested code works great!
query = db.product.id.belongs([list of ids])
Thanks, Anthony!
On Sunday, March 29, 2015 at 12:11:13 PM UTC-6, Niphlod wrote:
>
> btw: sqlite has a pretty "deep" default value that should handle 1000 of
> those "or". but or the sake of your app.... is it reaally necessary to
> fetch records in a single query asking for 1000 specific values ?
>
> On Saturday, March 28, 2015 at 6:37:03 PM UTC+1, Anthony wrote:
>>
>> In this particular case, you should instead use .belongs():
>>
>> query = db.product.id.belongs([list of ids])
>>
>> It's an interesting problem, though. A somewhat hackish solution would be:
>>
>> query = ' OR '.join(str(db.product.id == i) for i in [list of ids])
>>
>> The problem is that OR and AND operators always wrap the operands in
>> parentheses, even when not necessary. The result is the nesting you observe
>> when using reduce() or appending in a loop. Perhaps there should be a way
>> to suppress the parentheses when not needed.
>>
>> Anthony
>>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.