diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 2e0582303f4b0..5fcff5a4e6efa 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -91,6 +91,8 @@ class Connection extends PrimaryReadReplicaConnection { /** @var array */ protected $tableDirtyWrites = []; + protected string $requestId; + /** * Initializes a new instance of the Connection class. * @@ -118,6 +120,7 @@ public function __construct( $this->systemConfig = \OC::$server->getSystemConfig(); $this->clock = Server::get(ClockInterface::class); $this->logger = Server::get(LoggerInterface::class); + $this->requestId = Server::get(IRequestId::class)->getId(); /** @var \OCP\Profiler\IProfiler */ $profiler = Server::get(IProfiler::class); @@ -249,8 +252,7 @@ public function prepare($sql, $limit = null, $offset = null): Statement { $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); } @@ -307,8 +309,7 @@ public function executeQuery(string $sql, array $params = [], $types = [], ?Quer $this->ensureConnectedToPrimary(); } - $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); @@ -328,8 +329,7 @@ private function getQueriedTables(string $sql): array { * @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); @@ -354,8 +354,7 @@ public function executeStatement($sql, array $params = [], array $types = []): i foreach ($tables as $table) { $this->tableDirtyWrites[$table] = $this->clock->now()->getTimestamp(); } - $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); @@ -587,6 +586,12 @@ public function tableExists($table) { return $schema->tablesExist([$table]); } + protected function finishQuery(string $statement): string { + $statement = $this->replaceTablePrefix($statement); + $statement = $this->adapter->fixupStatement($statement); + return $statement . " /* reqid: " . $this->requestId . " */"; + } + // internal use /** * @param string $statement