git://git.onelab.eu
/
sfa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f9763b9
)
handle any exception raised by PostgreSQL.cursor()
author
Tony Mack
<tmack@cs.princeton.edu>
Thu, 4 Mar 2010 16:45:49 +0000
(16:45 +0000)
committer
Tony Mack
<tmack@cs.princeton.edu>
Thu, 4 Mar 2010 16:45:49 +0000
(16:45 +0000)
sfa/util/PostgreSQL.py
patch
|
blob
|
history
diff --git
a/sfa/util/PostgreSQL.py
b/sfa/util/PostgreSQL.py
index
34334de
..
984e514
100644
(file)
--- a/
sfa/util/PostgreSQL.py
+++ b/
sfa/util/PostgreSQL.py
@@
-44,6
+44,13
@@
if not psycopg2:
pgdb.pgdbTypeCache.typecast = unicast(pgdb.pgdbTypeCache.typecast)
pgdb.pgdbTypeCache.typecast = unicast(pgdb.pgdbTypeCache.typecast)
+def handle_exception(f):
+ def wrapper(*args, **kwds):
+ try: return f(*args, **kwds)
+ except Exception, fault:
+ raise SfaDBError(str(fault))
+ return wrapper
+
class PostgreSQL:
def __init__(self, config):
self.config = config
class PostgreSQL:
def __init__(self, config):
self.config = config
@@
-51,6
+58,7
@@
class PostgreSQL:
# self.debug = True
self.connection = None
# self.debug = True
self.connection = None
+ @handle_exception
def cursor(self):
if self.connection is None:
# (Re)initialize database connection
def cursor(self):
if self.connection is None:
# (Re)initialize database connection
@@
-132,13
+140,12
@@
class PostgreSQL:
return self.rowcount
def next_id(self, table_name, primary_key):
return self.rowcount
def next_id(self, table_name, primary_key):
- sequence = "%(table_name)s_%(primary_key)s_seq" % locals()
- sql = "SELECT nextval('%(sequence)s')" % locals()
- rows = self.selectall(sql, hashref = False)
- if rows:
- return rows[0][0]
-
- return None
+ sequence = "%(table_name)s_%(primary_key)s_seq" % locals()
+ sql = "SELECT nextval('%(sequence)s')" % locals()
+ rows = self.selectall(sql, hashref = False)
+ if rows:
+ return rows[0][0]
+ return None
def last_insert_id(self, table_name, primary_key):
if isinstance(self.lastrowid, int):
def last_insert_id(self, table_name, primary_key):
if isinstance(self.lastrowid, int):
@@
-202,7
+209,7
@@
class PostgreSQL:
print >> log, query
print >> log, "Params:"
print >> log, pformat(params)
print >> log, query
print >> log, "Params:"
print >> log, pformat(params)
- raise SfaDBError("Please contact support: %s" %
e
)
+ raise SfaDBError("Please contact support: %s" %
str(e)
)
return cursor
return cursor