Hello! Sorry for late answer. I was busy with my job and away from
SQLObject. :(

On Thu, Mar 02, 2006 at 06:22:27PM +0530, Rajeev J Sebastian wrote:
> I would like for instance something like this:
> 
> queryData = AND( SWITCH("searchByFirstName",
>                       CONTAINSTRING( Person.q.firstName, VAR("defaultParam", 
> type="String") )
>                                          )
>                            )
> With such a queryData, when I do:
> Person.select( queryData, .... , options={ "searchByFirstName":False } )
>
> .. it should generate something similiar to
> Person.select( AND(1), ... )
>
> or if I do:
> Person.select( queryData, .... , options={ "searchByFirstName":True,
> "defaultParam":"Ian" } )
> 
> ... it should generate something similiar to
> Person.select( AND(CONTAINSTRING(Person.q.firstName, "Ian") )
>
> The reason I want this, as you may already gather, is to "parametrize" the
> query. Also, I want to be able to switch elements out of or into the query by
> using the options dict. Another reason, is to be able to build a GUI from it,
> such as by traversing the Expression tree and looking for SWITCH and VAR, and
> building a GUI tree with checkboxes for each SWITCH and with appropriate
> controls for each VAR.
> 
> I think, I can implement the SWITCH and VAR just like SQLOp and does it, but
> the problem, as I can see it, is that the SQLExpression doesnt have access to
> its context, and so I cannot pass the options dict down the tree.

   SQLExpression doesn't need access to a context - it's enough to pass
parameters to it. I think you may try to go the following route:

class ParametrizedQuey(SQLExpression):
   def __init__(self, ....):
      ...

   def __call__(self, **options):
      return SomethingClever(self, **options)

Person.select(queryData(searchByFirstName=True, defaultParam="Ian")

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to