-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.py
More file actions
102 lines (94 loc) · 3.73 KB
/
User.py
File metadata and controls
102 lines (94 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import mysql.connector
import Tables
class User:
def __init__(self, db_cursor):
self.cursor = db_cursor
def displayUser():
print()
print("User Records: \n")
mycursor.execute("""SELECT UserRecord.UserID,UserRecord.UserName,UserRecord.Password,BookRecord.BookName,BookRecord.BookID
FROM UserRecord
LEFT JOIN BookRecord ON UserRecord.BookID=BookRecord.BookID""")
records=mycursor.fetchall()
row_no=0
for rows in records :
row_no+=1
print("******************************","Row no.",row_no,"******************************")
print("\t UserID: ", rows[0])
print("\t UserName: ", rows[1])
print("\t Password: ", rows[2])
print("\t Book Issued: ", rows[3])
print("\t Its BookID: ", rows[4])
print()
x=input("Press Enter key to return to the User Menu...")
return
def insertUser():
while True :
data=()
print()
UserID=input(" Enter UserID: ")
UserName=input(" Enter User Name: ")
Password=input(" Enter Password to be Set: ")
data=(UserID, UserName, Password,None)
query="INSERT INTO UserRecord VALUES (%s, %s, %s,%s)"
mycursor.execute(query,data)
mydb.commit()
print()
ch=input("Do you wish to do add more Users?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
def deleteUser():
while True:
print()
UserID=input(" Enter UserID whose details to be deleted : ")
mycursor.execute("DELETE from UserRecord where UserID = {0} ".format("\'"+UserID+"\'"))
mydb.commit()
ch=input("Do you wish to delete more Users?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
def searchUser():
while True:
print()
Search=input(" Enter UserID to be Searched: ")
mycursor.execute("SELECT UserID, UserName, Password , BookName, UserRecord.BookID\
FROM Library.UserRecord LEFT JOIN Library.BookRecord\
ON BookRecord.BookID=UserRecord.BookID\
WHERE UserRecord.UserID={0}".format("\'"+Search+"\'"))
records=mycursor.fetchall()
row_no=0
if records:
for rows in records :
row_no+=1
print("******************************","Searched User Record","******************************")
print("\t UserID: ", rows[0])
print("\t UserName: ", rows[1])
print("\t Password: ", rows[2])
print("\t Book Issued: ", rows[3])
print("\t Its BookID: ", rows[4])
print()
else:
print("Search Unsuccesful!!")
ch=input("Do you wish to Search more Users?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
def updateUser():
while True:
print()
data=()
UserID=input(" Enter User ID for whose details need to be updated : ")
UserName=input(" Enter Updated User Name : ")
Password=input(" Enter Updated Password : ")
query="UPDATE UserRecord SET Username = %s, Password = %s WHERE UserID=%s"
data=(UserName,Password,UserID)
mycursor.execute(query,data)
mydb.commit()
print("Updated succesfully")
ch=input("Do you wish to Update more Users?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
mydb=mysql.connector.connect(host="localhost",user="root",passwd="",database="Library")
mycursor=mydb.cursor()