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


Python Database.executeReadQuery方法代码示例

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


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

示例1: store

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
    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,代码行数:30,代码来源:appliance.py

示例2: getCreatedRules

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def getCreatedRules(self, includeDisabled = False, includeDeleted = False):

		from app.backend.model.rule import Rule


		query = "SELECT id FROM rules WHERE author_uuid = '@@[email protected]@'"
		query += " AND enabled='1'" if not includeDisabled else ""
		query += " AND deleted='0'" if not includeDeleted else ""
		query += ";"


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

		ruleList = []
		for record in queryResult:
			ruleId = record[0]

			rule = Rule(id = ruleId)
			rule.retrieve()

			ruleList.append(rule)

		return ruleList
开发者ID:alenacci,项目名称:BuildingRules,代码行数:29,代码来源:user.py

示例3: retrieve

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	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,代码行数:28,代码来源:mturk.py

示例4: retrieve

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	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,代码行数:35,代码来源:user.py

示例5: retrieve

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	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,代码行数:30,代码来源:notification.py

示例6: getFirstFreeUserSlot

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def getFirstFreeUserSlot(self):

		print "TODO REMOVE THIS METHOD - NEEDED ONLY FOR THE EXPERIMENTS"

		userList = []

		database = Database()
		query = "SELECT * FROM users WHERE password='verycomplexpasswordverycomplex-54--$$$-1-2-passwordverycomplexpassword' LIMIT 1;"
		database.open()
		queryResult = database.executeReadQuery(query)
		database.close()

		if len(queryResult) == 0:
			raise UserNotFoundError("No more slots available for new users. Thanks for your help! See ya!")

		for record in queryResult:
			uuid = record[0]
			username = record[1]
			email = record[2]
			password = record[3]
			personName = record[4]
			level = record[5]
			registrationTimestamp = datetime.datetime.now()

			user = User(uuid = uuid, username = username, email = email, password = password, personName = personName, level = level, registrationTimestamp = registrationTimestamp)
			user.store()
			return user
开发者ID:alenacci,项目名称:BuildingRules,代码行数:29,代码来源:users.py

示例7: retrieve

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	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,代码行数:31,代码来源:trigger.py

示例8: getActiveRulesId

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def getActiveRulesId(self, buildingName = None, roomName = None):


		query = "SELECT * FROM active_rules"

		if buildingName and not roomName: query += " WHERE building_name = '@@[email protected]@'"
		if buildingName and roomName: query += " WHERE building_name = '@@[email protected]@' AND room_name = '@@[email protected]@'"
		query += ";"
		
		if buildingName: query = query.replace("@@[email protected]@", buildingName)
		if roomName: query = query.replace("@@[email protected]@", roomName)
		

		database = Database()
		database.open()
		queryResult = database.executeReadQuery(query)
		database.close()

		rulesId = []
		for record in queryResult:
			ruleId = record[2]

			rulesId.append(ruleId)
		
		return rulesId
开发者ID:alenacci,项目名称:BuildingRules,代码行数:27,代码来源:rules.py

示例9: retrieve

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	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,代码行数:28,代码来源:setting.py

示例10: retrieve

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
    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,代码行数:34,代码来源:appliance.py

示例11: retrieveNotifications

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def retrieveNotifications(self, user = None, userUuid = None, excludeRead = True):

		if not user and not userUuid:
			raise MissingInputDataError("Cannot retrieve notifications without user or useruuid")

		if user:
			userUuid = user.uuid

		query = "SELECT * FROM notifications WHERE recipient_uuid = '@@[email protected]@' and message_read = '0';"
		if not excludeRead:
			query = "SELECT * FROM notifications WHERE recipient_uuid = '@@[email protected]@';"

		query = query.replace("@@[email protected]@", userUuid)

		notificationList = []

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

		for record in queryResult:
			notificationId = record[0]
			sendTimestamp = record[1]
			messageSubject = record[2]
			messageText = record[3]
			recipientUuid = record[4]
			messageRead = record[5]

			notification = Notification(id = notificationId, sendTimestamp = sendTimestamp, messageSubject = messageSubject, messageText = messageText, recipientUuid = recipientUuid, messageRead = messageRead)
			notificationList.append(notification)

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

示例12: checkUserBinding

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def checkUserBinding(self, user):

		database = Database()

		query = "SELECT user_uuid FROM users_rooms WHERE building_name = '@@[email protected]@' and user_uuid = '@@[email protected]@';"
		query = self.__replaceSqlQueryToken(query)
		query = query.replace('@@[email protected]@', str(user.uuid))
		database.open()
		queryResult = database.executeReadQuery(query)
		database.close()

		if len(queryResult) == 0:
			raise UserBuildingBindingError("The user is not associated with the requested building")
开发者ID:alenacci,项目名称:BuildingRules,代码行数:15,代码来源:building.py

示例13: translateTemplate

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def translateTemplate(self, language, actionTemplate):

		database = Database()
		database.open()
		query = "SELECT * FROM rule_translation_dictionary WHERE language = '@@[email protected]@' AND original = '@@[email protected]@';"
		query = query.replace('@@[email protected]@', language)
		query = query.replace('@@[email protected]@', actionTemplate)
		queryResult = database.executeReadQuery(query)
		database.close()

		if len(queryResult) > 0:
			translation = queryResult[0][3]
			return translation
				
		raise RuleTranslationNotFoundError("Impossibile to translate " + actionTemplate)
开发者ID:alenacci,项目名称:BuildingRules,代码行数:17,代码来源:actions.py

示例14: store

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def store(self):
		database = Database()
		database.open()

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

		if int(queryResult[0][0]) > 0:
			query = "UPDATE buildings SET label = '@@[email protected]@', description = '@@[email protected]@' WHERE building_name = '@@[email protected]@';"
		else:
			query = "INSERT INTO buildings (building_name, label, description) VALUES ('@@[email protected]@', '@@[email protected]@', '@@[email protected]@');"	
	
		query = self.__replaceSqlQueryToken(query)
		database.executeWriteQuery(query)
		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:18,代码来源:building.py

示例15: store

# 需要导入模块: from app.backend.commons.database import Database [as 别名]
# 或者: from app.backend.commons.database.Database import executeReadQuery [as 别名]
	def store(self):

		database = Database()
		database.open()

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

		if int(queryResult[0][0]) > 0:
			query = "UPDATE mturk SET day = '@@[email protected]@', user_uuid = '@@[email protected]@', token = '@@[email protected]@' WHERE id = '@@[email protected]@';"
		else:
			query = "INSERT INTO mturk (day, user_uuid, token) VALUES ('@@[email protected]@', '@@[email protected]@', '@@[email protected]@');"	
	
		query = self.__replaceSqlQueryToken(query)
		database.executeWriteQuery(query)
		database.close()
开发者ID:alenacci,项目名称:BuildingRules,代码行数:19,代码来源:mturk.py


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