Ticket #5236: django_sql_debug_stack.patch
File django_sql_debug_stack.patch, 1.6 KB (added by , 17 years ago) |
---|
-
django/db/backends/util.py
1 1 import datetime 2 2 import md5 3 import traceback 3 4 from time import time 5 from django.db import backends 4 6 from django.utils.encoding import smart_unicode, force_unicode 5 7 6 8 try: … … 18 20 try: 19 21 return self.cursor.execute(sql, params) 20 22 finally: 21 stop = time() 22 self.db.queries.append({ 23 'sql': smart_unicode(sql) % convert_args(params), 24 'time': "%.3f" % (stop - start), 25 }) 23 self.save_entry(smart_unicode(sql) % convert_args(params), start) 26 24 25 def save_entry (self, sql, start): 26 stop = time() 27 entry = { 28 'sql': sql, 29 'time': "%.3f" % (stop - start), 30 'stack': traceback.format_stack(), 31 } 32 self.db.queries.append(entry) 33 27 34 def executemany(self, sql, param_list): 28 35 start = time() 29 36 try: 30 37 return self.cursor.executemany(sql, param_list) 31 38 finally: 32 stop = time() 33 self.db.queries.append({ 34 'sql': 'MANY: ' + sql + ' ' + smart_unicode(tuple(param_list)), 35 'time': "%.3f" % (stop - start), 36 }) 39 strsql = 'MANY: ' + sql + ' ' + smart_unicode(tuple(param_list)) 40 self.save_entry(strsql, start) 37 41 38 42 def __getattr__(self, attr): 39 43 if attr in self.__dict__: