diff --git a/docs/en/reference/platforms.rst b/docs/en/reference/platforms.rst index da78e394f22..b216c61c939 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 and above. +- ``MySQL578Platform`` for version 5.7.8 and above. Oracle ^^^^^^ diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index eff79576291..5ee047797fd 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -22,6 +22,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\MySQL578Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\MySqlSchemaManager; @@ -136,6 +137,10 @@ public function createDatabasePlatformForVersion($version) $patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion; + if (version_compare($version, '5.7.8', '>=')) { + return new MySQL578Platform(); + } + if (version_compare($version, '5.7', '>=')) { return new MySQL57Platform(); } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL578Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL578Keywords.php new file mode 100644 index 00000000000..13a3a26d6e7 --- /dev/null +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL578Keywords.php @@ -0,0 +1,57 @@ +. + */ + +namespace Doctrine\DBAL\Platforms\Keywords; + +/** + * MySQL 5.7.8 reserved keywords list. + * + * @author İsmail BASKIN + * @link www.doctrine-project.org + * @since 2.6 + */ +class MySQL578Keywords extends MySQL57Keywords +{ + /** + * {@inheritdoc} + */ + public function getName() + { + return 'MySQL578'; + } + + /** + * {@inheritdoc} + * + * @link https://dev.mysql.com/doc/refman/5.7/en/keywords.html + */ + protected function getKeywords() + { + $parentKeywords = array_diff(parent::getKeywords(), array( + 'NONBLOCKING', + )); + + return array_merge($parentKeywords, array( + 'GENERATED', + 'OPTIMIZER_COSTS', + 'STORED', + 'VIRTUAL' + )); + } +} diff --git a/lib/Doctrine/DBAL/Platforms/MySQL578Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL578Platform.php new file mode 100644 index 00000000000..6857f4d6c08 --- /dev/null +++ b/lib/Doctrine/DBAL/Platforms/MySQL578Platform.php @@ -0,0 +1,64 @@ +. + */ + +namespace Doctrine\DBAL\Platforms; + +/** + * Provides the behavior, features and SQL dialect of the MySQL >=5.7.8 database platform. + * Extends for json support >=5.7.8 version + * + * @author İsmail BASKIN + * @link www.doctrine-project.org + * @since 2.6 + */ +class MySQL578Platform extends MySQL57Platform +{ + /** + * {@inheritdoc} + */ + protected function initializeDoctrineTypeMappings() + { + parent::initializeDoctrineTypeMappings(); + $this->doctrineTypeMapping['json'] = 'json_array'; + } + + /** + * {@inheritdoc} + */ + public function hasNativeJsonType() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function getJsonTypeDeclarationSQL(array $field) + { + return 'JSON'; + } + + /** + * {@inheritdoc} + */ + protected function getReservedKeywordsClass() + { + return 'Doctrine\DBAL\Platforms\Keywords\MySQL578Keywords'; + } +} diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index f7acd0a86ee..a726543a177 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -33,6 +33,7 @@ class ReservedWordsCommand extends Command private $keywordListClasses = array( 'mysql' => 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords', 'mysql57' => 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords', + 'mysql578' => 'Doctrine\DBAL\Platforms\Keywords\MySQL578Keywords', 'sqlserver' => 'Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords', 'sqlserver2005' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2005Keywords', 'sqlserver2008' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2008Keywords', diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index a680f5b3b3d..2d1f2dd817f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -59,7 +59,8 @@ protected function getDatabasePlatformsForVersions() array('5.7', 'Doctrine\DBAL\Platforms\MySQL57Platform'), array('5.7.0', 'Doctrine\DBAL\Platforms\MySQL57Platform'), array('5.7.1', 'Doctrine\DBAL\Platforms\MySQL57Platform'), - array('6', 'Doctrine\DBAL\Platforms\MySQL57Platform'), + array('5.7.8', 'Doctrine\DBAL\Platforms\MySQL578Platform'), + array('6', 'Doctrine\DBAL\Platforms\MySQL578Platform'), array('10.0.15-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'), array('10.1.2a-MariaDB-a1~lenny-log', 'Doctrine\DBAL\Platforms\MySqlPlatform'), array('5.5.40-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'), diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL578PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL578PlatformTest.php new file mode 100644 index 00000000000..2bc0a4673b3 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL578PlatformTest.php @@ -0,0 +1,41 @@ +assertTrue($this->_platform->hasNativeJsonType()); + } + + /** + * @group DBAL-553 + */ + public function testReturnsJsonTypeDeclarationSQL() + { + $this->assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array())); + } + + /** + * @group DBAL-553 + */ + public function testInitializesJsonTypeMapping() + { + $this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); + $this->assertEquals('json_array', $this->_platform->getDoctrineTypeMapping('json')); + } +}