Commit 76003bf4 authored by Jérome Perrin's avatar Jérome Perrin

Treat unicode objects as strings in SQLCatalog.buildSQLQuery



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9111 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4a163933
......@@ -726,4 +726,17 @@ class TestERP5Catalog(ERP5TypeTestCase):
module.searchFolder(group_uid=group_nexedi_category.getUid())]
self.assertEquals(organisation_list, [organisation])
def test_21_SearchingWithUnicode(self, quiet=quiet, run=run_all_test):
if not run: return
if not quiet:
message = 'Test searching with unicode'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
person_module = self.getPersonModule()
person_module.newContent(portal_type='Person', title='A Person')
get_transaction().commit()
self.tic()
self.assertNotEquals([], self.getCatalogTool().searchResults(
portal_type='Person', title=u'A Person'))
......@@ -1240,7 +1240,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Get the appropriate SQL Method
method = getattr(self, self.sql_getitem_by_path)
search_result = method(path = path, uid_only=1)
# If not emptyn return first record
# If not empty, return first record
if len(search_result) > 0:
return search_result[0].uid
else:
......@@ -1468,22 +1468,21 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# We must now turn sort_index into
# a dict with keys as sort keys and values as sort order
if type(sort_index) is type('a'):
if isinstance(sort_index, basestring):
sort_index = [(sort_index, so)]
elif type(sort_index) is not type(()) and type(sort_index) is not type([]):
elif not isinstance(sort_index, (list, tuple)):
sort_index = None
# If sort_index is a dictionnary
# then parse it and change it
sort_on = None
#LOG('sorting', 0, str(sort_index))
if sort_index is not None:
new_sort_index = []
for sort in sort_index:
if len(sort)==2:
new_sort_index.append((sort[0],sort[1],None))
elif len(sort)==3:
if len(sort) == 2:
new_sort_index.append((sort[0], sort[1], None))
elif len(sort) == 3:
new_sort_index.append(sort)
sort_index = new_sort_index
try:
......@@ -1580,7 +1579,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Add table to table dict
from_table_dict[acceptable_key_map[key][0]] = acceptable_key_map[key][0] # We use catalog by default
# Default case: variable equality
if type(value) is type('') or isinstance(value, DateTime):
if isinstance(value, basestring) or isinstance(value, DateTime):
# For security.
value = self._quoteSQLString(value)
if value != '' or not ignore_empty_string:
......@@ -1611,7 +1610,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
where_expression += ["MATCH %s AGAINST ('%s' %s)" % (key, value, mode)]
else:
where_expression += ["%s = '%s'" % (key, value)]
elif type(value) is type([]) or type(value) is type(()):
elif isinstance(value, (list, tuple)):
# We have to create an OR from tuple or list
query_item = []
for value_item in value:
......@@ -1639,11 +1638,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
query_item += ["%s = '%s'" % (key, value_item)]
if len(query_item) > 0:
where_expression += ['(%s)' % join(query_item, ' OR ')]
elif type(value) is type({}):
elif isinstance(value, dict):
# We are in the case of a complex query
query_item = []
query_value = value['query']
if type(query_value) != type([]) and type(query_value) != type(()) :
if not isinstance(query_value, (list, tuple)):
query_value = [query_value]
operator_value = sql_quote(value.get('operator', 'or'))
range_value = value.get('range')
......@@ -1671,10 +1670,10 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
elif key in topic_search_keys:
# ERP5 CPS compatibility
topic_operator = 'or'
if type(value) is type({}):
if isinstance(value, dict):
topic_operator = sql_quote(value.get('operator', 'or'))
value = value['query']
if type(value) is type(''):
if isinstance(value, basestring):
topic_value = [value]
else:
topic_value = value # list or tuple
......@@ -1718,7 +1717,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
where_expression = join(where_expression, ' AND ')
limit_expression = kw.get('limit', None)
if type(limit_expression) in (type(()), type([])):
if isinstance(limit_expression, (list, tuple)):
limit_expression = '%s,%s' % (limit_expression[0], limit_expression[1])
elif limit_expression is not None:
limit_expression = str(limit_expression)
......
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