diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 916e857be6a..c3015b558ab 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -510,7 +510,7 @@ public function getAlterTableSQL(TableDiff $diff) } if ($columnDiff->hasChanged('length')) { - $query = 'ALTER ' . $column->getName() . ' TYPE ' . $column->getType()->getSqlDeclaration($column->toArray(), $this); + $query = 'ALTER ' . $oldColumnName . ' TYPE ' . $column->getType()->getSqlDeclaration($column->toArray(), $this); $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query; } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index a03efb60766..786c864eb86 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -580,4 +580,20 @@ protected function getQuotedAlterTableRenameColumnSQL() "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'" ); } + + /** + * {@inheritdoc} + */ + protected function getQuotedAlterTableChangeColumnLengthSQL() + { + return array( + "ALTER TABLE mytable " . + "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " . + "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " . + "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " . + "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " . + "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " . + "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'" + ); + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 22f953d0d1a..57b115b7471 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -717,6 +717,48 @@ public function testQuotesAlterTableRenameColumn() */ abstract protected function getQuotedAlterTableRenameColumnSQL(); + /** + * @group DBAL-835 + */ + public function testQuotesAlterTableChangeColumnLength() + { + $fromTable = new Table('mytable'); + + $fromTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 10)); + $fromTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 10)); + $fromTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 10)); + + $fromTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 10)); + $fromTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 10)); + $fromTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 10)); + + $toTable = new Table('mytable'); + + $toTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 255)); + $toTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 255)); + $toTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 255)); + + $toTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 255)); + $toTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 255)); + $toTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 255)); + + $comparator = new Comparator(); + + $this->assertEquals( + $this->getQuotedAlterTableChangeColumnLengthSQL(), + $this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) + ); + } + + /** + * Returns SQL statements for {@link testQuotesAlterTableChangeColumnLength}. + * + * @return array + * + * @group DBAL-835 + */ + abstract protected function getQuotedAlterTableChangeColumnLengthSQL(); + /** * @group DBAL-807 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 800a72115f1..f8d2413bff5 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -634,6 +634,21 @@ protected function getQuotedAlterTableRenameColumnSQL() ); } + /** + * {@inheritdoc} + */ + protected function getQuotedAlterTableChangeColumnLengthSQL() + { + return array( + 'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)', + 'ALTER TABLE mytable ALTER unquoted2 TYPE VARCHAR(255)', + 'ALTER TABLE mytable ALTER unquoted3 TYPE VARCHAR(255)', + 'ALTER TABLE mytable ALTER "create" TYPE VARCHAR(255)', + 'ALTER TABLE mytable ALTER "table" TYPE VARCHAR(255)', + 'ALTER TABLE mytable ALTER "select" TYPE VARCHAR(255)', + ); + } + /** * @group DBAL-807 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index e8838bdef78..bfb3ba30f41 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -904,6 +904,14 @@ protected function getQuotedAlterTableRenameColumnSQL() ); } + /** + * {@inheritdoc} + */ + protected function getQuotedAlterTableChangeColumnLengthSQL() + { + $this->markTestIncomplete('Not implemented yet'); + } + /** * @group DBAL-807 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index 4327e2778e9..58669e371c4 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -435,6 +435,14 @@ protected function getQuotedAlterTableRenameColumnSQL() ); } + /** + * {@inheritdoc} + */ + protected function getQuotedAlterTableChangeColumnLengthSQL() + { + $this->markTestIncomplete('Not implemented yet'); + } + /** * @group DBAL-807 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index f848d9368b4..ccb29ce97ef 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -456,6 +456,14 @@ protected function getQuotedAlterTableRenameColumnSQL() ); } + /** + * {@inheritdoc} + */ + protected function getQuotedAlterTableChangeColumnLengthSQL() + { + $this->markTestIncomplete('Not implemented yet'); + } + /** * @group DBAL-807 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index b3ed13aa742..44ad422bbd4 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -846,6 +846,14 @@ protected function getQuotedAlterTableRenameColumnSQL() ); } + /** + * {@inheritdoc} + */ + protected function getQuotedAlterTableChangeColumnLengthSQL() + { + $this->markTestIncomplete('Not implemented yet'); + } + /** * @group DBAL-807 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index d6c6c20a850..224cd0760e8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -495,6 +495,20 @@ protected function getQuotedAlterTableRenameColumnSQL() 'INSERT INTO mytable (unquoted, "where", "foo", reserved_keyword, "from", "bar", quoted, "and", "baz") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM __temp__mytable', 'DROP TABLE __temp__mytable', ); + } + + /** + * {@inheritdoc} + */ + protected function getQuotedAlterTableChangeColumnLengthSQL() + { + return array( + 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable', + 'DROP TABLE mytable', + 'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL, unquoted2 VARCHAR(255) NOT NULL, unquoted3 VARCHAR(255) NOT NULL, "create" VARCHAR(255) NOT NULL, "table" VARCHAR(255) NOT NULL, "select" VARCHAR(255) NOT NULL)', + 'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable', + 'DROP TABLE __temp__mytable', + ); } /**