aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/views.py
diff options
context:
space:
mode:
authorRob Hudson2009-08-28 09:13:37 -0700
committerRob Hudson2009-08-28 09:13:37 -0700
commit4a59813e75d7cb3b88bf2b223b21d4e23d9ecb03 (patch)
treeb75b614c0eabc980cb72e3164adca6b08f3fc72d /debug_toolbar/views.py
parent0e5e71db6e1de7210aa9a546698942bfcdc98c73 (diff)
downloaddjango-debug-toolbar-4a59813e75d7cb3b88bf2b223b21d4e23d9ecb03.tar.bz2
Fixed sql profiling so it doesn't return a 500 if the SQL `SET PROFILING=1` results in an error. Also fixed view to render the correct template.
Diffstat (limited to 'debug_toolbar/views.py')
-rw-r--r--debug_toolbar/views.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py
index 9123a00..255a49c 100644
--- a/debug_toolbar/views.py
+++ b/debug_toolbar/views.py
@@ -109,21 +109,28 @@ def sql_profile(request):
if sql.lower().strip().startswith('select'):
params = simplejson.loads(params)
cursor = connection.cursor()
- cursor.execute("SET PROFILING=1") # Enable profiling
- cursor.execute(sql, params) # Execute SELECT
- cursor.execute("SET PROFILING=0") # Disable profiling
- # The Query ID should always be 1 here but I'll subselect to get the last one just in case...
- cursor.execute("SELECT * FROM information_schema.profiling WHERE query_id=(SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1)")
- headers = [d[0] for d in cursor.description]
- result = cursor.fetchall()
+ result = None
+ headers = None
+ result_error = None
+ try:
+ cursor.execute("SET PROFILING=1") # Enable profiling
+ cursor.execute(sql, params) # Execute SELECT
+ cursor.execute("SET PROFILING=0") # Disable profiling
+ # The Query ID should always be 1 here but I'll subselect to get the last one just in case...
+ cursor.execute("SELECT * FROM information_schema.profiling WHERE query_id=(SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1)")
+ headers = [d[0] for d in cursor.description]
+ result = cursor.fetchall()
+ except:
+ result_error = "Profiling is either not available or not supported by your database."
cursor.close()
context = {
'result': result,
+ 'result_error': result_error,
'sql': reformat_sql(cursor.db.ops.last_executed_query(cursor, sql, params)),
'time': request.GET.get('time', 0.0),
'headers': headers,
}
- return render_to_response('debug_toolbar/panels/sql_explain.html', context)
+ return render_to_response('debug_toolbar/panels/sql_profile.html', context)
raise InvalidSQLError("Only 'select' queries are allowed.")
def template_source(request):