+
+ # psycopg2 requires %()s format for all parameters,
+ # regardless of type.
+ # this needs to be done carefully though as with pattern-based filters
+ # we might have percents embedded in the query
+ # so e.g. GetPersons({'email':'*fake*'}) was resulting in .. LIKE '%sake%'
+ if psycopg2:
+ query = re.sub(r'(%\([^)]*\)|%)[df]', r'\1s', query)
+ # rewrite wildcards set by Filter.py as '***' into '%'
+ query = query.replace ('***','%')
+
+ if not params:
+ if self.debug:
+ print >> log,'execute0',query
+ cursor.execute(query)
+ elif isinstance(params,dict):
+ if self.debug:
+ print >> log,'execute-dict: params',params,'query',query%params
+ cursor.execute(query,params)
+ elif isinstance(params,tuple) and len(params)==1:
+ if self.debug:
+ print >> log,'execute-tuple',query%params[0]
+ cursor.execute(query,params[0])
+ else:
+ param_seq=(params,)
+ if self.debug:
+ for params in param_seq:
+ print >> log,'executemany',query%params
+ cursor.executemany(query, param_seq)