diff --git a/UPGRADE.md b/UPGRADE.md index e1ff68b0d0d..b3632793ae3 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,11 @@ awareness about deprecated code. # 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. diff --git a/psalm.xml.dist b/psalm.xml.dist index 1cf30cf29f9..61907a7a52a 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -74,6 +74,12 @@ --> + + + diff --git a/src/Connection.php b/src/Connection.php index a81e57e2c7d..35d608d6f92 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -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. diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 53b71a8dcd5..1014f8f52ef 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -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; @@ -1190,12 +1191,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)); diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index 1be232a6bbc..c03cf6efc37 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -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), ); } diff --git a/src/Schema/AbstractAsset.php b/src/Schema/AbstractAsset.php index de5b56f1d52..671bddfe809 100644 --- a/src/Schema/AbstractAsset.php +++ b/src/Schema/AbstractAsset.php @@ -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); diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index 25123e5db5e..858b671aec5 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -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; diff --git a/tests/Functional/Platform/QuotingTest.php b/tests/Functional/Platform/QuotingTest.php index a9a293e3671..c975404a4ce 100644 --- a/tests/Functional/Platform/QuotingTest.php +++ b/tests/Functional/Platform/QuotingTest.php @@ -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); diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 7ca35dee0d4..a2b01d7c5e8 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -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(); diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index c913cdc2c06..a19fc4675cc 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -524,7 +524,7 @@ public function testAlterTableChangeQuotedColumn(): void ]); self::assertStringContainsString( - $this->platform->quoteIdentifier('select'), + $this->platform->quoteSingleIdentifier('select'), implode(';', $this->platform->getAlterTableSQL($tableDiff)), ); } diff --git a/tests/TestUtil.php b/tests/TestUtil.php index ba54b07fd4e..f02d7e7de6a 100644 --- a/tests/TestUtil.php +++ b/tests/TestUtil.php @@ -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));