passing parameters for contains case_sensitive but often ignored. :-(
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.1-alpha.2+timestamp.2013.02.04.09.37.03
|
Version 2.4.1-alpha.2+timestamp.2013.02.04.09.54.44
|
||||||
|
|||||||
+27
-16
@@ -1233,9 +1233,9 @@ class BaseAdapter(ConnectionPool):
|
|||||||
return '(%s LIKE %s)' % (self.expand(first),
|
return '(%s LIKE %s)' % (self.expand(first),
|
||||||
self.expand('%'+second, 'string'))
|
self.expand('%'+second, 'string'))
|
||||||
|
|
||||||
def CONTAINS(self, first, second):
|
def CONTAINS(self, first, second, case_sensitive=False):
|
||||||
field = self.expand(first)
|
|
||||||
if isinstance(second,Expression):
|
if isinstance(second,Expression):
|
||||||
|
field = self.expand(first)
|
||||||
expr = self.expand(second,'string')
|
expr = self.expand(second,'string')
|
||||||
if first.type.startswith('list:'):
|
if first.type.startswith('list:'):
|
||||||
expr = 'CONCAT("|", %s, "|")' % expr
|
expr = 'CONCAT("|", %s, "|")' % expr
|
||||||
@@ -1249,7 +1249,8 @@ class BaseAdapter(ConnectionPool):
|
|||||||
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
|
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Expression Not Supported")
|
raise RuntimeError("Expression Not Supported")
|
||||||
return '(%s LIKE %s)' % (field,self.expand(key,'string'))
|
op = case_sensitive and self.LIKE or self.ILIKE
|
||||||
|
return op(first,key)
|
||||||
|
|
||||||
def EQ(self, first, second=None):
|
def EQ(self, first, second=None):
|
||||||
if second is None:
|
if second is None:
|
||||||
@@ -2627,12 +2628,13 @@ class PostgreSQLAdapter(BaseAdapter):
|
|||||||
return '(%s ILIKE %s)' % (self.expand(first),
|
return '(%s ILIKE %s)' % (self.expand(first),
|
||||||
self.expand('%'+second,'string'))
|
self.expand('%'+second,'string'))
|
||||||
|
|
||||||
def CONTAINS(self,first,second):
|
def CONTAINS(self,first,second,case_sensitive=False):
|
||||||
if first.type in ('string','text', 'json'):
|
if first.type in ('string','text', 'json'):
|
||||||
key = '%'+str(second).replace('%','%%')+'%'
|
key = '%'+str(second).replace('%','%%')+'%'
|
||||||
elif first.type.startswith('list:'):
|
elif first.type.startswith('list:'):
|
||||||
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
|
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
|
||||||
return '(%s ILIKE %s)' % (self.expand(first),self.expand(key,'string'))
|
op = case_sensitive and self.LIKE or self.ILIKE
|
||||||
|
return op(first,key)
|
||||||
|
|
||||||
# GIS functions
|
# GIS functions
|
||||||
|
|
||||||
@@ -3406,13 +3408,17 @@ class FireBirdAdapter(BaseAdapter):
|
|||||||
def SUBSTRING(self,field,parameters):
|
def SUBSTRING(self,field,parameters):
|
||||||
return 'SUBSTRING(%s from %s for %s)' % (self.expand(field), parameters[0], parameters[1])
|
return 'SUBSTRING(%s from %s for %s)' % (self.expand(field), parameters[0], parameters[1])
|
||||||
|
|
||||||
def CONTAINS(self, first, second):
|
def CONTAINING(self,first,second):
|
||||||
|
"case in-sensitive like operator"
|
||||||
|
return '(%s CONTAINING %s)' % (self.expand(first),
|
||||||
|
self.expand(second, 'string'))
|
||||||
|
|
||||||
|
def CONTAINS(self, first, second, case_sensitive=False):
|
||||||
if first.type in ('string','text'):
|
if first.type in ('string','text'):
|
||||||
key = str(second).replace('%','%%')
|
key = str(second).replace('%','%%')
|
||||||
elif first.type.startswith('list:'):
|
elif first.type.startswith('list:'):
|
||||||
key = '|'+str(second).replace('|','||').replace('%','%%')+'|'
|
key = '|'+str(second).replace('|','||').replace('%','%%')+'|'
|
||||||
return '(%s CONTAINING %s)' % (self.expand(first),
|
return self.CONTAINING(first,second)
|
||||||
self.expand(key,'string'))
|
|
||||||
|
|
||||||
def _drop(self,table,mode):
|
def _drop(self,table,mode):
|
||||||
sequence_name = table._sequence_name
|
sequence_name = table._sequence_name
|
||||||
@@ -4572,7 +4578,8 @@ class GoogleDatastoreAdapter(NoSQLAdapter):
|
|||||||
second = [Key.from_path(first._tablename, int(i)) for i in second]
|
second = [Key.from_path(first._tablename, int(i)) for i in second]
|
||||||
return [GAEF(first.name,'in',second,lambda a,b:a in b)]
|
return [GAEF(first.name,'in',second,lambda a,b:a in b)]
|
||||||
|
|
||||||
def CONTAINS(self,first,second):
|
def CONTAINS(self,first,second,case_sensitive=False):
|
||||||
|
# silently ignoring: GAE can only do case sensitive matches!
|
||||||
if not first.type.startswith('list:'):
|
if not first.type.startswith('list:'):
|
||||||
raise SyntaxError("Not supported")
|
raise SyntaxError("Not supported")
|
||||||
return [GAEF(first.name,'=',self.expand(second,first.type[5:]),lambda a,b:b in a)]
|
return [GAEF(first.name,'=',self.expand(second,first.type[5:]),lambda a,b:b in a)]
|
||||||
@@ -5525,8 +5532,9 @@ class MongoDBAdapter(NoSQLAdapter):
|
|||||||
return {self.expand(first): ('/%s^/' % \
|
return {self.expand(first): ('/%s^/' % \
|
||||||
self.expand(second, 'string'))}
|
self.expand(second, 'string'))}
|
||||||
|
|
||||||
def CONTAINS(self, first, second):
|
def CONTAINS(self, first, second, case_sensitive=False):
|
||||||
#There is a technical difference, but mongodb doesn't support
|
# silently ignore, only case sensitive
|
||||||
|
# There is a technical difference, but mongodb doesn't support
|
||||||
# that, but the result will be the same
|
# that, but the result will be the same
|
||||||
return {self.expand(first) : ('/%s/' % \
|
return {self.expand(first) : ('/%s/' % \
|
||||||
self.expand(second, 'string'))}
|
self.expand(second, 'string'))}
|
||||||
@@ -5556,7 +5564,8 @@ class MongoDBAdapter(NoSQLAdapter):
|
|||||||
re.escape(self.expand(second, 'string')) + '$'}}
|
re.escape(self.expand(second, 'string')) + '$'}}
|
||||||
|
|
||||||
#TODO verify full compatibilty with official oracle contains operator
|
#TODO verify full compatibilty with official oracle contains operator
|
||||||
def CONTAINS(self, first, second):
|
def CONTAINS(self, first, second, case_sensitive=False):
|
||||||
|
# silently ignore, only case sensitive
|
||||||
#There is a technical difference, but mongodb doesn't support
|
#There is a technical difference, but mongodb doesn't support
|
||||||
# that, but the result will be the same
|
# that, but the result will be the same
|
||||||
#TODO contains operators need to be transformed to Regex
|
#TODO contains operators need to be transformed to Regex
|
||||||
@@ -6346,7 +6355,8 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
# result = "(%s %s)" % (self.expand(first), self.expand(second))
|
# result = "(%s %s)" % (self.expand(first), self.expand(second))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def CONTAINS(self, first, second):
|
def CONTAINS(self, first, second, case_sensitive=False):
|
||||||
|
# silently ignore, only case sensitive
|
||||||
result = None
|
result = None
|
||||||
name = self.search_fields[first.name]
|
name = self.search_fields[first.name]
|
||||||
|
|
||||||
@@ -8764,17 +8774,18 @@ class Expression(object):
|
|||||||
raise SyntaxError("endswith used with incompatible field type")
|
raise SyntaxError("endswith used with incompatible field type")
|
||||||
return Query(db, db._adapter.ENDSWITH, self, value)
|
return Query(db, db._adapter.ENDSWITH, self, value)
|
||||||
|
|
||||||
def contains(self, value, all=False):
|
def contains(self, value, all=False, case_sensitive=False):
|
||||||
db = self.db
|
db = self.db
|
||||||
if isinstance(value,(list, tuple)):
|
if isinstance(value,(list, tuple)):
|
||||||
subqueries = [self.contains(str(v).strip()) for v in value if str(v).strip()]
|
subqueries = [self.contains(str(v).strip(),case_sensitive=case_sensitive)
|
||||||
|
for v in value if str(v).strip()]
|
||||||
if not subqueries:
|
if not subqueries:
|
||||||
return self.contains('')
|
return self.contains('')
|
||||||
else:
|
else:
|
||||||
return reduce(all and AND or OR,subqueries)
|
return reduce(all and AND or OR,subqueries)
|
||||||
if not self.type in ('string', 'text', 'json') and not self.type.startswith('list:'):
|
if not self.type in ('string', 'text', 'json') and not self.type.startswith('list:'):
|
||||||
raise SyntaxError("contains used with incompatible field type")
|
raise SyntaxError("contains used with incompatible field type")
|
||||||
return Query(db, db._adapter.CONTAINS, self, value)
|
return Query(db, db._adapter.CONTAINS, self, value, case_sensitive=case_sensitive)
|
||||||
|
|
||||||
def with_alias(self, alias):
|
def with_alias(self, alias):
|
||||||
db = self.db
|
db = self.db
|
||||||
|
|||||||
Reference in New Issue
Block a user