diff --git a/product/ZSQLCatalog/Operator/ComparisonOperator.py b/product/ZSQLCatalog/Operator/ComparisonOperator.py index 8379ceadedc4b6f5517004b7f7bedc088c95c71e..79895d68bcacd376e030b4fde530005040ef2763 100644 --- a/product/ZSQLCatalog/Operator/ComparisonOperator.py +++ b/product/ZSQLCatalog/Operator/ComparisonOperator.py @@ -183,5 +183,6 @@ operator_dict = { 'sphinxse': SphinxSEComparisonOperator('sphinxse'), 'in': MultivaluedComparisonOperator('in'), 'is': MonovaluedComparisonOperator('is'), + 'is not': MonovaluedComparisonOperator('is not', '!='), } diff --git a/product/ZSQLCatalog/Query/SimpleQuery.py b/product/ZSQLCatalog/Query/SimpleQuery.py index fab5959e38dc9572d9f620ed3b0249a064a6edff..dd4c7c1faddf7e012c584c9e13e004836af36f5f 100644 --- a/product/ZSQLCatalog/Query/SimpleQuery.py +++ b/product/ZSQLCatalog/Query/SimpleQuery.py @@ -34,6 +34,13 @@ from zope.interface.verify import verifyClass from Products.ZSQLCatalog.SQLCatalog import profiler_decorator, list_type_list from zLOG import LOG, WARNING +NULL_SEARCH_TEXT_OPERATOR_DICT = { + '=': 'is', + '!=': 'is not', +} +for value in NULL_SEARCH_TEXT_OPERATOR_DICT.values(): + NULL_SEARCH_TEXT_OPERATOR_DICT[value] = value + class SimpleQuery(Query): """ A SimpleQuery represents a single comparison between a single column and @@ -84,10 +91,12 @@ class SimpleQuery(Query): else: comparison_operator = 'in' if value is None: - if comparison_operator == '=': - comparison_operator = 'is' - elif comparison_operator != 'is': - raise ValueError, 'None value with a non-"=" comparison_operator (%r). Not sure what to do.' % (comparison_operator, ) + try: + comparison_operator = NULL_SEARCH_TEXT_OPERATOR_DICT[ + comparison_operator] + except KeyError: + raise ValueError('Unexpected comparison_operator %r for None value.' + % (comparison_operator, )) elif comparison_operator == 'is': raise ValueError, 'Non-None value (%r) with "is" comparison_operator. Not sure what to do.' % (value, ) self.value = value diff --git a/product/ZSQLCatalog/tests/testSQLCatalog.py b/product/ZSQLCatalog/tests/testSQLCatalog.py index 65d79104b9b72541d00e7bd329b711bdd1dbf452..58c801539246ec94c348aa43f50c15d5715868fe 100644 --- a/product/ZSQLCatalog/tests/testSQLCatalog.py +++ b/product/ZSQLCatalog/tests/testSQLCatalog.py @@ -575,6 +575,10 @@ class TestSQLCatalog(ERP5TypeTestCase): SimpleQuery(default=None)) self.assertEqual(ReferenceQuery(operator='is', default=None), SimpleQuery(default=None, comparison_operator='=')) + self.assertEqual(ReferenceQuery(operator='is not', default=None), + SimpleQuery(default=None, comparison_operator='!=')) + self.assertEqual(ReferenceQuery(operator='is not', default=None), + SimpleQuery(default=None, comparison_operator='is not')) self.assertRaises(ValueError, SimpleQuery, default=None, comparison_operator='>=') self.assertRaises(ValueError, SimpleQuery, default=1, comparison_operator='is')