summaryrefslogtreecommitdiffstats
path: root/notFinishedCode
diff options
context:
space:
mode:
authorRefik Hadzialic2011-07-15 19:57:16 +0200
committerRefik Hadzialic2011-07-15 19:57:16 +0200
commit8f4a6210663f55d63e0b9c7ddb49b847d59cf8a5 (patch)
treec5fb6cf1d9231711c3caf3bd002a2b6c00bc58ca /notFinishedCode
parentfinal code for landlineCall.py. adjusted to be compatible with communication ... (diff)
downloadgsm-selftest-8f4a6210663f55d63e0b9c7ddb49b847d59cf8a5.tar.gz
gsm-selftest-8f4a6210663f55d63e0b9c7ddb49b847d59cf8a5.tar.xz
gsm-selftest-8f4a6210663f55d63e0b9c7ddb49b847d59cf8a5.zip
changed it to make it work
Diffstat (limited to 'notFinishedCode')
-rw-r--r--notFinishedCode/dbClass.py56
1 files changed, 15 insertions, 41 deletions
diff --git a/notFinishedCode/dbClass.py b/notFinishedCode/dbClass.py
index ff0e485..ebdf73c 100644
--- a/notFinishedCode/dbClass.py
+++ b/notFinishedCode/dbClass.py
@@ -1,6 +1,6 @@
import MySQLdb
import string
-
+from time import sleep
class DBMySQLConnection:
def __init__(self, username, password, host, dbname):
#initialize at the start all the user parameters
@@ -11,7 +11,7 @@ class DBMySQLConnection:
self.connectionCreated = 0
self.tasksList = list()
global debugMode
- debugMode = 0
+ debugMode = 1
def connectDB(self):
try:
@@ -210,54 +210,28 @@ class DBMySQLConnection:
else:
return 0
- def anyTasksFromTo(self, fromDevice, toDevice, taskNo):
- #see are there any jobs to be executed and make a list out of it
- if self.connectionCreated == 1:
- try:
- query = "SELECT * FROM `TempTaskTable` WHERE `from` = '" + str(fromDevice) + "' AND `to` = '" + str(toDevice) + "'"
- self.cur.execute(query)
- 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
- notFound = 0 #used to test if a the task from to was found, if not insert it in the temporary task table
- for record in output:
- columns = list()
- for entry in record:
- notFound = 1
-
- if notFound == 0:
- if self.insertTaskIn2(fromDevice, toDevice, taskNo) == 1:
- return 4 #i inserted the new task
- else:
- return 5 #i didn't insert the new task
- else:
- return 1 #the task was already in the database
- 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 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;"
+
+ newQuery1 = 'SELECT taskID FROM `TempTaskTable` ORDER BY taskID DESC LIMIT 1';
successful = self.cur.execute(newQuery)
+ #self.datBaseConn.commit()
output = self.cur.fetchone()
+ #print 'izlaz', output
+# successful1 = self.cur.execute(newQuery1)
+# output1 = self.cur.fetchone()
+
+ #print output1
+ return 1
if debugMode == 1:
print output
- if successful == 0:
- return 1 #successfully added the result
- else:
- return 4 #hmmm
+
except MySQLdb.Error, e:
error = str(e)
if debugMode == 1:
@@ -313,20 +287,20 @@ print "update task result ", x.updateTaskResult(1,3)
print "update ping Table", x.updatePingResult(1,5,4,3,2,1)
print "delete a task from temp table", x.deleteTempTask(2)
-print "add a result to the table", x.addResult(2,34)
+print "add a result to the table", x.addResult(4,34)
#new task to do
#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#just made for Tri :)---------------------------------------------------------------
#print x.cleanTasksList()
-#print "do i have any task from SIP1 to GSM1 to do", x.anyTasksFromTo('SIP2', 'GSM1', 2)
+#print "do i have any task from SIP1 to GSM1 to do", x.anyTasksFromTo('SIP2', 'GSMu1', 2)
#for item in x.tasksList:
# taskID = item[0]
# callFrom = item[1]
# callTo = item[2]
# print "call from to ", taskID , callFrom , callTo
-#print x.insertTaskIn2('gsm4','sip8',2)
+print 'i am inserting into the table something', x.insertTaskIn2('gsm4','sip8',2)
#-----------------------------------------------------------------------------------
#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$