From 1c30bc016f7c6a40aadb61f570c48bc0af49d153 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Sun, 16 Sep 2012 19:32:32 -0700 Subject: Add EXPLAIN ANALYZE for Postgres --- debug_toolbar/views.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'debug_toolbar/views.py') diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py index be917ff..759cb66 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -87,6 +87,8 @@ def sql_explain(request): # EXPLAIN QUERY PLAN dumps a more human-readable summary # See http://www.sqlite.org/lang_explain.html for details cursor.execute("EXPLAIN QUERY PLAN %s" % (sql,), params) + elif engine == "psycopg2": + cursor.execute("EXPLAIN ANALYZE %s" % (sql,), params) else: cursor.execute("EXPLAIN %s" % (sql,), params) -- cgit v1.2.3 From d4971605cc0f82315805c44ea8346f609b1f07bb Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 30 Dec 2012 17:52:56 -0500 Subject: Use the built-in json module on python >= 2.6. `django.utils.simplejson` is pending deprecation as of django 1.5 and will be removed in 1.7. --- debug_toolbar/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'debug_toolbar/views.py') diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py index a642541..18b9460 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -9,13 +9,17 @@ import django.views.static from django.conf import settings from django.http import HttpResponseBadRequest from django.shortcuts import render_to_response -from django.utils import simplejson from debug_toolbar.utils.compat.db import connections +try: + import json +except ImportError: # python < 2.6 + from django.utils import simplejson as json + try: from hashlib import sha1 -except ImportError: +except ImportError: # python < 2.5 from django.utils.hashcompat import sha_constructor as sha1 @@ -45,7 +49,7 @@ def sql_select(request): if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): - params = simplejson.loads(params) + params = json.loads(params) cursor = connections[alias].cursor() cursor.execute(sql, params) headers = [d[0] for d in cursor.description] @@ -80,7 +84,7 @@ def sql_explain(request): if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): - params = simplejson.loads(params) + params = json.loads(params) cursor = connections[alias].cursor() conn = connections[alias].connection @@ -126,7 +130,7 @@ def sql_profile(request): if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): - params = simplejson.loads(params) + params = json.loads(params) cursor = connections[alias].cursor() result = None headers = None -- cgit v1.2.3