Commit a5b96113 authored by Jérome Perrin's avatar Jérome Perrin

handle provided key= to Query constructor even if the query value is a list


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22219 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7dd18f16
......@@ -179,6 +179,24 @@ class SimpleQuery(QueryMixin):
sql_expressions = {'where_expression': '1',
'select_expression_list': []}
# try to get search key type by the key definitions passed
if search_key_class is None:
if search_key == EXACT_MATCH_SEARCH_MODE:
search_key_class = RawKey
elif search_key == KEYWORD_SEARCH_MODE or \
(key in keyword_search_keys):
search_key_class = KeyWordKey
elif search_key == DATETIME_SEARCH_MODE or \
(key in datetime_search_keys):
search_key_class = DateTimeKey
elif search_key == FULL_TEXT_SEARCH_MODE or \
(key in full_text_search_keys):
search_key_class = FullTextKey
# get search class based on explicitly passed key type
if search_key_class is None:
search_key_class = self._getSearchKeyClassByType(type)
# some use cases where we can just return SQL without grammar staff
if key is None or (ignore_empty_string and \
isinstance(value, basestring) and \
......@@ -197,9 +215,6 @@ class SimpleQuery(QueryMixin):
sql_expressions = {'where_expression': "%s is NULL" % (key),
'select_expression_list': [],}
return sql_expressions
# get search class based on explicitly passed key type
if search_key_class is None:
search_key_class = self._getSearchKeyClassByType(type)
# we have a list of values and respective operator defined
if isinstance(value, (tuple, list)):
......@@ -259,20 +274,6 @@ class SimpleQuery(QueryMixin):
# try to guess by type of first_element in list
search_key_class = self._getSearchKeyClassByValue(value[0])
# try to get search key type by the key definitions passed
if search_key_class is None:
if search_key == EXACT_MATCH_SEARCH_MODE:
search_key_class = RawKey
elif search_key == KEYWORD_SEARCH_MODE or \
(key in keyword_search_keys):
search_key_class = KeyWordKey
elif search_key == DATETIME_SEARCH_MODE or \
(key in datetime_search_keys):
search_key_class = DateTimeKey
elif search_key == FULL_TEXT_SEARCH_MODE or \
(key in full_text_search_keys):
search_key_class = FullTextKey
# get search class based on value of value
if search_key_class is None:
search_key_class = self._getSearchKeyClassByValue(value)
......
......@@ -416,6 +416,21 @@ class TestQuery(unittest.TestCase):
select_expression_list=[]),
q.asSQLExpression())
def testListValuesInQuery(self):
q = Query(title=('Foo', 'Bar'))
self.assertEquals(
dict(where_expression="(((((title = 'Foo')))) OR ((((title = 'Bar')))))",
select_expression_list=[]),
q.asSQLExpression())
def testListValuesInQueryWithKey(self):
q = Query(title=('Foo', 'Bar'), key='Keyword')
self.assertEquals(
dict(where_expression=
"(((((title LIKE '%Foo%')))) OR ((((title LIKE '%Bar%')))))",
select_expression_list=[]),
q.asSQLExpression())
def test_suite():
suite = unittest.TestSuite()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment