function chado_set_active

2.x tripal_core.chado_general.api.inc chado_set_active($dbname = 'default')

Set the Tripal Database

The chado_set_active function is used to prevent namespace collisions when Chado and Drupal are installed in the same database but in different schemas. It is also used when using Drupal functions such as db_table_exists().

The connection settings can be altered through the hook hook_chado_connection_alter.

Current active connection name is stored in the global variable $GLOBALS['chado_active_db'].

See also

hook_chado_connection_alter()

Related topics

6 calls to chado_set_active()
chado_feature_delete in tripal_feature/includes/tripal_feature.chado_node.inc
Implements hook_delete().
chado_get_version in tripal_core/api/tripal_core.chado_schema.api.inc
Returns the version number of the currently installed Chado instance. It can return the real or effective version. Note, this function is executed in the hook_init() of the tripal_core module which then sets theā€¦
chado_query in tripal_core/api/tripal_core.chado_query.api.inc
Use this function instead of db_query() to avoid switching databases when making query to the chado database.
tripal_db_set_active in tripal_core/api/tripal_core.DEPRECATED.api.inc
tripal_populate_mview in tripal_core/api/tripal_core.mviews.api.inc
Update a Materialized View

... See full list

1 string reference to 'chado_set_active'

File

tripal_core/api/tripal_core.chado_general.api.inc, line 61
Provides an application programming interface (API) to manage data withing the Chado database.

Code

function chado_set_active($dbname = 'default') {

  // Check if the chado_active_db has been set yet.
  if (!array_key_exists('chado_active_db', $GLOBALS)) {
    $GLOBALS['chado_active_db'] = 'default';
  }

  $previous_db = $active_db = $GLOBALS['chado_active_db'];
  $search_path = tripal_get_schema_name('drupal');

  // Change only if 'chado' has been specified.
  // Notice that we leave the active_db set as chado but use the possibly user-altered
  // schema name for the actual search path. This is to keep outward facing mentions of
  // chado as "chado" while still allowing the user to alter the schema name used.
  if ($dbname == 'chado') {
    $active_db = 'chado';
    $search_path = tripal_get_schema_name('chado') . ',' . tripal_get_schema_name('drupal');
  }
  else {
    $active_db = $dbname;
  }

  $settings = array(
    'dbname' => $dbname,
    'new_active_db' => &$active_db,
    'new_search_path' => &$search_path,
  );

  // Will call all modules implementing hook_chado_search_path_alter
  // note: hooks can alter $active_db and $search_path.
  drupal_alter('chado_connection', $settings);

  // set chado_active_db to remember active db
  $GLOBALS['chado_active_db'] = $active_db;

  // set PostgreSQL search_path
  db_query('SET search_path TO ' . $search_path);

  return $previous_db;
}