Skip to content

Commit

Permalink
Merge pull request #6594 from morozov/remove-quote-identifier
Browse files Browse the repository at this point in the history
Remove AbstractPlatform::quoteIdentifier()
  • Loading branch information
morozov authored Nov 12, 2024
2 parents 2a8db3b + a6bf54a commit a56e4c1
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 96 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ awareness about deprecated code.

# Upgrade to 5.0

## BC BREAK: Removed `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()`

The `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()` methods have been removed.

## BC BREAK: Removed `Table::removeForeignKey()` and `::removeUniqueConstraint()`

The `Table::removeForeignKey()` and `::removeUniqueConstraint()` have been removed.
Expand Down
6 changes: 0 additions & 6 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@

<!-- TODO for PHPUnit 11 -->
<referencedMethod name="PHPUnit\Framework\TestCase::iniSet"/>

<!--
https://github.com/doctrine/dbal/pull/6590
TODO: remove in 5.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::quoteIdentifier" />
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down
28 changes: 0 additions & 28 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,34 +534,6 @@ private function extractTypeValues(array $columns, array $types): array
return $typeValues;
}

/**
* Quotes a string so it can be safely used as a table or column name, even if
* it is a reserved name.
*
* Delimiting style depends on the underlying database platform that is being used.
*
* NOTE: Just because you CAN use quoted identifiers does not mean
* you SHOULD use them. In general, they end up causing way more
* problems than they solve.
*
* @deprecated Use {@link quoteSingleIdentifier()} individually for each part of a qualified name instead.
*
* @param string $identifier The identifier to be quoted.
*
* @return string The quoted identifier.
*/
public function quoteIdentifier(string $identifier): string
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6590',
'Use quoteSingleIdentifier() individually for each part of a qualified name instead.',
__METHOD__,
);

return $this->getDatabasePlatform()->quoteIdentifier($identifier);
}

/**
* Quotes a string so that it can be safely used as an identifier in SQL.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ protected function doModifyLimitQuery(string $query, ?int $limit, int $offset):
return $query;
}

public function quoteSingleIdentifier(string $str): string
public function quoteSingleIdentifier(string $identifier): string
{
return '`' . str_replace('`', '``', $str) . '`';
return '`' . str_replace('`', '``', $identifier) . '`';
}

public function getRegexpExpression(): string
Expand Down
46 changes: 3 additions & 43 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Exception\TypeNotFound;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;

use function addcslashes;
use function array_map;
Expand All @@ -45,7 +44,6 @@
use function array_values;
use function assert;
use function count;
use function explode;
use function implode;
use function in_array;
use function is_array;
Expand All @@ -58,7 +56,6 @@
use function preg_quote;
use function preg_replace;
use function sprintf;
use function str_contains;
use function str_replace;
use function strlen;
use function strtolower;
Expand Down Expand Up @@ -1177,48 +1174,11 @@ public function getDropSchemaSQL(string $schemaName): string
}

/**
* 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. This also detects identifier
* chains separated 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
* problems than they solve.
*
* @deprecated Use {@link quoteSingleIdentifier()} individually for each part of a qualified name instead.
*
* @param string $identifier The identifier name to be quoted.
*
* @return string The quoted identifier string.
*/
public function quoteIdentifier(string $identifier): string
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6590',
'Use quoteSingleIdentifier() individually for each part of a qualified name instead.',
__METHOD__,
);

if (str_contains($identifier, '.')) {
$parts = array_map($this->quoteSingleIdentifier(...), explode('.', $identifier));

return implode('.', $parts);
}

return $this->quoteSingleIdentifier($identifier);
}

/**
* Quotes a single identifier (no dot chain separation).
*
* @param string $str The identifier name to be quoted.
*
* @return string The quoted identifier string.
* Quotes a string so that it can be safely used as an identifier in SQL.
*/
public function quoteSingleIdentifier(string $str): string
public function quoteSingleIdentifier(string $identifier): string
{
return '"' . str_replace('"', '""', $str) . '"';
return '"' . str_replace('"', '""', $identifier) . '"';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,9 +1132,9 @@ protected function createReservedKeywordsList(): KeywordList
return new SQLServerKeywords();
}

public function quoteSingleIdentifier(string $str): string
public function quoteSingleIdentifier(string $identifier): string
{
return '[' . str_replace(']', ']]', $str) . ']';
return '[' . str_replace(']', ']]', $identifier) . ']';
}

public function getTruncateTableSQL(string $tableName, bool $cascade = false): string
Expand Down
5 changes: 0 additions & 5 deletions tests/Platforms/AbstractMySQLPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,6 @@ public function testGetCreateTableSQLWithColumnCollation(): void
);
}

public function testQuoteIdentifier(): void
{
self::assertEquals('`test`.`test`', $this->platform->quoteIdentifier('test.test'));
}

protected function createComparator(): Comparator
{
return new MySQL\Comparator(
Expand Down
5 changes: 0 additions & 5 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ protected function createComparator(): Comparator
return new Comparator($this->platform, new ComparatorConfig());
}

public function testQuoteIdentifier(): void
{
self::assertEquals('"test"."test"', $this->platform->quoteIdentifier('test.test'));
}

#[DataProvider('getReturnsForeignKeyReferentialActionSQL')]
public function testReturnsForeignKeyReferentialActionSQL(string $action, string $expectedSQL): void
{
Expand Down
5 changes: 0 additions & 5 deletions tests/Platforms/SQLServerPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,6 @@ public function testModifyLimitSubquerySimple(): void
);
}

public function testQuoteIdentifier(): void
{
self::assertEquals('[test].[test]', $this->platform->quoteIdentifier('test.test'));
}

public function testCreateClusteredIndex(): void
{
$idx = new Index('idx', ['id']);
Expand Down

0 comments on commit a56e4c1

Please sign in to comment.