Opened 17 years ago
Closed 17 years ago
#5018 closed (wontfix)
Add SQL_DEBUG option that shows SQL queries being executed
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
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: | no | UI/UX: | no |
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)
Change History (3)
by , 17 years ago
Attachment: | 5018.patch.txt added |
---|
comment:1 by , 17 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
comment:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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.
patch for SQL_DEBUG