From 0e4c3838abc640fa64f061d2df242277501a4a34 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 15 May 2007 16:13:37 +0000 Subject: [PATCH] unicode: Improved the fix for debug query logging from [5208]. Refs #3891. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5247 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/util.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/django/db/backends/util.py b/django/db/backends/util.py index 000d03eae4..6047f7df08 100644 --- a/django/db/backends/util.py +++ b/django/db/backends/util.py @@ -13,12 +13,8 @@ class CursorDebugWrapper(object): return self.cursor.execute(sql, params) finally: stop = time() - # If params was a list, convert it to a tuple, because string - # formatting with '%' only works with tuples or dicts. - if not isinstance(params, (tuple, dict)): - params = tuple(params) self.db.queries.append({ - 'sql': smart_unicode(sql) % params, + 'sql': smart_unicode(sql) % convert_args(params), 'time': "%.3f" % (stop - start), }) @@ -29,7 +25,7 @@ class CursorDebugWrapper(object): finally: stop = time() self.db.queries.append({ - 'sql': 'MANY: ' + sql + ' ' + str(tuple(param_list)), + 'sql': 'MANY: ' + sql + ' ' + smart_unicode(tuple(param_list)), 'time': "%.3f" % (stop - start), }) @@ -39,6 +35,15 @@ class CursorDebugWrapper(object): else: return getattr(self.cursor, attr) +def convert_args(args): + """ + Convert sequence or dictionary to contain unicode values. + """ + if isinstance(args, (list, tuple)): + return tuple([smart_unicode(val) for val in args]) + else: + return dict([(smart_unicode(k), smart_unicode(v)) for k, v in args.items()]) + ############################################### # Converters from database (string) to Python # ###############################################