Commit 94089fd9 authored by dazz's avatar dazz Committed by Benjamin Eberlei

[DBAL-407] Implement error detection on unknown table for mysql and sqlite

parent 6b2b0a49
...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL; ...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL;
class DBALException extends \Exception class DBALException extends \Exception
{ {
const ERROR_DUPLICATE_KEY = 1; const ERROR_DUPLICATE_KEY = 1;
const ERROR_UNKNOWN_TABLE = 2;
/** /**
* @param string $method * @param string $method
......
...@@ -118,6 +118,8 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -118,6 +118,8 @@ class Driver implements \Doctrine\DBAL\Driver
switch ($exception->getCode()) { switch ($exception->getCode()) {
case 23000: case 23000:
return DBALException::ERROR_DUPLICATE_KEY; return DBALException::ERROR_DUPLICATE_KEY;
case '42S02':
return DBALException::ERROR_UNKNOWN_TABLE;
} }
return 0; return 0;
......
...@@ -122,6 +122,10 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -122,6 +122,10 @@ class Driver implements \Doctrine\DBAL\Driver
switch ($exception->getCode()) { switch ($exception->getCode()) {
case 23000: case 23000:
return DBALException::ERROR_DUPLICATE_KEY; return DBALException::ERROR_DUPLICATE_KEY;
case 'HY000':
if (strpos($exception->getMessage(), 'no such table:') !== false) {
return DBALException::ERROR_UNKNOWN_TABLE;
}
} }
return 0; return 0;
......
...@@ -23,5 +23,13 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -23,5 +23,13 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_DUPLICATE_KEY); $this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_DUPLICATE_KEY);
$this->_conn->insert("duplicatekey_table", array('id' => 1)); $this->_conn->insert("duplicatekey_table", array('id' => 1));
} }
public function testUnknownTableException()
{
$sql = "SELECT * FROM unknown_table";
$this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_UNKNOWN_TABLE);
$this->_conn->executeQuery($sql);
}
} }
\ No newline at end of file
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