On Jul 15, 2008, at 4:49 AM, Lele Gaifax wrote:

>
> Hi all,
>
> I'd like to have a generic function that executes a given SQL query
> filtering it with conditions passed as keyword args, but I do not find
> a clean way to refer to the primitive columns (on the underlying
> table) instead of those already bound to the select.
>
> Given a simple select::
>
>>>> query = sometable.select()
>
> and a dictionary::
>
>>>> args = { 'somecolname': 'avalue', 'othercolname': 1 }
>
> I tried to implement a simple function::
>
>>>> def apply_filters(query, args):
>  ...     for colname in args:
>  ...         query = query.where(XXX(colname) == args[colname])
>  ...     return query
>
> I first tried using "query.columns[colname]" in place of the "XXX()"
> stub, but that does not do the job, because it brings in a subselect.
>
> Of course it works when I refer to the table columns, but how can I
> reach them having just the query on the table? I tried inspecting the
> query, that carries a "_raw_columns", or "_froms", but it does not
> seem a clean approach. What am I missing?
>
> Thanks in advance for any hint,

The _raw_columns is where they actually are...another thing that comes  
to mind is to use clause adaption, but again you'd need to know the  
specific Table object you'd want to adapt to.

The question is, if your select() selects from two tables which both  
have a column named "foo", which table would {'foo':'somevalue'} query  
against ?





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to