diff --git a/docs/en/reference/platforms.rst b/docs/en/reference/platforms.rst index 2505680f7ce..5f57fec9226 100644 --- a/docs/en/reference/platforms.rst +++ b/docs/en/reference/platforms.rst @@ -35,6 +35,7 @@ MySQL - ``MySqlPlatform`` for version 5.0 and above. - ``MySQL57Platform`` for version 5.7 (5.7.9 GA) and above. +- ``MySQL80Platform`` for version 8.0 (8.0 GA) and above. Oracle ^^^^^^ diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index ed881052c0b..bf6e11f5f1a 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -24,6 +24,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; +use Doctrine\DBAL\Platforms\MySQL80Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\MySqlSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; @@ -137,8 +138,14 @@ public function createDatabasePlatformForVersion($version) return new MariaDb1027Platform(); } - if ( ! $mariadb && version_compare($this->getOracleMysqlVersionNumber($version), '5.7.9', '>=')) { - return new MySQL57Platform(); + if (! $mariadb) { + $oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version); + if (version_compare($oracleMysqlVersion, '8', '>=')) { + return new MySQL80Platform(); + } + if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) { + return new MySQL57Platform(); + } } return $this->getDatabasePlatform(); diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php new file mode 100644 index 00000000000..232b85cdd32 --- /dev/null +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php @@ -0,0 +1,81 @@ +. + */ + +namespace Doctrine\DBAL\Platforms\Keywords; + +use function array_merge; + +/** + * MySQL 8.0 reserved keywords list. + * + * @link www.doctrine-project.org + */ +class MySQL80Keywords extends MySQL57Keywords +{ + /** + * {@inheritdoc} + */ + public function getName() + { + return 'MySQL80'; + } + + /** + * {@inheritdoc} + * + * @link https://dev.mysql.com/doc/refman/8.0/en/keywords.html + */ + protected function getKeywords() + { + $keywords = parent::getKeywords(); + + $keywords = array_merge($keywords, [ + 'ADMIN', + 'CUBE', + 'CUME_DIST', + 'DENSE_RANK', + 'EMPTY', + 'EXCEPT', + 'FIRST_VALUE', + 'FUNCTION', + 'GROUPING', + 'GROUPS', + 'JSON_TABLE', + 'LAG', + 'LAST_VALUE', + 'LEAD', + 'NTH_VALUE', + 'NTILE', + 'OF', + 'OVER', + 'PERCENT_RANK', + 'PERSIST', + 'PERSIST_ONLY', + 'RANK', + 'RECURSIVE', + 'ROW', + 'ROWS', + 'ROW_NUMBER', + 'SYSTEM', + 'WINDOW', + ]); + + return $keywords; + } +} diff --git a/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php new file mode 100644 index 00000000000..e0727237b88 --- /dev/null +++ b/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php @@ -0,0 +1,36 @@ +. + */ + +namespace Doctrine\DBAL\Platforms; + +/** + * Provides the behavior, features and SQL dialect of the MySQL 8.0 (8.0 GA) database platform. + * + * @link www.doctrine-project.org + */ +class MySQL80Platform extends MySQL57Platform +{ + /** + * {@inheritdoc} + */ + protected function getReservedKeywordsClass() + { + return Keywords\MySQL80Keywords::class; + } +} diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 82b56241d93..83587bdb544 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -36,6 +36,7 @@ class ReservedWordsCommand extends Command private $keywordListClasses = [ 'mysql' => 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords', 'mysql57' => 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords', + 'mysql80' => 'Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords', 'sqlserver' => 'Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords', 'sqlserver2005' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2005Keywords', 'sqlserver2008' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2008Keywords', @@ -96,6 +97,7 @@ protected function configure() * mysql * mysql57 + * mysql80 * pgsql * pgsql92 * sqlite @@ -126,6 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $keywordLists = [ 'mysql', 'mysql57', + 'mysql80', 'pgsql', 'pgsql92', 'sqlite', diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index 11fd12a52fb..337a73c0e29 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; +use Doctrine\DBAL\Platforms\MySQL80Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\MySqlSchemaManager; @@ -63,6 +64,9 @@ protected function getDatabasePlatformsForVersions() : array ['5.7.8', MySqlPlatform::class], ['5.7.9', MySQL57Platform::class], ['5.7.10', MySQL57Platform::class], + ['8', MySQL80Platform::class], + ['8.0', MySQL80Platform::class], + ['8.0.11', MySQL80Platform::class], ['6', MySQL57Platform::class], ['10.0.15-MariaDB-1~wheezy', MySqlPlatform::class], ['5.5.5-10.1.25-MariaDB', MySqlPlatform::class],