You are here

protected function Schema::uniqueKeyExists in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::uniqueKeyExists()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::uniqueKeyExists()

Find if an unique key exists.

Parameters

mixed $table: Table name.

mixed $name: Index name.

Return value

bool Does the key exist?

4 calls to Schema::uniqueKeyExists()
Schema::addUniqueKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add a unique key.
Schema::changeField in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Change a field definition.
Schema::dropFieldRelatedObjects in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop the related objects of a column (indexes, constraints, etc.).
Schema::dropUniqueKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop a unique key.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 1973

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

protected function uniqueKeyExists($table, $name) {
  $prefixInfo = $this
    ->getPrefixInfo($table, TRUE);
  return (bool) $this->connection
    ->query('SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(:table) AND name = :name', [
    ':table' => $prefixInfo['table'],
    ':name' => $name . '_unique',
  ])
    ->fetchField();
}