예제 #1
0
    def select_profile(self, id=None, profile=None):
        """
        Returns Profile's instance from database with corresponding id.
        :param id: - int.
        :return User: - successful select means that there is a record with corresponding id.
        :raise RepositoryError: - error occured while working with database.
        """

        try:
            if id is not None and profile is None:
                query = "SELECT * FROM profile WHERE id = %d" % id

            elif id is None and profile is not None:
                query = "SELECT * FROM profile WHERE first_name = '{first_name}' AND second_name = '{second_name}' AND last_name = '{last_name}' AND age = {age}"
                query = query.format(first_name=profile.first_name,
                                     second_name=profile.second_name,
                                     last_name=profile.last_name,
                                     age=profile.age)
            else:
                raise RepositoryError

            self.__db.execute(query)
            if self.__db.cursor.rowcount == 1:
                return Profile.from_dict(self.__db.cursor.fetchone())
            else:
                return None

        except Exception as ex:
            print(ex)
            raise RepositoryError
예제 #2
0
    def select_profile(self, id):

        try:
            query = "SELECT * FROM profile WHERE id = %d" % id
            self.__db.execute(query)

            if self.__db.cursor.rowcount == 1:
                return Profile.from_dict(self.__db.cursor.fetchone())
            else:
                return None

        except Exception as ex:
            print(ex)
            raise RepositoryError
예제 #3
0
    def select_profile(self, id):
        """
        Returns Profile's instance from database with corresponding id.
        :param id: - int.
        :return User: - successful selection means that there is a record with corresponding id.
        :raise RepositoryError: - error occured while working with database.
        """

        try:
            query = "SELECT * FROM profile WHERE id = %d" % id
            self.__db.execute(query)

            if self.__db.cursor.rowcount == 1:
                return Profile.from_dict(self.__db.cursor.fetchone())
            else:
                return None

        except Exception as error:
            print(f'\n>>> Error: {error} <<<')
            raise RepositoryError
예제 #4
0
    def select_profile(self, id):
        """
        Возвращает объект класса Profile с бд с нужным нам id
        :param id: - int
        :return Profile: - успешный select (такая запись есть)
        :return None: - такой записи нету
        :raise RepositoryError: - ошибка в бд
        """

        try:
            query = "SELECT * FROM profile WHERE id = %d" % id
            self.__db.execute(query)

            if self.__db.cursor.rowcount == 1:
                return Profile.from_dict(self.__db.cursor.fetchone())
            else:
                return None

        except Exception as ex:
            print(ex)
            raise RepositoryError