From 985c940dcf7236d1286483581db338366e2f6d76 Mon Sep 17 00:00:00 2001
From: Glenn Proctor <gp1@sanger.ac.uk>
Date: Mon, 31 Oct 2005 12:59:53 +0000
Subject: [PATCH] Modify update() method to create a row in
 analysis_description if the analysis exists but doesn't have a description.
 If there is already a description, it gets updated.

---
 modules/Bio/EnsEMBL/DBSQL/AnalysisAdaptor.pm | 27 ++++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/modules/Bio/EnsEMBL/DBSQL/AnalysisAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/AnalysisAdaptor.pm
index bf321c6b79..ef0801359c 100755
--- a/modules/Bio/EnsEMBL/DBSQL/AnalysisAdaptor.pm
+++ b/modules/Bio/EnsEMBL/DBSQL/AnalysisAdaptor.pm
@@ -490,13 +490,30 @@ sub update {
 
   $sth->finish();
 
-  # also update description & display label
-  $sth = $self->prepare
-    ("UPDATE analysis_description SET description = ?, display_label = ? WHERE analysis_id = ?");
+  # also update description & display label - may need to create these if
+  # not already there
+  $sth = $self->prepare("SELECT description FROM analysis_description WHERE analysis_id= ?");
+  $sth->execute($a->dbID);
 
-  $sth->execute($a->description(), $a->display_label(), $a->dbID);
+  if ($sth->fetchrow_hashref) { # update if exists
 
-  $sth->finish();
+    $sth = $self->prepare
+      ("UPDATE analysis_description SET description = ?, display_label = ? WHERE analysis_id = ?");
+
+    $sth->execute($a->description(), $a->display_label(), $a->dbID);
+
+  } else { # create new entry
+
+    if( $a->description() || $a->display_label()) {
+      $sth = $self->prepare( "INSERT IGNORE INTO analysis_description (analysis_id, display_label, description) VALUES (?,?,?)");
+      $sth->execute( $a->dbID(), $a->display_label(), $a->description() );
+      $sth->finish();
+    }
+
+  }
+
+
+    $sth->finish();
 
   # the logic_name cache needs to be re-updated now, since we may have just
   # changed the logic_name
-- 
GitLab