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

[DBAL-407] Implemented not null exception detection for sqlite

parent 5d2d88c0
......@@ -25,6 +25,7 @@ class DBALException extends \Exception
const ERROR_UNKNOWN_TABLE = 2;
const ERROR_TABLE_ALREADY_EXISTS = 3;
const ERROR_FOREIGN_KEY_CONSTRAINT = 4;
const ERROR_NOT_NULL = 5;
/**
* @param string $method
......
......@@ -124,6 +124,9 @@ class Driver implements \Doctrine\DBAL\Driver
if (strpos($exception->getMessage(), 'must be unique') !== false) {
return DBALException::ERROR_DUPLICATE_KEY;
}
if (strpos($exception->getMessage(), 'may not be NULL') !== false) {
return DBALException::ERROR_NOT_NULL;
}
case 'HY000':
if (strpos($exception->getMessage(), 'no such table:') !== false) {
return DBALException::ERROR_UNKNOWN_TABLE;
......
......@@ -9,7 +9,6 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
public function testDuplicateKeyException()
{
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$table = new \Doctrine\DBAL\Schema\Table("duplicatekey_table");
$table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id'));
......@@ -54,6 +53,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
$schema = new \Doctrine\DBAL\Schema\Schema();
$table = $schema->createTable("constraint_error_table");
$table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id'));
......@@ -75,6 +75,23 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->delete('constraint_error_table', array('id' => 1));
}
public function testNotNullException()
{
$schema = new \Doctrine\DBAL\Schema\Schema();
$table = $schema->createTable("notnull_table");
$table->addColumn('id', 'integer', array());
$table->addColumn('value', 'integer', array('notnull' => true));
$table->setPrimaryKey(array('id'));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) AS $sql) {
$this->_conn->executeQuery($sql);
}
$this->setExpectedException('\Doctrine\DBAL\DBALException', null, DBALException::ERROR_NOT_NULL);
$this->_conn->insert("notnull_table", array('id' => 1));
}
protected function onNotSuccessfulTest(\Exception $e)
{
var_dump($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