Ajout d'instructions de fermeture des curseurs

This commit is contained in:
Valentin Moguérou 2023-05-15 05:37:58 +02:00
parent 38f24a3ec3
commit 9112028826

View File

@ -15,6 +15,7 @@ class Database:
cursor = self.db.cursor()
cursor.execute("DELETE FROM sessions WHERE expiry_date <= CURRENT_TIMESTAMP")
self.db.commit()
cursor.close()
def create_session(self, username, password):
cursor = self.db.cursor()
@ -28,19 +29,21 @@ class Database:
uuid = str(uuid4())
cursor.execute("INSERT INTO sessions (session_id, user_id) VALUES (%s, %s)", (uuid, user_id))
self.db.commit()
cursor.close()
return uuid
def destroy_session(self, uuid):
cursor = self.db.cursor()
cursor.execute("DELETE FROM sessions WHERE session_id=%s", (uuid,))
self.db.commit()
cursor.close()
def check_connection(self, uuid):
cursor = self.db.cursor()
cursor.execute("SELECT session_id FROM sessions WHERE session_id=%s", (uuid,))
return cursor.fetchall()
result = cursor.fetchall()
cursor.close()
return result
class User:
def __init__(self, user_id, username, nom, prenom, creation_date):
@ -61,6 +64,7 @@ class Session:
cursor.execute("SELECT utilisateurs.user_id, username, nom, prenom, creation_date FROM utilisateurs "
"JOIN sessions ON utilisateurs.user_id=sessions.user_id WHERE session_id=%s", (self.uuid,))
result = cursor.fetchall()
cursor.close()
return User(*result[0])
def fetch_grades(self):
@ -70,6 +74,7 @@ class Session:
"JOIN matieres ON devoirs.id_matiere=matieres.id_matiere WHERE id_eleve=%s", (self.user.id,))
result = cursor.fetchall()
cursor.close()
dico = {}
for note in result:
if note[0] in dico: