summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/tricode/DbClass.py
diff options
context:
space:
mode:
authorgsmselftest2011-11-02 16:27:02 +0100
committergsmselftest2011-11-02 16:27:02 +0100
commitff7af9232a102ac4b9071dbbc1fddea9d9cdbcb8 (patch)
tree3036f69fe6728e86db0aeeb4ad034d5d38fd74b2 /For Weekly Test/tricode/DbClass.py
parentBackup of server handlers with the new self-rebooting code (diff)
downloadgsm-selftest-ff7af9232a102ac4b9071dbbc1fddea9d9cdbcb8.tar.gz
gsm-selftest-ff7af9232a102ac4b9071dbbc1fddea9d9cdbcb8.tar.xz
gsm-selftest-ff7af9232a102ac4b9071dbbc1fddea9d9cdbcb8.zip
fix the bug
Diffstat (limited to 'For Weekly Test/tricode/DbClass.py')
-rwxr-xr-xFor Weekly Test/tricode/DbClass.py52
1 files changed, 47 insertions, 5 deletions
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
+