* tried to put some sense in the way things get logged, at least on server-side for now
[sfa.git] / sfa / util / table.py
index 5e9277b..c0d7d4f 100644 (file)
@@ -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()