function data_safe_name in Data 8
Same name and namespace in other branches
- 6 data.module \data_safe_name()
- 7 data.module \data_safe_name()
Create a safe name for MySQL field or table names.
@todo: IMPROVE.
- make sure all unsafe characters are removed.
- filter magic words.
- test pgsql.
File
- ./
data.module, line 211 - Hooks and API functions for data module.
Code
function data_safe_name($name) {
$map = array(
'.' => '_',
':' => '',
'/' => '',
'-' => '_',
' ' => '_',
',' => '_',
);
$simple = trim(strtolower(strip_tags($name)));
// Limit length to 64 as per http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
$simple = substr(strtr($simple, $map), 0, 64);
if (is_numeric($simple)) {
// We need to escape numerics because Drupal's drupal_write_record()
// does not properly escape token MYSQL names.
$simple = '__num_' . $simple;
}
return Database::getConnection()
->escapeTable($simple);
}