mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
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
This commit is contained in:
parent
19ad4a47ba
commit
0e4c3838ab
@ -13,12 +13,8 @@ class CursorDebugWrapper(object):
|
|||||||
return self.cursor.execute(sql, params)
|
return self.cursor.execute(sql, params)
|
||||||
finally:
|
finally:
|
||||||
stop = time()
|
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({
|
self.db.queries.append({
|
||||||
'sql': smart_unicode(sql) % params,
|
'sql': smart_unicode(sql) % convert_args(params),
|
||||||
'time': "%.3f" % (stop - start),
|
'time': "%.3f" % (stop - start),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -29,7 +25,7 @@ class CursorDebugWrapper(object):
|
|||||||
finally:
|
finally:
|
||||||
stop = time()
|
stop = time()
|
||||||
self.db.queries.append({
|
self.db.queries.append({
|
||||||
'sql': 'MANY: ' + sql + ' ' + str(tuple(param_list)),
|
'sql': 'MANY: ' + sql + ' ' + smart_unicode(tuple(param_list)),
|
||||||
'time': "%.3f" % (stop - start),
|
'time': "%.3f" % (stop - start),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -39,6 +35,15 @@ class CursorDebugWrapper(object):
|
|||||||
else:
|
else:
|
||||||
return getattr(self.cursor, attr)
|
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 #
|
# Converters from database (string) to Python #
|
||||||
###############################################
|
###############################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user