aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-05-09 14:29:03 +0200
committerGitHub <noreply@github.com>2023-05-09 14:29:03 +0200
commit9260ef5c29e026a1f547db59276c1635dcc1511e (patch)
tree5809e6c250f8623674e53764c097d683a2a82ec3 /lib
parent018b701d33603a96312df4895a138f38a4b675b7 (diff)
parent7f3af46690329f70162b6513eb6c68d63e27a0d3 (diff)
downloadnextcloud-server-9260ef5c29e026a1f547db59276c1635dcc1511e.tar.gz
nextcloud-server-9260ef5c29e026a1f547db59276c1635dcc1511e.zip
Merge pull request #37549 from nextcloud/backport/37520/stable26
[stable26] fix DBAL exception handling in setValues
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/Connection.php18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index ceaffbcfa9a..85c6a72dfdb 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -40,8 +40,6 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
-use Doctrine\DBAL\Exception\ConstraintViolationException;
-use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
@@ -381,10 +379,10 @@ class Connection extends \Doctrine\DBAL\Connection {
* @param array $values (column name => value)
* @param array $updatePreconditionValues ensure values match preconditions (column name => value)
* @return int number of new rows
- * @throws \Doctrine\DBAL\Exception
+ * @throws \OCP\DB\Exception
* @throws PreConditionNotMetException
*/
- public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) {
+ public function setValues(string $table, array $keys, array $values, array $updatePreconditionValues = []): int {
try {
$insertQb = $this->getQueryBuilder();
$insertQb->insert($table)
@@ -394,9 +392,15 @@ class Connection extends \Doctrine\DBAL\Connection {
}, array_merge($keys, $values))
);
return $insertQb->executeStatement();
- } catch (NotNullConstraintViolationException $e) {
- throw $e;
- } catch (ConstraintViolationException $e) {
+ } catch (\OCP\DB\Exception $e) {
+ if (!in_array($e->getReason(), [
+ \OCP\DB\Exception::REASON_CONSTRAINT_VIOLATION,
+ \OCP\DB\Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION,
+ ])
+ ) {
+ throw $e;
+ }
+
// value already exists, try update
$updateQb = $this->getQueryBuilder();
$updateQb->update($table);