当前位置: 首页>>代码示例>>Python>>正文


Python database.Database类代码示例

本文整理汇总了Python中app.backend.commons.database.Database的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: store

    def store(self):

        database = Database()
        database.open()

        if self.id:

            query = "SELECT COUNT(id) FROM appliances_network WHERE id = '@@[email protected]@';"
            query = self.__replaceSqlQueryToken(query)
            queryResult = database.executeReadQuery(query)

            if int(queryResult[0][0]) > 0:
                query = "UPDATE appliances_network SET name = '@@[email protected]@', label = '@@[email protected]@', brand = '@@[email protected]@', model = '@@[email protected]@', smart_appliance = '@@[email protected]@', protocol = '@@[email protected]@', address = '@@[email protected]@', timeslots = '@@[email protected]@' WHERE id = '@@[email protected]@';"

        else:

            query = "SELECT COUNT(id) FROM appliances_network WHERE name = '@@[email protected]@';"
            query = self.__replaceSqlQueryToken(query)
            queryResult = database.executeReadQuery(query)

            if int(queryResult[0][0]) > 0:
                query = "UPDATE appliances_network SET name = '@@[email protected]@', label = '@@[email protected]@', brand = '@@[email protected]@', model = '@@[email protected]@', smart_appliance = '@@[email protected]@', protocol = '@@[email protected]@', address = '@@[email protected]@', timeslots = '@@[email protected]@' WHERE name = '@@[email protected]@';"
            else:
                query = "INSERT INTO appliances_network (name, label, brand, model, smart_appliance, protocol, address, timeslots) VALUES ('@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@');"

        query = self.__replaceSqlQueryToken(query)
        database.executeWriteQuery(query)
        database.close()
开发者ID:andreuke,项目名称:danger,代码行数:28,代码来源:appliance.py

示例2: retrieve

	def retrieve(self):


		if self.id:
			query = "SELECT * FROM triggers WHERE id = '@@[email protected]@';"
		elif self.triggerName:
			query = "SELECT * FROM triggers WHERE trigger_name = '@@[email protected]@';"
		else:
			raise MissingInputDataError("Impossibile to query any trigger with missing parameters")

		database = Database()
		database.open()

		query = self.__replaceSqlQueryToken(query)
		queryResult = database.executeReadQuery(query)



		if len(queryResult) > 0:
			self.id = queryResult[0][0]
			self.category = queryResult[0][1]
			self.triggerName = queryResult[0][2]
			self.ruleAntecedent = queryResult[0][3]
			self.description = queryResult[0][4]
		else:
			database.close()
			raise TriggerNotFoundError("Impossibile to find any trigger with the provided values")

		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:29,代码来源:trigger.py

示例3: retrieve

    def retrieve(self):

        if self.id:
            query = "SELECT * FROM appliances_network WHERE id = '@@[email protected]@';"
        elif self.name:
            query = "SELECT * FROM appliances_network WHERE name = '@@[email protected]@';"
        else:
            raise MissingInputDataError("Impossibile to query any appliance with missing parameters")

        database = Database()
        database.open()

        query = self.__replaceSqlQueryToken(query)
        queryResult = database.executeReadQuery(query)

        if len(queryResult) > 0:

            self.id = queryResult[0][0]
            self.name = queryResult[0][1]
            self.label = queryResult[0][2]
            self.brand = queryResult[0][3]
            self.model = queryResult[0][4]
            self.smartAppliance = queryResult[0][5]
            self.protocol = queryResult[0][6]
            self.address = queryResult[0][7]
            self.timeslots = json.loads(queryResult[0][8]) if queryResult[0][8] else None

        else:
            database.close()
            raise ApplianceNotFoundError("Impossibile to find any action with the provided values")

        database.close()
开发者ID:andreuke,项目名称:danger,代码行数:32,代码来源:appliance.py

示例4: retrieve

	def retrieve(self):

		if self.id:
			query = "SELECT * FROM mturk WHERE id = '@@[email protected]@';"
		if self.day != None and self.userUuid != None:
			query = "SELECT * FROM mturk WHERE day = '@@[email protected]@' AND user_uuid = '@@[email protected]@' ;"
		else:
			raise MissingInputDataError("Impossibile to query any Mturk with missing parameters")

		database = Database()
		database.open()
		query = self.__replaceSqlQueryToken(query)
		queryResult = database.executeReadQuery(query)



		if len(queryResult) > 0:
			self.id = queryResult[0][0]
			self.day = queryResult[0][1]
			self.userUuid = queryResult[0][2]
			self.token = queryResult[0][3]
		else:
			database.close()
			raise MturkNotFoundError("Impossibile to find any Mturk with the provided values")

		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:26,代码来源:mturk.py

示例5: retrieve

	def retrieve(self):


		if self.id:
			query = "SELECT * FROM notifications WHERE id = '@@[email protected]@';"
		elif self.recipientUuid:
			query = "SELECT * FROM notifications WHERE recipient_uuid = '@@[email protected]@';"
		else:
			raise MissingInputDataError("Impossibile to query any notification with missing parameters")

		database = Database()
		database.open()

		query = self.__replaceSqlQueryToken(query)
		queryResult = database.executeReadQuery(query)

		if len(queryResult)>0:
			self.id = queryResult[0][0]
			self.sendTimestamp = queryResult[0][1]
			self.messageSubject = queryResult[0][2]
			self.messageText = queryResult[0][3]
			self.recipientUuid = queryResult[0][4]
			self.messageRead = queryResult[0][5]
		else:
			database.close()
			raise TriggerNotFoundError("Impossibile to find any notifications with the provided values")

		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:28,代码来源:notification.py

示例6: retrieve

	def retrieve(self):

		if self.key:
			query = "SELECT * FROM settings WHERE s_key = '@@[email protected]@';"
		else:
			raise MissingInputDataError("Impossibile to query any setting with missing parameters")
			

		database = Database()
		database.open()

		query = self.__replaceSqlQueryToken(query)
		queryResult = database.executeReadQuery(query)


		if len(queryResult) > 0:

			self.key = queryResult[0][0]
			self.value = queryResult[0][1]

		else:
			database.close()
			raise SettingNotFoundError("Impossibile to find any setting with the key '" + self.key + "'")


		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:26,代码来源:setting.py

示例7: retrieve

	def retrieve(self):

		if not self.uuid:
			if self.username and not self.password:
				query = "SELECT * FROM users WHERE username = '@@[email protected]@';"
			elif self.username and self.password:
				query = "SELECT * FROM users WHERE username = '@@[email protected]@' AND password = '@@[email protected]@';"
			else:
				raise ClassNotInitializedError("Impossibile querying a user: missing input data")
		else:
			query = "SELECT * FROM users WHERE uuid = '@@[email protected]@';"


		database = Database()
		database.open()

		query = self.__replaceSqlQueryToken(query)
		queryResult = database.executeReadQuery(query)

		if len(queryResult) > 0:
			self.uuid = int(queryResult[0][0])
			self.username = queryResult[0][1]
			self.email = queryResult[0][2]
			self.password = queryResult[0][3]
			self.personName = queryResult[0][4]
			self.level = int(queryResult[0][5])
			self.registrationTimestamp = queryResult[0][6]

		else:
			database.close()
			raise UserNotFoundError("Impossibile to find any user with the provided values")

		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:33,代码来源:user.py

示例8: checkIfUnique

	def checkIfUnique(self):
		
		if self.groupId:
			query = "SELECT count(id) FROM rules WHERE building_name = '@@[email protected]@' AND group_id = '@@[email protected]@' AND antecedent = '@@[email protected]@' AND consequent = '@@[email protected]@';"
		elif self.roomName:
			query = "SELECT count(id) FROM rules WHERE building_name = '@@[email protected]@' AND room_name = '@@[email protected]@' AND antecedent = '@@[email protected]@' AND consequent = '@@[email protected]@';"
		else:
			raise MissingInputDataError("To check if a rule is unique, or groupId or roomName is needed.")	

		database = Database()
		database.open()		
		query = self.__replaceSqlQueryToken(query)
		queryResult = database.executeReadQuery(query)

		if int(queryResult[0][0]) > 0:
			return False

		return True
开发者ID:alenacci,项目名称:BuildingRules,代码行数:18,代码来源:rule.py

示例9: store

	def store(self):

		updateQuery = False

		database = Database()
		database.open()

		query = "SELECT COUNT(id) FROM rules WHERE id = '@@[email protected]@';"
		query = self.__replaceSqlQueryToken(query)
		queryResult = database.executeReadQuery(query)

		if self.lastEditTimestamp == None:
			self.lastEditTimestamp =  datetime.datetime.now() 

		if self.creationTimestamp == None:
			self.creationTimestamp = datetime.datetime.now() 


		if int(queryResult[0][0]) > 0:
			
			self.lastEditTimestamp =  datetime.datetime.now() 

			query = """UPDATE rules SET 
					priority = '@@[email protected]@', category = '@@[email protected]@', building_name = '@@[email protected]@', group_id = '@@[email protected]@', room_name = '@@[email protected]@', 
					author_uuid = '@@[email protected]@', antecedent = '@@[email protected]@', consequent = '@@[email protected]@', enabled = '@@[email protected]@', 
					deleted = '@@[email protected]@', creation_timestamp = '@@[email protected]@', last_edit_timestamp = '@@[email protected]@'
					WHERE id = '@@[email protected]@';"""
			updateQuery = True
			
		else:

			query = """INSERT INTO rules (priority, category, building_name, group_id, room_name, author_uuid, antecedent, 
					consequent, enabled, deleted, creation_timestamp, last_edit_timestamp) VALUES (
					'@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', '@@[email protected]@', 
					'@@[email protected]@', '@@[email protected]@', '@@[email protected]@');"""


		query = self.__replaceSqlQueryToken(query)
		database.executeWriteQuery(query)
		self.id = int(database.getLastInsertedId()) if not self.id else self.id
		database.close()

		if not self.groupId and not updateQuery:
			from app.backend.model.rulePriority import RulePriority
			rulePriority = RulePriority(buildingName = self.buildingName, roomName = self.roomName, ruleId = self.id, rulePriority = self.__priority)
			rulePriority.store()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:46,代码来源:rule.py

示例10: delete

    def delete(self):

        database = Database()
        database.open()

        query = "DELETE FROM appliances_network WHERE id = '@@[email protected]@';"
        query = self.__replaceSqlQueryToken(query)
        database.executeWriteQuery(query)

        database.close()
开发者ID:andreuke,项目名称:danger,代码行数:10,代码来源:appliance.py

示例11: store

    def store(self):

        database = Database()
        database.open()

        query = "INSERT INTO sessions (session_key, user_uuid, expire_timestamp) VALUES ('@@[email protected]@', '@@[email protected]@', '@@[email protected]@');"

        query = self.__replaceSqlQueryToken(query)
        database.executeWriteQuery(query)
        database.close()
开发者ID:andreuke,项目名称:danger,代码行数:10,代码来源:session.py

示例12: addRoom

	def addRoom(self, room):
		database = Database()
		database.open()

		query = "INSERT INTO rooms_groups (group_id, building_name, room_name) VALUES ('@@[email protected]@', '@@[email protected]@', '@@[email protected]@');"
		query = self.__replaceSqlQueryToken(query)
		query = query.replace("@@[email protected]@", str(room.roomName))
		database.executeWriteQuery(query)

		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:10,代码来源:group.py

示例13: delete

	def delete(self):

		database = Database()
		database.open()

		query = "DELETE FROM settings WHERE s_key = '@@[email protected]@';"
		query = self.__replaceSqlQueryToken(query)
		database.executeWriteQuery(query)

		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:10,代码来源:setting.py

示例14: delete

    def delete(self):

        database = Database()
        database.open()

        query = "DELETE FROM feedbacks WHERE id = '@@[email protected]@';"
        query = self.__replaceSqlQueryToken(query)
        database.executeWriteQuery(query)

        database.close()
开发者ID:andreuke,项目名称:danger,代码行数:10,代码来源:feedback.py

示例15: deleteRoom

	def deleteRoom(self, room):
		database = Database()
		database.open()

		query = "DELETE FROM rooms_groups WHERE room_name = '@@[email protected]@' AND building_name = '@@[email protected]@' AND group_id = '@@[email protected]@';"
		query = self.__replaceSqlQueryToken(query)
		query = query.replace("@@[email protected]@", str(room.roomName))
		database.executeWriteQuery(query)

		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:10,代码来源:group.py


注:本文中的app.backend.commons.database.Database类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。