Ticket #4651: 0.91-bugfixes-unicodecursorwrapper-dict-params.diff

File 0.91-bugfixes-unicodecursorwrapper-dict-params.diff, 1.4 KB (added by Tom Tobin <korpios@…>, 17 years ago)

Allow psycopg1 backend on 0.91-bugfixes to accept dict sql params

  • django/core/db/backends/postgresql.py

    diff -r bfff0679ea4c django/core/db/backends/postgresql.py
    a b class UnicodeCursorWrapper(object):  
    3636        self.charset = charset
    3737
    3838    def execute(self, sql, params=()):
    39         return self.cursor.execute(sql, [smart_basestring(p, self.charset) for p in params])
     39        try:
     40            params = dict([(k, smart_basestring(v, self.charset)) for (k, v) in params.items()])
     41        except AttributeError:
     42            params = [smart_basestring(p, self.charset) for p in params]
     43        return self.cursor.execute(sql, params)
    4044
    4145    def executemany(self, sql, param_list):
    42         new_param_list = [tuple([smart_basestring(p, self.charset) for p in params]) for params in param_list]
     46        try:
     47            new_param_list = [
     48                dict(
     49                    [(k, smart_basestring(v, self.charset)) for (k, v) in params.items()]
     50                    )
     51                for params in param_list
     52                ]
     53        except AttributeError:
     54            new_param_list = [
     55                tuple(
     56                    [smart_basestring(p, self.charset) for p in params]
     57                    )
     58                for params in param_list
     59                ]
    4360        return self.cursor.executemany(sql, new_param_list)
    4461
    4562    def __getattr__(self, attr):
Back to Top