You are here

public function Schema::addIndex in Drupal driver for SQL Server and SQL Azure 8

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::addIndex()
  2. 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::addIndex()

Override DatabaseSchema::addIndex().

@status tested

Overrides Schema::addIndex

3 calls to Schema::addIndex()
Schema::createPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
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.
Schema::createTable in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
{@Inheritdoc}
Schema::recreateTableKeys in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Re-create keys associated to a table.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 1595
Definition of Drupal\Driver\Database\sqlsrv\Schema

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function addIndex($table, $name, $fields, array $spec = array()) {
  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($sql);
}