diff --git a/src/Database/Log/DebugLog.php b/src/Database/Log/DebugLog.php index 8403f132..a9e6d22b 100644 --- a/src/Database/Log/DebugLog.php +++ b/src/Database/Log/DebugLog.php @@ -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 * @@ -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; + } } /** diff --git a/templates/element/sql_log_panel.php b/templates/element/sql_log_panel.php index 4fbba0c9..7e6e6d52 100644 --- a/templates/element/sql_log_panel.php +++ b/templates/element/sql_log_panel.php @@ -73,7 +73,7 @@ - + > + + + + + + @@ -99,6 +105,6 @@ -
No active database connections
+
No active database connections
diff --git a/webroot/css/style.css b/webroot/css/style.css index d6d1e894..00ec962b 100644 --- a/webroot/css/style.css +++ b/webroot/css/style.css @@ -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);