Exemple #1
0
    def find_authors_books(self, author_id):
        """
        Validates author_id type is int
        Returns all authors books
        :param author_id: int
        :return: List of Books | None
        """

        # Validates type
        if not TypeUtils.is_type(author_id, var_type=int):
            print(ErrorMsgUtils.type_error(author_id, var_type=int))
            return

        sql = f"SELECT BOOKS.* FROM AUTHOR, BOOKS " \
              f"WHERE AUTHOR.ID = {author_id} AND BOOKS.AUTHOR_ID = {author_id}"
        # Execution
        try:
            self.cursor.execute(sql)
            results = self.cursor.fetchall()
            # No Data
            if not results:
                print(ErrorMsgUtils.no_data_available())
                return

            # Return results
            return results
        # Error
        except mysql.connector.Error as error:
            print(ErrorMsgUtils.display_error(error))
Exemple #2
0
    def find_all(self):
        """
        Returns all authors or none
        :return: List of Authors | None
        """

        sql = "SELECT * FROM AUTHOR"
        try:
            self.cursor.execute(sql)
            results = self.cursor.fetchall()
            # No Data case
            if not results:
                print(ErrorMsgUtils.no_data_available())
                return

            # Return results
            return results

        # Error
        except mysql.connector.Error as error:
            print(ErrorMsgUtils.display_error(error))
Exemple #3
0
    def find_all(self):
        """
        Returns all Books
        :param self:
        :return: List of Books
        """

        try:
            # Execution
            sql = "SELECT * FROM BOOKS"
            self.cursor.execute(sql)
            results = self.cursor.fetchall()

            # No Data
            if not results:
                print(ErrorMsgUtils.no_data_available())
                return

            # Return results
            return results

        # Error
        except mysql.connector.Error as error:
            print(ErrorMsgUtils.display_error(error))