Am Freitag, 10. August 2007 15:02 schrieb Christoph Haas: > On Fri, Aug 10, 2007 at 02:51:51PM +0200, Hermann Himmelbauer wrote: > > My web-application, that is in front of SQLAlchemy has various > > input-fields, which should act as a where-clause (with like()), a query > > looks e.g. like this: > > > > session.query(MyObj).filter(table1.c.input1.like(inputfield_1+'%'), > > > > table1.c.input2.like(inputfield_2+'%'), ...) > > > > The problem is that if such an input field is empty, it should not be > > included in the query. If I rule out empty fields manually, I have 2^n > > if-clauses (I think), so I need to dynamically create the where-clauses > > in some way. > > > > What would be the best way to accomplish this? > > You are on the right track with "filter()" already. Consider this: > > result = session.query(MyObj) > if 'name' in params: > result=result.filter_by(name=params['name']) > if 'min_age' in params: > result=result.filter_by(age>=params['min_age'])
Ah nice! That's easy and works fine! Thanks! Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---