Commit 3e580007 authored by dazz's avatar dazz Committed by Benjamin Eberlei

[DBAL-407] Added syntax error exception detection for sqlite driver

parent 2dd76c4a
......@@ -29,6 +29,7 @@ class DBALException extends \Exception
const ERROR_BAD_FIELD_NAME = 6;
const ERROR_NON_UNIQUE_FIELD_NAME = 7;
const ERROR_NOT_UNIQUE = 8;
const ERROR_SYNTAX = 9;
/**
* @param string $method
......
......@@ -148,6 +148,10 @@ class Driver implements \Doctrine\DBAL\Driver
if (strpos($exception->getMessage(), 'ambiguous column name') !== false) {
return DBALException::ERROR_NON_UNIQUE_FIELD_NAME;
}
if (strpos($exception->getMessage(), 'syntax error') !== false) {
return DBALException::ERROR_SYNTAX;
}
}
return 0;
......
......@@ -141,6 +141,21 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->insert("unique_field_table", array('id' => 5));
}
public function testSyntaxErrorException()
{
$table = new \Doctrine\DBAL\Schema\Table("syntax_error_table");
$table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) {
$this->_conn->executeQuery($sql);
}
$sql = 'SELECT id FRO syntax_error_table';
$this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_SYNTAX);
$this->_conn->executeQuery($sql);
}
protected function onNotSuccessfulTest(\Exception $e)
{
parent::onNotSuccessfulTest($e);
......
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