function chado_column_exists

2.x chado_column_exists($table, $column)

Check that any given column in a Chado table exists.

This function is necessary because Drupal's db_field_exists() will not look in any other schema but the one were Drupal is installed


$table: The name of the chado table.

$column: The name of the column in the chado table.

Return value

TRUE if the column exists for the table in the chado schema and FALSE if it does not.

Related topics

1 call to chado_column_exists()
tripal_core_upgrade_chado_1_2_to_1_3_pre_alter in tripal_core/includes/
Upgrade custom tables that may match the tables now in Chado v1.3.


tripal_core/api/, line 84


function chado_column_exists($table, $column) {
  global $databases;

  $default_db = $databases['default']['default']['database'];

  $sql = "
    SELECT 1
    FROM information_schema.columns
      table_name = :table_name AND
      column_name = :column_name AND
      table_schema = :chado AND
      table_catalog = :default_db
  $args = array(
    ':table_name' => $table,
    ':column_name' => $column,
    ':chado' => tripal_get_schema_name('chado'),
    ':default_db' => $default_db
  $results = db_query($sql, $args);
  $exists = $results->fetchField();
  if (!$exists) {
    return FALSE;
  return TRUE;