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): ...@@ -726,4 +726,17 @@ class TestERP5Catalog(ERP5TypeTestCase):
module.searchFolder(group_uid=group_nexedi_category.getUid())] module.searchFolder(group_uid=group_nexedi_category.getUid())]
self.assertEquals(organisation_list, [organisation]) 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): ...@@ -1240,7 +1240,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Get the appropriate SQL Method # Get the appropriate SQL Method
method = getattr(self, self.sql_getitem_by_path) method = getattr(self, self.sql_getitem_by_path)
search_result = method(path = path, uid_only=1) 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: if len(search_result) > 0:
return search_result[0].uid return search_result[0].uid
else: else:
...@@ -1468,22 +1468,21 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1468,22 +1468,21 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# We must now turn sort_index into # We must now turn sort_index into
# a dict with keys as sort keys and values as sort order # 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)] 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 sort_index = None
# If sort_index is a dictionnary # If sort_index is a dictionnary
# then parse it and change it # then parse it and change it
sort_on = None sort_on = None
#LOG('sorting', 0, str(sort_index))
if sort_index is not None: if sort_index is not None:
new_sort_index = [] new_sort_index = []
for sort in sort_index: for sort in sort_index:
if len(sort)==2: if len(sort) == 2:
new_sort_index.append((sort[0],sort[1],None)) new_sort_index.append((sort[0], sort[1], None))
elif len(sort)==3: elif len(sort) == 3:
new_sort_index.append(sort) new_sort_index.append(sort)
sort_index = new_sort_index sort_index = new_sort_index
try: try:
...@@ -1580,7 +1579,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1580,7 +1579,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Add table to table dict # Add table to table dict
from_table_dict[acceptable_key_map[key][0]] = acceptable_key_map[key][0] # We use catalog by default from_table_dict[acceptable_key_map[key][0]] = acceptable_key_map[key][0] # We use catalog by default
# Default case: variable equality # Default case: variable equality
if type(value) is type('') or isinstance(value, DateTime): if isinstance(value, basestring) or isinstance(value, DateTime):
# For security. # For security.
value = self._quoteSQLString(value) value = self._quoteSQLString(value)
if value != '' or not ignore_empty_string: if value != '' or not ignore_empty_string:
...@@ -1611,7 +1610,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1611,7 +1610,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
where_expression += ["MATCH %s AGAINST ('%s' %s)" % (key, value, mode)] where_expression += ["MATCH %s AGAINST ('%s' %s)" % (key, value, mode)]
else: else:
where_expression += ["%s = '%s'" % (key, value)] 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 # We have to create an OR from tuple or list
query_item = [] query_item = []
for value_item in value: for value_item in value:
...@@ -1639,11 +1638,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1639,11 +1638,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
query_item += ["%s = '%s'" % (key, value_item)] query_item += ["%s = '%s'" % (key, value_item)]
if len(query_item) > 0: if len(query_item) > 0:
where_expression += ['(%s)' % join(query_item, ' OR ')] 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 # We are in the case of a complex query
query_item = [] query_item = []
query_value = value['query'] 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] query_value = [query_value]
operator_value = sql_quote(value.get('operator', 'or')) operator_value = sql_quote(value.get('operator', 'or'))
range_value = value.get('range') range_value = value.get('range')
...@@ -1671,10 +1670,10 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1671,10 +1670,10 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
elif key in topic_search_keys: elif key in topic_search_keys:
# ERP5 CPS compatibility # ERP5 CPS compatibility
topic_operator = 'or' topic_operator = 'or'
if type(value) is type({}): if isinstance(value, dict):
topic_operator = sql_quote(value.get('operator', 'or')) topic_operator = sql_quote(value.get('operator', 'or'))
value = value['query'] value = value['query']
if type(value) is type(''): if isinstance(value, basestring):
topic_value = [value] topic_value = [value]
else: else:
topic_value = value # list or tuple topic_value = value # list or tuple
...@@ -1718,7 +1717,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1718,7 +1717,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
where_expression = join(where_expression, ' AND ') where_expression = join(where_expression, ' AND ')
limit_expression = kw.get('limit', None) 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]) limit_expression = '%s,%s' % (limit_expression[0], limit_expression[1])
elif limit_expression is not None: elif limit_expression is not None:
limit_expression = str(limit_expression) 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