diff roundup/backends/back_mysql.py @ 2379:a2025bdd1491

fix grouping by NULL linked values
author Richard Jones <richard@users.sourceforge.net>
date Sat, 29 May 2004 01:35:27 +0000
parents 10fc45eea226
children 7d0bb6601809
line wrap: on
line diff
--- a/roundup/backends/back_mysql.py	Sat May 29 00:08:07 2004 +0000
+++ b/roundup/backends/back_mysql.py	Sat May 29 01:35:27 2004 +0000
@@ -511,14 +511,17 @@
         cn = self.classname
 
         timezone = self.db.getUserTimezone()
-        
+
+        # vars to hold the components of the SQL statement
+        frum = ['_'+cn] # FROM clauses
+        loj = []        # LEFT OUTER JOIN clauses
+        where = []      # WHERE clauses
+        args = []       # *any* positional arguments
+        a = self.db.arg
+
         # figure the WHERE clause from the filterspec
         props = self.getprops()
-        frum = ['_'+cn]
-        where = []
-        args = []
-        a = self.db.arg
-        mlfilt = 0
+        mlfilt = 0      # are we joining with Multilink tables?
         for k, v in filterspec.items():
             propclass = props[k]
             # now do other where clause stuff
@@ -664,12 +667,15 @@
                     # determine whether the linked Class has an order property
                     lcn = props[prop].classname
                     link = self.db.classes[lcn]
+                    o = '_%s._%s'%(cn, prop)
                     if link.getprops().has_key('order'):
                         tn = '_' + lcn
-                        frum.append(tn)
-                        where.append('_%s._%s = %s.id'%(cn, prop, tn))
+                        loj.append('LEFT OUTER JOIN %s on %s=%s.id'%(tn,
+                            o, tn))
                         ordercols.append(tn + '._order')
                         o = tn + '._order'
+                    else:
+                        ordercols.append(o)
                 elif prop == 'id':
                     o = '_%s.id'%cn
                 else:
@@ -697,7 +703,8 @@
         else:
             order = ''
         cols = ','.join(cols)
-        sql = 'select %s from %s %s%s'%(cols, frum, where, order)
+        loj = ' '.join(loj)
+        sql = 'select %s from %s %s %s%s'%(cols, frum, loj, where, order)
         args = tuple(args)
         if __debug__:
             print >>hyperdb.DEBUG, 'filter', (self, sql, args)

Roundup Issue Tracker: http://roundup-tracker.org/