]> git.decadent.org.uk Git - dak.git/blobdiff - dak/dakdb/update3.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update3.py
index c91ecf56eadba987c11339109ea371a71cfa65a4..1eab89f66e45e2147403268b0984d8e60bce5670 100755 (executable)
@@ -36,11 +36,19 @@ def do_update(self):
 
     try:
         c = self.db.cursor()
-        c.execute("DROP FUNCTION versioncmp(text, text);")
+        # The reason we try and check to see if it exists is that
+        # psycopg2 might leave the cursor invalid if the drop fails
+        c.execute("SELECT proname from pg_catalog.pg_proc WHERE proname = 'versioncmp'")
+        rows = c.fetchall()
+        if rows:
+            c.execute("DROP FUNCTION versioncmp(text, text);")
+        else:
+            print "function already does not exist"
+
         c.execute("UPDATE config SET value = '3' WHERE name = 'db_revision'")
 
         self.db.commit()
 
-    except psycopg2.ProgrammingError, msg:
+    except psycopg2.ProgrammingError as msg:
         self.db.rollback()
         raise DBUpdateError, "Unable to appy versioncmp removal, rollback issued. Error message : %s" % (str(msg))