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_chado_upgrade_chado_1_2_to_1_3_pre_alter in tripal_chado/
includes/ tripal_chado.install.inc - Upgrade custom tables that may match the tables now in Chado v1.3.
File
- tripal_chado/
api/ tripal_chado.schema.api.inc, line 159 - Provides an application programming interface (API) for describing Chado tables.
Code
function chado_sequence_exists($sequence) {
global $databases;
$default_db = $databases['default']['default']['database'];
$cached_obj = cache_get('chado_sequences', 'cache');
$cached_seqs = $cached_obj->data;
if (is_array($cached_seqs) and array_key_exists($sequence, $cached_seqs)) {
return $cached_seqs[$sequence]['exists'];
}
$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' => chado_get_schema_name('chado'),
':sequence_catalog' => $default_db
);
$results = db_query($sql, $args);
$exists = $results->fetchField();
if (!$exists) {
$cached_seqs[$sequence]['exists'] = FALSE;
cache_set('chado_sequences', $cached_seqs, 'cache', CACHE_TEMPORARY);
return FALSE;
}
$cached_seqs[$sequence]['exists'] = FALSE;
cache_set('chado_sequences', $cached_seqs, 'cache', CACHE_TEMPORARY);
return TRUE;
}