Skip to content
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

Add MySQL 8 reserved keywords #3128

Merged
merged 1 commit into from
Jun 8, 2018
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
1 change: 1 addition & 0 deletions docs/en/reference/platforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^
Expand Down
11 changes: 9 additions & 2 deletions lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
81 changes: 81 additions & 0 deletions lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

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;
}
}
36 changes: 36 additions & 0 deletions lib/Doctrine/DBAL/Platforms/MySQL80Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -96,6 +97,7 @@ protected function configure()

* mysql
* mysql57
* mysql80
* pgsql
* pgsql92
* sqlite
Expand Down Expand Up @@ -126,6 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$keywordLists = [
'mysql',
'mysql57',
'mysql80',
'pgsql',
'pgsql92',
'sqlite',
Expand Down
4 changes: 4 additions & 0 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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],
Expand Down