From ff7af9232a102ac4b9071dbbc1fddea9d9cdbcb8 Mon Sep 17 00:00:00 2001 From: gsmselftest Date: Wed, 2 Nov 2011 16:27:02 +0100 Subject: fix the bug --- For Weekly Test/tricode/DbClass.py | 52 ++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) (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 8733ec9..cc3a083 100755 --- a/For Weekly Test/tricode/DbClass.py +++ b/For Weekly Test/tricode/DbClass.py @@ -323,14 +323,32 @@ class DBMySQLConnection: else: return 0 - def insertTask(self, fromDevice, toDevice): + def maxTaskID(self): if self.connectionCreated == 1: try: + succ = self.cur.execute("SELECT max(taskID) FROM TaskTable") + taskID = self.cur.fetchone() + self.taskID = taskID[0] + if self.taskID == None or self.taskID == '0' or self.taskID == '' or self.taskID == 0: + self.taskID = 1 + return self.taskID + + 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 - 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;" + return message + else: + return 0 + def insertTask(self, taskNo, fromDevice, toDevice): + if self.connectionCreated == 1: + try: + newQuery = ("INSERT INTO `TaskTable` (`taskNo`,`from`,`to`) VALUES ('"+str(taskNo)+"','" +str(fromDevice)+ "', '"+str(toDevice)+"')") successful = self.cur.execute(newQuery) output = self.cur.fetchone() @@ -348,7 +366,30 @@ class DBMySQLConnection: return 3 else: return 0 - + def insertTaskIn2(self, fromDevice, toDevice, taskNo): + if self.connectionCreated == 1: + try: + #we 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(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() + while self.cur.nextset() is not None: pass + + 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: try: @@ -394,3 +435,4 @@ class DBMySQLConnection: else: return 0 + -- cgit v1.2.3-55-g7522