From b242587871366d057ed8aa65356be7116dbb71e2 Mon Sep 17 00:00:00 2001 From: Triatmoko Date: Tue, 1 Nov 2011 14:58:20 +0100 Subject: all ping added --- For Weekly Test/tricode/DbClass.py | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'For Weekly Test/tricode/DbClass.py') diff --git a/For Weekly Test/tricode/DbClass.py b/For Weekly Test/tricode/DbClass.py index 027bc95..99c1e7c 100755 --- a/For Weekly Test/tricode/DbClass.py +++ b/For Weekly Test/tricode/DbClass.py @@ -298,6 +298,54 @@ class DBMySQLConnection: return 3 else: return 0 + def maxTaskNo(self): + if self.connectionCreated == 1: + try: + self.cur.execute("SELECT MAX(taskNo) FROM TaskTable") + self.taskNo = self.cur.fetchone() + if self.taskNo == None or self.taskNo == '0' or self.taskNo == '' or self.taskNo == 0: + self.taskNo = 1 + else: + self.taskNo = self.taskNo +1 + return self.taskNo + + except MySQLdb.Error, e: + error = str(e) + message = 'error' + if debugMode == 1: + print str(e) + if error[1:5] == '1062': + return message #duplicate entry for the key + + return message + else: + return 0 + + def insertTask(self, fromDevice, toDevice): + if self.connectionCreated == 1: + try: + + self.maxTaskNo() + #I used here a transaction since I want the mysql to execute a few commands and tell me was it successful rather than to execute some and there happens a mistake and one part is updated and the other isn't + newQuery = "START TRANSACTION; INSERT INTO `TaskTable` (`taskNo`, `from`, `to`) VALUES ('" + str(self.taskNo) + "', '" + str(fromDevice) + "', '" + str(toDevice) +"'); SELECT @taskID := LAST_INSERT_ID(); INSERT INTO `TempTaskTable` (`taskID`, `taskNo`, `from`, `to`) VALUES (@taskID, '" + str(taskNo) + "', '" + str(fromDevice) + "', '"+ str(toDevice) + "'); COMMIT;" + + successful = self.cur.execute(newQuery) + output = self.cur.fetchone() + + return 1 + + if debugMode == 1: + print output + + except MySQLdb.Error, e: + error = str(e) + if debugMode == 1: + print str(e) + if error[1:5] == '1062': + return 2 #duplicate entry for the key + return 3 + else: + return 0 def releaseMutex(self): if self.connectionCreated == 1: -- cgit v1.2.3-55-g7522