Commit 9e01f9a4 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #417 from kimhemsoe/drizzle_exceptions

Implement ExceptionConverterDriver for drizzle_pdo_mysql
parents 2a3d6cbf 2b002e50
...@@ -19,12 +19,15 @@ ...@@ -19,12 +19,15 @@
namespace Doctrine\DBAL\Driver\DrizzlePDOMySql; namespace Doctrine\DBAL\Driver\DrizzlePDOMySql;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\DBALException;
/** /**
* Drizzle driver using PDO MySql. * Drizzle driver using PDO MySql.
* *
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com> * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/ */
class Driver implements \Doctrine\DBAL\Driver class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -105,6 +108,38 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -105,6 +108,38 @@ class Driver implements \Doctrine\DBAL\Driver
*/ */
public function convertExceptionCode(\Exception $exception) public function convertExceptionCode(\Exception $exception)
{ {
switch ($exception->getCode()) {
case "42000":
return DBALException::ERROR_SYNTAX;
case "42S02":
return DBALException::ERROR_UNKNOWN_TABLE;
case "42S01":
return DBALException::ERROR_TABLE_ALREADY_EXISTS;
case "42S22":
return DBALException::ERROR_BAD_FIELD_NAME;
case "23000":
if (strpos($exception->getMessage(), 'Duplicate entry') !== false) {
return DBALException::ERROR_DUPLICATE_KEY;
}
if (strpos($exception->getMessage(), 'Cannot delete or update a parent row: a foreign key constraint fails') !== false) {
return DBALException::ERROR_FOREIGN_KEY_CONSTRAINT;
}
if (strpos($exception->getMessage(), ' cannot be null')) {
return DBALException::ERROR_NOT_NULL;
}
if (strpos($exception->getMessage(), 'in field list is ambiguous') !== false) {
return DBALException::ERROR_NON_UNIQUE_FIELD_NAME;
}
break;
}
return 0; return 0;
} }
} }
...@@ -217,6 +217,10 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -217,6 +217,10 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->markTestSkipped("Only skipped if platform is not sqlite"); $this->markTestSkipped("Only skipped if platform is not sqlite");
} }
if ($this->_conn->getDatabasePlatform()->getName() == 'drizzle') {
$this->markTestSkipped("Drizzle does not always support authentication");
}
if ($this->_conn->getDatabasePlatform()->getName() == 'postgresql' && isset($params['password'])) { if ($this->_conn->getDatabasePlatform()->getName() == 'postgresql' && isset($params['password'])) {
$this->markTestSkipped("Does not work on Travis"); $this->markTestSkipped("Does not work on Travis");
} }
......
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