On Friday 15 February 2008 7:01 pm, Ed Leafe wrote:
> On Feb 12, 2008, at 9:36 PM, Adrian Klaver wrote:
> > This form has to to do with plants,
> > so a search might be "select from plant1 where (i)like '%mint%'"
> > How is
> > the best way to do this or can someone point me to an existing
> > example?
>
> Sound like you need a parameterized query. To do that, set the where
> clause with:
>
> self.addWhere("myfield ilike '%%%s%%' ")
>
> Note that the literal '%' have to be doubled up; the parameter place
> holder is the '%s' in the middle. Now override bizobj.getParams to
> return a tuple that contains a value for each of placeholders in your
> where clause. Note that if you do several addWhere calls with
> parameters in them, the order they are added determines the order of
> the values returned in the tuple from getParams(). In your example,
> assuming that the value 'mint' that you wanted in your query was in
> stored in an attribute named 'plantType', getParams() would look like:
>
> def getParams(self):
> return (self.plantType, )
>
> Hope that helps,
>
> -- Ed Leafe
The solution I came up is to use the setWhereClause() method of the dBizobj.
This allows me to change the field I am filtering. For example
biz.setWhereClause('p_item_no='+p_no) where p_no is derived from a value in a
dOkCancelDialog. Or I can do biz.setWhereClause('common ilike ' +srch_string)
using the same method. This way I don't run in the problem of addWhere's
accumulating. I then do:
biz.requery()
self.update()
and presto the form has the correct values.
--
Adrian Klaver
[EMAIL PROTECTED]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]