Skip to content

Commit 11dac8e

Browse files
author
Richard Jones
committed
fix grouping by NULL linked values
1 parent 69a57fe commit 11dac8e

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

roundup/backends/back_mysql.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,17 @@ def filter(self, search_matches, filterspec, sort=(None,None),
511511
cn = self.classname
512512

513513
timezone = self.db.getUserTimezone()
514-
514+
515+
# vars to hold the components of the SQL statement
516+
frum = ['_'+cn] # FROM clauses
517+
loj = [] # LEFT OUTER JOIN clauses
518+
where = [] # WHERE clauses
519+
args = [] # *any* positional arguments
520+
a = self.db.arg
521+
515522
# figure the WHERE clause from the filterspec
516523
props = self.getprops()
517-
frum = ['_'+cn]
518-
where = []
519-
args = []
520-
a = self.db.arg
521-
mlfilt = 0
524+
mlfilt = 0 # are we joining with Multilink tables?
522525
for k, v in filterspec.items():
523526
propclass = props[k]
524527
# now do other where clause stuff
@@ -664,12 +667,15 @@ def filter(self, search_matches, filterspec, sort=(None,None),
664667
# determine whether the linked Class has an order property
665668
lcn = props[prop].classname
666669
link = self.db.classes[lcn]
670+
o = '_%s._%s'%(cn, prop)
667671
if link.getprops().has_key('order'):
668672
tn = '_' + lcn
669-
frum.append(tn)
670-
where.append('_%s._%s = %s.id'%(cn, prop, tn))
673+
loj.append('LEFT OUTER JOIN %s on %s=%s.id'%(tn,
674+
o, tn))
671675
ordercols.append(tn + '._order')
672676
o = tn + '._order'
677+
else:
678+
ordercols.append(o)
673679
elif prop == 'id':
674680
o = '_%s.id'%cn
675681
else:
@@ -697,7 +703,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
697703
else:
698704
order = ''
699705
cols = ','.join(cols)
700-
sql = 'select %s from %s %s%s'%(cols, frum, where, order)
706+
loj = ' '.join(loj)
707+
sql = 'select %s from %s %s %s%s'%(cols, frum, loj, where, order)
701708
args = tuple(args)
702709
if __debug__:
703710
print >>hyperdb.DEBUG, 'filter', (self, sql, args)

roundup/backends/rdbms_common.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.103 2004-05-28 01:09:11 richard Exp $
1+
# $Id: rdbms_common.py,v 1.104 2004-05-29 01:35:27 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -2006,13 +2006,16 @@ def filter(self, search_matches, filterspec, sort=(None,None),
20062006
cn = self.classname
20072007

20082008
timezone = self.db.getUserTimezone()
2009-
2009+
2010+
# vars to hold the components of the SQL statement
2011+
frum = ['_'+cn] # FROM clauses
2012+
loj = [] # LEFT OUTER JOIN clauses
2013+
where = [] # WHERE clauses
2014+
args = [] # *any* positional arguments
2015+
a = self.db.arg
2016+
20102017
# figure the WHERE clause from the filterspec
20112018
props = self.getprops()
2012-
frum = ['_'+cn]
2013-
where = []
2014-
args = []
2015-
a = self.db.arg
20162019
mlfilt = 0 # are we joining with Multilink tables?
20172020
for k, v in filterspec.items():
20182021
propclass = props[k]
@@ -2153,12 +2156,15 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21532156
# determine whether the linked Class has an order property
21542157
lcn = props[prop].classname
21552158
link = self.db.classes[lcn]
2159+
o = '_%s._%s'%(cn, prop)
21562160
if link.getprops().has_key('order'):
21572161
tn = '_' + lcn
2158-
frum.append(tn)
2159-
where.append('_%s._%s = %s.id'%(cn, prop, tn))
2162+
loj.append('LEFT OUTER JOIN %s on %s=%s.id'%(tn,
2163+
o, tn))
21602164
ordercols.append(tn + '._order')
21612165
o = tn + '._order'
2166+
else:
2167+
ordercols.append(o)
21622168
elif prop == 'id':
21632169
o = '_%s.id'%cn
21642170
else:
@@ -2186,7 +2192,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21862192
else:
21872193
order = ''
21882194
cols = ','.join(cols)
2189-
sql = 'select %s from %s %s%s'%(cols, frum, where, order)
2195+
loj = ' '.join(loj)
2196+
sql = 'select %s from %s %s %s%s'%(cols, frum, loj, where, order)
21902197
args = tuple(args)
21912198
if __debug__:
21922199
print >>hyperdb.DEBUG, 'filter', (self, sql, args)

0 commit comments

Comments
 (0)