Commit 79f4fcb3 authored by beberlei's avatar beberlei

[2.0] Fixed DDC-103 - Platform::getAlterTableSql() should return an array on...

[2.0] Fixed DDC-103 - Platform::getAlterTableSql() should return an array on all platforms, added doc-blocks on all methods and fixed some.
parent 140f597e
...@@ -645,15 +645,16 @@ abstract class AbstractPlatform ...@@ -645,15 +645,16 @@ abstract class AbstractPlatform
} }
/** /**
* Gets the sql for altering an existing table. * Gets the sql statements for altering an existing table.
* (this method is implemented by the drivers) *
* 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 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 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 * @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 * can perform the requested table alterations if the value is true or
* actually perform them otherwise. * actually perform them otherwise.
* @return string * @return array
*/ */
public function getAlterTableSql($name, array $changes, $check = false) public function getAlterTableSql($name, array $changes, $check = false)
{ {
......
...@@ -88,6 +88,18 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -88,6 +88,18 @@ class MsSqlPlatform extends AbstractPlatform
return $query; 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) public function getAlterTableSql($name, array $changes, $check = false)
{ {
foreach ($changes as $changeName => $change) { foreach ($changes as $changeName => $change) {
...@@ -165,7 +177,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -165,7 +177,7 @@ class MsSqlPlatform extends AbstractPlatform
return false; return false;
} }
return 'ALTER TABLE ' . $name . ' ' . $query; return array('ALTER TABLE ' . $name . ' ' . $query);
} }
/** /**
......
...@@ -655,7 +655,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -655,7 +655,7 @@ class MySqlPlatform extends AbstractPlatform
return false; return false;
} }
return 'ALTER TABLE ' . $name . ' ' . $query; return array('ALTER TABLE ' . $name . ' ' . $query);
} }
/** /**
......
...@@ -392,6 +392,18 @@ END;'; ...@@ -392,6 +392,18 @@ END;';
return 'DROP USER ' . $database . ' CASCADE'; 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) public function getAlterTableSql($name, array $changes, $check = false)
{ {
if ( ! $name) { if ( ! $name) {
......
...@@ -656,7 +656,7 @@ class SchemaTool ...@@ -656,7 +656,7 @@ class SchemaTool
$joinColumn['type'] = Type::getType($joinColumn['type']); $joinColumn['type'] = Type::getType($joinColumn['type']);
$changes['add'][$name] = $joinColumn; $changes['add'][$name] = $joinColumn;
} }
$sql[] = $this->_platform->getAlterTableSql($tableName, $changes); $sql = array_merge($sql, $this->_platform->getAlterTableSql($tableName, $changes));
} }
// Update existent columns // Update existent columns
...@@ -670,7 +670,7 @@ class SchemaTool ...@@ -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 // Drop any remaining columns
...@@ -682,7 +682,7 @@ class SchemaTool ...@@ -682,7 +682,7 @@ class SchemaTool
$changes['remove'][$column['name']] = $column; $changes['remove'][$column['name']] = $column;
} }
$sql[] = $this->_platform->getAlterTableSql($tableName, $changes); $sql = array_merge($sql, $this->_platform->getAlterTableSql($tableName, $changes));
} }
} }
} }
......
...@@ -50,10 +50,11 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ...@@ -50,10 +50,11 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase
'unsigned' => 1 'unsigned' => 1
) )
)); ));
$sql = $this->_platform->getAlterTableSql('mytable', $changes);
$this->assertEquals( $this->assertEquals(
'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL', 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL',
$this->_platform->getAlterTableSql('mytable', $changes) $sql[0]
); );
} }
......
...@@ -50,10 +50,11 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase ...@@ -50,10 +50,11 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase
'unsigned' => 1 'unsigned' => 1
) )
)); ));
$sql = $this->_platform->getAlterTableSql('mytable', $changes);
$this->assertEquals( $this->assertEquals(
'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL', 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL',
$this->_platform->getAlterTableSql('mytable', $changes) $sql[0]
); );
} }
......
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