Unverified Commit d69366ff authored by alexpott's avatar alexpott

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

(cherry picked from commit 43919219)
parent 563d6cb5
......@@ -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.
......@@ -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() {
......
......@@ -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.
*
......@@ -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);
}
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment