From 79f4fcb3c44205aade71851bea7dc8425f42052b Mon Sep 17 00:00:00 2001 From: beberlei Date: Mon, 2 Nov 2009 15:08:51 +0000 Subject: [PATCH] [2.0] Fixed DDC-103 - Platform::getAlterTableSql() should return an array on all platforms, added doc-blocks on all methods and fixed some. --- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 7 ++++--- lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php | 14 +++++++++++++- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 2 +- lib/Doctrine/DBAL/Platforms/OraclePlatform.php | 12 ++++++++++++ lib/Doctrine/ORM/Tools/SchemaTool.php | 6 +++--- .../Tests/DBAL/Platforms/MsSqlPlatformTest.php | 5 +++-- .../Tests/DBAL/Platforms/MySqlPlatformTest.php | 5 +++-- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 53dda5570..52eea73ab 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -645,15 +645,16 @@ abstract class AbstractPlatform } /** - * Gets the sql for altering an existing table. - * (this method is implemented by the drivers) + * Gets the sql statements for altering an existing table. + * + * The method returns an array of sql statements, since some platforms need several statements. * * @param string $name name of the table that is intended to be changed. * @param array $changes associative array that contains the details of each type * * @param boolean $check indicates whether the function should just check if the DBMS driver * can perform the requested table alterations if the value is true or * actually perform them otherwise. - * @return string + * @return array */ public function getAlterTableSql($name, array $changes, $check = false) { diff --git a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php index 3795d20f5..43e1ea0ea 100644 --- a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php @@ -88,6 +88,18 @@ class MsSqlPlatform extends AbstractPlatform return $query; } + /** + * Gets the sql statements for altering an existing table. + * + * The method returns an array of sql statements, since some platforms need several statements. + * + * @param string $name name of the table that is intended to be changed. + * @param array $changes associative array that contains the details of each type * + * @param boolean $check indicates whether the function should just check if the DBMS driver + * can perform the requested table alterations if the value is true or + * actually perform them otherwise. + * @return array + */ public function getAlterTableSql($name, array $changes, $check = false) { foreach ($changes as $changeName => $change) { @@ -165,7 +177,7 @@ class MsSqlPlatform extends AbstractPlatform return false; } - return 'ALTER TABLE ' . $name . ' ' . $query; + return array('ALTER TABLE ' . $name . ' ' . $query); } /** diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 1895e7bd1..d67073747 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -655,7 +655,7 @@ class MySqlPlatform extends AbstractPlatform return false; } - return 'ALTER TABLE ' . $name . ' ' . $query; + return array('ALTER TABLE ' . $name . ' ' . $query); } /** diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index da2f85200..4c0c28197 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -392,6 +392,18 @@ END;'; return 'DROP USER ' . $database . ' CASCADE'; } + /** + * Gets the sql statements for altering an existing table. + * + * The method returns an array of sql statements, since some platforms need several statements. + * + * @param string $name name of the table that is intended to be changed. + * @param array $changes associative array that contains the details of each type * + * @param boolean $check indicates whether the function should just check if the DBMS driver + * can perform the requested table alterations if the value is true or + * actually perform them otherwise. + * @return array + */ public function getAlterTableSql($name, array $changes, $check = false) { if ( ! $name) { diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 9732b78e5..fe70657d0 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -656,7 +656,7 @@ class SchemaTool $joinColumn['type'] = Type::getType($joinColumn['type']); $changes['add'][$name] = $joinColumn; } - $sql[] = $this->_platform->getAlterTableSql($tableName, $changes); + $sql = array_merge($sql, $this->_platform->getAlterTableSql($tableName, $changes)); } // Update existent columns @@ -670,7 +670,7 @@ class SchemaTool ); } - $sql[] = $this->_platform->getAlterTableSql($tableName, $changes); + $sql = array_merge($sql, $this->_platform->getAlterTableSql($tableName, $changes)); } // Drop any remaining columns @@ -682,7 +682,7 @@ class SchemaTool $changes['remove'][$column['name']] = $column; } - $sql[] = $this->_platform->getAlterTableSql($tableName, $changes); + $sql = array_merge($sql, $this->_platform->getAlterTableSql($tableName, $changes)); } } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php index c42cafa13..442df8fd1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php @@ -50,10 +50,11 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase 'unsigned' => 1 ) )); - + + $sql = $this->_platform->getAlterTableSql('mytable', $changes); $this->assertEquals( 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL', - $this->_platform->getAlterTableSql('mytable', $changes) + $sql[0] ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php index 5ba808d4d..596136035 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -50,10 +50,11 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase 'unsigned' => 1 ) )); - + + $sql = $this->_platform->getAlterTableSql('mytable', $changes); $this->assertEquals( 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL', - $this->_platform->getAlterTableSql('mytable', $changes) + $sql[0] ); }