Skip to content

Commit

Permalink
Merge branch '4.3.x' into 5.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Nov 11, 2024
2 parents 5ecf632 + 8879eb2 commit 2a8db3b
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 8 deletions.
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 @@ private function extractTypeValues(array $columns, array $types): array
* 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.
*
* @throws Exception
*/
public function quoteSingleIdentifier(string $identifier): string
{
return $this->getDatabasePlatform()->quoteSingleIdentifier($identifier);
}

/**
* 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 @@ public function dropTable(string $name): void
private function getQuotedIdentifierName(string $identifier): string
{
if (preg_match('/[a-z]/', $identifier) === 1) {
return $this->platform->quoteIdentifier($identifier);
return $this->platform->quoteSingleIdentifier($identifier);
}

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

0 comments on commit 2a8db3b

Please sign in to comment.