Skip to content

Commit 2a680ed

Browse files
authored
Merge pull request lonnieezell#24 from aa6my/master
Fixing the issue interpolateQuery
2 parents 78199e0 + b130844 commit 2a680ed

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

config/profiler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
$config['eloquent'] = FALSE;
1818
$config['uri_string'] = TRUE;
1919
$config['view_data'] = TRUE;
20-
$config['query_toggle_count'] = 50;
20+
$config['query_toggle_count'] = 50;

libraries/Profiler.php

+28-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ protected function _compile_eloquent()
253253
$time = number_format($q['time']/1000, 4);
254254
$total += $q['time']/1000;
255255

256-
$query = interpolateQuery($q['query'], $q['bindings']);
256+
$query = $this->interpolateQuery($q['query'], $q['bindings']);
257257
foreach ($highlight as $bold)
258258
$query = str_ireplace($bold, '<b>'.$bold.'</b>', $query);
259259

@@ -274,6 +274,33 @@ protected function _compile_eloquent()
274274
return $output;
275275
}
276276

277+
public function interpolateQuery($query, array $params) {
278+
$keys = array();
279+
$values = $params;
280+
281+
//build a regular expression for each parameter
282+
foreach ($params as $key => $value) {
283+
if (is_string($key)) {
284+
$keys[] = "/:" . $key . "/";
285+
} else {
286+
$keys[] = '/[?]/';
287+
}
288+
289+
if (is_string($value))
290+
$values[$key] = "'" . $value . "'";
291+
292+
if (is_array($value))
293+
$values[$key] = implode(',', $value);
294+
295+
if (is_null($value))
296+
$values[$key] = 'NULL';
297+
}
298+
299+
$query = preg_replace($keys, $values, $query, 1, $count);
300+
301+
return $query;
302+
}
303+
277304

278305
// --------------------------------------------------------------------
279306

0 commit comments

Comments
 (0)