# HG changeset patch # User casties # Date 1297967116 -3600 # Node ID 17b19345d011d66b4db0fb6392600347da492d10 # Parent 917e28a08c58c2f52bbf0a622f01daa3bd39da9f added autocommit option. diff -r 917e28a08c58 -r 17b19345d011 DBInterface.py --- a/DBInterface.py Tue Feb 15 21:14:03 2011 +0100 +++ b/DBInterface.py Thu Feb 17 19:25:16 2011 +0100 @@ -70,10 +70,11 @@ class DBInterface: """Object for database queries""" - def __init__(self, connection_id=None): + def __init__(self, connection_id=None, autocommit=False): """init""" # database connection id - self.connection_id = connection_id + self.connection_id = connection_id + self.autocommit = autocommit def getConnectionIDs(self): """return list of available connection ids""" @@ -94,6 +95,10 @@ con = getattr(self, self.connection_id) # call to get db object db = con() + if self.autocommit: + # force our transaction isolation level + db.tilevel = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT + return db def executeZSQL(self, query, args=None, max_rows=None): diff -r 917e28a08c58 -r 17b19345d011 ZDBInterfaceFolder.py --- a/ZDBInterfaceFolder.py Tue Feb 15 21:14:03 2011 +0100 +++ b/ZDBInterfaceFolder.py Thu Feb 17 19:25:16 2011 +0100 @@ -26,13 +26,13 @@ manage_editZDBInterfaceFolderForm=PageTemplateFile('zpt/editZDBInterfaceFolder',globals()) - def __init__(self, id, title, connection_id=None): + def __init__(self, id, title, connection_id=None, autocommit=False): """init""" self.id = id self.title = title # database connection id self.connection_id = connection_id - + self.autocommit = autocommit def getSQLQuery(self, table, argv): """returns dict with SQL query string and args""" @@ -42,7 +42,8 @@ order = None wheres = [] whereOp = "AND" - done = {} + processed = {} + unprocessed = {} limit = None offset = None @@ -95,7 +96,7 @@ # evaluate argv for (key, val) in argv.items(): - if key in done: + if key in processed: # parameter has been processed continue @@ -124,17 +125,19 @@ logging.debug("param=%s key=%s val=%s"%(param,key,val)) if param in argv: doOp(val, param, argv[param]) - done[param] = True + processed[param] = True else: # no corresponding parameter logging.error("getSQLquery: param=%s for op not found!"%param) + else: + # parameter=value pair + unprocessed[key] = val # process remaining parameters (without _op) - for (key, val) in argv.items(): - if key not in done and key[0] not in ("_", "-"): - param = sqlName(key) - # default is begins-with - doOp("bw", param, val) + for (key, val) in unprocessed.items(): + param = sqlName(key) + # default is begins-with + doOp("bw", param, val) # join it all query = "SELECT %s FROM %s"%(select, table) @@ -158,15 +161,18 @@ result = self.executeZSQL(query['query'], query['args']) return result - def manage_editZDBInterfaceFolder(self, title=None, connection_id=None, + def manage_editZDBInterfaceFolder(self, title=None, connection_id=None, autocommit=None, REQUEST=None): """Change the object""" + logging.debug("editZDBInterfaceFolder title=%s, connection_id=%s, autocommit=%s"%(title,connection_id,autocommit)) if title is not None: self.title = title if connection_id is not None: self.connection_id = connection_id + self.autocommit = (autocommit == "on") + #checkPermission=getSecurityManager().checkPermission REQUEST.RESPONSE.redirect('manage_main') diff -r 917e28a08c58 -r 17b19345d011 zpt/editRestDbInterface.zpt --- a/zpt/editRestDbInterface.zpt Tue Feb 15 21:14:03 2011 +0100 +++ b/zpt/editRestDbInterface.zpt Thu Feb 17 19:25:16 2011 +0100 @@ -6,11 +6,15 @@

Connection ID

+

Autocommit

+

+ autocommit (don't use when you want transactions) +

diff -r 917e28a08c58 -r 17b19345d011 zpt/editZDBInterfaceFolder.zpt --- a/zpt/editZDBInterfaceFolder.zpt Tue Feb 15 21:14:03 2011 +0100 +++ b/zpt/editZDBInterfaceFolder.zpt Thu Feb 17 19:25:16 2011 +0100 @@ -4,14 +4,17 @@

Title

Connection ID

-
     

+

Autocommit

+

+ autocommit (don't use when you want transactions) +