function tripal_db_set_active
2.x tripal_core.DEPRECATED.api.inc | tripal_db_set_active($dbname = 'default') |
3.x tripal_core.DEPRECATED.inc | tripal_db_set_active($dbname = 'default') |
1.x tripal_core_chado.api.inc | tripal_db_set_active($dbname = 'default') |
Set the Tripal Database
The tripal_db_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 for backwards compatibility with older versions of tripal or in cases where chado is located outside of the Drupal database.
Related topics
11 calls to tripal_db_set_active()
- chado_query in tripal_core/
api/ tripal_core_chado.api.inc - Use this function instead of db_query() to avoid switching databases when making query to the chado database
- tripal_add_mview in tripal_core/
api/ tripal_core_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…
- tripal_core_create_custom_table in tripal_core/
api/ tripal_core_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…
- tripal_core_install_sql in tripal_core/
includes/ chado_install.inc - Execute the provided SQL
- tripal_core_set_chado_version in tripal_core/
api/ tripal_core_chado.api.inc - Sets a Drupal variable with the current version of Chado. This variable can then be queried later using the tripal_core_get_chado_Version
File
- tripal_core/
api/ tripal_core_chado.api.inc, line 2892 - The Tripal Core API
Code
function tripal_db_set_active($dbname = 'default') {
global $db_url, $db_type, $active_db;
$chado_exists = 0;
// only postgres can support search paths. So if this is MysQL then
// just run the normal tripal_db_set_active function.
if (strcmp($db_type, 'pgsql') == 0) {
// if the 'chado' database is in the $db_url variable then chado is
// not in the same Drupal database, so we don't need to set any
// search_path and can just change the database
if (is_array($db_url)) {
if (isset($db_url[$dbname])) {
return db_set_active($dbname);
}
}
// if this is the default database then set the search path and return
if (strcmp($dbname, 'default') == 0) {
tripal_db_set_default_search_path();
return db_set_active($dbname);
}
// if the user requests a database other than the default
// then we need to try and set the chado search path. This
// only works if Chado is local to the Drpual database. If it
// fails then do nothing.
else {
if (tripal_db_set_chado_search_path($dbname)) {
// if the chado schema is local to Drupal then
// just return the active database.
return 'default';
}
else {
watchdog('tripal_core', "Cannot set 'search_path' variable for Postgres to %dbname",
array('%dbname' => $dbname), WATCHDOG_ERROR);
}
}
}
// a non postgres database
else {
return db_set_active($dbname);
}
}