1- # $Id: rdbms_common.py,v 1.98.2.22 2004-10-08 00:57:22 richard Exp $
1+ # $Id: rdbms_common.py,v 1.98.2.23 2004-10-08 01:29:30 richard Exp $
22''' Relational database (SQL) backend common code.
33
44Basics:
@@ -1953,8 +1953,8 @@ def find(self, **propspec):
19531953
19541954 # first, links
19551955 a = self .db .arg
1956- allvalues = (1 , )
1957- o = []
1956+ allvalues = ()
1957+ sql = []
19581958 where = []
19591959 for prop , values in propspec :
19601960 if not isinstance (props [prop ], hyperdb .Link ):
@@ -1975,35 +1975,32 @@ def find(self, **propspec):
19751975 allvalues += tuple (values )
19761976 s += '_%s in (%s)' % (prop , ',' .join ([a ]* len (values )))
19771977 where .append ('(' + s + ')' )
1978- tables = ['_%s' % self .classname ]
19791978 if where :
1980- o .append ('(' + ' and ' .join (where ) + ')' )
1979+ allvalues = (1 , ) + allvalues
1980+ sql .append ('''select id from _%s where __retired__ <> %s
1981+ and %s''' % (self .classname , a , ' and ' .join (where )))
19811982
19821983 # now multilinks
19831984 for prop , values in propspec :
19841985 if not isinstance (props [prop ], hyperdb .Multilink ):
19851986 continue
19861987 if not values :
19871988 continue
1989+ allvalues += (1 , )
19881990 if type (values ) is type ('' ):
19891991 allvalues += (values ,)
19901992 s = a
19911993 else :
19921994 allvalues += tuple (values .keys ())
19931995 s = ',' .join ([a ]* len (values ))
19941996 tn = '%s_%s' % (self .classname , prop )
1995- tables .append (tn )
1996- o .append ('(id=%s.nodeid and %s.linkid in (%s))' % (tn , tn , s ))
1997+ sql .append ('''select id from _%s, %s where __retired__ <> %s
1998+ and id = %s.nodeid and %s.linkid in (%s)''' % (self .classname ,
1999+ tn , a , tn , tn , s ))
19972000
1998- if not o :
2001+ if not sql :
19992002 return []
2000- elif len (o ) > 1 :
2001- o = '(' + ' or ' .join (['(%s)' % i for i in o ]) + ')'
2002- else :
2003- o = o [0 ]
2004- t = ', ' .join (tables )
2005- sql = 'select distinct(id) from %s where __retired__ <> %s and %s' % (
2006- t , a , o )
2003+ sql = ' union ' .join (sql )
20072004 self .db .sql (sql , allvalues )
20082005 # XXX numeric ids
20092006 l = [str (x [0 ]) for x in self .db .sql_fetchall ()]
0 commit comments