You are here

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

Tries to clean up the technical primary column. It will be deleted if (a) It is not being used as the current primary key and... (b) There is no unique constraint because they depend on this column (see addUniqueKey())

Parameters

string $table:

3 calls to Schema::cleanUpTechnicalPrimaryColumn()
Schema::addPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addPrimaryKey().
Schema::cleanUpPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop the primary key constraint.
Schema::dropUniqueKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::dropUniqueKey().

File

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

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

protected function cleanUpTechnicalPrimaryColumn($table) {

  // Get the number of remaining unique indexes on the table, that
  // are not primary keys and prune the technical primary column if possible.
  $unique_indexes = $this->connection
    ->query('SELECT COUNT(*) FROM sys.indexes WHERE object_id = OBJECT_ID(:table) AND is_unique = 1 AND is_primary_key = 0', array(
    ':table' => $this->connection
      ->prefixTables('{' . $table . '}'),
  ))
    ->fetchField();
  $primary_key_is_technical = $this
    ->isTechnicalPrimaryKey($this
    ->primaryKeyName($table));
  if (!$unique_indexes && !$primary_key_is_technical) {
    $this
      ->dropField($table, $this->TECHNICAL_PK_COLUMN_NAME);
  }
}