function chado_add_index

2.x tripal_core.chado_schema.api.inc chado_add_index($table, $name, $fields)

A Chado-aware wrapper for the db_add_index() function.

Parameters

$table: The table to be altered.

$name: The name of the index.

$fields: An array of field names.

1 call to chado_add_index()

File

tripal_core/api/tripal_core.chado_schema.api.inc, line 186

Code

function chado_add_index($table, $name, $fields) {
  $indexname = $table . '_' . $name . '_idx';

  $query = 'CREATE INDEX "' . $indexname . '" ON {' . $table . '} ';
  $query .= '(';
  $temp = array();
  foreach ($fields as $field) {
    if (is_array($field)) {
      $temp[] = 'substr(' . $field[0] . ', 1, ' . $field[1] . ')';
    }
    else {
      $temp[] = '"' . $field . '"';
    }
  }
  $query .= implode(', ', $temp);
  $query .= ')';
  return chado_query($query);
}