@csrf_exempt
def sql_explain(request):
 form = SQLSelectForm((request.POST or None))
 if form.is_valid():
  sql = form.cleaned_data[u'raw_sql']
  params = form.cleaned_data[u'params']
  vendor = form.connection.vendor
  cursor = form.cursor
  if (vendor == u'sqlite'):
   cursor.execute((u'EXPLAIN QUERY PLAN %s' % (sql,)), params)
  elif (vendor == u'postgresql'):
   cursor.execute((u'EXPLAIN ANALYZE %s' % (sql,)), params)
  else:
   cursor.execute((u'EXPLAIN %s' % (sql,)), params)
  headers = [d[0] for d in cursor.description]
  result = cursor.fetchall()
  cursor.close()
  context = {u'result': result, u'sql': form.reformat_sql(), u'duration': form.cleaned_data[u'duration'], u'headers': headers, u'alias': form.cleaned_data[u'alias']}
  return render_to_response(u'debug_toolbar/panels/sql_explain.html', context)
 return HttpResponseBadRequest(u'Form errors')

@ csrf_exempt def sql_explain ( request ) : form = SQLSelectForm ( ( request . POST or None ) ) if form . is_valid ( ) : sql = form . cleaned_data [ u'raw_sql' ] params = form . cleaned_data [ u'params' ] vendor = form . connection . vendor cursor = form . cursor if ( vendor == u'sqlite' ) : cursor . execute ( ( u'EXPLAIN QUERY PLAN %s' % ( sql , ) ) , params ) elif ( vendor == u'postgresql' ) : cursor . execute ( ( u'EXPLAIN ANALYZE %s' % ( sql , ) ) , params ) else : cursor . execute ( ( u'EXPLAIN %s' % ( sql , ) ) , params ) headers = [ d [ 0 ] for d in cursor . description ] result = cursor . fetchall ( ) cursor . close ( ) context = { u'result' : result , u'sql' : form . reformat_sql ( ) , u'duration' : form . cleaned_data [ u'duration' ] , u'headers' : headers , u'alias' : form . cleaned_data [ u'alias' ] } return render_to_response ( u'debug_toolbar/panels/sql_explain.html' , context ) return HttpResponseBadRequest ( u'Form errors' )
returns the output of the sql explain on the given query .