You are here

public function Connection::attachDatabase in Drupal 10

1 call to Connection::attachDatabase()
Connection::__construct in core/modules/sqlite/src/Driver/Database/sqlite/Connection.php
Constructs a \Drupal\sqlite\Driver\Database\sqlite\Connection object.

File

core/modules/sqlite/src/Driver/Database/sqlite/Connection.php, line 197

Class

Connection
SQLite implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\sqlite\Driver\Database\sqlite

Code

public function attachDatabase(string $database) : void {

  // Only attach the database once.
  if (!isset($this->attachedDatabases[$database])) {

    // In memory database use ':memory:' as database name. According to
    // http://www.sqlite.org/inmemorydb.html it will open a unique database so
    // attaching it twice is not a problem.
    $database_file = $this->connectionOptions['database'] !== ':memory:' ? $this->connectionOptions['database'] . '-' . $database : $this->connectionOptions['database'];
    $this
      ->query('ATTACH DATABASE :database_file AS :database', [
      ':database_file' => $database_file,
      ':database' => $database,
    ]);
    $this->attachedDatabases[$database] = $database;
  }
}