From e439c3d3f5561e30b44ea479be292d90a1e011b5 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Wed, 6 Feb 2013 17:09:43 +0000 Subject: [PATCH] minor refactoring - #297 --- lib/utils/api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/utils/api.py b/lib/utils/api.py index 22b1629da..0f4a0903e 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -75,6 +75,9 @@ class Database(object): self.cursor.close() self.connection.close() + def commit(self): + self.cursor.commit() + def execute(self, statement, arguments=None): if arguments: self.cursor.execute(statement, arguments) @@ -186,6 +189,10 @@ class StdDbOut(object): output = conf.database_cursor.execute("SELECT id, value FROM data WHERE taskid = ? AND status = ? AND content_type = ? LIMIT 0,1", (self.taskid, status, content_type)) + # Delete partial output from IPC database if we have got a complete output + if status == CONTENT_STATUS.COMPLETE and len(output) > 0: + conf.database_cursor.execute("DELETE FROM data WHERE id=?", (output[0][0],)) + if status == CONTENT_STATUS.IN_PROGRESS: if len(output) == 0: conf.database_cursor.execute("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)", @@ -195,10 +202,6 @@ class StdDbOut(object): conf.database_cursor.execute("UPDATE data SET value = ? WHERE id = ?", (jsonize(new_value), output[0][0])) else: - if len(output) > 0: - conf.database_cursor.execute("DELETE FROM data WHERE taskid = ? AND status = %s AND content_type = ?" % CONTENT_STATUS.IN_PROGRESS, - (self.taskid, content_type)) - conf.database_cursor.execute("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)", (self.taskid, status, content_type, jsonize(value))) else: