From ed239668c0e19d228017f5c421faf4d4291ebae0 Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sat, 31 Jul 2010 23:55:05 +0200 Subject: [PATCH] fix pgsql index and foreign key drops --- pyfpdb/Database.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 500dfb0a..2aea6790 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -951,6 +951,7 @@ class Database: # hmmm, tested by commenting out rollback in grapher. lock seems to work but # then drop still hangs :-( does work in some tests though?? # will leave code here for now pending further tests/enhancement ... + c.execute("BEGIN TRANSACTION") c.execute( "lock table %s in exclusive mode nowait" % (fk['fktab'],) ) #print "after lock, status:", c.statusmessage #print "alter table %s drop constraint %s_%s_fkey" % (fk['fktab'], fk['fktab'], fk['fkcol']) @@ -961,6 +962,7 @@ class Database: if "does not exist" not in str(sys.exc_value): print "warning: drop pg fk %s_%s_fkey failed: %s, continuing ..." \ % (fk['fktab'], fk['fkcol'], str(sys.exc_value).rstrip('\n') ) + c.execute("END TRANSACTION") except: print "warning: constraint %s_%s_fkey not dropped: %s, continuing ..." \ % (fk['fktab'],fk['fkcol'], str(sys.exc_value).rstrip('\n')) @@ -984,6 +986,7 @@ class Database: print "dropping pg index ", idx['tab'], idx['col'] try: # try to lock table to see if index drop will work: + c.execute("BEGIN TRANSACTION") c.execute( "lock table %s in exclusive mode nowait" % (idx['tab'],) ) #print "after lock, status:", c.statusmessage try: @@ -995,6 +998,7 @@ class Database: if "does not exist" not in str(sys.exc_value): print "warning: drop index %s_%s_idx failed: %s, continuing ..." \ % (idx['tab'],idx['col'], str(sys.exc_value).rstrip('\n')) + c.execute("END TRANSACTION") except: print "warning: index %s_%s_idx not dropped %s, continuing ..." \ % (idx['tab'],idx['col'], str(sys.exc_value).rstrip('\n'))