Skip to content

Rework handling quoted object names and reserved SQL keywords #6589

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

# Upgrade to 5.0

## BC BREAK: Removed Reserved Keyword Lists

The following components have been removed:

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

Prior to this change, DBAL would automatically quote reserved keywords and, as a side effect, preserve their case
on platforms that adhere to the SQL-92 standard (i.e., preserve lowercase identifiers on Oracle and IBM DB2,
and uppercase ones on PostgreSQL).

With this change, DBAL will:
1. Normalize the case of unquoted identifiers to match the behavior of the target database platform:
- Oracle and IBM DB2 – uppercase.
- PostgreSQL – lowercase.
- All other platforms – no modification.
2. Consistently quote all identifiers in SQL, regardless of whether they are keywords or not.

To preserve lowercase identifiers on Oracle and IBM DB2 or uppercase identifiers on PostgreSQL, quote the identifiers
explicitly.

## BC BREAK: Removed `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()`

The `AbstractPlatform::quoteIdentifier()` and `Connection::quoteIdentifier()` methods have been removed.
Expand Down
34 changes: 0 additions & 34 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,6 @@
<file name="src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php"/>
</errorLevel>
</ConflictingReferenceConstraint>
<DeprecatedClass>
<errorLevel type="suppress">
<!--
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>
<errorLevel type="suppress">
<!--
Expand All @@ -73,24 +55,8 @@

<!-- TODO for PHPUnit 11 -->
<referencedMethod name="PHPUnit\Framework\TestCase::iniSet"/>

<!--
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
5 changes: 0 additions & 5 deletions src/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\DBAL\Platforms\MariaDB1010Platform;
use Doctrine\DBAL\Platforms\MariaDB1060Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL84Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\ServerVersionProvider;

Expand Down Expand Up @@ -46,10 +45,6 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs
return new MariaDBPlatform();
}

if (version_compare($version, '8.4.0', '>=')) {
return new MySQL84Platform();
}

return new MySQLPlatform();
}

Expand Down
16 changes: 0 additions & 16 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\InvalidColumnType\ColumnValuesRequired;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\MySQLSchemaManager;
use Doctrine\DBAL\Schema\TableDiff;
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 @@ -757,19 +754,6 @@ protected function initializeDoctrineTypeMappings(): void
];
}

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

return new MySQLKeywords();
}

/**
* {@inheritDoc}
*
Expand Down
34 changes: 0 additions & 34 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\Exception\NoColumnsSpecifiedForTable;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
Expand All @@ -36,7 +35,6 @@
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 @@ -74,13 +72,6 @@ abstract class AbstractPlatform
/** @var string[]|null */
protected ?array $doctrineTypeMapping = null;

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

/**
* Returns the SQL snippet that declares a boolean column.
*
Expand Down Expand Up @@ -2125,31 +2116,6 @@ public function rollbackSavePoint(string $savepoint): string
return 'ROLLBACK TO SAVEPOINT ' . $savepoint;
}

/**
* 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;

/**
* Quotes a literal string.
* This method is NOT meant to fix SQL injections!
Expand Down
16 changes: 0 additions & 16 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Platforms\Keywords\DB2Keywords;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\DB2SchemaManager;
use Doctrine\DBAL\Schema\Identifier;
Expand All @@ -18,7 +16,6 @@
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 @@ -592,19 +589,6 @@ 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();
}

public function createSchemaManager(Connection $connection): DB2SchemaManager
{
return new DB2SchemaManager($connection, $this);
Expand Down
Loading