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
$insertQuery->execute($data);
return;
} catch (PDOException $e) {
$ecode = (string) $e->getCode();
switch ($ecode) {
case '23505': // PostgreSQL
break;
default:
Logger::error('Error while saving data: '.$e->getMessage());
throw $e;
$duplicateInsertErrorCodes = [
'pgsql' => '23505',
'sqlsrv' => '23000'
];
if (!array_key_exists($this->driver, $duplicateInsertErrorCodes) || $duplicateInsertErrorCodes[$this->driver] !== (string) $e->getCode()) {
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.
Finish editing this message first!
Please register or to comment