Jelajahi Sumber

Added a new tripal_set_active_db function to replace Drupal's set_active_db function. This function allows Tripal to use a chado database in an external location or a chado database within another schema within the Drupal database. This keeps backwards compatibility with older versions of Tripal.

spficklin 14 tahun lalu
induk
melakukan
3ab974ee52

+ 12 - 12
tripal_analysis/tripal_analysis.admin.inc

@@ -83,9 +83,9 @@ function get_tripal_analysis_admin_form_taxonomy_set(&$form) {
 
 	// get the list of analyses
 	$sql = "SELECT * FROM {Analysis} ORDER BY name";
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	$lib_rset = db_query($sql);
-	db_set_active($previous_db);  // now use drupal database
+	tripal_db_set_active($previous_db);  // now use drupal database
 
 	// iterate through all of the libraries
 	$lib_boxes = array();
@@ -129,9 +129,9 @@ function get_tripal_analysis_admin_form_reindex_set(&$form) {
 
 	// get the list of libraries
 	$sql = "SELECT * FROM {Analysis} ORDER BY name";
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	$lib_rset = db_query($sql);
-	db_set_active($previous_db);  // now use drupal database
+	tripal_db_set_active($previous_db);  // now use drupal database
 
 	// iterate through all of the libraries
 	$lib_boxes = array();
@@ -205,9 +205,9 @@ function get_tripal_analysis_admin_form_sync_set (&$form) {
 			
 		// get the list of analyses
 		$sql = "SELECT * FROM {analysis} ORDER BY name";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$ana_rset = db_query($sql);
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 			
 		// if we've added any analyses to the list that can be synced
 		// then we want to build the form components to allow the user
@@ -282,9 +282,9 @@ function tripal_analysis_admin_validate($form, &$form_state) {
 			if($analysis_id and preg_match("/^\d+$/i",$analysis_id)){
 				// get the list of analyses
 				$sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
-				$previous_db = db_set_active('chado');  // use chado database
+				$previous_db = tripal_db_set_active('chado');  // use chado database
 				$analysis = db_fetch_object(db_query($sql,$analysis_id));
-				db_set_active($previous_db);  // now use drupal database
+				tripal_db_set_active($previous_db);  // now use drupal database
 				$to_sync[$analysis_id] = $analysis->name;
 			}
 		}
@@ -310,9 +310,9 @@ function tripal_analysis_admin_validate($form, &$form_state) {
 			if($analysis_id and preg_match("/^\d+$/i",$analysis_id)){
 				// get the analysis info
 				$sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
-				$previous_db = db_set_active('chado');  // use chado database
+				$previous_db = tripal_db_set_active('chado');  // use chado database
 				$analysis = db_fetch_object(db_query($sql,$analysis_id));
-				db_set_active($previous_db);  // now use drupal database
+				tripal_db_set_active($previous_db);  // now use drupal database
 				$job_args[0] = $analysis_id;
 				tripal_add_job("Reindex features for analysis: $analysis->name",'tripal_analysis',
              'tripal_analysis_reindex_features',$job_args,$user->uid);
@@ -330,9 +330,9 @@ function tripal_analysis_admin_validate($form, &$form_state) {
 			if($analysis_id and preg_match("/^\d+$/i",$analysis_id)){
 				// get the analysis info
 				$sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
-				$previous_db = db_set_active('chado');  // use chado database
+				$previous_db = tripal_db_set_active('chado');  // use chado database
 				$analysis = db_fetch_object(db_query($sql,$analysis_id));
-				db_set_active($previous_db);  // now use drupal database
+				tripal_db_set_active($previous_db);  // now use drupal database
 				$job_args[0] = $analysis_id;
 				tripal_add_job("Set taxonomy for features in analysis: $analysis->name",'tripal_analysis',
              'tripal_analysis_taxonify_features',$job_args,$user->uid);

+ 2 - 2
tripal_analysis/tripal_analysis.install

@@ -15,7 +15,7 @@ function tripal_analysis_install() {
 	// Create analysisfeatureprop table in chado. This cannot be accomplished
 	// by calling drupal_install_schema because it's not in the drupal db. This
 	// table is used to store Blast xml and Interpro html/goterms
-	$previous_db = db_set_active('chado');
+	$previous_db = tripal_db_set_active('chado');
 	if (!db_table_exists('analysisfeatureprop')) {
 	   $sql = "CREATE TABLE {analysisfeatureprop} (".
 	          "  analysisfeatureprop_id SERIAL PRIMARY KEY, ".
@@ -27,7 +27,7 @@ function tripal_analysis_install() {
 	          ")";
 	   db_query($sql);
 	}
-	db_set_active($previous_db);
+	tripal_db_set_active($previous_db);
 
    tripal_add_cvterms('analysis_type','The type of analysis was performed. This value is automatically set by each Tripal Analysis module and should be equal to the module name (e.g. tripal_analysis_blast, tripal_analysis_go).');
 	tripal_add_cvterms('analysis_date','The date that an analysis was performed.');

+ 28 - 28
tripal_analysis/tripal_analysis.module

@@ -122,9 +122,9 @@ function chado_analysis_insert($node){
 		$sql = "SELECT analysis_id ".
                "FROM {Analysis} ".
                "WHERE analysis_id = %d ";
-		$previous_db = db_set_active('chado');
+		$previous_db = tripal_db_set_active('chado');
 		$analysis = db_fetch_object(db_query($sql, $node->analysis_id));
-		db_set_active($previous_db);
+		tripal_db_set_active($previous_db);
 	}
 
 	// If the analysis doesn't exist then let's create it in chado.
@@ -134,12 +134,12 @@ function chado_analysis_insert($node){
              "  (name, description, program, programversion, algorithm, ".
              "   sourcename, sourceversion, sourceuri, timeexecuted) ".
              "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		db_query($sql,$node->analysisname, $node->description,
 		$node->program,$node->programversion,$node->algorithm,
 		$node->sourcename, $node->sourceversion, $node->sourceuri,
 		$timestamp);
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
 	}
 
 	// Make sure the entry for this analysis doesn't already exist in the
@@ -194,9 +194,9 @@ function chado_analysis_delete($node){
 	db_query($sql_del, $node->nid, $node->vid);
 
 	//Remove from analysis and analysisprop tables of chado database as well
-	$previous_db = db_set_active('chado');
+	$previous_db = tripal_db_set_active('chado');
 	db_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
-	db_set_active($previous_db);
+	tripal_db_set_active($previous_db);
 }
 
 /*******************************************************************************
@@ -232,11 +232,11 @@ function chado_analysis_update($node){
              "    timeexecuted = '%s' ".
              "WHERE analysis_id = %d ";
 
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		db_query($sql, $node->analysisname, $node->description, $node->program,
 		$node->programversion,$node->algorithm,$node->sourcename,
 		$node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
-      db_set_active($previous_db);  // switch back to drupal database
+      tripal_db_set_active($previous_db);  // switch back to drupal database
 		
 		// Create a title for the analysis node using the unique keys so when the
 		// node is saved, it will have a title
@@ -367,7 +367,7 @@ function chado_analysis_load($node){
              "  sourceuri, timeexecuted ".
              "FROM {Analysis} ".
              "WHERE Analysis_id = $ana_node->analysis_id";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$additions = db_fetch_object(db_query($sql));
         // get number of features assc with this analysis
         $sql = "SELECT count(feature_id) as featurecount ".
@@ -375,7 +375,7 @@ function chado_analysis_load($node){
              "WHERE Analysis_id = %d";
         $additions->featurecount = db_result(db_query($sql, $ana_node->analysis_id));
 
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	}
 	// If the analysis has a name, use it as the node title. If not, construct
 	// the title using program programversion, and sourcename
@@ -422,18 +422,18 @@ function tripal_analysis_sync_analyses ($analysis_id = NULL, $job_id = NULL){
    		 "  programversion, algorithm, sourcename, sourceversion, sourceuri, ".
           "  timeexecuted ".
           "FROM {Analysis} ";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$results = db_query($sql);
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	} else {
 		$sql = "SELECT Analysis_id, name AS analysisname, description, program, ".
    		  "  programversion, algorithm, sourcename, sourceversion, sourceuri, ".
           "  timeexecuted ".
           "FROM {Analysis} ".
           "WHERE analysis_id = %d";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$results = db_query($sql,$analysis_id);
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	}
 
 
@@ -461,9 +461,9 @@ function tripal_analysis_sync_analyses ($analysis_id = NULL, $job_id = NULL){
                     AND type_id =  
                         (SELECT cvterm_id from {cvterm} where name = '%s')
             ";
-			$previous_db = db_set_active('chado');
+			$previous_db = tripal_db_set_active('chado');
 			$analysis_type = db_fetch_object(db_query($sql, $analysis->analysis_id, "analysis_type"));
-			db_set_active($previous_db);
+			tripal_db_set_active($previous_db);
 
 			// Get the type of analysis using cvterm_id
             // Current possibilities: kegg, unigene, interpro, blast
@@ -620,7 +620,7 @@ function get_chado_analyses() {
 	if ($no_orgs != 0) {
 		$sql = "SELECT analysis_id, CA.nid, type FROM {chado_analysis} CA INNER JOIN node ON CA.nid = node.nid";
 		$result = db_query($sql);
-		$previous_db = db_set_active('chado');
+		$previous_db = tripal_db_set_active('chado');
 		$sql = "SELECT Analysis_id, name AS analysisname, description, program, 
 		                       programversion, algorithm, sourcename, sourceversion, 
 		                       sourceuri, timeexecuted
@@ -638,7 +638,7 @@ function get_chado_analyses() {
 			$analyses ["$sortedBy$count"] = $analysis;
 			$count ++;
 		}
-		db_set_active($previous_db);
+		tripal_db_set_active($previous_db);
 
 		//Sort analyses by time, descending order
 		krsort($analyses, SORT_STRING);
@@ -746,9 +746,9 @@ function tripal_analyses_cleanup($dummy = NULL, $job_id = NULL) {
     $sql_chado = "SELECT analysis_id from {analysis} WHERE analysis_id = %d";
 
 	foreach($nid2aid as $nid => $aid){
-        $previous_db = db_set_active('chado');
+        $previous_db = tripal_db_set_active('chado');
 		$chado_record = db_fetch_object(db_query($sql_chado,$aid));
-        db_set_active($previous_db);
+        tripal_db_set_active($previous_db);
 		if(!$chado_record){
             node_delete($nid); 
 			$message = "Missing in analysis table in chado.... DELETING node: $nid\n";
@@ -770,17 +770,17 @@ function tripal_analysis_reindex_features ($analysis_id = NULL, $job_id = NULL){
 		$sql = "SELECT Analysis_id, Feature_id ".
           "FROM {Analysisfeature} ".
           "ORDER BY analysis_id";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$results = db_query($sql);
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	} else {
 		$sql = "SELECT Analysis_id, Feature_id ".
              "FROM {Analysisfeature} ".
              "WHERE analysis_id = %d";
              "ORDER BY analysis_id";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$results = db_query($sql,$analysis_id);
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	}
 
 	// load into ids array
@@ -814,17 +814,17 @@ function tripal_analysis_taxonify_features ($analysis_id = NULL, $job_id = NULL)
 		$sql = "SELECT Analysis_id, Feature_id ".
           "FROM {Analysisfeature} ".
           "ORDER BY analysis_id";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$results = db_query($sql);
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	} else {
 		$sql = "SELECT Analysis_id, Feature_id ".
              "FROM {Analysisfeature} ".
              "WHERE analysis_id = %d";
              "ORDER BY analysis_id";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$results = db_query($sql,$analysis_id);
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	}
 
 	// load into ids array

+ 6 - 6
tripal_analysis_blast/tripal_analysis_blast.install

@@ -36,25 +36,25 @@ function tripal_analysis_blast_install() {
                  "VALUES (%d, '%s', '%s', '%s', '%s', %d)";
    
    // Add swissprot parser
-   $previous_db = db_set_active ('chado');
+   $previous_db = tripal_db_set_active ('chado');
    $results = db_query($sql_db, "%swissprot%");
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    while ($db = db_fetch_object($results)) {
       db_query($sql_parser, $db->db_id, 'ExPASy Swissprot', '^sp\|.*?\|(.*?)\s.*?$', '^sp\|.*?\|.*?\s(.*)$', 'sp\|(.*?)\|.*?\s.*?$', 0);
    }
    
    // Add trembl parser
-   $previous_db = db_set_active ('chado');
+   $previous_db = tripal_db_set_active ('chado');
    $results = db_query($sql_db, "%trembl%");
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    while ($db = db_fetch_object($results)) {
       db_query($sql_parser, $db->db_id, 'ExPASy TrEMBL', '^.*?\|(.*?)\s.*?$', '^.*?\|.*?\s(.*)$', '^(.*?)\|.*?\s.*?$', 0);
    }
    
    // Add genbank parser
-   $previous_db = db_set_active ('chado');
+   $previous_db = tripal_db_set_active ('chado');
    $results = db_query($sql_db, "%genbank%");
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    while ($db = db_fetch_object($results)) {
       db_query($sql_parser, $db->db_id, 'Genbank', '', '', '', 1);
    }

+ 40 - 40
tripal_analysis_blast/tripal_analysis_blast.module

@@ -116,7 +116,7 @@ function tripal_get_blast_results($feature_id, $db_id, $max,$ajax){
 
 	// Get cvterm_id for 'analysis_blast_output_iteration_hits' which is required
 	// for inserting into the analysisfeatureprop table
-	$previous_db = db_set_active('chado');
+	$previous_db = tripal_db_set_active('chado');
 	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
           "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
           "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
@@ -132,7 +132,7 @@ function tripal_get_blast_results($feature_id, $db_id, $max,$ajax){
 	        WHERE feature_id = %d
 	        AND AFP.type_id = %d ";
 	$result = db_query($sql, $feature_id, $type_id);
-	db_set_active($previous_db);
+	tripal_db_set_active($previous_db);
 
 	// get the HTML content for viewing each of the XML file
 	while ($analysisfeatureprop = db_fetch_object($result)) {
@@ -142,19 +142,19 @@ function tripal_get_blast_results($feature_id, $db_id, $max,$ajax){
 		$att_db_id = $blastsettings [0];
 
 		// get analysis name and date
-		$previous_db = db_set_active('chado');
+		$previous_db = tripal_db_set_active('chado');
 		$sql = "SELECT analysis_id AS aid, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
 		        FROM {analysis} 		        WHERE analysis_id = %d";
 		$analysis = db_fetch_object(db_query($sql, $analysisfeatureprop->aid));
-		db_set_active($previous_db);
+		tripal_db_set_active($previous_db);
 
 		// If not called by ajax, go through all blast hits
 		if ($ajax == 0) {
 			// Get db object using the db_id
-			$previous_db = db_set_active('chado');
+			$previous_db = tripal_db_set_active('chado');
 			$sql = "SELECT * FROM {db} WHERE db_id=%d";
 			$db = db_fetch_object(db_query($sql, $att_db_id));
-			db_set_active($previous_db);
+			tripal_db_set_active($previous_db);
 
 			$content .= parse_NCBI_Blast_XML($analysisfeatureprop->afpvalue,$db,$max,$feature_id,$ajax, $analysis);
 
@@ -162,10 +162,10 @@ function tripal_get_blast_results($feature_id, $db_id, $max,$ajax){
 		} else {
 			if ($att_db_id == $db_id) {
 				// Get db object using the db_id
-				$previous_db = db_set_active('chado');
+				$previous_db = tripal_db_set_active('chado');
 				$sql = "SELECT * FROM {db} WHERE db_id=%d";
 				$db = db_fetch_object(db_query($sql, $att_db_id));
-				db_set_active($previous_db);
+				tripal_db_set_active($previous_db);
 				$content .= parse_NCBI_Blast_XML($analysisfeatureprop->afpvalue,$db,$max,$feature_id,$ajax, $analysis);
 			}
 		}
@@ -188,7 +188,7 @@ function tripal_get_blast_results_index_version ($feature_id){
 
 	// Get cvterm_id for 'analysis_blast_output_iteration_hits' which is required
 	// for inserting into the analysisfeatureprop table
-	$previous_db = db_set_active('chado');
+	$previous_db = tripal_db_set_active('chado');
 	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
           "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
           "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
@@ -204,25 +204,25 @@ function tripal_get_blast_results_index_version ($feature_id){
            WHERE feature_id = %d
            AND AFP.type_id = %d ";
 	$result = db_query($sql, $feature_id, $type_id);
-	db_set_active($previous_db);
+	tripal_db_set_active($previous_db);
 
 	// get the HTML content for viewing each of the XML file
 	while ($analysisfeatureprop = db_fetch_object($result)) {
 		// get analysis name and date
-		$previous_db = db_set_active('chado');
+		$previous_db = tripal_db_set_active('chado');
 		$sql = "SELECT analysis_id AS aid, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
               FROM {analysis}               WHERE analysis_id = %d";
 		$analysis = db_fetch_object(db_query($sql, $analysisfeatureprop->aid));
-		db_set_active($previous_db);
+		tripal_db_set_active($previous_db);
 
 		$blastsettings = explode("|", $analysisfeatureprop->apvalue);
 		$att_db_id = $blastsettings [0];
 
 		// Get db object using the db_id
-		$previous_db = db_set_active('chado');
+		$previous_db = tripal_db_set_active('chado');
 		$sql = "SELECT * FROM {db} WHERE db_id=%d";
 		$db = db_fetch_object(db_query($sql, $att_db_id));
-		db_set_active($previous_db);
+		tripal_db_set_active($previous_db);
 		// Only index best 10 hits because the default page only shows 10 blast results
 		$max = 10;
 		$content .= parse_NCBI_Blast_XML_index_version($analysisfeatureprop->afpvalue,$db,$max,$feature_id,$ajax, $analysis);
@@ -498,9 +498,9 @@ function parse_NCBI_Blast_XML($xml_string,$db,$max,$feature_id,$ajax, $analysis)
 		} else {
 			// Test if this is another feature in the database
 			$sql = "SELECT feature_id FROM {feature} WHERE uniquename = '%s'";
-			$previous_db = db_set_active('chado');
+			$previous_db = tripal_db_set_active('chado');
 			$hit_feature_id = db_result(db_query($sql, $hit_name));
-			db_set_active($previous_db);
+			tripal_db_set_active($previous_db);
 			// If it is, add link to that feature
 			if ($hit_feature_id) {
 				$hit_url = url("ID$hit_feature_id");
@@ -647,7 +647,7 @@ function tripal_analysis_blast_get_settings() {
       '#weight' => 10
 	);
 
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	// get a list of db from chado for user to choose
 	$sql = 'SELECT db_id, name FROM {db} ORDER BY lower(name)';
 	$results = db_query ($sql);
@@ -666,7 +666,7 @@ function tripal_analysis_blast_get_settings() {
       '#options' => $form['db_options']['#value'],
       '#attributes' => array(
          'onChange' => "return tripal_update_regex(this)",
-	)
+	    )
 	);
 	$form['blast_parser']['displayname'] = array(
       '#title' => t('Title for the blast analysis'),
@@ -677,7 +677,7 @@ function tripal_analysis_blast_get_settings() {
 	   '#type' => 'checkbox',
 	   '#attributes' => array(
          'onClick' => "return tripal_set_genbank_style(this)",
-	)
+	    )
 	);
 	$form['blast_parser']['hit_id'] = array(
       '#title' => t('Regular expression for Hit Name'),
@@ -695,7 +695,7 @@ function tripal_analysis_blast_get_settings() {
       '#type' => 'submit',
       '#value' => t('Save settings')
 	);
-	db_set_active($previous_db); // use drupal database
+	tripal_db_set_active($previous_db); // use drupal database
 
 	$settings->form = $form;
 	$settings->title = "Tripal Blast";
@@ -720,7 +720,7 @@ function tripal_analysis_blast_parseXMLFile ($analysis_id, $blastdb, $blastfile,
 
 		// Get cvterm_id for 'analysis_blast_output_iteration_hits' which is required
 		// for inserting into the analysisfeatureprop table
-		$previous_db = db_set_active('chado'); // use chado database
+		$previous_db = tripal_db_set_active('chado'); // use chado database
 		$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
           "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
           "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
@@ -753,9 +753,9 @@ function tripal_analysis_blast_parseXMLFile ($analysis_id, $blastdb, $blastfile,
 						$idx_iterations ++;
 						if ($idx_iterations % $interval == 0) {
 							$percentage = (int) ($idx_iterations / $no_iterations * 100);
-							db_set_active($previous_db);
+							tripal_db_set_active($previous_db);
 							tripal_job_set_progress($job_id, $percentage);
-							$previous_db = db_set_active('chado');
+							$previous_db = tripal_db_set_active('chado');
 							print $percentage."% ";
 						}
 						// now run through the blast hits/hsps of this iteration
@@ -857,7 +857,7 @@ function tripal_analysis_blast_parseXMLFile ($analysis_id, $blastdb, $blastfile,
 				}
 			}
 		}
-		db_set_active ($previous_db); // Use drupal database
+		tripal_db_set_active ($previous_db); // Use drupal database
 
 		// Otherwise, $blastfile is a directory. Iterate through all xml files in it
 	} else {
@@ -870,7 +870,7 @@ function tripal_analysis_blast_parseXMLFile ($analysis_id, $blastdb, $blastfile,
 
 		// Get cvterm_id for 'analysis_blast_output_iteration_hits' which is required
 		// for inserting into the analysisfeatureprop table
-		$previous_db = db_set_active('chado'); // use chado database
+		$previous_db = tripal_db_set_active('chado'); // use chado database
 		$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
           "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
           "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
@@ -883,9 +883,9 @@ function tripal_analysis_blast_parseXMLFile ($analysis_id, $blastdb, $blastfile,
 				// Set job status
 				if ($no_file % $interval == 0) {
 					$percentage = (int) ($no_file / $total_files * 100);
-					db_set_active($previous_db);
+					tripal_db_set_active($previous_db);
 					tripal_job_set_progress($job_id, $percentage);
-					$previous_db = db_set_active('chado');
+					$previous_db = tripal_db_set_active('chado');
 					print $percentage."% ";
 				}
 
@@ -1016,7 +1016,7 @@ function tripal_analysis_blast_parseXMLFile ($analysis_id, $blastdb, $blastfile,
 				$no_file ++;
 			}
 		}
-		db_set_active ($previous_db); // Use drupal database
+		tripal_db_set_active ($previous_db); // Use drupal database
 	}
 
 	print "Done.\nSuccessful and failed entries have been saved in the log file:\n $logfile\n";
@@ -1171,11 +1171,11 @@ function chado_analysis_blast_form ($node){
       '#weight' => 11
 	);
 
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	// get a list of db from chado for user to choose
 	$sql = 'SELECT db_id, name FROM {db} ORDER BY lower(name)';
 	$results = db_query ($sql);
-	db_set_active($previous_db);
+	tripal_db_set_active($previous_db);
 	$blastdbs = array();
 	while ($db = db_fetch_object($results)){
 		$blastdbs[$db->db_id] = $db->name;
@@ -1258,9 +1258,9 @@ function chado_analysis_blast_validate($node, &$form){
                 "WHERE program='%s'".
                 "AND programversion='%s'".
                 "AND sourcename='%s'";
-	        $previous_db = db_set_active('chado');
+	        $previous_db = tripal_db_set_active('chado');
 	        $analysis_id = db_result(db_query($sql, $node->program, $node->programversion, $node->sourcename));
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
         
             if($analysis_id){
                 //---------------------------------------------------
@@ -1318,7 +1318,7 @@ function chado_analysis_blast_insert($node){
            "  (name, description, program, programversion, algorithm, ".
            "   sourcename, sourceversion, sourceuri, timeexecuted) ".
            "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	db_query($sql,$node->analysisname, $node->description,
 	$node->program,$node->programversion,$node->algorithm,
 	$node->sourcename, $node->sourceversion, $node->sourceuri,
@@ -1348,7 +1348,7 @@ function chado_analysis_blast_insert($node){
 	$blastsettings = $node->blastdb."|".$node->blastfile."|".$node->blastparameters;
 	db_query($sql, $analysis_id, $type_id, $blastsettings);
 
-	db_set_active($previous_db);  // switch back to drupal database
+	tripal_db_set_active($previous_db);  // switch back to drupal database
 
     //---------------------------------------------------
 	// Add a job if the user wants to parse the xml output
@@ -1412,7 +1412,7 @@ function chado_analysis_blast_delete($node){
 	db_query($sql_del, $node->nid, $node->vid);
 
 	//Remove from analysisfeatureprop, analysisfeature, analysis, and analysisprop tables
-	$previous_db = db_set_active('chado');
+	$previous_db = tripal_db_set_active('chado');
 	$sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE analysis_id=%d";
 	$results = db_query($sql, $analysis_id);
 	while ($af = db_fetch_object($results)) {
@@ -1421,7 +1421,7 @@ function chado_analysis_blast_delete($node){
 	db_query("DELETE FROM {analysisfeature} WHERE analysis_id = %d", $analysis_id);
 	db_query("DELETE FROM {analysisprop} WHERE analysis_id = %d", $analysis_id);
 	db_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
-	db_set_active($previous_db);
+	tripal_db_set_active($previous_db);
 }
 
 /*******************************************************************************
@@ -1457,7 +1457,7 @@ function chado_analysis_blast_update($node){
              "    timeexecuted = '%s' ".
              "WHERE analysis_id = %d ";
 
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		db_query($sql, $node->analysisname, $node->description, $node->program,
 		$node->programversion,$node->algorithm,$node->sourcename,
 		$node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
@@ -1474,7 +1474,7 @@ function chado_analysis_blast_update($node){
              "WHERE analysis_id = %d AND type_id = %d";
 		$blastsettings = $node->blastdb."|".$node->blastfile."|".$node->blastparameters;
 		db_query($sql, $blastsettings, $analysis_id, $type_id);
-		db_set_active($previous_db);  // switch back to drupal database
+		tripal_db_set_active($previous_db);  // switch back to drupal database
 		// Add a job if the user wants to parse the xml output
 		if($node->blastjob) {
 			$job_args[0] = $analysis_id;
@@ -1521,7 +1521,7 @@ function chado_analysis_blast_load($node){
              "  sourceuri, timeexecuted ".
              "FROM {Analysis} ".
              "WHERE Analysis_id = $ana_node->analysis_id";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$additions = db_fetch_object(db_query($sql));
 
 		// get number of features assc with this analysis
@@ -1548,7 +1548,7 @@ function chado_analysis_blast_load($node){
 		$additions->blastfile = $prop_values[1];
 		$additions->blastparameters = $prop_values[2];
 
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	}
 	// If the analysis has a name, use it as the node title. If not, construct
 	// the title using program programversion, and sourcename

+ 2 - 2
tripal_analysis_go/tripal_analysis_go.install

@@ -10,7 +10,7 @@ function tripal_analysis_go_install(){
    // The following view will create counts of features that are assigned
    // either directly or by ancestry each GO term. The count is organized by
    // organisms.
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    if (db_table_exists('go_count_organism')) {
       $sql = "DROP TABLE go_count_organism";
       db_query($sql);
@@ -19,7 +19,7 @@ function tripal_analysis_go_install(){
       $sql = "DROP TABLE go_count_analysis";
       db_query($sql);
    }
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    
    tripal_add_mview(
       // view name

+ 16 - 16
tripal_analysis_go/tripal_analysis_go.module

@@ -224,9 +224,9 @@ function tripal_analysis_go_select_form(&$form_state = NULL,$node){
      WHERE organism_id = %d
      ORDER BY analysis_id DESC
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$node->organism_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    $analyses = array();
    $analyses[''] = '';
@@ -304,9 +304,9 @@ function tripal_analysis_go_organism_add($node) {
      WHERE organism_id = %d
      ORDER BY analysis_id DESC
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_fetch_object(db_query($sql,$node->organism_id));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    if($results){
       $select_analysis = drupal_get_form('tripal_analysis_go_select_form',$node);
@@ -356,9 +356,9 @@ function tripal_analysis_go_cv_chart($chart_id){
   $type        = preg_replace("/^tripal_analysis_go_cv_chart_(\d+)-(\d+)_(bp|cc|mf)$/","$3",$chart_id);
 
   $sql = "SELECT * FROM {Analysis} WHERE analysis_id = %d";
-  $previous_db = db_set_active('chado');  // use chado database
+  $previous_db = tripal_db_set_active('chado');  // use chado database
   $analysis = db_fetch_object(db_query($sql,$analysis_id));
-  db_set_active($previous_db);  // now use drupal database  
+  tripal_db_set_active($previous_db);  // now use drupal database  
  
   if(strcmp($type,'mf')==0){
      $class = 'molecular_function';
@@ -435,9 +435,9 @@ function tripal_analysis_go_cvterm_add($cvterm_id,$tree_id){
        INNER JOIN dbxref DBX on DBX.dbxref_id = CVT.dbxref_id
      WHERE cvterm_id = %d
   ";
-  $previous_db = db_set_active('chado');
+  $previous_db = tripal_db_set_active('chado');
   $xref = db_fetch_object(db_query($sql,$cvterm_id));
-  db_set_active($previous_db);
+  tripal_db_set_active($previous_db);
 
   $link = url("download_goterm_features/$cvterm_id/$tree_id");
   $options = array(
@@ -456,9 +456,9 @@ function tripal_analysis_go_get_goterm_features($cvterm_id,$tree_id){
         INNER JOIN dbxref DBX on DBX.dbxref_id = CVT.dbxref_id
       WHERE cvterm_id = %d
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $xref = db_fetch_object(db_query($sql,$cvterm_id));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    drupal_set_header('Content-Type: text');
    drupal_set_header('Content-Disposition: attachment; filename="GO_'.$xref->accession.'.fasta"');
@@ -476,9 +476,9 @@ function tripal_analysis_go_get_goterm_features($cvterm_id,$tree_id){
       WHERE CVTP.object_id = %d and F.organism_id = %d and AF.analysis_id = %d
       ORDER BY F.name
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$cvterm_id,$organism_id,$analysis_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    while($feature = db_fetch_object($results)){
       // get the go term information for each sequence
       $sql = "
@@ -489,9 +489,9 @@ function tripal_analysis_go_get_goterm_features($cvterm_id,$tree_id){
          WHERE FCVT.feature_id = %d
       ";
 
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $terms = db_query($sql,$feature->feature_id);
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       $desc = '[';
       while($term = db_fetch_object($terms)){
          $desc .= "GO:$term->accession $term->name; ";
@@ -522,9 +522,9 @@ function tripal_analysis_go_feature_add($node) {
         ORDER BY CV.name, CVT.name
    ";
 
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$node->feature->feature_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    $term = db_fetch_object($results); // retrive the first result
    if ($term) {
       $content .= "<div id=\"tripal_go_box\" class=\"tripal_go-info-box\">";

+ 20 - 20
tripal_analysis_interpro/tripal_analysis_interpro.module

@@ -187,9 +187,9 @@ function chado_analysis_interpro_insert($node){
 		$sql = "SELECT analysis_id ".
                "FROM {Analysis} ".
                "WHERE analysis_id = %d ";
-		$previous_db = db_set_active('chado');
+		$previous_db = tripal_db_set_active('chado');
 		$analysis = db_fetch_object(db_query($sql, $node->analysis_id));
-		db_set_active($previous_db);
+		tripal_db_set_active($previous_db);
 	}
 
 	// If the analysis doesn't exist then let's create it in chado.
@@ -199,7 +199,7 @@ function chado_analysis_interpro_insert($node){
              "  (name, description, program, programversion, algorithm, ".
              "   sourcename, sourceversion, sourceuri, timeexecuted) ".
              "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		db_query($sql,$node->analysisname, $node->description,
 		$node->program,$node->programversion,$node->algorithm,
 		$node->sourcename, $node->sourceversion, $node->sourceuri,
@@ -227,7 +227,7 @@ function chado_analysis_interpro_insert($node){
 		$interprosettings = $node->interprofile."|".$node->interproparameters;
 		db_query($sql, $analysis_id, $type_id, $interprosettings);
 
-		db_set_active($previous_db);  // switch back to drupal database
+		tripal_db_set_active($previous_db);  // switch back to drupal database
 		// Add a job if the user wants to parse the html output
 		if($node->interprojob) {
 			$job_args[0] = $analysis_id;
@@ -300,7 +300,7 @@ function chado_analysis_interpro_delete($node){
 	db_query($sql_del, $node->nid, $node->vid);
 
 	//Remove from analysisfeatureprop, analysisfeature, analysis, and analysisprop tables
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE analysis_id=%d";
    $results = db_query($sql, $analysis_id);
    while ($af = db_fetch_object($results)) {
@@ -309,7 +309,7 @@ function chado_analysis_interpro_delete($node){
    db_query("DELETE FROM {analysisfeature} WHERE analysis_id = %d", $analysis_id);
    db_query("DELETE FROM {analysisprop} WHERE analysis_id = %d", $analysis_id);
    db_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 }
 
 /*******************************************************************************
@@ -345,7 +345,7 @@ function chado_analysis_interpro_update($node){
              "    timeexecuted = '%s' ".
              "WHERE analysis_id = %d ";
 
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		db_query($sql, $node->analysisname, $node->description, $node->program,
 		$node->programversion,$node->algorithm,$node->sourcename,
 		$node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
@@ -362,7 +362,7 @@ function chado_analysis_interpro_update($node){
              "WHERE analysis_id = %d AND type_id = %d";
 		$interprosettings = $node->interprofile."|".$node->interproparameters;
 		db_query($sql, $interprosettings, $analysis_id, $type_id);
-		db_set_active($previous_db);  // switch back to drupal database
+		tripal_db_set_active($previous_db);  // switch back to drupal database
 		// Add a job if the user wants to parse the html output
 		if($node->interprojob) {
 			$job_args[0] = $analysis_id;
@@ -413,7 +413,7 @@ function chado_analysis_interpro_load($node){
              "  sourceuri, timeexecuted ".
              "FROM {Analysis} ".
              "WHERE Analysis_id = $ana_node->analysis_id";
-		$previous_db = db_set_active('chado');  // use chado database
+		$previous_db = tripal_db_set_active('chado');  // use chado database
 		$additions = db_fetch_object(db_query($sql));
 
 		// get cvterm_id for 'analysis_interpro_settings'
@@ -431,7 +431,7 @@ function chado_analysis_interpro_load($node){
 		$additions->interprofile = $prop_values[0];
 		$additions->interproparameters = $prop_values[1];
 
-		db_set_active($previous_db);  // now use drupal database
+		tripal_db_set_active($previous_db);  // now use drupal database
 	}
 	// If the analysis has a name, use it as the node title. If not, construct
 	// the title using program programversion, and sourcename
@@ -489,7 +489,7 @@ function tripal_analysis_interpro_parseHTMLFile ($analysis_id, $interprofile, $p
 
 	// Get cvterm_id for 'analysis_interpro_output_iteration_hits' which is required
 	// for inserting into the analysisfeatureprop table
-	$previous_db = db_set_active('chado'); // use chado database
+	$previous_db = tripal_db_set_active('chado'); // use chado database
 	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
           "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
           "WHERE CVT.name = 'analysis_interpro_output_hit' ".
@@ -527,9 +527,9 @@ function tripal_analysis_interpro_parseHTMLFile ($analysis_id, $interprofile, $p
             $idx_iterations ++;
             if ($idx_iterations % $interval == 0) {
                     $percentage = (int) ($idx_iterations / $no_iterations * 100);
-                    db_set_active($previous_db);
+                    tripal_db_set_active($previous_db);
                     tripal_job_set_progress($job_id, $percentage);
-                    $previous_db = db_set_active('chado');
+                    $previous_db = tripal_db_set_active('chado');
                     print $percentage."% ";
             }
 
@@ -704,7 +704,7 @@ function tripal_analysis_interpro_parseHTMLFile ($analysis_id, $interprofile, $p
             }
         }
     }
-    db_set_active ($previous_db); // Use drupal database
+    tripal_db_set_active ($previous_db); // Use drupal database
     print "Done.\nSuccessful and failed entries have been saved in the log file:\n $logfile\n";
 	
     fwrite($log, "\n");
@@ -786,7 +786,7 @@ function theme_parse_EBI_Interpro_XML_index_version ($node) {
 function tripal_get_interpro_results($feature_id){
 	// Get cvterm_id for 'analysis_interpro_output_hit' which is required
 	// for inserting into the analysisfeatureprop table
-	$previous_db = db_set_active('chado');
+	$previous_db = tripal_db_set_active('chado');
 	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT 
 	        INNER JOIN cv ON cv.cv_id = CVT.cv_id
 	        WHERE CVT.name = 'analysis_interpro_output_hit'
@@ -823,10 +823,10 @@ function tripal_get_interpro_results($feature_id){
          		  WHERE analysis_id = %d";
          $ana_details = db_fetch_object(db_query($sql, $ana->aid));
          // Find node id for the analysis
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
          $ana_url = url("node/".$ana_nid);
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
        
          // Show content
          $content .= "<strong>Analysis Date:</strong> $ana_details->time
@@ -847,7 +847,7 @@ function tripal_get_interpro_results($feature_id){
       $content .= '</td></tr></table></span></div></div>';
    }
      
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 	return $content;
 }
 
@@ -858,7 +858,7 @@ function tripal_get_interpro_results($feature_id){
 function tripal_get_interpro_results_index_version($feature_id){
    // Get cvterm_id for 'analysis_interpro_output_hit' which is required
    // for inserting into the analysisfeatureprop table
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
           "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
           "WHERE CVT.name = 'analysis_interpro_output_hit' ".
@@ -872,7 +872,7 @@ function tripal_get_interpro_results_index_version($feature_id){
           "WHERE feature_id = %d ".
           "AND AFP.type_id = %d ";
    $result = db_query($sql, $feature_id, $type_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    if (db_result($result)) {
       // get the HTML content for viewing each of the XML file
       while ($analysisfeatureprop = db_fetch_object($result)) {

+ 48 - 48
tripal_analysis_kegg/tripal_analysis_kegg.module

@@ -160,9 +160,9 @@ function tripal_analysis_kegg_brite($analysis_id, $type_id, $ajax){
               WHERE AP.analysis_id = %d
               AND CVT.definition LIKE 'KEGG BRITE term: %'
               ORDER BY CVT.cvterm_id";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $result = db_query($sql, $analysis_id);
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       while ($brite_term = db_fetch_object($result)) {
          $url = url("brite/$analysis_id/$brite_term->cvterm_id/1");
          $content .= "<li class=\"tripal_kegg_brite_terms\"><a onclick=\"return tripal_update_brite(".
@@ -178,7 +178,7 @@ function tripal_analysis_kegg_brite($analysis_id, $type_id, $ajax){
    // If called by ajax, generate tree structure
    } else {
       // Get BRITE term from cvterm table
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = 'SELECT name FROM {cvterm} WHERE cvterm_id=%d';
       $brite_term = db_result(db_query($sql, $type_id));
 
@@ -191,7 +191,7 @@ function tripal_analysis_kegg_brite($analysis_id, $type_id, $ajax){
            AND AP.analysis_id = %d";
 
       $result = db_fetch_object(db_query($sql, $brite_term, $analysis_id));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       $content .= "<div class=\"tripal_kegg_brite_tree\" id=\"tripal_kegg_brite_tree_$type_id\">$result->value</div>";
    }
     
@@ -354,9 +354,9 @@ function chado_analysis_kegg_insert($node){
       $sql = "SELECT analysis_id ".
              "FROM {Analysis} ".
              "WHERE analysis_id = %d ";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $analysis = db_fetch_object(db_query($sql, $node->analysis_id));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
    }
 
    // If the analysis doesn't exist then let's create it in chado.
@@ -366,7 +366,7 @@ function chado_analysis_kegg_insert($node){
              "  (name, description, program, programversion, algorithm, ".
              "   sourcename, sourceversion, sourceuri, timeexecuted) ".
              "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       db_query($sql,$node->analysisname, $node->description,
       $node->program,$node->programversion,$node->algorithm,
       $node->sourcename, $node->sourceversion, $node->sourceuri,
@@ -396,7 +396,7 @@ function chado_analysis_kegg_insert($node){
       $keggsettings = $node->hierfile;
       db_query($sql, $analysis_id, $type_id, $keggsettings);
 
-      db_set_active($previous_db);  // switch back to drupal database
+      tripal_db_set_active($previous_db);  // switch back to drupal database
       // Add a job if the user wants to parse the html output
       if($node->keggjob) {
          $job_args[0] = $analysis_id;
@@ -465,7 +465,7 @@ function chado_analysis_kegg_delete($node){
    db_query($sql_del, $node->nid, $node->vid);
 
    //Remove from analysisfeatureprop, analysisfeature, analysis, and analysisprop tables
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE analysis_id=%d";
    $results = db_query($sql, $analysis_id);
    while ($af = db_fetch_object($results)) {
@@ -474,7 +474,7 @@ function chado_analysis_kegg_delete($node){
    db_query("DELETE FROM {analysisfeature} WHERE analysis_id = %d", $analysis_id);
    db_query("DELETE FROM {analysisprop} WHERE analysis_id = %d", $analysis_id);
    db_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 }
 
 /*******************************************************************************
@@ -510,7 +510,7 @@ function chado_analysis_kegg_update($node){
              "    timeexecuted = '%s' ".
              "WHERE analysis_id = %d ";
 
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       db_query($sql, $node->analysisname, $node->description, $node->program,
       $node->programversion,$node->algorithm,$node->sourcename,
       $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
@@ -528,7 +528,7 @@ function chado_analysis_kegg_update($node){
       $keggsettings = $node->hierfile;
       db_query($sql, $keggsettings, $analysis_id, $type_id);
 
-      db_set_active($previous_db);  // switch back to drupal database
+      tripal_db_set_active($previous_db);  // switch back to drupal database
       // Add a job if the user wants to parse the html output
       if($node->keggjob) {
          $job_args[0] = $analysis_id;
@@ -575,7 +575,7 @@ function chado_analysis_kegg_load($node){
              "  sourceuri, timeexecuted ".
              "FROM {Analysis} ".
              "WHERE Analysis_id = $ana_node->analysis_id";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $additions = db_fetch_object(db_query($sql));
 
       // get cvterm_id for 'analysis_kegg_settings'
@@ -592,7 +592,7 @@ function chado_analysis_kegg_load($node){
       
       $additions->hierfile = $analysisprop;
 
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
    // If the analysis has a name, use it as the node title. If not, construct
    // the title using program programversion, and sourcename
@@ -674,14 +674,14 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
                                    WHERE CV.name = 'tripal' AND CVT.name = '%s'
                                    )
                    ";
-            $previous_db = db_set_active('chado');
+            $previous_db = tripal_db_set_active('chado');
             $oldvalue = db_result(db_query($sql, $analysis_id, $type));
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
             
             // Insert the content
             if ($oldvalue != $content) {
             	
-            	$previous_db = db_set_active('chado'); // Use chado database
+            	$previous_db = tripal_db_set_active('chado'); // Use chado database
             	// Get type_id for the BRITE term
             	$sql = "SELECT cvterm_id 
                        FROM {cvterm} CVT 
@@ -697,7 +697,7 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
                        VALUES (%d, %d,'$content')";   
                
                db_query($sql, $analysis_id, $brite_cvterm_id);
-               db_set_active($previous_db); // Use drupal database
+               tripal_db_set_active($previous_db); // Use drupal database
             }
             
          }
@@ -735,14 +735,14 @@ function tripal_analysis_kegg_parse_keg_file ($file,&$type,$analysis_id, $base_p
          // Set type as the matched term in the DEFINITION line and add it as a new cvterm
          $type = $matches[1];
          // Before inserting, make sure this cvterm doesn't exist
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $sql = "SELECT cvterm_id 
                  FROM {cvterm} CVT
                  INNER JOIN cv ON cv.cv_id = CVT.cv_id
                  WHERE cv.name = 'tripal'
                  AND CVT.name = '%s'";
          $type_id = db_result(db_query($sql, $type));
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          if (!$type_id) {
             tripal_add_cvterms($type, "KEGG BRITE term: $type");
             // Get newly added type_id
@@ -751,9 +751,9 @@ function tripal_analysis_kegg_parse_keg_file ($file,&$type,$analysis_id, $base_p
                     INNER JOIN cv ON cv.cv_id = CVT.cv_id
                     WHERE cv.name = 'tripal'
                     AND CVT.name = '%s'";
-            $previous_db = db_set_active('chado');
+            $previous_db = tripal_db_set_active('chado');
             $type_id = db_result(db_query($sql, $type));
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
          }
       }
       // get the depth of the hierarch (e.g. A,B,C or D);
@@ -784,25 +784,25 @@ function tripal_analysis_kegg_parse_keg_file ($file,&$type,$analysis_id, $base_p
                  INNER JOIN cv ON cv.cv_id = CVT.cv_id
                  WHERE cv.name = 'tripal'
                  AND CVT.name = '%s'";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $brite_data_type_id = db_result(db_query($sql, 'kegg_brite_data'));
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          
          $uniquename = $mat[1];
          // Find feature_id using uniquename
          $sql = "SELECT feature_id FROM {feature} WHERE uniquename = '%s'";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $feature_id = db_result(db_query($sql, $uniquename)); // retrive first returned feature_id (assuming uniquename is unique)
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          // Get the higest rank for this feature_id in analysisfeatureprop table
          $sql = "SELECT MAX(rank) FROM {analysisfeatureprop} AFP ".
                 "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".       
                 "WHERE feature_id=%d ".
                 "AND analysis_id=%d ".
                 "AND type_id=%d ";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $afp =  db_fetch_object(db_query($sql, $feature_id, $analysis_id, $brite_data_type_id));
-         db_set_active($prevous_db);
+         tripal_db_set_active($prevous_db);
          $hi_rank = 0;
          if ($afp) {
             $hi_rank = $afp->max + 1;
@@ -812,22 +812,22 @@ function tripal_analysis_kegg_parse_keg_file ($file,&$type,$analysis_id, $base_p
          //------------------------------------------------------
          $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
                 "VALUES (%d, %d)";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          db_query ($sql, $feature_id, $analysis_id);
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          // Get the newly inserted analysisfeature_id
          $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE feature_id = %d AND analysis_id = %d";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $analysisfeature_id = db_result(db_query($sql, $feature_id, $analysis_id));
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          //------------------------------------------------------
          // Insert into analysisfeatureprop table
          //------------------------------------------------------
          // Before inserting, make sure it's not a duplicate
          $sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id = %d AND type_id = %d";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $result = db_query($sql, $analysisfeature_id, $brite_data_type_id);
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          $duplicate = 0;
          while ($afp_value = db_fetch_object($result)) {
             preg_match("/<a.+?>(.+)<\/a>/",$afp_value->value,$old_ids);
@@ -839,9 +839,9 @@ function tripal_analysis_kegg_parse_keg_file ($file,&$type,$analysis_id, $base_p
          if (!$duplicate) {
             $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
                    "VALUES (%d, %d, '%s', %d)";
-            $previous_db = db_set_active('chado');
+            $previous_db = tripal_db_set_active('chado');
             db_query($sql, $analysisfeature_id, $brite_data_type_id, $mat[2], $hi_rank);
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
          }
          // Add link to each matched feature
          $feature_url = url("$prefix$feature_id");
@@ -932,7 +932,7 @@ function theme_tripal_analysis_kegg_search_index($node){
               INNER JOIN cv ON cv.cv_id = CVT.cv_id
               WHERE cv.name = 'tripal'
               AND CVT.name = '%s'";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $brite_data_type_id = db_result(db_query($sql, 'kegg_brite_data'));
       
       // Get analysis id
@@ -958,10 +958,10 @@ function theme_tripal_analysis_kegg_search_index($node){
                     WHERE analysis_id = %d";
             $ana_details = db_fetch_object(db_query($sql, $ana->aid));
             // Find node id for the analysis
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
             $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
             $ana_url = url("node/".$ana_nid);
-            $previous_db = db_set_active('chado');
+            $previous_db = tripal_db_set_active('chado');
        
             // Show content
             $content .= "$ana_details->name";
@@ -979,7 +979,7 @@ function theme_tripal_analysis_kegg_search_index($node){
             }
          }
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       return $content;
    }
 }
@@ -1031,9 +1031,9 @@ function tripal_analysis_kegg_full_report($analysis_id){
            WHERE AP.analysis_id = %d
               AND CVT.definition LIKE 'KEGG BRITE term: %'
            ORDER BY CVT.cvterm_id";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $result = db_query($sql, $analysis_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    if (db_result($result)) {
       $content = tripal_analysis_kegg_brite($analysis_id, $type_id, 0);
@@ -1086,7 +1086,7 @@ function tripal_analysis_kegg_feature_add($node) {
               INNER JOIN cv ON cv.cv_id = CVT.cv_id
               WHERE cv.name = 'tripal'
               AND CVT.name = '%s'";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $brite_data_type_id = db_result(db_query($sql, 'kegg_brite_data'));
       
       // Get analysis id
@@ -1119,10 +1119,10 @@ function tripal_analysis_kegg_feature_add($node) {
                     WHERE analysis_id = %d";
             $ana_details = db_fetch_object(db_query($sql, $ana->aid));
             // Find node id for the analysis
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
             $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
             $ana_url = url("node/".$ana_nid);
-            $previous_db = db_set_active('chado');
+            $previous_db = tripal_db_set_active('chado');
        
             // Show content
             $content .= "<strong>Analysis Date:</strong> $ana_details->time
@@ -1143,7 +1143,7 @@ function tripal_analysis_kegg_feature_add($node) {
          }
          $content .= '</td></tr></table></span></div></div>';
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
    return $content;
 }
 /************************************************************************
@@ -1202,9 +1202,9 @@ function tripal_analysis_kegg_select_form(&$form_state = NULL,$node){
      WHERE organism_id = %d
      ORDER BY analysis_id DESC
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$node->organism_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    $analyses = array();
    $analyses[''] = '';

+ 2 - 2
tripal_analysis_unigene/tripal_analysis_unigene.install

@@ -13,7 +13,7 @@ function tripal_analysis_unigene_install() {
    // required information into the {tripal_analysis} table.
    tripal_analysis_register_child('tripal_analysis_unigene');
 
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    if (db_table_exists('unigene_libraries_mview')) {
       $sql = "DROP TABLE unigene_libraries_mview";
       db_query($sql);
@@ -22,7 +22,7 @@ function tripal_analysis_unigene_install() {
       $sql = "DROP TABLE unigene_mview";
       db_query($sql);
    }
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    
    tripal_add_cvterms('unigene_version','The version number for the unigene ".
      "(e.g. v1, v2, etc...) ');

+ 14 - 14
tripal_analysis_unigene/tripal_analysis_unigene.module

@@ -147,11 +147,11 @@ function theme_tripal_analysis_unigene_search_index ($node) {
                    "FROM {featureloc} ".
                    "WHERE feature_id = $result->feature_id ".
                    "ORDER BY rank";
-            $previous_db = db_set_active ('chado');
+            $previous_db = tripal_db_set_active ('chado');
             $contig_fid = db_result(db_query($sql));
             $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
             $contig_name = db_result(db_query($sql));
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
             $sql = "SELECT nid ".
                    "FROM {chado_feature} ".
                    "WHERE feature_id = $contig_fid";
@@ -207,11 +207,11 @@ function theme_tripal_analysis_unigene_search_result ($node) {
                    "FROM {featureloc} ".
                    "WHERE feature_id = $result->feature_id ".
                    "ORDER BY rank";
-            $previous_db = db_set_active ('chado');
+            $previous_db = tripal_db_set_active ('chado');
             $contig_fid = db_result(db_query($sql));
             $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
             $contig_name = db_result(db_query($sql));
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
             $sql = "SELECT nid ".
                    "FROM {chado_feature} ".
                    "WHERE feature_id = $contig_fid";
@@ -286,11 +286,11 @@ function theme_tripal_analysis_unigene_feature_alignments($node) {
                    "FROM {featureloc} ".
                    "WHERE feature_id = $result->feature_id ".
                    "ORDER BY rank";
-            $previous_db = db_set_active ('chado');
+            $previous_db = tripal_db_set_active ('chado');
             $contig_fid = db_result(db_query($sql));
             $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
             $contig_name = db_result(db_query($sql));
-            db_set_active($previous_db);
+            tripal_db_set_active($previous_db);
             $sql = "SELECT nid ".
                    "FROM {chado_feature} ".
                    "WHERE feature_id = $contig_fid";
@@ -402,7 +402,7 @@ function tripal_analysis_unigene_get_alignments($map) {
           "WHERE srcfeature_id = %d AND ".
           "  NOT(CVT.name = 'match' or CVT.name = 'match_part') ".
           "ORDER BY FL.fmin, FL.fmax";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$map->feature_id);
    $alignments = array();
    $i=0;
@@ -436,7 +436,7 @@ function tripal_analysis_unigene_get_alignments($map) {
     }
     $additions->properties = $properties;
     */
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    return $additions;
 }
 /************************************************************************
@@ -470,18 +470,18 @@ function tripal_analysis_unigene_organism_add($node){
    // get information about this organism 
    $sql = "SELECT * FROM {organism} ".
           "WHERE organism_id = %d";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $organism = db_fetch_object(db_query($sql,$org_id->organism_id));
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // get information about this assembly and add it to the items in this node
    $sql = "SELECT * FROM {unigene_mview} ".
           "WHERE organism_id = %d ".
           "ORDER BY analysis_id DESC";
 
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query($sql,$org_id->organism_id);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    //$i = 0;
    //while ($assembly = db_fetch_object($results)){
@@ -490,9 +490,9 @@ function tripal_analysis_unigene_organism_add($node){
       //$libraries_sql = "SELECT library_id, library_name ".
                        //"FROM {unigene_libraries_mview} ".
                        //"WHERE analysis_id = %d ";
-      //$previous_db = db_set_active('chado');  // use chado database
+      //$previous_db = tripal_db_set_active('chado');  // use chado database
       //$libraries_result = db_query($libraries_sql,$assembly->analysis_id);
-      //db_set_active($previous_db);  // now use drupal database
+      //tripal_db_set_active($previous_db);  // now use drupal database
       //$library_sql = "SELECT * FROM {chado_library} WHERE library_id = %d";
       //$k = 0;
       //while ($library = db_fetch_object($libraries_result)){

+ 15 - 13
tripal_core/cvterms.php

@@ -9,21 +9,23 @@
 function tripal_add_cvterms ($name,$definition,$cv_name = 'tripal',$db_name='tripal'){
    
    
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = '$cv_name'"));
    if (!$cv->cv_id) {
-      db_set_active($previous_db);
-      tripal_add_cv('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc');
-      db_set_active('chado');
+      tripal_db_set_active($previous_db);
+      tripal_add_cv('tripal', 'Terms used by Tripal for modules to manage data such as that 
+                               stored in property tables like featureprop, analysisprop, etc');
+      tripal_db_set_active('chado');
       $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = '$cv_name'"));
    }
    $db = db_fetch_object(db_query("SELECT * FROM {db} WHERE name = '$db_name'"));
 	if (!$db->db_id) {
-	   db_set_active($previous_db);
+	   tripal_db_set_active($previous_db);
 	   tripal_add_db('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms', '', '');
-	   db_set_active('chado');
+	   tripal_db_set_active('chado');
 	   $db = db_fetch_object(db_query("SELECT * FROM {db} WHERE name = '$db_name'"));
 	}
+
 	// check to see if the dbxref already exists if not then add it
 	$sql = "SELECT * FROM {dbxref} WHERE db_id = $db->db_id and accession = '$name'";
 	$dbxref = db_fetch_object(db_query($sql));
@@ -41,7 +43,7 @@ function tripal_add_cvterms ($name,$definition,$cv_name = 'tripal',$db_name='tri
       $result = db_query("INSERT INTO {cvterm} (cv_id,name,definition,dbxref_id) ".
                          "VALUES ($cv->cv_id,'$name','$definition',$dbxref->dbxref_id)");
 	}
-   db_set_active($previous_db);  // now use drupal database	
+   tripal_db_set_active($previous_db);  // now use drupal database	
 	
    if(!$result){
      // TODO -- ERROR HANDLING
@@ -51,7 +53,7 @@ function tripal_add_cvterms ($name,$definition,$cv_name = 'tripal',$db_name='tri
 *
 */
 function tripal_add_db($db_name,$description,$urlprefix,$url){
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
 
    // use this SQL statement to get the db_id for the database name
    $id_sql = "SELECT db_id FROM {db} WHERE name = '%s'";
@@ -69,7 +71,7 @@ function tripal_add_db($db_name,$description,$urlprefix,$url){
       # now get the id for this new db entry
       $db = db_fetch_object(db_query($id_sql,$db_name));
    }
-   db_set_active($previous_db);  // now use drupal database	
+   tripal_db_set_active($previous_db);  // now use drupal database	
    return $db->db_id;
 }
 
@@ -77,10 +79,10 @@ function tripal_add_db($db_name,$description,$urlprefix,$url){
 *
 */
 function tripal_delete_db($db_name){
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $sql = "DELETE FROM {db} WHERE name ='%s'";
    db_query($sql,$db_name);
-   db_set_active($previous_db);  // now use drupal database 
+   tripal_db_set_active($previous_db);  // now use drupal database 
    
 }
 
@@ -88,7 +90,7 @@ function tripal_delete_db($db_name){
 *
 */
 function tripal_add_cv($cv_name,$definition){
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
 
    // use this SQL statement to get the db_id for the database name
    $id_sql = "SELECT cv_id FROM {cv} WHERE name = '%s'";
@@ -106,6 +108,6 @@ function tripal_add_cv($cv_name,$definition){
       # now get the id for this new db entry
       $cv = db_fetch_object(db_query($sql,$cv_name));
    }
-   db_set_active($previous_db);  // now use drupal database	
+   tripal_db_set_active($previous_db);  // now use drupal database	
    return $cv->cv_id;
 }

+ 8 - 8
tripal_core/mviews.php

@@ -32,12 +32,12 @@ function tripal_add_mview ($name,$modulename,$mv_table,$mv_specs,$indexed,$query
    if(drupal_write_record('tripal_mviews',$record)){
 
       // drop the table from chado if it exists
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       if (db_table_exists($mv_table)) {
          $sql = "DROP TABLE $mv_table";
          db_query($sql);
       }
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       
       // now add the table for this view
       $index = '';
@@ -45,9 +45,9 @@ function tripal_add_mview ($name,$modulename,$mv_table,$mv_specs,$indexed,$query
          $index = ", CONSTRAINT ". $mv_table . "_index UNIQUE ($indexed) ";
       }
       $sql = "CREATE TABLE {$mv_table} ($mv_specs $index)"; 
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       if($results){
          drupal_set_message(t("View '$name' created"));
       } else {
@@ -101,12 +101,12 @@ function tripal_mviews_action ($op,$mview_id){
       db_query($sql);
 		
 	   // drop the table from chado if it exists
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       if (db_table_exists($mview->mv_table)) {
          $sql = "DROP TABLE $mview->mv_table";
          db_query($sql);
       }
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
    return '';
 }
@@ -117,10 +117,10 @@ function tripal_update_mview ($mview_id){
    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
    $mview = db_fetch_object(db_query($sql,$mview_id));
    if($mview){
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
 	   $results = db_query("DELETE FROM {$mview->mv_table}");
       $results = db_query("INSERT INTO $mview->mv_table ($mview->query)");
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       if($results){
 	      $record = new stdClass();
          $record->mview_id = $mview_id;

+ 2 - 2
tripal_core/tripal_core.install

@@ -17,7 +17,7 @@ function tripal_core_install(){
 
 
   // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist
-  $previous_db = db_set_active('chado');  // use chado database
+  $previous_db = tripal_db_set_active('chado');  // use chado database
   if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
      $results = db_query("INSERT INTO {cv} (name,definition) ".
 	                     "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
@@ -26,7 +26,7 @@ function tripal_core_install(){
      $results = db_query("INSERT INTO {db} (name,description) ".
 	                     "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
   }  
-  db_set_active($previous_db);  // now use drupal database
+  tripal_db_set_active($previous_db);  // now use drupal database
 
   // create the tables that manage materialized views and jobs
   drupal_install_schema('tripal_core');

+ 35 - 4
tripal_core/tripal_core.module

@@ -1,9 +1,5 @@
 <?php
 
-//
-// Copyright 2009 Clemson University
-//
-
 require_once "jobs.php";
 require_once "mviews.php";
 require_once "cvterms.php";
@@ -171,3 +167,38 @@ function tripal_core_admin () {
    
    return system_settings_form($form);
 }
+/************************************************************************
+* 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.
+*/
+function tripal_db_set_active($dbname){
+   global $db_url, $db_type;
+
+   // 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
+      if(is_array($db_url)){ 
+         if(isset($db_url[$dbname])){
+            return tripal_db_set_active($dbname);
+         } 
+      }
+
+      // here we make the assumption that the default database schema is
+      // 'public'.  This will most likely always be the case but if not,
+      // then this code will break
+      if(strcmp($dbname,'chado')==0){
+         db_query("set search_path to %s",'chado,public');  
+         return 'public';
+      } 
+      else {
+         db_query("set search_path to %s",'public,chado');  
+         return 'chado';
+      }
+   }
+   else return tripal_db_set_active($dbname);
+}

+ 2 - 2
tripal_cv/charts.php

@@ -57,9 +57,9 @@ function tripal_cv_count_chart($cnt_table, $fk_column,
    ";    
 
    $features = array();
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
    $data = array();
    $axis = array();
    $legend = array();

+ 5 - 2
tripal_cv/obo_loader.php

@@ -96,13 +96,15 @@ function tripal_cv_load_obo_add_ref($name,$path){
 */
 function tripal_cv_load_obo_v1_2($file,$jobid = NULL,&$newcvs) {
 
+   global $previous_db;
+
    $header = array();
    $obo = array();
    
    print "Opening File $file\n";
 
    // set the search path
-   db_query("set search_path to chado,public");  // TODO: fix this
+   $previous_db = tripal_db_set_active('chado');
 
    // make sure we have an 'internal' and a '_global' database
    if(!tripal_cv_obo_add_db('internal')){
@@ -148,6 +150,7 @@ function tripal_cv_obo_quiterror ($message){
 */
 function tripal_cv_obo_loader_done (){
    // return the search path to normal
+   tripal_db_set_active($previous_db);
    db_query("set search_path to public");  
    return '';
 }
@@ -345,7 +348,7 @@ function tripal_cv_obo_add_cv($name,$comment){
 function tripal_cv_obo_add_cvterm_prop($cvterm,$property,$value,$rank){
 
    // make sure the 'cvterm_property_type' CV exists
-   $cv = tripal_cv_obo_add_cv($property,'');
+   $cv = tripal_cv_obo_add_cv('cvterm_property_type','');
    if(!$cv){ 
       tripal_cv_obo_quiterror("Cannot add/find cvterm_property_type cvterm");
    }

+ 16 - 16
tripal_cv/trees.php

@@ -90,9 +90,9 @@ function tripal_cv_init_tree($cv_id,$cnt_table = null, $fk_column = null,
       FROM {cv_root_mview} CRM
       WHERE cv_id = %d
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$cv_id);
-   db_set_active($previous_db); 
+   tripal_db_set_active($previous_db); 
 
    // prepare the SQL statement that will allow us to pull out count 
    // information for each term in the tree.
@@ -113,9 +113,9 @@ function tripal_cv_init_tree($cv_id,$cnt_table = null, $fk_column = null,
       $name = $term->name;
       $count = 0;
       if($cnt_table){
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $cnt_results = db_query($cnt_sql,$term->cvterm_id);
-         db_set_active($previous_db); 
+         tripal_db_set_active($previous_db); 
          while($cnt = db_fetch_object($cnt_results)){
             $count += $cnt->cnt;
          }
@@ -156,9 +156,9 @@ function tripal_cv_get_term_children($cvterm_id,$cnt_table = null,
       WHERE CVTR.object_id = %d
       ORDER BY CVT1.name
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$cvterm_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
 
    // prepare the SQL statement that will allow us to pull out count 
@@ -181,9 +181,9 @@ function tripal_cv_get_term_children($cvterm_id,$cnt_table = null,
       $name = $term->subject_name;
       $count = 0;
       if($cnt_table){
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $cnt_results = db_query($cnt_sql,$term->subject_id);
-         db_set_active($previous_db); 
+         tripal_db_set_active($previous_db); 
          while($cnt = db_fetch_object($cnt_results)){
             $count += $cnt->num_items;
          }
@@ -192,9 +192,9 @@ function tripal_cv_get_term_children($cvterm_id,$cnt_table = null,
          }
       }
       // check if we have any children if so then set the value
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $children = db_fetch_object(db_query($sql,$term->subject_id));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       $state = 'leaf';
       if($children){
          $state = 'closed';
@@ -259,9 +259,9 @@ function tripal_cv_cvterm_info($cvterm_id){
         INNER JOIN DB on DBX.db_id = DB.db_id
       WHERE CVT.cvterm_id = %d
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $cvterm = db_fetch_object(db_query($sql,$cvterm_id));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    $sql = "
       SELECT CVTS.synonym, CVT.name as cvname
       FROM {cvtermsynonym} CVTS
@@ -269,9 +269,9 @@ function tripal_cv_cvterm_info($cvterm_id){
       WHERE CVTS.cvterm_id = %d
     
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $results = db_query($sql,$cvterm_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    while($synonym = db_fetch_object($results)){
       $synonym_rows .= "<b>$synonym->cvname:</b>  $synonym->synonym<br>";
    }
@@ -316,9 +316,9 @@ function tripal_cv_list_form($form_state) {
          INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
          INNER JOIN CV on CV.cv_id = CVT.cv_id
    ";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query ($sql);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    $blastdbs = array();
    $cvs[''] = '';
    while ($cv = db_fetch_object($results)){

+ 2 - 2
tripal_cv/tripal_cv.install

@@ -10,12 +10,12 @@ function tripal_cv_install(){
 
    // Add the materialized view needed to keep track of the 
    // 
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    if (db_table_exists('cv_root_mview')) {
       $sql = "DROP TABLE cv_root_mview";
       db_query($sql);
    }
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    // Create the MView
    tripal_add_mview(

+ 20 - 20
tripal_cv/tripal_cv.module

@@ -191,11 +191,11 @@ function tripal_cv_admin_page(){
 */
 function tripal_cv_select_form(){
 
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	// get a list of db from chado for user to choose
 	$sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
 	$results = db_query ($sql);
-	db_set_active($previous_db); // use drupal database
+	tripal_db_set_active($previous_db); // use drupal database
 
 	$cvs = array();
    $cvs[] = '';
@@ -379,9 +379,9 @@ function tripal_cv_edit_form(&$form_state = NULL,$cvid = NULL){
 
   
    $sql = "SELECT * FROM {cv} WHERE cv_id = %d ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $cv = db_fetch_object(db_query($sql,$cvid));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
 
    # set the default values.  If there is a value set in the 
@@ -456,9 +456,9 @@ function tripal_cv_edit_form_submit($form, &$form_state){
            definition = '%s'
          WHERE cv_id = %d
       ";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $db = db_query($sql,$name,$desc,$cvid);
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if($db){
         drupal_set_message("Controlled vocabulary updated");
       } else {
@@ -470,9 +470,9 @@ function tripal_cv_edit_form_submit($form, &$form_state){
          DELETE FROM {cv}
          WHERE cv_id = %d
       ";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $db = db_query($sql,$cvid);
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if($db){
         drupal_set_message("Controlled vocabulary deleted");
       } else {
@@ -497,9 +497,9 @@ function tripal_cv_add_form_submit($form, &$form_state){
       VALUES 
        ('%s','%s')
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $db = db_query($sql,$name,$desc);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    if($db){
      drupal_set_message("Controlled vocabulary added");
    } else {
@@ -548,11 +548,11 @@ function tripal_cv_obo_form_submit($form, &$form_state){
 */
 function tripal_cv_cvtermpath_form () {
 
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	// get a list of db from chado for user to choose
 	$sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
 	$results = db_query ($sql);
-	db_set_active($previous_db); // use drupal database
+	tripal_db_set_active($previous_db); // use drupal database
 
 	$cvs = array();
    $cvs[] = '';
@@ -588,9 +588,9 @@ function tripal_cv_cvtermpath_form_validate($form, &$form_state) {
    $cvid =  $form_state['values']['cvid'];
 
    // first get the controlled vocabulary name:
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE cv_id = %d",$cvid));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    // Submit a job to update cvtermpath
    $job_args = array($cvid);
@@ -606,14 +606,14 @@ function tripal_cv_cvtermpath_form_validate($form, &$form_state) {
 function tripal_cv_update_cvtermpath($cvid = NULL, $job_id = NULL) {
 
    // first get the controlled vocabulary name:
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE cv_id = %d",$cvid));
    print "\nUpdating cvtermpath for $cv->name...\n";
 
    // now fill the cvtermpath table
    $sql = "SELECT * FROM fill_cvtermpath('%s')";
    db_query($sql,$cv->name);         
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    return;
 }
 
@@ -637,9 +637,9 @@ function tripal_cv_get_cv_id($cv_name){
    $sql = "
       SELECT cv_id FROM {cv} WHERE name = '%s'
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $cv = db_fetch_object(db_query($sql,$cv_name));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    return $cv->cv_id;
 }
 /*************************************************************************
@@ -652,9 +652,9 @@ function tripal_cv_cvterm_edit($cvterm_id){
         INNER JOIN CV on CVT.cv_id = CV.cv_id
       WHERE CVT.cvterm_id = %d
    ";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $cvterm = db_fetch_object(db_query($sql,$cvterm_id));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    return theme('tripal_cv_cvterm_edit',$cvterm);
 }
 /*************************************************************************

+ 10 - 10
tripal_db/tripal_db.module

@@ -70,11 +70,11 @@ function tripal_db_admin_page(){
 */
 function tripal_db_select_form(){
 
-	$previous_db = db_set_active('chado');  // use chado database
+	$previous_db = tripal_db_set_active('chado');  // use chado database
 	// get a list of db from chado for user to choose
 	$sql = "SELECT * FROM {db} WHERE NOT name = 'tripal' ORDER BY name ";
 	$results = db_query ($sql);
-	db_set_active($previous_db); // use drupal database
+	tripal_db_set_active($previous_db); // use drupal database
 
 	$dbs = array();
    $dbs[] = '';
@@ -114,9 +114,9 @@ function tripal_db_form(&$form_state = NULL,$dbid = NULL){
    // get this requested database
    if($dbid){
       $sql = "SELECT * FROM {db} WHERE db_id = $dbid ";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $db = db_fetch_object(db_query($sql));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
 
 
       # set the default values.  If there is a value set in the 
@@ -228,9 +228,9 @@ function tripal_db_form_submit($form, &$form_state){
               urlprefix = '%s'
             WHERE db_id = %d
          ";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $db = db_query($sql,$name,$desc,$url,$urlp,$dbid);
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          if($db){
            drupal_set_message("External database updated");
          } else {
@@ -242,9 +242,9 @@ function tripal_db_form_submit($form, &$form_state){
             DELETE FROM {db}
             WHERE db_id = %d
          ";
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $db = db_query($sql,$dbid);
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
          if($db){
            drupal_set_message("External database deleted");
          } else {
@@ -259,9 +259,9 @@ function tripal_db_form_submit($form, &$form_state){
          VALUES 
           ('%s','%s','%s','%s')
       ";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $db = db_query($sql,$name,$desc,$url,$urlp);
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if($db){
         drupal_set_message("External database added");
       } else {

+ 6 - 6
tripal_feature/syncFeatures.php

@@ -67,10 +67,10 @@ function tripal_feature_sync_features ($max_sync = 0, $job_id = NULL){
           "WHERE ($where_cvt) AND ($where_org) ".
           "ORDER BY feature_id";
    // get the list of features
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query($sql);
 
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // load into ids array
    $count = 0;
@@ -143,9 +143,9 @@ function tripal_feature_sync_feature ($feature_id){
            "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
            "  INNER JOIN Organism O ON F.organism_id = O.organism_ID ".
            "WHERE F.feature_id = %d";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $feature = db_fetch_object(db_query($fsql,$feature_id));
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // check to make sure that we don't have any nodes with this feature name as a title
    // but without a corresponding entry in the chado_feature table if so then we want to
@@ -260,9 +260,9 @@ function organism_get_synced() {
 
    // iterate through the organisms and build an array of those that are synced
    while($org = db_fetch_object($orgs)){
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $info = db_fetch_object(db_query($csql,$org->organism_id));
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       $org_list[] = $info;
    }    
    return $org_list;

+ 2 - 2
tripal_feature/tripal_feature.install

@@ -29,7 +29,7 @@ function tripal_feature_update_6000(){
    return $ret;
 }
 /*******************************************************************************
-* Implementation of hook_schema().
+
 */
 function tripal_feature_add_organism_count_mview(){
    $view_name = 'organism_feature_count';
@@ -151,4 +151,4 @@ function tripal_feature_requirements($phase) {
       }
    }
    return $requirements;
-}
+}

+ 40 - 40
tripal_feature/tripal_feature.module

@@ -260,9 +260,9 @@ function get_tripal_feature_admin_form_sync_set (&$form) {
   
    // get the list of organisms which will be synced.
    $feature_sql = "SELECT * FROM {Feature} WHERE uniquename = '%s' and organism_id = %d";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $feature = db_fetch_object(db_query($feature_sql,$node->title,$node->organism_id));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    // define the fieldsets
    $form['sync'] = array(
@@ -416,9 +416,9 @@ function chado_feature_insert($node){
    // TODO: the unique index in chado for this also includes the type_id. If the site
    // ever needs to have the same feature name for different types then this will break.
    $feature_sql = "SELECT * FROM {Feature} WHERE uniquename = '%s' and organism_id = %d";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $feature = db_fetch_object(db_query($feature_sql,$node->title,$node->organism_id));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    // if the feature doesn't exist then let's create it in chado.
    if(!$feature){
@@ -435,7 +435,7 @@ function chado_feature_insert($node){
       }
 
       // use chado database
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       db_query($sql,$node->organism_id,$node->title,$node->title,
       $residues,strlen($residues),$obsolete,$node->feature_type);
 
@@ -443,7 +443,7 @@ function chado_feature_insert($node){
       $feature = db_fetch_object(db_query($feature_sql,$node->title,$node->organism_id));
 
       // now use drupal database
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
    }
 
    // add the genbank accession and synonyms
@@ -488,9 +488,9 @@ function chado_feature_delete($node){
    // Remove data from feature tables of chado database.  This will
    // cause a cascade delete and remove all data in referencing tables
    // for this feature
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    db_query("DELETE FROM {feature} WHERE feature_id = %d", $feature_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    
    drupal_set_message("The feature and all associated data were removed from ".
       "chado");
@@ -525,11 +525,11 @@ function chado_feature_update($node){
       if($node->is_obsolete){
          $obsolete = 'TRUE';
       }
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       db_query($sql,$residues,$node->title,$node->title,
       strlen($residues),$node->organism_id,$obsolete,$node->feature_type,
       $feature->feature_id);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
 
       // add the genbank accession & synonyms
       // chado_feature_add_gbaccession($node->gbaccession,$feature->feature_id);
@@ -548,7 +548,7 @@ function chado_feature_add_synonyms($synonyms,$feature_id){
    $syn_array = explode(" ",$synonyms);
 
    // use the chado database
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
 
    // remove any old synonyms
    $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = %d";
@@ -558,7 +558,7 @@ function chado_feature_add_synonyms($synonyms,$feature_id){
 
    // return if we don't have any synonmys to add
    if(!$synonyms){
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       return;
    }
    // iterate through each synonym and add it to the database
@@ -597,7 +597,7 @@ function chado_feature_add_synonyms($synonyms,$feature_id){
    }
 
    // return to the drupal database
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    return $error;
 
 }
@@ -607,7 +607,7 @@ function chado_feature_add_synonyms($synonyms,$feature_id){
 function chado_feature_add_gbaccession($accession,$feature_id){
 
    // use chado database
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
 
    // remove any old accession from genbank dbEST
    $fdbxref_dsql = "DELETE FROM {feature_dbxref} ".
@@ -622,7 +622,7 @@ function chado_feature_add_gbaccession($accession,$feature_id){
 
    // if we don't have an accession number to add then just return
    if(!$accession){
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       return;
    }
    // get the db_id
@@ -657,7 +657,7 @@ function chado_feature_add_gbaccession($accession,$feature_id){
       $error .= 'Could not add feature database reference. ';
    }
 
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    return $error;
 }
 
@@ -729,9 +729,9 @@ function chado_feature_form ($node,$param){
    );
    // get the list of organisms
    $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $org_rset = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    //
    $organisms = array();
@@ -804,9 +804,9 @@ function chado_feature_validate($node){
    if($node->feature_id){
       $sql = "SELECT * FROM {Feature} WHERE uniquename = '%s' ".
              "  AND organism_id = %d AND NOT feature_id = %d";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $result = db_fetch_object(db_query($sql, $node->title,$node->organism_id,$node->feature_id));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if($result){
          form_set_error('title',t("Feature update cannot proceed. The feature name '$node->title' is not unique for this organism. Please provide a unique name for this feature. "));
       }
@@ -816,9 +816,9 @@ function chado_feature_validate($node){
    // already exist for this organism if it does then we need to throw an error
    else {
       $sql = "SELECT * FROM {Feature} WHERE uniquename = '%s' AND organism_id = %d";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $result = db_fetch_object(db_query($sql, $node->title,$node->organism_id));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if($result){
          form_set_error('title',t("Feature insert cannot proceed. The feature name '$node->title' already exists for this organism. Please provide a unique name for this feature. "));
       }
@@ -851,7 +851,7 @@ function chado_feature_load($node){
    $sql = 'SELECT feature_id FROM {chado_feature} WHERE vid = %d';
    $map = db_fetch_object(db_query($sql, $node->vid));
 
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
 
    // get information about this organism and add it to the items in this node
    $sql = "SELECT F.feature_id, F.name as featurename, F.uniquename, ".
@@ -898,7 +898,7 @@ function chado_feature_load($node){
       }
    }
    $additions->references = $references;
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // get organism node nid
    $sql = "SELECT nid FROM {chado_organism} WHERE organism_id = %d";
@@ -1015,9 +1015,9 @@ function theme_tripal_feature_counts($node){
       		 "WHERE organism_id = %d AND NOT feature_type = 'EST_match' ".
              "ORDER BY num_features desc";
       $features = array();
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql,$node->organism_id);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       $feature = db_fetch_object($results); // retrieve the first result
       if ($feature) {
          $content .= "<div class=\"tripal_feature_summary-info-box\"><br>
@@ -1124,9 +1124,9 @@ function theme_tripal_feature_browser($node){
                "WHERE organism_id = $node->organism_id and ($where_cvt) ".
                "GROUP BY organism_id ";
 
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $features = pager_query($sql,10,0,$csql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
 
       $content = "<br><div id=\"tripal_feature_box\" class=\"feature-info-box\">";
       $content .= "<div class=\"tripal_expandableBox\">".
@@ -1445,9 +1445,9 @@ function tripal_feature_set_taxonomy ($node,$feature_id){
           "  INNER JOIN Feature F on F.type_id = CVT.cvterm_id ".
           "  INNER JOIN Organism O ON F.organism_id = O.organism_id ".
           "WHERE F.feature_id = $feature_id";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $feature = db_fetch_object(db_query($sql));
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // Set the feature type for this feature
    if($do_ft && $ft_vid){
@@ -1464,9 +1464,9 @@ function tripal_feature_set_taxonomy ($node,$feature_id){
              "FROM {Library} L ".
              "  INNER JOIN Library_feature LF ON LF.library_id = L.library_id ".
              "WHERE LF.feature_id = %d ";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $library = db_fetch_object(db_query($sql,$feature_id));
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       $tags["$lb_vid"] = "$library->name";
    }
 
@@ -1483,14 +1483,14 @@ function tripal_feature_set_taxonomy ($node,$feature_id){
              "  INNER JOIN Analysisfeature AF ON AF.analysis_id = A.analysis_id ".
              "WHERE AF.feature_id = $feature_id ";
       $results = db_query($sql);
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $analysis_terms = array();
       while($analysis=db_fetch_object($results)){
          $tags2["$an_vid"] = "$analysis->name";
          $terms['tags'] = $tags2;
          taxonomy_node_save($node,$terms);
       }
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
 
 }
@@ -1553,9 +1553,9 @@ function tripal_features_cleanup($dummy = NULL, $job_id = NULL) {
       // if not, then delete the node.  This check will also take care of the
       // case when a node exists and an entry in the chado_feature table exists
       // but no feature with a matching feature_id exists
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $ftype = db_fetch_object(db_query($tsql,$feature->feature_id));
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
 
       if(!$ftype){
          node_delete($nid->nid);
@@ -1597,9 +1597,9 @@ function tripal_feature_load_fasta_form (&$form_state = NULL){
 
    // get the list of organisms
    $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $org_rset = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
    $organisms = array();
    $organisms[''] = '';
    while($organism = db_fetch_object($org_rset)){
@@ -1620,9 +1620,9 @@ function tripal_feature_load_fasta_form (&$form_state = NULL){
    $sql = "SELECT * FROM {Library} L ".
           "  INNER JOIN Organism O ON L.organism_id = O.organism_id ".
           "ORDER BY L.name";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $lib_rset = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
    $libraries = array();
    $libraries[''] = '';
    while($library = db_fetch_object($lib_rset)){

+ 2 - 2
tripal_library/tripal_library.install

@@ -25,12 +25,12 @@ function tripal_library_install(){
 
    // Add the materialized view needed to count the features for the library
    // Drop the MView table if it exists
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    if (db_table_exists('library_feature_count')) {
       $sql = "DROP TABLE library_feature_count";
       db_query($sql);
    }
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
    // Create the MView
    tripal_add_mview('library_feature_count','tripal_library',
       'library_feature_count',

+ 60 - 60
tripal_library/tripal_library.module

@@ -253,7 +253,7 @@ function theme_tripal_library_search_result ($node) {
    if ($node->type == 'chado_organism') {
       $content = "";
       // get the libraries for the organism
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = "SELECT * FROM {library} L ".
        	     "WHERE L.Organism_id = $node->organism_id";
       $libraries = array();
@@ -268,7 +268,7 @@ function theme_tripal_library_search_result ($node) {
          $library->description = $desc->value;
          $libraries[] = $library;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if(count($libraries) > 0){
          foreach ($libraries as $library){
             $content .= "Library: $library->name. ";
@@ -279,7 +279,7 @@ function theme_tripal_library_search_result ($node) {
    } else if ($node->type == 'chado_feature') {
       $content = "";
       $organism_id = $node->feature->organism_id;
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = "SELECT * FROM {library} L ".
              "  INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
        	  	 "WHERE LF.feature_id = " . $node->feature->feature_id;
@@ -288,7 +288,7 @@ function theme_tripal_library_search_result ($node) {
       while($library = db_fetch_object($results)){
          $libraries[] = $library;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if(count($libraries) > 0){
          $lib_additions = array();
          foreach ($libraries as $library){
@@ -311,7 +311,7 @@ function theme_tripal_library_search_index ($node) {
    if ($node->type == 'chado_organism') {
       $content = "";
       // get the libraries for the organism
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = "SELECT * FROM {library} L ".
        	     "WHERE L.Organism_id = $node->organism_id";
       $libraries = array();
@@ -326,7 +326,7 @@ function theme_tripal_library_search_index ($node) {
          $library->description = $desc->value;
          $libraries[] = $library;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if(count($libraries) > 0){
          foreach ($libraries as $library){
             $content .= "$library->name ";
@@ -337,7 +337,7 @@ function theme_tripal_library_search_index ($node) {
    } else if ($node->type == 'chado_feature') {
       $content = "";
       $organism_id = $node->feature->organism_id;
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = "SELECT * FROM {library} L ".
              "  INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
        	  	 "WHERE LF.feature_id = " . $node->feature->feature_id;
@@ -346,7 +346,7 @@ function theme_tripal_library_search_index ($node) {
       while($library = db_fetch_object($results)){
          $libraries[] = $library;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if(count($libraries) > 0){
          $lib_additions = array();
          foreach ($libraries as $library){
@@ -379,7 +379,7 @@ function theme_tripal_library_node_libraries($node) {
    // when a feature is previewed at its creation
    else if ($node->type == 'chado_feature' && $node->feature->feature_id) {
       $organism_id = $node->feature->organism_id;
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = "SELECT * FROM {library} L ".
              " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
        	  	 "WHERE LF.feature_id = " . $node->feature->feature_id;
@@ -388,7 +388,7 @@ function theme_tripal_library_node_libraries($node) {
       while($library = db_fetch_object($results)){
          $libraries[] = $library;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       if(count($libraries) > 0){
          $lib_additions = array();
          foreach ($libraries as $library){
@@ -419,7 +419,7 @@ function get_tripal_library_organism_libraries($nid) {
       $organism_id = db_result(db_query($sql, $nid));
 
       // get the libraries for the organism
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = "SELECT L.library_id, L.organism_id, L.name, L.uniquename, ".
              "   L.type_id, CVT.name as cvname, CVT.definition ".
              "FROM {library} L ".
@@ -437,7 +437,7 @@ function get_tripal_library_organism_libraries($nid) {
          $library->description = $desc->value;
          $libraries[] = $library;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
       
       if(strcmp($box_status,"menu_off")==0){
          $content .= "<div id=\"tripal_library_box\" class=\"tripal_library-info-box\">";
@@ -561,9 +561,9 @@ function get_tripal_library_admin_form_taxonomy_set(&$form) {
 
    // get the list of libraries
    $sql = "SELECT * FROM {Library} ORDER BY uniquename";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $lib_rset = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // iterate through all of the libraries
    $lib_boxes = array();
@@ -607,9 +607,9 @@ function get_tripal_library_admin_form_reindex_set(&$form) {
 
    // get the list of libraries
    $sql = "SELECT * FROM {Library} ORDER BY uniquename";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $lib_rset = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // iterate through all of the libraries
    $lib_boxes = array();
@@ -651,9 +651,9 @@ function get_tripal_library_admin_form_sync_set (&$form) {
 
    // get the list of libraries
    $sql = "SELECT * FROM {Library} ORDER BY uniquename";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $lib_rset = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // if we've added any libraries to the list that can be synced
    // then we want to build the form components to allow the user
@@ -729,9 +729,9 @@ function tripal_library_admin_validate($form, &$form_state) {
          if($library_id and preg_match("/^\d+$/i",$library_id)){
             // get the library info
             $sql = "SELECT * FROM {Library} WHERE library_id = %d";
-            $previous_db = db_set_active('chado');  // use chado database
+            $previous_db = tripal_db_set_active('chado');  // use chado database
             $library = db_fetch_object(db_query($sql,$library_id));
-            db_set_active($previous_db);  // now use drupal database
+            tripal_db_set_active($previous_db);  // now use drupal database
             $to_sync[$library_id] = $library->name;
          }
       }
@@ -756,9 +756,9 @@ function tripal_library_admin_validate($form, &$form_state) {
          if($library_id and preg_match("/^\d+$/i",$library_id)){
             // get the library info
             $sql = "SELECT * FROM {Library} WHERE library_id = %d";
-            $previous_db = db_set_active('chado');  // use chado database
+            $previous_db = tripal_db_set_active('chado');  // use chado database
             $library = db_fetch_object(db_query($sql,$library_id));
-            db_set_active($previous_db);  // now use drupal database
+            tripal_db_set_active($previous_db);  // now use drupal database
             $job_args[0] = $library_id;
             tripal_add_job("Reindex features for library: $library->name",'tripal_library',
              'tripal_library_reindex_features',$job_args,$user->uid);
@@ -774,9 +774,9 @@ function tripal_library_admin_validate($form, &$form_state) {
          if($library_id and preg_match("/^\d+$/i",$library_id)){
             // get the library info
             $sql = "SELECT * FROM {Library} WHERE library_id = %d";
-            $previous_db = db_set_active('chado');  // use chado database
+            $previous_db = tripal_db_set_active('chado');  // use chado database
             $library = db_fetch_object(db_query($sql,$library_id));
-            db_set_active($previous_db);  // now use drupal database
+            tripal_db_set_active($previous_db);  // now use drupal database
             $job_args[0] = $library_id;
             tripal_add_job("Set taxonomy for features in library: $library->name",'tripal_library',
              'tripal_library_taxonify_features',$job_args,$user->uid);
@@ -855,17 +855,17 @@ function chado_library_validate($node){
              "{Library} WHERE ".
              "uniquename = '%s' ".
              "AND NOT library_id = %d";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $lib = db_fetch_object(db_query($sql, $node->uniquename,
       $node->library_id));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
    } else {
       $sql = "SELECT * FROM ".
              "{Library} ".
              "WHERE uniquename = '%s'";
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $lib = db_fetch_object(db_query($sql, $node->uniquename));
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
    }
    if($lib){
       form_set_error('uniquename',t('The unique library name already exists. '.
@@ -886,7 +886,7 @@ function chado_library_insert($node){
            "WHERE organism_id = %d ".
            "AND uniquename = '%s' ".
            "AND type_id = %d";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $library = db_fetch_object(db_query($l_sql, $node->organism_id,
    $node->uniquename, $node->type_id));
    $libid = $node->library_id;
@@ -911,7 +911,7 @@ function chado_library_insert($node){
    }
 
    // Now use drupal database
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    // Next add the node to the drupal table
    $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
@@ -944,10 +944,10 @@ function chado_library_update($node){
              "               INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
              "               WHERE CV.name = 'local' and CVT.name = '%s') ".
              "WHERE library_id = %d ";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       db_query($sql, $node->title, $node->uniquename, $node->organism_id,
       $node->library_type, $lib->library_id);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       tripal_library_add_properties($node,$lib->library_id);
       tripal_library_add_taxonomy($node,$lib->library_id);
    }
@@ -958,7 +958,7 @@ function chado_library_update($node){
  */
 function tripal_library_add_properties ($node,$library_id){
    // Use chado database
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
 
    // Now remove any properties for this library and add the new properties
    // provided by the this posting.
@@ -981,7 +981,7 @@ function tripal_library_add_properties ($node,$library_id){
    }
 
    // now use drupal database
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 }
 /*******************************************************************************
  * Add the library as a taxonomy term for associating with library_features
@@ -1088,9 +1088,9 @@ function chado_library_form ($node){
 
    // get the list of organisms
    $sql = "SELECT * FROM {Organism}";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $org_rset = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    $organisms = array();
    $organisms[''] = '';
@@ -1137,14 +1137,14 @@ function tripal_library_sync_libraries ($library_id = NULL, $job_id = NULL){
    // get the list of libraries and create new nodes
    if(!$library_id){
       $sql = "SELECT * FROM {Library} L";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    } else {
       $sql = "SELECT * FROM {Library} L WHERE library_id = %d";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql,$library_id);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
 
    // We'll use the following SQL statement for checking if the library
@@ -1189,7 +1189,7 @@ function chado_library_load($node){
    $sql = 'SELECT library_id FROM {chado_library} WHERE vid = %d';
    $map = db_fetch_object(db_query($sql, $node->vid));
    $additions->library_id = $map->library_id;
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
 
    // get information about this library
    $sql = "SELECT L.organism_id, L.uniquename, CVT.name as type_name ".
@@ -1229,7 +1229,7 @@ function chado_library_load($node){
       $additions->num_features = db_fetch_object(db_query($sql, $map->library_id))->num_features;
    }
 
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
    return $additions;
 
 }
@@ -1247,13 +1247,13 @@ function chado_library_view ($node, $teaser = FALSE, $page = FALSE) {
       // but not genus/species/common_name. We need to get those from chado
       // database so they will show up in preview
       if(!$node->genus) {
-         $previous_db = db_set_active('chado');
+         $previous_db = tripal_db_set_active('chado');
          $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
          $data = db_fetch_object(db_query($sql, $node->organism_id));
          $node->genus = $data->genus;
          $node->species = $data->species;
          $node->common_name = $data->common_name;
-         db_set_active($previous_db);
+         tripal_db_set_active($previous_db);
       }
    }
    return $node;
@@ -1334,18 +1334,18 @@ function tripal_library_feature_set_taxonomy($library_id = NULL){
              "INNER JOIN Library L ON LF.library_id = L.library_id ".
              "WHERE L.library_id = $library_id ".
              "ORDER BY LF.feature_id";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $features = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    } else {
       print "Finding features for all libraries\n";
       $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
              "FROM {library_feature} LF ".
              "INNER JOIN Library L ON LF.library_id = L.library_id ".
              "ORDER BY LF.feature_id";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $features = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
 
    $node_sql = "SELECT * FROM {chado_feature} CF ".
@@ -1376,18 +1376,18 @@ function tripal_library_reindex_features ($library_id = NULL, $job_id = NULL){
              "  INNER JOIN Library L ON LF.library_id = L.library_id ".
              "WHERE L.library_id = $library_id ".
              "ORDER BY LF.feature_id";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
    else {
       $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
              " FROM {library_feature} LF ".
              "  INNER JOIN Library L ON LF.library_id = L.library_id ".
              "ORDER BY LF.feature_id";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
 
    // load into ids array
@@ -1423,18 +1423,18 @@ function tripal_library_taxonify_features ($library_id = NULL, $job_id = NULL){
              "  INNER JOIN Library L ON LF.library_id = L.library_id ".
              "WHERE L.library_id = $library_id ".
              "ORDER BY LF.feature_id";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
    else {
       $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
              " FROM {library_feature} LF ".
              "  INNER JOIN Library L ON LF.library_id = L.library_id ".
              "ORDER BY LF.feature_id";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
 
    // load into ids array
@@ -1492,10 +1492,10 @@ function chado_library_delete(&$node){
    db_query($sql_del, $node->nid, $node->vid);
 
    // Remove data from library and libraryprop tables of chado database as well
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    db_query("DELETE FROM {library} WHERE library_id = %d", $library_id);
    db_query("DELETE FROM {libraryprop} WHERE library_id = %d", $library_id);
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 }
 
 /************************************************************************
@@ -1545,7 +1545,7 @@ function get_chado_libraries() {
       // Get library_id's from drupal
       $sql = "SELECT library_id, nid FROM {chado_library}";
       $result = db_query($sql);
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       // Get library info from chado's library, organism, and cvterm tables
       $sql_info = "SELECT L.name, uniquename, genus, species, common_name, ".
                   "  CVT.name as type_name ".
@@ -1572,7 +1572,7 @@ function get_chado_libraries() {
          $key = strtolower($library->uniquename);
          $libraries [$key] = $library;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
 
       //Sort libraries by uniquename
       ksort($libraries, SORT_STRING);

+ 34 - 38
tripal_organism/tripal_organism.module

@@ -1,9 +1,5 @@
 <?php
 
-//
-// Copyright 2009 Clemson University
-//
-
 /*******************************************************************************
  *  Provide information to drupal about the node types that we're creating
  *  in this module
@@ -189,9 +185,9 @@ function get_tripal_organism_admin_form_taxonomy_set(&$form) {
 
   // get the list of libraries
   $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
-  $previous_db = db_set_active('chado');  // use chado database
+  $previous_db = tripal_db_set_active('chado');  // use chado database
   $org_rset = db_query($sql);
-  db_set_active($previous_db);  // now use drupal database
+  tripal_db_set_active($previous_db);  // now use drupal database
 
   // iterate through all of the libraries
   $org_boxes = array();
@@ -235,9 +231,9 @@ function get_tripal_organism_admin_form_reindex_set(&$form) {
 
   // get the list of libraries
   $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
-  $previous_db = db_set_active('chado');  // use chado database
+  $previous_db = tripal_db_set_active('chado');  // use chado database
   $org_rset = db_query($sql);
-  db_set_active($previous_db);  // now use drupal database
+  tripal_db_set_active($previous_db);  // now use drupal database
 
   // iterate through all of the libraries
   $org_boxes = array();
@@ -288,9 +284,9 @@ function get_tripal_organism_admin_form_sync_set (&$form) {
 
      // get the list of organisms
      $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
-     $previous_db = db_set_active('chado');  // use chado database
+     $previous_db = tripal_db_set_active('chado');  // use chado database
      $org_rset = db_query($sql);
-     db_set_active($previous_db);  // now use drupal database
+     tripal_db_set_active($previous_db);  // now use drupal database
 
      // if we've added any organisms to the list that can be synced
      // then we want to build the form components to allow the user
@@ -363,9 +359,9 @@ function tripal_organism_admin_validate($form, &$form_state) {
         if($organism_id and preg_match("/^\d+$/i",$organism_id)){
            // get the list of organisms
            $sql = "SELECT * FROM {Organism} WHERE organism_id = %d";
-           $previous_db = db_set_active('chado');  // use chado database
+           $previous_db = tripal_db_set_active('chado');  // use chado database
            $organism = db_fetch_object(db_query($sql,$organism_id));
-           db_set_active($previous_db);  // now use drupal database
+           tripal_db_set_active($previous_db);  // now use drupal database
            $to_sync[$organism_id] = "$organism->genus $organism->species";
         }
      }
@@ -392,9 +388,9 @@ function tripal_organism_admin_validate($form, &$form_state) {
        if($organism_id and preg_match("/^\d+$/i",$organism_id)){
           // get the organism info
           $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
-          $previous_db = db_set_active('chado');  // use chado database
+          $previous_db = tripal_db_set_active('chado');  // use chado database
           $organism = db_fetch_object(db_query($sql,$organism_id));
-          db_set_active($previous_db);  // now use drupal database
+          tripal_db_set_active($previous_db);  // now use drupal database
           $job_args[0] = $organism_id;
           tripal_add_job("Reindex features for organism: $organism->genus ".
              "$organism->species",'tripal_organism',
@@ -411,9 +407,9 @@ function tripal_organism_admin_validate($form, &$form_state) {
        if($organism_id and preg_match("/^\d+$/i",$organism_id)){
           // get the organism info
           $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
-          $previous_db = db_set_active('chado');  // use chado database
+          $previous_db = tripal_db_set_active('chado');  // use chado database
           $organism = db_fetch_object(db_query($sql,$organism_id));
-          db_set_active($previous_db);  // now use drupal database
+          tripal_db_set_active($previous_db);  // now use drupal database
           $job_args[0] = $organism_id;
           tripal_add_job("Set taxonomy for features in organism: ".
              "$organism->genus $organism->species",'tripal_organism',
@@ -463,9 +459,9 @@ function chado_organism_insert($node){
             "FROM {Organism} ".
             "WHERE genus = '%s' ".
             "AND species = '%s'";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $organism = db_fetch_object(db_query($o_sql, $node->genus,$node->species));
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 
    // if the feature doesn't exist then let's create it in chado.
    if(!$organism){
@@ -473,13 +469,13 @@ function chado_organism_insert($node){
       $sql = "INSERT INTO {organism} ".
              " (abbreviation, genus, species,common_name,comment) VALUES ".
              " ('%s','%s','%s','%s','%s')";
-     $previous_db = db_set_active('chado');  // use chado database
+     $previous_db = tripal_db_set_active('chado');  // use chado database
      db_query($sql,$node->abbreviation, $node->genus,
      $node->species,$node->common_name,$node->description);
 
      // find the newly entered organism_id
      $organism = db_fetch_object(db_query($o_sql, $node->genus,$node->species));
-     db_set_active($previous_db);  // switch back to drupal database
+     tripal_db_set_active($previous_db);  // switch back to drupal database
 
    }
 
@@ -533,7 +529,7 @@ function chado_organism_delete($node){
    // Test dependency before deleting from chado database. If a library or
    // feature depends on this organism, don't delete it
    $sql = "SELECT feature_id FROM {feature} WHERE organism_id = %d";
-   $previous_db = db_set_active('chado');
+   $previous_db = tripal_db_set_active('chado');
    $check_feature = db_result(db_query($sql, $organism_id));
    $sql = "SELECT library_id FROM {library} WHERE organism_id = %d";
    $check_lib = db_result(db_query($sql, $organism_id));
@@ -552,7 +548,7 @@ function chado_organism_delete($node){
                          "library or feature depends on this organism. It was ".
       					 "not removed from chado.");
    }
-   db_set_active($previous_db);
+   tripal_db_set_active($previous_db);
 }
 /*******************************************************************************
 *
@@ -595,10 +591,10 @@ function chado_organism_update($node){
              "    common_name = '%s' ".
              "WHERE organism_id = %d ";
 
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       db_query($sql,$node->description, $node->abbreviation, $node->genus,
           $node->species,$node->common_name,$org->organism_id);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
 
       //$sql = "UPDATE {node} SET title = '$node->genus $node->species' WHERE nid = $node->nid";
       //db_query($sql);
@@ -673,7 +669,7 @@ function chado_organism_load($node){
    $sql = "SELECT organism_id FROM {chado_organism} WHERE vid = %d";
    $org_node = db_fetch_object(db_query($sql, $node->vid));
 
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
 
    // get information about this organism and add it to the items in this node
    if ($org_node->organism_id) {
@@ -691,7 +687,7 @@ function chado_organism_load($node){
    $additions->description = $organism->description;
 
 
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    return $additions;
 }
@@ -715,14 +711,14 @@ function tripal_organism_sync_organisms ($organism_id = NULL, $job_id = NULL){
 
    if(!$organism_id){
       $sql = "SELECT * FROM {Organism} O";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    } else {
       $sql = "SELECT * FROM {Organism} L WHERE organism_id = %d";
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $results = db_query($sql,$organism_id);
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
    }
 
    // We'll use the following SQL statement for checking if the organism
@@ -839,7 +835,7 @@ function get_chado_organisms() {
    if ($no_orgs != 0) {
       $sql = "SELECT organism_id, nid FROM {chado_organism}";
       $result = db_query($sql);
-      $previous_db = db_set_active('chado');
+      $previous_db = tripal_db_set_active('chado');
       $sql = "SELECT genus, species, common_name, comment ".
              "FROM {Organism} ".
              "WHERE organism_id=%d";
@@ -855,7 +851,7 @@ function get_chado_organisms() {
          $organisms [$key] = $organism;
          $count ++;
       }
-      db_set_active($previous_db);
+      tripal_db_set_active($previous_db);
 
       //Sort organisms by common name
       ksort($organisms, SORT_STRING);
@@ -876,9 +872,9 @@ function tripal_organism_reindex_features ($organism_id = NULL, $job_id = NULL){
           "FROM {feature} ".
           "WHERE organism_id = $organism_id ".
           "ORDER BY feature_id";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query($sql);
-   db_set_active($previous_db);  // now use drupal databa  db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal databa  tripal_db_set_active($previous_db);  // now use drupal database
 
    // load into ids array
    $count = 0;
@@ -912,9 +908,9 @@ function tripal_organism_taxonify_features ($organism_id = NULL, $job_id = NULL)
           "FROM {feature} ".
           "WHERE organism_id = $organism_id ".
           "ORDER BY feature_id";
-   $previous_db = db_set_active('chado');  // use chado database
+   $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query($sql);
-   db_set_active($previous_db);  // now use drupal database
+   tripal_db_set_active($previous_db);  // now use drupal database
 
    // load into ids array
    $count = 0;
@@ -961,9 +957,9 @@ function tripal_organism_get_synced() {
 
    // iterate through the organisms and build an array of those that are synced
    while($org = db_fetch_object($orgs)){
-      $previous_db = db_set_active('chado');  // use chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
       $info = db_fetch_object(db_query($csql,$org->organism_id));
-      db_set_active($previous_db);  // now use drupal database
+      tripal_db_set_active($previous_db);  // now use drupal database
       $org_list[] = $info;
    }  
    return $org_list;

+ 2 - 2
tripal_organism/views/tripal_organism.views.inc

@@ -22,13 +22,13 @@ function tripal_organism_views_data() {
    
    //Retrieve common_names from chado database using the organism_id
    $sql = 'SELECT common_name FROM {organism} WHERE organism_id=%d';
-   $previous_db = db_set_active ('chado');
+   $previous_db = tripal_db_set_active ('chado');
    $common_names = array ();
    while ($org = db_fetch_object($result)) {     
       $common_name = db_result(db_query ($sql, $org->organism_id));
       $common_names [$org->nid] = $common_name;
    }
-   db_set_active ($previous_db);
+   tripal_db_set_active ($previous_db);
    
    // Insert common_name and nid to the custom table
    $sql = "INSERT INTO {tripal_organism_views_common_name} (nid, common_name) VALUES (%d, '%s')";

+ 2 - 2
tripal_search/tripal_search.module

@@ -78,10 +78,10 @@ function tripal_search_file($type, $keys, $results) {
     if($f_objd = db_fetch_object(db_query($sqld, $result->sid))){
 
        // Get sequence from chado database
-       $previous_db = db_set_active('chado');  // use chado database
+       $previous_db = tripal_db_set_active('chado');  // use chado database
        $sqlc = "SELECT * FROM {feature} WHERE feature_id = '%s'";
        $f_objc = db_fetch_object(db_query($sqlc,$f_objd->feature_id));
-       db_set_active($previous_db);  // now use drupal database
+       tripal_db_set_active($previous_db);  // now use drupal database
        print tripal_feature_return_fasta($f_objc, $desc);
     } 
   }