+
+ # 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:
+ logger.debug('execute0: {}'.format(query))
+ cursor.execute(query)
+ elif isinstance(params, dict):
+ if self.debug:
+ logger.debug('execute-dict: params {} query {}'
+ .format(params, query%params))
+ cursor.execute(query, params)
+ elif isinstance(params,tuple) and len(params)==1:
+ if self.debug:
+ logger.debug('execute-tuple {}'.format(query%params[0]))
+ cursor.execute(query,params[0])
+ else:
+ param_seq=(params,)
+ if self.debug:
+ for params in param_seq:
+ logger.debug('executemany {}'.format(query%params))
+ cursor.executemany(query, param_seq)