function chado_add_index

2.x tripal_core.chado_schema.api.inc chado_add_index($table, $name, $fields)
3.x tripal_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()
tripal_phylogeny_install in legacy/tripal_phylogeny/tripal_phylogeny.install
Implements hook_install().

File

tripal_chado/api/tripal_chado.schema.api.inc, line 228
Provides an application programming interface (API) for describing Chado tables.

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);
}