[web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread gbs
Yes, thanks, you'r right.

With you'r method, it's simple ;)
And you can make AND condition :

query &= db.mytable.tag == tag

OR condition :
query |= db.mytable.tag == tag

It's exactly what i'm seeking!
You'r solution, and Bruno's one, are perfect,

I hope that can help someone else,

Have a nice day!

On 11 fév, 00:23, Anthony  wrote:
> On Friday, February 10, 2012 6:19:09 PM UTC-5, gbs wrote:
>
> > I have try the solution of anthony, but i don't have the skill in
> > python to success..
> > (some error with 'Rows' object has no attribute 'select', etc ;)
>
> Once the query has been built, this should work:
>
> rows = db(query).select()
>
> Anthony


[web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread Anthony
On Friday, February 10, 2012 6:19:09 PM UTC-5, gbs wrote:
>
> I have try the solution of anthony, but i don't have the skill in 
> python to success.. 
> (some error with 'Rows' object has no attribute 'select', etc ;) 
>

Once the query has been built, this should work:

rows = db(query).select() 

Anthony


[web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread gbs
I have try the solution of anthony, but i don't have the skill in
python to success..
(some error with 'Rows' object has no attribute 'select', etc ;)

But it's my fault,

Thanks again

On 10 fév, 23:43, gbs  wrote:
> Thanks to all.
>
> I have test the first answer, from Bruno..
>
> It's work!
>
> Thanks a lot, i'm searching/reading during a long time!
>
> I will test the others solutions, why i think they are more simple/
> comprehensible for me :$
>
> Best regards
>
> ps : sorry for the language
>
> On 10 fév, 23:18, Bruno Rocha  wrote:
>
>
>
>
>
>
>
> > > *queries=[]*
> > > *if arg1 == "x": queries.append(db.table.field == x)*
> > > *if arg2 == "y": queries.append(db.table.otherfield == y)*
> > > *# many conditions here*
> > > *query = reduce(lambda a,b:(a&b),queries)*
> > > *db(query).select()*
>
> > On Fri, Feb 10, 2012 at 8:10 PM, gbs  wrote:
> > > Hi,
>
> > > i have search posts on this group, but i don't have found the solution
> > > of my question :$
>
> > > I have a table, wich display record of a database, nothing weird..
>
> > > I have made a form, so you can "filter" the result.
>
> > > You can check "Tag" of the record, "Status" of the record, so on...
>
> > > How can i create an sql "requete/statement" : ??
>
> > > sql = ""
> > > -- if tag :
> > >   sql += "tag = xxx"
> > > -- if status:
> > >   sql += " and status = xxx"
>
> > > result = db(sql).select()
>
> > > it's just an example, wich don't work, but i don't understand how to
> > > chain condition of a query :$
>
> > > Best regards
>
> > --
>
> > Bruno Rocha
> > [http://rochacbruno.com.br]


Re: [web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread Anthony
On Friday, February 10, 2012 5:35:50 PM UTC-5, Detectedstealth wrote:
>
> sql = db
> -- if tag :
>   sql = sql(db.mytable.tag = "xxx")
> -- if status:
>   sql = sql(db.mytable.status = "xxx")
>
> result = sql.select()


Yes, that's nice too. It works because the Set object is callable, and 
calling it adds a new condition to its query.

Anthony 


[web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread gbs
Thanks to all.

I have test the first answer, from Bruno..

It's work!

Thanks a lot, i'm searching/reading during a long time!

I will test the others solutions, why i think they are more simple/
comprehensible for me :$

Best regards

ps : sorry for the language

On 10 fév, 23:18, Bruno Rocha  wrote:
> > *queries=[]*
> > *if arg1 == "x": queries.append(db.table.field == x)*
> > *if arg2 == "y": queries.append(db.table.otherfield == y)*
> > *# many conditions here*
> > *query = reduce(lambda a,b:(a&b),queries)*
> > *db(query).select()*
>
> On Fri, Feb 10, 2012 at 8:10 PM, gbs  wrote:
> > Hi,
>
> > i have search posts on this group, but i don't have found the solution
> > of my question :$
>
> > I have a table, wich display record of a database, nothing weird..
>
> > I have made a form, so you can "filter" the result.
>
> > You can check "Tag" of the record, "Status" of the record, so on...
>
> > How can i create an sql "requete/statement" : ??
>
> > sql = ""
> > -- if tag :
> >   sql += "tag = xxx"
> > -- if status:
> >   sql += " and status = xxx"
>
> > result = db(sql).select()
>
> > it's just an example, wich don't work, but i don't understand how to
> > chain condition of a query :$
>
> > Best regards
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]


Re: [web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread Bruce Wade
sql = db
-- if tag :
  sql = sql(db.mytable.tag = "xxx")
-- if status:
  sql = sql(db.mytable.status = "xxx")

result = sql.select()

On Fri, Feb 10, 2012 at 2:25 PM, Anthony  wrote:

> You could do something like:
>
> query = db.mytable.id > 0
> if tag:
> query &= db.mytable.tag == tag
> if status:
> query &= db.mytable.status == status
>
> Anthony
>
>
> On Friday, February 10, 2012 5:10:01 PM UTC-5, gbs wrote:
>>
>> Hi,
>>
>> i have search posts on this group, but i don't have found the solution
>> of my question :$
>>
>> I have a table, wich display record of a database, nothing weird..
>>
>> I have made a form, so you can "filter" the result.
>>
>> You can check "Tag" of the record, "Status" of the record, so on...
>>
>> How can i create an sql "requete/statement" : ??
>>
>> sql = ""
>> -- if tag :
>>sql += "tag = xxx"
>> -- if status:
>>sql += " and status = xxx"
>>
>> result = db(sql).select()
>>
>> it's just an example, wich don't work, but i don't understand how to
>> chain condition of a query :$
>>
>> Best regards
>
>


-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


[web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread Anthony
You could do something like:

query = db.mytable.id > 0
if tag:
query &= db.mytable.tag == tag
if status:
query &= db.mytable.status == status

Anthony

On Friday, February 10, 2012 5:10:01 PM UTC-5, gbs wrote:
>
> Hi, 
>
> i have search posts on this group, but i don't have found the solution 
> of my question :$ 
>
> I have a table, wich display record of a database, nothing weird.. 
>
> I have made a form, so you can "filter" the result. 
>
> You can check "Tag" of the record, "Status" of the record, so on... 
>
> How can i create an sql "requete/statement" : ?? 
>
> sql = "" 
> -- if tag : 
>sql += "tag = xxx" 
> -- if status: 
>sql += " and status = xxx" 
>
> result = db(sql).select() 
>
> it's just an example, wich don't work, but i don't understand how to 
> chain condition of a query :$ 
>
> Best regards



[web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread gbs
Oh? you think?

Ok i will test, thanks a lot!

On 10 fév, 23:18, Bruno Rocha  wrote:
> > *queries=[]*
> > *if arg1 == "x": queries.append(db.table.field == x)*
> > *if arg2 == "y": queries.append(db.table.otherfield == y)*
> > *# many conditions here*
> > *query = reduce(lambda a,b:(a&b),queries)*
> > *db(query).select()*
>
> On Fri, Feb 10, 2012 at 8:10 PM, gbs  wrote:
> > Hi,
>
> > i have search posts on this group, but i don't have found the solution
> > of my question :$
>
> > I have a table, wich display record of a database, nothing weird..
>
> > I have made a form, so you can "filter" the result.
>
> > You can check "Tag" of the record, "Status" of the record, so on...
>
> > How can i create an sql "requete/statement" : ??
>
> > sql = ""
> > -- if tag :
> >   sql += "tag = xxx"
> > -- if status:
> >   sql += " and status = xxx"
>
> > result = db(sql).select()
>
> > it's just an example, wich don't work, but i don't understand how to
> > chain condition of a query :$
>
> > Best regards
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]


[web2py] Re: Chain/Multiple condition on select

2012-02-10 Thread gbs

I know that you can do :
result = db((db.xxx.tag==tag) & (db.xxx.status==status)).select()

But i don't know how to generate the condition, one by one...





On 10 fév, 23:10, gbs  wrote:
> Hi,
>
> i have search posts on this group, but i don't have found the solution
> of my question :$
>
> I have a table, wich display record of a database, nothing weird..
>
> I have made a form, so you can "filter" the result.
>
> You can check "Tag" of the record, "Status" of the record, so on...
>
> How can i create an sql "requete/statement" : ??
>
> sql = ""
> -- if tag :
>    sql += "tag = xxx"
> -- if status:
>    sql += " and status = xxx"
>
> result = db(sql).select()
>
> it's just an example, wich don't work, but i don't understand how to
> chain condition of a query :$
>
> Best regards