comparison DBInterface.py @ 8:17b19345d011

added autocommit option.
author casties
date Thu, 17 Feb 2011 19:25:16 +0100
parents 1b25a85a2165
children 22c16a632909
comparison
equal deleted inserted replaced
7:917e28a08c58 8:17b19345d011
68 68
69 69
70 class DBInterface: 70 class DBInterface:
71 """Object for database queries""" 71 """Object for database queries"""
72 72
73 def __init__(self, connection_id=None): 73 def __init__(self, connection_id=None, autocommit=False):
74 """init""" 74 """init"""
75 # database connection id 75 # database connection id
76 self.connection_id = connection_id 76 self.connection_id = connection_id
77 self.autocommit = autocommit
77 78
78 def getConnectionIDs(self): 79 def getConnectionIDs(self):
79 """return list of available connection ids""" 80 """return list of available connection ids"""
80 return SQLConnectionIDs(self) 81 return SQLConnectionIDs(self)
81 82
92 93
93 # get Connection instance 94 # get Connection instance
94 con = getattr(self, self.connection_id) 95 con = getattr(self, self.connection_id)
95 # call to get db object 96 # call to get db object
96 db = con() 97 db = con()
98 if self.autocommit:
99 # force our transaction isolation level
100 db.tilevel = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT
101
97 return db 102 return db
98 103
99 def executeZSQL(self, query, args=None, max_rows=None): 104 def executeZSQL(self, query, args=None, max_rows=None):
100 """execute query with args on the database and return all results as Result object.""" 105 """execute query with args on the database and return all results as Result object."""
101 logging.debug("executeZSQL query=%s args=%s"%(query,args)) 106 logging.debug("executeZSQL query=%s args=%s"%(query,args))