function chado_table_exists

2.x tripal_core.chado_schema.api.inc chado_table_exists($table)
3.x tripal_chado.schema.api.inc chado_table_exists($table)

Check that any given Chado table exists.

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

Parameters

$table: The name of the chado table whose existence should be checked.

Return value

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

Related topics

25 calls to chado_table_exists()
chado_add_mview in tripal_chado/api/tripal_chado.mviews.api.inc
Add a materialized view to the chado database to help speed data access. This function supports the older style where postgres column specifications are provided using the $mv_table, $mv_specs and $indexed variables. It also supports the newer…
chado_add_node_form_properties in legacy/tripal_core/api/tripal_core.chado_nodes.properties.api.inc
chado_add_node_form_relationships in legacy/tripal_core/api/tripal_core.chado_nodes.relationships.api.inc
Provides a form for adding to BASE_relationship and relationship tables
chado_create_custom_table in tripal_chado/api/tripal_chado.custom_tables.api.inc
Add a new table to the Chado schema. This function is simply a wrapper for the db_create_table() function of Drupal, but ensures the table is created inside the Chado schema rather than the Drupal schema. If the table already exists then it will be…
chado_delete_custom_table in tripal_chado/api/tripal_chado.custom_tables.api.inc
Deletes the specified custom table.

... See full list

File

tripal_chado/api/tripal_chado.schema.api.inc, line 49
Provides an application programming interface (API) for describing Chado tables.

Code

function chado_table_exists($table) {

  // Get the default database and chado schema.
  global $databases;
  $default_db = $databases['default']['default']['database'];
  $chado_schema = chado_get_schema_name('chado');

  // If we've already lookup up this table then don't do it again, as
  // we don't need to keep querying the database for the same tables.
  if (array_key_exists("chado_tables", $GLOBALS) and 
    array_key_exists($default_db, $GLOBALS["chado_tables"]) and 
    array_key_exists($chado_schema, $GLOBALS["chado_tables"][$default_db]) and 
    array_key_exists($table, $GLOBALS["chado_tables"][$default_db][$chado_schema])) {
    return TRUE;
  }

  $sql = "
    SELECT 1
    FROM information_schema.tables
    WHERE
      table_name = :table_name AND
      table_schema = :chado AND
      table_catalog = :default_db
  ";
  $args = array(
    ':table_name' => $table,
    ':chado' => $chado_schema,
    ':default_db' => $default_db
  );
  $results = db_query($sql, $args);
  $exists = $results->fetchObject();
  if (!$exists) {
    return FALSE;
  }

  // Set this table in the GLOBALS so we don't query for it again the next time.
  $GLOBALS["chado_tables"][$default_db][$chado_schema][$table] = TRUE;
  return TRUE;
}