Quellcode durchsuchen

Update the 6.x-1482618-API_for_default_views_integration to match the latest 6.x-1.x commit.

Lacey Sanderson vor 12 Jahren
Ursprung
Commit
4c2eceb2ab

+ 2 - 2
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -513,8 +513,8 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
     // Use prepared statement?
     if (variable_get('tripal_bulk_loader_prepare', TRUE)) {
       $options = array('statement_name' => 'record_' . $priority);
-      if ($addt->line_num == 1 && $addt->group_index == 1) {
-        $options['prepare'] = TRUE;
+      if (($addt->line_num > 1 && $addt->group_index == 1) OR $addt->group_index > 1) {
+        $options['is_prepared'] = TRUE;
       }
     }
     else {

+ 187 - 92
tripal_core/api/tripal_core.api.inc

@@ -73,15 +73,18 @@ require_once "tripal_core.schema_v1.11.api.inc";
  * @param $values
  *  An associative array containing the values for inserting.
  * @param $options
- *  An array of options such as:
- *    -prepare: TRUE or FALSE. Whether or not to prepare the current statement.
- *       statement_name must also be supplied.
- *    -statement_name: the name of the prepared statement to use. If prepare is TRUE,
- *       this indicates the name of the prepared statement to created; otherwise,
- *       it indicates the name of the already prepared statement to use.
- *    -skip_validation: TRUE or FALSE. If TRUE will skip all the validation steps and
- *       just try to insert as is. This is much faster but results in unhandled
- *       non user-friendly errors if the insert fails.
+ *  An array of options such as:  
+ *  - statement_name: the name of the prepared statement to use. If the statement
+ *     has not yet been prepared it will be prepared automatically. On subsequent
+ *     calls with the same statement_name only an execute on the previously
+ *     prepared statement will occur.
+ *  - is_prepared: TRUE or FALSE. Whether or not the statement is prepared. By
+ *     default if the statement is not prepared it will be automatically. 
+ *     However to avoid this check, which requires a database query you can
+ *     set this value to true and the check will not be performed. 
+ *  - skip_validation: TRUE or FALSE. If TRUE will skip all the validation steps and
+ *     just try to insert as is. This is much faster but results in unhandled
+ *     non user-friendly errors if the insert fails.
  *
  * @return
  *  On success this function returns TRUE. On failure, it returns FALSE.
@@ -115,21 +118,16 @@ require_once "tripal_core.schema_v1.11.api.inc";
  */
 function tripal_core_chado_insert($table, $values, $options = array()) {
   $insert_values = array();
-  $chado_db = tripal_db_persistent_chado();
+  
+  // we need to get a persistent connection.  If one exists this function
+  // will not recreate it, but if not it will create one and store it in
+  // a Drupal variable for reuse later.
+  tripal_db_persistent_chado();
 
   // Determine plan of action
   if ($options['statement_name']) {
+    // we have a prepared statment (or want to create one) so set $prepared = TRUE
     $prepared = TRUE;
-    $connection = tripal_db_persistent_chado();
-    if ($options['prepare']) {
-      $build_sql = TRUE;
-    }
-    else {
-      $build_sql = FALSE;
-    }
-  }
-  else {
-    $build_sql = TRUE;
   }
 
   if (array_key_exists('skip_validation', $options)) {
@@ -239,68 +237,52 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
       $idatatypes[] = 'text';
     }
   }
+  
+  // create the SQL
+  $sql = "INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $itypes) . ")";
 
-  if ($build_sql) {
-    // prepare the statement
-    if ($prepared) {
-      $prepare_sql = "PREPARE " . $options['statement_name'] . " (" . implode(', ', $idatatypes) . ") AS INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $iplaceholders) . ")";
-      $status = chado_query($prepare_sql);
+  // if this is a prepared statement then execute it
+  if ($prepared) {
+    // if this is the first time we've run this query 
+    // then we need to do the prepare, otherwise just execute
+    if ($options['is_prepared'] != TRUE and
+       !tripal_core_is_sql_prepared($options['statement_name'])) { 
+      // prepare the statement
+      $psql = "PREPARE " . $options['statement_name'] . " (" . implode(', ', $idatatypes) . ") AS INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $iplaceholders) . ")";
+      $status = chado_query($psql);
 
       if (!$status) {
         watchdog('tripal_core', "tripal_core_chado_insert: not able to prepare '%name' statement for: %sql", array('%name' => $options['statement_name'], '%sql' => $sql), 'WATCHDOG ERROR');
         return FALSE;
       }
     }
-    else {
-      $sql = "INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $itypes) . ")";
-    }
-  }
-
-  // finally perform the insert.
-  if ($prepared) {
 
     $sql = "EXECUTE " . $options['statement_name'] . "(" . implode(", ", $itypes) . ")";
     $result = chado_query($sql, $ivalues);
-
-    if ($result) {
-      // add primary keys to values before return
-      $primary_key = array();
-      if (!is_array($table_desc['primary key'])) {
-        $table_desc['primary key'] = array();
-        watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
-      }
-      foreach ($table_desc['primary key'] as $field) {
-        $value = db_last_insert_id($table, $field);
-        $values[$field] = $value;
-      }
-      return $values;
-    }
-    else {
-      watchdog('tripal_core', "tripal_core_chado_insert: not able to execute prepared statement '%name' with values: %values", array('%name' => $options['statement_name'], '%values' => print_r($values, TRUE)), 'WATCHDOG ERROR');
-      return FALSE;
-    }
   }
+  // if it's not a prepared statement then insert normally
   else {
     $previous_db = tripal_db_set_active('chado');  // use chado database
     $result = db_query($sql, $ivalues);
     tripal_db_set_active($previous_db);  // now use drupal database
-    if ($result) {
-      // add primary keys to values before return
-      $primary_key = array();
-      if (!is_array($table_desc['primary key'])) {
-        $table_desc['primary key'] = array();
-        watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
-      }
-      foreach ($table_desc['primary key'] as $field) {
-        $value = db_last_insert_id($table, $field);
-        $values[$field] = $value;
-      }
-      return $values;
+  }
+  
+  // if we have a result then add primary keys to return array
+  if ($result) {
+    $primary_key = array();
+    if (!is_array($table_desc['primary key'])) {
+      $table_desc['primary key'] = array();
+      watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
     }
-    else {
-      watchdog('tripal_core', "tripal_core_chado_insert: Cannot insert record into $table table: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
-      return FALSE;
+    foreach ($table_desc['primary key'] as $field) {
+      $value = db_last_insert_id($table, $field);
+      $values[$field] = $value;
     }
+    return $values;
+  }
+  else {
+    watchdog('tripal_core', "tripal_core_chado_insert: Cannot insert record into $table table: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
+    return FALSE;
   }
 
   return FALSE;
@@ -618,6 +600,14 @@ function tripal_core_chado_update($table, $match, $values) {
  *     An associative array containing the column names of the table as keys
  *     and the type of sort (i.e. ASC, DESC) as the values.  The results in the
  *     query will be sorted by the key values in the direction listed by the value
+ *  - statement_name: the name of the prepared statement to use. If the statement
+ *     has not yet been prepared it will be prepared automatically. On subsequent
+ *     calls with the same statement_name only an execute on the previously
+ *     prepared statement will occur.
+ *  - is_prepared: TRUE or FALSE. Whether or not the statement is prepared. By
+ *     default if the statement is not prepared it will be automatically. 
+ *     However to avoid this check, which requires a database query you can
+ *     set this value to true and the check will not be performed. 
  *
  * @return
  *  A database query result resource, FALSE if the query was not executed
@@ -653,6 +643,13 @@ function tripal_core_chado_update($table, $match, $values) {
  * @ingroup tripal_chado_api
  */
 function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
+
+  // we need to get a persistent connection.  If one exists this function
+  // will not recreate it, but if not it will create one and store it in
+  // a Drupal variable for reuse later.
+  tripal_db_persistent_chado();
+  
+  // get the options for this query
   if (!is_array($options)) {
     $options = array();
   }
@@ -665,6 +662,13 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   if (!$options['order_by']) {
     $options['order_by'] = array();
   }
+  
+  // if this is a prepared statement check to see if it has already been prepared
+  if ($options['statement_name']) {
+    $prepared = TRUE;  
+  }
+  
+  // check that our columns and values arguments are proper arrays
   if (!is_array($columns)) {
     watchdog('tripal_core', 'the $columns argument for tripal_core_chado_select must be an array.');
     return FALSE;
@@ -695,6 +699,15 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
           'regex_columns' => $options['regex_columns'],
           'case_insensitive_columns' => $options['case_insensitive_columns']
         );
+        if($options['statement_name']){
+           // add the fk relationship info to the prepared statement name so that
+           // we can prepare the selects run by the recrusive tripal_core_chado_get_foreign_key
+           // function.
+           $foreign_options['statement_name'] = $options['statement_name'] . "fk_" . $table . "_" . $field;
+        }
+        if($options['prepare']){
+           $foreign_options['prepare'] = $options['prepare'];
+        }
         $results = tripal_core_chado_get_foreign_key($table_desc, $field, $value, $foreign_options);
         if (!$results or count($results) ==0) {
 
@@ -726,70 +739,136 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     }
   }
 
-  // now build the SQL select statement
+  // now build the SQL and prepared SQL statements. We may not use
+  // the prepared statement if it wasn't requested in the options of if the
+  // argument in a where statement has multiple values.
   if (empty($where)) {
     // sometimes want to select everything
     $sql  = "SELECT " . implode(', ', $columns) . " ";
     $sql .= "FROM {$table} ";
-
+    // we don't prepare a statement if there is no where clause
+    $prepared = FALSE;
   }
   else {
     $sql  = "SELECT " . implode(', ', $columns) . " ";
     $sql .= "FROM {$table} ";
-    $sql .= "WHERE ";
-    foreach ($where as $field => $value) {
+    $sql .= "WHERE ";    
+    $psql = $sql;  // prepared SQL statement;
+    $i = 1;
+    $pvalues = array();
+    foreach ($where as $field => $value) {       
+     
+      // if we have multiple values returned then we need an 'IN' statement
+      // in our where statement
       if (count($value) > 1) {
         $sql .= "$field IN (" . db_placeholders($value, 'varchar') . ") AND ";
         foreach ($value as $v) {
-          $args[] = $v;
+          $args[] = $v;            
+          // we can't do a prepared statement with an 'IN' statement in a 
+          // where clause because we can't guarantee we'll always have the 
+          // same number of elements. 
+          $prepared = FALSE;  
         }
       }
+      // if we have a single value then we need an = in our where statement
       else {
         $operator = '=';
         if (in_array($field, $options['regex_columns'])) {
           $operator = '~*';
         }
-        if (in_array($field, $options['case_insensitive_columns'])) {
-          $sql .= "lower($field) $operator lower('%s') AND ";
+        
+        // get the types for the prepared statement. First check if the type
+        // is an integer
+        if (strcasecmp($table_desc['fields'][$field]['type'], 'serial')==0 OR
+            strcasecmp($table_desc['fields'][$field]['type'], 'int')==0 OR
+            strcasecmp($table_desc['fields'][$field]['type'], 'integer')==0) {
+          $sql .= "$field $operator %d AND ";
+          $psql .= "$field $operator \$" . $i . " AND ";
           $args[] = $value[0];
+          // set the variables needed for the prepared statement
+          $idatatypes[] = 'int';
+          $pvalues[] = $value[0];
         }
+        // else the type is a text
         else {
-          $sql .= "$field $operator '%s' AND ";
-          $args[] = $value[0];
+          if (in_array($field, $options['case_insensitive_columns'])) {
+            $sql .= "lower($field) $operator lower('%s') AND ";
+            $psql .= "lower($field) $operator lower('\$" . $i . "') AND ";
+            $args[] = $value;
+          }
+          else {
+            $sql .= "$field $operator '%s' AND ";
+            $psql .= "$field $operator \$" . $i . " AND ";
+            $args[] = $value[0];
+          } 
+          // set the variables needed for the prepared statement
+          $idatatypes[] = 'text';
+          $pvalues[] = "'" . $value[0] . "'";
         }
       }
+      $i++;
     }
     $sql = drupal_substr($sql, 0, -4);  // get rid of the trailing 'AND '
-  }
-
-  // finally add any ordering of the results to the SQL statement
-  if (count($options['order_by']) > 0) {
-    $sql .= " ORDER BY ";
-    foreach ($options['order_by'] as $field => $dir) {
-      $sql .= "$field $dir, ";
+    $psql = drupal_substr($psql, 0, -4);  // get rid of the trailing 'AND '
+    
+    // finally add any ordering of the results to the SQL statement
+    if (count($options['order_by']) > 0) {
+      $sql .= " ORDER BY ";
+      $psql .= " ORDER BY ";
+      foreach ($options['order_by'] as $field => $dir) {
+        $sql .= "$field $dir, ";
+        $psql .= "$field $dir, ";
+      }
+      $sql = drupal_substr($sql, 0, -2);  // get rid of the trailing ', '
+      $psql = drupal_substr($psql, 0, -2);  // get rid of the trailing ', '
     }
-    $sql = drupal_substr($sql, 0, -2);  // get rid of the trailing ', '
-  }
-
+    
+    // finish constructing the prepared SQL statement
+    $psql =  "PREPARE " . $options['statement_name'] . " (" . implode(', ', $idatatypes) . ") AS " . $psql;                 
+    
+  } // end if(empty($where)){ } else {
+  
   // if the caller has requested the SQL rather than the results...
   // which happens in the case of wanting to use the Drupal pager, then do so
   if ($options['return_sql']) {
     return array('sql' => $sql, 'args' => $args);
   }
 
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $resource = db_query($sql, $args);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  // prepare the statement
+  if ($prepared) {
+    // if this is the first time we've run this query 
+    // then we need to do the prepare, otherwise just execute
+    if ($options['is_prepared'] != TRUE and
+        !tripal_core_is_sql_prepared($options['statement_name'])) {
+      $status = chado_query($psql);
+#      print "$psql\n";
+      if (!$status) {
+        watchdog('tripal_core', "tripal_core_chado_select: not able to prepare '%name' statement for: %sql", array('%name' => $options['statement_name'], '%sql' => $sql), 'WATCHDOG ERROR');
+        return FALSE;
+      }
+    }
+    $sql = "EXECUTE " . $options['statement_name'] . "(" . implode(", ", $pvalues) . ")";
+#    print "$sql\n";
+    $resource = chado_query($sql, $ivalues);   
+  }
+  else {
+    $previous_db = tripal_db_set_active('chado');  // use chado database
+    $resource = db_query($sql, $args);
+    tripal_db_set_active($previous_db);  // now use drupal database
+  }
+  
+  // format results into an array
   $results = array();
   while ($r = db_fetch_object($resource)) {
     $results[] = $r;
   }
-  if (!$options['has_record']) {
-    return $results;
-  }
-  else {
+  if ($options['has_record']) {
     return count($results);
   }
+#  print "$psql\n";
+#  print "$sql\n";
+#  print '$results = ' . print_r($results,1);
+  return $results;
 }
 
 /**
@@ -1896,7 +1975,23 @@ function tripal_db_set_active($dbname) {
   }
 }
 
-
+/**
+ * Indicates if the SQL statement is prepapred
+ *
+ * @param $statement_name
+ *   The name of the statement to check if it is prepared.
+ *
+ * @return
+ *   TRUE if the statement is preapred, FALSE otherwise
+ */
+function tripal_core_is_sql_prepared($statement_name) {
+  $sql = "SELECT name FROM pg_prepared_statements WHERE name = '%s'";
+  $result = db_fetch_object(chado_query($sql,$statement_name));
+  if($result){
+     return TRUE;
+  }
+  return FALSE;
+}
 /**
  * Instantiate or Return a persistent chado connection
  *

+ 2 - 2
tripal_core/includes/jobs.php

@@ -54,7 +54,7 @@
  * tripal_add_job("Import FASTA file: $dfile", 'tripal_feature',
  *   'tripal_feature_load_fasta', $args, $user->uid);
  * @endcode
- * The code above is copied from the tripal_feature/fasta_loader.php file. The 
+ * The code above is copied from the tripal_feature/fasta_loader.php file. The
  * snipped first builds an array of arguments that will then be passed to the
  * tripal_add_job function.  The number of arguments provided in the $arguments
  * variable should match the argument set for the callback function provided
@@ -79,7 +79,7 @@ function tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $pr
   }
   if (drupal_write_record('tripal_jobs', $record)) {
     $jobs_url = url("admin/tripal/tripal_jobs");
-    drupal_set_message(t("Job '%job_name' submitted.  Check the %jobs_link for status", array('%job_name' => $job_name, '%jobs_link' => l($jobs_url, 'jobs page'))));
+    drupal_set_message(t("Job '%job_name' submitted.  Check the <a href='!jobs_url'>jobs page</a> for status", array('%job_name' => $job_name, '!jobs_url' => url($jobs_url))));
   }
   else {
     drupal_set_message(t("Failed to add job %job_name.", array('%job_name' => $job_name)), 'error');

+ 58 - 66
tripal_feature/includes/gff_loader.inc

@@ -534,6 +534,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_on
     if ($details['children']) {
       // get the parent
       $values = array(
+        'organism_id' => $organism->organism_id,
         'uniquename' => $parent,
         'type_id' => array(
            'cv_id' => array(
@@ -541,9 +542,9 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_on
             ),
            'name' => $details['type'],
         ),
-        'organism_id' => $organism->organism_id,
       );
-      $pfeature = tripal_core_chado_select('feature', array('*'), $values);
+      $options = array('statement_name' => 'sel_feature_organismid_uniquename_typeid');
+      $pfeature = tripal_core_chado_select('feature', array('*'), $values, $options);
 
       // sort the children by order of their fmin positions (values of assoc. array)
       // if the parent is on the reverse strand then sort in reverse
@@ -589,16 +590,17 @@ function tripal_feature_load_gff3_derives_from($feature, $subject, $gff_features
 
    // first get the subject feature
   $match = array(
-  'organism_id' => $organism->organism_id,
-  'uniquename' => $subject,
-  'type_id' => array(
-    'name' => $gff_features[$subject]['type'],
-    'cv_id' => array(
-      'name' => 'sequence'
+    'organism_id' => $organism->organism_id,
+    'uniquename' => $subject,
+    'type_id' => array(
+      'name' => $gff_features[$subject]['type'],
+      'cv_id' => array(
+        'name' => 'sequence'
+      ),
     ),
-  ),
   );
-  $sfeature = tripal_core_chado_select('feature', array('*'), $match);
+  $options = array('statement_name' => 'sel_feature_organismid_uniquename_typeid');
+  $sfeature = tripal_core_chado_select('feature', array('*'), $match, $options);
   if (count($sfeature)==0) {
     print "ERROR: could not add 'Derives_from' relationship for $feature->uniquename and $subject.  Subject feature, '$subject', cannot be found\n";
     return;
@@ -616,14 +618,16 @@ function tripal_feature_load_gff3_derives_from($feature, $subject, $gff_features
     ),
     'rank' => 0
   );
-    $rel = tripal_core_chado_select('feature_relationship', array('*'), $values);
+  $options = array('statement_name' => 'sel_featurerelationship_objectid_subjectid_typeid_rank');
+  $rel = tripal_core_chado_select('feature_relationship', array('*'), $values, $options);
   if (count($rel) > 0) {
     print "   Relationship already exists: $feature->uniquename derives_from $subject\n";
     return;
   }
 
-   // finally insert the relationship if it doesn't exist
-  $ret = tripal_core_chado_insert('feature_relationship', $values);
+  // finally insert the relationship if it doesn't exist
+  $options = array('statement_name' => 'ins_featurerelationship_objectid_subjectid_typeid_rank');
+  $ret = tripal_core_chado_insert('feature_relationship', $values, $options);
   if (!$ret) {
     print "ERROR: could not add 'Derives_from' relationship for $feature->uniquename and $subject\n";
   }
@@ -715,47 +719,56 @@ function tripal_feature_load_gff3_dbxref($feature, $dbxrefs) {
     // first check for the fully qualified URI (e.g. DB:<dbname>. If that
     // can't be found then look for the name as is.  If it still can't be found
     // the create the database
-    $db = tripal_core_chado_select('db', array('db_id'), array('name' => "DB:$dbname"));
-    if (sizeof($db) == 0) {
-      $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"));
+    $options = array('statement_name' => 'sel_db_name');
+    $db = tripal_core_chado_select('db', array('db_id'), array('name' => "DB:$dbname"), $options);
+    if (count($db) == 0) {
+      $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
     }
-    if (sizeof($db) == 0) {
+    if (count($db) == 0) {
+      $options = array('statement_name' => 'ins_db_name');
       $ret = tripal_core_chado_insert('db', array('name' => $dbname,
-       'description' => 'Added automatically by the GFF loader'));
+        'description' => 'Added automatically by the GFF loader'), $options);
       if ($ret) {
         print "   Added new database: $dbname\n";
-        $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"));
+        $options = array('statement_name' => 'sel_db_name');
+        $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
       }
       else {
         print "ERROR: cannot find or add the database $dbname\n";
+        exit;
         return 0;
       }
     }
     $db = $db[0];
 
     // now check to see if the accession exists
+    $options = array('statement_name' => 'sel_dbxref_accession_dbid');
     $dbxref = tripal_core_chado_select('dbxref', array('dbxref_id'), array(
-      'accession' => $accession, 'db_id' => $db->db_id));
+      'accession' => $accession, 'db_id' => $db->db_id), $options);
 
     // if the accession doesn't exist then we want to add it
     if (sizeof($dbxref) == 0) {
+      $options = array('statement_name' => 'ins_dbxref_dbid_accession_version');
       $ret = tripal_core_chado_insert('dbxref', array('db_id' => $db->db_id,
-        'accession' => $accession, 'version' => ''));
+        'accession' => $accession, 'version' => ''), $options);
+      $options = array('statement_name' => 'sel_dbxref_accession_dbid');
       $dbxref = tripal_core_chado_select('dbxref', array('dbxref_id'), array(
-        'accession' => $accession, 'db_id' => $db->db_id));
+        'accession' => $accession, 'db_id' => $db->db_id), $options);
     }
     $dbxref = $dbxref[0];
 
     // check to see if this feature dbxref already exists
+    $options = array('statement_name' => 'sel_featuredbxref_dbxrefid_featureid');
     $fdbx = tripal_core_chado_select('feature_dbxref', array('feature_dbxref_id'),
-      array('dbxref_id' => $dbxref->dbxref_id, 'feature_id' => $feature->feature_id));
+      array('dbxref_id' => $dbxref->dbxref_id, 'feature_id' => $feature->feature_id), $options);
 
     // now associate this feature with the database reference if it doesn't
     // already exist
     if (sizeof($fdbx)==0) {
+      $options = array('statement_name' => 'ins_featuredbxref_dbxrefid_featureid');
       $ret = tripal_core_chado_insert('feature_dbxref', array(
-        'feature_id' => $feature->feature_id,
-        'dbxref_id' => $dbxref->dbxref_id));
+        'dbxref_id' => $dbxref->dbxref_id,
+        'feature_id' => $feature->feature_id), $options);
       if ($ret) {
         print "   Adding Dbxref $dbname:$accession\n";
       }
@@ -786,9 +799,10 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs) {
     $accession = $ref[1];
 
     // first look for the database name
-    $db = tripal_core_chado_select('db', array('db_id'), array('name' => "DB:$dbname"));
+    $options = array('statement_name' => 'sel_db_name');
+    $db = tripal_core_chado_select('db', array('db_id'), array('name' => "DB:$dbname"), $options);
     if (sizeof($db) == 0) {
-      $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"));
+      $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
     }
     if (sizeof($db) == 0) {
       print "ERROR: Database, $dbname is missing for reference: $dbname:$accession\n";
@@ -797,8 +811,9 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs) {
     $db = $db[0];
 
     // now check to see if the accession exists
+    $options = array('statement_name' => 'sel_dbxref_accession_dbid');
     $dbxref = tripal_core_chado_select('dbxref', array('dbxref_id'), array(
-       'accession' => $accession, 'db_id' => $db->db_id));
+       'accession' => $accession, 'db_id' => $db->db_id), $options);
     if (sizeof($dbxref) == 0) {
       print "ERROR: Accession, $accession is missing for reference: $dbname:$accession\n";
       return 0;
@@ -806,12 +821,14 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs) {
     $dbxref = $dbxref[0];
 
     // now check to see if the cvterm exists
+    $options = array('statement_name' => 'sel_cvterm_dbxrefid');
     $cvterm = tripal_core_chado_select('cvterm', array('cvterm_id'), array(
-       'dbxref_id' => $dbxref->dbxref_id));
+       'dbxref_id' => $dbxref->dbxref_id), $options);
     // if it doesn't exist in the cvterm table, look for an alternate id
     if (sizeof($cvterm) == 0) {
+      $options = array('statement_name' => 'sel_cvtermdbxref_dbxrefid');
       $cvterm = tripal_core_chado_select('cvterm_dbxref', array('cvterm_id'), array(
-        'dbxref_id' => $dbxref->dbxref_id));
+        'dbxref_id' => $dbxref->dbxref_id), $options);
     }
     if (sizeof($cvterm) == 0) {
       print "ERROR: CVTerm is missing for reference: $dbname:$accession\n";
@@ -821,19 +838,22 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs) {
 
 
     // check to see if this feature cvterm already exists
+    $options = array('statement_name' => 'sel_featurecvterm_cvtermid_featureid');
     $fcvt = tripal_core_chado_select('feature_cvterm', array('feature_cvterm_id'),
-      array('cvterm_id' => $cvterm->cvterm_id, 'feature_id' => $feature->feature_id));
+      array('cvterm_id' => $cvterm->cvterm_id, 'feature_id' => $feature->feature_id),
+      $options);
 
     // now associate this feature with the cvterm if it doesn't already exist
     if (sizeof($fcvt)==0) {
       $values = array(
-        'feature_id' => $feature->feature_id,
         'cvterm_id' => $cvterm->cvterm_id,
+        'feature_id' => $feature->feature_id,
         'pub_id' => array(
           'uniquename' => 'null',
         ),
       );
-      $ret = tripal_core_chado_insert('feature_cvterm', $values);
+      $options = array('statement_name' => 'ins_featurecvterm_cvtermid_featureid_pubid');
+      $ret = tripal_core_chado_insert('feature_cvterm', $values, $options);
 
       if ($ret) {
         print "   Adding ontology term $dbname:$accession\n";
@@ -1014,13 +1034,16 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
     'analysis_id' => $analysis_id,
     'feature_id' => $feature->feature_id
   );
-  $afeature = tripal_core_chado_select('analysisfeature', array('analysisfeature_id'), $af_values, array('has_record'));
+  $options = array('statement_name' => 'sel_analysisfeature_analysisid_featureid');
+  $afeature = tripal_core_chado_select('analysisfeature', array('analysisfeature_id'), 
+    $af_values, $options);
   if (count($afeature)==0) {
     // if a score is avaialble then set that to be the significance field
     if (strcmp($score, '.')!=0) {
       $af_values['significance'] = $score;
     }
-    if (!tripal_core_chado_insert('analysisfeature', $af_values)) {
+    $options = array('statement_name' => 'ins_analysisfeature_analysisid_featureid_significance');
+    if (!tripal_core_chado_insert('analysisfeature', $af_values, $options)) {
       print "ERROR: could not add analysisfeature record: $analysis_id, $feature->feature_id\n";
     }
     else {
@@ -1178,35 +1201,4 @@ function tripal_feature_load_gff3_property($feature, $property, $value) {
     db_query($isql, $feature->feature_id, $cvterm->cvterm_id, $value, $rank);
   }
 }
-/*
-function tripal_feature_load_gff3_property($feature,$property,$value){
-   // first make sure the cvterm exists.  If the term already exists then
-   // the function should return it
-   $match = array(
-      'name' => $property,
-      'cv_id' => array(
-         'name' => 'feature_property',
-      ),
-   );
-   $cvterm = tripal_core_chado_select('cvterm',array('*'),$match);
-   if(sizeof($cvterm) == 0){
-      $term = array(
-         'id' => "null:$property",
-         'name' => $property,
-         'namespace' => 'feature_property',
-         'is_obsolete' => 0,
-      );
-      print "   Adding cvterm, $property\n";
-      $cvterm = tripal_cv_add_cvterm($term,'feature_property',0,0);
-   }
-
-   if(!$cvterm){
-      print "ERROR: cannot add cvterm, $property, before adding property\n";
-      exit;
-   }
-
-   // next give the feature the property
-   tripal_core_insert_property('feature',$feature->feature_id,$property,'feature_property',$value,1);
-}
- */
 

+ 1 - 1
tripal_feature/includes/syncFeatures.inc

@@ -261,7 +261,7 @@ function tripal_feature_sync_features($max_sync = 0, $organism_id = NULL,
       # to avoid this problem we will call this script through an
       # independent system call
       print "$i of $num_ids Syncing feature id: $feature_id\n";
-      $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/syncFeatures.php -f $feature_id ";
+      $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/includes/syncFeatures.inc -f $feature_id ";
       system($cmd);
 
     }

+ 25 - 16
tripal_feature/includes/tripal_feature-relationships.inc

@@ -119,14 +119,17 @@ function tripal_feature_add_ONE_relationship_form_validate($form, &$form_state)
       $links= array();
       for ($i=0; $i<sizeof($subject_results); $i++) {
       $links[] = l($i+1, "node/" . $subject_results[$i]->nid); }
-      $message = "Too many stocks match '" . $form_state['values']['subject_id'] . "'! "
-                  . " Please refine your input to match ONLY ONE stock. <br />"
-     . "To aid in this process, here are the stocks that match your initial input: "
-     . join(', ', $links);
+      $message = t("Too many features match '%object'! Please refine your input to match
+        ONLY ONE feature. <br />To aid in this process, here are the features that
+        match your initial input: %features",
+        array('%object' => $form_state['values']['subject_id'],
+          '%features' => join(', ', $links)
+        )
+      );
       form_set_error('subject_id', $message);
     }
     elseif (sizeof($subject_results) < 1) {
-      form_set_error('subject_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+      form_set_error('subject_id', t("There are no features matching your input. Please check your input for typos and/or lookup the feature <a href='!url'>here</a>", array('!url' => url('features'))));
     }
     elseif (sizeof($subject_results) == 1) {
       $form_state['values']['subject_id'] = $subject_results[0]->stock_id;
@@ -140,14 +143,17 @@ function tripal_feature_add_ONE_relationship_form_validate($form, &$form_state)
       $links= array();
       for ($i=0; $i<sizeof($object_results); $i++) {
       $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
-      $message = "Too many stocks match '" . $form_state['values']['object_id'] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br />"
-                 . "To aid in this process, here are the stocks that match your initial input: "
-                 . join(', ', $links);
+      $message = t("Too many features match '%object'! Please refine your input to match
+        ONLY ONE stock. <br />To aid in this process, here are the stocks that match
+        your initial input: %features",
+        array('%object' => $form_state['values']['object_id'],
+        '%features' => join(', ', $links)
+        )
+      );
       form_set_error('object_id', $message);
     }
     elseif (sizeof($object_results) < 1) {
-      form_set_error('object_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+      form_set_error('object_id', t("There are no features matching your input. Please check your input for typos and/or lookup the feature <a href='!url'>here</a>", array('!url' => url('features'))));
     }
     elseif (sizeof($object_results) == 1) {
       $form_state['values']['object_id'] = $object_results[0]->stock_id;
@@ -351,14 +357,17 @@ function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state
         $links= array();
         for ($j=0; $j<sizeof($subject_results); $j++) {
         $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
-        $message = "Too many stocks match '" . $form_state['values']["subject_id-$i"] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br />"
-                 . "To aid in this process, here are the stocks that match your initial input: "
-                 . join(', ', $links);
+        $message = t("Too many features match '%subject'!  Please refine your input to
+          match ONLY ONE feature. <br /> To aid in this process, here are the features that
+          match your initial input: %features",
+          array('%subject' => $form_state['values']["subject_id-$i"],
+            '%features' => join(', ', $links)
+          )
+        );
         form_set_error("subject_id-$i", $message);
       }
       elseif (sizeof($subject_results) < 1) {
-        form_set_error("subject_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+        form_set_error("subject_id-$i", t("There are no features matching your input. Please check your input for typos and/or lookup the <a href='!url'>here</a>", array('!url' => url('features'))));
       }
       elseif (sizeof($subject_results) == 1) {
         $form_state['values']["subject_id-$i"] = $subject_results[0]->stock_id;
@@ -379,7 +388,7 @@ function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state
         form_set_error("object_id-$i", $message);
       }
       elseif (sizeof($object_results) < 1) {
-        form_set_error("object_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+        form_set_error("object_id-$i", t("There are no features matching your input. Please check your input for typos and/or lookup the <a href='!url'>here</a>", array('!url' => url('features'))));
       }
       elseif (sizeof($object_results) == 1) {
         $form_state['values']["object_id-$i"] = $object_results[0]->stock_id;

+ 18 - 12
tripal_stock/tripal_stock-relationships.inc

@@ -121,7 +121,7 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
       form_set_error('subject_id', $message);
     }
     elseif (sizeof($subject_results) < 1) {
-      form_set_error('subject_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+      form_set_error('subject_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
     }
     elseif (sizeof($subject_results) == 1) {
       $form_state['values']['subject_id'] = $subject_results[0]->stock->stock_id;
@@ -133,14 +133,17 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
       $links= array();
       for ($i=0; $i<sizeof($object_results); $i++) {
       $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
-      $message = "Too many stocks match '" . $form_state['values']['object_id'] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br />"
-                 . "To aid in this process, here are the stocks that match your initial input: "
-                 . join(', ', $links);
+      $message = t("Too many stocks match '%object'!  Please refine your input to match
+        ONLY ONE stock. <br /> To aid in this process, here are the stocks that match your
+        initial input: %stocks.",
+        array('%object' => $form_state['values']['object_id'],
+          '%stocks' => join(', ', $links)
+        )
+      );
       form_set_error('object_id', $message);
     }
     elseif (sizeof($object_results) < 1) {
-      form_set_error('object_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+      form_set_error('object_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
     }
     elseif (sizeof($object_results) == 1) {
       $form_state['values']['object_id'] = $object_results[0]->stock->stock_id;
@@ -342,14 +345,17 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
         $links= array();
         for ($j=0; $j<sizeof($subject_results); $j++) {
         $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
-        $message = "Too many stocks match '" . $form_state['values']["subject_id-$i"] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br />"
-                 . "To aid in this process, here are the stocks that match your initial input: "
-                 . join(', ', $links);
+        $message = t("Too many stocks match '%subject'!  Please refine your input to match
+          ONLY ONE stock. <br /> To aid in this process, here are the stocks that match
+          your initial input: %stocks",
+          array('%subject' => $form_state['values']["subject_id-$i"],
+          '%stocks' => join(', ', $links)
+          )
+        );
         form_set_error("subject_id-$i", $message);
       }
       elseif (sizeof($subject_results) < 1) {
-        form_set_error("subject_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+        form_set_error("subject_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
       }
       elseif (sizeof($subject_results) == 1) {
         $form_state['values']["subject_id-$i"] = $subject_results[0]->stock->stock_id;
@@ -368,7 +374,7 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
         form_set_error("object_id-$i", $message);
       }
       elseif (sizeof($object_results) < 1) {
-        form_set_error("object_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
+        form_set_error("object_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
       }
       elseif (sizeof($object_results) == 1) {
         $form_state['values']["object_id-$i"] = $object_results[0]->stock->stock_id;