Skip to content

Deprecate reserved keyword lists #6607

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 2 commits into from
Nov 16, 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
14 changes: 14 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ awareness about deprecated code.

# Upgrade to 4.3

## Deprecated Reserved Keyword Lists

The use of DBAL as the source for platform-specific reserved keyword lists has been deprecated. The following components
have been deprecated:

1. The `KeywordList` class and all its subclasses.
2. The methods `AbstractPlatform::createReservedKeywordsList()` and `::getReservedKeywordsList()`.
3. The `AbstractPlatform::$_keywords` property.

Please refer to the official documentation provided by the respective database vendor for up-to-date information on
reserved keywords.

Additionally, the `MySQL84Platform` class has been deprecated. Use the `MySQLPlatform` class instead.

## Deprecated relying on the current implementation of the database object name parser

The current object name parser implicitly quotes identifiers in the following cases:
Expand Down
31 changes: 31 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
<referencedClass name="Doctrine\DBAL\Platforms\MariaDB1052Platform" />
<referencedClass name="Doctrine\DBAL\Platforms\MySQL80Platform" />
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQL120Platform" />

<!--
https://github.com/doctrine/dbal/pull/6607
TODO: remove in 5.0.0
-->
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\KeywordList" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\DB2Keywords" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\MariaDBKeywords" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\MySQLKeywords" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\MySQL84Keywords" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\OracleKeywords" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords" />
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords" />
<referencedClass name="Doctrine\DBAL\Platforms\MySQL84Platform" />
</errorLevel>
</DeprecatedClass>
<DeprecatedMethod>
Expand Down Expand Up @@ -80,8 +95,24 @@
TODO: remove in 5.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::quoteIdentifier" />

<!--
https://github.com/doctrine/dbal/pull/6607
TODO: remove in 5.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::createReservedKeywordsList" />
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getReservedKeywordsList" />
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
<errorLevel type="suppress">
<!--
https://github.com/doctrine/dbal/pull/6607
TODO: remove in 5.0.0
-->
<referencedProperty name="Doctrine\DBAL\Platforms\AbstractPlatform::$_keywords" />
</errorLevel>
</DeprecatedProperty>
<DocblockTypeContradiction>
<errorLevel type="suppress">
<!--
Expand Down
9 changes: 9 additions & 0 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\Deprecation;

use function array_map;
use function array_merge;
Expand Down Expand Up @@ -763,8 +764,16 @@
];
}

/** @deprecated */
protected function createReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

Check warning on line 775 in src/Platforms/AbstractMySQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractMySQLPlatform.php#L770-L775

Added lines #L770 - L775 were not covered by tests

return new MySQLKeywords();
}

Expand Down
13 changes: 13 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ abstract class AbstractPlatform

/**
* Holds the KeywordList instance for the current platform.
*
* @deprecated
*/
protected ?KeywordList $_keywords = null;

Expand Down Expand Up @@ -2170,15 +2172,26 @@ public function rollbackSavePoint(string $savepoint): string

/**
* Returns the keyword list instance of this platform.
*
* @deprecated
*/
final public function getReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

// Store the instance so it doesn't need to be generated on every request.
return $this->_keywords ??= $this->createReservedKeywordsList();
}

/**
* Creates an instance of the reserved keyword list of this platform.
*
* @deprecated
*/
abstract protected function createReservedKeywordsList(): KeywordList;

Expand Down
9 changes: 9 additions & 0 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\DateTimeType;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\Deprecation;

use function array_merge;
use function count;
Expand Down Expand Up @@ -591,8 +592,16 @@ public function supportsSavepoints(): bool
return false;
}

/** @deprecated */
protected function createReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

return new DB2Keywords();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Platforms/Keywords/DB2Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* DB2 Keywords.
*
* @deprecated
*/
class DB2Keywords extends KeywordList
{
Expand Down
14 changes: 14 additions & 0 deletions src/Platforms/Keywords/KeywordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@

namespace Doctrine\DBAL\Platforms\Keywords;

use Doctrine\Deprecations\Deprecation;

use function array_flip;
use function array_map;
use function strtoupper;

/**
* Abstract interface for a SQL reserved keyword dictionary.
*
* @deprecated
*/
abstract class KeywordList
{
/** @var string[]|null */
private ?array $keywords = null;

public function __construct()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
static::class,
);
}

/**
* Checks if the given word is a keyword of this dialect/vendor platform.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Platforms/Keywords/MariaDBKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\DBAL\Platforms\Keywords;

/** @deprecated */
class MariaDBKeywords extends MySQLKeywords
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/Keywords/MySQL80Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* MySQL 8.0 reserved keywords list.
*
* @deprecated This class will be removed once support for MySQL 5.7 is dropped.
* @deprecated
*/
class MySQL80Keywords extends MySQLKeywords
{
Expand Down
2 changes: 2 additions & 0 deletions src/Platforms/Keywords/MySQL84Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* MySQL 8.4 reserved keywords list.
*
* @deprecated
*/
class MySQL84Keywords extends MySQL80Keywords
{
Expand Down
2 changes: 2 additions & 0 deletions src/Platforms/Keywords/MySQLKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* MySQL Keywordlist.
*
* @deprecated
*/
class MySQLKeywords extends KeywordList
{
Expand Down
2 changes: 2 additions & 0 deletions src/Platforms/Keywords/OracleKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* Oracle Keywordlist.
*
* @deprecated
*/
class OracleKeywords extends KeywordList
{
Expand Down
2 changes: 2 additions & 0 deletions src/Platforms/Keywords/PostgreSQLKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* Reserved keywords list corresponding to the PostgreSQL database platform of the oldest supported version.
*
* @deprecated
*/
class PostgreSQLKeywords extends KeywordList
{
Expand Down
2 changes: 2 additions & 0 deletions src/Platforms/Keywords/SQLServerKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* Reserved keywords list corresponding to the Microsoft SQL Server database platform of the oldest supported version.
*
* @deprecated
*/
class SQLServerKeywords extends KeywordList
{
Expand Down
2 changes: 2 additions & 0 deletions src/Platforms/Keywords/SQLiteKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* SQLite Keywordlist.
*
* @deprecated
*/
class SQLiteKeywords extends KeywordList
{
Expand Down
9 changes: 9 additions & 0 deletions src/Platforms/MariaDBPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\Deprecations\Deprecation;

use function array_diff_key;
use function array_merge;
Expand Down Expand Up @@ -158,8 +159,16 @@ public function getColumnDeclarationSQL(string $name, array $column): string
return parent::getColumnDeclarationSQL($name, $column);
}

/** @deprecated */
protected function createReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

return new MariaDBKeywords();
}
}
8 changes: 8 additions & 0 deletions src/Platforms/MySQL80Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords;
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
use Doctrine\Deprecations\Deprecation;

/**
* Provides the behavior, features and SQL dialect of the MySQL 8.0 database platform.
Expand All @@ -17,6 +18,13 @@
{
protected function createReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

Check warning on line 26 in src/Platforms/MySQL80Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MySQL80Platform.php#L21-L26

Added lines #L21 - L26 were not covered by tests

return new MySQL80Keywords();
}

Expand Down
11 changes: 11 additions & 0 deletions src/Platforms/MySQL84Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@

use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Platforms\Keywords\MySQL84Keywords;
use Doctrine\Deprecations\Deprecation;

/**
* Provides the behavior, features and SQL dialect of the MySQL 8.4 database platform.
*
* @deprecated Please use {@link MySQLPlatform} instead.
*/
class MySQL84Platform extends MySQL80Platform
{
/** @deprecated */
protected function createReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

return new MySQL84Keywords();
}
}
9 changes: 9 additions & 0 deletions src/Platforms/MySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\Deprecations\Deprecation;

/**
* Provides the behavior, features and SQL dialect of the Oracle MySQL database platform
Expand Down Expand Up @@ -42,8 +43,16 @@ protected function getRenameIndexSQL(string $oldIndexName, Index $index, string
return ['ALTER TABLE ' . $tableName . ' RENAME INDEX ' . $oldIndexName . ' TO ' . $index->getQuotedName($this)];
}

/** @deprecated */
protected function createReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

return new MySQLKeywords();
}
}
9 changes: 9 additions & 0 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\BinaryType;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;

use function array_merge;
Expand Down Expand Up @@ -785,8 +786,16 @@ public function releaseSavePoint(string $savepoint): string
return '';
}

/** @deprecated */
protected function createReservedKeywordsList(): KeywordList
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6607',
'%s is deprecated.',
__METHOD__,
);

return new OracleKeywords();
}

Expand Down
Loading