فهرست منبع

Fixed bug where search_path wasn't getting set back to 'default' and tables were being created in the Chado schema rather than the default schema

spficklin 13 سال پیش
والد
کامیت
0f3e1677ce
2فایلهای تغییر یافته به همراه20 افزوده شده و 29 حذف شده
  1. 18 22
      tripal_core/api/tripal_core.api.inc
  2. 2 7
      tripal_core/tripal_core.module

+ 18 - 22
tripal_core/api/tripal_core.api.inc

@@ -1563,13 +1563,8 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
         // that has a foreign key to this one ($table_desc['primary key'][0]
         // that has a foreign key to this one ($table_desc['primary key'][0]
         // and to the node table (nid)
         // and to the node table (nid)
         $sql = "SELECT %s, nid FROM {chado_%s} WHERE %s=%d";
         $sql = "SELECT %s, nid FROM {chado_%s} WHERE %s=%d";
-        $mapping = db_fetch_object(db_query(
-        $sql,
-        $table_primary_key,
-        $table,
-        $table_primary_key,
-        $object->{$table_primary_key}
-        ));
+        $mapping = db_fetch_object(db_query($sql, $table_primary_key, $table,
+          $table_primary_key, $object->{$table_primary_key}));
         if ($mapping->{$table_primary_key}) {
         if ($mapping->{$table_primary_key}) {
           $object->nid = $mapping->nid;
           $object->nid = $mapping->nid;
           $object->expandable_nodes[] = $table;
           $object->expandable_nodes[] = $table;
@@ -1961,8 +1956,6 @@ function tripal_core_exclude_field_from_feature_by_default() {
  */
  */
 function chado_query($sql) {
 function chado_query($sql) {
 
 
-  //print memory_get_usage() . "\n";
-
   $args = func_get_args();
   $args = func_get_args();
   array_shift($args); // remove the $sql from the argument list
   array_shift($args); // remove the $sql from the argument list
   $sql = db_prefix_tables($sql);
   $sql = db_prefix_tables($sql);
@@ -1988,7 +1981,9 @@ function chado_query($sql) {
       $timer = (float) $usec + (float) $sec;
       $timer = (float) $usec + (float) $sec;
     }
     }
 
 
+    $previous_db = tripal_db_set_active('chado');
     $last_result = pg_query($persistent_connection, $query);
     $last_result = pg_query($persistent_connection, $query);
+    tripal_db_set_active($previous_db);
 
 
     if (variable_get('dev_query', 0)) {
     if (variable_get('dev_query', 0)) {
       $bt = debug_backtrace();
       $bt = debug_backtrace();
@@ -2411,8 +2406,8 @@ function tripal_get_moddir($module_name) {
  *
  *
  * @ingroup tripal_chado_api
  * @ingroup tripal_chado_api
  */
  */
-function tripal_db_set_active($dbname) {
-  global $db_url, $db_type;
+function tripal_db_set_active($dbname  = 'default') {
+  global $db_url, $db_type, $active_db;
   $chado_exists = 0;
   $chado_exists = 0;
 
 
   // only postgres can support search paths.  So if this is MysQL then
   // only postgres can support search paths.  So if this is MysQL then
@@ -2420,7 +2415,8 @@ function tripal_db_set_active($dbname) {
   if (strcmp($db_type, 'pgsql')==0) {
   if (strcmp($db_type, 'pgsql')==0) {
 
 
     // if the 'chado' database is in the $db_url variable then chado is
     // if the 'chado' database is in the $db_url variable then chado is
-    // not in the same Drupal database
+    // 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 (is_array($db_url)) {
       if (isset($db_url[$dbname])) {
       if (isset($db_url[$dbname])) {
         return db_set_active($dbname);
         return db_set_active($dbname);
@@ -2435,17 +2431,20 @@ function tripal_db_set_active($dbname) {
     // if the user requests a database other than the default
     // if the user requests a database other than the default
     // then we need to try and set the chado search path.  This
     // then we need to try and set the chado search path.  This
     // only works if Chado is local to the Drpual database. If it
     // only works if Chado is local to the Drpual database. If it
-    // fails then we assume the database is not local and we'll
-    // set it as normal.
+    // fails then do nothing.
     else {
     else {
       if (tripal_db_set_chado_search_path($dbname)) {
       if (tripal_db_set_chado_search_path($dbname)) {
-         return $dbname;
+      	 // if the chado schema is local to Drupal then 
+      	 // just return the active database.
+         return 'default';
       }
       }
       else {
       else {
-        return db_set_active($dbname);
+        watchdog('tripal_core',"Cannot set 'search_path' variable for Postgres to %dbname",
+          array('%dbname' => $dbname), WATCHDOG_ERROR);
       }
       }
     }
     }
   }
   }
+  // a non postgres database
   else {
   else {
     return db_set_active($dbname);
     return db_set_active($dbname);
   }
   }
@@ -2819,11 +2818,8 @@ function tripal_get_max_chado_rank($tablename, $where_options) {
     }
     }
   }
   }
   $previous_db = tripal_db_set_active('chado');
   $previous_db = tripal_db_set_active('chado');
-  $result = db_fetch_object(db_query(
-    "SELECT max(rank) as max_rank, count(rank) as count FROM %s WHERE %s",
-  $tablename,
-  implode(' AND ', $where)
-  ));
+  $result = db_fetch_object(db_query("SELECT max(rank) as max_rank, count(rank) as count FROM %s WHERE %s",
+    $tablename,  implode(' AND ', $where)));
   tripal_db_set_active($previous_db);
   tripal_db_set_active($previous_db);
   //drupal_set_message("Max Rank Query=SELECT max(rank) as max_rank, count(rank) as count FROM ".$tablename." WHERE ".implode(' AND ',$where));
   //drupal_set_message("Max Rank Query=SELECT max(rank) as max_rank, count(rank) as count FROM ".$tablename." WHERE ".implode(' AND ',$where));
   if ($result->count > 0) {
   if ($result->count > 0) {
@@ -2990,7 +2986,7 @@ function tripal_core_set_chado_version() {
   }
   }
 
 
   // we can't use the Tripal API to query this table
   // we can't use the Tripal API to query this table
-  // because the Tripal API depends on this fucntion to
+  // because the Tripal API depends on this function to
   // tell it the version. So, we need a typical SQL statement
   // tell it the version. So, we need a typical SQL statement
   $sql = "SELECT value "
   $sql = "SELECT value "
   ."FROM chadoprop CP "
   ."FROM chadoprop CP "

+ 2 - 7
tripal_core/tripal_core.module

@@ -23,12 +23,7 @@ require_once "api/tripal_core.api.inc";
  * @ingroup tripal_core
  * @ingroup tripal_core
  */
  */
 function tripal_core_init() {
 function tripal_core_init() {
-  global $base_url;
-  
-  // make sure we are in the public schema. If there is an errant
-  // module that doesn't properly set the search path back, then
-  // we'll have issues
-  tripal_db_set_default_search_path();
+  global $base_url;  
   
   
   // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
   // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
   // only if the chado database is present.
   // only if the chado database is present.
@@ -62,7 +57,7 @@ function tripal_core_init() {
   // make sure the date time settings are the way Tripal will insert them
   // make sure the date time settings are the way Tripal will insert them
   // otherwise PostgreSQL version that may have a different datestyle setting
   // otherwise PostgreSQL version that may have a different datestyle setting
   // will fail when inserting or updating a date column in a table.
   // will fail when inserting or updating a date column in a table.
-  db_query("SET DATESTYLE TO '%s'", 'MDY');
+  db_query("SET DATESTYLE TO '%s'", 'MDY'); 
     
     
 }
 }