[Biopython-dev] [Bug 2833] Features insertion on previous bioentry_id

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Tue Jun 2 15:54:23 UTC 2009


http://bugzilla.open-bio.org/show_bug.cgi?id=2833





------- Comment #18 from cymon.cox at gmail.com  2009-06-02 11:54 EST -------
(In reply to comment #17)
> How do you feel about this simplistic solution?: if the rules are present,
> before loading a new record, do a query to check to make sure there isn't a
> duplicate already present, and if there is raise an IntegrityError.

Now thats a much better solution than the way Ive been trying to go...

This does the trick:

diff --git a/BioSQL/BioSeqDatabase.py b/BioSQL/BioSeqDatabase.py
index 3f58e9c..a7a2470 100644
--- a/BioSQL/BioSeqDatabase.py
+++ b/BioSQL/BioSeqDatabase.py
@@ -330,6 +332,14 @@ class BioSeqDatabase:
         self.adaptor = adaptor
         self.name = name
         self.dbid = self.adaptor.fetch_dbid_by_dbname(name)
+
+        ##Test for presence of RULES in schema
+        self.postgres_rules_present= False
+        if "psycopg" in self.adaptor.conn.__class__.__module__:
+            sql = r"SELECT ev_class FROM pg_rewrite WHERE
rulename='rule_bioentry_i1'"
+            if self.adaptor.execute_and_fetchall(sql):
+                self.postgres_rules_present = True
+
     def __repr__(self):
         return "BioSeqDatabase(%r, %r)" % (self.adaptor, self.name)

@@ -439,5 +449,11 @@ class BioSeqDatabase:
         num_records = 0
         for cur_record in record_iterator :
             num_records += 1
+            if self.postgres_rules_present:
+                self.adaptor.execute("SELECT bioentry_id FROM bioentry "
+                                     "WHERE identifier = '%s'" %
cur_record.id)
+                if self.adaptor.cursor.fetchone():
+                    raise self.adaptor.conn.IntegrityError("Duplicate record " 
+                        "detected: record has not been inserted")
             db_loader.load_seqrecord(cur_record)
         return num_records

C.


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list