You are here

public function DatabaseSchema_sqlsrv::introspectPrimaryKeyFields 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::introspectPrimaryKeyFields()

Get the list of fields participating in the Primary Key

Parameters

string $table:

string $field:

Return value

string[]

3 calls to DatabaseSchema_sqlsrv::introspectPrimaryKeyFields()
DatabaseSchema_sqlsrv::addIndex in sqlsrv/schema.inc
Override DatabaseSchema::addIndex().
DatabaseSchema_sqlsrv::changeField in sqlsrv/schema.inc
Override DatabaseSchema::changeField().
DatabaseSchema_sqlsrv::compressPrimaryKeyIndex in sqlsrv/schema.inc
Sometimes the size of a table's primary key index needs to be reduced to allow for Primary XML Indexes.

File

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

Class

DatabaseSchema_sqlsrv

Code

public function introspectPrimaryKeyFields($table) {
  $data = $this
    ->queryColumnInformation($table, TRUE);

  // All primary keys have a default index,
  // use that to see if we have a primary key
  // before iterating.
  if (!isset($data['primary_key_index']) || !isset($data['indexes'][$data['primary_key_index']])) {
    return array();
  }
  $result = array();
  $index = $data['indexes'][$data['primary_key_index']];
  foreach ($index['columns'] as $column) {
    if ($column['name'] != $this->COMPUTED_PK_COLUMN_NAME) {
      $result[$column['name']] = $column['name'];
    }

    // Get full column definition
    $c = $data['columns'][$column['name']];

    // If this column depends on other columns
    // the other columns are also part of the index!
    // We don't support nested computed columns here.
    foreach ($c['dependencies'] as $name => $order) {
      $result[$name] = $name;
    }
  }
  return $result;
}