Loading core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +6 −9 Original line number Diff line number Diff line Loading @@ -197,15 +197,8 @@ public static function open(array &$connection_options = []) { 'init_commands' => [], ]; $sql_mode = 'ANSI,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,ONLY_FULL_GROUP_BY'; // NO_AUTO_CREATE_USER is removed in MySQL 8.0.11 // https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-11.html#mysqld-8-0-11-deprecation-removal $version_server = $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION); if (version_compare($version_server, '8.0.11', '<')) { $sql_mode .= ',NO_AUTO_CREATE_USER'; } $connection_options['init_commands'] += [ 'sql_mode' => "SET sql_mode = '$sql_mode'", 'sql_mode' => "SET sql_mode = 'ANSI,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,ONLY_FULL_GROUP_BY'", ]; // Execute initial commands. Loading Loading @@ -297,7 +290,11 @@ protected function getMariaDbVersionMatch(): ?string { * The PDO server version. */ protected function getServerVersion(): string { return $this->connection->getAttribute(\PDO::ATTR_SERVER_VERSION); static $server_version; if (!$server_version) { $server_version = $this->connection->query('SELECT VERSION()')->fetchColumn(); } return $server_version; } public function databaseType() { Loading core/tests/Drupal/Tests/Core/Database/Driver/mysql/ConnectionTest.php +17 −2 Original line number Diff line number Diff line Loading @@ -10,9 +10,17 @@ * * @coversDefaultClass \Drupal\Core\Database\Driver\mysql\Connection * @group Database * @runTestsInSeparateProcesses */ class ConnectionTest extends UnitTestCase { /** * A PDO statement prophecy. * * @var \PDOStatement|\Prophecy\Prophecy\ObjectProphecy */ private $pdoStatement; /** * A PDO object prophecy. * Loading @@ -24,6 +32,7 @@ class ConnectionTest extends UnitTestCase { * {@inheritdoc} */ public function setUp(): void { $this->pdoStatement = $this->prophesize(\PDOStatement::class); $this->pdoConnection = $this->prophesize(\PDO::class); } Loading Loading @@ -51,10 +60,16 @@ public function __construct(\PDO $connection) { * @dataProvider providerVersionAndIsMariaDb */ public function testVersionAndIsMariaDb(bool $expected_is_mariadb, string $server_version, string $expected_version): void { $this->pdoConnection ->getAttribute(\PDO::ATTR_SERVER_VERSION) $this->pdoStatement ->fetchColumn() ->shouldBeCalled() ->willReturn($server_version); $this->pdoConnection ->query('SELECT VERSION()') ->shouldBeCalled() ->willReturn($this->pdoStatement->reveal()); $connection = $this->createConnection(); $is_mariadb = $connection->isMariaDb(); Loading Loading
core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +6 −9 Original line number Diff line number Diff line Loading @@ -197,15 +197,8 @@ public static function open(array &$connection_options = []) { 'init_commands' => [], ]; $sql_mode = 'ANSI,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,ONLY_FULL_GROUP_BY'; // NO_AUTO_CREATE_USER is removed in MySQL 8.0.11 // https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-11.html#mysqld-8-0-11-deprecation-removal $version_server = $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION); if (version_compare($version_server, '8.0.11', '<')) { $sql_mode .= ',NO_AUTO_CREATE_USER'; } $connection_options['init_commands'] += [ 'sql_mode' => "SET sql_mode = '$sql_mode'", 'sql_mode' => "SET sql_mode = 'ANSI,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,ONLY_FULL_GROUP_BY'", ]; // Execute initial commands. Loading Loading @@ -297,7 +290,11 @@ protected function getMariaDbVersionMatch(): ?string { * The PDO server version. */ protected function getServerVersion(): string { return $this->connection->getAttribute(\PDO::ATTR_SERVER_VERSION); static $server_version; if (!$server_version) { $server_version = $this->connection->query('SELECT VERSION()')->fetchColumn(); } return $server_version; } public function databaseType() { Loading
core/tests/Drupal/Tests/Core/Database/Driver/mysql/ConnectionTest.php +17 −2 Original line number Diff line number Diff line Loading @@ -10,9 +10,17 @@ * * @coversDefaultClass \Drupal\Core\Database\Driver\mysql\Connection * @group Database * @runTestsInSeparateProcesses */ class ConnectionTest extends UnitTestCase { /** * A PDO statement prophecy. * * @var \PDOStatement|\Prophecy\Prophecy\ObjectProphecy */ private $pdoStatement; /** * A PDO object prophecy. * Loading @@ -24,6 +32,7 @@ class ConnectionTest extends UnitTestCase { * {@inheritdoc} */ public function setUp(): void { $this->pdoStatement = $this->prophesize(\PDOStatement::class); $this->pdoConnection = $this->prophesize(\PDO::class); } Loading Loading @@ -51,10 +60,16 @@ public function __construct(\PDO $connection) { * @dataProvider providerVersionAndIsMariaDb */ public function testVersionAndIsMariaDb(bool $expected_is_mariadb, string $server_version, string $expected_version): void { $this->pdoConnection ->getAttribute(\PDO::ATTR_SERVER_VERSION) $this->pdoStatement ->fetchColumn() ->shouldBeCalled() ->willReturn($server_version); $this->pdoConnection ->query('SELECT VERSION()') ->shouldBeCalled() ->willReturn($this->pdoStatement->reveal()); $connection = $this->createConnection(); $is_mariadb = $connection->isMariaDb(); Loading