Commit 6b2b0a49 authored by dazz's avatar dazz Committed by Benjamin Eberlei

[DBAL-407] Implement error detection on duplicate key for mysql and sqlite

parent e85e7130
...@@ -91,7 +91,7 @@ class DBALException extends \Exception ...@@ -91,7 +91,7 @@ class DBALException extends \Exception
} }
$msg .= ":\n\n".$driverEx->getMessage(); $msg .= ":\n\n".$driverEx->getMessage();
return new self($msg, 0, $driverEx); return new self($msg, $driver->convertExceptionCode($driverEx), $driverEx);
} }
/** /**
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
namespace Doctrine\DBAL\Driver\PDOMySql; namespace Doctrine\DBAL\Driver\PDOMySql;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
/** /**
* PDO MySql driver. * PDO MySql driver.
...@@ -114,6 +115,11 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -114,6 +115,11 @@ class Driver implements \Doctrine\DBAL\Driver
*/ */
public function convertExceptionCode(\Exception $exception) public function convertExceptionCode(\Exception $exception)
{ {
switch ($exception->getCode()) {
case 23000:
return DBALException::ERROR_DUPLICATE_KEY;
}
return 0; return 0;
} }
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
namespace Doctrine\DBAL\Driver\PDOSqlite; namespace Doctrine\DBAL\Driver\PDOSqlite;
use Doctrine\DBAL\DBALException;
/** /**
* The PDO Sqlite driver. * The PDO Sqlite driver.
...@@ -118,6 +119,11 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -118,6 +119,11 @@ class Driver implements \Doctrine\DBAL\Driver
*/ */
public function convertExceptionCode(\Exception $exception) public function convertExceptionCode(\Exception $exception)
{ {
switch ($exception->getCode()) {
case 23000:
return DBALException::ERROR_DUPLICATE_KEY;
}
return 0; return 0;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment