Skip to content
Snippets Groups Projects
Unverified Commit a50bcdab authored by Vincent Petry's avatar Vincent Petry
Browse files

Prevent log_query to mess up regular execution flow


When the "log_query" debug config parameter is set, SQL queries are
logged. However, if an error occurs when converting the values to
string, it will abort the request.

This fix catches the error and continues instead.

Also added handler for DateTime value which is already known to cause
aborts here.

Signed-off-by: default avatarVincent Petry <vincent@nextcloud.com>
parent c1161e27
No related branches found
No related tags found
Loading
...@@ -193,25 +193,33 @@ class QueryBuilder implements IQueryBuilder { ...@@ -193,25 +193,33 @@ class QueryBuilder implements IQueryBuilder {
*/ */
public function execute() { public function execute() {
if ($this->systemConfig->getValue('log_query', false)) { if ($this->systemConfig->getValue('log_query', false)) {
$params = []; try {
foreach ($this->getParameters() as $placeholder => $value) { $params = [];
if (is_array($value)) { foreach ($this->getParameters() as $placeholder => $value) {
$params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; if ($value instanceof \DateTime) {
$params[] = $placeholder . ' => DateTime:\'' . $value->format('c') . '\'';
} elseif (is_array($value)) {
$params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')';
} else {
$params[] = $placeholder . ' => \'' . $value . '\'';
}
}
if (empty($params)) {
$this->logger->debug('DB QueryBuilder: \'{query}\'', [
'query' => $this->getSQL(),
'app' => 'core',
]);
} else { } else {
$params[] = $placeholder . ' => \'' . $value . '\''; $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [
'query' => $this->getSQL(),
'params' => implode(', ', $params),
'app' => 'core',
]);
} }
} } catch (\Error $e) {
if (empty($params)) { // likely an error during conversion of $value to string
$this->logger->debug('DB QueryBuilder: \'{query}\'', [ $this->logger->debug('DB QueryBuilder: error trying to log SQL query');
'query' => $this->getSQL(), $this->logger->logException($e);
'app' => 'core',
]);
} else {
$this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [
'query' => $this->getSQL(),
'params' => implode(', ', $params),
'app' => 'core',
]);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment