You are here

public function DatabaseSchema_sqlite::findTablesD8 in Drupal 7

Finds all tables that are like the specified base table name. This is a backport of the change made to findTables in Drupal 8 to work with virtual, un-prefixed table names. The original function is retained for Backwards Compatibility.

Parameters

string $table_expression: An SQL expression, for example "cache_%" (without the quotes).

Return value

array Both the keys and the values are the matching tables.

Overrides DatabaseSchema::findTablesD8

See also

https://www.drupal.org/node/2552435

File

includes/database/sqlite/schema.inc, line 690
Database schema code for SQLite databases.

Class

DatabaseSchema_sqlite

Code

public function findTablesD8($table_expression) {
  $tables = array();

  // The SQLite implementation doesn't need to use the same filtering strategy
  // as the parent one because individually prefixed tables live in their own
  // schema (database), which means that neither the main database nor any
  // attached one will contain a prefixed table name, so we just need to loop
  // over all known schemas and filter by the user-supplied table expression.
  $attached_dbs = $this->connection
    ->getAttachedDatabases();
  foreach ($attached_dbs as $schema) {

    // Can't use query placeholders for the schema because the query would
    // have to be :prefixsqlite_master, which does not work. We also need to
    // ignore the internal SQLite tables.
    $result = db_query("SELECT name FROM " . $schema . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", array(
      ':type' => 'table',
      ':table_name' => $table_expression,
      ':pattern' => 'sqlite_%',
    ));
    $tables += $result
      ->fetchAllKeyed(0, 0);
  }
  return $tables;
}