summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/tricode/DbClass.py
diff options
context:
space:
mode:
authorTriatmoko2011-11-01 14:58:20 +0100
committerTriatmoko2011-11-01 14:58:20 +0100
commitb242587871366d057ed8aa65356be7116dbb71e2 (patch)
treeec585c1a700fde734537fe22d9525531bfc2539c /For Weekly Test/tricode/DbClass.py
parentReport change (diff)
downloadgsm-selftest-b242587871366d057ed8aa65356be7116dbb71e2.tar.gz
gsm-selftest-b242587871366d057ed8aa65356be7116dbb71e2.tar.xz
gsm-selftest-b242587871366d057ed8aa65356be7116dbb71e2.zip
all ping added
Diffstat (limited to 'For Weekly Test/tricode/DbClass.py')
-rwxr-xr-xFor Weekly Test/tricode/DbClass.py48
1 files changed, 48 insertions, 0 deletions
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: