[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2018-06-28 Thread Anthony
On Thursday, June 28, 2018 at 10:34:47 AM UTC-4, Artem wrote: > > Dear Antony , > From your example : > query = ' OR '.join(str(db.product.id == i) for i in [list of ids]) > result type(query) is a string , could you tell me how to correctly > convert it to the pydal.objects.Query / Set ? >

[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2018-06-28 Thread Artem
Dear Antony , >From your example : query = ' OR '.join(str(db.product.id == i) for i in [list of ids]) result type(query) is a string , could you tell me how to correctly convert it to the pydal.objects.Query / Set ? I'm trying query = db(query) , and get a pydal.objects.Set , but can't use

[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2015-03-31 Thread gb
Thanks, Gary! Works perfectly. On Tuesday, March 31, 2015 at 4:27:12 PM UTC-6, Gray Kanarek wrote: You want belongs, I think: query = db.product.id.belongs((selected_ids)) On Saturday, March 28, 2015 at 12:14:44 PM UTC-4, gb wrote: What is the DAL Code to generate a query like this:

[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2015-03-31 Thread gb
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 =

[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2015-03-31 Thread Gray Kanarek
You want belongs, I think: query = db.product.id.belongs((selected_ids)) On Saturday, March 28, 2015 at 12:14:44 PM UTC-4, gb wrote: What is the DAL Code to generate a query like this: SELECT * FROM product WHERE product.id=1 OR product.id=2 OR product.id=3 OR product.id product.id=4 OR

[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2015-03-29 Thread Niphlod
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

[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2015-03-28 Thread JorgeH
from Massimo, in another reply today (https://groups.google.com/forum/#!topic/web2py/RqSBO2dZU4E) : query = db.flatpage.f==request.function is the same as query = query (db.flatpage.f==request.function) Build a query from another query On Saturday, March 28, 2015 at 11:14:44 AM

[web2py] Re: Write dynamic query in DAL without extra nested parentheses

2015-03-28 Thread Anthony
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