You are here

protected function DatabaseSchema_pgsql::constraintExists in Drupal 7

Helper function: check if a constraint (PK, FK, UK) exists.

Parameters

$table: The name of the table.

$name: The name of the constraint (typically 'pkey' or '[constraint]_key').

4 calls to DatabaseSchema_pgsql::constraintExists()
DatabaseSchema_pgsql::addPrimaryKey in includes/database/pgsql/schema.inc
Add a primary key.
DatabaseSchema_pgsql::addUniqueKey in includes/database/pgsql/schema.inc
Add a unique key.
DatabaseSchema_pgsql::dropPrimaryKey in includes/database/pgsql/schema.inc
Drop the primary key.
DatabaseSchema_pgsql::dropUniqueKey in includes/database/pgsql/schema.inc
Drop a unique key.

File

includes/database/pgsql/schema.inc, line 431
Database schema code for PostgreSQL database servers.

Class

DatabaseSchema_pgsql

Code

protected function constraintExists($table, $name) {
  $constraint_name = '{' . $table . '}_' . $name;
  return (bool) $this->connection
    ->query("SELECT 1 FROM pg_constraint WHERE conname = '{$constraint_name}'")
    ->fetchField();
}