Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Malcolm Tredinnick authored May 15, 2007

Showing 1 changed file with 11 additions and 6 deletions. Show diff stats Hide diff stats

  1. 17  django/db/backends/util.py
17  django/db/backends/util.py
@@ -13,12 +13,8 @@ def execute(self, sql, params=()):
13 13
             return self.cursor.execute(sql, params)
14 14
         finally:
15 15
             stop = time()
16  
-            # If params was a list, convert it to a tuple, because string
17  
-            # formatting with '%' only works with tuples or dicts.
18  
-            if not isinstance(params, (tuple, dict)):
19  
-                params = tuple(params)
20 16
             self.db.queries.append({
21  
-                'sql': smart_unicode(sql) % params,
  17
+                'sql': smart_unicode(sql) % convert_args(params),
22 18
                 'time': "%.3f" % (stop - start),
23 19
             })
24 20
 
@@ -29,7 +25,7 @@ def executemany(self, sql, param_list):
29 25
         finally:
30 26
             stop = time()
31 27
             self.db.queries.append({
32  
-                'sql': 'MANY: ' + sql + ' ' + str(tuple(param_list)),
  28
+                'sql': 'MANY: ' + sql + ' ' + smart_unicode(tuple(param_list)),
33 29
                 'time': "%.3f" % (stop - start),
34 30
             })
35 31
 
@@ -39,6 +35,15 @@ def __getattr__(self, attr):
39 35
         else:
40 36
             return getattr(self.cursor, attr)
41 37
 
  38
+def convert_args(args):
  39
+    """
  40
+    Convert sequence or dictionary to contain unicode values.
  41
+    """
  42
+    if isinstance(args, (list, tuple)):
  43
+        return tuple([smart_unicode(val) for val in args])
  44
+    else:
  45
+        return dict([(smart_unicode(k), smart_unicode(v)) for k, v in args.items()])
  46
+
42 47
 ###############################################
43 48
 # Converters from database (string) to Python #
44 49
 ###############################################

0 notes on commit 0e4c383

Please sign in to comment.
Something went wrong with that request. Please try again.