From b99193ba68f947802245a288940e54904ecbee61 Mon Sep 17 00:00:00 2001 From: Triatmoko Date: Fri, 18 Nov 2011 13:23:49 +0100 Subject: final version --- Code/Server-Code/DbClass.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) mode change 100755 => 100644 Code/Server-Code/DbClass.py (limited to 'Code/Server-Code/DbClass.py') diff --git a/Code/Server-Code/DbClass.py b/Code/Server-Code/DbClass.py old mode 100755 new mode 100644 index a53987f..d937eb1 --- a/Code/Server-Code/DbClass.py +++ b/Code/Server-Code/DbClass.py @@ -4,8 +4,8 @@ import string class DBMySQLConnection: def __init__(self): #initialize at the start all the user parameters - self.usern = "selftest" - self.passw = "selftest" + self.usern = "root" + self.passw = "" self.host = "localhost" self.db = "gsmselftesting" self.connectionCreated = 0 @@ -19,7 +19,7 @@ class DBMySQLConnection: def connectDB(self): try: - #try the connection + #try to connect 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 @@ -115,7 +115,7 @@ class DBMySQLConnection: return 2 #the table doesn't exist if debugMode == 1: print str(e) - return 3 #some error happened 07667929147--Fitri + return 3 #some error happened else: return 0 #I am not connected def deviceList(self): # taking all device list and put it in the list @@ -171,6 +171,13 @@ class DBMySQLConnection: def updateGSMDevice(self, deviceName, newPortName, newNumber): if self.connectionCreated == 1: try: + try: + #delete old device portName which assign to this port, to prevent double port address in the table. + stmt = "UPDATE DeviceAddressTable SET portName = 'missing' WHERE portName = '"+newPortName+"'" + self.cur.execute(stmt) + except ValueError: + print "Error execute query" + stmt = "UPDATE DeviceAddressTable SET portName = '"+ newPortName + "', number = '"+ newNumber+ "' WHERE deviceName = '" + deviceName+ "'" self.cur.execute(stmt) return 1 -- cgit v1.2.3-55-g7522