Like this:
web.select("Content", where="Type=$type AND Title=$title", vars={"type":
"A", "title": "The Title"})
On Sun, Jun 23, 2013 at 4:10 AM, Marios Zindilis <[email protected]>wrote:
> I want to run a SELECT query on my database, in which there might be 0 or
> 1 or 2 WHERE conditions. The query runs in a function, e.g:
>
> def GetContent(Title=None, Type=None):
> return db.select('Content')
>
> What I want to do is use the Title and Type parameters as WHERE
> conditions, for example if only Title is specified, the query would be:
>
> SELECT * FROM Content WHERE Title='The Title';
>
> Or if only Type is specified, then the query should be:
>
> SELECT * FROM Content WHERE Type='A';
>
> But if both are defined then:
>
> SELECT * FROM Content WHERE Type='A' AND Title='The Title';
>
> I don't get how to create the 'WHERE ... AND ...' thing properly in
> web.py, and Anand said in another message on the list that it's a bad idea
> to build the query by concatenating strings.
>
> --
> Marios Zindilis
>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
> webpy+unsubscribe@**googlegroups.com<webpy%[email protected]>
> .
> To post to this group, send email to [email protected].
> Visit this group at
> http://groups.google.com/**group/webpy<http://groups.google.com/group/webpy>
> .
> For more options, visit
> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
> .
>
>
>
--
Anand
http://anandology.com/
--
You received this message because you are subscribed to the Google Groups
"web.py" 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/webpy.
For more options, visit https://groups.google.com/groups/opt_out.