Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Database/Log/DebugLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class DebugLog extends AbstractLogger
*/
protected bool $_includeSchema = false;

/**
* Whether a transaction is currently open or not.
*
* @var bool
*/
protected bool $inTransaction = false;

/**
* Constructor
*
Expand Down Expand Up @@ -162,11 +169,25 @@ public function log($level, string|Stringable $message, array $context = []): vo

$this->_totalTime += $data['took'];

$sql = (string)$query;
$isBegin = $sql === 'BEGIN';
$isCommitOrRollback = $sql === 'COMMIT' || $sql === 'ROLLBACK';

if ($isBegin) {
$this->inTransaction = true;
}

$this->_queries[] = [
'query' => (string)$query,
'query' => $sql,
'took' => $data['took'],
'rows' => $data['numRows'],
'inTransaction' => $this->inTransaction,
'isCommitOrRollback' => $isCommitOrRollback,
];

if ($isCommitOrRollback) {
$this->inTransaction = false;
}
}

/**
Expand Down
10 changes: 8 additions & 2 deletions templates/element/sql_log_panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</thead>
<tbody>
<?php foreach ($queries as $query) : ?>
<tr>
<tr<?= $query['inTransaction'] ? ' class="in-transaction"' : '' ?>>
<td>
<?=
(new SqlFormatter(
Expand All @@ -91,6 +91,12 @@
<td><?= h($query['rows']) ?></td>
<td><?= h($query['took']) ?></td>
</tr>
<?php if ($query['isCommitOrRollback']): ?>
<tr>
<td colspan="3" class="commit-or-rollback">
</td>
</tr>
<?php endif; ?>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to add space between the queries.

<?php endforeach; ?>
</tbody>
</table>
Expand All @@ -99,6 +105,6 @@
<?php endif; ?>

<?php if ($noOutput) : ?>
<div class="c-flash c-flash--warning">No active database connections</div>
<div class="c-flash c-flash--warning">No active database connections</div>
<?php endif ?>
</div>
4 changes: 4 additions & 0 deletions webroot/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ strong {
box-shadow: 0 2px 0 var(--routes-btn-active-border);
}

.c-sql-log-panel__entry .in-transaction {
background: var(--cake-light-gray);
}

.c-toolbar {
display: flex;
background: var(--toolbar-bg);
Expand Down