@@ -125,6 +125,49 @@ def execute(self, sql, params=()):
125
125
pass
126
126
del cur_frame
127
127
128
+ # We keep `sql` to maintain backwards compatibility
129
+ self .db .queries .append ({
130
+ 'sql' : self .db .ops .last_executed_query (self .cursor , sql , params ),
131
+ 'duration' : duration ,
132
+ 'raw_sql' : sql ,
133
+ 'params' : _params ,
134
+ 'hash' : sha_constructor (settings .SECRET_KEY + sql + _params ).hexdigest (),
135
+ 'stacktrace' : stacktrace ,
136
+ 'start_time' : start ,
137
+ 'stop_time' : stop ,
138
+ 'is_slow' : (duration > SQL_WARNING_THRESHOLD ),
139
+ 'is_select' : sql .lower ().strip ().startswith ('select' ),
140
+ 'template_info' : template_info ,
141
+ })
142
+
143
+ def executemany (self , sql , params = ()):
144
+ start = datetime .now ()
145
+ try :
146
+ return self .cursor .executemany (sql , params )
147
+ finally :
148
+ stop = datetime .now ()
149
+ duration = ms_from_timedelta (stop - start )
150
+ stacktrace = tidy_stacktrace (traceback .extract_stack ())
151
+ _params = ''
152
+ try :
153
+ _params = simplejson .dumps ([force_unicode (x , strings_only = True ) for x in params ])
154
+ except TypeError :
155
+ pass # object not JSON serializable
156
+
157
+ template_info = None
158
+ cur_frame = sys ._getframe ().f_back
159
+ try :
160
+ while cur_frame is not None :
161
+ if cur_frame .f_code .co_name == 'render' :
162
+ node = cur_frame .f_locals ['self' ]
163
+ if isinstance (node , Node ):
164
+ template_info = get_template_info (node .source )
165
+ break
166
+ cur_frame = cur_frame .f_back
167
+ except :
168
+ pass
169
+ del cur_frame
170
+
128
171
# We keep `sql` to maintain backwards compatibility
129
172
self .db .queries .append ({
130
173
'sql' : self .db .ops .last_executed_query (self .cursor , sql , params ),
0 commit comments