-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert_functions.py
91 lines (71 loc) · 1.81 KB
/
insert_functions.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
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
import sqlite3
conn = sqlite3.connect("mhd.db")
def insert_user(name, password):
global users
users = count_users()
conn.execute(
"INSERT INTO USERS (ID,NAME,PASSWORD) VALUES ("
+ str(users + 1)
+ ", '"
+ name
+ "', '"
+ password
+ "')"
)
conn.commit()
print(f"User {name} created")
users += 1
def insert_entry(id, currentdate, mhd, points):
conn.execute(
"INSERT INTO PROTOCOLL (ID,CURRENTDATE,MHD,POINTS) VALUES ("
+ str(id)
+ ", '"
+ currentdate
+ "', '"
+ mhd
+ "', "
+ str(points)
+ ")"
)
conn.commit()
print(f"Entry with id {id} created")
def delete_from_table(*tables):
for table in tables:
conn.execute(f"DELETE from {table};")
print("Records from tables deleted successfully")
def delete_user(id, name):
conn.execute(
"DELETE FROM USERS WHERE name = '"
+ name
+ "' AND id = "
+ str(id)
)
print(f"User {name} deleted")
# users -= 1
def check_password(name, password):
cursor = conn.execute(
"SELECT COUNT(1) FROM USERS WHERE name = '"
+ name
+ "' AND password = '"
+ password
+ "'"
)
for row in cursor:
return row[0]
def total_points(id):
cursor = conn.execute(
"SELECT SUM(Points) FROM Protocoll WHERE id = " + str(id)
)
for row in cursor:
total = row[0]
if total is None:
total = 0
return total
def count_users():
cursor = conn.execute("SELECT MAX(ID) FROM USERS")
for row in cursor:
cu = row[0]
if cu is None:
cu = 0
return cu
return 0