public function DatabaseSchema_pgsql::queryFieldInformation

public DatabaseSchema_pgsql::queryFieldInformation($table, $field)

Fetch the list of CHECK constraints used on a field.

We introspect the database to collect the information required by field alteration.

Parameters

$table: The non-prefixed name of the table.

$field: The name of the field.

Return value

An array of all the checks for the field.

File

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

Class

DatabaseSchema_pgsql

Code

public function queryFieldInformation($table, $field) {
  $prefixInfo = $this->getPrefixInfo($table, TRUE);

  // Split the key into schema and table for querying.
  $schema = $prefixInfo['schema'];
  $table_name = $prefixInfo['table'];

  $field_information = (object) array(
    'checks' => array(),
  );
  $checks = $this->connection->query("SELECT conname FROM pg_class cl INNER JOIN pg_constraint co ON co.conrelid = cl.oid INNER JOIN pg_attribute attr ON attr.attrelid = cl.oid AND attr.attnum = ANY (co.conkey) INNER JOIN pg_namespace ns ON cl.relnamespace = ns.oid WHERE co.contype = 'c' AND ns.nspname = :schema AND cl.relname = :table AND attr.attname = :column", array(
    ':schema' => $schema,
    ':table' => $table_name,
    ':column' => $field,
  ));
  $field_information = $checks->fetchCol();

  return $field_information;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!database!pgsql!schema.inc/function/DatabaseSchema_pgsql::queryFieldInformation/7.x