[FIX] osv.expression: fix =like/=ilike operators, broken by r.3631
Revision 3631 = vmt@openerp.com-20110920124252-l5snbvb7ywfogw1o bzr revid: odo@openerp.com-20110921224208-mji81to3g4kpmkuq
This commit is contained in:
parent
7080c6cde5
commit
886b7407de
|
@ -188,18 +188,18 @@
|
||||||
norm_domain = ['&','&','&'] + domain
|
norm_domain = ['&','&','&'] + domain
|
||||||
assert norm_domain == expression.normalize(domain), "Non-normalized domains should be properly normalized"
|
assert norm_domain == expression.normalize(domain), "Non-normalized domains should be properly normalized"
|
||||||
-
|
-
|
||||||
Check that =like/=ilike expressions are working with an untranslated field.
|
Check that =like/=ilike expressions (no wildcard variants of like/ilike) are working on an untranslated field.
|
||||||
-
|
-
|
||||||
!python {model: res.partner }: |
|
!python {model: res.partner }: |
|
||||||
all_ids = self.search(cr, uid, [('name', '=like', 'Ax')])
|
all_ids = self.search(cr, uid, [('name', '=like', 'A_e_or')])
|
||||||
assert len(all_ids) == 1, "It should have 1 record !"
|
assert len(all_ids) == 1, "Must match one partner (Axelor), got %r"%all_ids
|
||||||
all_ids = self.search(cr, uid, [('name', '=ilike', 'Ax')])
|
all_ids = self.search(cr, uid, [('name', '=ilike', 'm_____')])
|
||||||
assert len(all_ids) == 2, "It should have 2 records !"
|
assert len(all_ids) == 1, "Must match *only* one partner (Maxtor), got %r"%all_ids
|
||||||
-
|
-
|
||||||
Check that =like/=ilike expressions are working with a translated field.
|
Check that =like/=ilike expressions (no wildcard variants of like/ilike) are working on translated field.
|
||||||
-
|
-
|
||||||
!python {model: res.country }: |
|
!python {model: res.country }: |
|
||||||
all_ids = self.search(cr, uid, [('name', '=like', 'Ind')])
|
all_ids = self.search(cr, uid, [('name', '=like', 'Ind__')])
|
||||||
assert len(all_ids) == 3, "It should have 3 records !"
|
assert len(all_ids) == 1, "Must match India only, got %r"%all_ids
|
||||||
all_ids = self.search(cr, uid, [('name', '=ilike', 'Ind')])
|
all_ids = self.search(cr, uid, [('name', '=ilike', 'z%')])
|
||||||
assert len(all_ids) == 3, "It should have 3 records !"
|
assert len(all_ids) == 3, "Must match only countries with names starting with Z (currently 3), got %r"%all_ids
|
||||||
|
|
|
@ -425,10 +425,11 @@ class expression(object):
|
||||||
self.__exp[i] = tuple(self.__exp[i])
|
self.__exp[i] = tuple(self.__exp[i])
|
||||||
|
|
||||||
if field.translate:
|
if field.translate:
|
||||||
operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator)
|
need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike')
|
||||||
if operator in ('like', 'ilike', 'not like', 'not ilike'):
|
sql_operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator)
|
||||||
|
if need_wildcard:
|
||||||
right = '%%%s%%' % right
|
right = '%%%s%%' % right
|
||||||
|
|
||||||
query1 = '( SELECT res_id' \
|
query1 = '( SELECT res_id' \
|
||||||
' FROM ir_translation' \
|
' FROM ir_translation' \
|
||||||
' WHERE name = %s' \
|
' WHERE name = %s' \
|
||||||
|
@ -436,19 +437,19 @@ class expression(object):
|
||||||
' AND type = %s'
|
' AND type = %s'
|
||||||
instr = ' %s'
|
instr = ' %s'
|
||||||
#Covering in,not in operators with operands (%s,%s) ,etc.
|
#Covering in,not in operators with operands (%s,%s) ,etc.
|
||||||
if operator in ['in','not in']:
|
if sql_operator in ['in','not in']:
|
||||||
instr = ','.join(['%s'] * len(right))
|
instr = ','.join(['%s'] * len(right))
|
||||||
query1 += ' AND value ' + operator + ' ' +" (" + instr + ")" \
|
query1 += ' AND value ' + sql_operator + ' ' +" (" + instr + ")" \
|
||||||
') UNION (' \
|
') UNION (' \
|
||||||
' SELECT id' \
|
' SELECT id' \
|
||||||
' FROM "' + working_table._table + '"' \
|
' FROM "' + working_table._table + '"' \
|
||||||
' WHERE "' + left + '" ' + operator + ' ' +" (" + instr + "))"
|
' WHERE "' + left + '" ' + sql_operator + ' ' +" (" + instr + "))"
|
||||||
else:
|
else:
|
||||||
query1 += ' AND value ' + operator + instr + \
|
query1 += ' AND value ' + sql_operator + instr + \
|
||||||
') UNION (' \
|
') UNION (' \
|
||||||
' SELECT id' \
|
' SELECT id' \
|
||||||
' FROM "' + working_table._table + '"' \
|
' FROM "' + working_table._table + '"' \
|
||||||
' WHERE "' + left + '" ' + operator + instr + ")"
|
' WHERE "' + left + '" ' + sql_operator + instr + ")"
|
||||||
|
|
||||||
query2 = [working_table._name + ',' + left,
|
query2 = [working_table._name + ',' + left,
|
||||||
context.get('lang', False) or 'en_US',
|
context.get('lang', False) or 'en_US',
|
||||||
|
@ -521,18 +522,16 @@ class expression(object):
|
||||||
query = '%s.id %s %%s' % (table._table, operator)
|
query = '%s.id %s %%s' % (table._table, operator)
|
||||||
params = right
|
params = right
|
||||||
else:
|
else:
|
||||||
operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator)
|
need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike')
|
||||||
like = operator in ('like', 'ilike', 'not like', 'not ilike')
|
sql_operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator)
|
||||||
|
|
||||||
op = {'=like':'like','=ilike':'ilike'}.get(operator,operator)
|
|
||||||
if left in table._columns:
|
if left in table._columns:
|
||||||
format = like and '%s' or table._columns[left]._symbol_set[0]
|
format = need_wildcard and '%s' or table._columns[left]._symbol_set[0]
|
||||||
query = '(%s."%s" %s %s)' % (table._table, left, op, format)
|
query = '(%s."%s" %s %s)' % (table._table, left, sql_operator, format)
|
||||||
else:
|
else:
|
||||||
query = "(%s.\"%s\" %s '%s')" % (table._table, left, op, right)
|
query = "(%s.\"%s\" %s '%s')" % (table._table, left, sql_operator, right)
|
||||||
|
|
||||||
add_null = False
|
add_null = False
|
||||||
if like:
|
if need_wildcard:
|
||||||
if isinstance(right, str):
|
if isinstance(right, str):
|
||||||
str_utf8 = right
|
str_utf8 = right
|
||||||
elif isinstance(right, unicode):
|
elif isinstance(right, unicode):
|
||||||
|
|
Loading…
Reference in New Issue