Skip to content

Commit e2e5eca

Browse files
authored
Merge pull request #4077 from najdanovicivan/nosql/debug-toolbar
DebugToolbar - Handle Query display in Query class
2 parents 174b701 + e6ae0a2 commit e2e5eca

File tree

2 files changed

+58
-53
lines changed

2 files changed

+58
-53
lines changed

system/Database/Query.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,58 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
473473

474474
//--------------------------------------------------------------------
475475

476+
/**
477+
* Returns string to display in debug toolbar
478+
*
479+
* @return string
480+
*/
481+
public function debugToolbarDisplay(): string
482+
{
483+
// Key words we want bolded
484+
static $highlight = [
485+
'SELECT',
486+
'DISTINCT',
487+
'FROM',
488+
'WHERE',
489+
'AND',
490+
'LEFT JOIN',
491+
'RIGHT JOIN',
492+
'JOIN',
493+
'ORDER BY',
494+
'GROUP BY',
495+
'LIMIT',
496+
'INSERT',
497+
'INTO',
498+
'VALUES',
499+
'UPDATE',
500+
'OR ',
501+
'HAVING',
502+
'OFFSET',
503+
'NOT IN',
504+
'IN',
505+
'LIKE',
506+
'NOT LIKE',
507+
'COUNT',
508+
'MAX',
509+
'MIN',
510+
'ON',
511+
'AS',
512+
'AVG',
513+
'SUM',
514+
'(',
515+
')',
516+
];
517+
518+
$sql = $this->getQuery();
519+
520+
foreach ($highlight as $term)
521+
{
522+
$sql = str_replace($term, '<strong>' . $term . '</strong>', $sql);
523+
}
524+
525+
return $sql;
526+
}
527+
476528
/**
477529
* Return text representation of the query
478530
*

system/Debug/Toolbar/Collectors/Database.php

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Database extends BaseCollector
5757
* The query instances that have been collected
5858
* through the DBQuery Event.
5959
*
60-
* @var array
60+
* @var Query[]
6161
*/
6262
protected static $queries = [];
6363

@@ -138,59 +138,12 @@ protected function formatTimelineData(): array
138138
*/
139139
public function display(): array
140140
{
141-
// Key words we want bolded
142-
$highlight = [
143-
'SELECT',
144-
'DISTINCT',
145-
'FROM',
146-
'WHERE',
147-
'AND',
148-
'LEFT&nbsp;JOIN',
149-
'RIGHT&nbsp;JOIN',
150-
'JOIN',
151-
'ORDER&nbsp;BY',
152-
'GROUP&nbsp;BY',
153-
'LIMIT',
154-
'INSERT',
155-
'INTO',
156-
'VALUES',
157-
'UPDATE',
158-
'OR&nbsp;',
159-
'HAVING',
160-
'OFFSET',
161-
'NOT&nbsp;IN',
162-
'IN',
163-
'LIKE',
164-
'NOT&nbsp;LIKE',
165-
'COUNT',
166-
'MAX',
167-
'MIN',
168-
'ON',
169-
'AS',
170-
'AVG',
171-
'SUM',
172-
'(',
173-
')',
174-
];
175-
176-
$data = [
177-
'queries' => [],
178-
];
179-
180-
foreach (static::$queries as $query)
181-
{
182-
$sql = $query->getQuery();
183-
184-
foreach ($highlight as $term)
185-
{
186-
$sql = str_replace($term, "<strong>{$term}</strong>", $sql);
187-
}
188-
189-
$data['queries'][] = [
190-
'duration' => ($query->getDuration(5) * 1000) . ' ms',
191-
'sql' => $sql,
141+
$data['queries'] = array_map(function (Query $query) {
142+
return [
143+
'duration' => ((float) $query->getDuration(5) * 1000) . ' ms',
144+
'sql' => $query->debugToolbarDisplay(),
192145
];
193-
}
146+
}, static::$queries);
194147

195148
return $data;
196149
}

0 commit comments

Comments
 (0)