Commit 9cfbc216 authored by Steve Müller's avatar Steve Müller

fix renaming column with default value on SQL Server

parent 93af9aab
...@@ -506,7 +506,10 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -506,7 +506,10 @@ class SQLServerPlatform extends AbstractPlatform
// Recreate default constraint with new column name if necessary (for future reference). // Recreate default constraint with new column name if necessary (for future reference).
if ($column->getDefault() !== null) { if ($column->getDefault() !== null) {
$queryParts[] = $this->getAlterTableDropDefaultConstraintClause($diff->name, $oldColumnName); $queryParts[] = $this->getAlterTableDropDefaultConstraintClause(
$diff->name,
$oldColumnName->getQuotedName($this)
);
$queryParts[] = $this->getAlterTableAddDefaultConstraintClause($diff->name, $column); $queryParts[] = $this->getAlterTableAddDefaultConstraintClause($diff->name, $column);
} }
} }
......
...@@ -604,4 +604,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -604,4 +604,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
{ {
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); $this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
} }
/**
* {@inheritdoc}
*/
public function getAlterTableRenameColumnSQL()
{
return array(
"ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'",
);
}
} }
...@@ -5,6 +5,7 @@ namespace Doctrine\Tests\DBAL\Platforms; ...@@ -5,6 +5,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
...@@ -956,4 +957,32 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -956,4 +957,32 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{ {
$this->_platform->getGuidTypeDeclarationSQL(array()); $this->_platform->getGuidTypeDeclarationSQL(array());
} }
/**
* @group DBAL-1010
*/
public function testGeneratesAlterTableRenameColumnSQL()
{
$table = new Table('foo');
$table->addColumn(
'bar',
'integer',
array('notnull' => true, 'default' => 666, 'comment' => 'rename test')
);
$tableDiff = new TableDiff('foo');
$tableDiff->fromTable = $table;
$tableDiff->renamedColumns['bar'] = new Column(
'baz',
Type::getType('integer'),
array('notnull' => true, 'default' => 666, 'comment' => 'rename test')
);
$this->assertSame($this->getAlterTableRenameColumnSQL(), $this->_platform->getAlterTableSQL($tableDiff));
}
/**
* @return array
*/
abstract public function getAlterTableRenameColumnSQL();
} }
...@@ -672,4 +672,14 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -672,4 +672,14 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
{ {
$this->assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL(array())); $this->assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL(array()));
} }
/**
* {@inheritdoc}
*/
public function getAlterTableRenameColumnSQL()
{
return array(
'ALTER TABLE foo RENAME COLUMN bar TO baz',
);
}
} }
...@@ -1109,4 +1109,16 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1109,4 +1109,16 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
{ {
$this->assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array())); $this->assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array()));
} }
/**
* {@inheritdoc}
*/
public function getAlterTableRenameColumnSQL()
{
return array(
"sp_RENAME 'foo.bar', 'baz', 'COLUMN'",
'ALTER TABLE foo DROP CONSTRAINT DF_8C736521_76FF8CAA',
'ALTER TABLE foo ADD CONSTRAINT DF_8C736521_78240498 DEFAULT 666 FOR baz',
);
}
} }
...@@ -471,4 +471,14 @@ class DB2PlatformTest extends AbstractPlatformTestCase ...@@ -471,4 +471,14 @@ class DB2PlatformTest extends AbstractPlatformTestCase
{ {
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); $this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
} }
/**
* {@inheritdoc}
*/
public function getAlterTableRenameColumnSQL()
{
return array(
'ALTER TABLE foo RENAME COLUMN bar TO baz',
);
}
} }
...@@ -492,4 +492,14 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -492,4 +492,14 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{ {
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); $this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
} }
/**
* {@inheritdoc}
*/
public function getAlterTableRenameColumnSQL()
{
return array(
'ALTER TABLE foo RENAME COLUMN bar TO baz',
);
}
} }
...@@ -863,4 +863,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -863,4 +863,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
{ {
$this->assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array())); $this->assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array()));
} }
/**
* {@inheritdoc}
*/
public function getAlterTableRenameColumnSQL()
{
return array(
'ALTER TABLE foo RENAME bar TO baz',
);
}
} }
...@@ -560,4 +560,18 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -560,4 +560,18 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{ {
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); $this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
} }
/**
* {@inheritdoc}
*/
public function getAlterTableRenameColumnSQL()
{
return array(
'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo',
'DROP TABLE foo',
'CREATE TABLE foo (baz INTEGER DEFAULT 666 NOT NULL)',
'INSERT INTO foo (baz) SELECT bar FROM __temp__foo',
'DROP TABLE __temp__foo',
);
}
} }
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