Hi Marios,

Maybe you might find this little sql idea useful:
db.execute('select foo from bar where foofield = %s or %s is null', (foofield,foofield,))

When foofield == None, then everything matches.

Have a good day !

Christophe.

ps: I didn't check precisely the syntax, so, adapt ;)

Le 23/06/2013 00:40, Marios Zindilis a écrit :
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.


--
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.


Reply via email to