|
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 $ |
2 | 2 | ''' Relational database (SQL) backend common code. |
3 | 3 |
|
4 | 4 | Basics: |
@@ -2007,13 +2007,16 @@ def filter(self, search_matches, filterspec, sort=(None,None), |
2007 | 2007 | cn = self.classname |
2008 | 2008 |
|
2009 | 2009 | 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 | + |
2011 | 2018 | # figure the WHERE clause from the filterspec |
2012 | 2019 | props = self.getprops() |
2013 | | - frum = ['_'+cn] |
2014 | | - where = [] |
2015 | | - args = [] |
2016 | | - a = self.db.arg |
2017 | 2020 | mlfilt = 0 # are we joining with Multilink tables? |
2018 | 2021 | for k, v in filterspec.items(): |
2019 | 2022 | propclass = props[k] |
@@ -2154,12 +2157,15 @@ def filter(self, search_matches, filterspec, sort=(None,None), |
2154 | 2157 | # determine whether the linked Class has an order property |
2155 | 2158 | lcn = props[prop].classname |
2156 | 2159 | link = self.db.classes[lcn] |
| 2160 | + o = '_%s._%s'%(cn, prop) |
2157 | 2161 | if link.getprops().has_key('order'): |
2158 | 2162 | 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)) |
2161 | 2165 | ordercols.append(tn + '._order') |
2162 | 2166 | o = tn + '._order' |
| 2167 | + else: |
| 2168 | + ordercols.append(o) |
2163 | 2169 | elif prop == 'id': |
2164 | 2170 | o = '_%s.id'%cn |
2165 | 2171 | else: |
@@ -2187,7 +2193,8 @@ def filter(self, search_matches, filterspec, sort=(None,None), |
2187 | 2193 | else: |
2188 | 2194 | order = '' |
2189 | 2195 | 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) |
2191 | 2198 | args = tuple(args) |
2192 | 2199 | if __debug__: |
2193 | 2200 | print >>hyperdb.DEBUG, 'filter', (self, sql, args) |
|
0 commit comments