[Sqlalchemy-tickets] Issue #3034: Use my own bindparam for Query.limit() (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Dobes V. <iss...@bi...> - 2014-04-24 21:16:24
|
New issue 3034: Use my own bindparam for Query.limit() https://bitbucket.org/zzzeek/sqlalchemy/issue/3034/use-my-own-bindparam-for-querylimit Dobes Vandermeer: I am trying to use the "baked query" pattern to reduce the time spent generating SQL, which currently is quite significant for our app. One thing I can't seem to parameterize using a bindparam, however, is the limit on the query. Although in #805 the limit was changed into a bindparam, this doesn't allow me to provide my own bindparam but rather always creates its own bindparam, assuming the limit I procide is a number already. I think that if the places where currently it wraps a numeric limit into a bindparam using sql.literal() it would also check if limit was already a bindparam then it would be good. Here's an example that can be pasted into the test suite: ``` #!python def test_select_with_bindparam_limit(self): """Does a query allow bindparam for the limit?""" sess = self._downgrade_fixture() users = [] def go(): users[:] = sess.query(self.classes.User)\ .order_by(self.classes.User.id)\ .limit(sa.bindparam('n'))\ .params(n=10)\ .all() self.assert_sql_count(testing.db, go, 2) ``` |