Skip to content

Commit 2a8db3b

Browse files
committed
Merge branch '4.3.x' into 5.0.x
2 parents 5ecf632 + 8879eb2 commit 2a8db3b

File tree

11 files changed

+48
-8
lines changed

11 files changed

+48
-8
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ all drivers and middleware.
2929

3030
# Upgrade to 4.3
3131

32+
## Deprecated `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()`
33+
34+
The `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()` methods have been deprecated.
35+
Use the corresponding `quoteSingleIdentifier()` method individually for each part of a qualified name instead.
36+
3237
## Deprecated dropping columns referenced by constraints
3338

3439
Dropping columns that are referenced by constraints is deprecated. The constraints should be dropped first.

psalm.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555

5656
<!-- TODO for PHPUnit 11 -->
5757
<referencedMethod name="PHPUnit\Framework\TestCase::iniSet"/>
58+
59+
<!--
60+
https://github.com/doctrine/dbal/pull/6590
61+
TODO: remove in 5.0.0
62+
-->
63+
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::quoteIdentifier" />
5864
</errorLevel>
5965
</DeprecatedMethod>
6066
<DocblockTypeContradiction>

src/Connection.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,34 @@ private function extractTypeValues(array $columns, array $types): array
544544
* you SHOULD use them. In general, they end up causing way more
545545
* problems than they solve.
546546
*
547+
* @deprecated Use {@link quoteSingleIdentifier()} individually for each part of a qualified name instead.
548+
*
547549
* @param string $identifier The identifier to be quoted.
548550
*
549551
* @return string The quoted identifier.
550552
*/
551553
public function quoteIdentifier(string $identifier): string
552554
{
555+
Deprecation::trigger(
556+
'doctrine/dbal',
557+
'https://github.com/doctrine/dbal/pull/6590',
558+
'Use quoteSingleIdentifier() individually for each part of a qualified name instead.',
559+
__METHOD__,
560+
);
561+
553562
return $this->getDatabasePlatform()->quoteIdentifier($identifier);
554563
}
555564

565+
/**
566+
* Quotes a string so that it can be safely used as an identifier in SQL.
567+
*
568+
* @throws Exception
569+
*/
570+
public function quoteSingleIdentifier(string $identifier): string
571+
{
572+
return $this->getDatabasePlatform()->quoteSingleIdentifier($identifier);
573+
}
574+
556575
/**
557576
* The usage of this method is discouraged. Use prepared statements
558577
* or {@see AbstractPlatform::quoteStringLiteral()} instead.

src/Platforms/AbstractPlatform.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Doctrine\DBAL\Types;
3737
use Doctrine\DBAL\Types\Exception\TypeNotFound;
3838
use Doctrine\DBAL\Types\Type;
39+
use Doctrine\Deprecations\Deprecation;
3940

4041
use function addcslashes;
4142
use function array_map;
@@ -1184,12 +1185,21 @@ public function getDropSchemaSQL(string $schemaName): string
11841185
* you SHOULD use them. In general, they end up causing way more
11851186
* problems than they solve.
11861187
*
1188+
* @deprecated Use {@link quoteSingleIdentifier()} individually for each part of a qualified name instead.
1189+
*
11871190
* @param string $identifier The identifier name to be quoted.
11881191
*
11891192
* @return string The quoted identifier string.
11901193
*/
11911194
public function quoteIdentifier(string $identifier): string
11921195
{
1196+
Deprecation::trigger(
1197+
'doctrine/dbal',
1198+
'https://github.com/doctrine/dbal/pull/6590',
1199+
'Use quoteSingleIdentifier() individually for each part of a qualified name instead.',
1200+
__METHOD__,
1201+
);
1202+
11931203
if (str_contains($identifier, '.')) {
11941204
$parts = array_map($this->quoteSingleIdentifier(...), explode('.', $identifier));
11951205

src/Platforms/SQLServerPlatform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ private function getAlterTableDropDefaultConstraintClause(Column $column): strin
525525
);
526526
}
527527

528-
return 'DROP CONSTRAINT ' . $this->quoteIdentifier(
528+
return 'DROP CONSTRAINT ' . $this->quoteSingleIdentifier(
529529
$column->getPlatformOption(self::OPTION_DEFAULT_CONSTRAINT_NAME),
530530
);
531531
}

src/Schema/AbstractAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function getQuotedName(AbstractPlatform $platform): string
131131
$keywords = $platform->getReservedKeywordsList();
132132
$parts = explode('.', $this->getName());
133133
foreach ($parts as $k => $v) {
134-
$parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v;
134+
$parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteSingleIdentifier($v) : $v;
135135
}
136136

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

src/Schema/OracleSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function dropTable(string $name): void
305305
private function getQuotedIdentifierName(string $identifier): string
306306
{
307307
if (preg_match('/[a-z]/', $identifier) === 1) {
308-
return $this->platform->quoteIdentifier($identifier);
308+
return $this->platform->quoteSingleIdentifier($identifier);
309309
}
310310

311311
return $identifier;

tests/Functional/Platform/QuotingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testQuoteIdentifier(string $identifier): void
4343
}
4444

4545
$query = $platform->getDummySelectSQL(
46-
'NULL AS ' . $platform->quoteIdentifier($identifier),
46+
'NULL AS ' . $platform->quoteSingleIdentifier($identifier),
4747
);
4848

4949
$row = $this->connection->fetchAssociative($query);

tests/Functional/Schema/SchemaManagerFunctionalTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,8 @@ private function createReservedKeywordTables(): void
13161316
{
13171317
$platform = $this->connection->getDatabasePlatform();
13181318

1319-
$this->dropTableIfExists($platform->quoteIdentifier('user'));
1320-
$this->dropTableIfExists($platform->quoteIdentifier('group'));
1319+
$this->dropTableIfExists($platform->quoteSingleIdentifier('user'));
1320+
$this->dropTableIfExists($platform->quoteSingleIdentifier('group'));
13211321

13221322
$schema = new Schema();
13231323

tests/Platforms/AbstractPlatformTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public function testAlterTableChangeQuotedColumn(): void
524524
]);
525525

526526
self::assertStringContainsString(
527-
$this->platform->quoteIdentifier('select'),
527+
$this->platform->quoteSingleIdentifier('select'),
528528
implode(';', $this->platform->getAlterTableSQL($tableDiff)),
529529
);
530530
}

0 commit comments

Comments
 (0)