X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Ftable.py;h=6c68776d7cc6bbaaed74fc43ccb3c9e9adfd7ee4;hb=952322d76247f8991f3c2688ed7e1f5a22ca4572;hp=bccda20dcded85a53912e88c339221bfdb3ca305;hpb=c0f8a6b783387a8dfef0cec6f80a4539b175683d;p=sfa.git diff --git a/sfa/util/table.py b/sfa/util/table.py index bccda20d..6c68776d 100644 --- a/sfa/util/table.py +++ b/sfa/util/table.py @@ -28,7 +28,7 @@ class SfaTable(list): if record_filter: records = self.find(record_filter) - for record in reocrds: + for record in records: self.append(record) def exists(self): @@ -84,18 +84,22 @@ class SfaTable(list): self.db.do(querystr) for index in indexes: self.db.do(index) - + + self.db.commit() + def remove(self, record): - query_str = "DELETE FROM %s WHERE record_id = %s" % \ - (self.tablename, record['record_id']) - self.db.do(query_str) + params = {'record_id': record['record_id']} + template = "DELETE FROM %s " % self.tablename + sql = template + "WHERE record_id = %(record_id)s" + self.db.do(sql, params) # if this is a site, remove all records where 'authority' == the # site's hrn - if record['type'] == 'site': - sql = " DELETE FROM %s WHERE authority = %s" % \ - (self.tablename, record['hrn']) - self.db.do(sql) + if record['type'] == 'authority': + params = {'authority': record['hrn']} + sql = template + "WHERE authority = %(authority)s" + self.db.do(sql, params) + self.db.commit() def insert(self, record): db_fields = self.db_fields(record) @@ -180,9 +184,11 @@ class SfaTable(list): def drop(self): try: self.db.do('DROP TABLE IF EXISTS ' + self.tablename) + self.db.commit() except: try: self.db.do('DROP TABLE ' + self.tablename) + self.db.commit() except: pass