Browse Source

Added a fix to chado_query -we are currently only prefixing for selects so search_path changes are still needed for non-select queries

Lacey Sanderson 12 years ago
parent
commit
7b009368b7
1 changed files with 17 additions and 0 deletions
  1. 17 0
      tripal_core/api/tripal_core.api.inc

+ 17 - 0
tripal_core/api/tripal_core.api.inc

@@ -2260,6 +2260,11 @@ function chado_query($sql) {
   }
   }
   //print "$sql\n";
   //print "$sql\n";
 
 
+  // If the query is not a select then we still need to change the search_path
+  if (!preg_match('/^SELECT/',$sql)) {
+    $change_path = TRUE;
+  }
+
   // Execute the query on the chado database/schema
   // Execute the query on the chado database/schema
   // Use the persistent chado connection if it already exists
   // Use the persistent chado connection if it already exists
   if ($persistent_chado) {
   if ($persistent_chado) {
@@ -2275,7 +2280,13 @@ function chado_query($sql) {
     }
     }
     // if we're local we can just run the query
     // if we're local we can just run the query
     if ($is_local) {
     if ($is_local) {
+      if ($change_path) {
+        $previous_db = tripal_db_set_active('chado');
+      }
       $last_result = pg_query($persistent_chado, $query);
       $last_result = pg_query($persistent_chado, $query);
+      if ($change_path) {
+        tripal_db_set_active($previous_db);
+      }
     }
     }
     else {
     else {
       $previous_db = tripal_db_set_active('chado');
       $previous_db = tripal_db_set_active('chado');
@@ -2309,7 +2320,13 @@ function chado_query($sql) {
     // search_path but that caused a lot of database calls and wasted
     // search_path but that caused a lot of database calls and wasted
     // resources during long jobs.
     // resources during long jobs.
     if ($is_local) {
     if ($is_local) {
+      if ($change_path) {
+        $previous_db = tripal_db_set_active('chado');
+      }
       $results = _db_query($sql);
       $results = _db_query($sql);
+      if ($change_path) {
+        tripal_db_set_active($previous_db);
+      }
     }
     }
     else {
     else {
       $previous_db = tripal_db_set_active('chado') ;
       $previous_db = tripal_db_set_active('chado') ;