From ec2337858c011799d796bb7405af548828d3a0a4 Mon Sep 17 00:00:00 2001 From: Blake Eggleston Date: Fri, 25 Oct 2013 17:23:51 -0700 Subject: [PATCH] excluding order and limit from count queries --- cqlengine/statements.py | 4 ++-- cqlengine/tests/statements/test_select_statement.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cqlengine/statements.py b/cqlengine/statements.py index 45124c76..55dfa277 100644 --- a/cqlengine/statements.py +++ b/cqlengine/statements.py @@ -138,10 +138,10 @@ class SelectStatement(BaseCQLStatement): if self.where_clauses: qs += [self._where] - if self.order_by: + if self.order_by and not self.count: qs += ['ORDER BY {}'.format(', '.join(unicode(o) for o in self.order_by))] - if self.limit: + if self.limit and not self.count: qs += ['LIMIT {}'.format(self.limit)] if self.allow_filtering: diff --git a/cqlengine/tests/statements/test_select_statement.py b/cqlengine/tests/statements/test_select_statement.py index 4150ef3b..495258c2 100644 --- a/cqlengine/tests/statements/test_select_statement.py +++ b/cqlengine/tests/statements/test_select_statement.py @@ -33,9 +33,11 @@ class SelectStatementTests(TestCase): self.assertEqual(unicode(ss), 'SELECT * FROM table WHERE "a" = :0', unicode(ss)) def test_count(self): - ss = SelectStatement('table', count=True) + ss = SelectStatement('table', count=True, limit=10, order_by='d') ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b')) self.assertEqual(unicode(ss), 'SELECT COUNT(*) FROM table WHERE "a" = :0', unicode(ss)) + self.assertNotIn('LIMIT', unicode(ss)) + self.assertNotIn('ORDER', unicode(ss)) def test_context(self): ss = SelectStatement('table')