You are here

public function DataTable::changeIndex in Data 6

Same name and namespace in other branches
  1. 7 includes/DataTable.inc \DataTable::changeIndex()

Change indexes of a table.

Throws

DataException

File

includes/DataTable.inc, line 350
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 changeIndex($fields) {
  $schema = $this->table_schema;

  // @TODO: This array_keys() reduces indexes to single field indexes.
  // Will need adjustment when multi-field indexes are implemented.
  $indexes = isset($schema['indexes']) ? array_keys($schema['indexes']) : array();
  $add = array_diff($fields, $indexes);
  $drop = array_diff($indexes, $fields);
  foreach ($add as $field) {
    $this
      ->addIndex($field);
  }
  foreach ($drop as $field) {
    $this
      ->dropIndex($field);
  }
}