diff options
author | Vincent Petry <vincent@nextcloud.com> | 2020-12-02 14:10:35 +0100 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2020-12-02 14:10:35 +0100 |
commit | a50bcdabccf9334160092dc88bbd4a6d615fab82 (patch) | |
tree | 4ca833e589a82047db88f8703b4becdb9d66d904 /lib/private/DB | |
parent | c1161e27b47d1f5cd7b6f3ec0c229738bbc5c271 (diff) | |
download | nextcloud-server-a50bcdabccf9334160092dc88bbd4a6d615fab82.tar.gz nextcloud-server-a50bcdabccf9334160092dc88bbd4a6d615fab82.zip |
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: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'lib/private/DB')
-rw-r--r-- | lib/private/DB/QueryBuilder/QueryBuilder.php | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index c2686f7b4a0..ebd715df1c1 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -193,25 +193,33 @@ class QueryBuilder implements IQueryBuilder { */ public function execute() { if ($this->systemConfig->getValue('log_query', false)) { - $params = []; - foreach ($this->getParameters() as $placeholder => $value) { - if (is_array($value)) { - $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; + try { + $params = []; + foreach ($this->getParameters() as $placeholder => $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 { - $params[] = $placeholder . ' => \'' . $value . '\''; + $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ + 'query' => $this->getSQL(), + 'params' => implode(', ', $params), + 'app' => 'core', + ]); } - } - if (empty($params)) { - $this->logger->debug('DB QueryBuilder: \'{query}\'', [ - 'query' => $this->getSQL(), - 'app' => 'core', - ]); - } else { - $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ - 'query' => $this->getSQL(), - 'params' => implode(', ', $params), - 'app' => 'core', - ]); + } catch (\Error $e) { + // likely an error during conversion of $value to string + $this->logger->debug('DB QueryBuilder: error trying to log SQL query'); + $this->logger->logException($e); } } |