issue 1302, support for expressions in CONTAINS, thanks Paolo
This commit is contained in:
@@ -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
|
||||||
|
|||||||
+16
-5
@@ -1234,11 +1234,22 @@ class BaseAdapter(ConnectionPool):
|
|||||||
self.expand('%'+second, 'string'))
|
self.expand('%'+second, 'string'))
|
||||||
|
|
||||||
def CONTAINS(self, first, second):
|
def CONTAINS(self, first, second):
|
||||||
if first.type in ('string', 'text', 'json'):
|
field = self.expand(first)
|
||||||
key = '%'+str(second).replace('%','%%')+'%'
|
if isinstance(second,Expression):
|
||||||
elif first.type.startswith('list:'):
|
expr = self.expand(second,'string')
|
||||||
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
|
if first.type.startswith('list:'):
|
||||||
return '(%s LIKE %s)' % (self.expand(first),self.expand(key,'string'))
|
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):
|
def EQ(self, first, second=None):
|
||||||
if second is None:
|
if second is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user