Skip to content

Commit 8abcf2f

Browse files
author
Alexander Smishlajev
committed
fix filtering by Link property:
if value list contained both NULL (-1) and non-NULL items, 'is NULL' and 'in (list)' clauses were joined by 'and' instead of 'or'. in .find() and .filter(), put brackets around all 'where' segments that may contain ORed parts: 'or' has lower precedence than 'and'
1 parent 7c48502 commit 8abcf2f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

roundup/backends/rdbms_common.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.117 2004-07-02 08:15:01 a1s Exp $
1+
# $Id: rdbms_common.py,v 1.118 2004-07-03 16:51:52 a1s Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -1878,7 +1878,7 @@ def find(self, **propspec):
18781878
s = '_%s is NULL or '%prop
18791879
allvalues += tuple(values)
18801880
s += '_%s in (%s)'%(prop, ','.join([a]*len(values)))
1881-
where.append(s)
1881+
where.append('(' + s +')')
18821882
tables = ['_%s'%self.classname]
18831883
if where:
18841884
o.append('(' + ' and '.join(where) + ')')
@@ -2041,8 +2041,9 @@ def filter(self, search_matches, filterspec, sort=(None,None),
20412041
v = ['%%'+self.db.sql_stringquote(s)+'%%' for s in v]
20422042

20432043
# now add to the where clause
2044-
where.append(' or '.join(["_%s._%s LIKE '%s'"%(cn, k, s)
2045-
for s in v]))
2044+
where.append('('
2045+
+' or '.join(["_%s._%s LIKE '%s'"%(cn, k, s) for s in v])
2046+
+')')
20462047
# note: args are embedded in the query string now
20472048
elif isinstance(propclass, Link):
20482049
if isinstance(v, type([])):
@@ -2058,10 +2059,10 @@ def filter(self, search_matches, filterspec, sort=(None,None),
20582059
if d:
20592060
v = d.keys()
20602061
s = ','.join([a for x in v])
2061-
where.append('(_%s._%s in (%s))'%(cn, k, s))
2062+
l.append('(_%s._%s in (%s))'%(cn, k, s))
20622063
args = args + v
20632064
if l:
2064-
where.append(' or '.join(l))
2065+
where.append('(' + ' or '.join(l) +')')
20652066
else:
20662067
if v in ('-1', None):
20672068
v = None

0 commit comments

Comments
 (0)