4040use Doctrine \DBAL \Configuration ;
4141use Doctrine \DBAL \Driver ;
4242use Doctrine \DBAL \Exception ;
43- use Doctrine \DBAL \Exception \ConstraintViolationException ;
44- use Doctrine \DBAL \Exception \NotNullConstraintViolationException ;
4543use Doctrine \DBAL \Platforms \MySQLPlatform ;
4644use Doctrine \DBAL \Platforms \OraclePlatform ;
4745use Doctrine \DBAL \Platforms \PostgreSQL94Platform ;
@@ -381,10 +379,10 @@ private function getType($value) {
381379 * @param array $values (column name => value)
382380 * @param array $updatePreconditionValues ensure values match preconditions (column name => value)
383381 * @return int number of new rows
384- * @throws \Doctrine\DBAL \Exception
382+ * @throws \OCP\DB \Exception
385383 * @throws PreConditionNotMetException
386384 */
387- public function setValues ($ table , array $ keys , array $ values , array $ updatePreconditionValues = []) {
385+ public function setValues (string $ table , array $ keys , array $ values , array $ updatePreconditionValues = []): int {
388386 try {
389387 $ insertQb = $ this ->getQueryBuilder ();
390388 $ insertQb ->insert ($ table )
@@ -394,9 +392,15 @@ public function setValues($table, array $keys, array $values, array $updatePreco
394392 }, array_merge ($ keys , $ values ))
395393 );
396394 return $ insertQb ->executeStatement ();
397- } catch (NotNullConstraintViolationException $ e ) {
398- throw $ e ;
399- } catch (ConstraintViolationException $ e ) {
395+ } catch (\OCP \DB \Exception $ e ) {
396+ if (!in_array ($ e ->getReason (), [
397+ \OCP \DB \Exception::REASON_CONSTRAINT_VIOLATION ,
398+ \OCP \DB \Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION ,
399+ ])
400+ ) {
401+ throw $ e ;
402+ }
403+
400404 // value already exists, try update
401405 $ updateQb = $ this ->getQueryBuilder ();
402406 $ updateQb ->update ($ table );
0 commit comments