aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/management/commands/debugsqlshell.py
blob: 71723fa6ea4fa3f881a240a441b38056c85b6724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os
from optparse import make_option

from django.db.backends import util
from django.core.management.commands.shell import Command

from debug_toolbar.utils import sqlparse

class PrintQueryWrapper(util.CursorDebugWrapper):
    def execute(self, sql, params=()):
        try:
            return self.cursor.execute(sql, params)
        finally:
            raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
            print sqlparse.format(raw_sql, reindent=True)
            print

util.CursorDebugWrapper = PrintQueryWrapper