You are here

protected function DatabaseSchema_sqlsrv::cleanUpTechnicalPrimaryColumn in Drupal driver for SQL Server and SQL Azure 7.2

Same name and namespace in other branches
  1. 7.3 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::cleanUpTechnicalPrimaryColumn()
  2. 7 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::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 DatabaseSchema_sqlsrv::cleanUpTechnicalPrimaryColumn()
DatabaseSchema_sqlsrv::addPrimaryKey in sqlsrv/schema.inc
Override DatabaseSchema::addPrimaryKey().
DatabaseSchema_sqlsrv::cleanUpPrimaryKey in sqlsrv/schema.inc
Drop the primary key constraint.
DatabaseSchema_sqlsrv::dropUniqueKey in sqlsrv/schema.inc
Override DatabaseSchema::dropUniqueKey().

File

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

Class

DatabaseSchema_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_direct('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);
  }
}