function schema_unprefix_table in Schema 8
Same name and namespace in other branches
- 5 schema.module \schema_unprefix_table()
- 6 schema.module \schema_unprefix_table()
- 7 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()
File
- ./
schema.module, line 240 - 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;
}