function chado_sequence_exists

2.x tripal_core.chado_schema.api.inc chado_sequence_exists($sequence)
3.x tripal_chado.schema.api.inc chado_sequence_exists($sequence)

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

Parameters

sequence: The name of the sequence

Return value

TRUE if the seqeuence exists in the chado schema and FALSE if it does not.

Related topics

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

File

tripal_core/api/tripal_core.chado_schema.api.inc, line 125

Code

function chado_sequence_exists($sequence) {
  global $databases;

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

  $sql = "
    SELECT 1
    FROM information_schema.sequences
    WHERE
      sequence_name = :sequence_name AND
      sequence_schema = :sequence_schema AND
      sequence_catalog = :sequence_catalog
  ";
  $args = array(
    ':sequence_name' => $sequence,
    ':sequence_schema' => tripal_get_schema_name('chado'),
    ':sequence_catalog' => $default_db
  );
  $results = db_query($sql, $args);
  $exists = $results->fetchField();
  if (!$exists) {
    return FALSE;
  }
  return TRUE;
}