function data_safe_name

cis7 data.module data_safe_name($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()
data_build_schema in sites/all/modules/local_contrib/data/data.module
Helper function to generate a schema.

File

sites/all/modules/local_contrib/data/data.module, line 240
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);
}