issue 1302, support for expressions in CONTAINS, thanks Paolo
This commit is contained in:
2
VERSION
2
VERSION
@@ -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
|
||||
|
||||
21
gluon/dal.py
21
gluon/dal.py
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user