Browse Source

Tripal Views: Updated to DBTNG Database API -Module now enables without error

Lacey Sanderson 11 years ago
parent
commit
f7dfb60954

+ 114 - 47
tripal_views/api/tripal_views.api.inc

@@ -26,8 +26,10 @@
  */
 function tripal_views_get_table_lightest_priority($table_name) {
 
-  $sql = "SELECT priority FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
-  $setup = db_fetch_object(db_query($sql, $table_name));
+  // D7 TODO: Check DBTNG changes work
+  $sql = "SELECT priority FROM {tripal_views} WHERE table_name=:table ORDER BY priority ASC";
+  $setup = db_query($sql, array(':table' => $table_name));
+  $setup = $setup->fetchObject();
   if ($setup) {
     return $setup->priority;
   }
@@ -54,8 +56,10 @@ function tripal_views_get_table_lightest_priority($table_name) {
  */
 function tripal_views_get_lightest_priority_setup($table_name) {
 
-  $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
-  $setup = db_fetch_object(db_query($sql, $table_name));
+  // D7 TODO: Check DBTNG changes work
+  $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table ORDER BY priority ASC";
+  $setup = db_query($sql, array(':table' => $table_name));
+  $setup = $setup->fetchObject();
   if ($setup) {
     return $setup->setup_id;
   }
@@ -80,8 +84,10 @@ function tripal_views_get_lightest_priority_setup($table_name) {
  */
 function tripal_views_get_setup_id($table_name, $priority) {
 
-  $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d ORDER BY priority ASC";
-  $setup = db_fetch_object(db_query($sql, $table_name, $priority));
+  // D7 TODO: Check DBTNG changes work
+  $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority ORDER BY priority ASC";
+  $setup = db_query($sql, array(':table' => $table_name, ':priority' => $priority));
+  $setup = $setup->fetchObject();
   if ($setup) {
     return $setup->setup_id;
   }
@@ -108,12 +114,16 @@ function tripal_views_get_setup_id($table_name, $priority) {
 function tripal_views_is_integrated($table_name, $priority = NULL) {
 
   if ($priority) {
-    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d";
-    $setup = db_fetch_object(db_query($sql, $table_name, $priority));
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority";
+    $setup = db_query($sql, array(':table' => $table_name, ':priority' => $priority));
+    $setup = $setup->fetchObject();
   }
   else {
-    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
-    $setup = db_fetch_object(db_query($sql, $table_name));
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table ORDER BY priority ASC";
+    $setup = db_query($sql, array(':table' => $table_name));
+    $setup = $setup->fetchObject();
   }
   if ($setup) {
     return $setup->setup_id;
@@ -209,15 +219,22 @@ function tripal_views_integration_add_entry($defn_array) {
     'base_table' => $defn_array['base_table'],
   );
   if ($defn_array['type'] == 'mview') {
-    $mview = db_fetch_object(db_query("SELECT mview_id FROM {tripal_mviews} WHERE mv_table='%s'", $defn_array['table']));
+    // D7 TODO: Check DBTNG changes work
+    $mview = db_query("SELECT mview_id FROM {tripal_mviews} WHERE mv_table=:table", array(':table' => $defn_array['table']));
+    $mview = $mview->fetchObject();
     $view_record['mview_id'] = $mview->mview_id;
     if (!$mview->mview_id) {
       return FALSE;
     }
   }
   if ($view_record['name']) { // && $view_record['comment']) {  # SPF: commented out 9/24/2012 .. It's not required on the form
-    if ($defn_array['additional_content']) {
-      $setup = db_fetch_object(db_query("SELECT * FROM {tripal_views} WHERE table_name='%s' AND priority=%d", $view_record['table_name'], $view_record['priority']));
+    if (isset($defn_array['additional_content'])) {
+      // D7 TODO: Check DBTNG changes work
+      $setup = db_query(
+        "SELECT * FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
+        array(':table' => $view_record['table_name'], ':priority' => $view_record['priority'])
+      );
+      $setup = $setup->fetchObject();
       if (empty($setup->setup_id)) {
         $status = drupal_write_record('tripal_views', $view_record);
       }
@@ -240,11 +257,14 @@ function tripal_views_integration_add_entry($defn_array) {
     // Need to update the tripal_views record so base_table can be false
     // this is a fix because drupal_write_record() puts in defaults if !isset()
     // and a variable is considered not set if it's null!
+    // D7 TODO: Check DBTNG changes work
     db_query(
-      "UPDATE {tripal_views} SET base_table=%d WHERE table_name='%s' AND priority=%d",
-      $defn_array['base_table'],
-      $defn_array['table'],
-      $defn_array['priority']
+      "UPDATE {tripal_views} SET base_table=:base WHERE table_name=:table AND priority=:priority",
+      array(
+        ':base' => $defn_array['base_table'],
+        ':table' => $defn_array['table'],
+        ':priority' => $defn_array['priority']
+      )
     );
 
     // Insert Field Definitions
@@ -257,8 +277,16 @@ function tripal_views_integration_add_entry($defn_array) {
         'type' => $field['type'],
       );
       if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
-        if ($defn_array['additional_content']) {
-          $is = db_fetch_object(db_query("SELECT true as present FROM {tripal_views_field} WHERE column_name='%s' AND setup_id=%d", $field_record['column_name'], $field_record['setup_id']));
+        if (isset($defn_array['additional_content'])) {
+          // D7 TODO: Check DBTNG changes work
+          $is = db_query(
+            "SELECT true as present FROM {tripal_views_field} WHERE column_name=:column AND setup_id=:setup",
+            array(
+              ':column' => $field_record['column_name'],
+              ':setup' => $field_record['setup_id']
+              )
+            );
+          $is = $is->fetchObject();
           if (!$is->present) {
             $status = drupal_write_record('tripal_views_field', $field_record);
           }
@@ -371,7 +399,9 @@ function tripal_views_integration_add_entry($defn_array) {
 function tripal_views_integration_export_entry($setup_id) {
 
   // Main setup details
-  $r = db_fetch_object(db_query("SELECT * FROM {tripal_views} WHERE setup_id=%d", $setup_id));
+  // D7 TODO: Check DBTNG changes work
+  $r = db_query("SELECT * FROM {tripal_views} WHERE setup_id=:setup", array(':setup' => $setup_id));
+  $r = $r->fetchObject();
   $defn_array = array(
     'table' => $r->table_name,
     'name' => $r->name,
@@ -383,8 +413,9 @@ function tripal_views_integration_export_entry($setup_id) {
   );
 
   // Add fields
-  $resource = db_query("SELECT * FROM {tripal_views_field} WHERE setup_id=%d", $setup_id);
-  while ($r = db_fetch_object($resource)) {
+  // D7 TODO: Check DBTNG changes work
+  $resource = db_query("SELECT * FROM {tripal_views_field} WHERE setup_id=:setup", array(':setup' => $setup_id));
+  foreach ($resource as $r) {
     $defn_array['fields'][ $r->column_name ] = array(
         'name' => $r->column_name,
         'title' => $r->name,
@@ -396,16 +427,18 @@ function tripal_views_integration_export_entry($setup_id) {
   }
 
   // Add handlers
-  $resource = db_query("SELECT * FROM {tripal_views_handlers} WHERE setup_id=%d", $setup_id);
-  while ($r = db_fetch_object($resource)) {
+  // D7 TODO: Check DBTNG changes work
+  $resource = db_query("SELECT * FROM {tripal_views_handlers} WHERE setup_id=:setup", array(':setup' => $setup_id));
+  foreach ($resource as $r) {
     $defn_array['fields'][ $r->column_name ]['handlers'][ $r->handler_type ] = array(
       'name' => $r->handler_name
     );
   }
 
   // Add joins
-  $resource = db_query("SELECT * FROM {tripal_views_join} WHERE setup_id=%d", $setup_id);
-  while ($r = db_fetch_object($resource)) {
+  // D7 TODO: Check DBTNG changes work
+  $resource = db_query("SELECT * FROM {tripal_views_join} WHERE setup_id=:setup", array(':setup' => $setup_id));
+  foreach ($resource as $r) {
     $defn_array['fields'][ $r->base_field ]['joins'][ $r->left_table ] = array(
       'table' => $r->left_table,
       'field' => $r->left_field,
@@ -431,11 +464,15 @@ function tripal_views_integration_export_entry($setup_id) {
  */
 function tripal_views_integration_remove_entry_by_table_name($table_name, $priority) {
 
-  $views = db_fetch_object(db_query(
-    "SELECT * FROM {tripal_views} WHERE table_name='%s' AND priority=%d",
-    $table_name,
-    $priority
-  ));
+  // D7 TODO: Check DBTNG changes work
+  $views = db_query(
+    "SELECT * FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
+    array(
+      ':table' => $table_name,
+      ':priority' => $priority
+    )
+  );
+  $views = $views->fetchObject();
   if ($views->setup_id) {
     tripal_views_integration_remove_entry_by_setup_id($views->setup_id);
     return TRUE;
@@ -456,10 +493,11 @@ function tripal_views_integration_remove_entry_by_table_name($table_name, $prior
  */
 function tripal_views_integration_remove_entry_by_setup_id($setup_id) {
 
-    db_query('DELETE FROM {tripal_views} WHERE setup_id=%d', $setup_id);
-    db_query('DELETE FROM {tripal_views_field} WHERE setup_id=%d', $setup_id);
-    db_query('DELETE FROM {tripal_views_handlers} WHERE setup_id=%d', $setup_id);
-    db_query('DELETE FROM {tripal_views_join} WHERE setup_id=%d', $setup_id);
+    // D7 TODO: Check DBTNG changes work
+    db_query('DELETE FROM {tripal_views} WHERE setup_id=:setup', array(':setup' => $setup_id));
+    db_query('DELETE FROM {tripal_views_field} WHERE setup_id=:setup', array(':setup' => $setup_id));
+    db_query('DELETE FROM {tripal_views_handlers} WHERE setup_id=:setup', array(':setup' => $setup_id));
+    db_query('DELETE FROM {tripal_views_join} WHERE setup_id=:setup', array(':setup' => $setup_id));
 
 }
 
@@ -749,8 +787,16 @@ function tripal_views_clone_integration($table_name, $new_priority = NULL, $temp
     $defn_array['priority'] = $defn_array['priority'] - 1;
   }
 
+  // D7 TODO: Check DBTNG changes work
   tripal_views_integration_add_entry($defn_array);
-  $setup_id = db_result(db_query("SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d", $table_name, $new_priority));
+  $setup_id = db_query(
+    "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
+    array(
+      ':table' => $table_name,
+      ':priority' => $new_priority
+    )
+  );
+  $setup_id = $setup_id->fetchObject();
 
   if (empty($setup_id)) {
     watchdog('tripal_views','Unable to clone the setup for %table in order to add the following field to the integration: %field.',
@@ -791,7 +837,15 @@ function tripal_views_add_field_to_integration($table_name, $priority, $field) {
   }
 
   // First get the setup_id
-  $setup_id = db_result(db_query("SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d", $table_name, $priority));
+  // D7 TODO: Check DBTNG changes work
+  $setup_id = db_query(
+    "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
+    array(
+      ':table' => $table_name,
+      ':priority' => $priority
+    )
+  );
+  $setup_id = $setup_id->fetchObject();
 
   // If there isn't an integration matching that table/priority combination
   // then clone the lightest priority integration
@@ -800,9 +854,15 @@ function tripal_views_add_field_to_integration($table_name, $priority, $field) {
   }
 
   // Now delete any existing field
-  db_query("DELETE FROM {tripal_views_field} WHERE setup_id=%d AND column_name='%s'", $setup_id, $field['name']);
-  db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id=%d AND column_name='%s'", $setup_id, $field['name']);
-  db_query("DELETE FROM {tripal_views_join} WHERE setup_id=%d AND base_table='%s' AND base_field='%s'", $setup_id, $table_name, $field['name']);
+  db_query("DELETE FROM {tripal_views_field} WHERE setup_id=:setup AND column_name=:column",
+    array(':setup' => $setup_id, 'column' => $field['name'])
+  );
+  db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id=:setup AND column_name=:column",
+    array(':setup' => $setup_id, 'column' => $field['name'])
+  );
+  db_query("DELETE FROM {tripal_views_join} WHERE setup_id=:setup AND base_table=:table AND base_field=:field",
+    array(':setup' => $setup_id, ':table' => $table_name, ':field' => $field['name'])
+  );
 
   // Now we need to add/update the field
   $field_record = array(
@@ -814,7 +874,12 @@ function tripal_views_add_field_to_integration($table_name, $priority, $field) {
   );
   if ($setup_id && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
     if ($defn_array['additional_content']) {
-      $is = db_fetch_object(db_query("SELECT true as present FROM {tripal_views_field} WHERE column_name='%s' AND setup_id=%d", $field_record['column_name'], $field_record['setup_id']));
+      // D7 TODO: Check DBTNG changes work
+      $is = db_query(
+        "SELECT true as present FROM {tripal_views_field} WHERE column_name=:column AND setup_id=:setup",
+        array(':column' => $field_record['column_name'], ':setup' => $field_record['setup_id'])
+      );
+      $is = $is->fetchObject();
       if (!$is->present) {
         $status = drupal_write_record('tripal_views_field', $field_record);
       }
@@ -924,11 +989,13 @@ function tripal_views_add_field_to_integration($table_name, $priority, $field) {
  */
 function tripal_views_remove_join_from_integration($setup_id, $base_table, $base_field, $left_table, $left_field) {
   db_query(
-    "DELETE FROM {tripal_views_join} WHERE setup_id=%d AND base_table='%s' AND base_field='%s' AND left_table='%s' AND left_field='%s'",
-    $setup_id,
-    $base_table,
-    $base_field,
-    $left_table,
-    $left_field
+    "DELETE FROM {tripal_views_join} WHERE setup_id=:setup AND base_table=:base-table AND base_field=:base-field AND left_table=:left-table AND left_field=:left-field",
+    array(
+      ':setup' => $setup_id,
+      ':base-table' => $base_table,
+      ':base-field' => $base_field,
+      ':left-table' => $left_table,
+      ':left-field' => $left_field
+    )
   );
 }

+ 43 - 27
tripal_views/includes/tripal_views_integration.inc

@@ -34,12 +34,13 @@ function tripal_views_integration_setup_list() {
   $rows = array();
 
   // get the list of materialized views
+  // D7 TODO: Check DBTNG changes work
   $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tc.table_id, tv.priority, tv.comment '
                      .'FROM {tripal_views} tv '
                      .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
                      .'WHERE tv.mview_id IS NOT NULL '
                      .'ORDER BY tv.table_name ASC, tv.priority ASC');
-  while ($tview = db_fetch_object($tviews)) {
+  foreach ($tviews as $tview) {
     $rows[] = array(
       l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) . "<br />"
         . l(t('Export'), "admin/tripal/views/integration/export/" . $tview->setup_id) . "<br />"
@@ -67,12 +68,13 @@ function tripal_views_integration_setup_list() {
   $rows = array();
 
   // get the list of chado tables
+  // D7 TODO: Check DBTNG changes work
   $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tv.priority, tv.comment '
                      .'FROM {tripal_views} tv '
                      .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
                      .'WHERE mview_id IS NULL AND tc.table_id IS NOT NULL '
                      .'ORDER BY table_name ASC, priority ASC');
-  while ($tview = db_fetch_object($tviews)) {
+  foreach ($tviews as $tview) {
     $rows[] = array(
       l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) . "<br />"
         . l(t('Export'), "admin/tripal/views/integration/export/" . $tview->setup_id) . "<br />"
@@ -97,12 +99,13 @@ function tripal_views_integration_setup_list() {
   $rows = array();
 
   // get the list of chado tables
+  // D7 TODO: Check DBTNG changes work
   $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tv.priority, tv.comment '
                      .'FROM {tripal_views} tv '
                      .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
                      .'WHERE mview_id IS NULL AND tc.table_id IS NULL '
                      .'ORDER BY table_name ASC, priority ASC');
-  while ($tview = db_fetch_object($tviews)) {
+  foreach ($tviews as $tview) {
     $rows[] = array(
       l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) . "<br />"
         . l(t('Export'), "admin/tripal/views/integration/export/" . $tview->setup_id) . "<br />"
@@ -167,44 +170,50 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
   if (isset($setup_id)) {
 
     // get the deafult setup values
-    $sql = "SELECT * FROM {tripal_views} WHERE setup_id = %d";
-    $setup_obj = db_fetch_object(db_query($sql, $setup_id));
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_views} WHERE setup_id = :setup";
+    $setup_obj = db_query($sql, array(':setup' => $setup_id));
+    $setup_obj = $setup_obj->fetchObject();
     $mview_id = $setup_obj->mview_id;
     $table_name = $setup_obj->table_name;
     $form_state['values']['mview_id'] = $mview_id;
     $form_state['values']['table_name'] = $table_name;
 
     // get the default field name/description
-    $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
-    $query = db_query($sql, $setup_id);
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=:setup";
+    $query = db_query($sql, array(':setup' => $setup_id));
     $default_fields = array();
-    while ($field = db_fetch_object($query)) {
+    foreach ($query as $field) {
       $default_fields[$field->column_name]['name'] = $field->name;
       $default_fields[$field->column_name]['description'] = $field->description;
     }
 
     // get the default join settings and handlers
-    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-    $query = db_query($sql, $setup_id);
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
+    $query = db_query($sql, array(':setup' => $setup_id));
     $default_joins = array();
-    while ($join = db_fetch_object($query)) {
+    foreach ($query as $join) {
       $default_joins[$join->base_field]['left_table'] = $join->left_table;
       $default_joins[$join->base_field]['left_field'] = $join->left_field;
     }
 
     // get the default handlers
-    $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d";
-    $query = db_query($sql, $setup_id);
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = :setup";
+    $query = db_query($sql, array(':setup' => $setup_id));
     $default_handlers = array();
-    while ($handler = db_fetch_object($query)) {
+    foreach ($query as $handler) {
       $default_handlers[$handler->column_name][$handler->handler_type]['handler_name'] = $handler->handler_name;
       $default_handlers[$handler->column_name][$handler->handler_type]['arguments'] = $handler->arguments;
     }
 
     // get the default join handlers
-    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-    $query = db_query($sql, $setup_id);
-    while ($handler = db_fetch_object($query)) {
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
+    $query = db_query($sql, array(':setup' => $setup_id));
+    foreach ($query as $handler) {
       $default_handlers[$handler->base_field]['join']['handler_name'] = $handler->handler;
       //$default_handlers[$handler->base_field]['join']['arguments'] = $handler->arguments;
     }
@@ -247,10 +256,11 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
 
 
   // build the form element that lists the materialized views
+  // D7 TODO: Check DBTNG changes work
   $query = db_query("SELECT mview_id, name FROM {tripal_mviews} WHERE mv_schema is NULL or mv_schema = '' ORDER BY name");
   $mview_tables = array();
   $mview_tables['0'] = 'Select';
-  while ($mview = db_fetch_object($query)) {
+  foreach ($query as $mview) {
     $mview_tables[$mview->mview_id] = $mview->name;
   }
   $form['base_table_type']['mview_id'] = array(
@@ -366,8 +376,10 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
     // where the first word is the column name and the rest is the type
     $columns = array();
     if ($mview_id) {
-      $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
-      $mview = db_fetch_object(db_query($sql, $mview_id));
+      // D7 TODO: Check DBTNG changes work
+      $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = :id";
+      $mview = db_query($sql, array(':id' => $mview_id));
+      $mview = $mview->fetchObject();
       $columns = explode(",", $mview->mv_specs);
     }
     else {
@@ -847,8 +859,10 @@ function tripal_views_integration_form_submit($form, &$form_state) {
 
   // get details about this mview
   if ($mview_id) {
-    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
-    $mview = db_fetch_object(db_query($sql, $mview_id));
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :id";
+    $mview = db_query($sql, array(':id' => $mview_id));
+    $mview = $mview->fetchObject();
     $table_name = $mview->mv_table;
     $table_id = $mview_id;
     $type = 'mview';
@@ -862,8 +876,10 @@ function tripal_views_integration_form_submit($form, &$form_state) {
   $tripal_views_record = array();
   if ($mview_id) {
     // get details about this mview
-    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
-    $mview = db_fetch_object(db_query($sql, $mview_id));
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :id";
+    $mview = db_query($sql, array(':id' => $mview_id));
+    $mview = $mview->fetchObject();
 
     // build the record for insert/update
     $tripal_views_record = array(
@@ -913,9 +929,9 @@ function tripal_views_integration_form_submit($form, &$form_state) {
 
   // if this is an update then clean out the existing joins and handlers so we can add new ones
   if ($setup_id) {
-    db_query("DELETE FROM {tripal_views_field} WHERE setup_id = %d", $setup_id);
-    db_query("DELETE FROM {tripal_views_join} WHERE setup_id = %d", $setup_id);
-    db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id = %d", $setup_id);
+    db_query("DELETE FROM {tripal_views_field} WHERE setup_id = :setup", array(':setup' => $setup_id));
+    db_query("DELETE FROM {tripal_views_join} WHERE setup_id = :setup", array(':setup' => $setup_id));
+    db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id = :setup", array(':setup' => $setup_id));
   }
 
   // iterate through the columns of the form and add

+ 1 - 1
tripal_views/tripal_views.info

@@ -1,6 +1,6 @@
 name = Tripal Views
 description = This module provides integration with Drupal Views. Other Tripal modules may have an optional dependency with this module and once enabled Views support becomes active for those modules.  This module provides a way to integrate Materialized Views and Chado Tables with Views. It also integrates the Views Data Export module to allow for downloads of Views into Excel, CSV and FASTA formats.
-core = 6.x
+core = 7.x
 project = tripal_core
 package = Tripal
 version = 7.x-2.0beta

+ 3 - 1
tripal_views/tripal_views.module

@@ -116,7 +116,9 @@ function tripal_views_init() {
   // the user go to views UI. It would be ideal to do this in a hook called only once
   // directly after install/enabling of the module but such a hook doesn't
   // exist in Drupal 6
-  $tripal_views = db_fetch_object(db_query("SELECT true as has_rows FROM {tripal_views}"));
+  // D7 TODO: Check DBTNG changes work
+  $tripal_views = db_query("SELECT true as has_rows FROM {tripal_views}");
+  $tripal_views = $tripal_views->fetchObject();
   if (!$tripal_views->has_rows) {
     tripal_views_integrate_all_chado_tables();
   }

+ 51 - 41
tripal_views/tripal_views.views.inc

@@ -237,7 +237,8 @@ function tripal_views_views_data() {
 
   $tvi_query = db_query('SELECT * FROM {tripal_views}');
 
-  while ($tvi_row = db_fetch_object($tvi_query)) {
+  // D7 TODO: Check DBTNG changes work
+  foreach ($tvi_query as $tvi_row) {
 
     // check to see if this is the lightest (drupal-style) priority setup for this table
     // if not then don't use this definition
@@ -262,8 +263,10 @@ function tripal_views_views_data() {
     if ($mview_id) {
 
       // get the base table name from the materialized view
-      $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
-      $mview_table = db_fetch_object(db_query($sql, $mview_id));
+      // D7 TODO: Check DBTNG changes work
+      $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = :id";
+      $mview_table = db_query($sql, array(':id' => $mview_id));
+      $mview_table = $mview_table->fetchObject();
       $base_table = $mview_table->name;
 
       // get the columns in this materialized view.  They are separated by commas
@@ -281,9 +284,10 @@ function tripal_views_views_data() {
       }
 
       // get the field name and descriptions
-      $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
-      $query = db_query($sql, $setup_id);
-      while ($field = db_fetch_object($query)) {
+      // D7 TODO: Check DBTNG changes work
+      $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=:setup";
+      $query = db_query($sql, array(':setup' => $setup_id));
+      foreach($query as $field) {
         $base_fields[$field->column_name]['name'] = $field->name;
         $base_fields[$field->column_name]['help'] = $field->description;
       }
@@ -297,16 +301,17 @@ function tripal_views_views_data() {
       // as compared to create a whole new one
       if ($base_table == 'node') {
 
-      	/* -- SPF Jun 13, 2013 -- not sure why the node table 
+      	/* -- SPF Jun 13, 2013 -- not sure why the node table
       	 *    is included in the Chado integrated tables. I've commented
-      	 *    out.  I think it was here for integration of chado tables wiht 
+      	 *    out.  I think it was here for integration of chado tables wiht
       	 *    nodes, but code to do this has been added below and it's not
       	 *    necessary to have the node table in the list of integrated tables
       	 *
         // Add any joins between the node table and other tables
+        // D7 TODO: Check DBTNG changes work
         $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
         $joins = db_query($sql, $setup_id);
-        while ($join = db_fetch_object($joins)) {
+        foreach ($joins as $join) {
           $left_table = $join->left_table;
           $left_field = $join->left_field;
           $base_field = $join->base_field;
@@ -324,9 +329,10 @@ function tripal_views_views_data() {
 
 
         // Add in any handlers for node fields
+        // D7 TODO: Check DBTNG changes work
         $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id=%d";
         $query = db_query($sql, $setup_id);
-        while ($handler = db_fetch_object($query)) {
+        foreach ($query as $handler) {
           $data[$base_table][$handler->column_name][$handler->handler_type]['handler'] = $handler->handler_name;
 
           // Add in any additional arguments
@@ -337,7 +343,7 @@ function tripal_views_views_data() {
         }
         */
         continue;
-      } 
+      }
 
       // get the table description
       $table_desc = tripal_core_get_chado_table_schema($base_table);
@@ -354,9 +360,9 @@ function tripal_views_views_data() {
       }
 
       // get the field name and descriptions
-      $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
-      $query = db_query($sql, $setup_id);
-      while ($field = db_fetch_object($query)) {
+      $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=:setup";
+      $query = db_query($sql, array(':setup' => $setup_id));
+      foreach ($query as $field) {
         $base_fields[$field->column_name]['name'] = $field->name;
         $base_fields[$field->column_name]['help'] = $field->description;
       }
@@ -392,9 +398,10 @@ function tripal_views_views_data() {
 
 
       // now add the handlers
-      $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
-      $handlers = db_query($sql, $setup_id, $column_name);
-      while ($handler = db_fetch_object($handlers)) {
+      // D7 TODO: Check DBTNG changes work
+      $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = :setup AND column_name = :column";
+      $handlers = db_query($sql, array(':setup' => $setup_id, ':column' => $column_name));
+      foreach ($handlers as $handler) {
         $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
 
         // Add in any additional arguments
@@ -403,18 +410,18 @@ function tripal_views_views_data() {
           $data[$base_table][$column_name][$handler->handler_type] = array_merge($data[$base_table][$column_name][$handler->handler_type], unserialize($handler->arguments));
         }
       };
-      
+
       // add in joins to the node tables if the Chado schema is local
 		  if (tripal_core_chado_schema_exists()) {
-		    
+
 		    $linker_table = 'chado_' . $base_table;
 		    $linker_name = ucwords(str_replace('_', ' ', $base_table));
 		    $schema = tripal_core_get_chado_table_schema($base_table);
 		    $pkey = $schema['primary key'][0];
-		    
+
 		    // if a node linking table exists then add in the joins
-		    if (db_table_exists($linker_table)) {		
-		    		    		      
+		    if (db_table_exists($linker_table)) {
+
 		    	// add the linker table to the data array
 			    $data[$linker_table] = array(
 			      // describe the table
@@ -462,8 +469,8 @@ function tripal_views_views_data() {
               'sort' => array(
                 'handler' => 'views_handler_sort',
               ),
-            ),            
-          );  
+            ),
+          );
 
           // add the join instructions for the base table
           // (we'll add the recipricol joins for the node table in the hook_views_data_alter
@@ -477,7 +484,7 @@ function tripal_views_views_data() {
             'field' => 'organism_id',
           );
 
-			
+
 			    // Add relationship between linker and base table
 			    $data[$linker_table][$base_table . '_nid'] = array(
 			      'group' => $linker_name,
@@ -493,7 +500,7 @@ function tripal_views_views_data() {
 			        'base field' => $pkey
 			      ),
 			    );
-			
+
 			    // Add node relationship to base table
 			    $data[$linker_table][$linker_table .'_nid'] = array(
 			      'group' => $linker_name,
@@ -509,22 +516,23 @@ function tripal_views_views_data() {
 			        'base field' => 'nid'
 			      ),
 			    );
-		    } 
-		  }		  
+		    }
+		  }
     }
 
     // now add the joins
-    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-    $joins = db_query($sql, $setup_id);
+    // D7 TODO: Check DBTNG changes work
+    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
+    $joins = db_query($sql, array(':setup' => $setup_id));
     if (!isset($joins)) {
       $joins = array();
     }
-    while ($join = db_fetch_object($joins)) {
+    foreach ($joins as $join) {
       $left_table = $join->left_table;
       $left_field = $join->left_field;
       $base_field = $join->base_field;
       $handler = $join->handler;
-      
+
       // if the 'node' table is in our integrated list then
       // we want to skip it. It shouldn't be there.
       if ($left_table == 'node') {
@@ -549,21 +557,23 @@ function tripal_views_views_data() {
  * @ingroup tripal_views
  */
 function tripal_views_views_data_alter(&$data) {
+    // D7 TODO: Check DBTNG changes work
     $tvi_query = db_query('SELECT * FROM {tripal_views}');
 
     // iterate through the views that we manage
-    while ($tvi_row = db_fetch_object($tvi_query)) {
+    foreach ($tvi_query as $tvi_row) {
 
       //ids we'll use for queries
       $mview_id = $tvi_row->mview_id;
       $setup_id = $tvi_row->setup_id;
-      
+
 
       // iterate through the columns and alter the existing data array for
       // joins to other tables
-      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-      $joins = db_query($sql, $setup_id);
-      while ($join = db_fetch_object($joins)) {
+      // D7 TODO: Check DBTNG changes work
+      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
+      $joins = db_query($sql, array(':setup' => $setup_id));
+      foreach ($joins as $join) {
         $left_table = $join->left_table;
         $left_field = $join->left_field;
         $base_field = $join->base_field;
@@ -577,14 +587,14 @@ function tripal_views_views_data_alter(&$data) {
           );
         }
       }
-      
+
       // add in joins to the node tables if the Chado schema is local
       if (tripal_core_chado_schema_exists()) {
         $base_table = $tvi_row->table_name;
         $linker_table = 'chado_' . $base_table;
         // if a node linking table exists then add in the joins
-        if (db_table_exists($linker_table)) {         
-      
+        if (db_table_exists($linker_table)) {
+
           $data['node']['table']['join'][$linker_table] = array(
             'left_field' => 'nid',
             'field' => 'nid',
@@ -596,7 +606,7 @@ function tripal_views_views_data_alter(&$data) {
           );
         }
       }
-    }     
+    }
     return $data;
 }
 

+ 6 - 1
tripal_views/views/handlers/chado_views_handler_filter_boolean_operator.inc

@@ -66,7 +66,12 @@ class chado_views_handler_filter_boolean_operator extends views_handler_filter_b
     }
 
     // check if its a t/f or 1/0 boolean
-    $check = db_fetch_object(db_query("SELECT %s as val FROM %s LIMIT 1", $this->real_field, $this->table));
+    // D7 TODO: Check DBTNG changes work
+    $check = db_query(
+      "SELECT :field as val FROM :table LIMIT 1",
+      array(':field' => $this->real_field, ':table' => $this->table)
+    );
+    $check = $check->fetchObject();
     if (preg_match('/^[tTfF]/', $check->val)) {
       $true = 't';
       $false = 'f';

+ 12 - 2
tripal_views/views/handlers/chado_views_handler_filter_date.inc

@@ -50,7 +50,12 @@ class chado_views_handler_filter_date extends views_handler_filter_date {
   function op_between($field) {
 
     // Check whether we have a UNIX timestamp or an ISO Timestamp
-    $check = db_fetch_object(db_query("SELECT $this->real_field as val FROM $this->table WHERE $this->real_field IS NOT NULL LIMIT 1"));
+    // D7 TODO: Check DBTNG changes work
+    $check = db_query(
+      "SELECT :field as val FROM :table WHERE :field IS NOT NULL LIMIT 1",
+      array(':field' => $this->real_field, ':table' => $this->table)
+    );
+    $check = $check->fetchObject();
     if (preg_match('/^\d+$/', $check->val)) {
       // this is a unix timestamp
       $is_unix = TRUE;
@@ -102,7 +107,12 @@ class chado_views_handler_filter_date extends views_handler_filter_date {
     $value = intval(strtotime($this->value['value'], 0));
 
     // Check whether we have a UNIX timestamp or an ISO Timestamp
-    $check = db_fetch_object(db_query("SELECT $this->real_field as val FROM $this->table WHERE $this->real_field IS NOT NULL LIMIT 1"));
+    // D7 TODO: Check DBTNG changes work
+    $check = db_query(
+      "SELECT :field as val FROM :table WHERE :field IS NOT NULL LIMIT 1",
+      array(':field' => $this->real_field, ':table' => $this->table)
+    );
+    $check = $check->fetchObject();
     if (preg_match('/^\d+$/', $check->val)) {
       // this is a unix timestamp
       $is_unix = TRUE;

+ 4 - 2
tripal_views/views/handlers/deprecated/views_handler_field_chado_count.inc

@@ -45,13 +45,15 @@ class views_handler_field_chado_count extends views_handler_field {
       $primary_id = $record->{$this->aliases['primary_id']};
 
       //Select count from database
+      // D7 TODO: Check DBTNG changes work
       $sql = 'SELECT count(*) as count FROM %s WHERE %s=%d';
-      $result = db_fetch_object(chado_query(
+      $result = chado_query(
         $sql,
         $this->aliases['current_table'],
         $this->aliases['foreign_key'],
         $primary_id
-      ));
+      );
+      $result = $result->fetchObject();
 
       //Add to view results
       $this->view->result[$key]->{$this->field} = $result->count;

+ 3 - 1
tripal_views/views/handlers/deprecated/views_handler_field_dbxref_accession_link.inc

@@ -27,8 +27,10 @@ class views_handler_field_dbxref_accession_link extends views_handler_field {
     $db_id = $values->{$this->aliases['db_id']};
 
     if (!empty($db_id) AND !empty($accession)) {
+      // D7 TODO: Check DBTNG changes work
       // @coder-ignore: non-drupal schema therefore table prefixing does not apply
-      $result = db_fetch_object(chado_query('SELECT urlprefix FROM {db} WHERE db_id=%d', $db_id));
+      $result = chado_query('SELECT urlprefix FROM {db} WHERE db_id=%d', $db_id);
+      $result = $result->fetchObject()
       $urlprefix = $result->urlprefix;
 
       if (!empty($urlprefix)) {

+ 4 - 2
tripal_views/views/handlers/deprecated/views_handler_filter_chado_select_cvterm_name.inc

@@ -41,9 +41,10 @@ class views_handler_filter_chado_select_cvterm_name extends views_handler_filter
             .' LEFT JOIN {cvterm} cvterm ON cvterm.cvterm_id=' . $this->view->base_table . '.type_id '
             .'LEFT JOIN {cv} cv ON cv.cv_id=cvterm.cv_id';
         }
+        // D7 TODO: Check DBTNG changes work
         $resource = chado_query($sql);
         $cvterms = array();
-        while ( $r = db_fetch_object($resource) ) {
+        foreach ($resource as $r) {
           $results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array('cv_id' => $r->cv_id));
           if (empty($results)) {
             $results = array();
@@ -56,11 +57,12 @@ class views_handler_filter_chado_select_cvterm_name extends views_handler_filter
 
     }
     else {
+      // D7 TODO: Check DBTNG changes work
       // @coder-ignore: non-drupal schema therefore table prefixing does not apply
       $sql = "SELECT cvterm_id, name FROM {cvterm} WHERE cvterm_id IN (SELECT distinct(type_id) FROM {%s})";
       $resource = chado_query($sql, $this->table);
       $cvterms = array();
-      while ( $r = db_fetch_object($resource) ) {
+      foreach ($resource as $r) {
         $cvterms[$r->cvterm_id] = $r->name;
       }
     }

+ 4 - 3
tripal_views/views/handlers/deprecated/views_handler_filter_chado_select_string.inc

@@ -78,7 +78,7 @@ class views_handler_filter_chado_select_string extends views_handler_filter_stri
       $where = '';
       $filters = $this->view->filter;
       foreach ($filters as $filter_name => $details) {
-         // we only want to inclue non-exposed filters 
+         // we only want to inclue non-exposed filters
          if ($details->options['exposed'] == FALSE) {
             // we only want to filter on the table we're getting the list from
             if (strcmp($details->table, $this->table)==0) {
@@ -86,7 +86,7 @@ class views_handler_filter_chado_select_string extends views_handler_filter_stri
               $where .= ' AND ';
             }
          }
-      } 
+      }
       if ($where) {
          $where = "WHERE $where";
          $where = substr($where, 0, -5); # remove the final ' AND '
@@ -105,7 +105,8 @@ class views_handler_filter_chado_select_string extends views_handler_filter_stri
         //$options['<select '.$this->table.'>'] = '--None--';
         $options['All'] = '--Any--';
       }
-      while ($r = db_fetch_object($results)) {
+      // D7 TODO: Check DBTNG changes work
+      foreach ($results as $r) {
         if (drupal_strlen($r->{$this->field}) > $max_length) {
           $options[$r->{$this->field}] = drupal_substr($r->{$this->field}, 0, $max_length) . '...';
         }

+ 48 - 48
tripal_views/views/handlers/tripal_views_handler_field_sequence.inc

@@ -5,13 +5,13 @@
  * A chado wrapper for the views_handler_field.
  *
  * Handles display of sequence data.  If will aggregate sequences that need
- * to be aggregated (e.g. coding sequences) and provide 
+ * to be aggregated (e.g. coding sequences) and provide
  */
 class tripal_views_handler_field_sequence extends chado_views_handler_field {
 
   function init(&$view, $options) {
-    parent::init($view, $options);  
-        
+    parent::init($view, $options);
+
   }
 
   /**
@@ -47,7 +47,7 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
       '#title' => t('Derive sequence from parent'),
       '#description' => t('Rather than use the sequence from the \'residues\' of this feature, you may ' .
         'derive the sequence from the parent features to which it is aligned. This is useful in the case that the feature ' .
-        'does not have sequence associated with it and we need to get it through it\'s alignment. ' . 
+        'does not have sequence associated with it and we need to get it through it\'s alignment. ' .
         'Note: this will slow queries with large numbers of results on the page.'),
       '#default_value' => $this->options['display']['derive_from_parent'],
     );
@@ -71,14 +71,14 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
       '#description' => t('Choose an output format.  Raw output cannot be used when the sequence is derived from the parent.'),
       '#default_value' => $default_ouput_format,
     );
-  }  
+  }
 
   /**
   * We need to add a few fields to our query
   */
   function query() {
     parent::query();
-    
+
     // if we are going to get the sequence from the parent then
     // we will need to do more queries in the render function
     // and we must have the feature_id to do those
@@ -88,25 +88,25 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
       $this->query->add_field($this->table, 'name');
     }
   }
-    
+
   /**
   * Prior to display of results we want to format the sequence
   */
   function render($values) {
     $residues = '';
-             
+
     // get the number of bases to show per line
     $num_bases_per_line = $this->options['display']['num_bases_per_line'];
     $output_format = $this->options['display']['output_format'];
 
     // get the residues from the feature.residues column
     $field = $this->field_alias;
-    
+
     // get the feature id
     $feature_id = $values->feature_feature_id;
     $feature_name = $values->feature_name;
-        
-    // the upstream and downstream values get set by the 
+
+    // the upstream and downstream values get set by the
     // tripal_views_handlers_filter_sequence.inc
     $upstream = $_SESSION['upstream'];
     $downstream = $_SESSION['downstream'];
@@ -116,54 +116,54 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
     if (!$downstream) {
        $downstream = 0;
     }
-    
+
     $derive_from_parent = $this->options['display']['derive_from_parent'];
     $aggregate = $this->options['display']['aggregate'];
-    
-    $residues = tripal_feature_get_formatted_sequence($feature_id, $feature_name, 
+
+    $residues = tripal_feature_get_formatted_sequence($feature_id, $feature_name,
       $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
       $upstream, $downstream);
- /*   
+ /*
     // if we need to get the sequence from the parent but there is no aggregation
     // then do so now.
-    if ($this->options['display']['derive_from_parent']) {             
-      
+    if ($this->options['display']['derive_from_parent']) {
+
       // execute our prepared statement
       if (tripal_core_is_sql_prepared('sequence_by_parent')) {
         $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
         $parents = chado_query($sql, $upstream, $downstream, $feature_id);
       }
 
-      while ($parent = db_fetch_object($parents)) {  
+      while ($parent = d-b_f-etch_object($parents)) {
         $seq = '';  // initialize the sequence for each parent
-                
+
         // if we are to aggregate then we will ignore the feature returned
         // by the query above and rebuild it using the sub features
         if ($this->options['display']['aggregate']){
-          
+
           // now get the sub features that are located on the parent.
           $sql = "EXECUTE sub_features (%d, %d)";
           $children = chado_query($sql, $feature_id, $parent->srcfeature_id);
           $sql = "EXECUTE count_sub_features (%d, %d)";
-          $num_children = db_fetch_object(chado_query($sql, $feature_id, $parent->srcfeature_id));
-                 
+          $num_children = d-b_f-etch_object(chado_query($sql, $feature_id, $parent->srcfeature_id));
+
           // iterate through the sub features and concat their sequences. They
           // should already be in order.
           $types = array();
           $i = 0;
-          while($child = db_fetch_object($children)) {
+          while($child = d-b_f-etch_object($children)) {
             // keep up with the types
             if (!in_array($child->type_name,$types)) {
               $types[] = $child->type_name;
             }
-            
+
             $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
 
             // if the first sub feature we need to include the upstream bases
             if ($i == 0 and $parent->strand >= 0) {
               // -------------------------- ref
-              //    ....---->  ---->        
-              //     up    1       2         
+              //    ....---->  ---->
+              //     up    1       2
               $q = chado_query($sql, $upstream, 0, $child->feature_id);
             }
             elseif ($i == 0 and $parent->strand < 0) {
@@ -171,7 +171,7 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
               //    ....<----  <----
               //    down  1       2
               $q = chado_query($sql, 0, $downstream, $child->feature_id);
-            }          
+            }
             // if the last sub feature we need to include the downstream bases
             elseif ($i == $num_children->num_children - 1 and $parent->strand >= 0) {
               // -------------------------- ref
@@ -185,38 +185,38 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
               //          1       2  up
               $q = chado_query($sql, $upstream, 0, $child->feature_id);
             }
-            
+
             // for internal sub features we don't want upstream or downstream bases
-            else {         
+            else {
               $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
               $q = chado_query($sql, 0, 0, $child->feature_id);
             }
-            
-            while($subseq = db_fetch_object($q)){
-              // concatenate the sequences of all the sub features            
+
+            while ($subseq = d-b_f-etch_object($q)){
+              // concatenate the sequences of all the sub features
               if($subseq->srcfeature_id == $parent->srcfeature_id){
-                $seq .= $subseq->residues;   
+                $seq .= $subseq->residues;
               }
-            }                 
+            }
             $i++;
-          } 
-        } 
+          }
+        }
         // if this isn't an aggregate then use the parent residues
         else {
            $seq = $parent->residues;
         }
-                              
+
         // get the reverse compliment if feature is on the reverse strand
         $dir = 'forward';
         if ($parent->strand < 0) {
           $seq = trpial_feature_reverse_complement($seq);
           $dir = 'reverse';
         }
-        
+
         // now format for display
         if ($output_format == 'fasta_html') {
            $seq = wordwrap($seq, $num_bases_per_line, "<br>", TRUE);
-        } 
+        }
         elseif ($output_format == 'fasta_txt') {
            $seq = wordwrap($seq, $num_bases_per_line, "\n", TRUE);
         }
@@ -231,13 +231,13 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
            $residues .= "Includes " . $parent->downstream . " bases downstream.  ";
         }
         if (!$seq) {
-          $residues .= "No sequence available\n<br>";          
+          $residues .= "No sequence available\n<br>";
         }
         else {
           if ($output_format == 'fasta_html') {
             $residues .= "<br>";
           }
-          $residues .= "\n" . $seq . "\n";          
+          $residues .= "\n" . $seq . "\n";
           if ($output_format == 'fasta_html') {
             $residues .= "<br>";
           }
@@ -247,21 +247,21 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
     // if we are not getting the sequence from the parent sequence then
     // use what comes through from the feature record
     else {
-      $residues = $values->$field; 
+      $residues = $values->$field;
       if ($output_format == 'fasta_html') {
-         $residues = wordwrap($residues, $num_bases_per_line, "<br>", TRUE);  
-      } 
+         $residues = wordwrap($residues, $num_bases_per_line, "<br>", TRUE);
+      }
       elseif ($output_format == 'fasta_txt') {
-         $residues = wordwrap($residues, $num_bases_per_line, "\n", TRUE);  
+         $residues = wordwrap($residues, $num_bases_per_line, "\n", TRUE);
       }
     }
-    
+
     // format the residues for display
     if($residues and $num_bases_per_line){
       if ($output_format == 'fasta_html') {
          $residues = '<span style="font-family: monospace;">' . $residues . '</span>';
       }
     } */
-    return $residues;         
-  } 
+    return $residues;
+  }
 }

+ 5 - 3
tripal_views/views/handlers/tripal_views_handler_filter_select_cvterm.inc

@@ -36,7 +36,7 @@ class tripal_views_handler_filter_select_cvterm extends views_handler_filter_str
       else {
         //get a list of cvs currently used
         if ($this->view->base_table == 'cvterm') {
-          $sql = 'SELECT distinct(cv.cv_id) FROM {' . $this->view->base_table . '}' 
+          $sql = 'SELECT distinct(cv.cv_id) FROM {' . $this->view->base_table . '}'
             .' LEFT JOIN cv cv ON cv.cv_id=cvterm.cv_id';
         }
         else {
@@ -44,9 +44,10 @@ class tripal_views_handler_filter_select_cvterm extends views_handler_filter_str
             .' LEFT JOIN cvterm cvterm ON cvterm.cvterm_id=' . $this->view->base_table . '.type_id '
             .'LEFT JOIN cv cv ON cv.cv_id=cvterm.cv_id';
         }
+        // D7 TODO: Check DBTNG changes work
         $resource = chado_query($sql);
         $cvterms = array();
-        while ( $r = db_fetch_object($resource) ) {
+        foreach ($resource as $r) {
           $results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array('cv_id' => $r->cv_id));
           if (empty($results)) {
             $results = array();
@@ -60,10 +61,11 @@ class tripal_views_handler_filter_select_cvterm extends views_handler_filter_str
     }
     else {
       // @coder-ignore: non-drupal schema therefore table prefixing does not apply
+      // D7 TODO: Check DBTNG changes work
       $sql = "SELECT cvterm_id, name FROM {cvterm} WHERE cvterm_id IN (SELECT distinct(%s) FROM {%s})";
       $resource = chado_query($sql, $this->field, $this->table);
       $cvterms = array();
-      while ( $r = db_fetch_object($resource) ) {
+      foreach ($resource as $r) {
         $cvterms[$r->cvterm_id] = $r->name;
       }
     }

+ 2 - 1
tripal_views/views/handlers/tripal_views_handler_filter_select_string.inc

@@ -106,7 +106,8 @@ class tripal_views_handler_filter_select_string extends chado_views_handler_filt
         //$options['<select '.$this->table.'>'] = '--None--';
         $options['All'] = '--Any--';
       }
-      while ($r = db_fetch_object($results)) {
+      // D7 TODO: Check DBTNG changes work
+      foreach ($results as $r) {
         if (drupal_strlen($r->{$this->field}) > $max_length) {
           $options[$r->{$this->field}] = drupal_substr($r->{$this->field}, 0, $max_length) . '...';
         }

+ 2 - 1
tripal_views/views/handlers/views_handler_join_chado_aggregator.inc

@@ -205,8 +205,9 @@ class views_handler_join_chado_aggregator extends views_join {
               WHERE typname='nd_genotype_experiment'
                 AND attrelid=typrelid
                 AND attname NOT IN ('cmin','cmax','ctid','oid','tableoid','xmin','xmax')";
+      // D7 TODO: Check DBTNG changes work
       $resource = chado_query($sql);
-      while ($r = db_fetch_object($resource)) {
+      foreach ($resource as $r) {
         $table = $opt['table'];
         $alias = ''; //no alias needed if table is current table (only option if no schema api definition)
         $fname = $r->column;