function chado_set_active

2.x tripal_core.chado_general.api.inc chado_set_active($dbname = 'default')
3.x tripal_chado.query.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'].

Parameters

$dbname:

Return value

Global variable $GLOBALS['chado_active_db'].

See also

hook_chado_connection_alter()

Related topics

9 calls to chado_set_active()
chado_feature_delete in legacy/tripal_feature/includes/tripal_feature.chado_node.inc
Implements hook_delete().
chado_get_version in tripal_chado/api/tripal_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_chado module which then sets the…
chado_populate_mview in tripal_chado/api/tripal_chado.mviews.api.inc
Update a Materialized View.
chado_query in tripal_chado/api/tripal_chado.query.api.inc
A substitute for db_query() when querying from Chado.
chado_update_cvtermpath in tripal_chado/api/modules/tripal_chado.cv.api.inc
Duplicate of fill_cvtermpath() stored procedure in Chado.

... See full list

1 string reference to 'chado_set_active'

File

tripal_chado/api/tripal_chado.query.api.inc, line 328
Provides an API for querying of chado including inserting, updating, deleting and selecting from chado.

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 = chado_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 = chado_get_schema_name('chado') . ',' . chado_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;
}