From 5156391b5686a2b3bba628bb0bc1fece63409a44 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 22 Dec 2013 11:42:32 +0100 Subject: [PATCH] [DBAL-585] Quote Old column Names when generating ALTER TABLE SQL. --- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 2 +- .../DBAL/Platforms/DrizzlePlatform.php | 2 +- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 2 +- .../DBAL/Platforms/PostgreSqlPlatform.php | 2 +- lib/Doctrine/DBAL/Schema/ColumnDiff.php | 8 ++++++++ .../Platforms/AbstractPlatformTestCase.php | 20 +++++++++++++++++++ 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index acb06e460e0..241c9198d18 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -477,7 +477,7 @@ public function getAlterTableSQL(TableDiff $diff) /* @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */ $column = $columnDiff->column; - $queryParts[] = 'ALTER ' . ($columnDiff->oldColumnName) . ' ' + $queryParts[] = 'ALTER ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); } diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index f7450b8036b..dfa4ea8b083 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -426,7 +426,7 @@ public function getAlterTableSQL(TableDiff $diff) $column = $columnDiff->column; $columnArray = $column->toArray(); $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'CHANGE ' . ($columnDiff->oldColumnName) . ' ' + $queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 72dcc8018ec..7f5720d965a 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -557,7 +557,7 @@ public function getAlterTableSQL(TableDiff $diff) $column = $columnDiff->column; $columnArray = $column->toArray(); $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'CHANGE ' . ($columnDiff->oldColumnName) . ' ' + $queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 10e1e7fdee1..58ded8f3458 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -442,7 +442,7 @@ public function getAlterTableSQL(TableDiff $diff) continue; } - $oldColumnName = $columnDiff->oldColumnName; + $oldColumnName = $columnDiff->getOldColumnName()->getQuotedName($this); $column = $columnDiff->column; if ($columnDiff->hasChanged('type') || $columnDiff->hasChanged('precision') || $columnDiff->hasChanged('scale')) { diff --git a/lib/Doctrine/DBAL/Schema/ColumnDiff.php b/lib/Doctrine/DBAL/Schema/ColumnDiff.php index 18068b0a6fe..150f44e3fe8 100644 --- a/lib/Doctrine/DBAL/Schema/ColumnDiff.php +++ b/lib/Doctrine/DBAL/Schema/ColumnDiff.php @@ -71,4 +71,12 @@ public function hasChanged($propertyName) { return in_array($propertyName, $this->changedProperties); } + + /** + * @return \Doctrine\DBAL\Schema\Identifier + */ + public function getOldColumnName() + { + return new Identifier($this->oldColumnName); + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index f3be680f888..1e18dbd5a0c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -510,4 +510,24 @@ public function testSchemaNeedsCreation() { $this->_platform->schemaNeedsCreation('schema'); } + + /** + * @group DBAL-585 + */ + public function testAlterTableChangeQuotedColumn() + { + $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); + $tableDiff->fromTable = new \Doctrine\DBAL\Schema\Table('mytable'); + $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( + 'select', new \Doctrine\DBAL\Schema\Column( + 'select', \Doctrine\DBAL\Types\Type::getType('string') + ), + array('type') + ); + + $this->assertContains( + $this->_platform->quoteIdentifier('select'), + implode(';', $this->_platform->getAlterTableSQL($tableDiff)) + ); + } }