> > Is there a way to control what placeholder tokens are used for the bind
> params?
>
> yeah use bindparam():
>
> query.filter(MyClass.table == bindparam('foobar')).params(foobar=5)
>
> or
>
> query.filter(MyClass.table == bindparam('foobar', value=5))
>
I'll play around with this, thanks.
The names generated by SQLalchemy, i.e. :id_1, :id_2, etc. are deterministic
> - they will always be the same for the same query. If OTOH you're trying
> to get the SQLA Query object to exactly match SQL that is generated from
> something else, that seems like a pretty rough way to travel.
>
Yeah. We may decide it's too rough, and abandon it.
I have some code working that's based on the beaker_caching example.
The example code constructs cache keys by concatenating the query._entities
with the extracted bind parameter values. That approach works, but you can
end up with the same cache key for these two queries:
select foo from bar where id = 1
select foo from bar where id != 1
I think there various other collision cases.
My goal is to improve on the example, by hashing the entire query template,
and then using the hash + the extracted params as the key. But as you
say... reconstructing query objects in different parts of the app my be too
difficult in some cases. I think our fallback is going to be to use
synthetic query identifiers if necessary, and if we doing come up with
anything better.
--
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.