Ticket #3322: pyformat_psql.diff

File pyformat_psql.diff, 1.2 KB (added by kurtiss@…, 17 years ago)

Reissues support for pyformat style format parameters using postgresql's UnicodeCursorWrapper

  • base.py

     
    2525        return s.encode(charset)
    2626    return s
    2727
     28def 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
    2837class UnicodeCursorWrapper(object):
    2938    """
    3039    A thin wrapper around psycopg cursors that allows them to accept Unicode
     
    4049        self.charset = charset
    4150
    4251    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))
    4453
    4554    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]
    4756        return self.cursor.executemany(sql, new_param_list)
    4857
    4958    def __getattr__(self, attr):
Back to Top