· 6 years ago · Nov 03, 2019, 06:48 AM
1import sqlite3
2conn = sqlite3.connect("OS_Employee.db")
3
4space = " "
5email = "@gmail.com"
6EmpID = input("Please enter your employee ID number: ")
7 # Error checking 1: employee ID must not be blank.
8while not EmpID or not EmpID.isdigit() or not len(EmpID) == 4:
9 if not EmpID:
10 EmpID = input("Employee ID cannot be blank. Please enter your employee ID: ")
11 continue
12 # Error checking 2: employee ID must be in numerical values only.
13 if not EmpID.isdigit():
14 EmpID = input("Employee ID must contain numbers only.")
15 continue
16 # Error checking 3: employee ID must be 4 digits long
17 if not len(EmpID) == 4:
18 if len(EmpID) < 4:
19 EmpID = input("You entered less than 4 digits. Employee ID can only be 4 digits long.")
20 if len(EmpID) > 4:
21 EmpID = input("You entered more than 4 digits. Employee ID can only be 4 digits long.")
22 continue
23
24F_Name = input("Please enter first name: ")
25while not F_Name or not F_Name.isalpha():
26 if not F_Name:
27 F_Name = input ("First name cannot be blank. Please reenter your first name")
28 continue
29 if not F_Name.isalpha():
30 F_Name = input("The following contains characters not in the traditional alphabet. Please try again")
31 continue
32
33L_Name = input("Please enter last name: ")
34userEmail = input("Please enter email: ")
35while not userEmail or not email in userEmail:
36 if not userEmail:
37 userEmail = input("Email cannot be blank. Please enter your email to login in: ")
38 continue
39
40 #checks if user inputs a domain for email
41 if not email in userEmail:
42 userEmail = input("The following includes an invalid domain, please try again: ")
43 continue
44Password = input("Please enter password: ")
45
46with conn:
47 cur = conn.cursor()
48 try:
49 InsertValue = "INSERT INTO Employee VALUES ('{}','{}','{}','{}','{}')"
50 InsertString = InsertValue.format(EmpID,F_Name,L_Name,userEmail,Password)
51 cur.execute(InsertString)
52 cur.execute("SELECT*FROM Employee WHERE(EmployeeID == '{}')".format(EmpID))
53 #order of argument matters, does not know the difference between last name or employeeID.
54 results = cur.fetchone()
55 print(results)
56 except Exception as e:
57 print("connection failed" + str(e))