Skip to content
Snippets Groups Projects
Commit 5e247487 authored by Martin Krisell's avatar Martin Krisell Committed by Tim van Dijen
Browse files

Handle duplicate insertion also for SQL Server (#1134)

* Handle duplicate insertion also for SQL Server
* Improve 'update or insert' handling for different SQL drivers
parent 4ac846b9
No related branches found
No related tags found
No related merge requests found
...@@ -242,13 +242,14 @@ class SQL extends Store ...@@ -242,13 +242,14 @@ class SQL extends Store
$insertQuery->execute($data); $insertQuery->execute($data);
return; return;
} catch (PDOException $e) { } catch (PDOException $e) {
$ecode = (string) $e->getCode(); $duplicateInsertErrorCodes = [
switch ($ecode) { 'pgsql' => '23505',
case '23505': // PostgreSQL 'sqlsrv' => '23000'
break; ];
default:
Logger::error('Error while saving data: '.$e->getMessage()); if (!array_key_exists($this->driver, $duplicateInsertErrorCodes) || $duplicateInsertErrorCodes[$this->driver] !== (string) $e->getCode()) {
throw $e; Logger::error('Error while saving data: '.$e->getMessage());
throw $e;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment