adding where clause equality method
This commit is contained in:
@@ -540,7 +540,6 @@ class AbstractQuerySet(object):
|
||||
if self._batch:
|
||||
raise CQLEngineException("Only inserts, updates, and deletes are available in batch mode")
|
||||
|
||||
#TODO: check for previous query execution and return row count if it exists
|
||||
if self._result_cache is None:
|
||||
query = self._select_query()
|
||||
query.count = True
|
||||
|
||||
@@ -50,6 +50,14 @@ class BaseClause(object):
|
||||
def __str__(self):
|
||||
return unicode(self).encode('utf-8')
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, self.__class__):
|
||||
return self.field == other.field and self.value == other.value
|
||||
return False
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def get_context_size(self):
|
||||
""" returns the number of entries this clause will add to the query context """
|
||||
return 1
|
||||
@@ -78,6 +86,11 @@ class WhereClause(BaseClause):
|
||||
def __unicode__(self):
|
||||
return u'"{}" {} :{}'.format(self.field, self.operator, self.context_id)
|
||||
|
||||
def __eq__(self, other):
|
||||
if super(WhereClause, self).__eq__(other):
|
||||
return self.operator.__class__ == other.operator.__class__
|
||||
return False
|
||||
|
||||
def update_context(self, ctx):
|
||||
if isinstance(self.operator, InOperator):
|
||||
ctx[str(self.context_id)] = InQuoter(self.value)
|
||||
|
||||
0
cqlengine/tests/statements/test_quoter.py
Normal file
0
cqlengine/tests/statements/test_quoter.py
Normal file
@@ -16,3 +16,9 @@ class TestWhereClause(TestCase):
|
||||
wc.set_context_id(5)
|
||||
self.assertEqual('"a" = :5', unicode(wc))
|
||||
self.assertEqual('"a" = :5', str(wc))
|
||||
|
||||
def test_equality_method(self):
|
||||
""" tests that 2 identical where clauses evaluate as == """
|
||||
wc1 = WhereClause('a', EqualsOperator(), 'c')
|
||||
wc2 = WhereClause('a', EqualsOperator(), 'c')
|
||||
assert wc1 == wc2
|
||||
|
||||
Reference in New Issue
Block a user