Beispiel #1
0
def add_new_book(book : books) :
    try:
        query_str = "insert into books (BookName, BookWriter) values ('%s','%s')" % (book.bookName, book.bookWriter)
        result = query(query_str, False)
        print("Book has been added successfully: %s" % result)
    except Exception as err:
        print("An error has occured: %s" % err)
Beispiel #2
0
def return_book(book_id) -> str:
    try:
        query_str = "sp_return_book '{}'".format(book_id)
        result = query(query_str, True)
        return result
    except Exception as err:
        print("An error has occured: {}".format(err))
Beispiel #3
0
def search_book_by_name_or_id(search_string : str) -> list:
    try:
        query_str = ("select b.*,u.UserID from books b left join issuestatus i on b.bookid = i.bookid and i.issuestatus = 1"
                    + " left join users u on i.UserID = u.UserID"
                    + " where bookname like '%{}%' or b.bookid like '%{}%' "
                    + "or bookwriter like '%{}%'").format(search_string, search_string, search_string)
        result = query(query_str, True)
        return process_search_result(result)
    except Exception as err:
        print("An error has occured: %s", err)
Beispiel #4
0
def search_book_history_user(user_id) -> list:
    try:
        query_str = ("select B.BookID, B.BookName, Case when I.IssueStatus = 1 then 'Issued' else 'Returned' end 'IssueStatus' "
                    + ", I.IssueDate, I.ReturnDate from Users U left join IssueStatus I on U.UserID = I.UserID"
                    + " left join Books B on I.BookID = B.BookID where U.UserID = '{}' "
                    + " order by I.IssueStatus desc, I.IssueDate desc").format(user_id)

        result = query(query_str,True)
        return process_search_history_result(result)
    except Exception as err:
        print("An error has occured: {}".format(err))