From f4381c58c97e1ef6127085fd091dbdfa48d6b562 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Steve=20M=C3=BCller?= <st.mueller@dzh-online.de>
Date: Thu, 9 Feb 2017 23:34:52 +0100
Subject: [PATCH] merge MySQL 5.7.9 (GA) semantics into MySQL57Platform

---
 docs/en/reference/platforms.rst               |  2 +-
 .../DBAL/Driver/AbstractMySQLDriver.php       | 11 +++++--
 .../Platforms/Keywords/MySQL57Keywords.php    |  5 +++-
 .../DBAL/Platforms/MySQL57Platform.php        | 29 ++++++++++++++++++-
 .../DBAL/Driver/AbstractMySQLDriverTest.php   |  6 ++--
 .../DBAL/Platforms/MySQL57PlatformTest.php    | 16 ++++++++++
 6 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/docs/en/reference/platforms.rst b/docs/en/reference/platforms.rst
index da78e394f..8827842c4 100644
--- a/docs/en/reference/platforms.rst
+++ b/docs/en/reference/platforms.rst
@@ -34,7 +34,7 @@ MySQL
 ^^^^^
 
 -  ``MySqlPlatform`` for version 5.0 and above.
--  ``MySQL57Platform`` for version 5.7 and above.
+-  ``MySQL57Platform`` for version 5.7 (5.7.9 GA) and above.
 
 Oracle
 ^^^^^^
diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
index dd74a48fa..86fb00b92 100644
--- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
+++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
@@ -138,10 +138,15 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
 
         $majorVersion = $versionParts['major'];
         $minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
-        $patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
-        $version      = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
+        $patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : null;
 
-        if (version_compare($version, '5.7', '>=')) {
+        if ('5' === $majorVersion && '7' === $minorVersion && null === $patchVersion) {
+            $patchVersion = '9';
+        }
+
+        $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
+
+        if (version_compare($version, '5.7.9', '>=')) {
             return new MySQL57Platform();
         }
 
diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php
index 7d7b20208..ae2f5bc73 100644
--- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php
+++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php
@@ -119,6 +119,7 @@ class MySQL57Keywords extends MySQLKeywords
             'FOREIGN',
             'FROM',
             'FULLTEXT',
+            'GENERATED',
             'GET',
             'GRANT',
             'GROUP',
@@ -183,12 +184,12 @@ class MySQL57Keywords extends MySQLKeywords
             'MODIFIES',
             'NATURAL',
             'NO_WRITE_TO_BINLOG',
-            'NONBLOCKING',
             'NOT',
             'NULL',
             'NUMERIC',
             'ON',
             'OPTIMIZE',
+            'OPTIMIZER_COSTS',
             'OPTION',
             'OPTIONALLY',
             'OR',
@@ -240,6 +241,7 @@ class MySQL57Keywords extends MySQLKeywords
             'SQLWARNING',
             'SSL',
             'STARTING',
+            'STORED',
             'STRAIGHT_JOIN',
             'TABLE',
             'TERMINATED',
@@ -268,6 +270,7 @@ class MySQL57Keywords extends MySQLKeywords
             'VARCHAR',
             'VARCHARACTER',
             'VARYING',
+            'VIRTUAL',
             'WHEN',
             'WHERE',
             'WHILE',
diff --git a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php
index 36b525e20..8594aa651 100644
--- a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php
+++ b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php
@@ -23,14 +23,31 @@ use Doctrine\DBAL\Schema\Index;
 use Doctrine\DBAL\Schema\TableDiff;
 
 /**
- * Provides the behavior, features and SQL dialect of the MySQL 5.7 database platform.
+ * Provides the behavior, features and SQL dialect of the MySQL 5.7 (5.7.9 GA) database platform.
  *
+ * @author Ä°smail BASKIN <ismailbaskin1@gmail.com>
  * @author Steve MĂĽller <st.mueller@dzh-online.de>
  * @link   www.doctrine-project.org
  * @since  2.5
  */
 class MySQL57Platform extends MySqlPlatform
 {
+    /**
+     * {@inheritdoc}
+     */
+    public function hasNativeJsonType()
+    {
+        return true;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getJsonTypeDeclarationSQL(array $field)
+    {
+        return 'JSON';
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -64,4 +81,14 @@ class MySQL57Platform extends MySqlPlatform
     {
         return 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords';
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function initializeDoctrineTypeMappings()
+    {
+        parent::initializeDoctrineTypeMappings();
+
+        $this->doctrineTypeMapping['json'] = 'json_array';
+    }
 }
diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
index 83e15cf95..25833fcce 100644
--- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
+++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
@@ -57,8 +57,10 @@ class AbstractMySQLDriverTest extends AbstractDriverTest
         return array(
             array('5.6.9', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
             array('5.7', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
-            array('5.7.0', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
-            array('5.7.1', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
+            array('5.7.0', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
+            array('5.7.8', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
+            array('5.7.9', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
+            array('5.7.10', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
             array('6', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
             array('10.0.15-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
             array('10.1.2a-MariaDB-a1~lenny-log', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php
index 2fb87070d..64c3eb3bc 100644
--- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php
+++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php
@@ -14,6 +14,22 @@ class MySQL57PlatformTest extends AbstractMySQLPlatformTestCase
         return new MySQL57Platform();
     }
 
+    public function testHasNativeJsonType()
+    {
+        $this->assertTrue($this->_platform->hasNativeJsonType());
+    }
+
+    public function testReturnsJsonTypeDeclarationSQL()
+    {
+        $this->assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array()));
+    }
+
+    public function testInitializesJsonTypeMapping()
+    {
+        $this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('json'));
+        $this->assertSame('json_array', $this->_platform->getDoctrineTypeMapping('json'));
+    }
+
     /**
      * @group DBAL-234
      */
-- 
2.21.0