summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-15 16:13:37 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-15 16:13:37 +0000
commit0e4c3838abc640fa64f061d2df242277501a4a34 (patch)
tree2820c5197fd17a83cfe3f376ee3e159c95a04e87
parent19ad4a47ba660e5861a3a72f7b156a0653590370 (diff)
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
-rw-r--r--django/db/backends/util.py17
1 files 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 #
###############################################