From 2aa9d45c019202b0ad5d165f4cf49dc8c170dfae Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 14 May 2007 10:48:24 +0000 Subject: [PATCH] Reintroduced support for parameter dictionaries when using the PostgreSQL psycopg1 backend directly. Refs #3322. Based on a patch from kurtiss@meetro.com. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5227 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/db/backends/postgresql/base.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index f5d274ebc5..486359cc62 100644 --- a/AUTHORS +++ b/AUTHORS @@ -141,6 +141,7 @@ answer newbie questions, and generally made Django that much better: Bruce Kroeze Joseph Kocherhans konrad@gwu.edu + kurtiss@meetro.com lakin.wecker@gmail.com Stuart Langridge Nicola Larosa diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index ef0d06f6a1..a6a2351c6e 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -40,11 +40,21 @@ class UnicodeCursorWrapper(object): self.cursor = cursor self.charset = charset + def format_params(self, params): + if isinstance(params, dict): + result = {} + charset = self.charset + for key, value in params.items(): + result[smart_str(key, charset)] = smart_str(value, charset) + return result + else: + return tuple([smart_str(p, self.charset, True) for p in params]) + def execute(self, sql, params=()): - return self.cursor.execute(smart_str(sql, self.charset), [smart_str(p, self.charset, True) for p in params]) + return self.cursor.execute(smart_str(sql, self.charset), self.format_params(params)) def executemany(self, sql, param_list): - new_param_list = [tuple([smart_str(p, self.charset) for p in params]) for params in param_list] + new_param_list = [self.format_params(params) for params in param_list] return self.cursor.executemany(sql, new_param_list) def __getattr__(self, attr):