Commit 51074ffd authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #672 from deeky666/DBAL-830

[DBAL-830] Fix SQL Server default constraint name generation for quoted identifiers
parents 85fd6247 040bfc37
......@@ -322,11 +322,13 @@ class SQLServerPlatform extends AbstractPlatform
throw new \InvalidArgumentException("Incomplete column definition. 'default' required.");
}
$columnName = new Identifier($column['name']);
return
' CONSTRAINT ' .
$this->generateDefaultConstraintName($table, $column['name']) .
$this->getDefaultValueDeclarationSQL($column) .
' FOR ' . $column['name'];
' FOR ' . $columnName->getQuotedName($this);
}
/**
......@@ -1519,6 +1521,9 @@ class SQLServerPlatform extends AbstractPlatform
*/
private function generateIdentifierName($identifier)
{
return strtoupper(dechex(crc32($identifier)));
// Always generate name for unquoted identifiers to ensure consistency.
$identifier = new Identifier($identifier);
return strtoupper(dechex(crc32($identifier->getName())));
}
}
......@@ -155,7 +155,7 @@ abstract class AbstractAsset
*/
protected function isIdentifierQuoted($identifier)
{
return (isset($identifier[0]) && ($identifier[0] == '`' || $identifier[0] == '"'));
return (isset($identifier[0]) && ($identifier[0] == '`' || $identifier[0] == '"' || $identifier[0] == '['));
}
/**
......@@ -167,7 +167,7 @@ abstract class AbstractAsset
*/
protected function trimQuotes($identifier)
{
return str_replace(array('`', '"'), '', $identifier);
return str_replace(array('`', '"', '[', ']'), '', $identifier);
}
/**
......
......@@ -80,6 +80,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
/**
* @group DBAL-64
* @group DBAL-830
*/
public function testQuotedColumnName()
{
......@@ -92,6 +93,35 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar', $column->getName());
$this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform));
$this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform));
$column = new Column("[bar]", $string);
$sqlServerPlatform = new \Doctrine\DBAL\Platforms\SQLServerPlatform();
$this->assertEquals('bar', $column->getName());
$this->assertEquals('[bar]', $column->getQuotedName($sqlServerPlatform));
}
/**
* @dataProvider getIsQuoted
* @group DBAL-830
*/
public function testIsQuoted($columnName, $isQuoted)
{
$type = Type::getType('string');
$column = new Column($columnName, $type);
$this->assertSame($isQuoted, $column->isQuoted());
}
public function getIsQuoted()
{
return array(
array('bar', false),
array('`bar`', true),
array('"bar"', true),
array('[bar]', true),
);
}
/**
......
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