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
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -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() {
+17 −2
Original line number Diff line number Diff line
@@ -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();