Michael, thanks so much for the response.

right.key and right.*value*, that's what I was missing, guess the
default behavior is to print the key, so I didn't think about further
dissecting the object.

Yeah, I guess it's a bit unorthodox.  I've been trying to debug a parser
I'm writing to allow filter specifications in a web page and I'm
dynamically building the where clause from a query syntax similar to
Google's. I'm perfectly happy with the SA handling of the bind params,
it always does exactly what I tell it to.  But when it doesn't spit out
the results I'm expecting I just want to see what I ultimately ended up
passing to the database and find out where my parser went wrong.

I figured it was something small that was overlooking, and it was.  This
was so much help, I really appreciate it.

Michael Bayer wrote:
> im sorry this is giving you so much trouble...people usually dont ask
> about this since if they want to work with the bind parameters directly
> they usually use the bindparam() construct explicitly.
>
> this script will illustrate everything about the bind params:
>
> from sqlalchemy import *
>
> # create metadata using engine with mysql dialect
> meta = BoundMetaData('mysql://')
> t = Table( 'test', meta, Column('col1', Integer), Column('col2',
> Integer))
>
> # select statement
> s = t.select( t.c.col1 == 'somevalue' )
>
> # whereclause, in this case is a Boolean Expression
> print repr(s.whereclause)
>
> # string representation of whereclause, note it uses %s for the bind
> # param because the column "col1" is attached to "t" which loads in
> # the MySQL dialect which indicates the "format" paramstyle
> print s.whereclause
>
> # bind parameter by itself, doesnt know about MySQL dialect, so
> # defaults to :test_col1
> print s.whereclause.right
>
> # bind parameter is an instance of _BindParamClause
> print repr(s.whereclause.right)
>
> # key, value of the BindParamClause:
> print s.whereclause.right.key, s.whereclause.right.value
>
> # locate all binds in the select using the "visitor" interface
> class MyVisitor(ClauseVisitor):
>     def visit_bindparam(self, bindparam):
>         print bindparam.key, bindparam.value
> s.accept_visitor(MyVisitor())
>
> # full dictionary of binds also calulcated by the compile step
> # this dict is an instance of sql.ClauseParameters which has some
> # extra functionality
> print s.compile().get_params()
>
>
> >
>   


--~--~---------~--~----~------------~-------~--~----~
 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to