Skip to content

Merge 4.3.x up into 5.0.x #6591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ all drivers and middleware.

# Upgrade to 4.3

## Deprecated `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()`

The `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()` methods have been deprecated.
Use the corresponding `quoteSingleIdentifier()` method individually for each part of a qualified name instead.

## Deprecated dropping columns referenced by constraints

Dropping columns that are referenced by constraints is deprecated. The constraints should be dropped first.
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@

<!-- 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
19 changes: 19 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,34 @@
* 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__,
);

Check warning on line 560 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L555-L560

Added lines #L555 - L560 were not covered by tests

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

/**
* Quotes a string so that it can be safely used as an identifier in SQL.
*
* @throws Exception
*/
public function quoteSingleIdentifier(string $identifier): string

Check warning on line 570 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L570

Added line #L570 was not covered by tests
{
return $this->getDatabasePlatform()->quoteSingleIdentifier($identifier);

Check warning on line 572 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L572

Added line #L572 was not covered by tests
}

/**
* The usage of this method is discouraged. Use prepared statements
* or {@see AbstractPlatform::quoteStringLiteral()} instead.
Expand Down
10 changes: 10 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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 Down Expand Up @@ -1184,12 +1185,21 @@ public function getDropSchemaSQL(string $schemaName): string
* 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));

Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ private function getAlterTableDropDefaultConstraintClause(Column $column): strin
);
}

return 'DROP CONSTRAINT ' . $this->quoteIdentifier(
return 'DROP CONSTRAINT ' . $this->quoteSingleIdentifier(
$column->getPlatformOption(self::OPTION_DEFAULT_CONSTRAINT_NAME),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function getQuotedName(AbstractPlatform $platform): string
$keywords = $platform->getReservedKeywordsList();
$parts = explode('.', $this->getName());
foreach ($parts as $k => $v) {
$parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v;
$parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteSingleIdentifier($v) : $v;
}

return implode('.', $parts);
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
private function getQuotedIdentifierName(string $identifier): string
{
if (preg_match('/[a-z]/', $identifier) === 1) {
return $this->platform->quoteIdentifier($identifier);
return $this->platform->quoteSingleIdentifier($identifier);

Check warning on line 308 in src/Schema/OracleSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/OracleSchemaManager.php#L308

Added line #L308 was not covered by tests
}

return $identifier;
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Platform/QuotingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testQuoteIdentifier(string $identifier): void
}

$query = $platform->getDummySelectSQL(
'NULL AS ' . $platform->quoteIdentifier($identifier),
'NULL AS ' . $platform->quoteSingleIdentifier($identifier),
);

$row = $this->connection->fetchAssociative($query);
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1316,8 +1316,8 @@ private function createReservedKeywordTables(): void
{
$platform = $this->connection->getDatabasePlatform();

$this->dropTableIfExists($platform->quoteIdentifier('user'));
$this->dropTableIfExists($platform->quoteIdentifier('group'));
$this->dropTableIfExists($platform->quoteSingleIdentifier('user'));
$this->dropTableIfExists($platform->quoteSingleIdentifier('group'));

$schema = new Schema();

Expand Down
2 changes: 1 addition & 1 deletion tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public function testAlterTableChangeQuotedColumn(): void
]);

self::assertStringContainsString(
$this->platform->quoteIdentifier('select'),
$this->platform->quoteSingleIdentifier('select'),
implode(';', $this->platform->getAlterTableSQL($tableDiff)),
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static function generateResultSetQuery(array $columnNames, array $rows, A
$value = $platform->quoteStringLiteral($value);
}

return $value . ' ' . $platform->quoteIdentifier($column);
return $value . ' ' . $platform->quoteSingleIdentifier($column);
}, $columnNames, $row)),
);
}, $rows));
Expand Down
Loading