public function DataTable::addUniqueKey in Data 6
Same name and namespace in other branches
- 7 includes/DataTable.inc \DataTable::addUniqueKey()
 
Add a unique key to a field.
Throws
File
- includes/
DataTable.inc, line 311  - Contains class definition for DataTable.
 
Class
- DataTable
 - Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.
 
Code
public function addUniqueKey($field) {
  $schema = $this->table_schema;
  if ($schema['fields'][$field]) {
    $ret = array();
    $index = data_get_index_definition($field, $schema['fields'][$field]);
    db_add_unique_key($ret, $this->name, $field, $index);
    if ($ret[0]['success']) {
      $schema['unique keys'][$field] = array(
        $field,
      );
      $this
        ->update(array(
        'table_schema' => $schema,
      ));
      drupal_get_schema($this->name, TRUE);
      return;
    }
  }
  throw new DataException(t('Error adding unique key.'));
}