Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 0e4c3838abc640fa64f061d2df242277501a4a34 1 parent 19ad4a4
@malcolmt malcolmt authored
Showing with 11 additions and 6 deletions.
  1. +11 −6 django/db/backends/util.py
View
17 django/db/backends/util.py
@@ -13,12 +13,8 @@ def execute(self, sql, params=()):
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 @@ def executemany(self, sql, param_list):
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 @@ def __getattr__(self, attr):
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 #
###############################################
Please sign in to comment.
Something went wrong with that request. Please try again.