Opened 9 years ago

Closed 9 years ago

#5018 closed (wontfix)

Add SQL_DEBUG option that shows SQL queries being executed

Reported by: Yuri Baburov <burchik@…> Owned by: adrian
Component: Database layer (models, ORM) Version: master
Severity: Keywords: SQL_DEBUG, SQL, queries, show, development, server
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:


This should be self-explanatory

Index: D:/web/projects/django-newforms/django/db/backends/
--- D:/web/projects/django-newforms/django/db/backends/	(revision 5753)
+++ D:/web/projects/django-newforms/django/db/backends/	(working copy)
@@ -19,6 +19,15 @@
             return self.cursor.execute(sql, params)
             stop = time()
+            from django.conf import settings
+            # 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)
+            if getattr(settings, 'SQL_DEBUG', False):
+                if not isinstance(params, (tuple, dict)):
+                    params = tuple(params)
+                print '>', sql % params
                 'sql': smart_unicode(sql) % convert_args(params),
                 'time': "%.3f" % (stop - start),

Attachments (1)

5018.patch.txt (1.1 KB) - added by buriy <burchik@…> 9 years ago.
patch for SQL_DEBUG

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by buriy <burchik@…>

patch for SQL_DEBUG

comment:1 Changed 9 years ago by buriy <burchik@…>

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set

comment:2 Changed 9 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to closed

Instead of yet another setting, I'd like a cleaner solution to the problem of SQL queries being hard to get at -- perhaps a signal. We've discussed this recently on the django-developers mailing list.

Note: See TracTickets for help on using tickets.
Back to Top