Commit d0e0c2f3 authored by Steve Müller's avatar Steve Müller

Merge pull request #754 from SenseException/fixed-string-changedcolumns

[DBAL-1090] Changing string to fixed string is not recognized in PostgreSQL Platform
parents 19f5a139 4a842e65
......@@ -500,7 +500,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$oldColumnName = $columnDiff->getOldColumnName()->getQuotedName($this);
$column = $columnDiff->column;
if ($columnDiff->hasChanged('type') || $columnDiff->hasChanged('precision') || $columnDiff->hasChanged('scale')) {
if ($columnDiff->hasChanged('type') || $columnDiff->hasChanged('precision') || $columnDiff->hasChanged('scale') || $columnDiff->hasChanged('fixed')) {
$type = $column->getType();
// here was a server version check before, but DBAL API does not support this anymore.
......
......@@ -657,4 +657,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
{
return 'INDEX `select` (foo)';
}
/**
* {@inheritdoc}
*/
protected function getAlterStringToFixedStringSQL()
{
return array(
'ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL',
);
}
}
......@@ -1128,4 +1128,35 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
* @return array
*/
abstract protected function getQuotesTableIdentifiersInAlterTableSQL();
/**
* @group DBAL-1090
*/
public function testAlterStringToFixedString()
{
$table = new Table('mytable');
$table->addColumn('name', 'string', array('length' => 2));
$tableDiff = new TableDiff('mytable');
$tableDiff->fromTable = $table;
$tableDiff->changedColumns['name'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'name', new \Doctrine\DBAL\Schema\Column(
'name', \Doctrine\DBAL\Types\Type::getType('string'), array('fixed' => true, 'length' => 2)
),
array('fixed')
);
$sql = $this->_platform->getAlterTableSQL($tableDiff);
$expectedSql = $this->getAlterStringToFixedStringSQL();
$this->assertEquals($expectedSql, $sql);
}
/**
* @return array
*/
abstract protected function getAlterStringToFixedStringSQL();
}
......@@ -755,4 +755,14 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
{
return 'INDEX "select" (foo)';
}
/**
* {@inheritdoc}
*/
protected function getAlterStringToFixedStringSQL()
{
return array(
'ALTER TABLE mytable ALTER name TYPE CHAR(2)',
);
}
}
......@@ -1202,4 +1202,14 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
{
return 'INDEX [select] (foo)';
}
/**
* {@inheritdoc}
*/
protected function getAlterStringToFixedStringSQL()
{
return array(
'ALTER TABLE mytable ALTER COLUMN name NCHAR(2) NOT NULL',
);
}
}
......@@ -639,4 +639,15 @@ class DB2PlatformTest extends AbstractPlatformTestCase
{
return false;
}
/**
* {@inheritdoc}
*/
protected function getAlterStringToFixedStringSQL()
{
return array(
'ALTER TABLE mytable ALTER COLUMN name SET DATA TYPE CHAR(2)',
'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE mytable\')',
);
}
}
......@@ -658,4 +658,14 @@ EOD;
{
return 'INDEX "select" (foo)';
}
/**
* {@inheritdoc}
*/
protected function getAlterStringToFixedStringSQL()
{
return array(
'ALTER TABLE mytable MODIFY (name CHAR(2) DEFAULT NULL)',
);
}
}
......@@ -951,4 +951,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
{
return false;
}
/**
* {@inheritdoc}
*/
protected function getAlterStringToFixedStringSQL()
{
return array(
'ALTER TABLE mytable ALTER name CHAR(2) NOT NULL',
);
}
}
......@@ -624,4 +624,18 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{
return 'INDEX "select" (foo)';
}
/**
* {@inheritdoc}
*/
protected function getAlterStringToFixedStringSQL()
{
return array(
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT name FROM mytable',
'DROP TABLE mytable',
'CREATE TABLE mytable (name CHAR(2) NOT NULL)',
'INSERT INTO mytable (name) SELECT name FROM __temp__mytable',
'DROP TABLE __temp__mytable',
);
}
}
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