Commit d47e926e authored by dazz's avatar dazz Committed by Benjamin Eberlei

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

parent 6401e760
...@@ -27,6 +27,7 @@ class DBALException extends \Exception ...@@ -27,6 +27,7 @@ class DBALException extends \Exception
const ERROR_FOREIGN_KEY_CONSTRAINT = 4; const ERROR_FOREIGN_KEY_CONSTRAINT = 4;
const ERROR_NOT_NULL = 5; const ERROR_NOT_NULL = 5;
const ERROR_BAD_FIELD_NAME = 6; const ERROR_BAD_FIELD_NAME = 6;
const ERROR_NON_UNIQUE_FIELD_NAME = 7;
/** /**
* @param string $method * @param string $method
......
...@@ -139,6 +139,10 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -139,6 +139,10 @@ class Driver implements \Doctrine\DBAL\Driver
if (strpos($exception->getMessage(), 'has no column named') !== false) { if (strpos($exception->getMessage(), 'has no column named') !== false) {
return DBALException::ERROR_BAD_FIELD_NAME; return DBALException::ERROR_BAD_FIELD_NAME;
} }
if (strpos($exception->getMessage(), 'ambiguous column name') !== false) {
return DBALException::ERROR_NON_UNIQUE_FIELD_NAME;
}
} }
return 0; return 0;
......
...@@ -94,15 +94,36 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -94,15 +94,36 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{ {
$schema = new \Doctrine\DBAL\Schema\Schema(); $schema = new \Doctrine\DBAL\Schema\Schema();
$table = $schema->createTable("non_unique_table"); $table = $schema->createTable("bad_fieldname_table");
$table->addColumn('id', 'integer', array('unique' => true)); $table->addColumn('id', 'integer', array());
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) {
$this->_conn->executeQuery($sql); $this->_conn->executeQuery($sql);
} }
$this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_BAD_FIELD_NAME); $this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_BAD_FIELD_NAME);
$this->_conn->insert("non_unique_table", array('name' => 5)); $this->_conn->insert("bad_fieldname_table", array('name' => 5));
}
public function testNonUniqueFieldNameException()
{
$schema = new \Doctrine\DBAL\Schema\Schema();
$table = $schema->createTable("ambiguous_list_table");
$table->addColumn('id', 'integer');
$table2 = $schema->createTable("ambiguous_list_table_2");
$table2->addColumn('id', 'integer');
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) {
$this->_conn->executeQuery($sql);
}
$sql = 'SELECT id FROM ambiguous_list_table, ambiguous_list_table_2';
$this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_NON_UNIQUE_FIELD_NAME);
$this->_conn->executeQuery($sql);
} }
protected function onNotSuccessfulTest(\Exception $e) protected function onNotSuccessfulTest(\Exception $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