function schema_unprefix_table in Schema 7
Same name and namespace in other branches
- 8 schema.module \schema_unprefix_table()
- 5 schema.module \schema_unprefix_table()
- 6 schema.module \schema_unprefix_table()
Unprefix a table name.
This is pretty much the converse of DatabaseConnection::prefixTables().
Parameters
string $name: The prefixed table name.
DatabaseConnection $connection: An optional database connection object.
Return value
string The unprefixed table name.
3 calls to schema_unprefix_table()
- SchemaDatabaseSchema_mysql::inspect in engines/
mysql.inc - Retrieves the schema for the database's actual structure.
- SchemaDatabaseSchema_pgsql::inspect in engines/
pgsql.inc - SchemaUnitTestCase::testUnprefixTable in tests/
schema.test
File
- ./
schema.module, line 323 - The Schema module provides functionality built on the Schema API.
Code
function schema_unprefix_table($name, $connection = NULL) {
$prefixes =& drupal_static(__FUNCTION__, array());
if (!isset($connection)) {
$connection = Database::getConnection();
}
$key = $connection
->getKey();
if (!isset($prefixes[$key])) {
$prefixes[$key] = array();
$info = $connection
->getConnectionOptions();
if (isset($info['prefix'])) {
if (is_array($info['prefix'])) {
$info['prefix'] = $info['prefix'] + array(
'default' => '',
);
}
else {
$info['prefix'] = array(
'default' => $info['prefix'],
);
}
foreach ($info['prefix'] as $table => $prefix) {
if ($table != 'default') {
$prefixes[$key][$prefix . $table] = $table;
}
elseif ($prefix !== '') {
$prefixes[$key][$prefix] = '';
}
}
}
}
return !empty($prefixes[$key]) ? strtr($name, $prefixes[$key]) : $name;
}