@@ -139,12 +139,9 @@ public function startMemoryUsage()
139
139
140
140
/**
141
141
*
142
- * @param string $query
143
- * @param array $bindings
144
- * @param float $time
145
- * @param \Illuminate\Database\Connection $connection
142
+ * @param \Illuminate\Database\Events\QueryExecuted $query
146
143
*/
147
- public function addQuery ($ query, $ bindings , $ time , $ connection )
144
+ public function addQuery ($ query )
148
145
{
149
146
$ this ->queryCount ++;
150
147
@@ -154,24 +151,24 @@ public function addQuery($query, $bindings, $time, $connection)
154
151
155
152
$ limited = $ this ->softLimit && $ this ->queryCount > $ this ->softLimit ;
156
153
157
-
154
+ $ sql = ( string ) $ query -> sql ;
158
155
$ explainResults = [];
159
- $ time = $ time / 1000 ;
156
+ $ time = $ query -> time / 1000 ;
160
157
$ endTime = microtime (true );
161
158
$ startTime = $ endTime - $ time ;
162
- $ hints = $ this ->performQueryAnalysis ($ query );
159
+ $ hints = $ this ->performQueryAnalysis ($ sql );
163
160
164
161
$ pdo = null ;
165
162
try {
166
- $ pdo = $ connection ->getPdo ();
163
+ $ pdo = $ query -> connection ->getPdo ();
167
164
} catch (\Throwable $ e ) {
168
165
// ignore error for non-pdo laravel drivers
169
166
}
170
- $ bindings = $ connection ->prepareBindings ($ bindings );
167
+ $ bindings = $ query -> connection ->prepareBindings ($ query -> bindings );
171
168
172
169
// Run EXPLAIN on this query (if needed)
173
- if (!$ limited && $ this ->explainQuery && $ pdo && preg_match ('/^\s*( ' . implode ('| ' , $ this ->explainTypes ) . ') /i ' , $ query )) {
174
- $ statement = $ pdo ->prepare ('EXPLAIN ' . $ query );
170
+ if (!$ limited && $ this ->explainQuery && $ pdo && preg_match ('/^\s*( ' . implode ('| ' , $ this ->explainTypes ) . ') /i ' , $ sql )) {
171
+ $ statement = $ pdo ->prepare ('EXPLAIN ' . $ sql );
175
172
$ statement ->execute ($ bindings );
176
173
$ explainResults = $ statement ->fetchAll (\PDO ::FETCH_CLASS );
177
174
}
@@ -199,7 +196,7 @@ public function addQuery($query, $bindings, $time, $connection)
199
196
}
200
197
}
201
198
202
- $ query = preg_replace ($ regex , addcslashes ($ binding , '$ ' ), $ query , 1 );
199
+ $ sql = preg_replace ($ regex , addcslashes ($ binding , '$ ' ), $ sql , 1 );
203
200
}
204
201
}
205
202
@@ -213,16 +210,16 @@ public function addQuery($query, $bindings, $time, $connection)
213
210
}
214
211
215
212
$ this ->queries [] = [
216
- 'query ' => $ query ,
213
+ 'query ' => $ sql ,
217
214
'type ' => 'query ' ,
218
215
'bindings ' => !$ limited ? $ this ->getDataFormatter ()->escapeBindings ($ bindings ) : null ,
219
216
'start ' => $ startTime ,
220
217
'time ' => $ time ,
221
218
'memory ' => $ this ->lastMemoryUsage ? memory_get_usage (false ) - $ this ->lastMemoryUsage : 0 ,
222
219
'source ' => $ source ,
223
220
'explain ' => $ explainResults ,
224
- 'connection ' => $ connection ->getDatabaseName (),
225
- 'driver ' => $ connection ->getConfig ('driver ' ),
221
+ 'connection ' => $ query -> connection ->getDatabaseName (),
222
+ 'driver ' => $ query -> connection ->getConfig ('driver ' ),
226
223
'hints ' => ($ this ->showHints && !$ limited ) ? $ hints : null ,
227
224
'show_copy ' => $ this ->showCopyButton ,
228
225
];
0 commit comments