nextcloud/lib/private/DB/Logging/Connection.php
Joas Schilling de5a7c3c73
fix(db)!: Reimplement the query logger with a doctrine middleware
Signed-off-by: Joas Schilling <coding@schilljs.com>
2024-07-04 14:19:47 +02:00

49 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2024 Doctrine Project
* SPDX-License-Identifier: MIT
*/
namespace OC\DB\Logging;
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use OCP\Diagnostics\IQueryLogger;
final class Connection extends AbstractConnectionMiddleware {
public function __construct(
ConnectionInterface $connection,
private readonly IQueryLogger $queryLogger,
) {
parent::__construct($connection);
}
public function prepare(string $sql): DriverStatement {
return new Statement(
parent::prepare($sql),
$this->queryLogger,
$sql,
);
}
public function query(string $sql): Result {
$this->queryLogger->startQuery($sql);
$result = parent::query($sql);
$this->queryLogger->stopQuery();
return $result;
}
public function exec(string $sql): int|string {
$this->queryLogger->startQuery($sql);
$result = parent::exec($sql);
$this->queryLogger->stopQuery();
return $result;
}
}