def insertinsp(self, ip, rectime, curvetime, inspsum, inspa, inspb, inspc): db = pymysql.connect(self.ip, "root", "123456", self.dbname) sp = MySqlApi(db) addr = self.ip2addr(sp, ip) sql = "INSERT INTO insp VALUES (\'%s\', \'%s\', \'%s\', %f, %f, %f, %f)" % ( addr, rectime, curvetime, inspsum, inspa, inspb, inspc) ret = sp.execut(sql) # test print # sql = "SELECT * FROM volt WHERE curvetime = \'%s\'" % (curvetime) # sql = "SELECT * FROM insp" # sp.showdata(sql) db.close()
def insertlogin(self, addr, ip, port, rectime): db = pymysql.connect(self.ip, "root", "123456", self.dbname) sp = MySqlApi(db) sql = "INSERT INTO LoginHeart VALUES (\'%s\', \'%s\', %d, \'%s\')" % ( addr, ip, port, rectime) ret = sp.execut(sql) if ret == 0: self.updateheart(addr, ip, port, rectime) # test print # sql = "SELECT * FROM LoginHeart WHERE addr like %s" % ('\'123%\'') # sp.showaddrlist(sql) db.close()
def insertnegeng(self, ip, rectime, curvetime, negengsum, negeng1, negeng2, negeng3, negeng4, negeng5, negeng6, negeng7, negeng8): db = pymysql.connect(self.ip, "root", "123456", self.dbname) sp = MySqlApi(db) addr = self.ip2addr(sp, ip) sql = "INSERT INTO negeng VALUES (\'%s\', \'%s\', \'%s\', %f, %f, %f, %f, %f, %f, %f, %f, %f)" % ( addr, rectime, curvetime, negengsum, negeng1, negeng2, negeng3, negeng4, negeng5, negeng6, negeng7, negeng8) ret = sp.execut(sql) # test print # sql = "SELECT * FROM negeng WHERE curvetime = \'%s\'" % (curvetime) # sql = "SELECT * FROM negeng" # sp.showdata(sql) db.close()
def updateheart(self, addr, ip, port, rectime): db = pymysql.connect(self.ip, "root", "123456", self.dbname) sp = MySqlApi(db) sql = "UPDATE LoginHeart SET ip = \'%s\' WHERE addr = \'%s\'" % (ip, addr) sp.execut(sql) sql = "UPDATE LoginHeart SET port = %d WHERE addr = \'%s\'" % (port, addr) sp.execut(sql) sql = "UPDATE LoginHeart SET rectime = \'%s\' WHERE addr = \'%s\'" % ( rectime, addr) sp.execut(sql) db.close()