- fix can_update and return value
[plcapi.git] / PLC / PostgreSQL.py
index 5ca0caa..534a27a 100644 (file)
@@ -5,7 +5,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: PostgreSQL.py,v 1.3 2006/10/03 19:27:07 mlhuang Exp $
+# $Id: PostgreSQL.py,v 1.6 2006/10/20 17:53:42 mlhuang Exp $
 #
 
 import pgdb
@@ -25,7 +25,7 @@ class PostgreSQL:
         self.db = pgdb.connect(user = api.config.PLC_DB_USER,
                                password = api.config.PLC_DB_PASSWORD,
                                host = "%s:%d" % (api.config.PLC_DB_HOST, api.config.PLC_DB_PORT),
-                               database = api.config.PLC_DB_NAME)
+                               database = "planetlab4") # XXX api.config.PLC_DB_NAME)
         self.cursor = self.db.cursor()
 
         (self.rowcount, self.description, self.lastrowid) = \
@@ -39,7 +39,7 @@ class PostgreSQL:
         # pgdb._quote functions are good enough for general SQL quoting
         if hasattr(params, 'has_key'):
             params = pgdb._quoteitem(params)
-        elif isinstance(params, list) or isinstance(params, tuple):
+        elif isinstance(params, list) or isinstance(params, tuple) or isinstance(params, set):
             params = map(pgdb._quote, params)
         else:
             params = pgdb._quote(params)
@@ -100,8 +100,10 @@ class PostgreSQL:
             (self.rowcount, self.description, self.lastrowid) = \
                             (cursor.rowcount, cursor.description, cursor.lastrowid)
         except pgdb.DatabaseError, e:
-            cursor.close()
-            self.rollback()
+            try:
+                self.rollback()
+            except:
+                pass
             uuid = commands.getoutput("uuidgen")
             print >> log, "Database error %s:" % uuid
             print >> log, e