excluding order and limit from count queries

This commit is contained in:
Blake Eggleston
2013-10-25 17:23:51 -07:00
parent 647ebaf5f0
commit ec2337858c
2 changed files with 5 additions and 3 deletions

View File

@@ -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:

View File

@@ -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')