|
|
@@ -53,6 +53,7 @@ use OCP\Diagnostics\IEventLogger; |
|
|
|
use OCP\IRequestId; |
|
|
|
use OCP\PreConditionNotMetException; |
|
|
|
use OCP\Profiler\IProfiler; |
|
|
|
use OCP\Server; |
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
|
|
|
class Connection extends \Doctrine\DBAL\Connection { |
|
|
@@ -78,6 +79,9 @@ class Connection extends \Doctrine\DBAL\Connection { |
|
|
|
/** @var DbDataCollector|null */ |
|
|
|
protected $dbDataCollector = null; |
|
|
|
|
|
|
|
protected bool $logRequestId; |
|
|
|
protected string $requestId; |
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes a new instance of the Connection class. |
|
|
|
* |
|
|
@@ -105,6 +109,9 @@ class Connection extends \Doctrine\DBAL\Connection { |
|
|
|
$this->systemConfig = \OC::$server->getSystemConfig(); |
|
|
|
$this->logger = \OC::$server->get(LoggerInterface::class); |
|
|
|
|
|
|
|
$this->logRequestId = $this->systemConfig->getValue('db.log_request_id', false); |
|
|
|
$this->requestId = Server::get(IRequestId::class)->getId(); |
|
|
|
|
|
|
|
/** @var \OCP\Profiler\IProfiler */ |
|
|
|
$profiler = \OC::$server->get(IProfiler::class); |
|
|
|
if ($profiler->isEnabled()) { |
|
|
@@ -232,8 +239,7 @@ class Connection extends \Doctrine\DBAL\Connection { |
|
|
|
$platform = $this->getDatabasePlatform(); |
|
|
|
$sql = $platform->modifyLimitQuery($sql, $limit, $offset); |
|
|
|
} |
|
|
|
$statement = $this->replaceTablePrefix($sql); |
|
|
|
$statement = $this->adapter->fixupStatement($statement); |
|
|
|
$statement = $this->finishQuery($sql); |
|
|
|
|
|
|
|
return parent::prepare($statement); |
|
|
|
} |
|
|
@@ -254,8 +260,7 @@ class Connection extends \Doctrine\DBAL\Connection { |
|
|
|
* @throws \Doctrine\DBAL\Exception |
|
|
|
*/ |
|
|
|
public function executeQuery(string $sql, array $params = [], $types = [], QueryCacheProfile $qcp = null): Result { |
|
|
|
$sql = $this->replaceTablePrefix($sql); |
|
|
|
$sql = $this->adapter->fixupStatement($sql); |
|
|
|
$sql = $this->finishQuery($sql); |
|
|
|
$this->queriesExecuted++; |
|
|
|
$this->logQueryToFile($sql); |
|
|
|
return parent::executeQuery($sql, $params, $types, $qcp); |
|
|
@@ -265,8 +270,7 @@ class Connection extends \Doctrine\DBAL\Connection { |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public function executeUpdate(string $sql, array $params = [], array $types = []): int { |
|
|
|
$sql = $this->replaceTablePrefix($sql); |
|
|
|
$sql = $this->adapter->fixupStatement($sql); |
|
|
|
$sql = $this->finishQuery($sql); |
|
|
|
$this->queriesExecuted++; |
|
|
|
$this->logQueryToFile($sql); |
|
|
|
return parent::executeUpdate($sql, $params, $types); |
|
|
@@ -287,8 +291,7 @@ class Connection extends \Doctrine\DBAL\Connection { |
|
|
|
* @throws \Doctrine\DBAL\Exception |
|
|
|
*/ |
|
|
|
public function executeStatement($sql, array $params = [], array $types = []): int { |
|
|
|
$sql = $this->replaceTablePrefix($sql); |
|
|
|
$sql = $this->adapter->fixupStatement($sql); |
|
|
|
$sql = $this->finishQuery($sql); |
|
|
|
$this->queriesExecuted++; |
|
|
|
$this->logQueryToFile($sql); |
|
|
|
return (int)parent::executeStatement($sql, $params, $types); |
|
|
@@ -515,6 +518,16 @@ class Connection extends \Doctrine\DBAL\Connection { |
|
|
|
return $schema->tablesExist([$table]); |
|
|
|
} |
|
|
|
|
|
|
|
protected function finishQuery(string $statement): string { |
|
|
|
$statement = $this->replaceTablePrefix($statement); |
|
|
|
$statement = $this->adapter->fixupStatement($statement); |
|
|
|
if ($this->logRequestId) { |
|
|
|
return $statement . " /* reqid: " . $this->requestId . " */"; |
|
|
|
} else { |
|
|
|
return $statement; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// internal use |
|
|
|
/** |
|
|
|
* @param string $statement |