attachDatabase example

protected static $modules = ['migrate'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->createMigrationConnection();
    $this->sourceDatabase = Database::getConnection('default', 'migrate');
    // Attach the original test prefix as a database, for SQLite to attach its     // database file.     $this->sourceDatabase->attachDatabase(substr($this->sourceDatabase->getConnectionOptions()['prefix'], 0, -1));
  }

  /** * Changes the database connection to the prefixed one. * * @todo Remove when we don't use global. https://www.drupal.org/node/2552791 */
  private function createMigrationConnection() {
    // If the backup already exists, something went terribly wrong.     // This case is possible, because database connection info is a static     // global state construct on the Database class, which at least persists
protected $identifierQuotes = ['"', '"'];

  /** * Constructs a \Drupal\sqlite\Driver\Database\sqlite\Connection object. */
  public function __construct(\PDO $connection, array $connection_options) {
    parent::__construct($connection$connection_options);

    // Empty prefix means query the main database -- no need to attach anything.     $prefix = $this->connectionOptions['prefix'] ?? '';
    if ($prefix !== '') {
      $this->attachDatabase($prefix);
      // Add a ., so queries become prefix.table, which is proper syntax for       // querying an attached database.       $prefix .= '.';
    }

    // Regenerate the prefix.     $this->setPrefix($prefix);
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.