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 Holovaty
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:

Description

This should be self-explanatory

Index: D:/web/projects/django-newforms/django/db/backends/util.py
===================================================================
--- D:/web/projects/django-newforms/django/db/backends/util.py	(revision 5753)
+++ D:/web/projects/django-newforms/django/db/backends/util.py	(working copy)
@@ -19,6 +19,15 @@
             return self.cursor.execute(sql, params)
         finally:
             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
             self.db.queries.append({
                 '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@…>

Attachment: 5018.patch.txt added

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 Holovaty

Resolution: wontfix
Status: newclosed

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