aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/management/commands/debugsqlshell.py
blob: c0e1fc1d4388ccb9ca8ac7db61162a91b9831703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from datetime import datetime

from django.db.backends import util

from debug_toolbar.utils import ms_from_timedelta, sqlparse


class PrintQueryWrapper(util.CursorDebugWrapper):
    def execute(self, sql, params=()):
        starttime = datetime.now()
        try:
            return self.cursor.execute(sql, params)
        finally:
            raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
            execution_time = datetime.now() - starttime
            print sqlparse.format(raw_sql, reindent=True),
            print ' [%.2fms]' % (ms_from_timedelta(execution_time),)
            print

util.CursorDebugWrapper = PrintQueryWrapper