You are here

public function DatabaseSchema_sqlsrv::addIndex in Drupal driver for SQL Server and SQL Azure 7.3

Same name and namespace in other branches
  1. 7 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::addIndex()
  2. 7.2 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::addIndex()

Override DatabaseSchema::addIndex().

@status tested

Overrides DatabaseSchema::addIndex

3 calls to DatabaseSchema_sqlsrv::addIndex()
DatabaseSchema_sqlsrv::createPrimaryKey in sqlsrv/schema.inc
Create a Primary Key for the table, does not drop any prior primary keys neither it takes care of cleaning technical primary column. Only call this if you are sure the table does not currently hold a primary key.
DatabaseSchema_sqlsrv::createTable in sqlsrv/schema.inc
{@Inheritdoc}
DatabaseSchema_sqlsrv::recreateTableKeys in sqlsrv/schema.inc
Re-create keys associated to a table.

File

sqlsrv/schema.inc, line 1659
Database schema code for Microsoft SQL Server database servers.

Class

DatabaseSchema_sqlsrv

Code

public function addIndex($table, $name, $fields) {
  if (!$this
    ->tableExists($table, TRUE)) {
    throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add index %name to table %table: table doesn't exist.", array(
      '%table' => $table,
      '%name' => $name,
    )));
  }
  if ($this
    ->indexExists($table, $name)) {
    throw new DatabaseSchemaObjectExistsException(t("Cannot add index %name to table %table: index already exists.", array(
      '%table' => $table,
      '%name' => $name,
    )));
  }
  $xml_field = NULL;
  $sql = $this
    ->createIndexSql($table, $name, $fields, $xml_field);
  if (!empty($xml_field)) {

    // We can create an XML field, but the current primary key index
    // size needs to be under 128bytes.
    $pk_fields = $this
      ->introspectPrimaryKeyFields($table);
    $size = $this
      ->calculateClusteredIndexRowSizeBytes($table, $pk_fields, TRUE);
    if ($size > 128) {

      // Alright the compress the index.
      $this
        ->compressPrimaryKeyIndex($table, 128);
    }
  }
  $this->connection
    ->query_direct($sql);
  $this
    ->queryColumnInformationInvalidate($table);
}