.. changelog::
:version: 1.1.8
+ .. change::
+ :tags: bug, ext
+ :versions: 1.2.0b1
+
+ Added support for bound parameters, e.g. those normally set up
+ via :meth:`.Query.params`, to the :meth:`.baked.Result.count`
+ method. Previously, support for parameters were omitted. Pull request
+ courtesy Pat Deegan.
+
.. change::
:tags: bug, postgresql
:versions: 1.2.0b1
col = func.count(literal_column('*'))
bq = self.bq.with_criteria(lambda q: q.from_self(col))
- return bq.for_session(self.session).scalar()
+ return bq.for_session(self.session).params(self._params).scalar()
def scalar(self):
"""Return the first element of the first result or None
set([(8, 'ed'), (9, 'fred')])
)
+ def test_count_with_bindparams(self):
+ User = self.classes.User
+
+ bq = self.bakery(lambda s: s.query(User))
+
+ sess = Session()
+
+ eq_(
+ bq(sess).count(),
+ 4
+ )
+
+ bq += lambda q: q.filter(User.name == bindparam("uname"))
+ # calling with *args
+ eq_(
+ bq(sess).params(uname='fred').count(), 1
+ )
+ # with multiple params, the **kwargs will be used
+ bq += lambda q: q.filter(User.id == bindparam("anid"))
+ eq_(
+ bq(sess).params(uname='fred', anid=9).count(), 1
+ )
+ eq_(
+ # wrong id, so 0 results:
+ bq(sess).params(uname='fred', anid=8).count(), 0
+ )
+
+
def test_get_pk_w_null(self):
"""test the re-implementation of logic to do get with IS NULL."""