Skip to content

Commit d8273a7

Browse files
author
Richard Jones
committed
backport from HEAD
1 parent 7200c85 commit d8273a7

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ are given with the most recent entry first.
55
Fixed:
66
- re-acquire the OTK manager when we re-open the database
77
- mailgw handler can close the database on us
8+
- fixed grouping by a NULL Link value
89

910

1011
2004-05-28 0.7.3

roundup/backends/back_mysql.py

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

517517
timezone = self.db.getUserTimezone()
518-
518+
519+
# vars to hold the components of the SQL statement
520+
frum = ['_'+cn] # FROM clauses
521+
loj = [] # LEFT OUTER JOIN clauses
522+
where = [] # WHERE clauses
523+
args = [] # *any* positional arguments
524+
a = self.db.arg
525+
519526
# figure the WHERE clause from the filterspec
520527
props = self.getprops()
521-
frum = ['_'+cn]
522-
where = []
523-
args = []
524-
a = self.db.arg
525-
mlfilt = 0
528+
mlfilt = 0 # are we joining with Multilink tables?
526529
for k, v in filterspec.items():
527530
propclass = props[k]
528531
# now do other where clause stuff
@@ -668,12 +671,15 @@ def filter(self, search_matches, filterspec, sort=(None,None),
668671
# determine whether the linked Class has an order property
669672
lcn = props[prop].classname
670673
link = self.db.classes[lcn]
674+
o = '_%s._%s'%(cn, prop)
671675
if link.getprops().has_key('order'):
672676
tn = '_' + lcn
673-
frum.append(tn)
674-
where.append('_%s._%s = %s.id'%(cn, prop, tn))
677+
loj.append('LEFT OUTER JOIN %s on %s=%s.id'%(tn,
678+
o, tn))
675679
ordercols.append(tn + '._order')
676680
o = tn + '._order'
681+
else:
682+
ordercols.append(o)
677683
elif prop == 'id':
678684
o = '_%s.id'%cn
679685
else:
@@ -701,7 +707,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
701707
else:
702708
order = ''
703709
cols = ','.join(cols)
704-
sql = 'select %s from %s %s%s'%(cols, frum, where, order)
710+
loj = ' '.join(loj)
711+
sql = 'select %s from %s %s %s%s'%(cols, frum, loj, where, order)
705712
args = tuple(args)
706713
if __debug__:
707714
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.98.2.4 2004-05-23 23:26:29 richard Exp $
1+
# $Id: rdbms_common.py,v 1.98.2.5 2004-05-29 02:09:13 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -2007,13 +2007,16 @@ def filter(self, search_matches, filterspec, sort=(None,None),
20072007
cn = self.classname
20082008

20092009
timezone = self.db.getUserTimezone()
2010-
2010+
2011+
# vars to hold the components of the SQL statement
2012+
frum = ['_'+cn] # FROM clauses
2013+
loj = [] # LEFT OUTER JOIN clauses
2014+
where = [] # WHERE clauses
2015+
args = [] # *any* positional arguments
2016+
a = self.db.arg
2017+
20112018
# figure the WHERE clause from the filterspec
20122019
props = self.getprops()
2013-
frum = ['_'+cn]
2014-
where = []
2015-
args = []
2016-
a = self.db.arg
20172020
mlfilt = 0 # are we joining with Multilink tables?
20182021
for k, v in filterspec.items():
20192022
propclass = props[k]
@@ -2154,12 +2157,15 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21542157
# determine whether the linked Class has an order property
21552158
lcn = props[prop].classname
21562159
link = self.db.classes[lcn]
2160+
o = '_%s._%s'%(cn, prop)
21572161
if link.getprops().has_key('order'):
21582162
tn = '_' + lcn
2159-
frum.append(tn)
2160-
where.append('_%s._%s = %s.id'%(cn, prop, tn))
2163+
loj.append('LEFT OUTER JOIN %s on %s=%s.id'%(tn,
2164+
o, tn))
21612165
ordercols.append(tn + '._order')
21622166
o = tn + '._order'
2167+
else:
2168+
ordercols.append(o)
21632169
elif prop == 'id':
21642170
o = '_%s.id'%cn
21652171
else:
@@ -2187,7 +2193,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21872193
else:
21882194
order = ''
21892195
cols = ','.join(cols)
2190-
sql = 'select %s from %s %s%s'%(cols, frum, where, order)
2196+
loj = ' '.join(loj)
2197+
sql = 'select %s from %s %s %s%s'%(cols, frum, loj, where, order)
21912198
args = tuple(args)
21922199
if __debug__:
21932200
print >>hyperdb.DEBUG, 'filter', (self, sql, args)

0 commit comments

Comments
 (0)