예제 #1
0
def query(q_string):
	'''
	Query the db with the given string and return with an array of user objects.
	'''
	try:
		_db = mysql.Database()
		_db._cursor.execute( '''%s''' % (q_string))
		logging.debug("Running mysql query: %s" % q_string)
		temp = _db._cursor.fetchall()
		users = []
		for t in temp:
			t = mysql.users_convert_to_dict(t)
			users.append(User(t['id']))
		return users
	except Exception, e:
		logging.error(e.__str__())
예제 #2
0
def query(q_string):
    '''
	Query the db with the given string and return with an array of user objects.
	'''
    try:
        _db = mysql.Database()
        _db._cursor.execute('''%s''' % (q_string))
        logging.debug("Running mysql query: %s" % q_string)
        temp = _db._cursor.fetchall()
        users = []
        for t in temp:
            t = mysql.users_convert_to_dict(t)
            users.append(User(t['id']))
        return users
    except Exception, e:
        logging.error(e.__str__())
예제 #3
0
	def load_user(self, id, as_dict=False):
		'''
		load a user with a specific id
		'''
		logging.debug("Loading user: %s" % id)
		try:
			self.db._cursor.execute( '''SELECT * FROM users WHERE id = %s''', id)
			user = mysql.users_convert_to_dict(self.db._cursor.fetchone())
			if as_dict == True: return user
			self.name = user['name']
			self.phone = user['phone']
			self.email = user['email']
			self.state = user['state']
			self.team = user['team']
			self.lastAlert = user['lastAlert']
			self.createDate = user['createDate']
			self.id = user['id']
		except Exception, e:
			logging.error(e.__str__())
			self.id = 0
예제 #4
0
    def load_user(self, id, as_dict=False):
        '''
		load a user with a specific id
		'''
        logging.debug("Loading user: %s" % id)
        try:
            self.db._cursor.execute('''SELECT * FROM users WHERE id = %s''',
                                    id)
            user = mysql.users_convert_to_dict(self.db._cursor.fetchone())
            if as_dict == True: return user
            self.name = user['name']
            self.phone = user['phone']
            self.email = user['email']
            self.state = user['state']
            self.team = user['team']
            self.lastAlert = user['lastAlert']
            self.createDate = user['createDate']
            self.id = user['id']
        except Exception, e:
            logging.error(e.__str__())
            self.id = 0