Library Management Class 12
Library Management Class 12
BHIWADI
Session - 2022-23
Computer Science (083)
Library Management
My sincere thanks go to Dr. Prabhat Kaushik, our principal, for his co-
ordination in extending every possible support for the completion of
this project.
Finally, I would like to thank all those who had helped directly or
indirectly towards the completion of this project.
Prachi
import mysql.connector:
By importing this package, we are able to establish the connection
between SQL and Python.
Functions:
connect():
cursor():
execute():
This function is used to execute the sql query and retrieve records
using python.
The syntax is:
def():
fetchall():
This function will return all the rows from the result set in the form
of a tuple containing the records.
fetchone():
This Function will return one row from the result set in the form of a
tuple containing the records.
commit():
1.) Books
2.) Issue
3.) Return
a) bname
b) author
c) bcode
d) total
e) subject
c.) bcode
d.) issue_date
3.) The table Return contain the following columns:
a.) name
b.) regno
c.) bcode
d.) return_date
SOURCE
CODE
PYTHON
import mysql.connector as a
print("""
*******************************************************
**************************************************
WELCOME TO
LIBRARY MANAGEMENT
*******************************************************
**************************************************
""")
print("""
DESIGNED AND MAINTAINED BY
PRACHI CLASS:XII COMMERCE"B
""")
con =
a.connect(host="localhost",user="root",password="hrithi
k_@123")
c =con.cursor()
c.execute("Create database if not exists library_app")
c.execute("use library_app")
c.execute("create table if not exists books(bname
varchar(50),author varchar(50),bcode varchar(50),total
int(50),subject varchar(50))")
c.execute("create table if not exists issue(name
varchar(50),regno varchar(50),bcode int(50),issue_date
varchar(50))")
c.execute("create table if not exists ret(name
varchar(50),regno varchar(50),bcode int(50),return_date
varchar(50))")
con.commit()
def addbook():
bn =input("Enter Book Name: ")
ba =input("Enter Author's Name: ")
c =int(input("Enter Book Code: "))
t =int(input("Total Books: "))
s =input("Enter Subject: ")
data =(bn,ba,c,t,s)
sql ='insert into books values(%s, %s, %s, %s,%s);'
c=con.cursor()
c.execute(sql,data)
con.commit()
print("\n\n\n\nBooked Successful
Added..........\n\n\n\n")
wait = input('\n\n\nPress enter to
continue.....\n\n\n\n\n\n')
main()
def issueb():
n=input("Enter Student Name: ")
r=int(input("Enter Reg No.: "))
co=int(input("Enter Book Code: "))
d=input("Enter Date: ")
a="insert into issue values(%s,%s,%s,%s);"
data=(n,r,co,d)
c=con.cursor()
c.execute(a,data)
con.commit()
print("\n\n\n\nBook issued successfully to: ",n)
wait = input('\n\n\nPress enter to
continue.....\n\n\n\n\n\n')
bookup(co,-1)
main()
def retb():
n=input("Enter Student Name:")
r=int(input("Enter Reg No.: "))
co=int(input("Enter Book Code: "))
d =input("Enter Date: ")
a="insert into ret values(%s,%s,%s,%s);"
data=(n,r,co,d)
c=con.cursor()
c.execute(a,data)
con.commit()
print("Book returned by: ",n)
wait=input("\n\n\nPress enter to
continue.....\n\n\n\n\n\n")
bookup(co,1)
main()
def bookup(co,u):
a="select total from books where bcode=%s;"
data=(co,)
c=con.cursor()
c.execute(a,data)
myresult=c.fetchone()
t=myresult[0]+u
sql="update books set total=%s where bcode=%s;"
d=(t,co)
c.execute(sql,d)
con.commit()
wait = input("\n\n\nPress enter to
continue.....\n\n\n\n\n\n")
main()
def dbook():
ac=int(input("Enter Book Code: "))
a="delete from books where bcode=%s;"
data=(ac,)
c=con.cursor()
c.execute(a,data)
con.commit()
print("Book deleted successfully")
wait= input("\n\n\nPress enter to
continue.....\n\n\n\n\n\n\n\n\n\n\n\n")
main()
def displaybook():
a="select * from books;"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print("Book name: ",i[0])
print("Author: ",[1])
print("Book code: ",[2])
print("Total:",i[3])
print("Subject:",i[4])
print("\n\n")
def report_issued_books():
a="select from issue;"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print(myresult)
def report_return_22_books():
a="select * from ret;"
c=con.cursor()
c.execute(a)
result=c.fetchall()
for i in myresult:
print(myresult)
def main():
print("""
LIBRARY MANAGEMENT APPLICATION
1. ADD BOOK
2. ISSUE OF BOOK
3. RETURN OF BOOK
4. DELETE BOOK
5. DISPLAY BOOKS
6. REPORT MENU
7. EXIT PROGRAM
""")
if(choice=='1'):
addbook()
elif(choice =='2'):
issueb()
elif(choice =='3'):
retb()
elif(choice=='4'):
dbook()
elif(choice=='5'):
displaybook()
elif(choice=='6'):
print(""" REPORT MENU
1. ISSUED BOOKS
2. RETURNED BOOKS
3. GO BACK TO MAIN MENU
\n\n\n
""")
choice=input("Enter Task No:......")
print("\n\n\n\n\n\n\n")
if choice=='1':
report_issued_books()
elif choice=='2':
report_ret_books()
elif choice=='3':
main()
else:
print("Please try
again........\n\n\n\n\n\n\n\n\n")
main()
elif(choice=="7"):
print('\n\n\n\n\n\n\n\n\n\n\n\nThank you and
have a great day
ahead.............\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')
else:
print("Please try
again........\n\n\n\n\n\n\n\n\n\n\n\n")
main()
main()
OUTPUT
1. Add books
2. Issue a book
3. Return of books
SQL COMMAND
BIBLIOGRAPHY
CS kips Class 12 Textbook
Class 12 NCERT Textbook
www.google.com