Skip to content
Snippets Groups Projects
Unverified Commit 43919219 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3089902 by Taran2L, jmlsteele, anmolgoyal74, longwave, kishor_kolekar,...

Issue #3089902 by Taran2L, jmlsteele, anmolgoyal74, longwave, kishor_kolekar, tuan.hmt, alexpott, daffie, Aron Novak, hploeger: "Azure Database for MySQL server" reports wrong database version
parent f02a7732
No related branches found
No related tags found
No related merge requests found
...@@ -197,15 +197,8 @@ public static function open(array &$connection_options = []) { ...@@ -197,15 +197,8 @@ public static function open(array &$connection_options = []) {
'init_commands' => [], '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'] += [ $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. // Execute initial commands.
...@@ -297,7 +290,11 @@ protected function getMariaDbVersionMatch(): ?string { ...@@ -297,7 +290,11 @@ protected function getMariaDbVersionMatch(): ?string {
* The PDO server version. * The PDO server version.
*/ */
protected function getServerVersion(): string { 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() { public function databaseType() {
......
...@@ -10,9 +10,17 @@ ...@@ -10,9 +10,17 @@
* *
* @coversDefaultClass \Drupal\Core\Database\Driver\mysql\Connection * @coversDefaultClass \Drupal\Core\Database\Driver\mysql\Connection
* @group Database * @group Database
* @runTestsInSeparateProcesses
*/ */
class ConnectionTest extends UnitTestCase { class ConnectionTest extends UnitTestCase {
/**
* A PDO statement prophecy.
*
* @var \PDOStatement|\Prophecy\Prophecy\ObjectProphecy
*/
private $pdoStatement;
/** /**
* A PDO object prophecy. * A PDO object prophecy.
* *
...@@ -24,6 +32,7 @@ class ConnectionTest extends UnitTestCase { ...@@ -24,6 +32,7 @@ class ConnectionTest extends UnitTestCase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setUp(): void { public function setUp(): void {
$this->pdoStatement = $this->prophesize(\PDOStatement::class);
$this->pdoConnection = $this->prophesize(\PDO::class); $this->pdoConnection = $this->prophesize(\PDO::class);
} }
...@@ -51,10 +60,16 @@ public function __construct(\PDO $connection) { ...@@ -51,10 +60,16 @@ public function __construct(\PDO $connection) {
* @dataProvider providerVersionAndIsMariaDb * @dataProvider providerVersionAndIsMariaDb
*/ */
public function testVersionAndIsMariaDb(bool $expected_is_mariadb, string $server_version, string $expected_version): void { public function testVersionAndIsMariaDb(bool $expected_is_mariadb, string $server_version, string $expected_version): void {
$this->pdoConnection $this->pdoStatement
->getAttribute(\PDO::ATTR_SERVER_VERSION) ->fetchColumn()
->shouldBeCalled() ->shouldBeCalled()
->willReturn($server_version); ->willReturn($server_version);
$this->pdoConnection
->query('SELECT VERSION()')
->shouldBeCalled()
->willReturn($this->pdoStatement->reveal());
$connection = $this->createConnection(); $connection = $this->createConnection();
$is_mariadb = $connection->isMariaDb(); $is_mariadb = $connection->isMariaDb();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment