summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/database/database.inc12
-rw-r--r--includes/database/schema.inc18
-rw-r--r--modules/simpletest/simpletest.module36
-rw-r--r--modules/system/system.test6
4 files changed, 36 insertions, 36 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc
index b44846aa2..91c5ea4cb 100644
--- a/includes/database/database.inc
+++ b/includes/database/database.inc
@@ -1674,6 +1674,18 @@ function db_column_exists($table, $column) {
return Database::getActiveConnection()->schema()->columnExists($table, $column);
}
+ /**
+ * Find all tables that are like the specified base table name.
+ *
+ * @param table_expression
+ * An SQL expression, for example simpletest% . BEWARE: this is not
+ * prefixed, the caller should take care of that.
+ * @return
+ * Array, both the keys and the values are the matching tables.
+ */
+function db_find_tables($table_expression) {
+ return Database::getActiveConnection()->schema()->findTables($table_expression);
+}
/**
* Given a Schema API field type, return the correct %-placeholder.
diff --git a/includes/database/schema.inc b/includes/database/schema.inc
index 03114d2cd..391db547c 100644
--- a/includes/database/schema.inc
+++ b/includes/database/schema.inc
@@ -405,6 +405,24 @@ abstract class DatabaseSchema {
return $ret;
}
+ /**
+ * Find all tables that are like the specified base table name.
+ *
+ * @param table_expression
+ * An SQL expression, for example "simpletest%" (without the quotes).
+ * BEWARE: this is not prefixed, the caller should take care of that.
+ * @return
+ * Array, both the keys and the values are the matching tables.
+ */
+ public function findTables($table_expression) {
+ global $db_prefix;
+ $info = Database::getConnectionInfo();
+ $result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = :database AND table_name LIKE :table_name", array(
+ ':database' => $info['default']['database'],
+ ':table_name' => $table_expression,
+ ));
+ return $result->fetchAllKeyed(0, 0);
+ }
}
/**
diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module
index 3f514c664..bc51a6899 100644
--- a/modules/simpletest/simpletest.module
+++ b/modules/simpletest/simpletest.module
@@ -505,10 +505,10 @@ function simpletest_clean_environment() {
* Removed prefixed talbes from the database that are left over from crashed tests.
*/
function simpletest_clean_database() {
- $tables = simpletest_get_like_tables();
-
+ $tables = db_find_tables(Database::getActiveConnection()->prefixTables('simpletest') . '%');
+ $schema = drupal_get_schema_unprocessed('simpletest');
$ret = array();
- foreach ($tables as $table) {
+ foreach (array_diff_key($tables, $schema) as $table) {
db_drop_table($ret, $table);
}
@@ -521,36 +521,6 @@ function simpletest_clean_database() {
}
/**
- * Find all tables that are like the specified base table name.
- *
- * @param string $base_table Base table name.
- * @param boolean $count Return the table count instead of list of tables.
- * @return mixed Array of matching tables or count of tables.
- */
-function simpletest_get_like_tables($base_table = 'simpletest', $count = FALSE) {
- global $db_prefix, $database;
- $connection_info = Database::getConnectionInfo();
- $database_name = $connection_info['default']['database'];
- $select = $count ? 'COUNT(table_name)' : 'table_name';
- $result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = :database AND table_name LIKE :table_name", array(
- ':database' => $database_name,
- ':table_name' => $db_prefix . $base_table . '%',
- ));
- $schema = drupal_get_schema_unprocessed('simpletest');
-
- if ($count) {
- return db_result($result);
- }
- $tables = array();
- while ($table = db_result($result)) {
- if (!isset($schema[$table])) {
- $tables[] = $table;
- }
- }
- return $tables;
-}
-
-/**
* Find all left over temporary directories and remove them.
*/
function simpletest_clean_temporary_directories() {
diff --git a/modules/system/system.test b/modules/system/system.test
index 2aa7c9a7e..d3814aa8a 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -118,12 +118,12 @@ class EnableDisableCoreTestCase extends DrupalWebTestCase {
* @return boolean Tables with specified base table.
*/
function assertTableCount($base_table, $count) {
- $match_count = simpletest_get_like_tables($base_table, TRUE);
+ $tables = db_find_tables(Database::getActiveConnection()->prefixTables($base_table) . '%');
if ($count) {
- return $this->assertTrue($match_count, t('Tables matching "@base_table" found.', array('@base_table' => $base_table)));
+ return $this->assertTrue($tables, t('Tables matching "@base_table" found.', array('@base_table' => $base_table)));
}
- return $this->assertFalse($match_count, t('Tables matching "@base_table" not found.', array('@base_table' => $base_table)));
+ return $this->assertFalse($tables, t('Tables matching "@base_table" not found.', array('@base_table' => $base_table)));
}
/**