Commit c752fc01 authored by Bill Schaller's avatar Bill Schaller

Merge pull request #2288 from deeky666/DBAL-1255

Preserve quotation of old column name in ColumnDiff
parents 68558492 d6317d35
......@@ -77,6 +77,8 @@ class ColumnDiff
*/
public function getOldColumnName()
{
return new Identifier($this->oldColumnName);
$quote = $this->fromColumn && $this->fromColumn->isQuoted();
return new Identifier($this->oldColumnName, $quote);
}
}
......@@ -35,9 +35,14 @@ class Identifier extends AbstractAsset
* Constructor.
*
* @param string $identifier Identifier name to wrap.
* @param bool $quote Whether to force quoting the given identifier.
*/
public function __construct($identifier)
public function __construct($identifier, $quote = false)
{
$this->_setName($identifier);
if ($quote && ! $this->_quoted) {
$this->_setName('"' . $this->getName() . '"');
}
}
}
<?php
namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Types\Type;
class ColumnDiffTest extends \PHPUnit_Framework_TestCase
{
/**
* @group DBAL-1255
*/
public function testPreservesOldColumnNameQuotation()
{
$fromColumn = new Column('"foo"', Type::getType(Type::INTEGER));
$toColumn = new Column('bar', Type::getType(Type::INTEGER));
$columnDiff = new ColumnDiff('"foo"', $toColumn, array());
$this->assertTrue($columnDiff->getOldColumnName()->isQuoted());
$columnDiff = new ColumnDiff('"foo"', $toColumn, array(), $fromColumn);
$this->assertTrue($columnDiff->getOldColumnName()->isQuoted());
$columnDiff = new ColumnDiff('foo', $toColumn, array(), $fromColumn);
$this->assertTrue($columnDiff->getOldColumnName()->isQuoted());
}
}
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