summaryrefslogtreecommitdiffstats
path: root/For Weekly Test
diff options
context:
space:
mode:
authorMac-Linux2011-07-26 14:05:10 +0200
committerMac-Linux2011-07-26 14:05:10 +0200
commit43d5f3c6a3245525202846cd0dd025c6a5a8bf3c (patch)
treed46be2cb37b19ebad8dc35b8f3e55a20a4bc41f8 /For Weekly Test
parentdont know what kind of change. (diff)
parentfor refik (diff)
downloadgsm-selftest-43d5f3c6a3245525202846cd0dd025c6a5a8bf3c.tar.gz
gsm-selftest-43d5f3c6a3245525202846cd0dd025c6a5a8bf3c.tar.xz
gsm-selftest-43d5f3c6a3245525202846cd0dd025c6a5a8bf3c.zip
Merge branch 'master' of lab.ks.uni-freiburg.de:lsfks/projekte/gsm-selftest
Conflicts: For Weekly Test/30-07-2011/DbClass.py
Diffstat (limited to 'For Weekly Test')
-rw-r--r--For Weekly Test/30-07-2011/ClientClass.pycbin3637 -> 3601 bytes
-rw-r--r--For Weekly Test/30-07-2011/ControllerClass.pycbin5839 -> 5799 bytes
-rw-r--r--For Weekly Test/30-07-2011/DbClass.py30
-rw-r--r--For Weekly Test/30-07-2011/DbClass.pycbin7660 -> 7029 bytes
-rw-r--r--For Weekly Test/30-07-2011/LogFileClass.pycbin1514 -> 1494 bytes
-rw-r--r--For Weekly Test/30-07-2011/PingClass.pycbin1267 -> 1251 bytes
-rw-r--r--For Weekly Test/30-07-2011/classCheck.pycbin1093 -> 1081 bytes
-rw-r--r--For Weekly Test/30-07-2011/dbClass.py271
-rw-r--r--For Weekly Test/30-07-2011/dbClass.pycbin0 -> 7453 bytes
-rw-r--r--For Weekly Test/30-07-2011/test3.py14
-rw-r--r--For Weekly Test/30-07-2011/test4.py26
-rw-r--r--For Weekly Test/30-07-2011/test5.py6
-rw-r--r--For Weekly Test/30-07-2011/test6.py35
-rw-r--r--For Weekly Test/DBProblem/DbClass.py252
-rw-r--r--For Weekly Test/DBProblem/test3.py31
15 files changed, 636 insertions, 29 deletions
diff --git a/For Weekly Test/30-07-2011/ClientClass.pyc b/For Weekly Test/30-07-2011/ClientClass.pyc
index 99656f8..7cdfa60 100644
--- a/For Weekly Test/30-07-2011/ClientClass.pyc
+++ b/For Weekly Test/30-07-2011/ClientClass.pyc
Binary files differ
diff --git a/For Weekly Test/30-07-2011/ControllerClass.pyc b/For Weekly Test/30-07-2011/ControllerClass.pyc
index 234bf41..855e630 100644
--- a/For Weekly Test/30-07-2011/ControllerClass.pyc
+++ b/For Weekly Test/30-07-2011/ControllerClass.pyc
Binary files differ
diff --git a/For Weekly Test/30-07-2011/DbClass.py b/For Weekly Test/30-07-2011/DbClass.py
index 03d2039..929efa5 100644
--- a/For Weekly Test/30-07-2011/DbClass.py
+++ b/For Weekly Test/30-07-2011/DbClass.py
@@ -63,11 +63,7 @@ class DBMySQLConnection:
#parse the output from the mysql by creating a list
#with lists where each attribue(column) gets independent
#element of the list
- for record in output:
- columns = list()
- for entry in record:
- columns.append(str(entry))
- self.tasksList.append(columns)
+ self.tasksList = output
return 1
except MySQLdb.Error, e:
error = str(e)
@@ -172,10 +168,11 @@ class DBMySQLConnection:
try:
successful = self.cur.execute("DELETE FROM TempTaskTable WHERE taskID=%i"%(int(taskID)))
output = self.cur.fetchone()
-
+
if debugMode == 1:
print output
+<<<<<<< HEAD
wasInIF = 0
def removeItem(item):
@@ -191,14 +188,16 @@ class DBMySQLConnection:
return 1 #deleted it
if wasInIF == 0:
+=======
+ if successful == 1:
+ return 1 #deleted it
+ else:
+>>>>>>> 0727c4e120c701b6fd66bd267afecdfe7d6f2722
return 4 #that taskID didn't exist or something else
except MySQLdb.Error, e:
if debugMode == 1:
print str(e)
return 3
-
- else:
- return 0
def addResult(self, taskID, result):
if self.connectionCreated == 1:
@@ -240,19 +239,6 @@ class DBMySQLConnection:
while self.cur.nextset() is not None: pass
- newQuery1 = 'SELECT taskID FROM `TempTaskTable` ORDER BY taskID DESC LIMIT 1';
- successful1 = self.cur.execute(newQuery1)
- record = self.cur.fetchone()
-
- columns = list()
- for entry in record:
- columns.append(str(entry))
-
- columns.append(str(taskNo))
- columns.append(str(fromDevice))
- columns.append(str(toDevice))
- self.tasksList.append(columns)
-
return 1
if debugMode == 1:
diff --git a/For Weekly Test/30-07-2011/DbClass.pyc b/For Weekly Test/30-07-2011/DbClass.pyc
index 9b827be..2b125c7 100644
--- a/For Weekly Test/30-07-2011/DbClass.pyc
+++ b/For Weekly Test/30-07-2011/DbClass.pyc
Binary files differ
diff --git a/For Weekly Test/30-07-2011/LogFileClass.pyc b/For Weekly Test/30-07-2011/LogFileClass.pyc
index 6c2ecdc..52fd946 100644
--- a/For Weekly Test/30-07-2011/LogFileClass.pyc
+++ b/For Weekly Test/30-07-2011/LogFileClass.pyc
Binary files differ
diff --git a/For Weekly Test/30-07-2011/PingClass.pyc b/For Weekly Test/30-07-2011/PingClass.pyc
index 2252892..9ac5c4b 100644
--- a/For Weekly Test/30-07-2011/PingClass.pyc
+++ b/For Weekly Test/30-07-2011/PingClass.pyc
Binary files differ
diff --git a/For Weekly Test/30-07-2011/classCheck.pyc b/For Weekly Test/30-07-2011/classCheck.pyc
index 2d0e213..d36941a 100644
--- a/For Weekly Test/30-07-2011/classCheck.pyc
+++ b/For Weekly Test/30-07-2011/classCheck.pyc
Binary files differ
diff --git a/For Weekly Test/30-07-2011/dbClass.py b/For Weekly Test/30-07-2011/dbClass.py
new file mode 100644
index 0000000..dc7ca41
--- /dev/null
+++ b/For Weekly Test/30-07-2011/dbClass.py
@@ -0,0 +1,271 @@
+import MySQLdb
+import string
+
+class DBMySQLConnection:
+ def __init__(self, username, password, host, dbname):
+ #initialize at the start all the user parameters
+ self.usern = username
+ self.passw = password
+ self.host = host
+ self.db = dbname
+ self.connectionCreated = 0
+ self.tasksList = list()
+ global debugMode
+ debugMode = 0
+
+ def connectDB(self):
+ try:
+ #try the connection
+ self.datBaseConn=MySQLdb.connect(self.host,self.usern, self.passw,self.db)
+ self.datBaseConn.paramstyle = 'format'
+ self.cur = self.datBaseConn.cursor() #make the cursor, used for sending queries
+ self.connectionCreated = 1 #use it as an indicator that the connection was created
+ return 1
+
+ except MySQLdb.Error, e:
+ #if we have an error then try to catch it
+ error=str(e)
+ if error[1:5] == '1045':
+ #wrong username or password
+ return 0
+ elif error[1:5] == '2002':
+ #can't connect to mysql, mysql shutdown or wrong host
+ return 2
+ else:
+ if debugMode == 1:
+ print error
+ return 3
+
+ def closeDBConn(self):
+ #close the connection to the database here
+ if self.connectionCreated == 1:
+ try:
+ #close the cursor and then the connection to the DB
+ self.cur.close()
+ self.datBaseConn.close()
+ return 1
+ except MySQLdb.Error, e:
+ #in case of an error
+ if debugMode == 1:
+ error = str(e)
+ print error
+ return 3
+ else:
+ #I never really had a connection
+ return 0
+
+ def anyTasksToDo(self):
+ #see are there any jobs to be executed and make a list out of it
+ if self.connectionCreated == 1:
+ try:
+ self.cur.execute("SELECT * FROM TempTaskTable")
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ for record in output:
+ columns = list()
+ for entry in record:
+ columns.append(str(entry))
+ self.tasksList.append(columns)
+ return 1
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def cleanTasksList(self):
+ if self.connectionCreated == 1:
+ del self.tasksList[:]
+ return 1
+ else:
+ return 0
+
+ def removeTaskFromList(self, taskID):
+ #remove only one task from the task list
+ if self.connectionCreated == 1:
+ for index in range(len(self.tasksList)):
+ item = self.tasksList[index]
+ if item[0] == str(taskID):
+ #self.tasksList.remove(index)
+ #print 'found it'
+ del self.tasksList[index]
+ return 1 #deleted taskID
+
+ return 2 #didn't find that taskID
+ else:
+ return 0
+
+ def deviceAddress(self,deviceName):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("SELECT `deviceIP` FROM DeviceAddress where `deviceName`=%s", deviceName)
+ #self.cur.execute()
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ deviceAddr = ''
+ for record in output:
+ columns = list()
+ for entry in record:
+ deviceAddr = str(entry)
+ return deviceAddr
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3 #some error happened
+ else:
+ return 0 #I am not connected
+
+ def updateTaskResult(self, taskID, status):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE TaskTable SET status=%i WHERE taskID=%i"%(int(status), int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #update successful
+ else:
+ return 4 #taskID doesn't exist
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def updatePingResult(self, taskNo, sipServer, sipGate, sipLoc, gsmBox1, gsmBox2):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE PingResultTable SET sipServer=%i, sipGate=%i, sipLoc=%i, gsmBox1=%i, gsmBox2=%i WHERE taskNo=%i"%(int(sipServer), int(sipGate), int(sipLoc), int(gsmBox1), int(gsmBox2), int(taskNo)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #ping table updated
+ else:
+ return 4 #the taskNo didn't exist
+
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def deleteTempTask(self, taskID):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("DELETE FROM TempTaskTable WHERE taskID=%i"%(int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+
+ if successful == 1:
+ return 1 #deleted it
+ else:
+ return 4 #that taskID didn't exist or something else
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+
+ else:
+ return 0
+
+ def addResult(self, taskID, result):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("INSERT INTO ResultTable(taskID, result) VALUES ('%i', '%i')"%(int(taskID), int(result)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 1:
+ return 1 #successfully added the result
+ else:
+ return 4 #hmmm
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1062':
+ return 2 #duplicate entry for the key
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+
+ def insertTaskIn2(self, fromDevice, toDevice, taskNo):
+ if self.connectionCreated == 1:
+ try:
+ #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`, `status`) VALUES ('" + str(taskNo) + "', '" + str(fromDevice) + "', '" + str(toDevice) +"', '0'); 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()
+
+
+ #without closing the cursos we get a MySQL error, the mistake is an internal mistak of the MySQLdb python library
+ # self.cur.close()
+ # self.cur = self.datBaseConn.cursor()
+
+ while self.cur.nextset() is not None: pass
+
+ newQuery1 = 'SELECT taskID FROM `TempTaskTable` ORDER BY taskID DESC LIMIT 1';
+ successful1 = self.cur.execute(newQuery1)
+ record = self.cur.fetchone()
+
+ columns = list()
+ for entry in record:
+ columns.append(str(entry))
+
+ columns.append(str(taskNo))
+ columns.append(str(fromDevice))
+ columns.append(str(toDevice))
+ self.tasksList.append(columns)
+
+ 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 searchTaskList(self, fromDevice, toDevice):
+ if self.connectionCreated == 1:
+ for item in self.tasksList:
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item [3]
+ if callFrom == fromDevice and callTo == toDevice:
+ return 1 #that task was found
+ return 2 #that task wasn't found
+ else:
+ return 0
diff --git a/For Weekly Test/30-07-2011/dbClass.pyc b/For Weekly Test/30-07-2011/dbClass.pyc
new file mode 100644
index 0000000..d51d30e
--- /dev/null
+++ b/For Weekly Test/30-07-2011/dbClass.pyc
Binary files differ
diff --git a/For Weekly Test/30-07-2011/test3.py b/For Weekly Test/30-07-2011/test3.py
index 85b67c0..bd759ca 100644
--- a/For Weekly Test/30-07-2011/test3.py
+++ b/For Weekly Test/30-07-2011/test3.py
@@ -11,9 +11,8 @@ db.connectDB()
dbStatus = db.connectDB()
db.anyTasksToDo()
if db.anyTasksToDo() == 1:
-
- for item in reversed(db.tasksList):
-
+ templist = db.tasksList
+ for item in templist:
taskID = item[0]
taskNo = item[1]
callFrom = item[2]
@@ -22,10 +21,11 @@ if db.anyTasksToDo() == 1:
print "Test ID : " , taskID
print "Caller : " , callFrom
print "Receiver : " , callTo
+ #templist.remove(item)
+ #print item
+ #db.deleteTempTask(taskID)
+ if callTo == 'sip':
+ db.insertTaskIn2(callTo,callFrom,taskNo)
-
- db.deleteTempTask(taskID)
- db.cleanTasksList()
- db.anyTasksToDo()
else:
print "No job at all"
diff --git a/For Weekly Test/30-07-2011/test4.py b/For Weekly Test/30-07-2011/test4.py
new file mode 100644
index 0000000..f12163d
--- /dev/null
+++ b/For Weekly Test/30-07-2011/test4.py
@@ -0,0 +1,26 @@
+import dbClass
+user = 'root'
+passw = 'randompasswordSQL'
+host = 'localhost'
+dbname = 'gsmselftesting'
+
+x = dbClass.DBMySQLConnection(user, passw, host, dbname)
+print "connected to the DB ", x.connectDB()
+print "do i have anything to do", x.anyTasksToDo()
+temp = x.tasksList[:]
+for index in range(len(temp)):
+ item = temp[index]
+ taskID = item[0]
+ if item[0] == '17' or item[0] =='18' or item[0]=='19':
+ print "delete a task from temp table", x.deleteTempTask(taskID)
+ x.tasksList.remove(item)
+
+for item in x.tasksList[:]:
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item[3]
+ print "call from to ", taskID , callFrom , callTo, taskNo
+print "close connection to the DB", x.closeDBConn()
+
+del x
diff --git a/For Weekly Test/30-07-2011/test5.py b/For Weekly Test/30-07-2011/test5.py
new file mode 100644
index 0000000..3f11e79
--- /dev/null
+++ b/For Weekly Test/30-07-2011/test5.py
@@ -0,0 +1,6 @@
+lista = ['a', 'b', 'c', 'd']
+templist = lista[:]
+for item in templist:
+ print item
+ lista.remove(item)
+
diff --git a/For Weekly Test/30-07-2011/test6.py b/For Weekly Test/30-07-2011/test6.py
new file mode 100644
index 0000000..fa17798
--- /dev/null
+++ b/For Weekly Test/30-07-2011/test6.py
@@ -0,0 +1,35 @@
+import sys
+import pjsua as pj
+import os
+import re
+import time
+import MySQLdb
+import subprocess
+from time import sleep
+from datetime import datetime
+
+
+try:
+ mydb = MySQLdb.connect('localhost', 'root', 'randompasswordSQL','gsmselftesting');
+ db=mydb.cursor()
+except MySQLdb.Error, e:
+ print "Error %d: %s" % (e.args[0],e.args[1])
+ sys.exit(1)
+
+db.execute("SELECT * FROM TempTaskTable")
+rows = db.fetchall()
+
+global tasksList
+tasksList = list()
+print rows
+for row in rows:
+ columns = list()
+ print row
+ for rowe in rows:
+ columns.append(str(row))
+ print tasksList.append(columns)
+ #print taskList
+# print "%s, %s" % (row[0], row[1])
+# print "Number of rows returned: %d" % db.rowcount
+
+
diff --git a/For Weekly Test/DBProblem/DbClass.py b/For Weekly Test/DBProblem/DbClass.py
new file mode 100644
index 0000000..5556d47
--- /dev/null
+++ b/For Weekly Test/DBProblem/DbClass.py
@@ -0,0 +1,252 @@
+import MySQLdb
+import string
+
+class DBMySQLConnection:
+ def __init__(self, username, password, host, dbname):
+ #initialize at the start all the user parameters
+ self.usern = username
+ self.passw = password
+ self.host = host
+ self.db = dbname
+ self.connectionCreated = 0
+ self.tasksList = list()
+ global debugMode
+ debugMode = 0
+
+ def connectDB(self):
+ try:
+ #try the connection
+ self.datBaseConn=MySQLdb.connect(self.host,self.usern, self.passw,self.db)
+ self.datBaseConn.paramstyle = 'format'
+ self.cur = self.datBaseConn.cursor() #make the cursor, used for sending queries
+ self.connectionCreated = 1 #use it as an indicator that the connection was created
+ return 1
+
+ except MySQLdb.Error, e:
+ #if we have an error then try to catch it
+ error=str(e)
+ if error[1:5] == '1045':
+ #wrong username or password
+ return 0
+ elif error[1:5] == '2002':
+ #can't connect to mysql, mysql shutdown or wrong host
+ return 2
+ else:
+ if debugMode == 1:
+ print error
+ return 3
+
+ def closeDBConn(self):
+ #close the connection to the database here
+ if self.connectionCreated == 1:
+ try:
+ #close the cursor and then the connection to the DB
+ self.cur.close()
+ self.datBaseConn.close()
+ return 1
+ except MySQLdb.Error, e:
+ #in case of an error
+ if debugMode == 1:
+ error = str(e)
+ print error
+ return 3
+ else:
+ #I never really had a connection
+ return 0
+
+ def anyTasksToDo(self):
+ #see are there any jobs to be executed and make a list out of it
+ if self.connectionCreated == 1:
+ try:
+ self.cur.execute("SELECT * FROM TempTaskTable")
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ self.tasksList = output
+ return 1
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def cleanTasksList(self):
+ if self.connectionCreated == 1:
+ del self.tasksList[:]
+ return 1
+ else:
+ return 0
+
+ def removeTaskFromList(self, taskID):
+ #remove only one task from the task list
+ if self.connectionCreated == 1:
+ for index in range(len(self.tasksList)):
+ item = self.tasksList[index]
+ if item[0] == str(taskID):
+ #self.tasksList.remove(index)
+ #print 'found it'
+ del self.tasksList[index]
+ return 1 #deleted taskID
+
+ return 2 #didn't find that taskID
+ else:
+ return 0
+
+ def deviceAddress(self,deviceName):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("SELECT `deviceIP` FROM DeviceAddress where `deviceName`=%s", deviceName)
+ #self.cur.execute()
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ deviceAddr = ''
+ for record in output:
+ columns = list()
+ for entry in record:
+ deviceAddr = str(entry)
+ return deviceAddr
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3 #some error happened
+ else:
+ return 0 #I am not connected
+
+ def updateTaskResult(self, taskID, status):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE TaskTable SET status=%i WHERE taskID=%i"%(int(status), int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #update successful
+ else:
+ return 4 #taskID doesn't exist
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def updatePingResult(self, taskNo, sipServer, sipGate, sipLoc, gsmBox1, gsmBox2):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE PingResultTable SET sipServer=%i, sipGate=%i, sipLoc=%i, gsmBox1=%i, gsmBox2=%i WHERE taskNo=%i"%(int(sipServer), int(sipGate), int(sipLoc), int(gsmBox1), int(gsmBox2), int(taskNo)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #ping table updated
+ else:
+ return 4 #the taskNo didn't exist
+
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def deleteTempTask(self, taskID):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("DELETE FROM TempTaskTable WHERE taskID=%i"%(int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+
+ if successful == 1:
+ return 1 #deleted it
+ else:
+ return 4 #that taskID didn't exist or something else
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+
+ def addResult(self, taskID, result):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("INSERT INTO ResultTable(taskID, result) VALUES ('%i', '%i')"%(int(taskID), int(result)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 1:
+ return 1 #successfully added the result
+ else:
+ return 4 #hmmm
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1062':
+ return 2 #duplicate entry for the key
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+
+ def insertTaskIn2(self, fromDevice, toDevice, taskNo):
+ if self.connectionCreated == 1:
+ try:
+ #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`, `status`) VALUES ('" + str(taskNo) + "', '" + str(fromDevice) + "', '" + str(toDevice) +"', '0'); 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()
+
+
+ #without closing the cursos we get a MySQL error, the mistake is an internal mistak of the MySQLdb python library
+ # self.cur.close()
+ # self.cur = self.datBaseConn.cursor()
+
+ 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 searchTaskList(self, fromDevice, toDevice):
+ if self.connectionCreated == 1:
+ for item in self.tasksList:
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item [3]
+ if callFrom == fromDevice and callTo == toDevice:
+ return 1 #that task was found
+ return 2 #that task wasn't found
+ else:
+ return 0
+
diff --git a/For Weekly Test/DBProblem/test3.py b/For Weekly Test/DBProblem/test3.py
new file mode 100644
index 0000000..bd759ca
--- /dev/null
+++ b/For Weekly Test/DBProblem/test3.py
@@ -0,0 +1,31 @@
+import sys
+import ClientClass
+import DbClass
+import ControllerClass
+import classCheck
+from time import sleep
+
+
+db = DbClass.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
+db.connectDB()
+dbStatus = db.connectDB()
+db.anyTasksToDo()
+if db.anyTasksToDo() == 1:
+ templist = db.tasksList
+ for item in templist:
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item[3]
+
+ print "Test ID : " , taskID
+ print "Caller : " , callFrom
+ print "Receiver : " , callTo
+ #templist.remove(item)
+ #print item
+ #db.deleteTempTask(taskID)
+ if callTo == 'sip':
+ db.insertTaskIn2(callTo,callFrom,taskNo)
+
+else:
+ print "No job at all"