Browse Source

Oops should have put the code to add the chado schema to the SQL in a differnet place in the chado_query function.

spficklin 12 years ago
parent
commit
2ba111dac2

+ 23 - 13
tripal_core/api/tripal_core.api.inc

@@ -2197,6 +2197,8 @@ function tripal_core_exclude_field_from_feature_by_default() {
  */
 function chado_query($sql) {
 
+  $is_local = tripal_core_is_chado_local();
+  
   $args = func_get_args();
   array_shift($args); // remove the $sql from the argument list
   $sql = db_prefix_tables($sql);
@@ -2204,9 +2206,18 @@ function chado_query($sql) {
     $args = $args[0];
   }
 
+  // run the Drupal command to clean up the SQL
   _db_query_callback($args, TRUE);
   $sql = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $sql);
 
+  // add the chado schema to the table names if Chado is local to the Drupal database
+  if ($is_local) {
+    $sql = preg_replace('/\n/', '', $sql);  // remove carriage returns
+    $sql = preg_replace('/FROM\s+(.*?)\s/i', 'FROM chado.\1 ', $sql);
+    $sql = preg_replace('/INNER\s+JOIN\s+(.*?)\s/i', 'INNER JOIN chado.\1 ', $sql);
+  }
+  print "$sql\n";
+
   // Execute the query on the chado database/schema
   // Use the persistent chado connection if it already exists
   $persistent_connection = variable_get('tripal_persistent_chado', NULL);
@@ -2214,17 +2225,22 @@ function chado_query($sql) {
 
     $query = $sql;
     // Duplicate the _db_query code in order to ensure that the drupal
-    // $active_db variable is never touched
+    // $active_db variable is not used in the pg_query command
     // thus changed $active_db to $persistent_connection
     // START COPY FROM _db_query in database.pgsql.inc
     if (variable_get('dev_query', 0)) {
       list($usec, $sec) = explode(' ', microtime());
       $timer = (float) $usec + (float) $sec;
     }
-
-    $previous_db = tripal_db_set_active('chado');
-    $last_result = pg_query($persistent_connection, $query);
-    tripal_db_set_active($previous_db);
+    // if we're local we can just run the query 
+    if ($is_local) { 
+      $last_result = pg_query($persistent_connection, $query);
+    }
+    else {
+      $previous_db = tripal_db_set_active('chado');
+      $last_result = pg_query($persistent_connection, $query);
+      tripal_db_set_active($previous_db);
+    }
 
     if (variable_get('dev_query', 0)) {
       $bt = debug_backtrace();
@@ -2251,21 +2267,15 @@ function chado_query($sql) {
     // the chado schema.  Previously use had to make changes to the 
     // search_path but that caused a lot of database calls and wasted 
     // resources during long jobs.  
-    if (tripal_core_is_chado_local()) { 
-      $sql = preg_replace('/\n/', '', $sql);  // remove carriage returns
-      $sql = preg_replace('/FROM\s+(.*?)\s/i', 'FROM chado.\1 ', $sql);
-      $sql = preg_replace('/INNER\s+JOIN\s+(.*?)\s/i', 'INNER JOIN chado.\1 ', $sql);
+    if ($is_local) { 
       $results = _db_query($sql);
     }
-    // if Chado is not local to the Drupal schema then use the old style
     else {
       $previous_db = tripal_db_set_active('chado') ;
       $results = _db_query($sql);
       tripal_db_set_active($previous_db);
-    }
-    
+    }    
   }
-
   return $results;
 }
 

+ 6 - 7
tripal_views/includes/tripal_views_integration.inc

@@ -76,13 +76,12 @@ function tripal_views_integration_setup_list() {
   $output .= '<h3>' . l(t('Add a new entry'), "admin/tripal/views/integration/new") . " | " .
     l(t("Create Materialized View"), 'admin/build/views/add') . '</h3>';
 
-  $output .= '<p>The following tables list the views integration setups available. If '
-    .'there is more then one setup for a given table, then the setup with the lightest '
-    .'priority will be used. For example, if you have created a custom setup for the '
-    .'feature chado table and your setup has a priority of -5 then your setup will be '
-    .'used instead of the default feature integration because -5 is lighter then 10.'
-    .'Priorities use the Drupal -10 to +10 scale where a record with -10 has a '
-    .'greater priority then one with 0 and both have a greater priority then one with +10.</p>';
+  $output .= '<p>' . t('The following tables are available for integration with Drupal Views. If '
+    . 'a table is integrated more than once, then the setup with the lightest '
+    . 'priority will be used. For example, if you have created a custom setup with a priority of -5 then '
+    . 'that will be used instead of the default setup with priority 10. '
+    . 'Priorities range from -10 to +10  where a setup with -10 has '
+    . 'greater precedent than any other and +10 has the least.') . '</p>';
 
 
   // Start with materialized views