Ticket #3322: pyformat_psql.diff
File pyformat_psql.diff, 1.2 KB (added by , 18 years ago) |
---|
-
base.py
25 25 return s.encode(charset) 26 26 return s 27 27 28 def smart_formatobj(o, charset): 29 if isinstance(o, dict): 30 def reduction(encoded_dct, key): 31 encoded_dct[key] = smart_basestring(o[key], charset) 32 return encoded_dct 33 return reduce(reduction, o, {}) 34 else: 35 return [smart_basestring(param, charset) for param in o] 36 28 37 class UnicodeCursorWrapper(object): 29 38 """ 30 39 A thin wrapper around psycopg cursors that allows them to accept Unicode … … 40 49 self.charset = charset 41 50 42 51 def execute(self, sql, params=()): 43 return self.cursor.execute(sql, [smart_basestring(p, self.charset) for p in params])52 return self.cursor.execute(sql, smart_formatobj(params, self.charset)) 44 53 45 54 def executemany(self, sql, param_list): 46 new_param_list = [tuple( [smart_basestring(p, self.charset) for p in params]) for params in param_list]55 new_param_list = [tuple(smart_formatobj(params, self.charset)) for params in param_list] 47 56 return self.cursor.executemany(sql, new_param_list) 48 57 49 58 def __getattr__(self, attr):