function chado_column_exists
2.x tripal_core.chado_schema.api.inc | chado_column_exists($table, $column) |
3.x tripal_chado.schema.api.inc | 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
Parameters
$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/ 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 84
Code
function chado_column_exists($table, $column) {
global $databases;
$default_db = $databases['default']['default']['database'];
$sql = "
SELECT 1
FROM information_schema.columns
WHERE
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;
}