issue 1302, support for expressions in CONTAINS, thanks Paolo

This commit is contained in:
Massimo
2013-01-25 15:29:04 -06:00
parent d4e68e6c18
commit ca330a99e2
2 changed files with 17 additions and 6 deletions

View File

@@ -1 +1 @@
Version 2.4.1-alpha.2+timestamp.2013.01.24.15.51.43
Version 2.4.1-alpha.2+timestamp.2013.01.25.15.28.24

View File

@@ -1234,11 +1234,22 @@ class BaseAdapter(ConnectionPool):
self.expand('%'+second, 'string'))
def CONTAINS(self, first, second):
if first.type in ('string', 'text', 'json'):
key = '%'+str(second).replace('%','%%')+'%'
elif first.type.startswith('list:'):
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
return '(%s LIKE %s)' % (self.expand(first),self.expand(key,'string'))
field = self.expand(first)
if isinstance(second,Expression):
expr = self.expand(second,'string')
if first.type.startswith('list:'):
expr = 'CONCAT("|", %s, "|")' % expr
elif not first.type in ('string', 'text', 'json'):
raise RuntimeError("Expression Not Supported")
return 'INSTR(%s,%s)' % (field, expr)
else:
if first.type in ('string', 'text', 'json'):
key = '%'+str(second).replace('%','%%')+'%'
elif first.type.startswith('list:'):
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
else:
raise RuntimeError("Expression Not Supported")
return '(%s LIKE %s)' % (field,self.expand(key,'string'))
def EQ(self, first, second=None):
if second is None: