From ee75a75f7e379b492af927b261726bc5d40fdb50 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 20 Sep 2008 23:31:45 +0100 Subject: Show 1 SQL query v.s. 3 SQL queries --- debug_toolbar/panels/sql.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'debug_toolbar/panels/sql.py') diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 4b059ac..81834b4 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -39,7 +39,11 @@ class SQLDebugPanel(DebugPanel): def title(self): self._sql_time = sum(map(lambda q: float(q['time']) * 1000, connection.queries)) - return '%d SQL Queries (%.2fms)' % (len(connection.queries), self._sql_time) + return '%d SQL %s (%.2fms)' % ( + len(connection.queries), + (len(connection.queries) == 1) and 'query' or 'queries', + self._sql_time + ) def url(self): return '' -- cgit v1.2.3 From ee810109f7dfb8c70278b5c447b4604bccc987a0 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Sun, 21 Sep 2008 22:35:15 -0700 Subject: Refactoring middleware and panels so panels have more explicit middleware-like methods to be more clear when panel processing happens. --- debug_toolbar/panels/sql.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'debug_toolbar/panels/sql.py') diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 81834b4..b99709f 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -27,13 +27,13 @@ util.CursorDebugWrapper = DatabaseStatTracker class SQLDebugPanel(DebugPanel): """ - Panel that displays information about the SQL queries run while processing the request. + Panel that displays information about the SQL queries run while processing + the request. """ name = 'SQL' has_content = True - def __init__(self, request): - super(SQLDebugPanel, self).__init__(request) + def __init__(self): self._offset = len(connection.queries) self._sql_time = 0 -- cgit v1.2.3 From 7ea7e780b775680be3050a8d6eb71f63b5a1fd34 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Tue, 23 Sep 2008 19:55:18 -0700 Subject: Updating pygments styles to better match new toolbar styles. --- debug_toolbar/panels/sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'debug_toolbar/panels/sql.py') diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index b99709f..e4e3c02 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -72,7 +72,7 @@ def reformat_sql(sql): from pygments import highlight from pygments.lexers import SqlLexer from pygments.formatters import HtmlFormatter - sql = highlight(sql, SqlLexer(), HtmlFormatter(noclasses=True)) + sql = highlight(sql, SqlLexer(), HtmlFormatter()) except ImportError: pass return sql -- cgit v1.2.3 From 159e690ff3d07c8821332942ae722bdf0bdf5208 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Tue, 23 Sep 2008 21:06:39 -0700 Subject: Add catch for non JSON serializable objects and don't show the EXPLAIN link for these. --- debug_toolbar/panels/sql.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'debug_toolbar/panels/sql.py') diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index e4e3c02..9223cb7 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -16,12 +16,17 @@ class DatabaseStatTracker(util.CursorDebugWrapper): return self.cursor.execute(sql, params) finally: stop = time.time() + _params = None + try: + _params = simplejson.dumps(params) + except TypeError: + pass # object not JSON serializable # We keep `sql` to maintain backwards compatibility self.db.queries.append({ 'sql': self.db.ops.last_executed_query(self.cursor, sql, params), 'time': stop - start, 'raw_sql': sql, - 'params': simplejson.dumps(params), + 'params': _params }) util.CursorDebugWrapper = DatabaseStatTracker -- cgit v1.2.3 From 85d879803c88aa036934d36977a10b5d28b70aaa Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Wed, 24 Sep 2008 16:23:01 -0700 Subject: Adding a SHA-1 hash to the parameters passed to get the EXPLAIN query to avoid any sort of tampering of the SQL or parameters. --- debug_toolbar/panels/sql.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'debug_toolbar/panels/sql.py') diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 9223cb7..22d65a7 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -1,9 +1,11 @@ import time from debug_toolbar.panels import DebugPanel +from django.conf import settings from django.db import connection from django.db.backends import util from django.template.loader import render_to_string from django.utils import simplejson +from django.utils.hashcompat import sha_constructor class DatabaseStatTracker(util.CursorDebugWrapper): """ @@ -26,7 +28,8 @@ class DatabaseStatTracker(util.CursorDebugWrapper): 'sql': self.db.ops.last_executed_query(self.cursor, sql, params), 'time': stop - start, 'raw_sql': sql, - 'params': _params + 'params': _params, + 'hash': sha_constructor(settings.SECRET_KEY + sql + _params).hexdigest(), }) util.CursorDebugWrapper = DatabaseStatTracker @@ -37,7 +40,7 @@ class SQLDebugPanel(DebugPanel): """ name = 'SQL' has_content = True - + def __init__(self): self._offset = len(connection.queries) self._sql_time = 0 -- cgit v1.2.3