function DatabaseSchema_pgsql::fieldExists

Check if a column exists in the given table.

Parameters

$table: The name of the table in drupal (no prefixing).

$name: The name of the column.

Return value

TRUE if the given column exists, otherwise FALSE.

Overrides DatabaseSchema::fieldExists

5 calls to DatabaseSchema_pgsql::fieldExists()
DatabaseSchema_pgsql::addField in includes/database/pgsql/schema.inc
Add a new field to a table.
DatabaseSchema_pgsql::changeField in includes/database/pgsql/schema.inc
Change a field definition.
DatabaseSchema_pgsql::dropField in includes/database/pgsql/schema.inc
Drop a field.
DatabaseSchema_pgsql::fieldSetDefault in includes/database/pgsql/schema.inc
Set the default value for a field.
DatabaseSchema_pgsql::fieldSetNoDefault in includes/database/pgsql/schema.inc
Set a field to have no default value.

File

includes/database/pgsql/schema.inc, line 605

Class

DatabaseSchema_pgsql

Code

public function fieldExists($table, $column) {
  // In PostgreSQL "unquoted names are always folded to lower case."
  // @see DatabaseSchema_pgsql::buildTableNameCondition().
  $prefixInfo = $this->getPrefixInfo(strtolower($table));
  return (bool) $this->connection
    ->query("SELECT 1 FROM pg_attribute WHERE attrelid = :key::regclass AND attname = :column AND NOT attisdropped AND attnum > 0", array(
    ':key' => $prefixInfo['schema'] . '.' . $prefixInfo['table'],
    ':column' => $column,
  ))
    ->fetchField();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.