Don't try to update on NotNullConstraintViolationException, only on unique or foreign key

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-11-09 17:33:32 +01:00
parent a66591ee79
commit dee42027ed
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 3 additions and 0 deletions

View File

@ -39,6 +39,7 @@ use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception\ConstraintViolationException; use Doctrine\DBAL\Exception\ConstraintViolationException;
use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use OC\DB\QueryBuilder\QueryBuilder; use OC\DB\QueryBuilder\QueryBuilder;
@ -297,6 +298,8 @@ class Connection extends ReconnectWrapper implements IDBConnection {
}, array_merge($keys, $values)) }, array_merge($keys, $values))
); );
return $insertQb->execute(); return $insertQb->execute();
} catch (NotNullConstraintViolationException $e) {
throw $e;
} catch (ConstraintViolationException $e) { } catch (ConstraintViolationException $e) {
// value already exists, try update // value already exists, try update
$updateQb = $this->getQueryBuilder(); $updateQb = $this->getQueryBuilder();