Skip to content

Commit

Permalink
[doctrineGH-4645] Fix SQLServerPlatform::quoteIdentifier()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed May 13, 2021
1 parent b728198 commit fde42dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ protected function getReservedKeywordsClass()
*/
public function quoteSingleIdentifier($str)
{
return '[' . str_replace(']', '][', $str) . ']';
return '[' . str_replace(']', ']]', $str) . ']';
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Doctrine\Tests\DbalFunctionalTestCase;

use function key;

class QuotingTest extends DbalFunctionalTestCase
{
/**
Expand All @@ -29,4 +31,30 @@ public static function stringLiteralProvider(): iterable
'single-quote' => ["'"],
];
}

/**
* @dataProvider identifierProvider
*/
public function testQuoteIdentifier(string $identifier): void
{
$platform = $this->connection->getDatabasePlatform();
$query = $platform->getDummySelectSQL(
'NULL AS ' . $platform->quoteIdentifier($identifier)
);

self::assertSame($identifier, key($this->connection->fetchAssociative($query)));
}

/**
* @return iterable<string,array{0:string}>
*/
public static function identifierProvider(): iterable
{
return [
'[' => ['['],
']' => [']'],
'"' => ['"'],
'`' => ['`'],
];
}
}

0 comments on commit fde42dd

Please sign in to comment.