When you have a clause you'd need to descend through the structure in the appropriate way to link bind parameters with associated column elements. An expression like "x = :param" would require looking at the "left" and "right" elements of a _BinaryClause, but bind parameters can occur in other places besides comparisons against single columns, such as embedded within a cast(), in_(), compared against a subquery, etc.
A routine that is closely tailored towards distilling clauses into pairs of scalar expression elements is sqlalchemy.sql.util.criterion_as_pairs. I'd advise reading its source to understand how it works, and either use it directly or adapt it to your needs. It builds upon the traversal routines in sqlalchemy.sql.visitors which are also worth knowing for a task like this one. On Dec 27, 2010, at 9:42 PM, Will Weaver wrote: > Does the lack of a response mean that it can't be done or just that no > one knows how to do it? Or did I not ask the question good enough? > > On Tue, Dec 21, 2010 at 12:02 PM, Will <[email protected]> wrote: >> In continuation of the following post >> >> http://groups.google.com/group/sqlalchemy/browse_thread/thread/160870682c011611/8229a3eb9c10f870?lnk=gst&q=parameters+select#8229a3eb9c10f870 >> >> Is there a way to get the columns that the bind parameters correspond >> to? I was able to get the param values but that's half the battle. >> >> In [11]: print clause >> SELECT count(1) AS count_1 >> FROM links >> WHERE :param_1 = links.foo_id AND :param_2 = ana.links.bar_id >> >> In [12]: compiled = clause.compile() >> >> In [13]: print compiled.params >> {u'param_1': 8, u'param_2': 1} >> >> -- >> 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. > > -- > 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. > -- 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.
