You are here

function simpletest_db_find_tables in SimpleTest 6.2

Finds all tables that are like the specified base table name.

Parameters

$table_expression: An SQL expression, for example "simpletest%%" (without the quotes). BEWARE: this is not prefixed, the caller should take care of that.

Return value

Array, both the keys and the values are the matching tables.

1 call to simpletest_db_find_tables()
simpletest_clean_database in ./simpletest.module
Removed prefixed tables from the database that are left over from crashed tests.

File

./simpletest.module, line 518
Provides testing functionality.

Code

function simpletest_db_find_tables($table_expression) {
  global $db_url;

  // Get the database name.
  $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
  $database = substr($url['path'], 1);
  switch ($GLOBALS['db_type']) {
    default:
      $query = db_query("SELECT table_name FROM information_schema.tables WHERE (table_schema = '%s' OR table_catalog = '%s') AND table_name LIKE '%s'", array(
        ':table_schema' => $database,
        ':table_catalog' => $database,
        ':table_name' => $table_expression,
      ));
      break;
  }
  $tables = array();
  if (isset($query)) {
    while ($table = db_result($query)) {
      $tables[] = $table;
    }
  }
  return $tables;
}