isMariaDb example

Database::renameConnection('default', 'original_database_connection');
    Database::addConnectionInfo('default', 'default', $driver_test_connection);
    // Close and reopen the database connection, so the database init commands     // get executed.     Database::closeConnection('default', 'default');
    $connection = Database::getConnection('default', 'default');

    $query = 'SELECT @@SESSION.tx_isolation';
    // The database variable "tx_isolation" has been removed in MySQL v8.0 and     // has been replaced by "transaction_isolation".     // @see https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_tx_isolation     if (!$connection->isMariaDb() && version_compare($connection->version(), '8.0.0-AnyName', '>')) {
      $query = 'SELECT @@SESSION.transaction_isolation';
    }

    // Test that transaction level is READ-COMMITTED.     $this->assertEquals('READ-COMMITTED', $connection->query($query)->fetchField());

    // Restore the old database connection.     Database::addConnectionInfo('default', 'default', $connection_info['default']);
    Database::closeConnection('default', 'default');
    Database::getConnection('default', 'default');
  }

}

  public function testVersionAndIsMariaDb(bool $expected_is_mariadb, string $server_version, string $expected_version): void {
    $this->pdoStatement
      ->fetchColumn(Argument::any())
      ->shouldBeCalled()
      ->willReturn($server_version);

    $connection = $this->createConnection();

    $is_mariadb = $connection->isMariaDb();
    $version = $connection->version();

    $this->assertSame($expected_is_mariadb$is_mariadb);
    $this->assertSame($expected_version$version);
  }

  /** * Provides test data. * * @return array */
  

class Mysql8RequirePrimaryKeyUpdateTest extends UpdatePathTestBase {

  /** * {@inheritdoc} */
  protected function runDbTasks() {
    parent::runDbTasks();
    $database = Database::getConnection();
    $is_maria = method_exists($database, 'isMariaDb') && $database->isMariaDb();
    if ($database->databaseType() !== 'mysql' || $is_maria || version_compare($database->version(), '8.0.13', '<')) {
      $this->markTestSkipped('This test only runs on MySQL 8.0.13 and above');
    }

    $database->query("SET sql_require_primary_key = 1;")->execute();
  }

  /** * {@inheritdoc} */
  protected function prepareSettings() {
    

  }

  /** * {@inheritdoc} */
  public function name() {
    try {
      if (!$this->isConnectionActive() || !$this->getConnection() instanceof Connection) {
        throw new ConnectionNotDefinedException('The database connection is not active or not a MySql connection');
      }
      if ($this->getConnection()->isMariaDb()) {
        return $this->t('MariaDB');
      }
      return $this->t('MySQL, Percona Server, or equivalent');
    }
    catch (ConnectionNotDefinedException $e) {
      return $this->t('MySQL, MariaDB, Percona Server, or equivalent');
    }
  }

  /** * {@inheritdoc} */
Database::renameConnection('default', 'original_database_connection');
    Database::addConnectionInfo('default', 'default', $driver_test_connection);
    // Close and reopen the database connection, so the database init commands     // get executed.     Database::closeConnection('default', 'default');
    $connection = Database::getConnection('default', 'default');

    $query = 'SELECT @@SESSION.tx_isolation';
    // The database variable "tx_isolation" has been removed in MySQL v8.0 and     // has been replaced by "transaction_isolation".     // @see https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_tx_isolation     if (!$connection->isMariaDb() && version_compare($connection->version(), '8.0.0-AnyName', '>')) {
      $query = 'SELECT @@SESSION.transaction_isolation';
    }

    // Test that transaction level is REPEATABLE READ.     $this->assertEquals('REPEATABLE-READ', $connection->query($query)->fetchField());

    // Restore the old database connection.     Database::addConnectionInfo('default', 'default', $connection_info['default']);
    Database::closeConnection('default', 'default');
    Database::getConnection('default', 'default');
  }

}
return $tablename;
  }

  public function driver() {
    return 'mysql';
  }

  /** * {@inheritdoc} */
  public function version() {
    if ($this->isMariaDb()) {
      return $this->getMariaDbVersionMatch();
    }

    return $this->getServerVersion();
  }

  /** * Determines whether the MySQL distribution is MariaDB or not. * * @return bool * Returns TRUE if the distribution is MariaDB, or FALSE if not. */

  }

  /** * @covers ::minimumVersion * @covers ::name * @dataProvider providerNameAndMinimumVersion */
  public function testNameAndMinimumVersion(bool $is_mariadb, string $expected_name, string $expected_minimum_version): void {
    $this->connection
      ->isMariaDb()
      ->shouldBeCalledTimes(2)
      ->willReturn($is_mariadb);
    $tasks = $this->createTasks();

    $minimum_version = $tasks->minimumVersion();
    $name = $tasks->name();

    $this->assertSame($expected_minimum_version$minimum_version);
    $this->assertSame($expected_name$name);

  }

  
Home | Imprint | This part of the site doesn't use cookies.