-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseUtils.py
36 lines (31 loc) · 1.26 KB
/
DatabaseUtils.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
import pyodbc
import pickle
from constant import SERVER, DATABASE, PORT, USERNAME, PASSWORD
from Utils import findCurrentDayOfWeek
# print(SERVER, DATABASE, USERNAME, PASSWORD)
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+SERVER+';DATABASE='+DATABASE+';Trusted_Connection=yes;')
cursor = cnxn.cursor()
print('connect database success')
def insertFaceData(id, data):
for img in data:
pickledData = pickle.dumps(img)
count = cursor.execute("""
INSERT INTO StudentImage(StudentID, EncodedImage)
VALUES (?,?)""", id, pickledData).rowcount
cnxn.commit()
def getAllFaceData():
cursor.execute("SELECT StudentID, EncodedImage FROM StudentImage")
return cursor.fetchall()
def getStudentNameById(id):
cursor.execute("SELECT FullName, Class FROM Student WHERE StudentID = '"+id+"'")
return cursor.fetchone()
def getUserByEmail(email):
cursor.execute("SELECT * FROM Teacher WHERE Email = '"+email+"'")
return cursor.fetchone()
def getAllTodayClassByTeacherId(id):
day = findCurrentDayOfWeek()
cursor.execute("SELECT ClassID, ClassName FROM Class WHERE TeacherID = '"+str(id)+"' AND ClassTime = "+str(day)+"")
return cursor.fetchall()
def closeConnection():
cursor.close()
cnxn.close()