Commit 6401e760 authored by dazz's avatar dazz Committed by Benjamin Eberlei

[DBAL-407] Implement and detect bad field name exception for sqlite

parent 68f1045d
......@@ -26,6 +26,7 @@ class DBALException extends \Exception
const ERROR_TABLE_ALREADY_EXISTS = 3;
const ERROR_FOREIGN_KEY_CONSTRAINT = 4;
const ERROR_NOT_NULL = 5;
const ERROR_BAD_FIELD_NAME = 6;
/**
* @param string $method
......
......@@ -135,6 +135,10 @@ class Driver implements \Doctrine\DBAL\Driver
if (strpos($exception->getMessage(), 'already exists') !== false) {
return DBALException::ERROR_TABLE_ALREADY_EXISTS;
}
if (strpos($exception->getMessage(), 'has no column named') !== false) {
return DBALException::ERROR_BAD_FIELD_NAME;
}
}
return 0;
......
......@@ -29,7 +29,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->executeQuery($sql);
}
public function testTableAlreadyExists()
public function testTableAlreadyExistsException()
{
$table = new \Doctrine\DBAL\Schema\Table("alreadyexist_table");
$table->addColumn('id', 'integer', array());
......@@ -90,6 +90,21 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->insert("notnull_table", array('id' => 1));
}
public function testBadFieldNameException()
{
$schema = new \Doctrine\DBAL\Schema\Schema();
$table = $schema->createTable("non_unique_table");
$table->addColumn('id', 'integer', array('unique' => true));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) {
$this->_conn->executeQuery($sql);
}
$this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_BAD_FIELD_NAME);
$this->_conn->insert("non_unique_table", array('name' => 5));
}
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