diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index 1b32458..e1eb459 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -169,6 +169,18 @@ public function __destruct() { } /** + * Gets all the attached databases. + * + * @return array + * An array of attached database names. + * + * @see \Drupal\Core\Database\Driver\sqlite\Connection::__construct() + */ + public function getAttachedDatabases() { + return $this->attachedDatabases; + } + + /** * SQLite compatibility implementation for the IF() SQL function. */ public static function sqlFunctionIf($condition, $expr1, $expr2 = NULL) { diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php index 7f7ff2d..9130620 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php @@ -696,17 +696,27 @@ public function fieldSetNoDefault($table, $field) { $this->alterTable($table, $old_schema, $new_schema); } + /** + * {@inheritdoc} + */ public function findTables($table_expression) { - $info = $this->getPrefixInfo($table_expression); - - // 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 " . $info['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_%', - )); - return $result->fetchAllKeyed(0, 0); + $tables = []; + + // Try to find tables in all attached databases. + $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; } + } diff --git a/core/modules/system/src/Tests/Database/SchemaTest.php b/core/modules/system/src/Tests/Database/SchemaTest.php index 4511320..fb5a1c2 100644 --- a/core/modules/system/src/Tests/Database/SchemaTest.php +++ b/core/modules/system/src/Tests/Database/SchemaTest.php @@ -733,7 +733,6 @@ public function testFindTables() { // Check the "all tables" syntax. $tables = Database::getConnection()->schema()->findTables('%'); sort($tables); - debug($tables); $expected = [ // The 'config' table is added by // \Drupal\simpletest\KernelTestBase::containerBuild().