|
|
@@ -91,6 +91,9 @@ class Connection extends PrimaryReadReplicaConnection { |
|
|
|
/** @var array<string, int> */ |
|
|
|
protected $tableDirtyWrites = []; |
|
|
|
|
|
|
|
protected bool $logRequestId; |
|
|
|
protected string $requestId; |
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes a new instance of the Connection class. |
|
|
|
* |
|
|
@@ -119,6 +122,9 @@ class Connection extends PrimaryReadReplicaConnection { |
|
|
|
$this->clock = Server::get(ClockInterface::class); |
|
|
|
$this->logger = 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 = Server::get(IProfiler::class); |
|
|
|
if ($profiler->isEnabled()) { |
|
|
@@ -249,8 +255,7 @@ class Connection extends PrimaryReadReplicaConnection { |
|
|
|
$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 +312,7 @@ class Connection extends PrimaryReadReplicaConnection { |
|
|
|
$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 +332,7 @@ class Connection extends PrimaryReadReplicaConnection { |
|
|
|
* @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 +357,7 @@ class Connection extends PrimaryReadReplicaConnection { |
|
|
|
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 +589,16 @@ class Connection extends PrimaryReadReplicaConnection { |
|
|
|
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 |