function data_safe_name in Data 6
Same name and namespace in other branches
- 8 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.
1 call to data_safe_name()
- DataTestCaseUI::randomFields in data_ui/
tests/ data_ui.test - Generate N random fields. Will create at least 1 field.
File
- ./
data.module, line 267 - 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 db_escape_table($simple);
}