Commit 8f4d499a authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DDC-1360' into 2.2

parents 5df86161 4f77e750
......@@ -1276,7 +1276,8 @@ abstract class AbstractPlatform
/**
* Quotes a string so that it can be safely used as a table or column name,
* even if it is a reserved word of the platform.
* even if it is a reserved word of the platform. This also detects identifier
* chains seperated by dot and quotes them independently.
*
* NOTE: Just because you CAN use quoted identifiers doesn't mean
* you SHOULD use them. In general, they end up causing way more
......@@ -1286,6 +1287,22 @@ abstract class AbstractPlatform
* @return string quoted identifier string
*/
public function quoteIdentifier($str)
{
if (strpos($str, ".") !== false) {
$parts = array_map(array($this, "quoteIdentifier"), explode(".", $str));
return implode(".", $parts);
}
return $this->quoteSingleIdentifier($str);
}
/**
* Quote a single identifier (no dot chain seperation)
*
* @param string $str
* @return string
*/
public function quoteSingleIdentifier($str)
{
$c = $this->getIdentifierQuoteCharacter();
......@@ -2591,4 +2608,4 @@ abstract class AbstractPlatform
{
throw DBALException::notSupported(__METHOD__);
}
}
\ No newline at end of file
}
......@@ -831,17 +831,9 @@ class MsSqlPlatform extends AbstractPlatform
}
/**
* Quotes a string so that it can be safely used as a table or column name,
* even if it is a reserved word of the platform.
*
* NOTE: Just because you CAN use quoted identifiers doesn't mean
* you SHOULD use them. In general, they end up causing way more
* problems than they solve.
*
* @param string $str identifier name to be quoted
* @return string quoted identifier string
* {@inheritDoc}
*/
public function quoteIdentifier($str)
public function quoteSingleIdentifier($str)
{
return "[" . str_replace("]", "][", $str) . "]";
}
......
......@@ -19,6 +19,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->_platform = $this->createPlatform();
}
/**
* @group DDC-1360
*/
public function testQuoteIdentifier()
{
if ($this->_platform->getName() == "mssql") {
......@@ -26,9 +29,26 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
}
$c = $this->_platform->getIdentifierQuoteCharacter();
$this->assertEquals($c."test".$c, $this->_platform->quoteIdentifier("test"));
$this->assertEquals($c."test".$c.".".$c."test".$c, $this->_platform->quoteIdentifier("test.test"));
$this->assertEquals(str_repeat($c, 4), $this->_platform->quoteIdentifier($c));
}
/**
* @group DDC-1360
*/
public function testQuoteSingleIdentifier()
{
if ($this->_platform->getName() == "mssql") {
$this->markTestSkipped('Not working this way on mssql.');
}
$c = $this->_platform->getIdentifierQuoteCharacter();
$this->assertEquals($c."test".$c, $this->_platform->quoteSingleIdentifier("test"));
$this->assertEquals($c."test.test".$c, $this->_platform->quoteSingleIdentifier("test.test"));
$this->assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c));
}
public function testGetInvalidtForeignKeyReferentialActionSQL()
{
$this->setExpectedException('InvalidArgumentException');
......
......@@ -171,8 +171,23 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
$this->assertEquals('SELECT TOP 10 * FROM user ORDER BY username DESC', $sql);
}
/**
* @group DDC-1360
*/
public function testQuoteIdentifier()
{
$this->assertEquals('[fo][o]', $this->_platform->quoteIdentifier('fo]o'));
$this->assertEquals('[test]', $this->_platform->quoteIdentifier('test'));
$this->assertEquals('[test].[test]', $this->_platform->quoteIdentifier('test.test'));
}
}
\ No newline at end of file
/**
* @group DDC-1360
*/
public function testQuoteSingleIdentifier()
{
$this->assertEquals('[fo][o]', $this->_platform->quoteSingleIdentifier('fo]o'));
$this->assertEquals('[test]', $this->_platform->quoteSingleIdentifier('test'));
$this->assertEquals('[test.test]', $this->_platform->quoteSingleIdentifier('test.test'));
}
}
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