You are here

public function Schema::addPrimaryKey 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::addPrimaryKey()
  2. 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::addPrimaryKey()

Override DatabaseSchema::addPrimaryKey().

@status tested

Overrides Schema::addPrimaryKey

1 call to Schema::addPrimaryKey()
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 1417
Definition of Drupal\Driver\Database\sqlsrv\Schema

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function addPrimaryKey($table, $fields) {
  if (!$this
    ->tableExists($table, TRUE)) {
    throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add primary key to table %table: table doesn't exist.", array(
      '%table' => $table,
    )));
  }
  if ($primary_key_name = $this
    ->primaryKeyName($table)) {
    if ($this
      ->isTechnicalPrimaryKey($primary_key_name)) {

      // Destroy the existing technical primary key.
      $this->connection
        ->query_direct('ALTER TABLE [{' . $table . '}] DROP CONSTRAINT [' . $primary_key_name . ']');
      $this
        ->cleanUpTechnicalPrimaryColumn($table);
    }
    else {
      throw new DatabaseSchemaObjectExistsException(t("Cannot add primary key to table %table: primary key already exists.", array(
        '%table' => $table,
      )));
    }
  }

  // The size limit of the primary key depends on the
  // cohexistance with an XML field.
  if ($this
    ->tableHasXmlIndex($table)) {
    $this
      ->createPrimaryKey($table, $fields, 128);
  }
  else {
    $this
      ->createPrimaryKey($table, $fields);
  }
  return TRUE;
}