protected function Schema::findPrimaryKeyColumns in Drupal driver for SQL Server and SQL Azure 3.1.x
Same name and namespace in other branches
- 4.2.x src/Driver/Database/sqlsrv/Schema.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Schema::findPrimaryKeyColumns()
- 4.0.x src/Driver/Database/sqlsrv/Schema.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Schema::findPrimaryKeyColumns()
- 4.1.x src/Driver/Database/sqlsrv/Schema.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Schema::findPrimaryKeyColumns()
Finds the primary key columns of a table, from the database.
Parameters
string $table: The name of the table.
Return value
string[]|false A simple array with the names of the columns composing the table's primary key, or FALSE if the table does not exist.
Throws
\RuntimeException If the driver does not override this method.
Overrides Schema::findPrimaryKeyColumns
4 calls to Schema::findPrimaryKeyColumns()
- Schema::addField in src/
Driver/ Database/ sqlsrv/ Schema.php - Add a new field to a table.
- Schema::changeField in src/
Driver/ Database/ sqlsrv/ Schema.php - Change a field definition.
- Schema::dropField in src/
Driver/ Database/ sqlsrv/ Schema.php - Should this be in a Transaction?
- Schema::introspectIndexSchema in src/
Driver/ Database/ sqlsrv/ Schema.php - Finds the columns for the primary key, unique keys and indexes of a table.
File
- src/
Driver/ Database/ sqlsrv/ Schema.php, line 455
Class
Namespace
Drupal\sqlsrv\Driver\Database\sqlsrvCode
protected function findPrimaryKeyColumns($table) {
if (!$this
->tableExists($table)) {
return FALSE;
}
// Use already prefixed table name.
$prefixInfo = $this
->getPrefixInfo($table, TRUE);
$query = "SELECT column_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC " . "INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KU " . "ON TC.CONSTRAINT_TYPE = 'PRIMARY KEY' AND " . "TC.CONSTRAINT_NAME = KU.CONSTRAINT_NAME AND " . "KU.table_name=:table AND column_name != '__pk' AND column_name != '__pkc' " . "ORDER BY KU.ORDINAL_POSITION";
$result = $this->connection
->query($query, [
':table' => $prefixInfo['table'],
])
->fetchAllAssoc('column_name');
return array_keys($result);
}