Commit 1a25de1a authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #687 from deeky666/DBAL-1001

[DBAL-1001] Fix NULL / NOT NULL clause for column alterations in Oracle
parents d5bb0441 5565342b
...@@ -733,7 +733,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -733,7 +733,7 @@ LEFT JOIN user_cons_columns r_cols
$columnInfo = $column->toArray(); $columnInfo = $column->toArray();
if ( ! $columnDiff->hasChanged('notnull')) { if ( ! $columnDiff->hasChanged('notnull')) {
$columnInfo['notnull'] = false; unset($columnInfo['notnull']);
} }
$fields[] = $column->getQuotedName($this) . $this->getColumnDeclarationSQL('', $columnInfo); $fields[] = $column->getQuotedName($this) . $this->getColumnDeclarationSQL('', $columnInfo);
...@@ -799,7 +799,11 @@ LEFT JOIN user_cons_columns r_cols ...@@ -799,7 +799,11 @@ LEFT JOIN user_cons_columns r_cols
} else { } else {
$default = $this->getDefaultValueDeclarationSQL($field); $default = $this->getDefaultValueDeclarationSQL($field);
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; $notnull = '';
if (isset($field['notnull'])) {
$notnull = $field['notnull'] ? ' NOT NULL' : ' NULL';
}
$unique = (isset($field['unique']) && $field['unique']) ? $unique = (isset($field['unique']) && $field['unique']) ?
' ' . $this->getUniqueFieldDeclarationSQL() : ''; ' ' . $this->getUniqueFieldDeclarationSQL() : '';
......
...@@ -61,6 +61,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -61,6 +61,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
/** /**
* @group DBAL-472 * @group DBAL-472
* @group DBAL-1001
*/ */
public function testAlterTableColumnNotNull() public function testAlterTableColumnNotNull()
{ {
...@@ -70,6 +71,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -70,6 +71,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$table->addColumn('id', 'integer'); $table->addColumn('id', 'integer');
$table->addColumn('foo', 'integer'); $table->addColumn('foo', 'integer');
$table->addColumn('bar', 'string');
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
$this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateTable($table);
...@@ -78,9 +80,11 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -78,9 +80,11 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertTrue($columns['id']->getNotnull()); $this->assertTrue($columns['id']->getNotnull());
$this->assertTrue($columns['foo']->getNotnull()); $this->assertTrue($columns['foo']->getNotnull());
$this->assertTrue($columns['bar']->getNotnull());
$diffTable = clone $table; $diffTable = clone $table;
$diffTable->changeColumn('foo', array('notnull' => false)); $diffTable->changeColumn('foo', array('notnull' => false));
$diffTable->changeColumn('bar', array('length' => 1024));
$this->_sm->alterTable($comparator->diffTable($table, $diffTable)); $this->_sm->alterTable($comparator->diffTable($table, $diffTable));
...@@ -88,6 +92,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -88,6 +92,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertTrue($columns['id']->getNotnull()); $this->assertTrue($columns['id']->getNotnull());
$this->assertFalse($columns['foo']->getNotnull()); $this->assertFalse($columns['foo']->getNotnull());
$this->assertTrue($columns['bar']->getNotnull());
} }
public function testListDatabases() public function testListDatabases()
......
...@@ -310,6 +310,10 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -310,6 +310,10 @@ class OraclePlatformTest extends AbstractPlatformTestCase
); );
} }
/**
* @group DBAL-472
* @group DBAL-1001
*/
public function testAlterTableNotNULL() public function testAlterTableNotNULL()
{ {
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
...@@ -333,7 +337,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -333,7 +337,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
); );
$expectedSql = array( $expectedSql = array(
"ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla' NULL, baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL NULL)", "ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL NULL)",
); );
$this->assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); $this->assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff));
} }
......
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