-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBase.py
More file actions
94 lines (72 loc) · 2.25 KB
/
DataBase.py
File metadata and controls
94 lines (72 loc) · 2.25 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
import sqlite3 as sql
import os
# connection = sql.connect('userbase.db')
# cursor = connection.cursor()
#
# cursor.execute("""CREATE TABLE IF NOT EXISTS users(
# user_id INT PRIMARY KEY,
# user_name TEXT);
# """)
# connection.commit()
#
# cursor.execute("""CREATE TABLE IF NOT EXISTS exams(
# user_id INT,
# exam_id TEXT PRIMARY KEY
# )""")
# connection.commit()
# connection.close()
def add_user(user_id: int, user_name: str):
connection = sql.connect('userbase.db')
cursor = connection.cursor()
cursor.execute(f"""insert into users
values('{user_id}', '{user_name}')""")
connection.commit()
connection.close()
def add_exam(user_id: int, exam_id: str):
connection = sql.connect('userbase.db')
cursor = connection.cursor()
cursor.execute(f"""insert into exams
values('{user_id}', '{exam_id}')""")
connection.commit()
connection.close()
def get_exam_list(user_id: int):
connection = sql.connect('userbase.db')
cursor = connection.cursor()
cursor.execute(f"SELECT exam_id FROM exams where user_id = '{user_id}';")
result = cursor.fetchall()
connection.close()
return result
def get_user_list():
connection = sql.connect('userbase.db')
cursor = connection.cursor()
cursor.execute(f"SELECT * FROM users;")
result = cursor.fetchall()
connection.close()
return result
def get_user_name(user_id: int):
connection = sql.connect('userbase.db')
cursor = connection.cursor()
cursor.execute(f"SELECT user_name FROM users where user_id = {user_id};")
result = cursor.fetchall()
connection.close()
if result:
return result
else:
result = [[None], []]
return result
def delete_exam(exam_id: str):
connection = sql.connect('userbase.db')
cursor = connection.cursor()
cursor.execute(f"DELETE FROM exams where exam_id = '{exam_id}';")
connection.commit()
connection.close()
try:
os.remove(f'./Exams/{exam_id}.blet')
except:
print(f'delete error 404. {exam_id}')
def delete_user(user_id: int):
connection = sql.connect('userbase.db')
cursor = connection.cursor()
cursor.execute(f"DELETE FROM users where user_id = '{user_id}';")
connection.commit()
connection.close()