1- # $Id: rdbms_common.py,v 1.98.2.2 2004-05-16 09:33:13 richard Exp $
1+ # $Id: rdbms_common.py,v 1.98.2.3 2004-05-16 22:00:08 richard Exp $
22''' Relational database (SQL) backend common code.
33
44Basics:
@@ -2024,23 +2024,26 @@ def filter(self, search_matches, filterspec, sort=(None,None),
20242024 if v in ('-1' , ['-1' ]):
20252025 # only match rows that have count(linkid)=0 in the
20262026 # corresponding multilink table)
2027- where .append ('id not in (select nodeid from %s)' % tn )
2027+ where .append ('_%s.id not in (select nodeid from %s)' % (cn ,
2028+ tn ))
20282029 elif isinstance (v , type ([])):
20292030 frum .append (tn )
20302031 s = ',' .join ([a for x in v ])
2031- where .append ('id=%s.nodeid and %s.linkid in (%s)' % (tn ,tn ,s ))
2032+ where .append ('_%s.id=%s.nodeid and %s.linkid in (%s)' % (cn ,
2033+ tn , tn , s ))
20322034 args = args + v
20332035 else :
20342036 frum .append (tn )
2035- where .append ('id=%s.nodeid and %s.linkid=%s' % (tn , tn , a ))
2037+ where .append ('_%s.id=%s.nodeid and %s.linkid=%s' % (cn , tn ,
2038+ tn , a ))
20362039 args .append (v )
20372040 elif k == 'id' :
20382041 if isinstance (v , type ([])):
20392042 s = ',' .join ([a for x in v ])
2040- where .append ('%s in (%s)' % (k , s ))
2043+ where .append ('_%s.%s in (%s)' % (cn , k , s ))
20412044 args = args + v
20422045 else :
2043- where .append ('%s =%s' % (k , a ))
2046+ where .append ('_%s.%s =%s' % (cn , k , a ))
20442047 args .append (v )
20452048 elif isinstance (propclass , String ):
20462049 if not isinstance (v , type ([])):
@@ -2052,44 +2055,45 @@ def filter(self, search_matches, filterspec, sort=(None,None),
20522055 v = ['%%' + self .db .sql_stringquote (s )+ '%%' for s in v ]
20532056
20542057 # now add to the where clause
2055- where .append (' or ' .join (["_%s LIKE '%s'" % (k , s ) for s in v ]))
2058+ where .append (' or ' .join (["_%s._%s LIKE '%s'" % (cn , k , s )
2059+ for s in v ]))
20562060 # note: args are embedded in the query string now
20572061 elif isinstance (propclass , Link ):
20582062 if isinstance (v , type ([])):
20592063 if '-1' in v :
20602064 v = v [:]
20612065 v .remove ('-1' )
2062- xtra = ' or _%s is NULL' % k
2066+ xtra = ' or _%s._%s is NULL' % ( cn , k )
20632067 else :
20642068 xtra = ''
20652069 if v :
20662070 s = ',' .join ([a for x in v ])
2067- where .append ('(_%s in (%s)%s)' % (k , s , xtra ))
2071+ where .append ('(_%s._%s in (%s)%s)' % (cn , k , s , xtra ))
20682072 args = args + v
20692073 else :
2070- where .append ('_%s is NULL' % k )
2074+ where .append ('_%s._%s is NULL' % ( cn , k ) )
20712075 else :
20722076 if v == '-1' :
20732077 v = None
2074- where .append ('_%s is NULL' % k )
2078+ where .append ('_%s._%s is NULL' % ( cn , k ) )
20752079 else :
2076- where .append ('_%s=%s' % (k , a ))
2080+ where .append ('_%s._%s =%s' % (cn , k , a ))
20772081 args .append (v )
20782082 elif isinstance (propclass , Date ):
20792083 dc = self .db .hyperdb_to_sql_value [hyperdb .Date ]
20802084 if isinstance (v , type ([])):
20812085 s = ',' .join ([a for x in v ])
2082- where .append ('_%s in (%s)' % (k , s ))
2086+ where .append ('_%s._%s in (%s)' % (cn , k , s ))
20832087 args = args + [dc (date .Date (v )) for x in v ]
20842088 else :
20852089 try :
20862090 # Try to filter on range of dates
20872091 date_rng = Range (v , date .Date , offset = timezone )
20882092 if date_rng .from_value :
2089- where .append ('_%s >= %s' % (k , a ))
2093+ where .append ('_%s._%s >= %s' % (cn , k , a ))
20902094 args .append (dc (date_rng .from_value ))
20912095 if date_rng .to_value :
2092- where .append ('_%s <= %s' % (k , a ))
2096+ where .append ('_%s._%s <= %s' % (cn , k , a ))
20932097 args .append (dc (date_rng .to_value ))
20942098 except ValueError :
20952099 # If range creation fails - ignore that search parameter
@@ -2098,28 +2102,28 @@ def filter(self, search_matches, filterspec, sort=(None,None),
20982102 # filter using the __<prop>_int__ column
20992103 if isinstance (v , type ([])):
21002104 s = ',' .join ([a for x in v ])
2101- where .append ('__%s_int__ in (%s)' % (k , s ))
2105+ where .append ('_%s. __%s_int__ in (%s)' % (cn , k , s ))
21022106 args = args + [date .Interval (x ).as_seconds () for x in v ]
21032107 else :
21042108 try :
21052109 # Try to filter on range of intervals
21062110 date_rng = Range (v , date .Interval )
21072111 if date_rng .from_value :
2108- where .append ('__%s_int__ >= %s' % (k , a ))
2112+ where .append ('_%s. __%s_int__ >= %s' % (cn , k , a ))
21092113 args .append (date_rng .from_value .as_seconds ())
21102114 if date_rng .to_value :
2111- where .append ('__%s_int__ <= %s' % (k , a ))
2115+ where .append ('_%s. __%s_int__ <= %s' % (cn , k , a ))
21122116 args .append (date_rng .to_value .as_seconds ())
21132117 except ValueError :
21142118 # If range creation fails - ignore that search parameter
21152119 pass
21162120 else :
21172121 if isinstance (v , type ([])):
21182122 s = ',' .join ([a for x in v ])
2119- where .append ('_%s in (%s)' % (k , s ))
2123+ where .append ('_%s._%s in (%s)' % (cn , k , s ))
21202124 args = args + v
21212125 else :
2122- where .append ('_%s=%s' % (k , a ))
2126+ where .append ('_%s._%s =%s' % (cn , k , a ))
21232127 args .append (v )
21242128
21252129 # don't match retired nodes
@@ -2129,7 +2133,7 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21292133 if search_matches is not None :
21302134 v = search_matches .keys ()
21312135 s = ',' .join ([a for x in v ])
2132- where .append ('id in (%s)' % s )
2136+ where .append ('_%s. id in (%s)' % ( cn , s ) )
21332137 args = args + v
21342138
21352139 # "grouping" is just the first-order sorting in the SQL fetch
@@ -2157,9 +2161,9 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21572161 ordercols .append (tn + '._order' )
21582162 o = tn + '._order'
21592163 elif prop == 'id' :
2160- o = 'id'
2164+ o = '_%s. id' % cn
21612165 else :
2162- o = '_' + prop
2166+ o = '_%s._%s' % ( cn , prop )
21632167 ordercols .append (o )
21642168 if sdir == '-' :
21652169 o += ' desc'
@@ -2187,6 +2191,7 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21872191 args = tuple (args )
21882192 if __debug__ :
21892193 print >> hyperdb .DEBUG , 'filter' , (self , sql , args )
2194+ __traceback_info__ = (sql , args )
21902195 if args :
21912196 self .db .cursor .execute (sql , args )
21922197 else :
0 commit comments