diff options
Diffstat (limited to 'debug_toolbar/views.py')
| -rw-r--r-- | debug_toolbar/views.py | 23 |
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): |
