X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Ftable.py;h=c0d7d4f4cbb1d7eb2c95861b6d95519cf99f638c;hb=0cf0d31c313a366e3f272f830bdb4f2a7308e11f;hp=5e9277b056102c6bd75010694071432875d473f6;hpb=b86b5211e66e49680f413304152b41e04d5f271a;p=sfa.git diff --git a/sfa/util/table.py b/sfa/util/table.py index 5e9277b0..c0d7d4f4 100644 --- a/sfa/util/table.py +++ b/sfa/util/table.py @@ -11,7 +11,6 @@ import pgdb from sfa.util.PostgreSQL import * from sfa.trust.gid import * from sfa.util.record import * -from sfa.util.debug import * from sfa.util.config import * from sfa.util.filter import * @@ -28,7 +27,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 +83,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) @@ -127,19 +130,10 @@ class SfaTable(list): self.db.commit() def quote_string(self, value): - return str(self.quote(value)) + return str(self.db.quote(value)) def quote(self, value): - """ - Returns quoted version of the specified value. - """ - - # The pgdb._quote function is good enough for general SQL - # quoting, except for array types. - if isinstance(value, (list, tuple, set)): - return "ARRAY[%s]" % ", ".join(map, self.quote_string, value) - else: - return pgdb._quote(value) + return self.db.quote(value) def find(self, record_filter = None, columns=None): if not columns: @@ -189,11 +183,13 @@ 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 - def sfa_records_purge(): + def sfa_records_purge(self): self.drop()