Пример #1
0
	def deleteDeviceById(cls,id1):
		dao=DAOClass()
		sql="delete from sessions where device_id='"+id1+"'"
		print(sql)
		r=dao.updateData(sql)
		sql="delete from devices where id='"+id1+"'"
		print(sql)
		r=dao.updateData(sql)
		print(r)
		return r
Пример #2
0
	def deleteSessionById(cls,id1):
		dao=DAOClass()
		sql="delete from sessions where id="+str(id1)
		print(sql)
		r=dao.updateData(sql)
		print(r)
		return r
Пример #3
0
	def deleteSessionsByDevice(cls,device_id):
		dao=DAOClass()
		sql="delete from sessions where device_id='"+device_id+"'"
		print(sql)
		r=dao.updateData(sql)
		print(r)
		return r
Пример #4
0
	def addUser(self):
		u=User.getUserByEmail(self.email)
		if(u=="User Not Found"):
			dao=DAOClass()
			sql="insert into users(name,email,pwd) values('"+self.name+"','"+self.email+"','"+self.pwd+"')"
			print("addUser: "******"""
				if(isinstance(u,User)):
					return u.getid()
				else:
					return u
				"""

			else:
				return "Database Error"
		elif(u=="Database Error"):
			return "Database Error"
		else:
			msg="User Already Exists"
			print(msg)
			return msg
Пример #5
0
	def updateDevice(self):
		dao=DAOClass()
		sql="select * from devices where owner="+str(self.owner)+" and name='"+self.name+"'"
		print(sql)
		rows=dao.getData(sql)
		print(rows)
		if(rows==[]):
			sql="update devices set name='"+self.name+"' where id='"+self.id+"'"
			print(sql)
			r=dao.updateData(sql)
			if(r==True):
				return r
			else:
				msg="Database Error"
				print(msg)
				return msg

		elif(rows==None):
			msg="Database Error"
			print(msg)
			return msg
		else:
			msg="Another Device having same name found."
			print(msg)
			return msg
Пример #6
0
	def addDevice(self):
		dao=DAOClass()
		sql="select * from devices where owner="+str(self.owner)+" and name='"+self.name+"'"
		print(sql)
		rows=dao.getData(sql)
		print(rows)
		if(rows==[]):
			sql="insert into devices(id,name,state,owner,authtoken) values('"+self.id+"','"+self.name+"',"+str(int(self.state))+","+str(self.owner)+",'"+self.auth_token+"')"
			print(sql)
			r=dao.updateData(sql)
			if(r==True):
				return r
			else:
				msg="Database Error"
				print(msg)
				return msg

		elif(rows==None):
			msg="Database Error"
			print(msg)
			return msg
		else:
			msg="Another Device having same name found."
			print(msg)
			return msg
Пример #7
0
	def addNotification(self):
		dao=DAOClass()
		sql="insert into notifications(user_id,time,type,msg,readn) \
		values("+str(self.user_id)+",now(),'"+self.type+"','"+self.msg+"',0)"
		
		print(sql)
		r=dao.updateData(sql)
		return r
Пример #8
0
	def updateUserById(self):
		dao=DAOClass()
		sql="update users set name='"+self.name+"', email='"+self.email+"', pwd='"+self.pwd+"' where id="+self.id
		print("updateUserById: "+sql)
		r=dao.updateData(sql)
		if(r==True):
			msg="User Data Updated"
			print(msg)
			return msg
		else:
			msg="Database Error"
			print(msg)
			return msg
Пример #9
0
	def addSession(self):		
		dao=DAOClass()
		sql="insert into sessions(device_id,start_time) values('"+self.deviceid+"',now())"
		r=dao.updateData(sql)
		if(r==True):
			sql="select max(id) from sessions where device_id='"+self.deviceid+"' and end_time is NULL"
			rows=dao.getData(sql)
			if(rows==None):
				return "Database Error"
			else:
				self.id=rows[0][0]
				return int(self.id)
		else:
			return "Database Error"
Пример #10
0
	def updateLastBillDate(cls,user_id):
		dao=DAOClass()
		sql="select svalue from usersettings where user_id="+user_id+" and setting='billingcycle'"
		print(sql)
		billingcycle=dao.getData(sql)[0][0]
		print(billingcycle)
		if(billingcycle==None):
			return False

		sql="update usersettings set svalue=svalue+INTERVAL "+billingcycle+" DAY\
		 where user_id="+user_id+" and setting='lastbilldate' \
		 and now()>svalue+INTERVAL "+billingcycle+" DAY"
		print(sql)
		r=dao.updateData(sql)
		return r
Пример #11
0
	def readNotification(cls,nid):
		dao=DAOClass()
		sql="update notifications set readn=1 where id="+str(nid)
		r=dao.updateData(sql)
		print(sql)
		return r
Пример #12
0
	def updateSetting(self):
		dao=DAOClass()
		sql="update usersettings set svalue='"+self.value+"' where user_id="+str(self.user_id)+" and setting='"+self.setting+"'"
		print(sql)
		r=dao.updateData(sql)
		return r
Пример #13
0
	def addSetting(self):
		dao=DAOClass()
		sql="insert into usersettings values("+str(self.user_id)+",'"+self.setting+"','"+self.value+"')"
		print(sql)
		r=dao.updateData(sql)
		return r
Пример #14
0
	def updateSession(self):
		dao=DAOClass()
		sql="update sessions set end_time=now(), energy_consumed="+str(self.energy_consumed)+" where id="+str(self.id)
		print(sql)
		r=dao.updateData(sql)
		return r
Пример #15
0
	def updateDeviceStateById(cls,id1,state1):
		dao=DAOClass()
		sql="update devices set state="+str(int(state1))+" where id='"+id1+"'"
		print(sql)
		r=dao.updateData(sql)
		return r