-
Notifications
You must be signed in to change notification settings - Fork 0
/
group-hw3-2.py
44 lines (32 loc) · 1.46 KB
/
group-hw3-2.py
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
import sqlite3
db_con = sqlite3.connect("my_db.txt")
cursor = db_con.cursor()
def createFacultyTable(cursor):
SQL = """CREATE TABLE IF NOT EXISTS Faculty
(FacultyID int (11) NOT NULL,
Name varchar (25) NOT NULL,
Title varchar (100) NOT NULL,
Email varchar (30),
Areas varchar (200)
);"""
cursor.execute(SQL)
def insertFaculty(cursor, FacultyID, Name, Title, Email, Areas):
SQL = "INSERT INTO Faculty (FacultyID, Name, Title, Email, Areas) VALUES ('"
SQL += str(FacultyID)+"', '"+str(Name) + "', '" + str(Title) + "', '" +str(Email)+ "', '" + str(Areas) + "');"
cursor.execute(SQL)
db_con.commit()
createFacultyTable(cursor)
insertFaculty(cursor, 1, 'Will Smith', 'English teacher', '[email protected]', 'English')
insertFaculty(cursor, 2, 'Mr. Bob', 'Chemistry teacher', '[email protected]', 'Chemistry, Biology')
insertFaculty(cursor, 3, 'Mrs. Williams', 'Geography teacher', '[email protected]', 'Geography, History')
insertFaculty(cursor, 4, 'Ms. Robins', 'Calculus Professor', '[email protected]', 'Mathematics')
insertFaculty(cursor, 5, 'Beau Buck', 'History Teacher', '[email protected]', 'History')
def displayData(cursor):
cursor.execute("SELECT * FROM Faculty")
results = cursor.fetchall()
result=""
for row in results:
for i in row:
result += str(i)+"\t"
print(result)
displayData(cursor)