Skip to content

Commit fba93b8

Browse files
acdharobhudson
authored andcommitted
Views.py tweaked to use friendlier "EXPLAIN QUERY PLAN" with sqlite3
Signed-off-by: Rob Hudson <[email protected]>
1 parent a349704 commit fba93b8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

debug_toolbar/views.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ def sql_explain(request):
7777
if sql.lower().strip().startswith('select'):
7878
params = simplejson.loads(params)
7979
cursor = connection.cursor()
80-
cursor.execute("EXPLAIN %s" % (sql,), params)
80+
81+
if settings.DATABASE_ENGINE == "sqlite3":
82+
# SQLite's EXPLAIN dumps the low-level opcodes generated for a query;
83+
# EXPLAIN QUERY PLAN dumps a more human-readable summary
84+
# See http://www.sqlite.org/lang_explain.html for details
85+
cursor.execute("EXPLAIN QUERY PLAN %s" % (sql,), params)
86+
else:
87+
cursor.execute("EXPLAIN %s" % (sql,), params)
88+
8189
headers = [d[0] for d in cursor.description]
8290
result = cursor.fetchall()
8391
cursor.close()

0 commit comments

Comments
 (0)